import { Metadata } from 'next';
import { DailyPageClient } from './DailyPageClient';
import { dailyService } from '@/services/task-management/daily';
import { DeadlineAnalyticsService } from '@/services/analytics/deadline-analytics';
import { getToday } from '@/lib/date-utils';

// Force dynamic rendering (no static generation)
export const dynamic = 'force-dynamic';

export const metadata: Metadata = {
  title: 'Daily - Tower Control',
  description: 'Gestion quotidienne des tâches et objectifs',
};

export default async function DailyPage() {
  // Récupérer les données côté serveur
  const today = getToday();
  
  try {
    const [dailyView, dailyDates, deadlineMetrics] = await Promise.all([
      dailyService.getDailyView(today),
      dailyService.getDailyDates(),
      DeadlineAnalyticsService.getDeadlineMetrics().catch(() => null) // Graceful fallback
    ]);

    return (
      <DailyPageClient 
        initialDailyView={dailyView}
        initialDailyDates={dailyDates}
        initialDate={today}
        initialDeadlineMetrics={deadlineMetrics}
      />
    );
  } catch (error) {
    console.error('Erreur SSR Daily:', error);
    // Fallback vers client-side rendering
    return <DailyPageClient />;
  }
}
