{"version":3,"file":"useIsTenantSwitching.mjs","names":["useContext","UserDispatchContext","useUser","normalizeTenantId","id","undefined","String","useSelectedTenantId","$","_c","user","actions","t0","selectedTenantId","currentTenantId","useIsTenantSwitching","Boolean","isTenantSwitching"],"sources":["../../../src/utilities/tenant/useIsTenantSwitching.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { UserDispatchContext } from '../auth/internal';\nimport { useUser } from '../auth/useUser';\n\nconst normalizeTenantId = (\n  id: string | number | null | undefined\n): string | null =>\n  id === null || id === undefined || id === '' ? null : String(id);\n\n/**\n * The tenant the app is switching TO, or the active one when no switch is in\n * flight. Prefer `user.currentTenantId` for anything describing the tenant\n * whose data is currently rendered; use this when you need the tenant the user\n * has asked for.\n */\nexport const useSelectedTenantId = (): string | null => {\n  const user = useUser();\n  const actions = useContext(UserDispatchContext);\n  return (\n    normalizeTenantId(actions?.selectedTenantId) ??\n    normalizeTenantId(user?.currentTenantId)\n  );\n};\n\n/**\n * True from the moment a tenant switch starts until the tenant-scoped user has\n * caught up.\n *\n * `UserProvider` keeps the previous user rendered while the new one loads, so\n * for that window `user.currentTenantId` still names the tenant we just left —\n * and so does everything keyed off it: menus, permissions, the `/` home\n * redirect. Guard on this before acting on tenant-scoped data.\n *\n * Read from the user query rather than compared against the selected tenant on\n * purpose: the API may answer a switch with a different tenant than the one\n * asked for (no access, so it falls back to the user's default), and a\n * comparison would then read as \"switching\" forever.\n */\nexport const useIsTenantSwitching = (): boolean => {\n  const actions = useContext(UserDispatchContext);\n  return Boolean(actions?.isTenantSwitching);\n};\n"],"mappings":";;;;;AAIA,MAAMG,qBACJC,OAEAA,OAAO,QAAQA,OAAOC,KAAAA,KAAaD,OAAO,KAAK,OAAOE,OAAOF,GAAG;;;;;;;AAQlE,MAAaG,4BAAsB;CAAA,MAAAC,IAAAC,EAAA,EAAA;CACjC,MAAAC,OAAaR,SAAS;CACtB,MAAAS,UAAgBX,WAAWC,oBAAoB;CAAC,IAAAW;AAAA,KAAAJ,EAAA,OAAAG,SAAAE,oBAAAL,EAAA,OAAAE,MAAAI,iBAAA;AAE9CF,OAAAT,kBAAkBQ,SAAOE,iBACe,IAAxCV,kBAAkBO,MAAII,gBAAkB;AAAAN,IAAA,KAAAG,SAAAE;AAAAL,IAAA,KAAAE,MAAAI;AAAAN,IAAA,KAAAI;OAAAA,MAAAJ,EAAA;AAAA,QADxCI;;;;;;;;;;;;;;;;AAmBJ,MAAaG,6BAAuB;CAClC,MAAAJ,UAAgBX,WAAWC,oBAAoB;AAAC,QACzCe,QAAQL,SAAOM,kBAAoB"}