<?php
/**
 * Extra helper functions
 */

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

/**
 * Get footer copyright text with variable replacement
 */
function wpbs_get_footer_text() {
    $text = get_theme_mod('wpbs_footer_text', '');
    
    if (empty($text)) {
        $text = '&copy; {year} {site}. All Rights Reserved.';
    }
    
    $text = str_replace('{year}', date('Y'), $text);
    $text = str_replace('{site}', get_bloginfo('name'), $text);
    
    return wp_kses_post($text);
}

/**
 * Get navbar classes based on Customizer settings
 */
function wpbs_navbar_classes() {
    $style = get_theme_mod('wpbs_navbar_style', 'light');
    $fixed = get_theme_mod('wpbs_navbar_fixed', false);
    
    $classes = ['navbar', 'navbar-expand-lg', 'wpbs-navbar'];
    
    switch ($style) {
        case 'dark':
            $classes[] = 'navbar-dark';
            $classes[] = 'bg-dark';
            break;
        case 'transparent':
            $classes[] = 'navbar-light';
            $classes[] = 'position-absolute';
            $classes[] = 'w-100';
            $classes[] = 'bg-transparent';
            break;
        default: // light
            $classes[] = 'navbar-light';
            break;
    }
    
    if ($fixed) {
        $classes[] = 'sticky-top';
    }
    
    return implode(' ', $classes);
}

/**
 * Get offcanvas classes based on navbar style
 */
function wpbs_offcanvas_classes() {
    $style = get_theme_mod('wpbs_navbar_style', 'light');
    
    $classes = ['offcanvas', 'offcanvas-end'];
    
    if ($style === 'dark') {
        $classes[] = 'text-bg-dark';
    }
    
    return implode(' ', $classes);
}

/**
 * Check if page is using Bootstrap Studio plugin
 */
function wpbs_is_studio_page() {
    if (!is_singular('page')) return false;
    return (bool) get_post_meta(get_the_ID(), '_wpbs_enabled', true);
}

/**
 * Custom excerpt length
 */
function wpbs_excerpt_length($length) {
    return 25;
}
add_filter('excerpt_length', 'wpbs_excerpt_length');

/**
 * Custom excerpt more text
 */
function wpbs_excerpt_more($more) {
    return '&hellip;';
}
add_filter('excerpt_more', 'wpbs_excerpt_more');
