<?php
/**
 * Announcement Bar Template (Free Version)
 *
 * @package Blog_Over
 */

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

if (!get_theme_mod('blog_over_announcement_show', false)) {
    return;
}

$bars = get_theme_mod('blog_over_announcement_bars', array());
if (empty($bars) || !is_array($bars)) {
    return;
}

// In the free version, limit to 1 bar
$bar = $bars[0];
if (empty($bar['text'])) {
    return;
}

$text       = isset($bar['text']) ? $bar['text'] : '';
$link       = isset($bar['link']) ? $bar['link'] : '';
$link_text  = isset($bar['link_text']) ? $bar['link_text'] : '';
$new_tab    = !empty($bar['new_tab']);

$bg_color    = get_theme_mod('blog_over_announcement_bg_color', '#3b82f6');
$text_color  = get_theme_mod('blog_over_announcement_text_color', '#ffffff');

// Free version hardcoded defaults (Pro unlocks these)
$dismissible = false;
$position    = 'above-header';

$wrapper_classes = array('blog-over-announcement-wrapper');
$wrapper_classes[] = 'blog-over-announcement-pos-' . esc_attr($position);

// In free theme, there's only 1 bar so auto-rotate is false
$data_attrs = 'data-auto-rotate="0" data-dismissible="0"';

$bar_classes = array('blog-over-announcement-bar', 'blog-over-announcement-layout-classic', 'blog-over-announcement-active');

$wrapper_style = sprintf('background-color: %s;', esc_attr($bg_color));
$bar_style = sprintf('color: %s;', esc_attr($text_color));
?>
<div class="<?php echo esc_attr(implode(' ', $wrapper_classes)); ?>" <?php echo $data_attrs; // phpcs:ignore ?> style="<?php echo esc_attr($wrapper_style); ?>">
    <div class="<?php echo esc_attr(implode(' ', $bar_classes)); ?>" style="<?php echo esc_attr($bar_style); ?>" data-index="0">
        <div class="blog-over-container">
            <div class="blog-over-announcement-inner blog-over-announcement-inner-classic">
                <span class="blog-over-announcement-text"><?php echo esc_html($text); ?></span>
                <?php if (!empty($link) && !empty($link_text)) : ?>
                    <a href="<?php echo esc_url($link); ?>"
                       class="blog-over-announcement-btn"
                       style="color: <?php echo esc_attr($text_color); ?>;"
                       <?php echo $new_tab ? 'target="_blank" rel="noopener noreferrer"' : ''; ?>>
                        <?php echo esc_html($link_text); ?>
                    </a>
                <?php endif; ?>
            </div>
        </div>
        <?php if ($dismissible) : ?>
            <button class="blog-over-announcement-close" aria-label="<?php esc_attr_e('Close announcement', 'blog-over'); ?>" style="color: <?php echo esc_attr($text_color); ?>;">
                &times;
            </button>
        <?php endif; ?>
    </div>
</div>
