{{!-- 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">

    {{!-- Attributs Section --}}
    {{#if (eq attrKey "tochoose")}}
      <div class="form-group attributes-section">
        <label>Attribut principal</label>
        <select id="attrKey" name="attrKey">
          {{#each selectableAttributes as |attr key|}}
            <option value="{{key}}" {{#if (eq ../attrKey key)}}selected{{/if}}>
              {{attr.label}} ({{attr.value}})
            </option>
          {{/each}}
        </select>
      </div>
    {{/if}}

    {{#if hasAttr2}}
      <div class="form-group">
        <label>Attribut secondaire</label>
        <select id="attrKey2" name="attrKey2">
          {{#each selectableAttributes as |attr key|}}
            <option value="{{key}}" {{#if (eq ../attrKey2 key)}}selected{{/if}}>
              {{attr.label}} ({{attr.value}})
            </option>
          {{/each}}
        </select>
      </div>
    {{/if}}

    {{!-- Adversité et Modificateurs --}}
    <div class="modifiers-grid">
      <div class="form-group">
        <label>Adversité</label>
        <input type="text" value="{{nbAdversites}}" disabled />
      </div>

      {{#unless isTir}}
      <div class="form-group">
        <label>Difficulté</label>
        <select id="difficulte" name="difficulte">
          {{#each config.optionsDifficulte as |opt|}}
            <option value="{{opt.key}}" {{#if (eq ../difficulte opt.key)}}selected{{/if}}>{{opt.label}}</option>
          {{/each}}
        </select>
      </div>
      {{/unless}}

      <div class="form-group">
        <label>Modificateur</label>
        <select id="modificateur" name="modificateur">
          {{#each config.optionsBonusMalus as |opt|}}
            <option value="{{opt.key}}" {{#if (eq ../modificateur opt.key)}}selected{{/if}}>{{opt.label}}</option>
          {{/each}}
        </select>
      </div>

      <div class="form-group">
        <label>Soutiens</label>
        <select id="soutiens" name="soutiens">
          {{#each config.optionsSoutiens as |opt|}}
            <option value="{{opt.key}}" {{#if (eq ../soutiens opt.key)}}selected{{/if}}>{{opt.label}}</option>
          {{/each}}
        </select>
      </div>
    </div>

    {{!-- Compétence et Maîtrise --}}
    {{#if competence}}
      <div class="competence-section">
        <div class="competence-info">
          <span class="competence-label">{{competence.name}}</span>
          <span class="competence-niveau">Niveau {{competence.system.niveau}}</span>
        </div>

        {{#if competence.system.maitrise}}
          <div class="form-group">
            <label>Maîtrise</label>
            <select id="select-maitrise" name="maitrise">
              {{#each competence.system.maitrise as |mait|}}
                <option value="{{mait._id}}">{{mait.name}}</option>
              {{/each}}
            </select>
          </div>
        {{/if}}

        {{#if competence.system.talents}}
          <div class="form-group talents-group">
            <label>Talents disponibles</label>
            <select id="competence-talents" name="talents" multiple size="4">
              {{#each competence.system.talents as |talent|}}
                <option value="{{talent._id}}">{{talent.name}}</option>
              {{/each}}
            </select>
            <small class="help-text">Maintenez Ctrl/Cmd pour sélection multiple</small>
          </div>
        {{/if}}
      </div>
    {{/if}}

    {{!-- Combat Modifiers --}}
    {{#if isCombat}}
      <div class="combat-modifiers">
        <h4><i class="fa-solid fa-crossed-swords"></i> Modificateurs de Combat</h4>

        {{#unless isTir}}
        <div class="modifiers-columns">
          <div class="modifiers-column">
            {{#if bonusArmeNaturelle}}
            <div class="form-group">
              <label>Arme naturelle/fortune en défense</label>
              <span>{{bonusArmeNaturelle}}</span>
            </div>
            {{/if}}

            <label class="checkbox-label">
              <input type="checkbox" id="defenseur-au-sol" name="defenseurAuSol" {{#if defenseurAuSol}}checked{{/if}} />
              <span>En surplomb, défenseur au sol (+3)</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="attaquants-multiple" name="attaquantsMultiple" {{#if attaquantsMultiple}}checked{{/if}} />
              <span>Attaquants multiples (après le premier) (+3)</span>
            </label>

            {{#if hasAmbidextre}}
            <label class="checkbox-label">
              <input type="checkbox" id="ambidextre-1" name="ambidextre1" {{#if ambidextre1}}checked{{/if}} />
              <span>Première attaque avec deux armes (-3)</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="ambidextre-2" name="ambidextre2" {{#if ambidextre2}}checked{{/if}} />
              <span>Seconde attaque avec deux armes (-6)</span>
            </label>
            {{/if}}

            {{#if hasFeinte}}
            <label class="checkbox-label">
              <input type="checkbox" id="feinte" name="feinte" {{#if feinte}}checked{{/if}} />
              <span>Feinte (<strong>coût : 1 BA</strong>)</span>
            </label>
            {{/if}}

            <label class="checkbox-label">
              <input type="checkbox" id="defenseur-aveugle" name="defenseurAveugle" {{#if defenseurAveugle}}checked{{/if}} />
              <span>Défenseur aveuglé (+10)</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="defenseur-de-dos" name="defenseurDeDos" {{#if defenseurDeDos}}checked{{/if}} />
              <span>Défenseur de dos (+5)</span>
            </label>
          </div>

          <div class="modifiers-column">
            <label class="checkbox-label">
              <input type="checkbox" id="defenseur-restreint" name="defenseurRestreint" {{#if defenseurRestreint}}checked{{/if}} />
              <span>Défenseur dans espace restreint (+3)</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="defenseur-immobilise" name="defenseurImmobilise" {{#if defenseurImmobilise}}checked{{/if}} />
              <span>Défenseur immobilisé (+5)</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="attaque-charge" name="attaqueCharge" {{#if attaqueCharge}}checked{{/if}} />
              <span>Charge</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="contenir" name="contenir" {{#if contenir}}checked{{/if}} />
              <span>Contenir</span>
            </label>
            <label class="checkbox-label">
              <input type="checkbox" id="attaque-desarme" name="attaqueDesarme" {{#if attaqueDesarme}}checked{{/if}} />
              <span>Désarmer (SD+10)</span>
            </label>

            {{#if isMonte}}
            <label class="checkbox-label">
              <input type="checkbox" id="charge-cavalerie" name="chargeCavalerie" {{#if chargeCavalerie}}checked{{/if}} />
              <span>Charge de cavalerie</span>
            </label>
            {{/if}}
          </div>
        </div>
        {{/unless}}

        {{#if isTir}}
          <div class="tir-modifiers">
            <div class="form-group">
              <label>SD de distance</label>
              <select id="distance-tir" name="distanceTir">
                {{#each config.optionsDistanceTir as |opt|}}
                  <option value="{{opt.key}}" {{#if (eq ../distanceTir opt.key)}}selected{{/if}}>{{opt.label}}</option>
                {{/each}}
              </select>
            </div>

            <div class="form-group">
              <label>Tireur en déplacement ?</label>
              <select id="tireur-deplacement" name="tireurDeplacement">
                {{#each config.optionsTireurDeplacement as |opt|}}
                  <option value="{{opt.key}}" {{#if (eq ../tireurDeplacement opt.key)}}selected{{/if}}>{{opt.label}}</option>
                {{/each}}
              </select>
            </div>

            <div class="form-group">
              <label>Couvert de la cible ?</label>
              <select id="cible-couvert" name="cibleCouvert">
                {{#each config.optionsCouvert as |opt|}}
                  <option value="{{opt.key}}" {{#if (eq ../cibleCouvert opt.key)}}selected{{/if}}>{{opt.label}}</option>
                {{/each}}
              </select>
            </div>

            <div class="form-group">
              <label>Taille de la cible ?</label>
              <select id="taille-cible" name="tailleCible">
                {{#each config.optionsTailleCible as |opt|}}
                  <option value="{{opt.key}}" {{#if (eq ../tailleCible opt.key)}}selected{{/if}}>{{opt.label}}</option>
                {{/each}}
              </select>
            </div>

            <div class="modifiers-columns">
              <label class="checkbox-label">
                <input type="checkbox" id="cible-deplace" name="cibleDeplace" {{#if cibleDeplace}}checked{{/if}} />
                <span>Cible se déplace vite (SD+3)</span>
              </label>
              <label class="checkbox-label">
                <input type="checkbox" id="cible-cac" name="cibleCaC" {{#if cibleCaC}}checked{{/if}} />
                <span>Cible corps à corps (SD+3)</span>
              </label>
            </div>
          </div>
        {{/if}}
      </div>
    {{/if}}
  </div>
