<?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' ) ) :
function purenote_register_frontpage_web_stories_options( $wp_customize ) {

    /* -----------------------------------------------------------------Section--------------------------------------------------------- */
   
    $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
    /* ----------------------------------------------------------------------- */
    $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(),
        )
    ) );

    /* ----------------------------------------------------------------------- */
    /* General Tab
    /* ----------------------------------------------------------------------- */

    // Enable toggle
    $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,
        )
    ) );

    // Section Title
    $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' => '==',
                ),
            ),
        )
    ) );

    // Posts Order By
    $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' => '==',
                ),
            ),
        )
    ) );

    // Posts Date Filter
    $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' => '==',
                ),
            ),
        )
    ) );

    /* ----------------------------------------------------------------------- */
    /* Style Tab – Heading
    /* ----------------------------------------------------------------------- */
    $wp_customize->add_setting( 'purenote_web_stories_style_heading', array(
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( new purenote_Control_Heading(
        $wp_customize, 'purenote_web_stories_style_heading',
        array(
            'label'    => __( 'Style Settings', 'purenote' ),
            'section'  => 'purenote_section_frontpage_web_stories',
            'priority' => 100,
            'required' => array(
                array(
                    'control'  => 'purenote_web_stories_enable',
                    'value'    => true,
                    'operator' => '==',
                ),
            ),
        )
    ) );

    // Preview Image Size
    $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,
            'required' => array(
                array(
                    'control'  => 'purenote_web_stories_enable',
                    'value'    => true,
                    'operator' => '==',
                ),
            ),
        )
    ) );

    // Hover Effect
    $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,
            'required' => array(
                array(
                    'control'  => 'purenote_web_stories_enable',
                    'value'    => true,
                    'operator' => '==',
                ),
            ),
        )
    ) );
}
endif;