{"version":3,"file":"WithPhoneValidation.f6tFD0b9.mjs","names":["React.useRef","React.useState","React.useMemo","React.useCallback"],"sources":["https:/framerusercontent.com/modules/JGlHTkAm7CEY5gNUAoK7/refTtEmS5wFXuoesjEB9/WithPhoneValidation.js"],"sourcesContent":["// User request: Create a Framer code override HOC named withPhoneValidation for native form phone inputs, validating via setCustomValidity with CZ messages, normalization, anti-fake rules, and tunable override props.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";function normalizePhoneValue(rawValue){return rawValue.replace(/[\\s\\-()]/g,\"\");}function extractNationalDigits(value,allowCountryCode){const nationalLength=9;const stripOptionalTrunkZero=digits=>{if(digits.length===nationalLength+1&&digits.startsWith(\"0\")){return digits.slice(1);}return digits;};const plusMatch=value.match(/^\\+(\\d+)$/);if(plusMatch){const digits=plusMatch[1];if(!allowCountryCode)return null;let remainder=digits;if(digits.startsWith(\"420\")||digits.startsWith(\"421\")){remainder=digits.slice(3);}return remainder?stripOptionalTrunkZero(remainder):null;}if(/^\\d+$/.test(value)){let remainder=value;if(allowCountryCode){if(remainder.startsWith(\"00420\"))remainder=remainder.slice(5);else if(remainder.startsWith(\"00421\"))remainder=remainder.slice(5);else if(remainder.startsWith(\"420\"))remainder=remainder.slice(3);else if(remainder.startsWith(\"421\"))remainder=remainder.slice(3);}const normalized=stripOptionalTrunkZero(remainder);return normalized?normalized:null;}return null;}function isAscendingOrDescendingSequence(value){if(value.length<2)return false;let ascending=true;let descending=true;for(let i=1;i<value.length;i++){const previous=Number(value[i-1]);const current=Number(value[i]);if(current!==previous+1)ascending=false;if(current!==previous-1)descending=false;}return ascending||descending;}function getValidationMessage(nationalDigits,requiredLength,allowedPrefixSet,minUniqueDigits,fallbackErrorMessage){if(!nationalDigits||!/^\\d+$/.test(nationalDigits)){return\"Zadejte platn\\xe9 telefonn\\xed č\\xedslo (9 č\\xedslic).\";}if(nationalDigits.length!==requiredLength){return\"Zadejte platn\\xe9 telefonn\\xed č\\xedslo (9 č\\xedslic).\";}if(allowedPrefixSet.size>0&&!allowedPrefixSet.has(nationalDigits.charAt(0))){return\"Zadejte platn\\xe9 mobiln\\xed č\\xedslo.\";}if(/^(\\d)\\1+$/.test(nationalDigits)){return fallbackErrorMessage;}if(isAscendingOrDescendingSequence(nationalDigits)){return fallbackErrorMessage;}const uniqueDigits=new Set(nationalDigits.split(\"\")).size;if(uniqueDigits<minUniqueDigits){return fallbackErrorMessage;}const blocklist=new Set([\"111111111\",\"123123123\",\"111222333\"]);if(blocklist.has(nationalDigits)){return fallbackErrorMessage;}return\"\";}export function withPhoneValidation(Component){const WithPhoneValidation=/*#__PURE__*/React.forwardRef(function WithPhoneValidation(props,ref){const isStaticRenderer=useIsStaticRenderer();const internalRef=React.useRef(null);const[mountedNode,setMountedNode]=React.useState(null);const{requiredLength=9,minUniqueDigits=4,allowCountryCode=true,allowedPrefixes=\"6,7,9\",errorMessage=\"Zadejte pros\\xedm skutečn\\xe9 telefonn\\xed č\\xedslo.\",...rest}=props;const allowedPrefixSet=React.useMemo(()=>{return new Set(allowedPrefixes.split(\",\").map(prefix=>prefix.trim()).filter(prefix=>/^\\d$/.test(prefix)));},[allowedPrefixes]);const setRefs=React.useCallback(node=>{internalRef.current=node;React.startTransition(()=>{setMountedNode(node);});if(typeof ref===\"function\"){ref(node);}else if(ref&&\"current\"in ref){ref.current=node;}},[ref]);React.useEffect(()=>{if(isStaticRenderer||typeof window===\"undefined\"||typeof document===\"undefined\"||!mountedNode){return;}const resolvedInput=mountedNode instanceof HTMLInputElement?mountedNode:mountedNode.querySelector(\"input\");if(!resolvedInput)return;const validateCurrentValue=()=>{const normalized=normalizePhoneValue(resolvedInput.value);const nationalDigits=extractNationalDigits(normalized,allowCountryCode);const message=getValidationMessage(nationalDigits,requiredLength,allowedPrefixSet,minUniqueDigits,errorMessage);resolvedInput.setCustomValidity(message);return message;};const handleInputLike=()=>{validateCurrentValue();};const handleSubmitCapture=event=>{const message=validateCurrentValue();if(!message)return;event.preventDefault();event.stopImmediatePropagation();event.stopPropagation();resolvedInput.focus();resolvedInput.reportValidity();};validateCurrentValue();resolvedInput.addEventListener(\"input\",handleInputLike);resolvedInput.addEventListener(\"change\",handleInputLike);resolvedInput.addEventListener(\"blur\",handleInputLike);const form=resolvedInput.closest(\"form\");if(form){form.addEventListener(\"submit\",handleSubmitCapture,true);}return()=>{resolvedInput.removeEventListener(\"input\",handleInputLike);resolvedInput.removeEventListener(\"change\",handleInputLike);resolvedInput.removeEventListener(\"blur\",handleInputLike);if(form){form.removeEventListener(\"submit\",handleSubmitCapture,true);}};},[allowCountryCode,allowedPrefixSet,errorMessage,isStaticRenderer,minUniqueDigits,mountedNode,requiredLength]);return /*#__PURE__*/_jsx(Component,{...rest,ref:setRefs});});addPropertyControls(WithPhoneValidation,{requiredLength:{type:ControlType.Number,title:\"Length\",defaultValue:9,min:1,max:20,step:1},minUniqueDigits:{type:ControlType.Number,title:\"Min Unique\",defaultValue:4,min:1,max:10,step:1},allowCountryCode:{type:ControlType.Boolean,title:\"Country Code\",defaultValue:true,enabledTitle:\"Allow\",disabledTitle:\"Disallow\"},allowedPrefixes:{type:ControlType.String,title:\"Prefixes\",defaultValue:\"6,7,9\"},errorMessage:{type:ControlType.String,title:\"Error\",defaultValue:\"Zadejte pros\\xedm skutečn\\xe9 telefonn\\xed č\\xedslo.\",displayTextArea:true}});return WithPhoneValidation;}\nexport const __FramerMetadata__ = {\"exports\":{\"withPhoneValidation\":{\"type\":\"reactHoc\",\"name\":\"withPhoneValidation\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithPhoneValidation.map"],"mappings":"0OAC+I,SAAS,EAAoB,EAAS,CAAC,OAAO,EAAS,QAAQ,YAAY,EAAE,CAAE,CAAC,SAAS,EAAsB,EAAM,EAAiB,CAAwB,IAAM,EAAuB,GAAY,EAAO,SAAS,IAAkB,EA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