/**
 * Reactive sidebar visibility state. Provisioned by `AppShell.svelte` via
 * `sidebar_state_context`; consumers read `show_sidebar` and call
 * `toggle_sidebar` / `activate`.
 *
 * @module
 */
import { create_context } from '@fuzdev/fuz_ui/context_helpers.js';
/**
 * Svelte context carrying a reactive `SidebarState` accessor. Set by
 * `AppShell.svelte` (creates a fresh `SidebarState` if not supplied);
 * consumers call `sidebar_state_context.get()` to read or toggle visibility.
 */
export const sidebar_state_context = create_context();
export class SidebarState {
    #get_enabled;
    #enabled = $state.raw(true);
    #show_sidebar = $state.raw(true);
    get enabled() {
        return this.#get_enabled?.() ?? this.#enabled;
    }
    set enabled(value) {
        this.#enabled = value;
    }
    get show_sidebar() {
        if (!this.enabled)
            return false;
        return this.#show_sidebar;
    }
    set show_sidebar(value) {
        this.#show_sidebar = value;
    }
    constructor(options) {
        this.#get_enabled = options?.enabled;
    }
    toggle_sidebar(value = !this.show_sidebar) {
        this.show_sidebar = value;
    }
    /**
     * Show the sidebar and enable the toggle. The returned disposer hides
     * and disables on cleanup — pair with `$effect` for scoped activation.
     *
     * @mutates `this` - sets `enabled` and `show_sidebar`; disposer clears both
     */
    activate() {
        this.enabled = true;
        this.show_sidebar = true;
        return () => {
            this.enabled = false;
            this.show_sidebar = false;
        };
    }
}
