<x-app-layout>
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1 class="h3 fw-bold mb-0">
                    <i class="bi bi-bell me-2 text-primary"></i>Notifications
                </h1>
                @if ($notifications->where('read_at', null)->count() > 0)
                    <form action="{{ route('notifications.mark-all-read') }}" method="POST">
                        @csrf
                        <button type="submit" class="btn btn-outline-primary btn-sm">
                            <i class="bi bi-check-all me-1"></i>Mark All As Read
                        </button>
                    </form>
                @endif
            </div>

            @forelse ($notifications as $notification)
                <div class="card shadow-sm border-0 mb-3 {{ $notification->read_at ? '' : 'border-start border-primary border-3' }}">
                    <div class="card-body p-4">
                        <div class="d-flex align-items-start justify-content-between gap-3">
                            <div class="flex-grow-1">
                                <div class="d-flex align-items-center gap-2 mb-1">
                                    @if (!$notification->read_at)
                                        <span class="badge bg-primary rounded-pill" style="width:8px;height:8px;padding:0"></span>
                                    @endif
                                    <h6 class="fw-semibold mb-0">
                                        {{ $notification->token?->title ?? 'Notification' }}
                                    </h6>
                                </div>
                                <p class="text-secondary mb-1 small">{{ $notification->message }}</p>
                                <p class="text-muted mb-0" style="font-size:.75rem">{{ $notification->created_at->diffForHumans() }}</p>
                            </div>
                            <div class="d-flex align-items-center gap-2 flex-shrink-0">
                                @if ($notification->token)
                                    <a href="{{ route('tokens.show', $notification->token) }}"
                                       class="btn btn-outline-primary btn-sm">View</a>
                                @endif
                                @if (!$notification->read_at)
                                    <form action="{{ route('notifications.mark-read', $notification) }}" method="POST">
                                        @csrf
                                        <button type="submit" class="btn btn-outline-secondary btn-sm" title="Mark as read">
                                            <i class="bi bi-check2"></i>
                                        </button>
                                    </form>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
            @empty
                <div class="card shadow-sm border-0">
                    <div class="card-body text-center py-5">
                        <i class="bi bi-bell-slash fs-1 text-muted mb-3 d-block"></i>
                        <p class="text-muted mb-0">No notifications yet</p>
                    </div>
                </div>
            @endforelse
        </div>
    </div>
</x-app-layout>