import { useNavigate, useSearchParams } from "@solidjs/router";
import { createEffect } from "solid-js";

/**
 * Signup index route - redirects to role-specific signup pages
 * 
 * Routes:
 * - /signup → /signup/job-seeker
 * - /signup?intent=company → /signup/company
 * - /signup?intent=job_seeker → /signup/job-seeker
 * - /signup?intent=professional → /signup/professional
 * - /signup?intent=customer → /signup/customer
 */
export default function SignupIndexRoute() {
  const navigate = useNavigate();
  const [search] = useSearchParams();

  createEffect(() => {
    const intent = (typeof search.intent === 'string' ? search.intent : Array.isArray(search.intent) ? search.intent[0] : '')?.toLowerCase() || "";
    
    if (intent.includes("company")) {
      navigate("/signup/company", { replace: true });
    } else if (intent.includes("professional")) {
      navigate("/signup/professional", { replace: true });
    } else if (intent.includes("customer")) {
      navigate("/signup/customer", { replace: true });
    } else if (intent.includes("job_seeker") || intent.includes("jobseeker") || intent.includes("job-seeker")) {
      navigate("/signup/jobseeker", { replace: true });
    } else {
      // Default to job seeker if no intent specified
      navigate("/signup/jobseeker", { replace: true });
    }
  });

  return (
    <div style={{ 
      display: "flex", 
      "justify-content": "center", 
      "align-items": "center",
      height: "100vh",
      background: "#07051a"
    }}>
      <p style={{ color: "#fff" }}>Redirecting...</p>
    </div>
  );
}
