import type { Component } from "solid-js";
import { Show, createMemo, createResource } from "solid-js";
import DashboardShell from "../../../../components/dashboard/shared/dashboard-shell";
import DashboardTeacherAssignmentCreate from "../../../../components/dashboard/teacher/dashboard-teacher-assignment-create";
import { getTeacherDashboardHomeData } from "../../../../components/dashboard/teacher/dashboard-teacher-home.data";
import { useAuth } from "~/context/auth/context";

const TeacherDashboardAssignmentCreatePage: Component = () => {
	const auth = useAuth();
	const teacherId = createMemo(() => (auth.isReady() && auth.user()?.role === "teacher" ? auth.user()!.id : null));
	const [shellData] = createResource(teacherId, getTeacherDashboardHomeData);

	return (
		<DashboardShell sidebarData={shellData()?.shell} topbarData={shellData()?.shell}>
			<Show when={auth.isReady()} fallback={<section>Loading your dashboard session…</section>}>
				<Show when={auth.user()?.role === "teacher"} fallback={<section>This assignment setup view is for teacher accounts.</section>}>
					<DashboardTeacherAssignmentCreate />
				</Show>
			</Show>
		</DashboardShell>
	);
};

export default TeacherDashboardAssignmentCreatePage;
