<?php use App\Core\Csrf; $open=array_values(array_filter($tasks,static fn($t)=>$t['status']==='open'));$done=array_values(array_filter($tasks,static fn($t)=>$t['status']!=='open')); ?>
<link rel="stylesheet" href="/public/assets/css/cda-alerts-969.css">
<main class="alert-page">
<header class="alert-hero"><div><a href="/public/">← Retour à l’accueil</a><span>AXIOM · Suivi quotidien</span><h1>Alertes et tâches</h1><p>Les actions à réaliser sont regroupées ici. Un seul récapitulatif par jour peut être envoyé.</p></div><strong><?=count($open)?></strong></header>

<section class="alert-settings">
<div><h2>Rappel quotidien par e-mail</h2><p>Vous pouvez le désactiver. Les alertes resteront visibles dans AXIOM.</p></div>
<form method="post" action="/public/alertes/preferences"><?=Csrf::field()?>
<label class="alert-switch"><input type="checkbox" name="daily_email_enabled" value="1" <?=!empty($preference['daily_email_enabled'])?'checked':''?>><span>Recevoir le récapitulatif quotidien</span></label>
<label>À partir de <select name="digest_hour"><?php for($h=6;$h<=18;$h++):?><option value="<?=$h?>" <?=(int)$preference['digest_hour']===$h?'selected':''?>><?=sprintf('%02d:00',$h)?></option><?php endfor?></select></label><button>Enregistrer</button>
</form></section>

<section class="alert-section"><header><div><span>À traiter</span><h2><?=count($open)?> tâche(s) ouverte(s)</h2></div><?php if($canManage):?><em>Vue direction : tous les responsables</em><?php endif?></header>
<div class="alert-list"><?php if(!$open):?><article class="alert-empty">✓ Aucune tâche en attente.</article><?php endif?><?php foreach($open as $task):?>
<article class="alert-card priority-<?=htmlspecialchars($task['priority'])?>"><div class="alert-icon"><?=$task['alert_type']==='invoice_to_prepare'?'€':'✓'?></div><div class="alert-content"><div><span><?=htmlspecialchars($task['alert_type']==='invoice_to_prepare'?'Facturation':'Journée professeur')?></span><small><?=htmlspecialchars($task['assigned_prenom'].' '.$task['assigned_nom'])?></small></div><h3><?=htmlspecialchars($task['title'])?></h3><p><?=htmlspecialchars((string)$task['message'])?></p><footer><?php if($task['due_at']):?><time>Échéance : <?=htmlspecialchars(date('d/m/Y H:i',strtotime($task['due_at'])))?></time><?php endif?><div><?php if($task['action_url']):?><a href="<?=htmlspecialchars($task['action_url'])?>">Ouvrir</a><?php endif?><form method="post" action="/public/alertes/terminer"><?=Csrf::field()?><input type="hidden" name="id" value="<?=(int)$task['id']?>"><button>Terminer</button></form></div></footer></div></article>
<?php endforeach?></div></section>

<?php if($done):?><details class="alert-history"><summary>Historique récent (<?=count($done)?>)</summary><div><?php foreach(array_slice($done,0,50) as $task):?><p><strong><?=htmlspecialchars($task['title'])?></strong><span><?=htmlspecialchars($task['status'])?> · <?=htmlspecialchars($task['assigned_prenom'].' '.$task['assigned_nom'])?></span></p><?php endforeach?></div></details><?php endif?>
</main>
