<?php
/**
 * Archive Settings Section
 * With Override Toggle - when ON uses archive-specific settings, when OFF inherits Blog Settings
 *
 * @package Blog_Over
 */

// ---------------------------------------------
// Section: Archive Settings
// ---------------------------------------------
Kirki::add_section('blog_over_archive_section', array(
    'title' => esc_html__('Archive Settings', 'blog-over'),
    'panel' => 'Blog_Over_panel',
    'priority' => 15,
));

// =============================================
// Archive Override Toggle (Master Control)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_archive_override',
    'label' => esc_html__('Customize Archive Pages', 'blog-over'),
    'description' => esc_html__('OFF = Archive pages (categories, tags, date) will use your Blog Settings automatically. ON = Customize archive pages separately with options below.', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => false,
    'priority' => 1,
    'partial_refresh' => array(
        'blog_over_archive_override_refresh' => array(
            'selector' => '.blog-over-archive-content-wrapper',
            'render_callback' => '__return_false',
        ),
    ),
));

// =============================================
// Archive Layout (Override Control)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-image',
    'settings' => 'blog_over_archive_layout',
    'label' => esc_html__('Archive Layout', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => 'right-sidebar',
    'priority' => 10,
    'choices' => array(
        'right-sidebar' => get_template_directory_uri() . '/assets/images/layout-right-sidebar.svg',
        'left-sidebar' => get_template_directory_uri() . '/assets/images/layout-left-sidebar.svg',
        'full-width' => get_template_directory_uri() . '/assets/images/layout-fullwidth.svg',
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_archive_override', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Archive Blog Style (Override Control)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_archive_style',
    'label' => esc_html__('Archive Blog Style', 'blog-over'),
    'description' => esc_html__('Choose the visual style for archive pages.', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => 'default',
    'priority' => 15,
    'choices' => array(
        'default' => esc_html__('Default (Current)', 'blog-over'),
        'modern-cards' => esc_html__('Modern Card Grid', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_archive_override', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Archive Post Elements (Sortable - Override Control)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_archive_entry_elements',
    'label' => esc_html__('Archive Post Elements', 'blog-over'),
    'description' => esc_html__('Drag to reorder. Uncheck to hide.', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => array(
        'category',
        'header',
        'meta',
        'summary',
        'footer',
    ),
    'choices' => array(
        'category' => esc_html__('Category Badge', 'blog-over'),
        'header' => esc_html__('Post Title', 'blog-over'),
        'meta' => esc_html__('Post Meta', 'blog-over'),
        'summary' => esc_html__('Excerpt', 'blog-over'),
        'footer' => esc_html__('Read More Button', 'blog-over'),
    ),
    'priority' => 20,
    'active_callback' => array(
        array('setting' => 'blog_over_archive_override', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Archive Post Meta (Sortable - Override Control)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_archive_entry_meta',
    'label' => esc_html__('Archive Meta Elements', 'blog-over'),
    'description' => esc_html__('Set order and visibility for post meta items.', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => array(
        'author',
        'date',
        'comments',
    ),
    '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' => 30,
    'active_callback' => array(
        array('setting' => 'blog_over_archive_override', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Archive Excerpt Length (Override Control)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_archive_excerpt_length',
    'label' => esc_html__('Archive Excerpt Length (words)', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => 25,
    'choices' => array('min' => 10, 'max' => 100, 'step' => 5),
    'priority' => 40,
    'active_callback' => array(
        array('setting' => 'blog_over_archive_override', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Existing Archive Settings (Always Visible)
// These are archive-specific settings that don't need override
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_archive_display_heading',
    'section' => 'blog_over_archive_section',
    'default' => '<div style="padding: 12px 0; border-top: 1px solid #ddd; margin-top: 20px;"><strong>' . esc_html__('Archive Display Options', 'blog-over') . '</strong></div>',
    'priority' => 50,
));

// Show Archive Header
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_archive_header',
    'label' => esc_html__('Show Archive Header (Title & Description)', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => true,
    'priority' => 60,
));

// Show Category Description
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_archive_description',
    'label' => esc_html__('Show Category/Tag Description', 'blog-over'),
    'section' => 'blog_over_archive_section',
    'default' => true,
    'priority' => 70,
));
