{{!-- Header --}}
<div class="dialog-header">
  <img class="actor-icon" src="{{img}}" alt="{{name}}" />
  <div class="dialog-title">
    <h3>{{name}}</h3>
    {{#if competence}}
      <div class="competence-name">
        {{competence.name}}
        {{#if arme}}— {{arme.name}}{{/if}}
        {{#if (and attr (ne attrKey "tochoose"))}}
          <span class="attribut-info"> ({{attr.label}} : {{attr.value}})</span>
        {{/if}}
      </div>
    {{else}}
      {{#if (and attr (ne attrKey "tochoose"))}}
        <div class="competence-name">
          <span class="attribut-info">{{attr.label}} : {{attr.value}}</span>
        </div>
      {{/if}}
    {{/if}}
  </div>
</div>

{{!-- Main Content --}}
<div class="dialog-content">

  {{!-- Attribut à choisir --}}
  {{#if (eq attrKey "tochoose")}}
    <div class="form-group attributes-section">
      <label>Attribut</label>
      <select id="attrKey" name="attrKey">
        {{selectOptions attributs selected=attrKey}}
      </select>
    </div>
  {{/if}}

  {{!-- Second attribut (hors compétence) --}}
  {{#if (not competence)}}
    <div class="form-group">
      <label>Second attribut</label>
      <select id="attrKey2" name="attrKey2">
        {{#select attrKey2}}
        <option value="none">{{localize "MNBL.none"}}</option>
        {{#each attributs as |attrLabel attrKey|}}
          <option value="{{attrKey}}">{{attrLabel}}</option>
        {{/each}}
        {{/select}}
      </select>
    </div>
  {{/if}}

  {{!-- Malus d'adversités (CYD 2.0) --}}
  {{#if nbAdversites}}
    <div class="malus-section">
      <div class="malus-grid">
        <div class="malus-item">
          <span class="malus-label">Malus d'adversités</span>
          <span class="malus-value">- {{nbAdversites}}</span>
        </div>
      </div>
    </div>
  {{/if}}

  {{!-- Compétence + Maîtrises --}}
  {{#if competence}}
    <div class="form-group">
      <label>{{competence.name}}</label>
      <span class="field-value">{{competence.system.niveau}}</span>
    </div>
    {{#if maitrises}}
    <div class="form-group">
      <label>Utiliser une maîtrise</label>
      <select id="select-maitrise" name="select-maitrise">
        {{selectOptions maitrises selected=maitriseId valueAttr="key" nameAttr="key" labelAttr="label"}}
      </select>
    </div>
    {{/if}}
  {{/if}}

  {{!-- Talents --}}
  {{#if (count talents)}}
    <div class="form-group">
      <label>Talents</label>
      <select class="flex1" name="competence-talents" id="competence-talents" multiple>
        {{#each talents as |talent key|}}
          <option value="{{talent._id}}">{{talent.name}}</option>
        {{/each}}
      </select>
    </div>
  {{/if}}

  {{!-- Conditions communes (hors arme) --}}
  {{#if conditionsCommunes}}
    <div class="combat-modifiers">
      <h4>Avantages Tactiques</h4>
      <div class="modifiers-columns">
        <label class="checkbox-label">
          <input type="checkbox" id="defenseur-au-sol" {{checked defenseurAuSol}} />
          <span>En surplomb / défenseur au sol (+3)</span>
        </label>
        <label class="checkbox-label">
          <input type="checkbox" id="defenseur-aveugle" {{checked defenseurAveugle}} />
          <span>Défenseur aveuglé (+10)</span>
        </label>
        <label class="checkbox-label">
          <input type="checkbox" id="defenseur-de-dos" {{checked defenseurDeDos}} />
          <span>Défenseur de dos (+5)</span>
        </label>
        <label class="checkbox-label">
          <input type="checkbox" id="defenseur-immobilise" {{checked defenseurImmobilise}} />
          <span>Défenseur immobilisé (+5)</span>
        </label>
      </div>
    </div>
  {{/if}}

  {{!-- Manœuvres spéciales (immobiliser / repousser) --}}
  {{#if (or immobiliser repousser)}}
    <div class="form-group">
      <label class="checkbox-label">
        <input type="checkbox" id="cibleconsciente" {{checked cibleconsciente}} />
        <span>Cible consciente</span>
      </label>
    </div>
  {{/if}}

  {{!-- Rune --}}
  {{#if rune}}
    <div class="rune-section">
      <div class="form-group">
        <label>Rune</label>
        <span class="field-value">{{rune.name}}{{#if rune.system.formule}} — {{rune.system.formule}}{{/if}}</span>
      </div>
      <div class="form-group">
        <label>Mode de lancement</label>
        <select id="runemode" name="runemode">
          {{selectOptions config.lancementRuneOptions selected=runemode}}
        </select>
      </div>
      <div class="form-group">
        <label>{{localize "MNBL.soulpoints"}} (Pouvoir)</label>
        <select id="runeame" name="runeame">
          {{selectOptions config.pointsAmeOptions selected=runeame}}
        </select>
      </div>
    </div>
  {{/if}}

  {{!-- Section arme --}}
  {{#if arme}}
    <div class="weapon-section">
      <div class="weapon-info">
        <span class="weapon-label">{{arme.name}}</span>
        <span class="weapon-bonus">+{{arme.system.bonusmaniementoff}}</span>
      </div>

      {{!-- Arme de mêlée --}}
      {{#if arme.system.isMelee}}
        {{#if bonusArmeNaturelle}}
          <div class="form-group">
            <label>Arme naturelle/fortune</label>
            <span class="field-value">{{bonusArmeNaturelle}}</span>
          </div>
        {{/if}}

        <h4>Modificateurs de Combat</h4>
        <div class="modifiers-columns">
          <label class="checkbox-label">
            <input type="checkbox" id="defenseur-au-sol" {{checked defenseurAuSol}} />
            <span>En surplomb / défenseur au sol (+3)</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="attaquants-multiple" {{checked attaquantsMultiples}} />
            <span>Attaquants multiples (+3)</span>
          </label>
          {{#if hasAmbidextre}}
          <label class="checkbox-label">
            <input type="checkbox" id="ambidextre-1" {{checked attaqueAmbidextre1}} />
            <span>1ère attaque avec deux armes (-3)</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="ambidextre-2" {{checked attaqueAmbidextre2}} />
            <span>2ème attaque avec deux armes (-6)</span>
          </label>
          {{/if}}
          {{#if hasFeinte}}
          <label class="checkbox-label">
            <input type="checkbox" id="feinte" {{checked feinte}} />
            <span>Feinte <strong>(coût : 1 BA)</strong></span>
          </label>
          {{/if}}
          <label class="checkbox-label">
            <input type="checkbox" id="defenseur-aveugle" {{checked defenseurAveugle}} />
            <span>Défenseur aveuglé (+10)</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="defenseur-de-dos" {{checked defenseurDeDos}} />
            <span>Défenseur de dos (+5)</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="defenseur-restreint" {{checked defenseurRestreint}} />
            <span>Espace restreint (+3)</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="defenseur-immobilise" {{checked defenseurImmobilise}} />
            <span>Défenseur immobilisé (+5)</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="attaque-charge" {{checked attaqueCharge}} />
            <span>Charge</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="contenir" {{checked contenir}} />
            <span>Contenir</span>
          </label>
          <label class="checkbox-label">
            <input type="checkbox" id="attaque-desarme" {{checked attaqueDesarme}} />
            <span>Désarmer (SD+10)</span>
          </label>
          {{#if isMonte}}
          <label class="checkbox-label">
            <input type="checkbox" id="charge-cavalerie" {{checked chargeCavalerie}} />
            <span>Charge de cavalerie</span>
          </label>
          {{/if}}
        </div>

        <div class="form-group">
          <label>Soutiens</label>
          <select id="soutiens" name="soutiens">
            {{selectOptions config.optionsSoutiens selected=soutiens valueAttr="key" nameAttr="key" labelAttr="label"}}
          </select>
        </div>
      {{/if}}

      {{!-- Arme à distance --}}
      {{#if arme.system.isDistance}}
        <div class="ranged-combat-section">
          <h4>Modificateurs de Tir</h4>
          <div class="modifiers-columns">
            <label class="checkbox-label">
              <input type="checkbox" id="tireur-cible-deplace" {{checked cibleDeplace}} />
              <span>Cible se déplace vite (SD+3)</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="tireur-cible-cac" {{checked cibleCaC}} />
              <span>Cible en corps-à-corps (SD+3)</span>
            </label>
          </div>
          <div class="modifiers-grid">
            <div class="form-group">
              <label>Tireur en déplacement</label>
              <select id="tireur-deplacement" name="tireur-deplacement">
                {{selectOptions config.optionsTireurDeplacement selected=tireurDeplacement valueAttr="key" nameAttr="key" labelAttr="label"}}
              </select>
            </div>
            <div class="form-group">
              <label>Couvert de la cible</label>
              <select id="cible-couvert" name="cible-couvert">
                {{selectOptions config.optionsCouvert selected=cibleCouvert valueAttr="key" nameAttr="key" labelAttr="label"}}
              </select>
            </div>
            <div class="form-group">
              <label>Taille de la cible</label>
              <select id="taille-cible" name="taille-cible">
                {{selectOptions config.optionsTailleCible selected=tailleCible valueAttr="key" nameAttr="key" labelAttr="label"}}
              </select>
            </div>
            <div class="form-group">
              <label>SD distance</label>
              <select id="distance-tir" name="distance-tir">
                {{selectOptions config.optionsDistanceTir selected=distanceTir valueAttr="key" nameAttr="key" labelAttr="label"}}
              </select>
            </div>
          </div>
        </div>
      {{/if}}

      {{!-- SD de l'adversaire (mêlée) --}}
      {{#if (and armeDefense (not arme.system.isDistance))}}
        <div class="defense-info">
          <span class="defense-label">{{#if desengager}}C. Offensive adversaire{{else}}C. Défensive adversaire{{/if}}</span>
          <span class="defense-value">{{difficulte}}</span>
        </div>
      {{/if}}
    </div>
  {{/if}}

  {{!-- Bonus / Malus contextuel et Difficulté --}}
  <div class="modifiers-grid">
    <div class="form-group">
      <label>Bonus / Malus</label>
      <select id="bonus-malus-context" name="bonus-malus-context">
        {{selectOptions config.optionsBonusMalus selected=bonusMalusContext valueAttr="key" nameAttr="key" labelAttr="label"}}
      </select>
    </div>

    {{#if (not isInit)}}
      {{#unless (or armeDefense arme.system.isDistance)}}
        <div class="form-group">
          <label>{{localize "MNBL.difficulty"}}</label>
          <select id="difficulte" name="difficulte">
            {{selectOptions config.optionsDifficulte selected=difficulte valueAttr="key" nameAttr="key" labelAttr="label"}}
          </select>
        </div>
      {{/unless}}
    {{/if}}
  </div>

</div>
