/**
 * Reactive state for admin session overview.
 *
 * Both the listing and the two revoke-all mutations flow through the shared
 * `AdminAccountsRpc` adapter (`list_sessions`, `session_revoke_all`,
 * `token_revoke_all`); the listing wraps the `admin_session_list` RPC
 * method.
 *
 * Holds one fetch `AsyncSlot` (`list`) plus two `KeyedAsyncSlot`s keyed by
 * `account_id` — `revoke_sessions` and `revoke_tokens`. Per-account
 * concurrent revokes are independent (clicking row B does not abort row A)
 * and per-row errors surface via `revoke_sessions.error(account_id)` /
 * `revoke_tokens.error(account_id)`.
 *
 * @module
 */
import { AsyncSlot } from './async_slot.svelte.js';
import { KeyedAsyncSlot } from './keyed_async_slot.svelte.js';
export class AdminSessionsState {
    #get_rpc;
    list = new AsyncSlot();
    revoke_sessions = new KeyedAsyncSlot();
    revoke_tokens = new KeyedAsyncSlot();
    sessions = $state.raw([]);
    active_count = $derived(this.sessions.length);
    constructor(options) {
        this.#get_rpc = options.get_rpc;
    }
    async fetch() {
        await this.list.run(async () => {
            const { sessions } = await this.#get_rpc().list_sessions();
            this.sessions = sessions;
        });
    }
    async submit_revoke_sessions(account_id) {
        await this.revoke_sessions.run(account_id, async () => {
            await this.#get_rpc().session_revoke_all({ account_id });
        });
        if (this.revoke_sessions.succeeded(account_id))
            await this.fetch();
    }
    async submit_revoke_tokens(account_id) {
        await this.revoke_tokens.run(account_id, async () => {
            await this.#get_rpc().token_revoke_all({ account_id });
        });
        if (this.revoke_tokens.succeeded(account_id))
            await this.fetch();
    }
}
