<?php use App\Core\Csrf; ?>
<link rel="stylesheet" href="/public/assets/css/axiom-ui.css">
<link rel="stylesheet" href="/public/assets/css/axiom-identity.css">
<main class="axiom-identity">
  <div class="axiom-page-nav"><div class="axiom-page-nav__trail"><a href="/public/administration/axiom">AXIOM Studio</a><span>›</span><strong>Identity Engine</strong></div><div class="axiom-page-nav__actions"><a class="axiom-btn-back" href="/public/administration/axiom">← Retour à AXIOM Studio</a></div></div>
  <header class="identity-hero">
    <div><span class="identity-kicker">REGISTRE CENTRAL</span><h2>AXIOM Identity Engine</h2><p>Une seule identité, plusieurs rôles et relations, sans doublons.</p></div>
    <div class="identity-actions"><a class="btn-back" href="/public/administration/axiom">← Retour</a><a class="btn-primary" href="/public/administration/axiom/identites/nouveau">＋ Nouvelle identité</a></div>
  </header>
  <section class="identity-kpis">
    <article><span>Total actif</span><strong><?= (int)$stats['total'] ?></strong></article><article><span>Personnes</span><strong><?= (int)$stats['personnes'] ?></strong></article><article><span>Organisations</span><strong><?= (int)$stats['organisations'] ?></strong></article><article><span>Rôles actifs</span><strong><?= (int)$stats['roles'] ?></strong></article>
  </section>
  <form class="identity-search" method="get"><input name="q" value="<?= htmlspecialchars($q) ?>" placeholder="Nom, prénom, organisation ou identifiant…"><select name="type"><option value="">Tous les types</option><option value="personne" <?= $type==='personne'?'selected':'' ?>>Personnes</option><option value="organisation" <?= $type==='organisation'?'selected':'' ?>>Organisations</option></select><button>Rechercher</button></form>
  <section class="identity-panel"><div class="identity-panel-head"><h3>Registre des identités</h3><span><?= count($identities) ?> résultat(s)</span></div>
    <div class="identity-table-wrap"><table><thead><tr><th>Identité</th><th>Type</th><th>Rôles</th><th>Identifiant</th><th>Action</th></tr></thead><tbody>
    <?php foreach($identities as $i): ?><tr><td><strong><?= htmlspecialchars((string)($i['raison_sociale'] ?: trim(($i['nom']??'').' '.($i['prenom']??'')))) ?></strong></td><td><span class="identity-badge"><?= htmlspecialchars((string)$i['type_identite']) ?></span></td><td><?= htmlspecialchars((string)($i['roles']??'—')) ?></td><td><?= htmlspecialchars((string)($i['identifiant_externe']??'—')) ?></td><td><a class="btn-small" href="/public/administration/axiom/identites/voir?id=<?= (int)$i['id'] ?>">Voir</a></td></tr><?php endforeach; ?>
    <?php if(!$identities): ?><tr><td colspan="5" class="identity-empty">Aucune identité enregistrée.</td></tr><?php endif; ?>
    </tbody></table></div>
  </section>
</main>
