import type { JSX } from "react";
import Link from "next/link";
import { ArrowLeft } from "lucide-react";
import { getTranslations } from "next-intl/server";
import { requirePermission } from "@/shared/lib/auth-guard";
import { Permissions } from "@/shared/types/permissions";
import { Button } from "@/shared/components/ui/button";
import { CalendarView } from "@/modules/lesson-preparation/components/calendar-view";

export const dynamic = "force-dynamic";

export default async function CalendarPage(): Promise<JSX.Element> {
  const t = await getTranslations("lessonPreparation");
  // V4 P0-2 修复：页面层补齐 requirePermission 权限校验
  const ctx = await requirePermission(Permissions.LESSON_PLAN_READ);

  return (
    <div className="p-6 space-y-4">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold tracking-tight">{t("calendar.title")}</h1>
          <p className="text-muted-foreground">{t("calendar.description")}</p>
        </div>
        <Button asChild variant="outline" size="sm">
          <Link href="/teacher/lesson-plans">
            <ArrowLeft className="h-4 w-4 mr-2" aria-hidden="true" />
            {t("action.back")}
          </Link>
        </Button>
      </div>
      <CalendarView initialTeacherId={ctx.userId} />
    </div>
  );
}
