<?php $h=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8'); ?>
<link rel="stylesheet" href="/public/assets/css/axiom-studio.css">
<main class="axiom-studio studio-designer-page">
<section class="axiom-studio-hero studio-designer-hero"><div><span class="axiom-studio-kicker">CRUD GENERATOR V1 · 9.4.3</span><h2>Générer une application métier</h2><p>Prévisualisez puis générez un socle MVC, ses vues, ses routes et ses permissions sans modifier automatiquement la production.</p></div><div class="axiom-studio-version"><span>Sortie sécurisée</span><strong>storage/generated</strong></div></section>
<?php if(!empty($_SESSION['flash_success'])):?><div class="studio-alert success"><?= $h($_SESSION['flash_success']); unset($_SESSION['flash_success']); ?></div><?php endif;?>
<?php if(!empty($_SESSION['flash_error'])):?><div class="studio-alert error"><?= $h($_SESSION['flash_error']); unset($_SESSION['flash_error']); ?></div><?php endif;?>
<section class="studio-generator-toolbar"><form method="get" action="/public/administration/axiom/crud-generator"><label>Module<select name="module_id" onchange="this.form.submit()"><?php foreach($modules as $m):?><option value="<?= (int)$m['id'] ?>" <?= (int)$m['id']===$moduleId?'selected':'' ?>><?= $h($m['name']) ?></option><?php endforeach;?></select></label><label>Entité<select name="entity_id" onchange="this.form.submit()"><?php foreach($entities as $e):?><option value="<?= (int)$e['id'] ?>" <?= (int)$e['id']===$entityId?'selected':'' ?>><?= $h($e['name']) ?></option><?php endforeach;?></select></label></form><?php if($preview):?><form method="post" action="/public/administration/axiom/crud-generator/generer"><?= \App\Core\Csrf::field() ?><input type="hidden" name="module_id" value="<?= $moduleId ?>"><input type="hidden" name="entity_id" value="<?= $entityId ?>"><button class="studio-primary">Générer les artefacts</button></form><?php endif;?></section>
<?php if($preview):?><div class="crud-generator-grid"><section class="studio-panel"><div class="studio-panel-head"><div><span class="axiom-studio-kicker">PLAN DE GÉNÉRATION</span><h3><?= $h($preview['entity']['name']) ?></h3><code><?= $h($preview['entity']['table_name']) ?></code></div><span class="type-chip"><?= count($preview['files']) ?> fichiers</span></div><div class="artifact-list"><?php foreach($preview['files'] as $f):?><div><span>✓</span><code><?= $h($f) ?></code></div><?php endforeach;?></div></section><section class="studio-panel"><div class="studio-tabs"><button class="active" data-tab="routes">Routes</button><button data-tab="permissions">Permissions</button><button data-tab="code">Code</button></div><div class="studio-tab active" data-panel="routes"><pre><code><?= $h(json_encode($preview['routes'],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)) ?></code></pre></div><div class="studio-tab" data-panel="permissions"><pre><code><?= $h(json_encode($preview['permissions'],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)) ?></code></pre></div><div class="studio-tab" data-panel="code"><pre><code><?= $h(implode("\n\n/* ——— */\n\n",array_values($preview['snippets']))) ?></code></pre></div></section></div><?php else:?><section class="studio-canvas-empty"><div>⚙</div><h3>Aucun modèle générable</h3><p>Créez une entité et ajoutez au moins un champ métier.</p></section><?php endif;?>
<section class="axiom-studio-section"><div class="axiom-studio-section-head"><h3>Historique de génération</h3></div><div class="generation-history"><?php if(!$history):?><p class="studio-muted">Aucune génération pour ce module.</p><?php endif;?><?php foreach($history as $r):?><article><div><strong><?= $h($r['entity_name']??'Entité supprimée') ?></strong><small><?= $h($r['created_at']) ?> · <?= $h($r['axiom_version']) ?></small></div><span class="feature-state <?= ($r['status']??'')==='completed'?'on':'off' ?>"><?= $h($r['status']) ?></span><code><?= (int)($r['artifact_count']??0) ?> artefacts</code></article><?php endforeach;?></div></section>
</main><script>document.querySelectorAll('.studio-tabs button').forEach(b=>b.addEventListener('click',()=>{const box=b.closest('.studio-panel');box.querySelectorAll('.studio-tabs button').forEach(x=>x.classList.remove('active'));box.querySelectorAll('.studio-tab').forEach(x=>x.classList.remove('active'));b.classList.add('active');box.querySelector('[data-panel="'+b.dataset.tab+'"]').classList.add('active')}));</script>
