"use client"; import { useRouter } from "next/navigation"; import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts"; import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "@/components/ui/chart"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { tr } from "@/i18n/tr"; import { formatUnitPrice, unitPriceBase } from "@/shared/prices"; import type { UnitPriceReport } from "../extra"; import { dayLabel, monthLabel, monthShort } from "./report-frame"; const t = tr.reports.unitPrice; const config = { min: { label: t.min, color: "var(--income)" }, avg: { label: t.avg, color: "var(--budget)" }, } satisfies ChartConfig; /** Ürün tipi seçimi (URL'de) ve aylık en düşük / ortalama birim fiyat. */ export function UnitPriceView({ data }: { data: UnitPriceReport }) { const router = useRouter(); const sel = data.selected; if (!sel) return (
{t.noTypes}
); const base = unitPriceBase(sel.unit); // Gösterim biriminde TL (g → kg, ml → lt). const tl = (minor: number | null) => (minor === null ? null : (minor * base.factor) / 100); const chart = sel.points.map((p) => ({ month: p.month, label: monthShort(p.month), min: tl(p.minMinor), avg: tl(p.avgMinor), })); const fmt = (minor: number | null) => (minor === null ? "—" : formatUnitPrice(minor, sel.unit)); return (| {t.month} | {t.min} | {t.avg} | {t.count} |
|---|---|---|---|
| {monthLabel(p.month)} | {fmt(p.minMinor)} | {fmt(p.avgMinor)} | {p.count} |
| {t.store} | {t.min} | {t.last} |
|---|---|---|
| {s.label} | {fmt(s.minMinor)} | {dayLabel(s.lastDate)} |