import { TossPaymentSuccessPanel } from "@/components/toss-payment-success-panel";

type TossSuccessPageProps = {
  searchParams?: Promise<Record<string, string | string[] | undefined>>;
};

function pickParam(value: string | string[] | undefined) {
  return Array.isArray(value) ? value[0] : value;
}

export default async function TossSuccessPage({ searchParams }: TossSuccessPageProps) {
  const params = searchParams ? await searchParams : {};
  const paymentKey = pickParam(params.paymentKey) ?? "";
  const orderId = pickParam(params.orderId) ?? "";
  const amountValue = pickParam(params.amount) ?? "";
  const amount = Number(amountValue);
  const simulated = pickParam(params.simulated) === "1";

  return (
    <TossPaymentSuccessPanel
      amount={Number.isFinite(amount) ? amount : null}
      orderId={orderId}
      paymentKey={paymentKey}
      simulated={simulated}
    />
  );
}
