<form autocomplete="off" spellcheck="off">
    <h2>{{localize header}}</h2>

    <section class="entries">
        <section class="new entry">

            <div class="form-group">
                <label for="{{options.id}}-new-type">{{localize "PF2E.Actor.IWREditor.Type"}}</label>
                <div class="form-fields">
                    <select id="{{options.id}}-new-type" class="iwr-type" data-property="type">
                        <option value=""></option>
                        {{selectOptions types localize=true sort=true}}
                    </select>
                    {{#unless (eq category "immunities")}}
                        <input type="number" min="1" data-property="value" placeholder="5" />
                    {{/unless}}
                    <a class="form-action" data-action="add" data-tooltip="Save"><i class="fa-solid fa-fw fa-floppy-disk"></i></a>
                </div>
            </div>

            <div class="form-group">
                <label for="{{@root.options.id}}-new-exceptions">{{localize "PF2E.Actor.IWREditor.Exceptions"}}</label>
                <div class="form-fields">
                    <input type="text" id="{{@root.options.id}}-new-exceptions" class="pf2e-tagify" data-property="exceptions" />
                </div>
            </div>

            {{#if (eq @root.category "resistances")}}
                <div class="form-group">
                    <label for="{{@root.options.id}}-new-double-vs">{{localize "PF2E.Actor.IWREditor.DoubleVs"}}</label>
                    <div class="form-fields">
                        <input type="text" id="{{@root.options.id}}-new-double-vs" class="pf2e-tagify" data-property="doubleVs" />
                    </div>
                </div>
            {{/if}}
        </section>
    </section>

    {{#if list}}
        <hr />
        <section class="entries">
            {{#each list as |iwr index|}}
                <section class="entry"{{#if iwr.source}} data-synthetic="true"{{/if}}>
                    <div class="form-group">
                        <label for="{{@root.options.id}}-{{index}}-type">{{localize "PF2E.Actor.IWREditor.Type"}}</label>
                        <div class="form-fields">
                        <select id="{{@root.options.id}}-{{index}}-type" class="iwr-type" data-property="type" {{disabled iwr.source}}>
                            {{#if iwr.source}}
                                <option value="{{iwr.type}}" selected>{{iwr.typeLabel}}</option>
                            {{else}}
                                {{selectOptions @root.types selected=iwr.type localize=true sort=true}}
                            {{/if}}
                        </select>
                        {{#unless (eq @root.category "immunities")}}
                            <input type="number" min="1" value="{{iwr.value}}" data-property="value" placeholder="5" {{disabled iwr.source}} />
                        {{/unless}}
                        {{#if iwr.source}}
                            <span class="synthetic-source">
                                <i class="fa-solid fa-fw fa-info-circle" data-tooltip="{{iwr.source}}" data-tooltip-direction="UP"></i>
                            </span>
                        {{else}}
                            <a class="form-action" data-action="remove">
                                <i class="fa-solid fa-fw fa-times" data-tooltip="Delete"></i>
                            </a>
                        {{/if}}
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="{{@root.options.id}}-{{index}}-exceptions">{{localize "PF2E.Actor.IWREditor.Exceptions"}}</label>
                        <div class="form-fields">
                            <input type="text" id="{{@root.options.id}}-{{index}}-exceptions" value="{{json iwr.exceptions}}" class="pf2e-tagify" data-property="exceptions" {{disabled iwr.source}} />
                        </div>
                    </div>

                    {{#if (eq @root.category "resistances")}}
                        <div class="form-group">
                            <label for="{{@root.options.id}}-{{index}}-double-vs">{{localize "PF2E.Actor.IWREditor.DoubleVs"}}</label>
                            <div class="form-fields">
                                <input type="text" id="{{@root.options.id}}-{{index}}-double-vs" value="{{json iwr.doubleVs}}" class="pf2e-tagify" data-property="doubleVs" {{disabled iwr.source}} />
                            </div>
                        </div>
                    {{/if}}
                </section>
            {{/each}}
        </section>
    {{/if}}

    <input type="hidden" name="system.attributes.{{category}}", data-dtype="JSON" value="{{json sourceData}}" />
</form>
