<section
  class="character-main character-main-{{ifThen isPlayMode 'play' 'edit'}}"
>
  {{log "character-main context" this}}
  {{log "isEditMode" isEditMode "isPlayMode" isPlayMode}}
  <fieldset>
    <legend>{{localize "HAMALRON.Label.character"}}</legend>
    <div class="character-pc character-pc-{{ifThen isPlayMode 'play' 'edit'}}">
      <div class="character-left">
        <div class="character-left-image">
          <img
            class="character-img"
            src="{{actor.img}}"
            data-edit="img"
            data-action="editImage"
            data-tooltip="{{actor.name}}"
          />
        </div>
        <fieldset class="character-definition">
          <div class="flexcol">
            <div class="form-group">
              <label>{{localize "HAMALRON.Label.peuple"}}</label>
              <div class="item-controls">
                {{#if peuple}}
                  <span class="item-name">{{peuple.name}}</span>
                  {{#if isEditMode}}
                    <a
                      class="control"
                      data-action="edit"
                      data-item-id="{{peuple._id}}"
                      data-item-uuid="{{peuple.uuid}}"
                      data-tooltip="Éditer"
                    >
                      <i class="fa-solid fa-edit"></i>
                    </a>
                    <a
                      class="control"
                      data-action="delete"
                      data-item-uuid="{{peuple.uuid}}"
                      data-tooltip="Supprimer"
                    >
                      <i class="fa-solid fa-trash"></i>
                    </a>
                  {{/if}}
                {{else}}
                  <span class="item-name">-</span>
                {{/if}}
              </div>
            </div>
            <div class="form-group">
              <label>{{localize "HAMALRON.Label.faction"}}</label>
              <div class="item-controls">
                {{#if faction}}
                  <span class="item-name">{{faction.name}}</span>
                  {{#if isEditMode}}
                    <a
                      class="control"
                      data-action="edit"
                      data-item-id="{{faction._id}}"
                      data-item-uuid="{{faction.uuid}}"
                      data-tooltip="Éditer"
                    >
                      <i class="fa-solid fa-edit"></i>
                    </a>
                    <a
                      class="control"
                      data-action="delete"
                      data-item-uuid="{{faction.uuid}}"
                      data-tooltip="Supprimer"
                    >
                      <i class="fa-solid fa-trash"></i>
                    </a>
                  {{/if}}
                {{else}}
                  <span class="item-name">-</span>
                {{/if}}
              </div>
            </div>
          </div>
        </fieldset>
      </div>

      <div class="character-right">
        <div class="character-name">
          <input
            type="text"
            name="name"
            value="{{source.name}}"
            {{#if isPlayMode}}disabled{{/if}}
          />
          <a
            class="control"
            data-action="toggleSheet"
            data-tooltip="HAMALRON.ToggleSheet"
            data-tooltip-direction="UP"
          >
            <i class="fa-solid fa-user-{{ifThen isPlayMode 'lock' 'pen'}}"></i>
          </a>
        </div>

        <fieldset
          class="character-stats character-stats-{{ifThen
              isPlayMode
              'play'
              'edit'
            }}"
        >
          <legend>{{localize "HAMALRON.Label.cartesSucces"}}</legend>
          {{log "cartesSucces data:" system.cartesSucces}}
          <div class="stats-grid">
            {{#each system.cartesSucces as |carte symbole|}}
              {{log "Processing carte:" symbole carte "isEditMode in loop:" ../isEditMode}}
              <div class="character-stat">
                <label
                  class="rollable stat-label"
                  data-roll-type="carte"
                  data-symbole-id="{{symbole}}"
                >
                  {{carte.label}}
                </label>
                <div class="stat-values">
                  {{log "In stat-values, isEditMode:" ../isEditMode}}
                  {{#if ../isEditMode}}
                    {{log "Rendering input for carte"}}
                    <input
                      type="number"
                      name="system.cartesSucces.{{symbole}}.value"
                      value="{{carte.value}}"
                    />
                  {{else}}
                    {{log "Rendering span for carte"}}
                    <span class="stat-value">{{carte.value}}</span>
                  {{/if}}
                </div>
              </div>
            {{/each}}
          </div>
        </fieldset>

        <fieldset class="character-resistances">
          <legend>
            {{localize "HAMALRON.Label.resistances"}}
            {{#unless isEditMode}}
              <a class="control" data-action="openRecovery" data-tooltip="{{localize 'HAMALRON.Recovery.Title'}}" data-tooltip-direction="UP">
                <i class="fas fa-bed"></i>
              </a>
            {{/unless}}
          </legend>
          <div class="resistances-grid">
            {{#each system.resistances as |resistance symbole|}}
              <div class="resistance-stat">
                <label class="stat-label">{{resistance.label}}</label>
                <div class="stat-values">
                  {{#if ../isEditMode}}
                    <input
                      type="number"
                      name="system.resistances.{{symbole}}.value"
                      value="{{resistance.value}}"
                    />
                    <span class="separator">/</span>
                    <input
                      type="number"
                      name="system.resistances.{{symbole}}.max"
                      value="{{resistance.max}}"
                    />
                  {{else}}
                    <a
                      class="control resistance-control"
                      data-action="modifyResistance"
                      data-symbole="{{symbole}}"
                      data-delta="-1"
                      data-tooltip="Diminuer"
                    >
                      <i class="fa-solid fa-minus"></i>
                    </a>
                    <span class="stat-value">{{resistance.value}}</span>
                    <span class="separator">/</span>
                    <span class="stat-value">{{resistance.max}}</span>
                    <a
                      class="control resistance-control"
                      data-action="modifyResistance"
                      data-symbole="{{symbole}}"
                      data-delta="1"
                      data-tooltip="Augmenter"
                    >
                      <i class="fa-solid fa-plus"></i>
                    </a>
                  {{/if}}
                </div>
              </div>
            {{/each}}
          </div>
        </fieldset>

        {{#if (and system.blessureIncapacitante isPlayMode)}}
          <div class="wound-banner">
            <i class="fas fa-bandage"></i>
            {{localize "HAMALRON.Wound.Active"}} ({{system.malusBlessure}})
            <a class="control" data-action="removeWound" data-tooltip="{{localize 'HAMALRON.Wound.Remove'}}">
              <i class="fa-solid fa-check"></i>
            </a>
          </div>
        {{/if}}
      </div>
    </div>
  </fieldset>
</section>