"use client"; import { ChevronDown, CreditCard, Landmark, Percent, Wallet } from "lucide-react"; import { useState } from "react"; import { useQuickAdd } from "@/components/layout/quick-add"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; import { tr } from "@/i18n/tr"; import { cn } from "@/lib/utils"; import { formatDate, formatMoney } from "@/shared/format"; import { formatMoneyInput } from "@/shared/money"; import type { CardSummary, OverdraftSummary } from "../card"; import { Amount, rowTitle } from "./transaction-parts"; const c = tr.card; const o = tr.overdraft; const d = (ymd: string) => formatDate(`${ymd}T12:00:00+03:00`); const pct = (bp: number) => formatMoneyInput(bp).replace(/,00$/, ""); function Stat({ label, value, tone, sub, }: { label: string; value: string; tone?: string; sub?: React.ReactNode; }) { return (

{label}

{value}

{sub ?

{sub}

: null}
); } /** Limit kullanım çubuğu: borç + gelecek taksitler / limit. */ function UsageBar({ used, pending, limit }: { used: number; pending: number; limit: number }) { if (limit <= 0) return null; const u = Math.min(100, (used / limit) * 100); const p = Math.min(100 - u, (pending / limit) * 100); return (
); } export function CardSummaryPanel({ summary: s, accountId, canWrite, }: { summary: CardSummary; accountId: string; canWrite: boolean; }) { const { openTransactionForm } = useQuickAdd(); const [historyOpen, setHistoryOpen] = useState(false); const st = s.statement; function pay() { openTransactionForm({ kind: "create", type: "transfer", prefill: { accountId: s.paymentAccount?.id, toAccountId: accountId, amountMinor: st.remainingMinor || undefined, description: c.payDescription, }, }); } return ( {c.title}
{s.pendingInstallmentsMinor ? (

{c.pendingInstallments(formatMoney(s.pendingInstallmentsMinor))}

) : null}

{c.statementPeriod}

{c.periodRange(d(st.period.start), d(st.period.end))}

{c.dueDate}: {d(st.dueDate)}{" "} {st.remainingMinor ? `· ${c.daysLeft(s.daysToDue)}` : `· ${c.paidInFull}`}

{canWrite ? ( ) : null}

{c.currentPeriod}

{c.periodRange(d(s.current.start), d(s.current.end))}

{c.upcomingInstallments}

{s.upcomingInstallments.length ? (
    {s.upcomingInstallments.map((x) => (
  • {c.installmentPeriod(d(x.periodEnd), d(x.dueDate), x.count)} {formatMoney(x.totalMinor)}
  • ))}
) : (

{c.noInstallments}

)}
{s.planned.length ? (

{c.planned}

    {s.planned.map((p) => (
  • {d(p.date)} · {rowTitle(p)}
  • ))}
) : null}
{s.history.map((h) => ( ))}
{c.historyHeaders.period} {c.historyHeaders.debt} {c.historyHeaders.minimum} {c.historyHeaders.paid} {c.historyHeaders.due}
{c.periodRange(d(h.period.start), d(h.period.end))} {formatMoney(h.debtMinor)} {formatMoney(h.minimumMinor)} {formatMoney(h.paidMinor)} {d(h.dueDate)}
); } export function OverdraftPanel({ summary: s, accountId, canWrite, }: { summary: OverdraftSummary; accountId: string; canWrite: boolean; }) { const { openTransactionForm } = useQuickAdd(); const range = c.periodRange(d(s.statement.start), d(s.statement.end)); function bookInterest() { openTransactionForm({ kind: "create", type: "expense", prefill: { accountId, amountMinor: s.statement.interestMinor || undefined, categoryId: s.interestCategoryId ?? undefined, date: s.statement.end, description: o.interestDescription(range), }, }); } return ( {o.title}

{o.lastPeriod}

{range}
{s.interestBooked ? (

{o.booked}

) : canWrite && s.statement.interestMinor > 0 ? ( ) : null}

{o.taxNote}

{o.currentSoFar}:{" "} {formatMoney(s.current.interestSoFarMinor)}

); }