"use client"; import { ExternalLink, User } from "lucide-react"; import { useState } from "react"; import { Button, Card, CardContent, CardHeader, CardTitle, Skeleton } from "../../../../shadcnui"; import { StripeCustomerInterface, StripeCustomerService } from "../../stripe-customer"; type CustomerInfoCardProps = { customer: StripeCustomerInterface | null; loading?: boolean; error?: string; }; function formatBalance(balance: number | undefined, currency: string | undefined): string { if (balance === undefined || balance === 0) return "$0.00"; const currencyCode = currency?.toUpperCase() || "USD"; // Balance in Stripe is negative when customer has credit const displayBalance = -balance; return new Intl.NumberFormat(undefined, { style: "currency", currency: currencyCode, }).format(displayBalance / 100); } export function CustomerInfoCard({ customer, loading, error }: CustomerInfoCardProps) { const [portalLoading, setPortalLoading] = useState(false); const handlePortalClick = async (e: React.MouseEvent) => { e.stopPropagation(); setPortalLoading(true); try { const { url } = await StripeCustomerService.createPortalSession(); window.open(url, "_blank"); } catch (err) { console.error("[CustomerInfoCard] Failed to create portal session:", err); } finally { setPortalLoading(false); } }; if (loading) { return ( Billing Account ); } if (error) { return ( Billing Account

{error}

); } if (!customer) { return ( Billing Account

Not set up

Billing account will be created when you subscribe

); } return ( Billing Account
{customer.name &&

{customer.name}

} {customer.email &&

{customer.email}

} {customer.balance !== undefined && customer.balance !== 0 && (

Credit Balance: {formatBalance(customer.balance, customer.currency)}

)}
); }