df-ae-forms-package 1.0.26 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import e,{useState as t,useEffect as n,useCallback as i,useRef as s,useMemo as r}from"react";import{AlertTriangle as a,X as o,User as l,Calendar as c,MessageSquare as d,Loader2 as u,Navigation as m,MapPin as p,Bold as h,Italic as f,List as b,ListOrdered as g,Image as v,Paperclip as y,Check as x,Mail as j,AlertCircle as N,ChevronUp as C,ChevronDown as w,ChevronRight as S,GripVertical as $,Edit as k,Trash2 as E,Grid as T,Table as A}from"lucide-react";import{createPortal as I}from"react-dom";import{useDroppable as R}from"@dnd-kit/core";import{SortableContext as L,verticalListSortingStrategy as D,useSortable as V,horizontalListSortingStrategy as F}from"@dnd-kit/sortable";import{CSS as O}from"@dnd-kit/utilities";import{v4 as M}from"uuid";var P,z={exports:{}},q={};var _,W={};
1
+ import e,{useState as t,useEffect as n,useCallback as i,useRef as s,useMemo as r}from"react";import{AlertTriangle as a,X as o,User as l,Calendar as c,MessageSquare as d,Loader2 as u,Navigation as m,MapPin as p,Bold as h,Italic as f,List as b,ListOrdered as g,Image as v,Paperclip as y,Check as x,Mail as j,AlertCircle as N,ChevronUp as C,ChevronDown as w,ChevronRight as S,GripVertical as $,Edit as k,Trash2 as E,Grid as A,Table as T}from"lucide-react";import{createPortal as L}from"react-dom";import{useDroppable as I}from"@dnd-kit/core";import{SortableContext as R,verticalListSortingStrategy as D,useSortable as V,horizontalListSortingStrategy as F}from"@dnd-kit/sortable";import{CSS as O}from"@dnd-kit/utilities";import{v4 as q}from"uuid";var P,M={exports:{}},z={};var _,W={};
2
2
  /**
3
3
  * @license React
4
4
  * react-jsx-runtime.development.js
@@ -7,5 +7,5 @@ import e,{useState as t,useEffect as n,useCallback as i,useRef as s,useMemo as r
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */"production"===process.env.NODE_ENV?z.exports=function(){if(P)return q;P=1;var t=e,n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,r=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(e,t,i){var o,l={},c=null,d=null;for(o in void 0!==i&&(c=""+i),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(d=t.ref),t)s.call(t,o)&&!a.hasOwnProperty(o)&&(l[o]=t[o]);if(e&&e.defaultProps)for(o in t=e.defaultProps)void 0===l[o]&&(l[o]=t[o]);return{$$typeof:n,type:e,key:c,ref:d,props:l,_owner:r.current}}return q.Fragment=i,q.jsx=o,q.jsxs=o,q}():z.exports=(_||(_=1,"production"!==process.env.NODE_ENV&&function(){var t,n=e,i=Symbol.for("react.element"),s=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),c=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),f=Symbol.for("react.offscreen"),b=Symbol.iterator,g=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];!function(e,t,n){var i=g.ReactDebugCurrentFrame.getStackAddendum();""!==i&&(t+="%s",n=n.concat([i]));var s=n.map(function(e){return String(e)});s.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,s)}("error",e,n)}function y(e){return e.displayName||"Context"}function x(e){if(null==e)return null;if("number"==typeof e.tag&&v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case r:return"Fragment";case s:return"Portal";case o:return"Profiler";case a:return"StrictMode";case u:return"Suspense";case m:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case c:return y(e)+".Consumer";case l:return y(e._context)+".Provider";case d:return function(e,t,n){var i=e.displayName;if(i)return i;var s=t.displayName||t.name||"";return""!==s?n+"("+s+")":n}(e,e.render,"ForwardRef");case p:var t=e.displayName||null;return null!==t?t:x(e.type)||"Memo";case h:var n=e,i=n._payload,f=n._init;try{return x(f(i))}catch(e){return null}}return null}t=Symbol.for("react.module.reference");var j,N,C,w,S,$,k,E=Object.assign,T=0;function A(){}A.__reactDisabledLog=!0;var I,R=g.ReactCurrentDispatcher;function L(e,t,n){if(void 0===I)try{throw Error()}catch(e){var i=e.stack.trim().match(/\n( *(at )?)/);I=i&&i[1]||""}return"\n"+I+e}var D,V=!1,F="function"==typeof WeakMap?WeakMap:Map;function O(e,t){if(!e||V)return"";var n,i=D.get(e);if(void 0!==i)return i;V=!0;var s,r=Error.prepareStackTrace;Error.prepareStackTrace=void 0,s=R.current,R.current=null,function(){if(0===T){j=console.log,N=console.info,C=console.warn,w=console.error,S=console.group,$=console.groupCollapsed,k=console.groupEnd;var e={configurable:!0,enumerable:!0,value:A,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}T++}();try{if(t){var a=function(){throw Error()};if(Object.defineProperty(a.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(a,[])}catch(e){n=e}Reflect.construct(e,[],a)}else{try{a.call()}catch(e){n=e}e.call(a.prototype)}}else{try{throw Error()}catch(e){n=e}e()}}catch(t){if(t&&n&&"string"==typeof t.stack){for(var o=t.stack.split("\n"),l=n.stack.split("\n"),c=o.length-1,d=l.length-1;c>=1&&d>=0&&o[c]!==l[d];)d--;for(;c>=1&&d>=0;c--,d--)if(o[c]!==l[d]){if(1!==c||1!==d)do{if(c--,--d<0||o[c]!==l[d]){var u="\n"+o[c].replace(" at new "," at ");return e.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,u),u}}while(c>=1&&d>=0);break}}}finally{V=!1,R.current=s,function(){if(0===--T){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:E({},e,{value:j}),info:E({},e,{value:N}),warn:E({},e,{value:C}),error:E({},e,{value:w}),group:E({},e,{value:S}),groupCollapsed:E({},e,{value:$}),groupEnd:E({},e,{value:k})})}T<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=r}var m=e?e.displayName||e.name:"",p=m?L(m):"";return"function"==typeof e&&D.set(e,p),p}function M(e,t,n){if(null==e)return"";if("function"==typeof e)return O(e,!(!(i=e.prototype)||!i.isReactComponent));var i;if("string"==typeof e)return L(e);switch(e){case u:return L("Suspense");case m:return L("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case d:return O(e.render,!1);case p:return M(e.type,t,n);case h:var s=e,r=s._payload,a=s._init;try{return M(a(r),t,n)}catch(e){}}return""}D=new F;var P=Object.prototype.hasOwnProperty,z={},q=g.ReactDebugCurrentFrame;function _(e){if(e){var t=e._owner,n=M(e.type,e._source,t?t.type:null);q.setExtraStackFrame(n)}else q.setExtraStackFrame(null)}var B=Array.isArray;function U(e){return B(e)}function G(e){return""+e}function J(e){if(function(e){try{return G(e),!1}catch(e){return!0}}(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),G(e)}var H,Y,K,X=g.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,n,s,r){var a,o={},l=null,c=null;for(a in void 0!==n&&(J(n),l=""+n),function(e){if(P.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(J(t.key),l=""+t.key),function(e){if(P.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e,t){if("string"==typeof e.ref&&X.current&&t&&X.current.stateNode!==t){var n=x(X.current.type);K[n]||(v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',x(X.current.type),e.ref),K[n]=!0)}}(t,r)),t)P.call(t,a)&&!Z.hasOwnProperty(a)&&(o[a]=t[a]);if(e&&e.defaultProps){var d=e.defaultProps;for(a in d)void 0===o[a]&&(o[a]=d[a])}if(l||c){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;l&&function(e,t){var n=function(){H||(H=!0,v("%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://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,u),c&&function(e,t){var n=function(){Y||(Y=!0,v("%s: `ref` 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://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}(o,u)}return function(e,t,n,s,r,a,o){var l={$$typeof:i,type:e,key:t,ref:n,props:o,_owner:a,_store:{}};return Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:r}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l}(e,l,c,r,s,X.current,o)}K={};var ee,te=g.ReactCurrentOwner,ne=g.ReactDebugCurrentFrame;function ie(e){if(e){var t=e._owner,n=M(e.type,e._source,t?t.type:null);ne.setExtraStackFrame(n)}else ne.setExtraStackFrame(null)}function se(e){return"object"==typeof e&&null!==e&&e.$$typeof===i}function re(){if(te.current){var e=x(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var ae={};function oe(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var n=function(e){var t=re();if(!t){var n="string"==typeof e?e:e.displayName||e.name;n&&(t="\n\nCheck the top-level render call using <"+n+">.")}return t}(t);if(!ae[n]){ae[n]=!0;var i="";e&&e._owner&&e._owner!==te.current&&(i=" It was passed a child from "+x(e._owner.type)+"."),ie(e),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,i),ie(null)}}}function le(e,t){if("object"==typeof e)if(U(e))for(var n=0;n<e.length;n++){var i=e[n];se(i)&&oe(i,t)}else if(se(e))e._store&&(e._store.validated=!0);else if(e){var s=function(e){if(null===e||"object"!=typeof e)return null;var t=b&&e[b]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof s&&s!==e.entries)for(var r,a=s.call(e);!(r=a.next()).done;)se(r.value)&&oe(r.value,t)}}function ce(e){var t,n=e.type;if(null!=n&&"string"!=typeof n){if("function"==typeof n)t=n.propTypes;else{if("object"!=typeof n||n.$$typeof!==d&&n.$$typeof!==p)return;t=n.propTypes}if(t){var i=x(n);!function(e,t,n,i,s){var r=Function.call.bind(P);for(var a in e)if(r(e,a)){var o=void 0;try{if("function"!=typeof e[a]){var l=Error((i||"React class")+": "+n+" type `"+a+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[a]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw l.name="Invariant Violation",l}o=e[a](t,a,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){o=e}!o||o instanceof Error||(_(s),v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",i||"React class",n,a,typeof o),_(null)),o instanceof Error&&!(o.message in z)&&(z[o.message]=!0,_(s),v("Failed %s type: %s",n,o.message),_(null))}}(t,e.props,"prop",i,e)}else void 0===n.PropTypes||ee||(ee=!0,v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",x(n)||"Unknown"));"function"!=typeof n.getDefaultProps||n.getDefaultProps.isReactClassApproved||v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var de={};function ue(e,n,s,b,g,y){var j=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===o||e===a||e===u||e===m||e===f||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===p||e.$$typeof===l||e.$$typeof===c||e.$$typeof===d||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!j){var N="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(N+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var C,w=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(g);N+=w||re(),null===e?C="null":U(e)?C="array":void 0!==e&&e.$$typeof===i?(C="<"+(x(e.type)||"Unknown")+" />",N=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,N)}var S=Q(e,n,s,g,y);if(null==S)return S;if(j){var $=n.children;if(void 0!==$)if(b)if(U($)){for(var k=0;k<$.length;k++)le($[k],e);Object.freeze&&Object.freeze($)}else v("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 le($,e)}if(P.call(n,"key")){var E=x(e),T=Object.keys(n).filter(function(e){return"key"!==e}),A=T.length>0?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}";de[E+A]||(v('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,E,T.length>0?"{"+T.join(": ..., ")+": ...}":"{}",E),de[E+A]=!0)}return e===r?function(e){for(var t=Object.keys(e.props),n=0;n<t.length;n++){var i=t[n];if("children"!==i&&"key"!==i){ie(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),ie(null);break}}null!==e.ref&&(ie(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),ie(null))}(S):ce(S),S}var me=function(e,t,n){return ue(e,t,n,!1)},pe=function(e,t,n){return ue(e,t,n,!0)};W.Fragment=r,W.jsx=me,W.jsxs=pe}()),W);var B=z.exports;class U{constructor(){}static getInstance(){return U.instance||(U.instance=new U),U.instance}getAvailableComponentsForConditional(e,t){if(!e||!Array.isArray(e))return[];return e.filter(e=>!t||e.id!==t).map(e=>({id:e.id,label:e.basic?.label||e.id,type:e.name,key:e.id})).sort((e,t)=>e.label.localeCompare(t.label))}getApplicableOperators(e){switch(e){case"text-input":case"email-input":case"textarea":return["equals","notEquals","contains","notContains","isEmpty","isNotEmpty"];case"number-input":case"date-picker":case"datetime-picker":return["equals","notEquals","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual","isEmpty","isNotEmpty"];case"select":case"radio":case"segment":default:return["equals","notEquals","isEmpty","isNotEmpty"];case"checkbox":return["contains","notContains","isEmpty","isNotEmpty"]}}validateConditionalLogic(e,t){const n=[];return e?(["show","hide","always"].includes(e.action)||n.push("Invalid conditional action"),["all","any"].includes(e.when)||n.push("Invalid when condition"),e.conditions&&0!==e.conditions.length?e.conditions.forEach((e,i)=>{const s=t.find(t=>t.id===e.when);if(!s)return void n.push(`Condition ${i+1}: Component not found`);this.getApplicableOperators(s.name).includes(e.operator)||n.push(`Condition ${i+1}: Operator not applicable for component type`),this.isValidConditionValue(e.value,s.name,e.operator)||n.push(`Condition ${i+1}: Invalid condition value`)}):n.push("At least one condition is required"),{isValid:0===n.length,errors:n}):{isValid:!0,errors:[]}}evaluateConditionalLogic(e,t,n){if("always"===e.action)return{shouldShow:!0,evaluatedConditions:[]};if(!e||!e.conditions||0===e.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const i=e.conditions.map(e=>{const i=this.getComponentValue(e.when,t,n);return{condition:e,result:this.evaluateCondition(e,i),componentValue:i}});return{shouldShow:this.determineFinalResult(e,i),evaluatedConditions:i}}getComponentValue(e,t,n){if(n&&void 0!==n[e])return n[e];const i=t.find(t=>t.id===e);return i&&"defaultValue"in i.basic?i.basic.defaultValue:void 0}evaluateCondition(e,t){const{operator:n,value:i}=e;if("checked"===i||"notChecked"===i)return this.evaluateCheckboxCondition(t,i);switch(n){case"equals":return this.isEqual(t,i);case"notEquals":return!this.isEqual(t,i);case"isEmpty":return this.isEmpty(t);case"isNotEmpty":return!this.isEmpty(t);case"contains":return this.contains(t,i);case"notContains":return!this.contains(t,i);case"greaterThan":return this.isGreaterThan(t,i);case"lessThan":return this.isLessThan(t,i);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(t,i);case"lessThanOrEqual":return this.isLessThanOrEqual(t,i);default:return!1}}evaluateCheckboxCondition(e,t){const n=this.isCheckboxChecked(e);return"checked"===t?n:"notChecked"===t&&!n}isCheckboxChecked(e){return null!=e&&("boolean"==typeof e?e:"string"==typeof e?"true"===e.toLowerCase()||"1"===e:Array.isArray(e)?e.length>0:"number"==typeof e&&e>0)}determineFinalResult(e,t){let n,i;return n="all"===e.when?t.every(e=>e.result):"any"===e.when&&t.some(e=>e.result),i="show"===e.action?n:"hide"===e.action?!n:(e.action,!0),i}isEqual(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>this.isEqual(e,t[n]));if("object"==typeof e&&"object"==typeof t){const n=Object.keys(e),i=Object.keys(t);return n.length===i.length&&n.every(n=>this.isEqual(e[n],t[n]))}return!1}isEmpty(e){return null==e||void 0===e||("string"==typeof e?""===e.trim():Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}contains(e,t){return null!=e&&null!=t&&("string"==typeof e?e.toLowerCase().includes(String(t).toLowerCase()):!!Array.isArray(e)&&e.some(e=>this.isEqual(e,t)))}isGreaterThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>i}isLessThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<i}isGreaterThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>=i}isLessThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<=i}isValidConditionValue(e,t,n){if(null==e)return["isEmpty","isNotEmpty"].includes(n);switch(t){case"number-input":return!isNaN(Number(e))||["isEmpty","isNotEmpty"].includes(n);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(e))||["isEmpty","isNotEmpty"].includes(n);case"checkbox":return Array.isArray(e)||"string"==typeof e||"number"==typeof e;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(e){return{equals:"Is Equal To",notEquals:"Is Not Equal To",contains:"Contains",notContains:"Does Not Contain",isEmpty:"Is Empty",isNotEmpty:"Is Not Empty",greaterThan:"Is Greater Than",lessThan:"Is Less Than",greaterThanOrEqual:"Is Greater Than Or Equal To",lessThanOrEqual:"Is Less Than Or Equal To"}[e]||e}getActionDisplayText(e){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[e]||e}getConditionalLogicSummary(e,t){if(!e||0===e.conditions.length)return"No conditions";if("always"===e.action)return"Always show";const n=this.getActionDisplayText(e.action),i=e.conditions.map(e=>{const n=t.find(t=>t.id===e.when);return`${n?.basic.label||"Unknown component"} ${this.getOperatorDisplayText(e.operator)} ${this.formatConditionValue(e.value)}`}),s="all"===e.when?" and ":" or ";return`${n} ${i.join(s)}`}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const G=U.getInstance();const J=new class{constructor(){this.toasts=[],this.listeners=[],this.defaultDuration=3e3,this.timeouts={}}generateId(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}notifyListeners(){this.listeners.forEach(e=>e([...this.toasts]))}addToast(e){try{this.toasts.push(e),this.notifyListeners(),this.timeouts[e.id]=setTimeout(()=>{this.removeToast(e.id)},e.duration||this.defaultDuration)}catch(e){console.error("Error displaying toast message:",e)}}removeToast(e){this.timeouts[e]&&(clearTimeout(this.timeouts[e]),delete this.timeouts[e]),this.toasts=this.toasts.filter(t=>t.id!==e),this.notifyListeners()}showSuccess(e,t=3e3){const n={id:this.generateId(),message:e,type:"success",duration:t};this.addToast(n)}showError(e,t=5e3){const n={id:this.generateId(),message:e,type:"danger",duration:t};this.addToast(n)}showWarning(e,t){const n={id:this.generateId(),message:e,type:"warning",duration:t};this.addToast(n)}showInfo(e,t){const n={id:this.generateId(),message:e,type:"info",duration:t};this.addToast(n)}show(e,t="success",n){const i={id:this.generateId(),message:e,type:t,duration:n};this.addToast(i)}clearAll(){Object.values(this.timeouts).forEach(e=>clearTimeout(e)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}getToasts(){return[...this.toasts]}},H=({validationErrors:e,fieldId:t,touchedFields:n,formSubmitted:i,properties:s,localValidation:r,isTouched:a,mode:o})=>{const l=e=>{const t=s.basic.label||"This field",n=s.validation?.customValidationMessage;if("pattern"===e&&n&&""!==n.trim())return n;if(n&&""!==n.trim()&&"pattern"!==e)return n;const i=s.name||"",r="date-picker"===i||"datetime-picker"===i?s.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"):null;switch(e){case"required":return`${t} is required`;case"invalidDate":return"time"===r?"Please select a valid time":"datetime"===r?"Please select a valid date and time":"date"===r?"Please select a valid date":`${t} is invalid`;case"minLength":return`${t} must be at least ${s.validation.minLength} characters long`;case"maxLength":return`${t} must be no more than ${s.validation.maxLength} characters long`;case"min":return`${t} must be at least ${s.validation.min}`;case"max":return`${t} must be no more than ${s.validation.max}`;case"lowerLimit":const e=s.validation,n=e?.lowerLimit;return`You are under the limit. ${t} must be at least ${n}`;case"upperLimit":const i=s.validation,a=i?.upperLimit;return`You crossed the limit. ${t} must be no more than ${a}`;case"pattern":return`${t} format is invalid`;case"email":return`${t} must be a valid email address`;default:return`${t} is invalid`}},c=(()=>{if("test"!==o)return"";if(!(a||n[t]||i))return"";if(r&&r.isValid)return"";if(r&&!r.isValid&&Object.keys(r.errors).length>0){const e=Object.keys(r.errors).filter(e=>!0===r.errors[e]);if(e.length>0){const t=e[0];return l(t)}}const c=e[t];if(c&&"string"==typeof c&&""!==c.trim()){const e=s.name||"";if("number-input"===e&&r&&r.isValid)return"";if(("date-picker"===e||"datetime-picker"===e)&&c.includes("valid date")){const t=s.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 c}return""})();return c?B.jsx("div",{className:"form-error-msg",children:c}):null};var Y;!function(e){e.OPEN="Open",e.IN_PROGRESS="In-Progress",e.REJECTED="Rejected",e.RESOLVE="Resolve"}(Y||(Y={}));const K=({isOpen:e,onClose:i,onSuccess:s,component:r,formTemplateId:u,notes:m="",attachments:p=null,issue:h=null,onCreateIssue:f,onUpdateIssue:b,user:g,availableUsers:v=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"]})=>{const[y,x]=t(""),[j,N]=t(""),[C,w]=t(""),[S,$]=t(""),[k,E]=t("Medium"),[T,A]=t(Y.OPEN),[R,L]=t(""),[D,V]=t(""),[F,O]=t(!1),M=!!h;n(()=>{if(e)if(h){x(h.title||""),N(h.description||""),w(h.workOrderNumber||""),$(h.assetNumber||""),E(h.priority||"Medium");const e=h.status||Y.OPEN,t=e===Y.OPEN||e===Y.IN_PROGRESS||e===Y.REJECTED||e===Y.RESOLVE?e:Y.OPEN;A(t),L(h.assignee||""),V(h.comments||"")}else if(r){const e=r.basic?.label||"Component";x(`${e} - Issue`);let t=`Issue raised for component: ${e}`;r.basic&&"value"in r.basic&&r.basic.value&&(t+=`\nComponent Value: ${r.basic.value}`),m&&(t+=`\nNotes: ${m}`),N(t),V(m||"")}},[e,r,m,h]);const P=async e=>{if(h){O(!0);try{const t={title:String(y||"").trim(),description:String(j||"").trim(),workOrderNumber:String(C||"").trim()||"",assetNumber:String(S||"").trim()||"",formTemplateId:h.formTemplateId||"",component:h.component||{},priority:k,assignee:String(R||"").trim()||void 0,status:e,comments:String(D||"").trim()||""};b&&h._id&&await b(h._id,t),A(e);const n={[Y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[Y.RESOLVE]:"Issue resolved successfully",[Y.REJECTED]:"Issue rejected"};J.showSuccess(n[e]||"Issue status updated successfully"),s&&s(),i()}catch(e){const t=e?.message||e?.error?.message||"Failed to update issue status. Please try again.";J.showError(t)}finally{O(!1)}}};if(!e)return null;const z=B.jsx("div",{className:"raise-issue-modal-overlay",onClick:i,children:B.jsxs("div",{className:"raise-issue-modal",onClick:e=>e.stopPropagation(),children:[B.jsxs("div",{className:"raise-issue-modal-header",children:[B.jsxs("div",{className:"raise-issue-modal-header-left",children:[B.jsx(a,{className:"raise-issue-modal-icon",size:20}),B.jsx("div",{className:"raise-issue-modal-header-text",children:B.jsx("div",{className:"raise-issue-modal-title-main",children:"Issue Details"})})]}),B.jsx("button",{className:"raise-issue-modal-close",onClick:i,"aria-label":"Close",children:B.jsx(o,{size:18})})]}),B.jsx("div",{className:"raise-issue-modal-content",children:B.jsxs("div",{className:"raise-issue-fields-grid",children:[M&&h?.issueNumber&&B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),B.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:h.issueNumber,readOnly:!0})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Title ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(M?"raise-issue-field-readonly":""),value:y,onChange:e=>x(e.target.value),placeholder:"Enter issue title",readOnly:M})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(M?"raise-issue-field-readonly":""),value:C,onChange:e=>w(e.target.value),placeholder:"N/A",readOnly:M})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(M?"raise-issue-field-readonly":""),value:S,onChange:e=>$(e.target.value),placeholder:"Enter asset number",readOnly:M})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Raised By"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(l,{size:16}),B.jsx("span",{children:g&&`${g.firstName||""} ${g.lastName||""}`.trim()||"User"})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(c,{size:16}),B.jsx("span",{children:M&&h?.createdAt?new Date(h.createdAt).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0}):(new Date).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Description ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("textarea",{className:"raise-issue-field-textarea "+(M?"raise-issue-field-readonly":""),value:j,onChange:e=>N(e.target.value),placeholder:"Enter issue description",rows:4,readOnly:M})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Status ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select "+(M?"":"raise-issue-field-readonly"),value:T,onChange:e=>A(e.target.value),disabled:!M,children:[B.jsx("option",{value:Y.OPEN,children:Y.OPEN}),B.jsx("option",{value:Y.IN_PROGRESS,children:Y.IN_PROGRESS}),B.jsx("option",{value:Y.REJECTED,children:Y.REJECTED}),B.jsx("option",{value:Y.RESOLVE,children:Y.RESOLVE})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Assignee ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select",value:R,onChange:e=>L(e.target.value),children:[B.jsx("option",{value:"",children:"Unassigned"}),v.map(e=>B.jsx("option",{value:e,children:e},e))]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("div",{className:"raise-issue-priority-buttons",children:[B.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===k?"active":""),onClick:()=>E("Low"),children:"Low"}),B.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===k?"active":""),onClick:()=>E("Medium"),children:"Medium"}),B.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===k?"active":""),onClick:()=>E("High"),children:"High"})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[B.jsx(d,{size:16}),B.jsx("span",{children:"Comments"})]}),!D&&B.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),B.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(M?"raise-issue-field-readonly":""),value:D,onChange:e=>V(e.target.value),placeholder:"Add a comment...",rows:4,readOnly:M})]})]})}),B.jsx("div",{className:"raise-issue-modal-actions",children:B.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[M&&h&&B.jsxs(B.Fragment,{children:[T===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:async()=>{await P(Y.IN_PROGRESS)},disabled:F,children:F?"Processing...":"Accept"}),T===Y.IN_PROGRESS&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:async()=>{await P(Y.RESOLVE)},disabled:F,children:F?"Processing...":"Resolve"}),T===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:async()=>{await P(Y.REJECTED)},disabled:F,children:F?"Processing...":"Reject"})]}),!M&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save",onClick:async()=>{if(String(y||"").trim())if(String(j||"").trim()){O(!0);try{if(M&&h){const e={title:String(y||"").trim(),description:String(j||"").trim(),workOrderNumber:String(C||"").trim()||"",assetNumber:String(S||"").trim()||void 0,formTemplateId:h.formTemplateId||"",component:h.component||{},priority:k,assignee:String(R||"").trim()||void 0,status:T,comments:String(D||"").trim()||""};b&&h._id&&await b(h._id,e),J.showSuccess("Issue updated successfully"),s&&s(),i()}else{if(!r)return J.showError("Component is required"),void O(!1);if(!u||""===String(u||"").trim())return J.showError("Form template is required"),void O(!1);const e={...r,basic:{...r.basic,comments:String(m||"")}},t={title:String(y||"").trim(),workOrderNumber:String(C||"").trim()||void 0,assetNumber:String(S||"").trim()||void 0,component:e,description:String(j||"").trim(),formTemplateId:u,assignee:String(R||"").trim()||void 0,priority:k,status:T,comments:String(D||"").trim()||""};let n;f&&(n=await f(t,p||[])),J.showSuccess("Issue raised successfully"),s&&s(n),i()}}catch(e){const t=e?.message||e?.error?.message||(M?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");J.showError(t)}finally{O(!1)}}else J.showError("Description is required");else J.showError("Title is required")},disabled:F||!String(y||"").trim()||!String(j||"").trim(),children:F?"Saving...":"Save Changes"})]})})]})});return I(z,document.body)},X=({component:e,condition:s,currentValue:r,thresholdValue:o,formTemplateId:l,onIssueRaised:c,isIssueRaised:d=!1,compact:u=!1})=>{const[m,p]=t(!1),[h,f]=t(null),[b,g]=t(!1),[v,y]=t(!1);n(()=>{d&&y(!0)},[d]),n(()=>{y(!1)},[s?.id]);const x=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),j=i(async()=>{if(d||v){if(h)return void p(!0);g(!0);try{f(null),p(!0)}catch(e){console.error("Error fetching issue:",e),J.showError("Failed to load issue details")}finally{g(!1)}}else f(null),p(!0)},[d,v,l,e,h]),N=i(()=>{p(!1),d||v||f(null)},[d,v]),C=i(e=>{p(!1),f(e||null),y(!0),c&&s?.id&&c(s.id)},[c,s]);return d||v?B.jsx(B.Fragment,{children:m&&B.jsx(K,{isOpen:m,onClose:N,onSuccess:C,component:e,formTemplateId:l,notes:"",attachments:null,issue:h})}):u?B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content-compact",children:[B.jsx(a,{className:"threshold-alert-icon-compact",size:14}),B.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${x(s.operator)} ${o}`}),B.jsx("button",{type:"button",onClick:j,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),m&&B.jsx(K,{isOpen:m,onClose:N,onSuccess:C,component:e,formTemplateId:l,notes:"",attachments:null,issue:h})]}):B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content",children:[B.jsx("div",{className:"threshold-alert-header",children:B.jsxs("div",{className:"threshold-alert-title-group",children:[B.jsx(a,{className:"threshold-alert-icon",size:20}),B.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),B.jsxs("div",{className:"threshold-alert-message",children:[(()=>{const t=x(s.operator);return`${e.basic?.label||"Value"}: Value ${r} exceeds threshold ${t} ${o}`})(),B.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),B.jsx("div",{className:"threshold-alert-buttons",children:B.jsx("button",{type:"button",onClick:j,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),m&&B.jsx(K,{isOpen:m,onClose:N,onSuccess:C,component:e,formTemplateId:l,notes:"",attachments:null,issue:h})]})},Z=({id:e,properties:a,validationErrors:o={},formValue:l="",inputType:c="text",readonly:d=!1,disabled:u=!1,touchedFields:m={},formSubmitted:p=!1,mode:h="test",onValueChange:f,onBlur:b,onFocus:g,className:v="",hideLabel:y=!1,formTemplateId:x,onThresholdIssueRaised:j,raisedThresholdIssues:N=new Set})=>{const C=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?C(e.value):"label"in e?C(e.label):"":String(e||""),w=s(e),S=s(null);n(()=>{e!==w.current&&(console.warn(`[DfFormInput] Component ID changed from ${w.current} to ${e}`),w.current=e)},[e]);const $=C(l||a?.basic?.defaultValue||""),[k,E]=t($),[T,A]=t(!1),[I,R]=t(!1),[L,D]=t(new Set),[V,F]=t($),O=()=>{if(c)return c;const e=a?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},M=i(e=>{const t=(()=>{const e={};if(a?.validation?.required&&(e.required=!0),"email"===O()&&(e.email=!0),"text"===O()){const t=a.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===O()){const t=a.validation;t?.min&&(e.min=t.min),t?.max&&(e.max=t.max),void 0!==t?.lowerLimit&&(e.lowerLimit=t.lowerLimit),void 0!==t?.upperLimit&&(e.upperLimit=t.upperLimit)}return e})(),n={};let i=!0;const s="string"==typeof e?e:null!=e?String(e):"";if(!t.required||s&&""!==s.trim()||(n.required=!0,i=!1),t.email&&s&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(s)&&(n.email=!0,i=!1),t.minLength&&s&&s.length<t.minLength&&(n.minLength=!0,i=!1),t.maxLength&&s&&s.length>t.maxLength&&(n.maxLength=!0,i=!1),"number"===O()&&s&&""!==s.trim()){const e=s.trim();if(/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(e)){const s=parseFloat(e);if(isNaN(s)){/^-?\.?$/.test(e)||/^-?\d+\.?$/.test(e)||(n.pattern=!0,i=!1)}else delete n.pattern,void 0!==t.min&&s<t.min&&(n.min=!0,i=!1),void 0!==t.max&&s>t.max&&(n.max=!0,i=!1),void 0!==t.lowerLimit&&s<t.lowerLimit&&(n.lowerLimit=!0,i=!1),void 0!==t.upperLimit&&s>t.upperLimit&&(n.upperLimit=!0,i=!1),i&&delete n.pattern}else{const t=/^-?\.?$/.test(e)||/^-?\d+\.?$/.test(e);e.length>0&&!t&&(n.pattern=!0,i=!1)}}else"number"===O()&&s&&""===s.trim()?delete n.pattern:"number"!==O()||s&&""!==s||delete n.pattern;return{isValid:i,errors:n}},[a,O]),P=i(t=>{const n="string"==typeof t?t:null!=t?String(t):"";if(E(n),f){const t=M(n),i=w.current,s={id:i,value:n,isValid:t.isValid,errors:t.errors};i!==e&&console.error(`[DfFormInput] ID mismatch in handleValueChange! ref: ${i}, prop: ${e}`),f(s)}},[e,f,M,w]);n(()=>{T&&(m[e]=!0)},[T,e,m]),n(()=>{if("edit"===h){A(!1);E(a?.basic?.defaultValue||"")}else"test"===h&&(A(!1),E(""))},[h,a?.basic?.defaultValue]),n(()=>{const t=w.current,n=C(l||a?.basic?.defaultValue||"");n===k||I||""===n&&""!==String(k||"").trim()?""===n&&String(k||"").trim():null!=l&&(t===e?E(n):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${t}, prop id: ${e}`))},[l,k,I,a?.basic?.defaultValue,e]),n(()=>{p&&A(!0)},[p]),n(()=>{"test"!==h&&E("")},[h]);const z=i((e,t)=>{if(!t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(isNaN(n)||isNaN(i))return!1;switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}},[]),q=r(()=>a?.condition?.conditions||[],[a?.condition]);n(()=>{k!==V&&(D(new Set),F(k))},[k,V]);const _=r(()=>{if("test"!==h||!k||""===k)return null;const e=q.filter(e=>z(e,k));if(0===e.length)return null;for(const t of e)if(!L.has(t.id))return t;return null},[k,q,L,h,z,N]),W=i(e=>{D(t=>new Set(t).add(e))},[]),U=O(),G=u||d||a?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:`form-group ${(()=>{const e=a?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!y&&a.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[a.basic.label,a.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",ref:S,children:[B.jsx("input",{type:U,id:e,value:k,onChange:e=>{const t=e.target.value;P(t)},onFocus:()=>{R(!0),g&&g()},onBlur:()=>{if(R(!1),A(!0),"test"===h&&f){const t="string"==typeof k?k:null!=k?String(k):"",n=M(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};f(i)}b&&b()},placeholder:a.basic.placeholder,disabled:G,readOnly:d||a?.validation?.readonly,className:(()=>{const t="form-control";if("test"===h){const n=!M(k).isValid&&T,i=o[e]&&(T||p);return`${t} ${n||i?"is-invalid":""} ${v}`.trim()}return`${t} ${v}`.trim()})()}),B.jsx(H,{validationErrors:o,fieldId:e,touchedFields:m,formSubmitted:p,properties:a,localValidation:M(k),isTouched:T,mode:h})]})]}),_&&"test"===h&&(()=>{const e=N?.has(_.id)||!1,t=null!==S.current?.closest(".table-cell")||null!==S.current?.closest(".cell-content")||null!==S.current?.closest(".datagrid-table-view")||null!==S.current?.closest(".datagrid-list-view")||v.includes("table-cell")||v.includes("cell-content");return B.jsx(X,{component:a,condition:_,currentValue:k,thresholdValue:_.value,formTemplateId:x,onDismiss:()=>W(_.id),onIssueRaised:j,isIssueRaised:e,compact:t},`${_.id}-${e}`)})()]})},Q=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),s?.validation?.minLength&&e&&e.length<s.validation.minLength&&(t.minLength=!0,n=!1),s?.validation?.maxLength&&e&&e.length>s.validation.maxLength&&(t.maxLength=!0,n=!1),{isValid:n,errors:t}},[s]),N=i(t=>{if(v(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{""===g&&""!==a&&v(a)},[a]),n(()=>{d&&x(!0)},[d]),n(()=>{"test"!==u&&v("")},[u]);const C=l||o||s?.validation?.readonly,w=s?.validation?.rows||4;return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("textarea",{id:e,value:g,onChange:e=>{const t=e.target.value;N(t)},onFocus:()=>{h&&h()},onBlur:()=>{x(!0),p&&p()},placeholder:s.basic.placeholder,disabled:C,readOnly:o||s?.validation?.readonly,rows:w,className:`form-textarea ${!j(g).isValid&&y?"is-invalid":""} ${f}`.trim()}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})]})},ee=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=s?.validation?.multiple||!1,N=i(e=>{const t={};let n=!0;return s?.validation?.required&&(j?Array.isArray(e)&&0!==e.length||(t.required=!0,n=!1):(!e||"string"==typeof e&&""===e.trim())&&(t.required=!0,n=!1)),{isValid:n,errors:t}},[s,j]),C=i(t=>{if(v(t),m){const n=N(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,N]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{JSON.stringify(a)!==JSON.stringify(g)&&v(a)},[a,g]),n(()=>{d&&x(!0)},[d]);const w=l||o||s?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("select",{id:e,value:g,onChange:e=>{if(j){const t=Array.from(e.target.selectedOptions,e=>e.value);C(t)}else C(e.target.value)},onFocus:()=>{h&&h()},onBlur:()=>{x(!0),p&&p()},disabled:w,multiple:j,className:`form-select ${!N(g).isValid&&y?"is-invalid":""} ${f}`.trim(),children:[!j&&B.jsx("option",{value:"",children:s.basic.placeholder||"Select an option"}),(s.options||[]).map((e,t)=>B.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:N(g),isTouched:y,mode:u})]})]})},te=({id:e,properties:s,validationErrors:r={},formValue:a=[],readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(!1),y=Array.isArray(a)?a:[],x=i(e=>{const t={};let n=!0;return s?.validation?.required&&0===e.length&&(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),j=i(t=>{if(m){const n=x(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,x,y]),N=(e,t)=>{let n;n=t?[...y,e]:y.filter(t=>t!==e),j(n)},C=()=>{h&&h()},w=()=>{v(!0),p&&p()};n(()=>{g&&(c[e]=!0)},[g,e,c]),n(()=>{},[a,e,y]),n(()=>{d&&v(!0)},[d]);const S=l||o||s?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group checkbox-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${s?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!b&&s.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:x(y),isTouched:g,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:x(y),isTouched:g,mode:u})]})})})},ne=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),N=i(t=>{if(v(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=e=>{N(e)},w=()=>{h&&h()},S=()=>{x(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{a!==g&&v(a)},[a,g]),n(()=>{d&&x(!0)},[d]);const $=l||o||s?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group radio-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${s?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!b&&s.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:g===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:$||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:g===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:$||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})})})},ie=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),N=i(t=>{if(v(t),x(!0),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=()=>{h&&h()},w=()=>{x(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{a!==g&&v(a)},[a,g]),n(()=>{d&&x(!0)},[d]);const S=()=>s?.basic?.inlineLayout?"inline-layout":"grid-layout",$=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},k=e=>{if(void 0!==e?.icon&&""!==e.icon)return e.icon;return"pass"===$(e?.value||e)?"✓":"×"},E=(e,t)=>e?.color||e?.backgroundColor?{color:t?"#ffffff":e.color||"#00814b",backgroundColor:t?e.color||"#00814b":e.backgroundColor||"#34bd4914",borderColor:e.color||"#00814b"}:{},T=e=>{if(e?.color||e?.backgroundColor)return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===$(e?.value||e)?"pass-button":"fail-button")},A=l||o||s?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsx("div",{className:`form-group segment-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${f}`,children:!b&&s.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(s.options||[]).map((t,n)=>{const i=g===t.value,s=E(t,i),r=T(t),a=k(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!A&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:A||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:r,style:Object.keys(s).length>0?s:void 0,children:[a&&B.jsx("span",{className:"segment-icon",children:a}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})]}):B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(s.options||[]).map((t,n)=>{const i=g===t.value,s=E(t,i),r=T(t),a=k(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!A&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:A||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:r,style:Object.keys(s).length>0?s:void 0,children:[a&&B.jsx("span",{className:"segment-icon",children:a}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})},se=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const g=i(e=>{if(!e)return"";if("string"==typeof e){if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e))return e;const t=new Date(e);if(!isNaN(t.getTime())){const e=s.name||"",n=s.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("datetime"===n){return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}T${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}return e}if(e instanceof Date){if(isNaN(e.getTime()))return"";const t=s.name||"",n=s.basic?.dateTimeMode||("datetime-picker"===t?"datetime":"date");if("datetime"===n){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}T${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}if("object"==typeof e&&null!==e){if("value"in e&&e.value)return g(e.value);if("date"in e&&e.date)return g(e.date);try{const t=String(e),n=new Date(t);if(!isNaN(n.getTime()))return g(n)}catch(e){}return""}return""},[s]),v=g(a),[y,x]=t(v),[j,N]=t(!1),[C,w]=t(!1),S=i(e=>{const t={};let n=!0;const i=s.name||"",r=s.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"),a=e?String(e).trim():"";if(s?.validation?.required&&(!a||""===a))return t.required=!0,n=!1,{isValid:n,errors:t};if(a&&""!==a)if("time"===r){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(a))return t.invalidDate=!0,n=!1,{isValid:n,errors:t}}else if("datetime"===r){const e=new Date(a);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(s?.validation?.minDate){const i=new Date(s.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date and time must be on or after ${i.toLocaleDateString()}`,n=!1)}if(s?.validation?.maxDate){const i=new Date(s.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date and time must be on or before ${i.toLocaleDateString()}`,n=!1)}}else{const e=new Date(a);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(s?.validation?.minDate){const i=new Date(s.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date must be on or after ${i.toLocaleDateString()}`,n=!1)}if(s?.validation?.maxDate){const i=new Date(s.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date must be on or before ${i.toLocaleDateString()}`,n=!1)}}return{isValid:n,errors:t}},[s]),$=i(t=>{if(x(t),m){const n=S(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,S]);n(()=>{j&&(c[e]=!0)},[j,e,c]),n(()=>{const e=g(a);e===y||C||x(e)},[a,y,C,g]),n(()=>{d&&N(!0)},[d]);const k=l||o||s?.validation?.readonly,E=s.name||"",T=s.basic?.dateTimeMode||("datetime-picker"===E?"datetime":"date"),A=(()=>{switch(T){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("input",{type:A,id:e,value:y,onChange:e=>{const t=e.target.value;$(t)},onFocus:()=>{w(!0),h&&h()},onBlur:()=>{if(w(!1),N(!0),m){const t=S(y),n={id:e,value:y,isValid:t.isValid,errors:t.errors};m(n)}p&&p()},disabled:k,readOnly:o||s?.validation?.readonly,min:s?.validation?.minDate,max:s?.validation?.maxDate,className:`form-date ${!S(y).isValid&&j?"is-invalid":""} ${f}`.trim()}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:S(y),isTouched:j,mode:u})]})]})},re=({id:e,properties:r,validationErrors:a={},formValue:o="",readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="preview",onValueChange:p,onBlur:h,onFocus:f,className:b="",hideLabel:g=!1})=>{const v=s(null),[y,x]=t(!1),[j,N]=t(!1),[C,w]=t(o),[S,$]=t(!1),k=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),E=i(t=>{if(w(t),p){const n=k(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};p(i)}},[e,p,k]),T=i(()=>{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}},[]),A=i(t=>{if(!t)return;const n=v.current;if(!n)return;const i=n.getContext("2d");if(!i)return;const s=new Image;s.onload=()=>{i.clearRect(0,0,n.width,n.height);const e=T();i.fillStyle=e.backgroundColor,i.fillRect(0,0,n.width,n.height);const t=n.width/n.height,r=s.width/s.height;let a=n.width,o=n.height,l=0,c=0;r>t?(o=n.width/r,c=(n.height-o)/2):(a=n.height*r,l=(n.width-a)/2),i.drawImage(s,l,c,a,o)},s.onerror=n=>{console.error("DfFormSignature: error loading image",{id:e,error:n,dataURL:t.substring(0,50)+"..."})},s.src=t},[T,e]),I=i(()=>{const e=v.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height,e.style.width=n.width+"px",e.style.height=n.height+"px";const i=T();t.strokeStyle=i.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?A(C):(t.fillStyle=i.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,T,A]),R=i(()=>{setTimeout(()=>{I()},100)},[I]);n(()=>{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 L=i(e=>{const t=v.current;if(!t)return{x:0,y:0};const n=t.getBoundingClientRect(),i=t.width/n.width,s=t.height/n.height,r=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,a=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(r-n.left)*i,y:(a-n.top)*s}},[]),D=e=>{if(l||c||r?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),x(!0),N(!0);const t=v.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:s}=L(e),a=T();n.strokeStyle=a.strokeColor,n.lineWidth=2,n.lineCap="round",n.lineJoin="round",n.beginPath(),n.moveTo(i,s)},V=e=>{if(!y)return;e.preventDefault(),e.stopPropagation();const t=v.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:s}=L(e);n.lineTo(i,s),n.stroke()},F=()=>{if(!y)return;x(!1),$(!0);const e=v.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const n=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<n.length;e+=4){const t=n[e],i=n[e+1],s=n[e+2];if(n[e+3]>0&&(t<255||i<255||s<255))return!0}})(e);const t=e.toDataURL("image/png");w(t),E(t),setTimeout(()=>{$(!1)},100)}else $(!1)},O=i(()=>{const e=v.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=T();if(t.strokeStyle=n.strokeColor,C){const i=C,s=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,s.width,s.height),i&&A(i)}else{const i=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,i.width,i.height)}},[T,C,A]);n(()=>{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]);n(()=>{j&&(d[e]=!0)},[j,e,d]),n(()=>{if(!(o===C||y||S||""!==C&&""===o)){if(o===C)return;w(o),o&&A(o)}},[o,C,y,S]),n(()=>{u&&N(!0)},[u]),n(()=>{if("test"!==m){w("");const e=v.current;if(e){const t=e.getContext("2d");if(t){const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height;const i=T();t.fillStyle=i.backgroundColor,t.fillRect(0,0,n.width,n.height)}}}},[m]),n(()=>{I()},[m]);const M=c||l||r?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[B.jsx("canvas",{ref:v,id:e,className:`form-signature ${!k(C).isValid&&j?"is-invalid":""} ${b}`.trim(),onMouseDown:D,onMouseMove:V,onMouseUp:F,onMouseLeave:F,onTouchStart:D,onTouchMove:V,onTouchEnd:F,onFocus:()=>{f&&f()},onBlur:()=>{h&&h()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:M?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!M&&B.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=v.current;if(!t)return;const n=t.getBoundingClientRect();t.width=n.width,t.height=n.height;const i=t.getContext("2d");if(!i)return;const s=T();i.fillStyle=s.backgroundColor,i.fillRect(0,0,n.width,n.height),i.strokeStyle=s.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"})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:k(C),isTouched:j,mode:m})]})]})},ae=({id:e,properties:r,validationErrors:a={},formValue:o=null,readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="test",onValueChange:p,onBlur:h,onFocus:f,className:b="",hideLabel:g=!1})=>{const[v,y]=t([]),[x,j]=t(!1),[N,C]=t(!1),w=s(null),S=i(t=>{if(!t)return[];const n=Array.isArray(t)?t:Array.from(t),i=[];return n.forEach((t,n)=>{if(t&&"object"==typeof t&&!(t instanceof File)&&!(t instanceof Blob)){const s=t;if(s.data||s.url||s.name&&s.type){const t=s.name||s.fileName||`file-${n}`,r=s.size||s.fileSize||0,a=s.type||s.fileType||s.mimeType||"";let o;if(s.url)o=s.url;else if(s.data){const e=s.data;if("string"==typeof e)if(e.startsWith("data:"))o=e;else{const t=e.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>10){let e=a;e||(e=t.startsWith("/9j/")||t.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":t.startsWith("iVBORw0KGgo")?"image/png":t.startsWith("R0lGOD")?"image/gif":t.startsWith("UklGR")?"image/webp":"image/png"),o=`data:${e};base64,${t}`}else o=e}}const l=new File([],t,{type:a});return void i.push({file:l,id:`${e}-file-${n}`,size:r,type:a,name:t,preview:o})}}let s,r,a=0,o="",l="";if(t instanceof File||t instanceof Blob){const e=t;if(a=e.size||0,o=e.type||"",l=e.name||`file-${n}`,r=e,o.startsWith("image/"))try{s=URL.createObjectURL(e)}catch(e){console.error("Error creating object URL:",e),s=void 0}}else if("string"==typeof t){const e=t,i=e.replace(/\s/g,""),a=i.length>50&&/^[A-Za-z0-9+/=]+$/.test(i)&&!e.startsWith("http")&&!e.startsWith("https")&&!e.startsWith("data:")&&!e.startsWith("blob:")&&!e.startsWith("/");let c=e;if(a){let e="image/png";i.startsWith("/9j/")||i.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?e="image/jpeg":i.startsWith("iVBORw0KGgo")?e="image/png":i.startsWith("R0lGOD")?e="image/gif":i.startsWith("UklGR")&&(e="image/webp"),c=`data:${e};base64,${i}`}let d="";if(c.startsWith("data:")){const e=c.match(/filename=([^;]+)/i);if(e)d=decodeURIComponent(e[1]);else{const e=c.match(/data:([^;]+)/);if(e){const t=e[1];d=`file-${n+1}.${t.includes("image")?t.includes("jpeg")?"jpg":"png":t.includes("pdf")?"pdf":t.includes("word")?"doc":t.includes("excel")?"xls":"file"}`}else d=`file-${n+1}`}}else if(c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))try{const t=new URL(e),i=t.pathname.split("/").pop()||"";if(i&&i.includes("."))d=decodeURIComponent(i);else{const e=t.searchParams.get("filename")||t.searchParams.get("name");d=e?decodeURIComponent(e):`file-${n+1}`}}catch(t){const i=e.lastIndexOf("/"),s=i>=0?e.substring(i+1):e,r=s.indexOf("?"),a=r>=0?s.substring(0,r):s;d=a&&a.includes(".")?decodeURIComponent(a):`file-${n+1}`}else d=`file-${n+1}`;if(l=d||`file-${n+1}`,c.startsWith("data:")){const e=c.indexOf(";");o=e>5?c.substring(5,e):"application/octet-stream"}else{const e=c.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i)||l.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(e){o={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 o=a?"image/png":"application/octet-stream"}(c.startsWith("data:image")||c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))&&(s=c),r=new File([],l,{type:o})}else{if(!t||"object"!=typeof t)return;{const e=t;if(l=e.name||e.fileName||`file-${n}`,a=e.size||e.fileSize||0,o=e.type||e.fileType||e.mimeType||"",e.url||e.path)s=e.url||e.path;else if(o.startsWith("image/")&&e.data){const t=e.data;if("string"==typeof t)if(t.startsWith("data:"))s=t;else{const e=t.replace(/\s/g,"");s=/^[A-Za-z0-9+/=]+$/.test(e)&&e.length>50?`data:${o};base64,${e}`:t}else s=void 0}r=new File([],l,{type:o})}}i.push({file:r,id:`${e}-file-${n}`,size:a,type:o,name:l,preview:s})}),i},[e]),$=i(()=>({isValid:!0,errors:{}}),[]),k=i(t=>{if(l||c)return;const n=S(t),i=v.length>0?[...v,...n]:n,s=r?.validation?.maxFiles||1/0,a=i.slice(0,s);if(y(a),C(!0),p){const t=$(),n={id:e,value:a.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}},[v,r,l,c,p,$,S,e]),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]},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")?"📦":"📁";n(()=>{N&&(d[e]=!0)},[N,e,d]),n(()=>{("edit"===m||"test"===m)&&C(!1)},[m]),n(()=>{const e=S(o);null!=o&&(Array.isArray(o)&&o.length>0||"string"==typeof o&&""!==String(o).trim()||"object"==typeof o&&!Array.isArray(o)&&Object.keys(o).length>0)||0===v.length&&null!=o?y(e):(null==o||Array.isArray(o)&&0===o.length)&&v.length>0&&y([])},[o,S,v.length]),n(()=>{u&&C(!0)},[u]),n(()=>()=>{v.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[v]);const A=()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"},I=c||l||r?.validation?.readonly,R=r?.validation?.multiple||!1,L=r?.validation?.accept||"*/*",D=r?.validation?.maxFiles||1/0,V=v.length<D&&(R||D>1),F="edit"===m,O="preview"===m||"test"===m,M=v.filter(e=>e.type.startsWith("image/")),P=v.filter(e=>!e.type.startsWith("image/")),z=M.length>0;return O&&z?B.jsxs("div",{className:`form-group ${A()}`,children:[!g&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic?.label||"Attachments",r.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:"file-image-display",children:[M.map(e=>B.jsxs("div",{className:"file-image-container",children:[e.preview&&B.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),B.jsxs("div",{className:"file-image-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:E(e.size)})]})]},e.id)),P.length>0&&B.jsxs("div",{className:"file-other-files",children:[B.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),P.map(e=>B.jsxs("div",{className:"file-item-minimal",children:[B.jsx("div",{className:"file-icon",children:T(e.type)}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:E(e.size)})]})]},e.id))]})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:$(),isTouched:N,mode:m})]})]}):B.jsxs("div",{className:`form-group ${A()}`,children:[!g&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic?.label||"Attachments",r.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:`file-upload-area ${x?"drag-over":""} ${l?"readonly":""} ${c?"disabled":""} ${b}`.trim(),onDragOver:e=>{e.preventDefault(),l||c||j(!0)},onDragLeave:e=>{e.preventDefault(),j(!1)},onDrop:e=>{if(e.preventDefault(),j(!1),l||c)return;const t=e.dataTransfer.files;t.length>0&&k(t)},onClick:e=>{const t=e.target,n=null!==t.closest(".file-item"),i=null!==t.closest(".file-remove");!F||I||0!==v.length||n||i||w.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(C(!0),"test"===m&&p){const t=$(),n={id:e,value:v.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}h&&h()},tabIndex:I?-1:0,children:[B.jsx("input",{ref:w,type:"file",id:e,multiple:R,accept:L,onChange:e=>{const t=e.target.files;t&&t.length>0&&(k(t),e.target.value="")},disabled:I,style:{display:"none"}}),0===v.length?B.jsxs("div",{className:"upload-placeholder",onClick:e=>{e.stopPropagation(),F&&!I&&w.current?.click()},children:[B.jsx("div",{className:"upload-icon",children:"📁"}),B.jsx("div",{className:"upload-text",children:r.basic.placeholder&&B.jsx("p",{className:"upload-hint",children:r.basic.placeholder})})]}):B.jsx("div",{className:"file-list",children:v.map(t=>B.jsxs("div",{className:"file-item",children:[B.jsx("div",{className:"file-preview",children:t.preview?B.jsx("img",{src:t.preview,alt:t.name,className:"file-image"}):B.jsx("div",{className:"file-icon",children:T(t.type)})}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:t.name,children:t.name}),B.jsx("div",{className:"file-size",children:E(t.size)})]}),F&&!I&&B.jsx("button",{type:"button",className:"file-remove",onClick:n=>{n.stopPropagation(),(t=>{if(l||c)return;const n=v.filter(e=>e.id!==t);if(y(n),C(!0),p){const t=$(),i={id:e,value:n.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(i)}})(t.id)},"aria-label":`Remove ${t.name}`,children:"✕"})]},t.id))})]}),v.length>0&&V&&!I&&F&&B.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!I&&w.current&&F&&(w.current.value="",w.current.click())},"aria-label":"Add more files",children:[B.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B.jsx("path",{d:"M12 5v14M5 12h14"})}),B.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:$(),isTouched:N,mode:m})]})]})},oe=({id:e,properties:r,validationErrors:a={},formValue:l=null,readonly:c=!1,disabled:d=!1,touchedFields:h={},formSubmitted:f=!1,mode:b="test",onValueChange:g,onBlur:v,onFocus:y,className:x="",hideLabel:j=!1})=>{const[N,C]=t(l),[w,S]=t(!1),[$,k]=t(""),[E,T]=t(!1),[A,I]=t(!1),[R,L]=t({lat:40.7128,lng:-74.006}),[D,V]=t(null),[F,O]=t(10),[M,P]=t(""),[z,q]=t(!1),_=s(null),[W,U]=t(!1),[G,J]=t(null),[Y,K]=t(!1);n(()=>{if(l&&l.latitude&&l.longitude){40.7128===l.latitude&&-74.006===l.longitude||(C(l),V({lat:l.latitude,lng:l.longitude,isCurrentLocation:!1}),L({lat:l.latitude,lng:l.longitude}))}else null==l&&(C(null),V(null))},[l]),n(()=>{A&&40.7128===R.lat&&R.lng},[A,R]),n(()=>{(c||d)&&(A&&I(!1),M&&P(""),W&&(U(!1),J(null)))},[c,d]);const X=i(async(e,t)=>{K(!0);try{const n=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),i=await n.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{K(!1)}return{placeName:"",city:"",country:""}},[]),Z=i(async(t,n,i)=>{const s=await X(t,n),r={latitude:t,longitude:n,timestamp:Date.now(),placeName:s.placeName,city:s.city,country:s.country,address:s.placeName,...i};if(C(r),V({lat:t,lng:n,isCurrentLocation:!1}),T(!0),g){g({id:e,value:r,isValid:!0,errors:{}})}},[X,e,g]),Q=i(async()=>{if(c||d)return;S(!0),k("");if(void 0!==window.Capacitor)try{const{Geolocation:e}=window.Capacitor.Plugins;if(e)try{if("granted"!==(await e.requestPermissions()).location)return S(!1),void k("Location permission is required. Please enable location access in your device settings.");const t=await e.getCurrentPosition({enableHighAccuracy:r.validation?.enableHighAccuracy??!0,timeout:r.validation?.timeout??1e4,maximumAge:r.validation?.maximumAge??3e5}),n=t.coords.latitude,i=t.coords.longitude;return V({lat:n,lng:i,isCurrentLocation:!0}),L({lat:n,lng:i}),T(!0),await Z(n,i,{accuracy:t.coords.accuracy,timestamp:Date.now()}),S(!1),void k("")}catch(e){return S(!1),void(e.message?.includes("permission")||e.message?.includes("denied")?k("Location permission is required. Please enable location access in your device settings."):e.message?.includes("timeout")?k("Location request timed out. Please try again."):k("Unable to retrieve your location. Please try again."))}}catch(e){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return S(!1),void k("Geolocation is not supported by this browser.");const e={enableHighAccuracy:r.validation?.enableHighAccuracy??!0,timeout:r.validation?.timeout??1e4,maximumAge:r.validation?.maximumAge??3e5};navigator.geolocation.getCurrentPosition(async e=>{const t=e.coords.latitude,n=e.coords.longitude;V({lat:t,lng:n,isCurrentLocation:!0}),L({lat:t,lng:n}),T(!0),await Z(t,n,{accuracy:e.coords.accuracy,timestamp:e.timestamp}),S(!1),k("")},e=>{S(!1);let t="Unable to retrieve your location.";switch(e.code){case e.PERMISSION_DENIED:t="Location access denied by user. Please enable location access in your browser/device settings.";break;case e.POSITION_UNAVAILABLE:t="Location information is unavailable.";break;case e.TIMEOUT:t="Location request timed out. Please try again."}k(t)},e)},[c,d,r,Z]),ee=i(()=>{if(!c&&!d&&(C(null),V(null),k(""),T(!0),g)){g({id:e,value:null,isValid:!0,errors:{}})}},[c,d,e,g]),te=i(()=>{c||d||I(!A)},[c,d,A]),ne=i((e,t,n,i,s,r)=>{const a=e-s/2,o=t-r/2,l=156543.03392*Math.cos(n.lat*Math.PI/180)/Math.pow(2,i),c=a*l,d=o*l;return{lat:n.lat+d/111320,lng:n.lng+c/(111320*Math.cos(n.lat*Math.PI/180))}},[]),ie=i(e=>{c||d||!_.current||0===e.button&&(U(!0),J({x:e.clientX,y:e.clientY}),e.preventDefault())},[c,d]),se=i(e=>{if(!W||!G||!_.current)return;const t=e.clientX-G.x,n=e.clientY-G.y,i=156543.03392*Math.cos(R.lat*Math.PI/180)/Math.pow(2,F),s=-n*i/111320,r=t*i/(111320*Math.cos(R.lat*Math.PI/180));L({lat:R.lat+s,lng:R.lng+r}),J({x:e.clientX,y:e.clientY})},[W,G,R,F]),re=i(async e=>{if(!_.current)return;if(W&&G){const t=Math.abs(e.clientX-G.x),n=Math.abs(e.clientY-G.y);if(t>5||n>5)return U(!1),void J(null)}if(c||d)return U(!1),void J(null);const t=_.current.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,{lat:s,lng:r}=ne(n,i,R,F,t.width,t.height);await Z(s,r),U(!1),J(null)},[c,d,_,R,F,ne,Z,W,G]),ae=i(async t=>{if(t.trim()&&!c&&!d){q(!0),k("");try{const n=await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(t)}&limit=5&addressdetails=1`),i=await n.json();if(i&&i.length>0){const t=i[0],n=parseFloat(t.lat),s=parseFloat(t.lon),r=t.address||{},a={latitude:n,longitude:s,address:t.display_name,placeName:t.display_name,city:r.city||r.town||r.village||r.municipality||"",country:r.country||"",timestamp:Date.now()};if(C(a),V({lat:n,lng:s,isCurrentLocation:!1}),L({lat:n,lng:s}),T(!0),g){g({id:e,value:a,isValid:!0,errors:{}})}}else k("No locations found for your search.")}catch(e){k("Failed to search for location. Please try again.")}finally{q(!1)}}},[c,d,e,g]),oe=()=>{y&&y()},le=()=>{T(!0),v&&v()},ce=d||c||r?.validation?.readonly,de=r?.basic?.label||"Location",ue=r?.basic?.description||"";return B.jsxs("div",{className:`form-group ${j?"no-label":""} ${x}`,children:[!j&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[de,r?.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),ue&&B.jsx("div",{className:"form-group-description",children:ue}),B.jsxs("div",{className:"location-wrapper",children:[!(c&&N)&&B.jsxs("div",{className:"location-controls",children:[B.jsx("button",{type:"button",className:"location-btn "+(w?"loading":""),onClick:Q,disabled:ce||w,onFocus:oe,onBlur:le,tabIndex:ce?-1:0,children:w?B.jsxs(B.Fragment,{children:[B.jsx(u,{size:16,className:"loading-spinner"}),"Getting Location..."]}):B.jsxs(B.Fragment,{children:[B.jsx(m,{size:16}),"Get Current Location"]})}),B.jsxs("button",{type:"button",className:"location-btn secondary",onClick:te,disabled:ce,onFocus:oe,onBlur:le,tabIndex:ce?-1:0,children:[B.jsx(p,{size:16}),A?"Hide Map":"Choose on Map"]})]}),N&&B.jsxs("div",{className:"location-display",children:[!c&&B.jsx("button",{type:"button",className:"location-clear-btn",onClick:ee,disabled:ce,title:"Clear location",children:B.jsx(o,{size:16})}),N.placeName&&B.jsxs("div",{className:"location-place-name",children:[B.jsx("strong",{children:"Place:"})," ",N.placeName]}),(N.city||N.country)&&B.jsxs("div",{className:"location-address",children:[B.jsx("strong",{children:"Address:"})," ",[N.city,N.country].filter(Boolean).join(", ")]}),B.jsxs("div",{className:"location-coordinates",children:[B.jsx("strong",{children:"Coordinates:"})," ",(pe=N.latitude,he=N.longitude,void 0===pe||void 0===he||isNaN(pe)||isNaN(he)?"":`${Number(pe).toFixed(6)}, ${Number(he).toFixed(6)}`)]}),N.accuracy&&B.jsxs("div",{className:"location-accuracy",children:[B.jsx("strong",{children:"Accuracy:"})," ",(me=N.accuracy,me?`±${Math.round(me)}m`:"")]}),N.timestamp&&B.jsxs("div",{className:"location-timestamp",children:[B.jsx("strong",{children:"Captured:"})," ",new Date(N.timestamp).toLocaleString()]})]}),A&&!c&&B.jsxs("div",{className:"location-map-container",children:[B.jsxs("div",{className:"location-map-header",children:[B.jsx("h4",{children:"Select Location on Map"}),B.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),B.jsx("div",{className:"location-search",children:B.jsx("form",{onSubmit:e=>{e.preventDefault(),M.trim()&&ae(M)},className:"search-form",children:B.jsxs("div",{className:"search-input-group",children:[B.jsx("input",{type:"text",value:M,onChange:e=>{P(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:ce||z}),B.jsx("button",{type:"submit",className:"search-btn",disabled:ce||z||!M.trim(),children:z?B.jsx(u,{size:16,className:"loading-spinner"}):"Search"})]})})}),B.jsxs("div",{ref:_,className:"location-map "+(W?"dragging":""),onMouseDown:ie,onMouseMove:se,onMouseUp:re,onMouseLeave:()=>{U(!1),J(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:W?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${F}/${Math.floor((R.lng+180)/360*Math.pow(2,F))}/${Math.floor((1-Math.log(Math.tan(R.lat*Math.PI/180)+1/Math.cos(R.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,F))}.png) center/cover no-repeat`,userSelect:"none"},children:[D&&B.jsx("div",{className:"map-marker "+(D.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:B.jsx(p,{size:24})}),B.jsx("div",{className:"map-center-indicator",style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"4px",backgroundColor:"var(--df-color-primary)",borderRadius:"50%",zIndex:5}}),B.jsxs("div",{className:"map-controls",children:[B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.min(18,e+1)),disabled:F>=18,children:"+"}),B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.max(1,e-1)),disabled:F<=1,children:"−"})]})]}),B.jsxs("div",{className:"location-map-instructions",children:[B.jsx("p",{children:B.jsx("strong",{children:"Instructions:"})}),B.jsxs("ul",{children:[B.jsx("li",{children:"Search for a place using the search box above"}),B.jsx("li",{children:"Click anywhere on the map to select a location"}),B.jsx("li",{children:"Drag the map to pan around"}),B.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),B.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),Y&&B.jsxs("div",{className:"location-loading",children:[B.jsx(u,{size:16,className:"loading-spinner"}),B.jsx("span",{children:"Loading address details..."})]})]}),$&&B.jsx("div",{className:"location-error",children:$})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:h,formSubmitted:f,properties:r,localValidation:{isValid:!0,errors:{}},isTouched:E,mode:b})]});var me,pe,he},le=({id:e,properties:t,className:n="",hideLabel:i=!1})=>{const s=t.styles?.level??t.basic.level??1,r=t.basic.label,a=()=>{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${s} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${n}`.trim(),style:a()};switch(s){case 1:default:return B.jsx("h1",{...i,children:r});case 2:return B.jsx("h2",{...i,children:r});case 3:return B.jsx("h3",{...i,children:r});case 4:return B.jsx("h4",{...i,children:r});case 5:return B.jsx("h5",{...i,children:r});case 6:return B.jsx("h6",{...i,children:r})}})()},ce=({id:e,properties:r,mode:a="preview",formValue:o,onValueChange:l,className:c="",hideLabel:d=!1})=>{const[u,m]=t(""),[p,y]=t(r.validation?.listStyle||"numbers"),[x,j]=t("#000000"),N=s(null),C=s(null),w=s(!1),S="edit"===a,$=s({instructions:[],listStyle:"numbers",formValue:void 0}),k=s(a);n(()=>{let e=[],t="numbers";if(null!=o&&("object"==typeof o&&o.instructions?(Array.isArray(o.instructions)?e=o.instructions:"string"==typeof o.instructions&&(e=[o.instructions]),o.listStyle&&(t=o.listStyle)):Array.isArray(o)?e=o:"string"==typeof o&&(e=[o])),0===e.length&&r.basic?.value){const n=r.basic.value;n&&"object"==typeof n&&!Array.isArray(n)&&n.instructions?(Array.isArray(n.instructions)?e=n.instructions:"string"==typeof n.instructions&&(e=[n.instructions]),n.listStyle&&"string"==typeof n.listStyle&&(t=n.listStyle)):Array.isArray(n)?e=n:"string"==typeof n&&(e=[n])}0===e.length&&r.basic?.instructions&&(Array.isArray(r.basic.instructions)?e=r.basic.instructions:"string"==typeof r.basic.instructions&&(e=[r.basic.instructions])),t&&"numbers"!==t||(t=r.validation?.listStyle||r.basic?.value?.listStyle||"numbers");const n=JSON.stringify(e)!==JSON.stringify($.current.instructions)||t!==$.current.listStyle,i=a!==k.current,s=JSON.stringify(o)!==JSON.stringify($.current.formValue),l=!$.current.formValue||Array.isArray($.current.formValue)&&0===$.current.formValue.length||"string"==typeof $.current.formValue&&""===$.current.formValue.trim(),c=null!=o&&(Array.isArray(o)&&o.length>0||"string"==typeof o&&""!==o.trim()||"object"==typeof o&&Object.keys(o).length>0);if(n||i||s||l&&c){const s=e=>"string"!=typeof e?e:e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))),r=e.map(e=>"string"==typeof e?s(e):e),l=r.some(e=>"string"==typeof e&&/<[^>]+>/.test(e));let c="";if(r.length>0)if(l)c=r.join("");else{const e="numbers"===t?"ol":"bullets"===t?"ul":"div",n=r.filter(e=>e&&"string"==typeof e).map(e=>`<li>${e.replace(/\n/g,"<br>")}</li>`).join("");c="div"===e?r.filter(e=>e&&"string"==typeof e).map(e=>`<div>${e.replace(/\n/g,"<br>")}</div>`).join(""):`<${e}>${n}</${e}>`}y(t),m(c),S&&N.current&&(i||n&&N.current.innerHTML.trim()!==c.trim())&&(N.current.innerHTML=c),$.current={instructions:e,listStyle:t,formValue:o},k.current=a}},[o,r.basic?.instructions,r.validation?.listStyle,a,S]),n(()=>{if(S&&N.current){const e=N.current.innerHTML.trim();u.trim()===e||w.current||(N.current.innerHTML=u)}if(w.current){const e=setTimeout(()=>{w.current=!1},200);return()=>clearTimeout(e)}},[u,S]);const E=i(()=>{if(!N.current)return;w.current=!0;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}t!==u&&m(t)},[e,p,l,u]),T=i(()=>{if(!N.current)return;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}m(t),w.current=!1},[e,p,l]),A=i((e,t)=>{document.execCommand(e,!1,t),N.current?.focus(),E()},[E]),I=i(()=>{A("bold")},[A]),R=i(()=>{A("italic")},[A]),L=i(e=>{const t=e.target.value;j(t),A("foreColor",t)},[A]),D=i(t=>{if(y(t),!N.current)return;const n=window.getSelection(),i=n&&n.rangeCount>0?n.getRangeAt(0):null;let s=N.current.innerHTML;if("numbers"===t){if(s=s.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!s.includes("<ol>")&&!s.includes("<ul>")){const e=s.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(s="<ol>"+e.map(e=>`<li>${e}</li>`).join("")+"</ol>")}}else if("bullets"===t){if(s=s.replace(/<ol>/gi,"<ul>").replace(/<\/ol>/gi,"</ul>"),!s.includes("<ol>")&&!s.includes("<ul>")){const e=s.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(s="<ul>"+e.map(e=>`<li>${e}</li>`).join("")+"</ul>")}}else s=s.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(N.current.innerHTML=s,m(s),i&&n)try{n.removeAllRanges(),n.addRange(i)}catch(e){}if(E(),l){l({id:e,value:{instructions:s?[s]:[],listStyle:t},isValid:!0,errors:{}})}},[e,E,l]),V=i(e=>{const t=e.target.files?.[0];if(!t||!t.type.startsWith("image/"))return;const n=new FileReader;n.onload=e=>{const t=e.target?.result;if(t&&N.current){const e=document.createElement("img");e.src=t,e.style.maxWidth="100%",e.style.height="auto";const n=window.getSelection();if(n&&n.rangeCount>0){const t=n.getRangeAt(0);t.deleteContents(),t.insertNode(e)}else N.current.appendChild(e);E()}},n.readAsDataURL(t),C.current&&(C.current.value="")},[E]),F=i(e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain"),n=window.getSelection();if(n&&n.rangeCount>0){const e=n.getRangeAt(0);e.deleteContents();const i=document.createTextNode(t);e.insertNode(i),e.setStartAfter(i),e.collapse(!0),n.removeAllRanges(),n.addRange(e)}E()},[E]),O=i(e=>document.queryCommandState(e),[]);return B.jsxs("div",{className:`form-group instruction-group ${c}`,children:[!d&&B.jsx("label",{htmlFor:e,className:"instruction-label",children:"Instructions"}),S?B.jsxs("div",{className:"instruction-rich-editor",children:[B.jsxs("div",{className:"instruction-toolbar",children:[B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+(O("bold")?"active":""),onClick:I,title:"Bold","aria-label":"Bold",children:B.jsx(h,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+(O("italic")?"active":""),onClick:R,title:"Italic","aria-label":"Italic",children:B.jsx(f,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsx("div",{className:"toolbar-group",children:B.jsxs("div",{className:"color-picker-wrapper",children:[B.jsx("input",{type:"color",value:x,onChange:L,className:"color-picker-input",title:"Text Color"}),B.jsx("label",{className:"color-picker-label",title:"Text Color",children:B.jsx("span",{style:{color:x},children:"A"})})]})}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===p?"active":""),onClick:()=>D("bullets"),title:"Bullet List","aria-label":"Bullet List",children:B.jsx(b,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===p?"active":""),onClick:()=>D("numbers"),title:"Numbered List","aria-label":"Numbered List",children:B.jsx(g,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>C.current?.click(),title:"Insert Image","aria-label":"Insert Image",children:B.jsx(v,{size:16})}),B.jsx("input",{ref:C,type:"file",accept:"image/*",onChange:V,style:{display:"none"}})]})]}),B.jsx("div",{ref:N,contentEditable:!0,className:"instruction-editor-content",onInput:E,onBlur:T,onPaste:F,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):B.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===p?"instruction-list-numbers":"bullets"===p?"instruction-list-bullets":""),children:u?B.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:u}}):B.jsx("div",{className:"instruction-empty",children:B.jsx("p",{children:"No instructions provided"})})})]})},de=({attachments:e,onRemove:i})=>{const[s,r]=t(new Map);return n(()=>{if(!e)return void r(e=>(e.forEach(e=>URL.revokeObjectURL(e)),new Map));const t=new Map;return e.forEach((e,n)=>{if(e.type.startsWith("image/")){const i=URL.createObjectURL(e);t.set(n,i)}}),r(e=>(e.forEach((e,n)=>{t.has(n)||URL.revokeObjectURL(e)}),t)),()=>{t.forEach(e=>URL.revokeObjectURL(e))}},[e]),e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type.startsWith("image/"),r=s.get(t);return B.jsx("div",{className:"attachment-thumbnail",children:n&&r?B.jsxs(B.Fragment,{children:[B.jsx("img",{src:r,alt:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(o,{size:14})})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"file-icon-placeholder",children:B.jsx(y,{size:20})}),B.jsx("span",{className:"file-name",children:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(o,{size:14})})]})},t)})}):null},ue=({component:e,mode:r,formTemplateId:a,formValue:o,onNotesChange:l,onAttachmentChange:c,notes:u="",attachments:m=null,onThresholdActionCompletion:p,onThresholdIssueRaised:h,onBasicPropertyActionCompletion:f})=>{const[b,g]=t(u||""),[v,S]=t(m||null),[$,k]=t(!1),[E,T]=t(!1),[A,I]=t(!1),[R,L]=t(!1),[D,V]=t(!1),F=s(null),O=s(o),M=s(!1),P=s(!1);n(()=>{if(!M.current&&null!=u){const e="string"==typeof u?u:String(u||"");g(e),M.current=!0}},[u]),n(()=>{P.current||void 0===m||(S(m),P.current=!0)},[m]),n(()=>{if(M.current&&!$&&null!=u){const e="string"==typeof u?u:String(u||"");b&&""!==String(b||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==b&&g(e):g(e)}},[u,$,b]),n(()=>{P.current&&void 0!==m&&(!v||m&&m.length>0&&m!==v)&&S(m)},[m,v]),n(()=>{const t=["select","radio","checkbox","segment"].includes(e.name||"");if(t){const t=O.current,n=o;let i=!1;if("checkbox"===e.name){const e=Array.isArray(t)?t:t?[t]:[],s=Array.isArray(n)?n:n?[n]:[];i=JSON.stringify(e.sort())!==JSON.stringify(s.sort())}else i=t!==n&&void 0!==t;if(i){I(!1),L(!1),T(!1),k(!1),V(!1);const e="string"==typeof u?u:String(u||"");e&&""!==e.trim()?g(e):g(""),m&&0!==m.length?S(m):S(null)}O.current=n}t||(O.current=o)},[o,e.name,u,m]);const z=i((e,t)=>{const{operator:n,value:i}=e,s=String(t).toLowerCase(),r=String(i).toLowerCase();switch(n){case"equals":return s===r||String(t)===String(i);case"notEquals":return s!==r&&String(t)!==String(i);case"greaterThan":return Number(t)>Number(i);case"lessThan":return Number(t)<Number(i);case"greaterThanOrEqual":return Number(t)>=Number(i);case"lessThanOrEqual":return Number(t)<=Number(i);default:return!1}},[]),q=i(()=>{if(!(null!=o&&""!==o&&!(Array.isArray(o)&&0===o.length)))return[];const t=e.condition;if(!t||!t.conditions||0===t.conditions.length)return[];const n=[];if("checkbox"===e.name&&Array.isArray(o))o.forEach(e=>{const i=t.conditions.find(t=>z(t,e));i&&!n.find(e=>e.id===i.id)&&n.push(i)});else{const e=t.conditions.find(e=>z(e,o));e&&n.push(e)}return n},[e,o,z]),_=i(t=>{const n=t.target.value;g(n),l&&l(n);const i=q(),s=String(n||"").trim().length>0;i.forEach(e=>{!0===e.enableNotes&&p&&p(e.id,"notes",s)});const r=e.condition;!(r&&r.conditions&&r.conditions.length>0)&&f&&f("notes",s)},[l,q,p,e,f]),W=i(()=>{if(l){const e="string"==typeof b?b:String(b||"");l(e),setTimeout(()=>{k(!1)},0)}else k(!1)},[b,l]),U=i(()=>{W()},[W]),G=i(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),W())},[W]),J=i(()=>{k(!0)},[]),H=i(()=>{k(!0)},[]),Y=i(()=>{F.current?.click()},[]),X=i(t=>{const n=t.target.files;if(n&&n.length>0){const t=Array.from(n);S(t),c&&c(t);q().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!0)});const i=e.condition;!(i&&i.conditions&&i.conditions.length>0)&&f&&f("attachments",!0)}F.current&&(F.current.value="")},[c,q,p,e,f]),Z=i(t=>{if(v){const n=v.filter((e,n)=>n!==t);if(0===n.length){S(null),c&&c(null);q().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!1)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("attachments",!1)}else S(n),c&&c(n)}},[v,c,q,p,e,f]),Q=i(()=>{I(!0);q().forEach(e=>{!0===e.enableSendEmail&&p&&p(e.id,"email",!0)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("email",!0),setTimeout(()=>{I(!1)},3e3)},[q,p,e,f]),ee=i(()=>{T(!0)},[]),te=i(()=>{T(!1)},[]),ne=i(()=>{T(!1),L(!0);const t=e.condition;if(t&&t.conditions&&t.conditions.length>0){q().forEach(e=>{!0===e.enableRaiseIssue&&h&&h(e.id)})}else f&&f("issue",!0)},[e,f,q,h]);if("test"!==r)return null;const ie=["select","radio","checkbox","segment"].includes(e.name||""),se=e.basic?.options||e.options||[];let re=!1,ae=!1,oe=!1,le=!1,ce=null;const ue=null!=o&&""!==o&&!(Array.isArray(o)&&0===o.length),me=e.condition,pe=me&&me.conditions&&me.conditions.length>0;if(pe&&ue)if("checkbox"===e.name&&Array.isArray(o)){const e=o;for(const t of e){const e=me.conditions.find(e=>z(e,t));e&&(re=re||!0===e.enableNotes,ae=ae||!0===e.enableAttachment,oe=oe||!0===e.enableRaiseIssue,le=le||!0===e.enableSendEmail)}}else if(ie){const e=me.conditions.find(e=>z(e,o));e&&(re=!0===e.enableNotes,ae=!0===e.enableAttachment,oe=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}else{const e=me.conditions.find(e=>z(e,o));e&&(re=!0===e.enableNotes,ae=!0===e.enableAttachment,oe=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}if(!pe){const t=e.basic,n=!0===t?.enableNotes,i=!0===t?.enableAttachment,s=!0===t?.enableRaiseIssue,r=!0===t?.enableSendEmail;if(ie)if(ue)if("checkbox"===e.name){(Array.isArray(o)?o:[o]).forEach(e=>{const t=se.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(re=re||!0===t.enableNotes,ae=ae||!0===t.enableAttachment,oe=oe||!0===t.enableRaiseIssue,le=le||!0===t.enableSendEmail,ce||(ce=t))}),re=re||n,ae=ae||i,oe=oe||s,le=le||r}else if(ce=se.find(e=>!(!e||!e.value)&&(e.value===o||(String(e.value)===String(o)||(e.label===o||String(e.label)===String(o))))),ce){const e=!0===ce.enableNotes,t=!0===ce.enableAttachment,a=!0===ce.enableRaiseIssue,o=!0===ce.enableSendEmail;re=e||n,ae=t||i,oe=a||s,le=o||r}else re=n,ae=i,oe=s,le=r;else re=n,ae=i,oe=s,le=r;else re=n,ae=i,oe=s,le=r}if(!(re||ae||oe||le))return null;const he=q(),fe=e.condition,be=fe&&fe.conditions&&fe.conditions.length>0,ge=!!be&&he.some(e=>!0===e.enableNotes),ve=!!be&&he.some(e=>!0===e.enableAttachment),ye=!!be&&he.some(e=>!0===e.enableSendEmail),xe=!!be&&he.some(e=>!0===e.enableRaiseIssue),je=String(b||"").trim().length>0,Ne=v&&v.length>0,Ce=v?v.length:0;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"component-action-features",children:[B.jsxs("div",{className:"action-icons-toolbar",children:[re&&B.jsxs("button",{type:"button",className:`action-icon-button ${je?"active":""} ${ge?"mandatory":""}`,onClick:J,title:"Add Notes",children:[B.jsx(d,{size:14,fill:je?"currentColor":"none"}),ge&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ae&&B.jsxs("button",{type:"button",className:`action-icon-button ${Ne?"active":""} ${ve?"mandatory":""}`,onClick:Y,title:"Add Attachment",children:[B.jsx(y,{size:14,fill:Ne?"currentColor":"none"}),Ce>0&&B.jsx("span",{className:"attachment-count-badge",children:Ce}),ve&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),le&&B.jsxs("button",{type:"button",className:`action-icon-button ${A?"active sent":""} ${ye?"mandatory":""}`,onClick:Q,disabled:A,title:"Send Email",children:[A?B.jsx(B.Fragment,{children:B.jsx(x,{size:14})}):B.jsx(j,{size:14,fill:A?"currentColor":"none"}),ye&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),oe&&B.jsxs("button",{type:"button",className:`action-icon-button ${R?"active":""} ${xe?"mandatory":""}`,onClick:ee,title:"Raise an Issue",children:[B.jsx(N,{size:14,fill:R?"currentColor":"none"}),xe&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(je&&re||Ne&&ae)&&B.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>V(!D),title:D?"Collapse":"Expand",children:D?B.jsx(C,{size:14}):B.jsx(w,{size:14})})]}),$&&re&&B.jsxs("div",{className:"notes-input-overlay",children:[B.jsx("textarea",{className:"action-notes-textarea",value:b,onChange:_,onBlur:U,onKeyDown:G,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),B.jsxs("div",{className:"notes-input-actions",children:[B.jsx("button",{type:"button",className:"notes-save-button",onClick:W,title:"Save notes (Ctrl+Enter)",children:"Save"}),B.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{k(!1)},title:"Cancel",children:"Cancel"})]})]}),D&&B.jsxs("div",{className:"actions-content",children:[!$&&je&&re&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",onClick:H,children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",b]})}),Ne&&ae&&B.jsx("div",{className:"attachments-section",children:B.jsx(de,{attachments:v,onRemove:Z})})]}),ae&&B.jsx("input",{ref:F,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:X,style:{display:"none"}})]}),E&&B.jsx(K,{isOpen:E,onClose:te,onSuccess:ne,component:ce?{...e,basic:{...e.basic,label:`${e.basic?.label||"Component"} - ${ce.label||ce.value}`,value:ce.value||e.basic?.value||""}}:e,formTemplateId:a||"",notes:b,attachments:v})]})},me=({attachments:e})=>e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type?.startsWith("image/")||!1,i=n?(e=>e.data?e.data.startsWith("data:")?e.data:`data:${e.type||"image/png"};base64,${e.data}`:"")(e):"";return B.jsx("div",{className:"attachment-thumbnail",children:n&&i?B.jsx("img",{src:i,alt:e.name||`Attachment ${t+1}`}):B.jsxs("div",{className:"file-icon-placeholder",children:[B.jsx(y,{size:20}),B.jsx("span",{className:"file-name",children:e.name||`File ${t+1}`})]})},t)})}):null,pe=({component:e})=>{const t=e.basic?.notes||"",n=e.basic?.attachments||[],i=t&&t.trim().length>0,s=n&&n.length>0;return i||s?B.jsx("div",{className:"component-submission-actions",children:B.jsxs("div",{className:"actions-content",children:[i&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",t]})}),s&&B.jsx("div",{className:"attachments-section",children:B.jsx(me,{attachments:n})})]})}):null},he=({child:e,selectedChild:t,mode:n,onChildSelect:i,onChildDelete:s,renderFormComponent:r,isOverlay:a=!1,isChildrenEditMode:o=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:b,listeners:g,setNodeRef:v,transform:y,transition:x,isDragging:j,isSorting:N}=V({id:e.id,disabled:a||"edit"!==n}),C={transform:O.Transform.toString(y),transition:x,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:v,style:C,className:`form-component section-child ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""} ${o?"children-edit-active":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:[("edit"===n||o)&&B.jsx("div",{className:"child-drag-handle",...g,...b,onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:B.jsx($,{size:14})}),B.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===n||o)&&B.jsxs("div",{className:"component-actions child-actions",children:[B.jsx("button",{className:"btn edit-btn",onClick:t=>{t.stopPropagation(),i(e)},onMouseDown:e=>e.stopPropagation(),title:"Edit properties",children:B.jsx(k,{size:12})}),B.jsx("button",{className:"btn delete-btn",onClick:t=>s(e,t),onMouseDown:e=>e.stopPropagation(),title:"Delete component",children:B.jsx(E,{size:12})})]}),B.jsxs("div",{className:"component-preview child-preview",children:[r(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]})]})]})},fe=({id:e,properties:s,mode:r="edit",formData:a={},onValueChange:o,onSelect:l,isSelected:c=!1,className:d="",onSectionSelect:u,onChildSelect:m,onChildDelete:p,selectedChild:h,renderFormComponent:f,formTemplateId:b,onThresholdActionCompletion:g,onThresholdIssueRaised:v,onNotesChange:y,onAttachmentChange:x})=>{const[j,N]=t(s.basic.collapsed),[C,$]=t(!1),[k,E]=t(!1),[T,A]=t(s.basic.label),[I,V]=t(s.basic.description),[F,O]=t(s.children||[]),[M,P]=t(!1);n(()=>{O(s.children||[])},[s.children]),n(()=>{A(s.basic.label),V(s.basic.description)},[s.basic.label,s.basic.description]);const{setNodeRef:z,isOver:q}=R({id:`section-${e}`,disabled:"edit"!==r}),_=!("preview"!==r&&"test"!==r||s.children&&s.children.length>0),W=i(t=>{A(t),o?.({id:e,value:{...s,basic:{...s.basic,label:t}}})},[e,s,o]),U=i(t=>{V(t),o?.({id:e,value:{...s,basic:{...s.basic,description:t}}})},[e,s,o]),G=i(e=>{m?.(e)},[m]),J=i((e,t)=>{t.stopPropagation();const n=F.filter(t=>t.id!==e.id);O(n),p?.(e.id)},[p,F,e]),H=i(()=>{u?.(s),l?.()},[u,l,s]),Y=i(e=>{e.stopPropagation(),"edit"===r&&F.length>0&&P(!M)},[r,F.length,M]),K=i(t=>{t.stopPropagation(),N(!j),o?.({id:e,value:{...s,basic:{...s.basic,collapsed:!j}}})},[j,e,s,o]),X=f||i(e=>{const t=a[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let n=t;"number-input"===e.name&&"number"==typeof t?n=String(t):"number-input"===e.name&&null==t&&(n="");const i={id:e.id,properties:e,validationErrors:{},formValue:n,touchedFields:{},formSubmitted:!1,mode:r,onValueChange:o,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...i,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...i,properties:e,readonly:!1,disabled:!1});case"select":const t={...e,options:e.basic?.options||[]};return B.jsx(ee,{...i,properties:t,disabled:!1});case"checkbox":const n={...e,options:e.basic?.options||[]};return B.jsx(te,{...i,properties:n,formValue:[],disabled:!1});case"radio":const s={...e,options:e.basic?.options||[]};return B.jsx(ne,{...i,properties:s,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...i,properties:e,readonly:!1,disabled:!1});case"signature":return B.jsx(re,{...i,properties:e});case"heading":return B.jsx(le,{...i,properties:e});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}},[r,o,a]);if(_)return null;const ie={backgroundColor:s.styles?.backgroundColor||"var(--df-color-fb-container)",borderColor:s.styles?.borderColor||"var(--df-color-fb-border)",borderWidth:s.styles?.borderWidth||"2px",borderRadius:s.styles?.borderRadius||"8px",padding:s.styles?.padding||"16px",margin:s.styles?.margin||"16px 0"};return B.jsxs("div",{ref:z,className:`df-form-section ${c?"selected":""} ${q?"drag-over":""} ${d}`,style:ie,children:[B.jsxs("div",{className:"section-header "+(M?"children-edit-mode":""),onClick:H,onDoubleClick:Y,children:[B.jsx("div",{className:"section-header-content",children:B.jsxs("div",{className:"section-title",children:[B.jsx("span",{className:"section-toggle",title:j?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),K(e)},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),K(e))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:j?B.jsx(S,{size:18}):B.jsx(w,{size:18})}),"edit"===r&&C?B.jsx("input",{type:"text",value:T,onChange:e=>A(e.target.value),onBlur:()=>{$(!1),W(T)},onKeyDown:e=>{"Enter"===e.key&&($(!1),W(T))},className:"section-title-input",autoFocus:!0}):B.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===r&&$(!0),style:{display:"inline",margin:0},children:T||"Untitled Section"})]})}),(I||"edit"===r)&&B.jsx("div",{className:"section-description",children:"edit"===r&&k?B.jsx("textarea",{value:I,onChange:e=>V(e.target.value),onBlur:()=>{E(!1),U(I)},onKeyDown:e=>{"Enter"===e.key&&e.ctrlKey&&(E(!1),U(I))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):B.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===r&&E(!0),children:I||"Section description"})})]}),!j&&B.jsx("div",{className:`section-content ${q?"drag-over":""} ${0===F.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&H()},children:B.jsx(L,{items:F.map(e=>e.id),strategy:D,children:0===F.length?B.jsxs("div",{className:"section-empty-state",onClick:H,style:{textAlign:"center",color:"#6b7280",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",cursor:"pointer",border:"2px dotted #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",transition:"all 0.3s ease",margin:"16px 0"},children:[B.jsx("div",{style:{fontWeight:"500",color:q?"#3b82f6":"#374151"},children:q?"Drop components here":"Empty Section"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):F.map(e=>B.jsx(he,{child:e,selectedChild:h||null,mode:r,onChildSelect:G,onChildDelete:J,renderFormComponent:X,isChildrenEditMode:M,formData:a,formTemplateId:b,onNotesChange:y,onAttachmentChange:x,onThresholdActionCompletion:g,onThresholdIssueRaised:v},e.id))})})]})},be=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:s,onComponentEdit:r,renderFormComponent:a,isOverlay:o=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:b,listeners:g,setNodeRef:v,transform:y,transition:x,isDragging:j,isSorting:N}=V({id:e.id,disabled:o}),C={transform:O.Transform.toString(y),transition:x,opacity:j?.3:1,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:v,style:{...C,border:t?.id===e.id?"2px solid #3b82f6":"1px solid var(--df-color-fb-border)",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",padding:"12px",position:"relative",minHeight:"80px",transition:"all 0.2s ease",boxShadow:t?.id===e.id?"0 4px 12px rgba(59, 130, 246, 0.15)":"0 1px 3px rgba(0, 0, 0, 0.1)",cursor:"pointer"},className:`form-component grid-component ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...g,...b,onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"50%",left:"4px",transform:"translateY(-50%)",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"4px",cursor:"grab",opacity:1,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:B.jsx($,{size:12,color:"var(--df-color-text-light)"})}),B.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===n?"24px":"0",paddingLeft:"edit"===n?"28px":"0",minHeight:"60px"},children:[a(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[r&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),r(e)},type:"button",title:"Edit Component",style:{padding:"4px",backgroundColor:"#3b82f6",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#3b82f6"},children:B.jsx(k,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),s(e,t)},type:"button",title:"Delete Component",style:{padding:"4px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#ef4444"},children:B.jsx(E,{size:12})})]})]})},ge=({gridComponents:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:r,selectedComponent:a,renderFormComponent:o,gridId:l,formData:c={},formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})=>{const{setNodeRef:f,isOver:b}=R({id:`grid-drop-zone-${l}`,disabled:"edit"!==t});return B.jsx("div",{ref:f,className:"grid-drop-zone",style:{border:b?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:b?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?B.jsxs(B.Fragment,{children:[B.jsx(L,{items:e.map(e=>e.id),strategy:F,children:B.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:e.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:e.map(e=>B.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:B.jsx(be,{component:e,selectedComponent:a,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:r,renderFormComponent:o,formData:c,formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})},e.id))})}),B.jsx("div",{style:{border:b?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:b?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:b?B.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):B.jsx("span",{children:"+ Drop more components here"})})]}):B.jsxs("div",{style:{textAlign:"center",color:"var(--df-color-text-light)",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed var(--df-color-fb-border)",borderRadius:"8px"},children:[B.jsx("div",{style:{fontWeight:"500",color:b?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:b?"Drop components here":"Empty DataGrid"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},ve=({templateComponents:e,dataEntries:t,renderFormComponent:n,renderComponent:i,mode:s="preview",allowAddRemoveEntries:r=!0,addAnotherText:a="Add Another",removeText:o="Remove",maxEntries:l=10,minEntries:c=1,displayAsGrid:d=!0,onAddEntry:u,onRemoveEntry:m,formData:p={},formTemplateId:h,onThresholdActionCompletion:f,onThresholdIssueRaised:b,onNotesChange:g,onAttachmentChange:v,datagridId:y=""})=>0===e.length?B.jsxs("div",{style:{textAlign:"center",padding:"40px",color:"var(--df-color-text-light)",border:"1px dashed #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)"},children:["No components defined. Add components to see the ",d?"table":"list"," view."]}):d?B.jsxs("div",{className:"datagrid-table-view",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",backgroundColor:"var(--df-color-fb-container)",maxWidth:"100%"},children:[B.jsx("div",{style:{position:"absolute",top:"8px",right:"8px",zIndex:10,fontSize:"12px",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",padding:"4px 8px",borderRadius:"4px",border:"1px solid var(--df-color-fb-border)",opacity:e.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),B.jsxs("div",{className:"table-scroll-container",style:{overflowX:"auto",overflowY:"hidden",maxWidth:"100%",scrollbarWidth:"thin",scrollbarColor:"var(--df-color-fb-border) var(--df-color-fb-icon-bg)",position:"relative"},children:[B.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*e.length+"px"},children:e.map((t,n)=>B.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:n<e.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.basic?.label||`Column ${n+1}`},`header-${t.id}`))}),t.length>0?t.map((s,a)=>B.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:a<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:a%2==0?"var(--df-color-fb-container)":"var(--df-color-fb-bg)",position:"relative",minWidth:150*e.length+"px",isolation:"isolate"},children:[e.map((t,r)=>{let o=s.components?.[r];const l=`${t.id||`component-${r}`}-entry-${y}-${a}-${r}`;return o=o?o.id!==l?{...o,id:l,basic:{...o.basic,showLabel:!1}}:{...o,id:o.id,basic:{...o.basic,showLabel:!1}}:{...t,id:l,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsx("div",{style:{padding:"12px 16px",borderRight:r<e.length-1?"1px solid var(--df-color-fb-border)":"none",minHeight:"60px",minWidth:"150px",display:"flex",alignItems:"center",overflow:"visible",position:"relative",zIndex:1},children:B.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:i?i(o,!0):n(o,!0)})},`${s.id}-${r}`)}),r&&t.length>c&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(a)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",zIndex:1e3,minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto"},title:o,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},s.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",borderTop:"1px solid var(--df-color-fb-border)"},children:["No data entries. ",r?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]})]}),r&&B.jsx("div",{style:{padding:"16px",backgroundColor:"var(--df-color-fb-bg)",borderTop:"1px solid var(--df-color-fb-border)",display:"flex",justifyContent:"center",position:"sticky",bottom:0,zIndex:5},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{style:{fontSize:"16px"},children:"+"}),a]})})]}):B.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[t.length>0?t.map((a,l)=>B.jsxs("div",{className:"list-entry",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",padding:"16px",backgroundColor:"var(--df-color-fb-container)",position:"relative",transition:"all 0.2s ease"},children:[B.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[B.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",l+1]}),r&&t.length>1&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(l)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},title:o,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),B.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:e.map((e,t)=>{let r=a.components?.[t];const o=`${e.id||`component-${t}`}-entry-${y}-${l}-${t}`;return r||(r=a.components?.find(t=>t.name===e.name&&t.basic?.label===e.basic?.label)),r=r?r.id!==o?{...r,id:o,basic:{...r.basic,showLabel:!1}}:{...r,id:r.id,basic:{...r.basic,showLabel:!1}}:{...e,id:o,basic:{...e.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[B.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:e.basic?.label||`Field ${t+1}`}),B.jsxs("div",{style:{minHeight:"40px",display:"flex",alignItems:"center",flexDirection:"column",width:"100%"},children:[i?i(r):n(r),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(r.name)&&B.jsx(ue,{component:r,mode:"test",formTemplateId:h,formValue:p[r.id],onThresholdActionCompletion:f,onThresholdIssueRaised:b,onNotesChange:g?e=>g(r.id,e):void 0,onAttachmentChange:v?e=>v(r.id,e):void 0}),"preview"===s&&(r.basic?.notes&&r.basic.notes.trim().length>0||r.basic?.attachments&&Array.isArray(r.basic.attachments)&&r.basic.attachments.length>0?B.jsx(pe,{component:r}):null)]})]},`${a.id}-${t}`)})})]},a.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed #d1d5db",borderRadius:"8px"},children:["No data entries. ",r?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]}),"test"===s&&r&&B.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{children:"+"}),a]})})]}),ye=({id:e,properties:r,mode:a="edit",formData:o={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onDataGridSelect:f,onComponentSelect:b,onComponentDelete:g,onComponentEdit:v,onComponentUpdate:y,selectedComponent:x,renderFormComponent:j,onEntryAdd:N,onEntryRemove:C,formTemplateId:$,onThresholdActionCompletion:k,onThresholdIssueRaised:E,onNotesChange:A,onAttachmentChange:I})=>{const[R,L]=t(!1),D=s(!1);let V=r.templateComponents||[];const F=r.entries||[];0===V.length&&F.length>0&&F[0].components&&(V=F[0].components.map(e=>({...e,id:e.id?.replace(/-entry-\d+$/,"")||e.id,basic:{...e.basic,showLabel:!0}}))),n(()=>{if("edit"===a&&!r.templateComponents&&u&&D.current){const t={...r,templateComponents:[]};JSON.stringify(t)!==JSON.stringify(r)&&u({id:e,value:t})}D.current=!0},[r.templateComponents,e,u,r,a]),n(()=>{if(V.length>0){if("test"===a&&0===F.length&&D.current){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...r,entries:[t]};JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n})}return}if("edit"!==a||!D.current)return;if(F.some(e=>e.components?.some((t,n)=>{const i=`${V[n]?.id}-entry-${e.index}-${n}`;return t.id!==i}))&&u){const t=F.map(e=>({...e,components:e.components?.map((t,n)=>({...t,id:`${V[n]?.id}-entry-${e.index}-${n}`}))||[]})),n={...r,entries:t};return void(JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n}))}if(0===F.length&&"edit"===a){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...r,entries:[t]};JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n})}}else if(F.length>0){if(F.some(e=>V.some((t,n)=>{const i=e.components?.[n];if(!i)return!0;const s=`${t.id}-entry-${e.index}-${n}`,r=i.id===s,a=JSON.stringify(i.basic?.options)!==JSON.stringify(t.basic?.options)||i.basic?.placeholder!==t.basic?.placeholder||i.basic?.defaultValue!==t.basic?.defaultValue||i.basic?.label!==t.basic?.label||i.validation?.required!==t.validation?.required;return!r||a}))&&u){const t=F.map(t=>{const n=V.map((n,i)=>{let s=t.components?.[i];s||(s=t.components?.find(e=>e.name===n.name&&e.basic?.label===n.basic?.label));const r=`${n.id||`component-${i}`}-entry-${e}-${t.index}-${i}`;if(s){return{...n,id:r,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}return{...n,id:r,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}});return{...t,components:n}}),n={...r,entries:t};JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n})}}}},[V,F,e,u,r,a,r.templateComponents]);const O=i(e=>{e.stopPropagation(),m?.(),f?.(r)},[m,f,r]),M=i((t,n)=>{n.stopPropagation(),g&&g(t,n);const i=V.filter(e=>e.id!==t.id),s=F.map(e=>({...e,components:e.components?.filter(e=>!(e.name===t.name&&e.basic?.label===t.basic?.label))||[]}));u&&u({id:e,value:{...r,templateComponents:i,entries:s}})},[g,r,u,e,V,F]),P=i((t,n)=>{y&&y(t,n);const i=V.map(e=>e.id===t?{...e,...n}:e);u&&u({id:e,value:{...r,templateComponents:i}})},[y,r,u,e,V]),z=i(e=>{"test"===a&&u&&u({id:e.id,value:e.value})},[u]),q=i(()=>{const t=r.entries||[],n=t.length,i={id:`entry-${e}-${n}`,index:n,components:V.map((t,i)=>{const s=`${t.id||`component-${i}`}-entry-${e}-${n}-${i}`;return{...t,id:s,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}},s=[...t,i];u&&u({id:e,value:{...r,entries:s}}),N?.()},[r,u,e,N,V]),_=i(t=>{const n=r.entries.filter((e,n)=>n!==t).map((t,n)=>({...t,index:n,id:`entry-${e}-${n}`}));u&&u({id:e,value:{...r,entries:n}})},[r,u,e,C]),W=i((e,t=!1)=>{const n=o[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let i=n;"number-input"===e.name&&"number"==typeof n?i=String(n):"number-input"===e.name&&null==n&&(i="");const s={id:e.id,properties:e,validationErrors:l||{},formValue:i,touchedFields:c||{},formSubmitted:d||!1,mode:a,hideLabel:t,onValueChange:z,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...s,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1,hideLabel:t});case"textarea":return B.jsx(Q,{...s,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"select":const n={...e,options:e.basic?.options||[]};return B.jsx(ee,{...s,properties:n,disabled:!1,hideLabel:t});case"checkbox":const i={...e,options:e.basic?.options||[]};return B.jsx(te,{...s,properties:i,formValue:[],disabled:!1,hideLabel:t});case"radio":const r={...e,options:e.basic?.options||[]};return B.jsx(ne,{...s,properties:r,readonly:!1,disabled:!1,hideLabel:t});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...s,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"signature":return B.jsx(re,{...s,properties:e,hideLabel:t});case"heading":return B.jsx(le,{...s,properties:e,hideLabel:t});case"instructions":return B.jsx(ce,{...s,properties:e,hideLabel:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",e.name]})}},[a,z,o,l,c,d]),U={backgroundColor:r.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:r.styles.borderColor||"var(--df-color-fb-border)",borderWidth:r.styles.borderWidth||"2px",borderRadius:r.styles.borderRadius||"8px",padding:r.styles.padding||"16px",margin:r.styles.margin||"16px 0"};return B.jsxs("div",{className:`form-group df-form-datagrid ${p?"selected":""} ${h}`,onClick:O,style:U,children:[B.jsx("div",{className:"grid-header",children:B.jsx("div",{className:"grid-title",onClick:t=>{t.stopPropagation(),L(!R),u?.({id:e,value:{...r,basic:{...r.basic,collapsed:!R}}})},children:B.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[R?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(T,{size:16}),B.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:r.basic.label}),r.validation.required&&B.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),r.basic.description&&!R&&B.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:r.basic.description}),!R&&B.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===a?B.jsx(ge,{gridComponents:V,mode:a,onComponentSelect:b||(()=>{}),onComponentDelete:M,onComponentEdit:v,onComponentUpdate:P,selectedComponent:x||null,renderFormComponent:j||W,gridId:e,formData:o,formTemplateId:$,onThresholdActionCompletion:k,onThresholdIssueRaised:E,onNotesChange:A,onAttachmentChange:I}):B.jsx(ve,{templateComponents:V,dataEntries:F,renderFormComponent:j||W,mode:a,allowAddRemoveEntries:r.datagrid?.allowAddRemoveEntries??!0,addAnotherText:r.datagrid?.addAnotherText??"Add Entry",removeText:r.datagrid?.removeText??"Remove",maxEntries:r.datagrid?.maxEntries??10,minEntries:r.datagrid?.minEntries??1,displayAsGrid:r.datagrid?.displayAsGrid??!0,onAddEntry:N||q,onRemoveEntry:C||_,formData:o,formTemplateId:$,onThresholdActionCompletion:k,onThresholdIssueRaised:E,onNotesChange:A,onAttachmentChange:I,datagridId:e})})]})},xe=e.lazy(()=>Promise.resolve().then(function(){return Te})),je=({formComponents:r=[],currentDevice:a="desktop",isPreviewMode:o=!1,initialFormData:l=[],onSubmit:c,onFormDataChange:d,formTitle:u,formDescription:m,formTemplateId:p,onComponentSelect:h,onComponentDelete:f,onComponentEdit:b,onComponentUpdate:g,selectedComponent:v})=>{const[y,x]=t({}),[j,N]=t({}),[C,w]=t(!1),[S,$]=t({}),[k,E]=t({}),[T,A]=t(new Set),[I,R]=t(new Map),[L,D]=t({isValid:!0});n(()=>{F()},[r,l]);const V=(e,t)=>{e.forEach(e=>{if(e.id&&("value"in e.basic&&void 0!==e.basic.value?t[e.id]=e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?t[e.id]=e.basic.defaultValue:"checkbox"===e.name||"select"===e.name?t[e.id]=[]:t[e.id]=""),e.cells&&Array.isArray(e.cells)&&e.cells.forEach((e,n)=>{Array.isArray(e)&&e.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&V(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&V(e.components,t)}),"file"===e.name&&e.basic){const n=e.basic.files||e.basic.attachments||e.basic.value;n&&(t[e.id]=n)}if("instructions"===e.name&&e.basic){e.basic.instructions||(e.basic.instructions=[]);const n=e.basic.value||e.basic.instructions;n&&(t[e.id]=n)}e.children&&Array.isArray(e.children)&&V(e.children,t)})},F=i(()=>{const e={},t=new Set,n=e=>{e.forEach(e=>{e.id&&(t.has(e.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${e.id}. Component:`,e),e.id=`${e.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${e.id}`)),t.add(e.id)),e.children&&Array.isArray(e.children)&&n(e.children),e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})})};r&&r.length>0&&n(r),l&&l.length>0&&n(l),l&&l.length>0&&V(l,e),r&&r.length>0&&V(r,e),x(e),M()},[l,r]),O=(e,t)=>{e.forEach(e=>{if(e.id)if("table"===e.name||"datagrid"===e.name)t[e.id]=!0;else if(e.conditional){const n=G.evaluateConditionalLogic(e.conditional,r,y);t[e.id]=n.shouldShow}else t[e.id]=!0;e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{e.forEach(e=>{e.components&&Array.isArray(e.components)&&O(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&O(e.components,t)}),e.children&&Array.isArray(e.children)&&O(e.children,t)})},M=i(()=>{const e={};r&&r.length>0&&O(r,e),E(e)},[r,y]),P=i(e=>{const t=r.find(t=>t.id===e);if(t&&("table"===t.name||"datagrid"===t.name))return!0;return!1!==k[e]},[k,r]),z=i(e=>{if(!e.id||"string"!=typeof e.id||""===e.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",e);const t=r.filter(t=>t.id===e.id);if(t.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${e.id}":`,t.map(e=>({id:e.id,name:e.name,label:e.basic?.label})));const n=y[e.id];void 0!==n&&n!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:n,newValue:e.value});const i={...y,[e.id]:e.value};x(i);const s=r.find(t=>t.id===e.id);if(s){const e=s?.threshold;e&&e.conditions&&e.conditions.length>0&&A(t=>{const n=new Set(t);return e.conditions.forEach(e=>{n.delete(e.id)}),n})}const a=t=>t.map(t=>t.id===e.id&&"defaultValue"in t.basic?{...t,basic:{...t.basic,value:e.value??t.basic.defaultValue,defaultValue:e.value}}:"section"===t.name&&t.children?{...t,children:a(t.children)}:"table"===t.name&&t.cells?{...t,cells:t.cells.map(e=>e.map(e=>{const t={...e};return t.components&&(t.components=a(t.components)),t}))}:"datagrid"===t.name&&t.entries?{...t,entries:t.entries.map(e=>{const t={...e};return t.components&&(t.components=a(t.components)),t})}:t),l=a(r);if(d?.(l),j[e.id]&&N(t=>({...t,[e.id]:""})),!o){if(e.isValid)return void N(t=>{const n=t[e.id];return n&&""!==n.trim()?{...t,[e.id]:""}:t});setTimeout(()=>{_(e.id)},150)}setTimeout(()=>{const e={};r.forEach(t=>{if("table"===t.name||"datagrid"===t.name)e[t.id]=!0;else if(t.conditional){const n=G.evaluateConditionalLogic(t.conditional,r,i);e[t.id]=n.shouldShow}else e[t.id]=!0}),E(e)},0)},[r,y,j,d]),q=i((e,t)=>{for(const n of e){if(n.id===t)return n;if("section"===n.name&&n.children){const e=q(n.children,t);if(e)return e}if("table"===n.name&&n.cells)for(const e of n.cells)for(const n of e)if(n.components){const e=q(n.components,t);if(e)return e}if("datagrid"===n.name&&n.entries)for(const e of n.entries)if(e.components){const n=q(e.components,t);if(n)return n}}return null},[]),_=i(e=>{if(o)return;const t=q(r,e);if(!t)return;const n=y[e]||"";if("number-input"===t.name&&(!n||""===n)){if(t.validation.required){const n=t.validation.customValidationMessage,i=t.basic.label||"This field",s=n||`${i} is required`;N(t=>({...t,[e]:s}))}else N(t=>({...t,[e]:""}));return}let i=!1;i=Array.isArray(n)?n.length>0:"string"==typeof n?""!==n.trim():null!=n;let s="";if(t.validation.required&&!i){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} is required`}else if("email-input"===t.name&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be a valid email`}else if(t.validation.minLength&&i&&n.length<t.validation.minLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be at least ${t.validation.minLength} characters`}else if(t.validation.maxLength&&i&&n.length>t.validation.maxLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be no more than ${t.validation.maxLength} characters`}else if("number-input"===t.name&&i){const e=String(n).trim();if(!(/^-?\.?$/.test(e)||/^-?\d+\.?$/.test(e))){if(/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(e)){const n=parseFloat(e);if(isNaN(n)){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be a valid number`}else{const e=t.validation;if(void 0!==e.min&&n<e.min){const n=t.validation.customValidationMessage,i=t.basic.label||"This field";s=n||`${i} must be at least ${e.min}`}else if(void 0!==e.max&&n>e.max){const n=t.validation.customValidationMessage,i=t.basic.label||"This field";s=n||`${i} must be no more than ${e.max}`}else if(void 0!==e.lowerLimit&&n<e.lowerLimit){const n=t.validation.customValidationMessage,i=t.basic.label||"This field";s=n||`You are under the limit. ${i} must be at least ${e.lowerLimit}`}else if(void 0!==e.upperLimit&&n>e.upperLimit){const n=t.validation.customValidationMessage,i=t.basic.label||"This field";s=n||`You crossed the limit. ${i} must be no more than ${e.upperLimit}`}}}else{const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be a valid number`}}}N(t=>({...t,[e]:s}))},[r,o,y,q]),W=i(e=>{$(t=>({...t,[e]:!0})),o||setTimeout(()=>{_(e)},0)},[o,_]),U=i(e=>{j[e]&&N(t=>({...t,[e]:""}))},[j]),H=i(()=>r.every(e=>{const t=y[e.id]||"";let n=!1;return n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,!(e.validation.required&&!n)}),[r,y]),Y=i((e,t)=>{if(Array.isArray(t))return t.some(t=>Y(e,t));if(null==t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(!isNaN(n)&&!isNaN(i))switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}const s=String(t).toLowerCase(),r=String(e.value).toLowerCase();switch(e.operator){case"equals":return s===r||String(t)===String(e.value);case"notEquals":return s!==r&&String(t)!==String(e.value);default:return!1}},[]),K=i(()=>{if(o)return[];const e=[];return r.forEach(t=>{const n=t?.condition;if(!n||!n.conditions||0===n.conditions.length)return;const i=y[t.id];null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length)&&n.conditions.forEach(n=>{Y(n,i)&&e.push({componentId:t.id,condition:n,componentLabel:t.basic?.label||"Field"})})}),e},[r,y,o,Y]),X=i(()=>{if(o)return{isValid:!0};const e=K();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:n}of e){const e=I.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},i=[];if(!0!==t.enableRaiseIssue||T.has(t.id)||i.push("raise an issue"),!0!==t.enableNotes||e.notesCompleted||i.push("add notes"),!0!==t.enableAttachment||e.attachmentsCompleted||i.push("add attachments"),!0!==t.enableSendEmail||e.emailSent||i.push("send email"),i.length>0){return{isValid:!1,errorMessage:`Please ${1===i.length?i[0]:i.slice(0,-1).join(", ")+" and "+i[i.length-1]} for the threshold condition met in "${n}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[o,K,T,I]),de=i(e=>{e&&A(t=>{const n=new Set(t);return n.add(e),n})},[]),me=i((e,t,n)=>{e&&R(i=>{const s=new Map(i),r=s.get(e)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===t?s.set(e,{...r,notesCompleted:n}):"attachments"===t?s.set(e,{...r,attachmentsCompleted:n}):"email"===t&&s.set(e,{...r,emailSent:n}),s})},[]);n(()=>{if(!o){const e=X();D(e)}},[y,T,I,o,X]);const he=i(()=>{if(o)return!0;let e=!0;w(!0);const t={};return r.forEach(n=>{const i=y[n.id]||"";let s=!1;if(s=Array.isArray(i)?i.length>0:"string"==typeof i?""!==i.trim():null!=i,n.validation.required&&!s){const i=n.validation.customValidationMessage,s=n.basic.label||"This field",r=i||`${s} is required`;t[n.id]=r,e=!1}else t[n.id]="";$(e=>({...e,[n.id]:!0}))}),N(t),e},[r,o,y]),be=i(()=>{if(w(!0),!he()){const e=r.find(e=>{const t=y[e.id]||"";let n=!1;return n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!n});if(e){const t=document.getElementById(e.id);t&&t.focus()}return}const e=X();if(!e.isValid){e.errorMessage&&J.showError(e.errorMessage);const t=K().find(({condition:e})=>!T.has(e.id));if(t){const e=document.getElementById(t.componentId);e&&e.scrollIntoView({behavior:"smooth",block:"center"})}return}const t=e=>e.map(e=>{let n=y[e.id];"text-input"===e.name&&e.basic,void 0===n&&(n="value"in e.basic&&void 0!==e.basic.value?e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?e.basic.defaultValue:""),"text-input"===e.name&&e.basic;const i={...e,basic:{...e.basic,value:n,defaultValue:n}};return"section"===i.name&&i.children&&(i.children=t(i.children)),"table"===i.name&&i.cells&&(i.cells=i.cells.map(e=>e.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n}))),"datagrid"===i.name&&i.entries&&(i.entries=i.entries.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n})),i}),n=t(r);c?.(n)},[r,y,he,c]),ge=i(()=>({[`device-${a}`]:!0,readonly:o}),[a,o]),ve=s(new Map),je=s(0),Ne=t=>{let n;if(t.id&&"string"==typeof t.id&&""!==t.id.trim())n=t.id;else{const e=t.basic?.label||"",i=t.name||"unknown",s=`${i}-${e}`;let r=ve.current.get(s);r||(je.current+=1,r=`generated-${i}-${je.current}-${Math.random().toString(36).substr(2,9)}`,ve.current.set(s,r),console.warn("[DfFormPreview] Generated and cached ID for component:",r,"key:",s)),n=r,t={...t,id:n}}const i=n,s=y[i];if(void 0!==s){const e=r.filter(e=>e.id!==i&&y[e.id]===s);e.length>0&&console.warn(`[DfFormPreview] Component ${i} shares form value with other components:`,e.map(e=>e.id))}const a={id:i,validationErrors:j,formValue:s,touchedFields:S,formSubmitted:C,mode:"test",readonly:!1,onValueChange:z,onBlur:()=>W(i),onFocus:()=>U(i)};switch(t.name){case"text-input":case"number-input":case"email-input":return B.jsx(Z,{...a,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",formTemplateId:p,onThresholdIssueRaised:de,raisedThresholdIssues:T});case"textarea":return B.jsx(Q,{...a,properties:t});case"select":const n={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ee,{...a,properties:n});case"checkbox":const i={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(te,{...a,properties:i});case"radio":const o={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ne,{...a,properties:o});case"segment":const l={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ie,{...a,properties:l});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...a,properties:t});case"signature":return B.jsx(re,{...a,properties:t});case"heading":return B.jsx(le,{...a,properties:t});case"instructions":const c=s||t.basic?.value||null;return B.jsx(ce,{...a,properties:t,formValue:c});case"location":return B.jsx(oe,{...a,properties:t});case"section":return B.jsx(fe,{...a,properties:t,formData:y,formTemplateId:p,onThresholdActionCompletion:me,onThresholdIssueRaised:de,renderFormComponent:e=>Ne(e)});case"table":return B.jsx(e.Suspense,{fallback:B.jsx("div",{children:"Loading table..."}),children:B.jsx(xe,{...a,properties:t,formData:y,formTemplateId:p,mode:a.mode,validationErrors:j,touchedFields:S,formSubmitted:C,onThresholdActionCompletion:me,onThresholdIssueRaised:de,onNotesChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},renderFormComponent:e=>Ne(e)})});case"datagrid":return B.jsx(ye,{...a,properties:t,formData:y,formTemplateId:p,mode:a.mode,validationErrors:j,touchedFields:S,formSubmitted:C,onThresholdActionCompletion:me,onThresholdIssueRaised:de,onComponentSelect:h,onComponentDelete:f,onComponentEdit:b,onComponentUpdate:g,selectedComponent:v,onValueChange:e=>{if(e.id===t.id&&e.value&&"object"==typeof e.value&&"entries"in e.value){const n=r.map(n=>n.id===t.id?{...n,...e.value}:n);d?.(n),e.value.entries&&Array.isArray(e.value.entries)&&e.value.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&e.components.forEach(e=>{if(void 0!==y[e.id]);else{const t=e.basic?.defaultValue;void 0!==t&&x(n=>({...n,[e.id]:t}))}})})}else z(e)},onEntryAdd:()=>{const e=r.find(e=>e.id===t.id);if(e&&e.entries){const e=r.map(e=>e.id===t.id?{...e,entries:e.entries||[]}:e);d?.(e)}else setTimeout(()=>{const e=y[t.id];if(e&&"object"==typeof e&&"entries"in e){const n=r.map(n=>n.id===t.id?{...n,entries:e.entries}:n);d?.(n)}},100)},onEntryRemove:e=>{const n=r.map(n=>{if(n.id===t.id&&n.entries){const t=(n.entries||[]).filter((t,n)=>n!==e).map((e,t)=>({...e,index:t,id:`entry-${n.id}-${t}`,components:e.components?.map((e,n)=>{const i=(e.templateComponents||[])[n];return{...e,id:i?`${i.id}-entry-${t}-${n}`:e.id}})||[]}));return{...n,entries:t}}return n});d?.(n)},onNotesChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},renderFormComponent:e=>Ne(e)});case"file":const u=s||t.basic?.value||t.basic?.files||t.basic?.attachments||null;return B.jsx(ae,{...a,properties:t,formValue:u});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",t.name]})})}};return B.jsx("div",{className:"form-preview-container",children:B.jsx("div",{className:"form-preview-wrapper",children:B.jsxs("div",{className:`form-preview ${Object.entries(ge()).map(([e,t])=>t?e:"").join(" ")}`,children:[B.jsx("div",{className:"form-canvas-header"}),0===r.length?B.jsx("div",{className:"empty-state",children:B.jsx("div",{className:"empty-state-card",children:B.jsx("div",{className:"empty-state-preview-area",children:B.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):B.jsxs("form",{className:"form-preview-form",onSubmit:e=>{e.preventDefault(),be()},children:[(u||m)&&B.jsxs("div",{className:"form-header",children:[u&&B.jsx("h1",{className:"form-title",children:u}),m&&B.jsx("p",{className:"form-description",children:m})]}),r.map(e=>{const t=e.basic,n=y[e.id],i=["select","radio","checkbox","segment"].includes(e.name||""),s=e.options||t?.options||[],a=(()=>{const t=e?.styles?.column;return"section"===e.name||"table"===e.name||"datagrid"===e.name?"col-12":3===t?"col-3":6===t?"col-6":9===t?"col-9":"col-12"})();let l=!1;if(!o)if(i&&null!=n&&""!==n)if("checkbox"===e.name){l=(Array.isArray(n)?n:[n]).some(e=>{const t=s.find(t=>t.value===e);return t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)})}else{const e=s.find(e=>e.value===n);l=e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)}else l=t?.enableNotes||t?.enableAttachment||t?.enableRaiseIssue||t?.enableSendEmail;const c=o&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:`form-group ${a} ${l||c?"has-action-features":""}`,style:{display:P(e.id)?"block":"none"},children:[Ne(e),!o&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:o?"preview":"test",formTemplateId:p,formValue:n,onThresholdActionCompletion:me,onThresholdIssueRaised:de,onNotesChange:t=>{const n=r.map(n=>n.id===e.id?{...n,basic:{...n.basic,notes:t||""}}:n);d?.(n)},onAttachmentChange:t=>{const n=r.map(n=>n.id===e.id?{...n,basic:{...n.basic,attachments:t||[]}}:n);d?.(n)},notes:e.basic?.notes||"",attachments:e.basic?.attachments||null}),o&&c&&B.jsx(pe,{component:e})]},e.id)}),!o&&B.jsx("div",{className:"form-actions",children:B.jsx("button",{type:"submit",disabled:!H()||!L.isValid,className:"form-submit-button",title:L.isValid?"":L.errorMessage,children:"Submit"})})]})]})})})},Ne=({comment:e="",onSave:s,placeholder:r="Enter your reason...",className:a="",disabled:o=!1})=>{const[l,c]=t(!0),[d,u]=t(e),[m,p]=t(!1);n(()=>{u(e),p(!1)},[e]);const h=i(t=>{const n=t.target.value;u(n),p(n!==e)},[e]),f=i(()=>{m&&s&&!o&&(s(d),p(!1))},[m,s,d,o]),b=i(()=>{},[]),g=i(()=>{o||c(!l)},[l,o]);return B.jsxs("div",{className:`df-form-comments ${a}`,children:[B.jsxs("div",{className:"df-form-comments__header",children:[B.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),B.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:g,"aria-expanded":l,"aria-label":"Toggle comments section",disabled:o,children:l?B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),B.jsx("div",{className:"df-form-comments__content "+(l?"df-form-comments__content--expanded":""),children:B.jsx("div",{className:"df-form-comments__input-container",children:B.jsx("div",{className:"df-form-comments__input-line",children:B.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:d,onChange:h,onBlur:f,onFocus:b,placeholder:r,disabled:o})})})})]})},Ce=e=>e.id?e:{...e,id:M()},we=({component:e,mode:t,renderFormComponent:n,formData:i={},formTemplateId:s,onThresholdActionCompletion:r,onThresholdIssueRaised:a,onNotesChange:o,onAttachmentChange:l})=>{const c=i[e.id],d="preview"===t&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:"simple-table-component",children:[n(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:s,formValue:c,onThresholdActionCompletion:r,onThresholdIssueRaised:a,onNotesChange:o?t=>o(e.id,t):void 0,onAttachmentChange:l?t=>l(e.id,t):void 0}),d&&B.jsx(pe,{component:e})]})},Se=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:s,onComponentEdit:r,renderFormComponent:a,isOverlay:o=!1})=>{const{attributes:l,listeners:c,setNodeRef:d,transform:u,transition:m,isDragging:p,isSorting:h}=V({id:e.id,disabled:o}),f={transform:O.Transform.toString(u),transition:m,opacity:p?.3:1,zIndex:p?1e3:"auto"};return B.jsxs("div",{ref:d,style:f,className:`form-component table-component ${t?.id===e.id?"selected":""} ${p?"dragging":""} ${h?"sorting":""}`,onClick:()=>!p&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...c,...l,onClick:e=>e.stopPropagation(),style:{opacity:1},children:B.jsx($,{size:14})}),B.jsx("div",{className:"component-content",children:a(e)}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{opacity:1},children:[r&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),r(e)},type:"button",title:"Edit Component",children:B.jsx(k,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),s(e,t)},type:"button",title:"Delete Component",children:B.jsx(E,{size:12})})]})]})},$e=({cell:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,selectedComponent:r,renderFormComponent:a,formData:o={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,tableId:u,onNotesChange:m,onAttachmentChange:p})=>{const h=`table-cell-${u}-${e.row}-${e.column}`,{setNodeRef:f,isOver:b}=R({id:h,disabled:"edit"!==t,data:{type:"table-cell",tableId:u,cell:e,row:e.row,column:e.column}}),g={...e.styles,backgroundColor:b?"var(--df-color-primary-light)":e.styles?.backgroundColor||"transparent",minHeight:e.styles?.minHeight||"preview"===t||"test"===t?"40px":"60px",padding:(e.styles,"8px"),border:"preview"===t||"test"===t?"none":b?"2px dashed var(--df-color-primary)":e.styles?.borderColor?`1px solid ${e.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===t||"test"===t?"0":"4px",position:"relative",verticalAlign:e.styles?.verticalAlign||"top"};return B.jsx("td",{ref:f,style:g,className:"table-cell "+(b?"drag-over":""),children:B.jsx("div",{className:"cell-content",children:e.components&&Array.isArray(e.components)&&e.components.length>0?"edit"===t?B.jsx(L,{items:e.components.map(e=>e.id||M()),strategy:D,children:e.components.map(e=>{const o=Ce(e);return B.jsx(Se,{component:o,selectedComponent:r,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,renderFormComponent:a},o.id)})}):e.components.map(e=>{const n=e.id?e:Ce(e);return B.jsx(we,{component:n,mode:t,renderFormComponent:a,formData:o,formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,onNotesChange:m,onAttachmentChange:p},n.id)}):"edit"===t?B.jsx("div",{className:"empty-cell-placeholder",children:B.jsxs("div",{className:"cell-info",children:[B.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),B.jsxs("span",{className:"cell-coordinates",children:["Cell (",e.row+1,", ",e.column+1,")"]})]})}):B.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},ke=({id:e,properties:s,mode:a="edit",formData:o={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onTableSelect:f,onComponentSelect:b,onComponentDelete:g,onComponentEdit:v,selectedComponent:y,renderFormComponent:x,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,onNotesChange:$,onAttachmentChange:k})=>{const[E,T]=t(!1),I=s.cells?.some(e=>e.some(e=>e.components&&e.components.length>0))||!1;n(()=>{},[s.table?.rows,s.table?.columns,s.basic?.rows,s.basic?.columns,s.cells,e,u]);const R=i(e=>{e.stopPropagation(),m?.(),f?.(s)},[m,f,s]),L=i((t,n)=>{n.stopPropagation();const i=s.cells.map(e=>e.map(e=>{if(e.components&&e.components.some(e=>e.id===t.id)){const n=e.components.filter(e=>e.id!==t.id);return{...e,components:n}}return e}));u&&u({id:e,value:{...s,cells:i}})},[g,s,u,e]),D=r(()=>s.cells?s.cells.map((t,n)=>t.map((t,i)=>({...t,components:t.components&&Array.isArray(t.components)?t.components.map((t,s)=>{if(t.id&&"string"==typeof t.id&&""!==t.id.trim())return t;const r=`${t.name||"component"}-table-${e}-row-${n}-cell-${i}-comp-${s}`;return{...t,id:r}}):[]}))):[],[s.cells,e]),V=x||i(e=>{const t=e.id?e:Ce(e),n=o[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let i=n;"number-input"===t.name&&"number"==typeof n?i=String(n):"number-input"===t.name&&null==n&&(i="");const s={id:t.id,properties:t,validationErrors:{},formValue:i,touchedFields:{},formSubmitted:!1,mode:a,onValueChange:e=>{u?.(e)},onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...s,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...s,properties:t,readonly:!1,disabled:!1});case"select":const e={...t,options:t.basic?.options||[]};return B.jsx(ee,{...s,properties:e,disabled:!1});case"checkbox":const n={...t,options:t.basic?.options||[]};return B.jsx(te,{...s,properties:n,formValue:[],disabled:!1});case"radio":const i={...t,options:t.basic?.options||[]};return B.jsx(ne,{...s,properties:i,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...s,properties:t,readonly:!1,disabled:!1});case"signature":return B.jsx(re,{...s,properties:t});case"heading":return B.jsx(le,{...s,properties:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",t.name]})}},[x,a,o,u]),F={backgroundColor:s.styles?.backgroundColor||"var(--df-color-fb-container)",borderColor:s.styles?.borderColor||"var(--df-color-fb-border)",borderWidth:s.styles?.borderWidth||"2px",borderRadius:s.styles?.borderRadius||"8px",padding:s.styles?.padding||"16px",margin:s.styles?.margin||"16px 0"},O={width:"100%",minWidth:"600px",borderCollapse:"preview"===a||"test"===a?"separate":"collapse",tableLayout:"fixed",border:"preview"===a||"test"===a?"1px solid var(--df-color-fb-border)":"none"};return I||"preview"!==a?B.jsxs("div",{className:`form-group df-form-table ${p?"selected":""} ${"preview"===a?"preview-mode":"test"===a?"test-mode":""} ${h}`,onClick:R,style:F,children:[B.jsx("div",{className:"table-header",children:B.jsx("div",{className:"table-title",onClick:t=>{t.stopPropagation(),T(!E),u?.({id:e,value:{...s,basic:{...s.basic||{},collapsed:!E}}})},children:B.jsxs("div",{className:"title-content",children:[E?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(A,{size:16}),B.jsx("span",{className:"table-label",children:s.basic?.label||"Table"}),s.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]})})}),s.basic?.description&&!E&&B.jsx("div",{className:"table-description",children:s.basic.description}),!E&&B.jsxs("div",{className:"table-content",children:[null,B.jsxs("table",{style:O,children:[s.table?.displayAsTable&&("edit"===a||s.table?.showColumns)&&B.jsx("thead",{children:B.jsx("tr",{className:"table-header-row",children:Array.from({length:s.table?.columns||s.basic?.columns||3},(e,t)=>{const n=(s.table?.columnNames?.split(",").map(e=>e.trim())||[])[t]||`Column ${t+1}`;return B.jsx("th",{className:"table-header-cell",style:{backgroundColor:(s.styles.headerBackgroundColor,"var(--df-color-fb-container)"),color:s.styles.headerTextColor||"var(--df-color-text-dark)",padding:"12px",border:"1px solid var(--df-color-fb-border)",fontWeight:"600",fontSize:"14px",textAlign:"center"},children:n},`header-${t}`)})})}),B.jsx("tbody",{children:D.map((t,n)=>B.jsx("tr",{className:"table-row",children:t.map(t=>B.jsx($e,{cell:t,mode:a,onComponentSelect:b||(()=>{}),onComponentDelete:L,onComponentEdit:v,selectedComponent:y||null,renderFormComponent:V,formData:o,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,tableId:e,onNotesChange:$,onAttachmentChange:k},t.id))},n))})]})]})]}):null};var Ee,Te=Object.freeze({__proto__:null,DfFormTable:ke,default:ke});!function(e){e.Top="top",e.Left="left"}(Ee||(Ee={}));export{ue as ComponentActionFeatures,pe as ComponentSubmissionActions,te as DfFormCheckbox,Ne as DfFormComments,ye as DfFormDataGrid,se as DfFormDateTime,H as DfFormErrorMsg,ae as DfFormFileUpload,le as DfFormHeading,Z as DfFormInput,ce as DfFormInstruction,oe as DfFormLocation,je as DfFormPreview,ne as DfFormRadio,fe as DfFormSection,ie as DfFormSegment,ee as DfFormSelect,re as DfFormSignature,ke as DfFormTable,Q as DfFormTextarea,Ee as ELabelAlignment,K as RaiseIssueModal,X as ThresholdAlert,G as conditionalLogicService,J as toastService};
10
+ */"production"===process.env.NODE_ENV?M.exports=function(){if(P)return z;P=1;var t=e,n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,r=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(e,t,i){var o,l={},c=null,d=null;for(o in void 0!==i&&(c=""+i),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(d=t.ref),t)s.call(t,o)&&!a.hasOwnProperty(o)&&(l[o]=t[o]);if(e&&e.defaultProps)for(o in t=e.defaultProps)void 0===l[o]&&(l[o]=t[o]);return{$$typeof:n,type:e,key:c,ref:d,props:l,_owner:r.current}}return z.Fragment=i,z.jsx=o,z.jsxs=o,z}():M.exports=(_||(_=1,"production"!==process.env.NODE_ENV&&function(){var t,n=e,i=Symbol.for("react.element"),s=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),c=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),f=Symbol.for("react.offscreen"),b=Symbol.iterator,g=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];!function(e,t,n){var i=g.ReactDebugCurrentFrame.getStackAddendum();""!==i&&(t+="%s",n=n.concat([i]));var s=n.map(function(e){return String(e)});s.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,s)}("error",e,n)}function y(e){return e.displayName||"Context"}function x(e){if(null==e)return null;if("number"==typeof e.tag&&v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case r:return"Fragment";case s:return"Portal";case o:return"Profiler";case a:return"StrictMode";case u:return"Suspense";case m:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case c:return y(e)+".Consumer";case l:return y(e._context)+".Provider";case d:return function(e,t,n){var i=e.displayName;if(i)return i;var s=t.displayName||t.name||"";return""!==s?n+"("+s+")":n}(e,e.render,"ForwardRef");case p:var t=e.displayName||null;return null!==t?t:x(e.type)||"Memo";case h:var n=e,i=n._payload,f=n._init;try{return x(f(i))}catch(e){return null}}return null}t=Symbol.for("react.module.reference");var j,N,C,w,S,$,k,E=Object.assign,A=0;function T(){}T.__reactDisabledLog=!0;var L,I=g.ReactCurrentDispatcher;function R(e,t,n){if(void 0===L)try{throw Error()}catch(e){var i=e.stack.trim().match(/\n( *(at )?)/);L=i&&i[1]||""}return"\n"+L+e}var D,V=!1,F="function"==typeof WeakMap?WeakMap:Map;function O(e,t){if(!e||V)return"";var n,i=D.get(e);if(void 0!==i)return i;V=!0;var s,r=Error.prepareStackTrace;Error.prepareStackTrace=void 0,s=I.current,I.current=null,function(){if(0===A){j=console.log,N=console.info,C=console.warn,w=console.error,S=console.group,$=console.groupCollapsed,k=console.groupEnd;var e={configurable:!0,enumerable:!0,value:T,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}A++}();try{if(t){var a=function(){throw Error()};if(Object.defineProperty(a.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(a,[])}catch(e){n=e}Reflect.construct(e,[],a)}else{try{a.call()}catch(e){n=e}e.call(a.prototype)}}else{try{throw Error()}catch(e){n=e}e()}}catch(t){if(t&&n&&"string"==typeof t.stack){for(var o=t.stack.split("\n"),l=n.stack.split("\n"),c=o.length-1,d=l.length-1;c>=1&&d>=0&&o[c]!==l[d];)d--;for(;c>=1&&d>=0;c--,d--)if(o[c]!==l[d]){if(1!==c||1!==d)do{if(c--,--d<0||o[c]!==l[d]){var u="\n"+o[c].replace(" at new "," at ");return e.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,u),u}}while(c>=1&&d>=0);break}}}finally{V=!1,I.current=s,function(){if(0===--A){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:E({},e,{value:j}),info:E({},e,{value:N}),warn:E({},e,{value:C}),error:E({},e,{value:w}),group:E({},e,{value:S}),groupCollapsed:E({},e,{value:$}),groupEnd:E({},e,{value:k})})}A<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=r}var m=e?e.displayName||e.name:"",p=m?R(m):"";return"function"==typeof e&&D.set(e,p),p}function q(e,t,n){if(null==e)return"";if("function"==typeof e)return O(e,!(!(i=e.prototype)||!i.isReactComponent));var i;if("string"==typeof e)return R(e);switch(e){case u:return R("Suspense");case m:return R("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case d:return O(e.render,!1);case p:return q(e.type,t,n);case h:var s=e,r=s._payload,a=s._init;try{return q(a(r),t,n)}catch(e){}}return""}D=new F;var P=Object.prototype.hasOwnProperty,M={},z=g.ReactDebugCurrentFrame;function _(e){if(e){var t=e._owner,n=q(e.type,e._source,t?t.type:null);z.setExtraStackFrame(n)}else z.setExtraStackFrame(null)}var B=Array.isArray;function U(e){return B(e)}function G(e){return""+e}function J(e){if(function(e){try{return G(e),!1}catch(e){return!0}}(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),G(e)}var H,Y,K,X=g.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,n,s,r){var a,o={},l=null,c=null;for(a in void 0!==n&&(J(n),l=""+n),function(e){if(P.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(J(t.key),l=""+t.key),function(e){if(P.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e,t){if("string"==typeof e.ref&&X.current&&t&&X.current.stateNode!==t){var n=x(X.current.type);K[n]||(v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',x(X.current.type),e.ref),K[n]=!0)}}(t,r)),t)P.call(t,a)&&!Z.hasOwnProperty(a)&&(o[a]=t[a]);if(e&&e.defaultProps){var d=e.defaultProps;for(a in d)void 0===o[a]&&(o[a]=d[a])}if(l||c){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;l&&function(e,t){var n=function(){H||(H=!0,v("%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://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,u),c&&function(e,t){var n=function(){Y||(Y=!0,v("%s: `ref` 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://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}(o,u)}return function(e,t,n,s,r,a,o){var l={$$typeof:i,type:e,key:t,ref:n,props:o,_owner:a,_store:{}};return Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:r}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l}(e,l,c,r,s,X.current,o)}K={};var ee,te=g.ReactCurrentOwner,ne=g.ReactDebugCurrentFrame;function ie(e){if(e){var t=e._owner,n=q(e.type,e._source,t?t.type:null);ne.setExtraStackFrame(n)}else ne.setExtraStackFrame(null)}function se(e){return"object"==typeof e&&null!==e&&e.$$typeof===i}function re(){if(te.current){var e=x(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var ae={};function oe(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var n=function(e){var t=re();if(!t){var n="string"==typeof e?e:e.displayName||e.name;n&&(t="\n\nCheck the top-level render call using <"+n+">.")}return t}(t);if(!ae[n]){ae[n]=!0;var i="";e&&e._owner&&e._owner!==te.current&&(i=" It was passed a child from "+x(e._owner.type)+"."),ie(e),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,i),ie(null)}}}function le(e,t){if("object"==typeof e)if(U(e))for(var n=0;n<e.length;n++){var i=e[n];se(i)&&oe(i,t)}else if(se(e))e._store&&(e._store.validated=!0);else if(e){var s=function(e){if(null===e||"object"!=typeof e)return null;var t=b&&e[b]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof s&&s!==e.entries)for(var r,a=s.call(e);!(r=a.next()).done;)se(r.value)&&oe(r.value,t)}}function ce(e){var t,n=e.type;if(null!=n&&"string"!=typeof n){if("function"==typeof n)t=n.propTypes;else{if("object"!=typeof n||n.$$typeof!==d&&n.$$typeof!==p)return;t=n.propTypes}if(t){var i=x(n);!function(e,t,n,i,s){var r=Function.call.bind(P);for(var a in e)if(r(e,a)){var o=void 0;try{if("function"!=typeof e[a]){var l=Error((i||"React class")+": "+n+" type `"+a+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[a]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw l.name="Invariant Violation",l}o=e[a](t,a,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){o=e}!o||o instanceof Error||(_(s),v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",i||"React class",n,a,typeof o),_(null)),o instanceof Error&&!(o.message in M)&&(M[o.message]=!0,_(s),v("Failed %s type: %s",n,o.message),_(null))}}(t,e.props,"prop",i,e)}else void 0===n.PropTypes||ee||(ee=!0,v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",x(n)||"Unknown"));"function"!=typeof n.getDefaultProps||n.getDefaultProps.isReactClassApproved||v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var de={};function ue(e,n,s,b,g,y){var j=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===o||e===a||e===u||e===m||e===f||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===p||e.$$typeof===l||e.$$typeof===c||e.$$typeof===d||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!j){var N="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(N+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var C,w=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(g);N+=w||re(),null===e?C="null":U(e)?C="array":void 0!==e&&e.$$typeof===i?(C="<"+(x(e.type)||"Unknown")+" />",N=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,N)}var S=Q(e,n,s,g,y);if(null==S)return S;if(j){var $=n.children;if(void 0!==$)if(b)if(U($)){for(var k=0;k<$.length;k++)le($[k],e);Object.freeze&&Object.freeze($)}else v("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 le($,e)}if(P.call(n,"key")){var E=x(e),A=Object.keys(n).filter(function(e){return"key"!==e}),T=A.length>0?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}";de[E+T]||(v('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} />',T,E,A.length>0?"{"+A.join(": ..., ")+": ...}":"{}",E),de[E+T]=!0)}return e===r?function(e){for(var t=Object.keys(e.props),n=0;n<t.length;n++){var i=t[n];if("children"!==i&&"key"!==i){ie(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),ie(null);break}}null!==e.ref&&(ie(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),ie(null))}(S):ce(S),S}var me=function(e,t,n){return ue(e,t,n,!1)},pe=function(e,t,n){return ue(e,t,n,!0)};W.Fragment=r,W.jsx=me,W.jsxs=pe}()),W);var B=M.exports;class U{constructor(){}static getInstance(){return U.instance||(U.instance=new U),U.instance}getAvailableComponentsForConditional(e,t){if(!e||!Array.isArray(e))return[];return e.filter(e=>!t||e.id!==t).map(e=>({id:e.id,label:e.basic?.label||e.id,type:e.name,key:e.id})).sort((e,t)=>e.label.localeCompare(t.label))}getApplicableOperators(e){switch(e){case"text-input":case"email-input":case"textarea":return["equals","notEquals","contains","notContains","isEmpty","isNotEmpty"];case"number-input":case"date-picker":case"datetime-picker":return["equals","notEquals","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual","isEmpty","isNotEmpty"];case"select":case"radio":case"segment":default:return["equals","notEquals","isEmpty","isNotEmpty"];case"checkbox":return["contains","notContains","isEmpty","isNotEmpty"]}}validateConditionalLogic(e,t){const n=[];return e?(["show","hide","always"].includes(e.action)||n.push("Invalid conditional action"),["all","any"].includes(e.when)||n.push("Invalid when condition"),e.conditions&&0!==e.conditions.length?e.conditions.forEach((e,i)=>{const s=t.find(t=>t.id===e.when);if(!s)return void n.push(`Condition ${i+1}: Component not found`);this.getApplicableOperators(s.name).includes(e.operator)||n.push(`Condition ${i+1}: Operator not applicable for component type`),this.isValidConditionValue(e.value,s.name,e.operator)||n.push(`Condition ${i+1}: Invalid condition value`)}):n.push("At least one condition is required"),{isValid:0===n.length,errors:n}):{isValid:!0,errors:[]}}evaluateConditionalLogic(e,t,n){if("always"===e.action)return{shouldShow:!0,evaluatedConditions:[]};if(!e||!e.conditions||0===e.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const i=e.conditions.map(e=>{const i=this.getComponentValue(e.when,t,n);return{condition:e,result:this.evaluateCondition(e,i),componentValue:i}});return{shouldShow:this.determineFinalResult(e,i),evaluatedConditions:i}}getComponentValue(e,t,n){if(n&&void 0!==n[e])return n[e];const i=t.find(t=>t.id===e);return i&&"defaultValue"in i.basic?i.basic.defaultValue:void 0}evaluateCondition(e,t){const{operator:n,value:i}=e;if("checked"===i||"notChecked"===i)return this.evaluateCheckboxCondition(t,i);switch(n){case"equals":return this.isEqual(t,i);case"notEquals":return!this.isEqual(t,i);case"isEmpty":return this.isEmpty(t);case"isNotEmpty":return!this.isEmpty(t);case"contains":return this.contains(t,i);case"notContains":return!this.contains(t,i);case"greaterThan":return this.isGreaterThan(t,i);case"lessThan":return this.isLessThan(t,i);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(t,i);case"lessThanOrEqual":return this.isLessThanOrEqual(t,i);default:return!1}}evaluateCheckboxCondition(e,t){const n=this.isCheckboxChecked(e);return"checked"===t?n:"notChecked"===t&&!n}isCheckboxChecked(e){return null!=e&&("boolean"==typeof e?e:"string"==typeof e?"true"===e.toLowerCase()||"1"===e:Array.isArray(e)?e.length>0:"number"==typeof e&&e>0)}determineFinalResult(e,t){let n,i;return n="all"===e.when?t.every(e=>e.result):"any"===e.when&&t.some(e=>e.result),i="show"===e.action?n:"hide"===e.action?!n:(e.action,!0),i}isEqual(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>this.isEqual(e,t[n]));if("object"==typeof e&&"object"==typeof t){const n=Object.keys(e),i=Object.keys(t);return n.length===i.length&&n.every(n=>this.isEqual(e[n],t[n]))}return!1}isEmpty(e){return null==e||void 0===e||("string"==typeof e?""===e.trim():Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}contains(e,t){return null!=e&&null!=t&&("string"==typeof e?e.toLowerCase().includes(String(t).toLowerCase()):!!Array.isArray(e)&&e.some(e=>this.isEqual(e,t)))}isGreaterThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>i}isLessThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<i}isGreaterThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>=i}isLessThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<=i}isValidConditionValue(e,t,n){if(null==e)return["isEmpty","isNotEmpty"].includes(n);switch(t){case"number-input":return!isNaN(Number(e))||["isEmpty","isNotEmpty"].includes(n);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(e))||["isEmpty","isNotEmpty"].includes(n);case"checkbox":return Array.isArray(e)||"string"==typeof e||"number"==typeof e;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(e){return{equals:"Is Equal To",notEquals:"Is Not Equal To",contains:"Contains",notContains:"Does Not Contain",isEmpty:"Is Empty",isNotEmpty:"Is Not Empty",greaterThan:"Is Greater Than",lessThan:"Is Less Than",greaterThanOrEqual:"Is Greater Than Or Equal To",lessThanOrEqual:"Is Less Than Or Equal To"}[e]||e}getActionDisplayText(e){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[e]||e}getConditionalLogicSummary(e,t){if(!e||0===e.conditions.length)return"No conditions";if("always"===e.action)return"Always show";const n=this.getActionDisplayText(e.action),i=e.conditions.map(e=>{const n=t.find(t=>t.id===e.when);return`${n?.basic.label||"Unknown component"} ${this.getOperatorDisplayText(e.operator)} ${this.formatConditionValue(e.value)}`}),s="all"===e.when?" and ":" or ";return`${n} ${i.join(s)}`}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const G=U.getInstance();const J=new class{constructor(){this.toasts=[],this.listeners=[],this.defaultDuration=3e3,this.timeouts={}}generateId(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}notifyListeners(){this.listeners.forEach(e=>e([...this.toasts]))}addToast(e){try{this.toasts.push(e),this.notifyListeners(),this.timeouts[e.id]=setTimeout(()=>{this.removeToast(e.id)},e.duration||this.defaultDuration)}catch(e){console.error("Error displaying toast message:",e)}}removeToast(e){this.timeouts[e]&&(clearTimeout(this.timeouts[e]),delete this.timeouts[e]),this.toasts=this.toasts.filter(t=>t.id!==e),this.notifyListeners()}showSuccess(e,t=3e3){const n={id:this.generateId(),message:e,type:"success",duration:t};this.addToast(n)}showError(e,t=5e3){const n={id:this.generateId(),message:e,type:"danger",duration:t};this.addToast(n)}showWarning(e,t){const n={id:this.generateId(),message:e,type:"warning",duration:t};this.addToast(n)}showInfo(e,t){const n={id:this.generateId(),message:e,type:"info",duration:t};this.addToast(n)}show(e,t="success",n){const i={id:this.generateId(),message:e,type:t,duration:n};this.addToast(i)}clearAll(){Object.values(this.timeouts).forEach(e=>clearTimeout(e)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}getToasts(){return[...this.toasts]}},H=({validationErrors:e,fieldId:t,touchedFields:n,formSubmitted:i,properties:s,localValidation:r,isTouched:a,mode:o})=>{const l=e=>{const t=s.basic.label||"This field",n=s.name||"",i=s.validation?.customValidationMessage;if("number-input"===n)switch(e){case"required":return`${t} is required`;case"lowerLimit":return"Number is below the lower limit";case"upperLimit":return"Number is above the upper limit";default:return""}if(i)return i;const r="date-picker"===n||"datetime-picker"===n?s.basic?.dateTimeMode||("datetime-picker"===n?"datetime":"date"):null;switch(e){case"required":return`${t} is required`;case"invalidDate":return"time"===r?"Please select a valid time":"datetime"===r?"Please select a valid date and time":"date"===r?"Please select a valid date":`${t} is invalid`;case"minLength":return`${t} must be at least ${s.validation.minLength} characters long`;case"maxLength":return`${t} must be no more than ${s.validation.maxLength} characters long`;case"min":return`${t} must be at least ${s.validation.min}`;case"max":return`${t} must be no more than ${s.validation.max}`;case"lowerLimit":const e=s.validation,n=e?.lowerLimit;return`You are under the limit. ${t} must be at least ${n}`;case"upperLimit":const i=s.validation,a=i?.upperLimit;return`You crossed the limit. ${t} must be no more than ${a}`;case"pattern":return`${t} format is invalid`;case"email":return`${t} must be a valid email address`;default:return`${t} is invalid`}},c=(()=>{if("test"!==o)return"";if(!(a||n[t]||i))return"";if(r&&r.isValid)return"";if(r&&!r.isValid&&Object.keys(r.errors).length>0){const e=Object.keys(r.errors).filter(e=>!0===r.errors[e]);if(e.length>0){const t=e[0],n=s.name||"";return"pattern"===t&&"number-input"===n?"":l(t)}}const c=e[t];if(c&&"string"==typeof c&&""!==c.trim()){const e=s.name||"";if("number-input"===e&&r){const e=s.validation,t=e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit,n=e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||t||n?(r.isValid,""):""}if(("date-picker"===e||"datetime-picker"===e)&&c.includes("valid date")){const t=s.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 c}return""})();return c?B.jsx("div",{className:"form-error-msg",children:c}):null};var Y;!function(e){e.OPEN="Open",e.IN_PROGRESS="In-Progress",e.REJECTED="Rejected",e.RESOLVE="Resolve"}(Y||(Y={}));const K=({isOpen:e,onClose:i,onSuccess:s,component:r,formTemplateId:u,notes:m="",attachments:p=null,issue:h=null,onCreateIssue:f,onUpdateIssue:b,user:g,availableUsers:v=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"]})=>{const[y,x]=t(""),[j,N]=t(""),[C,w]=t(""),[S,$]=t(""),[k,E]=t("Medium"),[A,T]=t(Y.OPEN),[I,R]=t(""),[D,V]=t(""),[F,O]=t(!1),q=!!h;n(()=>{if(e)if(h){x(h.title||""),N(h.description||""),w(h.workOrderNumber||""),$(h.assetNumber||""),E(h.priority||"Medium");const e=h.status||Y.OPEN,t=e===Y.OPEN||e===Y.IN_PROGRESS||e===Y.REJECTED||e===Y.RESOLVE?e:Y.OPEN;T(t),R(h.assignee||""),V(h.comments||"")}else if(r){const e=r.basic?.label||"Component";x(`${e} - Issue`);let t=`Issue raised for component: ${e}`;r.basic&&"value"in r.basic&&r.basic.value&&(t+=`\nComponent Value: ${r.basic.value}`),m&&(t+=`\nNotes: ${m}`),N(t),V(m||"")}},[e,r,m,h]);const P=async e=>{if(h){O(!0);try{const t={title:String(y||"").trim(),description:String(j||"").trim(),workOrderNumber:String(C||"").trim()||"",assetNumber:String(S||"").trim()||"",formTemplateId:h.formTemplateId||"",component:h.component||{},priority:k,assignee:String(I||"").trim()||void 0,status:e,comments:String(D||"").trim()||""};b&&h._id&&await b(h._id,t),T(e);const n={[Y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[Y.RESOLVE]:"Issue resolved successfully",[Y.REJECTED]:"Issue rejected"};J.showSuccess(n[e]||"Issue status updated successfully"),s&&s(),i()}catch(e){const t=e?.message||e?.error?.message||"Failed to update issue status. Please try again.";J.showError(t)}finally{O(!1)}}};if(!e)return null;const M=B.jsx("div",{className:"raise-issue-modal-overlay",onClick:i,children:B.jsxs("div",{className:"raise-issue-modal",onClick:e=>e.stopPropagation(),children:[B.jsxs("div",{className:"raise-issue-modal-header",children:[B.jsxs("div",{className:"raise-issue-modal-header-left",children:[B.jsx(a,{className:"raise-issue-modal-icon",size:20}),B.jsx("div",{className:"raise-issue-modal-header-text",children:B.jsx("div",{className:"raise-issue-modal-title-main",children:"Issue Details"})})]}),B.jsx("button",{className:"raise-issue-modal-close",onClick:i,"aria-label":"Close",children:B.jsx(o,{size:18})})]}),B.jsx("div",{className:"raise-issue-modal-content",children:B.jsxs("div",{className:"raise-issue-fields-grid",children:[q&&h?.issueNumber&&B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),B.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:h.issueNumber,readOnly:!0})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Title ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:y,onChange:e=>x(e.target.value),placeholder:"Enter issue title",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:C,onChange:e=>w(e.target.value),placeholder:"N/A",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:S,onChange:e=>$(e.target.value),placeholder:"Enter asset number",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Raised By"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(l,{size:16}),B.jsx("span",{children:g&&`${g.firstName||""} ${g.lastName||""}`.trim()||"User"})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(c,{size:16}),B.jsx("span",{children:q&&h?.createdAt?new Date(h.createdAt).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0}):(new Date).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Description ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("textarea",{className:"raise-issue-field-textarea "+(q?"raise-issue-field-readonly":""),value:j,onChange:e=>N(e.target.value),placeholder:"Enter issue description",rows:4,readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Status ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select "+(q?"":"raise-issue-field-readonly"),value:A,onChange:e=>T(e.target.value),disabled:!q,children:[B.jsx("option",{value:Y.OPEN,children:Y.OPEN}),B.jsx("option",{value:Y.IN_PROGRESS,children:Y.IN_PROGRESS}),B.jsx("option",{value:Y.REJECTED,children:Y.REJECTED}),B.jsx("option",{value:Y.RESOLVE,children:Y.RESOLVE})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Assignee ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select",value:I,onChange:e=>R(e.target.value),children:[B.jsx("option",{value:"",children:"Unassigned"}),v.map(e=>B.jsx("option",{value:e,children:e},e))]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("div",{className:"raise-issue-priority-buttons",children:[B.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===k?"active":""),onClick:()=>E("Low"),children:"Low"}),B.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===k?"active":""),onClick:()=>E("Medium"),children:"Medium"}),B.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===k?"active":""),onClick:()=>E("High"),children:"High"})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[B.jsx(d,{size:16}),B.jsx("span",{children:"Comments"})]}),!D&&B.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),B.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(q?"raise-issue-field-readonly":""),value:D,onChange:e=>V(e.target.value),placeholder:"Add a comment...",rows:4,readOnly:q})]})]})}),B.jsx("div",{className:"raise-issue-modal-actions",children:B.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[q&&h&&B.jsxs(B.Fragment,{children:[A===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:async()=>{await P(Y.IN_PROGRESS)},disabled:F,children:F?"Processing...":"Accept"}),A===Y.IN_PROGRESS&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:async()=>{await P(Y.RESOLVE)},disabled:F,children:F?"Processing...":"Resolve"}),A===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:async()=>{await P(Y.REJECTED)},disabled:F,children:F?"Processing...":"Reject"})]}),!q&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save",onClick:async()=>{if(String(y||"").trim())if(String(j||"").trim())if(String(C||"").trim())if(String(S||"").trim())if(String(I||"").trim()){O(!0);try{if(q&&h){const e={title:String(y||"").trim(),description:String(j||"").trim(),workOrderNumber:String(C||"").trim()||"",assetNumber:String(S||"").trim()||void 0,formTemplateId:h.formTemplateId||"",component:h.component||{},priority:k,assignee:String(I||"").trim()||void 0,status:A,comments:String(D||"").trim()||""};b&&h._id&&await b(h._id,e),J.showSuccess("Issue updated successfully"),s&&s(),i()}else{if(!r)return J.showError("Component is required"),void O(!1);if(!u||""===String(u||"").trim())return J.showError("Form template is required"),void O(!1);const e={...r,basic:{...r.basic,comments:String(m||"")}},t={title:String(y||"").trim(),workOrderNumber:String(C||"").trim()||void 0,assetNumber:String(S||"").trim()||void 0,component:e,description:String(j||"").trim(),formTemplateId:u,assignee:String(I||"").trim()||void 0,priority:k,status:A,comments:String(D||"").trim()||""};let n;f&&(n=await f(t,p||[])),J.showSuccess("Issue raised successfully"),s&&s(n),i()}}catch(e){const t=e?.message||e?.error?.message||(q?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");J.showError(t)}finally{O(!1)}}else J.showError("Assignee is required");else J.showError("Asset Number is required");else J.showError("Work Order is required");else J.showError("Description is required");else J.showError("Title is required")},disabled:F||!String(y||"").trim()||!String(j||"").trim()||!String(C||"").trim()||!String(S||"").trim()||!String(I||"").trim(),children:F?"Saving...":"Save Changes"})]})})]})});return L(M,document.body)},X=({component:e,condition:s,currentValue:r,thresholdValue:o,formTemplateId:l,onIssueRaised:c,isIssueRaised:d=!1,compact:u=!1})=>{const[m,p]=t(!1),[h,f]=t(null),[b,g]=t(!1),[v,y]=t(!1);n(()=>{d&&y(!0)},[d]),n(()=>{y(!1)},[s?.id]);const x=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),j=i(async()=>{if(d||v){if(h)return void p(!0);g(!0);try{f(null),p(!0)}catch(e){console.error("Error fetching issue:",e),J.showError("Failed to load issue details")}finally{g(!1)}}else f(null),p(!0)},[d,v,l,e,h]),N=i(()=>{p(!1),d||v||f(null)},[d,v]),C=i(e=>{p(!1),f(e||null),y(!0),c&&s?.id&&c(s.id)},[c,s]);return d||v?B.jsx(B.Fragment,{children:m&&B.jsx(K,{isOpen:m,onClose:N,onSuccess:C,component:e,formTemplateId:l,notes:"",attachments:null,issue:h})}):u?B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content-compact",children:[B.jsx(a,{className:"threshold-alert-icon-compact",size:14}),B.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${x(s.operator)} ${o}`}),B.jsx("button",{type:"button",onClick:j,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),m&&B.jsx(K,{isOpen:m,onClose:N,onSuccess:C,component:e,formTemplateId:l,notes:"",attachments:null,issue:h})]}):B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content",children:[B.jsx("div",{className:"threshold-alert-header",children:B.jsxs("div",{className:"threshold-alert-title-group",children:[B.jsx(a,{className:"threshold-alert-icon",size:20}),B.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),B.jsxs("div",{className:"threshold-alert-message",children:[(()=>{const t=x(s.operator);return`${e.basic?.label||"Value"}: Value ${r} exceeds threshold ${t} ${o}`})(),B.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),B.jsx("div",{className:"threshold-alert-buttons",children:B.jsx("button",{type:"button",onClick:j,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),m&&B.jsx(K,{isOpen:m,onClose:N,onSuccess:C,component:e,formTemplateId:l,notes:"",attachments:null,issue:h})]})},Z=({id:e,properties:a,validationErrors:o={},formValue:l="",inputType:c="text",readonly:d=!1,disabled:u=!1,touchedFields:m={},formSubmitted:p=!1,mode:h="test",onValueChange:f,onBlur:b,onFocus:g,className:v="",hideLabel:y=!1,formTemplateId:x,onThresholdIssueRaised:j,raisedThresholdIssues:N=new Set})=>{const C=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?C(e.value):"label"in e?C(e.label):"":String(e||""),w=s(e),S=s(null);n(()=>{e!==w.current&&(console.warn(`[DfFormInput] Component ID changed from ${w.current} to ${e}`),w.current=e)},[e]);const $=C(l||a?.basic?.defaultValue||""),[k,E]=t($),[A,T]=t(!1),[L,I]=t(!1),[R,D]=t(new Set),[V,F]=t($),O=()=>{if(c)return c;const e=a?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},q=i(e=>{const t=(()=>{const e={};if(a?.validation?.required&&(e.required=!0),"email"===O()&&(e.email=!0),"text"===O()){const t=a.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===O()){const t=a.validation;t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&(e.lowerLimit=t.lowerLimit),t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&(e.upperLimit=t.upperLimit)}return e})(),n={};let i=!0;const s="string"==typeof e?e:null!=e?String(e):"";if(!t.required||s&&""!==s.trim()||(n.required=!0,i=!1),t.email&&s&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(s)&&(n.email=!0,i=!1),t.minLength&&s&&s.length<t.minLength&&(n.minLength=!0,i=!1),t.maxLength&&s&&s.length>t.maxLength&&(n.maxLength=!0,i=!1),"number"===O())if(delete n.pattern,delete n.min,delete n.max,s&&""!==s.trim()){const e=s.trim(),r=parseFloat(e);isNaN(r)||("lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&r<t.lowerLimit&&(n.lowerLimit=!0,i=!1),"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&r>t.upperLimit&&(n.upperLimit=!0,i=!1))}else delete n.lowerLimit,delete n.upperLimit;return{isValid:i,errors:n}},[a,O]),P=i(t=>{const n="string"==typeof t?t:null!=t?String(t):"";if(E(n),f){const t=q(n),i=w.current,s={id:i,value:n,isValid:t.isValid,errors:t.errors};i!==e&&console.error(`[DfFormInput] ID mismatch in handleValueChange! ref: ${i}, prop: ${e}`),f(s)}},[e,f,q,w]);n(()=>{A&&(m[e]=!0)},[A,e,m]),n(()=>{if("edit"===h){T(!1);E(a?.basic?.defaultValue||"")}else"test"===h&&(T(!1),E(""))},[h,a?.basic?.defaultValue]),n(()=>{const t=w.current,n=C(l||a?.basic?.defaultValue||"");n===k||L||""===n&&""!==String(k||"").trim()?""===n&&String(k||"").trim():null!=l&&(t===e?E(n):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${t}, prop id: ${e}`))},[l,k,L,a?.basic?.defaultValue,e]),n(()=>{p&&T(!0)},[p]),n(()=>{"test"!==h&&E("")},[h]);const M=i((e,t)=>{if(!t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(isNaN(n)||isNaN(i))return!1;switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}},[]),z=r(()=>a?.condition?.conditions||[],[a?.condition]);n(()=>{k!==V&&(D(new Set),F(k))},[k,V]);const _=r(()=>{if("test"!==h||!k||""===k)return null;const e=z.filter(e=>M(e,k));if(0===e.length)return null;for(const t of e)if(!R.has(t.id))return t;return null},[k,z,R,h,M,N]),W=i(e=>{D(t=>new Set(t).add(e))},[]),U=O(),G=u||d||a?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:`form-group ${(()=>{const e=a?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!y&&a.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[a.basic.label,a.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",ref:S,children:[B.jsx("input",{type:U,id:e,value:k,onChange:e=>{const t=e.target.value;P(t)},onFocus:()=>{I(!0),g&&g()},onBlur:()=>{if(I(!1),T(!0),"test"===h&&f){const t="string"==typeof k?k:null!=k?String(k):"",n=q(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};f(i)}b&&b()},placeholder:a.basic.placeholder,disabled:G,readOnly:d||a?.validation?.readonly,className:(()=>{const t="form-control";if("test"===h){const n="string"==typeof k?k:null!=k?String(k):"",i=q(n);if(i.isValid)return`${t} ${v}`.trim();const s=!i.isValid&&A,r=o[e]&&(A||p)&&!i;return`${t} ${s||r?"is-invalid":""} ${v}`.trim()}return`${t} ${v}`.trim()})()}),B.jsx(H,{validationErrors:o,fieldId:e,touchedFields:m,formSubmitted:p,properties:a,localValidation:q(k),isTouched:A,mode:h})]})]}),_&&"test"===h&&(()=>{const e=N?.has(_.id)||!1,t=null!==S.current?.closest(".table-cell")||null!==S.current?.closest(".cell-content")||null!==S.current?.closest(".datagrid-table-view")||null!==S.current?.closest(".datagrid-list-view")||v.includes("table-cell")||v.includes("cell-content");return B.jsx(X,{component:a,condition:_,currentValue:k,thresholdValue:_.value,formTemplateId:x,onDismiss:()=>W(_.id),onIssueRaised:j,isIssueRaised:e,compact:t},`${_.id}-${e}`)})()]})},Q=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),s?.validation?.minLength&&e&&e.length<s.validation.minLength&&(t.minLength=!0,n=!1),s?.validation?.maxLength&&e&&e.length>s.validation.maxLength&&(t.maxLength=!0,n=!1),{isValid:n,errors:t}},[s]),N=i(t=>{if(v(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{""===g&&""!==a&&v(a)},[a]),n(()=>{d&&x(!0)},[d]),n(()=>{"test"!==u&&v("")},[u]);const C=l||o||s?.validation?.readonly,w=s?.validation?.rows||4;return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("textarea",{id:e,value:g,onChange:e=>{const t=e.target.value;N(t)},onFocus:()=>{h&&h()},onBlur:()=>{x(!0),p&&p()},placeholder:s.basic.placeholder,disabled:C,readOnly:o||s?.validation?.readonly,rows:w,className:`form-textarea ${!j(g).isValid&&y?"is-invalid":""} ${f}`.trim()}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})]})},ee=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=s?.validation?.multiple||!1,N=i(e=>{const t={};let n=!0;return s?.validation?.required&&(j?Array.isArray(e)&&0!==e.length||(t.required=!0,n=!1):(!e||"string"==typeof e&&""===e.trim())&&(t.required=!0,n=!1)),{isValid:n,errors:t}},[s,j]),C=i(t=>{if(v(t),m){const n=N(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,N]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{JSON.stringify(a)!==JSON.stringify(g)&&v(a)},[a,g]),n(()=>{d&&x(!0)},[d]);const w=l||o||s?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("select",{id:e,value:g,onChange:e=>{if(j){const t=Array.from(e.target.selectedOptions,e=>e.value);C(t)}else C(e.target.value)},onFocus:()=>{h&&h()},onBlur:()=>{x(!0),p&&p()},disabled:w,multiple:j,className:`form-select ${!N(g).isValid&&y?"is-invalid":""} ${f}`.trim(),children:[!j&&B.jsx("option",{value:"",children:s.basic.placeholder||"Select an option"}),(s.options||[]).map((e,t)=>B.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:N(g),isTouched:y,mode:u})]})]})},te=({id:e,properties:s,validationErrors:r={},formValue:a=[],readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(!1),y=Array.isArray(a)?a:[],x=i(e=>{const t={};let n=!0;return s?.validation?.required&&0===e.length&&(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),j=i(t=>{if(m){const n=x(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,x,y]),N=(e,t)=>{let n;n=t?[...y,e]:y.filter(t=>t!==e),j(n)},C=()=>{h&&h()},w=()=>{v(!0),p&&p()};n(()=>{g&&(c[e]=!0)},[g,e,c]),n(()=>{},[a,e,y]),n(()=>{d&&v(!0)},[d]);const S=l||o||s?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group checkbox-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${s?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!b&&s.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:x(y),isTouched:g,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:x(y),isTouched:g,mode:u})]})})})},ne=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),N=i(t=>{if(v(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=e=>{N(e)},w=()=>{h&&h()},S=()=>{x(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{a!==g&&v(a)},[a,g]),n(()=>{d&&x(!0)},[d]);const $=l||o||s?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group radio-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${s?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!b&&s.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:g===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:$||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(s?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(s.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:g===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:$||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})})})},ie=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const[g,v]=t(a),[y,x]=t(!1),j=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),N=i(t=>{if(v(t),x(!0),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=()=>{h&&h()},w=()=>{x(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{a!==g&&v(a)},[a,g]),n(()=>{d&&x(!0)},[d]);const S=()=>s?.basic?.inlineLayout?"inline-layout":"grid-layout",$=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},k=e=>{if(void 0!==e?.icon&&""!==e.icon)return e.icon;return"pass"===$(e?.value||e)?"✓":"×"},E=(e,t)=>e?.color||e?.backgroundColor?{color:t?"#ffffff":e.color||"#00814b",backgroundColor:t?e.color||"#00814b":e.backgroundColor||"#34bd4914",borderColor:e.color||"#00814b"}:{},A=e=>{if(e?.color||e?.backgroundColor)return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===$(e?.value||e)?"pass-button":"fail-button")},T=l||o||s?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsx("div",{className:`form-group segment-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${f}`,children:!b&&s.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(s.options||[]).map((t,n)=>{const i=g===t.value,s=E(t,i),r=A(t),a=k(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!T&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:T||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:r,style:Object.keys(s).length>0?s:void 0,children:[a&&B.jsx("span",{className:"segment-icon",children:a}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})]}):B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(s.options||[]).map((t,n)=>{const i=g===t.value,s=E(t,i),r=A(t),a=k(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!T&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:T||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:r,style:Object.keys(s).length>0?s:void 0,children:[a&&B.jsx("span",{className:"segment-icon",children:a}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,mode:u})]})},se=({id:e,properties:s,validationErrors:r={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:b=!1})=>{const g=i(e=>{if(!e)return"";if("string"==typeof e){if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e))return e;const t=new Date(e);if(!isNaN(t.getTime())){const e=s.name||"",n=s.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("datetime"===n){return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}T${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}return e}if(e instanceof Date){if(isNaN(e.getTime()))return"";const t=s.name||"",n=s.basic?.dateTimeMode||("datetime-picker"===t?"datetime":"date");if("datetime"===n){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}T${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}if("object"==typeof e&&null!==e){if("value"in e&&e.value)return g(e.value);if("date"in e&&e.date)return g(e.date);try{const t=String(e),n=new Date(t);if(!isNaN(n.getTime()))return g(n)}catch(e){}return""}return""},[s]),v=g(a),[y,x]=t(v),[j,N]=t(!1),[C,w]=t(!1),S=i(e=>{const t={};let n=!0;const i=s.name||"",r=s.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"),a=e?String(e).trim():"";if(s?.validation?.required&&(!a||""===a))return t.required=!0,n=!1,{isValid:n,errors:t};if(a&&""!==a)if("time"===r){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(a))return t.invalidDate=!0,n=!1,{isValid:n,errors:t}}else if("datetime"===r){const e=new Date(a);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(s?.validation?.minDate){const i=new Date(s.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date and time must be on or after ${i.toLocaleDateString()}`,n=!1)}if(s?.validation?.maxDate){const i=new Date(s.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date and time must be on or before ${i.toLocaleDateString()}`,n=!1)}}else{const e=new Date(a);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(s?.validation?.minDate){const i=new Date(s.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date must be on or after ${i.toLocaleDateString()}`,n=!1)}if(s?.validation?.maxDate){const i=new Date(s.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date must be on or before ${i.toLocaleDateString()}`,n=!1)}}return{isValid:n,errors:t}},[s]),$=i(t=>{if(x(t),m){const n=S(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,S]);n(()=>{j&&(c[e]=!0)},[j,e,c]),n(()=>{const e=g(a);e===y||C||x(e)},[a,y,C,g]),n(()=>{d&&N(!0)},[d]);const k=l||o||s?.validation?.readonly,E=s.name||"",A=s.basic?.dateTimeMode||("datetime-picker"===E?"datetime":"date"),T=(()=>{switch(A){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("input",{type:T,id:e,value:y,onChange:e=>{const t=e.target.value;$(t)},onFocus:()=>{w(!0),h&&h()},onBlur:()=>{if(w(!1),N(!0),m){const t=S(y),n={id:e,value:y,isValid:t.isValid,errors:t.errors};m(n)}p&&p()},disabled:k,readOnly:o||s?.validation?.readonly,min:s?.validation?.minDate,max:s?.validation?.maxDate,className:`form-date ${!S(y).isValid&&j?"is-invalid":""} ${f}`.trim()}),B.jsx(H,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:S(y),isTouched:j,mode:u})]})]})},re=({id:e,properties:r,validationErrors:a={},formValue:o="",readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="preview",onValueChange:p,onBlur:h,onFocus:f,className:b="",hideLabel:g=!1})=>{const v=s(null),[y,x]=t(!1),[j,N]=t(!1),[C,w]=t(o),[S,$]=t(!1),k=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),E=i(t=>{if(w(t),p){const n=k(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};p(i)}},[e,p,k]),A=i(()=>{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}},[]),T=i(t=>{if(!t)return;const n=v.current;if(!n)return;const i=n.getContext("2d");if(!i)return;const s=new Image;s.onload=()=>{i.clearRect(0,0,n.width,n.height);const e=A();i.fillStyle=e.backgroundColor,i.fillRect(0,0,n.width,n.height);const t=n.width/n.height,r=s.width/s.height;let a=n.width,o=n.height,l=0,c=0;r>t?(o=n.width/r,c=(n.height-o)/2):(a=n.height*r,l=(n.width-a)/2),i.drawImage(s,l,c,a,o)},s.onerror=n=>{console.error("DfFormSignature: error loading image",{id:e,error:n,dataURL:t.substring(0,50)+"..."})},s.src=t},[A,e]),L=i(()=>{const e=v.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height,e.style.width=n.width+"px",e.style.height=n.height+"px";const i=A();t.strokeStyle=i.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?T(C):(t.fillStyle=i.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,A,T]),I=i(()=>{setTimeout(()=>{L()},100)},[L]);n(()=>{const e=()=>{I()},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"))&&I()}})});return t.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[I]);const R=i(e=>{const t=v.current;if(!t)return{x:0,y:0};const n=t.getBoundingClientRect(),i=t.width/n.width,s=t.height/n.height,r=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,a=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(r-n.left)*i,y:(a-n.top)*s}},[]),D=e=>{if(l||c||r?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),x(!0),N(!0);const t=v.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:s}=R(e),a=A();n.strokeStyle=a.strokeColor,n.lineWidth=2,n.lineCap="round",n.lineJoin="round",n.beginPath(),n.moveTo(i,s)},V=e=>{if(!y)return;e.preventDefault(),e.stopPropagation();const t=v.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:s}=R(e);n.lineTo(i,s),n.stroke()},F=()=>{if(!y)return;x(!1),$(!0);const e=v.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const n=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<n.length;e+=4){const t=n[e],i=n[e+1],s=n[e+2];if(n[e+3]>0&&(t<255||i<255||s<255))return!0}})(e);const t=e.toDataURL("image/png");w(t),E(t),setTimeout(()=>{$(!1)},100)}else $(!1)},O=i(()=>{const e=v.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=A();if(t.strokeStyle=n.strokeColor,C){const i=C,s=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,s.width,s.height),i&&T(i)}else{const i=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,i.width,i.height)}},[A,C,T]);n(()=>{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]);n(()=>{j&&(d[e]=!0)},[j,e,d]),n(()=>{if(!(o===C||y||S||""!==C&&""===o)){if(o===C)return;w(o),o&&T(o)}},[o,C,y,S]),n(()=>{u&&N(!0)},[u]),n(()=>{if("test"!==m){w("");const e=v.current;if(e){const t=e.getContext("2d");if(t){const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height;const i=A();t.fillStyle=i.backgroundColor,t.fillRect(0,0,n.width,n.height)}}}},[m]),n(()=>{L()},[m]);const q=c||l||r?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[B.jsx("canvas",{ref:v,id:e,className:`form-signature ${!k(C).isValid&&j?"is-invalid":""} ${b}`.trim(),onMouseDown:D,onMouseMove:V,onMouseUp:F,onMouseLeave:F,onTouchStart:D,onTouchMove:V,onTouchEnd:F,onFocus:()=>{f&&f()},onBlur:()=>{h&&h()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:q?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!q&&B.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=v.current;if(!t)return;const n=t.getBoundingClientRect();t.width=n.width,t.height=n.height;const i=t.getContext("2d");if(!i)return;const s=A();i.fillStyle=s.backgroundColor,i.fillRect(0,0,n.width,n.height),i.strokeStyle=s.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"})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:k(C),isTouched:j,mode:m})]})]})},ae=({id:e,properties:r,validationErrors:a={},formValue:o=null,readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="test",onValueChange:p,onBlur:h,onFocus:f,className:b="",hideLabel:g=!1})=>{const[v,y]=t([]),[x,j]=t(!1),[N,C]=t(!1),w=s(null),S=i(t=>{if(!t)return[];const n=Array.isArray(t)?t:Array.from(t),i=[];return n.forEach((t,n)=>{if(t&&"object"==typeof t&&!(t instanceof File)&&!(t instanceof Blob)){const s=t;if(s.data||s.url||s.name&&s.type){const t=s.name||s.fileName||`file-${n}`,r=s.size||s.fileSize||0,a=s.type||s.fileType||s.mimeType||"";let o;if(s.url)o=s.url;else if(s.data){const e=s.data;if("string"==typeof e)if(e.startsWith("data:"))o=e;else{const t=e.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>10){let e=a;e||(e=t.startsWith("/9j/")||t.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":t.startsWith("iVBORw0KGgo")?"image/png":t.startsWith("R0lGOD")?"image/gif":t.startsWith("UklGR")?"image/webp":"image/png"),o=`data:${e};base64,${t}`}else o=e}}const l=new File([],t,{type:a});return void i.push({file:l,id:`${e}-file-${n}`,size:r,type:a,name:t,preview:o})}}let s,r,a=0,o="",l="";if(t instanceof File||t instanceof Blob){const e=t;if(a=e.size||0,o=e.type||"",l=e.name||`file-${n}`,r=e,o.startsWith("image/"))try{s=URL.createObjectURL(e)}catch(e){console.error("Error creating object URL:",e),s=void 0}}else if("string"==typeof t){const e=t,i=e.replace(/\s/g,""),a=i.length>50&&/^[A-Za-z0-9+/=]+$/.test(i)&&!e.startsWith("http")&&!e.startsWith("https")&&!e.startsWith("data:")&&!e.startsWith("blob:")&&!e.startsWith("/");let c=e;if(a){let e="image/png";i.startsWith("/9j/")||i.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?e="image/jpeg":i.startsWith("iVBORw0KGgo")?e="image/png":i.startsWith("R0lGOD")?e="image/gif":i.startsWith("UklGR")&&(e="image/webp"),c=`data:${e};base64,${i}`}let d="";if(c.startsWith("data:")){const e=c.match(/filename=([^;]+)/i);if(e)d=decodeURIComponent(e[1]);else{const e=c.match(/data:([^;]+)/);if(e){const t=e[1];d=`file-${n+1}.${t.includes("image")?t.includes("jpeg")?"jpg":"png":t.includes("pdf")?"pdf":t.includes("word")?"doc":t.includes("excel")?"xls":"file"}`}else d=`file-${n+1}`}}else if(c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))try{const t=new URL(e),i=t.pathname.split("/").pop()||"";if(i&&i.includes("."))d=decodeURIComponent(i);else{const e=t.searchParams.get("filename")||t.searchParams.get("name");d=e?decodeURIComponent(e):`file-${n+1}`}}catch(t){const i=e.lastIndexOf("/"),s=i>=0?e.substring(i+1):e,r=s.indexOf("?"),a=r>=0?s.substring(0,r):s;d=a&&a.includes(".")?decodeURIComponent(a):`file-${n+1}`}else d=`file-${n+1}`;if(l=d||`file-${n+1}`,c.startsWith("data:")){const e=c.indexOf(";");o=e>5?c.substring(5,e):"application/octet-stream"}else{const e=c.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i)||l.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(e){o={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 o=a?"image/png":"application/octet-stream"}(c.startsWith("data:image")||c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))&&(s=c),r=new File([],l,{type:o})}else{if(!t||"object"!=typeof t)return;{const e=t;if(l=e.name||e.fileName||`file-${n}`,a=e.size||e.fileSize||0,o=e.type||e.fileType||e.mimeType||"",e.url||e.path)s=e.url||e.path;else if(o.startsWith("image/")&&e.data){const t=e.data;if("string"==typeof t)if(t.startsWith("data:"))s=t;else{const e=t.replace(/\s/g,"");s=/^[A-Za-z0-9+/=]+$/.test(e)&&e.length>50?`data:${o};base64,${e}`:t}else s=void 0}r=new File([],l,{type:o})}}i.push({file:r,id:`${e}-file-${n}`,size:a,type:o,name:l,preview:s})}),i},[e]),$=i(()=>({isValid:!0,errors:{}}),[]),k=i(t=>{if(l||c)return;const n=S(t),i=v.length>0?[...v,...n]:n,s=r?.validation?.maxFiles||1/0,a=i.slice(0,s);if(y(a),C(!0),p){const t=$(),n={id:e,value:a.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}},[v,r,l,c,p,$,S,e]),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]},A=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")?"📦":"📁";n(()=>{N&&(d[e]=!0)},[N,e,d]),n(()=>{("edit"===m||"test"===m)&&C(!1)},[m]),n(()=>{const e=S(o);null!=o&&(Array.isArray(o)&&o.length>0||"string"==typeof o&&""!==String(o).trim()||"object"==typeof o&&!Array.isArray(o)&&Object.keys(o).length>0)||0===v.length&&null!=o?y(e):(null==o||Array.isArray(o)&&0===o.length)&&v.length>0&&y([])},[o,S,v.length]),n(()=>{u&&C(!0)},[u]),n(()=>()=>{v.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[v]);const T=()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"},L=c||l||r?.validation?.readonly,I=r?.validation?.multiple||!1,R=r?.validation?.accept||"*/*",D=r?.validation?.maxFiles||1/0,V=v.length<D&&(I||D>1),F="edit"===m,O="preview"===m||"test"===m,q=v.filter(e=>e.type.startsWith("image/")),P=v.filter(e=>!e.type.startsWith("image/")),M=q.length>0;return O&&M?B.jsxs("div",{className:`form-group ${T()}`,children:[!g&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic?.label||"Attachments",r.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:"file-image-display",children:[q.map(e=>B.jsxs("div",{className:"file-image-container",children:[e.preview&&B.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),B.jsxs("div",{className:"file-image-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:E(e.size)})]})]},e.id)),P.length>0&&B.jsxs("div",{className:"file-other-files",children:[B.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),P.map(e=>B.jsxs("div",{className:"file-item-minimal",children:[B.jsx("div",{className:"file-icon",children:A(e.type)}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:E(e.size)})]})]},e.id))]})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:$(),isTouched:N,mode:m})]})]}):B.jsxs("div",{className:`form-group ${T()}`,children:[!g&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic?.label||"Attachments",r.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:`file-upload-area ${x?"drag-over":""} ${l?"readonly":""} ${c?"disabled":""} ${b}`.trim(),onDragOver:e=>{e.preventDefault(),l||c||j(!0)},onDragLeave:e=>{e.preventDefault(),j(!1)},onDrop:e=>{if(e.preventDefault(),j(!1),l||c)return;const t=e.dataTransfer.files;t.length>0&&k(t)},onClick:e=>{const t=e.target,n=null!==t.closest(".file-item"),i=null!==t.closest(".file-remove");!F||L||0!==v.length||n||i||w.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(C(!0),"test"===m&&p){const t=$(),n={id:e,value:v.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}h&&h()},tabIndex:L?-1:0,children:[B.jsx("input",{ref:w,type:"file",id:e,multiple:I,accept:R,onChange:e=>{const t=e.target.files;t&&t.length>0&&(k(t),e.target.value="")},disabled:L,style:{display:"none"}}),0===v.length?B.jsxs("div",{className:"upload-placeholder",onClick:e=>{e.stopPropagation(),F&&!L&&w.current?.click()},children:[B.jsx("div",{className:"upload-icon",children:"📁"}),B.jsx("div",{className:"upload-text",children:r.basic.placeholder&&B.jsx("p",{className:"upload-hint",children:r.basic.placeholder})})]}):B.jsx("div",{className:"file-list",children:v.map(t=>B.jsxs("div",{className:"file-item",children:[B.jsx("div",{className:"file-preview",children:t.preview?B.jsx("img",{src:t.preview,alt:t.name,className:"file-image"}):B.jsx("div",{className:"file-icon",children:A(t.type)})}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:t.name,children:t.name}),B.jsx("div",{className:"file-size",children:E(t.size)})]}),F&&!L&&B.jsx("button",{type:"button",className:"file-remove",onClick:n=>{n.stopPropagation(),(t=>{if(l||c)return;const n=v.filter(e=>e.id!==t);if(y(n),C(!0),p){const t=$(),i={id:e,value:n.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(i)}})(t.id)},"aria-label":`Remove ${t.name}`,children:"✕"})]},t.id))})]}),v.length>0&&V&&!L&&F&&B.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!L&&w.current&&F&&(w.current.value="",w.current.click())},"aria-label":"Add more files",children:[B.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B.jsx("path",{d:"M12 5v14M5 12h14"})}),B.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:$(),isTouched:N,mode:m})]})]})},oe=({id:e,properties:r,validationErrors:a={},formValue:l=null,readonly:c=!1,disabled:d=!1,touchedFields:h={},formSubmitted:f=!1,mode:b="test",onValueChange:g,onBlur:v,onFocus:y,className:x="",hideLabel:j=!1})=>{const[N,C]=t(l),[w,S]=t(!1),[$,k]=t(""),[E,A]=t(!1),[T,L]=t(!1),[I,R]=t({lat:40.7128,lng:-74.006}),[D,V]=t(null),[F,O]=t(10),[q,P]=t(""),[M,z]=t(!1),_=s(null),[W,U]=t(!1),[G,J]=t(null),[Y,K]=t(!1);n(()=>{if(l&&l.latitude&&l.longitude){40.7128===l.latitude&&-74.006===l.longitude||(C(l),V({lat:l.latitude,lng:l.longitude,isCurrentLocation:!1}),R({lat:l.latitude,lng:l.longitude}))}else null==l&&(C(null),V(null))},[l]),n(()=>{T&&40.7128===I.lat&&I.lng},[T,I]),n(()=>{(c||d)&&(T&&L(!1),q&&P(""),W&&(U(!1),J(null)))},[c,d]);const X=i(async(e,t)=>{K(!0);try{const n=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),i=await n.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{K(!1)}return{placeName:"",city:"",country:""}},[]),Z=i(async(t,n,i)=>{const s=await X(t,n),r={latitude:t,longitude:n,timestamp:Date.now(),placeName:s.placeName,city:s.city,country:s.country,address:s.placeName,...i};if(C(r),V({lat:t,lng:n,isCurrentLocation:!1}),A(!0),g){g({id:e,value:r,isValid:!0,errors:{}})}},[X,e,g]),Q=i(async()=>{if(c||d)return;S(!0),k("");if(void 0!==window.Capacitor)try{const{Geolocation:e}=window.Capacitor.Plugins;if(e)try{if("granted"!==(await e.requestPermissions()).location)return S(!1),void k("Location permission is required. Please enable location access in your device settings.");const t=await e.getCurrentPosition({enableHighAccuracy:r.validation?.enableHighAccuracy??!0,timeout:r.validation?.timeout??1e4,maximumAge:r.validation?.maximumAge??3e5}),n=t.coords.latitude,i=t.coords.longitude;return V({lat:n,lng:i,isCurrentLocation:!0}),R({lat:n,lng:i}),A(!0),await Z(n,i,{accuracy:t.coords.accuracy,timestamp:Date.now()}),S(!1),void k("")}catch(e){return S(!1),void(e.message?.includes("permission")||e.message?.includes("denied")?k("Location permission is required. Please enable location access in your device settings."):e.message?.includes("timeout")?k("Location request timed out. Please try again."):k("Unable to retrieve your location. Please try again."))}}catch(e){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return S(!1),void k("Geolocation is not supported by this browser.");const e={enableHighAccuracy:r.validation?.enableHighAccuracy??!0,timeout:r.validation?.timeout??1e4,maximumAge:r.validation?.maximumAge??3e5};navigator.geolocation.getCurrentPosition(async e=>{const t=e.coords.latitude,n=e.coords.longitude;V({lat:t,lng:n,isCurrentLocation:!0}),R({lat:t,lng:n}),A(!0),await Z(t,n,{accuracy:e.coords.accuracy,timestamp:e.timestamp}),S(!1),k("")},e=>{S(!1);let t="Unable to retrieve your location.";switch(e.code){case e.PERMISSION_DENIED:t="Location access denied by user. Please enable location access in your browser/device settings.";break;case e.POSITION_UNAVAILABLE:t="Location information is unavailable.";break;case e.TIMEOUT:t="Location request timed out. Please try again."}k(t)},e)},[c,d,r,Z]),ee=i(()=>{if(!c&&!d&&(C(null),V(null),k(""),A(!0),g)){g({id:e,value:null,isValid:!0,errors:{}})}},[c,d,e,g]),te=i(()=>{c||d||L(!T)},[c,d,T]),ne=i((e,t,n,i,s,r)=>{const a=e-s/2,o=t-r/2,l=156543.03392*Math.cos(n.lat*Math.PI/180)/Math.pow(2,i),c=a*l,d=o*l;return{lat:n.lat+d/111320,lng:n.lng+c/(111320*Math.cos(n.lat*Math.PI/180))}},[]),ie=i(e=>{c||d||!_.current||0===e.button&&(U(!0),J({x:e.clientX,y:e.clientY}),e.preventDefault())},[c,d]),se=i(e=>{if(!W||!G||!_.current)return;const t=e.clientX-G.x,n=e.clientY-G.y,i=156543.03392*Math.cos(I.lat*Math.PI/180)/Math.pow(2,F),s=-n*i/111320,r=t*i/(111320*Math.cos(I.lat*Math.PI/180));R({lat:I.lat+s,lng:I.lng+r}),J({x:e.clientX,y:e.clientY})},[W,G,I,F]),re=i(async e=>{if(!_.current)return;if(W&&G){const t=Math.abs(e.clientX-G.x),n=Math.abs(e.clientY-G.y);if(t>5||n>5)return U(!1),void J(null)}if(c||d)return U(!1),void J(null);const t=_.current.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,{lat:s,lng:r}=ne(n,i,I,F,t.width,t.height);await Z(s,r),U(!1),J(null)},[c,d,_,I,F,ne,Z,W,G]),ae=i(async t=>{if(t.trim()&&!c&&!d){z(!0),k("");try{const n=await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(t)}&limit=5&addressdetails=1`),i=await n.json();if(i&&i.length>0){const t=i[0],n=parseFloat(t.lat),s=parseFloat(t.lon),r=t.address||{},a={latitude:n,longitude:s,address:t.display_name,placeName:t.display_name,city:r.city||r.town||r.village||r.municipality||"",country:r.country||"",timestamp:Date.now()};if(C(a),V({lat:n,lng:s,isCurrentLocation:!1}),R({lat:n,lng:s}),A(!0),g){g({id:e,value:a,isValid:!0,errors:{}})}}else k("No locations found for your search.")}catch(e){k("Failed to search for location. Please try again.")}finally{z(!1)}}},[c,d,e,g]),oe=()=>{y&&y()},le=()=>{A(!0),v&&v()},ce=d||c||r?.validation?.readonly,de=r?.basic?.label||"Location",ue=r?.basic?.description||"";return B.jsxs("div",{className:`form-group ${j?"no-label":""} ${x}`,children:[!j&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[de,r?.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),ue&&B.jsx("div",{className:"form-group-description",children:ue}),B.jsxs("div",{className:"location-wrapper",children:[!(c&&N)&&B.jsxs("div",{className:"location-controls",children:[B.jsx("button",{type:"button",className:"location-btn "+(w?"loading":""),onClick:Q,disabled:ce||w,onFocus:oe,onBlur:le,tabIndex:ce?-1:0,children:w?B.jsxs(B.Fragment,{children:[B.jsx(u,{size:16,className:"loading-spinner"}),"Getting Location..."]}):B.jsxs(B.Fragment,{children:[B.jsx(m,{size:16}),"Get Current Location"]})}),B.jsxs("button",{type:"button",className:"location-btn secondary",onClick:te,disabled:ce,onFocus:oe,onBlur:le,tabIndex:ce?-1:0,children:[B.jsx(p,{size:16}),T?"Hide Map":"Choose on Map"]})]}),N&&B.jsxs("div",{className:"location-display",children:[!c&&B.jsx("button",{type:"button",className:"location-clear-btn",onClick:ee,disabled:ce,title:"Clear location",children:B.jsx(o,{size:16})}),N.placeName&&B.jsxs("div",{className:"location-place-name",children:[B.jsx("strong",{children:"Place:"})," ",N.placeName]}),(N.city||N.country)&&B.jsxs("div",{className:"location-address",children:[B.jsx("strong",{children:"Address:"})," ",[N.city,N.country].filter(Boolean).join(", ")]}),B.jsxs("div",{className:"location-coordinates",children:[B.jsx("strong",{children:"Coordinates:"})," ",(pe=N.latitude,he=N.longitude,void 0===pe||void 0===he||isNaN(pe)||isNaN(he)?"":`${Number(pe).toFixed(6)}, ${Number(he).toFixed(6)}`)]}),N.accuracy&&B.jsxs("div",{className:"location-accuracy",children:[B.jsx("strong",{children:"Accuracy:"})," ",(me=N.accuracy,me?`±${Math.round(me)}m`:"")]}),N.timestamp&&B.jsxs("div",{className:"location-timestamp",children:[B.jsx("strong",{children:"Captured:"})," ",new Date(N.timestamp).toLocaleString()]})]}),T&&!c&&B.jsxs("div",{className:"location-map-container",children:[B.jsxs("div",{className:"location-map-header",children:[B.jsx("h4",{children:"Select Location on Map"}),B.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),B.jsx("div",{className:"location-search",children:B.jsx("form",{onSubmit:e=>{e.preventDefault(),q.trim()&&ae(q)},className:"search-form",children:B.jsxs("div",{className:"search-input-group",children:[B.jsx("input",{type:"text",value:q,onChange:e=>{P(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:ce||M}),B.jsx("button",{type:"submit",className:"search-btn",disabled:ce||M||!q.trim(),children:M?B.jsx(u,{size:16,className:"loading-spinner"}):"Search"})]})})}),B.jsxs("div",{ref:_,className:"location-map "+(W?"dragging":""),onMouseDown:ie,onMouseMove:se,onMouseUp:re,onMouseLeave:()=>{U(!1),J(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:W?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${F}/${Math.floor((I.lng+180)/360*Math.pow(2,F))}/${Math.floor((1-Math.log(Math.tan(I.lat*Math.PI/180)+1/Math.cos(I.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,F))}.png) center/cover no-repeat`,userSelect:"none"},children:[D&&B.jsx("div",{className:"map-marker "+(D.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:B.jsx(p,{size:24})}),B.jsx("div",{className:"map-center-indicator",style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"4px",backgroundColor:"var(--df-color-primary)",borderRadius:"50%",zIndex:5}}),B.jsxs("div",{className:"map-controls",children:[B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.min(18,e+1)),disabled:F>=18,children:"+"}),B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.max(1,e-1)),disabled:F<=1,children:"−"})]})]}),B.jsxs("div",{className:"location-map-instructions",children:[B.jsx("p",{children:B.jsx("strong",{children:"Instructions:"})}),B.jsxs("ul",{children:[B.jsx("li",{children:"Search for a place using the search box above"}),B.jsx("li",{children:"Click anywhere on the map to select a location"}),B.jsx("li",{children:"Drag the map to pan around"}),B.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),B.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),Y&&B.jsxs("div",{className:"location-loading",children:[B.jsx(u,{size:16,className:"loading-spinner"}),B.jsx("span",{children:"Loading address details..."})]})]}),$&&B.jsx("div",{className:"location-error",children:$})]}),B.jsx(H,{validationErrors:a,fieldId:e,touchedFields:h,formSubmitted:f,properties:r,localValidation:{isValid:!0,errors:{}},isTouched:E,mode:b})]});var me,pe,he},le=({id:e,properties:t,className:n="",hideLabel:i=!1})=>{const s=t.styles?.level??t.basic.level??1,r=t.basic.label,a=()=>{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${s} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${n}`.trim(),style:a()};switch(s){case 1:default:return B.jsx("h1",{...i,children:r});case 2:return B.jsx("h2",{...i,children:r});case 3:return B.jsx("h3",{...i,children:r});case 4:return B.jsx("h4",{...i,children:r});case 5:return B.jsx("h5",{...i,children:r});case 6:return B.jsx("h6",{...i,children:r})}})()},ce=({id:e,properties:r,mode:a="preview",formValue:o,onValueChange:l,className:c="",hideLabel:d=!1})=>{const[u,m]=t(""),[p,y]=t(r.validation?.listStyle||"numbers"),[x,j]=t("#000000"),N=s(null),C=s(null),w=s(!1),S="edit"===a,$=s({instructions:[],listStyle:"numbers",formValue:void 0}),k=s(a);n(()=>{let e=[],t="numbers";if(null!=o&&("object"==typeof o&&o.instructions?(Array.isArray(o.instructions)?e=o.instructions:"string"==typeof o.instructions&&(e=[o.instructions]),o.listStyle&&(t=o.listStyle)):Array.isArray(o)?e=o:"string"==typeof o&&(e=[o])),0===e.length&&r.basic?.value){const n=r.basic.value;n&&"object"==typeof n&&!Array.isArray(n)&&n.instructions?(Array.isArray(n.instructions)?e=n.instructions:"string"==typeof n.instructions&&(e=[n.instructions]),n.listStyle&&"string"==typeof n.listStyle&&(t=n.listStyle)):Array.isArray(n)?e=n:"string"==typeof n&&(e=[n])}0===e.length&&r.basic?.instructions&&(Array.isArray(r.basic.instructions)?e=r.basic.instructions:"string"==typeof r.basic.instructions&&(e=[r.basic.instructions])),t&&"numbers"!==t||(t=r.validation?.listStyle||r.basic?.value?.listStyle||"numbers");const n=JSON.stringify(e)!==JSON.stringify($.current.instructions)||t!==$.current.listStyle,i=a!==k.current,s=JSON.stringify(o)!==JSON.stringify($.current.formValue),l=!$.current.formValue||Array.isArray($.current.formValue)&&0===$.current.formValue.length||"string"==typeof $.current.formValue&&""===$.current.formValue.trim(),c=null!=o&&(Array.isArray(o)&&o.length>0||"string"==typeof o&&""!==o.trim()||"object"==typeof o&&Object.keys(o).length>0);if(n||i||s||l&&c){const s=e=>"string"!=typeof e?e:e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))),r=e.map(e=>"string"==typeof e?s(e):e),l=r.some(e=>"string"==typeof e&&/<[^>]+>/.test(e));let c="";if(r.length>0)if(l)c=r.join("");else{const e="numbers"===t?"ol":"bullets"===t?"ul":"div",n=r.filter(e=>e&&"string"==typeof e).map(e=>`<li>${e.replace(/\n/g,"<br>")}</li>`).join("");c="div"===e?r.filter(e=>e&&"string"==typeof e).map(e=>`<div>${e.replace(/\n/g,"<br>")}</div>`).join(""):`<${e}>${n}</${e}>`}y(t),m(c),S&&N.current&&(i||n&&N.current.innerHTML.trim()!==c.trim())&&(N.current.innerHTML=c),$.current={instructions:e,listStyle:t,formValue:o},k.current=a}},[o,r.basic?.instructions,r.validation?.listStyle,a,S]),n(()=>{if(S&&N.current){const e=N.current.innerHTML.trim();u.trim()===e||w.current||(N.current.innerHTML=u)}if(w.current){const e=setTimeout(()=>{w.current=!1},200);return()=>clearTimeout(e)}},[u,S]);const E=i(()=>{if(!N.current)return;w.current=!0;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}t!==u&&m(t)},[e,p,l,u]),A=i(()=>{if(!N.current)return;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}m(t),w.current=!1},[e,p,l]),T=i((e,t)=>{document.execCommand(e,!1,t),N.current?.focus(),E()},[E]),L=i(()=>{T("bold")},[T]),I=i(()=>{T("italic")},[T]),R=i(e=>{const t=e.target.value;j(t),T("foreColor",t)},[T]),D=i(t=>{if(y(t),!N.current)return;const n=window.getSelection(),i=n&&n.rangeCount>0?n.getRangeAt(0):null;let s=N.current.innerHTML;if("numbers"===t){if(s=s.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!s.includes("<ol>")&&!s.includes("<ul>")){const e=s.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(s="<ol>"+e.map(e=>`<li>${e}</li>`).join("")+"</ol>")}}else if("bullets"===t){if(s=s.replace(/<ol>/gi,"<ul>").replace(/<\/ol>/gi,"</ul>"),!s.includes("<ol>")&&!s.includes("<ul>")){const e=s.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(s="<ul>"+e.map(e=>`<li>${e}</li>`).join("")+"</ul>")}}else s=s.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(N.current.innerHTML=s,m(s),i&&n)try{n.removeAllRanges(),n.addRange(i)}catch(e){}if(E(),l){l({id:e,value:{instructions:s?[s]:[],listStyle:t},isValid:!0,errors:{}})}},[e,E,l]),V=i(e=>{const t=e.target.files?.[0];if(!t||!t.type.startsWith("image/"))return;const n=new FileReader;n.onload=e=>{const t=e.target?.result;if(t&&N.current){const e=document.createElement("img");e.src=t,e.style.maxWidth="100%",e.style.height="auto";const n=window.getSelection();if(n&&n.rangeCount>0){const t=n.getRangeAt(0);t.deleteContents(),t.insertNode(e)}else N.current.appendChild(e);E()}},n.readAsDataURL(t),C.current&&(C.current.value="")},[E]),F=i(e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain"),n=window.getSelection();if(n&&n.rangeCount>0){const e=n.getRangeAt(0);e.deleteContents();const i=document.createTextNode(t);e.insertNode(i),e.setStartAfter(i),e.collapse(!0),n.removeAllRanges(),n.addRange(e)}E()},[E]),O=i(e=>document.queryCommandState(e),[]);return B.jsxs("div",{className:`form-group instruction-group ${c}`,children:[!d&&B.jsx("label",{htmlFor:e,className:"instruction-label",children:"Instructions"}),S?B.jsxs("div",{className:"instruction-rich-editor",children:[B.jsxs("div",{className:"instruction-toolbar",children:[B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+(O("bold")?"active":""),onClick:L,title:"Bold","aria-label":"Bold",children:B.jsx(h,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+(O("italic")?"active":""),onClick:I,title:"Italic","aria-label":"Italic",children:B.jsx(f,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsx("div",{className:"toolbar-group",children:B.jsxs("div",{className:"color-picker-wrapper",children:[B.jsx("input",{type:"color",value:x,onChange:R,className:"color-picker-input",title:"Text Color"}),B.jsx("label",{className:"color-picker-label",title:"Text Color",children:B.jsx("span",{style:{color:x},children:"A"})})]})}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===p?"active":""),onClick:()=>D("bullets"),title:"Bullet List","aria-label":"Bullet List",children:B.jsx(b,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===p?"active":""),onClick:()=>D("numbers"),title:"Numbered List","aria-label":"Numbered List",children:B.jsx(g,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>C.current?.click(),title:"Insert Image","aria-label":"Insert Image",children:B.jsx(v,{size:16})}),B.jsx("input",{ref:C,type:"file",accept:"image/*",onChange:V,style:{display:"none"}})]})]}),B.jsx("div",{ref:N,contentEditable:!0,className:"instruction-editor-content",onInput:E,onBlur:A,onPaste:F,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):B.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===p?"instruction-list-numbers":"bullets"===p?"instruction-list-bullets":""),children:u?B.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:u}}):B.jsx("div",{className:"instruction-empty",children:B.jsx("p",{children:"No instructions provided"})})})]})},de=({attachments:e,onRemove:i})=>{const[s,r]=t(new Map);return n(()=>{if(!e)return void r(e=>(e.forEach(e=>URL.revokeObjectURL(e)),new Map));const t=new Map;return e.forEach((e,n)=>{if(e.type.startsWith("image/")){const i=URL.createObjectURL(e);t.set(n,i)}}),r(e=>(e.forEach((e,n)=>{t.has(n)||URL.revokeObjectURL(e)}),t)),()=>{t.forEach(e=>URL.revokeObjectURL(e))}},[e]),e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type.startsWith("image/"),r=s.get(t);return B.jsx("div",{className:"attachment-thumbnail",children:n&&r?B.jsxs(B.Fragment,{children:[B.jsx("img",{src:r,alt:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(o,{size:14})})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"file-icon-placeholder",children:B.jsx(y,{size:20})}),B.jsx("span",{className:"file-name",children:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(o,{size:14})})]})},t)})}):null},ue=({component:e,mode:r,formTemplateId:a,formValue:o,onNotesChange:l,onAttachmentChange:c,notes:u="",attachments:m=null,onThresholdActionCompletion:p,onThresholdIssueRaised:h,onBasicPropertyActionCompletion:f})=>{const[b,g]=t(u||""),[v,S]=t(m||null),[$,k]=t(!1),[E,A]=t(!1),[T,L]=t(!1),[I,R]=t(!1),[D,V]=t(!1),F=s(null),O=s(o),q=s(!1),P=s(!1);n(()=>{if(!q.current&&null!=u){const e="string"==typeof u?u:String(u||"");g(e),q.current=!0}},[u]),n(()=>{P.current||void 0===m||(S(m),P.current=!0)},[m]),n(()=>{if(q.current&&!$&&null!=u){const e="string"==typeof u?u:String(u||"");b&&""!==String(b||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==b&&g(e):g(e)}},[u,$,b]),n(()=>{P.current&&void 0!==m&&(!v||m&&m.length>0&&m!==v)&&S(m)},[m,v]),n(()=>{const t=["select","radio","checkbox","segment"].includes(e.name||"");if(t){const t=O.current,n=o;let i=!1;if("checkbox"===e.name){const e=Array.isArray(t)?t:t?[t]:[],s=Array.isArray(n)?n:n?[n]:[];i=JSON.stringify(e.sort())!==JSON.stringify(s.sort())}else i=t!==n&&void 0!==t;if(i){L(!1),R(!1),A(!1),k(!1),V(!1);const e="string"==typeof u?u:String(u||"");e&&""!==e.trim()?g(e):g(""),m&&0!==m.length?S(m):S(null)}O.current=n}t||(O.current=o)},[o,e.name,u,m]);const M=i((e,t)=>{const{operator:n,value:i}=e,s=String(t).toLowerCase(),r=String(i).toLowerCase();switch(n){case"equals":return s===r||String(t)===String(i);case"notEquals":return s!==r&&String(t)!==String(i);case"greaterThan":return Number(t)>Number(i);case"lessThan":return Number(t)<Number(i);case"greaterThanOrEqual":return Number(t)>=Number(i);case"lessThanOrEqual":return Number(t)<=Number(i);default:return!1}},[]),z=i(()=>{if(!(null!=o&&""!==o&&!(Array.isArray(o)&&0===o.length)))return[];const t=e.condition;if(!t||!t.conditions||0===t.conditions.length)return[];const n=[];if("checkbox"===e.name&&Array.isArray(o))o.forEach(e=>{const i=t.conditions.find(t=>M(t,e));i&&!n.find(e=>e.id===i.id)&&n.push(i)});else{const e=t.conditions.find(e=>M(e,o));e&&n.push(e)}return n},[e,o,M]),_=i(t=>{const n=t.target.value;g(n),l&&l(n);const i=z(),s=String(n||"").trim().length>0;i.forEach(e=>{!0===e.enableNotes&&p&&p(e.id,"notes",s)});const r=e.condition;!(r&&r.conditions&&r.conditions.length>0)&&f&&f("notes",s)},[l,z,p,e,f]),W=i(()=>{if(l){const e="string"==typeof b?b:String(b||"");l(e),setTimeout(()=>{k(!1)},0)}else k(!1)},[b,l]),U=i(()=>{W()},[W]),G=i(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),W())},[W]),J=i(()=>{k(!0)},[]),H=i(()=>{k(!0)},[]),Y=i(()=>{F.current?.click()},[]),X=i(t=>{const n=t.target.files;if(n&&n.length>0){const t=Array.from(n);S(t),c&&c(t);z().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!0)});const i=e.condition;!(i&&i.conditions&&i.conditions.length>0)&&f&&f("attachments",!0)}F.current&&(F.current.value="")},[c,z,p,e,f]),Z=i(t=>{if(v){const n=v.filter((e,n)=>n!==t);if(0===n.length){S(null),c&&c(null);z().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!1)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("attachments",!1)}else S(n),c&&c(n)}},[v,c,z,p,e,f]),Q=i(()=>{L(!0);z().forEach(e=>{!0===e.enableSendEmail&&p&&p(e.id,"email",!0)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("email",!0),setTimeout(()=>{L(!1)},3e3)},[z,p,e,f]),ee=i(()=>{A(!0)},[]),te=i(()=>{A(!1)},[]),ne=i(()=>{A(!1),R(!0);const t=e.condition;if(t&&t.conditions&&t.conditions.length>0){z().forEach(e=>{!0===e.enableRaiseIssue&&h&&h(e.id)})}else f&&f("issue",!0)},[e,f,z,h]);if("test"!==r)return null;const ie=["select","radio","checkbox","segment"].includes(e.name||""),se=e.basic?.options||e.options||[];let re=!1,ae=!1,oe=!1,le=!1,ce=null;const ue=null!=o&&""!==o&&!(Array.isArray(o)&&0===o.length),me=e.condition,pe=me&&me.conditions&&me.conditions.length>0;if(pe&&ue)if("checkbox"===e.name&&Array.isArray(o)){const e=o;for(const t of e){const e=me.conditions.find(e=>M(e,t));e&&(re=re||!0===e.enableNotes,ae=ae||!0===e.enableAttachment,oe=oe||!0===e.enableRaiseIssue,le=le||!0===e.enableSendEmail)}}else if(ie){const e=me.conditions.find(e=>M(e,o));e&&(re=!0===e.enableNotes,ae=!0===e.enableAttachment,oe=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}else{const e=me.conditions.find(e=>M(e,o));e&&(re=!0===e.enableNotes,ae=!0===e.enableAttachment,oe=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}if(!pe){const t=e.basic,n=!0===t?.enableNotes,i=!0===t?.enableAttachment,s=!0===t?.enableRaiseIssue,r=!0===t?.enableSendEmail;if(ie)if(ue)if("checkbox"===e.name){(Array.isArray(o)?o:[o]).forEach(e=>{const t=se.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(re=re||!0===t.enableNotes,ae=ae||!0===t.enableAttachment,oe=oe||!0===t.enableRaiseIssue,le=le||!0===t.enableSendEmail,ce||(ce=t))}),re=re||n,ae=ae||i,oe=oe||s,le=le||r}else if(ce=se.find(e=>!(!e||!e.value)&&(e.value===o||(String(e.value)===String(o)||(e.label===o||String(e.label)===String(o))))),ce){const e=!0===ce.enableNotes,t=!0===ce.enableAttachment,a=!0===ce.enableRaiseIssue,o=!0===ce.enableSendEmail;re=e||n,ae=t||i,oe=a||s,le=o||r}else re=n,ae=i,oe=s,le=r;else re=n,ae=i,oe=s,le=r;else re=n,ae=i,oe=s,le=r}if(!(re||ae||oe||le))return null;const he=z(),fe=e.condition,be=fe&&fe.conditions&&fe.conditions.length>0,ge=!!be&&he.some(e=>!0===e.enableNotes),ve=!!be&&he.some(e=>!0===e.enableAttachment),ye=!!be&&he.some(e=>!0===e.enableSendEmail),xe=!!be&&he.some(e=>!0===e.enableRaiseIssue),je=String(b||"").trim().length>0,Ne=v&&v.length>0,Ce=v?v.length:0;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"component-action-features",children:[B.jsxs("div",{className:"action-icons-toolbar",children:[re&&B.jsxs("button",{type:"button",className:`action-icon-button ${je?"active":""} ${ge?"mandatory":""}`,onClick:J,title:"Add Notes",children:[B.jsx(d,{size:14,fill:je?"currentColor":"none"}),ge&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ae&&B.jsxs("button",{type:"button",className:`action-icon-button ${Ne?"active":""} ${ve?"mandatory":""}`,onClick:Y,title:"Add Attachment",children:[B.jsx(y,{size:14,fill:Ne?"currentColor":"none"}),Ce>0&&B.jsx("span",{className:"attachment-count-badge",children:Ce}),ve&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),le&&B.jsxs("button",{type:"button",className:`action-icon-button ${T?"active sent":""} ${ye?"mandatory":""}`,onClick:Q,disabled:T,title:"Send Email",children:[T?B.jsx(B.Fragment,{children:B.jsx(x,{size:14})}):B.jsx(j,{size:14,fill:T?"currentColor":"none"}),ye&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),oe&&B.jsxs("button",{type:"button",className:`action-icon-button ${I?"active":""} ${xe?"mandatory":""}`,onClick:ee,title:"Raise an Issue",children:[B.jsx(N,{size:14,fill:I?"currentColor":"none"}),xe&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(je&&re||Ne&&ae)&&B.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>V(!D),title:D?"Collapse":"Expand",children:D?B.jsx(C,{size:14}):B.jsx(w,{size:14})})]}),$&&re&&B.jsxs("div",{className:"notes-input-overlay",children:[B.jsx("textarea",{className:"action-notes-textarea",value:b,onChange:_,onBlur:U,onKeyDown:G,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),B.jsxs("div",{className:"notes-input-actions",children:[B.jsx("button",{type:"button",className:"notes-save-button",onClick:W,title:"Save notes (Ctrl+Enter)",children:"Save"}),B.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{k(!1)},title:"Cancel",children:"Cancel"})]})]}),D&&B.jsxs("div",{className:"actions-content",children:[!$&&je&&re&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",onClick:H,children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",b]})}),Ne&&ae&&B.jsx("div",{className:"attachments-section",children:B.jsx(de,{attachments:v,onRemove:Z})})]}),ae&&B.jsx("input",{ref:F,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:X,style:{display:"none"}})]}),E&&B.jsx(K,{isOpen:E,onClose:te,onSuccess:ne,component:ce?{...e,basic:{...e.basic,label:`${e.basic?.label||"Component"} - ${ce.label||ce.value}`,value:ce.value||e.basic?.value||""}}:e,formTemplateId:a||"",notes:b,attachments:v})]})},me=({attachments:e})=>e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type?.startsWith("image/")||!1,i=n?(e=>e.data?e.data.startsWith("data:")?e.data:`data:${e.type||"image/png"};base64,${e.data}`:"")(e):"";return B.jsx("div",{className:"attachment-thumbnail",children:n&&i?B.jsx("img",{src:i,alt:e.name||`Attachment ${t+1}`}):B.jsxs("div",{className:"file-icon-placeholder",children:[B.jsx(y,{size:20}),B.jsx("span",{className:"file-name",children:e.name||`File ${t+1}`})]})},t)})}):null,pe=({component:e})=>{const t=e.basic?.notes||"",n=e.basic?.attachments||[],i=t&&t.trim().length>0,s=n&&n.length>0;return i||s?B.jsx("div",{className:"component-submission-actions",children:B.jsxs("div",{className:"actions-content",children:[i&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",t]})}),s&&B.jsx("div",{className:"attachments-section",children:B.jsx(me,{attachments:n})})]})}):null},he=({child:e,selectedChild:t,mode:n,onChildSelect:i,onChildDelete:s,renderFormComponent:r,isOverlay:a=!1,isChildrenEditMode:o=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:b,listeners:g,setNodeRef:v,transform:y,transition:x,isDragging:j,isSorting:N}=V({id:e.id,disabled:a||"edit"!==n}),C={transform:O.Transform.toString(y),transition:x,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:v,style:C,className:`form-component section-child ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""} ${o?"children-edit-active":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:[("edit"===n||o)&&B.jsx("div",{className:"child-drag-handle",...g,...b,onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:B.jsx($,{size:14})}),B.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===n||o)&&B.jsxs("div",{className:"component-actions child-actions",children:[B.jsx("button",{className:"btn edit-btn",onClick:t=>{t.stopPropagation(),i(e)},onMouseDown:e=>e.stopPropagation(),title:"Edit properties",children:B.jsx(k,{size:12})}),B.jsx("button",{className:"btn delete-btn",onClick:t=>s(e,t),onMouseDown:e=>e.stopPropagation(),title:"Delete component",children:B.jsx(E,{size:12})})]}),B.jsxs("div",{className:"component-preview child-preview",children:[r(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]})]})]})},fe=({id:e,properties:s,mode:r="edit",formData:a={},onValueChange:o,onSelect:l,isSelected:c=!1,className:d="",onSectionSelect:u,onChildSelect:m,onChildDelete:p,selectedChild:h,renderFormComponent:f,formTemplateId:b,onThresholdActionCompletion:g,onThresholdIssueRaised:v,onNotesChange:y,onAttachmentChange:x})=>{const[j,N]=t(s.basic.collapsed),[C,$]=t(!1),[k,E]=t(!1),[A,T]=t(s.basic.label),[L,V]=t(s.basic.description),[F,O]=t(s.children||[]),[q,P]=t(!1);n(()=>{O(s.children||[])},[s.children]),n(()=>{T(s.basic.label),V(s.basic.description)},[s.basic.label,s.basic.description]);const{setNodeRef:M,isOver:z}=I({id:`section-${e}`,disabled:"edit"!==r}),_=!("preview"!==r&&"test"!==r||s.children&&s.children.length>0),W=i(t=>{T(t),o?.({id:e,value:{...s,basic:{...s.basic,label:t}}})},[e,s,o]),U=i(t=>{V(t),o?.({id:e,value:{...s,basic:{...s.basic,description:t}}})},[e,s,o]),G=i(e=>{m?.(e)},[m]),J=i((e,t)=>{t.stopPropagation();const n=F.filter(t=>t.id!==e.id);O(n),p?.(e.id)},[p,F,e]),H=i(()=>{u?.(s),l?.()},[u,l,s]),Y=i(e=>{e.stopPropagation(),"edit"===r&&F.length>0&&P(!q)},[r,F.length,q]),K=i(t=>{t.stopPropagation(),N(!j),o?.({id:e,value:{...s,basic:{...s.basic,collapsed:!j}}})},[j,e,s,o]),X=f||i(e=>{const t=a[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let n=t;"number-input"===e.name&&"number"==typeof t?n=String(t):"number-input"===e.name&&null==t&&(n="");const i={id:e.id,properties:e,validationErrors:{},formValue:n,touchedFields:{},formSubmitted:!1,mode:r,onValueChange:o,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...i,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...i,properties:e,readonly:!1,disabled:!1});case"select":const t={...e,options:e.basic?.options||[]};return B.jsx(ee,{...i,properties:t,disabled:!1});case"checkbox":const n={...e,options:e.basic?.options||[]};return B.jsx(te,{...i,properties:n,formValue:[],disabled:!1});case"radio":const s={...e,options:e.basic?.options||[]};return B.jsx(ne,{...i,properties:s,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...i,properties:e,readonly:!1,disabled:!1});case"signature":return B.jsx(re,{...i,properties:e});case"heading":return B.jsx(le,{...i,properties:e});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}},[r,o,a]);if(_)return null;const ie={backgroundColor:s.styles?.backgroundColor||"var(--df-color-fb-container)",borderColor:s.styles?.borderColor||"var(--df-color-fb-border)",borderWidth:s.styles?.borderWidth||"2px",borderRadius:s.styles?.borderRadius||"8px",padding:s.styles?.padding||"16px",margin:s.styles?.margin||"16px 0"};return B.jsxs("div",{ref:M,className:`df-form-section ${c?"selected":""} ${z?"drag-over":""} ${d}`,style:ie,children:[B.jsxs("div",{className:"section-header "+(q?"children-edit-mode":""),onClick:H,onDoubleClick:Y,children:[B.jsx("div",{className:"section-header-content",children:B.jsxs("div",{className:"section-title",children:[B.jsx("span",{className:"section-toggle",title:j?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),K(e)},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),K(e))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:j?B.jsx(S,{size:18}):B.jsx(w,{size:18})}),"edit"===r&&C?B.jsx("input",{type:"text",value:A,onChange:e=>T(e.target.value),onBlur:()=>{$(!1),W(A)},onKeyDown:e=>{"Enter"===e.key&&($(!1),W(A))},className:"section-title-input",autoFocus:!0}):B.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===r&&$(!0),style:{display:"inline",margin:0},children:A||"Untitled Section"})]})}),(L||"edit"===r)&&B.jsx("div",{className:"section-description",children:"edit"===r&&k?B.jsx("textarea",{value:L,onChange:e=>V(e.target.value),onBlur:()=>{E(!1),U(L)},onKeyDown:e=>{"Enter"===e.key&&e.ctrlKey&&(E(!1),U(L))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):B.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===r&&E(!0),children:L||"Section description"})})]}),!j&&B.jsx("div",{className:`section-content ${z?"drag-over":""} ${0===F.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&H()},children:B.jsx(R,{items:F.map(e=>e.id),strategy:D,children:0===F.length?B.jsxs("div",{className:"section-empty-state",onClick:H,style:{textAlign:"center",color:"#6b7280",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",cursor:"pointer",border:"2px dotted #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",transition:"all 0.3s ease",margin:"16px 0"},children:[B.jsx("div",{style:{fontWeight:"500",color:z?"#3b82f6":"#374151"},children:z?"Drop components here":"Empty Section"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):F.map(e=>B.jsx(he,{child:e,selectedChild:h||null,mode:r,onChildSelect:G,onChildDelete:J,renderFormComponent:X,isChildrenEditMode:q,formData:a,formTemplateId:b,onNotesChange:y,onAttachmentChange:x,onThresholdActionCompletion:g,onThresholdIssueRaised:v},e.id))})})]})},be=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:s,onComponentEdit:r,renderFormComponent:a,isOverlay:o=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:b,listeners:g,setNodeRef:v,transform:y,transition:x,isDragging:j,isSorting:N}=V({id:e.id,disabled:o}),C={transform:O.Transform.toString(y),transition:x,opacity:j?.3:1,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:v,style:{...C,border:t?.id===e.id?"2px solid #3b82f6":"1px solid var(--df-color-fb-border)",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",padding:"12px",position:"relative",minHeight:"80px",transition:"all 0.2s ease",boxShadow:t?.id===e.id?"0 4px 12px rgba(59, 130, 246, 0.15)":"0 1px 3px rgba(0, 0, 0, 0.1)",cursor:"pointer"},className:`form-component grid-component ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...g,...b,onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"50%",left:"4px",transform:"translateY(-50%)",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"4px",cursor:"grab",opacity:1,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:B.jsx($,{size:12,color:"var(--df-color-text-light)"})}),B.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===n?"24px":"0",paddingLeft:"edit"===n?"28px":"0",minHeight:"60px"},children:[a(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[r&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),r(e)},type:"button",title:"Edit Component",style:{padding:"4px",backgroundColor:"#3b82f6",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#3b82f6"},children:B.jsx(k,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),s(e,t)},type:"button",title:"Delete Component",style:{padding:"4px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#ef4444"},children:B.jsx(E,{size:12})})]})]})},ge=({gridComponents:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:r,selectedComponent:a,renderFormComponent:o,gridId:l,formData:c={},formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})=>{const{setNodeRef:f,isOver:b}=I({id:`grid-drop-zone-${l}`,disabled:"edit"!==t});return B.jsx("div",{ref:f,className:"grid-drop-zone",style:{border:b?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:b?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?B.jsxs(B.Fragment,{children:[B.jsx(R,{items:e.map(e=>e.id),strategy:F,children:B.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:e.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:e.map(e=>B.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:B.jsx(be,{component:e,selectedComponent:a,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:r,renderFormComponent:o,formData:c,formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})},e.id))})}),B.jsx("div",{style:{border:b?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:b?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:b?B.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):B.jsx("span",{children:"+ Drop more components here"})})]}):B.jsxs("div",{style:{textAlign:"center",color:"var(--df-color-text-light)",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed var(--df-color-fb-border)",borderRadius:"8px"},children:[B.jsx("div",{style:{fontWeight:"500",color:b?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:b?"Drop components here":"Empty DataGrid"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},ve=({templateComponents:e,dataEntries:t,renderFormComponent:n,renderComponent:i,mode:s="preview",allowAddRemoveEntries:r=!0,addAnotherText:a="Add Another",removeText:o="Remove",maxEntries:l=10,minEntries:c=1,displayAsGrid:d=!0,onAddEntry:u,onRemoveEntry:m,formData:p={},formTemplateId:h,onThresholdActionCompletion:f,onThresholdIssueRaised:b,onNotesChange:g,onAttachmentChange:v,datagridId:y=""})=>0===e.length?B.jsxs("div",{style:{textAlign:"center",padding:"40px",color:"var(--df-color-text-light)",border:"1px dashed #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)"},children:["No components defined. Add components to see the ",d?"table":"list"," view."]}):d?B.jsxs("div",{className:"datagrid-table-view",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",backgroundColor:"var(--df-color-fb-container)",maxWidth:"100%"},children:[B.jsx("div",{style:{position:"absolute",top:"8px",right:"8px",zIndex:10,fontSize:"12px",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",padding:"4px 8px",borderRadius:"4px",border:"1px solid var(--df-color-fb-border)",opacity:e.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),B.jsxs("div",{className:"table-scroll-container",style:{overflowX:"auto",overflowY:"hidden",maxWidth:"100%",scrollbarWidth:"thin",scrollbarColor:"var(--df-color-fb-border) var(--df-color-fb-icon-bg)",position:"relative"},children:[B.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*e.length+"px"},children:e.map((t,n)=>B.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:n<e.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.basic?.label||`Column ${n+1}`},`header-${t.id}`))}),t.length>0?t.map((s,a)=>B.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:a<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:a%2==0?"var(--df-color-fb-container)":"var(--df-color-fb-bg)",position:"relative",minWidth:150*e.length+"px",isolation:"isolate"},children:[e.map((t,r)=>{let o=s.components?.[r];const l=`${t.id||`component-${r}`}-entry-${y}-${a}-${r}`;return o=o?o.id!==l?{...o,id:l,basic:{...o.basic,showLabel:!1}}:{...o,id:o.id,basic:{...o.basic,showLabel:!1}}:{...t,id:l,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsx("div",{style:{padding:"12px 16px",borderRight:r<e.length-1?"1px solid var(--df-color-fb-border)":"none",minHeight:"60px",minWidth:"150px",display:"flex",alignItems:"center",overflow:"visible",position:"relative",zIndex:1},children:B.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:i?i(o,!0):n(o,!0)})},`${s.id}-${r}`)}),r&&t.length>c&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(a)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",zIndex:1e3,minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto"},title:o,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},s.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",borderTop:"1px solid var(--df-color-fb-border)"},children:["No data entries. ",r?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]})]}),r&&B.jsx("div",{style:{padding:"16px",backgroundColor:"var(--df-color-fb-bg)",borderTop:"1px solid var(--df-color-fb-border)",display:"flex",justifyContent:"center",position:"sticky",bottom:0,zIndex:5},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{style:{fontSize:"16px"},children:"+"}),a]})})]}):B.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[t.length>0?t.map((a,l)=>B.jsxs("div",{className:"list-entry",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",padding:"16px",backgroundColor:"var(--df-color-fb-container)",position:"relative",transition:"all 0.2s ease"},children:[B.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[B.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",l+1]}),r&&t.length>1&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(l)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},title:o,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),B.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:e.map((e,t)=>{let r=a.components?.[t];const o=`${e.id||`component-${t}`}-entry-${y}-${l}-${t}`;return r||(r=a.components?.find(t=>t.name===e.name&&t.basic?.label===e.basic?.label)),r=r?r.id!==o?{...r,id:o,basic:{...r.basic,showLabel:!1}}:{...r,id:r.id,basic:{...r.basic,showLabel:!1}}:{...e,id:o,basic:{...e.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[B.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:e.basic?.label||`Field ${t+1}`}),B.jsxs("div",{style:{minHeight:"40px",display:"flex",alignItems:"center",flexDirection:"column",width:"100%"},children:[i?i(r):n(r),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(r.name)&&B.jsx(ue,{component:r,mode:"test",formTemplateId:h,formValue:p[r.id],onThresholdActionCompletion:f,onThresholdIssueRaised:b,onNotesChange:g?e=>g(r.id,e):void 0,onAttachmentChange:v?e=>v(r.id,e):void 0}),"preview"===s&&(r.basic?.notes&&r.basic.notes.trim().length>0||r.basic?.attachments&&Array.isArray(r.basic.attachments)&&r.basic.attachments.length>0?B.jsx(pe,{component:r}):null)]})]},`${a.id}-${t}`)})})]},a.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed #d1d5db",borderRadius:"8px"},children:["No data entries. ",r?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]}),"test"===s&&r&&B.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{children:"+"}),a]})})]}),ye=({id:e,properties:r,mode:a="edit",formData:o={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onDataGridSelect:f,onComponentSelect:b,onComponentDelete:g,onComponentEdit:v,onComponentUpdate:y,selectedComponent:x,renderFormComponent:j,onEntryAdd:N,onEntryRemove:C,formTemplateId:$,onThresholdActionCompletion:k,onThresholdIssueRaised:E,onNotesChange:T,onAttachmentChange:L})=>{const[I,R]=t(!1),D=s(!1);let V=r.templateComponents||[];const F=r.entries||[];0===V.length&&F.length>0&&F[0].components&&(V=F[0].components.map(e=>({...e,id:e.id?.replace(/-entry-\d+$/,"")||e.id,basic:{...e.basic,showLabel:!0}}))),n(()=>{if("edit"===a&&!r.templateComponents&&u&&D.current){const t={...r,templateComponents:[]};JSON.stringify(t)!==JSON.stringify(r)&&u({id:e,value:t})}D.current=!0},[r.templateComponents,e,u,r,a]),n(()=>{if(V.length>0){if("test"===a&&0===F.length&&D.current){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...r,entries:[t]};JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n})}return}if("edit"!==a||!D.current)return;if(F.some(e=>e.components?.some((t,n)=>{const i=`${V[n]?.id}-entry-${e.index}-${n}`;return t.id!==i}))&&u){const t=F.map(e=>({...e,components:e.components?.map((t,n)=>({...t,id:`${V[n]?.id}-entry-${e.index}-${n}`}))||[]})),n={...r,entries:t};return void(JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n}))}if(0===F.length&&"edit"===a){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...r,entries:[t]};JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n})}}else if(F.length>0){if(F.some(e=>V.some((t,n)=>{const i=e.components?.[n];if(!i)return!0;const s=`${t.id}-entry-${e.index}-${n}`,r=i.id===s,a=JSON.stringify(i.basic?.options)!==JSON.stringify(t.basic?.options)||i.basic?.placeholder!==t.basic?.placeholder||i.basic?.defaultValue!==t.basic?.defaultValue||i.basic?.label!==t.basic?.label||i.validation?.required!==t.validation?.required;return!r||a}))&&u){const t=F.map(t=>{const n=V.map((n,i)=>{let s=t.components?.[i];s||(s=t.components?.find(e=>e.name===n.name&&e.basic?.label===n.basic?.label));const r=`${n.id||`component-${i}`}-entry-${e}-${t.index}-${i}`;if(s){return{...n,id:r,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}return{...n,id:r,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}});return{...t,components:n}}),n={...r,entries:t};JSON.stringify(n)!==JSON.stringify(r)&&u({id:e,value:n})}}}},[V,F,e,u,r,a,r.templateComponents]);const O=i(e=>{e.stopPropagation(),m?.(),f?.(r)},[m,f,r]),q=i((t,n)=>{n.stopPropagation(),g&&g(t,n);const i=V.filter(e=>e.id!==t.id),s=F.map(e=>({...e,components:e.components?.filter(e=>!(e.name===t.name&&e.basic?.label===t.basic?.label))||[]}));u&&u({id:e,value:{...r,templateComponents:i,entries:s}})},[g,r,u,e,V,F]),P=i((t,n)=>{y&&y(t,n);const i=V.map(e=>e.id===t?{...e,...n}:e);u&&u({id:e,value:{...r,templateComponents:i}})},[y,r,u,e,V]),M=i(e=>{"test"===a&&u&&u({id:e.id,value:e.value})},[u]),z=i(()=>{const t=r.entries||[],n=t.length,i={id:`entry-${e}-${n}`,index:n,components:V.map((t,i)=>{const s=`${t.id||`component-${i}`}-entry-${e}-${n}-${i}`;return{...t,id:s,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}},s=[...t,i];u&&u({id:e,value:{...r,entries:s}}),N?.()},[r,u,e,N,V]),_=i(t=>{const n=r.entries.filter((e,n)=>n!==t).map((t,n)=>({...t,index:n,id:`entry-${e}-${n}`}));u&&u({id:e,value:{...r,entries:n}})},[r,u,e,C]),W=i((e,t=!1)=>{const n=o[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let i=n;"number-input"===e.name&&"number"==typeof n?i=String(n):"number-input"===e.name&&null==n&&(i="");const s={id:e.id,properties:e,validationErrors:l||{},formValue:i,touchedFields:c||{},formSubmitted:d||!1,mode:a,hideLabel:t,onValueChange:M,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...s,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1,hideLabel:t});case"textarea":return B.jsx(Q,{...s,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"select":const n={...e,options:e.basic?.options||[]};return B.jsx(ee,{...s,properties:n,disabled:!1,hideLabel:t});case"checkbox":const i={...e,options:e.basic?.options||[]};return B.jsx(te,{...s,properties:i,formValue:[],disabled:!1,hideLabel:t});case"radio":const r={...e,options:e.basic?.options||[]};return B.jsx(ne,{...s,properties:r,readonly:!1,disabled:!1,hideLabel:t});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...s,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"signature":return B.jsx(re,{...s,properties:e,hideLabel:t});case"heading":return B.jsx(le,{...s,properties:e,hideLabel:t});case"instructions":return B.jsx(ce,{...s,properties:e,hideLabel:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",e.name]})}},[a,M,o,l,c,d]),U={backgroundColor:r.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:r.styles.borderColor||"var(--df-color-fb-border)",borderWidth:r.styles.borderWidth||"2px",borderRadius:r.styles.borderRadius||"8px",padding:r.styles.padding||"16px",margin:r.styles.margin||"16px 0"};return B.jsxs("div",{className:`form-group df-form-datagrid ${p?"selected":""} ${h}`,onClick:O,style:U,children:[B.jsx("div",{className:"grid-header",children:B.jsx("div",{className:"grid-title",onClick:t=>{t.stopPropagation(),R(!I),u?.({id:e,value:{...r,basic:{...r.basic,collapsed:!I}}})},children:B.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[I?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(A,{size:16}),B.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:r.basic.label}),r.validation.required&&B.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),r.basic.description&&!I&&B.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:r.basic.description}),!I&&B.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===a?B.jsx(ge,{gridComponents:V,mode:a,onComponentSelect:b||(()=>{}),onComponentDelete:q,onComponentEdit:v,onComponentUpdate:P,selectedComponent:x||null,renderFormComponent:j||W,gridId:e,formData:o,formTemplateId:$,onThresholdActionCompletion:k,onThresholdIssueRaised:E,onNotesChange:T,onAttachmentChange:L}):B.jsx(ve,{templateComponents:V,dataEntries:F,renderFormComponent:j||W,mode:a,allowAddRemoveEntries:r.datagrid?.allowAddRemoveEntries??!0,addAnotherText:r.datagrid?.addAnotherText??"Add Entry",removeText:r.datagrid?.removeText??"Remove",maxEntries:r.datagrid?.maxEntries??10,minEntries:r.datagrid?.minEntries??1,displayAsGrid:r.datagrid?.displayAsGrid??!0,onAddEntry:N||z,onRemoveEntry:C||_,formData:o,formTemplateId:$,onThresholdActionCompletion:k,onThresholdIssueRaised:E,onNotesChange:T,onAttachmentChange:L,datagridId:e})})]})},xe=e.lazy(()=>Promise.resolve().then(function(){return Ae})),je=({formComponents:r=[],currentDevice:a="desktop",isPreviewMode:o=!1,initialFormData:l=[],onSubmit:c,onFormDataChange:d,formTitle:u,formDescription:m,formTemplateId:p,onComponentSelect:h,onComponentDelete:f,onComponentEdit:b,onComponentUpdate:g,selectedComponent:v})=>{const[y,x]=t({}),[j,N]=t({}),[C,w]=t(!1),[S,$]=t({}),[k,E]=t({}),[A,T]=t(new Set),[L,I]=t(new Map),[R,D]=t({isValid:!0});n(()=>{F()},[r,l]);const V=(e,t)=>{e.forEach(e=>{if(e.id&&("value"in e.basic&&void 0!==e.basic.value?t[e.id]=e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?t[e.id]=e.basic.defaultValue:"checkbox"===e.name||"select"===e.name?t[e.id]=[]:t[e.id]=""),e.cells&&Array.isArray(e.cells)&&e.cells.forEach((e,n)=>{Array.isArray(e)&&e.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&V(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&V(e.components,t)}),"file"===e.name&&e.basic){const n=e.basic.files||e.basic.attachments||e.basic.value;n&&(t[e.id]=n)}if("instructions"===e.name&&e.basic){e.basic.instructions||(e.basic.instructions=[]);const n=e.basic.value||e.basic.instructions;n&&(t[e.id]=n)}e.children&&Array.isArray(e.children)&&V(e.children,t)})},F=i(()=>{const e={},t=new Set,n=e=>{e.forEach(e=>{e.id&&(t.has(e.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${e.id}. Component:`,e),e.id=`${e.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${e.id}`)),t.add(e.id)),e.children&&Array.isArray(e.children)&&n(e.children),e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})})};r&&r.length>0&&n(r),l&&l.length>0&&n(l),l&&l.length>0&&V(l,e),r&&r.length>0&&V(r,e),x(e),q()},[l,r]),O=(e,t)=>{e.forEach(e=>{if(e.id)if("table"===e.name||"datagrid"===e.name)t[e.id]=!0;else if(e.conditional){const n=G.evaluateConditionalLogic(e.conditional,r,y);t[e.id]=n.shouldShow}else t[e.id]=!0;e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{e.forEach(e=>{e.components&&Array.isArray(e.components)&&O(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&O(e.components,t)}),e.children&&Array.isArray(e.children)&&O(e.children,t)})},q=i(()=>{const e={};r&&r.length>0&&O(r,e),E(e)},[r,y]),P=i(e=>{const t=r.find(t=>t.id===e);if(t&&("table"===t.name||"datagrid"===t.name))return!0;return!1!==k[e]},[k,r]),M=i(e=>{if(!e.id||"string"!=typeof e.id||""===e.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",e);const t=r.filter(t=>t.id===e.id);if(t.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${e.id}":`,t.map(e=>({id:e.id,name:e.name,label:e.basic?.label})));const n=y[e.id];void 0!==n&&n!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:n,newValue:e.value});const i={...y,[e.id]:e.value};x(i);const s=r.find(t=>t.id===e.id);if(s){const e=s?.threshold;e&&e.conditions&&e.conditions.length>0&&T(t=>{const n=new Set(t);return e.conditions.forEach(e=>{n.delete(e.id)}),n})}const a=t=>t.map(t=>t.id===e.id&&"defaultValue"in t.basic?{...t,basic:{...t.basic,value:e.value??t.basic.defaultValue,defaultValue:e.value}}:"section"===t.name&&t.children?{...t,children:a(t.children)}:"table"===t.name&&t.cells?{...t,cells:t.cells.map(e=>e.map(e=>{const t={...e};return t.components&&(t.components=a(t.components)),t}))}:"datagrid"===t.name&&t.entries?{...t,entries:t.entries.map(e=>{const t={...e};return t.components&&(t.components=a(t.components)),t})}:t),l=a(r);if(d?.(l),j[e.id]&&N(t=>({...t,[e.id]:""})),!o){if(e.isValid)return void N(t=>{const n=t[e.id];return n&&""!==n.trim()?{...t,[e.id]:""}:t});setTimeout(()=>{_(e.id)},150)}setTimeout(()=>{const e={};r.forEach(t=>{if("table"===t.name||"datagrid"===t.name)e[t.id]=!0;else if(t.conditional){const n=G.evaluateConditionalLogic(t.conditional,r,i);e[t.id]=n.shouldShow}else e[t.id]=!0}),E(e)},0)},[r,y,j,d]),z=i((e,t)=>{for(const n of e){if(n.id===t)return n;if("section"===n.name&&n.children){const e=z(n.children,t);if(e)return e}if("table"===n.name&&n.cells)for(const e of n.cells)for(const n of e)if(n.components){const e=z(n.components,t);if(e)return e}if("datagrid"===n.name&&n.entries)for(const e of n.entries)if(e.components){const n=z(e.components,t);if(n)return n}}return null},[]),_=i(e=>{if(o)return;const t=z(r,e);if(!t)return;const n=y[e]||"";if("number-input"===t.name&&(!n||""===n)){if(t.validation.required){const n=t.validation.customValidationMessage,i=t.basic.label||"This field",s=n||`${i} is required`;N(t=>({...t,[e]:s}))}else N(t=>({...t,[e]:""}));return}let i=!1;i=Array.isArray(n)?n.length>0:"string"==typeof n?""!==n.trim():null!=n;let s="";if(t.validation.required&&!i){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} is required`}else if("email-input"===t.name&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be a valid email`}else if(t.validation.minLength&&i&&n.length<t.validation.minLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be at least ${t.validation.minLength} characters`}else if(t.validation.maxLength&&i&&n.length>t.validation.maxLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";s=e||`${n} must be no more than ${t.validation.maxLength} characters`}else if("number-input"===t.name&&i){const e=String(n).trim(),i=parseFloat(e);if(!isNaN(i)){const e=t.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&i<e.lowerLimit?s="Number is below the lower limit":e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&i>e.upperLimit&&(s="Number is above the upper limit")}}N(t=>({...t,[e]:s}))},[r,o,y,z]),W=i(e=>{$(t=>({...t,[e]:!0})),o||setTimeout(()=>{_(e)},0)},[o,_]),U=i(e=>{j[e]&&N(t=>({...t,[e]:""}))},[j]),H=i(()=>!Object.values(j).some(e=>e&&"string"==typeof e&&""!==e.trim())&&r.every(e=>{const t=y[e.id]||"";let n=!1;if(n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!n)return!1;if("number-input"===e.name&&n){const n=String(t).trim(),i=parseFloat(n);if(!isNaN(i)){const t=e.validation;if(t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&i<t.lowerLimit)return!1;if(t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&i>t.upperLimit)return!1}}return!0}),[r,y,j]),Y=i((e,t)=>{if(Array.isArray(t))return t.some(t=>Y(e,t));if(null==t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(!isNaN(n)&&!isNaN(i))switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}const s=String(t).toLowerCase(),r=String(e.value).toLowerCase();switch(e.operator){case"equals":return s===r||String(t)===String(e.value);case"notEquals":return s!==r&&String(t)!==String(e.value);default:return!1}},[]),K=i(()=>{if(o)return[];const e=[];return r.forEach(t=>{const n=t?.condition;if(!n||!n.conditions||0===n.conditions.length)return;const i=y[t.id];null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length)&&n.conditions.forEach(n=>{Y(n,i)&&e.push({componentId:t.id,condition:n,componentLabel:t.basic?.label||"Field"})})}),e},[r,y,o,Y]),X=i(()=>{if(o)return{isValid:!0};const e=K();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:n}of e){const e=L.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},i=[];if(!0!==t.enableRaiseIssue||A.has(t.id)||i.push("raise an issue"),!0!==t.enableNotes||e.notesCompleted||i.push("add notes"),!0!==t.enableAttachment||e.attachmentsCompleted||i.push("add attachments"),!0!==t.enableSendEmail||e.emailSent||i.push("send email"),i.length>0){return{isValid:!1,errorMessage:`Please ${1===i.length?i[0]:i.slice(0,-1).join(", ")+" and "+i[i.length-1]} for the threshold condition met in "${n}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[o,K,A,L]),de=i(e=>{e&&T(t=>{const n=new Set(t);return n.add(e),n})},[]),me=i((e,t,n)=>{e&&I(i=>{const s=new Map(i),r=s.get(e)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===t?s.set(e,{...r,notesCompleted:n}):"attachments"===t?s.set(e,{...r,attachmentsCompleted:n}):"email"===t&&s.set(e,{...r,emailSent:n}),s})},[]);n(()=>{if(!o){const e=X();D(e)}},[y,A,L,o,X]);const he=i(()=>{if(o)return!0;let e=!0;w(!0);const t={};return r.forEach(n=>{const i=y[n.id]||"";let s=!1;if(s=Array.isArray(i)?i.length>0:"string"==typeof i?""!==i.trim():null!=i,n.validation.required&&!s){const i=n.validation.customValidationMessage,s=n.basic.label||"This field",r=i||`${s} is required`;t[n.id]=r,e=!1}else if("number-input"===n.name&&s){const s=String(i).trim(),r=parseFloat(s);if(isNaN(r))t[n.id]="";else{const i=n.validation;i&&"lowerLimit"in i&&void 0!==i.lowerLimit&&null!==i.lowerLimit&&0!==i.lowerLimit&&r<i.lowerLimit?(t[n.id]="Number is below the lower limit",e=!1):i&&"upperLimit"in i&&void 0!==i.upperLimit&&null!==i.upperLimit&&0!==i.upperLimit&&r>i.upperLimit?(t[n.id]="Number is above the upper limit",e=!1):t[n.id]=""}}else t[n.id]="";$(e=>({...e,[n.id]:!0}))}),N(t),e},[r,o,y]),be=i(()=>{if(w(!0),!he()){const e=r.find(e=>{const t=y[e.id]||"";let n=!1;return n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!n});if(e){const t=document.getElementById(e.id);t&&t.focus()}return}const e=X();if(!e.isValid){e.errorMessage&&J.showError(e.errorMessage);const t=K().find(({condition:e})=>!A.has(e.id));if(t){const e=document.getElementById(t.componentId);e&&e.scrollIntoView({behavior:"smooth",block:"center"})}return}const t=e=>e.map(e=>{let n=y[e.id];"text-input"===e.name&&e.basic,void 0===n&&(n="value"in e.basic&&void 0!==e.basic.value?e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?e.basic.defaultValue:""),"text-input"===e.name&&e.basic;const i={...e,basic:{...e.basic,value:n,defaultValue:n}};return"section"===i.name&&i.children&&(i.children=t(i.children)),"table"===i.name&&i.cells&&(i.cells=i.cells.map(e=>e.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n}))),"datagrid"===i.name&&i.entries&&(i.entries=i.entries.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n})),i}),n=t(r);c?.(n)},[r,y,he,c]),ge=i(()=>({[`device-${a}`]:!0,readonly:o}),[a,o]),ve=s(new Map),je=s(0),Ne=t=>{let n;if(t.id&&"string"==typeof t.id&&""!==t.id.trim())n=t.id;else{const e=t.basic?.label||"",i=t.name||"unknown",s=`${i}-${e}`;let r=ve.current.get(s);r||(je.current+=1,r=`generated-${i}-${je.current}-${Math.random().toString(36).substr(2,9)}`,ve.current.set(s,r),console.warn("[DfFormPreview] Generated and cached ID for component:",r,"key:",s)),n=r,t={...t,id:n}}const i=n,s=y[i];if(void 0!==s){const e=r.filter(e=>e.id!==i&&y[e.id]===s);e.length>0&&console.warn(`[DfFormPreview] Component ${i} shares form value with other components:`,e.map(e=>e.id))}const a={id:i,validationErrors:j,formValue:s,touchedFields:S,formSubmitted:C,mode:"test",readonly:!1,onValueChange:M,onBlur:()=>W(i),onFocus:()=>U(i)};switch(t.name){case"text-input":case"number-input":case"email-input":return B.jsx(Z,{...a,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",formTemplateId:p,onThresholdIssueRaised:de,raisedThresholdIssues:A});case"textarea":return B.jsx(Q,{...a,properties:t});case"select":const n={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ee,{...a,properties:n});case"checkbox":const i={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(te,{...a,properties:i});case"radio":const o={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ne,{...a,properties:o});case"segment":const l={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ie,{...a,properties:l});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...a,properties:t});case"signature":return B.jsx(re,{...a,properties:t});case"heading":return B.jsx(le,{...a,properties:t});case"instructions":const c=s||t.basic?.value||null;return B.jsx(ce,{...a,properties:t,formValue:c});case"location":return B.jsx(oe,{...a,properties:t});case"section":return B.jsx(fe,{...a,properties:t,formData:y,formTemplateId:p,onThresholdActionCompletion:me,onThresholdIssueRaised:de,renderFormComponent:e=>Ne(e)});case"table":return B.jsx(e.Suspense,{fallback:B.jsx("div",{children:"Loading table..."}),children:B.jsx(xe,{...a,properties:t,formData:y,formTemplateId:p,mode:a.mode,validationErrors:j,touchedFields:S,formSubmitted:C,onThresholdActionCompletion:me,onThresholdIssueRaised:de,onNotesChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},renderFormComponent:e=>Ne(e)})});case"datagrid":return B.jsx(ye,{...a,properties:t,formData:y,formTemplateId:p,mode:a.mode,validationErrors:j,touchedFields:S,formSubmitted:C,onThresholdActionCompletion:me,onThresholdIssueRaised:de,onComponentSelect:h,onComponentDelete:f,onComponentEdit:b,onComponentUpdate:g,selectedComponent:v,onValueChange:e=>{if(e.id===t.id&&e.value&&"object"==typeof e.value&&"entries"in e.value){const n=r.map(n=>n.id===t.id?{...n,...e.value}:n);d?.(n),e.value.entries&&Array.isArray(e.value.entries)&&e.value.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&e.components.forEach(e=>{if(void 0!==y[e.id]);else{const t=e.basic?.defaultValue;void 0!==t&&x(n=>({...n,[e.id]:t}))}})})}else M(e)},onEntryAdd:()=>{const e=r.find(e=>e.id===t.id);if(e&&e.entries){const e=r.map(e=>e.id===t.id?{...e,entries:e.entries||[]}:e);d?.(e)}else setTimeout(()=>{const e=y[t.id];if(e&&"object"==typeof e&&"entries"in e){const n=r.map(n=>n.id===t.id?{...n,entries:e.entries}:n);d?.(n)}},100)},onEntryRemove:e=>{const n=r.map(n=>{if(n.id===t.id&&n.entries){const t=(n.entries||[]).filter((t,n)=>n!==e).map((e,t)=>({...e,index:t,id:`entry-${n.id}-${t}`,components:e.components?.map((e,n)=>{const i=(e.templateComponents||[])[n];return{...e,id:i?`${i.id}-entry-${t}-${n}`:e.id}})||[]}));return{...n,entries:t}}return n});d?.(n)},onNotesChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=r.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},renderFormComponent:e=>Ne(e)});case"file":const u=s||t.basic?.value||t.basic?.files||t.basic?.attachments||null;return B.jsx(ae,{...a,properties:t,formValue:u});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",t.name]})})}};return B.jsx("div",{className:"form-preview-container",children:B.jsx("div",{className:"form-preview-wrapper",children:B.jsxs("div",{className:`form-preview ${Object.entries(ge()).map(([e,t])=>t?e:"").join(" ")}`,children:[B.jsx("div",{className:"form-canvas-header"}),0===r.length?B.jsx("div",{className:"empty-state",children:B.jsx("div",{className:"empty-state-card",children:B.jsx("div",{className:"empty-state-preview-area",children:B.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):B.jsxs("form",{className:"form-preview-form",onSubmit:e=>{e.preventDefault(),be()},children:[(u||m)&&B.jsxs("div",{className:"form-header",children:[u&&B.jsx("h1",{className:"form-title",children:u}),m&&B.jsx("p",{className:"form-description",children:m})]}),r.map(e=>{const t=e.basic,n=y[e.id],i=["select","radio","checkbox","segment"].includes(e.name||""),s=e.options||t?.options||[],a=(()=>{const t=e?.styles?.column;return"section"===e.name||"table"===e.name||"datagrid"===e.name?"col-12":3===t?"col-3":6===t?"col-6":9===t?"col-9":"col-12"})();let l=!1;if(!o)if(i&&null!=n&&""!==n)if("checkbox"===e.name){l=(Array.isArray(n)?n:[n]).some(e=>{const t=s.find(t=>t.value===e);return t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)})}else{const e=s.find(e=>e.value===n);l=e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)}else l=t?.enableNotes||t?.enableAttachment||t?.enableRaiseIssue||t?.enableSendEmail;const c=o&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:`form-group ${a} ${l||c?"has-action-features":""}`,style:{display:P(e.id)?"block":"none"},children:[Ne(e),!o&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:o?"preview":"test",formTemplateId:p,formValue:n,onThresholdActionCompletion:me,onThresholdIssueRaised:de,onNotesChange:t=>{const n=r.map(n=>n.id===e.id?{...n,basic:{...n.basic,notes:t||""}}:n);d?.(n)},onAttachmentChange:t=>{const n=r.map(n=>n.id===e.id?{...n,basic:{...n.basic,attachments:t||[]}}:n);d?.(n)},notes:e.basic?.notes||"",attachments:e.basic?.attachments||null}),o&&c&&B.jsx(pe,{component:e})]},e.id)}),!o&&B.jsx("div",{className:"form-actions",children:B.jsx("button",{type:"submit",disabled:!H()||!R.isValid,className:"form-submit-button",title:R.isValid?"":R.errorMessage,children:"Submit"})})]})]})})})},Ne=({comment:e="",onSave:s,placeholder:r="Enter your reason...",className:a="",disabled:o=!1})=>{const[l,c]=t(!0),[d,u]=t(e),[m,p]=t(!1);n(()=>{u(e),p(!1)},[e]);const h=i(t=>{const n=t.target.value;u(n),p(n!==e)},[e]),f=i(()=>{m&&s&&!o&&(s(d),p(!1))},[m,s,d,o]),b=i(()=>{},[]),g=i(()=>{o||c(!l)},[l,o]);return B.jsxs("div",{className:`df-form-comments ${a}`,children:[B.jsxs("div",{className:"df-form-comments__header",children:[B.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),B.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:g,"aria-expanded":l,"aria-label":"Toggle comments section",disabled:o,children:l?B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),B.jsx("div",{className:"df-form-comments__content "+(l?"df-form-comments__content--expanded":""),children:B.jsx("div",{className:"df-form-comments__input-container",children:B.jsx("div",{className:"df-form-comments__input-line",children:B.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:d,onChange:h,onBlur:f,onFocus:b,placeholder:r,disabled:o})})})})]})},Ce=e=>e.id?e:{...e,id:q()},we=({component:e,mode:t,renderFormComponent:n,formData:i={},formTemplateId:s,onThresholdActionCompletion:r,onThresholdIssueRaised:a,onNotesChange:o,onAttachmentChange:l})=>{const c=i[e.id],d="preview"===t&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:"simple-table-component",children:[n(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:s,formValue:c,onThresholdActionCompletion:r,onThresholdIssueRaised:a,onNotesChange:o?t=>o(e.id,t):void 0,onAttachmentChange:l?t=>l(e.id,t):void 0}),d&&B.jsx(pe,{component:e})]})},Se=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:s,onComponentEdit:r,renderFormComponent:a,isOverlay:o=!1})=>{const{attributes:l,listeners:c,setNodeRef:d,transform:u,transition:m,isDragging:p,isSorting:h}=V({id:e.id,disabled:o}),f={transform:O.Transform.toString(u),transition:m,opacity:p?.3:1,zIndex:p?1e3:"auto"};return B.jsxs("div",{ref:d,style:f,className:`form-component table-component ${t?.id===e.id?"selected":""} ${p?"dragging":""} ${h?"sorting":""}`,onClick:()=>!p&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...c,...l,onClick:e=>e.stopPropagation(),style:{opacity:1},children:B.jsx($,{size:14})}),B.jsx("div",{className:"component-content",children:a(e)}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{opacity:1},children:[r&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),r(e)},type:"button",title:"Edit Component",children:B.jsx(k,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),s(e,t)},type:"button",title:"Delete Component",children:B.jsx(E,{size:12})})]})]})},$e=({cell:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,selectedComponent:r,renderFormComponent:a,formData:o={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,tableId:u,onNotesChange:m,onAttachmentChange:p})=>{const h=`table-cell-${u}-${e.row}-${e.column}`,{setNodeRef:f,isOver:b}=I({id:h,disabled:"edit"!==t,data:{type:"table-cell",tableId:u,cell:e,row:e.row,column:e.column}}),g={...e.styles,backgroundColor:b?"var(--df-color-primary-light)":e.styles?.backgroundColor||"transparent",minHeight:e.styles?.minHeight||"preview"===t||"test"===t?"40px":"60px",padding:(e.styles,"8px"),border:"preview"===t||"test"===t?"none":b?"2px dashed var(--df-color-primary)":e.styles?.borderColor?`1px solid ${e.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===t||"test"===t?"0":"4px",position:"relative",verticalAlign:e.styles?.verticalAlign||"top"};return B.jsx("td",{ref:f,style:g,className:"table-cell "+(b?"drag-over":""),children:B.jsx("div",{className:"cell-content",children:e.components&&Array.isArray(e.components)&&e.components.length>0?"edit"===t?B.jsx(R,{items:e.components.map(e=>e.id||q()),strategy:D,children:e.components.map(e=>{const o=Ce(e);return B.jsx(Se,{component:o,selectedComponent:r,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,renderFormComponent:a},o.id)})}):e.components.map(e=>{const n=e.id?e:Ce(e);return B.jsx(we,{component:n,mode:t,renderFormComponent:a,formData:o,formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,onNotesChange:m,onAttachmentChange:p},n.id)}):"edit"===t?B.jsx("div",{className:"empty-cell-placeholder",children:B.jsxs("div",{className:"cell-info",children:[B.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),B.jsxs("span",{className:"cell-coordinates",children:["Cell (",e.row+1,", ",e.column+1,")"]})]})}):B.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},ke=({id:e,properties:s,mode:a="edit",formData:o={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onTableSelect:f,onComponentSelect:b,onComponentDelete:g,onComponentEdit:v,selectedComponent:y,renderFormComponent:x,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,onNotesChange:$,onAttachmentChange:k})=>{const[E,A]=t(!1),L=s.cells?.some(e=>e.some(e=>e.components&&e.components.length>0))||!1;n(()=>{},[s.table?.rows,s.table?.columns,s.basic?.rows,s.basic?.columns,s.cells,e,u]);const I=i(e=>{e.stopPropagation(),m?.(),f?.(s)},[m,f,s]),R=i((t,n)=>{n.stopPropagation();const i=s.cells.map(e=>e.map(e=>{if(e.components&&e.components.some(e=>e.id===t.id)){const n=e.components.filter(e=>e.id!==t.id);return{...e,components:n}}return e}));u&&u({id:e,value:{...s,cells:i}})},[g,s,u,e]),D=r(()=>s.cells?s.cells.map((t,n)=>t.map((t,i)=>({...t,components:t.components&&Array.isArray(t.components)?t.components.map((t,s)=>{if(t.id&&"string"==typeof t.id&&""!==t.id.trim())return t;const r=`${t.name||"component"}-table-${e}-row-${n}-cell-${i}-comp-${s}`;return{...t,id:r}}):[]}))):[],[s.cells,e]),V=x||i(e=>{const t=e.id?e:Ce(e),n=o[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let i=n;"number-input"===t.name&&"number"==typeof n?i=String(n):"number-input"===t.name&&null==n&&(i="");const s={id:t.id,properties:t,validationErrors:{},formValue:i,touchedFields:{},formSubmitted:!1,mode:a,onValueChange:e=>{u?.(e)},onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...s,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...s,properties:t,readonly:!1,disabled:!1});case"select":const e={...t,options:t.basic?.options||[]};return B.jsx(ee,{...s,properties:e,disabled:!1});case"checkbox":const n={...t,options:t.basic?.options||[]};return B.jsx(te,{...s,properties:n,formValue:[],disabled:!1});case"radio":const i={...t,options:t.basic?.options||[]};return B.jsx(ne,{...s,properties:i,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...s,properties:t,readonly:!1,disabled:!1});case"signature":return B.jsx(re,{...s,properties:t});case"heading":return B.jsx(le,{...s,properties:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",t.name]})}},[x,a,o,u]),F={backgroundColor:s.styles?.backgroundColor||"var(--df-color-fb-container)",borderColor:s.styles?.borderColor||"var(--df-color-fb-border)",borderWidth:s.styles?.borderWidth||"2px",borderRadius:s.styles?.borderRadius||"8px",padding:s.styles?.padding||"16px",margin:s.styles?.margin||"16px 0"},O={width:"100%",minWidth:"600px",borderCollapse:"preview"===a||"test"===a?"separate":"collapse",tableLayout:"fixed",border:"preview"===a||"test"===a?"1px solid var(--df-color-fb-border)":"none"};return L||"preview"!==a?B.jsxs("div",{className:`form-group df-form-table ${p?"selected":""} ${"preview"===a?"preview-mode":"test"===a?"test-mode":""} ${h}`,onClick:I,style:F,children:[B.jsx("div",{className:"table-header",children:B.jsx("div",{className:"table-title",onClick:t=>{t.stopPropagation(),A(!E),u?.({id:e,value:{...s,basic:{...s.basic||{},collapsed:!E}}})},children:B.jsxs("div",{className:"title-content",children:[E?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(T,{size:16}),B.jsx("span",{className:"table-label",children:s.basic?.label||"Table"}),s.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]})})}),s.basic?.description&&!E&&B.jsx("div",{className:"table-description",children:s.basic.description}),!E&&B.jsxs("div",{className:"table-content",children:[null,B.jsxs("table",{style:O,children:[s.table?.displayAsTable&&("edit"===a||s.table?.showColumns)&&B.jsx("thead",{children:B.jsx("tr",{className:"table-header-row",children:Array.from({length:s.table?.columns||s.basic?.columns||3},(e,t)=>{const n=(s.table?.columnNames?.split(",").map(e=>e.trim())||[])[t]||`Column ${t+1}`;return B.jsx("th",{className:"table-header-cell",style:{backgroundColor:(s.styles.headerBackgroundColor,"var(--df-color-fb-container)"),color:s.styles.headerTextColor||"var(--df-color-text-dark)",padding:"12px",border:"1px solid var(--df-color-fb-border)",fontWeight:"600",fontSize:"14px",textAlign:"center"},children:n},`header-${t}`)})})}),B.jsx("tbody",{children:D.map((t,n)=>B.jsx("tr",{className:"table-row",children:t.map(t=>B.jsx($e,{cell:t,mode:a,onComponentSelect:b||(()=>{}),onComponentDelete:R,onComponentEdit:v,selectedComponent:y||null,renderFormComponent:V,formData:o,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,tableId:e,onNotesChange:$,onAttachmentChange:k},t.id))},n))})]})]})]}):null};var Ee,Ae=Object.freeze({__proto__:null,DfFormTable:ke,default:ke});!function(e){e.Top="top",e.Left="left"}(Ee||(Ee={}));export{ue as ComponentActionFeatures,pe as ComponentSubmissionActions,te as DfFormCheckbox,Ne as DfFormComments,ye as DfFormDataGrid,se as DfFormDateTime,H as DfFormErrorMsg,ae as DfFormFileUpload,le as DfFormHeading,Z as DfFormInput,ce as DfFormInstruction,oe as DfFormLocation,je as DfFormPreview,ne as DfFormRadio,fe as DfFormSection,ie as DfFormSegment,ee as DfFormSelect,re as DfFormSignature,ke as DfFormTable,Q as DfFormTextarea,Ee as ELabelAlignment,K as RaiseIssueModal,X as ThresholdAlert,G as conditionalLogicService,J as toastService};
11
11
  //# sourceMappingURL=index.esm.js.map