{{!-- 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 (and attr (ne attrKey "tochoose"))}}
          <span class="attribut-info"> ({{attr.label}}: {{attr.value}})</span>
        {{/if}}
      </div>
    {{else if charme}}
      <div class="competence-name">
        {{charme.name}}
      </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</label>
      <select id="attrKey" name="attrKey">
        {{selectOptions config.attributs selected=attrKey}}
      </select>
    </div>
  {{/if}}

  {{!-- Charme Section --}}
  {{#if charme}}
    <div class="form-group">
      <label>Dé additionnel</label>
      <select id="charmeDice" name="charmeDice">
        {{selectOptions config.dices selected=charmeDice}}
      </select>
    </div>
  {{/if}}

  {{!-- Arme Section --}}
  {{#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>

      {{#if arme.system.isMelee}}
        <div class="form-group">
          <label>Type d'attaque</label>
          <select id="typeAttaque" name="typeAttaque">
            {{selectOptions config.attaques selected=typeAttaque}}
          </select>
        </div>

        {{#if isMonte}}
          <label class="checkbox-label">
            <input type="checkbox" id="isMonte" name="isMonte" {{checked isMonte}} />
            <span>Bonus d'attaque monté (+5)</span>
          </label>
        {{/if}}
      {{/if}}

      {{#if difficulte}}
        <div class="defense-info">
          <span class="defense-label">Défense de la cible</span>
          <span class="defense-value">{{difficulte}}</span>
        </div>
      {{/if}}

      {{!-- Combat à distance --}}
      {{#if arme.system.isDistance}}
        <div class="ranged-combat-section">
          <h4>Modificateurs de Tir</h4>

          <label class="checkbox-label">
            <input type="checkbox" id="visee" name="visee" {{checked visee}} />
            <span>Visée (+5)</span>
          </label>

          {{#if defender}}
            <label class="checkbox-label">
              <input type="checkbox" id="cibleconsciente" name="cibleconsciente" {{checked cibleconsciente}} />
              <span>Cible voit le tir (-{{defender.system.attributs.adr.value}})</span>
            </label>
          {{else}}
            <div class="info-message">
              Pas de cible sélectionnée
            </div>
          {{/if}}

          <label class="checkbox-label">
            <input type="checkbox" id="ciblecourt" name="ciblecourt" {{checked ciblecourt}} />
            <span>Cible en déplacement</span>
          </label>

          <div class="modifiers-grid">
            <div class="form-group">
              <label>Couvert</label>
              <select id="typeCouvert" name="typeCouvert">
                {{selectOptions config.couverts labelAttr="name" selected=typeCouvert}}
              </select>
            </div>

            <div class="form-group">
              <label>Portée</label>
              <select id="difficulte" name="difficulte">
                {{selectOptions config.listePortees selected=difficulte}}
              </select>
            </div>
          </div>
        </div>
      {{/if}}
    </div>
  {{/if}}

  {{!-- Désavantages positionnels --}}
  {{#if hasDesavantageBonus}}
    <div class="combat-modifiers">
      <h4>Avantages Tactiques</h4>

      <div class="modifiers-columns">
        <label class="checkbox-label">
          <input type="checkbox" id="cibleausol" name="cibleausol" {{checked cibleausol}} />
          <span>Cible au sol (+5)</span>
        </label>

        <label class="checkbox-label">
          <input type="checkbox" id="cibledesarmee" name="cibledesarmee" {{checked cibledesarmee}} />
          <span>Cible désarmée (+5)</span>
        </label>

        <label class="checkbox-label">
          <input type="checkbox" id="ciblerestreint" name="ciblerestreint" {{checked ciblerestreint}} />
          <span>Espace restreint (+5)</span>
        </label>

        <label class="checkbox-label">
          <input type="checkbox" id="cibleimmobilisée" name="cibleimmobilisée" {{checked cibleimmobilisée}} />
          <span>Cible immobilisée (+5)</span>
        </label>

        <label class="checkbox-label">
          <input type="checkbox" id="ciblesurplomb" name="ciblesurplomb" {{checked ciblesurplomb}} />
          <span>En surplomb (+5)</span>
        </label>
      </div>
    </div>
  {{/if}}

  {{!-- Modificateur manuel et difficulté --}}
  <div class="modifiers-grid">
    <div class="form-group">
      <label>Modificateur</label>
      <select id="modificateur" name="modificateur">
        {{selectOptions config.modificateurOptions valueAttr="key" nameAttr="key" labelAttr="label" selected=modificateur}}
      </select>
    </div>

    {{#if charme}}
      {{!-- Pas de difficulté pour charme --}}
    {{else if armeDefense}}
      <div class="form-group">
        <label>Défense adversaire</label>
        <input type="number" value="{{difficulte}}" disabled />
      </div>
    {{else}}
      <div class="form-group">
        <label>Difficulté</label>
        <select id="difficulte" name="difficulte">
          {{selectOptions config.difficulteOptions selected=difficulte}}
        </select>
      </div>
    {{/if}}
  </div>

  {{!-- Double D20 --}}
  {{#if canEclatDoubleD20}}
    <div class="special-option">
      <label class="checkbox-label highlight">
        <input type="checkbox" id="doubleD20" name="doubleD20" {{checked doubleD20}} />
        <span>Double D20 (1 Point d'Éclat)</span>
      </label>
    </div>
  {{/if}}

</div>
