import {
  atomWithLocalStorage,
  getLocalStorageItem,
  setLocalStorageItem,
} from './utils/atomWithLocalStorage';

const CUSTOM_WINDOW_CHROME = 'customWindowChrome';

/**
 * P5-47 — TDS Custom Window Chrome opt-in flag (default `false`).
 *
 * Standalone, `localStorage`-backed boolean atom kept separate from
 * `state/settings.ts` on purpose. When `true` (and running inside Tauri) the app
 * strips the native window frame and renders its own `<TitleBar/>`; when `false`
 * the native OS frame is used. The feature is runtime-reversible, so flipping
 * this atom is all it takes to switch back and forth.
 */
export const customWindowChromeAtom = atomWithLocalStorage<boolean>(
  CUSTOM_WINDOW_CHROME,
  (key) => getLocalStorageItem<boolean>(key, false),
  (key, value) => setLocalStorageItem(key, value),
);
