import { getTranslations } from 'next-intl/server';
import { Link } from '@/i18n/navigation';
import { Card, CardContent } from '@/components/ui/card';
import { CreditCard } from 'lucide-react';

export default async function LettreCreditPage() {
  const t = await getTranslations('dashboard.wikiPages');

  const types = t.raw('lettreCredit.types') as Array<{ name: string; description: string }>;
  const parties = t.raw('lettreCredit.parties') as Array<{ role: string; description: string }>;
  const documents = t.raw('lettreCredit.documents') as Array<{ name: string; description: string }>;
  const errors = t.raw('lettreCredit.errors') as string[];
  const datesItems = t.raw('lettreCredit.datesItems') as Array<{
    label: string;
    description: string;
  }>;
  const costsItems = t.raw('lettreCredit.costsItems') as Array<{
    label: string;
    description: string;
  }>;

  return (
    <div className="space-y-6">
      <div className="flex items-center gap-4 mb-6">
        <Link
          href="/dashboard/wiki"
          className="flex items-center text-blue-600 hover:text-blue-800 transition-colors"
        >
          <svg className="w-5 h-5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path
              strokeLinecap="round"
              strokeLinejoin="round"
              strokeWidth={2}
              d="M15 19l-7-7 7-7"
            />
          </svg>
          {t('backToWiki')}
        </Link>
      </div>

      <div className="mb-8">
        <div className="flex items-center gap-3">
          <CreditCard className="w-10 h-10 text-blue-600" />
          <h1 className="text-3xl font-bold text-gray-900">{t('lettreCredit.title')}</h1>
        </div>
        <p className="mt-3 text-gray-600 max-w-3xl">{t('lettreCredit.description')}</p>
      </div>

      <div className="mt-8">
        <h2 className="text-xl font-bold text-gray-900 mb-4">{t('lettreCredit.typesTitle')}</h2>
        <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
          {types.map(type => (
            <Card key={type.name} className="bg-white">
              <CardContent className="pt-4">
                <h4 className="font-semibold text-gray-900">{type.name}</h4>
                <p className="text-sm text-gray-600 mt-1">{type.description}</p>
              </CardContent>
            </Card>
          ))}
        </div>
      </div>

      <div className="mt-8">
        <h2 className="text-xl font-bold text-gray-900 mb-4">{t('lettreCredit.partiesTitle')}</h2>
        <div className="overflow-x-auto">
          <table className="w-full text-sm bg-white rounded-lg border">
            <thead className="bg-gray-50">
              <tr>
                <th className="text-left p-3 font-medium">{t('lettreCredit.colRole')}</th>
                <th className="text-left p-3 font-medium">Description</th>
              </tr>
            </thead>
            <tbody>
              {parties.map(p => (
                <tr key={p.role} className="border-t hover:bg-gray-50">
                  <td className="p-3 font-medium text-blue-700">{p.role}</td>
                  <td className="p-3 text-gray-600">{p.description}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>

      <div className="mt-8">
        <h2 className="text-xl font-bold text-gray-900 mb-4">{t('lettreCredit.documentsTitle')}</h2>
        <div className="space-y-3">
          {documents.map(doc => (
            <div key={doc.name} className="flex items-start gap-3 bg-white p-4 rounded-lg border">
              <span className="text-green-500 mt-0.5 flex-shrink-0">✓</span>
              <div>
                <span className="font-medium text-gray-900">{doc.name}</span>
                <span className="text-sm text-gray-500 ml-2">— {doc.description}</span>
              </div>
            </div>
          ))}
        </div>
      </div>

      <Card className="mt-8 bg-red-50 border-red-200">
        <CardContent className="pt-6">
          <h3 className="font-semibold text-red-900 mb-3">{t('lettreCredit.errorsTitle')}</h3>
          <ul className="space-y-2">
            {errors.map((err, i) => (
              <li key={i} className="flex items-start gap-2 text-sm text-red-800">
                <span className="text-red-500 mt-0.5 flex-shrink-0">⚠</span> {err}
              </li>
            ))}
          </ul>
        </CardContent>
      </Card>

      <Card className="mt-4 bg-blue-50 border-blue-200">
        <CardContent className="pt-6">
          <h3 className="font-semibold text-blue-900 mb-2">{t('lettreCredit.ucp600Title')}</h3>
          <p className="text-sm text-blue-800">{t('lettreCredit.ucp600Content')}</p>
        </CardContent>
      </Card>

      <div className="grid grid-cols-1 md:grid-cols-2 gap-6 mt-8">
        <Card className="bg-white">
          <CardContent className="pt-6">
            <h3 className="font-semibold text-gray-900 mb-3">{t('lettreCredit.datesTitle')}</h3>
            <div className="space-y-3">
              {datesItems.map(item => (
                <div key={item.label}>
                  <span className="font-medium text-gray-800 text-sm">{item.label}</span>
                  <p className="text-xs text-gray-600 mt-0.5">{item.description}</p>
                </div>
              ))}
            </div>
          </CardContent>
        </Card>
        <Card className="bg-white">
          <CardContent className="pt-6">
            <h3 className="font-semibold text-gray-900 mb-3">{t('lettreCredit.costsTitle')}</h3>
            <div className="space-y-3">
              {costsItems.map(item => (
                <div key={item.label}>
                  <span className="font-medium text-gray-800 text-sm">{item.label}</span>
                  <p className="text-xs text-gray-600 mt-0.5">{item.description}</p>
                </div>
              ))}
            </div>
          </CardContent>
        </Card>
      </div>
    </div>
  );
}
