/**
 * Reactive state for admin app settings management.
 *
 * Flows every operation through an injected `AppSettingsRpc` adapter — mirrors
 * `AdminInvitesRpc` / `AuditLogRpc`. Tests can inject plain-function stubs
 * and consumers adapt their typed RPC client to the same shape.
 *
 * Holds two `AsyncSlot`s — `list` (the initial fetch) and `update` (the
 * `app_settings_update` write). Slots track status/error; the canonical
 * `settings` lives on the class so consumers don't unwrap `slot.data`.
 *
 * @module
 */
import { create_context } from '@fuzdev/fuz_ui/context_helpers.js';
import { AsyncSlot } from './async_slot.svelte.js';
/**
 * Svelte context carrying the reactive `AppSettingsRpc` accessor. Mirrors
 * `admin_accounts_rpc_context`. `get()` throws when no provisioner ran above
 * the component — the adapter is required.
 */
export const app_settings_rpc_context = create_context();
export class AppSettingsState {
    #get_rpc;
    list = new AsyncSlot();
    update = new AsyncSlot();
    settings = $state.raw(null);
    constructor(options) {
        this.#get_rpc = options.get_rpc;
    }
    async fetch() {
        await this.list.run(async () => {
            const { settings } = await this.#get_rpc().get();
            this.settings = settings;
        });
    }
    async update_open_signup(value) {
        await this.update.run(async () => {
            const { settings } = await this.#get_rpc().update({ open_signup: value });
            this.settings = settings;
        });
    }
}
