<?php
/**
 * Featured Links Customizer Section Settings
 *
 * @package Blog_Over
 */

// Create Featured Links Section
Kirki::add_section('blog_over_featured_section', array(
    'title' => esc_html__('Featured Links', 'blog-over'),
    'panel' => 'blog_over_frontpage_panel',
    'priority' => 30,
));

// ─────────────────────────────────────────────
// A) Enable Toggle
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'toggle',
    'settings' => 'blog_over_enable_featured_links',
    'label' => esc_html__('Enable Featured Links', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => false,
    'priority' => 10,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-all',
    ),
    'partial_refresh' => array(
        'blog_over_featured_links_refresh' => array(
            'selector' => '.blog-over-featured-links-wrapper .blog-over-container',
            'render_callback' => function () {
                get_template_part('template-parts/sections/featured');
            },
        ),
    ),
));

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

// ─────────────────────────────────────────────
// A2) Section Title
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'text',
    'settings' => 'blog_over_featured_section_title',
    'label' => esc_html__('Section Title', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => '',
    'priority' => 12,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
    ),
    'partial_refresh' => array(
        'blog_over_featured_section_title_refresh' => array(
            'selector' => '.blog-over-featured-section-header',
            'render_callback' => function () {
                $title = get_theme_mod('blog_over_featured_section_title', '');
                $desc = get_theme_mod('blog_over_featured_section_description', '');
                if ($title || $desc) {
                    echo '<div class="blog-over-featured-section-header">';
                    if ($title) {
                        echo '<h2 class="blog-over-featured-section-title">' . esc_html($title) . '</h2>';
                    }
                    if ($desc) {
                        echo '<p class="blog-over-featured-section-description">' . esc_html($desc) . '</p>';
                    }
                    echo '</div>';
                }
            },
        ),
    ),
));

// ─────────────────────────────────────────────
// A3) Section Description
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'text',
    'settings' => 'blog_over_featured_section_description',
    'label' => esc_html__('Section Description', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => '',
    'priority' => 13,
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// B) Enable On (Page Visibility)
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'multicheck',
    'settings' => 'blog_over_featured_enable_on',
    'label' => esc_html__('Show On Pages:', 'blog-over'),
    'description' => esc_html__('Choose pages to show Featured Items', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => array('home', 'posts_page'),
    'priority' => 10.5,
    'choices' => array(
        'home' => esc_html__('Home Page', 'blog-over'),
        'posts_page' => esc_html__('Blog / Posts Page', 'blog-over'),
        'archive' => esc_html__('Archive Page', 'blog-over'),
        'search' => esc_html__('Search Page', 'blog-over'),
        'post' => esc_html__('Single Post', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// C) Layout Style
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_featured_layout',
    'label' => esc_html__('Layout Style', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => 'grid',
    'priority' => 20,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-design',
    ),
    'choices' => blog_over_get_featured_layout_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// D) Repeater for Links (After Layout Style)
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type'     => 'repeater',
    'settings' => 'blog_over_featured_links_repeater',
    'label'    => esc_html__('Featured Items', 'blog-over'),
    'section'  => 'blog_over_featured_section',
    'priority' => 25,
    'row_label'   => array(
        'type'  => 'field',
        'value' => esc_html__('Featured Item', 'blog-over'),
        'field' => 'link_title',
    ),
    'button_label' => esc_html__('+ Add New Item', 'blog-over'),
    'default' => array(
        array(
            'link_title'    => esc_html__('Travel', 'blog-over'),
            'link_category' => esc_html__('Travel', 'blog-over'),
            'badge_color'   => '#10b981',
            'link_url'      => '#',
            'link_image'    => '',
            'btn_text'      => esc_html__('Read More', 'blog-over'),
            'open_new_tab'  => false,
        ),
        array(
            'link_title'    => esc_html__('Lifestyle', 'blog-over'),
            'link_category' => esc_html__('Lifestyle', 'blog-over'),
            'badge_color'   => '#f59e0b',
            'link_url'      => '#',
            'link_image'    => '',
            'btn_text'      => esc_html__('Read More', 'blog-over'),
            'open_new_tab'  => false,
        ),
        array(
            'link_title'    => esc_html__('Fashion', 'blog-over'),
            'link_category' => esc_html__('Fashion', 'blog-over'),
            'badge_color'   => '#ec4899',
            'link_url'      => '#',
            'link_image'    => '',
            'btn_text'      => esc_html__('Read More', 'blog-over'),
            'open_new_tab'  => false,
        ),
    ),
    'fields' => array(

        // ── Core fields (work for ALL layouts) ─────────────────

        'link_title' => array(
            'type'    => 'text',
            'label'   => esc_html__('Title', 'blog-over'),
            'default' => '',
        ),

        'link_url' => array(
            'type'    => 'text',
            'label'   => esc_html__('Link URL', 'blog-over'),
            'default' => '#',
        ),

        'link_image' => array(
            'type'    => 'image',
            'label'   => esc_html__('Image', 'blog-over'),
            'default' => '',
        ),

        'btn_text' => array(
            'type'    => 'text',
            'label'   => esc_html__('Button Text', 'blog-over'),
            'default' => esc_html__('Read More', 'blog-over'),
        ),

        'open_new_tab' => array(
            'type'    => 'checkbox',
            'label'   => esc_html__('Open in New Tab', 'blog-over'),
            'default' => false,
        ),

        // ── Category Badge (all layouts) ───────────────────────

        'link_category' => array(
            'type'    => 'text',
            'label'   => esc_html__('Category / Badge Text', 'blog-over'),
            'default' => '',
        ),

        'badge_color' => array(
            'type'    => 'color',
            'label'   => esc_html__('Badge Color', 'blog-over'),
            'default' => '#3b82f6',
        ),

    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// E) Design Heading (Dropdown Toggle)
// Registered in customizer-headings.php at priority 50
// All settings below priority 50 will be inside the dropdown
// ─────────────────────────────────────────────

// ─────────────────────────────────────────────
// F) Section Width (Inside Design Dropdown)
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_featured_section_width',
    'label' => esc_html__('Section Width', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => 'boxed',
    'priority' => 51,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-design',
    ),
    'choices' => array(
        'boxed' => esc_html__('Boxed', 'blog-over'),
        'full-width' => esc_html__('Full Width', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
    ),
));

// ─────────────────────────────────────────────
// G) Columns (Inside Design Dropdown)
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'radio-buttonset',
    'settings' => 'blog_over_featured_columns',
    'label' => esc_html__('Columns', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => '3',
    'priority' => 21,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-design',
    ),
    'choices' => array(
        '2' => esc_html__('2', 'blog-over'),
        '3' => esc_html__('3', 'blog-over'),
        '4' => esc_html__('4', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
        array('setting' => 'blog_over_featured_layout', 'operator' => '!=', 'value' => 'minimal'),
    ),
));

// ─────────────────────────────────────────────
// H) Border Hover Effect (Inside Design Dropdown)
// ─────────────────────────────────────────────
Kirki::add_field('Blog_Over_config', array(
    'type' => 'select',
    'settings' => 'blog_over_featured_border_effect',
    'label' => esc_html__('Border Hover Effect', 'blog-over'),
    'description' => esc_html__('Add an animated border effect when visitors hover over featured items.', 'blog-over'),
    'section' => 'blog_over_featured_section',
    'default' => 'none',
    'priority' => 53,
    'wrapper_attrs' => array(
        'class' => '{default_class} blog-over-tab-design',
    ),
    'choices' => array(
        'none' => esc_html__('None - No Effect', 'blog-over'),
        'metis' => esc_html__('Line Slide - Border slides from left', 'blog-over'),
        'io' => esc_html__('Double Line - Two lines appear', 'blog-over'),
        'thebe' => esc_html__('Grow Line - Line grows from center', 'blog-over'),
        'leda' => esc_html__('Reveal Slide - Border reveals sliding', 'blog-over'),
        'ersa' => esc_html__('Strike Through - Line strikes through', 'blog-over'),
        'elara' => esc_html__('Split Line - Line splits from middle', 'blog-over'),
        'dia' => esc_html__('Fade In - Lines fade in smoothly', 'blog-over'),
        'kale' => esc_html__('Wave Up - Wavy line moves up', 'blog-over'),
        'carpo' => esc_html__('Meet Middle - Lines meet in center', 'blog-over'),
        'helike' => esc_html__('Glitch - Glitchy border effect', 'blog-over'),
        'mneme' => esc_html__('Cover Up - Border covers item', 'blog-over'),
        'iocaste' => esc_html__('Curve Slide - Curved line slides', 'blog-over'),
        'herse' => esc_html__('Arc Draw - Arc shaped border', 'blog-over'),
        'carme' => esc_html__('Scribble - Hand-drawn style line', 'blog-over'),
        'eirene' => esc_html__('Bounce - Bouncy line animation', 'blog-over'),
    ),
    'active_callback' => array(
        array('setting' => 'blog_over_enable_featured_links', 'operator' => '==', 'value' => true),
    ),
));

