import { createFileRoute } from "@tanstack/react-router";
import { SipProvider, useSip } from "@/lib/sip-data";
import { LoginView } from "@/components/sip/LoginView";
import { AppShell } from "@/components/sip/AppShell";

const title = "SIP SMPN 8 Palangka Raya | Sistem Informasi Petugas Piket";
const description =
  "Aplikasi piket sekolah SMP Negeri 8 Palangka Raya: buku tamu digital, pencatatan pelanggaran, izin keluar siswa, jadwal piket, dan rekap laporan.";

export const Route = createFileRoute("/")({
  head: () => ({
    meta: [
      { title },
      { name: "description", content: description },
      { property: "og:title", content: title },
      { property: "og:description", content: description },
      { property: "og:type", content: "website" },
      { name: "twitter:card", content: "summary_large_image" },
    ],
  }),
  component: Index,
});

function Screen() {
  const { currentUser } = useSip();
  return currentUser ? <AppShell /> : <LoginView />;
}

function Index() {
  return (
    <SipProvider>
      <h1 className="sr-only">Sistem Informasi Petugas Piket SMP Negeri 8 Palangka Raya</h1>
      <Screen />
    </SipProvider>
  );
}
