"use client";

import { useSearchParams } from "next/navigation";

import type { PayChannel } from "@/data/dto/payment";

import { TipScreen } from "./tip-screen";

function toPayChannel(value: string | null): PayChannel | null {
  if (value === "ezpay" || value === "stripe") return value;
  return null;
}

export function TipPageClient() {
  const searchParams = useSearchParams();

  return (
    <TipScreen
      shouldResumePendingOrder={searchParams.get("paymentReturn") === "1"}
      initialPayChannel={toPayChannel(searchParams.get("payChannel"))}
    />
  );
}
