<div class="pg-setup-content">
    <section class="pg-wheel-availability" aria-label="Player Wheel availability">
        <label><input type="checkbox" name="playerGatewayEnabled" {{#if wheelEnabled}}checked{{/if}} {{#if busy}}disabled{{/if}} aria-describedby="pg-wheel-availability-hint"> Enable Player Wheel <span class="pg-state-label">All players and GMs</span></label>
        <p id="pg-wheel-availability-hint" class="pg-help" role="status">{{#if wheelEnabled}}Applies to everyone in this world. Changes save immediately.{{else}}The Player Wheel is disabled for everyone. Its toolbar control is hidden. Player identities and assignments are kept.{{/if}}</p>
    </section>
    <header class="pg-setup-header">
        <label>Player / GM<select name="userId" {{#if busy}}disabled{{/if}}>{{#each users}}<option value="{{id}}" {{#if selected}}selected{{/if}}>{{name}}{{#if isGM}} (GM){{/if}}</option>{{/each}}</select></label>
        {{#if hasUser}}<button type="button" data-action="preview" {{#unless wheelEnabled}}disabled{{/unless}}><i class="fas fa-compass"></i> {{#if isOwnHome}}Open my wheel{{else}}Preview wheel{{/if}}</button>{{/if}}
    </header>
    {{#if hasUser}}
    <section class="pg-identity-section">
        <header class="pg-section-heading"><button type="button" class="pg-section-toggle" data-action="toggleSection" data-section="character" aria-expanded="{{#if characterCollapsed}}false{{else}}true{{/if}}"><span><i class="fas fa-user"></i> Your character</span>{{#if characterCollapsed}}<small>{{characterSummary}}</small>{{/if}}<i class="fas {{#if characterCollapsed}}fa-chevron-right{{else}}fa-chevron-down{{/if}}"></i></button></header>
        {{#unless characterCollapsed}}
        <div class="pg-identity-grid">
            <div class="pg-identity-slot" data-drop-target="actor" aria-label="Drop character Actor">
                <span class="pg-slot-label">Character Actor</span>
                {{#if actor}}
                <div class="pg-setup-card">
                    <button type="button" class="pg-setup-record" data-action="open" data-kind="actor" data-uuid="{{actor.uuid}}"><img src="{{actor.image}}" alt="" draggable="false"><span><strong>{{actor.name}}</strong><small>{{actor.type}} · Actor sheet</small></span></button>
                    <button type="button" class="pg-setup-options" data-action="options" data-kind="actor" data-uuid="{{actor.uuid}}" aria-label="Options for {{actor.name}}" aria-haspopup="menu" aria-expanded="false"><i class="fas fa-ellipsis" aria-hidden="true"></i></button>
                </div>
                <small class="pg-drop-hint">Drop another Actor to replace</small>
                {{else}}<div class="pg-drop-empty"><i class="fas fa-user"></i><strong>Drop a character Actor</strong><small>From the Actors directory</small></div>{{/if}}
            </div>
            <div class="pg-identity-slot" data-drop-target="person" aria-label="Drop Nexus Person">
                <span class="pg-slot-label">Nexus Person</span>
                {{#if person}}
                <div class="pg-setup-card">
                    <button type="button" class="pg-setup-record" data-action="open" data-kind="person" data-uuid="{{person.uuid}}"><img src="{{person.image}}" alt="" draggable="false"><span><strong>{{person.name}}</strong><small>Person · Nexus dossier</small></span></button>
                    <button type="button" class="pg-setup-options" data-action="options" data-kind="person" data-uuid="{{person.uuid}}" aria-label="Options for {{person.name}}" aria-haspopup="menu" aria-expanded="false"><i class="fas fa-ellipsis" aria-hidden="true"></i></button>
                </div>
                <small class="pg-drop-hint">Drop another Person to replace</small>
                {{else}}<div class="pg-drop-empty"><i class="fas fa-address-card"></i><strong>Drop a Nexus Person</strong><small>From the Nexus directory</small></div>{{/if}}
            </div>
        </div>
        <div class="pg-identity-footer">
            {{#if canClearIdentity}}<button type="button" data-action="clearIdentity" data-actor-id="{{savedActorId}}" title="Remove this user's character assignment. Keeps the Actor, Person and Actor permissions."><i class="fas fa-unlink"></i> Clear identity</button>{{/if}}
            <p class="pg-help">Drops save immediately.{{#unless actor}} Choose an Actor first to create a Person.{{/unless}}</p>
            {{#unless person}}<button type="button" class="pg-primary-action" data-action="createPerson" {{#unless canCreatePerson}}disabled{{/unless}}><i class="fas fa-user-plus"></i> Create New Person</button>{{/unless}}
        </div>
        {{/unless}}
    </section>
    <section class="pg-identity-section pg-ship-section">
        <header class="pg-section-heading"><button type="button" class="pg-section-toggle" data-action="toggleSection" data-section="ship" aria-expanded="{{#if shipCollapsed}}false{{else}}true{{/if}}"><span><i class="fas fa-ship"></i> Your ship</span>{{#if shipCollapsed}}<small>{{shipSummary}}</small>{{/if}}<i class="fas {{#if shipCollapsed}}fa-chevron-right{{else}}fa-chevron-down{{/if}}"></i></button></header>
        {{#unless shipCollapsed}}
        <div class="pg-identity-grid">
            <div class="pg-identity-slot" data-drop-target="shipActor" aria-label="Drop Ship Actor">
                <span class="pg-slot-label">Ship Actor</span>
                {{#if shipActor}}
                <div class="pg-setup-card">
                    <button type="button" class="pg-setup-record" data-action="open" data-kind="actor" data-uuid="{{shipActor.uuid}}"><img src="{{shipActor.image}}" alt="" draggable="false"><span><strong>{{shipActor.name}}</strong><small>{{shipActor.type}} · Actor sheet</small></span></button>
                    <button type="button" class="pg-setup-options" data-action="options" data-kind="actor" data-uuid="{{shipActor.uuid}}" aria-label="Options for {{shipActor.name}}" aria-haspopup="menu" aria-expanded="false"><i class="fas fa-ellipsis" aria-hidden="true"></i></button>
                </div>
                <small class="pg-drop-hint">Drop another Actor to replace</small>
                {{else}}<div class="pg-drop-empty"><i class="fas fa-ship"></i><strong>Drop a Ship Actor</strong><small>Optional · From the Actors directory</small></div>{{/if}}
            </div>
            <div class="pg-identity-slot" data-drop-target="ship" aria-label="Drop Nexus Ship">
                <span class="pg-slot-label">Nexus Ship</span>
                {{#if ship}}
                <div class="pg-setup-card">
                    <button type="button" class="pg-setup-record" data-action="open" data-kind="ship" data-uuid="{{ship.uuid}}"><img src="{{ship.image}}" alt="" draggable="false"><span><strong>{{ship.name}}</strong><small>Ship · Nexus dossier</small></span></button>
                    <button type="button" class="pg-setup-options" data-action="options" data-kind="ship" data-uuid="{{ship.uuid}}" aria-label="Options for {{ship.name}}" aria-haspopup="menu" aria-expanded="false"><i class="fas fa-ellipsis" aria-hidden="true"></i></button>
                </div>
                <small class="pg-drop-hint">Drop another Ship to replace</small>
                {{else}}<div class="pg-drop-empty"><i class="fas fa-ship"></i><strong>Drop a Nexus Ship</strong><small>From the Nexus directory</small></div>{{/if}}
            </div>
        </div>
        <div class="pg-identity-footer">
            {{#if canClearShip}}<button type="button" data-action="clearShip" data-uuid="{{savedShipUuid}}" data-actor-uuid="{{savedShipActorUuid}}" title="Clear the Ship Actor and Nexus Ship assignments. Keeps documents, their link and permissions."><i class="fas fa-unlink"></i> Clear ship</button>{{/if}}
            <p class="pg-help">Drops save immediately. Ships can be shared by several players.</p>
            {{#unless ship}}<button type="button" class="pg-primary-action" data-action="createShip" {{#if busy}}disabled{{/if}}><i class="fas fa-plus"></i> Create New Ship</button>{{/unless}}
        </div>
        {{/unless}}
    </section>
    <section class="pg-assignment-section" data-drop-target="assignments" aria-label="Drop campaign entities to assign">
        <header class="pg-section-heading"><h3><i class="fas fa-layer-group"></i> {{#if selectedIsGM}}Wheel assignments{{else}}Additional access{{/if}}</h3><span class="pg-state-label">{{assignmentCount}} assigned</span></header>
        <p class="pg-help">{{#if selectedIsGM}}Choose People, Groups, Ships, or Places for this GM’s wheel. Drop an entry below.{{else}}Give this player access to other People, Groups, Ships, or Places. Drop an entry below.{{/if}}</p>
        {{#if suggested}}<button type="button" class="pg-suggested" data-action="addSuggested"><i class="fas fa-plus"></i> Assign {{suggested.name}}</button>{{/if}}
        <div class="pg-assigned">
            {{#each assigned}}
            <article class="pg-setup-card {{#if missing}}is-missing{{/if}}">
                <button type="button" class="pg-setup-record" data-action="open" data-kind="assignment" data-uuid="{{uuid}}" {{#if missing}}disabled{{/if}}><img src="{{image}}" alt="" draggable="false"><span><strong>{{name}}</strong><small>{{typeLabel}}</small><em class="pg-access-label">{{accessLabel}}</em></span></button>
                <button type="button" class="pg-setup-options" data-action="options" data-kind="assignment" data-uuid="{{uuid}}" aria-label="Options for {{name}}" aria-haspopup="menu" aria-expanded="false"><i class="fas fa-ellipsis" aria-hidden="true"></i></button>
            </article>
            {{else}}<div class="pg-drop-empty"><i class="fas fa-hand-holding"></i><strong>Give access to other campaign entities</strong><small>Drop campaign entities to start their collection</small></div>{{/each}}
            <div class="pg-assignment-drop-hint"><i class="fas fa-plus"></i> Drop to assign</div>
        </div>
        <p class="pg-help pg-access-help">{{#if selectedIsGM}}Assignments choose what appears in the wheel. The GM keeps full access.{{else}}View only: the player can see it. Full control: they can edit it. Removing access never deletes the object.{{/if}}</p>
    </section>
    {{else}}<p class="pg-help">Create a player User in Foundry first.</p>{{/if}}
    {{#if message}}<p class="pg-message" role="status">{{message}}</p>{{/if}}
</div>
