<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h1 class="darlink-title mb-1">
            <i class="bi bi-tags me-2"></i>Marques
        </h1>
        <p class="text-muted mb-0">
            Ajouter, modifier ou désactiver les marques utilisées pour les articles.
        </p>
    </div>

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

<div class="darlink-card darlink-form-card mb-4">
    <div class="darlink-form-header">
        <h2 class="h5 mb-0">Nouvelle marque</h2>
    </div>

    <form method="post" action="index.php?page=parametres_marques_articles_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. Diversey, Karcher, Nilfisk..."
                        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 marques</strong>
        </div>

        <div class="darlink-table-toolbar-right">
            <span class="text-muted small">
                <?= count($marquesArticles) ?> marque(s)
            </span>
        </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 style="width:180px;">État</th>
                <th class="text-end" style="width:140px;">Actions</th>
            </tr>
            </thead>

            <tbody>
            <?php if (empty($marquesArticles)): ?>
                <tr>
                    <td colspan="3" class="text-center text-muted py-5">
                        Aucune marque enregistrée.
                    </td>
                </tr>
            <?php endif; ?>

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

                            <input
                                name="libelle"
                                class="darlink-input"
                                value="<?= htmlspecialchars($marque['libelle']) ?>"
                                required
                            >
                    </td>

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

                            <option
                                value="0"
                                <?= (int)$marque['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_marques_articles_delete"
                            class="d-inline"
                            onsubmit="return confirm('Désactiver cette marque ?');"
                        >
                            <input
                                type="hidden"
                                name="id"
                                value="<?= (int)$marque['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>