{"version":3,"file":"index.CVRKgaU6.js","sources":["../../../../../../src/lib/utils/session-store/local/store.ts","../../../../../../src/lib/utils/session-store/index.ts"],"sourcesContent":["import type { SessionStore, PendingUserInfo } from \"../types\"\nimport { type Readable, type Writable, writable, derived } from 'svelte/store';\nimport { browser } from \"$app/environment\";\nimport type { SubmitDownloadBrochureResponse } from \"$lib/api/generated/cta-services\";\n\nconst createLocalStore = (key, startValue) => {\n const {\n subscribe,\n set,\n update\n } = writable(startValue)\n\n return {\n subscribe,\n set,\n update,\n useLocalStorage: () => {\n const json = localStorage.getItem(key);\n if (json) {\n set(JSON.parse(json));\n }\n\n subscribe(current => {\n localStorage.setItem(key, JSON.stringify(current));\n });\n }\n };\n}\n\nconst createSessionStore = (key, startValue) => {\n const store = writable(startValue);\n return {\n ...store,\n useSessionStore: () => {\n const json = sessionStorage.getItem(key);\n if(json) {\n store.set(JSON.parse(json));\n }\n store.subscribe(current => sessionStorage.setItem(key, JSON.stringify(current)));\n }\n }\n}\n\n/**\n * Basic implementation of session store\n */\nexport class SessionStoreImpl implements SessionStore {\n\n private static _instance: SessionStoreImpl | null;\n private _pendingUserInfo: Writable;\n private static PENDING_USER_INFO_KEY = \"pendingUserInfo\";\n\n private _downloadBrochureResult: Writable;\n private static DOWNLOAD_BROCHURE_RESULT_KEY = \"downloadBrochureResult\";\n\n private _loginOptions: Writable<{ email: string; channel: string}>;\n private static LOGIN_OPTIONS_KEY = \"loginOptions\";\n\n private _companyStatus: Writable;\n private static COMPANY_STATUS_KEY = \"CompanyStatus\";\n\n private _selectedCompanyStatus: Writable;\n private static SELECTED_COMPANY_STATUS_KEY = \"selectedCompanyStatus\";\n\n private constructor() {\n this._pendingUserInfo = createLocalStore(SessionStoreImpl.PENDING_USER_INFO_KEY, null);\n this._downloadBrochureResult = createSessionStore(SessionStoreImpl.DOWNLOAD_BROCHURE_RESULT_KEY, null);\n this._loginOptions = createLocalStore(SessionStoreImpl.LOGIN_OPTIONS_KEY, null);\n this._companyStatus = createLocalStore(SessionStoreImpl.COMPANY_STATUS_KEY, false);\n this._selectedCompanyStatus = createLocalStore(SessionStoreImpl.SELECTED_COMPANY_STATUS_KEY, null);\n\n if (browser) {\n (this._pendingUserInfo as any).useLocalStorage();\n (this._downloadBrochureResult as any).useSessionStore();\n (this._loginOptions as any).useLocalStorage();\n (this._companyStatus as any).useLocalStorage();\n (this._selectedCompanyStatus as any).useLocalStorage();\n }\n }\n\n public static getInstance() {\n if (SessionStoreImpl._instance == null) {\n SessionStoreImpl._instance = new SessionStoreImpl();\n }\n\n return SessionStoreImpl._instance;\n }\n\n /**\n * Store the not confirmed user info into the session.\n * @param userInfo The user info to store.\n */\n public setPendingUserInfo(userInfo: PendingUserInfo) {\n this._pendingUserInfo.set(userInfo);\n }\n\n /**\n * Clean the pending user info fro the store.\n */\n public cleanPendingUserInfo() {\n this._pendingUserInfo.set(null);\n }\n\n /**\n * Get the unconfirmed user info from the session.\n */\n get pendingUserInfo(): Readable {\n return derived(this._pendingUserInfo, (value) => { return value });\n }\n\n\n /**\n * Store te download brochure result into the session\n * @param downloadBrochureResult The result to store\n */\n setLoginOptions(loginOptions: { email: string; channel: string }) {\n this._loginOptions.set(loginOptions);\n }\n\n\n /**\n * Clean the login options from the session store\n */\n cleanLoginOptions() {\n this._loginOptions.set(null);\n }\n\n\n get loginOptions() {\n return derived(this._loginOptions, (value) => (value));\n }\n\n\n /**\n * Store the login options into the local store\n * @param downloadBrochureResult The result to store\n */\n setDownloadBrochureResult(downloadBrochureResult: DownloadBrochureResult) {\n this._downloadBrochureResult.set(downloadBrochureResult);\n }\n\n\n /**\n * Clean the download brochure result from the session store\n */\n cleanDownloadBrochureResult() {\n this._downloadBrochureResult.set(null);\n }\n\n\n /**\n * Get the company status result from the local storage\n */\n get downloadBrochureresult(): Readable {\n return derived(this._downloadBrochureResult, (value) => (value));\n }\n\n\n /**\n * Store the company status result into the local store\n */\n setCompanyStatus(companyStatus: boolean) {\n this._companyStatus.set(companyStatus);\n this._selectedCompanyStatus.set(true);\n }\n\n\n /**\n * Clean the company status from the local store\n */\n cleanCompanyStatus() {\n this._companyStatus.set(null);\n }\n\n\n get companyStatus() {\n return derived(this._companyStatus, (value) => (value));\n }\n\n /**\n * Store the company status selected result into the local store\n */\n setSelectedCompanyStatus(companyStatus: boolean) {\n this._selectedCompanyStatus.set(companyStatus);\n }\n\n get selectedCompanyStatus() {\n return derived(this._selectedCompanyStatus, (value) => (value));\n }\n}","export type { SessionStore, PendingUserInfo } from './types'\n\nimport { SessionStoreImpl } from './local/store'\n\nexport const useSessionStore = SessionStoreImpl.getInstance"],"names":["createLocalStore","key","startValue","subscribe","set","update","writable","json","current","createSessionStore","store","_SessionStoreImpl","__publicField","userInfo","derived","value","loginOptions","downloadBrochureResult","companyStatus","SessionStoreImpl","useSessionStore"],"mappings":"mNAKA,MAAMA,EAAmB,CAACC,EAAKC,IAAe,CACpC,KAAA,CACF,UAAAC,EACA,IAAAC,EACA,OAAAC,CAAA,EACAC,EAASJ,CAAU,EAEhB,MAAA,CACH,UAAAC,EACA,IAAAC,EACA,OAAAC,EACA,gBAAiB,IAAM,CACb,MAAAE,EAAO,aAAa,QAAQN,CAAG,EACjCM,GACIH,EAAA,KAAK,MAAMG,CAAI,CAAC,EAGxBJ,EAAqBK,GAAA,CACjB,aAAa,QAAQP,EAAK,KAAK,UAAUO,CAAO,CAAC,CAAA,CACpD,CAAA,CAET,CACJ,EAEMC,EAAqB,CAACR,EAAKC,IAAe,CACtC,MAAAQ,EAAQJ,EAASJ,CAAU,EAC1B,MAAA,CACH,GAAGQ,EACH,gBAAiB,IAAM,CACb,MAAAH,EAAO,eAAe,QAAQN,CAAG,EACpCM,GACCG,EAAM,IAAI,KAAK,MAAMH,CAAI,CAAC,EAExBG,EAAA,aAAqB,eAAe,QAAQT,EAAK,KAAK,UAAUO,CAAO,CAAC,CAAC,CAAA,CAEvF,CACJ,EAKaG,EAAN,MAAMA,CAAyC,CAkB1C,aAAc,CAfdC,EAAA,yBA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