UNPKG

df-forms-preview-react

Version:

A comprehensive React form preview component library with form controls, validation, and responsive design

23 lines 118 kB
import e,{useState as t,useCallback as r,useEffect as i,useRef as n,forwardRef as a,createElement as o,useLayoutEffect as s,useMemo as l,createContext as d,useContext as c}from"react";import{useTranslation as u}from"react-i18next";import"react-dom";var p,m={exports:{}},h={};var f,b={}; /** * @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?m.exports=function(){if(p)return h;p=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(t,r,i){var n=null;if(void 0!==i&&(n=""+i),void 0!==r.key&&(n=""+r.key),"key"in r)for(var a in i={},r)"key"!==a&&(i[a]=r[a]);else i=r;return r=i.ref,{$$typeof:e,type:t,key:n,ref:void 0!==r?r:null,props:i}}return h.Fragment=t,h.jsx=r,h.jsxs=r,h}():m.exports=(f||(f=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 h:return"Fragment";case g:return"Profiler";case f:return"StrictMode";case j:return"Suspense";case w: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 m: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 N:return null!==(r=e.displayName||null)?r:t(e.type)||"Memo";case C: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,n="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.",n),r(e)}}function n(e){if(e===h)return"<>";if("object"==typeof e&&null!==e&&e.$$typeof===C)return"<...>";try{var r=t(e);return r?"<"+r+">":"<...>"}catch(e){return"<...>"}}function a(){return Error("react-stack-top-frame")}function o(){var e=t(this.type);return L[e]||(L[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 s(e,r,n,a,s,d){var u,m=r.children;if(void 0!==m)if(a)if(V(m)){for(a=0;a<m.length;a++)l(m[a]);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 l(m);if(D.call(r,"key")){m=t(e);var h=Object.keys(r).filter(function(e){return"key"!==e});a=0<h.length?"{key: someKey, "+h.join(": ..., ")+": ...}":"{key: someKey}",F[m+a]||(h=0<h.length?"{"+h.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} />',a,m,h,m),F[m+a]=!0)}if(m=null,void 0!==n&&(i(n),m=""+n),function(e){if(D.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 f in n={},r)"key"!==f&&(n[f]=r[f]);else n=r;return m&&function(e,t){function r(){c||(c=!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})}(n,"function"==typeof e?e.displayName||e.name||"Unknown":e),function(e,t,r,i,n,a){var s=r.ref;return e={$$typeof:p,type:e,key:t,props:r,_owner:i},null!==(void 0!==s?s:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:o}):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:n}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(e,m,n,null===(u=$.A)?null:u.getOwner(),s,d)}function l(e){d(e)?e._store&&(e._store.validated=1):"object"==typeof e&&null!==e&&e.$$typeof===C&&("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 c,u=e,p=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),f=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"),w=Symbol.for("react.suspense_list"),N=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),k=Symbol.for("react.activity"),S=Symbol.for("react.client.reference"),$=u.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,V=Array.isArray,I=console.createTask?console.createTask:function(){return null},L={},E=(u={react_stack_bottom_frame:function(e){return e()}}).react_stack_bottom_frame.bind(u,a)(),R=I(n(a)),F={};b.Fragment=h,b.jsx=function(e,t,r){var i=1e4>$.recentlyCreatedOwnerStacks++;return s(e,t,r,!1,i?Error("react-stack-top-frame"):E,i?I(n(e)):R)},b.jsxs=function(e,t,r){var i=1e4>$.recentlyCreatedOwnerStacks++;return s(e,t,r,!0,i?Error("react-stack-top-frame"):E,i?I(n(e)):R)}}()),b);var g=m.exports;const v=({validationErrors:e,fieldId:t,touchedFields:r,formSubmitted:i,properties:n,localValidation:a,isTouched:o,mode:s})=>{const l=e=>{const t=n.basic.label||"This field",r=n.validation.customValidationMessage;if(r)return r;const i=n.name||"",a="date-picker"===i||"datetime-picker"===i?n.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"):null;switch(e){case"required":return`${t} is required`;case"invalidDate":return"time"===a?"Please select a valid time":"datetime"===a?"Please select a valid date and time":"date"===a?"Please select a valid date":`${t} is invalid`;case"minLength":return`${t} must be at least ${n.validation.minLength} characters long`;case"maxLength":return`${t} must be no more than ${n.validation.maxLength} characters long`;case"min":return`${t} must be at least ${n.validation.min}`;case"max":return`${t} must be no more than ${n.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"!==s)return"";if(!(o||r[t]||i))return"";if(a&&a.isValid)return"";if(a&&!a.isValid&&Object.keys(a.errors).length>0){const e=Object.keys(a.errors);if(e.length>0){const t=e[0];return l(t)}}const d=e[t];if(d&&"string"==typeof d&&""!==d.trim()){const e=n.name||"";if(("date-picker"===e||"datetime-picker"===e)&&d.includes("valid date")){const t=n.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 d}return""})();return d?g.jsx("div",{className:"form-error-msg",children:d}):null},x=({id:e,properties:n,validationErrors:a={},formValue:o="",inputType:s="text",readonly:l=!1,disabled:d=!1,touchedFields:c={},formSubmitted:u=!1,mode:p="test",onValueChange:m,onBlur:h,onFocus:f,className:b="",hideLabel:x=!1})=>{const[y,j]=t(o||n?.basic?.defaultValue||""),[w,N]=t(!1),[C,k]=t(!1),S=()=>{if(s)return s;const e=n?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},$=r(e=>{const t=(()=>{const e={};if(n?.validation?.required&&(e.required=!0),"email"===S()&&(e.email=!0),"text"===S()){const t=n.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===S()){const t=n.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})(),r={};let i=!0;if(!t.required||e&&""!==e.trim()||(r.required=!0,i=!1),t.email&&e&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)&&(r.email=!0,i=!1),t.minLength&&e&&e.length<t.minLength&&(r.minLength=!0,i=!1),t.maxLength&&e&&e.length>t.maxLength&&(r.maxLength=!0,i=!1),"number"===S()&&e){const n=parseFloat(e);isNaN(n)?(r.pattern=!0,i=!1):(void 0!==t.min&&n<t.min&&(r.min=!0,i=!1),void 0!==t.max&&n>t.max&&(r.max=!0,i=!1))}return{isValid:i,errors:r}},[n,S]),D=r(t=>{if(j(t),m){const r=$(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors};m(i)}},[e,m,$]);i(()=>{w&&(c[e]=!0)},[w,e,c]),i(()=>{if("edit"===p){N(!1);j(n?.basic?.defaultValue||"")}else"test"===p&&(N(!1),j(""))},[p,n?.basic?.defaultValue]),i(()=>{const e=o||n?.basic?.defaultValue||"";e===y||C||""===e&&""!==y.trim()?""===e&&y.trim():j(e)},[o,y,C,n?.basic?.defaultValue]),i(()=>{u&&N(!0)},[u]),i(()=>{"test"!==p&&j("")},[p]);const V=S(),I=d||l||n?.validation?.readonly;return g.jsxs("div",{className:`form-group ${(()=>{const e=n?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!x&&n.basic.label&&g.jsxs("label",{htmlFor:e,className:"form-label",children:[n.basic.label,n.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"input-wrapper",children:[g.jsx("input",{type:V,id:e,value:y,onChange:e=>{const t=e.target.value;D(t)},onFocus:()=>{k(!0),f&&f()},onBlur:()=>{if(k(!1),N(!0),"test"===p&&m){const t=$(y),r={id:e,value:y,isValid:t.isValid,errors:t.errors};m(r)}h&&h()},placeholder:n.basic.placeholder,disabled:I,readOnly:l||n?.validation?.readonly,className:(()=>{const t="form-control";if("test"===p){const r=!$(y).isValid&&w,i=a[e]&&(w||u);return`${t} ${r||i?"is-invalid":""} ${b}`.trim()}return`${t} ${b}`.trim()})()}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:c,formSubmitted:u,properties:n,localValidation:$(y),isTouched:w,mode:p})]})]})},y=({id:e,properties:n,validationErrors:a={},formValue:o="",readonly:s=!1,disabled:l=!1,touchedFields:d={},formSubmitted:c=!1,mode:u="preview",onValueChange:p,onBlur:m,onFocus:h,className:f="",hideLabel:b=!1})=>{const[x,y]=t(o),[j,w]=t(!1),N=r(e=>{const t={};let r=!0;return!n?.validation?.required||e&&""!==e.trim()||(t.required=!0,r=!1),n?.validation?.minLength&&e&&e.length<n.validation.minLength&&(t.minLength=!0,r=!1),n?.validation?.maxLength&&e&&e.length>n.validation.maxLength&&(t.maxLength=!0,r=!1),{isValid:r,errors:t}},[n]),C=r(t=>{if(y(t),p){const r=N(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors};p(i)}},[e,p,N]);i(()=>{j&&(d[e]=!0)},[j,e,d]),i(()=>{""===x&&""!==o&&y(o)},[o]),i(()=>{c&&w(!0)},[c]),i(()=>{"test"!==u&&y("")},[u]);const k=l||s||n?.validation?.readonly,S=n?.validation?.rows||4;return g.jsxs("div",{className:`form-group ${(()=>{const e=n?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&n.basic.label&&g.jsxs("label",{htmlFor:e,className:"form-label",children:[n.basic.label,n.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"input-wrapper",children:[g.jsx("textarea",{id:e,value:x,onChange:e=>{const t=e.target.value;C(t)},onFocus:()=>{h&&h()},onBlur:()=>{w(!0),m&&m()},placeholder:n.basic.placeholder,disabled:k,readOnly:s||n?.validation?.readonly,rows:S,className:`form-textarea ${!N(x).isValid&&j?"is-invalid":""} ${f}`.trim()}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:N(x),isTouched:j,mode:u})]})]})},j=({comment:e="",onSave:n,placeholder:a="Enter your reason...",className:o="",disabled:s=!1})=>{const[l,d]=t(!0),[c,u]=t(e),[p,m]=t(!1);i(()=>{u(e),m(!1)},[e]);const h=r(t=>{const r=t.target.value;u(r),m(r!==e)},[e]),f=r(()=>{p&&n&&!s&&(n(c),m(!1))},[p,n,c,s]),b=r(()=>{},[]),v=r(()=>{s||d(!l)},[l,s]);return g.jsxs("div",{className:`df-form-comments ${o}`,children:[g.jsxs("div",{className:"df-form-comments__header",children:[g.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),g.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:v,"aria-expanded":l,"aria-label":"Toggle comments section",disabled:s,children:l?g.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):g.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),g.jsx("div",{className:"df-form-comments__content "+(l?"df-form-comments__content--expanded":""),children:g.jsx("div",{className:"df-form-comments__input-container",children:g.jsx("div",{className:"df-form-comments__input-line",children:g.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:c,onChange:h,onBlur:f,onFocus:b,placeholder:a,disabled:s})})})})]})},w=({id:e,properties:n,validationErrors:a={},formValue:o="",readonly:s=!1,disabled:l=!1,touchedFields:d={},formSubmitted:c=!1,mode:u="preview",onValueChange:p,onBlur:m,onFocus:h,className:f="",hideLabel:b=!1,showCommentsInPreview:x=!1})=>{const[y,w]=t(o),[N,C]=t(!1),[k,S]=t(""),[$,D]=t(!1),V=n?.validation?.multiple||!1;i(()=>{"preview"===u&&x&&n?.basic?.comments&&S(n.basic.comments)},[u,x,n]);const I=r(e=>{const t={};let r=!0;return n?.validation?.required&&(V?Array.isArray(e)&&0!==e.length||(t.required=!0,r=!1):(!e||"string"==typeof e&&""===e.trim())&&(t.required=!0,r=!1)),{isValid:r,errors:t}},[n,V]),L=r(t=>{if(w(t),p){const r=I(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors,comments:k};p(i)}},[e,p,I,k]),E=e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t},R=()=>V?Array.isArray(y)&&y.some(e=>E(e)):"string"==typeof y&&E(y);i(()=>{N&&(d[e]=!0)},[N,e,d]),i(()=>{JSON.stringify(o)!==JSON.stringify(y)&&w(o)},[o,y]),i(()=>{c&&C(!0)},[c]);const F=l||s||n?.validation?.readonly;return g.jsxs("div",{className:`form-group ${(()=>{const e=n?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&n.basic.label&&g.jsxs("label",{htmlFor:e,className:"form-label",children:[n.basic.label,n.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"input-wrapper",children:[g.jsxs("select",{id:e,value:y,onChange:e=>{if(V){const t=Array.from(e.target.selectedOptions,e=>e.value);L(t)}else L(e.target.value)},onFocus:()=>{h&&h()},onBlur:()=>{C(!0),m&&m()},disabled:F,multiple:V,className:`form-select ${!I(y).isValid&&N?"is-invalid":""} ${f}`.trim(),children:[!V&&g.jsx("option",{value:"",children:n.basic.placeholder||"Select an option"}),(n.options||[]).map((e,t)=>g.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:I(y),isTouched:N,mode:u}),(!F||"preview"===u&&x)&&g.jsxs(g.Fragment,{children:[(!("preview"!==u||!x||!k)||R()&&!$&&!!k)&&g.jsx("div",{onClick:"preview"===u?void 0:()=>{"preview"!==u&&D(!$)},style:{cursor:"preview"===u?"default":"pointer"},children:g.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",k]})}),(()=>{if("preview"===u)return!1;const e=R(),t=!k||""===k.trim();return e&&($||t)})()&&g.jsx(j,{comment:k,onSave:t=>{if(S(t),D(!1),p){const r=I(y),i={id:e,value:y,isValid:r.isValid,errors:r.errors,comments:t};p(i)}},placeholder:"Enter your reason...",disabled:F})]})]})]})},N=({id:e,properties:n,validationErrors:a={},formValue:o=[],readonly:s=!1,disabled:l=!1,touchedFields:d={},formSubmitted:c=!1,mode:u="preview",onValueChange:p,onBlur:m,onFocus:h,className:f="",hideLabel:b=!1,showCommentsInPreview:x=!1})=>{const[y,w]=t(!1),[N,C]=t(""),[k,S]=t(!1),$=Array.isArray(o)?o:[];i(()=>{"preview"===u&&x&&n?.basic?.comments&&C(n.basic.comments)},[u,x,n]);const D=r(e=>{const t={};let r=!0;return n?.validation?.required&&0===e.length&&(t.required=!0,r=!1),{isValid:r,errors:t}},[n]),V=r(t=>{if(p){const r=D(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors,comments:N};p(i)}},[e,p,D,N,$]),I=()=>$.some(e=>(e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t})(e)),L=(e,t)=>{let r;r=t?[...$,e]:$.filter(t=>t!==e),V(r)},E=()=>{h&&h()},R=()=>{w(!0),m&&m()};i(()=>{y&&(d[e]=!0)},[y,e,d]),i(()=>{},[o,e,$]),i(()=>{c&&w(!0)},[c]);const F=l||s||n?.validation?.readonly;return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:`form-group checkbox-group ${(()=>{const e=n?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${n?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!b&&n.basic.label?g.jsxs(g.Fragment,{children:[g.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"input-wrapper",children:[g.jsx("div",{className:"mt-2 "+(n?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((t,r)=>g.jsxs("div",{className:"form-check",children:[g.jsx("input",{type:"checkbox",id:`${e}-${r}`,name:e,value:t.value,checked:$.includes(t.value),onChange:e=>{L(t.value,e.target.checked)},onFocus:E,onBlur:R,disabled:F||t.disabled,className:"form-check-input"}),g.jsx("label",{htmlFor:`${e}-${r}`,className:"form-check-label",children:t.label})]},r))}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:D($),isTouched:y,mode:u})]})]}):g.jsxs("div",{className:"input-wrapper",children:[g.jsx("div",{className:"mt-2 "+(n?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((t,r)=>g.jsxs("div",{className:"form-check",children:[g.jsx("input",{type:"checkbox",id:`${e}-${r}`,name:e,value:t.value,checked:$.includes(t.value),onChange:e=>{L(t.value,e.target.checked)},onFocus:E,onBlur:R,disabled:F||t.disabled,className:"form-check-input"}),g.jsx("label",{htmlFor:`${e}-${r}`,className:"form-check-label",children:t.label})]},r))}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:D($),isTouched:y,mode:u})]})}),(!F||"preview"===u&&x)&&g.jsxs(g.Fragment,{children:[(!("preview"!==u||!x||!N)||I()&&!k&&!!N)&&g.jsx("div",{onClick:"preview"===u?void 0:()=>{"preview"!==u&&S(!k)},style:{cursor:"preview"===u?"default":"pointer"},children:g.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",N]})}),(()=>{if("preview"===u)return!1;const e=I(),t=!N||""===N.trim();return e&&(k||t)})()&&g.jsx(j,{comment:N,onSave:t=>{if(C(t),S(!1),p){const r=D($),i={id:e,value:$,isValid:r.isValid,errors:r.errors,comments:t};p(i)}},placeholder:"Enter your reason...",disabled:F})]})]})},C=({id:e,properties:n,validationErrors:a={},formValue:o="",readonly:s=!1,disabled:l=!1,touchedFields:d={},formSubmitted:c=!1,mode:u="preview",onValueChange:p,onBlur:m,onFocus:h,className:f="",hideLabel:b=!1,showCommentsInPreview:x=!1})=>{const[y,w]=t(o),[N,C]=t(!1),[k,S]=t(""),[$,D]=t(!1);i(()=>{"preview"===u&&x&&n?.basic?.comments&&S(n.basic.comments)},[u,x,n]);const V=r(e=>{const t={};let r=!0;return!n?.validation?.required||e&&""!==e.trim()||(t.required=!0,r=!1),{isValid:r,errors:t}},[n]),I=r(t=>{if(w(t),p){const r=V(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors,comments:k};p(i)}},[e,p,V,k]),L=()=>(e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t})(y),E=e=>{I(e)},R=()=>{h&&h()},F=()=>{C(!0),m&&m()};i(()=>{N&&(d[e]=!0)},[N,e,d]),i(()=>{o!==y&&w(o)},[o,y]),i(()=>{c&&C(!0)},[c]);const T=l||s||n?.validation?.readonly;return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:`form-group radio-group ${(()=>{const e=n?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${n?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!b&&n.basic.label?g.jsxs(g.Fragment,{children:[g.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"input-wrapper",children:[g.jsx("div",{className:"mt-2 "+(n?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((t,r)=>g.jsxs("div",{className:"form-check",children:[g.jsx("input",{type:"radio",id:`${e}-${r}`,name:e,value:t.value,checked:y===t.value,onChange:()=>E(t.value),onFocus:R,onBlur:F,disabled:T||t.disabled,className:"form-check-input"}),g.jsx("label",{htmlFor:`${e}-${r}`,className:"form-check-label",children:t.label})]},r))}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:V(y),isTouched:N,mode:u})]})]}):g.jsxs("div",{className:"input-wrapper",children:[g.jsx("div",{className:"mt-2 "+(n?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((t,r)=>g.jsxs("div",{className:"form-check",children:[g.jsx("input",{type:"radio",id:`${e}-${r}`,name:e,value:t.value,checked:y===t.value,onChange:()=>E(t.value),onFocus:R,onBlur:F,disabled:T||t.disabled,className:"form-check-input"}),g.jsx("label",{htmlFor:`${e}-${r}`,className:"form-check-label",children:t.label})]},r))}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:V(y),isTouched:N,mode:u})]})}),(!T||"preview"===u&&x)&&g.jsxs(g.Fragment,{children:[(!("preview"!==u||!x||!k)||L()&&!$&&!!k)&&g.jsx("div",{onClick:"preview"===u?void 0:()=>{"preview"!==u&&D(!$)},style:{cursor:"preview"===u?"default":"pointer"},children:g.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",k]})}),(()=>{if("preview"===u)return!1;const e=L(),t=!k||""===k.trim();return e&&($||t)})()&&g.jsx(j,{comment:k,onSave:t=>{if(S(t),D(!1),p){const r=V(y),i={id:e,value:y,isValid:r.isValid,errors:r.errors,comments:t};p(i)}},placeholder:"Enter your reason...",disabled:T})]})]})},k=({id:e,properties:n,validationErrors:a={},formValue:o="",readonly:s=!1,disabled:l=!1,touchedFields:d={},formSubmitted:c=!1,mode:u="preview",onValueChange:p,onBlur:m,onFocus:h,className:f="",hideLabel:b=!1,showCommentsInPreview:x=!1})=>{const[y,w]=t(o),[N,C]=t(!1),[k,S]=t(""),[$,D]=t(!1);i(()=>{"preview"===u&&x&&n?.basic?.comments&&S(n.basic.comments)},[u,x,n]);const V=r(e=>{const t={};let r=!0;!n?.validation?.required||e&&""!==e.trim()||(t.required=!0,r=!1);const i=n?.options?.find(t=>t.value===e);return!(i&&F(i.value))||k&&""!==k.trim()||(t.commentRequired=!0,r=!1),{isValid:r,errors:t}},[n,k]),I=r(t=>{if(w(t),C(!0),p){const r=V(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors,comments:k};p(i)}},[e,p,V,k]),L=()=>{h&&h()},E=()=>{C(!0),m&&m()};i(()=>{N&&(d[e]=!0)},[N,e,d]),i(()=>{o!==y&&(w(o),"test"===u&&(S(""),D(!1)))},[o,y,u]),i(()=>{c&&C(!0)},[c]),i(()=>{"edit"===u&&(S(""),D(!1))},[u]),i(()=>{const e=n?.options?.find(e=>e.value===y),t=e&&F(e.value);t&&!k?D(!0):t||D(!1)},[y,n?.options,k]);const R=()=>n?.basic?.inlineLayout?"inline-layout":"grid-layout",F=e=>{const t=e.toLowerCase();return"no"===t||"fail"===t||"false"===t},T=()=>{const e=n?.options?.find(e=>e.value===y);return!!e&&F(e.value)},M=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},A=e=>"pass"===M(e)?"✓":"×",z=l||s||n?.validation?.readonly;return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:`form-group segment-group ${(()=>{const e=n?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${f}`,children:!b&&n.basic.label?g.jsxs(g.Fragment,{children:[g.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsx("div",{className:"form-segment-wrapper",children:g.jsx("div",{className:`form-segment-container ${R()}`,children:(n.options||[]).map((t,r)=>{const i=y===t.value;return g.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[g.jsx("input",{type:"radio",id:`${e}_option_${r}`,name:e,value:t.value,checked:i,onChange:()=>!z&&!t.disabled&&I(t.value),onFocus:L,onBlur:E,disabled:z||t.disabled,className:"form-segment-radio"}),g.jsxs("label",{htmlFor:`${e}_option_${r}`,className:"segment-button-label "+("pass"===M(t.value)?"pass-button":"fail-button"),children:[g.jsx("span",{className:"segment-icon",children:A(t.value)}),g.jsx("span",{className:"segment-text",children:t.value})]})]},r)})})})]}):g.jsx("div",{className:"form-segment-wrapper",children:g.jsx("div",{className:`form-segment-container ${R()}`,children:(n.options||[]).map((t,r)=>{const i=y===t.value;return g.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[g.jsx("input",{type:"radio",id:`${e}_option_${r}`,name:e,value:t.value,checked:i,onChange:()=>!z&&!t.disabled&&I(t.value),onFocus:L,onBlur:E,disabled:z||t.disabled,className:"form-segment-radio"}),g.jsxs("label",{htmlFor:`${e}_option_${r}`,className:"segment-button-label "+("pass"===M(t.value)?"pass-button":"fail-button"),children:[g.jsx("span",{className:"segment-icon",children:A(t.value)}),g.jsx("span",{className:"segment-text",children:t.value})]})]},r)})})})}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:{isValid:V(y).isValid,errors:Object.fromEntries(Object.entries(V(y).errors).filter(([e])=>"commentRequired"!==e))},isTouched:N,mode:u}),(!z||"preview"===u&&x)&&g.jsxs(g.Fragment,{children:[(()=>{if("preview"===u&&x&&k)return!0;return T()&&!$&&!!k})()&&g.jsx("div",{onClick:"preview"===u?void 0:()=>{"preview"!==u&&D(!$)},style:{cursor:"preview"===u?"default":"pointer"},children:g.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",k]})}),(()=>{if("preview"===u)return!1;const e=T(),t=!k||""===k.trim();return e&&($||t)})()&&g.jsx(j,{comment:k,onSave:t=>{S(t),D(!1);const r=V(y);if(p){const i={id:e,value:y,isValid:r.isValid,errors:r.errors,comments:t};p(i)}},placeholder:"Enter your reason...",disabled:z}),(()=>{if("preview"===u)return!1;return!T()&&Boolean(k&&""!==k.trim())})()&&g.jsx("div",{children:g.jsxs("label",{className:"form-label notes-label-text",children:["Notes: ",k]})}),"preview"!==u&&T()&&T()&&!k&&N&&g.jsx("div",{children:g.jsx("label",{className:"form-label notes-label-text error-message no-border",children:"Notes are required"})})]})]})},S=({id:e,properties:n,validationErrors:a={},formValue:o="",readonly:s=!1,disabled:l=!1,touchedFields:d={},formSubmitted:c=!1,mode:u="preview",onValueChange:p,onBlur:m,onFocus:h,className:f="",hideLabel:b=!1})=>{const[x,y]=t(o),[j,w]=t(!1),[N,C]=t(!1),k=r(e=>{const t={};let r=!0;const i=n.name||"",a=n.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"),o=e?String(e).trim():"";if(n?.validation?.required&&(!o||""===o))return t.required=!0,r=!1,{isValid:r,errors:t};if(o&&""!==o)if("time"===a){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(o))return t.invalidDate=!0,r=!1,{isValid:r,errors:t}}else if("datetime"===a){const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,r=!1,{isValid:r,errors:t};if(n?.validation?.minDate){const i=new Date(n.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date and time must be on or after ${i.toLocaleDateString()}`,r=!1)}if(n?.validation?.maxDate){const i=new Date(n.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date and time must be on or before ${i.toLocaleDateString()}`,r=!1)}}else{const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,r=!1,{isValid:r,errors:t};if(n?.validation?.minDate){const i=new Date(n.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date must be on or after ${i.toLocaleDateString()}`,r=!1)}if(n?.validation?.maxDate){const i=new Date(n.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date must be on or before ${i.toLocaleDateString()}`,r=!1)}}return{isValid:r,errors:t}},[n]),S=r(t=>{if(y(t),p){const r=k(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors};p(i)}},[e,p,k]);i(()=>{j&&(d[e]=!0)},[j,e,d]),i(()=>{o===x||N||y(o)},[o,x,N]),i(()=>{c&&w(!0)},[c]);const $=l||s||n?.validation?.readonly,D=n.name||"",V=n.basic?.dateTimeMode||("datetime-picker"===D?"datetime":"date"),I=(()=>{switch(V){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return g.jsxs("div",{className:`form-group ${(()=>{const e=n?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&n.basic.label&&g.jsxs("label",{htmlFor:e,className:"form-label",children:[n.basic.label,n.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"input-wrapper",children:[g.jsx("input",{type:I,id:e,value:x,onChange:e=>{const t=e.target.value;S(t)},onFocus:()=>{C(!0),h&&h()},onBlur:()=>{if(C(!1),w(!0),p){const t=k(x),r={id:e,value:x,isValid:t.isValid,errors:t.errors};p(r)}m&&m()},disabled:$,readOnly:s||n?.validation?.readonly,min:n?.validation?.minDate,max:n?.validation?.maxDate,className:`form-date ${!k(x).isValid&&j?"is-invalid":""} ${f}`.trim()}),g.jsx(v,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:c,properties:n,localValidation:k(x),isTouched:j,mode:u})]})]})},$=({id:e,properties:a,validationErrors:o={},formValue:s="",readonly:l=!1,disabled:d=!1,touchedFields:c={},formSubmitted:u=!1,mode:p="preview",onValueChange:m,onBlur:h,onFocus:f,className:b="",hideLabel:x=!1})=>{const y=n(null),[j,w]=t(!1),[N,C]=t(!1),[k,S]=t(s),[$,D]=t(!1),V=r(e=>{const t={};let r=!0;return!a?.validation?.required||e&&""!==e.trim()||(t.required=!0,r=!1),{isValid:r,errors:t}},[a]),I=r(t=>{if(S(t),m){const r=V(t),i={id:e,value:t,isValid:r.isValid,errors:r.errors};m(i)}},[e,m,V]),L=r(()=>{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}},[]),E=r(t=>{if(!t)return;const r=y.current;if(!r)return;const i=r.getContext("2d");if(!i)return;const n=new Image;n.onload=()=>{i.clearRect(0,0,r.width,r.height);const e=L();i.fillStyle=e.backgroundColor,i.fillRect(0,0,r.width,r.height);const t=r.width/r.height,a=n.width/n.height;let o=r.width,s=r.height,l=0,d=0;a>t?(s=r.width/a,d=(r.height-s)/2):(o=r.height*a,l=(r.width-o)/2),i.drawImage(n,l,d,o,s)},n.onerror=r=>{console.error("DfFormSignature: error loading image",{id:e,error:r,dataURL:t.substring(0,50)+"..."})},n.src=t},[L,e]),R=r(()=>{const e=y.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=L();t.strokeStyle=i.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",k?E(k):(t.fillStyle=i.backgroundColor,t.fillRect(0,0,e.width,e.height))},[k,L,E]),F=r(()=>{setTimeout(()=>{R()},100)},[R]);i(()=>{const e=()=>{F()},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"))&&F()}})});return t.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[F]);const T=r(e=>{const t=y.current;if(!t)return{x:0,y:0};const r=t.getBoundingClientRect(),i=t.width/r.width,n=t.height/r.height,a=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,o=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(a-r.left)*i,y:(o-r.top)*n}},[]),M=e=>{if(l||d||a?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),w(!0),C(!0);const t=y.current;if(!t)return;const r=t.getContext("2d");if(!r)return;const{x:i,y:n}=T(e),o=L();r.strokeStyle=o.strokeColor,r.lineWidth=2,r.lineCap="round",r.lineJoin="round",r.beginPath(),r.moveTo(i,n)},A=e=>{if(!j)return;e.preventDefault(),e.stopPropagation();const t=y.current;if(!t)return;const r=t.getContext("2d");if(!r)return;const{x:i,y:n}=T(e);r.lineTo(i,n),r.stroke()},z=()=>{if(!j)return;w(!1),D(!0);const e=y.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],n=r[e+2];if(r[e+3]>0&&(t<255||i<255||n<255))return!0}})(e);const t=e.toDataURL("image/png");S(t),I(t),setTimeout(()=>{D(!1)},100)}else D(!1)},O=r(()=>{const e=y.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const r=L();if(t.strokeStyle=r.strokeColor,k){const i=k,n=e.getBoundingClientRect();t.fillStyle=r.backgroundColor,t.fillRect(0,0,n.width,n.height),i&&E(i)}else{const i=e.getBoundingClientRect();t.fillStyle=r.backgroundColor,t.fillRect(0,0,i.width,i.height)}},[L,k,E]);i(()=>{const e=new MutationObserver(e=>{e.forEach(e=>{"attributes"!==e.type||"class"!==e.attributeName&&"data-theme"!==e.attributeName||O()})});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{e.disconnect()}},[O]);i(()=>{N&&(c[e]=!0)},[N,e,c]),i(()=>{if(!(s===k||j||$||""!==k&&""===s)){if(s===k)return;S(s),s&&E(s)}},[s,k,j,$]),i(()=>{u&&C(!0)},[u]),i(()=>{if("test"!==p){S("");const e=y.current;if(e){const t=e.getContext("2d");if(t){const r=e.getBoundingClientRect();e.width=r.width,e.height=r.height;const i=L();t.fillStyle=i.backgroundColor,t.fillRect(0,0,r.width,r.height)}}}},[p]),i(()=>{R()},[p]);const _=d||l||a?.validation?.readonly;return g.jsxs("div",{className:`form-group ${(()=>{const e=a?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!x&&a.basic.label&&g.jsxs("label",{htmlFor:e,className:"form-label",children:[a.basic.label,a.validation.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"input-wrapper",children:[g.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[g.jsx("canvas",{ref:y,id:e,className:`form-signature ${!V(k).isValid&&N?"is-invalid":""} ${b}`.trim(),onMouseDown:M,onMouseMove:A,onMouseUp:z,onMouseLeave:z,onTouchStart:M,onTouchMove:A,onTouchEnd:z,onFocus:()=>{f&&f()},onBlur:()=>{h&&h()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:_?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!_&&g.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=y.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 n=L();i.fillStyle=n.backgroundColor,i.fillRect(0,0,r.width,r.height),i.strokeStyle=n.strokeColor,i.lineWidth=2,i.lineCap="round",i.lineJoin="round",S(""),I("")})(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"})]}),g.jsx(v,{validationErrors:o,fieldId:e,touchedFields:c,formSubmitted:u,properties:a,localValidation:V(k),isTouched:N,mode:p})]})]})},D=({id:e,properties:t,className:r="",hideLabel:i=!1})=>{const n=t.styles?.level??t.basic.level??1,a=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${n} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${r}`.trim(),style:o()};switch(n){case 1:default:return g.jsx("h1",{...i,children:a});case 2:return g.jsx("h2",{...i,children:a});case 3:return g.jsx("h3",{...i,children:a});case 4:return g.jsx("h4",{...i,children:a});case 5:return g.jsx("h5",{...i,children:a});case 6:return g.jsx("h6",{...i,children:a})}})()},V=({id:e,properties:a,validationErrors:o={},formValue:s=null,readonly:l=!1,disabled:d=!1,touchedFields:c={},formSubmitted:u=!1,mode:p="test",onValueChange:m,onBlur:h,onFocus:f,className:b="",hideLabel:x=!1})=>{const[y,j]=t([]),[w,N]=t(!1),[C,k]=t(!1),S=n(null),$=r(t=>{if(!t)return[];const r=Array.isArray(t)?t:Array.from(t),i=[];return r.forEach((t,r)=>{let n,a,o=0,s="",l="";if(t instanceof File||t instanceof Blob){const e=t;if(o=e.size||0,s=e.type||"",l=e.name||`file-${r}`,a=e,s.startsWith("image/"))try{n=URL.createObjectURL(e)}catch(e){console.error("Error creating object URL:",e),n=void 0}}else if("string"==typeof t){const e=t;if(l=`file-${r}`,e.startsWith("data:")){const t=e.indexOf(";");s=t>5?e.substring(5,t):"application/octet-stream"}else{const t=e.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(t){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"}[t[1].toLowerCase()]||"application/octet-stream"}else s="application/octet-stream"}(e.startsWith("data:image")||e.startsWith("http://")||e.startsWith("https://")||e.startsWith("blob:"))&&(n=e),a=new File([],l,{type:s})}else{if(!t||"object"!=typeof t)return;{const e=t;if(l=e.name||e.fileName||`file-${r}`,o=e.size||e.fileSize||0,s=e.type||e.fileType||e.mimeType||"",e.url||e.path)n=e.url||e.path;else if(s.startsWith("image/")&&e.data){const t=e.data;n="string"==typeof t?t.startsWith("data:")?t:`data:${s};base64,${t}`:void 0}a=new File([],l,{type:s})}}i.push({file:a,id:`${e}-file-${r}`,size:o,type:s,name:l,preview:n})}),i},[e]),D=r(()=>({isValid:!0,errors:{}}),[]),V=r(t=>{if(l||d)return;const r=$(t),i=y.length>0?[...y,...r]:r,n=a?.validation?.maxFiles||1/0,o=i.slice(0,n);if(j(o),k(!0),m){const t=D(),r={id:e,value:o.map(e=>e.file),isValid:t.isValid,errors:t.errors};m(r)}},[y,a,l,d,m,D,$,e]),I=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]},L=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")?"📦":"📁";i(()=>{C&&(c[e]=!0)},[C,e,c]),i(()=>{("edit"===p||"test"===p)&&k(!1)},[p]),i(()=>{const e=$(s);j(e)},[s,$]),i(()=>{u&&k(!0)},[u]),i(()=>()=>{y.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[y]);const E=()=>{const e=a?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"},R=d||l||a?.validation?.readonly,F=a?.validation?.multiple||!1,T=a?.validation?.accept||"*/*",M=a?.validation?.maxFiles||1/0,A=y.length<M&&(F||M>1),z="edit"===p,O="preview"===p||"test"===p,_=y.filter(e=>e.type.startsWith("image/")),B=y.filter(e=>!e.type.startsWith("image/")),P=_.length>0;return O&&P?g.jsxs("div",{className:`form-group ${E()}`,children:[!x&&g.jsxs("label",{htmlFor:e,className:"form-label",children:[a.basic?.label||"Attachments",a.validation?.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"file-upload-wrapper",children:[g.jsxs("div",{className:"file-image-display",children:[_.map(e=>g.jsxs("div",{className:"file-image-container",children:[e.preview&&g.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),g.jsxs("div",{className:"file-image-info",children:[g.jsx("div",{className:"file-name",title:e.name,children:e.name}),g.jsx("div",{className:"file-size",children:I(e.size)})]})]},e.id)),B.length>0&&g.jsxs("div",{className:"file-other-files",children:[g.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),B.map(e=>g.jsxs("div",{className:"file-item-minimal",children:[g.jsx("div",{className:"file-icon",children:L(e.type)}),g.jsxs("div",{className:"file-info",children:[g.jsx("div",{className:"file-name",title:e.name,children:e.name}),g.jsx("div",{className:"file-size",children:I(e.size)})]})]},e.id))]})]}),g.jsx(v,{validationErrors:o,fieldId:e,touchedFields:c,formSubmitted:u,properties:a,localValidation:D(),isTouched:C,mode:p})]})]}):g.jsxs("div",{className:`form-group ${E()}`,children:[!x&&g.jsxs("label",{htmlFor:e,className:"form-label",children:[a.basic?.label||"Attachments",a.validation?.required&&g.jsx("span",{className:"required-indicator",children:"*"})]}),g.jsxs("div",{className:"file-upload-wrapper",children:[g.jsxs("div",{className:`file-upload-area ${w?"drag-over":""} ${l?"readonly":""} ${d?"disabled":""} ${b}`.trim(),onDragOver:e=>{e.preventDefault(),l||d||N(!0)},onDragLeave:e=>{e.preventDefault(),N(!1)},onDrop:e=>{if(e.preventDefault(),N(!1),l||d)return;const t=e.dataTransfer.files;t.length>0&&V(t)},onClick:e=>{const t=e.target,r=null!==t.closest(".file-item"),i=null!==t.closest(".file-remove");!z||R||0!==y.length||r||i||S.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(k(!0),"test"===p&&m){const t=D(),r={id:e,value:y.map(e=>e.file),isValid:t.isValid,errors:t.errors};m(r)}h&&h()},tabIndex:R?-1:0,children:[g.jsx("input",{ref:S,type:"file",id:e,multiple:F,accept:T,onChange:e=>{const t=e.target.files;t&&t.length>0&&(V(t),e.target.value="")},disabled:R,style:{display:"none"}}),0===y.length?g.jsxs("div",{className:"upload-placeholder",onClick:e=>{e.stopPropagation(),z&&!R&&S.current?.click()},children:[g.jsx("div",{className:"upload-icon",children:"📁"}),g.jsx("div",{className:"upload-text",children:a.basic.placeholder&&g.jsx("p",{className:"upload-hint",children:a.basic.placeholder})})]}):g.jsx("div",{className:"file-list",children:y.map(t=>g.jsxs("div",{className:"file-item",children:[g.jsx("div",{className:"file-preview",children:t.preview?g.jsx("img",{src:t.preview,alt:t.name,className:"file-image"}):g.jsx("div",{className:"file-icon",children:L(t.type)})}),g.jsxs("div",{className:"file-info",children:[g.jsx("div",{className:"file-name",title:t.name,children:t.name}),g.jsx("div",{className:"file-size",children:I(t.size)})]}),z&&!R&&g.jsx("button",{type:"button",className:"file-remove",onClick:r=>{r.stopPropagation(),(t=>{if(l||d)return;const r=y.filter(e=>e.id!==t);if(j(r),k(!0),m){const t=D(),i={id:e,value:r.map(e=>e.file),isValid:t.isValid,errors:t.errors};m(i)}})(t.id)},"aria-label":`Remove ${t.name}`,children:"✕"})]},t.id))})]}),y.length>0&&A&&!R&&z&&g.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!R&&S.current&&z&&(S.current.value="",S.current.click())},"aria-label":"Add more files",children:[g.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:g.jsx("path",{d:"M12 5v14M5 12h14"})}),g.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),g.jsx(v,{validationErrors:o,fieldId:e,touchedFields:c,formSubmitted:u,properties:a,localValidation:D(),isTouched:C,mode:p})]})]})},I=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)},L=(...e)=>e.filter((e,t,r)=>Boolean(e)&&""!==e.trim()&&r.indexOf(e)===t).join(" ").trim(),E=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 R={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 F=a(({color:e="currentColor",size:t=24,strokeWidth:r=2,absoluteStrokeWidth:i,className:n="",children:a,iconNode:s,...l},d)=>o("svg",{ref:d,...R,width:t,height:t,stroke:e,strokeWidth:i?24*Number(r)/Number(t):r,className:L("lucide",n),...!a&&!E(l)&&{"aria-hidden":"true"},...l},[...s.map(([e,t])=>o(e,t)),...Array.isArray(a)?a:[a]])),T=(e,t)=>{const r=a(({className:r,...i},n)=>{return o(F,{ref:n,iconNode:t,className:L(`lucide-${a=I(e),a.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${e}`,r),...i});var a});return r.displayName=I(e),r},M=T("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"}]]),A=T("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]),z=T("chevron-right",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]),O=T("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"}]]),_=T("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"}]]),B=T("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"}]]),P=T("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"}]]),q=T("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"}]]),W=T("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"}]]),U=T("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]),H=T("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"}]]),J=T("navigation",[["polygon",{points:"3 11 22 2 13 21 11 13 3 11",key:"1ltx0t"}]]),Y=T("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"}]]),X=T("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"}]]),G=T("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"}]]),K=T("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),Z=({id:e,properties:a,validationErrors:o={},formValue:s=null,readonly:l=!1,disabled:d=!1,touchedFields:c={},formSubmitted:u=!1,mode:p="test",onValueChange:m,onBlur:h,onFocus:f,className:b="",hideLabel:x=!1})=>{const[y,j]=t(s),[w,N]=t(!1),[C,k]=t(""),[S,$]=t(!1),[D,V]=t(!1),[I,L]=t({lat:40.7128,lng:-74.006}),[E,R]=t(null),[F,T]=t(10),[M,A]=t(""),[z,O]=t(!1),_=n(null),[B,P]=t(!1),[q,W]=t(null),[Y,X]=t(!1);i(()=>{s?(j(s),s.latitude&&s.longitude&&(R({lat:s.latitude,lng:s.longitude,isCurrentLocation:!1}),L({lat:s.latitude,lng:s.longitude}))):(j(null),R(null))},[s]),i(()=>{D&&40.7128===I.lat&&I.lng},[D,I]),i(()=>{(l||d)&&(D&&V(!1),M&&A(""),B&&(P(!1),W(null)))},[l,d]);const G=r(async(e,t)=>{X(!0);try{const r=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),i=await r.json();if(i&&i.address){const e=i.address;return{placeName:i.display_name||"",city:e.city||e.town||e.village||e.municipality||"",country:e.country||""}}}catch(e){console.error("Reverse geocoding failed:",e)}finally{X(!1)}return{placeName:"",city:"",country:""}},[]),Z=r(async(t,r,i)=>{const n=await G(t,r),a={latitude:t,longitude:r,timestamp:Date.now(),placeName:n.placeName,city:n.city,country:n.country,address:n.placeName,...i};if(j(a),R({lat:t,lng:r,isCurrentLocation:!1}),$(!0),m){m({id:e,value:a,isValid:!0,errors:{}})}},[G,e,m]),Q=r(()=>{if(l||d)return;if(!navigator.geolocation)return void k("Geolocation is not supported by this browser.");N(!0),k("");const e={enableHighAccuracy:a.validation?.enableHighAccuracy??!0,timeout:a.validation?.timeout??1e4,maximumAge:a.validation?.maximumAge??3e5};navigator.geolocation.getCurrentPosition(async e=>