<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h1 class="darlink-title mb-1">
            <i class="bi bi-people me-2"></i>Types de clients
        </h1>
        <p class="text-muted mb-0">Ajouter, modifier ou désactiver les catégories de clients.</p>
    </div>

    <a href="index.php?page=parametres_societe" class="btn btn-outline-secondary">
        <i class="bi bi-arrow-left me-1"></i> Paramètres
    </a>
</div>

<div class="darlink-card darlink-form-card mb-4">
    <div class="darlink-form-header">
        <h2 class="h5 mb-0">Nouveau type de client</h2>
    </div>

    <form method="post" action="index.php?page=parametres_types_clients_store">
        <div class="darlink-form-body">
            <div class="row g-3 align-items-end">
                <div class="col-md-8 darlink-form-group mb-0">
                    <label class="darlink-label">Libellé</label>
                    <input name="libelle" class="darlink-input" placeholder="Ex. Hôtel, Restaurant, Clinique..." required>
                </div>

                <div class="col-md-4">
                    <button type="submit" class="btn darlink-btn-primary">
                        <i class="bi bi-plus-lg me-1"></i> Ajouter
                    </button>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="darlink-card darlink-table-card">
    <div class="darlink-table-toolbar">
        <div class="darlink-table-toolbar-left">
            <strong>Liste des types de clients</strong>
        </div>
    </div>

    <div class="table-responsive darlink-table-wrapper">
        <table class="table align-middle darlink-table darlink-table-modern">
            <thead>
            <tr>
                <th>Libellé</th>
                <th>État</th>
                <th class="text-end">Actions</th>
            </tr>
            </thead>
            <tbody>
            <?php if (empty($typesClients)): ?>
                <tr>
                    <td colspan="3" class="text-center text-muted py-5">
                        Aucun type de client enregistré.
                    </td>
                </tr>
            <?php endif; ?>

            <?php foreach ($typesClients as $type): ?>
                <tr>
                    <td>
                        <form method="post" action="index.php?page=parametres_types_clients_update" class="d-flex gap-2">
                            <input type="hidden" name="id" value="<?= (int)$type['id'] ?>">
                            <input name="libelle" class="darlink-input" value="<?= htmlspecialchars($type['libelle']) ?>">
                    </td>

                    <td>
                        <select name="actif" class="darlink-select">
                            <option value="1" <?= (int)$type['actif'] === 1 ? 'selected' : '' ?>>Actif</option>
                            <option value="0" <?= (int)$type['actif'] === 0 ? 'selected' : '' ?>>Inactif</option>
                        </select>
                    </td>

                    <td class="text-end darlink-actions">
                            <button type="submit" class="darlink-icon-btn darlink-icon-btn-edit" title="Enregistrer">
                                <i class="bi bi-check-lg"></i>
                            </button>
                        </form>

                        <form method="post"
                              action="index.php?page=parametres_types_clients_delete"
                              class="d-inline"
                              onsubmit="return confirm('Désactiver ce type de client ?');">
                            <input type="hidden" name="id" value="<?= (int)$type['id'] ?>">
                            <button type="submit" class="darlink-icon-btn darlink-icon-btn-delete" title="Désactiver">
                                <i class="bi bi-trash"></i>
                            </button>
                        </form>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>