<?php ob_start(); ?>

<div class="max-w-2xl mx-auto">
    <div class="mb-6">
        <a href="<?= BASE_URL ?>/admin/ia" class="inline-flex items-center text-slate-600 hover:text-cyan-600 transition">
            <i class="fas fa-arrow-left mr-2"></i>Retour à la configuration IA
        </a>
    </div>

    <div class="bg-white rounded-2xl border border-slate-200 overflow-hidden">
        <div class="p-6 border-b border-slate-100 bg-gradient-to-r from-slate-50 to-white">
            <div class="flex items-center">
                <div class="w-12 h-12 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-xl flex items-center justify-center mr-4">
                    <i class="fas fa-edit text-white text-xl"></i>
                </div>
                <div>
                    <h2 class="text-xl font-bold text-slate-800">Modifier la FAQ</h2>
                    <p class="text-sm text-slate-500">Mettez à jour cette question/réponse</p>
                </div>
            </div>
        </div>

        <form action="<?= BASE_URL ?>/admin/ia/faq/<?= $faq['id'] ?>" method="POST" class="p-6">
            <input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">

            <div class="space-y-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        <i class="fas fa-question-circle text-cyan-500 mr-1"></i>Question
                    </label>
                    <input type="text" name="question" required
                           value="<?= htmlspecialchars($faq['question']) ?>"
                           class="w-full px-4 py-3 border border-slate-200 rounded-xl focus:ring-2 focus:ring-cyan-500 focus:border-transparent">
                </div>

                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        <i class="fas fa-reply text-emerald-500 mr-1"></i>Réponse
                    </label>
                    <textarea name="reponse" rows="5" required
                              class="w-full px-4 py-3 border border-slate-200 rounded-xl focus:ring-2 focus:ring-cyan-500 focus:border-transparent"><?= htmlspecialchars($faq['reponse']) ?></textarea>
                </div>

                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">Catégorie</label>
                    <input type="text" name="categorie" 
                           value="<?= htmlspecialchars($faq['categorie'] ?? 'Général') ?>"
                           class="w-full px-4 py-3 border border-slate-200 rounded-xl focus:ring-2 focus:ring-cyan-500 focus:border-transparent">
                </div>

                <div class="flex items-center p-4 bg-slate-50 rounded-xl">
                    <input type="checkbox" name="is_active" id="is_active" value="1"
                           <?= $faq['is_active'] ? 'checked' : '' ?>
                           class="w-5 h-5 text-cyan-600 rounded focus:ring-cyan-500">
                    <label for="is_active" class="ml-3">
                        <span class="font-medium text-slate-700">FAQ active</span>
                        <p class="text-sm text-slate-500">L'IA utilisera cette information pour répondre</p>
                    </label>
                </div>

                <!-- Statistiques -->
                <div class="p-4 bg-blue-50 rounded-xl">
                    <h4 class="font-medium text-blue-800 mb-2"><i class="fas fa-chart-bar mr-2"></i>Statistiques</h4>
                    <div class="grid grid-cols-2 gap-4 text-sm">
                        <div>
                            <span class="text-blue-600">Utilisations:</span>
                            <span class="font-semibold text-blue-800"><?= $faq['views_count'] ?? 0 ?></span>
                        </div>
                        <div>
                            <span class="text-blue-600">Créée le:</span>
                            <span class="font-semibold text-blue-800"><?= date('d/m/Y', strtotime($faq['created_at'])) ?></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="flex items-center justify-between mt-8 pt-6 border-t border-slate-100">
                <form action="<?= BASE_URL ?>/admin/ia/faq/<?= $faq['id'] ?>/delete" method="POST" 
                      onsubmit="return confirm('Êtes-vous sûr de vouloir supprimer cette FAQ ?')">
                    <button type="submit" class="px-4 py-2 text-red-600 hover:bg-red-50 rounded-lg transition">
                        <i class="fas fa-trash mr-2"></i>Supprimer
                    </button>
                </form>
                <div class="flex items-center space-x-4">
                    <a href="<?= BASE_URL ?>/admin/ia" class="px-6 py-3 border border-slate-200 rounded-xl text-slate-600 hover:bg-slate-50 transition">
                        Annuler
                    </a>
                    <button type="submit" class="px-6 py-3 bg-gradient-to-r from-cyan-500 to-emerald-500 hover:from-cyan-600 hover:to-emerald-600 text-white rounded-xl font-medium transition">
                        <i class="fas fa-save mr-2"></i>Enregistrer
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<?php 
$content = ob_get_clean();
$title = 'Modifier FAQ - ' . APP_NAME;
$pageTitle = 'Modifier la FAQ';
include VIEWS_PATH . '/layouts/main.php';
?>
