<?php

function welding_workshop_remove_customize_register() {
    global $wp_customize;
    $wp_customize->remove_section( 'construction_hub_about_section' );

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

    $wp_customize->remove_setting( 'construction_hub_slider_arrow' );
    $wp_customize->remove_control( 'construction_hub_slider_arrow' );
}
add_action( 'customize_register', 'welding_workshop_remove_customize_register', 11 );

if ( ! defined( 'WELDING_WORKSHOP_TEXT' ) ) {
    define( 'WELDING_WORKSHOP_TEXT', __( 'Construction Renovation Pro','welding-workshop' ));
}
if ( ! defined( 'WELDING_WORKSHOP_BUY_TEXT' ) ) {
    define( 'WELDING_WORKSHOP_BUY_TEXT', __( 'Upgrade Pro','welding-workshop' ));
}

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( WELDING_WORKSHOP_TEXT,'welding-workshop' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'welding-workshop' ),
            'button_url'  => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL )
        ] )
    );

} );

function welding_workshop_customize_register( $wp_customize ) {

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

    // Pro Version
    class Welding_Workshop_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( WELDING_WORKSHOP_BUY_TEXT,'welding-workshop' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

    $wp_customize->add_setting('welding_workshop_slider_content_layout',array(
        'default' => 'LEFT-ALIGN',
        'sanitize_callback' => 'construction_hub_sanitize_choices'
    ));
    $wp_customize->add_control('welding_workshop_slider_content_layout',array(
        'type' => 'radio',
        'label'     => __('Slider Content Layout', 'welding-workshop'),
        'section' => 'construction_hub_slider_section',
        'choices' => array(
            'LEFT-ALIGN' => __('LEFT-ALIGN','welding-workshop'),
            'CENTER-ALIGN' => __('CENTER-ALIGN','welding-workshop'),
            'RIGHT-ALIGN' => __('RIGHT-ALIGN','welding-workshop'),
        ),
    ) );

    //Social Media
    $wp_customize->add_section( 'welding_workshop_social_media', array(
        'title'      => __( 'Social Media Links', 'welding-workshop' ),
        'priority' => 7,
        'description' => __( 'Add your Social Links', 'welding-workshop' ),
        'panel' => 'construction_hub_panel_id'
    ) );

    $wp_customize->add_setting('welding_workshop_facebook_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('welding_workshop_facebook_url',array(
        'label' => __('Facebook Link','welding-workshop'),
        'section'=> 'welding_workshop_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('welding_workshop_twitter_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('welding_workshop_twitter_url',array(
        'label' => __('Twitter Link','welding-workshop'),
        'section'=> 'welding_workshop_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('welding_workshop_instagram_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('welding_workshop_instagram_url',array(
        'label' => __('Instagram Link','welding-workshop'),
        'section'=> 'welding_workshop_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('welding_workshop_youtube_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('welding_workshop_youtube_url',array(
        'label' => __('YouTube Link','welding-workshop'),
        'section'=> 'welding_workshop_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('welding_workshop_pint_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('welding_workshop_pint_url',array(
        'label' => __('Pinterest Link','welding-workshop'),
        'section'=> 'welding_workshop_social_media',
        'type'=> 'url'
    ));

      $wp_customize->add_setting('welding_workshop_social_icon_fontsize',array(
        'default'=> '14',
        'sanitize_callback' => 'welding_workshop_sanitize_number_absint'
        ));
    $wp_customize->add_control('welding_workshop_social_icon_fontsize',array(
        'label' => __('Social Icons Font Size in PX','welding-workshop'),
        'type'=> 'number',
        'section'=> 'welding_workshop_social_media',
        'input_attrs' => array(
          'step' => 1,
          'min'  => 0,
          'max'  => 30,
            ),
    ));

    // Pro Version
    $wp_customize->add_setting( 'welding_workshop_social_media_pro_version_logo', array(
        'sanitize_callback' => 'welding_workshop_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Welding_Workshop_Customize_Pro_Version ( $wp_customize,'welding_workshop_social_media_pro_version_logo', array(
        'section'     => 'welding_workshop_social_media',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'welding-workshop' ),
        'description' => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL ),
        'priority'    => 10,
    )));

    $wp_customize->add_setting( 'welding_workshop_slider_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'construction_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Welding_Workshop_Toggle_Control( $wp_customize, 'welding_workshop_slider_show_hide', array(
        'label'       => esc_html__( 'Show / Hide Slider section', 'welding-workshop' ),
        'priority' => 1,
        'section'     => 'construction_hub_slider_section',
        'type'        => 'toggle',
        'settings'    => 'welding_workshop_slider_show_hide',
    ) ) );

    //Projects
    $wp_customize->add_section('welding_workshop_projects',array(
        'title' => __('Projects Section','welding-workshop'),
        'panel' => 'construction_hub_panel_id',
        'priority' => 9,
    ));

    $wp_customize->add_setting( 'welding_workshop_project_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'construction_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Welding_Workshop_Toggle_Control( $wp_customize, 'welding_workshop_project_show_hide', array(
        'label'       => esc_html__( 'Show / Hide section', 'welding-workshop' ),
        'section'     => 'welding_workshop_projects',
        'type'        => 'toggle',
        'settings'    => 'welding_workshop_project_show_hide',
    ) ) );

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

    $wp_customize->add_setting('welding_workshop_projetcs_main_text',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('welding_workshop_projetcs_main_text',array(
        'label' => esc_html__('Section Heading Text','welding-workshop'),
        'section'=> 'welding_workshop_projects',
        'type'=> 'text'
    ));

    $wp_customize->add_setting('welding_workshop_projetcs_main_heading',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('welding_workshop_projetcs_main_heading',array(
        'label' => esc_html__('Section Heading','welding-workshop'),
        'section'=> 'welding_workshop_projects',
        'type'=> 'text'
    ));

    $wp_customize->add_setting('welding_workshop_projetcs_number',array(
        'default'=> '6',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('welding_workshop_projetcs_number',array(
        'label' => esc_html__('No of Tabs to show','welding-workshop'),
        'section'=> 'welding_workshop_projects',
        'type' => 'number',
        'input_attrs' => array(
        'step'  => 1,
         'min'  => 0,
         'max'  => 4,
         ),
    ));

    $featured_post = get_theme_mod('welding_workshop_projetcs_number','6');
    for ( $j = 1; $j <= $featured_post; $j++ ) {
        $wp_customize->add_setting('welding_workshop_projetcs_text'.$j,array(
            'default'=> '',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('welding_workshop_projetcs_text'.$j,array(
            'label' => esc_html__('Tab ','welding-workshop').$j,
            'section'=> 'welding_workshop_projects',
            'type'=> 'text'
        ));

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

        $wp_customize->add_setting('welding_workshop_projetcs_category'.$j,array(
            'default'   => 'select',
            'sanitize_callback' => 'welding_workshop_sanitize_choices',
        ));
        $wp_customize->add_control('welding_workshop_projetcs_category'.$j,array(
            'type'    => 'select',
            'choices' => $cat_posts,
            'label' => __('Select Category to display projects','welding-workshop'),
            'section' => 'welding_workshop_projects',
        ));
    }

    $wp_customize->add_setting('welding_workshop_slider_top',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('welding_workshop_slider_top',array(
        'label' => esc_html__('Add Slider Top Text','welding-workshop'),
        'section'=> 'construction_hub_slider_section',
        'type'=> 'text'
    ));

    // Pro Version
    $wp_customize->add_setting( 'welding_workshop_services_pro_version_logo', array(
        'sanitize_callback' => 'welding_workshop_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Welding_Workshop_Customize_Pro_Version ( $wp_customize,'welding_workshop_services_pro_version_logo', array(
        'section'     => 'welding_workshop_projects',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'welding-workshop' ),
        'description' => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL ),
        'priority'    => 10,
    )));
}
add_action( 'customize_register', 'welding_workshop_customize_register' );
