"use client"; /* eslint-disable @next/next/no-img-element */ import { PaymentMethod, PaymentMethodType } from "@prisma/client"; import { PAYMENT_METHOD_LABELS } from "@/lib/constants"; import { CopyButton } from "@/components/public/copy-button"; type PublicPaymentMethod = Pick< PaymentMethod, "id" | "type" | "label" | "value" | "network" | "description" | "isVisible" > & { qrPayload: string | null; qrDataUrl: string | null; }; 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 linkTarget = method.qrPayload && isHttpUrl(method.qrPayload) ? method.qrPayload : null; return (

{method.label}

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

{method.value}

{method.description ?

{method.description}

: null}
{method.qrPayload ? (
QR

{method.label} QR

{method.qrDataUrl ? ( {`${method.label} ) : (

Could not generate QR code for this value.

)}

{method.qrPayload}

) : null} {linkTarget ? ( Open ) : null}
); }