import { useQuery } from '@tanstack/react-query'
import { FileText, CheckCircle2, AlertTriangle, TrendingUp, Coins, Pencil, Clock, Inbox } from 'lucide-react'
import { useNavigate } from 'react-router-dom'
import { PageHeader } from '@/components/PageHeader'
import { BarChart } from '@/components/BarChart'
import { PhaseBadge } from '@/components/PhaseBadge'
import { useAuth } from '@/contexts/AuthContext'
import { api } from '@/lib/api'
import { cn } from '@/lib/cn'
import type { DashboardStats } from '@/types/reports'
type MyDashboard = {
draftsInProgress: number
pendingMyApproval: number
dueSoon: number
overdue: number
draftsTotalValue: number
}
const fmtMoney = (v: number) => {
if (v >= 1_000_000_000) return (v / 1_000_000_000).toFixed(1) + ' tỷ'
if (v >= 1_000_000) return (v / 1_000_000).toFixed(1) + ' tr'
return v.toLocaleString('vi-VN')
}
// Tone → tinted icon chip (brand-led, semantic accents for warn/good).
const STAT_TONE: Record<'default' | 'warn' | 'good', { chip: string; icon: string; value: string }> = {
default: { chip: 'bg-brand-50', icon: 'text-brand-600', value: 'text-slate-900' },
warn: { chip: 'bg-amber-50', icon: 'text-amber-600', value: 'text-amber-700' },
good: { chip: 'bg-emerald-50', icon: 'text-emerald-600', value: 'text-slate-900' },
}
function StatCard({ icon: Icon, label, value, hint, tone = 'default' }: {
icon: React.ComponentType<{ className?: string }>
label: string
value: React.ReactNode
hint?: string
tone?: 'default' | 'warn' | 'good'
}) {
const t = STAT_TONE[tone]
return (
{label}
{value}
{hint &&
{hint}
}
)
}
// Small section title with a brand tick — gives each band a clear, quiet anchor.
function SectionLabel({ children }: { children: React.ReactNode }) {
return (
{children}
)
}
function MyDashboardRow() {
const navigate = useNavigate()
const { user } = useAuth()
const q = useQuery({
queryKey: ['my-dashboard'],
queryFn: async () => (await api.get('/reports/my-dashboard')).data,
staleTime: 30_000,
})
const d = q.data
if (!d) return null
// Admin thấy everything nhưng card "Tôi đang soạn thảo" + "Chờ tôi duyệt"
// thường = 0 cho admin. Chỉ show row nếu có ít nhất 1 card có giá trị.
const anyValue = d.draftsInProgress + d.pendingMyApproval + d.dueSoon + d.overdue > 0
if (!anyValue && user?.roles.includes('Admin')) return null
return (