import { tasksService } from '@/services/task-management/tasks';
import { tagsService } from '@/services/task-management/tags';
import { backupService } from '@/services/data-management/backup';
import { backupScheduler } from '@/services/data-management/backup-scheduler';
import { AdvancedSettingsPageClient } from '@/components/settings/AdvancedSettingsPageClient';

// Force dynamic rendering for real-time data
export const dynamic = 'force-dynamic';

export default async function AdvancedSettingsPage() {
  // Fetch all data server-side
  const [taskStats, tags] = await Promise.all([
    tasksService.getTaskStats(),
    tagsService.getTags()
  ]);

  // Compose backup data like the API does
  const backups = await backupService.listBackups();
  const schedulerStatus = backupScheduler.getStatus();
  const config = backupService.getConfig();
  
  const backupData = {
    backups,
    scheduler: {
      ...schedulerStatus,
      nextBackup: schedulerStatus.nextBackup?.toISOString() || null
    },
    config
  };

  const dbStats = {
    taskCount: taskStats.total,
    tagCount: tags.length,
    completionRate: taskStats.completionRate
  };

  return (
    <AdvancedSettingsPageClient 
      initialDbStats={dbStats}
      initialBackupData={backupData}
    />
  );
}
