"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useSession } from "next-auth/react";

export default () => {
	const router = useRouter();
	const session = useSession();

	useEffect(() => {
		if (session.status === "authenticated" && session.data?.user) {
			const hasDispoPermission = session.data.user.permissions?.includes("DISPO");

			if (hasDispoPermission) {
				router.replace("/dispatch");
			} else {
				router.replace("/pilot");
			}
		} else {
			router.replace("/tracker");
		}
	}, [router, session]);

	return null;
};
