@extends('layouts.app')

@section('page_title', 'Announcements')

@section('content')
    <div class="row">
        <div class="col-lg-12">
            <h4 class="fw-bold mb-4">Company Announcements</h4>

            @forelse($announcements as $anc)
                <div class="card border-0 shadow-sm mb-4 transition hover-shadow">
                    <div class="card-body p-4">
                        <div class="d-flex justify-content-between align-items-start mb-3">
                            <div class="d-flex align-items-center">
                                <div class="icon-box bg-primary-subtle text-primary rounded-3 me-3"
                                    style="width:45px; height:45px; display:flex; align-items:center; justify-content:center;">
                                    <i class="bi bi-megaphone fs-5"></i>
                                </div>
                                <div>
                                    <h5 class="fw-bold mb-0">
                                        @if ($anc->pinned)
                                            <i class="bi bi-pin-angle-fill text-danger me-1" title="Pinned"></i>
                                        @endif
                                        {{ $anc->title }}
                                    </h5>
                                    <span class="text-muted smaller">{{ $anc->created_at->format('M d, Y') }} —
                                        {{ $anc->created_at->diffForHumans() }}</span>
                                </div>
                            </div>
                            <a href="{{ route('announcements.show', $anc->id) }}"
                                class="btn btn-light btn-sm px-3 rounded-pill">View Details</a>
                        </div>
                        <p class="text-secondary">{{ Str::limit($anc->body, 250) }}</p>
                        @if ($anc->expires_at)
                            <div class="mt-3">
                                <span class="badge bg-warning-subtle text-warning small px-3 py-2">
                                    <i class="bi bi-clock-history me-1"></i> Expires:
                                    {{ $anc->expires_at->format('d M, Y') }}
                                </span>
                            </div>
                        @endif
                    </div>
                </div>
            @empty
                <div class="text-center py-5 bg-white rounded-4 shadow-sm">
                    <i class="bi bi-chat-dots fs-1 text-light"></i>
                    <p class="text-muted mt-3">No announcements found at the moment.</p>
                </div>
            @endforelse

        </div>
    </div>
@endsection
