<link rel="stylesheet" href="/public/assets/css/axiom-studio.css">
<?php $h=static fn(mixed $v):string=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');$mid=(int)$module['id'];$eid=$entity?(int)$entity['id']:0; ?>
<main class="axiom-studio studio-designer-page"><section class="axiom-studio-hero studio-designer-hero"><div><span class="axiom-studio-kicker">FORM DESIGNER 1.0</span><h2><?= $h($module['name']) ?></h2><p>Composez un formulaire responsive à partir du modèle de données.</p></div><div class="studio-actions"><a href="/public/administration/axiom/entity-designer?module_id=<?= $mid ?>">Entity Designer</a><a href="/public/administration/axiom/modules">Modules</a></div></section>
<?php foreach(['success','error'] as $k): if(!empty($_SESSION['flash_'.$k])):?><div class="studio-alert <?= $k ?>"><?= $h($_SESSION['flash_'.$k]);unset($_SESSION['flash_'.$k]);?></div><?php endif;endforeach;?>
<div class="studio-workbench form-designer-workbench"><aside class="studio-panel studio-tree"><div class="studio-panel-head"><div><span class="axiom-studio-kicker">ENTITÉS</span><h3>Formulaires</h3></div></div><nav class="studio-entity-list"><?php foreach($entities as $e):?><a class="<?= (int)$e['id']===$eid?'active':'' ?>" href="/public/administration/axiom/form-designer?module_id=<?= $mid ?>&entity_id=<?= (int)$e['id'] ?>"><span>▤</span><div><strong><?= $h($e['name']) ?></strong><small><?= $h($e['table_name']) ?></small></div></a><?php endforeach;?></nav></aside>
<section class="studio-panel studio-canvas"><?php if($entity):?><div class="studio-panel-head"><div><span class="axiom-studio-kicker">CANEVAS</span><h3><?= $h($entity['name']) ?></h3></div><button type="button" class="studio-primary" data-dialog="component-dialog">＋ Composant</button></div><form method="post" action="/public/administration/axiom/form-designer/ordre" id="order-form"><?= \App\Core\Csrf::field() ?><input type="hidden" name="module_id" value="<?= $mid ?>"><input type="hidden" name="entity_id" value="<?= $eid ?>"><input type="hidden" name="form_id" value="<?= $formId ?>"><input type="hidden" name="order_json" id="order-json"><div class="form-builder-grid" id="form-builder"><?php foreach($components as $c):?><article class="form-builder-item span-<?= (int)$c['width_desktop'] ?>" draggable="true" data-id="<?= (int)$c['id'] ?>"><span class="drag-handle">⋮⋮</span><div><strong><?= $h($c['label']) ?><?= $c['is_required']?' *':'' ?></strong><small><?= $h($c['component_type']) ?> · <?= (int)$c['width_desktop'] ?>/12</small><input disabled placeholder="<?= $h($c['placeholder']??'') ?>"></div><button type="submit" form="archive-<?= (int)$c['id'] ?>" class="studio-row-action">×</button></article><?php endforeach;?></div><button class="studio-secondary wide" type="submit">Enregistrer l’ordre</button></form><?php foreach($components as $c):?><form id="archive-<?= (int)$c['id'] ?>" method="post" action="/public/administration/axiom/form-designer/archiver" onsubmit="return confirm('Archiver ce composant ?')"><?= \App\Core\Csrf::field() ?><input type="hidden" name="module_id" value="<?= $mid ?>"><input type="hidden" name="entity_id" value="<?= $eid ?>"><input type="hidden" name="component_id" value="<?= (int)$c['id'] ?>"></form><?php endforeach;?><?php else:?><div class="studio-canvas-empty"><h3>Aucune entité disponible</h3><p>Créez d’abord une entité dans Entity Designer.</p></div><?php endif;?></section>
<aside class="studio-panel studio-preview-panel"><div class="studio-panel-head"><div><span class="axiom-studio-kicker">PRÉVISUALISATION</span><h3>Responsive</h3></div></div><div class="device-switch"><button class="active" data-device="desktop">PC</button><button data-device="tablet">Tablette</button><button data-device="mobile">Mobile</button></div><div class="live-form-preview" id="live-preview"><?php foreach($components as $c):?><label class="span-<?= (int)$c['width_desktop'] ?>" data-desktop="<?= (int)$c['width_desktop'] ?>" data-tablet="<?= (int)$c['width_tablet'] ?>" data-mobile="<?= (int)$c['width_mobile'] ?>"><?= $h($c['label']) ?><?= $c['is_required']?' *':'' ?><input disabled placeholder="<?= $h($c['placeholder']??'') ?>"><?php if($c['help_text']):?><small><?= $h($c['help_text']) ?></small><?php endif;?></label><?php endforeach;?></div><details><summary>Définition JSON</summary><pre><code><?= $h($preview['json']) ?></code></pre></details></aside></div>
<dialog id="component-dialog" class="studio-dialog"><form method="post" action="/public/administration/axiom/form-designer/composant"><?= \App\Core\Csrf::field() ?><input type="hidden" name="module_id" value="<?= $mid ?>"><input type="hidden" name="entity_id" value="<?= $eid ?>"><input type="hidden" name="form_id" value="<?= $formId ?>"><div class="studio-dialog-head"><div><span class="axiom-studio-kicker">NOUVEAU COMPOSANT</span><h3>Ajouter au formulaire</h3></div><button type="button" data-close>×</button></div><div class="studio-form-grid"><label>Champ lié<select name="field_id"><option value="">Composant libre</option><?php foreach($fields as $f):?><option value="<?= (int)$f['id'] ?>"><?= $h($f['label']) ?></option><?php endforeach;?></select></label><label>Type<select name="component_type"><?php foreach(['text'=>'Texte','textarea'=>'Texte long','select'=>'Liste','checkbox'=>'Case à cocher','radio'=>'Boutons radio','date'=>'Date','time'=>'Heure','datetime'=>'Date/heure','email'=>'E-mail','phone'=>'Téléphone','number'=>'Nombre','currency'=>'Monnaie','percentage'=>'Pourcentage','signature'=>'Signature','file'=>'Fichier','image'=>'Image','address'=>'Adresse','relation'=>'Relation','heading'=>'Titre','separator'=>'Séparateur'] as $v=>$l):?><option value="<?= $v ?>"><?= $l ?></option><?php endforeach;?></select></label><label>Libellé<input name="label" required></label><label>Placeholder<input name="placeholder"></label><label>Largeur PC<select name="width_desktop"><?php foreach([12,9,8,6,4,3] as $w):?><option><?= $w ?></option><?php endforeach;?></select></label><label>Tablette<select name="width_tablet"><?php foreach([12,9,8,6,4,3] as $w):?><option><?= $w ?></option><?php endforeach;?></select></label><label>Mobile<select name="width_mobile"><option>12</option><option>6</option></select></label></div><label><input type="checkbox" name="is_required" value="1"> Obligatoire</label><label>Aide<input name="help_text"></label><fieldset><legend>Affichage conditionnel</legend><div class="studio-form-grid"><label>Champ<input name="condition_field"></label><label>Opérateur<select name="condition_operator"><option value="">Toujours</option><option value="equals">Égal à</option><option value="not_equals">Différent de</option><option value="not_empty">Non vide</option></select></label><label>Valeur<input name="condition_value"></label></div></fieldset><div class="studio-actions"><button type="button" data-close>Annuler</button><button class="studio-primary">Ajouter</button></div></form></dialog></main><script src="/public/assets/js/axiom-form-designer.js"></script>
