<?php $packages=is_array($repairPackages??null)?$repairPackages:[]; $diagnostics=is_array($repairDiagnostics??null)?$repairDiagnostics:[]; ?>
<style>
.ax-repair{max-width:1500px;margin:0 auto;padding:24px}.ax-head,.ax-card{background:#fff;border:1px solid #dbe4ef;border-radius:18px;box-shadow:0 12px 32px rgba(15,23,42,.06)}.ax-head{padding:24px;margin-bottom:18px}.ax-grid{display:grid;grid-template-columns:minmax(320px,440px) 1fr;gap:18px}.ax-card{padding:20px}.ax-actions{display:flex;gap:10px;flex-wrap:wrap}.ax-btn{border:0;border-radius:10px;padding:11px 16px;font-weight:700;cursor:pointer}.ax-primary{background:#0b57d0;color:#fff}.ax-secondary{background:#eef4ff;color:#174ea6}.ax-danger{background:#b42318;color:#fff}.ax-table{width:100%;border-collapse:collapse}.ax-table th,.ax-table td{padding:11px;border-bottom:1px solid #e6edf5;text-align:left;font-size:14px}.ax-badge{display:inline-flex;border-radius:999px;padding:4px 9px;font-weight:700;font-size:12px;background:#eef2f7}.ax-note{color:#64748b}.ax-nav{display:flex;gap:8px;flex-wrap:wrap;margin-top:14px}.ax-nav a{padding:8px 12px;border-radius:999px;background:#eef4ff;text-decoration:none;color:#174ea6;font-weight:700}@media(max-width:900px){.ax-grid{grid-template-columns:1fr}.ax-repair{padding:14px}.ax-table{display:block;overflow:auto}}
</style>
<div class="ax-repair">
 <section class="ax-head"><div class="ax-badge">PLATFORM-023.3.3 · AXIOM 10.2.2</div><h1>Repair & Recovery Engine</h1><p class="ax-note">Diagnostiquer un package depuis son archive signée d’origine, simuler la réparation, puis restaurer uniquement les fichiers absents ou altérés avec rollback automatique.</p><nav class="ax-nav"><a href="<?= APP_URL ?>/administration/plateforme/packages">Package Manager</a><a href="<?= APP_URL ?>/administration/plateforme/packages/dependances">Dépendances</a><a href="<?= APP_URL ?>/studio/updates">Centre de mises à jour</a></nav></section>
 <div class="ax-grid">
  <section class="ax-card"><h2>Nouveau diagnostic</h2>
   <?php if(!$packages): ?><p class="ax-note">Aucun package installé n’est disponible.</p><?php else: ?>
   <form method="post" action="<?= APP_URL ?>/administration/plateforme/packages/reparation/diagnostiquer">
    <input type="hidden" name="_csrf" value="<?= htmlspecialchars(\App\Core\Csrf::token(),ENT_QUOTES) ?>">
    <label>Package</label><select name="registry_id" required style="width:100%;padding:11px;margin:8px 0 14px;border:1px solid #cbd5e1;border-radius:10px">
     <?php foreach($packages as $p): ?><option value="<?= (int)$p['id'] ?>"><?= htmlspecialchars((string)$p['package_name']) ?> · <?= htmlspecialchars((string)$p['version']) ?> · <?= htmlspecialchars((string)$p['package_status']) ?></option><?php endforeach; ?>
    </select><button class="ax-btn ax-primary">Lancer le diagnostic</button>
   </form><hr style="border:0;border-top:1px solid #e6edf5;margin:22px 0">
   <form method="post" action="<?= APP_URL ?>/administration/plateforme/packages/reparation/executer">
    <input type="hidden" name="_csrf" value="<?= htmlspecialchars(\App\Core\Csrf::token(),ENT_QUOTES) ?>">
    <label>Package</label><select name="registry_id" required style="width:100%;padding:11px;margin:8px 0 14px;border:1px solid #cbd5e1;border-radius:10px">
     <?php foreach($packages as $p): ?><option value="<?= (int)$p['id'] ?>"><?= htmlspecialchars((string)$p['package_name']) ?> · <?= htmlspecialchars((string)$p['version']) ?></option><?php endforeach; ?>
    </select><div class="ax-actions"><button name="mode" value="simulate" class="ax-btn ax-secondary">Simuler la réparation</button><button name="mode" value="repair" class="ax-btn ax-danger" onclick="return confirm('Créer la sauvegarde locale puis restaurer les fichiers altérés ?')">Réparer maintenant</button></div>
   </form><?php endif; ?>
  </section>
  <section class="ax-card"><h2>Derniers diagnostics</h2><table class="ax-table"><thead><tr><th>Package</th><th>État</th><th>Score</th><th>Contrôlés</th><th>Absents</th><th>Modifiés</th><th>Date</th></tr></thead><tbody>
   <?php if(!$diagnostics): ?><tr><td colspan="7" class="ax-note">Aucun diagnostic.</td></tr><?php endif; ?>
   <?php foreach($diagnostics as $d): ?><tr><td><?= htmlspecialchars((string)$d['package_name']) ?><br><small><?= htmlspecialchars((string)$d['version']) ?></small></td><td><span class="ax-badge"><?= htmlspecialchars((string)$d['health_state']) ?></span></td><td><?= (int)$d['health_score'] ?>/100</td><td><?= (int)$d['checked_files'] ?></td><td><?= (int)$d['missing_files'] ?></td><td><?= (int)$d['modified_files'] ?></td><td><?= htmlspecialchars((string)$d['created_at']) ?></td></tr><?php endforeach; ?>
  </tbody></table></section>
 </div>
</div>
