
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { redirect } from 'next/navigation';
import { CalendarView } from '@/components/calendar/calendar-view';

export const metadata = {
  title: 'CRM Calendar | Quote2Contract',
  description: 'Manage work schedules, deliveries, inspections, and sign-offs'
};

export default async function CalendarPage() {
  const session = await getServerSession(authOptions);

  if (!session) {
    redirect('/auth/signin');
  }

  // Only allow admins, sales, and contractors to access calendar
  const allowedRoles = ['ADMIN', 'SALES', 'CONTRACTOR'];
  if (!allowedRoles.includes(session.user.role as string)) {
    redirect('/dashboard');
  }

  return (
    <div className="container mx-auto py-8 px-4">
      <div className="mb-8">
        <h1 className="text-3xl font-bold mb-2">CRM Calendar</h1>
        <p className="text-muted-foreground">
          Manage work start dates, deliveries, inspections, and sign-offs. 
          Sync with Google Calendar or Microsoft Outlook to keep everyone's phones updated.
        </p>
      </div>
      <CalendarView />
    </div>
  );
}
