df-ae-forms-package 1.0.35 → 1.0.36
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.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +29 -0
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e,{useState as t,useEffect as
|
|
1
|
+
import e,{useState as t,useEffect as i,useCallback as n,useRef as s,useMemo as r}from"react";import{AlertTriangle as a,X as o,User as l,Calendar as c,Paperclip as d,Trash2 as u,MessageSquare as m,Loader2 as p,Navigation as h,MapPin as f,Bold as b,Italic as g,List as x,ListOrdered as y,Image as v,Check as j,Mail as N,AlertCircle as C,ChevronUp as w,ChevronDown as S,ChevronRight as k,GripVertical as $,Edit as A,Grid as E,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 O,useSortable as D,horizontalListSortingStrategy as V}from"@dnd-kit/sortable";import{CSS as F}from"@dnd-kit/utilities";import{v4 as z}from"uuid";var M,q={exports:{}},P={};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?q.exports=function(){if(M)return P;M=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,o={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,i){var a,l={},c=null,d=null;for(a in void 0!==i&&(c=""+i),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(d=t.ref),t)s.call(t,a)&&!o.hasOwnProperty(a)&&(l[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===l[a]&&(l[a]=t[a]);return{$$typeof:n,type:e,key:c,ref:d,props:l,_owner:r.current}}return P.Fragment=i,P.jsx=a,P.jsxs=a,P}():q.exports=(W||(W=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"),o=Symbol.for("react.strict_mode"),a=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"),g=Symbol.iterator,b=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(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=b.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 v(e){if(null==e)return null;if("number"==typeof e.tag&&x("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 a:return"Profiler";case o: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:v(e.type)||"Memo";case h:var n=e,i=n._payload,f=n._init;try{return v(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=b.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,k=console.groupCollapsed,$=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 o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(o,[])}catch(e){n=e}Reflect.construct(e,[],o)}else{try{o.call()}catch(e){n=e}e.call(o.prototype)}}else{try{throw Error()}catch(e){n=e}e()}}catch(t){if(t&&n&&"string"==typeof t.stack){for(var a=t.stack.split("\n"),l=n.stack.split("\n"),c=a.length-1,d=l.length-1;c>=1&&d>=0&&a[c]!==l[d];)d--;for(;c>=1&&d>=0;c--,d--)if(a[c]!==l[d]){if(1!==c||1!==d)do{if(c--,--d<0||a[c]!==l[d]){var u="\n"+a[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:k}),groupEnd:E({},e,{value:$})})}A<0&&x("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 z(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 z(e.type,t,n);case h:var s=e,r=s._payload,o=s._init;try{return z(o(r),t,n)}catch(e){}}return""}D=new F;var M=Object.prototype.hasOwnProperty,q={},P=b.ReactDebugCurrentFrame;function W(e){if(e){var t=e._owner,n=z(e.type,e._source,t?t.type:null);P.setExtraStackFrame(n)}else P.setExtraStackFrame(null)}var B=Array.isArray;function U(e){return B(e)}function G(e){return""+e}function H(e){if(function(e){try{return G(e),!1}catch(e){return!0}}(e))return x("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 J,Y,K,X=b.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,n,s,r){var o,a={},l=null,c=null;for(o in void 0!==n&&(H(n),l=""+n),function(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(H(t.key),l=""+t.key),function(e){if(M.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=v(X.current.type);K[n]||(x('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',v(X.current.type),e.ref),K[n]=!0)}}(t,r)),t)M.call(t,o)&&!Z.hasOwnProperty(o)&&(a[o]=t[o]);if(e&&e.defaultProps){var d=e.defaultProps;for(o in d)void 0===a[o]&&(a[o]=d[o])}if(l||c){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;l&&function(e,t){var n=function(){J||(J=!0,x("%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})}(a,u),c&&function(e,t){var n=function(){Y||(Y=!0,x("%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})}(a,u)}return function(e,t,n,s,r,o,a){var l={$$typeof:i,type:e,key:t,ref:n,props:a,_owner:o,_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,a)}K={};var ee,te=b.ReactCurrentOwner,ne=b.ReactDebugCurrentFrame;function ie(e){if(e){var t=e._owner,n=z(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=v(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var oe={};function ae(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(!oe[n]){oe[n]=!0;var i="";e&&e._owner&&e._owner!==te.current&&(i=" It was passed a child from "+v(e._owner.type)+"."),ie(e),x('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)&&ae(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=g&&e[g]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof s&&s!==e.entries)for(var r,o=s.call(e);!(r=o.next()).done;)se(r.value)&&ae(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=v(n);!function(e,t,n,i,s){var r=Function.call.bind(M);for(var o in e)if(r(e,o)){var a=void 0;try{if("function"!=typeof e[o]){var l=Error((i||"React class")+": "+n+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw l.name="Invariant Violation",l}a=e[o](t,o,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){a=e}!a||a instanceof Error||(W(s),x("%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,o,typeof a),W(null)),a instanceof Error&&!(a.message in q)&&(q[a.message]=!0,W(s),x("Failed %s type: %s",n,a.message),W(null))}}(t,e.props,"prop",i,e)}else void 0===n.PropTypes||ee||(ee=!0,x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v(n)||"Unknown"));"function"!=typeof n.getDefaultProps||n.getDefaultProps.isReactClassApproved||x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var de={};function ue(e,n,s,g,b,y){var j=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===a||e===o||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+".":""}(b);N+=w||re(),null===e?C="null":U(e)?C="array":void 0!==e&&e.$$typeof===i?(C="<"+(v(e.type)||"Unknown")+" />",N=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,x("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,b,y);if(null==S)return S;if(j){var k=n.children;if(void 0!==k)if(g)if(U(k)){for(var $=0;$<k.length;$++)le(k[$],e);Object.freeze&&Object.freeze(k)}else x("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(k,e)}if(M.call(n,"key")){var E=v(e),A=Object.keys(n).filter(function(e){return"key"!==e}),T=A.length>0?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}";de[E+T]||(x('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),x("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),x("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)};_.Fragment=r,_.jsx=me,_.jsxs=pe}()),_);var B=q.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 H=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]}},J=({validationErrors:e,fieldId:t,touchedFields:n,formSubmitted:i,properties:s,localValidation:r,isTouched:o,mode:a})=>{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,o=i?.upperLimit;return`You crossed the limit. ${t} must be no more than ${o}`;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"!==a)return"";if(!(o||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:g,user:b,availableUsers:x=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:y,assetNumber:v})=>{const[j,N]=t(""),[C,w]=t(""),[S,k]=t(""),[$,E]=t(""),[A,T]=t("Medium"),[I,R]=t(Y.OPEN),[D,V]=t(""),[F,O]=t(""),[z,M]=t(!1),q=!!h;n(()=>{if(e)if(h){N(h.title||""),w(h.description||""),k(h.workOrderNumber||""),E(h.assetNumber||""),T(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;R(t),V(h.assignee||""),O(h.comments||"")}else if(r){const e=r.basic?.label||"Component";N(`${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}`),w(t),O(m||""),y&&k(y),v&&E(v)}},[e,r,m,h,y,v]);const P=async e=>{if(h){M(!0);try{const t={title:String(j||"").trim(),description:String(C||"").trim(),workOrderNumber:String(S||"").trim()||"",assetNumber:String($||"").trim()||"",formTemplateId:h.formTemplateId||"",component:h.component||{},priority:A,assignee:String(D||"").trim()||void 0,status:e,comments:String(F||"").trim()||""};g&&h._id&&await g(h._id,t),R(e);const n={[Y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[Y.RESOLVE]:"Issue resolved successfully",[Y.REJECTED]:"Issue rejected"};H.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.";H.showError(t)}finally{M(!1)}}};if(!e)return null;const W=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(o,{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(a,{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:j,onChange:e=>N(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:S,onChange:e=>k(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:$,onChange:e=>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:b&&`${b.firstName||""} ${b.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:C,onChange:e=>w(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:I,onChange:e=>R(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:D,onChange:e=>V(e.target.value),children:[B.jsx("option",{value:"",children:"Unassigned"}),x.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"===A?"active":""),onClick:()=>T("Low"),children:"Low"}),B.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===A?"active":""),onClick:()=>T("Medium"),children:"Medium"}),B.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===A?"active":""),onClick:()=>T("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"})]}),!F&&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:F,onChange:e=>O(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:[I===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:async()=>{await P(Y.IN_PROGRESS)},disabled:z,children:z?"Processing...":"Accept"}),I===Y.IN_PROGRESS&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:async()=>{await P(Y.RESOLVE)},disabled:z,children:z?"Processing...":"Resolve"}),I===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:async()=>{await P(Y.REJECTED)},disabled:z,children:z?"Processing...":"Reject"})]}),!q&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save",onClick:async()=>{if(String(j||"").trim())if(String(C||"").trim())if(String(S||"").trim())if(String($||"").trim())if(String(D||"").trim()){M(!0);try{if(q&&h){const e={title:String(j||"").trim(),description:String(C||"").trim(),workOrderNumber:String(S||"").trim()||"",assetNumber:String($||"").trim()||void 0,formTemplateId:h.formTemplateId||"",component:h.component||{},priority:A,assignee:String(D||"").trim()||void 0,status:I,comments:String(F||"").trim()||""};g&&h._id&&await g(h._id,e),H.showSuccess("Issue updated successfully"),s&&s(),i()}else{if(!r)return H.showError("Component is required"),void M(!1);if(!u||""===String(u||"").trim())return H.showError("Form template is required"),void M(!1);const e={...r,basic:{...r.basic,comments:String(m||"")}},t={title:String(j||"").trim(),workOrderNumber:String(S||"").trim()||void 0,assetNumber:String($||"").trim()||void 0,component:e,description:String(C||"").trim(),formTemplateId:u,assignee:String(D||"").trim()||void 0,priority:A,status:I,comments:String(F||"").trim()||""};let n;f&&(n=await f(t,p||[])),H.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.");H.showError(t)}finally{M(!1)}}else H.showError("Assignee is required");else H.showError("Asset Number is required");else H.showError("Work Order is required");else H.showError("Description is required");else H.showError("Title is required")},disabled:z||!String(j||"").trim()||!String(C||"").trim()||!String(S||"").trim()||!String($||"").trim()||!String(D||"").trim(),children:z?"Saving...":"Save Changes"})]})})]})});return L(W,document.body)},X=({component:e,condition:s,currentValue:r,thresholdValue:a,formTemplateId:l,workOrderNumber:c,assetNumber:d,onIssueRaised:u,isIssueRaised:m=!1,compact:p=!1})=>{const[h,f]=t(!1),[g,b]=t(null),[x,y]=t(!1),[v,j]=t(!1);n(()=>{m&&j(!0)},[m]),n(()=>{j(!1)},[s?.id]);const N=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),C=i(async()=>{if(m||v){if(g)return void f(!0);y(!0);try{b(null),f(!0)}catch(e){console.error("Error fetching issue:",e),H.showError("Failed to load issue details")}finally{y(!1)}}else b(null),f(!0)},[m,v,l,e,g]),w=i(()=>{f(!1),m||v||b(null)},[m,v]),S=i(e=>{f(!1),b(e||null),j(!0),u&&s?.id&&u(s.id)},[u,s]);return m||v?B.jsx(B.Fragment,{children:h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})}):p?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(o,{className:"threshold-alert-icon-compact",size:14}),B.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${N(s.operator)} ${a}`}),B.jsx("button",{type:"button",onClick:C,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})]}):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(o,{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=N(s.operator);return`${e.basic?.label||"Value"}: Value ${r} exceeds threshold ${t} ${a}`})(),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:C,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})]})},Z=({id:e,properties:o,validationErrors:a={},formValue:l="",inputType:c="text",readonly:d=!1,disabled:u=!1,touchedFields:m={},formSubmitted:p=!1,mode:h="test",onValueChange:f,onBlur:g,onFocus:b,className:x="",hideLabel:y=!1,formTemplateId:v,onThresholdIssueRaised:j,raisedThresholdIssues:N=new Set,workOrderNumber:C,assetNumber:w})=>{const S=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?S(e.value):"label"in e?S(e.label):"":String(e||""),k=s(e),$=s(null);n(()=>{e!==k.current&&(console.warn(`[DfFormInput] Component ID changed from ${k.current} to ${e}`),k.current=e)},[e]);const E=S(l||o?.basic?.defaultValue||""),[A,T]=t(E),[L,I]=t(!1),[R,D]=t(!1),[V,F]=t(new Set),[O,z]=t(E),M=()=>{if(c)return c;const e=o?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},q=i(e=>{const t=(()=>{const e={};if(o?.validation?.required&&(e.required=!0),"email"===M()&&(e.email=!0),"text"===M()){const t=o.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===M()){const t=o.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"===M())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}},[o,M]),P=i(t=>{const n="string"==typeof t?t:null!=t?String(t):"";if(T(n),f){const t=q(n),i=k.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,k]);n(()=>{L&&(m[e]=!0)},[L,e,m]),n(()=>{if("edit"===h){I(!1);T(o?.basic?.defaultValue||"")}else"test"===h&&(I(!1),T(""))},[h,o?.basic?.defaultValue]),n(()=>{const t=k.current,n=S(l||o?.basic?.defaultValue||"");n===A||R||""===n&&""!==String(A||"").trim()?""===n&&String(A||"").trim():null!=l&&(t===e?T(n):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${t}, prop id: ${e}`))},[l,A,R,o?.basic?.defaultValue,e]),n(()=>{p&&I(!0)},[p]),n(()=>{"test"!==h&&T("")},[h]);const W=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}},[]),_=r(()=>o?.condition?.conditions||[],[o?.condition]);n(()=>{A!==O&&(F(new Set),z(A))},[A,O]);const U=r(()=>{if("test"!==h||!A||""===A)return null;const e=_.filter(e=>W(e,A));if(0===e.length)return null;for(const t of e)if(!V.has(t.id))return t;return null},[A,_,V,h,W,N]),G=i(e=>{F(t=>new Set(t).add(e))},[]),H=M(),Y=u||d||o?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:`form-group ${(()=>{const e=o?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!y&&o.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[o.basic.label,o.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",ref:$,children:[B.jsx("input",{type:H,id:e,value:A,onChange:e=>{const t=e.target.value;P(t)},onFocus:()=>{D(!0),b&&b()},onBlur:()=>{if(D(!1),I(!0),"test"===h&&f){const t="string"==typeof A?A:null!=A?String(A):"",n=q(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};f(i)}g&&g()},placeholder:o.basic.placeholder,disabled:Y,readOnly:d||o?.validation?.readonly,className:(()=>{const t="form-control";if("test"===h){const n="string"==typeof A?A:null!=A?String(A):"",i=q(n);if(i.isValid)return`${t} ${x}`.trim();const s=!i.isValid&&L,r=a[e]&&(L||p)&&!i;return`${t} ${s||r?"is-invalid":""} ${x}`.trim()}return`${t} ${x}`.trim()})()}),B.jsx(J,{validationErrors:a,fieldId:e,touchedFields:m,formSubmitted:p,properties:o,localValidation:q(A),isTouched:L,mode:h})]})]}),U&&"test"===h&&(()=>{const e=N?.has(U.id)||!1,t=null!==$.current?.closest(".table-cell")||null!==$.current?.closest(".cell-content")||null!==$.current?.closest(".datagrid-table-view")||null!==$.current?.closest(".datagrid-list-view")||x.includes("table-cell")||x.includes("cell-content");return B.jsx(X,{component:o,condition:U,currentValue:A,thresholdValue:U.value,formTemplateId:v,workOrderNumber:C,assetNumber:w,onDismiss:()=>G(U.id),onIssueRaised:j,isIssueRaised:e,compact:t},`${U.id}-${e}`)})()]})},Q=({id:e,properties:s,validationErrors:r={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=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(x(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(()=>{""===b&&""!==o&&x(o)},[o]),n(()=>{d&&v(!0)},[d]),n(()=>{"test"!==u&&x("")},[u]);const C=l||a||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:[!g&&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:b,onChange:e=>{const t=e.target.value;N(t)},onFocus:()=>{h&&h()},onBlur:()=>{v(!0),p&&p()},placeholder:s.basic.placeholder,disabled:C,readOnly:a||s?.validation?.readonly,rows:w,className:`form-textarea ${!j(b).isValid&&y?"is-invalid":""} ${f}`.trim()}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(b),isTouched:y,mode:u})]})]})},ee=({id:e,properties:s,validationErrors:r={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=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(x(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(o)!==JSON.stringify(b)&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const w=l||a||s?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&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:b,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:()=>{v(!0),p&&p()},disabled:w,multiple:j,className:`form-select ${!N(b).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(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:N(b),isTouched:y,mode:u})]})]})},te=({id:e,properties:s,validationErrors:r={},formValue:o=[],readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(!1),y=Array.isArray(o)?o:[],v=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=v(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,v,y]),N=(e,t)=>{let n;n=t?[...y,e]:y.filter(t=>t!==e),j(n)},C=()=>{h&&h()},w=()=>{x(!0),p&&p()};n(()=>{b&&(c[e]=!0)},[b,e,c]),n(()=>{},[o,e,y]),n(()=>{d&&x(!0)},[d]);const S=l||a||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:!g&&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(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:v(y),isTouched:b,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(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:v(y),isTouched:b,mode:u})]})})})},ne=({id:e,properties:s,validationErrors:r={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=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(x(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=()=>{v(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{o!==b&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const k=l||a||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:!g&&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:b===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(b),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:b===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(b),isTouched:y,mode:u})]})})})},ie=({id:e,properties:s,validationErrors:r={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=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(x(t),v(!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=()=>{v(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{o!==b&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const S=()=>s?.basic?.inlineLayout?"inline-layout":"grid-layout",k=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},$=e=>{if(void 0!==e?.icon&&""!==e.icon)return e.icon;return"pass"===k(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"===k(e?.value||e)?"pass-button":"fail-button")},T=l||a||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:!g&&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=b===t.value,s=E(t,i),r=A(t),o=$(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:[o&&B.jsx("span",{className:"segment-icon",children:o}),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=b===t.value,s=E(t,i),r=A(t),o=$(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:[o&&B.jsx("span",{className:"segment-icon",children:o}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(b),isTouched:y,mode:u})]})},se=({id:e,properties:s,validationErrors:r={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const b=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 b(e.value);if("date"in e&&e.date)return b(e.date);try{const t=String(e),n=new Date(t);if(!isNaN(n.getTime()))return b(n)}catch(e){}return""}return""},[s]),x=b(o),[y,v]=t(x),[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"),o=e?String(e).trim():"";if(s?.validation?.required&&(!o||""===o))return t.required=!0,n=!1,{isValid:n,errors:t};if(o&&""!==o)if("time"===r){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(o))return t.invalidDate=!0,n=!1,{isValid:n,errors:t}}else if("datetime"===r){const e=new Date(o);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(o);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]),k=i(t=>{if(v(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=b(o);e===y||C||v(e)},[o,y,C,b]),n(()=>{d&&N(!0)},[d]);const $=l||a||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:[!g&&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;k(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:$,readOnly:a||s?.validation?.readonly,min:s?.validation?.minDate,max:s?.validation?.maxDate,className:`form-date ${!S(y).isValid&&j?"is-invalid":""} ${f}`.trim()}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:S(y),isTouched:j,mode:u})]})]})},re=({id:e,properties:r,validationErrors:o={},formValue:a="",readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="preview",onValueChange:p,onBlur:h,onFocus:f,className:g="",hideLabel:b=!1})=>{const x=s(null),[y,v]=t(!1),[j,N]=t(!1),[C,w]=t(a),[S,k]=t(!1),$=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=$(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};p(i)}},[e,p,$]),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=x.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 o=n.width,a=n.height,l=0,c=0;r>t?(a=n.width/r,c=(n.height-a)/2):(o=n.height*r,l=(n.width-o)/2),i.drawImage(s,l,c,o,a)},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=x.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=x.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,o=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(r-n.left)*i,y:(o-n.top)*s}},[]),D=e=>{if(l||c||r?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),v(!0),N(!0);const t=x.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:s}=R(e),o=A();n.strokeStyle=o.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=x.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;v(!1),k(!0);const e=x.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(()=>{k(!1)},100)}else k(!1)},O=i(()=>{const e=x.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(!(a===C||y||S||""!==C&&""===a)){if(a===C)return;w(a),a&&T(a)}},[a,C,y,S]),n(()=>{u&&N(!0)},[u]),n(()=>{if("test"!==m){w("");const e=x.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 z=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:[!b&&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:x,id:e,className:`form-signature ${!$(C).isValid&&j?"is-invalid":""} ${g}`.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:z?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!z&&B.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=x.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(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:$(C),isTouched:j,mode:m})]})]})},oe=({id:e,properties:r,validationErrors:o={},formValue:a=null,readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="test",onValueChange:p,onBlur:h,onFocus:f,className:g="",hideLabel:b=!1})=>{const[x,y]=t([]),[v,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,o=s.type||s.fileType||s.mimeType||"";let a;if(s.url)a=s.url;else if(s.data){const e=s.data;if("string"==typeof e)if(e.startsWith("data:"))a=e;else{const t=e.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>10){let e=o;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"),a=`data:${e};base64,${t}`}else a=e}}const l=new File([],t,{type:o});return void i.push({file:l,id:`${e}-file-${n}`,size:r,type:o,name:t,preview:a})}}let s,r,o=0,a="",l="";if(t instanceof File||t instanceof Blob){const e=t;if(o=e.size||0,a=e.type||"",l=e.name||`file-${n}`,r=e,a.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,""),o=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(o){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("?"),o=r>=0?s.substring(0,r):s;d=o&&o.includes(".")?decodeURIComponent(o):`file-${n+1}`}else d=`file-${n+1}`;if(l=d||`file-${n+1}`,c.startsWith("data:")){const e=c.indexOf(";");a=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){a={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 a=o?"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:a})}else{if(!t||"object"!=typeof t)return;{const e=t;if(l=e.name||e.fileName||`file-${n}`,o=e.size||e.fileSize||0,a=e.type||e.fileType||e.mimeType||"",e.url||e.path)s=e.url||e.path;else if(a.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:${a};base64,${e}`:t}else s=void 0}r=new File([],l,{type:a})}}i.push({file:r,id:`${e}-file-${n}`,size:o,type:a,name:l,preview:s})}),i},[e]),k=i(()=>({isValid:!0,errors:{}}),[]),$=i(t=>{if(l||c)return;const n=S(t),i=x.length>0?[...x,...n]:n,s=r?.validation?.maxFiles||1/0,o=i.slice(0,s);if(y(o),C(!0),p){const t=k(),n={id:e,value:o.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}},[x,r,l,c,p,k,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(a);null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==String(a).trim()||"object"==typeof a&&!Array.isArray(a)&&Object.keys(a).length>0)||0===x.length&&null!=a?y(e):(null==a||Array.isArray(a)&&0===a.length)&&x.length>0&&y([])},[a,S,x.length]),n(()=>{u&&C(!0)},[u]),n(()=>()=>{x.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[x]);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=x.length<D&&(I||D>1),F="edit"===m,O="preview"===m||"test"===m,z=x.filter(e=>e.type.startsWith("image/")),M=x.filter(e=>!e.type.startsWith("image/")),q=z.length>0;return O&&q?B.jsxs("div",{className:`form-group ${T()}`,children:[!b&&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:[z.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)),M.length>0&&B.jsxs("div",{className:"file-other-files",children:[B.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),M.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(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:k(),isTouched:N,mode:m})]})]}):B.jsxs("div",{className:`form-group ${T()}`,children:[!b&&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 ${v?"drag-over":""} ${l?"readonly":""} ${c?"disabled":""} ${g}`.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&&$(t)},onClick:e=>{const t=e.target,n=null!==t.closest(".file-item"),i=null!==t.closest(".file-remove");!F||L||0!==x.length||n||i||w.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(C(!0),"test"===m&&p){const t=k(),n={id:e,value:x.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&&($(t),e.target.value="")},disabled:L,style:{display:"none"}}),0===x.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:x.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=x.filter(e=>e.id!==t);if(y(n),C(!0),p){const t=k(),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))})]}),x.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(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:k(),isTouched:N,mode:m})]})]})},ae=({id:e,properties:r,validationErrors:o={},formValue:l=null,readonly:c=!1,disabled:d=!1,touchedFields:h={},formSubmitted:f=!1,mode:g="test",onValueChange:b,onBlur:x,onFocus:y,className:v="",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),[z,M]=t(""),[q,P]=t(!1),W=s(null),[_,U]=t(!1),[G,H]=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),z&&M(""),_&&(U(!1),H(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),b){b({id:e,value:r,isValid:!0,errors:{}})}},[X,e,b]),Q=i(async()=>{if(c||d)return;S(!0),$("");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 $("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 $("")}catch(e){return S(!1),void(e.message?.includes("permission")||e.message?.includes("denied")?$("Location permission is required. Please enable location access in your device settings."):e.message?.includes("timeout")?$("Location request timed out. Please try again."):$("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 $("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),$("")},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."}$(t)},e)},[c,d,r,Z]),ee=i(()=>{if(!c&&!d&&(C(null),V(null),$(""),A(!0),b)){b({id:e,value:null,isValid:!0,errors:{}})}},[c,d,e,b]),te=i(()=>{c||d||L(!T)},[c,d,T]),ne=i((e,t,n,i,s,r)=>{const o=e-s/2,a=t-r/2,l=156543.03392*Math.cos(n.lat*Math.PI/180)/Math.pow(2,i),c=o*l,d=a*l;return{lat:n.lat+d/111320,lng:n.lng+c/(111320*Math.cos(n.lat*Math.PI/180))}},[]),ie=i(e=>{c||d||!W.current||0===e.button&&(U(!0),H({x:e.clientX,y:e.clientY}),e.preventDefault())},[c,d]),se=i(e=>{if(!_||!G||!W.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}),H({x:e.clientX,y:e.clientY})},[_,G,I,F]),re=i(async e=>{if(!W.current)return;if(_&&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 H(null)}if(c||d)return U(!1),void H(null);const t=W.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),H(null)},[c,d,W,I,F,ne,Z,_,G]),oe=i(async t=>{if(t.trim()&&!c&&!d){P(!0),$("");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||{},o={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(o),V({lat:n,lng:s,isCurrentLocation:!1}),R({lat:n,lng:s}),A(!0),b){b({id:e,value:o,isValid:!0,errors:{}})}}else $("No locations found for your search.")}catch(e){$("Failed to search for location. Please try again.")}finally{P(!1)}}},[c,d,e,b]),ae=()=>{y&&y()},le=()=>{A(!0),x&&x()},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":""} ${v}`,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:ae,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:ae,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(a,{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(),z.trim()&&oe(z)},className:"search-form",children:B.jsxs("div",{className:"search-input-group",children:[B.jsx("input",{type:"text",value:z,onChange:e=>{M(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:ce||q}),B.jsx("button",{type:"submit",className:"search-btn",disabled:ce||q||!z.trim(),children:q?B.jsx(u,{size:16,className:"loading-spinner"}):"Search"})]})})}),B.jsxs("div",{ref:W,className:"location-map "+(_?"dragging":""),onMouseDown:ie,onMouseMove:se,onMouseUp:re,onMouseLeave:()=>{U(!1),H(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:_?"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..."})]})]}),k&&B.jsx("div",{className:"location-error",children:k})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:h,formSubmitted:f,properties:r,localValidation:{isValid:!0,errors:{}},isTouched:E,mode:g})]});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,o=()=>{const e={};return t?.styles?.fontSize&&(e.fontSize=t.styles.fontSize),t?.styles?.color&&(e.color=t.styles.color),e};return i?null:(()=>{const i={id:e,className:`form-heading h${s} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${n}`.trim(),style:o()};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:o="preview",formValue:a,onValueChange:l,className:c="",hideLabel:d=!1})=>{const[u,m]=t(""),[p,y]=t(r.validation?.listStyle||"numbers"),[v,j]=t("#000000"),N=s(null),C=s(null),w=s(!1),S="edit"===o,k=s({instructions:[],listStyle:"numbers",formValue:void 0}),$=s(o);n(()=>{let e=[],t="numbers";if(null!=a&&("object"==typeof a&&a.instructions?(Array.isArray(a.instructions)?e=a.instructions:"string"==typeof a.instructions&&(e=[a.instructions]),a.listStyle&&(t=a.listStyle)):Array.isArray(a)?e=a:"string"==typeof a&&(e=[a])),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(k.current.instructions)||t!==k.current.listStyle,i=o!==$.current,s=JSON.stringify(a)!==JSON.stringify(k.current.formValue),l=!k.current.formValue||Array.isArray(k.current.formValue)&&0===k.current.formValue.length||"string"==typeof k.current.formValue&&""===k.current.formValue.trim(),c=null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==a.trim()||"object"==typeof a&&Object.keys(a).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),k.current={instructions:e,listStyle:t,formValue:a},$.current=o}},[a,r.basic?.instructions,r.validation?.listStyle,o,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:v,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:v},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(g,{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(b,{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(x,{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&&e.type&&"string"==typeof e.type&&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&&e.type&&"string"==typeof e.type&&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?e.name:"Attachment"}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(a,{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?e.name:"Unknown File"}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(a,{size:14})})]})},t)})}):null},ue=({component:e,mode:r,formTemplateId:o,formValue:a,onNotesChange:l,onAttachmentChange:c,notes:u="",attachments:m=null,onThresholdActionCompletion:p,onThresholdIssueRaised:h,onBasicPropertyActionCompletion:f})=>{const[g,b]=t(u||""),[x,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(a),z=s(!1),M=s(!1);n(()=>{if(!z.current&&null!=u){const e="string"==typeof u?u:String(u||"");b(e),z.current=!0}},[u]),n(()=>{M.current||void 0===m||(S(m),M.current=!0)},[m]),n(()=>{if(z.current&&!k&&null!=u){const e="string"==typeof u?u:String(u||"");g&&""!==String(g||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==g&&b(e):b(e)}},[u,k,g]),n(()=>{M.current&&void 0!==m&&(!x||m&&m.length>0&&m!==x)&&S(m)},[m,x]),n(()=>{const t=["select","radio","checkbox","segment"].includes(e.name||"");if(t){const t=O.current,n=a;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),$(!1),V(!1);const e="string"==typeof u?u:String(u||"");e&&""!==e.trim()?b(e):b(""),m&&0!==m.length?S(m):S(null)}O.current=n}t||(O.current=a)},[a,e.name,u,m]);const q=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}},[]),P=i(()=>{if(!(null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length)))return[];const t=e.condition;if(!t||!t.conditions||0===t.conditions.length)return[];const n=[];if("checkbox"===e.name&&Array.isArray(a))a.forEach(e=>{const i=t.conditions.find(t=>q(t,e));i&&!n.find(e=>e.id===i.id)&&n.push(i)});else{const e=t.conditions.find(e=>q(e,a));e&&n.push(e)}return n},[e,a,q]),W=i(t=>{const n=t.target.value;b(n),l&&l(n);const i=P(),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,P,p,e,f]),_=i(()=>{if(l){const e="string"==typeof g?g:String(g||"");l(e),setTimeout(()=>{$(!1)},0)}else $(!1)},[g,l]),U=i(()=>{_()},[_]),G=i(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),_())},[_]),H=i(()=>{$(!0)},[]),J=i(()=>{$(!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);P().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,P,p,e,f]),Z=i(t=>{if(x){const n=x.filter((e,n)=>n!==t);if(0===n.length){S(null),c&&c(null);P().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)}},[x,c,P,p,e,f]),Q=i(()=>{L(!0);P().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)},[P,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){P().forEach(e=>{!0===e.enableRaiseIssue&&h&&h(e.id)})}else f&&f("issue",!0)},[e,f,P,h]);if("test"!==r)return null;const ie=["select","radio","checkbox","segment"].includes(e.name||""),se=e.basic?.options||e.options||[];let re=!1,oe=!1,ae=!1,le=!1,ce=null;const ue=null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length),me=e.condition,pe=me&&me.conditions&&me.conditions.length>0;if(pe&&ue)if("checkbox"===e.name&&Array.isArray(a)){const e=a;for(const t of e){const e=me.conditions.find(e=>q(e,t));e&&(re=re||!0===e.enableNotes,oe=oe||!0===e.enableAttachment,ae=ae||!0===e.enableRaiseIssue,le=le||!0===e.enableSendEmail)}}else if(ie){const e=me.conditions.find(e=>q(e,a));e&&(re=!0===e.enableNotes,oe=!0===e.enableAttachment,ae=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}else{const e=me.conditions.find(e=>q(e,a));e&&(re=!0===e.enableNotes,oe=!0===e.enableAttachment,ae=!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(a)?a:[a]).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,oe=oe||!0===t.enableAttachment,ae=ae||!0===t.enableRaiseIssue,le=le||!0===t.enableSendEmail,ce||(ce=t))}),re=re||n,oe=oe||i,ae=ae||s,le=le||r}else if(ce=se.find(e=>!(!e||!e.value)&&(e.value===a||(String(e.value)===String(a)||(e.label===a||String(e.label)===String(a))))),ce){const e=!0===ce.enableNotes,t=!0===ce.enableAttachment,o=!0===ce.enableRaiseIssue,a=!0===ce.enableSendEmail;re=e||n,oe=t||i,ae=o||s,le=a||r}else re=n,oe=i,ae=s,le=r;else re=n,oe=i,ae=s,le=r;else re=n,oe=i,ae=s,le=r}if(!(re||oe||ae||le))return null;const he=P(),fe=e.condition,ge=fe&&fe.conditions&&fe.conditions.length>0,be=!!ge&&he.some(e=>!0===e.enableNotes),xe=!!ge&&he.some(e=>!0===e.enableAttachment),ye=!!ge&&he.some(e=>!0===e.enableSendEmail),ve=!!ge&&he.some(e=>!0===e.enableRaiseIssue),je=String(g||"").trim().length>0,Ne=x&&x.length>0,Ce=x?x.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":""} ${be?"mandatory":""}`,onClick:H,title:"Add Notes",children:[B.jsx(d,{size:14,fill:je?"currentColor":"none"}),be&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),oe&&B.jsxs("button",{type:"button",className:`action-icon-button ${Ne?"active":""} ${xe?"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}),xe&&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(v,{size:14})}):B.jsx(j,{size:14,fill:T?"currentColor":"none"}),ye&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ae&&B.jsxs("button",{type:"button",className:`action-icon-button ${I?"active":""} ${ve?"mandatory":""}`,onClick:ee,title:"Raise an Issue",children:[B.jsx(N,{size:14,fill:I?"currentColor":"none"}),ve&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(je&&re||Ne&&oe)&&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})})]}),k&&re&&B.jsxs("div",{className:"notes-input-overlay",children:[B.jsx("textarea",{className:"action-notes-textarea",value:g,onChange:W,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:_,title:"Save notes (Ctrl+Enter)",children:"Save"}),B.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{$(!1)},title:"Cancel",children:"Cancel"})]})]}),D&&B.jsxs("div",{className:"actions-content",children:[!k&&je&&re&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",onClick:J,children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",g]})}),Ne&&oe&&B.jsx("div",{className:"attachments-section",children:B.jsx(de,{attachments:x,onRemove:Z})})]}),oe&&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:o||"",notes:g,attachments:x})]})},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:o=!1,isChildrenEditMode:a=!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:g,listeners:b,setNodeRef:x,transform:y,transition:v,isDragging:j,isSorting:N}=V({id:e.id,disabled:o||"edit"!==n}),C={transform:O.Transform.toString(y),transition:v,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:x,style:C,className:`form-component section-child ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""} ${a?"children-edit-active":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:[("edit"===n||a)&&B.jsx("div",{className:"child-drag-handle",...b,...g,onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:B.jsx(k,{size:14})}),B.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===n||a)&&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($,{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:o={},onValueChange:a,onSelect:l,isSelected:c=!1,className:d="",onSectionSelect:u,onChildSelect:m,onChildDelete:p,selectedChild:h,renderFormComponent:f,formTemplateId:g,onThresholdActionCompletion:b,onThresholdIssueRaised:x,onNotesChange:y,onAttachmentChange:v})=>{const[j,N]=t(s.basic.collapsed),[C,k]=t(!1),[$,E]=t(!1),[A,T]=t(s.basic.label),[L,V]=t(s.basic.description),[F,O]=t(s.children||[]),[z,M]=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:q,isOver:P}=I({id:`section-${e}`,disabled:"edit"!==r}),W=!("preview"!==r&&"test"!==r||s.children&&s.children.length>0),_=i(t=>{T(t),a?.({id:e,value:{...s,basic:{...s.basic,label:t}}})},[e,s,a]),U=i(t=>{V(t),a?.({id:e,value:{...s,basic:{...s.basic,description:t}}})},[e,s,a]),G=i(e=>{m?.(e)},[m]),H=i((e,t)=>{t.stopPropagation();const n=F.filter(t=>t.id!==e.id);O(n),p?.(e.id)},[p,F,e]),J=i(()=>{u?.(s),l?.()},[u,l,s]),Y=i(e=>{e.stopPropagation(),"edit"===r&&F.length>0&&M(!z)},[r,F.length,z]),K=i(t=>{t.stopPropagation(),N(!j),a?.({id:e,value:{...s,basic:{...s.basic,collapsed:!j}}})},[j,e,s,a]),X=f||i(e=>{const t=o[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:a,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,a,o]);if(W)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:q,className:`df-form-section ${c?"selected":""} ${P?"drag-over":""} ${d}`,style:ie,children:[B.jsxs("div",{className:"section-header "+(z?"children-edit-mode":""),onClick:J,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:()=>{k(!1),_(A)},onKeyDown:e=>{"Enter"===e.key&&(k(!1),_(A))},className:"section-title-input",autoFocus:!0}):B.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===r&&k(!0),style:{display:"inline",margin:0},children:A||"Untitled Section"})]})}),(L||"edit"===r)&&B.jsx("div",{className:"section-description",children:"edit"===r&&$?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 ${P?"drag-over":""} ${0===F.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&J()},children:B.jsx(R,{items:F.map(e=>e.id),strategy:D,children:0===F.length?B.jsxs("div",{className:"section-empty-state",onClick:J,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:P?"#3b82f6":"#374151"},children:P?"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:H,renderFormComponent:X,isChildrenEditMode:z,formData:o,formTemplateId:g,onNotesChange:y,onAttachmentChange:v,onThresholdActionCompletion:b,onThresholdIssueRaised:x},e.id))})})]})},ge=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:s,onComponentEdit:r,renderFormComponent:o,isOverlay:a=!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:g,listeners:b,setNodeRef:x,transform:y,transition:v,isDragging:j,isSorting:N}=V({id:e.id,disabled:a}),C={transform:O.Transform.toString(y),transition:v,opacity:j?.3:1,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:x,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",...b,...g,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(k,{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:[o(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($,{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})})]})]})},be=({gridComponents:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:r,selectedComponent:o,renderFormComponent:a,gridId:l,formData:c={},formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})=>{const{setNodeRef:f,isOver:g}=I({id:`grid-drop-zone-${l}`,disabled:"edit"!==t});return B.jsx("div",{ref:f,className:"grid-drop-zone",style:{border:g?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:g?"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(ge,{component:e,selectedComponent:o,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:r,renderFormComponent:a,formData:c,formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})},e.id))})}),B.jsx("div",{style:{border:g?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:g?"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:g?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:g?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:g?"Drop components here":"Empty DataGrid"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},xe=({templateComponents:e,dataEntries:t,renderFormComponent:n,renderComponent:i,mode:s="preview",allowAddRemoveEntries:r=!0,addAnotherText:o="Add Another",removeText:a="Remove",maxEntries:l=10,minEntries:c=1,displayAsGrid:d=!0,onAddEntry:u,onRemoveEntry:m,formData:p={},formTemplateId:h,onThresholdActionCompletion:f,onThresholdIssueRaised:g,onNotesChange:b,onAttachmentChange:x,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,o)=>B.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:o<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:o%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 a=s.components?.[r];const l=`${t.id||`component-${r}`}-entry-${y}-${o}-${r}`;return a=a?a.id!==l?{...a,id:l,basic:{...a.basic,showLabel:!1}}:{...a,id:a.id,basic:{...a.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(a,!0):n(a,!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(o)}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:a,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:"+"}),o]})})]}):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((o,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:a,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=o.components?.[t];const a=`${e.id||`component-${t}`}-entry-${y}-${l}-${t}`;return r||(r=o.components?.find(t=>t.name===e.name&&t.basic?.label===e.basic?.label)),r=r?r.id!==a?{...r,id:a,basic:{...r.basic,showLabel:!1}}:{...r,id:r.id,basic:{...r.basic,showLabel:!1}}:{...e,id:a,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:g,onNotesChange:b?e=>b(r.id,e):void 0,onAttachmentChange:x?e=>x(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)]})]},`${o.id}-${t}`)})})]},o.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:"+"}),o]})})]}),ye=({id:e,properties:r,mode:o="edit",formData:a={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onDataGridSelect:f,onComponentSelect:g,onComponentDelete:b,onComponentEdit:x,onComponentUpdate:y,selectedComponent:v,renderFormComponent:j,onEntryAdd:N,onEntryRemove:C,formTemplateId:k,onThresholdActionCompletion:$,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"===o&&!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,o]),n(()=>{if(V.length>0){if("test"===o&&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"!==o||!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"===o){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,o=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||o}))&&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,o,r.templateComponents]);const O=i(e=>{e.stopPropagation(),m?.(),f?.(r)},[m,f,r]),z=i((t,n)=>{n.stopPropagation(),b&&b(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}})},[b,r,u,e,V,F]),M=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]),q=i(e=>{"test"===o&&u&&u({id:e.id,value:e.value})},[u]),P=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]),W=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]),_=i((e,t=!1)=>{const n=a[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:o,hideLabel:t,onValueChange:q,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]})}},[o,q,a,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"===o?B.jsx(be,{gridComponents:V,mode:o,onComponentSelect:g||(()=>{}),onComponentDelete:z,onComponentEdit:x,onComponentUpdate:M,selectedComponent:v||null,renderFormComponent:j||_,gridId:e,formData:a,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:E,onNotesChange:T,onAttachmentChange:L}):B.jsx(xe,{templateComponents:V,dataEntries:F,renderFormComponent:j||_,mode:o,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||P,onRemoveEntry:C||W,formData:a,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:E,onNotesChange:T,onAttachmentChange:L,datagridId:e})})]})},ve=e.lazy(()=>Promise.resolve().then(function(){return Ee})),je=({formComponents:r=[],currentDevice:o="desktop",isPreviewMode:a=!1,initialFormData:l=[],onSubmit:c,onFormDataChange:d,formTitle:u,formDescription:m,formTemplateId:p,onComponentSelect:h,onComponentDelete:f,onComponentEdit:g,onComponentUpdate:b,selectedComponent:x,workOrderNumber:y,assetNumber:v})=>{const[j,N]=t({}),[C,w]=t({}),[S,k]=t(!1),[$,E]=t({}),[A,T]=t({}),[L,I]=t(new Set),[R,D]=t(new Map),[V,F]=t({isValid:!0}),[O,z]=t({}),[M,q]=t({});n(()=>{W()},[r,l]);const P=(e,t)=>{e.forEach(e=>{if(e.id&&(void 0!==t[e.id]||(e.basic&&"value"in e.basic&&void 0!==e.basic.value&&""!==e.basic.value&&null!==e.basic.value?t[e.id]=e.basic.value:e.basic&&"defaultValue"in e.basic&&void 0!==e.basic.defaultValue&&""!==e.basic.defaultValue&&null!==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)&&P(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&P(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(e.id&&e.basic&&e.basic.notes,"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)&&P(e.children,t)})},W=i(()=>{const e={},t={},n={},i=new Set,s=e=>{e.forEach(e=>{e.id&&((e.basic?.notes||e.basic?.comments)&&(t[e.id]=e.basic?.notes||e.basic?.comments),e.basic?.attachments&&(n[e.id]=e.basic.attachments)),e.children&&s(e.children),e.cells&&e.cells.forEach(e=>e.forEach(e=>{e.components&&s(e.components)})),e.entries&&e.entries.forEach(e=>{e.components&&s(e.components)})})},o=e=>{e.forEach((e,t)=>{if(e.id&&"string"==typeof e.id&&""!==e.id.trim())i.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}`));else{const n=e.name||"component",i=(e.basic?.label||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);e.id=`${n}-${i||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${t}`}i.add(e.id),e.children&&Array.isArray(e.children)&&o(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)&&o(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&o(e.components)})})};r&&r.length>0&&o(r),l&&l.length>0&&o(l),l&&l.length>0&&P(l,e),l&&l.length>0&&P(l,e),r&&r.length>0&&(P(r,e),s(r)),N(t=>({...e,...t})),z(e=>({...t,...e})),q(e=>({...n,...e})),U()},[l,r]),_=(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,j);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)&&_(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&_(e.components,t)}),e.children&&Array.isArray(e.children)&&_(e.children,t)})},U=i(()=>{const e={};r&&r.length>0&&_(r,e),T(e)},[r,j]),J=i(e=>{const t=r.find(t=>t.id===e);if(t&&("table"===t.name||"datagrid"===t.name))return!0;return!1!==A[e]},[A,r]),Y=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=j[e.id];void 0!==n&&n!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:n,newValue:e.value});const i={...j,[e.id]:e.value};N(i);const s=r.find(t=>t.id===e.id);if(s){const e=s?.threshold;e&&e.conditions&&e.conditions.length>0&&I(t=>{const n=new Set(t);return e.conditions.forEach(e=>{n.delete(e.id)}),n})}const o=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:o(t.children)}:"table"===t.name&&t.cells?{...t,cells:t.cells.map(e=>e.map(e=>{const t={...e};return t.components&&(t.components=o(t.components)),t}))}:"datagrid"===t.name&&t.entries?{...t,entries:t.entries.map(e=>{const t={...e};return t.components&&(t.components=o(t.components)),t})}:t),l=o(r);if(d?.(l),C[e.id]&&w(t=>({...t,[e.id]:""})),!a){if(e.isValid)return void w(t=>{const n=t[e.id];return n&&""!==n.trim()?{...t,[e.id]:""}:t});setTimeout(()=>{X(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}),T(e)},0)},[r,j,C,d]),K=i((e,t)=>{for(const n of e){if(n.id===t)return n;if("section"===n.name&&n.children){const e=K(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=K(n.components,t);if(e)return e}if("datagrid"===n.name&&n.entries)for(const e of n.entries)if(e.components){const n=K(e.components,t);if(n)return n}}return null},[]),X=i(e=>{if(a)return;const t=K(r,e);if(!t)return;const n=j[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`;w(t=>({...t,[e]:s}))}else w(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")}}w(t=>({...t,[e]:s}))},[r,a,j,K]),de=i(e=>{E(t=>({...t,[e]:!0})),a||setTimeout(()=>{X(e)},0)},[a,X]),me=i(e=>{C[e]&&w(t=>({...t,[e]:""}))},[C]),he=i(()=>!Object.values(C).some(e=>e&&"string"==typeof e&&""!==e.trim())&&r.every(e=>{const t=j[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,j,C]),ge=i((e,t)=>{if(Array.isArray(t))return t.some(t=>ge(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}},[]),be=i(()=>{if(a)return[];const e=[];return r.forEach(t=>{const n=t?.condition;if(!n||!n.conditions||0===n.conditions.length)return;const i=j[t.id];null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length)&&n.conditions.forEach(n=>{ge(n,i)&&e.push({componentId:t.id,condition:n,componentLabel:t.basic?.label||"Field"})})}),e},[r,j,a,ge]),xe=i(()=>{if(a)return{isValid:!0};const e=be();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:n}of e){const e=R.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},i=[];if(!0!==t.enableRaiseIssue||L.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}},[a,be,L,R]),je=i(e=>{e&&I(t=>{const n=new Set(t);return n.add(e),n})},[]),Ne=i((e,t,n)=>{e&&D(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(!a){const e=xe();F(e)}},[j,L,R,a,xe]);const Ce=i(()=>{if(a)return!0;let e=!0;k(!0);const t={};return r.forEach(n=>{const i=j[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=>({...e,[n.id]:!0}))}),w(t),e},[r,a,j]),we=i(()=>{if(k(!0),!Ce()){const e=r.find(e=>{const t=j[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=xe();if(!e.isValid){e.errorMessage&&H.showError(e.errorMessage);const t=be().find(({condition:e})=>!L.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=j[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,notes:void 0!==O[e.id]?O[e.id]:e.basic?.notes,comments:void 0!==O[e.id]?O[e.id]:e.basic?.comments||e.basic?.notes,attachments:void 0!==M[e.id]?M[e.id]:e.basic?.attachments}};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),i={...j};c?.(n,i)},[r,j,Ce,c,O,M]),Se=i(()=>({[`device-${o}`]:!0,readonly:a}),[o,a]),ke=s(new Map),$e=s(0),Ee=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=ke.current.get(s);r||($e.current+=1,r=`generated-${i}-${$e.current}-${Math.random().toString(36).substr(2,9)}`,ke.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=j[i];if(void 0!==s){const e=r.filter(e=>e.id!==i&&j[e.id]===s);e.length>0&&console.warn(`[DfFormPreview] Component ${i} shares form value with other components:`,e.map(e=>e.id))}const o={id:i,validationErrors:C,formValue:s,touchedFields:$,formSubmitted:S,mode:"test",readonly:!1,onValueChange:Y,onBlur:()=>de(i),onFocus:()=>me(i)};switch(t.name){case"text-input":case"number-input":case"email-input":return B.jsx(Z,{...o,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",formTemplateId:p,onThresholdIssueRaised:je,raisedThresholdIssues:L,workOrderNumber:y,assetNumber:v});case"textarea":return B.jsx(Q,{...o,properties:t});case"select":const n={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ee,{...o,properties:n});case"checkbox":const i={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(te,{...o,properties:i});case"radio":const a={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ne,{...o,properties:a});case"segment":const l={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ie,{...o,properties:l});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...o,properties:t});case"signature":return B.jsx(re,{...o,properties:t});case"heading":return B.jsx(le,{...o,properties:t});case"instructions":const c=s||t.basic?.value||null;return B.jsx(ce,{...o,properties:t,formValue:c});case"location":return B.jsx(ae,{...o,properties:t});case"section":return B.jsx(fe,{...o,properties:t,formData:j,formTemplateId:p,onThresholdActionCompletion:Ne,onThresholdIssueRaised:je,renderFormComponent:e=>Ee(e)});case"table":return B.jsx(e.Suspense,{fallback:B.jsx("div",{children:"Loading table..."}),children:B.jsx(ve,{...o,properties:t,formData:j,formTemplateId:p,mode:o.mode,validationErrors:C,touchedFields:$,formSubmitted:S,onThresholdActionCompletion:Ne,onThresholdIssueRaised:je,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=>Ee(e)})});case"datagrid":return B.jsx(ye,{...o,properties:t,formData:j,formTemplateId:p,mode:o.mode,validationErrors:C,touchedFields:$,formSubmitted:S,onThresholdActionCompletion:Ne,onThresholdIssueRaised:je,onComponentSelect:h,onComponentDelete:f,onComponentEdit:g,onComponentUpdate:b,selectedComponent:x,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!==j[e.id]);else{const t=e.basic?.defaultValue;void 0!==t&&N(n=>({...n,[e.id]:t}))}})})}else Y(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=j[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=>Ee(e)});case"file":const u=s||t.basic?.value||t.basic?.files||t.basic?.attachments||null;return B.jsx(oe,{...o,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(Se()).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(),we()},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=j[e.id],i=["select","radio","checkbox","segment"].includes(e.name||""),s=e.options||t?.options||[],o=(()=>{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(!a)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=a&&(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 ${o} ${l||c?"has-action-features":""}`,style:{display:J(e.id)?"block":"none"},children:[Ee(e),!a&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:a?"preview":"test",formTemplateId:p,formValue:n,onThresholdActionCompletion:Ne,onThresholdIssueRaised:je,onNotesChange:t=>{z(n=>({...n,[e.id]:t}));const n=r.map(n=>n.id===e.id?{...n,basic:{...n.basic,notes:t||""}}:n);d?.(n)},onAttachmentChange:t=>{q(n=>({...n,[e.id]:t||[]}));const n=r.map(n=>n.id===e.id?{...n,basic:{...n.basic,attachments:t||[]}}:n);d?.(n)},notes:void 0!==O[e.id]?O[e.id]:e.basic?.notes||"",attachments:void 0!==M[e.id]?M[e.id]:e.basic?.attachments||null}),a&&c&&B.jsx(pe,{component:e})]},e.id)}),!a&&B.jsx("div",{className:"form-actions",children:B.jsx("button",{type:"submit",disabled:!he()||!V.isValid,className:"form-submit-button",title:V.isValid?"":V.errorMessage,children:"Submit"})})]})]})})})},Ne=({comment:e="",onSave:s,placeholder:r="Enter your reason...",className:o="",disabled:a=!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&&!a&&(s(d),p(!1))},[m,s,d,a]),g=i(()=>{},[]),b=i(()=>{a||c(!l)},[l,a]);return B.jsxs("div",{className:`df-form-comments ${o}`,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:b,"aria-expanded":l,"aria-label":"Toggle comments section",disabled:a,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:g,placeholder:r,disabled:a})})})})]})},Ce=e=>e.id?e:{...e,id:z()},we=({component:e,mode:t,renderFormComponent:n,formData:i={},formTemplateId:s,onThresholdActionCompletion:r,onThresholdIssueRaised:o,onNotesChange:a,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:o,onNotesChange:a?t=>a(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:o,isOverlay:a=!1})=>{const{attributes:l,listeners:c,setNodeRef:d,transform:u,transition:m,isDragging:p,isSorting:h}=V({id:e.id,disabled:a}),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(k,{size:14})}),B.jsx("div",{className:"component-content",children:o(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($,{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})})]})]})},ke=({cell:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,selectedComponent:r,renderFormComponent:o,formData:a={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,tableId:u,onNotesChange:m,onAttachmentChange:p})=>{const h=`table-cell-${u}-${e.row}-${e.column}`,{setNodeRef:f,isOver:g}=I({id:h,disabled:"edit"!==t,data:{type:"table-cell",tableId:u,cell:e,row:e.row,column:e.column}}),b={...e.styles,backgroundColor:g?"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":g?"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:b,className:"table-cell "+(g?"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||z()),strategy:D,children:e.components.map(e=>{const a=Ce(e);return B.jsx(Se,{component:a,selectedComponent:r,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:s,renderFormComponent:o},a.id)})}):e.components.map(e=>{const n=e.id?e:Ce(e);return B.jsx(we,{component:n,mode:t,renderFormComponent:o,formData:a,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:" "})})})},$e=({id:e,properties:s,mode:o="edit",formData:a={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onTableSelect:f,onComponentSelect:g,onComponentDelete:b,onComponentEdit:x,selectedComponent:y,renderFormComponent:v,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,onNotesChange:k,onAttachmentChange:$})=>{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}})},[b,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=v||i(e=>{const t=e.id?e:Ce(e),n=a[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:o,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]})}},[v,o,a,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"===o||"test"===o?"separate":"collapse",tableLayout:"fixed",border:"preview"===o||"test"===o?"1px solid var(--df-color-fb-border)":"none"};return L||"preview"!==o?B.jsxs("div",{className:`form-group df-form-table ${p?"selected":""} ${"preview"===o?"preview-mode":"test"===o?"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"===o||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(ke,{cell:t,mode:o,onComponentSelect:g||(()=>{}),onComponentDelete:R,onComponentEdit:x,selectedComponent:y||null,renderFormComponent:V,formData:a,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,tableId:e,onNotesChange:k,onAttachmentChange:$},t.id))},n))})]})]})]}):null};var Ee=Object.freeze({__proto__:null,DfFormTable:$e,default:$e});const Ae={page:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',padding:"30px",backgroundColor:"#ffffff",color:"#000000",lineHeight:"1.4"},header:{marginBottom:"30px",paddingBottom:"15px",borderBottom:"2px solid #303992",display:"flex",justifyContent:"space-between",alignItems:"flex-end"},title:{margin:"0 0 5px 0",fontSize:"24px",fontWeight:"bold",color:"#303992"},description:{margin:"0",fontSize:"14px",color:"#666666"},submittedBy:{fontSize:"14px",color:"#333",textAlign:"right",whiteSpace:"nowrap",marginBottom:"2px"},formGroup:{marginBottom:"20px",breakInside:"avoid"},label:{fontWeight:"400",display:"block",marginBottom:"8px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",fontColor:"var(--df-color-text-dark)"},labelLeft:{fontWeight:"400",display:"block",marginRight:"10px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",width:"60%",fontColor:"var(--df-color-text-dark)"},valueContainer:{border:"1px solid #e2e8f0",borderRadius:"6px",padding:"8px 12px",backgroundColor:"#ffffff",minHeight:"20px",fontSize:"14px",flex:1},value:{fontSize:"14px",color:"#000000"},gridRow:{display:"flex",flexWrap:"wrap",gap:"16px",marginBottom:"20px"},gridCol:e=>({flex:`0 0 calc(${e/12*100}% - 8px)`,minWidth:"0"}),img:{maxWidth:"100%",maxHeight:"300px",border:"1px solid #ddd",borderRadius:"4px",display:"block",marginTop:"5px"},table:{width:"100%",borderCollapse:"collapse",border:"1px solid #ddd",marginTop:"10px",tableLayout:"fixed"},th:{border:"1px solid #ddd",padding:"8px",backgroundColor:"#f5f5f5",fontWeight:"bold",textAlign:"left",fontSize:"13px"},td:{border:"1px solid #ddd",padding:"8px",fontSize:"13px",verticalAlign:"top"},section:{marginBottom:"25px",breakInside:"avoid"},sectionHeader:{fontSize:"18px",marginBottom:"15px",display:"block",fontWeight:"600"},sectionChildren:{marginLeft:"20px",paddingLeft:"20px",borderLeft:"2px solid #3b82f6",marginTop:"15px"},notesSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",fontSize:"13px",boxSizing:"border-box"},notesLabel:{fontWeight:"bold",color:"#303992",marginRight:"5px"},attachmentsSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",display:"flex",flexWrap:"wrap",gap:"10px",boxSizing:"border-box"},attachmentThumbnail:{width:"60px",height:"60px",border:"1px solid #e5e7eb",borderRadius:"4px",overflow:"hidden",backgroundColor:"#fff",display:"flex",alignItems:"center",justifyContent:"center"},attachmentImg:{width:"100%",height:"100%",objectFit:"cover"},segmentContainer:{display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center"},segmentButton:{display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",borderRadius:"6px",border:"1px solid #e0e0e0",backgroundColor:"#ffffff",fontSize:"10px",fontWeight:600,minWidth:"30px",color:"#666"},segmentIcon:{marginRight:"4px",fontSize:"9px",fontWeight:"bold",display:"inline-block",lineHeight:"1"},checkboxItem:{display:"flex",alignItems:"center",padding:"10px 14px",backgroundColor:"#f8f9fa",borderRadius:"6px",marginBottom:"8px",width:"100%",boxSizing:"border-box"}},Te=e=>{if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.startsWith("data:image")||t.startsWith("iVBORw0KGgo")||t.startsWith("/9j/4AAQ")||t.startsWith("UklGR")||t.startsWith("R0lGOD")},Le=(e,t)=>{if(!e)return"";const n=e.trim();return n.startsWith("data:")||n.startsWith("http")||n.startsWith("blob:")||n.startsWith("/")?n:n.startsWith("iVBORw0KGgo")?`data:image/png;base64,${n}`:n.startsWith("/9j/4AAQ")?`data:image/jpeg;base64,${n}`:n.startsWith("UklGR")?`data:image/webp;base64,${n}`:n.startsWith("R0lGOD")?`data:image/gif;base64,${n}`:t&&t.startsWith("image/")?`data:${t};base64,${n}`:n},Ie=e=>{if(null!=e?.icon)return e.icon;return"pass"===(e=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"})(e?.value||e)?"✓":"×"},Re=({component:e})=>{const t=e.basic?.notes||"",n=e.basic?.attachments||[];return t.trim()||0!==n.length?B.jsxs("div",{style:{marginTop:"5px"},children:[t.trim().length>0&&B.jsxs("div",{style:Ae.notesSection,children:[B.jsx("span",{style:Ae.notesLabel,children:"Notes:"}),t]}),n.length>0&&B.jsx("div",{style:Ae.attachmentsSection,children:n.map((e,t)=>{const n=!(!e.data&&!e.url),i=(e.type?.startsWith("image/")||Te(e.data||e.url||""))&&n?Le(e.data||e.url||"",e.type):null;return B.jsx("div",{style:Ae.attachmentThumbnail,children:i?B.jsx("img",{src:i,alt:e.name||"Attachment",style:Ae.attachmentImg}):B.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},t)})})]}):null},De=({component:e})=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue,{name:n}=e;if("signature"===n)return t&&Te(t)?B.jsx("div",{style:{marginTop:"5px"},children:B.jsx("img",{src:Le(t),alt:"Signature",style:{...Ae.img,maxHeight:"100px",width:"auto"}})}):B.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===n){const n=e.basic?.options||[],i=Array.isArray(t)?t:[t];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:n.map((e,t)=>{const n=i.includes(e.value);return B.jsxs("div",{style:Ae.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(n?"#303992":"#cbd5e1"),borderRadius:"4px",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:n?"#303992":"#ffffff"},children:n&&B.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("radio"===n){const n=e.basic?.options||[];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:n.map((e,n)=>{const i=t===e.value;return B.jsxs("div",{style:Ae.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(i?"#303992":"#cbd5e1"),borderRadius:"50%",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#ffffff"},children:i&&B.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},n)})})}if("segment"===n){const n=e.basic?.options||[],i=t;return B.jsx("div",{style:Ae.segmentContainer,children:n.map((e,t)=>{const n=i===e.value,s=Ie(e),r=e.color||"#666";let o={...Ae.segmentButton};return o=n?{...o,backgroundColor:r,color:"#ffffff",borderColor:r}:{...o,backgroundColor:"#ffffff",color:r,borderColor:r},B.jsxs("div",{style:o,children:[B.jsx("span",{style:Ae.segmentIcon,children:s}),B.jsx("span",{children:e.value})]},t)})})}if("file"===n){const e=(Array.isArray(t)?t:t?[t]:[]).filter(e=>{const t=!(!e.data&&!e.url),n=e.type&&e.type.startsWith("image/"),i=t&&Te(e.data||e.url);return n||i});return e.length>0?B.jsx("div",{style:{marginTop:"10px"},children:e.map((e,t)=>{const n=Le(e.data||e.url,e.type);return n?B.jsx("img",{src:n,alt:e.name||"File",style:{...Ae.img,marginBottom:"10px"}},t):null})}):B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===n){if(t&&"object"==typeof t){const e=t;return B.jsxs("div",{style:{fontSize:"14px"},children:[e.placeName&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Place:"})," ",e.placeName]}),(e.city||e.country)&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Address:"})," ",[e.city,e.country].filter(Boolean).join(", ")]}),e.latitude&&e.longitude&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Coordinates:"})," ",e.latitude.toFixed(6),", ",e.longitude.toFixed(6)]}),e.timestamp&&B.jsxs("div",{children:[B.jsx("strong",{children:"Captured:"})," ",new Date(e.timestamp).toLocaleString()]})]})}return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===n){const t=e.basic?.instructions||[],n=e.validation?.listStyle||"numbers";if(!Array.isArray(t)||0===t.length)return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const i=()=>B.jsx("div",{dangerouslySetInnerHTML:{__html:t.join("")}});return"numbers"===n?B.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(i,{})}):"bullets"===n?B.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(i,{})}):B.jsx("div",{style:{margin:"10px 0"},children:B.jsx(i,{})})}const i="object"==typeof t?JSON.stringify(t):String(t);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid"].includes(n)){const e="textarea"===n;return B.jsx("div",{style:{...Ae.valueContainer,...e?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}},children:B.jsx("div",{style:Ae.value,children:i})})}return B.jsx("div",{style:Ae.value,children:i})},Ve=({component:e})=>{const{name:t,basic:n,styles:i,validation:s}=e,r=n?.label,o=s?.required,a="left"===(i?.labelAlignment||"top");if("section"===t){const t=i?.headerBackgroundColor,s=i?.headerTextColor,a={...Ae.sectionHeader,...t?{backgroundColor:t,padding:"8px",borderRadius:"4px"}:{},...s?{color:s}:{},display:"flex",alignItems:"center"};return B.jsxs("div",{style:Ae.section,children:[r&&B.jsx("label",{style:a,children:B.jsxs("span",{style:{flex:1},children:[r,o&&" *"]})}),n?.description&&B.jsx("p",{style:{...Ae.description,marginBottom:"15px"},children:n.description}),B.jsx(Re,{component:e}),B.jsx("div",{style:Ae.sectionChildren,children:B.jsx(Fe,{components:e.children||[]})})]})}if("heading"===t){const e=`h${Math.max(1,Math.min(6,i?.level??n?.level??1))}`,t={...i?.headerBackgroundColor?{backgroundColor:i.headerBackgroundColor,padding:"8px",borderRadius:"4px"}:{},...i?.headerTextColor?{color:i.headerTextColor}:{},...i?.fontSize?{fontSize:i.fontSize}:{},...i?.textAlign?{textAlign:i.textAlign}:{},marginTop:0,marginBottom:"15px"};return B.jsx("div",{style:Ae.formGroup,children:B.jsx(e,{style:t,children:n?.label||n?.value})})}if("table"===t){const t=e.cells||[],n=Math.max(0,...t.map(e=>e?e.length:0)),s=n>0?100/n:100,a=i?.headerBackgroundColor,l=i?.headerTextColor,c={...Ae.label,...a?{backgroundColor:a,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...l?{color:l}:{}};return B.jsxs("div",{style:Ae.formGroup,children:[r&&B.jsxs("label",{style:c,children:[r,o&&" *"]}),B.jsx("table",{style:Ae.table,children:B.jsx("tbody",{children:t.map((e,t)=>B.jsx("tr",{children:e&&e.map((e,t)=>B.jsx("td",{style:{...Ae.td,width:`${s}%`},children:e.components&&e.components.map((e,t)=>B.jsxs("div",{style:{marginBottom:"8px"},children:[e.basic?.label&&B.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[e.basic.label,":"]}),B.jsx(De,{component:e}),B.jsx(Re,{component:e})]},t))},t))},t))})})]})}if("datagrid"===t){const t=e.entries||[];let n=e.templateComponents||[];0===n.length&&t.length>0&&t[0]?.components&&(n=t[0].components.map(e=>({...e,basic:{...e.basic,label:e.basic?.label||e.name}})));const s=i?.headerBackgroundColor,a=i?.headerTextColor,l={...Ae.label,...s?{backgroundColor:s,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...a?{color:a}:{}},c=t.filter(e=>!(!e.components||0===e.components.length)&&e.components.some(e=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue;return Array.isArray(t)?t.length>0:null!=t&&""!==String(t).trim()}));return 0===c.length?B.jsxs("div",{style:Ae.formGroup,children:[r&&B.jsxs("label",{style:l,children:[r,o&&" *"]}),B.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):B.jsxs("div",{style:Ae.formGroup,children:[r&&B.jsxs("label",{style:l,children:[r,o&&" *"]}),B.jsxs("table",{style:Ae.table,children:[B.jsx("thead",{children:B.jsx("tr",{children:n.map((e,t)=>B.jsx("th",{style:Ae.th,children:e.basic?.label||e.name},t))})}),B.jsx("tbody",{children:c.map((e,t)=>B.jsx("tr",{children:n.map((t,n)=>{const i=e.components[n];return B.jsx("td",{style:Ae.td,children:i?B.jsxs(B.Fragment,{children:[B.jsx(De,{component:i}),B.jsx(Re,{component:i})]}):"N/A"},n)})},t))})]})]})}if(a&&"instructions"!==t){const n=["segment"].includes(t);return B.jsxs("div",{style:Ae.formGroup,children:[B.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[r&&B.jsxs("label",{style:Ae.labelLeft,children:[r,o&&" *"]}),B.jsx("div",{style:{flex:1,...n?{display:"flex",justifyContent:"flex-end"}:{}},children:B.jsx(De,{component:e})})]}),B.jsx(Re,{component:e})]})}return B.jsxs("div",{style:Ae.formGroup,children:[r&&B.jsxs("label",{style:Ae.label,children:[r,o&&" *"]}),B.jsx(De,{component:e}),B.jsx(Re,{component:e})]})},Fe=({components:e})=>{if(!e||0===e.length)return null;const t=[];let n=[],i=0;return e.forEach(e=>{const s=["section","table","datagrid","heading","instructions"].includes(e.name),r=s?12:e.styles?.column||12;i+r>12&&n.length>0&&(t.push(n),n=[],i=0),n.push(e),i+=r,(s||i>=12)&&i>0&&(t.push(n),n=[],i=0)}),n.length>0&&t.push(n),B.jsx(B.Fragment,{children:t.map((e,t)=>1===e.length?B.jsx(Ve,{component:e[0]},e[0].id||t):B.jsx("div",{style:Ae.gridRow,children:e.map((e,t)=>{const n=e.styles?.column||12;return B.jsx("div",{style:Ae.gridCol(n),children:B.jsx(Ve,{component:e})},e.id||t)})},t))})},Oe=({formTitle:e,formDescription:t,userName:n,components:i})=>B.jsxs("div",{className:"pdf-container",style:Ae.page,children:[B.jsxs("div",{style:Ae.header,children:[B.jsxs("div",{children:[B.jsx("h1",{style:Ae.title,children:e}),t&&B.jsx("p",{style:Ae.description,children:t})]}),n&&B.jsxs("div",{style:Ae.submittedBy,children:[B.jsx("strong",{children:"Submitted By:"})," ",n]})]}),B.jsx("div",{className:"form-content",children:B.jsx(Fe,{components:i})})]});var ze;!function(e){e.Top="top",e.Left="left"}(ze||(ze={}));export{ue as ComponentActionFeatures,pe as ComponentSubmissionActions,te as DfFormCheckbox,Ne as DfFormComments,ye as DfFormDataGrid,se as DfFormDateTime,J as DfFormErrorMsg,oe as DfFormFileUpload,le as DfFormHeading,Z as DfFormInput,ce as DfFormInstruction,ae as DfFormLocation,je as DfFormPreview,ne as DfFormRadio,fe as DfFormSection,ie as DfFormSegment,ee as DfFormSelect,re as DfFormSignature,$e as DfFormTable,Q as DfFormTextarea,ze as ELabelAlignment,Oe as FormSubmissionPdf,K as RaiseIssueModal,X as ThresholdAlert,G as conditionalLogicService,H as toastService};
|
|
10
|
+
*/"production"===process.env.NODE_ENV?q.exports=function(){if(M)return P;M=1;var t=e,i=Symbol.for("react.element"),n=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,n){var o,l={},c=null,d=null;for(o in void 0!==n&&(c=""+n),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:i,type:e,key:c,ref:d,props:l,_owner:r.current}}return P.Fragment=n,P.jsx=o,P.jsxs=o,P}():q.exports=(W||(W=1,"production"!==process.env.NODE_ENV&&function(){var t,i=e,n=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=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(e){for(var t=arguments.length,i=new Array(t>1?t-1:0),n=1;n<t;n++)i[n-1]=arguments[n];!function(e,t,i){var n=g.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(t+="%s",i=i.concat([n]));var s=i.map(function(e){return String(e)});s.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,s)}("error",e,i)}function y(e){return e.displayName||"Context"}function v(e){if(null==e)return null;if("number"==typeof e.tag&&x("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,i){var n=e.displayName;if(n)return n;var s=t.displayName||t.name||"";return""!==s?i+"("+s+")":i}(e,e.render,"ForwardRef");case p:var t=e.displayName||null;return null!==t?t:v(e.type)||"Memo";case h:var i=e,n=i._payload,f=i._init;try{return v(f(n))}catch(e){return null}}return null}t=Symbol.for("react.module.reference");var j,N,C,w,S,k,$,A=Object.assign,E=0;function T(){}T.__reactDisabledLog=!0;var L,I=g.ReactCurrentDispatcher;function R(e,t,i){if(void 0===L)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);L=n&&n[1]||""}return"\n"+L+e}var O,D=!1,V="function"==typeof WeakMap?WeakMap:Map;function F(e,t){if(!e||D)return"";var i,n=O.get(e);if(void 0!==n)return n;D=!0;var s,r=Error.prepareStackTrace;Error.prepareStackTrace=void 0,s=I.current,I.current=null,function(){if(0===E){j=console.log,N=console.info,C=console.warn,w=console.error,S=console.group,k=console.groupCollapsed,$=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})}E++}();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){i=e}Reflect.construct(e,[],a)}else{try{a.call()}catch(e){i=e}e.call(a.prototype)}}else{try{throw Error()}catch(e){i=e}e()}}catch(t){if(t&&i&&"string"==typeof t.stack){for(var o=t.stack.split("\n"),l=i.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&&O.set(e,u),u}}while(c>=1&&d>=0);break}}}finally{D=!1,I.current=s,function(){if(0===--E){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:A({},e,{value:j}),info:A({},e,{value:N}),warn:A({},e,{value:C}),error:A({},e,{value:w}),group:A({},e,{value:S}),groupCollapsed:A({},e,{value:k}),groupEnd:A({},e,{value:$})})}E<0&&x("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&&O.set(e,p),p}function z(e,t,i){if(null==e)return"";if("function"==typeof e)return F(e,!(!(n=e.prototype)||!n.isReactComponent));var n;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 F(e.render,!1);case p:return z(e.type,t,i);case h:var s=e,r=s._payload,a=s._init;try{return z(a(r),t,i)}catch(e){}}return""}O=new V;var M=Object.prototype.hasOwnProperty,q={},P=g.ReactDebugCurrentFrame;function W(e){if(e){var t=e._owner,i=z(e.type,e._source,t?t.type:null);P.setExtraStackFrame(i)}else P.setExtraStackFrame(null)}var B=Array.isArray;function U(e){return B(e)}function G(e){return""+e}function H(e){if(function(e){try{return G(e),!1}catch(e){return!0}}(e))return x("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 J,Y,K,X=g.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,i,s,r){var a,o={},l=null,c=null;for(a in void 0!==i&&(H(i),l=""+i),function(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(H(t.key),l=""+t.key),function(e){if(M.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 i=v(X.current.type);K[i]||(x('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',v(X.current.type),e.ref),K[i]=!0)}}(t,r)),t)M.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 i=function(){J||(J=!0,x("%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))};i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}(o,u),c&&function(e,t){var i=function(){Y||(Y=!0,x("%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))};i.isReactWarning=!0,Object.defineProperty(e,"ref",{get:i,configurable:!0})}(o,u)}return function(e,t,i,s,r,a,o){var l={$$typeof:n,type:e,key:t,ref:i,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,ie=g.ReactDebugCurrentFrame;function ne(e){if(e){var t=e._owner,i=z(e.type,e._source,t?t.type:null);ie.setExtraStackFrame(i)}else ie.setExtraStackFrame(null)}function se(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function re(){if(te.current){var e=v(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 i=function(e){var t=re();if(!t){var i="string"==typeof e?e:e.displayName||e.name;i&&(t="\n\nCheck the top-level render call using <"+i+">.")}return t}(t);if(!ae[i]){ae[i]=!0;var n="";e&&e._owner&&e._owner!==te.current&&(n=" It was passed a child from "+v(e._owner.type)+"."),ne(e),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',i,n),ne(null)}}}function le(e,t){if("object"==typeof e)if(U(e))for(var i=0;i<e.length;i++){var n=e[i];se(n)&&oe(n,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,i=e.type;if(null!=i&&"string"!=typeof i){if("function"==typeof i)t=i.propTypes;else{if("object"!=typeof i||i.$$typeof!==d&&i.$$typeof!==p)return;t=i.propTypes}if(t){var n=v(i);!function(e,t,i,n,s){var r=Function.call.bind(M);for(var a in e)if(r(e,a)){var o=void 0;try{if("function"!=typeof e[a]){var l=Error((n||"React class")+": "+i+" 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,n,i,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){o=e}!o||o instanceof Error||(W(s),x("%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).",n||"React class",i,a,typeof o),W(null)),o instanceof Error&&!(o.message in q)&&(q[o.message]=!0,W(s),x("Failed %s type: %s",i,o.message),W(null))}}(t,e.props,"prop",n,e)}else void 0===i.PropTypes||ee||(ee=!0,x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v(i)||"Unknown"));"function"!=typeof i.getDefaultProps||i.getDefaultProps.isReactClassApproved||x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var de={};function ue(e,i,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===n?(C="<"+(v(e.type)||"Unknown")+" />",N=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,x("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,i,s,g,y);if(null==S)return S;if(j){var k=i.children;if(void 0!==k)if(b)if(U(k)){for(var $=0;$<k.length;$++)le(k[$],e);Object.freeze&&Object.freeze(k)}else x("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(k,e)}if(M.call(i,"key")){var A=v(e),E=Object.keys(i).filter(function(e){return"key"!==e}),T=E.length>0?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}";de[A+T]||(x('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,A,E.length>0?"{"+E.join(": ..., ")+": ...}":"{}",A),de[A+T]=!0)}return e===r?function(e){for(var t=Object.keys(e.props),i=0;i<t.length;i++){var n=t[i];if("children"!==n&&"key"!==n){ne(e),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),ne(null);break}}null!==e.ref&&(ne(e),x("Invalid attribute `ref` supplied to `React.Fragment`."),ne(null))}(S):ce(S),S}var me=function(e,t,i){return ue(e,t,i,!1)},pe=function(e,t,i){return ue(e,t,i,!0)};_.Fragment=r,_.jsx=me,_.jsxs=pe}()),_);var B=q.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 i=[];return e?(["show","hide","always"].includes(e.action)||i.push("Invalid conditional action"),["all","any"].includes(e.when)||i.push("Invalid when condition"),e.conditions&&0!==e.conditions.length?e.conditions.forEach((e,n)=>{const s=t.find(t=>t.id===e.when);if(!s)return void i.push(`Condition ${n+1}: Component not found`);this.getApplicableOperators(s.name).includes(e.operator)||i.push(`Condition ${n+1}: Operator not applicable for component type`),this.isValidConditionValue(e.value,s.name,e.operator)||i.push(`Condition ${n+1}: Invalid condition value`)}):i.push("At least one condition is required"),{isValid:0===i.length,errors:i}):{isValid:!0,errors:[]}}evaluateConditionalLogic(e,t,i){if("always"===e.action)return{shouldShow:!0,evaluatedConditions:[]};if(!e||!e.conditions||0===e.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const n=e.conditions.map(e=>{const n=this.getComponentValue(e.when,t,i);return{condition:e,result:this.evaluateCondition(e,n),componentValue:n}});return{shouldShow:this.determineFinalResult(e,n),evaluatedConditions:n}}getComponentValue(e,t,i){if(i&&void 0!==i[e])return i[e];const n=t.find(t=>t.id===e);return n&&"defaultValue"in n.basic?n.basic.defaultValue:void 0}evaluateCondition(e,t){const{operator:i,value:n}=e;if("checked"===n||"notChecked"===n)return this.evaluateCheckboxCondition(t,n);switch(i){case"equals":return this.isEqual(t,n);case"notEquals":return!this.isEqual(t,n);case"isEmpty":return this.isEmpty(t);case"isNotEmpty":return!this.isEmpty(t);case"contains":return this.contains(t,n);case"notContains":return!this.contains(t,n);case"greaterThan":return this.isGreaterThan(t,n);case"lessThan":return this.isLessThan(t,n);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(t,n);case"lessThanOrEqual":return this.isLessThanOrEqual(t,n);default:return!1}}evaluateCheckboxCondition(e,t){const i=this.isCheckboxChecked(e);return"checked"===t?i:"notChecked"===t&&!i}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 i,n;return i="all"===e.when?t.every(e=>e.result):"any"===e.when&&t.some(e=>e.result),n="show"===e.action?i:"hide"===e.action?!i:(e.action,!0),n}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,i)=>this.isEqual(e,t[i]));if("object"==typeof e&&"object"==typeof t){const i=Object.keys(e),n=Object.keys(t);return i.length===n.length&&i.every(i=>this.isEqual(e[i],t[i]))}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 i=Number(e),n=Number(t);return!isNaN(i)&&!isNaN(n)&&i>n}isLessThan(e,t){const i=Number(e),n=Number(t);return!isNaN(i)&&!isNaN(n)&&i<n}isGreaterThanOrEqual(e,t){const i=Number(e),n=Number(t);return!isNaN(i)&&!isNaN(n)&&i>=n}isLessThanOrEqual(e,t){const i=Number(e),n=Number(t);return!isNaN(i)&&!isNaN(n)&&i<=n}isValidConditionValue(e,t,i){if(null==e)return["isEmpty","isNotEmpty"].includes(i);switch(t){case"number-input":return!isNaN(Number(e))||["isEmpty","isNotEmpty"].includes(i);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(e))||["isEmpty","isNotEmpty"].includes(i);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 i=this.getActionDisplayText(e.action),n=e.conditions.map(e=>{const i=t.find(t=>t.id===e.when);return`${i?.basic.label||"Unknown component"} ${this.getOperatorDisplayText(e.operator)} ${this.formatConditionValue(e.value)}`}),s="all"===e.when?" and ":" or ";return`${i} ${n.join(s)}`}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const G=U.getInstance();const H=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 i={id:this.generateId(),message:e,type:"success",duration:t};this.addToast(i)}showError(e,t=5e3){const i={id:this.generateId(),message:e,type:"danger",duration:t};this.addToast(i)}showWarning(e,t){const i={id:this.generateId(),message:e,type:"warning",duration:t};this.addToast(i)}showInfo(e,t){const i={id:this.generateId(),message:e,type:"info",duration:t};this.addToast(i)}show(e,t="success",i){const n={id:this.generateId(),message:e,type:t,duration:i};this.addToast(n)}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]}},J=({validationErrors:e,fieldId:t,touchedFields:i,formSubmitted:n,properties:s,localValidation:r,isTouched:a,mode:o})=>{const l=e=>{const t=s.basic.label||"This field",i=s.name||"",n=s.validation?.customValidationMessage;if("number-input"===i)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(n)return n;const 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,i=e?.lowerLimit;return`You are under the limit. ${t} must be at least ${i}`;case"upperLimit":const n=s.validation,a=n?.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||i[t]||n))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],i=s.name||"";return"pattern"===t&&"number-input"===i?"":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,i=e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||t||i?(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:n,onClose:s,onSuccess:r,component:p,formTemplateId:h,notes:f="",attachments:b=null,issue:g=null,onCreateIssue:x,onUpdateIssue:y,user:v,availableUsers:j=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:N,assetNumber:C,isStandalone:w})=>{const[S,k]=t(""),[$,A]=t(""),[E,T]=t(""),[I,R]=t(""),[O,D]=t("Medium"),[V,F]=t(Y.OPEN),[z,M]=t(""),[q,P]=t(""),[W,_]=t(!1),[U,G]=t(b||[]),J=e.useRef(null),K=!!g;i(()=>{b&&G(b)},[b]);i(()=>{if(n)if(g){k(g.title||""),A(g.description||""),T(g.workOrderNumber||""),R(g.assetNumber||""),D(g.priority||"Medium");const e=g.status||Y.OPEN,t=e===Y.OPEN||e===Y.IN_PROGRESS||e===Y.REJECTED||e===Y.RESOLVE?e:Y.OPEN;F(t),M(g.assignTo||g.assignee||""),P(g.comments||"")}else p&&(p.basic,k(""),A(""),P(f||""),N&&T(N),C&&R(C))},[n,p,f,g,N,C]);const X=e.useMemo(()=>{if(!S.trim())return!1;if(!$.trim())return!1;if(!V)return!1;if(!z)return!1;if(!w){if(!E.trim())return!1;if(!I.trim())return!1}return!0},[S,$,V,z,w,E,I]),Z=async e=>{if(g){_(!0);try{const t={title:String(S||"").trim(),description:String($||"").trim(),workOrderNumber:String(E||"").trim()||"",assetNumber:String(I||"").trim()||"",formTemplateId:g.formTemplateId||"",component:g.component||{},priority:O,assignee:String(z||"").trim()||void 0,status:e,comments:String(q||"").trim()||""};y&&g._id&&await y(g._id,t),F(e);const i={[Y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[Y.RESOLVE]:"Issue resolved successfully",[Y.REJECTED]:"Issue rejected"};H.showSuccess(i[e]||"Issue status updated successfully"),r&&r(),s()}catch(e){const t=e?.message||e?.error?.message||"Failed to update issue status. Please try again.";H.showError(t)}finally{_(!1)}}};if(!n)return null;const Q=B.jsx("div",{className:"raise-issue-modal-overlay",onClick:s,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:K?"Edit Issue":"Create Issue"})})]}),B.jsx("button",{className:"raise-issue-modal-close",onClick:s,"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:[K&&g?.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:g.issueNumber,readOnly:!0})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Task"}),B.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:K?g?.component?.basic?.label:p?.basic?.label||"",readOnly:!0})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Task Value"}),B.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:K?g?.component?.basic?.value:p?.basic?.value||"",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 "+(K?"raise-issue-field-readonly":""),value:S,onChange:e=>k(e.target.value),placeholder:"Enter issue title",readOnly:K})]}),!w&&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 "+(K?"raise-issue-field-readonly":""),value:E,onChange:e=>T(e.target.value),placeholder:"N/A",readOnly:K})]}),!w&&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 "+(K?"raise-issue-field-readonly":""),value:I,onChange:e=>R(e.target.value),placeholder:"Enter asset number",readOnly:K})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Raised By ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(l,{size:16}),B.jsx("span",{children:v&&`${v.firstName||""} ${v.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:K&&g?.createdAt?new Date(g.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 "+(K?"raise-issue-field-readonly":""),value:$,onChange:e=>A(e.target.value),placeholder:"Enter issue description",rows:4,readOnly:K})]}),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:"Attachments"})]}),B.jsxs("div",{className:"raise-issue-attachments-container",children:[U.length>0&&B.jsx("div",{className:"raise-issue-attachments-list",children:U.map((e,t)=>B.jsxs("div",{className:"raise-issue-attachment-item",children:[B.jsxs("div",{style:{display:"flex",alignItems:"center",overflow:"hidden",flex:1},children:[B.jsx("span",{className:"attachment-name",children:e.name}),B.jsxs("span",{className:"attachment-size",children:[(e.size/1024).toFixed(1)," KB"]})]}),!K&&B.jsx("button",{type:"button",className:"attachment-remove-btn",onClick:()=>(e=>{G(t=>t.filter((t,i)=>i!==e))})(t),children:B.jsx(u,{size:14})})]},t))}),!K&&B.jsxs("div",{className:"raise-issue-add-attachment",children:[B.jsx("input",{type:"file",ref:J,onChange:e=>{if(e.target.files&&e.target.files.length>0){const t=Array.from(e.target.files);G(e=>[...e,...t]),J.current&&(J.current.value="")}},multiple:!0,style:{display:"none"}}),B.jsxs("button",{type:"button",className:"add-attachment-btn",onClick:()=>J.current?.click(),children:[B.jsx(d,{size:14}),"Add Attachment"]})]})]})]}),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 "+(K?"":"raise-issue-field-readonly"),value:V,onChange:e=>F(e.target.value),disabled:!K,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:["Assign to ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select",value:z,onChange:e=>M(e.target.value),children:[B.jsx("option",{value:"",children:"Unassigned"}),j.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"===O?"active":""),onClick:()=>D("Low"),children:"Low"}),B.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===O?"active":""),onClick:()=>D("Medium"),children:"Medium"}),B.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===O?"active":""),onClick:()=>D("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(m,{size:16}),B.jsx("span",{children:"Comments"})]}),!q&&B.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),B.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(K?"raise-issue-field-readonly":""),value:q,onChange:e=>P(e.target.value),placeholder:"Add a comment...",rows:4,readOnly:K})]})]})}),B.jsx("div",{className:"raise-issue-modal-actions",children:B.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[K&&g&&B.jsxs(B.Fragment,{children:[V===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:async()=>{await Z(Y.IN_PROGRESS)},disabled:W,children:W?"Processing...":"Accept"}),V===Y.IN_PROGRESS&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:async()=>{await Z(Y.RESOLVE)},disabled:W,children:W?"Processing...":"Resolve"}),V===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:async()=>{await Z(Y.REJECTED)},disabled:W,children:W?"Processing...":"Reject"})]}),!K&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save "+(X?"":"disabled"),onClick:async()=>{if(String(S||"").trim())if(String($||"").trim())if(w||String(E||"").trim())if(w||String(I||"").trim())if(String(z||"").trim()){_(!0);try{if(K&&g){const e={title:String(S||"").trim(),description:String($||"").trim(),workOrderNumber:String(E||"").trim()||"",assetNumber:String(I||"").trim()||void 0,formTemplateId:g.formTemplateId||"",component:g.component||{},priority:O,assignTo:String(z||"").trim()||void 0,status:V,comments:String(q||"").trim()||"",task:g.component?.basic?.label||"",taskValue:g.component?.basic?.value||""};y&&g._id&&await y(g._id,e),H.showSuccess("Issue updated successfully"),r&&r(),s()}else{if(!p)return H.showError("Component is required"),void _(!1);if(!h||""===String(h||"").trim())return H.showError("Form template is required"),void _(!1);const e={...p,basic:{...p.basic,comments:String(f||"")}},t=v?`${v.firstName||""} ${v.lastName||""}`.trim():"User",i={title:String(S||"").trim(),workOrderNumber:String(E||"").trim()||void 0,assetNumber:String(I||"").trim()||void 0,component:e,description:String($||"").trim(),formTemplateId:h,assignTo:String(z||"").trim()||void 0,priority:O,status:V,comments:String(q||"").trim()||"",createdBy:t,task:p?.basic?.label||"",taskValue:p?.basic?.value||""};let n;x&&(n=await x(i,U)),H.showSuccess("Issue raised successfully"),r&&r(n),s()}}catch(e){const t=e?.message||e?.error?.message||(K?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");H.showError(t)}finally{_(!1)}}else H.showError("Assignee is required");else H.showError("Asset Number is required");else H.showError("Work Order is required");else H.showError("Description is required");else H.showError("Title is required")},disabled:W||!X,children:W?K?"Saving...":"Creating...":K?"Save Changes":"Create Issue"})]})})]})});return L(Q,document.body)},X=({component:e,condition:s,currentValue:r,thresholdValue:o,formTemplateId:l,workOrderNumber:c,assetNumber:d,user:u,onIssueRaised:m,isIssueRaised:p=!1,compact:h=!1})=>{const[f,b]=t(!1),[g,x]=t(null),[y,v]=t(!1),[j,N]=t(!1);i(()=>{p&&N(!0)},[p]),i(()=>{N(!1)},[s?.id]);const C=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),w=n(async()=>{if(p||j){if(g)return void b(!0);v(!0);try{x(null),b(!0)}catch(e){console.error("Error fetching issue:",e),H.showError("Failed to load issue details")}finally{v(!1)}}else x(null),b(!0)},[p,j,l,e,g]),S=n(()=>{b(!1),p||j||x(null)},[p,j]),k=n(e=>{b(!1),x(e||null),N(!0),m&&s?.id&&m(s.id)},[m,s]);return p||j?B.jsx(B.Fragment,{children:f&&B.jsx(K,{isOpen:f,onClose:S,onSuccess:k,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,user:u,notes:"",attachments:null,issue:g})}):h?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 ${C(s.operator)} ${o}`}),B.jsx("button",{type:"button",onClick:w,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),f&&B.jsx(K,{isOpen:f,onClose:S,onSuccess:k,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,user:u,notes:"",attachments:null,issue:g})]}):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=C(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:w,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),f&&B.jsx(K,{isOpen:f,onClose:S,onSuccess:k,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,user:u,notes:"",attachments:null,issue:g})]})},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:x="",hideLabel:y=!1,formTemplateId:v,onThresholdIssueRaised:j,raisedThresholdIssues:N=new Set,workOrderNumber:C,assetNumber:w,user:S})=>{const k=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?k(e.value):"label"in e?k(e.label):"":String(e||""),$=s(e),A=s(null);i(()=>{e!==$.current&&(console.warn(`[DfFormInput] Component ID changed from ${$.current} to ${e}`),$.current=e)},[e]);const E=k(l||a?.basic?.defaultValue||""),[T,L]=t(E),[I,R]=t(!1),[O,D]=t(!1),[V,F]=t(new Set),[z,M]=t(E),q=()=>{if(c)return c;const e=a?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},P=n(e=>{const t=(()=>{const e={};if(a?.validation?.required&&(e.required=!0),"email"===q()&&(e.email=!0),"text"===q()){const t=a.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===q()){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})(),i={};let n=!0;const s="string"==typeof e?e:null!=e?String(e):"";if(!t.required||s&&""!==s.trim()||(i.required=!0,n=!1),t.email&&s&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(s)&&(i.email=!0,n=!1),t.minLength&&s&&s.length<t.minLength&&(i.minLength=!0,n=!1),t.maxLength&&s&&s.length>t.maxLength&&(i.maxLength=!0,n=!1),"number"===q())if(delete i.pattern,delete i.min,delete i.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&&(i.lowerLimit=!0,n=!1),"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&r>t.upperLimit&&(i.upperLimit=!0,n=!1))}else delete i.lowerLimit,delete i.upperLimit;return{isValid:n,errors:i}},[a,q]),W=n(t=>{const i="string"==typeof t?t:null!=t?String(t):"";if(L(i),f){const t=P(i),n=$.current,s={id:n,value:i,isValid:t.isValid,errors:t.errors};n!==e&&console.error(`[DfFormInput] ID mismatch in handleValueChange! ref: ${n}, prop: ${e}`),f(s)}},[e,f,P,$]);i(()=>{I&&(m[e]=!0)},[I,e,m]),i(()=>{if("edit"===h){R(!1);L(a?.basic?.defaultValue||"")}else"test"===h&&(R(!1),L(""))},[h,a?.basic?.defaultValue]),i(()=>{const t=$.current,i=k(l||a?.basic?.defaultValue||"");i===T||O||""===i&&""!==String(T||"").trim()?""===i&&String(T||"").trim():null!=l&&(t===e?L(i):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${t}, prop id: ${e}`))},[l,T,O,a?.basic?.defaultValue,e]),i(()=>{p&&R(!0)},[p]),i(()=>{"test"!==h&&L("")},[h]);const _=n((e,t)=>{if(!t||""===t)return!1;const i="string"==typeof t?parseFloat(t):t,n="string"==typeof e.value?parseFloat(e.value):e.value;if(isNaN(i)||isNaN(n))return!1;switch(e.operator){case"greaterThan":return i>n;case"lessThan":return i<n;case"greaterThanOrEqual":return i>=n;case"lessThanOrEqual":return i<=n;case"equals":return i===n;case"notEquals":return i!==n;default:return!1}},[]),U=r(()=>a?.condition?.conditions||[],[a?.condition]);i(()=>{T!==z&&(F(new Set),M(T))},[T,z]);const G=r(()=>{if("test"!==h||!T||""===T)return null;const e=U.filter(e=>_(e,T));if(0===e.length)return null;for(const t of e)if(!V.has(t.id))return t;return null},[T,U,V,h,_,N]),H=n(e=>{F(t=>new Set(t).add(e))},[]),Y=q(),K=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:A,children:[B.jsx("input",{type:Y,id:e,value:T,onChange:e=>{const t=e.target.value;W(t)},onFocus:()=>{D(!0),g&&g()},onBlur:()=>{if(D(!1),R(!0),"test"===h&&f){const t="string"==typeof T?T:null!=T?String(T):"",i=P(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};f(n)}b&&b()},placeholder:a.basic.placeholder,disabled:K,readOnly:d||a?.validation?.readonly,className:(()=>{const t="form-control";if("test"===h){const i="string"==typeof T?T:null!=T?String(T):"",n=P(i);if(n.isValid)return`${t} ${x}`.trim();const s=!n.isValid&&I,r=o[e]&&(I||p)&&!n;return`${t} ${s||r?"is-invalid":""} ${x}`.trim()}return`${t} ${x}`.trim()})()}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:m,formSubmitted:p,properties:a,localValidation:P(T),isTouched:I,mode:h})]})]}),G&&"test"===h&&(()=>{const e=N?.has(G.id)||!1,t=null!==A.current?.closest(".table-cell")||null!==A.current?.closest(".cell-content")||null!==A.current?.closest(".datagrid-table-view")||null!==A.current?.closest(".datagrid-list-view")||x.includes("table-cell")||x.includes("cell-content");return B.jsx(X,{component:a,condition:G,currentValue:T,thresholdValue:G.value,formTemplateId:v,workOrderNumber:C,assetNumber:w,user:S,onDismiss:()=>H(G.id),onIssueRaised:j,isIssueRaised:e,compact:t},`${G.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,x]=t(a),[y,v]=t(!1),j=n(e=>{const t={};let i=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1),s?.validation?.minLength&&e&&e.length<s.validation.minLength&&(t.minLength=!0,i=!1),s?.validation?.maxLength&&e&&e.length>s.validation.maxLength&&(t.maxLength=!0,i=!1),{isValid:i,errors:t}},[s]),N=n(t=>{if(x(t),m){const i=j(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};m(n)}},[e,m,j]);i(()=>{y&&(c[e]=!0)},[y,e,c]),i(()=>{""===g&&""!==a&&x(a)},[a]),i(()=>{d&&v(!0)},[d]),i(()=>{"test"!==u&&x("")},[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:()=>{v(!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(J,{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,x]=t(a),[y,v]=t(!1),j=s?.validation?.multiple||!1,N=n(e=>{const t={};let i=!0;return s?.validation?.required&&(j?Array.isArray(e)&&0!==e.length||(t.required=!0,i=!1):(!e||"string"==typeof e&&""===e.trim())&&(t.required=!0,i=!1)),{isValid:i,errors:t}},[s,j]),C=n(t=>{if(x(t),m){const i=N(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};m(n)}},[e,m,N]);i(()=>{y&&(c[e]=!0)},[y,e,c]),i(()=>{JSON.stringify(a)!==JSON.stringify(g)&&x(a)},[a,g]),i(()=>{d&&v(!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:()=>{v(!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(J,{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,x]=t(!1),y=Array.isArray(a)?a:[],v=n(e=>{const t={};let i=!0;return s?.validation?.required&&0===e.length&&(t.required=!0,i=!1),{isValid:i,errors:t}},[s]),j=n(t=>{if(m){const i=v(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};m(n)}},[e,m,v,y]),N=(e,t)=>{let i;i=t?[...y,e]:y.filter(t=>t!==e),j(i)},C=()=>{h&&h()},w=()=>{x(!0),p&&p()};i(()=>{g&&(c[e]=!0)},[g,e,c]),i(()=>{},[a,e,y]),i(()=>{d&&x(!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,i)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${i}`,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}-${i}`,className:"form-check-label",children:t.label})]},i))}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:v(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,i)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${i}`,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}-${i}`,className:"form-check-label",children:t.label})]},i))}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:v(y),isTouched:g,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,x]=t(a),[y,v]=t(!1),j=n(e=>{const t={};let i=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1),{isValid:i,errors:t}},[s]),N=n(t=>{if(x(t),m){const i=j(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};m(n)}},[e,m,j]),C=e=>{N(e)},w=()=>{h&&h()},S=()=>{v(!0),p&&p()};i(()=>{y&&(c[e]=!0)},[y,e,c]),i(()=>{a!==g&&x(a)},[a,g]),i(()=>{d&&v(!0)},[d]);const k=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,i)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${i}`,name:e,value:t.value,checked:g===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${i}`,className:"form-check-label",children:t.label})]},i))}),B.jsx(J,{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,i)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${i}`,name:e,value:t.value,checked:g===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${i}`,className:"form-check-label",children:t.label})]},i))}),B.jsx(J,{validationErrors:r,fieldId:e,touchedFields:c,formSubmitted:d,properties:s,localValidation:j(g),isTouched:y,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,x]=t(a),[y,v]=t(!1),j=n(e=>{const t={};let i=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1),{isValid:i,errors:t}},[s]),N=n(t=>{if(x(t),v(!0),m){const i=j(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};m(n)}},[e,m,j]),C=()=>{h&&h()},w=()=>{v(!0),p&&p()};i(()=>{y&&(c[e]=!0)},[y,e,c]),i(()=>{a!==g&&x(a)},[a,g]),i(()=>{d&&v(!0)},[d]);const S=()=>s?.basic?.inlineLayout?"inline-layout":"grid-layout",k=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},$=e=>{if(void 0!==e?.icon&&""!==e.icon)return e.icon;return"pass"===k(e?.value||e)?"✓":"×"},A=(e,t)=>e?.color||e?.backgroundColor?{color:t?"#ffffff":e.color||"#00814b",backgroundColor:t?e.color||"#00814b":e.backgroundColor||"#34bd4914",borderColor:e.color||"#00814b"}:{},E=e=>{if(e?.color||e?.backgroundColor)return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===k(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,i)=>{const n=g===t.value,s=A(t,n),r=E(t),a=$(t);return B.jsxs("div",{className:"form-segment-option "+(n?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${i}`,name:e,value:t.value,checked:n,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_${i}`,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})]})]},i)})})})]}):B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(s.options||[]).map((t,i)=>{const n=g===t.value,s=A(t,n),r=E(t),a=$(t);return B.jsxs("div",{className:"form-segment-option "+(n?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${i}`,name:e,value:t.value,checked:n,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_${i}`,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})]})]},i)})})})}),B.jsx(J,{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=n(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||"",i=s.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("datetime"===i){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"===i){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||"",i=s.basic?.dateTimeMode||("datetime-picker"===t?"datetime":"date");if("datetime"===i){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"===i){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),i=new Date(t);if(!isNaN(i.getTime()))return g(i)}catch(e){}return""}return""},[s]),x=g(a),[y,v]=t(x),[j,N]=t(!1),[C,w]=t(!1),S=n(e=>{const t={};let i=!0;const n=s.name||"",r=s.basic?.dateTimeMode||("datetime-picker"===n?"datetime":"date"),a=e?String(e).trim():"";if(s?.validation?.required&&(!a||""===a))return t.required=!0,i=!1,{isValid:i,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,i=!1,{isValid:i,errors:t}}else if("datetime"===r){const e=new Date(a);if(isNaN(e.getTime()))return t.invalidDate=!0,i=!1,{isValid:i,errors:t};if(s?.validation?.minDate){const n=new Date(s.validation.minDate);e<n&&(t.minDate=!0,t.minDateMessage=`Date and time must be on or after ${n.toLocaleDateString()}`,i=!1)}if(s?.validation?.maxDate){const n=new Date(s.validation.maxDate);e>n&&(t.maxDate=!0,t.maxDateMessage=`Date and time must be on or before ${n.toLocaleDateString()}`,i=!1)}}else{const e=new Date(a);if(isNaN(e.getTime()))return t.invalidDate=!0,i=!1,{isValid:i,errors:t};if(s?.validation?.minDate){const n=new Date(s.validation.minDate);e<n&&(t.minDate=!0,t.minDateMessage=`Date must be on or after ${n.toLocaleDateString()}`,i=!1)}if(s?.validation?.maxDate){const n=new Date(s.validation.maxDate);e>n&&(t.maxDate=!0,t.maxDateMessage=`Date must be on or before ${n.toLocaleDateString()}`,i=!1)}}return{isValid:i,errors:t}},[s]),k=n(t=>{if(v(t),m){const i=S(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};m(n)}},[e,m,S]);i(()=>{j&&(c[e]=!0)},[j,e,c]),i(()=>{const e=g(a);e===y||C||v(e)},[a,y,C,g]),i(()=>{d&&N(!0)},[d]);const $=l||o||s?.validation?.readonly,A=s.name||"",E=s.basic?.dateTimeMode||("datetime-picker"===A?"datetime":"date"),T=(()=>{switch(E){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;k(t)},onFocus:()=>{w(!0),h&&h()},onBlur:()=>{if(w(!1),N(!0),m){const t=S(y),i={id:e,value:y,isValid:t.isValid,errors:t.errors};m(i)}p&&p()},disabled:$,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(J,{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 x=s(null),[y,v]=t(!1),[j,N]=t(!1),[C,w]=t(o),[S,k]=t(!1),$=n(e=>{const t={};let i=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,i=!1),{isValid:i,errors:t}},[r]),A=n(t=>{if(w(t),p){const i=$(t),n={id:e,value:t,isValid:i.isValid,errors:i.errors};p(n)}},[e,p,$]),E=n(()=>{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=n(t=>{if(!t)return;const i=x.current;if(!i)return;const n=i.getContext("2d");if(!n)return;const s=new Image;s.onload=()=>{n.clearRect(0,0,i.width,i.height);const e=E();n.fillStyle=e.backgroundColor,n.fillRect(0,0,i.width,i.height);const t=i.width/i.height,r=s.width/s.height;let a=i.width,o=i.height,l=0,c=0;r>t?(o=i.width/r,c=(i.height-o)/2):(a=i.height*r,l=(i.width-a)/2),n.drawImage(s,l,c,a,o)},s.onerror=i=>{console.error("DfFormSignature: error loading image",{id:e,error:i,dataURL:t.substring(0,50)+"..."})},s.src=t},[E,e]),L=n(()=>{const e=x.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const i=e.getBoundingClientRect();e.width=i.width,e.height=i.height,e.style.width=i.width+"px",e.style.height=i.height+"px";const n=E();t.strokeStyle=n.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?T(C):(t.fillStyle=n.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,E,T]),I=n(()=>{setTimeout(()=>{L()},100)},[L]);i(()=>{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=n(e=>{const t=x.current;if(!t)return{x:0,y:0};const i=t.getBoundingClientRect(),n=t.width/i.width,s=t.height/i.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-i.left)*n,y:(a-i.top)*s}},[]),O=e=>{if(l||c||r?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),v(!0),N(!0);const t=x.current;if(!t)return;const i=t.getContext("2d");if(!i)return;const{x:n,y:s}=R(e),a=E();i.strokeStyle=a.strokeColor,i.lineWidth=2,i.lineCap="round",i.lineJoin="round",i.beginPath(),i.moveTo(n,s)},D=e=>{if(!y)return;e.preventDefault(),e.stopPropagation();const t=x.current;if(!t)return;const i=t.getContext("2d");if(!i)return;const{x:n,y:s}=R(e);i.lineTo(n,s),i.stroke()},V=()=>{if(!y)return;v(!1),k(!0);const e=x.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const i=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<i.length;e+=4){const t=i[e],n=i[e+1],s=i[e+2];if(i[e+3]>0&&(t<255||n<255||s<255))return!0}})(e);const t=e.toDataURL("image/png");w(t),A(t),setTimeout(()=>{k(!1)},100)}else k(!1)},F=n(()=>{const e=x.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const i=E();if(t.strokeStyle=i.strokeColor,C){const n=C,s=e.getBoundingClientRect();t.fillStyle=i.backgroundColor,t.fillRect(0,0,s.width,s.height),n&&T(n)}else{const n=e.getBoundingClientRect();t.fillStyle=i.backgroundColor,t.fillRect(0,0,n.width,n.height)}},[E,C,T]);i(()=>{const e=new MutationObserver(e=>{e.forEach(e=>{"attributes"!==e.type||"class"!==e.attributeName&&"data-theme"!==e.attributeName||F()})});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{e.disconnect()}},[F]);i(()=>{j&&(d[e]=!0)},[j,e,d]),i(()=>{if(!(o===C||y||S||""!==C&&""===o)){if(o===C)return;w(o),o&&T(o)}},[o,C,y,S]),i(()=>{u&&N(!0)},[u]),i(()=>{if("test"!==m){w("");const e=x.current;if(e){const t=e.getContext("2d");if(t){const i=e.getBoundingClientRect();e.width=i.width,e.height=i.height;const n=E();t.fillStyle=n.backgroundColor,t.fillRect(0,0,i.width,i.height)}}}},[m]),i(()=>{L()},[m]);const z=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:x,id:e,className:`form-signature ${!$(C).isValid&&j?"is-invalid":""} ${b}`.trim(),onMouseDown:O,onMouseMove:D,onMouseUp:V,onMouseLeave:V,onTouchStart:O,onTouchMove:D,onTouchEnd:V,onFocus:()=>{f&&f()},onBlur:()=>{h&&h()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:z?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!z&&B.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=x.current;if(!t)return;const i=t.getBoundingClientRect();t.width=i.width,t.height=i.height;const n=t.getContext("2d");if(!n)return;const s=E();n.fillStyle=s.backgroundColor,n.fillRect(0,0,i.width,i.height),n.strokeStyle=s.strokeColor,n.lineWidth=2,n.lineCap="round",n.lineJoin="round",w(""),A("")})(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(J,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:$(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[x,y]=t([]),[v,j]=t(!1),[N,C]=t(!1),w=s(null),S=n(t=>{if(!t)return[];const i=Array.isArray(t)?t:Array.from(t),n=[];return i.forEach((t,i)=>{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-${i}`,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 n.push({file:l,id:`${e}-file-${i}`,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-${i}`,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,n=e.replace(/\s/g,""),a=n.length>50&&/^[A-Za-z0-9+/=]+$/.test(n)&&!e.startsWith("http")&&!e.startsWith("https")&&!e.startsWith("data:")&&!e.startsWith("blob:")&&!e.startsWith("/");let c=e;if(a){let e="image/png";n.startsWith("/9j/")||n.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?e="image/jpeg":n.startsWith("iVBORw0KGgo")?e="image/png":n.startsWith("R0lGOD")?e="image/gif":n.startsWith("UklGR")&&(e="image/webp"),c=`data:${e};base64,${n}`}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-${i+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-${i+1}`}}else if(c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))try{const t=new URL(e),n=t.pathname.split("/").pop()||"";if(n&&n.includes("."))d=decodeURIComponent(n);else{const e=t.searchParams.get("filename")||t.searchParams.get("name");d=e?decodeURIComponent(e):`file-${i+1}`}}catch(t){const n=e.lastIndexOf("/"),s=n>=0?e.substring(n+1):e,r=s.indexOf("?"),a=r>=0?s.substring(0,r):s;d=a&&a.includes(".")?decodeURIComponent(a):`file-${i+1}`}else d=`file-${i+1}`;if(l=d||`file-${i+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-${i}`,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})}}n.push({file:r,id:`${e}-file-${i}`,size:a,type:o,name:l,preview:s})}),n},[e]),k=n(()=>({isValid:!0,errors:{}}),[]),$=n(t=>{if(l||c)return;const i=S(t),n=x.length>0?[...x,...i]:i,s=r?.validation?.maxFiles||1/0,a=n.slice(0,s);if(y(a),C(!0),p){const t=k(),i={id:e,value:a.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(i)}},[x,r,l,c,p,k,S,e]),A=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]},E=e=>e.startsWith("image/")?"🖼️":e.startsWith("video/")?"🎥":e.startsWith("audio/")?"🎵":e.includes("pdf")?"📄":e.includes("word")||e.includes("document")?"📝":e.includes("excel")||e.includes("spreadsheet")?"📊":e.includes("zip")||e.includes("rar")?"📦":"📁";i(()=>{N&&(d[e]=!0)},[N,e,d]),i(()=>{("edit"===m||"test"===m)&&C(!1)},[m]),i(()=>{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===x.length&&null!=o?y(e):(null==o||Array.isArray(o)&&0===o.length)&&x.length>0&&y([])},[o,S,x.length]),i(()=>{u&&C(!0)},[u]),i(()=>()=>{x.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[x]);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||"*/*",O=r?.validation?.maxFiles||1/0,D=x.length<O&&(I||O>1),V="edit"===m,F="preview"===m||"test"===m,z=x.filter(e=>e.type.startsWith("image/")),M=x.filter(e=>!e.type.startsWith("image/")),q=z.length>0;return F&&q?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:[z.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:A(e.size)})]})]},e.id)),M.length>0&&B.jsxs("div",{className:"file-other-files",children:[B.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),M.map(e=>B.jsxs("div",{className:"file-item-minimal",children:[B.jsx("div",{className:"file-icon",children:E(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:A(e.size)})]})]},e.id))]})]}),B.jsx(J,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:k(),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 ${v?"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&&$(t)},onClick:e=>{const t=e.target,i=null!==t.closest(".file-item"),n=null!==t.closest(".file-remove");!V||L||0!==x.length||i||n||w.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(C(!0),"test"===m&&p){const t=k(),i={id:e,value:x.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(i)}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&&($(t),e.target.value="")},disabled:L,style:{display:"none"}}),0===x.length?B.jsxs("div",{className:"upload-placeholder",onClick:e=>{e.stopPropagation(),V&&!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:x.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:E(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:A(t.size)})]}),V&&!L&&B.jsx("button",{type:"button",className:"file-remove",onClick:i=>{i.stopPropagation(),(t=>{if(l||c)return;const i=x.filter(e=>e.id!==t);if(y(i),C(!0),p){const t=k(),n={id:e,value:i.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}})(t.id)},"aria-label":`Remove ${t.name}`,children:"✕"})]},t.id))})]}),x.length>0&&D&&!L&&V&&B.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!L&&w.current&&V&&(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(J,{validationErrors:a,fieldId:e,touchedFields:d,formSubmitted:u,properties:r,localValidation:k(),isTouched:N,mode:m})]})]})},oe=({id:e,properties:r,validationErrors:a={},formValue:l=null,readonly:c=!1,disabled:d=!1,touchedFields:u={},formSubmitted:m=!1,mode:b="test",onValueChange:g,onBlur:x,onFocus:y,className:v="",hideLabel:j=!1})=>{const[N,C]=t(l),[w,S]=t(!1),[k,$]=t(""),[A,E]=t(!1),[T,L]=t(!1),[I,R]=t({lat:40.7128,lng:-74.006}),[O,D]=t(null),[V,F]=t(10),[z,M]=t(""),[q,P]=t(!1),W=s(null),[_,U]=t(!1),[G,H]=t(null),[Y,K]=t(!1);i(()=>{if(l&&l.latitude&&l.longitude){40.7128===l.latitude&&-74.006===l.longitude||(C(l),D({lat:l.latitude,lng:l.longitude,isCurrentLocation:!1}),R({lat:l.latitude,lng:l.longitude}))}else null==l&&(C(null),D(null))},[l]),i(()=>{T&&40.7128===I.lat&&I.lng},[T,I]),i(()=>{(c||d)&&(T&&L(!1),z&&M(""),_&&(U(!1),H(null)))},[c,d]);const X=n(async(e,t)=>{K(!0);try{const i=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),n=await i.json();if(n&&n.address){const e=n.address;return{placeName:n.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=n(async(t,i,n)=>{const s=await X(t,i),r={latitude:t,longitude:i,timestamp:Date.now(),placeName:s.placeName,city:s.city,country:s.country,address:s.placeName,...n};if(C(r),D({lat:t,lng:i,isCurrentLocation:!1}),E(!0),g){g({id:e,value:r,isValid:!0,errors:{}})}},[X,e,g]),Q=n(async()=>{if(c||d)return;S(!0),$("");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 $("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}),i=t.coords.latitude,n=t.coords.longitude;return D({lat:i,lng:n,isCurrentLocation:!0}),R({lat:i,lng:n}),E(!0),await Z(i,n,{accuracy:t.coords.accuracy,timestamp:Date.now()}),S(!1),void $("")}catch(e){return S(!1),void(e.message?.includes("permission")||e.message?.includes("denied")?$("Location permission is required. Please enable location access in your device settings."):e.message?.includes("timeout")?$("Location request timed out. Please try again."):$("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 $("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,i=e.coords.longitude;D({lat:t,lng:i,isCurrentLocation:!0}),R({lat:t,lng:i}),E(!0),await Z(t,i,{accuracy:e.coords.accuracy,timestamp:e.timestamp}),S(!1),$("")},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."}$(t)},e)},[c,d,r,Z]),ee=n(()=>{if(!c&&!d&&(C(null),D(null),$(""),E(!0),g)){g({id:e,value:null,isValid:!0,errors:{}})}},[c,d,e,g]),te=n(()=>{c||d||L(!T)},[c,d,T]),ie=n((e,t,i,n,s,r)=>{const a=e-s/2,o=t-r/2,l=156543.03392*Math.cos(i.lat*Math.PI/180)/Math.pow(2,n),c=a*l,d=o*l;return{lat:i.lat+d/111320,lng:i.lng+c/(111320*Math.cos(i.lat*Math.PI/180))}},[]),ne=n(e=>{c||d||!W.current||0===e.button&&(U(!0),H({x:e.clientX,y:e.clientY}),e.preventDefault())},[c,d]),se=n(e=>{if(!_||!G||!W.current)return;const t=e.clientX-G.x,i=e.clientY-G.y,n=156543.03392*Math.cos(I.lat*Math.PI/180)/Math.pow(2,V),s=-i*n/111320,r=t*n/(111320*Math.cos(I.lat*Math.PI/180));R({lat:I.lat+s,lng:I.lng+r}),H({x:e.clientX,y:e.clientY})},[_,G,I,V]),re=n(async e=>{if(!W.current)return;if(_&&G){const t=Math.abs(e.clientX-G.x),i=Math.abs(e.clientY-G.y);if(t>5||i>5)return U(!1),void H(null)}if(c||d)return U(!1),void H(null);const t=W.current.getBoundingClientRect(),i=e.clientX-t.left,n=e.clientY-t.top,{lat:s,lng:r}=ie(i,n,I,V,t.width,t.height);await Z(s,r),U(!1),H(null)},[c,d,W,I,V,ie,Z,_,G]),ae=n(async t=>{if(t.trim()&&!c&&!d){P(!0),$("");try{const i=await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(t)}&limit=5&addressdetails=1`),n=await i.json();if(n&&n.length>0){const t=n[0],i=parseFloat(t.lat),s=parseFloat(t.lon),r=t.address||{},a={latitude:i,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),D({lat:i,lng:s,isCurrentLocation:!1}),R({lat:i,lng:s}),E(!0),g){g({id:e,value:a,isValid:!0,errors:{}})}}else $("No locations found for your search.")}catch(e){$("Failed to search for location. Please try again.")}finally{P(!1)}}},[c,d,e,g]),oe=()=>{y&&y()},le=()=>{E(!0),x&&x()},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":""} ${v}`,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(p,{size:16,className:"loading-spinner"}),"Getting Location..."]}):B.jsxs(B.Fragment,{children:[B.jsx(h,{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(f,{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(),z.trim()&&ae(z)},className:"search-form",children:B.jsxs("div",{className:"search-input-group",children:[B.jsx("input",{type:"text",value:z,onChange:e=>{M(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:ce||q}),B.jsx("button",{type:"submit",className:"search-btn",disabled:ce||q||!z.trim(),children:q?B.jsx(p,{size:16,className:"loading-spinner"}):"Search"})]})})}),B.jsxs("div",{ref:W,className:"location-map "+(_?"dragging":""),onMouseDown:ne,onMouseMove:se,onMouseUp:re,onMouseLeave:()=>{U(!1),H(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:_?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${V}/${Math.floor((I.lng+180)/360*Math.pow(2,V))}/${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,V))}.png) center/cover no-repeat`,userSelect:"none"},children:[O&&B.jsx("div",{className:"map-marker "+(O.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:B.jsx(f,{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:()=>F(e=>Math.min(18,e+1)),disabled:V>=18,children:"+"}),B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>F(e=>Math.max(1,e-1)),disabled:V<=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(p,{size:16,className:"loading-spinner"}),B.jsx("span",{children:"Loading address details..."})]})]}),k&&B.jsx("div",{className:"location-error",children:k})]}),B.jsx(J,{validationErrors:a,fieldId:e,touchedFields:u,formSubmitted:m,properties:r,localValidation:{isValid:!0,errors:{}},isTouched:A,mode:b})]});var me,pe,he},le=({id:e,properties:t,className:i="",hideLabel:n=!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 n?null:(()=>{const n={id:e,className:`form-heading h${s} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${i}`.trim(),style:a()};switch(s){case 1:default:return B.jsx("h1",{...n,children:r});case 2:return B.jsx("h2",{...n,children:r});case 3:return B.jsx("h3",{...n,children:r});case 4:return B.jsx("h4",{...n,children:r});case 5:return B.jsx("h5",{...n,children:r});case 6:return B.jsx("h6",{...n,children:r})}})()},ce=({id:e,properties:r,mode:a="preview",formValue:o,onValueChange:l,className:c="",hideLabel:d=!1})=>{const[u,m]=t(""),[p,h]=t(r.validation?.listStyle||"numbers"),[f,j]=t("#000000"),N=s(null),C=s(null),w=s(!1),S="edit"===a,k=s({instructions:[],listStyle:"numbers",formValue:void 0}),$=s(a);i(()=>{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 i=r.basic.value;i&&"object"==typeof i&&!Array.isArray(i)&&i.instructions?(Array.isArray(i.instructions)?e=i.instructions:"string"==typeof i.instructions&&(e=[i.instructions]),i.listStyle&&"string"==typeof i.listStyle&&(t=i.listStyle)):Array.isArray(i)?e=i:"string"==typeof i&&(e=[i])}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 i=JSON.stringify(e)!==JSON.stringify(k.current.instructions)||t!==k.current.listStyle,n=a!==$.current,s=JSON.stringify(o)!==JSON.stringify(k.current.formValue),l=!k.current.formValue||Array.isArray(k.current.formValue)&&0===k.current.formValue.length||"string"==typeof k.current.formValue&&""===k.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(i||n||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",i=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}>${i}</${e}>`}h(t),m(c),S&&N.current&&(n||i&&N.current.innerHTML.trim()!==c.trim())&&(N.current.innerHTML=c),k.current={instructions:e,listStyle:t,formValue:o},$.current=a}},[o,r.basic?.instructions,r.validation?.listStyle,a,S]),i(()=>{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 A=n(()=>{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]),E=n(()=>{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=n((e,t)=>{document.execCommand(e,!1,t),N.current?.focus(),A()},[A]),L=n(()=>{T("bold")},[T]),I=n(()=>{T("italic")},[T]),R=n(e=>{const t=e.target.value;j(t),T("foreColor",t)},[T]),O=n(t=>{if(h(t),!N.current)return;const i=window.getSelection(),n=i&&i.rangeCount>0?i.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),n&&i)try{i.removeAllRanges(),i.addRange(n)}catch(e){}if(A(),l){l({id:e,value:{instructions:s?[s]:[],listStyle:t},isValid:!0,errors:{}})}},[e,A,l]),D=n(e=>{const t=e.target.files?.[0];if(!t||!t.type.startsWith("image/"))return;const i=new FileReader;i.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 i=window.getSelection();if(i&&i.rangeCount>0){const t=i.getRangeAt(0);t.deleteContents(),t.insertNode(e)}else N.current.appendChild(e);A()}},i.readAsDataURL(t),C.current&&(C.current.value="")},[A]),V=n(e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain"),i=window.getSelection();if(i&&i.rangeCount>0){const e=i.getRangeAt(0);e.deleteContents();const n=document.createTextNode(t);e.insertNode(n),e.setStartAfter(n),e.collapse(!0),i.removeAllRanges(),i.addRange(e)}A()},[A]),F=n(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 "+(F("bold")?"active":""),onClick:L,title:"Bold","aria-label":"Bold",children:B.jsx(b,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+(F("italic")?"active":""),onClick:I,title:"Italic","aria-label":"Italic",children:B.jsx(g,{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:f,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:f},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:()=>O("bullets"),title:"Bullet List","aria-label":"Bullet List",children:B.jsx(x,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===p?"active":""),onClick:()=>O("numbers"),title:"Numbered List","aria-label":"Numbered List",children:B.jsx(y,{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:D,style:{display:"none"}})]})]}),B.jsx("div",{ref:N,contentEditable:!0,className:"instruction-editor-content",onInput:A,onBlur:E,onPaste:V,"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:n})=>{const[s,r]=t(new Map);return i(()=>{if(!e)return void r(e=>(e.forEach(e=>URL.revokeObjectURL(e)),new Map));const t=new Map;return e.forEach((e,i)=>{if(e&&e.type&&"string"==typeof e.type&&e.type.startsWith("image/")){const n=URL.createObjectURL(e);t.set(i,n)}}),r(e=>(e.forEach((e,i)=>{t.has(i)||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 i=e&&e.type&&"string"==typeof e.type&&e.type.startsWith("image/"),r=s.get(t);return B.jsx("div",{className:"attachment-thumbnail",children:i&&r?B.jsxs(B.Fragment,{children:[B.jsx("img",{src:r,alt:e?e.name:"Attachment"}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>n(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(d,{size:20})}),B.jsx("span",{className:"file-name",children:e?e.name:"Unknown File"}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>n(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:p=null,onThresholdActionCompletion:h,onThresholdIssueRaised:f,onBasicPropertyActionCompletion:b,workOrderNumber:g,assetNumber:x,isStandalone:y,user:v})=>{const[k,$]=t(u||""),[A,E]=t(p||null),[T,L]=t(!1),[I,R]=t(!1),[O,D]=t(!1),[V,F]=t(!1),[z,M]=t(!1),q=s(null),P=s(o),W=s(!1),_=s(!1);i(()=>{if(!W.current&&null!=u){const e="string"==typeof u?u:String(u||"");$(e),W.current=!0}},[u]),i(()=>{_.current||void 0===p||(E(p),_.current=!0)},[p]),i(()=>{if(W.current&&!T&&null!=u){const e="string"==typeof u?u:String(u||"");k&&""!==String(k||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==k&&$(e):$(e)}},[u,T,k]),i(()=>{_.current&&void 0!==p&&(!A||p&&p.length>0&&p!==A)&&E(p)},[p,A]),i(()=>{const t=["select","radio","checkbox","segment"].includes(e.name||"");if(t){const t=P.current,i=o;let n=!1;if("checkbox"===e.name){const e=Array.isArray(t)?t:t?[t]:[],s=Array.isArray(i)?i:i?[i]:[];n=JSON.stringify(e.sort())!==JSON.stringify(s.sort())}else n=t!==i&&void 0!==t;if(n){D(!1),F(!1),R(!1),L(!1),M(!1);const e="string"==typeof u?u:String(u||"");e&&""!==e.trim()?$(e):$(""),p&&0!==p.length?E(p):E(null)}P.current=i}t||(P.current=o)},[o,e.name,u,p]);const U=n((e,t)=>{const{operator:i,value:n}=e,s=String(t).toLowerCase(),r=String(n).toLowerCase();switch(i){case"equals":return s===r||String(t)===String(n);case"notEquals":return s!==r&&String(t)!==String(n);case"greaterThan":return Number(t)>Number(n);case"lessThan":return Number(t)<Number(n);case"greaterThanOrEqual":return Number(t)>=Number(n);case"lessThanOrEqual":return Number(t)<=Number(n);default:return!1}},[]),G=n(()=>{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 i=[];if("checkbox"===e.name&&Array.isArray(o))o.forEach(e=>{const n=t.conditions.find(t=>U(t,e));n&&!i.find(e=>e.id===n.id)&&i.push(n)});else{const e=t.conditions.find(e=>U(e,o));e&&i.push(e)}return i},[e,o,U]),H=n(t=>{const i=t.target.value;$(i),l&&l(i);const n=G(),s=String(i||"").trim().length>0;n.forEach(e=>{!0===e.enableNotes&&h&&h(e.id,"notes",s)});const r=e.condition;!(r&&r.conditions&&r.conditions.length>0)&&b&&b("notes",s)},[l,G,h,e,b]),J=n(()=>{if(l){const e="string"==typeof k?k:String(k||"");l(e),setTimeout(()=>{L(!1)},0)}else L(!1)},[k,l]),Y=n(()=>{J()},[J]),X=n(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),J())},[J]),Z=n(()=>{L(!0)},[]),Q=n(()=>{L(!0)},[]),ee=n(()=>{q.current?.click()},[]),te=n(t=>{const i=t.target.files;if(i&&i.length>0){const t=Array.from(i);E(t),c&&c(t);G().forEach(e=>{!0===e.enableAttachment&&h&&h(e.id,"attachments",!0)});const n=e.condition;!(n&&n.conditions&&n.conditions.length>0)&&b&&b("attachments",!0)}q.current&&(q.current.value="")},[c,G,h,e,b]),ie=n(t=>{if(A){const i=A.filter((e,i)=>i!==t);if(0===i.length){E(null),c&&c(null);G().forEach(e=>{!0===e.enableAttachment&&h&&h(e.id,"attachments",!1)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&b&&b("attachments",!1)}else E(i),c&&c(i)}},[A,c,G,h,e,b]),ne=n(()=>{D(!0);G().forEach(e=>{!0===e.enableSendEmail&&h&&h(e.id,"email",!0)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&b&&b("email",!0),setTimeout(()=>{D(!1)},3e3)},[G,h,e,b]),se=n(()=>{R(!0)},[]),re=n(()=>{R(!1)},[]),ae=n(()=>{R(!1),F(!0);const t=e.condition;if(t&&t.conditions&&t.conditions.length>0){G().forEach(e=>{!0===e.enableRaiseIssue&&f&&f(e.id)})}else b&&b("issue",!0)},[e,b,G,f]);if("test"!==r)return null;const oe=["select","radio","checkbox","segment"].includes(e.name||""),le=e.basic?.options||e.options||[];let ce=!1,ue=!1,me=!1,pe=!1,he=null;const fe=null!=o&&""!==o&&!(Array.isArray(o)&&0===o.length),be=e.condition,ge=be&&be.conditions&&be.conditions.length>0;if(ge&&fe)if("checkbox"===e.name&&Array.isArray(o)){const e=o;for(const t of e){const e=be.conditions.find(e=>U(e,t));e&&(ce=ce||!0===e.enableNotes,ue=ue||!0===e.enableAttachment,me=me||!0===e.enableRaiseIssue,pe=pe||!0===e.enableSendEmail)}}else if(oe){const e=be.conditions.find(e=>U(e,o));e&&(ce=!0===e.enableNotes,ue=!0===e.enableAttachment,me=!0===e.enableRaiseIssue,pe=!0===e.enableSendEmail)}else{const e=be.conditions.find(e=>U(e,o));e&&(ce=!0===e.enableNotes,ue=!0===e.enableAttachment,me=!0===e.enableRaiseIssue,pe=!0===e.enableSendEmail)}if(!ge){const t=e.basic,i=!0===t?.enableNotes,n=!0===t?.enableAttachment,s=!0===t?.enableRaiseIssue,r=!0===t?.enableSendEmail;if(oe)if(fe)if("checkbox"===e.name){(Array.isArray(o)?o:[o]).forEach(e=>{const t=le.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(ce=ce||!0===t.enableNotes,ue=ue||!0===t.enableAttachment,me=me||!0===t.enableRaiseIssue,pe=pe||!0===t.enableSendEmail,he||(he=t))}),ce=ce||i,ue=ue||n,me=me||s,pe=pe||r}else if(he=le.find(e=>!(!e||!e.value)&&(e.value===o||(String(e.value)===String(o)||(e.label===o||String(e.label)===String(o))))),he){const e=!0===he.enableNotes,t=!0===he.enableAttachment,a=!0===he.enableRaiseIssue,o=!0===he.enableSendEmail;ce=e||i,ue=t||n,me=a||s,pe=o||r}else ce=i,ue=n,me=s,pe=r;else ce=i,ue=n,me=s,pe=r;else ce=i,ue=n,me=s,pe=r}if(!(ce||ue||me||pe))return null;const xe=G(),ye=e.condition,ve=ye&&ye.conditions&&ye.conditions.length>0,je=!!ve&&xe.some(e=>!0===e.enableNotes),Ne=!!ve&&xe.some(e=>!0===e.enableAttachment),Ce=!!ve&&xe.some(e=>!0===e.enableSendEmail),we=!!ve&&xe.some(e=>!0===e.enableRaiseIssue),Se=String(k||"").trim().length>0,ke=A&&A.length>0,$e=A?A.length:0;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"component-action-features",children:[B.jsxs("div",{className:"action-icons-toolbar",children:[ce&&B.jsxs("button",{type:"button",className:`action-icon-button ${Se?"active":""} ${je?"mandatory":""}`,onClick:Z,title:"Add Notes",children:[B.jsx(m,{size:14,fill:Se?"currentColor":"none"}),je&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ue&&B.jsxs("button",{type:"button",className:`action-icon-button ${ke?"active":""} ${Ne?"mandatory":""}`,onClick:ee,title:"Add Attachment",children:[B.jsx(d,{size:14,fill:ke?"currentColor":"none"}),$e>0&&B.jsx("span",{className:"attachment-count-badge",children:$e}),Ne&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),pe&&B.jsxs("button",{type:"button",className:`action-icon-button ${O?"active sent":""} ${Ce?"mandatory":""}`,onClick:ne,disabled:O,title:"Send Email",children:[O?B.jsx(B.Fragment,{children:B.jsx(j,{size:14})}):B.jsx(N,{size:14,fill:O?"currentColor":"none"}),Ce&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),me&&B.jsxs("button",{type:"button",className:`action-icon-button ${V?"active":""} ${we?"mandatory":""}`,onClick:se,title:"Raise an Issue",children:[B.jsx(C,{size:14,fill:V?"currentColor":"none"}),we&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(Se&&ce||ke&&ue)&&B.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>M(!z),title:z?"Collapse":"Expand",children:z?B.jsx(w,{size:14}):B.jsx(S,{size:14})})]}),T&&ce&&B.jsxs("div",{className:"notes-input-overlay",children:[B.jsx("textarea",{className:"action-notes-textarea",value:k,onChange:H,onBlur:Y,onKeyDown:X,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:J,title:"Save notes (Ctrl+Enter)",children:"Save"}),B.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{L(!1)},title:"Cancel",children:"Cancel"})]})]}),z&&B.jsxs("div",{className:"actions-content",children:[!T&&Se&&ce&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",onClick:Q,children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",k]})}),ke&&ue&&B.jsx("div",{className:"attachments-section",children:B.jsx(de,{attachments:A,onRemove:ie})})]}),ue&&B.jsx("input",{ref:q,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:te,style:{display:"none"}})]}),I&&B.jsx(K,{isOpen:I,onClose:re,onSuccess:ae,component:he?{...e,basic:{...e.basic,label:`${e.basic?.label||"Component"} - ${he.label||he.value}`,value:he.value||e.basic?.value||""}}:{...e,basic:{...e.basic,value:null!=o?Array.isArray(o)?o.join(", "):String(o):e.basic?.value||""}},formTemplateId:a||"",notes:k,attachments:A,workOrderNumber:g,assetNumber:x,user:v,isStandalone:y})]})},me=({attachments:e})=>e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const i=e.type?.startsWith("image/")||!1,n=i?(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:i&&n?B.jsx("img",{src:n,alt:e.name||`Attachment ${t+1}`}):B.jsxs("div",{className:"file-icon-placeholder",children:[B.jsx(d,{size:20}),B.jsx("span",{className:"file-name",children:e.name||`File ${t+1}`})]})},t)})}):null,pe=({component:e})=>{const t=e.basic?.notes||"",i=e.basic?.attachments||[],n=t&&t.trim().length>0,s=i&&i.length>0;return n||s?B.jsx("div",{className:"component-submission-actions",children:B.jsxs("div",{className:"actions-content",children:[n&&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:i})})]})}):null},he=({child:e,selectedChild:t,mode:i,onChildSelect:n,onChildDelete:s,renderFormComponent:r,isOverlay:a=!1,isChildrenEditMode:o=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h,workOrderNumber:f,assetNumber:b})=>{const g=l[e.id],x="preview"===i&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:y,listeners:v,setNodeRef:j,transform:N,transition:C,isDragging:w,isSorting:S}=D({id:e.id,disabled:a||"edit"!==i}),k={transform:F.Transform.toString(N),transition:C,zIndex:w?1e3:"auto"};return B.jsxs("div",{ref:j,style:k,className:`form-component section-child ${t?.id===e.id?"selected":""} ${w?"dragging":""} ${S?"sorting":""} ${o?"children-edit-active":""}`,onClick:()=>!w&&n(e),role:"button",tabIndex:0,children:[("edit"===i||o)&&B.jsx("div",{className:"child-drag-handle",...v,...y,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"===i||o)&&B.jsxs("div",{className:"component-actions child-actions",children:[B.jsx("button",{className:"btn edit-btn",onClick:t=>{t.stopPropagation(),n(e)},onMouseDown:e=>e.stopPropagation(),title:"Edit properties",children:B.jsx(A,{size:12})}),B.jsx("button",{className:"btn delete-btn",onClick:t=>s(e,t),onMouseDown:e=>e.stopPropagation(),title:"Delete component",children:B.jsx(u,{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:g,onThresholdActionCompletion:d,onThresholdIssueRaised:m,onNotesChange:p?t=>p(e.id,t):void 0,onAttachmentChange:h?t=>h(e.id,t):void 0,workOrderNumber:f,assetNumber:b}),x&&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:x,onNotesChange:y,onAttachmentChange:v,workOrderNumber:j,assetNumber:N})=>{const[C,w]=t(s.basic.collapsed),[$,A]=t(!1),[E,T]=t(!1),[L,D]=t(s.basic.label),[V,F]=t(s.basic.description),[z,M]=t(s.children||[]),[q,P]=t(!1);i(()=>{M(s.children||[])},[s.children]),i(()=>{D(s.basic.label),F(s.basic.description)},[s.basic.label,s.basic.description]);const{setNodeRef:W,isOver:_}=I({id:`section-${e}`,disabled:"edit"!==r}),U=!("preview"!==r&&"test"!==r||s.children&&s.children.length>0),G=n(t=>{D(t),o?.({id:e,value:{...s,basic:{...s.basic,label:t}}})},[e,s,o]),H=n(t=>{F(t),o?.({id:e,value:{...s,basic:{...s.basic,description:t}}})},[e,s,o]),J=n(e=>{m?.(e)},[m]),Y=n((e,t)=>{t.stopPropagation();const i=z.filter(t=>t.id!==e.id);M(i),p?.(e.id)},[p,z,e]),K=n(()=>{u?.(s),l?.()},[u,l,s]),X=n(e=>{e.stopPropagation(),"edit"===r&&z.length>0&&P(!q)},[r,z.length,q]),ne=n(t=>{t.stopPropagation(),w(!C),o?.({id:e,value:{...s,basic:{...s.basic,collapsed:!C}}})},[C,e,s,o]),ae=f||n(e=>{const t=a[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let i=t;"number-input"===e.name&&"number"==typeof t?i=String(t):"number-input"===e.name&&null==t&&(i="");const n={id:e.id,properties:e,validationErrors:{},formValue:i,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,{...n,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...n,properties:e,readonly:!1,disabled:!1});case"select":const t={...e,options:e.basic?.options||[]};return B.jsx(ee,{...n,properties:t,disabled:!1});case"checkbox":const i={...e,options:e.basic?.options||[]};return B.jsx(te,{...n,properties:i,formValue:[],disabled:!1});case"radio":const s={...e,options:e.basic?.options||[]};return B.jsx(ie,{...n,properties:s,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(se,{...n,properties:e,readonly:!1,disabled:!1});case"signature":return B.jsx(re,{...n,properties:e});case"heading":return B.jsx(le,{...n,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(U)return null;const oe={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:W,className:`df-form-section ${c?"selected":""} ${_?"drag-over":""} ${d}`,style:oe,children:[B.jsxs("div",{className:"section-header "+(q?"children-edit-mode":""),onClick:K,onDoubleClick:X,children:[B.jsx("div",{className:"section-header-content",children:B.jsxs("div",{className:"section-title",children:[B.jsx("span",{className:"section-toggle",title:C?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),ne(e)},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),ne(e))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:C?B.jsx(k,{size:18}):B.jsx(S,{size:18})}),"edit"===r&&$?B.jsx("input",{type:"text",value:L,onChange:e=>D(e.target.value),onBlur:()=>{A(!1),G(L)},onKeyDown:e=>{"Enter"===e.key&&(A(!1),G(L))},className:"section-title-input",autoFocus:!0}):B.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===r&&A(!0),style:{display:"inline",margin:0},children:L||"Untitled Section"})]})}),(V||"edit"===r)&&B.jsx("div",{className:"section-description",children:"edit"===r&&E?B.jsx("textarea",{value:V,onChange:e=>F(e.target.value),onBlur:()=>{T(!1),H(V)},onKeyDown:e=>{"Enter"===e.key&&e.ctrlKey&&(T(!1),H(V))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):B.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===r&&T(!0),children:V||"Section description"})})]}),!C&&B.jsx("div",{className:`section-content ${_?"drag-over":""} ${0===z.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&K()},children:B.jsx(R,{items:z.map(e=>e.id),strategy:O,children:0===z.length?B.jsxs("div",{className:"section-empty-state",onClick:K,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:_?"#3b82f6":"#374151"},children:_?"Drop components here":"Empty Section"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):z.map(e=>B.jsx(he,{child:e,selectedChild:h||null,mode:r,onChildSelect:J,onChildDelete:Y,renderFormComponent:ae,isChildrenEditMode:q,formData:a,formTemplateId:b,onNotesChange:y,onAttachmentChange:v,onThresholdActionCompletion:g,onThresholdIssueRaised:x,workOrderNumber:j,assetNumber:N},e.id))})})]})},be=({component:e,selectedComponent:t,mode:i,onComponentSelect:n,onComponentDelete:s,onComponentEdit:r,renderFormComponent:a,isOverlay:o=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h,workOrderNumber:f,assetNumber:b})=>{const g=l[e.id],x="preview"===i&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:y,listeners:v,setNodeRef:j,transform:N,transition:C,isDragging:w,isSorting:S}=D({id:e.id,disabled:o}),k={transform:F.Transform.toString(N),transition:C,opacity:w?.3:1,zIndex:w?1e3:"auto"};return B.jsxs("div",{ref:j,style:{...k,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":""} ${w?"dragging":""} ${S?"sorting":""}`,onClick:()=>!w&&n(e),role:"button",tabIndex:0,children:["edit"===i&&B.jsx("div",{className:"component-drag-handle",...v,...y,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"===i?"24px":"0",paddingLeft:"edit"===i?"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:g,onThresholdActionCompletion:d,onThresholdIssueRaised:m,onNotesChange:p?t=>p(e.id,t):void 0,onAttachmentChange:h?t=>h(e.id,t):void 0,workOrderNumber:f,assetNumber:b}),x&&B.jsx(pe,{component:e})]}),"edit"===i&&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(A,{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(u,{size:12})})]})]})},ge=({gridComponents:e,mode:t,onComponentSelect:i,onComponentDelete:n,onComponentEdit:s,onComponentUpdate:r,selectedComponent:a,renderFormComponent:o,gridId:l,formData:c={},formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h,workOrderNumber:f,assetNumber:b})=>{const{setNodeRef:g,isOver:x}=I({id:`grid-drop-zone-${l}`,disabled:"edit"!==t});return B.jsx("div",{ref:g,className:"grid-drop-zone",style:{border:x?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:x?"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:V,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:i,onComponentDelete:n,onComponentEdit:s,onComponentUpdate:r,renderFormComponent:o,formData:c,formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h,workOrderNumber:f,assetNumber:b})},e.id))})}),B.jsx("div",{style:{border:x?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:x?"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:x?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:x?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:x?"Drop components here":"Empty DataGrid"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},xe=({templateComponents:e,dataEntries:t,renderFormComponent:i,renderComponent:n,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:x,datagridId:y="",workOrderNumber:v,assetNumber:j})=>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,i)=>B.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:i<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 ${i+1}`},`header-${t.id}`))}),t.length>0?t.map((a,l)=>B.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:l<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:l%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=a.components?.[r];const c=`${t.id||`component-${r}`}-entry-${y}-${l}-${r}`;return o=o?o.id!==c?{...o,id:c,basic:{...o.basic,showLabel:!1}}:{...o,id:o.id,basic:{...o.basic,showLabel:!1}}:{...t,id:c,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsxs("div",{style:{padding:"12px 16px",borderRight:r<e.length-1?"1px solid var(--df-color-fb-border)":"none",minHeight:"60px",minWidth:"150px",display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center",overflow:"visible",position:"relative",zIndex:1},children:[B.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:n?n(o,!0):i(o,!0)}),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(o.name)&&B.jsxs("div",{style:{marginTop:"8px",width:"100%"},children:[B.jsx(ue,{component:o,mode:"test",formTemplateId:h,formData:p,formValue:p[o.id],onThresholdActionCompletion:f,onThresholdIssueRaised:b,onNotesChange:g?e=>g(o.id,e):void 0,onAttachmentChange:x?e=>x(o.id,e):void 0,notes:o.basic?.notes||p[o.id]?.notes,attachments:o.basic?.attachments||p[o.id]?.attachments,workOrderNumber:v,assetNumber:j}),"preview"===s&&(o.basic?.notes||o.basic?.attachments)&&B.jsx(pe,{component:o})]})]},`${a.id}-${r}`)}),r&&t.length>c&&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:{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:"×"})})]},a.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:[n?n(r):i(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:x?e=>x(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:x,onComponentUpdate:y,selectedComponent:v,renderFormComponent:j,onEntryAdd:N,onEntryRemove:C,formTemplateId:w,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L,workOrderNumber:I,assetNumber:R})=>{const[O,D]=t(!1),V=s(!1);let F=r.templateComponents||[];const z=r.entries||[];0===F.length&&z.length>0&&z[0].components&&(F=z[0].components.map(e=>({...e,id:e.id?.replace(/-entry-\d+$/,"")||e.id,basic:{...e.basic,showLabel:!0}}))),i(()=>{if("edit"===a&&!r.templateComponents&&u&&V.current){const t={...r,templateComponents:[]};JSON.stringify(t)!==JSON.stringify(r)&&u({id:e,value:t})}V.current=!0},[r.templateComponents,e,u,r,a]),i(()=>{if(F.length>0){if("test"===a&&0===z.length&&V.current){const t={id:`entry-${e}-0`,index:0,components:F.map((t,i)=>{const n=t.id||`component-${i}`;return{...t,id:`${n}-entry-${e}-0-${i}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const i={...r,entries:[t]};JSON.stringify(i)!==JSON.stringify(r)&&u({id:e,value:i})}return}if("edit"!==a||!V.current)return;if(z.some(e=>e.components?.some((t,i)=>{const n=`${F[i]?.id}-entry-${e.index}-${i}`;return t.id!==n}))&&u){const t=z.map(e=>({...e,components:e.components?.map((t,i)=>({...t,id:`${F[i]?.id}-entry-${e.index}-${i}`}))||[]})),i={...r,entries:t};return void(JSON.stringify(i)!==JSON.stringify(r)&&u({id:e,value:i}))}if(0===z.length&&"edit"===a){const t={id:`entry-${e}-0`,index:0,components:F.map((t,i)=>{const n=t.id||`component-${i}`;return{...t,id:`${n}-entry-${e}-0-${i}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const i={...r,entries:[t]};JSON.stringify(i)!==JSON.stringify(r)&&u({id:e,value:i})}}else if(z.length>0){if(z.some(e=>F.some((t,i)=>{const n=e.components?.[i];if(!n)return!0;const s=`${t.id}-entry-${e.index}-${i}`,r=n.id===s,a=JSON.stringify(n.basic?.options)!==JSON.stringify(t.basic?.options)||n.basic?.placeholder!==t.basic?.placeholder||n.basic?.defaultValue!==t.basic?.defaultValue||n.basic?.label!==t.basic?.label||n.validation?.required!==t.validation?.required;return!r||a}))&&u){const t=z.map(t=>{const i=F.map((i,n)=>{let s=t.components?.[n];s||(s=t.components?.find(e=>e.name===i.name&&e.basic?.label===i.basic?.label));const r=`${i.id||`component-${n}`}-entry-${e}-${t.index}-${n}`;if(s){return{...i,id:r,basic:{...i.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}return{...i,id:r,basic:{...i.basic,showLabel:!1,defaultValue:void 0,value:void 0}}});return{...t,components:i}}),i={...r,entries:t};JSON.stringify(i)!==JSON.stringify(r)&&u({id:e,value:i})}}}},[F,z,e,u,r,a,r.templateComponents]);const M=n(e=>{e.stopPropagation(),m?.(),f?.(r)},[m,f,r]),q=n((t,i)=>{i.stopPropagation(),g&&g(t,i);const n=F.filter(e=>e.id!==t.id),s=z.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:n,entries:s}})},[g,r,u,e,F,z]),P=n((t,i)=>{y&&y(t,i);const n=F.map(e=>e.id===t?{...e,...i}:e);u&&u({id:e,value:{...r,templateComponents:n}})},[y,r,u,e,F]),W=n(e=>{"test"===a&&u&&u({id:e.id,value:e.value})},[u]),_=n(()=>{const t=r.entries||[],i=t.length,n={id:`entry-${e}-${i}`,index:i,components:F.map((t,n)=>{const s=`${t.id||`component-${n}`}-entry-${e}-${i}-${n}`;return{...t,id:s,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}},s=[...t,n];u&&u({id:e,value:{...r,entries:s}}),N?.()},[r,u,e,N,F]),U=n(t=>{const i=r.entries.filter((e,i)=>i!==t).map((t,i)=>({...t,index:i,id:`entry-${e}-${i}`}));u&&u({id:e,value:{...r,entries:i}})},[r,u,e,C]),G=n((e,t=!1)=>{const i=o[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let n=i;"number-input"===e.name&&"number"==typeof i?n=String(i):"number-input"===e.name&&null==i&&(n="");const s={id:e.id,properties:e,validationErrors:l||{},formValue:n,touchedFields:c||{},formSubmitted:d||!1,mode:a,hideLabel:t,onValueChange:W,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 i={...e,options:e.basic?.options||[]};return B.jsx(ee,{...s,properties:i,disabled:!1,hideLabel:t});case"checkbox":const n={...e,options:e.basic?.options||[]};return B.jsx(te,{...s,properties:n,formValue:[],disabled:!1,hideLabel:t});case"radio":const r={...e,options:e.basic?.options||[]};return B.jsx(ie,{...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,W,o,l,c,d]),H={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:M,style:H,children:[B.jsx("div",{className:"grid-header",children:B.jsx("div",{className:"grid-title",onClick:t=>{t.stopPropagation(),D(!O),u?.({id:e,value:{...r,basic:{...r.basic,collapsed:!O}}})},children:B.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[O?B.jsx(k,{size:16}):B.jsx(S,{size:16}),B.jsx(E,{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&&!O&&B.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:r.basic.description}),!O&&B.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===a?B.jsx(ge,{gridComponents:F,mode:a,onComponentSelect:b||(()=>{}),onComponentDelete:q,onComponentEdit:x,onComponentUpdate:P,selectedComponent:v||null,renderFormComponent:j||G,gridId:e,formData:o,formTemplateId:w,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L,workOrderNumber:I,assetNumber:R}):B.jsx(xe,{templateComponents:F,dataEntries:z,renderFormComponent:j||G,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||_,onRemoveEntry:C||U,formData:o,formTemplateId:w,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L,datagridId:e,workOrderNumber:I,assetNumber:R})})]})},ve=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:x,workOrderNumber:y,assetNumber:v,isStandalone:j,user:N})=>{const[C,w]=t({}),[S,k]=t({}),[$,A]=t(!1),[E,T]=t({}),[L,I]=t({}),[R,O]=t(new Set),[D,V]=t(new Map),[F,z]=t({isValid:!0}),[M,q]=t({}),[P,W]=t({});i(()=>{U()},[r,l]);const _=(e,t)=>{e.forEach(e=>{if(e.id&&(void 0!==t[e.id]||(e.basic&&"value"in e.basic&&void 0!==e.basic.value&&""!==e.basic.value&&null!==e.basic.value?t[e.id]=e.basic.value:e.basic&&"defaultValue"in e.basic&&void 0!==e.basic.defaultValue&&""!==e.basic.defaultValue&&null!==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,i)=>{Array.isArray(e)&&e.forEach((e,i)=>{e&&e.components&&Array.isArray(e.components)&&_(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,i)=>{e&&e.components&&Array.isArray(e.components)&&_(e.components,t)}),"file"===e.name&&e.basic){const i=e.basic.files||e.basic.attachments||e.basic.value;i&&(t[e.id]=i)}if(e.id&&e.basic&&e.basic.notes,"instructions"===e.name&&e.basic){e.basic.instructions||(e.basic.instructions=[]);const i=e.basic.value||e.basic.instructions;i&&(t[e.id]=i)}e.children&&Array.isArray(e.children)&&_(e.children,t)})},U=n(()=>{const e={},t={},i={},n=new Set,s=e=>{e.forEach(e=>{e.id&&((e.basic?.notes||e.basic?.comments)&&(t[e.id]=e.basic?.notes||e.basic?.comments),e.basic?.attachments&&(i[e.id]=e.basic.attachments)),e.children&&s(e.children),e.cells&&e.cells.forEach(e=>e.forEach(e=>{e.components&&s(e.components)})),e.entries&&e.entries.forEach(e=>{e.components&&s(e.components)})})},a=e=>{e.forEach((e,t)=>{if(e.id&&"string"==typeof e.id&&""!==e.id.trim())n.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}`));else{const i=e.name||"component",n=(e.basic?.label||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);e.id=`${i}-${n||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${t}`}n.add(e.id),e.children&&Array.isArray(e.children)&&a(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)&&a(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&a(e.components)})})};r&&r.length>0&&a(r),l&&l.length>0&&a(l),l&&l.length>0&&_(l,e),l&&l.length>0&&_(l,e),r&&r.length>0&&(_(r,e),s(r)),w(t=>({...e,...t})),q(e=>({...t,...e})),W(e=>({...i,...e})),Y()},[l,r]),J=(e,t)=>{e.forEach(e=>{if(e.id)if("table"===e.name||"datagrid"===e.name)t[e.id]=!0;else if(e.conditional){const i=G.evaluateConditionalLogic(e.conditional,r,C);t[e.id]=i.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)&&J(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&J(e.components,t)}),e.children&&Array.isArray(e.children)&&J(e.children,t)})},Y=n(()=>{const e={};r&&r.length>0&&J(r,e),I(e)},[r,C]),K=n(e=>{const t=r.find(t=>t.id===e);if(t&&("table"===t.name||"datagrid"===t.name))return!0;return!1!==L[e]},[L,r]),X=n(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 i=C[e.id];void 0!==i&&i!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:i,newValue:e.value});const n={...C,[e.id]:e.value};w(n);const s=r.find(t=>t.id===e.id);if(s){const e=s?.threshold;e&&e.conditions&&e.conditions.length>0&&O(t=>{const i=new Set(t);return e.conditions.forEach(e=>{i.delete(e.id)}),i})}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),S[e.id]&&k(t=>({...t,[e.id]:""})),!o){if(e.isValid)return void k(t=>{const i=t[e.id];return i&&""!==i.trim()?{...t,[e.id]:""}:t});setTimeout(()=>{me(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 i=G.evaluateConditionalLogic(t.conditional,r,n);e[t.id]=i.shouldShow}else e[t.id]=!0}),I(e)},0)},[r,C,S,d]),de=n((e,t)=>{for(const i of e){if(i.id===t)return i;if("section"===i.name&&i.children){const e=de(i.children,t);if(e)return e}if("table"===i.name&&i.cells)for(const e of i.cells)for(const i of e)if(i.components){const e=de(i.components,t);if(e)return e}if("datagrid"===i.name&&i.entries)for(const e of i.entries)if(e.components){const i=de(e.components,t);if(i)return i}}return null},[]),me=n(e=>{if(o)return;const t=de(r,e);if(!t)return;const i=C[e]||"";if("number-input"===t.name&&(!i||""===i)){if(t.validation.required){const i=t.validation.customValidationMessage,n=t.basic.label||"This field",s=i||`${n} is required`;k(t=>({...t,[e]:s}))}else k(t=>({...t,[e]:""}));return}let n=!1;n=Array.isArray(i)?i.length>0:"string"==typeof i?""!==i.trim():null!=i;let s="";if(t.validation.required&&!n){const e=t.validation.customValidationMessage,i=t.basic.label||"This field";s=e||`${i} is required`}else if("email-input"===t.name&&n&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(i)){const e=t.validation.customValidationMessage,i=t.basic.label||"This field";s=e||`${i} must be a valid email`}else if(t.validation.minLength&&n&&i.length<t.validation.minLength){const e=t.validation.customValidationMessage,i=t.basic.label||"This field";s=e||`${i} must be at least ${t.validation.minLength} characters`}else if(t.validation.maxLength&&n&&i.length>t.validation.maxLength){const e=t.validation.customValidationMessage,i=t.basic.label||"This field";s=e||`${i} must be no more than ${t.validation.maxLength} characters`}else if("number-input"===t.name&&n){const e=String(i).trim(),n=parseFloat(e);if(!isNaN(n)){const e=t.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&n<e.lowerLimit?s="Number is below the lower limit":e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&n>e.upperLimit&&(s="Number is above the upper limit")}}k(t=>({...t,[e]:s}))},[r,o,C,de]),he=n(e=>{T(t=>({...t,[e]:!0})),o||setTimeout(()=>{me(e)},0)},[o,me]),be=n(e=>{S[e]&&k(t=>({...t,[e]:""}))},[S]),ge=n(()=>!Object.values(S).some(e=>e&&"string"==typeof e&&""!==e.trim())&&r.every(e=>{const t=C[e.id]||"";let i=!1;if(i=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!i)return!1;if("number-input"===e.name&&i){const i=String(t).trim(),n=parseFloat(i);if(!isNaN(n)){const t=e.validation;if(t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&n<t.lowerLimit)return!1;if(t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&n>t.upperLimit)return!1}}return!0}),[r,C,S]),xe=n((e,t)=>{if(Array.isArray(t))return t.some(t=>xe(e,t));if(null==t||""===t)return!1;const i="string"==typeof t?parseFloat(t):t,n="string"==typeof e.value?parseFloat(e.value):e.value;if(!isNaN(i)&&!isNaN(n))switch(e.operator){case"greaterThan":return i>n;case"lessThan":return i<n;case"greaterThanOrEqual":return i>=n;case"lessThanOrEqual":return i<=n;case"equals":return i===n;case"notEquals":return i!==n;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}},[]),je=n(()=>{if(o)return[];const e=[];return r.forEach(t=>{const i=t?.condition;if(!i||!i.conditions||0===i.conditions.length)return;const n=C[t.id];null!=n&&""!==n&&!(Array.isArray(n)&&0===n.length)&&i.conditions.forEach(i=>{xe(i,n)&&e.push({componentId:t.id,condition:i,componentLabel:t.basic?.label||"Field"})})}),e},[r,C,o,xe]),Ne=n(()=>{if(o)return{isValid:!0};const e=je();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:i}of e){const e=D.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},n=[];if(!0!==t.enableRaiseIssue||R.has(t.id)||n.push("raise an issue"),!0!==t.enableNotes||e.notesCompleted||n.push("add notes"),!0!==t.enableAttachment||e.attachmentsCompleted||n.push("add attachments"),!0!==t.enableSendEmail||e.emailSent||n.push("send email"),n.length>0){return{isValid:!1,errorMessage:`Please ${1===n.length?n[0]:n.slice(0,-1).join(", ")+" and "+n[n.length-1]} for the threshold condition met in "${i}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[o,je,R,D]),Ce=n(e=>{e&&O(t=>{const i=new Set(t);return i.add(e),i})},[]),we=n((e,t,i)=>{e&&V(n=>{const s=new Map(n),r=s.get(e)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===t?s.set(e,{...r,notesCompleted:i}):"attachments"===t?s.set(e,{...r,attachmentsCompleted:i}):"email"===t&&s.set(e,{...r,emailSent:i}),s})},[]);i(()=>{if(!o){const e=Ne();z(e)}},[C,R,D,o,Ne]);const Se=n(()=>{if(o)return!0;let e=!0;A(!0);const t={};return r.forEach(i=>{const n=C[i.id]||"";let s=!1;if(s=Array.isArray(n)?n.length>0:"string"==typeof n?""!==n.trim():null!=n,i.validation.required&&!s){const n=i.validation.customValidationMessage,s=i.basic.label||"This field",r=n||`${s} is required`;t[i.id]=r,e=!1}else if("number-input"===i.name&&s){const s=String(n).trim(),r=parseFloat(s);if(isNaN(r))t[i.id]="";else{const n=i.validation;n&&"lowerLimit"in n&&void 0!==n.lowerLimit&&null!==n.lowerLimit&&0!==n.lowerLimit&&r<n.lowerLimit?(t[i.id]="Number is below the lower limit",e=!1):n&&"upperLimit"in n&&void 0!==n.upperLimit&&null!==n.upperLimit&&0!==n.upperLimit&&r>n.upperLimit?(t[i.id]="Number is above the upper limit",e=!1):t[i.id]=""}}else t[i.id]="";T(e=>({...e,[i.id]:!0}))}),k(t),e},[r,o,C]),ke=n((e="Submitted")=>{if(A(!0),!Se()){const e=r.find(e=>{const t=C[e.id]||"";let i=!1;return i=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!i});if(e){const t=document.getElementById(e.id);t&&t.focus()}return}const t=Ne();if(!t.isValid){t.errorMessage&&H.showError(t.errorMessage);const e=je().find(({condition:e})=>!R.has(e.id));if(e){const t=document.getElementById(e.componentId);t&&t.scrollIntoView({behavior:"smooth",block:"center"})}return}const i=e=>e.map(e=>{let t=C[e.id];"text-input"===e.name&&e.basic,void 0===t&&(t="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 n={...e,basic:{...e.basic,value:t,defaultValue:t,notes:void 0!==M[e.id]?M[e.id]:e.basic?.notes,comments:void 0!==M[e.id]?M[e.id]:e.basic?.comments||e.basic?.notes,attachments:void 0!==P[e.id]?P[e.id]:e.basic?.attachments}};return"section"===n.name&&n.children&&(n.children=i(n.children)),"table"===n.name&&n.cells&&(n.cells=n.cells.map(e=>e.map(e=>{const t={...e};return t.components&&(t.components=i(t.components)),t}))),"datagrid"===n.name&&n.entries&&(n.entries=n.entries.map(e=>{const t={...e};return t.components&&(t.components=i(t.components)),t})),n}),n=i(r),s={...C,status:e};c?.(n,s)},[r,C,Se,c,M,P]),$e=n(()=>({[`device-${a}`]:!0,readonly:o}),[a,o]),Ae=n((e,t)=>{q(i=>({...i,[e]:t}))},[]),Ee=n((e,t)=>{W(i=>({...i,[e]:t||[]}))},[]),Te=s(new Map),Le=s(0),Ie=t=>{let i;if(t.id&&"string"==typeof t.id&&""!==t.id.trim())i=t.id;else{const e=t.basic?.label||"",n=t.name||"unknown",s=`${n}-${e}`;let r=Te.current.get(s);r||(Le.current+=1,r=`generated-${n}-${Le.current}-${Math.random().toString(36).substr(2,9)}`,Te.current.set(s,r),console.warn("[DfFormPreview] Generated and cached ID for component:",r,"key:",s)),i=r,t={...t,id:i}}const n=i,s=C[n];if(void 0!==s){const e=r.filter(e=>e.id!==n&&C[e.id]===s);e.length>0&&console.warn(`[DfFormPreview] Component ${n} shares form value with other components:`,e.map(e=>e.id))}const a={id:n,validationErrors:S,formValue:s,touchedFields:E,formSubmitted:$,mode:"test",readonly:!1,onValueChange:X,onBlur:()=>he(n),onFocus:()=>be(n)};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:Ce,raisedThresholdIssues:R,workOrderNumber:y,assetNumber:v,user:N});case"textarea":return B.jsx(Q,{...a,properties:t});case"select":const i={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ee,{...a,properties:i});case"checkbox":const n={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(te,{...a,properties:n});case"radio":const o={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ie,{...a,properties:o});case"segment":const l={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ne,{...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:C,formTemplateId:p,onThresholdActionCompletion:we,onThresholdIssueRaised:Ce,onNotesChange:Ae,onAttachmentChange:Ee,workOrderNumber:y,assetNumber:v,renderFormComponent:e=>Ie(e)});case"table":return B.jsx(e.Suspense,{fallback:B.jsx("div",{children:"Loading table..."}),children:B.jsx(ve,{...a,properties:t,formData:C,formTemplateId:p,mode:a.mode,validationErrors:S,touchedFields:E,formSubmitted:$,onThresholdActionCompletion:we,onThresholdIssueRaised:Ce,workOrderNumber:y,assetNumber:v,onNotesChange:(e,i)=>{const n=r.map(n=>{if(n.id===t.id&&n.cells){const t=n.cells.map(t=>t.map(t=>{if(t.components){const n=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:i}}:t);return{...t,components:n}}return t}));return{...n,cells:t}}return n});d?.(n)},onAttachmentChange:(e,i)=>{const n=r.map(n=>{if(n.id===t.id&&n.cells){const t=n.cells.map(t=>t.map(t=>{if(t.components){const n=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:i||[]}}:t);return{...t,components:n}}return t}));return{...n,cells:t}}return n});d?.(n)},renderFormComponent:e=>Ie(e)})});case"datagrid":return B.jsx(ye,{...a,properties:t,formData:C,formTemplateId:p,mode:a.mode,validationErrors:S,touchedFields:E,formSubmitted:$,onThresholdActionCompletion:we,onThresholdIssueRaised:Ce,workOrderNumber:y,assetNumber:v,onComponentSelect:h,onComponentDelete:f,onComponentEdit:b,onComponentUpdate:g,selectedComponent:x,onNotesChange:(e,i)=>{Ae(e,i);const n=r.map(n=>{if(n.id===t.id&&n.entries){const t=n.entries.map(t=>{if(t.components){const n=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:i||""}}:t);return{...t,components:n}}return t});return{...n,entries:t}}return n});d?.(n)},onAttachmentChange:(e,i)=>{Ee(e,i);const n=r.map(n=>{if(n.id===t.id&&n.entries){const t=n.entries.map(t=>{if(t.components){const n=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:i||[]}}:t);return{...t,components:n}}return t});return{...n,entries:t}}return n});d?.(n)},onValueChange:e=>{if(e.id===t.id&&e.value&&"object"==typeof e.value&&"entries"in e.value){const i=r.map(i=>i.id===t.id?{...i,...e.value}:i);d?.(i),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!==C[e.id]);else{const t=e.basic?.defaultValue;void 0!==t&&w(i=>({...i,[e.id]:t}))}})})}else X(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=C[t.id];if(e&&"object"==typeof e&&"entries"in e){const i=r.map(i=>i.id===t.id?{...i,entries:e.entries}:i);d?.(i)}},100)},onEntryRemove:e=>{const i=r.map(i=>{if(i.id===t.id&&i.entries){const t=(i.entries||[]).filter((t,i)=>i!==e).map((e,t)=>({...e,index:t,id:`entry-${i.id}-${t}`,components:e.components?.map((e,i)=>{const n=(e.templateComponents||[])[i];return{...e,id:n?`${n.id}-entry-${t}-${i}`:e.id}})||[]}));return{...i,entries:t}}return i});d?.(i)},renderFormComponent:e=>Ie(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($e()).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(),ke()},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,i=C[e.id],n=["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(n&&null!=i&&""!==i)if("checkbox"===e.name){l=(Array.isArray(i)?i:[i]).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===i);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:K(e.id)?"block":"none"},children:[Ie(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:i,onThresholdActionCompletion:we,onThresholdIssueRaised:Ce,onNotesChange:t=>{q(i=>({...i,[e.id]:t}));const i=r.map(i=>i.id===e.id?{...i,basic:{...i.basic,notes:t||""}}:i);d?.(i)},onAttachmentChange:t=>{W(i=>({...i,[e.id]:t||[]}));const i=r.map(i=>i.id===e.id?{...i,basic:{...i.basic,attachments:t||[]}}:i);d?.(i)},notes:void 0!==M[e.id]?M[e.id]:e.basic?.notes||"",attachments:void 0!==P[e.id]?P[e.id]:e.basic?.attachments||null,workOrderNumber:y,assetNumber:v,isStandalone:j,user:N}),o&&c&&B.jsx(pe,{component:e})]},e.id)}),!o&&B.jsxs("div",{className:"form-actions",children:[B.jsx("button",{type:"button",onClick:()=>ke("Saved"),className:"form-save-button",disabled:$&&!ge(),children:"Save"}),B.jsx("button",{type:"button",disabled:!ge()||!F.isValid,className:"form-submit-button",title:F.isValid?"":F.errorMessage,onClick:()=>ke("Submitted"),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);i(()=>{u(e),p(!1)},[e]);const h=n(t=>{const i=t.target.value;u(i),p(i!==e)},[e]),f=n(()=>{m&&s&&!o&&(s(d),p(!1))},[m,s,d,o]),b=n(()=>{},[]),g=n(()=>{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:z()},we=({component:e,mode:t,renderFormComponent:i,formData:n={},formTemplateId:s,onThresholdActionCompletion:r,onThresholdIssueRaised:a,onNotesChange:o,onAttachmentChange:l,workOrderNumber:c,assetNumber:d})=>{const u=n[e.id],m="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:[i(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:s,formValue:u,onThresholdActionCompletion:r,onThresholdIssueRaised:a,onNotesChange:o?t=>o(e.id,t):void 0,onAttachmentChange:l?t=>l(e.id,t):void 0,workOrderNumber:c,assetNumber:d}),m&&B.jsx(pe,{component:e})]})},Se=({component:e,selectedComponent:t,mode:i,onComponentSelect:n,onComponentDelete:s,onComponentEdit:r,renderFormComponent:a,isOverlay:o=!1})=>{const{attributes:l,listeners:c,setNodeRef:d,transform:m,transition:p,isDragging:h,isSorting:f}=D({id:e.id,disabled:o}),b={transform:F.Transform.toString(m),transition:p,opacity:h?.3:1,zIndex:h?1e3:"auto"};return B.jsxs("div",{ref:d,style:b,className:`form-component table-component ${t?.id===e.id?"selected":""} ${h?"dragging":""} ${f?"sorting":""}`,onClick:()=>!h&&n(e),role:"button",tabIndex:0,children:["edit"===i&&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"===i&&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(A,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),s(e,t)},type:"button",title:"Delete Component",children:B.jsx(u,{size:12})})]})]})},ke=({cell:e,mode:t,onComponentSelect:i,onComponentDelete:n,onComponentEdit:s,selectedComponent:r,renderFormComponent:a,formData:o={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,tableId:u,onNotesChange:m,onAttachmentChange:p,workOrderNumber:h,assetNumber:f})=>{const b=`table-cell-${u}-${e.row}-${e.column}`,{setNodeRef:g,isOver:x}=I({id:b,disabled:"edit"!==t,data:{type:"table-cell",tableId:u,cell:e,row:e.row,column:e.column}}),y={...e.styles,backgroundColor:x?"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":x?"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:g,style:y,className:"table-cell "+(x?"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||z()),strategy:O,children:e.components.map(e=>{const o=Ce(e);return B.jsx(Se,{component:o,selectedComponent:r,mode:t,onComponentSelect:i,onComponentDelete:n,onComponentEdit:s,renderFormComponent:a},o.id)})}):e.components.map(e=>{const i=e.id?e:Ce(e);return B.jsx(we,{component:i,mode:t,renderFormComponent:a,formData:o,formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,onNotesChange:m,onAttachmentChange:p,workOrderNumber:h,assetNumber:f},i.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:" "})})})},$e=({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:x,selectedComponent:y,renderFormComponent:v,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,onNotesChange:w,onAttachmentChange:$,workOrderNumber:A,assetNumber:E})=>{const[L,I]=t(!1),R=s.cells?.some(e=>e.some(e=>e.components&&e.components.length>0))||!1;i(()=>{},[s.table?.rows,s.table?.columns,s.basic?.rows,s.basic?.columns,s.cells,e,u]);const O=n(e=>{e.stopPropagation(),m?.(),f?.(s)},[m,f,s]),D=n((t,i)=>{i.stopPropagation();const n=s.cells.map(e=>e.map(e=>{if(e.components&&e.components.some(e=>e.id===t.id)){const i=e.components.filter(e=>e.id!==t.id);return{...e,components:i}}return e}));u&&u({id:e,value:{...s,cells:n}})},[g,s,u,e]),V=r(()=>s.cells?s.cells.map((t,i)=>t.map((t,n)=>({...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-${i}-cell-${n}-comp-${s}`;return{...t,id:r}}):[]}))):[],[s.cells,e]),F=v||n(e=>{const t=e.id?e:Ce(e),i=o[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let n=i;"number-input"===t.name&&"number"==typeof i?n=String(i):"number-input"===t.name&&null==i&&(n="");const s={id:t.id,properties:t,validationErrors:{},formValue:n,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 i={...t,options:t.basic?.options||[]};return B.jsx(te,{...s,properties:i,formValue:[],disabled:!1});case"radio":const n={...t,options:t.basic?.options||[]};return B.jsx(ie,{...s,properties:n,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]})}},[v,a,o,u]),z={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"},M={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 R||"preview"!==a?B.jsxs("div",{className:`form-group df-form-table ${p?"selected":""} ${"preview"===a?"preview-mode":"test"===a?"test-mode":""} ${h}`,onClick:O,style:z,children:[B.jsx("div",{className:"table-header",children:B.jsx("div",{className:"table-title",onClick:t=>{t.stopPropagation(),I(!L),u?.({id:e,value:{...s,basic:{...s.basic||{},collapsed:!L}}})},children:B.jsxs("div",{className:"title-content",children:[L?B.jsx(k,{size:16}):B.jsx(S,{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&&!L&&B.jsx("div",{className:"table-description",children:s.basic.description}),!L&&B.jsxs("div",{className:"table-content",children:[null,B.jsxs("table",{style:M,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 i=(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:i},`header-${t}`)})})}),B.jsx("tbody",{children:V.map((t,i)=>B.jsx("tr",{className:"table-row",children:t.map(t=>B.jsx(ke,{cell:t,mode:a,onComponentSelect:b||(()=>{}),onComponentDelete:D,onComponentEdit:x,selectedComponent:y||null,renderFormComponent:F,formData:o,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,tableId:e,onNotesChange:w,onAttachmentChange:$,workOrderNumber:A,assetNumber:E},t.id))},i))})]})]})]}):null};var Ae=Object.freeze({__proto__:null,DfFormTable:$e,default:$e});const Ee={page:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',padding:"30px",backgroundColor:"#ffffff",color:"#000000",lineHeight:"1.4"},header:{marginBottom:"30px",paddingBottom:"15px",borderBottom:"2px solid #303992",display:"flex",justifyContent:"space-between",alignItems:"flex-end"},title:{margin:"0 0 5px 0",fontSize:"24px",fontWeight:"bold",color:"#303992"},description:{margin:"0",fontSize:"14px",color:"#666666"},submittedBy:{fontSize:"14px",color:"#333",textAlign:"right",whiteSpace:"nowrap",marginBottom:"2px"},formGroup:{marginBottom:"20px",breakInside:"avoid"},label:{fontWeight:"400",display:"block",marginBottom:"8px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",fontColor:"var(--df-color-text-dark)"},labelLeft:{fontWeight:"400",display:"block",marginRight:"10px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",width:"60%",fontColor:"var(--df-color-text-dark)"},valueContainer:{border:"1px solid #e2e8f0",borderRadius:"6px",padding:"8px 12px",backgroundColor:"#ffffff",minHeight:"20px",fontSize:"14px",flex:1},value:{fontSize:"14px",color:"#000000"},gridRow:{display:"flex",flexWrap:"wrap",gap:"16px",marginBottom:"20px"},gridCol:e=>({flex:`0 0 calc(${e/12*100}% - 8px)`,minWidth:"0"}),img:{maxWidth:"100%",maxHeight:"300px",border:"1px solid #ddd",borderRadius:"4px",display:"block",marginTop:"5px"},table:{width:"100%",borderCollapse:"collapse",border:"1px solid #ddd",marginTop:"10px",tableLayout:"fixed"},th:{border:"1px solid #ddd",padding:"8px",backgroundColor:"#f5f5f5",fontWeight:"bold",textAlign:"left",fontSize:"13px"},td:{border:"1px solid #ddd",padding:"8px",fontSize:"13px",verticalAlign:"top"},section:{marginBottom:"25px",breakInside:"avoid"},sectionHeader:{fontSize:"18px",marginBottom:"15px",display:"block",fontWeight:"600"},sectionChildren:{marginLeft:"20px",paddingLeft:"20px",borderLeft:"2px solid #3b82f6",marginTop:"15px"},notesSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",fontSize:"13px",boxSizing:"border-box"},notesLabel:{fontWeight:"bold",color:"#303992",marginRight:"5px"},attachmentsSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",display:"flex",flexWrap:"wrap",gap:"10px",boxSizing:"border-box"},attachmentThumbnail:{width:"60px",height:"60px",border:"1px solid #e5e7eb",borderRadius:"4px",overflow:"hidden",backgroundColor:"#fff",display:"flex",alignItems:"center",justifyContent:"center"},attachmentImg:{width:"100%",height:"100%",objectFit:"cover"},segmentContainer:{display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center"},segmentButton:{display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",borderRadius:"6px",border:"1px solid #e0e0e0",backgroundColor:"#ffffff",fontSize:"10px",fontWeight:600,minWidth:"30px",color:"#666"},segmentIcon:{marginRight:"4px",fontSize:"9px",fontWeight:"bold",display:"inline-block",lineHeight:"1"},checkboxItem:{display:"flex",alignItems:"center",padding:"10px 14px",backgroundColor:"#f8f9fa",borderRadius:"6px",marginBottom:"8px",width:"100%",boxSizing:"border-box"}},Te=e=>{if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.startsWith("data:image")||t.startsWith("iVBORw0KGgo")||t.startsWith("/9j/4AAQ")||t.startsWith("UklGR")||t.startsWith("R0lGOD")},Le=(e,t)=>{if(!e)return"";const i=e.trim();return i.startsWith("data:")||i.startsWith("http")||i.startsWith("blob:")||i.startsWith("/")?i:i.startsWith("iVBORw0KGgo")?`data:image/png;base64,${i}`:i.startsWith("/9j/4AAQ")?`data:image/jpeg;base64,${i}`:i.startsWith("UklGR")?`data:image/webp;base64,${i}`:i.startsWith("R0lGOD")?`data:image/gif;base64,${i}`:t&&t.startsWith("image/")?`data:${t};base64,${i}`:i},Ie=e=>{if(null!=e?.icon)return e.icon;return"pass"===(e=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"})(e?.value||e)?"✓":"×"},Re=({component:e})=>{const t=e.basic?.notes||"",i=e.basic?.attachments||[];return t.trim()||0!==i.length?B.jsxs("div",{style:{marginTop:"5px"},children:[t.trim().length>0&&B.jsxs("div",{style:Ee.notesSection,children:[B.jsx("span",{style:Ee.notesLabel,children:"Notes:"}),t]}),i.length>0&&B.jsx("div",{style:Ee.attachmentsSection,children:i.map((e,t)=>{const i=!(!e.data&&!e.url),n=(e.type?.startsWith("image/")||Te(e.data||e.url||""))&&i?Le(e.data||e.url||"",e.type):null;return B.jsx("div",{style:Ee.attachmentThumbnail,children:n?B.jsx("img",{src:n,alt:e.name||"Attachment",style:Ee.attachmentImg}):B.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},t)})})]}):null},Oe=({component:e})=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue,{name:i}=e;if("signature"===i)return t&&Te(t)?B.jsx("div",{style:{marginTop:"5px"},children:B.jsx("img",{src:Le(t),alt:"Signature",style:{...Ee.img,maxHeight:"100px",width:"auto"}})}):B.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===i){const i=e.basic?.options||[],n=Array.isArray(t)?t:[t];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:i.map((e,t)=>{const i=n.includes(e.value);return B.jsxs("div",{style:Ee.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(i?"#303992":"#cbd5e1"),borderRadius:"4px",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:i?"#303992":"#ffffff"},children:i&&B.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("radio"===i){const i=e.basic?.options||[];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:i.map((e,i)=>{const n=t===e.value;return B.jsxs("div",{style:Ee.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(n?"#303992":"#cbd5e1"),borderRadius:"50%",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#ffffff"},children:n&&B.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},i)})})}if("segment"===i){const i=e.basic?.options||[],n=t;return B.jsx("div",{style:Ee.segmentContainer,children:i.map((e,t)=>{const i=n===e.value,s=Ie(e),r=e.color||"#666";let a={...Ee.segmentButton};return a=i?{...a,backgroundColor:r,color:"#ffffff",borderColor:r}:{...a,backgroundColor:"#ffffff",color:r,borderColor:r},B.jsxs("div",{style:a,children:[B.jsx("span",{style:Ee.segmentIcon,children:s}),B.jsx("span",{children:e.value})]},t)})})}if("file"===i){const e=(Array.isArray(t)?t:t?[t]:[]).filter(e=>{const t=!(!e.data&&!e.url),i=e.type&&e.type.startsWith("image/"),n=t&&Te(e.data||e.url);return i||n});return e.length>0?B.jsx("div",{style:{marginTop:"10px"},children:e.map((e,t)=>{const i=Le(e.data||e.url,e.type);return i?B.jsx("img",{src:i,alt:e.name||"File",style:{...Ee.img,marginBottom:"10px"}},t):null})}):B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===i){if(t&&"object"==typeof t){const e=t;return B.jsxs("div",{style:{fontSize:"14px"},children:[e.placeName&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Place:"})," ",e.placeName]}),(e.city||e.country)&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Address:"})," ",[e.city,e.country].filter(Boolean).join(", ")]}),e.latitude&&e.longitude&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Coordinates:"})," ",e.latitude.toFixed(6),", ",e.longitude.toFixed(6)]}),e.timestamp&&B.jsxs("div",{children:[B.jsx("strong",{children:"Captured:"})," ",new Date(e.timestamp).toLocaleString()]})]})}return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===i){const t=e.basic?.instructions||[],i=e.validation?.listStyle||"numbers";if(!Array.isArray(t)||0===t.length)return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const n=()=>B.jsx("div",{dangerouslySetInnerHTML:{__html:t.join("")}});return"numbers"===i?B.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(n,{})}):"bullets"===i?B.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(n,{})}):B.jsx("div",{style:{margin:"10px 0"},children:B.jsx(n,{})})}const n="object"==typeof t?JSON.stringify(t):String(t);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid"].includes(i)){const e="textarea"===i;return B.jsx("div",{style:{...Ee.valueContainer,...e?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}},children:B.jsx("div",{style:Ee.value,children:n})})}return B.jsx("div",{style:Ee.value,children:n})},De=({component:e})=>{const{name:t,basic:i,styles:n,validation:s}=e,r=i?.label,a=s?.required,o="left"===(n?.labelAlignment||"top");if("section"===t){const t=n?.headerBackgroundColor,s=n?.headerTextColor,o={...Ee.sectionHeader,...t?{backgroundColor:t,padding:"8px",borderRadius:"4px"}:{},...s?{color:s}:{},display:"flex",alignItems:"center"};return B.jsxs("div",{style:Ee.section,children:[r&&B.jsx("label",{style:o,children:B.jsxs("span",{style:{flex:1},children:[r,a&&" *"]})}),i?.description&&B.jsx("p",{style:{...Ee.description,marginBottom:"15px"},children:i.description}),B.jsx(Re,{component:e}),B.jsx("div",{style:Ee.sectionChildren,children:B.jsx(Ve,{components:e.children||[]})})]})}if("heading"===t){const e=`h${Math.max(1,Math.min(6,n?.level??i?.level??1))}`,t={...n?.headerBackgroundColor?{backgroundColor:n.headerBackgroundColor,padding:"8px",borderRadius:"4px"}:{},...n?.headerTextColor?{color:n.headerTextColor}:{},...n?.fontSize?{fontSize:n.fontSize}:{},...n?.textAlign?{textAlign:n.textAlign}:{},marginTop:0,marginBottom:"15px"};return B.jsx("div",{style:Ee.formGroup,children:B.jsx(e,{style:t,children:i?.label||i?.value})})}if("table"===t){const t=e.cells||[],i=Math.max(0,...t.map(e=>e?e.length:0)),s=i>0?100/i:100,o=n?.headerBackgroundColor,l=n?.headerTextColor,c={...Ee.label,...o?{backgroundColor:o,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...l?{color:l}:{}};return B.jsxs("div",{style:Ee.formGroup,children:[r&&B.jsxs("label",{style:c,children:[r,a&&" *"]}),B.jsx("table",{style:Ee.table,children:B.jsx("tbody",{children:t.map((e,t)=>B.jsx("tr",{children:e&&e.map((e,t)=>B.jsx("td",{style:{...Ee.td,width:`${s}%`},children:e.components&&e.components.map((e,t)=>B.jsxs("div",{style:{marginBottom:"8px"},children:[e.basic?.label&&B.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[e.basic.label,":"]}),B.jsx(Oe,{component:e}),B.jsx(Re,{component:e})]},t))},t))},t))})})]})}if("datagrid"===t){const t=e.entries||[];let i=e.templateComponents||[];0===i.length&&t.length>0&&t[0]?.components&&(i=t[0].components.map(e=>({...e,basic:{...e.basic,label:e.basic?.label||e.name}})));const s=n?.headerBackgroundColor,o=n?.headerTextColor,l={...Ee.label,...s?{backgroundColor:s,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...o?{color:o}:{}},c=t.filter(e=>!(!e.components||0===e.components.length)&&e.components.some(e=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue;return Array.isArray(t)?t.length>0:null!=t&&""!==String(t).trim()}));return 0===c.length?B.jsxs("div",{style:Ee.formGroup,children:[r&&B.jsxs("label",{style:l,children:[r,a&&" *"]}),B.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):B.jsxs("div",{style:Ee.formGroup,children:[r&&B.jsxs("label",{style:l,children:[r,a&&" *"]}),B.jsxs("table",{style:Ee.table,children:[B.jsx("thead",{children:B.jsx("tr",{children:i.map((e,t)=>B.jsx("th",{style:Ee.th,children:e.basic?.label||e.name},t))})}),B.jsx("tbody",{children:c.map((e,t)=>B.jsx("tr",{children:i.map((t,i)=>{const n=e.components[i];return B.jsx("td",{style:Ee.td,children:n?B.jsxs(B.Fragment,{children:[B.jsx(Oe,{component:n}),B.jsx(Re,{component:n})]}):"N/A"},i)})},t))})]})]})}if(o&&"instructions"!==t){const i=["segment"].includes(t);return B.jsxs("div",{style:Ee.formGroup,children:[B.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[r&&B.jsxs("label",{style:Ee.labelLeft,children:[r,a&&" *"]}),B.jsx("div",{style:{flex:1,...i?{display:"flex",justifyContent:"flex-end"}:{}},children:B.jsx(Oe,{component:e})})]}),B.jsx(Re,{component:e})]})}return B.jsxs("div",{style:Ee.formGroup,children:[r&&B.jsxs("label",{style:Ee.label,children:[r,a&&" *"]}),B.jsx(Oe,{component:e}),B.jsx(Re,{component:e})]})},Ve=({components:e})=>{if(!e||0===e.length)return null;const t=[];let i=[],n=0;return e.forEach(e=>{const s=["section","table","datagrid","heading","instructions"].includes(e.name),r=s?12:e.styles?.column||12;n+r>12&&i.length>0&&(t.push(i),i=[],n=0),i.push(e),n+=r,(s||n>=12)&&n>0&&(t.push(i),i=[],n=0)}),i.length>0&&t.push(i),B.jsx(B.Fragment,{children:t.map((e,t)=>1===e.length?B.jsx(De,{component:e[0]},e[0].id||t):B.jsx("div",{style:Ee.gridRow,children:e.map((e,t)=>{const i=e.styles?.column||12;return B.jsx("div",{style:Ee.gridCol(i),children:B.jsx(De,{component:e})},e.id||t)})},t))})},Fe=({formTitle:e,formDescription:t,userName:i,components:n})=>B.jsxs("div",{className:"pdf-container",style:Ee.page,children:[B.jsxs("div",{style:Ee.header,children:[B.jsxs("div",{children:[B.jsx("h1",{style:Ee.title,children:e}),t&&B.jsx("p",{style:Ee.description,children:t})]}),i&&B.jsxs("div",{style:Ee.submittedBy,children:[B.jsx("strong",{children:"Submitted By:"})," ",i]})]}),B.jsx("div",{className:"form-content",children:B.jsx(Ve,{components:n})})]});var ze;!function(e){e.Top="top",e.Left="left"}(ze||(ze={}));export{ue as ComponentActionFeatures,pe as ComponentSubmissionActions,te as DfFormCheckbox,Ne as DfFormComments,ye as DfFormDataGrid,se as DfFormDateTime,J as DfFormErrorMsg,ae as DfFormFileUpload,le as DfFormHeading,Z as DfFormInput,ce as DfFormInstruction,oe as DfFormLocation,je as DfFormPreview,ie as DfFormRadio,fe as DfFormSection,ne as DfFormSegment,ee as DfFormSelect,re as DfFormSignature,$e as DfFormTable,Q as DfFormTextarea,ze as ELabelAlignment,Fe as FormSubmissionPdf,K as RaiseIssueModal,X as ThresholdAlert,G as conditionalLogicService,H as toastService};
|
|
11
11
|
//# sourceMappingURL=index.esm.js.map
|