/**
 * Cross-component flag for the reader's "hide all chrome" view.
 *
 * The reader page toggles this; the root layout reads it to hide the
 * top app navbar; the reader itself reads it to hide its own nav bar
 * and bottom chapter bar. CSS handles the slide animations via a
 * `data-reader-fullscreen` attribute on `<html>` so the entire frame
 * (layout chrome included) stays synchronised.
 *
 * Always reset on reader unmount — letting the flag leak across
 * navigation would orphan a hidden app navbar on other pages.
 */
let active = $state(false);

export const readerFullscreen = {
    get value() {
        return active;
    },
    set value(v: boolean) {
        active = v;
        if (typeof document !== 'undefined') {
            if (v) document.documentElement.dataset.readerFullscreen = 'true';
            else delete document.documentElement.dataset.readerFullscreen;
        }
    },
    toggle() {
        this.value = !active;
    },
    /** Force off — call from the reader's onDestroy. */
    reset() {
        this.value = false;
    }
};
