"use client";

import { useSearchParams } from "next/navigation";
import type { Lang } from "@/lib/config";
import PaymentSuccessContent from "./PaymentSuccessContent";
import SubscriptionSuccessContent from "./SubscriptionSuccessContent";
import QuotationPaymentSuccess from "./QuotationPaymentSuccess";

interface PageProps {
  params: { lang: Lang };
}

/**
 * Payment Success Page
 *
 * Routes to the appropriate component based on URL parameters:
 * - type=quotation: One-time quotation payment success
 * - booking_id present: Booking payment success (PaymentSuccessContent)
 * - Otherwise: Subscription success (SubscriptionSuccessContent)
 */
export default function PaymentSuccessPage({ params }: PageProps) {
  const { lang } = params;
  const searchParams = useSearchParams();
  const type = searchParams.get("type");
  const bookingId = searchParams.get("booking_id");
  const sessionId = searchParams.get("session_id");

  // Quotation one-time payment (or no params at all — show success rather than error)
  if (type === "quotation" || (!bookingId && !sessionId)) {
    return <QuotationPaymentSuccess lang={lang} />;
  }

  // Booking deposit payment
  if (bookingId) {
    return (
      <PaymentSuccessContent
        lang={lang}
        bookingId={bookingId}
        sessionId={sessionId || undefined}
      />
    );
  }

  // Subscription payment
  return (
    <SubscriptionSuccessContent
      lang={lang}
      sessionId={sessionId || undefined}
      bookingId={bookingId || undefined}
    />
  );
}
