<?php
/**
 * You Missed Section Customizer Settings
 * Single section with design dropdown
 *
 * @package Blog_Over
 */

/**
 * Helper function to get categories dropdown
 */
if (!function_exists('blog_over_get_categories_dropdown')) {
    function blog_over_get_categories_dropdown()
    {
        $categories = get_categories(array(
            'orderby' => 'name',
            'order' => 'ASC',
            'hide_empty' => true,
        ));

        $choices = array('all' => esc_html__('All Categories', 'blog-over'));

        foreach ($categories as $category) {
            $choices[$category->slug] = esc_html($category->name);
        }

        return $choices;
    }
}

// ─────────────────────────────────────────────
// Section: You Missed (standalone section - after Featured Links)
// ─────────────────────────────────────────────
Kirki::add_section('blog_over_youmissed_section', array(
    'title' => esc_html__('You Missed Section', 'blog-over'),
    'panel' => 'blog_over_frontpage_panel',
    'priority' => 40,
));

// ═══════════════════════════════════════════
// A) Enable Toggle
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_you_missed_show',
    'label' => esc_html__('Enable You Missed Section', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => false,
    'priority' => 5,
    'partial_refresh' => array(
        'blog_over_you_missed_show' => array(
            'selector' => '.blog-over-missed-wrapper',
            'render_callback' => 'blog_over_render_missed',
        ),
    ),
));

// ═══════════════════════════════════════════
// B) Section Title
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'text',
    'settings' => 'blog_over_you_missed_title',
    'label' => esc_html__('Section Title', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => esc_html__('You Missed', 'blog-over'),
    'priority' => 10,
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
    'partial_refresh' => array(
        'blog_over_you_missed_title' => array(
            'selector' => '.blog-over-missed-heading',
            'render_callback' => function () {
                return esc_html(get_theme_mod('blog_over_you_missed_title', __('You Missed', 'blog-over')));
            },
        ),
    ),
));

// ═══════════════════════════════════════════
// C) Number of Posts
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_you_missed_count',
    'label' => esc_html__('Number of Posts', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => 4,
    'priority' => 15,
    'choices' => array('min' => 1, 'max' => 12, 'step' => 1),
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// D) Show On Pages
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'multicheck',
    'settings' => 'blog_over_you_missed_show_on',
    'label' => esc_html__('Show On Pages', 'blog-over'),
    'description' => esc_html__('Select pages where section should appear.', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => array('blog', 'single', 'archive'),
    'priority' => 6,
    'choices' => array(
        'home' => esc_html__('Home Page', 'blog-over'),
        'blog' => esc_html__('Blog / Posts Page', 'blog-over'),
        'single' => esc_html__('Single Post', 'blog-over'),
        'page' => esc_html__('Single Page', 'blog-over'),
        'archive' => esc_html__('Archive Pages', 'blog-over'),
        'search' => esc_html__('Search Results', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// D.2) Section Width
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_you_missed_section_width',
    'label' => esc_html__('Section Width', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => 'boxed',
    'priority' => 7,
    'choices' => array(
        'boxed' => esc_html__('Boxed', 'blog-over'),
        'full-width' => esc_html__('Full Width', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// E) Category Filter
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_you_missed_category',
    'label' => esc_html__('Filter by Category', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => 'all',
    'priority' => 17,
    'choices' => blog_over_get_categories_dropdown(),
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// DESIGN SETTINGS HEADING (before Layout)
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_ym_design_heading_main',
    'section' => 'blog_over_youmissed_section',
    'default' => '<div style="background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); padding: 10px 14px; border-radius: 6px; margin-top: 20px; border-left: 3px solid #3b82f6;"><span style="font-size: 13px; font-weight: 600; color: #1e40af; text-transform: uppercase; letter-spacing: 0.5px;">' . esc_html__('Design Settings', 'blog-over') . '</span></div>',
    'priority' => 19,
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// F) Layout Style
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_you_missed_layout',
    'label' => esc_html__('Layout Style', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => 'default',
    'priority' => 20,
    'choices' => blog_over_get_you_missed_layout_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// G) Column Count
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_you_missed_columns',
    'label' => esc_html__('Columns', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => '4',
    'priority' => 21,
    'choices' => blog_over_get_you_missed_columns_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// H) Image Height
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_you_missed_image_height',
    'label' => esc_html__('Image Height (px)', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => 180,
    'priority' => 22,
    'choices' => array('min' => 100, 'max' => 350, 'step' => 10),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-missed-thumb',
            'property' => 'height',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// I) Post Card Elements (sortable)
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_ym_elements_heading',
    'section' => 'blog_over_youmissed_section',
    'default' => '<div style="background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); padding: 10px 14px; border-radius: 6px; margin-top: 20px; border-left: 3px solid #3b82f6;"><span style="font-size: 13px; font-weight: 600; color: #1e40af; text-transform: uppercase; letter-spacing: 0.5px;">' . esc_html__('Post Elements', 'blog-over') . '</span></div>',
    'priority' => 25,
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_you_missed_elements',
    'label' => esc_html__('Card Elements', 'blog-over'),
    'description' => esc_html__('Drag to reorder. Uncheck to hide.', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => array(
        'category',
        'title',
        'meta',
    ),
    'choices' => array(
        'category' => esc_html__('Category Badge', 'blog-over'),
        'title' => esc_html__('Post Title', 'blog-over'),
        'meta' => esc_html__('Post Meta', 'blog-over'),
    ),
    'priority' => 26,
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
    ),
));

// ═══════════════════════════════════════════
// J) Meta Elements (sortable - like blog settings)
// ═══════════════════════════════════════════
Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_you_missed_meta_elements',
    'label' => esc_html__('Meta Elements', 'blog-over'),
    'description' => esc_html__('Drag to reorder. Uncheck to hide.', 'blog-over'),
    'section' => 'blog_over_youmissed_section',
    'default' => array(
        'date',
    ),
    'choices' => array(
        'author' => esc_html__('Author', 'blog-over'),
        'date' => esc_html__('Date', 'blog-over'),
        'comments' => esc_html__('Comments', 'blog-over'),
    ),
    'priority' => 27,
    'active_callback' => array(
        array('setting' => 'blog_over_you_missed_show', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_you_missed_elements', 'operator' => 'contains', 'value' => 'meta'),
    ),
));
