<?php

function car_repair_remove_customize_register() {
    global $wp_customize;

    $wp_customize->remove_setting( 'automobile_hub_menu_font_size' );
    $wp_customize->remove_control( 'automobile_hub_menu_font_size' );

    $wp_customize->remove_setting( 'automobile_hub_mail_icon' );
    $wp_customize->remove_control( 'automobile_hub_mail_icon' );

    $wp_customize->remove_setting( 'automobile_hub_call_icon' );
    $wp_customize->remove_control( 'automobile_hub_call_icon' );
    
    $wp_customize->remove_setting( 'automobile_hub_slider_icon' );
    $wp_customize->remove_control( 'automobile_hub_slider_icon' );
}
add_action( 'customize_register', 'car_repair_remove_customize_register', 11 );

if ( ! defined( 'CAR_REPAIR_TEXT' ) ) {
    define( 'CAR_REPAIR_TEXT', __( 'Car Repair Pro','car-repair' ));
}
if ( ! defined( 'CAR_REPAIR_BUY_TEXT' ) ) {
    define( 'CAR_REPAIR_BUY_TEXT', __( 'Upgrade Pro','car-repair' ));
}


add_action( 'customize_register', function( $manager ) {

// Load custom sections.
load_template( trailingslashit( get_template_directory() ) . '/inc/section-pro.php' );

    $manager->register_section_type( Automobile_Hub_Button::class );

    $manager->add_section(
        new Automobile_Hub_Button( $manager, 'automobile_hub_pro', [
            'title'       => esc_html( CAR_REPAIR_TEXT,'car-repair' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'car-repair' ),
            'button_url'  => esc_url( AUTOMOBILE_HUB_PRO_THEME_URL )
        ] )
    );

} );

function car_repair_customize_register( $wp_customize ) {

	// Pro Version
    class car_repair_Customize_Pro_Version extends WP_Customize_Control {
        public $type = 'pro_options';

        public function render_content() {
            echo '<span>Unlock Premium <strong>'. esc_html( $this->label ) .'</strong>? </span>';
            echo '<a href="'. esc_url($this->description) .'" target="_blank">';
                echo '<span class="dashicons dashicons-info"></span>';
                echo '<strong> '. esc_html( CAR_REPAIR_BUY_TEXT,'car-repair' ) .'<strong></a>';
            echo '</a>';
        }
    }

    // Custom Controls
    function car_repair_sanitize_custom_control( $input ) {
        return $input;
    }

	$wp_customize->add_setting('automobile_hub_address_text',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('automobile_hub_address_text',array(
		'label'	=> __('Add Location Text','car-repair'),
		'section'	=> 'automobile_hub_topbar',
		'type'		=> 'text'
	)); 
	
	$wp_customize->selective_refresh->add_partial( 'automobile_hub_address_text', array(
		'selector' => '.headerbox p',
		'render_callback' => 'automobile_hub_address_text_customize_partial_automobile_hub_address_text',
	) );
	$wp_customize->add_setting('automobile_hub_address',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('automobile_hub_address',array(
		'label'	=> __('Add Location','car-repair'),
		'section'	=> 'automobile_hub_topbar',
		'type'		=> 'text'
	));

	$wp_customize->add_setting('car_repair_button2_text',array(
		'default' => 'CONTACT NOW',
		'sanitize_callback' => 'sanitize_text_field',
		'capability' => 'edit_theme_options',
	));
	$wp_customize->add_control( 'car_repair_button2_text', array(
	   'settings' => 'car_repair_button2_text',
	   'section'   => 'automobile_hub_slider_section',
	   'label' => __('Add Button 2 Text', 'car-repair'),
	   'type'      => 'text'
	));

	$wp_customize->add_setting('car_repair_button2_url',array(
		'default' => '',
		'sanitize_callback' => 'esc_url_raw',
		'capability' => 'edit_theme_options',
	));
	$wp_customize->add_control( 'car_repair_button2_url', array(
	   'settings' => 'car_repair_button2_url',
	   'section'   => 'automobile_hub_slider_section',
	   'label' => __('Add Button 2 URL', 'car-repair'),
	   'type'      => 'url'
	));

	//TP Color Option
	$wp_customize->add_section('car_repair_color_option',array(
     'title'         => __('TP Color Option', 'car-repair'),
     'priority' => 1,
     'panel' => 'car_repair_panel_id'
    ) );
	$wp_customize->add_setting( 'car_repair_tp_color_option', array(
	    'default' => '#fff',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'car_repair_tp_color_option', array(
	    'description' => __('It will change the complete theme color in one click.', 'car-repair'),
	    'section' => 'car_repair_color_option',
	    'settings' => 'car_repair_tp_color_option',
  	)));
  	$wp_customize->add_setting( 'car_repair_tp_color_option_link', array(
	    'default' => '#000',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'car_repair_tp_color_option_link', array(
	    'description' => __('It will change the complete theme hover link color in one click.', 'car-repair'),
	    'section' => 'car_repair_color_option',
	    'settings' => 'car_repair_tp_color_option_link',
  	)));

	//TP Color Option
	$wp_customize->add_section('automobile_hub_color_option',array(
     'title'         => __('TP Color Option', 'car-repair'),
     'priority' => 1,
     'panel' => 'automobile_hub_panel_id'
    ) );
	$wp_customize->add_setting( 'automobile_hub_tp_color_option', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'automobile_hub_tp_color_option', array(
	    'description' => __('It will change the complete theme color in one click.', 'car-repair'),
	    'section' => 'automobile_hub_color_option',
	    'settings' => 'automobile_hub_tp_color_option',
  	)));
  	$wp_customize->add_setting( 'automobile_hub_tp_color_option_link', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_hex_color'
  	));
  	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'automobile_hub_tp_color_option_link', array(
	    'description' => __('It will change the complete theme hover link color in one click.', 'car-repair'),
	    'section' => 'automobile_hub_color_option',
	    'settings' => 'automobile_hub_tp_color_option_link',
  	)));


  	//Best Seller Products Section
	$wp_customize->add_section('car_repair_best_seller_products_section',array(
		'title'	=> __('Our Products Section','car-repair'),
		'panel' => 'automobile_hub_panel_id',
		'priority' => '4',
	));

	$wp_customize->add_setting( 'car_repair_product_show_hide', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'automobile_hub_sanitize_checkbox',
	) );
	$wp_customize->add_control( new Automobile_Hub_Toggle_Control( $wp_customize, 'car_repair_product_show_hide', array(
		'label'       => esc_html__( 'Show /hide Product Section', 'car-repair' ),
		'section'     => 'car_repair_best_seller_products_section',
		'type'        => 'toggle',
		'settings'    => 'car_repair_product_show_hide',
	) ) );

	$wp_customize->add_setting( 'car_repair_product_sec_animation', array(
		'default'           => true,
		'transport'         => 'refresh',
		'sanitize_callback' => 'automobile_hub_sanitize_checkbox',
	) );
	$wp_customize->add_control( new Automobile_Hub_Toggle_Control( $wp_customize, 'car_repair_product_sec_animation', array(
		'label'       => esc_html__( 'Show / Hide Product Section Animation', 'automobile-hub' ),
		'priority' => 1,
		'section'     => 'car_repair_best_seller_products_section',
		'type'        => 'toggle',
		'settings'    => 'car_repair_product_sec_animation',
	) ) );

	$wp_customize->add_setting('car_repair_featured_car_section_short_title', array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	));	
	$wp_customize->add_control('car_repair_featured_car_section_short_title', array(
		'label'    => __('Short Title','automobile-hub'),
		'section'  => 'car_repair_best_seller_products_section',
		'type'     => 'text',
	));

	$wp_customize->add_setting('car_repair_featured_car_section_tittle', array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	));	
	$wp_customize->add_control('car_repair_featured_car_section_tittle', array(
		'label'    => __('Main Title','automobile-hub'),
		'section'  => 'car_repair_best_seller_products_section',
		'type'     => 'text',
	));

	$wp_customize->add_setting('car_repair_featured_car_button_text', array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	));	
	$wp_customize->add_control('car_repair_featured_car_button_text', array(
		'label'    => __('Button Text','automobile-hub'),
		'section'  => 'car_repair_best_seller_products_section',
		'type'     => 'text',
	));

	$wp_customize->add_setting('car_repair_featured_car_button_link', array(
		'default'           => '',
		'sanitize_callback' => 'esc_url_raw',
	));	
	$wp_customize->add_control('car_repair_featured_car_button_link', array(
		'label'    => __('Button Link','automobile-hub'),
		'section'  => 'car_repair_best_seller_products_section',
		'type'     => 'url',
	));

	  	// Retrieve the default product page ID from theme mod
		$default_product_page_id = get_theme_mod('car_repair_bestseller_product_page');

		$wp_customize->add_setting('car_repair_bestseller_product_page', array(
			'default'           => $default_product_page_id, // Set the default dynamically
			'sanitize_callback' => 'automobile_hub_sanitize_dropdown_pages'
		));
		$wp_customize->add_control('car_repair_bestseller_product_page', array(
			'label'           => __('Select Products Page', 'car-repair'),
			'section'         => 'car_repair_best_seller_products_section',
			'type'            => 'dropdown-pages'
		));

		// Pro Version
    $wp_customize->add_setting( 'car_repair_product_pro_version_logo', array(
        'sanitize_callback' => 'car_repair_sanitize_custom_control'
    ));
    $wp_customize->add_control( new car_repair_Customize_Pro_Version ( $wp_customize,'car_repair_product_pro_version_logo', array(
        'section'     => 'car_repair_best_seller_products_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'car-repair' ),
        'description' => esc_url( AUTOMOBILE_HUB_PRO_THEME_URL ),
        'priority'    => 10,
    )));

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

	if ( ! defined( 'AUTOMOBILE_HUB_PRO_THEME_NAME' ) ) {
		define( 'AUTOMOBILE_HUB_PRO_THEME_NAME', esc_html__( 'Car Repair Pro Theme', 'car-repair' ));
	}
	if ( ! defined( 'AUTOMOBILE_HUB_PRO_THEME_URL' ) ) {
		define( 'AUTOMOBILE_HUB_PRO_THEME_URL', esc_url('https://www.themespride.com/products/car-repair-wordpress-theme'));
	}
