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 (
<>
{s.empty}
) : ({s.othersHint}
{s.totalValue}
{formatMoney(p.value_total)}
{p.last_fetch && ({s.ratesAt(formatDateTime(p.last_fetch))}
)}{label}
{children}
{hint &&{hint}
}{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' && (
{i.value === null ? '—' : formatMoney(i.value)}
{i.unrealized_pl !== null && a.quantity_e6 > 0 && a.kind !== 'cash' && (