<?php
/**
 * Blog Over Breadcrumb Settings
 * 
 * @package Blog_Over
 */

if (!defined('ABSPATH')) {
    exit;
}

if (!class_exists('Kirki')) {
    return;
}

// =============================================
// Section: Breadcrumb Settings
// =============================================
// Pencil icon will appear centered above breadcrumb wherever it is displayed
Kirki::add_section('blog_over_breadcrumb_section', array(
    'title' => esc_html__('Breadcrumb Settings', 'blog-over'),
    'panel' => 'blog_over_theme_panel',
    'priority' => 15,
    // Target the breadcrumb nav element directly - works in both positions
    'preview_selector' => '.blog-over-breadcrumb',
));

// =============================================
// Enable Breadcrumbs
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_breadcrumb_enable',
    'label' => esc_html__('Enable Breadcrumbs', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => true,
    'priority' => 10,
    // Partial refresh to show pencil icon on breadcrumb
    'partial_refresh' => array(
        'blog_over_breadcrumb_in_header' => array(
            'selector' => '.blog-over-page-header .blog-over-breadcrumb',
            'render_callback' => 'blog_over_output_breadcrumb_trail',
            'container_inclusive' => false,
        ),
        'blog_over_breadcrumb_standalone' => array(
            'selector' => '.blog-over-breadcrumb-wrapper',
            'render_callback' => 'Blog_Over_breadcrumb',
            'container_inclusive' => true,
        ),
    ),
));

// =============================================
// Disable On Specific Pages
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'multicheck',
    'settings' => 'blog_over_breadcrumb_hide_on',
    'label' => esc_html__('Disable On:', 'blog-over'),
    'description' => esc_html__('Choose on which pages you want to disable breadcrumbs.', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => array(),
    'priority' => 20,
    'choices' => array(
        'home' => esc_html__('Homepage', 'blog-over'),
        'posts' => esc_html__('Blog Page', 'blog-over'),
        'single' => esc_html__('Single Posts', 'blog-over'),
        'page' => esc_html__('Pages', 'blog-over'),
        'archive' => esc_html__('Archives', 'blog-over'),
        'search' => esc_html__('Search Results', 'blog-over'),
        '404' => esc_html__('404 Page', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Breadcrumb Type (Source)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_breadcrumb_type',
    'label' => esc_html__('Breadcrumb Source', 'blog-over'),
    'description' => esc_html__('Theme Default works out of the box. Other options require their plugins to be installed: NavXT, Yoast SEO, or Rank Math.', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 'default',
    'priority' => 30,
    'choices' => array(
        'default' => esc_html__('Theme Default (No Plugin Needed)', 'blog-over'),
        'navxt' => esc_html__('Breadcrumb NavXT (Plugin Required)', 'blog-over'),
        'yoast' => esc_html__('Yoast SEO (Plugin Required)', 'blog-over'),
        'rankmath' => esc_html__('Rank Math (Plugin Required)', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Breadcrumb Position
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_breadcrumb_position',
    'label' => esc_html__('Position', 'blog-over'),
    'description' => esc_html__('"In Page Header" places breadcrumb inside the page header banner. Requires Page Header to be enabled in Theme Design.', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 'below-header',
    'priority' => 40,
    'choices' => array(
        'in-page-header' => esc_html__('In Page Header', 'blog-over'),
        'below-header' => esc_html__('Below Header', 'blog-over'),
    ),
    // Use refresh transport so pencil icon appears in correct location after position change
    'transport' => 'refresh',
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Breadcrumb Alignment
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_breadcrumb_alignment',
    'label' => esc_html__('Alignment', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 'left',
    'priority' => 50,
    'choices' => array(
        'left' => esc_html__('Left', 'blog-over'),
        'center' => esc_html__('Center', 'blog-over'),
        'right' => esc_html__('Right', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_position', 'operator' => '!=', 'value' => 'in-page-header'),
    ),
));

// =============================================
// Alignment Note (shown when in-page-header AND page header enabled)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_breadcrumb_alignment_note',
    'section' => 'blog_over_breadcrumb_section',
    'default' => '<div style="padding: 10px 12px; background: #d1ecf1; border-left: 4px solid #17a2b8; border-radius: 4px; color: #0c5460; font-size: 13px;"><strong>Info:</strong> ' . esc_html__('Some settings like alignment, padding, and background are managed by Page Header settings when breadcrumb is inside the header.', 'blog-over') . '</div>',
    'priority' => 51,
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_position', 'operator' => '==', 'value' => 'in-page-header'),
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Warning Note (shown when in-page-header BUT page header disabled)
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'custom',
    'settings' => 'blog_over_breadcrumb_header_disabled_note',
    'section' => 'blog_over_breadcrumb_section',
    'default' => '<div style="padding: 10px 12px; background: #f8d7da; border-left: 4px solid #dc3545; border-radius: 4px; color: #721c24; font-size: 13px;"><strong>Warning:</strong> ' . esc_html__('Page Header is currently disabled. Please enable it in Page Header settings for breadcrumbs to appear inside the header.', 'blog-over') . '</div>',
    'priority' => 51,
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_position', 'operator' => '==', 'value' => 'in-page-header'),
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => false),
    ),
));

// =============================================
// Breadcrumb Separator
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_breadcrumb_separator',
    'label' => esc_html__('Separator', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 'chevron',
    'priority' => 60,
    'choices' => array(
        'chevron' => esc_html__('› Chevron', 'blog-over'),
        'arrow' => esc_html__('→ Arrow', 'blog-over'),
        'slash' => esc_html__('/ Slash', 'blog-over'),
        'pipe' => esc_html__('| Pipe', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_type', 'operator' => '==', 'value' => 'default'),
    ),
));

// =============================================
// Background Image
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'image',
    'settings' => 'blog_over_breadcrumb_bg_image',
    'label' => esc_html__('Background Image', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => '',
    'priority' => 65,
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_position', 'operator' => '!=', 'value' => 'in-page-header'),
    ),
));

// =============================================
// Background Color
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_breadcrumb_bg_color',
    'label' => esc_html__('Background Color', 'blog-over'),
    'description' => esc_html__('Applied when no background image is set. Respects theme skin.', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => '',
    'priority' => 70,
    'choices' => array('alpha' => true),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_position', 'operator' => '!=', 'value' => 'in-page-header'),
    ),
));

// =============================================
// Breadcrumb Color Mode
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_breadcrumb_color_mode',
    'label' => esc_html__('Text/Link Color', 'blog-over'),
    'description' => esc_html__('Default uses theme skin colors. Custom allows manual color selection.', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 'default',
    'priority' => 75,
    'choices' => array(
        'default' => esc_html__('Default Color', 'blog-over'),
        'custom' => esc_html__('Custom Color', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
    ),
));

// =============================================
// Text Color
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_breadcrumb_text_color',
    'label' => esc_html__('Text Color', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => '#64748b',
    'priority' => 80,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-breadcrumb, .blog-over-breadcrumb-item, .blog-over-breadcrumb-item::after, .blog-over-page-header .blog-over-breadcrumb, .blog-over-page-header .blog-over-breadcrumb-item',
            'property' => 'color',
            'suffix' => ' !important',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_color_mode', 'operator' => '==', 'value' => 'custom'),
    ),
));

// =============================================
// Link Color
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_breadcrumb_link_color',
    'label' => esc_html__('Link Color', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => '#3b82f6',
    'priority' => 90,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-breadcrumb-item a, .blog-over-page-header .blog-over-breadcrumb-item a',
            'property' => 'color',
            'suffix' => ' !important',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_color_mode', 'operator' => '==', 'value' => 'custom'),
    ),
));

// =============================================
// Link Hover Color
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_breadcrumb_link_hover_color',
    'label' => esc_html__('Link Hover Color', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => '#1d4ed8',
    'priority' => 100,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-breadcrumb-item a:hover, .blog-over-page-header .blog-over-breadcrumb-item a:hover',
            'property' => 'color',
            'suffix' => ' !important',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_color_mode', 'operator' => '==', 'value' => 'custom'),
    ),
));

// =============================================
// Padding Top
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_breadcrumb_padding_top',
    'label' => esc_html__('Padding Top (px)', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 15,
    'priority' => 110,
    'choices' => array('min' => 0, 'max' => 50, 'step' => 1),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-breadcrumb-wrapper, .blog-over-page-header .blog-over-breadcrumb',
            'property' => 'padding-top',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_position', 'operator' => '!=', 'value' => 'in-page-header'),
    ),
));

// =============================================
// Padding Bottom
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_breadcrumb_padding_bottom',
    'label' => esc_html__('Padding Bottom (px)', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 15,
    'priority' => 120,
    'choices' => array('min' => 0, 'max' => 50, 'step' => 1),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-breadcrumb-wrapper, .blog-over-page-header .blog-over-breadcrumb',
            'property' => 'padding-bottom',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_breadcrumb_position', 'operator' => '!=', 'value' => 'in-page-header'),
    ),
));

// =============================================
// Font Size
// =============================================
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_breadcrumb_font_size',
    'label' => esc_html__('Font Size (px)', 'blog-over'),
    'section' => 'blog_over_breadcrumb_section',
    'default' => 13,
    'priority' => 130,
    'choices' => array('min' => 10, 'max' => 20, 'step' => 1),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-breadcrumb, .blog-over-breadcrumb-item, .blog-over-breadcrumb-list',
            'property' => 'font-size',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_breadcrumb_enable', 'operator' => '==', 'value' => true),
    ),
));
