import { useNavigate } from "@solidjs/router";
import type { Component } from "solid-js";
import { Show, createEffect } from "solid-js";
import { useAuth } from "../../context/auth/context";
import { getDashboardSettingsHref } from "../../lib/routes";

const DashboardSettingsRoute: Component = () => {
	const auth = useAuth();
	const navigate = useNavigate();

	createEffect(() => {
		if (!auth.isReady()) return;
		const user = auth.user();
		if (!user) return;
		void navigate(getDashboardSettingsHref(user.role), { replace: true });
	});

	return (
		<Show when={auth.isReady()} fallback={<section>Loading your dashboard session…</section>}>
			<section>Redirecting to your settings…</section>
		</Show>
	);
};

export default DashboardSettingsRoute;
