<?php
/**
 * Adds the Site Style section and its fields within the General Settings panel.
 * 
 * @package PureNote
 */

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

add_action( 'customize_register', 'purenote_register_site_style_options' );

if ( ! function_exists( 'purenote_register_site_style_options' ) ) :

    /**
     * Register theme options for Site Style section.
     * 
     * @param WP_Customize_Manager $wp_customize Object that holds the settings.
     * @since 1.0.0
     */
    function purenote_register_site_style_options( $wp_customize ) {

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

        /**
         * Add Site Style Section
         * 
         * General Settings > Site Style
         * 
         * @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 Purenote_Customize_Section (
            $wp_customize, 'purenote_section_site_style',
                array(
                    'priority'  => 10,
                    'panel'     => 'purenote_panel_general',
                    'title'     => __( 'Site Style', 'purenote' ),
                )
            )
        );

        /**
         * Radio image field for site layout
         *
         * General Settings > Site Style
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_site_container_layout',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_site_container_layout' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize->add_control( new Purenote_Control_Radio_Image(
            $wp_customize, 'purenote_site_container_layout',
                array(
                    'priority'      => 10,
                    'section'       => 'purenote_section_site_style',
                    'settings'      => 'purenote_site_container_layout',
                    'label'         => __( 'Container Layout', 'purenote' ),
                    'choices'       => purenote_site_container_layout_choices(),
                )
            )
        );

        // Sticky Posts Section
        $wp_customize->add_section( new purenote_Customize_Section(
            $wp_customize,
            'purenote_section_sticky_posts',
            array(
                'priority' => 15,
                'panel'    => 'purenote_panel_general',
                'title'    => __( 'Sticky Posts', 'purenote' ),
            )
        ));

        /**
          * Text field for sticky-post-header
          * 
          * General Settings > sticky post header
          * 
          * @since 1.0.0
          */
        $wp_customize-> add_setting( 'purenote_sticky_posts_heading',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_sticky_posts_heading' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize-> add_control( new Purenote_Customize_Control (
            $wp_customize, 'purenote_sticky_posts_heading',
                array(
                    'priority'  => 20,
                    'section'   => 'purenote_section_sticky_posts',
                    'settings'  => 'purenote_sticky_posts_heading',
                    'type'      => 'text',
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_sticky_posts_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        // Enable Toggle
        $wp_customize->add_setting( 'purenote_sticky_posts_enable', array(
            'default'           => purenote_get_customizer_default( 'purenote_sticky_posts_enable' ),
            'sanitize_callback' => 'purenote_sanitize_checkbox',
        ));
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize,
            'purenote_sticky_posts_enable',
            array(
                'priority' => 5,
                'section'  => 'purenote_section_sticky_posts',
                'label'    => __( 'Enable Sticky Posts Section', 'purenote' ),
            )
        ));

    }

endif;