<?php
$packages=$catalogPackages??[];$metrics=$catalogMetrics??[];$categories=$catalogCategories??[];$statuses=$catalogStatuses??[];$filters=$catalogFilters??[];$options=$catalogCompareOptions??[];
$h=static fn($v):string=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');
$badge=static fn(string $s):string=>match(strtoupper($s)){'INSTALLED','SYSTEM'=>'ok','BROKEN','REPAIR_REQUIRED'=>'bad','OBSOLETE'=>'warn',default=>'info'};
?>
<style>
.pcx{display:grid;gap:16px}.pcx-hero{padding:24px;border-radius:22px;background:linear-gradient(135deg,#173b5a,#246f9d);color:#fff;display:flex;justify-content:space-between;gap:18px;align-items:center}.pcx-hero h1{margin:4px 0}.pcx-actions{display:flex;flex-wrap:wrap;gap:8px}.pcx-btn{border:0;border-radius:10px;padding:10px 13px;background:#edf4fa;color:#234e70;font-weight:850;text-decoration:none;cursor:pointer}.pcx-btn.primary{background:#2370aa;color:#fff}.pcx-btn.ghost{background:rgba(255,255,255,.14);color:#fff}.pcx-card{background:#fff;border:1px solid #dbe5ef;border-radius:18px;padding:17px;box-shadow:0 8px 24px rgba(23,50,77,.055)}.pcx-kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:11px}.pcx-kpi small{color:#64748b}.pcx-kpi strong{display:block;font-size:27px;color:#173b5a}.pcx-toolbar{display:grid;grid-template-columns:1.4fr repeat(3,.55fr) auto;gap:9px;align-items:end}.pcx-toolbar label{display:block;font-size:11px;font-weight:850;color:#52677a;margin-bottom:5px}.pcx-toolbar input,.pcx-toolbar select{width:100%;padding:10px;border:1px solid #ccd9e6;border-radius:10px}.pcx-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(290px,1fr));gap:13px}.pcx-package{display:grid;gap:12px}.pcx-head{display:flex;justify-content:space-between;gap:10px}.pcx-title h3{margin:4px 0;color:#173b5a}.pcx-title p{margin:0;color:#64748b;font-size:12px}.pcx-badge{display:inline-flex;padding:5px 8px;border-radius:999px;font-size:10px;font-weight:900}.pcx-badge.ok{background:#dcfce7;color:#166534}.pcx-badge.bad{background:#fee2e2;color:#991b1b}.pcx-badge.warn{background:#fef3c7;color:#92400e}.pcx-badge.info{background:#e0f2fe;color:#075985}.pcx-scores{display:grid;grid-template-columns:1fr 1fr;gap:8px}.pcx-score{background:#f6f9fc;border-radius:11px;padding:9px}.pcx-score span{font-size:10px;color:#64748b;display:block}.pcx-score strong{font-size:18px;color:#173b5a}.pcx-flags{display:flex;gap:7px;flex-wrap:wrap}.pcx-flag{border:1px solid #d6e2ed;background:#fff;border-radius:9px;padding:7px 9px;cursor:pointer}.pcx-flag.active{background:#e7f2fb;border-color:#8db9d8}.pcx-table-wrap{overflow:auto}.pcx-table{width:100%;border-collapse:collapse;min-width:850px}.pcx-table th,.pcx-table td{padding:10px;border-bottom:1px solid #e6edf4;text-align:left}.pcx-table th{font-size:11px;color:#64748b;text-transform:uppercase}.pcx-compare{display:grid;grid-template-columns:1fr 1fr auto;gap:9px;align-items:end}.pcx-empty{text-align:center;padding:30px;color:#64748b}@media(max-width:900px){.pcx-hero{align-items:flex-start;flex-direction:column}.pcx-toolbar,.pcx-compare{grid-template-columns:1fr}}@media(max-width:560px){.pcx-grid{grid-template-columns:1fr}.pcx-kpis{grid-template-columns:repeat(2,1fr)}}
</style>
<div class="pcx">
<section class="pcx-hero"><div><small>PLATFORM-023.3.4 · AXIOM 10.2.3</small><h1>Enterprise Package Catalog</h1><p>Explorez, classez, surveillez et comparez tous les composants de la plateforme.</p></div><div class="pcx-actions"><a class="pcx-btn ghost" href="/public/administration/plateforme/packages">Package Manager</a><a class="pcx-btn ghost" href="/public/administration/plateforme/packages/dependances">Dépendances</a><a class="pcx-btn ghost" href="/public/administration/plateforme/packages/reparation">Réparation</a></div></section>
<div class="pcx-kpis"><?php foreach(['total'=>'Packages','installed'=>'Installés','favorites'=>'Favoris','critical'=>'Critiques','watched'=>'Surveillés','repair'=>'À réparer','trust_average'=>'Trust moyen','compatibility_average'=>'Compatibilité'] as $k=>$l): ?><article class="pcx-card pcx-kpi"><small><?= $h($l) ?></small><strong><?= (int)($metrics[$k]??0) ?><?= str_contains($k,'average')?'/100':'' ?></strong></article><?php endforeach; ?></div>
<section class="pcx-card"><form method="get" class="pcx-toolbar"><div><label>Recherche</label><input name="q" value="<?= $h($filters['q']??'') ?>" placeholder="Nom, UUID, version, éditeur..."></div><div><label>Catégorie</label><select name="category"><option value="">Toutes</option><?php foreach($categories as $c): ?><option value="<?= $h($c) ?>" <?= ($filters['category']??'')===$c?'selected':'' ?>><?= $h($c) ?></option><?php endforeach; ?></select></div><div><label>État</label><select name="status"><option value="">Tous</option><?php foreach($statuses as $s): ?><option value="<?= $h($s) ?>" <?= ($filters['status']??'')===$s?'selected':'' ?>><?= $h($s) ?></option><?php endforeach; ?></select></div><div><label>Marquage</label><select name="flag"><option value="">Tous</option><option value="favorite" <?= ($filters['flag']??'')==='favorite'?'selected':'' ?>>Favoris</option><option value="critical" <?= ($filters['flag']??'')==='critical'?'selected':'' ?>>Critiques</option><option value="watched" <?= ($filters['flag']??'')==='watched'?'selected':'' ?>>Surveillés</option></select></div><button class="pcx-btn primary">Filtrer</button></form><div class="pcx-actions" style="margin-top:10px"><a class="pcx-btn" href="?<?= http_build_query(array_merge($filters,['view'=>'cards'])) ?>">Cartes</a><a class="pcx-btn" href="?<?= http_build_query(array_merge($filters,['view'=>'table'])) ?>">Tableau</a><a class="pcx-btn" href="/public/administration/plateforme/packages/catalogue/export.csv">Exporter CSV</a></div></section>
<section class="pcx-card"><h2>Comparateur</h2><form class="pcx-compare" method="get" action="/public/administration/plateforme/packages/catalogue/comparer"><div><label>Package A</label><select name="left" required><option value="">Sélectionner</option><?php foreach($options as $o): ?><option value="<?= (int)$o['id'] ?>"><?= $h($o['package_name'].' · '.$o['version']) ?></option><?php endforeach; ?></select></div><div><label>Package B</label><select name="right" required><option value="">Sélectionner</option><?php foreach($options as $o): ?><option value="<?= (int)$o['id'] ?>"><?= $h($o['package_name'].' · '.$o['version']) ?></option><?php endforeach; ?></select></div><button class="pcx-btn primary">Comparer</button></form></section>
<section class="pcx-card"><h2>Catalogue</h2><?php if(($filters['view']??'cards')==='table'): ?><div class="pcx-table-wrap"><table class="pcx-table"><thead><tr><th>Package</th><th>Version</th><th>Catégorie</th><th>État</th><th>Trust</th><th>Compatibilité</th><th>Marquages</th></tr></thead><tbody><?php foreach($packages as $p): ?><tr><td><strong><?= $h($p['package_name']) ?></strong><br><small><?= $h($p['publisher']) ?></small></td><td><?= $h($p['version']) ?></td><td><?= $h($p['category']) ?></td><td><span class="pcx-badge <?= $badge((string)$p['package_status']) ?>"><?= $h($p['package_status']) ?></span></td><td><?= $h($p['trust_score']??'—') ?></td><td><?= $h($p['compatibility_score']??'—') ?></td><td><?= (int)$p['is_favorite']?'⭐ ':'' ?><?= (int)$p['is_critical']?'🔥 ':'' ?><?= (int)$p['is_watched']?'👁 ':'' ?></td></tr><?php endforeach; ?></tbody></table></div><?php else: ?><div class="pcx-grid"><?php foreach($packages as $p): ?><article class="pcx-card pcx-package"><div class="pcx-head"><div class="pcx-title"><span class="pcx-badge info"><?= $h($p['category']) ?></span><h3><?= $h($p['package_name']) ?></h3><p><?= $h($p['publisher']) ?> · <?= $h($p['version']) ?></p></div><span class="pcx-badge <?= $badge((string)$p['package_status']) ?>"><?= $h($p['package_status']) ?></span></div><div class="pcx-scores"><div class="pcx-score"><span>Trust</span><strong><?= $h($p['trust_score']??'—') ?></strong></div><div class="pcx-score"><span>Compatibilité</span><strong><?= $h($p['compatibility_score']??'—') ?></strong></div></div><p><?= $h($p['description']?:'Composant AXIOM administré par l’Enterprise Package Manager.') ?></p><div class="pcx-flags"><?php foreach(['favorite'=>'⭐ Favori','critical'=>'🔥 Critique','watched'=>'👁 Surveillé'] as $f=>$label): $active=(int)$p['is_'.$f]===1; ?><form method="post" action="/public/administration/plateforme/packages/catalogue/preference"><input type="hidden" name="_csrf" value="<?= $h(\App\Core\Csrf::token()) ?>"><input type="hidden" name="registry_id" value="<?= (int)$p['id'] ?>"><input type="hidden" name="flag" value="<?= $h($f) ?>"><button class="pcx-flag <?= $active?'active':'' ?>" type="submit"><?= $h($label) ?></button></form><?php endforeach; ?></div></article><?php endforeach; ?><?php if(!$packages): ?><div class="pcx-empty">Aucun package ne correspond aux filtres.</div><?php endif; ?></div><?php endif; ?></section>
</div>
