"use client"; import type { ReactNode } from "react"; import Link from "next/link"; import type { BankAccount } from "@/payload-types"; import { LandmarkIcon, WalletIcon } from "lucide-react"; import { Item, ItemContent, ItemHeader, ItemMedia, ItemTitle } from "@/components/ui/item"; import { formatAmount } from "@/lib/banking/format"; import { AccountCard } from "@/components/frontend/banking/AccountCard"; import { CreateAccountDialog } from "@/components/frontend/banking/CreateAccountDialog"; import { MyWalletCard } from "@/components/frontend/banking/MyWalletCard"; interface BankingOverviewProps { accounts: BankAccount[]; currentUserId: number; isManager: boolean; factions: { id: number; name: string }[]; } function Section({ title, count, children, }: { title: string; count: number; children: ReactNode; }) { return (

{title}

{count} account{count !== 1 ? "s" : ""}
{count === 0 ? (

None.

) : (
{children}
)}
); } export function BankingOverview({ accounts, currentUserId, isManager, factions, }: BankingOverviewProps) { const treasury = accounts.filter((a) => a.accountType === "treasury"); const faction = accounts.filter((a) => a.accountType === "faction"); const personal = accounts.filter((a) => a.accountType === "personal"); const myAccount = personal.find((a) => { const ownerId = typeof a.ownerUser === "object" ? a.ownerUser?.id : a.ownerUser; return ownerId === currentUserId; }); const unitFunds = [...treasury, ...faction].reduce( (sum, a) => sum + (a.balance ?? 0), 0, ); const currency = accounts.length > 0 && typeof accounts[0].currency === "object" ? accounts[0].currency : null; const accountTypeLabels: Record = { treasury: "Treasury", faction: "Faction", personal: "Personal", }; return (
Unit funds {formatAmount(unitFunds, currency)} Accounts {accounts.length} {myAccount ? ( My wallet {formatAmount(myAccount.balance ?? 0, currency)} ) : ( )}

Accounts

{treasury.map((account) => ( ))}
{faction.map((account) => ( ))}
{personal.map((account) => ( ))}
{accounts.length === 0 && (

No accounts yet. Create your first account to get started. {isManager ? "" : " (Ask logistics personnel to set up the unit treasury.)"}

)}

Account types: {Object.values(accountTypeLabels).join(" ยท ")}. Balances are denominated in the main currency set in Game Rules.

); }