import { useNavigate } from 'react-router-dom' import { Ic } from '@/icons' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Shimmer } from '@/components/shared/shimmer_frontend' import { useAuthStore } from '@/stores/auth' import { useTranslation } from '@/i18n' import { toFa } from '@/lib/utils' import { useLiveDashboard } from './hooks/useLiveDashboard' import type { DashboardTimeRange } from './services/dashboard-api' const TIME_RANGES: { id: DashboardTimeRange; labelKey: string }[] = [ { id: 'all', labelKey: 'dashboard.rangeAll' }, { id: '6m', labelKey: 'dashboard.range6m' }, { id: '30d', labelKey: 'dashboard.range30d' }, { id: '7d', labelKey: 'dashboard.range7d' }, { id: '24h', labelKey: 'dashboard.range24h' }, ] export default function DashboardHome() { const user = useAuthStore((s) => s.user) const { t } = useTranslation() const navigate = useNavigate() const { data, isLoading, isRefreshing, range, setRange, manualRefresh } = useLiveDashboard('all') if (isLoading && !data) { return (
{[1, 2, 3, 4].map((i) => (
))}
) } const d = data! return (
{/* ========================================================================= */} {/* 1. سربرگ اصلی داشبورد: طراحی مینیمال، وزین و بدون شلوغی بصری */} {/* ========================================================================= */}
{/* هاله نور پس‌زمینه لطیف */}

{t('dashboard.welcome', { name: user?.name || t('navigation.adminRole') })}

{t('dashboard.welcomeSubtitle')}

{/* گوشه کناری: دراپ‌داون بازه زمانی + دکمه رفرش */}
{/* ========================================================================= */} {/* 2. کارت‌های کلان شاخص‌های کلیدی عملکرد (4 Top KPI Cards - با ترنزیشن و هاله) */} {/* ========================================================================= */}
{/* ۱. کل کاربران و زائران */}
navigate('/users')} className="group relative flex flex-col justify-between overflow-hidden rounded-3xl border border-border-soft bg-card p-6 shadow-xs transition-all duration-300 hover:-translate-y-1 hover:border-primary/40 hover:shadow-lg cursor-pointer" >
{t('dashboard.totalUsersTitle')}
{Number(d.users.total).toLocaleString('en-US')} {t('dashboard.activeUsersBadge', { count: toFa(d.users.active) })}
↑ {t('dashboard.newUsersInRange', { count: toFa(d.users.newInRange) })} {d.users.growthRate} {t('dashboard.growthLabel')}
{/* نوار گرادینت پایین کارت */}
{/* ۲. مجموع واریزی‌های قطعی (درآمد کل) */}
navigate('/billing')} className="group relative flex flex-col justify-between overflow-hidden rounded-3xl border border-border-soft bg-card p-6 shadow-xs transition-all duration-300 hover:-translate-y-1 hover:border-emerald-500/40 hover:shadow-lg cursor-pointer" >
{t('dashboard.totalRevenueTitle')}
${d.billing.paidAmountUsd.toLocaleString('en-US')}
{t('dashboard.paidFactorsCount', { count: toFa(d.billing.paidCount) })} {t('dashboard.finalSettlement')}
{/* ۳. مطالبات در انتظار وصول */}
navigate('/billing')} className="group relative flex flex-col justify-between overflow-hidden rounded-3xl border border-border-soft bg-card p-6 shadow-xs transition-all duration-300 hover:-translate-y-1 hover:border-amber-500/40 hover:shadow-lg cursor-pointer" >
{t('dashboard.pendingCollectionTitle')}
${Math.round(d.billing.pendingAmountUsd).toLocaleString('en-US')}
{t('dashboard.pendingFactorsCount', { count: toFa(d.billing.pendingCount) })} {t('dashboard.needsFollowUp')}
{/* ۴. کل تعاملات و سفارشات */}
navigate('/custom-trip/orders')} className="group relative flex flex-col justify-between overflow-hidden rounded-3xl border border-border-soft bg-card p-6 shadow-xs transition-all duration-300 hover:-translate-y-1 hover:border-primary/40 hover:shadow-lg cursor-pointer" >
{t('dashboard.totalOrdersTitle')}
{toFa(d.customTrips.totalCount + d.tours.totalCount)} {t('dashboard.pilgrimageDossiers')}
{t('dashboard.customTripsCount', { count: toFa(d.customTrips.totalCount) })} {t('dashboard.toursCount', { count: toFa(d.tours.totalCount) })}
{/* ========================================================================= */} {/* 3. شبکه تحلیل تفصیلی: امور مالی در برابر کاروان‌ها و سفرهای اختصاصی */} {/* ========================================================================= */}
{/* بلوک ۱: صورت‌حساب‌ها و پایش مالی */}

{t('dashboard.billingSectionTitle')}

{t('dashboard.billingSectionDesc')}

{/* ۳ تایل آماری فاکتورها */}
{t('dashboard.paidInvoices')} ${d.billing.paidAmountUsd.toLocaleString('en-US')} {t('dashboard.paidCountBadge', { count: toFa(d.billing.paidCount) })}
{t('dashboard.pendingInvoices')} ${Math.round(d.billing.pendingAmountUsd).toLocaleString('en-US')} {t('dashboard.pendingCountBadge', { count: toFa(d.billing.pendingCount) })}
{t('dashboard.rejectedInvoices')} {toFa(d.billing.rejectedCount + d.billing.expiredCount)} {t('dashboard.closedOrExpiredBadge')}
{/* نوار گرادینت شاخص نرخ وصول مطالبات */}
{t('dashboard.collectionRate')} {toFa(d.billing.collectionRate)}%
0% ۵۰٪ 100%
{/* جدول فشرده آخرین تراکنش‌ها */}
{t('dashboard.recentTransactions')}
{d.billing.recentFactors.slice(0, 4).map((f) => { const isApproved = f.status === 'approved' return (
navigate('/billing')} className="flex items-center justify-between p-3 text-xs hover:bg-muted/40 transition-colors cursor-pointer" >
{isApproved ? '✓' : '⏳'}
{t('dashboard.invoicePrefix', { id: f.factor_number || f.id })} {f.user_info?.fullname || f.user_info?.phone_number || t('dashboard.platformUser')}
${Number(f.amount || 0).toLocaleString('en-US')} {isApproved ? t('dashboard.settledStatus') : t('dashboard.awaitingPaymentStatus')}
) })}
{/* بلوک ۲: تورهای گروهی و سفرهای اختصاصی */}

{t('dashboard.toursSectionTitle')} و {t('dashboard.customTripSectionTitle')}

{t('dashboard.toursAndCustomSubtitle')}

{/* آمار تورهای گروهی زیارتی */}
🕋 {t('dashboard.toursSectionTitle')}
{toFa(d.tours.activeCount)} {t('dashboard.activeToursCard')}
{toFa(d.tours.travelingCount)} {t('dashboard.travelingToursCard')}
{toFa(d.tours.soldOutCount)} {t('dashboard.soldOutToursCard')}
{/* آمار سفرهای اختصاصی */}
{t('dashboard.customTripSectionTitle')}
{toFa(d.customTrips.pendingReviewCount)} {t('dashboard.adminReviewCard')}
{toFa(d.customTrips.awaitingPaymentCount)} {t('dashboard.awaitingPaymentCard')}
{toFa(d.customTrips.approvedCount)} {t('dashboard.finalApprovedCard')}
{/* سهم مقاصد پرتقاضای سفر اختصاصی */}
{t('dashboard.popularDestinations')}
{d.customTrips.popularDestinations.map((dest) => (
{dest.flag} {dest.city}
{toFa(dest.percent)}%
))}
{/* ========================================================================= */} {/* 4. خط زمانی رویدادهای زنده سیستم (Live Activity Timeline) */} {/* ========================================================================= */}

{t('dashboard.activityFeedTitle')}

{t('dashboard.activityFeedDesc')}

{d.activityFeed.length === 0 ? (

{t('dashboard.noActivity')}

) : ( d.activityFeed.map((act) => (
{act.title} {act.subtitle}
{act.amount && ( {act.amount} )} {act.badgeText}
)) )}
) }