import { lazy, Suspense, useState, type ReactNode } from 'react' import { ChevronRight } from 'lucide-react' import { Link } from 'react-router' import { assetPath } from '@/components/layout/nav-items' import { PageError, PageHeader } from '@/components/page' import { Skeleton } from '@/components/skeleton' import { usePortfolio } from '@/lib/assets' import { formatDateTime, formatMoney, toIsoDate } from '@/lib/format' import { isFetchStale, kindEmoji, qty, splitAssets } from '@/lib/savings' import { t } from '@/lib/strings' import { cn } from '@/lib/utils' import type { Portfolio } from '@/types/Portfolio' import type { PortfolioItem } from '@/types/PortfolioItem' import { AddCurrency } from './add-currency' import { Notice, Pl, RateLine } from './parts' const s = t.assets /** Recharts büyük → dağılım grafiği ayrı parça */ const AllocationChart = lazy(() => import('./allocation-chart')) export function SavingsPage() { const portfolio = usePortfolio() return ( <> {portfolio.isError ? ( ) : !portfolio.data ? (
) : ( )} ) } function SavingsView({ p }: { p: Portfolio }) { const [now] = useState(() => new Date()) const today = toIsoDate(now) const { held, others } = splitAssets(p.items) const hasValue = p.value_total > 0 return (
{p.last_fetch === null ? ( {s.noFetch} ) : isFetchStale(p.last_fetch, now) ? ( {s.staleFetch} ) : null} {p.unpriced > 0 && {s.unpriced(p.unpriced)}}
{hasValue && ( }> )}

{s.listTitle}

{held.length === 0 ? (

{s.empty}

) : (
    {held.map((i) => ( ))}
)}
{others.length > 0 && (
{s.othersTitle(others.length)}

{s.othersHint}

    {others.map((i) => ( ))}
)}
) } function Summary({ p }: { p: Portfolio }) { return (

{s.totalValue}

{formatMoney(p.value_total)}

{p.last_fetch && (

{s.ratesAt(formatDateTime(p.last_fetch))}

)}
{formatMoney(p.cost_total)} {/* Mobilde 3. küçük kart tek kalmasın: tam genişlik */}
) } function Tile({ label, hint, className, children, }: { label: string hint?: string className?: string children: ReactNode }) { return (

{label}

{children}

{hint &&

{hint}

}
) } function AssetRow({ item: i, today, compact, }: { item: PortfolioItem today: string compact?: boolean }) { const a = i.asset return (
  • {kindEmoji[a.kind]}

    {a.name} {!a.is_active && ( {s.inactive} )}

    {!compact && a.kind !== 'cash' && (

    {qty(a)} {a.avg_cost_e6 !== null && ( <> · {s.avgCost(formatMoney(Math.round(a.avg_cost_e6 / 10_000)))} )}

    )} {a.kind !== 'cash' && (

    )}
    {!compact && (

    {i.value === null ? '—' : formatMoney(i.value)}

    {i.unrealized_pl !== null && a.quantity_e6 > 0 && a.kind !== 'cash' && (

    )}
    )}
  • ) }