<?php

function construction_engineering_remove_customize_register() {
   global $wp_customize;

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

    $wp_customize->remove_setting( 'construction_hub_tp_color_option_link' );
    $wp_customize->remove_control( 'construction_hub_tp_color_option_link' );
}
add_action( 'customize_register', 'construction_engineering_remove_customize_register', 11 );

if ( ! defined( 'CONSTRUCTION_ENGINEERING_TEXT' ) ) {
    define( 'CONSTRUCTION_ENGINEERING_TEXT', __( 'Construction Renovation Pro','construction-engineering' ));
}
if ( ! defined( 'CONSTRUCTION_ENGINEERING_BUY_TEXT' ) ) {
    define( 'CONSTRUCTION_ENGINEERING_BUY_TEXT', __( 'Upgrade Pro','construction-engineering' ));
}


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

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

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

    $manager->add_section(
        new Construction_Hub_Button( $manager, 'construction_hub_pro', [
            'title'       => esc_html( CONSTRUCTION_ENGINEERING_TEXT,'construction-engineering' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'construction-engineering' ),
            'button_url'  => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL )
        ] )
    );

} );

function construction_engineering_customize_register( $wp_customize ) {

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

    // Pro Version
    class Construction_Engineering_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( CONSTRUCTION_ENGINEERING_BUY_TEXT,'construction-engineering' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

    // Our Services Section
    $wp_customize->add_section('construction_engineering_services_section',array(
        'title' => __('Our Services Section','construction-engineering'),
        'panel' => 'construction_hub_panel_id',
        'priority' => 9,
    ));

    $wp_customize->add_setting( 'construction_engineering_service_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'construction_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Construction_Engineering_Toggle_Control( $wp_customize, 'construction_engineering_service_show_hide', array(
        'label'       => esc_html__( 'Show / Hide section', 'construction-engineering' ),
        'section'     => 'construction_engineering_services_section',
        'type'        => 'toggle',
        'settings'    => 'construction_engineering_service_show_hide',
    ) ) );

    $wp_customize->add_setting( 'construction_engineering_service_sec_animation', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'construction_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new construction_hub_Toggle_Control( $wp_customize, 'construction_engineering_service_sec_animation', array(
        'label'       => esc_html__( 'Show / Hide Section Animation', 'construction-engineering' ),
        'priority' => 1,
        'section'     => 'construction_engineering_services_section',
        'type'        => 'toggle',
        'settings'    => 'construction_engineering_service_sec_animation',
    ) ) );

    $wp_customize->add_setting('construction_engineering_services_heading',array(
        'default' => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('construction_engineering_services_heading',array(
        'label' => __('Section Title','construction-engineering'),
        'section'   => 'construction_engineering_services_section',
        'type'      => 'text'
    ));
    $wp_customize->selective_refresh->add_partial( 'construction_engineering_services_heading', array(
        'selector' => '#our_services h2',
        'render_callback' => 'construction_engineering_customize_partial_construction_engineering_services_heading',
    ) );

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

    $wp_customize->add_setting('construction_engineering_services_section_category',array(
        'default'   => 'select',
        'sanitize_callback' => 'construction_hub_sanitize_choices',
    ));
    $wp_customize->add_control('construction_engineering_services_section_category',array(
        'type'    => 'select',
        'choices' => $offer_cat,
        'label' => __('Select Category','construction-engineering'),
        'section' => 'construction_engineering_services_section',
    ));

    $wp_customize->add_setting('construction_engineering_slider_text',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('construction_engineering_slider_text',array(
        'label' => __('Add Slider Top Text','construction-engineering'),
        'section'=> 'construction_hub_slider_section',
        'type'=> 'text'
    ));

    // Pro Version
    $wp_customize->add_setting( 'construction_engineering_services_pro_version_logo', array(
        'sanitize_callback' => 'construction_engineering_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Construction_Engineering_Customize_Pro_Version ( $wp_customize,'construction_engineering_services_pro_version_logo', array(
        'section'     => 'construction_engineering_services_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'construction-engineering' ),
        'description' => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL ),
        'priority'    => 10,
    )));
}
add_action( 'customize_register', 'construction_engineering_customize_register' );
