<?php
/**
 * Site Identity Settings
 * 
 * @package chic-lifestyle
 */

add_action( 'customize_register', 'chic_lifestyle_change_site_identity_panel' );

function chic_lifestyle_change_site_identity_panel( $wp_customize)  {

    $wp_customize->get_section( 'title_tagline' )->priority = 1;
    $wp_customize->get_section( 'title_tagline' )->panel = 'chic_lifestyle_header_panel';

    $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
    //$wp_customize->get_control( 'blogname' )->priority = 2;
    $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
    //$wp_customize->get_control( 'blogdescription' )->priority = 3;

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

    $wp_customize->add_setting( 'site_title_color_option', array(
        'capability'        => 'edit_theme_options',
        'default'           => '#000',
        'sanitize_callback' => 'chic_lifestyle_sanitize_hex_color',
        'transport'         => 'refresh',
    ) );
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'site_title_color_option', array(
        'label'    => esc_html__( 'Title Color', 'chic-lifestyle' ),
        'section'  => 'title_tagline',
        'settings' => 'site_title_color_option'
    ) ) );

    $wp_customize->add_setting( 'chic_lifestyle_logo_size', array(
        'default'           => 30,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( new Chic_Lifestyle_Slider_Control(
        $wp_customize, 'chic_lifestyle_logo_size', array(
            'section' => 'title_tagline',
            'settings' => 'chic_lifestyle_logo_size',
            'label'   => esc_html__( 'Title Size', 'chic-lifestyle' ),
            'choices'     => array(
                'min'   => 15,
                'max'   => 60,
                'step'  => 1,
            )
        )
    ) );

    $wp_customize->add_setting( 'site_title_font_family', array(
        'capability'        => 'edit_theme_options',
        'default'           => 'Rock Salt',
        'sanitize_callback' => 'chic_lifestyle_sanitize_google_fonts',
    ) );
    $wp_customize->add_control( 'site_title_font_family', array(
        'settings' => 'site_title_font_family',
        'label'    => esc_html__( 'Title Font Family', 'chic-lifestyle' ),
        'section'  => 'title_tagline',
        'type'     => 'select',
        'choices'  => google_fonts()
    ) );
}

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

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