@extends('layouts.user')

@section('title', 'User Dashboard')

@section('content')
<div class="min-h-screen bg-gray-50">
    <!-- Header -->
    <header class="bg-white shadow-sm border-b border-gray-200">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between items-center py-4">
                <div class="flex items-center">
                    <h1 class="text-2xl font-bold text-gray-900">👤 User Dashboard</h1>
                </div>
                <div class="flex items-center gap-3">
                    <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>
                    <span class="text-sm text-gray-500">Welcome, {{ Auth::user()->name }}</span>
                    <a href="{{ route('logout') }}" class="text-red-600 hover:text-red-900 text-sm font-medium">Logout</a>
                </div>
            </div>
        </div>
    </header>

    <main class="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
        <!-- User Stats -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
            <div class="bg-white overflow-hidden shadow rounded-lg">
                <div class="p-5">
                    <div class="flex items-center">
                        <div class="flex-shrink-0 bg-blue-500 rounded-md p-3">
                            <svg class="h-6 w-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2v0a2 2 0 00-2-2H9"></path>
                            </svg>
                        </div>
                        <div class="ml-5 w-0 flex-1">
                            <dl>
                                <dt class="text-sm font-medium text-gray-500 truncate">Total Bookings</dt>
                                <dd class="text-lg font-medium text-gray-900">{{ $stats['total_bookings'] }}</dd>
                            </dl>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white overflow-hidden shadow rounded-lg">
                <div class="p-5">
                    <div class="flex items-center">
                        <div class="flex-shrink-0 bg-green-500 rounded-md p-3">
                            <svg class="h-6 w-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2z"></path>
                            </svg>
                        </div>
                        <div class="ml-5 w-0 flex-1">
                            <dl>
                                <dt class="text-sm font-medium text-gray-500 truncate">Confirmed Bookings</dt>
                                <dd class="text-lg font-medium text-gray-900">{{ $stats['confirmed_bookings'] }}</dd>
                            </dl>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white overflow-hidden shadow rounded-lg">
                <div class="p-5">
                    <div class="flex items-center">
                        <div class="flex-shrink-0 bg-yellow-500 rounded-md p-3">
                            <svg class="h-6 w-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3-2-3m0 8c1.11 0 2.08.402 2.599 1M12 8V7m0 1l-3 6m0 0l3-6m-6 3h6"></path>
                            </svg>
                        </div>
                        <div class="ml-5 w-0 flex-1">
                            <dl>
                                <dt class="text-sm font-medium text-gray-500 truncate">Total Spent</dt>
                                <dd class="text-lg font-medium text-gray-900">${{ number_format($stats['total_spent'], 2) }}</dd>
                            </dl>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Recent & Upcoming Bookings -->
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
            <!-- Recent Bookings -->
            <div class="bg-white shadow rounded-lg">
                <div class="px-4 py-5 sm:p-6">
                    <h3 class="text-lg leading-6 font-medium text-gray-900 mb-4">📋 Recent Bookings</h3>
                    <div class="flow-root">
                        <ul class="-my-5 divide-y divide-gray-200">
                            @forelse ($recentBookings as $booking)
                                <li class="py-4">
                                    <div class="flex items-center space-x-4">
                                        <div class="flex-shrink-0">
                                            <img src="{{ $booking->package->main_image ?? asset('images/package-placeholder.jpg') }}" 
                                                 class="h-10 w-10 rounded-full object-cover" alt="{{ $booking->package->title }}">
                                        </div>
                                        <div class="flex-1 min-w-0">
                                            <p class="text-sm font-medium text-gray-900 truncate">{{ $booking->package->title }}</p>
                                            <p class="text-sm text-gray-500">{{ $booking->booking_reference }} • {{ $booking->created_at->format('M d, Y') }}</p>
                                        </div>
                                        <div>
                                            <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full
                                                {{ $booking->status === 'confirmed' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800' }}">
                                                {{ ucfirst($booking->status) }}
                                            </span>
                                        </div>
                                    </div>
                                </li>
                            @empty
                                <li class="py-4 text-center text-gray-500">
                                    No recent bookings
                                </li>
                            @endforelse
                        </ul>
                    </div>
                    <div class="mt-4">
                        <a href="{{ route('user.bookings') }}" class="text-blue-600 hover:text-blue-900 text-sm font-medium">View All Bookings →</a>
                    </div>
                </div>
            </div>

            <!-- Upcoming Bookings -->
            <div class="bg-white shadow rounded-lg">
                <div class="px-4 py-5 sm:p-6">
                    <h3 class="text-lg leading-6 font-medium text-gray-900 mb-4">📅 Upcoming Trips</h3>
                    <div class="flow-root">
                        <ul class="-my-5 divide-y divide-gray-200">
                            @forelse ($upcomingBookings as $booking)
                                <li class="py-4">
                                    <div class="flex items-center space-x-4">
                                        <div class="flex-shrink-0">
                                            <div class="h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center">
                                                <svg class="h-6 w-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
                                                </svg>
                                            </div>
                                        </div>
                                        <div class="flex-1 min-w-0">
                                            <p class="text-sm font-medium text-gray-900 truncate">{{ $booking->package->title }}</p>
                                            <p class="text-sm text-gray-500">{{ $booking->travel_date->format('M d, Y') }} • {{ $booking->number_of_people }} people</p>
                                        </div>
                                    </div>
                                </li>
                            @empty
                                <li class="py-4 text-center text-gray-500">
                                    No upcoming trips
                                </li>
                            @endforelse
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <!-- Favorite Packages -->
        <div class="bg-white shadow rounded-lg mb-8">
            <div class="px-4 py-5 sm:p-6">
                <div class="flex justify-between items-center mb-4">
                    <h3 class="text-lg leading-6 font-medium text-gray-900">❤️ Favorite Packages</h3>
                    <a href="{{ route('user.favorites') }}" class="text-blue-600 hover:text-blue-900 text-sm font-medium">View All →</a>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                    @forelse ($favoritePackages as $package)
                        <div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition-shadow">
                            <img src="{{ $package->main_image ?? asset('images/package-placeholder.jpg') }}" 
                                 class="w-full h-32 object-cover rounded-lg mb-3" alt="{{ $package->title }}">
                            <h4 class="text-sm font-medium text-gray-900 mb-1">{{ $package->title }}</h4>
                            <p class="text-sm text-gray-500 mb-2">{{ $package->destination }}</p>
                            <div class="flex justify-between items-center">
                                <span class="text-sm font-bold text-green-600">{{ $package->formatted_price }}</span>
                                <span class="text-xs text-gray-500">{{ $package->bookings_count }} bookings</span>
                            </div>
                        </div>
                    @empty
                        <div class="col-span-full text-center text-gray-500 py-8">
                            <p class="mb-2">No favorite packages yet</p>
                            <a href="{{ route('packages.index') }}" class="text-blue-600 hover:text-blue-900 text-sm font-medium">Browse Packages</a>
                        </div>
                    @endforelse
                </div>
            </div>
        </div>

        <!-- Quick Actions -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
            <a href="{{ route('packages.index') }}" class="bg-white shadow rounded-lg p-6 hover:shadow-lg transition-shadow">
                <div class="text-center">
                    <div class="text-3xl mb-2">🔍</div>
                    <h3 class="text-lg font-medium text-gray-900">Browse Packages</h3>
                    <p class="text-sm text-gray-500 mt-1">Discover amazing destinations</p>
                </div>
            </a>

            <a href="{{ route('user.bookings') }}" class="bg-white shadow rounded-lg p-6 hover:shadow-lg transition-shadow">
                <div class="text-center">
                    <div class="text-3xl mb-2">📋</div>
                    <h3 class="text-lg font-medium text-gray-900">My Bookings</h3>
                    <p class="text-sm text-gray-500 mt-1">View booking history</p>
                </div>
            </a>

            <a href="{{ route('user.profile') }}" class="bg-white shadow rounded-lg p-6 hover:shadow-lg transition-shadow">
                <div class="text-center">
                    <div class="text-3xl mb-2">⚙️</div>
                    <h3 class="text-lg font-medium text-gray-900">Profile Settings</h3>
                    <p class="text-sm text-gray-500 mt-1">Update your information</p>
                </div>
            </a>
        </div>
    </main>
</div>
@endsection
