{"version":3,"file":"Show.CtwltCoQ.mjs","names":["setLoading"],"sources":["https:/framerusercontent.com/modules/kwbqPQkyxJ5zu7TgSVpn/Lwx5P43bagrnFf28gyNN/Store.js","https:/framerusercontent.com/modules/Qx8RgmGf7kk8MHCDTWJo/IJAe5RmyA0BUdjzI8ID6/Show.js"],"sourcesContent":["import{createStore}from\"https://framerusercontent.com/modules/ecmnSddXBJpQsAujxCSQ/2zMFA9EQryEKkWl3wsPK/State.js\";export const useApi=createStore({profile:{}});export const useLoading=createStore({isLoadingProfile:true});\nexport const __FramerMetadata__ = {\"exports\":{\"useLoading\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useApi\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Store.map","// Show.tsx\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useApi,useLoading}from\"https://framerusercontent.com/modules/kwbqPQkyxJ5zu7TgSVpn/Lwx5P43bagrnFf28gyNN/Store.js\";import{fetchData}from\"https://framerusercontent.com/modules/isEeIcye7ChOHOrloOwT/HfmhQso7rzmL5H2oUzFp/Fetch.js\";import{useEffect}from\"react\";import{toast}from\"sonner\";import Skeleton from\"https://framerusercontent.com/modules/wrEJ8oVMagKXTJJpuvZR/aCn6i9g6yo4ByshUBVvX/Skeleton.js\";export const initComponent=Component=>{return props=>{const[,setLoading]=useLoading();const[api,setApi]=useApi();useEffect(()=>{setLoading({isLoadingProfile:true});fetchData(`/web/user/profile/`,{empty:{}}).then(response=>{console.log(\"profile\",response);if(response.code===401)return window.location.href=\"/login\";setApi({profile:response.data});}).then(()=>setLoading({isLoadingProfile:false})).catch(()=>window.location.href=\"/login\");},[]);return /*#__PURE__*/_jsx(Component,{...props});};};export const setLoading=Component=>{return props=>{const[loading]=useLoading();if(loading.isLoadingProfile){return /*#__PURE__*/_jsx(Skeleton,{style:{minHeight:\"32px\"}});}return /*#__PURE__*/_jsx(Component,{...props});};};export const formUpdateProfile=Component=>{return props=>{const[loading,setLoading]=useLoading();const[api,setApi]=useApi();const handleClick=async e=>{e.preventDefault();e.stopPropagation();if(loading.isLoadingProfile)return;const form=e.target.closest(\"form\");if(!form){console.warn(\"⚠️ No se encontr\\xf3 un formulario\");return;}const formData=new FormData(form);const values={};formData.forEach((value,key)=>{if(key===\"variant\"){const raw=typeof value===\"string\"?value:String(value??\"\");if(!raw||raw.trim()===\"\"){values[key]=\"\";return;}try{values[key]=JSON.parse(raw);}catch{values[key]=raw;}}else{values[key]=value;}});const requiredFields=[\"first_name\",\"last_name\",\"phone_number\",// \"email\",\n\"company_name\"];for(const field of requiredFields){const v=values[field];if(v===undefined||String(v).trim()===\"\"){const label=field.replace(\"_\",\" \");toast.error(`${label[0].toUpperCase()+label.slice(1)} is required`);return;}}// const email = String(values.email)\n// if (!/^\\S+@\\S+\\.\\S+$/.test(email)) {\n//     toast.error(\"Email is invalid\")\n//     return\n// }\ntry{setLoading({isLoadingProfile:true});const response=await fetchData(`/web/user/profile`,{method:\"PUT\",body:values});if([200,201].includes(response?.code)){setApi({profile:response.data});toast.success(\"Profile Updated.\");}else{toast.error(\"Fail Updated\");}}catch(error){console.error(\"Updated error:\",error);toast.error(\"An error occurred while submitting the update profile.\");}finally{setLoading({isLoadingProfile:false});}};if(loading.isLoadingProfile){return /*#__PURE__*/_jsx(Component,{...props,variant:\"L / Primary - Disabled\",onClick:handleClick});}return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};};export const populateFormWithProfile=Component=>{return props=>{const[api]=useApi();const[loading,setLoading]=useLoading();useEffect(()=>{if(!api?.profile)return;console.log(\"api\",api.profile);const form=document.querySelector('[data-framer-name=\"Form Profile\"]');if(!form)return;const{first_name,last_name,email,phone_number,company_name,billing_address,shipping_address}=api.profile;const mappings={first_name,last_name,email,phone_number,company_name};if(billing_address){mappings.billing_first_name=billing_address.first_name;mappings.billing_last_name=billing_address.last_name;mappings.billing_email=billing_address.email;mappings.billing_phone_number=billing_address.phone;mappings.billing_company_name=billing_address.company;mappings.billing_address_line_1=billing_address.address_line_1;mappings.billing_address_line_2=billing_address.address_line_2;mappings.billing_city=billing_address.city;mappings.billing_state=billing_address.state;mappings.billing_zip_code=billing_address.zip_code;mappings.billing_country=billing_address.country;}if(shipping_address){mappings.shipping_first_name=shipping_address.first_name;mappings.shipping_last_name=shipping_address.last_name;mappings.shipping_email=shipping_address.email;mappings.shipping_phone_number=shipping_address.phone;mappings.shipping_company_name=shipping_address.company;mappings.shipping_address_line_1=shipping_address.address_line_1;mappings.shipping_address_line_2=shipping_address.address_line_2;mappings.shipping_city=shipping_address.city;mappings.shipping_state=shipping_address.state;mappings.shipping_zip_code=shipping_address.zip_code;mappings.shipping_country=shipping_address.country;}Object.entries(mappings).forEach(([key,value])=>{if(value===undefined||value===null)return;const input=form.querySelector(`[name=\"${key}\"]`);if(input){input.value=String(value);}});},[api.profile]);return /*#__PURE__*/_jsx(Component,{...props});};};export const formUpdatePassword=Component=>{return props=>{const[loading,setLoading]=useLoading();const[,setApi]=useApi();const handleClick=async e=>{e.preventDefault();e.stopPropagation();if(loading.isUpdatingPassword)return;const form=e.target.closest(\"form\");if(!form){console.warn(\"⚠️ No se encontr\\xf3 un formulario\");return;}const formData=new FormData(form);const values={};formData.forEach((value,key)=>{values[key]=value;});const requiredFields=[\"current_password\",\"new_password\",\"confirm_password\"];for(const field of requiredFields){const v=values[field];if(v===undefined||String(v).trim()===\"\"){const label=field.replace(\"_\",\" \");toast.error(`${label[0].toUpperCase()+label.slice(1)} is required`);return;}}if(values.new_password!==values.confirm_password){toast.error(\"New Password and Confirm Password do not match\");return;}try{setLoading({isUpdatingPassword:true});const response=await fetchData(`/web/user/password`,{method:\"PUT\",body:{current_password:values.current_password,new_password:values.new_password}});if([200,204].includes(response?.code)){toast.success(\"Password updated successfully.\");}else if([400,401].includes(response?.code)){toast.error(response?.data||\"Password update failed.\");}else{toast.error(\"Unexpected error occurred.\");}}catch(error){console.error(\"Password update error:\",error);toast.error(\"An error occurred while changing the password.\");}finally{setLoading({isUpdatingPassword:false});}};if(loading.isUpdatingPassword){return /*#__PURE__*/_jsx(Component,{...props,variant:\"L / Primary - Disabled\",onClick:handleClick});}return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};};export const inputPassword=Component=>{return props=>{return /*#__PURE__*/_jsx(Component,{...props,type:\"password\"});};};export const formUpdateEmail=Component=>{return props=>{const[loading,setLoading]=useLoading();const[,setApi]=useApi();const handleClick=async e=>{e.preventDefault();e.stopPropagation();if(loading.isUpdatingEmail)return;const form=e.target.closest(\"form\");if(!form){console.warn(\"⚠️ No se encontr\\xf3 un formulario\");return;}const formData=new FormData(form);const values={};formData.forEach((value,key)=>{values[key]=value;});const email=String(values.new_email||\"\").trim();if(!email){toast.error(\"New Email is required\");return;}const isValidEmail=/^\\S+@\\S+\\.\\S+$/.test(email);if(!isValidEmail){toast.error(\"Email is invalid\");return;}try{setLoading({isUpdatingEmail:true});const response=await fetchData(`/web/user/email/request`,{method:\"POST\",body:{new_email:email}});if([200,201].includes(response?.code)){toast.success(\"Email update request sent.\");}else if([400,401].includes(response?.code)){toast.error(response?.data||\"Email update failed.\");}else{toast.error(\"Unexpected error occurred.\");}}catch(error){console.error(\"Email update error:\",error);toast.error(\"An error occurred while updating the email.\");}finally{setLoading({isUpdatingEmail:false});}};if(loading.isUpdatingEmail){return /*#__PURE__*/_jsx(Component,{...props,variant:\"L / Primary - Disabled\",onClick:handleClick});}return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};};\nexport const __FramerMetadata__ = {\"exports\":{\"populateFormWithProfile\":{\"type\":\"reactHoc\",\"name\":\"populateFormWithProfile\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"formUpdatePassword\":{\"type\":\"reactHoc\",\"name\":\"formUpdatePassword\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"inputPassword\":{\"type\":\"reactHoc\",\"name\":\"inputPassword\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"formUpdateProfile\":{\"type\":\"reactHoc\",\"name\":\"formUpdateProfile\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"setLoading\":{\"type\":\"reactHoc\",\"name\":\"setLoading\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"formUpdateEmail\":{\"type\":\"reactHoc\",\"name\":\"formUpdateEmail\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"initComponent\":{\"type\":\"reactHoc\",\"name\":\"initComponent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Show.map"],"mappings":"uVAAkH,CAAa,EAAO,EAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAc,EAAW,EAAY,CAAC,iBAAiB,GAAK,CAAC,mCCCjL,IAAwH,IAAgH,IAA6B,IAA0B,IAAkH,CAAa,EAAc,GAAmB,GAAO,CAAC,GAAK,EAAEA,GAAY,GAAY,CAAM,CAAC,EAAI,GAAQ,GAAQ,CAA4U,OAA3U,MAAc,CAAC,EAAW,CAAC,iBAAiB,GAAK,CAAC,CAAC,EAAU,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAK,GAAU,CAAiC,GAAhC,QAAQ,IAAI,UAAU,EAAS,CAAI,EAAS,OAAO,IAAI,MAAO,GAAO,SAAS,KAAK,SAAS,EAAO,CAAC,QAAQ,EAAS,KAAK,CAAC,EAAG,CAAC,SAASA,EAAW,CAAC,iBAAiB,GAAM,CAAC,CAAC,CAAC,UAAU,EAAO,SAAS,KAAK,SAAS,EAAG,EAAE,CAAC,CAAqB,EAAK,EAAU,CAAC,GAAG,EAAM,CAAC,EAAkB,EAAW,GAAmB,GAAO,CAAC,GAAK,CAAC,GAAS,GAAY,CAA6F,OAAzF,EAAQ,iBAAsC,EAAK,EAAS,CAAC,MAAM,CAAC,UAAU,OAAO,CAAC,CAAC,CAAsB,EAAK,EAAU,CAAC,GAAG,EAAM,CAA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