<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

    <!--
        Composant réutilisable: Bouton Action Utilisateur (WOU/DRY Pattern)
        
        Auteur: Lions User Manager
        Version: 1.0.0
        Description: Bouton générique pour actions utilisateur
        
        Paramètres:
        - value: String (requis) - Texte du bouton
        - icon: String (optionnel) - Classe d'icône PrimeIcons
        - action: String (optionnel) - Action à exécuter
        - outcome: String (optionnel) - Page de redirection
        - severity: String (défaut: "primary") - Severity: "primary", "success", "warning", "danger", "info", "secondary"
        - size: String (défaut: "normal") - Taille: "small", "normal", "large"
        - disabled: Boolean (défaut: false) - Désactiver le bouton
        - update: String (optionnel) - Composants à mettre à jour
        - process: String (défaut: "@this") - Composants à traiter
        - styleClass: String (optionnel) - Classes CSS supplémentaires
        
        Exemples d'utilisation:
        
        1. Bouton simple:
        <ui:include src="/templates/components/shared/buttons/button-user-action.xhtml">
            <ui:param name="value" value="Créer Utilisateur" />
            <ui:param name="icon" value="pi-user-plus" />
            <ui:param name="action" value="#{userBean.createUser}" />
        </ui:include>
        
        2. Bouton avec redirection:
        <ui:include src="/templates/components/shared/buttons/button-user-action.xhtml">
            <ui:param name="value" value="Voir Profil" />
            <ui:param name="icon" value="pi-eye" />
            <ui:param name="outcome" value="/pages/user-manager/users/profile" />
        </ui:include>
    -->
    
    <c:set var="severity" value="#{empty severity ? 'primary' : severity}" />
    <c:set var="size" value="#{empty size ? 'normal' : size}" />
    <c:set var="disabled" value="#{empty disabled ? false : disabled}" />
    <c:set var="process" value="#{empty process ? '@this' : process}" />
    
    <!-- Déterminer la classe selon la severity -->
    <c:choose>
        <c:when test="#{severity == 'primary'}">
            <c:set var="buttonClass" value="p-button-primary" />
        </c:when>
        <c:when test="#{severity == 'success'}">
            <c:set var="buttonClass" value="p-button-success" />
        </c:when>
        <c:when test="#{severity == 'warning'}">
            <c:set var="buttonClass" value="p-button-warning" />
        </c:when>
        <c:when test="#{severity == 'danger'}">
            <c:set var="buttonClass" value="p-button-danger" />
        </c:when>
        <c:when test="#{severity == 'info'}">
            <c:set var="buttonClass" value="p-button-info" />
        </c:when>
        <c:otherwise>
            <c:set var="buttonClass" value="p-button-secondary" />
        </c:otherwise>
    </c:choose>
    
    <!-- Ajouter la taille -->
    <c:if test="#{size == 'small'}">
        <c:set var="buttonClass" value="#{buttonClass} p-button-sm" />
    </c:if>
    <c:if test="#{size == 'large'}">
        <c:set var="buttonClass" value="#{buttonClass} p-button-lg" />
    </c:if>
    
    <!-- Ajouter les classes personnalisées -->
    <c:if test="#{not empty styleClass}">
        <c:set var="buttonClass" value="#{buttonClass} #{styleClass}" />
    </c:if>
    
    <p:commandButton 
        value="#{value}"
        icon="#{not empty icon ? icon : ''}"
        styleClass="#{buttonClass}"
        disabled="#{disabled}"
        action="#{not empty action ? action : null}"
        outcome="#{not empty outcome ? outcome : null}"
        update="#{not empty update ? update : '@form'}"
        process="#{process}" />
    
</ui:composition>

