"use client"; import { useState } from "react"; import { Badge, Button, 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, CalendarDays, Plus } from "lucide-react"; import { QuickActionsSheet } from "@/components/dashboard/quick-actions-sheet"; export type DashboardData = { tasks: { id: string; status: string; created_at: string; updated_at?: string; due_at?: string }[]; projects: { id: string; status: string; name: string }[]; finances: { id: string; type: string; amount: number; transaction_date: string }[]; logs: { id: string; log_date: string; mood_score: number; energy_score: number }[]; events: { id: string; title: string; type: string; starts_at: string }[]; }; type DashboardClientProps = { data: DashboardData; }; export function DashboardClient({ data }: DashboardClientProps) { const [dateRange, setDateRange] = useState("this_month"); const [isQuickActionOpen, setIsQuickActionOpen] = useState(false); // Calculate real metrics from the `data` prop depending on `dateRange` const now = new Date(); // Helper to filter by date const filterByDate = (dateStr: string | null) => { if (!dateStr) return false; const date = new Date(dateStr); if (dateRange === "today") { return date.toDateString() === now.toDateString(); } if (dateRange === "this_week") { const firstDay = new Date(now.setDate(now.getDate() - now.getDay() + (now.getDay() === 0 ? -6 : 1))); // Monday return date >= firstDay; } if (dateRange === "this_month") { return date.getMonth() === now.getMonth() && date.getFullYear() === now.getFullYear(); } return true; }; // KPIs const filteredFinances = data.finances.filter(f => filterByDate(f.transaction_date)); const income = filteredFinances.filter(f => f.type === "income").reduce((acc, curr) => acc + Number(curr.amount), 0); const expense = filteredFinances.filter(f => f.type === "expense").reduce((acc, curr) => acc + Number(curr.amount), 0); const netProfit = income - expense; const activeProjectsCount = data.projects.filter(p => p.status === "active").length; const completedTasksCount = data.tasks.filter(t => t.status === "completed" && filterByDate(t.updated_at || t.created_at)).length; const filteredLogs = data.logs.filter(l => filterByDate(l.log_date)); const avgMood = filteredLogs.length > 0 ? (filteredLogs.reduce((acc, curr) => acc + curr.mood_score, 0) / filteredLogs.length).toFixed(1) : "0.0"; // Recharts Data Prep // Group finances by date const financeMap = new Map(); filteredFinances.forEach(f => { const d = new Date(f.transaction_date).toLocaleDateString("tr-TR", { month: "short", day: "numeric" }); if (!financeMap.has(d)) { financeMap.set(d, { name: d, income: 0, expense: 0 }); } const entry = financeMap.get(d); if (f.type === "income") entry.income += Number(f.amount); if (f.type === "expense") entry.expense += Number(f.amount); }); const incomeTrendData = Array.from(financeMap.values()); // Group logs by date const moodTrendData = filteredLogs.map(l => ({ date: new Date(l.log_date).toLocaleDateString("tr-TR", { month: "short", day: "numeric" }), mood: l.mood_score, energy: l.energy_score, })); // Format currency const formatCurrency = (val: number) => { return new Intl.NumberFormat("tr-TR", { style: "currency", currency: "USD", maximumFractionDigits: 0, }).format(val); }; return (
{/* Header */}
Genel Bakış

Dashboard

İş performansını, gelirlerini ve günlük durumunu takip et.

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

Gelir / Gider Özeti

{incomeTrendData.length > 0 ? ( ) : (
Bu tarih aralığında finansal veri yok.
)}

Mood & Enerji Trendi

{moodTrendData.length > 0 ? ( ) : (
Bu tarih aralığında günlük verisi yok.
)}
{/* Upcoming & Tasks List */}

Yaklaşan Etkinlikler ve Deadlinelar

{data.events.length > 0 ? data.events.map((event) => (

{event.title}

{new Date(event.starts_at).toLocaleDateString("tr-TR", { month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" })}

)) : (
Yaklaşan etkinlik yok.
)}
); } function StatCard({ label, value, icon: Icon, tone, }: { label: string; value: string; icon: typeof FolderKanban; tone: "green" | "blue" | "amber" | "red"; }) { const toneClass = { green: "bg-emerald-50 text-emerald-700", blue: "bg-blue-50 text-blue-700", amber: "bg-amber-50 text-amber-700", red: "bg-primary/10 text-primary", }[tone]; return (

{label}

{value}

); }