<?php
/**
 * Podcast Guru Theme Customizer
 *
 * @package podcast_guru
 */

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

	$podcast_guru_options = podcast_guru_theme_options();

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


    $wp_customize->add_setting('podcast_guru_theme_options[site_title_show]',
        array(
            'type' => 'option',
            'default'        => true,
            'default' => $podcast_guru_options['site_title_show'],
            'sanitize_callback' => 'podcast_guru_sanitize_checkbox',
        )
    );

    $wp_customize->add_control('podcast_guru_theme_options[site_title_show]',
        array(
            'label' => esc_html__('Show Title & Tagline', 'podcast-guru'),
            'type' => 'Checkbox',
            'section' => 'title_tagline',

        )
    );
    

    $wp_customize->add_panel(
        'theme_options',
        array(
            'title' => esc_html__('Theme Options', 'podcast-guru'),
            'priority' => 2,
        )
    );



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

	$wp_customize->add_setting('podcast_guru_theme_options[facebook]',
	    array(
	        'type' => 'option',
	        'default' => $podcast_guru_options['facebook'],
	        'sanitize_callback' => 'podcast_guru_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcast_guru_theme_options[facebook]',
	    array(
	        'label' => esc_html__('Facebook Link', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'header_section',
	        'settings' => 'podcast_guru_theme_options[facebook]',
	    )
	);


	$wp_customize->add_setting('podcast_guru_theme_options[twitter]',
	    array(
	        'type' => 'option',
	        'default' => $podcast_guru_options['twitter'],
	        'sanitize_callback' => 'podcast_guru_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcast_guru_theme_options[twitter]',
	    array(
	        'label' => esc_html__('Twitter Link', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'header_section',
	        'settings' => 'podcast_guru_theme_options[twitter]',
	    )
	);



    /* Banner Section */

    $wp_customize->add_section(
        'banner_section',
        array(
            'title' => esc_html__( 'Banner Section','podcast-guru' ),
            'panel'=>'theme_options',
            'capability'=>'edit_theme_options',
        )
    );




	$wp_customize->add_setting('podcast_guru_theme_options[banner_title]',
	    array(
	        'type' => 'option',
	        'sanitize_callback' => 'sanitize_text_field',
	    )
	);
	$wp_customize->add_control('banner_title',
	    array(
	        'label' => esc_html__('Title', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'banner_section',
	        'settings' => 'podcast_guru_theme_options[banner_title]',
	    )
	);
	$wp_customize->add_setting('podcast_guru_theme_options[banner_desc]',
    array(
        'type' => 'option',
        'sanitize_callback' => 'sanitize_text_field',
    )
);
$wp_customize->add_control('banner_desc',
    array(
        'label' => esc_html__('Banner Description', 'podcast-guru'),
        'type' => 'text',
        'section' => 'banner_section',
        'settings' => 'podcast_guru_theme_options[banner_desc]',
    )
);
	$wp_customize->add_setting('podcast_guru_theme_options[single_button]',
	array(
		'type' => 'option',
		'sanitize_callback' => 'sanitize_text_field',
	)
	);
	$wp_customize->add_control('single_button',
	array(
		'label' => esc_html__('Button Text', 'podcast-guru'),
		'type' => 'text',
		'section' => 'banner_section',
		'settings' => 'podcast_guru_theme_options[single_button]',
	)
	);
	
	$wp_customize->add_setting('podcast_guru_theme_options[single_button_url]',
	array(
		'type' => 'option',
		'default' => $podcast_guru_options['single_button_url'],
		'sanitize_callback' => 'podcast_guru_sanitize_url',
	)
	);
	$wp_customize->add_control('podcast_guru_theme_options[single_button_url]',
	array(
		'label' => esc_html__('Button Link', 'podcast-guru'),
		'type' => 'text',
		'section' => 'banner_section',
		'settings' => 'podcast_guru_theme_options[single_button_url]',
	)
	);
	$wp_customize->add_setting('podcast_guru_theme_options[spotify_button_url]',
    array(
        'type' => 'option',
        'default' => $podcast_guru_options['spotify_button_url'],
        'sanitize_callback' => 'podcast_guru_sanitize_url',
    )
);
$wp_customize->add_control('podcast_guru_theme_options[spotify_button_url]',
    array(
        'label' => esc_html__('Spotify Link', 'podcast-guru'),
        'type' => 'text',
        'section' => 'banner_section',
        'settings' => 'podcast_guru_theme_options[spotify_button_url]',
    )
);


$wp_customize->add_setting('podcast_guru_theme_options[itunes_button_url]',
    array(
        'type' => 'option',
        'default' => $podcast_guru_options['itunes_button_url'],
        'sanitize_callback' => 'podcast_guru_sanitize_url',
    )
);
$wp_customize->add_control('podcast_guru_theme_options[itunes_button_url]',
    array(
        'label' => esc_html__('iTunes Link', 'podcast-guru'),
        'type' => 'text',
        'section' => 'banner_section',
        'settings' => 'podcast_guru_theme_options[itunes_button_url]',
    )
);

$wp_customize->add_setting('podcast_guru_theme_options[pocketcasts_button_url]',
    array(
        'type' => 'option',
        'default' => $podcast_guru_options['pocketcasts_button_url'],
        'sanitize_callback' => 'podcast_guru_sanitize_url',
    )
);
$wp_customize->add_control('podcast_guru_theme_options[pocketcasts_button_url]',
    array(
        'label' => esc_html__('Pocket Casts Link', 'podcast-guru'),
        'type' => 'text',
        'section' => 'banner_section',
        'settings' => 'podcast_guru_theme_options[pocketcasts_button_url]',
    )
);


	$wp_customize->add_setting('podcast_guru_theme_options[banner_bg_image]',
	    array(
	        'type' => 'option',
	        'sanitize_callback' => 'esc_url_raw',
	    )
	);
	$wp_customize->add_control(
	    new WP_Customize_Image_Control(
	        $wp_customize,
	        'podcast_guru_theme_options[banner_bg_image]',
	        array(
	            'label' => esc_html__('Add Background Image', 'podcast-guru'),
	            'section' => 'banner_section',
	            'settings' => 'podcast_guru_theme_options[banner_bg_image]',
	        ))
	);



	/* album Section*/




	$wp_customize->add_section('podcast_episode_section', [
		'title' => esc_html__('Podcast Episode Section ', 'podcast-guru'),
		'panel' => 'theme_options',
		'capability' => 'edit_theme_options',
	]);
	
	
	$wp_customize->add_setting(
		'podcast_guru_theme_options[episode_section_show]',
		[
			'type' => 'option',
			'default' => true,
			'default' => $podcast_guru_options['episode_section_show'],
			'sanitize_callback' => 'podcast_guru_sanitize_checkbox',
		]
	);
	
	$wp_customize->add_control(
		'podcast_guru_theme_options[episode_section_show]',
		[
			'label' => esc_html__('Show Section', 'podcast-guru'),
			'type' => 'Checkbox',
			'priority' => 1,
			'section' => 'podcast_episode_section',
		]
	);
	$wp_customize->add_setting('podcast_guru_theme_options[episode_title]',
	array(
		'capability' => 'edit_theme_options',
		'default' => $podcast_guru_options['episode_title'],
		'sanitize_callback' => 'sanitize_text_field',
		'type' => 'option',
	)
	);
	$wp_customize->add_control('podcast_guru_theme_options[episode_title]',
	array(
		'label' => esc_html__('Section Title', 'podcast-guru'),
		'priority' => 1,
		'section' => 'podcast_episode_section',
		'type' => 'text',
	)
	);
	$wp_customize->add_setting('podcast_guru_theme_options[episode_desc]',
	array(
		'default' => $podcast_guru_options['episode_desc'],
		'type' => 'option',
		'sanitize_callback' => 'sanitize_text_field'
	)
	);
	
	$wp_customize->add_control('podcast_guru_theme_options[episode_desc]',
	array(
		'label' => esc_html__('Episode Section Description', 'podcast-guru'),
		'type' => 'text',
		'section' => 'podcast_episode_section',
		'settings' => 'podcast_guru_theme_options[episode_desc]',
	)
	);
	







    $wp_customize->add_section(
        'video_section',
        array(
            'title' => esc_html__( 'About Section','podcast-guru' ),
            'panel'=>'theme_options',
            'capability'=>'edit_theme_options',
        )
    );


    $wp_customize->add_setting('podcast_guru_theme_options[about_show]',
        array(
            'type' => 'option',
            'default'        => true,
            'default' => $podcast_guru_options['about_show'],
            'sanitize_callback' => 'podcast_guru_sanitize_checkbox',
        )
    );

    $wp_customize->add_control('podcast_guru_theme_options[about_show]',
        array(
            'label' => esc_html__('Show About Section', 'podcast-guru'),
            'type' => 'Checkbox',
            'priority' => 1,
            'section' => 'video_section',

        )
    );
	$wp_customize->add_setting('podcast_guru_theme_options[about_title]',
	    array(
	        'type' => 'option',
	        'sanitize_callback' => 'sanitize_text_field',
	    )
	);
	$wp_customize->add_control('about_title',
	    array(
	        'label' => esc_html__('About Title', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'video_section',
	        'settings' => 'podcast_guru_theme_options[about_title]',
	    )
	);

	$wp_customize->add_setting('podcast_guru_theme_options[about_desc]',
	    array(
	        'type' => 'option',
	        'sanitize_callback' => 'sanitize_text_field',
	    )
	);
	$wp_customize->add_control('about_desc',
	    array(
	        'label' => esc_html__('About Description', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'video_section',
	        'settings' => 'podcast_guru_theme_options[about_desc]',
	    )
	);


	$wp_customize->add_setting('podcast_guru_theme_options[video_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcast_guru_options['video_url'],
	        'sanitize_callback' => 'podcast_guru_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcast_guru_theme_options[video_url]',
	    array(
	        'label' => esc_html__('Video Link', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'video_section',
	        'settings' => 'podcast_guru_theme_options[video_url]',
	    )
	);


	$wp_customize->add_setting('podcast_guru_theme_options[video_bg_image]',
	    array(
	        'type' => 'option',
	        'sanitize_callback' => 'esc_url_raw',
	    )
	);
	$wp_customize->add_control(
	    new WP_Customize_Image_Control(
	        $wp_customize,
	        'podcast_guru_theme_options[video_bg_image]',
	        array(
	            'label' => esc_html__('Add Image', 'podcast-guru'),
	            'section' => 'video_section',
	            'settings' => 'podcast_guru_theme_options[video_bg_image]',
	        ))
	);
	$wp_customize->add_setting('podcast_guru_theme_options[video_button_txt]',
	    array(
	        'type' => 'option',
	        'default' => $podcast_guru_options['video_button_txt'],
	        'sanitize_callback' => 'sanitize_text_field',
	    )
	);
	$wp_customize->add_control('podcast_guru_theme_options[video_button_txt]',
	    array(
	        'label' => esc_html__('Button Text', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'video_section',
	        'settings' => 'podcast_guru_theme_options[video_button_txt]',
	    )
	);
	$wp_customize->add_setting('podcast_guru_theme_options[video_button_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcast_guru_options['video_button_url'],
	        'sanitize_callback' => 'podcast_guru_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcast_guru_theme_options[video_button_url]',
	    array(
	        'label' => esc_html__('Button Link', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'video_section',
	        'settings' => 'podcast_guru_theme_options[video_button_url]',
	    )
	);





    /* Blog Section */

    $wp_customize->add_section(
        'blog_section',
        array(
            'title' => esc_html__( 'Blog Section','podcast-guru' ),
            'panel'=>'theme_options',
            'capability'=>'edit_theme_options',
        )
    );
	

    $wp_customize->add_setting('podcast_guru_theme_options[blog_show]',
        array(
            'type' => 'option',
            'default'        => true,
            'default' => $podcast_guru_options['blog_show'],
            'sanitize_callback' => 'podcast_guru_sanitize_checkbox',
        )
    );

    $wp_customize->add_control('podcast_guru_theme_options[blog_show]',
        array(
            'label' => esc_html__('Show Blog Section', 'podcast-guru'),
            'type' => 'Checkbox',
            'priority' => 1,
            'section' => 'blog_section',

        )
    );
	$wp_customize->add_setting('podcast_guru_theme_options[blog_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcast_guru_options['blog_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcast_guru_theme_options[blog_title]',
	    array(
	        'label' => esc_html__('Section Title', 'podcast-guru'),
	        'priority' => 1,
	        'section' => 'blog_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('podcast_guru_theme_options[blog_desc]',
	    array(
	        'default' => $podcast_guru_options['blog_desc'],
	        'type' => 'option',
	        'sanitize_callback' => 'sanitize_text_field'
	    )
	);

	$wp_customize->add_control('podcast_guru_theme_options[blog_desc]',
	    array(
	        'label' => esc_html__('Blog Section Description', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'blog_section',
	        'settings' => 'podcast_guru_theme_options[blog_desc]',
	    )
	);

	$wp_customize->add_setting('podcast_guru_theme_options[blog_category]', array(
	    'default' => $podcast_guru_options['blog_category'],
	    'type' => 'option',
	    'sanitize_callback' => 'podcast_guru_sanitize_select',
	    'capability' => 'edit_theme_options',

	));

	$wp_customize->add_control(new podcast_guru_Dropdown_Customize_Control(
	    $wp_customize, 'podcast_guru_theme_options[blog_category]',
	    array(
	        'label' => esc_html__('Select Blog Category', 'podcast-guru'),
	        'section' => 'blog_section',
	        'choices' => podcast_guru_get_categories_select(),
	        'settings' => 'podcast_guru_theme_options[blog_category]',
	    )
	));



    /* Blog Section */

    $wp_customize->add_section(
        'prefooter_section',
        array(
            'title' => esc_html__( 'Prefooter Section','podcast-guru' ),
            'panel'=>'theme_options',
            'capability'=>'edit_theme_options',
        )
    );

    $wp_customize->add_setting('podcast_guru_theme_options[show_prefooter]',
        array(
            'type' => 'option',
            'default'        => true,
            'default' => $podcast_guru_options['show_prefooter'],
            'sanitize_callback' => 'podcast_guru_sanitize_checkbox',
        )
    );

    $wp_customize->add_control('podcast_guru_theme_options[show_prefooter]',
        array(
            'label' => esc_html__('Show Prefooter Section', 'podcast-guru'),
            'type' => 'Checkbox',
            'priority' => 1,
            'section' => 'prefooter_section',

        )
    );

       $wp_customize->add_section(
        'single_article',
        array(
            'title' => esc_html__( 'Single Article Page Options','podcast-guru' ),
            'panel'=>'theme_options',
            'capability'=>'edit_theme_options',
        )
    );

	/*Copyright section*/

	$wp_customize->add_section(
        'copyright_section',
        array(
            'title' => esc_html__( 'Copyright Section','podcast-guru' ),
            'panel'=>'theme_options',
            'capability'=>'edit_theme_options',
        )
    );

	$wp_customize->add_setting('podcast_guru_theme_options[copyright_text]',
	    array(
	        'default' => $podcast_guru_options['copyright_text'],
	        'type' => 'option',
	        'sanitize_callback' => 'sanitize_text_field'
	    )
	);

	$wp_customize->add_control('podcast_guru_theme_options[copyright_text]',
	    array(
	        'label' => esc_html__('Copyright Text', 'podcast-guru'),
	        'type' => 'text',
	        'section' => 'copyright_section',
	        'settings' => 'podcast_guru_theme_options[copyright_text]',
	    )
	);
	


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

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

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

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


