@php
    $bar = $settings->announcement_bar ?? [];
    $enabled = $bar['enabled'] ?? false;
    $showUntil = $bar['show_until'] ?? null;
    $isExpired = $showUntil && now()->isAfter($showUntil);
@endphp

@if($enabled && !$isExpired)
    <div x-data="{ dismissed: localStorage.getItem('announcement_dismissed_{{ $academy->id }}') === 'true' }"
         x-show="!dismissed"
         x-transition:leave="transition ease-in duration-200"
         x-transition:leave-start="opacity-100 max-h-16"
         x-transition:leave-end="opacity-0 max-h-0"
         class="relative overflow-hidden"
         style="background-color: {{ $bar['bg_color'] ?? 'var(--site-accent)' }}; color: {{ $bar['text_color'] ?? '#ffffff' }}">
        <div class="max-w-7xl mx-auto px-4 py-2.5 flex items-center justify-center gap-3 text-sm font-medium">
            @if(!empty($bar['link']))
                <a href="{{ $bar['link'] }}" class="hover:underline">
                    {{ $bar['text'] ?? '' }}
                </a>
            @else
                <span>{{ $bar['text'] ?? '' }}</span>
            @endif

            @if($bar['dismissible'] ?? true)
                <button @click="dismissed = true; localStorage.setItem('announcement_dismissed_{{ $academy->id }}', 'true')"
                        class="absolute end-3 top-1/2 -translate-y-1/2 p-1 rounded-full hover:bg-white/20 transition-colors"
                        aria-label="إغلاق">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                </button>
            @endif
        </div>
    </div>
@endif
