<div class="roll-dialog-content">
  <!-- HIDDEN DATA -->
  <input type="hidden" name="label" id="label" value="{{ label }}" />
  <input type="hidden" name="rollType" id="rollType" value="{{ rollType }}" />
  <input type="hidden" name="abilityScore" id="abilityScore" value="{{ abilityScore }}" />
  <input type="hidden" name="skillScore" id="skillScore" value="{{ skillScore }}" />
  <input type="hidden" name="speakerId" value="{{ speakerId }}" />
  <input type="hidden" name="skillLabel" value="{{ skill }}" />

  <div class="dice-pool">
    
    <!-- MAIN ROLL SELECTION -->
    <div class="flexrow main-roll-section">
      
      <!-- CHARACTERISTIC -->
      <div class="flexcol characteristic-section">
        <label class="label">{{localize 'VERMINE.ability'}}</label>
        <select
          class="info-value"
          data-roll="true"
          data-dtype="String"
          type="number"
          name="ability"
          id="ability"
          min="1"
          max="5"
        >
          <option value="0">-- {{localize 'VERMINE.choose_ability'}} --</option>
          {{#each config.abilityCategories as |abilCategory catkey|}}
            <optgroup label="{{ smarttlk 'ABILITY_CATEGORIES' catkey 'name' }}">
              {{#each @root.actor.system.abilities as |abil key|}}
                {{#ife abil.category catkey}}
                  <option
                    value="{{abil.value}}"
                    data-label="{{key}}"
                    data-category="{{abil.category}}"
                    {{#ife @root.rollType "ability"}}
                      {{#ife @root.labelKey key}}
                        selected="true"
                      {{/ife}}
                    {{/ife}}
                  >
                    {{ smarttlk 'ABILITIES' key 'name' }} / {{abil.value}}
                  </option>
                {{/ife}}
              {{/each}}
            </optgroup>
          {{/each}}
        </select>
        <div class="ability-score flexrow">
          <span id="abilityScore">{{localize 'VERMINE.score'}}: </span>
          <span id="abilityScoreValue">0</span>
        </div>
      </div>

      <!-- SKILL -->
      <div class="flexcol skill-section">
        <label class="label">{{localize 'VERMINE.skill_title'}}</label>
        <select
          class="info-value"
          data-roll="true"
          data-dtype="String"
          type="number"
          name="skill"
          id="skill"
          min="1"
          max="5"
        >
          <option value="">-- {{localize 'VERMINE.choose_skill'}} --</option>
          {{#each config.skillCategories as |skillCategory catkey|}}
            <optgroup label="{{ smarttlk 'SKILLS_CATEGORIES' catkey 'name' }}">
              {{#each @root.actor.system.skills as |skill key|}}
                {{#ife skill.category catkey}}
                  <option
                    value="{{skill.value}}"
                    data-pool="{{skillLevel 'dicePool' skill.value}}"
                    data-label="{{key}}"
                    data-category="{{skill.category}}"
                    data-reroll="{{skillLevel 'reroll' skill.value}}"
                    {{#ife @root.rollType "skill"}}
                      {{#ife @root.labelKey key}}
                        selected="true"
                      {{/ife}}
                    {{/ife}}
                  >
                    <b>{{ smarttlk 'SKILLS' key 'name' }}</b> / 
                    <i>{{skillLevel "label" skill.value}}</i>
                  </option>
                {{/ife}}
              {{/each}}
            </optgroup>
          {{/each}}
        </select>
      </div>
    </div>

    <!-- SPECIALTIES (shown when skill selected) -->
    {{#if availableSpecialties.length}}
      <details class="specialties-section">
        <summary class="flexrow">
          <span class="label">{{localize 'VERMINE.specialty'}} (+1D)</span>
          <span class="current-specialty">{{localize 'VERMINE.none'}}</span>
        </summary>
        <div class="flexrow specialty-options">
          <label class="flexrow">
            <input
              type="radio"
              data-roll="true"
              name="usingSpecialization"
              id="usingSpecialization"
              value="aucune"
            />
            <span>{{localize 'VERMINE.none'}}</span>
          </label>
          {{#each availableSpecialties as |spec ind|}}
            <label class="flexrow">
              <input
                type="radio"
                data-roll="true"
                name="usingSpecialization"
                id="usingSpecialization"
                value="{{spec.name}}"
                data-spec-skill="{{spec.system.skill}}"
                {{#if specialty}}checked{{/if}}
              />
              <span>{{spec.name}}</span>
            </label>
          {{/each}}
        </div>
      </details>
    {{/if}}

    <!-- DIFFICULTY AND HANDICAP -->
    <details class="difficulty-section" open>
      <summary class="flexrow">
        <span class="label">{{localize 'VERMINE.difficulty'}}</span>
        <span class="current-values">
          <span id="current-difficulty">{{localize 'DIFFICULTY_LEVELS.hard'}} (7)</span>
          <span id="current-handicap">{{localize 'VERMINE.none'}}</span>
        </span>
      </summary>
      <div class="flexrow difficulty-controls">
        <div class="flexcol">
          <label class="label" for="difficulty">{{localize 'VERMINE.difficulty'}}</label>
          <select
            class="info-value"
            data-roll="true"
            data-dtype="String"
            type="number"
            name="difficulty"
            id="difficulty"
            min="3"
            max="10"
          >
              <option value="{{ diffLevel 'difficulty' 1}}">{{ diffLevel 'label' 1}} ({{ diffLevel 'difficulty' 1}})</option>
              <option value="{{ diffLevel 'difficulty' 2}}">{{ diffLevel 'label' 2}} ({{ diffLevel 'difficulty' 2}})</option>
              <option value="{{ diffLevel 'difficulty' 3}}" selected>{{ diffLevel 'label' 3}} ({{ diffLevel 'difficulty' 3}})</option>
              <option value="{{ diffLevel 'difficulty' 4}}">{{ diffLevel 'label' 4}} ({{ diffLevel 'difficulty' 4}})</option>
              <option value="{{ diffLevel 'difficulty' 5}}">{{ diffLevel 'label' 5}} ({{ diffLevel 'difficulty' 5}})</option>
          </select>
        </div>
        <div class="flexcol">
          <label class="label" for="handicap">{{localize 'VERMINE.handicap'}}</label>
          <select
            class="info-value"
            data-roll="true"
            data-dtype="String"
            type="number"
            name="handicap"
            id="handicap"
            min="0"
            max="3"
          >
            <option value="1" selected>{{localize 'VERMINE.none'}}</option>
            <option value="2">(I)</option>
            <option value="3">(II)</option>
            <option value="4">(III)</option>
          </select>
        </div>
      </div>
    </details>

    <!-- BONUSES SECTION -->
    <details class="bonuses-section">
      <summary class="flexrow">
        <span class="label">{{localize 'VERMINE.bonuses'}}</span>
        <span class="bonus-count">+<span id="total-bonus">0</span>D</span>
      </summary>
      <div class="grid grid-2col bonus-grid">
        
        <!-- HELP -->
        <div class="flexrow bonus-item">
          <input
            type="checkbox"
            data-roll="true"
            name="helped"
            id="helped"
            value="1"
            {{#if help}}checked{{/if}}
          />
          <label class="label" for="helped">{{localize 'VERMINE.help'}} (+1D)</label>
        </div>

        <!-- GROUP -->
        <div class="flexrow bonus-item">
          <label class="label" for="group">{{localize 'VERMINE.bonus_supplementary'}}</label>
          <input
            type="number"
            data-roll="true"
            class="numeric-entry"
            style="text-align: center;"
            name="group"
            id="group"
            min="0"
            max="5"
            value="0"
          />
          <span>D</span>
        </div>

        <!-- SELF CONTROL -->
        <div class="flexrow bonus-item full-width">
          <label class="label" for="self_control">
            {{localize 'VERMINE.self_control'}} 
            <span>(+<span id="self_control_value">0</span>D)</span>
          </label>
          <input
            type="range"
            id="self_control"
            data-roll="true"
            name="self_control"
            min="0"
            max="0"
            value="0"
          />
        </div>

        <!-- TOOLS -->
        <div class="flexrow bonus-item full-width">
          <label class="label">{{localize 'VERMINE.tooling'}} (+1D / +2D)</label>
          <div class="item-list grid grid-4col">
            <label>
              <input
                type="radio"
                data-roll="true"
                name="usingTools"
                id="usingTools"
                value="0"
                checked
              />
              <i>{{localize 'VERMINE.none'}}</i>
            </label>
            {{#each availableItems as |item ind|}}
              <label>
                <input
                  type="radio"
                  data-roll="true"
                  name="usingTools"
                  id="usingTools"
                  value="{{item.name}}"
                />
                <i>{{item.name}}{{#if item.system.traits.pratique}} <em class="tool-bonus">+2D</em>{{/if}}{{#if item.system.traits.ponctuel}} <em class="tool-ponctuel">P{{item.system.traits.ponctuel.value}}</em>{{/if}}</i>
              </label>
            {{/each}}
          </div>
        </div>

        <!-- INTIMIDANT -->
        {{#if hasIntimidant}}
        <div class="flexrow bonus-item full-width">
          <input type="checkbox" data-roll="true" name="intimidant" id="intimidant" value="1" />
          <label class="label" for="intimidant">{{ localize 'VERMINE.intimidant_check' intimidantName=intimidantName }}</label>
        </div>
        {{/if}}

        <!-- TEMPORARY MALUS -->
        <div class="flexrow bonus-item full-width">
          <label class="label" for="temporary-malus">{{localize 'VERMINE.temporary_malus'}}</label>
          <input
            type="number"
            data-roll="true"
            class="numeric-entry"
            style="text-align: center;"
            name="temporary-malus"
            id="temporary-malus"
            min="0"
            max="5"
            value="0"
          />
          <span>D</span>
        </div>

        <!-- TOTEMS -->
        {{#ifgt @root.actor.system.adaptation.totems.human.value 0}}
          {{#ifgt @root.actor.system.adaptation.totems.adapted.value 0}}
            <div class="flexrow bonus-item full-width totems-section">
              <label class="label">{{localize 'VERMINE.totem_dice'}}</label>
              <div class="flexrow totem-options">
                <label class="totem-option">
                  <input
                    type="checkbox"
                    data-roll="true"
                    name="human-totem"
                    id="human-totem"
                    value="1"
                    class="totem-checkbox"
                  />
                  <span class="totem-label">{{localize 'TOTEMS.human.name'}}</span>
                  <small>({{@root.actor.system.adaptation.totems.human.value}}D)</small>
                </label>
                <label class="totem-option">
                  <input
                    type="checkbox"
                    data-roll="true"
                    name="adapted-totem"
                    id="adapted-totem"
                    value="1"
                    class="totem-checkbox"
                  />
                  <span class="totem-label">{{localize 'TOTEMS.adapted.name'}}</span>
                  <small>({{@root.actor.system.adaptation.totems.adapted.value}}D)</small>
                </label>
              </div>
              <small class="totem-hint">{{localize 'VERMINE.totem_hint'}}</small>
            </div>
          {{else}}
            {{#ifgt @root.actor.system.adaptation.totems.human.value 0}}
              <div class="flexrow bonus-item totems-section">
                <label class="totem-option">
                  <input
                    type="checkbox"
                    data-roll="true"
                    name="human-totem"
                    id="human-totem"
                    value="1"
                  />
                  <span class="totem-label">{{localize 'TOTEMS.human.name'}}</span>
                  <small>({{@root.actor.system.adaptation.totems.human.value}}D)</small>
                </label>
              </div>
            {{/ifgt}}
          {{/ifgt}}
        {{else}}
          {{#ifgt @root.actor.system.adaptation.totems.adapted.value 0}}
            <div class="flexrow bonus-item totems-section">
              <label class="totem-option">
                <input
                  type="checkbox"
                  data-roll="true"
                  name="adapted-totem"
                  id="adapted-totem"
                  value="1"
                />
                <span class="totem-label">{{localize 'TOTEMS.adapted.name'}}</span>
                <small>({{@root.actor.system.adaptation.totems.adapted.value}}D)</small>
              </label>
            </div>
          {{/ifgt}}
        {{/ifgt}}

      </div>
    </details>

    <!-- EXPERIENCE DICE -->
    {{#if experience.hasExperience}}
    <details class="experience-section">
      <summary class="flexrow">
        <span class="label">{{localize 'VERMINE.experience_transfer'}}</span>
        <span class="current-values">{{localize 'VERMINE.experience_dice'}}: <span id="exp-individual">{{experience.individual}}</span>D</span>
      </summary>
      <div class="flexcol experience-controls">
        <div class="flexrow bonus-item">
          <label class="label" for="experience-pull">{{localize 'VERMINE.experience_pull'}}</label>
          <select class="info-value" data-roll="true" id="experience-pull" name="experience-pull"
            {{#unless experience.canPull}}disabled{{/unless}}>
            {{#each experience.pullOptions}}
            <option value="{{this}}">{{this}}D</option>
            {{/each}}
          </select>
          <span class="experience-group">{{localize 'VERMINE.collective_group'}}: <span id="exp-group">{{experience.groupPool}}</span>D</span>
        </div>
        <div class="flexrow bonus-item">
          <button type="button" data-action="giveToGroup" {{#unless experience.canGive}}disabled{{/unless}}>
            <i class="fas fa-share"></i> {{localize 'VERMINE.experience_give'}}
          </button>
        </div>
      </div>
    </details>
    {{/if}}

    <!-- TOTAL DICE POOL -->
    <div class="flexrow total-section">
      <label class="label">{{localize 'VERMINE.total'}}:</label>
      <span id="dice-pool-total" class="total-value">0D</span>
      {{#ifgt @root.actor.system.adaptation.totems.human.value 0}}
        {{#ifgt @root.actor.system.adaptation.totems.adapted.value 0}}
          <span class="totem-selector">
            ({{localize 'VERMINE.keep_totem'}}
            <select id="keep-totem-select" name="keep_totem">
              <option value="human">{{localize 'TOTEMS.human.name'}}</option>
              <option value="adapted">{{localize 'TOTEMS.adapted.name'}}</option>
            </select>)
          </span>
        {{/ifgt}}
      {{/ifgt}}
    </div>

  </div>

  <footer class="sheet-footer flexrow">
    <button type="button" data-action="cancel">
      <i class="fas fa-times"></i> {{localize "VERMINE.cancel"}}
    </button>
    <button type="button" data-action="roll">
      <i class="fas fa-check"></i> {{localize "VERMINE.roll"}}
    </button>
  </footer>
</div>
