df-forms-preview-react
Version:
A comprehensive React form preview component library with form controls, validation, and responsive design
23 lines • 120 kB
JavaScript
"use strict";var e=require("react"),t=require("react-i18next");require("react-dom");var r,i={exports:{}},a={};var n,o={};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/"production"===process.env.NODE_ENV?i.exports=function(){if(r)return a;r=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function i(t,r,i){var a=null;if(void 0!==i&&(a=""+i),void 0!==r.key&&(a=""+r.key),"key"in r)for(var n in i={},r)"key"!==n&&(i[n]=r[n]);else i=r;return r=i.ref,{$$typeof:e,type:t,key:a,ref:void 0!==r?r:null,props:i}}return a.Fragment=t,a.jsx=i,a.jsxs=i,a}():i.exports=(n||(n=1,"production"!==process.env.NODE_ENV&&function(){function t(e){if(null==e)return null;if("function"==typeof e)return e.$$typeof===S?null:e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case b:return"Fragment";case g:return"Profiler";case h:return"StrictMode";case j:return"Suspense";case C:return"SuspenseList";case k:return"Activity"}if("object"==typeof e)switch("number"==typeof e.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case f:return"Portal";case x:return e.displayName||"Context";case v:return(e._context.displayName||"Context")+".Consumer";case y:var r=e.render;return(e=e.displayName)||(e=""!==(e=r.displayName||r.name||"")?"ForwardRef("+e+")":"ForwardRef"),e;case w:return null!==(r=e.displayName||null)?r:t(e.type)||"Memo";case N:r=e._payload,e=e._init;try{return t(e(r))}catch(e){}}return null}function r(e){return""+e}function i(e){try{r(e);var t=!1}catch(e){t=!0}if(t){var i=(t=console).error,a="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",a),r(e)}}function a(e){if(e===b)return"<>";if("object"==typeof e&&null!==e&&e.$$typeof===N)return"<...>";try{var r=t(e);return r?"<"+r+">":"<...>"}catch(e){return"<...>"}}function n(){return Error("react-stack-top-frame")}function s(){var e=t(this.type);return R[e]||(R[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(e=this.props.ref)?e:null}function l(e,r,a,n,o,l){var d,m=r.children;if(void 0!==m)if(n)if(D(m)){for(n=0;n<m.length;n++)c(m[n]);Object.freeze&&Object.freeze(m)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else c(m);if($.call(r,"key")){m=t(e);var f=Object.keys(r).filter(function(e){return"key"!==e});n=0<f.length?"{key: someKey, "+f.join(": ..., ")+": ...}":"{key: someKey}",L[m+n]||(f=0<f.length?"{"+f.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',n,m,f,m),L[m+n]=!0)}if(m=null,void 0!==a&&(i(a),m=""+a),function(e){if($.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(i(r.key),m=""+r.key),"key"in r)for(var b in a={},r)"key"!==b&&(a[b]=r[b]);else a=r;return m&&function(e,t){function r(){u||(u=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(a,"function"==typeof e?e.displayName||e.name||"Unknown":e),function(e,t,r,i,a,n){var o=r.ref;return e={$$typeof:p,type:e,key:t,props:r,_owner:i},null!==(void 0!==o?o:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:s}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:n}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(e,m,a,null===(d=E.A)?null:d.getOwner(),o,l)}function c(e){d(e)?e._store&&(e._store.validated=1):"object"==typeof e&&null!==e&&e.$$typeof===N&&("fulfilled"===e._payload.status?d(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function d(e){return"object"==typeof e&&null!==e&&e.$$typeof===p}var u,m=e,p=Symbol.for("react.transitional.element"),f=Symbol.for("react.portal"),b=Symbol.for("react.fragment"),h=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),x=Symbol.for("react.context"),y=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),C=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),N=Symbol.for("react.lazy"),k=Symbol.for("react.activity"),S=Symbol.for("react.client.reference"),E=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,$=Object.prototype.hasOwnProperty,D=Array.isArray,V=console.createTask?console.createTask:function(){return null},R={},F=(m={react_stack_bottom_frame:function(e){return e()}}).react_stack_bottom_frame.bind(m,n)(),I=V(a(n)),L={};o.Fragment=b,o.jsx=function(e,t,r){var i=1e4>E.recentlyCreatedOwnerStacks++;return l(e,t,r,!1,i?Error("react-stack-top-frame"):F,i?V(a(e)):I)},o.jsxs=function(e,t,r){var i=1e4>E.recentlyCreatedOwnerStacks++;return l(e,t,r,!0,i?Error("react-stack-top-frame"):F,i?V(a(e)):I)}}()),o);var s=i.exports;const l=({validationErrors:e,fieldId:t,touchedFields:r,formSubmitted:i,properties:a,localValidation:n,isTouched:o,mode:l})=>{const c=e=>{const t=a.basic.label||"This field",r=a.validation.customValidationMessage;if(r)return r;const i=a.name||"",n="date-picker"===i||"datetime-picker"===i?a.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"):null;switch(e){case"required":return`${t} is required`;case"invalidDate":return"time"===n?"Please select a valid time":"datetime"===n?"Please select a valid date and time":"date"===n?"Please select a valid date":`${t} is invalid`;case"minLength":return`${t} must be at least ${a.validation.minLength} characters long`;case"maxLength":return`${t} must be no more than ${a.validation.maxLength} characters long`;case"min":return`${t} must be at least ${a.validation.min}`;case"max":return`${t} must be no more than ${a.validation.max}`;case"pattern":return`${t} format is invalid`;case"email":return`${t} must be a valid email address`;default:return`${t} is invalid`}},d=(()=>{if("test"!==l)return"";if(!(o||r[t]||i))return"";if(n&&n.isValid)return"";if(n&&!n.isValid&&Object.keys(n.errors).length>0){const e=Object.keys(n.errors);if(e.length>0){const t=e[0];return c(t)}}const s=e[t];if(s&&"string"==typeof s&&""!==s.trim()){const e=a.name||"";if(("date-picker"===e||"datetime-picker"===e)&&s.includes("valid date")){const t=a.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("time"===t)return"Please select a valid time";if("datetime"===t)return"Please select a valid date and time"}return s}return""})();return d?s.jsx("div",{className:"form-error-msg",children:d}):null},c=({id:t,properties:r,validationErrors:i={},formValue:a="",inputType:n="text",readonly:o=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="test",onValueChange:p,onBlur:f,onFocus:b,className:h="",hideLabel:g=!1})=>{const[v,x]=e.useState(a||r?.basic?.defaultValue||""),[y,j]=e.useState(!1),[C,w]=e.useState(!1),N=()=>{if(n)return n;const e=r?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},k=e.useCallback(e=>{const t=(()=>{const e={};if(r?.validation?.required&&(e.required=!0),"email"===N()&&(e.email=!0),"text"===N()){const t=r.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===N()){const t=r.validation;t?.min&&(e.min=t.min),t?.max&&(e.max=t.max),t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}return e})(),i={};let a=!0;if(!t.required||e&&""!==e.trim()||(i.required=!0,a=!1),t.email&&e&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)&&(i.email=!0,a=!1),t.minLength&&e&&e.length<t.minLength&&(i.minLength=!0,a=!1),t.maxLength&&e&&e.length>t.maxLength&&(i.maxLength=!0,a=!1),"number"===N()&&e){const r=parseFloat(e);isNaN(r)?(i.pattern=!0,a=!1):(void 0!==t.min&&r<t.min&&(i.min=!0,a=!1),void 0!==t.max&&r>t.max&&(i.max=!0,a=!1))}return{isValid:a,errors:i}},[r,N]),S=e.useCallback(e=>{if(x(e),p){const r=k(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors};p(i)}},[t,p,k]);e.useEffect(()=>{y&&(d[t]=!0)},[y,t,d]),e.useEffect(()=>{if("edit"===m){j(!1);x(r?.basic?.defaultValue||"")}else"test"===m&&(j(!1),x(""))},[m,r?.basic?.defaultValue]),e.useEffect(()=>{const e=a||r?.basic?.defaultValue||"";e===v||C||""===e&&""!==v.trim()?""===e&&v.trim():x(e)},[a,v,C,r?.basic?.defaultValue]),e.useEffect(()=>{u&&j(!0)},[u]),e.useEffect(()=>{"test"!==m&&x("")},[m]);const E=N(),$=c||o||r?.validation?.readonly;return s.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&s.jsxs("label",{htmlFor:t,className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"input-wrapper",children:[s.jsx("input",{type:E,id:t,value:v,onChange:e=>{const t=e.target.value;S(t)},onFocus:()=>{w(!0),b&&b()},onBlur:()=>{if(w(!1),j(!0),"test"===m&&p){const e=k(v),r={id:t,value:v,isValid:e.isValid,errors:e.errors};p(r)}f&&f()},placeholder:r.basic.placeholder,disabled:$,readOnly:o||r?.validation?.readonly,className:(()=>{const e="form-control";if("test"===m){const r=!k(v).isValid&&y,a=i[t]&&(y||u);return`${e} ${r||a?"is-invalid":""} ${h}`.trim()}return`${e} ${h}`.trim()})()}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:d,formSubmitted:u,properties:r,localValidation:k(v),isTouched:y,mode:m})]})]})},d=({id:t,properties:r,validationErrors:i={},formValue:a="",readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:f,className:b="",hideLabel:h=!1})=>{const[g,v]=e.useState(a),[x,y]=e.useState(!1),j=e.useCallback(e=>{const t={};let i=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1),r?.validation?.minLength&&e&&e.length<r.validation.minLength&&(t.minLength=!0,i=!1),r?.validation?.maxLength&&e&&e.length>r.validation.maxLength&&(t.maxLength=!0,i=!1),{isValid:i,errors:t}},[r]),C=e.useCallback(e=>{if(v(e),m){const r=j(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors};m(i)}},[t,m,j]);e.useEffect(()=>{x&&(c[t]=!0)},[x,t,c]),e.useEffect(()=>{""===g&&""!==a&&v(a)},[a]),e.useEffect(()=>{d&&y(!0)},[d]),e.useEffect(()=>{"test"!==u&&v("")},[u]);const w=o||n||r?.validation?.readonly,N=r?.validation?.rows||4;return s.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!h&&r.basic.label&&s.jsxs("label",{htmlFor:t,className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"input-wrapper",children:[s.jsx("textarea",{id:t,value:g,onChange:e=>{const t=e.target.value;C(t)},onFocus:()=>{f&&f()},onBlur:()=>{y(!0),p&&p()},placeholder:r.basic.placeholder,disabled:w,readOnly:n||r?.validation?.readonly,rows:N,className:`form-textarea ${!j(g).isValid&&x?"is-invalid":""} ${b}`.trim()}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(g),isTouched:x,mode:u})]})]})},u=({comment:t="",onSave:r,placeholder:i="Enter your reason...",className:a="",disabled:n=!1})=>{const[o,l]=e.useState(!0),[c,d]=e.useState(t),[u,m]=e.useState(!1);e.useEffect(()=>{d(t),m(!1)},[t]);const p=e.useCallback(e=>{const r=e.target.value;d(r),m(r!==t)},[t]),f=e.useCallback(()=>{u&&r&&!n&&(r(c),m(!1))},[u,r,c,n]),b=e.useCallback(()=>{},[]),h=e.useCallback(()=>{n||l(!o)},[o,n]);return s.jsxs("div",{className:`df-form-comments ${a}`,children:[s.jsxs("div",{className:"df-form-comments__header",children:[s.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),s.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:h,"aria-expanded":o,"aria-label":"Toggle comments section",disabled:n,children:o?s.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):s.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),s.jsx("div",{className:"df-form-comments__content "+(o?"df-form-comments__content--expanded":""),children:s.jsx("div",{className:"df-form-comments__input-container",children:s.jsx("div",{className:"df-form-comments__input-line",children:s.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:c,onChange:p,onBlur:f,onFocus:b,placeholder:i,disabled:n})})})})]})},m=({id:t,properties:r,validationErrors:i={},formValue:a="",readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:m="preview",onValueChange:p,onBlur:f,onFocus:b,className:h="",hideLabel:g=!1,showCommentsInPreview:v=!1})=>{const[x,y]=e.useState(a),[j,C]=e.useState(!1),[w,N]=e.useState(""),[k,S]=e.useState(!1),E=r?.validation?.multiple||!1;e.useEffect(()=>{"preview"===m&&v&&r?.basic?.comments&&N(r.basic.comments)},[m,v,r]);const $=e.useCallback(e=>{const t={};let i=!0;return r?.validation?.required&&(E?Array.isArray(e)&&0!==e.length||(t.required=!0,i=!1):(!e||"string"==typeof e&&""===e.trim())&&(t.required=!0,i=!1)),{isValid:i,errors:t}},[r,E]),D=e.useCallback(e=>{if(y(e),p){const r=$(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors,comments:w};p(i)}},[t,p,$,w]),V=e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t},R=()=>E?Array.isArray(x)&&x.some(e=>V(e)):"string"==typeof x&&V(x);e.useEffect(()=>{j&&(c[t]=!0)},[j,t,c]),e.useEffect(()=>{JSON.stringify(a)!==JSON.stringify(x)&&y(a)},[a,x]),e.useEffect(()=>{d&&C(!0)},[d]);const F=o||n||r?.validation?.readonly;return s.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&s.jsxs("label",{htmlFor:t,className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"input-wrapper",children:[s.jsxs("select",{id:t,value:x,onChange:e=>{if(E){const t=Array.from(e.target.selectedOptions,e=>e.value);D(t)}else D(e.target.value)},onFocus:()=>{b&&b()},onBlur:()=>{C(!0),f&&f()},disabled:F,multiple:E,className:`form-select ${!$(x).isValid&&j?"is-invalid":""} ${h}`.trim(),children:[!E&&s.jsx("option",{value:"",children:r.basic.placeholder||"Select an option"}),(r.options||[]).map((e,t)=>s.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:$(x),isTouched:j,mode:m}),(!F||"preview"===m&&v)&&s.jsxs(s.Fragment,{children:[(!("preview"!==m||!v||!w)||R()&&!k&&!!w)&&s.jsx("div",{onClick:"preview"===m?void 0:()=>{"preview"!==m&&S(!k)},style:{cursor:"preview"===m?"default":"pointer"},children:s.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",w]})}),(()=>{if("preview"===m)return!1;const e=R(),t=!w||""===w.trim();return e&&(k||t)})()&&s.jsx(u,{comment:w,onSave:e=>{if(N(e),S(!1),p){const r=$(x),i={id:t,value:x,isValid:r.isValid,errors:r.errors,comments:e};p(i)}},placeholder:"Enter your reason...",disabled:F})]})]})]})},p=({id:t,properties:r,validationErrors:i={},formValue:a=[],readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:m="preview",onValueChange:p,onBlur:f,onFocus:b,className:h="",hideLabel:g=!1,showCommentsInPreview:v=!1})=>{const[x,y]=e.useState(!1),[j,C]=e.useState(""),[w,N]=e.useState(!1),k=Array.isArray(a)?a:[];e.useEffect(()=>{"preview"===m&&v&&r?.basic?.comments&&C(r.basic.comments)},[m,v,r]);const S=e.useCallback(e=>{const t={};let i=!0;return r?.validation?.required&&0===e.length&&(t.required=!0,i=!1),{isValid:i,errors:t}},[r]),E=e.useCallback(e=>{if(p){const r=S(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors,comments:j};p(i)}},[t,p,S,j,k]),$=()=>k.some(e=>(e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t})(e)),D=(e,t)=>{let r;r=t?[...k,e]:k.filter(t=>t!==e),E(r)},V=()=>{b&&b()},R=()=>{y(!0),f&&f()};e.useEffect(()=>{x&&(c[t]=!0)},[x,t,c]),e.useEffect(()=>{},[a,t,k]),e.useEffect(()=>{d&&y(!0)},[d]);const F=o||n||r?.validation?.readonly;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`form-group checkbox-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${r?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${h}`,children:!g&&r.basic.label?s.jsxs(s.Fragment,{children:[s.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"input-wrapper",children:[s.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((e,r)=>s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"checkbox",id:`${t}-${r}`,name:t,value:e.value,checked:k.includes(e.value),onChange:t=>{D(e.value,t.target.checked)},onFocus:V,onBlur:R,disabled:F||e.disabled,className:"form-check-input"}),s.jsx("label",{htmlFor:`${t}-${r}`,className:"form-check-label",children:e.label})]},r))}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:S(k),isTouched:x,mode:m})]})]}):s.jsxs("div",{className:"input-wrapper",children:[s.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((e,r)=>s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"checkbox",id:`${t}-${r}`,name:t,value:e.value,checked:k.includes(e.value),onChange:t=>{D(e.value,t.target.checked)},onFocus:V,onBlur:R,disabled:F||e.disabled,className:"form-check-input"}),s.jsx("label",{htmlFor:`${t}-${r}`,className:"form-check-label",children:e.label})]},r))}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:S(k),isTouched:x,mode:m})]})}),(!F||"preview"===m&&v)&&s.jsxs(s.Fragment,{children:[(!("preview"!==m||!v||!j)||$()&&!w&&!!j)&&s.jsx("div",{onClick:"preview"===m?void 0:()=>{"preview"!==m&&N(!w)},style:{cursor:"preview"===m?"default":"pointer"},children:s.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",j]})}),(()=>{if("preview"===m)return!1;const e=$(),t=!j||""===j.trim();return e&&(w||t)})()&&s.jsx(u,{comment:j,onSave:e=>{if(C(e),N(!1),p){const r=S(k),i={id:t,value:k,isValid:r.isValid,errors:r.errors,comments:e};p(i)}},placeholder:"Enter your reason...",disabled:F})]})]})},f=({id:t,properties:r,validationErrors:i={},formValue:a="",readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:m="preview",onValueChange:p,onBlur:f,onFocus:b,className:h="",hideLabel:g=!1,showCommentsInPreview:v=!1})=>{const[x,y]=e.useState(a),[j,C]=e.useState(!1),[w,N]=e.useState(""),[k,S]=e.useState(!1);e.useEffect(()=>{"preview"===m&&v&&r?.basic?.comments&&N(r.basic.comments)},[m,v,r]);const E=e.useCallback(e=>{const t={};let i=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1),{isValid:i,errors:t}},[r]),$=e.useCallback(e=>{if(y(e),p){const r=E(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors,comments:w};p(i)}},[t,p,E,w]),D=()=>(e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t})(x),V=e=>{$(e)},R=()=>{b&&b()},F=()=>{C(!0),f&&f()};e.useEffect(()=>{j&&(c[t]=!0)},[j,t,c]),e.useEffect(()=>{a!==x&&y(a)},[a,x]),e.useEffect(()=>{d&&C(!0)},[d]);const I=o||n||r?.validation?.readonly;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`form-group radio-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${r?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${h}`,children:!g&&r.basic.label?s.jsxs(s.Fragment,{children:[s.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"input-wrapper",children:[s.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((e,r)=>s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"radio",id:`${t}-${r}`,name:t,value:e.value,checked:x===e.value,onChange:()=>V(e.value),onFocus:R,onBlur:F,disabled:I||e.disabled,className:"form-check-input"}),s.jsx("label",{htmlFor:`${t}-${r}`,className:"form-check-label",children:e.label})]},r))}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:E(x),isTouched:j,mode:m})]})]}):s.jsxs("div",{className:"input-wrapper",children:[s.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((e,r)=>s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"radio",id:`${t}-${r}`,name:t,value:e.value,checked:x===e.value,onChange:()=>V(e.value),onFocus:R,onBlur:F,disabled:I||e.disabled,className:"form-check-input"}),s.jsx("label",{htmlFor:`${t}-${r}`,className:"form-check-label",children:e.label})]},r))}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:E(x),isTouched:j,mode:m})]})}),(!I||"preview"===m&&v)&&s.jsxs(s.Fragment,{children:[(!("preview"!==m||!v||!w)||D()&&!k&&!!w)&&s.jsx("div",{onClick:"preview"===m?void 0:()=>{"preview"!==m&&S(!k)},style:{cursor:"preview"===m?"default":"pointer"},children:s.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",w]})}),(()=>{if("preview"===m)return!1;const e=D(),t=!w||""===w.trim();return e&&(k||t)})()&&s.jsx(u,{comment:w,onSave:e=>{if(N(e),S(!1),p){const r=E(x),i={id:t,value:x,isValid:r.isValid,errors:r.errors,comments:e};p(i)}},placeholder:"Enter your reason...",disabled:I})]})]})},b=({id:t,properties:r,validationErrors:i={},formValue:a="",readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:m="preview",onValueChange:p,onBlur:f,onFocus:b,className:h="",hideLabel:g=!1,showCommentsInPreview:v=!1})=>{const[x,y]=e.useState(a),[j,C]=e.useState(!1),[w,N]=e.useState(""),[k,S]=e.useState(!1);e.useEffect(()=>{"preview"===m&&v&&r?.basic?.comments&&N(r.basic.comments)},[m,v,r]);const E=e.useCallback(e=>{const t={};let i=!0;!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1);const a=r?.options?.find(t=>t.value===e);return!(a&&F(a.value))||w&&""!==w.trim()||(t.commentRequired=!0,i=!1),{isValid:i,errors:t}},[r,w]),$=e.useCallback(e=>{if(y(e),C(!0),p){const r=E(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors,comments:w};p(i)}},[t,p,E,w]),D=()=>{b&&b()},V=()=>{C(!0),f&&f()};e.useEffect(()=>{j&&(c[t]=!0)},[j,t,c]),e.useEffect(()=>{a!==x&&(y(a),"test"===m&&(N(""),S(!1)))},[a,x,m]),e.useEffect(()=>{d&&C(!0)},[d]),e.useEffect(()=>{"edit"===m&&(N(""),S(!1))},[m]),e.useEffect(()=>{const e=r?.options?.find(e=>e.value===x),t=e&&F(e.value);t&&!w?S(!0):t||S(!1)},[x,r?.options,w]);const R=()=>r?.basic?.inlineLayout?"inline-layout":"grid-layout",F=e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t},I=()=>{const e=r?.options?.find(e=>e.value===x);return!!e&&F(e.value)},L=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},M=e=>"pass"===L(e)?"✓":"×",T=o||n||r?.validation?.readonly;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`form-group segment-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${h}`,children:!g&&r.basic.label?s.jsxs(s.Fragment,{children:[s.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsx("div",{className:"form-segment-wrapper",children:s.jsx("div",{className:`form-segment-container ${R()}`,children:(r.options||[]).map((e,r)=>{const i=x===e.value;return s.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[s.jsx("input",{type:"radio",id:`${t}_option_${r}`,name:t,value:e.value,checked:i,onChange:()=>!T&&!e.disabled&&$(e.value),onFocus:D,onBlur:V,disabled:T||e.disabled,className:"form-segment-radio"}),s.jsxs("label",{htmlFor:`${t}_option_${r}`,className:"segment-button-label "+("pass"===L(e.value)?"pass-button":"fail-button"),children:[s.jsx("span",{className:"segment-icon",children:M(e.value)}),s.jsx("span",{className:"segment-text",children:e.value})]})]},r)})})})]}):s.jsx("div",{className:"form-segment-wrapper",children:s.jsx("div",{className:`form-segment-container ${R()}`,children:(r.options||[]).map((e,r)=>{const i=x===e.value;return s.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[s.jsx("input",{type:"radio",id:`${t}_option_${r}`,name:t,value:e.value,checked:i,onChange:()=>!T&&!e.disabled&&$(e.value),onFocus:D,onBlur:V,disabled:T||e.disabled,className:"form-segment-radio"}),s.jsxs("label",{htmlFor:`${t}_option_${r}`,className:"segment-button-label "+("pass"===L(e.value)?"pass-button":"fail-button"),children:[s.jsx("span",{className:"segment-icon",children:M(e.value)}),s.jsx("span",{className:"segment-text",children:e.value})]})]},r)})})})}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:{isValid:E(x).isValid,errors:Object.fromEntries(Object.entries(E(x).errors).filter(([e])=>"commentRequired"!==e))},isTouched:j,mode:m}),(!T||"preview"===m&&v)&&s.jsxs(s.Fragment,{children:[(()=>{if("preview"===m&&v&&w)return!0;return I()&&!k&&!!w})()&&s.jsx("div",{onClick:"preview"===m?void 0:()=>{"preview"!==m&&S(!k)},style:{cursor:"preview"===m?"default":"pointer"},children:s.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",w]})}),(()=>{if("preview"===m)return!1;const e=I(),t=!w||""===w.trim();return e&&(k||t)})()&&s.jsx(u,{comment:w,onSave:e=>{N(e),S(!1);const r=E(x);if(p){const i={id:t,value:x,isValid:r.isValid,errors:r.errors,comments:e};p(i)}},placeholder:"Enter your reason...",disabled:T}),(()=>{if("preview"===m)return!1;return!I()&&Boolean(w&&""!==w.trim())})()&&s.jsx("div",{children:s.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",w]})}),"preview"!==m&&I()&&I()&&!w&&j&&s.jsx("div",{children:s.jsx("label",{className:"form-label notes-label-text error-message no-border",children:"Notes are required"})})]})]})},h=({id:t,properties:r,validationErrors:i={},formValue:a="",readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:f,className:b="",hideLabel:h=!1})=>{const[g,v]=e.useState(a),[x,y]=e.useState(!1),[j,C]=e.useState(!1),w=e.useCallback(e=>{const t={};let i=!0;const a=r.name||"",n=r.basic?.dateTimeMode||("datetime-picker"===a?"datetime":"date"),o=e?String(e).trim():"";if(r?.validation?.required&&(!o||""===o))return t.required=!0,i=!1,{isValid:i,errors:t};if(o&&""!==o)if("time"===n){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(o))return t.invalidDate=!0,i=!1,{isValid:i,errors:t}}else if("datetime"===n){const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,i=!1,{isValid:i,errors:t};if(r?.validation?.minDate){const a=new Date(r.validation.minDate);e<a&&(t.minDate=!0,t.minDateMessage=`Date and time must be on or after ${a.toLocaleDateString()}`,i=!1)}if(r?.validation?.maxDate){const a=new Date(r.validation.maxDate);e>a&&(t.maxDate=!0,t.maxDateMessage=`Date and time must be on or before ${a.toLocaleDateString()}`,i=!1)}}else{const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,i=!1,{isValid:i,errors:t};if(r?.validation?.minDate){const a=new Date(r.validation.minDate);e<a&&(t.minDate=!0,t.minDateMessage=`Date must be on or after ${a.toLocaleDateString()}`,i=!1)}if(r?.validation?.maxDate){const a=new Date(r.validation.maxDate);e>a&&(t.maxDate=!0,t.maxDateMessage=`Date must be on or before ${a.toLocaleDateString()}`,i=!1)}}return{isValid:i,errors:t}},[r]),N=e.useCallback(e=>{if(v(e),m){const r=w(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors};m(i)}},[t,m,w]);e.useEffect(()=>{x&&(c[t]=!0)},[x,t,c]),e.useEffect(()=>{a===g||j||v(a)},[a,g,j]),e.useEffect(()=>{d&&y(!0)},[d]);const k=o||n||r?.validation?.readonly,S=r.name||"",E=r.basic?.dateTimeMode||("datetime-picker"===S?"datetime":"date"),$=(()=>{switch(E){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return s.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!h&&r.basic.label&&s.jsxs("label",{htmlFor:t,className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"input-wrapper",children:[s.jsx("input",{type:$,id:t,value:g,onChange:e=>{const t=e.target.value;N(t)},onFocus:()=>{C(!0),f&&f()},onBlur:()=>{if(C(!1),y(!0),m){const e=w(g),r={id:t,value:g,isValid:e.isValid,errors:e.errors};m(r)}p&&p()},disabled:k,readOnly:n||r?.validation?.readonly,min:r?.validation?.minDate,max:r?.validation?.maxDate,className:`form-date ${!w(g).isValid&&x?"is-invalid":""} ${b}`.trim()}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:w(g),isTouched:x,mode:u})]})]})},g=({id:t,properties:r,validationErrors:i={},formValue:a="",readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:f,className:b="",hideLabel:h=!1})=>{const g=e.useRef(null),[v,x]=e.useState(!1),[y,j]=e.useState(!1),[C,w]=e.useState(a),[N,k]=e.useState(!1),S=e.useCallback(e=>{const t={};let i=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1),{isValid:i,errors:t}},[r]),E=e.useCallback(e=>{if(w(e),m){const r=S(e),i={id:t,value:e,isValid:r.isValid,errors:r.errors};m(i)}},[t,m,S]),$=e.useCallback(()=>{const e=document.documentElement.classList.contains("dark")||"dark"===document.documentElement.getAttribute("data-theme");let t=getComputedStyle(document.documentElement).getPropertyValue("--df-color-fb-input-bg").trim();t||(t=e?"#2c2e34":"#ffffff");return{strokeColor:e?"#ffffff":"#000000",backgroundColor:t}},[]),D=e.useCallback(e=>{if(!e)return;const r=g.current;if(!r)return;const i=r.getContext("2d");if(!i)return;const a=new Image;a.onload=()=>{i.clearRect(0,0,r.width,r.height);const e=$();i.fillStyle=e.backgroundColor,i.fillRect(0,0,r.width,r.height);const t=r.width/r.height,n=a.width/a.height;let o=r.width,s=r.height,l=0,c=0;n>t?(s=r.width/n,c=(r.height-s)/2):(o=r.height*n,l=(r.width-o)/2),i.drawImage(a,l,c,o,s)},a.onerror=r=>{console.error("DfFormSignature: error loading image",{id:t,error:r,dataURL:e.substring(0,50)+"..."})},a.src=e},[$,t]),V=e.useCallback(()=>{const e=g.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const r=e.getBoundingClientRect();e.width=r.width,e.height=r.height,e.style.width=r.width+"px",e.style.height=r.height+"px";const i=$();t.strokeStyle=i.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?D(C):(t.fillStyle=i.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,$,D]),R=e.useCallback(()=>{setTimeout(()=>{V()},100)},[V]);e.useEffect(()=>{const e=()=>{R()},t=new MutationObserver(e=>{e.forEach(e=>{if("attributes"===e.type&&"class"===e.attributeName){const t=e.target;t.classList.contains("form-canvas-container")&&(t.classList.contains("mobile-view")||t.classList.contains("tablet-view")||t.classList.contains("desktop-view"))&&R()}})});return t.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[R]);const F=e.useCallback(e=>{const t=g.current;if(!t)return{x:0,y:0};const r=t.getBoundingClientRect(),i=t.width/r.width,a=t.height/r.height,n=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,o=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(n-r.left)*i,y:(o-r.top)*a}},[]),I=e=>{if(n||o||r?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),x(!0),j(!0);const t=g.current;if(!t)return;const i=t.getContext("2d");if(!i)return;const{x:a,y:s}=F(e),l=$();i.strokeStyle=l.strokeColor,i.lineWidth=2,i.lineCap="round",i.lineJoin="round",i.beginPath(),i.moveTo(a,s)},L=e=>{if(!v)return;e.preventDefault(),e.stopPropagation();const t=g.current;if(!t)return;const r=t.getContext("2d");if(!r)return;const{x:i,y:a}=F(e);r.lineTo(i,a),r.stroke()},M=()=>{if(!v)return;x(!1),k(!0);const e=g.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const r=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<r.length;e+=4){const t=r[e],i=r[e+1],a=r[e+2];if(r[e+3]>0&&(t<255||i<255||a<255))return!0}})(e);const t=e.toDataURL("image/png");w(t),E(t),setTimeout(()=>{k(!1)},100)}else k(!1)},T=e.useCallback(()=>{const e=g.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const r=$();if(t.strokeStyle=r.strokeColor,C){const i=C,a=e.getBoundingClientRect();t.fillStyle=r.backgroundColor,t.fillRect(0,0,a.width,a.height),i&&D(i)}else{const i=e.getBoundingClientRect();t.fillStyle=r.backgroundColor,t.fillRect(0,0,i.width,i.height)}},[$,C,D]);e.useEffect(()=>{const e=new MutationObserver(e=>{e.forEach(e=>{"attributes"!==e.type||"class"!==e.attributeName&&"data-theme"!==e.attributeName||T()})});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{e.disconnect()}},[T]);e.useEffect(()=>{y&&(c[t]=!0)},[y,t,c]),e.useEffect(()=>{if(!(a===C||v||N||""!==C&&""===a)){if(a===C)return;w(a),a&&D(a)}},[a,C,v,N]),e.useEffect(()=>{d&&j(!0)},[d]),e.useEffect(()=>{if("test"!==u){w("");const e=g.current;if(e){const t=e.getContext("2d");if(t){const r=e.getBoundingClientRect();e.width=r.width,e.height=r.height;const i=$();t.fillStyle=i.backgroundColor,t.fillRect(0,0,r.width,r.height)}}}},[u]),e.useEffect(()=>{V()},[u]);const A=o||n||r?.validation?.readonly;return s.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!h&&r.basic.label&&s.jsxs("label",{htmlFor:t,className:"form-label",children:[r.basic.label,r.validation.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"input-wrapper",children:[s.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[s.jsx("canvas",{ref:g,id:t,className:`form-signature ${!S(C).isValid&&y?"is-invalid":""} ${b}`.trim(),onMouseDown:I,onMouseMove:L,onMouseUp:M,onMouseLeave:M,onTouchStart:I,onTouchMove:L,onTouchEnd:M,onFocus:()=>{f&&f()},onBlur:()=>{p&&p()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:A?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!A&&s.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=g.current;if(!t)return;const r=t.getBoundingClientRect();t.width=r.width,t.height=r.height;const i=t.getContext("2d");if(!i)return;const a=$();i.fillStyle=a.backgroundColor,i.fillRect(0,0,r.width,r.height),i.strokeStyle=a.strokeColor,i.lineWidth=2,i.lineCap="round",i.lineJoin="round",w(""),E("")})(e),className:"clear-signature-btn",style:{position:"absolute",bottom:"8px",right:"8px",padding:"4px 8px",backgroundColor:"var(--df-color-error-primary)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"0.75rem",fontWeight:"500",zIndex:10,transition:"all 0.2s ease",minWidth:"60px",minHeight:"28px"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-dark, #dc2626)",e.currentTarget.style.transform="scale(1.05)"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-primary)",e.currentTarget.style.transform="scale(1)"},children:"Clear"})]}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:S(C),isTouched:y,mode:u})]})]})},v=({id:e,properties:t,className:r="",hideLabel:i=!1})=>{const a=t.styles?.level??t.basic.level??1,n=t.basic.label,o=()=>{const e={};return t?.styles?.fontSize&&(e.fontSize=t.styles.fontSize),t?.styles?.color&&(e.color=t.styles.color),e};return i?null:(()=>{const i={id:e,className:`form-heading h${a} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${r}`.trim(),style:o()};switch(a){case 1:default:return s.jsx("h1",{...i,children:n});case 2:return s.jsx("h2",{...i,children:n});case 3:return s.jsx("h3",{...i,children:n});case 4:return s.jsx("h4",{...i,children:n});case 5:return s.jsx("h5",{...i,children:n});case 6:return s.jsx("h6",{...i,children:n})}})()},x=({id:t,properties:r,validationErrors:i={},formValue:a=null,readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="test",onValueChange:m,onBlur:p,onFocus:f,className:b="",hideLabel:h=!1})=>{const[g,v]=e.useState([]),[x,y]=e.useState(!1),[j,C]=e.useState(!1),w=e.useRef(null),N=e.useCallback(e=>{if(!e)return[];const r=Array.isArray(e)?e:Array.from(e),i=[];return r.forEach((e,r)=>{let a,n,o=0,s="",l="";if(e instanceof File||e instanceof Blob){const t=e;if(o=t.size||0,s=t.type||"",l=t.name||`file-${r}`,n=t,s.startsWith("image/"))try{a=URL.createObjectURL(t)}catch(e){console.error("Error creating object URL:",e),a=void 0}}else if("string"==typeof e){const t=e;if(l=`file-${r}`,t.startsWith("data:")){const e=t.indexOf(";");s=e>5?t.substring(5,e):"application/octet-stream"}else{const e=t.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(e){s={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",zip:"application/zip",rar:"application/x-rar-compressed"}[e[1].toLowerCase()]||"application/octet-stream"}else s="application/octet-stream"}(t.startsWith("data:image")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("blob:"))&&(a=t),n=new File([],l,{type:s})}else{if(!e||"object"!=typeof e)return;{const t=e;if(l=t.name||t.fileName||`file-${r}`,o=t.size||t.fileSize||0,s=t.type||t.fileType||t.mimeType||"",t.url||t.path)a=t.url||t.path;else if(s.startsWith("image/")&&t.data){const e=t.data;a="string"==typeof e?e.startsWith("data:")?e:`data:${s};base64,${e}`:void 0}n=new File([],l,{type:s})}}i.push({file:n,id:`${t}-file-${r}`,size:o,type:s,name:l,preview:a})}),i},[t]),k=e.useCallback(()=>({isValid:!0,errors:{}}),[]),S=e.useCallback(e=>{if(n||o)return;const i=N(e),a=g.length>0?[...g,...i]:i,s=r?.validation?.maxFiles||1/0,l=a.slice(0,s);if(v(l),C(!0),m){const e=k(),r={id:t,value:l.map(e=>e.file),isValid:e.isValid,errors:e.errors};m(r)}},[g,r,n,o,m,k,N,t]),E=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]},$=e=>e.startsWith("image/")?"🖼️":e.startsWith("video/")?"🎥":e.startsWith("audio/")?"🎵":e.includes("pdf")?"📄":e.includes("word")||e.includes("document")?"📝":e.includes("excel")||e.includes("spreadsheet")?"📊":e.includes("zip")||e.includes("rar")?"📦":"📁";e.useEffect(()=>{j&&(c[t]=!0)},[j,t,c]),e.useEffect(()=>{("edit"===u||"test"===u)&&C(!1)},[u]),e.useEffect(()=>{const e=N(a);v(e)},[a,N]),e.useEffect(()=>{d&&C(!0)},[d]),e.useEffect(()=>()=>{g.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[g]);const D=()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"},V=o||n||r?.validation?.readonly,R=r?.validation?.multiple||!1,F=r?.validation?.accept||"*/*",I=r?.validation?.maxFiles||1/0,L=g.length<I&&(R||I>1),M="edit"===u,T="preview"===u||"test"===u,A=g.filter(e=>e.type.startsWith("image/")),z=g.filter(e=>!e.type.startsWith("image/")),O=A.length>0;return T&&O?s.jsxs("div",{className:`form-group ${D()}`,children:[!h&&s.jsxs("label",{htmlFor:t,className:"form-label",children:[r.basic?.label||"Attachments",r.validation?.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"file-upload-wrapper",children:[s.jsxs("div",{className:"file-image-display",children:[A.map(e=>s.jsxs("div",{className:"file-image-container",children:[e.preview&&s.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),s.jsxs("div",{className:"file-image-info",children:[s.jsx("div",{className:"file-name",title:e.name,children:e.name}),s.jsx("div",{className:"file-size",children:E(e.size)})]})]},e.id)),z.length>0&&s.jsxs("div",{className:"file-other-files",children:[s.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),z.map(e=>s.jsxs("div",{className:"file-item-minimal",children:[s.jsx("div",{className:"file-icon",children:$(e.type)}),s.jsxs("div",{className:"file-info",children:[s.jsx("div",{className:"file-name",title:e.name,children:e.name}),s.jsx("div",{className:"file-size",children:E(e.size)})]})]},e.id))]})]}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:k(),isTouched:j,mode:u})]})]}):s.jsxs("div",{className:`form-group ${D()}`,children:[!h&&s.jsxs("label",{htmlFor:t,className:"form-label",children:[r.basic?.label||"Attachments",r.validation?.required&&s.jsx("span",{className:"required-indicator",children:"*"})]}),s.jsxs("div",{className:"file-upload-wrapper",children:[s.jsxs("div",{className:`file-upload-area ${x?"drag-over":""} ${n?"readonly":""} ${o?"disabled":""} ${b}`.trim(),onDragOver:e=>{e.preventDefault(),n||o||y(!0)},onDragLeave:e=>{e.preventDefault(),y(!1)},onDrop:e=>{if(e.preventDefault(),y(!1),n||o)return;const t=e.dataTransfer.files;t.length>0&&S(t)},onClick:e=>{const t=e.target,r=null!==t.closest(".file-item"),i=null!==t.closest(".file-remove");!M||V||0!==g.length||r||i||w.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(C(!0),"test"===u&&m){const e=k(),r={id:t,value:g.map(e=>e.file),isValid:e.isValid,errors:e.errors};m(r)}p&&p()},tabIndex:V?-1:0,children:[s.jsx("input",{ref:w,type:"file",id:t,multiple:R,accept:F,onChange:e=>{const t=e.target.files;t&&t.length>0&&(S(t),e.target.value="")},disabled:V,style:{display:"none"}}),0===g.length?s.jsxs("div",{className:"upload-placeholder",onClick:e=>{e.stopPropagation(),M&&!V&&w.current?.click()},children:[s.jsx("div",{className:"upload-icon",children:"📁"}),s.jsx("div",{className:"upload-text",children:r.basic.placeholder&&s.jsx("p",{className:"upload-hint",children:r.basic.placeholder})})]}):s.jsx("div",{className:"file-list",children:g.map(e=>s.jsxs("div",{className:"file-item",children:[s.jsx("div",{className:"file-preview",children:e.preview?s.jsx("img",{src:e.preview,alt:e.name,className:"file-image"}):s.jsx("div",{className:"file-icon",children:$(e.type)})}),s.jsxs("div",{className:"file-info",children:[s.jsx("div",{className:"file-name",title:e.name,children:e.name}),s.jsx("div",{className:"file-size",children:E(e.size)})]}),M&&!V&&s.jsx("button",{type:"button",className:"file-remove",onClick:r=>{r.stopPropagation(),(e=>{if(n||o)return;const r=g.filter(t=>t.id!==e);if(v(r),C(!0),m){const e=k(),i={id:t,value:r.map(e=>e.file),isValid:e.isValid,errors:e.errors};m(i)}})(e.id)},"aria-label":`Remove ${e.name}`,children:"✕"})]},e.id))})]}),g.length>0&&L&&!V&&M&&s.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!V&&w.current&&M&&(w.current.value="",w.current.click())},"aria-label":"Add more files",children:[s.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M12 5v14M5 12h14"})}),s.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),s.jsx(l,{validationErrors:i,fieldId:t,touchedFields:c,formSubmitted:d,properties:r,localValidation:k(),isTouched:j,mode:u})]})]})},y=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,r)=>r?r.toUpperCase():t.toLowerCase()))(e);return t.charAt(0).toUpperCase()+t.slice(1)},j=(...e)=>e.filter((e,t,r)=>Boolean(e)&&""!==e.trim()&&r.indexOf(e)===t).join(" ").trim(),C=e=>{for(const t in e)if(t.startsWith("aria-")||"role"===t||"title"===t)return!0};
/**
* @license lucide-react v0.552.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/
var w={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};
/**
* @license lucide-react v0.552.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const N=e.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:i=2,absoluteStrokeWidth:a,className:n="",children:o,iconNode:s,...l},c)=>e.createElement("svg",{ref:c,...w,width:r,height:r,stroke:t,strokeWidth:a?24*Number(i)/Number(r):i,className:j("lucide",n),...!o&&!C(l)&&{"aria-hidden":"true"},...l},[...s.map(([t,r])=>e.createElement(t,r)),...Array.isArray(o)?o:[o]])),k=(t,r)=>{const i=e.forwardRef(({className:i,...a},n)=>{return e.createElement(N,{ref:n,iconNode:r,className:j(`lucide-${o=y(t),o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${t}`,i),...a});var o});return i.displayName=y(t),i},S=k("bold",[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]]),E=k("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]),$=k("chevron-right",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]),D=k("grid-3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]),V=k("grip-vertical",[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]),R=k("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]),F=k("italic",[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]]),I=k("list-ordered",[["path",{d:"M11 5h10",key:"1cz7ny"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 19h10",key:"11t30w"}],["path",{d:"M4 4h1v5",key:"10yrso"}],["path",{d:"M4 9h2",key:"r1h2o0"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02",key:"xtkcd5"}]]),L=k("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]),M=k("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]),T=k("map-pin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]),A=k("navigation",[["polygon",{points:"3 11 22 2 13 21 11 13 3 11",key:"1ltx0t"}]]),z=k("square-pen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]),O=k("table",[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]]),_=k("trash-2",[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]]),P=k("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),B=({id:t,properties:r,validationErrors:i={},formValue:a=null,readonly:n=!1,disabled:o=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="test",onValueChange:m,onBlur:p,onFocus:f,className:b="",hideLabel:h=!1})=>{const[g,v]=e.useState(a),[x,y]=e.useState(!1),[j,C]=e.useState(""),[w,N]=e.useState(!1),[k,S]=e.useState(!1),[E,$]=e.useState({lat:40.7128,lng:-74.006}),[D,V]=e.useState(null),[R,F]=e.useState(10),[I,L]=e.useState(""),[z,O]=e.useState(!1),_=e.useRef(null),[B,q]=e.useState(!1),[W,U]=e.useState(null),[H,J]=e.useState(!1);e.useEffect(()=>{a?(v(a),a.latitude&&a.longitude&&(V({lat:a.latitude,lng:a.longitude,isCurrentLocation:!1}),$({lat:a.latitude,lng:a.longitude}))):(v(null),V(null))},[a])