<?php
/**
 * Announcement Bar Section Settings (Free Version)
 *
 * Provides a repeater limited to 1 announcement bar in free theme.
 * Pro plugin overrides with unlimited repeater.
 *
 * @package Blog_Over
 */

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

// ---------------------------------------------
// Section: Announcement Bar
// ---------------------------------------------
Kirki::add_section('blog_over_announcement_bar_section', array(
    'title'    => esc_html__('Announcement Bar', 'blog-over'),
    'panel'    => 'blog_over_header_panel',
    'priority' => 11,
));

// ── Enable Toggle ───────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type'        => 'toggle',
    'settings'    => 'blog_over_announcement_show',
    'label'       => esc_html__('Enable Announcement Bar', 'blog-over'),
    'section'     => 'blog_over_announcement_bar_section',
    'default'     => false,
    'priority'    => 1,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-all',
    ),
    'partial_refresh' => array(
        'blog_over_announcement_show_refresh' => array(
            'selector'        => '.blog-over-announcement-wrapper',
            'render_callback' => 'blog_over_render_announcement_partial',
            'container_inclusive' => true,
            'fallback_refresh' => true,
        ),
    ),
));

// TABS CONTROL
Kirki::add_field('Blog_Over_config', array(
    'type' => 'blog-over-tabs',
    'settings' => 'blog_over_announcement_tabs',
    'section' => 'blog_over_announcement_bar_section',
    'priority' => 0.5,
    'active_callback' => array(
        array('setting' => 'blog_over_announcement_show', 'operator' => '==', 'value' => true),
    ),
));

// ── Background Color ────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type'        => 'color',
    'settings'    => 'blog_over_announcement_bg_color',
    'label'       => esc_html__('Background Color', 'blog-over'),
    'section'     => 'blog_over_announcement_bar_section',
    'default'     => '#3b82f6',
    'priority'    => 10,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-design',
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_announcement_show', 'operator' => '==', 'value' => true),
    ),
));

// ── Text Color ──────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type'        => 'color',
    'settings'    => 'blog_over_announcement_text_color',
    'label'       => esc_html__('Text Color', 'blog-over'),
    'section'     => 'blog_over_announcement_bar_section',
    'default'     => '#ffffff',
    'priority'    => 11,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-design',
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_announcement_show', 'operator' => '==', 'value' => true),
    ),
));



// ─────────────────────────────────────────────
// Announcement Repeater (Free: limit 1)
// ─────────────────────────────────────────────

$is_pro = function_exists('blog_over_is_pro_active') && blog_over_is_pro_active();

if (!$is_pro) {
    Kirki::add_field('Blog_Over_config', array(
        'type'         => 'repeater',
        'settings'     => 'blog_over_announcement_bars',
        'label'        => esc_html__('Announcement Bars', 'blog-over'),
        'description'  => esc_html__('Add an announcement bar. Pro version unlocks unlimited bars and layouts!', 'blog-over'),
        'section'      => 'blog_over_announcement_bar_section',
        'priority'     => 2,
        'choices'      => array('limit' => 1),
        'row_label'    => array(
            'type'  => 'field',
            'value' => esc_html__('Announcement', 'blog-over'),
            'field' => 'text',
        ),
        'button_label' => esc_html__('Add Announcement', 'blog-over'),
        'default'      => array(
            array(
                'text'        => esc_html__('🔥 Special Offer: Get 50% Off Today!', 'blog-over'),
                'link'        => '#',
                'link_text'   => esc_html__('Shop Now →', 'blog-over'),
                'new_tab'     => true,
            ),
        ),
        'fields'       => array(
            'text' => array(
                'type'    => 'text',
                'label'   => esc_html__('Announcement Text', 'blog-over'),
                'default' => esc_html__('New announcement here!', 'blog-over'),
            ),
            'link' => array(
                'type'    => 'text',
                'label'   => esc_html__('Link URL', 'blog-over'),
                'default' => '',
            ),
            'link_text' => array(
                'type'    => 'text',
                'label'   => esc_html__('Link / Button Text', 'blog-over'),
                'default' => esc_html__('Learn More →', 'blog-over'),
            ),
            'new_tab' => array(
                'type'    => 'checkbox',
                'label'   => esc_html__('Open Link in New Tab', 'blog-over'),
                'default' => true,
            ),
        ),
        'active_callback' => array(
            array('setting' => 'blog_over_announcement_show', 'operator' => '==', 'value' => true),
        ),
        'partial_refresh' => array(
            'blog_over_announcement_bars_refresh' => array(
                'selector'        => '.blog-over-announcement-wrapper',
                'render_callback' => 'blog_over_render_announcement_partial',
                'container_inclusive' => true,
                'fallback_refresh' => true,
            ),
        ),
    ));
}

