/* eslint-disable */ /* © 2026 K2B NETWORK SOLUTIONS LLC. All rights reserved. Proprietary and confidential. Unauthorized copying, distribution, or use of this file, via any medium, is strictly prohibited. Original work product. */ // K2B DMS — StoreKit (RC35, lane brd): what the screen shows of the STORE you are in and the store switch (SPEC 4.3 / 4.4). // the 4 px stripe in the store's color (only once the server has 2+ stores - with one store the screen is RC34's) // the top bar's store: the print name (one store) or a button "● ▾" (2+ stores) that opens the store menu // the top of the ☰ Menu on a phone's service screens: logo + name + "Switch store" // the store's logo (or its monogram) - never another store's file // the switch dialogs: unsaved work, "this window is in another store", "you can no longer use this store" // window.k2bUnsaved.register(id, { label, isDirty(), save?(), discard?() }) -> unregister (screens with their own Save button) // window.k2bStoreSwitchFlow(id) = K2BStore.switchTo(id): unsaved work first (nothing is half-saved), then the server, then a FULL reload. const sk$ = () => window.K2BStore || null; /** re-render on every store change (boot answer, branding broadcast, store list) */ function useK2BStore() { const [, setN] = React.useState(0); React.useEffect(() => { const st = sk$(); if (!st) return undefined; return st.onChange(() => setN((n) => n + 1)); }, []); return sk$(); } /* ── the unsaved-work registry ── */ const skUnsaved = (() => { const items = new Map(); return { register(id, spec) { if (!id || !spec) return () => {}; items.set(String(id), spec); return () => { if (items.get(String(id)) === spec) items.delete(String(id)); }; }, list() { return Array.from(items.entries()).map(([id, s]) => ({ id, label: String(s.label || id), dirty: (() => { try { return !!(s.isDirty && s.isDirty()); } catch (e) { return false; } })(), spec: s })); }, dirty() { return this.list().filter((x) => x.dirty); }, }; })(); window.k2bUnsaved = skUnsaved; /** a screen with its own Save button: useK2BUnsaved("svc-setup", { label: "Service Setup", isDirty: () => dirty, save, discard }) */ function useK2BUnsaved(id, spec) { const ref = React.useRef(spec); ref.current = spec; React.useEffect(() => skUnsaved.register(id, { get label() { return ref.current.label; }, isDirty: () => !!(ref.current.isDirty && ref.current.isDirty()), save: ref.current.save ? () => ref.current.save() : undefined, discard: ref.current.discard ? () => ref.current.discard() : undefined }), [id]); } window.useK2BUnsaved = useK2BUnsaved; /* ── pieces of the screen ── */ function K2BStoreLogo({ size, className, style }) { const st = useK2BStore(); if (!st) return null; const b = st.branding(); const src = st.logoUrl(size >= 64 ? "large" : "small") || st.monogramUrl(Math.max(24, size || 38)); return {b.dba}; } function K2BStoreBand() { const st = useK2BStore(); if (!st || !st.multiStore()) return null; return