<?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">WORKFLOW DESIGNER V1 · 9.4.4</span><h2>Concevoir les processus métier</h2><p>Créez les étapes, reliez-les, simulez le parcours puis publiez une version exécutable.</p></div><div class="axiom-studio-version"><span>Moteur</span><strong>BPM V1</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/workflow-designer"><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>Workflow<select name="workflow_id" onchange="this.form.submit()"><option value="0">Nouveau workflow…</option><?php foreach($workflows as $w):?><option value="<?= (int)$w['id']?>" <?= $workflow&&(int)$w['id']===(int)$workflow['id']?'selected':''?>><?= $h($w['name'])?> · <?= $h($w['status'])?></option><?php endforeach;?></select></label></form><?php if($workflow):?><form method="post" action="/public/administration/axiom/workflow-designer/publier"><?= \App\Core\Csrf::field()?><input type="hidden" name="module_id" value="<?= $moduleId?>"><input type="hidden" name="workflow_id" value="<?= (int)$workflow['id']?>"><button class="studio-primary">Publier la version</button></form><?php endif;?></section>
<?php if(!$workflow):?><section class="studio-panel workflow-create"><div class="studio-panel-head"><div><span class="axiom-studio-kicker">NOUVEAU PROCESSUS</span><h3>Créer un workflow</h3></div></div><form method="post" action="/public/administration/axiom/workflow-designer/workflow" class="studio-form-grid"><?= \App\Core\Csrf::field()?><input type="hidden" name="module_id" value="<?= $moduleId?>"><label>Nom<input name="name" required placeholder="Validation d'inscription"></label><label>Code<input name="code" placeholder="validation_inscription"></label><label>Entité associée<select name="entity_id"><option value="">Aucune</option><?php foreach($entities as $e):?><option value="<?= (int)$e['id']?>"><?= $h($e['name'])?></option><?php endforeach;?></select></label><label class="span-2">Description<textarea name="description" rows="3"></textarea></label><div><button class="studio-primary">Créer le workflow</button></div></form></section><?php else:?>
<div class="workflow-layout"><aside class="studio-panel workflow-sidebar"><div class="studio-panel-head"><div><span class="axiom-studio-kicker">ÉTAPES</span><h3>Ajouter un nœud</h3></div></div><form method="post" action="/public/administration/axiom/workflow-designer/noeud" class="workflow-form"><?= \App\Core\Csrf::field()?><input type="hidden" name="module_id" value="<?= $moduleId?>"><input type="hidden" name="workflow_id" value="<?= (int)$workflow['id']?>"><label>Type<select name="node_type"><?php foreach($nodeTypes as $k=>$v):?><option value="<?= $h($k)?>"><?= $h($v)?></option><?php endforeach;?></select></label><label>Libellé<input name="label" required></label><label>Code<input name="code"></label><label>Affectation<select name="assignee_type"><option value="">Aucune</option><option value="user">Utilisateur</option><option value="role">Rôle</option><option value="service">Service</option></select></label><label>Valeur d'affectation<input name="assignee_value"></label><label>Message<textarea name="message" rows="2"></textarea></label><button class="studio-secondary wide">Ajouter l'étape</button></form><hr><div class="studio-panel-head"><div><span class="axiom-studio-kicker">TRANSITION</span><h3>Relier deux étapes</h3></div></div><form method="post" action="/public/administration/axiom/workflow-designer/transition" class="workflow-form"><?= \App\Core\Csrf::field()?><input type="hidden" name="module_id" value="<?= $moduleId?>"><input type="hidden" name="workflow_id" value="<?= (int)$workflow['id']?>"><label>Depuis<select name="source_node_id"><?php foreach($nodes as $n):?><option value="<?= (int)$n['id']?>"><?= $h($n['label'])?></option><?php endforeach;?></select></label><label>Vers<select name="target_node_id"><?php foreach($nodes as $n):?><option value="<?= (int)$n['id']?>"><?= $h($n['label'])?></option><?php endforeach;?></select></label><label>Libellé<input name="label" value="Continuer"></label><label>Condition<input name="condition_expression" placeholder="status == 'approved'"></label><button class="studio-secondary wide">Créer la transition</button></form></aside>
<section class="studio-panel workflow-canvas-panel"><div class="studio-panel-head"><div><span class="axiom-studio-kicker"><?= $h(strtoupper($workflow['status']))?></span><h3><?= $h($workflow['name'])?></h3><code><?= $h($workflow['code'])?></code></div><span class="type-chip"><?= count($nodes)?> étapes · <?= count($transitions)?> liens</span></div><div class="workflow-canvas"><?php foreach($nodes as $n):?><article class="workflow-node type-<?= $h($n['node_type'])?>"><div class="workflow-node-icon"><?= $n['node_type']==='start'?'▶':($n['node_type']==='end'?'■':'◆')?></div><div><strong><?= $h($n['label'])?></strong><small><?= $h($nodeTypes[$n['node_type']]??$n['node_type'])?> · <?= $h($n['code'])?></small></div><?php if(!in_array($n['node_type'],['start','end'],true)):?><form method="post" action="/public/administration/axiom/workflow-designer/archiver"><?= \App\Core\Csrf::field()?><input type="hidden" name="module_id" value="<?= $moduleId?>"><input type="hidden" name="workflow_id" value="<?= (int)$workflow['id']?>"><input type="hidden" name="object_type" value="node"><input type="hidden" name="object_id" value="<?= (int)$n['id']?>"><button title="Archiver">×</button></form><?php endif;?></article><?php endforeach;?></div><div class="workflow-transitions"><h4>Transitions</h4><?php if(!$transitions):?><p class="studio-muted">Aucune transition. Reliez l'étape Début à la suite du parcours.</p><?php endif;?><?php foreach($transitions as $t):?><div><span><?= $h($t['source_label'])?></span><b>→ <?= $h($t['label'])?> →</b><span><?= $h($t['target_label'])?></span><code><?= $h($t['condition_expression']??'toujours')?></code></div><?php endforeach;?></div></section>
<aside class="studio-panel workflow-inspector"><div class="studio-panel-head"><div><span class="axiom-studio-kicker">SIMULATEUR</span><h3>Contrôle du graphe</h3></div></div><?php if($simulation):?><div class="workflow-score <?= $simulation['valid']?'ok':'error'?>"><strong><?= $simulation['valid']?'Structure valide':'Structure bloquante'?></strong><span><?= (int)$simulation['reachable_count']?>/<?= (int)$simulation['node_count']?> étapes atteignables</span></div><?php foreach($simulation['errors'] as $e):?><p class="workflow-message error"><?= $h($e)?></p><?php endforeach;?><?php foreach($simulation['warnings'] as $w):?><p class="workflow-message warning"><?= $h($w)?></p><?php endforeach;?><?php if(!$simulation['errors']&&!$simulation['warnings']):?><p class="workflow-message success">Toutes les étapes sont atteignables et reliées.</p><?php endif;?><?php endif;?><div class="workflow-meta"><dl><dt>Version</dt><dd><?= (int)$workflow['current_version']?></dd><dt>Statut</dt><dd><?= $h($workflow['status'])?></dd><dt>Entité</dt><dd><?= $h($workflow['entity_id']?:'Non liée')?></dd></dl></div></aside></div><?php endif;?>
</main>
