<?php

function kanary_options_panel_init()
{
	$options_panel = new Kanary_Options();
	global $theme_settings;

	$theme_settings = $options_panel->get_options();
}

add_action('init', 'kanary_options_panel_init', 0);
add_action('customize_preview_init', 'kanary_options_panel_init');

require_once 'options-framework.php';

/**
 * Returns an array of system fonts
 * Feel free to edit this, update the font fallbacks, etc.
 */
function kanary_supported_os_fonts()
{
	// OS Font Defaults
	$os_faces = array(
		'Arial, sans-serif'                                       => 'Arial',
		"'Avant Garde', sans-serif"                               => 'Avant Garde',
		'Cambria, Georgia, serif'                                 => 'Cambria',
		'Copse, sans-serif'                                       => 'Copse',
		"Garamond, 'Hoefler Text', Times New Roman, Times, serif" => 'Garamond',
		'Georgia, serif'                                          => 'Georgia',
		"'Helvetica Neue', Helvetica, sans-serif"                 => 'Helvetica Neue',
		'Tahoma, Geneva, sans-serif'                              => 'Tahoma'
	);

	return $os_faces;
}

/**
 * Returns a select list of Google fonts
 * Feel free to edit this, update the fallbacks, etc.
 */

function kanary_supported_google_fonts()
{
	// Google Font Defaults
	$google_faces = array(
		'Arvo, serif'                     => 'Arvo (Google)',
		'Copse, sans-serif'               => 'Copse (Google)',
		'Droid Sans, sans-serif'          => 'Droid Sans (Google)',
		'Droid Serif, serif'              => 'Droid Serif (Google)',
		'Lobster, cursive'                => 'Lobster (Google)',
		'Nobile, sans-serif'              => 'Nobile (Google)',
		'Open Sans, sans-serif'           => 'Open Sans (Google)',
		'Oswald, sans-serif'              => 'Oswald (Google)',
		'Pacifico, cursive'               => 'Pacifico (Google)',
		'Rokkitt, serif'                  => 'Rokkit (Google)',
		'PT Sans, sans-serif'             => 'PT Sans (Google)',
		'Quattrocento, serif'             => 'Quattrocento (Google)',
		'Raleway, cursive'                => 'Raleway (Google)',
		'Ubuntu, sans-serif'              => 'Ubuntu (Google)',
		'Yanone Kaffeesatz, sans-serif'   => 'Yanone Kaffeesatz (Google)',
		'Bree Serif, serif'               => 'Bree Serif (Google)',
		'Poiret One, cursive'             => 'Poiret One (Google)',
		'PT Serif, serif'                 => 'PT Serif (Google)',
		'Titillium Web, sans-serif'       => 'Titillium Web (Google)',
		'Merriweather, serif'             => 'Merriweather (Google)',
		'Roboto, sans-serif'              => 'Roboto (Google)',
		'Roboto Slab, serif'              => 'Roboto Slab (Google)',
		'Open Sans Condensed, sans-serif' => 'Open Sans Condensed (Google)'
	);
	return $google_faces;
}

class Kanary_Options extends Kanary_Options_Framework
{

	function __construct()
	{
		$option_id = "kanary_theme_options";
		$option_id = apply_filters('kanary_option_id', $option_id);
		parent::__construct($option_id);
	}

	protected function get_setting_sections()
	{
		$settings_sections = array(
			'general' => __('Kanary General', 'emerald'),
			'home'    => __('Kanary Homepage', 'emerald'),
			'slider'  => __('Kanary Slider', 'emerald'),
			'layouts' => __('Kanary Layout', 'emerald'),
			'styling' => __('Kanary Styling', 'emerald'),
			'fonts'   => __('Kanary Fonts', 'emerald'),
			'social'  => __('Kanary Social', 'emerald'),
			'footer'  => __('Kanary Footer', 'emerald')
		);

		return apply_filters('kanary_setting_sections', $settings_sections);
	}

	protected function get_setting_fields()
	{

		$fonts = array_merge(kanary_supported_os_fonts(), kanary_supported_google_fonts());
		asort($fonts);
		$fonts = array_merge(array('' => 'Inherit'), $fonts);

		$layouts = array(
			''                => __('Inherit', 'emerald'),
			'content-sidebar' => __('Right Sidebar', 'emerald'),
			'sidebar-content' => __('Left Sidebar', 'emerald'),
			'fullwidth'       => __('Fullwidth', 'emerald')
		);

		$setting_fields = array(
			'general' => array(
				'custom_favicon' => array(
					'label' => __('Favicon', 'emerald'),
					'type'  => 'media_url'
				),

				'logo' => array(
					'label' => __('Logo URL', 'emerald'),
					'type'  => 'media_url'
				),

				'custom_css' => array(
					'label' => __('Custom CSS', 'emerald'),
					'type'  => 'textarea'
				)
			),

			'layouts' => array(
				'sidebar_width' => array(
					'label'   => __('Sidebar Width', 'emerald'),
					'type'    => 'select',
					'choices' => array(
						''            => '250px',
						'sidebar-300' => '300px',
						'sidebar-350' => '350px',
						'sidebar-400' => '400px'
					)
				),

				'general' => array(
					'label'   => __('Layout', 'emerald'),
					'type'    => 'select',
					'choices' => $layouts
				),

				'single' => array(
					'label'   => __('Single Layout', 'emerald'),
					'type'    => 'select',
					'choices' => $layouts
				),

				'single_post' => array(
					'label'   => __('Single Post Layout', 'emerald'),
					'type'    => 'select',
					'choices' => $layouts
				),

				'single_page' => array(
					'label'   => __('Single Page Layout', 'emerald'),
					'type'    => 'select',
					'choices' => $layouts
				),

				'archive' => array(
					'label'   => __('Archive Layout', 'emerald'),
					'type'    => 'select',
					'choices' => $layouts
				),

				'archive_category' => array(
					'label'   => __('Category Archive Layout', 'emerald'),
					'type'    => 'select',
					'choices' => $layouts
				),

				'archive_tag' => array(
					'label'   => __('Tag Archive Layout', 'emerald'),
					'type'    => 'select',
					'choices' => $layouts
				)
			),

			'home' => array(
				'show_excerpts' => array(
					'label' => __('Show Excerpts', 'emerald'),
					'type'  => 'checkbox'
				),
			),

			'slider' => array(
				'disable_slider' => array(
					'label' => __('Disable slider?', 'emerald'),
					'type'  => 'checkbox'
				),

				'slides' => array(
					'label' => __('Slider Images', 'emerald'),
					'type'  => 'media_items'
				),

				'transitionStyle' => array(
					'label'   => __('Transition Style', 'emerald'),
					'type'    => 'select',
					'choices' => array('' => __('Slide', 'emerald'), 'fade' => __('Fade', 'emerald'), 'backSlide' => __('Back Slide', 'emerald'), 'goDown' => __('Go Down', 'emerald'), 'fadeUp' => __('Fade Up', 'emerald')),
				),

				'pagination' => array(
					'label'   => __('Display Pagination', 'emerald'),
					'type'    => 'checkbox',
					'default' => true
				),

				'autoPlay' => array(
					'label'   => __('Auto Play', 'emerald'),
					'type'    => 'checkbox',
					'default' => false
				),

				'stopOnHover' => array(
					'label'   => __('Stop On Hover', 'emerald'),
					'type'    => 'checkbox',
					'default' => false
				),

				'navigation' => array(
					'label'   => __('Display Navigation', 'emerald'),
					'type'    => 'checkbox',
					'default' => false
				)
			),

			'styling' => array(
				'bg_color' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'body{background-color:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Background Color', 'emerald'),
							'type'  => 'color'
						)
					)
				),

				'bg_img' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'body{background-image:url(%s);}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Background Image', 'emerald'),
							'type'  => 'media_url'
						)
					)
				),

				'bg_repeat' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'body{background-repeat:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label'   => __('Background Repeat', 'emerald'),
							'type'    => 'select',
							'choices' => array('repeat' => __('Horizontally & vertically', 'emerald'), 'repeat-x' => __('Horizontally', 'emerald'), 'repeat-y' => __('Vertically', 'emerald'))
						)
					)
				),

				'a_color' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'a{color:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Link Color', 'emerald'),
							'type'  => 'color'
						)
					)
				),

				'a_visited_color' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'a:visited{color:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Link Visited Color', 'emerald'),
							'type'  => 'color'
						)
					)
				),

				'a_hover_color' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'a:hover{color:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Link Hover Color', 'emerald'),
							'type'  => 'color'
						)
					)
				),

				'entry_title_a_color' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => '.entry-title a{color:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Entry Title Link Color', 'emerald'),
							'type'  => 'color'
						)
					)
				),

				'entry_title_a_visited_color' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => '.entry-title a:visited{color:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Entry Title Link Visited Color', 'emerald'),
							'type'  => 'color'
						)
					)
				),

				'entry_title_a_hover_color' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => '.entry-title a:hover{color:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label' => __('Entry Title Link Hover Color', 'emerald'),
							'type'  => 'color'
						)
					)
				)

			),

			'fonts' => array(
				'font_size' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'body, button, input, select, textarea{font-size:%spx;}',
							'customizer' => false
						),
						'value'  => array(
							'label'   => __('Font Size', 'emerald'),
							'type'    => 'number',
							'default' => 16
						)
					)
				),

				'font_family' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'body, button, input, select, textarea{font-family:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label'   => __('Basic Font', 'emerald'),
							'type'    => 'select',
							'choices' => $fonts
						)
					)
				),

				'headings_font_family' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => 'h1,h2,h3,h4,h5,h6{font-family:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label'   => __('Headings Font', 'emerald'),
							'type'    => 'select',
							'choices' => $fonts
						)
					)
				),

				'site_title_font_family' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => '.site-title{font-family:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label'   => __('Site Title Font', 'emerald'),
							'type'    => 'select',
							'choices' => $fonts
						)
					)
				),

				'post_title_font_family' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => '.entry-title{font-family:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label'   => __('Post Title Font', 'emerald'),
							'type'    => 'select',
							'choices' => $fonts
						)
					)
				),

				'widget_title_font_family' => array(
					'type'  => 'nested',
					'items' => array(
						'format' => array(
							'type'       => 'hidden',
							'default'    => '.widget-title{font-family:%s;}',
							'customizer' => false
						),
						'value'  => array(
							'label'   => __('Widget Title Font', 'emerald'),
							'type'    => 'select',
							'choices' => $fonts
						)
					)
				),
			),

			'social' => array(
				'twitter' => array(
					'label' => __('Twitter URL', 'emerald'),
					'type'  => 'url'
				),

				'fb' => array(
					'label' => __('Facebook URL', 'emerald'),
					'type'  => 'url'
				),

				'google_plus' => array(
					'label' => __('Google Plus URL', 'emerald'),
					'type'  => 'url'
				),

				'instagram' => array(
					'label' => __('Instagram URL', 'emerald'),
					'type'  => 'url'
				),

				'pinterest' => array(
					'label' => __('Pinterest URL', 'emerald'),
					'type'  => 'url'
				),

				'youtube' => array(
					'label' => __('Youtube URL', 'emerald'),
					'type'  => 'url'
				),

				'feedburner' => array(
					'label' => __('Feedburner URL', 'emerald'),
					'type'  => 'url'
				)
			),

			'footer' => array(
				'footer_text' => array(
					'label'   => __('Footer Copyright Text', 'emerald'),
					'type'    => 'text',
					'default' => '&copy; ' . get_bloginfo('name')
				),

				'hide_credits' => array(
					'label' => __('Hide credit link?', 'emerald'),
					'type'  => 'checkbox'
				)
			)
		);

		return apply_filters('kanary_setting_fields', $setting_fields);
	}
}