import React from 'react';
import { getLegalDocument } from '@/lib/legal';

import { getSiteSettings } from '@/lib/settings';
import { Metadata } from 'next';

export async function generateMetadata(): Promise<Metadata> {
  const settings = await getSiteSettings();
  return {
    title: `Conditions Générales d'Utilisation - ${settings.siteName}`,
    description: `Consultez les conditions générales d'utilisation de la plateforme ${settings.siteName}.`,
  };
}

export default async function CGUPage() {
  const doc = await getLegalDocument('CGU');

  if (!doc) {
    return (
      <div className="bg-white min-h-screen py-16 px-4 flex items-center justify-center">
        <p className="text-gray-500">Document non disponible.</p>
      </div>
    );
  }

  return (
    <div className="bg-white min-h-screen py-16 px-4 sm:px-6 lg:px-8">
      <div className="max-w-3xl mx-auto">
        <h1 className="text-3xl font-serif font-bold text-gray-900 mb-8 border-b pb-4">
          {doc.title}
        </h1>
        
        <div 
          className="prose prose-orange max-w-none text-gray-600 space-y-6"
          dangerouslySetInnerHTML={{ __html: doc.content }}
        />

        <div className="mt-12 pt-8 border-t border-gray-100 text-xs text-gray-400">
           Dernière mise à jour : {new Date(doc.updatedAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'long', year: 'numeric' })}
        </div>
      </div>
    </div>
  );
}
