<?php
/**
 * Related Posts Section Settings
 * Matches Blog Settings structure
 *
 * @package Blog_Over
 */

// ---------------------------------------------
// Section: Related Posts
// ---------------------------------------------
Kirki::add_section('blog_over_related_section', array(
    'title' => esc_html__('Related Posts', 'blog-over'),
    'panel' => 'Blog_Over_panel',
    'priority' => 60,
));

// Enable Related Posts
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_enable_related',
    'label' => esc_html__('Show Related Posts', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => true,
    'priority' => 10,
    'partial_refresh' => array(
        'blog_over_related_posts_refresh' => array(
            'selector' => '.blog-over-related-posts',
            'render_callback' => 'blog_over_related_posts',
        ),
    ),
));

// Section Title
Kirki::add_field('Blog_Over_config', array(
    'type' => 'text',
    'settings' => 'blog_over_related_title',
    'label' => esc_html__('Section Title', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => esc_html__('Related Posts', 'blog-over'),
    'priority' => 20,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
    ),
));

// Number of Posts
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_related_count',
    'label' => esc_html__('Number of Posts', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => 3,
    'priority' => 30,
    'choices' => array(
        'min' => 2,
        'max' => 6,
        'step' => 1,
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
    ),
));

// Column Count
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_related_columns',
    'label' => esc_html__('Columns', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => '3',
    'priority' => 35,
    'choices' => array(
        '2' => '2',
        '3' => '3',
        '4' => '4',
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
    ),
));

// Related by
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_related_by',
    'label' => esc_html__('Related Posts Based On', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => 'category',
    'priority' => 40,
    'choices' => blog_over_get_related_by_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
    ),
));

// Custom Categories (multi-select)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_related_custom_cats',
    'label' => esc_html__('Select Categories', 'blog-over'),
    'description' => esc_html__('Choose categories to show related posts from', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => array(),
    'priority' => 41,
    'multiple' => 999,
    'choices' => blog_over_get_categories_choices(),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_related_by', 'operator' => '==', 'value' => 'custom_category'),
    ),
));

// Custom Tags (multi-select)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_related_custom_tags',
    'label' => esc_html__('Select Tags', 'blog-over'),
    'description' => esc_html__('Choose tags to show related posts from', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => array(),
    'priority' => 42,
    'multiple' => 999,
    'choices' => blog_over_get_tags_choices(),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_related_by', 'operator' => '==', 'value' => 'custom_tag'),
    ),
));

// =============================================
// POST ELEMENTS (Like Blog Settings)
// =============================================

Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_related_elements_heading',
    'section' => 'blog_over_related_section',
    'default' => '<div style="padding: 12px 0; border-top: 1px solid #ddd; margin-top: 20px;"><strong>' . esc_html__('Post Elements', 'blog-over') . '</strong></div>',
    'priority' => 50,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
    ),
));

// Post Card Elements Sortable (Like Blog Settings - includes thumbnail)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_related_entry_elements',
    'label' => esc_html__('Post Card Elements', 'blog-over'),
    'description' => esc_html__('Drag to reorder. Uncheck to hide.', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => array(
        'thumbnail',
        'meta',
        'title',
        'excerpt',
    ),
    'choices' => array(
        'thumbnail' => esc_html__('Featured Image', 'blog-over'),
        'meta' => esc_html__('Post Meta', 'blog-over'),
        'title' => esc_html__('Post Title', 'blog-over'),
        'excerpt' => esc_html__('Excerpt', 'blog-over'),
    ),
    'priority' => 51,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
    ),
));

// Excerpt Length Slider (after Post Card Elements, hidden if excerpt is hidden)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_related_excerpt_length',
    'label' => esc_html__('Excerpt Length (words)', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => 12,
    'choices' => array('min' => 5, 'max' => 30, 'step' => 1),
    'priority' => 52,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_related_entry_elements', 'operator' => 'contains', 'value' => 'excerpt'),
    ),
));

// =============================================
// POST META (Sortable like Blog Settings)
// =============================================

Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_related_meta_heading',
    'section' => 'blog_over_related_section',
    'default' => '<div style="padding: 12px 0; border-top: 1px solid #ddd; margin-top: 20px;"><strong>' . esc_html__('Post Meta', 'blog-over') . '</strong></div>',
    'priority' => 60,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_related_entry_elements', 'operator' => 'contains', 'value' => 'meta'),
    ),
));

// Meta Elements Sortable (like Blog Settings - with comments)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_related_meta_elements',
    'label' => esc_html__('Meta Elements', 'blog-over'),
    'description' => esc_html__('Set order and visibility for post meta items.', 'blog-over'),
    'section' => 'blog_over_related_section',
    'default' => array(
        'author',
        'date',
        'category',
    ),
    'choices' => array(
        'author' => esc_html__('Author', 'blog-over'),
        'date' => esc_html__('Publish Date', 'blog-over'),
        'category' => esc_html__('Category', 'blog-over'),
        'comments' => esc_html__('Comments', 'blog-over'),
    ),
    'priority' => 61,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_related', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_related_entry_elements', 'operator' => 'contains', 'value' => 'meta'),
    ),
));
