<section>

  {{!-- Sheet Header --}}
  <header class="sheet-header">

    <div class="header-banner">
      <img class="profile-img" src="{{actor.img}}" data-action="editImage" title="{{actor.name}}" />
      <h1 class="charname"><input name="name" type="text" value="{{actor.name}}" placeholder="Nom de la créature" /></h1>
    </div>

    <div class="header-stat-cards">

      {{!-- RESSOURCES --}}
      <div class="stat-card card-ba">
        <div class="stat-card-title">★ Ressources</div>
        <div class="stat-card-content">
          <div class="stat-field">
            <label>Valeur</label>
            <input type="text" name="system.ressources.value" value="{{system.ressources.value}}" data-dtype="Number" />
          </div>
        </div>
      </div>

      {{!-- VIGUEUR --}}
      <div class="stat-card card-vigueur">
        <div class="stat-card-title">♥ Vigueur <span class="stat-sub">({{system.sante.vigueur}})</span></div>
        <div class="stat-card-content">
          <div class="stat-field">
            <label>État</label>
            <select name="system.sante.etat">
              {{selectOptions combativiteList selected=system.sante.etat valueAttr="value" nameAttr="value" labelAttr="label"}}
            </select>
          </div>
          <div class="stat-field">
            <label>Niveaux</label>
            <input type="text" name="system.sante.nbcombativite" value="{{system.sante.nbcombativite}}" data-dtype="Number" />
          </div>
          <div class="stat-field">
            <label>Seuil de Vigueur</label>
            <input type="text" name="system.sante.vigueur" value="{{system.sante.vigueur}}" data-dtype="Number" />
          </div>
        </div>
      </div>

      {{!-- ÂME --}}
      <div class="stat-card card-ame">
        <div class="stat-card-title">✦ Âme <span class="stat-sub">(Seuil {{system.ame.seuilpouvoir}})</span></div>
        <div class="stat-card-content">
          <div class="stat-field">
            <label>État</label>
            <select name="system.ame.etat">
              {{selectOptions ameList selected=system.ame.etat valueAttr="value" nameAttr="value" labelAttr="label"}}
            </select>
          </div>
          <div class="stat-field">
            <label>Niveaux</label>
            <input type="text" name="system.ame.nbame" value="{{system.ame.nbame}}" data-dtype="Number" />
          </div>
          <div class="stat-field">
            <label>Seuil de Pouvoir</label>
            <input type="text" name="system.ame.seuilpouvoir" value="{{system.ame.seuilpouvoir}}" data-dtype="Number" />
          </div>
        </div>
      </div>

      {{!-- COMBAT --}}
      <div class="stat-card card-combat">
        <div class="stat-card-title">⚡ Combat</div>
        <div class="stat-card-content">
          <div class="stat-field">
            <label>Init.</label>
            <input type="text" name="system.combat.inittotal" value="{{system.combat.inittotal}}" data-dtype="Number" placeholder="{{initiative}}" />
          </div>
          <div class="stat-field">
            <label>Déf.</label>
            <input type="text" name="system.combat.defensetotal" value="{{system.combat.defensetotal}}" data-dtype="Number" placeholder="{{combat.defenseTotal}}" />
          </div>
          <div class="stat-field">
            <label>Prot.</label>
            <input type="text" name="system.combat.protectiontotal" value="{{system.combat.protectiontotal}}" data-dtype="Number" placeholder="{{protectionTotal}}" />
          </div>
        </div>
      </div>

    </div>

  </header>

  <hr>
  <nav class="sheet-tabs tabs" data-group="primary">
    <a class="item" data-tab="principal">Technique</a>
    <a class="item" data-tab="competences">Compétences</a>
    <a class="item" data-tab="talents">Talents</a>
    <a class="item" data-tab="armes">Armes</a>
    <a class="item" data-tab="effects">Effets</a>
    <a class="item" data-tab="biodata">Bio&Notes</a>
  </nav>
  <hr>

  <section class="sheet-body">

    {{!-- Technique Tab --}}
    <div class="tab principal" data-group="primary" data-tab="principal">
      <div class="grid grid-2col">

        {{!-- Colonne gauche : Attributs + Santé + Actions --}}
        <div class="sheet-box color-bg-archetype">

          <div class="section-title">Attributs</div>
          <ul class="item-list alternate-list">
            {{#each system.attributs as |attr key|}}
            <li class="item flexrow" data-attr-key="{{key}}">
              <img class="item-name-img" src="systems/fvtt-mournblade-cyd-2-0/assets/icons/{{attr.labelnorm}}.webp">
              <span class="item-name-label competence-name item-field-label-medium">
                <a data-action="rollAttribut" data-attr-key="{{key}}" data-tooltip="Jet {{attr.label}}">{{attr.label}}</a>
              </span>
              <select class="status-small-label color-class-common competence-niveau"
                name="system.attributs.{{key}}.value" data-dtype="Number">
                {{selectOptions @root.config.listeNiveauCreature selected=attr.value}}
              </select>
            </li>
            {{/each}}
            <li class="item flexrow">
              <img class="item-name-img" src="systems/fvtt-mournblade-cyd-2-0/assets/icons/vitesse.webp">
              <span class="item-name-label competence-name item-field-label-medium">Vitesse</span>
              <input type="text" class="padd-right numeric-input item-field-label-short" name="system.vitesse.value"
                value="{{system.vitesse.value}}" data-dtype="Number" />
            </li>
          </ul>

          <div class="section-title">Santé</div>
          <ul class="item-list alternate-list">
            <li class="item flexrow">
              <label class="label-name item-field-label-medium">Vigueur (seuil)</label>
              <input type="text" class="padd-right numeric-input item-field-label-short" data-dtype="Number"
                name="system.sante.vigueur" value="{{system.sante.vigueur}}">
            </li>
          </ul>

          <div class="section-title">Actions de combat</div>
          <ul class="item-list alternate-list">
            <li class="item flexrow">
              <button type="button" class="chat-card-button" data-action="rollInitiative">⚡ Initiative ({{initiative}})</button>
            </li>
            <li class="item flexrow">
              <input type="checkbox" name="system.combat.monte" {{checked system.combat.monte}} />
              <label class="item-field-label-medium">Monté</label>
              <input type="checkbox" name="system.combat.defensetotale" {{checked system.combat.defensetotale}} />
              <label class="item-field-label-medium">Déf. totale</label>
            </li>
            <li class="item flexrow">
              <button type="button" class="chat-card-button" data-action="rollAssommer">Assommer</button>
              <button type="button" class="chat-card-button" data-action="rollCoupBas">Coup bas</button>
            </li>
            <li class="item flexrow">
              <button type="button" class="chat-card-button" data-action="rollImmobiliser">Immobiliser</button>
              <button type="button" class="chat-card-button" data-action="rollRepousser">Repousser</button>
            </li>
            <li class="item flexrow">
              <button type="button" class="chat-card-button" data-action="rollDesengager">Se désengager</button>
            </li>
          </ul>

        </div>

        {{!-- Colonne droite : Adversité --}}
        <div class="sheet-box color-bg-archetype adversite-section">

          <h4 class="adversite-section-title">Adversités</h4>
          <div class="adversite-cards">
            {{#each system.adversite as |adv key|}}
            <div class="adversite-card adversite-{{key}}" data-adversite="{{key}}">
              <div class="adversite-card-title">{{upperFirst key}}</div>
              <img class="adversite-gem" src="systems/fvtt-mournblade-cyd-2-0/assets/icons/gemme_{{key}}.webp">
              <div class="adversite-value">{{adv}}</div>
              <div class="adversite-controls">
                <a data-action="modifyAdversite" class="adv-btn adv-minus" data-adversite-value="-1">−</a>
                <a data-action="modifyAdversite" class="adv-btn adv-plus" data-adversite-value="1">+</a>
              </div>
            </div>
            {{/each}}
          </div>

          <div class="adversite-total {{#if adversiteTotal}}adversite-total-nonzero{{/if}}"
               data-tooltip="Malus soustrait à tous les jets de dés">
            <span class="adversite-total-label">Malus jets</span>
            <span class="adversite-total-value">−{{adversiteTotal}}</span>
          </div>

          <div class="sheet-box color-bg-archetype">
            <ul class="item-list alternate-list">
              <li class="item flexrow list-item items-title-bg">
                <span class="item-name-label-header">
                  <h3><label class="items-title-text">Traits Chaotiques</label></h3>
                </span>
                <div class="item-filler">&nbsp;</div>
                <div class="item-controls item-controls-fixed">
                  <a class="item-control" data-action="createItem" data-type="traitchaotique" title="Ajouter un Trait Chaotique">
                    <i class="fas fa-plus"></i>
                  </a>
                </div>
              </li>
              {{#each traitsChaotiques as |trait key|}}
              <li class="item flexrow" data-item-id="{{trait._id}}" data-item-type="traitchaotique">
                <img class="item-name-img" src="{{trait.img}}" />
                <span class="item-name-label competence-name">{{trait.name}}</span>
                <div class="item-filler">&nbsp;</div>
                <div class="item-controls item-controls-fixed">
                  <a class="item-control" data-action="editItem" title="Éditer"><i class="fas fa-edit"></i></a>
                  <a class="item-control" data-action="deleteItem" title="Supprimer"><i class="fas fa-trash"></i></a>
                </div>
              </li>
              {{/each}}
            </ul>
          </div>

          <div class="sheet-box color-bg-archetype">
            <ul class="item-list alternate-list">
              <li class="item flexrow list-item items-title-bg">
                <span class="item-name-label-header">
                  <h3><label class="items-title-text">Traits d'Espèce</label></h3>
                </span>
                <div class="item-filler">&nbsp;</div>
                <div class="item-controls item-controls-fixed">
                  <a class="item-control" data-action="createItem" data-type="traitespece" title="Ajouter un Trait d'Espèce">
                    <i class="fas fa-plus"></i>
                  </a>
                </div>
              </li>
              {{#each traitsEspeces as |trait key|}}
              <li class="item flexrow" data-item-id="{{trait._id}}" data-item-type="traitespece">
                <img class="item-name-img" src="{{trait.img}}" />
                <span class="item-name-label competence-name">{{trait.name}}</span>
                <div class="item-filler">&nbsp;</div>
                <div class="item-controls item-controls-fixed">
                  <a class="item-control" data-action="editItem" title="Éditer"><i class="fas fa-edit"></i></a>
                  <a class="item-control" data-action="deleteItem" title="Supprimer"><i class="fas fa-trash"></i></a>
                </div>
              </li>
              {{/each}}
            </ul>
          </div>

        </div>

      </div>
    </div>

    {{!-- Compétences Tab --}}
    <div class="tab competences" data-group="primary" data-tab="competences">
      <div class="flexrow">
        <div class="sheet-box color-bg-archetype">
          <ul class="item-list alternate-list">
            <li class="item flexrow list-item items-title-bg">
              <span class="item-name-label-header">
                <h3><label class="items-title-text">Compétences</label></h3>
              </span>
              <span class="item-field-label-short"><label class="short-label">Niveau</label></span>
              <div class="item-filler">&nbsp;</div>
            </li>
            {{#each skills as |skill key|}}
            <li class="item flexrow" data-item-id="{{skill._id}}" data-item-type="competence">
              <img class="item-name-img" src="{{skill.img}}" />
              <div class="flexcol item-name-label">
                <span class="item-name-label competence-name">
                  <a data-action="rollCompetence" data-attr-key="tochoose">{{skill.name}}</a>
                </span>
                <span class="predilection-text">
                  {{#each skill.system.predilections as |pred key|}}
                    {{#if (and pred.acquise (not pred.used))}}{{pred.name}}{{#unless (eq key (subtract skill.system.predilections.length 1))}}, {{/unless}}{{/if}}
                  {{/each}}
                </span>
              </div>
              <select class="status-small-label color-class-common edit-item-data competence-niveau"
                data-item-field="niveau" data-dtype="Number">
                {{selectOptions @root.config.listeNiveauCreature selected=skill.system.niveau}}
              </select>
              {{#if (ne skill.system.attribut1 "none")}}
              <button data-action="rollCompetence" class="button-sheet-roll" data-attr-key="{{skill.system.attribut1}}">{{upper skill.system.attribut1}} : {{skill.system.attribut1total}}</button>
              {{/if}}
              {{#if (ne skill.system.attribut2 "none")}}
              <button data-action="rollCompetence" class="button-sheet-roll" data-attr-key="{{skill.system.attribut2}}">{{upper skill.system.attribut2}} : {{skill.system.attribut2total}}</button>
              {{/if}}
              {{#if (ne skill.system.attribut3 "none")}}
              <button data-action="rollCompetence" class="button-sheet-roll" data-attr-key="{{skill.system.attribut3}}">{{upper skill.system.attribut3}} : {{skill.system.attribut3total}}</button>
              {{/if}}
              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control" data-action="editItem" title="Éditer"><i class="fas fa-edit"></i></a>
                <a class="item-control" data-action="deleteItem" title="Supprimer"><i class="fas fa-trash"></i></a>
              </div>
            </li>
            {{/each}}
          </ul>
        </div>
      </div>
    </div>

    {{!-- Talents Tab --}}
    <div class="tab talents" data-group="primary" data-tab="talents">
      <div class="flexrow">
        <div class="sheet-box color-bg-archetype">
          <ul class="item-list alternate-list">
            <li class="item flexrow list-item items-title-bg">
              <span class="item-name-label-header">
                <h3><label class="items-title-text">Talents</label></h3>
              </span>
              <span class="item-field-label-long2"><label class="short-label">Résumé</label></span>
              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control" data-action="createItem" data-type="talent" title="Ajouter un Talent">
                  <i class="fas fa-plus"></i>
                </a>
              </div>
            </li>
            {{#each talents as |talent key|}}
            <li class="item flexrow" data-item-id="{{talent._id}}" data-item-type="talent">
              <img class="item-name-img" src="{{talent.img}}" />
              <span class="item-name-label competence-name">{{talent.name}}</span>
              <span class="item-name-label item-field-label-long2">{{talent.system.resumebonus}}</span>
              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control" data-action="editItem" title="Éditer"><i class="fas fa-edit"></i></a>
                <a class="item-control" data-action="deleteItem" title="Supprimer"><i class="fas fa-trash"></i></a>
              </div>
            </li>
            {{/each}}
          </ul>
        </div>
      </div>
    </div>

    {{!-- Armes Tab --}}
    <div class="tab armes" data-group="primary" data-tab="armes">
      <div class="flexcol">

        <div class="sheet-box color-bg-archetype">
          <ul class="item-list alternate-list">
            <li class="item flexrow list-item items-title-bg">
              <span class="item-name-label-header">
                <h3><label class="items-title-text">Armes</label></h3>
              </span>
              <span class="item-field-label-short"><label class="short-label">Attaque</label></span>
              <span class="item-field-label-short"><label class="short-label">Défense</label></span>
              <span class="item-field-label-short"><label class="short-label">Dégâts</label></span>
              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control" data-action="createItem" data-type="arme" title="Ajouter une arme">
                  <i class="fas fa-plus"></i>
                </a>
              </div>
            </li>
            {{#each armes as |arme key|}}
            <li class="item flexrow" data-item-id="{{arme._id}}" data-item-type="arme">
              <img class="item-name-img" src="{{arme.img}}" />
              <span class="item-name-label competence-name">{{arme.name}}</span>
              <span class="item-field-label-short">
                {{#if arme.system.equipped}}
                <button data-action="rollArmeOffensif" class="button-sheet-roll">{{arme.system.totalOffensif}}</button>
                {{else}}
                <button disabled class="button-sheet-roll">{{arme.system.totalOffensif}}</button>
                {{/if}}
              </span>
              {{#if arme.system.isdefense}}
              <span class="item-field-label-short arme-defensif"><label class="defense-sheet">{{arme.system.totalDefensif}}</label></span>
              {{else}}
              <span class="item-field-label-short arme-defensif"><label class="defense-sheet">N/A</label></span>
              {{/if}}
              <span class="item-field-label-short">
                {{#if arme.system.equipped}}
                <button data-action="rollArmeDegats" class="button-sheet-roll">{{arme.system.totalDegats}}</button>
                {{else}}
                <button disabled class="button-sheet-roll">{{arme.system.totalDegats}}</button>
                {{/if}}
              </span>
              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control" data-action="equipItem" title="Équiper">
                  {{#if arme.system.equipped}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}
                </a>
                <a class="item-control" data-action="editItem" title="Éditer"><i class="fas fa-edit"></i></a>
                <a class="item-control" data-action="deleteItem" title="Supprimer"><i class="fas fa-trash"></i></a>
              </div>
            </li>
            {{/each}}
          </ul>
        </div>

        <div class="sheet-box color-bg-archetype">
          <ul class="item-list alternate-list">
            <li class="item flexrow list-item items-title-bg">
              <span class="item-name-label-header">
                <h3><label class="items-title-text">Protections</label></h3>
              </span>
              <span class="item-field-label-short"><label class="short-label">Protection</label></span>
              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control" data-action="createItem" data-type="protection" title="Ajouter une protection">
                  <i class="fas fa-plus"></i>
                </a>
              </div>
            </li>
            {{#each protections as |protection key|}}
            <li class="item flexrow" data-item-id="{{protection._id}}" data-item-type="protection">
              <img class="item-name-img" src="{{protection.img}}" />
              <span class="item-name-label competence-name">{{protection.name}}</span>
              <span class="item-field-label-short arme-defensif">
                <label class="arme-defensif">{{protection.system.protection}}</label>
              </span>
              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control" data-action="equipItem" title="Équiper">
                  {{#if protection.system.equipped}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}
                </a>
                <a class="item-control" data-action="editItem" title="Éditer"><i class="fas fa-edit"></i></a>
                <a class="item-control" data-action="deleteItem" title="Supprimer"><i class="fas fa-trash"></i></a>
              </div>
            </li>
            {{/each}}
          </ul>
        </div>

      </div>
    </div>

    {{!-- Effects Tab --}}
    <div class="tab effects" data-group="primary" data-tab="effects">
      {{> systems/fvtt-mournblade-cyd-2-0/templates/partial-active-effects.hbs}}
    </div>

    {{!-- Bio&Notes Tab --}}
    <div class="tab biodata" data-group="primary" data-tab="biodata">
      <div class="sheet-box color-bg-archetype">
        <div class="section-title">Description</div>
        <div class="editor">
          {{formInput systemFields.biodata.fields.description enriched=enrichedDescription value=system.biodata.description name="system.biodata.description" toggled=true}}
        </div>
      </div>
      <div class="sheet-box color-bg-archetype">
        <div class="section-title">Habitat</div>
        <div class="editor">
          {{formInput systemFields.biodata.fields.habitat enriched=enrichedHabitat value=system.biodata.habitat name="system.biodata.habitat" toggled=true}}
        </div>
      </div>
    </div>

  </section>
</section>
