<?php
/**
 * Pixel Hair Spa Theme Customizer
 *
 * @package Pixel Hair Spa
 */

// Customize Controls.
require get_template_directory() . '/inc/custom-settings-control/customize-controls.php';

// Sanitization For Customize Controls.
require get_template_directory() . '/inc/custom-settings-control/sanitization.php';

/**
 * Provide postMessage support for the Theme Customizer's site title and description.
 */
function pixel_hair_spa_customize_register( $wp_customize ) {

	// Header Settings Panel.
	$wp_customize->add_panel( 'pixel_hair_spa_header_settings_panel',
    array(
        'title'      => esc_html__( 'Header Settings', 'pixel-hair-spa' ),
        'priority'   => 2,
        'capability' => 'edit_theme_options',
    )
    );

    // Frontpage Sections Settings Panel.
    $wp_customize->add_panel( 'pixel_hair_spa_frontpage_sections_settings_panel',
        array(
            'title'      => esc_html__( 'Frontpage Sections Settings', 'pixel-hair-spa' ),
            'priority'   => 3,
            'capability' => 'edit_theme_options',
        )
    );

    // Footer Settings Panel.
    $wp_customize->add_panel( 'pixel_hair_spa_footer_settings_panel',
        array(
            'title'      => esc_html__( 'Footer Settings', 'pixel-hair-spa' ),
            'priority'   => 3,
            'capability' => 'edit_theme_options',
        )
    );

	// Header Options

	$wp_customize->add_section(
		'pixel_hair_spa_header_section',
		array(
			'panel'      => 'pixel_hair_spa_header_settings_panel',
			'title'    => esc_html__( 'Header Options', 'pixel-hair-spa' ),
		)
	);

	$wp_customize->add_setting(
		'pixel_hair_spa_header_section_on_off_setting',
		array(
			'default'           => false,
			'sanitize_callback' => 'pixel_hair_spa_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new Pixel_Hair_Spa_On_Off_Custom_Control(
			$wp_customize,
			'pixel_hair_spa_header_section_on_off_setting',
			array(
				'label'    => esc_html__( 'ON / OFF Topbar Section', 'pixel-hair-spa' ),
				'section'  => 'pixel_hair_spa_header_section',
				'settings' => 'pixel_hair_spa_header_section_on_off_setting',
			)
		)
	);

    $wp_customize->add_setting(
        'pixel_hair_spa_discount_text',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_discount_text',
        array(
            'label'           => sprintf( esc_html__( 'Add Discount Text', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_header_section',
            'settings'        => 'pixel_hair_spa_discount_text' ,
            'type'            => 'text',
        )
    );

	$wp_customize->add_setting(
        'pixel_hair_spa_phone_number',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_phone_number',
        array(
            'label'           => sprintf( esc_html__( 'Add Phone Number', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_header_section',
            'settings'        => 'pixel_hair_spa_phone_number' ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
        'pixel_hair_spa_address',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_address',
        array(
            'label'           => sprintf( esc_html__( 'Add Address', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_header_section',
            'settings'        => 'pixel_hair_spa_address' ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
        'pixel_hair_spa_btn_url',
        array(
            'default'           => '#',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_btn_url',
        array(
            'label'           => sprintf( esc_html__( 'Add Button Link', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_header_section',
            'settings'        => 'pixel_hair_spa_btn_url' ,
            'type'            => 'url',
        )
    );

	// Social Options

	$wp_customize->add_section(
		'pixel_hair_spa_social_section',
		array(
			'panel'      => 'pixel_hair_spa_header_settings_panel',
			'title'    => esc_html__( 'Social Options', 'pixel-hair-spa' ),
		)
	);

    $wp_customize->add_setting(
        'pixel_hair_spa_facebook_url',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_facebook_url',
        array(
            'label'           => sprintf( esc_html__( 'Add Facebook Link', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_social_section',
            'settings'        => 'pixel_hair_spa_facebook_url' ,
            'type'            => 'url',
        )
    );

	$wp_customize->add_setting(
        'pixel_hair_spa_twitter_url',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_twitter_url',
        array(
            'label'           => sprintf( esc_html__( 'Add Twitter Link', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_social_section',
            'settings'        => 'pixel_hair_spa_twitter_url' ,
            'type'            => 'url',
        )
    );

    $wp_customize->add_setting(
        'pixel_hair_spa_instagram_url',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_instagram_url',
        array(
            'label'           => sprintf( esc_html__( 'Add Instagram Link', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_social_section',
            'settings'        => 'pixel_hair_spa_instagram_url' ,
            'type'            => 'url',
        )
    );

    $wp_customize->add_setting(
        'pixel_hair_spa_youtube_url',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_youtube_url',
        array(
            'label'           => sprintf( esc_html__( 'Add Youtube Link', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_social_section',
            'settings'        => 'pixel_hair_spa_youtube_url' ,
            'type'            => 'url',
        )
    );

	$wp_customize->add_setting(
        'pixel_hair_spa_whatsapp_url',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_whatsapp_url',
        array(
            'label'           => sprintf( esc_html__( 'Add Whatsapp Link', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_social_section',
            'settings'        => 'pixel_hair_spa_whatsapp_url' ,
            'type'            => 'url',
        )
    );
	
	// Banner Options

	$wp_customize->add_section(
		'pixel_hair_spa_banner_section',
		array(
			'panel'      => 'pixel_hair_spa_frontpage_sections_settings_panel',
			'title'    => esc_html__( 'Banner Options', 'pixel-hair-spa' ),
		)
	);

	$wp_customize->add_setting(
		'pixel_hair_spa_banner_section_on_off_setting',
		array(
			'default'           => false,
			'sanitize_callback' => 'pixel_hair_spa_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new Pixel_Hair_Spa_On_Off_Custom_Control(
			$wp_customize,
			'pixel_hair_spa_banner_section_on_off_setting',
			array(
				'label'    => esc_html__( 'ON / OFF Banner Section', 'pixel-hair-spa' ),
				'section'  => 'pixel_hair_spa_banner_section',
				'settings' => 'pixel_hair_spa_banner_section_on_off_setting',
			)
		)
	);

	$wp_customize->add_setting(
	    'pixel_hair_spa_slider',
	    array(
	        'default'           => '',
	        'sanitize_callback' => 'pixel_hair_spa_sanitize_number',
	    )
	);

	$wp_customize->add_control(
	    'pixel_hair_spa_slider',
	    array(
	        'label'       => esc_html__( 'No of banner', 'pixel-hair-spa' ),
	        'section'     => 'pixel_hair_spa_banner_section',
	        'settings'    => 'pixel_hair_spa_slider',
	        'type'        => 'number',
	        'input_attrs' => array(
	            'min' => 1,
	            'max' => 3,
	        ),
	    )
	);

	$pixel_hair_spa_banner = get_theme_mod( 'pixel_hair_spa_slider');
	for ( $i = 1; $i <= $pixel_hair_spa_banner; $i++ ){
		$wp_customize->add_setting(
			'pixel_hair_spa_banner_heading'.$i,
			array(
				'default'           => '',
				'sanitize_callback' => 'sanitize_text_field',
			)
		);

		$wp_customize->add_control(
			'pixel_hair_spa_banner_heading'.$i,
			array(
				'label'           => sprintf( esc_html__( 'Banner Heading 0', 'pixel-hair-spa' ).$i, ),
				'section'         => 'pixel_hair_spa_banner_section',
				'settings'        => 'pixel_hair_spa_banner_heading'.$i,
				'type'            => 'text',
			)
		);

		$wp_customize->add_setting(
			'pixel_hair_spa_banner_content'.$i,
			array(
				'default'           => '',
				'sanitize_callback' => 'sanitize_text_field',
			)
		);

		$wp_customize->add_control(
			'pixel_hair_spa_banner_content'.$i,
			array(
				'label'           => sprintf( esc_html__( 'Banner Content 0', 'pixel-hair-spa' ).$i, ),
				'section'         => 'pixel_hair_spa_banner_section',
				'settings'        => 'pixel_hair_spa_banner_content'.$i,
				'type'            => 'text',
			)
		);

        $wp_customize->add_setting(
            'pixel_hair_spa_banner_btn'.$i,
            array(
                'default'           => '',
                'sanitize_callback' => 'sanitize_text_field',
            )
        );

        $wp_customize->add_control(
            'pixel_hair_spa_banner_btn'.$i,
            array(
                'label'           => sprintf( esc_html__( 'Banner Button 0', 'pixel-hair-spa' ).$i, ),
                'section'         => 'pixel_hair_spa_banner_section',
                'settings'        => 'pixel_hair_spa_banner_btn'.$i,
                'type'            => 'text',
            )
        );

		$wp_customize->add_setting(
			'pixel_hair_spa_banner_button_link'.$i,
			array(
				'default'           => '',
				'sanitize_callback' => 'esc_url_raw',
			)
		);

		$wp_customize->add_control(
			'pixel_hair_spa_banner_button_link'.$i,
			array(
				'label'           => sprintf( esc_html__( 'Banner Button Link 0', 'pixel-hair-spa' ).$i, ),
				'section'         => 'pixel_hair_spa_banner_section',
				'settings'        => 'pixel_hair_spa_banner_button_link'.$i,
				'type'            => 'url',
			)
		);
		
		$wp_customize->add_setting(
			'pixel_hair_spa_banner_image'.$i,
			array(
	        	'default'           => '',
	        	'sanitize_callback' => 'pixel_hair_spa_sanitize_image',

	    	)
	    );
	    
	    $wp_customize->add_control(
	     	new WP_Customize_Image_Control(
	    		$wp_customize, 'pixel_hair_spa_banner_image'.$i, 
	    		array(
	    			'label'           => sprintf( esc_html__( 'Banner Image 0', 'pixel-hair-spa' ).$i, ),
			        'settings'  => 'pixel_hair_spa_banner_image'.$i,
			        'section'   => 'pixel_hair_spa_banner_section'
	    		) 
	    	)
	    );
	}

    // Services Option

	$wp_customize->add_section(
		'pixel_hair_spa_services_section',
		array(
			'panel'      => 'pixel_hair_spa_frontpage_sections_settings_panel',
			'title'    => esc_html__( 'Services Options', 'pixel-hair-spa' ),
		)
	);

	$wp_customize->add_setting(
		'pixel_hair_spa_services_section_on_off_setting',
		array(
			'default'           => false,
			'sanitize_callback' => 'pixel_hair_spa_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new Pixel_Hair_Spa_On_Off_Custom_Control(
			$wp_customize,
			'pixel_hair_spa_services_section_on_off_setting',
			array(
				'label'    => esc_html__( 'ON / OFF Services Section', 'pixel-hair-spa' ),
				'section'  => 'pixel_hair_spa_services_section',
				'settings' => 'pixel_hair_spa_services_section_on_off_setting',
			)
		)
	);

	$wp_customize->add_setting(
        'pixel_hair_spa_services_title',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_services_title',
        array(
            'label'           => sprintf( esc_html__( 'Services Heading', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_services_section',
            'settings'        => 'pixel_hair_spa_services_title' ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
        'pixel_hair_spa_services_short_title',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_services_short_title',
        array(
            'label'           => sprintf( esc_html__( 'Services Short Content', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_services_section',
            'settings'        => 'pixel_hair_spa_services_short_title' ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
	    'pixel_hair_spa_services_count',
	    array(
	        'default'           => '',
	        'sanitize_callback' => 'pixel_hair_spa_sanitize_number',
	    )
	);

	$wp_customize->add_control(
	    'pixel_hair_spa_services_count',
	    array(
	        'label'       => esc_html__( 'No of Services', 'pixel-hair-spa' ),
	        'section'     => 'pixel_hair_spa_services_section',
	        'settings'    => 'pixel_hair_spa_services_count',
	        'type'        => 'number',
	        'input_attrs' => array(
	            'min' => 1,
	            'max' => 6,
	        ),
	    )
	);

	$pixel_hair_spa_services = get_theme_mod( 'pixel_hair_spa_services_count');
	for ( $i = 1; $i <= $pixel_hair_spa_services; $i++ ){

		$wp_customize->add_setting(
			'pixel_hair_spa_services_image'.$i,
			array(
	        	'default'           => '',
	        	'sanitize_callback' => 'pixel_hair_spa_sanitize_image',

	    	)
	    );
	    
	    $wp_customize->add_control(
	     	new WP_Customize_Image_Control(
	    		$wp_customize, 'pixel_hair_spa_services_image'.$i, 
	    		array(
	    			'label'           => sprintf( esc_html__( 'Services Member Image 0', 'pixel-hair-spa' ).$i, ),
			        'settings'  => 'pixel_hair_spa_services_image'.$i,
			        'section'   => 'pixel_hair_spa_services_section'
	    		) 
	    	)
	    );

		$wp_customize->add_setting(
			'pixel_hair_spa_services_name'.$i,
			array(
				'default'           => '',
				'sanitize_callback' => 'sanitize_text_field',
			)
		);

		$wp_customize->add_control(
			'pixel_hair_spa_services_name'.$i,
			array(
				'label'           => sprintf( esc_html__( 'Services Member Name 0', 'pixel-hair-spa' ).$i, ),
				'section'         => 'pixel_hair_spa_services_section',
				'settings'        => 'pixel_hair_spa_services_name'.$i,
				'type'            => 'text',
			)
		);

		$wp_customize->add_setting(
			'pixel_hair_spa_services_designation'.$i,
			array(
				'default'           => '',
				'sanitize_callback' => 'sanitize_text_field',
			)
		);

		$wp_customize->add_control(
			'pixel_hair_spa_services_designation'.$i,
			array(
				'label'           => sprintf( esc_html__( 'Services Member Designation 0', 'pixel-hair-spa' ).$i, ),
				'section'         => 'pixel_hair_spa_services_section',
				'settings'        => 'pixel_hair_spa_services_designation'.$i,
				'type'            => 'text',
			)
		);
	}

	// Footer Option

	$wp_customize->add_section(
		'pixel_hair_spa_footer_section',
		array(
			'panel'      => 'pixel_hair_spa_footer_settings_panel',
			'title'    => esc_html__( 'Footer Copyright Options', 'pixel-hair-spa' ),
		)
	);

	$wp_customize->add_setting(
        'pixel_hair_spa_footer_text',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

	$wp_customize->add_control(
        'pixel_hair_spa_footer_text',
        array(
            'label'           => sprintf( esc_html__( 'Edit Footer Copyright Text', 'pixel-hair-spa' ), ),
            'section'         => 'pixel_hair_spa_footer_section',
            'settings'        => 'pixel_hair_spa_footer_text' ,
            'type'            => 'text',
        )
    );
}
add_action( 'customize_register', 'pixel_hair_spa_customize_register' );

/**
 * Create the site title for the partial selective refresh.
 *
 * @return void
 */
function pixel_hair_spa_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Create the website's slogan for the partial selective refresh.
 *
 * @return void
 */
function pixel_hair_spa_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Singleton class for handling the theme's customizer integration.
 *
 * @since  1.0.0
 * @access public
 */
final class Pixel_Hair_Spa_Customize_Buttons {
	/**
	 * Returns the instance.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return object
	 */
	public static function Pixel_Hair_Spa_get_instance() {

		static $pixel_hair_spa_instance = null;

		if ( is_null( $pixel_hair_spa_instance ) ) {
			$pixel_hair_spa_instance = new self;
			$pixel_hair_spa_instance->Pixel_Hair_Spa_setup_actions();
		}

		return $pixel_hair_spa_instance;
	}

	/**
	 * Constructor method.
	 *
	 * @since  1.0.0
	 * @access private
	 * @return void
	 */
	private function __construct() {}

	/**
	 * Sets up initial actions.
	 *
	 * @since  1.0.0
	 * @access private
	 * @return void
	 */
	private function Pixel_Hair_Spa_setup_actions() {

		// Register panels, sections, settings, controls, and partials.
		add_action( 'customize_register', array( $this, 'sections' ) );

		// Register scripts and styles for the controls.
		add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ), 0 );
	}

	/**
	 * Sets up the customizer sections.
	 *
	 * @since  1.0.0
	 * @access public
	 * @param  object  $pixel_hair_spa_manager
	 * @return void
	*/
	public function sections( $pixel_hair_spa_manager ) {
		load_template( trailingslashit( get_template_directory() ) . '/inc/pixel-hair-spa-section-pro.php' );

		$pixel_hair_spa_manager->register_section_type( 'Pixel_Hair_Spa_Customize_Section_Pro' );

		$pixel_hair_spa_manager->add_section( new Pixel_Hair_Spa_Customize_Section_Pro( $pixel_hair_spa_manager,'pixel_hair_spa_buy_now', array(
			'priority'   => 1,
			'title'    => esc_html__( 'Buy Pixel Hair Spa Pro', 'pixel-hair-spa' ),
			'pro_text' => esc_html__( 'Buy Pro Theme', 'pixel-hair-spa' ),
			'pro_url'    => esc_url( PIXEL_HAIR_SPA_BUY_NOW ),
		) )	);

		$pixel_hair_spa_manager->add_section( new Pixel_Hair_Spa_Customize_Section_Pro( $pixel_hair_spa_manager, 'pixel_hair_spa_live_demo', array(
		    'priority'   => 1,
		    'title'      => esc_html__( 'Preview Pro Theme', 'pixel-hair-spa' ),
		    'pro_text'   => esc_html__( 'View Live Demo', 'pixel-hair-spa' ),
		    'pro_url'    => esc_url( PIXEL_HAIR_SPA_LIVE_DEMO ),
		) ) );	
	}

	/**
	 * Loads theme customizer CSS.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return void
	 */
	public function enqueue_control_scripts() {

		wp_enqueue_script( 'pixel-hair-spa-customize-controls', trailingslashit( get_template_directory_uri() ) . '/assets/js/customize-controls.js', array( 'customize-controls' ) );

		wp_enqueue_style( 'pixel-hair-spa-customize-controls', trailingslashit( get_template_directory_uri() ) . '/assets/css/customize-controls.css' );
	}
}
Pixel_Hair_Spa_Customize_Buttons::Pixel_Hair_Spa_get_instance();