@page
@model AsadiTools.Pages.Admin.AdminIndexModel
@{ ViewData["Title"] = "داشبورد"; Layout = "_AdminLayout"; }

<div class="p-6 md:p-8">
    <h1 class="text-2xl font-extrabold text-gray-900 mb-8">داشبورد</h1>

    <!-- Stats -->
    <div class="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-10">
        <div class="bg-white rounded-2xl border border-gray-100 p-5">
            <div class="w-10 h-10 rounded-xl bg-blue-100 text-blue-600 flex items-center justify-center text-xl mb-3">🛍️</div>
            <div class="text-2xl font-extrabold text-gray-900 mb-0.5">@Model.TotalOrders</div>
            <div class="text-sm text-gray-500">کل سفارش‌ها</div>
        </div>
        <div class="bg-white rounded-2xl border border-gray-100 p-5">
            <div class="w-10 h-10 rounded-xl bg-yellow-100 text-yellow-600 flex items-center justify-center text-xl mb-3">⏳</div>
            <div class="text-2xl font-extrabold text-gray-900 mb-0.5">@Model.PendingOrders</div>
            <div class="text-sm text-gray-500">در انتظار تأیید</div>
        </div>
        <div class="bg-white rounded-2xl border border-gray-100 p-5">
            <div class="w-10 h-10 rounded-xl bg-green-100 text-green-600 flex items-center justify-center text-xl mb-3">💰</div>
            <div class="text-lg font-extrabold text-gray-900 mb-0.5">@SiteData.FormatPrice(Model.TotalRevenue)</div>
            <div class="text-sm text-gray-500">درآمد کل</div>
        </div>
        <div class="bg-white rounded-2xl border border-gray-100 p-5">
            <div class="w-10 h-10 rounded-xl bg-purple-100 text-purple-600 flex items-center justify-center text-xl mb-3">📦</div>
            <div class="text-2xl font-extrabold text-gray-900 mb-0.5">@Model.ActiveProducts</div>
            <div class="text-sm text-gray-500">محصولات فعال</div>
        </div>
    </div>

    <!-- Recent orders -->
    <div class="bg-white rounded-2xl border border-gray-100 p-6">
        <div class="flex items-center justify-between mb-5">
            <h2 class="font-bold text-gray-900">آخرین سفارش‌ها</h2>
            <a href="/Admin/Orders" class="text-sm text-blue-600 hover:underline">مشاهده همه</a>
        </div>
        @if (!Model.RecentOrders.Any())
        {
            <p class="text-gray-400 text-sm text-center py-8">هنوز سفارشی ثبت نشده</p>
        }
        else
        {
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr class="border-b text-gray-500">
                            <th class="pb-3 text-right font-medium">شماره</th>
                            <th class="pb-3 text-right font-medium">مشتری</th>
                            <th class="pb-3 text-right font-medium">مبلغ</th>
                            <th class="pb-3 text-right font-medium">وضعیت</th>
                            <th class="pb-3 text-right font-medium">تاریخ</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-50">
                        @foreach (var o in Model.RecentOrders)
                        {
                            <tr class="hover:bg-gray-50">
                                <td class="py-3 font-mono text-xs text-gray-500">@o.OrderNumber</td>
                                <td class="py-3 font-medium">@o.CustomerName</td>
                                <td class="py-3 text-blue-700 font-bold">@SiteData.FormatPrice(o.Total)</td>
                                <td class="py-3">
                                    <span class="text-xs px-2 py-1 rounded-full font-medium @SiteData.OrderStatusBadge(o.Status)">
                                        @SiteData.OrderStatusLabel(o.Status)
                                    </span>
                                </td>
                                <td class="py-3 text-gray-400 text-xs">@SiteData.ToJalali(o.CreatedAt)</td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        }
    </div>
</div>
