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

const TeacherClosedAssignmentsPage: 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 closed-homework view is for teacher accounts.</section>}>
					<DashboardTeacherAssignments mode="closed" />
				</Show>
			</Show>
		</DashboardShell>
	);
};

export default TeacherClosedAssignmentsPage;
