import React, { useMemo } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Input } from "@/components/ui/input"; import { Progress } from "@/components/ui/progress"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Separator } from "@/components/ui/separator"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { LayoutDashboard, CreditCard, ArrowRightLeft, Users, Store, Package, Settings, TrendingUp, TrendingDown, CalendarDays, Banknote, Wallet, Link2, Bell, HelpCircle, Search, Menu, CheckCircle2, Clock3, AlertTriangle, Download, } from "lucide-react"; import { motion } from "framer-motion"; // --- Types --- interface MetricBar { label: string; value: number; // current max: number; // scale tint?: "green" | "blue" | "orange" | "pink" | "purple" | "slate"; href?: string; } interface QuickLink { label: string; icon: React.ReactNode; href: string; } interface TimelineItem { date: string; // ISO or human title: string; amount?: string; href?: string; type?: "note" | "info" | "warning" | "success"; } interface DashboardData { dateLabel: string; kpi: { monthTurnoverTL: string; monthExpensesTL: string; stockValueTL: string; }; assets: MetricBar[]; liabilities: MetricBar[]; overdueReceivables: TimelineItem[]; upcomingExpenses: TimelineItem[]; recentActions: TimelineItem[]; announcements: TimelineItem[]; quickLinks: QuickLink[]; } const demo: DashboardData = { dateLabel: "28 Eylül 2025 Pazar", kpi: { monthTurnoverTL: "TL 19.825,06", monthExpensesTL: "TL 9.883,32", stockValueTL: "214.448,78", }, assets: [ { label: "Kasa", value: 31_023, max: 365_022, tint: "green", href: "/finance/cash" }, { label: "POS", value: 101_346, max: 365_022, tint: "blue", href: "/finance/pos" }, { label: "Banka", value: 12_615, max: 365_022, tint: "purple", href: "/finance/banks" }, { label: "Stok", value: 214_448, max: 365_022, tint: "orange", href: "/inventory" }, { label: "Açık Hesap", value: 5_587, max: 365_022, tint: "slate", href: "/crm/open-accounts" }, ], liabilities: [ { label: "Açık Hesap", value: 177_773, max: 216_000, tint: "pink", href: "/payables" }, ], overdueReceivables: [ { date: "335 gün gecikmiş", title: "ALTINSOFT BİLİŞİM TEKNOLOJİLERİ", amount: "5.587,98 TL", href: "/crm/receivables/altinsoft", type: "warning" }, ], upcomingExpenses: [ { date: "29.09.2025", title: "Geldi Elektrik Per. / Tedarikçi No: 062", amount: "1.140,00", href: "/expenses/062", type: "info" }, ], recentActions: [ { date: "28.09.2025 20:12", title: "İsmail Eker sisteme giriş yaptı", type: "success" }, { date: "27.09.2025 11:21", title: "İsmail Eker sisteme giriş yaptı", type: "success" }, { date: "26.09.2025 23:45", title: "KÖFTECİ YUSUF HAZIR YEMEK TEMİZLİK CANLI HAYVAN – 900,00 TL tahsilat kaydedildi", type: "note" }, ], announcements: [ { date: "Davet et, kazan", title: "Arkadaşını davet et, 1 ay ek kullanım tanımlayalım!", href: "/referral", type: "info" }, ], quickLinks: [ { label: "Muhasebe", icon: , href: "/accounting" }, { label: "Müşteriler", icon: , href: "/customers" }, { label: "Tedarikçiler", icon: , href: "/suppliers" }, { label: "Ürünler", icon: , href: "/products" }, { label: "Teklifler", icon: , href: "/quotes" }, { label: "E‑Ticaret", icon: , href: "/ecommerce" }, { label: "Raporlar", icon: , href: "/reports" }, { label: "Ayarlar", icon: , href: "/settings" }, ], }; // --- Helpers --- const tintToClass = (t: MetricBar["tint"]) => { switch (t) { case "green": return "bg-emerald-500"; case "blue": return "bg-sky-500"; case "orange": return "bg-amber-500"; case "pink": return "bg-pink-500"; case "purple": return "bg-violet-500"; default: return "bg-slate-400"; } }; function formatTL(n: number) { try { return new Intl.NumberFormat("tr-TR", { style: "currency", currency: "TRY" }).format(n); } catch { return `${n.toLocaleString("tr-TR")} TL`; } } function NavItem({ icon, label, active = false }: { icon: React.ReactNode; label: string; active?: boolean }) { return ( {icon} {label} ); } export default function EGAdminDashboard({ data = demo }: { data?: DashboardData }) { const totalAssets = useMemo(() => data.assets.reduce((a, b) => a + (b.value || 0), 0), [data.assets]); const navigate = (href?: string) => { if (!href) return; // 👉 Burayı projede kendi router'ınıza bağlayın (Next.js: useRouter, React Router: useNavigate) window?.open?.(href, "_self"); }; return ( {/* Top Bar */} Yönetim Paneli Ana Ekran Bildirimler {data.dateLabel} {/* Sidebar */} Modüller {data.quickLinks.map((q, i) => ( navigate(q.href)}> ))} Toplam Varlık: {formatTL(totalAssets)} {/* Main */} {/* KPI Row */} Eylül Cirosu {data.kpi.monthTurnoverTL} {data.assets.map((m, i) => ( navigate(m.href)}> {m.label} {formatTL(m.value)} ))} Eylül Masrafları {data.kpi.monthExpensesTL} {data.liabilities.map((m, i) => ( navigate(m.href)}> {m.label} {formatTL(m.value)} ))} Stok Değeri {data.kpi.stockValueTL} Güncel envanter maliyet toplamı navigate("/inventory")}>Envanter navigate("/purchase-orders")}>Satın Alma {/* Middle Row */} Vadesi Geçen Açık Hesap Alacaklar navigate("/crm/receivables")}>Tümü {data.overdueReceivables.map((i, idx) => ( navigate(i.href)}>{i.title} {i.date} {i.amount} ))} Duyurular navigate("/announcements")}>Detay {data.announcements.map((n, idx) => ( {n.date} {n.title} navigate(n.href)}>Git ))} {/* Bottom Row */} Yaklaşan Masraflar navigate("/expenses")}>Takvim {data.upcomingExpenses.map((e, idx) => ( {e.date} navigate(e.href)}>{e.title} {e.amount} ))} Son İşlemler navigate("/activity")}>Tümü {data.recentActions.map((a, idx) => ( {a.type === "success" && } {a.type === "warning" && } {(!a.type || a.type === "note" || a.type === "info") && } {a.title} {a.date} ))} ); }