<?php

add_action('customize_register', 'buildz_customize_register_custom_controls', 9);

function buildz_customize_register_custom_controls($wp_customize) {
    get_template_part('lib/proupgrade/buildz', 'sectionpro');
}

function buildz_customize_controls_js() {
    $theme = wp_get_theme();
    wp_enqueue_script('buildz-customizer-section-pro-jquery', get_template_directory_uri() . '/lib/proupgrade/buildz_customize-controls.js', array('customize-controls'), $theme->get('Version'), true);
    wp_enqueue_style('buildz-customizer-section-pro', get_template_directory_uri() . '/lib/proupgrade/buildz_customize-controls.css', $theme->get('Version'));
}

add_action('customize_controls_enqueue_scripts', 'buildz_customize_controls_js');

function buildz_enqueue_comments_reply() {
    if (get_option('thread_comments')) {
        wp_enqueue_script('comment-reply');
    }
}

add_action('comment_form_before', 'buildz_enqueue_comments_reply');

if (!function_exists('buildz_sanitize_page')) :

    function buildz_sanitize_page($page_id, $setting) {
        // Ensure $input is an absolute integer.
        $page_id = absint($page_id);
        // If $page_id is an ID of a published page, return it; otherwise, return the default.
        return ( 'publish' === get_post_status($page_id) ? $page_id : $setting->default );
    }

endif;

function buildz_customize_register($wp_customize) {

    // Register custom section types.
    $wp_customize->register_section_type('buildz_Customize_Section_Pro');

    // Register sections.
    $wp_customize->add_section(new buildz_Customize_Section_Pro(
                    $wp_customize,
                    'theme_go_pro',
                    array(
                'priority' => 1,
                'title'    => esc_html__('BuildZ Pro', 'buildz'),
                'pro_text' => esc_html__('Upgrade To Pro', 'buildz'),
                'pro_url'  => 'https://themestulip.com/themes/construction-wordpress-theme/',
                    )
    ));
    $wp_customize->add_section('buildz_header', array(
        'title'       => esc_html__('BuildZ Header Phone and Address', 'buildz'),
        'description' => '',
        'priority'    => 30,
    ));
    $wp_customize->add_section('buildz_social', array(
        'title'       => esc_html__('BuildZ Social Link', 'buildz'),
        'description' => '',
        'priority'    => 35,
    ));


    //  =============================
    //  = Text Input phone number                =
    //  =============================
    $wp_customize->add_setting('buildz_phone', array(
        'default'           => '',
        'sanitize_callback' => 'buildz_sanitize_phone_number'
    ));

    $wp_customize->add_control('buildz_phone', array(
        'label'   => esc_html__('Phone Number', 'buildz'),
        'section' => 'buildz_header',
        'setting' => 'buildz_phone',
        'type'    => 'text'
    ));

    //  =============================
    //  = Text Input Email                =
    //  =============================
    $wp_customize->add_setting('buildz_address', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field'
    ));

    $wp_customize->add_control('buildz_address', array(
        'label'   => esc_html__('Full Address', 'buildz'),
        'section' => 'buildz_header',
        'setting' => 'buildz_address',
        'type'    => 'textarea'
    ));

    //  =============================
    //  = Text Input facebook                =
    //  =============================
    $wp_customize->add_setting('buildz_fb', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('buildz_fb', array(
        'label'   => esc_html__('Facebook', 'buildz'),
        'section' => 'buildz_social',
        'setting' => 'buildz_fb',
    ));
    //  =============================
    //  = Text Input Twitter                =
    //  =============================
    $wp_customize->add_setting('buildz_twitter', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('buildz_twitter', array(
        'label'   => esc_html__('Twitter', 'buildz'),
        'section' => 'buildz_social',
        'setting' => 'buildz_twitter',
    ));
    //  =============================
    //  = Text Input googleplus                =
    //  =============================
    $wp_customize->add_setting('buildz_youtube', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('buildz_youtube', array(
        'label'   => esc_html__('YouTube', 'buildz'),
        'section' => 'buildz_social',
        'setting' => 'buildz_youtube',
    ));
    //  =============================
    //  = Text Input linkedin                =
    //  =============================
    $wp_customize->add_setting('buildz_in', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('buildz_in', array(
        'label'   => esc_html__('Linkedin', 'buildz'),
        'section' => 'buildz_social',
        'setting' => 'buildz_in',
    ));

    //  =============================
    //  = slider section              =
    //  =============================
    $wp_customize->add_section('business_multi_lite_banner', array(
        'title'       => esc_html__('BuildZ Home Banner Text', 'buildz'),
        'description' => esc_html__('add home banner text here.', 'buildz'),
        'priority'    => 36,
    ));

// Banner heading Text
    $wp_customize->add_setting('banner_heading', array(
        'default'           => null,
        'sanitize_callback' => 'sanitize_text_field'
    ));

    $wp_customize->add_control('banner_heading', array(
        'type'    => 'text',
        'label'   => esc_html__('Add Banner heading here', 'buildz'),
        'section' => 'business_multi_lite_banner',
        'setting' => 'banner_heading'
    )); // Banner heading Text
    // Banner heading Text
    $wp_customize->add_setting('banner_sub_heading', array(
        'default'           => null,
        'sanitize_callback' => 'sanitize_text_field'
    ));

    $wp_customize->add_control('banner_sub_heading', array(
        'type'    => 'text',
        'label'   => esc_html__('Add Banner sub heading here', 'buildz'),
        'section' => 'business_multi_lite_banner',
        'setting' => 'banner_sub_heading'
    )); // Banner heading Text
    //  =============================
    //  = Footer              =
    //  =============================

    $wp_customize->add_section('buildz_footer', array(
        'title'       => esc_html__('BuildZ Footer', 'buildz'),
        'description' => '',
        'priority'    => 37,
    ));

    // Footer design and developed
    $wp_customize->add_setting('buildz_design', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field'
    ));

    $wp_customize->add_control('buildz_design', array(
        'label'   => esc_html__('Design and developed', 'buildz'),
        'section' => 'buildz_footer',
        'setting' => 'buildz_design',
        'type'    => 'textarea'
    ));
    // Footer copyright
    $wp_customize->add_setting('buildz_copyright', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field'
    ));

    $wp_customize->add_control('buildz_copyright', array(
        'label'   => esc_html__('Copyright', 'buildz'),
        'section' => 'buildz_footer',
        'setting' => 'buildz_copyright',
        'type'    => 'textarea'
    ));
}

add_action('customize_register', 'buildz_customize_register');
