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

    // Site Title Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'vegan_cafe_restaurant_site_title_setting' , 
			array(
			'default' => 1,
			'sanitize_callback' => 'vegan_cafe_restaurant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'vegan_cafe_restaurant_site_title_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Site Title', 'vegan-cafe-restaurant' ),
			'section'     => 'title_tagline',
			'settings'    => 'vegan_cafe_restaurant_site_title_setting',
			'type'        => 'checkbox'
		) 
	);

	// Tagline Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'vegan_cafe_restaurant_tagline_setting' , 
			array(
			'default' => '',
			'sanitize_callback' => 'vegan_cafe_restaurant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	
	$wp_customize->add_control(
	'vegan_cafe_restaurant_tagline_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Tagline', 'vegan-cafe-restaurant' ),
			'section'     => 'title_tagline',
			'settings'    => 'vegan_cafe_restaurant_tagline_setting',
			'type'        => 'checkbox'
		) 
	);

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

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

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

	/*=========================================
	Vegan Cafe Restaurant Site Identity
	=========================================*/
	$wp_customize->add_section(
        'title_tagline',
        array(
        	'priority'      => 1,
            'title' 		=> __('Site Identity','vegan-cafe-restaurant'),
			'panel'  		=> 'vegan_cafe_restaurant_frontpage_sections',
		)
    );

    /*=========================================
	top header
	=========================================*/
	$wp_customize->add_section(
        'vegan_cafe_restaurant_topbar',
        array(
        	'priority'      => 3,
            'title' 		=> __('Header Information','vegan-cafe-restaurant'),
			'panel'  		=> 'vegan_cafe_restaurant_frontpage_sections',
		)
    );

    $wp_customize->add_setting( 
		'vegan_cafe_restaurant_top_header' , 
			array(
			'default' => true,
			'sanitize_callback' => 'vegan_cafe_restaurant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	$wp_customize->add_control(
	'vegan_cafe_restaurant_top_header', 
		array(
			'label'	      => esc_html__( 'Show / Hide Topbar', 'vegan-cafe-restaurant' ),
			'section'     => 'vegan_cafe_restaurant_topbar',
			'settings'    => 'vegan_cafe_restaurant_top_header',
			'type'        => 'checkbox'
		) 
	);
    
    $wp_customize->add_setting('vegan_cafe_restaurant_topbar_text',array(
		'default'=> 'Learn about Guest Favourites, the most loved homes on Explorer.',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('vegan_cafe_restaurant_topbar_text',array(
		'label'	=> __('Topbar Text','vegan-cafe-restaurant'),
		'section'=> 'vegan_cafe_restaurant_topbar',
		'type'=> 'text'
	));

	$wp_customize->add_setting( 
		'vegan_cafe_restaurant_header_sidebar' , 
			array(
			'default' => true,
			'sanitize_callback' => 'vegan_cafe_restaurant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
		) 
	);
	$wp_customize->add_control(
	'vegan_cafe_restaurant_header_sidebar', 
		array(
			'label'	      => esc_html__( 'Show / Hide Header Sidebar Toggle', 'vegan-cafe-restaurant' ),
			'section'     => 'vegan_cafe_restaurant_topbar',
			'settings'    => 'vegan_cafe_restaurant_header_sidebar',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting('vegan_cafe_restaurant_facebook_url',array(
		'default'=> '#',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('vegan_cafe_restaurant_facebook_url',array(
		'label'	=> __('Facebook Link','vegan-cafe-restaurant'),
		'section'=> 'vegan_cafe_restaurant_topbar',
		'type'=> 'url'
	));

	$wp_customize->add_setting('vegan_cafe_restaurant_twitter_url',array(
		'default'=> '#',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('vegan_cafe_restaurant_twitter_url',array(
		'label'	=> __('Twitter Link','vegan-cafe-restaurant'),
		'section'=> 'vegan_cafe_restaurant_topbar',
		'type'=> 'url'
	));

	$wp_customize->add_setting('vegan_cafe_restaurant_instagram_url',array(
		'default'=> '#',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('vegan_cafe_restaurant_instagram_url',array(
		'label'	=> __('Instagram Link','vegan-cafe-restaurant'),
		'section'=> 'vegan_cafe_restaurant_topbar',
		'type'=> 'url'
	));

	$wp_customize->add_setting('vegan_cafe_restaurant_youtube_url',array(
		'default'=> '#',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('vegan_cafe_restaurant_youtube_url',array(
		'label'	=> __('YouTube Link','vegan-cafe-restaurant'),
		'section'=> 'vegan_cafe_restaurant_topbar',
		'type'=> 'url'
	));

	$wp_customize->add_setting('vegan_cafe_restaurant_pint_url',array(
		'default'=> '#',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('vegan_cafe_restaurant_pint_url',array(
		'label'	=> __('Pinterest Link','vegan-cafe-restaurant'),
		'section'=> 'vegan_cafe_restaurant_topbar',
		'type'=> 'url'
	));

	$wp_customize->add_setting( 'vegan_cafe_restaurant_upgrade_page_settings_156454',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Vegan_Cafe_Restaurant_Control_Upgrade(
        $wp_customize, 'vegan_cafe_restaurant_upgrade_page_settings_156454',
            array(
                'priority'      => 200,
                'section'       => 'vegan_cafe_restaurant_topbar',
                'settings'      => 'vegan_cafe_restaurant_upgrade_page_settings_156454',
                'label'         => __( 'Vegan Cafe Restaurant Pro comes with additional features.', 'vegan-cafe-restaurant' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'vegan-cafe-restaurant' ), __( 'One-Click Demo Import', 'vegan-cafe-restaurant' ), __( 'WooCommerce Integrated', 'vegan-cafe-restaurant' ), __( 'Drag & Drop Section Reordering', 'vegan-cafe-restaurant' ),__( 'Advanced Typography Control', 'vegan-cafe-restaurant' ),__( 'Intuitive Customization Options', 'vegan-cafe-restaurant' ),__( '24/7 Support', 'vegan-cafe-restaurant' ), )
            )
        )
    );

	$wp_customize->register_panel_type( 'Vegan_Cafe_Restaurant_WP_Customize_Panel' );
	$wp_customize->register_section_type( 'Vegan_Cafe_Restaurant_WP_Customize_Section' );

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

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