<?php

function roofing_contractor_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', 'roofing_contractor_remove_customize_register', 11 );

if ( ! defined( 'ROOFING_CONTRACTOR_TEXT' ) ) {
    define( 'ROOFING_CONTRACTOR_TEXT', __( 'Construction Renovation Pro','roofing-contractor' ));
}
if ( ! defined( 'ROOFING_CONTRACTOR_BUY_TEXT' ) ) {
    define( 'ROOFING_CONTRACTOR_BUY_TEXT', __( 'Upgrade Pro','roofing-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( ROOFING_CONTRACTOR_TEXT,'roofing-contractor' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'roofing-contractor' ),
            'button_url'  => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL )
        ] )
    );

} );

function roofing_contractor_customize_register( $wp_customize ) {

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

    // Pro Version
    class Roofing_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( ROOFING_CONTRACTOR_BUY_TEXT,'roofing-contractor' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

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

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

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

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

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

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

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

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

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

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

    $wp_customize->add_setting( 'roofing_contractor_project_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'construction_hub_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Roofing_Contractor_Toggle_Control( $wp_customize, 'roofing_contractor_project_show_hide', array(
        'label'       => esc_html__( 'Show / Hide section', 'roofing-contractor' ),
        'section'     => 'roofing_contractor_projects',
        'type'        => 'toggle',
        'settings'    => 'roofing_contractor_project_show_hide',
    ) ) );

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

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

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

    $featured_post = get_theme_mod('roofing_contractor_projetcs_number','6');
    for ( $j = 1; $j <= $featured_post; $j++ ) {
        $wp_customize->add_setting('roofing_contractor_projetcs_text'.$j,array(
            'default'=> '',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('roofing_contractor_projetcs_text'.$j,array(
            'label' => esc_html__('Tab ','roofing-contractor').$j,
            'section'=> 'roofing_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('roofing_contractor_projetcs_category'.$j,array(
            'default'   => 'select',
            'sanitize_callback' => 'roofing_contractor_sanitize_choices',
        ));
        $wp_customize->add_control('roofing_contractor_projetcs_category'.$j,array(
            'type'    => 'select',
            'choices' => $cat_posts,
            'label' => __('Select Category to display projects','roofing-contractor'),
            'section' => 'roofing_contractor_projects',
        ));
    }

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

    // Pro Version
    $wp_customize->add_setting( 'roofing_contractor_services_pro_version_logo', array(
        'sanitize_callback' => 'roofing_contractor_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Roofing_Contractor_Customize_Pro_Version ( $wp_customize,'roofing_contractor_services_pro_version_logo', array(
        'section'     => 'roofing_contractor_projects',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'roofing-contractor' ),
        'description' => esc_url( CONSTRUCTION_HUB_PRO_THEME_URL ),
        'priority'    => 10,
    )));
    
}
add_action( 'customize_register', 'roofing_contractor_customize_register' );
