"use client";

import { useSearchParams } from "next/navigation";

import {
  SubscriptionScreen,
  type SubscriptionType,
} from "./subscription-screen";

function toSubscriptionType(value: string | null): SubscriptionType {
  return value === "topup" ? "topup" : "vip";
}

function toReturnTo(value: string | null): "chat" | null {
  return value === "chat" ? "chat" : null;
}

export function SubscriptionPageClient() {
  const searchParams = useSearchParams();
  const subscriptionType = toSubscriptionType(searchParams.get("type"));
  const shouldResumePendingOrder = searchParams.get("paymentReturn") === "1";
  const returnTo = toReturnTo(searchParams.get("returnTo"));

  return (
    <SubscriptionScreen
      subscriptionType={subscriptionType}
      shouldResumePendingOrder={shouldResumePendingOrder}
      returnTo={returnTo}
    />
  );
}
