{"version":3,"file":"InputLengthOverride.fTPcuB2F.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/Kg5H0zQu4ebRIis7XGlj/BJvcEQyB7DSI5duVyDP8/InputLengthOverride.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useState}from\"react\";// ==============================================\n// INPUT FIELD OVERRIDE WITH CHARACTER VALIDATION\n// ==============================================\n// Configuration - Edit these values directly in the code\nconst CONFIG={minLength:2,maxLength:32,showCounter:false,counterPosition:\"below\",customErrorMessage:\"\",ignoreMaxForEmail:false,emailMaxLength:256,disallowNumbersAndSpecialChars:true};// Global validation state manager\nconst validationState={errors:new Map,listeners:new Set,setError(fieldId,hasError){this.errors.set(fieldId,hasError);this.notifyListeners();},hasErrors(){return Array.from(this.errors.values()).some(error=>error);},subscribe(listener){this.listeners.add(listener);return()=>this.listeners.delete(listener);},notifyListeners(){this.listeners.forEach(listener=>listener());}};export function withCharacterLength(Component){return props=>{const{value:propValue,onChange:propOnChange,onBlur:propOnBlur,...rest}=props;// Check if this is an email input\nconst isEmailInput=props.type===\"email\"||props.inputType===\"email\";// Apply maxLength based on input type\nlet effectiveMaxLength=CONFIG.maxLength;if(isEmailInput){effectiveMaxLength=CONFIG.ignoreMaxForEmail?0:CONFIG.emailMaxLength;}const minLength=CONFIG.minLength;const maxLength=effectiveMaxLength;const showCounter=CONFIG.showCounter;const counterPosition=CONFIG.counterPosition;const validationMessage=CONFIG.customErrorMessage;// Generate unique ID for this field\nconst[fieldId]=useState(()=>`field-${Math.random().toString(36).substr(2,9)}`);const[value,setValue]=useState(propValue||\"\");const[error,setError]=useState(\"\");const[touched,setTouched]=useState(false);useEffect(()=>{if(propValue!==undefined){setValue(propValue);}},[propValue]);useEffect(()=>{// Clean up validation state when component unmounts\nreturn()=>{validationState.errors.delete(fieldId);validationState.notifyListeners();};},[fieldId]);const validateLength=(val,isTouched=true)=>{const length=val.length;let hasError=false;let errorMsg=\"\";// Email validation for email inputs\nif(isEmailInput&&length>0){const emailRegex=/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;if(!emailRegex.test(val)){if(isTouched){errorMsg=\"Please enter a valid email address\";setError(errorMsg);}hasError=true;validationState.setError(fieldId,hasError);return!hasError;}}// Character validation for regular text inputs (not email)\nif(!isEmailInput&&CONFIG.disallowNumbersAndSpecialChars&&length>0){// Allow letters (including Croatian: š,č,ž,đ,ć and their uppercase), spaces, and basic punctuation (. , ' ' ' - )\nconst textOnlyRegex=/^[a-zA-ZÀ-ÿšŠčČžŽđĐćĆ\\s.,''''-]+$/;// Check if value contains valid characters\nif(!textOnlyRegex.test(val)){if(isTouched){errorMsg=\"Please use only letters\";setError(errorMsg);}hasError=true;validationState.setError(fieldId,hasError);return!hasError;}// Check for spaces around hyphens (e.g., \"Ana - Marija\" is invalid)\nif(/\\s-\\s|-\\s|\\s-/.test(val)){if(isTouched){errorMsg=\"No spaces allowed around hyphens\";setError(errorMsg);}hasError=true;validationState.setError(fieldId,hasError);return!hasError;}// Check that it doesn't start with punctuation or spaces\nconst startsWithLetterRegex=/^[a-zA-ZÀ-ÿšŠčČžŽđĐćĆ]/;if(!startsWithLetterRegex.test(val)){if(isTouched){errorMsg=\"Must start with a letter\";setError(errorMsg);}hasError=true;validationState.setError(fieldId,hasError);return!hasError;}}// Length validation\nif(minLength&&length>0&&length<minLength){if(isTouched){errorMsg=validationMessage||`Minimum ${minLength} characters required`;setError(errorMsg);}hasError=true;}else if(maxLength&&length>maxLength){// This shouldn't happen due to hard limit, but just in case\nerrorMsg=validationMessage||`Maximum ${maxLength} characters allowed`;setError(errorMsg);hasError=true;}else{setError(\"\");hasError=false;}validationState.setError(fieldId,hasError);return!hasError;};const handleChange=e=>{// Properly extract the value from the event\nconst newValue=typeof e===\"string\"?e:e?.target?.value??\"\";// HARD LIMIT: Prevent input beyond maxLength\nlet finalValue=newValue;if(maxLength&&finalValue.length>maxLength){finalValue=finalValue.slice(0,maxLength);}setValue(finalValue);validateLength(finalValue,touched);};const handleBlur=e=>{setTouched(true);validateLength(value,true);};const currentLength=value.length;const remaining=maxLength?maxLength-currentLength:null;return /*#__PURE__*/_jsxs(\"div\",{style:{width:\"100%\",position:\"relative\"},children:[/*#__PURE__*/_jsx(Component,{...rest,value:value,onChange:handleChange,onBlur:handleBlur,style:{...props.style,borderColor:error?\"#ef4444\":props.style?.borderColor}}),showCounter&&maxLength&&counterPosition===\"inside\"&&/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",right:\"12px\",top:\"50%\",transform:\"translateY(-50%)\",fontSize:\"12px\",color:remaining<10?\"#ef4444\":\"#9ca3af\",pointerEvents:\"none\"},children:remaining}),(error||showCounter&&counterPosition===\"below\")&&/*#__PURE__*/_jsxs(\"div\",{style:{marginTop:\"4px\",fontSize:\"12px\",display:\"flex\",justifyContent:\"space-between\",alignItems:\"center\"},children:[error&&/*#__PURE__*/_jsx(\"span\",{style:{color:\"#ef4444\"},children:error}),showCounter&&counterPosition===\"below\"&&maxLength&&/*#__PURE__*/_jsxs(\"span\",{style:{color:remaining<10?\"#ef4444\":\"#9ca3af\",marginLeft:error?\"8px\":\"auto\"},children:[currentLength,\" / \",maxLength]})]})]});};}// ==============================================\n// SUBMIT BUTTON OVERRIDE WITH VALIDATION\n// ==============================================\n// Configuration for submit button\nconst SUBMIT_CONFIG={disabledVariant:\"Disabled\"};export function withFormValidation(Component){return props=>{const[hasErrors,setHasErrors]=useState(validationState.hasErrors());useEffect(()=>{// Subscribe to validation state changes\nconst unsubscribe=validationState.subscribe(()=>{setHasErrors(validationState.hasErrors());});return unsubscribe;},[]);const isDisabled=hasErrors||props.disabled;return /*#__PURE__*/_jsx(Component,{...props,disabled:isDisabled,variant:isDisabled?SUBMIT_CONFIG.disabledVariant:props.variant,style:{...props.style,cursor:isDisabled?\"not-allowed\":\"pointer\"}});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withCharacterLength\":{\"type\":\"reactHoc\",\"name\":\"withCharacterLength\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withFormValidation\":{\"type\":\"reactHoc\",\"name\":\"withFormValidation\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./InputLengthOverride.map"],"mappings":"2HAKsX,SAAgB,EAAoB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,MAAM,EAAU,SAAS,EAAa,OAAO,EAAW,GAAG,GAAM,EACrf,EAAa,EAAM,OAAO,SAAS,EAAM,YAAY,QACvD,EAAmB,EAAO,UAAa,IAAc,EAAmB,EAAO,kBAAkB,EAAE,EAAO,gBAAgB,IAAM,EAAU,EAAO,UAAgB,EAAU,EAAyB,EAAY,EAAO,YAAkB,EAAgB,EAAO,gBAAsB,EAAkB,EAAO,mBAC9S,CAAC,GAASA,MAAa,SAAS,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAM,CAAC,EAAM,GAAUA,EAAS,GAAW,GAAG,CAAM,CAAC,EAAM,GAAUA,EAAS,GAAG,CAAM,CAAC,EAAQ,GAAYA,EAAS,GAAM,CAAC,MAAc,CAAI,IAAY,IAAA,IAAW,EAAS,EAAU,EAAI,CAAC,EAAU,CAAC,CAAC,UAC7Q,CAAC,EAAgB,OAAO,OAAO,EAAQ,CAAC,EAAgB,iBAAiB,EAAK,CAAC,EAAQ,CAAC,CAAC,IAAM,GAAgB,EAAI,EAAU,KAAO,CAAC,IAAM,EAAO,EAAI,OAAW,EAAS,GAAU,EAAS,GACvM,GAAG,GAAc,EAAO,GAAoD,CAAhC,6BAA4C,KAAK,EAAI,CAA2I,OAAtI,IAAW,EAAS,qCAAqC,EAAS,EAAS,EAAE,EAAS,GAAK,EAAgB,SAAS,EAAQ,EAAS,CAAO,CAAC,EACnP,GAAG,CAAC,GAAc,EAAO,gCAAgC,EAAO,EAAE,CAElE,GAAG,CADiB,oCACF,KAAK,EAAI,CAAgI,OAA3H,IAA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