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


	/*=========================================
	Islamic Trust Site Identity
	=========================================*/
	$wp_customize->add_section(
        'title_tagline',
        array(
        	'priority'      => 1,
            'title' 		=> __('Site Identity','islamic-trust'),
			'panel'  		=> 'islamic_trust_frontpage_sections',
		)
    );

    // Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'islamic_trust_site_title_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'islamic_trust_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'islamic_trust_site_title_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Site Title', 'islamic-trust' ),
			'section'     => 'title_tagline',
			'settings'    => 'islamic_trust_site_title_setting',
			'type'        => 'checkbox'
		) 
	);

	// Tagline Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'islamic_trust_tagline_setting' , 
			array(
			'default' => '0',
			'sanitize_callback' => 'islamic_trust_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'islamic_trust_tagline_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Tagline', 'islamic-trust' ),
			'section'     => 'title_tagline',
			'settings'    => 'islamic_trust_tagline_setting',
			'type'        => 'checkbox'
		) 
	);

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

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

	$wp_customize->add_setting( 'islamic_trust_upgrade_page_settings_111',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Islamic_Trust_Control_Upgrade(
		$wp_customize, 'islamic_trust_upgrade_page_settings_111',
			array(
				'priority'      => 200,
				'section'       => 'title_tagline',
				'settings'      => 'islamic_trust_upgrade_page_settings_111',
				'label'         => __( 'Islamic Trust Pro comes with additional features.', 'islamic-trust' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'islamic-trust' ), __( 'One-Click Demo Import', 'islamic-trust' ), __( 'WooCommerce Integrated', 'islamic-trust' ), __( 'Drag & Drop Section Reordering', 'islamic-trust' ),__( 'Advanced Typography Control', 'islamic-trust' ),__( 'Intuitive Customization Options', 'islamic-trust' ),__( '24/7 Support', 'islamic-trust' ), )
			)
		)
	); 
	
    /*=========================================
	top header
	=========================================*/
	$wp_customize->add_section(
        'islamic_trust_topbar',
        array(
        	'priority'      => 3,
            'title' 		=> __('Header Informations','islamic-trust'),
			'panel'  		=> 'islamic_trust_frontpage_sections',
		)
    );
    
    $wp_customize->add_setting('islamic_trust_header_button',array(
		'default'=> 'Donate Now',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('islamic_trust_header_button',array(
		'label'	=> __('Header Button Text','islamic-trust'),
		'section'=> 'islamic_trust_topbar',
		'type'=> 'text'
	));

	$wp_customize->add_setting('islamic_trust_header_link',array(
		'default'=> '#',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('islamic_trust_header_link',array(
		'label'	=> __('Header Button Link','islamic-trust'),
		'section'=> 'islamic_trust_topbar',
		'type'=> 'url'
	));

	$wp_customize->add_setting( 'islamic_trust_upgrade_page_settings_111151',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Islamic_Trust_Control_Upgrade(
		$wp_customize, 'islamic_trust_upgrade_page_settings_111151',
			array(
				'priority'      => 200,
				'section'       => 'islamic_trust_topbar',
				'settings'      => 'islamic_trust_upgrade_page_settings_111151',
				'label'         => __( 'Islamic Trust Pro comes with additional features.', 'islamic-trust' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'islamic-trust' ), __( 'One-Click Demo Import', 'islamic-trust' ), __( 'WooCommerce Integrated', 'islamic-trust' ), __( 'Drag & Drop Section Reordering', 'islamic-trust' ),__( 'Advanced Typography Control', 'islamic-trust' ),__( 'Intuitive Customization Options', 'islamic-trust' ),__( '24/7 Support', 'islamic-trust' ), )
			)
		)
	); 


	$wp_customize->register_panel_type( 'Islamic_Trust_WP_Customize_Panel' );
	$wp_customize->register_section_type( 'Islamic_Trust_WP_Customize_Section' );

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

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