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

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

add_action( 'customize_register', 'purenote_register_sidebar_layout_options' );

if ( ! function_exists( 'purenote_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 purenote_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 Purenote_Customize_Section (
            $wp_customize, 'purenote_section_sidebar_layout',
                array(
                    'priority'  => 45,
                    'panel'     => 'purenote_panel_general',
                    'title'     => __( 'Sidebar Layout', 'purenote' ),
                )
            )
        );

        /**
         * Toggle option for sidebar sticky
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_sidebar_sticky_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_sidebar_sticky_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_sidebar_sticky_enable',
                array(
                    'priority'      => 5,
                    'section'       => 'purenote_section_sidebar_layout',
                    'settings'      => 'purenote_sidebar_sticky_enable',
                    'label'         => __( 'Enable Sidebar Sticky', 'purenote' )
                )
            )
        );

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

        /**
         * Radio image field for archive/blog sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_archive_sidebar_layout',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_archive_sidebar_layout' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize->add_control( new Purenote_Control_Radio_Image(
            $wp_customize, 'purenote_archive_sidebar_layout',
                array(
                    'priority'      => 15,
                    'section'       => 'purenote_section_sidebar_layout',
                    'settings'      => 'purenote_archive_sidebar_layout',
                    'choices'       => purenote_sidebar_layout_choices(),
                )
            )
        );

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

        /**
         * Radio image field for posts sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_posts_sidebar_layout',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_posts_sidebar_layout' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize->add_control( new Purenote_Control_Radio_Image(
            $wp_customize, 'purenote_posts_sidebar_layout',
                array(
                    'priority'      => 30,
                    'section'       => 'purenote_section_sidebar_layout',
                    'settings'      => 'purenote_posts_sidebar_layout',
                    'choices'       => purenote_sidebar_layout_choices(),
                )
            )
        );

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

        /**
         * Radio image field for posts sidebar
         *
         * General Settings > Sidebar Layout
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_pages_sidebar_layout',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_pages_sidebar_layout' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize->add_control( new Purenote_Control_Radio_Image(
            $wp_customize, 'purenote_pages_sidebar_layout',
                array(
                    'priority'      => 45,
                    'section'       => 'purenote_section_sidebar_layout',
                    'settings'      => 'purenote_pages_sidebar_layout',
                    'choices'       => purenote_sidebar_layout_choices(),
                )
            )
        );

    }

endif;