{"version":3,"file":"OutsettaOverride.Cy8-9kAk.mjs","names":[],"sources":["https:/framerusercontent.com/modules/9o3mfikk34mnHV5KGo3F/rwM3508StLt2dIxZa0cH/OutsettaOverride.js"],"sourcesContent":["/// VERSION 0.0.1\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState}from\"react\";/////////////////// Button Overrides\nexport function withRegisterPopup(Component){return props=>{return /*#__PURE__*/_jsx(Component,{...props,\"data-o-anonymous\":\"1\",\"data-o-auth\":\"1\",\"data-mode\":\"popup\",\"data-widget-mode\":\"register\"});};}export function asLoginPopupButton(Component){return props=>{return /*#__PURE__*/_jsx(Component,{...props,\"data-o-anonymous\":\"1\",\"data-o-auth\":\"1\",\"data-mode\":\"popup\",\"data-widget-mode\":\"login\"});};}export function asProfilePopupButton(Component){return props=>{return /*#__PURE__*/_jsx(Component,{...props,\"data-o-authenticated\":\"1\",\"data-o-profile\":\"1\",\"data-mode\":\"popup\"});};}export function asLogoutButton(Component){return props=>{return /*#__PURE__*/_jsx(Component,{...props,\"data-o-authenticated\":\"1\",\"data-o-logout-link\":\"1\"});};}/////////////////// Visibility Overrides\nexport function showForAuthenticated(Component){return props=>{return /*#__PURE__*/_jsx(Component,{...props,\"data-o-authenticated\":\"1\"});};}export function showForAnonymous(Component){return props=>{return /*#__PURE__*/_jsx(Component,{...props,\"data-o-anonymous\":\"1\"});};}/////////// Visibility Overrides Based on Plan Uid\n/////// Instruction\n// 1. Find the plan uid on the plan page in Outseta\n// 2. Replace aWxYEbmV in function name with the plan uid\n// 3. Replace the aWxYEbmV value of validPlanUid with the plan uid\n// Duplicate function for additional plan uids\nexport function showForSinglePlan_aWxYEbmV(Component){const validPlanUid=\"aWxYEbmV\";return props=>{try{const user=useUser();const value=user&&user[\"Account.CurrentSubscription.Plan.Uid\"];if(value===validPlanUid){return /*#__PURE__*/_jsx(Component,{...props});}return null;}catch(error){log(\"error in showForSinglePlan\",validPlanUid,error.message);return null;}};}/////////// Visibility Based on an Account Custom Property\n/////// Instruction\n// 1. Give the function as useful name\n// 2. Replace the \"PARTY\" value of validPropertyValue with the uppercase version of the value you want\n// 3. Replace MyCustomAccountProperty with the system name of your custom account property\n// Duplicate the functions for additional account properties and/or values\nexport function showForPartyAccounts(Component){const validPropertyValue=\"PARTY\";return props=>{try{const user=useUser();const value=user&&user[\"Account.MyCustomAccountProperty\"]?.toUpperCase();if(value===validPropertyValue){return /*#__PURE__*/_jsx(Component,{...props});}return null;}catch(error){log(\"error in showForPartyPlan\",validPropertyValue,error.message);return null;}};}/////////// Visibility Based on an Person Custom Property\n/////// Instruction\n// 1. Give the function a useful name\n// 2. Replace the \"PARTY\" value of validPropertyValue with the uppercase version of the value you want\n// 3. Replace MyCustomPersonProperty with the system name of your custom person property\n// Duplicate the functions for additional account properties and/or values\nexport function showForPartyPeople(Component){const validPropertyValue=\"PARTY\";return props=>{try{const user=useUser();const value=user&&user[\"MyCustomPersonProperty\"]?.toUpperCase();if(value===validPropertyValue){return /*#__PURE__*/_jsx(Component,{...props});}return null;}catch(error){log(\"error in showForPartyPeople\",validPropertyValue,error.message);return null;}};}/////////////////// Text Overrides\nexport function withUserFirstName(Component){return withProperty(\"FirstName\",Component);}export function withUserLastName(Component){return withProperty(\"LastName\",Component);}export function withUserFullName(Component){return withProperty(\"FullName\",Component);}export function withUserEmail(Component){return withProperty(\"Email\",Component);}export function withAccountName(Component){return withProperty(\"Account.Name\",Component);}export function withAccountSubscriptionUid(Component){return withProperty(\"Account.CurrentSubscription.Plan.Uid\",Component);}export function withAccountSubscriptionName(Component){return withProperty(\"Account.CurrentSubscription.Plan.Name\",Component);}export function withAccountSubscriptionDescription(Component){return withProperty(\"Account.CurrentSubscription.Plan.Description\",Component);}/////////////////// Image Overrides\nexport function withUserAvatar(Component){return withImageProperty(\"ProfileImageS3Url\",Component);}let user=null;const listeners=new Set;const fetchUser=async event=>{try{log(\"fetch user\",event);const userObject=await getOutseta().getUser();user=flattenObject(userObject);log(\"fetch user fulfilled\",event,userObject,user);notifyListeners();}catch(error){log(\"fetch user failed\",error);}};const clearUser=event=>{user=null;// Possible race condition that an earlier\nlog(\"cleared user\",event);notifyListeners();};const notifyListeners=()=>{listeners.forEach(listener=>listener(user));};export const subscribe=listener=>{listeners.add(listener);return()=>listeners.delete(listener);};export const getUser=()=>user;// Listen to global events that might change the user\nconst outsetaFetchUserEvents=[\"accessToken.set\",\"profile.update\",\"account.update\"];outsetaFetchUserEvents.forEach(event=>{getOutseta()?.on(event,()=>fetchUser(event));});// Listen to global events that should clear the user\nconst outsetaClearUserEvents=[\"logout\"];outsetaClearUserEvents.forEach(event=>{getOutseta()?.on(event,()=>clearUser(event));});/////////////////// User Hook\nfunction useUser(){const[user,setUser]=useState(getUser());useEffect(()=>{const updateData=newData=>setUser(newData);const unsubscribe=subscribe(updateData);return()=>{unsubscribe();};},[]);return user;}export function getOutseta(){if(window&&window[\"Outseta\"]){return window[\"Outseta\"];}else if(window){console.log(\"Outseta is missing, have you added the Outseta Script and Options to the head of the site?\");alert(`We're sorry, but it seems that Outseta is missing. Please reach out to the owner of ${window.location.hostname} to let them know. Thank you for your understanding 🙏`);}else{// Rendering on the server\n}}/////////////////// Helpers\nfunction withProperty(property,Component){return props=>{const user=useUser();if(!user)return null;return /*#__PURE__*/_jsx(Component,{...props,text:user[property]});};}function withImageProperty(property,Component){return props=>{const user=useUser();if(!user)return null;const imageSrc=user[property];log(\"avatar source\",user[property]);if(imageSrc){return /*#__PURE__*/_jsx(Component,{...props,background:{...props.background,src:imageSrc,srcSet:undefined}});}else if(props.background?.src){// Component has image set, use as fallback\nreturn /*#__PURE__*/_jsx(Component,{...props});}else{// Component has no image set, remove\nreturn null;}};}function log(...props){getOutseta()?.debug(\"outseta.framer.override.user\",...props);}function flattenObject(obj,parent=\"\",res={}){for(let key in obj){let propName=parent?`${parent}.${key}`:key;if(Array.isArray(obj[key])){obj[key].forEach((item,index)=>{flattenObject(item,`${propName}[${index}]`,res);});}else if(typeof obj[key]===\"object\"&&obj[key]!==null){flattenObject(obj[key],propName,res);}else{res[propName]=obj[key];}}return res;}\nexport const __FramerMetadata__ = {\"exports\":{\"asLogoutButton\":{\"type\":\"reactHoc\",\"name\":\"asLogoutButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withUserAvatar\":{\"type\":\"reactHoc\",\"name\":\"withUserAvatar\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"showForPartyPeople\":{\"type\":\"reactHoc\",\"name\":\"showForPartyPeople\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"showForPartyAccounts\":{\"type\":\"reactHoc\",\"name\":\"showForPartyAccounts\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAccountSubscriptionUid\":{\"type\":\"reactHoc\",\"name\":\"withAccountSubscriptionUid\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"showForSinglePlan_aWxYEbmV\":{\"type\":\"reactHoc\",\"name\":\"showForSinglePlan_aWxYEbmV\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAccountSubscriptionDescription\":{\"type\":\"reactHoc\",\"name\":\"withAccountSubscriptionDescription\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAccountName\":{\"type\":\"reactHoc\",\"name\":\"withAccountName\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getUser\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withUserLastName\":{\"type\":\"reactHoc\",\"name\":\"withUserLastName\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withUserFullName\":{\"type\":\"reactHoc\",\"name\":\"withUserFullName\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withRegisterPopup\":{\"type\":\"reactHoc\",\"name\":\"withRegisterPopup\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getOutseta\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAccountSubscriptionName\":{\"type\":\"reactHoc\",\"name\":\"withAccountSubscriptionName\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"asProfilePopupButton\":{\"type\":\"reactHoc\",\"name\":\"asProfilePopupButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"subscribe\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withUserEmail\":{\"type\":\"reactHoc\",\"name\":\"withUserEmail\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withUserFirstName\":{\"type\":\"reactHoc\",\"name\":\"withUserFirstName\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"asLoginPopupButton\":{\"type\":\"reactHoc\",\"name\":\"asLoginPopupButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"showForAnonymous\":{\"type\":\"reactHoc\",\"name\":\"showForAnonymous\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"showForAuthenticated\":{\"type\":\"reactHoc\",\"name\":\"showForAuthenticated\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./OutsettaOverride.map"],"mappings":"yHAGA,SAAgB,EAAqB,EAAU,CAAC,MAAO,IAA4B,EAAK,EAAU,CAAC,GAAG,EAAM,uBAAuB,IAAI,CAAC,CAAI,SAAgB,EAAiB,EAAU,CAAC,MAAO,IAA4B,EAAK,EAAU,CAAC,GAAG,EAAM,mBAAmB,IAAI,CAAC,CAwBjE,SAAgB,GAAY,CAAC,GAAG,GAAQ,EAAO,QAAY,OAAO,EAAO,QAAoB,IAAQ,QAAQ,IAAI,6FAA6F,CAAC,MAAM,uFAAuF,EAAO,SAAS,SAAS,wDAAwD,EAIxjB,SAAS,EAAI,GAAG,EAAM,CAAC,GAAY,EAAE,MAAM,+BAA+B,GAAG,EAAM,CAAE,SAAS,EAAc,EAAI,EAAO,GAAG,EAAI,EAAE,CAAC,CAAC,IAAI,IAAI,KAAO,EAAI,CAAC,IAAI,EAAS,EAAO,GAAG,EAAO,GAAG,IAAM,EAAO,MAAM,QAAQ,EAAI,GAAK,CAAE,EAAI,GAAK,SAA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