// Which workspace file is open in the viewer. Sibling to SelectionStore (which
// owns thread-item inspect selection) — the two are orthogonal domains with
// different lifecycles, so they stay separate stores rather than one fused FSM.
/**
 * Framework-agnostic store for the currently-open workspace file.
 *
 * Implements the `useSyncExternalStore` contract identical to
 * {@link import("./selection-store.js").SelectionStore}: the context carries the
 * store instance (stable ref), and `getSelection` returns the stored object
 * reference — a new object is allocated only inside `select` — so `getSnapshot`
 * never triggers a re-render loop.
 */
export class WorkspaceFileSelectionStore {
    _selected = null;
    _listeners = new Set();
    // -- Mutations -----------------------------------------------------------
    select(file) {
        if (selectedEqual(this._selected, file))
            return;
        this._selected = file;
        this._notify();
    }
    deselect() {
        if (this._selected === null)
            return;
        this._selected = null;
        this._notify();
    }
    toggle(file) {
        if (selectedEqual(this._selected, file)) {
            this.deselect();
        }
        else {
            this.select(file);
        }
    }
    // -- useSyncExternalStore contract ---------------------------------------
    subscribe = (listener) => {
        this._listeners.add(listener);
        return () => {
            this._listeners.delete(listener);
        };
    };
    /** Returns the current selection (stable ref between mutations). */
    getSelection = () => {
        return this._selected;
    };
    // -- Internal ------------------------------------------------------------
    _notify() {
        for (const listener of this._listeners) {
            listener();
        }
    }
}
function selectedEqual(a, b) {
    if (a === b)
        return true;
    if (a === null || b === null)
        return false;
    return a.entryId === b.entryId && a.path === b.path;
}
//# sourceMappingURL=workspace-file-selection-store.js.map