{"version":3,"file":"Validation.BYTMPJsu.mjs","names":["phoneFields"],"sources":["https:/framerusercontent.com/modules/Q5ODPxdHJSwmt99gsfOC/AC9QJ1c5eAMQeMPSS88v/Validation.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect}from\"react\";/**\n * @framerDisableUnlink\n * @framerIntrinsicWidth 100\n * @framerIntrinsicHeight 100\n */export function withPhoneMaskAndNameValidation(Component){return props=>{useEffect(()=>{const applyPhoneMask=event=>{const matrix=\"+998 (__) ___-__-__\";let i=0;const def=matrix.replace(/\\D/g,\"\");let currentValue=event.target.value.replace(/\\D/g,\"\");if(def.length>=currentValue.length){currentValue=def;}const newValue=matrix.replace(/./g,char=>{return/[_\\d]/.test(char)&&i<currentValue.length?currentValue.charAt(i++):i>=currentValue.length?\"\":char;});event.target.value=newValue;};const handleFocus=event=>{if(!event.target.value){event.target.value=\"+998 (\";}};const handleBlur=event=>{const field=event.target;const value=field.value.replace(/\\D/g,\"\");if(value.length<12){let errorMsg=field.parentElement?.querySelector(\".phone-error\");if(!errorMsg){errorMsg=document.createElement(\"div\");errorMsg.className=\"phone-error\";errorMsg.style.color=\"red\";errorMsg.style.fontSize=\"12px\";errorMsg.style.marginTop=\"4px\";errorMsg.textContent=\"Введите полный номер телефона\";field.parentElement?.appendChild(errorMsg);}}else{const errorMsg=field.parentElement?.querySelector(\".phone-error\");if(errorMsg)errorMsg.remove();}};const restrictNameInput=event=>{const regex=/^[a-zA-Zа-яА-ЯёЁ\\s]*$/;if(!regex.test(event.target.value)){event.target.value=event.target.value.replace(/[^a-zA-Zа-яА-ЯёЁ\\s]/g,\"\");}};const handleSubmit=event=>{const phoneFields=document.querySelectorAll('input[type=\"tel\"]');let hasError=false;phoneFields.forEach(field=>{const value=field.value.replace(/\\D/g,\"\");if(value.length<12){hasError=true;field.focus();let errorMsg=field.parentElement?.querySelector(\".phone-error\");if(!errorMsg){errorMsg=document.createElement(\"div\");errorMsg.className=\"phone-error\";errorMsg.style.color=\"red\";errorMsg.style.fontSize=\"12px\";errorMsg.style.marginTop=\"4px\";errorMsg.textContent=\"Введите полный номер телефона\";field.parentElement?.appendChild(errorMsg);}}});if(hasError){event.preventDefault();event.stopPropagation();}};const phoneFields=document.querySelectorAll('input[type=\"tel\"]');const nameFields=document.querySelectorAll('input[name=\"name\"], input[name=\"surname\"]');const forms=document.querySelectorAll(\"form\");phoneFields.forEach(phoneField=>{phoneField.addEventListener(\"input\",applyPhoneMask);phoneField.addEventListener(\"focus\",handleFocus);phoneField.addEventListener(\"blur\",handleBlur);});nameFields.forEach(nameField=>{nameField.addEventListener(\"input\",restrictNameInput);});forms.forEach(form=>{form.addEventListener(\"submit\",handleSubmit,true);});return()=>{phoneFields.forEach(phoneField=>{phoneField.removeEventListener(\"input\",applyPhoneMask);phoneField.removeEventListener(\"focus\",handleFocus);phoneField.removeEventListener(\"blur\",handleBlur);});nameFields.forEach(nameField=>{nameField.removeEventListener(\"input\",restrictNameInput);});forms.forEach(form=>{form.removeEventListener(\"submit\",handleSubmit,true);});};},[]);return /*#__PURE__*/_jsx(Component,{...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withPhoneMaskAndNameValidation\":{\"type\":\"reactHoc\",\"name\":\"withPhoneMaskAndNameValidation\",\"annotations\":{\"framerDisableUnlink\":\"* @framerIntrinsicWidth 100\",\"framerIntrinsicHeight\":\"100\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Validation.map"],"mappings":"kHAIG,SAAgB,EAA+B,EAAU,CAAC,MAAO,KAAQ,MAAc,CAAC,IAAM,EAAe,GAAO,CAAC,IAAM,EAAO,sBAA0B,EAAE,EAAQ,EAAI,EAAO,QAAQ,MAAM,GAAG,CAAK,EAAa,EAAM,OAAO,MAAM,QAAQ,MAAM,GAAG,CAAI,EAAI,QAAQ,EAAa,SAAQ,EAAa,GAAK,IAAM,EAAS,EAAO,QAAQ,KAAK,GAAa,QAAQ,K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