import React, { useEffect } from "react";
import VerificationPending from "../components/External-Portal-Navigation/VerificationPending";
import LandingPage from "../../layout/landingpage";
import Cookies from "js-cookie";
import { useUser } from "@/shared/context/UserContext";
export default function VerificationPendingPage() {
  const userDetails = useUser();
  const hasCompletedRegistration = userDetails?.hasFinishedRegistration;
  // Remove token cookie after 15 minutes
  useEffect(() => {
    if (!hasCompletedRegistration) {
      const timer = setTimeout(() => {
        Cookies.remove("auth-token");
      }, 15 * 60 * 1000); // 15 minutes in milliseconds

      return () => clearTimeout(timer); // cleanup if the component unmounts
    }
  }, [hasCompletedRegistration]);
  // If registration is finished → show landing page
  if (hasCompletedRegistration) {
    return <LandingPage />;
  }

  // Otherwise → show pending page
  return (
    <VerificationPending
      hasCompletedRegistration={!!hasCompletedRegistration}
      contactNumber="+251 955232323"
      email="info@triaplc.com"
    />
  );
}
