@extends('layouts.app')

@section('title', 'Notifications')

@section('content')
<div class="max-w-4xl mx-auto space-y-6">

    <!-- Header -->
    <div class="flex items-center justify-between pb-4 border-b border-slate-200">
        <div>
            <h1 class="text-2xl font-bold text-slate-900 tracking-tight">Notifications</h1>
            <p class="text-xs text-slate-500 mt-1">View all activity notifications and system alerts.</p>
        </div>
        <form method="POST" action="{{ route('notifications.read-all') }}">
            @csrf
            <button type="submit" class="px-3 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 font-semibold rounded text-xs">
                Mark All as Read
            </button>
        </form>
    </div>

    <!-- Notification List -->
    <div class="bg-white rounded-lg border border-slate-200 shadow-sm overflow-hidden divide-y divide-slate-100">
        @forelse($notifications as $n)
            <div class="p-4 hover:bg-slate-50 transition-colors flex items-start justify-between {{ is_null($n->read_at) ? 'bg-blue-50/30' : '' }}">
                <div class="space-y-1 pr-4">
                    <div class="flex items-center space-x-2">
                        <span class="font-bold text-sm text-slate-900">{{ $n->data['title'] ?? 'Notification' }}</span>
                        @if(is_null($n->read_at))
                            <span class="px-2 py-0.5 text-[10px] font-bold uppercase bg-blue-600 text-white rounded-full">Unread</span>
                        @endif
                    </div>
                    <p class="text-xs text-slate-600">{{ $n->data['message'] ?? '' }}</p>
                    <div class="text-[11px] text-slate-400">{{ $n->created_at->diffForHumans() }} ({{ $n->created_at->format('d M Y, g:i A') }})</div>
                </div>

                <div class="flex items-center space-x-2 flex-shrink-0">
                    @if(isset($n->data['url']))
                        <a href="{{ $n->data['url'] }}" class="px-3 py-1.5 bg-harcourts-blue text-white font-bold text-xs rounded hover:bg-blue-800">
                            View
                        </a>
                    @endif
                    @if(is_null($n->read_at))
                        <form method="POST" action="{{ route('notifications.read', $n->id) }}">
                            @csrf
                            <button type="submit" class="px-2.5 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-600 text-xs rounded font-medium">
                                Mark Read
                            </button>
                        </form>
                    @endif
                </div>
            </div>
        @empty
            <div class="p-8 text-center text-slate-400 text-xs">
                You have no notifications.
            </div>
        @endforelse
    </div>

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

</div>
@endsection
