{{!-- stances --}}
{{#if stances}}
<header data-filter-value="{{stances.filterValue}}">
    <div class="name">{{@root.i18n 'stances'}}</div>
</header>
{{/if}}
{{#each stances.actions as |stance|}}
<div class="item action" data-item-id="{{stance.id}}" draggable="true"
    data-effect-uuid="{{stance.uuid}}" data-filter-value="{{stance.filterValue}}">
    {{> (@root.partial 'item-image') stance}}
    <div class="name">
        <a data-action="item-description">{{stance.label}}</a>
    </div>
    <div class="controls">
        <a {{#unless ../stances.canUseStances}}class="disabled" {{/unless}}
            data-action="toggle-stance">
            <i class="fa-solid fa-toggle-{{ifThen stance.active 'large-on' 'off'}}"></i>
        </a>
    </div>
</div>
{{/each}}
{{!-- blasts --}}
{{#if blasts}}
<header class="blasts" data-filter-value="{{blasts.filterValue}}">
    <div class="name">{{@root.i18n 'blasts'}}</div>
    <a class="controls item" data-item-id="{{blasts.cost.id}}" draggable="true"
        data-action="toggle-blast-action-cost" data-tooltip="{{blasts.cost.selected.tooltip}}">
        {{#each blasts.cost.costs as |cost|}}
        <span {{#if cost.selected}} class="selected" {{/if}}>{{cost.label}}</span>
        {{/each}}
        <img src="{{blasts.cost.img}}" class="drag-img">
    </a>
</header>
{{/if}}
{{#each blasts.actions as |blast|}}
<div class="item attack ready" data-filter-value="{{blast.filterValue}}"
    data-item-id="{{blast.blastId}}" draggable="true">
    <div class="name">
        <img src="{{blast.img}}">
        <a data-action="item-description">{{localize blast.label}}</a>
    </div>
    {{!-- attack/damage --}}
    {{> 'blast-row' blast=blast melee=true}}
    {{> 'blast-row' blast=blast melee=false}}
    {{!-- damage type variants --}}
    {{#if (gt blast.damageTypes.length 1)}}
    <div class="variants versatiles">
        {{#each blast.damageTypes as |damageType|}}
        <div class="variant{{#if damageType.selected}} selected{{/if}}"
            data-tooltip="{{damageType.label}}" {{#unless damageType.selected}}
            data-action="blast-set-damage-type" data-value="{{damageType.value}}" {{/unless}}>
            <i class="fa-solid fa-fw fa-{{damageType.icon}}"></i>
        </div>
        {{/each}}
    </div>
    {{/if}}
</div>
{{/each}}
{{!-- strikes --}}
{{#if strikes}}
<header class="strikes" data-filter-value="{{strikes.filterValue}}">
    {{#if @root.isCharacter}}
    <div class="controls left">
        <a {{#if strikes.shields}} class="active" {{/if}} data-action="toggle-show-shields"
            {{{@root.i18n.tooltip 'shields' (ifThen strikes.shields 'shown' 'hidden' )}}}>
            <i class="fa-solid fa-shield"></i>
        </a>
    </div>
    {{/if}}
    <div class="name">{{localize 'PF2E.Actor.Attacks'}}</div>
    {{#if @root.isCharacter}}
    <div class="controls">
        <a {{#unless strikes.stowed}} class="active" {{/unless}} data-action="toggle-hide-stowed"
            {{{@root.i18n.tooltip 'stowedWeapons' (ifThen strikes.stowed 'hidden' 'shown' )}}}>
            <i class="fa-solid fa-eye"></i>
        </a>
    </div>
    {{/if}}
</header>
{{/if}}
{{#each strikes.actions as |strike|}}
<div class="item attack{{#if strike.ready}} ready{{/if}}" data-item-id="{{strike.id}}"
    data-index="{{strike.index}}" data-filter-value="{{strike.filterValue}}" draggable="true">
    {{!-- name --}}
    <div class="name">
        <img src="{{strike.img}}">
        <a data-action="item-description">{{strike.label}}</a>
    </div>
    {{!-- npc traits --}}
    {{#unless @root.isCharacter}}
    {{#if (or strike.traits.length strike.additionalEffects.length)}}
    <div class="variants">
        {{#each strike.traits as |trait|}}
        <div class="variant info" data-tooltip="{{trait.description}}">
            {{trait.label}}
        </div>
        {{/each}}
        {{#each strike.additionalEffects as |trait|}}
        <div class="variant trait">
            {{localize trait.label}}
        </div>
        {{/each}}
    </div>
    {{/if}}
    {{/unless}}
    {{!-- attack/damage --}}
    {{#if strike.ready}}
    {{#if (or @root.isNPC strike.canAttack)}}
    {{> 'strike-row' strike}}
    {{/if}}
    {{else if (not strike.handsAvailable)}}
    <span class="hands-occupied">{{localize "PF2E.Actor.Character.HandsOccupied"}}</span>
    {{/if}}
    {{!-- alt usages --}}
    {{#if strike.ready}}
    {{#each strike.altStrikes as |altStrike|}}
    {{> 'strike-row' altStrike}}
    {{/each}}
    {{/if}}
    {{!-- controls --}}
    {{#if @root.isCharacter}}
    {{!-- reload --}}
    {{#if (and strike.ready strike.ammunition.requiresReload)}}
    <div class="variants reload">
        {{#each strike.ammunition.loaded as |ammo|}}
        <div class="variant loaded {{#if (eq ammo.id strike.ammunition.selected.id)}}active{{/if}}"
            data-ammo-id="{{ammo.id}}">
            <img src="{{ammo.img}}" />
            <a class="ammo-name" data-action="select-ammo">{{ammo.name}}</a>
            <input type="number" data-action="change-ammo-quantity" value="{{ammo.quantity}}"
                min="0" max="{{ammo.max}}" />
            <a data-action="unload">
                <i class="fa-solid fa-eject"></i>
            </a>
        </div>
        {{/each}}
    </div>
    {{/if}}
    {{!-- controls --}}
    <div class="variants controls">
        {{!-- ammo --}}
        {{#if (and strike.ready strike.ammunition)}}
        {{!-- firearm --}}
        {{#if (and strike.ammunition.requiresReload strike.ammunition.remaining)}}
        <div class="variant reload" data-action="reload">
            <span>
                {{localize "PF2E.Actions.Interact.Reload.Title"}}
                <span class="action-glyph">{{strike.ammunition.reloadGlyph}}</span>
            </span>
            {{#if (gt strike.ammunition.capacity 1)}}
            <span>({{strike.ammunition.remaining}})</span>
            {{/if}}
        </div>
        {{!-- regular ranged --}}
        {{else if (not strike.ammunition.requiresReload)}}
        <div class="variant ammo">
            <select class="linked" data-action="link-ammo">
                {{selectOptions strike.ammunition.compatible selected=strike.ammunition.selected.id
                valueAttr="id" blank="PF2E.NoAmmoLabel" localize=true}}
            </select>
        </div>
        {{/if}}
        {{/if}}
        {{!-- auxiliaries --}}
        {{#if strike.handsAvailable}}
        {{!-- regular auxiliaries --}}
        {{#each strike.auxiliaryActions as |aux index|}}
        <div class="variant auxiliary" data-action="auxiliary-action"
            data-auxiliary-action-index="{{index}}">
            <span>{{aux.label}}</span>
            <span class="action-glyph">{{aux.glyph}}</span>
            {{#if aux.options}}
            <select class="modular">
                {{#each aux.options as |option|}}
                <option value="{{option.value}}" {{#if option.selected}} selected{{/if}}>
                    {{option.label}} {{#if option.selected}}&nbsp;✔{{/if}}
                </option>
                {{/each}}
            </select>
            {{/if}}
        </div>
        {{/each}}
        {{/if}}
    </div>
    {{/if}}
</div>
{{/each}}
{{!-- hero actions --}}
{{#if heroActions}}
<header class="hero-actions" data-filter-value="{{heroActions.filterValue}}">
    <div class="name">{{heroActions.i18n 'label'}}</div>
    <div class="controls">
        {{#if heroActions.usesCount}}
        <a class="redraw" data-action="hero-actions-draw"
            data-tooltip="{{heroActions.i18n 'redraw'}}">
            <i class="fa-regular fa-cards-blank"></i>
        </a>
        {{else if heroActions.mustDraw}}
        <a class="draw" data-action="hero-actions-draw"
            data-tooltip="{{heroActions.i18n 'draw' nb=heroActions.diff}}">
            <i class="fa-regular fa-cards-blank"></i>
        </a>
        {{/if}}
        {{#if heroActions.canTrade}}
        <a data-action="hero-actions-trade" data-tooltip="{{heroActions.i18n 'trade'}}">
            <i class="fas fa-right-left"></i>
        </a>
        {{/if}}
    </div>
</header>
{{#each heroActions.actions as |action|}}
<div class="item action" data-uuid="{{action.uuid}}" data-filter-value="{{action.filterValue}}">
    <div class="image" data-action="send-hero-action-to-chat">
        <img src="{{resolvePath 'icons/actions/Passive.webp'}}">
        <i class="fa-solid fa-message chat"></i>
    </div>
    <div class="name">
        <a data-action="hero-action-description">{{action.name}}</a>
    </div>
    <div class="controls">
        {{#if ../heroActions.canUse}}
        <a data-action="hero-action-use" data-tooltip="{{../heroActions.i18n 'action.use'}}">
            <i class="fa-solid fa-play"></i>
        </a>
        {{/if}}
        {{#if ../heroActions.mustDiscard}}
        <a class="discard" data-action="hero-action-discard"
            data-tooltip="{{../heroActions.i18n 'action.discard'}}">
            <i class="fa-solid fa-fw fa-trash"></i>
        </a>
        {{/if}}
    </div>
</div>
{{/each}}
{{/if}}
{{!-- actions --}}
{{#each sections as |section|}}
<header data-filter-value="{{section.filterValue}}">
    <div class="name">{{localize section.label}}</div>
</header>
{{#each section.actions as |action|}}
<div class="item action{{#if disabled}} inactive{{/if}}"
    data-item-id="{{action.id}}" {{#if action.virtual}}data-item-uuid="{{action.uuid}}"{{/if}}
    draggable="true" data-filter-value="{{action.filterValue}}">
    {{> (@root.partial 'item-image') action}}
    <div class="name">
        <a data-action="item-description">{{action.label}}</a>
    </div>
    <div class="controls">
        {{!-- toggles --}}
        {{#each action.toggles as |toggle|}}
        <a {{#if toggle.selected}}class="active" {{/if}} data-tooltip="{{toggle.tooltip}}"
            data-action="toggle-trait" data-trait="{{toggle.trait}}"><i
                class="fa-solid fa-fw fa-{{toggle.icon}}"></i></a>
        {{/each}}
        {{!-- if usages --}}
        {{#if action.usage}}
        {{!-- resource field --}}
        {{#if action.resource}}
        <input type="number" class="small" value="{{action.resource.value}}"
            data-tooltip="{{action.resource.label}}" disabled>
        {{!-- frequency field --}}
        {{else if action.frequency}}
        <input type="number" class="small" data-item-id="{{action.id}}"
            {{#if action.virtual}}data-virtual-action="true"{{else}}data-item-property="system.frequency.value"{{/if}}
            value="{{action.frequency.value}}" min="0" max="{{action.frequency.max}}" data-tooltip="{{action.frequency.label}}">
        {{/if}}
        {{!-- remove effect --}}
        {{#if action.usage.effect}}
        <a data-action="remove-effect" data-tooltip="{{action.usage.label}}">
            <i class="fa-solid fa-xmark"></i>
        </a>
        {{!-- use btn --}}
        {{else if (not action.untrainedTactic)}}
        <a data-action="use-action" {{#if action.usage.disabled}} class="disabled" {{/if}}
            data-tooltip="{{action.usage.label}}">
            <i class="fa-solid fa-play"></i>
        </a>
        {{/if}}
        {{!-- no usages but exploration --}}
        {{else if action.exploration}}
        <a data-action="toggle-exploration">
            <i class="fa-solid fa-toggle-{{ifThen action.exploration.active 'large-on' 'off'}}"></i>
        </a>
        {{!-- end if usages --}}
        {{/if}}
        {{!-- untrained commander tactic --}}
        {{#if untrainedTactic}}
        {{{untrainedTactic}}}
        {{/if}}
    </div>
</div>
{{/each}}
{{/each}}


{{#*inline 'attack-category'}}
<span class="category">
    {{#if (eq type 'blast')}}
    <i class="alt-usage-icon fa-regular fa-meteor fa-rotate-180" data-tooltip="{{tooltip}}"></i>
    {{else if (eq type 'auto-fire')}}
    <img class="alt-usage-icon {{type}}" src="{{resolvePath 'assets/icons/striking-balls.svg'}}" data-tooltip="{{tooltip}}">
    {{else if (eq type 'area-fire')}}
    <i class="alt-usage-icon {{type}} fa-regular fa-bullseye-arrow" data-tooltip="{{tooltip}}"></i>
    {{else if (eq type 'melee')}}
    <img class="alt-usage-icon" src="{{resolvePath 'icons/mdi/sword.svg'}}" data-tooltip="{{tooltip}}">
    {{else if (eq type 'thrown')}}
    <img class="alt-usage-icon" src="{{resolvePath 'icons/mdi/thrown.svg'}}" data-tooltip="{{tooltip}}">
    {{else }}
    <i class="fa-regular fa-bow-arrow" data-tooltip="{{tooltip}}"></i>
    {{/if}}
</span>
{{/inline}}


{{#*inline 'strike-row'}}
<div class="variants">
    {{!-- category --}}
    {{#if @root.isCharacter}}
    {{> 'attack-category' category}}
    {{/if}}
    {{!-- attacks --}}
    {{#each variants as |variant index|}}
    <div class="variant attack" data-action="strike-attack" data-variant-index="{{index}}" {{#if
        ../isAltUsage}} data-alt-usage="{{../altIndex}}" {{/if}} {{#if (eq ../quantity 0)}}
        data-disabled="true" data-tooltip="{{localize 'PF2E.ErrorMessage.WeaponQuantityZero'}}"
        {{/if}}>
        {{!-- first attack --}}
        {{#if (eq index 0)}}
        {{#if (or (eq ../type 'auto-fire') (eq ../type 'area-fire'))}}
        <span class="action-glyph">{{../glyph}}</span>
        {{else if @root.isCharacter}}
        {{localize 'PF2E.WeaponStrikeLabel'}}
        {{/if}}
        {{variant.label}}
        {{!-- other map --}}
        {{else}}
        {{@root.variantLabel variant.label}}
        {{/if}}
    </div>
    {{/each}}
    {{!-- damage/critical --}}
    {{#if item.dealsDamage}}
    {{!-- if not character, we split into a new variants line --}}
    {{#unless @root.isCharacter}}
</div>
<div class="variants">
    {{/unless}}
    {{!-- back to damage --}}
    <div class="variant damage" data-action="strike-damage" {{#if
        isAltUsage}}data-alt-usage="{{altIndex}}" {{/if}} {{#if
        @root.isCharacter}}data-tooltip="{{formula.damage}}" {{/if}}>
        {{#if @root.isCharacter}}
        {{localize "PF2E.DamageLabel"}}
        {{else}}
        {{formula.damage}}
        {{/if}}
    </div>
    {{!-- critical --}}
    <div class="variant damage" data-action="strike-critical" {{#if
        isAltUsage}}data-alt-usage="{{altIndex}}" {{/if}} data-tooltip="{{formula.critical}}">
        {{localize "PF2E.CriticalDamageLabel"}}
    </div>
    {{/if}}
</div>
{{!-- versitile options --}}
{{#if (and item.dealsDamage (or doubleBarrel versatileOptions.length))}}
<div class="variants versatiles">
    {{#if doubleBarrel}}
    <div class="variant double-barrel physical{{#if doubleBarrel.selected}} selected{{/if}}"
        {{#unless doubleBarrel.selected}} data-action="toggle-weapon-trait"
        data-trait="double-barrel" {{/unless}} data-tooltip="{{localize 'PF2E.TraitDoubleBarrel'}}">
        <span class="fa-stack fa-fw">
            <i class="fa-solid barrels fa-pause fa-rotate-90 fa-stack-1x icon"></i>
            <i class="fa-solid blast fa-explosion fa-rotate-90 fa-stack-1x icon"></i>
        </span>
    </div>
    {{/if}}
    {{#each versatileOptions as |option|}}
    <div class="variant{{#if option.selected}} selected{{/if}}" {{#unless option.selected}}
        data-value="{{option.value}}" data-action="toggle-weapon-trait" data-trait="versatile"
        {{/unless}} {{#if ../isAltUsage}} data-alt-usage="{{../altIndex}}" {{/if}}
        data-tooltip="{{localize option.label}}">
        <i class="fa-solid fa-{{option.glyph}} fa-fw icon"></i>
    </div>
    {{/each}}
</div>
{{/if}}
{{/inline}}




{{#*inline 'blast-row'}}
<div class="variants">
    {{!-- category --}}
    {{#if melee}}
    {{> 'attack-category' type='melee' tooltip=blast.reach}}
    {{else}}
    {{> 'attack-category' type='blast' tooltip=blast.range.label}}
    {{/if}}
    {{!-- attacks --}}
    <div class="variant attack" data-action="blast-attack" data-melee="{{melee}}"
        data-map-increases="0">
        {{localize "PF2E.SpecificRule.Kineticist.Impulse.ElementalBlast.ShortLabel"}}
        {{numberFormat blast.statistic.check.mod sign=true}}
    </div>
    <div class="variant attack" data-action="blast-attack" data-melee="{{melee}}"
        data-map-increases="1">
        {{#if melee}}
        {{@root.variantLabel blast.maps.melee.map1}}
        {{else}}
        {{@root.variantLabel blast.maps.ranged.map1}}
        {{/if}}
    </div>
    <div class="variant attack" data-action="blast-attack" data-melee="{{melee}}"
        data-map-increases="2">
        {{#if melee}}
        {{@root.variantLabel blast.maps.melee.map2}}
        {{else}}
        {{@root.variantLabel blast.maps.ranged.map2}}
        {{/if}}
    </div>
    {{!-- damages --}}
    <div class="variant damage" data-action="blast-damage" data-melee="{{melee}}"
        data-outcome="success" data-tooltip="{{blast.formulaTooltip melee 'damage'}}">
        {{localize "PF2E.DamageLabel"}}
    </div>
    <div class="variant damage" data-action="blast-damage" data-melee="{{melee}}"
        data-outcome="critical-success" data-tooltip="{{blast.formulaTooltip melee 'critical'}}">
        {{localize "PF2E.CriticalDamageLabel"}}
    </div>
</div>
{{/inline}}
