<?php

/**
 * Banner Section
 *
 * @package aster_vlogger
 */

 // Add Banner Section
$wp_customize->add_section(
    'aster_vlogger_banner_section',
    array(
        'panel'    => 'aster_vlogger_front_page_options',
        'title'    => esc_html__( 'Banner Section', 'aster-vlogger' ),
        'priority' => 10,
    )
);

// Enable Banner Section
$wp_customize->add_setting(
    'aster_vlogger_enable_banner_section',
    array(
        'default'           => false,
        'sanitize_callback' => 'aster_vlogger_sanitize_switch',
    )
);

$wp_customize->add_control(
    new Aster_Vlogger_Toggle_Switch_Custom_Control(
        $wp_customize,
        'aster_vlogger_enable_banner_section',
        array(
            'label'    => esc_html__( 'Enable Banner Section', 'aster-vlogger' ),
            'section'  => 'aster_vlogger_banner_section',
            'settings' => 'aster_vlogger_enable_banner_section',
        )
    )
);

if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial(
        'aster_vlogger_enable_banner_section',
        array(
            'selector' => '#aster_vlogger_banner_section .section-link',
            'settings' => 'aster_vlogger_enable_banner_section',
        )
    );
}

// Banner Slider Content Type
$wp_customize->add_setting(
    'aster_vlogger_banner_slider_content_type',
    array(
        'default'           => 'post',
        'sanitize_callback' => 'aster_vlogger_sanitize_select',
    )
);

$wp_customize->add_control(
    'aster_vlogger_banner_slider_content_type',
    array(
        'label'           => esc_html__( 'Select Banner Slider Content Type', 'aster-vlogger' ),
        'section'         => 'aster_vlogger_banner_section',
        'settings'        => 'aster_vlogger_banner_slider_content_type',
        'type'            => 'select',
        'active_callback' => 'aster_vlogger_is_banner_slider_section_enabled',
        'choices'         => array(
            'page' => esc_html__( 'Page', 'aster-vlogger' ),
            'post' => esc_html__( 'Post', 'aster-vlogger' ),
        ),
    )
);

// Banner Slider Category
$wp_customize->add_setting(
    'aster_vlogger_banner_slider_category',
    array(
        'default'           => 'slider',
        'sanitize_callback' => 'sanitize_text_field',
    )
);

$wp_customize->add_control(
    new Aster_Vlogger_Customize_Category_Dropdown_Control(
        $wp_customize,
        'aster_vlogger_banner_slider_category',
        array(
            'label'           => esc_html__( 'Select Banner Slider Category', 'aster-vlogger' ),
            'section'         => 'aster_vlogger_banner_section',
            'settings'        => 'aster_vlogger_banner_slider_category',
            'active_callback' => function() use ($wp_customize) {
                return $wp_customize->get_setting('aster_vlogger_banner_slider_content_type')->value() === 'post';
            },
        )
    )
);

// Loop to create settings and controls for Banner Section posts and pages
for ( $aster_vlogger_i = 1; $aster_vlogger_i <= 6; $aster_vlogger_i++ ) {
    // Select Banner Post
    $wp_customize->add_setting(
        'aster_vlogger_banner_slider_content_post_' . $aster_vlogger_i,
        array(
            'sanitize_callback' => 'absint',
        )
    );

    $wp_customize->add_control(
        'aster_vlogger_banner_slider_content_post_' . $aster_vlogger_i,
        array(
            /* translators: %d: Select Post Count. */
            'label'           => sprintf( esc_html__( 'Select Post %d', 'aster-vlogger' ), $aster_vlogger_i ),
            'description'     => esc_html__( 'Select a Post based on the category selected in the upper settings', 'aster-vlogger' ),
            'section'         => 'aster_vlogger_banner_section',
            'settings'        => 'aster_vlogger_banner_slider_content_post_' . $aster_vlogger_i,
            'active_callback' => 'aster_vlogger_is_banner_slider_section_and_content_type_post_enabled',
            'type'            => 'select',
            'choices'         => aster_vlogger_get_post_choices(),
        )
    );

    // Select Banner Page
    $wp_customize->add_setting(
        'aster_vlogger_banner_slider_content_page_' . $aster_vlogger_i,
        array(
            'sanitize_callback' => 'absint',
        )
    );

    $wp_customize->add_control(
        'aster_vlogger_banner_slider_content_page_' . $aster_vlogger_i,
        array(
            /* translators: %d: Select Page Count. */
            'label'           => sprintf( esc_html__( 'Select Page %d', 'aster-vlogger' ), $aster_vlogger_i ),
            'section'         => 'aster_vlogger_banner_section',
            'settings'        => 'aster_vlogger_banner_slider_content_page_' . $aster_vlogger_i,
            'active_callback' => 'aster_vlogger_is_banner_slider_section_and_content_type_page_enabled',
            'type'            => 'select',
            'choices'         => aster_vlogger_get_page_choices(),
        )
    );
}