"use client"; import { PaymentMethod, PaymentMethodType } from "@prisma/client"; import { PAYMENT_METHOD_LABELS, SUPPORTS_QR } from "@/lib/constants"; import { buildPaymentUri } from "@/lib/payment-uri"; import { CopyButton } from "@/components/public/copy-button"; import { QrModal } from "@/components/public/qr-modal"; type PublicPaymentMethod = Pick< PaymentMethod, "id" | "type" | "label" | "value" | "network" | "description" | "isVisible" >; type PaymentMethodCardProps = { method: PublicPaymentMethod; }; function isHttpUrl(value: string) { try { const url = new URL(value); return url.protocol === "http:" || url.protocol === "https:"; } catch { return false; } } export function PaymentMethodCard({ method }: PaymentMethodCardProps) { const typeLabel = PAYMENT_METHOD_LABELS[method.type as PaymentMethodType]; const qrPayload = buildPaymentUri(method.type, method.value, method.network); const linkTarget = isHttpUrl(qrPayload) ? qrPayload : null; return (

{method.label}

{typeLabel} {method.network ? ` ยท ${method.network}` : ""}

{method.value}

{method.description ?

{method.description}

: null}
{SUPPORTS_QR.has(method.type) ? : null} {linkTarget ? ( Open ) : null}
); }