<?php

function legal_law_consulting_remove_customize_register() {
    global $wp_customize;
    $wp_customize->remove_section( 'lawyer_hub_social_media' );

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

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

    $wp_customize->remove_setting( 'lawyer_hub_footer_widget_image' );
    $wp_customize->remove_control( 'lawyer_hub_footer_widget_image' );
}
add_action( 'customize_register', 'legal_law_consulting_remove_customize_register', 11 );


if ( ! defined( 'LEGAL_LAW_CONSULTING_TEXT' ) ) {
    define( 'LEGAL_LAW_CONSULTING_TEXT', __( 'Law Firm Attorney Pro','legal-law-consulting' ));
}
if ( ! defined( 'LEGAL_LAW_CONSULTING_BUY_TEXT' ) ) {
    define( 'LEGAL_LAW_CONSULTING_BUY_TEXT', __( 'Upgrade Pro','legal-law-consulting' ));
}


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

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

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

    $manager->add_section(
        new lawyer_hub_Button( $manager, 'lawyer_hub_pro', [
            'title'       => esc_html( LEGAL_LAW_CONSULTING_TEXT,'legal-law-consulting' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'legal-law-consulting' ),
            'button_url'  => esc_url( LAWYER_HUB_PRO_THEME_URL )
        ] )
    );

} );

function legal_law_consulting_customize_register( $wp_customize ) {
    // Register the custom control type.
    $wp_customize->register_control_type( 'Legal_Law_Consulting_Toggle_Control' );

    // Pro Version
    class legal_law_consulting_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( LEGAL_LAW_CONSULTING_BUY_TEXT,'legal-law-consulting' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

    // Services
    $wp_customize->add_section( 'legal_law_consulting_services', array(
        'title'      => __( 'Service Section', 'legal-law-consulting' ),
        'priority' => 4,
        'description' => __( 'Add your law firm services', 'legal-law-consulting' ),
        'panel' => 'lawyer_hub_panel_id'
    ) );

    $wp_customize->add_setting( 'legal_law_consulting_services_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'lawyer_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Legal_Law_Consulting_Toggle_Control( $wp_customize, 'legal_law_consulting_services_show_hide', array(
        'label'       => esc_html__( 'Show / Hide section', 'legal-law-consulting' ),
        'section'     => 'legal_law_consulting_services',
        'type'        => 'toggle',
        'settings'    => 'legal_law_consulting_services_show_hide',
    ) ) );

    $wp_customize->add_setting( 'legal_law_consulting_services_animation', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'lawyer_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new lawyer_hub_Toggle_Control( $wp_customize, 'legal_law_consulting_services_animation', array(
        'label'       => esc_html__( 'Show / Hide Section Animation', 'legal-law-consulting' ),
        'priority' => 1,
        'section'     => 'legal_law_consulting_services',
        'type'        => 'toggle',
        'settings'    => 'legal_law_consulting_services_animation',
    ) ) );

    $wp_customize->add_setting('legal_law_consulting_services_title',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('legal_law_consulting_services_title',array(
        'label' => __('Add Section Title','legal-law-consulting'),
        'section'=> 'legal_law_consulting_services',
        'type'=> 'text'
    ));
    $wp_customize->add_setting('legal_law_consulting_services_text',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('legal_law_consulting_services_text',array(
        'label' => __('Add Section Text','legal-law-consulting'),
        'section'=> 'legal_law_consulting_services',
        'type'=> 'text'
    ));
    $wp_customize->add_setting('legal_law_consulting_services_btn_text',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('legal_law_consulting_services_btn_text',array(
        'label' => __('Add Section Button Text','legal-law-consulting'),
        'section'=> 'legal_law_consulting_services',
        'type'=> 'text'
    ));
    $wp_customize->add_setting('legal_law_consulting_services_btn_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('legal_law_consulting_services_btn_url',array(
        'label' => __('Add Section Button URL','legal-law-consulting'),
        'section'=> 'legal_law_consulting_services',
        'type'=> 'url'
    ));
    $categories = get_categories();
    $cats = array();
    $i = 0;
    $services_cat[]= 'select';
    foreach($categories as $category){
        if($i==0){
            $default = $category->slug;
            $i++;
        }
        $services_cat[$category->slug] = $category->name;
    }
    $wp_customize->add_setting('legal_law_consulting_services_section_category',array(
        'default'   => 'select',
        'sanitize_callback' => 'legal_law_consulting_sanitize_select',
    ));
    $wp_customize->add_control('legal_law_consulting_services_section_category',array(
        'type'    => 'select',
        'choices' => $services_cat,
        'label' => __('Select Category','legal-law-consulting'),
        'section' => 'legal_law_consulting_services',
    ));

    // Pro Version
    $wp_customize->add_setting( 'legal_law_consulting_services_pro_version_logo', array(
        'sanitize_callback' => 'legal_law_consulting_sanitize_custom_control'
    ));
    $wp_customize->add_control( new legal_law_consulting_Customize_Pro_Version ( $wp_customize,'legal_law_consulting_services_pro_version_logo', array(
        'section'     => 'legal_law_consulting_services',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'legal-law-consulting' ),
        'description' => esc_url( LAWYER_HUB_PRO_THEME_URL ),
        'priority'    => 10,
    )));
}
add_action( 'customize_register', 'legal_law_consulting_customize_register' );
