{"version":3,"file":"Outseta.L943FfLm.mjs","names":[],"sources":["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…\");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":"qPAIA,SAAgB,EAAiB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,EAAS,CAAC,IAAsB,EAAQ,EACzG,EAAa,EAAM,KAAK,MAAM,OAAO,GAAqF,OAA/E,EAAM,WAAU,EAAQ,EAAM,SAAS,QAAQ,SAAS,EAAa,UAA+B,EAAK,EAAU,CAAC,GAAG,EAAc,UAAQ,sBAAsB,SAAS,CAAG,CAAE,CAgBlO,SAAgB,EAAgB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,EAAS,CAAC,IAChF,GAAU,IAAS,OAAY,CAAC,IAAI,EAAQ,EAAO,QACnD,GAAG,CAAC,EAAuF,OAA9E,QAAQ,KAAK,iEAAsF,EAAK,EAAU,CAAC,GAAG,EAAM,EAAO,EAAM,UAAU,EAAQ,UAAU,KAAK,IACvL,EAAS,CAAC,WAAS,EAAE,QAAQ,IAAI,sBAA6B,IAAY,KAAK,GAAU,CAAK,EAAS,QAAQ,YAE/B,QAAQ,IAAI,gCAFgC,QAAQ,IAAI,qDAAqD,EAAQ,UAAU,K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