df-ae-forms-package 1.0.43 → 1.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -7,7 +7,7 @@ import t,{useState as e,useEffect as A,useCallback as r,useRef as n,useMemo as i
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */"production"===process.env.NODE_ENV?z.exports=function(){if(V)return G;V=1;var e=t,A=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function a(t,e,r){var a,o={},l=null,c=null;for(a in void 0!==r&&(l=""+r),void 0!==e.key&&(l=""+e.key),void 0!==e.ref&&(c=e.ref),e)n.call(e,a)&&!s.hasOwnProperty(a)&&(o[a]=e[a]);if(t&&t.defaultProps)for(a in e=t.defaultProps)void 0===o[a]&&(o[a]=e[a]);return{$$typeof:A,type:t,key:l,ref:c,props:o,_owner:i.current}}return G.Fragment=r,G.jsx=a,G.jsxs=a,G}():z.exports=(q||(q=1,"production"!==process.env.NODE_ENV&&function(){var e,A=t,r=Symbol.for("react.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),o=Symbol.for("react.provider"),l=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),g=Symbol.iterator,m=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(t){for(var e=arguments.length,A=new Array(e>1?e-1:0),r=1;r<e;r++)A[r-1]=arguments[r];!function(t,e,A){var r=m.ReactDebugCurrentFrame.getStackAddendum();""!==r&&(e+="%s",A=A.concat([r]));var n=A.map(function(t){return String(t)});n.unshift("Warning: "+e),Function.prototype.apply.call(console[t],console,n)}("error",t,A)}function v(t){return t.displayName||"Context"}function B(t){if(null==t)return null;if("number"==typeof t.tag&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof t)return t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case i:return"Fragment";case n:return"Portal";case a:return"Profiler";case s:return"StrictMode";case u:return"Suspense";case h:return"SuspenseList"}if("object"==typeof t)switch(t.$$typeof){case l:return v(t)+".Consumer";case o:return v(t._context)+".Provider";case c:return function(t,e,A){var r=t.displayName;if(r)return r;var n=e.displayName||e.name||"";return""!==n?A+"("+n+")":A}(t,t.render,"ForwardRef");case d:var e=t.displayName||null;return null!==e?e:B(t.type)||"Memo";case f:var A=t,r=A._payload,p=A._init;try{return B(p(r))}catch(t){return null}}return null}e=Symbol.for("react.module.reference");var b,y,C,x,F,Q,U,E=Object.assign,N=0;function S(){}S.__reactDisabledLog=!0;var L,I=m.ReactCurrentDispatcher;function _(t,e,A){if(void 0===L)try{throw Error()}catch(t){var r=t.stack.trim().match(/\n( *(at )?)/);L=r&&r[1]||""}return"\n"+L+t}var O,k=!1,T="function"==typeof WeakMap?WeakMap:Map;function j(t,e){if(!t||k)return"";var A,r=O.get(t);if(void 0!==r)return r;k=!0;var n,i=Error.prepareStackTrace;Error.prepareStackTrace=void 0,n=I.current,I.current=null,function(){if(0===N){b=console.log,y=console.info,C=console.warn,x=console.error,F=console.group,Q=console.groupCollapsed,U=console.groupEnd;var t={configurable:!0,enumerable:!0,value:S,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}N++}();try{if(e){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(t){A=t}Reflect.construct(t,[],s)}else{try{s.call()}catch(t){A=t}t.call(s.prototype)}}else{try{throw Error()}catch(t){A=t}t()}}catch(e){if(e&&A&&"string"==typeof e.stack){for(var a=e.stack.split("\n"),o=A.stack.split("\n"),l=a.length-1,c=o.length-1;l>=1&&c>=0&&a[l]!==o[c];)c--;for(;l>=1&&c>=0;l--,c--)if(a[l]!==o[c]){if(1!==l||1!==c)do{if(l--,--c<0||a[l]!==o[c]){var u="\n"+a[l].replace(" at new "," at ");return t.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",t.displayName)),"function"==typeof t&&O.set(t,u),u}}while(l>=1&&c>=0);break}}}finally{k=!1,I.current=n,function(){if(0===--N){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:E({},t,{value:b}),info:E({},t,{value:y}),warn:E({},t,{value:C}),error:E({},t,{value:x}),group:E({},t,{value:F}),groupCollapsed:E({},t,{value:Q}),groupEnd:E({},t,{value:U})})}N<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=i}var h=t?t.displayName||t.name:"",d=h?_(h):"";return"function"==typeof t&&O.set(t,d),d}function H(t,e,A){if(null==t)return"";if("function"==typeof t)return j(t,!(!(r=t.prototype)||!r.isReactComponent));var r;if("string"==typeof t)return _(t);switch(t){case u:return _("Suspense");case h:return _("SuspenseList")}if("object"==typeof t)switch(t.$$typeof){case c:return j(t.render,!1);case d:return H(t.type,e,A);case f:var n=t,i=n._payload,s=n._init;try{return H(s(i),e,A)}catch(t){}}return""}O=new T;var P=Object.prototype.hasOwnProperty,D={},M=m.ReactDebugCurrentFrame;function R(t){if(t){var e=t._owner,A=H(t.type,t._source,e?e.type:null);M.setExtraStackFrame(A)}else M.setExtraStackFrame(null)}var K=Array.isArray;function V(t){return K(t)}function z(t){return""+t}function G(t){if(function(t){try{return z(t),!1}catch(t){return!0}}(t))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(t){return"function"==typeof Symbol&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object"}(t)),z(t)}var q,X,Y,J=m.ReactCurrentOwner,$={key:!0,ref:!0,__self:!0,__source:!0};function Z(t,e,A,n,i){var s,a={},o=null,l=null;for(s in void 0!==A&&(G(A),o=""+A),function(t){if(P.call(t,"key")){var e=Object.getOwnPropertyDescriptor(t,"key").get;if(e&&e.isReactWarning)return!1}return void 0!==t.key}(e)&&(G(e.key),o=""+e.key),function(t){if(P.call(t,"ref")){var e=Object.getOwnPropertyDescriptor(t,"ref").get;if(e&&e.isReactWarning)return!1}return void 0!==t.ref}(e)&&(l=e.ref,function(t,e){if("string"==typeof t.ref&&J.current&&e&&J.current.stateNode!==e){var A=B(J.current.type);Y[A]||(w('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',B(J.current.type),t.ref),Y[A]=!0)}}(e,i)),e)P.call(e,s)&&!$.hasOwnProperty(s)&&(a[s]=e[s]);if(t&&t.defaultProps){var c=t.defaultProps;for(s in c)void 0===a[s]&&(a[s]=c[s])}if(o||l){var u="function"==typeof t?t.displayName||t.name||"Unknown":t;o&&function(t,e){var A=function(){q||(q=!0,w("%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)",e))};A.isReactWarning=!0,Object.defineProperty(t,"key",{get:A,configurable:!0})}(a,u),l&&function(t,e){var A=function(){X||(X=!0,w("%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)",e))};A.isReactWarning=!0,Object.defineProperty(t,"ref",{get:A,configurable:!0})}(a,u)}return function(t,e,A,n,i,s,a){var o={$$typeof:r,type:t,key:e,ref:A,props:a,_owner:s,_store:{}};return Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o}(t,o,l,i,n,J.current,a)}Y={};var tt,et=m.ReactCurrentOwner,At=m.ReactDebugCurrentFrame;function rt(t){if(t){var e=t._owner,A=H(t.type,t._source,e?e.type:null);At.setExtraStackFrame(A)}else At.setExtraStackFrame(null)}function nt(t){return"object"==typeof t&&null!==t&&t.$$typeof===r}function it(){if(et.current){var t=B(et.current.type);if(t)return"\n\nCheck the render method of `"+t+"`."}return""}tt=!1;var st={};function at(t,e){if(t._store&&!t._store.validated&&null==t.key){t._store.validated=!0;var A=function(t){var e=it();if(!e){var A="string"==typeof t?t:t.displayName||t.name;A&&(e="\n\nCheck the top-level render call using <"+A+">.")}return e}(e);if(!st[A]){st[A]=!0;var r="";t&&t._owner&&t._owner!==et.current&&(r=" It was passed a child from "+B(t._owner.type)+"."),rt(t),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',A,r),rt(null)}}}function ot(t,e){if("object"==typeof t)if(V(t))for(var A=0;A<t.length;A++){var r=t[A];nt(r)&&at(r,e)}else if(nt(t))t._store&&(t._store.validated=!0);else if(t){var n=function(t){if(null===t||"object"!=typeof t)return null;var e=g&&t[g]||t["@@iterator"];return"function"==typeof e?e:null}(t);if("function"==typeof n&&n!==t.entries)for(var i,s=n.call(t);!(i=s.next()).done;)nt(i.value)&&at(i.value,e)}}function lt(t){var e,A=t.type;if(null!=A&&"string"!=typeof A){if("function"==typeof A)e=A.propTypes;else{if("object"!=typeof A||A.$$typeof!==c&&A.$$typeof!==d)return;e=A.propTypes}if(e){var r=B(A);!function(t,e,A,r,n){var i=Function.call.bind(P);for(var s in t)if(i(t,s)){var a=void 0;try{if("function"!=typeof t[s]){var o=Error((r||"React class")+": "+A+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw o.name="Invariant Violation",o}a=t[s](e,s,r,A,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(t){a=t}!a||a instanceof Error||(R(n),w("%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).",r||"React class",A,s,typeof a),R(null)),a instanceof Error&&!(a.message in D)&&(D[a.message]=!0,R(n),w("Failed %s type: %s",A,a.message),R(null))}}(e,t.props,"prop",r,t)}else void 0===A.PropTypes||tt||(tt=!0,w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",B(A)||"Unknown"));"function"!=typeof A.getDefaultProps||A.getDefaultProps.isReactClassApproved||w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ct={};function ut(t,A,n,g,m,v){var b=function(t){return"string"==typeof t||"function"==typeof t||t===i||t===a||t===s||t===u||t===h||t===p||"object"==typeof t&&null!==t&&(t.$$typeof===f||t.$$typeof===d||t.$$typeof===o||t.$$typeof===l||t.$$typeof===c||t.$$typeof===e||void 0!==t.getModuleId)}(t);if(!b){var y="";(void 0===t||"object"==typeof t&&null!==t&&0===Object.keys(t).length)&&(y+=" 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,x=function(t){return void 0!==t?"\n\nCheck your code at "+t.fileName.replace(/^.*[\\\/]/,"")+":"+t.lineNumber+".":""}(m);y+=x||it(),null===t?C="null":V(t)?C="array":void 0!==t&&t.$$typeof===r?(C="<"+(B(t.type)||"Unknown")+" />",y=" Did you accidentally export a JSX literal instead of a component?"):C=typeof t,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,y)}var F=Z(t,A,n,m,v);if(null==F)return F;if(b){var Q=A.children;if(void 0!==Q)if(g)if(V(Q)){for(var U=0;U<Q.length;U++)ot(Q[U],t);Object.freeze&&Object.freeze(Q)}else w("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 ot(Q,t)}if(P.call(A,"key")){var E=B(t),N=Object.keys(A).filter(function(t){return"key"!==t}),S=N.length>0?"{key: someKey, "+N.join(": ..., ")+": ...}":"{key: someKey}";ct[E+S]||(w('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} />',S,E,N.length>0?"{"+N.join(": ..., ")+": ...}":"{}",E),ct[E+S]=!0)}return t===i?function(t){for(var e=Object.keys(t.props),A=0;A<e.length;A++){var r=e[A];if("children"!==r&&"key"!==r){rt(t),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",r),rt(null);break}}null!==t.ref&&(rt(t),w("Invalid attribute `ref` supplied to `React.Fragment`."),rt(null))}(F):lt(F),F}var ht=function(t,e,A){return ut(t,e,A,!1)},dt=function(t,e,A){return ut(t,e,A,!0)};W.Fragment=i,W.jsx=ht,W.jsxs=dt}()),W);var X=z.exports;class Y{constructor(){}static getInstance(){return Y.instance||(Y.instance=new Y),Y.instance}getAvailableComponentsForConditional(t,e){if(!t||!Array.isArray(t))return[];const A=t.filter(t=>!e||t.id!==e).map(t=>{var e;return{id:t.id,label:(null===(e=t.basic)||void 0===e?void 0:e.label)||t.id,type:t.name,key:t.id}}).sort((t,e)=>t.label.localeCompare(e.label));return A}getApplicableOperators(t){switch(t){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(t,e){const A=[];return t?(["show","hide","always"].includes(t.action)||A.push("Invalid conditional action"),["all","any"].includes(t.when)||A.push("Invalid when condition"),t.conditions&&0!==t.conditions.length?t.conditions.forEach((t,r)=>{const n=e.find(e=>e.id===t.when);if(!n)return void A.push(`Condition ${r+1}: Component not found`);this.getApplicableOperators(n.name).includes(t.operator)||A.push(`Condition ${r+1}: Operator not applicable for component type`),this.isValidConditionValue(t.value,n.name,t.operator)||A.push(`Condition ${r+1}: Invalid condition value`)}):A.push("At least one condition is required"),{isValid:0===A.length,errors:A}):{isValid:!0,errors:[]}}evaluateConditionalLogic(t,e,A){if("always"===t.action)return{shouldShow:!0,evaluatedConditions:[]};if(!t||!t.conditions||0===t.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const r=t.conditions.map(t=>{const r=this.getComponentValue(t.when,e,A);return{condition:t,result:this.evaluateCondition(t,r),componentValue:r}});return{shouldShow:this.determineFinalResult(t,r),evaluatedConditions:r}}getComponentValue(t,e,A){if(A&&void 0!==A[t])return A[t];const r=e.find(e=>e.id===t);return r&&"defaultValue"in r.basic?r.basic.defaultValue:void 0}evaluateCondition(t,e){const{operator:A,value:r}=t;if("checked"===r||"notChecked"===r)return this.evaluateCheckboxCondition(e,r);switch(A){case"equals":return this.isEqual(e,r);case"notEquals":return!this.isEqual(e,r);case"isEmpty":return this.isEmpty(e);case"isNotEmpty":return!this.isEmpty(e);case"contains":return this.contains(e,r);case"notContains":return!this.contains(e,r);case"greaterThan":return this.isGreaterThan(e,r);case"lessThan":return this.isLessThan(e,r);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(e,r);case"lessThanOrEqual":return this.isLessThanOrEqual(e,r);default:return!1}}evaluateCheckboxCondition(t,e){const A=this.isCheckboxChecked(t);return"checked"===e?A:"notChecked"===e&&!A}isCheckboxChecked(t){return null!=t&&("boolean"==typeof t?t:"string"==typeof t?"true"===t.toLowerCase()||"1"===t:Array.isArray(t)?t.length>0:"number"==typeof t&&t>0)}determineFinalResult(t,e){let A,r;return A="all"===t.when?e.every(t=>t.result):"any"===t.when&&e.some(t=>t.result),r="show"===t.action?A:"hide"===t.action?!A:(t.action,!0),r}isEqual(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(Array.isArray(t)&&Array.isArray(e))return t.length===e.length&&t.every((t,A)=>this.isEqual(t,e[A]));if("object"==typeof t&&"object"==typeof e){const A=Object.keys(t),r=Object.keys(e);return A.length===r.length&&A.every(A=>this.isEqual(t[A],e[A]))}return!1}isEmpty(t){return null==t||void 0===t||("string"==typeof t?""===t.trim():Array.isArray(t)?0===t.length:"object"==typeof t&&0===Object.keys(t).length)}contains(t,e){return null!=t&&null!=e&&("string"==typeof t?t.toLowerCase().includes(String(e).toLowerCase()):!!Array.isArray(t)&&t.some(t=>this.isEqual(t,e)))}isGreaterThan(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A>r}isLessThan(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A<r}isGreaterThanOrEqual(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A>=r}isLessThanOrEqual(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A<=r}isValidConditionValue(t,e,A){if(null==t)return["isEmpty","isNotEmpty"].includes(A);switch(e){case"number-input":return!isNaN(Number(t))||["isEmpty","isNotEmpty"].includes(A);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(t))||["isEmpty","isNotEmpty"].includes(A);case"checkbox":return Array.isArray(t)||"string"==typeof t||"number"==typeof t;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(t){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"}[t]||t}getActionDisplayText(t){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[t]||t}getConditionalLogicSummary(t,e){if(!t||0===t.conditions.length)return"No conditions";if("always"===t.action)return"Always show";const A=this.getActionDisplayText(t.action),r=t.conditions.map(t=>{const A=e.find(e=>e.id===t.when);return`${(null==A?void 0:A.basic.label)||"Unknown component"} ${this.getOperatorDisplayText(t.operator)} ${this.formatConditionValue(t.value)}`}),n="all"===t.when?" and ":" or ";return`${A} ${r.join(n)}`}formatConditionValue(t){return null==t?"empty":Array.isArray(t)?`[${t.join(", ")}]`:"string"==typeof t?`"${t}"`:String(t)}}const J=Y.getInstance();const $=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(t=>t([...this.toasts]))}addToast(t){try{this.toasts.push(t),this.notifyListeners(),this.timeouts[t.id]=setTimeout(()=>{this.removeToast(t.id)},t.duration||this.defaultDuration)}catch(t){console.error("Error displaying toast message:",t)}}removeToast(t){this.timeouts[t]&&(clearTimeout(this.timeouts[t]),delete this.timeouts[t]),this.toasts=this.toasts.filter(e=>e.id!==t),this.notifyListeners()}showSuccess(t,e=3e3){const A={id:this.generateId(),message:t,type:"success",duration:e};this.addToast(A)}showError(t,e=5e3){const A={id:this.generateId(),message:t,type:"danger",duration:e};this.addToast(A)}showWarning(t,e){const A={id:this.generateId(),message:t,type:"warning",duration:e};this.addToast(A)}showInfo(t,e){const A={id:this.generateId(),message:t,type:"info",duration:e};this.addToast(A)}show(t,e="success",A){const r={id:this.generateId(),message:t,type:e,duration:A};this.addToast(r)}clearAll(){Object.values(this.timeouts).forEach(t=>clearTimeout(t)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(t){return this.listeners.push(t),()=>{this.listeners=this.listeners.filter(e=>e!==t)}}getToasts(){return[...this.toasts]}},Z=({validationErrors:t,fieldId:e,touchedFields:A,formSubmitted:r,properties:n,localValidation:i,isTouched:s,mode:a})=>{const o=t=>{var e,A;const r=n.basic.label||"This field",i=n.name||"",s=null===(e=n.validation)||void 0===e?void 0:e.customValidationMessage;if("number-input"===i)switch(t){case"required":return`${r} is required`;case"lowerLimit":return"Number is below the lower limit";case"upperLimit":return"Number is above the upper limit";default:return""}if(s)return s;const a="date-picker"===i||"datetime-picker"===i?(null===(A=n.basic)||void 0===A?void 0:A.dateTimeMode)||("datetime-picker"===i?"datetime":"date"):null;switch(t){case"required":return`${r} is required`;case"invalidDate":return"time"===a?"Please select a valid time":"datetime"===a?"Please select a valid date and time":"date"===a?"Please select a valid date":`${r} is invalid`;case"minLength":return`${r} must be at least ${n.validation.minLength} characters long`;case"maxLength":return`${r} must be no more than ${n.validation.maxLength} characters long`;case"min":return`${r} must be at least ${n.validation.min}`;case"max":return`${r} must be no more than ${n.validation.max}`;case"lowerLimit":const t=n.validation;return`You are under the limit. ${r} must be at least ${null==t?void 0:t.lowerLimit}`;case"upperLimit":const e=n.validation;return`You crossed the limit. ${r} must be no more than ${null==e?void 0:e.upperLimit}`;case"pattern":return`${r} format is invalid`;case"email":return`${r} must be a valid email address`;default:return`${r} is invalid`}},l=(()=>{var l;if("test"!==a)return"";if(!(s||A[e]||r))return"";if(i&&i.isValid)return"";if(i&&!i.isValid&&Object.keys(i.errors).length>0){const t=Object.keys(i.errors).filter(t=>!0===i.errors[t]);if(t.length>0){const e=t[0],A=n.name||"";return"pattern"===e&&"number-input"===A?"":o(e)}}const c=t[e];if(c&&"string"==typeof c&&""!==c.trim()){const t=n.name||"";if("number-input"===t&&i){const t=n.validation,e=t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit,A=t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||e||A?(i.isValid,""):""}if(("date-picker"===t||"datetime-picker"===t)&&c.includes("valid date")){const e=(null===(l=n.basic)||void 0===l?void 0:l.dateTimeMode)||("datetime-picker"===t?"datetime":"date");if("time"===e)return"Please select a valid time";if("datetime"===e)return"Please select a valid date and time"}return c}return""})();return l?X.jsx("div",{className:"form-error-msg",children:l}):null};function tt(t,e,A,r){return new(A||(A=Promise))(function(n,i){function s(t){try{o(r.next(t))}catch(t){i(t)}}function a(t){try{o(r.throw(t))}catch(t){i(t)}}function o(t){var e;t.done?n(t.value):(e=t.value,e instanceof A?e:new A(function(t){t(e)})).then(s,a)}o((r=r.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const et=t=>{if(null==t||""===t)return null;if(t instanceof Date)return isNaN(t.getTime())?null:t;if("number"==typeof t){const e=new Date(t);return isNaN(e.getTime())?null:e}if("string"==typeof t){let e=t.trim();e.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)&&(e=e.replace(" ","T"));const A=new Date(e);return isNaN(A.getTime())?null:A}return null};var At;!function(t){t.OPEN="Open",t.IN_PROGRESS="In-Progress",t.REJECTED="Rejected",t.RESOLVE="Resolve"}(At||(At={}));const rt=({isOpen:r,onClose:n,onSuccess:i,component:d,formTemplateId:f,notes:p="",attachments:g=null,issue:m=null,onCreateIssue:w,onUpdateIssue:v,user:B,availableUsers:b=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:y,assetNumber:C,isStandalone:x,allowWorkflowActions:F,isEdit:Q})=>{var U,E,N,S,L,I;const O=void 0!==F?F:Q||!1,[k,T]=e(""),[j,H]=e(""),[P,D]=e(""),[M,R]=e(""),[K,V]=e("Medium"),[z,G]=e(At.OPEN),[q,W]=e(""),[Y,J]=e(""),[Z,rt]=e(!1),[nt,it]=e(g||[]),[st,at]=e(!1),ot=t.useRef(null),lt=void 0!==Q?Q:!!m;A(()=>{(null==m?void 0:m.attachments)&&m.attachments.length>0?it(m.attachments):g&&it(g)},[g,m]);const ct=t=>{if(!t)return"Attachment";if(t instanceof File)return t.name;if("string"==typeof t){if(t.startsWith("data:"))return"Attachment";const e=t.split("/");return e[e.length-1]||"Attachment"}return t.fileName||t.filename||t.name||"Attachment"},ut=t=>{if(!t)return null;const e=t=>/\.(jpg|jpeg|png|gif|webp)$/i.test(t),A=t=>t.startsWith("data:image");return t instanceof File?t.type.startsWith("image/")?URL.createObjectURL(t):null:"string"==typeof t?A(t)||e(t)?t:null:t.data&&A(t.data)||t.fileName&&e(t.fileName)&&t.data?t.data:null};A(()=>{var t;if(r)if(m||lt){T((null==m?void 0:m.title)||""),H((null==m?void 0:m.description)||""),D((null==m?void 0:m.workOrderNumber)||y||""),R((null==m?void 0:m.assetNumber)||C||""),V((null==m?void 0:m.priority)||"Medium");const t=(null==m?void 0:m.status)||At.OPEN,e=t===At.OPEN||t===At.IN_PROGRESS||t===At.REJECTED||t===At.RESOLVE?t:At.OPEN;G(e),W((null==m?void 0:m.assignTo)||(null==m?void 0:m.assignee)||""),J((null==m?void 0:m.comments)||"")}else d&&(null===(t=d.basic)||void 0===t||t.label,T(""),H(""),J(p||""),y&&D(y),C&&R(C))},[r,d,p,m,y,C]);const ht=t.useMemo(()=>{if(!k.trim())return!1;if(!j.trim())return!1;if(!z)return!1;if(!q)return!1;if(!x){if(!P.trim())return!1;if(!M.trim())return!1}return!0},[k,j,z,q,x,P,M]),dt=t=>tt(void 0,void 0,void 0,function*(){var e;if(m){rt(!0);try{const e={title:String(k||"").trim(),description:String(j||"").trim(),workOrderNumber:String(P||"").trim()||"",assetNumber:String(M||"").trim()||"",formTemplateId:m.formTemplateId||"",component:m.component||{},priority:K,assignee:String(q||"").trim()||void 0,status:t,comments:String(Y||"").trim()||""};v&&m._id&&(yield v(m._id,e)),G(t);const A={[At.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[At.RESOLVE]:"Issue resolved successfully",[At.REJECTED]:"Issue rejected"};$.showSuccess(A[t]||"Issue status updated successfully"),i&&i(),n()}catch(t){const A=(null==t?void 0:t.message)||(null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.message)||"Failed to update issue status. Please try again.";$.showError(A)}finally{rt(!1)}}});if(!r)return null;const ft=X.jsx("div",{className:"raise-issue-modal-overlay",onClick:n,children:X.jsxs("div",{className:"raise-issue-modal",onClick:t=>t.stopPropagation(),children:[X.jsxs("div",{className:"raise-issue-modal-header",children:[X.jsxs("div",{className:"raise-issue-modal-header-left",children:[X.jsx(s,{className:"raise-issue-modal-icon",size:20}),X.jsx("div",{className:"raise-issue-modal-header-text",children:X.jsx("div",{className:"raise-issue-modal-title-main",children:lt?O?"Edit Issue":"Issue Details":"Create Issue"})})]}),X.jsx("button",{className:"raise-issue-modal-close",onClick:n,"aria-label":"Close",children:X.jsx(a,{size:18})})]}),X.jsx("div",{className:"raise-issue-modal-content",children:X.jsxs("div",{className:"raise-issue-fields-grid",children:[lt&&(null==m?void 0:m.issueNumber)&&X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),X.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:m.issueNumber,readOnly:!0})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Task"}),X.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:lt?null===(E=null===(U=null==m?void 0:m.component)||void 0===U?void 0:U.basic)||void 0===E?void 0:E.label:(null===(N=null==d?void 0:d.basic)||void 0===N?void 0:N.label)||"",readOnly:!0})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Task Value"}),X.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:lt?null===(L=null===(S=null==m?void 0:m.component)||void 0===S?void 0:S.basic)||void 0===L?void 0:L.value:(null===(I=null==d?void 0:d.basic)||void 0===I?void 0:I.value)||"",readOnly:!0})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Title ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("input",{type:"text",className:"raise-issue-field-input "+(lt?"raise-issue-field-readonly":""),value:k,onChange:t=>T(t.target.value),placeholder:"Enter issue title",readOnly:lt})]}),!x&&X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("input",{type:"text",className:"raise-issue-field-input "+(lt?"raise-issue-field-readonly":""),value:P,onChange:t=>D(t.target.value),placeholder:"N/A",readOnly:lt})]}),!x&&X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("input",{type:"text",className:"raise-issue-field-input "+(lt?"raise-issue-field-readonly":""),value:M,onChange:t=>R(t.target.value),placeholder:"Enter asset number",readOnly:lt})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Raised By ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[X.jsx(o,{size:16}),X.jsx("span",{children:B&&`${B.firstName||""} ${B.lastName||""}`.trim()||"User"})]})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),X.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[X.jsx(l,{size:16}),X.jsx("span",{children:lt&&(null==m?void 0:m.createdAt)?(et(m.createdAt)||new Date).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})})]})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Description ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("textarea",{className:"raise-issue-field-textarea "+(lt?"raise-issue-field-readonly":""),value:j,onChange:t=>H(t.target.value),placeholder:"Enter issue description",rows:4,readOnly:lt})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Status ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("select",{className:"raise-issue-field-select "+(lt?"":"raise-issue-field-readonly"),value:z,onChange:t=>G(t.target.value),disabled:!lt,children:[X.jsx("option",{value:At.OPEN,children:At.OPEN}),X.jsx("option",{value:At.IN_PROGRESS,children:At.IN_PROGRESS}),X.jsx("option",{value:At.REJECTED,children:At.REJECTED}),X.jsx("option",{value:At.RESOLVE,children:At.RESOLVE})]})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Assign to ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("select",{className:"raise-issue-field-select",value:q,onChange:t=>W(t.target.value),children:[X.jsx("option",{value:"",children:"Unassigned"}),b.map(t=>X.jsx("option",{value:t,children:t},t))]})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("div",{className:"raise-issue-priority-buttons",children:[X.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===K?"active":""),onClick:()=>V("Low"),children:"Low"}),X.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===K?"active":""),onClick:()=>V("Medium"),children:"Medium"}),X.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===K?"active":""),onClick:()=>V("High"),children:"High"})]})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[X.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[X.jsx(c,{size:16}),X.jsx("span",{children:"Comments"})]}),!Y&&X.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),X.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(lt?"raise-issue-field-readonly":""),value:Y,onChange:t=>J(t.target.value),placeholder:"Add a comment...",rows:4,readOnly:lt})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",style:{marginTop:"1rem"},children:[X.jsx("label",{className:"raise-issue-field-label",children:"Attachments"}),X.jsxs("div",{className:"raise-issue-attachments-container",children:[!lt&&X.jsxs("div",{className:"raise-issue-dropzone "+(st?"dragging":""),onDragOver:t=>{t.preventDefault(),at(!0)},onDragLeave:t=>{t.preventDefault(),at(!1)},onDrop:t=>{if(t.preventDefault(),at(!1),t.dataTransfer.files&&t.dataTransfer.files.length>0){const e=Array.from(t.dataTransfer.files);it(t=>[...t,...e])}},onClick:()=>{var t;return null===(t=ot.current)||void 0===t?void 0:t.click()},children:[X.jsx("input",{type:"file",ref:ot,style:{display:"none"},onChange:t=>{if(t.target.files&&t.target.files.length>0){const e=Array.from(t.target.files);it(t=>[...t,...e]),ot.current&&(ot.current.value="")}},multiple:!0}),X.jsx("div",{className:"raise-issue-dropzone-icon",children:X.jsx(u,{size:24})}),X.jsx("div",{className:"raise-issue-dropzone-text",children:"Click to upload or drag and drop"}),X.jsx("div",{className:"raise-issue-dropzone-hint",children:"PNG, JPG up to 10MB"})]}),nt.length>0&&X.jsx("div",{className:"raise-issue-attachments-list",children:nt.map((t,e)=>X.jsxs("div",{className:"raise-issue-attachment-item",children:[X.jsx("div",{className:"raise-issue-attachment-thumbnail",children:ut(t)?X.jsx("img",{src:ut(t),alt:"Thumbnail"}):X.jsx(h,{size:20,color:"#9ca3af"})}),X.jsxs("div",{className:"raise-issue-attachment-info",children:[X.jsx("span",{className:"attachment-name",title:ct(t),children:ct(t)}),t instanceof File&&X.jsxs("span",{className:"attachment-size",children:[(t.size/1024).toFixed(1)," KB"]})]}),!lt&&X.jsx("button",{type:"button",className:"attachment-remove-btn",onClick:()=>(t=>{it(e=>e.filter((e,A)=>A!==t))})(e),title:"Remove",children:X.jsx(a,{size:12})})]},e))})]})]})]})}),X.jsx("div",{className:"raise-issue-modal-actions",children:X.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[O&&lt&&m&&X.jsxs(X.Fragment,{children:[z===At.OPEN&&X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:()=>tt(void 0,void 0,void 0,function*(){yield dt(At.IN_PROGRESS)}),disabled:Z,children:Z?"Processing...":"Accept"}),z===At.IN_PROGRESS&&X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:()=>tt(void 0,void 0,void 0,function*(){yield dt(At.RESOLVE)}),disabled:Z,children:Z?"Processing...":"Resolve"}),(z===At.OPEN||z===At.IN_PROGRESS)&&X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:()=>tt(void 0,void 0,void 0,function*(){yield dt(At.REJECTED)}),disabled:Z,children:Z?"Processing...":"Reject"})]}),!lt&&X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save "+(ht?"":"disabled"),onClick:()=>tt(void 0,void 0,void 0,function*(){var t,e,A,r,s,a,o;if(String(k||"").trim())if(String(j||"").trim())if(x||String(P||"").trim())if(x||String(M||"").trim())if(String(q||"").trim()){rt(!0);try{if(lt&&m){const s={title:String(k||"").trim(),description:String(j||"").trim(),workOrderNumber:String(P||"").trim()||"",assetNumber:String(M||"").trim()||void 0,formTemplateId:m.formTemplateId||"",component:m.component||{},priority:K,assignTo:String(q||"").trim()||void 0,status:z,comments:String(Y||"").trim()||"",task:(null===(e=null===(t=m.component)||void 0===t?void 0:t.basic)||void 0===e?void 0:e.label)||"",taskValue:(null===(r=null===(A=m.component)||void 0===A?void 0:A.basic)||void 0===r?void 0:r.value)||""};v&&m._id&&(yield v(m._id,s)),$.showSuccess("Issue updated successfully"),i&&i(),n()}else{if(!d)return $.showError("Component is required"),void rt(!1);if(!f||""===String(f||"").trim())return $.showError("Form template is required"),void rt(!1);const t=Object.assign(Object.assign({},d),{basic:Object.assign(Object.assign({},d.basic),{comments:String(p||"")})}),e=B?`${B.firstName||""} ${B.lastName||""}`.trim():"User",A={title:String(k||"").trim(),workOrderNumber:String(P||"").trim()||void 0,assetNumber:String(M||"").trim()||void 0,component:t,description:String(j||"").trim(),formTemplateId:f,assignTo:String(q||"").trim()||void 0,priority:K,status:z,comments:String(Y||"").trim()||"",createdBy:e,task:(null===(s=null==d?void 0:d.basic)||void 0===s?void 0:s.label)||"",taskValue:(null===(a=null==d?void 0:d.basic)||void 0===a?void 0:a.value)||""};let r;if(w&&(r=yield w(A,nt)),$.showSuccess("Issue raised successfully"),i){const t=Object.assign({_id:(null==r?void 0:r._id)||"temp-id",issueNumber:(null==r?void 0:r.issueNumber)||"",title:A.title,description:A.description,status:A.status,priority:A.priority,createdAt:(null==r?void 0:r.createdAt)||(new Date).toISOString(),updatedAt:(null==r?void 0:r.updatedAt)||(new Date).toISOString(),component:A.component,workOrderNumber:A.workOrderNumber,assetNumber:A.assetNumber,assignee:A.assignTo,comments:A.comments,attachments:(null==r?void 0:r.attachments)||nt},r);i(t)}n()}}catch(t){const e=(null==t?void 0:t.message)||(null===(o=null==t?void 0:t.error)||void 0===o?void 0:o.message)||(lt?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");$.showError(e)}finally{rt(!1)}}else $.showError("Assignee is required");else $.showError("Asset Number is required");else $.showError("Work Order is required");else $.showError("Description is required");else $.showError("Title is required")}),disabled:Z||!ht,children:Z?lt?"Saving...":"Creating...":lt?"Save Changes":"Create Issue"})]})})]})});return _(ft,document.body)},nt=({component:t,condition:n,currentValue:i,thresholdValue:a,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,onIssueRaised:h,isIssueRaised:d=!1,compact:f=!1})=>{const[p,g]=e(!1),[m,w]=e(null),[v,B]=e(!1),[b,y]=e(!1);A(()=>{d&&y(!0)},[d]),A(()=>{y(!1)},[null==n?void 0:n.id]);const C=t=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[t]||t),x=r(()=>tt(void 0,void 0,void 0,function*(){if(d||b){if(m)return void g(!0);B(!0);try{w(null),g(!0)}catch(t){console.error("Error fetching issue:",t),$.showError("Failed to load issue details")}finally{B(!1)}}else w(null),g(!0)}),[d,b,o,t,m]),F=r(()=>{g(!1),d||b||w(null)},[d,b]),Q=r(t=>{g(!1),w(t||null),y(!0),h&&(null==n?void 0:n.id)&&h(n.id)},[h,n]);return d||b?X.jsx(X.Fragment,{children:p&&X.jsx(rt,{isOpen:p,onClose:F,onSuccess:Q,component:t,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,notes:"",attachments:null,issue:m})}):f?X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[X.jsx("div",{className:"threshold-alert-border"}),X.jsxs("div",{className:"threshold-alert-content-compact",children:[X.jsx(s,{className:"threshold-alert-icon-compact",size:14}),X.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${C(n.operator)} ${a}`}),X.jsx("button",{type:"button",onClick:x,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),p&&X.jsx(rt,{isOpen:p,onClose:F,onSuccess:Q,component:t,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,notes:"",attachments:null,issue:m})]}):X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[X.jsx("div",{className:"threshold-alert-border"}),X.jsxs("div",{className:"threshold-alert-content",children:[X.jsx("div",{className:"threshold-alert-header",children:X.jsxs("div",{className:"threshold-alert-title-group",children:[X.jsx(s,{className:"threshold-alert-icon",size:20}),X.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),X.jsxs("div",{className:"threshold-alert-message",children:[(()=>{var e;const A=C(n.operator);return`${(null===(e=t.basic)||void 0===e?void 0:e.label)||"Value"}: Value ${i} exceeds threshold ${A} ${a}`})(),X.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),X.jsx("div",{className:"threshold-alert-buttons",children:X.jsx("button",{type:"button",onClick:x,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),p&&X.jsx(rt,{isOpen:p,onClose:F,onSuccess:Q,component:t,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,notes:"",attachments:null,issue:m})]})},it=({id:t,properties:s,validationErrors:a={},formValue:o="",inputType:l="text",readonly:c=!1,disabled:u=!1,touchedFields:h={},formSubmitted:d=!1,mode:f="test",onValueChange:p,onBlur:g,onFocus:m,className:w="",hideLabel:v=!1,formTemplateId:B,onThresholdIssueRaised:b,raisedThresholdIssues:y=new Set,workOrderNumber:C,assetNumber:x,user:F})=>{var Q,U,E,N,S;const L=t=>null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):"object"==typeof t?Array.isArray(t)?"":"value"in t?L(t.value):"label"in t?L(t.label):"":String(t||""),I=n(t),_=n(null);A(()=>{t!==I.current&&(console.warn(`[DfFormInput] Component ID changed from ${I.current} to ${t}`),I.current=t)},[t]);const O=L(o||(null===(Q=null==s?void 0:s.basic)||void 0===Q?void 0:Q.defaultValue)||""),[k,T]=e(O),[j,H]=e(!1),[P,D]=e(!1),[M,R]=e(new Set),[K,V]=e(O),z=()=>{if(l)return l;const t=null==s?void 0:s.name;return"text-input"===t?"text":"number-input"===t?"number":"email-input"===t?"email":"text"},G=r(t=>{const e=(()=>{var t;const e={};if((null===(t=null==s?void 0:s.validation)||void 0===t?void 0:t.required)&&(e.required=!0),"email"===z()&&(e.email=!0),"text"===z()){const t=s.validation;(null==t?void 0:t.minLength)&&(e.minLength=t.minLength),(null==t?void 0:t.maxLength)&&(e.maxLength=t.maxLength)}if("number"===z()){const t=s.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})(),A={};let r=!0;const n="string"==typeof t?t:null!=t?String(t):"";if(!e.required||n&&""!==n.trim()||(A.required=!0,r=!1),e.email&&n&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)&&(A.email=!0,r=!1),e.minLength&&n&&n.length<e.minLength&&(A.minLength=!0,r=!1),e.maxLength&&n&&n.length>e.maxLength&&(A.maxLength=!0,r=!1),"number"===z())if(delete A.pattern,delete A.min,delete A.max,n&&""!==n.trim()){const t=n.trim(),i=parseFloat(t);isNaN(i)||("lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&i<e.lowerLimit&&(A.lowerLimit=!0,r=!1),"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&i>e.upperLimit&&(A.upperLimit=!0,r=!1))}else delete A.lowerLimit,delete A.upperLimit;return{isValid:r,errors:A}},[s,z]),q=r(e=>{const A="string"==typeof e?e:null!=e?String(e):"";if(T(A),p){const e=G(A),r=I.current,n={id:r,value:A,isValid:e.isValid,errors:e.errors};r!==t&&console.error(`[DfFormInput] ID mismatch in handleValueChange! ref: ${r}, prop: ${t}`),p(n)}},[t,p,G,I]);A(()=>{j&&(h[t]=!0)},[j,t,h]),A(()=>{var t;if("edit"===f){H(!1);const e=(null===(t=null==s?void 0:s.basic)||void 0===t?void 0:t.defaultValue)||"";T(e)}else"test"===f&&(H(!1),T(""))},[f,null===(U=null==s?void 0:s.basic)||void 0===U?void 0:U.defaultValue]),A(()=>{var e;const A=I.current,r=L(o||(null===(e=null==s?void 0:s.basic)||void 0===e?void 0:e.defaultValue)||"");r===k||P||""===r&&""!==String(k||"").trim()?""===r&&String(k||"").trim():null!=o&&(A===t?T(r):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${A}, prop id: ${t}`))},[o,k,P,null===(E=null==s?void 0:s.basic)||void 0===E?void 0:E.defaultValue,t]),A(()=>{d&&H(!0)},[d]),A(()=>{"test"!==f&&T("")},[f]);const W=r((t,e)=>{if(!e||""===e)return!1;const A="string"==typeof e?parseFloat(e):e,r="string"==typeof t.value?parseFloat(t.value):t.value;if(isNaN(A)||isNaN(r))return!1;switch(t.operator){case"greaterThan":return A>r;case"lessThan":return A<r;case"greaterThanOrEqual":return A>=r;case"lessThanOrEqual":return A<=r;case"equals":return A===r;case"notEquals":return A!==r;default:return!1}},[]),Y=i(()=>{var t;return(null===(t=null==s?void 0:s.condition)||void 0===t?void 0:t.conditions)||[]},[null==s?void 0:s.condition]);A(()=>{k!==K&&(R(new Set),V(k))},[k,K]);const J=i(()=>{if("test"!==f||!k||""===k)return null;const t=Y.filter(t=>W(t,k));if(0===t.length)return null;for(const e of t)if(!M.has(e.id))return e;return null},[k,Y,M,f,W,y]),$=r(t=>{R(e=>new Set(e).add(t))},[]),tt=z(),et=u||c||(null===(N=null==s?void 0:s.validation)||void 0===N?void 0:N.readonly);return X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==s?void 0:s.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!v&&s.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[s.basic.label,s.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",ref:_,children:[X.jsx("input",{type:tt,id:t,value:k,onChange:t=>{const e=t.target.value;q(e)},onFocus:()=>{D(!0),m&&m()},onBlur:()=>{if(D(!1),H(!0),"test"===f&&p){const e="string"==typeof k?k:null!=k?String(k):"",A=G(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};p(r)}g&&g()},placeholder:s.basic.placeholder,disabled:et,readOnly:c||(null===(S=null==s?void 0:s.validation)||void 0===S?void 0:S.readonly),className:(()=>{const e="form-control";if("test"===f){const A="string"==typeof k?k:null!=k?String(k):"",r=G(A);if(r.isValid)return`${e} ${w}`.trim();const n=!r.isValid&&j,i=a[t]&&(j||d)&&!r;return`${e} ${n||i?"is-invalid":""} ${w}`.trim()}return`${e} ${w}`.trim()})()}),X.jsx(Z,{validationErrors:a,fieldId:t,touchedFields:h,formSubmitted:d,properties:s,localValidation:G(k),isTouched:j,mode:f})]})]}),J&&"test"===f&&(()=>{var t,e,A,r;const n=(null==y?void 0:y.has(J.id))||!1,i=null!==(null===(t=_.current)||void 0===t?void 0:t.closest(".table-cell"))||null!==(null===(e=_.current)||void 0===e?void 0:e.closest(".cell-content"))||null!==(null===(A=_.current)||void 0===A?void 0:A.closest(".datagrid-table-view"))||null!==(null===(r=_.current)||void 0===r?void 0:r.closest(".datagrid-list-view"))||w.includes("table-cell")||w.includes("cell-content");return X.jsx(nt,{component:s,condition:J,currentValue:k,thresholdValue:J.value,formTemplateId:B,workOrderNumber:C,assetNumber:x,user:F,onDismiss:()=>$(J.id),onIssueRaised:b,isIssueRaised:n,compact:i},`${J.id}-${n}`)})()]})},st=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v;const[B,b]=e(s),[y,C]=e(!1),x=r(t=>{var e,A,r;const i={};let s=!0;return!(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(i.required=!0,s=!1),(null===(A=null==n?void 0:n.validation)||void 0===A?void 0:A.minLength)&&t&&t.length<n.validation.minLength&&(i.minLength=!0,s=!1),(null===(r=null==n?void 0:n.validation)||void 0===r?void 0:r.maxLength)&&t&&t.length>n.validation.maxLength&&(i.maxLength=!0,s=!1),{isValid:s,errors:i}},[n]),F=r(e=>{if(b(e),h){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,x]);A(()=>{y&&(l[t]=!0)},[y,t,l]),A(()=>{""===B&&""!==s&&b(s)},[s]),A(()=>{c&&C(!0)},[c]),A(()=>{"test"!==u&&b("")},[u]);const Q=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly),U=(null===(w=null==n?void 0:n.validation)||void 0===w?void 0:w.rows)||4;return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&n.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("textarea",{id:t,value:B,onChange:t=>{const e=t.target.value;F(e)},onFocus:()=>{f&&f()},onBlur:()=>{C(!0),d&&d()},placeholder:n.basic.placeholder,disabled:Q,readOnly:a||(null===(v=null==n?void 0:n.validation)||void 0===v?void 0:v.readonly),rows:U,className:`form-textarea ${!x(B).isValid&&y?"is-invalid":""} ${p}`.trim()}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(B),isTouched:y,mode:u})]})]})},at=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w;const[v,B]=e(s),[b,y]=e(!1),C=(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.multiple)||!1,x=r(t=>{var e;const A={};let r=!0;return(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)&&(C?Array.isArray(t)&&0!==t.length||(A.required=!0,r=!1):(!t||"string"==typeof t&&""===t.trim())&&(A.required=!0,r=!1)),{isValid:r,errors:A}},[n,C]),F=r(e=>{if(B(e),h){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,x]);A(()=>{b&&(l[t]=!0)},[b,t,l]),A(()=>{JSON.stringify(s)!==JSON.stringify(v)&&B(s)},[s,v]),A(()=>{c&&y(!0)},[c]);const Q=o||a||(null===(w=null==n?void 0:n.validation)||void 0===w?void 0:w.readonly);return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&n.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsxs("select",{id:t,value:v,onChange:t=>{if(C){const e=Array.from(t.target.selectedOptions,t=>t.value);F(e)}else F(t.target.value)},onFocus:()=>{f&&f()},onBlur:()=>{y(!0),d&&d()},disabled:Q,multiple:C,className:`form-select ${!x(v).isValid&&b?"is-invalid":""} ${p}`.trim(),children:[!C&&X.jsx("option",{value:"",children:n.basic.placeholder||"Select an option"}),(n.options||[]).map((t,e)=>X.jsx("option",{value:t.value,disabled:t.disabled,children:t.label},e))]}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(v),isTouched:b,mode:u})]})]})},ot=({id:t,properties:n,validationErrors:i={},formValue:s=[],readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v;const[B,b]=e(!1),y=Array.isArray(s)?s:[],C=r(t=>{var e;const A={};let r=!0;return(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)&&0===t.length&&(A.required=!0,r=!1),{isValid:r,errors:A}},[n]),x=r(e=>{if(h){const A=C(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,C,y]),F=(t,e)=>{let A;A=e?[...y,t]:y.filter(e=>e!==t),x(A)},Q=()=>{f&&f()},U=()=>{b(!0),d&&d()};A(()=>{B&&(l[t]=!0)},[B,t,l]),A(()=>{},[s,t,y]),A(()=>{c&&b(!0)},[c]);const E=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly);return X.jsx(X.Fragment,{children:X.jsx("div",{className:`form-group checkbox-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var t;return(null===(t=null==n?void 0:n.basic)||void 0===t?void 0:t.inlineLayout)?"inline-layout":"vertical-layout"})()} ${p}`,children:!g&&n.basic.label?X.jsxs(X.Fragment,{children:[X.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(w=null==n?void 0:n.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"checkbox",id:`${t}-${A}`,name:t,value:e.value,checked:y.includes(e.value),onChange:t=>{F(e.value,t.target.checked)},onFocus:Q,onBlur:U,disabled:E||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:C(y),isTouched:B,mode:u})]})]}):X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(v=null==n?void 0:n.basic)||void 0===v?void 0:v.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"checkbox",id:`${t}-${A}`,name:t,value:e.value,checked:y.includes(e.value),onChange:t=>{F(e.value,t.target.checked)},onFocus:Q,onBlur:U,disabled:E||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:C(y),isTouched:B,mode:u})]})})})},lt=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v;const[B,b]=e(s),[y,C]=e(!1),x=r(t=>{var e;const A={};let r=!0;return!(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(A.required=!0,r=!1),{isValid:r,errors:A}},[n]),F=r(e=>{if(b(e),h){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,x]),Q=t=>{F(t)},U=()=>{f&&f()},E=()=>{C(!0),d&&d()};A(()=>{y&&(l[t]=!0)},[y,t,l]),A(()=>{s!==B&&b(s)},[s,B]),A(()=>{c&&C(!0)},[c]);const N=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly);return X.jsx(X.Fragment,{children:X.jsx("div",{className:`form-group radio-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var t;return(null===(t=null==n?void 0:n.basic)||void 0===t?void 0:t.inlineLayout)?"inline-layout":"vertical-layout"})()} ${p}`,children:!g&&n.basic.label?X.jsxs(X.Fragment,{children:[X.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(w=null==n?void 0:n.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"radio",id:`${t}-${A}`,name:t,value:e.value,checked:B===e.value,onChange:()=>Q(e.value),onFocus:U,onBlur:E,disabled:N||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(B),isTouched:y,mode:u})]})]}):X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(v=null==n?void 0:n.basic)||void 0===v?void 0:v.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"radio",id:`${t}-${A}`,name:t,value:e.value,checked:B===e.value,onChange:()=>Q(e.value),onFocus:U,onBlur:E,disabled:N||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(B),isTouched:y,mode:u})]})})})},ct=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m;const[w,v]=e(s),[B,b]=e(!1),y=r(t=>{var e;const A={};let r=!0;return!(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(A.required=!0,r=!1),{isValid:r,errors:A}},[n]),C=r(e=>{if(v(e),b(!0),h){const A=y(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,y]),x=()=>{f&&f()},F=()=>{b(!0),d&&d()};A(()=>{B&&(l[t]=!0)},[B,t,l]),A(()=>{s!==w&&v(s)},[s,w]),A(()=>{c&&b(!0)},[c]);const Q=()=>{var t;return(null===(t=null==n?void 0:n.basic)||void 0===t?void 0:t.inlineLayout)?"inline-layout":"grid-layout"},U=t=>{const e=null==t?void 0:t.toLowerCase();return"pass"===e||"yes"===e?"pass":"fail"===e||"no"===e?"fail":"pass"},E=t=>{if(void 0!==(null==t?void 0:t.icon)&&""!==t.icon)return t.icon;return"pass"===U((null==t?void 0:t.value)||t)?"✓":"×"},N=(t,e)=>(null==t?void 0:t.color)||(null==t?void 0:t.backgroundColor)?{color:e?"#ffffff":t.color||"#00814b",backgroundColor:e?t.color||"#00814b":t.backgroundColor||"#34bd4914",borderColor:t.color||"#00814b"}:{},S=t=>{if((null==t?void 0:t.color)||(null==t?void 0:t.backgroundColor))return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===U((null==t?void 0:t.value)||t)?"pass-button":"fail-button")},L=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly);return X.jsxs(X.Fragment,{children:[X.jsx("div",{className:`form-group segment-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()} ${p}`,children:!g&&n.basic.label?X.jsxs(X.Fragment,{children:[X.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsx("div",{className:"form-segment-wrapper",children:X.jsx("div",{className:`form-segment-container ${Q()}`,children:(n.options||[]).map((e,A)=>{const r=w===e.value,n=N(e,r),i=S(e),s=E(e);return X.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[X.jsx("input",{type:"radio",id:`${t}_option_${A}`,name:t,value:e.value,checked:r,onChange:()=>!L&&!e.disabled&&C(e.value),onFocus:x,onBlur:F,disabled:L||e.disabled,className:"form-segment-radio"}),X.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&X.jsx("span",{className:"segment-icon",children:s}),X.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})]}):X.jsx("div",{className:"form-segment-wrapper",children:X.jsx("div",{className:`form-segment-container ${Q()}`,children:(n.options||[]).map((e,A)=>{const r=w===e.value,n=N(e,r),i=S(e),s=E(e);return X.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[X.jsx("input",{type:"radio",id:`${t}_option_${A}`,name:t,value:e.value,checked:r,onChange:()=>!L&&!e.disabled&&C(e.value),onFocus:x,onBlur:F,disabled:L||e.disabled,className:"form-segment-radio"}),X.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&X.jsx("span",{className:"segment-icon",children:s}),X.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:y(w),isTouched:B,mode:u})]})},ut=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v,B,b;const y=r(t=>{var e,A;if(!t)return"";if("string"==typeof t){if(/^\d{4}-\d{2}-\d{2}$/.test(t))return t;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return t;const A=et(t);if(A&&!isNaN(A.getTime())){const t=n.name||"",r=(null===(e=n.basic)||void 0===e?void 0:e.dateTimeMode)||("datetime-picker"===t?"datetime":"date");if("datetime"===r){return`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")}T${String(A.getHours()).padStart(2,"0")}:${String(A.getMinutes()).padStart(2,"0")}`}if("time"===r){return`${String(A.getHours()).padStart(2,"0")}:${String(A.getMinutes()).padStart(2,"0")}`}return`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")}`}return t}if(t instanceof Date){if(isNaN(t.getTime()))return"";const e=n.name||"",r=(null===(A=n.basic)||void 0===A?void 0:A.dateTimeMode)||("datetime-picker"===e?"datetime":"date");if("datetime"===r){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"===r){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")}`}if("object"==typeof t&&null!==t){if("value"in t&&t.value)return y(t.value);if("date"in t&&t.date)return y(t.date);try{const e=String(t),A=et(e);if(A&&!isNaN(A.getTime()))return y(A)}catch(t){}return""}return""},[n]),C=y(s),[x,F]=e(C),[Q,U]=e(!1),[E,N]=e(!1),S=r(t=>{var e,A,r,i,s,a;const o={};let l=!0;const c=n.name||"",u=(null===(e=n.basic)||void 0===e?void 0:e.dateTimeMode)||("datetime-picker"===c?"datetime":"date"),h=t?String(t).trim():"";if((null===(A=null==n?void 0:n.validation)||void 0===A?void 0:A.required)&&(!h||""===h))return o.required=!0,l=!1,{isValid:l,errors:o};if(h&&""!==h)if("time"===u){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(h))return o.invalidDate=!0,l=!1,{isValid:l,errors:o}}else if("datetime"===u){const t=et(h);if(!t||isNaN(t.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(r=null==n?void 0:n.validation)||void 0===r?void 0:r.minDate){const e=et(n.validation.minDate);e&&t<e&&(o.minDate=!0,o.minDateMessage=`Date and time must be on or after ${e.toLocaleDateString()}`,l=!1)}if(null===(i=null==n?void 0:n.validation)||void 0===i?void 0:i.maxDate){const e=et(n.validation.maxDate);e&&t>e&&(o.maxDate=!0,o.maxDateMessage=`Date and time must be on or before ${e.toLocaleDateString()}`,l=!1)}}else{const t=et(h);if(!t||isNaN(t.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(s=null==n?void 0:n.validation)||void 0===s?void 0:s.minDate){const e=et(n.validation.minDate);e&&t<e&&(o.minDate=!0,o.minDateMessage=`Date must be on or after ${e.toLocaleDateString()}`,l=!1)}if(null===(a=null==n?void 0:n.validation)||void 0===a?void 0:a.maxDate){const e=et(n.validation.maxDate);e&&t>e&&(o.maxDate=!0,o.maxDateMessage=`Date must be on or before ${e.toLocaleDateString()}`,l=!1)}}return{isValid:l,errors:o}},[n]),L=r(e=>{if(F(e),h){const A=S(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,S]);A(()=>{Q&&(l[t]=!0)},[Q,t,l]),A(()=>{const t=y(s);t===x||E||F(t)},[s,x,E,y]),A(()=>{c&&U(!0)},[c]);const I=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly),_=n.name||"",O=(null===(w=n.basic)||void 0===w?void 0:w.dateTimeMode)||("datetime-picker"===_?"datetime":"date"),k=(()=>{switch(O){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&n.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("input",{type:k,id:t,value:x,onChange:t=>{const e=t.target.value;L(e)},onFocus:()=>{N(!0),f&&f()},onBlur:()=>{if(N(!1),U(!0),h){const e=S(x),A={id:t,value:x,isValid:e.isValid,errors:e.errors};h(A)}d&&d()},disabled:I,readOnly:a||(null===(v=null==n?void 0:n.validation)||void 0===v?void 0:v.readonly),min:null===(B=null==n?void 0:n.validation)||void 0===B?void 0:B.minDate,max:null===(b=null==n?void 0:n.validation)||void 0===b?void 0:b.maxDate,className:`form-date ${!S(x).isValid&&Q?"is-invalid":""} ${p}`.trim()}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:S(x),isTouched:Q,mode:u})]})]})},ht=({id:t,properties:i,validationErrors:s={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:u=!1,mode:h="preview",onValueChange:d,onBlur:f,onFocus:p,className:g="",hideLabel:m=!1})=>{var w;const v=n(null),[B,b]=e(!1),[y,C]=e(!1),[x,F]=e(a),[Q,U]=e(!1),E=r(t=>{var e;const A={};let r=!0;return!(null===(e=null==i?void 0:i.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(A.required=!0,r=!1),{isValid:r,errors:A}},[i]),N=r(e=>{if(F(e),d){const A=E(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};d(r)}},[t,d,E]),S=r(()=>{const t=document.documentElement.classList.contains("dark")||"dark"===document.documentElement.getAttribute("data-theme");let e=getComputedStyle(document.documentElement).getPropertyValue("--df-color-fb-input-bg").trim();e||(e=t?"#2c2e34":"#ffffff");return{strokeColor:t?"#ffffff":"#000000",backgroundColor:e}},[]),L=r(e=>{if(!e)return;const A=v.current;if(!A)return;const r=A.getContext("2d");if(!r)return;const n=new Image;n.onload=()=>{r.clearRect(0,0,A.width,A.height);const t=S();r.fillStyle=t.backgroundColor,r.fillRect(0,0,A.width,A.height);const e=A.width/A.height,i=n.width/n.height;let s=A.width,a=A.height,o=0,l=0;i>e?(a=A.width/i,l=(A.height-a)/2):(s=A.height*i,o=(A.width-s)/2),r.drawImage(n,o,l,s,a)},n.onerror=A=>{console.error("DfFormSignature: error loading image",{id:t,error:A,dataURL:e.substring(0,50)+"..."})},n.src=e},[S,t]),I=r(()=>{const t=v.current;if(!t)return;const e=t.getContext("2d");if(!e)return;const A=t.getBoundingClientRect();t.width=A.width,t.height=A.height,t.style.width=A.width+"px",t.style.height=A.height+"px";const r=S();e.strokeStyle=r.strokeColor,e.lineWidth=2,e.lineCap="round",e.lineJoin="round",x?L(x):(e.fillStyle=r.backgroundColor,e.fillRect(0,0,t.width,t.height))},[x,S,L]),_=r(()=>{setTimeout(()=>{I()},100)},[I]);A(()=>{const t=()=>{_()},e=new MutationObserver(t=>{t.forEach(t=>{if("attributes"===t.type&&"class"===t.attributeName){const e=t.target;e.classList.contains("form-canvas-container")&&(e.classList.contains("mobile-view")||e.classList.contains("tablet-view")||e.classList.contains("desktop-view"))&&_()}})});return e.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",t),()=>{e.disconnect(),window.removeEventListener("resize",t)}},[_]);const O=r(t=>{const e=v.current;if(!e)return{x:0,y:0};const A=e.getBoundingClientRect(),r=e.width/A.width,n=e.height/A.height,i=t.type.includes("mouse")?t.clientX:t.touches[0].clientX,s=t.type.includes("mouse")?t.clientY:t.touches[0].clientY;return{x:(i-A.left)*r,y:(s-A.top)*n}},[]),k=t=>{var e;if(o||l||(null===(e=null==i?void 0:i.validation)||void 0===e?void 0:e.readonly))return;if(t.target.closest(".clear-signature-btn"))return;t.preventDefault(),t.stopPropagation(),b(!0),C(!0);const A=v.current;if(!A)return;const r=A.getContext("2d");if(!r)return;const{x:n,y:s}=O(t),a=S();r.strokeStyle=a.strokeColor,r.lineWidth=2,r.lineCap="round",r.lineJoin="round",r.beginPath(),r.moveTo(n,s)},T=t=>{if(!B)return;t.preventDefault(),t.stopPropagation();const e=v.current;if(!e)return;const A=e.getContext("2d");if(!A)return;const{x:r,y:n}=O(t);A.lineTo(r,n),A.stroke()},j=()=>{if(!B)return;b(!1),U(!0);const t=v.current;if(t){(t=>{const e=t.getContext("2d");if(!e)return!1;const A=e.getImageData(0,0,t.width,t.height).data;for(let t=0;t<A.length;t+=4){const e=A[t],r=A[t+1],n=A[t+2];if(A[t+3]>0&&(e<255||r<255||n<255))return!0}})(t);const e=t.toDataURL("image/png");F(e),N(e),setTimeout(()=>{U(!1)},100)}else U(!1)},H=r(()=>{const t=v.current;if(!t)return;const e=t.getContext("2d");if(!e)return;const A=S();if(e.strokeStyle=A.strokeColor,x){const r=x,n=t.getBoundingClientRect();e.fillStyle=A.backgroundColor,e.fillRect(0,0,n.width,n.height),r&&L(r)}else{const r=t.getBoundingClientRect();e.fillStyle=A.backgroundColor,e.fillRect(0,0,r.width,r.height)}},[S,x,L]);A(()=>{const t=new MutationObserver(t=>{t.forEach(t=>{"attributes"!==t.type||"class"!==t.attributeName&&"data-theme"!==t.attributeName||H()})});return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{t.disconnect()}},[H]);A(()=>{y&&(c[t]=!0)},[y,t,c]),A(()=>{if(!(a===x||B||Q||""!==x&&""===a)){if(a===x)return;F(a),a&&L(a)}},[a,x,B,Q]),A(()=>{u&&C(!0)},[u]),A(()=>{if("test"!==h){F("");const t=v.current;if(t){const e=t.getContext("2d");if(e){const A=t.getBoundingClientRect();t.width=A.width,t.height=A.height;const r=S();e.fillStyle=r.backgroundColor,e.fillRect(0,0,A.width,A.height)}}}},[h]),A(()=>{I()},[h]);const P=l||o||(null===(w=null==i?void 0:i.validation)||void 0===w?void 0:w.readonly);return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==i?void 0:i.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!m&&i.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[i.basic.label,i.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[X.jsx("canvas",{ref:v,id:t,className:`form-signature ${!E(x).isValid&&y?"is-invalid":""} ${g}`.trim(),onMouseDown:k,onMouseMove:T,onMouseUp:j,onMouseLeave:j,onTouchStart:k,onTouchMove:T,onTouchEnd:j,onFocus:()=>{p&&p()},onBlur:()=>{f&&f()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:P?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!P&&X.jsx("button",{type:"button",onClick:t=>(t=>{null==t||t.preventDefault(),null==t||t.stopPropagation();const e=v.current;if(!e)return;const A=e.getBoundingClientRect();e.width=A.width,e.height=A.height;const r=e.getContext("2d");if(!r)return;const n=S();r.fillStyle=n.backgroundColor,r.fillRect(0,0,A.width,A.height),r.strokeStyle=n.strokeColor,r.lineWidth=2,r.lineCap="round",r.lineJoin="round",F(""),N("")})(t),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:t=>{t.currentTarget.style.backgroundColor="var(--df-color-error-dark, #dc2626)",t.currentTarget.style.transform="scale(1.05)"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="var(--df-color-error-primary)",t.currentTarget.style.transform="scale(1)"},children:"Clear"})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:c,formSubmitted:u,properties:i,localValidation:E(x),isTouched:y,mode:h})]})]})},dt=({id:t,properties:i,validationErrors:s={},formValue:a=null,readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:u=!1,mode:h="test",onValueChange:d,onBlur:f,onFocus:p,className:g="",hideLabel:m=!1})=>{var w,v,B,b,y,C,x,F;const[Q,U]=e([]),[E,N]=e(!1),[S,L]=e(!1),I=n(null),_=r(e=>{if(!e)return[];const A=Array.isArray(e)?e:Array.from(e),r=[];return A.forEach((e,A)=>{if(e&&"object"==typeof e&&!(e instanceof File)&&!(e instanceof Blob)){const n=e;if(n.data||n.url||n.name&&n.type){const e=n.name||n.fileName||`file-${A}`,i=n.size||n.fileSize||0,s=n.type||n.fileType||n.mimeType||"";let a;if(n.url)a=n.url;else if(n.data){const t=n.data;if("string"==typeof t)if(t.startsWith("data:"))a=t;else{const e=t.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(e)&&e.length>10){let t=s;t||(t=e.startsWith("/9j/")||e.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":e.startsWith("iVBORw0KGgo")?"image/png":e.startsWith("R0lGOD")?"image/gif":e.startsWith("UklGR")?"image/webp":"image/png"),a=`data:${t};base64,${e}`}else a=t}}const o=new File([],e,{type:s});return void r.push({file:o,id:`${t}-file-${A}`,size:i,type:s,name:e,preview:a})}}let n,i,s=0,a="",o="";if(e instanceof File||e instanceof Blob){const t=e;if(s=t.size||0,a=t.type||"",o=t.name||`file-${A}`,i=t,a.startsWith("image/"))try{n=URL.createObjectURL(t)}catch(t){console.error("Error creating object URL:",t),n=void 0}}else if("string"==typeof e){const t=e,r=t.replace(/\s/g,""),s=r.length>50&&/^[A-Za-z0-9+/=]+$/.test(r)&&!t.startsWith("http")&&!t.startsWith("https")&&!t.startsWith("data:")&&!t.startsWith("blob:")&&!t.startsWith("/");let l=t;if(s){let t="image/png";r.startsWith("/9j/")||r.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?t="image/jpeg":r.startsWith("iVBORw0KGgo")?t="image/png":r.startsWith("R0lGOD")?t="image/gif":r.startsWith("UklGR")&&(t="image/webp"),l=`data:${t};base64,${r}`}let c="";if(l.startsWith("data:")){const t=l.match(/filename=([^;]+)/i);if(t)c=decodeURIComponent(t[1]);else{const t=l.match(/data:([^;]+)/);if(t){const e=t[1];c=`file-${A+1}.${e.includes("image")?e.includes("jpeg")?"jpg":"png":e.includes("pdf")?"pdf":e.includes("word")?"doc":e.includes("excel")?"xls":"file"}`}else c=`file-${A+1}`}}else if(l.startsWith("http://")||l.startsWith("https://")||l.startsWith("blob:"))try{const e=new URL(t),r=e.pathname.split("/").pop()||"";if(r&&r.includes("."))c=decodeURIComponent(r);else{const t=e.searchParams.get("filename")||e.searchParams.get("name");c=t?decodeURIComponent(t):`file-${A+1}`}}catch(e){const r=t.lastIndexOf("/"),n=r>=0?t.substring(r+1):t,i=n.indexOf("?"),s=i>=0?n.substring(0,i):n;c=s&&s.includes(".")?decodeURIComponent(s):`file-${A+1}`}else c=`file-${A+1}`;if(o=c||`file-${A+1}`,l.startsWith("data:")){const t=l.indexOf(";");a=t>5?l.substring(5,t):"application/octet-stream"}else{const t=l.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i)||o.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(t){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"}[t[1].toLowerCase()]||"application/octet-stream"}else a=s?"image/png":"application/octet-stream"}(l.startsWith("data:image")||l.startsWith("http://")||l.startsWith("https://")||l.startsWith("blob:"))&&(n=l),i=new File([],o,{type:a})}else{if(!e||"object"!=typeof e)return;{const t=e;if(o=t.name||t.fileName||`file-${A}`,s=t.size||t.fileSize||0,a=t.type||t.fileType||t.mimeType||"",t.url||t.path)n=t.url||t.path;else if(a.startsWith("image/")&&t.data){const e=t.data;if("string"==typeof e)if(e.startsWith("data:"))n=e;else{const t=e.replace(/\s/g,"");n=/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>50?`data:${a};base64,${t}`:e}else n=void 0}i=new File([],o,{type:a})}}r.push({file:i,id:`${t}-file-${A}`,size:s,type:a,name:o,preview:n})}),r},[t]),O=r(()=>({isValid:!0,errors:{}}),[]),k=r(e=>{var A;if(o||l)return;const r=_(e),n=Q.length>0?[...Q,...r]:r,s=(null===(A=null==i?void 0:i.validation)||void 0===A?void 0:A.maxFiles)||1/0,a=n.slice(0,s);if(U(a),L(!0),d){const e=O(),A={id:t,value:a.map(t=>t.file),isValid:e.isValid,errors:e.errors};d(A)}},[Q,i,o,l,d,O,_,t]),T=t=>{if(0===t)return"0 Bytes";const e=Math.floor(Math.log(t)/Math.log(1024));return parseFloat((t/Math.pow(1024,e)).toFixed(2))+" "+["Bytes","KB","MB","GB"][e]},j=t=>t.startsWith("image/")?"🖼️":t.startsWith("video/")?"🎥":t.startsWith("audio/")?"🎵":t.includes("pdf")?"📄":t.includes("word")||t.includes("document")?"📝":t.includes("excel")||t.includes("spreadsheet")?"📊":t.includes("zip")||t.includes("rar")?"📦":"📁";A(()=>{S&&(c[t]=!0)},[S,t,c]),A(()=>{("edit"===h||"test"===h)&&L(!1)},[h]),A(()=>{const t=_(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===Q.length&&null!=a?U(t):(null==a||Array.isArray(a)&&0===a.length)&&Q.length>0&&U([])},[a,_,Q.length]),A(()=>{u&&L(!0)},[u]),A(()=>()=>{Q.forEach(t=>{if(t.preview&&t.preview.startsWith("blob:"))try{URL.revokeObjectURL(t.preview)}catch(t){console.error("Error revoking object URL:",t)}})},[Q]);const H=()=>{var t;return"left"===(null===(t=null==i?void 0:i.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"},P=l||o||(null===(w=null==i?void 0:i.validation)||void 0===w?void 0:w.readonly),D=(null===(v=null==i?void 0:i.validation)||void 0===v?void 0:v.multiple)||!1,M=(null===(B=null==i?void 0:i.validation)||void 0===B?void 0:B.accept)||"*/*",R=(null===(b=null==i?void 0:i.validation)||void 0===b?void 0:b.maxFiles)||1/0,K=Q.length<R&&(D||R>1),V="edit"===h,z="preview"===h||"test"===h,G=Q.filter(t=>t.type.startsWith("image/")),q=Q.filter(t=>!t.type.startsWith("image/")),W=G.length>0;return z&&W?X.jsxs("div",{className:`form-group ${H()}`,children:[!m&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(y=i.basic)||void 0===y?void 0:y.label)||"Attachments",(null===(C=i.validation)||void 0===C?void 0:C.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"file-upload-wrapper",children:[X.jsxs("div",{className:"file-image-display",children:[G.map(t=>X.jsxs("div",{className:"file-image-container",children:[t.preview&&X.jsx("img",{src:t.preview,alt:t.name,className:"file-image-preview"}),X.jsxs("div",{className:"file-image-info",children:[X.jsx("div",{className:"file-name",title:t.name,children:t.name}),X.jsx("div",{className:"file-size",children:T(t.size)})]})]},t.id)),q.length>0&&X.jsxs("div",{className:"file-other-files",children:[X.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),q.map(t=>X.jsxs("div",{className:"file-item-minimal",children:[X.jsx("div",{className:"file-icon",children:j(t.type)}),X.jsxs("div",{className:"file-info",children:[X.jsx("div",{className:"file-name",title:t.name,children:t.name}),X.jsx("div",{className:"file-size",children:T(t.size)})]})]},t.id))]})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:c,formSubmitted:u,properties:i,localValidation:O(),isTouched:S,mode:h})]})]}):X.jsxs("div",{className:`form-group ${H()}`,children:[!m&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(x=i.basic)||void 0===x?void 0:x.label)||"Attachments",(null===(F=i.validation)||void 0===F?void 0:F.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"file-upload-wrapper",children:[X.jsxs("div",{className:`file-upload-area ${E?"drag-over":""} ${o?"readonly":""} ${l?"disabled":""} ${g}`.trim(),onDragOver:t=>{t.preventDefault(),o||l||N(!0)},onDragLeave:t=>{t.preventDefault(),N(!1)},onDrop:t=>{if(t.preventDefault(),N(!1),o||l)return;const e=t.dataTransfer.files;e.length>0&&k(e)},onClick:t=>{var e;const A=t.target,r=null!==A.closest(".file-item"),n=null!==A.closest(".file-remove");!V||P||0!==Q.length||r||n||null===(e=I.current)||void 0===e||e.click()},onFocus:()=>{p&&p()},onBlur:()=>{if(L(!0),"test"===h&&d){const e=O(),A={id:t,value:Q.map(t=>t.file),isValid:e.isValid,errors:e.errors};d(A)}f&&f()},tabIndex:P?-1:0,children:[X.jsx("input",{ref:I,type:"file",id:t,multiple:D,accept:M,onChange:t=>{const e=t.target.files;e&&e.length>0&&(k(e),t.target.value="")},disabled:P,style:{display:"none"}}),0===Q.length?X.jsxs("div",{className:"upload-placeholder",onClick:t=>{var e;t.stopPropagation(),V&&!P&&(null===(e=I.current)||void 0===e||e.click())},children:[X.jsx("div",{className:"upload-icon",children:"📁"}),X.jsx("div",{className:"upload-text",children:i.basic.placeholder&&X.jsx("p",{className:"upload-hint",children:i.basic.placeholder})})]}):X.jsx("div",{className:"file-list",children:Q.map(e=>X.jsxs("div",{className:"file-item",children:[X.jsx("div",{className:"file-preview",children:e.preview?X.jsx("img",{src:e.preview,alt:e.name,className:"file-image"}):X.jsx("div",{className:"file-icon",children:j(e.type)})}),X.jsxs("div",{className:"file-info",children:[X.jsx("div",{className:"file-name",title:e.name,children:e.name}),X.jsx("div",{className:"file-size",children:T(e.size)})]}),V&&!P&&X.jsx("button",{type:"button",className:"file-remove",onClick:A=>{A.stopPropagation(),(e=>{if(o||l)return;const A=Q.filter(t=>t.id!==e);if(U(A),L(!0),d){const e=O(),r={id:t,value:A.map(t=>t.file),isValid:e.isValid,errors:e.errors};d(r)}})(e.id)},"aria-label":`Remove ${e.name}`,children:"✕"})]},e.id))})]}),Q.length>0&&K&&!P&&V&&X.jsxs("button",{type:"button",className:"file-add-more",onClick:t=>{t.stopPropagation(),!P&&I.current&&V&&(I.current.value="",I.current.click())},"aria-label":"Add more files",children:[X.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:X.jsx("path",{d:"M12 5v14M5 12h14"})}),X.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:c,formSubmitted:u,properties:i,localValidation:O(),isTouched:S,mode:h})]})]})},ft=({id:t,properties:i,validationErrors:s={},formValue:o=null,readonly:l=!1,disabled:c=!1,touchedFields:u={},formSubmitted:h=!1,mode:g="test",onValueChange:m,onBlur:w,onFocus:v,className:B="",hideLabel:b=!1})=>{var y,C,x,F;const[Q,U]=e(o),[E,N]=e(!1),[S,L]=e(""),[I,_]=e(!1),[O,k]=e(!1),[T,j]=e({lat:40.7128,lng:-74.006}),[H,P]=e(null),[D,M]=e(10),[R,K]=e(""),[V,z]=e(!1),G=n(null),[q,W]=e(!1),[Y,J]=e(null),[$,At]=e(!1);A(()=>{if(o&&o.latitude&&o.longitude){40.7128===o.latitude&&-74.006===o.longitude||(U(o),P({lat:o.latitude,lng:o.longitude,isCurrentLocation:!1}),j({lat:o.latitude,lng:o.longitude}))}else null==o&&(U(null),P(null))},[o]),A(()=>{O&&40.7128===T.lat&&T.lng},[O,T]),A(()=>{(l||c)&&(O&&k(!1),R&&K(""),q&&(W(!1),J(null)))},[l,c]);const rt=r((t,e)=>tt(void 0,void 0,void 0,function*(){At(!0);try{const A=yield fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${t}&lon=${e}&addressdetails=1&zoom=18`),r=yield A.json();if(r&&r.address){const t=r.address;return{placeName:r.display_name||"",city:t.city||t.town||t.village||t.municipality||"",country:t.country||""}}}catch(t){console.error("Reverse geocoding failed:",t)}finally{At(!1)}return{placeName:"",city:"",country:""}}),[]),nt=r((e,A,r)=>tt(void 0,void 0,void 0,function*(){const n=yield rt(e,A),i=Object.assign({latitude:e,longitude:A,timestamp:Date.now(),placeName:n.placeName,city:n.city,country:n.country,address:n.placeName},r);if(U(i),P({lat:e,lng:A,isCurrentLocation:!1}),_(!0),m){m({id:t,value:i,isValid:!0,errors:{}})}}),[rt,t,m]),it=r(()=>tt(void 0,void 0,void 0,function*(){var t,e,A,r,n,s,a,o,u,h,d,f,p,g,m;if(l||c)return;N(!0),L("");if(void 0!==window.Capacitor)try{const{Geolocation:l}=window.Capacitor.Plugins;if(l)try{if("granted"!==(yield l.requestPermissions()).location)return N(!1),void L("Location permission is required. Please enable location access in your device settings.");const a=yield l.getCurrentPosition({enableHighAccuracy:null===(e=null===(t=i.validation)||void 0===t?void 0:t.enableHighAccuracy)||void 0===e||e,timeout:null!==(r=null===(A=i.validation)||void 0===A?void 0:A.timeout)&&void 0!==r?r:1e4,maximumAge:null!==(s=null===(n=i.validation)||void 0===n?void 0:n.maximumAge)&&void 0!==s?s:3e5}),o=a.coords.latitude,c=a.coords.longitude;return P({lat:o,lng:c,isCurrentLocation:!0}),j({lat:o,lng:c}),_(!0),yield nt(o,c,{accuracy:a.coords.accuracy,timestamp:Date.now()}),N(!1),void L("")}catch(t){return N(!1),void((null===(a=t.message)||void 0===a?void 0:a.includes("permission"))||(null===(o=t.message)||void 0===o?void 0:o.includes("denied"))?L("Location permission is required. Please enable location access in your device settings."):(null===(u=t.message)||void 0===u?void 0:u.includes("timeout"))?L("Location request timed out. Please try again."):L("Unable to retrieve your location. Please try again."))}}catch(t){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return N(!1),void L("Geolocation is not supported by this browser.");const w={enableHighAccuracy:null===(d=null===(h=i.validation)||void 0===h?void 0:h.enableHighAccuracy)||void 0===d||d,timeout:null!==(p=null===(f=i.validation)||void 0===f?void 0:f.timeout)&&void 0!==p?p:1e4,maximumAge:null!==(m=null===(g=i.validation)||void 0===g?void 0:g.maximumAge)&&void 0!==m?m:3e5};navigator.geolocation.getCurrentPosition(t=>tt(void 0,void 0,void 0,function*(){const e=t.coords.latitude,A=t.coords.longitude;P({lat:e,lng:A,isCurrentLocation:!0}),j({lat:e,lng:A}),_(!0),yield nt(e,A,{accuracy:t.coords.accuracy,timestamp:t.timestamp}),N(!1),L("")}),t=>{N(!1);let e="Unable to retrieve your location.";switch(t.code){case t.PERMISSION_DENIED:e="Location access denied by user. Please enable location access in your browser/device settings.";break;case t.POSITION_UNAVAILABLE:e="Location information is unavailable.";break;case t.TIMEOUT:e="Location request timed out. Please try again."}L(e)},w)}),[l,c,i,nt]),st=r(()=>{if(!l&&!c&&(U(null),P(null),L(""),_(!0),m)){m({id:t,value:null,isValid:!0,errors:{}})}},[l,c,t,m]),at=r(()=>{l||c||k(!O)},[l,c,O]),ot=r((t,e,A,r,n,i)=>{const s=t-n/2,a=e-i/2,o=156543.03392*Math.cos(A.lat*Math.PI/180)/Math.pow(2,r),l=s*o,c=a*o;return{lat:A.lat+c/111320,lng:A.lng+l/(111320*Math.cos(A.lat*Math.PI/180))}},[]),lt=r(t=>{l||c||!G.current||0===t.button&&(W(!0),J({x:t.clientX,y:t.clientY}),t.preventDefault())},[l,c]),ct=r(t=>{if(!q||!Y||!G.current)return;const e=t.clientX-Y.x,A=t.clientY-Y.y,r=156543.03392*Math.cos(T.lat*Math.PI/180)/Math.pow(2,D),n=-A*r/111320,i=e*r/(111320*Math.cos(T.lat*Math.PI/180));j({lat:T.lat+n,lng:T.lng+i}),J({x:t.clientX,y:t.clientY})},[q,Y,T,D]),ut=r(t=>tt(void 0,void 0,void 0,function*(){if(!G.current)return;if(q&&Y){const e=Math.abs(t.clientX-Y.x),A=Math.abs(t.clientY-Y.y);if(e>5||A>5)return W(!1),void J(null)}if(l||c)return W(!1),void J(null);const e=G.current.getBoundingClientRect(),A=t.clientX-e.left,r=t.clientY-e.top,{lat:n,lng:i}=ot(A,r,T,D,e.width,e.height);yield nt(n,i),W(!1),J(null)}),[l,c,G,T,D,ot,nt,q,Y]),ht=r(e=>tt(void 0,void 0,void 0,function*(){if(e.trim()&&!l&&!c){z(!0),L("");try{const A=yield fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(e)}&limit=5&addressdetails=1`),r=yield A.json();if(r&&r.length>0){const e=r[0],A=parseFloat(e.lat),n=parseFloat(e.lon),i=e.address||{},s={latitude:A,longitude:n,address:e.display_name,placeName:e.display_name,city:i.city||i.town||i.village||i.municipality||"",country:i.country||"",timestamp:Date.now()};if(U(s),P({lat:A,lng:n,isCurrentLocation:!1}),j({lat:A,lng:n}),_(!0),m){m({id:t,value:s,isValid:!0,errors:{}})}}else L("No locations found for your search.")}catch(t){L("Failed to search for location. Please try again.")}finally{z(!1)}}}),[l,c,t,m]),dt=()=>{v&&v()},ft=()=>{_(!0),w&&w()},pt=c||l||(null===(y=null==i?void 0:i.validation)||void 0===y?void 0:y.readonly),gt=(null===(C=null==i?void 0:i.basic)||void 0===C?void 0:C.label)||"Location",mt=(null===(x=null==i?void 0:i.basic)||void 0===x?void 0:x.description)||"";return X.jsxs("div",{className:`form-group ${b?"no-label":""} ${B}`,children:[!b&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[gt,(null===(F=null==i?void 0:i.validation)||void 0===F?void 0:F.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]}),mt&&X.jsx("div",{className:"form-group-description",children:mt}),X.jsxs("div",{className:"location-wrapper",children:[!(l&&Q)&&X.jsxs("div",{className:"location-controls",children:[X.jsx("button",{type:"button",className:"location-btn "+(E?"loading":""),onClick:it,disabled:pt||E,onFocus:dt,onBlur:ft,tabIndex:pt?-1:0,children:E?X.jsxs(X.Fragment,{children:[X.jsx(d,{size:16,className:"loading-spinner"}),"Getting Location..."]}):X.jsxs(X.Fragment,{children:[X.jsx(f,{size:16}),"Get Current Location"]})}),X.jsxs("button",{type:"button",className:"location-btn secondary",onClick:at,disabled:pt,onFocus:dt,onBlur:ft,tabIndex:pt?-1:0,children:[X.jsx(p,{size:16}),O?"Hide Map":"Choose on Map"]})]}),Q&&X.jsxs("div",{className:"location-display",children:[!l&&X.jsx("button",{type:"button",className:"location-clear-btn",onClick:st,disabled:pt,title:"Clear location",children:X.jsx(a,{size:16})}),Q.placeName&&X.jsxs("div",{className:"location-place-name",children:[X.jsx("strong",{children:"Place:"})," ",Q.placeName]}),(Q.city||Q.country)&&X.jsxs("div",{className:"location-address",children:[X.jsx("strong",{children:"Address:"})," ",[Q.city,Q.country].filter(Boolean).join(", ")]}),X.jsxs("div",{className:"location-coordinates",children:[X.jsx("strong",{children:"Coordinates:"})," ",(vt=Q.latitude,Bt=Q.longitude,void 0===vt||void 0===Bt||isNaN(vt)||isNaN(Bt)?"":`${Number(vt).toFixed(6)}, ${Number(Bt).toFixed(6)}`)]}),Q.accuracy&&X.jsxs("div",{className:"location-accuracy",children:[X.jsx("strong",{children:"Accuracy:"})," ",(wt=Q.accuracy,wt?`±${Math.round(wt)}m`:"")]}),Q.timestamp&&X.jsxs("div",{className:"location-timestamp",children:[X.jsx("strong",{children:"Captured:"})," ",(et(Q.timestamp)||new Date).toLocaleString()]})]}),O&&!l&&X.jsxs("div",{className:"location-map-container",children:[X.jsxs("div",{className:"location-map-header",children:[X.jsx("h4",{children:"Select Location on Map"}),X.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),X.jsx("div",{className:"location-search",children:X.jsx("form",{onSubmit:t=>{t.preventDefault(),R.trim()&&ht(R)},className:"search-form",children:X.jsxs("div",{className:"search-input-group",children:[X.jsx("input",{type:"text",value:R,onChange:t=>{K(t.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:pt||V}),X.jsx("button",{type:"submit",className:"search-btn",disabled:pt||V||!R.trim(),children:V?X.jsx(d,{size:16,className:"loading-spinner"}):"Search"})]})})}),X.jsxs("div",{ref:G,className:"location-map "+(q?"dragging":""),onMouseDown:lt,onMouseMove:ct,onMouseUp:ut,onMouseLeave:()=>{W(!1),J(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:q?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${D}/${Math.floor((T.lng+180)/360*Math.pow(2,D))}/${Math.floor((1-Math.log(Math.tan(T.lat*Math.PI/180)+1/Math.cos(T.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,D))}.png) center/cover no-repeat`,userSelect:"none"},children:[H&&X.jsx("div",{className:"map-marker "+(H.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:X.jsx(p,{size:24})}),X.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}}),X.jsxs("div",{className:"map-controls",children:[X.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>M(t=>Math.min(18,t+1)),disabled:D>=18,children:"+"}),X.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>M(t=>Math.max(1,t-1)),disabled:D<=1,children:"−"})]})]}),X.jsxs("div",{className:"location-map-instructions",children:[X.jsx("p",{children:X.jsx("strong",{children:"Instructions:"})}),X.jsxs("ul",{children:[X.jsx("li",{children:"Search for a place using the search box above"}),X.jsx("li",{children:"Click anywhere on the map to select a location"}),X.jsx("li",{children:"Drag the map to pan around"}),X.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),X.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),$&&X.jsxs("div",{className:"location-loading",children:[X.jsx(d,{size:16,className:"loading-spinner"}),X.jsx("span",{children:"Loading address details..."})]})]}),S&&X.jsx("div",{className:"location-error",children:S})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:u,formSubmitted:h,properties:i,localValidation:{isValid:!0,errors:{}},isTouched:I,mode:g})]});var wt,vt,Bt},pt=({id:t,properties:e,className:A="",hideLabel:r=!1})=>{var n,i,s;const a=null!==(s=null!==(i=null===(n=e.styles)||void 0===n?void 0:n.level)&&void 0!==i?i:e.basic.level)&&void 0!==s?s:1,o=e.basic.label,l=()=>{var t;return`form-heading ${`h${a}`} ${(null===(t=null==e?void 0:e.styles)||void 0===t?void 0:t.textAlign)?`text-${e.styles.textAlign}`:""} ${A}`.trim()},c=()=>{var t,A;const r={};return(null===(t=null==e?void 0:e.styles)||void 0===t?void 0:t.fontSize)&&(r.fontSize=e.styles.fontSize),(null===(A=null==e?void 0:e.styles)||void 0===A?void 0:A.color)&&(r.color=e.styles.color),r};return r?null:(()=>{const e={id:t,className:l(),style:c()};switch(a){case 1:default:return X.jsx("h1",Object.assign({},e,{children:o}));case 2:return X.jsx("h2",Object.assign({},e,{children:o}));case 3:return X.jsx("h3",Object.assign({},e,{children:o}));case 4:return X.jsx("h4",Object.assign({},e,{children:o}));case 5:return X.jsx("h5",Object.assign({},e,{children:o}));case 6:return X.jsx("h6",Object.assign({},e,{children:o}))}})()},gt=({id:t,properties:i,mode:s="preview",formValue:a,onValueChange:o,className:l="",hideLabel:c=!1})=>{var u,h,d;const[f,p]=e(""),[b,y]=e((null===(u=i.validation)||void 0===u?void 0:u.listStyle)||"numbers"),[C,x]=e("#000000"),F=n(null),Q=n(null),U=n(!1),E="edit"===s,N=n({instructions:[],listStyle:"numbers",formValue:void 0}),S=n(s);A(()=>{var t,e,A,r,n;let o=[],l="numbers";if(null!=a&&("object"==typeof a&&a.instructions?(Array.isArray(a.instructions)?o=a.instructions:"string"==typeof a.instructions&&(o=[a.instructions]),a.listStyle&&(l=a.listStyle)):Array.isArray(a)?o=a:"string"==typeof a&&(o=[a])),0===o.length&&(null===(t=i.basic)||void 0===t?void 0:t.value)){const t=i.basic.value;t&&"object"==typeof t&&!Array.isArray(t)&&t.instructions?(Array.isArray(t.instructions)?o=t.instructions:"string"==typeof t.instructions&&(o=[t.instructions]),t.listStyle&&"string"==typeof t.listStyle&&(l=t.listStyle)):Array.isArray(t)?o=t:"string"==typeof t&&(o=[t])}0===o.length&&(null===(e=i.basic)||void 0===e?void 0:e.instructions)&&(Array.isArray(i.basic.instructions)?o=i.basic.instructions:"string"==typeof i.basic.instructions&&(o=[i.basic.instructions])),l&&"numbers"!==l||(l=(null===(A=i.validation)||void 0===A?void 0:A.listStyle)||(null===(n=null===(r=i.basic)||void 0===r?void 0:r.value)||void 0===n?void 0:n.listStyle)||"numbers");const c=JSON.stringify(o)!==JSON.stringify(N.current.instructions)||l!==N.current.listStyle,u=s!==S.current,h=JSON.stringify(a)!==JSON.stringify(N.current.formValue),d=!N.current.formValue||Array.isArray(N.current.formValue)&&0===N.current.formValue.length||"string"==typeof N.current.formValue&&""===N.current.formValue.trim(),f=null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==a.trim()||"object"==typeof a&&Object.keys(a).length>0);if(c||u||h||d&&f){const t=t=>"string"!=typeof t?t:t.replace(/\\u([0-9a-fA-F]{4})/g,(t,e)=>String.fromCharCode(parseInt(e,16))),e=o.map(e=>"string"==typeof e?t(e):e),A=e.some(t=>"string"==typeof t&&/<[^>]+>/.test(t));let r="";if(e.length>0)if(A)r=e.join("");else{const t="numbers"===l?"ol":"bullets"===l?"ul":"div",A=e.filter(t=>t&&"string"==typeof t).map(t=>`<li>${t.replace(/\n/g,"<br>")}</li>`).join("");r="div"===t?e.filter(t=>t&&"string"==typeof t).map(t=>`<div>${t.replace(/\n/g,"<br>")}</div>`).join(""):`<${t}>${A}</${t}>`}y(l),p(r),E&&F.current&&(u||c&&F.current.innerHTML.trim()!==r.trim())&&(F.current.innerHTML=r),N.current={instructions:o,listStyle:l,formValue:a},S.current=s}},[a,null===(h=i.basic)||void 0===h?void 0:h.instructions,null===(d=i.validation)||void 0===d?void 0:d.listStyle,s,E]),A(()=>{if(E&&F.current){const t=F.current.innerHTML.trim();f.trim()===t||U.current||(F.current.innerHTML=f)}if(U.current){const t=setTimeout(()=>{U.current=!1},200);return()=>clearTimeout(t)}},[f,E]);const L=r(()=>{if(!F.current)return;U.current=!0;const e=F.current.innerHTML.trim();if(o){o({id:t,value:{instructions:e?[e]:[],listStyle:b},isValid:!0,errors:{}})}e!==f&&p(e)},[t,b,o,f]),I=r(()=>{if(!F.current)return;const e=F.current.innerHTML.trim();if(o){o({id:t,value:{instructions:e?[e]:[],listStyle:b},isValid:!0,errors:{}})}p(e),U.current=!1},[t,b,o]),_=r((t,e)=>{var A;document.execCommand(t,!1,e),null===(A=F.current)||void 0===A||A.focus(),L()},[L]),O=r(()=>{_("bold")},[_]),k=r(()=>{_("italic")},[_]),T=r(t=>{const e=t.target.value;x(e),_("foreColor",e)},[_]),j=r(e=>{if(y(e),!F.current)return;const A=window.getSelection(),r=A&&A.rangeCount>0?A.getRangeAt(0):null;let n=F.current.innerHTML;if("numbers"===e){if(n=n.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!n.includes("<ol>")&&!n.includes("<ul>")){const t=n.split(/<br\s*\/?>/i).filter(t=>t.trim());t.length>0&&(n="<ol>"+t.map(t=>`<li>${t}</li>`).join("")+"</ol>")}}else if("bullets"===e){if(n=n.replace(/<ol>/gi,"<ul>").replace(/<\/ol>/gi,"</ul>"),!n.includes("<ol>")&&!n.includes("<ul>")){const t=n.split(/<br\s*\/?>/i).filter(t=>t.trim());t.length>0&&(n="<ul>"+t.map(t=>`<li>${t}</li>`).join("")+"</ul>")}}else n=n.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(F.current.innerHTML=n,p(n),r&&A)try{A.removeAllRanges(),A.addRange(r)}catch(t){}if(L(),o){o({id:t,value:{instructions:n?[n]:[],listStyle:e},isValid:!0,errors:{}})}},[t,L,o]),H=r(t=>{var e;const A=null===(e=t.target.files)||void 0===e?void 0:e[0];if(!A||!A.type.startsWith("image/"))return;const r=new FileReader;r.onload=t=>{var e;const A=null===(e=t.target)||void 0===e?void 0:e.result;if(A&&F.current){const t=document.createElement("img");t.src=A,t.style.maxWidth="100%",t.style.height="auto";const e=window.getSelection();if(e&&e.rangeCount>0){const A=e.getRangeAt(0);A.deleteContents(),A.insertNode(t)}else F.current.appendChild(t);L()}},r.readAsDataURL(A),Q.current&&(Q.current.value="")},[L]),P=r(t=>{t.preventDefault();const e=t.clipboardData.getData("text/plain"),A=window.getSelection();if(A&&A.rangeCount>0){const t=A.getRangeAt(0);t.deleteContents();const r=document.createTextNode(e);t.insertNode(r),t.setStartAfter(r),t.collapse(!0),A.removeAllRanges(),A.addRange(t)}L()},[L]),D=r(t=>document.queryCommandState(t),[]);return X.jsxs("div",{className:`form-group instruction-group ${l}`,children:[!c&&X.jsx("label",{htmlFor:t,className:"instruction-label",children:"Instructions"}),E?X.jsxs("div",{className:"instruction-rich-editor",children:[X.jsxs("div",{className:"instruction-toolbar",children:[X.jsxs("div",{className:"toolbar-group",children:[X.jsx("button",{type:"button",className:"toolbar-btn "+(D("bold")?"active":""),onClick:O,title:"Bold","aria-label":"Bold",children:X.jsx(g,{size:16})}),X.jsx("button",{type:"button",className:"toolbar-btn "+(D("italic")?"active":""),onClick:k,title:"Italic","aria-label":"Italic",children:X.jsx(m,{size:16})})]}),X.jsx("div",{className:"toolbar-separator"}),X.jsx("div",{className:"toolbar-group",children:X.jsxs("div",{className:"color-picker-wrapper",children:[X.jsx("input",{type:"color",value:C,onChange:T,className:"color-picker-input",title:"Text Color"}),X.jsx("label",{className:"color-picker-label",title:"Text Color",children:X.jsx("span",{style:{color:C},children:"A"})})]})}),X.jsx("div",{className:"toolbar-separator"}),X.jsxs("div",{className:"toolbar-group",children:[X.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===b?"active":""),onClick:()=>j("bullets"),title:"Bullet List","aria-label":"Bullet List",children:X.jsx(w,{size:16})}),X.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===b?"active":""),onClick:()=>j("numbers"),title:"Numbered List","aria-label":"Numbered List",children:X.jsx(v,{size:16})})]}),X.jsx("div",{className:"toolbar-separator"}),X.jsxs("div",{className:"toolbar-group",children:[X.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>{var t;return null===(t=Q.current)||void 0===t?void 0:t.click()},title:"Insert Image","aria-label":"Insert Image",children:X.jsx(B,{size:16})}),X.jsx("input",{ref:Q,type:"file",accept:"image/*",onChange:H,style:{display:"none"}})]})]}),X.jsx("div",{ref:F,contentEditable:!0,className:"instruction-editor-content",onInput:L,onBlur:I,onPaste:P,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):X.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===b?"instruction-list-numbers":"bullets"===b?"instruction-list-bullets":""),children:f?X.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:f}}):X.jsx("div",{className:"instruction-empty",children:X.jsx("p",{children:"No instructions provided"})})})]})},mt=({attachments:t,onRemove:r})=>{const[n,i]=e(new Map);return A(()=>{if(!t)return void i(t=>(t.forEach(t=>URL.revokeObjectURL(t)),new Map));const e=new Map;return t.forEach((t,A)=>{if(t&&t.type&&"string"==typeof t.type&&t.type.startsWith("image/")){const r=URL.createObjectURL(t);e.set(A,r)}}),i(t=>(t.forEach((t,A)=>{e.has(A)||URL.revokeObjectURL(t)}),e)),()=>{e.forEach(t=>URL.revokeObjectURL(t))}},[t]),t&&0!==t.length?X.jsx("div",{className:"attachment-thumbnails-container",children:t.map((t,e)=>{const A=t&&t.type&&"string"==typeof t.type&&t.type.startsWith("image/"),i=n.get(e);return X.jsx("div",{className:"attachment-thumbnail",children:A&&i?X.jsxs(X.Fragment,{children:[X.jsx("img",{src:i,alt:t?t.name:"Attachment"}),X.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(e),title:"Remove attachment",children:X.jsx(a,{size:14})})]}):X.jsxs(X.Fragment,{children:[X.jsx("div",{className:"file-icon-placeholder",children:X.jsx(h,{size:20})}),X.jsx("span",{className:"file-name",children:t?t.name:"Unknown File"}),X.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(e),title:"Remove attachment",children:X.jsx(a,{size:14})})]})},e)})}):null},wt=({component:t,mode:i,formTemplateId:s,formValue:a,onNotesChange:o,onAttachmentChange:l,notes:u="",attachments:d=null,onThresholdActionCompletion:f,onThresholdIssueRaised:p,onBasicPropertyActionCompletion:g,workOrderNumber:m,assetNumber:w,isStandalone:v,user:B,onCreateIssue:Q,onUpdateIssue:U})=>{var E,N,S,L;const[I,_]=e(u||""),[O,k]=e(d||null),[T,j]=e(!1),[H,P]=e(!1),[D,M]=e(!1),[R,K]=e(!1),[V,z]=e(null),[G,q]=e(!1),W=n(null),Y=n(a),J=n(!1),$=n(!1);A(()=>{if(!J.current&&null!=u){const t="string"==typeof u?u:String(u||"");_(t),J.current=!0}},[u]),A(()=>{$.current||void 0===d||(k(d),$.current=!0)},[d]),A(()=>{if(J.current&&!T&&null!=u){const t="string"==typeof u?u:String(u||"");I&&""!==String(I||"").trim()||!t||""===t.trim()?t&&""!==t.trim()&&t!==I&&_(t):_(t)}},[u,T,I]),A(()=>{$.current&&void 0!==d&&(!O||d&&d.length>0&&d!==O)&&k(d)},[d,O]),A(()=>{const e=["select","radio","checkbox","segment"].includes(t.name||"");if(e){const e=Y.current,A=a;let r=!1;if("checkbox"===t.name){const t=Array.isArray(e)?e:e?[e]:[],n=Array.isArray(A)?A:A?[A]:[];r=JSON.stringify(t.sort())!==JSON.stringify(n.sort())}else r=e!==A&&void 0!==e;if(r){M(!1),K(!1),z(null),P(!1),j(!1),q(!1);const t="string"==typeof u?u:String(u||"");t&&""!==t.trim()?_(t):_(""),d&&0!==d.length?k(d):k(null)}Y.current=A}e||(Y.current=a)},[a,t.name,u,d]);const Z=r((t,e)=>{const{operator:A,value:r}=t,n=String(e).toLowerCase(),i=String(r).toLowerCase();switch(A){case"equals":return n===i||String(e)===String(r);case"notEquals":return n!==i&&String(e)!==String(r);case"greaterThan":return Number(e)>Number(r);case"lessThan":return Number(e)<Number(r);case"greaterThanOrEqual":return Number(e)>=Number(r);case"lessThanOrEqual":return Number(e)<=Number(r);default:return!1}},[]),tt=r(()=>{if(!(null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length)))return[];const e=t.condition;if(!e||!e.conditions||0===e.conditions.length)return[];const A=[];if("checkbox"===t.name&&Array.isArray(a))a.forEach(t=>{const r=e.conditions.find(e=>Z(e,t));r&&!A.find(t=>t.id===r.id)&&A.push(r)});else{const t=e.conditions.find(t=>Z(t,a));t&&A.push(t)}return A},[t,a,Z]),et=r(e=>{const A=e.target.value;_(A),o&&o(A);const r=tt(),n=String(A||"").trim().length>0;r.forEach(t=>{!0===t.enableNotes&&f&&f(t.id,"notes",n)});const i=t.condition;!(i&&i.conditions&&i.conditions.length>0)&&g&&g("notes",n)},[o,tt,f,t,g]),At=r(()=>{if(o){const t="string"==typeof I?I:String(I||"");o(t),setTimeout(()=>{j(!1)},0)}else j(!1)},[I,o]),nt=r(()=>{At()},[At]),it=r(t=>{(t.ctrlKey||t.metaKey)&&"Enter"===t.key&&(t.preventDefault(),At())},[At]),st=r(()=>{j(!0)},[]),at=r(()=>{j(!0)},[]),ot=r(()=>{var t;null===(t=W.current)||void 0===t||t.click()},[]),lt=r(e=>{const A=e.target.files;if(A&&A.length>0){const e=Array.from(A);k(e),l&&l(e);tt().forEach(t=>{!0===t.enableAttachment&&f&&f(t.id,"attachments",!0)});const r=t.condition;!(r&&r.conditions&&r.conditions.length>0)&&g&&g("attachments",!0)}W.current&&(W.current.value="")},[l,tt,f,t,g]),ct=r(e=>{if(O){const A=O.filter((t,A)=>A!==e);if(0===A.length){k(null),l&&l(null);tt().forEach(t=>{!0===t.enableAttachment&&f&&f(t.id,"attachments",!1)});const e=t.condition;!(e&&e.conditions&&e.conditions.length>0)&&g&&g("attachments",!1)}else k(A),l&&l(A)}},[O,l,tt,f,t,g]),ut=r(()=>{M(!0);tt().forEach(t=>{!0===t.enableSendEmail&&f&&f(t.id,"email",!0)});const e=t.condition;!(e&&e.conditions&&e.conditions.length>0)&&g&&g("email",!0),setTimeout(()=>{M(!1)},3e3)},[tt,f,t,g]),ht=r(()=>{P(!0)},[]),dt=r(()=>{P(!1)},[]),ft=r(e=>{P(!1),K(!0),e&&z(e);const A=t.condition;if(A&&A.conditions&&A.conditions.length>0){tt().forEach(t=>{!0===t.enableRaiseIssue&&p&&p(t.id)})}else g&&g("issue",!0)},[t,g,tt,p]);if("test"!==i)return null;const pt=["select","radio","checkbox","segment"].includes(t.name||""),gt=(null===(E=t.basic)||void 0===E?void 0:E.options)||t.options||[];let wt=!1,vt=!1,Bt=!1,bt=!1,yt=null;const Ct=null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length),xt=t.condition,Ft=xt&&xt.conditions&&xt.conditions.length>0;if(Ft&&Ct)if("checkbox"===t.name&&Array.isArray(a)){const t=a;for(const e of t){const t=xt.conditions.find(t=>Z(t,e));t&&(wt=wt||!0===t.enableNotes,vt=vt||!0===t.enableAttachment,Bt=Bt||!0===t.enableRaiseIssue,bt=bt||!0===t.enableSendEmail)}}else if(pt){const t=xt.conditions.find(t=>Z(t,a));t&&(wt=!0===t.enableNotes,vt=!0===t.enableAttachment,Bt=!0===t.enableRaiseIssue,bt=!0===t.enableSendEmail)}else{const t=xt.conditions.find(t=>Z(t,a));t&&(wt=!0===t.enableNotes,vt=!0===t.enableAttachment,Bt=!0===t.enableRaiseIssue,bt=!0===t.enableSendEmail)}if(!Ft){const e=t.basic,A=!0===(null==e?void 0:e.enableNotes),r=!0===(null==e?void 0:e.enableAttachment),n=!0===(null==e?void 0:e.enableRaiseIssue),i=!0===(null==e?void 0:e.enableSendEmail);if(pt)if(Ct)if("checkbox"===t.name){(Array.isArray(a)?a:[a]).forEach(t=>{const e=gt.find(e=>!(!e||!e.value)&&(e.value===t||(String(e.value)===String(t)||(e.label===t||String(e.label)===String(t)))));e&&(wt=wt||!0===e.enableNotes,vt=vt||!0===e.enableAttachment,Bt=Bt||!0===e.enableRaiseIssue,bt=bt||!0===e.enableSendEmail,yt||(yt=e))}),wt=wt||A,vt=vt||r,Bt=Bt||n,bt=bt||i}else if(yt=gt.find(t=>!(!t||!t.value)&&(t.value===a||(String(t.value)===String(a)||(t.label===a||String(t.label)===String(a))))),yt){const t=!0===yt.enableNotes,e=!0===yt.enableAttachment,s=!0===yt.enableRaiseIssue,a=!0===yt.enableSendEmail;wt=t||A,vt=e||r,Bt=s||n,bt=a||i}else wt=A,vt=r,Bt=n,bt=i;else wt=A,vt=r,Bt=n,bt=i;else wt=A,vt=r,Bt=n,bt=i}if(!(wt||vt||Bt||bt))return null;const Qt=tt(),Ut=t.condition,Et=Ut&&Ut.conditions&&Ut.conditions.length>0,Nt=!!Et&&Qt.some(t=>!0===t.enableNotes),St=!!Et&&Qt.some(t=>!0===t.enableAttachment),Lt=!!Et&&Qt.some(t=>!0===t.enableSendEmail),It=!!Et&&Qt.some(t=>!0===t.enableRaiseIssue),_t=String(I||"").trim().length>0,Ot=O&&O.length>0,kt=O?O.length:0;return X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"component-action-features",children:[X.jsxs("div",{className:"action-icons-toolbar",children:[wt&&X.jsxs("button",{type:"button",className:`action-icon-button ${_t?"active":""} ${Nt?"mandatory":""}`,onClick:st,title:"Add Notes",children:[X.jsx(c,{size:14,fill:_t?"currentColor":"none"}),Nt&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),vt&&X.jsxs("button",{type:"button",className:`action-icon-button ${Ot?"active":""} ${St?"mandatory":""}`,onClick:ot,title:"Add Attachment",children:[X.jsx(h,{size:14,fill:Ot?"currentColor":"none"}),kt>0&&X.jsx("span",{className:"attachment-count-badge",children:kt}),St&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),bt&&X.jsxs("button",{type:"button",className:`action-icon-button ${D?"active sent":""} ${Lt?"mandatory":""}`,onClick:ut,disabled:D,title:"Send Email",children:[D?X.jsx(X.Fragment,{children:X.jsx(b,{size:14})}):X.jsx(y,{size:14,fill:D?"currentColor":"none"}),Lt&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),Bt&&X.jsxs("button",{type:"button",className:`action-icon-button ${R?"active":""} ${It?"mandatory":""}`,onClick:ht,title:"Raise an Issue",children:[X.jsx(C,{size:14,fill:R?"currentColor":"none"}),It&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(_t&&wt||Ot&&vt)&&X.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>q(!G),title:G?"Collapse":"Expand",children:G?X.jsx(x,{size:14}):X.jsx(F,{size:14})})]}),T&&wt&&X.jsxs("div",{className:"notes-input-overlay",children:[X.jsx("textarea",{className:"action-notes-textarea",value:I,onChange:et,onBlur:nt,onKeyDown:it,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),X.jsxs("div",{className:"notes-input-actions",children:[X.jsx("button",{type:"button",className:"notes-save-button",onClick:At,title:"Save notes (Ctrl+Enter)",children:"Save"}),X.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{j(!1)},title:"Cancel",children:"Cancel"})]})]}),G&&X.jsxs("div",{className:"actions-content",children:[!T&&_t&&wt&&X.jsx("div",{className:"notes-summary-section",children:X.jsxs("div",{className:"notes-full-text",onClick:at,children:[X.jsx("span",{className:"notes-label",children:"Notes:"})," ",I]})}),Ot&&vt&&X.jsx("div",{className:"attachments-section",children:X.jsx(mt,{attachments:O,onRemove:ct})})]}),vt&&X.jsx("input",{ref:W,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:lt,style:{display:"none"}})]}),H&&X.jsx(rt,{isOpen:H,onClose:dt,onSuccess:ft,issue:V,component:yt?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{label:`${(null===(N=t.basic)||void 0===N?void 0:N.label)||"Component"} - ${yt.label||yt.value}`,value:yt.value||(null===(S=t.basic)||void 0===S?void 0:S.value)||""})}):Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{value:null!=a?Array.isArray(a)?a.join(", "):String(a):(null===(L=t.basic)||void 0===L?void 0:L.value)||""})}),formTemplateId:s||"",notes:I,attachments:O,workOrderNumber:m,assetNumber:w,user:B,isStandalone:v,onCreateIssue:Q,onUpdateIssue:U})]})},vt=({attachments:t})=>t&&0!==t.length?X.jsx("div",{className:"attachment-thumbnails-container",children:t.map((t,e)=>{var A;const r=(null===(A=t.type)||void 0===A?void 0:A.startsWith("image/"))||!1,n=r?(t=>t.data?t.data.startsWith("data:")?t.data:`data:${t.type||"image/png"};base64,${t.data}`:"")(t):"";return X.jsx("div",{className:"attachment-thumbnail",children:r&&n?X.jsx("img",{src:n,alt:t.name||`Attachment ${e+1}`}):X.jsxs("div",{className:"file-icon-placeholder",children:[X.jsx(h,{size:20}),X.jsx("span",{className:"file-name",children:t.name||`File ${e+1}`})]})},e)})}):null,Bt=({component:t})=>{var e,A;const r=(null===(e=t.basic)||void 0===e?void 0:e.notes)||"",n=(null===(A=t.basic)||void 0===A?void 0:A.attachments)||[],i=r&&r.trim().length>0,s=n&&n.length>0;return i||s?X.jsx("div",{className:"component-submission-actions",children:X.jsxs("div",{className:"actions-content",children:[i&&X.jsx("div",{className:"notes-summary-section",children:X.jsxs("div",{className:"notes-full-text",children:[X.jsx("span",{className:"notes-label",children:"Notes:"})," ",r]})}),s&&X.jsx("div",{className:"attachments-section",children:X.jsx(vt,{attachments:n})})]})}):null},bt=({child:t,selectedChild:e,mode:A,onChildSelect:r,onChildDelete:n,renderFormComponent:i,isOverlay:s=!1,isChildrenEditMode:a=!1,formData:o={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w})=>{var v,B;const b=o[t.id],y="preview"===A&&((null===(v=t.basic)||void 0===v?void 0:v.notes)&&t.basic.notes.trim().length>0||(null===(B=t.basic)||void 0===B?void 0:B.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0),{attributes:C,listeners:x,setNodeRef:F,transform:Q,transition:S,isDragging:L,isSorting:I}=j({id:t.id,disabled:s||"edit"!==A}),_={transform:P.Transform.toString(Q),transition:S,zIndex:L?1e3:"auto"};return X.jsxs("div",{ref:F,style:_,className:`form-component section-child ${(null==e?void 0:e.id)===t.id?"selected":""} ${L?"dragging":""} ${I?"sorting":""} ${a?"children-edit-active":""}`,onClick:()=>!L&&r(t),role:"button",tabIndex:0,children:[("edit"===A||a)&&X.jsx("div",Object.assign({className:"child-drag-handle"},x,C,{onClick:t=>t.stopPropagation(),onMouseDown:t=>t.stopPropagation(),children:X.jsx(U,{size:14})})),X.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===A||a)&&X.jsxs("div",{className:"component-actions child-actions",children:[X.jsx("button",{className:"btn edit-btn",onClick:e=>{e.stopPropagation(),r(t)},onMouseDown:t=>t.stopPropagation(),title:"Edit properties",children:X.jsx(E,{size:12})}),X.jsx("button",{className:"btn delete-btn",onClick:e=>n(t,e),onMouseDown:t=>t.stopPropagation(),title:"Delete component",children:X.jsx(N,{size:12})})]}),X.jsxs("div",{className:"component-preview child-preview",children:[i(t),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:"test",formTemplateId:l,formValue:b,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h?e=>h(t.id,e):void 0,onAttachmentChange:d?e=>d(t.id,e):void 0,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w}),y&&X.jsx(Bt,{component:t})]})]})]})},yt=({id:t,properties:n,mode:i="edit",formData:s={},onValueChange:a,onSelect:o,isSelected:l=!1,className:c="",onSectionSelect:u,onChildSelect:h,onChildDelete:d,selectedChild:f,renderFormComponent:p,formTemplateId:g,onThresholdActionCompletion:m,onThresholdIssueRaised:w,onNotesChange:v,onAttachmentChange:B,workOrderNumber:b,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:U})=>{var E,N,S,L,I,_;const[j,H]=e(n.basic.collapsed),[P,D]=e(!1),[M,R]=e(!1),[K,V]=e(n.basic.label),[z,G]=e(n.basic.description),[q,W]=e(n.children||[]),[Y,J]=e(!1);A(()=>{W(n.children||[])},[n.children]),A(()=>{V(n.basic.label),G(n.basic.description)},[n.basic.label,n.basic.description]);const{setNodeRef:$,isOver:Z}=O({id:`section-${t}`,disabled:"edit"!==i}),tt=!("preview"!==i&&"test"!==i||n.children&&n.children.length>0),et=r(e=>{V(e),null==a||a({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic),{label:e})})})},[t,n,a]),At=r(e=>{G(e),null==a||a({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic),{description:e})})})},[t,n,a]),rt=r(t=>{null==h||h(t)},[h]),nt=r((t,e)=>{e.stopPropagation();const A=q.filter(e=>e.id!==t.id);W(A),null==d||d(t.id)},[d,q,t]),ct=r(()=>{null==u||u(n),null==o||o()},[u,o,n]),dt=r(t=>{t.stopPropagation(),"edit"===i&&q.length>0&&J(!Y)},[i,q.length,Y]),ft=r(e=>{e.stopPropagation(),H(!j),null==a||a({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic),{collapsed:!j})})})},[j,t,n,a]),gt=p||r(t=>{var e,A,r;const n=s[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let o=n;"number-input"===t.name&&"number"==typeof n?o=String(n):"number-input"===t.name&&null==n&&(o="");const l={id:t.id,properties:t,validationErrors:{},formValue:o,touchedFields:{},formSubmitted:!1,mode:i,onValueChange:a,onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return X.jsx(it,Object.assign({},l,{properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return X.jsx(st,Object.assign({},l,{properties:t,readonly:!1,disabled:!1}));case"select":const n=Object.assign(Object.assign({},t),{options:(null===(e=t.basic)||void 0===e?void 0:e.options)||[]});return X.jsx(at,Object.assign({},l,{properties:n,disabled:!1}));case"checkbox":const i=Object.assign(Object.assign({},t),{options:(null===(A=t.basic)||void 0===A?void 0:A.options)||[]});return X.jsx(ot,Object.assign({},l,{properties:i,formValue:[],disabled:!1}));case"radio":const s=Object.assign(Object.assign({},t),{options:(null===(r=t.basic)||void 0===r?void 0:r.options)||[]});return X.jsx(lt,Object.assign({},l,{properties:s,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},l,{properties:t,readonly:!1,disabled:!1}));case"signature":return X.jsx(ht,Object.assign({},l,{properties:t}));case"heading":return X.jsx(pt,Object.assign({},l,{properties:t}));default:return X.jsx("div",{className:"form-group",children:X.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",t.name]})})}},[i,a,s]);if(tt)return null;const mt={backgroundColor:(null===(E=n.styles)||void 0===E?void 0:E.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(N=n.styles)||void 0===N?void 0:N.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(S=n.styles)||void 0===S?void 0:S.borderWidth)||"2px",borderRadius:(null===(L=n.styles)||void 0===L?void 0:L.borderRadius)||"8px",padding:(null===(I=n.styles)||void 0===I?void 0:I.padding)||"16px",margin:(null===(_=n.styles)||void 0===_?void 0:_.margin)||"16px 0"};return X.jsxs("div",{ref:$,className:`df-form-section ${l?"selected":""} ${Z?"drag-over":""} ${c}`,style:mt,children:[X.jsxs("div",{className:"section-header "+(Y?"children-edit-mode":""),onClick:ct,onDoubleClick:dt,children:[X.jsx("div",{className:"section-header-content",children:X.jsxs("div",{className:"section-title",children:[X.jsx("span",{className:"section-toggle",title:j?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:t=>{t.stopPropagation(),ft(t)},onKeyDown:t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),ft(t))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:j?X.jsx(Q,{size:18}):X.jsx(F,{size:18})}),"edit"===i&&P?X.jsx("input",{type:"text",value:K,onChange:t=>V(t.target.value),onBlur:()=>{D(!1),et(K)},onKeyDown:t=>{"Enter"===t.key&&(D(!1),et(K))},className:"section-title-input",autoFocus:!0}):X.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===i&&D(!0),style:{display:"inline",margin:0},children:K||"Untitled Section"})]})}),(z||"edit"===i)&&X.jsx("div",{className:"section-description",children:"edit"===i&&M?X.jsx("textarea",{value:z,onChange:t=>G(t.target.value),onBlur:()=>{R(!1),At(z)},onKeyDown:t=>{"Enter"===t.key&&t.ctrlKey&&(R(!1),At(z))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):X.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===i&&R(!0),children:z||"Section description"})})]}),!j&&X.jsx("div",{className:`section-content ${Z?"drag-over":""} ${0===q.length?"empty":"has-children"}`,onClick:t=>{t.target===t.currentTarget&&ct()},children:X.jsx(k,{items:q.map(t=>t.id),strategy:T,children:0===q.length?X.jsxs("div",{className:"section-empty-state",onClick:ct,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:[X.jsx("div",{style:{fontWeight:"500",color:Z?"#3b82f6":"#374151"},children:Z?"Drop components here":"Empty Section"}),X.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):q.map(t=>X.jsx(bt,{child:t,selectedChild:f||null,mode:i,onChildSelect:rt,onChildDelete:nt,renderFormComponent:gt,isChildrenEditMode:Y,formData:s,formTemplateId:g,onNotesChange:v,onAttachmentChange:B,onThresholdActionCompletion:m,onThresholdIssueRaised:w,workOrderNumber:b,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:U},t.id))})})]})},Ct=({component:t,selectedComponent:e,mode:A,onComponentSelect:r,onComponentDelete:n,onComponentEdit:i,renderFormComponent:s,isOverlay:a=!1,formData:o={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,onCreateIssue:g,onUpdateIssue:m})=>{var w,v;const B=o[t.id],b="preview"===A&&((null===(w=t.basic)||void 0===w?void 0:w.notes)&&t.basic.notes.trim().length>0||(null===(v=t.basic)||void 0===v?void 0:v.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0),{attributes:y,listeners:C,setNodeRef:x,transform:F,transition:Q,isDragging:S,isSorting:L}=j({id:t.id,disabled:a}),I={transform:P.Transform.toString(F),transition:Q,opacity:S?.3:1,zIndex:S?1e3:"auto"};return X.jsxs("div",{ref:x,style:Object.assign(Object.assign({},I),{border:(null==e?void 0:e.id)===t.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:(null==e?void 0:e.id)===t.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 ${(null==e?void 0:e.id)===t.id?"selected":""} ${S?"dragging":""} ${L?"sorting":""}`,onClick:()=>!S&&r(t),role:"button",tabIndex:0,children:["edit"===A&&X.jsx("div",Object.assign({className:"component-drag-handle"},C,y,{onClick:t=>t.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:X.jsx(U,{size:12,color:"var(--df-color-text-light)"})})),X.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===A?"24px":"0",paddingLeft:"edit"===A?"28px":"0",minHeight:"60px"},children:[s(t),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:"test",formTemplateId:l,formValue:B,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h?e=>h(t.id,e):void 0,onAttachmentChange:d?e=>d(t.id,e):void 0,workOrderNumber:f,assetNumber:p,onCreateIssue:g,onUpdateIssue:m}),b&&X.jsx(Bt,{component:t})]}),"edit"===A&&X.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[i&&X.jsx("button",{className:"component-edit-btn",onClick:e=>{e.stopPropagation(),i(t)},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:t=>{t.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="#3b82f6"},children:X.jsx(E,{size:12})}),X.jsx("button",{className:"component-delete-btn",onClick:e=>{e.stopPropagation(),n(t,e)},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:t=>{t.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="#ef4444"},children:X.jsx(N,{size:12})})]})]})},xt=({gridComponents:t,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,onComponentUpdate:i,selectedComponent:s,renderFormComponent:a,gridId:o,formData:l={},formTemplateId:c,onThresholdActionCompletion:u,onThresholdIssueRaised:h,onNotesChange:d,onAttachmentChange:f,workOrderNumber:p,assetNumber:g,onCreateIssue:m,onUpdateIssue:w})=>{const{setNodeRef:v,isOver:B}=O({id:`grid-drop-zone-${o}`,disabled:"edit"!==e});return X.jsx("div",{ref:v,className:"grid-drop-zone",style:{border:B?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:B?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:t.length>0?X.jsxs(X.Fragment,{children:[X.jsx(k,{items:t.map(t=>t.id),strategy:H,children:X.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:t.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:t.map(t=>X.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:X.jsx(Ct,{component:t,selectedComponent:s,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,onComponentUpdate:i,renderFormComponent:a,formData:l,formTemplateId:c,onThresholdActionCompletion:u,onThresholdIssueRaised:h,onNotesChange:d,onAttachmentChange:f,workOrderNumber:p,assetNumber:g,onCreateIssue:m,onUpdateIssue:w})},t.id))})}),X.jsx("div",{style:{border:B?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:B?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:B?X.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):X.jsx("span",{children:"+ Drop more components here"})})]}):X.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:[X.jsx("div",{style:{fontWeight:"500",color:B?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:B?"Drop components here":"Empty DataGrid"}),X.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},Ft=({templateComponents:t,dataEntries:e,renderFormComponent:A,renderComponent:r,mode:n="preview",allowAddRemoveEntries:i=!0,addAnotherText:s="Add Another",removeText:a="Remove",maxEntries:o=10,minEntries:l=1,displayAsGrid:c=!0,onAddEntry:u,onRemoveEntry:h,formData:d={},formTemplateId:f,onThresholdActionCompletion:p,onThresholdIssueRaised:g,onNotesChange:m,onAttachmentChange:w,datagridId:v="",workOrderNumber:B,assetNumber:b,onCreateIssue:y,onUpdateIssue:C})=>0===t.length?X.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 ",c?"table":"list"," view."]}):c?X.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:[X.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:t.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),X.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:[X.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${t.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*t.length+"px"},children:t.map((e,A)=>{var r;return X.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:A<t.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(null===(r=e.basic)||void 0===r?void 0:r.label)||`Column ${A+1}`},`header-${e.id}`)})}),e.length>0?e.map((s,o)=>X.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${t.length}, minmax(150px, 1fr))`,borderBottom:o<e.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*t.length+"px",isolation:"isolate"},children:[t.map((e,i)=>{var a,l,c,u,h,x,F;let Q=null===(a=s.components)||void 0===a?void 0:a[i];const U=`${e.id||`component-${i}`}-entry-${v}-${o}-${i}`;return Q=Q?Q.id!==U?Object.assign(Object.assign({},Q),{id:U,basic:Object.assign(Object.assign({},Q.basic),{showLabel:!1})}):Object.assign(Object.assign({},Q),{id:Q.id,basic:Object.assign(Object.assign({},Q.basic),{showLabel:!1})}):Object.assign(Object.assign({},e),{id:U,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),X.jsxs("div",{style:{padding:"12px 16px",borderRight:i<t.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:[X.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:r?r(Q,!0):A(Q,!0)}),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(Q.name)&&X.jsxs("div",{style:{marginTop:"8px",width:"100%"},children:[X.jsx(wt,{component:Q,mode:"test",formTemplateId:f,formValue:d[Q.id],onThresholdActionCompletion:p,onThresholdIssueRaised:g,onNotesChange:m?t=>m(Q.id,t):void 0,onAttachmentChange:w?t=>w(Q.id,t):void 0,notes:(null===(l=Q.basic)||void 0===l?void 0:l.notes)||(null===(c=d[Q.id])||void 0===c?void 0:c.notes),attachments:(null===(u=Q.basic)||void 0===u?void 0:u.attachments)||(null===(h=d[Q.id])||void 0===h?void 0:h.attachments),workOrderNumber:B,assetNumber:b,onCreateIssue:y,onUpdateIssue:C}),"preview"===n&&((null===(x=Q.basic)||void 0===x?void 0:x.notes)||(null===(F=Q.basic)||void 0===F?void 0:F.attachments))&&X.jsx(Bt,{component:Q})]})]},`${s.id}-${i}`)}),i&&e.length>l&&X.jsx("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length<=l)&&h)try{h(o)}catch(t){console.error("Error removing entry:",t)}},disabled:e.length<=l,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:e.length<=l?"#f3f4f6":"#ef4444",color:e.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:e.length<=l?"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:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#ef4444")},children:X.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},s.id)):X.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. ",i?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]})]}),i&&X.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:X.jsxs("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length>=o)&&u)try{u()}catch(t){console.error("Error adding entry:",t)}},disabled:e.length>=o,style:{padding:"8px 16px",backgroundColor:e.length>=o?"#f3f4f6":"#10b981",color:e.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:e.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#059669")},onMouseLeave:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#10b981")},children:[X.jsx("span",{style:{fontSize:"16px"},children:"+"}),s]})})]}):X.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[e.length>0?e.map((s,o)=>X.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:[X.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[X.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",o+1]}),i&&e.length>1&&X.jsx("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length<=l)&&h)try{h(o)}catch(t){console.error("Error removing entry:",t)}},disabled:e.length<=l,style:{padding:"4px 8px",backgroundColor:e.length<=l?"#f3f4f6":"#ef4444",color:e.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:e.length<=l?"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:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#ef4444")},children:X.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),X.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:t.map((t,e)=>{var i,a,l;let c=null===(i=s.components)||void 0===i?void 0:i[e];const u=`${t.id||`component-${e}`}-entry-${v}-${o}-${e}`;return c||(c=null===(a=s.components)||void 0===a?void 0:a.find(e=>{var A,r;return e.name===t.name&&(null===(A=e.basic)||void 0===A?void 0:A.label)===(null===(r=t.basic)||void 0===r?void 0:r.label)})),c=c?c.id!==u?Object.assign(Object.assign({},c),{id:u,basic:Object.assign(Object.assign({},c.basic),{showLabel:!1})}):Object.assign(Object.assign({},c),{id:c.id,basic:Object.assign(Object.assign({},c.basic),{showLabel:!1})}):Object.assign(Object.assign({},t),{id:u,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),X.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[X.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:(null===(l=t.basic)||void 0===l?void 0:l.label)||`Field ${e+1}`}),X.jsxs("div",{style:{minHeight:"40px",display:"flex",alignItems:"center",flexDirection:"column",width:"100%"},children:[r?r(c):A(c),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(c.name)&&X.jsx(wt,{component:c,mode:"test",formTemplateId:f,formValue:d[c.id],onThresholdActionCompletion:p,onThresholdIssueRaised:g,onNotesChange:m?t=>m(c.id,t):void 0,onAttachmentChange:w?t=>w(c.id,t):void 0}),"preview"===n&&(()=>{var t,e;return(null===(t=c.basic)||void 0===t?void 0:t.notes)&&c.basic.notes.trim().length>0||(null===(e=c.basic)||void 0===e?void 0:e.attachments)&&Array.isArray(c.basic.attachments)&&c.basic.attachments.length>0?X.jsx(Bt,{component:c}):null})()]})]},`${s.id}-${e}`)})})]},s.id)):X.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. ",i?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]}),"test"===n&&i&&X.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:X.jsxs("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length>=o)&&u)try{u()}catch(t){console.error("Error adding entry:",t)}},disabled:e.length>=o,style:{padding:"8px 16px",backgroundColor:e.length>=o?"#f3f4f6":"#10b981",color:e.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:e.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#059669")},onMouseLeave:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#10b981")},children:[X.jsx("span",{children:"+"}),s]})})]}),Qt=({id:t,properties:i,mode:s="edit",formData:a={},validationErrors:o={},touchedFields:l={},formSubmitted:c=!1,onValueChange:u,onSelect:h,isSelected:d=!1,className:f="",onDataGridSelect:p,onComponentSelect:g,onComponentDelete:m,onComponentEdit:w,onComponentUpdate:v,selectedComponent:B,renderFormComponent:b,onEntryAdd:y,onEntryRemove:C,formTemplateId:x,onThresholdActionCompletion:U,onThresholdIssueRaised:E,onNotesChange:N,onAttachmentChange:L,workOrderNumber:I,assetNumber:_,onCreateIssue:O,onUpdateIssue:k})=>{var T,j,H,P,D,M,R,K,V,z,G,q;const[W,Y]=e(!1),J=n(!1);let $=i.templateComponents||[];const Z=i.entries||[];0===$.length&&Z.length>0&&Z[0].components&&($=Z[0].components.map(t=>{var e;return Object.assign(Object.assign({},t),{id:(null===(e=t.id)||void 0===e?void 0:e.replace(/-entry-\d+$/,""))||t.id,basic:Object.assign(Object.assign({},t.basic),{showLabel:!0})})})),A(()=>{if("edit"===s&&!i.templateComponents&&u&&J.current){const e=Object.assign(Object.assign({},i),{templateComponents:[]});JSON.stringify(e)!==JSON.stringify(i)&&u({id:t,value:e})}J.current=!0},[i.templateComponents,t,u,i,s]),A(()=>{if($.length>0){if("test"===s&&0===Z.length&&J.current){const e={id:`entry-${t}-0`,index:0,components:$.map((e,A)=>{const r=e.id||`component-${A}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${t}-0-${A}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(u){const A=Object.assign(Object.assign({},i),{entries:[e]});JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A})}return}if("edit"!==s||!J.current)return;const e=Z.some(t=>{var e;return null===(e=t.components)||void 0===e?void 0:e.some((e,A)=>{var r;const n=`${null===(r=$[A])||void 0===r?void 0:r.id}-entry-${t.index}-${A}`;return e.id!==n})});if(e&&u){const e=Z.map(t=>{var e;return Object.assign(Object.assign({},t),{components:(null===(e=t.components)||void 0===e?void 0:e.map((e,A)=>{var r;return Object.assign(Object.assign({},e),{id:`${null===(r=$[A])||void 0===r?void 0:r.id}-entry-${t.index}-${A}`})}))||[]})}),A=Object.assign(Object.assign({},i),{entries:e});return void(JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A}))}if(0===Z.length&&"edit"===s){const e={id:`entry-${t}-0`,index:0,components:$.map((e,A)=>{const r=e.id||`component-${A}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${t}-0-${A}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(u){const A=Object.assign(Object.assign({},i),{entries:[e]});JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A})}}else if(Z.length>0){const e=Z.some(t=>$.some((e,A)=>{var r,n,i,s,a,o,l,c,u,h,d;const f=null===(r=t.components)||void 0===r?void 0:r[A];if(!f)return!0;const p=`${e.id}-entry-${t.index}-${A}`,g=f.id===p,m=JSON.stringify(null===(n=f.basic)||void 0===n?void 0:n.options)!==JSON.stringify(null===(i=e.basic)||void 0===i?void 0:i.options)||(null===(s=f.basic)||void 0===s?void 0:s.placeholder)!==(null===(a=e.basic)||void 0===a?void 0:a.placeholder)||(null===(o=f.basic)||void 0===o?void 0:o.defaultValue)!==(null===(l=e.basic)||void 0===l?void 0:l.defaultValue)||(null===(c=f.basic)||void 0===c?void 0:c.label)!==(null===(u=e.basic)||void 0===u?void 0:u.label)||(null===(h=f.validation)||void 0===h?void 0:h.required)!==(null===(d=e.validation)||void 0===d?void 0:d.required);return!g||m}));if(e&&u){const e=Z.map(e=>{const A=$.map((A,r)=>{var n,i;let s=null===(n=e.components)||void 0===n?void 0:n[r];s||(s=null===(i=e.components)||void 0===i?void 0:i.find(t=>{var e,r;return t.name===A.name&&(null===(e=t.basic)||void 0===e?void 0:e.label)===(null===(r=A.basic)||void 0===r?void 0:r.label)}));const a=`${A.id||`component-${r}`}-entry-${t}-${e.index}-${r}`;if(s){return Object.assign(Object.assign({},A),{id:a,basic:Object.assign(Object.assign({},A.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}return Object.assign(Object.assign({},A),{id:a,basic:Object.assign(Object.assign({},A.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})});return Object.assign(Object.assign({},e),{components:A})}),A=Object.assign(Object.assign({},i),{entries:e});JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A})}}}},[$,Z,t,u,i,s,i.templateComponents]);const tt=r(t=>{t.stopPropagation(),null==h||h(),null==p||p(i)},[h,p,i]),et=r((e,A)=>{A.stopPropagation(),m&&m(e,A);const r=$.filter(t=>t.id!==e.id),n=Z.map(t=>{var A;return Object.assign(Object.assign({},t),{components:(null===(A=t.components)||void 0===A?void 0:A.filter(t=>{var A,r;return!(t.name===e.name&&(null===(A=t.basic)||void 0===A?void 0:A.label)===(null===(r=e.basic)||void 0===r?void 0:r.label))}))||[]})});u&&u({id:t,value:Object.assign(Object.assign({},i),{templateComponents:r,entries:n})})},[m,i,u,t,$,Z]),At=r((e,A)=>{v&&v(e,A);const r=$.map(t=>t.id===e?Object.assign(Object.assign({},t),A):t);u&&u({id:t,value:Object.assign(Object.assign({},i),{templateComponents:r})})},[v,i,u,t,$]),rt=r(t=>{"test"===s&&u&&u({id:t.id,value:t.value})},[u]),nt=r(()=>{const e=i.entries||[],A=e.length,r={id:`entry-${t}-${A}`,index:A,components:$.map((e,r)=>{const n=`${e.id||`component-${r}`}-entry-${t}-${A}-${r}`;return Object.assign(Object.assign({},e),{id:n,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}},n=[...e,r];u&&u({id:t,value:Object.assign(Object.assign({},i),{entries:n})}),null==y||y()},[i,u,t,y,$]),ct=r(e=>{const A=i.entries.filter((t,A)=>A!==e).map((e,A)=>Object.assign(Object.assign({},e),{index:A,id:`entry-${t}-${A}`}));u&&u({id:t,value:Object.assign(Object.assign({},i),{entries:A})})},[i,u,t,C]),dt=r((t,e=!1)=>{var A,r,n;const i=a[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let u=i;"number-input"===t.name&&"number"==typeof i?u=String(i):"number-input"===t.name&&null==i&&(u="");const h={id:t.id,properties:t,validationErrors:o||{},formValue:u,touchedFields:l||{},formSubmitted:c||!1,mode:s,hideLabel:e,onValueChange:rt,onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return X.jsx(it,Object.assign({},h,{properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1,hideLabel:e}));case"textarea":return X.jsx(st,Object.assign({},h,{properties:t,readonly:!1,disabled:!1,hideLabel:e}));case"select":const i=Object.assign(Object.assign({},t),{options:(null===(A=t.basic)||void 0===A?void 0:A.options)||[]});return X.jsx(at,Object.assign({},h,{properties:i,disabled:!1,hideLabel:e}));case"checkbox":const s=Object.assign(Object.assign({},t),{options:(null===(r=t.basic)||void 0===r?void 0:r.options)||[]});return X.jsx(ot,Object.assign({},h,{properties:s,formValue:[],disabled:!1,hideLabel:e}));case"radio":const a=Object.assign(Object.assign({},t),{options:(null===(n=t.basic)||void 0===n?void 0:n.options)||[]});return X.jsx(lt,Object.assign({},h,{properties:a,readonly:!1,disabled:!1,hideLabel:e}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},h,{properties:t,readonly:!1,disabled:!1,hideLabel:e}));case"signature":return X.jsx(ht,Object.assign({},h,{properties:t,hideLabel:e}));case"heading":return X.jsx(pt,Object.assign({},h,{properties:t,hideLabel:e}));case"instructions":return X.jsx(gt,Object.assign({},h,{properties:t,hideLabel:e}));default:return X.jsxs("div",{className:"unknown-component",children:["Unknown component: ",t.name]})}},[s,rt,a,o,l,c]),ft={backgroundColor:i.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:i.styles.borderColor||"var(--df-color-fb-border)",borderWidth:i.styles.borderWidth||"2px",borderRadius:i.styles.borderRadius||"8px",padding:i.styles.padding||"16px",margin:i.styles.margin||"16px 0"};return X.jsxs("div",{className:`form-group df-form-datagrid ${d?"selected":""} ${f}`,onClick:tt,style:ft,children:[X.jsx("div",{className:"grid-header",children:X.jsx("div",{className:"grid-title",onClick:e=>{e.stopPropagation(),Y(!W),null==u||u({id:t,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{collapsed:!W})})})},children:X.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[W?X.jsx(Q,{size:16}):X.jsx(F,{size:16}),X.jsx(S,{size:16}),X.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:i.basic.label}),i.validation.required&&X.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),i.basic.description&&!W&&X.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:i.basic.description}),!W&&X.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===s?X.jsx(xt,{gridComponents:$,mode:s,onComponentSelect:g||(()=>{}),onComponentDelete:et,onComponentEdit:w,onComponentUpdate:At,selectedComponent:B||null,renderFormComponent:b||dt,gridId:t,formData:a,formTemplateId:x,onThresholdActionCompletion:U,onThresholdIssueRaised:E,onNotesChange:N,onAttachmentChange:L,workOrderNumber:I,assetNumber:_,onCreateIssue:O,onUpdateIssue:k}):X.jsx(Ft,{templateComponents:$,dataEntries:Z,renderFormComponent:b||dt,mode:s,allowAddRemoveEntries:null===(j=null===(T=i.datagrid)||void 0===T?void 0:T.allowAddRemoveEntries)||void 0===j||j,addAnotherText:null!==(P=null===(H=i.datagrid)||void 0===H?void 0:H.addAnotherText)&&void 0!==P?P:"Add Entry",removeText:null!==(M=null===(D=i.datagrid)||void 0===D?void 0:D.removeText)&&void 0!==M?M:"Remove",maxEntries:null!==(K=null===(R=i.datagrid)||void 0===R?void 0:R.maxEntries)&&void 0!==K?K:10,minEntries:null!==(z=null===(V=i.datagrid)||void 0===V?void 0:V.minEntries)&&void 0!==z?z:1,displayAsGrid:null===(q=null===(G=i.datagrid)||void 0===G?void 0:G.displayAsGrid)||void 0===q||q,onAddEntry:y||nt,onRemoveEntry:C||ct,formData:a,formTemplateId:x,onThresholdActionCompletion:U,onThresholdIssueRaised:E,onNotesChange:N,onAttachmentChange:L,datagridId:t,workOrderNumber:I,assetNumber:_,onCreateIssue:O,onUpdateIssue:k})})]})},Ut=t.lazy(()=>Promise.resolve().then(function(){return kt})),Et=({formComponents:i=[],currentDevice:s="desktop",isPreviewMode:a=!1,initialFormData:o=[],onSubmit:l,onFormDataChange:c,formTitle:u,formDescription:h,formTemplateId:d,onComponentSelect:f,onComponentDelete:p,onComponentEdit:g,onComponentUpdate:m,selectedComponent:w,workOrderNumber:v,assetNumber:B,isStandalone:b,user:y,onCreateIssue:C,onUpdateIssue:x})=>{const[F,Q]=e({}),[U,E]=e({}),[N,S]=e(!1),[L,I]=e({}),[_,O]=e({}),[k,T]=e(new Set),[j,H]=e(new Map),[P,D]=e({isValid:!0}),[M,R]=e({}),[K,V]=e({});A(()=>{G()},[i,o]);const z=(t,e)=>{t.forEach(t=>{if(t.id&&(void 0!==e[t.id]||(t.basic&&"value"in t.basic&&void 0!==t.basic.value&&""!==t.basic.value&&null!==t.basic.value?e[t.id]=t.basic.value:t.basic&&"defaultValue"in t.basic&&void 0!==t.basic.defaultValue&&""!==t.basic.defaultValue&&null!==t.basic.defaultValue?e[t.id]=t.basic.defaultValue:"checkbox"===t.name||"select"===t.name?e[t.id]=[]:e[t.id]="")),t.cells&&Array.isArray(t.cells)&&t.cells.forEach((t,A)=>{Array.isArray(t)&&t.forEach((t,A)=>{t&&t.components&&Array.isArray(t.components)&&z(t.components,e)})}),t.entries&&Array.isArray(t.entries)&&t.entries.forEach((t,A)=>{t&&t.components&&Array.isArray(t.components)&&z(t.components,e)}),"file"===t.name&&t.basic){const A=t.basic.files||t.basic.attachments||t.basic.value;A&&(e[t.id]=A)}if(t.id&&t.basic&&t.basic.notes,"instructions"===t.name&&t.basic){t.basic.instructions||(t.basic.instructions=[]);const A=t.basic.value||t.basic.instructions;A&&(e[t.id]=A)}t.children&&Array.isArray(t.children)&&z(t.children,e)})},G=r(()=>{const t={},e={},A={},r=new Set,n=t=>{t.forEach(t=>{var r,i,s,a,o;t.id&&(((null===(r=t.basic)||void 0===r?void 0:r.notes)||(null===(i=t.basic)||void 0===i?void 0:i.comments))&&(e[t.id]=(null===(s=t.basic)||void 0===s?void 0:s.notes)||(null===(a=t.basic)||void 0===a?void 0:a.comments)),(null===(o=t.basic)||void 0===o?void 0:o.attachments)&&(A[t.id]=t.basic.attachments)),t.children&&n(t.children),t.cells&&t.cells.forEach(t=>t.forEach(t=>{t.components&&n(t.components)})),t.entries&&t.entries.forEach(t=>{t.components&&n(t.components)})})},s=t=>{t.forEach((t,e)=>{var A;if(t.id&&"string"==typeof t.id&&""!==t.id.trim())r.has(t.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${t.id}. Component:`,t),t.id=`${t.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${t.id}`));else{const r=t.name||"component",n=((null===(A=t.basic)||void 0===A?void 0:A.label)||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);t.id=`${r}-${n||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${e}`}r.add(t.id),t.children&&Array.isArray(t.children)&&s(t.children),t.cells&&Array.isArray(t.cells)&&t.cells.forEach(t=>{Array.isArray(t)&&t.forEach(t=>{t&&t.components&&Array.isArray(t.components)&&s(t.components)})}),t.entries&&Array.isArray(t.entries)&&t.entries.forEach(t=>{t&&t.components&&Array.isArray(t.components)&&s(t.components)})})};i&&i.length>0&&s(i),o&&o.length>0&&s(o),o&&o.length>0&&z(o,t),o&&o.length>0&&z(o,t),i&&i.length>0&&(z(i,t),n(i)),Q(e=>Object.assign(Object.assign({},t),e)),R(t=>Object.assign(Object.assign({},e),t)),V(t=>Object.assign(Object.assign({},A),t)),W()},[o,i]),q=(t,e)=>{t.forEach(t=>{if(t.id)if("table"===t.name||"datagrid"===t.name)e[t.id]=!0;else if(t.conditional){const A=J.evaluateConditionalLogic(t.conditional,i,F);e[t.id]=A.shouldShow}else e[t.id]=!0;t.cells&&Array.isArray(t.cells)&&t.cells.forEach(t=>{t.forEach(t=>{t.components&&Array.isArray(t.components)&&q(t.components,e)})}),t.entries&&Array.isArray(t.entries)&&t.entries.forEach(t=>{t.components&&Array.isArray(t.components)&&q(t.components,e)}),t.children&&Array.isArray(t.children)&&q(t.children,e)})},W=r(()=>{const t={};i&&i.length>0&&q(i,t),O(t)},[i,F]),Y=r(t=>{const e=i.find(e=>e.id===t);if(e&&("table"===e.name||"datagrid"===e.name))return!0;return!1!==_[t]},[_,i]),Z=r(t=>{if(!t.id||"string"!=typeof t.id||""===t.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",t);const e=i.filter(e=>e.id===t.id);if(e.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${t.id}":`,e.map(t=>{var e;return{id:t.id,name:t.name,label:null===(e=t.basic)||void 0===e?void 0:e.label}}));const A=F[t.id];void 0!==A&&A!==t.value&&console.log("[DfFormPreview] Updating form value:",{id:t.id,oldValue:A,newValue:t.value});const r=Object.assign(Object.assign({},F),{[t.id]:t.value});Q(r);const n=i.find(e=>e.id===t.id);if(n){const t=null==n?void 0:n.threshold;t&&t.conditions&&t.conditions.length>0&&T(e=>{const A=new Set(e);return t.conditions.forEach(t=>{A.delete(t.id)}),A})}const s=e=>e.map(e=>{var A;return e.id===t.id&&"defaultValue"in e.basic?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{value:null!==(A=t.value)&&void 0!==A?A:e.basic.defaultValue,defaultValue:t.value})}):"section"===e.name&&e.children?Object.assign(Object.assign({},e),{children:s(e.children)}):"table"===e.name&&e.cells?Object.assign(Object.assign({},e),{cells:e.cells.map(t=>t.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=s(e.components)),e}))}):"datagrid"===e.name&&e.entries?Object.assign(Object.assign({},e),{entries:e.entries.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=s(e.components)),e})}):e}),o=s(i);if(null==c||c(o),U[t.id]&&E(e=>Object.assign(Object.assign({},e),{[t.id]:""})),!a){if(t.isValid)return void E(e=>{const A=e[t.id];return A&&""!==A.trim()?Object.assign(Object.assign({},e),{[t.id]:""}):e});setTimeout(()=>{et(t.id)},150)}setTimeout(()=>{const t={};i.forEach(e=>{if("table"===e.name||"datagrid"===e.name)t[e.id]=!0;else if(e.conditional){const A=J.evaluateConditionalLogic(e.conditional,i,r);t[e.id]=A.shouldShow}else t[e.id]=!0}),O(t)},0)},[i,F,U,c]),tt=r((t,e)=>{for(const A of t){if(A.id===e)return A;if("section"===A.name&&A.children){const t=tt(A.children,e);if(t)return t}if("table"===A.name&&A.cells)for(const t of A.cells)for(const A of t)if(A.components){const t=tt(A.components,e);if(t)return t}if("datagrid"===A.name&&A.entries)for(const t of A.entries)if(t.components){const A=tt(t.components,e);if(A)return A}}return null},[]),et=r(t=>{if(a)return;const e=tt(i,t);if(!e)return;const A=F[t]||"";if("number-input"===e.name&&(!A||""===A)){if(e.validation.required){const A=e.validation.customValidationMessage,r=e.basic.label||"This field",n=A||`${r} is required`;E(e=>Object.assign(Object.assign({},e),{[t]:n}))}else E(e=>Object.assign(Object.assign({},e),{[t]:""}));return}let r=!1;r=Array.isArray(A)?A.length>0:"string"==typeof A?""!==A.trim():null!=A;let n="";if(e.validation.required&&!r){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} is required`}else if("email-input"===e.name&&r&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(A)){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} must be a valid email`}else if(e.validation.minLength&&r&&A.length<e.validation.minLength){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} must be at least ${e.validation.minLength} characters`}else if(e.validation.maxLength&&r&&A.length>e.validation.maxLength){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} must be no more than ${e.validation.maxLength} characters`}else if("number-input"===e.name&&r){const t=String(A).trim(),r=parseFloat(t);if(!isNaN(r)){const t=e.validation;t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&r<t.lowerLimit?n="Number is below the lower limit":t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&r>t.upperLimit&&(n="Number is above the upper limit")}}E(e=>Object.assign(Object.assign({},e),{[t]:n}))},[i,a,F,tt]),At=r(t=>{I(e=>Object.assign(Object.assign({},e),{[t]:!0})),a||setTimeout(()=>{et(t)},0)},[a,et]),rt=r(t=>{U[t]&&E(e=>Object.assign(Object.assign({},e),{[t]:""}))},[U]),nt=r(()=>!Object.values(U).some(t=>t&&"string"==typeof t&&""!==t.trim())&&i.every(t=>{const e=F[t.id]||"";let A=!1;if(A=Array.isArray(e)?e.length>0:"string"==typeof e?""!==e.trim():null!=e,t.validation.required&&!A)return!1;if("number-input"===t.name&&A){const A=String(e).trim(),r=parseFloat(A);if(!isNaN(r)){const e=t.validation;if(e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&r<e.lowerLimit)return!1;if(e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&r>e.upperLimit)return!1}}return!0}),[i,F,U]),mt=r((t,e)=>{if(Array.isArray(e))return e.some(e=>mt(t,e));if(null==e||""===e)return!1;const A="string"==typeof e?parseFloat(e):e,r="string"==typeof t.value?parseFloat(t.value):t.value;if(!isNaN(A)&&!isNaN(r))switch(t.operator){case"greaterThan":return A>r;case"lessThan":return A<r;case"greaterThanOrEqual":return A>=r;case"lessThanOrEqual":return A<=r;case"equals":return A===r;case"notEquals":return A!==r;default:return!1}const n=String(e).toLowerCase(),i=String(t.value).toLowerCase();switch(t.operator){case"equals":return n===i||String(e)===String(t.value);case"notEquals":return n!==i&&String(e)!==String(t.value);default:return!1}},[]),vt=r(()=>{if(a)return[];const t=[];return i.forEach(e=>{const A=null==e?void 0:e.condition;if(!A||!A.conditions||0===A.conditions.length)return;const r=F[e.id];null!=r&&""!==r&&!(Array.isArray(r)&&0===r.length)&&A.conditions.forEach(A=>{var n;mt(A,r)&&t.push({componentId:e.id,condition:A,componentLabel:(null===(n=e.basic)||void 0===n?void 0:n.label)||"Field"})})}),t},[i,F,a,mt]),bt=r(()=>{if(a)return{isValid:!0};const t=vt();if(0===t.length)return{isValid:!0};for(const{condition:e,componentLabel:A}of t){const t=j.get(e.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},r=[];if(!0!==e.enableRaiseIssue||k.has(e.id)||r.push("raise an issue"),!0!==e.enableNotes||t.notesCompleted||r.push("add notes"),!0!==e.enableAttachment||t.attachmentsCompleted||r.push("add attachments"),!0!==e.enableSendEmail||t.emailSent||r.push("send email"),r.length>0){return{isValid:!1,errorMessage:`Please ${1===r.length?r[0]:r.slice(0,-1).join(", ")+" and "+r[r.length-1]} for the threshold condition met in "${A}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[a,vt,k,j]),Ct=r(t=>{t&&T(e=>{const A=new Set(e);return A.add(t),A})},[]),xt=r((t,e,A)=>{t&&H(r=>{const n=new Map(r),i=n.get(t)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===e?n.set(t,Object.assign(Object.assign({},i),{notesCompleted:A})):"attachments"===e?n.set(t,Object.assign(Object.assign({},i),{attachmentsCompleted:A})):"email"===e&&n.set(t,Object.assign(Object.assign({},i),{emailSent:A})),n})},[]);A(()=>{if(!a){const t=bt();D(t)}},[F,k,j,a,bt]);const Ft=r(()=>{if(a)return!0;let t=!0;S(!0);const e={};return i.forEach(A=>{const r=F[A.id]||"";let n=!1;if(n=Array.isArray(r)?r.length>0:"string"==typeof r?""!==r.trim():null!=r,A.validation.required&&!n){const r=A.validation.customValidationMessage,n=A.basic.label||"This field",i=r||`${n} is required`;e[A.id]=i,t=!1}else if("number-input"===A.name&&n){const n=String(r).trim(),i=parseFloat(n);if(isNaN(i))e[A.id]="";else{const r=A.validation;r&&"lowerLimit"in r&&void 0!==r.lowerLimit&&null!==r.lowerLimit&&0!==r.lowerLimit&&i<r.lowerLimit?(e[A.id]="Number is below the lower limit",t=!1):r&&"upperLimit"in r&&void 0!==r.upperLimit&&null!==r.upperLimit&&0!==r.upperLimit&&i>r.upperLimit?(e[A.id]="Number is above the upper limit",t=!1):e[A.id]=""}}else e[A.id]="";I(t=>Object.assign(Object.assign({},t),{[A.id]:!0}))}),E(e),t},[i,a,F]),Et=r((t="Submitted")=>{if(S(!0),!Ft()){const t=i.find(t=>{const e=F[t.id]||"";let A=!1;return A=Array.isArray(e)?e.length>0:"string"==typeof e?""!==e.trim():null!=e,t.validation.required&&!A});if(t){const e=document.getElementById(t.id);e&&e.focus()}return}const e=bt();if(!e.isValid){e.errorMessage&&$.showError(e.errorMessage);const t=vt().find(({condition:t})=>!k.has(t.id));if(t){const e=document.getElementById(t.componentId);e&&e.scrollIntoView({behavior:"smooth",block:"center"})}return}const A=t=>t.map(t=>{var e,r,n,i,s,a;let o=F[t.id];"text-input"===t.name&&(null===(e=t.basic)||void 0===e||e.label),void 0===o&&(o="value"in t.basic&&void 0!==t.basic.value?t.basic.value:"defaultValue"in t.basic&&void 0!==t.basic.defaultValue?t.basic.defaultValue:""),"text-input"===t.name&&(null===(r=t.basic)||void 0===r||r.label);const l=Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{value:o,defaultValue:o,notes:void 0!==M[t.id]?M[t.id]:null===(n=t.basic)||void 0===n?void 0:n.notes,comments:void 0!==M[t.id]?M[t.id]:(null===(i=t.basic)||void 0===i?void 0:i.comments)||(null===(s=t.basic)||void 0===s?void 0:s.notes),attachments:void 0!==K[t.id]?K[t.id]:null===(a=t.basic)||void 0===a?void 0:a.attachments})});return"section"===l.name&&l.children&&(l.children=A(l.children)),"table"===l.name&&l.cells&&(l.cells=l.cells.map(t=>t.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=A(e.components)),e}))),"datagrid"===l.name&&l.entries&&(l.entries=l.entries.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=A(e.components)),e})),l}),r=A(i),n=Object.assign(Object.assign({},F),{status:t});null==l||l(r,n)},[i,F,Ft,l,M,K]),Nt=r(()=>({[`device-${s}`]:!0,readonly:a}),[s,a]),St=r((t,e)=>{R(A=>Object.assign(Object.assign({},A),{[t]:e}))},[]),Lt=r((t,e)=>{V(A=>Object.assign(Object.assign({},A),{[t]:e||[]}))},[]),It=n(new Map),_t=n(0),Ot=e=>{var A,r,n,s,a,o,l,u,h,b,E,S,I;let _;if(e.id&&"string"==typeof e.id&&""!==e.id.trim())_=e.id;else{const t=(null===(A=e.basic)||void 0===A?void 0:A.label)||"",r=e.name||"unknown",n=`${r}-${t}`;let i=It.current.get(n);i||(_t.current+=1,i=`generated-${r}-${_t.current}-${Math.random().toString(36).substr(2,9)}`,It.current.set(n,i),console.warn("[DfFormPreview] Generated and cached ID for component:",i,"key:",n)),_=i,e=Object.assign(Object.assign({},e),{id:_})}const O=_,T=F[O];if(void 0!==T){const t=i.filter(t=>t.id!==O&&F[t.id]===T);t.length>0&&console.warn(`[DfFormPreview] Component ${O} shares form value with other components:`,t.map(t=>t.id))}const j={id:O,validationErrors:U,formValue:T,touchedFields:L,formSubmitted:N,mode:"test",readonly:!1,onValueChange:Z,onBlur:()=>At(O),onFocus:()=>rt(O)};switch(e.name){case"text-input":case"number-input":case"email-input":return X.jsx(it,Object.assign({},j,{properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",formTemplateId:d,onThresholdIssueRaised:Ct,raisedThresholdIssues:k,workOrderNumber:v,assetNumber:B,user:y}));case"textarea":return X.jsx(st,Object.assign({},j,{properties:e}));case"select":const A=Object.assign(Object.assign({},e),{options:(null===(r=e.basic)||void 0===r?void 0:r.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(n=e.basic)||void 0===n?void 0:n.comments)||""})});return X.jsx(at,Object.assign({},j,{properties:A}));case"checkbox":const _=Object.assign(Object.assign({},e),{options:(null===(s=e.basic)||void 0===s?void 0:s.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(a=e.basic)||void 0===a?void 0:a.comments)||""})});return X.jsx(ot,Object.assign({},j,{properties:_}));case"radio":const O=Object.assign(Object.assign({},e),{options:(null===(o=e.basic)||void 0===o?void 0:o.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(l=e.basic)||void 0===l?void 0:l.comments)||""})});return X.jsx(lt,Object.assign({},j,{properties:O}));case"segment":const H=Object.assign(Object.assign({},e),{options:(null===(u=e.basic)||void 0===u?void 0:u.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(h=e.basic)||void 0===h?void 0:h.comments)||""})});return X.jsx(ct,Object.assign({},j,{properties:H}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},j,{properties:e}));case"signature":return X.jsx(ht,Object.assign({},j,{properties:e}));case"heading":return X.jsx(pt,Object.assign({},j,{properties:e}));case"instructions":const P=T||(null===(b=e.basic)||void 0===b?void 0:b.value)||null;return X.jsx(gt,Object.assign({},j,{properties:e,formValue:P}));case"location":return X.jsx(ft,Object.assign({},j,{properties:e}));case"section":return X.jsx(yt,Object.assign({},j,{properties:e,formData:F,formTemplateId:d,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,onNotesChange:St,onAttachmentChange:Lt,workOrderNumber:v,assetNumber:B,user:y,onCreateIssue:C,onUpdateIssue:x,renderFormComponent:t=>Ot(t)}));case"table":return X.jsx(t.Suspense,{fallback:X.jsx("div",{children:"Loading table..."}),children:X.jsx(Ut,Object.assign({},j,{properties:e,formData:F,formTemplateId:d,mode:j.mode,validationErrors:U,touchedFields:L,formSubmitted:N,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,workOrderNumber:v,assetNumber:B,onCreateIssue:C,onUpdateIssue:x,onNotesChange:(t,A)=>{const r=i.map(r=>{if(r.id===e.id&&r.cells){const e=r.cells.map(e=>e.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{notes:A})}):e);return Object.assign(Object.assign({},e),{components:r})}return e}));return Object.assign(Object.assign({},r),{cells:e})}return r});null==c||c(r)},onAttachmentChange:(t,A)=>{const r=i.map(r=>{if(r.id===e.id&&r.cells){const e=r.cells.map(e=>e.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{attachments:A||[]})}):e);return Object.assign(Object.assign({},e),{components:r})}return e}));return Object.assign(Object.assign({},r),{cells:e})}return r});null==c||c(r)},renderFormComponent:t=>Ot(t)}))});case"datagrid":return X.jsx(Qt,Object.assign({},j,{properties:e,formData:F,formTemplateId:d,mode:j.mode,validationErrors:U,touchedFields:L,formSubmitted:N,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,workOrderNumber:v,assetNumber:B,onComponentSelect:f,onComponentDelete:p,onComponentEdit:g,onCreateIssue:C,onUpdateIssue:x,onComponentUpdate:m,selectedComponent:w,onNotesChange:(t,A)=>{St(t,A);const r=i.map(r=>{if(r.id===e.id&&r.entries){const e=r.entries.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{notes:A||""})}):e);return Object.assign(Object.assign({},e),{components:r})}return e});return Object.assign(Object.assign({},r),{entries:e})}return r});null==c||c(r)},onAttachmentChange:(t,A)=>{Lt(t,A);const r=i.map(r=>{if(r.id===e.id&&r.entries){const e=r.entries.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{attachments:A||[]})}):e);return Object.assign(Object.assign({},e),{components:r})}return e});return Object.assign(Object.assign({},r),{entries:e})}return r});null==c||c(r)},onValueChange:t=>{if(t.id===e.id&&t.value&&"object"==typeof t.value&&"entries"in t.value){const A=i.map(A=>A.id===e.id?Object.assign(Object.assign({},A),t.value):A);null==c||c(A),t.value.entries&&Array.isArray(t.value.entries)&&t.value.entries.forEach(t=>{t.components&&Array.isArray(t.components)&&t.components.forEach(t=>{var e;if(void 0!==F[t.id]);else{const A=null===(e=t.basic)||void 0===e?void 0:e.defaultValue;void 0!==A&&Q(e=>Object.assign(Object.assign({},e),{[t.id]:A}))}})})}else Z(t)},onEntryAdd:()=>{const t=i.find(t=>t.id===e.id);if(t&&t.entries){const t=i.map(t=>t.id===e.id?Object.assign(Object.assign({},t),{entries:t.entries||[]}):t);null==c||c(t)}else setTimeout(()=>{const t=F[e.id];if(t&&"object"==typeof t&&"entries"in t){const A=i.map(A=>A.id===e.id?Object.assign(Object.assign({},A),{entries:t.entries}):A);null==c||c(A)}},100)},onEntryRemove:t=>{const A=i.map(A=>{if(A.id===e.id&&A.entries){const e=(A.entries||[]).filter((e,A)=>A!==t).map((t,e)=>{var r;return Object.assign(Object.assign({},t),{index:e,id:`entry-${A.id}-${e}`,components:(null===(r=t.components)||void 0===r?void 0:r.map((t,A)=>{const r=(t.templateComponents||[])[A];return Object.assign(Object.assign({},t),{id:r?`${r.id}-entry-${e}-${A}`:t.id})}))||[]})});return Object.assign(Object.assign({},A),{entries:e})}return A});null==c||c(A)},renderFormComponent:t=>Ot(t)}));case"file":const D=T||(null===(E=e.basic)||void 0===E?void 0:E.value)||(null===(S=e.basic)||void 0===S?void 0:S.files)||(null===(I=e.basic)||void 0===I?void 0:I.attachments)||null;return X.jsx(dt,Object.assign({},j,{properties:e,formValue:D}));default:return X.jsx("div",{className:"form-group",children:X.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}};return X.jsx("div",{className:"form-preview-container",children:X.jsx("div",{className:"form-preview-wrapper",children:X.jsxs("div",{className:`form-preview ${Object.entries(Nt()).map(([t,e])=>e?t:"").join(" ")}`,children:[X.jsx("div",{className:"form-canvas-header"}),0===i.length?X.jsx("div",{className:"empty-state",children:X.jsx("div",{className:"empty-state-card",children:X.jsx("div",{className:"empty-state-preview-area",children:X.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):X.jsxs("form",{className:"form-preview-form",onSubmit:t=>{t.preventDefault(),Et()},children:[(u||h)&&X.jsxs("div",{className:"form-header",children:[u&&X.jsx("h1",{className:"form-title",children:u}),h&&X.jsx("p",{className:"form-description",children:h})]}),i.map(t=>{var e,A,r,n;const s=t.basic,o=F[t.id],l=["select","radio","checkbox","segment"].includes(t.name||""),u=t.options||(null==s?void 0:s.options)||[],h=(()=>{var e;const A=null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.column;return"section"===t.name||"table"===t.name||"datagrid"===t.name?"col-12":3===A?"col-3":6===A?"col-6":9===A?"col-9":"col-12"})();let f=!1;if(!a)if(l&&null!=o&&""!==o)if("checkbox"===t.name){f=(Array.isArray(o)?o:[o]).some(t=>{const e=u.find(e=>e.value===t);return e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)})}else{const t=u.find(t=>t.value===o);f=t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)}else f=(null==s?void 0:s.enableNotes)||(null==s?void 0:s.enableAttachment)||(null==s?void 0:s.enableRaiseIssue)||(null==s?void 0:s.enableSendEmail);const p=a&&((null===(e=t.basic)||void 0===e?void 0:e.notes)&&t.basic.notes.trim().length>0||(null===(A=t.basic)||void 0===A?void 0:A.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0);return X.jsxs("div",{className:`form-group ${h} ${f||p?"has-action-features":""}`,style:{display:Y(t.id)?"block":"none"},children:[Ot(t),!a&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:a?"preview":"test",formTemplateId:d,formValue:o,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,onNotesChange:e=>{R(A=>Object.assign(Object.assign({},A),{[t.id]:e}));const A=i.map(A=>A.id===t.id?Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{notes:e||""})}):A);null==c||c(A)},onAttachmentChange:e=>{V(A=>Object.assign(Object.assign({},A),{[t.id]:e||[]}));const A=i.map(A=>A.id===t.id?Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{attachments:e||[]})}):A);null==c||c(A)},notes:void 0!==M[t.id]?M[t.id]:(null===(r=t.basic)||void 0===r?void 0:r.notes)||"",attachments:void 0!==K[t.id]?K[t.id]:(null===(n=t.basic)||void 0===n?void 0:n.attachments)||null,workOrderNumber:v,assetNumber:B,isStandalone:b,user:y,onCreateIssue:C,onUpdateIssue:x}),a&&p&&X.jsx(Bt,{component:t})]},t.id)}),!a&&X.jsxs("div",{className:"form-actions",children:[X.jsx("button",{type:"button",onClick:()=>Et("Saved"),className:"form-save-button",disabled:N&&!nt(),children:"Save"}),X.jsx("button",{type:"button",disabled:!nt()||!P.isValid,className:"form-submit-button",title:P.isValid?"":P.errorMessage,onClick:()=>Et("Submitted"),children:"Submit"})]})]})]})})})},Nt=({comment:t="",onSave:n,placeholder:i="Enter your reason...",className:s="",disabled:a=!1})=>{const[o,l]=e(!0),[c,u]=e(t),[h,d]=e(!1);A(()=>{u(t),d(!1)},[t]);const f=r(e=>{const A=e.target.value;u(A),d(A!==t)},[t]),p=r(()=>{h&&n&&!a&&(n(c),d(!1))},[h,n,c,a]),g=r(()=>{},[]),m=r(()=>{a||l(!o)},[o,a]);return X.jsxs("div",{className:`df-form-comments ${s}`,children:[X.jsxs("div",{className:"df-form-comments__header",children:[X.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),X.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:m,"aria-expanded":o,"aria-label":"Toggle comments section",disabled:a,children:o?X.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):X.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),X.jsx("div",{className:"df-form-comments__content "+(o?"df-form-comments__content--expanded":""),children:X.jsx("div",{className:"df-form-comments__input-container",children:X.jsx("div",{className:"df-form-comments__input-line",children:X.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:c,onChange:f,onBlur:p,onFocus:g,placeholder:i,disabled:a})})})})]})},St=t=>t.id?t:Object.assign(Object.assign({},t),{id:D()}),Lt=({component:t,mode:e,renderFormComponent:A,formData:r={},formTemplateId:n,onThresholdActionCompletion:i,onThresholdIssueRaised:s,onNotesChange:a,onAttachmentChange:o,workOrderNumber:l,assetNumber:c,user:u,onCreateIssue:h,onUpdateIssue:d})=>{var f,p;const g=r[t.id],m="preview"===e&&((null===(f=t.basic)||void 0===f?void 0:f.notes)&&t.basic.notes.trim().length>0||(null===(p=t.basic)||void 0===p?void 0:p.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0);return X.jsxs("div",{className:"simple-table-component",children:[A(t),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:"test",formTemplateId:n,formValue:g,onThresholdActionCompletion:i,onThresholdIssueRaised:s,onNotesChange:a?e=>a(t.id,e):void 0,onAttachmentChange:o?e=>o(t.id,e):void 0,workOrderNumber:l,assetNumber:c,user:u,onCreateIssue:h,onUpdateIssue:d}),m&&X.jsx(Bt,{component:t})]})},It=({component:t,selectedComponent:e,mode:A,onComponentSelect:r,onComponentDelete:n,onComponentEdit:i,renderFormComponent:s,isOverlay:a=!1})=>{const{attributes:o,listeners:l,setNodeRef:c,transform:u,transition:h,isDragging:d,isSorting:f}=j({id:t.id,disabled:a}),p={transform:P.Transform.toString(u),transition:h,opacity:d?.3:1,zIndex:d?1e3:"auto"};return X.jsxs("div",{ref:c,style:p,className:`form-component table-component ${(null==e?void 0:e.id)===t.id?"selected":""} ${d?"dragging":""} ${f?"sorting":""}`,onClick:()=>!d&&r(t),role:"button",tabIndex:0,children:["edit"===A&&X.jsx("div",Object.assign({className:"component-drag-handle"},l,o,{onClick:t=>t.stopPropagation(),style:{opacity:1},children:X.jsx(U,{size:14})})),X.jsx("div",{className:"component-content",children:s(t)}),"edit"===A&&X.jsxs("div",{className:"component-actions",style:{opacity:1},children:[i&&X.jsx("button",{className:"component-edit-btn",onClick:e=>{e.stopPropagation(),i(t)},type:"button",title:"Edit Component",children:X.jsx(E,{size:12})}),X.jsx("button",{className:"component-delete-btn",onClick:e=>{e.stopPropagation(),n(t,e)},type:"button",title:"Delete Component",children:X.jsx(N,{size:12})})]})]})},_t=({cell:t,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,selectedComponent:i,renderFormComponent:s,formData:a={},formTemplateId:o,onThresholdActionCompletion:l,onThresholdIssueRaised:c,tableId:u,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w})=>{var v,B,b,y,C;const x=`table-cell-${u}-${t.row}-${t.column}`,{setNodeRef:F,isOver:Q}=O({id:x,disabled:"edit"!==e,data:{type:"table-cell",tableId:u,cell:t,row:t.row,column:t.column}}),U=Object.assign(Object.assign({},t.styles),{backgroundColor:Q?"var(--df-color-primary-light)":(null===(v=t.styles)||void 0===v?void 0:v.backgroundColor)||"transparent",minHeight:(null===(B=t.styles)||void 0===B?void 0:B.minHeight)||"preview"===e||"test"===e?"40px":"60px",padding:(null===(b=t.styles)||void 0===b||b.padding,"8px"),border:"preview"===e||"test"===e?"none":Q?"2px dashed var(--df-color-primary)":(null===(y=t.styles)||void 0===y?void 0:y.borderColor)?`1px solid ${t.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===e||"test"===e?"0":"4px",position:"relative",verticalAlign:(null===(C=t.styles)||void 0===C?void 0:C.verticalAlign)||"top"});return X.jsx("td",{ref:F,style:U,className:"table-cell "+(Q?"drag-over":""),children:X.jsx("div",{className:"cell-content",children:t.components&&Array.isArray(t.components)&&t.components.length>0?"edit"===e?X.jsx(k,{items:t.components.map(t=>t.id||D()),strategy:T,children:t.components.map(t=>{const a=St(t);return X.jsx(It,{component:a,selectedComponent:i,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,renderFormComponent:s},a.id)})}):t.components.map(t=>{const A=t.id?t:St(t);return X.jsx(Lt,{component:A,mode:e,renderFormComponent:s,formData:a,formTemplateId:o,onThresholdActionCompletion:l,onThresholdIssueRaised:c,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w},A.id)}):"edit"===e?X.jsx("div",{className:"empty-cell-placeholder",children:X.jsxs("div",{className:"cell-info",children:[X.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),X.jsxs("span",{className:"cell-coordinates",children:["Cell (",t.row+1,", ",t.column+1,")"]})]})}):X.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},Ot=({id:t,properties:n,mode:s="edit",formData:a={},validationErrors:o={},touchedFields:l={},formSubmitted:c=!1,onValueChange:u,onSelect:h,isSelected:d=!1,className:f="",onTableSelect:p,onComponentSelect:g,onComponentDelete:m,onComponentEdit:w,selectedComponent:v,renderFormComponent:B,formTemplateId:b,onThresholdActionCompletion:y,onThresholdIssueRaised:C,onNotesChange:x,onAttachmentChange:U,workOrderNumber:E,assetNumber:N,user:S,onCreateIssue:I,onUpdateIssue:_})=>{var O,k,T,j,H,P,D,M,R,K,V,z,G,q,W,Y,J,$;const[Z,tt]=e(!1),et=(null===(O=n.cells)||void 0===O?void 0:O.some(t=>t.some(t=>t.components&&t.components.length>0)))||!1;A(()=>{},[null===(k=n.table)||void 0===k?void 0:k.rows,null===(T=n.table)||void 0===T?void 0:T.columns,null===(j=n.basic)||void 0===j?void 0:j.rows,null===(H=n.basic)||void 0===H?void 0:H.columns,n.cells,t,u]);const At=r(t=>{t.stopPropagation(),null==h||h(),null==p||p(n)},[h,p,n]),rt=r((e,A)=>{A.stopPropagation();const r=n.cells.map(t=>t.map(t=>{if(t.components&&t.components.some(t=>t.id===e.id)){const A=t.components.filter(t=>t.id!==e.id);return Object.assign(Object.assign({},t),{components:A})}return t}));u&&u({id:t,value:Object.assign(Object.assign({},n),{cells:r})})},[m,n,u,t]),nt=i(()=>n.cells?n.cells.map((e,A)=>e.map((e,r)=>Object.assign(Object.assign({},e),{components:e.components&&Array.isArray(e.components)?e.components.map((e,n)=>{if(e.id&&"string"==typeof e.id&&""!==e.id.trim())return e;const i=`${e.name||"component"}-table-${t}-row-${A}-cell-${r}-comp-${n}`;return Object.assign(Object.assign({},e),{id:i})}):[]}))):[],[n.cells,t]),ct=B||r(t=>{var e,A,r;const n=t.id?t:St(t),i=a[n.id]||"defaultValue"in n.basic&&n.basic.defaultValue||"";let o=i;"number-input"===n.name&&"number"==typeof i?o=String(i):"number-input"===n.name&&null==i&&(o="");const l={id:n.id,properties:n,validationErrors:{},formValue:o,touchedFields:{},formSubmitted:!1,mode:s,onValueChange:t=>{null==u||u(t)},onBlur:()=>{},onFocus:()=>{}};switch(n.name){case"text-input":case"email-input":case"number-input":return X.jsx(it,Object.assign({},l,{properties:n,inputType:"text-input"===n.name?"text":"number-input"===n.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return X.jsx(st,Object.assign({},l,{properties:n,readonly:!1,disabled:!1}));case"select":const t=Object.assign(Object.assign({},n),{options:(null===(e=n.basic)||void 0===e?void 0:e.options)||[]});return X.jsx(at,Object.assign({},l,{properties:t,disabled:!1}));case"checkbox":const i=Object.assign(Object.assign({},n),{options:(null===(A=n.basic)||void 0===A?void 0:A.options)||[]});return X.jsx(ot,Object.assign({},l,{properties:i,formValue:[],disabled:!1}));case"radio":const s=Object.assign(Object.assign({},n),{options:(null===(r=n.basic)||void 0===r?void 0:r.options)||[]});return X.jsx(lt,Object.assign({},l,{properties:s,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},l,{properties:n,readonly:!1,disabled:!1}));case"signature":return X.jsx(ht,Object.assign({},l,{properties:n}));case"heading":return X.jsx(pt,Object.assign({},l,{properties:n}));default:return X.jsxs("div",{className:"unknown-component",children:["Unknown component: ",n.name]})}},[B,s,a,u]),dt={backgroundColor:(null===(P=n.styles)||void 0===P?void 0:P.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(D=n.styles)||void 0===D?void 0:D.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(M=n.styles)||void 0===M?void 0:M.borderWidth)||"2px",borderRadius:(null===(R=n.styles)||void 0===R?void 0:R.borderRadius)||"8px",padding:(null===(K=n.styles)||void 0===K?void 0:K.padding)||"16px",margin:(null===(V=n.styles)||void 0===V?void 0:V.margin)||"16px 0"},ft={width:"100%",minWidth:"600px",borderCollapse:"preview"===s||"test"===s?"separate":"collapse",tableLayout:"fixed",border:"preview"===s||"test"===s?"1px solid var(--df-color-fb-border)":"none"};return et||"preview"!==s?X.jsxs("div",{className:`form-group df-form-table ${d?"selected":""} ${"preview"===s?"preview-mode":"test"===s?"test-mode":""} ${f}`,onClick:At,style:dt,children:[X.jsx("div",{className:"table-header",children:X.jsx("div",{className:"table-title",onClick:e=>{e.stopPropagation(),tt(!Z),null==u||u({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic||{}),{collapsed:!Z})})})},children:X.jsxs("div",{className:"title-content",children:[Z?X.jsx(Q,{size:16}):X.jsx(F,{size:16}),X.jsx(L,{size:16}),X.jsx("span",{className:"table-label",children:(null===(z=n.basic)||void 0===z?void 0:z.label)||"Table"}),(null===(G=n.validation)||void 0===G?void 0:G.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]})})}),(null===(q=n.basic)||void 0===q?void 0:q.description)&&!Z&&X.jsx("div",{className:"table-description",children:n.basic.description}),!Z&&X.jsxs("div",{className:"table-content",children:[null,X.jsxs("table",{style:ft,children:[(null===(W=n.table)||void 0===W?void 0:W.displayAsTable)&&("edit"===s||(null===(Y=n.table)||void 0===Y?void 0:Y.showColumns))&&X.jsx("thead",{children:X.jsx("tr",{className:"table-header-row",children:Array.from({length:(null===(J=n.table)||void 0===J?void 0:J.columns)||(null===($=n.basic)||void 0===$?void 0:$.columns)||3},(t,e)=>{var A,r;const i=((null===(r=null===(A=n.table)||void 0===A?void 0:A.columnNames)||void 0===r?void 0:r.split(",").map(t=>t.trim()))||[])[e]||`Column ${e+1}`;return X.jsx("th",{className:"table-header-cell",style:{backgroundColor:(n.styles.headerBackgroundColor,"var(--df-color-fb-container)"),color:n.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-${e}`)})})}),X.jsx("tbody",{children:nt.map((e,A)=>X.jsx("tr",{className:"table-row",children:e.map(e=>X.jsx(_t,{cell:e,mode:s,onComponentSelect:g||(()=>{}),onComponentDelete:rt,onComponentEdit:w,selectedComponent:v||null,renderFormComponent:ct,formData:a,formTemplateId:b,onThresholdActionCompletion:y,onThresholdIssueRaised:C,tableId:t,onNotesChange:x,onAttachmentChange:U,workOrderNumber:E,assetNumber:N,user:S,onCreateIssue:I,onUpdateIssue:_},e.id))},A))})]})]})]}):null};var kt=Object.freeze({__proto__:null,DfFormTable:Ot,default:Ot});const Tt={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:t=>({flex:`0 0 calc(${t/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"}},jt=t=>{if(!t||"string"!=typeof t)return!1;const e=t.trim();return e.startsWith("data:image")||e.startsWith("iVBORw0KGgo")||e.startsWith("/9j/4AAQ")||e.startsWith("UklGR")||e.startsWith("R0lGOD")},Ht=(t,e)=>{if(!t)return"";const A=t.trim();return A.startsWith("data:")||A.startsWith("http")||A.startsWith("blob:")||A.startsWith("/")?A:A.startsWith("iVBORw0KGgo")?`data:image/png;base64,${A}`:A.startsWith("/9j/4AAQ")?`data:image/jpeg;base64,${A}`:A.startsWith("UklGR")?`data:image/webp;base64,${A}`:A.startsWith("R0lGOD")?`data:image/gif;base64,${A}`:e&&e.startsWith("image/")?`data:${e};base64,${A}`:A},Pt=t=>{if(void 0!==(null==t?void 0:t.icon)&&null!==(null==t?void 0:t.icon))return t.icon;return"pass"===(t=>{const e=String(t||"").toLowerCase();return"pass"===e||"yes"===e?"pass":"fail"===e||"no"===e?"fail":"pass"})((null==t?void 0:t.value)||t)?"✓":"×"},Dt=({component:t})=>{var e,A;const r=(null===(e=t.basic)||void 0===e?void 0:e.notes)||"",n=(null===(A=t.basic)||void 0===A?void 0:A.attachments)||[];return r.trim()||0!==n.length?X.jsxs("div",{style:{marginTop:"5px"},children:[r.trim().length>0&&X.jsxs("div",{style:Tt.notesSection,children:[X.jsx("span",{style:Tt.notesLabel,children:"Notes:"}),r]}),n.length>0&&X.jsx("div",{style:Tt.attachmentsSection,children:n.map((t,e)=>{var A;const r=!(!t.data&&!t.url),n=((null===(A=t.type)||void 0===A?void 0:A.startsWith("image/"))||jt(t.data||t.url||""))&&r?Ht(t.data||t.url||"",t.type):null;return X.jsx("div",{style:Tt.attachmentThumbnail,children:n?X.jsx("img",{src:n,alt:t.name||"Attachment",style:Tt.attachmentImg}):X.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},e)})})]}):null},Mt=({component:t})=>{var e,A,r,n,i,s,a;const o=void 0!==(null===(e=t.basic)||void 0===e?void 0:e.value)?t.basic.value:null===(A=t.basic)||void 0===A?void 0:A.defaultValue,{name:l}=t;if("signature"===l)return o&&jt(o)?X.jsx("div",{style:{marginTop:"5px"},children:X.jsx("img",{src:Ht(o),alt:"Signature",style:Object.assign(Object.assign({},Tt.img),{maxHeight:"100px",width:"auto"})})}):X.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===l){const e=(null===(r=t.basic)||void 0===r?void 0:r.options)||[],A=Array.isArray(o)?o:[o];return X.jsx("div",{style:{marginTop:"5px",width:"100%"},children:e.map((t,e)=>{const r=A.includes(t.value);return X.jsxs("div",{style:Tt.checkboxItem,children:[X.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(r?"#303992":"#cbd5e1"),borderRadius:"4px",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:r?"#303992":"#ffffff"},children:r&&X.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),X.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:t.label})]},e)})})}if("radio"===l){const e=(null===(n=t.basic)||void 0===n?void 0:n.options)||[];return X.jsx("div",{style:{marginTop:"5px",width:"100%"},children:e.map((t,e)=>{const A=o===t.value;return X.jsxs("div",{style:Tt.checkboxItem,children:[X.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(A?"#303992":"#cbd5e1"),borderRadius:"50%",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#ffffff"},children:A&&X.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),X.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:t.label})]},e)})})}if("segment"===l){const e=(null===(i=t.basic)||void 0===i?void 0:i.options)||[],A=o;return X.jsx("div",{style:Tt.segmentContainer,children:e.map((t,e)=>{const r=A===t.value,n=Pt(t),i=t.color||"#666";let s=Object.assign({},Tt.segmentButton);return s=r?Object.assign(Object.assign({},s),{backgroundColor:i,color:"#ffffff",borderColor:i}):Object.assign(Object.assign({},s),{backgroundColor:"#ffffff",color:i,borderColor:i}),X.jsxs("div",{style:s,children:[X.jsx("span",{style:Tt.segmentIcon,children:n}),X.jsx("span",{children:t.value})]},e)})})}if("file"===l){const t=(Array.isArray(o)?o:o?[o]:[]).filter(t=>{const e=!(!t.data&&!t.url),A=t.type&&t.type.startsWith("image/"),r=e&&jt(t.data||t.url);return A||r});return t.length>0?X.jsx("div",{style:{marginTop:"10px"},children:t.map((t,e)=>{const A=Ht(t.data||t.url,t.type);return A?X.jsx("img",{src:A,alt:t.name||"File",style:Object.assign(Object.assign({},Tt.img),{marginBottom:"10px"})},e):null})}):X.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===l){if(o&&"object"==typeof o){const t=o;return X.jsxs("div",{style:{fontSize:"14px"},children:[t.placeName&&X.jsxs("div",{style:{marginBottom:"4px"},children:[X.jsx("strong",{children:"Place:"})," ",t.placeName]}),(t.city||t.country)&&X.jsxs("div",{style:{marginBottom:"4px"},children:[X.jsx("strong",{children:"Address:"})," ",[t.city,t.country].filter(Boolean).join(", ")]}),t.latitude&&t.longitude&&X.jsxs("div",{style:{marginBottom:"4px"},children:[X.jsx("strong",{children:"Coordinates:"})," ",t.latitude.toFixed(6),", ",t.longitude.toFixed(6)]}),t.timestamp&&X.jsxs("div",{children:[X.jsx("strong",{children:"Captured:"})," ",(et(t.timestamp)||new Date).toLocaleString()]})]})}return X.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===l){const e=(null===(s=t.basic)||void 0===s?void 0:s.instructions)||[],A=(null===(a=t.validation)||void 0===a?void 0:a.listStyle)||"numbers";if(!Array.isArray(e)||0===e.length)return X.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const r=()=>X.jsx("div",{dangerouslySetInnerHTML:{__html:e.join("")}});return"numbers"===A?X.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:X.jsx(r,{})}):"bullets"===A?X.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:X.jsx(r,{})}):X.jsx("div",{style:{margin:"10px 0"},children:X.jsx(r,{})})}const c="object"==typeof o?JSON.stringify(o):String(o);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid"].includes(l)){const t="textarea"===l;return X.jsx("div",{style:Object.assign(Object.assign({},Tt.valueContainer),t?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}),children:X.jsx("div",{style:Tt.value,children:c})})}return X.jsx("div",{style:Tt.value,children:c})},Rt=({component:t})=>{var e,A,r;const{name:n,basic:i,styles:s,validation:a}=t,o=null==i?void 0:i.label,l=null==a?void 0:a.required,c="left"===((null==s?void 0:s.labelAlignment)||"top");if("section"===n){const e=null==s?void 0:s.headerBackgroundColor,A=null==s?void 0:s.headerTextColor,r=Object.assign(Object.assign(Object.assign(Object.assign({},Tt.sectionHeader),e?{backgroundColor:e,padding:"8px",borderRadius:"4px"}:{}),A?{color:A}:{}),{display:"flex",alignItems:"center"});return X.jsxs("div",{style:Tt.section,children:[o&&X.jsx("label",{style:r,children:X.jsxs("span",{style:{flex:1},children:[o,l&&" *"]})}),(null==i?void 0:i.description)&&X.jsx("p",{style:Object.assign(Object.assign({},Tt.description),{marginBottom:"15px"}),children:i.description}),X.jsx(Dt,{component:t}),X.jsx("div",{style:Tt.sectionChildren,children:X.jsx(Kt,{components:t.children||[]})})]})}if("heading"===n){const t=`h${Math.max(1,Math.min(6,null!==(A=null!==(e=null==s?void 0:s.level)&&void 0!==e?e:null==i?void 0:i.level)&&void 0!==A?A:1))}`,r=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},(null==s?void 0:s.headerBackgroundColor)?{backgroundColor:s.headerBackgroundColor,padding:"8px",borderRadius:"4px"}:{}),(null==s?void 0:s.headerTextColor)?{color:s.headerTextColor}:{}),(null==s?void 0:s.fontSize)?{fontSize:s.fontSize}:{}),(null==s?void 0:s.textAlign)?{textAlign:s.textAlign}:{}),{marginTop:0,marginBottom:"15px"});return X.jsx("div",{style:Tt.formGroup,children:X.jsx(t,{style:r,children:(null==i?void 0:i.label)||(null==i?void 0:i.value)})})}if("table"===n){const e=t.cells||[],A=Math.max(0,...e.map(t=>t?t.length:0)),r=A>0?100/A:100,n=null==s?void 0:s.headerBackgroundColor,i=null==s?void 0:s.headerTextColor,a=Object.assign(Object.assign(Object.assign({},Tt.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{});return X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:a,children:[o,l&&" *"]}),X.jsx("table",{style:Tt.table,children:X.jsx("tbody",{children:e.map((t,e)=>X.jsx("tr",{children:t&&t.map((t,e)=>X.jsx("td",{style:Object.assign(Object.assign({},Tt.td),{width:`${r}%`}),children:t.components&&t.components.map((t,e)=>{var A;return X.jsxs("div",{style:{marginBottom:"8px"},children:[(null===(A=t.basic)||void 0===A?void 0:A.label)&&X.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[t.basic.label,":"]}),X.jsx(Mt,{component:t}),X.jsx(Dt,{component:t})]},e)})},e))},e))})})]})}if("datagrid"===n){const e=t.entries||[];let A=t.templateComponents||[];0===A.length&&e.length>0&&(null===(r=e[0])||void 0===r?void 0:r.components)&&(A=e[0].components.map(t=>{var e;return Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{label:(null===(e=t.basic)||void 0===e?void 0:e.label)||t.name})})}));const n=null==s?void 0:s.headerBackgroundColor,i=null==s?void 0:s.headerTextColor,a=Object.assign(Object.assign(Object.assign({},Tt.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{}),c=e.filter(t=>!(!t.components||0===t.components.length)&&t.components.some(t=>{var e,A;const r=void 0!==(null===(e=t.basic)||void 0===e?void 0:e.value)?t.basic.value:null===(A=t.basic)||void 0===A?void 0:A.defaultValue;return Array.isArray(r)?r.length>0:null!=r&&""!==String(r).trim()}));return 0===c.length?X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:a,children:[o,l&&" *"]}),X.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:a,children:[o,l&&" *"]}),X.jsxs("table",{style:Tt.table,children:[X.jsx("thead",{children:X.jsx("tr",{children:A.map((t,e)=>{var A;return X.jsx("th",{style:Tt.th,children:(null===(A=t.basic)||void 0===A?void 0:A.label)||t.name},e)})})}),X.jsx("tbody",{children:c.map((t,e)=>X.jsx("tr",{children:A.map((e,A)=>{const r=t.components[A];return X.jsx("td",{style:Tt.td,children:r?X.jsxs(X.Fragment,{children:[X.jsx(Mt,{component:r}),X.jsx(Dt,{component:r})]}):"N/A"},A)})},e))})]})]})}if(c&&"instructions"!==n){const e=["segment"].includes(n);return X.jsxs("div",{style:Tt.formGroup,children:[X.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[o&&X.jsxs("label",{style:Tt.labelLeft,children:[o,l&&" *"]}),X.jsx("div",{style:Object.assign({flex:1},e?{display:"flex",justifyContent:"flex-end"}:{}),children:X.jsx(Mt,{component:t})})]}),X.jsx(Dt,{component:t})]})}return X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:Tt.label,children:[o,l&&" *"]}),X.jsx(Mt,{component:t}),X.jsx(Dt,{component:t})]})},Kt=({components:t})=>{if(!t||0===t.length)return null;const e=[];let A=[],r=0;return t.forEach(t=>{var n;const i=["section","table","datagrid","heading","instructions"].includes(t.name),s=i?12:(null===(n=t.styles)||void 0===n?void 0:n.column)||12;r+s>12&&A.length>0&&(e.push(A),A=[],r=0),A.push(t),r+=s,(i||r>=12)&&r>0&&(e.push(A),A=[],r=0)}),A.length>0&&e.push(A),X.jsx(X.Fragment,{children:e.map((t,e)=>1===t.length?X.jsx(Rt,{component:t[0]},t[0].id||e):X.jsx("div",{style:Tt.gridRow,children:t.map((t,e)=>{var A;const r=(null===(A=t.styles)||void 0===A?void 0:A.column)||12;return X.jsx("div",{style:Tt.gridCol(r),children:X.jsx(Rt,{component:t})},t.id||e)})},e))})},Vt=({formTitle:t,formDescription:e,userName:A,components:r})=>X.jsxs("div",{className:"pdf-container",style:Tt.page,children:[X.jsxs("div",{style:Tt.header,children:[X.jsxs("div",{children:[X.jsx("h1",{style:Tt.title,children:t}),e&&X.jsx("p",{style:Tt.description,children:e})]}),A&&X.jsxs("div",{style:Tt.submittedBy,children:[X.jsx("strong",{children:"Submitted By:"})," ",A]})]}),X.jsx("div",{className:"form-content",children:X.jsx(Kt,{components:r})})]});var zt,Gt=I;if("production"===process.env.NODE_ENV)zt=Gt.createRoot,Gt.hydrateRoot;else{var qt=Gt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;zt=function(t,e){qt.usingClientEntryPoint=!0;try{return Gt.createRoot(t,e)}finally{qt.usingClientEntryPoint=!1}}}var Wt={exports:{}};
10
+ */"production"===process.env.NODE_ENV?z.exports=function(){if(V)return G;V=1;var e=t,A=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function a(t,e,r){var a,o={},l=null,c=null;for(a in void 0!==r&&(l=""+r),void 0!==e.key&&(l=""+e.key),void 0!==e.ref&&(c=e.ref),e)n.call(e,a)&&!s.hasOwnProperty(a)&&(o[a]=e[a]);if(t&&t.defaultProps)for(a in e=t.defaultProps)void 0===o[a]&&(o[a]=e[a]);return{$$typeof:A,type:t,key:l,ref:c,props:o,_owner:i.current}}return G.Fragment=r,G.jsx=a,G.jsxs=a,G}():z.exports=(q||(q=1,"production"!==process.env.NODE_ENV&&function(){var e,A=t,r=Symbol.for("react.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),o=Symbol.for("react.provider"),l=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),g=Symbol.iterator,m=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(t){for(var e=arguments.length,A=new Array(e>1?e-1:0),r=1;r<e;r++)A[r-1]=arguments[r];!function(t,e,A){var r=m.ReactDebugCurrentFrame.getStackAddendum();""!==r&&(e+="%s",A=A.concat([r]));var n=A.map(function(t){return String(t)});n.unshift("Warning: "+e),Function.prototype.apply.call(console[t],console,n)}("error",t,A)}function v(t){return t.displayName||"Context"}function B(t){if(null==t)return null;if("number"==typeof t.tag&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof t)return t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case i:return"Fragment";case n:return"Portal";case a:return"Profiler";case s:return"StrictMode";case u:return"Suspense";case h:return"SuspenseList"}if("object"==typeof t)switch(t.$$typeof){case l:return v(t)+".Consumer";case o:return v(t._context)+".Provider";case c:return function(t,e,A){var r=t.displayName;if(r)return r;var n=e.displayName||e.name||"";return""!==n?A+"("+n+")":A}(t,t.render,"ForwardRef");case d:var e=t.displayName||null;return null!==e?e:B(t.type)||"Memo";case f:var A=t,r=A._payload,p=A._init;try{return B(p(r))}catch(t){return null}}return null}e=Symbol.for("react.module.reference");var b,y,C,x,F,Q,U,E=Object.assign,N=0;function S(){}S.__reactDisabledLog=!0;var L,I=m.ReactCurrentDispatcher;function _(t,e,A){if(void 0===L)try{throw Error()}catch(t){var r=t.stack.trim().match(/\n( *(at )?)/);L=r&&r[1]||""}return"\n"+L+t}var O,k=!1,T="function"==typeof WeakMap?WeakMap:Map;function j(t,e){if(!t||k)return"";var A,r=O.get(t);if(void 0!==r)return r;k=!0;var n,i=Error.prepareStackTrace;Error.prepareStackTrace=void 0,n=I.current,I.current=null,function(){if(0===N){b=console.log,y=console.info,C=console.warn,x=console.error,F=console.group,Q=console.groupCollapsed,U=console.groupEnd;var t={configurable:!0,enumerable:!0,value:S,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}N++}();try{if(e){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(t){A=t}Reflect.construct(t,[],s)}else{try{s.call()}catch(t){A=t}t.call(s.prototype)}}else{try{throw Error()}catch(t){A=t}t()}}catch(e){if(e&&A&&"string"==typeof e.stack){for(var a=e.stack.split("\n"),o=A.stack.split("\n"),l=a.length-1,c=o.length-1;l>=1&&c>=0&&a[l]!==o[c];)c--;for(;l>=1&&c>=0;l--,c--)if(a[l]!==o[c]){if(1!==l||1!==c)do{if(l--,--c<0||a[l]!==o[c]){var u="\n"+a[l].replace(" at new "," at ");return t.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",t.displayName)),"function"==typeof t&&O.set(t,u),u}}while(l>=1&&c>=0);break}}}finally{k=!1,I.current=n,function(){if(0===--N){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:E({},t,{value:b}),info:E({},t,{value:y}),warn:E({},t,{value:C}),error:E({},t,{value:x}),group:E({},t,{value:F}),groupCollapsed:E({},t,{value:Q}),groupEnd:E({},t,{value:U})})}N<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=i}var h=t?t.displayName||t.name:"",d=h?_(h):"";return"function"==typeof t&&O.set(t,d),d}function H(t,e,A){if(null==t)return"";if("function"==typeof t)return j(t,!(!(r=t.prototype)||!r.isReactComponent));var r;if("string"==typeof t)return _(t);switch(t){case u:return _("Suspense");case h:return _("SuspenseList")}if("object"==typeof t)switch(t.$$typeof){case c:return j(t.render,!1);case d:return H(t.type,e,A);case f:var n=t,i=n._payload,s=n._init;try{return H(s(i),e,A)}catch(t){}}return""}O=new T;var P=Object.prototype.hasOwnProperty,D={},M=m.ReactDebugCurrentFrame;function R(t){if(t){var e=t._owner,A=H(t.type,t._source,e?e.type:null);M.setExtraStackFrame(A)}else M.setExtraStackFrame(null)}var K=Array.isArray;function V(t){return K(t)}function z(t){return""+t}function G(t){if(function(t){try{return z(t),!1}catch(t){return!0}}(t))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(t){return"function"==typeof Symbol&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object"}(t)),z(t)}var q,X,Y,J=m.ReactCurrentOwner,$={key:!0,ref:!0,__self:!0,__source:!0};function Z(t,e,A,n,i){var s,a={},o=null,l=null;for(s in void 0!==A&&(G(A),o=""+A),function(t){if(P.call(t,"key")){var e=Object.getOwnPropertyDescriptor(t,"key").get;if(e&&e.isReactWarning)return!1}return void 0!==t.key}(e)&&(G(e.key),o=""+e.key),function(t){if(P.call(t,"ref")){var e=Object.getOwnPropertyDescriptor(t,"ref").get;if(e&&e.isReactWarning)return!1}return void 0!==t.ref}(e)&&(l=e.ref,function(t,e){if("string"==typeof t.ref&&J.current&&e&&J.current.stateNode!==e){var A=B(J.current.type);Y[A]||(w('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',B(J.current.type),t.ref),Y[A]=!0)}}(e,i)),e)P.call(e,s)&&!$.hasOwnProperty(s)&&(a[s]=e[s]);if(t&&t.defaultProps){var c=t.defaultProps;for(s in c)void 0===a[s]&&(a[s]=c[s])}if(o||l){var u="function"==typeof t?t.displayName||t.name||"Unknown":t;o&&function(t,e){var A=function(){q||(q=!0,w("%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)",e))};A.isReactWarning=!0,Object.defineProperty(t,"key",{get:A,configurable:!0})}(a,u),l&&function(t,e){var A=function(){X||(X=!0,w("%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)",e))};A.isReactWarning=!0,Object.defineProperty(t,"ref",{get:A,configurable:!0})}(a,u)}return function(t,e,A,n,i,s,a){var o={$$typeof:r,type:t,key:e,ref:A,props:a,_owner:s,_store:{}};return Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o}(t,o,l,i,n,J.current,a)}Y={};var tt,et=m.ReactCurrentOwner,At=m.ReactDebugCurrentFrame;function rt(t){if(t){var e=t._owner,A=H(t.type,t._source,e?e.type:null);At.setExtraStackFrame(A)}else At.setExtraStackFrame(null)}function nt(t){return"object"==typeof t&&null!==t&&t.$$typeof===r}function it(){if(et.current){var t=B(et.current.type);if(t)return"\n\nCheck the render method of `"+t+"`."}return""}tt=!1;var st={};function at(t,e){if(t._store&&!t._store.validated&&null==t.key){t._store.validated=!0;var A=function(t){var e=it();if(!e){var A="string"==typeof t?t:t.displayName||t.name;A&&(e="\n\nCheck the top-level render call using <"+A+">.")}return e}(e);if(!st[A]){st[A]=!0;var r="";t&&t._owner&&t._owner!==et.current&&(r=" It was passed a child from "+B(t._owner.type)+"."),rt(t),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',A,r),rt(null)}}}function ot(t,e){if("object"==typeof t)if(V(t))for(var A=0;A<t.length;A++){var r=t[A];nt(r)&&at(r,e)}else if(nt(t))t._store&&(t._store.validated=!0);else if(t){var n=function(t){if(null===t||"object"!=typeof t)return null;var e=g&&t[g]||t["@@iterator"];return"function"==typeof e?e:null}(t);if("function"==typeof n&&n!==t.entries)for(var i,s=n.call(t);!(i=s.next()).done;)nt(i.value)&&at(i.value,e)}}function lt(t){var e,A=t.type;if(null!=A&&"string"!=typeof A){if("function"==typeof A)e=A.propTypes;else{if("object"!=typeof A||A.$$typeof!==c&&A.$$typeof!==d)return;e=A.propTypes}if(e){var r=B(A);!function(t,e,A,r,n){var i=Function.call.bind(P);for(var s in t)if(i(t,s)){var a=void 0;try{if("function"!=typeof t[s]){var o=Error((r||"React class")+": "+A+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw o.name="Invariant Violation",o}a=t[s](e,s,r,A,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(t){a=t}!a||a instanceof Error||(R(n),w("%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).",r||"React class",A,s,typeof a),R(null)),a instanceof Error&&!(a.message in D)&&(D[a.message]=!0,R(n),w("Failed %s type: %s",A,a.message),R(null))}}(e,t.props,"prop",r,t)}else void 0===A.PropTypes||tt||(tt=!0,w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",B(A)||"Unknown"));"function"!=typeof A.getDefaultProps||A.getDefaultProps.isReactClassApproved||w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ct={};function ut(t,A,n,g,m,v){var b=function(t){return"string"==typeof t||"function"==typeof t||t===i||t===a||t===s||t===u||t===h||t===p||"object"==typeof t&&null!==t&&(t.$$typeof===f||t.$$typeof===d||t.$$typeof===o||t.$$typeof===l||t.$$typeof===c||t.$$typeof===e||void 0!==t.getModuleId)}(t);if(!b){var y="";(void 0===t||"object"==typeof t&&null!==t&&0===Object.keys(t).length)&&(y+=" 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,x=function(t){return void 0!==t?"\n\nCheck your code at "+t.fileName.replace(/^.*[\\\/]/,"")+":"+t.lineNumber+".":""}(m);y+=x||it(),null===t?C="null":V(t)?C="array":void 0!==t&&t.$$typeof===r?(C="<"+(B(t.type)||"Unknown")+" />",y=" Did you accidentally export a JSX literal instead of a component?"):C=typeof t,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,y)}var F=Z(t,A,n,m,v);if(null==F)return F;if(b){var Q=A.children;if(void 0!==Q)if(g)if(V(Q)){for(var U=0;U<Q.length;U++)ot(Q[U],t);Object.freeze&&Object.freeze(Q)}else w("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 ot(Q,t)}if(P.call(A,"key")){var E=B(t),N=Object.keys(A).filter(function(t){return"key"!==t}),S=N.length>0?"{key: someKey, "+N.join(": ..., ")+": ...}":"{key: someKey}";ct[E+S]||(w('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} />',S,E,N.length>0?"{"+N.join(": ..., ")+": ...}":"{}",E),ct[E+S]=!0)}return t===i?function(t){for(var e=Object.keys(t.props),A=0;A<e.length;A++){var r=e[A];if("children"!==r&&"key"!==r){rt(t),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",r),rt(null);break}}null!==t.ref&&(rt(t),w("Invalid attribute `ref` supplied to `React.Fragment`."),rt(null))}(F):lt(F),F}var ht=function(t,e,A){return ut(t,e,A,!1)},dt=function(t,e,A){return ut(t,e,A,!0)};W.Fragment=i,W.jsx=ht,W.jsxs=dt}()),W);var X=z.exports;class Y{constructor(){}static getInstance(){return Y.instance||(Y.instance=new Y),Y.instance}getAvailableComponentsForConditional(t,e){if(!t||!Array.isArray(t))return[];const A=t.filter(t=>!e||t.id!==e).map(t=>{var e;return{id:t.id,label:(null===(e=t.basic)||void 0===e?void 0:e.label)||t.id,type:t.name,key:t.id}}).sort((t,e)=>t.label.localeCompare(e.label));return A}getApplicableOperators(t){switch(t){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(t,e){const A=[];return t?(["show","hide","always"].includes(t.action)||A.push("Invalid conditional action"),["all","any"].includes(t.when)||A.push("Invalid when condition"),t.conditions&&0!==t.conditions.length?t.conditions.forEach((t,r)=>{const n=e.find(e=>e.id===t.when);if(!n)return void A.push(`Condition ${r+1}: Component not found`);this.getApplicableOperators(n.name).includes(t.operator)||A.push(`Condition ${r+1}: Operator not applicable for component type`),this.isValidConditionValue(t.value,n.name,t.operator)||A.push(`Condition ${r+1}: Invalid condition value`)}):A.push("At least one condition is required"),{isValid:0===A.length,errors:A}):{isValid:!0,errors:[]}}evaluateConditionalLogic(t,e,A){if("always"===t.action)return{shouldShow:!0,evaluatedConditions:[]};if(!t||!t.conditions||0===t.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const r=t.conditions.map(t=>{const r=this.getComponentValue(t.when,e,A);return{condition:t,result:this.evaluateCondition(t,r),componentValue:r}});return{shouldShow:this.determineFinalResult(t,r),evaluatedConditions:r}}getComponentValue(t,e,A){if(A&&void 0!==A[t])return A[t];const r=e.find(e=>e.id===t);return r&&"defaultValue"in r.basic?r.basic.defaultValue:void 0}evaluateCondition(t,e){const{operator:A,value:r}=t;if("checked"===r||"notChecked"===r)return this.evaluateCheckboxCondition(e,r);switch(A){case"equals":return this.isEqual(e,r);case"notEquals":return!this.isEqual(e,r);case"isEmpty":return this.isEmpty(e);case"isNotEmpty":return!this.isEmpty(e);case"contains":return this.contains(e,r);case"notContains":return!this.contains(e,r);case"greaterThan":return this.isGreaterThan(e,r);case"lessThan":return this.isLessThan(e,r);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(e,r);case"lessThanOrEqual":return this.isLessThanOrEqual(e,r);default:return!1}}evaluateCheckboxCondition(t,e){const A=this.isCheckboxChecked(t);return"checked"===e?A:"notChecked"===e&&!A}isCheckboxChecked(t){return null!=t&&("boolean"==typeof t?t:"string"==typeof t?"true"===t.toLowerCase()||"1"===t:Array.isArray(t)?t.length>0:"number"==typeof t&&t>0)}determineFinalResult(t,e){let A,r;return A="all"===t.when?e.every(t=>t.result):"any"===t.when&&e.some(t=>t.result),r="show"===t.action?A:"hide"===t.action?!A:(t.action,!0),r}isEqual(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(Array.isArray(t)&&Array.isArray(e))return t.length===e.length&&t.every((t,A)=>this.isEqual(t,e[A]));if("object"==typeof t&&"object"==typeof e){const A=Object.keys(t),r=Object.keys(e);return A.length===r.length&&A.every(A=>this.isEqual(t[A],e[A]))}return!1}isEmpty(t){return null==t||void 0===t||("string"==typeof t?""===t.trim():Array.isArray(t)?0===t.length:"object"==typeof t&&0===Object.keys(t).length)}contains(t,e){return null!=t&&null!=e&&("string"==typeof t?t.toLowerCase().includes(String(e).toLowerCase()):!!Array.isArray(t)&&t.some(t=>this.isEqual(t,e)))}isGreaterThan(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A>r}isLessThan(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A<r}isGreaterThanOrEqual(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A>=r}isLessThanOrEqual(t,e){const A=Number(t),r=Number(e);return!isNaN(A)&&!isNaN(r)&&A<=r}isValidConditionValue(t,e,A){if(null==t)return["isEmpty","isNotEmpty"].includes(A);switch(e){case"number-input":return!isNaN(Number(t))||["isEmpty","isNotEmpty"].includes(A);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(t))||["isEmpty","isNotEmpty"].includes(A);case"checkbox":return Array.isArray(t)||"string"==typeof t||"number"==typeof t;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(t){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"}[t]||t}getActionDisplayText(t){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[t]||t}getConditionalLogicSummary(t,e){if(!t||0===t.conditions.length)return"No conditions";if("always"===t.action)return"Always show";const A=this.getActionDisplayText(t.action),r=t.conditions.map(t=>{const A=e.find(e=>e.id===t.when);return`${(null==A?void 0:A.basic.label)||"Unknown component"} ${this.getOperatorDisplayText(t.operator)} ${this.formatConditionValue(t.value)}`}),n="all"===t.when?" and ":" or ";return`${A} ${r.join(n)}`}formatConditionValue(t){return null==t?"empty":Array.isArray(t)?`[${t.join(", ")}]`:"string"==typeof t?`"${t}"`:String(t)}}const J=Y.getInstance();const $=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(t=>t([...this.toasts]))}addToast(t){try{this.toasts.push(t),this.notifyListeners(),this.timeouts[t.id]=setTimeout(()=>{this.removeToast(t.id)},t.duration||this.defaultDuration)}catch(t){console.error("Error displaying toast message:",t)}}removeToast(t){this.timeouts[t]&&(clearTimeout(this.timeouts[t]),delete this.timeouts[t]),this.toasts=this.toasts.filter(e=>e.id!==t),this.notifyListeners()}showSuccess(t,e=3e3){const A={id:this.generateId(),message:t,type:"success",duration:e};this.addToast(A)}showError(t,e=5e3){const A={id:this.generateId(),message:t,type:"danger",duration:e};this.addToast(A)}showWarning(t,e){const A={id:this.generateId(),message:t,type:"warning",duration:e};this.addToast(A)}showInfo(t,e){const A={id:this.generateId(),message:t,type:"info",duration:e};this.addToast(A)}show(t,e="success",A){const r={id:this.generateId(),message:t,type:e,duration:A};this.addToast(r)}clearAll(){Object.values(this.timeouts).forEach(t=>clearTimeout(t)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(t){return this.listeners.push(t),()=>{this.listeners=this.listeners.filter(e=>e!==t)}}getToasts(){return[...this.toasts]}},Z=({validationErrors:t,fieldId:e,touchedFields:A,formSubmitted:r,properties:n,localValidation:i,isTouched:s,mode:a})=>{const o=t=>{var e,A;const r=n.basic.label||"This field",i=n.name||"",s=null===(e=n.validation)||void 0===e?void 0:e.customValidationMessage;if("number-input"===i)switch(t){case"required":return`${r} is required`;case"lowerLimit":return"Number is below the lower limit";case"upperLimit":return"Number is above the upper limit";default:return""}if(s)return s;const a="date-picker"===i||"datetime-picker"===i?(null===(A=n.basic)||void 0===A?void 0:A.dateTimeMode)||("datetime-picker"===i?"datetime":"date"):null;switch(t){case"required":return`${r} is required`;case"invalidDate":return"time"===a?"Please select a valid time":"datetime"===a?"Please select a valid date and time":"date"===a?"Please select a valid date":`${r} is invalid`;case"minLength":return`${r} must be at least ${n.validation.minLength} characters long`;case"maxLength":return`${r} must be no more than ${n.validation.maxLength} characters long`;case"min":return`${r} must be at least ${n.validation.min}`;case"max":return`${r} must be no more than ${n.validation.max}`;case"lowerLimit":const t=n.validation;return`You are under the limit. ${r} must be at least ${null==t?void 0:t.lowerLimit}`;case"upperLimit":const e=n.validation;return`You crossed the limit. ${r} must be no more than ${null==e?void 0:e.upperLimit}`;case"pattern":return`${r} format is invalid`;case"email":return`${r} must be a valid email address`;default:return`${r} is invalid`}},l=(()=>{var l;if("test"!==a)return"";if(!(s||A[e]||r))return"";if(i&&i.isValid)return"";if(i&&!i.isValid&&Object.keys(i.errors).length>0){const t=Object.keys(i.errors).filter(t=>!0===i.errors[t]);if(t.length>0){const e=t[0],A=n.name||"";return"pattern"===e&&"number-input"===A?"":o(e)}}const c=t[e];if(c&&"string"==typeof c&&""!==c.trim()){const t=n.name||"";if("number-input"===t&&i){const t=n.validation,e=t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit,A=t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||e||A?(i.isValid,""):""}if(("date-picker"===t||"datetime-picker"===t)&&c.includes("valid date")){const e=(null===(l=n.basic)||void 0===l?void 0:l.dateTimeMode)||("datetime-picker"===t?"datetime":"date");if("time"===e)return"Please select a valid time";if("datetime"===e)return"Please select a valid date and time"}return c}return""})();return l?X.jsx("div",{className:"form-error-msg",children:l}):null};function tt(t,e,A,r){return new(A||(A=Promise))(function(n,i){function s(t){try{o(r.next(t))}catch(t){i(t)}}function a(t){try{o(r.throw(t))}catch(t){i(t)}}function o(t){var e;t.done?n(t.value):(e=t.value,e instanceof A?e:new A(function(t){t(e)})).then(s,a)}o((r=r.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const et=t=>{if(null==t||""===t)return null;if(t instanceof Date)return isNaN(t.getTime())?null:t;if("number"==typeof t){const e=new Date(t);return isNaN(e.getTime())?null:e}if("string"==typeof t){let e=t.trim();e.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)&&(e=e.replace(" ","T"));const A=new Date(e);return isNaN(A.getTime())?null:A}return null};var At;!function(t){t.OPEN="Open",t.IN_PROGRESS="In-Progress",t.REJECTED="Rejected",t.RESOLVE="Resolve"}(At||(At={}));const rt=({isOpen:r,onClose:n,onSuccess:i,component:d,formTemplateId:f,notes:p="",attachments:g=null,issue:m=null,onCreateIssue:w,onUpdateIssue:v,user:B,availableUsers:b=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:y,assetNumber:C,isStandalone:x,isEdit:F})=>{var Q,U,E,N,S,L;const[I,O]=e(""),[k,T]=e(""),[j,H]=e(""),[P,D]=e(""),[M,R]=e("Medium"),[K,V]=e(At.OPEN),[z,G]=e(""),[q,W]=e(""),[Y,J]=e(!1),[Z,rt]=e(g||[]),[nt,it]=e(!1),st=t.useRef(null),at=void 0!==F?F:!!m;A(()=>{(null==m?void 0:m.attachments)&&m.attachments.length>0?rt(m.attachments):g&&rt(g)},[g,m]);const ot=t=>{if(!t)return"Attachment";if(t instanceof File)return t.name;if("string"==typeof t){if(t.startsWith("data:"))return"Attachment";const e=t.split("/");return e[e.length-1]||"Attachment"}return t.fileName||t.filename||t.name||"Attachment"},lt=t=>{if(!t)return null;const e=t=>/\.(jpg|jpeg|png|gif|webp)$/i.test(t),A=t=>t.startsWith("data:image");return t instanceof File?t.type.startsWith("image/")?URL.createObjectURL(t):null:"string"==typeof t?A(t)||e(t)?t:null:t.data&&A(t.data)||t.fileName&&e(t.fileName)&&t.data?t.data:null};A(()=>{var t;if(r)if(m||at){O((null==m?void 0:m.title)||""),T((null==m?void 0:m.description)||""),H((null==m?void 0:m.workOrderNumber)||y||""),D((null==m?void 0:m.assetNumber)||C||""),R((null==m?void 0:m.priority)||"Medium");const t=(null==m?void 0:m.status)||At.OPEN,e=t===At.OPEN||t===At.IN_PROGRESS||t===At.REJECTED||t===At.RESOLVE?t:At.OPEN;V(e),G((null==m?void 0:m.assignTo)||(null==m?void 0:m.assignee)||""),W((null==m?void 0:m.comments)||"")}else d&&(null===(t=d.basic)||void 0===t||t.label,O(""),T(""),W(p||""),y&&H(y),C&&D(C))},[r,d,p,m,y,C]);const ct=t.useMemo(()=>{if(!I.trim())return!1;if(!k.trim())return!1;if(!K)return!1;if(!z)return!1;if(!x){if(!j.trim())return!1;if(!P.trim())return!1}return!0},[I,k,K,z,x,j,P]),ut=t=>tt(void 0,void 0,void 0,function*(){var e;if(m){J(!0);try{const e={title:String(I||"").trim(),description:String(k||"").trim(),workOrderNumber:String(j||"").trim()||void 0,assetNumber:String(P||"").trim()||void 0,formTemplateId:m.formTemplateId||"",component:m.component||{},priority:M,assignee:String(z||"").trim()||void 0,status:t,comments:String(q||"").trim()||""};v&&m._id&&(yield v(m._id,e)),V(t);const A={[At.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[At.RESOLVE]:"Issue resolved successfully",[At.REJECTED]:"Issue rejected"};$.showSuccess(A[t]||"Issue status updated successfully"),i&&i(),n()}catch(t){const A=(null==t?void 0:t.message)||(null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.message)||"Failed to update issue status. Please try again.";$.showError(A)}finally{J(!1)}}});if(!r)return null;const ht=X.jsx("div",{className:"raise-issue-modal-overlay",onClick:n,children:X.jsxs("div",{className:"raise-issue-modal",onClick:t=>t.stopPropagation(),children:[X.jsxs("div",{className:"raise-issue-modal-header",children:[X.jsxs("div",{className:"raise-issue-modal-header-left",children:[X.jsx(s,{className:"raise-issue-modal-icon",size:20}),X.jsx("div",{className:"raise-issue-modal-header-text",children:X.jsx("div",{className:"raise-issue-modal-title-main",children:at?"Edit Issue":"Create Issue"})})]}),X.jsx("button",{className:"raise-issue-modal-close",onClick:n,"aria-label":"Close",children:X.jsx(a,{size:18})})]}),X.jsx("div",{className:"raise-issue-modal-content",children:X.jsxs("div",{className:"raise-issue-fields-grid",children:[at&&(null==m?void 0:m.issueNumber)&&X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),X.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:m.issueNumber,readOnly:!0})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Task"}),X.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:at?(null===(U=null===(Q=null==m?void 0:m.component)||void 0===Q?void 0:Q.basic)||void 0===U?void 0:U.label)||"":(null===(E=null==d?void 0:d.basic)||void 0===E?void 0:E.label)||"",readOnly:!0})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Task Value"}),X.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:at?(null===(S=null===(N=null==m?void 0:m.component)||void 0===N?void 0:N.basic)||void 0===S?void 0:S.value)||"":(null===(L=null==d?void 0:d.basic)||void 0===L?void 0:L.value)||"",readOnly:!0})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Title ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("input",{type:"text",className:"raise-issue-field-input "+(at?"raise-issue-field-readonly":""),value:I,onChange:t=>O(t.target.value),placeholder:"Enter issue title",readOnly:at})]}),!x&&X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("input",{type:"text",className:"raise-issue-field-input "+(at?"raise-issue-field-readonly":""),value:j,onChange:t=>H(t.target.value),placeholder:"N/A",readOnly:at})]}),!x&&X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("input",{type:"text",className:"raise-issue-field-input "+(at?"raise-issue-field-readonly":""),value:P,onChange:t=>D(t.target.value),placeholder:"Enter asset number",readOnly:at})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Raised By ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[X.jsx(o,{size:16}),X.jsx("span",{children:B&&`${B.firstName||""} ${B.lastName||""}`.trim()||"User"})]})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),X.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[X.jsx(l,{size:16}),X.jsx("span",{children:at&&(null==m?void 0:m.createdAt)?(et(m.createdAt)||new Date).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})})]})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Description ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsx("textarea",{className:"raise-issue-field-textarea "+(at?"raise-issue-field-readonly":""),value:k,onChange:t=>T(t.target.value),placeholder:"Enter issue description",rows:4,readOnly:at})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Status ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("select",{className:"raise-issue-field-select "+(at?"":"raise-issue-field-readonly"),value:K,onChange:t=>V(t.target.value),disabled:!at,children:[X.jsx("option",{value:At.OPEN,children:At.OPEN}),X.jsx("option",{value:At.IN_PROGRESS,children:At.IN_PROGRESS}),X.jsx("option",{value:At.REJECTED,children:At.REJECTED}),X.jsx("option",{value:At.RESOLVE,children:At.RESOLVE})]})]}),X.jsxs("div",{className:"raise-issue-field",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Assign to ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("select",{className:"raise-issue-field-select",value:z,onChange:t=>G(t.target.value),children:[X.jsx("option",{value:"",children:"Unassigned"}),b.map(t=>X.jsx("option",{value:t,children:t},t))]})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[X.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",X.jsx("span",{className:"raise-issue-required",children:"*"})]}),X.jsxs("div",{className:"raise-issue-priority-buttons",children:[X.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===M?"active":""),onClick:()=>R("Low"),children:"Low"}),X.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===M?"active":""),onClick:()=>R("Medium"),children:"Medium"}),X.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===M?"active":""),onClick:()=>R("High"),children:"High"})]})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[X.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[X.jsx(c,{size:16}),X.jsx("span",{children:"Comments"})]}),!q&&X.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),X.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(at?"raise-issue-field-readonly":""),value:q,onChange:t=>W(t.target.value),placeholder:"Add a comment...",rows:4,readOnly:at})]}),X.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",style:{marginTop:"1rem"},children:[X.jsx("label",{className:"raise-issue-field-label",children:"Attachments"}),X.jsxs("div",{className:"raise-issue-attachments-container",children:[!at&&X.jsxs("div",{className:"raise-issue-dropzone "+(nt?"dragging":""),onDragOver:t=>{t.preventDefault(),it(!0)},onDragLeave:t=>{t.preventDefault(),it(!1)},onDrop:t=>{if(t.preventDefault(),it(!1),t.dataTransfer.files&&t.dataTransfer.files.length>0){const e=Array.from(t.dataTransfer.files);rt(t=>[...t,...e])}},onClick:()=>{var t;return null===(t=st.current)||void 0===t?void 0:t.click()},children:[X.jsx("input",{type:"file",ref:st,style:{display:"none"},onChange:t=>{if(t.target.files&&t.target.files.length>0){const e=Array.from(t.target.files);rt(t=>[...t,...e]),st.current&&(st.current.value="")}},multiple:!0}),X.jsx("div",{className:"raise-issue-dropzone-icon",children:X.jsx(u,{size:24})}),X.jsx("div",{className:"raise-issue-dropzone-text",children:"Click to upload or drag and drop"}),X.jsx("div",{className:"raise-issue-dropzone-hint",children:"PNG, JPG up to 10MB"})]}),Z.length>0&&X.jsx("div",{className:"raise-issue-attachments-list",children:Z.map((t,e)=>X.jsxs("div",{className:"raise-issue-attachment-item",children:[X.jsx("div",{className:"raise-issue-attachment-thumbnail",children:lt(t)?X.jsx("img",{src:lt(t),alt:"Thumbnail"}):X.jsx(h,{size:20,color:"#9ca3af"})}),X.jsxs("div",{className:"raise-issue-attachment-info",children:[X.jsx("span",{className:"attachment-name",title:ot(t),children:ot(t)}),t instanceof File&&X.jsxs("span",{className:"attachment-size",children:[(t.size/1024).toFixed(1)," KB"]})]}),!at&&X.jsx("button",{type:"button",className:"attachment-remove-btn",onClick:()=>(t=>{rt(e=>e.filter((e,A)=>A!==t))})(e),title:"Remove",children:X.jsx(a,{size:12})})]},e))})]})]})]})}),X.jsx("div",{className:"raise-issue-modal-actions",children:X.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[at&&m&&X.jsxs(X.Fragment,{children:[K===At.OPEN&&X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:()=>tt(void 0,void 0,void 0,function*(){yield ut(At.IN_PROGRESS)}),disabled:Y,children:Y?"Processing...":"Accept"}),K===At.IN_PROGRESS&&X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:()=>tt(void 0,void 0,void 0,function*(){yield ut(At.RESOLVE)}),disabled:Y,children:Y?"Processing...":"Resolve"}),(K===At.OPEN||K===At.IN_PROGRESS)&&X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:()=>tt(void 0,void 0,void 0,function*(){yield ut(At.REJECTED)}),disabled:Y,children:Y?"Processing...":"Reject"})]}),X.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save "+(ct?"":"disabled"),onClick:()=>tt(void 0,void 0,void 0,function*(){var t,e,A,r,s,a,o;if(String(I||"").trim())if(String(k||"").trim())if(x||String(j||"").trim())if(x||String(P||"").trim())if(String(z||"").trim()){J(!0);try{if(at&&m){const s={title:String(I||"").trim(),description:String(k||"").trim(),workOrderNumber:String(j||"").trim()||void 0,assetNumber:String(P||"").trim()||void 0,formTemplateId:m.formTemplateId||"",component:m.component||{},priority:M,assignTo:String(z||"").trim()||void 0,status:K,comments:String(q||"").trim()||"",task:(null===(e=null===(t=m.component)||void 0===t?void 0:t.basic)||void 0===e?void 0:e.label)||"",taskValue:(null===(r=null===(A=m.component)||void 0===A?void 0:A.basic)||void 0===r?void 0:r.value)||""};v&&m._id&&(yield v(m._id,s)),$.showSuccess("Issue updated successfully"),i&&i(),n()}else{if(!d)return $.showError("Component is required"),void J(!1);if(!f||""===String(f||"").trim())return $.showError("Form template is required"),void J(!1);const t=Object.assign(Object.assign({},d),{basic:Object.assign(Object.assign({},d.basic),{comments:String(p||"")})}),e=B?`${B.firstName||""} ${B.lastName||""}`.trim():"User",A={title:String(I||"").trim(),workOrderNumber:String(j||"").trim()||void 0,assetNumber:String(P||"").trim()||void 0,component:t,description:String(k||"").trim(),formTemplateId:f,assignTo:String(z||"").trim()||void 0,priority:M,status:K,comments:String(q||"").trim()||"",createdBy:e,task:(null===(s=null==d?void 0:d.basic)||void 0===s?void 0:s.label)||"",taskValue:(null===(a=null==d?void 0:d.basic)||void 0===a?void 0:a.value)||""};let r;if(w&&(r=yield w(A,Z)),$.showSuccess("Issue raised successfully"),i){const t=Object.assign({_id:(null==r?void 0:r._id)||"temp-id",issueNumber:(null==r?void 0:r.issueNumber)||"",title:A.title,description:A.description,status:A.status,priority:A.priority,createdAt:(null==r?void 0:r.createdAt)||(new Date).toISOString(),updatedAt:(null==r?void 0:r.updatedAt)||(new Date).toISOString(),component:A.component,workOrderNumber:A.workOrderNumber,assetNumber:A.assetNumber,assignee:A.assignTo,comments:A.comments,attachments:(null==r?void 0:r.attachments)||Z},r);i(t)}n()}}catch(t){const e=(null==t?void 0:t.message)||(null===(o=null==t?void 0:t.error)||void 0===o?void 0:o.message)||(at?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");$.showError(e)}finally{J(!1)}}else $.showError("Assignee is required");else $.showError("Asset Number is required");else $.showError("Work Order is required");else $.showError("Description is required");else $.showError("Title is required")}),disabled:Y||!ct,children:Y?at?"Saving...":"Creating...":at?"Save Changes":"Create Issue"})]})})]})});return _(ht,document.body)},nt=({component:t,condition:n,currentValue:i,thresholdValue:a,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,onIssueRaised:h,isIssueRaised:d=!1,compact:f=!1})=>{const[p,g]=e(!1),[m,w]=e(null),[v,B]=e(!1),[b,y]=e(!1);A(()=>{d&&y(!0)},[d]),A(()=>{y(!1)},[null==n?void 0:n.id]);const C=t=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[t]||t),x=r(()=>tt(void 0,void 0,void 0,function*(){if(d||b){if(m)return void g(!0);B(!0);try{w(null),g(!0)}catch(t){console.error("Error fetching issue:",t),$.showError("Failed to load issue details")}finally{B(!1)}}else w(null),g(!0)}),[d,b,o,t,m]),F=r(()=>{g(!1),d||b||w(null)},[d,b]),Q=r(t=>{g(!1),w(t||null),y(!0),h&&(null==n?void 0:n.id)&&h(n.id)},[h,n]);return d||b?X.jsx(X.Fragment,{children:p&&X.jsx(rt,{isOpen:p,onClose:F,onSuccess:Q,component:t,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,notes:"",attachments:null,issue:m})}):f?X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[X.jsx("div",{className:"threshold-alert-border"}),X.jsxs("div",{className:"threshold-alert-content-compact",children:[X.jsx(s,{className:"threshold-alert-icon-compact",size:14}),X.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${C(n.operator)} ${a}`}),X.jsx("button",{type:"button",onClick:x,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),p&&X.jsx(rt,{isOpen:p,onClose:F,onSuccess:Q,component:t,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,notes:"",attachments:null,issue:m})]}):X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[X.jsx("div",{className:"threshold-alert-border"}),X.jsxs("div",{className:"threshold-alert-content",children:[X.jsx("div",{className:"threshold-alert-header",children:X.jsxs("div",{className:"threshold-alert-title-group",children:[X.jsx(s,{className:"threshold-alert-icon",size:20}),X.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),X.jsxs("div",{className:"threshold-alert-message",children:[(()=>{var e;const A=C(n.operator);return`${(null===(e=t.basic)||void 0===e?void 0:e.label)||"Value"}: Value ${i} exceeds threshold ${A} ${a}`})(),X.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),X.jsx("div",{className:"threshold-alert-buttons",children:X.jsx("button",{type:"button",onClick:x,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),p&&X.jsx(rt,{isOpen:p,onClose:F,onSuccess:Q,component:t,formTemplateId:o,workOrderNumber:l,assetNumber:c,user:u,notes:"",attachments:null,issue:m})]})},it=({id:t,properties:s,validationErrors:a={},formValue:o="",inputType:l="text",readonly:c=!1,disabled:u=!1,touchedFields:h={},formSubmitted:d=!1,mode:f="test",onValueChange:p,onBlur:g,onFocus:m,className:w="",hideLabel:v=!1,formTemplateId:B,onThresholdIssueRaised:b,raisedThresholdIssues:y=new Set,workOrderNumber:C,assetNumber:x,user:F})=>{var Q,U,E,N,S;const L=t=>null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):"object"==typeof t?Array.isArray(t)?"":"value"in t?L(t.value):"label"in t?L(t.label):"":String(t||""),I=n(t),_=n(null);A(()=>{t!==I.current&&(console.warn(`[DfFormInput] Component ID changed from ${I.current} to ${t}`),I.current=t)},[t]);const O=L(o||(null===(Q=null==s?void 0:s.basic)||void 0===Q?void 0:Q.defaultValue)||""),[k,T]=e(O),[j,H]=e(!1),[P,D]=e(!1),[M,R]=e(new Set),[K,V]=e(O),z=()=>{if(l)return l;const t=null==s?void 0:s.name;return"text-input"===t?"text":"number-input"===t?"number":"email-input"===t?"email":"text"},G=r(t=>{const e=(()=>{var t;const e={};if((null===(t=null==s?void 0:s.validation)||void 0===t?void 0:t.required)&&(e.required=!0),"email"===z()&&(e.email=!0),"text"===z()){const t=s.validation;(null==t?void 0:t.minLength)&&(e.minLength=t.minLength),(null==t?void 0:t.maxLength)&&(e.maxLength=t.maxLength)}if("number"===z()){const t=s.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})(),A={};let r=!0;const n="string"==typeof t?t:null!=t?String(t):"";if(!e.required||n&&""!==n.trim()||(A.required=!0,r=!1),e.email&&n&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)&&(A.email=!0,r=!1),e.minLength&&n&&n.length<e.minLength&&(A.minLength=!0,r=!1),e.maxLength&&n&&n.length>e.maxLength&&(A.maxLength=!0,r=!1),"number"===z())if(delete A.pattern,delete A.min,delete A.max,n&&""!==n.trim()){const t=n.trim(),i=parseFloat(t);isNaN(i)||("lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&i<e.lowerLimit&&(A.lowerLimit=!0,r=!1),"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&i>e.upperLimit&&(A.upperLimit=!0,r=!1))}else delete A.lowerLimit,delete A.upperLimit;return{isValid:r,errors:A}},[s,z]),q=r(e=>{const A="string"==typeof e?e:null!=e?String(e):"";if(T(A),p){const e=G(A),r=I.current,n={id:r,value:A,isValid:e.isValid,errors:e.errors};r!==t&&console.error(`[DfFormInput] ID mismatch in handleValueChange! ref: ${r}, prop: ${t}`),p(n)}},[t,p,G,I]);A(()=>{j&&(h[t]=!0)},[j,t,h]),A(()=>{var t;if("edit"===f){H(!1);const e=(null===(t=null==s?void 0:s.basic)||void 0===t?void 0:t.defaultValue)||"";T(e)}else"test"===f&&(H(!1),T(""))},[f,null===(U=null==s?void 0:s.basic)||void 0===U?void 0:U.defaultValue]),A(()=>{var e;const A=I.current,r=L(o||(null===(e=null==s?void 0:s.basic)||void 0===e?void 0:e.defaultValue)||"");r===k||P||""===r&&""!==String(k||"").trim()?""===r&&String(k||"").trim():null!=o&&(A===t?T(r):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${A}, prop id: ${t}`))},[o,k,P,null===(E=null==s?void 0:s.basic)||void 0===E?void 0:E.defaultValue,t]),A(()=>{d&&H(!0)},[d]),A(()=>{"test"!==f&&T("")},[f]);const W=r((t,e)=>{if(!e||""===e)return!1;const A="string"==typeof e?parseFloat(e):e,r="string"==typeof t.value?parseFloat(t.value):t.value;if(isNaN(A)||isNaN(r))return!1;switch(t.operator){case"greaterThan":return A>r;case"lessThan":return A<r;case"greaterThanOrEqual":return A>=r;case"lessThanOrEqual":return A<=r;case"equals":return A===r;case"notEquals":return A!==r;default:return!1}},[]),Y=i(()=>{var t;return(null===(t=null==s?void 0:s.condition)||void 0===t?void 0:t.conditions)||[]},[null==s?void 0:s.condition]);A(()=>{k!==K&&(R(new Set),V(k))},[k,K]);const J=i(()=>{if("test"!==f||!k||""===k)return null;const t=Y.filter(t=>W(t,k));if(0===t.length)return null;for(const e of t)if(!M.has(e.id))return e;return null},[k,Y,M,f,W,y]),$=r(t=>{R(e=>new Set(e).add(t))},[]),tt=z(),et=u||c||(null===(N=null==s?void 0:s.validation)||void 0===N?void 0:N.readonly);return X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==s?void 0:s.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!v&&s.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[s.basic.label,s.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",ref:_,children:[X.jsx("input",{type:tt,id:t,value:k,onChange:t=>{const e=t.target.value;q(e)},onFocus:()=>{D(!0),m&&m()},onBlur:()=>{if(D(!1),H(!0),"test"===f&&p){const e="string"==typeof k?k:null!=k?String(k):"",A=G(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};p(r)}g&&g()},placeholder:s.basic.placeholder,disabled:et,readOnly:c||(null===(S=null==s?void 0:s.validation)||void 0===S?void 0:S.readonly),className:(()=>{const e="form-control";if("test"===f){const A="string"==typeof k?k:null!=k?String(k):"",r=G(A);if(r.isValid)return`${e} ${w}`.trim();const n=!r.isValid&&j,i=a[t]&&(j||d)&&!r;return`${e} ${n||i?"is-invalid":""} ${w}`.trim()}return`${e} ${w}`.trim()})()}),X.jsx(Z,{validationErrors:a,fieldId:t,touchedFields:h,formSubmitted:d,properties:s,localValidation:G(k),isTouched:j,mode:f})]})]}),J&&"test"===f&&(()=>{var t,e,A,r;const n=(null==y?void 0:y.has(J.id))||!1,i=null!==(null===(t=_.current)||void 0===t?void 0:t.closest(".table-cell"))||null!==(null===(e=_.current)||void 0===e?void 0:e.closest(".cell-content"))||null!==(null===(A=_.current)||void 0===A?void 0:A.closest(".datagrid-table-view"))||null!==(null===(r=_.current)||void 0===r?void 0:r.closest(".datagrid-list-view"))||w.includes("table-cell")||w.includes("cell-content");return X.jsx(nt,{component:s,condition:J,currentValue:k,thresholdValue:J.value,formTemplateId:B,workOrderNumber:C,assetNumber:x,user:F,onDismiss:()=>$(J.id),onIssueRaised:b,isIssueRaised:n,compact:i},`${J.id}-${n}`)})()]})},st=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v;const[B,b]=e(s),[y,C]=e(!1),x=r(t=>{var e,A,r;const i={};let s=!0;return!(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(i.required=!0,s=!1),(null===(A=null==n?void 0:n.validation)||void 0===A?void 0:A.minLength)&&t&&t.length<n.validation.minLength&&(i.minLength=!0,s=!1),(null===(r=null==n?void 0:n.validation)||void 0===r?void 0:r.maxLength)&&t&&t.length>n.validation.maxLength&&(i.maxLength=!0,s=!1),{isValid:s,errors:i}},[n]),F=r(e=>{if(b(e),h){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,x]);A(()=>{y&&(l[t]=!0)},[y,t,l]),A(()=>{""===B&&""!==s&&b(s)},[s]),A(()=>{c&&C(!0)},[c]),A(()=>{"test"!==u&&b("")},[u]);const Q=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly),U=(null===(w=null==n?void 0:n.validation)||void 0===w?void 0:w.rows)||4;return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&n.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("textarea",{id:t,value:B,onChange:t=>{const e=t.target.value;F(e)},onFocus:()=>{f&&f()},onBlur:()=>{C(!0),d&&d()},placeholder:n.basic.placeholder,disabled:Q,readOnly:a||(null===(v=null==n?void 0:n.validation)||void 0===v?void 0:v.readonly),rows:U,className:`form-textarea ${!x(B).isValid&&y?"is-invalid":""} ${p}`.trim()}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(B),isTouched:y,mode:u})]})]})},at=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w;const[v,B]=e(s),[b,y]=e(!1),C=(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.multiple)||!1,x=r(t=>{var e;const A={};let r=!0;return(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)&&(C?Array.isArray(t)&&0!==t.length||(A.required=!0,r=!1):(!t||"string"==typeof t&&""===t.trim())&&(A.required=!0,r=!1)),{isValid:r,errors:A}},[n,C]),F=r(e=>{if(B(e),h){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,x]);A(()=>{b&&(l[t]=!0)},[b,t,l]),A(()=>{JSON.stringify(s)!==JSON.stringify(v)&&B(s)},[s,v]),A(()=>{c&&y(!0)},[c]);const Q=o||a||(null===(w=null==n?void 0:n.validation)||void 0===w?void 0:w.readonly);return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&n.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsxs("select",{id:t,value:v,onChange:t=>{if(C){const e=Array.from(t.target.selectedOptions,t=>t.value);F(e)}else F(t.target.value)},onFocus:()=>{f&&f()},onBlur:()=>{y(!0),d&&d()},disabled:Q,multiple:C,className:`form-select ${!x(v).isValid&&b?"is-invalid":""} ${p}`.trim(),children:[!C&&X.jsx("option",{value:"",children:n.basic.placeholder||"Select an option"}),(n.options||[]).map((t,e)=>X.jsx("option",{value:t.value,disabled:t.disabled,children:t.label},e))]}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(v),isTouched:b,mode:u})]})]})},ot=({id:t,properties:n,validationErrors:i={},formValue:s=[],readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v;const[B,b]=e(!1),y=Array.isArray(s)?s:[],C=r(t=>{var e;const A={};let r=!0;return(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)&&0===t.length&&(A.required=!0,r=!1),{isValid:r,errors:A}},[n]),x=r(e=>{if(h){const A=C(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,C,y]),F=(t,e)=>{let A;A=e?[...y,t]:y.filter(e=>e!==t),x(A)},Q=()=>{f&&f()},U=()=>{b(!0),d&&d()};A(()=>{B&&(l[t]=!0)},[B,t,l]),A(()=>{},[s,t,y]),A(()=>{c&&b(!0)},[c]);const E=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly);return X.jsx(X.Fragment,{children:X.jsx("div",{className:`form-group checkbox-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var t;return(null===(t=null==n?void 0:n.basic)||void 0===t?void 0:t.inlineLayout)?"inline-layout":"vertical-layout"})()} ${p}`,children:!g&&n.basic.label?X.jsxs(X.Fragment,{children:[X.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(w=null==n?void 0:n.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"checkbox",id:`${t}-${A}`,name:t,value:e.value,checked:y.includes(e.value),onChange:t=>{F(e.value,t.target.checked)},onFocus:Q,onBlur:U,disabled:E||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:C(y),isTouched:B,mode:u})]})]}):X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(v=null==n?void 0:n.basic)||void 0===v?void 0:v.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"checkbox",id:`${t}-${A}`,name:t,value:e.value,checked:y.includes(e.value),onChange:t=>{F(e.value,t.target.checked)},onFocus:Q,onBlur:U,disabled:E||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:C(y),isTouched:B,mode:u})]})})})},lt=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v;const[B,b]=e(s),[y,C]=e(!1),x=r(t=>{var e;const A={};let r=!0;return!(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(A.required=!0,r=!1),{isValid:r,errors:A}},[n]),F=r(e=>{if(b(e),h){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,x]),Q=t=>{F(t)},U=()=>{f&&f()},E=()=>{C(!0),d&&d()};A(()=>{y&&(l[t]=!0)},[y,t,l]),A(()=>{s!==B&&b(s)},[s,B]),A(()=>{c&&C(!0)},[c]);const N=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly);return X.jsx(X.Fragment,{children:X.jsx("div",{className:`form-group radio-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var t;return(null===(t=null==n?void 0:n.basic)||void 0===t?void 0:t.inlineLayout)?"inline-layout":"vertical-layout"})()} ${p}`,children:!g&&n.basic.label?X.jsxs(X.Fragment,{children:[X.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(w=null==n?void 0:n.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"radio",id:`${t}-${A}`,name:t,value:e.value,checked:B===e.value,onChange:()=>Q(e.value),onFocus:U,onBlur:E,disabled:N||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(B),isTouched:y,mode:u})]})]}):X.jsxs("div",{className:"input-wrapper",children:[X.jsx("div",{className:"mt-2 "+((null===(v=null==n?void 0:n.basic)||void 0===v?void 0:v.inlineLayout)?"inline-options-grid":"space-y-2"),children:(n.options||[]).map((e,A)=>X.jsxs("div",{className:"form-check",children:[X.jsx("input",{type:"radio",id:`${t}-${A}`,name:t,value:e.value,checked:B===e.value,onChange:()=>Q(e.value),onFocus:U,onBlur:E,disabled:N||e.disabled,className:"form-check-input"}),X.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:x(B),isTouched:y,mode:u})]})})})},ct=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m;const[w,v]=e(s),[B,b]=e(!1),y=r(t=>{var e;const A={};let r=!0;return!(null===(e=null==n?void 0:n.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(A.required=!0,r=!1),{isValid:r,errors:A}},[n]),C=r(e=>{if(v(e),b(!0),h){const A=y(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,y]),x=()=>{f&&f()},F=()=>{b(!0),d&&d()};A(()=>{B&&(l[t]=!0)},[B,t,l]),A(()=>{s!==w&&v(s)},[s,w]),A(()=>{c&&b(!0)},[c]);const Q=()=>{var t;return(null===(t=null==n?void 0:n.basic)||void 0===t?void 0:t.inlineLayout)?"inline-layout":"grid-layout"},U=t=>{const e=null==t?void 0:t.toLowerCase();return"pass"===e||"yes"===e?"pass":"fail"===e||"no"===e?"fail":"pass"},E=t=>{if(void 0!==(null==t?void 0:t.icon)&&""!==t.icon)return t.icon;return"pass"===U((null==t?void 0:t.value)||t)?"✓":"×"},N=(t,e)=>(null==t?void 0:t.color)||(null==t?void 0:t.backgroundColor)?{color:e?"#ffffff":t.color||"#00814b",backgroundColor:e?t.color||"#00814b":t.backgroundColor||"#34bd4914",borderColor:t.color||"#00814b"}:{},S=t=>{if((null==t?void 0:t.color)||(null==t?void 0:t.backgroundColor))return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===U((null==t?void 0:t.value)||t)?"pass-button":"fail-button")},L=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly);return X.jsxs(X.Fragment,{children:[X.jsx("div",{className:`form-group segment-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()} ${p}`,children:!g&&n.basic.label?X.jsxs(X.Fragment,{children:[X.jsxs("label",{className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsx("div",{className:"form-segment-wrapper",children:X.jsx("div",{className:`form-segment-container ${Q()}`,children:(n.options||[]).map((e,A)=>{const r=w===e.value,n=N(e,r),i=S(e),s=E(e);return X.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[X.jsx("input",{type:"radio",id:`${t}_option_${A}`,name:t,value:e.value,checked:r,onChange:()=>!L&&!e.disabled&&C(e.value),onFocus:x,onBlur:F,disabled:L||e.disabled,className:"form-segment-radio"}),X.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&X.jsx("span",{className:"segment-icon",children:s}),X.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})]}):X.jsx("div",{className:"form-segment-wrapper",children:X.jsx("div",{className:`form-segment-container ${Q()}`,children:(n.options||[]).map((e,A)=>{const r=w===e.value,n=N(e,r),i=S(e),s=E(e);return X.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[X.jsx("input",{type:"radio",id:`${t}_option_${A}`,name:t,value:e.value,checked:r,onChange:()=>!L&&!e.disabled&&C(e.value),onFocus:x,onBlur:F,disabled:L||e.disabled,className:"form-segment-radio"}),X.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&X.jsx("span",{className:"segment-icon",children:s}),X.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:y(w),isTouched:B,mode:u})]})},ut=({id:t,properties:n,validationErrors:i={},formValue:s="",readonly:a=!1,disabled:o=!1,touchedFields:l={},formSubmitted:c=!1,mode:u="preview",onValueChange:h,onBlur:d,onFocus:f,className:p="",hideLabel:g=!1})=>{var m,w,v,B,b;const y=r(t=>{var e,A;if(!t)return"";if("string"==typeof t){if(/^\d{4}-\d{2}-\d{2}$/.test(t))return t;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return t;const A=et(t);if(A&&!isNaN(A.getTime())){const t=n.name||"",r=(null===(e=n.basic)||void 0===e?void 0:e.dateTimeMode)||("datetime-picker"===t?"datetime":"date");if("datetime"===r){return`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")}T${String(A.getHours()).padStart(2,"0")}:${String(A.getMinutes()).padStart(2,"0")}`}if("time"===r){return`${String(A.getHours()).padStart(2,"0")}:${String(A.getMinutes()).padStart(2,"0")}`}return`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")}`}return t}if(t instanceof Date){if(isNaN(t.getTime()))return"";const e=n.name||"",r=(null===(A=n.basic)||void 0===A?void 0:A.dateTimeMode)||("datetime-picker"===e?"datetime":"date");if("datetime"===r){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"===r){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")}`}if("object"==typeof t&&null!==t){if("value"in t&&t.value)return y(t.value);if("date"in t&&t.date)return y(t.date);try{const e=String(t),A=et(e);if(A&&!isNaN(A.getTime()))return y(A)}catch(t){}return""}return""},[n]),C=y(s),[x,F]=e(C),[Q,U]=e(!1),[E,N]=e(!1),S=r(t=>{var e,A,r,i,s,a;const o={};let l=!0;const c=n.name||"",u=(null===(e=n.basic)||void 0===e?void 0:e.dateTimeMode)||("datetime-picker"===c?"datetime":"date"),h=t?String(t).trim():"";if((null===(A=null==n?void 0:n.validation)||void 0===A?void 0:A.required)&&(!h||""===h))return o.required=!0,l=!1,{isValid:l,errors:o};if(h&&""!==h)if("time"===u){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(h))return o.invalidDate=!0,l=!1,{isValid:l,errors:o}}else if("datetime"===u){const t=et(h);if(!t||isNaN(t.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(r=null==n?void 0:n.validation)||void 0===r?void 0:r.minDate){const e=et(n.validation.minDate);e&&t<e&&(o.minDate=!0,o.minDateMessage=`Date and time must be on or after ${e.toLocaleDateString()}`,l=!1)}if(null===(i=null==n?void 0:n.validation)||void 0===i?void 0:i.maxDate){const e=et(n.validation.maxDate);e&&t>e&&(o.maxDate=!0,o.maxDateMessage=`Date and time must be on or before ${e.toLocaleDateString()}`,l=!1)}}else{const t=et(h);if(!t||isNaN(t.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(s=null==n?void 0:n.validation)||void 0===s?void 0:s.minDate){const e=et(n.validation.minDate);e&&t<e&&(o.minDate=!0,o.minDateMessage=`Date must be on or after ${e.toLocaleDateString()}`,l=!1)}if(null===(a=null==n?void 0:n.validation)||void 0===a?void 0:a.maxDate){const e=et(n.validation.maxDate);e&&t>e&&(o.maxDate=!0,o.maxDateMessage=`Date must be on or before ${e.toLocaleDateString()}`,l=!1)}}return{isValid:l,errors:o}},[n]),L=r(e=>{if(F(e),h){const A=S(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};h(r)}},[t,h,S]);A(()=>{Q&&(l[t]=!0)},[Q,t,l]),A(()=>{const t=y(s);t===x||E||F(t)},[s,x,E,y]),A(()=>{c&&U(!0)},[c]);const I=o||a||(null===(m=null==n?void 0:n.validation)||void 0===m?void 0:m.readonly),_=n.name||"",O=(null===(w=n.basic)||void 0===w?void 0:w.dateTimeMode)||("datetime-picker"===_?"datetime":"date"),k=(()=>{switch(O){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==n?void 0:n.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&n.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[n.basic.label,n.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsx("input",{type:k,id:t,value:x,onChange:t=>{const e=t.target.value;L(e)},onFocus:()=>{N(!0),f&&f()},onBlur:()=>{if(N(!1),U(!0),h){const e=S(x),A={id:t,value:x,isValid:e.isValid,errors:e.errors};h(A)}d&&d()},disabled:I,readOnly:a||(null===(v=null==n?void 0:n.validation)||void 0===v?void 0:v.readonly),min:null===(B=null==n?void 0:n.validation)||void 0===B?void 0:B.minDate,max:null===(b=null==n?void 0:n.validation)||void 0===b?void 0:b.maxDate,className:`form-date ${!S(x).isValid&&Q?"is-invalid":""} ${p}`.trim()}),X.jsx(Z,{validationErrors:i,fieldId:t,touchedFields:l,formSubmitted:c,properties:n,localValidation:S(x),isTouched:Q,mode:u})]})]})},ht=({id:t,properties:i,validationErrors:s={},formValue:a="",readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:u=!1,mode:h="preview",onValueChange:d,onBlur:f,onFocus:p,className:g="",hideLabel:m=!1})=>{var w;const v=n(null),[B,b]=e(!1),[y,C]=e(!1),[x,F]=e(a),[Q,U]=e(!1),E=r(t=>{var e;const A={};let r=!0;return!(null===(e=null==i?void 0:i.validation)||void 0===e?void 0:e.required)||t&&""!==t.trim()||(A.required=!0,r=!1),{isValid:r,errors:A}},[i]),N=r(e=>{if(F(e),d){const A=E(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};d(r)}},[t,d,E]),S=r(()=>{const t=document.documentElement.classList.contains("dark")||"dark"===document.documentElement.getAttribute("data-theme");let e=getComputedStyle(document.documentElement).getPropertyValue("--df-color-fb-input-bg").trim();e||(e=t?"#2c2e34":"#ffffff");return{strokeColor:t?"#ffffff":"#000000",backgroundColor:e}},[]),L=r(e=>{if(!e)return;const A=v.current;if(!A)return;const r=A.getContext("2d");if(!r)return;const n=new Image;n.onload=()=>{r.clearRect(0,0,A.width,A.height);const t=S();r.fillStyle=t.backgroundColor,r.fillRect(0,0,A.width,A.height);const e=A.width/A.height,i=n.width/n.height;let s=A.width,a=A.height,o=0,l=0;i>e?(a=A.width/i,l=(A.height-a)/2):(s=A.height*i,o=(A.width-s)/2),r.drawImage(n,o,l,s,a)},n.onerror=A=>{console.error("DfFormSignature: error loading image",{id:t,error:A,dataURL:e.substring(0,50)+"..."})},n.src=e},[S,t]),I=r(()=>{const t=v.current;if(!t)return;const e=t.getContext("2d");if(!e)return;const A=t.getBoundingClientRect();t.width=A.width,t.height=A.height,t.style.width=A.width+"px",t.style.height=A.height+"px";const r=S();e.strokeStyle=r.strokeColor,e.lineWidth=2,e.lineCap="round",e.lineJoin="round",x?L(x):(e.fillStyle=r.backgroundColor,e.fillRect(0,0,t.width,t.height))},[x,S,L]),_=r(()=>{setTimeout(()=>{I()},100)},[I]);A(()=>{const t=()=>{_()},e=new MutationObserver(t=>{t.forEach(t=>{if("attributes"===t.type&&"class"===t.attributeName){const e=t.target;e.classList.contains("form-canvas-container")&&(e.classList.contains("mobile-view")||e.classList.contains("tablet-view")||e.classList.contains("desktop-view"))&&_()}})});return e.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",t),()=>{e.disconnect(),window.removeEventListener("resize",t)}},[_]);const O=r(t=>{const e=v.current;if(!e)return{x:0,y:0};const A=e.getBoundingClientRect(),r=e.width/A.width,n=e.height/A.height,i=t.type.includes("mouse")?t.clientX:t.touches[0].clientX,s=t.type.includes("mouse")?t.clientY:t.touches[0].clientY;return{x:(i-A.left)*r,y:(s-A.top)*n}},[]),k=t=>{var e;if(o||l||(null===(e=null==i?void 0:i.validation)||void 0===e?void 0:e.readonly))return;if(t.target.closest(".clear-signature-btn"))return;t.preventDefault(),t.stopPropagation(),b(!0),C(!0);const A=v.current;if(!A)return;const r=A.getContext("2d");if(!r)return;const{x:n,y:s}=O(t),a=S();r.strokeStyle=a.strokeColor,r.lineWidth=2,r.lineCap="round",r.lineJoin="round",r.beginPath(),r.moveTo(n,s)},T=t=>{if(!B)return;t.preventDefault(),t.stopPropagation();const e=v.current;if(!e)return;const A=e.getContext("2d");if(!A)return;const{x:r,y:n}=O(t);A.lineTo(r,n),A.stroke()},j=()=>{if(!B)return;b(!1),U(!0);const t=v.current;if(t){(t=>{const e=t.getContext("2d");if(!e)return!1;const A=e.getImageData(0,0,t.width,t.height).data;for(let t=0;t<A.length;t+=4){const e=A[t],r=A[t+1],n=A[t+2];if(A[t+3]>0&&(e<255||r<255||n<255))return!0}})(t);const e=t.toDataURL("image/png");F(e),N(e),setTimeout(()=>{U(!1)},100)}else U(!1)},H=r(()=>{const t=v.current;if(!t)return;const e=t.getContext("2d");if(!e)return;const A=S();if(e.strokeStyle=A.strokeColor,x){const r=x,n=t.getBoundingClientRect();e.fillStyle=A.backgroundColor,e.fillRect(0,0,n.width,n.height),r&&L(r)}else{const r=t.getBoundingClientRect();e.fillStyle=A.backgroundColor,e.fillRect(0,0,r.width,r.height)}},[S,x,L]);A(()=>{const t=new MutationObserver(t=>{t.forEach(t=>{"attributes"!==t.type||"class"!==t.attributeName&&"data-theme"!==t.attributeName||H()})});return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{t.disconnect()}},[H]);A(()=>{y&&(c[t]=!0)},[y,t,c]),A(()=>{if(!(a===x||B||Q||""!==x&&""===a)){if(a===x)return;F(a),a&&L(a)}},[a,x,B,Q]),A(()=>{u&&C(!0)},[u]),A(()=>{if("test"!==h){F("");const t=v.current;if(t){const e=t.getContext("2d");if(e){const A=t.getBoundingClientRect();t.width=A.width,t.height=A.height;const r=S();e.fillStyle=r.backgroundColor,e.fillRect(0,0,A.width,A.height)}}}},[h]),A(()=>{I()},[h]);const P=l||o||(null===(w=null==i?void 0:i.validation)||void 0===w?void 0:w.readonly);return X.jsxs("div",{className:`form-group ${(()=>{var t;return"left"===(null===(t=null==i?void 0:i.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"})()}`,children:[!m&&i.basic.label&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[i.basic.label,i.validation.required&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"input-wrapper",children:[X.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[X.jsx("canvas",{ref:v,id:t,className:`form-signature ${!E(x).isValid&&y?"is-invalid":""} ${g}`.trim(),onMouseDown:k,onMouseMove:T,onMouseUp:j,onMouseLeave:j,onTouchStart:k,onTouchMove:T,onTouchEnd:j,onFocus:()=>{p&&p()},onBlur:()=>{f&&f()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:P?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!P&&X.jsx("button",{type:"button",onClick:t=>(t=>{null==t||t.preventDefault(),null==t||t.stopPropagation();const e=v.current;if(!e)return;const A=e.getBoundingClientRect();e.width=A.width,e.height=A.height;const r=e.getContext("2d");if(!r)return;const n=S();r.fillStyle=n.backgroundColor,r.fillRect(0,0,A.width,A.height),r.strokeStyle=n.strokeColor,r.lineWidth=2,r.lineCap="round",r.lineJoin="round",F(""),N("")})(t),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:t=>{t.currentTarget.style.backgroundColor="var(--df-color-error-dark, #dc2626)",t.currentTarget.style.transform="scale(1.05)"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="var(--df-color-error-primary)",t.currentTarget.style.transform="scale(1)"},children:"Clear"})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:c,formSubmitted:u,properties:i,localValidation:E(x),isTouched:y,mode:h})]})]})},dt=({id:t,properties:i,validationErrors:s={},formValue:a=null,readonly:o=!1,disabled:l=!1,touchedFields:c={},formSubmitted:u=!1,mode:h="test",onValueChange:d,onBlur:f,onFocus:p,className:g="",hideLabel:m=!1})=>{var w,v,B,b,y,C,x,F;const[Q,U]=e([]),[E,N]=e(!1),[S,L]=e(!1),I=n(null),_=r(e=>{if(!e)return[];const A=Array.isArray(e)?e:Array.from(e),r=[];return A.forEach((e,A)=>{if(e&&"object"==typeof e&&!(e instanceof File)&&!(e instanceof Blob)){const n=e;if(n.data||n.url||n.name&&n.type){const e=n.name||n.fileName||`file-${A}`,i=n.size||n.fileSize||0,s=n.type||n.fileType||n.mimeType||"";let a;if(n.url)a=n.url;else if(n.data){const t=n.data;if("string"==typeof t)if(t.startsWith("data:"))a=t;else{const e=t.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(e)&&e.length>10){let t=s;t||(t=e.startsWith("/9j/")||e.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":e.startsWith("iVBORw0KGgo")?"image/png":e.startsWith("R0lGOD")?"image/gif":e.startsWith("UklGR")?"image/webp":"image/png"),a=`data:${t};base64,${e}`}else a=t}}const o=new File([],e,{type:s});return void r.push({file:o,id:`${t}-file-${A}`,size:i,type:s,name:e,preview:a})}}let n,i,s=0,a="",o="";if(e instanceof File||e instanceof Blob){const t=e;if(s=t.size||0,a=t.type||"",o=t.name||`file-${A}`,i=t,a.startsWith("image/"))try{n=URL.createObjectURL(t)}catch(t){console.error("Error creating object URL:",t),n=void 0}}else if("string"==typeof e){const t=e,r=t.replace(/\s/g,""),s=r.length>50&&/^[A-Za-z0-9+/=]+$/.test(r)&&!t.startsWith("http")&&!t.startsWith("https")&&!t.startsWith("data:")&&!t.startsWith("blob:")&&!t.startsWith("/");let l=t;if(s){let t="image/png";r.startsWith("/9j/")||r.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?t="image/jpeg":r.startsWith("iVBORw0KGgo")?t="image/png":r.startsWith("R0lGOD")?t="image/gif":r.startsWith("UklGR")&&(t="image/webp"),l=`data:${t};base64,${r}`}let c="";if(l.startsWith("data:")){const t=l.match(/filename=([^;]+)/i);if(t)c=decodeURIComponent(t[1]);else{const t=l.match(/data:([^;]+)/);if(t){const e=t[1];c=`file-${A+1}.${e.includes("image")?e.includes("jpeg")?"jpg":"png":e.includes("pdf")?"pdf":e.includes("word")?"doc":e.includes("excel")?"xls":"file"}`}else c=`file-${A+1}`}}else if(l.startsWith("http://")||l.startsWith("https://")||l.startsWith("blob:"))try{const e=new URL(t),r=e.pathname.split("/").pop()||"";if(r&&r.includes("."))c=decodeURIComponent(r);else{const t=e.searchParams.get("filename")||e.searchParams.get("name");c=t?decodeURIComponent(t):`file-${A+1}`}}catch(e){const r=t.lastIndexOf("/"),n=r>=0?t.substring(r+1):t,i=n.indexOf("?"),s=i>=0?n.substring(0,i):n;c=s&&s.includes(".")?decodeURIComponent(s):`file-${A+1}`}else c=`file-${A+1}`;if(o=c||`file-${A+1}`,l.startsWith("data:")){const t=l.indexOf(";");a=t>5?l.substring(5,t):"application/octet-stream"}else{const t=l.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i)||o.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(t){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"}[t[1].toLowerCase()]||"application/octet-stream"}else a=s?"image/png":"application/octet-stream"}(l.startsWith("data:image")||l.startsWith("http://")||l.startsWith("https://")||l.startsWith("blob:"))&&(n=l),i=new File([],o,{type:a})}else{if(!e||"object"!=typeof e)return;{const t=e;if(o=t.name||t.fileName||`file-${A}`,s=t.size||t.fileSize||0,a=t.type||t.fileType||t.mimeType||"",t.url||t.path)n=t.url||t.path;else if(a.startsWith("image/")&&t.data){const e=t.data;if("string"==typeof e)if(e.startsWith("data:"))n=e;else{const t=e.replace(/\s/g,"");n=/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>50?`data:${a};base64,${t}`:e}else n=void 0}i=new File([],o,{type:a})}}r.push({file:i,id:`${t}-file-${A}`,size:s,type:a,name:o,preview:n})}),r},[t]),O=r(()=>({isValid:!0,errors:{}}),[]),k=r(e=>{var A;if(o||l)return;const r=_(e),n=Q.length>0?[...Q,...r]:r,s=(null===(A=null==i?void 0:i.validation)||void 0===A?void 0:A.maxFiles)||1/0,a=n.slice(0,s);if(U(a),L(!0),d){const e=O(),A={id:t,value:a.map(t=>t.file),isValid:e.isValid,errors:e.errors};d(A)}},[Q,i,o,l,d,O,_,t]),T=t=>{if(0===t)return"0 Bytes";const e=Math.floor(Math.log(t)/Math.log(1024));return parseFloat((t/Math.pow(1024,e)).toFixed(2))+" "+["Bytes","KB","MB","GB"][e]},j=t=>t.startsWith("image/")?"🖼️":t.startsWith("video/")?"🎥":t.startsWith("audio/")?"🎵":t.includes("pdf")?"📄":t.includes("word")||t.includes("document")?"📝":t.includes("excel")||t.includes("spreadsheet")?"📊":t.includes("zip")||t.includes("rar")?"📦":"📁";A(()=>{S&&(c[t]=!0)},[S,t,c]),A(()=>{("edit"===h||"test"===h)&&L(!1)},[h]),A(()=>{const t=_(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===Q.length&&null!=a?U(t):(null==a||Array.isArray(a)&&0===a.length)&&Q.length>0&&U([])},[a,_,Q.length]),A(()=>{u&&L(!0)},[u]),A(()=>()=>{Q.forEach(t=>{if(t.preview&&t.preview.startsWith("blob:"))try{URL.revokeObjectURL(t.preview)}catch(t){console.error("Error revoking object URL:",t)}})},[Q]);const H=()=>{var t;return"left"===(null===(t=null==i?void 0:i.styles)||void 0===t?void 0:t.labelAlignment)?"label-left":"label-top"},P=l||o||(null===(w=null==i?void 0:i.validation)||void 0===w?void 0:w.readonly),D=(null===(v=null==i?void 0:i.validation)||void 0===v?void 0:v.multiple)||!1,M=(null===(B=null==i?void 0:i.validation)||void 0===B?void 0:B.accept)||"*/*",R=(null===(b=null==i?void 0:i.validation)||void 0===b?void 0:b.maxFiles)||1/0,K=Q.length<R&&(D||R>1),V="edit"===h,z="preview"===h||"test"===h,G=Q.filter(t=>t.type.startsWith("image/")),q=Q.filter(t=>!t.type.startsWith("image/")),W=G.length>0;return z&&W?X.jsxs("div",{className:`form-group ${H()}`,children:[!m&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(y=i.basic)||void 0===y?void 0:y.label)||"Attachments",(null===(C=i.validation)||void 0===C?void 0:C.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"file-upload-wrapper",children:[X.jsxs("div",{className:"file-image-display",children:[G.map(t=>X.jsxs("div",{className:"file-image-container",children:[t.preview&&X.jsx("img",{src:t.preview,alt:t.name,className:"file-image-preview"}),X.jsxs("div",{className:"file-image-info",children:[X.jsx("div",{className:"file-name",title:t.name,children:t.name}),X.jsx("div",{className:"file-size",children:T(t.size)})]})]},t.id)),q.length>0&&X.jsxs("div",{className:"file-other-files",children:[X.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),q.map(t=>X.jsxs("div",{className:"file-item-minimal",children:[X.jsx("div",{className:"file-icon",children:j(t.type)}),X.jsxs("div",{className:"file-info",children:[X.jsx("div",{className:"file-name",title:t.name,children:t.name}),X.jsx("div",{className:"file-size",children:T(t.size)})]})]},t.id))]})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:c,formSubmitted:u,properties:i,localValidation:O(),isTouched:S,mode:h})]})]}):X.jsxs("div",{className:`form-group ${H()}`,children:[!m&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(x=i.basic)||void 0===x?void 0:x.label)||"Attachments",(null===(F=i.validation)||void 0===F?void 0:F.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]}),X.jsxs("div",{className:"file-upload-wrapper",children:[X.jsxs("div",{className:`file-upload-area ${E?"drag-over":""} ${o?"readonly":""} ${l?"disabled":""} ${g}`.trim(),onDragOver:t=>{t.preventDefault(),o||l||N(!0)},onDragLeave:t=>{t.preventDefault(),N(!1)},onDrop:t=>{if(t.preventDefault(),N(!1),o||l)return;const e=t.dataTransfer.files;e.length>0&&k(e)},onClick:t=>{var e;const A=t.target,r=null!==A.closest(".file-item"),n=null!==A.closest(".file-remove");!V||P||0!==Q.length||r||n||null===(e=I.current)||void 0===e||e.click()},onFocus:()=>{p&&p()},onBlur:()=>{if(L(!0),"test"===h&&d){const e=O(),A={id:t,value:Q.map(t=>t.file),isValid:e.isValid,errors:e.errors};d(A)}f&&f()},tabIndex:P?-1:0,children:[X.jsx("input",{ref:I,type:"file",id:t,multiple:D,accept:M,onChange:t=>{const e=t.target.files;e&&e.length>0&&(k(e),t.target.value="")},disabled:P,style:{display:"none"}}),0===Q.length?X.jsxs("div",{className:"upload-placeholder",onClick:t=>{var e;t.stopPropagation(),V&&!P&&(null===(e=I.current)||void 0===e||e.click())},children:[X.jsx("div",{className:"upload-icon",children:"📁"}),X.jsx("div",{className:"upload-text",children:i.basic.placeholder&&X.jsx("p",{className:"upload-hint",children:i.basic.placeholder})})]}):X.jsx("div",{className:"file-list",children:Q.map(e=>X.jsxs("div",{className:"file-item",children:[X.jsx("div",{className:"file-preview",children:e.preview?X.jsx("img",{src:e.preview,alt:e.name,className:"file-image"}):X.jsx("div",{className:"file-icon",children:j(e.type)})}),X.jsxs("div",{className:"file-info",children:[X.jsx("div",{className:"file-name",title:e.name,children:e.name}),X.jsx("div",{className:"file-size",children:T(e.size)})]}),V&&!P&&X.jsx("button",{type:"button",className:"file-remove",onClick:A=>{A.stopPropagation(),(e=>{if(o||l)return;const A=Q.filter(t=>t.id!==e);if(U(A),L(!0),d){const e=O(),r={id:t,value:A.map(t=>t.file),isValid:e.isValid,errors:e.errors};d(r)}})(e.id)},"aria-label":`Remove ${e.name}`,children:"✕"})]},e.id))})]}),Q.length>0&&K&&!P&&V&&X.jsxs("button",{type:"button",className:"file-add-more",onClick:t=>{t.stopPropagation(),!P&&I.current&&V&&(I.current.value="",I.current.click())},"aria-label":"Add more files",children:[X.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:X.jsx("path",{d:"M12 5v14M5 12h14"})}),X.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:c,formSubmitted:u,properties:i,localValidation:O(),isTouched:S,mode:h})]})]})},ft=({id:t,properties:i,validationErrors:s={},formValue:o=null,readonly:l=!1,disabled:c=!1,touchedFields:u={},formSubmitted:h=!1,mode:g="test",onValueChange:m,onBlur:w,onFocus:v,className:B="",hideLabel:b=!1})=>{var y,C,x,F;const[Q,U]=e(o),[E,N]=e(!1),[S,L]=e(""),[I,_]=e(!1),[O,k]=e(!1),[T,j]=e({lat:40.7128,lng:-74.006}),[H,P]=e(null),[D,M]=e(10),[R,K]=e(""),[V,z]=e(!1),G=n(null),[q,W]=e(!1),[Y,J]=e(null),[$,At]=e(!1);A(()=>{if(o&&o.latitude&&o.longitude){40.7128===o.latitude&&-74.006===o.longitude||(U(o),P({lat:o.latitude,lng:o.longitude,isCurrentLocation:!1}),j({lat:o.latitude,lng:o.longitude}))}else null==o&&(U(null),P(null))},[o]),A(()=>{O&&40.7128===T.lat&&T.lng},[O,T]),A(()=>{(l||c)&&(O&&k(!1),R&&K(""),q&&(W(!1),J(null)))},[l,c]);const rt=r((t,e)=>tt(void 0,void 0,void 0,function*(){At(!0);try{const A=yield fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${t}&lon=${e}&addressdetails=1&zoom=18`),r=yield A.json();if(r&&r.address){const t=r.address;return{placeName:r.display_name||"",city:t.city||t.town||t.village||t.municipality||"",country:t.country||""}}}catch(t){console.error("Reverse geocoding failed:",t)}finally{At(!1)}return{placeName:"",city:"",country:""}}),[]),nt=r((e,A,r)=>tt(void 0,void 0,void 0,function*(){const n=yield rt(e,A),i=Object.assign({latitude:e,longitude:A,timestamp:Date.now(),placeName:n.placeName,city:n.city,country:n.country,address:n.placeName},r);if(U(i),P({lat:e,lng:A,isCurrentLocation:!1}),_(!0),m){m({id:t,value:i,isValid:!0,errors:{}})}}),[rt,t,m]),it=r(()=>tt(void 0,void 0,void 0,function*(){var t,e,A,r,n,s,a,o,u,h,d,f,p,g,m;if(l||c)return;N(!0),L("");if(void 0!==window.Capacitor)try{const{Geolocation:l}=window.Capacitor.Plugins;if(l)try{if("granted"!==(yield l.requestPermissions()).location)return N(!1),void L("Location permission is required. Please enable location access in your device settings.");const a=yield l.getCurrentPosition({enableHighAccuracy:null===(e=null===(t=i.validation)||void 0===t?void 0:t.enableHighAccuracy)||void 0===e||e,timeout:null!==(r=null===(A=i.validation)||void 0===A?void 0:A.timeout)&&void 0!==r?r:1e4,maximumAge:null!==(s=null===(n=i.validation)||void 0===n?void 0:n.maximumAge)&&void 0!==s?s:3e5}),o=a.coords.latitude,c=a.coords.longitude;return P({lat:o,lng:c,isCurrentLocation:!0}),j({lat:o,lng:c}),_(!0),yield nt(o,c,{accuracy:a.coords.accuracy,timestamp:Date.now()}),N(!1),void L("")}catch(t){return N(!1),void((null===(a=t.message)||void 0===a?void 0:a.includes("permission"))||(null===(o=t.message)||void 0===o?void 0:o.includes("denied"))?L("Location permission is required. Please enable location access in your device settings."):(null===(u=t.message)||void 0===u?void 0:u.includes("timeout"))?L("Location request timed out. Please try again."):L("Unable to retrieve your location. Please try again."))}}catch(t){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return N(!1),void L("Geolocation is not supported by this browser.");const w={enableHighAccuracy:null===(d=null===(h=i.validation)||void 0===h?void 0:h.enableHighAccuracy)||void 0===d||d,timeout:null!==(p=null===(f=i.validation)||void 0===f?void 0:f.timeout)&&void 0!==p?p:1e4,maximumAge:null!==(m=null===(g=i.validation)||void 0===g?void 0:g.maximumAge)&&void 0!==m?m:3e5};navigator.geolocation.getCurrentPosition(t=>tt(void 0,void 0,void 0,function*(){const e=t.coords.latitude,A=t.coords.longitude;P({lat:e,lng:A,isCurrentLocation:!0}),j({lat:e,lng:A}),_(!0),yield nt(e,A,{accuracy:t.coords.accuracy,timestamp:t.timestamp}),N(!1),L("")}),t=>{N(!1);let e="Unable to retrieve your location.";switch(t.code){case t.PERMISSION_DENIED:e="Location access denied by user. Please enable location access in your browser/device settings.";break;case t.POSITION_UNAVAILABLE:e="Location information is unavailable.";break;case t.TIMEOUT:e="Location request timed out. Please try again."}L(e)},w)}),[l,c,i,nt]),st=r(()=>{if(!l&&!c&&(U(null),P(null),L(""),_(!0),m)){m({id:t,value:null,isValid:!0,errors:{}})}},[l,c,t,m]),at=r(()=>{l||c||k(!O)},[l,c,O]),ot=r((t,e,A,r,n,i)=>{const s=t-n/2,a=e-i/2,o=156543.03392*Math.cos(A.lat*Math.PI/180)/Math.pow(2,r),l=s*o,c=a*o;return{lat:A.lat+c/111320,lng:A.lng+l/(111320*Math.cos(A.lat*Math.PI/180))}},[]),lt=r(t=>{l||c||!G.current||0===t.button&&(W(!0),J({x:t.clientX,y:t.clientY}),t.preventDefault())},[l,c]),ct=r(t=>{if(!q||!Y||!G.current)return;const e=t.clientX-Y.x,A=t.clientY-Y.y,r=156543.03392*Math.cos(T.lat*Math.PI/180)/Math.pow(2,D),n=-A*r/111320,i=e*r/(111320*Math.cos(T.lat*Math.PI/180));j({lat:T.lat+n,lng:T.lng+i}),J({x:t.clientX,y:t.clientY})},[q,Y,T,D]),ut=r(t=>tt(void 0,void 0,void 0,function*(){if(!G.current)return;if(q&&Y){const e=Math.abs(t.clientX-Y.x),A=Math.abs(t.clientY-Y.y);if(e>5||A>5)return W(!1),void J(null)}if(l||c)return W(!1),void J(null);const e=G.current.getBoundingClientRect(),A=t.clientX-e.left,r=t.clientY-e.top,{lat:n,lng:i}=ot(A,r,T,D,e.width,e.height);yield nt(n,i),W(!1),J(null)}),[l,c,G,T,D,ot,nt,q,Y]),ht=r(e=>tt(void 0,void 0,void 0,function*(){if(e.trim()&&!l&&!c){z(!0),L("");try{const A=yield fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(e)}&limit=5&addressdetails=1`),r=yield A.json();if(r&&r.length>0){const e=r[0],A=parseFloat(e.lat),n=parseFloat(e.lon),i=e.address||{},s={latitude:A,longitude:n,address:e.display_name,placeName:e.display_name,city:i.city||i.town||i.village||i.municipality||"",country:i.country||"",timestamp:Date.now()};if(U(s),P({lat:A,lng:n,isCurrentLocation:!1}),j({lat:A,lng:n}),_(!0),m){m({id:t,value:s,isValid:!0,errors:{}})}}else L("No locations found for your search.")}catch(t){L("Failed to search for location. Please try again.")}finally{z(!1)}}}),[l,c,t,m]),dt=()=>{v&&v()},ft=()=>{_(!0),w&&w()},pt=c||l||(null===(y=null==i?void 0:i.validation)||void 0===y?void 0:y.readonly),gt=(null===(C=null==i?void 0:i.basic)||void 0===C?void 0:C.label)||"Location",mt=(null===(x=null==i?void 0:i.basic)||void 0===x?void 0:x.description)||"";return X.jsxs("div",{className:`form-group ${b?"no-label":""} ${B}`,children:[!b&&X.jsxs("label",{htmlFor:t,className:"form-label",children:[gt,(null===(F=null==i?void 0:i.validation)||void 0===F?void 0:F.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]}),mt&&X.jsx("div",{className:"form-group-description",children:mt}),X.jsxs("div",{className:"location-wrapper",children:[!(l&&Q)&&X.jsxs("div",{className:"location-controls",children:[X.jsx("button",{type:"button",className:"location-btn "+(E?"loading":""),onClick:it,disabled:pt||E,onFocus:dt,onBlur:ft,tabIndex:pt?-1:0,children:E?X.jsxs(X.Fragment,{children:[X.jsx(d,{size:16,className:"loading-spinner"}),"Getting Location..."]}):X.jsxs(X.Fragment,{children:[X.jsx(f,{size:16}),"Get Current Location"]})}),X.jsxs("button",{type:"button",className:"location-btn secondary",onClick:at,disabled:pt,onFocus:dt,onBlur:ft,tabIndex:pt?-1:0,children:[X.jsx(p,{size:16}),O?"Hide Map":"Choose on Map"]})]}),Q&&X.jsxs("div",{className:"location-display",children:[!l&&X.jsx("button",{type:"button",className:"location-clear-btn",onClick:st,disabled:pt,title:"Clear location",children:X.jsx(a,{size:16})}),Q.placeName&&X.jsxs("div",{className:"location-place-name",children:[X.jsx("strong",{children:"Place:"})," ",Q.placeName]}),(Q.city||Q.country)&&X.jsxs("div",{className:"location-address",children:[X.jsx("strong",{children:"Address:"})," ",[Q.city,Q.country].filter(Boolean).join(", ")]}),X.jsxs("div",{className:"location-coordinates",children:[X.jsx("strong",{children:"Coordinates:"})," ",(vt=Q.latitude,Bt=Q.longitude,void 0===vt||void 0===Bt||isNaN(vt)||isNaN(Bt)?"":`${Number(vt).toFixed(6)}, ${Number(Bt).toFixed(6)}`)]}),Q.accuracy&&X.jsxs("div",{className:"location-accuracy",children:[X.jsx("strong",{children:"Accuracy:"})," ",(wt=Q.accuracy,wt?`±${Math.round(wt)}m`:"")]}),Q.timestamp&&X.jsxs("div",{className:"location-timestamp",children:[X.jsx("strong",{children:"Captured:"})," ",(et(Q.timestamp)||new Date).toLocaleString()]})]}),O&&!l&&X.jsxs("div",{className:"location-map-container",children:[X.jsxs("div",{className:"location-map-header",children:[X.jsx("h4",{children:"Select Location on Map"}),X.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),X.jsx("div",{className:"location-search",children:X.jsx("form",{onSubmit:t=>{t.preventDefault(),R.trim()&&ht(R)},className:"search-form",children:X.jsxs("div",{className:"search-input-group",children:[X.jsx("input",{type:"text",value:R,onChange:t=>{K(t.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:pt||V}),X.jsx("button",{type:"submit",className:"search-btn",disabled:pt||V||!R.trim(),children:V?X.jsx(d,{size:16,className:"loading-spinner"}):"Search"})]})})}),X.jsxs("div",{ref:G,className:"location-map "+(q?"dragging":""),onMouseDown:lt,onMouseMove:ct,onMouseUp:ut,onMouseLeave:()=>{W(!1),J(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:q?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${D}/${Math.floor((T.lng+180)/360*Math.pow(2,D))}/${Math.floor((1-Math.log(Math.tan(T.lat*Math.PI/180)+1/Math.cos(T.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,D))}.png) center/cover no-repeat`,userSelect:"none"},children:[H&&X.jsx("div",{className:"map-marker "+(H.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:X.jsx(p,{size:24})}),X.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}}),X.jsxs("div",{className:"map-controls",children:[X.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>M(t=>Math.min(18,t+1)),disabled:D>=18,children:"+"}),X.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>M(t=>Math.max(1,t-1)),disabled:D<=1,children:"−"})]})]}),X.jsxs("div",{className:"location-map-instructions",children:[X.jsx("p",{children:X.jsx("strong",{children:"Instructions:"})}),X.jsxs("ul",{children:[X.jsx("li",{children:"Search for a place using the search box above"}),X.jsx("li",{children:"Click anywhere on the map to select a location"}),X.jsx("li",{children:"Drag the map to pan around"}),X.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),X.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),$&&X.jsxs("div",{className:"location-loading",children:[X.jsx(d,{size:16,className:"loading-spinner"}),X.jsx("span",{children:"Loading address details..."})]})]}),S&&X.jsx("div",{className:"location-error",children:S})]}),X.jsx(Z,{validationErrors:s,fieldId:t,touchedFields:u,formSubmitted:h,properties:i,localValidation:{isValid:!0,errors:{}},isTouched:I,mode:g})]});var wt,vt,Bt},pt=({id:t,properties:e,className:A="",hideLabel:r=!1})=>{var n,i,s;const a=null!==(s=null!==(i=null===(n=e.styles)||void 0===n?void 0:n.level)&&void 0!==i?i:e.basic.level)&&void 0!==s?s:1,o=e.basic.label,l=()=>{var t;return`form-heading ${`h${a}`} ${(null===(t=null==e?void 0:e.styles)||void 0===t?void 0:t.textAlign)?`text-${e.styles.textAlign}`:""} ${A}`.trim()},c=()=>{var t,A;const r={};return(null===(t=null==e?void 0:e.styles)||void 0===t?void 0:t.fontSize)&&(r.fontSize=e.styles.fontSize),(null===(A=null==e?void 0:e.styles)||void 0===A?void 0:A.color)&&(r.color=e.styles.color),r};return r?null:(()=>{const e={id:t,className:l(),style:c()};switch(a){case 1:default:return X.jsx("h1",Object.assign({},e,{children:o}));case 2:return X.jsx("h2",Object.assign({},e,{children:o}));case 3:return X.jsx("h3",Object.assign({},e,{children:o}));case 4:return X.jsx("h4",Object.assign({},e,{children:o}));case 5:return X.jsx("h5",Object.assign({},e,{children:o}));case 6:return X.jsx("h6",Object.assign({},e,{children:o}))}})()},gt=({id:t,properties:i,mode:s="preview",formValue:a,onValueChange:o,className:l="",hideLabel:c=!1})=>{var u,h,d;const[f,p]=e(""),[b,y]=e((null===(u=i.validation)||void 0===u?void 0:u.listStyle)||"numbers"),[C,x]=e("#000000"),F=n(null),Q=n(null),U=n(!1),E="edit"===s,N=n({instructions:[],listStyle:"numbers",formValue:void 0}),S=n(s);A(()=>{var t,e,A,r,n;let o=[],l="numbers";if(null!=a&&("object"==typeof a&&a.instructions?(Array.isArray(a.instructions)?o=a.instructions:"string"==typeof a.instructions&&(o=[a.instructions]),a.listStyle&&(l=a.listStyle)):Array.isArray(a)?o=a:"string"==typeof a&&(o=[a])),0===o.length&&(null===(t=i.basic)||void 0===t?void 0:t.value)){const t=i.basic.value;t&&"object"==typeof t&&!Array.isArray(t)&&t.instructions?(Array.isArray(t.instructions)?o=t.instructions:"string"==typeof t.instructions&&(o=[t.instructions]),t.listStyle&&"string"==typeof t.listStyle&&(l=t.listStyle)):Array.isArray(t)?o=t:"string"==typeof t&&(o=[t])}0===o.length&&(null===(e=i.basic)||void 0===e?void 0:e.instructions)&&(Array.isArray(i.basic.instructions)?o=i.basic.instructions:"string"==typeof i.basic.instructions&&(o=[i.basic.instructions])),l&&"numbers"!==l||(l=(null===(A=i.validation)||void 0===A?void 0:A.listStyle)||(null===(n=null===(r=i.basic)||void 0===r?void 0:r.value)||void 0===n?void 0:n.listStyle)||"numbers");const c=JSON.stringify(o)!==JSON.stringify(N.current.instructions)||l!==N.current.listStyle,u=s!==S.current,h=JSON.stringify(a)!==JSON.stringify(N.current.formValue),d=!N.current.formValue||Array.isArray(N.current.formValue)&&0===N.current.formValue.length||"string"==typeof N.current.formValue&&""===N.current.formValue.trim(),f=null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==a.trim()||"object"==typeof a&&Object.keys(a).length>0);if(c||u||h||d&&f){const t=t=>"string"!=typeof t?t:t.replace(/\\u([0-9a-fA-F]{4})/g,(t,e)=>String.fromCharCode(parseInt(e,16))),e=o.map(e=>"string"==typeof e?t(e):e),A=e.some(t=>"string"==typeof t&&/<[^>]+>/.test(t));let r="";if(e.length>0)if(A)r=e.join("");else{const t="numbers"===l?"ol":"bullets"===l?"ul":"div",A=e.filter(t=>t&&"string"==typeof t).map(t=>`<li>${t.replace(/\n/g,"<br>")}</li>`).join("");r="div"===t?e.filter(t=>t&&"string"==typeof t).map(t=>`<div>${t.replace(/\n/g,"<br>")}</div>`).join(""):`<${t}>${A}</${t}>`}y(l),p(r),E&&F.current&&(u||c&&F.current.innerHTML.trim()!==r.trim())&&(F.current.innerHTML=r),N.current={instructions:o,listStyle:l,formValue:a},S.current=s}},[a,null===(h=i.basic)||void 0===h?void 0:h.instructions,null===(d=i.validation)||void 0===d?void 0:d.listStyle,s,E]),A(()=>{if(E&&F.current){const t=F.current.innerHTML.trim();f.trim()===t||U.current||(F.current.innerHTML=f)}if(U.current){const t=setTimeout(()=>{U.current=!1},200);return()=>clearTimeout(t)}},[f,E]);const L=r(()=>{if(!F.current)return;U.current=!0;const e=F.current.innerHTML.trim();if(o){o({id:t,value:{instructions:e?[e]:[],listStyle:b},isValid:!0,errors:{}})}e!==f&&p(e)},[t,b,o,f]),I=r(()=>{if(!F.current)return;const e=F.current.innerHTML.trim();if(o){o({id:t,value:{instructions:e?[e]:[],listStyle:b},isValid:!0,errors:{}})}p(e),U.current=!1},[t,b,o]),_=r((t,e)=>{var A;document.execCommand(t,!1,e),null===(A=F.current)||void 0===A||A.focus(),L()},[L]),O=r(()=>{_("bold")},[_]),k=r(()=>{_("italic")},[_]),T=r(t=>{const e=t.target.value;x(e),_("foreColor",e)},[_]),j=r(e=>{if(y(e),!F.current)return;const A=window.getSelection(),r=A&&A.rangeCount>0?A.getRangeAt(0):null;let n=F.current.innerHTML;if("numbers"===e){if(n=n.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!n.includes("<ol>")&&!n.includes("<ul>")){const t=n.split(/<br\s*\/?>/i).filter(t=>t.trim());t.length>0&&(n="<ol>"+t.map(t=>`<li>${t}</li>`).join("")+"</ol>")}}else if("bullets"===e){if(n=n.replace(/<ol>/gi,"<ul>").replace(/<\/ol>/gi,"</ul>"),!n.includes("<ol>")&&!n.includes("<ul>")){const t=n.split(/<br\s*\/?>/i).filter(t=>t.trim());t.length>0&&(n="<ul>"+t.map(t=>`<li>${t}</li>`).join("")+"</ul>")}}else n=n.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(F.current.innerHTML=n,p(n),r&&A)try{A.removeAllRanges(),A.addRange(r)}catch(t){}if(L(),o){o({id:t,value:{instructions:n?[n]:[],listStyle:e},isValid:!0,errors:{}})}},[t,L,o]),H=r(t=>{var e;const A=null===(e=t.target.files)||void 0===e?void 0:e[0];if(!A||!A.type.startsWith("image/"))return;const r=new FileReader;r.onload=t=>{var e;const A=null===(e=t.target)||void 0===e?void 0:e.result;if(A&&F.current){const t=document.createElement("img");t.src=A,t.style.maxWidth="100%",t.style.height="auto";const e=window.getSelection();if(e&&e.rangeCount>0){const A=e.getRangeAt(0);A.deleteContents(),A.insertNode(t)}else F.current.appendChild(t);L()}},r.readAsDataURL(A),Q.current&&(Q.current.value="")},[L]),P=r(t=>{t.preventDefault();const e=t.clipboardData.getData("text/plain"),A=window.getSelection();if(A&&A.rangeCount>0){const t=A.getRangeAt(0);t.deleteContents();const r=document.createTextNode(e);t.insertNode(r),t.setStartAfter(r),t.collapse(!0),A.removeAllRanges(),A.addRange(t)}L()},[L]),D=r(t=>document.queryCommandState(t),[]);return X.jsxs("div",{className:`form-group instruction-group ${l}`,children:[!c&&X.jsx("label",{htmlFor:t,className:"instruction-label",children:"Instructions"}),E?X.jsxs("div",{className:"instruction-rich-editor",children:[X.jsxs("div",{className:"instruction-toolbar",children:[X.jsxs("div",{className:"toolbar-group",children:[X.jsx("button",{type:"button",className:"toolbar-btn "+(D("bold")?"active":""),onClick:O,title:"Bold","aria-label":"Bold",children:X.jsx(g,{size:16})}),X.jsx("button",{type:"button",className:"toolbar-btn "+(D("italic")?"active":""),onClick:k,title:"Italic","aria-label":"Italic",children:X.jsx(m,{size:16})})]}),X.jsx("div",{className:"toolbar-separator"}),X.jsx("div",{className:"toolbar-group",children:X.jsxs("div",{className:"color-picker-wrapper",children:[X.jsx("input",{type:"color",value:C,onChange:T,className:"color-picker-input",title:"Text Color"}),X.jsx("label",{className:"color-picker-label",title:"Text Color",children:X.jsx("span",{style:{color:C},children:"A"})})]})}),X.jsx("div",{className:"toolbar-separator"}),X.jsxs("div",{className:"toolbar-group",children:[X.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===b?"active":""),onClick:()=>j("bullets"),title:"Bullet List","aria-label":"Bullet List",children:X.jsx(w,{size:16})}),X.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===b?"active":""),onClick:()=>j("numbers"),title:"Numbered List","aria-label":"Numbered List",children:X.jsx(v,{size:16})})]}),X.jsx("div",{className:"toolbar-separator"}),X.jsxs("div",{className:"toolbar-group",children:[X.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>{var t;return null===(t=Q.current)||void 0===t?void 0:t.click()},title:"Insert Image","aria-label":"Insert Image",children:X.jsx(B,{size:16})}),X.jsx("input",{ref:Q,type:"file",accept:"image/*",onChange:H,style:{display:"none"}})]})]}),X.jsx("div",{ref:F,contentEditable:!0,className:"instruction-editor-content",onInput:L,onBlur:I,onPaste:P,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):X.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===b?"instruction-list-numbers":"bullets"===b?"instruction-list-bullets":""),children:f?X.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:f}}):X.jsx("div",{className:"instruction-empty",children:X.jsx("p",{children:"No instructions provided"})})})]})},mt=({attachments:t,onRemove:r})=>{const[n,i]=e(new Map);return A(()=>{if(!t)return void i(t=>(t.forEach(t=>URL.revokeObjectURL(t)),new Map));const e=new Map;return t.forEach((t,A)=>{if(t&&t.type&&"string"==typeof t.type&&t.type.startsWith("image/")){const r=URL.createObjectURL(t);e.set(A,r)}}),i(t=>(t.forEach((t,A)=>{e.has(A)||URL.revokeObjectURL(t)}),e)),()=>{e.forEach(t=>URL.revokeObjectURL(t))}},[t]),t&&0!==t.length?X.jsx("div",{className:"attachment-thumbnails-container",children:t.map((t,e)=>{const A=t&&t.type&&"string"==typeof t.type&&t.type.startsWith("image/"),i=n.get(e);return X.jsx("div",{className:"attachment-thumbnail",children:A&&i?X.jsxs(X.Fragment,{children:[X.jsx("img",{src:i,alt:t?t.name:"Attachment"}),X.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(e),title:"Remove attachment",children:X.jsx(a,{size:14})})]}):X.jsxs(X.Fragment,{children:[X.jsx("div",{className:"file-icon-placeholder",children:X.jsx(h,{size:20})}),X.jsx("span",{className:"file-name",children:t?t.name:"Unknown File"}),X.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(e),title:"Remove attachment",children:X.jsx(a,{size:14})})]})},e)})}):null},wt=({component:t,mode:i,formTemplateId:s,formValue:a,onNotesChange:o,onAttachmentChange:l,notes:u="",attachments:d=null,onThresholdActionCompletion:f,onThresholdIssueRaised:p,onBasicPropertyActionCompletion:g,workOrderNumber:m,assetNumber:w,isStandalone:v,user:B,onCreateIssue:Q,onUpdateIssue:U})=>{var E,N,S,L;const[I,_]=e(u||""),[O,k]=e(d||null),[T,j]=e(!1),[H,P]=e(!1),[D,M]=e(!1),[R,K]=e(!1),[V,z]=e(null),[G,q]=e(!1),W=n(null),Y=n(a),J=n(!1),$=n(!1);A(()=>{if(!J.current&&null!=u){const t="string"==typeof u?u:String(u||"");_(t),J.current=!0}},[u]),A(()=>{$.current||void 0===d||(k(d),$.current=!0)},[d]),A(()=>{if(J.current&&!T&&null!=u){const t="string"==typeof u?u:String(u||"");I&&""!==String(I||"").trim()||!t||""===t.trim()?t&&""!==t.trim()&&t!==I&&_(t):_(t)}},[u,T,I]),A(()=>{$.current&&void 0!==d&&(!O||d&&d.length>0&&d!==O)&&k(d)},[d,O]),A(()=>{const e=["select","radio","checkbox","segment"].includes(t.name||"");if(e){const e=Y.current,A=a;let r=!1;if("checkbox"===t.name){const t=Array.isArray(e)?e:e?[e]:[],n=Array.isArray(A)?A:A?[A]:[];r=JSON.stringify(t.sort())!==JSON.stringify(n.sort())}else r=e!==A&&void 0!==e;if(r){M(!1),K(!1),z(null),P(!1),j(!1),q(!1);const t="string"==typeof u?u:String(u||"");t&&""!==t.trim()?_(t):_(""),d&&0!==d.length?k(d):k(null)}Y.current=A}e||(Y.current=a)},[a,t.name,u,d]);const Z=r((t,e)=>{const{operator:A,value:r}=t,n=String(e).toLowerCase(),i=String(r).toLowerCase();switch(A){case"equals":return n===i||String(e)===String(r);case"notEquals":return n!==i&&String(e)!==String(r);case"greaterThan":return Number(e)>Number(r);case"lessThan":return Number(e)<Number(r);case"greaterThanOrEqual":return Number(e)>=Number(r);case"lessThanOrEqual":return Number(e)<=Number(r);default:return!1}},[]),tt=r(()=>{if(!(null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length)))return[];const e=t.condition;if(!e||!e.conditions||0===e.conditions.length)return[];const A=[];if("checkbox"===t.name&&Array.isArray(a))a.forEach(t=>{const r=e.conditions.find(e=>Z(e,t));r&&!A.find(t=>t.id===r.id)&&A.push(r)});else{const t=e.conditions.find(t=>Z(t,a));t&&A.push(t)}return A},[t,a,Z]),et=r(e=>{const A=e.target.value;_(A),o&&o(A);const r=tt(),n=String(A||"").trim().length>0;r.forEach(t=>{!0===t.enableNotes&&f&&f(t.id,"notes",n)});const i=t.condition;!(i&&i.conditions&&i.conditions.length>0)&&g&&g("notes",n)},[o,tt,f,t,g]),At=r(()=>{if(o){const t="string"==typeof I?I:String(I||"");o(t),setTimeout(()=>{j(!1)},0)}else j(!1)},[I,o]),nt=r(()=>{At()},[At]),it=r(t=>{(t.ctrlKey||t.metaKey)&&"Enter"===t.key&&(t.preventDefault(),At())},[At]),st=r(()=>{j(!0)},[]),at=r(()=>{j(!0)},[]),ot=r(()=>{var t;null===(t=W.current)||void 0===t||t.click()},[]),lt=r(e=>{const A=e.target.files;if(A&&A.length>0){const e=Array.from(A);k(e),l&&l(e);tt().forEach(t=>{!0===t.enableAttachment&&f&&f(t.id,"attachments",!0)});const r=t.condition;!(r&&r.conditions&&r.conditions.length>0)&&g&&g("attachments",!0)}W.current&&(W.current.value="")},[l,tt,f,t,g]),ct=r(e=>{if(O){const A=O.filter((t,A)=>A!==e);if(0===A.length){k(null),l&&l(null);tt().forEach(t=>{!0===t.enableAttachment&&f&&f(t.id,"attachments",!1)});const e=t.condition;!(e&&e.conditions&&e.conditions.length>0)&&g&&g("attachments",!1)}else k(A),l&&l(A)}},[O,l,tt,f,t,g]),ut=r(()=>{M(!0);tt().forEach(t=>{!0===t.enableSendEmail&&f&&f(t.id,"email",!0)});const e=t.condition;!(e&&e.conditions&&e.conditions.length>0)&&g&&g("email",!0),setTimeout(()=>{M(!1)},3e3)},[tt,f,t,g]),ht=r(()=>{R||P(!0)},[R]),dt=r(()=>{P(!1)},[]),ft=r(e=>{P(!1),K(!0),e&&z(e);const A=t.condition;if(A&&A.conditions&&A.conditions.length>0){tt().forEach(t=>{!0===t.enableRaiseIssue&&p&&p(t.id)})}else g&&g("issue",!0)},[t,g,tt,p]);if("test"!==i)return null;const pt=["select","radio","checkbox","segment"].includes(t.name||""),gt=(null===(E=t.basic)||void 0===E?void 0:E.options)||t.options||[];let wt=!1,vt=!1,Bt=!1,bt=!1,yt=null;const Ct=null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length),xt=t.condition,Ft=xt&&xt.conditions&&xt.conditions.length>0;if(Ft&&Ct)if("checkbox"===t.name&&Array.isArray(a)){const t=a;for(const e of t){const t=xt.conditions.find(t=>Z(t,e));t&&(wt=wt||!0===t.enableNotes,vt=vt||!0===t.enableAttachment,Bt=Bt||!0===t.enableRaiseIssue,bt=bt||!0===t.enableSendEmail)}}else if(pt){const t=xt.conditions.find(t=>Z(t,a));t&&(wt=!0===t.enableNotes,vt=!0===t.enableAttachment,Bt=!0===t.enableRaiseIssue,bt=!0===t.enableSendEmail)}else{const t=xt.conditions.find(t=>Z(t,a));t&&(wt=!0===t.enableNotes,vt=!0===t.enableAttachment,Bt=!0===t.enableRaiseIssue,bt=!0===t.enableSendEmail)}if(!Ft){const e=t.basic,A=!0===(null==e?void 0:e.enableNotes),r=!0===(null==e?void 0:e.enableAttachment),n=!0===(null==e?void 0:e.enableRaiseIssue),i=!0===(null==e?void 0:e.enableSendEmail);if(pt)if(Ct)if("checkbox"===t.name){(Array.isArray(a)?a:[a]).forEach(t=>{const e=gt.find(e=>!(!e||!e.value)&&(e.value===t||(String(e.value)===String(t)||(e.label===t||String(e.label)===String(t)))));e&&(wt=wt||!0===e.enableNotes,vt=vt||!0===e.enableAttachment,Bt=Bt||!0===e.enableRaiseIssue,bt=bt||!0===e.enableSendEmail,yt||(yt=e))}),wt=wt||A,vt=vt||r,Bt=Bt||n,bt=bt||i}else if(yt=gt.find(t=>!(!t||!t.value)&&(t.value===a||(String(t.value)===String(a)||(t.label===a||String(t.label)===String(a))))),yt){const t=!0===yt.enableNotes,e=!0===yt.enableAttachment,s=!0===yt.enableRaiseIssue,a=!0===yt.enableSendEmail;wt=t||A,vt=e||r,Bt=s||n,bt=a||i}else wt=A,vt=r,Bt=n,bt=i;else wt=A,vt=r,Bt=n,bt=i;else wt=A,vt=r,Bt=n,bt=i}if(!(wt||vt||Bt||bt))return null;const Qt=tt(),Ut=t.condition,Et=Ut&&Ut.conditions&&Ut.conditions.length>0,Nt=!!Et&&Qt.some(t=>!0===t.enableNotes),St=!!Et&&Qt.some(t=>!0===t.enableAttachment),Lt=!!Et&&Qt.some(t=>!0===t.enableSendEmail),It=!!Et&&Qt.some(t=>!0===t.enableRaiseIssue),_t=String(I||"").trim().length>0,Ot=O&&O.length>0,kt=O?O.length:0;return X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"component-action-features",children:[X.jsxs("div",{className:"action-icons-toolbar",children:[wt&&X.jsxs("button",{type:"button",className:`action-icon-button ${_t?"active":""} ${Nt?"mandatory":""}`,onClick:st,title:"Add Notes",children:[X.jsx(c,{size:14,fill:_t?"currentColor":"none"}),Nt&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),vt&&X.jsxs("button",{type:"button",className:`action-icon-button ${Ot?"active":""} ${St?"mandatory":""}`,onClick:ot,title:"Add Attachment",children:[X.jsx(h,{size:14,fill:Ot?"currentColor":"none"}),kt>0&&X.jsx("span",{className:"attachment-count-badge",children:kt}),St&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),bt&&X.jsxs("button",{type:"button",className:`action-icon-button ${D?"active sent":""} ${Lt?"mandatory":""}`,onClick:ut,disabled:D,title:"Send Email",children:[D?X.jsx(X.Fragment,{children:X.jsx(b,{size:14})}):X.jsx(y,{size:14,fill:D?"currentColor":"none"}),Lt&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),Bt&&X.jsxs("button",{type:"button",className:`action-icon-button ${R?"active":""} ${It?"mandatory":""}`,onClick:ht,title:"Raise an Issue",children:[X.jsx(C,{size:14,fill:R?"currentColor":"none"}),It&&X.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(_t&&wt||Ot&&vt)&&X.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>q(!G),title:G?"Collapse":"Expand",children:G?X.jsx(x,{size:14}):X.jsx(F,{size:14})})]}),T&&wt&&X.jsxs("div",{className:"notes-input-overlay",children:[X.jsx("textarea",{className:"action-notes-textarea",value:I,onChange:et,onBlur:nt,onKeyDown:it,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),X.jsxs("div",{className:"notes-input-actions",children:[X.jsx("button",{type:"button",className:"notes-save-button",onClick:At,title:"Save notes (Ctrl+Enter)",children:"Save"}),X.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{j(!1)},title:"Cancel",children:"Cancel"})]})]}),G&&X.jsxs("div",{className:"actions-content",children:[!T&&_t&&wt&&X.jsx("div",{className:"notes-summary-section",children:X.jsxs("div",{className:"notes-full-text",onClick:at,children:[X.jsx("span",{className:"notes-label",children:"Notes:"})," ",I]})}),Ot&&vt&&X.jsx("div",{className:"attachments-section",children:X.jsx(mt,{attachments:O,onRemove:ct})})]}),vt&&X.jsx("input",{ref:W,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:lt,style:{display:"none"}})]}),H&&X.jsx(rt,{isOpen:H,onClose:dt,onSuccess:ft,issue:V,component:yt?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{label:`${(null===(N=t.basic)||void 0===N?void 0:N.label)||"Component"} - ${yt.label||yt.value}`,value:yt.value||(null===(S=t.basic)||void 0===S?void 0:S.value)||""})}):Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{value:null!=a?Array.isArray(a)?a.join(", "):String(a):(null===(L=t.basic)||void 0===L?void 0:L.value)||""})}),formTemplateId:s||"",notes:I,attachments:O,workOrderNumber:m,assetNumber:w,user:B,isStandalone:v,onCreateIssue:Q,onUpdateIssue:U})]})},vt=({attachments:t})=>t&&0!==t.length?X.jsx("div",{className:"attachment-thumbnails-container",children:t.map((t,e)=>{var A;const r=(null===(A=t.type)||void 0===A?void 0:A.startsWith("image/"))||!1,n=r?(t=>t.data?t.data.startsWith("data:")?t.data:`data:${t.type||"image/png"};base64,${t.data}`:"")(t):"";return X.jsx("div",{className:"attachment-thumbnail",children:r&&n?X.jsx("img",{src:n,alt:t.name||`Attachment ${e+1}`}):X.jsxs("div",{className:"file-icon-placeholder",children:[X.jsx(h,{size:20}),X.jsx("span",{className:"file-name",children:t.name||`File ${e+1}`})]})},e)})}):null,Bt=({component:t})=>{var e,A;const r=(null===(e=t.basic)||void 0===e?void 0:e.notes)||"",n=(null===(A=t.basic)||void 0===A?void 0:A.attachments)||[],i=r&&r.trim().length>0,s=n&&n.length>0;return i||s?X.jsx("div",{className:"component-submission-actions",children:X.jsxs("div",{className:"actions-content",children:[i&&X.jsx("div",{className:"notes-summary-section",children:X.jsxs("div",{className:"notes-full-text",children:[X.jsx("span",{className:"notes-label",children:"Notes:"})," ",r]})}),s&&X.jsx("div",{className:"attachments-section",children:X.jsx(vt,{attachments:n})})]})}):null},bt=({child:t,selectedChild:e,mode:A,onChildSelect:r,onChildDelete:n,renderFormComponent:i,isOverlay:s=!1,isChildrenEditMode:a=!1,formData:o={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w})=>{var v,B;const b=o[t.id],y="preview"===A&&((null===(v=t.basic)||void 0===v?void 0:v.notes)&&t.basic.notes.trim().length>0||(null===(B=t.basic)||void 0===B?void 0:B.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0),{attributes:C,listeners:x,setNodeRef:F,transform:Q,transition:S,isDragging:L,isSorting:I}=j({id:t.id,disabled:s||"edit"!==A}),_={transform:P.Transform.toString(Q),transition:S,zIndex:L?1e3:"auto"};return X.jsxs("div",{ref:F,style:_,className:`form-component section-child ${(null==e?void 0:e.id)===t.id?"selected":""} ${L?"dragging":""} ${I?"sorting":""} ${a?"children-edit-active":""}`,onClick:()=>!L&&r(t),role:"button",tabIndex:0,children:[("edit"===A||a)&&X.jsx("div",Object.assign({className:"child-drag-handle"},x,C,{onClick:t=>t.stopPropagation(),onMouseDown:t=>t.stopPropagation(),children:X.jsx(U,{size:14})})),X.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===A||a)&&X.jsxs("div",{className:"component-actions child-actions",children:[X.jsx("button",{className:"btn edit-btn",onClick:e=>{e.stopPropagation(),r(t)},onMouseDown:t=>t.stopPropagation(),title:"Edit properties",children:X.jsx(E,{size:12})}),X.jsx("button",{className:"btn delete-btn",onClick:e=>n(t,e),onMouseDown:t=>t.stopPropagation(),title:"Delete component",children:X.jsx(N,{size:12})})]}),X.jsxs("div",{className:"component-preview child-preview",children:[i(t),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:"test",formTemplateId:l,formValue:b,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h?e=>h(t.id,e):void 0,onAttachmentChange:d?e=>d(t.id,e):void 0,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w}),y&&X.jsx(Bt,{component:t})]})]})]})},yt=({id:t,properties:n,mode:i="edit",formData:s={},onValueChange:a,onSelect:o,isSelected:l=!1,className:c="",onSectionSelect:u,onChildSelect:h,onChildDelete:d,selectedChild:f,renderFormComponent:p,formTemplateId:g,onThresholdActionCompletion:m,onThresholdIssueRaised:w,onNotesChange:v,onAttachmentChange:B,workOrderNumber:b,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:U})=>{var E,N,S,L,I,_;const[j,H]=e(n.basic.collapsed),[P,D]=e(!1),[M,R]=e(!1),[K,V]=e(n.basic.label),[z,G]=e(n.basic.description),[q,W]=e(n.children||[]),[Y,J]=e(!1);A(()=>{W(n.children||[])},[n.children]),A(()=>{V(n.basic.label),G(n.basic.description)},[n.basic.label,n.basic.description]);const{setNodeRef:$,isOver:Z}=O({id:`section-${t}`,disabled:"edit"!==i}),tt=!("preview"!==i&&"test"!==i||n.children&&n.children.length>0),et=r(e=>{V(e),null==a||a({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic),{label:e})})})},[t,n,a]),At=r(e=>{G(e),null==a||a({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic),{description:e})})})},[t,n,a]),rt=r(t=>{null==h||h(t)},[h]),nt=r((t,e)=>{e.stopPropagation();const A=q.filter(e=>e.id!==t.id);W(A),null==d||d(t.id)},[d,q,t]),ct=r(()=>{null==u||u(n),null==o||o()},[u,o,n]),dt=r(t=>{t.stopPropagation(),"edit"===i&&q.length>0&&J(!Y)},[i,q.length,Y]),ft=r(e=>{e.stopPropagation(),H(!j),null==a||a({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic),{collapsed:!j})})})},[j,t,n,a]),gt=p||r(t=>{var e,A,r;const n=s[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let o=n;"number-input"===t.name&&"number"==typeof n?o=String(n):"number-input"===t.name&&null==n&&(o="");const l={id:t.id,properties:t,validationErrors:{},formValue:o,touchedFields:{},formSubmitted:!1,mode:i,onValueChange:a,onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return X.jsx(it,Object.assign({},l,{properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return X.jsx(st,Object.assign({},l,{properties:t,readonly:!1,disabled:!1}));case"select":const n=Object.assign(Object.assign({},t),{options:(null===(e=t.basic)||void 0===e?void 0:e.options)||[]});return X.jsx(at,Object.assign({},l,{properties:n,disabled:!1}));case"checkbox":const i=Object.assign(Object.assign({},t),{options:(null===(A=t.basic)||void 0===A?void 0:A.options)||[]});return X.jsx(ot,Object.assign({},l,{properties:i,formValue:[],disabled:!1}));case"radio":const s=Object.assign(Object.assign({},t),{options:(null===(r=t.basic)||void 0===r?void 0:r.options)||[]});return X.jsx(lt,Object.assign({},l,{properties:s,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},l,{properties:t,readonly:!1,disabled:!1}));case"signature":return X.jsx(ht,Object.assign({},l,{properties:t}));case"heading":return X.jsx(pt,Object.assign({},l,{properties:t}));default:return X.jsx("div",{className:"form-group",children:X.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",t.name]})})}},[i,a,s]);if(tt)return null;const mt={backgroundColor:(null===(E=n.styles)||void 0===E?void 0:E.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(N=n.styles)||void 0===N?void 0:N.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(S=n.styles)||void 0===S?void 0:S.borderWidth)||"2px",borderRadius:(null===(L=n.styles)||void 0===L?void 0:L.borderRadius)||"8px",padding:(null===(I=n.styles)||void 0===I?void 0:I.padding)||"16px",margin:(null===(_=n.styles)||void 0===_?void 0:_.margin)||"16px 0"};return X.jsxs("div",{ref:$,className:`df-form-section ${l?"selected":""} ${Z?"drag-over":""} ${c}`,style:mt,children:[X.jsxs("div",{className:"section-header "+(Y?"children-edit-mode":""),onClick:ct,onDoubleClick:dt,children:[X.jsx("div",{className:"section-header-content",children:X.jsxs("div",{className:"section-title",children:[X.jsx("span",{className:"section-toggle",title:j?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:t=>{t.stopPropagation(),ft(t)},onKeyDown:t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),ft(t))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:j?X.jsx(Q,{size:18}):X.jsx(F,{size:18})}),"edit"===i&&P?X.jsx("input",{type:"text",value:K,onChange:t=>V(t.target.value),onBlur:()=>{D(!1),et(K)},onKeyDown:t=>{"Enter"===t.key&&(D(!1),et(K))},className:"section-title-input",autoFocus:!0}):X.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===i&&D(!0),style:{display:"inline",margin:0},children:K||"Untitled Section"})]})}),(z||"edit"===i)&&X.jsx("div",{className:"section-description",children:"edit"===i&&M?X.jsx("textarea",{value:z,onChange:t=>G(t.target.value),onBlur:()=>{R(!1),At(z)},onKeyDown:t=>{"Enter"===t.key&&t.ctrlKey&&(R(!1),At(z))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):X.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===i&&R(!0),children:z||"Section description"})})]}),!j&&X.jsx("div",{className:`section-content ${Z?"drag-over":""} ${0===q.length?"empty":"has-children"}`,onClick:t=>{t.target===t.currentTarget&&ct()},children:X.jsx(k,{items:q.map(t=>t.id),strategy:T,children:0===q.length?X.jsxs("div",{className:"section-empty-state",onClick:ct,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:[X.jsx("div",{style:{fontWeight:"500",color:Z?"#3b82f6":"#374151"},children:Z?"Drop components here":"Empty Section"}),X.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):q.map(t=>X.jsx(bt,{child:t,selectedChild:f||null,mode:i,onChildSelect:rt,onChildDelete:nt,renderFormComponent:gt,isChildrenEditMode:Y,formData:s,formTemplateId:g,onNotesChange:v,onAttachmentChange:B,onThresholdActionCompletion:m,onThresholdIssueRaised:w,workOrderNumber:b,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:U},t.id))})})]})},Ct=({component:t,selectedComponent:e,mode:A,onComponentSelect:r,onComponentDelete:n,onComponentEdit:i,renderFormComponent:s,isOverlay:a=!1,formData:o={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,onCreateIssue:g,onUpdateIssue:m})=>{var w,v;const B=o[t.id],b="preview"===A&&((null===(w=t.basic)||void 0===w?void 0:w.notes)&&t.basic.notes.trim().length>0||(null===(v=t.basic)||void 0===v?void 0:v.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0),{attributes:y,listeners:C,setNodeRef:x,transform:F,transition:Q,isDragging:S,isSorting:L}=j({id:t.id,disabled:a}),I={transform:P.Transform.toString(F),transition:Q,opacity:S?.3:1,zIndex:S?1e3:"auto"};return X.jsxs("div",{ref:x,style:Object.assign(Object.assign({},I),{border:(null==e?void 0:e.id)===t.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:(null==e?void 0:e.id)===t.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 ${(null==e?void 0:e.id)===t.id?"selected":""} ${S?"dragging":""} ${L?"sorting":""}`,onClick:()=>!S&&r(t),role:"button",tabIndex:0,children:["edit"===A&&X.jsx("div",Object.assign({className:"component-drag-handle"},C,y,{onClick:t=>t.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:X.jsx(U,{size:12,color:"var(--df-color-text-light)"})})),X.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===A?"24px":"0",paddingLeft:"edit"===A?"28px":"0",minHeight:"60px"},children:[s(t),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:"test",formTemplateId:l,formValue:B,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onNotesChange:h?e=>h(t.id,e):void 0,onAttachmentChange:d?e=>d(t.id,e):void 0,workOrderNumber:f,assetNumber:p,onCreateIssue:g,onUpdateIssue:m}),b&&X.jsx(Bt,{component:t})]}),"edit"===A&&X.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[i&&X.jsx("button",{className:"component-edit-btn",onClick:e=>{e.stopPropagation(),i(t)},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:t=>{t.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="#3b82f6"},children:X.jsx(E,{size:12})}),X.jsx("button",{className:"component-delete-btn",onClick:e=>{e.stopPropagation(),n(t,e)},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:t=>{t.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="#ef4444"},children:X.jsx(N,{size:12})})]})]})},xt=({gridComponents:t,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,onComponentUpdate:i,selectedComponent:s,renderFormComponent:a,gridId:o,formData:l={},formTemplateId:c,onThresholdActionCompletion:u,onThresholdIssueRaised:h,onNotesChange:d,onAttachmentChange:f,workOrderNumber:p,assetNumber:g,onCreateIssue:m,onUpdateIssue:w})=>{const{setNodeRef:v,isOver:B}=O({id:`grid-drop-zone-${o}`,disabled:"edit"!==e});return X.jsx("div",{ref:v,className:"grid-drop-zone",style:{border:B?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:B?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:t.length>0?X.jsxs(X.Fragment,{children:[X.jsx(k,{items:t.map(t=>t.id),strategy:H,children:X.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:t.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:t.map(t=>X.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:X.jsx(Ct,{component:t,selectedComponent:s,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,onComponentUpdate:i,renderFormComponent:a,formData:l,formTemplateId:c,onThresholdActionCompletion:u,onThresholdIssueRaised:h,onNotesChange:d,onAttachmentChange:f,workOrderNumber:p,assetNumber:g,onCreateIssue:m,onUpdateIssue:w})},t.id))})}),X.jsx("div",{style:{border:B?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:B?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:B?X.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):X.jsx("span",{children:"+ Drop more components here"})})]}):X.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:[X.jsx("div",{style:{fontWeight:"500",color:B?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:B?"Drop components here":"Empty DataGrid"}),X.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},Ft=({templateComponents:t,dataEntries:e,renderFormComponent:A,renderComponent:r,mode:n="preview",allowAddRemoveEntries:i=!0,addAnotherText:s="Add Another",removeText:a="Remove",maxEntries:o=10,minEntries:l=1,displayAsGrid:c=!0,onAddEntry:u,onRemoveEntry:h,formData:d={},formTemplateId:f,onThresholdActionCompletion:p,onThresholdIssueRaised:g,onNotesChange:m,onAttachmentChange:w,datagridId:v="",workOrderNumber:B,assetNumber:b,onCreateIssue:y,onUpdateIssue:C})=>0===t.length?X.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 ",c?"table":"list"," view."]}):c?X.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:[X.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:t.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),X.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:[X.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${t.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*t.length+"px"},children:t.map((e,A)=>{var r;return X.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:A<t.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(null===(r=e.basic)||void 0===r?void 0:r.label)||`Column ${A+1}`},`header-${e.id}`)})}),e.length>0?e.map((s,o)=>X.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${t.length}, minmax(150px, 1fr))`,borderBottom:o<e.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*t.length+"px",isolation:"isolate"},children:[t.map((e,i)=>{var a,l,c,u,h,x,F;let Q=null===(a=s.components)||void 0===a?void 0:a[i];const U=`${e.id||`component-${i}`}-entry-${v}-${o}-${i}`;return Q=Q?Q.id!==U?Object.assign(Object.assign({},Q),{id:U,basic:Object.assign(Object.assign({},Q.basic),{showLabel:!1})}):Object.assign(Object.assign({},Q),{id:Q.id,basic:Object.assign(Object.assign({},Q.basic),{showLabel:!1})}):Object.assign(Object.assign({},e),{id:U,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),X.jsxs("div",{style:{padding:"12px 16px",borderRight:i<t.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:[X.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:r?r(Q,!0):A(Q,!0)}),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(Q.name)&&X.jsxs("div",{style:{marginTop:"8px",width:"100%"},children:[X.jsx(wt,{component:Q,mode:"test",formTemplateId:f,formValue:d[Q.id],onThresholdActionCompletion:p,onThresholdIssueRaised:g,onNotesChange:m?t=>m(Q.id,t):void 0,onAttachmentChange:w?t=>w(Q.id,t):void 0,notes:(null===(l=Q.basic)||void 0===l?void 0:l.notes)||(null===(c=d[Q.id])||void 0===c?void 0:c.notes),attachments:(null===(u=Q.basic)||void 0===u?void 0:u.attachments)||(null===(h=d[Q.id])||void 0===h?void 0:h.attachments),workOrderNumber:B,assetNumber:b,onCreateIssue:y,onUpdateIssue:C}),"preview"===n&&((null===(x=Q.basic)||void 0===x?void 0:x.notes)||(null===(F=Q.basic)||void 0===F?void 0:F.attachments))&&X.jsx(Bt,{component:Q})]})]},`${s.id}-${i}`)}),i&&e.length>l&&X.jsx("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length<=l)&&h)try{h(o)}catch(t){console.error("Error removing entry:",t)}},disabled:e.length<=l,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:e.length<=l?"#f3f4f6":"#ef4444",color:e.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:e.length<=l?"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:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#ef4444")},children:X.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},s.id)):X.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. ",i?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]})]}),i&&X.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:X.jsxs("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length>=o)&&u)try{u()}catch(t){console.error("Error adding entry:",t)}},disabled:e.length>=o,style:{padding:"8px 16px",backgroundColor:e.length>=o?"#f3f4f6":"#10b981",color:e.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:e.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#059669")},onMouseLeave:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#10b981")},children:[X.jsx("span",{style:{fontSize:"16px"},children:"+"}),s]})})]}):X.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[e.length>0?e.map((s,o)=>X.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:[X.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[X.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",o+1]}),i&&e.length>1&&X.jsx("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length<=l)&&h)try{h(o)}catch(t){console.error("Error removing entry:",t)}},disabled:e.length<=l,style:{padding:"4px 8px",backgroundColor:e.length<=l?"#f3f4f6":"#ef4444",color:e.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:e.length<=l?"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:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:t=>{e.length>l&&(t.currentTarget.style.backgroundColor="#ef4444")},children:X.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),X.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:t.map((t,e)=>{var i,a,l;let c=null===(i=s.components)||void 0===i?void 0:i[e];const u=`${t.id||`component-${e}`}-entry-${v}-${o}-${e}`;return c||(c=null===(a=s.components)||void 0===a?void 0:a.find(e=>{var A,r;return e.name===t.name&&(null===(A=e.basic)||void 0===A?void 0:A.label)===(null===(r=t.basic)||void 0===r?void 0:r.label)})),c=c?c.id!==u?Object.assign(Object.assign({},c),{id:u,basic:Object.assign(Object.assign({},c.basic),{showLabel:!1})}):Object.assign(Object.assign({},c),{id:c.id,basic:Object.assign(Object.assign({},c.basic),{showLabel:!1})}):Object.assign(Object.assign({},t),{id:u,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),X.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[X.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:(null===(l=t.basic)||void 0===l?void 0:l.label)||`Field ${e+1}`}),X.jsxs("div",{style:{minHeight:"40px",display:"flex",alignItems:"center",flexDirection:"column",width:"100%"},children:[r?r(c):A(c),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(c.name)&&X.jsx(wt,{component:c,mode:"test",formTemplateId:f,formValue:d[c.id],onThresholdActionCompletion:p,onThresholdIssueRaised:g,onNotesChange:m?t=>m(c.id,t):void 0,onAttachmentChange:w?t=>w(c.id,t):void 0}),"preview"===n&&(()=>{var t,e;return(null===(t=c.basic)||void 0===t?void 0:t.notes)&&c.basic.notes.trim().length>0||(null===(e=c.basic)||void 0===e?void 0:e.attachments)&&Array.isArray(c.basic.attachments)&&c.basic.attachments.length>0?X.jsx(Bt,{component:c}):null})()]})]},`${s.id}-${e}`)})})]},s.id)):X.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. ",i?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]}),"test"===n&&i&&X.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:X.jsxs("button",{type:"button",onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!(e.length>=o)&&u)try{u()}catch(t){console.error("Error adding entry:",t)}},disabled:e.length>=o,style:{padding:"8px 16px",backgroundColor:e.length>=o?"#f3f4f6":"#10b981",color:e.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:e.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#059669")},onMouseLeave:t=>{e.length<o&&(t.currentTarget.style.backgroundColor="#10b981")},children:[X.jsx("span",{children:"+"}),s]})})]}),Qt=({id:t,properties:i,mode:s="edit",formData:a={},validationErrors:o={},touchedFields:l={},formSubmitted:c=!1,onValueChange:u,onSelect:h,isSelected:d=!1,className:f="",onDataGridSelect:p,onComponentSelect:g,onComponentDelete:m,onComponentEdit:w,onComponentUpdate:v,selectedComponent:B,renderFormComponent:b,onEntryAdd:y,onEntryRemove:C,formTemplateId:x,onThresholdActionCompletion:U,onThresholdIssueRaised:E,onNotesChange:N,onAttachmentChange:L,workOrderNumber:I,assetNumber:_,onCreateIssue:O,onUpdateIssue:k})=>{var T,j,H,P,D,M,R,K,V,z,G,q;const[W,Y]=e(!1),J=n(!1);let $=i.templateComponents||[];const Z=i.entries||[];0===$.length&&Z.length>0&&Z[0].components&&($=Z[0].components.map(t=>{var e;return Object.assign(Object.assign({},t),{id:(null===(e=t.id)||void 0===e?void 0:e.replace(/-entry-\d+$/,""))||t.id,basic:Object.assign(Object.assign({},t.basic),{showLabel:!0})})})),A(()=>{if("edit"===s&&!i.templateComponents&&u&&J.current){const e=Object.assign(Object.assign({},i),{templateComponents:[]});JSON.stringify(e)!==JSON.stringify(i)&&u({id:t,value:e})}J.current=!0},[i.templateComponents,t,u,i,s]),A(()=>{if($.length>0){if("test"===s&&0===Z.length&&J.current){const e={id:`entry-${t}-0`,index:0,components:$.map((e,A)=>{const r=e.id||`component-${A}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${t}-0-${A}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(u){const A=Object.assign(Object.assign({},i),{entries:[e]});JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A})}return}if("edit"!==s||!J.current)return;const e=Z.some(t=>{var e;return null===(e=t.components)||void 0===e?void 0:e.some((e,A)=>{var r;const n=`${null===(r=$[A])||void 0===r?void 0:r.id}-entry-${t.index}-${A}`;return e.id!==n})});if(e&&u){const e=Z.map(t=>{var e;return Object.assign(Object.assign({},t),{components:(null===(e=t.components)||void 0===e?void 0:e.map((e,A)=>{var r;return Object.assign(Object.assign({},e),{id:`${null===(r=$[A])||void 0===r?void 0:r.id}-entry-${t.index}-${A}`})}))||[]})}),A=Object.assign(Object.assign({},i),{entries:e});return void(JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A}))}if(0===Z.length&&"edit"===s){const e={id:`entry-${t}-0`,index:0,components:$.map((e,A)=>{const r=e.id||`component-${A}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${t}-0-${A}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(u){const A=Object.assign(Object.assign({},i),{entries:[e]});JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A})}}else if(Z.length>0){const e=Z.some(t=>$.some((e,A)=>{var r,n,i,s,a,o,l,c,u,h,d;const f=null===(r=t.components)||void 0===r?void 0:r[A];if(!f)return!0;const p=`${e.id}-entry-${t.index}-${A}`,g=f.id===p,m=JSON.stringify(null===(n=f.basic)||void 0===n?void 0:n.options)!==JSON.stringify(null===(i=e.basic)||void 0===i?void 0:i.options)||(null===(s=f.basic)||void 0===s?void 0:s.placeholder)!==(null===(a=e.basic)||void 0===a?void 0:a.placeholder)||(null===(o=f.basic)||void 0===o?void 0:o.defaultValue)!==(null===(l=e.basic)||void 0===l?void 0:l.defaultValue)||(null===(c=f.basic)||void 0===c?void 0:c.label)!==(null===(u=e.basic)||void 0===u?void 0:u.label)||(null===(h=f.validation)||void 0===h?void 0:h.required)!==(null===(d=e.validation)||void 0===d?void 0:d.required);return!g||m}));if(e&&u){const e=Z.map(e=>{const A=$.map((A,r)=>{var n,i;let s=null===(n=e.components)||void 0===n?void 0:n[r];s||(s=null===(i=e.components)||void 0===i?void 0:i.find(t=>{var e,r;return t.name===A.name&&(null===(e=t.basic)||void 0===e?void 0:e.label)===(null===(r=A.basic)||void 0===r?void 0:r.label)}));const a=`${A.id||`component-${r}`}-entry-${t}-${e.index}-${r}`;if(s){return Object.assign(Object.assign({},A),{id:a,basic:Object.assign(Object.assign({},A.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}return Object.assign(Object.assign({},A),{id:a,basic:Object.assign(Object.assign({},A.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})});return Object.assign(Object.assign({},e),{components:A})}),A=Object.assign(Object.assign({},i),{entries:e});JSON.stringify(A)!==JSON.stringify(i)&&u({id:t,value:A})}}}},[$,Z,t,u,i,s,i.templateComponents]);const tt=r(t=>{t.stopPropagation(),null==h||h(),null==p||p(i)},[h,p,i]),et=r((e,A)=>{A.stopPropagation(),m&&m(e,A);const r=$.filter(t=>t.id!==e.id),n=Z.map(t=>{var A;return Object.assign(Object.assign({},t),{components:(null===(A=t.components)||void 0===A?void 0:A.filter(t=>{var A,r;return!(t.name===e.name&&(null===(A=t.basic)||void 0===A?void 0:A.label)===(null===(r=e.basic)||void 0===r?void 0:r.label))}))||[]})});u&&u({id:t,value:Object.assign(Object.assign({},i),{templateComponents:r,entries:n})})},[m,i,u,t,$,Z]),At=r((e,A)=>{v&&v(e,A);const r=$.map(t=>t.id===e?Object.assign(Object.assign({},t),A):t);u&&u({id:t,value:Object.assign(Object.assign({},i),{templateComponents:r})})},[v,i,u,t,$]),rt=r(t=>{"test"===s&&u&&u({id:t.id,value:t.value})},[u]),nt=r(()=>{const e=i.entries||[],A=e.length,r={id:`entry-${t}-${A}`,index:A,components:$.map((e,r)=>{const n=`${e.id||`component-${r}`}-entry-${t}-${A}-${r}`;return Object.assign(Object.assign({},e),{id:n,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}},n=[...e,r];u&&u({id:t,value:Object.assign(Object.assign({},i),{entries:n})}),null==y||y()},[i,u,t,y,$]),ct=r(e=>{const A=i.entries.filter((t,A)=>A!==e).map((e,A)=>Object.assign(Object.assign({},e),{index:A,id:`entry-${t}-${A}`}));u&&u({id:t,value:Object.assign(Object.assign({},i),{entries:A})})},[i,u,t,C]),dt=r((t,e=!1)=>{var A,r,n;const i=a[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let u=i;"number-input"===t.name&&"number"==typeof i?u=String(i):"number-input"===t.name&&null==i&&(u="");const h={id:t.id,properties:t,validationErrors:o||{},formValue:u,touchedFields:l||{},formSubmitted:c||!1,mode:s,hideLabel:e,onValueChange:rt,onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return X.jsx(it,Object.assign({},h,{properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1,hideLabel:e}));case"textarea":return X.jsx(st,Object.assign({},h,{properties:t,readonly:!1,disabled:!1,hideLabel:e}));case"select":const i=Object.assign(Object.assign({},t),{options:(null===(A=t.basic)||void 0===A?void 0:A.options)||[]});return X.jsx(at,Object.assign({},h,{properties:i,disabled:!1,hideLabel:e}));case"checkbox":const s=Object.assign(Object.assign({},t),{options:(null===(r=t.basic)||void 0===r?void 0:r.options)||[]});return X.jsx(ot,Object.assign({},h,{properties:s,formValue:[],disabled:!1,hideLabel:e}));case"radio":const a=Object.assign(Object.assign({},t),{options:(null===(n=t.basic)||void 0===n?void 0:n.options)||[]});return X.jsx(lt,Object.assign({},h,{properties:a,readonly:!1,disabled:!1,hideLabel:e}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},h,{properties:t,readonly:!1,disabled:!1,hideLabel:e}));case"signature":return X.jsx(ht,Object.assign({},h,{properties:t,hideLabel:e}));case"heading":return X.jsx(pt,Object.assign({},h,{properties:t,hideLabel:e}));case"instructions":return X.jsx(gt,Object.assign({},h,{properties:t,hideLabel:e}));default:return X.jsxs("div",{className:"unknown-component",children:["Unknown component: ",t.name]})}},[s,rt,a,o,l,c]),ft={backgroundColor:i.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:i.styles.borderColor||"var(--df-color-fb-border)",borderWidth:i.styles.borderWidth||"2px",borderRadius:i.styles.borderRadius||"8px",padding:i.styles.padding||"16px",margin:i.styles.margin||"16px 0"};return X.jsxs("div",{className:`form-group df-form-datagrid ${d?"selected":""} ${f}`,onClick:tt,style:ft,children:[X.jsx("div",{className:"grid-header",children:X.jsx("div",{className:"grid-title",onClick:e=>{e.stopPropagation(),Y(!W),null==u||u({id:t,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{collapsed:!W})})})},children:X.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[W?X.jsx(Q,{size:16}):X.jsx(F,{size:16}),X.jsx(S,{size:16}),X.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:i.basic.label}),i.validation.required&&X.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),i.basic.description&&!W&&X.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:i.basic.description}),!W&&X.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===s?X.jsx(xt,{gridComponents:$,mode:s,onComponentSelect:g||(()=>{}),onComponentDelete:et,onComponentEdit:w,onComponentUpdate:At,selectedComponent:B||null,renderFormComponent:b||dt,gridId:t,formData:a,formTemplateId:x,onThresholdActionCompletion:U,onThresholdIssueRaised:E,onNotesChange:N,onAttachmentChange:L,workOrderNumber:I,assetNumber:_,onCreateIssue:O,onUpdateIssue:k}):X.jsx(Ft,{templateComponents:$,dataEntries:Z,renderFormComponent:b||dt,mode:s,allowAddRemoveEntries:null===(j=null===(T=i.datagrid)||void 0===T?void 0:T.allowAddRemoveEntries)||void 0===j||j,addAnotherText:null!==(P=null===(H=i.datagrid)||void 0===H?void 0:H.addAnotherText)&&void 0!==P?P:"Add Entry",removeText:null!==(M=null===(D=i.datagrid)||void 0===D?void 0:D.removeText)&&void 0!==M?M:"Remove",maxEntries:null!==(K=null===(R=i.datagrid)||void 0===R?void 0:R.maxEntries)&&void 0!==K?K:10,minEntries:null!==(z=null===(V=i.datagrid)||void 0===V?void 0:V.minEntries)&&void 0!==z?z:1,displayAsGrid:null===(q=null===(G=i.datagrid)||void 0===G?void 0:G.displayAsGrid)||void 0===q||q,onAddEntry:y||nt,onRemoveEntry:C||ct,formData:a,formTemplateId:x,onThresholdActionCompletion:U,onThresholdIssueRaised:E,onNotesChange:N,onAttachmentChange:L,datagridId:t,workOrderNumber:I,assetNumber:_,onCreateIssue:O,onUpdateIssue:k})})]})},Ut=t.lazy(()=>Promise.resolve().then(function(){return kt})),Et=({formComponents:i=[],currentDevice:s="desktop",isPreviewMode:a=!1,initialFormData:o=[],onSubmit:l,onFormDataChange:c,formTitle:u,formDescription:h,formTemplateId:d,onComponentSelect:f,onComponentDelete:p,onComponentEdit:g,onComponentUpdate:m,selectedComponent:w,workOrderNumber:v,assetNumber:B,isStandalone:b,user:y,onCreateIssue:C,onUpdateIssue:x})=>{const[F,Q]=e({}),[U,E]=e({}),[N,S]=e(!1),[L,I]=e({}),[_,O]=e({}),[k,T]=e(new Set),[j,H]=e(new Map),[P,D]=e({isValid:!0}),[M,R]=e({}),[K,V]=e({});A(()=>{G()},[i,o]);const z=(t,e)=>{t.forEach(t=>{if(t.id&&(void 0!==e[t.id]||(t.basic&&"value"in t.basic&&void 0!==t.basic.value&&""!==t.basic.value&&null!==t.basic.value?e[t.id]=t.basic.value:t.basic&&"defaultValue"in t.basic&&void 0!==t.basic.defaultValue&&""!==t.basic.defaultValue&&null!==t.basic.defaultValue?e[t.id]=t.basic.defaultValue:"checkbox"===t.name||"select"===t.name?e[t.id]=[]:e[t.id]="")),t.cells&&Array.isArray(t.cells)&&t.cells.forEach((t,A)=>{Array.isArray(t)&&t.forEach((t,A)=>{t&&t.components&&Array.isArray(t.components)&&z(t.components,e)})}),t.entries&&Array.isArray(t.entries)&&t.entries.forEach((t,A)=>{t&&t.components&&Array.isArray(t.components)&&z(t.components,e)}),"file"===t.name&&t.basic){const A=t.basic.files||t.basic.attachments||t.basic.value;A&&(e[t.id]=A)}if(t.id&&t.basic&&t.basic.notes,"instructions"===t.name&&t.basic){t.basic.instructions||(t.basic.instructions=[]);const A=t.basic.value||t.basic.instructions;A&&(e[t.id]=A)}t.children&&Array.isArray(t.children)&&z(t.children,e)})},G=r(()=>{const t={},e={},A={},r=new Set,n=t=>{t.forEach(t=>{var r,i,s,a,o;t.id&&(((null===(r=t.basic)||void 0===r?void 0:r.notes)||(null===(i=t.basic)||void 0===i?void 0:i.comments))&&(e[t.id]=(null===(s=t.basic)||void 0===s?void 0:s.notes)||(null===(a=t.basic)||void 0===a?void 0:a.comments)),(null===(o=t.basic)||void 0===o?void 0:o.attachments)&&(A[t.id]=t.basic.attachments)),t.children&&n(t.children),t.cells&&t.cells.forEach(t=>t.forEach(t=>{t.components&&n(t.components)})),t.entries&&t.entries.forEach(t=>{t.components&&n(t.components)})})},s=t=>{t.forEach((t,e)=>{var A;if(t.id&&"string"==typeof t.id&&""!==t.id.trim())r.has(t.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${t.id}. Component:`,t),t.id=`${t.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${t.id}`));else{const r=t.name||"component",n=((null===(A=t.basic)||void 0===A?void 0:A.label)||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);t.id=`${r}-${n||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${e}`}r.add(t.id),t.children&&Array.isArray(t.children)&&s(t.children),t.cells&&Array.isArray(t.cells)&&t.cells.forEach(t=>{Array.isArray(t)&&t.forEach(t=>{t&&t.components&&Array.isArray(t.components)&&s(t.components)})}),t.entries&&Array.isArray(t.entries)&&t.entries.forEach(t=>{t&&t.components&&Array.isArray(t.components)&&s(t.components)})})};i&&i.length>0&&s(i),o&&o.length>0&&s(o),o&&o.length>0&&z(o,t),o&&o.length>0&&z(o,t),i&&i.length>0&&(z(i,t),n(i)),Q(e=>Object.assign(Object.assign({},t),e)),R(t=>Object.assign(Object.assign({},e),t)),V(t=>Object.assign(Object.assign({},A),t)),W()},[o,i]),q=(t,e)=>{t.forEach(t=>{if(t.id)if("table"===t.name||"datagrid"===t.name)e[t.id]=!0;else if(t.conditional){const A=J.evaluateConditionalLogic(t.conditional,i,F);e[t.id]=A.shouldShow}else e[t.id]=!0;t.cells&&Array.isArray(t.cells)&&t.cells.forEach(t=>{t.forEach(t=>{t.components&&Array.isArray(t.components)&&q(t.components,e)})}),t.entries&&Array.isArray(t.entries)&&t.entries.forEach(t=>{t.components&&Array.isArray(t.components)&&q(t.components,e)}),t.children&&Array.isArray(t.children)&&q(t.children,e)})},W=r(()=>{const t={};i&&i.length>0&&q(i,t),O(t)},[i,F]),Y=r(t=>{const e=i.find(e=>e.id===t);if(e&&("table"===e.name||"datagrid"===e.name))return!0;return!1!==_[t]},[_,i]),Z=r(t=>{if(!t.id||"string"!=typeof t.id||""===t.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",t);const e=i.filter(e=>e.id===t.id);if(e.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${t.id}":`,e.map(t=>{var e;return{id:t.id,name:t.name,label:null===(e=t.basic)||void 0===e?void 0:e.label}}));const A=F[t.id];void 0!==A&&A!==t.value&&console.log("[DfFormPreview] Updating form value:",{id:t.id,oldValue:A,newValue:t.value});const r=Object.assign(Object.assign({},F),{[t.id]:t.value});Q(r);const n=i.find(e=>e.id===t.id);if(n){const t=null==n?void 0:n.threshold;t&&t.conditions&&t.conditions.length>0&&T(e=>{const A=new Set(e);return t.conditions.forEach(t=>{A.delete(t.id)}),A})}const s=e=>e.map(e=>{var A;return e.id===t.id&&"defaultValue"in e.basic?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{value:null!==(A=t.value)&&void 0!==A?A:e.basic.defaultValue,defaultValue:t.value})}):"section"===e.name&&e.children?Object.assign(Object.assign({},e),{children:s(e.children)}):"table"===e.name&&e.cells?Object.assign(Object.assign({},e),{cells:e.cells.map(t=>t.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=s(e.components)),e}))}):"datagrid"===e.name&&e.entries?Object.assign(Object.assign({},e),{entries:e.entries.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=s(e.components)),e})}):e}),o=s(i);if(null==c||c(o),U[t.id]&&E(e=>Object.assign(Object.assign({},e),{[t.id]:""})),!a){if(t.isValid)return void E(e=>{const A=e[t.id];return A&&""!==A.trim()?Object.assign(Object.assign({},e),{[t.id]:""}):e});setTimeout(()=>{et(t.id)},150)}setTimeout(()=>{const t={};i.forEach(e=>{if("table"===e.name||"datagrid"===e.name)t[e.id]=!0;else if(e.conditional){const A=J.evaluateConditionalLogic(e.conditional,i,r);t[e.id]=A.shouldShow}else t[e.id]=!0}),O(t)},0)},[i,F,U,c]),tt=r((t,e)=>{for(const A of t){if(A.id===e)return A;if("section"===A.name&&A.children){const t=tt(A.children,e);if(t)return t}if("table"===A.name&&A.cells)for(const t of A.cells)for(const A of t)if(A.components){const t=tt(A.components,e);if(t)return t}if("datagrid"===A.name&&A.entries)for(const t of A.entries)if(t.components){const A=tt(t.components,e);if(A)return A}}return null},[]),et=r(t=>{if(a)return;const e=tt(i,t);if(!e)return;const A=F[t]||"";if("number-input"===e.name&&(!A||""===A)){if(e.validation.required){const A=e.validation.customValidationMessage,r=e.basic.label||"This field",n=A||`${r} is required`;E(e=>Object.assign(Object.assign({},e),{[t]:n}))}else E(e=>Object.assign(Object.assign({},e),{[t]:""}));return}let r=!1;r=Array.isArray(A)?A.length>0:"string"==typeof A?""!==A.trim():null!=A;let n="";if(e.validation.required&&!r){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} is required`}else if("email-input"===e.name&&r&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(A)){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} must be a valid email`}else if(e.validation.minLength&&r&&A.length<e.validation.minLength){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} must be at least ${e.validation.minLength} characters`}else if(e.validation.maxLength&&r&&A.length>e.validation.maxLength){const t=e.validation.customValidationMessage,A=e.basic.label||"This field";n=t||`${A} must be no more than ${e.validation.maxLength} characters`}else if("number-input"===e.name&&r){const t=String(A).trim(),r=parseFloat(t);if(!isNaN(r)){const t=e.validation;t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&r<t.lowerLimit?n="Number is below the lower limit":t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&r>t.upperLimit&&(n="Number is above the upper limit")}}E(e=>Object.assign(Object.assign({},e),{[t]:n}))},[i,a,F,tt]),At=r(t=>{I(e=>Object.assign(Object.assign({},e),{[t]:!0})),a||setTimeout(()=>{et(t)},0)},[a,et]),rt=r(t=>{U[t]&&E(e=>Object.assign(Object.assign({},e),{[t]:""}))},[U]),nt=r(()=>!Object.values(U).some(t=>t&&"string"==typeof t&&""!==t.trim())&&i.every(t=>{const e=F[t.id]||"";let A=!1;if(A=Array.isArray(e)?e.length>0:"string"==typeof e?""!==e.trim():null!=e,t.validation.required&&!A)return!1;if("number-input"===t.name&&A){const A=String(e).trim(),r=parseFloat(A);if(!isNaN(r)){const e=t.validation;if(e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&r<e.lowerLimit)return!1;if(e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&r>e.upperLimit)return!1}}return!0}),[i,F,U]),mt=r((t,e)=>{if(Array.isArray(e))return e.some(e=>mt(t,e));if(null==e||""===e)return!1;const A="string"==typeof e?parseFloat(e):e,r="string"==typeof t.value?parseFloat(t.value):t.value;if(!isNaN(A)&&!isNaN(r))switch(t.operator){case"greaterThan":return A>r;case"lessThan":return A<r;case"greaterThanOrEqual":return A>=r;case"lessThanOrEqual":return A<=r;case"equals":return A===r;case"notEquals":return A!==r;default:return!1}const n=String(e).toLowerCase(),i=String(t.value).toLowerCase();switch(t.operator){case"equals":return n===i||String(e)===String(t.value);case"notEquals":return n!==i&&String(e)!==String(t.value);default:return!1}},[]),vt=r(()=>{if(a)return[];const t=[];return i.forEach(e=>{const A=null==e?void 0:e.condition;if(!A||!A.conditions||0===A.conditions.length)return;const r=F[e.id];null!=r&&""!==r&&!(Array.isArray(r)&&0===r.length)&&A.conditions.forEach(A=>{var n;mt(A,r)&&t.push({componentId:e.id,condition:A,componentLabel:(null===(n=e.basic)||void 0===n?void 0:n.label)||"Field"})})}),t},[i,F,a,mt]),bt=r(()=>{if(a)return{isValid:!0};const t=vt();if(0===t.length)return{isValid:!0};for(const{condition:e,componentLabel:A}of t){const t=j.get(e.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},r=[];if(!0!==e.enableRaiseIssue||k.has(e.id)||r.push("raise an issue"),!0!==e.enableNotes||t.notesCompleted||r.push("add notes"),!0!==e.enableAttachment||t.attachmentsCompleted||r.push("add attachments"),!0!==e.enableSendEmail||t.emailSent||r.push("send email"),r.length>0){return{isValid:!1,errorMessage:`Please ${1===r.length?r[0]:r.slice(0,-1).join(", ")+" and "+r[r.length-1]} for the threshold condition met in "${A}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[a,vt,k,j]),Ct=r(t=>{t&&T(e=>{const A=new Set(e);return A.add(t),A})},[]),xt=r((t,e,A)=>{t&&H(r=>{const n=new Map(r),i=n.get(t)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===e?n.set(t,Object.assign(Object.assign({},i),{notesCompleted:A})):"attachments"===e?n.set(t,Object.assign(Object.assign({},i),{attachmentsCompleted:A})):"email"===e&&n.set(t,Object.assign(Object.assign({},i),{emailSent:A})),n})},[]);A(()=>{if(!a){const t=bt();D(t)}},[F,k,j,a,bt]);const Ft=r(()=>{if(a)return!0;let t=!0;S(!0);const e={};return i.forEach(A=>{const r=F[A.id]||"";let n=!1;if(n=Array.isArray(r)?r.length>0:"string"==typeof r?""!==r.trim():null!=r,A.validation.required&&!n){const r=A.validation.customValidationMessage,n=A.basic.label||"This field",i=r||`${n} is required`;e[A.id]=i,t=!1}else if("number-input"===A.name&&n){const n=String(r).trim(),i=parseFloat(n);if(isNaN(i))e[A.id]="";else{const r=A.validation;r&&"lowerLimit"in r&&void 0!==r.lowerLimit&&null!==r.lowerLimit&&0!==r.lowerLimit&&i<r.lowerLimit?(e[A.id]="Number is below the lower limit",t=!1):r&&"upperLimit"in r&&void 0!==r.upperLimit&&null!==r.upperLimit&&0!==r.upperLimit&&i>r.upperLimit?(e[A.id]="Number is above the upper limit",t=!1):e[A.id]=""}}else e[A.id]="";I(t=>Object.assign(Object.assign({},t),{[A.id]:!0}))}),E(e),t},[i,a,F]),Et=r((t="Submitted")=>{if(S(!0),!Ft()){const t=i.find(t=>{const e=F[t.id]||"";let A=!1;return A=Array.isArray(e)?e.length>0:"string"==typeof e?""!==e.trim():null!=e,t.validation.required&&!A});if(t){const e=document.getElementById(t.id);e&&e.focus()}return}const e=bt();if(!e.isValid){e.errorMessage&&$.showError(e.errorMessage);const t=vt().find(({condition:t})=>!k.has(t.id));if(t){const e=document.getElementById(t.componentId);e&&e.scrollIntoView({behavior:"smooth",block:"center"})}return}const A=t=>t.map(t=>{var e,r,n,i,s,a;let o=F[t.id];"text-input"===t.name&&(null===(e=t.basic)||void 0===e||e.label),void 0===o&&(o="value"in t.basic&&void 0!==t.basic.value?t.basic.value:"defaultValue"in t.basic&&void 0!==t.basic.defaultValue?t.basic.defaultValue:""),"text-input"===t.name&&(null===(r=t.basic)||void 0===r||r.label);const l=Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{value:o,defaultValue:o,notes:void 0!==M[t.id]?M[t.id]:null===(n=t.basic)||void 0===n?void 0:n.notes,comments:void 0!==M[t.id]?M[t.id]:(null===(i=t.basic)||void 0===i?void 0:i.comments)||(null===(s=t.basic)||void 0===s?void 0:s.notes),attachments:void 0!==K[t.id]?K[t.id]:null===(a=t.basic)||void 0===a?void 0:a.attachments})});return"section"===l.name&&l.children&&(l.children=A(l.children)),"table"===l.name&&l.cells&&(l.cells=l.cells.map(t=>t.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=A(e.components)),e}))),"datagrid"===l.name&&l.entries&&(l.entries=l.entries.map(t=>{const e=Object.assign({},t);return e.components&&(e.components=A(e.components)),e})),l}),r=A(i),n=Object.assign(Object.assign({},F),{status:t});null==l||l(r,n)},[i,F,Ft,l,M,K]),Nt=r(()=>({[`device-${s}`]:!0,readonly:a}),[s,a]),St=r((t,e)=>{R(A=>Object.assign(Object.assign({},A),{[t]:e}))},[]),Lt=r((t,e)=>{V(A=>Object.assign(Object.assign({},A),{[t]:e||[]}))},[]),It=n(new Map),_t=n(0),Ot=e=>{var A,r,n,s,a,o,l,u,h,b,E,S,I;let _;if(e.id&&"string"==typeof e.id&&""!==e.id.trim())_=e.id;else{const t=(null===(A=e.basic)||void 0===A?void 0:A.label)||"",r=e.name||"unknown",n=`${r}-${t}`;let i=It.current.get(n);i||(_t.current+=1,i=`generated-${r}-${_t.current}-${Math.random().toString(36).substr(2,9)}`,It.current.set(n,i),console.warn("[DfFormPreview] Generated and cached ID for component:",i,"key:",n)),_=i,e=Object.assign(Object.assign({},e),{id:_})}const O=_,T=F[O];if(void 0!==T){const t=i.filter(t=>t.id!==O&&F[t.id]===T);t.length>0&&console.warn(`[DfFormPreview] Component ${O} shares form value with other components:`,t.map(t=>t.id))}const j={id:O,validationErrors:U,formValue:T,touchedFields:L,formSubmitted:N,mode:"test",readonly:!1,onValueChange:Z,onBlur:()=>At(O),onFocus:()=>rt(O)};switch(e.name){case"text-input":case"number-input":case"email-input":return X.jsx(it,Object.assign({},j,{properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",formTemplateId:d,onThresholdIssueRaised:Ct,raisedThresholdIssues:k,workOrderNumber:v,assetNumber:B,user:y}));case"textarea":return X.jsx(st,Object.assign({},j,{properties:e}));case"select":const A=Object.assign(Object.assign({},e),{options:(null===(r=e.basic)||void 0===r?void 0:r.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(n=e.basic)||void 0===n?void 0:n.comments)||""})});return X.jsx(at,Object.assign({},j,{properties:A}));case"checkbox":const _=Object.assign(Object.assign({},e),{options:(null===(s=e.basic)||void 0===s?void 0:s.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(a=e.basic)||void 0===a?void 0:a.comments)||""})});return X.jsx(ot,Object.assign({},j,{properties:_}));case"radio":const O=Object.assign(Object.assign({},e),{options:(null===(o=e.basic)||void 0===o?void 0:o.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(l=e.basic)||void 0===l?void 0:l.comments)||""})});return X.jsx(lt,Object.assign({},j,{properties:O}));case"segment":const H=Object.assign(Object.assign({},e),{options:(null===(u=e.basic)||void 0===u?void 0:u.options)||[],basic:Object.assign(Object.assign({},e.basic),{comments:(null===(h=e.basic)||void 0===h?void 0:h.comments)||""})});return X.jsx(ct,Object.assign({},j,{properties:H}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},j,{properties:e}));case"signature":return X.jsx(ht,Object.assign({},j,{properties:e}));case"heading":return X.jsx(pt,Object.assign({},j,{properties:e}));case"instructions":const P=T||(null===(b=e.basic)||void 0===b?void 0:b.value)||null;return X.jsx(gt,Object.assign({},j,{properties:e,formValue:P}));case"location":return X.jsx(ft,Object.assign({},j,{properties:e}));case"section":return X.jsx(yt,Object.assign({},j,{properties:e,formData:F,formTemplateId:d,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,onNotesChange:St,onAttachmentChange:Lt,workOrderNumber:v,assetNumber:B,user:y,onCreateIssue:C,onUpdateIssue:x,renderFormComponent:t=>Ot(t)}));case"table":return X.jsx(t.Suspense,{fallback:X.jsx("div",{children:"Loading table..."}),children:X.jsx(Ut,Object.assign({},j,{properties:e,formData:F,formTemplateId:d,mode:j.mode,validationErrors:U,touchedFields:L,formSubmitted:N,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,workOrderNumber:v,assetNumber:B,onCreateIssue:C,onUpdateIssue:x,onNotesChange:(t,A)=>{const r=i.map(r=>{if(r.id===e.id&&r.cells){const e=r.cells.map(e=>e.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{notes:A})}):e);return Object.assign(Object.assign({},e),{components:r})}return e}));return Object.assign(Object.assign({},r),{cells:e})}return r});null==c||c(r)},onAttachmentChange:(t,A)=>{const r=i.map(r=>{if(r.id===e.id&&r.cells){const e=r.cells.map(e=>e.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{attachments:A||[]})}):e);return Object.assign(Object.assign({},e),{components:r})}return e}));return Object.assign(Object.assign({},r),{cells:e})}return r});null==c||c(r)},renderFormComponent:t=>Ot(t)}))});case"datagrid":return X.jsx(Qt,Object.assign({},j,{properties:e,formData:F,formTemplateId:d,mode:j.mode,validationErrors:U,touchedFields:L,formSubmitted:N,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,workOrderNumber:v,assetNumber:B,onComponentSelect:f,onComponentDelete:p,onComponentEdit:g,onCreateIssue:C,onUpdateIssue:x,onComponentUpdate:m,selectedComponent:w,onNotesChange:(t,A)=>{St(t,A);const r=i.map(r=>{if(r.id===e.id&&r.entries){const e=r.entries.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{notes:A||""})}):e);return Object.assign(Object.assign({},e),{components:r})}return e});return Object.assign(Object.assign({},r),{entries:e})}return r});null==c||c(r)},onAttachmentChange:(t,A)=>{Lt(t,A);const r=i.map(r=>{if(r.id===e.id&&r.entries){const e=r.entries.map(e=>{if(e.components){const r=e.components.map(e=>e.id===t?Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{attachments:A||[]})}):e);return Object.assign(Object.assign({},e),{components:r})}return e});return Object.assign(Object.assign({},r),{entries:e})}return r});null==c||c(r)},onValueChange:t=>{if(t.id===e.id&&t.value&&"object"==typeof t.value&&"entries"in t.value){const A=i.map(A=>A.id===e.id?Object.assign(Object.assign({},A),t.value):A);null==c||c(A),t.value.entries&&Array.isArray(t.value.entries)&&t.value.entries.forEach(t=>{t.components&&Array.isArray(t.components)&&t.components.forEach(t=>{var e;if(void 0!==F[t.id]);else{const A=null===(e=t.basic)||void 0===e?void 0:e.defaultValue;void 0!==A&&Q(e=>Object.assign(Object.assign({},e),{[t.id]:A}))}})})}else Z(t)},onEntryAdd:()=>{const t=i.find(t=>t.id===e.id);if(t&&t.entries){const t=i.map(t=>t.id===e.id?Object.assign(Object.assign({},t),{entries:t.entries||[]}):t);null==c||c(t)}else setTimeout(()=>{const t=F[e.id];if(t&&"object"==typeof t&&"entries"in t){const A=i.map(A=>A.id===e.id?Object.assign(Object.assign({},A),{entries:t.entries}):A);null==c||c(A)}},100)},onEntryRemove:t=>{const A=i.map(A=>{if(A.id===e.id&&A.entries){const e=(A.entries||[]).filter((e,A)=>A!==t).map((t,e)=>{var r;return Object.assign(Object.assign({},t),{index:e,id:`entry-${A.id}-${e}`,components:(null===(r=t.components)||void 0===r?void 0:r.map((t,A)=>{const r=(t.templateComponents||[])[A];return Object.assign(Object.assign({},t),{id:r?`${r.id}-entry-${e}-${A}`:t.id})}))||[]})});return Object.assign(Object.assign({},A),{entries:e})}return A});null==c||c(A)},renderFormComponent:t=>Ot(t)}));case"file":const D=T||(null===(E=e.basic)||void 0===E?void 0:E.value)||(null===(S=e.basic)||void 0===S?void 0:S.files)||(null===(I=e.basic)||void 0===I?void 0:I.attachments)||null;return X.jsx(dt,Object.assign({},j,{properties:e,formValue:D}));default:return X.jsx("div",{className:"form-group",children:X.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}};return X.jsx("div",{className:"form-preview-container",children:X.jsx("div",{className:"form-preview-wrapper",children:X.jsxs("div",{className:`form-preview ${Object.entries(Nt()).map(([t,e])=>e?t:"").join(" ")}`,children:[X.jsx("div",{className:"form-canvas-header"}),0===i.length?X.jsx("div",{className:"empty-state",children:X.jsx("div",{className:"empty-state-card",children:X.jsx("div",{className:"empty-state-preview-area",children:X.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):X.jsxs("form",{className:"form-preview-form",onSubmit:t=>{t.preventDefault(),Et()},children:[(u||h)&&X.jsxs("div",{className:"form-header",children:[u&&X.jsx("h1",{className:"form-title",children:u}),h&&X.jsx("p",{className:"form-description",children:h})]}),i.map(t=>{var e,A,r,n;const s=t.basic,o=F[t.id],l=["select","radio","checkbox","segment"].includes(t.name||""),u=t.options||(null==s?void 0:s.options)||[],h=(()=>{var e;const A=null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.column;return"section"===t.name||"table"===t.name||"datagrid"===t.name?"col-12":3===A?"col-3":6===A?"col-6":9===A?"col-9":"col-12"})();let f=!1;if(!a)if(l&&null!=o&&""!==o)if("checkbox"===t.name){f=(Array.isArray(o)?o:[o]).some(t=>{const e=u.find(e=>e.value===t);return e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)})}else{const t=u.find(t=>t.value===o);f=t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)}else f=(null==s?void 0:s.enableNotes)||(null==s?void 0:s.enableAttachment)||(null==s?void 0:s.enableRaiseIssue)||(null==s?void 0:s.enableSendEmail);const p=a&&((null===(e=t.basic)||void 0===e?void 0:e.notes)&&t.basic.notes.trim().length>0||(null===(A=t.basic)||void 0===A?void 0:A.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0);return X.jsxs("div",{className:`form-group ${h} ${f||p?"has-action-features":""}`,style:{display:Y(t.id)?"block":"none"},children:[Ot(t),!a&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:a?"preview":"test",formTemplateId:d,formValue:o,onThresholdActionCompletion:xt,onThresholdIssueRaised:Ct,onNotesChange:e=>{R(A=>Object.assign(Object.assign({},A),{[t.id]:e}));const A=i.map(A=>A.id===t.id?Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{notes:e||""})}):A);null==c||c(A)},onAttachmentChange:e=>{V(A=>Object.assign(Object.assign({},A),{[t.id]:e||[]}));const A=i.map(A=>A.id===t.id?Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{attachments:e||[]})}):A);null==c||c(A)},notes:void 0!==M[t.id]?M[t.id]:(null===(r=t.basic)||void 0===r?void 0:r.notes)||"",attachments:void 0!==K[t.id]?K[t.id]:(null===(n=t.basic)||void 0===n?void 0:n.attachments)||null,workOrderNumber:v,assetNumber:B,isStandalone:b,user:y,onCreateIssue:C,onUpdateIssue:x}),a&&p&&X.jsx(Bt,{component:t})]},t.id)}),!a&&X.jsxs("div",{className:"form-actions",children:[X.jsx("button",{type:"button",onClick:()=>Et("Saved"),className:"form-save-button",disabled:N&&!nt(),children:"Save"}),X.jsx("button",{type:"button",disabled:!nt()||!P.isValid,className:"form-submit-button",title:P.isValid?"":P.errorMessage,onClick:()=>Et("Submitted"),children:"Submit"})]})]})]})})})},Nt=({comment:t="",onSave:n,placeholder:i="Enter your reason...",className:s="",disabled:a=!1})=>{const[o,l]=e(!0),[c,u]=e(t),[h,d]=e(!1);A(()=>{u(t),d(!1)},[t]);const f=r(e=>{const A=e.target.value;u(A),d(A!==t)},[t]),p=r(()=>{h&&n&&!a&&(n(c),d(!1))},[h,n,c,a]),g=r(()=>{},[]),m=r(()=>{a||l(!o)},[o,a]);return X.jsxs("div",{className:`df-form-comments ${s}`,children:[X.jsxs("div",{className:"df-form-comments__header",children:[X.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),X.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:m,"aria-expanded":o,"aria-label":"Toggle comments section",disabled:a,children:o?X.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):X.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),X.jsx("div",{className:"df-form-comments__content "+(o?"df-form-comments__content--expanded":""),children:X.jsx("div",{className:"df-form-comments__input-container",children:X.jsx("div",{className:"df-form-comments__input-line",children:X.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:c,onChange:f,onBlur:p,onFocus:g,placeholder:i,disabled:a})})})})]})},St=t=>t.id?t:Object.assign(Object.assign({},t),{id:D()}),Lt=({component:t,mode:e,renderFormComponent:A,formData:r={},formTemplateId:n,onThresholdActionCompletion:i,onThresholdIssueRaised:s,onNotesChange:a,onAttachmentChange:o,workOrderNumber:l,assetNumber:c,user:u,onCreateIssue:h,onUpdateIssue:d})=>{var f,p;const g=r[t.id],m="preview"===e&&((null===(f=t.basic)||void 0===f?void 0:f.notes)&&t.basic.notes.trim().length>0||(null===(p=t.basic)||void 0===p?void 0:p.attachments)&&Array.isArray(t.basic.attachments)&&t.basic.attachments.length>0);return X.jsxs("div",{className:"simple-table-component",children:[A(t),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(t.name)&&X.jsx(wt,{component:t,mode:"test",formTemplateId:n,formValue:g,onThresholdActionCompletion:i,onThresholdIssueRaised:s,onNotesChange:a?e=>a(t.id,e):void 0,onAttachmentChange:o?e=>o(t.id,e):void 0,workOrderNumber:l,assetNumber:c,user:u,onCreateIssue:h,onUpdateIssue:d}),m&&X.jsx(Bt,{component:t})]})},It=({component:t,selectedComponent:e,mode:A,onComponentSelect:r,onComponentDelete:n,onComponentEdit:i,renderFormComponent:s,isOverlay:a=!1})=>{const{attributes:o,listeners:l,setNodeRef:c,transform:u,transition:h,isDragging:d,isSorting:f}=j({id:t.id,disabled:a}),p={transform:P.Transform.toString(u),transition:h,opacity:d?.3:1,zIndex:d?1e3:"auto"};return X.jsxs("div",{ref:c,style:p,className:`form-component table-component ${(null==e?void 0:e.id)===t.id?"selected":""} ${d?"dragging":""} ${f?"sorting":""}`,onClick:()=>!d&&r(t),role:"button",tabIndex:0,children:["edit"===A&&X.jsx("div",Object.assign({className:"component-drag-handle"},l,o,{onClick:t=>t.stopPropagation(),style:{opacity:1},children:X.jsx(U,{size:14})})),X.jsx("div",{className:"component-content",children:s(t)}),"edit"===A&&X.jsxs("div",{className:"component-actions",style:{opacity:1},children:[i&&X.jsx("button",{className:"component-edit-btn",onClick:e=>{e.stopPropagation(),i(t)},type:"button",title:"Edit Component",children:X.jsx(E,{size:12})}),X.jsx("button",{className:"component-delete-btn",onClick:e=>{e.stopPropagation(),n(t,e)},type:"button",title:"Delete Component",children:X.jsx(N,{size:12})})]})]})},_t=({cell:t,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,selectedComponent:i,renderFormComponent:s,formData:a={},formTemplateId:o,onThresholdActionCompletion:l,onThresholdIssueRaised:c,tableId:u,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w})=>{var v,B,b,y,C;const x=`table-cell-${u}-${t.row}-${t.column}`,{setNodeRef:F,isOver:Q}=O({id:x,disabled:"edit"!==e,data:{type:"table-cell",tableId:u,cell:t,row:t.row,column:t.column}}),U=Object.assign(Object.assign({},t.styles),{backgroundColor:Q?"var(--df-color-primary-light)":(null===(v=t.styles)||void 0===v?void 0:v.backgroundColor)||"transparent",minHeight:(null===(B=t.styles)||void 0===B?void 0:B.minHeight)||"preview"===e||"test"===e?"40px":"60px",padding:(null===(b=t.styles)||void 0===b||b.padding,"8px"),border:"preview"===e||"test"===e?"none":Q?"2px dashed var(--df-color-primary)":(null===(y=t.styles)||void 0===y?void 0:y.borderColor)?`1px solid ${t.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===e||"test"===e?"0":"4px",position:"relative",verticalAlign:(null===(C=t.styles)||void 0===C?void 0:C.verticalAlign)||"top"});return X.jsx("td",{ref:F,style:U,className:"table-cell "+(Q?"drag-over":""),children:X.jsx("div",{className:"cell-content",children:t.components&&Array.isArray(t.components)&&t.components.length>0?"edit"===e?X.jsx(k,{items:t.components.map(t=>t.id||D()),strategy:T,children:t.components.map(t=>{const a=St(t);return X.jsx(It,{component:a,selectedComponent:i,mode:e,onComponentSelect:A,onComponentDelete:r,onComponentEdit:n,renderFormComponent:s},a.id)})}):t.components.map(t=>{const A=t.id?t:St(t);return X.jsx(Lt,{component:A,mode:e,renderFormComponent:s,formData:a,formTemplateId:o,onThresholdActionCompletion:l,onThresholdIssueRaised:c,onNotesChange:h,onAttachmentChange:d,workOrderNumber:f,assetNumber:p,user:g,onCreateIssue:m,onUpdateIssue:w},A.id)}):"edit"===e?X.jsx("div",{className:"empty-cell-placeholder",children:X.jsxs("div",{className:"cell-info",children:[X.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),X.jsxs("span",{className:"cell-coordinates",children:["Cell (",t.row+1,", ",t.column+1,")"]})]})}):X.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},Ot=({id:t,properties:n,mode:s="edit",formData:a={},validationErrors:o={},touchedFields:l={},formSubmitted:c=!1,onValueChange:u,onSelect:h,isSelected:d=!1,className:f="",onTableSelect:p,onComponentSelect:g,onComponentDelete:m,onComponentEdit:w,selectedComponent:v,renderFormComponent:B,formTemplateId:b,onThresholdActionCompletion:y,onThresholdIssueRaised:C,onNotesChange:x,onAttachmentChange:U,workOrderNumber:E,assetNumber:N,user:S,onCreateIssue:I,onUpdateIssue:_})=>{var O,k,T,j,H,P,D,M,R,K,V,z,G,q,W,Y,J,$;const[Z,tt]=e(!1),et=(null===(O=n.cells)||void 0===O?void 0:O.some(t=>t.some(t=>t.components&&t.components.length>0)))||!1;A(()=>{},[null===(k=n.table)||void 0===k?void 0:k.rows,null===(T=n.table)||void 0===T?void 0:T.columns,null===(j=n.basic)||void 0===j?void 0:j.rows,null===(H=n.basic)||void 0===H?void 0:H.columns,n.cells,t,u]);const At=r(t=>{t.stopPropagation(),null==h||h(),null==p||p(n)},[h,p,n]),rt=r((e,A)=>{A.stopPropagation();const r=n.cells.map(t=>t.map(t=>{if(t.components&&t.components.some(t=>t.id===e.id)){const A=t.components.filter(t=>t.id!==e.id);return Object.assign(Object.assign({},t),{components:A})}return t}));u&&u({id:t,value:Object.assign(Object.assign({},n),{cells:r})})},[m,n,u,t]),nt=i(()=>n.cells?n.cells.map((e,A)=>e.map((e,r)=>Object.assign(Object.assign({},e),{components:e.components&&Array.isArray(e.components)?e.components.map((e,n)=>{if(e.id&&"string"==typeof e.id&&""!==e.id.trim())return e;const i=`${e.name||"component"}-table-${t}-row-${A}-cell-${r}-comp-${n}`;return Object.assign(Object.assign({},e),{id:i})}):[]}))):[],[n.cells,t]),ct=B||r(t=>{var e,A,r;const n=t.id?t:St(t),i=a[n.id]||"defaultValue"in n.basic&&n.basic.defaultValue||"";let o=i;"number-input"===n.name&&"number"==typeof i?o=String(i):"number-input"===n.name&&null==i&&(o="");const l={id:n.id,properties:n,validationErrors:{},formValue:o,touchedFields:{},formSubmitted:!1,mode:s,onValueChange:t=>{null==u||u(t)},onBlur:()=>{},onFocus:()=>{}};switch(n.name){case"text-input":case"email-input":case"number-input":return X.jsx(it,Object.assign({},l,{properties:n,inputType:"text-input"===n.name?"text":"number-input"===n.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return X.jsx(st,Object.assign({},l,{properties:n,readonly:!1,disabled:!1}));case"select":const t=Object.assign(Object.assign({},n),{options:(null===(e=n.basic)||void 0===e?void 0:e.options)||[]});return X.jsx(at,Object.assign({},l,{properties:t,disabled:!1}));case"checkbox":const i=Object.assign(Object.assign({},n),{options:(null===(A=n.basic)||void 0===A?void 0:A.options)||[]});return X.jsx(ot,Object.assign({},l,{properties:i,formValue:[],disabled:!1}));case"radio":const s=Object.assign(Object.assign({},n),{options:(null===(r=n.basic)||void 0===r?void 0:r.options)||[]});return X.jsx(lt,Object.assign({},l,{properties:s,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return X.jsx(ut,Object.assign({},l,{properties:n,readonly:!1,disabled:!1}));case"signature":return X.jsx(ht,Object.assign({},l,{properties:n}));case"heading":return X.jsx(pt,Object.assign({},l,{properties:n}));default:return X.jsxs("div",{className:"unknown-component",children:["Unknown component: ",n.name]})}},[B,s,a,u]),dt={backgroundColor:(null===(P=n.styles)||void 0===P?void 0:P.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(D=n.styles)||void 0===D?void 0:D.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(M=n.styles)||void 0===M?void 0:M.borderWidth)||"2px",borderRadius:(null===(R=n.styles)||void 0===R?void 0:R.borderRadius)||"8px",padding:(null===(K=n.styles)||void 0===K?void 0:K.padding)||"16px",margin:(null===(V=n.styles)||void 0===V?void 0:V.margin)||"16px 0"},ft={width:"100%",minWidth:"600px",borderCollapse:"preview"===s||"test"===s?"separate":"collapse",tableLayout:"fixed",border:"preview"===s||"test"===s?"1px solid var(--df-color-fb-border)":"none"};return et||"preview"!==s?X.jsxs("div",{className:`form-group df-form-table ${d?"selected":""} ${"preview"===s?"preview-mode":"test"===s?"test-mode":""} ${f}`,onClick:At,style:dt,children:[X.jsx("div",{className:"table-header",children:X.jsx("div",{className:"table-title",onClick:e=>{e.stopPropagation(),tt(!Z),null==u||u({id:t,value:Object.assign(Object.assign({},n),{basic:Object.assign(Object.assign({},n.basic||{}),{collapsed:!Z})})})},children:X.jsxs("div",{className:"title-content",children:[Z?X.jsx(Q,{size:16}):X.jsx(F,{size:16}),X.jsx(L,{size:16}),X.jsx("span",{className:"table-label",children:(null===(z=n.basic)||void 0===z?void 0:z.label)||"Table"}),(null===(G=n.validation)||void 0===G?void 0:G.required)&&X.jsx("span",{className:"required-indicator",children:"*"})]})})}),(null===(q=n.basic)||void 0===q?void 0:q.description)&&!Z&&X.jsx("div",{className:"table-description",children:n.basic.description}),!Z&&X.jsxs("div",{className:"table-content",children:[null,X.jsxs("table",{style:ft,children:[(null===(W=n.table)||void 0===W?void 0:W.displayAsTable)&&("edit"===s||(null===(Y=n.table)||void 0===Y?void 0:Y.showColumns))&&X.jsx("thead",{children:X.jsx("tr",{className:"table-header-row",children:Array.from({length:(null===(J=n.table)||void 0===J?void 0:J.columns)||(null===($=n.basic)||void 0===$?void 0:$.columns)||3},(t,e)=>{var A,r;const i=((null===(r=null===(A=n.table)||void 0===A?void 0:A.columnNames)||void 0===r?void 0:r.split(",").map(t=>t.trim()))||[])[e]||`Column ${e+1}`;return X.jsx("th",{className:"table-header-cell",style:{backgroundColor:(n.styles.headerBackgroundColor,"var(--df-color-fb-container)"),color:n.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-${e}`)})})}),X.jsx("tbody",{children:nt.map((e,A)=>X.jsx("tr",{className:"table-row",children:e.map(e=>X.jsx(_t,{cell:e,mode:s,onComponentSelect:g||(()=>{}),onComponentDelete:rt,onComponentEdit:w,selectedComponent:v||null,renderFormComponent:ct,formData:a,formTemplateId:b,onThresholdActionCompletion:y,onThresholdIssueRaised:C,tableId:t,onNotesChange:x,onAttachmentChange:U,workOrderNumber:E,assetNumber:N,user:S,onCreateIssue:I,onUpdateIssue:_},e.id))},A))})]})]})]}):null};var kt=Object.freeze({__proto__:null,DfFormTable:Ot,default:Ot});const Tt={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:t=>({flex:`0 0 calc(${t/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"}},jt=t=>{if(!t||"string"!=typeof t)return!1;const e=t.trim();return e.startsWith("data:image")||e.startsWith("iVBORw0KGgo")||e.startsWith("/9j/4AAQ")||e.startsWith("UklGR")||e.startsWith("R0lGOD")},Ht=(t,e)=>{if(!t)return"";const A=t.trim();return A.startsWith("data:")||A.startsWith("http")||A.startsWith("blob:")||A.startsWith("/")?A:A.startsWith("iVBORw0KGgo")?`data:image/png;base64,${A}`:A.startsWith("/9j/4AAQ")?`data:image/jpeg;base64,${A}`:A.startsWith("UklGR")?`data:image/webp;base64,${A}`:A.startsWith("R0lGOD")?`data:image/gif;base64,${A}`:e&&e.startsWith("image/")?`data:${e};base64,${A}`:A},Pt=t=>{if(void 0!==(null==t?void 0:t.icon)&&null!==(null==t?void 0:t.icon))return t.icon;return"pass"===(t=>{const e=String(t||"").toLowerCase();return"pass"===e||"yes"===e?"pass":"fail"===e||"no"===e?"fail":"pass"})((null==t?void 0:t.value)||t)?"✓":"×"},Dt=({component:t})=>{var e,A;const r=(null===(e=t.basic)||void 0===e?void 0:e.notes)||"",n=(null===(A=t.basic)||void 0===A?void 0:A.attachments)||[];return r.trim()||0!==n.length?X.jsxs("div",{style:{marginTop:"5px"},children:[r.trim().length>0&&X.jsxs("div",{style:Tt.notesSection,children:[X.jsx("span",{style:Tt.notesLabel,children:"Notes:"}),r]}),n.length>0&&X.jsx("div",{style:Tt.attachmentsSection,children:n.map((t,e)=>{var A;const r=!(!t.data&&!t.url),n=((null===(A=t.type)||void 0===A?void 0:A.startsWith("image/"))||jt(t.data||t.url||""))&&r?Ht(t.data||t.url||"",t.type):null;return X.jsx("div",{style:Tt.attachmentThumbnail,children:n?X.jsx("img",{src:n,alt:t.name||"Attachment",style:Tt.attachmentImg}):X.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},e)})})]}):null},Mt=({component:t})=>{var e,A,r,n,i,s,a;const o=void 0!==(null===(e=t.basic)||void 0===e?void 0:e.value)?t.basic.value:null===(A=t.basic)||void 0===A?void 0:A.defaultValue,{name:l}=t;if("signature"===l)return o&&jt(o)?X.jsx("div",{style:{marginTop:"5px"},children:X.jsx("img",{src:Ht(o),alt:"Signature",style:Object.assign(Object.assign({},Tt.img),{maxHeight:"100px",width:"auto"})})}):X.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===l){const e=(null===(r=t.basic)||void 0===r?void 0:r.options)||[],A=Array.isArray(o)?o:[o];return X.jsx("div",{style:{marginTop:"5px",width:"100%"},children:e.map((t,e)=>{const r=A.includes(t.value);return X.jsxs("div",{style:Tt.checkboxItem,children:[X.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(r?"#303992":"#cbd5e1"),borderRadius:"4px",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:r?"#303992":"#ffffff"},children:r&&X.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),X.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:t.label})]},e)})})}if("radio"===l){const e=(null===(n=t.basic)||void 0===n?void 0:n.options)||[];return X.jsx("div",{style:{marginTop:"5px",width:"100%"},children:e.map((t,e)=>{const A=o===t.value;return X.jsxs("div",{style:Tt.checkboxItem,children:[X.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(A?"#303992":"#cbd5e1"),borderRadius:"50%",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#ffffff"},children:A&&X.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),X.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:t.label})]},e)})})}if("segment"===l){const e=(null===(i=t.basic)||void 0===i?void 0:i.options)||[],A=o;return X.jsx("div",{style:Tt.segmentContainer,children:e.map((t,e)=>{const r=A===t.value,n=Pt(t),i=t.color||"#666";let s=Object.assign({},Tt.segmentButton);return s=r?Object.assign(Object.assign({},s),{backgroundColor:i,color:"#ffffff",borderColor:i}):Object.assign(Object.assign({},s),{backgroundColor:"#ffffff",color:i,borderColor:i}),X.jsxs("div",{style:s,children:[X.jsx("span",{style:Tt.segmentIcon,children:n}),X.jsx("span",{children:t.value})]},e)})})}if("file"===l){const t=(Array.isArray(o)?o:o?[o]:[]).filter(t=>{const e=!(!t.data&&!t.url),A=t.type&&t.type.startsWith("image/"),r=e&&jt(t.data||t.url);return A||r});return t.length>0?X.jsx("div",{style:{marginTop:"10px"},children:t.map((t,e)=>{const A=Ht(t.data||t.url,t.type);return A?X.jsx("img",{src:A,alt:t.name||"File",style:Object.assign(Object.assign({},Tt.img),{marginBottom:"10px"})},e):null})}):X.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===l){if(o&&"object"==typeof o){const t=o;return X.jsxs("div",{style:{fontSize:"14px"},children:[t.placeName&&X.jsxs("div",{style:{marginBottom:"4px"},children:[X.jsx("strong",{children:"Place:"})," ",t.placeName]}),(t.city||t.country)&&X.jsxs("div",{style:{marginBottom:"4px"},children:[X.jsx("strong",{children:"Address:"})," ",[t.city,t.country].filter(Boolean).join(", ")]}),t.latitude&&t.longitude&&X.jsxs("div",{style:{marginBottom:"4px"},children:[X.jsx("strong",{children:"Coordinates:"})," ",t.latitude.toFixed(6),", ",t.longitude.toFixed(6)]}),t.timestamp&&X.jsxs("div",{children:[X.jsx("strong",{children:"Captured:"})," ",(et(t.timestamp)||new Date).toLocaleString()]})]})}return X.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===l){const e=(null===(s=t.basic)||void 0===s?void 0:s.instructions)||[],A=(null===(a=t.validation)||void 0===a?void 0:a.listStyle)||"numbers";if(!Array.isArray(e)||0===e.length)return X.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const r=()=>X.jsx("div",{dangerouslySetInnerHTML:{__html:e.join("")}});return"numbers"===A?X.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:X.jsx(r,{})}):"bullets"===A?X.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:X.jsx(r,{})}):X.jsx("div",{style:{margin:"10px 0"},children:X.jsx(r,{})})}const c="object"==typeof o?JSON.stringify(o):String(o);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid"].includes(l)){const t="textarea"===l;return X.jsx("div",{style:Object.assign(Object.assign({},Tt.valueContainer),t?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}),children:X.jsx("div",{style:Tt.value,children:c})})}return X.jsx("div",{style:Tt.value,children:c})},Rt=({component:t})=>{var e,A,r;const{name:n,basic:i,styles:s,validation:a}=t,o=null==i?void 0:i.label,l=null==a?void 0:a.required,c="left"===((null==s?void 0:s.labelAlignment)||"top");if("section"===n){const e=null==s?void 0:s.headerBackgroundColor,A=null==s?void 0:s.headerTextColor,r=Object.assign(Object.assign(Object.assign(Object.assign({},Tt.sectionHeader),e?{backgroundColor:e,padding:"8px",borderRadius:"4px"}:{}),A?{color:A}:{}),{display:"flex",alignItems:"center"});return X.jsxs("div",{style:Tt.section,children:[o&&X.jsx("label",{style:r,children:X.jsxs("span",{style:{flex:1},children:[o,l&&" *"]})}),(null==i?void 0:i.description)&&X.jsx("p",{style:Object.assign(Object.assign({},Tt.description),{marginBottom:"15px"}),children:i.description}),X.jsx(Dt,{component:t}),X.jsx("div",{style:Tt.sectionChildren,children:X.jsx(Kt,{components:t.children||[]})})]})}if("heading"===n){const t=`h${Math.max(1,Math.min(6,null!==(A=null!==(e=null==s?void 0:s.level)&&void 0!==e?e:null==i?void 0:i.level)&&void 0!==A?A:1))}`,r=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},(null==s?void 0:s.headerBackgroundColor)?{backgroundColor:s.headerBackgroundColor,padding:"8px",borderRadius:"4px"}:{}),(null==s?void 0:s.headerTextColor)?{color:s.headerTextColor}:{}),(null==s?void 0:s.fontSize)?{fontSize:s.fontSize}:{}),(null==s?void 0:s.textAlign)?{textAlign:s.textAlign}:{}),{marginTop:0,marginBottom:"15px"});return X.jsx("div",{style:Tt.formGroup,children:X.jsx(t,{style:r,children:(null==i?void 0:i.label)||(null==i?void 0:i.value)})})}if("table"===n){const e=t.cells||[],A=Math.max(0,...e.map(t=>t?t.length:0)),r=A>0?100/A:100,n=null==s?void 0:s.headerBackgroundColor,i=null==s?void 0:s.headerTextColor,a=Object.assign(Object.assign(Object.assign({},Tt.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{});return X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:a,children:[o,l&&" *"]}),X.jsx("table",{style:Tt.table,children:X.jsx("tbody",{children:e.map((t,e)=>X.jsx("tr",{children:t&&t.map((t,e)=>X.jsx("td",{style:Object.assign(Object.assign({},Tt.td),{width:`${r}%`}),children:t.components&&t.components.map((t,e)=>{var A;return X.jsxs("div",{style:{marginBottom:"8px"},children:[(null===(A=t.basic)||void 0===A?void 0:A.label)&&X.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[t.basic.label,":"]}),X.jsx(Mt,{component:t}),X.jsx(Dt,{component:t})]},e)})},e))},e))})})]})}if("datagrid"===n){const e=t.entries||[];let A=t.templateComponents||[];0===A.length&&e.length>0&&(null===(r=e[0])||void 0===r?void 0:r.components)&&(A=e[0].components.map(t=>{var e;return Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{label:(null===(e=t.basic)||void 0===e?void 0:e.label)||t.name})})}));const n=null==s?void 0:s.headerBackgroundColor,i=null==s?void 0:s.headerTextColor,a=Object.assign(Object.assign(Object.assign({},Tt.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{}),c=e.filter(t=>!(!t.components||0===t.components.length)&&t.components.some(t=>{var e,A;const r=void 0!==(null===(e=t.basic)||void 0===e?void 0:e.value)?t.basic.value:null===(A=t.basic)||void 0===A?void 0:A.defaultValue;return Array.isArray(r)?r.length>0:null!=r&&""!==String(r).trim()}));return 0===c.length?X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:a,children:[o,l&&" *"]}),X.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:a,children:[o,l&&" *"]}),X.jsxs("table",{style:Tt.table,children:[X.jsx("thead",{children:X.jsx("tr",{children:A.map((t,e)=>{var A;return X.jsx("th",{style:Tt.th,children:(null===(A=t.basic)||void 0===A?void 0:A.label)||t.name},e)})})}),X.jsx("tbody",{children:c.map((t,e)=>X.jsx("tr",{children:A.map((e,A)=>{const r=t.components[A];return X.jsx("td",{style:Tt.td,children:r?X.jsxs(X.Fragment,{children:[X.jsx(Mt,{component:r}),X.jsx(Dt,{component:r})]}):"N/A"},A)})},e))})]})]})}if(c&&"instructions"!==n){const e=["segment"].includes(n);return X.jsxs("div",{style:Tt.formGroup,children:[X.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[o&&X.jsxs("label",{style:Tt.labelLeft,children:[o,l&&" *"]}),X.jsx("div",{style:Object.assign({flex:1},e?{display:"flex",justifyContent:"flex-end"}:{}),children:X.jsx(Mt,{component:t})})]}),X.jsx(Dt,{component:t})]})}return X.jsxs("div",{style:Tt.formGroup,children:[o&&X.jsxs("label",{style:Tt.label,children:[o,l&&" *"]}),X.jsx(Mt,{component:t}),X.jsx(Dt,{component:t})]})},Kt=({components:t})=>{if(!t||0===t.length)return null;const e=[];let A=[],r=0;return t.forEach(t=>{var n;const i=["section","table","datagrid","heading","instructions"].includes(t.name),s=i?12:(null===(n=t.styles)||void 0===n?void 0:n.column)||12;r+s>12&&A.length>0&&(e.push(A),A=[],r=0),A.push(t),r+=s,(i||r>=12)&&r>0&&(e.push(A),A=[],r=0)}),A.length>0&&e.push(A),X.jsx(X.Fragment,{children:e.map((t,e)=>1===t.length?X.jsx(Rt,{component:t[0]},t[0].id||e):X.jsx("div",{style:Tt.gridRow,children:t.map((t,e)=>{var A;const r=(null===(A=t.styles)||void 0===A?void 0:A.column)||12;return X.jsx("div",{style:Tt.gridCol(r),children:X.jsx(Rt,{component:t})},t.id||e)})},e))})},Vt=({formTitle:t,formDescription:e,userName:A,components:r})=>X.jsxs("div",{className:"pdf-container",style:Tt.page,children:[X.jsxs("div",{style:Tt.header,children:[X.jsxs("div",{children:[X.jsx("h1",{style:Tt.title,children:t}),e&&X.jsx("p",{style:Tt.description,children:e})]}),A&&X.jsxs("div",{style:Tt.submittedBy,children:[X.jsx("strong",{children:"Submitted By:"})," ",A]})]}),X.jsx("div",{className:"form-content",children:X.jsx(Kt,{components:r})})]});var zt,Gt=I;if("production"===process.env.NODE_ENV)zt=Gt.createRoot,Gt.hydrateRoot;else{var qt=Gt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;zt=function(t,e){qt.usingClientEntryPoint=!0;try{return Gt.createRoot(t,e)}finally{qt.usingClientEntryPoint=!1}}}var Wt={exports:{}};
11
11
  /*!
12
12
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>
13
13
  * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>