<?php
/**
 * Single Post Settings Section
 *
 * @package Blog_Over
 */

// ---------------------------------------------
// Section: Single Post Settings
// ---------------------------------------------
Kirki::add_section('blog_over_single_section', array(
    'title' => esc_html__('Single Post Settings', 'blog-over'),
    'panel' => 'Blog_Over_panel',
    'priority' => 40,
));

// =============================================
// LAYOUT SETTINGS
// =============================================

// Post Layout (Sidebar Position)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-image',
    'settings' => 'blog_over_single_layout',
    'label' => esc_html__('Post Layout', 'blog-over'),
    'section' => 'blog_over_single_section',
    'default' => 'single-right',
    'priority' => 5,
    'choices' => array(
        'single-right' => get_template_directory_uri() . '/assets/images/layout-right-sidebar.svg',
        'single-left' => get_template_directory_uri() . '/assets/images/layout-left-sidebar.svg',
        'single-full' => get_template_directory_uri() . '/assets/images/layout-fullwidth.svg',
    ),
    'transport' => 'refresh',
));

// Title & Meta Position
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_single_title_position',
    'label' => esc_html__('Title & Meta Position', 'blog-over'),
    'description' => esc_html__('Where to show title, category and meta. Note: "In Page Header" requires Page Header to be enabled.', 'blog-over'),
    'section' => 'blog_over_single_section',
    'default' => 'in-page-header',
    'priority' => 5,
    'choices' => array(
        'in-page-header' => esc_html__('In Page Header', 'blog-over'),
        'in-content' => esc_html__('In Content', 'blog-over'),
    ),
    'transport' => 'refresh',
));

// Content Width
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_single_content_width',
    'label' => esc_html__('Content Width', 'blog-over'),
    'description' => esc_html__('Controls how wide your post content area is. Narrow is best for reading.', 'blog-over'),
    'section' => 'blog_over_single_section',
    'default' => 'default',
    'priority' => 6,
    'choices' => array(
        'narrow' => esc_html__('Narrow (800px)', 'blog-over'),
        'default' => esc_html__('Default (1000px)', 'blog-over'),
        'wide' => esc_html__('Wide (1200px)', 'blog-over'),
        'full' => esc_html__('Full (100%)', 'blog-over'),
    ),
    'transport' => 'refresh',
));

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

Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_single_elements_heading',
    'section' => 'blog_over_single_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' => 10,
));

// Featured Image Toggle
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_single_show_featured',
    'label' => esc_html__('Featured Image', 'blog-over'),
    'description' => esc_html__('Show featured image on single posts.', 'blog-over'),
    'section' => 'blog_over_single_section',
    'default' => true,
    'priority' => 11,
));

// Post Elements Sortable
Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_single_elements',
    'label' => esc_html__('Post Elements', 'blog-over'),
    'description' => esc_html__('Drag to reorder. Uncheck to hide.', 'blog-over'),
    'section' => 'blog_over_single_section',
    'default' => array(
        'category',
        'meta',
        'tags',
        'share',
        'author_box',
        'post_nav',
        'comments',
    ),
    'choices' => array(
        'category' => esc_html__('Category', 'blog-over'),
        'meta' => esc_html__('Post Meta', 'blog-over'),
        'tags' => esc_html__('Tags', 'blog-over'),
        'share' => esc_html__('Share Buttons', 'blog-over'),
        'author_box' => esc_html__('Author Box', 'blog-over'),
        'post_nav' => esc_html__('Post Navigation', 'blog-over'),
        'comments' => esc_html__('Comments Section', 'blog-over'),
    ),
    'priority' => 12,
    'partial_refresh' => array(
        'blog_over_single_elements_refresh' => array(
            'selector' => '.blog-over-single-post, .blog-over-page-header',
            'render_callback' => function () {
                get_template_part('template-parts/content', 'single');
                // Page header refresh logic if needed, but selector targets header too
            },
        ),
    ),
));

// Notice for In Page Header
Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_single_header_notice',
    'section' => 'blog_over_single_section',
    'default' => '<div style="padding: 10px; background-color: #e3f2fd; border-left: 4px solid #2196f3; color: #0c5460; font-size: 13px; margin-top: 15px;">' . esc_html__('Note: Elements selected above will only appear in the Page Header if the "Title Position" is set to "In Page Header" and the Global Page Header is enabled.', 'blog-over') . '</div>',
    'priority' => 12,
    'active_callback' => array(
        array(
            'setting' => 'blog_over_single_title_position',
            'operator' => '==',
            'value' => 'in-page-header',
        ),
    ),
));

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

Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_single_meta_heading',
    'section' => 'blog_over_single_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' => 15,
    'active_callback' => array(
        array('setting' => 'blog_over_single_elements', 'operator' => 'contains', 'value' => 'meta'),
    ),
));

Kirki::add_field('Blog_Over_config', array(
    'type' => 'sortable',
    'settings' => 'blog_over_single_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_single_section',
    'default' => array(
        'author',
        'date',
        'comments',
    ),
    'choices' => array(
        'author' => esc_html__('Author', 'blog-over'),
        'date' => esc_html__('Publish Date', 'blog-over'),
        'comments' => esc_html__('Comments Count', 'blog-over'),
    ),
    'priority' => 16,
    'active_callback' => array(
        array('setting' => 'blog_over_single_elements', 'operator' => 'contains', 'value' => 'meta'),
    ),
));

// =============================================
// TYPOGRAPHY
// =============================================

Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_single_typography_heading',
    'section' => 'blog_over_single_section',
    'default' => '<div style="padding: 12px 0; border-top: 1px solid #ddd; margin-top: 20px;"><strong>' . esc_html__('Typography', 'blog-over') . '</strong></div>',
    'priority' => 20,
));

// Drop Caps
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_single_drop_caps',
    'label' => esc_html__('Enable Drop Caps', 'blog-over'),
    'description' => esc_html__('Make the first letter of content larger.', 'blog-over'),
    'section' => 'blog_over_single_section',
    'default' => false,
    'priority' => 21,
));
