<?php

/**
 * Colorful Blog Theme Customizer
 *
 * @package Colorful Blog
 */


// adctive call back function for header social
if (!function_exists('colorful_blog_header_social_callback')) :
	function colorful_blog_header_social_callback()
	{
		if (get_theme_mod('colorful_blog_header_social_show') == 1 && get_theme_mod('colorful_blog_headertop_show') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;
// adctive call back function for header social
if (!function_exists('colorful_blog_header_top_callback')) :
	function colorful_blog_header_top_callback()
	{
		if (get_theme_mod('colorful_blog_headertop_show') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;
// adctive call back function for header social
if (!function_exists('colorful_blog_menubar_callback')) :
	function colorful_blog_menubar_callback()
	{
		if (get_theme_mod('colorful_blog_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 colorful_blog_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';

	//select sanitization function
	function colorful_blog_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('colorful_blog_hide_tagline', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  ' ',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_hide_tagline', array(
		'label'      => __('Hide Site Tagline?', 'colorful-blog'),
		'section'    => 'title_tagline',
		'settings'   => 'colorful_blog_hide_tagline',
		'type'       => 'checkbox',
	));

	$wp_customize->add_panel('colorful_blog_settings', array(
		'priority'       => 50,
		'title'          => __('Colorful Blog Theme settings', 'colorful-blog'),
		'description'    => __('All Colorful Blog theme settings', 'colorful-blog'),
	));
	$wp_customize->add_section('colorful_blog_header', array(
		'title' => __('Colorful Blog Header Settings', 'colorful-blog'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Colorful Blog theme header settings', 'colorful-blog'),
		'panel'    => 'colorful_blog_settings',

	));

	$wp_customize->add_setting('colorful_blog_headertop_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_headertop_show', array(
		'label'      => __('Show Header Top?', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_headertop_show',
		'type'       => 'checkbox',
	));
	$wp_customize->add_setting('colorful_blog_mlogo_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_mlogo_show', array(
		'label'      => __('Show Header Top Logo?', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_mlogo_show',
		'type'       => 'checkbox',
		'active_callback' => 'colorful_blog_header_top_callback',

	));
	$wp_customize->add_setting('colorful_blog_search_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_search_show', array(
		'label'      => __('Show Header Search?', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_search_show',
		'type'       => 'checkbox',
		'active_callback' => 'colorful_blog_header_top_callback',

	));
	$wp_customize->add_setting('colorful_blog_header_social_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_header_social_show', array(
		'label'      => __('Show Header Social?', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_header_social_show',
		'type'       => 'checkbox',
		'active_callback' => 'colorful_blog_header_top_callback',

	));
	// header social link start
	// Header facebook url
	$wp_customize->add_setting('colorful_blog_hfacebook_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_hfacebook_link', array(
		'label'      => __('Header Facebook url', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_hfacebook_link',
		'type'       => 'url',
		'active_callback' => 'colorful_blog_header_social_callback',
	));
	// Header twitter url
	$wp_customize->add_setting('colorful_blog_htwitter_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_htwitter_link', array(
		'label'      => __('Header Twitter url', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_htwitter_link',
		'type'       => 'url',
		'active_callback' => 'colorful_blog_header_social_callback',
	));
	// Header linkedin url
	$wp_customize->add_setting('colorful_blog_hlinkedin_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_hlinkedin_link', array(
		'label'      => __('Header Linkedin url', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_hlinkedin_link',
		'type'       => 'url',
		'active_callback' => 'colorful_blog_header_social_callback',
	));
	// Header linkedin url
	$wp_customize->add_setting('colorful_blog_hyoutube_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_hyoutube_link', array(
		'label'      => __('Header Youtube url', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_hyoutube_link',
		'type'       => 'url',
		'active_callback' => 'colorful_blog_header_social_callback',
	));
	// Header pinterest url
	$wp_customize->add_setting('colorful_blog_hpinterest_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_hpinterest_link', array(
		'label'      => __('Header Pinterest url', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_hpinterest_link',
		'type'       => 'url',
		'active_callback' => 'colorful_blog_header_social_callback',
	));
	// Header INSTAGRAM url
	$wp_customize->add_setting('colorful_blog_hinstagram_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_hinstagram_link', array(
		'label'      => __('Header Instagram url', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_hinstagram_link',
		'type'       => 'url',
		'active_callback' => 'colorful_blog_header_social_callback',
	));
	// Header Menu bar

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

	$wp_customize->add_setting('colorful_blog_menubarlogo_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_menubarlogo_show', array(
		'label'      => __('Show Menubar Logo?', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_menubarlogo_show',
		'type'       => 'checkbox',
		'active_callback' => 'colorful_blog_menubar_callback',

	));
	$wp_customize->add_setting('colorful_blog_mainmenu_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_mainmenu_show', array(
		'label'      => __('Show Main Menu?', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_mainmenu_show',
		'type'       => 'checkbox',
		'active_callback' => 'colorful_blog_menubar_callback',

	));
	$wp_customize->add_setting('colorful_blog_menusearch_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_menusearch_show', array(
		'label'      => __('Show Menubar Search Icon?', 'colorful-blog'),
		'section'    => 'colorful_blog_header',
		'settings'   => 'colorful_blog_menusearch_show',
		'type'       => 'checkbox',
		'active_callback' => 'colorful_blog_menubar_callback',
	));



	//NewsBox PLus blog settings
	$wp_customize->add_section('colorful_blog_blog', array(
		'title' => __('Colorful Blog Blog Settings', 'colorful-blog'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Colorful Blog theme blog settings', 'colorful-blog'),
		'panel'    => 'colorful_blog_settings',

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

	$wp_customize->add_setting('colorful_blog_blog_layout', array(
		'default'        => 'rightside',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'colorful_blog_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_blog_layout', array(
		'label'      => __('Select Blog Layout', 'colorful-blog'),
		'description' => __('Right and Left sidebar only show when sidebar widget is available. ', 'colorful-blog'),
		'section'    => 'colorful_blog_blog',
		'settings'   => 'colorful_blog_blog_layout',
		'type'       => 'select',
		'choices'    => array(
			'rightside' => __('Right Sidebar', 'colorful-blog'),
			'leftside' => __('Left Sidebar', 'colorful-blog'),
			'fullwidth' => __('No Sidebar', 'colorful-blog'),
		),
	));
	$wp_customize->add_setting('colorful_blog_blog_style', array(
		'default'        => 'grid',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'colorful_blog_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('colorful_blog_blog_style', array(
		'label'      => __('Select Blog Style', 'colorful-blog'),
		'section'    => 'colorful_blog_blog',
		'settings'   => 'colorful_blog_blog_style',
		'type'       => 'select',
		'choices'    => array(
			'grid' => __('Grid Style', 'colorful-blog'),
			'list' => __('List Style', 'colorful-blog'),
			'classic' => __('Classic Style', 'colorful-blog'),
		),
	));
	//Colorful Blog page settings
	$wp_customize->add_section('colorful_blog_page', array(
		'title' => __('Colorful Blog Page Settings', 'colorful-blog'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Colorful Blog theme blog settings', 'colorful-blog'),
		'panel'    => 'colorful_blog_settings',

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




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

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

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

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