{"version":3,"file":"Outseta.B8Gfa2aG.mjs","names":[],"sources":["https:/framerusercontent.com/modules/kvaCzo5L3KAHjO8A38A2/pEtPb5XQiMgJdLxJQio4/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":"0KAIA,SAAgB,EAAiB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,GAAU,GAAiB,CAAK,EAAQ,EACzG,EAAa,EAAM,KAAK,MAAM,MAAM,CAAC,GAAqF,OAA/E,EAAM,WAAU,EAAQ,EAAM,SAAS,QAAQ,SAAS,EAAa,UAA+B,EAAK,EAAU,CAAC,GAAG,EAAc,UAAQ,sBAAsB,SAAS,CAAC,EAC9N,SAAS,EAAmB,EAAa,EAAU,EAAM,EAAS,CACxD,IAAS,SAChB,EAAM,SAAS,QAAQ,SAAS,EAAa,UAAU,EAGsB,QAAQ,IAAI,qBAAqB,EAAa,qBAAqB,IAAY,CAH9E,EAAO,QAAmB,SAAS,CAAC,KAAK,GAAU,CACpI,EAAS,QAAQ,SAAS,EAAa,SAAS,EAAU,EAAS,OAAO,EAAS,CACnF,EAAS,CAAC,SAAS,CAAC,GAAG,EAAM,SAAS,QAAQ,CAAC,GAAG,EAAM,SAAS,SAAS,SAAS,EAAa,SAAS,EAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,qBA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