{"version":3,"file":"FramerAuth.BmU3be2g.mjs","names":[],"sources":["https:/framerusercontent.com/modules/i94QUZXSTktuJHPDI4Gn/0lRKJSlJ2QqpLY1N9dJT/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\":{\"withLoggedOut\":{\"type\":\"reactHoc\",\"name\":\"withLoggedOut\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withActionCompleteLesson\":{\"type\":\"reactHoc\",\"name\":\"withActionCompleteLesson\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSignOut\":{\"type\":\"reactHoc\",\"name\":\"withSignOut\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withActiveLicense\":{\"type\":\"reactHoc\",\"name\":\"withActiveLicense\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withNoActiveLicense\":{\"type\":\"reactHoc\",\"name\":\"withNoActiveLicense\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withVariant\":{\"type\":\"reactHoc\",\"name\":\"withVariant\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAuth\":{\"type\":\"reactHoc\",\"name\":\"withAuth\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLoggedIn\":{\"type\":\"reactHoc\",\"name\":\"withLoggedIn\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withEmail\":{\"type\":\"reactHoc\",\"name\":\"withEmail\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withIsLessonComplete\":{\"type\":\"reactHoc\",\"name\":\"withIsLessonComplete\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withStore\":{\"type\":\"reactHoc\",\"name\":\"withStore\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withVariantActiveLicense\":{\"type\":\"reactHoc\",\"name\":\"withVariantActiveLicense\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withFirstName\":{\"type\":\"reactHoc\",\"name\":\"withFirstName\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FramerAuth.map"],"mappings":"sXAA8V,SAAgB,EAAS,EAAU,CAAC,MAAO,CAAA,GAAO,CAAC,GAAK,CAAC,EAAM,EAAS,CAAC,GAAU,CAA2N,MAA1N,GAAU,IAAI,CAAC,AAAI,EAAM,iBAAiB,EAAK,QAAQ,CAAC,OAAM,CAAM,EAAC,CAAC,KAAK,CAAC,CAAC,OAAK,QAAM,GAAG,CAAC,GAAK,CAAC,OAAK,CAAC,EAAK,AAAS,EAAN,EAAe,CAAM,OAAK,iBAAgB,EAAK,UAAS,CAAK,EAAiB,CAAC,UAAS,CAAK,EAAC,AAAG,EAAC,AAAG,EAAC,CAAE,EAAC,CAAqB,EAAK,EAAU,CAAC,GAAG,EAAY,OAAM,EAAC,AAAE,CAAE,CAAk+C,SAAgB,EAAoB,EAAU,CAAC,MAAO,CAAA,GAAO,CAAC,IAAI,EAAY,GAAK,CAAC,EAAM,CAAC,GAAU,CAAO,EAA8E,CAA5D,EAAY,EAAM,OAAsD,SAAS,KAAK,GAAS,EAAQ,SAAS,SAAS,CAAiC,OAA7B,EAAwB,KAAyB,EAAK,EAAU,CAAC,GAAG,CAAM,EAAC,AAAE,CAAE,gBAA/tE,AAAvR,GAA2C,IAA6B,IAAqE,IAAwD,IAA4E,CAAM,EAAS,EAAY,CAAC,KAAK,KAAK,iBAAgB,EAAM,UAAS,CAAM,EAAC"}