<?php

/**
 * Affiliate Eye Theme Customizer
 *
 * @package Affiliate Eye
 */

//calback functon for topbar header
if (!function_exists('affiliate_eye_header_top_calback')) :
	function affiliate_eye_header_top_calback()
	{
		if (get_theme_mod('affiliate_eye_header_top') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;

// adctive call back function for header social
if (!function_exists('affiliate_eye_header_social_callback')) :
	function affiliate_eye_header_social_callback()
	{
		if (get_theme_mod('affiliate_eye_header_social_show') == 1 && get_theme_mod('affiliate_eye_headermiddle_show') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;
// adctive call back function for header social
if (!function_exists('affiliate_eye_header_middle_callback')) :
	function affiliate_eye_header_middle_callback()
	{
		if (get_theme_mod('affiliate_eye_headermiddle_show') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;
// adctive call back function for header social
if (!function_exists('affiliate_eye_menubar_callback')) :
	function affiliate_eye_menubar_callback()
	{
		if (get_theme_mod('affiliate_eye_menubar_show') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */

function affiliate_eye_customize_register($wp_customize)
{
	$wp_customize->get_setting('blogname')->transport         = 'postMessage';
	$wp_customize->get_setting('blogdescription')->transport  = 'postMessage';
	$wp_customize->get_setting('header_textcolor')->transport = 'postMessage';

	$theme = wp_get_theme();
	$affiliate_eye_textdomain = $theme->get('TextDomain');

	if ($affiliate_eye_textdomain == 'affiliate-eye') {
		$affiliate_eye_default1 = '';
		$affiliate_eye_default2 = 1;
	} else {
		$affiliate_eye_default1 = 1;
		$affiliate_eye_default2 = '';
	}

	//select sanitization function
	function affiliate_eye_sanitize_select($input, $setting)
	{
		$input = sanitize_key($input);
		$choices = $setting->manager->get_control($setting->id)->choices;
		return (array_key_exists($input, $choices) ? $input : $setting->default);
	}
	$wp_customize->add_setting('affiliate_eye_hide_tagline', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_hide_tagline', array(
		'label'      => __('Hide Site Tagline?', 'affiliate-eye'),
		'section'    => 'title_tagline',
		'settings'   => 'affiliate_eye_hide_tagline',
		'type'       => 'checkbox',
	));

	$wp_customize->add_panel('affiliate_eye_settings', array(
		'priority'       => 50,
		'title'          => __('Affiliate Eye Theme settings', 'affiliate-eye'),
		'description'    => __('All Affiliate Eye theme settings', 'affiliate-eye'),
	));
	$wp_customize->add_section('affiliate_eye_header', array(
		'title' => __('Affiliate Eye Header Settings', 'affiliate-eye'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Affiliate Eye theme header settings', 'affiliate-eye'),
		'panel'    => 'affiliate_eye_settings',

	));

	$wp_customize->add_setting('affiliate_eye_header_top', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_header_top', array(
		'label'      => __('Show Header Area Top?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_header_top',
		'type'       => 'checkbox',
	));

	$wp_customize->add_setting('affiliate_eye_latest_news', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_latest_news', array(
		'label'      => __('Show Latest News Ticker?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_latest_news',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_header_top_calback',
	));
	$wp_customize->add_setting('affiliate_eye_date_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_date_show', array(
		'label'      => __('Date Show?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_date_show',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_header_top_calback',
	));

	$wp_customize->add_setting('affiliate_eye_headermiddle_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  $affiliate_eye_default1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_headermiddle_show', array(
		'label'      => __('Show Header Middle?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_headermiddle_show',
		'type'       => 'checkbox',
	));
	$wp_customize->add_setting('affiliate_eye_mlogo_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_mlogo_show', array(
		'label'      => __('Show Header Middle Logo?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_mlogo_show',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_header_middle_callback',

	));
	$wp_customize->add_setting('affiliate_eye_search_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_search_show', array(
		'label'      => __('Show Header Search?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_search_show',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_header_middle_callback',

	));
	$wp_customize->add_setting('affiliate_eye_header_social_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  $affiliate_eye_default2,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_header_social_show', array(
		'label'      => __('Show Header Social?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_header_social_show',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_header_middle_callback',

	));
	// header social link start
	// Header facebook url
	$wp_customize->add_setting('affiliate_eye_hfacebook_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_hfacebook_link', array(
		'label'      => __('Header Facebook url', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_hfacebook_link',
		'type'       => 'url',
		'active_callback' => 'affiliate_eye_header_social_callback',
	));
	// Header twitter url
	$wp_customize->add_setting('affiliate_eye_htwitter_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_htwitter_link', array(
		'label'      => __('Header Twitter url', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_htwitter_link',
		'type'       => 'url',
		'active_callback' => 'affiliate_eye_header_social_callback',
	));
	// Header linkedin url
	$wp_customize->add_setting('affiliate_eye_hlinkedin_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_hlinkedin_link', array(
		'label'      => __('Header Linkedin url', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_hlinkedin_link',
		'type'       => 'url',
		'active_callback' => 'affiliate_eye_header_social_callback',
	));
	// Header linkedin url
	$wp_customize->add_setting('affiliate_eye_hyoutube_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_hyoutube_link', array(
		'label'      => __('Header Youtube url', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_hyoutube_link',
		'type'       => 'url',
		'active_callback' => 'affiliate_eye_header_social_callback',
	));
	// Header pinterest url
	$wp_customize->add_setting('affiliate_eye_hpinterest_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_hpinterest_link', array(
		'label'      => __('Header Pinterest url', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_hpinterest_link',
		'type'       => 'url',
		'active_callback' => 'affiliate_eye_header_social_callback',
	));
	// Header INSTAGRAM url
	$wp_customize->add_setting('affiliate_eye_hinstagram_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_hinstagram_link', array(
		'label'      => __('Header Instagram url', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_hinstagram_link',
		'type'       => 'url',
		'active_callback' => 'affiliate_eye_header_social_callback',
	));
	// Header Menu bar

	$wp_customize->add_setting('affiliate_eye_menubar_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_menubar_show', array(
		'label'      => __('Show Menubar Section?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_menubar_show',
		'type'       => 'checkbox',
	));

	$wp_customize->add_setting('affiliate_eye_menubarlogo_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_menubarlogo_show', array(
		'label'      => __('Show Menubar Logo?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_menubarlogo_show',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_menubar_callback',

	));
	$wp_customize->add_setting('affiliate_eye_mainmenu_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_mainmenu_show', array(
		'label'      => __('Show Main Menu?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_mainmenu_show',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_menubar_callback',

	));
	$wp_customize->add_setting('affiliate_eye_menusearch_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_menusearch_show', array(
		'label'      => __('Show Menubar Search Icon?', 'affiliate-eye'),
		'section'    => 'affiliate_eye_header',
		'settings'   => 'affiliate_eye_menusearch_show',
		'type'       => 'checkbox',
		'active_callback' => 'affiliate_eye_menubar_callback',
	));



	//NewsBox PLus blog settings
	$wp_customize->add_section('affiliate_eye_blog', array(
		'title' => __('Affiliate Eye Blog Settings', 'affiliate-eye'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Affiliate Eye theme blog settings', 'affiliate-eye'),
		'panel'    => 'affiliate_eye_settings',

	));
	$wp_customize->add_setting('affiliate_eye_blog_container', array(
		'default'        => 'container',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'affiliate_eye_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_blog_container', array(
		'label'      => __('Container type', 'affiliate-eye'),
		'description' => __('You can set standard container or full width container. ', 'affiliate-eye'),
		'section'    => 'affiliate_eye_blog',
		'settings'   => 'affiliate_eye_blog_container',
		'type'       => 'select',
		'choices'    => array(
			'container' => __('Standard Container', 'affiliate-eye'),
			'container-fluid' => __('Full width Container', 'affiliate-eye'),
		),
	));

	$wp_customize->add_setting('affiliate_eye_blog_layout', array(
		'default'        => 'rightside',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'affiliate_eye_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_blog_layout', array(
		'label'      => __('Select Blog Layout', 'affiliate-eye'),
		'description' => __('Right and Left sidebar only show when sidebar widget is available. ', 'affiliate-eye'),
		'section'    => 'affiliate_eye_blog',
		'settings'   => 'affiliate_eye_blog_layout',
		'type'       => 'select',
		'choices'    => array(
			'rightside' => __('Right Sidebar', 'affiliate-eye'),
			'leftside' => __('Left Sidebar', 'affiliate-eye'),
			'fullwidth' => __('No Sidebar', 'affiliate-eye'),
		),
	));
	$wp_customize->add_setting('affiliate_eye_blog_style', array(
		'default'        => 'grid',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'affiliate_eye_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_blog_style', array(
		'label'      => __('Select Blog Style', 'affiliate-eye'),
		'section'    => 'affiliate_eye_blog',
		'settings'   => 'affiliate_eye_blog_style',
		'type'       => 'select',
		'choices'    => array(
			'grid' => __('Grid Style', 'affiliate-eye'),
			'list' => __('List Style', 'affiliate-eye'),
			'classic' => __('Classic Style', 'affiliate-eye'),
		),
	));
	//Affiliate Eye page settings
	$wp_customize->add_section('affiliate_eye_page', array(
		'title' => __('Affiliate Eye Page Settings', 'affiliate-eye'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Affiliate Eye theme blog settings', 'affiliate-eye'),
		'panel'    => 'affiliate_eye_settings',

	));
	$wp_customize->add_setting('affiliate_eye_page_container', array(
		'default'        => 'container',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'affiliate_eye_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_page_container', array(
		'label'      => __('Page Container type', 'affiliate-eye'),
		'description' => __('You can set standard container or full width container for page. ', 'affiliate-eye'),
		'section'    => 'affiliate_eye_page',
		'settings'   => 'affiliate_eye_page_container',
		'type'       => 'select',
		'choices'    => array(
			'container' => __('Standard Container', 'affiliate-eye'),
			'container-fluid' => __('Full width Container', 'affiliate-eye'),
		),
	));
	$wp_customize->add_setting('affiliate_eye_page_header', array(
		'default'        => 'show',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'affiliate_eye_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('affiliate_eye_page_header', array(
		'label'      => __('Show Page header', 'affiliate-eye'),
		'section'    => 'affiliate_eye_page',
		'settings'   => 'affiliate_eye_page_header',
		'type'       => 'select',
		'choices'    => array(
			'show' => __('Show all pages', 'affiliate-eye'),
			'hide-home' => __('Hide Only Front Page', 'affiliate-eye'),
			'hide' => __('Hide All Pages', 'affiliate-eye'),
		),
	));




	if (isset($wp_customize->selective_refresh)) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'affiliate_eye_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'affiliate_eye_customize_partial_blogdescription',
			)
		);
	}
}
add_action('customize_register', 'affiliate_eye_customize_register');

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function affiliate_eye_customize_partial_blogname()
{
	bloginfo('name');
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function affiliate_eye_customize_partial_blogdescription()
{
	bloginfo('description');
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function affiliate_eye_customize_preview_js()
{
	wp_enqueue_script('affiliate-eye-customizer', get_template_directory_uri() . '/assets/js/customizer.js', array('customize-preview'), AFFILIATE_EYE_VERSION, true);
}
add_action('customize_preview_init', 'affiliate_eye_customize_preview_js');
