<?php
/**
 * Blog Over Customizer Choice Functions & Sanitize Helpers
 *
 * All customizer select/radio choices are defined here.
 * Free theme contains only functional options — no locked or labelled Pro items.
 * The Pro plugin adds its own options via filters.
 *
 * @package Blog_Over
 * @since 2.0.0
 */

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

// =============================================
// PRO ACTIVE CHECK
// =============================================

/**
 * Check if Blog Over Pro plugin is active.
 *
 * @return bool True if Pro plugin is active.
 */
function blog_over_is_pro_active()
{
    return defined('BLOG_OVER_PRO_VERSION');
}

// =============================================
// BLOG STYLE CHOICES
// =============================================

/**
 * Blog style choices.
 *
 * Free theme provides default, modern-cards, and editorial.
 * Pro plugin adds masonry, magazine-grid, etc. via filter.
 *
 * @return array Choices.
 */
function blog_over_get_blog_style_choices()
{
    return apply_filters('blog_over_blog_style_choices', array(
        'default'      => __('Default (Classic List)', 'blog-over'),
        'modern-cards' => __('Modern Card Grid', 'blog-over'),
        'editorial'    => __('Editorial List', 'blog-over'),
    ));
}

// =============================================
// SANITIZE CALLBACKS
// =============================================

/**
 * Sanitize select and radio controls.
 *
 * Validates input against the control's choices list.
 * Falls back to default if value is not in choices.
 *
 * @param string              $input   The value to sanitize.
 * @param WP_Customize_Setting $setting The setting instance.
 * @return string Sanitized value.
 */
function blog_over_sanitize_select($input, $setting)
{
    $input = sanitize_text_field($input);

    $control = $setting->manager->get_control($setting->id);
    if ($control && isset($control->choices) && !array_key_exists($input, $control->choices)) {
        return $setting->default;
    }

    return $input;
}

/**
 * Sanitize featured links repeater.
 *
 * @param mixed $input The repeater value.
 * @return array Sanitized array.
 */
function blog_over_sanitize_featured_links_repeater($input)
{
    if (!is_array($input)) {
        $input = json_decode($input, true);
    }

    if (!is_array($input)) {
        return array();
    }

    $sanitized = array();
    foreach ($input as $item) {
        $sanitized[] = array(
            'link_title'    => isset($item['link_title'])    ? sanitize_text_field($item['link_title'])    : '',
            'link_url'      => isset($item['link_url'])      ? esc_url_raw($item['link_url'])              : '#',
            'link_image'    => isset($item['link_image'])    ? esc_url_raw($item['link_image'])            : '',
            'btn_text'      => isset($item['btn_text'])      ? sanitize_text_field($item['btn_text'])      : '',
            'open_new_tab'  => isset($item['open_new_tab'])  ? (bool) $item['open_new_tab']               : false,
            'link_category' => isset($item['link_category']) ? sanitize_text_field($item['link_category']) : '',
            'badge_color'   => isset($item['badge_color'])   ? sanitize_hex_color($item['badge_color'])    : '#3b82f6',
        );
    }

    return $sanitized;
}

// =============================================
// HEADER PANEL
// =============================================

/**
 * Search style choices.
 *
 * @return array Choices.
 */
function blog_over_get_search_style_choices()
{
    return apply_filters('blog_over_search_style_choices', array(
        'popup' => __('Popup Modal Search', 'blog-over'),
    ));
}

/**
 * Menu layout choices.
 *
 * @return array Choices.
 */
function blog_over_get_menu_layout_choices()
{
    return apply_filters('blog_over_menu_layout_choices', array(
        'layout-1' => __('Layout 1 (Classic)', 'blog-over'),
    ));
}

// =============================================
// FRONT PAGE – TICKER
// =============================================

/**
 * Ticker content source choices.
 *
 * @return array Choices.
 */
function blog_over_get_ticker_source_choices()
{
    return apply_filters('blog_over_ticker_source_choices', array(
        'latest' => __('Latest Posts', 'blog-over'),
    ));
}

/**
 * Ticker scroll direction choices.
 *
 * @return array Choices.
 */
function blog_over_get_ticker_direction_choices()
{
    return apply_filters('blog_over_ticker_direction_choices', array(
        'left' => __('← Left', 'blog-over'),
    ));
}

/**
 * Ticker layout style choices.
 *
 * Free theme provides only classic.
 * Pro plugin adds minimal, pill, gradient, vertical-flip, spotlight via filter.
 *
 * @return array Choices.
 */
function blog_over_get_ticker_layout_choices()
{
    return apply_filters('blog_over_ticker_layout_choices', array(
        'classic' => __('Classic', 'blog-over'),
    ));
}

// =============================================
// HERO SECTION
// =============================================

/**
 * Hero slide effect choices.
 *
 * @return array Choices.
 */
function blog_over_get_hero_slide_effect_choices()
{
    return apply_filters('blog_over_hero_slide_effect_choices', array(
        'slide' => __('Slide', 'blog-over'),
    ));
}

// =============================================
// FEATURED LINKS
// =============================================

/**
 * Featured links layout choices.
 *
 * @return array Choices.
 */
function blog_over_get_featured_layout_choices()
{
    return apply_filters('blog_over_featured_layout_choices', array(
        'grid'    => __('Grid', 'blog-over'),
        'cards'   => __('Cards', 'blog-over'),
        'minimal' => __('Minimal', 'blog-over'),
    ));
}

// =============================================
// YOU MISSED SECTION
// =============================================

/**
 * You Missed layout choices.
 *
 * @return array Choices.
 */
function blog_over_get_you_missed_layout_choices()
{
    return apply_filters('blog_over_you_missed_layout_choices', array(
        'default' => __('Default', 'blog-over'),
    ));
}

/**
 * You Missed columns choices.
 *
 * @return array Choices.
 */
function blog_over_get_you_missed_columns_choices()
{
    return apply_filters('blog_over_you_missed_columns_choices', array(
        '4' => __('4', 'blog-over'),
    ));
}

// =============================================
// BLOG PANEL – AUTHOR BOX
// =============================================

/**
 * Author box style choices.
 *
 * @return array Choices.
 */
function blog_over_get_author_box_style_choices()
{
    return apply_filters('blog_over_author_box_style_choices', array(
        'modern' => __('Modern Card', 'blog-over'),
    ));
}

// =============================================
// BLOG PANEL – POST NAVIGATION
// =============================================

/**
 * Post navigation style choices.
 *
 * @return array Choices.
 */
function blog_over_get_postnav_style_choices()
{
    return apply_filters('blog_over_postnav_style_choices', array(
        'cards' => __('Card Style', 'blog-over'),
    ));
}

// =============================================
// BLOG PANEL – RELATED POSTS
// =============================================

/**
 * Related posts "based on" choices.
 *
 * @return array Choices.
 */
function blog_over_get_related_by_choices()
{
    return apply_filters('blog_over_related_by_choices', array(
        'category' => __('Current Post Category', 'blog-over'),
    ));
}

// =============================================
// SIDEBAR
// =============================================

/**
 * Widget title style choices.
 *
 * @return array Choices.
 */
function blog_over_get_widget_title_style_choices()
{
    return apply_filters('blog_over_widget_title_style_choices', array(
        'default' => __('Default', 'blog-over'),
    ));
}

// =============================================
// LOADER
// =============================================

/**
 * Loader animation style choices.
 *
 * @return array Choices.
 */
function blog_over_get_loader_style_choices()
{
    return apply_filters('blog_over_loader_style_choices', array(
        'spinner' => __('Rotating Rings', 'blog-over'),
    ));
}

/**
 * Loader background type choices.
 *
 * @return array Choices.
 */
function blog_over_get_loader_bg_type_choices()
{
    return apply_filters('blog_over_loader_bg_type_choices', array(
        'solid' => __('Solid', 'blog-over'),
        'gradient' => __('Gradient', 'blog-over'),
    ));
}

// =============================================
// GO TO TOP
// =============================================

/**
 * Go to top button icon choices.
 *
 * @return array Choices.
 */
function blog_over_get_gototop_icon_choices()
{
    return array(
        'fas fa-chevron-up' => '<i class="fas fa-chevron-up" style="font-size: 1.2rem;"></i>',
        'fas fa-arrow-up' => '<i class="fas fa-arrow-up" style="font-size: 1.2rem;"></i>',
        'fas fa-angle-up' => '<i class="fas fa-angle-up" style="font-size: 1.2rem;"></i>',
        'fas fa-caret-up' => '<i class="fas fa-caret-up" style="font-size: 1.2rem;"></i>',
        'fas fa-long-arrow-alt-up' => '<i class="fas fa-long-arrow-alt-up" style="font-size: 1.2rem;"></i>',
    );
}

// =============================================
// BLOG IMAGE RATIO
// =============================================

/**
 * Image ratio choices for blog cards.
 *
 * Free theme provides only default and full.
 * Pro plugin adds square, landscape, wide, portrait via filter.
 *
 * @return array Choices.
 */
function blog_over_get_image_ratio_choices()
{
    return apply_filters('blog_over_image_ratio_choices', array(
        'default' => __('Default', 'blog-over'),
        'full'    => __('Full Height', 'blog-over'),
    ));
}

/**
 * Get the CSS class for the current blog image ratio.
 *
 * Free theme always returns 'ratio-full'.
 * Pro plugin can override this via filter based on customizer setting.
 *
 * @return string CSS class name.
 */
function blog_over_get_image_ratio_class()
{
    return apply_filters('blog_over_image_ratio_class', 'ratio-full');
}

