{"version":3,"file":"Outseta_course.B6XcFixc.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/40nt0A4o1KL1FtCBuwDS/AwMi9ZuMyfV0IoqKnGWz/Outseta_course.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\";// Store for Outseta user data\nconst useOutsetaStore=createStore({userData:null});// Course config\nconst numberOfLessons=41;// Status variant names (must match your Framer component variants exactly)\nconst loadingVariantName=\"Loading\";const notStartedVariantName=\"Not started\";const inProgressVariantName=\"In progress\";const finishedVariantName=\"Finished\";// Helper: safely get the lesson number from props\nfunction getLessonNumber(props){if(typeof props.lessonNumber===\"number\"&&props.lessonNumber>0){return props.lessonNumber;}console.warn(\"Lesson button is missing a lessonNumber prop. \"+\"Bind the CMS 'lessonNumber' field to this component.\");return null;}// Helper: figure out which lesson \"Continue\" should point to.\n// Returns null when there's nothing to resume:\n//   - User data not yet loaded\n//   - No lessons finished yet (hide Continue entirely)\n//   - Course is fully complete\nfunction getResumeLessonNumber(userData){if(!userData||!userData.Account)return null;const lastFinished=userData.Account.LastLessonFinished;if(typeof lastFinished!==\"number\"||lastFinished<1)return null;if(lastFinished>=numberOfLessons)return null;return lastFinished+1;}// ─────────────────────────────────────────────────────────────\n// STATUS BUTTON — shows Not started / In progress / Finished\n// ─────────────────────────────────────────────────────────────\nexport function withLessonStatus(Component){return props=>{const[store]=useOutsetaStore();let variant=loadingVariantName;const lessonNumber=getLessonNumber(props);if(store.userData&&lessonNumber!==null){variant=store.userData.Account[`Lesson${lessonNumber}Status`]||notStartedVariantName;}return /*#__PURE__*/_jsx(Component,{...props,variant:variant,\"data-outseta-button\":\"status\"});};}// ─────────────────────────────────────────────────────────────\n// Shared function to update lesson status in Outseta + store\n// ─────────────────────────────────────────────────────────────\nfunction updateLessonStatus(lessonNumber,newStatus,store,setStore){if(typeof window===\"undefined\")return;if(!store.userData){console.warn(\"User data not loaded yet — cannot update status.\");return;}const currentStatus=store.userData.Account[`Lesson${lessonNumber}Status`];if(currentStatus===newStatus){console.log(`Status of Lesson #${lessonNumber} is already ${newStatus}`);return;}const Outseta=window[\"Outseta\"];if(!Outseta){console.warn(\"Outseta is not defined.\");return;}Outseta.getUser().then(userData=>{userData.Account[`Lesson${lessonNumber}Status`]=newStatus;if(newStatus===finishedVariantName){userData.Account.LastLessonFinished=lessonNumber;}userData.update(userData);const updatedAccount={...store.userData.Account,[`Lesson${lessonNumber}Status`]:newStatus};if(newStatus===finishedVariantName){updatedAccount.LastLessonFinished=lessonNumber;}setStore({userData:{...store.userData,Account:updatedAccount}});console.log(`Status of Lesson #${lessonNumber} set to ${newStatus}`);}).catch(error=>{console.error(\"An error occurred while updating lesson status:\",error);});}// ─────────────────────────────────────────────────────────────\n// MARK AS FINISHED button\n// ─────────────────────────────────────────────────────────────\nexport function withLessonFinishedButton(Component){return props=>{const[store,setStore]=useOutsetaStore();const handleClick=()=>{const lessonNumber=getLessonNumber(props);if(lessonNumber===null)return;updateLessonStatus(lessonNumber,finishedVariantName,store,setStore);};return /*#__PURE__*/_jsx(\"div\",{onClick:handleClick,\"data-outseta-button\":\"finish\",children:/*#__PURE__*/_jsx(Component,{...props})});};}// ─────────────────────────────────────────────────────────────\n// MARK AS IN PROGRESS — attach to the lesson page so that\n// landing on a lesson moves it out of \"Not started\"\n// ─────────────────────────────────────────────────────────────\nexport function withLessonInProgress(Component){return props=>{const[store,setStore]=useOutsetaStore();if(typeof window!==\"undefined\"&&store.userData&&typeof props.lessonNumber===\"number\"){const currentStatus=store.userData.Account[`Lesson${props.lessonNumber}Status`];if(currentStatus===notStartedVariantName){updateLessonStatus(props.lessonNumber,inProgressVariantName,store,setStore);}}return /*#__PURE__*/_jsx(Component,{...props});};}// ─────────────────────────────────────────────────────────────\n// RESET button\n// ─────────────────────────────────────────────────────────────\nexport function withLessonResetButton(Component){return props=>{const[store,setStore]=useOutsetaStore();const handleClick=()=>{const lessonNumber=getLessonNumber(props);if(lessonNumber===null)return;updateLessonStatus(lessonNumber,notStartedVariantName,store,setStore);};return /*#__PURE__*/_jsx(\"div\",{onClick:handleClick,\"data-outseta-button\":\"reset\",children:/*#__PURE__*/_jsx(Component,{...props})});};}// ─────────────────────────────────────────────────────────────\n// CONTINUE SECTION — Hides the ENTIRE section (header, subtitle,\n// CMS list, everything) when there's no lesson to resume.\n// Attach this to the outermost Continue section frame.\n// ─────────────────────────────────────────────────────────────\nexport function withContinueSection(Component){return props=>{const[store]=useOutsetaStore();// Hide while user data loads, to prevent a flicker of the\n// section before we know whether there's anything to resume\nif(!store.userData){return /*#__PURE__*/_jsx(\"div\",{style:{display:\"none\"}});}const resumeLesson=getResumeLessonNumber(store.userData);// No lesson to resume → hide the whole section\nif(resumeLesson===null){return /*#__PURE__*/_jsx(\"div\",{style:{display:\"none\"}});}return /*#__PURE__*/_jsx(Component,{...props});};}// ─────────────────────────────────────────────────────────────\n// CONTINUE CARD — Hides all CMS list cards except the one whose\n// lessonNumber matches the resume lesson. Attach this to the\n// card component inside the CMS collection list.\n// ─────────────────────────────────────────────────────────────\nexport function withContinueCard(Component){return props=>{const[store]=useOutsetaStore();if(!store.userData){return /*#__PURE__*/_jsx(\"div\",{style:{display:\"none\"}});}const resumeLesson=getResumeLessonNumber(store.userData);if(resumeLesson===null||props.lessonNumber!==resumeLesson){return /*#__PURE__*/_jsx(\"div\",{style:{display:\"none\"}});}return /*#__PURE__*/_jsx(Component,{...props});};}// ─────────────────────────────────────────────────────────────\n// FETCH + INITIALISE USER DATA\n// ─────────────────────────────────────────────────────────────\nlet fetchStarted=false;let fetchPromise=null;function fetchAndInitUserData(setStore){if(fetchStarted)return fetchPromise;fetchStarted=true;const waitForOutseta=(attempt=0)=>{const Outseta=window[\"Outseta\"];if(Outseta)return Promise.resolve(Outseta);if(attempt>50){return Promise.reject(new Error(\"Outseta did not load within 5 seconds\"));}return new Promise(resolve=>setTimeout(()=>resolve(waitForOutseta(attempt+1)),100));};fetchPromise=waitForOutseta().then(Outseta=>Outseta.getUser()).then(userData=>{setStore({userData});console.log(\"User data fetched!\");return userData;}).then(userData=>{if(!userData.Account.AccountInit){console.log(\"Initialising account…\");for(let i=1;i<=numberOfLessons;i++){userData.Account[`Lesson${i}Status`]=notStartedVariantName;}userData.Account.AccountInit=true;userData.Account.LastLessonFinished=null;userData.update(userData);setStore({userData});console.log(\"Account initialised\");}else{console.log(\"Account already initialised\");}}).catch(error=>{const isTimeout=error&&error.message&&error.message.includes(\"did not load\");if(isTimeout){console.warn(\"Outseta load timed out — likely a Framer preview quirk. \"+\"This will not occur on the published site.\");}else{console.error(\"Error fetching user data:\",error);}if(!isTimeout){fetchStarted=false;fetchPromise=null;}});return fetchPromise;}export function withOutsetaData(Component){return props=>{const[store,setStore]=useOutsetaStore();if(typeof window!==\"undefined\"&&!store.userData){fetchAndInitUserData(setStore);}return /*#__PURE__*/_jsx(Component,{...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withLessonInProgress\":{\"type\":\"reactHoc\",\"name\":\"withLessonInProgress\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLessonStatus\":{\"type\":\"reactHoc\",\"name\":\"withLessonStatus\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withContinueSection\":{\"type\":\"reactHoc\",\"name\":\"withContinueSection\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLessonResetButton\":{\"type\":\"reactHoc\",\"name\":\"withLessonResetButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withOutsetaData\":{\"type\":\"reactHoc\",\"name\":\"withOutsetaData\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withContinueCard\":{\"type\":\"reactHoc\",\"name\":\"withContinueCard\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLessonFinishedButton\":{\"type\":\"reactHoc\",\"name\":\"withLessonFinishedButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Outseta_course.map"],"mappings":"2LAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM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