<div class="coc7 chat-card melee target" data-actor-key="{{actorKey}}" data-initiator-key="{{initiatorKey}}" data-fast-forward="{{fastForward}}" data-resolved="{{resolved}}" data-outnumbered="{{outnumbered}}" data-surprised="{{surprised}}" data-auto-success="{{autoSuccess}}" data-dice-modifier="{{diceModifier}}" data-parent-message-id="{{parentMessageId}}" data-skill-id="{{skillId}}" data-item-id="{{itemId}}" data-dodging="{{dodging}}" data-not-responding="{{notResponding}}" data-fighting-back="{{fightingBack}}" data-maneuvering="{{maneuvering}}" data-resolution-card="{{resolutionCard}}" data-is-blind="false">

  <header class="card-header flexcol-coc7">
    <div class="flexrow-coc7">
      {{#if displayActorOnCard}}
        <img class="open-actor" data-actor-key="{{actorKey}}" style="flex: none;" src="{{actorImg}}" title="{{name}}" width="36" height="36" />
      {{/if}}
      {{#if dodging}}
        <img class="open-actor" style="flex: none;" data-actor-key="{{actorKey}}" src="{{actor.dodgeSkill.img}}" title="{{actor.dodgeSkill.name}}" width="36" height="36" />
        <h3 style="text-align: center;font-weight: bolder;" class="item-name card-title">{{actor.dodgeSkill.name}}</h3>
      {{else if notResponding}}
        <h3 style="text-align: center;font-weight: bolder;" class="item-name card-title">{{localize 'CoC7.NoResponse'}}</h3>
      {{else if fightingBack}}
        <img class="open-actor" style="flex: none;" data-actor-key="{{actorKey}}" src="{{weapon.img}}" title="{{weapon.name}}" width="36" height="36" />
        <h3 style="text-align: center;font-weight: bolder;" class="item-name card-title">{{weapon.name}}</h3>
      {{else if maneuvering}}
        <img class="open-actor" style="flex: none;" data-actor-key="{{actorKey}}" src="{{skill.img}}" title="{{skill.name}}" width="36" height="36" />
        <h3 style="text-align: center;font-weight: bolder;" class="item-name card-title">{{skill.name}}</h3>
      {{else}}
        <h3 style="text-align: center;font-weight: bolder;" class="item-name card-title">...</h3>
      {{/if}}
      <img class="open-actor" style="flex: none;" data-actor-key="{{initiatorKey}}" src="{{targetImg}}" title="{{targetName}}" width="36" height="36" />
    </div>

    {{#unless notResponding}}
      <div class="card-content">
        {{#if dodging}}
          {{{actor.dodgeSkill.system.description.value}}}
        {{else if fightingBack}}
          {{{weapon.system.description.value}}}
        {{else if maneuvering}}
          {{{skill.system.description.value}}}
        {{/if}}
        {{#if rolled}}
          <div class="flex0 advantage-selection">
            {{#if dodging}}<span class="tag" title="{{actor.dodgeSkill.name}}">{{localize 'CoC7.Dodge'}}</span>{{/if}}
            {{#if fightingBack}}<span class="tag" title="{{weapon.name}}">{{localize 'CoC7.FightBack'}}</span>{{/if}}
            {{#if maneuvering}}<span class="tag" title="{{skill.name}}">{{localize 'CoC7.Maneuver'}}</span>{{/if}}
          </div>
        {{/if}}
      </div>
    {{/unless}}
  </header>

  {{#unless rolled}}
    <div class="flexrow-coc7 response-selection owner-only">
      <span class="flex1 toggle-switch dodge {{#if actor.dodgeSkill.id}}{{#unless rolled}}simple-toggle{{/unless}}{{else}}inactive{{/if}} {{#if dodging}}switched-on{{/if}}" data-action="dodge" data-skill-id="{{actor.dodgeSkill.id}}">{{localize 'CoC7.Dodge'}}</span>
      <span class="flex1 toggle-switch no-response simple-toggle {{#if notResponding}}switched-on{{/if}}" data-action="noResponse">{{localize 'CoC7.NoResponse'}}</span>
    </div>
    <div class="flexrow-coc7 response-selection owner-only">
      <div class="flex1 toggle-switch fight-back {{#unless rolled}}dropdown{{/unless}} {{#if fightingBack}}switched-on{{/if}}">
        <span class="combat-action {{#unless rolled}}dropbtn{{/unless}}">{{localize 'CoC7.FightBack'}}</span>
        <div class="actor-skill dropdown-content">
          {{#each actor.closeCombatWeapons as |weapon key|}}
            <a class="dropdown-element" data-action="fightBack" data-weapon-id="{{weapon.id}}" data-skill-id="{{weapon.system.skill.main.id}}">{{weapon.name}} ({{weapon.system.skill.main.value}}%)</a> {{!-- TODO: Check skill value correctly displayed --}}
          {{/each}}
        </div>
      </div>
      <div class="flex1 toggle-switch maneuver {{#unless rolled}}dropdown{{/unless}} {{#if maneuvering}}switched-on{{/if}}">
        <span class="combat-action {{#unless rolled}}dropbtn{{/unless}}">{{localize 'CoC7.Maneuver'}}</span>
        <div class="actor-skill dropdown-content">
          {{#each actor.fightingSkills as |skill key|}}
            <a class="dropdown-element" data-action="maneuver" data-skill-id="{{skill.id}}">{{skill.name}} ({{skill.value}}%)</a>
          {{/each}}
        </div>
      </div>
    </div>
  {{/unless}}
  {{#unless (or rolled notResponding)}}
    <div class="owner-only" style="flex: 1;display: flex;flex-direction: column;margin: 0.5rem 1rem 0;opacity:0.6">
      <div class="flexrow-coc7">
        <span style="flex: 4; text-align: left">{{localize 'CoC7.PenaltyDice'}}</span>
        <span style="flex: 1">&nbsp;</span>
        <span style="flex: 4; text-align: right">{{localize 'CoC7.BonusDice'}}</span>
      </div>
      <div class="flexrow-coc7">
        <span style="flex: 1; text-align: left;">-2</span>
        <span style="flex: 1; text-align: center;"></span>
        <span style="flex: 1; text-align: center;">-1</span>
        <span style="flex: 1; text-align: center;"></span>
        <span style="flex: 1; text-align: center;">0</span>
        <span style="flex: 1; text-align: center;"></span>
        <span style="flex: 1; text-align: center;">+1</span>
        <span style="flex: 1; text-align: center;"></span>
        <span style="flex: 1; text-align: right;">+2</span>
      </div>
      <input type="range" name="diceModifier" min="-2" max="2" value="{{diceModifier}}" class="slider gm-range-only">
    </div>
  {{/unless}}

  {{#if (and rolled notResponding)}}
  {{else if rolled}}
    <div class="dice-roll" style="padding-top: 5px;" data-roll-type={{roll.rollType}} data-side={{roll.side}} data-action={{roll.action}} data-ref-message-id={{roll.referenceMessageId}} data-success-level={{roll.successLevel}} data-difficulty={{roll.difficulty}} data-actor-id={{roll.actorId}} data-token-id={{roll.tokenId}} data-actor-key={{roll.actorKey}} data-skill-id={{roll.skillId}} data-item-id={{roll.itemId}} data-dice-mod={{roll.diceMod}} data-value={{roll.value}} data-result={{roll.result}} data-fumble={{roll.fumble}} data-critical={{roll.critical}} data-characteristic={{roll.characteristic}} data-is-blind="false">
      <div class="dice-result">
        <div class="dice-tooltip" style="display: none;">
          <section class="tooltip-part">
            <div class="dice">
              <span class="part-formula part-header flexrow-coc7">
                {{#if check.dices.tenOnlyOneDie}}
                  {{localize 'CoC7.TensDie'}}
                {{else}}
                  {{check.dices.tens.length}} {{localize 'CoC7.TensDice'}}
                {{/if}}
                <div class="flex1"></div>
                <span class="part-total flex0">{{check.dices.tenResult}}</span>
              </span>
              <ol class="dice-rolls">
                {{#each check.dices.tens as |die key|}}
                  <li class="roll die d10 {{#unless die.selected}}discarded{{/unless}} {{#if die.isMax}}min{{/if}} {{#if die.isMin}}max{{/if}}">{{die.value}}</li>
                {{/each}}
              </ol>
            </div>
          </section>
          <section class="tooltip-part">
            <div class="dice">
              <span class="part-formula part-header flexrow-coc7">
                {{localize 'CoC7.UnitsDie'}}
                <div class="flex1"></div>
                <span class="part-total flex0">{{check.dices.unit.value}}</span>
              </span>
              <ol class="dice-rolls">
                <li class="roll die d10">{{check.dices.unit.value}}</li>
              </ol>
            </div>
          </section>

          <h4 class="result-details" style="margin: 0">{{check.resultType}}</h4>

          <div class="card-buttons owner-only" data-actor-id="{{check.actor.id}}" style="padding: 2px 0;margin: 0;">
            {{#unless check.isSuccess}}
              {{#if check.canBePushed}}
                {{#unless check.pushing}}
                  <button data-action="push">{{localize 'CoC7.PushSkill'}}</button>
                {{/unless}}
              {{/if}}
              {{#if check.hasEnoughLuck}}
                {{#unless check.pushing}}
                  <button data-action="useLuck" data-luck-amount="{{check.luckNeeded}}" data-new-success-level="{{check.difficulty}}">{{check.luckNeededTxt}}</button>
                {{/unless}}
              {{/if}}
            {{/unless}}

            {{#unless check.pushing}}
              {{#if check.canIncreaseSuccess}}
                {{#each check.increaseSuccess as |level|}}
                  <button data-action="useLuck" data-luck-amount="{{level.luckToSpend}}" data-new-success-level="{{level.difficulty}}">{{localize 'CoC7.UpgradeSuccessWithLuck' difficultyName=level.difficultyName luckToSpend=level.luckToSpend}}</button>
                {{/each}}
              {{/if}}
            {{/unless}}
          </div>

        </div>
        <div class="dice-total {{#if check.isSuccess}}success{{else}}failure{{/if}}{{#if check.isCritical}} critical{{/if}}{{#if check.isFumble}} fumble{{/if}} ">
          {{check.dices.total}} {{check.resultType}}
        </div>
        {{#if check.hasMalfunction}}
          <h4 class="malfunction">{{check.malfunctionTxt}}</h4>
        {{/if}}
      </div>
    </div>
  {{else if actionSelected}}
    <div class="selected-action card-buttons owner-only">
      {{#if fightingBack}}
        <button data-action="melee-target-roll" data-skill="{{skill.id}}" data-item-id="{{weapon.id}}">{{weapon.name}}: {{skill.name}} ({{skill.value}}%)</button>
      {{else if notResponding}}
        <button data-action="melee-target-no-response">{{localize 'CoC7.NoResponse'}}</button>
      {{else}}
        <button data-action="melee-target-roll" data-skill="{{skill.id}}">{{skill.name}} ({{skill.value}}%)</button>
      {{/if}}
    </div>
  {{/if}}
</div>
