<?php

/**
 * Banner Section
 *
 * @package social_blog
 */

 // Add Banner Section
$wp_customize->add_section(
    'social_blog_banner_section',
    array(
        'panel'    => 'social_blog_front_page_options',
        'title'    => esc_html__( 'Banner Section', 'social-blog' ),
        'priority' => 10,
    )
);

// Enable Banner Section
$wp_customize->add_setting(
    'social_blog_enable_banner_section',
    array(
        'default'           => true,
        'sanitize_callback' => 'social_blog_sanitize_switch',
    )
);

$wp_customize->add_control(
    new Social_Blog_Toggle_Switch_Custom_Control(
        $wp_customize,
        'social_blog_enable_banner_section',
        array(
            'label'    => esc_html__( 'Enable Banner Section', 'social-blog' ),
            'section'  => 'social_blog_banner_section',
            'settings' => 'social_blog_enable_banner_section',
        )
    )
);

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

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

$wp_customize->add_control(
    'social_blog_banner_slider_content_type',
    array(
        'label'           => esc_html__( 'Select Banner Slider Content Type', 'social-blog' ),
        'section'         => 'social_blog_banner_section',
        'settings'        => 'social_blog_banner_slider_content_type',
        'type'            => 'select',
        'active_callback' => 'social_blog_is_banner_slider_section_enabled',
        'choices'         => array(
            'page' => esc_html__( 'Page', 'social-blog' ),
            'post' => esc_html__( 'Post', 'social-blog' ),
        ),
    )
);

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

$wp_customize->add_control(
    new Social_Blog_Customize_Category_Dropdown_Control(
        $wp_customize,
        'social_blog_banner_slider_category',
        array(
            'label'           => esc_html__( 'Select Banner Slider Category', 'social-blog' ),
            'section'         => 'social_blog_banner_section',
            'settings'        => 'social_blog_banner_slider_category',
            'active_callback' => function() use ($wp_customize) {
                return $wp_customize->get_setting('social_blog_banner_slider_content_type')->value() === 'post';
            },
        )
    )
);

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

    $wp_customize->add_control(
        'social_blog_banner_slider_content_post_' . $social_blog_i,
        array(
            /* translators: %d: Select Post Count. */
            'label'           => sprintf( esc_html__( 'Select Post %d', 'social-blog' ), $social_blog_i ),
            'description'     => esc_html__( 'Select a Post based on the category selected in the upper settings', 'social-blog' ),
            'section'         => 'social_blog_banner_section',
            'settings'        => 'social_blog_banner_slider_content_post_' . $social_blog_i,
            'active_callback' => 'social_blog_is_banner_slider_section_and_content_type_post_enabled',
            'type'            => 'select',
            'choices'         => social_blog_get_post_choices(),
        )
    );

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

    $wp_customize->add_control(
        'social_blog_banner_slider_content_page_' . $social_blog_i,
        array(
            /* translators: %d: Select Page Count. */
            'label'           => sprintf( esc_html__( 'Select Page %d', 'social-blog' ), $social_blog_i ),
            'section'         => 'social_blog_banner_section',
            'settings'        => 'social_blog_banner_slider_content_page_' . $social_blog_i,
            'active_callback' => 'social_blog_is_banner_slider_section_and_content_type_page_enabled',
            'type'            => 'select',
            'choices'         => social_blog_get_page_choices(),
        )
    );
}