<?php

/**
 * Blog Grow Theme Customizer
 *
 * @package Blog Grow
 */

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

// adctive call back function for header social
if (!function_exists('BLOG_GROW_header_social_callback')) :
	function BLOG_GROW_header_social_callback()
	{
		if (get_theme_mod('BLOG_GROW_header_social_show') == 1 && get_theme_mod('BLOG_GROW_headermiddle_show') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;
// adctive call back function for header social
if (!function_exists('BLOG_GROW_header_middle_callback')) :
	function BLOG_GROW_header_middle_callback()
	{
		if (get_theme_mod('BLOG_GROW_headermiddle_show') == 1) {
			return true;
		} else {
			return false;
		}
	}
endif;
// adctive call back function for header social
if (!function_exists('BLOG_GROW_menubar_callback')) :
	function BLOG_GROW_menubar_callback()
	{
		if (get_theme_mod('BLOG_GROW_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 BLOG_GROW_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 BLOG_GROW_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('BLOG_GROW_hide_tagline', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  ' ',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_hide_tagline', array(
		'label'      => __('Hide Site Tagline?', 'blog-grow'),
		'section'    => 'title_tagline',
		'settings'   => 'BLOG_GROW_hide_tagline',
		'type'       => 'checkbox',
	));

	$wp_customize->add_panel('BLOG_GROW_settings', array(
		'priority'       => 50,
		'title'          => __('Blog Grow Theme settings', 'blog-grow'),
		'description'    => __('All Blog Grow theme settings', 'blog-grow'),
	));
	$wp_customize->add_section('BLOG_GROW_header', array(
		'title' => __('Blog Grow Header Settings', 'blog-grow'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Blog Grow theme header settings', 'blog-grow'),
		'panel'    => 'BLOG_GROW_settings',

	));

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

	$wp_customize->add_setting('BLOG_GROW_latest_news', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_latest_news', array(
		'label'      => __('Show Latest News Ticker?', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_latest_news',
		'type'       => 'checkbox',
		'active_callback' => 'BLOG_GROW_header_top_calback',
	));
	$wp_customize->add_setting('BLOG_GROW_date_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_date_show', array(
		'label'      => __('Date Show?', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_date_show',
		'type'       => 'checkbox',
		'active_callback' => 'BLOG_GROW_header_top_calback',
	));

	$wp_customize->add_setting('BLOG_GROW_headermiddle_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_headermiddle_show', array(
		'label'      => __('Show Header Middle?', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_headermiddle_show',
		'type'       => 'checkbox',
	));
	$wp_customize->add_setting('BLOG_GROW_mlogo_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  '1',
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_mlogo_show', array(
		'label'      => __('Show Header Middle Logo?', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_mlogo_show',
		'type'       => 'checkbox',
		'active_callback' => 'BLOG_GROW_header_middle_callback',

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

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

	));
	// header social link start
	// Header facebook url
	$wp_customize->add_setting('BLOG_GROW_hfacebook_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_hfacebook_link', array(
		'label'      => __('Header Facebook url', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_hfacebook_link',
		'type'       => 'url',
		'active_callback' => 'BLOG_GROW_header_social_callback',
	));
	// Header twitter url
	$wp_customize->add_setting('BLOG_GROW_htwitter_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_htwitter_link', array(
		'label'      => __('Header Twitter url', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_htwitter_link',
		'type'       => 'url',
		'active_callback' => 'BLOG_GROW_header_social_callback',
	));
	// Header linkedin url
	$wp_customize->add_setting('BLOG_GROW_hlinkedin_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_hlinkedin_link', array(
		'label'      => __('Header Linkedin url', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_hlinkedin_link',
		'type'       => 'url',
		'active_callback' => 'BLOG_GROW_header_social_callback',
	));
	// Header linkedin url
	$wp_customize->add_setting('BLOG_GROW_hyoutube_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_hyoutube_link', array(
		'label'      => __('Header Youtube url', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_hyoutube_link',
		'type'       => 'url',
		'active_callback' => 'BLOG_GROW_header_social_callback',
	));
	// Header pinterest url
	$wp_customize->add_setting('BLOG_GROW_hpinterest_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_hpinterest_link', array(
		'label'      => __('Header Pinterest url', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_hpinterest_link',
		'type'       => 'url',
		'active_callback' => 'BLOG_GROW_header_social_callback',
	));
	// Header INSTAGRAM url
	$wp_customize->add_setting('BLOG_GROW_hinstagram_link', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'esc_url_raw',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_hinstagram_link', array(
		'label'      => __('Header Instagram url', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_hinstagram_link',
		'type'       => 'url',
		'active_callback' => 'BLOG_GROW_header_social_callback',
	));
	// Header Menu bar

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

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

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

	));
	$wp_customize->add_setting('BLOG_GROW_menusearch_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_menusearch_show', array(
		'label'      => __('Show Menubar Search Icon?', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_menusearch_show',
		'type'       => 'checkbox',
		'active_callback' => 'BLOG_GROW_menubar_callback',
	));
	$wp_customize->add_setting('BLOG_GROW_catmenu_show', array(
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'default'       =>  1,
		'sanitize_callback' => 'absint',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_catmenu_show', array(
		'label'      => __('Show Categories Menu?', 'blog-grow'),
		'section'    => 'BLOG_GROW_header',
		'settings'   => 'BLOG_GROW_catmenu_show',
		'type'       => 'checkbox',
	));



	//NewsBox PLus blog settings
	$wp_customize->add_section('BLOG_GROW_blog', array(
		'title' => __('Blog Grow Blog Settings', 'blog-grow'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Blog Grow theme blog settings', 'blog-grow'),
		'panel'    => 'BLOG_GROW_settings',

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

	$wp_customize->add_setting('BLOG_GROW_blog_layout', array(
		'default'        => 'rightside',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'BLOG_GROW_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_blog_layout', array(
		'label'      => __('Select Blog Layout', 'blog-grow'),
		'description' => __('Right and Left sidebar only show when sidebar widget is available. ', 'blog-grow'),
		'section'    => 'BLOG_GROW_blog',
		'settings'   => 'BLOG_GROW_blog_layout',
		'type'       => 'select',
		'choices'    => array(
			'rightside' => __('Right Sidebar', 'blog-grow'),
			'leftside' => __('Left Sidebar', 'blog-grow'),
			'fullwidth' => __('No Sidebar', 'blog-grow'),
		),
	));
	$wp_customize->add_setting('BLOG_GROW_blog_style', array(
		'default'        => 'grid',
		'capability'     => 'edit_theme_options',
		'type'           => 'theme_mod',
		'sanitize_callback' => 'BLOG_GROW_sanitize_select',
		'transport' => 'refresh',
	));
	$wp_customize->add_control('BLOG_GROW_blog_style', array(
		'label'      => __('Select Blog Style', 'blog-grow'),
		'section'    => 'BLOG_GROW_blog',
		'settings'   => 'BLOG_GROW_blog_style',
		'type'       => 'select',
		'choices'    => array(
			'grid' => __('Grid Style', 'blog-grow'),
			'list' => __('List Style', 'blog-grow'),
			'classic' => __('Classic Style', 'blog-grow'),
		),
	));
	//Blog Grow page settings
	$wp_customize->add_section('BLOG_GROW_page', array(
		'title' => __('Blog Grow Page Settings', 'blog-grow'),
		'capability'     => 'edit_theme_options',
		'description'     => __('Blog Grow theme blog settings', 'blog-grow'),
		'panel'    => 'BLOG_GROW_settings',

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




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

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

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

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