@extends(auth()->user()->isEmployee() ? 'employee.layouts.app' : 'admin.layouts.app')

@section('title', 'Notifications')
@section('page-title', 'Notifications')

@section('content')
    <div class="space-y-6">
        <div class="rounded-3xl border border-gray-200 bg-white p-6 shadow-sm">
            <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
                <div>
                    <h2 class="text-2xl font-bold text-gray-900">All Notifications</h2>
                    <p class="mt-1 text-sm text-gray-500">Lead updates, blog review events, assignments, and workflow alerts all appear here.</p>
                </div>

                <form method="POST" action="{{ route('notifications.read-all') }}">
                    @csrf
                    <button type="submit" class="inline-flex items-center justify-center rounded-full bg-gray-900 px-5 py-2.5 text-sm font-semibold text-white transition hover:bg-black">
                        Mark all as read
                    </button>
                </form>
            </div>
        </div>

        <div class="space-y-4">
            @forelse($notifications as $notification)
                <div class="rounded-3xl border {{ $notification->read_at ? 'border-gray-200 bg-white' : 'border-blue-200 bg-blue-50/50' }} p-5 shadow-sm">
                    <div class="flex flex-col gap-4 md:flex-row md:items-start md:justify-between">
                        <div class="flex min-w-0 items-start gap-4">
                            <span class="mt-1 inline-flex h-3.5 w-3.5 flex-shrink-0 rounded-full {{ $notification->read_at ? 'bg-gray-300' : 'bg-blue-500 shadow-[0_0_0_8px_rgba(59,130,246,0.12)]' }}"></span>
                            <div class="min-w-0">
                                <div class="flex flex-wrap items-center gap-2">
                                    <h3 class="text-base font-semibold text-gray-900">{{ $notification->title }}</h3>
                                    @if(!$notification->read_at)
                                        <span class="inline-flex items-center rounded-full bg-blue-600 px-2.5 py-1 text-[11px] font-bold uppercase tracking-[0.18em] text-white">Unread</span>
                                    @endif
                                </div>
                                <p class="mt-2 text-sm leading-6 text-gray-600">{{ $notification->message }}</p>
                                <div class="mt-3 flex flex-wrap items-center gap-3 text-xs text-gray-400">
                                    <span>{{ $notification->created_at->format('d M Y, h:i A') }}</span>
                                    <span>{{ $notification->created_at->diffForHumans() }}</span>
                                    <span class="rounded-full bg-gray-100 px-2.5 py-1 font-medium text-gray-500">{{ str($notification->type)->replace('_', ' ')->title() }}</span>
                                </div>
                            </div>
                        </div>

                        <div class="flex flex-wrap items-center gap-2 md:justify-end">
                            @if(!$notification->read_at)
                                <form method="POST" action="{{ route('notifications.read', $notification) }}">
                                    @csrf
                                    <button type="submit" class="inline-flex items-center justify-center rounded-full border border-gray-200 px-4 py-2 text-sm font-semibold text-gray-700 transition hover:border-blue-200 hover:text-blue-600">
                                        Mark read
                                    </button>
                                </form>
                            @endif

                            @if($notification->action_url)
                                <form method="POST" action="{{ route('notifications.read', $notification) }}">
                                    @csrf
                                    <input type="hidden" name="redirect_to" value="{{ $notification->action_url }}">
                                    <button type="submit" class="inline-flex items-center justify-center rounded-full bg-blue-600 px-4 py-2 text-sm font-semibold text-white transition hover:bg-blue-700">
                                        Open
                                    </button>
                                </form>
                            @endif
                        </div>
                    </div>
                </div>
            @empty
                <div class="rounded-3xl border border-dashed border-gray-300 bg-white px-6 py-14 text-center shadow-sm">
                    <h3 class="text-lg font-semibold text-gray-900">No notifications yet</h3>
                    <p class="mt-2 text-sm text-gray-500">When leads are assigned, blog articles are reviewed, or statuses change, they will appear here.</p>
                </div>
            @endforelse
        </div>

        <div>
            {{ $notifications->links() }}
        </div>
    </div>
@endsection
