<?php ob_start(); ?>

<div class="max-w-4xl">
    <div class="bg-white rounded-xl shadow-sm border border-gray-100">
        <div class="p-6 border-b border-gray-100">
            <h3 class="text-lg font-semibold text-gray-800">
                <i class="fas fa-cog mr-2 text-indigo-600"></i>Paramètres
            </h3>
        </div>
        
        <form action="<?= BASE_URL ?>/admin/parametres/update" method="POST" class="p-6">
            <input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
            
            <?php $config = json_decode($entreprise['widget_config'] ?? '{}', true); ?>
            
            <div class="space-y-8">
                <div>
                    <h4 class="text-md font-medium text-gray-700 mb-4 pb-2 border-b">
                        <i class="fas fa-palette mr-2"></i>Widget Chat
                    </h4>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Couleur principale</label>
                            <input type="color" name="couleur_primaire" value="<?= $config['couleur_primaire'] ?? '#4F46E5' ?>"
                                   class="w-full h-10 border border-gray-300 rounded-lg cursor-pointer">
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Position du widget</label>
                            <select name="position" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                                <option value="right" <?= ($config['position'] ?? 'right') === 'right' ? 'selected' : '' ?>>Droite</option>
                                <option value="left" <?= ($config['position'] ?? '') === 'left' ? 'selected' : '' ?>>Gauche</option>
                            </select>
                        </div>
                        
                        <div class="md:col-span-2">
                            <label class="block text-sm font-medium text-gray-700 mb-2">Message de bienvenue</label>
                            <textarea name="message_bienvenue" rows="3"
                                      class="w-full px-4 py-2 border border-gray-300 rounded-lg"><?= htmlspecialchars($config['message_bienvenue'] ?? 'Bonjour! Comment puis-je vous aider?') ?></textarea>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h4 class="text-md font-medium text-gray-700 mb-4 pb-2 border-b">
                        <i class="fas fa-code mr-2"></i>Intégration
                    </h4>
                    
                    <div class="bg-gray-50 rounded-lg p-4">
                        <p class="text-sm text-gray-600 mb-2">Token du widget:</p>
                        <code class="block bg-white px-4 py-2 rounded border text-sm"><?= $entreprise['widget_token'] ?></code>
                        
                        <p class="text-sm text-gray-600 mt-4 mb-2">URL du widget:</p>
                        <code class="block bg-white px-4 py-2 rounded border text-sm break-all"><?= BASE_URL ?>/widget/<?= $entreprise['widget_token'] ?></code>
                    </div>
                </div>
            </div>
            
            <div class="mt-8 flex justify-end">
                <button type="submit" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition">
                    <i class="fas fa-save mr-2"></i>Enregistrer
                </button>
            </div>
        </form>
    </div>
    
    <div class="mt-6 bg-white rounded-xl shadow-sm border border-gray-100 p-6">
        <h4 class="font-medium text-gray-800 mb-4"><i class="fas fa-language mr-2"></i>Langues activées</h4>
        <?php $languesActives = json_decode($entreprise['langues_actives'] ?? '["fr"]', true); ?>
        <div class="flex flex-wrap gap-2">
            <?php foreach ($languesActives as $code): ?>
                <span class="px-3 py-1 bg-indigo-100 text-indigo-700 rounded-full text-sm">
                    <?= $langues[$code] ?? $code ?>
                </span>
            <?php endforeach; ?>
        </div>
        <p class="text-xs text-gray-500 mt-3">Pour modifier les langues, contactez l'administrateur de la plateforme.</p>
    </div>
</div>

<?php 
$content = ob_get_clean();
$title = 'Paramètres - ' . APP_NAME;
$pageTitle = 'Paramètres';
include VIEWS_PATH . '/layouts/main.php';
?>
