{"version":3,"file":"useLastUsedAuthMethod.mjs","sources":["../../../../../../../../../web/src/ui/b2b/hooks/useLastUsedAuthMethod.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport { readB2BInternals } from '../../../utils/internal';\nimport { safeLocalStorage } from '../../../utils/storage';\nimport { useStytch } from '../GlobalContextProvider';\nimport { LastUsedMethod } from '../types/authMethodKeys';\n\n/**\n * Hook for managing the last used authentication method in B2B flows.\n * The returned value is not reactive and will not update when setLastUsedMethod is called.\n */\nexport function useLastUsedAuthMethod() {\n  const stytch = useStytch();\n  const { publicToken } = readB2BInternals(stytch);\n\n  // Deliberately not using useLocalStorage because we _don't_ want the buttons\n  // to reorder while the user is still seeing this page\n  const lastUsedMethod = useMemo(() => safeLocalStorage.getItem(publicToken, 'b2b_last_used_method'), [publicToken]);\n  const setLastUsedMethod = (method: LastUsedMethod) => {\n    safeLocalStorage.setItem(publicToken, 'b2b_last_used_method', method);\n  };\n\n  return [lastUsedMethod, setLastUsedMethod] as const;\n}\n"],"names":["useLastUsedAuthMethod","stytch","useStytch","publicToken","readB2BInternals","lastUsedMethod","useMemo","safeLocalStorage","getItem","setLastUsedMethod","method","setItem"],"mappings":";;;;;;AAOA;;;AAGC,IACM,SAASA,qBAAAA,GAAAA;AACd,IAAA,MAAMC,MAAAA,GAASC,SAAAA,EAAAA;AACf,IAAA,MAAM,EAAEC,WAAW,EAAE,GAAGC,gBAAAA,CAAiBH,MAAAA,CAAAA;;;AAIzC,IAAA,MAAMI,iBAAiBC,CAAAA,CAAQ,IAAMC,iBAAiBC,OAAO,CAACL,aAAa,sBAAA,CAAA,EAAyB;AAACA,QAAAA;AAAY,KAAA,CAAA;AACjH,IAAA,MAAMM,oBAAoB,CAACC,MAAAA,GAAAA;QACzBH,gBAAAA,CAAiBI,OAAO,CAACR,WAAAA,EAAa,sBAAA,EAAwBO,MAAAA,CAAAA;AAChE,IAAA,CAAA;IAEA,OAAO;AAACL,QAAAA,cAAAA;AAAgBI,QAAAA;AAAkB,KAAA;AAC5C;;;;"}