{"version":3,"file":"dashboardStateStore.cjs","names":["Store","useStore","useCallback"],"sources":["../../../src/web/stores/dashboardStateStore.ts"],"sourcesContent":["import { useStore } from '@tanstack/react-store';\nimport { Store } from '@tanstack/store';\nimport { useCallback, type Dispatch, type SetStateAction } from 'react';\n\nconst states = new Map<string, unknown>();\n\n/** Memory only. Keys include the form and its resource, never the selected template. */\nexport function dashboardStateFor<T>(key: string, initial: T | (() => T)): Store<T> {\n  let store = states.get(key) as Store<T> | undefined;\n  if (store === undefined) {\n    store = new Store(typeof initial === 'function' ? (initial as () => T)() : initial);\n    states.set(key, store);\n  }\n  return store;\n}\n\n/** The store is also exposed for synchronous admission checks in event handlers. */\nexport function useDashboardState<T>(key: string, initial: T | (() => T)): [T, Dispatch<SetStateAction<T>>, Store<T>] {\n  const store = dashboardStateFor(key, initial);\n  const value = useStore(store);\n  const set = useCallback<Dispatch<SetStateAction<T>>>(\n    (next) => {\n      store.setState((previous) => (typeof next === 'function' ? (next as (value: T) => T)(previous) : next));\n    },\n    [store],\n  );\n  return [value, set, store];\n}\n\n/** Test seam. Existing subscribers must be unmounted before resetting. */\nexport function resetDashboardState(): void {\n  states.clear();\n}\n"],"mappings":";;;;AAIA,MAAM,yBAAS,IAAI,IAAqB;;AAGxC,SAAgB,kBAAqB,KAAa,SAAkC;CAClF,IAAI,QAAQ,OAAO,IAAI,GAAG;CAC1B,IAAI,UAAU,KAAA,GAAW;EACvB,QAAQ,IAAIA,gBAAAA,MAAM,OAAO,YAAY,aAAc,QAAoB,IAAI,OAAO;EAClF,OAAO,IAAI,KAAK,KAAK;CACvB;CACA,OAAO;AACT;;AAGA,SAAgB,kBAAqB,KAAa,SAAoE;CACpH,MAAM,QAAQ,kBAAkB,KAAK,OAAO;CAQ5C,OAAO;GAPOC,GAAAA,sBAAAA,SAAAA,CAAS,KAOX;GANAC,GAAAA,MAAAA,YAAAA,EACT,SAAS;GACR,MAAM,UAAU,aAAc,OAAO,SAAS,aAAc,KAAyB,QAAQ,IAAI,IAAK;EACxG,GACA,CAAC,KAAK,CAES;EAAG;CAAK;AAC3B;;AAGA,SAAgB,sBAA4B;CAC1C,OAAO,MAAM;AACf"}