"use client"; import Link from "next/link"; import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "@/components/ui/chart"; import { tr } from "@/i18n/tr"; import { cn } from "@/lib/utils"; import { formatDate, formatMoney } from "@/shared/format"; import type { PeriodReport } from "@/shared/portfolio"; import type { ReportRange } from "../service"; import { ProfitLoss, Stat } from "./assets-view"; const t = tr.assets.report; const RANGES: ReportRange[] = ["3", "6", "12", "tum"]; const d = (ymd: string) => formatDate(`${ymd}T12:00:00+03:00`); const tickFmt = new Intl.DateTimeFormat("tr-TR", { day: "numeric", month: "short", timeZone: "Europe/Istanbul", }); const compact = new Intl.NumberFormat("tr-TR", { notation: "compact", maximumFractionDigits: 1 }); const config = { value: { label: t.value, color: "var(--budget)" }, cost: { label: t.cost, color: "var(--muted-foreground)" }, } satisfies ChartConfig; /** Dönem seçici + özet + aylık değer/maliyet grafiği + tablo görünümü. */ export function PeriodReportView({ report, range, basePath, }: { report: PeriodReport & { excluded: number }; range: ReportRange; basePath: string; }) { const data = report.points.map((p) => ({ date: p.date, label: tickFmt.format(new Date(`${p.date}T12:00:00+03:00`)), // Kuruş → TL (eksen ve ipucu TL gösterir). value: p.valueMinor === null ? null : p.valueMinor / 100, cost: p.costMinor / 100, })); const hasData = report.points.some((p) => p.costMinor > 0 || (p.valueMinor ?? 0) > 0); return (
{t.title} {t.period(d(report.from), d(report.to))}
{report.startValueMinor !== null ? formatMoney(report.startValueMinor) : t.noPrice} {formatMoney(report.investedMinor)} {report.endValueMinor !== null ? formatMoney(report.endValueMinor) : t.noPrice} {report.proceedsMinor ? ( {formatMoney(report.proceedsMinor)} ) : null} {report.giftInMinor ? ( {formatMoney(report.giftInMinor)} ) : null} {report.giftOutMinor ? ( {formatMoney(report.giftOutMinor)} ) : null}

{t.formula}

{report.excluded ? (

{t.excluded(report.excluded)}

) : null} {hasData ? ( <> compact.format(v)} /> { const date = payload?.[0]?.payload?.date as string | undefined; return date ? d(date) : ""; }} formatter={(value, name) => (
{config[name as keyof typeof config]?.label} {formatMoney(Math.round(Number(value) * 100))}
)} /> } /> } />
{t.table} {report.points.map((p) => ( ))}
{t.date} {t.value} {t.cost}
{d(p.date)} {p.valueMinor !== null ? formatMoney(p.valueMinor) : t.noPrice} {formatMoney(p.costMinor)}
) : (

{t.empty}

)}
); }