df-ae-forms-package 1.0.42 → 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.js CHANGED
@@ -7,7 +7,7 @@
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?u.exports=function(){if(c)return h;c=1;var t=e,A=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,r){var a,o={},l=null,c=null;for(a in void 0!==r&&(l=""+r),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(c=t.ref),t)n.call(t,a)&&!s.hasOwnProperty(a)&&(o[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===o[a]&&(o[a]=t[a]);return{$$typeof:A,type:e,key:l,ref:c,props:o,_owner:i.current}}return h.Fragment=r,h.jsx=a,h.jsxs=a,h}():u.exports=(d||(d=1,"production"!==process.env.NODE_ENV&&function(){var t,A=e,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"),p=Symbol.for("react.lazy"),g=Symbol.for("react.offscreen"),m=Symbol.iterator,w=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(e){for(var t=arguments.length,A=new Array(t>1?t-1:0),r=1;r<t;r++)A[r-1]=arguments[r];!function(e,t,A){var r=w.ReactDebugCurrentFrame.getStackAddendum();""!==r&&(t+="%s",A=A.concat([r]));var n=A.map(function(e){return String(e)});n.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,n)}("error",e,A)}function b(e){return e.displayName||"Context"}function B(e){if(null==e)return null;if("number"==typeof e.tag&&v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case 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 e)switch(e.$$typeof){case l:return b(e)+".Consumer";case o:return b(e._context)+".Provider";case c:return function(e,t,A){var r=e.displayName;if(r)return r;var n=t.displayName||t.name||"";return""!==n?A+"("+n+")":A}(e,e.render,"ForwardRef");case d:var t=e.displayName||null;return null!==t?t:B(e.type)||"Memo";case p:var A=e,r=A._payload,f=A._init;try{return B(f(r))}catch(e){return null}}return null}t=Symbol.for("react.module.reference");var y,C,x,F,Q,U,E,S=Object.assign,N=0;function L(){}L.__reactDisabledLog=!0;var I,_=w.ReactCurrentDispatcher;function k(e,t,A){if(void 0===I)try{throw Error()}catch(e){var r=e.stack.trim().match(/\n( *(at )?)/);I=r&&r[1]||""}return"\n"+I+e}var O,T=!1,j="function"==typeof WeakMap?WeakMap:Map;function H(e,t){if(!e||T)return"";var A,r=O.get(e);if(void 0!==r)return r;T=!0;var n,i=Error.prepareStackTrace;Error.prepareStackTrace=void 0,n=_.current,_.current=null,function(){if(0===N){y=console.log,C=console.info,x=console.warn,F=console.error,Q=console.group,U=console.groupCollapsed,E=console.groupEnd;var e={configurable:!0,enumerable:!0,value:L,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}N++}();try{if(t){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(e){A=e}Reflect.construct(e,[],s)}else{try{s.call()}catch(e){A=e}e.call(s.prototype)}}else{try{throw Error()}catch(e){A=e}e()}}catch(t){if(t&&A&&"string"==typeof t.stack){for(var a=t.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 e.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",e.displayName)),"function"==typeof e&&O.set(e,u),u}}while(l>=1&&c>=0);break}}}finally{T=!1,_.current=n,function(){if(0===--N){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:S({},e,{value:y}),info:S({},e,{value:C}),warn:S({},e,{value:x}),error:S({},e,{value:F}),group:S({},e,{value:Q}),groupCollapsed:S({},e,{value:U}),groupEnd:S({},e,{value:E})})}N<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=i}var h=e?e.displayName||e.name:"",d=h?k(h):"";return"function"==typeof e&&O.set(e,d),d}function P(e,t,A){if(null==e)return"";if("function"==typeof e)return H(e,!(!(r=e.prototype)||!r.isReactComponent));var r;if("string"==typeof e)return k(e);switch(e){case u:return k("Suspense");case h:return k("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case c:return H(e.render,!1);case d:return P(e.type,t,A);case p:var n=e,i=n._payload,s=n._init;try{return P(s(i),t,A)}catch(e){}}return""}O=new j;var D=Object.prototype.hasOwnProperty,M={},R=w.ReactDebugCurrentFrame;function K(e){if(e){var t=e._owner,A=P(e.type,e._source,t?t.type:null);R.setExtraStackFrame(A)}else R.setExtraStackFrame(null)}var V=Array.isArray;function G(e){return V(e)}function z(e){return""+e}function q(e){if(function(e){try{return z(e),!1}catch(e){return!0}}(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),z(e)}var W,X,Y,J=w.ReactCurrentOwner,$={key:!0,ref:!0,__self:!0,__source:!0};function Z(e,t,A,n,i){var s,a={},o=null,l=null;for(s in void 0!==A&&(q(A),o=""+A),function(e){if(D.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(q(t.key),o=""+t.key),function(e){if(D.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(l=t.ref,function(e,t){if("string"==typeof e.ref&&J.current&&t&&J.current.stateNode!==t){var A=B(J.current.type);Y[A]||(v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',B(J.current.type),e.ref),Y[A]=!0)}}(t,i)),t)D.call(t,s)&&!$.hasOwnProperty(s)&&(a[s]=t[s]);if(e&&e.defaultProps){var c=e.defaultProps;for(s in c)void 0===a[s]&&(a[s]=c[s])}if(o||l){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;o&&function(e,t){var A=function(){W||(W=!0,v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};A.isReactWarning=!0,Object.defineProperty(e,"key",{get:A,configurable:!0})}(a,u),l&&function(e,t){var A=function(){X||(X=!0,v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};A.isReactWarning=!0,Object.defineProperty(e,"ref",{get:A,configurable:!0})}(a,u)}return function(e,t,A,n,i,s,a){var o={$$typeof:r,type:e,key:t,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}(e,o,l,i,n,J.current,a)}Y={};var ee,te=w.ReactCurrentOwner,Ae=w.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,A=P(e.type,e._source,t?t.type:null);Ae.setExtraStackFrame(A)}else Ae.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===r}function ie(){if(te.current){var e=B(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var se={};function ae(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var A=function(e){var t=ie();if(!t){var A="string"==typeof e?e:e.displayName||e.name;A&&(t="\n\nCheck the top-level render call using <"+A+">.")}return t}(t);if(!se[A]){se[A]=!0;var r="";e&&e._owner&&e._owner!==te.current&&(r=" It was passed a child from "+B(e._owner.type)+"."),re(e),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',A,r),re(null)}}}function oe(e,t){if("object"==typeof e)if(G(e))for(var A=0;A<e.length;A++){var r=e[A];ne(r)&&ae(r,t)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var n=function(e){if(null===e||"object"!=typeof e)return null;var t=m&&e[m]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof n&&n!==e.entries)for(var i,s=n.call(e);!(i=s.next()).done;)ne(i.value)&&ae(i.value,t)}}function le(e){var t,A=e.type;if(null!=A&&"string"!=typeof A){if("function"==typeof A)t=A.propTypes;else{if("object"!=typeof A||A.$$typeof!==c&&A.$$typeof!==d)return;t=A.propTypes}if(t){var r=B(A);!function(e,t,A,r,n){var i=Function.call.bind(D);for(var s in e)if(i(e,s)){var a=void 0;try{if("function"!=typeof e[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 e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw o.name="Invariant Violation",o}a=e[s](t,s,r,A,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){a=e}!a||a instanceof Error||(K(n),v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",r||"React class",A,s,typeof a),K(null)),a instanceof Error&&!(a.message in M)&&(M[a.message]=!0,K(n),v("Failed %s type: %s",A,a.message),K(null))}}(t,e.props,"prop",r,e)}else void 0===A.PropTypes||ee||(ee=!0,v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",B(A)||"Unknown"));"function"!=typeof A.getDefaultProps||A.getDefaultProps.isReactClassApproved||v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ce={};function ue(e,A,n,f,m,w){var b=function(e){return"string"==typeof e||"function"==typeof e||e===i||e===a||e===s||e===u||e===h||e===g||"object"==typeof e&&null!==e&&(e.$$typeof===p||e.$$typeof===d||e.$$typeof===o||e.$$typeof===l||e.$$typeof===c||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!b){var y="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).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(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(m);y+=x||ie(),null===e?C="null":G(e)?C="array":void 0!==e&&e.$$typeof===r?(C="<"+(B(e.type)||"Unknown")+" />",y=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,y)}var F=Z(e,A,n,m,w);if(null==F)return F;if(b){var Q=A.children;if(void 0!==Q)if(f)if(G(Q)){for(var U=0;U<Q.length;U++)oe(Q[U],e);Object.freeze&&Object.freeze(Q)}else v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else oe(Q,e)}if(D.call(A,"key")){var E=B(e),S=Object.keys(A).filter(function(e){return"key"!==e}),N=S.length>0?"{key: someKey, "+S.join(": ..., ")+": ...}":"{key: someKey}";ce[E+N]||(v('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',N,E,S.length>0?"{"+S.join(": ..., ")+": ...}":"{}",E),ce[E+N]=!0)}return e===i?function(e){for(var t=Object.keys(e.props),A=0;A<t.length;A++){var r=t[A];if("children"!==r&&"key"!==r){re(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",r),re(null);break}}null!==e.ref&&(re(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(F):le(F),F}var he=function(e,t,A){return ue(e,t,A,!1)},de=function(e,t,A){return ue(e,t,A,!0)};f.Fragment=i,f.jsx=he,f.jsxs=de}()),f);var p=u.exports;class g{constructor(){}static getInstance(){return g.instance||(g.instance=new g),g.instance}getAvailableComponentsForConditional(e,t){if(!e||!Array.isArray(e))return[];const A=e.filter(e=>!t||e.id!==t).map(e=>{var t;return{id:e.id,label:(null===(t=e.basic)||void 0===t?void 0:t.label)||e.id,type:e.name,key:e.id}}).sort((e,t)=>e.label.localeCompare(t.label));return A}getApplicableOperators(e){switch(e){case"text-input":case"email-input":case"textarea":return["equals","notEquals","contains","notContains","isEmpty","isNotEmpty"];case"number-input":case"date-picker":case"datetime-picker":return["equals","notEquals","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual","isEmpty","isNotEmpty"];case"select":case"radio":case"segment":default:return["equals","notEquals","isEmpty","isNotEmpty"];case"checkbox":return["contains","notContains","isEmpty","isNotEmpty"]}}validateConditionalLogic(e,t){const A=[];return e?(["show","hide","always"].includes(e.action)||A.push("Invalid conditional action"),["all","any"].includes(e.when)||A.push("Invalid when condition"),e.conditions&&0!==e.conditions.length?e.conditions.forEach((e,r)=>{const n=t.find(t=>t.id===e.when);if(!n)return void A.push(`Condition ${r+1}: Component not found`);this.getApplicableOperators(n.name).includes(e.operator)||A.push(`Condition ${r+1}: Operator not applicable for component type`),this.isValidConditionValue(e.value,n.name,e.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(e,t,A){if("always"===e.action)return{shouldShow:!0,evaluatedConditions:[]};if(!e||!e.conditions||0===e.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const r=e.conditions.map(e=>{const r=this.getComponentValue(e.when,t,A);return{condition:e,result:this.evaluateCondition(e,r),componentValue:r}});return{shouldShow:this.determineFinalResult(e,r),evaluatedConditions:r}}getComponentValue(e,t,A){if(A&&void 0!==A[e])return A[e];const r=t.find(t=>t.id===e);return r&&"defaultValue"in r.basic?r.basic.defaultValue:void 0}evaluateCondition(e,t){const{operator:A,value:r}=e;if("checked"===r||"notChecked"===r)return this.evaluateCheckboxCondition(t,r);switch(A){case"equals":return this.isEqual(t,r);case"notEquals":return!this.isEqual(t,r);case"isEmpty":return this.isEmpty(t);case"isNotEmpty":return!this.isEmpty(t);case"contains":return this.contains(t,r);case"notContains":return!this.contains(t,r);case"greaterThan":return this.isGreaterThan(t,r);case"lessThan":return this.isLessThan(t,r);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(t,r);case"lessThanOrEqual":return this.isLessThanOrEqual(t,r);default:return!1}}evaluateCheckboxCondition(e,t){const A=this.isCheckboxChecked(e);return"checked"===t?A:"notChecked"===t&&!A}isCheckboxChecked(e){return null!=e&&("boolean"==typeof e?e:"string"==typeof e?"true"===e.toLowerCase()||"1"===e:Array.isArray(e)?e.length>0:"number"==typeof e&&e>0)}determineFinalResult(e,t){let A,r;return A="all"===e.when?t.every(e=>e.result):"any"===e.when&&t.some(e=>e.result),r="show"===e.action?A:"hide"===e.action?!A:(e.action,!0),r}isEqual(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,A)=>this.isEqual(e,t[A]));if("object"==typeof e&&"object"==typeof t){const A=Object.keys(e),r=Object.keys(t);return A.length===r.length&&A.every(A=>this.isEqual(e[A],t[A]))}return!1}isEmpty(e){return null==e||void 0===e||("string"==typeof e?""===e.trim():Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}contains(e,t){return null!=e&&null!=t&&("string"==typeof e?e.toLowerCase().includes(String(t).toLowerCase()):!!Array.isArray(e)&&e.some(e=>this.isEqual(e,t)))}isGreaterThan(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A>r}isLessThan(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A<r}isGreaterThanOrEqual(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A>=r}isLessThanOrEqual(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A<=r}isValidConditionValue(e,t,A){if(null==e)return["isEmpty","isNotEmpty"].includes(A);switch(t){case"number-input":return!isNaN(Number(e))||["isEmpty","isNotEmpty"].includes(A);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(e))||["isEmpty","isNotEmpty"].includes(A);case"checkbox":return Array.isArray(e)||"string"==typeof e||"number"==typeof e;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(e){return{equals:"Is Equal To",notEquals:"Is Not Equal To",contains:"Contains",notContains:"Does Not Contain",isEmpty:"Is Empty",isNotEmpty:"Is Not Empty",greaterThan:"Is Greater Than",lessThan:"Is Less Than",greaterThanOrEqual:"Is Greater Than Or Equal To",lessThanOrEqual:"Is Less Than Or Equal To"}[e]||e}getActionDisplayText(e){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[e]||e}getConditionalLogicSummary(e,t){if(!e||0===e.conditions.length)return"No conditions";if("always"===e.action)return"Always show";const A=this.getActionDisplayText(e.action),r=e.conditions.map(e=>{const A=t.find(t=>t.id===e.when);return`${(null==A?void 0:A.basic.label)||"Unknown component"} ${this.getOperatorDisplayText(e.operator)} ${this.formatConditionValue(e.value)}`}),n="all"===e.when?" and ":" or ";return`${A} ${r.join(n)}`}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const m=g.getInstance();const w=new class{constructor(){this.toasts=[],this.listeners=[],this.defaultDuration=3e3,this.timeouts={}}generateId(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}notifyListeners(){this.listeners.forEach(e=>e([...this.toasts]))}addToast(e){try{this.toasts.push(e),this.notifyListeners(),this.timeouts[e.id]=setTimeout(()=>{this.removeToast(e.id)},e.duration||this.defaultDuration)}catch(e){console.error("Error displaying toast message:",e)}}removeToast(e){this.timeouts[e]&&(clearTimeout(this.timeouts[e]),delete this.timeouts[e]),this.toasts=this.toasts.filter(t=>t.id!==e),this.notifyListeners()}showSuccess(e,t=3e3){const A={id:this.generateId(),message:e,type:"success",duration:t};this.addToast(A)}showError(e,t=5e3){const A={id:this.generateId(),message:e,type:"danger",duration:t};this.addToast(A)}showWarning(e,t){const A={id:this.generateId(),message:e,type:"warning",duration:t};this.addToast(A)}showInfo(e,t){const A={id:this.generateId(),message:e,type:"info",duration:t};this.addToast(A)}show(e,t="success",A){const r={id:this.generateId(),message:e,type:t,duration:A};this.addToast(r)}clearAll(){Object.values(this.timeouts).forEach(e=>clearTimeout(e)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}getToasts(){return[...this.toasts]}},v=({validationErrors:e,fieldId:t,touchedFields:A,formSubmitted:r,properties:n,localValidation:i,isTouched:s,mode:a})=>{const o=e=>{var t,A;const r=n.basic.label||"This field",i=n.name||"",s=null===(t=n.validation)||void 0===t?void 0:t.customValidationMessage;if("number-input"===i)switch(e){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(e){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 e=n.validation;return`You are under the limit. ${r} must be at least ${null==e?void 0:e.lowerLimit}`;case"upperLimit":const t=n.validation;return`You crossed the limit. ${r} must be no more than ${null==t?void 0:t.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[t]||r))return"";if(i&&i.isValid)return"";if(i&&!i.isValid&&Object.keys(i.errors).length>0){const e=Object.keys(i.errors).filter(e=>!0===i.errors[e]);if(e.length>0){const t=e[0],A=n.name||"";return"pattern"===t&&"number-input"===A?"":o(t)}}const c=e[t];if(c&&"string"==typeof c&&""!==c.trim()){const e=n.name||"";if("number-input"===e&&i){const e=n.validation,t=e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit,A=e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||t||A?(i.isValid,""):""}if(("date-picker"===e||"datetime-picker"===e)&&c.includes("valid date")){const t=(null===(l=n.basic)||void 0===l?void 0:l.dateTimeMode)||("datetime-picker"===e?"datetime":"date");if("time"===t)return"Please select a valid time";if("datetime"===t)return"Please select a valid date and time"}return c}return""})();return l?p.jsx("div",{className:"form-error-msg",children:l}):null};function b(e,t,A,r){return new(A||(A=Promise))(function(n,i){function s(e){try{o(r.next(e))}catch(e){i(e)}}function a(e){try{o(r.throw(e))}catch(e){i(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof A?t:new A(function(e){e(t)})).then(s,a)}o((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const B=e=>{if(null==e||""===e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;if("number"==typeof e){const t=new Date(e);return isNaN(t.getTime())?null:t}if("string"==typeof e){let t=e.trim();t.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)&&(t=t.replace(" ","T"));const A=new Date(t);return isNaN(A.getTime())?null:A}return null};var y;!function(e){e.OPEN="Open",e.IN_PROGRESS="In-Progress",e.REJECTED="Rejected",e.RESOLVE="Resolve"}(y||(y={}));const C=({isOpen:r,onClose:n,onSuccess:i,component:s,formTemplateId:a,notes:o="",attachments:l=null,issue:c=null,onCreateIssue:u,onUpdateIssue:h,user:d,availableUsers:f=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:g,assetNumber:m,isStandalone:v,allowWorkflowActions:C=!1,isEdit:x})=>{var F,Q,U,E,S,N;const[L,I]=e.useState(""),[_,k]=e.useState(""),[O,T]=e.useState(""),[j,H]=e.useState(""),[P,D]=e.useState("Medium"),[M,R]=e.useState(y.OPEN),[K,V]=e.useState(""),[G,z]=e.useState(""),[q,W]=e.useState(!1),[X,Y]=e.useState(l||[]),[J,$]=e.useState(!1),Z=e.useRef(null),ee=void 0!==x?x:!!c;e.useEffect(()=>{(null==c?void 0:c.attachments)&&c.attachments.length>0?Y(c.attachments):l&&Y(l)},[l,c]);const te=e=>{if(!e)return"Attachment";if(e instanceof File)return e.name;if("string"==typeof e){if(e.startsWith("data:"))return"Attachment";const t=e.split("/");return t[t.length-1]||"Attachment"}return e.fileName||e.filename||e.name||"Attachment"},Ae=e=>{if(!e)return null;const t=e=>/\.(jpg|jpeg|png|gif|webp)$/i.test(e),A=e=>e.startsWith("data:image");return e instanceof File?e.type.startsWith("image/")?URL.createObjectURL(e):null:"string"==typeof e?A(e)||t(e)?e:null:e.data&&A(e.data)||e.fileName&&t(e.fileName)&&e.data?e.data:null};e.useEffect(()=>{var e;if(r)if(c||ee){I((null==c?void 0:c.title)||""),k((null==c?void 0:c.description)||""),T((null==c?void 0:c.workOrderNumber)||g||""),H((null==c?void 0:c.assetNumber)||m||""),D((null==c?void 0:c.priority)||"Medium");const e=(null==c?void 0:c.status)||y.OPEN,t=e===y.OPEN||e===y.IN_PROGRESS||e===y.REJECTED||e===y.RESOLVE?e:y.OPEN;R(t),V((null==c?void 0:c.assignTo)||(null==c?void 0:c.assignee)||""),z((null==c?void 0:c.comments)||"")}else s&&(null===(e=s.basic)||void 0===e||e.label,I(""),k(""),z(o||""),g&&T(g),m&&H(m))},[r,s,o,c,g,m]);const re=e.useMemo(()=>{if(!L.trim())return!1;if(!_.trim())return!1;if(!M)return!1;if(!K)return!1;if(!v){if(!O.trim())return!1;if(!j.trim())return!1}return!0},[L,_,M,K,v,O,j]),ne=e=>b(void 0,void 0,void 0,function*(){var t;if(c){W(!0);try{const t={title:String(L||"").trim(),description:String(_||"").trim(),workOrderNumber:String(O||"").trim()||"",assetNumber:String(j||"").trim()||"",formTemplateId:c.formTemplateId||"",component:c.component||{},priority:P,assignee:String(K||"").trim()||void 0,status:e,comments:String(G||"").trim()||""};h&&c._id&&(yield h(c._id,t)),R(e);const A={[y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[y.RESOLVE]:"Issue resolved successfully",[y.REJECTED]:"Issue rejected"};w.showSuccess(A[e]||"Issue status updated successfully"),i&&i(),n()}catch(e){const A=(null==e?void 0:e.message)||(null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.message)||"Failed to update issue status. Please try again.";w.showError(A)}finally{W(!1)}}});if(!r)return null;const ie=p.jsx("div",{className:"raise-issue-modal-overlay",onClick:n,children:p.jsxs("div",{className:"raise-issue-modal",onClick:e=>e.stopPropagation(),children:[p.jsxs("div",{className:"raise-issue-modal-header",children:[p.jsxs("div",{className:"raise-issue-modal-header-left",children:[p.jsx(t.AlertTriangle,{className:"raise-issue-modal-icon",size:20}),p.jsx("div",{className:"raise-issue-modal-header-text",children:p.jsx("div",{className:"raise-issue-modal-title-main",children:ee?C?"Edit Issue":"Issue Details":"Create Issue"})})]}),p.jsx("button",{className:"raise-issue-modal-close",onClick:n,"aria-label":"Close",children:p.jsx(t.X,{size:18})})]}),p.jsx("div",{className:"raise-issue-modal-content",children:p.jsxs("div",{className:"raise-issue-fields-grid",children:[ee&&(null==c?void 0:c.issueNumber)&&p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),p.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:c.issueNumber,readOnly:!0})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Task"}),p.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:ee?null===(Q=null===(F=null==c?void 0:c.component)||void 0===F?void 0:F.basic)||void 0===Q?void 0:Q.label:(null===(U=null==s?void 0:s.basic)||void 0===U?void 0:U.label)||"",readOnly:!0})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Task Value"}),p.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:ee?null===(S=null===(E=null==c?void 0:c.component)||void 0===E?void 0:E.basic)||void 0===S?void 0:S.value:(null===(N=null==s?void 0:s.basic)||void 0===N?void 0:N.value)||"",readOnly:!0})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Title ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("input",{type:"text",className:"raise-issue-field-input "+(ee?"raise-issue-field-readonly":""),value:L,onChange:e=>I(e.target.value),placeholder:"Enter issue title",readOnly:ee})]}),!v&&p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("input",{type:"text",className:"raise-issue-field-input "+(ee?"raise-issue-field-readonly":""),value:O,onChange:e=>T(e.target.value),placeholder:"N/A",readOnly:ee})]}),!v&&p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("input",{type:"text",className:"raise-issue-field-input "+(ee?"raise-issue-field-readonly":""),value:j,onChange:e=>H(e.target.value),placeholder:"Enter asset number",readOnly:ee})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Raised By ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[p.jsx(t.User,{size:16}),p.jsx("span",{children:d&&`${d.firstName||""} ${d.lastName||""}`.trim()||"User"})]})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),p.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[p.jsx(t.Calendar,{size:16}),p.jsx("span",{children:ee&&(null==c?void 0:c.createdAt)?(B(c.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})})]})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Description ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("textarea",{className:"raise-issue-field-textarea "+(ee?"raise-issue-field-readonly":""),value:_,onChange:e=>k(e.target.value),placeholder:"Enter issue description",rows:4,readOnly:ee})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Status ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("select",{className:"raise-issue-field-select "+(ee?"":"raise-issue-field-readonly"),value:M,onChange:e=>R(e.target.value),disabled:!ee,children:[p.jsx("option",{value:y.OPEN,children:y.OPEN}),p.jsx("option",{value:y.IN_PROGRESS,children:y.IN_PROGRESS}),p.jsx("option",{value:y.REJECTED,children:y.REJECTED}),p.jsx("option",{value:y.RESOLVE,children:y.RESOLVE})]})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Assign to ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("select",{className:"raise-issue-field-select",value:K,onChange:e=>V(e.target.value),children:[p.jsx("option",{value:"",children:"Unassigned"}),f.map(e=>p.jsx("option",{value:e,children:e},e))]})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("div",{className:"raise-issue-priority-buttons",children:[p.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===P?"active":""),onClick:()=>D("Low"),children:"Low"}),p.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===P?"active":""),onClick:()=>D("Medium"),children:"Medium"}),p.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===P?"active":""),onClick:()=>D("High"),children:"High"})]})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[p.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[p.jsx(t.MessageSquare,{size:16}),p.jsx("span",{children:"Comments"})]}),!G&&p.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),p.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(ee?"raise-issue-field-readonly":""),value:G,onChange:e=>z(e.target.value),placeholder:"Add a comment...",rows:4,readOnly:ee})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",style:{marginTop:"1rem"},children:[p.jsx("label",{className:"raise-issue-field-label",children:"Attachments"}),p.jsxs("div",{className:"raise-issue-attachments-container",children:[!ee&&p.jsxs("div",{className:"raise-issue-dropzone "+(J?"dragging":""),onDragOver:e=>{e.preventDefault(),$(!0)},onDragLeave:e=>{e.preventDefault(),$(!1)},onDrop:e=>{if(e.preventDefault(),$(!1),e.dataTransfer.files&&e.dataTransfer.files.length>0){const t=Array.from(e.dataTransfer.files);Y(e=>[...e,...t])}},onClick:()=>{var e;return null===(e=Z.current)||void 0===e?void 0:e.click()},children:[p.jsx("input",{type:"file",ref:Z,style:{display:"none"},onChange:e=>{if(e.target.files&&e.target.files.length>0){const t=Array.from(e.target.files);Y(e=>[...e,...t]),Z.current&&(Z.current.value="")}},multiple:!0}),p.jsx("div",{className:"raise-issue-dropzone-icon",children:p.jsx(t.UploadCloud,{size:24})}),p.jsx("div",{className:"raise-issue-dropzone-text",children:"Click to upload or drag and drop"}),p.jsx("div",{className:"raise-issue-dropzone-hint",children:"PNG, JPG up to 10MB"})]}),X.length>0&&p.jsx("div",{className:"raise-issue-attachments-list",children:X.map((e,A)=>p.jsxs("div",{className:"raise-issue-attachment-item",children:[p.jsx("div",{className:"raise-issue-attachment-thumbnail",children:Ae(e)?p.jsx("img",{src:Ae(e),alt:"Thumbnail"}):p.jsx(t.Paperclip,{size:20,color:"#9ca3af"})}),p.jsxs("div",{className:"raise-issue-attachment-info",children:[p.jsx("span",{className:"attachment-name",title:te(e),children:te(e)}),e instanceof File&&p.jsxs("span",{className:"attachment-size",children:[(e.size/1024).toFixed(1)," KB"]})]}),!ee&&p.jsx("button",{type:"button",className:"attachment-remove-btn",onClick:()=>(e=>{Y(t=>t.filter((t,A)=>A!==e))})(A),title:"Remove",children:p.jsx(t.X,{size:12})})]},A))})]})]})]})}),p.jsx("div",{className:"raise-issue-modal-actions",children:p.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[C&&ee&&c&&p.jsxs(p.Fragment,{children:[M===y.OPEN&&p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:()=>b(void 0,void 0,void 0,function*(){yield ne(y.IN_PROGRESS)}),disabled:q,children:q?"Processing...":"Accept"}),M===y.IN_PROGRESS&&p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:()=>b(void 0,void 0,void 0,function*(){yield ne(y.RESOLVE)}),disabled:q,children:q?"Processing...":"Resolve"}),(M===y.OPEN||M===y.IN_PROGRESS)&&p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:()=>b(void 0,void 0,void 0,function*(){yield ne(y.REJECTED)}),disabled:q,children:q?"Processing...":"Reject"})]}),!ee&&p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save "+(re?"":"disabled"),onClick:()=>b(void 0,void 0,void 0,function*(){var e,t,A,r,l,f,p;if(String(L||"").trim())if(String(_||"").trim())if(v||String(O||"").trim())if(v||String(j||"").trim())if(String(K||"").trim()){W(!0);try{if(ee&&c){const s={title:String(L||"").trim(),description:String(_||"").trim(),workOrderNumber:String(O||"").trim()||"",assetNumber:String(j||"").trim()||void 0,formTemplateId:c.formTemplateId||"",component:c.component||{},priority:P,assignTo:String(K||"").trim()||void 0,status:M,comments:String(G||"").trim()||"",task:(null===(t=null===(e=c.component)||void 0===e?void 0:e.basic)||void 0===t?void 0:t.label)||"",taskValue:(null===(r=null===(A=c.component)||void 0===A?void 0:A.basic)||void 0===r?void 0:r.value)||""};h&&c._id&&(yield h(c._id,s)),w.showSuccess("Issue updated successfully"),i&&i(),n()}else{if(!s)return w.showError("Component is required"),void W(!1);if(!a||""===String(a||"").trim())return w.showError("Form template is required"),void W(!1);const e=Object.assign(Object.assign({},s),{basic:Object.assign(Object.assign({},s.basic),{comments:String(o||"")})}),t=d?`${d.firstName||""} ${d.lastName||""}`.trim():"User",A={title:String(L||"").trim(),workOrderNumber:String(O||"").trim()||void 0,assetNumber:String(j||"").trim()||void 0,component:e,description:String(_||"").trim(),formTemplateId:a,assignTo:String(K||"").trim()||void 0,priority:P,status:M,comments:String(G||"").trim()||"",createdBy:t,task:(null===(l=null==s?void 0:s.basic)||void 0===l?void 0:l.label)||"",taskValue:(null===(f=null==s?void 0:s.basic)||void 0===f?void 0:f.value)||""};let r;if(u&&(r=yield u(A,X)),w.showSuccess("Issue raised successfully"),i){const e=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)||X},r);i(e)}n()}}catch(e){const t=(null==e?void 0:e.message)||(null===(p=null==e?void 0:e.error)||void 0===p?void 0:p.message)||(ee?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");w.showError(t)}finally{W(!1)}}else w.showError("Assignee is required");else w.showError("Asset Number is required");else w.showError("Work Order is required");else w.showError("Description is required");else w.showError("Title is required")}),disabled:q||!re,children:q?ee?"Saving...":"Creating...":ee?"Save Changes":"Create Issue"})]})})]})});return A.createPortal(ie,document.body)},x=({component:A,condition:r,currentValue:n,thresholdValue:i,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,onIssueRaised:c,isIssueRaised:u=!1,compact:h=!1})=>{const[d,f]=e.useState(!1),[g,m]=e.useState(null),[v,B]=e.useState(!1),[y,x]=e.useState(!1);e.useEffect(()=>{u&&x(!0)},[u]),e.useEffect(()=>{x(!1)},[null==r?void 0:r.id]);const F=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),Q=e.useCallback(()=>b(void 0,void 0,void 0,function*(){if(u||y){if(g)return void f(!0);B(!0);try{m(null),f(!0)}catch(e){console.error("Error fetching issue:",e),w.showError("Failed to load issue details")}finally{B(!1)}}else m(null),f(!0)}),[u,y,s,A,g]),U=e.useCallback(()=>{f(!1),u||y||m(null)},[u,y]),E=e.useCallback(e=>{f(!1),m(e||null),x(!0),c&&(null==r?void 0:r.id)&&c(r.id)},[c,r]);return u||y?p.jsx(p.Fragment,{children:d&&p.jsx(C,{isOpen:d,onClose:U,onSuccess:E,component:A,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,notes:"",attachments:null,issue:g})}):h?p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[p.jsx("div",{className:"threshold-alert-border"}),p.jsxs("div",{className:"threshold-alert-content-compact",children:[p.jsx(t.AlertTriangle,{className:"threshold-alert-icon-compact",size:14}),p.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${F(r.operator)} ${i}`}),p.jsx("button",{type:"button",onClick:Q,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),d&&p.jsx(C,{isOpen:d,onClose:U,onSuccess:E,component:A,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,notes:"",attachments:null,issue:g})]}):p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[p.jsx("div",{className:"threshold-alert-border"}),p.jsxs("div",{className:"threshold-alert-content",children:[p.jsx("div",{className:"threshold-alert-header",children:p.jsxs("div",{className:"threshold-alert-title-group",children:[p.jsx(t.AlertTriangle,{className:"threshold-alert-icon",size:20}),p.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),p.jsxs("div",{className:"threshold-alert-message",children:[(()=>{var e;const t=F(r.operator);return`${(null===(e=A.basic)||void 0===e?void 0:e.label)||"Value"}: Value ${n} exceeds threshold ${t} ${i}`})(),p.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),p.jsx("div",{className:"threshold-alert-buttons",children:p.jsx("button",{type:"button",onClick:Q,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),d&&p.jsx(C,{isOpen:d,onClose:U,onSuccess:E,component:A,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,notes:"",attachments:null,issue:g})]})},F=({id:t,properties:A,validationErrors:r={},formValue:n="",inputType:i="text",readonly:s=!1,disabled:a=!1,touchedFields:o={},formSubmitted:l=!1,mode:c="test",onValueChange:u,onBlur:h,onFocus:d,className:f="",hideLabel:g=!1,formTemplateId:m,onThresholdIssueRaised:w,raisedThresholdIssues:b=new Set,workOrderNumber:B,assetNumber:y,user:C})=>{var F,Q,U,E,S;const N=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?N(e.value):"label"in e?N(e.label):"":String(e||""),L=e.useRef(t),I=e.useRef(null);e.useEffect(()=>{t!==L.current&&(console.warn(`[DfFormInput] Component ID changed from ${L.current} to ${t}`),L.current=t)},[t]);const _=N(n||(null===(F=null==A?void 0:A.basic)||void 0===F?void 0:F.defaultValue)||""),[k,O]=e.useState(_),[T,j]=e.useState(!1),[H,P]=e.useState(!1),[D,M]=e.useState(new Set),[R,K]=e.useState(_),V=()=>{if(i)return i;const e=null==A?void 0:A.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},G=e.useCallback(e=>{const t=(()=>{var e;const t={};if((null===(e=null==A?void 0:A.validation)||void 0===e?void 0:e.required)&&(t.required=!0),"email"===V()&&(t.email=!0),"text"===V()){const e=A.validation;(null==e?void 0:e.minLength)&&(t.minLength=e.minLength),(null==e?void 0:e.maxLength)&&(t.maxLength=e.maxLength)}if("number"===V()){const e=A.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&(t.lowerLimit=e.lowerLimit),e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&(t.upperLimit=e.upperLimit)}return t})(),r={};let n=!0;const i="string"==typeof e?e:null!=e?String(e):"";if(!t.required||i&&""!==i.trim()||(r.required=!0,n=!1),t.email&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(i)&&(r.email=!0,n=!1),t.minLength&&i&&i.length<t.minLength&&(r.minLength=!0,n=!1),t.maxLength&&i&&i.length>t.maxLength&&(r.maxLength=!0,n=!1),"number"===V())if(delete r.pattern,delete r.min,delete r.max,i&&""!==i.trim()){const e=i.trim(),A=parseFloat(e);isNaN(A)||("lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&A<t.lowerLimit&&(r.lowerLimit=!0,n=!1),"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&A>t.upperLimit&&(r.upperLimit=!0,n=!1))}else delete r.lowerLimit,delete r.upperLimit;return{isValid:n,errors:r}},[A,V]),z=e.useCallback(e=>{const A="string"==typeof e?e:null!=e?String(e):"";if(O(A),u){const e=G(A),r=L.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}`),u(n)}},[t,u,G,L]);e.useEffect(()=>{T&&(o[t]=!0)},[T,t,o]),e.useEffect(()=>{var e;if("edit"===c){j(!1);const t=(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.defaultValue)||"";O(t)}else"test"===c&&(j(!1),O(""))},[c,null===(Q=null==A?void 0:A.basic)||void 0===Q?void 0:Q.defaultValue]),e.useEffect(()=>{var e;const r=L.current,i=N(n||(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.defaultValue)||"");i===k||H||""===i&&""!==String(k||"").trim()?""===i&&String(k||"").trim():null!=n&&(r===t?O(i):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${r}, prop id: ${t}`))},[n,k,H,null===(U=null==A?void 0:A.basic)||void 0===U?void 0:U.defaultValue,t]),e.useEffect(()=>{l&&j(!0)},[l]),e.useEffect(()=>{"test"!==c&&O("")},[c]);const q=e.useCallback((e,t)=>{if(!t||""===t)return!1;const A="string"==typeof t?parseFloat(t):t,r="string"==typeof e.value?parseFloat(e.value):e.value;if(isNaN(A)||isNaN(r))return!1;switch(e.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}},[]),W=e.useMemo(()=>{var e;return(null===(e=null==A?void 0:A.condition)||void 0===e?void 0:e.conditions)||[]},[null==A?void 0:A.condition]);e.useEffect(()=>{k!==R&&(M(new Set),K(k))},[k,R]);const X=e.useMemo(()=>{if("test"!==c||!k||""===k)return null;const e=W.filter(e=>q(e,k));if(0===e.length)return null;for(const t of e)if(!D.has(t.id))return t;return null},[k,W,D,c,q,b]),Y=e.useCallback(e=>{M(t=>new Set(t).add(e))},[]),J=V(),$=a||s||(null===(E=null==A?void 0:A.validation)||void 0===E?void 0:E.readonly);return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",ref:I,children:[p.jsx("input",{type:J,id:t,value:k,onChange:e=>{const t=e.target.value;z(t)},onFocus:()=>{P(!0),d&&d()},onBlur:()=>{if(P(!1),j(!0),"test"===c&&u){const e="string"==typeof k?k:null!=k?String(k):"",A=G(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};u(r)}h&&h()},placeholder:A.basic.placeholder,disabled:$,readOnly:s||(null===(S=null==A?void 0:A.validation)||void 0===S?void 0:S.readonly),className:(()=>{const e="form-control";if("test"===c){const A="string"==typeof k?k:null!=k?String(k):"",n=G(A);if(n.isValid)return`${e} ${f}`.trim();const i=!n.isValid&&T,s=r[t]&&(T||l)&&!n;return`${e} ${i||s?"is-invalid":""} ${f}`.trim()}return`${e} ${f}`.trim()})()}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:o,formSubmitted:l,properties:A,localValidation:G(k),isTouched:T,mode:c})]})]}),X&&"test"===c&&(()=>{var e,t,r,n;const i=(null==b?void 0:b.has(X.id))||!1,s=null!==(null===(e=I.current)||void 0===e?void 0:e.closest(".table-cell"))||null!==(null===(t=I.current)||void 0===t?void 0:t.closest(".cell-content"))||null!==(null===(r=I.current)||void 0===r?void 0:r.closest(".datagrid-table-view"))||null!==(null===(n=I.current)||void 0===n?void 0:n.closest(".datagrid-list-view"))||f.includes("table-cell")||f.includes("cell-content");return p.jsx(x,{component:A,condition:X,currentValue:k,thresholdValue:X.value,formTemplateId:m,workOrderNumber:B,assetNumber:y,user:C,onDismiss:()=>Y(X.id),onIssueRaised:w,isIssueRaised:i,compact:s},`${X.id}-${i}`)})()]})},Q=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w;const[b,B]=e.useState(n),[y,C]=e.useState(!1),x=e.useCallback(e=>{var t,r,n;const i={};let s=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(i.required=!0,s=!1),(null===(r=null==A?void 0:A.validation)||void 0===r?void 0:r.minLength)&&e&&e.length<A.validation.minLength&&(i.minLength=!0,s=!1),(null===(n=null==A?void 0:A.validation)||void 0===n?void 0:n.maxLength)&&e&&e.length>A.validation.maxLength&&(i.maxLength=!0,s=!1),{isValid:s,errors:i}},[A]),F=e.useCallback(e=>{if(B(e),c){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,x]);e.useEffect(()=>{y&&(a[t]=!0)},[y,t,a]),e.useEffect(()=>{""===b&&""!==n&&B(n)},[n]),e.useEffect(()=>{o&&C(!0)},[o]),e.useEffect(()=>{"test"!==l&&B("")},[l]);const Q=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly),U=(null===(m=null==A?void 0:A.validation)||void 0===m?void 0:m.rows)||4;return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("textarea",{id:t,value:b,onChange:e=>{const t=e.target.value;F(t)},onFocus:()=>{h&&h()},onBlur:()=>{C(!0),u&&u()},placeholder:A.basic.placeholder,disabled:Q,readOnly:i||(null===(w=null==A?void 0:A.validation)||void 0===w?void 0:w.readonly),rows:U,className:`form-textarea ${!x(b).isValid&&y?"is-invalid":""} ${d}`.trim()}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(b),isTouched:y,mode:l})]})]})},U=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m;const[w,b]=e.useState(n),[B,y]=e.useState(!1),C=(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.multiple)||!1,x=e.useCallback(e=>{var t;const r={};let n=!0;return(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)&&(C?Array.isArray(e)&&0!==e.length||(r.required=!0,n=!1):(!e||"string"==typeof e&&""===e.trim())&&(r.required=!0,n=!1)),{isValid:n,errors:r}},[A,C]),F=e.useCallback(e=>{if(b(e),c){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,x]);e.useEffect(()=>{B&&(a[t]=!0)},[B,t,a]),e.useEffect(()=>{JSON.stringify(n)!==JSON.stringify(w)&&b(n)},[n,w]),e.useEffect(()=>{o&&y(!0)},[o]);const Q=s||i||(null===(m=null==A?void 0:A.validation)||void 0===m?void 0:m.readonly);return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsxs("select",{id:t,value:w,onChange:e=>{if(C){const t=Array.from(e.target.selectedOptions,e=>e.value);F(t)}else F(e.target.value)},onFocus:()=>{h&&h()},onBlur:()=>{y(!0),u&&u()},disabled:Q,multiple:C,className:`form-select ${!x(w).isValid&&B?"is-invalid":""} ${d}`.trim(),children:[!C&&p.jsx("option",{value:"",children:A.basic.placeholder||"Select an option"}),(A.options||[]).map((e,t)=>p.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(w),isTouched:B,mode:l})]})]})},E=({id:t,properties:A,validationErrors:r={},formValue:n=[],readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w;const[b,B]=e.useState(!1),y=Array.isArray(n)?n:[],C=e.useCallback(e=>{var t;const r={};let n=!0;return(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)&&0===e.length&&(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),x=e.useCallback(e=>{if(c){const A=C(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,C,y]),F=(e,t)=>{let A;A=t?[...y,e]:y.filter(t=>t!==e),x(A)},Q=()=>{h&&h()},U=()=>{B(!0),u&&u()};e.useEffect(()=>{b&&(a[t]=!0)},[b,t,a]),e.useEffect(()=>{},[n,t,y]),e.useEffect(()=>{o&&B(!0)},[o]);const E=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsx(p.Fragment,{children:p.jsx("div",{className:`form-group checkbox-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var e;return(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.inlineLayout)?"inline-layout":"vertical-layout"})()} ${d}`,children:!f&&A.basic.label?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(m=null==A?void 0:A.basic)||void 0===m?void 0:m.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:C(y),isTouched:b,mode:l})]})]}):p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(w=null==A?void 0:A.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:C(y),isTouched:b,mode:l})]})})})},S=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w;const[b,B]=e.useState(n),[y,C]=e.useState(!1),x=e.useCallback(e=>{var t;const r={};let n=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),F=e.useCallback(e=>{if(B(e),c){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,x]),Q=e=>{F(e)},U=()=>{h&&h()},E=()=>{C(!0),u&&u()};e.useEffect(()=>{y&&(a[t]=!0)},[y,t,a]),e.useEffect(()=>{n!==b&&B(n)},[n,b]),e.useEffect(()=>{o&&C(!0)},[o]);const S=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsx(p.Fragment,{children:p.jsx("div",{className:`form-group radio-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var e;return(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.inlineLayout)?"inline-layout":"vertical-layout"})()} ${d}`,children:!f&&A.basic.label?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(m=null==A?void 0:A.basic)||void 0===m?void 0:m.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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:S||e.disabled,className:"form-check-input"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(b),isTouched:y,mode:l})]})]}):p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(w=null==A?void 0:A.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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:S||e.disabled,className:"form-check-input"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(b),isTouched:y,mode:l})]})})})},N=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g;const[m,w]=e.useState(n),[b,B]=e.useState(!1),y=e.useCallback(e=>{var t;const r={};let n=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),C=e.useCallback(e=>{if(w(e),B(!0),c){const A=y(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,y]),x=()=>{h&&h()},F=()=>{B(!0),u&&u()};e.useEffect(()=>{b&&(a[t]=!0)},[b,t,a]),e.useEffect(()=>{n!==m&&w(n)},[n,m]),e.useEffect(()=>{o&&B(!0)},[o]);const Q=()=>{var e;return(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.inlineLayout)?"inline-layout":"grid-layout"},U=e=>{const t=null==e?void 0:e.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},E=e=>{if(void 0!==(null==e?void 0:e.icon)&&""!==e.icon)return e.icon;return"pass"===U((null==e?void 0:e.value)||e)?"✓":"×"},S=(e,t)=>(null==e?void 0:e.color)||(null==e?void 0:e.backgroundColor)?{color:t?"#ffffff":e.color||"#00814b",backgroundColor:t?e.color||"#00814b":e.backgroundColor||"#34bd4914",borderColor:e.color||"#00814b"}:{},N=e=>{if((null==e?void 0:e.color)||(null==e?void 0:e.backgroundColor))return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===U((null==e?void 0:e.value)||e)?"pass-button":"fail-button")},L=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsxs(p.Fragment,{children:[p.jsx("div",{className:`form-group segment-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()} ${d}`,children:!f&&A.basic.label?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsx("div",{className:"form-segment-wrapper",children:p.jsx("div",{className:`form-segment-container ${Q()}`,children:(A.options||[]).map((e,A)=>{const r=m===e.value,n=S(e,r),i=N(e),s=E(e);return p.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[p.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"}),p.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&p.jsx("span",{className:"segment-icon",children:s}),p.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})]}):p.jsx("div",{className:"form-segment-wrapper",children:p.jsx("div",{className:`form-segment-container ${Q()}`,children:(A.options||[]).map((e,A)=>{const r=m===e.value,n=S(e,r),i=N(e),s=E(e);return p.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[p.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"}),p.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&p.jsx("span",{className:"segment-icon",children:s}),p.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:y(m),isTouched:b,mode:l})]})},L=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w,b,y;const C=e.useCallback(e=>{var t,r;if(!e)return"";if("string"==typeof e){if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e))return e;const r=B(e);if(r&&!isNaN(r.getTime())){const e=A.name||"",n=(null===(t=A.basic)||void 0===t?void 0:t.dateTimeMode)||("datetime-picker"===e?"datetime":"date");if("datetime"===n){return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}T${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`}return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}return e}if(e instanceof Date){if(isNaN(e.getTime()))return"";const t=A.name||"",n=(null===(r=A.basic)||void 0===r?void 0:r.dateTimeMode)||("datetime-picker"===t?"datetime":"date");if("datetime"===n){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}T${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}if("object"==typeof e&&null!==e){if("value"in e&&e.value)return C(e.value);if("date"in e&&e.date)return C(e.date);try{const t=String(e),A=B(t);if(A&&!isNaN(A.getTime()))return C(A)}catch(e){}return""}return""},[A]),x=C(n),[F,Q]=e.useState(x),[U,E]=e.useState(!1),[S,N]=e.useState(!1),L=e.useCallback(e=>{var t,r,n,i,s,a;const o={};let l=!0;const c=A.name||"",u=(null===(t=A.basic)||void 0===t?void 0:t.dateTimeMode)||("datetime-picker"===c?"datetime":"date"),h=e?String(e).trim():"";if((null===(r=null==A?void 0:A.validation)||void 0===r?void 0:r.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 e=B(h);if(!e||isNaN(e.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(n=null==A?void 0:A.validation)||void 0===n?void 0:n.minDate){const t=B(A.validation.minDate);t&&e<t&&(o.minDate=!0,o.minDateMessage=`Date and time must be on or after ${t.toLocaleDateString()}`,l=!1)}if(null===(i=null==A?void 0:A.validation)||void 0===i?void 0:i.maxDate){const t=B(A.validation.maxDate);t&&e>t&&(o.maxDate=!0,o.maxDateMessage=`Date and time must be on or before ${t.toLocaleDateString()}`,l=!1)}}else{const e=B(h);if(!e||isNaN(e.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(s=null==A?void 0:A.validation)||void 0===s?void 0:s.minDate){const t=B(A.validation.minDate);t&&e<t&&(o.minDate=!0,o.minDateMessage=`Date must be on or after ${t.toLocaleDateString()}`,l=!1)}if(null===(a=null==A?void 0:A.validation)||void 0===a?void 0:a.maxDate){const t=B(A.validation.maxDate);t&&e>t&&(o.maxDate=!0,o.maxDateMessage=`Date must be on or before ${t.toLocaleDateString()}`,l=!1)}}return{isValid:l,errors:o}},[A]),I=e.useCallback(e=>{if(Q(e),c){const A=L(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,L]);e.useEffect(()=>{U&&(a[t]=!0)},[U,t,a]),e.useEffect(()=>{const e=C(n);e===F||S||Q(e)},[n,F,S,C]),e.useEffect(()=>{o&&E(!0)},[o]);const _=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly),k=A.name||"",O=(null===(m=A.basic)||void 0===m?void 0:m.dateTimeMode)||("datetime-picker"===k?"datetime":"date"),T=(()=>{switch(O){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("input",{type:T,id:t,value:F,onChange:e=>{const t=e.target.value;I(t)},onFocus:()=>{N(!0),h&&h()},onBlur:()=>{if(N(!1),E(!0),c){const e=L(F),A={id:t,value:F,isValid:e.isValid,errors:e.errors};c(A)}u&&u()},disabled:_,readOnly:i||(null===(w=null==A?void 0:A.validation)||void 0===w?void 0:w.readonly),min:null===(b=null==A?void 0:A.validation)||void 0===b?void 0:b.minDate,max:null===(y=null==A?void 0:A.validation)||void 0===y?void 0:y.maxDate,className:`form-date ${!L(F).isValid&&U?"is-invalid":""} ${d}`.trim()}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:L(F),isTouched:U,mode:l})]})]})},I=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g;const m=e.useRef(null),[w,b]=e.useState(!1),[B,y]=e.useState(!1),[C,x]=e.useState(n),[F,Q]=e.useState(!1),U=e.useCallback(e=>{var t;const r={};let n=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),E=e.useCallback(e=>{if(x(e),c){const A=U(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,U]),S=e.useCallback(()=>{const e=document.documentElement.classList.contains("dark")||"dark"===document.documentElement.getAttribute("data-theme");let t=getComputedStyle(document.documentElement).getPropertyValue("--df-color-fb-input-bg").trim();t||(t=e?"#2c2e34":"#ffffff");return{strokeColor:e?"#ffffff":"#000000",backgroundColor:t}},[]),N=e.useCallback(e=>{if(!e)return;const A=m.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 e=S();r.fillStyle=e.backgroundColor,r.fillRect(0,0,A.width,A.height);const t=A.width/A.height,i=n.width/n.height;let s=A.width,a=A.height,o=0,l=0;i>t?(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]),L=e.useCallback(()=>{const e=m.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const A=e.getBoundingClientRect();e.width=A.width,e.height=A.height,e.style.width=A.width+"px",e.style.height=A.height+"px";const r=S();t.strokeStyle=r.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?N(C):(t.fillStyle=r.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,S,N]),I=e.useCallback(()=>{setTimeout(()=>{L()},100)},[L]);e.useEffect(()=>{const e=()=>{I()},t=new MutationObserver(e=>{e.forEach(e=>{if("attributes"===e.type&&"class"===e.attributeName){const t=e.target;t.classList.contains("form-canvas-container")&&(t.classList.contains("mobile-view")||t.classList.contains("tablet-view")||t.classList.contains("desktop-view"))&&I()}})});return t.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[I]);const _=e.useCallback(e=>{const t=m.current;if(!t)return{x:0,y:0};const A=t.getBoundingClientRect(),r=t.width/A.width,n=t.height/A.height,i=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,s=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(i-A.left)*r,y:(s-A.top)*n}},[]),k=e=>{var t;if(i||s||(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.readonly))return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),b(!0),y(!0);const r=m.current;if(!r)return;const n=r.getContext("2d");if(!n)return;const{x:a,y:o}=_(e),l=S();n.strokeStyle=l.strokeColor,n.lineWidth=2,n.lineCap="round",n.lineJoin="round",n.beginPath(),n.moveTo(a,o)},O=e=>{if(!w)return;e.preventDefault(),e.stopPropagation();const t=m.current;if(!t)return;const A=t.getContext("2d");if(!A)return;const{x:r,y:n}=_(e);A.lineTo(r,n),A.stroke()},T=()=>{if(!w)return;b(!1),Q(!0);const e=m.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const A=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<A.length;e+=4){const t=A[e],r=A[e+1],n=A[e+2];if(A[e+3]>0&&(t<255||r<255||n<255))return!0}})(e);const t=e.toDataURL("image/png");x(t),E(t),setTimeout(()=>{Q(!1)},100)}else Q(!1)},j=e.useCallback(()=>{const e=m.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const A=S();if(t.strokeStyle=A.strokeColor,C){const r=C,n=e.getBoundingClientRect();t.fillStyle=A.backgroundColor,t.fillRect(0,0,n.width,n.height),r&&N(r)}else{const r=e.getBoundingClientRect();t.fillStyle=A.backgroundColor,t.fillRect(0,0,r.width,r.height)}},[S,C,N]);e.useEffect(()=>{const e=new MutationObserver(e=>{e.forEach(e=>{"attributes"!==e.type||"class"!==e.attributeName&&"data-theme"!==e.attributeName||j()})});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{e.disconnect()}},[j]);e.useEffect(()=>{B&&(a[t]=!0)},[B,t,a]),e.useEffect(()=>{if(!(n===C||w||F||""!==C&&""===n)){if(n===C)return;x(n),n&&N(n)}},[n,C,w,F]),e.useEffect(()=>{o&&y(!0)},[o]),e.useEffect(()=>{if("test"!==l){x("");const e=m.current;if(e){const t=e.getContext("2d");if(t){const A=e.getBoundingClientRect();e.width=A.width,e.height=A.height;const r=S();t.fillStyle=r.backgroundColor,t.fillRect(0,0,A.width,A.height)}}}},[l]),e.useEffect(()=>{L()},[l]);const H=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[p.jsx("canvas",{ref:m,id:t,className:`form-signature ${!U(C).isValid&&B?"is-invalid":""} ${d}`.trim(),onMouseDown:k,onMouseMove:O,onMouseUp:T,onMouseLeave:T,onTouchStart:k,onTouchMove:O,onTouchEnd:T,onFocus:()=>{h&&h()},onBlur:()=>{u&&u()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:H?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!H&&p.jsx("button",{type:"button",onClick:e=>(e=>{null==e||e.preventDefault(),null==e||e.stopPropagation();const t=m.current;if(!t)return;const A=t.getBoundingClientRect();t.width=A.width,t.height=A.height;const r=t.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",x(""),E("")})(e),className:"clear-signature-btn",style:{position:"absolute",bottom:"8px",right:"8px",padding:"4px 8px",backgroundColor:"var(--df-color-error-primary)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"0.75rem",fontWeight:"500",zIndex:10,transition:"all 0.2s ease",minWidth:"60px",minHeight:"28px"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-dark, #dc2626)",e.currentTarget.style.transform="scale(1.05)"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-primary)",e.currentTarget.style.transform="scale(1)"},children:"Clear"})]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:U(C),isTouched:B,mode:l})]})]})},_=({id:t,properties:A,validationErrors:r={},formValue:n=null,readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="test",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w,b,B,y,C,x;const[F,Q]=e.useState([]),[U,E]=e.useState(!1),[S,N]=e.useState(!1),L=e.useRef(null),I=e.useCallback(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 e=n.data;if("string"==typeof e)if(e.startsWith("data:"))a=e;else{const t=e.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>10){let e=s;e||(e=t.startsWith("/9j/")||t.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":t.startsWith("iVBORw0KGgo")?"image/png":t.startsWith("R0lGOD")?"image/gif":t.startsWith("UklGR")?"image/webp":"image/png"),a=`data:${e};base64,${t}`}else a=e}}const 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(e){console.error("Error creating object URL:",e),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 e="image/png";r.startsWith("/9j/")||r.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?e="image/jpeg":r.startsWith("iVBORw0KGgo")?e="image/png":r.startsWith("R0lGOD")?e="image/gif":r.startsWith("UklGR")&&(e="image/webp"),l=`data:${e};base64,${r}`}let c="";if(l.startsWith("data:")){const e=l.match(/filename=([^;]+)/i);if(e)c=decodeURIComponent(e[1]);else{const e=l.match(/data:([^;]+)/);if(e){const t=e[1];c=`file-${A+1}.${t.includes("image")?t.includes("jpeg")?"jpg":"png":t.includes("pdf")?"pdf":t.includes("word")?"doc":t.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 e=l.indexOf(";");a=e>5?l.substring(5,e):"application/octet-stream"}else{const e=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(e){a={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",zip:"application/zip",rar:"application/x-rar-compressed"}[e[1].toLowerCase()]||"application/octet-stream"}else a=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]),_=e.useCallback(()=>({isValid:!0,errors:{}}),[]),k=e.useCallback(e=>{var r;if(i||s)return;const n=I(e),a=F.length>0?[...F,...n]:n,o=(null===(r=null==A?void 0:A.validation)||void 0===r?void 0:r.maxFiles)||1/0,l=a.slice(0,o);if(Q(l),N(!0),c){const e=_(),A={id:t,value:l.map(e=>e.file),isValid:e.isValid,errors:e.errors};c(A)}},[F,A,i,s,c,_,I,t]),O=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]},T=e=>e.startsWith("image/")?"🖼️":e.startsWith("video/")?"🎥":e.startsWith("audio/")?"🎵":e.includes("pdf")?"📄":e.includes("word")||e.includes("document")?"📝":e.includes("excel")||e.includes("spreadsheet")?"📊":e.includes("zip")||e.includes("rar")?"📦":"📁";e.useEffect(()=>{S&&(a[t]=!0)},[S,t,a]),e.useEffect(()=>{("edit"===l||"test"===l)&&N(!1)},[l]),e.useEffect(()=>{const e=I(n);null!=n&&(Array.isArray(n)&&n.length>0||"string"==typeof n&&""!==String(n).trim()||"object"==typeof n&&!Array.isArray(n)&&Object.keys(n).length>0)||0===F.length&&null!=n?Q(e):(null==n||Array.isArray(n)&&0===n.length)&&F.length>0&&Q([])},[n,I,F.length]),e.useEffect(()=>{o&&N(!0)},[o]),e.useEffect(()=>()=>{F.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[F]);const j=()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"},H=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly),P=(null===(m=null==A?void 0:A.validation)||void 0===m?void 0:m.multiple)||!1,D=(null===(w=null==A?void 0:A.validation)||void 0===w?void 0:w.accept)||"*/*",M=(null===(b=null==A?void 0:A.validation)||void 0===b?void 0:b.maxFiles)||1/0,R=F.length<M&&(P||M>1),K="edit"===l,V="preview"===l||"test"===l,G=F.filter(e=>e.type.startsWith("image/")),z=F.filter(e=>!e.type.startsWith("image/")),q=G.length>0;return V&&q?p.jsxs("div",{className:`form-group ${j()}`,children:[!f&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(B=A.basic)||void 0===B?void 0:B.label)||"Attachments",(null===(y=A.validation)||void 0===y?void 0:y.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"file-upload-wrapper",children:[p.jsxs("div",{className:"file-image-display",children:[G.map(e=>p.jsxs("div",{className:"file-image-container",children:[e.preview&&p.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),p.jsxs("div",{className:"file-image-info",children:[p.jsx("div",{className:"file-name",title:e.name,children:e.name}),p.jsx("div",{className:"file-size",children:O(e.size)})]})]},e.id)),z.length>0&&p.jsxs("div",{className:"file-other-files",children:[p.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),z.map(e=>p.jsxs("div",{className:"file-item-minimal",children:[p.jsx("div",{className:"file-icon",children:T(e.type)}),p.jsxs("div",{className:"file-info",children:[p.jsx("div",{className:"file-name",title:e.name,children:e.name}),p.jsx("div",{className:"file-size",children:O(e.size)})]})]},e.id))]})]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:_(),isTouched:S,mode:l})]})]}):p.jsxs("div",{className:`form-group ${j()}`,children:[!f&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(C=A.basic)||void 0===C?void 0:C.label)||"Attachments",(null===(x=A.validation)||void 0===x?void 0:x.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"file-upload-wrapper",children:[p.jsxs("div",{className:`file-upload-area ${U?"drag-over":""} ${i?"readonly":""} ${s?"disabled":""} ${d}`.trim(),onDragOver:e=>{e.preventDefault(),i||s||E(!0)},onDragLeave:e=>{e.preventDefault(),E(!1)},onDrop:e=>{if(e.preventDefault(),E(!1),i||s)return;const t=e.dataTransfer.files;t.length>0&&k(t)},onClick:e=>{var t;const A=e.target,r=null!==A.closest(".file-item"),n=null!==A.closest(".file-remove");!K||H||0!==F.length||r||n||null===(t=L.current)||void 0===t||t.click()},onFocus:()=>{h&&h()},onBlur:()=>{if(N(!0),"test"===l&&c){const e=_(),A={id:t,value:F.map(e=>e.file),isValid:e.isValid,errors:e.errors};c(A)}u&&u()},tabIndex:H?-1:0,children:[p.jsx("input",{ref:L,type:"file",id:t,multiple:P,accept:D,onChange:e=>{const t=e.target.files;t&&t.length>0&&(k(t),e.target.value="")},disabled:H,style:{display:"none"}}),0===F.length?p.jsxs("div",{className:"upload-placeholder",onClick:e=>{var t;e.stopPropagation(),K&&!H&&(null===(t=L.current)||void 0===t||t.click())},children:[p.jsx("div",{className:"upload-icon",children:"📁"}),p.jsx("div",{className:"upload-text",children:A.basic.placeholder&&p.jsx("p",{className:"upload-hint",children:A.basic.placeholder})})]}):p.jsx("div",{className:"file-list",children:F.map(e=>p.jsxs("div",{className:"file-item",children:[p.jsx("div",{className:"file-preview",children:e.preview?p.jsx("img",{src:e.preview,alt:e.name,className:"file-image"}):p.jsx("div",{className:"file-icon",children:T(e.type)})}),p.jsxs("div",{className:"file-info",children:[p.jsx("div",{className:"file-name",title:e.name,children:e.name}),p.jsx("div",{className:"file-size",children:O(e.size)})]}),K&&!H&&p.jsx("button",{type:"button",className:"file-remove",onClick:A=>{A.stopPropagation(),(e=>{if(i||s)return;const A=F.filter(t=>t.id!==e);if(Q(A),N(!0),c){const e=_(),r={id:t,value:A.map(e=>e.file),isValid:e.isValid,errors:e.errors};c(r)}})(e.id)},"aria-label":`Remove ${e.name}`,children:"✕"})]},e.id))})]}),F.length>0&&R&&!H&&K&&p.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!H&&L.current&&K&&(L.current.value="",L.current.click())},"aria-label":"Add more files",children:[p.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:p.jsx("path",{d:"M12 5v14M5 12h14"})}),p.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:_(),isTouched:S,mode:l})]})]})},k=({id:A,properties:r,validationErrors:n={},formValue:i=null,readonly:s=!1,disabled:a=!1,touchedFields:o={},formSubmitted:l=!1,mode:c="test",onValueChange:u,onBlur:h,onFocus:d,className:f="",hideLabel:g=!1})=>{var m,w,y,C;const[x,F]=e.useState(i),[Q,U]=e.useState(!1),[E,S]=e.useState(""),[N,L]=e.useState(!1),[I,_]=e.useState(!1),[k,O]=e.useState({lat:40.7128,lng:-74.006}),[T,j]=e.useState(null),[H,P]=e.useState(10),[D,M]=e.useState(""),[R,K]=e.useState(!1),V=e.useRef(null),[G,z]=e.useState(!1),[q,W]=e.useState(null),[X,Y]=e.useState(!1);e.useEffect(()=>{if(i&&i.latitude&&i.longitude){40.7128===i.latitude&&-74.006===i.longitude||(F(i),j({lat:i.latitude,lng:i.longitude,isCurrentLocation:!1}),O({lat:i.latitude,lng:i.longitude}))}else null==i&&(F(null),j(null))},[i]),e.useEffect(()=>{I&&40.7128===k.lat&&k.lng},[I,k]),e.useEffect(()=>{(s||a)&&(I&&_(!1),D&&M(""),G&&(z(!1),W(null)))},[s,a]);const J=e.useCallback((e,t)=>b(void 0,void 0,void 0,function*(){Y(!0);try{const A=yield fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),r=yield A.json();if(r&&r.address){const e=r.address;return{placeName:r.display_name||"",city:e.city||e.town||e.village||e.municipality||"",country:e.country||""}}}catch(e){console.error("Reverse geocoding failed:",e)}finally{Y(!1)}return{placeName:"",city:"",country:""}}),[]),$=e.useCallback((e,t,r)=>b(void 0,void 0,void 0,function*(){const n=yield J(e,t),i=Object.assign({latitude:e,longitude:t,timestamp:Date.now(),placeName:n.placeName,city:n.city,country:n.country,address:n.placeName},r);if(F(i),j({lat:e,lng:t,isCurrentLocation:!1}),L(!0),u){u({id:A,value:i,isValid:!0,errors:{}})}}),[J,A,u]),Z=e.useCallback(()=>b(void 0,void 0,void 0,function*(){var e,t,A,n,i,o,l,c,u,h,d,f,p,g,m;if(s||a)return;U(!0),S("");if(void 0!==window.Capacitor)try{const{Geolocation:s}=window.Capacitor.Plugins;if(s)try{if("granted"!==(yield s.requestPermissions()).location)return U(!1),void S("Location permission is required. Please enable location access in your device settings.");const a=yield s.getCurrentPosition({enableHighAccuracy:null===(t=null===(e=r.validation)||void 0===e?void 0:e.enableHighAccuracy)||void 0===t||t,timeout:null!==(n=null===(A=r.validation)||void 0===A?void 0:A.timeout)&&void 0!==n?n:1e4,maximumAge:null!==(o=null===(i=r.validation)||void 0===i?void 0:i.maximumAge)&&void 0!==o?o:3e5}),l=a.coords.latitude,c=a.coords.longitude;return j({lat:l,lng:c,isCurrentLocation:!0}),O({lat:l,lng:c}),L(!0),yield $(l,c,{accuracy:a.coords.accuracy,timestamp:Date.now()}),U(!1),void S("")}catch(e){return U(!1),void((null===(l=e.message)||void 0===l?void 0:l.includes("permission"))||(null===(c=e.message)||void 0===c?void 0:c.includes("denied"))?S("Location permission is required. Please enable location access in your device settings."):(null===(u=e.message)||void 0===u?void 0:u.includes("timeout"))?S("Location request timed out. Please try again."):S("Unable to retrieve your location. Please try again."))}}catch(e){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return U(!1),void S("Geolocation is not supported by this browser.");const w={enableHighAccuracy:null===(d=null===(h=r.validation)||void 0===h?void 0:h.enableHighAccuracy)||void 0===d||d,timeout:null!==(p=null===(f=r.validation)||void 0===f?void 0:f.timeout)&&void 0!==p?p:1e4,maximumAge:null!==(m=null===(g=r.validation)||void 0===g?void 0:g.maximumAge)&&void 0!==m?m:3e5};navigator.geolocation.getCurrentPosition(e=>b(void 0,void 0,void 0,function*(){const t=e.coords.latitude,A=e.coords.longitude;j({lat:t,lng:A,isCurrentLocation:!0}),O({lat:t,lng:A}),L(!0),yield $(t,A,{accuracy:e.coords.accuracy,timestamp:e.timestamp}),U(!1),S("")}),e=>{U(!1);let t="Unable to retrieve your location.";switch(e.code){case e.PERMISSION_DENIED:t="Location access denied by user. Please enable location access in your browser/device settings.";break;case e.POSITION_UNAVAILABLE:t="Location information is unavailable.";break;case e.TIMEOUT:t="Location request timed out. Please try again."}S(t)},w)}),[s,a,r,$]),ee=e.useCallback(()=>{if(!s&&!a&&(F(null),j(null),S(""),L(!0),u)){u({id:A,value:null,isValid:!0,errors:{}})}},[s,a,A,u]),te=e.useCallback(()=>{s||a||_(!I)},[s,a,I]),Ae=e.useCallback((e,t,A,r,n,i)=>{const s=e-n/2,a=t-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))}},[]),re=e.useCallback(e=>{s||a||!V.current||0===e.button&&(z(!0),W({x:e.clientX,y:e.clientY}),e.preventDefault())},[s,a]),ne=e.useCallback(e=>{if(!G||!q||!V.current)return;const t=e.clientX-q.x,A=e.clientY-q.y,r=156543.03392*Math.cos(k.lat*Math.PI/180)/Math.pow(2,H),n=-A*r/111320,i=t*r/(111320*Math.cos(k.lat*Math.PI/180));O({lat:k.lat+n,lng:k.lng+i}),W({x:e.clientX,y:e.clientY})},[G,q,k,H]),ie=e.useCallback(e=>b(void 0,void 0,void 0,function*(){if(!V.current)return;if(G&&q){const t=Math.abs(e.clientX-q.x),A=Math.abs(e.clientY-q.y);if(t>5||A>5)return z(!1),void W(null)}if(s||a)return z(!1),void W(null);const t=V.current.getBoundingClientRect(),A=e.clientX-t.left,r=e.clientY-t.top,{lat:n,lng:i}=Ae(A,r,k,H,t.width,t.height);yield $(n,i),z(!1),W(null)}),[s,a,V,k,H,Ae,$,G,q]),se=e.useCallback(e=>b(void 0,void 0,void 0,function*(){if(e.trim()&&!s&&!a){K(!0),S("");try{const t=yield fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(e)}&limit=5&addressdetails=1`),r=yield t.json();if(r&&r.length>0){const e=r[0],t=parseFloat(e.lat),n=parseFloat(e.lon),i=e.address||{},s={latitude:t,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(F(s),j({lat:t,lng:n,isCurrentLocation:!1}),O({lat:t,lng:n}),L(!0),u){u({id:A,value:s,isValid:!0,errors:{}})}}else S("No locations found for your search.")}catch(e){S("Failed to search for location. Please try again.")}finally{K(!1)}}}),[s,a,A,u]),ae=()=>{d&&d()},oe=()=>{L(!0),h&&h()},le=a||s||(null===(m=null==r?void 0:r.validation)||void 0===m?void 0:m.readonly),ce=(null===(w=null==r?void 0:r.basic)||void 0===w?void 0:w.label)||"Location",ue=(null===(y=null==r?void 0:r.basic)||void 0===y?void 0:y.description)||"";return p.jsxs("div",{className:`form-group ${g?"no-label":""} ${f}`,children:[!g&&p.jsxs("label",{htmlFor:A,className:"form-label",children:[ce,(null===(C=null==r?void 0:r.validation)||void 0===C?void 0:C.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]}),ue&&p.jsx("div",{className:"form-group-description",children:ue}),p.jsxs("div",{className:"location-wrapper",children:[!(s&&x)&&p.jsxs("div",{className:"location-controls",children:[p.jsx("button",{type:"button",className:"location-btn "+(Q?"loading":""),onClick:Z,disabled:le||Q,onFocus:ae,onBlur:oe,tabIndex:le?-1:0,children:Q?p.jsxs(p.Fragment,{children:[p.jsx(t.Loader2,{size:16,className:"loading-spinner"}),"Getting Location..."]}):p.jsxs(p.Fragment,{children:[p.jsx(t.Navigation,{size:16}),"Get Current Location"]})}),p.jsxs("button",{type:"button",className:"location-btn secondary",onClick:te,disabled:le,onFocus:ae,onBlur:oe,tabIndex:le?-1:0,children:[p.jsx(t.MapPin,{size:16}),I?"Hide Map":"Choose on Map"]})]}),x&&p.jsxs("div",{className:"location-display",children:[!s&&p.jsx("button",{type:"button",className:"location-clear-btn",onClick:ee,disabled:le,title:"Clear location",children:p.jsx(t.X,{size:16})}),x.placeName&&p.jsxs("div",{className:"location-place-name",children:[p.jsx("strong",{children:"Place:"})," ",x.placeName]}),(x.city||x.country)&&p.jsxs("div",{className:"location-address",children:[p.jsx("strong",{children:"Address:"})," ",[x.city,x.country].filter(Boolean).join(", ")]}),p.jsxs("div",{className:"location-coordinates",children:[p.jsx("strong",{children:"Coordinates:"})," ",(de=x.latitude,fe=x.longitude,void 0===de||void 0===fe||isNaN(de)||isNaN(fe)?"":`${Number(de).toFixed(6)}, ${Number(fe).toFixed(6)}`)]}),x.accuracy&&p.jsxs("div",{className:"location-accuracy",children:[p.jsx("strong",{children:"Accuracy:"})," ",(he=x.accuracy,he?`±${Math.round(he)}m`:"")]}),x.timestamp&&p.jsxs("div",{className:"location-timestamp",children:[p.jsx("strong",{children:"Captured:"})," ",(B(x.timestamp)||new Date).toLocaleString()]})]}),I&&!s&&p.jsxs("div",{className:"location-map-container",children:[p.jsxs("div",{className:"location-map-header",children:[p.jsx("h4",{children:"Select Location on Map"}),p.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),p.jsx("div",{className:"location-search",children:p.jsx("form",{onSubmit:e=>{e.preventDefault(),D.trim()&&se(D)},className:"search-form",children:p.jsxs("div",{className:"search-input-group",children:[p.jsx("input",{type:"text",value:D,onChange:e=>{M(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:le||R}),p.jsx("button",{type:"submit",className:"search-btn",disabled:le||R||!D.trim(),children:R?p.jsx(t.Loader2,{size:16,className:"loading-spinner"}):"Search"})]})})}),p.jsxs("div",{ref:V,className:"location-map "+(G?"dragging":""),onMouseDown:re,onMouseMove:ne,onMouseUp:ie,onMouseLeave:()=>{z(!1),W(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:G?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${H}/${Math.floor((k.lng+180)/360*Math.pow(2,H))}/${Math.floor((1-Math.log(Math.tan(k.lat*Math.PI/180)+1/Math.cos(k.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,H))}.png) center/cover no-repeat`,userSelect:"none"},children:[T&&p.jsx("div",{className:"map-marker "+(T.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:p.jsx(t.MapPin,{size:24})}),p.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}}),p.jsxs("div",{className:"map-controls",children:[p.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>P(e=>Math.min(18,e+1)),disabled:H>=18,children:"+"}),p.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>P(e=>Math.max(1,e-1)),disabled:H<=1,children:"−"})]})]}),p.jsxs("div",{className:"location-map-instructions",children:[p.jsx("p",{children:p.jsx("strong",{children:"Instructions:"})}),p.jsxs("ul",{children:[p.jsx("li",{children:"Search for a place using the search box above"}),p.jsx("li",{children:"Click anywhere on the map to select a location"}),p.jsx("li",{children:"Drag the map to pan around"}),p.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),p.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),X&&p.jsxs("div",{className:"location-loading",children:[p.jsx(t.Loader2,{size:16,className:"loading-spinner"}),p.jsx("span",{children:"Loading address details..."})]})]}),E&&p.jsx("div",{className:"location-error",children:E})]}),p.jsx(v,{validationErrors:n,fieldId:A,touchedFields:o,formSubmitted:l,properties:r,localValidation:{isValid:!0,errors:{}},isTouched:N,mode:c})]});var he,de,fe},O=({id:e,properties:t,className:A="",hideLabel:r=!1})=>{var n,i,s;const a=null!==(s=null!==(i=null===(n=t.styles)||void 0===n?void 0:n.level)&&void 0!==i?i:t.basic.level)&&void 0!==s?s:1,o=t.basic.label,l=()=>{var e;return`form-heading ${`h${a}`} ${(null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.textAlign)?`text-${t.styles.textAlign}`:""} ${A}`.trim()},c=()=>{var e,A;const r={};return(null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.fontSize)&&(r.fontSize=t.styles.fontSize),(null===(A=null==t?void 0:t.styles)||void 0===A?void 0:A.color)&&(r.color=t.styles.color),r};return r?null:(()=>{const t={id:e,className:l(),style:c()};switch(a){case 1:default:return p.jsx("h1",Object.assign({},t,{children:o}));case 2:return p.jsx("h2",Object.assign({},t,{children:o}));case 3:return p.jsx("h3",Object.assign({},t,{children:o}));case 4:return p.jsx("h4",Object.assign({},t,{children:o}));case 5:return p.jsx("h5",Object.assign({},t,{children:o}));case 6:return p.jsx("h6",Object.assign({},t,{children:o}))}})()},T=({id:A,properties:r,mode:n="preview",formValue:i,onValueChange:s,className:a="",hideLabel:o=!1})=>{var l,c,u;const[h,d]=e.useState(""),[f,g]=e.useState((null===(l=r.validation)||void 0===l?void 0:l.listStyle)||"numbers"),[m,w]=e.useState("#000000"),v=e.useRef(null),b=e.useRef(null),B=e.useRef(!1),y="edit"===n,C=e.useRef({instructions:[],listStyle:"numbers",formValue:void 0}),x=e.useRef(n);e.useEffect(()=>{var e,t,A,s,a;let o=[],l="numbers";if(null!=i&&("object"==typeof i&&i.instructions?(Array.isArray(i.instructions)?o=i.instructions:"string"==typeof i.instructions&&(o=[i.instructions]),i.listStyle&&(l=i.listStyle)):Array.isArray(i)?o=i:"string"==typeof i&&(o=[i])),0===o.length&&(null===(e=r.basic)||void 0===e?void 0:e.value)){const e=r.basic.value;e&&"object"==typeof e&&!Array.isArray(e)&&e.instructions?(Array.isArray(e.instructions)?o=e.instructions:"string"==typeof e.instructions&&(o=[e.instructions]),e.listStyle&&"string"==typeof e.listStyle&&(l=e.listStyle)):Array.isArray(e)?o=e:"string"==typeof e&&(o=[e])}0===o.length&&(null===(t=r.basic)||void 0===t?void 0:t.instructions)&&(Array.isArray(r.basic.instructions)?o=r.basic.instructions:"string"==typeof r.basic.instructions&&(o=[r.basic.instructions])),l&&"numbers"!==l||(l=(null===(A=r.validation)||void 0===A?void 0:A.listStyle)||(null===(a=null===(s=r.basic)||void 0===s?void 0:s.value)||void 0===a?void 0:a.listStyle)||"numbers");const c=JSON.stringify(o)!==JSON.stringify(C.current.instructions)||l!==C.current.listStyle,u=n!==x.current,h=JSON.stringify(i)!==JSON.stringify(C.current.formValue),f=!C.current.formValue||Array.isArray(C.current.formValue)&&0===C.current.formValue.length||"string"==typeof C.current.formValue&&""===C.current.formValue.trim(),p=null!=i&&(Array.isArray(i)&&i.length>0||"string"==typeof i&&""!==i.trim()||"object"==typeof i&&Object.keys(i).length>0);if(c||u||h||f&&p){const e=e=>"string"!=typeof e?e:e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))),t=o.map(t=>"string"==typeof t?e(t):t),A=t.some(e=>"string"==typeof e&&/<[^>]+>/.test(e));let r="";if(t.length>0)if(A)r=t.join("");else{const e="numbers"===l?"ol":"bullets"===l?"ul":"div",A=t.filter(e=>e&&"string"==typeof e).map(e=>`<li>${e.replace(/\n/g,"<br>")}</li>`).join("");r="div"===e?t.filter(e=>e&&"string"==typeof e).map(e=>`<div>${e.replace(/\n/g,"<br>")}</div>`).join(""):`<${e}>${A}</${e}>`}g(l),d(r),y&&v.current&&(u||c&&v.current.innerHTML.trim()!==r.trim())&&(v.current.innerHTML=r),C.current={instructions:o,listStyle:l,formValue:i},x.current=n}},[i,null===(c=r.basic)||void 0===c?void 0:c.instructions,null===(u=r.validation)||void 0===u?void 0:u.listStyle,n,y]),e.useEffect(()=>{if(y&&v.current){const e=v.current.innerHTML.trim();h.trim()===e||B.current||(v.current.innerHTML=h)}if(B.current){const e=setTimeout(()=>{B.current=!1},200);return()=>clearTimeout(e)}},[h,y]);const F=e.useCallback(()=>{if(!v.current)return;B.current=!0;const e=v.current.innerHTML.trim();if(s){s({id:A,value:{instructions:e?[e]:[],listStyle:f},isValid:!0,errors:{}})}e!==h&&d(e)},[A,f,s,h]),Q=e.useCallback(()=>{if(!v.current)return;const e=v.current.innerHTML.trim();if(s){s({id:A,value:{instructions:e?[e]:[],listStyle:f},isValid:!0,errors:{}})}d(e),B.current=!1},[A,f,s]),U=e.useCallback((e,t)=>{var A;document.execCommand(e,!1,t),null===(A=v.current)||void 0===A||A.focus(),F()},[F]),E=e.useCallback(()=>{U("bold")},[U]),S=e.useCallback(()=>{U("italic")},[U]),N=e.useCallback(e=>{const t=e.target.value;w(t),U("foreColor",t)},[U]),L=e.useCallback(e=>{if(g(e),!v.current)return;const t=window.getSelection(),r=t&&t.rangeCount>0?t.getRangeAt(0):null;let n=v.current.innerHTML;if("numbers"===e){if(n=n.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!n.includes("<ol>")&&!n.includes("<ul>")){const e=n.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(n="<ol>"+e.map(e=>`<li>${e}</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 e=n.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(n="<ul>"+e.map(e=>`<li>${e}</li>`).join("")+"</ul>")}}else n=n.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(v.current.innerHTML=n,d(n),r&&t)try{t.removeAllRanges(),t.addRange(r)}catch(e){}if(F(),s){s({id:A,value:{instructions:n?[n]:[],listStyle:e},isValid:!0,errors:{}})}},[A,F,s]),I=e.useCallback(e=>{var t;const A=null===(t=e.target.files)||void 0===t?void 0:t[0];if(!A||!A.type.startsWith("image/"))return;const r=new FileReader;r.onload=e=>{var t;const A=null===(t=e.target)||void 0===t?void 0:t.result;if(A&&v.current){const e=document.createElement("img");e.src=A,e.style.maxWidth="100%",e.style.height="auto";const t=window.getSelection();if(t&&t.rangeCount>0){const A=t.getRangeAt(0);A.deleteContents(),A.insertNode(e)}else v.current.appendChild(e);F()}},r.readAsDataURL(A),b.current&&(b.current.value="")},[F]),_=e.useCallback(e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain"),A=window.getSelection();if(A&&A.rangeCount>0){const e=A.getRangeAt(0);e.deleteContents();const r=document.createTextNode(t);e.insertNode(r),e.setStartAfter(r),e.collapse(!0),A.removeAllRanges(),A.addRange(e)}F()},[F]),k=e.useCallback(e=>document.queryCommandState(e),[]);return p.jsxs("div",{className:`form-group instruction-group ${a}`,children:[!o&&p.jsx("label",{htmlFor:A,className:"instruction-label",children:"Instructions"}),y?p.jsxs("div",{className:"instruction-rich-editor",children:[p.jsxs("div",{className:"instruction-toolbar",children:[p.jsxs("div",{className:"toolbar-group",children:[p.jsx("button",{type:"button",className:"toolbar-btn "+(k("bold")?"active":""),onClick:E,title:"Bold","aria-label":"Bold",children:p.jsx(t.Bold,{size:16})}),p.jsx("button",{type:"button",className:"toolbar-btn "+(k("italic")?"active":""),onClick:S,title:"Italic","aria-label":"Italic",children:p.jsx(t.Italic,{size:16})})]}),p.jsx("div",{className:"toolbar-separator"}),p.jsx("div",{className:"toolbar-group",children:p.jsxs("div",{className:"color-picker-wrapper",children:[p.jsx("input",{type:"color",value:m,onChange:N,className:"color-picker-input",title:"Text Color"}),p.jsx("label",{className:"color-picker-label",title:"Text Color",children:p.jsx("span",{style:{color:m},children:"A"})})]})}),p.jsx("div",{className:"toolbar-separator"}),p.jsxs("div",{className:"toolbar-group",children:[p.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===f?"active":""),onClick:()=>L("bullets"),title:"Bullet List","aria-label":"Bullet List",children:p.jsx(t.List,{size:16})}),p.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===f?"active":""),onClick:()=>L("numbers"),title:"Numbered List","aria-label":"Numbered List",children:p.jsx(t.ListOrdered,{size:16})})]}),p.jsx("div",{className:"toolbar-separator"}),p.jsxs("div",{className:"toolbar-group",children:[p.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>{var e;return null===(e=b.current)||void 0===e?void 0:e.click()},title:"Insert Image","aria-label":"Insert Image",children:p.jsx(t.Image,{size:16})}),p.jsx("input",{ref:b,type:"file",accept:"image/*",onChange:I,style:{display:"none"}})]})]}),p.jsx("div",{ref:v,contentEditable:!0,className:"instruction-editor-content",onInput:F,onBlur:Q,onPaste:_,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):p.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===f?"instruction-list-numbers":"bullets"===f?"instruction-list-bullets":""),children:h?p.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:h}}):p.jsx("div",{className:"instruction-empty",children:p.jsx("p",{children:"No instructions provided"})})})]})},j=({attachments:A,onRemove:r})=>{const[n,i]=e.useState(new Map);return e.useEffect(()=>{if(!A)return void i(e=>(e.forEach(e=>URL.revokeObjectURL(e)),new Map));const e=new Map;return A.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(e=>URL.revokeObjectURL(e))}},[A]),A&&0!==A.length?p.jsx("div",{className:"attachment-thumbnails-container",children:A.map((e,A)=>{const i=e&&e.type&&"string"==typeof e.type&&e.type.startsWith("image/"),s=n.get(A);return p.jsx("div",{className:"attachment-thumbnail",children:i&&s?p.jsxs(p.Fragment,{children:[p.jsx("img",{src:s,alt:e?e.name:"Attachment"}),p.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(A),title:"Remove attachment",children:p.jsx(t.X,{size:14})})]}):p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"file-icon-placeholder",children:p.jsx(t.Paperclip,{size:20})}),p.jsx("span",{className:"file-name",children:e?e.name:"Unknown File"}),p.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(A),title:"Remove attachment",children:p.jsx(t.X,{size:14})})]})},A)})}):null},H=({component:A,mode:r,formTemplateId:n,formValue:i,onNotesChange:s,onAttachmentChange:a,notes:o="",attachments:l=null,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onBasicPropertyActionCompletion:h,workOrderNumber:d,assetNumber:f,isStandalone:g,user:m,onCreateIssue:w,onUpdateIssue:v})=>{var b,B,y,x;const[F,Q]=e.useState(o||""),[U,E]=e.useState(l||null),[S,N]=e.useState(!1),[L,I]=e.useState(!1),[_,k]=e.useState(!1),[O,T]=e.useState(!1),[H,P]=e.useState(null),[D,M]=e.useState(!1),R=e.useRef(null),K=e.useRef(i),V=e.useRef(!1),G=e.useRef(!1);e.useEffect(()=>{if(!V.current&&null!=o){const e="string"==typeof o?o:String(o||"");Q(e),V.current=!0}},[o]),e.useEffect(()=>{G.current||void 0===l||(E(l),G.current=!0)},[l]),e.useEffect(()=>{if(V.current&&!S&&null!=o){const e="string"==typeof o?o:String(o||"");F&&""!==String(F||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==F&&Q(e):Q(e)}},[o,S,F]),e.useEffect(()=>{G.current&&void 0!==l&&(!U||l&&l.length>0&&l!==U)&&E(l)},[l,U]),e.useEffect(()=>{const e=["select","radio","checkbox","segment"].includes(A.name||"");if(e){const e=K.current,t=i;let r=!1;if("checkbox"===A.name){const A=Array.isArray(e)?e:e?[e]:[],n=Array.isArray(t)?t:t?[t]:[];r=JSON.stringify(A.sort())!==JSON.stringify(n.sort())}else r=e!==t&&void 0!==e;if(r){k(!1),T(!1),P(null),I(!1),N(!1),M(!1);const e="string"==typeof o?o:String(o||"");e&&""!==e.trim()?Q(e):Q(""),l&&0!==l.length?E(l):E(null)}K.current=t}e||(K.current=i)},[i,A.name,o,l]);const z=e.useCallback((e,t)=>{const{operator:A,value:r}=e,n=String(t).toLowerCase(),i=String(r).toLowerCase();switch(A){case"equals":return n===i||String(t)===String(r);case"notEquals":return n!==i&&String(t)!==String(r);case"greaterThan":return Number(t)>Number(r);case"lessThan":return Number(t)<Number(r);case"greaterThanOrEqual":return Number(t)>=Number(r);case"lessThanOrEqual":return Number(t)<=Number(r);default:return!1}},[]),q=e.useCallback(()=>{if(!(null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length)))return[];const e=A.condition;if(!e||!e.conditions||0===e.conditions.length)return[];const t=[];if("checkbox"===A.name&&Array.isArray(i))i.forEach(A=>{const r=e.conditions.find(e=>z(e,A));r&&!t.find(e=>e.id===r.id)&&t.push(r)});else{const A=e.conditions.find(e=>z(e,i));A&&t.push(A)}return t},[A,i,z]),W=e.useCallback(e=>{const t=e.target.value;Q(t),s&&s(t);const r=q(),n=String(t||"").trim().length>0;r.forEach(e=>{!0===e.enableNotes&&c&&c(e.id,"notes",n)});const i=A.condition;!(i&&i.conditions&&i.conditions.length>0)&&h&&h("notes",n)},[s,q,c,A,h]),X=e.useCallback(()=>{if(s){const e="string"==typeof F?F:String(F||"");s(e),setTimeout(()=>{N(!1)},0)}else N(!1)},[F,s]),Y=e.useCallback(()=>{X()},[X]),J=e.useCallback(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),X())},[X]),$=e.useCallback(()=>{N(!0)},[]),Z=e.useCallback(()=>{N(!0)},[]),ee=e.useCallback(()=>{var e;null===(e=R.current)||void 0===e||e.click()},[]),te=e.useCallback(e=>{const t=e.target.files;if(t&&t.length>0){const e=Array.from(t);E(e),a&&a(e);q().forEach(e=>{!0===e.enableAttachment&&c&&c(e.id,"attachments",!0)});const r=A.condition;!(r&&r.conditions&&r.conditions.length>0)&&h&&h("attachments",!0)}R.current&&(R.current.value="")},[a,q,c,A,h]),Ae=e.useCallback(e=>{if(U){const t=U.filter((t,A)=>A!==e);if(0===t.length){E(null),a&&a(null);q().forEach(e=>{!0===e.enableAttachment&&c&&c(e.id,"attachments",!1)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&h&&h("attachments",!1)}else E(t),a&&a(t)}},[U,a,q,c,A,h]),re=e.useCallback(()=>{k(!0);q().forEach(e=>{!0===e.enableSendEmail&&c&&c(e.id,"email",!0)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&h&&h("email",!0),setTimeout(()=>{k(!1)},3e3)},[q,c,A,h]),ne=e.useCallback(()=>{I(!0)},[]),ie=e.useCallback(()=>{I(!1)},[]),se=e.useCallback(e=>{I(!1),T(!0),e&&P(e);const t=A.condition;if(t&&t.conditions&&t.conditions.length>0){q().forEach(e=>{!0===e.enableRaiseIssue&&u&&u(e.id)})}else h&&h("issue",!0)},[A,h,q,u]);if("test"!==r)return null;const ae=["select","radio","checkbox","segment"].includes(A.name||""),oe=(null===(b=A.basic)||void 0===b?void 0:b.options)||A.options||[];let le=!1,ce=!1,ue=!1,he=!1,de=null;const fe=null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length),pe=A.condition,ge=pe&&pe.conditions&&pe.conditions.length>0;if(ge&&fe)if("checkbox"===A.name&&Array.isArray(i)){const e=i;for(const t of e){const e=pe.conditions.find(e=>z(e,t));e&&(le=le||!0===e.enableNotes,ce=ce||!0===e.enableAttachment,ue=ue||!0===e.enableRaiseIssue,he=he||!0===e.enableSendEmail)}}else if(ae){const e=pe.conditions.find(e=>z(e,i));e&&(le=!0===e.enableNotes,ce=!0===e.enableAttachment,ue=!0===e.enableRaiseIssue,he=!0===e.enableSendEmail)}else{const e=pe.conditions.find(e=>z(e,i));e&&(le=!0===e.enableNotes,ce=!0===e.enableAttachment,ue=!0===e.enableRaiseIssue,he=!0===e.enableSendEmail)}if(!ge){const e=A.basic,t=!0===(null==e?void 0:e.enableNotes),r=!0===(null==e?void 0:e.enableAttachment),n=!0===(null==e?void 0:e.enableRaiseIssue),s=!0===(null==e?void 0:e.enableSendEmail);if(ae)if(fe)if("checkbox"===A.name){(Array.isArray(i)?i:[i]).forEach(e=>{const t=oe.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(le=le||!0===t.enableNotes,ce=ce||!0===t.enableAttachment,ue=ue||!0===t.enableRaiseIssue,he=he||!0===t.enableSendEmail,de||(de=t))}),le=le||t,ce=ce||r,ue=ue||n,he=he||s}else if(de=oe.find(e=>!(!e||!e.value)&&(e.value===i||(String(e.value)===String(i)||(e.label===i||String(e.label)===String(i))))),de){const e=!0===de.enableNotes,A=!0===de.enableAttachment,i=!0===de.enableRaiseIssue,a=!0===de.enableSendEmail;le=e||t,ce=A||r,ue=i||n,he=a||s}else le=t,ce=r,ue=n,he=s;else le=t,ce=r,ue=n,he=s;else le=t,ce=r,ue=n,he=s}if(!(le||ce||ue||he))return null;const me=q(),we=A.condition,ve=we&&we.conditions&&we.conditions.length>0,be=!!ve&&me.some(e=>!0===e.enableNotes),Be=!!ve&&me.some(e=>!0===e.enableAttachment),ye=!!ve&&me.some(e=>!0===e.enableSendEmail),Ce=!!ve&&me.some(e=>!0===e.enableRaiseIssue),xe=String(F||"").trim().length>0,Fe=U&&U.length>0,Qe=U?U.length:0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"component-action-features",children:[p.jsxs("div",{className:"action-icons-toolbar",children:[le&&p.jsxs("button",{type:"button",className:`action-icon-button ${xe?"active":""} ${be?"mandatory":""}`,onClick:$,title:"Add Notes",children:[p.jsx(t.MessageSquare,{size:14,fill:xe?"currentColor":"none"}),be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ce&&p.jsxs("button",{type:"button",className:`action-icon-button ${Fe?"active":""} ${Be?"mandatory":""}`,onClick:ee,title:"Add Attachment",children:[p.jsx(t.Paperclip,{size:14,fill:Fe?"currentColor":"none"}),Qe>0&&p.jsx("span",{className:"attachment-count-badge",children:Qe}),Be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),he&&p.jsxs("button",{type:"button",className:`action-icon-button ${_?"active sent":""} ${ye?"mandatory":""}`,onClick:re,disabled:_,title:"Send Email",children:[_?p.jsx(p.Fragment,{children:p.jsx(t.Check,{size:14})}):p.jsx(t.Mail,{size:14,fill:_?"currentColor":"none"}),ye&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ue&&p.jsxs("button",{type:"button",className:`action-icon-button ${O?"active":""} ${Ce?"mandatory":""}`,onClick:ne,title:"Raise an Issue",children:[p.jsx(t.AlertCircle,{size:14,fill:O?"currentColor":"none"}),Ce&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(xe&&le||Fe&&ce)&&p.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>M(!D),title:D?"Collapse":"Expand",children:D?p.jsx(t.ChevronUp,{size:14}):p.jsx(t.ChevronDown,{size:14})})]}),S&&le&&p.jsxs("div",{className:"notes-input-overlay",children:[p.jsx("textarea",{className:"action-notes-textarea",value:F,onChange:W,onBlur:Y,onKeyDown:J,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),p.jsxs("div",{className:"notes-input-actions",children:[p.jsx("button",{type:"button",className:"notes-save-button",onClick:X,title:"Save notes (Ctrl+Enter)",children:"Save"}),p.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{N(!1)},title:"Cancel",children:"Cancel"})]})]}),D&&p.jsxs("div",{className:"actions-content",children:[!S&&xe&&le&&p.jsx("div",{className:"notes-summary-section",children:p.jsxs("div",{className:"notes-full-text",onClick:Z,children:[p.jsx("span",{className:"notes-label",children:"Notes:"})," ",F]})}),Fe&&ce&&p.jsx("div",{className:"attachments-section",children:p.jsx(j,{attachments:U,onRemove:Ae})})]}),ce&&p.jsx("input",{ref:R,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:te,style:{display:"none"}})]}),L&&p.jsx(C,{isOpen:L,onClose:ie,onSuccess:se,issue:H,component:de?Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{label:`${(null===(B=A.basic)||void 0===B?void 0:B.label)||"Component"} - ${de.label||de.value}`,value:de.value||(null===(y=A.basic)||void 0===y?void 0:y.value)||""})}):Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{value:null!=i?Array.isArray(i)?i.join(", "):String(i):(null===(x=A.basic)||void 0===x?void 0:x.value)||""})}),formTemplateId:n||"",notes:F,attachments:U,workOrderNumber:d,assetNumber:f,user:m,isStandalone:g,onCreateIssue:w,onUpdateIssue:v})]})},P=({attachments:e})=>e&&0!==e.length?p.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,A)=>{var r;const n=(null===(r=e.type)||void 0===r?void 0:r.startsWith("image/"))||!1,i=n?(e=>e.data?e.data.startsWith("data:")?e.data:`data:${e.type||"image/png"};base64,${e.data}`:"")(e):"";return p.jsx("div",{className:"attachment-thumbnail",children:n&&i?p.jsx("img",{src:i,alt:e.name||`Attachment ${A+1}`}):p.jsxs("div",{className:"file-icon-placeholder",children:[p.jsx(t.Paperclip,{size:20}),p.jsx("span",{className:"file-name",children:e.name||`File ${A+1}`})]})},A)})}):null,D=({component:e})=>{var t,A;const r=(null===(t=e.basic)||void 0===t?void 0:t.notes)||"",n=(null===(A=e.basic)||void 0===A?void 0:A.attachments)||[],i=r&&r.trim().length>0,s=n&&n.length>0;return i||s?p.jsx("div",{className:"component-submission-actions",children:p.jsxs("div",{className:"actions-content",children:[i&&p.jsx("div",{className:"notes-summary-section",children:p.jsxs("div",{className:"notes-full-text",children:[p.jsx("span",{className:"notes-label",children:"Notes:"})," ",r]})}),s&&p.jsx("div",{className:"attachments-section",children:p.jsx(P,{attachments:n})})]})}):null},M=({child:e,selectedChild:A,mode:r,onChildSelect:s,onChildDelete:a,renderFormComponent:o,isOverlay:l=!1,isChildrenEditMode:c=!1,formData:u={},formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y})=>{var C,x;const F=u[e.id],Q="preview"===r&&((null===(C=e.basic)||void 0===C?void 0:C.notes)&&e.basic.notes.trim().length>0||(null===(x=e.basic)||void 0===x?void 0:x.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:U,listeners:E,setNodeRef:S,transform:N,transition:L,isDragging:I,isSorting:_}=n.useSortable({id:e.id,disabled:l||"edit"!==r}),k={transform:i.CSS.Transform.toString(N),transition:L,zIndex:I?1e3:"auto"};return p.jsxs("div",{ref:S,style:k,className:`form-component section-child ${(null==A?void 0:A.id)===e.id?"selected":""} ${I?"dragging":""} ${_?"sorting":""} ${c?"children-edit-active":""}`,onClick:()=>!I&&s(e),role:"button",tabIndex:0,children:[("edit"===r||c)&&p.jsx("div",Object.assign({className:"child-drag-handle"},E,U,{onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:p.jsx(t.GripVertical,{size:14})})),p.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===r||c)&&p.jsxs("div",{className:"component-actions child-actions",children:[p.jsx("button",{className:"btn edit-btn",onClick:t=>{t.stopPropagation(),s(e)},onMouseDown:e=>e.stopPropagation(),title:"Edit properties",children:p.jsx(t.Edit,{size:12})}),p.jsx("button",{className:"btn delete-btn",onClick:t=>a(e,t),onMouseDown:e=>e.stopPropagation(),title:"Delete component",children:p.jsx(t.Trash2,{size:12})})]}),p.jsxs("div",{className:"component-preview child-preview",children:[o(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:"test",formTemplateId:h,formValue:F,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y}),Q&&p.jsx(D,{component:e})]})]})]})},R=({id:A,properties:i,mode:s="edit",formData:a={},onValueChange:o,onSelect:l,isSelected:c=!1,className:u="",onSectionSelect:h,onChildSelect:d,onChildDelete:f,selectedChild:g,renderFormComponent:m,formTemplateId:w,onThresholdActionCompletion:v,onThresholdIssueRaised:b,onNotesChange:B,onAttachmentChange:y,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k})=>{var T,j,H,P,D,R;const[K,V]=e.useState(i.basic.collapsed),[G,z]=e.useState(!1),[q,W]=e.useState(!1),[X,Y]=e.useState(i.basic.label),[J,$]=e.useState(i.basic.description),[Z,ee]=e.useState(i.children||[]),[te,Ae]=e.useState(!1);e.useEffect(()=>{ee(i.children||[])},[i.children]),e.useEffect(()=>{Y(i.basic.label),$(i.basic.description)},[i.basic.label,i.basic.description]);const{setNodeRef:re,isOver:ne}=r.useDroppable({id:`section-${A}`,disabled:"edit"!==s}),ie=!("preview"!==s&&"test"!==s||i.children&&i.children.length>0),se=e.useCallback(e=>{Y(e),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{label:e})})})},[A,i,o]),ae=e.useCallback(e=>{$(e),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{description:e})})})},[A,i,o]),oe=e.useCallback(e=>{null==d||d(e)},[d]),le=e.useCallback((e,t)=>{t.stopPropagation();const A=Z.filter(t=>t.id!==e.id);ee(A),null==f||f(e.id)},[f,Z,A]),ce=e.useCallback(()=>{null==h||h(i),null==l||l()},[h,l,i]),ue=e.useCallback(e=>{e.stopPropagation(),"edit"===s&&Z.length>0&&Ae(!te)},[s,Z.length,te]),he=e.useCallback(e=>{e.stopPropagation(),V(!K),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{collapsed:!K})})})},[K,A,i,o]),de=m||e.useCallback(e=>{var t,A,r;const n=a[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let i=n;"number-input"===e.name&&"number"==typeof n?i=String(n):"number-input"===e.name&&null==n&&(i="");const l={id:e.id,properties:e,validationErrors:{},formValue:i,touchedFields:{},formSubmitted:!1,mode:s,onValueChange:o,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return p.jsx(F,Object.assign({},l,{properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return p.jsx(Q,Object.assign({},l,{properties:e,readonly:!1,disabled:!1}));case"select":const n=Object.assign(Object.assign({},e),{options:(null===(t=e.basic)||void 0===t?void 0:t.options)||[]});return p.jsx(U,Object.assign({},l,{properties:n,disabled:!1}));case"checkbox":const i=Object.assign(Object.assign({},e),{options:(null===(A=e.basic)||void 0===A?void 0:A.options)||[]});return p.jsx(E,Object.assign({},l,{properties:i,formValue:[],disabled:!1}));case"radio":const s=Object.assign(Object.assign({},e),{options:(null===(r=e.basic)||void 0===r?void 0:r.options)||[]});return p.jsx(S,Object.assign({},l,{properties:s,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},l,{properties:e,readonly:!1,disabled:!1}));case"signature":return p.jsx(I,Object.assign({},l,{properties:e}));case"heading":return p.jsx(O,Object.assign({},l,{properties:e}));default:return p.jsx("div",{className:"form-group",children:p.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}},[s,o,a]);if(ie)return null;const fe={backgroundColor:(null===(T=i.styles)||void 0===T?void 0:T.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(j=i.styles)||void 0===j?void 0:j.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(H=i.styles)||void 0===H?void 0:H.borderWidth)||"2px",borderRadius:(null===(P=i.styles)||void 0===P?void 0:P.borderRadius)||"8px",padding:(null===(D=i.styles)||void 0===D?void 0:D.padding)||"16px",margin:(null===(R=i.styles)||void 0===R?void 0:R.margin)||"16px 0"};return p.jsxs("div",{ref:re,className:`df-form-section ${c?"selected":""} ${ne?"drag-over":""} ${u}`,style:fe,children:[p.jsxs("div",{className:"section-header "+(te?"children-edit-mode":""),onClick:ce,onDoubleClick:ue,children:[p.jsx("div",{className:"section-header-content",children:p.jsxs("div",{className:"section-title",children:[p.jsx("span",{className:"section-toggle",title:K?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),he(e)},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),he(e))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:K?p.jsx(t.ChevronRight,{size:18}):p.jsx(t.ChevronDown,{size:18})}),"edit"===s&&G?p.jsx("input",{type:"text",value:X,onChange:e=>Y(e.target.value),onBlur:()=>{z(!1),se(X)},onKeyDown:e=>{"Enter"===e.key&&(z(!1),se(X))},className:"section-title-input",autoFocus:!0}):p.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===s&&z(!0),style:{display:"inline",margin:0},children:X||"Untitled Section"})]})}),(J||"edit"===s)&&p.jsx("div",{className:"section-description",children:"edit"===s&&q?p.jsx("textarea",{value:J,onChange:e=>$(e.target.value),onBlur:()=>{W(!1),ae(J)},onKeyDown:e=>{"Enter"===e.key&&e.ctrlKey&&(W(!1),ae(J))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):p.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===s&&W(!0),children:J||"Section description"})})]}),!K&&p.jsx("div",{className:`section-content ${ne?"drag-over":""} ${0===Z.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&ce()},children:p.jsx(n.SortableContext,{items:Z.map(e=>e.id),strategy:n.verticalListSortingStrategy,children:0===Z.length?p.jsxs("div",{className:"section-empty-state",onClick:ce,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:[p.jsx("div",{style:{fontWeight:"500",color:ne?"#3b82f6":"#374151"},children:ne?"Drop components here":"Empty Section"}),p.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):Z.map(e=>p.jsx(M,{child:e,selectedChild:g||null,mode:s,onChildSelect:oe,onChildDelete:le,renderFormComponent:de,isChildrenEditMode:te,formData:a,formTemplateId:w,onNotesChange:B,onAttachmentChange:y,onThresholdActionCompletion:v,onThresholdIssueRaised:b,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k},e.id))})})]})},K=({component:e,selectedComponent:A,mode:r,onComponentSelect:s,onComponentDelete:a,onComponentEdit:o,renderFormComponent:l,isOverlay:c=!1,formData:u={},formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B})=>{var y,C;const x=u[e.id],F="preview"===r&&((null===(y=e.basic)||void 0===y?void 0:y.notes)&&e.basic.notes.trim().length>0||(null===(C=e.basic)||void 0===C?void 0:C.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:Q,listeners:U,setNodeRef:E,transform:S,transition:N,isDragging:L,isSorting:I}=n.useSortable({id:e.id,disabled:c}),_={transform:i.CSS.Transform.toString(S),transition:N,opacity:L?.3:1,zIndex:L?1e3:"auto"};return p.jsxs("div",{ref:E,style:Object.assign(Object.assign({},_),{border:(null==A?void 0:A.id)===e.id?"2px solid #3b82f6":"1px solid var(--df-color-fb-border)",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",padding:"12px",position:"relative",minHeight:"80px",transition:"all 0.2s ease",boxShadow:(null==A?void 0:A.id)===e.id?"0 4px 12px rgba(59, 130, 246, 0.15)":"0 1px 3px rgba(0, 0, 0, 0.1)",cursor:"pointer"}),className:`form-component grid-component ${(null==A?void 0:A.id)===e.id?"selected":""} ${L?"dragging":""} ${I?"sorting":""}`,onClick:()=>!L&&s(e),role:"button",tabIndex:0,children:["edit"===r&&p.jsx("div",Object.assign({className:"component-drag-handle"},U,Q,{onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"50%",left:"4px",transform:"translateY(-50%)",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"4px",cursor:"grab",opacity:1,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:p.jsx(t.GripVertical,{size:12,color:"var(--df-color-text-light)"})})),p.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===r?"24px":"0",paddingLeft:"edit"===r?"28px":"0",minHeight:"60px"},children:[l(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:"test",formTemplateId:h,formValue:x,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B}),F&&p.jsx(D,{component:e})]}),"edit"===r&&p.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[o&&p.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),o(e)},type:"button",title:"Edit Component",style:{padding:"4px",backgroundColor:"#3b82f6",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#3b82f6"},children:p.jsx(t.Edit,{size:12})}),p.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),a(e,t)},type:"button",title:"Delete Component",style:{padding:"4px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#ef4444"},children:p.jsx(t.Trash2,{size:12})})]})]})},V=({gridComponents:e,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:a,selectedComponent:o,renderFormComponent:l,gridId:c,formData:u={},formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B})=>{const{setNodeRef:y,isOver:C}=r.useDroppable({id:`grid-drop-zone-${c}`,disabled:"edit"!==t});return p.jsx("div",{ref:y,className:"grid-drop-zone",style:{border:C?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:C?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?p.jsxs(p.Fragment,{children:[p.jsx(n.SortableContext,{items:e.map(e=>e.id),strategy:n.horizontalListSortingStrategy,children:p.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:e.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:e.map(e=>p.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:p.jsx(K,{component:e,selectedComponent:o,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:a,renderFormComponent:l,formData:u,formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B})},e.id))})}),p.jsx("div",{style:{border:C?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:C?"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:C?p.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):p.jsx("span",{children:"+ Drop more components here"})})]}):p.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:[p.jsx("div",{style:{fontWeight:"500",color:C?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:C?"Drop components here":"Empty DataGrid"}),p.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},G=({templateComponents:e,dataEntries:t,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:g,onThresholdIssueRaised:m,onNotesChange:w,onAttachmentChange:v,datagridId:b="",workOrderNumber:B,assetNumber:y,onCreateIssue:C,onUpdateIssue:x})=>0===e.length?p.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?p.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:[p.jsx("div",{style:{position:"absolute",top:"8px",right:"8px",zIndex:10,fontSize:"12px",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",padding:"4px 8px",borderRadius:"4px",border:"1px solid var(--df-color-fb-border)",opacity:e.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),p.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:[p.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*e.length+"px"},children:e.map((t,A)=>{var r;return p.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:A<e.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(null===(r=t.basic)||void 0===r?void 0:r.label)||`Column ${A+1}`},`header-${t.id}`)})}),t.length>0?t.map((s,o)=>p.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:o<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:o%2==0?"var(--df-color-fb-container)":"var(--df-color-fb-bg)",position:"relative",minWidth:150*e.length+"px",isolation:"isolate"},children:[e.map((t,i)=>{var a,l,c,u,h,F,Q;let U=null===(a=s.components)||void 0===a?void 0:a[i];const E=`${t.id||`component-${i}`}-entry-${b}-${o}-${i}`;return U=U?U.id!==E?Object.assign(Object.assign({},U),{id:E,basic:Object.assign(Object.assign({},U.basic),{showLabel:!1})}):Object.assign(Object.assign({},U),{id:U.id,basic:Object.assign(Object.assign({},U.basic),{showLabel:!1})}):Object.assign(Object.assign({},t),{id:E,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),p.jsxs("div",{style:{padding:"12px 16px",borderRight:i<e.length-1?"1px solid var(--df-color-fb-border)":"none",minHeight:"60px",minWidth:"150px",display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center",overflow:"visible",position:"relative",zIndex:1},children:[p.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:r?r(U,!0):A(U,!0)}),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(U.name)&&p.jsxs("div",{style:{marginTop:"8px",width:"100%"},children:[p.jsx(H,{component:U,mode:"test",formTemplateId:f,formValue:d[U.id],onThresholdActionCompletion:g,onThresholdIssueRaised:m,onNotesChange:w?e=>w(U.id,e):void 0,onAttachmentChange:v?e=>v(U.id,e):void 0,notes:(null===(l=U.basic)||void 0===l?void 0:l.notes)||(null===(c=d[U.id])||void 0===c?void 0:c.notes),attachments:(null===(u=U.basic)||void 0===u?void 0:u.attachments)||(null===(h=d[U.id])||void 0===h?void 0:h.attachments),workOrderNumber:B,assetNumber:y,onCreateIssue:C,onUpdateIssue:x}),"preview"===n&&((null===(F=U.basic)||void 0===F?void 0:F.notes)||(null===(Q=U.basic)||void 0===Q?void 0:Q.attachments))&&p.jsx(D,{component:U})]})]},`${s.id}-${i}`)}),i&&t.length>l&&p.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=l)&&h)try{h(o)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=l,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:t.length<=l?"#f3f4f6":"#ef4444",color:t.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.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:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#ef4444")},children:p.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},s.id)):p.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&&p.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:p.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=o)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=o,style:{padding:"8px 16px",backgroundColor:t.length>=o?"#f3f4f6":"#10b981",color:t.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#10b981")},children:[p.jsx("span",{style:{fontSize:"16px"},children:"+"}),s]})})]}):p.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[t.length>0?t.map((s,o)=>p.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:[p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[p.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",o+1]}),i&&t.length>1&&p.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=l)&&h)try{h(o)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=l,style:{padding:"4px 8px",backgroundColor:t.length<=l?"#f3f4f6":"#ef4444",color:t.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.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:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#ef4444")},children:p.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),p.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:e.map((e,t)=>{var i,a,l;let c=null===(i=s.components)||void 0===i?void 0:i[t];const u=`${e.id||`component-${t}`}-entry-${b}-${o}-${t}`;return c||(c=null===(a=s.components)||void 0===a?void 0:a.find(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)})),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({},e),{id:u,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),p.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[p.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:(null===(l=e.basic)||void 0===l?void 0:l.label)||`Field ${t+1}`}),p.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)&&p.jsx(H,{component:c,mode:"test",formTemplateId:f,formValue:d[c.id],onThresholdActionCompletion:g,onThresholdIssueRaised:m,onNotesChange:w?e=>w(c.id,e):void 0,onAttachmentChange:v?e=>v(c.id,e):void 0}),"preview"===n&&(()=>{var e,t;return(null===(e=c.basic)||void 0===e?void 0:e.notes)&&c.basic.notes.trim().length>0||(null===(t=c.basic)||void 0===t?void 0:t.attachments)&&Array.isArray(c.basic.attachments)&&c.basic.attachments.length>0?p.jsx(D,{component:c}):null})()]})]},`${s.id}-${t}`)})})]},s.id)):p.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&&p.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:p.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=o)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=o,style:{padding:"8px 16px",backgroundColor:t.length>=o?"#f3f4f6":"#10b981",color:t.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#10b981")},children:[p.jsx("span",{children:"+"}),s]})})]}),z=({id:A,properties:r,mode:n="edit",formData:i={},validationErrors:s={},touchedFields:a={},formSubmitted:o=!1,onValueChange:l,onSelect:c,isSelected:u=!1,className:h="",onDataGridSelect:d,onComponentSelect:f,onComponentDelete:g,onComponentEdit:m,onComponentUpdate:w,selectedComponent:v,renderFormComponent:b,onEntryAdd:B,onEntryRemove:y,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,workOrderNumber:j,assetNumber:H,onCreateIssue:P,onUpdateIssue:D})=>{var M,R,K,z,q,W,X,Y,J,$,Z,ee;const[te,Ae]=e.useState(!1),re=e.useRef(!1);let ne=r.templateComponents||[];const ie=r.entries||[];0===ne.length&&ie.length>0&&ie[0].components&&(ne=ie[0].components.map(e=>{var t;return Object.assign(Object.assign({},e),{id:(null===(t=e.id)||void 0===t?void 0:t.replace(/-entry-\d+$/,""))||e.id,basic:Object.assign(Object.assign({},e.basic),{showLabel:!0})})})),e.useEffect(()=>{if("edit"===n&&!r.templateComponents&&l&&re.current){const e=Object.assign(Object.assign({},r),{templateComponents:[]});JSON.stringify(e)!==JSON.stringify(r)&&l({id:A,value:e})}re.current=!0},[r.templateComponents,A,l,r,n]),e.useEffect(()=>{if(ne.length>0){if("test"===n&&0===ie.length&&re.current){const e={id:`entry-${A}-0`,index:0,components:ne.map((e,t)=>{const r=e.id||`component-${t}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${A}-0-${t}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(l){const t=Object.assign(Object.assign({},r),{entries:[e]});JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t})}return}if("edit"!==n||!re.current)return;const e=ie.some(e=>{var t;return null===(t=e.components)||void 0===t?void 0:t.some((t,A)=>{var r;const n=`${null===(r=ne[A])||void 0===r?void 0:r.id}-entry-${e.index}-${A}`;return t.id!==n})});if(e&&l){const e=ie.map(e=>{var t;return Object.assign(Object.assign({},e),{components:(null===(t=e.components)||void 0===t?void 0:t.map((t,A)=>{var r;return Object.assign(Object.assign({},t),{id:`${null===(r=ne[A])||void 0===r?void 0:r.id}-entry-${e.index}-${A}`})}))||[]})}),t=Object.assign(Object.assign({},r),{entries:e});return void(JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t}))}if(0===ie.length&&"edit"===n){const e={id:`entry-${A}-0`,index:0,components:ne.map((e,t)=>{const r=e.id||`component-${t}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${A}-0-${t}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(l){const t=Object.assign(Object.assign({},r),{entries:[e]});JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t})}}else if(ie.length>0){const e=ie.some(e=>ne.some((t,A)=>{var r,n,i,s,a,o,l,c,u,h,d;const f=null===(r=e.components)||void 0===r?void 0:r[A];if(!f)return!0;const p=`${t.id}-entry-${e.index}-${A}`,g=f.id===p,m=JSON.stringify(null===(n=f.basic)||void 0===n?void 0:n.options)!==JSON.stringify(null===(i=t.basic)||void 0===i?void 0:i.options)||(null===(s=f.basic)||void 0===s?void 0:s.placeholder)!==(null===(a=t.basic)||void 0===a?void 0:a.placeholder)||(null===(o=f.basic)||void 0===o?void 0:o.defaultValue)!==(null===(l=t.basic)||void 0===l?void 0:l.defaultValue)||(null===(c=f.basic)||void 0===c?void 0:c.label)!==(null===(u=t.basic)||void 0===u?void 0:u.label)||(null===(h=f.validation)||void 0===h?void 0:h.required)!==(null===(d=t.validation)||void 0===d?void 0:d.required);return!g||m}));if(e&&l){const e=ie.map(e=>{const t=ne.map((t,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(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)}));const a=`${t.id||`component-${r}`}-entry-${A}-${e.index}-${r}`;if(s){return Object.assign(Object.assign({},t),{id:a,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}return Object.assign(Object.assign({},t),{id:a,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})});return Object.assign(Object.assign({},e),{components:t})}),t=Object.assign(Object.assign({},r),{entries:e});JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t})}}}},[ne,ie,A,l,r,n,r.templateComponents]);const se=e.useCallback(e=>{e.stopPropagation(),null==c||c(),null==d||d(r)},[c,d,r]),ae=e.useCallback((e,t)=>{t.stopPropagation(),g&&g(e,t);const n=ne.filter(t=>t.id!==e.id),i=ie.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))}))||[]})});l&&l({id:A,value:Object.assign(Object.assign({},r),{templateComponents:n,entries:i})})},[g,r,l,A,ne,ie]),oe=e.useCallback((e,t)=>{w&&w(e,t);const n=ne.map(A=>A.id===e?Object.assign(Object.assign({},A),t):A);l&&l({id:A,value:Object.assign(Object.assign({},r),{templateComponents:n})})},[w,r,l,A,ne]),le=e.useCallback(e=>{"test"===n&&l&&l({id:e.id,value:e.value})},[l]),ce=e.useCallback(()=>{const e=r.entries||[],t=e.length,n={id:`entry-${A}-${t}`,index:t,components:ne.map((e,r)=>{const n=`${e.id||`component-${r}`}-entry-${A}-${t}-${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:{}},i=[...e,n];l&&l({id:A,value:Object.assign(Object.assign({},r),{entries:i})}),null==B||B()},[r,l,A,B,ne]),ue=e.useCallback(e=>{const t=r.entries.filter((t,A)=>A!==e).map((e,t)=>Object.assign(Object.assign({},e),{index:t,id:`entry-${A}-${t}`}));l&&l({id:A,value:Object.assign(Object.assign({},r),{entries:t})})},[r,l,A,y]),he=e.useCallback((e,t=!1)=>{var A,r,l;const c=i[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let u=c;"number-input"===e.name&&"number"==typeof c?u=String(c):"number-input"===e.name&&null==c&&(u="");const h={id:e.id,properties:e,validationErrors:s||{},formValue:u,touchedFields:a||{},formSubmitted:o||!1,mode:n,hideLabel:t,onValueChange:le,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return p.jsx(F,Object.assign({},h,{properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1,hideLabel:t}));case"textarea":return p.jsx(Q,Object.assign({},h,{properties:e,readonly:!1,disabled:!1,hideLabel:t}));case"select":const n=Object.assign(Object.assign({},e),{options:(null===(A=e.basic)||void 0===A?void 0:A.options)||[]});return p.jsx(U,Object.assign({},h,{properties:n,disabled:!1,hideLabel:t}));case"checkbox":const i=Object.assign(Object.assign({},e),{options:(null===(r=e.basic)||void 0===r?void 0:r.options)||[]});return p.jsx(E,Object.assign({},h,{properties:i,formValue:[],disabled:!1,hideLabel:t}));case"radio":const s=Object.assign(Object.assign({},e),{options:(null===(l=e.basic)||void 0===l?void 0:l.options)||[]});return p.jsx(S,Object.assign({},h,{properties:s,readonly:!1,disabled:!1,hideLabel:t}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},h,{properties:e,readonly:!1,disabled:!1,hideLabel:t}));case"signature":return p.jsx(I,Object.assign({},h,{properties:e,hideLabel:t}));case"heading":return p.jsx(O,Object.assign({},h,{properties:e,hideLabel:t}));case"instructions":return p.jsx(T,Object.assign({},h,{properties:e,hideLabel:t}));default:return p.jsxs("div",{className:"unknown-component",children:["Unknown component: ",e.name]})}},[n,le,i,s,a,o]),de={backgroundColor:r.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:r.styles.borderColor||"var(--df-color-fb-border)",borderWidth:r.styles.borderWidth||"2px",borderRadius:r.styles.borderRadius||"8px",padding:r.styles.padding||"16px",margin:r.styles.margin||"16px 0"};return p.jsxs("div",{className:`form-group df-form-datagrid ${u?"selected":""} ${h}`,onClick:se,style:de,children:[p.jsx("div",{className:"grid-header",children:p.jsx("div",{className:"grid-title",onClick:e=>{e.stopPropagation(),Ae(!te),null==l||l({id:A,value:Object.assign(Object.assign({},r),{basic:Object.assign(Object.assign({},r.basic),{collapsed:!te})})})},children:p.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[te?p.jsx(t.ChevronRight,{size:16}):p.jsx(t.ChevronDown,{size:16}),p.jsx(t.Grid,{size:16}),p.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:r.basic.label}),r.validation.required&&p.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),r.basic.description&&!te&&p.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:r.basic.description}),!te&&p.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===n?p.jsx(V,{gridComponents:ne,mode:n,onComponentSelect:f||(()=>{}),onComponentDelete:ae,onComponentEdit:m,onComponentUpdate:oe,selectedComponent:v||null,renderFormComponent:b||he,gridId:A,formData:i,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,workOrderNumber:j,assetNumber:H,onCreateIssue:P,onUpdateIssue:D}):p.jsx(G,{templateComponents:ne,dataEntries:ie,renderFormComponent:b||he,mode:n,allowAddRemoveEntries:null===(R=null===(M=r.datagrid)||void 0===M?void 0:M.allowAddRemoveEntries)||void 0===R||R,addAnotherText:null!==(z=null===(K=r.datagrid)||void 0===K?void 0:K.addAnotherText)&&void 0!==z?z:"Add Entry",removeText:null!==(W=null===(q=r.datagrid)||void 0===q?void 0:q.removeText)&&void 0!==W?W:"Remove",maxEntries:null!==(Y=null===(X=r.datagrid)||void 0===X?void 0:X.maxEntries)&&void 0!==Y?Y:10,minEntries:null!==($=null===(J=r.datagrid)||void 0===J?void 0:J.minEntries)&&void 0!==$?$:1,displayAsGrid:null===(ee=null===(Z=r.datagrid)||void 0===Z?void 0:Z.displayAsGrid)||void 0===ee||ee,onAddEntry:B||ce,onRemoveEntry:y||ue,formData:i,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,datagridId:A,workOrderNumber:j,assetNumber:H,onCreateIssue:P,onUpdateIssue:D})})]})},q=e.lazy(()=>Promise.resolve().then(function(){return Z})),W=e=>e.id?e:Object.assign(Object.assign({},e),{id:s.v4()}),X=({component:e,mode:t,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,g;const m=r[e.id],w="preview"===t&&((null===(f=e.basic)||void 0===f?void 0:f.notes)&&e.basic.notes.trim().length>0||(null===(g=e.basic)||void 0===g?void 0:g.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return p.jsxs("div",{className:"simple-table-component",children:[A(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:"test",formTemplateId:n,formValue:m,onThresholdActionCompletion:i,onThresholdIssueRaised:s,onNotesChange:a?t=>a(e.id,t):void 0,onAttachmentChange:o?t=>o(e.id,t):void 0,workOrderNumber:l,assetNumber:c,user:u,onCreateIssue:h,onUpdateIssue:d}),w&&p.jsx(D,{component:e})]})},Y=({component:e,selectedComponent:A,mode:r,onComponentSelect:s,onComponentDelete:a,onComponentEdit:o,renderFormComponent:l,isOverlay:c=!1})=>{const{attributes:u,listeners:h,setNodeRef:d,transform:f,transition:g,isDragging:m,isSorting:w}=n.useSortable({id:e.id,disabled:c}),v={transform:i.CSS.Transform.toString(f),transition:g,opacity:m?.3:1,zIndex:m?1e3:"auto"};return p.jsxs("div",{ref:d,style:v,className:`form-component table-component ${(null==A?void 0:A.id)===e.id?"selected":""} ${m?"dragging":""} ${w?"sorting":""}`,onClick:()=>!m&&s(e),role:"button",tabIndex:0,children:["edit"===r&&p.jsx("div",Object.assign({className:"component-drag-handle"},h,u,{onClick:e=>e.stopPropagation(),style:{opacity:1},children:p.jsx(t.GripVertical,{size:14})})),p.jsx("div",{className:"component-content",children:l(e)}),"edit"===r&&p.jsxs("div",{className:"component-actions",style:{opacity:1},children:[o&&p.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),o(e)},type:"button",title:"Edit Component",children:p.jsx(t.Edit,{size:12})}),p.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),a(e,t)},type:"button",title:"Delete Component",children:p.jsx(t.Trash2,{size:12})})]})]})},J=({cell:e,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:a,selectedComponent:o,renderFormComponent:l,formData:c={},formTemplateId:u,onThresholdActionCompletion:h,onThresholdIssueRaised:d,tableId:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y})=>{var C,x,F,Q,U;const E=`table-cell-${f}-${e.row}-${e.column}`,{setNodeRef:S,isOver:N}=r.useDroppable({id:E,disabled:"edit"!==t,data:{type:"table-cell",tableId:f,cell:e,row:e.row,column:e.column}}),L=Object.assign(Object.assign({},e.styles),{backgroundColor:N?"var(--df-color-primary-light)":(null===(C=e.styles)||void 0===C?void 0:C.backgroundColor)||"transparent",minHeight:(null===(x=e.styles)||void 0===x?void 0:x.minHeight)||"preview"===t||"test"===t?"40px":"60px",padding:(null===(F=e.styles)||void 0===F||F.padding,"8px"),border:"preview"===t||"test"===t?"none":N?"2px dashed var(--df-color-primary)":(null===(Q=e.styles)||void 0===Q?void 0:Q.borderColor)?`1px solid ${e.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===t||"test"===t?"0":"4px",position:"relative",verticalAlign:(null===(U=e.styles)||void 0===U?void 0:U.verticalAlign)||"top"});return p.jsx("td",{ref:S,style:L,className:"table-cell "+(N?"drag-over":""),children:p.jsx("div",{className:"cell-content",children:e.components&&Array.isArray(e.components)&&e.components.length>0?"edit"===t?p.jsx(n.SortableContext,{items:e.components.map(e=>e.id||s.v4()),strategy:n.verticalListSortingStrategy,children:e.components.map(e=>{const r=W(e);return p.jsx(Y,{component:r,selectedComponent:o,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:a,renderFormComponent:l},r.id)})}):e.components.map(e=>{const A=e.id?e:W(e);return p.jsx(X,{component:A,mode:t,renderFormComponent:l,formData:c,formTemplateId:u,onThresholdActionCompletion:h,onThresholdIssueRaised:d,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y},A.id)}):"edit"===t?p.jsx("div",{className:"empty-cell-placeholder",children:p.jsxs("div",{className:"cell-info",children:[p.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),p.jsxs("span",{className:"cell-coordinates",children:["Cell (",e.row+1,", ",e.column+1,")"]})]})}):p.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},$=({id:A,properties:r,mode:n="edit",formData:i={},validationErrors:s={},touchedFields:a={},formSubmitted:o=!1,onValueChange:l,onSelect:c,isSelected:u=!1,className:h="",onTableSelect:d,onComponentSelect:f,onComponentDelete:g,onComponentEdit:m,selectedComponent:w,renderFormComponent:v,formTemplateId:b,onThresholdActionCompletion:B,onThresholdIssueRaised:y,onNotesChange:C,onAttachmentChange:x,workOrderNumber:N,assetNumber:_,user:k,onCreateIssue:T,onUpdateIssue:j})=>{var H,P,D,M,R,K,V,G,z,q,X,Y,$,Z,ee,te,Ae,re;const[ne,ie]=e.useState(!1),se=(null===(H=r.cells)||void 0===H?void 0:H.some(e=>e.some(e=>e.components&&e.components.length>0)))||!1;e.useEffect(()=>{},[null===(P=r.table)||void 0===P?void 0:P.rows,null===(D=r.table)||void 0===D?void 0:D.columns,null===(M=r.basic)||void 0===M?void 0:M.rows,null===(R=r.basic)||void 0===R?void 0:R.columns,r.cells,A,l]);const ae=e.useCallback(e=>{e.stopPropagation(),null==c||c(),null==d||d(r)},[c,d,r]),oe=e.useCallback((e,t)=>{t.stopPropagation();const n=r.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}));l&&l({id:A,value:Object.assign(Object.assign({},r),{cells:n})})},[g,r,l,A]),le=e.useMemo(()=>r.cells?r.cells.map((e,t)=>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-${A}-row-${t}-cell-${r}-comp-${n}`;return Object.assign(Object.assign({},e),{id:i})}):[]}))):[],[r.cells,A]),ce=v||e.useCallback(e=>{var t,A,r;const s=e.id?e:W(e),a=i[s.id]||"defaultValue"in s.basic&&s.basic.defaultValue||"";let o=a;"number-input"===s.name&&"number"==typeof a?o=String(a):"number-input"===s.name&&null==a&&(o="");const c={id:s.id,properties:s,validationErrors:{},formValue:o,touchedFields:{},formSubmitted:!1,mode:n,onValueChange:e=>{null==l||l(e)},onBlur:()=>{},onFocus:()=>{}};switch(s.name){case"text-input":case"email-input":case"number-input":return p.jsx(F,Object.assign({},c,{properties:s,inputType:"text-input"===s.name?"text":"number-input"===s.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return p.jsx(Q,Object.assign({},c,{properties:s,readonly:!1,disabled:!1}));case"select":const e=Object.assign(Object.assign({},s),{options:(null===(t=s.basic)||void 0===t?void 0:t.options)||[]});return p.jsx(U,Object.assign({},c,{properties:e,disabled:!1}));case"checkbox":const n=Object.assign(Object.assign({},s),{options:(null===(A=s.basic)||void 0===A?void 0:A.options)||[]});return p.jsx(E,Object.assign({},c,{properties:n,formValue:[],disabled:!1}));case"radio":const i=Object.assign(Object.assign({},s),{options:(null===(r=s.basic)||void 0===r?void 0:r.options)||[]});return p.jsx(S,Object.assign({},c,{properties:i,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},c,{properties:s,readonly:!1,disabled:!1}));case"signature":return p.jsx(I,Object.assign({},c,{properties:s}));case"heading":return p.jsx(O,Object.assign({},c,{properties:s}));default:return p.jsxs("div",{className:"unknown-component",children:["Unknown component: ",s.name]})}},[v,n,i,l]),ue={backgroundColor:(null===(K=r.styles)||void 0===K?void 0:K.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(V=r.styles)||void 0===V?void 0:V.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(G=r.styles)||void 0===G?void 0:G.borderWidth)||"2px",borderRadius:(null===(z=r.styles)||void 0===z?void 0:z.borderRadius)||"8px",padding:(null===(q=r.styles)||void 0===q?void 0:q.padding)||"16px",margin:(null===(X=r.styles)||void 0===X?void 0:X.margin)||"16px 0"},he={width:"100%",minWidth:"600px",borderCollapse:"preview"===n||"test"===n?"separate":"collapse",tableLayout:"fixed",border:"preview"===n||"test"===n?"1px solid var(--df-color-fb-border)":"none"};return se||"preview"!==n?p.jsxs("div",{className:`form-group df-form-table ${u?"selected":""} ${"preview"===n?"preview-mode":"test"===n?"test-mode":""} ${h}`,onClick:ae,style:ue,children:[p.jsx("div",{className:"table-header",children:p.jsx("div",{className:"table-title",onClick:e=>{e.stopPropagation(),ie(!ne),null==l||l({id:A,value:Object.assign(Object.assign({},r),{basic:Object.assign(Object.assign({},r.basic||{}),{collapsed:!ne})})})},children:p.jsxs("div",{className:"title-content",children:[ne?p.jsx(t.ChevronRight,{size:16}):p.jsx(t.ChevronDown,{size:16}),p.jsx(t.Table,{size:16}),p.jsx("span",{className:"table-label",children:(null===(Y=r.basic)||void 0===Y?void 0:Y.label)||"Table"}),(null===($=r.validation)||void 0===$?void 0:$.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]})})}),(null===(Z=r.basic)||void 0===Z?void 0:Z.description)&&!ne&&p.jsx("div",{className:"table-description",children:r.basic.description}),!ne&&p.jsxs("div",{className:"table-content",children:[null,p.jsxs("table",{style:he,children:[(null===(ee=r.table)||void 0===ee?void 0:ee.displayAsTable)&&("edit"===n||(null===(te=r.table)||void 0===te?void 0:te.showColumns))&&p.jsx("thead",{children:p.jsx("tr",{className:"table-header-row",children:Array.from({length:(null===(Ae=r.table)||void 0===Ae?void 0:Ae.columns)||(null===(re=r.basic)||void 0===re?void 0:re.columns)||3},(e,t)=>{var A,n;const i=((null===(n=null===(A=r.table)||void 0===A?void 0:A.columnNames)||void 0===n?void 0:n.split(",").map(e=>e.trim()))||[])[t]||`Column ${t+1}`;return p.jsx("th",{className:"table-header-cell",style:{backgroundColor:(r.styles.headerBackgroundColor,"var(--df-color-fb-container)"),color:r.styles.headerTextColor||"var(--df-color-text-dark)",padding:"12px",border:"1px solid var(--df-color-fb-border)",fontWeight:"600",fontSize:"14px",textAlign:"center"},children:i},`header-${t}`)})})}),p.jsx("tbody",{children:le.map((e,t)=>p.jsx("tr",{className:"table-row",children:e.map(e=>p.jsx(J,{cell:e,mode:n,onComponentSelect:f||(()=>{}),onComponentDelete:oe,onComponentEdit:m,selectedComponent:w||null,renderFormComponent:ce,formData:i,formTemplateId:b,onThresholdActionCompletion:B,onThresholdIssueRaised:y,tableId:A,onNotesChange:C,onAttachmentChange:x,workOrderNumber:N,assetNumber:_,user:k,onCreateIssue:T,onUpdateIssue:j},e.id))},t))})]})]})]}):null};var Z=Object.freeze({__proto__:null,DfFormTable:$,default:$});const ee={page:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',padding:"30px",backgroundColor:"#ffffff",color:"#000000",lineHeight:"1.4"},header:{marginBottom:"30px",paddingBottom:"15px",borderBottom:"2px solid #303992",display:"flex",justifyContent:"space-between",alignItems:"flex-end"},title:{margin:"0 0 5px 0",fontSize:"24px",fontWeight:"bold",color:"#303992"},description:{margin:"0",fontSize:"14px",color:"#666666"},submittedBy:{fontSize:"14px",color:"#333",textAlign:"right",whiteSpace:"nowrap",marginBottom:"2px"},formGroup:{marginBottom:"20px",breakInside:"avoid"},label:{fontWeight:"400",display:"block",marginBottom:"8px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",fontColor:"var(--df-color-text-dark)"},labelLeft:{fontWeight:"400",display:"block",marginRight:"10px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",width:"60%",fontColor:"var(--df-color-text-dark)"},valueContainer:{border:"1px solid #e2e8f0",borderRadius:"6px",padding:"8px 12px",backgroundColor:"#ffffff",minHeight:"20px",fontSize:"14px",flex:1},value:{fontSize:"14px",color:"#000000"},gridRow:{display:"flex",flexWrap:"wrap",gap:"16px",marginBottom:"20px"},gridCol:e=>({flex:`0 0 calc(${e/12*100}% - 8px)`,minWidth:"0"}),img:{maxWidth:"100%",maxHeight:"300px",border:"1px solid #ddd",borderRadius:"4px",display:"block",marginTop:"5px"},table:{width:"100%",borderCollapse:"collapse",border:"1px solid #ddd",marginTop:"10px",tableLayout:"fixed"},th:{border:"1px solid #ddd",padding:"8px",backgroundColor:"#f5f5f5",fontWeight:"bold",textAlign:"left",fontSize:"13px"},td:{border:"1px solid #ddd",padding:"8px",fontSize:"13px",verticalAlign:"top"},section:{marginBottom:"25px",breakInside:"avoid"},sectionHeader:{fontSize:"18px",marginBottom:"15px",display:"block",fontWeight:"600"},sectionChildren:{marginLeft:"20px",paddingLeft:"20px",borderLeft:"2px solid #3b82f6",marginTop:"15px"},notesSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",fontSize:"13px",boxSizing:"border-box"},notesLabel:{fontWeight:"bold",color:"#303992",marginRight:"5px"},attachmentsSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",display:"flex",flexWrap:"wrap",gap:"10px",boxSizing:"border-box"},attachmentThumbnail:{width:"60px",height:"60px",border:"1px solid #e5e7eb",borderRadius:"4px",overflow:"hidden",backgroundColor:"#fff",display:"flex",alignItems:"center",justifyContent:"center"},attachmentImg:{width:"100%",height:"100%",objectFit:"cover"},segmentContainer:{display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center"},segmentButton:{display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",borderRadius:"6px",border:"1px solid #e0e0e0",backgroundColor:"#ffffff",fontSize:"10px",fontWeight:600,minWidth:"30px",color:"#666"},segmentIcon:{marginRight:"4px",fontSize:"9px",fontWeight:"bold",display:"inline-block",lineHeight:"1"},checkboxItem:{display:"flex",alignItems:"center",padding:"10px 14px",backgroundColor:"#f8f9fa",borderRadius:"6px",marginBottom:"8px",width:"100%",boxSizing:"border-box"}},te=e=>{if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.startsWith("data:image")||t.startsWith("iVBORw0KGgo")||t.startsWith("/9j/4AAQ")||t.startsWith("UklGR")||t.startsWith("R0lGOD")},Ae=(e,t)=>{if(!e)return"";const A=e.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}`:t&&t.startsWith("image/")?`data:${t};base64,${A}`:A},re=e=>{if(void 0!==(null==e?void 0:e.icon)&&null!==(null==e?void 0:e.icon))return e.icon;return"pass"===(e=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"})((null==e?void 0:e.value)||e)?"✓":"×"},ne=({component:e})=>{var t,A;const r=(null===(t=e.basic)||void 0===t?void 0:t.notes)||"",n=(null===(A=e.basic)||void 0===A?void 0:A.attachments)||[];return r.trim()||0!==n.length?p.jsxs("div",{style:{marginTop:"5px"},children:[r.trim().length>0&&p.jsxs("div",{style:ee.notesSection,children:[p.jsx("span",{style:ee.notesLabel,children:"Notes:"}),r]}),n.length>0&&p.jsx("div",{style:ee.attachmentsSection,children:n.map((e,t)=>{var A;const r=!(!e.data&&!e.url),n=((null===(A=e.type)||void 0===A?void 0:A.startsWith("image/"))||te(e.data||e.url||""))&&r?Ae(e.data||e.url||"",e.type):null;return p.jsx("div",{style:ee.attachmentThumbnail,children:n?p.jsx("img",{src:n,alt:e.name||"Attachment",style:ee.attachmentImg}):p.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},t)})})]}):null},ie=({component:e})=>{var t,A,r,n,i,s,a;const o=void 0!==(null===(t=e.basic)||void 0===t?void 0:t.value)?e.basic.value:null===(A=e.basic)||void 0===A?void 0:A.defaultValue,{name:l}=e;if("signature"===l)return o&&te(o)?p.jsx("div",{style:{marginTop:"5px"},children:p.jsx("img",{src:Ae(o),alt:"Signature",style:Object.assign(Object.assign({},ee.img),{maxHeight:"100px",width:"auto"})})}):p.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===l){const t=(null===(r=e.basic)||void 0===r?void 0:r.options)||[],A=Array.isArray(o)?o:[o];return p.jsx("div",{style:{marginTop:"5px",width:"100%"},children:t.map((e,t)=>{const r=A.includes(e.value);return p.jsxs("div",{style:ee.checkboxItem,children:[p.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&&p.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),p.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("radio"===l){const t=(null===(n=e.basic)||void 0===n?void 0:n.options)||[];return p.jsx("div",{style:{marginTop:"5px",width:"100%"},children:t.map((e,t)=>{const A=o===e.value;return p.jsxs("div",{style:ee.checkboxItem,children:[p.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&&p.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),p.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("segment"===l){const t=(null===(i=e.basic)||void 0===i?void 0:i.options)||[],A=o;return p.jsx("div",{style:ee.segmentContainer,children:t.map((e,t)=>{const r=A===e.value,n=re(e),i=e.color||"#666";let s=Object.assign({},ee.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}),p.jsxs("div",{style:s,children:[p.jsx("span",{style:ee.segmentIcon,children:n}),p.jsx("span",{children:e.value})]},t)})})}if("file"===l){const e=(Array.isArray(o)?o:o?[o]:[]).filter(e=>{const t=!(!e.data&&!e.url),A=e.type&&e.type.startsWith("image/"),r=t&&te(e.data||e.url);return A||r});return e.length>0?p.jsx("div",{style:{marginTop:"10px"},children:e.map((e,t)=>{const A=Ae(e.data||e.url,e.type);return A?p.jsx("img",{src:A,alt:e.name||"File",style:Object.assign(Object.assign({},ee.img),{marginBottom:"10px"})},t):null})}):p.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===l){if(o&&"object"==typeof o){const e=o;return p.jsxs("div",{style:{fontSize:"14px"},children:[e.placeName&&p.jsxs("div",{style:{marginBottom:"4px"},children:[p.jsx("strong",{children:"Place:"})," ",e.placeName]}),(e.city||e.country)&&p.jsxs("div",{style:{marginBottom:"4px"},children:[p.jsx("strong",{children:"Address:"})," ",[e.city,e.country].filter(Boolean).join(", ")]}),e.latitude&&e.longitude&&p.jsxs("div",{style:{marginBottom:"4px"},children:[p.jsx("strong",{children:"Coordinates:"})," ",e.latitude.toFixed(6),", ",e.longitude.toFixed(6)]}),e.timestamp&&p.jsxs("div",{children:[p.jsx("strong",{children:"Captured:"})," ",(B(e.timestamp)||new Date).toLocaleString()]})]})}return p.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===l){const t=(null===(s=e.basic)||void 0===s?void 0:s.instructions)||[],A=(null===(a=e.validation)||void 0===a?void 0:a.listStyle)||"numbers";if(!Array.isArray(t)||0===t.length)return p.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const r=()=>p.jsx("div",{dangerouslySetInnerHTML:{__html:t.join("")}});return"numbers"===A?p.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:p.jsx(r,{})}):"bullets"===A?p.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:p.jsx(r,{})}):p.jsx("div",{style:{margin:"10px 0"},children:p.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 e="textarea"===l;return p.jsx("div",{style:Object.assign(Object.assign({},ee.valueContainer),e?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}),children:p.jsx("div",{style:ee.value,children:c})})}return p.jsx("div",{style:ee.value,children:c})},se=({component:e})=>{var t,A,r;const{name:n,basic:i,styles:s,validation:a}=e,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 t=null==s?void 0:s.headerBackgroundColor,A=null==s?void 0:s.headerTextColor,r=Object.assign(Object.assign(Object.assign(Object.assign({},ee.sectionHeader),t?{backgroundColor:t,padding:"8px",borderRadius:"4px"}:{}),A?{color:A}:{}),{display:"flex",alignItems:"center"});return p.jsxs("div",{style:ee.section,children:[o&&p.jsx("label",{style:r,children:p.jsxs("span",{style:{flex:1},children:[o,l&&" *"]})}),(null==i?void 0:i.description)&&p.jsx("p",{style:Object.assign(Object.assign({},ee.description),{marginBottom:"15px"}),children:i.description}),p.jsx(ne,{component:e}),p.jsx("div",{style:ee.sectionChildren,children:p.jsx(ae,{components:e.children||[]})})]})}if("heading"===n){const e=`h${Math.max(1,Math.min(6,null!==(A=null!==(t=null==s?void 0:s.level)&&void 0!==t?t: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 p.jsx("div",{style:ee.formGroup,children:p.jsx(e,{style:r,children:(null==i?void 0:i.label)||(null==i?void 0:i.value)})})}if("table"===n){const t=e.cells||[],A=Math.max(0,...t.map(e=>e?e.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({},ee.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{});return p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:a,children:[o,l&&" *"]}),p.jsx("table",{style:ee.table,children:p.jsx("tbody",{children:t.map((e,t)=>p.jsx("tr",{children:e&&e.map((e,t)=>p.jsx("td",{style:Object.assign(Object.assign({},ee.td),{width:`${r}%`}),children:e.components&&e.components.map((e,t)=>{var A;return p.jsxs("div",{style:{marginBottom:"8px"},children:[(null===(A=e.basic)||void 0===A?void 0:A.label)&&p.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[e.basic.label,":"]}),p.jsx(ie,{component:e}),p.jsx(ne,{component:e})]},t)})},t))},t))})})]})}if("datagrid"===n){const t=e.entries||[];let A=e.templateComponents||[];0===A.length&&t.length>0&&(null===(r=t[0])||void 0===r?void 0:r.components)&&(A=t[0].components.map(e=>{var t;return Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{label:(null===(t=e.basic)||void 0===t?void 0:t.label)||e.name})})}));const n=null==s?void 0:s.headerBackgroundColor,i=null==s?void 0:s.headerTextColor,a=Object.assign(Object.assign(Object.assign({},ee.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{}),c=t.filter(e=>!(!e.components||0===e.components.length)&&e.components.some(e=>{var t,A;const r=void 0!==(null===(t=e.basic)||void 0===t?void 0:t.value)?e.basic.value:null===(A=e.basic)||void 0===A?void 0:A.defaultValue;return Array.isArray(r)?r.length>0:null!=r&&""!==String(r).trim()}));return 0===c.length?p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:a,children:[o,l&&" *"]}),p.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:a,children:[o,l&&" *"]}),p.jsxs("table",{style:ee.table,children:[p.jsx("thead",{children:p.jsx("tr",{children:A.map((e,t)=>{var A;return p.jsx("th",{style:ee.th,children:(null===(A=e.basic)||void 0===A?void 0:A.label)||e.name},t)})})}),p.jsx("tbody",{children:c.map((e,t)=>p.jsx("tr",{children:A.map((t,A)=>{const r=e.components[A];return p.jsx("td",{style:ee.td,children:r?p.jsxs(p.Fragment,{children:[p.jsx(ie,{component:r}),p.jsx(ne,{component:r})]}):"N/A"},A)})},t))})]})]})}if(c&&"instructions"!==n){const t=["segment"].includes(n);return p.jsxs("div",{style:ee.formGroup,children:[p.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[o&&p.jsxs("label",{style:ee.labelLeft,children:[o,l&&" *"]}),p.jsx("div",{style:Object.assign({flex:1},t?{display:"flex",justifyContent:"flex-end"}:{}),children:p.jsx(ie,{component:e})})]}),p.jsx(ne,{component:e})]})}return p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:ee.label,children:[o,l&&" *"]}),p.jsx(ie,{component:e}),p.jsx(ne,{component:e})]})},ae=({components:e})=>{if(!e||0===e.length)return null;const t=[];let A=[],r=0;return e.forEach(e=>{var n;const i=["section","table","datagrid","heading","instructions"].includes(e.name),s=i?12:(null===(n=e.styles)||void 0===n?void 0:n.column)||12;r+s>12&&A.length>0&&(t.push(A),A=[],r=0),A.push(e),r+=s,(i||r>=12)&&r>0&&(t.push(A),A=[],r=0)}),A.length>0&&t.push(A),p.jsx(p.Fragment,{children:t.map((e,t)=>1===e.length?p.jsx(se,{component:e[0]},e[0].id||t):p.jsx("div",{style:ee.gridRow,children:e.map((e,t)=>{var A;const r=(null===(A=e.styles)||void 0===A?void 0:A.column)||12;return p.jsx("div",{style:ee.gridCol(r),children:p.jsx(se,{component:e})},e.id||t)})},t))})},oe=({formTitle:e,formDescription:t,userName:A,components:r})=>p.jsxs("div",{className:"pdf-container",style:ee.page,children:[p.jsxs("div",{style:ee.header,children:[p.jsxs("div",{children:[p.jsx("h1",{style:ee.title,children:e}),t&&p.jsx("p",{style:ee.description,children:t})]}),A&&p.jsxs("div",{style:ee.submittedBy,children:[p.jsx("strong",{children:"Submitted By:"})," ",A]})]}),p.jsx("div",{className:"form-content",children:p.jsx(ae,{components:r})})]});var le,ce=A;if("production"===process.env.NODE_ENV)le=ce.createRoot,ce.hydrateRoot;else{var ue=ce.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;le=function(e,t){ue.usingClientEntryPoint=!0;try{return ce.createRoot(e,t)}finally{ue.usingClientEntryPoint=!1}}}var he={exports:{}};
10
+ */"production"===process.env.NODE_ENV?u.exports=function(){if(c)return h;c=1;var t=e,A=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,r){var a,o={},l=null,c=null;for(a in void 0!==r&&(l=""+r),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(c=t.ref),t)n.call(t,a)&&!s.hasOwnProperty(a)&&(o[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===o[a]&&(o[a]=t[a]);return{$$typeof:A,type:e,key:l,ref:c,props:o,_owner:i.current}}return h.Fragment=r,h.jsx=a,h.jsxs=a,h}():u.exports=(d||(d=1,"production"!==process.env.NODE_ENV&&function(){var t,A=e,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"),p=Symbol.for("react.lazy"),g=Symbol.for("react.offscreen"),m=Symbol.iterator,w=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(e){for(var t=arguments.length,A=new Array(t>1?t-1:0),r=1;r<t;r++)A[r-1]=arguments[r];!function(e,t,A){var r=w.ReactDebugCurrentFrame.getStackAddendum();""!==r&&(t+="%s",A=A.concat([r]));var n=A.map(function(e){return String(e)});n.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,n)}("error",e,A)}function b(e){return e.displayName||"Context"}function B(e){if(null==e)return null;if("number"==typeof e.tag&&v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case 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 e)switch(e.$$typeof){case l:return b(e)+".Consumer";case o:return b(e._context)+".Provider";case c:return function(e,t,A){var r=e.displayName;if(r)return r;var n=t.displayName||t.name||"";return""!==n?A+"("+n+")":A}(e,e.render,"ForwardRef");case d:var t=e.displayName||null;return null!==t?t:B(e.type)||"Memo";case p:var A=e,r=A._payload,f=A._init;try{return B(f(r))}catch(e){return null}}return null}t=Symbol.for("react.module.reference");var y,C,x,F,Q,U,E,S=Object.assign,N=0;function L(){}L.__reactDisabledLog=!0;var I,_=w.ReactCurrentDispatcher;function k(e,t,A){if(void 0===I)try{throw Error()}catch(e){var r=e.stack.trim().match(/\n( *(at )?)/);I=r&&r[1]||""}return"\n"+I+e}var O,T=!1,j="function"==typeof WeakMap?WeakMap:Map;function H(e,t){if(!e||T)return"";var A,r=O.get(e);if(void 0!==r)return r;T=!0;var n,i=Error.prepareStackTrace;Error.prepareStackTrace=void 0,n=_.current,_.current=null,function(){if(0===N){y=console.log,C=console.info,x=console.warn,F=console.error,Q=console.group,U=console.groupCollapsed,E=console.groupEnd;var e={configurable:!0,enumerable:!0,value:L,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}N++}();try{if(t){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(e){A=e}Reflect.construct(e,[],s)}else{try{s.call()}catch(e){A=e}e.call(s.prototype)}}else{try{throw Error()}catch(e){A=e}e()}}catch(t){if(t&&A&&"string"==typeof t.stack){for(var a=t.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 e.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",e.displayName)),"function"==typeof e&&O.set(e,u),u}}while(l>=1&&c>=0);break}}}finally{T=!1,_.current=n,function(){if(0===--N){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:S({},e,{value:y}),info:S({},e,{value:C}),warn:S({},e,{value:x}),error:S({},e,{value:F}),group:S({},e,{value:Q}),groupCollapsed:S({},e,{value:U}),groupEnd:S({},e,{value:E})})}N<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=i}var h=e?e.displayName||e.name:"",d=h?k(h):"";return"function"==typeof e&&O.set(e,d),d}function P(e,t,A){if(null==e)return"";if("function"==typeof e)return H(e,!(!(r=e.prototype)||!r.isReactComponent));var r;if("string"==typeof e)return k(e);switch(e){case u:return k("Suspense");case h:return k("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case c:return H(e.render,!1);case d:return P(e.type,t,A);case p:var n=e,i=n._payload,s=n._init;try{return P(s(i),t,A)}catch(e){}}return""}O=new j;var D=Object.prototype.hasOwnProperty,M={},R=w.ReactDebugCurrentFrame;function K(e){if(e){var t=e._owner,A=P(e.type,e._source,t?t.type:null);R.setExtraStackFrame(A)}else R.setExtraStackFrame(null)}var V=Array.isArray;function G(e){return V(e)}function z(e){return""+e}function q(e){if(function(e){try{return z(e),!1}catch(e){return!0}}(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),z(e)}var W,X,Y,J=w.ReactCurrentOwner,$={key:!0,ref:!0,__self:!0,__source:!0};function Z(e,t,A,n,i){var s,a={},o=null,l=null;for(s in void 0!==A&&(q(A),o=""+A),function(e){if(D.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(q(t.key),o=""+t.key),function(e){if(D.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(l=t.ref,function(e,t){if("string"==typeof e.ref&&J.current&&t&&J.current.stateNode!==t){var A=B(J.current.type);Y[A]||(v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',B(J.current.type),e.ref),Y[A]=!0)}}(t,i)),t)D.call(t,s)&&!$.hasOwnProperty(s)&&(a[s]=t[s]);if(e&&e.defaultProps){var c=e.defaultProps;for(s in c)void 0===a[s]&&(a[s]=c[s])}if(o||l){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;o&&function(e,t){var A=function(){W||(W=!0,v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};A.isReactWarning=!0,Object.defineProperty(e,"key",{get:A,configurable:!0})}(a,u),l&&function(e,t){var A=function(){X||(X=!0,v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};A.isReactWarning=!0,Object.defineProperty(e,"ref",{get:A,configurable:!0})}(a,u)}return function(e,t,A,n,i,s,a){var o={$$typeof:r,type:e,key:t,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}(e,o,l,i,n,J.current,a)}Y={};var ee,te=w.ReactCurrentOwner,Ae=w.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,A=P(e.type,e._source,t?t.type:null);Ae.setExtraStackFrame(A)}else Ae.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===r}function ie(){if(te.current){var e=B(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var se={};function ae(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var A=function(e){var t=ie();if(!t){var A="string"==typeof e?e:e.displayName||e.name;A&&(t="\n\nCheck the top-level render call using <"+A+">.")}return t}(t);if(!se[A]){se[A]=!0;var r="";e&&e._owner&&e._owner!==te.current&&(r=" It was passed a child from "+B(e._owner.type)+"."),re(e),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',A,r),re(null)}}}function oe(e,t){if("object"==typeof e)if(G(e))for(var A=0;A<e.length;A++){var r=e[A];ne(r)&&ae(r,t)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var n=function(e){if(null===e||"object"!=typeof e)return null;var t=m&&e[m]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof n&&n!==e.entries)for(var i,s=n.call(e);!(i=s.next()).done;)ne(i.value)&&ae(i.value,t)}}function le(e){var t,A=e.type;if(null!=A&&"string"!=typeof A){if("function"==typeof A)t=A.propTypes;else{if("object"!=typeof A||A.$$typeof!==c&&A.$$typeof!==d)return;t=A.propTypes}if(t){var r=B(A);!function(e,t,A,r,n){var i=Function.call.bind(D);for(var s in e)if(i(e,s)){var a=void 0;try{if("function"!=typeof e[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 e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw o.name="Invariant Violation",o}a=e[s](t,s,r,A,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){a=e}!a||a instanceof Error||(K(n),v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",r||"React class",A,s,typeof a),K(null)),a instanceof Error&&!(a.message in M)&&(M[a.message]=!0,K(n),v("Failed %s type: %s",A,a.message),K(null))}}(t,e.props,"prop",r,e)}else void 0===A.PropTypes||ee||(ee=!0,v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",B(A)||"Unknown"));"function"!=typeof A.getDefaultProps||A.getDefaultProps.isReactClassApproved||v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ce={};function ue(e,A,n,f,m,w){var b=function(e){return"string"==typeof e||"function"==typeof e||e===i||e===a||e===s||e===u||e===h||e===g||"object"==typeof e&&null!==e&&(e.$$typeof===p||e.$$typeof===d||e.$$typeof===o||e.$$typeof===l||e.$$typeof===c||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!b){var y="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).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(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(m);y+=x||ie(),null===e?C="null":G(e)?C="array":void 0!==e&&e.$$typeof===r?(C="<"+(B(e.type)||"Unknown")+" />",y=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,y)}var F=Z(e,A,n,m,w);if(null==F)return F;if(b){var Q=A.children;if(void 0!==Q)if(f)if(G(Q)){for(var U=0;U<Q.length;U++)oe(Q[U],e);Object.freeze&&Object.freeze(Q)}else v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else oe(Q,e)}if(D.call(A,"key")){var E=B(e),S=Object.keys(A).filter(function(e){return"key"!==e}),N=S.length>0?"{key: someKey, "+S.join(": ..., ")+": ...}":"{key: someKey}";ce[E+N]||(v('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',N,E,S.length>0?"{"+S.join(": ..., ")+": ...}":"{}",E),ce[E+N]=!0)}return e===i?function(e){for(var t=Object.keys(e.props),A=0;A<t.length;A++){var r=t[A];if("children"!==r&&"key"!==r){re(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",r),re(null);break}}null!==e.ref&&(re(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(F):le(F),F}var he=function(e,t,A){return ue(e,t,A,!1)},de=function(e,t,A){return ue(e,t,A,!0)};f.Fragment=i,f.jsx=he,f.jsxs=de}()),f);var p=u.exports;class g{constructor(){}static getInstance(){return g.instance||(g.instance=new g),g.instance}getAvailableComponentsForConditional(e,t){if(!e||!Array.isArray(e))return[];const A=e.filter(e=>!t||e.id!==t).map(e=>{var t;return{id:e.id,label:(null===(t=e.basic)||void 0===t?void 0:t.label)||e.id,type:e.name,key:e.id}}).sort((e,t)=>e.label.localeCompare(t.label));return A}getApplicableOperators(e){switch(e){case"text-input":case"email-input":case"textarea":return["equals","notEquals","contains","notContains","isEmpty","isNotEmpty"];case"number-input":case"date-picker":case"datetime-picker":return["equals","notEquals","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual","isEmpty","isNotEmpty"];case"select":case"radio":case"segment":default:return["equals","notEquals","isEmpty","isNotEmpty"];case"checkbox":return["contains","notContains","isEmpty","isNotEmpty"]}}validateConditionalLogic(e,t){const A=[];return e?(["show","hide","always"].includes(e.action)||A.push("Invalid conditional action"),["all","any"].includes(e.when)||A.push("Invalid when condition"),e.conditions&&0!==e.conditions.length?e.conditions.forEach((e,r)=>{const n=t.find(t=>t.id===e.when);if(!n)return void A.push(`Condition ${r+1}: Component not found`);this.getApplicableOperators(n.name).includes(e.operator)||A.push(`Condition ${r+1}: Operator not applicable for component type`),this.isValidConditionValue(e.value,n.name,e.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(e,t,A){if("always"===e.action)return{shouldShow:!0,evaluatedConditions:[]};if(!e||!e.conditions||0===e.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const r=e.conditions.map(e=>{const r=this.getComponentValue(e.when,t,A);return{condition:e,result:this.evaluateCondition(e,r),componentValue:r}});return{shouldShow:this.determineFinalResult(e,r),evaluatedConditions:r}}getComponentValue(e,t,A){if(A&&void 0!==A[e])return A[e];const r=t.find(t=>t.id===e);return r&&"defaultValue"in r.basic?r.basic.defaultValue:void 0}evaluateCondition(e,t){const{operator:A,value:r}=e;if("checked"===r||"notChecked"===r)return this.evaluateCheckboxCondition(t,r);switch(A){case"equals":return this.isEqual(t,r);case"notEquals":return!this.isEqual(t,r);case"isEmpty":return this.isEmpty(t);case"isNotEmpty":return!this.isEmpty(t);case"contains":return this.contains(t,r);case"notContains":return!this.contains(t,r);case"greaterThan":return this.isGreaterThan(t,r);case"lessThan":return this.isLessThan(t,r);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(t,r);case"lessThanOrEqual":return this.isLessThanOrEqual(t,r);default:return!1}}evaluateCheckboxCondition(e,t){const A=this.isCheckboxChecked(e);return"checked"===t?A:"notChecked"===t&&!A}isCheckboxChecked(e){return null!=e&&("boolean"==typeof e?e:"string"==typeof e?"true"===e.toLowerCase()||"1"===e:Array.isArray(e)?e.length>0:"number"==typeof e&&e>0)}determineFinalResult(e,t){let A,r;return A="all"===e.when?t.every(e=>e.result):"any"===e.when&&t.some(e=>e.result),r="show"===e.action?A:"hide"===e.action?!A:(e.action,!0),r}isEqual(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,A)=>this.isEqual(e,t[A]));if("object"==typeof e&&"object"==typeof t){const A=Object.keys(e),r=Object.keys(t);return A.length===r.length&&A.every(A=>this.isEqual(e[A],t[A]))}return!1}isEmpty(e){return null==e||void 0===e||("string"==typeof e?""===e.trim():Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}contains(e,t){return null!=e&&null!=t&&("string"==typeof e?e.toLowerCase().includes(String(t).toLowerCase()):!!Array.isArray(e)&&e.some(e=>this.isEqual(e,t)))}isGreaterThan(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A>r}isLessThan(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A<r}isGreaterThanOrEqual(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A>=r}isLessThanOrEqual(e,t){const A=Number(e),r=Number(t);return!isNaN(A)&&!isNaN(r)&&A<=r}isValidConditionValue(e,t,A){if(null==e)return["isEmpty","isNotEmpty"].includes(A);switch(t){case"number-input":return!isNaN(Number(e))||["isEmpty","isNotEmpty"].includes(A);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(e))||["isEmpty","isNotEmpty"].includes(A);case"checkbox":return Array.isArray(e)||"string"==typeof e||"number"==typeof e;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(e){return{equals:"Is Equal To",notEquals:"Is Not Equal To",contains:"Contains",notContains:"Does Not Contain",isEmpty:"Is Empty",isNotEmpty:"Is Not Empty",greaterThan:"Is Greater Than",lessThan:"Is Less Than",greaterThanOrEqual:"Is Greater Than Or Equal To",lessThanOrEqual:"Is Less Than Or Equal To"}[e]||e}getActionDisplayText(e){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[e]||e}getConditionalLogicSummary(e,t){if(!e||0===e.conditions.length)return"No conditions";if("always"===e.action)return"Always show";const A=this.getActionDisplayText(e.action),r=e.conditions.map(e=>{const A=t.find(t=>t.id===e.when);return`${(null==A?void 0:A.basic.label)||"Unknown component"} ${this.getOperatorDisplayText(e.operator)} ${this.formatConditionValue(e.value)}`}),n="all"===e.when?" and ":" or ";return`${A} ${r.join(n)}`}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const m=g.getInstance();const w=new class{constructor(){this.toasts=[],this.listeners=[],this.defaultDuration=3e3,this.timeouts={}}generateId(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}notifyListeners(){this.listeners.forEach(e=>e([...this.toasts]))}addToast(e){try{this.toasts.push(e),this.notifyListeners(),this.timeouts[e.id]=setTimeout(()=>{this.removeToast(e.id)},e.duration||this.defaultDuration)}catch(e){console.error("Error displaying toast message:",e)}}removeToast(e){this.timeouts[e]&&(clearTimeout(this.timeouts[e]),delete this.timeouts[e]),this.toasts=this.toasts.filter(t=>t.id!==e),this.notifyListeners()}showSuccess(e,t=3e3){const A={id:this.generateId(),message:e,type:"success",duration:t};this.addToast(A)}showError(e,t=5e3){const A={id:this.generateId(),message:e,type:"danger",duration:t};this.addToast(A)}showWarning(e,t){const A={id:this.generateId(),message:e,type:"warning",duration:t};this.addToast(A)}showInfo(e,t){const A={id:this.generateId(),message:e,type:"info",duration:t};this.addToast(A)}show(e,t="success",A){const r={id:this.generateId(),message:e,type:t,duration:A};this.addToast(r)}clearAll(){Object.values(this.timeouts).forEach(e=>clearTimeout(e)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}getToasts(){return[...this.toasts]}},v=({validationErrors:e,fieldId:t,touchedFields:A,formSubmitted:r,properties:n,localValidation:i,isTouched:s,mode:a})=>{const o=e=>{var t,A;const r=n.basic.label||"This field",i=n.name||"",s=null===(t=n.validation)||void 0===t?void 0:t.customValidationMessage;if("number-input"===i)switch(e){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(e){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 e=n.validation;return`You are under the limit. ${r} must be at least ${null==e?void 0:e.lowerLimit}`;case"upperLimit":const t=n.validation;return`You crossed the limit. ${r} must be no more than ${null==t?void 0:t.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[t]||r))return"";if(i&&i.isValid)return"";if(i&&!i.isValid&&Object.keys(i.errors).length>0){const e=Object.keys(i.errors).filter(e=>!0===i.errors[e]);if(e.length>0){const t=e[0],A=n.name||"";return"pattern"===t&&"number-input"===A?"":o(t)}}const c=e[t];if(c&&"string"==typeof c&&""!==c.trim()){const e=n.name||"";if("number-input"===e&&i){const e=n.validation,t=e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit,A=e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||t||A?(i.isValid,""):""}if(("date-picker"===e||"datetime-picker"===e)&&c.includes("valid date")){const t=(null===(l=n.basic)||void 0===l?void 0:l.dateTimeMode)||("datetime-picker"===e?"datetime":"date");if("time"===t)return"Please select a valid time";if("datetime"===t)return"Please select a valid date and time"}return c}return""})();return l?p.jsx("div",{className:"form-error-msg",children:l}):null};function b(e,t,A,r){return new(A||(A=Promise))(function(n,i){function s(e){try{o(r.next(e))}catch(e){i(e)}}function a(e){try{o(r.throw(e))}catch(e){i(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof A?t:new A(function(e){e(t)})).then(s,a)}o((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const B=e=>{if(null==e||""===e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;if("number"==typeof e){const t=new Date(e);return isNaN(t.getTime())?null:t}if("string"==typeof e){let t=e.trim();t.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)&&(t=t.replace(" ","T"));const A=new Date(t);return isNaN(A.getTime())?null:A}return null};var y;!function(e){e.OPEN="Open",e.IN_PROGRESS="In-Progress",e.REJECTED="Rejected",e.RESOLVE="Resolve"}(y||(y={}));const C=({isOpen:r,onClose:n,onSuccess:i,component:s,formTemplateId:a,notes:o="",attachments:l=null,issue:c=null,onCreateIssue:u,onUpdateIssue:h,user:d,availableUsers:f=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:g,assetNumber:m,isStandalone:v,isEdit:C})=>{var x,F,Q,U,E,S;const[N,L]=e.useState(""),[I,_]=e.useState(""),[k,O]=e.useState(""),[T,j]=e.useState(""),[H,P]=e.useState("Medium"),[D,M]=e.useState(y.OPEN),[R,K]=e.useState(""),[V,G]=e.useState(""),[z,q]=e.useState(!1),[W,X]=e.useState(l||[]),[Y,J]=e.useState(!1),$=e.useRef(null),Z=void 0!==C?C:!!c;e.useEffect(()=>{(null==c?void 0:c.attachments)&&c.attachments.length>0?X(c.attachments):l&&X(l)},[l,c]);const ee=e=>{if(!e)return"Attachment";if(e instanceof File)return e.name;if("string"==typeof e){if(e.startsWith("data:"))return"Attachment";const t=e.split("/");return t[t.length-1]||"Attachment"}return e.fileName||e.filename||e.name||"Attachment"},te=e=>{if(!e)return null;const t=e=>/\.(jpg|jpeg|png|gif|webp)$/i.test(e),A=e=>e.startsWith("data:image");return e instanceof File?e.type.startsWith("image/")?URL.createObjectURL(e):null:"string"==typeof e?A(e)||t(e)?e:null:e.data&&A(e.data)||e.fileName&&t(e.fileName)&&e.data?e.data:null};e.useEffect(()=>{var e;if(r)if(c||Z){L((null==c?void 0:c.title)||""),_((null==c?void 0:c.description)||""),O((null==c?void 0:c.workOrderNumber)||g||""),j((null==c?void 0:c.assetNumber)||m||""),P((null==c?void 0:c.priority)||"Medium");const e=(null==c?void 0:c.status)||y.OPEN,t=e===y.OPEN||e===y.IN_PROGRESS||e===y.REJECTED||e===y.RESOLVE?e:y.OPEN;M(t),K((null==c?void 0:c.assignTo)||(null==c?void 0:c.assignee)||""),G((null==c?void 0:c.comments)||"")}else s&&(null===(e=s.basic)||void 0===e||e.label,L(""),_(""),G(o||""),g&&O(g),m&&j(m))},[r,s,o,c,g,m]);const Ae=e.useMemo(()=>{if(!N.trim())return!1;if(!I.trim())return!1;if(!D)return!1;if(!R)return!1;if(!v){if(!k.trim())return!1;if(!T.trim())return!1}return!0},[N,I,D,R,v,k,T]),re=e=>b(void 0,void 0,void 0,function*(){var t;if(c){q(!0);try{const t={title:String(N||"").trim(),description:String(I||"").trim(),workOrderNumber:String(k||"").trim()||void 0,assetNumber:String(T||"").trim()||void 0,formTemplateId:c.formTemplateId||"",component:c.component||{},priority:H,assignee:String(R||"").trim()||void 0,status:e,comments:String(V||"").trim()||""};h&&c._id&&(yield h(c._id,t)),M(e);const A={[y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[y.RESOLVE]:"Issue resolved successfully",[y.REJECTED]:"Issue rejected"};w.showSuccess(A[e]||"Issue status updated successfully"),i&&i(),n()}catch(e){const A=(null==e?void 0:e.message)||(null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.message)||"Failed to update issue status. Please try again.";w.showError(A)}finally{q(!1)}}});if(!r)return null;const ne=p.jsx("div",{className:"raise-issue-modal-overlay",onClick:n,children:p.jsxs("div",{className:"raise-issue-modal",onClick:e=>e.stopPropagation(),children:[p.jsxs("div",{className:"raise-issue-modal-header",children:[p.jsxs("div",{className:"raise-issue-modal-header-left",children:[p.jsx(t.AlertTriangle,{className:"raise-issue-modal-icon",size:20}),p.jsx("div",{className:"raise-issue-modal-header-text",children:p.jsx("div",{className:"raise-issue-modal-title-main",children:Z?"Edit Issue":"Create Issue"})})]}),p.jsx("button",{className:"raise-issue-modal-close",onClick:n,"aria-label":"Close",children:p.jsx(t.X,{size:18})})]}),p.jsx("div",{className:"raise-issue-modal-content",children:p.jsxs("div",{className:"raise-issue-fields-grid",children:[Z&&(null==c?void 0:c.issueNumber)&&p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),p.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:c.issueNumber,readOnly:!0})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Task"}),p.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:Z?(null===(F=null===(x=null==c?void 0:c.component)||void 0===x?void 0:x.basic)||void 0===F?void 0:F.label)||"":(null===(Q=null==s?void 0:s.basic)||void 0===Q?void 0:Q.label)||"",readOnly:!0})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Task Value"}),p.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:Z?(null===(E=null===(U=null==c?void 0:c.component)||void 0===U?void 0:U.basic)||void 0===E?void 0:E.value)||"":(null===(S=null==s?void 0:s.basic)||void 0===S?void 0:S.value)||"",readOnly:!0})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Title ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("input",{type:"text",className:"raise-issue-field-input "+(Z?"raise-issue-field-readonly":""),value:N,onChange:e=>L(e.target.value),placeholder:"Enter issue title",readOnly:Z})]}),!v&&p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("input",{type:"text",className:"raise-issue-field-input "+(Z?"raise-issue-field-readonly":""),value:k,onChange:e=>O(e.target.value),placeholder:"N/A",readOnly:Z})]}),!v&&p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("input",{type:"text",className:"raise-issue-field-input "+(Z?"raise-issue-field-readonly":""),value:T,onChange:e=>j(e.target.value),placeholder:"Enter asset number",readOnly:Z})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Raised By ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[p.jsx(t.User,{size:16}),p.jsx("span",{children:d&&`${d.firstName||""} ${d.lastName||""}`.trim()||"User"})]})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),p.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[p.jsx(t.Calendar,{size:16}),p.jsx("span",{children:Z&&(null==c?void 0:c.createdAt)?(B(c.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})})]})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Description ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsx("textarea",{className:"raise-issue-field-textarea "+(Z?"raise-issue-field-readonly":""),value:I,onChange:e=>_(e.target.value),placeholder:"Enter issue description",rows:4,readOnly:Z})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Status ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("select",{className:"raise-issue-field-select "+(Z?"":"raise-issue-field-readonly"),value:D,onChange:e=>M(e.target.value),disabled:!Z,children:[p.jsx("option",{value:y.OPEN,children:y.OPEN}),p.jsx("option",{value:y.IN_PROGRESS,children:y.IN_PROGRESS}),p.jsx("option",{value:y.REJECTED,children:y.REJECTED}),p.jsx("option",{value:y.RESOLVE,children:y.RESOLVE})]})]}),p.jsxs("div",{className:"raise-issue-field",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Assign to ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("select",{className:"raise-issue-field-select",value:R,onChange:e=>K(e.target.value),children:[p.jsx("option",{value:"",children:"Unassigned"}),f.map(e=>p.jsx("option",{value:e,children:e},e))]})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[p.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",p.jsx("span",{className:"raise-issue-required",children:"*"})]}),p.jsxs("div",{className:"raise-issue-priority-buttons",children:[p.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===H?"active":""),onClick:()=>P("Low"),children:"Low"}),p.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===H?"active":""),onClick:()=>P("Medium"),children:"Medium"}),p.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===H?"active":""),onClick:()=>P("High"),children:"High"})]})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[p.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[p.jsx(t.MessageSquare,{size:16}),p.jsx("span",{children:"Comments"})]}),!V&&p.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),p.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(Z?"raise-issue-field-readonly":""),value:V,onChange:e=>G(e.target.value),placeholder:"Add a comment...",rows:4,readOnly:Z})]}),p.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",style:{marginTop:"1rem"},children:[p.jsx("label",{className:"raise-issue-field-label",children:"Attachments"}),p.jsxs("div",{className:"raise-issue-attachments-container",children:[!Z&&p.jsxs("div",{className:"raise-issue-dropzone "+(Y?"dragging":""),onDragOver:e=>{e.preventDefault(),J(!0)},onDragLeave:e=>{e.preventDefault(),J(!1)},onDrop:e=>{if(e.preventDefault(),J(!1),e.dataTransfer.files&&e.dataTransfer.files.length>0){const t=Array.from(e.dataTransfer.files);X(e=>[...e,...t])}},onClick:()=>{var e;return null===(e=$.current)||void 0===e?void 0:e.click()},children:[p.jsx("input",{type:"file",ref:$,style:{display:"none"},onChange:e=>{if(e.target.files&&e.target.files.length>0){const t=Array.from(e.target.files);X(e=>[...e,...t]),$.current&&($.current.value="")}},multiple:!0}),p.jsx("div",{className:"raise-issue-dropzone-icon",children:p.jsx(t.UploadCloud,{size:24})}),p.jsx("div",{className:"raise-issue-dropzone-text",children:"Click to upload or drag and drop"}),p.jsx("div",{className:"raise-issue-dropzone-hint",children:"PNG, JPG up to 10MB"})]}),W.length>0&&p.jsx("div",{className:"raise-issue-attachments-list",children:W.map((e,A)=>p.jsxs("div",{className:"raise-issue-attachment-item",children:[p.jsx("div",{className:"raise-issue-attachment-thumbnail",children:te(e)?p.jsx("img",{src:te(e),alt:"Thumbnail"}):p.jsx(t.Paperclip,{size:20,color:"#9ca3af"})}),p.jsxs("div",{className:"raise-issue-attachment-info",children:[p.jsx("span",{className:"attachment-name",title:ee(e),children:ee(e)}),e instanceof File&&p.jsxs("span",{className:"attachment-size",children:[(e.size/1024).toFixed(1)," KB"]})]}),!Z&&p.jsx("button",{type:"button",className:"attachment-remove-btn",onClick:()=>(e=>{X(t=>t.filter((t,A)=>A!==e))})(A),title:"Remove",children:p.jsx(t.X,{size:12})})]},A))})]})]})]})}),p.jsx("div",{className:"raise-issue-modal-actions",children:p.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[Z&&c&&p.jsxs(p.Fragment,{children:[D===y.OPEN&&p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:()=>b(void 0,void 0,void 0,function*(){yield re(y.IN_PROGRESS)}),disabled:z,children:z?"Processing...":"Accept"}),D===y.IN_PROGRESS&&p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:()=>b(void 0,void 0,void 0,function*(){yield re(y.RESOLVE)}),disabled:z,children:z?"Processing...":"Resolve"}),(D===y.OPEN||D===y.IN_PROGRESS)&&p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:()=>b(void 0,void 0,void 0,function*(){yield re(y.REJECTED)}),disabled:z,children:z?"Processing...":"Reject"})]}),p.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save "+(Ae?"":"disabled"),onClick:()=>b(void 0,void 0,void 0,function*(){var e,t,A,r,l,f,p;if(String(N||"").trim())if(String(I||"").trim())if(v||String(k||"").trim())if(v||String(T||"").trim())if(String(R||"").trim()){q(!0);try{if(Z&&c){const s={title:String(N||"").trim(),description:String(I||"").trim(),workOrderNumber:String(k||"").trim()||void 0,assetNumber:String(T||"").trim()||void 0,formTemplateId:c.formTemplateId||"",component:c.component||{},priority:H,assignTo:String(R||"").trim()||void 0,status:D,comments:String(V||"").trim()||"",task:(null===(t=null===(e=c.component)||void 0===e?void 0:e.basic)||void 0===t?void 0:t.label)||"",taskValue:(null===(r=null===(A=c.component)||void 0===A?void 0:A.basic)||void 0===r?void 0:r.value)||""};h&&c._id&&(yield h(c._id,s)),w.showSuccess("Issue updated successfully"),i&&i(),n()}else{if(!s)return w.showError("Component is required"),void q(!1);if(!a||""===String(a||"").trim())return w.showError("Form template is required"),void q(!1);const e=Object.assign(Object.assign({},s),{basic:Object.assign(Object.assign({},s.basic),{comments:String(o||"")})}),t=d?`${d.firstName||""} ${d.lastName||""}`.trim():"User",A={title:String(N||"").trim(),workOrderNumber:String(k||"").trim()||void 0,assetNumber:String(T||"").trim()||void 0,component:e,description:String(I||"").trim(),formTemplateId:a,assignTo:String(R||"").trim()||void 0,priority:H,status:D,comments:String(V||"").trim()||"",createdBy:t,task:(null===(l=null==s?void 0:s.basic)||void 0===l?void 0:l.label)||"",taskValue:(null===(f=null==s?void 0:s.basic)||void 0===f?void 0:f.value)||""};let r;if(u&&(r=yield u(A,W)),w.showSuccess("Issue raised successfully"),i){const e=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)||W},r);i(e)}n()}}catch(e){const t=(null==e?void 0:e.message)||(null===(p=null==e?void 0:e.error)||void 0===p?void 0:p.message)||(Z?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");w.showError(t)}finally{q(!1)}}else w.showError("Assignee is required");else w.showError("Asset Number is required");else w.showError("Work Order is required");else w.showError("Description is required");else w.showError("Title is required")}),disabled:z||!Ae,children:z?Z?"Saving...":"Creating...":Z?"Save Changes":"Create Issue"})]})})]})});return A.createPortal(ne,document.body)},x=({component:A,condition:r,currentValue:n,thresholdValue:i,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,onIssueRaised:c,isIssueRaised:u=!1,compact:h=!1})=>{const[d,f]=e.useState(!1),[g,m]=e.useState(null),[v,B]=e.useState(!1),[y,x]=e.useState(!1);e.useEffect(()=>{u&&x(!0)},[u]),e.useEffect(()=>{x(!1)},[null==r?void 0:r.id]);const F=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),Q=e.useCallback(()=>b(void 0,void 0,void 0,function*(){if(u||y){if(g)return void f(!0);B(!0);try{m(null),f(!0)}catch(e){console.error("Error fetching issue:",e),w.showError("Failed to load issue details")}finally{B(!1)}}else m(null),f(!0)}),[u,y,s,A,g]),U=e.useCallback(()=>{f(!1),u||y||m(null)},[u,y]),E=e.useCallback(e=>{f(!1),m(e||null),x(!0),c&&(null==r?void 0:r.id)&&c(r.id)},[c,r]);return u||y?p.jsx(p.Fragment,{children:d&&p.jsx(C,{isOpen:d,onClose:U,onSuccess:E,component:A,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,notes:"",attachments:null,issue:g})}):h?p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[p.jsx("div",{className:"threshold-alert-border"}),p.jsxs("div",{className:"threshold-alert-content-compact",children:[p.jsx(t.AlertTriangle,{className:"threshold-alert-icon-compact",size:14}),p.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${F(r.operator)} ${i}`}),p.jsx("button",{type:"button",onClick:Q,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),d&&p.jsx(C,{isOpen:d,onClose:U,onSuccess:E,component:A,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,notes:"",attachments:null,issue:g})]}):p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[p.jsx("div",{className:"threshold-alert-border"}),p.jsxs("div",{className:"threshold-alert-content",children:[p.jsx("div",{className:"threshold-alert-header",children:p.jsxs("div",{className:"threshold-alert-title-group",children:[p.jsx(t.AlertTriangle,{className:"threshold-alert-icon",size:20}),p.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),p.jsxs("div",{className:"threshold-alert-message",children:[(()=>{var e;const t=F(r.operator);return`${(null===(e=A.basic)||void 0===e?void 0:e.label)||"Value"}: Value ${n} exceeds threshold ${t} ${i}`})(),p.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),p.jsx("div",{className:"threshold-alert-buttons",children:p.jsx("button",{type:"button",onClick:Q,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),d&&p.jsx(C,{isOpen:d,onClose:U,onSuccess:E,component:A,formTemplateId:s,workOrderNumber:a,assetNumber:o,user:l,notes:"",attachments:null,issue:g})]})},F=({id:t,properties:A,validationErrors:r={},formValue:n="",inputType:i="text",readonly:s=!1,disabled:a=!1,touchedFields:o={},formSubmitted:l=!1,mode:c="test",onValueChange:u,onBlur:h,onFocus:d,className:f="",hideLabel:g=!1,formTemplateId:m,onThresholdIssueRaised:w,raisedThresholdIssues:b=new Set,workOrderNumber:B,assetNumber:y,user:C})=>{var F,Q,U,E,S;const N=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?N(e.value):"label"in e?N(e.label):"":String(e||""),L=e.useRef(t),I=e.useRef(null);e.useEffect(()=>{t!==L.current&&(console.warn(`[DfFormInput] Component ID changed from ${L.current} to ${t}`),L.current=t)},[t]);const _=N(n||(null===(F=null==A?void 0:A.basic)||void 0===F?void 0:F.defaultValue)||""),[k,O]=e.useState(_),[T,j]=e.useState(!1),[H,P]=e.useState(!1),[D,M]=e.useState(new Set),[R,K]=e.useState(_),V=()=>{if(i)return i;const e=null==A?void 0:A.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},G=e.useCallback(e=>{const t=(()=>{var e;const t={};if((null===(e=null==A?void 0:A.validation)||void 0===e?void 0:e.required)&&(t.required=!0),"email"===V()&&(t.email=!0),"text"===V()){const e=A.validation;(null==e?void 0:e.minLength)&&(t.minLength=e.minLength),(null==e?void 0:e.maxLength)&&(t.maxLength=e.maxLength)}if("number"===V()){const e=A.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&(t.lowerLimit=e.lowerLimit),e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&(t.upperLimit=e.upperLimit)}return t})(),r={};let n=!0;const i="string"==typeof e?e:null!=e?String(e):"";if(!t.required||i&&""!==i.trim()||(r.required=!0,n=!1),t.email&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(i)&&(r.email=!0,n=!1),t.minLength&&i&&i.length<t.minLength&&(r.minLength=!0,n=!1),t.maxLength&&i&&i.length>t.maxLength&&(r.maxLength=!0,n=!1),"number"===V())if(delete r.pattern,delete r.min,delete r.max,i&&""!==i.trim()){const e=i.trim(),A=parseFloat(e);isNaN(A)||("lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&A<t.lowerLimit&&(r.lowerLimit=!0,n=!1),"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&A>t.upperLimit&&(r.upperLimit=!0,n=!1))}else delete r.lowerLimit,delete r.upperLimit;return{isValid:n,errors:r}},[A,V]),z=e.useCallback(e=>{const A="string"==typeof e?e:null!=e?String(e):"";if(O(A),u){const e=G(A),r=L.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}`),u(n)}},[t,u,G,L]);e.useEffect(()=>{T&&(o[t]=!0)},[T,t,o]),e.useEffect(()=>{var e;if("edit"===c){j(!1);const t=(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.defaultValue)||"";O(t)}else"test"===c&&(j(!1),O(""))},[c,null===(Q=null==A?void 0:A.basic)||void 0===Q?void 0:Q.defaultValue]),e.useEffect(()=>{var e;const r=L.current,i=N(n||(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.defaultValue)||"");i===k||H||""===i&&""!==String(k||"").trim()?""===i&&String(k||"").trim():null!=n&&(r===t?O(i):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${r}, prop id: ${t}`))},[n,k,H,null===(U=null==A?void 0:A.basic)||void 0===U?void 0:U.defaultValue,t]),e.useEffect(()=>{l&&j(!0)},[l]),e.useEffect(()=>{"test"!==c&&O("")},[c]);const q=e.useCallback((e,t)=>{if(!t||""===t)return!1;const A="string"==typeof t?parseFloat(t):t,r="string"==typeof e.value?parseFloat(e.value):e.value;if(isNaN(A)||isNaN(r))return!1;switch(e.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}},[]),W=e.useMemo(()=>{var e;return(null===(e=null==A?void 0:A.condition)||void 0===e?void 0:e.conditions)||[]},[null==A?void 0:A.condition]);e.useEffect(()=>{k!==R&&(M(new Set),K(k))},[k,R]);const X=e.useMemo(()=>{if("test"!==c||!k||""===k)return null;const e=W.filter(e=>q(e,k));if(0===e.length)return null;for(const t of e)if(!D.has(t.id))return t;return null},[k,W,D,c,q,b]),Y=e.useCallback(e=>{M(t=>new Set(t).add(e))},[]),J=V(),$=a||s||(null===(E=null==A?void 0:A.validation)||void 0===E?void 0:E.readonly);return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!g&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",ref:I,children:[p.jsx("input",{type:J,id:t,value:k,onChange:e=>{const t=e.target.value;z(t)},onFocus:()=>{P(!0),d&&d()},onBlur:()=>{if(P(!1),j(!0),"test"===c&&u){const e="string"==typeof k?k:null!=k?String(k):"",A=G(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};u(r)}h&&h()},placeholder:A.basic.placeholder,disabled:$,readOnly:s||(null===(S=null==A?void 0:A.validation)||void 0===S?void 0:S.readonly),className:(()=>{const e="form-control";if("test"===c){const A="string"==typeof k?k:null!=k?String(k):"",n=G(A);if(n.isValid)return`${e} ${f}`.trim();const i=!n.isValid&&T,s=r[t]&&(T||l)&&!n;return`${e} ${i||s?"is-invalid":""} ${f}`.trim()}return`${e} ${f}`.trim()})()}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:o,formSubmitted:l,properties:A,localValidation:G(k),isTouched:T,mode:c})]})]}),X&&"test"===c&&(()=>{var e,t,r,n;const i=(null==b?void 0:b.has(X.id))||!1,s=null!==(null===(e=I.current)||void 0===e?void 0:e.closest(".table-cell"))||null!==(null===(t=I.current)||void 0===t?void 0:t.closest(".cell-content"))||null!==(null===(r=I.current)||void 0===r?void 0:r.closest(".datagrid-table-view"))||null!==(null===(n=I.current)||void 0===n?void 0:n.closest(".datagrid-list-view"))||f.includes("table-cell")||f.includes("cell-content");return p.jsx(x,{component:A,condition:X,currentValue:k,thresholdValue:X.value,formTemplateId:m,workOrderNumber:B,assetNumber:y,user:C,onDismiss:()=>Y(X.id),onIssueRaised:w,isIssueRaised:i,compact:s},`${X.id}-${i}`)})()]})},Q=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w;const[b,B]=e.useState(n),[y,C]=e.useState(!1),x=e.useCallback(e=>{var t,r,n;const i={};let s=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(i.required=!0,s=!1),(null===(r=null==A?void 0:A.validation)||void 0===r?void 0:r.minLength)&&e&&e.length<A.validation.minLength&&(i.minLength=!0,s=!1),(null===(n=null==A?void 0:A.validation)||void 0===n?void 0:n.maxLength)&&e&&e.length>A.validation.maxLength&&(i.maxLength=!0,s=!1),{isValid:s,errors:i}},[A]),F=e.useCallback(e=>{if(B(e),c){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,x]);e.useEffect(()=>{y&&(a[t]=!0)},[y,t,a]),e.useEffect(()=>{""===b&&""!==n&&B(n)},[n]),e.useEffect(()=>{o&&C(!0)},[o]),e.useEffect(()=>{"test"!==l&&B("")},[l]);const Q=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly),U=(null===(m=null==A?void 0:A.validation)||void 0===m?void 0:m.rows)||4;return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("textarea",{id:t,value:b,onChange:e=>{const t=e.target.value;F(t)},onFocus:()=>{h&&h()},onBlur:()=>{C(!0),u&&u()},placeholder:A.basic.placeholder,disabled:Q,readOnly:i||(null===(w=null==A?void 0:A.validation)||void 0===w?void 0:w.readonly),rows:U,className:`form-textarea ${!x(b).isValid&&y?"is-invalid":""} ${d}`.trim()}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(b),isTouched:y,mode:l})]})]})},U=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m;const[w,b]=e.useState(n),[B,y]=e.useState(!1),C=(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.multiple)||!1,x=e.useCallback(e=>{var t;const r={};let n=!0;return(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)&&(C?Array.isArray(e)&&0!==e.length||(r.required=!0,n=!1):(!e||"string"==typeof e&&""===e.trim())&&(r.required=!0,n=!1)),{isValid:n,errors:r}},[A,C]),F=e.useCallback(e=>{if(b(e),c){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,x]);e.useEffect(()=>{B&&(a[t]=!0)},[B,t,a]),e.useEffect(()=>{JSON.stringify(n)!==JSON.stringify(w)&&b(n)},[n,w]),e.useEffect(()=>{o&&y(!0)},[o]);const Q=s||i||(null===(m=null==A?void 0:A.validation)||void 0===m?void 0:m.readonly);return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsxs("select",{id:t,value:w,onChange:e=>{if(C){const t=Array.from(e.target.selectedOptions,e=>e.value);F(t)}else F(e.target.value)},onFocus:()=>{h&&h()},onBlur:()=>{y(!0),u&&u()},disabled:Q,multiple:C,className:`form-select ${!x(w).isValid&&B?"is-invalid":""} ${d}`.trim(),children:[!C&&p.jsx("option",{value:"",children:A.basic.placeholder||"Select an option"}),(A.options||[]).map((e,t)=>p.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(w),isTouched:B,mode:l})]})]})},E=({id:t,properties:A,validationErrors:r={},formValue:n=[],readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w;const[b,B]=e.useState(!1),y=Array.isArray(n)?n:[],C=e.useCallback(e=>{var t;const r={};let n=!0;return(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)&&0===e.length&&(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),x=e.useCallback(e=>{if(c){const A=C(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,C,y]),F=(e,t)=>{let A;A=t?[...y,e]:y.filter(t=>t!==e),x(A)},Q=()=>{h&&h()},U=()=>{B(!0),u&&u()};e.useEffect(()=>{b&&(a[t]=!0)},[b,t,a]),e.useEffect(()=>{},[n,t,y]),e.useEffect(()=>{o&&B(!0)},[o]);const E=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsx(p.Fragment,{children:p.jsx("div",{className:`form-group checkbox-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var e;return(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.inlineLayout)?"inline-layout":"vertical-layout"})()} ${d}`,children:!f&&A.basic.label?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(m=null==A?void 0:A.basic)||void 0===m?void 0:m.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:C(y),isTouched:b,mode:l})]})]}):p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(w=null==A?void 0:A.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:C(y),isTouched:b,mode:l})]})})})},S=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w;const[b,B]=e.useState(n),[y,C]=e.useState(!1),x=e.useCallback(e=>{var t;const r={};let n=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),F=e.useCallback(e=>{if(B(e),c){const A=x(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,x]),Q=e=>{F(e)},U=()=>{h&&h()},E=()=>{C(!0),u&&u()};e.useEffect(()=>{y&&(a[t]=!0)},[y,t,a]),e.useEffect(()=>{n!==b&&B(n)},[n,b]),e.useEffect(()=>{o&&C(!0)},[o]);const S=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsx(p.Fragment,{children:p.jsx("div",{className:`form-group radio-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()} ${(()=>{var e;return(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.inlineLayout)?"inline-layout":"vertical-layout"})()} ${d}`,children:!f&&A.basic.label?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(m=null==A?void 0:A.basic)||void 0===m?void 0:m.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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:S||e.disabled,className:"form-check-input"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(b),isTouched:y,mode:l})]})]}):p.jsxs("div",{className:"input-wrapper",children:[p.jsx("div",{className:"mt-2 "+((null===(w=null==A?void 0:A.basic)||void 0===w?void 0:w.inlineLayout)?"inline-options-grid":"space-y-2"),children:(A.options||[]).map((e,A)=>p.jsxs("div",{className:"form-check",children:[p.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:S||e.disabled,className:"form-check-input"}),p.jsx("label",{htmlFor:`${t}-${A}`,className:"form-check-label",children:e.label})]},A))}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(b),isTouched:y,mode:l})]})})})},N=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g;const[m,w]=e.useState(n),[b,B]=e.useState(!1),y=e.useCallback(e=>{var t;const r={};let n=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),C=e.useCallback(e=>{if(w(e),B(!0),c){const A=y(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,y]),x=()=>{h&&h()},F=()=>{B(!0),u&&u()};e.useEffect(()=>{b&&(a[t]=!0)},[b,t,a]),e.useEffect(()=>{n!==m&&w(n)},[n,m]),e.useEffect(()=>{o&&B(!0)},[o]);const Q=()=>{var e;return(null===(e=null==A?void 0:A.basic)||void 0===e?void 0:e.inlineLayout)?"inline-layout":"grid-layout"},U=e=>{const t=null==e?void 0:e.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},E=e=>{if(void 0!==(null==e?void 0:e.icon)&&""!==e.icon)return e.icon;return"pass"===U((null==e?void 0:e.value)||e)?"✓":"×"},S=(e,t)=>(null==e?void 0:e.color)||(null==e?void 0:e.backgroundColor)?{color:t?"#ffffff":e.color||"#00814b",backgroundColor:t?e.color||"#00814b":e.backgroundColor||"#34bd4914",borderColor:e.color||"#00814b"}:{},N=e=>{if((null==e?void 0:e.color)||(null==e?void 0:e.backgroundColor))return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===U((null==e?void 0:e.value)||e)?"pass-button":"fail-button")},L=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsxs(p.Fragment,{children:[p.jsx("div",{className:`form-group segment-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()} ${d}`,children:!f&&A.basic.label?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsx("div",{className:"form-segment-wrapper",children:p.jsx("div",{className:`form-segment-container ${Q()}`,children:(A.options||[]).map((e,A)=>{const r=m===e.value,n=S(e,r),i=N(e),s=E(e);return p.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[p.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"}),p.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&p.jsx("span",{className:"segment-icon",children:s}),p.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})]}):p.jsx("div",{className:"form-segment-wrapper",children:p.jsx("div",{className:`form-segment-container ${Q()}`,children:(A.options||[]).map((e,A)=>{const r=m===e.value,n=S(e,r),i=N(e),s=E(e);return p.jsxs("div",{className:"form-segment-option "+(r?"selected":""),children:[p.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"}),p.jsxs("label",{htmlFor:`${t}_option_${A}`,className:i,style:Object.keys(n).length>0?n:void 0,children:[s&&p.jsx("span",{className:"segment-icon",children:s}),p.jsx("span",{className:"segment-text",children:e.value})]})]},A)})})})}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:y(m),isTouched:b,mode:l})]})},L=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w,b,y;const C=e.useCallback(e=>{var t,r;if(!e)return"";if("string"==typeof e){if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e))return e;const r=B(e);if(r&&!isNaN(r.getTime())){const e=A.name||"",n=(null===(t=A.basic)||void 0===t?void 0:t.dateTimeMode)||("datetime-picker"===e?"datetime":"date");if("datetime"===n){return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}T${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`}return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}return e}if(e instanceof Date){if(isNaN(e.getTime()))return"";const t=A.name||"",n=(null===(r=A.basic)||void 0===r?void 0:r.dateTimeMode)||("datetime-picker"===t?"datetime":"date");if("datetime"===n){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}T${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}if("object"==typeof e&&null!==e){if("value"in e&&e.value)return C(e.value);if("date"in e&&e.date)return C(e.date);try{const t=String(e),A=B(t);if(A&&!isNaN(A.getTime()))return C(A)}catch(e){}return""}return""},[A]),x=C(n),[F,Q]=e.useState(x),[U,E]=e.useState(!1),[S,N]=e.useState(!1),L=e.useCallback(e=>{var t,r,n,i,s,a;const o={};let l=!0;const c=A.name||"",u=(null===(t=A.basic)||void 0===t?void 0:t.dateTimeMode)||("datetime-picker"===c?"datetime":"date"),h=e?String(e).trim():"";if((null===(r=null==A?void 0:A.validation)||void 0===r?void 0:r.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 e=B(h);if(!e||isNaN(e.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(n=null==A?void 0:A.validation)||void 0===n?void 0:n.minDate){const t=B(A.validation.minDate);t&&e<t&&(o.minDate=!0,o.minDateMessage=`Date and time must be on or after ${t.toLocaleDateString()}`,l=!1)}if(null===(i=null==A?void 0:A.validation)||void 0===i?void 0:i.maxDate){const t=B(A.validation.maxDate);t&&e>t&&(o.maxDate=!0,o.maxDateMessage=`Date and time must be on or before ${t.toLocaleDateString()}`,l=!1)}}else{const e=B(h);if(!e||isNaN(e.getTime()))return o.invalidDate=!0,l=!1,{isValid:l,errors:o};if(null===(s=null==A?void 0:A.validation)||void 0===s?void 0:s.minDate){const t=B(A.validation.minDate);t&&e<t&&(o.minDate=!0,o.minDateMessage=`Date must be on or after ${t.toLocaleDateString()}`,l=!1)}if(null===(a=null==A?void 0:A.validation)||void 0===a?void 0:a.maxDate){const t=B(A.validation.maxDate);t&&e>t&&(o.maxDate=!0,o.maxDateMessage=`Date must be on or before ${t.toLocaleDateString()}`,l=!1)}}return{isValid:l,errors:o}},[A]),I=e.useCallback(e=>{if(Q(e),c){const A=L(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,L]);e.useEffect(()=>{U&&(a[t]=!0)},[U,t,a]),e.useEffect(()=>{const e=C(n);e===F||S||Q(e)},[n,F,S,C]),e.useEffect(()=>{o&&E(!0)},[o]);const _=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly),k=A.name||"",O=(null===(m=A.basic)||void 0===m?void 0:m.dateTimeMode)||("datetime-picker"===k?"datetime":"date"),T=(()=>{switch(O){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsx("input",{type:T,id:t,value:F,onChange:e=>{const t=e.target.value;I(t)},onFocus:()=>{N(!0),h&&h()},onBlur:()=>{if(N(!1),E(!0),c){const e=L(F),A={id:t,value:F,isValid:e.isValid,errors:e.errors};c(A)}u&&u()},disabled:_,readOnly:i||(null===(w=null==A?void 0:A.validation)||void 0===w?void 0:w.readonly),min:null===(b=null==A?void 0:A.validation)||void 0===b?void 0:b.minDate,max:null===(y=null==A?void 0:A.validation)||void 0===y?void 0:y.maxDate,className:`form-date ${!L(F).isValid&&U?"is-invalid":""} ${d}`.trim()}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:L(F),isTouched:U,mode:l})]})]})},I=({id:t,properties:A,validationErrors:r={},formValue:n="",readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="preview",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g;const m=e.useRef(null),[w,b]=e.useState(!1),[B,y]=e.useState(!1),[C,x]=e.useState(n),[F,Q]=e.useState(!1),U=e.useCallback(e=>{var t;const r={};let n=!0;return!(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.required)||e&&""!==e.trim()||(r.required=!0,n=!1),{isValid:n,errors:r}},[A]),E=e.useCallback(e=>{if(x(e),c){const A=U(e),r={id:t,value:e,isValid:A.isValid,errors:A.errors};c(r)}},[t,c,U]),S=e.useCallback(()=>{const e=document.documentElement.classList.contains("dark")||"dark"===document.documentElement.getAttribute("data-theme");let t=getComputedStyle(document.documentElement).getPropertyValue("--df-color-fb-input-bg").trim();t||(t=e?"#2c2e34":"#ffffff");return{strokeColor:e?"#ffffff":"#000000",backgroundColor:t}},[]),N=e.useCallback(e=>{if(!e)return;const A=m.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 e=S();r.fillStyle=e.backgroundColor,r.fillRect(0,0,A.width,A.height);const t=A.width/A.height,i=n.width/n.height;let s=A.width,a=A.height,o=0,l=0;i>t?(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]),L=e.useCallback(()=>{const e=m.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const A=e.getBoundingClientRect();e.width=A.width,e.height=A.height,e.style.width=A.width+"px",e.style.height=A.height+"px";const r=S();t.strokeStyle=r.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?N(C):(t.fillStyle=r.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,S,N]),I=e.useCallback(()=>{setTimeout(()=>{L()},100)},[L]);e.useEffect(()=>{const e=()=>{I()},t=new MutationObserver(e=>{e.forEach(e=>{if("attributes"===e.type&&"class"===e.attributeName){const t=e.target;t.classList.contains("form-canvas-container")&&(t.classList.contains("mobile-view")||t.classList.contains("tablet-view")||t.classList.contains("desktop-view"))&&I()}})});return t.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[I]);const _=e.useCallback(e=>{const t=m.current;if(!t)return{x:0,y:0};const A=t.getBoundingClientRect(),r=t.width/A.width,n=t.height/A.height,i=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,s=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(i-A.left)*r,y:(s-A.top)*n}},[]),k=e=>{var t;if(i||s||(null===(t=null==A?void 0:A.validation)||void 0===t?void 0:t.readonly))return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),b(!0),y(!0);const r=m.current;if(!r)return;const n=r.getContext("2d");if(!n)return;const{x:a,y:o}=_(e),l=S();n.strokeStyle=l.strokeColor,n.lineWidth=2,n.lineCap="round",n.lineJoin="round",n.beginPath(),n.moveTo(a,o)},O=e=>{if(!w)return;e.preventDefault(),e.stopPropagation();const t=m.current;if(!t)return;const A=t.getContext("2d");if(!A)return;const{x:r,y:n}=_(e);A.lineTo(r,n),A.stroke()},T=()=>{if(!w)return;b(!1),Q(!0);const e=m.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const A=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<A.length;e+=4){const t=A[e],r=A[e+1],n=A[e+2];if(A[e+3]>0&&(t<255||r<255||n<255))return!0}})(e);const t=e.toDataURL("image/png");x(t),E(t),setTimeout(()=>{Q(!1)},100)}else Q(!1)},j=e.useCallback(()=>{const e=m.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const A=S();if(t.strokeStyle=A.strokeColor,C){const r=C,n=e.getBoundingClientRect();t.fillStyle=A.backgroundColor,t.fillRect(0,0,n.width,n.height),r&&N(r)}else{const r=e.getBoundingClientRect();t.fillStyle=A.backgroundColor,t.fillRect(0,0,r.width,r.height)}},[S,C,N]);e.useEffect(()=>{const e=new MutationObserver(e=>{e.forEach(e=>{"attributes"!==e.type||"class"!==e.attributeName&&"data-theme"!==e.attributeName||j()})});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{e.disconnect()}},[j]);e.useEffect(()=>{B&&(a[t]=!0)},[B,t,a]),e.useEffect(()=>{if(!(n===C||w||F||""!==C&&""===n)){if(n===C)return;x(n),n&&N(n)}},[n,C,w,F]),e.useEffect(()=>{o&&y(!0)},[o]),e.useEffect(()=>{if("test"!==l){x("");const e=m.current;if(e){const t=e.getContext("2d");if(t){const A=e.getBoundingClientRect();e.width=A.width,e.height=A.height;const r=S();t.fillStyle=r.backgroundColor,t.fillRect(0,0,A.width,A.height)}}}},[l]),e.useEffect(()=>{L()},[l]);const H=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly);return p.jsxs("div",{className:`form-group ${(()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"})()}`,children:[!f&&A.basic.label&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[A.basic.label,A.validation.required&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"input-wrapper",children:[p.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[p.jsx("canvas",{ref:m,id:t,className:`form-signature ${!U(C).isValid&&B?"is-invalid":""} ${d}`.trim(),onMouseDown:k,onMouseMove:O,onMouseUp:T,onMouseLeave:T,onTouchStart:k,onTouchMove:O,onTouchEnd:T,onFocus:()=>{h&&h()},onBlur:()=>{u&&u()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:H?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!H&&p.jsx("button",{type:"button",onClick:e=>(e=>{null==e||e.preventDefault(),null==e||e.stopPropagation();const t=m.current;if(!t)return;const A=t.getBoundingClientRect();t.width=A.width,t.height=A.height;const r=t.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",x(""),E("")})(e),className:"clear-signature-btn",style:{position:"absolute",bottom:"8px",right:"8px",padding:"4px 8px",backgroundColor:"var(--df-color-error-primary)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"0.75rem",fontWeight:"500",zIndex:10,transition:"all 0.2s ease",minWidth:"60px",minHeight:"28px"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-dark, #dc2626)",e.currentTarget.style.transform="scale(1.05)"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-primary)",e.currentTarget.style.transform="scale(1)"},children:"Clear"})]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:U(C),isTouched:B,mode:l})]})]})},_=({id:t,properties:A,validationErrors:r={},formValue:n=null,readonly:i=!1,disabled:s=!1,touchedFields:a={},formSubmitted:o=!1,mode:l="test",onValueChange:c,onBlur:u,onFocus:h,className:d="",hideLabel:f=!1})=>{var g,m,w,b,B,y,C,x;const[F,Q]=e.useState([]),[U,E]=e.useState(!1),[S,N]=e.useState(!1),L=e.useRef(null),I=e.useCallback(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 e=n.data;if("string"==typeof e)if(e.startsWith("data:"))a=e;else{const t=e.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>10){let e=s;e||(e=t.startsWith("/9j/")||t.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":t.startsWith("iVBORw0KGgo")?"image/png":t.startsWith("R0lGOD")?"image/gif":t.startsWith("UklGR")?"image/webp":"image/png"),a=`data:${e};base64,${t}`}else a=e}}const 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(e){console.error("Error creating object URL:",e),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 e="image/png";r.startsWith("/9j/")||r.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?e="image/jpeg":r.startsWith("iVBORw0KGgo")?e="image/png":r.startsWith("R0lGOD")?e="image/gif":r.startsWith("UklGR")&&(e="image/webp"),l=`data:${e};base64,${r}`}let c="";if(l.startsWith("data:")){const e=l.match(/filename=([^;]+)/i);if(e)c=decodeURIComponent(e[1]);else{const e=l.match(/data:([^;]+)/);if(e){const t=e[1];c=`file-${A+1}.${t.includes("image")?t.includes("jpeg")?"jpg":"png":t.includes("pdf")?"pdf":t.includes("word")?"doc":t.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 e=l.indexOf(";");a=e>5?l.substring(5,e):"application/octet-stream"}else{const e=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(e){a={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",zip:"application/zip",rar:"application/x-rar-compressed"}[e[1].toLowerCase()]||"application/octet-stream"}else a=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]),_=e.useCallback(()=>({isValid:!0,errors:{}}),[]),k=e.useCallback(e=>{var r;if(i||s)return;const n=I(e),a=F.length>0?[...F,...n]:n,o=(null===(r=null==A?void 0:A.validation)||void 0===r?void 0:r.maxFiles)||1/0,l=a.slice(0,o);if(Q(l),N(!0),c){const e=_(),A={id:t,value:l.map(e=>e.file),isValid:e.isValid,errors:e.errors};c(A)}},[F,A,i,s,c,_,I,t]),O=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]},T=e=>e.startsWith("image/")?"🖼️":e.startsWith("video/")?"🎥":e.startsWith("audio/")?"🎵":e.includes("pdf")?"📄":e.includes("word")||e.includes("document")?"📝":e.includes("excel")||e.includes("spreadsheet")?"📊":e.includes("zip")||e.includes("rar")?"📦":"📁";e.useEffect(()=>{S&&(a[t]=!0)},[S,t,a]),e.useEffect(()=>{("edit"===l||"test"===l)&&N(!1)},[l]),e.useEffect(()=>{const e=I(n);null!=n&&(Array.isArray(n)&&n.length>0||"string"==typeof n&&""!==String(n).trim()||"object"==typeof n&&!Array.isArray(n)&&Object.keys(n).length>0)||0===F.length&&null!=n?Q(e):(null==n||Array.isArray(n)&&0===n.length)&&F.length>0&&Q([])},[n,I,F.length]),e.useEffect(()=>{o&&N(!0)},[o]),e.useEffect(()=>()=>{F.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[F]);const j=()=>{var e;return"left"===(null===(e=null==A?void 0:A.styles)||void 0===e?void 0:e.labelAlignment)?"label-left":"label-top"},H=s||i||(null===(g=null==A?void 0:A.validation)||void 0===g?void 0:g.readonly),P=(null===(m=null==A?void 0:A.validation)||void 0===m?void 0:m.multiple)||!1,D=(null===(w=null==A?void 0:A.validation)||void 0===w?void 0:w.accept)||"*/*",M=(null===(b=null==A?void 0:A.validation)||void 0===b?void 0:b.maxFiles)||1/0,R=F.length<M&&(P||M>1),K="edit"===l,V="preview"===l||"test"===l,G=F.filter(e=>e.type.startsWith("image/")),z=F.filter(e=>!e.type.startsWith("image/")),q=G.length>0;return V&&q?p.jsxs("div",{className:`form-group ${j()}`,children:[!f&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(B=A.basic)||void 0===B?void 0:B.label)||"Attachments",(null===(y=A.validation)||void 0===y?void 0:y.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"file-upload-wrapper",children:[p.jsxs("div",{className:"file-image-display",children:[G.map(e=>p.jsxs("div",{className:"file-image-container",children:[e.preview&&p.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),p.jsxs("div",{className:"file-image-info",children:[p.jsx("div",{className:"file-name",title:e.name,children:e.name}),p.jsx("div",{className:"file-size",children:O(e.size)})]})]},e.id)),z.length>0&&p.jsxs("div",{className:"file-other-files",children:[p.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),z.map(e=>p.jsxs("div",{className:"file-item-minimal",children:[p.jsx("div",{className:"file-icon",children:T(e.type)}),p.jsxs("div",{className:"file-info",children:[p.jsx("div",{className:"file-name",title:e.name,children:e.name}),p.jsx("div",{className:"file-size",children:O(e.size)})]})]},e.id))]})]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:_(),isTouched:S,mode:l})]})]}):p.jsxs("div",{className:`form-group ${j()}`,children:[!f&&p.jsxs("label",{htmlFor:t,className:"form-label",children:[(null===(C=A.basic)||void 0===C?void 0:C.label)||"Attachments",(null===(x=A.validation)||void 0===x?void 0:x.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]}),p.jsxs("div",{className:"file-upload-wrapper",children:[p.jsxs("div",{className:`file-upload-area ${U?"drag-over":""} ${i?"readonly":""} ${s?"disabled":""} ${d}`.trim(),onDragOver:e=>{e.preventDefault(),i||s||E(!0)},onDragLeave:e=>{e.preventDefault(),E(!1)},onDrop:e=>{if(e.preventDefault(),E(!1),i||s)return;const t=e.dataTransfer.files;t.length>0&&k(t)},onClick:e=>{var t;const A=e.target,r=null!==A.closest(".file-item"),n=null!==A.closest(".file-remove");!K||H||0!==F.length||r||n||null===(t=L.current)||void 0===t||t.click()},onFocus:()=>{h&&h()},onBlur:()=>{if(N(!0),"test"===l&&c){const e=_(),A={id:t,value:F.map(e=>e.file),isValid:e.isValid,errors:e.errors};c(A)}u&&u()},tabIndex:H?-1:0,children:[p.jsx("input",{ref:L,type:"file",id:t,multiple:P,accept:D,onChange:e=>{const t=e.target.files;t&&t.length>0&&(k(t),e.target.value="")},disabled:H,style:{display:"none"}}),0===F.length?p.jsxs("div",{className:"upload-placeholder",onClick:e=>{var t;e.stopPropagation(),K&&!H&&(null===(t=L.current)||void 0===t||t.click())},children:[p.jsx("div",{className:"upload-icon",children:"📁"}),p.jsx("div",{className:"upload-text",children:A.basic.placeholder&&p.jsx("p",{className:"upload-hint",children:A.basic.placeholder})})]}):p.jsx("div",{className:"file-list",children:F.map(e=>p.jsxs("div",{className:"file-item",children:[p.jsx("div",{className:"file-preview",children:e.preview?p.jsx("img",{src:e.preview,alt:e.name,className:"file-image"}):p.jsx("div",{className:"file-icon",children:T(e.type)})}),p.jsxs("div",{className:"file-info",children:[p.jsx("div",{className:"file-name",title:e.name,children:e.name}),p.jsx("div",{className:"file-size",children:O(e.size)})]}),K&&!H&&p.jsx("button",{type:"button",className:"file-remove",onClick:A=>{A.stopPropagation(),(e=>{if(i||s)return;const A=F.filter(t=>t.id!==e);if(Q(A),N(!0),c){const e=_(),r={id:t,value:A.map(e=>e.file),isValid:e.isValid,errors:e.errors};c(r)}})(e.id)},"aria-label":`Remove ${e.name}`,children:"✕"})]},e.id))})]}),F.length>0&&R&&!H&&K&&p.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!H&&L.current&&K&&(L.current.value="",L.current.click())},"aria-label":"Add more files",children:[p.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:p.jsx("path",{d:"M12 5v14M5 12h14"})}),p.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),p.jsx(v,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:_(),isTouched:S,mode:l})]})]})},k=({id:A,properties:r,validationErrors:n={},formValue:i=null,readonly:s=!1,disabled:a=!1,touchedFields:o={},formSubmitted:l=!1,mode:c="test",onValueChange:u,onBlur:h,onFocus:d,className:f="",hideLabel:g=!1})=>{var m,w,y,C;const[x,F]=e.useState(i),[Q,U]=e.useState(!1),[E,S]=e.useState(""),[N,L]=e.useState(!1),[I,_]=e.useState(!1),[k,O]=e.useState({lat:40.7128,lng:-74.006}),[T,j]=e.useState(null),[H,P]=e.useState(10),[D,M]=e.useState(""),[R,K]=e.useState(!1),V=e.useRef(null),[G,z]=e.useState(!1),[q,W]=e.useState(null),[X,Y]=e.useState(!1);e.useEffect(()=>{if(i&&i.latitude&&i.longitude){40.7128===i.latitude&&-74.006===i.longitude||(F(i),j({lat:i.latitude,lng:i.longitude,isCurrentLocation:!1}),O({lat:i.latitude,lng:i.longitude}))}else null==i&&(F(null),j(null))},[i]),e.useEffect(()=>{I&&40.7128===k.lat&&k.lng},[I,k]),e.useEffect(()=>{(s||a)&&(I&&_(!1),D&&M(""),G&&(z(!1),W(null)))},[s,a]);const J=e.useCallback((e,t)=>b(void 0,void 0,void 0,function*(){Y(!0);try{const A=yield fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),r=yield A.json();if(r&&r.address){const e=r.address;return{placeName:r.display_name||"",city:e.city||e.town||e.village||e.municipality||"",country:e.country||""}}}catch(e){console.error("Reverse geocoding failed:",e)}finally{Y(!1)}return{placeName:"",city:"",country:""}}),[]),$=e.useCallback((e,t,r)=>b(void 0,void 0,void 0,function*(){const n=yield J(e,t),i=Object.assign({latitude:e,longitude:t,timestamp:Date.now(),placeName:n.placeName,city:n.city,country:n.country,address:n.placeName},r);if(F(i),j({lat:e,lng:t,isCurrentLocation:!1}),L(!0),u){u({id:A,value:i,isValid:!0,errors:{}})}}),[J,A,u]),Z=e.useCallback(()=>b(void 0,void 0,void 0,function*(){var e,t,A,n,i,o,l,c,u,h,d,f,p,g,m;if(s||a)return;U(!0),S("");if(void 0!==window.Capacitor)try{const{Geolocation:s}=window.Capacitor.Plugins;if(s)try{if("granted"!==(yield s.requestPermissions()).location)return U(!1),void S("Location permission is required. Please enable location access in your device settings.");const a=yield s.getCurrentPosition({enableHighAccuracy:null===(t=null===(e=r.validation)||void 0===e?void 0:e.enableHighAccuracy)||void 0===t||t,timeout:null!==(n=null===(A=r.validation)||void 0===A?void 0:A.timeout)&&void 0!==n?n:1e4,maximumAge:null!==(o=null===(i=r.validation)||void 0===i?void 0:i.maximumAge)&&void 0!==o?o:3e5}),l=a.coords.latitude,c=a.coords.longitude;return j({lat:l,lng:c,isCurrentLocation:!0}),O({lat:l,lng:c}),L(!0),yield $(l,c,{accuracy:a.coords.accuracy,timestamp:Date.now()}),U(!1),void S("")}catch(e){return U(!1),void((null===(l=e.message)||void 0===l?void 0:l.includes("permission"))||(null===(c=e.message)||void 0===c?void 0:c.includes("denied"))?S("Location permission is required. Please enable location access in your device settings."):(null===(u=e.message)||void 0===u?void 0:u.includes("timeout"))?S("Location request timed out. Please try again."):S("Unable to retrieve your location. Please try again."))}}catch(e){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return U(!1),void S("Geolocation is not supported by this browser.");const w={enableHighAccuracy:null===(d=null===(h=r.validation)||void 0===h?void 0:h.enableHighAccuracy)||void 0===d||d,timeout:null!==(p=null===(f=r.validation)||void 0===f?void 0:f.timeout)&&void 0!==p?p:1e4,maximumAge:null!==(m=null===(g=r.validation)||void 0===g?void 0:g.maximumAge)&&void 0!==m?m:3e5};navigator.geolocation.getCurrentPosition(e=>b(void 0,void 0,void 0,function*(){const t=e.coords.latitude,A=e.coords.longitude;j({lat:t,lng:A,isCurrentLocation:!0}),O({lat:t,lng:A}),L(!0),yield $(t,A,{accuracy:e.coords.accuracy,timestamp:e.timestamp}),U(!1),S("")}),e=>{U(!1);let t="Unable to retrieve your location.";switch(e.code){case e.PERMISSION_DENIED:t="Location access denied by user. Please enable location access in your browser/device settings.";break;case e.POSITION_UNAVAILABLE:t="Location information is unavailable.";break;case e.TIMEOUT:t="Location request timed out. Please try again."}S(t)},w)}),[s,a,r,$]),ee=e.useCallback(()=>{if(!s&&!a&&(F(null),j(null),S(""),L(!0),u)){u({id:A,value:null,isValid:!0,errors:{}})}},[s,a,A,u]),te=e.useCallback(()=>{s||a||_(!I)},[s,a,I]),Ae=e.useCallback((e,t,A,r,n,i)=>{const s=e-n/2,a=t-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))}},[]),re=e.useCallback(e=>{s||a||!V.current||0===e.button&&(z(!0),W({x:e.clientX,y:e.clientY}),e.preventDefault())},[s,a]),ne=e.useCallback(e=>{if(!G||!q||!V.current)return;const t=e.clientX-q.x,A=e.clientY-q.y,r=156543.03392*Math.cos(k.lat*Math.PI/180)/Math.pow(2,H),n=-A*r/111320,i=t*r/(111320*Math.cos(k.lat*Math.PI/180));O({lat:k.lat+n,lng:k.lng+i}),W({x:e.clientX,y:e.clientY})},[G,q,k,H]),ie=e.useCallback(e=>b(void 0,void 0,void 0,function*(){if(!V.current)return;if(G&&q){const t=Math.abs(e.clientX-q.x),A=Math.abs(e.clientY-q.y);if(t>5||A>5)return z(!1),void W(null)}if(s||a)return z(!1),void W(null);const t=V.current.getBoundingClientRect(),A=e.clientX-t.left,r=e.clientY-t.top,{lat:n,lng:i}=Ae(A,r,k,H,t.width,t.height);yield $(n,i),z(!1),W(null)}),[s,a,V,k,H,Ae,$,G,q]),se=e.useCallback(e=>b(void 0,void 0,void 0,function*(){if(e.trim()&&!s&&!a){K(!0),S("");try{const t=yield fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(e)}&limit=5&addressdetails=1`),r=yield t.json();if(r&&r.length>0){const e=r[0],t=parseFloat(e.lat),n=parseFloat(e.lon),i=e.address||{},s={latitude:t,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(F(s),j({lat:t,lng:n,isCurrentLocation:!1}),O({lat:t,lng:n}),L(!0),u){u({id:A,value:s,isValid:!0,errors:{}})}}else S("No locations found for your search.")}catch(e){S("Failed to search for location. Please try again.")}finally{K(!1)}}}),[s,a,A,u]),ae=()=>{d&&d()},oe=()=>{L(!0),h&&h()},le=a||s||(null===(m=null==r?void 0:r.validation)||void 0===m?void 0:m.readonly),ce=(null===(w=null==r?void 0:r.basic)||void 0===w?void 0:w.label)||"Location",ue=(null===(y=null==r?void 0:r.basic)||void 0===y?void 0:y.description)||"";return p.jsxs("div",{className:`form-group ${g?"no-label":""} ${f}`,children:[!g&&p.jsxs("label",{htmlFor:A,className:"form-label",children:[ce,(null===(C=null==r?void 0:r.validation)||void 0===C?void 0:C.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]}),ue&&p.jsx("div",{className:"form-group-description",children:ue}),p.jsxs("div",{className:"location-wrapper",children:[!(s&&x)&&p.jsxs("div",{className:"location-controls",children:[p.jsx("button",{type:"button",className:"location-btn "+(Q?"loading":""),onClick:Z,disabled:le||Q,onFocus:ae,onBlur:oe,tabIndex:le?-1:0,children:Q?p.jsxs(p.Fragment,{children:[p.jsx(t.Loader2,{size:16,className:"loading-spinner"}),"Getting Location..."]}):p.jsxs(p.Fragment,{children:[p.jsx(t.Navigation,{size:16}),"Get Current Location"]})}),p.jsxs("button",{type:"button",className:"location-btn secondary",onClick:te,disabled:le,onFocus:ae,onBlur:oe,tabIndex:le?-1:0,children:[p.jsx(t.MapPin,{size:16}),I?"Hide Map":"Choose on Map"]})]}),x&&p.jsxs("div",{className:"location-display",children:[!s&&p.jsx("button",{type:"button",className:"location-clear-btn",onClick:ee,disabled:le,title:"Clear location",children:p.jsx(t.X,{size:16})}),x.placeName&&p.jsxs("div",{className:"location-place-name",children:[p.jsx("strong",{children:"Place:"})," ",x.placeName]}),(x.city||x.country)&&p.jsxs("div",{className:"location-address",children:[p.jsx("strong",{children:"Address:"})," ",[x.city,x.country].filter(Boolean).join(", ")]}),p.jsxs("div",{className:"location-coordinates",children:[p.jsx("strong",{children:"Coordinates:"})," ",(de=x.latitude,fe=x.longitude,void 0===de||void 0===fe||isNaN(de)||isNaN(fe)?"":`${Number(de).toFixed(6)}, ${Number(fe).toFixed(6)}`)]}),x.accuracy&&p.jsxs("div",{className:"location-accuracy",children:[p.jsx("strong",{children:"Accuracy:"})," ",(he=x.accuracy,he?`±${Math.round(he)}m`:"")]}),x.timestamp&&p.jsxs("div",{className:"location-timestamp",children:[p.jsx("strong",{children:"Captured:"})," ",(B(x.timestamp)||new Date).toLocaleString()]})]}),I&&!s&&p.jsxs("div",{className:"location-map-container",children:[p.jsxs("div",{className:"location-map-header",children:[p.jsx("h4",{children:"Select Location on Map"}),p.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),p.jsx("div",{className:"location-search",children:p.jsx("form",{onSubmit:e=>{e.preventDefault(),D.trim()&&se(D)},className:"search-form",children:p.jsxs("div",{className:"search-input-group",children:[p.jsx("input",{type:"text",value:D,onChange:e=>{M(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:le||R}),p.jsx("button",{type:"submit",className:"search-btn",disabled:le||R||!D.trim(),children:R?p.jsx(t.Loader2,{size:16,className:"loading-spinner"}):"Search"})]})})}),p.jsxs("div",{ref:V,className:"location-map "+(G?"dragging":""),onMouseDown:re,onMouseMove:ne,onMouseUp:ie,onMouseLeave:()=>{z(!1),W(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:G?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${H}/${Math.floor((k.lng+180)/360*Math.pow(2,H))}/${Math.floor((1-Math.log(Math.tan(k.lat*Math.PI/180)+1/Math.cos(k.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,H))}.png) center/cover no-repeat`,userSelect:"none"},children:[T&&p.jsx("div",{className:"map-marker "+(T.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:p.jsx(t.MapPin,{size:24})}),p.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}}),p.jsxs("div",{className:"map-controls",children:[p.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>P(e=>Math.min(18,e+1)),disabled:H>=18,children:"+"}),p.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>P(e=>Math.max(1,e-1)),disabled:H<=1,children:"−"})]})]}),p.jsxs("div",{className:"location-map-instructions",children:[p.jsx("p",{children:p.jsx("strong",{children:"Instructions:"})}),p.jsxs("ul",{children:[p.jsx("li",{children:"Search for a place using the search box above"}),p.jsx("li",{children:"Click anywhere on the map to select a location"}),p.jsx("li",{children:"Drag the map to pan around"}),p.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),p.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),X&&p.jsxs("div",{className:"location-loading",children:[p.jsx(t.Loader2,{size:16,className:"loading-spinner"}),p.jsx("span",{children:"Loading address details..."})]})]}),E&&p.jsx("div",{className:"location-error",children:E})]}),p.jsx(v,{validationErrors:n,fieldId:A,touchedFields:o,formSubmitted:l,properties:r,localValidation:{isValid:!0,errors:{}},isTouched:N,mode:c})]});var he,de,fe},O=({id:e,properties:t,className:A="",hideLabel:r=!1})=>{var n,i,s;const a=null!==(s=null!==(i=null===(n=t.styles)||void 0===n?void 0:n.level)&&void 0!==i?i:t.basic.level)&&void 0!==s?s:1,o=t.basic.label,l=()=>{var e;return`form-heading ${`h${a}`} ${(null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.textAlign)?`text-${t.styles.textAlign}`:""} ${A}`.trim()},c=()=>{var e,A;const r={};return(null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.fontSize)&&(r.fontSize=t.styles.fontSize),(null===(A=null==t?void 0:t.styles)||void 0===A?void 0:A.color)&&(r.color=t.styles.color),r};return r?null:(()=>{const t={id:e,className:l(),style:c()};switch(a){case 1:default:return p.jsx("h1",Object.assign({},t,{children:o}));case 2:return p.jsx("h2",Object.assign({},t,{children:o}));case 3:return p.jsx("h3",Object.assign({},t,{children:o}));case 4:return p.jsx("h4",Object.assign({},t,{children:o}));case 5:return p.jsx("h5",Object.assign({},t,{children:o}));case 6:return p.jsx("h6",Object.assign({},t,{children:o}))}})()},T=({id:A,properties:r,mode:n="preview",formValue:i,onValueChange:s,className:a="",hideLabel:o=!1})=>{var l,c,u;const[h,d]=e.useState(""),[f,g]=e.useState((null===(l=r.validation)||void 0===l?void 0:l.listStyle)||"numbers"),[m,w]=e.useState("#000000"),v=e.useRef(null),b=e.useRef(null),B=e.useRef(!1),y="edit"===n,C=e.useRef({instructions:[],listStyle:"numbers",formValue:void 0}),x=e.useRef(n);e.useEffect(()=>{var e,t,A,s,a;let o=[],l="numbers";if(null!=i&&("object"==typeof i&&i.instructions?(Array.isArray(i.instructions)?o=i.instructions:"string"==typeof i.instructions&&(o=[i.instructions]),i.listStyle&&(l=i.listStyle)):Array.isArray(i)?o=i:"string"==typeof i&&(o=[i])),0===o.length&&(null===(e=r.basic)||void 0===e?void 0:e.value)){const e=r.basic.value;e&&"object"==typeof e&&!Array.isArray(e)&&e.instructions?(Array.isArray(e.instructions)?o=e.instructions:"string"==typeof e.instructions&&(o=[e.instructions]),e.listStyle&&"string"==typeof e.listStyle&&(l=e.listStyle)):Array.isArray(e)?o=e:"string"==typeof e&&(o=[e])}0===o.length&&(null===(t=r.basic)||void 0===t?void 0:t.instructions)&&(Array.isArray(r.basic.instructions)?o=r.basic.instructions:"string"==typeof r.basic.instructions&&(o=[r.basic.instructions])),l&&"numbers"!==l||(l=(null===(A=r.validation)||void 0===A?void 0:A.listStyle)||(null===(a=null===(s=r.basic)||void 0===s?void 0:s.value)||void 0===a?void 0:a.listStyle)||"numbers");const c=JSON.stringify(o)!==JSON.stringify(C.current.instructions)||l!==C.current.listStyle,u=n!==x.current,h=JSON.stringify(i)!==JSON.stringify(C.current.formValue),f=!C.current.formValue||Array.isArray(C.current.formValue)&&0===C.current.formValue.length||"string"==typeof C.current.formValue&&""===C.current.formValue.trim(),p=null!=i&&(Array.isArray(i)&&i.length>0||"string"==typeof i&&""!==i.trim()||"object"==typeof i&&Object.keys(i).length>0);if(c||u||h||f&&p){const e=e=>"string"!=typeof e?e:e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))),t=o.map(t=>"string"==typeof t?e(t):t),A=t.some(e=>"string"==typeof e&&/<[^>]+>/.test(e));let r="";if(t.length>0)if(A)r=t.join("");else{const e="numbers"===l?"ol":"bullets"===l?"ul":"div",A=t.filter(e=>e&&"string"==typeof e).map(e=>`<li>${e.replace(/\n/g,"<br>")}</li>`).join("");r="div"===e?t.filter(e=>e&&"string"==typeof e).map(e=>`<div>${e.replace(/\n/g,"<br>")}</div>`).join(""):`<${e}>${A}</${e}>`}g(l),d(r),y&&v.current&&(u||c&&v.current.innerHTML.trim()!==r.trim())&&(v.current.innerHTML=r),C.current={instructions:o,listStyle:l,formValue:i},x.current=n}},[i,null===(c=r.basic)||void 0===c?void 0:c.instructions,null===(u=r.validation)||void 0===u?void 0:u.listStyle,n,y]),e.useEffect(()=>{if(y&&v.current){const e=v.current.innerHTML.trim();h.trim()===e||B.current||(v.current.innerHTML=h)}if(B.current){const e=setTimeout(()=>{B.current=!1},200);return()=>clearTimeout(e)}},[h,y]);const F=e.useCallback(()=>{if(!v.current)return;B.current=!0;const e=v.current.innerHTML.trim();if(s){s({id:A,value:{instructions:e?[e]:[],listStyle:f},isValid:!0,errors:{}})}e!==h&&d(e)},[A,f,s,h]),Q=e.useCallback(()=>{if(!v.current)return;const e=v.current.innerHTML.trim();if(s){s({id:A,value:{instructions:e?[e]:[],listStyle:f},isValid:!0,errors:{}})}d(e),B.current=!1},[A,f,s]),U=e.useCallback((e,t)=>{var A;document.execCommand(e,!1,t),null===(A=v.current)||void 0===A||A.focus(),F()},[F]),E=e.useCallback(()=>{U("bold")},[U]),S=e.useCallback(()=>{U("italic")},[U]),N=e.useCallback(e=>{const t=e.target.value;w(t),U("foreColor",t)},[U]),L=e.useCallback(e=>{if(g(e),!v.current)return;const t=window.getSelection(),r=t&&t.rangeCount>0?t.getRangeAt(0):null;let n=v.current.innerHTML;if("numbers"===e){if(n=n.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!n.includes("<ol>")&&!n.includes("<ul>")){const e=n.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(n="<ol>"+e.map(e=>`<li>${e}</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 e=n.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(n="<ul>"+e.map(e=>`<li>${e}</li>`).join("")+"</ul>")}}else n=n.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(v.current.innerHTML=n,d(n),r&&t)try{t.removeAllRanges(),t.addRange(r)}catch(e){}if(F(),s){s({id:A,value:{instructions:n?[n]:[],listStyle:e},isValid:!0,errors:{}})}},[A,F,s]),I=e.useCallback(e=>{var t;const A=null===(t=e.target.files)||void 0===t?void 0:t[0];if(!A||!A.type.startsWith("image/"))return;const r=new FileReader;r.onload=e=>{var t;const A=null===(t=e.target)||void 0===t?void 0:t.result;if(A&&v.current){const e=document.createElement("img");e.src=A,e.style.maxWidth="100%",e.style.height="auto";const t=window.getSelection();if(t&&t.rangeCount>0){const A=t.getRangeAt(0);A.deleteContents(),A.insertNode(e)}else v.current.appendChild(e);F()}},r.readAsDataURL(A),b.current&&(b.current.value="")},[F]),_=e.useCallback(e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain"),A=window.getSelection();if(A&&A.rangeCount>0){const e=A.getRangeAt(0);e.deleteContents();const r=document.createTextNode(t);e.insertNode(r),e.setStartAfter(r),e.collapse(!0),A.removeAllRanges(),A.addRange(e)}F()},[F]),k=e.useCallback(e=>document.queryCommandState(e),[]);return p.jsxs("div",{className:`form-group instruction-group ${a}`,children:[!o&&p.jsx("label",{htmlFor:A,className:"instruction-label",children:"Instructions"}),y?p.jsxs("div",{className:"instruction-rich-editor",children:[p.jsxs("div",{className:"instruction-toolbar",children:[p.jsxs("div",{className:"toolbar-group",children:[p.jsx("button",{type:"button",className:"toolbar-btn "+(k("bold")?"active":""),onClick:E,title:"Bold","aria-label":"Bold",children:p.jsx(t.Bold,{size:16})}),p.jsx("button",{type:"button",className:"toolbar-btn "+(k("italic")?"active":""),onClick:S,title:"Italic","aria-label":"Italic",children:p.jsx(t.Italic,{size:16})})]}),p.jsx("div",{className:"toolbar-separator"}),p.jsx("div",{className:"toolbar-group",children:p.jsxs("div",{className:"color-picker-wrapper",children:[p.jsx("input",{type:"color",value:m,onChange:N,className:"color-picker-input",title:"Text Color"}),p.jsx("label",{className:"color-picker-label",title:"Text Color",children:p.jsx("span",{style:{color:m},children:"A"})})]})}),p.jsx("div",{className:"toolbar-separator"}),p.jsxs("div",{className:"toolbar-group",children:[p.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===f?"active":""),onClick:()=>L("bullets"),title:"Bullet List","aria-label":"Bullet List",children:p.jsx(t.List,{size:16})}),p.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===f?"active":""),onClick:()=>L("numbers"),title:"Numbered List","aria-label":"Numbered List",children:p.jsx(t.ListOrdered,{size:16})})]}),p.jsx("div",{className:"toolbar-separator"}),p.jsxs("div",{className:"toolbar-group",children:[p.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>{var e;return null===(e=b.current)||void 0===e?void 0:e.click()},title:"Insert Image","aria-label":"Insert Image",children:p.jsx(t.Image,{size:16})}),p.jsx("input",{ref:b,type:"file",accept:"image/*",onChange:I,style:{display:"none"}})]})]}),p.jsx("div",{ref:v,contentEditable:!0,className:"instruction-editor-content",onInput:F,onBlur:Q,onPaste:_,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):p.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===f?"instruction-list-numbers":"bullets"===f?"instruction-list-bullets":""),children:h?p.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:h}}):p.jsx("div",{className:"instruction-empty",children:p.jsx("p",{children:"No instructions provided"})})})]})},j=({attachments:A,onRemove:r})=>{const[n,i]=e.useState(new Map);return e.useEffect(()=>{if(!A)return void i(e=>(e.forEach(e=>URL.revokeObjectURL(e)),new Map));const e=new Map;return A.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(e=>URL.revokeObjectURL(e))}},[A]),A&&0!==A.length?p.jsx("div",{className:"attachment-thumbnails-container",children:A.map((e,A)=>{const i=e&&e.type&&"string"==typeof e.type&&e.type.startsWith("image/"),s=n.get(A);return p.jsx("div",{className:"attachment-thumbnail",children:i&&s?p.jsxs(p.Fragment,{children:[p.jsx("img",{src:s,alt:e?e.name:"Attachment"}),p.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(A),title:"Remove attachment",children:p.jsx(t.X,{size:14})})]}):p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"file-icon-placeholder",children:p.jsx(t.Paperclip,{size:20})}),p.jsx("span",{className:"file-name",children:e?e.name:"Unknown File"}),p.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>r(A),title:"Remove attachment",children:p.jsx(t.X,{size:14})})]})},A)})}):null},H=({component:A,mode:r,formTemplateId:n,formValue:i,onNotesChange:s,onAttachmentChange:a,notes:o="",attachments:l=null,onThresholdActionCompletion:c,onThresholdIssueRaised:u,onBasicPropertyActionCompletion:h,workOrderNumber:d,assetNumber:f,isStandalone:g,user:m,onCreateIssue:w,onUpdateIssue:v})=>{var b,B,y,x;const[F,Q]=e.useState(o||""),[U,E]=e.useState(l||null),[S,N]=e.useState(!1),[L,I]=e.useState(!1),[_,k]=e.useState(!1),[O,T]=e.useState(!1),[H,P]=e.useState(null),[D,M]=e.useState(!1),R=e.useRef(null),K=e.useRef(i),V=e.useRef(!1),G=e.useRef(!1);e.useEffect(()=>{if(!V.current&&null!=o){const e="string"==typeof o?o:String(o||"");Q(e),V.current=!0}},[o]),e.useEffect(()=>{G.current||void 0===l||(E(l),G.current=!0)},[l]),e.useEffect(()=>{if(V.current&&!S&&null!=o){const e="string"==typeof o?o:String(o||"");F&&""!==String(F||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==F&&Q(e):Q(e)}},[o,S,F]),e.useEffect(()=>{G.current&&void 0!==l&&(!U||l&&l.length>0&&l!==U)&&E(l)},[l,U]),e.useEffect(()=>{const e=["select","radio","checkbox","segment"].includes(A.name||"");if(e){const e=K.current,t=i;let r=!1;if("checkbox"===A.name){const A=Array.isArray(e)?e:e?[e]:[],n=Array.isArray(t)?t:t?[t]:[];r=JSON.stringify(A.sort())!==JSON.stringify(n.sort())}else r=e!==t&&void 0!==e;if(r){k(!1),T(!1),P(null),I(!1),N(!1),M(!1);const e="string"==typeof o?o:String(o||"");e&&""!==e.trim()?Q(e):Q(""),l&&0!==l.length?E(l):E(null)}K.current=t}e||(K.current=i)},[i,A.name,o,l]);const z=e.useCallback((e,t)=>{const{operator:A,value:r}=e,n=String(t).toLowerCase(),i=String(r).toLowerCase();switch(A){case"equals":return n===i||String(t)===String(r);case"notEquals":return n!==i&&String(t)!==String(r);case"greaterThan":return Number(t)>Number(r);case"lessThan":return Number(t)<Number(r);case"greaterThanOrEqual":return Number(t)>=Number(r);case"lessThanOrEqual":return Number(t)<=Number(r);default:return!1}},[]),q=e.useCallback(()=>{if(!(null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length)))return[];const e=A.condition;if(!e||!e.conditions||0===e.conditions.length)return[];const t=[];if("checkbox"===A.name&&Array.isArray(i))i.forEach(A=>{const r=e.conditions.find(e=>z(e,A));r&&!t.find(e=>e.id===r.id)&&t.push(r)});else{const A=e.conditions.find(e=>z(e,i));A&&t.push(A)}return t},[A,i,z]),W=e.useCallback(e=>{const t=e.target.value;Q(t),s&&s(t);const r=q(),n=String(t||"").trim().length>0;r.forEach(e=>{!0===e.enableNotes&&c&&c(e.id,"notes",n)});const i=A.condition;!(i&&i.conditions&&i.conditions.length>0)&&h&&h("notes",n)},[s,q,c,A,h]),X=e.useCallback(()=>{if(s){const e="string"==typeof F?F:String(F||"");s(e),setTimeout(()=>{N(!1)},0)}else N(!1)},[F,s]),Y=e.useCallback(()=>{X()},[X]),J=e.useCallback(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),X())},[X]),$=e.useCallback(()=>{N(!0)},[]),Z=e.useCallback(()=>{N(!0)},[]),ee=e.useCallback(()=>{var e;null===(e=R.current)||void 0===e||e.click()},[]),te=e.useCallback(e=>{const t=e.target.files;if(t&&t.length>0){const e=Array.from(t);E(e),a&&a(e);q().forEach(e=>{!0===e.enableAttachment&&c&&c(e.id,"attachments",!0)});const r=A.condition;!(r&&r.conditions&&r.conditions.length>0)&&h&&h("attachments",!0)}R.current&&(R.current.value="")},[a,q,c,A,h]),Ae=e.useCallback(e=>{if(U){const t=U.filter((t,A)=>A!==e);if(0===t.length){E(null),a&&a(null);q().forEach(e=>{!0===e.enableAttachment&&c&&c(e.id,"attachments",!1)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&h&&h("attachments",!1)}else E(t),a&&a(t)}},[U,a,q,c,A,h]),re=e.useCallback(()=>{k(!0);q().forEach(e=>{!0===e.enableSendEmail&&c&&c(e.id,"email",!0)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&h&&h("email",!0),setTimeout(()=>{k(!1)},3e3)},[q,c,A,h]),ne=e.useCallback(()=>{O||I(!0)},[O]),ie=e.useCallback(()=>{I(!1)},[]),se=e.useCallback(e=>{I(!1),T(!0),e&&P(e);const t=A.condition;if(t&&t.conditions&&t.conditions.length>0){q().forEach(e=>{!0===e.enableRaiseIssue&&u&&u(e.id)})}else h&&h("issue",!0)},[A,h,q,u]);if("test"!==r)return null;const ae=["select","radio","checkbox","segment"].includes(A.name||""),oe=(null===(b=A.basic)||void 0===b?void 0:b.options)||A.options||[];let le=!1,ce=!1,ue=!1,he=!1,de=null;const fe=null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length),pe=A.condition,ge=pe&&pe.conditions&&pe.conditions.length>0;if(ge&&fe)if("checkbox"===A.name&&Array.isArray(i)){const e=i;for(const t of e){const e=pe.conditions.find(e=>z(e,t));e&&(le=le||!0===e.enableNotes,ce=ce||!0===e.enableAttachment,ue=ue||!0===e.enableRaiseIssue,he=he||!0===e.enableSendEmail)}}else if(ae){const e=pe.conditions.find(e=>z(e,i));e&&(le=!0===e.enableNotes,ce=!0===e.enableAttachment,ue=!0===e.enableRaiseIssue,he=!0===e.enableSendEmail)}else{const e=pe.conditions.find(e=>z(e,i));e&&(le=!0===e.enableNotes,ce=!0===e.enableAttachment,ue=!0===e.enableRaiseIssue,he=!0===e.enableSendEmail)}if(!ge){const e=A.basic,t=!0===(null==e?void 0:e.enableNotes),r=!0===(null==e?void 0:e.enableAttachment),n=!0===(null==e?void 0:e.enableRaiseIssue),s=!0===(null==e?void 0:e.enableSendEmail);if(ae)if(fe)if("checkbox"===A.name){(Array.isArray(i)?i:[i]).forEach(e=>{const t=oe.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(le=le||!0===t.enableNotes,ce=ce||!0===t.enableAttachment,ue=ue||!0===t.enableRaiseIssue,he=he||!0===t.enableSendEmail,de||(de=t))}),le=le||t,ce=ce||r,ue=ue||n,he=he||s}else if(de=oe.find(e=>!(!e||!e.value)&&(e.value===i||(String(e.value)===String(i)||(e.label===i||String(e.label)===String(i))))),de){const e=!0===de.enableNotes,A=!0===de.enableAttachment,i=!0===de.enableRaiseIssue,a=!0===de.enableSendEmail;le=e||t,ce=A||r,ue=i||n,he=a||s}else le=t,ce=r,ue=n,he=s;else le=t,ce=r,ue=n,he=s;else le=t,ce=r,ue=n,he=s}if(!(le||ce||ue||he))return null;const me=q(),we=A.condition,ve=we&&we.conditions&&we.conditions.length>0,be=!!ve&&me.some(e=>!0===e.enableNotes),Be=!!ve&&me.some(e=>!0===e.enableAttachment),ye=!!ve&&me.some(e=>!0===e.enableSendEmail),Ce=!!ve&&me.some(e=>!0===e.enableRaiseIssue),xe=String(F||"").trim().length>0,Fe=U&&U.length>0,Qe=U?U.length:0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"component-action-features",children:[p.jsxs("div",{className:"action-icons-toolbar",children:[le&&p.jsxs("button",{type:"button",className:`action-icon-button ${xe?"active":""} ${be?"mandatory":""}`,onClick:$,title:"Add Notes",children:[p.jsx(t.MessageSquare,{size:14,fill:xe?"currentColor":"none"}),be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ce&&p.jsxs("button",{type:"button",className:`action-icon-button ${Fe?"active":""} ${Be?"mandatory":""}`,onClick:ee,title:"Add Attachment",children:[p.jsx(t.Paperclip,{size:14,fill:Fe?"currentColor":"none"}),Qe>0&&p.jsx("span",{className:"attachment-count-badge",children:Qe}),Be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),he&&p.jsxs("button",{type:"button",className:`action-icon-button ${_?"active sent":""} ${ye?"mandatory":""}`,onClick:re,disabled:_,title:"Send Email",children:[_?p.jsx(p.Fragment,{children:p.jsx(t.Check,{size:14})}):p.jsx(t.Mail,{size:14,fill:_?"currentColor":"none"}),ye&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ue&&p.jsxs("button",{type:"button",className:`action-icon-button ${O?"active":""} ${Ce?"mandatory":""}`,onClick:ne,title:"Raise an Issue",children:[p.jsx(t.AlertCircle,{size:14,fill:O?"currentColor":"none"}),Ce&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(xe&&le||Fe&&ce)&&p.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>M(!D),title:D?"Collapse":"Expand",children:D?p.jsx(t.ChevronUp,{size:14}):p.jsx(t.ChevronDown,{size:14})})]}),S&&le&&p.jsxs("div",{className:"notes-input-overlay",children:[p.jsx("textarea",{className:"action-notes-textarea",value:F,onChange:W,onBlur:Y,onKeyDown:J,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),p.jsxs("div",{className:"notes-input-actions",children:[p.jsx("button",{type:"button",className:"notes-save-button",onClick:X,title:"Save notes (Ctrl+Enter)",children:"Save"}),p.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{N(!1)},title:"Cancel",children:"Cancel"})]})]}),D&&p.jsxs("div",{className:"actions-content",children:[!S&&xe&&le&&p.jsx("div",{className:"notes-summary-section",children:p.jsxs("div",{className:"notes-full-text",onClick:Z,children:[p.jsx("span",{className:"notes-label",children:"Notes:"})," ",F]})}),Fe&&ce&&p.jsx("div",{className:"attachments-section",children:p.jsx(j,{attachments:U,onRemove:Ae})})]}),ce&&p.jsx("input",{ref:R,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:te,style:{display:"none"}})]}),L&&p.jsx(C,{isOpen:L,onClose:ie,onSuccess:se,issue:H,component:de?Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{label:`${(null===(B=A.basic)||void 0===B?void 0:B.label)||"Component"} - ${de.label||de.value}`,value:de.value||(null===(y=A.basic)||void 0===y?void 0:y.value)||""})}):Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic),{value:null!=i?Array.isArray(i)?i.join(", "):String(i):(null===(x=A.basic)||void 0===x?void 0:x.value)||""})}),formTemplateId:n||"",notes:F,attachments:U,workOrderNumber:d,assetNumber:f,user:m,isStandalone:g,onCreateIssue:w,onUpdateIssue:v})]})},P=({attachments:e})=>e&&0!==e.length?p.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,A)=>{var r;const n=(null===(r=e.type)||void 0===r?void 0:r.startsWith("image/"))||!1,i=n?(e=>e.data?e.data.startsWith("data:")?e.data:`data:${e.type||"image/png"};base64,${e.data}`:"")(e):"";return p.jsx("div",{className:"attachment-thumbnail",children:n&&i?p.jsx("img",{src:i,alt:e.name||`Attachment ${A+1}`}):p.jsxs("div",{className:"file-icon-placeholder",children:[p.jsx(t.Paperclip,{size:20}),p.jsx("span",{className:"file-name",children:e.name||`File ${A+1}`})]})},A)})}):null,D=({component:e})=>{var t,A;const r=(null===(t=e.basic)||void 0===t?void 0:t.notes)||"",n=(null===(A=e.basic)||void 0===A?void 0:A.attachments)||[],i=r&&r.trim().length>0,s=n&&n.length>0;return i||s?p.jsx("div",{className:"component-submission-actions",children:p.jsxs("div",{className:"actions-content",children:[i&&p.jsx("div",{className:"notes-summary-section",children:p.jsxs("div",{className:"notes-full-text",children:[p.jsx("span",{className:"notes-label",children:"Notes:"})," ",r]})}),s&&p.jsx("div",{className:"attachments-section",children:p.jsx(P,{attachments:n})})]})}):null},M=({child:e,selectedChild:A,mode:r,onChildSelect:s,onChildDelete:a,renderFormComponent:o,isOverlay:l=!1,isChildrenEditMode:c=!1,formData:u={},formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y})=>{var C,x;const F=u[e.id],Q="preview"===r&&((null===(C=e.basic)||void 0===C?void 0:C.notes)&&e.basic.notes.trim().length>0||(null===(x=e.basic)||void 0===x?void 0:x.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:U,listeners:E,setNodeRef:S,transform:N,transition:L,isDragging:I,isSorting:_}=n.useSortable({id:e.id,disabled:l||"edit"!==r}),k={transform:i.CSS.Transform.toString(N),transition:L,zIndex:I?1e3:"auto"};return p.jsxs("div",{ref:S,style:k,className:`form-component section-child ${(null==A?void 0:A.id)===e.id?"selected":""} ${I?"dragging":""} ${_?"sorting":""} ${c?"children-edit-active":""}`,onClick:()=>!I&&s(e),role:"button",tabIndex:0,children:[("edit"===r||c)&&p.jsx("div",Object.assign({className:"child-drag-handle"},E,U,{onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:p.jsx(t.GripVertical,{size:14})})),p.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===r||c)&&p.jsxs("div",{className:"component-actions child-actions",children:[p.jsx("button",{className:"btn edit-btn",onClick:t=>{t.stopPropagation(),s(e)},onMouseDown:e=>e.stopPropagation(),title:"Edit properties",children:p.jsx(t.Edit,{size:12})}),p.jsx("button",{className:"btn delete-btn",onClick:t=>a(e,t),onMouseDown:e=>e.stopPropagation(),title:"Delete component",children:p.jsx(t.Trash2,{size:12})})]}),p.jsxs("div",{className:"component-preview child-preview",children:[o(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:"test",formTemplateId:h,formValue:F,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y}),Q&&p.jsx(D,{component:e})]})]})]})},R=({id:A,properties:i,mode:s="edit",formData:a={},onValueChange:o,onSelect:l,isSelected:c=!1,className:u="",onSectionSelect:h,onChildSelect:d,onChildDelete:f,selectedChild:g,renderFormComponent:m,formTemplateId:w,onThresholdActionCompletion:v,onThresholdIssueRaised:b,onNotesChange:B,onAttachmentChange:y,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k})=>{var T,j,H,P,D,R;const[K,V]=e.useState(i.basic.collapsed),[G,z]=e.useState(!1),[q,W]=e.useState(!1),[X,Y]=e.useState(i.basic.label),[J,$]=e.useState(i.basic.description),[Z,ee]=e.useState(i.children||[]),[te,Ae]=e.useState(!1);e.useEffect(()=>{ee(i.children||[])},[i.children]),e.useEffect(()=>{Y(i.basic.label),$(i.basic.description)},[i.basic.label,i.basic.description]);const{setNodeRef:re,isOver:ne}=r.useDroppable({id:`section-${A}`,disabled:"edit"!==s}),ie=!("preview"!==s&&"test"!==s||i.children&&i.children.length>0),se=e.useCallback(e=>{Y(e),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{label:e})})})},[A,i,o]),ae=e.useCallback(e=>{$(e),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{description:e})})})},[A,i,o]),oe=e.useCallback(e=>{null==d||d(e)},[d]),le=e.useCallback((e,t)=>{t.stopPropagation();const A=Z.filter(t=>t.id!==e.id);ee(A),null==f||f(e.id)},[f,Z,A]),ce=e.useCallback(()=>{null==h||h(i),null==l||l()},[h,l,i]),ue=e.useCallback(e=>{e.stopPropagation(),"edit"===s&&Z.length>0&&Ae(!te)},[s,Z.length,te]),he=e.useCallback(e=>{e.stopPropagation(),V(!K),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{collapsed:!K})})})},[K,A,i,o]),de=m||e.useCallback(e=>{var t,A,r;const n=a[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let i=n;"number-input"===e.name&&"number"==typeof n?i=String(n):"number-input"===e.name&&null==n&&(i="");const l={id:e.id,properties:e,validationErrors:{},formValue:i,touchedFields:{},formSubmitted:!1,mode:s,onValueChange:o,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return p.jsx(F,Object.assign({},l,{properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return p.jsx(Q,Object.assign({},l,{properties:e,readonly:!1,disabled:!1}));case"select":const n=Object.assign(Object.assign({},e),{options:(null===(t=e.basic)||void 0===t?void 0:t.options)||[]});return p.jsx(U,Object.assign({},l,{properties:n,disabled:!1}));case"checkbox":const i=Object.assign(Object.assign({},e),{options:(null===(A=e.basic)||void 0===A?void 0:A.options)||[]});return p.jsx(E,Object.assign({},l,{properties:i,formValue:[],disabled:!1}));case"radio":const s=Object.assign(Object.assign({},e),{options:(null===(r=e.basic)||void 0===r?void 0:r.options)||[]});return p.jsx(S,Object.assign({},l,{properties:s,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},l,{properties:e,readonly:!1,disabled:!1}));case"signature":return p.jsx(I,Object.assign({},l,{properties:e}));case"heading":return p.jsx(O,Object.assign({},l,{properties:e}));default:return p.jsx("div",{className:"form-group",children:p.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}},[s,o,a]);if(ie)return null;const fe={backgroundColor:(null===(T=i.styles)||void 0===T?void 0:T.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(j=i.styles)||void 0===j?void 0:j.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(H=i.styles)||void 0===H?void 0:H.borderWidth)||"2px",borderRadius:(null===(P=i.styles)||void 0===P?void 0:P.borderRadius)||"8px",padding:(null===(D=i.styles)||void 0===D?void 0:D.padding)||"16px",margin:(null===(R=i.styles)||void 0===R?void 0:R.margin)||"16px 0"};return p.jsxs("div",{ref:re,className:`df-form-section ${c?"selected":""} ${ne?"drag-over":""} ${u}`,style:fe,children:[p.jsxs("div",{className:"section-header "+(te?"children-edit-mode":""),onClick:ce,onDoubleClick:ue,children:[p.jsx("div",{className:"section-header-content",children:p.jsxs("div",{className:"section-title",children:[p.jsx("span",{className:"section-toggle",title:K?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),he(e)},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),he(e))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:K?p.jsx(t.ChevronRight,{size:18}):p.jsx(t.ChevronDown,{size:18})}),"edit"===s&&G?p.jsx("input",{type:"text",value:X,onChange:e=>Y(e.target.value),onBlur:()=>{z(!1),se(X)},onKeyDown:e=>{"Enter"===e.key&&(z(!1),se(X))},className:"section-title-input",autoFocus:!0}):p.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===s&&z(!0),style:{display:"inline",margin:0},children:X||"Untitled Section"})]})}),(J||"edit"===s)&&p.jsx("div",{className:"section-description",children:"edit"===s&&q?p.jsx("textarea",{value:J,onChange:e=>$(e.target.value),onBlur:()=>{W(!1),ae(J)},onKeyDown:e=>{"Enter"===e.key&&e.ctrlKey&&(W(!1),ae(J))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):p.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===s&&W(!0),children:J||"Section description"})})]}),!K&&p.jsx("div",{className:`section-content ${ne?"drag-over":""} ${0===Z.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&ce()},children:p.jsx(n.SortableContext,{items:Z.map(e=>e.id),strategy:n.verticalListSortingStrategy,children:0===Z.length?p.jsxs("div",{className:"section-empty-state",onClick:ce,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:[p.jsx("div",{style:{fontWeight:"500",color:ne?"#3b82f6":"#374151"},children:ne?"Drop components here":"Empty Section"}),p.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):Z.map(e=>p.jsx(M,{child:e,selectedChild:g||null,mode:s,onChildSelect:oe,onChildDelete:le,renderFormComponent:de,isChildrenEditMode:te,formData:a,formTemplateId:w,onNotesChange:B,onAttachmentChange:y,onThresholdActionCompletion:v,onThresholdIssueRaised:b,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k},e.id))})})]})},K=({component:e,selectedComponent:A,mode:r,onComponentSelect:s,onComponentDelete:a,onComponentEdit:o,renderFormComponent:l,isOverlay:c=!1,formData:u={},formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B})=>{var y,C;const x=u[e.id],F="preview"===r&&((null===(y=e.basic)||void 0===y?void 0:y.notes)&&e.basic.notes.trim().length>0||(null===(C=e.basic)||void 0===C?void 0:C.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:Q,listeners:U,setNodeRef:E,transform:S,transition:N,isDragging:L,isSorting:I}=n.useSortable({id:e.id,disabled:c}),_={transform:i.CSS.Transform.toString(S),transition:N,opacity:L?.3:1,zIndex:L?1e3:"auto"};return p.jsxs("div",{ref:E,style:Object.assign(Object.assign({},_),{border:(null==A?void 0:A.id)===e.id?"2px solid #3b82f6":"1px solid var(--df-color-fb-border)",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",padding:"12px",position:"relative",minHeight:"80px",transition:"all 0.2s ease",boxShadow:(null==A?void 0:A.id)===e.id?"0 4px 12px rgba(59, 130, 246, 0.15)":"0 1px 3px rgba(0, 0, 0, 0.1)",cursor:"pointer"}),className:`form-component grid-component ${(null==A?void 0:A.id)===e.id?"selected":""} ${L?"dragging":""} ${I?"sorting":""}`,onClick:()=>!L&&s(e),role:"button",tabIndex:0,children:["edit"===r&&p.jsx("div",Object.assign({className:"component-drag-handle"},U,Q,{onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"50%",left:"4px",transform:"translateY(-50%)",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"4px",cursor:"grab",opacity:1,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:p.jsx(t.GripVertical,{size:12,color:"var(--df-color-text-light)"})})),p.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===r?"24px":"0",paddingLeft:"edit"===r?"28px":"0",minHeight:"60px"},children:[l(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:"test",formTemplateId:h,formValue:x,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B}),F&&p.jsx(D,{component:e})]}),"edit"===r&&p.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[o&&p.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),o(e)},type:"button",title:"Edit Component",style:{padding:"4px",backgroundColor:"#3b82f6",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#3b82f6"},children:p.jsx(t.Edit,{size:12})}),p.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),a(e,t)},type:"button",title:"Delete Component",style:{padding:"4px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#ef4444"},children:p.jsx(t.Trash2,{size:12})})]})]})},V=({gridComponents:e,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:a,selectedComponent:o,renderFormComponent:l,gridId:c,formData:u={},formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B})=>{const{setNodeRef:y,isOver:C}=r.useDroppable({id:`grid-drop-zone-${c}`,disabled:"edit"!==t});return p.jsx("div",{ref:y,className:"grid-drop-zone",style:{border:C?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:C?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?p.jsxs(p.Fragment,{children:[p.jsx(n.SortableContext,{items:e.map(e=>e.id),strategy:n.horizontalListSortingStrategy,children:p.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:e.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:e.map(e=>p.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:p.jsx(K,{component:e,selectedComponent:o,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:s,onComponentUpdate:a,renderFormComponent:l,formData:u,formTemplateId:h,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,onCreateIssue:b,onUpdateIssue:B})},e.id))})}),p.jsx("div",{style:{border:C?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:C?"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:C?p.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):p.jsx("span",{children:"+ Drop more components here"})})]}):p.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:[p.jsx("div",{style:{fontWeight:"500",color:C?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:C?"Drop components here":"Empty DataGrid"}),p.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},G=({templateComponents:e,dataEntries:t,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:g,onThresholdIssueRaised:m,onNotesChange:w,onAttachmentChange:v,datagridId:b="",workOrderNumber:B,assetNumber:y,onCreateIssue:C,onUpdateIssue:x})=>0===e.length?p.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?p.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:[p.jsx("div",{style:{position:"absolute",top:"8px",right:"8px",zIndex:10,fontSize:"12px",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",padding:"4px 8px",borderRadius:"4px",border:"1px solid var(--df-color-fb-border)",opacity:e.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),p.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:[p.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*e.length+"px"},children:e.map((t,A)=>{var r;return p.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:A<e.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(null===(r=t.basic)||void 0===r?void 0:r.label)||`Column ${A+1}`},`header-${t.id}`)})}),t.length>0?t.map((s,o)=>p.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:o<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:o%2==0?"var(--df-color-fb-container)":"var(--df-color-fb-bg)",position:"relative",minWidth:150*e.length+"px",isolation:"isolate"},children:[e.map((t,i)=>{var a,l,c,u,h,F,Q;let U=null===(a=s.components)||void 0===a?void 0:a[i];const E=`${t.id||`component-${i}`}-entry-${b}-${o}-${i}`;return U=U?U.id!==E?Object.assign(Object.assign({},U),{id:E,basic:Object.assign(Object.assign({},U.basic),{showLabel:!1})}):Object.assign(Object.assign({},U),{id:U.id,basic:Object.assign(Object.assign({},U.basic),{showLabel:!1})}):Object.assign(Object.assign({},t),{id:E,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),p.jsxs("div",{style:{padding:"12px 16px",borderRight:i<e.length-1?"1px solid var(--df-color-fb-border)":"none",minHeight:"60px",minWidth:"150px",display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center",overflow:"visible",position:"relative",zIndex:1},children:[p.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:r?r(U,!0):A(U,!0)}),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(U.name)&&p.jsxs("div",{style:{marginTop:"8px",width:"100%"},children:[p.jsx(H,{component:U,mode:"test",formTemplateId:f,formValue:d[U.id],onThresholdActionCompletion:g,onThresholdIssueRaised:m,onNotesChange:w?e=>w(U.id,e):void 0,onAttachmentChange:v?e=>v(U.id,e):void 0,notes:(null===(l=U.basic)||void 0===l?void 0:l.notes)||(null===(c=d[U.id])||void 0===c?void 0:c.notes),attachments:(null===(u=U.basic)||void 0===u?void 0:u.attachments)||(null===(h=d[U.id])||void 0===h?void 0:h.attachments),workOrderNumber:B,assetNumber:y,onCreateIssue:C,onUpdateIssue:x}),"preview"===n&&((null===(F=U.basic)||void 0===F?void 0:F.notes)||(null===(Q=U.basic)||void 0===Q?void 0:Q.attachments))&&p.jsx(D,{component:U})]})]},`${s.id}-${i}`)}),i&&t.length>l&&p.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=l)&&h)try{h(o)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=l,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:t.length<=l?"#f3f4f6":"#ef4444",color:t.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.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:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#ef4444")},children:p.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},s.id)):p.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&&p.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:p.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=o)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=o,style:{padding:"8px 16px",backgroundColor:t.length>=o?"#f3f4f6":"#10b981",color:t.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#10b981")},children:[p.jsx("span",{style:{fontSize:"16px"},children:"+"}),s]})})]}):p.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[t.length>0?t.map((s,o)=>p.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:[p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[p.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",o+1]}),i&&t.length>1&&p.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=l)&&h)try{h(o)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=l,style:{padding:"4px 8px",backgroundColor:t.length<=l?"#f3f4f6":"#ef4444",color:t.length<=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.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:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>l&&(e.currentTarget.style.backgroundColor="#ef4444")},children:p.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),p.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:e.map((e,t)=>{var i,a,l;let c=null===(i=s.components)||void 0===i?void 0:i[t];const u=`${e.id||`component-${t}`}-entry-${b}-${o}-${t}`;return c||(c=null===(a=s.components)||void 0===a?void 0:a.find(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)})),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({},e),{id:u,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})}),p.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[p.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:(null===(l=e.basic)||void 0===l?void 0:l.label)||`Field ${t+1}`}),p.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)&&p.jsx(H,{component:c,mode:"test",formTemplateId:f,formValue:d[c.id],onThresholdActionCompletion:g,onThresholdIssueRaised:m,onNotesChange:w?e=>w(c.id,e):void 0,onAttachmentChange:v?e=>v(c.id,e):void 0}),"preview"===n&&(()=>{var e,t;return(null===(e=c.basic)||void 0===e?void 0:e.notes)&&c.basic.notes.trim().length>0||(null===(t=c.basic)||void 0===t?void 0:t.attachments)&&Array.isArray(c.basic.attachments)&&c.basic.attachments.length>0?p.jsx(D,{component:c}):null})()]})]},`${s.id}-${t}`)})})]},s.id)):p.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&&p.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:p.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=o)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=o,style:{padding:"8px 16px",backgroundColor:t.length>=o?"#f3f4f6":"#10b981",color:t.length>=o?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=o?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<o&&(e.currentTarget.style.backgroundColor="#10b981")},children:[p.jsx("span",{children:"+"}),s]})})]}),z=({id:A,properties:r,mode:n="edit",formData:i={},validationErrors:s={},touchedFields:a={},formSubmitted:o=!1,onValueChange:l,onSelect:c,isSelected:u=!1,className:h="",onDataGridSelect:d,onComponentSelect:f,onComponentDelete:g,onComponentEdit:m,onComponentUpdate:w,selectedComponent:v,renderFormComponent:b,onEntryAdd:B,onEntryRemove:y,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,workOrderNumber:j,assetNumber:H,onCreateIssue:P,onUpdateIssue:D})=>{var M,R,K,z,q,W,X,Y,J,$,Z,ee;const[te,Ae]=e.useState(!1),re=e.useRef(!1);let ne=r.templateComponents||[];const ie=r.entries||[];0===ne.length&&ie.length>0&&ie[0].components&&(ne=ie[0].components.map(e=>{var t;return Object.assign(Object.assign({},e),{id:(null===(t=e.id)||void 0===t?void 0:t.replace(/-entry-\d+$/,""))||e.id,basic:Object.assign(Object.assign({},e.basic),{showLabel:!0})})})),e.useEffect(()=>{if("edit"===n&&!r.templateComponents&&l&&re.current){const e=Object.assign(Object.assign({},r),{templateComponents:[]});JSON.stringify(e)!==JSON.stringify(r)&&l({id:A,value:e})}re.current=!0},[r.templateComponents,A,l,r,n]),e.useEffect(()=>{if(ne.length>0){if("test"===n&&0===ie.length&&re.current){const e={id:`entry-${A}-0`,index:0,components:ne.map((e,t)=>{const r=e.id||`component-${t}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${A}-0-${t}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(l){const t=Object.assign(Object.assign({},r),{entries:[e]});JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t})}return}if("edit"!==n||!re.current)return;const e=ie.some(e=>{var t;return null===(t=e.components)||void 0===t?void 0:t.some((t,A)=>{var r;const n=`${null===(r=ne[A])||void 0===r?void 0:r.id}-entry-${e.index}-${A}`;return t.id!==n})});if(e&&l){const e=ie.map(e=>{var t;return Object.assign(Object.assign({},e),{components:(null===(t=e.components)||void 0===t?void 0:t.map((t,A)=>{var r;return Object.assign(Object.assign({},t),{id:`${null===(r=ne[A])||void 0===r?void 0:r.id}-entry-${e.index}-${A}`})}))||[]})}),t=Object.assign(Object.assign({},r),{entries:e});return void(JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t}))}if(0===ie.length&&"edit"===n){const e={id:`entry-${A}-0`,index:0,components:ne.map((e,t)=>{const r=e.id||`component-${t}`;return Object.assign(Object.assign({},e),{id:`${r}-entry-${A}-0-${t}`,basic:Object.assign(Object.assign({},e.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}),styles:{}};if(l){const t=Object.assign(Object.assign({},r),{entries:[e]});JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t})}}else if(ie.length>0){const e=ie.some(e=>ne.some((t,A)=>{var r,n,i,s,a,o,l,c,u,h,d;const f=null===(r=e.components)||void 0===r?void 0:r[A];if(!f)return!0;const p=`${t.id}-entry-${e.index}-${A}`,g=f.id===p,m=JSON.stringify(null===(n=f.basic)||void 0===n?void 0:n.options)!==JSON.stringify(null===(i=t.basic)||void 0===i?void 0:i.options)||(null===(s=f.basic)||void 0===s?void 0:s.placeholder)!==(null===(a=t.basic)||void 0===a?void 0:a.placeholder)||(null===(o=f.basic)||void 0===o?void 0:o.defaultValue)!==(null===(l=t.basic)||void 0===l?void 0:l.defaultValue)||(null===(c=f.basic)||void 0===c?void 0:c.label)!==(null===(u=t.basic)||void 0===u?void 0:u.label)||(null===(h=f.validation)||void 0===h?void 0:h.required)!==(null===(d=t.validation)||void 0===d?void 0:d.required);return!g||m}));if(e&&l){const e=ie.map(e=>{const t=ne.map((t,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(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)}));const a=`${t.id||`component-${r}`}-entry-${A}-${e.index}-${r}`;if(s){return Object.assign(Object.assign({},t),{id:a,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})}return Object.assign(Object.assign({},t),{id:a,basic:Object.assign(Object.assign({},t.basic),{showLabel:!1,defaultValue:void 0,value:void 0})})});return Object.assign(Object.assign({},e),{components:t})}),t=Object.assign(Object.assign({},r),{entries:e});JSON.stringify(t)!==JSON.stringify(r)&&l({id:A,value:t})}}}},[ne,ie,A,l,r,n,r.templateComponents]);const se=e.useCallback(e=>{e.stopPropagation(),null==c||c(),null==d||d(r)},[c,d,r]),ae=e.useCallback((e,t)=>{t.stopPropagation(),g&&g(e,t);const n=ne.filter(t=>t.id!==e.id),i=ie.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))}))||[]})});l&&l({id:A,value:Object.assign(Object.assign({},r),{templateComponents:n,entries:i})})},[g,r,l,A,ne,ie]),oe=e.useCallback((e,t)=>{w&&w(e,t);const n=ne.map(A=>A.id===e?Object.assign(Object.assign({},A),t):A);l&&l({id:A,value:Object.assign(Object.assign({},r),{templateComponents:n})})},[w,r,l,A,ne]),le=e.useCallback(e=>{"test"===n&&l&&l({id:e.id,value:e.value})},[l]),ce=e.useCallback(()=>{const e=r.entries||[],t=e.length,n={id:`entry-${A}-${t}`,index:t,components:ne.map((e,r)=>{const n=`${e.id||`component-${r}`}-entry-${A}-${t}-${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:{}},i=[...e,n];l&&l({id:A,value:Object.assign(Object.assign({},r),{entries:i})}),null==B||B()},[r,l,A,B,ne]),ue=e.useCallback(e=>{const t=r.entries.filter((t,A)=>A!==e).map((e,t)=>Object.assign(Object.assign({},e),{index:t,id:`entry-${A}-${t}`}));l&&l({id:A,value:Object.assign(Object.assign({},r),{entries:t})})},[r,l,A,y]),he=e.useCallback((e,t=!1)=>{var A,r,l;const c=i[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let u=c;"number-input"===e.name&&"number"==typeof c?u=String(c):"number-input"===e.name&&null==c&&(u="");const h={id:e.id,properties:e,validationErrors:s||{},formValue:u,touchedFields:a||{},formSubmitted:o||!1,mode:n,hideLabel:t,onValueChange:le,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return p.jsx(F,Object.assign({},h,{properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1,hideLabel:t}));case"textarea":return p.jsx(Q,Object.assign({},h,{properties:e,readonly:!1,disabled:!1,hideLabel:t}));case"select":const n=Object.assign(Object.assign({},e),{options:(null===(A=e.basic)||void 0===A?void 0:A.options)||[]});return p.jsx(U,Object.assign({},h,{properties:n,disabled:!1,hideLabel:t}));case"checkbox":const i=Object.assign(Object.assign({},e),{options:(null===(r=e.basic)||void 0===r?void 0:r.options)||[]});return p.jsx(E,Object.assign({},h,{properties:i,formValue:[],disabled:!1,hideLabel:t}));case"radio":const s=Object.assign(Object.assign({},e),{options:(null===(l=e.basic)||void 0===l?void 0:l.options)||[]});return p.jsx(S,Object.assign({},h,{properties:s,readonly:!1,disabled:!1,hideLabel:t}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},h,{properties:e,readonly:!1,disabled:!1,hideLabel:t}));case"signature":return p.jsx(I,Object.assign({},h,{properties:e,hideLabel:t}));case"heading":return p.jsx(O,Object.assign({},h,{properties:e,hideLabel:t}));case"instructions":return p.jsx(T,Object.assign({},h,{properties:e,hideLabel:t}));default:return p.jsxs("div",{className:"unknown-component",children:["Unknown component: ",e.name]})}},[n,le,i,s,a,o]),de={backgroundColor:r.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:r.styles.borderColor||"var(--df-color-fb-border)",borderWidth:r.styles.borderWidth||"2px",borderRadius:r.styles.borderRadius||"8px",padding:r.styles.padding||"16px",margin:r.styles.margin||"16px 0"};return p.jsxs("div",{className:`form-group df-form-datagrid ${u?"selected":""} ${h}`,onClick:se,style:de,children:[p.jsx("div",{className:"grid-header",children:p.jsx("div",{className:"grid-title",onClick:e=>{e.stopPropagation(),Ae(!te),null==l||l({id:A,value:Object.assign(Object.assign({},r),{basic:Object.assign(Object.assign({},r.basic),{collapsed:!te})})})},children:p.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[te?p.jsx(t.ChevronRight,{size:16}):p.jsx(t.ChevronDown,{size:16}),p.jsx(t.Grid,{size:16}),p.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:r.basic.label}),r.validation.required&&p.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),r.basic.description&&!te&&p.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:r.basic.description}),!te&&p.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===n?p.jsx(V,{gridComponents:ne,mode:n,onComponentSelect:f||(()=>{}),onComponentDelete:ae,onComponentEdit:m,onComponentUpdate:oe,selectedComponent:v||null,renderFormComponent:b||he,gridId:A,formData:i,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,workOrderNumber:j,assetNumber:H,onCreateIssue:P,onUpdateIssue:D}):p.jsx(G,{templateComponents:ne,dataEntries:ie,renderFormComponent:b||he,mode:n,allowAddRemoveEntries:null===(R=null===(M=r.datagrid)||void 0===M?void 0:M.allowAddRemoveEntries)||void 0===R||R,addAnotherText:null!==(z=null===(K=r.datagrid)||void 0===K?void 0:K.addAnotherText)&&void 0!==z?z:"Add Entry",removeText:null!==(W=null===(q=r.datagrid)||void 0===q?void 0:q.removeText)&&void 0!==W?W:"Remove",maxEntries:null!==(Y=null===(X=r.datagrid)||void 0===X?void 0:X.maxEntries)&&void 0!==Y?Y:10,minEntries:null!==($=null===(J=r.datagrid)||void 0===J?void 0:J.minEntries)&&void 0!==$?$:1,displayAsGrid:null===(ee=null===(Z=r.datagrid)||void 0===Z?void 0:Z.displayAsGrid)||void 0===ee||ee,onAddEntry:B||ce,onRemoveEntry:y||ue,formData:i,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,datagridId:A,workOrderNumber:j,assetNumber:H,onCreateIssue:P,onUpdateIssue:D})})]})},q=e.lazy(()=>Promise.resolve().then(function(){return Z})),W=e=>e.id?e:Object.assign(Object.assign({},e),{id:s.v4()}),X=({component:e,mode:t,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,g;const m=r[e.id],w="preview"===t&&((null===(f=e.basic)||void 0===f?void 0:f.notes)&&e.basic.notes.trim().length>0||(null===(g=e.basic)||void 0===g?void 0:g.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return p.jsxs("div",{className:"simple-table-component",children:[A(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:"test",formTemplateId:n,formValue:m,onThresholdActionCompletion:i,onThresholdIssueRaised:s,onNotesChange:a?t=>a(e.id,t):void 0,onAttachmentChange:o?t=>o(e.id,t):void 0,workOrderNumber:l,assetNumber:c,user:u,onCreateIssue:h,onUpdateIssue:d}),w&&p.jsx(D,{component:e})]})},Y=({component:e,selectedComponent:A,mode:r,onComponentSelect:s,onComponentDelete:a,onComponentEdit:o,renderFormComponent:l,isOverlay:c=!1})=>{const{attributes:u,listeners:h,setNodeRef:d,transform:f,transition:g,isDragging:m,isSorting:w}=n.useSortable({id:e.id,disabled:c}),v={transform:i.CSS.Transform.toString(f),transition:g,opacity:m?.3:1,zIndex:m?1e3:"auto"};return p.jsxs("div",{ref:d,style:v,className:`form-component table-component ${(null==A?void 0:A.id)===e.id?"selected":""} ${m?"dragging":""} ${w?"sorting":""}`,onClick:()=>!m&&s(e),role:"button",tabIndex:0,children:["edit"===r&&p.jsx("div",Object.assign({className:"component-drag-handle"},h,u,{onClick:e=>e.stopPropagation(),style:{opacity:1},children:p.jsx(t.GripVertical,{size:14})})),p.jsx("div",{className:"component-content",children:l(e)}),"edit"===r&&p.jsxs("div",{className:"component-actions",style:{opacity:1},children:[o&&p.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),o(e)},type:"button",title:"Edit Component",children:p.jsx(t.Edit,{size:12})}),p.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),a(e,t)},type:"button",title:"Delete Component",children:p.jsx(t.Trash2,{size:12})})]})]})},J=({cell:e,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:a,selectedComponent:o,renderFormComponent:l,formData:c={},formTemplateId:u,onThresholdActionCompletion:h,onThresholdIssueRaised:d,tableId:f,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y})=>{var C,x,F,Q,U;const E=`table-cell-${f}-${e.row}-${e.column}`,{setNodeRef:S,isOver:N}=r.useDroppable({id:E,disabled:"edit"!==t,data:{type:"table-cell",tableId:f,cell:e,row:e.row,column:e.column}}),L=Object.assign(Object.assign({},e.styles),{backgroundColor:N?"var(--df-color-primary-light)":(null===(C=e.styles)||void 0===C?void 0:C.backgroundColor)||"transparent",minHeight:(null===(x=e.styles)||void 0===x?void 0:x.minHeight)||"preview"===t||"test"===t?"40px":"60px",padding:(null===(F=e.styles)||void 0===F||F.padding,"8px"),border:"preview"===t||"test"===t?"none":N?"2px dashed var(--df-color-primary)":(null===(Q=e.styles)||void 0===Q?void 0:Q.borderColor)?`1px solid ${e.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===t||"test"===t?"0":"4px",position:"relative",verticalAlign:(null===(U=e.styles)||void 0===U?void 0:U.verticalAlign)||"top"});return p.jsx("td",{ref:S,style:L,className:"table-cell "+(N?"drag-over":""),children:p.jsx("div",{className:"cell-content",children:e.components&&Array.isArray(e.components)&&e.components.length>0?"edit"===t?p.jsx(n.SortableContext,{items:e.components.map(e=>e.id||s.v4()),strategy:n.verticalListSortingStrategy,children:e.components.map(e=>{const r=W(e);return p.jsx(Y,{component:r,selectedComponent:o,mode:t,onComponentSelect:A,onComponentDelete:i,onComponentEdit:a,renderFormComponent:l},r.id)})}):e.components.map(e=>{const A=e.id?e:W(e);return p.jsx(X,{component:A,mode:t,renderFormComponent:l,formData:c,formTemplateId:u,onThresholdActionCompletion:h,onThresholdIssueRaised:d,onNotesChange:g,onAttachmentChange:m,workOrderNumber:w,assetNumber:v,user:b,onCreateIssue:B,onUpdateIssue:y},A.id)}):"edit"===t?p.jsx("div",{className:"empty-cell-placeholder",children:p.jsxs("div",{className:"cell-info",children:[p.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),p.jsxs("span",{className:"cell-coordinates",children:["Cell (",e.row+1,", ",e.column+1,")"]})]})}):p.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},$=({id:A,properties:r,mode:n="edit",formData:i={},validationErrors:s={},touchedFields:a={},formSubmitted:o=!1,onValueChange:l,onSelect:c,isSelected:u=!1,className:h="",onTableSelect:d,onComponentSelect:f,onComponentDelete:g,onComponentEdit:m,selectedComponent:w,renderFormComponent:v,formTemplateId:b,onThresholdActionCompletion:B,onThresholdIssueRaised:y,onNotesChange:C,onAttachmentChange:x,workOrderNumber:N,assetNumber:_,user:k,onCreateIssue:T,onUpdateIssue:j})=>{var H,P,D,M,R,K,V,G,z,q,X,Y,$,Z,ee,te,Ae,re;const[ne,ie]=e.useState(!1),se=(null===(H=r.cells)||void 0===H?void 0:H.some(e=>e.some(e=>e.components&&e.components.length>0)))||!1;e.useEffect(()=>{},[null===(P=r.table)||void 0===P?void 0:P.rows,null===(D=r.table)||void 0===D?void 0:D.columns,null===(M=r.basic)||void 0===M?void 0:M.rows,null===(R=r.basic)||void 0===R?void 0:R.columns,r.cells,A,l]);const ae=e.useCallback(e=>{e.stopPropagation(),null==c||c(),null==d||d(r)},[c,d,r]),oe=e.useCallback((e,t)=>{t.stopPropagation();const n=r.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}));l&&l({id:A,value:Object.assign(Object.assign({},r),{cells:n})})},[g,r,l,A]),le=e.useMemo(()=>r.cells?r.cells.map((e,t)=>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-${A}-row-${t}-cell-${r}-comp-${n}`;return Object.assign(Object.assign({},e),{id:i})}):[]}))):[],[r.cells,A]),ce=v||e.useCallback(e=>{var t,A,r;const s=e.id?e:W(e),a=i[s.id]||"defaultValue"in s.basic&&s.basic.defaultValue||"";let o=a;"number-input"===s.name&&"number"==typeof a?o=String(a):"number-input"===s.name&&null==a&&(o="");const c={id:s.id,properties:s,validationErrors:{},formValue:o,touchedFields:{},formSubmitted:!1,mode:n,onValueChange:e=>{null==l||l(e)},onBlur:()=>{},onFocus:()=>{}};switch(s.name){case"text-input":case"email-input":case"number-input":return p.jsx(F,Object.assign({},c,{properties:s,inputType:"text-input"===s.name?"text":"number-input"===s.name?"number":"email",readonly:!1,disabled:!1}));case"textarea":return p.jsx(Q,Object.assign({},c,{properties:s,readonly:!1,disabled:!1}));case"select":const e=Object.assign(Object.assign({},s),{options:(null===(t=s.basic)||void 0===t?void 0:t.options)||[]});return p.jsx(U,Object.assign({},c,{properties:e,disabled:!1}));case"checkbox":const n=Object.assign(Object.assign({},s),{options:(null===(A=s.basic)||void 0===A?void 0:A.options)||[]});return p.jsx(E,Object.assign({},c,{properties:n,formValue:[],disabled:!1}));case"radio":const i=Object.assign(Object.assign({},s),{options:(null===(r=s.basic)||void 0===r?void 0:r.options)||[]});return p.jsx(S,Object.assign({},c,{properties:i,readonly:!1,disabled:!1}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},c,{properties:s,readonly:!1,disabled:!1}));case"signature":return p.jsx(I,Object.assign({},c,{properties:s}));case"heading":return p.jsx(O,Object.assign({},c,{properties:s}));default:return p.jsxs("div",{className:"unknown-component",children:["Unknown component: ",s.name]})}},[v,n,i,l]),ue={backgroundColor:(null===(K=r.styles)||void 0===K?void 0:K.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(V=r.styles)||void 0===V?void 0:V.borderColor)||"var(--df-color-fb-border)",borderWidth:(null===(G=r.styles)||void 0===G?void 0:G.borderWidth)||"2px",borderRadius:(null===(z=r.styles)||void 0===z?void 0:z.borderRadius)||"8px",padding:(null===(q=r.styles)||void 0===q?void 0:q.padding)||"16px",margin:(null===(X=r.styles)||void 0===X?void 0:X.margin)||"16px 0"},he={width:"100%",minWidth:"600px",borderCollapse:"preview"===n||"test"===n?"separate":"collapse",tableLayout:"fixed",border:"preview"===n||"test"===n?"1px solid var(--df-color-fb-border)":"none"};return se||"preview"!==n?p.jsxs("div",{className:`form-group df-form-table ${u?"selected":""} ${"preview"===n?"preview-mode":"test"===n?"test-mode":""} ${h}`,onClick:ae,style:ue,children:[p.jsx("div",{className:"table-header",children:p.jsx("div",{className:"table-title",onClick:e=>{e.stopPropagation(),ie(!ne),null==l||l({id:A,value:Object.assign(Object.assign({},r),{basic:Object.assign(Object.assign({},r.basic||{}),{collapsed:!ne})})})},children:p.jsxs("div",{className:"title-content",children:[ne?p.jsx(t.ChevronRight,{size:16}):p.jsx(t.ChevronDown,{size:16}),p.jsx(t.Table,{size:16}),p.jsx("span",{className:"table-label",children:(null===(Y=r.basic)||void 0===Y?void 0:Y.label)||"Table"}),(null===($=r.validation)||void 0===$?void 0:$.required)&&p.jsx("span",{className:"required-indicator",children:"*"})]})})}),(null===(Z=r.basic)||void 0===Z?void 0:Z.description)&&!ne&&p.jsx("div",{className:"table-description",children:r.basic.description}),!ne&&p.jsxs("div",{className:"table-content",children:[null,p.jsxs("table",{style:he,children:[(null===(ee=r.table)||void 0===ee?void 0:ee.displayAsTable)&&("edit"===n||(null===(te=r.table)||void 0===te?void 0:te.showColumns))&&p.jsx("thead",{children:p.jsx("tr",{className:"table-header-row",children:Array.from({length:(null===(Ae=r.table)||void 0===Ae?void 0:Ae.columns)||(null===(re=r.basic)||void 0===re?void 0:re.columns)||3},(e,t)=>{var A,n;const i=((null===(n=null===(A=r.table)||void 0===A?void 0:A.columnNames)||void 0===n?void 0:n.split(",").map(e=>e.trim()))||[])[t]||`Column ${t+1}`;return p.jsx("th",{className:"table-header-cell",style:{backgroundColor:(r.styles.headerBackgroundColor,"var(--df-color-fb-container)"),color:r.styles.headerTextColor||"var(--df-color-text-dark)",padding:"12px",border:"1px solid var(--df-color-fb-border)",fontWeight:"600",fontSize:"14px",textAlign:"center"},children:i},`header-${t}`)})})}),p.jsx("tbody",{children:le.map((e,t)=>p.jsx("tr",{className:"table-row",children:e.map(e=>p.jsx(J,{cell:e,mode:n,onComponentSelect:f||(()=>{}),onComponentDelete:oe,onComponentEdit:m,selectedComponent:w||null,renderFormComponent:ce,formData:i,formTemplateId:b,onThresholdActionCompletion:B,onThresholdIssueRaised:y,tableId:A,onNotesChange:C,onAttachmentChange:x,workOrderNumber:N,assetNumber:_,user:k,onCreateIssue:T,onUpdateIssue:j},e.id))},t))})]})]})]}):null};var Z=Object.freeze({__proto__:null,DfFormTable:$,default:$});const ee={page:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',padding:"30px",backgroundColor:"#ffffff",color:"#000000",lineHeight:"1.4"},header:{marginBottom:"30px",paddingBottom:"15px",borderBottom:"2px solid #303992",display:"flex",justifyContent:"space-between",alignItems:"flex-end"},title:{margin:"0 0 5px 0",fontSize:"24px",fontWeight:"bold",color:"#303992"},description:{margin:"0",fontSize:"14px",color:"#666666"},submittedBy:{fontSize:"14px",color:"#333",textAlign:"right",whiteSpace:"nowrap",marginBottom:"2px"},formGroup:{marginBottom:"20px",breakInside:"avoid"},label:{fontWeight:"400",display:"block",marginBottom:"8px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",fontColor:"var(--df-color-text-dark)"},labelLeft:{fontWeight:"400",display:"block",marginRight:"10px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",width:"60%",fontColor:"var(--df-color-text-dark)"},valueContainer:{border:"1px solid #e2e8f0",borderRadius:"6px",padding:"8px 12px",backgroundColor:"#ffffff",minHeight:"20px",fontSize:"14px",flex:1},value:{fontSize:"14px",color:"#000000"},gridRow:{display:"flex",flexWrap:"wrap",gap:"16px",marginBottom:"20px"},gridCol:e=>({flex:`0 0 calc(${e/12*100}% - 8px)`,minWidth:"0"}),img:{maxWidth:"100%",maxHeight:"300px",border:"1px solid #ddd",borderRadius:"4px",display:"block",marginTop:"5px"},table:{width:"100%",borderCollapse:"collapse",border:"1px solid #ddd",marginTop:"10px",tableLayout:"fixed"},th:{border:"1px solid #ddd",padding:"8px",backgroundColor:"#f5f5f5",fontWeight:"bold",textAlign:"left",fontSize:"13px"},td:{border:"1px solid #ddd",padding:"8px",fontSize:"13px",verticalAlign:"top"},section:{marginBottom:"25px",breakInside:"avoid"},sectionHeader:{fontSize:"18px",marginBottom:"15px",display:"block",fontWeight:"600"},sectionChildren:{marginLeft:"20px",paddingLeft:"20px",borderLeft:"2px solid #3b82f6",marginTop:"15px"},notesSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",fontSize:"13px",boxSizing:"border-box"},notesLabel:{fontWeight:"bold",color:"#303992",marginRight:"5px"},attachmentsSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",display:"flex",flexWrap:"wrap",gap:"10px",boxSizing:"border-box"},attachmentThumbnail:{width:"60px",height:"60px",border:"1px solid #e5e7eb",borderRadius:"4px",overflow:"hidden",backgroundColor:"#fff",display:"flex",alignItems:"center",justifyContent:"center"},attachmentImg:{width:"100%",height:"100%",objectFit:"cover"},segmentContainer:{display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center"},segmentButton:{display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",borderRadius:"6px",border:"1px solid #e0e0e0",backgroundColor:"#ffffff",fontSize:"10px",fontWeight:600,minWidth:"30px",color:"#666"},segmentIcon:{marginRight:"4px",fontSize:"9px",fontWeight:"bold",display:"inline-block",lineHeight:"1"},checkboxItem:{display:"flex",alignItems:"center",padding:"10px 14px",backgroundColor:"#f8f9fa",borderRadius:"6px",marginBottom:"8px",width:"100%",boxSizing:"border-box"}},te=e=>{if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.startsWith("data:image")||t.startsWith("iVBORw0KGgo")||t.startsWith("/9j/4AAQ")||t.startsWith("UklGR")||t.startsWith("R0lGOD")},Ae=(e,t)=>{if(!e)return"";const A=e.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}`:t&&t.startsWith("image/")?`data:${t};base64,${A}`:A},re=e=>{if(void 0!==(null==e?void 0:e.icon)&&null!==(null==e?void 0:e.icon))return e.icon;return"pass"===(e=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"})((null==e?void 0:e.value)||e)?"✓":"×"},ne=({component:e})=>{var t,A;const r=(null===(t=e.basic)||void 0===t?void 0:t.notes)||"",n=(null===(A=e.basic)||void 0===A?void 0:A.attachments)||[];return r.trim()||0!==n.length?p.jsxs("div",{style:{marginTop:"5px"},children:[r.trim().length>0&&p.jsxs("div",{style:ee.notesSection,children:[p.jsx("span",{style:ee.notesLabel,children:"Notes:"}),r]}),n.length>0&&p.jsx("div",{style:ee.attachmentsSection,children:n.map((e,t)=>{var A;const r=!(!e.data&&!e.url),n=((null===(A=e.type)||void 0===A?void 0:A.startsWith("image/"))||te(e.data||e.url||""))&&r?Ae(e.data||e.url||"",e.type):null;return p.jsx("div",{style:ee.attachmentThumbnail,children:n?p.jsx("img",{src:n,alt:e.name||"Attachment",style:ee.attachmentImg}):p.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},t)})})]}):null},ie=({component:e})=>{var t,A,r,n,i,s,a;const o=void 0!==(null===(t=e.basic)||void 0===t?void 0:t.value)?e.basic.value:null===(A=e.basic)||void 0===A?void 0:A.defaultValue,{name:l}=e;if("signature"===l)return o&&te(o)?p.jsx("div",{style:{marginTop:"5px"},children:p.jsx("img",{src:Ae(o),alt:"Signature",style:Object.assign(Object.assign({},ee.img),{maxHeight:"100px",width:"auto"})})}):p.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===l){const t=(null===(r=e.basic)||void 0===r?void 0:r.options)||[],A=Array.isArray(o)?o:[o];return p.jsx("div",{style:{marginTop:"5px",width:"100%"},children:t.map((e,t)=>{const r=A.includes(e.value);return p.jsxs("div",{style:ee.checkboxItem,children:[p.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&&p.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),p.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("radio"===l){const t=(null===(n=e.basic)||void 0===n?void 0:n.options)||[];return p.jsx("div",{style:{marginTop:"5px",width:"100%"},children:t.map((e,t)=>{const A=o===e.value;return p.jsxs("div",{style:ee.checkboxItem,children:[p.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&&p.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),p.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("segment"===l){const t=(null===(i=e.basic)||void 0===i?void 0:i.options)||[],A=o;return p.jsx("div",{style:ee.segmentContainer,children:t.map((e,t)=>{const r=A===e.value,n=re(e),i=e.color||"#666";let s=Object.assign({},ee.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}),p.jsxs("div",{style:s,children:[p.jsx("span",{style:ee.segmentIcon,children:n}),p.jsx("span",{children:e.value})]},t)})})}if("file"===l){const e=(Array.isArray(o)?o:o?[o]:[]).filter(e=>{const t=!(!e.data&&!e.url),A=e.type&&e.type.startsWith("image/"),r=t&&te(e.data||e.url);return A||r});return e.length>0?p.jsx("div",{style:{marginTop:"10px"},children:e.map((e,t)=>{const A=Ae(e.data||e.url,e.type);return A?p.jsx("img",{src:A,alt:e.name||"File",style:Object.assign(Object.assign({},ee.img),{marginBottom:"10px"})},t):null})}):p.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===l){if(o&&"object"==typeof o){const e=o;return p.jsxs("div",{style:{fontSize:"14px"},children:[e.placeName&&p.jsxs("div",{style:{marginBottom:"4px"},children:[p.jsx("strong",{children:"Place:"})," ",e.placeName]}),(e.city||e.country)&&p.jsxs("div",{style:{marginBottom:"4px"},children:[p.jsx("strong",{children:"Address:"})," ",[e.city,e.country].filter(Boolean).join(", ")]}),e.latitude&&e.longitude&&p.jsxs("div",{style:{marginBottom:"4px"},children:[p.jsx("strong",{children:"Coordinates:"})," ",e.latitude.toFixed(6),", ",e.longitude.toFixed(6)]}),e.timestamp&&p.jsxs("div",{children:[p.jsx("strong",{children:"Captured:"})," ",(B(e.timestamp)||new Date).toLocaleString()]})]})}return p.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===l){const t=(null===(s=e.basic)||void 0===s?void 0:s.instructions)||[],A=(null===(a=e.validation)||void 0===a?void 0:a.listStyle)||"numbers";if(!Array.isArray(t)||0===t.length)return p.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const r=()=>p.jsx("div",{dangerouslySetInnerHTML:{__html:t.join("")}});return"numbers"===A?p.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:p.jsx(r,{})}):"bullets"===A?p.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:p.jsx(r,{})}):p.jsx("div",{style:{margin:"10px 0"},children:p.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 e="textarea"===l;return p.jsx("div",{style:Object.assign(Object.assign({},ee.valueContainer),e?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}),children:p.jsx("div",{style:ee.value,children:c})})}return p.jsx("div",{style:ee.value,children:c})},se=({component:e})=>{var t,A,r;const{name:n,basic:i,styles:s,validation:a}=e,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 t=null==s?void 0:s.headerBackgroundColor,A=null==s?void 0:s.headerTextColor,r=Object.assign(Object.assign(Object.assign(Object.assign({},ee.sectionHeader),t?{backgroundColor:t,padding:"8px",borderRadius:"4px"}:{}),A?{color:A}:{}),{display:"flex",alignItems:"center"});return p.jsxs("div",{style:ee.section,children:[o&&p.jsx("label",{style:r,children:p.jsxs("span",{style:{flex:1},children:[o,l&&" *"]})}),(null==i?void 0:i.description)&&p.jsx("p",{style:Object.assign(Object.assign({},ee.description),{marginBottom:"15px"}),children:i.description}),p.jsx(ne,{component:e}),p.jsx("div",{style:ee.sectionChildren,children:p.jsx(ae,{components:e.children||[]})})]})}if("heading"===n){const e=`h${Math.max(1,Math.min(6,null!==(A=null!==(t=null==s?void 0:s.level)&&void 0!==t?t: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 p.jsx("div",{style:ee.formGroup,children:p.jsx(e,{style:r,children:(null==i?void 0:i.label)||(null==i?void 0:i.value)})})}if("table"===n){const t=e.cells||[],A=Math.max(0,...t.map(e=>e?e.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({},ee.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{});return p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:a,children:[o,l&&" *"]}),p.jsx("table",{style:ee.table,children:p.jsx("tbody",{children:t.map((e,t)=>p.jsx("tr",{children:e&&e.map((e,t)=>p.jsx("td",{style:Object.assign(Object.assign({},ee.td),{width:`${r}%`}),children:e.components&&e.components.map((e,t)=>{var A;return p.jsxs("div",{style:{marginBottom:"8px"},children:[(null===(A=e.basic)||void 0===A?void 0:A.label)&&p.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[e.basic.label,":"]}),p.jsx(ie,{component:e}),p.jsx(ne,{component:e})]},t)})},t))},t))})})]})}if("datagrid"===n){const t=e.entries||[];let A=e.templateComponents||[];0===A.length&&t.length>0&&(null===(r=t[0])||void 0===r?void 0:r.components)&&(A=t[0].components.map(e=>{var t;return Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{label:(null===(t=e.basic)||void 0===t?void 0:t.label)||e.name})})}));const n=null==s?void 0:s.headerBackgroundColor,i=null==s?void 0:s.headerTextColor,a=Object.assign(Object.assign(Object.assign({},ee.label),n?{backgroundColor:n,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{}),i?{color:i}:{}),c=t.filter(e=>!(!e.components||0===e.components.length)&&e.components.some(e=>{var t,A;const r=void 0!==(null===(t=e.basic)||void 0===t?void 0:t.value)?e.basic.value:null===(A=e.basic)||void 0===A?void 0:A.defaultValue;return Array.isArray(r)?r.length>0:null!=r&&""!==String(r).trim()}));return 0===c.length?p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:a,children:[o,l&&" *"]}),p.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:a,children:[o,l&&" *"]}),p.jsxs("table",{style:ee.table,children:[p.jsx("thead",{children:p.jsx("tr",{children:A.map((e,t)=>{var A;return p.jsx("th",{style:ee.th,children:(null===(A=e.basic)||void 0===A?void 0:A.label)||e.name},t)})})}),p.jsx("tbody",{children:c.map((e,t)=>p.jsx("tr",{children:A.map((t,A)=>{const r=e.components[A];return p.jsx("td",{style:ee.td,children:r?p.jsxs(p.Fragment,{children:[p.jsx(ie,{component:r}),p.jsx(ne,{component:r})]}):"N/A"},A)})},t))})]})]})}if(c&&"instructions"!==n){const t=["segment"].includes(n);return p.jsxs("div",{style:ee.formGroup,children:[p.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[o&&p.jsxs("label",{style:ee.labelLeft,children:[o,l&&" *"]}),p.jsx("div",{style:Object.assign({flex:1},t?{display:"flex",justifyContent:"flex-end"}:{}),children:p.jsx(ie,{component:e})})]}),p.jsx(ne,{component:e})]})}return p.jsxs("div",{style:ee.formGroup,children:[o&&p.jsxs("label",{style:ee.label,children:[o,l&&" *"]}),p.jsx(ie,{component:e}),p.jsx(ne,{component:e})]})},ae=({components:e})=>{if(!e||0===e.length)return null;const t=[];let A=[],r=0;return e.forEach(e=>{var n;const i=["section","table","datagrid","heading","instructions"].includes(e.name),s=i?12:(null===(n=e.styles)||void 0===n?void 0:n.column)||12;r+s>12&&A.length>0&&(t.push(A),A=[],r=0),A.push(e),r+=s,(i||r>=12)&&r>0&&(t.push(A),A=[],r=0)}),A.length>0&&t.push(A),p.jsx(p.Fragment,{children:t.map((e,t)=>1===e.length?p.jsx(se,{component:e[0]},e[0].id||t):p.jsx("div",{style:ee.gridRow,children:e.map((e,t)=>{var A;const r=(null===(A=e.styles)||void 0===A?void 0:A.column)||12;return p.jsx("div",{style:ee.gridCol(r),children:p.jsx(se,{component:e})},e.id||t)})},t))})},oe=({formTitle:e,formDescription:t,userName:A,components:r})=>p.jsxs("div",{className:"pdf-container",style:ee.page,children:[p.jsxs("div",{style:ee.header,children:[p.jsxs("div",{children:[p.jsx("h1",{style:ee.title,children:e}),t&&p.jsx("p",{style:ee.description,children:t})]}),A&&p.jsxs("div",{style:ee.submittedBy,children:[p.jsx("strong",{children:"Submitted By:"})," ",A]})]}),p.jsx("div",{className:"form-content",children:p.jsx(ae,{components:r})})]});var le,ce=A;if("production"===process.env.NODE_ENV)le=ce.createRoot,ce.hydrateRoot;else{var ue=ce.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;le=function(e,t){ue.usingClientEntryPoint=!0;try{return ce.createRoot(e,t)}finally{ue.usingClientEntryPoint=!1}}}var he={exports:{}};
11
11
  /*!
12
12
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>
13
13
  * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>