{{!-- Partial pour l'affichage des ActiveEffects --}}

<div class="sheet-box color-bg-archetype">
  <ul class="item-list alternate-list">
    
    {{!-- En-tête --}}
    <li class="item flexrow list-item items-title-bg">
      <span class="item-name-label-header">
        <h3><label class="items-title-text">{{localize "EFFECT.activeEffects"}}</label></h3>
      </span>
      <div class="item-filler">&nbsp;</div>
      <div class="item-controls item-controls-fixed">
        <a class="item-control" data-action="createEffect" title="{{localize "EFFECT.new"}}">
          <i class="fas fa-plus"></i>
        </a>
      </div>
    </li>
    
    {{!-- Affiche un message si aucun effet --}}
    {{#if (not actor.effects.length)}}
    <li class="item flexrow">
      <span class="item-name-label competence-name" style="color: #888; font-style: italic;">{{localize "EFFECT.noActiveEffects"}}</span>
    </li>
    {{/if}}
    
    {{!-- Liste des effets --}}
    {{#each actor.effects as |effect|}}
    <li class="item flexrow" data-effect-id="{{effect.id}}" {{#if effect.disabled}}style="opacity: 0.6;"{{/if}}>
      {{!-- Icône de l'effet --}}
      <img class="item-name-img" src="{{effect.icon}}" onerror="this.src='systems/fvtt-mournblade-cyd-2-0/assets/icons/capacite.webp'" />
      
      {{!-- Nom et description de l'effet --}}
      <div class="flexcol item-name-label">
        <span class="item-name-label competence-name">
          {{effect.name}}
          {{#if effect.disabled}}<i class="fas fa-ban" style="color: #ff5555; margin-left: 5px;" title="Désactivé"></i>{{/if}}
        </span>
        
        {{!-- Affichage compact des modifications --}}
        {{#if effect.changes.length}}
        <span class="predilection-text" style="font-size: 0.85em; color: #aaa;">
          {{#each effect.changes as |change index|}}
            {{#if (eq change.mode 0)}}(+{{/if}}{{#if (eq change.mode 1)}}(*{{/if}}{{#if (eq change.mode 2)}}={{/if}}{{change.value}}{{#if (eq change.mode 0)}}){{/if}}{{#if (eq change.mode 1)}}){{/if}}
            {{#unless (eq index (subtract effect.changes.length 1))}}, {{/unless}}
          {{/each}}
          {{#each effect.statuses as |status|}}
            {{#if (and (ne status "") (not (eq index 0)))}}, {{/if}}
            <i class="fas fa-exclamation-triangle" style="color: #ffaa00;" title="{{status}}"></i>
          {{/each}}
        </span>
        {{/if}}
      </div>
      
      {{!-- Affichage de la durée --}}
      {{#if effect.duration.units}}
      <span class="item-field-label-short" style="font-size: 0.85em;">
        {{#if (eq effect.duration.units "rounds")}}🔄{{/if}}
        {{#if (eq effect.duration.units "turns")}}🎭{{/if}}
        {{#if (eq effect.duration.units "seconds")}}⏱️{{/if}}
        {{#if (eq effect.duration.units "combat")}}⚔️{{/if}}
        {{#if (eq effect.duration.units "scene")}}📜{{/if}}
        {{effect.duration.value}}
      </span>
      {{/if}}
      
      {{!-- Contrôles --}}
      <div class="item-controls item-controls-fixed">
        <a class="item-control" data-action="editEffect" data-effect-id="{{effect.id}}" title="Éditer">
          <i class="fas fa-edit"></i>
        </a>
        <a class="item-control" data-action="toggleEffect" data-effect-id="{{effect.id}}" title="{{#if effect.disabled}}Activer{{else}}Désactiver{{/if}}">
          <i class="fas fa-{{#if effect.disabled}}check{{else}}times{{/if}}"></i>
        </a>
        <a class="item-control" data-action="deleteEffect" data-effect-id="{{effect.id}}" title="Supprimer">
          <i class="fas fa-trash"></i>
        </a>
      </div>
    </li>
    {{/each}}
    
  </ul>
</div>

{{!-- Affichage détaillé des effets actifs --}}
{{#if actor.effects.length}}
<div class="sheet-box color-bg-archetype effect-summary">
  <h4 class="section-title">{{localize "EFFECT.effectSummary"}}</h4>
  <div class="effect-modifications">
    {{#each actor.effects as |effect|}}
    {{#if (not effect.disabled)}}
    {{#if effect.changes.length}}
    <div class="effect-category">
      <strong>{{effect.name}}:</strong>
      {{#each effect.changes as |change|}}
      <span class="effect-modification">
        {{change.key}}: 
        {{#if (eq change.mode 0)}}+{{/if}}
        {{#if (eq change.mode 1)}}*{{/if}}
        {{#if (eq change.mode 2)}}={{/if}}
        {{change.value}}
        {{#if (eq change.mode 0)}}{{/if}}
        {{#if (eq change.mode 1)}}{{/if}}
      </span>{{#unless @last}}, {{/unless}}
      {{/each}}
    </div>
    {{/if}}
    {{/if}}
    {{/each}}
  </div>
</div>
{{/if}}
