{"version":3,"file":"WithPhoneValidation.BasjPWfN.mjs","names":["useRef","useRef"],"sources":["https:/framerusercontent.com/modules/q2uZAItnOYjX8h1Zolf1/8k2b3lwnDwzzCJdzhwoE/withNameValidation.js","https:/framerusercontent.com/modules/PAvcZIVif6hVvEQYB6O8/T3rYEB9Fj7EFpX9kYQss/WithPhoneValidation.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useRef,useEffect}from\"react\";export function withNameValidation(Component){return props=>{const ref=useRef(null);useEffect(()=>{const container=ref.current;if(!container)return;const input=container.querySelector(\"input\");if(!input)return;const handleInput=e=>{const target=e.target;const filtered=target.value.replace(/[^a-zA-Z\\u0600-\\u06FF\\s]/g,\"\");if(target.value!==filtered){target.value=filtered;target.dispatchEvent(new Event(\"input\",{bubbles:true}));}};const handleKeyDown=e=>{const key=e.key;// Allow control keys\nif(key.length>1)return;// Block if not a letter or space\nif(!/^[a-zA-Z\\u0600-\\u06FF\\s]$/.test(key)){e.preventDefault();}};input.addEventListener(\"input\",handleInput);input.addEventListener(\"keydown\",handleKeyDown);return()=>{input.removeEventListener(\"input\",handleInput);input.removeEventListener(\"keydown\",handleKeyDown);};},[]);return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{display:\"contents\"},children:/*#__PURE__*/_jsx(Component,{...props})});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withNameValidation\":{\"type\":\"reactHoc\",\"name\":\"withNameValidation\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./withNameValidation.map","import{jsx as _jsx}from\"react/jsx-runtime\";import{useRef,useEffect}from\"react\";const arabicHinduToWestern={\"٠\":\"0\",\"١\":\"1\",\"٢\":\"2\",\"٣\":\"3\",\"٤\":\"4\",\"٥\":\"5\",\"٦\":\"6\",\"٧\":\"7\",\"٨\":\"8\",\"٩\":\"9\"};function toWesternDigits(value){return value.split(\"\").map(char=>arabicHinduToWestern[char]||char).join(\"\");}function stripNonDigits(value,keepPlus=false){if(keepPlus){return value.replace(/[^0-9+]/g,\"\");}return value.replace(/[^0-9]/g,\"\");}function getCountryCodeLen(digits){if(digits.startsWith(\"1\"))return 1;if(digits.startsWith(\"44\")||digits.startsWith(\"91\")||digits.startsWith(\"20\")||digits.startsWith(\"33\")||digits.startsWith(\"49\")||digits.startsWith(\"90\")||digits.startsWith(\"92\")||digits.startsWith(\"62\")||digits.startsWith(\"55\")||digits.startsWith(\"81\")||digits.startsWith(\"86\")||digits.startsWith(\"61\")||digits.startsWith(\"34\")||digits.startsWith(\"39\")||digits.startsWith(\"31\")||digits.startsWith(\"46\")||digits.startsWith(\"47\")||digits.startsWith(\"45\")||digits.startsWith(\"41\")||digits.startsWith(\"43\")||digits.startsWith(\"32\")||digits.startsWith(\"48\")||digits.startsWith(\"30\")||digits.startsWith(\"36\")||digits.startsWith(\"40\")||digits.startsWith(\"27\")||digits.startsWith(\"82\")||digits.startsWith(\"60\")||digits.startsWith(\"63\")||digits.startsWith(\"64\")||digits.startsWith(\"65\")||digits.startsWith(\"66\")||digits.startsWith(\"52\")||digits.startsWith(\"51\")||digits.startsWith(\"54\")||digits.startsWith(\"56\")||digits.startsWith(\"57\")||digits.startsWith(\"58\")||digits.startsWith(\"53\")||digits.startsWith(\"7\"))return 2;return 3;}// Max digits after the country code (subscriber number)\nconst PHONE_DIGITS=9;// Max digits for a local number starting with 0\nconst LOCAL_DIGITS=10;// Hard cap on total digits for international numbers (cc up to 3 + 9 subscriber = 12)\nconst INTL_MAX_DIGITS=12;function countDigits(value){return(value.match(/[0-9]/g)||[]).length;}function formatPhone(raw){const converted=toWesternDigits(raw);const cleaned=stripNonDigits(converted,true);if(cleaned.startsWith(\"+\")){// Strip to pure digits, cap at INTL_MAX_DIGITS total\nconst allDigits=cleaned.slice(1).replace(/\\D/g,\"\").slice(0,INTL_MAX_DIGITS);const ccLen=getCountryCodeLen(allDigits);const cc=allDigits.slice(0,ccLen);const rest=allDigits.slice(ccLen).slice(0,PHONE_DIGITS);const parts=[];const pattern=[2,3,2,2];let idx=0;for(const len of pattern){if(idx>=rest.length)break;parts.push(rest.slice(idx,idx+len));idx+=len;}return\"+\"+cc+(parts.length?\" \"+parts.join(\" \"):\"\");}const digits=cleaned.replace(/\\D/g,\"\").slice(0,LOCAL_DIGITS);if(digits.startsWith(\"0\")){const parts=[];const pattern=[3,3,2,2];let idx=0;for(const len of pattern){if(idx>=digits.length)break;parts.push(digits.slice(idx,idx+len));idx+=len;}return parts.join(\" \");}return digits;}/**\n * Returns the max number of raw digits allowed given the current value.\n * For international: we allow up to INTL_MAX_DIGITS total digits (cc + subscriber).\n * For local: LOCAL_DIGITS.\n *\n * We intentionally use INTL_MAX_DIGITS as an upper bound rather than\n * computing ccLen + PHONE_DIGITS from a partial country code, which\n * caused premature blocking while the user was still typing the cc.\n */function getMaxDigits(value){const converted=toWesternDigits(value);const cleaned=stripNonDigits(converted,true);if(cleaned.startsWith(\"+\")){return INTL_MAX_DIGITS// 12: enough for any cc (1–3) + 9 subscriber digits\n;}return LOCAL_DIGITS// 10 for 05X XXX XX XX\n;}export function withPhoneValidation(Component){return props=>{const ref=useRef(null);useEffect(()=>{const container=ref.current;if(!container)return;const input=container.querySelector(\"input\");if(!input)return;const handleInput=e=>{const target=e.target;const cursorPos=target.selectionStart||0;const prevLen=target.value.length;const formatted=formatPhone(target.value);if(target.value!==formatted){target.value=formatted;const diff=formatted.length-prevLen;const newPos=Math.max(0,cursorPos+diff);target.setSelectionRange(newPos,newPos);target.dispatchEvent(new Event(\"input\",{bubbles:true}));}};const handleKeyDown=e=>{const key=e.key;if(key.length>1)return;// allow Backspace, Arrow keys, etc.\n// Block anything that isn't a digit, Arabic-Indic digit, or leading +\nif(!/^[0-9٠-٩+]$/.test(key)){e.preventDefault();return;}// + is only allowed as the very first character\nif(key===\"+\"&&e.target.value.length>0){e.preventDefault();return;}// For digit keys, check whether we've already hit the cap\nif(/^[0-9٠-٩]$/.test(key)){const currentValue=e.target.value;const max=getMaxDigits(currentValue);// Count digits in current value (spaces and + don't count)\nconst currentDigits=countDigits(toWesternDigits(currentValue));if(currentDigits>=max){e.preventDefault();}}};input.addEventListener(\"input\",handleInput);input.addEventListener(\"keydown\",handleKeyDown);return()=>{input.removeEventListener(\"input\",handleInput);input.removeEventListener(\"keydown\",handleKeyDown);};},[]);return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{display:\"contents\"},children:/*#__PURE__*/_jsx(Component,{...props})});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withPhoneValidation\":{\"type\":\"reactHoc\",\"name\":\"withPhoneValidation\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithPhoneValidation.map"],"mappings":"yHAA+E,SAAgB,EAAmB,EAAU,CAAC,MAAO,IAAO,CAAC,IAAM,EAAIA,EAAO,IAAI,EAEiH,OAF/G,MAAc,CAAC,IAAM,EAAU,EAAI,QAAQ,GAAG,CAAC,EAAU,OAAO,IAAM,EAAM,EAAU,cAAc,OAAO,EAAE,GAAG,CAAC,EAAM,OAAO,IAAM,EAAY,GAAG,CAAC,IAAM,EAAO,EAAE,OAAa,EAAS,EAAO,MAAM,QAAQ,4BAA4B,EAAE,EAAK,EAAO,QAAQ,IAAU,EAAO,MAAM,EAAS,EAAO,cAAc,IAAI,MAAM,QAAQ,CAAC,QAAQ,EAAI,CAAC,CAAC,EAAG,EAAQ,EAAc,GAAG,CAAC,IAAM,EAAI,EAAE,IAC/hB,EAAI,OAAO,GACV,4BAA4B,KAAK,CAAG,GAAG,EAAE,eAAe,CAAG,EAA8F,OAA5F,EAAM,iBAAiB,QAAQ,CAAW,EAAE,EAAM,iBAAiB,UAAU,CAAa,MAAY,CAAC,EAAM,oBAAoB,QAAQ,CAAW,EAAE,EAAM,oBAAoB,UAAU,CAAa,CAAE,CAAE,EAAE,CAAC,CAAC,EAAsB,EAAK,MAAM,CAAK,MAAI,MAAM,C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