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


	/*=========================================
	Mobile App Launch Site Identity
	=========================================*/
	$wp_customize->add_section(
        'title_tagline',
        array(
        	'priority'      => 1,
            'title' 		=> __('Site Identity','mobile-app-launch'),
			'panel'  		=> 'mobile_app_launch_frontpage_sections',
		)
    );

    // Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'mobile_app_launch_site_title_setting' , 
			array(
			'default' => 1,
			'sanitize_callback' => 'mobile_app_launch_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'mobile_app_launch_site_title_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Site Title', 'mobile-app-launch' ),
			'section'     => 'title_tagline',
			'settings'    => 'mobile_app_launch_site_title_setting',
			'type'        => 'checkbox'
		) 
	);

	// Tagline Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'mobile_app_launch_tagline_setting' , 
			array(
			'default' => '',
			'sanitize_callback' => 'mobile_app_launch_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'mobile_app_launch_tagline_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Tagline', 'mobile-app-launch' ),
			'section'     => 'title_tagline',
			'settings'    => 'mobile_app_launch_tagline_setting',
			'type'        => 'checkbox'
		) 
	);

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

	// Add control for logo width
	$wp_customize->add_control( 
		'mobile_app_launch_logo_width',
		array(
			'label'     => __('Logo Width', 'mobile-app-launch'),
			'section'   => 'title_tagline',
			'type'      => 'number',
			'input_attrs' => array(
				'min'   => 1,
				'max'   => 150,
				'step'  => 1,
			),
			'transport' => $selective_refresh,
		)  
	);
	
	$wp_customize->add_setting( 'mobile_app_launch_upgrade_page_settings_6122',
		array(
			'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Mobile_App_Launch_Control_Upgrade(
		$wp_customize, 'mobile_app_launch_upgrade_page_settings_6122',
			array(
				'priority'      => 200,
				'section'       => 'title_tagline',
				'settings'      => 'mobile_app_launch_upgrade_page_settings_6122',
				'label'         => __( 'Mobile App Launch Pro comes with additional features.', 'mobile-app-launch' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'mobile-app-launch' ), __( 'One-Click Demo Import', 'mobile-app-launch' ), __( 'WooCommerce Integrated', 'mobile-app-launch' ), __( 'Drag & Drop Section Reordering', 'mobile-app-launch' ),__( 'Advanced Typography Control', 'mobile-app-launch' ),__( 'Intuitive Customization Options', 'mobile-app-launch' ),__( '24/7 Support', 'mobile-app-launch' ), )
			)
		)
	); 
	
    /*=========================================
	top header
	=========================================*/
	$wp_customize->add_section(
        'mobile_app_launch_topbar',
        array(
        	'priority'      => 3,
            'title' 		=> __('Header Information','mobile-app-launch'),
			'panel'  		=> 'mobile_app_launch_frontpage_sections',
		)
    );
    
    $wp_customize->add_setting('mobile_app_launch_header_button',array(
		'default'=> 'Sign Up',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('mobile_app_launch_header_button',array(
		'label'	=> __('Header Button Text','mobile-app-launch'),
		'section'=> 'mobile_app_launch_topbar',
		'type'=> 'text'
	));

	$wp_customize->add_setting('mobile_app_launch_header_link',array(
		'default'=> '',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('mobile_app_launch_header_link',array(
		'label'	=> __('Header Button Link','mobile-app-launch'),
		'section'=> 'mobile_app_launch_topbar',
		'type'=> 'url'
	));

	$wp_customize->add_setting( 'mobile_app_launch_upgrade_page_settings_612',
		array(
			'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Mobile_App_Launch_Control_Upgrade(
		$wp_customize, 'mobile_app_launch_upgrade_page_settings_612',
			array(
				'priority'      => 200,
				'section'       => 'mobile_app_launch_topbar',
				'settings'      => 'mobile_app_launch_upgrade_page_settings_612',
				'label'         => __( 'Mobile App Launch Pro comes with additional features.', 'mobile-app-launch' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'mobile-app-launch' ), __( 'One-Click Demo Import', 'mobile-app-launch' ), __( 'WooCommerce Integrated', 'mobile-app-launch' ), __( 'Drag & Drop Section Reordering', 'mobile-app-launch' ),__( 'Advanced Typography Control', 'mobile-app-launch' ),__( 'Intuitive Customization Options', 'mobile-app-launch' ),__( '24/7 Support', 'mobile-app-launch' ), )
			)
		)
	); 

	$wp_customize->register_panel_type( 'Mobile_App_Launch_WP_Customize_Panel' );
	$wp_customize->register_section_type( 'Mobile_App_Launch_WP_Customize_Section' );

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

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