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

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

// ---------------------------------------------
// Section: Advertising Banner
// ---------------------------------------------
Kirki::add_section('blog_over_advertisement_section', array(
    'title' => esc_html__('Advertising Banner', 'blog-over'),
    'panel' => 'blog_over_frontpage_panel',
    'priority' => 70,
));

// ─────────────────────────────────────────────
// Enable Banner
// ─────────────────────────────────────────────

Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_ad_banner_enable',
    'label' => esc_html__('Enable Banner', 'blog-over'),
    'section' => 'blog_over_advertisement_section',
    'default' => false,
    'priority' => 10,
));

// ─────────────────────────────────────────────
// Section Width
// ─────────────────────────────────────────────

Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_ad_banner_section_width',
    'label' => esc_html__('Section Width', 'blog-over'),
    'section' => 'blog_over_advertisement_section',
    'default' => 'boxed',
    'priority' => 15,
    'choices' => array(
        'boxed' => esc_html__('Boxed', 'blog-over'),
        'full-width' => esc_html__('Full Width', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_ad_banner_enable', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// Banner Repeater (Free: limit 2)
// ─────────────────────────────────────────────

$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_ad_banners',
        'label' => esc_html__('Advertisement Banners', 'blog-over'),
        'section' => 'blog_over_advertisement_section',
        'priority' => 20,
        'choices' => array('limit' => 1),
        'row_label' => array(
            'type' => 'field',
            'value' => esc_html__('Banner', 'blog-over'),
            'field' => 'ad_title',
        ),
        'button_label' => esc_html__('Add Advertisement', 'blog-over'),
        'default' => array(
            array(
                'ad_title' => esc_html__('Your Ad Here', 'blog-over'),
                'ad_description' => esc_html__('Promote your brand with a stunning banner advertisement.', 'blog-over'),
                'ad_title_alignment' => 'center',
                'banner_layout' => 'classic',
                'placement' => 'below-header',
                'desktop_image' => get_template_directory_uri() . '/assets/images/starter-content/starter-ad-banner.jpg',
                'banner_link' => '#',
                'new_tab' => true,
                'btn_text' => esc_html__('Learn More', 'blog-over'),
                'btn_link' => '#',
                'btn_alignment' => 'center',
                'banner_max_width' => 100,
                'banner_height' => 0,
            )
        ),
        'partial_refresh' => array(
            'blog_over_ad_banners_top' => array(
                'selector' => '.blog-over-ad-placement-below-header',
                'render_callback' => 'blog_over_render_ads_below_header',
                'container_inclusive' => true,
                'fallback_refresh' => true,
            ),
            'blog_over_ad_banners_bottom' => array(
                'selector' => '.blog-over-ad-placement-above-footer',
                'render_callback' => 'blog_over_render_ads_above_footer',
                'container_inclusive' => true,
                'fallback_refresh' => true,
            ),
        ),
        'fields' => array(
            'ad_title' => array(
                'type' => 'text',
                'label' => esc_html__('Ad Title', 'blog-over'),
                'default' => esc_html__('Your Ad Here', 'blog-over'),
            ),
            'ad_description' => array(
                'type' => 'text',
                'label' => esc_html__('Ad Description', 'blog-over'),
                'default' => esc_html__('Promote your brand with a stunning banner advertisement.', 'blog-over'),
            ),
            'ad_title_alignment' => array(
                'type' => 'radio-buttonset',
                'label' => esc_html__('Title Alignment', 'blog-over'),
                'default' => 'center',
                'choices' => array(
                    'left' => esc_html__('Left', 'blog-over'),
                    'center' => esc_html__('Center', 'blog-over'),
                    'right' => esc_html__('Right', 'blog-over'),
                ),
            ),
            'banner_layout' => array(
                'type' => 'select',
                'label' => esc_html__('Banner Layout Style', 'blog-over'),
                'default' => 'classic',
                'choices' => array(
                    'classic' => esc_html__('Classic', 'blog-over'),
                    'split' => esc_html__('Split', 'blog-over'),
                ),
            ),
            'placement' => array(
                'type' => 'select',
                'label' => esc_html__('Placement', 'blog-over'),
                'default' => 'below-header',
                'choices' => array(
                    'below-header' => esc_html__('Below Header', 'blog-over'),
                    'above-footer' => esc_html__('Above Footer', 'blog-over'),
                ),
            ),
            'desktop_image' => array(
                'type' => 'image',
                'label' => esc_html__('Banner Image', 'blog-over'),
                'default' => get_template_directory_uri() . '/assets/images/starter-content/starter-ad-banner.jpg',
            ),
            'banner_link' => array(
                'type' => 'text',
                'label' => esc_html__('Banner Link', 'blog-over'),
                'default' => '#',
            ),
            'new_tab' => array(
                'type' => 'checkbox',
                'label' => esc_html__('Open in New Tab', 'blog-over'),
                'default' => true,
            ),
            'btn_text' => array(
                'type' => 'text',
                'label' => esc_html__('Button Text', 'blog-over'),
                'default' => esc_html__('Learn More', 'blog-over'),
            ),
            'btn_link' => array(
                'type' => 'text',
                'label' => esc_html__('Button Link', 'blog-over'),
                'default' => '#',
            ),
            'btn_alignment' => array(
                'type' => 'radio-buttonset',
                'label' => esc_html__('Button Alignment', 'blog-over'),
                'default' => 'center',
                'choices' => array(
                    'left' => esc_html__('Left', 'blog-over'),
                    'center' => esc_html__('Center', 'blog-over'),
                    'right' => esc_html__('Right', 'blog-over'),
                ),
            ),
            'banner_max_width' => array(
                'type' => 'number',
                'label' => esc_html__('Max Width (%)', 'blog-over'),
                'default' => 100,
                'choices' => array('min' => 30, 'max' => 100, 'step' => 1),
            ),
            'banner_height' => array(
                'type' => 'number',
                'label' => esc_html__('Height (px, 0 = auto)', 'blog-over'),
                'default' => 0,
                'choices' => array('min' => 0, 'max' => 600, 'step' => 5),
            ),
        ),
        'active_callback' => array(
            array('setting' => 'blog_over_ad_banner_enable', 'operator' => '==', 'value' => true),
        ),
    ));

}
