<?php $h=fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');$cfg=$report['config']??[];?><main class="axiom-studio-page report-designer"><header class="studio-hero"><div><span class="axiom-studio-kicker">AXIOM STUDIO 9.4.7</span><h1>Report Designer</h1><p>Créez, filtrez, prévisualisez et exportez des rapports sans écrire de code.</p></div><a class="studio-secondary" href="/public/administration/axiom">Retour au Studio</a></header>
<section class="studio-panel report-toolbar"><form method="get" action="/public/administration/axiom/report-designer"><label>Module<select name="module_id" onchange="this.form.submit()"><?php foreach($modules as $m):?><option value="<?= (int)$m['id']?>" <?= $moduleId===(int)$m['id']?'selected':''?>><?= $h($m['name'])?></option><?php endforeach;?></select></label><label>Rapport<select name="report_id" onchange="this.form.submit()"><option value="0">Nouveau rapport</option><?php foreach($reports as $r):?><option value="<?= (int)$r['id']?>" <?= (int)($report['id']??0)===(int)$r['id']?'selected':''?>><?= $h($r['name'])?> · <?= $h($r['status'])?></option><?php endforeach;?></select></label></form><?php if($report):?><div class="report-actions"><a class="studio-secondary" href="/public/administration/axiom/report-designer/export-csv?report_id=<?= (int)$report['id']?>">CSV / Excel</a><button type="button" class="studio-secondary" onclick="window.print()">Imprimer / PDF</button><form method="post" action="/public/administration/axiom/report-designer/publier"><?= \App\Core\Csrf::field()?><input type="hidden" name="module_id" value="<?= $moduleId?>"><input type="hidden" name="report_id" value="<?= (int)$report['id']?>"><button class="studio-primary">Publier</button></form></div><?php endif;?></section>
<div class="report-grid"><section class="studio-panel"><h2><?= $report?'Configurer le rapport':'Nouveau rapport'?></h2><form method="post" action="/public/administration/axiom/report-designer/enregistrer" class="report-form"><?= \App\Core\Csrf::field()?><input type="hidden" name="module_id" value="<?= $moduleId?>"><input type="hidden" name="report_id" value="<?= (int)($report['id']??0)?>"><label>Nom<input name="name" required value="<?= $h($report['name']??'')?>"></label><label>Description<textarea name="description"><?= $h($report['description']??'')?></textarea></label><label>Entité source<select name="entity_id" onchange="location.href='/public/administration/axiom/report-designer?module_id=<?= $moduleId?>&entity_id='+this.value+'<?= $report?'&report_id='.(int)$report['id']:''?>'"><?php foreach($entities as $e):?><option value="<?= (int)$e['id']?>" <?= $entityId===(int)$e['id']?'selected':''?>><?= $h($e['name'])?></option><?php endforeach;?></select></label><fieldset><legend>Colonnes</legend><div class="report-columns"><?php foreach($fields as $f):?><label><input type="checkbox" name="columns[]" value="<?= (int)$f['id']?>" <?= in_array((int)$f['id'],array_map('intval',$cfg['columns']??[]),true)?'checked':''?>> <?= $h($f['name'])?> <small><?= $h($f['field_type'])?></small></label><?php endforeach;?></div></fieldset><div class="report-two"><label>Filtre sur<select name="filter_field_id"><option value="0">Aucun</option><?php foreach($fields as $f):?><option value="<?= (int)$f['id']?>" <?= (int)($cfg['filter_field_id']??0)===(int)$f['id']?'selected':''?>><?= $h($f['name'])?></option><?php endforeach;?></select></label><label>Opérateur<select name="filter_operator"><option value="contains">Contient</option><option value="equals" <?= ($cfg['filter_operator']??'')==='equals'?'selected':''?>>Égal à</option><option value="starts" <?= ($cfg['filter_operator']??'')==='starts'?'selected':''?>>Commence par</option></select></label><label>Valeur<input name="filter_value" value="<?= $h($cfg['filter_value']??'')?>"></label><label>Tri<select name="sort_field_id"><option value="0">Aucun</option><?php foreach($fields as $f):?><option value="<?= (int)$f['id']?>" <?= (int)($cfg['sort_field_id']??0)===(int)$f['id']?'selected':''?>><?= $h($f['name'])?></option><?php endforeach;?></select></label><label>Sens<select name="sort_direction"><option>ASC</option><option <?= ($cfg['sort_direction']??'')==='DESC'?'selected':''?>>DESC</option></select></label><label>Limite<input type="number" min="1" max="500" name="limit" value="<?= (int)($cfg['limit']??50)?>"></label></div><button class="studio-primary wide">Enregistrer et prévisualiser</button></form></section>
<section class="studio-panel report-preview"><div class="studio-panel-head"><div><span class="axiom-studio-kicker">APERÇU</span><h2><?= $h($report['name']??'Rapport non enregistré')?></h2></div><span class="studio-badge"><?= count($preview['rows']??[])?> ligne(s)</span></div><?php if(!empty($preview['columns'])):?><div class="report-table-wrap"><table><thead><tr><?php foreach($preview['columns'] as $c):?><th><?= $h($c['name'])?></th><?php endforeach;?></tr></thead><tbody><?php foreach($preview['rows'] as $row):?><tr><?php foreach($row as $v):?><td><?= $h($v)?></td><?php endforeach;?></tr><?php endforeach;?></tbody></table></div><?php else:?><div class="dashboard-empty">Enregistrez un rapport avec au moins une colonne pour afficher l’aperçu.</div><?php endif;?></section></div></main>