<?php
/**
 * Theme Customizer
 *
 * @package Portfolio_One
 */

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

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



	$default = portfolio_one_customizer_defaults();

	$wp_customize->register_control_type( 'Portfolio_One_Checkbox' );
	$wp_customize->register_control_type( 'Portfolio_One_Heading' );
	

	/**
	 * Theme color 
	 * 
	 * 
	 */ 
	$wp_customize->add_setting('cww_theme_color', 
			array(
		        'default'           => $default['cww_theme_color'],
		        'sanitize_callback' => 'portfolio_one_sanitize_color',
		    )
		);

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'cww_theme_color', 
		array(
	        'label'           	=> esc_html__( 'Theme Color', 'portfolio-one' ),
	        'active_callback' 	=> 'portfolio_one_header_cta_cb',
	        'section'         	=> 'colors',
	        'priority'			=> 50,
	    ) ) );




	/**
	* Header Options
	*
	*/
	require get_template_directory() . '/inc/customizer/header-settings.php';


	//Sidebar settings
	require get_template_directory() . '/inc/customizer/sidebar/archive-pages.php';
	require get_template_directory() . '/inc/customizer/sidebar/single-post.php';

	//footer settings
	require get_template_directory() . '/inc/customizer/footer-settings.php';


	/**
	 * Additional Settings
	 */
	require get_template_directory() . '/inc/customizer/additional-settings/additional-settings.php';
	require get_template_directory() . '/inc/customizer/additional-settings/dark-mode.php';
	require get_template_directory() . '/inc/customizer/additional-settings/advanced-settings.php';
	require get_template_directory() . '/inc/customizer/additional-settings/social-icons.php';


	$wp_customize->register_section_type( 'Portfolio_One_Customize_Section_Pro' );

		// Register sections.
		$wp_customize->add_section(
		    new Portfolio_One_Customize_Section_Pro(
		        $wp_customize,
		        'portfolio-one-pro',
		        array(
		            'title'    => esc_html__( 'Premium Template Available', 'portfolio-one' ),
		            'pro_text' => esc_html__( 'Details','portfolio-one' ),
		            'pro_url'  => 'https://codeworkweb.com/wordpress-themes/portfolio-one-pro/',
		            'priority' => 0,
		        )
		    )
		);
		$wp_customize->add_setting(
			'portfolio_one_upgrade',
			array(
				'section' => 'portfolio-one-pro',
				'sanitize_callback' => 'esc_attr',
			)
		);

		$wp_customize->add_control(
			'portfolio_one_upgrade',
			array(
				'section' => 'portfolio-one-pro'
			)
		);


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

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

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

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function portfolio_one_customize_preview_js() {
	wp_enqueue_script( 'portfolio-one-customizer', get_theme_file_uri('/assets/js/customizer.js'), array( 'customize-preview' ), PORTFOLIO_ONE_VER, true );
}
add_action( 'customize_preview_init', 'portfolio_one_customize_preview_js' );