<section class="{{cssClass}} sheet-form-layout creature-sheet" autocomplete="off">

  {{!-- Sheet Header --}}
  <header class="sheet-header">
    <div class="header-fields background-sheet-header-creature">
      <div class="flexrow">
        <img class="profile-img" src="{{actor.img}}" data-action="editImage" data-edit="img" title="{{actor.name}}" />
        <div class="flexcol header-main-content">
          <div style="display: flex; align-items: center; gap: 0.3rem; width: 100%;">
            <h1 class="charname" style="flex: 1; margin: 0; min-width: 0;"><input name="name" type="text" value="{{actor.name}}" placeholder="Name" {{#if isPlayMode}}disabled{{/if}} /></h1>
            <button type="button" class="sheet-mode-toggle" data-action="toggleSheet" data-tooltip="{{#if isEditMode}}Mode Visualisation{{else}}Mode Édition{{/if}}">
              <i class="{{#if isEditMode}}fas fa-eye{{else}}fas fa-edit{{/if}}"></i>
            </button>
          </div>
          <div style="display: flex; align-items: center; gap: 0.5rem; margin-top: 0.2rem;">
            <label style="font-size: 0.8em; white-space: nowrap;">{{localize "MNBL.creatureType"}}</label>
            <select name="system.biodata.creatureType" style="font-size: 0.8em; width: 120px;" {{#if isPlayMode}}disabled{{/if}}>
              {{selectOptions config.creatureTypeOptions selected=system.biodata.creatureType}}
            </select>
            {{#if (eq system.biodata.creatureType "elementaire")}}
            <label style="font-size: 0.8em; white-space: nowrap;">{{localize "MNBL.elementType"}}</label>
            <select name="system.biodata.elementType" style="font-size: 0.8em; width: 90px;" {{#if isPlayMode}}disabled{{/if}}>
              {{selectOptions config.elementTypeOptions selected=system.biodata.elementType}}
            </select>
            {{/if}}
            {{#if (eq system.biodata.creatureType "demon")}}
            <label style="font-size: 0.8em; white-space: nowrap;">{{localize "MNBL.demonType"}}</label>
            <select name="system.biodata.demonType" style="font-size: 0.8em; width: 130px;" {{#if isPlayMode}}disabled{{/if}}>
              {{selectOptions config.demonTypeOptions selected=system.biodata.demonType}}
            </select>
            <label style="font-size: 0.8em; white-space: nowrap;">{{localize "MNBL.demonPuissance"}}</label>
            <select name="system.biodata.demonPuissance" style="font-size: 0.8em; width: 90px;" {{#if isPlayMode}}disabled{{/if}}>
              {{selectOptions config.demonPuissanceOptions selected=system.biodata.demonPuissance}}
            </select>
            {{/if}}
            {{#if (eq system.biodata.creatureType "automaton")}}
            <label style="font-size: 0.8em; white-space: nowrap;">{{localize "MNBL.automatonType"}}</label>
            <select name="system.biodata.automatonType" style="font-size: 0.8em; width: 120px;" {{#if isPlayMode}}disabled{{/if}}>
              {{selectOptions config.automatonTypeOptions selected=system.biodata.automatonType}}
            </select>
            <label style="font-size: 0.8em; white-space: nowrap;">{{localize "MNBL.automatonPuissance"}}</label>
            <select name="system.biodata.automatonPuissance" style="font-size: 0.8em; width: 90px;" {{#if isPlayMode}}disabled{{/if}}>
              {{selectOptions config.automatonPuissanceOptions selected=system.biodata.automatonPuissance}}
            </select>
            {{#if (eq system.biodata.automatonType "voyage")}}
            <label style="font-size: 0.8em; white-space: nowrap;">{{localize "MNBL.automatonVoyageType"}}</label>
            <select name="system.biodata.automatonVoyageType" style="font-size: 0.8em; width: 130px;" {{#if isPlayMode}}disabled{{/if}}>
              {{selectOptions config.automatonVoyageTypeOptions selected=system.biodata.automatonVoyageType}}
            </select>
            {{/if}}
            {{/if}}
          </div>
        </div>
      </div>
    </div>
  </header>

  {{!-- Sheet Tab Navigation --}}
  <nav class="sheet-tabs tabs" data-group="primary">
    <a class="item" data-tab="stats">{{localize "MNBL.attributes"}}</a>
    <a class="item" data-tab="competences">{{localize "MNBL.skills"}}</a>
    <a class="item" data-tab="equipement">{{localize "MNBL.attacks"}}</a>
    <a class="item" data-tab="biodata">{{localize "MNBL.bio"}}</a>
  </nav>

  {{!-- Sheet Body --}}
  <section class="sheet-body">

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

        {{!-- Attributs Section --}}
        <div class="sheet-box color-bg-archetype">
          <div class="section-grid">
            <h4 class="section-title">{{localize "MNBL.attributes"}}</h4>
            {{#each system.attributs as |attr key|}}
            <div class="grid-row attr-row" data-attr-key="{{key}}">
              <img class="item-name-img" src="systems/fvtt-mournblade/assets/icons/{{attr.labelnorm}}.webp">
              <label class="label-name"><a data-action="rollAttribut" data-attr-key="{{key}}">{{localize attr.label}}</a></label>
              <select class="status-small-label color-class-common item-field-label-short" type="text"
                name="system.attributs.{{key}}.value" value="{{attr.value}}" data-dtype="Number" {{#if @root.isPlayMode}}disabled{{/if}}>
                {{selectOptions @root.config.listeNiveauCreature selected=attr.value}}
              </select>
            </div>
            {{/each}}
          </div>
        </div>

        {{!-- Santé & Âme Section --}}
        <div class="sheet-box color-bg-archetype">

          <div class="section-grid">
            <h4 class="section-title">{{localize "MNBL.health"}}</h4>
            <div class="grid-row">
              <label class="label-name">Total Santé</label>
              <input type="number" class="input-numeric-short" name="system.sante.base" value="{{system.sante.base}}"
                data-dtype="Number" {{#if isPlayMode}}disabled{{/if}} />
            </div>

            <div class="grid-row damage-row">
              <label class="label-name damage-label">{{localize "MNBL.nonlethal"}}</label>
              <div class="damage-controls">
                <a class="plus-minus-button" data-action="modifySante" data-type="nonletaux" data-value="-1">−</a>
                <input type="number" class="input-numeric-medium" name="system.sante.nonletaux" {{#if isPlayMode}}disabled{{/if}}
                  value="{{system.sante.nonletaux}}" data-dtype="Number" />
                <a class="plus-minus-button" data-action="modifySante" data-type="nonletaux" data-value="1">+</a>
              </div>
            </div>

            <div class="grid-row damage-row">
              <label class="label-name damage-label">{{localize "MNBL.lethal"}}</label>
              <div class="damage-controls">
                <a class="plus-minus-button" data-action="modifySante" data-type="letaux" data-value="-1">−</a>
                <input type="number" class="input-numeric-medium" name="system.sante.letaux" {{#if isPlayMode}}disabled{{/if}} value="{{system.sante.letaux}}"
                  data-dtype="Number" />
                <a class="plus-minus-button" data-action="modifySante" data-type="letaux" data-value="1">+</a>
              </div>
            </div>

            <div class="grid-row malus-row">
              <label class="label-name">{{localize "MNBL.malus"}}</label>
              <input type="number" class="input-numeric-short" name="system.sante.malusmanuel" {{#if isPlayMode}}disabled{{/if}}
                value="{{system.sante.malusmanuel}}" data-dtype="Number" />
              <label class="label-name">{{localize "MNBL.automalus"}}</label>
              <div class="malus-value">{{santeMalus}}</div>
            </div>
          </div>

          <div class="section-grid">
            <h4 class="section-title">{{localize "MNBL.soul"}}</h4>
            <div class="grid-row">
              <label class="label-name">Max Absolu</label>
              <input type="number" class="input-numeric-short" name="system.ame.fullmax" value="{{system.ame.fullmax}}"
                data-dtype="Number" {{#if isPlayMode}}disabled{{/if}} />
              <label class="label-name">{{localize "MNBL.currentmax"}}</label>
              <input type="number" class="input-numeric-short" name="system.ame.currentmax"
                value="{{system.ame.currentmax}}" data-dtype="Number" {{#if isPlayMode}}disabled{{/if}} />
            </div>

            <div class="grid-row soul-consumed-row">
              <label class="label-name">{{localize "MNBL.consumed"}}</label>
              <div class="damage-controls">
                <a class="plus-minus-button" data-action="modifyAme" data-value="-1">−</a>
                <input type="number" class="input-numeric-medium" name="system.ame.value" value="{{system.ame.value}}"
                  data-dtype="Number" {{#if isPlayMode}}disabled{{/if}} />
                <a class="plus-minus-button" data-action="modifyAme" data-value="1">+</a>
              </div>
            </div>

            <div class="grid-row">
              <label class="label-name">{{localize "MNBL.automalus"}}</label>
              <div class="malus-value">{{ameMalus}}</div>
            </div>
          </div>

        </div>

      </div>
    </div>

    {{!-- Compétences Tab --}}
    <div class="tab competences scrollable" data-group="primary" data-tab="competences">
      <div class="section-grid">
        <h4 class="section-title">{{localize "MNBL.skills"}}</h4>
        <ul class="item-list compact-list">
          <li class="item flexrow list-item items-title-bg">
            <span class="item-name-label-header">{{localize "MNBL.skills"}}</span>
            <span class="item-field-label-short">{{localize "MNBL.level"}}</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|}}
                {{pred.name}},
                {{/each}}
              </span>
            </div>
            <select class="status-small-label color-class-common edit-item-data competence-niveau" type="text"
              data-item-field="niveau" data-dtype="Number" {{#if @root.isPlayMode}}disabled{{/if}}>
              {{selectOptions @root.config.listeNiveauSkill selected=skill.system.niveau}}
            </select>

            {{#if (ne skill.system.attribut1 "none")}}
            <span class="item-field-label-short">
              <button class="button-sheet-roll" data-action="rollCompetence" data-attr-key="{{skill.system.attribut1}}">{{upper
                skill.system.attribut1}} : {{skill.system.attribut1total}}</button>
            </span>
            {{/if}}
            {{#if (ne skill.system.attribut2 "none")}}
            <span class="item-field-label-short">
              <button class="button-sheet-roll" data-action="rollCompetence" data-attr-key="{{skill.system.attribut2}}">{{upper
                skill.system.attribut2}} : {{skill.system.attribut2total}}</button>
            </span>
            {{/if}}
            {{#if (ne skill.system.attribut3 "none")}}
            <span class="item-field-label-short">
              <button class="button-sheet-roll" data-action="rollCompetence" data-attr-key="{{skill.system.attribut3}}">{{upper
                skill.system.attribut3}} : {{skill.system.attribut3total}}</button>
            </span>
            {{/if}}

            <div class="item-filler">&nbsp;</div>
            <div class="item-controls item-controls-fixed">
              <a data-action="editItem" title="Edit Item"><i class="fas fa-edit"></i></a>
              <a data-action="deleteItem" title="Delete Item"><i class="fas fa-trash"></i></a>
            </div>
          </li>
          {{/each}}
        </ul>
      </div>
    </div>

    {{!-- Équipement/Armes Tab --}}
    <div class="tab equipement scrollable" data-group="primary" data-tab="equipement">
      <div class="section-grid">
        <h4 class="section-title">{{localize "MNBL.weapons"}}</h4>
        <ul class="item-list compact-list">
          <li class="item flexrow list-item items-title-bg">
            <span class="item-name-label-header">{{localize "MNBL.weapons"}}</span>
            <span class="item-field-label-short">{{localize "MNBL.attack"}}</span>
            <span class="item-field-label-short">{{localize "MNBL.damage"}}</span>
            <div class="item-filler">&nbsp;</div>
            <div class="item-controls item-controls-fixed">
              <a 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>

            {{#if arme.system.isDistance}}
            <span class="item-field-label-short">
              <button class="button-sheet-roll" data-action="rollArmeSpecial" data-arme-id="{{arme._id}}">{{localize "MNBL.use"}}</button>
            </span>
            {{else}}
              <span class="item-field-label-short">
                <button class="button-sheet-roll" data-action="rollArmeOffensif" data-arme-id="{{arme._id}}">{{arme.system.totalOffensif}}</button>
              </span>
            {{/if}}

            <span class="item-field-label-short">
              <button class="button-sheet-roll" data-action="rollArmeDegats" data-arme-id="{{arme._id}}">{{arme.system.totalDegats}}</button>
            </span>

            <div class="item-filler">&nbsp;</div>
            <div class="item-controls item-controls-fixed">
              <a data-action="editItem" title="Edit Item"><i class="fas fa-edit"></i></a>
              <a data-action="deleteItem" title="Delete Item"><i class="fas fa-trash"></i></a>
            </div>
          </li>
          {{/each}}
        </ul>
      </div>

      {{#if (count protections)}}
      <div class="section-grid">
        <h4 class="section-title">{{localize "MNBL.protections"}}</h4>
        <ul class="item-list compact-list">
          <li class="item flexrow list-item items-title-bg">
            <span class="item-name-label-header">{{localize "MNBL.protection"}}</span>
            <span class="item-field-label-short">{{localize "MNBL.pr"}}</span>
            <div class="item-filler">&nbsp;</div>
          </li>
          {{#each protections as |protection key|}}
          <li class="item flexrow" data-item-id="{{protection._id}}">
            <img class="item-name-img" src="{{protection.img}}" />
            <span class="item-name-label">{{protection.name}}</span>
            <span class="item-field-label-short">{{protection.system.pr}}</span>
            <div class="item-filler">&nbsp;</div>
            <div class="item-controls item-controls-fixed">
              <a data-action="editItem" title="Edit Item"><i class="fas fa-edit"></i></a>
              <a data-action="deleteItem" title="Delete Item"><i class="fas fa-trash"></i></a>
            </div>
          </li>
          {{/each}}
          <li class="item flexrow">
            <label class="label-name">{{localize "MNBL.totalprotection"}}</label>
            <div class="protection-value">{{protectionTotal}}</div>
          </li>
        </ul>
      </div>
      {{/if}}

      <div class="section-grid">
        <h4 class="section-title">{{localize "MNBL.capacites"}}</h4>
        <ul class="item-list compact-list">
          <li class="item flexrow list-item items-title-bg">
            <span class="item-name-label-header">{{localize "MNBL.capacites"}}</span>
            <div class="item-filler">&nbsp;</div>
            <div class="item-controls item-controls-fixed">
              <a data-action="createItem" data-type="capacite" title="Ajouter une capacité"><i class="fas fa-plus"></i></a>
            </div>
          </li>
          {{#each capacites as |capacite key|}}
          <li class="item flexrow" data-item-id="{{capacite._id}}" data-item-type="capacite">
            <img class="item-name-img" src="{{capacite.img}}" />
            <span class="item-name-label">{{capacite.name}}</span>
            <div class="item-filler">&nbsp;</div>
            <div class="item-controls item-controls-fixed">
              <a data-action="postItem" data-item-id="{{capacite._id}}" title="Poster dans le chat"><i class="fas fa-comment"></i></a>
              <a data-action="editItem" title="Éditer"><i class="fas fa-edit"></i></a>
              <a data-action="deleteItem" title="Supprimer"><i class="fas fa-trash"></i></a>
            </div>
          </li>
          {{/each}}
        </ul>
      </div>

    </div>

    {{!-- Bio Tab --}}
    <div class="tab biodata scrollable" data-group="primary" data-tab="biodata">

      {{#if isGM}}
      <div class="section-grid gm-tools-section">
        <h4 class="section-title">{{localize "MNBL.gmtools"}}</h4>
        <div class="grid grid-2col" style="gap: 0.5rem; margin: 0;">
          <div>
            <ul class="item-list compact-list">
              <li class="flexrow item">
                <label class="label-name">{{localize "MNBL.soulmultiplier"}}</label>
                <input type="number" class="input-numeric-short" name="system.biodata.amemultiplier"
                  value="{{system.biodata.amemultiplier}}" data-dtype="Number" {{#if isPlayMode}}disabled{{/if}} />
              </li>
            </ul>
          </div>
          <div>
            <ul class="item-list compact-list">
              <li class="flexrow item">
                <label class="label-name">{{localize "MNBL.ignorehealthmalus"}} ?</label>
                <input type="checkbox" name="system.biodata.ignoresantemalus" {{checked system.biodata.ignoresantemalus}} {{#if isPlayMode}}disabled{{/if}} />
              </li>
              <li class="flexrow item">
                <label class="label-name">{{localize "MNBL.ignoresoulmalus"}} ?</label>
                <input type="checkbox" name="system.biodata.ignoreamemalus" {{checked system.biodata.ignoreamemalus}} {{#if isPlayMode}}disabled{{/if}} />
              </li>
            </ul>
          </div>
        </div>
      </div>
      {{/if}}

      <div class="section-grid">
        <h4 class="section-title">Description</h4>
        <div class="medium-editor item-text-long-line">
          {{formInput systemFields.biodata.fields.description enriched=enrichedDescription value=system.biodata.description name="system.biodata.description" toggled=true}}
        </div>
      </div>
    </div>

  </section>
</section>
