<!DOCTYPE html>
<html lang="id">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard Kurir - Glow Beauty</title>

    <!-- Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>

    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">

    <style>
        * {
            font-family: 'Poppins', 'Inter', sans-serif;
        }

        .nav-link {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 14px;
            border-radius: 10px;
            font-size: 0.875rem;
            font-weight: 500;
            transition: all 0.2s ease;
        }

        .nav-link:hover {
            background-color: #fef2f8;
            color: #ec489a;
        }

        .active-nav {
            background-color: #fef2f8;
            color: #ec489a;
            border: 1px solid #fbcfe8;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 14px;
            border-radius: 10px;
            font-size: 0.875rem;
            font-weight: 600;
        }

        .stat-card {
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(244, 114, 182, 0.2);
        }

        .assignment-card {
            transition: all 0.3s ease;
        }

        .assignment-card:hover {
            transform: translateX(5px);
            border-left-width: 8px;
        }

        .badge-status {
            padding: 4px 12px;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 600;
            display: inline-flex;
            align-items: center;
            gap: 4px;
        }

        .badge-ditugaskan {
            background-color: #dbeafe;
            color: #1e40af;
        }

        .badge-dijemput {
            background-color: #fef3c7;
            color: #b45309;
        }

        .badge-diantar {
            background-color: #e0f2fe;
            color: #0369a1;
        }

        .badge-selesai {
            background-color: #d1fae5;
            color: #065f46;
        }

        .action-btn {
            transition: all 0.2s ease;
        }

        .action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        
        .bg-gradient-pink {
            background: linear-gradient(135deg, #fdf2f8 0%, #fff1f3 100%);
        }
        
        .border-pink-light {
            border-color: #fbcfe8;
        }
    </style>
</head>

<body class="bg-gradient-pink min-h-screen">

    <!-- NAVBAR -->
    <nav class="bg-white/95 backdrop-blur-md border-b border-pink-light shadow-sm sticky top-0 z-50 w-full">
        <div class="px-4 sm:px-6 lg:px-8 py-3">
            <div class="flex flex-col md:flex-row md:items-center md:justify-between">

                <div class="flex items-center gap-3 mb-3 md:mb-0">
                    <div
                        class="w-10 h-10 bg-gradient-to-br from-pink-400 to-pink-500 rounded-lg flex items-center justify-center shadow-md">
                        <span class="text-white font-bold text-lg">✨</span>
                    </div>
                    <div>
                        <h1 class="font-bold text-lg text-gray-800">Glow Beauty</h1>
                        <p class="text-xs text-pink-400">Kurir Dashboard Skincare</p>
                    </div>
                </div>

                <div class="flex flex-wrap items-center gap-1">
                    <a href="{{ route('kurir.dashboard') }}"
                        class="flex items-center gap-2 px-4 py-2 rounded-lg active-nav">
                        <i class="fas fa-tachometer-alt"></i> Dashboard
                    </a>

                    <a href="{{ route('kurir.history') }}"
                        class="flex items-center gap-2 px-4 py-2 rounded-lg text-gray-600 hover:bg-pink-50 hover:text-pink-600 transition">
                        <i class="fas fa-history"></i> Riwayat
                    </a>
                </div>

                <!-- USER DROPDOWN -->
                <div class="relative" id="userDropdown">
                    <button onclick="toggleDropdown()"
                        class="flex items-center gap-3 px-3 py-2 hover:bg-pink-50 rounded-xl transition-all duration-200 border border-transparent hover:border-pink-200 group">
                        <div
                            class="w-9 h-9 bg-gradient-to-br from-pink-400 to-pink-500 rounded-full flex items-center justify-center text-white font-semibold shadow-md">
                            {{ Auth::user()->inisial ?? substr(Auth::user()->name, 0, 1) }}
                        </div>
                        <div class="hidden md:block text-left">
                            <p class="text-sm font-medium text-gray-700 group-hover:text-pink-600">
                                {{ Auth::user()->name }}</p>
                            <p class="text-xs text-gray-500">
                                <i class="fas fa-truck mr-1 text-pink-500"></i> Kurir
                            </p>
                        </div>
                        <i class="fas fa-chevron-down text-sm text-gray-400 group-hover:text-pink-600 transition-transform duration-200"
                            id="dropdownIcon"></i>
                    </button>

                    <div id="dropdownMenu"
                        class="hidden absolute right-0 mt-2 w-64 bg-white rounded-xl shadow-xl border border-gray-100 py-2 z-50">
                        <div class="px-4 py-4 border-b border-gray-100">
                            <div class="flex items-center gap-3">
                                <div
                                    class="w-12 h-12 bg-gradient-to-br from-pink-400 to-pink-500 rounded-full flex items-center justify-center text-white font-bold text-xl shadow-md">
                                    {{ Auth::user()->inisial ?? substr(Auth::user()->name, 0, 1) }}
                                </div>
                                <div>
                                    <p class="font-semibold text-gray-800">{{ Auth::user()->name }}</p>
                                    <p class="text-sm text-gray-500">{{ Auth::user()->email }}</p>
                                    <span
                                        class="inline-block mt-1 px-2 py-0.5 bg-pink-100 text-pink-600 rounded-full text-xs font-medium">
                                        <i class="fas fa-truck mr-1"></i> Kurir
                                    </span>
                                </div>
                            </div>
                        </div>

                        <a href="{{ route('profile.edit') }}"
                            class="flex items-center gap-3 px-4 py-3 hover:bg-pink-50 text-gray-700 transition group">
                            <div
                                class="w-8 h-8 bg-gray-100 rounded-lg flex items-center justify-center group-hover:bg-pink-100">
                                <i class="fas fa-user text-gray-500 group-hover:text-pink-600"></i>
                            </div>
                            <div>
                                <p class="font-medium">Profil Saya</p>
                                <p class="text-xs text-gray-500">Lihat dan edit profil</p>
                            </div>
                        </a>

                        <div class="border-t border-gray-100 mt-1 pt-1">
                            <form method="POST" action="{{ route('logout') }}">
                                @csrf
                                <button type="submit"
                                    class="w-full flex items-center gap-3 px-4 py-3 hover:bg-red-50 text-red-600 transition group">
                                    <div
                                        class="w-8 h-8 bg-red-50 rounded-lg flex items-center justify-center group-hover:bg-red-100">
                                        <i class="fas fa-sign-out-alt text-red-500"></i>
                                    </div>
                                    <div class="text-left">
                                        <p class="font-medium">Keluar</p>
                                        <p class="text-xs text-red-400">Akhiri sesi</p>
                                    </div>
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </nav>

    <!-- MAIN CONTENT -->
    <div class="w-full px-4 sm:px-6 lg:px-8 py-6">

        <!-- HEADER SECTION -->
        <div
            class="relative overflow-hidden bg-gradient-to-r from-pink-400 to-pink-500 rounded-xl px-8 py-5 mb-6 shadow-md">
            <div class="absolute right-32 top-1/2 -translate-y-1/2 opacity-10 flex gap-6">
                <i class="fas fa-truck text-white text-7xl"></i>
                <i class="fas fa-box-open text-white text-8xl"></i>
                <i class="fas fa-spa text-white text-6xl"></i>
            </div>
            <div class="relative z-10 flex items-center justify-between">
                <div class="flex items-center gap-4">
                    <div class="bg-white/20 p-3 rounded-xl">
                        <i class="fas fa-tachometer-alt text-white text-xl"></i>
                    </div>
                    <div>
                        <h2 class="text-3xl font-bold text-white">Dashboard Kurir</h2>
                        <p class="text-pink-100 text-lg">Kelola pengiriman pesanan skincare dengan mudah</p>
                    </div>
                </div>
                <span class="bg-white/20 backdrop-blur-sm px-4 py-2 rounded-lg text-white text-sm">
                    <i class="fas fa-calendar-alt mr-2"></i> {{ now()->format('d M Y') }}
                </span>
            </div>
        </div>

        <!-- NOTIFICATION -->
        @if(session('success'))
            <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-6 rounded-lg shadow-sm w-full"
                role="alert">
                <div class="flex items-center">
                    <i class="fas fa-check-circle mr-2"></i>
                    <p>{{ session('success') }}</p>
                </div>
            </div>
        @endif

        @if(session('error'))
            <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-6 rounded-lg shadow-sm w-full"
                role="alert">
                <div class="flex items-center">
                    <i class="fas fa-exclamation-circle mr-2"></i>
                    <p>{{ session('error') }}</p>
                </div>
            </div>
        @endif

        <!-- STATISTICS CARDS -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
            <!-- Ditugaskan -->
            <div class="bg-white rounded-xl shadow-sm p-5 border-l-4 border-blue-500 stat-card">
                <div class="flex justify-between items-center">
                    <div>
                        <p class="text-sm text-gray-500 mb-1">Ditugaskan</p>
                        <p class="text-3xl font-bold text-gray-800">{{ $statistik['ditugaskan'] }}</p>
                    </div>
                    <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-clipboard-list text-blue-600 text-xl"></i>
                    </div>
                </div>
                <p class="text-xs text-gray-400 mt-2">Menunggu diambil</p>
            </div>

            <!-- Dijemput -->
            <div class="bg-white rounded-xl shadow-sm p-5 border-l-4 border-yellow-500 stat-card">
                <div class="flex justify-between items-center">
                    <div>
                        <p class="text-sm text-gray-500 mb-1">Dijemput</p>
                        <p class="text-3xl font-bold text-gray-800">{{ $statistik['dijemput'] }}</p>
                    </div>
                    <div class="w-12 h-12 bg-yellow-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-box text-yellow-600 text-xl"></i>
                    </div>
                </div>
                <p class="text-xs text-gray-400 mt-2">Sedang diproses</p>
            </div>

            <!-- Diantar -->
            <div class="bg-white rounded-xl shadow-sm p-5 border-l-4 border-blue-500 stat-card">
                <div class="flex justify-between items-center">
                    <div>
                        <p class="text-sm text-gray-500 mb-1">Diantar</p>
                        <p class="text-3xl font-bold text-gray-800">{{ $statistik['diantar'] }}</p>
                    </div>
                    <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-truck text-blue-600 text-xl"></i>
                    </div>
                </div>
                <p class="text-xs text-gray-400 mt-2">Dalam perjalanan</p>
            </div>

            <!-- Selesai -->
            <div class="bg-white rounded-xl shadow-sm p-5 border-l-4 border-green-500 stat-card">
                <div class="flex justify-between items-center">
                    <div>
                        <p class="text-sm text-gray-500 mb-1">Selesai</p>
                        <p class="text-3xl font-bold text-gray-800">{{ $statistik['selesai'] }}</p>
                    </div>
                    <div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-check-circle text-green-600 text-xl"></i>
                    </div>
                </div>
                <p class="text-xs text-gray-400 mt-2">Telah diterima</p>
            </div>
        </div>

        <!-- ACTIVITY TIMELINE -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8">
            <!-- Daftar Penugasan Aktif -->
            <div class="lg:col-span-2">
                <div class="bg-white rounded-xl shadow-sm border border-pink-100 overflow-hidden">
                    <div class="px-6 py-4 bg-gradient-to-r from-pink-50 to-white border-b border-pink-100">
                        <div class="flex items-center justify-between">
                            <div class="flex items-center gap-3">
                                <div class="w-8 h-8 bg-pink-100 rounded-lg flex items-center justify-center">
                                    <i class="fas fa-tasks text-pink-600"></i>
                                </div>
                                <h3 class="font-bold text-gray-800">Penugasan Aktif</h3>
                            </div>
                            <span class="text-xs bg-pink-100 text-pink-600 px-2 py-1 rounded-full">
                                {{ $penugasan->where('status', '!=', 'selesai')->count() }} aktif
                            </span>
                        </div>
                    </div>

                    <div class="divide-y divide-gray-100">
                        @forelse($penugasan->where('status', '!=', 'selesai') as $assignment)
                            <div class="assignment-card p-4 hover:bg-pink-50/50 transition-all border-l-4
                                @if($assignment->status == 'ditugaskan') border-blue-500
                                @elseif($assignment->status == 'dijemput') border-yellow-500
                                @elseif($assignment->status == 'diantar') border-blue-500
                                @endif">
                                <div class="flex items-start justify-between">
                                    <div class="flex-1">
                                        <div class="flex items-center gap-2 mb-2">
                                            <span
                                                class="font-semibold text-gray-800">{{ $assignment->pesanan->kode_pesanan }}</span>
                                            <span class="badge-status
                                                @if($assignment->status == 'ditugaskan') badge-ditugaskan
                                                @elseif($assignment->status == 'dijemput') badge-dijemput
                                                @elseif($assignment->status == 'diantar') badge-diantar
                                                @endif">
                                                <i class="fas {{ $assignment->status_icon }}"></i>
                                                {{ strtoupper($assignment->status) }}
                                            </span>
                                        </div>
                                        <p class="text-sm text-gray-600 mb-1">
                                            <i class="fas fa-user mr-2 text-gray-400"></i>
                                            {{ $assignment->pesanan->user->name }}
                                        </p>
                                        <p class="text-xs text-gray-500 line-clamp-2">
                                            <i class="fas fa-map-marker-alt mr-2 text-gray-400"></i>
                                            {{ $assignment->pesanan->alamat->alamat_lengkap ?? 'Alamat tidak tersedia' }}
                                        </p>
                                    </div>
                                    <a href="{{ route('kurir.show', $assignment->id) }}"
                                        class="action-btn px-4 py-2 bg-pink-500 text-white rounded-lg text-sm font-medium hover:bg-pink-600 ml-4 whitespace-nowrap">
                                        <i class="fas fa-eye mr-1"></i> Detail
                                    </a>
                                </div>
                            </div>
                        @empty
                            <div class="p-8 text-center">
                                <div
                                    class="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4">
                                    <i class="fas fa-truck text-gray-400 text-2xl"></i>
                                </div>
                                <p class="text-gray-500 font-medium">Tidak ada penugasan aktif</p>
                                <p class="text-sm text-gray-400 mt-1">Semua pesanan skincare sudah selesai</p>
                            </div>
                        @endforelse
                    </div>

                    @if($penugasan->where('status', '!=', 'selesai')->count() > 0)
                        <div class="px-6 py-3 bg-gray-50 border-t border-gray-100">
                            <a href="#"
                                class="text-sm text-pink-600 hover:text-pink-700 flex items-center justify-center gap-1">
                                <i class="fas fa-sync-alt"></i> Refresh
                            </a>
                        </div>
                    @endif
                </div>
            </div>

            <!-- Aktivitas Terbaru -->
            <div class="lg:col-span-1">
                <div class="bg-white rounded-xl shadow-sm border border-pink-100 overflow-hidden h-full">
                    <div class="px-6 py-4 bg-gradient-to-r from-pink-50 to-white border-b border-pink-100">
                        <div class="flex items-center gap-3">
                            <div class="w-8 h-8 bg-pink-100 rounded-lg flex items-center justify-center">
                                <i class="fas fa-history text-pink-600"></i>
                            </div>
                            <h3 class="font-bold text-gray-800">Aktivitas Terbaru</h3>
                        </div>
                    </div>

                    <div class="p-4 space-y-4">
                        @forelse($aktivitasTerbaru as $activity)
                            <div class="flex items-start gap-3 border-b border-gray-100 pb-3 last:border-0">
                                <div class="w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0
                                    @if($activity->status == 'ditugaskan') bg-blue-100
                                    @elseif($activity->status == 'dijemput') bg-yellow-100
                                    @elseif($activity->status == 'diantar') bg-blue-100
                                    @else bg-green-100
                                    @endif">
                                    <i class="fas {{ $activity->status_icon }}
                                        @if($activity->status == 'ditugaskan') text-blue-600
                                        @elseif($activity->status == 'dijemput') text-yellow-600
                                        @elseif($activity->status == 'diantar') text-blue-600
                                        @else text-green-600
                                        @endif text-xs">
                                    </i>
                                </div>
                                <div class="flex-1">
                                    <p class="text-sm font-medium text-gray-800">
                                        {{ $activity->pesanan->kode_pesanan }}
                                    </p>
                                    <p class="text-xs text-gray-500">
                                        {{ $activity->pesanan->user->name }}
                                    </p>
                                    <p class="text-xs text-gray-400 mt-1">
                                        <i class="far fa-clock mr-1"></i>
                                        {{ $activity->created_at->diffForHumans() }}
                                    </p>
                                </div>
                                <span class="badge-status text-xs
                                    @if($activity->status == 'ditugaskan') badge-ditugaskan
                                    @elseif($activity->status == 'dijemput') badge-dijemput
                                    @elseif($activity->status == 'diantar') badge-diantar
                                    @endif">
                                    {{ substr($activity->status, 0, 3) }}
                                </span>
                            </div>
                        @empty
                            <div class="text-center py-6">
                                <i class="fas fa-clock text-gray-300 text-3xl mb-2"></i>
                                <p class="text-gray-500 text-sm">Belum ada aktivitas</p>
                            </div>
                        @endforelse
                    </div>
                </div>
            </div>
        </div>

        <!-- QUICK ACTIONS -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div class="bg-gradient-to-br from-blue-50 to-blue-100 rounded-xl p-5 border border-blue-200">
                <div class="flex items-center gap-3 mb-3">
                    <div class="w-10 h-10 bg-blue-500 rounded-lg flex items-center justify-center">
                        <i class="fas fa-map-marked-alt text-white"></i>
                    </div>
                    <h4 class="font-semibold text-gray-800">Rute Pengiriman</h4>
                </div>
                <p class="text-sm text-gray-600 mb-3">Lihat rute pengiriman terdekat untuk hari ini</p>
                <a href="#" class="text-blue-600 text-sm font-medium hover:text-blue-700 flex items-center gap-1">
                    Lihat Rute <i class="fas fa-arrow-right"></i>
                </a>
            </div>

            <div class="bg-gradient-to-br from-green-50 to-green-100 rounded-xl p-5 border border-green-200">
                <div class="flex items-center gap-3 mb-3">
                    <div class="w-10 h-10 bg-green-500 rounded-lg flex items-center justify-center">
                        <i class="fas fa-check-circle text-white"></i>
                    </div>
                    <h4 class="font-semibold text-gray-800">Pengiriman Selesai</h4>
                </div>
                <p class="text-sm text-gray-600 mb-3">{{ $statistik['selesai'] }} pengiriman skincare telah selesai</p>
                <a href="{{ route('kurir.history') }}"
                    class="text-green-600 text-sm font-medium hover:text-green-700 flex items-center gap-1">
                    Lihat Riwayat <i class="fas fa-arrow-right"></i>
                </a>
            </div>

            <div class="bg-gradient-to-br from-purple-50 to-purple-100 rounded-xl p-5 border border-purple-200">
                <div class="flex items-center gap-3 mb-3">
                    <div class="w-10 h-10 bg-purple-500 rounded-lg flex items-center justify-center">
                        <i class="fas fa-chart-line text-white"></i>
                    </div>
                    <h4 class="font-semibold text-gray-800">Statistik Bulan Ini</h4>
                </div>
                <p class="text-sm text-gray-600 mb-3">Total {{ $statistik['selesai'] }} pengiriman skincare sukses</p>
                <a href="#" class="text-purple-600 text-sm font-medium hover:text-purple-700 flex items-center gap-1">
                    Lihat Statistik <i class="fas fa-arrow-right"></i>
                </a>
            </div>
        </div>
    </div>

    <script>
        function toggleDropdown() {
            const menu = document.getElementById('dropdownMenu');
            const icon = document.getElementById('dropdownIcon');
            menu.classList.toggle('hidden');
            icon.style.transform = menu.classList.contains('hidden') ? 'rotate(0deg)' : 'rotate(180deg)';
        }

        document.addEventListener('click', function (e) {
            const dropdown = document.getElementById('userDropdown');
            if (dropdown && !dropdown.contains(e.target)) {
                const menu = document.getElementById('dropdownMenu');
                const icon = document.getElementById('dropdownIcon');
                if (menu) menu.classList.add('hidden');
                if (icon) icon.style.transform = 'rotate(0deg)';
            }
        });

        // Auto-hide alerts
        setTimeout(() => {
            document.querySelectorAll('[role="alert"]').forEach(el => {
                el.style.transition = 'opacity 0.5s';
                el.style.opacity = '0';
                setTimeout(() => el.remove(), 500);
            });
        }, 5000);
    </script>
</body>

</html>