<?php
/**
 * Adds the Main Area section and its fields to the Header Settings panel.
 * 
 * @package Blogbuster
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

add_action( 'customize_register', 'blogbuster_register_main_area_options' );

if ( ! function_exists( 'blogbuster_register_main_area_options' ) ) :

    /**
     * Register theme options for Main Area section.
     * 
     * @param WP_Customize_Manager $wp_customize Object that holds the customizer data.
     * @since 1.0.0
     */
    function blogbuster_register_main_area_options( $wp_customize ) {

        /*
         * Failsafe is safe
         */
        if ( ! isset( $wp_customize ) ) {
            return;
        }

        /**
         * Add Main Area Section
         * 
         * Header Settings > Main Area
         * 
         * @uses $wp_customize->add_section() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_section/
         * @since 1.0.0
         */
        $wp_customize->add_section( new Blogbuster_Customize_Section (
            $wp_customize, 'blogbuster_section_header_main_area',
                array(
                    'priority'  => 20,
                    'panel'     => 'blogbuster_panel_header',
                    'title'     => __( 'Main Area', 'blogbuster' ),
                )
            )
        );

        /**
         * Toggle option for header site mode switcher.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_site_mode_switch_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_site_mode_switch_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_site_mode_switch_enable',
                array(
                    'priority'      => 5,
                    'section'       => 'blogbuster_section_header_main_area',
                    'settings'      => 'blogbuster_site_mode_switch_enable',
                    'label'         => __( 'Enable site mode switcher', 'blogbuster' )
                )
            )
        );

        /**
         * Toggle option for header social icon.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_header_social_icons_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_header_social_icons_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_header_social_icons_enable',
                array(
                    'priority'      => 20,
                    'section'       => 'blogbuster_section_header_main_area',
                    'settings'      => 'blogbuster_header_social_icons_enable',
                    'label'         => __( 'Enable Social Icons', 'blogbuster' )
                )
            )
        );

        /**
         * Toggle option for header search icon.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_header_search_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_header_search_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_header_search_enable',
                array(
                    'priority'      => 25,
                    'section'       => 'blogbuster_section_header_main_area',
                    'settings'      => 'blogbuster_header_search_enable',
                    'label'         => __( 'Enable Search Icon', 'blogbuster' )
                )
            )
        );

        /**
         * Toggle option for header sticky.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_header_sticky_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_header_sticky_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_header_sticky_enable',
                array(
                    'priority'      => 50,
                    'section'       => 'blogbuster_section_header_main_area',
                    'settings'      => 'blogbuster_header_sticky_enable',
                    'label'         => __( 'Enable Header Sticky', 'blogbuster' )
                )
            )
        );

        /**
         * Upgrade field for header main section
         * 
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'blogbuster_upgrade_header_main',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Upgrade(
            $wp_customize, 'blogbuster_upgrade_header_main',
                array(
                    'priority'      => 70,
                    'section'       => 'blogbuster_section_header_main_area',
                    'settings'      => 'blogbuster_upgrade_header_main',
                    'label'         => __( 'More features with Blogbuster Pro', 'blogbuster' ),
                    'choices'       => blogbuster_upgrade_choices( 'blogbuster_header_main' )
                )
            )
        );

    }

endif;