"use client"; import { getDocumentIntlLocale } from "@/lib/i18n/browser"; import { useTranslations } from "@/components/i18n/i18n-provider"; import { useRouter, usePathname, useSearchParams } from "next/navigation"; import { PendingLink } from "@/components/ui/pending-link"; import { StatCard } from "@/components/system/stat-card"; import { Badge, Card, CardContent } from "poyraz-ui/atoms"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "poyraz-ui/molecules"; import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis, Line, LineChart } from "recharts"; import { CheckCircle2, Wallet, FolderKanban, Activity, Users } from "lucide-react"; export type DashboardData = { metrics: { netProfit: number; activeProjectsCount: number; completedTasksCount: number; avgMood: string; financeTrend: { date: string; income: number; expense: number }[]; moodTrend: { date: string; mood: number; energy: number }[]; }; projects: { id: string; status: string; name: string; created_at: string }[]; clients: { id: string; name: string; company_name: string; created_at: string }[]; range: string; }; type DashboardClientProps = { data: DashboardData; }; export function DashboardClient({ data }: DashboardClientProps) { const t = useTranslations(); const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); const handleRangeChange = (newRange: string) => { const params = new URLSearchParams(searchParams.toString()); params.set("range", newRange); router.push(`${pathname}?${params.toString()}`); }; const { netProfit, activeProjectsCount, completedTasksCount, avgMood, financeTrend, moodTrend } = data.metrics; // Format dates for Recharts using local timezone const incomeTrendData = (financeTrend || []).map(f => ({ name: new Date(f.date).toLocaleDateString(getDocumentIntlLocale(), { month: "short", day: "numeric" }), income: f.income, expense: f.expense })); const moodTrendData = (moodTrend || []).map(l => ({ date: new Date(l.date).toLocaleDateString(getDocumentIntlLocale(), { month: "short", day: "numeric" }), mood: l.mood, energy: l.energy, })); // Format currency const formatCurrency = (val: number) => { return new Intl.NumberFormat(getDocumentIntlLocale(), { style: "currency", currency: "USD", maximumFractionDigits: 0, }).format(val); }; return (
{/* Header */}

{t("dashboard.title")}

{/* KPI Cards */}
{/* Charts */}

{t("dashboard.sections.financeSummary")}

{incomeTrendData.length > 0 ? ( { if (active && payload && payload.length) { return (

{label}

{payload.map((entry, index) => (
{entry.name === 'income' ? t('dashboard.charts.income') : t('dashboard.charts.expense')}
{formatCurrency(Number(entry.value ?? 0))}
))}
); } return null; }} /> ) : (
{t("dashboard.empty.finance")}
)}

{t("dashboard.sections.moodTrend")}

{moodTrendData.length > 0 ? ( ) : (
{t("dashboard.empty.journal")}
)}
{/* Recent Items */}
{/* Recent Projects */}

{t("dashboard.sections.recentProjects")}

{(data.projects || []).slice(0, 5).map((project) => (

{project.name}

{new Date(project.created_at).toLocaleDateString(getDocumentIntlLocale(), { month: "short", day: "numeric" })}

{project.status === 'completed' ? t('dashboard.status.completed') : project.status === 'active' ? t('dashboard.status.active') : t('dashboard.status.pending')}
))} {data.projects.length === 0 && (
{t("dashboard.empty.projects")}
)}
{/* Recent Clients */}

{t("dashboard.sections.recentClients")}

{(data.clients || []).length > 0 ? (data.clients || []).map((client) => (
{client.name.charAt(0).toUpperCase()}

{client.name}

{client.company_name || t("dashboard.clients.individual")}

{new Date(client.created_at).toLocaleDateString(getDocumentIntlLocale(), { month: "short", day: "numeric" })}
)) : (
{t("dashboard.empty.clients")}
)}
); }