"use client";

import { Suspense, useEffect } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import Layout from "@/components/layout";

function PaymentResultRedirect() {
  const router = useRouter();
  const searchParams = useSearchParams();

  useEffect(() => {
    const paymentUuid = searchParams.get("payment_uuid");
    const status = searchParams.get("status");
    if (paymentUuid) {
      const q = status ? `?status=${status}` : "";
      router.replace(`/payment/${paymentUuid}${q}`);
    } else {
      router.replace("/dashboard?sidebar=1");
    }
  }, [searchParams, router]);

  return (
    <div className="flex items-center justify-center min-h-screen">
      <div className="flex flex-col items-center gap-4">
        <div className="w-12 h-12 border-4 border-[#5559CE] border-t-transparent rounded-full animate-spin"></div>
        <p className="text-[#3B3B3B] text-[16px]">در حال انتقال به نتیجه‌ی پرداخت...</p>
      </div>
    </div>
  );
}

export default function PaymentResultPage() {
  return (
    <Layout>
      <Suspense fallback={null}>
        <PaymentResultRedirect />
      </Suspense>
    </Layout>
  );
}
