<div class="vermine-roll-message" data-free-successes="{{verdict.bonusSuccesses}}" data-actor-id="{{param.actor.id}}" data-actor-uuid="{{param.actor.uuid}}">
  {{!-- Verdict --}}
  <div class="roll-verdict {{#if verdict.success}}success{{else}}failure{{/if}}">
    {{#if verdict.success}}
      <i class="fas fa-check-circle"></i>
      <span>{{localize "VERMINE.roll_success"}}</span>
    {{else}}
      <i class="fas fa-times-circle"></i>
      <span>{{localize "VERMINE.roll_failure"}}</span>
    {{/if}}
  </div>

  <h3>{{param.actor.name}} : {{localize "VERMINE.test_of"}} {{param.rollLabel}}</h3>

  {{#if param.weapon}}
  <div class="weapon-block">
    <div class="weapon-block-header flexrow">
      <span class="weapon-icon"><i class="fas fa-crosshairs"></i></span>
      <span class="weapon-name">{{param.weapon.name}}</span>
      {{#if param.targets.length}}
      <span class="weapon-targets"><i class="fas fa-bullseye"></i> {{param.targets}}</span>
      {{/if}}
    </div>
    <div class="flexrow flex-wrap weapon-details">
      <span class="weapon-detail">
        <strong>{{localize "VERMINE.damages"}}:</strong>
        {{#if param.weapon.system.damage.addVigor}}{{localize "ADVERSITY.vigor"}}+ {{/if}}
        {{param.weapon.system.damage.value}} ({{param.weapon.system.damage.type}})
      </span>
      <span class="weapon-detail">
        <strong>{{localize "VERMINE.ranges"}}:</strong>
        {{param.weapon.system.min_range}} / {{param.weapon.system.max_range}}
      </span>
      {{#if param.effectiveRange}}
      <span class="weapon-detail">
        <strong>{{localize "VERMINE.effective_range"}}:</strong>
        {{param.effectiveRange}} m
      </span>
      {{/if}}
      <span class="weapon-detail">
        <strong>{{localize "VERMINE.ammo"}}:</strong>
        {{param.weapon.system.ammo}}
      </span>
    </div>
    {{#if param.weapon.system.traits}}
    <div class="flexrow flex-wrap weapon-traits">
      <span class="weapon-detail weapon-traits-label">
        <strong>{{localize "VERMINE.traits"}}:</strong>
      </span>
      {{#each param.weapon.system.traits as |trait key|}}
      {{#if trait}}
      <span class="weapon-trait" data-tooltip="{{trait.description}}">{{trait.name}}{{#if trait.value}} ({{trait.value}}){{/if}}</span>
      {{/if}}
      {{/each}}
    </div>
    {{/if}}
    {{#if param.weapon.system.traits.duree}}
    <div class="weapon-detail duree-note"><i class="fas fa-hourglass-half"></i> {{ localize 'VERMINE.duree_note' value=param.weapon.system.traits.duree.value }}</div>
    {{/if}}
  </div>
  {{/if}}

  {{#if param.attack}}
  <div class="exchange-actions" data-exchange-id="{{param.attack.id}}">
    <div class="exchange-header"><i class="fas fa-exchange-alt"></i> {{localize "VERMINE.exchange"}}</div>
    {{#if param.attack.rapideHandicap}}
    <div class="exchange-reminder"><i class="fas fa-bolt"></i> {{ localize 'VERMINE.rapide_note' handicap=param.attack.rapideHandicap }}</div>
    {{/if}}
    {{#if param.attack.zoneValue}}
    <div class="exchange-reminder"><i class="fas fa-burst"></i> {{ localize 'VERMINE.zone_note' value=param.attack.zoneValue }}</div>
    {{/if}}
    {{#each param.attack.targets}}
    <div class="exchange-target">
      <span class="exchange-target-name"><i class="fas fa-bullseye"></i> {{this.name}}</span>
      {{#if this.canDefend}}
      <button type="button" class="exchange-defend" data-type="esquive" data-target-id="{{this.id}}" data-target-uuid="{{this.uuid}}" title="{{localize 'VERMINE.defense_esquive'}}"><i class="fas fa-running"></i> {{localize "VERMINE.defense_esquive"}}</button>
      {{#ife @root.param.attack.mode "contact"}}
      <button type="button" class="exchange-defend" data-type="parade" data-target-id="{{this.id}}" data-target-uuid="{{this.uuid}}" title="{{localize 'VERMINE.defense_parade'}}"><i class="fas fa-shield-alt"></i> {{localize "VERMINE.defense_parade"}}</button>
      {{/ife}}
      {{else}}
      <span class="exchange-passive"><i class="fas fa-shield-virus"></i> {{localize "VERMINE.passive_defense"}}</span>
      {{/if}}
      {{#if @root.param.weapon.system.traits.incapacitant}}
      <button type="button" class="exchange-incapacitant" data-target-id="{{this.id}}" data-target-uuid="{{this.uuid}}" data-value="{{@root.param.weapon.system.traits.incapacitant.value}}" title="{{localize 'VERMINE.incapacitant_roll'}}"><i class="fas fa-bolt"></i> {{localize "VERMINE.incapacitant_roll"}} ({{@root.param.weapon.system.traits.incapacitant.value}})</button>
      {{/if}}
    </div>
    {{/each}}
    <button type="button" class="exchange-resolve" data-exchange-id="{{param.attack.id}}"><i class="fas fa-balance-scale"></i> {{localize "VERMINE.resolve"}}</button>
    {{#if param.attack.zoneValue}}
    <button type="button" class="exchange-zone" data-exchange-id="{{param.attack.id}}"><i class="fas fa-burst"></i> {{ localize "VERMINE.zone_apply" }}</button>
    {{/if}}
  </div>
  {{/if}}

  {{!-- Context --}}
  <div class="roll-context flexrow flex-wrap">
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.difficulty"}}</span>
      <span class="context-value" id="difficulty">{{param.difficulty}}</span>
    </div>
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.success_required"}}</span>
      <span class="context-value">{{verdict.required}}</span>
    </div>
    {{#if param.handicap}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.handicap"}}</span>
      <span class="context-value">+{{param.handicap}}</span>
    </div>
    {{/if}}
    {{#if param.mobilityHandicap}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.mobility"}}</span>
      <span class="context-value">{{ localize 'VERMINE.traits_mobility_note' handicap=param.mobilityHandicap }}</span>
    </div>
    {{/if}}
    {{#if verdict.bonusSuccesses}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.auto_successes"}}</span>
      <span class="context-value">+{{verdict.bonusSuccesses}}</span>
    </div>
    {{/if}}
    {{#if param.intimidant}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.intimidant"}}</span>
      <span class="context-value">{{#if param.intimidant.psychology}}{{localize "VERMINE.intimidant_psychology"}}{{else}}{{localize "VERMINE.intimidant_reroll"}}{{/if}}</span>
    </div>
    {{/if}}
    {{#if param.ponctuelUsed}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.ponctuel"}}</span>
      <span class="context-value">{{ localize 'VERMINE.ponctuel_used' value=param.ponctuelUsed }}</span>
    </div>
    {{/if}}
    {{#if param.specialtyName}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.specialty"}}</span>
      <span class="context-value">+1D {{param.specialtyName}}</span>
    </div>
    {{/if}}
    {{#if param.self_control}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.self_control"}}</span>
      <span class="context-value">+{{param.self_control}}D</span>
    </div>
    {{/if}}
    {{#if param.totems.human}}
    <div class="context-item totem-human">
      <span class="context-label">{{localize "VERMINE.totem_used"}}</span>
      <span class="context-value">{{localize "TOTEMS.human.name"}}{{#ife param.keepTotem "human"}} ({{localize "VERMINE.totem_keep"}}){{/ife}}</span>
    </div>
    {{/if}}
    {{#if param.totems.adapted}}
    <div class="context-item totem-adapted">
      <span class="context-label">{{localize "VERMINE.totem_used"}}</span>
      <span class="context-value">{{localize "TOTEMS.adapted.name"}}{{#ife param.keepTotem "adapted"}} ({{localize "VERMINE.totem_keep"}}){{/ife}}</span>
    </div>
    {{/if}}
    {{#if param.skillLevel}}
    <div class="context-item">
      <span class="context-label">{{localize "VERMINE.skill_mastery"}}</span>
      <span class="context-value">{{skillLevel "label" param.skillLevel}}</span>
    </div>
    {{/if}}
  </div>

  {{!-- Dice pool breakdown --}}
  {{#if param.poolBreakdown}}
  <div class="roll-pool">
    <h4>{{localize "VERMINE.roll_pool"}}</h4>
    <div class="flexrow flex-wrap pool-breakdown">
      {{#if param.poolBreakdown.ability}}
      <span class="pool-item">{{localize "VERMINE.pool_ability"}} {{param.poolBreakdown.ability}}D</span>
      {{/if}}
      {{#if param.poolBreakdown.skill}}
      <span class="pool-item">{{localize "VERMINE.pool_skill"}} {{param.poolBreakdown.skill}}D</span>
      {{/if}}
      {{#if param.poolBreakdown.specialty}}
      <span class="pool-item">{{localize "VERMINE.pool_specialty"}} +{{param.poolBreakdown.specialty}}D</span>
      {{/if}}
      {{#if param.poolBreakdown.help}}
      <span class="pool-item">{{localize "VERMINE.pool_help"}} +{{param.poolBreakdown.help}}D</span>
      {{/if}}
    {{#if param.poolBreakdown.tooling}}
    <span class="pool-item">{{localize "VERMINE.pool_tooling"}} +{{param.poolBreakdown.tooling}}D</span>
    {{/if}}
    {{#if param.poolBreakdown.tempMalus}}
    <span class="pool-item pool-malus">{{localize "VERMINE.pool_temp_malus"}} -{{param.poolBreakdown.tempMalus}}D</span>
    {{/if}}
    {{#if param.poolBreakdown.psychology}}
    <span class="pool-item pool-malus">{{localize "VERMINE.pool_psychology"}} -{{param.poolBreakdown.psychology}}D</span>
    {{/if}}
      {{#if param.poolBreakdown.group}}
      <span class="pool-item">{{localize "VERMINE.bonus_supplementary"}} +{{param.poolBreakdown.group}}D</span>
      {{/if}}
      {{#if param.poolBreakdown.pools}}
      <span class="pool-item">{{localize "VERMINE.pool_pools"}} +{{param.poolBreakdown.pools}}D</span>
      {{/if}}
      {{#if param.poolBreakdown.experience}}
      <span class="pool-item">{{localize "VERMINE.pool_experience"}} +{{param.poolBreakdown.experience}}D</span>
      {{/if}}
      {{#if param.poolBreakdown.selfControl}}
      <span class="pool-item">{{localize "VERMINE.pool_selfControl"}} +{{param.poolBreakdown.selfControl}}D</span>
      {{/if}}
      {{#if param.poolBreakdown.domainBonus}}
      <span class="pool-item">{{#ifgt param.poolBreakdown.domainBonus 0}}{{localize "VERMINE.domain_bonus"}}{{else}}{{localize "VERMINE.domain_penalty"}}{{/ifgt}} {{param.poolBreakdown.domainBonus}}D</span>
      {{/if}}
    {{#unless param.poolBreakdown.wound}}
    {{#unless param.poolBreakdown.lourd}}
    {{#if param.poolBreakdown.malus}}
    <span class="pool-item pool-malus">{{localize "VERMINE.pool_malus"}} -{{param.poolBreakdown.malus}}D</span>
    {{/if}}
    {{/unless}}
    {{/unless}}
    {{#if param.poolBreakdown.wound}}
    <span class="pool-item pool-malus">{{localize "VERMINE.pool_wound"}} -{{param.poolBreakdown.wound}}D</span>
    {{/if}}
    {{#if param.poolBreakdown.lourd}}
    <span class="pool-item pool-malus">{{localize "VERMINE.pool_lourd"}} -{{param.poolBreakdown.lourd}}D</span>
    {{/if}}
      <span class="pool-item pool-total">{{localize "VERMINE.pool_total"}} {{param.poolBreakdown.total}}D</span>
    </div>
  </div>
  {{/if}}

  <div class="reroll-fromroll">
    <h4>{{localize "VERMINE.rerolls_possible"}} : <span id="allowed_reroll">{{param.Reroll}}</span></h4>
    <div class="reroll flexrow">
      {{#ifgt param.actor.system.attributes.effort.value 0}}
      <div class="reroll-from-effort flexrow">
        <h4 class="flexcol">
          <span>{{localize "VERMINE.effort"}}</span>
          <span class="effort-pool">{{param.actor.system.attributes.effort.value}}/{{param.actor.system.attributes.effort.max}}</span>
        </h4>
        <input type="range" 
          min="0"
          max="{{param.max_effort}}"
          value="0"
          id="effort-reroll">
        </input>
        <button class="grant-reroll" data-tooltip="{{localize 'VERMINE.grant_reroll'}}"> 
          <span id="granted-reroll">0</span> 
        </button>
      </div>
      {{/ifgt}}
    </div>
  </div>

  {{!-- Dice results --}}
  <ul class="flexrow roll-results initial-roll" data-difficulty="{{param.difficulty}}">
    {{#each roll.dice as |dieType index|}}
      {{#each dieType.results as |die index|}}
        {{! Determine dice class and type based on flavor (leading token) }}
        {{#ifStartsWith dieType.options.flavor "human_"}}
          {{set diceClass="human"}}
          {{set diceTypeVal="human"}}
        {{else ifStartsWith dieType.options.flavor "adapted_"}}
          {{set diceClass="adapted"}}
          {{set diceTypeVal="adapted"}}
        {{else}}
          {{set diceClass="regular"}}
          {{set diceTypeVal="regular"}}
        {{/ifStartsWith}}
        <li class="roll die flexcol {{diceClass}} {{#if die.success}}success{{/if}}"
          data-dice-type="{{diceTypeVal}}"
          data-result="{{die.result}}">
          <span>{{die.result}}</span>
        </li>
      {{/each}}
    {{/each}}
  </ul>

  {{!-- Dice summary --}}
  <div class="roll-dice-summary flexrow">
    {{#if diceStats.regular.count}}
    <span class="die-summary regular">{{diceStats.regular.count}} {{localize "VERMINE.die_regular"}} · {{diceStats.regular.success}} {{localize "VERMINE.die_successes"}}</span>
    {{/if}}
    {{#if diceStats.human.count}}
    <span class="die-summary human">{{diceStats.human.count}} {{localize "VERMINE.die_human"}} · {{diceStats.human.success}} {{localize "VERMINE.die_successes"}}</span>
    {{/if}}
    {{#if diceStats.adapted.count}}
    <span class="die-summary adapted">{{diceStats.adapted.count}} {{localize "VERMINE.die_adapted"}} · {{diceStats.adapted.success}} {{localize "VERMINE.die_successes"}}</span>
    {{/if}}
  </div>

  {{!-- Total --}}
  <div class="roll-total flexrow">
    <div class="flexcol">
      <h4>{{localize "VERMINE.success_count"}}:</h4>
      <span id="total">{{verdict.total}}</span>
    </div>
    <div class="flexcol">
      <h4>{{localize "VERMINE.success_required"}}:</h4>
      <span id="required">{{verdict.required}}</span>
    </div>
  </div>
</div>
