<?php
/**
 * Adds the Sidebar Layout section and its fields to the General Settings panel.
 * 
 * @package Blogbuster
 */

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

add_action( 'customize_register', 'blogbuster_register_sidebar_layout_options' );

if ( ! function_exists( 'blogbuster_register_sidebar_layout_options' ) ) :

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

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

        /**
         * Add Sidebar Layout Section
         * 
         * General Settings > Sidebar Layout
         * 
         * @uses $wp_customize->add_section() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_section/
         * @since 1.2.0
         */
        $wp_customize->add_section( new Blogbuster_Customize_Section (
            $wp_customize, 'blogbuster_section_sidebar_layout',
                array(
                    'priority'  => 45,
                    'panel'     => 'blogbuster_panel_general',
                    'title'     => __( 'Sidebar Layout', 'blogbuster' ),
                )
            )
        );

        /**
         * Toggle option for sidebar sticky
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_global_sidebar_sticky_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_global_sidebar_sticky_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_global_sidebar_sticky_enable',
                array(
                    'priority'      => 5,
                    'section'       => 'blogbuster_section_sidebar_layout',
                    'settings'      => 'blogbuster_global_sidebar_sticky_enable',
                    'label'         => __( 'Enable Global Sidebar Sticky', 'blogbuster' )
                )
            )
        );

        /**
         * Heading field for Archive / Blog Sidebar Layout
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_sidebar_archive_heading_toggle',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Heading_Toggle(
            $wp_customize, 'blogbuster_sidebar_archive_heading_toggle',
                array(
                    'priority'      => 5,
                    'section'       => 'blogbuster_section_sidebar_layout',
                    'settings'      => 'blogbuster_sidebar_archive_heading_toggle',
                    'label'         => __( 'Archive/Blog Sidebar Layout', 'blogbuster' ),
                )
            )
        );

        /**
         * Radio image field for archive/blog sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_archive_sidebar_layout',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_archive_sidebar_layout' ),
                'sanitize_callback' => 'blogbuster_sanitize_select',
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Radio_Image(
            $wp_customize, 'blogbuster_archive_sidebar_layout',
                array(
                    'priority'      => 15,
                    'section'       => 'blogbuster_section_sidebar_layout',
                    'settings'      => 'blogbuster_archive_sidebar_layout',
                    'choices'       => blogbuster_sidebar_layout_choices(),
                )
            )
        );

        /**
         * Heading field for Posts Sidebar Layout
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_sidebar_posts_heading_toggle',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Heading_Toggle(
            $wp_customize, 'blogbuster_sidebar_posts_heading_toggle',
                array(
                    'priority'      => 20,
                    'section'       => 'blogbuster_section_sidebar_layout',
                    'settings'      => 'blogbuster_sidebar_posts_heading_toggle',
                    'label'         => __( 'Posts Sidebar Layout', 'blogbuster' ),
                    'initial'       => false,
                )
            )
        );

        /**
         * Radio image field for posts sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_posts_sidebar_layout',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_posts_sidebar_layout' ),
                'sanitize_callback' => 'blogbuster_sanitize_select',
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Radio_Image(
            $wp_customize, 'blogbuster_posts_sidebar_layout',
                array(
                    'priority'      => 30,
                    'section'       => 'blogbuster_section_sidebar_layout',
                    'settings'      => 'blogbuster_posts_sidebar_layout',
                    'choices'       => blogbuster_sidebar_layout_choices(),
                )
            )
        );

        /**
         * Heading field for Pages Sidebar Layout
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_sidebar_pages_heading_toggle',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Heading_Toggle(
            $wp_customize, 'blogbuster_sidebar_pages_heading_toggle',
                array(
                    'priority'      => 35,
                    'section'       => 'blogbuster_section_sidebar_layout',
                    'settings'      => 'blogbuster_sidebar_pages_heading_toggle',
                    'label'         => __( 'Pages Sidebar Layout', 'blogbuster' ),
                    'initial'       => false,
                )
            )
        );

        /**
         * Radio image field for posts sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_pages_sidebar_layout',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_pages_sidebar_layout' ),
                'sanitize_callback' => 'blogbuster_sanitize_select',
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Radio_Image(
            $wp_customize, 'blogbuster_pages_sidebar_layout',
                array(
                    'priority'      => 45,
                    'section'       => 'blogbuster_section_sidebar_layout',
                    'settings'      => 'blogbuster_pages_sidebar_layout',
                    'choices'       => blogbuster_sidebar_layout_choices(),
                )
            )
        );

    }

endif;