<?php

function painting_contractor_remove_customize_register() {
    global $wp_customize;

    $wp_customize->remove_section( 'construction_hub_about_section' );

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

    $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' );

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

if ( ! defined( 'PAINTING_CONTRACTOR_TEXT' ) ) {
    define( 'PAINTING_CONTRACTOR_TEXT', __( 'Construction Renovation Pro','painting-contractor' ));
}
if ( ! defined( 'PAINTING_CONTRACTOR_BUY_TEXT' ) ) {
    define( 'PAINTING_CONTRACTOR_BUY_TEXT', __( 'Upgrade Pro','painting-contractor' ));
}

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

} );

function painting_contractor_customize_register( $wp_customize ) {

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

    // Pro Version
    class Painting_Contractor_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( PAINTING_CONTRACTOR_BUY_TEXT,'painting-contractor' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

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

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

    $wp_customize->add_setting('painting_contractor_facebook_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('painting_contractor_facebook_url',array(
        'label' => __('Facebook Link','painting-contractor'),
        'section'=> 'painting_contractor_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('painting_contractor_twitter_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('painting_contractor_twitter_url',array(
        'label' => __('Twitter Link','painting-contractor'),
        'section'=> 'painting_contractor_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('painting_contractor_instagram_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('painting_contractor_instagram_url',array(
        'label' => __('Instagram Link','painting-contractor'),
        'section'=> 'painting_contractor_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('painting_contractor_youtube_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('painting_contractor_youtube_url',array(
        'label' => __('YouTube Link','painting-contractor'),
        'section'=> 'painting_contractor_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('painting_contractor_pint_url',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('painting_contractor_pint_url',array(
        'label' => __('Pinterest Link','painting-contractor'),
        'section'=> 'painting_contractor_social_media',
        'type'=> 'url'
    ));

    $wp_customize->add_setting('painting_contractor_social_icon_fontsize',array(
        'default'=> '14',
        'sanitize_callback'	=> 'painting_contractor_sanitize_number_absint'
        ));
    $wp_customize->add_control('painting_contractor_social_icon_fontsize',array(
        'label'	=> __('Social Icons Font Size in PX','painting-contractor'),
        'type'=> 'number',
        'section'=> 'painting_contractor_social_media',
        'input_attrs' => array(
          'step' => 1,
          'min'  => 0,
          'max'  => 30,
            ),
    ));

    $wp_customize->add_setting( 'painting_contractor_slider_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'construction_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Painting_Contractor_Toggle_Control( $wp_customize, 'painting_contractor_slider_show_hide', array(
        'label'       => esc_html__( 'Show / Hide slider section', 'painting-contractor' ),
        'priority' => 1,
        'section'     => 'construction_hub_slider_section',
        'type'        => 'toggle',
        'settings'    => 'painting_contractor_slider_show_hide',
    ) ) );

    //Projects
    $wp_customize->add_section('painting_contractor_projects',array(
        'title' => __('Projects Section','painting-contractor'),
        'panel' => 'construction_hub_panel_id',
        'priority' => 9,
    ));

    $wp_customize->add_setting( 'painting_contractor_project_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'construction_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Painting_Contractor_Toggle_Control( $wp_customize, 'painting_contractor_project_show_hide', array(
        'label'       => esc_html__( 'Show / Hide section', 'painting-contractor' ),
        'section'     => 'painting_contractor_projects',
        'type'        => 'toggle',
        'settings'    => 'painting_contractor_project_show_hide',
    ) ) );

    $wp_customize->add_setting('painting_contractor_projetcs_main_text',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('painting_contractor_projetcs_main_text',array(
        'label' => esc_html__('Section Heading Text','painting-contractor'),
        'section'=> 'painting_contractor_projects',
        'type'=> 'text'
    ));

    $wp_customize->add_setting('painting_contractor_projetcs_main_heading',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('painting_contractor_projetcs_main_heading',array(
        'label' => esc_html__('Section Heading','painting-contractor'),
        'section'=> 'painting_contractor_projects',
        'type'=> 'text'
    ));

    $wp_customize->add_setting('painting_contractor_projetcs_btn_text',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('painting_contractor_projetcs_btn_text',array(
        'label' => esc_html__('Section Button Text','painting-contractor'),
        'section'=> 'painting_contractor_projects',
        'type'=> 'text'
    ));

    $wp_customize->add_setting('painting_contractor_projetcs_btn_url',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('painting_contractor_projetcs_btn_url',array(
        'label' => esc_html__('Section Button Url','painting-contractor'),
        'section'=> 'painting_contractor_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('painting_contractor_projetcs_category',array(
        'default'   => 'select',
        'sanitize_callback' => 'painting_contractor_sanitize_choices',
    ));
    $wp_customize->add_control('painting_contractor_projetcs_category',array(
        'type'    => 'select',
        'choices' => $cat_posts,
        'label' => __('Select Category to display projects','painting-contractor'),
        'section' => 'painting_contractor_projects',
    ));

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

    $wp_customize->add_setting('painting_contractor_tp_color_sec', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_hex_color'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'painting_contractor_tp_color_sec', array(
        'label'       => __('Theme Second Color', 'painting-contractor'),
        'description' => __('It will change the complete theme color in one click.', 'painting-contractor'),
        'section'     => 'construction_hub_color_option',
        'settings'    => 'painting_contractor_tp_color_sec',
    )));

    // Pro Version
    $wp_customize->add_setting( 'painting_contractor_services_pro_version_logo', array(
        'sanitize_callback' => 'painting_contractor_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Painting_Contractor_Customize_Pro_Version ( $wp_customize,'painting_contractor_services_pro_version_logo', array(
        'section'     => 'painting_contractor_projects',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'painting-contractor' ),
        'description' => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL ),
        'priority'    => 10,
    )));
}
add_action( 'customize_register', 'painting_contractor_customize_register' );
