<?php

function medical_medicare_remove_customize_register() {
    global $wp_customize;
    $wp_customize->remove_setting( 'online_pharmacy_footer_widget_image' );
    $wp_customize->remove_control( 'online_pharmacy_footer_widget_image' );
    $wp_customize->remove_setting( 'online_pharmacy_shopping_bag' );
    $wp_customize->remove_control( 'online_pharmacy_shopping_bag' );
    $wp_customize->remove_setting( 'online_pharmacy_slider_content_layout' );
    $wp_customize->remove_control( 'online_pharmacy_slider_content_layout' );

    $wp_customize->remove_setting( 'online_pharmacy_tp_color_sec' );
    $wp_customize->remove_control( 'online_pharmacy_tp_color_sec' );
}
add_action( 'customize_register', 'medical_medicare_remove_customize_register', 11 );


if ( ! defined( 'MEDICAL_MEDICARE_TEXT' ) ) {
    define( 'MEDICAL_MEDICARE_TEXT', __( 'Medical Medicare Pro','medical-medicare' ));
}
if ( ! defined( 'MEDICAL_MEDICARE_BUY_TEXT' ) ) {
    define( 'MEDICAL_MEDICARE_BUY_TEXT', __( 'Upgrade Pro','medical-medicare' ));
}

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

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

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

    $manager->add_section(
        new online_pharmacy_Button( $manager, 'online_pharmacy_pro', [
            'title'       => esc_html( MEDICAL_MEDICARE_TEXT,'medical-medicare' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'medical-medicare' ),
            'button_url'  => esc_url( ONLINE_PHARMACY_PRO_THEME_URL )
        ] )
    );

} );

function medical_medicare_customize_register( $wp_customize ) {

    // Pro Version
    class Medical_Medicare_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( MEDICAL_MEDICARE_BUY_TEXT,'medical-medicare' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

    // Register the custom control type.
    $wp_customize->register_control_type( 'Medical_Medicare_Toggle_Control' );


    $wp_customize->add_setting('medical_medicare_slider_content_layout',array(
        'default' => 'RIGHT-ALIGN',
        'sanitize_callback' => 'online_pharmacy_sanitize_choices'
    ));
    $wp_customize->add_control('medical_medicare_slider_content_layout',array(
        'type' => 'radio',
        'label'     => __('Slider Content Layout', 'medical-medicare'),
        'section' => 'online_pharmacy_slider_section',
        'choices' => array(
            'RIGHT-ALIGN' => __('RIGHT-ALIGN','medical-medicare'),
            'CENTER-ALIGN' => __('CENTER-ALIGN','medical-medicare'),
            'LEFT-ALIGN' => __('LEFT-ALIGN','medical-medicare'),
            
        ),
    ) );

   $wp_customize->add_section( 'medical_medicare_directions_section' , array(
        'title'      => __( 'Services Settings', 'medical-medicare' ),
        'priority' => 17,
        'panel' => 'online_pharmacy_panel_id'
    ) );

    $wp_customize->add_setting( 'medical_medicare_directions_section_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'online_pharmacy_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Medical_Medicare_Toggle_Control( $wp_customize, 'medical_medicare_directions_section_show_hide', array(
        'label'       => esc_html__( 'Show / Hide section', 'medical-medicare' ),
        'section'     => 'medical_medicare_directions_section',
        'type'        => 'toggle',
        'settings'    => 'medical_medicare_directions_section_show_hide',
    ) ) );

    $wp_customize->add_setting('medical_medicare_services_section_tittle',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('medical_medicare_services_section_tittle',array(
        'label' => __('Section Title','medical-medicare'),
        'section'   => 'medical_medicare_directions_section',
        'type'      => 'text'
    ));

    $categories = get_categories();
    $cats = array();
    $i = 0;
    $medical_medicare_offer_cat[]= 'select';
    foreach($categories as $category){
        if($i==0){
            $default = $category->slug;
            $i++;
        }
        $medical_medicare_offer_cat[$category->slug] = $category->name;
    }

    $wp_customize->add_setting('medical_medicare_services_section_category',array(
        'default'   => 'select',
        'sanitize_callback' => 'online_pharmacy_sanitize_choices',
    ));
    $wp_customize->add_control('medical_medicare_services_section_category',array(
        'type'    => 'select',
        'choices' => $medical_medicare_offer_cat,
        'label' => __('Select Category','medical-medicare'),
        'section' => 'medical_medicare_directions_section',
    ));

    // Pro Version
    $wp_customize->add_setting( 'medical_medicare_products_pro_version_logo', array(
        'sanitize_callback' => 'medical_medicare_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Medical_Medicare_Customize_Pro_Version ( $wp_customize,'medical_medicare_products_pro_version_logo', array(
        'section'     => 'medical_medicare_directions_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'medical-medicare' ),
        'description' => esc_url( ONLINE_PHARMACY_PRO_THEME_URL ),
        'priority'    => 10,
    )));

    //Slider height
    $wp_customize->add_setting('medical_medicare_slider_img_height',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('medical_medicare_slider_img_height',array(
        'label' => __('Slider Height','medical-medicare'),
        'description'   => __('Add slider height in px(eg. 700px).','medical-medicare'),
        'section'=> 'online_pharmacy_slider_section',
        'type'=> 'text'
    ));

    //Slider height
    $wp_customize->add_setting('medical_medicare_slider_img_height_responsive',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('medical_medicare_slider_img_height_responsive',array(
        'label' => __('Slider Height','medical-medicare'),
        'description'   => __('Add slider height in px(eg. 700px).','medical-medicare'),
        'section'=> 'online_pharmacy_mobile_media_option',
        'type'=> 'text'
    ));
}
add_action( 'customize_register', 'medical_medicare_customize_register' );
