"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { ChevronRightIcon, WalletIcon } from "lucide-react"; import type { BankAccount, Resource } from "@/payload-types"; import { Button } from "@/components/ui/button"; import { formatAmount } from "@/lib/banking/format"; import { type AccountStatus, accountStatusBase, accountStatusClass, formatLastActivity, } from "@/lib/banking/ui"; import { BankTransactionDialog } from "@/components/frontend/banking/BankTransactionDialog"; import { ensureMyAccount } from "@/app/(frontend)/logistics/banking/actions"; interface WalletHeroProps { account: BankAccount | null; currentUser: { id: number; username: string; displayName?: string } | null; currencyResource: Resource | null; } // Shared terminal-aesthetic class for small uppercase mono labels in the hero. const labelCls = "font-mono text-[10px] uppercase tracking-wider text-muted-foreground"; export function WalletHero({ account, currentUser, currencyResource }: WalletHeroProps) { const router = useRouter(); const [initializing, setInitializing] = useState(false); const [initError, setInitError] = useState(null); async function handleInitialize() { setInitializing(true); setInitError(null); const res = await ensureMyAccount(); if (res.success) { router.push(`/logistics/banking/${res.data}`); router.refresh(); } else { setInitError(res.error ?? "Failed to initialize wallet."); setInitializing(false); } } // Empty state — terminal-flavored "WALLET NOT INITIALIZED" if (!account || !currentUser) { return (
<OPERATOR WALLET>

{"> WALLET NOT INITIALIZED"}

Run initialization to provision your personal account.

{initError && (

{"> ERROR: "} {initError}

)}
); } const accountId = account.id; const lastActivity = formatLastActivity(account.updatedAt); const currency = typeof account.currency === "object" ? account.currency : currencyResource; const operatorLabel = currentUser.displayName ?? currentUser.username; const statusKey = (account.status ?? "open") as AccountStatus; // otherAccounts requires names for the transfer destination select. // We only know this wallet here; the BankTransactionDialog receives an empty // list — transfer mode will prompt the user to use the account detail page. // Deposits/withdrawals work standalone on the hero. const otherAccounts: { id: number; name: string }[] = []; return (
<OPERATOR WALLET>
@{operatorLabel} {statusKey}
ID #{accountId.toString().padStart(6, "0")}

{formatAmount(account.balance ?? 0, currency)}

LAST ACTIVITY {lastActivity}

); }