@extends('layouts.user')

@section('title', 'Notifications')

@section('content')
<div class="flex h-screen bg-gray-100">
    <!-- Sidebar -->
    @include('user.sidebar')

    <!-- Main Content -->
    <main class="flex-1 overflow-auto">
        <!-- Top Header -->
        <header class="bg-white shadow-sm sticky top-0 z-10">
            <div class="px-8 py-4 flex items-center justify-between">
                <div>
                    <h1 class="text-2xl font-bold text-gray-900">🔔 Notifications</h1>
                    <p class="text-sm text-gray-500">Stay updated on your bookings and account activity</p>
                </div>
                <a href="{{ route('home') }}" target="_blank" rel="noopener noreferrer"
                   class="inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg bg-white border border-gray-200 hover:border-emerald-300 hover:bg-emerald-50 text-gray-600 hover:text-emerald-700 transition-all">
                    <span>View Website</span>
                    <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="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
                    </svg>
                </a>
            </div>
        </header>

        <div class="p-8 max-w-4xl">

            @if (session('success'))
                <div class="mb-6 p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg">
                    {{ session('success') }}
                </div>
            @endif

            @if($notifications->count() > 0)
                <div class="bg-white rounded-2xl shadow border border-gray-200 divide-y divide-gray-100">
                    @foreach($notifications as $notification)
                        <div class="p-5 flex items-start justify-between hover:bg-gray-50 transition-colors">
                            <div class="flex-1 pr-4">
                                <div class="font-medium text-gray-900">
                                    {{ $notification->data['title'] ?? 'Notification' }}
                                </div>
                                <div class="text-sm text-gray-600 mt-1">
                                    {{ $notification->data['message'] ?? '' }}
                                </div>
                                <div class="text-xs text-gray-400 mt-2">
                                    {{ $notification->created_at->diffForHumans() }}
                                </div>
                            </div>

                            <div class="flex flex-col items-end gap-2 text-sm">
                                @if($notification->read_at)
                                    <span class="text-green-500 text-xs">Read</span>
                                @else
                                    <span class="text-yellow-500 text-xs font-medium">New</span>
                                @endif

                                <form action="{{ route('user.notifications.delete', $notification->id) }}" method="POST" onsubmit="return confirm('Delete this notification?')">
                                    @csrf
                                    <button type="submit" class="text-red-500 hover:text-red-700 text-xs">Delete</button>
                                </form>
                            </div>
                        </div>
                    @endforeach
                </div>

                <div class="mt-6">
                    {{ $notifications->links() }}
                </div>
            @else
                <div class="bg-white rounded-2xl shadow border border-gray-200 p-12 text-center">
                    <div class="text-6xl mb-4">🔔</div>
                    <h3 class="text-xl font-semibold text-gray-900 mb-2">No notifications yet</h3>
                    <p class="text-gray-600 max-w-sm mx-auto">
                        You'll see updates about your bookings, payments, and account activity here.
                    </p>
                </div>
            @endif

        </div>
    </main>
</div>
@endsection