'use client';

import { useEffect } from 'react';
import { useAppStore } from '@/stores/app-store';
import LoginPage from '@/components/app/login-page';
import AppShell from '@/components/app/app-shell';
import DashboardPage from '@/components/app/dashboard-page';
import SantriPage from '@/components/app/santri-page';
import HafalanPage from '@/components/app/hafalan-page';
import NgajiPage from '@/components/app/ngaji-page';
import JilidPage from '@/components/app/jilid-page';
import OrtuDashboard from '@/components/app/ortu-dashboard';
import LaporanPage from '@/components/app/laporan-page';
import KepsekDashboard from '@/components/app/kepsek-dashboard';
import KepsekGuruPage from '@/components/app/kepsek-guru-page';
import KepsekSantriPage from '@/components/app/kepsek-santri-page';

export default function Home() {
  const { user, currentPage, restoreSession } = useAppStore();

  useEffect(() => {
    restoreSession();
  }, [restoreSession]);

  if (!user) return <LoginPage />;

  if (user.role === 'ortu') {
    return (
      <AppShell>
        <OrtuDashboard />
      </AppShell>
    );
  }

  const pages: Record<string, React.ReactNode> = {
    // Guru
    dashboard: <DashboardPage />,
    santri: <SantriPage />,
    hafalan: <HafalanPage />,
    ngaji: <NgajiPage />,
    jilid: <JilidPage />,
    laporan: <LaporanPage />,
    // Kepala Sekolah
    'kepsek-dashboard': <KepsekDashboard />,
    'kepsek-guru': <KepsekGuruPage />,
    'kepsek-santri': <KepsekSantriPage />,
  };

  return (
    <AppShell>
      {pages[currentPage] || <DashboardPage />}
    </AppShell>
  );
}