<section>
  <div class="header">
    <img class="item-img" src="{{item.img}}" data-edit="img" data-action="editImage" data-tooltip="{{item.name}}" />
    {{formInput fields.name value=source.name}}
  </div>

  {{! Navigation des onglets }}
  <nav class="sheet-tabs tabs" data-group="primary">
    <a class="item {{tabs.details.cssClass}}" data-tab="details">{{localize "PRISMRPG.Label.details"}}</a>
    <a class="item {{tabs.advancements.cssClass}}" data-tab="advancements">{{localize "PRISMRPG.Label.advancement"}}</a>
    <a class="item {{tabs.description.cssClass}}" data-tab="description">{{localize "PRISMRPG.Label.description"}}</a>
  </nav>

  {{! Onglet Details }}
  <div class="tab {{tabs.details.cssClass}}" data-group="primary" data-tab="details">
  <div class="flexrow">
    <div class="align-top">

      {{! Class Type and Archetype }}
      {{formField systemFields.archetype value=system.archetype localize=true}}

      {{formField systemFields.classType value=system.classType localize=true}}

      {{#if (eq system.classType "continental")}}
        {{formField systemFields.continent value=system.continent}}
      {{/if}}

      {{formField systemFields.level value=system.level}}

    </div>
    <div class="align-top">

      {{! Proficiencies }}
      {{formField systemFields.weaponProficiencies value=system.weaponProficiencies}}

      {{formField systemFields.armorProficiencies value=system.armorProficiencies}}

      {{! Spellcasting }}
      {{formField systemFields.spellcasting value=system.spellcasting}}

      {{#if system.spellcasting}}
        {{formField systemFields.spellcastingType value=system.spellcastingType localize=true}}
      {{/if}}

    </div>
  </div>

  {{! Attribute Bonuses }}
  <fieldset>
    <legend>{{localize "PRISMRPG.Label.attributeBonuses"}}</legend>
    {{formInput
      systemFields.attributeBonuses
      enriched=enrichedAttributeBonuses
      value=system.attributeBonuses
      name="system.attributeBonuses"
      toggled=true
    }}
  </fieldset>

  {{! Class Features }}
  <fieldset>
    <legend>{{localize "PRISMRPG.Label.classFeatures"}}</legend>

    {{#each system.features as |feature level|}}
        <label>{{localize "PRISMRPG.Label.level"}} {{replace @key "level" ""}}</label>
        {{formInput
          (lookup ../systemFields.features.fields @key)
          enriched=(lookup ../enrichedFeatures @key)
          value=feature
          name=(concat "system.features." @key)
          toggled=true
        }}
    {{/each}}
  </fieldset>
  </div>

  {{! Onglet Advancements }}
  <div class="tab {{tabs.advancements.cssClass}}" data-group="primary" data-tab="advancements">
    <fieldset>
      <legend>{{localize "PRISMRPG.Label.advancement"}}</legend>

      {{#each advancementsByLevel as |levelData|}}
        <div class="advancement-level">
          <h3>
            <span class="level-title">{{localize "PRISMRPG.Label.level"}} {{levelData.level}}</span>
            <button type="button" class="add-advancement" data-level="{{levelData.levelKey}}" data-tooltip="{{localize 'PRISMRPG.Label.addAdvancement'}}">
              <i class="fas fa-plus"></i>
            </button>
          </h3>

          {{#if levelData.advancements.length}}
            <div class="advancement-list">
              {{#each levelData.advancements as |advancement|}}
                <div class="advancement-item">
                  <div class="advancement-header">
                    <img class="advancement-icon" src="{{advancement.icon}}" data-level="{{advancement.levelKey}}" data-index="{{advancement.index}}" />
                    {{formInput
                      ../../systemFields.advancements.fields.level1.element.fields.name
                      value=advancement.name
                      name=(concat "system.advancements." advancement.levelKey "." advancement.index ".name")
                      placeholder=(localize "PRISMRPG.Label.advancementName")
                    }}
                    <button type="button" class="toggle-advancement-description" data-tooltip="{{localize 'PRISMRPG.Label.toggleDescription'}}">
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <button type="button" class="delete-advancement" data-level="{{advancement.levelKey}}" data-index="{{advancement.index}}" data-tooltip="{{localize 'PRISMRPG.Label.deleteAdvancement'}}">
                      <i class="fas fa-trash"></i>
                    </button>
                  </div>
                  <div class="advancement-description collapsed">
                    {{formInput
                      ../../systemFields.advancements.fields.level1.element.fields.description
                      enriched=advancement.enrichedDescription
                      value=advancement.description
                      name=(concat "system.advancements." advancement.levelKey "." advancement.index ".description")
                      toggled=true
                    }}
                  </div>
                </div>
              {{/each}}
            </div>
          {{else}}
            <p class="empty-advancements">{{localize "PRISMRPG.Label.noAdvancements"}}</p>
          {{/if}}
        </div>
      {{/each}}
    </fieldset>
  </div>

  {{! Onglet Description }}
  <div class="tab {{tabs.description.cssClass}}" data-group="primary" data-tab="description">
    <fieldset>
      <legend>{{localize "PRISMRPG.Label.description"}}</legend>
      {{formInput
        systemFields.description
        enriched=enrichedDescription
        value=system.description
        name="system.description"
        toggled=true
      }}
    </fieldset>

    {{! Notes }}
    <fieldset>
      <legend>{{localize "PRISMRPG.Label.notes"}}</legend>
      {{formInput
        systemFields.notes
        enriched=enrichedNotes
        value=system.notes
        name="system.notes"
        toggled=true
      }}
    </fieldset>
  </div>

</section>
