import { getServerSession } from 'next-auth';
import { redirect } from 'next/navigation';
import { authOptions } from '@/lib/auth';
import { MainNav } from '@/components/navigation/main-nav';
import { AdvancedAnalyticsDashboard } from '@/components/analytics/advanced-analytics-dashboard';

export const dynamic = 'force-dynamic';

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

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

  // Only admins and sales can access analytics
  if (session.user.role !== 'ADMIN' && session.user.role !== 'SALES') {
    redirect('/dashboard');
  }

  return (
    <div className="min-h-screen bg-background">
      <MainNav />
      <main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
        <AdvancedAnalyticsDashboard />
      </main>
    </div>
  );
}
