<?php
/**
 * Travel Blogz Theme Customizer
 *
 * @package Travel Blogz
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function travel_blogz_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';

	$travel_blogz_options = travel_blogz_theme_options();

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'travel_blogz_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'travel_blogz_customize_partial_blogdescription',
			)
		);
	}

	$wp_customize->add_panel(
        'theme_options',
        array(
            'title' => esc_html__('Home Page Options', 'travel-blogz'),
            'priority' => 2,
        )
    );



//Social Links
    $wp_customize->add_section(
    'social_section',
	    array(
	        'title' => esc_html__( 'Social Links','travel-blogz' ),
		     'description' => esc_html__( 'More Social Links are available in Premium Version','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);
	$wp_customize->add_setting('travel_blogz_theme_options[fb_url]',
	    array(
	        'type' => 'option',
	        'default' => $travel_blogz_options['fb_url'],
	        'sanitize_callback' => 'travel_blogz_sanitize_url',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[fb_url]',
	    array(
	        'label' => esc_html__('Facebook Link', 'travel-blogz'),
	        'type' => 'text',
	        'section' => 'social_section',
	        'settings' => 'travel_blogz_theme_options[fb_url]',
	    )
	);
		$wp_customize->add_setting('travel_blogz_theme_options[insta_url]',
	    array(
	        'type' => 'option',
	        'default' => $travel_blogz_options['insta_url'],
	        'sanitize_callback' => 'travel_blogz_sanitize_url',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[insta_url]',
	    array(
	        'label' => esc_html__('Instagram Link', 'travel-blogz'),
	        'type' => 'text',
	        'section' => 'social_section',
	        'settings' => 'travel_blogz_theme_options[insta_url]',
	    )
	);
		$wp_customize->add_setting('travel_blogz_theme_options[twitter_url]',
	    array(
	        'type' => 'option',
	        'default' => $travel_blogz_options['twitter_url'],
	        'sanitize_callback' => 'travel_blogz_sanitize_url',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[twitter_url]',
	    array(
	        'label' => esc_html__('Twiiter X Link', 'travel-blogz'),
	        'type' => 'text',
	        'section' => 'social_section',
	        'settings' => 'travel_blogz_theme_options[twitter_url]',
	    )
	);


    $wp_customize->add_section(
    'article_section',
	    array(
	        'title' => esc_html__( 'Single Article/Blog Page','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[sidebar_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['sidebar_show'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[sidebar_show]',
	    array(
	        'label' => esc_html__('Show Sidebar in Single Article?', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'section' => 'article_section',

	    )
	);



//Header Section
    $wp_customize->add_section(
    'header_section',
	    array(
	        'title' => esc_html__( 'Header Section','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);


       $wp_customize->add_setting( 'travel_blogz_theme_options[header_layout]', array(
          'capability' => 'edit_theme_options',
          'default' => 'header1',
          'sanitize_callback' => 'travel_blogz_sanitize_radio',
          'type' => 'option',
    ) );

    $wp_customize->add_control( 'travel_blogz_theme_options[header_layout]', array(
          'type' => 'radio',
          'section' => 'header_section', // Add a default or your own section
          'label' => esc_attr( __('Choose Header Layout', 'travel-blogz') ),
          'choices' => array(
            'header1' => esc_attr( __('Default Header', 'travel-blogz') ),
            'header2' => esc_attr( __('Centered Layout', 'travel-blogz') ),
            'header3' => esc_attr( __('Bottom Menu Layout', 'travel-blogz') ),
          ),
    ) );


	$wp_customize->add_setting('travel_blogz_theme_options[dark_header]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['dark_header'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[dark_header]',
	    array(
	        'label' => esc_html__('Dark Header?', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'section' => 'header_section',

	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[header_full_width]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['header_full_width'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[header_full_width]',
	    array(
	        'label' => esc_html__('Full Width?', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'section' => 'header_section',

	    )
	);


//Banner section
    $wp_customize->add_section(
    'banner_section',
	    array(
	        'title' => esc_html__( 'Banner Section','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[banner_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['banner_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[banner_title]',
	    array(
	        'label' => esc_html__('Banner Title', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'banner_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[banner_sub_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['banner_sub_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[banner_sub_title]',
	    array(
	        'label' => esc_html__('Banner Sub Title', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'banner_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[banner_image]',
	array(
	    'type' => 'option',
	    'sanitize_callback' => 'esc_url_raw',
	)
	);
	$wp_customize->add_control(
	new WP_Customize_Image_Control(
	    $wp_customize,
	    'travel_blogz_theme_options[banner_image]',
	    array(
	        'label' => esc_html__('Add Background Image', 'travel-blogz'),
	        'section' => 'banner_section',
	        'settings' => 'travel_blogz_theme_options[banner_image]',
	    ))
	);

$wp_customize->add_setting(
    'travel_blogz_theme_options[banner_blog_category]',
    [
        'type' => 'option',
        'sanitize_callback' => 'travel_blogz_sanitize_select',
        'default' => $travel_blogz_options['banner_blog_category'],
    ]
);

$wp_customize->add_control(
    'travel_blogz_theme_options[banner_blog_category]',
    [
        'section' => 'banner_section',
        'type' => 'select',
        'choices' => travel_blogz_get_categories_select(),
        'label' => esc_html__('Select Post Category', 'travel-blogz'),
        'description' => esc_html__(
            'Max 4 Posts will be shown from the selected Category and no carousel in Free Version ',
            'travel-blogz'
        ),
        'settings' => 'travel_blogz_theme_options[banner_blog_category]',
    ]
);



    //Blog section
	$wp_customize->add_section(
    'blog_section',
	    array(
	        'title' => esc_html__( 'Recent Blog Section','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[blog_sec_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['blog_sec_show'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[blog_sec_show]',
	    array(
	        'label' => esc_html__('Show Recent Blog Section', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'section' => 'blog_section',

	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[blog_sec_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['blog_sec_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[blog_sec_title]',
	    array(
	        'label' => esc_html__('Blog Section Title', 'travel-blogz'),
	        'section' => 'blog_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[blog_post_no]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['blog_post_no'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[blog_post_no]',
	    array(
	        'label' => esc_html__('No Of Blog Posts to show?', 'travel-blogz'),
	        'section' => 'blog_section',
	        'type' => 'text',
	    )
	);



    //About section
	$wp_customize->add_section(
    'about_section',
	    array(
	        'title' => esc_html__( 'About Section','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[about_sec_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['about_sec_show'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[about_sec_show]',
	    array(
	        'label' => esc_html__('Show About Section', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'priority' => 1,
	        'section' => 'about_section',

	    )
	);


	$wp_customize->add_setting('travel_blogz_theme_options[about_sec_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['about_sec_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[about_sec_title]',
	    array(
	        'label' => esc_html__('About Title', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'about_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[about_sec_description]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['about_sec_description'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[about_sec_description]',
	    array(
	        'label' => esc_html__('About Description', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'about_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[about_btn_text]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['about_btn_text'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[about_btn_text]',
	    array(
	        'label' => esc_html__('About Button Text', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'about_section',
	        'type' => 'text',
	    )
	);
	$wp_customize->add_setting('travel_blogz_theme_options[about_button_url]',
	    array(
	        'type' => 'option',
	        'default' => $travel_blogz_options['about_button_url'],
	        'sanitize_callback' => 'travel_blogz_sanitize_url',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[about_button_url]',
	    array(
	        'label' => esc_html__('About Button Link', 'travel-blogz'),
	        'type' => 'text',
	        'section' => 'about_section',
	        'settings' => 'travel_blogz_theme_options[about_button_url]',
	    )
	);


	$wp_customize->add_setting('travel_blogz_theme_options[about_front_image]',
	array(
	    'type' => 'option',
	    'sanitize_callback' => 'esc_url_raw',
	)
	);
	$wp_customize->add_control(
	new WP_Customize_Image_Control(
	    $wp_customize,
	    'travel_blogz_theme_options[about_front_image]',
	    array(
	        'label' => esc_html__('Add About Image', 'travel-blogz'),
	        'section' => 'about_section',
	        'settings' => 'travel_blogz_theme_options[about_front_image]',
	    ))
	);



   //Blog section
	$wp_customize->add_section(
    'bottomblog_section',
	    array(
	        'title' => esc_html__( 'Bottom Blog Section','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[bottomblog_sec_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['bottomblog_sec_show'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[bottomblog_sec_show]',
	    array(
	        'label' => esc_html__('Show Bottom Blog Section', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'section' => 'bottomblog_section',

	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[bottomblog_sec_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['bottomblog_sec_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[bottomblog_sec_title]',
	    array(
	        'label' => esc_html__('Blog Section Title', 'travel-blogz'),
	        'section' => 'bottomblog_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[bottomblog_post_no]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['bottomblog_post_no'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[bottomblog_post_no]',
	    array(
	        'label' => esc_html__('No Of Blog Posts to show?', 'travel-blogz'),
	        'section' => 'bottomblog_section',
	        'type' => 'text',
	    )
	);
$wp_customize->add_setting(
    'travel_blogz_theme_options[bottomblog_category]',
    [
        'type' => 'option',
        'sanitize_callback' => 'travel_blogz_sanitize_select',
        'default' => $travel_blogz_options['bottomblog_category'],
    ]
);

$wp_customize->add_control(
    'travel_blogz_theme_options[bottomblog_category]',
    [
        'section' => 'bottomblog_section',
        'type' => 'select',
        'choices' => travel_blogz_get_categories_select(),
        'label' => esc_html__('Select Post Category', 'travel-blogz'),
        'description' => esc_html__(
            'Max 6 Posts will be shown from the selected Category in Free Version ',
            'travel-blogz'
        ),
        'settings' => 'travel_blogz_theme_options[bottomblog_category]',
    ]
);


    //CTA section
	$wp_customize->add_section(
    'newsletter_section',
	    array(
	        'title' => esc_html__( 'Newsletter Section','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[newsletter_sec_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['newsletter_sec_show'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[newsletter_sec_show]',
	    array(
	        'label' => esc_html__('Show Newsletter Section', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'priority' => 1,
	        'section' => 'newsletter_section',

	    )
	);


	$wp_customize->add_setting('travel_blogz_theme_options[newsletter_sec_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['newsletter_sec_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[newsletter_sec_title]',
	    array(
	        'label' => esc_html__('Newsletter Title', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'newsletter_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[newsletter_description]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['newsletter_description'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[newsletter_description]',
	    array(
	        'label' => esc_html__('Newsletter Description', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'newsletter_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[newsletter_shortcode]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $travel_blogz_options['newsletter_shortcode'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('travel_blogz_theme_options[newsletter_shortcode]',
	    array(
	        'label' => esc_html__('Newsletter Shortcode', 'travel-blogz'),
	        'priority' => 1,
	        'section' => 'newsletter_section',
	        'type' => 'text',
	    )
	);
	$wp_customize->add_setting('travel_blogz_theme_options[newsletter_image]',
	array(
	    'type' => 'option',
	    'sanitize_callback' => 'esc_url_raw',
	)
	);
	$wp_customize->add_control(
	new WP_Customize_Image_Control(
	    $wp_customize,
	    'travel_blogz_theme_options[newsletter_image]',
	    array(
	        'label' => esc_html__('Add Background Image', 'travel-blogz'),
	        'section' => 'newsletter_section',
	        'settings' => 'travel_blogz_theme_options[newsletter_image]',
	    ))
	);



	$wp_customize->add_section(
    'footer_section',
	    array(
	        'title' => esc_html__( 'Footer Option','travel-blogz' ),
	       	'description' => esc_html__( 'Copyright text can be changed in Premium Version','travel-blogz' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('travel_blogz_theme_options[show_widgets]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $travel_blogz_options['show_widgets'],
	        'sanitize_callback' => 'travel_blogz_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('travel_blogz_theme_options[show_widgets]',
	    array(
	        'label' => esc_html__('Show Widgets', 'travel-blogz'),
	        'type' => 'Checkbox',
	        'priority' => 1,
	        'section' => 'footer_section',

	    )
	);


}
add_action( 'customize_register', 'travel_blogz_customize_register' );

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

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

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function travel_blogz_customize_preview_js() {
	wp_enqueue_script( 'travel-blogz-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), _S_VERSION, true );
}
add_action( 'customize_preview_init', 'travel_blogz_customize_preview_js' );
