import { LoadingOverlay } from "@/components";
import { useIsLoggedIn } from "@/lib/hooks";
import { Navigate } from "react-router-dom";

export const StartPage = () => {
  const { status, data: { authenticated, redirectTo } = {} } = useIsLoggedIn();

  if (status !== "success") {
    return <LoadingOverlay />;
  }

  if (!authenticated) {
    return (
      <Navigate
        to={redirectTo ?? "/login"}
        state={{
          error: "No authentication, please complete the login process.",
        }}
      />
    );
  }

  return <Navigate to={"/quotes"} />;
};
