<header class="character-header-sheet">
    <line-div></line-div>
    <div class="name-row">
        <h1
            class="actor-name input"
            contenteditable="plaintext-only"
            data-property="name"
            placeholder="{{localize "DAGGERHEART.GENERAL.actorName"}}"
            autocomplete="off"
            spellcheck="false"
        >{{source.name}}</h1>
        <div class='level-div'>
            <h3 class='label'>
                {{#if @root.editable}}
                    {{#if document.system.needsCharacterSetup}}
                        <button
                            type="button"
                            class="level-button glow"
                            data-action="levelManagement"
                        >
                            {{localize "DAGGERHEART.APPLICATIONS.CharacterCreation.buttonTitle"}}
                        </button>
                    {{else if document.system.levelData.canLevelUp}}
                        <button
                            type="button"
                            class="level-button glow" data-tooltip="{{localize "DAGGERHEART.ACTORS.Character.levelUp"}}"
                            data-action="levelManagement"
                        >
                            <i class="fa-solid fa-angles-up"></i>
                        </button>
                    {{/if}}
                {{/if}}
                {{#unless document.system.needsCharacterSetup}}
                    {{localize 'DAGGERHEART.GENERAL.level'}}
                    <input type="text" data-dtype="Number" class="level-value" value={{#if document.system.needsCharacterSetup}}0{{else}}{{document.system.levelData.level.changed}}{{/if}} {{#if document.system.needsCharacterSetup}}disabled{{/if}} />
                {{/unless}}
            </h3>
        </div>
    </div>
    <div class="character-details">
        <div>
            {{#if document.system.class.value}}
                <span data-action="editDoc" data-item-uuid="{{document.system.class.value.uuid}}">{{document.system.class.value.name}}</span>
            {{else}}
                <span class="missing-header-feature" data-action="openPack" data-key="classes">{{localize 'TYPES.Item.class'}}</span>
            {{/if}}
            <span class="dot">•</span>
            {{#if document.system.class.subclass}}
                <span data-action="editDoc" data-item-uuid="{{document.system.class.subclass.uuid}}">{{document.system.class.subclass.name}}</span>
            {{else}}
                <span class="missing-header-feature" data-action="openPack" data-key="subclasses">{{localize 'TYPES.Item.subclass'}}</span>
            {{/if}}
            <span class="dot">•</span>
            {{#if document.system.community}}
                <span data-action="editDoc" data-item-uuid="{{document.system.community.uuid}}">{{document.system.community.name}}</span>
            {{else}}
                <span class="missing-header-feature" data-action="openPack" data-key="communities">{{localize 'TYPES.Item.community'}}</span>
            {{/if}}
            <span class="dot">•</span>
            {{#if document.system.ancestry}}
                <span data-action="editDoc" data-item-uuid="{{document.system.ancestry.uuid}}">{{document.system.ancestry.name}}</span>
            {{else}}
                <span class="missing-header-feature" data-action="openPack" data-key="ancestries">{{localize 'TYPES.Item.ancestry'}}</span>
            {{/if}}
        </div>

        {{#if (or document.system.multiclass.value document.system.multiclass.subclass)}}
            <div class="multiclass">
                {{#if document.system.multiclass.value}}
                    <span data-action="editDoc"data-item-uuid="{{document.system.multiclass.value.uuid}}">{{document.system.multiclass.value.name}}</span>
                {{else}}
                    <span data-action="openPack" data-key="classes">{{localize 'DAGGERHEART.GENERAL.multiclass'}}</span>
                {{/if}}
                <span class="dot">•</span>
                {{#if document.system.multiclass.subclass}}
                    <span data-action="editDoc" data-item-uuid="{{document.system.multiclass.subclass.uuid}}">{{document.system.multiclass.subclass.name}}</span>
                {{else}}
                    <span class="missing-header-feature" data-action="openPack" data-key="subclasses">{{localize 'TYPES.Item.subclass'}}</span>
                {{/if}}
            </div>
        {{/if}}


    </div>

    <div class="character-row">
        <div class="resource-section">
            <div class="hope-section">
                <h4>{{localize "DAGGERHEART.GENERAL.hope"}}</h4>
                {{#times document.system.resources.hope.max}}
                    <span class='hope-value' data-action='toggleHope' data-value="{{add this 1}}">
                        {{#if (gte ../document.system.resources.hope.value (add this 1))}}
                            <i class='fa-solid fa-diamond'></i>
                        {{else}}
                            <i class='fa-regular fa-circle'></i>
                        {{/if}}
                    </span>
                {{/times}}
                {{#times document.system.scars}}
                    <span class='hope-value scar'>
                        <i class='fa-regular fa-ban'></i>
                    </span>
                {{/times}}
                {{#if hasExtraResources}}<a type="button" class="resource-manager" data-action="toggleResourceManagement"><i class="fa-solid fa-angle-down"></i></a>{{/if}}
            </div>
        </div>
        {{#if document.system.class.value}}
            <div class="domains-section">
                {{#each document.system.domainData as |data|}}
                    <div class="domain">
                        <img src="{{data.src}}" alt="" data-tooltip="{{data.label}}" />
                    </div>
                {{/each}}
            </div>
        {{/if}}
        <div class="downtime-section">
            {{#if document.parties.size}}
                <button type="button" data-action="viewParty" data-tooltip="DAGGERHEART.ACTORS.Character.viewParty">
                    <i class="fa-solid fa-fw fa-users"></i>
                </button>
            {{/if}}
            {{#if @root.editable}}
                <button type="button" data-action="useDowntime" data-type="shortRest" data-tooltip="DAGGERHEART.APPLICATIONS.Downtime.shortRest.title">
                    <i class="fa-solid fa-fw fa-utensils"></i>
                </button>
                <button type="button" data-action="useDowntime" data-type="longRest" data-tooltip="DAGGERHEART.APPLICATIONS.Downtime.longRest.title">
                    <i class="fa-solid fa-fw fa-bed"></i>
                </button>
            {{/if}}
        </div>
    </div>

    <div class="character-traits">
        {{#each this.attributes as |attribute key|}} 
            <div class="trait {{#if isSpellcasting}}with-spellcasting{{/if}}" data-tooltip="<b>{{attribute.label}}:</b><br>{{#each attribute.verbs}}{{this}}<br>{{/each}}" data-action="rollAttribute" data-attribute="{{key}}" data-value="{{attribute.value}}">
                <div class="trait-name">
                    <div class="tier-mark {{#if attribute.tierMarked}}marked{{/if}}"></div>
                    <span>{{attribute.label}}</span>
                </div>
                <div class="trait-value-area">
                    <svg width="52" height="46" viewBox="0 0 52 46" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M 0,0 H 52 L 51.0714,18.254 48.781,24.0952 47.5745,39.9596 26,46 4.42553,39.9596 3.219,24.0952 0.928571,18.254 Z" fill="var(--color-border)"/>
                        <path d="M 3.312,5.357 8.58596,0 H 43.414 l 5.274,5.357 -1.8797,28.846 c -0.2431,2.605 -2.1461,4.7522 -4.7031,5.3064 l -14.8343,3.2151 c -0.8375,0.1816 -1.7043,0.1816 -2.5418,0 L 9.89482,39.5094 C 7.33785,38.9552 5.43478,36.808 5.19169,34.203 Z" fill="var(--background)"/>
                    </svg>
                    <div class="trait-value">
                        {{#if (gt attribute.value 0)}}
                            <span>+{{attribute.value}}</span>
                        {{else}}
                            <span>{{attribute.value}}</span>
                        {{/if}}
                    </div>
                    {{#if isSpellcasting}}
                        <div class="spellcasting-mark" data-tooltip="DAGGERHEART.ITEMS.Subclass.spellcastingTrait">
                            <i class="fa-solid fa-wand-magic-sparkles" inert></i>
                        </div>
                    {{/if}}
                </div>
            </div>
        {{/each}}
    </div>

    {{#> 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' }}
        <button type="button" data-action="openSettings" data-tooltip-text="{{localize "DAGGERHEART.UI.Tooltip.openSheetSettings"}}"><i class="fa-solid fa-wrench"></i></button>
    {{/'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs'}}
</header>