<?php
/**
 * Blog Over Page Header Settings
 * 
 * @package Blog_Over
 */

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

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

// =============================================
// Section: Page Header Settings
// =============================================
Kirki::add_section('blog_over_page_header_section', array(
    'title' => esc_html__('Page Header', 'blog-over'),
    'panel' => 'blog_over_theme_panel',
    'priority' => 14,
    'preview_selector' => '.blog-over-page-title',
));

// =============================================
// Settings Hierarchy: 
// 1. Enable Toggle
// 2. Title Toggle (Moved from Page Settings)
// 3. Alignment
// 4. Background Priority Logic:
//    - Background Image (Custom)
//    - Use Featured Image (Toggle)
//    - Background Color (Fallback)
// =============================================

// = [1] Enable Page Header =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_page_header_enable',
    'label' => esc_html__('Enable Page Header', 'blog-over'),
    'description' => esc_html__('Show a page header section with title on pages and posts.', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => true,
    'priority' => 10,
    'partial_refresh' => array(
        'blog_over_page_header_enable_refresh' => array(
            'selector' => '.blog-over-page-header-container',
            'render_callback' => 'blog_over_page_header',
            'container_inclusive' => false,
        ),
    ),
));

// = [1.5] Show On Pages =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'multicheck',
    'settings' => 'blog_over_page_header_show_on',
    'label' => esc_html__('Enable On:', 'blog-over'),
    'description' => esc_html__('Choose which pages display the Page Header', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => array('single', 'page', 'archive', 'search', '404'),
    'priority' => 12,
    'choices' => array(
        'home' => esc_html__('Homepage', 'blog-over'),
        'posts_page' => esc_html__('Blog Posts Page', 'blog-over'),
        'single' => esc_html__('Single Posts', 'blog-over'),
        'page' => esc_html__('Pages', 'blog-over'),
        'archive' => esc_html__('Archives (Category, Tag, Date)', 'blog-over'),
        'search' => esc_html__('Search Results', 'blog-over'),
        '404' => esc_html__('404 Error Page', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

// = [2] Show Title =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_page_header_show_title',
    'label' => esc_html__('Show Page Title', 'blog-over'),
    'description' => esc_html__('Display the title inside the page header.', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => true,
    'priority' => 15,
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

// = [3] Alignment =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_page_header_alignment',
    'label' => esc_html__('Alignment', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => 'center',
    'priority' => 20,
    '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_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

// = [4] Background Image (Custom) =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'image',
    'settings' => 'blog_over_page_header_bg_image',
    'label' => esc_html__('Custom Background Image', 'blog-over'),
    'description' => esc_html__('Upload a specific image for all page headers.', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => '',
    'priority' => 25,
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

// = [5] Use Featured Image =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_page_header_use_featured',
    'label' => esc_html__('Featured Image as Background', 'blog-over'),
    'description' => esc_html__('NOTE: When no custom header image is selected, the page featured image will be used as the header background.', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => false,
    'priority' => 28,
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

// = [6] Background Color =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_page_header_bg_color',
    'label' => esc_html__('Background Color', 'blog-over'),
    'description' => esc_html__('NOTE: When no custom or featured image is available, the background color will be used', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => '',
    'priority' => 30,
    'choices' => array('alpha' => true),
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

// = [7] Text Color =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'color',
    'settings' => 'blog_over_page_header_text_color',
    'label' => esc_html__('Title Color', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => '',
    'priority' => 40,
    'choices' => array('alpha' => true),
    'transport' => 'postMessage',
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
    'partial_refresh' => array(
        'blog_over_page_header_text_color' => array(
            'selector' => '.blog-over-page-header',
            'render_callback' => 'blog_over_page_header',
            'container_inclusive' => true,
        ),
    ),
));

// = [8] Padding =
Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_page_header_padding_top',
    'label' => esc_html__('Padding Top (px)', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => 40,
    'priority' => 50,
    'choices' => array('min' => 0, 'max' => 150, 'step' => 5),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-page-header',
            'property' => 'padding-top',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));

Kirki::add_field('Blog_Over_config', array(
    'type' => 'slider',
    'settings' => 'blog_over_page_header_padding_bottom',
    'label' => esc_html__('Padding Bottom (px)', 'blog-over'),
    'section' => 'blog_over_page_header_section',
    'default' => 40,
    'priority' => 55,
    'choices' => array('min' => 0, 'max' => 150, 'step' => 5),
    'transport' => 'auto',
    'output' => array(
        array(
            'element' => '.blog-over-page-header',
            'property' => 'padding-bottom',
            'units' => 'px',
        ),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_page_header_enable', 'operator' => '==', 'value' => true),
    ),
));
