<?php
/**
 * Medo Pixel Theme Customizer
 *
 * @package Medo Pixel
 */

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

// Customize Controls.
require get_template_directory() . '/inc/custom-range-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 medo_pixel_customize_register( $wp_customize ) {

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

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

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

	// Site Identity

	$wp_customize->add_setting(
		'medo_pixel_site_logo',
		array(
			'default'           => false,
			'sanitize_callback' => 'medo_pixel_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new medo_pixel_On_Off_Custom_Control(
			$wp_customize,
			'medo_pixel_site_logo',
			array(
				'label'    => esc_html__( 'ON / OFF Site Logo', 'medo-pixel' ),
				'section'  => 'title_tagline',
				'settings' => 'medo_pixel_site_logo',
			)
		)
	);



	$wp_customize->add_setting(
		'medo_pixel_site_title_text',
		array(
			'default'           => true,
			'sanitize_callback' => 'medo_pixel_sanitize_on_off',
		)
	);



	$wp_customize->add_control(
		new medo_pixel_On_Off_Custom_Control(
			$wp_customize,
			'medo_pixel_site_title_text',
			array(
				'label'    => esc_html__( 'ON / OFF Site Title', 'medo-pixel' ),
				'section'  => 'title_tagline',
				'settings' => 'medo_pixel_site_title_text',
			)
		)
	);

	$wp_customize->add_setting(
        'medo_pixel_title_font_size',
        array(
            'default'    => 22,
            'sanitize_callback' => 'medo_pixel_sanitize_number_range',
        )
    );

    $wp_customize->add_control(
        new medo_pixel_Slider(
            $wp_customize,
            'medo_pixel_title_font_size',
            array(
                'label'    => esc_html__( 'Site Title Font Size', 'medo-pixel' ),
                'section'  => 'title_tagline',
                'label' => esc_html__('Site Title Font Size', 'medo-pixel'),
                'input_attrs' => array(
					'reset'			   => 22,
		            'step'             => 1,
					'min'              => 0,
					'max'              => 50,
		        ),
            )
        )
    );

	$wp_customize->add_setting(
		'medo_pixel_site_tagline_text',
		array(
			'default'           => false,
			'sanitize_callback' => 'medo_pixel_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new medo_pixel_On_Off_Custom_Control(
			$wp_customize,
			'medo_pixel_site_tagline_text',
			array(
				'label'    => esc_html__( 'ON / OFF Site Tagline', 'medo-pixel' ),
				'section'  => 'title_tagline',
				'settings' => 'medo_pixel_site_tagline_text',
			)
		)
	);

	$wp_customize->add_setting(
        'medo_pixel_site_tagline_font_size',
        array(
            'default'    => 14,
            'sanitize_callback' => 'medo_pixel_sanitize_number_range',
        )
    );

    $wp_customize->add_control(
        new medo_pixel_Slider(
            $wp_customize,
            'medo_pixel_site_tagline_font_size',
            array(
                'label'    => esc_html__( 'Tagline Font Size', 'medo-pixel' ),
                'section'  => 'title_tagline',
                'label' => esc_html__('Tagline Font Size', 'medo-pixel'),
                'input_attrs' => array(
					'reset'			   => 14,
		            'step'             => 1,
					'min'              => 0,
					'max'              => 50,
		        ),
            )
        )
    );
	
	//Woo Coomerce
    $wp_customize->add_setting('medo_pixel_per_columns',array(
        'default'=> 3,
        'sanitize_callback' => 'medo_pixel_sanitize_number_absint'
    ));
    $wp_customize->add_control('medo_pixel_per_columns',array(
        'label' => __('Product Per Row','medo-pixel'),
        'section'=> 'woocommerce_product_catalog',
        'type'=> 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 6,
            'step' => 1,
        ),
    ));
    $wp_customize->add_setting('medo_pixel_product_per_page',array(
        'default'=> 10,
        'sanitize_callback' => 'medo_pixel_sanitize_number_absint'
    ));
    $wp_customize->add_control('medo_pixel_product_per_page',array(
        'label' => __('Product Per Page','medo-pixel'),
        'section'=> 'woocommerce_product_catalog',
        'type'=> 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 20,
            'step' => 1,
        ),
    ));

    $wp_customize->add_section(
        'woocommerce_product_extra_section',
        array(
            'panel'      => 'woocommerce',
            'title'    => esc_html__( 'Extra WooCommerce Settings', 'medo-pixel' ),
        )
    );

    $wp_customize->add_setting( 'medo_pixel_single_product_sidebar', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'medo_pixel_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new medo_pixel_On_Off_Custom_Control( $wp_customize, 'medo_pixel_single_product_sidebar', array(
        'label'       => esc_html__( 'Show / Hide Product Page Sidebar', 'medo-pixel' ),
        'section'     => 'woocommerce_product_extra_section',
        'type'        => 'toggle',
        'settings'    => 'medo_pixel_single_product_sidebar',
    ) ) );

	// Header Option

	$wp_customize->add_section(
		'medo_pixel_header_section',
		array(
			'panel'      => 'medo_pixel_header_settings_panel',
			'title'    => esc_html__( 'Header Options', 'medo-pixel' ),
		)
	);

	//MENU TYPOGRAPHY
	
	$wp_customize->add_setting('medo_pixel_menu_font_weight',array(
        'default' => '',
        'sanitize_callback' => 'medo_pixel_sanitize_choices'
	));
	$wp_customize->add_control('medo_pixel_menu_font_weight',array(
     'type' => 'radio',
     'label'     => __('Menu Font Weight', 'medo-pixel'),
     'section' => 'medo_pixel_header_section',
     'type' => 'select',
     'choices' => array(
         '100' => __('100','medo-pixel'),
         '200' => __('200','medo-pixel'),
         '300' => __('300','medo-pixel'),
         '400' => __('400','medo-pixel'),
         '500' => __('500','medo-pixel'),
         '600' => __('600','medo-pixel'),
         '700' => __('700','medo-pixel'),
         '800' => __('800','medo-pixel'),
         '900' => __('900','medo-pixel')
     ),
	) );
	
	$wp_customize->add_setting('medo_pixel_menu_text_tranform',array(
		'default' => 'Capitalize',
		'sanitize_callback' => 'medo_pixel_sanitize_choices'
 	));
 	$wp_customize->add_control('medo_pixel_menu_text_tranform',array(
		'type' => 'select',
		'label' => __('Menu Text Transform','medo-pixel'),
		'section' => 'medo_pixel_header_section',
		'choices' => array(
		   'Uppercase' => __('Uppercase','medo-pixel'),
		   'Lowercase' => __('Lowercase','medo-pixel'),
		   'Capitalize' => __('Capitalize','medo-pixel'),
		),
	) );
	$wp_customize->add_setting('medo_pixel_menu_font_size', array(
	    'default'	=> 16,
        'sanitize_callback' => 'medo_pixel_sanitize_number_range',
	));
	$wp_customize->add_control(new medo_pixel_Slider($wp_customize, 'medo_pixel_menu_font_size', array(
        'section' => 'medo_pixel_header_section',
        'label' => esc_html__('Menu Font Size', 'medo-pixel'),
        'input_attrs' => array(
					'reset'			   => 16,
		            'step'             => 1,
					'min'              => 0,
					'max'              => 35,
		        ),
	)));


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

	$wp_customize->add_control(
		'medo_pixel_button_url',
		array(
			'label'           => sprintf( esc_html__( 'Button Url', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_header_section',
			'settings'        => 'medo_pixel_button_url' ,
			'type'            => 'text',
		)
	);

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

	$wp_customize->add_control(
		'medo_pixel_button_text_header',
		array(
			'label'           => sprintf( esc_html__( 'Button Text', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_header_section',
			'settings'        => 'medo_pixel_button_text_header' ,
			'type'            => 'text',
		)
	);

	// Banner Option

	$wp_customize->add_section(
		'medo_pixel_banner_section',
		array(
			'panel'      => 'medo_pixel_frontpage_sections_settings_panel',
			'title'    => esc_html__( 'Banner Options', 'medo-pixel' ),
		)
	);

	$wp_customize->add_setting(
		'medo_pixel_banner_section_on_off_setting',
		array(
			'default'           => false,
			'sanitize_callback' => 'medo_pixel_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new Medo_Pixel_On_Off_Custom_Control(
			$wp_customize,
			'medo_pixel_banner_section_on_off_setting',
			array(
				'label'    => esc_html__( 'ON / OFF Banner Section', 'medo-pixel' ),
				'section'  => 'medo_pixel_banner_section',
				'settings' => 'medo_pixel_banner_section_on_off_setting',
			)
		)
	);

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

	$wp_customize->add_control(
		'medo_pixel_banner_heading',
		array(
			'label'           => sprintf( esc_html__( 'Banner Heading', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_banner_section',
			'settings'        => 'medo_pixel_banner_heading' ,
			'type'            => 'text',
		)
	);

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

	$wp_customize->add_control(
		'medo_pixel_banner_text',
		array(
			'label'           => sprintf( esc_html__( 'Banner Content', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_banner_section',
			'settings'        => 'medo_pixel_banner_text' ,
			'type'            => 'text',
		)
	);

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

	$wp_customize->add_control(
		'medo_pixel_banner_button_link',
		array(
			'label'           => sprintf( esc_html__( 'Banner Button Link', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_banner_section',
			'settings'        => 'medo_pixel_banner_button_link' ,
			'type'            => 'url',
		)
	);

	$wp_customize->add_setting(
		'medo_pixel_banner_button_text',
		array(
			'default'           => 'Get A Quote',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'medo_pixel_banner_button_text',
		array(
			'label'           => sprintf( esc_html__( 'Banner Button Text', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_banner_section',
			'settings'        => 'medo_pixel_banner_button_text' ,
			'type'            => 'text',
		)
	);

	$wp_customize->add_setting(
		'medo_pixel_banner_image',
		array(
        	'default'           => '',
        	'sanitize_callback' => 'medo_pixel_sanitize_image',

    	)
    );
    
    $wp_customize->add_control(
     	new WP_Customize_Image_Control(
    		$wp_customize, 'medo_pixel_banner_image', 
    		array(
    			'label'           => sprintf( esc_html__( 'Banner Image', 'medo-pixel' ), ),
		        'settings'  => 'medo_pixel_banner_image',
		        'section'   => 'medo_pixel_banner_section'
    		) 
    	)
    );

    // About Us Option

	$wp_customize->add_section(
		'medo_pixel_about_section',
		array(
			'panel'      => 'medo_pixel_frontpage_sections_settings_panel',
			'title'    => esc_html__( 'About Us Options', 'medo-pixel' ),
		)
	);

	$wp_customize->add_setting(
		'medo_pixel_about_section_on_off_setting',
		array(
			'default'           => false,
			'sanitize_callback' => 'medo_pixel_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new Medo_Pixel_On_Off_Custom_Control(
			$wp_customize,
			'medo_pixel_about_section_on_off_setting',
			array(
				'label'    => esc_html__( 'ON / OFF About Us Section', 'medo-pixel' ),
				'section'  => 'medo_pixel_about_section',
				'settings' => 'medo_pixel_about_section_on_off_setting',
			)
		)
	);

	$wp_customize->add_setting(
		'medo_pixel_about_image_big',
		array(
        	'default'           => '',
        	'sanitize_callback' => 'medo_pixel_sanitize_image',
    	)
    );
    
    $wp_customize->add_control(
     	new WP_Customize_Image_Control(
    		$wp_customize, 'medo_pixel_about_image_big', 
    		array(
    			'label'           => sprintf( esc_html__( 'About Big Image', 'medo-pixel' ), ),
		        'settings'  => 'medo_pixel_about_image_big',
		        'section'   => 'medo_pixel_about_section'
    		) 
    	)
    );

    $wp_customize->add_setting(
		'medo_pixel_about_image_small',
		array(
        	'default'           => '',
        	'sanitize_callback' => 'medo_pixel_sanitize_image',
    	)
    );
    
    $wp_customize->add_control(
     	new WP_Customize_Image_Control(
    		$wp_customize, 'medo_pixel_about_image_small', 
    		array(
    			'label'           => sprintf( esc_html__( 'About Small Image', 'medo-pixel' ), ),
		        'settings'  => 'medo_pixel_about_image_small',
		        'section'   => 'medo_pixel_about_section'
    		) 
    	)
    );

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

	$wp_customize->add_control(
		'medo_pixel_about_short_heading',
		array(
			'label'           => sprintf( esc_html__( 'About Short Heading', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_about_section',
			'settings'        => 'medo_pixel_about_short_heading' ,
			'type'            => 'text',
		)
	);

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

	$wp_customize->add_control(
		'medo_pixel_about_heading',
		array(
			'label'           => sprintf( esc_html__( 'About Heading', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_about_section',
			'settings'        => 'medo_pixel_about_heading' ,
			'type'            => 'text',
		)
	);

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

	$wp_customize->add_control(
		'medo_pixel_about_content',
		array(
			'label'           => sprintf( esc_html__( 'About Content', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_about_section',
			'settings'        => 'medo_pixel_about_content' ,
			'type'            => 'text',
		)
	);

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

	$wp_customize->add_control(
		'medo_pixel_about_button_link',
		array(
			'label'           => sprintf( esc_html__( 'About Button Link', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_about_section',
			'settings'        => 'medo_pixel_about_button_link' ,
			'type'            => 'url',
		)
	);

	$wp_customize->add_setting(
		'medo_pixel_about_button_text',
		array(
			'default'           => 'Get A Quote',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'medo_pixel_about_button_text',
		array(
			'label'           => sprintf( esc_html__( 'About Button Text', 'medo-pixel' ), ),
			'section'         => 'medo_pixel_about_section',
			'settings'        => 'medo_pixel_about_button_text' ,
			'type'            => 'text',
		)
	);

	// Footer Option

	$wp_customize->add_section(
        'medo_pixel_footer_widgets_section',
        array(
            'panel'      => 'medo_pixel_footer_settings_panel',
            'title'    => esc_html__( 'Footer Widgets Options', 'medo-pixel' ),
        )
    );

	$wp_customize->add_setting(
		'medo_pixel_footer_widgets_section_on_off_setting',
		array(
			'default'           => true,
			'sanitize_callback' => 'medo_pixel_sanitize_on_off',
		)
	);

	$wp_customize->add_control(
		new medo_pixel_On_Off_Custom_Control(
			$wp_customize,
			'medo_pixel_footer_widgets_section_on_off_setting',
			array(
				'label'    => esc_html__( 'ON / OFF Footer Widgets', 'medo-pixel' ),
				'section'  => 'medo_pixel_footer_widgets_section',
				'settings' => 'medo_pixel_footer_widgets_section_on_off_setting',
			)
		)
	);

	$wp_customize->add_setting( 'medo_pixel_footer_widget_background_color', array(
		    'default' => '',
		    'sanitize_callback' => 'sanitize_hex_color'
		));
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'medo_pixel_footer_widget_background_color', array(
		    'label'     => __('Footer Widget Background Color', 'medo-pixel'),
		    'description' => __('It will change the complete footer widget background color.', 'medo-pixel'),
		    'section' => 'medo_pixel_footer_widgets_section',
		    'settings' => 'medo_pixel_footer_widget_background_color',
		)));

		$wp_customize->add_setting('medo_pixel_footer_widget_background_image',array(
		    'default'   => '',
		    'sanitize_callback' => 'esc_url_raw',
		));
		$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize,'medo_pixel_footer_widget_background_image',array(
		    'label' => __('Footer Widget Background Image','medo-pixel'),
		    'section' => 'medo_pixel_footer_widgets_section'
		)));
	
	$wp_customize->add_section(
        'medo_pixel_copyright_section',
        array(
            'panel'      => 'medo_pixel_footer_settings_panel',
            'title'    => esc_html__( 'Copyright Options', 'medo-pixel' ),
        )
    );

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

    $wp_customize->add_control(
        'medo_pixel_footer_text',
        array(
            'label'           => sprintf( esc_html__( 'Edit Copyright Text', 'medo-pixel' ), ),
            'section'         => 'medo_pixel_copyright_section',
            'settings'        => 'medo_pixel_footer_text' ,
            'type'            => 'text',
        )
    );

    // Add Settings and Controls for Scroll top
    $wp_customize->add_setting('medo_pixel_scroll_top_position',array(
        'default' => 'Right',
        'sanitize_callback' => 'medo_pixel_sanitize_choices'
    ));
    $wp_customize->add_control('medo_pixel_scroll_top_position',array(
        'type' => 'radio',
        'label'     => __('Scroll to top Position', 'medo-pixel'),
        'description'   => __('This option work for scroll to top', 'medo-pixel'),
       'section' => 'medo_pixel_copyright_section',
       'choices' => array(
            'Right' => __('Right','medo-pixel'),
            'Left' => __('Left','medo-pixel'),
            'Center' => __('Center','medo-pixel')
     ),
    ) );
	

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

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

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

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

		static $medo_pixel_instance = null;

		if ( is_null( $medo_pixel_instance ) ) {
			$medo_pixel_instance = new self;
			$medo_pixel_instance->Medo_Pixel_setup_actions();
		}

		return $medo_pixel_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 Medo_Pixel_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  $medo_pixel_manager
	 * @return void
	*/
	public function sections( $medo_pixel_manager ) {
		load_template( trailingslashit( get_template_directory() ) . '/inc/medo-pixel-section-pro.php' );

		$medo_pixel_manager->register_section_type( 'Medo_Pixel_Customize_Section_Pro' );

		$medo_pixel_manager->add_section( new Medo_Pixel_Customize_Section_Pro( $medo_pixel_manager,'medo_pixel_buy_now', array(
			'priority'   => 1,
			'title'    => esc_html__( 'Buy Medo Pixel Pro', 'medo-pixel' ),
			'pro_text' => esc_html__( 'Buy Pro Theme', 'medo-pixel' ),
			'pro_url'    => esc_url( MEDO_PIXEL_BUY_NOW ),
		) )	);

		$medo_pixel_manager->add_section( new Medo_Pixel_Customize_Section_Pro( $medo_pixel_manager, 'medo_pixel_live_demo', array(
		    'priority'   => 1,
		    'title'      => esc_html__( 'Preview Pro Theme', 'medo-pixel' ),
		    'pro_text'   => esc_html__( 'View Live Demo', 'medo-pixel' ),
		    'pro_url'    => esc_url( MEDO_PIXEL_LIVE_DEMO ),
		) ) );	
	}

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

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

		wp_enqueue_style( 'medo-pixel-customize-controls', trailingslashit( get_template_directory_uri() ) . '/assets/css/customize-controls.css' );
	}
}
Medo_Pixel_Customize_Buttons::Medo_Pixel_get_instance();