<?php
/**
 * Category Showcase Section – Customizer Settings
 *
 * A visually rich section that displays categories as styled cards/tiles.
 * Completely different from all existing sections — no post loops, no sliders.
 * Purpose: Help users browse content by topic/interest at a glance.
 *
 * @package Blog_Over
 * @since   1.1.0
 */

// NOTE: Choice functions (blog_over_get_catshowcase_layout_choices, etc.) are
// defined in inc/pro-filters.php to keep everything in one canonical place.

// ─────────────────────────────────────────────────────────────────────────────
// Register Customizer Section
// ─────────────────────────────────────────────────────────────────────────────

Kirki::add_section( 'blog_over_catshowcase_section', array(
    'title'    => esc_html__( 'Category Showcase Section', 'blog-over' ),
    'panel'    => 'blog_over_frontpage_panel',
    'priority' => 55,
) );

// ═══════════════════════════════════════════
// A) GENERAL SETTINGS HEADING
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'custom',
    'settings' => 'blog_over_catshowcase_general_heading',
    'section'  => 'blog_over_catshowcase_section',
    'default'  => '<div style="background:linear-gradient(135deg,#eff6ff,#dbeafe);padding:10px 14px;border-radius:6px;border-left:3px solid #3b82f6;"><span style="font-size:13px;font-weight:600;color:#1e40af;text-transform:uppercase;letter-spacing:.5px;">' . esc_html__( 'General Settings', 'blog-over' ) . '</span></div>',
    'priority' => 1,
) );

// ═══════════════════════════════════════════
// B) Enable Toggle
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'toggle',
    'settings' => 'blog_over_catshowcase_enable',
    'label'    => esc_html__( 'Enable Category Showcase Section', 'blog-over' ),
    'description' => esc_html__( 'Display your blog categories as visual tiles — helps readers discover content by topic.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => false,
    'priority' => 5,
    'partial_refresh' => array(
        'blog_over_catshowcase_enable_refresh' => array(
            'selector'        => '.blog-over-catshowcase-wrapper',
            'render_callback' => 'blog_over_render_catshowcase_partial',
        ),
    ),
) );

// ═══════════════════════════════════════════
// C) Section Title
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'text',
    'settings' => 'blog_over_catshowcase_title',
    'label'    => esc_html__( 'Section Title', 'blog-over' ),
    'description' => esc_html__( 'Heading displayed above the category tiles.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => esc_html__( 'Explore Topics', 'blog-over' ),
    'priority' => 10,
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
    'partial_refresh' => array(
        'blog_over_catshowcase_title_refresh' => array(
            'selector'        => '.blog-over-catshowcase-heading',
            'render_callback' => function() {
                return esc_html( get_theme_mod( 'blog_over_catshowcase_title', __( 'Explore Topics', 'blog-over' ) ) );
            },
        ),
    ),
) );

// ═══════════════════════════════════════════
// D) Show On Pages
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'        => 'multicheck',
    'settings'    => 'blog_over_catshowcase_show_on',
    'label'       => esc_html__( 'Show On Pages', 'blog-over' ),
    'description' => esc_html__( 'Select which page types should display the Category Showcase.', 'blog-over' ),
    'section'     => 'blog_over_catshowcase_section',
    'default'     => array( 'home' ),
    'priority'    => 11,
    'choices'     => array(
        'home'    => esc_html__( 'Home Page', 'blog-over' ),
        'blog'    => esc_html__( 'Blog / Posts Page', 'blog-over' ),
        'archive' => esc_html__( 'Archive Pages', 'blog-over' ),
    ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// E) Section Width
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_catshowcase_section_width',
    'label'    => esc_html__( 'Section Width', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => 'boxed',
    'priority' => 12,
    'choices'  => array(
        'boxed'      => esc_html__( 'Boxed', 'blog-over' ),
        'full-width' => esc_html__( 'Full Width', 'blog-over' ),
    ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// CONTENT SETTINGS HEADING
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'custom',
    'settings' => 'blog_over_catshowcase_content_heading',
    'section'  => 'blog_over_catshowcase_section',
    'default'  => '<div style="background:linear-gradient(135deg,#eff6ff,#dbeafe);padding:10px 14px;border-radius:6px;border-left:3px solid #3b82f6;margin-top:20px;"><span style="font-size:13px;font-weight:600;color:#1e40af;text-transform:uppercase;letter-spacing:.5px;">' . esc_html__( 'Content Settings', 'blog-over' ) . '</span></div>',
    'priority' => 13,
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// F) Number of Categories to Show
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'slider',
    'settings' => 'blog_over_catshowcase_count',
    'label'    => esc_html__( 'Number of Categories', 'blog-over' ),
    'description' => esc_html__( 'How many category tiles to display. Categories are ordered by post count (highest first).', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => 6,
    'priority' => 14,
    'choices'  => array( 'min' => 2, 'max' => 12, 'step' => 1 ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// G) Show Post Count Badge
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'toggle',
    'settings' => 'blog_over_catshowcase_show_count',
    'label'    => esc_html__( 'Show Post Count Badge', 'blog-over' ),
    'description' => esc_html__( 'Display a small badge showing the number of posts in each category.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => true,
    'priority' => 15,
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// H) Show Category Description
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'toggle',
    'settings' => 'blog_over_catshowcase_show_description',
    'label'    => esc_html__( 'Show Category Description', 'blog-over' ),
    'description' => esc_html__( 'If a category has a description set in WordPress, display it on the tile.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => false,
    'priority' => 16,
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// DESIGN SETTINGS HEADING
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'custom',
    'settings' => 'blog_over_catshowcase_design_heading',
    'section'  => 'blog_over_catshowcase_section',
    'default'  => '<div style="background:linear-gradient(135deg,#eff6ff,#dbeafe);padding:10px 14px;border-radius:6px;border-left:3px solid #3b82f6;margin-top:20px;"><span style="font-size:13px;font-weight:600;color:#1e40af;text-transform:uppercase;letter-spacing:.5px;">' . esc_html__( 'Design & Style', 'blog-over' ) . '</span></div>',
    'priority' => 18,
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// I) Layout Style
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_catshowcase_layout',
    'label'    => esc_html__( 'Layout Style', 'blog-over' ),
    'description' => esc_html__( 'Equal Grid is free. Masonry, List, and Feature Grid layouts are available in Pro.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => 'grid',
    'priority' => 19,
    'choices'  => blog_over_get_catshowcase_layout_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// J) Card Style
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_catshowcase_card_style',
    'label'    => esc_html__( 'Card Style', 'blog-over' ),
    'description' => esc_html__( 'Image Overlay is included free. More card styles available in Pro.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => 'overlay',
    'priority' => 20,
    'choices'  => blog_over_get_catshowcase_card_style_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// K) Grid Columns
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_catshowcase_columns',
    'label'    => esc_html__( 'Grid Columns', 'blog-over' ),
    'description' => esc_html__( 'Number of category tiles per row on desktop.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => '3',
    'priority' => 21,
    'choices'  => array(
        '2' => esc_html__( '2', 'blog-over' ),
        '3' => esc_html__( '3', 'blog-over' ),
        '4' => esc_html__( '4', 'blog-over' ),
    ),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => function() {
        if ( ! get_theme_mod( 'blog_over_catshowcase_enable', false ) ) {
            return false;
        }
        $layout = get_theme_mod( 'blog_over_catshowcase_layout', 'grid' );
        return in_array( $layout, array( 'grid', 'masonry', 'feature_grid' ), true );
    },
) );

// ═══════════════════════════════════════════
// L) Card Height
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'slider',
    'settings' => 'blog_over_catshowcase_card_height',
    'label'    => esc_html__( 'Card Height (px)', 'blog-over' ),
    'description' => esc_html__( 'Height of each category card tile.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => 200,
    'priority' => 22,
    'choices'  => array( 'min' => 120, 'max' => 380, 'step' => 10 ),
    'output'   => array(
        array(
            'element'  => '.blog-over-catshowcase-wrapper',
            'property' => '--catshowcase-height',
            'units'    => 'px',
        ),
        array(
            'element'  => '.blog-over-catshowcase-card',
            'property' => 'height',
            'value_pattern' => 'var(--catshowcase-height, $)',
        ),
    ),
    'active_callback' => function() {
        if ( ! get_theme_mod( 'blog_over_catshowcase_enable', false ) ) {
            return false;
        }
        $layout = get_theme_mod( 'blog_over_catshowcase_layout', 'grid' );
        return $layout !== 'masonry';
    },
) );

// ═══════════════════════════════════════════
// M) Overlay Opacity
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'slider',
    'settings' => 'blog_over_catshowcase_overlay_opacity',
    'label'    => esc_html__( 'Image Overlay Darkness (%)', 'blog-over' ),
    'description' => esc_html__( 'How dark the gradient overlay appears on top of the category image. Higher = more readable text.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => 55,
    'priority' => 23,
    'choices'  => array( 'min' => 10, 'max' => 90, 'step' => 5 ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
    'partial_refresh' => array(
        'blog_over_catshowcase_overlay_opacity_refresh' => array(
            'selector'        => '.blog-over-catshowcase-wrapper',
            'render_callback' => 'blog_over_render_catshowcase_partial',
        ),
    ),
) );

// ═══════════════════════════════════════════
// N) Show Hover Zoom Effect
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'toggle',
    'settings' => 'blog_over_catshowcase_hover_zoom',
    'label'    => esc_html__( 'Enable Hover Zoom Effect', 'blog-over' ),
    'description' => esc_html__( 'Gently scale up the category image on mouse hover for a premium feel.', 'blog-over' ),
    'section'  => 'blog_over_catshowcase_section',
    'default'  => true,
    'priority' => 24,
    'active_callback' => array(
        array( 'setting' => 'blog_over_catshowcase_enable', 'operator' => '==', 'value' => true ),
    ),
) );
