<?php
/**
 * Adds the Sidebar Layout section and its fields to the General Settings panel.
 * 
 * Allows users to configure sidebar layout options for the theme.
 *
 * @package Yaatra
 */

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

add_action( 'customize_register', 'yaatra_register_sidebar_layout_options' );

if ( ! function_exists( 'yaatra_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.1.0
     */
    function yaatra_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.0.0
         */
        $wp_customize->add_section( new Yaatra_Customize_Section (
            $wp_customize, 'yaatra_section_sidebar_layout',
                array(
                    'priority'  => 40,
                    'panel'     => 'yaatra_panel_general',
                    'title'     => __( 'Sidebar Layout', 'yaatra' ),
                )
            )
        );

        /**
         * Heading field for Archive / Blog Sidebar Layout
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_sidebar_archive_heading_toggle',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Heading_Toggle(
            $wp_customize, 'yaatra_sidebar_archive_heading_toggle',
                array(
                    'priority'      => 10,
                    'section'       => 'yaatra_section_sidebar_layout',
                    'settings'      => 'yaatra_sidebar_archive_heading_toggle',
                    'label'         => __( 'Archive/Blog Sidebar Layout', 'yaatra' ),
                )
            )
        );

        /**
         * Radio image field for archive/blog sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_archive_sidebar',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_archive_sidebar' ),
                'sanitize_callback' => 'yaatra_sanitize_select',
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Radio_Image(
            $wp_customize, 'yaatra_archive_sidebar',
                array(
                    'priority'      => 15,
                    'section'       => 'yaatra_section_sidebar_layout',
                    'settings'      => 'yaatra_archive_sidebar',
                    'choices'       => yaatra_sidebar_layout_choices(),
                )
            )
        );

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

        /**
         * Radio image field for posts sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_global_post_sidebar',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_global_post_sidebar' ),
                'sanitize_callback' => 'yaatra_sanitize_select',
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Radio_Image(
            $wp_customize, 'yaatra_global_post_sidebar',
                array(
                    'priority'      => 25,
                    'section'       => 'yaatra_section_sidebar_layout',
                    'settings'      => 'yaatra_global_post_sidebar',
                    'choices'       => yaatra_sidebar_layout_choices(),
                )
            )
        );

        /**
         * Heading field for Pages Sidebar Layout
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_sidebar_pages_heading_toggle',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Heading_Toggle(
            $wp_customize, 'yaatra_sidebar_pages_heading_toggle',
                array(
                    'priority'      => 30,
                    'section'       => 'yaatra_section_sidebar_layout',
                    'settings'      => 'yaatra_sidebar_pages_heading_toggle',
                    'label'         => __( 'Pages Sidebar Layout', 'yaatra' ),
                    'initial'       => false,
                )
            )
        );

        /**
         * Radio image field for posts sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_global_page_sidebar',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_global_page_sidebar' ),
                'sanitize_callback' => 'yaatra_sanitize_select',
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Radio_Image(
            $wp_customize, 'yaatra_global_page_sidebar',
                array(
                    'priority'      => 35,
                    'section'       => 'yaatra_section_sidebar_layout',
                    'settings'      => 'yaatra_global_page_sidebar',
                    'choices'       => yaatra_sidebar_layout_choices(),
                )
            )
        );

    }

endif;