import PageContainer from '@/components/layout/page-container';
import OnlineLessonForm from '@/features/online-lessons/components/online-lesson-form';
import { hasAnyPermission } from '@/lib/auth/authorization';
import { requireEmployeeDashboardAccess } from '@/lib/auth/page-guards';
import { redirect } from 'next/navigation';

export const metadata = {
  title: 'Dashboard : New Online Lesson'
};

export default async function Page() {
  const access = await requireEmployeeDashboardAccess();

  if (!hasAnyPermission(access.session.user.effectivePermissions, ['online_lesson:create'])) {
    redirect('/dashboard/online-lessons');
  }

  return (
    <PageContainer>
      <OnlineLessonForm
        initialData={null}
        currentUserId={access.session.user.id}
        permissions={access.session.user.effectivePermissions}
      />
    </PageContainer>
  );
}
