"use client";

import { useSearchParams } from "next/navigation";
import { useEffect } from "react";

export default function payCallback() {
  const searchParams = useSearchParams();
  const sessionId = searchParams.get("session_id");
  const userId = searchParams.get("user_id");
  const canceled = searchParams.get("canceled")||false;

  useEffect(() => {
    window.opener?.postMessage(
      { type: "payment-callback", canceled, sessionId, userId },
      "*"
    );
    window.close();
  }, []);

  return <></>;
}
