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

    // Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'automotive_services_site_title_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'automotive_services_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'automotive_services_site_title_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Site Title', 'automotive-services' ),
			'section'     => 'title_tagline',
			'settings'    => 'automotive_services_site_title_setting',
			'type'        => 'checkbox'
		) 
	);

	// Tagline Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'automotive_services_tagline_setting' , 
			array(
			'default' => '',
			'sanitize_callback' => 'automotive_services_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'automotive_services_tagline_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Tagline', 'automotive-services' ),
			'section'     => 'title_tagline',
			'settings'    => 'automotive_services_tagline_setting',
			'type'        => 'checkbox'
		) 
	);

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

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

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


	/*=========================================
	Automotive Services Site Identity
	=========================================*/
	$wp_customize->add_section(
        'title_tagline',
        array(
        	'priority'      => 1,
            'title' 		=> __('Site Identity','automotive-services'),
			'panel'  		=> 'automotive_services_frontpage_sections',
		)
    );    

	/*=========================================
	Top header
	=========================================*/
	$wp_customize->add_section(
        'automotive_services_top_header',
        array(
        	'priority'      => 2,
            'title' 		=> __('Header Informations','automotive-services'),
			'panel'  		=> 'automotive_services_frontpage_sections',
		)
    );

    $wp_customize->add_setting('automotive_services_location',array(
		'default'=> '1901 Thornridge Cir. Shiloh, Hawaii 81063',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('automotive_services_location',array(
		'label'	=> __('Add location','automotive-services'),
		'section'=> 'automotive_services_top_header',
		'type'=> 'text'
	));

	$wp_customize->add_setting('automotive_services_call',array(
		'default'=> '(+33)7 35 55 21 02',
		'sanitize_callback'	=> 'automotive_services_sanitize_phone_number'
	));
	$wp_customize->add_control('automotive_services_call',array(
		'label'	=> __('Add Phone Number','automotive-services'),
		'section'=> 'automotive_services_top_header',
		'type'=> 'text'
	));

	$wp_customize->add_setting('automotive_services_header_button',array(
		'default'=> 'Get Consultant',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('automotive_services_header_button',array(
		'label'	=> __('Header Button Text','automotive-services'),
		'section'=> 'automotive_services_top_header',
		'type'=> 'text'
	));

	$wp_customize->add_setting('automotive_services_header_link',array(
		'default'=> '#',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('automotive_services_header_link',array(
		'label'	=> __('Header Button Link','automotive-services'),
		'section'=> 'automotive_services_top_header',
		'type'=> 'url'
	));

	$wp_customize->add_setting( 'automotive_services_upgrade_page_settings_11112',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Automotive_Services_Control_Upgrade(
		$wp_customize, 'automotive_services_upgrade_page_settings_11112',
			array(
				'priority'      => 200,
				'section'       => 'automotive_services_top_header',
				'settings'      => 'automotive_services_upgrade_page_settings_11112',
				'label'         => __( 'Automotive Services Pro comes with additional features.', 'automotive-services' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'automotive-services' ), __( 'One-Click Demo Import', 'automotive-services' ), __( 'WooCommerce Integrated', 'automotive-services' ), __( 'Drag & Drop Section Reordering', 'automotive-services' ),__( 'Advanced Typography Control', 'automotive-services' ),__( 'Intuitive Customization Options', 'automotive-services' ),__( '24/7 Support', 'automotive-services' ), )
			)
		)
	); 

	$wp_customize->register_panel_type( 'Automotive_Services_WP_Customize_Panel' );
	$wp_customize->register_section_type( 'Automotive_Services_WP_Customize_Section' );

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


if ( class_exists( 'WP_Customize_Panel' ) ) {
  	class Automotive_Services_WP_Customize_Panel extends WP_Customize_Panel {
	   public $panel;
	   public $type = 'automotive_services_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 Automotive_Services_WP_Customize_Section extends WP_Customize_Section {
	   public $section;
	   public $type = 'automotive_services_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;
    	}
  	}
}