<?php
/**
 * Blog Over Kirki Customizer - MINIMAL VERSION
 * 
 * Step-by-step panel enable to find dirty state issue
 * Currently: ONLY Top Bar basic settings (no headings, no complex controls)
 *
 * @package Blog_Over
 */

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

// Check if Kirki exists
if (!class_exists('Kirki')) {
    return;
}

/**
 * Add Kirki Config
 */
Kirki::add_config('Blog_Over_config', array(
    'capability' => 'edit_theme_options',
    'option_type' => 'theme_mod',
));

/**
 * ===========================================
 * PANEL: Header Options
 * ===========================================
 */
Kirki::add_panel('blog_over_header_panel', array(
    'priority' => 10,
    'title' => esc_html__('Header Options', 'blog-over'),
));

// ---------------------------------------------
// Section: Top Bar Settings
// ---------------------------------------------
Kirki::add_section('blog_over_topbar_section', array(
    'title' => esc_html__('Top Bar Settings', 'blog-over'),
    'panel' => 'blog_over_header_panel',
    'priority' => 10,
));

// === BASIC TOP BAR SETTINGS (MINIMAL - NO HEADINGS) ===

// 1. Show Top Bar Toggle
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_topbar_show',
    'label' => esc_html__('Show Top Bar', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => true,
    'priority' => 10,
));

// 2. Top Bar Height
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_topbar_height',
    'label' => esc_html__('Top Bar Height (px)', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => 40,
    'priority' => 20,
    'choices' => array('min' => 30, 'max' => 80, 'step' => 1),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-topbar',
            'property' => 'min-height',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_topbar_show', 'operator' => '==', 'value' => true),
    ),
));

// 3. Top Bar Width
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_topbar_width',
    'label' => esc_html__('Top Bar Width', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => 'full-width',
    'priority' => 30,
    'choices' => array(
        'full-width' => esc_html__('Full Width', 'blog-over'),
        'boxed' => esc_html__('Boxed', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_topbar_show', 'operator' => '==', 'value' => true),
    ),
));

// 4. Background Color (Simple solid color only)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_topbar_bg',
    'label' => esc_html__('Background Color', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => '#1e293b',
    'priority' => 40,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-topbar',
            'property' => 'background-color',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_topbar_show', 'operator' => '==', 'value' => true),
    ),
));

// 5. Text Color
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_topbar_text_color',
    'label' => esc_html__('Text Color', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => '#94a3b8',
    'priority' => 50,
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => ':root',
            'property' => '--blog-over-topbar-text',
        ),
        array(
            'element' => '.blog-over-topbar-date, .blog-over-topbar-text, .blog-over-topbar-custom-text, .blog-over-topbar a, .blog-over-topbar-centered-message, .blog-over-topbar-mobile-text',
            'property' => 'color',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_topbar_show', 'operator' => '==', 'value' => true),
    ),
));

// ===========================================
// PANEL 3 - Border Bottom Settings (Parent + Children)
// ===========================================

// 6. Show Border Bottom (Parent Toggle)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_topbar_border_show',
    'label' => esc_html__('Show Border Bottom', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => false,
    'priority' => 60,
    'active_callback' => array(
        array('setting' => 'blog_over_topbar_show', 'operator' => '==', 'value' => true),
    ),
));

// 7. Border Color (Child - only visible when border is enabled)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_topbar_border_color',
    'label' => esc_html__('Border Color', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => '#334155',
    'priority' => 61,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-topbar.blog-over-topbar-border',
            'property' => 'border-bottom-color',
            'suffix' => ' !important',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_topbar_show', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_topbar_border_show', 'operator' => '==', 'value' => true),
    ),
));

// 8. Border Width (Child - only visible when border is enabled)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_topbar_border_width',
    'label' => esc_html__('Border Width (px)', 'blog-over'),
    'section' => 'blog_over_topbar_section',
    'default' => 1,
    'priority' => 62,
    'choices' => array('min' => 1, 'max' => 5, 'step' => 1),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-topbar.blog-over-topbar-border',
            'property' => 'border-bottom-width',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_topbar_show', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_topbar_border_show', 'operator' => '==', 'value' => true),
    ),
));

// ===========================================
// PANEL 4 - Social Icons Section
// ===========================================

Kirki::add_section('blog_over_social_section', array(
    'title' => esc_html__('Social Icons', 'blog-over'),
    'panel' => 'blog_over_header_panel',
    'priority' => 20,
));

// 1. Show Social Icons Toggle (Parent)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_header_social_show',
    'label' => esc_html__('Show Social Icons in Header', 'blog-over'),
    'section' => 'blog_over_social_section',
    'default' => true,
    'priority' => 10,
));

// 2. Icon Size
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_social_icon_size',
    'label' => esc_html__('Icon Size (px)', 'blog-over'),
    'section' => 'blog_over_social_section',
    'default' => 14,
    'priority' => 20,
    'choices' => array('min' => 10, 'max' => 30, 'step' => 1),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-topbar-social-link i',
            'property' => 'font-size',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_header_social_show', 'operator' => '==', 'value' => true),
    ),
));

// 3. Icon Color
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_social_icon_color',
    'label' => esc_html__('Icon Color', 'blog-over'),
    'section' => 'blog_over_social_section',
    'default' => '#94a3b8',
    'priority' => 30,
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-topbar-social-link, .blog-over-topbar-social-link i',
            'property' => 'color',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_header_social_show', 'operator' => '==', 'value' => true),
    ),
));

// 4. Icon Hover Color
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_social_icon_hover_color',
    'label' => esc_html__('Icon Hover Color', 'blog-over'),
    'section' => 'blog_over_social_section',
    'default' => '#ffffff',
    'priority' => 40,
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-topbar-social-link:hover, .blog-over-topbar-social-link:hover i',
            'property' => 'color',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_header_social_show', 'operator' => '==', 'value' => true),
    ),
));

// 5. Icon Style
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_social_icon_style',
    'label' => esc_html__('Icon Style', 'blog-over'),
    'section' => 'blog_over_social_section',
    'default' => 'default',
    'priority' => 50,
    'choices' => array(
        'default' => esc_html__('Default', 'blog-over'),
        'outline' => esc_html__('Outline', 'blog-over'),
        'filled' => esc_html__('Filled', 'blog-over'),
        'rounded' => esc_html__('Rounded', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_header_social_show', 'operator' => '==', 'value' => true),
    ),
));

// ===========================================
// PANEL 5 - Button Settings (CTA)
// ===========================================

Kirki::add_section('blog_over_button_section', array(
    'title' => esc_html__('Button Settings', 'blog-over'),
    'panel' => 'blog_over_header_panel',
    'priority' => 32,
));

// 1. Show Subscribe Button (Parent)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_show_subscribe_btn',
    'label' => esc_html__('Show Subscribe Button', 'blog-over'),
    'section' => 'blog_over_button_section',
    'default' => true,
    'priority' => 10,
));

// 2. Button Text
Kirki::add_field('Blog_Over_config', array(
    'type' => 'text',
    'settings' => 'blog_over_subscribe_text',
    'label' => esc_html__('Button Text', 'blog-over'),
    'section' => 'blog_over_button_section',
    'default' => 'Subscribe',
    'priority' => 20,
    'active_callback' => array(
        array('setting' => 'blog_over_show_subscribe_btn', 'operator' => '==', 'value' => true),
    ),
));

// 3. Button URL
Kirki::add_field('Blog_Over_config', array(
    'type' => 'url',
    'settings' => 'blog_over_subscribe_url',
    'label' => esc_html__('Button URL', 'blog-over'),
    'section' => 'blog_over_button_section',
    'default' => '#',
    'priority' => 30,
    'active_callback' => array(
        array('setting' => 'blog_over_show_subscribe_btn', 'operator' => '==', 'value' => true),
    ),
));

// 4. Open in New Tab
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_subscribe_new_tab',
    'label' => esc_html__('Open in New Tab', 'blog-over'),
    'section' => 'blog_over_button_section',
    'default' => true,
    'priority' => 40,
    'active_callback' => array(
        array('setting' => 'blog_over_show_subscribe_btn', 'operator' => '==', 'value' => true),
    ),
));

// 5. Button Background Color
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_button_bg_color',
    'label' => esc_html__('Button Background', 'blog-over'),
    'section' => 'blog_over_button_section',
    'default' => '#3b82f6',
    'priority' => 50,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-subscribe-btn',
            'property' => 'background',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_show_subscribe_btn', 'operator' => '==', 'value' => true),
    ),
));

// 6. Button Text Color
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_button_text_color',
    'label' => esc_html__('Button Text Color', 'blog-over'),
    'section' => 'blog_over_button_section',
    'default' => '#ffffff',
    'priority' => 60,
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-subscribe-btn, .blog-over-subscribe-btn span',
            'property' => 'color',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_show_subscribe_btn', 'operator' => '==', 'value' => true),
    ),
));

// ===========================================
// PANEL 6 - Search Settings
// ===========================================

Kirki::add_section('blog_over_search_section', array(
    'title' => esc_html__('Search Settings', 'blog-over'),
    'panel' => 'blog_over_header_panel',
    'priority' => 35,
));

// 1. Show Search Icon (Parent)
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_show_search',
    'label' => esc_html__('Show Search Icon', 'blog-over'),
    'section' => 'blog_over_search_section',
    'default' => true,
    'priority' => 10,
));

// 2. Search Style
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_search_style',
    'label' => esc_html__('Search Style', 'blog-over'),
    'description' => esc_html__('Choose how the search opens.', 'blog-over'),
    'section' => 'blog_over_search_section',
    'default' => 'popup',
    'priority' => 20,
    'choices' => array(
        'popup' => esc_html__('Popup Modal', 'blog-over'),
        'inline' => esc_html__('Inline Expand', 'blog-over'),
        'slide-panel' => esc_html__('Slide Panel (LTR)', 'blog-over'),
        'slide-panel-rtl' => esc_html__('Slide Panel (RTL)', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_show_search', 'operator' => '==', 'value' => true),
    ),
));

// 3. Search Icon Size
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_search_icon_size',
    'label' => esc_html__('Icon Size (px)', 'blog-over'),
    'section' => 'blog_over_search_section',
    'default' => 16,
    'priority' => 30,
    'choices' => array('min' => 12, 'max' => 30, 'step' => 1),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-search-toggle i',
            'property' => 'font-size',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_show_search', 'operator' => '==', 'value' => true),
    ),
));

// 4. Search Icon Color
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_search_icon_color',
    'label' => esc_html__('Icon Color', 'blog-over'),
    'section' => 'blog_over_search_section',
    'default' => '#94a3b8',
    'priority' => 40,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-search-toggle, .blog-over-search-toggle i',
            'property' => 'color',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_show_search', 'operator' => '==', 'value' => true),
    ),
));

// 5. Search Icon Background
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_search_icon_bg',
    'label' => esc_html__('Icon Background', 'blog-over'),
    'section' => 'blog_over_search_section',
    'default' => 'transparent',
    'priority' => 50,
    'choices' => array('alpha' => true),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-search-toggle',
            'property' => 'background-color',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_show_search', 'operator' => '==', 'value' => true),
    ),
));
