<?php /* admin/views/subsidiaries.php */ ?>

<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success">✅ Filiale mise à jour avec succès.</div>
<?php endif; ?>

<?php if (isset($_GET['deleted'])): ?>
<div class="alert alert-success">🗑 Filiale supprimée avec succès.</div>
<?php endif; ?>

<div class="admin-breadcrumb">
  <a href="/admin">Dashboard</a> / <span>Filiales</span>
</div>

<div class="admin-table-wrap">
  <table class="admin-table">
    <thead>
      <tr>
        <th>Nom (FR)</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody>
      <?php if (empty($subs)): ?>
      <tr>
        <td colspan="2" style="text-align:center;padding:2rem;color:#5e5e5e">Aucune filiale trouvée.</td>
      </tr>
      <?php else: ?>
      <?php foreach ($subs as $s): ?>
      <tr>
        <td style="color:#f0ece4;font-weight:600;"><?= htmlspecialchars($s['name'] ?? 'Sans nom') ?></td>
        <td>
          <a href="/admin/subsidiaries/<?= $s['id'] ?>/edit" class="tbl-action" style="margin-right:1rem;">✏️ Modifier</a>
          
          <form action="/admin/subsidiaries/<?= $s['id'] ?>/delete" method="POST" style="display:inline;">
            <input type="hidden" name="_csrf" value="<?= htmlspecialchars($csrf) ?>">
            <button type="submit" class="tbl-action" style="border:none; background:none; color:#e74c3c; cursor:pointer; padding:0;"
                    onclick="return confirm('⚠️ Attention : Voulez-vous vraiment supprimer « <?= htmlspecialchars($s['name']) ?> » ?');">
              🗑 Supprimer
            </button>
          </form>
        </td>
      </tr>
      <?php endforeach; ?>
      <?php endif; ?>
    </tbody>
  </table>
</div>

<style>
.admin-breadcrumb { margin-bottom:1.5rem;font-size:.82rem;color:#5e5e5e; }
.admin-breadcrumb a { color:#C9A84C; }
.tbl-action { color:#C9A84C;font-size:.82rem;font-weight:600; text-decoration:none; }
.tbl-action:hover { text-decoration:underline; }
.alert { padding:.85rem 1.25rem;margin-bottom:1.5rem;font-size:.88rem; }
.alert-success { background:rgba(39,174,96,.1);border:1px solid rgba(39,174,96,.3);color:#27ae60; }
</style>