<?php
/**
 * Hero Section Settings
 *
 * @package Blog_Over
 */

Kirki::add_section('blog_over_hero_section', array(
    'title' => esc_html__('Hero Section', 'blog-over'),
    'panel' => 'blog_over_frontpage_panel',
    'priority' => 20,
));

// ─────────────────────────────────────────────
// A) Enable / Visibility
// ─────────────────────────────────────────────

// Hero Enable
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_enable_hero',
    'label' => esc_html__('Enable Hero Section', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'default' => false,
    'priority' => 10,
));

// Enable On (Page visibility)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'multicheck',
    'settings' => 'blog_over_hero_enable_on',
    'label' => esc_html__('Show On Pages:', 'blog-over'),
    'description' => esc_html__('Choose pages to show Hero Section', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'default' => array('home', 'posts_page'),
    'priority' => 11,
    'choices' => array(
        'home' => esc_html__('Home Page', 'blog-over'),
        'posts_page' => esc_html__('Blog / Posts Page', 'blog-over'),
        'archive' => esc_html__('Archive Page', 'blog-over'),
        'search' => esc_html__('Search Page', 'blog-over'),
        'post' => esc_html__('Single Post', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
));

// Section Width
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_hero_container',
    'label' => esc_html__('Section Width', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'default' => 'container',
    'priority' => 12,
    'choices' => array(
        'container' => esc_html__('Contained', 'blog-over'),
        'full-width' => esc_html__('Full Width', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
));

// Slide Effect (Global for all sliders)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_hero_slide_effect',
    'label' => esc_html__('Slide Effect', 'blog-over'),
    'description' => esc_html__('Transition effect for all sliders', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'default' => 'slide',
    'priority' => 13,
    'choices' => blog_over_get_hero_slide_effect_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// B) Slider Layout (Single Setting Controls Everything)
// ─────────────────────────────────────────────

Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_hero_slide_count',
    'label' => esc_html__('Slider Layout', 'blog-over'),
    'description' => esc_html__('Choose how many slider columns to display. Each column shows posts from its own category.', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'default' => '3',
    'priority' => 15,
    'choices' => array(
        '1' => esc_html__('1 Column', 'blog-over'),
        '2' => esc_html__('2 Columns', 'blog-over'),
        '3' => esc_html__('3 Columns', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
    'partial_refresh' => array(
        'blog_over_hero_slide_count_refresh' => array(
            'selector' => '.blog-over-hero-wrapper',
            'render_callback' => 'blog_over_render_hero_partial',
            'container_inclusive' => true,
        ),
    ),
));

// ─────────────────────────────────────────────
// B2) Hero Height (Master Setting for All Layouts)
// ─────────────────────────────────────────────

Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_hero_height',
    'label' => esc_html__('Hero Height (px)', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'default' => 620,
    'priority' => 54,
    'choices' => array(
        'min' => 400,
        'max' => 900,
        'step' => 10,
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
    'output' => array(
        array(
            'element' => '.blog-over-hero-grid',
            'property' => 'height',
            'units' => 'px',
        ),
        array(
            'element' => '.hero-slide-count-1 .blog-over-hero-slot',
            'property' => 'height',
            'units' => 'px',
        ),
    ),
));

// ─────────────────────────────────────────────
// C) Slider Widgets (Always 3 widgets, visibility controlled by Slide Count)
// ─────────────────────────────────────────────

Kirki::add_field('Blog_Over_config', array(
    'type' => 'repeater',
    'settings' => 'blog_over_hero_slider_widgets',
    'label' => esc_html__('Slider Widgets', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'priority' => 20,
    'row_label' => array(
        'type' => 'field',
        'value' => esc_html__('Slider', 'blog-over'),
        'field' => 'widget_title',
    ),
    'button_label' => esc_html__('', 'blog-over'),
    'choices' => array(
        'limit' => 3,
    ),
    'default' => array(
        array(
            'widget_title' => esc_html__('Slider 1', 'blog-over'),
            'category' => '',
            'posts_count' => 5,
            'autoplay' => true,
            'autoplay_speed' => 8,
            'loop' => true,
            'show_arrows' => false,
            'show_dots' => true,
            'order' => 'latest',
        ),
        array(
            'widget_title' => esc_html__('Slider 2', 'blog-over'),
            'category' => '',
            'posts_count' => 5,
            'autoplay' => true,
            'autoplay_speed' => 10,
            'loop' => true,
            'show_arrows' => false,
            'show_dots' => true,
            'order' => 'latest',
        ),
        array(
            'widget_title' => esc_html__('Slider 3', 'blog-over'),
            'category' => '',
            'posts_count' => 5,
            'autoplay' => true,
            'autoplay_speed' => 5,
            'loop' => true,
            'show_arrows' => false,
            'show_dots' => true,
            'order' => 'latest',
        ),
    ),
    'fields' => array(
        'widget_title' => array(
            'type' => 'text',
            'label' => esc_html__('Widget Title', 'blog-over'),
            'default' => esc_html__('Slider', 'blog-over'),
        ),
        'category' => array(
            'type' => 'select',
            'label' => esc_html__('Category', 'blog-over'),
            'default' => '',
            'choices' => blog_over_get_categories_choices(),
        ),
        'posts_count' => array(
            'type' => 'number',
            'label' => esc_html__('Posts Count', 'blog-over'),
            'default' => 5,
            'choices' => array(
                'min' => 1,
                'max' => 10,
                'step' => 1,
            ),
        ),
        'autoplay' => array(
            'type' => 'checkbox',
            'label' => esc_html__('Enable Autoplay', 'blog-over'),
            'default' => true,
        ),
        'autoplay_speed' => array(
            'type' => 'number',
            'label' => esc_html__('Autoplay Speed (seconds)', 'blog-over'),
            'default' => 5,
            'choices' => array(
                'min' => 2,
                'max' => 15,
                'step' => 1,
            ),
        ),
        'loop' => array(
            'type' => 'checkbox',
            'label' => esc_html__('Loop Slides', 'blog-over'),
            'default' => true,
        ),
        'show_arrows' => array(
            'type' => 'checkbox',
            'label' => esc_html__('Show Navigation Arrows', 'blog-over'),
            'default' => false,
        ),
        'show_dots' => array(
            'type' => 'checkbox',
            'label' => esc_html__('Show Dots/Pagination', 'blog-over'),
            'default' => true,
        ),
        'order' => array(
            'type' => 'select',
            'label' => esc_html__('Post Order', 'blog-over'),
            'default' => 'latest',
            'choices' => array(
                'latest' => esc_html__('Latest Posts', 'blog-over'),
                'random' => esc_html__('Random Posts', 'blog-over'),
            ),
        ),

    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// D) Post Card Elements (sortable like blog settings)
// ─────────────────────────────────────────────

// Post Elements Heading
Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_hero_elements_heading',
    'section' => 'blog_over_hero_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__('Slider Elements', 'blog-over') . '</span></div>',
    'priority' => 50,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
));

Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_hero_elements',
    'label' => esc_html__('Slider Elements', 'blog-over'),
    'description' => esc_html__('Drag to reorder. Uncheck to hide.', 'blog-over'),
    'section' => 'blog_over_hero_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' => 51,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// E) Meta Elements (sortable - nested under Post Meta)
// ─────────────────────────────────────────────

Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_hero_meta_elements',
    'label' => esc_html__('Slider Meta Elements', 'blog-over'),
    'description' => esc_html__('Drag to reorder. Uncheck to hide.', 'blog-over'),
    'section' => 'blog_over_hero_section',
    'default' => array(
        'author',
        'date',
    ),
    'choices' => array(
        'author' => esc_html__('Author', 'blog-over'),
        'date' => esc_html__('Publish Date', 'blog-over'),
    ),
    'priority' => 52,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_hero', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_hero_elements', 'operator' => 'contains', 'value' => 'meta'),
    ),
));
