import {
  getFirstPaymentSearchParam,
  parsePaymentReturnSearchParams,
  type PaymentSearchParams,
} from "@/lib/payment/payment_search_params";
import {
  DEFAULT_TIP_COFFEE_TYPE,
  resolveTipCoffeeType,
  TIP_COFFEE_TYPE_PARAM,
} from "@/lib/tip/tip_coffee";
import { TipScreen } from "@/app/tip/tip-screen";

export default async function CharacterTipPage({
  searchParams,
}: {
  searchParams: Promise<PaymentSearchParams>;
}) {
  const query = await searchParams;
  const paymentReturn = parsePaymentReturnSearchParams(query);
  const coffeeType =
    resolveTipCoffeeType(
      getFirstPaymentSearchParam(query[TIP_COFFEE_TYPE_PARAM]),
    ) ?? DEFAULT_TIP_COFFEE_TYPE;

  return (
    <TipScreen
      coffeeType={coffeeType}
      shouldResumePendingOrder={paymentReturn.shouldResumePendingOrder}
      initialPayChannel={paymentReturn.initialPayChannel}
    />
  );
}
