<?php use App\Core\Csrf; ?>
<section class="page-intro"><div><span class="page-kicker">Identités externes</span><h2>Comptes portail</h2><p>Gérez les accès Famille séparément des comptes internes du CDA.</p></div><a class="button button-secondary" href="/public/clients">Retour aux adhérents</a></section>
<form method="get" action="/public/administration/comptes-portail" class="form-card" style="margin-bottom:18px"><div class="form-grid grid-4"><label class="field" style="grid-column:span 3"><span>Rechercher</span><input name="q" value="<?= htmlspecialchars((string)$query,ENT_QUOTES,'UTF-8') ?>" placeholder="Nom, e-mail, code adhérent ou famille"></label><div style="align-self:end"><button class="button button-primary">Rechercher</button></div></div></form>
<section class="form-card"><header class="form-card-header"><div class="form-step blue">🔐</div><div><h3>Accès externes</h3><p><?= count($accounts) ?> compte(s) portail.</p></div></header><div style="overflow:auto"><table class="data-table"><thead><tr><th>Personne</th><th>E-mail</th><th>Dossier</th><th>Statut</th><th>Dernière connexion</th><th>Actions</th></tr></thead><tbody>
<?php foreach($accounts as $a): ?><tr><td><strong><?= htmlspecialchars((string)$a['prenom'].' '.(string)$a['nom']) ?></strong><br><small><?= htmlspecialchars((string)$a['account_type']) ?></small></td><td><?= htmlspecialchars((string)$a['email']) ?></td><td><?= htmlspecialchars((string)($a['code_client']?:$a['reference_famille'])) ?></td><td><span class="badge"><?= htmlspecialchars((string)$a['status']) ?></span></td><td><?= htmlspecialchars((string)($a['derniere_connexion_at']?:'Jamais')) ?></td><td><form method="post" action="/public/administration/comptes-portail/invitation" style="display:inline"><?= Csrf::field() ?><input type="hidden" name="account_id" value="<?= (int)$a['id'] ?>"><button class="button button-secondary" type="submit">Renvoyer le lien</button></form> <?php if($a['status']==='active'): ?><form method="post" action="/public/administration/comptes-portail/statut" style="display:inline"><?= Csrf::field() ?><input type="hidden" name="account_id" value="<?= (int)$a['id'] ?>"><input type="hidden" name="status" value="suspended"><button class="button button-danger" type="submit">Suspendre</button></form><?php else: ?><form method="post" action="/public/administration/comptes-portail/statut" style="display:inline"><?= Csrf::field() ?><input type="hidden" name="account_id" value="<?= (int)$a['id'] ?>"><input type="hidden" name="status" value="active"><button class="button button-primary" type="submit">Réactiver</button></form><?php endif; ?></td></tr><?php endforeach; ?>
<?php if(!$accounts): ?><tr><td colspan="6">Aucun compte portail.</td></tr><?php endif; ?></tbody></table></div></section>
