<?php
$packages=is_array($dependencyPackages??null)?$dependencyPackages:[];$selected=is_array($dependencySelected??null)?$dependencySelected:null;$metrics=is_array($dependencyMetrics??null)?$dependencyMetrics:[];$graph=is_array($dependencyGraph??null)?$dependencyGraph:[];$h=static fn($v):string=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');
$badge=static fn(string $d):string=>match($d){'RESOLVED'=>'ok','WARNING'=>'warn','INCOMPATIBLE'=>'bad',default=>'info'};
?>
<style>
.dep{display:grid;gap:18px}.dep *{box-sizing:border-box}.dep-hero{border-radius:24px;padding:26px;background:linear-gradient(135deg,#10223c,#1c4f79 58%,#2671a8);color:#fff;display:flex;justify-content:space-between;gap:20px;align-items:center;box-shadow:0 18px 44px rgba(15,43,70,.18)}.dep-hero h1{margin:5px 0 8px;font-size:clamp(28px,4vw,42px)}.dep-hero p{margin:0;color:#dbeafe}.dep-actions{display:flex;gap:9px;flex-wrap:wrap}.dep-btn{border:1px solid #cbd8e6;border-radius:11px;background:#fff;color:#1c4e77;padding:10px 14px;font-weight:800;text-decoration:none;cursor:pointer;display:inline-flex}.dep-btn.primary{background:#1f67a2;border-color:#1f67a2;color:#fff}.dep-btn.ghost{background:rgba(255,255,255,.1);border-color:rgba(255,255,255,.35);color:#fff}.dep-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px}.dep-card{background:#fff;border:1px solid #dbe5ef;border-radius:18px;padding:18px;box-shadow:0 8px 26px rgba(23,50,77,.055)}.dep-kpi small{color:#64748b}.dep-kpi strong{display:block;font-size:30px;color:#173b5a;margin-top:4px}.dep-layout{display:grid;grid-template-columns:minmax(300px,.8fr) minmax(0,1.2fr);gap:14px}.dep-list{display:grid;gap:9px;max-height:720px;overflow:auto}.dep-package{display:flex;justify-content:space-between;gap:12px;align-items:center;padding:12px;border:1px solid #e1e9f1;border-radius:13px;text-decoration:none;color:#173b5a}.dep-package.active{border-color:#2d76ad;background:#eef7fe}.dep-package small{display:block;color:#64748b}.dep-badge{display:inline-flex;padding:5px 8px;border-radius:999px;font-size:11px;font-weight:900}.dep-badge.ok{background:#dcfce7;color:#166534}.dep-badge.warn{background:#fef3c7;color:#92400e}.dep-badge.bad{background:#fee2e2;color:#991b1b}.dep-badge.info{background:#e0f2fe;color:#075985}.dep-table-wrap{overflow:auto}.dep-table{width:100%;border-collapse:collapse;min-width:660px}.dep-table th,.dep-table td{padding:10px;border-bottom:1px solid #e6edf4;text-align:left}.dep-table th{font-size:11px;text-transform:uppercase;color:#64748b}.dep-plan{display:grid;gap:8px;counter-reset:step}.dep-step{display:flex;gap:11px;align-items:center;padding:11px;background:#f7f9fc;border-radius:12px}.dep-step:before{counter-increment:step;content:counter(step);width:28px;height:28px;border-radius:50%;background:#1f67a2;color:#fff;display:grid;place-items:center;font-weight:900}.dep-empty{text-align:center;color:#64748b;padding:32px}@media(max-width:900px){.dep-hero{align-items:flex-start;flex-direction:column}.dep-layout{grid-template-columns:1fr}}
</style>
<div class="dep">
<section class="dep-hero"><div><small>PLATFORM-023.3.2 · AXIOM 10.2.1</small><h1>Dependency Resolver</h1><p>Analyse des dépendances, conflits, cycles et ordre d’installation des packages AXIOM.</p></div><div class="dep-actions"><a class="dep-btn ghost" href="/public/administration/plateforme/packages">Package Manager</a><a class="dep-btn ghost" href="/public/administration/plateforme/compatibilite-packages">Compatibility Engine</a></div></section>
<div class="dep-grid"><?php foreach(['packages'=>'Packages','relations'=>'Relations','resolved'=>'Résolus','warnings'=>'Vigilances','incompatible'=>'Incompatibles','cycles'=>'Cycles'] as $k=>$l): ?><article class="dep-card dep-kpi"><small><?= $h($l) ?></small><strong><?= (int)($metrics[$k]??0) ?></strong></article><?php endforeach; ?></div>
<section class="dep-layout"><aside class="dep-card"><h2>Registre des packages</h2><div class="dep-list"><?php foreach($packages as $p): $d=(string)($p['dependency_decision']??'NON_ANALYSE'); ?><a class="dep-package <?= $selected&&(int)$selected['id']===(int)$p['id']?'active':'' ?>" href="?package_id=<?= (int)$p['id'] ?>"><div><strong><?= $h($p['package_name']) ?></strong><small><?= $h($p['version']) ?> · <?= (int)$p['required_dependencies'] ?> dépendance(s)</small></div><span class="dep-badge <?= $badge($d) ?>"><?= $h($d) ?></span></a><?php endforeach; ?><?php if(!$packages): ?><div class="dep-empty">Aucun package dans le registre.</div><?php endif; ?></div></aside>
<main class="dep-card"><?php if($selected): ?><div style="display:flex;justify-content:space-between;gap:12px;align-items:flex-start"><div><span class="dep-badge info"><?= $h($selected['category']) ?></span><h2 style="margin:8px 0 3px"><?= $h($selected['package_name']) ?></h2><small><?= $h($selected['package_key']) ?> · <?= $h($selected['version']) ?></small></div><form method="post" action="/public/administration/plateforme/packages/dependances/analyser"><input type="hidden" name="_csrf" value="<?= $h(\App\Core\Csrf::token()) ?>"><input type="hidden" name="package_id" value="<?= (int)$selected['id'] ?>"><button class="dep-btn primary">Analyser maintenant</button></form></div>
<?php $analysis=$selected['latest_analysis']??null;if(is_array($analysis)): ?><div class="dep-grid" style="margin-top:15px"><article class="dep-card dep-kpi"><small>Score</small><strong><?= (int)$analysis['score'] ?>/100</strong></article><article class="dep-card dep-kpi"><small>Décision</small><strong style="font-size:20px"><span class="dep-badge <?= $badge((string)$analysis['decision']) ?>"><?= $h($analysis['decision']) ?></span></strong></article><article class="dep-card dep-kpi"><small>Résolues</small><strong><?= (int)$analysis['resolved_count'] ?>/<?= (int)$analysis['required_count'] ?></strong></article></div><?php endif; ?>
<h3>Dépendances déclarées</h3><div class="dep-table-wrap"><table class="dep-table"><thead><tr><th>Type</th><th>Package</th><th>Version min.</th><th>Version max.</th><th>Source</th></tr></thead><tbody><?php foreach((array)$selected['dependencies'] as $d): ?><tr><td><span class="dep-badge <?= $d['dependency_type']==='CONFLICT'?'bad':($d['dependency_type']==='OPTIONAL'?'warn':'info') ?>"><?= $h($d['dependency_type']) ?></span></td><td><strong><?= $h($d['dependency_key']) ?></strong></td><td><?= $h($d['min_version']??'—') ?></td><td><?= $h($d['max_version']??'—') ?></td><td><?= $h($d['source']) ?></td></tr><?php endforeach; ?><?php if(empty($selected['dependencies'])):?><tr><td colspan="5">Aucune dépendance déclarée dans le manifeste disponible.</td></tr><?php endif; ?></tbody></table></div>
<h3>Plan d’installation calculé</h3><div class="dep-plan"><?php foreach((array)(($selected['plan']['steps']??[])) as $step): ?><div class="dep-step"><div><strong><?= $h($step['package_name']) ?></strong><br><small><?= $h($step['version']) ?> · <?= $h($step['status']) ?></small></div></div><?php endforeach; ?><?php if(empty($selected['plan']['steps'])):?><div class="dep-empty">Aucun plan disponible.</div><?php endif; ?></div>
<h3>Packages dépendants</h3><div class="dep-table-wrap"><table class="dep-table"><thead><tr><th>Package</th><th>Version</th><th>Type</th><th>État</th></tr></thead><tbody><?php foreach((array)$selected['dependents'] as $d): ?><tr><td><?= $h($d['package_name']) ?></td><td><?= $h($d['version']) ?></td><td><?= $h($d['dependency_type']) ?></td><td><?= $h($d['package_status']) ?></td></tr><?php endforeach; ?><?php if(empty($selected['dependents'])):?><tr><td colspan="4">Aucun package dépendant.</td></tr><?php endif; ?></tbody></table></div>
<?php else: ?><div class="dep-empty"><h2>Sélectionne un package</h2><p>La fiche affichera les dépendances, les conflits, l’impact et l’ordre d’installation proposé.</p></div><?php endif; ?></main></section>
<section class="dep-card"><h2>Graphe des relations</h2><div class="dep-table-wrap"><table class="dep-table"><thead><tr><th>Package source</th><th>Relation</th><th>Package cible</th></tr></thead><tbody><?php foreach($graph as $edge): ?><tr><td><?= $h($edge['package_name']) ?></td><td><span class="dep-badge info"><?= $h($edge['dependency_type']) ?></span></td><td><?= $h($edge['dependency_key']) ?></td></tr><?php endforeach; ?><?php if(!$graph): ?><tr><td colspan="3">Les manifestes installés ne déclarent encore aucune relation exploitable.</td></tr><?php endif; ?></tbody></table></div><small>Analyse générée le <?= $h($dependencyGeneratedAt??'') ?></small></section>
</div>
