<fieldset class="basics">
    <div class="form-group">
        <label for="{{fieldIdPrefix}}category">{{localize "PF2E.Category"}}</label>
        <select name="system.category" id="{{fieldIdPrefix}}category">
            {{#select data.category}}
                {{#each categories as |label slug|}}
                    <option value="{{slug}}">{{label}}</option>
                {{/each}}
            {{/select}}
        </select>
    </div>
    <div class="form-group">
        <label for="{{fieldIdPrefix}}group">{{localize "PF2E.WeaponGroupLabel"}}</label>
        <select name="system.group" id="{{fieldIdPrefix}}group">
            {{#select data.group}}
                <option value=""></option>
                {{#each groups as |name type|}}
                    <option value="{{type}}">{{localize name}}</option>
                {{/each}}
            {{/select}}
        </select>
    </div>
    <div class="form-group">
        <label for="{{fieldIdPrefix}}base">{{localize "PF2E.WeaponBaseLabel"}}</label>
        <select id="{{fieldIdPrefix}}base" data-property="system.baseItem">
            {{#select data.baseItem}}
                <option value=""></option>
                {{#each baseTypes as |label slug|}}
                    <option value="{{slug}}">{{label}}</option>
                {{/each}}
            {{/select}}
        </select>
    </div>
    <div class="form-group">
        <label for="{{fieldIdPrefix}}range">
            {{localize "PF2E.TraitRange"}}
            {{#if mandatoryMelee}}
                <i class="fa-solid fa-info-circle" data-tooltip="PF2E.Item.Weapon.MandatoryMelee"></i>
            {{/if}}
        </label>
        <select name="system.range" id="{{fieldIdPrefix}}range" data-dtype="Number" {{disabled mandatoryMelee}}>
            {{#select item._source.system.range}}
                {{#unless mandatoryRanged}}<option value="">{{localize "PF2E.Item.Weapon.NoRangeMelee"}}</option>{{/unless}}
                {{#each weaponRanges as |label range|}}
                    <option value="{{range}}">{{localize label range=range}}</option>
                {{/each}}
            {{/select}}
        </select>
    </div>
    {{#if data.range}}
        <div class="form-group">
            <label for="{{fieldIdPrefix}}reload">{{localize "PF2E.WeaponReloadLabel"}}</label>
            <select name="system.reload.value" id="{{fieldIdPrefix}}reload">
                {{#select data.reload.value}}
                    <option value=""></option>
                    {{#each weaponReload as |name type|}}
                        <option value="{{type}}">{{localize name}}</option>
                    {{/each}}
                {{/select}}
            </select>
        </div>
    {{/if}}

    {{#if isBomb}}
        <div class="form-group">
            <label for="{{fieldIdPrefix}}bomb-bonus">{{localize "PF2E.WeaponBonusAttackLabel"}}</label>
            <input type="number" name="system.bonus.value" id="{{fieldIdPrefix}}bomb-bonus" value="{{data.bonus.value}}" />
        </div>
    {{/if}}
</fieldset>

{{#unless isBomb}}
    <fieldset>
        <legend>{{localize "PF2E.Item.Physical.MaterialRunes.Label"}}</legend>
        <div class="form-group precious-material">
            <label for="{{fieldIdPrefix}}material">{{localize "PF2E.PreciousMaterialLabel"}}</label>
            <select
                id="{{fieldIdPrefix}}material"
                data-property="system.material"
                data-value-base="{{json item._source.system.material}}"
                data-dtype="JSON"
            >
                {{#select preciousMaterials.value}}
                    <option value="{&quot;type&quot;:null,&quot;grade&quot;:null}"></option>
                    {{#each preciousMaterials.materials as |material|}}
                        <optgroup label="{{material.label}}">
                            {{#each material.grades as |grade|}}
                                <option value="{{grade.value}}">
                                    {{localize "PF2E.Item.Weapon.MaterialAndRunes.MaterialOption" type=material.label grade=grade.label}}
                                </option>
                            {{/each}}
                        </optgroup>
                    {{/each}}
                {{/select}}
            </select>
        </div>
        {{#unless abpEnabled}}
            <div class="form-group">
                <label for="{{fieldIdPrefix}}rune-potency">{{localize "PF2E.PotencyRuneLabel"}}</label>
                <select name="system.runes.potency" id="{{fieldIdPrefix}}rune-potency" data-dtype="Number">
                    {{#select data.runes.potency}}
                        {{#each runeTypes.potency as |data number|}}
                            <option value="{{number}}">{{localize (coalesce data.name "")}}</option>
                        {{/each}}
                    {{/select}}
                </select>
            </div>
            <div class="form-group">
                <label for="{{fieldIdPrefix}}rune-striking">{{localize "PF2E.StrikingRuneLabel"}}</label>
                <select name="system.runes.striking" id="{{fieldIdPrefix}}rune-striking" data-dtype="Number">
                    {{#select data.runes.striking}}
                        {{#each runeTypes.striking as |data number|}}
                            <option value="{{number}}">{{localize (coalesce data.name "")}}</option>
                        {{/each}}
                    {{/select}}
                </select>
            </div>
        {{/unless}}

        {{#each propertyRuneSlots as |slot index|}}
            <div class="form-group">
                <label
                    for="{{../fieldIdPrefix}}runes-property-{{index}}"
                    {{#if slot.disabled}}class="disabled"{{/if}}
                >
                    {{localize (concat "PF2E.PropertyRuneLabel" (add index 1))}}
                </label>
                <select
                    name="system.runes.property.{{index}}"
                    id="{{../fieldIdPrefix}}runes-property-{{index}}"
                    {{disabled slot.disabled}}
                    {{#if @root.item.isSpecific}}class="readonly"{{/if}}
                >
                    {{#select slot.slug}}
                        <option value=""></option>
                        {{#each @root.runeTypes.property as |rune|}}
                            <option value="{{rune.slug}}">{{localize rune.name}}</option>
                        {{/each}}
                    {{/select}}
                </select>
            </div>
        {{/each}}

        <div class="form-group">
            <label for="{{fieldIdPrefix}}specific" class="large">
                {{localize "PF2E.Item.Weapon.SpecificMagicWeapon.Label"}}
                <i class="fa-solid fa-info-circle" data-tooltip="PF2E.Item.Weapon.SpecificMagicWeapon.Hint"></i>
            </label>
            <input
                type="checkbox"
                name="system.specific"
                id="{{fieldIdPrefix}}specific"
                value="{{json specificMagicData}}"
                data-dtype="JSON"
                {{checked data.specific}}
            />
        </div>
    </fieldset>
{{/unless}}

<fieldset>
    <legend>
        {{localize "PF2E.DamageLabel"}}
        <i class="fa-solid fa-info-circle" data-tooltip="PF2E.WeaponBaseDamageTitle"></i>
    </legend>

    <div class="form-group">
        <label for="{{fieldIdPrefix}}damage-dice-number">
            {{localize "PF2E.WeaponBaseLabel"}}
            {{#if adjustedDiceHint}}<i class="fa-solid fa-info-circle" data-tooltip="{{adjustedDiceHint}}"></i>{{/if}}
        </label>

        <div class="dice-data">
            <input type="number"
                {{#if adjustedDiceHint}} class="adjusted"{{/if}}
                id="{{fieldIdPrefix}}damage-dice-number"
                data-property="system.damage.dice"
                value="{{data.damage.dice}}"
            />
            <select name="system.damage.die">
                {{#select data.damage.die}}
                    <option value=""></option>
                    {{#each damageDie as |name type|}}
                        <option value="{{type}}">{{localize name}}</option>
                    {{/each}}
                {{/select}}
            </select>
            <select name="system.damage.damageType">
                {{#select data.damage.damageType}}
                    {{#each damageTypes as |label slug|}}
                        {{#unless (eq slug "bleed")}}<option value="{{slug}}">{{label}}</option>{{/unless}}
                    {{/each}}
                {{/select}}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label{{#unless data.splashDamage.value}} class="no-data"{{/unless}} for="{{fieldIdPrefix}}damage-splash">
            {{localize "PF2E.TraitSplash"}}
        </label>
        <input type="number" name="system.splashDamage.value" id="{{fieldIdPrefix}}damage-splash" value="{{data.splashDamage.value}}" />
    </div>

    <div class="form-group">
        <label{{#unless data.damage.persistent}} class="no-data"{{/unless}} for="{{fieldIdPrefix}}damage-persistent">
            {{localize "PF2E.ConditionTypePersistentShort"}}
        </label>

        <div class="dice-data">
            <input type="number"
                id="{{fieldIdPrefix}}damage-persistent"
                data-action="update-persistent"
                data-persistent-field="number"
                value="{{coalesce data.damage.persistent.number 0}}"
            />

            <select data-action="update-persistent" data-persistent-field="faces">
                {{#select data.damage.persistent.faces}}
                    <option value=""></option>
                    {{#each damageDieFaces as |label value|}}
                        <option value="{{value}}">{{localize label}}</option>
                    {{/each}}
                {{/select}}
            </select>

            <select data-action="update-persistent" data-persistent-field="type" value="{{data.damage.persistent.damageType}}">
                {{#select data.damage.persistent.type}}
                    <option value=""></option>
                    {{#each damageTypes as |label slug|}}
                        <option value="{{slug}}">{{label}}</option>
                    {{/each}}
                {{/select}}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label{{#unless data.bonusDamage.value}} class="no-data"{{/unless}} for="{{fieldIdPrefix}}damage-bonus">
            {{localize "PF2E.Bonus"}}
        </label>
        <input type="number" name="system.bonusDamage.value" id="{{fieldIdPrefix}}damage-bonus" value="{{data.bonusDamage.value}}" />
    </div>
</fieldset>

<fieldset>
    <legend>
        {{localize "PF2E.WeaponCustomDamageLabel"}}
        <i class="fa-solid fa-info-circle" data-tooltip="PF2E.WeaponCustomDamageTitle"></i>
    </legend>
    <div class="form-group">
        <label>{{localize "PF2E.ItemDescription"}}</label>
        <input type="text" name="system.property1.value" value="{{data.property1.value}}" />
    </div>

    <div class="form-group">
        <label>{{localize "PF2E.WeaponPropertyStrikeDamageLabel"}}</label>
        <div class="dice-data">
            <input type="number" name="system.property1.dice" value="{{data.property1.dice}}" />
            <select name="system.property1.die">
                {{#select data.property1.die}}
                    <option value=""></option>
                    {{#each damageDie as |name type|}}
                        <option value="{{type}}">{{localize name}}</option>
                    {{/each}}
                {{/select}}
            </select>
            <select name="system.property1.damageType">
                {{#select data.property1.damageType}}
                    <option value=""></option>
                    {{#each damageTypes as |label slug|}}
                        <option value="{{slug}}">{{label}}</option>
                    {{/each}}
                {{/select}}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label>{{localize "PF2E.WeaponPropertyStrikeEffectLabel"}}</label>
        <div class="effects-container">
            <select name="system.property1.strikeConditionType">
                {{#select data.property1.strikeConditionType}}
                    <option value=""></option>
                    {{#each conditionTypes as |label slug|}}
                        <option value="{{slug}}">{{label}}</option>
                    {{/each}}
                {{/select}}
            </select>
            <select name="system.property1.strikeConditionValue" data-dtype="Number">
                {{#select data.property1.strikeConditionValue}}
                    <option value=""></option>
                    {{#each damageDice as |name type|}}
                        <option value="{{type}}">{{localize name}}</option>
                    {{/each}}
                {{/select}}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label>{{localize "PF2E.WeaponPropertyCriticalDamageLabel"}}</label>
        <div class="dice-data">
            <input type="number" name="system.property1.critDice" value="{{data.property1.critDice}}" />
            <select name="system.property1.critDie">
                {{#select data.property1.critDie}}
                    <option value=""></option>
                    {{#each damageDie as |name type|}}
                        <option value="{{type}}">{{localize name}}</option>
                    {{/each}}
                {{/select}}
            </select>
            <select name="system.property1.critDamageType">
                {{#select data.property1.critDamageType}}
                    <option value=""></option>
                    {{#each damageTypes as |name type|}}
                        <option value="{{type}}">{{localize name}}</option>
                    {{/each}}
                {{/select}}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label>{{localize "PF2E.WeaponPropertyCriticalEffectLabel"}}</label>
        <div class="effects-container">
            <select name="system.property1.criticalConditionType">
                {{#select data.property1.criticalConditionType}}
                    <option value=""></option>
                    {{#each conditionTypes as |label slug|}}
                        <option value="{{slug}}">{{localize label}}</option>
                    {{/each}}
                {{/select}}
            </select>
            <select name="system.property1.criticalConditionValue" data-dtype="Number">
                {{#select data.property1.criticalConditionValue}}
                    <option value=""></option>
                    {{#each damageDice as |name type|}}
                        <option value="{{type}}">{{localize name}}</option>
                    {{/each}}
                {{/select}}
            </select>
        </div>
    </div>
</fieldset>

{{#if isComboWeapon}}
    <ol class="form-list">
        <h3>
            {{localize "PF2E.Item.Weapon.MeleeUsage.Label"}}
            <i class="fa-solid fa-info-circle" data-tooltip="PF2E.Item.Weapon.MeleeUsage.Hint"></i>
        </h3>
        <div class="form-group">
            <label>{{localize "PF2E.WeaponGroupLabel"}}</label>
            <select name="system.meleeUsage.group">
                {{#select meleeUsage.group}}
                    {{#each meleeGroups as |label slug|}}
                        <option value="{{slug}}">{{label}}</option>
                    {{/each}}
                {{/select}}
            </select>
        </div>
        <div class="form-group">
            <label>{{localize "PF2E.WeaponDamageLabel"}}</label>
            <div class="details-container-three-columns">
                <select name="system.meleeUsage.damage.die">
                    {{#select meleeUsage.damage.die}}
                        {{#each damageDie as |value faces|}}
                            <option value="{{faces}}">1{{faces}}</option>
                        {{/each}}
                    {{/select}}
                </select>
                <select name="system.meleeUsage.damage.type">
                    {{#select meleeUsage.damage.type}}
                        {{#each damageTypes as |label type|}}
                            <option value="{{type}}">{{label}}</option>
                        {{/each}}
                    {{/select}}
                </select>
            </div>
        </div>
        <div class="form-group">
            <label>
                {{localize "PF2E.TraitsLabel"}}
                <a class="tag-selector" data-tag-selector="basic" data-config-types="weaponTraits" data-property="system.meleeUsage.traits" data-no-custom="true" data-flat="true">
                    <i class="fa-solid fa-edit"></i>
                </a>
            </label>
            <ul class="traits-list tags">
                {{#each meleeUsageTraits as |trait|}}
                    <li class="tag">{{trait.label}}</li>
                {{/each}}
            </ul>
        </div>
    </ol>
{{/if}}

<div class="form-group stacked">
    <label>
        {{localize "PF2E.Item.Physical.OtherTags.Label"}}
        <i class="fa-solid fa-info-circle" data-tooltip="PF2E.Item.Physical.OtherTags.Hint"></i>
        {{#if editable}}
            <a class="tag-selector" data-tag-selector="basic" data-config-types="otherWeaponTags" data-title="PF2E.Item.Physical.OtherTags.Label" data-property="system.traits.otherTags"><i class="fa-solid fa-edit"></i></a>
        {{/if}}
    </label>
    <ul class="traits-list tags">
        {{#each otherTags as |tag|}}
            <li class="tag tag_alt">{{tag.label}}</li>
        {{/each}}
    </ul>
</div>
{{#if item.isThrowable}}
    <div class="form-group">
        <label>
            {{localize "PF2E.Item.Weapon.CanBeAmmo.Label"}}
            <i class="fa-solid fa-info-circle" data-tooltip-width="300" data-tooltip="PF2E.Item.Weapon.CanBeAmmo.Hint"></i>
        </label>
        <input type="checkbox" name="system.usage.canBeAmmo" {{checked item.system.usage.canBeAmmo}} />
    </div>
{{/if}}
