<section class="panel">
    <div class="powercasting-ability">
        <label>{{localize "SW5E.PowerAbility"}}
        <select name="data.attributes.powercasting" data-type="String">
            {{#select data.attributes.powercasting}}
            <option value="">{{localize "SW5E.None"}}</option>
            {{#each data.abilities as |abl a|}}
            <option value="{{a}}">{{abl.label}}</option>
            {{/each}}
            {{/select}}
        </select>
        </label>
        {{#if isNPC}}
        <label>{{localize "SW5E.PowercasterLevel"}}
        <input class="powercasting-level" type="text" name="data.details.powerLevel" value="{{data.details.powerLevel}}"
            data-dtype="Number" placeholder="0" />
            </label>
        {{/if}}
        <h3 class="power-dc">{{localize "SW5E.PowerDC"}} <span>{{data.attributes.powerdc}}</span></h3>
    </div>

    <ul class="filter-list" data-filter="powerbook">
        <li class="filter-title">{{localize "SW5E.Filter"}}</li>
        <li class="filter-item" data-filter="action">{{localize "SW5E.Action"}}</li>
        <li class="filter-item" data-filter="bonus">{{localize "SW5E.BonusAction"}}</li>
        <li class="filter-item" data-filter="reaction">{{localize "SW5E.Reaction"}}</li>
        <li class="filter-item" data-filter="concentration">{{localize "SW5E.AbbreviationConc"}}</li>
        <li class="filter-item" data-filter="ritual">{{localize "SW5E.Ritual"}}</li>
        <li class="filter-item" data-filter="prepared">{{localize "SW5E.Prepared"}}{{#if preparedPowers}}
            ({{preparedPowers}}){{/if}}</li>
    </ul>

    <div class="group-list-header group-grid-powers">
        <div></div>
        <div class="item-detail item-uses"></div>
        <div class="item-detail item-school">{{localize "SW5E.PowerSchool"}}</div>
        <div class="item-detail item-action">{{localize "SW5E.PowerUsage"}}</div>
        <div class="item-detail item-target">{{localize "SW5E.PowerTarget"}}</div>

    </div>
    <ol class="group-list">
        {{#each powerbook as |section|}}
        <li>
            <div class="group-list-title group-grid-powers">
                <div class="item-name">
                    <h3>{{section.label}}</h3>
                    {{#if section.canCreate}}
                    <a class="item-control item-create" title="{{localize 'SW5E.PowerCreate'}}"
                        {{#each section.dataset as |v k|}}data-{{k}}="{{v}}" {{/each}}>
                        <i class="fas fa-plus"></i> {{localize "SW5E.Add"}}
                    </a>
                    {{/if}}
                </div>
    
                <div class="item-detail item-uses">
                    {{#if section.usesSlots}}
                    <input type="text" name="data.powers.{{section.prop}}.value" value="{{section.uses}}" placeholder="0"
                        data-dtype="Number" />
                    /
                    <span data-level="{{section.prop}}" data-slots="{{section.slots}}">
                        {{{section.slots}}}
                        {{#if ../editable}}
                        <a class="slot-max-override" title="{{localize 'SW5E.PowerProgOverride'}}">
                            <i class="fas fa-edit"></i>
                        </a>
                        {{/if}}
                        {{ else }}
                        {{{section.uses}}} / {{{section.slots}}}
                        {{/if}}
                </div>
            </div>
            <ol class="item-list">
                {{#each section.powers as |item i|}}
                <li class="item group-grid-powers" data-item-id="{{item._id}}">
                    <div class="item-name rollable">
                        <div class="item-image" style="background-image: url({{item.img}})"></div>
                        <h4>{{item.name}}</h4>
                    </div>
                    
                    <div class="item-detail item-uses">
                        {{#if item.data.uses.per }}
                        Uses {{item.data.uses.value}} / {{item.data.uses.max}}
                        {{/if}}
                    </div>
                    
                    <!-- <div class="power-comps">
                        {{#each labels.components}}
                        <span class="power-component {{this}}">{{this}}</span>
                        {{/each}}
                    </div> -->
                    <div class="item-detail item-school">{{labels.school}}</div>
                    <div class="item-detail item-action">{{labels.activation}}</div>
                    <div class="item-detail item-target" title="{{localize 'SW5E.Range'}}: {{labels.range}}">
                        {{#if labels.target}}
                        {{labels.target}}
                        {{else}}None
                        {{/if}}
                    </div>


                    {{#if ../../owner}}
                    <div class="item-detail item-controls">
                        {{#if section.canPrepare}}
                        <a class="item-control item-toggle {{item.toggleClass}}" title="{{item.toggleTitle}}"><i
                                class="fas fa-check-circle"></i></a>
                        {{/if}}
                        <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
                        <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
                    </div>
                    {{/if}}
                </li>
                {{/each}}
            </ol>
        </li>
        {{else}}
        {{#if owner}}
        {{#if filters.powerbook.size}}
        <li class="item flexrow">
            <p class="notes">{{localize "SW5E.FilterNoPowers"}}</p>
        </li>
        {{else}}
        <li class="item flexrow inventory-header powerbook-header powerbook-empty">
            <div class="item-controls">
                <a class="item-control item-create" title="{{localize 'SW5E.PowerCreate'}}" data-type="power"
                    data-level="{{lvl}}"><i class="fas fa-plus"></i> {{localize "SW5E.PowerAdd"}}</a>
            </div>
        </li>
        <li class="item flexrow">
            <p class="notes">{{localize "SW5E.NoPowerLevels"}}</p>
        </li>
        {{/if}}
        {{/if}}
        {{/each}}
    </ol>
</section>