<?php
function expert_author_header_settings( $wp_customize ) {
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';

    // Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_author_site_title_setting' , 
			array(
			'default' => '0',
			'sanitize_callback' => 'expert_author_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'expert_author_site_title_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Site Title', 'expert-author' ),
			'section'     => 'title_tagline',
			'settings'    => 'expert_author_site_title_setting',
			'type'        => 'checkbox'
		) 
	);

	// Tagline Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_author_tagline_setting' , 
			array(
			'default' => '',
			'sanitize_callback' => 'expert_author_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'expert_author_tagline_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Tagline', 'expert-author' ),
			'section'     => 'title_tagline',
			'settings'    => 'expert_author_tagline_setting',
			'type'        => 'checkbox'
		) 
	);

	// Add the setting for logo width
	$wp_customize->add_setting(
	    'expert_author_logo_width',
	    array(
	        'sanitize_callback' => 'expert_author_sanitize_logo_width',
	        'priority'          => 2,
	    )
	);

	// Add control for logo width
	$wp_customize->add_control( 
	    'expert_author_logo_width',
	    array(
	        'label'     => __('Logo Width', 'expert-author'),
	        'section'   => 'title_tagline',
	        'type'      => 'number',
	        'input_attrs' => array(
	            'min'   => 1,
	            'max'   => 250,
	            'step'  => 1,
	        ),
	        'transport' => $selective_refresh,
	    )  
	);

	$wp_customize->add_setting( 'expert_author_upgrade_page_settings_10a',
    array(
        'sanitize_callback' => 'sanitize_text_field'
    )
    );
    $wp_customize->add_control( new Expert_Author_Control_Upgrade(
        $wp_customize, 'expert_author_upgrade_page_settings_10a',
            array(
                'priority'      => 200,
                'section'       => 'title_tagline',
                'settings'      => 'expert_author_upgrade_page_settings_10a',
                'label'         => __( 'Expert Author Pro comes with additional features.', 'expert-author' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'expert-author' ), __( 'One-Click Demo Import', 'expert-author' ), __( 'WooCommerce Integrated', 'expert-author' ), __( 'Drag & Drop Section Reordering', 'expert-author' ),__( 'Advanced Typography Control', 'expert-author' ),__( 'Intuitive Customization Options', 'expert-author' ),__( '24/7 Support', 'expert-author' ), )
            )
        )
    ); 

	/*=========================================
	Expert Author Site Identity
	=========================================*/
	$wp_customize->add_section(
        'title_tagline',
        array(
        	'priority'      => 1,
            'title' 		=> __('Site Identity','expert-author'),
			'panel'  		=> 'expert_author_frontpage_sections',
		)
    );    

	/*=========================================
	Top header
	=========================================*/
	$wp_customize->add_section(
        'expert_author_top_header',
        array(
        	'priority'      => 2,
            'title' 		=> __('Header','expert-author'),
			'panel'  		=> 'expert_author_frontpage_sections',
		)
    );

    // Header Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_author_header_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'expert_author_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_author_header_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-author' ),
			'section'     => 'expert_author_top_header',
			'settings'    => 'expert_author_header_setting',
			'type'        => 'checkbox'
		) 
	);

   	$wp_customize->add_setting(
    	'expert_author_topheader_text',
    	array(
			'default' => 'Almost before we knew it, we had left the ground.',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_author_topheader_text',
		array(
		    'label'   		=> __('Header Text','expert-author'),
		    'section'		=> 'expert_author_top_header',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_author_sign_in_text',
    	array(
			'default' => 'Sign In',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_author_sign_in_text',
		array(
		    'label'   		=> __('Sign In Text','expert-author'),
		    'section'		=> 'expert_author_top_header',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_author_sign_in_link',
    	array(
			'default' => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_author_sign_in_link',
		array(
		    'label'   		=> __('Sign In Link','expert-author'),
		    'section'		=> 'expert_author_top_header',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting( 'expert_author_upgrade_page_settings_11',
    array(
        'sanitize_callback' => 'sanitize_text_field'
    )
    );
    $wp_customize->add_control( new Expert_Author_Control_Upgrade(
        $wp_customize, 'expert_author_upgrade_page_settings_11',
            array(
                'priority'      => 200,
                'section'       => 'expert_author_top_header',
                'settings'      => 'expert_author_upgrade_page_settings_11',
                'label'         => __( 'Expert Author Pro comes with additional features.', 'expert-author' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'expert-author' ), __( 'One-Click Demo Import', 'expert-author' ), __( 'WooCommerce Integrated', 'expert-author' ), __( 'Drag & Drop Section Reordering', 'expert-author' ),__( 'Advanced Typography Control', 'expert-author' ),__( 'Intuitive Customization Options', 'expert-author' ),__( '24/7 Support', 'expert-author' ), )
            )
        )
    ); 

	$wp_customize->register_panel_type( 'Expert_Author_WP_Customize_Panel' );
	$wp_customize->register_section_type( 'Expert_Author_WP_Customize_Section' );

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


if ( class_exists( 'WP_Customize_Panel' ) ) {
  	class Expert_Author_WP_Customize_Panel extends WP_Customize_Panel {
	   public $panel;
	   public $type = 'expert_author_panel';
	   public function json() {

	      $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'type', 'panel', ) );
	      $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
	      $array['content'] = $this->get_content();
	      $array['active'] = $this->active();
	      $array['instanceNumber'] = $this->instance_number;
	      return $array;
    	}
  	}
}

if ( class_exists( 'WP_Customize_Section' ) ) {
  	class Expert_Author_WP_Customize_Section extends WP_Customize_Section {
	   public $section;
	   public $type = 'expert_author_section';
	   public function json() {

	      $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'panel', 'type', 'description_hidden', 'section', ) );
	      $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
	      $array['content'] = $this->get_content();
	      $array['active'] = $this->active();
	      $array['instanceNumber'] = $this->instance_number;

	      if ( $this->panel ) {
	        $array['customizeAction'] = sprintf( 'Customizing &#9656; %s', esc_html( $this->manager->get_panel( $this->panel )->title ) );
	      } else {
	        $array['customizeAction'] = 'Customizing';
	      }
	      return $array;
    	}
  	}
}