{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/2pPIzIqjTTFDFKpQTOgW/x0k1TeAkssgDW7ao7K2C/Outseta.js"],
  "sourcesContent": ["import{jsx as _jsx}from\"react/jsx-runtime\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";// Create a store for Outseta user data\nconst useOutsetaStore=createStore({userData:null});// Define constant for the total number of lessons in the course\nconst numberOfLessons=15;// Define constants for the different lesson status variants\nconst loadingVariantName=\"Loading\";const notStartedVariantName=\"Not started\";const finishedVariantName=\"Finished\";// This function is an override that adds a 'variant' prop to a component based on the lesson status in the Outseta store\nexport function withLessonStatus(Component){return props=>{const[store,setStore]=useOutsetaStore();let variant=loadingVariantName;// Extract the lesson number from props.name\nconst lessonNumber=props.name.match(/\\d+/)[0];if(store.userData){variant=store.userData.Account[`Lesson${lessonNumber}Status`];}return /*#__PURE__*/ _jsx(Component,{...props,variant:variant,\"data-outseta-button\":\"status\"});};}// This function updates the status of a lesson in both Outseta and the store\nfunction updateLessonStatus(lessonNumber,newStatus,store,setStore){// Check if window object exists (i.e., code is running in the browser)\nif(typeof window!==\"undefined\"){// Check if status has to be changed\nif(store.userData.Account[`Lesson${lessonNumber}Status`]!=newStatus){let Outseta=window[\"Outseta\"];Outseta.getUser().then(userData=>{// Update the corresponding lesson status in Outseta\nuserData.Account[`Lesson${lessonNumber}Status`]=newStatus;userData.update(userData);// Update the corresponding lesson status in the store\nsetStore({userData:{...store.userData,Account:{...store.userData.Account,[`Lesson${lessonNumber}Status`]:newStatus}}});console.log(`Status of Lesson #${lessonNumber} set to ${newStatus}`);}).catch(error=>{// Handle any errors that occurred while fetching user data\nconsole.error(\"An error occurred while updating lesson status:\",error);});}else{console.log(`Status of Lesson #${lessonNumber} is already set to ${newStatus}`);}}}// This function is an override that adds an onClick handler to a component\n// The handler sets the status of a lesson in Outseta and the store to 'Finished'\nexport function withLessonFinishedButton(Component){return props=>{const[store,setStore]=useOutsetaStore();const handleClick=()=>{// Extract the lesson number from props.name\nconst lessonNumber=props.name.match(/\\d+/)[0];// Update the lesson status to 'Finished'\nupdateLessonStatus(lessonNumber,finishedVariantName,store,setStore);};return /*#__PURE__*/ _jsx(\"div\",{onClick:handleClick,\"data-outseta-button\":\"finish\",children:/*#__PURE__*/ _jsx(Component,{...props})});};}// This function is an override that adds an onClick handler to a component\n// The handler sets the status of a lesson in Outseta and the store to 'Not Started'\nexport function withLessonResetButton(Component){return props=>{const[store,setStore]=useOutsetaStore();const handleClick=()=>{// Extract the lesson number from props.name\nconst lessonNumber=props.name.match(/\\d+/)[0];// Update the lesson status to 'Not Started'\nupdateLessonStatus(lessonNumber,notStartedVariantName,store,setStore);};return /*#__PURE__*/ _jsx(\"div\",{onClick:handleClick,\"data-outseta-button\":\"reset\",children:/*#__PURE__*/ _jsx(Component,{...props})});};}// This function is an override that fetches user data from Outseta when a component is first rendered\n// If the user's account is not initialized, it initializes the status of each lesson to 'Not started'\nexport function withOutsetaData(Component){return props=>{const[store,setStore]=useOutsetaStore();// Check if window object exists (i.e., code is running in the browser)\nif(typeof window!==\"undefined\"){let Outseta=window[\"Outseta\"];// If Outseta is not defined, just return the component without the data\nif(!Outseta){console.warn(\"Outseta is not defined. Returning the component without data.\");return /*#__PURE__*/ _jsx(Component,{...props});}if(!store.userData){Outseta.getUser().then(userData=>{// Update the store with the fetched user data\nsetStore({userData});console.log(\"User data fetched!\");return userData;}).then(userData=>{if(!userData.Account.AccountInit){console.log(\"Account not initialized, starting initialization\u2026\");Outseta.getUser().then(function(user){// Initialize lessons\nfor(let i=1;i<=numberOfLessons;i++){userData.Account[`Lesson${i}Status`]=notStartedVariantName;}userData.Account.AccountInit=true;userData.update(userData);return userData;}).then(userData=>{setStore({userData});console.log(\"Account initialization finished\");}).catch(error=>{// Handle any errors that occurred while fetching user data\nconsole.error(\"An error occurred while initializing user data:\",error);});}else{console.log(\"Account already initialized\");// For testing purposes\n/* Outseta.getUser().then(function (user) {\n                                user.Account.AccountInit = false\n                                user.update(user)\n                            }) */ }}).catch(error=>{// Handle any errors that occurred while fetching user data\nconsole.error(\"An error occurred while fetching user data:\",error);});}}return /*#__PURE__*/ _jsx(Component,{...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withOutsetaData\":{\"type\":\"reactHoc\",\"name\":\"withOutsetaData\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLessonFinishedButton\":{\"type\":\"reactHoc\",\"name\":\"withLessonFinishedButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLessonStatus\":{\"type\":\"reactHoc\",\"name\":\"withLessonStatus\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLessonResetButton\":{\"type\":\"reactHoc\",\"name\":\"withLessonResetButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Outseta.map"],
  "mappings": "2HACA,IAAMA,EAAgBC,EAAY,CAAC,SAAS,IAAI,CAAC,EAC3CC,EAAgB,GAChBC,EAAmB,UAAgBC,EAAsB,cACxD,SAASC,EAAiBC,EAAU,CAAC,OAAOC,GAAO,CAAC,GAAK,CAACC,EAAMC,CAAQ,EAAEC,EAAgB,EAAMC,EAAQC,EACzGC,EAAaN,EAAM,KAAK,MAAM,KAAK,EAAE,CAAC,EAAE,OAAGC,EAAM,WAAUG,EAAQH,EAAM,SAAS,QAAQ,SAASK,CAAY,QAAQ,GAAwBC,EAAKR,EAAU,CAAC,GAAGC,EAAM,QAAQI,EAAQ,sBAAsB,QAAQ,CAAC,CAAE,CAAE,CAgB1N,SAASI,EAAgBC,EAAU,CAAC,OAAOC,GAAO,CAAC,GAAK,CAACC,EAAMC,CAAQ,EAAEC,EAAgB,EAChG,GAAG,OAAOC,EAAS,IAAY,CAAC,IAAIC,EAAQD,EAAO,QACnD,GAAG,CAACC,EAAS,eAAQ,KAAK,+DAA+D,EAAuBC,EAAKP,EAAU,CAAC,GAAGC,CAAK,CAAC,EAAOC,EAAM,UAAUI,EAAQ,QAAQ,EAAE,KAAKE,IACvLL,EAAS,CAAC,SAAAK,CAAQ,CAAC,EAAE,QAAQ,IAAI,oBAAoB,EAASA,EAAU,EAAE,KAAKA,GAAU,CAAKA,EAAS,QAAQ,YAE/B,QAAQ,IAAI,6BAA6B,GAFG,QAAQ,IAAI,wDAAmD,EAAEF,EAAQ,QAAQ,EAAE,KAAK,SAASG,EAAK,CAClO,QAAQC,EAAE,EAAEA,GAAGC,EAAgBD,IAAKF,EAAS,QAAQ,SAASE,CAAC,QAAQ,EAAEE,EAAuB,OAAAJ,EAAS,QAAQ,YAAY,GAAKA,EAAS,OAAOA,CAAQ,EAASA,CAAS,CAAC,EAAE,KAAKA,GAAU,CAACL,EAAS,CAAC,SAAAK,CAAQ,CAAC,EAAE,QAAQ,IAAI,iCAAiC,CAAE,CAAC,EAAE,MAAMK,GAAO,CACnR,QAAQ,MAAM,kDAAkDA,CAAK,CAAE,CAAC,EAIrC,CAAC,EAAE,MAAMA,GAAO,CACnD,QAAQ,MAAM,8CAA8CA,CAAK,CAAE,CAAC,CAAG,CAAC,OAAqBN,EAAKP,EAAU,CAAC,GAAGC,CAAK,CAAC,CAAE,CAAE",
  "names": ["useOutsetaStore", "createStore", "numberOfLessons", "loadingVariantName", "notStartedVariantName", "withLessonStatus", "Component", "props", "store", "setStore", "useOutsetaStore", "variant", "loadingVariantName", "lessonNumber", "p", "withOutsetaData", "Component", "props", "store", "setStore", "useOutsetaStore", "window", "Outseta", "p", "userData", "user", "i", "numberOfLessons", "notStartedVariantName", "error"]
}
