<?php

function market_bizz_customize_register($wp_customize) {

    $wp_customize->add_section('market_bizz_header', array(
        'title'       => esc_html__(' Header Phone, email and address', 'market-bizz'),
        'description' => '',
        'priority'    => 30,
    ));

    $wp_customize->add_section('market_bizz_social', array(
        'title'       => esc_html__(' Social Link', 'market-bizz'),
        'description' => '',
        'priority'    => 35,
    ));

    $wp_customize->add_section('market_bizz_footer', array(
        'title'       => esc_html__(' Footer', 'market-bizz'),
        'description' => '',
        'priority'    => 37,
    ));

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

    $wp_customize->add_control('market_bizz_phone', array(
        'label'   => esc_html__('Phone Number', 'market-bizz'),
        'section' => 'market_bizz_header',
        'setting' => 'market_bizz_phone',
        'type'    => 'text'
    ));

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

    $wp_customize->add_control('market_bizz_email', array(
        'label'   => esc_html__('Email', 'market-bizz'),
        'section' => 'market_bizz_header',
        'setting' => 'market_bizz_email',
        'type'    => 'email'
    ));

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

    $wp_customize->add_control('market_bizz_fb', array(
        'label'   => esc_html__('Facebook', 'market-bizz'),
        'section' => 'market_bizz_social',
        'setting' => 'market_bizz_fb',
        'type'    => 'url'
    ));
    //  =============================
    //  = Text Input Twitter                =
    //  =============================
    $wp_customize->add_setting('market_bizz_twitter', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('market_bizz_twitter', array(
        'label'   => esc_html__('Twitter', 'market-bizz'),
        'section' => 'market_bizz_social',
        'setting' => 'market_bizz_twitter',
        'type'    => 'url'
    ));
    //  =============================
    //  = Text Input googleplus                =
    //  =============================
    $wp_customize->add_setting('market_bizz_youtube', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('market_bizz_youtube', array(
        'label'   => esc_html__('YouTube', 'market-bizz'),
        'section' => 'market_bizz_social',
        'setting' => 'market_bizz_youtube',
        'type'    => 'url'
    ));
    //  =============================
    //  = Text Input linkedin                =
    //  =============================
    $wp_customize->add_setting('market_bizz_in', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('market_bizz_in', array(
        'label'   => esc_html__('Linkedin', 'market-bizz'),
        'section' => 'market_bizz_social',
        'setting' => 'market_bizz_in',
        'type'    => 'url'
    ));

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

    $wp_customize->add_control('market_bizz_pin', array(
        'label'   => esc_html__('Pinterest', 'market-bizz'),
        'section' => 'market_bizz_social',
        'setting' => 'market_bizz_pin',
        'type'    => 'url'
    ));
    //  =============================
    //  = slider section              =
    //  =============================
    $wp_customize->add_section('market_bizz_banner', array(
        'title'       => esc_html__(' Home banner Text', 'market-bizz'),
        'description' => esc_html__('add home banner text here.', 'market-bizz'),
        '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', 'market-bizz'),
        'section' => 'market_bizz_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', 'market-bizz'),
        'section' => 'market_bizz_banner',
        'setting' => 'banner_sub_heading'
    )); // Banner heading Text
    //  =============================
    //  = url banner readmoret                =
    //  =============================
    $wp_customize->add_setting('market_bizz_slider_url', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw'
    ));

    $wp_customize->add_control('market_bizz_slider_url', array(
        'label'   => esc_html__('Url', 'market-bizz'),
        'section' => 'market_bizz_banner',
        'setting' => 'market_bizz_slider_url',
        'type'    => 'url'
    ));

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

    $wp_customize->add_control('market_bizz_slider_readmore', array(
        'type'    => 'text',
        'label'   => esc_html__('Add button text here', 'market-bizz'),
        'section' => 'market_bizz_banner',
        'setting' => 'market_bizz_slider_readmore'
    )); // Banner heading Text
    //  =============================
    //  = box section              =
    //  =============================
    $wp_customize->add_section('market_bizz_box', array(
        'title'       => esc_html__('Resource Section', 'market-bizz'),
        'description' => esc_html__('Upload image, it will auto crop with 400*250.', 'market-bizz'),
        'priority'    => 36,
    ));

    $wp_customize->add_setting('market_bizz_box1', array(
        'default'           => '0',
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'market_bizz_sanitize_page'
    ));

    $wp_customize->add_control('market_bizz_box1', array(
        'type'    => 'dropdown-pages',
        'label'   => esc_html__('Select page for Resource first:', 'market-bizz'),
        'section' => 'market_bizz_box'
    ));

    $wp_customize->add_setting('market_bizz_box2', array(
        'default'           => '0',
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'market_bizz_sanitize_page'
    ));

    $wp_customize->add_control('market_bizz_box2', array(
        'type'    => 'dropdown-pages',
        'label'   => esc_html__('Select page for Resource second:', 'market-bizz'),
        'section' => 'market_bizz_box'
    ));

    $wp_customize->add_setting('market_bizz_box3', array(
        'default'           => '0',
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'market_bizz_sanitize_page'
    ));

    $wp_customize->add_control('market_bizz_box3', array(
        'type'    => 'dropdown-pages',
        'label'   => esc_html__('Select page for Resource third:', 'market-bizz'),
        'section' => 'market_bizz_box'
    ));
    
    // Box CTA Text
    $wp_customize->add_setting('market_bizz_box_cta', array(
        'default'           => null,
        'sanitize_callback' => 'sanitize_text_field'
    ));

    $wp_customize->add_control('market_bizz_box_cta', array(
        'type'    => 'text',
        'label'   => esc_html__('Add button text', 'market-bizz'),
        'section' => 'market_bizz_box',
        'setting' => 'market_bizz_box_cta'
    )); 

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

    $wp_customize->add_control('market_bizz_design', array(
        'label'   => esc_html__('Design and developed', 'market-bizz'),
        'section' => 'market_bizz_footer',
        'setting' => 'market_bizz_design',
        'type'    => 'textarea'
    ));
    // Footer copyright
    $wp_customize->add_setting('market_bizz_copyright', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field'
    ));

    $wp_customize->add_control('market_bizz_copyright', array(
        'label'   => esc_html__('Copyright', 'market-bizz'),
        'section' => 'market_bizz_footer',
        'setting' => 'market_bizz_copyright',
        'type'    => 'textarea'
    ));
}

add_action('customize_register', 'market_bizz_customize_register');

if (!function_exists('market_bizz_sanitize_page')) :

    function market_bizz_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;