<?php

/**
 * Popular Posts Settings
 *
 * @package Chic Lifestyle
 */
add_action( 'customize_register', 'chic_lifestyle_customize_register_featured_posts_section' );
function chic_lifestyle_customize_register_featured_posts_section(  $wp_customize  ) {
    // Add Popular Posts Section under the Homepage Options panel.
    $wp_customize->add_section( 'chic_lifestyle_archive_sections', array(
        'title'       => esc_html__( 'Featured Posts', 'chic-lifestyle' ),
        'description' => esc_html__( 'Configure the Featured Posts section', 'chic-lifestyle' ),
        'panel'       => 'chic_lifestyle_homepage_panel',
        'priority'    => 3,
    ) );
    // Setting: Display Popular Posts Option.
    $wp_customize->add_setting( 'archive_display', array(
        'sanitize_callback' => 'chic_lifestyle_sanitize_checkbox',
        'default'           => true,
    ) );
    $wp_customize->add_control( new Chic_Lifestyle_Toggle_Control($wp_customize, 'archive_display', array(
        'label'    => esc_html__( 'Hide / Show Featured Posts', 'chic-lifestyle' ),
        'section'  => 'chic_lifestyle_archive_sections',
        'settings' => 'archive_display',
        'type'     => 'toggle',
    )) );
    $wp_customize->selective_refresh->add_partial( 'archive_display', array(
        'selector' => '#chic_lifestyle_archive_sections > .container',
    ) );
    // Setting: Featured Posts Title.
    $wp_customize->add_setting( 'archive_title', array(
        'sanitize_callback' => 'sanitize_text_field',
        'default'           => '',
    ) );
    $wp_customize->add_control( 'archive_title', array(
        'label'    => esc_html__( 'Section Title', 'chic-lifestyle' ),
        'section'  => 'chic_lifestyle_archive_sections',
        'settings' => 'archive_title',
        'type'     => 'text',
    ) );
    // Setting: Featured Posts Category.
    $wp_customize->add_setting( 'archive_category', array(
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'chic_lifestyle_sanitize_category',
        'default'           => '',
    ) );
    $wp_customize->add_control( new Chic_Lifestyle_Customize_Dropdown_Taxonomies_Control($wp_customize, 'archive_category', array(
        'label'    => esc_html__( 'Choose Category', 'chic-lifestyle' ),
        'section'  => 'chic_lifestyle_archive_sections',
        'settings' => 'archive_category',
        'type'     => 'dropdown-taxonomies',
        'taxonomy' => 'category',
    )) );
    $wp_customize->add_setting( 'chic_lifestyle_archive_section_sidebar_layout', array(
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'chic_lifestyle_sanitize_choices',
        'default'           => 'right-sidebar',
    ) );
    $wp_customize->add_control( new Chic_Lifestyle_Radio_Buttonset_Control($wp_customize, 'chic_lifestyle_archive_section_sidebar_layout', array(
        'label'    => esc_html__( 'Select sidebar layout', 'chic-lifestyle' ),
        'section'  => 'chic_lifestyle_archive_sections',
        'settings' => 'chic_lifestyle_archive_section_sidebar_layout',
        'type'     => 'radio-buttonset',
        'choices'  => array(
            'left-sidebar'  => esc_attr__( 'Sidebar at left', 'chic-lifestyle' ),
            'right-sidebar' => esc_attr__( 'Sidebar at right', 'chic-lifestyle' ),
            'no-sidebar'    => esc_attr__( 'No sidebar', 'chic-lifestyle' ),
        ),
    )) );
    $wp_customize->add_setting( 'archive_list_details', array(
        'default'           => array('date', 'categories', 'readmore'),
        'sanitize_callback' => 'chic_lifestyle_sanitize_array',
    ) );
    $wp_customize->add_control( new Chic_Lifestyle_Multi_Check_Control($wp_customize, 'archive_list_details', array(
        'label'   => esc_html__( 'Show / Hide details', 'chic-lifestyle' ),
        'section' => 'chic_lifestyle_archive_sections',
        'choices' => array(
            'author'             => esc_html__( 'Show post author', 'chic-lifestyle' ),
            'date'               => esc_html__( 'Show post date', 'chic-lifestyle' ),
            'categories'         => esc_html__( 'Show categories', 'chic-lifestyle' ),
            'tags'               => esc_html__( 'Show tags', 'chic-lifestyle' ),
            'number_of_comments' => esc_html__( 'Show number of comments', 'chic-lifestyle' ),
        ),
    )) );
    //TODO: add upgrade-to-pro control (post view)
}
