<?php
/**
 * Add Web Stories section and its fields inside Frontpage Settings panel.
 *
 * @package Purenote
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

add_action( 'customize_register', 'purenote_register_frontpage_web_stories_options' );

if ( ! function_exists( 'purenote_register_frontpage_web_stories_options' ) ) :

    /**
     * Register theme options for Web Stories Section.
     *
     * @param WP_Customize_Manager $wp_customize Object that holds the customizer data.
     * @since 1.0.0
     */
    function purenote_register_frontpage_web_stories_options( $wp_customize ) {

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

        /**
         * Add Web Stories Section
         * 
         * Frontpage Settings > Web Stories
         * 
         * @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_frontpage_web_stories',
                array(
                    'title'    => __( 'Web Stories', 'purenote' ),
                    'priority' => 25,
                    'panel'    => 'purenote_panel_front_page',
                )
            )
        );

        /**
         * Tabs field for Web Stories section
         *
         * Frontpage Settings > Web Stories
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_web_stories_tabs',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_web_stories_tabs' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( new Purenote_Control_Tabs(
            $wp_customize, 'purenote_web_stories_tabs',
                array(
                    'section'  => 'purenote_section_frontpage_web_stories',
                    'priority' => 10,
                    'choices'  => purenote_frontpage_web_stories_tabs_choices(),
                    'required' => array(
                        array(
                            'control'  => 'purenote_web_stories_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    ),
                )
            )
        );

        /**
         * Toggle option for web stories section.
         *
         * Frontpage Settings > Web Stories
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_web_stories_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_web_stories_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox',
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_web_stories_enable',
                array(
                    'label'    => __( 'Enable Web Stories Section', 'purenote' ),
                    'section'  => 'purenote_section_frontpage_web_stories',
                    'priority' => 20,
                )
            )
        );

        /**
         * Text field option for web stories section title.
         *
         * Frontpage Settings > Web Stories
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_web_stories_title',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_web_stories_title' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control(
            $wp_customize, 'purenote_web_stories_title',
                array(
                    'label'    => __( 'Section Title', 'purenote' ),
                    'section'  => 'purenote_section_frontpage_web_stories',
                    'type'     => 'text',
                    'priority' => 30,
                    'required' => array(
                        array(
                            'control'  => 'purenote_web_stories_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    ),
                )
            )
        );

        /**
         * Select option for web stories posts order by.
         *
         * Frontpage Settings > Web Stories
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_web_stories_orderby',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_web_stories_orderby' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control(
            $wp_customize, 'purenote_web_stories_orderby',
                array(
                    'label'    => __( 'Posts Order By', 'purenote' ),
                    'section'  => 'purenote_section_frontpage_web_stories',
                    'type'     => 'select',
                    'choices'  => purenote_posts_order_by_choices(),
                    'priority' => 40,
                    'required' => array(
                        array(
                            'control'  => 'purenote_web_stories_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    ),
                )
            )
        );

        /**
         * Select option for web stories posts date filter.
         *
         * Frontpage Settings > Web Stories
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_web_stories_date_filter',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_web_stories_date_filter' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control(
            $wp_customize, 'purenote_web_stories_date_filter',
                array(
                    'label'    => __( 'Posts Date Filter', 'purenote' ),
                    'section'  => 'purenote_section_frontpage_web_stories',
                    'type'     => 'select',
                    'choices'  => purenote_posts_date_filter_choices(),
                    'priority' => 50,
                    'required' => array(
                        array(
                            'control'  => 'purenote_web_stories_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    ),
                )
            )
        );

        /**
         * Select option for web stories preview image size.
         *
         * Frontpage Settings > Web Stories
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_web_stories_image_size',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_web_stories_image_size' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control(
            $wp_customize, 'purenote_web_stories_image_size',
                array(
                    'label'    => __( 'Preview Image Size', 'purenote' ),
                    'section'  => 'purenote_section_frontpage_web_stories',
                    'type'     => 'select',
                    'choices'  => purenote_image_size_choices(),
                    'priority' => 110
                )
            )
        );

        /**
         * Select option for web stories preview image hover effect.
         *
         * Frontpage Settings > Web Stories
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_web_stories_hover_effect',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_web_stories_hover_effect' ),
                'sanitize_callback' => 'sanitize_key',
            )

        );
        $wp_customize->add_control( new Purenote_Customize_Control(
            $wp_customize, 'purenote_web_stories_hover_effect',
                array(
                    'label'    => __( 'Hover Effect', 'purenote' ),
                    'section'  => 'purenote_section_frontpage_web_stories',
                    'type'     => 'select',
                    'choices'  => purenote_hover_effect_choices(),
                    'priority' => 120
                )
            )
        );

    }

endif;