{"version":3,"file":"FramerAuth.B0HAREJs.mjs","names":[],"sources":["https:/framerusercontent.com/modules/DZEVwThWtWaAFXkDqxtZ/BWKKjMXO7qXHtPPkWQhn/FramerAuth.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";import{useRouter,inferInitialRouteFromPath}from\"framer\";import{auth}from\"https://cdn.framerauth.com/scripts/framerauth-sdk@beta.js\";const useStore=createStore({user:null,isAuthenticated:false,isLoaded:false});export function withAuth(Component){return props=>{const[store,setStore]=useStore();useEffect(()=>{if(!store.isAuthenticated){auth.getUser({cache:false}).then(({data,error})=>{const{user}=data;if(user){setStore({user:user,isAuthenticated:true,isLoaded:true});}else{setStore({isLoaded:true});}});}},[]);return /*#__PURE__*/_jsx(Component,{...props,store:store});};}export function withStore(Component){return props=>{const[store,setStore]=useStore();return /*#__PURE__*/_jsx(Component,{...props,store:store});};}export function withSignOut(Component){const handleClick=()=>{auth.signOut(\"/\");};return props=>{const[store,setStore]=useStore();if(!store.user)return null;return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};}export function withEmail(Component){return props=>{const[store,setStore]=useStore();if(!store.user)return null;return /*#__PURE__*/_jsx(Component,{...props,text:store.user.email});};}export function withFirstName(Component){return props=>{const[store,setStore]=useStore();if(!store.user)return null;return /*#__PURE__*/_jsx(Component,{...props,text:store.user.first_name});};}export function withLoggedIn(Component){return props=>{const[store,setStore]=useStore();if(!store.user)return null;return /*#__PURE__*/_jsx(Component,{...props});};}export function withLoggedOut(Component){return props=>{const[store]=useStore();if(store.user)return null;let className=props.className||\"\";if(!store.isLoaded){className+=\" fa-cloak\";}return /*#__PURE__*/_jsx(Component,{...props,className:className.trim()});};}export function withActiveLicense(Component){return props=>{var _store_user;const[store]=useStore();const hasActiveLicense=(_store_user=store.user)===null||_store_user===void 0?void 0:_store_user.licenses.some(license=>license.status===\"active\");if(!hasActiveLicense)return null;return /*#__PURE__*/_jsx(Component,{...props});};}export function withNoActiveLicense(Component){return props=>{var _store_user;const[store]=useStore();const hasActiveLicense=(_store_user=store.user)===null||_store_user===void 0?void 0:_store_user.licenses.some(license=>license.status===\"active\");if(hasActiveLicense)return null;return /*#__PURE__*/_jsx(Component,{...props});};}export function withVariant(Component){return props=>{const[store]=useStore();const variant=store.user?null:props===null||props===void 0?void 0:props.variant;return /*#__PURE__*/_jsx(Component,{...props,variant:variant});};}export function withVariantActiveLicense(Component){return props=>{var _store_user;const[store]=useStore();const hasActiveLicense=(_store_user=store.user)===null||_store_user===void 0?void 0:_store_user.licenses.some(license=>license.status===\"active\");const variant=hasActiveLicense?null:props===null||props===void 0?void 0:props.variant;return /*#__PURE__*/_jsx(Component,{...props,variant:variant});};}export function withIsLessonComplete(Component){return props=>{var _store_user_data,_store_user;const[store,setStore]=useStore();// Do not display the component if the user is logged out\nif(!store.user)return null;const key=`course:status:${props===null||props===void 0?void 0:props.slug}`;const isCompleted=((_store_user=store.user)===null||_store_user===void 0?void 0:(_store_user_data=_store_user.data)===null||_store_user_data===void 0?void 0:_store_user_data[key])===\"completed\";if(!isCompleted)return null;return /*#__PURE__*/_jsx(Component,{...props});};}export function withActionCompleteLesson(Component){return props=>{var _store_user_data,_store_user;const router=useRouter();const[store,setStore]=useStore();const key=`course:status:${props===null||props===void 0?void 0:props.slug}`;let isCompleted=((_store_user=store.user)===null||_store_user===void 0?void 0:(_store_user_data=_store_user.data)===null||_store_user_data===void 0?void 0:_store_user_data[key])===\"completed\";// Do not display the component if the user is logged out\nif(!store.user)return null;// Define an async function handleClick to handle the click event.\nconst handleClick=async event=>{try{// If the lesson has been completed exit the function\nif(isCompleted)return;// Update the components local state (for instant UI update)\nisCompleted=true;// Call the FramerAuth API to update the user data, marking the course as completed.\nconst{data,error}=await auth.patchUserData({[key]:\"completed\"});// If there is an error throw it.\nif(error){throw new Error(\"Error updating course status.\");}// If there is no error, update the user data in the store with the updated data.\nconst updatedUser={...store.user,data};setStore({user:updatedUser});// If there is a link, redirect the user.\nif(props===null||props===void 0?void 0:props.link){const[path,hash]=props.link.split(\"#\");const{routeId,pathVariables}=inferInitialRouteFromPath(router.routes,path);if(routeId){router.navigate(routeId,hash,pathVariables);}}}catch(error){console.error(error);isCompleted=false;}};// Set the variant based on the completed state\nconst variant=isCompleted?props===null||props===void 0?void 0:props.variant:null;// Render the original component with the modified props and onClick handler.\nreturn /*#__PURE__*/_jsx(Component,{...props,variant:variant,onClick:handleClick});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withNoActiveLicense\":{\"type\":\"reactHoc\",\"name\":\"withNoActiveLicense\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withVariant\":{\"type\":\"reactHoc\",\"name\":\"withVariant\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSignOut\":{\"type\":\"reactHoc\",\"name\":\"withSignOut\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLoggedOut\":{\"type\":\"reactHoc\",\"name\":\"withLoggedOut\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withEmail\":{\"type\":\"reactHoc\",\"name\":\"withEmail\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withIsLessonComplete\":{\"type\":\"reactHoc\",\"name\":\"withIsLessonComplete\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withActionCompleteLesson\":{\"type\":\"reactHoc\",\"name\":\"withActionCompleteLesson\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withActiveLicense\":{\"type\":\"reactHoc\",\"name\":\"withActiveLicense\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAuth\":{\"type\":\"reactHoc\",\"name\":\"withAuth\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLoggedIn\":{\"type\":\"reactHoc\",\"name\":\"withLoggedIn\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withFirstName\":{\"type\":\"reactHoc\",\"name\":\"withFirstName\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withVariantActiveLicense\":{\"type\":\"reactHoc\",\"name\":\"withVariantActiveLicense\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withStore\":{\"type\":\"reactHoc\",\"name\":\"withStore\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FramerAuth.map"],"mappings":"kRAA8V,SAAgB,EAAS,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,GAAU,EAAS,EAA4N,OAA1N,MAAc,CAAK,EAAM,iBAAiB,EAAK,QAAQ,CAAC,MAAM,EAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAK,WAAS,CAAC,GAAK,CAAC,QAAM,EAAc,EAAN,EAAe,CAAM,OAAK,gBAAgB,GAAK,SAAS,EAAI,EAAkB,CAAC,SAAS,EAAI,CAAC,CAAG,CAAC,CAAG,EAAE,CAAC,CAAC,EAAsB,EAAK,EAAU,CAAC,GAAG,EAAY,OAAK,CAAC,CAAE,CAAE,CAAuX,SAAgB,EAAU,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,GAAU,EAAS,EAA6B,OAAvB,EAAM,KAAqC,EAAK,EAAU,CAAC,GAAG,EAAM,KAAK,EAAM,KAAK,KAAK,CAAC,EAAxE,IAA0E,CAAE,CAAC,SAAgB,EAAc,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,GAAU,EAAS,EAA6B,OAAvB,EAAM,KAAqC,EAAK,EAAU,CAAC,GAAG,EAAM,KAAK,EAAM,KAAK,UAAU,CAAC,EAA7E,IAA+E,CAAE,CAAovB,SAAgB,EAAoB,EAAU,CAAC,MAAO,IAAO,CAAiB,GAAK,CAAC,GAAO,EAAS,EAAoL,OAA9I,EAAM,MAAsD,SAAS,KAAK,GAAS,EAAQ,SAAS,QAAQ,EAA6B,KAAyB,EAAK,EAAU,CAAC,GAAG,CAAK,CAAC,CAAE,CAAE,CAAsnB,SAAgB,EAAqB,EAAU,CAAC,MAAO,IAAO,CAAkC,GAAK,CAAC,EAAM,GAAU,EAAS,EAC1uG,GAAG,CAAC,EAAM,KAAK,OAAO,KAAK,IAAM,EAAI,iBAAiB,GAA0C,OAAqO,OAA9L,EAAM,MAAwE,OAAgE,KAAQ,YAA4D,EAAK,EAAU,CAAC,GAAG,CAAK,CAAC,EAAlD,IAAoD,CAAE,mBAD5U,IAA6B,IAAqE,IAAwD,IAA4E,EAAO,EAAS,EAAY,CAAC,KAAK,KAAK,gBAAgB,GAAM,SAAS,EAAK,CAAC"}