{"version":3,"file":"SignInForm.Rbdn1CUd.mjs","names":["SignInForm","BaseForm"],"sources":["https:/framerusercontent.com/modules/pMP2anKUHudrYUE4TaAp/bBPSs3BgJvhUGhA1fSP0/SignInForm.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useMemo,useState}from\"react\";// @ts-ignore\nimport{addPropertyControls,ControlType,withCSS,inferInitialRouteFromPath,useRouter}from\"framer\";// @ts-ignore\nimport{auth}from\"https://cdn.framerauth.com/packages/sdk/live/latest/framerauth.esm.js\";import BaseForm,{basePropertyControls}from\"https://framerusercontent.com/modules/ExV5oOjPmSTY0gHEjmby/NpqywsqBSPokrP5l2Kmw/BaseForm.js\";//////////////////////////////////\n/////// FORM CONFIGURATION ///////\n//////////////////////////////////\n// Define inputs\nconst baseInputs=[{label:\"Email\",name:\"email\",type:\"email\",required:true,extra:false,placeholder:\"Email\"},{label:\"Password\",name:\"password\",type:\"password\",required:true,extra:false,placeholder:\"Password\"}];const formId=\"sign_in\"// Unique form ID for this form.\n;const defaultButtonLabel=\"Sign In\"// Default submit button label on this form.\n;const exposePasswordVisibilityToggle=true// Expose password visibility toggle property for password inputs.\n;const buttonLabelKey=`${formId}_button_label`// Key for button label property control.\n;/**\n * Sign In Form\n * By Joel Whitaker\n *\n * @framerDisableUnlink\n *\n * @framerIntrinsicWidth 300\n * @framerIntrinsicHeight 40\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight any\n */const SignInForm=withCSS(function SignInForm({...baseProps}){const[inputs,setInputs]=useState(baseInputs)// We can override inputs with property controls.\n;const[redirectLink,setRedirectLink]=useState(baseProps.link);const[initializing,setInitializing]=useState(true);const buttonProps=useMemo(()=>{// Map button label to button\n// This is to avoid style copy-pasting of the button label.\nreturn{...baseProps.button,label:baseProps.button[buttonLabelKey]};},[baseProps.button,baseProps.button[buttonLabelKey]]);useEffect(()=>{// Map input labels to inputs\nif(baseProps.inputFields){const newInputs=[];baseInputs.forEach((input,_idx)=>{const inputControlName=snakeToCamel(input.name);if(!(inputControlName in baseProps.inputFields)){// If the input is not in the inputFields object, skip it.\nconsole.log(`Input ${inputControlName} not found in inputFields object.`);return;}const inputField=baseProps.inputFields[inputControlName];const display=inputField.display;const label=inputField.label;const placeholder=label;if(display===true||display===undefined){newInputs.push({...input,label,placeholder});}});setInputs(newInputs);}},[baseProps.inputFields]);const router=useRouter();useEffect(()=>{const checkAuthStatus=async()=>{setInitializing(true);try{if(isBrowser()){var _site_links;const{data:{site}}=await auth.getSite({cache:true});const accountPage=(site===null||site===void 0?void 0:(_site_links=site.links)===null||_site_links===void 0?void 0:_site_links.account)||\"/account\";const licenseKey=getParamValue(\"license_key\");const{data:_,error}=await auth.getUser();if(!error){if(licenseKey){navigateTo(`${accountPage}#license_key=${licenseKey}`);}else{if(redirectLink){navigateTo(redirectLink);}// setLoading(false)\n}}else{if(licenseKey){setRedirectLink(`${accountPage}#license_key=${licenseKey}`);}// setLoading(false)\n}}}finally{setInitializing(false);}};checkAuthStatus();},[]);const navigateTo=link=>{const[path,hash]=link.split(\"#\");const{routeId,pathVariables}=inferInitialRouteFromPath(router.routes,path);if(routeId){router.navigate(routeId,hash,pathVariables);}};const onSubmit=async formData=>{// Prevent submitting while submitting\nconst{data:_,error}=await auth.signInWithPassword({email:formData.email,password:formData.password});if(error){return{ok:false,message:error.message};}// const event = new Event('framerAuthRefetchUser');\n// window.dispatchEvent(event);\nreturn{ok:true,message:\"Successfully Signed in.\"};};return /*#__PURE__*/_jsx(BaseForm,{...baseProps,isInitializing:initializing,link:redirectLink,button:buttonProps,inputs:inputs,onSubmit:onSubmit});},[]);const isBrowser=()=>{return typeof window!==\"undefined\";};const getParamValue=paramName=>{if(!isBrowser()){return null;}const urlParams=new URLSearchParams(window.location.search);if(urlParams.has(paramName)){return urlParams.get(paramName);}const hashParams=new URLSearchParams(window.location.hash.substring(1))// Remove the '#' part\n;if(hashParams.has(paramName)){return hashParams.get(paramName);}return null;};const snakeToCamel=str=>{return str.split(\"_\").map((word,index)=>{if(index===0){return word;}return word.charAt(0).toUpperCase()+word.slice(1);}).join(\"\");};// Here we can override property controls if we don't want to expose them to the user.\n// We generate the inputs property controls dynamically based on the inputs array.\nconst inputsPropertyControls={};baseInputs.forEach((input,_idx)=>{const inputControlName=snakeToCamel(input.name);inputsPropertyControls[inputControlName]={title:`${input.label}`,type:ControlType.Object,controls:{display:input.extra===true?{title:\"Display\",type:ControlType.Boolean,defaultValue:true}:undefined,label:{title:\"Label\",type:ControlType.String,defaultValue:input.label}}};});const exportBasePropertyControls={...basePropertyControls,link:{title:\"Redirect\",type:ControlType.Link},inputFields:{title:\"Inputs\",type:ControlType.Object,controls:inputsPropertyControls},input:{...basePropertyControls.input,controls:{...basePropertyControls.input.controls,icon:exposePasswordVisibilityToggle?{type:ControlType.Object,title:\"Icon\",controls:{showPasswordVisibilityIcon:{title:\"Activated\",type:ControlType.Boolean,defaultValue:true},color:{title:\"Color\",type:ControlType.Color,defaultValue:\"#000\",hidden:props=>!props.showPasswordVisibilityIcon}}}:undefined}},button:{// Inject default button label\n...basePropertyControls.button,controls:{...basePropertyControls.button.controls,label:undefined,[buttonLabelKey]:{...basePropertyControls.button.controls.label,defaultValue:defaultButtonLabel}}}};// @ts-ignore - TS doesn't like our basePropertyControls type.\naddPropertyControls(SignInForm,exportBasePropertyControls);SignInForm.defaultProps={...BaseForm.defaultProps,...SignInForm.defaultProps};export default SignInForm;\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SignInForm\",\"slots\":[],\"annotations\":{\"framerIntrinsicHeight\":\"40\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerIntrinsicWidth\":\"300\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any\",\"framerDisableUnlink\":\"*\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SignInForm.map"],"mappings":"oiBAAA,GAA2C,IAA8C,CACzF,GAAgG,C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