{"version":3,"file":"SignInForm.Ca9c0Q7t.mjs","names":["SignInForm","useState","useMemo","auth","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":"+UAA2C,IAA8C,IACO,IAC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