<?php
namespace App\Controllers;
use App\Core\Auth; use App\Core\Controller; use App\Core\Csrf; use App\Core\Permission; use App\Models\DisciplineIcon;
final class DisciplineIconController extends Controller {
 public function index(): void { Auth::requireLogin(); Permission::require('parametres.icones.view'); $this->view('parameters/icons',['pageTitle'=>'Bibliothèque d’icônes','iconGroups'=>DisciplineIcon::grouped()]); }
 public function store(): void { Auth::requireLogin(); Permission::require('parametres.icones.manage'); Csrf::verify($_POST['_csrf']??null); $code=strtoupper(trim($_POST['code']??'')); $lib=trim($_POST['libelle']??''); $val=trim($_POST['valeur_icone']??''); if($code===''||$lib===''||$val===''){$_SESSION['error']='Code, libellé et icône obligatoires.';$this->redirect('/parametres/icones');} DisciplineIcon::create(['organisation_id'=>(int)(Auth::user()['organisation_id']??1),'code'=>$code,'libelle'=>$lib,'categorie'=>trim($_POST['categorie']??'general'),'type_icone'=>'emoji','valeur_icone'=>$val,'couleur_defaut'=>trim($_POST['couleur_defaut']??'#64748B'),'ordre_affichage'=>(int)($_POST['ordre_affichage']??100)]); $_SESSION['success']='Icône ajoutée.'; $this->redirect('/parametres/icones'); }
 public function archive(): void { Auth::requireLogin(); Permission::require('parametres.icones.manage'); Csrf::verify($_POST['_csrf']??null); DisciplineIcon::archive((int)($_POST['id']??0)); $_SESSION['success']='Icône archivée.'; $this->redirect('/parametres/icones'); }
 public function assign(): void { Auth::requireLogin(); Permission::require('parametres.disciplines.icon'); Csrf::verify($_POST['_csrf']??null); $id=(int)($_POST['discipline_id']??0); DisciplineIcon::assign($id,(int)($_POST['icon_id']??0),trim($_POST['couleur_accent']??'')); $_SESSION['success']='Identité visuelle enregistrée.'; $this->redirect('/parametres/disciplines/modifier?id='.$id); }
}
