{"version":3,"file":"Outseta.D1FbZG_d.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/kvaCzo5L3KAHjO8A38A2/pEtPb5XQiMgJdLxJQio4/Outseta.js"],"sourcesContent":["import{useState,useEffect}from\"react\";import{Data,useObserveData}from\"framer\";export function createStore(state1){// Use Data so that a Preview reload resets the state\nconst dataStore=Data({state:Object.freeze({...state1})});// Create a set function that updates the state\nconst setDataStore=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(dataStore.state);}dataStore.state=Object.freeze({...dataStore.state,...newState});};// Store the initial state, copy the object if it's an object\nlet storeState=typeof state1===\"object\"?Object.freeze({...state1}):state1;// Keep a list of all the listeners, in the form of React hook setters\nconst storeSetters=new Set();// Create a set function that updates all the listeners / setters\nconst setStoreState=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(storeState);}storeState=typeof newState===\"object\"?Object.freeze({...storeState,...newState}):newState;// Update all the listeners / setters with the new value\nstoreSetters.forEach(setter=>setter(storeState));};// Create the actual hook based on everything above\nfunction useStore(){// Create the hook we are going to use as a listener\nconst[state,setState]=useState(storeState);// If we unmount the component using this hook, we need to remove the listener\n// @ts-ignore\nuseEffect(()=>{// But right now, we need to add the listener\nstoreSetters.add(setState);return()=>storeSetters.delete(setState);},[]);// If Data context exists, use Data, otherwise use vanilla React state\nif(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{// Return the state and a function to update the central store\nreturn[state,setStoreState];}}return useStore;}\nexport const __FramerMetadata__ = {\"exports\":{\"createStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./createStore.map","/*\n * createStore (framer/store@1.0.1)\n *\n * Learn More: https://www.framer.com/asset-urls\n */\n\nexport * from \"https://framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js\"\n","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":"sSAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM,EAAU,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,CAAC,CAAC,CAClD,EAAa,GAAU,CAC1B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAU,MAAM,EAAE,EAAU,MAAM,OAAO,OAAO,CAAC,GAAG,EAAU,MAAM,GAAG,EAAS,CAAC,EAChI,EAAW,OAAO,GAAS,SAAS,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,CAAC,EAC7D,EAAa,IAAI,IACjB,EAAc,GAAU,CAC3B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAW,EAAE,EAAW,OAAO,GAAW,SAAS,OAAO,OAAO,CAAC,GAAG,EAAW,GAAG,EAAS,CAAC,CAAC,EACjJ,EAAa,QAAQ,GAAQ,EAAO,EAAW,CAAC,EAChD,SAAS,GAAU,CACnB,GAAK,CAAC,EAAM,GAAUA,EAAS,EAAW,CAK1C,OAHA,OACA,EAAa,IAAI,EAAS,KAAW,EAAa,OAAO,EAAS,EAAG,EAAE,CAAC,CACrE,GAAgB,GAAG,IAAM,GAAgB,CAAO,CAAC,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