df-ae-forms-package 1.0.46 → 1.0.47

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,v=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(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=v.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&&w("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,_=v.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&&w("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=v.ReactDebugCurrentFrame;function V(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 K=Array.isArray;function G(e){return K(e)}function z(e){return""+e}function q(e){if(function(e){try{return z(e),!1}catch(e){return!0}}(e))return w("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=v.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]||(w('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',B(J.current.type),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,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};A.isReactWarning=!0,Object.defineProperty(e,"key",{get:A,configurable:!0})}(a,u),l&&function(e,t){var A=function(){X||(X=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",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=v.ReactCurrentOwner,Ae=v.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),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',A,r),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||(V(n),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",r||"React class",A,s,typeof a),V(null)),a instanceof Error&&!(a.message in M)&&(M[a.message]=!0,V(n),w("Failed %s type: %s",A,a.message),V(null))}}(t,e.props,"prop",r,e)}else void 0===A.PropTypes||ee||(ee=!0,w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",B(A)||"Unknown"));"function"!=typeof A.getDefaultProps||A.getDefaultProps.isReactClassApproved||w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ce={};function ue(e,A,n,f,m,v){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,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,y)}var F=Z(e,A,n,m,v);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 w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else 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]||(w('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',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),w("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),w("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)=>{let n=t.find(t=>{var A;return(null===(A=t.basic)||void 0===A?void 0:A.label)===e.when});if(n||(n=t.find(t=>t.id===e.when)),!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];let r=t.find(t=>{var A;return(null===(A=t.basic)||void 0===A?void 0:A.label)===e});return r||(r=t.find(t=>t.id===e)),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=>{let A=t.find(t=>{var A;return(null===(A=t.basic)||void 0===A?void 0:A.label)===e.when});A||(A=t.find(t=>t.id===e.when));return`${(null==A?void 0:A.basic.label)||e.when||"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 v=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]}},w=({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:w,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,V]=e.useState(""),[K,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),V((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(!w){if(!k.trim())return!1;if(!T.trim())return!1}return!0},[N,I,D,R,w,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(K||"").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"};v.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.";v.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})]}),!w&&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})]}),!w&&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=>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"===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"})]}),!K&&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:K,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"})]}),!Z&&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(w||String(k||"").trim())if(w||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(K||"").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)),v.showSuccess("Issue updated successfully"),i&&i(),n()}else{if(!s)return v.showError("Component is required"),void q(!1);if(!a||""===String(a||"").trim())return v.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(K||"").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)),v.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.");v.showError(t)}finally{q(!1)}}else v.showError("Assignee is required");else v.showError("Asset Number is required");else v.showError("Work Order is required");else v.showError("Description is required");else v.showError("Title is required")}),disabled:z||!Ae,children:z?"Creating...":"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),[w,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),v.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:v,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,V]=e.useState(_),K=()=>{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"===K()&&(t.email=!0),"text"===K()){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"===K()){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"===K())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,K]),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),V(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=K(),$=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(w,{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:v,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,v;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===(v=null==A?void 0:A.validation)||void 0===v?void 0:v.readonly),rows:U,className:`form-textarea ${!x(b).isValid&&y?"is-invalid":""} ${d}`.trim()}),p.jsx(w,{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[v,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(v)&&b(n)},[n,v]),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:v,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(v).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(w,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(v),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,v;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(w,{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===(v=null==A?void 0:A.basic)||void 0===v?void 0:v.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(w,{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,v;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(w,{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===(v=null==A?void 0:A.basic)||void 0===v?void 0:v.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(w,{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,v]=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(v(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&&v(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(w,{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,v,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===(v=null==A?void 0:A.validation)||void 0===v?void 0:v.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(w,{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),[v,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(!v)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(!v)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||v||F||""!==C&&""===n)){if(n===C)return;x(n),n&&N(n)}},[n,C,v,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(w,{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,v,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===(v=null==A?void 0:A.validation)||void 0===v?void 0:v.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),V="edit"===l,K="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 K&&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(w,{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");!V||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(),V&&!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)})]}),V&&!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&&V&&p.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!H&&L.current&&V&&(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(w,{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,v,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,V]=e.useState(!1),K=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 v={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)},v)}),[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||!K.current||0===e.button&&(z(!0),W({x:e.clientX,y:e.clientY}),e.preventDefault())},[s,a]),ne=e.useCallback(e=>{if(!G||!q||!K.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(!K.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=K.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,K,k,H,Ae,$,G,q]),se=e.useCallback(e=>b(void 0,void 0,void 0,function*(){if(e.trim()&&!s&&!a){V(!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{V(!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===(v=null==r?void 0:r.basic)||void 0===v?void 0:v.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:K,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(w,{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,v]=e.useState("#000000"),w=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&&w.current&&(u||c&&w.current.innerHTML.trim()!==r.trim())&&(w.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&&w.current){const e=w.current.innerHTML.trim();h.trim()===e||B.current||(w.current.innerHTML=h)}if(B.current){const e=setTimeout(()=>{B.current=!1},200);return()=>clearTimeout(e)}},[h,y]);const F=e.useCallback(()=>{if(!w.current)return;B.current=!0;const e=w.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(!w.current)return;const e=w.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=w.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;v(t),U("foreColor",t)},[U]),L=e.useCallback(e=>{if(g(e),!w.current)return;const t=window.getSelection(),r=t&&t.rangeCount>0?t.getRangeAt(0):null;let n=w.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(w.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&&w.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 w.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:w,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,formData:s,onNotesChange:a,onAttachmentChange:o,notes:l="",attachments:c=null,onThresholdActionCompletion:u,onThresholdIssueRaised:h,onBasicPropertyActionCompletion:d,workOrderNumber:f,assetNumber:g,isStandalone:m,user:v,onCreateIssue:w,onUpdateIssue:b})=>{var B;const y=void 0!==i?i:s?s[A.id]:void 0,[x,F]=e.useState(l||""),[Q,U]=e.useState(c||null),[E,S]=e.useState(!1),[N,L]=e.useState(!1),[I,_]=e.useState(!1),[k,O]=e.useState(!1),[T,H]=e.useState(null),[P,D]=e.useState(!1),M=e.useRef(null),R=e.useRef(y),V=e.useRef(!1),K=e.useRef(!1);e.useEffect(()=>{l&&l!==x&&!V.current&&(F(l),V.current=!0)},[l,x]),e.useEffect(()=>{c&&c!==Q&&!K.current&&(U(c),K.current=!0)},[c,Q]),e.useEffect(()=>{if(V.current&&!E&&null!=l){const e="string"==typeof l?l:String(l||"");x&&""!==String(x||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==x&&F(e):F(e)}},[l,E,x]),e.useEffect(()=>{K.current&&void 0!==c&&(!Q||c&&c.length>0&&c!==Q)&&U(c)},[c,Q]),e.useEffect(()=>{const e=["select","radio","checkbox","segment"].includes(A.name||"");if(e){const e=R.current,t=y;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;r&&(_(!1),O(!1),H(null),L(!1),S(!1),D(!1),l&&""!==l.trim()||F(""),c&&0!==c.length||U(null)),R.current=t}e||(R.current=y)},[y,A.name,l,c]);const G=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}},[]),z=e.useCallback(()=>{if(!(null!=y&&""!==y&&!(Array.isArray(y)&&0===y.length)))return[];const e=A.condition;if(!e||!e.conditions||0===e.conditions.length)return[];const t=[];if("checkbox"===A.name&&Array.isArray(y))y.forEach(A=>{const r=e.conditions.find(e=>G(e,A));r&&!t.find(e=>e.id===r.id)&&t.push(r)});else{const A=e.conditions.find(e=>G(e,y));A&&t.push(A)}return t},[A,y,G]),q=e.useCallback(e=>{const t=e.target.value;F(t),a&&a(t);const r=z(),n=t.trim().length>0;r.forEach(e=>{!0===e.enableNotes&&u&&u(e.id,"notes",n)});const i=A.condition;!(i&&i.conditions&&i.conditions.length>0)&&d&&d("notes",n)},[a,z,u,A,d]),W=e.useCallback(()=>{if(a){const e="string"==typeof x?x:String(x||"");a(e),setTimeout(()=>{S(!1)},0)}else S(!1)},[x,a]),X=e.useCallback(()=>{W()},[W]),Y=e.useCallback(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),W())},[W]),J=e.useCallback(()=>{S(!0)},[]),$=e.useCallback(()=>{S(!0)},[]),Z=e.useCallback(()=>{var e;null===(e=M.current)||void 0===e||e.click()},[]),ee=e.useCallback(e=>{const t=e.target.files;if(t&&t.length>0){const e=Array.from(t);U(e),o&&o(e);z().forEach(e=>{!0===e.enableAttachment&&u&&u(e.id,"attachments",!0)});const r=A.condition;!(r&&r.conditions&&r.conditions.length>0)&&d&&d("attachments",!0)}M.current&&(M.current.value="")},[o,z,u,A,d]),te=e.useCallback(e=>{if(Q){const t=Q.filter((t,A)=>A!==e);if(0===t.length){U(null),o&&o(null);z().forEach(e=>{!0===e.enableAttachment&&u&&u(e.id,"attachments",!1)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&d&&d("attachments",!1)}else U(t),o&&o(t)}},[Q,o,z,u,A,d]),Ae=e.useCallback(()=>{_(!0);z().forEach(e=>{!0===e.enableSendEmail&&u&&u(e.id,"email",!0)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&d&&d("email",!0),setTimeout(()=>{_(!1)},3e3)},[z,u,A,d]),re=e.useCallback(()=>{k||L(!0)},[k]),ne=e.useCallback(()=>{L(!1)},[]),ie=e.useCallback(e=>{L(!1),O(!0),e&&H(e);const t=A.condition;if(t&&t.conditions&&t.conditions.length>0){z().forEach(e=>{!0===e.enableRaiseIssue&&h&&h(e.id)})}else d&&d("issue",!0)},[A,d,z,h]);if("test"!==r)return null;const se=["select","radio","checkbox","segment"].includes(A.name||""),ae=(null===(B=A.basic)||void 0===B?void 0:B.options)||A.options||[];let oe=!1,le=!1,ce=!1,ue=!1,he=null;const de=null!=y&&""!==y&&!(Array.isArray(y)&&0===y.length),fe=A.condition,pe=fe&&fe.conditions&&fe.conditions.length>0;if(pe&&de)if("checkbox"===A.name&&Array.isArray(y)){const e=y;for(const t of e){const e=fe.conditions.find(e=>G(e,t));e&&(oe=oe||!0===e.enableNotes,le=le||!0===e.enableAttachment,ce=ce||!0===e.enableRaiseIssue,ue=ue||!0===e.enableSendEmail)}}else if(se){const e=fe.conditions.find(e=>G(e,y));e&&(oe=!0===e.enableNotes,le=!0===e.enableAttachment,ce=!0===e.enableRaiseIssue,ue=!0===e.enableSendEmail)}else{const e=fe.conditions.find(e=>G(e,y));e&&(oe=!0===e.enableNotes,le=!0===e.enableAttachment,ce=!0===e.enableRaiseIssue,ue=!0===e.enableSendEmail)}if(!pe){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),i=!0===(null==e?void 0:e.enableSendEmail);if(se)if(de)if("checkbox"===A.name){(Array.isArray(y)?y:[y]).forEach(e=>{const t=ae.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(oe=oe||!0===t.enableNotes,le=le||!0===t.enableAttachment,ce=ce||!0===t.enableRaiseIssue,ue=ue||!0===t.enableSendEmail,he||(he=t))}),oe=oe||t,le=le||r,ce=ce||n,ue=ue||i}else if(he=ae.find(e=>!(!e||!e.value)&&(e.value===y||(String(e.value)===String(y)||(e.label===y||String(e.label)===String(y))))),he){const e=!0===he.enableNotes,A=!0===he.enableAttachment,s=!0===he.enableRaiseIssue,a=!0===he.enableSendEmail;oe=e||t,le=A||r,ce=s||n,ue=a||i}else oe=t,le=r,ce=n,ue=i;else oe=t,le=r,ce=n,ue=i;else oe=t,le=r,ce=n,ue=i}if(!(oe||le||ce||ue))return null;const ge=z(),me=A.condition,ve=me&&me.conditions&&me.conditions.length>0,we=!!ve&&ge.some(e=>!0===e.enableNotes),be=!!ve&&ge.some(e=>!0===e.enableAttachment),Be=!!ve&&ge.some(e=>!0===e.enableSendEmail),ye=!!ve&&ge.some(e=>!0===e.enableRaiseIssue),Ce=x.trim().length>0,xe=Q&&Q.length>0,Fe=Q?Q.length:0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"component-action-features",children:[p.jsxs("div",{className:"action-icons-toolbar",children:[oe&&p.jsxs("button",{type:"button",className:`action-icon-button ${Ce?"active":""} ${we?"mandatory":""}`,onClick:J,title:"Add Notes",children:[p.jsx(t.MessageSquare,{size:14,fill:Ce?"currentColor":"none"}),we&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),le&&p.jsxs("button",{type:"button",className:`action-icon-button ${xe?"active":""} ${be?"mandatory":""}`,onClick:Z,title:"Add Attachment",children:[p.jsx(t.Paperclip,{size:14,fill:xe?"currentColor":"none"}),Fe>0&&p.jsx("span",{className:"attachment-count-badge",children:Fe}),be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ue&&p.jsxs("button",{type:"button",className:`action-icon-button ${I?"active sent":""} ${Be?"mandatory":""}`,onClick:Ae,disabled:I,title:"Send Email",children:[I?p.jsx(p.Fragment,{children:p.jsx(t.Check,{size:14})}):p.jsx(t.Mail,{size:14,fill:I?"currentColor":"none"}),Be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ce&&p.jsxs("button",{type:"button",className:`action-icon-button ${k?"active":""} ${ye?"mandatory":""}`,onClick:re,title:"Raise an Issue",children:[p.jsx(t.AlertCircle,{size:14,fill:k?"currentColor":"none"}),ye&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(Ce&&oe||xe&&le)&&p.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>D(!P),title:P?"Collapse":"Expand",children:P?p.jsx(t.ChevronUp,{size:14}):p.jsx(t.ChevronDown,{size:14})})]}),E&&oe&&p.jsxs("div",{className:"notes-input-overlay",children:[p.jsx("textarea",{className:"action-notes-textarea",value:x,onChange:q,onBlur:X,onKeyDown:Y,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:W,title:"Save notes (Ctrl+Enter)",children:"Save"}),p.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{S(!1)},title:"Cancel",children:"Cancel"})]})]}),P&&p.jsxs("div",{className:"actions-content",children:[!E&&Ce&&oe&&p.jsx("div",{className:"notes-summary-section",children:p.jsxs("div",{className:"notes-full-text",onClick:$,children:[p.jsx("span",{className:"notes-label",children:"Notes:"})," ",x]})}),xe&&le&&p.jsx("div",{className:"attachments-section",children:p.jsx(j,{attachments:Q,onRemove:te})})]}),le&&p.jsx("input",{ref:M,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:ee,style:{display:"none"}})]}),N&&p.jsx(C,{isOpen:N,onClose:ne,onSuccess:ie,issue:T,component:(()=>{var e,t;const r=null!=y?Array.isArray(y)?y.join(", "):String(y):(null===(e=A.basic)||void 0===e?void 0:e.value)||"",n=Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic||{}),{value:r})});return he&&(n.basic.label=`${(null===(t=A.basic)||void 0===t?void 0:t.label)||"Component"} - ${he.label||he.value}`,n.basic.value=he.value||r),n})(),formTemplateId:n||"",notes:x,attachments:Q,isStandalone:m,workOrderNumber:f,assetNumber:g,user:v,onCreateIssue:w,onUpdateIssue:b})]})},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:v,assetNumber:w,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,formData:u,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:v,assetNumber:w,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:v,onThresholdActionCompletion:w,onThresholdIssueRaised:b,onNotesChange:B,onAttachmentChange:y,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k})=>{var T,j,H,P,D,R;const[V,K]=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(),K(!V),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{collapsed:!V})})})},[V,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:V?"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:V?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"})})]}),!V&&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:v,onNotesChange:B,onAttachmentChange:y,onThresholdActionCompletion:w,onThresholdIssueRaised:b,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k},e.id))})})]})},V=({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:v,assetNumber:w,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:c}),k={transform:i.CSS.Transform.toString(N),transition:L,opacity:I?.3:1,zIndex:I?1e3:"auto"};return p.jsxs("div",{ref:S,style:Object.assign(Object.assign({},k),{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":""} ${I?"dragging":""} ${_?"sorting":""}`,onClick:()=>!I&&s(e),role:"button",tabIndex:0,children:["edit"===r&&p.jsx("div",Object.assign({className:"component-drag-handle"},E,U,{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:F,formData:u,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:v,assetNumber:w,user:b,onCreateIssue:B,onUpdateIssue:y}),Q&&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})})]})]})},K=({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:v,assetNumber:w,user:b,onCreateIssue:B,onUpdateIssue:y})=>{const{setNodeRef:C,isOver:x}=r.useDroppable({id:`grid-drop-zone-${c}`,disabled:"edit"!==t});return p.jsx("div",{ref:C,className:"grid-drop-zone",style:{border:x?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:x?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?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(V,{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:v,assetNumber:w,user:b,onCreateIssue:B,onUpdateIssue:y})},e.id))})}),p.jsx("div",{style:{border:x?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:x?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:x?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:x?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:x?"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:v,onAttachmentChange:w,datagridId:b="",workOrderNumber:B,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:F})=>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,Q,U;let E=null===(a=s.components)||void 0===a?void 0:a[i];const S=`${t.id||`component-${i}`}-entry-${b}-${o}-${i}`;return E=E?E.id!==S?Object.assign(Object.assign({},E),{id:S,basic:Object.assign(Object.assign({},E.basic),{showLabel:!1})}):Object.assign(Object.assign({},E),{id:E.id,basic:Object.assign(Object.assign({},E.basic),{showLabel:!1})}):Object.assign(Object.assign({},t),{id:S,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(E,!0):A(E,!0)}),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(E.name)&&p.jsxs("div",{style:{marginTop:"8px",width:"100%"},children:[p.jsx(H,{component:E,mode:"test",formTemplateId:f,formValue:d[E.id],formData:d,onThresholdActionCompletion:g,onThresholdIssueRaised:m,onNotesChange:v?e=>v(E.id,e):void 0,onAttachmentChange:w?e=>w(E.id,e):void 0,notes:(null===(l=E.basic)||void 0===l?void 0:l.notes)||(null===(c=d[E.id])||void 0===c?void 0:c.notes),attachments:(null===(u=E.basic)||void 0===u?void 0:u.attachments)||(null===(h=d[E.id])||void 0===h?void 0:h.attachments),workOrderNumber:B,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:F}),"preview"===n&&((null===(Q=E.basic)||void 0===Q?void 0:Q.notes)||(null===(U=E.basic)||void 0===U?void 0:U.attachments))&&p.jsx(D,{component:E})]})]},`${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:v?e=>v(c.id,e):void 0,onAttachmentChange:w?e=>w(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:v,selectedComponent:w,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,V,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)=>{v&&v(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})})},[v,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(K,{gridComponents:ne,mode:n,onComponentSelect:f||(()=>{}),onComponentDelete:ae,onComponentEdit:m,onComponentUpdate:oe,selectedComponent:w||null,renderFormComponent:b||he,gridId:A,formData:i,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,workOrderNumber:j,assetNumber:H,user:user,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===(V=r.datagrid)||void 0===V?void 0:V.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,user:user,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],v="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,formData:r,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}),v&&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:v}=n.useSortable({id:e.id,disabled:c}),w={transform:i.CSS.Transform.toString(f),transition:g,opacity:m?.3:1,zIndex:m?1e3:"auto"};return p.jsxs("div",{ref:d,style:w,className:`form-component table-component ${(null==A?void 0:A.id)===e.id?"selected":""} ${m?"dragging":""} ${v?"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:v,assetNumber:w,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:v,assetNumber:w,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:v,renderFormComponent:w,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,V,K,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=w||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]})}},[w,n,i,l]),ue={backgroundColor:(null===(V=r.styles)||void 0===V?void 0:V.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(K=r.styles)||void 0===K?void 0:K.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:v||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=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},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,o;const l=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:c}=e;if("signature"===c)return l&&te(l)?p.jsx("div",{style:{marginTop:"5px"},children:p.jsx("img",{src:Ae(l),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"===c){const t=(null===(r=e.basic)||void 0===r?void 0:r.options)||[],A=(Array.isArray(l)?l:l?[l]:[]).map(e=>String(e));return p.jsx("div",{style:{marginTop:"5px",width:"100%"},children:t.map((e,t)=>{const r=A.includes(String(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"===c){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=String(l||"")===String(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"===c){const t=(null===(i=e.basic)||void 0===i?void 0:i.options)||[],A=l;return p.jsx("div",{style:ee.segmentContainer,children:t.map((e,t)=>{const r=String(A||"")===String(e.value||""),n=(e=>void 0!==(null==e?void 0:e.icon)&&null!==(null==e?void 0:e.icon)?e.icon:"pass"===re((null==e?void 0:e.value)||e)?"✓":"×")(e),i=e.color||e.backgroundColor,s=re(e.value);let a,o,l;i?r?(a=i,o="#ffffff",l=i):(a=`${i}20`,o=i,l=i):"pass"===s?r?(a="#00814b",o="#ffffff",l="#00814b"):(a="#34bd4914",o="#00814b",l="#e0e0e0"):r?(a="#dc3545",o="#ffffff",l="#dc3545"):(a="#fa323d14",o="#dc3545",l="#e0e0e0");const c=Object.assign(Object.assign({},ee.segmentButton),{backgroundColor:a,color:o,borderColor:l,borderWidth:"1px",borderStyle:"solid"});return p.jsxs("div",{style:c,children:[p.jsx("span",{style:ee.segmentIcon,children:n}),p.jsx("span",{children:e.value})]},t)})})}if("file"===c){const e=(Array.isArray(l)?l:l?[l]:[]).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"===c){if(l&&"object"==typeof l){const e=l;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"===c){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,{})})}if("select"===c){const t=(null===(o=e.basic)||void 0===o?void 0:o.options)||[],A=l;let r="";if(Array.isArray(A))r=A.map(e=>{const A=t.find(t=>String(t.value)===String(e));return A?A.label:e}).join(", ");else{const e=A,n=t.find(t=>String(t.value)===String(e));r=n?n.label||n.value:null!=e?String(e):""}return p.jsx("div",{style:ee.valueContainer,children:p.jsx("div",{style:ee.value,children:r})})}const u="object"==typeof l?JSON.stringify(l):String(l);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid","select"].includes(c)){const e="textarea"===c;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:u})})}return p.jsx("div",{style:ee.value,children:u})},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,v=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(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=v.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&&w("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,_=v.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&&w("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=v.ReactDebugCurrentFrame;function V(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 K=Array.isArray;function G(e){return K(e)}function z(e){return""+e}function q(e){if(function(e){try{return z(e),!1}catch(e){return!0}}(e))return w("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=v.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]||(w('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',B(J.current.type),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,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};A.isReactWarning=!0,Object.defineProperty(e,"key",{get:A,configurable:!0})}(a,u),l&&function(e,t){var A=function(){X||(X=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",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=v.ReactCurrentOwner,Ae=v.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),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',A,r),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||(V(n),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",r||"React class",A,s,typeof a),V(null)),a instanceof Error&&!(a.message in M)&&(M[a.message]=!0,V(n),w("Failed %s type: %s",A,a.message),V(null))}}(t,e.props,"prop",r,e)}else void 0===A.PropTypes||ee||(ee=!0,w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",B(A)||"Unknown"));"function"!=typeof A.getDefaultProps||A.getDefaultProps.isReactClassApproved||w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ce={};function ue(e,A,n,f,m,v){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,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,y)}var F=Z(e,A,n,m,v);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 w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else 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]||(w('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',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),w("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),w("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=[];try{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)=>{try{let n=t.find(t=>{var A;return(null===(A=t.basic)||void 0===A?void 0:A.label)===e.when});if(n||(n=t.find(t=>t.id===e.when)),!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`)}catch(e){console.error("[ConditionalLogicService] Error validating condition:",e),A.push(`Condition ${r+1}: Validation error`)}}):A.push("At least one condition is required"),{isValid:0===A.length,errors:A}):{isValid:!0,errors:[]}}catch(e){return console.error("[ConditionalLogicService] Error in validateConditionalLogic:",e),{isValid:!1,errors:["Validation failed due to an error"]}}}evaluateConditionalLogic(e,t,A){try{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=>{try{const r=this.getComponentValue(e.when,t,A);return{condition:e,result:this.evaluateCondition(e,r),componentValue:r}}catch(t){return console.error("[ConditionalLogicService] Error evaluating condition:",t,e),{condition:e,result:!1,componentValue:void 0}}});return{shouldShow:this.determineFinalResult(e,r),evaluatedConditions:r}}catch(e){return console.error("[ConditionalLogicService] Error in evaluateConditionalLogic:",e),{shouldShow:!0,evaluatedConditions:[]}}}getComponentValue(e,t,A){let r=t.find(t=>{var A;return(null===(A=t.basic)||void 0===A?void 0:A.label)===e});return r||(r=t.find(t=>t.id===e)),r?A&&void 0!==A[r.id]?A[r.id]:r.basic&&"defaultValue"in r.basic?r.basic.defaultValue:void 0:A&&void 0!==A[e]?A[e]: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){try{if(!e||!e.conditions||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=>{var A;try{let r=t.find(t=>{var A;return(null===(A=t.basic)||void 0===A?void 0:A.label)===e.when});r||(r=t.find(t=>t.id===e.when));const n=(null===(A=null==r?void 0:r.basic)||void 0===A?void 0:A.label)||e.when||"Unknown component",i=this.getOperatorDisplayText(e.operator);return`${n} ${i} ${this.formatConditionValue(e.value)}`}catch(e){return console.error("[ConditionalLogicService] Error formatting condition:",e),"Invalid condition"}}),n="all"===e.when?" and ":" or ";return`${A} ${r.join(n)}`}catch(e){return console.error("[ConditionalLogicService] Error in getConditionalLogicSummary:",e),"Error displaying conditions"}}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const m=g.getInstance();const v=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]}},w=({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:w,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,V]=e.useState(""),[K,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),V((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(!w){if(!k.trim())return!1;if(!T.trim())return!1}return!0},[N,I,D,R,w,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(K||"").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"};v.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.";v.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})]}),!w&&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})]}),!w&&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=>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"===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"})]}),!K&&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:K,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"})]}),!Z&&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(w||String(k||"").trim())if(w||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(K||"").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)),v.showSuccess("Issue updated successfully"),i&&i(),n()}else{if(!s)return v.showError("Component is required"),void q(!1);if(!a||""===String(a||"").trim())return v.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(K||"").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)),v.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.");v.showError(t)}finally{q(!1)}}else v.showError("Assignee is required");else v.showError("Asset Number is required");else v.showError("Work Order is required");else v.showError("Description is required");else v.showError("Title is required")}),disabled:z||!Ae,children:z?"Creating...":"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),[w,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),v.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:v,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,V]=e.useState(_),K=()=>{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"===K()&&(t.email=!0),"text"===K()){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"===K()){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"===K())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,K]),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),V(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=K(),$=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(w,{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:v,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,v;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===(v=null==A?void 0:A.validation)||void 0===v?void 0:v.readonly),rows:U,className:`form-textarea ${!x(b).isValid&&y?"is-invalid":""} ${d}`.trim()}),p.jsx(w,{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[v,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(v)&&b(n)},[n,v]),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:v,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(v).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(w,{validationErrors:r,fieldId:t,touchedFields:a,formSubmitted:o,properties:A,localValidation:x(v),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,v;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(w,{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===(v=null==A?void 0:A.basic)||void 0===v?void 0:v.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(w,{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,v;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(w,{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===(v=null==A?void 0:A.basic)||void 0===v?void 0:v.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(w,{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,v]=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(v(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&&v(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(w,{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,v,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===(v=null==A?void 0:A.validation)||void 0===v?void 0:v.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(w,{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),[v,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(!v)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(!v)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||v||F||""!==C&&""===n)){if(n===C)return;x(n),n&&N(n)}},[n,C,v,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(w,{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,v,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===(v=null==A?void 0:A.validation)||void 0===v?void 0:v.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),V="edit"===l,K="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 K&&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(w,{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");!V||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(),V&&!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)})]}),V&&!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&&V&&p.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!H&&L.current&&V&&(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(w,{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,v,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,V]=e.useState(!1),K=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 v={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)},v)}),[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||!K.current||0===e.button&&(z(!0),W({x:e.clientX,y:e.clientY}),e.preventDefault())},[s,a]),ne=e.useCallback(e=>{if(!G||!q||!K.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(!K.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=K.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,K,k,H,Ae,$,G,q]),se=e.useCallback(e=>b(void 0,void 0,void 0,function*(){if(e.trim()&&!s&&!a){V(!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{V(!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===(v=null==r?void 0:r.basic)||void 0===v?void 0:v.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:K,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(w,{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,v]=e.useState("#000000"),w=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&&w.current&&(u||c&&w.current.innerHTML.trim()!==r.trim())&&(w.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&&w.current){const e=w.current.innerHTML.trim();h.trim()===e||B.current||(w.current.innerHTML=h)}if(B.current){const e=setTimeout(()=>{B.current=!1},200);return()=>clearTimeout(e)}},[h,y]);const F=e.useCallback(()=>{if(!w.current)return;B.current=!0;const e=w.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(!w.current)return;const e=w.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=w.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;v(t),U("foreColor",t)},[U]),L=e.useCallback(e=>{if(g(e),!w.current)return;const t=window.getSelection(),r=t&&t.rangeCount>0?t.getRangeAt(0):null;let n=w.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(w.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&&w.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 w.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:w,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,formData:s,onNotesChange:a,onAttachmentChange:o,notes:l="",attachments:c=null,onThresholdActionCompletion:u,onThresholdIssueRaised:h,onBasicPropertyActionCompletion:d,workOrderNumber:f,assetNumber:g,isStandalone:m,user:v,onCreateIssue:w,onUpdateIssue:b})=>{var B;const y=void 0!==i?i:s?s[A.id]:void 0,[x,F]=e.useState(l||""),[Q,U]=e.useState(c||null),[E,S]=e.useState(!1),[N,L]=e.useState(!1),[I,_]=e.useState(!1),[k,O]=e.useState(!1),[T,H]=e.useState(null),[P,D]=e.useState(!1),M=e.useRef(null),R=e.useRef(y),V=e.useRef(!1),K=e.useRef(!1);e.useEffect(()=>{l&&l!==x&&!V.current&&(F(l),V.current=!0)},[l,x]),e.useEffect(()=>{c&&c!==Q&&!K.current&&(U(c),K.current=!0)},[c,Q]),e.useEffect(()=>{if(V.current&&!E&&null!=l){const e="string"==typeof l?l:String(l||"");x&&""!==String(x||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==x&&F(e):F(e)}},[l,E,x]),e.useEffect(()=>{K.current&&void 0!==c&&(!Q||c&&c.length>0&&c!==Q)&&U(c)},[c,Q]),e.useEffect(()=>{const e=["select","radio","checkbox","segment"].includes(A.name||"");if(e){const e=R.current,t=y;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;r&&(_(!1),O(!1),H(null),L(!1),S(!1),D(!1),l&&""!==l.trim()||F(""),c&&0!==c.length||U(null)),R.current=t}e||(R.current=y)},[y,A.name,l,c]);const G=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}},[]),z=e.useCallback(()=>{if(!(null!=y&&""!==y&&!(Array.isArray(y)&&0===y.length)))return[];const e=A.condition;if(!e||!e.conditions||0===e.conditions.length)return[];const t=[];if("checkbox"===A.name&&Array.isArray(y))y.forEach(A=>{const r=e.conditions.find(e=>G(e,A));r&&!t.find(e=>e.id===r.id)&&t.push(r)});else{const A=e.conditions.find(e=>G(e,y));A&&t.push(A)}return t},[A,y,G]),q=e.useCallback(e=>{const t=e.target.value;F(t),a&&a(t);const r=z(),n=t.trim().length>0;r.forEach(e=>{!0===e.enableNotes&&u&&u(e.id,"notes",n)});const i=A.condition;!(i&&i.conditions&&i.conditions.length>0)&&d&&d("notes",n)},[a,z,u,A,d]),W=e.useCallback(()=>{if(a){const e="string"==typeof x?x:String(x||"");a(e),setTimeout(()=>{S(!1)},0)}else S(!1)},[x,a]),X=e.useCallback(()=>{W()},[W]),Y=e.useCallback(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),W())},[W]),J=e.useCallback(()=>{S(!0)},[]),$=e.useCallback(()=>{S(!0)},[]),Z=e.useCallback(()=>{var e;null===(e=M.current)||void 0===e||e.click()},[]),ee=e.useCallback(e=>{const t=e.target.files;if(t&&t.length>0){const e=Array.from(t);U(e),o&&o(e);z().forEach(e=>{!0===e.enableAttachment&&u&&u(e.id,"attachments",!0)});const r=A.condition;!(r&&r.conditions&&r.conditions.length>0)&&d&&d("attachments",!0)}M.current&&(M.current.value="")},[o,z,u,A,d]),te=e.useCallback(e=>{if(Q){const t=Q.filter((t,A)=>A!==e);if(0===t.length){U(null),o&&o(null);z().forEach(e=>{!0===e.enableAttachment&&u&&u(e.id,"attachments",!1)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&d&&d("attachments",!1)}else U(t),o&&o(t)}},[Q,o,z,u,A,d]),Ae=e.useCallback(()=>{_(!0);z().forEach(e=>{!0===e.enableSendEmail&&u&&u(e.id,"email",!0)});const e=A.condition;!(e&&e.conditions&&e.conditions.length>0)&&d&&d("email",!0),setTimeout(()=>{_(!1)},3e3)},[z,u,A,d]),re=e.useCallback(()=>{k||L(!0)},[k]),ne=e.useCallback(()=>{L(!1)},[]),ie=e.useCallback(e=>{L(!1),O(!0),e&&H(e);const t=A.condition;if(t&&t.conditions&&t.conditions.length>0){z().forEach(e=>{!0===e.enableRaiseIssue&&h&&h(e.id)})}else d&&d("issue",!0)},[A,d,z,h]);if("test"!==r)return null;const se=["select","radio","checkbox","segment"].includes(A.name||""),ae=(null===(B=A.basic)||void 0===B?void 0:B.options)||A.options||[];let oe=!1,le=!1,ce=!1,ue=!1,he=null;const de=null!=y&&""!==y&&!(Array.isArray(y)&&0===y.length),fe=A.condition,pe=fe&&fe.conditions&&fe.conditions.length>0;if(pe&&de)if("checkbox"===A.name&&Array.isArray(y)){const e=y;for(const t of e){const e=fe.conditions.find(e=>G(e,t));e&&(oe=oe||!0===e.enableNotes,le=le||!0===e.enableAttachment,ce=ce||!0===e.enableRaiseIssue,ue=ue||!0===e.enableSendEmail)}}else if(se){const e=fe.conditions.find(e=>G(e,y));e&&(oe=!0===e.enableNotes,le=!0===e.enableAttachment,ce=!0===e.enableRaiseIssue,ue=!0===e.enableSendEmail)}else{const e=fe.conditions.find(e=>G(e,y));e&&(oe=!0===e.enableNotes,le=!0===e.enableAttachment,ce=!0===e.enableRaiseIssue,ue=!0===e.enableSendEmail)}if(!pe){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),i=!0===(null==e?void 0:e.enableSendEmail);if(se)if(de)if("checkbox"===A.name){(Array.isArray(y)?y:[y]).forEach(e=>{const t=ae.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(oe=oe||!0===t.enableNotes,le=le||!0===t.enableAttachment,ce=ce||!0===t.enableRaiseIssue,ue=ue||!0===t.enableSendEmail,he||(he=t))}),oe=oe||t,le=le||r,ce=ce||n,ue=ue||i}else if(he=ae.find(e=>!(!e||!e.value)&&(e.value===y||(String(e.value)===String(y)||(e.label===y||String(e.label)===String(y))))),he){const e=!0===he.enableNotes,A=!0===he.enableAttachment,s=!0===he.enableRaiseIssue,a=!0===he.enableSendEmail;oe=e||t,le=A||r,ce=s||n,ue=a||i}else oe=t,le=r,ce=n,ue=i;else oe=t,le=r,ce=n,ue=i;else oe=t,le=r,ce=n,ue=i}if(!(oe||le||ce||ue))return null;const ge=z(),me=A.condition,ve=me&&me.conditions&&me.conditions.length>0,we=!!ve&&ge.some(e=>!0===e.enableNotes),be=!!ve&&ge.some(e=>!0===e.enableAttachment),Be=!!ve&&ge.some(e=>!0===e.enableSendEmail),ye=!!ve&&ge.some(e=>!0===e.enableRaiseIssue),Ce=x.trim().length>0,xe=Q&&Q.length>0,Fe=Q?Q.length:0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"component-action-features",children:[p.jsxs("div",{className:"action-icons-toolbar",children:[oe&&p.jsxs("button",{type:"button",className:`action-icon-button ${Ce?"active":""} ${we?"mandatory":""}`,onClick:J,title:"Add Notes",children:[p.jsx(t.MessageSquare,{size:14,fill:Ce?"currentColor":"none"}),we&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),le&&p.jsxs("button",{type:"button",className:`action-icon-button ${xe?"active":""} ${be?"mandatory":""}`,onClick:Z,title:"Add Attachment",children:[p.jsx(t.Paperclip,{size:14,fill:xe?"currentColor":"none"}),Fe>0&&p.jsx("span",{className:"attachment-count-badge",children:Fe}),be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ue&&p.jsxs("button",{type:"button",className:`action-icon-button ${I?"active sent":""} ${Be?"mandatory":""}`,onClick:Ae,disabled:I,title:"Send Email",children:[I?p.jsx(p.Fragment,{children:p.jsx(t.Check,{size:14})}):p.jsx(t.Mail,{size:14,fill:I?"currentColor":"none"}),Be&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ce&&p.jsxs("button",{type:"button",className:`action-icon-button ${k?"active":""} ${ye?"mandatory":""}`,onClick:re,title:"Raise an Issue",children:[p.jsx(t.AlertCircle,{size:14,fill:k?"currentColor":"none"}),ye&&p.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(Ce&&oe||xe&&le)&&p.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>D(!P),title:P?"Collapse":"Expand",children:P?p.jsx(t.ChevronUp,{size:14}):p.jsx(t.ChevronDown,{size:14})})]}),E&&oe&&p.jsxs("div",{className:"notes-input-overlay",children:[p.jsx("textarea",{className:"action-notes-textarea",value:x,onChange:q,onBlur:X,onKeyDown:Y,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:W,title:"Save notes (Ctrl+Enter)",children:"Save"}),p.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{S(!1)},title:"Cancel",children:"Cancel"})]})]}),P&&p.jsxs("div",{className:"actions-content",children:[!E&&Ce&&oe&&p.jsx("div",{className:"notes-summary-section",children:p.jsxs("div",{className:"notes-full-text",onClick:$,children:[p.jsx("span",{className:"notes-label",children:"Notes:"})," ",x]})}),xe&&le&&p.jsx("div",{className:"attachments-section",children:p.jsx(j,{attachments:Q,onRemove:te})})]}),le&&p.jsx("input",{ref:M,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:ee,style:{display:"none"}})]}),N&&p.jsx(C,{isOpen:N,onClose:ne,onSuccess:ie,issue:T,component:(()=>{var e,t;const r=null!=y?Array.isArray(y)?y.join(", "):String(y):(null===(e=A.basic)||void 0===e?void 0:e.value)||"",n=Object.assign(Object.assign({},A),{basic:Object.assign(Object.assign({},A.basic||{}),{value:r})});return he&&(n.basic.label=`${(null===(t=A.basic)||void 0===t?void 0:t.label)||"Component"} - ${he.label||he.value}`,n.basic.value=he.value||r),n})(),formTemplateId:n||"",notes:x,attachments:Q,isStandalone:m,workOrderNumber:f,assetNumber:g,user:v,onCreateIssue:w,onUpdateIssue:b})]})},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:v,assetNumber:w,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,formData:u,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:v,assetNumber:w,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:v,onThresholdActionCompletion:w,onThresholdIssueRaised:b,onNotesChange:B,onAttachmentChange:y,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k})=>{var T,j,H,P,D,R;const[V,K]=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(),K(!V),null==o||o({id:A,value:Object.assign(Object.assign({},i),{basic:Object.assign(Object.assign({},i.basic),{collapsed:!V})})})},[V,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:V?"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:V?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"})})]}),!V&&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:v,onNotesChange:B,onAttachmentChange:y,onThresholdActionCompletion:w,onThresholdIssueRaised:b,workOrderNumber:C,assetNumber:x,user:N,onCreateIssue:_,onUpdateIssue:k},e.id))})})]})},V=({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:v,assetNumber:w,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:c}),k={transform:i.CSS.Transform.toString(N),transition:L,opacity:I?.3:1,zIndex:I?1e3:"auto"};return p.jsxs("div",{ref:S,style:Object.assign(Object.assign({},k),{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":""} ${I?"dragging":""} ${_?"sorting":""}`,onClick:()=>!I&&s(e),role:"button",tabIndex:0,children:["edit"===r&&p.jsx("div",Object.assign({className:"component-drag-handle"},E,U,{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:F,formData:u,onThresholdActionCompletion:d,onThresholdIssueRaised:f,onNotesChange:g?t=>g(e.id,t):void 0,onAttachmentChange:m?t=>m(e.id,t):void 0,workOrderNumber:v,assetNumber:w,user:b,onCreateIssue:B,onUpdateIssue:y}),Q&&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})})]})]})},K=({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:v,assetNumber:w,user:b,onCreateIssue:B,onUpdateIssue:y})=>{const{setNodeRef:C,isOver:x}=r.useDroppable({id:`grid-drop-zone-${c}`,disabled:"edit"!==t});return p.jsx("div",{ref:C,className:"grid-drop-zone",style:{border:x?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:x?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?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(V,{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:v,assetNumber:w,user:b,onCreateIssue:B,onUpdateIssue:y})},e.id))})}),p.jsx("div",{style:{border:x?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:x?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:x?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:x?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:x?"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:v,onAttachmentChange:w,datagridId:b="",workOrderNumber:B,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:F})=>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,Q,U;let E=null===(a=s.components)||void 0===a?void 0:a[i];const S=`${t.id||`component-${i}`}-entry-${b}-${o}-${i}`;return E=E?E.id!==S?Object.assign(Object.assign({},E),{id:S,basic:Object.assign(Object.assign({},E.basic),{showLabel:!1})}):Object.assign(Object.assign({},E),{id:E.id,basic:Object.assign(Object.assign({},E.basic),{showLabel:!1})}):Object.assign(Object.assign({},t),{id:S,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(E,!0):A(E,!0)}),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(E.name)&&p.jsxs("div",{style:{marginTop:"8px",width:"100%"},children:[p.jsx(H,{component:E,mode:"test",formTemplateId:f,formValue:d[E.id],formData:d,onThresholdActionCompletion:g,onThresholdIssueRaised:m,onNotesChange:v?e=>v(E.id,e):void 0,onAttachmentChange:w?e=>w(E.id,e):void 0,notes:(null===(l=E.basic)||void 0===l?void 0:l.notes)||(null===(c=d[E.id])||void 0===c?void 0:c.notes),attachments:(null===(u=E.basic)||void 0===u?void 0:u.attachments)||(null===(h=d[E.id])||void 0===h?void 0:h.attachments),workOrderNumber:B,assetNumber:y,user:C,onCreateIssue:x,onUpdateIssue:F}),"preview"===n&&((null===(Q=E.basic)||void 0===Q?void 0:Q.notes)||(null===(U=E.basic)||void 0===U?void 0:U.attachments))&&p.jsx(D,{component:E})]})]},`${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:v?e=>v(c.id,e):void 0,onAttachmentChange:w?e=>w(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:v,selectedComponent:w,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,V,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)=>{v&&v(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})})},[v,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(K,{gridComponents:ne,mode:n,onComponentSelect:f||(()=>{}),onComponentDelete:ae,onComponentEdit:m,onComponentUpdate:oe,selectedComponent:w||null,renderFormComponent:b||he,gridId:A,formData:i,formTemplateId:C,onThresholdActionCompletion:x,onThresholdIssueRaised:N,onNotesChange:_,onAttachmentChange:k,workOrderNumber:j,assetNumber:H,user:user,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===(V=r.datagrid)||void 0===V?void 0:V.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,user:user,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],v="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,formData:r,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}),v&&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:v}=n.useSortable({id:e.id,disabled:c}),w={transform:i.CSS.Transform.toString(f),transition:g,opacity:m?.3:1,zIndex:m?1e3:"auto"};return p.jsxs("div",{ref:d,style:w,className:`form-component table-component ${(null==A?void 0:A.id)===e.id?"selected":""} ${m?"dragging":""} ${v?"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:v,assetNumber:w,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:v,assetNumber:w,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:v,renderFormComponent:w,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,V,K,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=w||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]})}},[w,n,i,l]),ue={backgroundColor:(null===(V=r.styles)||void 0===V?void 0:V.backgroundColor)||"var(--df-color-fb-container)",borderColor:(null===(K=r.styles)||void 0===K?void 0:K.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:v||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=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},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,o;const l=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:c}=e;if("signature"===c)return l&&te(l)?p.jsx("div",{style:{marginTop:"5px"},children:p.jsx("img",{src:Ae(l),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"===c){const t=(null===(r=e.basic)||void 0===r?void 0:r.options)||[],A=(Array.isArray(l)?l:l?[l]:[]).map(e=>String(e));return p.jsx("div",{style:{marginTop:"5px",width:"100%"},children:t.map((e,t)=>{const r=A.includes(String(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"===c){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=String(l||"")===String(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"===c){const t=(null===(i=e.basic)||void 0===i?void 0:i.options)||[],A=l;return p.jsx("div",{style:ee.segmentContainer,children:t.map((e,t)=>{const r=String(A||"")===String(e.value||""),n=(e=>void 0!==(null==e?void 0:e.icon)&&null!==(null==e?void 0:e.icon)?e.icon:"pass"===re((null==e?void 0:e.value)||e)?"✓":"×")(e),i=e.color||e.backgroundColor,s=re(e.value);let a,o,l;i?r?(a=i,o="#ffffff",l=i):(a=`${i}20`,o=i,l=i):"pass"===s?r?(a="#00814b",o="#ffffff",l="#00814b"):(a="#34bd4914",o="#00814b",l="#e0e0e0"):r?(a="#dc3545",o="#ffffff",l="#dc3545"):(a="#fa323d14",o="#dc3545",l="#e0e0e0");const c=Object.assign(Object.assign({},ee.segmentButton),{backgroundColor:a,color:o,borderColor:l,borderWidth:"1px",borderStyle:"solid"});return p.jsxs("div",{style:c,children:[p.jsx("span",{style:ee.segmentIcon,children:n}),p.jsx("span",{children:e.value})]},t)})})}if("file"===c){const e=(Array.isArray(l)?l:l?[l]:[]).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"===c){if(l&&"object"==typeof l){const e=l;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"===c){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,{})})}if("select"===c){const t=(null===(o=e.basic)||void 0===o?void 0:o.options)||[],A=l;let r="";if(Array.isArray(A))r=A.map(e=>{const A=t.find(t=>String(t.value)===String(e));return A?A.label:e}).join(", ");else{const e=A,n=t.find(t=>String(t.value)===String(e));r=n?n.label||n.value:null!=e?String(e):""}return p.jsx("div",{style:ee.valueContainer,children:p.jsx("div",{style:ee.value,children:r})})}const u="object"==typeof l?JSON.stringify(l):String(l);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid","select"].includes(c)){const e="textarea"===c;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:u})})}return p.jsx("div",{style:ee.value,children:u})},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>
@@ -361,5 +361,5 @@ var oF=function(e,t){return(oF=Object.setPrototypeOf||{__proto__:[]}instanceof A
361
361
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
362
362
  * OTHER DEALINGS IN THE SOFTWARE.
363
363
  */
364
- var DF=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],MF=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function RF(e,t,A,r,n,i){if(!(isNaN(i)||i<1)){i|=0;var s=function(e,t,A,r,n){if("string"==typeof e&&(e=document.getElementById(e)),!e||"object"!==PF(e)||!("getContext"in e))throw new TypeError("Expecting canvas with `getContext` method in processCanvasRGB(A) calls!");var i=e.getContext("2d");try{return i.getImageData(t,A,r,n)}catch(e){throw new Error("unable to access image data: "+e)}}(e,t,A,r,n);s=function(e,t,A,r,n,i){for(var s,a=e.data,o=2*i+1,l=r-1,c=n-1,u=i+1,h=u*(u+1)/2,d=new VF,f=d,p=1;p<o;p++)f=f.next=new VF,p===u&&(s=f);f.next=d;for(var g=null,m=null,v=0,w=0,b=DF[i],B=MF[i],y=0;y<n;y++){f=d;for(var C=a[w],x=a[w+1],F=a[w+2],Q=a[w+3],U=0;U<u;U++)f.r=C,f.g=x,f.b=F,f.a=Q,f=f.next;for(var E=0,S=0,N=0,L=0,I=u*C,_=u*x,k=u*F,O=u*Q,T=h*C,j=h*x,H=h*F,P=h*Q,D=1;D<u;D++){var M=w+((l<D?l:D)<<2),R=a[M],V=a[M+1],K=a[M+2],G=a[M+3],z=u-D;T+=(f.r=R)*z,j+=(f.g=V)*z,H+=(f.b=K)*z,P+=(f.a=G)*z,E+=R,S+=V,N+=K,L+=G,f=f.next}g=d,m=s;for(var q=0;q<r;q++){var W=P*b>>>B;if(a[w+3]=W,0!==W){var X=255/W;a[w]=(T*b>>>B)*X,a[w+1]=(j*b>>>B)*X,a[w+2]=(H*b>>>B)*X}else a[w]=a[w+1]=a[w+2]=0;T-=I,j-=_,H-=k,P-=O,I-=g.r,_-=g.g,k-=g.b,O-=g.a;var Y=q+i+1;Y=v+(Y<l?Y:l)<<2,T+=E+=g.r=a[Y],j+=S+=g.g=a[Y+1],H+=N+=g.b=a[Y+2],P+=L+=g.a=a[Y+3],g=g.next;var J=m,$=J.r,Z=J.g,ee=J.b,te=J.a;I+=$,_+=Z,k+=ee,O+=te,E-=$,S-=Z,N-=ee,L-=te,m=m.next,w+=4}v+=r}for(var Ae=0;Ae<r;Ae++){var re=a[w=Ae<<2],ne=a[w+1],ie=a[w+2],se=a[w+3],ae=u*re,oe=u*ne,le=u*ie,ce=u*se,ue=h*re,he=h*ne,de=h*ie,fe=h*se;f=d;for(var pe=0;pe<u;pe++)f.r=re,f.g=ne,f.b=ie,f.a=se,f=f.next;for(var ge=r,me=0,ve=0,we=0,be=0,Be=1;Be<=i;Be++){w=ge+Ae<<2;var ye=u-Be;ue+=(f.r=re=a[w])*ye,he+=(f.g=ne=a[w+1])*ye,de+=(f.b=ie=a[w+2])*ye,fe+=(f.a=se=a[w+3])*ye,be+=re,me+=ne,ve+=ie,we+=se,f=f.next,Be<c&&(ge+=r)}w=Ae,g=d,m=s;for(var Ce=0;Ce<n;Ce++){var xe=w<<2;a[xe+3]=se=fe*b>>>B,se>0?(se=255/se,a[xe]=(ue*b>>>B)*se,a[xe+1]=(he*b>>>B)*se,a[xe+2]=(de*b>>>B)*se):a[xe]=a[xe+1]=a[xe+2]=0,ue-=ae,he-=oe,de-=le,fe-=ce,ae-=g.r,oe-=g.g,le-=g.b,ce-=g.a,xe=Ae+((xe=Ce+u)<c?xe:c)*r<<2,ue+=be+=g.r=a[xe],he+=me+=g.g=a[xe+1],de+=ve+=g.b=a[xe+2],fe+=we+=g.a=a[xe+3],g=g.next,ae+=re=m.r,oe+=ne=m.g,le+=ie=m.b,ce+=se=m.a,be-=re,me-=ne,ve-=ie,we-=se,m=m.next,w+=r}}return e}(s,0,0,r,n,i),e.getContext("2d").putImageData(s,t,A)}}var VF=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.r=0,this.g=0,this.b=0,this.a=0,this.next=null};var KF=Object.freeze({__proto__:null,offscreen:function(){var{DOMParser:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={window:null,ignoreAnimation:!0,ignoreMouse:!0,DOMParser:e,createCanvas:(e,t)=>new OffscreenCanvas(e,t),createImage:e=>Jv(function*(){var t=yield fetch(e),A=yield t.blob();return yield createImageBitmap(A)})()};return"undefined"==typeof DOMParser&&void 0!==e||Reflect.deleteProperty(t,"DOMParser"),t},node:function(e){var{DOMParser:t,canvas:A,fetch:r}=e;return{window:null,ignoreAnimation:!0,ignoreMouse:!0,DOMParser:t,fetch:r,createCanvas:A.createCanvas,createImage:A.loadImage}}});function GF(e){return e.replace(/(?!\u3000)\s+/gm," ")}function zF(e){return e.replace(/^[\n \t]+/,"")}function qF(e){return e.replace(/[\n \t]+$/,"")}function WF(e){return((e||"").match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm)||[]).map(parseFloat)}var XF=/^[A-Z-]+$/;function YF(e){return XF.test(e)?e.toLowerCase():e}function JF(e){var t=/url\(('([^']+)'|"([^"]+)"|([^'")]+))\)/.exec(e)||[];return t[2]||t[3]||t[4]}function $F(e){if(!e.startsWith("rgb"))return e;var t=3;return e.replace(/\d+(\.\d+)?/g,(e,A)=>t--&&A?String(Math.round(parseFloat(e))):e)}var ZF=/(\[[^\]]+\])/g,eQ=/(#[^\s+>~.[:]+)/g,tQ=/(\.[^\s+>~.[:]+)/g,AQ=/(::[^\s+>~.[:]+|:first-line|:first-letter|:before|:after)/gi,rQ=/(:[\w-]+\([^)]*\))/gi,nQ=/(:[^\s+>~.[:]+)/g,iQ=/([^\s+>~.[:]+)/g;function sQ(e,t){var A=t.exec(e);return A?[e.replace(t," "),A.length]:[e,0]}function aQ(e){var t=[0,0,0],A=e.replace(/:not\(([^)]*)\)/g," $1 ").replace(/{[\s\S]*/gm," "),r=0;return[A,r]=sQ(A,ZF),t[1]+=r,[A,r]=sQ(A,eQ),t[0]+=r,[A,r]=sQ(A,tQ),t[1]+=r,[A,r]=sQ(A,AQ),t[2]+=r,[A,r]=sQ(A,rQ),t[1]+=r,[A,r]=sQ(A,nQ),t[1]+=r,A=A.replace(/[*\s+>~]/g," ").replace(/[#.]/g," "),[A,r]=sQ(A,iQ),t[2]+=r,t.join("")}var oQ=1e-8;function lQ(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2))}function cQ(e,t){return(e[0]*t[0]+e[1]*t[1])/(lQ(e)*lQ(t))}function uQ(e,t){return(e[0]*t[1]<e[1]*t[0]?-1:1)*Math.acos(cQ(e,t))}function hQ(e){return e*e*e}function dQ(e){return 3*e*e*(1-e)}function fQ(e){return 3*e*(1-e)*(1-e)}function pQ(e){return(1-e)*(1-e)*(1-e)}function gQ(e){return e*e}function mQ(e){return 2*e*(1-e)}function vQ(e){return(1-e)*(1-e)}class wQ{constructor(e,t,A){this.document=e,this.name=t,this.value=A,this.isNormalizedColor=!1}static empty(e){return new wQ(e,"EMPTY","")}split(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:" ",{document:t,name:A}=this;return GF(this.getString()).trim().split(e).map(e=>new wQ(t,A,e))}hasValue(e){var{value:t}=this;return null!==t&&""!==t&&(e||0!==t)&&void 0!==t}isString(e){var{value:t}=this,A="string"==typeof t;return A&&e?e.test(t):A}isUrlDefinition(){return this.isString(/^url\(/)}isPixels(){if(!this.hasValue())return!1;var e=this.getString();switch(!0){case e.endsWith("px"):case/^[0-9]+$/.test(e):return!0;default:return!1}}setValue(e){return this.value=e,this}getValue(e){return void 0===e||this.hasValue()?this.value:e}getNumber(e){if(!this.hasValue())return void 0===e?0:parseFloat(e);var{value:t}=this,A=parseFloat(t);return this.isString(/%$/)&&(A/=100),A}getString(e){return void 0===e||this.hasValue()?void 0===this.value?"":String(this.value):String(e)}getColor(e){var t=this.getString(e);return this.isNormalizedColor||(this.isNormalizedColor=!0,t=$F(t),this.value=t),t}getDpi(){return 96}getRem(){return this.document.rootEmSize}getEm(){return this.document.emSize}getUnits(){return this.getString().replace(/[0-9.-]/g,"")}getPixels(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasValue())return 0;var[A,r]="boolean"==typeof e?[void 0,e]:[e],{viewPort:n}=this.document.screen;switch(!0){case this.isString(/vmin$/):return this.getNumber()/100*Math.min(n.computeSize("x"),n.computeSize("y"));case this.isString(/vmax$/):return this.getNumber()/100*Math.max(n.computeSize("x"),n.computeSize("y"));case this.isString(/vw$/):return this.getNumber()/100*n.computeSize("x");case this.isString(/vh$/):return this.getNumber()/100*n.computeSize("y");case this.isString(/rem$/):return this.getNumber()*this.getRem();case this.isString(/em$/):return this.getNumber()*this.getEm();case this.isString(/ex$/):return this.getNumber()*this.getEm()/2;case this.isString(/px$/):return this.getNumber();case this.isString(/pt$/):return this.getNumber()*this.getDpi()*(1/72);case this.isString(/pc$/):return 15*this.getNumber();case this.isString(/cm$/):return this.getNumber()*this.getDpi()/2.54;case this.isString(/mm$/):return this.getNumber()*this.getDpi()/25.4;case this.isString(/in$/):return this.getNumber()*this.getDpi();case this.isString(/%$/)&&r:return this.getNumber()*this.getEm();case this.isString(/%$/):return this.getNumber()*n.computeSize(A);default:var i=this.getNumber();return t&&i<1?i*n.computeSize(A):i}}getMilliseconds(){return this.hasValue()?this.isString(/ms$/)?this.getNumber():1e3*this.getNumber():0}getRadians(){if(!this.hasValue())return 0;switch(!0){case this.isString(/deg$/):return this.getNumber()*(Math.PI/180);case this.isString(/grad$/):return this.getNumber()*(Math.PI/200);case this.isString(/rad$/):return this.getNumber();default:return this.getNumber()*(Math.PI/180)}}getDefinition(){var e=this.getString(),t=/#([^)'"]+)/.exec(e);return t&&(t=t[1]),t||(t=e),this.document.definitions[t]}getFillStyleDefinition(e,t){var A=this.getDefinition();if(!A)return null;if("function"==typeof A.createGradient)return A.createGradient(this.document.ctx,e,t);if("function"==typeof A.createPattern){if(A.getHrefAttribute().hasValue()){var r=A.getAttribute("patternTransform");A=A.getHrefAttribute().getDefinition(),r.hasValue()&&A.getAttribute("patternTransform",!0).setValue(r.value)}return A.createPattern(this.document.ctx,e,t)}return null}getTextBaseline(){return this.hasValue()?wQ.textBaselineMapping[this.getString()]:null}addOpacity(e){for(var t=this.getColor(),A=t.length,r=0,n=0;n<A&&(","===t[n]&&r++,3!==r);n++);if(e.hasValue()&&this.isString()&&3!==r){var i=new Gx(t);i.ok&&(i.alpha=e.getNumber(),t=i.toRGBA())}return new wQ(this.document,this.name,t)}}wQ.textBaselineMapping={baseline:"alphabetic","before-edge":"top","text-before-edge":"top",middle:"middle",central:"middle","after-edge":"bottom","text-after-edge":"bottom",ideographic:"ideographic",alphabetic:"alphabetic",hanging:"hanging",mathematical:"alphabetic"};class bQ{constructor(){this.viewPorts=[]}clear(){this.viewPorts=[]}setCurrent(e,t){this.viewPorts.push({width:e,height:t})}removeCurrent(){this.viewPorts.pop()}getCurrent(){var{viewPorts:e}=this;return e[e.length-1]}get width(){return this.getCurrent().width}get height(){return this.getCurrent().height}computeSize(e){return"number"==typeof e?e:"x"===e?this.width:"y"===e?this.height:Math.sqrt(Math.pow(this.width,2)+Math.pow(this.height,2))/Math.sqrt(2)}}class BQ{constructor(e,t){this.x=e,this.y=t}static parse(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,[A=t,r=t]=WF(e);return new BQ(A,r)}static parseScale(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,[A=t,r=A]=WF(e);return new BQ(A,r)}static parsePath(e){for(var t=WF(e),A=t.length,r=[],n=0;n<A;n+=2)r.push(new BQ(t[n],t[n+1]));return r}angleTo(e){return Math.atan2(e.y-this.y,e.x-this.x)}applyTransform(e){var{x:t,y:A}=this,r=t*e[0]+A*e[2]+e[4],n=t*e[1]+A*e[3]+e[5];this.x=r,this.y=n}}class yQ{constructor(e){this.screen=e,this.working=!1,this.events=[],this.eventElements=[],this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this)}isWorking(){return this.working}start(){if(!this.working){var{screen:e,onClick:t,onMouseMove:A}=this,r=e.ctx.canvas;r.onclick=t,r.onmousemove=A,this.working=!0}}stop(){if(this.working){var e=this.screen.ctx.canvas;this.working=!1,e.onclick=null,e.onmousemove=null}}hasEvents(){return this.working&&this.events.length>0}runEvents(){if(this.working){var{screen:e,events:t,eventElements:A}=this,{style:r}=e.ctx.canvas;r&&(r.cursor=""),t.forEach((e,t)=>{for(var{run:r}=e,n=A[t];n;)r(n),n=n.parent}),this.events=[],this.eventElements=[]}}checkPath(e,t){if(this.working&&t){var{events:A,eventElements:r}=this;A.forEach((A,n)=>{var{x:i,y:s}=A;!r[n]&&t.isPointInPath&&t.isPointInPath(i,s)&&(r[n]=e)})}}checkBoundingBox(e,t){if(this.working&&t){var{events:A,eventElements:r}=this;A.forEach((A,n)=>{var{x:i,y:s}=A;!r[n]&&t.isPointInBox(i,s)&&(r[n]=e)})}}mapXY(e,t){for(var{window:A,ctx:r}=this.screen,n=new BQ(e,t),i=r.canvas;i;)n.x-=i.offsetLeft,n.y-=i.offsetTop,i=i.offsetParent;return A.scrollX&&(n.x+=A.scrollX),A.scrollY&&(n.y+=A.scrollY),n}onClick(e){var{x:t,y:A}=this.mapXY(e.clientX,e.clientY);this.events.push({type:"onclick",x:t,y:A,run(e){e.onClick&&e.onClick()}})}onMouseMove(e){var{x:t,y:A}=this.mapXY(e.clientX,e.clientY);this.events.push({type:"onmousemove",x:t,y:A,run(e){e.onMouseMove&&e.onMouseMove()}})}}var CQ="undefined"!=typeof window?window:null,xQ="undefined"!=typeof fetch?fetch.bind(void 0):null;class FQ{constructor(e){var{fetch:t=xQ,window:A=CQ}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.ctx=e,this.FRAMERATE=30,this.MAX_VIRTUAL_PIXELS=3e4,this.CLIENT_WIDTH=800,this.CLIENT_HEIGHT=600,this.viewPort=new bQ,this.mouse=new yQ(this),this.animations=[],this.waits=[],this.frameDuration=0,this.isReadyLock=!1,this.isFirstRender=!0,this.intervalId=null,this.window=A,this.fetch=t}wait(e){this.waits.push(e)}ready(){return this.readyPromise?this.readyPromise:Promise.resolve()}isReady(){if(this.isReadyLock)return!0;var e=this.waits.every(e=>e());return e&&(this.waits=[],this.resolveReady&&this.resolveReady()),this.isReadyLock=e,e}setDefaults(e){e.strokeStyle="rgba(0,0,0,0)",e.lineCap="butt",e.lineJoin="miter",e.miterLimit=4}setViewBox(e){var{document:t,ctx:A,aspectRatio:r,width:n,desiredWidth:i,height:s,desiredHeight:a,minX:o=0,minY:l=0,refX:c,refY:u,clip:h=!1,clipX:d=0,clipY:f=0}=e,p=GF(r).replace(/^defer\s/,""),[g,m]=p.split(" "),v=g||"xMidYMid",w=m||"meet",b=n/i,B=s/a,y=Math.min(b,B),C=Math.max(b,B),x=i,F=a;"meet"===w&&(x*=y,F*=y),"slice"===w&&(x*=C,F*=C);var Q=new wQ(t,"refX",c),U=new wQ(t,"refY",u),E=Q.hasValue()&&U.hasValue();if(E&&A.translate(-y*Q.getPixels("x"),-y*U.getPixels("y")),h){var S=y*d,N=y*f;A.beginPath(),A.moveTo(S,N),A.lineTo(n,N),A.lineTo(n,s),A.lineTo(S,s),A.closePath(),A.clip()}if(!E){var L="meet"===w&&y===B,I="slice"===w&&C===B,_="meet"===w&&y===b,k="slice"===w&&C===b;v.startsWith("xMid")&&(L||I)&&A.translate(n/2-x/2,0),v.endsWith("YMid")&&(_||k)&&A.translate(0,s/2-F/2),v.startsWith("xMax")&&(L||I)&&A.translate(n-x,0),v.endsWith("YMax")&&(_||k)&&A.translate(0,s-F)}switch(!0){case"none"===v:A.scale(b,B);break;case"meet"===w:A.scale(y,y);break;case"slice"===w:A.scale(C,C)}A.translate(-o,-l)}start(e){var{enableRedraw:t=!1,ignoreMouse:A=!1,ignoreAnimation:r=!1,ignoreDimensions:n=!1,ignoreClear:i=!1,forceRedraw:s,scaleWidth:a,scaleHeight:o,offsetX:l,offsetY:c}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{FRAMERATE:u,mouse:h}=this,d=1e3/u;if(this.frameDuration=d,this.readyPromise=new Promise(e=>{this.resolveReady=e}),this.isReady()&&this.render(e,n,i,a,o,l,c),t){var f=Date.now(),p=f,g=0,m=()=>{f=Date.now(),(g=f-p)>=d&&(p=f-g%d,this.shouldUpdate(r,s)&&(this.render(e,n,i,a,o,l,c),h.runEvents())),this.intervalId=Nx(m)};A||h.start(),this.intervalId=Nx(m)}}stop(){this.intervalId&&(Nx.cancel(this.intervalId),this.intervalId=null),this.mouse.stop()}shouldUpdate(e,t){if(!e){var{frameDuration:A}=this;if(this.animations.reduce((e,t)=>t.update(A)||e,!1))return!0}return!("function"!=typeof t||!t())||(!(this.isReadyLock||!this.isReady())||!!this.mouse.hasEvents())}render(e,t,A,r,n,i,s){var{CLIENT_WIDTH:a,CLIENT_HEIGHT:o,viewPort:l,ctx:c,isFirstRender:u}=this,h=c.canvas;l.clear(),h.width&&h.height?l.setCurrent(h.width,h.height):l.setCurrent(a,o);var d=e.getStyle("width"),f=e.getStyle("height");!t&&(u||"number"!=typeof r&&"number"!=typeof n)&&(d.hasValue()&&(h.width=d.getPixels("x"),h.style&&(h.style.width="".concat(h.width,"px"))),f.hasValue()&&(h.height=f.getPixels("y"),h.style&&(h.style.height="".concat(h.height,"px"))));var p=h.clientWidth||h.width,g=h.clientHeight||h.height;if(t&&d.hasValue()&&f.hasValue()&&(p=d.getPixels("x"),g=f.getPixels("y")),l.setCurrent(p,g),"number"==typeof i&&e.getAttribute("x",!0).setValue(i),"number"==typeof s&&e.getAttribute("y",!0).setValue(s),"number"==typeof r||"number"==typeof n){var m=WF(e.getAttribute("viewBox").getString()),v=0,w=0;if("number"==typeof r){var b=e.getStyle("width");b.hasValue()?v=b.getPixels("x")/r:isNaN(m[2])||(v=m[2]/r)}if("number"==typeof n){var B=e.getStyle("height");B.hasValue()?w=B.getPixels("y")/n:isNaN(m[3])||(w=m[3]/n)}v||(v=w),w||(w=v),e.getAttribute("width",!0).setValue(r),e.getAttribute("height",!0).setValue(n);var y=e.getStyle("transform",!0,!0);y.setValue("".concat(y.getString()," scale(").concat(1/v,", ").concat(1/w,")"))}A||c.clearRect(0,0,p,g),e.render(c),u&&(this.isFirstRender=!1)}}FQ.defaultWindow=CQ,FQ.defaultFetch=xQ;var{defaultFetch:QQ}=FQ,UQ="undefined"!=typeof DOMParser?DOMParser:null;class EQ{constructor(){var{fetch:e=QQ,DOMParser:t=UQ}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.fetch=e,this.DOMParser=t}parse(e){var t=this;return Jv(function*(){return e.startsWith("<")?t.parseFromString(e):t.load(e)})()}parseFromString(e){var t=new this.DOMParser;try{return this.checkDocument(t.parseFromString(e,"image/svg+xml"))}catch(A){return this.checkDocument(t.parseFromString(e,"text/xml"))}}checkDocument(e){var t=e.getElementsByTagName("parsererror")[0];if(t)throw new Error(t.textContent);return e}load(e){var t=this;return Jv(function*(){var A=yield t.fetch(e),r=yield A.text();return t.parseFromString(r)})()}}class SQ{constructor(e,t){this.type="translate",this.point=null,this.point=BQ.parse(t)}apply(e){var{x:t,y:A}=this.point;e.translate(t||0,A||0)}unapply(e){var{x:t,y:A}=this.point;e.translate(-1*t||0,-1*A||0)}applyToPoint(e){var{x:t,y:A}=this.point;e.applyTransform([1,0,0,1,t||0,A||0])}}class NQ{constructor(e,t,A){this.type="rotate",this.angle=null,this.originX=null,this.originY=null,this.cx=0,this.cy=0;var r=WF(t);this.angle=new wQ(e,"angle",r[0]),this.originX=A[0],this.originY=A[1],this.cx=r[1]||0,this.cy=r[2]||0}apply(e){var{cx:t,cy:A,originX:r,originY:n,angle:i}=this,s=t+r.getPixels("x"),a=A+n.getPixels("y");e.translate(s,a),e.rotate(i.getRadians()),e.translate(-s,-a)}unapply(e){var{cx:t,cy:A,originX:r,originY:n,angle:i}=this,s=t+r.getPixels("x"),a=A+n.getPixels("y");e.translate(s,a),e.rotate(-1*i.getRadians()),e.translate(-s,-a)}applyToPoint(e){var{cx:t,cy:A,angle:r}=this,n=r.getRadians();e.applyTransform([1,0,0,1,t||0,A||0]),e.applyTransform([Math.cos(n),Math.sin(n),-Math.sin(n),Math.cos(n),0,0]),e.applyTransform([1,0,0,1,-t||0,-A||0])}}class LQ{constructor(e,t,A){this.type="scale",this.scale=null,this.originX=null,this.originY=null;var r=BQ.parseScale(t);0!==r.x&&0!==r.y||(r.x=oQ,r.y=oQ),this.scale=r,this.originX=A[0],this.originY=A[1]}apply(e){var{scale:{x:t,y:A},originX:r,originY:n}=this,i=r.getPixels("x"),s=n.getPixels("y");e.translate(i,s),e.scale(t,A||t),e.translate(-i,-s)}unapply(e){var{scale:{x:t,y:A},originX:r,originY:n}=this,i=r.getPixels("x"),s=n.getPixels("y");e.translate(i,s),e.scale(1/t,1/A||t),e.translate(-i,-s)}applyToPoint(e){var{x:t,y:A}=this.scale;e.applyTransform([t||0,0,0,A||0,0,0])}}class IQ{constructor(e,t,A){this.type="matrix",this.matrix=[],this.originX=null,this.originY=null,this.matrix=WF(t),this.originX=A[0],this.originY=A[1]}apply(e){var{originX:t,originY:A,matrix:r}=this,n=t.getPixels("x"),i=A.getPixels("y");e.translate(n,i),e.transform(r[0],r[1],r[2],r[3],r[4],r[5]),e.translate(-n,-i)}unapply(e){var{originX:t,originY:A,matrix:r}=this,n=r[0],i=r[2],s=r[4],a=r[1],o=r[3],l=r[5],c=1/(n*(1*o-0*l)-i*(1*a-0*l)+s*(0*a-0*o)),u=t.getPixels("x"),h=A.getPixels("y");e.translate(u,h),e.transform(c*(1*o-0*l),c*(0*l-1*a),c*(0*s-1*i),c*(1*n-0*s),c*(i*l-s*o),c*(s*a-n*l)),e.translate(-u,-h)}applyToPoint(e){e.applyTransform(this.matrix)}}class _Q extends IQ{constructor(e,t,A){super(e,t,A),this.type="skew",this.angle=null,this.angle=new wQ(e,"angle",t)}}class kQ extends _Q{constructor(e,t,A){super(e,t,A),this.type="skewX",this.matrix=[1,0,Math.tan(this.angle.getRadians()),1,0,0]}}class OQ extends _Q{constructor(e,t,A){super(e,t,A),this.type="skewY",this.matrix=[1,Math.tan(this.angle.getRadians()),0,1,0,0]}}class TQ{constructor(e,t,A){this.document=e,this.transforms=[];var r=function(e){return GF(e).trim().replace(/\)([a-zA-Z])/g,") $1").replace(/\)(\s?,\s?)/g,") ").split(/\s(?=[a-z])/)}(t);r.forEach(e=>{if("none"!==e){var[t,r]=function(e){var[t,A]=e.split("(");return[t.trim(),A.trim().replace(")","")]}(e),n=TQ.transformTypes[t];void 0!==n&&this.transforms.push(new n(this.document,r,A))}})}static fromElement(e,t){var A=t.getStyle("transform",!1,!0),[r,n=r]=t.getStyle("transform-origin",!1,!0).split(),i=[r,n];return A.hasValue()?new TQ(e,A.getString(),i):null}apply(e){for(var{transforms:t}=this,A=t.length,r=0;r<A;r++)t[r].apply(e)}unapply(e){for(var{transforms:t}=this,A=t.length-1;A>=0;A--)t[A].unapply(e)}applyToPoint(e){for(var{transforms:t}=this,A=t.length,r=0;r<A;r++)t[r].applyToPoint(e)}}TQ.transformTypes={translate:SQ,rotate:NQ,scale:LQ,matrix:IQ,skewX:kQ,skewY:OQ};class jQ{constructor(e,t){var A=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(this.document=e,this.node=t,this.captureTextNodes=A,this.attributes=Object.create(null),this.styles=Object.create(null),this.stylesSpecificity=Object.create(null),this.animationFrozen=!1,this.animationFrozenValue="",this.parent=null,this.children=[],t&&1===t.nodeType){if(Array.from(t.attributes).forEach(t=>{var A=YF(t.nodeName);this.attributes[A]=new wQ(e,A,t.value)}),this.addStylesFromStyleDefinition(),this.getAttribute("style").hasValue()){var r=this.getAttribute("style").getString().split(";").map(e=>e.trim());r.forEach(t=>{if(t){var[A,r]=t.split(":").map(e=>e.trim());this.styles[A]=new wQ(e,A,r)}})}var{definitions:n}=e,i=this.getAttribute("id");i.hasValue()&&(n[i.getString()]||(n[i.getString()]=this)),Array.from(t.childNodes).forEach(t=>{if(1===t.nodeType)this.addChild(t);else if(A&&(3===t.nodeType||4===t.nodeType)){var r=e.createTextNode(t);r.getText().length>0&&this.addChild(r)}})}}getAttribute(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],A=this.attributes[e];if(!A&&t){var r=new wQ(this.document,e,"");return this.attributes[e]=r,r}return A||wQ.empty(this.document)}getHrefAttribute(){for(var e in this.attributes)if("href"===e||e.endsWith(":href"))return this.attributes[e];return wQ.empty(this.document)}getStyle(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],A=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this.styles[e];if(r)return r;var n=this.getAttribute(e);if(null!=n&&n.hasValue())return this.styles[e]=n,n;if(!A){var{parent:i}=this;if(i){var s=i.getStyle(e);if(null!=s&&s.hasValue())return s}}if(t){var a=new wQ(this.document,e,"");return this.styles[e]=a,a}return r||wQ.empty(this.document)}render(e){if("none"!==this.getStyle("display").getString()&&"hidden"!==this.getStyle("visibility").getString()){if(e.save(),this.getStyle("mask").hasValue()){var t=this.getStyle("mask").getDefinition();t&&(this.applyEffects(e),t.apply(e,this))}else if("none"!==this.getStyle("filter").getValue("none")){var A=this.getStyle("filter").getDefinition();A&&(this.applyEffects(e),A.apply(e,this))}else this.setContext(e),this.renderChildren(e),this.clearContext(e);e.restore()}}setContext(e){}applyEffects(e){var t=TQ.fromElement(this.document,this);t&&t.apply(e);var A=this.getStyle("clip-path",!1,!0);if(A.hasValue()){var r=A.getDefinition();r&&r.apply(e)}}clearContext(e){}renderChildren(e){this.children.forEach(t=>{t.render(e)})}addChild(e){var t=e instanceof jQ?e:this.document.createElement(e);t.parent=this,jQ.ignoreChildTypes.includes(t.type)||this.children.push(t)}matchesSelector(e){var t,{node:A}=this;if("function"==typeof A.matches)return A.matches(e);var r=null===(t=A.getAttribute)||void 0===t?void 0:t.call(A,"class");return!(!r||""===r)&&r.split(" ").some(t=>".".concat(t)===e)}addStylesFromStyleDefinition(){var{styles:e,stylesSpecificity:t}=this.document;for(var A in e)if(!A.startsWith("@")&&this.matchesSelector(A)){var r=e[A],n=t[A];if(r)for(var i in r){var s=this.stylesSpecificity[i];void 0===s&&(s="000"),n>=s&&(this.styles[i]=r[i],this.stylesSpecificity[i]=n)}}}removeStyles(e,t){return t.reduce((t,A)=>{var r=e.getStyle(A);if(!r.hasValue())return t;var n=r.getString();return r.setValue(""),[...t,[A,n]]},[])}restoreStyles(e,t){t.forEach(t=>{var[A,r]=t;e.getStyle(A,!0).setValue(r)})}isFirstChild(){var e;return 0===(null===(e=this.parent)||void 0===e?void 0:e.children.indexOf(this))}}jQ.ignoreChildTypes=["title"];class HQ extends jQ{constructor(e,t,A){super(e,t,A)}}function PQ(e){var t=e.trim();return/^('|")/.test(t)?t:'"'.concat(t,'"')}function DQ(e){if(!e)return"";var t=e.trim().toLowerCase();switch(t){case"normal":case"italic":case"oblique":case"inherit":case"initial":case"unset":return t;default:return/^oblique\s+(-|)\d+deg$/.test(t)?t:""}}function MQ(e){if(!e)return"";var t=e.trim().toLowerCase();switch(t){case"normal":case"bold":case"lighter":case"bolder":case"inherit":case"initial":case"unset":return t;default:return/^[\d.]+$/.test(t)?t:""}}class RQ{constructor(e,t,A,r,n,i){var s=i?"string"==typeof i?RQ.parse(i):i:{};this.fontFamily=n||s.fontFamily,this.fontSize=r||s.fontSize,this.fontStyle=e||s.fontStyle,this.fontWeight=A||s.fontWeight,this.fontVariant=t||s.fontVariant}static parse(){var e=arguments.length>1?arguments[1]:void 0,t="",A="",r="",n="",i="",s=GF(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().split(" "),a={fontSize:!1,fontStyle:!1,fontWeight:!1,fontVariant:!1};return s.forEach(e=>{switch(!0){case!a.fontStyle&&RQ.styles.includes(e):"inherit"!==e&&(t=e),a.fontStyle=!0;break;case!a.fontVariant&&RQ.variants.includes(e):"inherit"!==e&&(A=e),a.fontStyle=!0,a.fontVariant=!0;break;case!a.fontWeight&&RQ.weights.includes(e):"inherit"!==e&&(r=e),a.fontStyle=!0,a.fontVariant=!0,a.fontWeight=!0;break;case!a.fontSize:"inherit"!==e&&([n]=e.split("/")),a.fontStyle=!0,a.fontVariant=!0,a.fontWeight=!0,a.fontSize=!0;break;default:"inherit"!==e&&(i+=e)}}),new RQ(t,A,r,n,i,e)}toString(){return[DQ(this.fontStyle),this.fontVariant,MQ(this.fontWeight),this.fontSize,(e=this.fontFamily,"undefined"==typeof process?e:e.trim().split(",").map(PQ).join(","))].join(" ").trim();var e}}RQ.styles="normal|italic|oblique|inherit",RQ.variants="normal|small-caps|inherit",RQ.weights="normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit";class VQ{constructor(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Number.NaN,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Number.NaN,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Number.NaN,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Number.NaN;this.x1=e,this.y1=t,this.x2=A,this.y2=r,this.addPoint(e,t),this.addPoint(A,r)}get x(){return this.x1}get y(){return this.y1}get width(){return this.x2-this.x1}get height(){return this.y2-this.y1}addPoint(e,t){void 0!==e&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=e,this.x2=e),e<this.x1&&(this.x1=e),e>this.x2&&(this.x2=e)),void 0!==t&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),t<this.y1&&(this.y1=t),t>this.y2&&(this.y2=t))}addX(e){this.addPoint(e,null)}addY(e){this.addPoint(null,e)}addBoundingBox(e){if(e){var{x1:t,y1:A,x2:r,y2:n}=e;this.addPoint(t,A),this.addPoint(r,n)}}sumCubic(e,t,A,r,n){return Math.pow(1-e,3)*t+3*Math.pow(1-e,2)*e*A+3*(1-e)*Math.pow(e,2)*r+Math.pow(e,3)*n}bezierCurveAdd(e,t,A,r,n){var i=6*t-12*A+6*r,s=-3*t+9*A-9*r+3*n,a=3*A-3*t;if(0!==s){var o=Math.pow(i,2)-4*a*s;if(!(o<0)){var l=(-i+Math.sqrt(o))/(2*s);0<l&&l<1&&(e?this.addX(this.sumCubic(l,t,A,r,n)):this.addY(this.sumCubic(l,t,A,r,n)));var c=(-i-Math.sqrt(o))/(2*s);0<c&&c<1&&(e?this.addX(this.sumCubic(c,t,A,r,n)):this.addY(this.sumCubic(c,t,A,r,n)))}}else{if(0===i)return;var u=-a/i;0<u&&u<1&&(e?this.addX(this.sumCubic(u,t,A,r,n)):this.addY(this.sumCubic(u,t,A,r,n)))}}addBezierCurve(e,t,A,r,n,i,s,a){this.addPoint(e,t),this.addPoint(s,a),this.bezierCurveAdd(!0,e,A,n,s),this.bezierCurveAdd(!1,t,r,i,a)}addQuadraticCurve(e,t,A,r,n,i){var s=e+2/3*(A-e),a=t+2/3*(r-t),o=s+1/3*(n-e),l=a+1/3*(i-t);this.addBezierCurve(e,t,s,o,a,l,n,i)}isPointInBox(e,t){var{x1:A,y1:r,x2:n,y2:i}=this;return A<=e&&e<=n&&r<=t&&t<=i}}class KQ extends QF{constructor(e){super(e.replace(/([+\-.])\s+/gm,"$1").replace(/[^MmZzLlHhVvCcSsQqTtAae\d\s.,+-].*/g,"")),this.control=null,this.start=null,this.current=null,this.command=null,this.commands=this.commands,this.i=-1,this.previousCommand=null,this.points=[],this.angles=[]}reset(){this.i=-1,this.command=null,this.previousCommand=null,this.start=new BQ(0,0),this.control=new BQ(0,0),this.current=new BQ(0,0),this.points=[],this.angles=[]}isEnd(){var{i:e,commands:t}=this;return e>=t.length-1}next(){var e=this.commands[++this.i];return this.previousCommand=this.command,this.command=e,e}getPoint(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"x",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"y",A=new BQ(this.command[e],this.command[t]);return this.makeAbsolute(A)}getAsControlPoint(e,t){var A=this.getPoint(e,t);return this.control=A,A}getAsCurrentPoint(e,t){var A=this.getPoint(e,t);return this.current=A,A}getReflectedControlPoint(){var e=this.previousCommand.type;if(e!==QF.CURVE_TO&&e!==QF.SMOOTH_CURVE_TO&&e!==QF.QUAD_TO&&e!==QF.SMOOTH_QUAD_TO)return this.current;var{current:{x:t,y:A},control:{x:r,y:n}}=this;return new BQ(2*t-r,2*A-n)}makeAbsolute(e){if(this.command.relative){var{x:t,y:A}=this.current;e.x+=t,e.y+=A}return e}addMarker(e,t,A){var{points:r,angles:n}=this;A&&n.length>0&&!n[n.length-1]&&(n[n.length-1]=r[r.length-1].angleTo(A)),this.addMarkerAngle(e,t?t.angleTo(e):null)}addMarkerAngle(e,t){this.points.push(e),this.angles.push(t)}getMarkerPoints(){return this.points}getMarkerAngles(){for(var{angles:e}=this,t=e.length,A=0;A<t;A++)if(!e[A])for(var r=A+1;r<t;r++)if(e[r]){e[A]=e[r];break}return e}}class GQ extends jQ{constructor(){super(...arguments),this.modifiedEmSizeStack=!1}calculateOpacity(){for(var e=1,t=this;t;){var A=t.getStyle("opacity",!1,!0);A.hasValue(!0)&&(e*=A.getNumber()),t=t.parent}return e}setContext(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!t){var A=this.getStyle("fill"),r=this.getStyle("fill-opacity"),n=this.getStyle("stroke"),i=this.getStyle("stroke-opacity");if(A.isUrlDefinition()){var s=A.getFillStyleDefinition(this,r);s&&(e.fillStyle=s)}else if(A.hasValue()){"currentColor"===A.getString()&&A.setValue(this.getStyle("color").getColor());var a=A.getColor();"inherit"!==a&&(e.fillStyle="none"===a?"rgba(0,0,0,0)":a)}if(r.hasValue()){var o=new wQ(this.document,"fill",e.fillStyle).addOpacity(r).getColor();e.fillStyle=o}if(n.isUrlDefinition()){var l=n.getFillStyleDefinition(this,i);l&&(e.strokeStyle=l)}else if(n.hasValue()){"currentColor"===n.getString()&&n.setValue(this.getStyle("color").getColor());var c=n.getString();"inherit"!==c&&(e.strokeStyle="none"===c?"rgba(0,0,0,0)":c)}if(i.hasValue()){var u=new wQ(this.document,"stroke",e.strokeStyle).addOpacity(i).getString();e.strokeStyle=u}var h=this.getStyle("stroke-width");if(h.hasValue()){var d=h.getPixels();e.lineWidth=d||oQ}var f=this.getStyle("stroke-linecap"),p=this.getStyle("stroke-linejoin"),g=this.getStyle("stroke-miterlimit"),m=this.getStyle("stroke-dasharray"),v=this.getStyle("stroke-dashoffset");if(f.hasValue()&&(e.lineCap=f.getString()),p.hasValue()&&(e.lineJoin=p.getString()),g.hasValue()&&(e.miterLimit=g.getNumber()),m.hasValue()&&"none"!==m.getString()){var w=WF(m.getString());void 0!==e.setLineDash?e.setLineDash(w):void 0!==e.webkitLineDash?e.webkitLineDash=w:void 0===e.mozDash||1===w.length&&0===w[0]||(e.mozDash=w);var b=v.getPixels();void 0!==e.lineDashOffset?e.lineDashOffset=b:void 0!==e.webkitLineDashOffset?e.webkitLineDashOffset=b:void 0!==e.mozDashOffset&&(e.mozDashOffset=b)}}if(this.modifiedEmSizeStack=!1,void 0!==e.font){var B=this.getStyle("font"),y=this.getStyle("font-style"),C=this.getStyle("font-variant"),x=this.getStyle("font-weight"),F=this.getStyle("font-size"),Q=this.getStyle("font-family"),U=new RQ(y.getString(),C.getString(),x.getString(),F.hasValue()?"".concat(F.getPixels(!0),"px"):"",Q.getString(),RQ.parse(B.getString(),e.font));y.setValue(U.fontStyle),C.setValue(U.fontVariant),x.setValue(U.fontWeight),F.setValue(U.fontSize),Q.setValue(U.fontFamily),e.font=U.toString(),F.isPixels()&&(this.document.emSize=F.getPixels(),this.modifiedEmSizeStack=!0)}t||(this.applyEffects(e),e.globalAlpha=this.calculateOpacity())}clearContext(e){super.clearContext(e),this.modifiedEmSizeStack&&this.document.popEmSize()}}class zQ extends GQ{constructor(e,t,A){super(e,t,A),this.type="path",this.pathParser=null,this.pathParser=new KQ(this.getAttribute("d").getString())}path(e){var{pathParser:t}=this,A=new VQ;for(t.reset(),e&&e.beginPath();!t.isEnd();)switch(t.next().type){case KQ.MOVE_TO:this.pathM(e,A);break;case KQ.LINE_TO:this.pathL(e,A);break;case KQ.HORIZ_LINE_TO:this.pathH(e,A);break;case KQ.VERT_LINE_TO:this.pathV(e,A);break;case KQ.CURVE_TO:this.pathC(e,A);break;case KQ.SMOOTH_CURVE_TO:this.pathS(e,A);break;case KQ.QUAD_TO:this.pathQ(e,A);break;case KQ.SMOOTH_QUAD_TO:this.pathT(e,A);break;case KQ.ARC:this.pathA(e,A);break;case KQ.CLOSE_PATH:this.pathZ(e,A)}return A}getBoundingBox(e){return this.path()}getMarkers(){var{pathParser:e}=this,t=e.getMarkerPoints(),A=e.getMarkerAngles(),r=t.map((e,t)=>[e,A[t]]);return r}renderChildren(e){this.path(e),this.document.screen.mouse.checkPath(this,e);var t=this.getStyle("fill-rule");""!==e.fillStyle&&("inherit"!==t.getString("inherit")?e.fill(t.getString()):e.fill()),""!==e.strokeStyle&&("non-scaling-stroke"===this.getAttribute("vector-effect").getString()?(e.save(),e.setTransform(1,0,0,1,0,0),e.stroke(),e.restore()):e.stroke());var A=this.getMarkers();if(A){var r=A.length-1,n=this.getStyle("marker-start"),i=this.getStyle("marker-mid"),s=this.getStyle("marker-end");if(n.isUrlDefinition()){var a=n.getDefinition(),[o,l]=A[0];a.render(e,o,l)}if(i.isUrlDefinition())for(var c=i.getDefinition(),u=1;u<r;u++){var[h,d]=A[u];c.render(e,h,d)}if(s.isUrlDefinition()){var f=s.getDefinition(),[p,g]=A[r];f.render(e,p,g)}}}static pathM(e){var t=e.getAsCurrentPoint();return e.start=e.current,{point:t}}pathM(e,t){var{pathParser:A}=this,{point:r}=zQ.pathM(A),{x:n,y:i}=r;A.addMarker(r),t.addPoint(n,i),e&&e.moveTo(n,i)}static pathL(e){var{current:t}=e;return{current:t,point:e.getAsCurrentPoint()}}pathL(e,t){var{pathParser:A}=this,{current:r,point:n}=zQ.pathL(A),{x:i,y:s}=n;A.addMarker(n,r),t.addPoint(i,s),e&&e.lineTo(i,s)}static pathH(e){var{current:t,command:A}=e,r=new BQ((A.relative?t.x:0)+A.x,t.y);return e.current=r,{current:t,point:r}}pathH(e,t){var{pathParser:A}=this,{current:r,point:n}=zQ.pathH(A),{x:i,y:s}=n;A.addMarker(n,r),t.addPoint(i,s),e&&e.lineTo(i,s)}static pathV(e){var{current:t,command:A}=e,r=new BQ(t.x,(A.relative?t.y:0)+A.y);return e.current=r,{current:t,point:r}}pathV(e,t){var{pathParser:A}=this,{current:r,point:n}=zQ.pathV(A),{x:i,y:s}=n;A.addMarker(n,r),t.addPoint(i,s),e&&e.lineTo(i,s)}static pathC(e){var{current:t}=e;return{current:t,point:e.getPoint("x1","y1"),controlPoint:e.getAsControlPoint("x2","y2"),currentPoint:e.getAsCurrentPoint()}}pathC(e,t){var{pathParser:A}=this,{current:r,point:n,controlPoint:i,currentPoint:s}=zQ.pathC(A);A.addMarker(s,i,n),t.addBezierCurve(r.x,r.y,n.x,n.y,i.x,i.y,s.x,s.y),e&&e.bezierCurveTo(n.x,n.y,i.x,i.y,s.x,s.y)}static pathS(e){var{current:t}=e;return{current:t,point:e.getReflectedControlPoint(),controlPoint:e.getAsControlPoint("x2","y2"),currentPoint:e.getAsCurrentPoint()}}pathS(e,t){var{pathParser:A}=this,{current:r,point:n,controlPoint:i,currentPoint:s}=zQ.pathS(A);A.addMarker(s,i,n),t.addBezierCurve(r.x,r.y,n.x,n.y,i.x,i.y,s.x,s.y),e&&e.bezierCurveTo(n.x,n.y,i.x,i.y,s.x,s.y)}static pathQ(e){var{current:t}=e;return{current:t,controlPoint:e.getAsControlPoint("x1","y1"),currentPoint:e.getAsCurrentPoint()}}pathQ(e,t){var{pathParser:A}=this,{current:r,controlPoint:n,currentPoint:i}=zQ.pathQ(A);A.addMarker(i,n,n),t.addQuadraticCurve(r.x,r.y,n.x,n.y,i.x,i.y),e&&e.quadraticCurveTo(n.x,n.y,i.x,i.y)}static pathT(e){var{current:t}=e,A=e.getReflectedControlPoint();return e.control=A,{current:t,controlPoint:A,currentPoint:e.getAsCurrentPoint()}}pathT(e,t){var{pathParser:A}=this,{current:r,controlPoint:n,currentPoint:i}=zQ.pathT(A);A.addMarker(i,n,n),t.addQuadraticCurve(r.x,r.y,n.x,n.y,i.x,i.y),e&&e.quadraticCurveTo(n.x,n.y,i.x,i.y)}static pathA(e){var{current:t,command:A}=e,{rX:r,rY:n,xRot:i,lArcFlag:s,sweepFlag:a}=A,o=i*(Math.PI/180),l=e.getAsCurrentPoint(),c=new BQ(Math.cos(o)*(t.x-l.x)/2+Math.sin(o)*(t.y-l.y)/2,-Math.sin(o)*(t.x-l.x)/2+Math.cos(o)*(t.y-l.y)/2),u=Math.pow(c.x,2)/Math.pow(r,2)+Math.pow(c.y,2)/Math.pow(n,2);u>1&&(r*=Math.sqrt(u),n*=Math.sqrt(u));var h=(s===a?-1:1)*Math.sqrt((Math.pow(r,2)*Math.pow(n,2)-Math.pow(r,2)*Math.pow(c.y,2)-Math.pow(n,2)*Math.pow(c.x,2))/(Math.pow(r,2)*Math.pow(c.y,2)+Math.pow(n,2)*Math.pow(c.x,2)));isNaN(h)&&(h=0);var d=new BQ(h*r*c.y/n,h*-n*c.x/r),f=new BQ((t.x+l.x)/2+Math.cos(o)*d.x-Math.sin(o)*d.y,(t.y+l.y)/2+Math.sin(o)*d.x+Math.cos(o)*d.y),p=uQ([1,0],[(c.x-d.x)/r,(c.y-d.y)/n]),g=[(c.x-d.x)/r,(c.y-d.y)/n],m=[(-c.x-d.x)/r,(-c.y-d.y)/n],v=uQ(g,m);return cQ(g,m)<=-1&&(v=Math.PI),cQ(g,m)>=1&&(v=0),{currentPoint:l,rX:r,rY:n,sweepFlag:a,xAxisRotation:o,centp:f,a1:p,ad:v}}pathA(e,t){var{pathParser:A}=this,{currentPoint:r,rX:n,rY:i,sweepFlag:s,xAxisRotation:a,centp:o,a1:l,ad:c}=zQ.pathA(A),u=1-s?1:-1,h=l+u*(c/2),d=new BQ(o.x+n*Math.cos(h),o.y+i*Math.sin(h));if(A.addMarkerAngle(d,h-u*Math.PI/2),A.addMarkerAngle(r,h-u*Math.PI),t.addPoint(r.x,r.y),e&&!isNaN(l)&&!isNaN(c)){var f=n>i?n:i,p=n>i?1:n/i,g=n>i?i/n:1;e.translate(o.x,o.y),e.rotate(a),e.scale(p,g),e.arc(0,0,f,l,l+c,Boolean(1-s)),e.scale(1/p,1/g),e.rotate(-a),e.translate(-o.x,-o.y)}}static pathZ(e){e.current=e.start}pathZ(e,t){zQ.pathZ(this.pathParser),e&&t.x1!==t.x2&&t.y1!==t.y2&&e.closePath()}}class qQ extends zQ{constructor(e,t,A){super(e,t,A),this.type="glyph",this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber(),this.unicode=this.getAttribute("unicode").getString(),this.arabicForm=this.getAttribute("arabic-form").getString()}}class WQ extends GQ{constructor(e,t,A){super(e,t,new.target===WQ||A),this.type="text",this.x=0,this.y=0,this.measureCache=-1}setContext(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];super.setContext(e,t);var A=this.getStyle("dominant-baseline").getTextBaseline()||this.getStyle("alignment-baseline").getTextBaseline();A&&(e.textBaseline=A)}initializeCoordinates(){this.x=0,this.y=0,this.leafTexts=[],this.textChunkStart=0,this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY}getBoundingBox(e){if("text"!==this.type)return this.getTElementBoundingBox(e);this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(e);var t=null;return this.children.forEach((A,r)=>{var n=this.getChildBoundingBox(e,this,this,r);t?t.addBoundingBox(n):t=n}),t}getFontSize(){var{document:e,parent:t}=this,A=RQ.parse(e.ctx.font).fontSize;return t.getStyle("font-size").getNumber(A)}getTElementBoundingBox(e){var t=this.getFontSize();return new VQ(this.x,this.y-t,this.x+this.measureText(e),this.y)}getGlyph(e,t,A){var r=t[A],n=null;if(e.isArabic){var i=t.length,s=t[A-1],a=t[A+1],o="isolated";if((0===A||" "===s)&&A<i-1&&" "!==a&&(o="terminal"),A>0&&" "!==s&&A<i-1&&" "!==a&&(o="medial"),A>0&&" "!==s&&(A===i-1||" "===a)&&(o="initial"),void 0!==e.glyphs[r]){var l=e.glyphs[r];n=l instanceof qQ?l:l[o]}}else n=e.glyphs[r];return n||(n=e.missingGlyph),n}getText(){return""}getTextFromNode(e){var t=e||this.node,A=Array.from(t.parentNode.childNodes),r=A.indexOf(t),n=A.length-1,i=GF(t.textContent||"");return 0===r&&(i=zF(i)),r===n&&(i=qF(i)),i}renderChildren(e){if("text"===this.type){this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(e),this.children.forEach((t,A)=>{this.renderChild(e,this,this,A)});var{mouse:t}=this.document.screen;t.isWorking()&&t.checkBoundingBox(this,this.getBoundingBox(e))}else this.renderTElementChildren(e)}renderTElementChildren(e){var{document:t,parent:A}=this,r=this.getText(),n=A.getStyle("font-family").getDefinition();if(n)for(var{unitsPerEm:i}=n.fontFace,s=RQ.parse(t.ctx.font),a=A.getStyle("font-size").getNumber(s.fontSize),o=A.getStyle("font-style").getString(s.fontStyle),l=a/i,c=n.isRTL?r.split("").reverse().join(""):r,u=WF(A.getAttribute("dx").getString()),h=c.length,d=0;d<h;d++){var f=this.getGlyph(n,c,d);e.translate(this.x,this.y),e.scale(l,-l);var p=e.lineWidth;e.lineWidth=e.lineWidth*i/a,"italic"===o&&e.transform(1,0,.4,1,0,0),f.render(e),"italic"===o&&e.transform(1,0,-.4,1,0,0),e.lineWidth=p,e.scale(1/l,-1/l),e.translate(-this.x,-this.y),this.x+=a*(f.horizAdvX||n.horizAdvX)/i,void 0===u[d]||isNaN(u[d])||(this.x+=u[d])}else{var{x:g,y:m}=this;e.fillStyle&&e.fillText(r,g,m),e.strokeStyle&&e.strokeText(r,g,m)}}applyAnchoring(){if(!(this.textChunkStart>=this.leafTexts.length)){var e=this.leafTexts[this.textChunkStart],t=e.getStyle("text-anchor").getString("start"),A=0;A="start"===t?e.x-this.minX:"end"===t?e.x-this.maxX:e.x-(this.minX+this.maxX)/2;for(var r=this.textChunkStart;r<this.leafTexts.length;r++)this.leafTexts[r].x+=A;this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY,this.textChunkStart=this.leafTexts.length}}adjustChildCoordinatesRecursive(e){this.children.forEach((t,A)=>{this.adjustChildCoordinatesRecursiveCore(e,this,this,A)}),this.applyAnchoring()}adjustChildCoordinatesRecursiveCore(e,t,A,r){var n=A.children[r];n.children.length>0?n.children.forEach((A,r)=>{t.adjustChildCoordinatesRecursiveCore(e,t,n,r)}):this.adjustChildCoordinates(e,t,A,r)}adjustChildCoordinates(e,t,A,r){var n=A.children[r];if("function"!=typeof n.measureText)return n;e.save(),n.setContext(e,!0);var i=n.getAttribute("x"),s=n.getAttribute("y"),a=n.getAttribute("dx"),o=n.getAttribute("dy"),l=n.getStyle("font-family").getDefinition(),c=Boolean(l)&&l.isRTL;0===r&&(i.hasValue()||i.setValue(n.getInheritedAttribute("x")),s.hasValue()||s.setValue(n.getInheritedAttribute("y")),a.hasValue()||a.setValue(n.getInheritedAttribute("dx")),o.hasValue()||o.setValue(n.getInheritedAttribute("dy")));var u=n.measureText(e);return c&&(t.x-=u),i.hasValue()?(t.applyAnchoring(),n.x=i.getPixels("x"),a.hasValue()&&(n.x+=a.getPixels("x"))):(a.hasValue()&&(t.x+=a.getPixels("x")),n.x=t.x),t.x=n.x,c||(t.x+=u),s.hasValue()?(n.y=s.getPixels("y"),o.hasValue()&&(n.y+=o.getPixels("y"))):(o.hasValue()&&(t.y+=o.getPixels("y")),n.y=t.y),t.y=n.y,t.leafTexts.push(n),t.minX=Math.min(t.minX,n.x,n.x+u),t.maxX=Math.max(t.maxX,n.x,n.x+u),n.clearContext(e),e.restore(),n}getChildBoundingBox(e,t,A,r){var n=A.children[r];if("function"!=typeof n.getBoundingBox)return null;var i=n.getBoundingBox(e);return i?(n.children.forEach((A,r)=>{var s=t.getChildBoundingBox(e,t,n,r);i.addBoundingBox(s)}),i):null}renderChild(e,t,A,r){var n=A.children[r];n.render(e),n.children.forEach((A,r)=>{t.renderChild(e,t,n,r)})}measureText(e){var{measureCache:t}=this;if(~t)return t;var A=this.getText(),r=this.measureTargetText(e,A);return this.measureCache=r,r}measureTargetText(e,t){if(!t.length)return 0;var{parent:A}=this,r=A.getStyle("font-family").getDefinition();if(r){for(var n=this.getFontSize(),i=r.isRTL?t.split("").reverse().join(""):t,s=WF(A.getAttribute("dx").getString()),a=i.length,o=0,l=0;l<a;l++){o+=(this.getGlyph(r,i,l).horizAdvX||r.horizAdvX)*n/r.fontFace.unitsPerEm,void 0===s[l]||isNaN(s[l])||(o+=s[l])}return o}if(!e.measureText)return 10*t.length;e.save(),this.setContext(e,!0);var{width:c}=e.measureText(t);return this.clearContext(e),e.restore(),c}getInheritedAttribute(e){for(var t=this;t instanceof WQ&&t.isFirstChild();){var A=t.parent.getAttribute(e);if(A.hasValue(!0))return A.getValue("0");t=t.parent}return null}}class XQ extends WQ{constructor(e,t,A){super(e,t,new.target===XQ||A),this.type="tspan",this.text=this.children.length>0?"":this.getTextFromNode()}getText(){return this.text}}class YQ extends XQ{constructor(){super(...arguments),this.type="textNode"}}class JQ extends GQ{constructor(){super(...arguments),this.type="svg",this.root=!1}setContext(e){var t,{document:A}=this,{screen:r,window:n}=A,i=e.canvas;if(r.setDefaults(e),i.style&&void 0!==e.font&&n&&void 0!==n.getComputedStyle){e.font=n.getComputedStyle(i).getPropertyValue("font");var s=new wQ(A,"fontSize",RQ.parse(e.font).fontSize);s.hasValue()&&(A.rootEmSize=s.getPixels("y"),A.emSize=A.rootEmSize)}this.getAttribute("x").hasValue()||this.getAttribute("x",!0).setValue(0),this.getAttribute("y").hasValue()||this.getAttribute("y",!0).setValue(0);var{width:a,height:o}=r.viewPort;this.getStyle("width").hasValue()||this.getStyle("width",!0).setValue("100%"),this.getStyle("height").hasValue()||this.getStyle("height",!0).setValue("100%"),this.getStyle("color").hasValue()||this.getStyle("color",!0).setValue("black");var l=this.getAttribute("refX"),c=this.getAttribute("refY"),u=this.getAttribute("viewBox"),h=u.hasValue()?WF(u.getString()):null,d=!this.root&&"visible"!==this.getStyle("overflow").getValue("hidden"),f=0,p=0,g=0,m=0;h&&(f=h[0],p=h[1]),this.root||(a=this.getStyle("width").getPixels("x"),o=this.getStyle("height").getPixels("y"),"marker"===this.type&&(g=f,m=p,f=0,p=0)),r.viewPort.setCurrent(a,o),!this.node||this.parent&&"foreignObject"!==(null===(t=this.node.parentNode)||void 0===t?void 0:t.nodeName)||!this.getStyle("transform",!1,!0).hasValue()||this.getStyle("transform-origin",!1,!0).hasValue()||this.getStyle("transform-origin",!0,!0).setValue("50% 50%"),super.setContext(e),e.translate(this.getAttribute("x").getPixels("x"),this.getAttribute("y").getPixels("y")),h&&(a=h[2],o=h[3]),A.setViewBox({ctx:e,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:r.viewPort.width,desiredWidth:a,height:r.viewPort.height,desiredHeight:o,minX:f,minY:p,refX:l.getValue(),refY:c.getValue(),clip:d,clipX:g,clipY:m}),h&&(r.viewPort.removeCurrent(),r.viewPort.setCurrent(a,o))}clearContext(e){super.clearContext(e),this.document.screen.viewPort.removeCurrent()}resize(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,A=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this.getAttribute("width",!0),n=this.getAttribute("height",!0),i=this.getAttribute("viewBox"),s=this.getAttribute("style"),a=r.getNumber(0),o=n.getNumber(0);if(A)if("string"==typeof A)this.getAttribute("preserveAspectRatio",!0).setValue(A);else{var l=this.getAttribute("preserveAspectRatio");l.hasValue()&&l.setValue(l.getString().replace(/^\s*(\S.*\S)\s*$/,"$1"))}if(r.setValue(e),n.setValue(t),i.hasValue()||i.setValue("0 0 ".concat(a||e," ").concat(o||t)),s.hasValue()){var c=this.getStyle("width"),u=this.getStyle("height");c.hasValue()&&c.setValue("".concat(e,"px")),u.hasValue()&&u.setValue("".concat(t,"px"))}}}class $Q extends zQ{constructor(){super(...arguments),this.type="rect"}path(e){var t=this.getAttribute("x").getPixels("x"),A=this.getAttribute("y").getPixels("y"),r=this.getStyle("width",!1,!0).getPixels("x"),n=this.getStyle("height",!1,!0).getPixels("y"),i=this.getAttribute("rx"),s=this.getAttribute("ry"),a=i.getPixels("x"),o=s.getPixels("y");if(i.hasValue()&&!s.hasValue()&&(o=a),s.hasValue()&&!i.hasValue()&&(a=o),a=Math.min(a,r/2),o=Math.min(o,n/2),e){var l=(Math.sqrt(2)-1)/3*4;e.beginPath(),n>0&&r>0&&(e.moveTo(t+a,A),e.lineTo(t+r-a,A),e.bezierCurveTo(t+r-a+l*a,A,t+r,A+o-l*o,t+r,A+o),e.lineTo(t+r,A+n-o),e.bezierCurveTo(t+r,A+n-o+l*o,t+r-a+l*a,A+n,t+r-a,A+n),e.lineTo(t+a,A+n),e.bezierCurveTo(t+a-l*a,A+n,t,A+n-o+l*o,t,A+n-o),e.lineTo(t,A+o),e.bezierCurveTo(t,A+o-l*o,t+a-l*a,A,t+a,A),e.closePath())}return new VQ(t,A,t+r,A+n)}getMarkers(){return null}}class ZQ extends zQ{constructor(){super(...arguments),this.type="circle"}path(e){var t=this.getAttribute("cx").getPixels("x"),A=this.getAttribute("cy").getPixels("y"),r=this.getAttribute("r").getPixels();return e&&r>0&&(e.beginPath(),e.arc(t,A,r,0,2*Math.PI,!1),e.closePath()),new VQ(t-r,A-r,t+r,A+r)}getMarkers(){return null}}class eU extends zQ{constructor(){super(...arguments),this.type="ellipse"}path(e){var t=(Math.sqrt(2)-1)/3*4,A=this.getAttribute("rx").getPixels("x"),r=this.getAttribute("ry").getPixels("y"),n=this.getAttribute("cx").getPixels("x"),i=this.getAttribute("cy").getPixels("y");return e&&A>0&&r>0&&(e.beginPath(),e.moveTo(n+A,i),e.bezierCurveTo(n+A,i+t*r,n+t*A,i+r,n,i+r),e.bezierCurveTo(n-t*A,i+r,n-A,i+t*r,n-A,i),e.bezierCurveTo(n-A,i-t*r,n-t*A,i-r,n,i-r),e.bezierCurveTo(n+t*A,i-r,n+A,i-t*r,n+A,i),e.closePath()),new VQ(n-A,i-r,n+A,i+r)}getMarkers(){return null}}class tU extends zQ{constructor(){super(...arguments),this.type="line"}getPoints(){return[new BQ(this.getAttribute("x1").getPixels("x"),this.getAttribute("y1").getPixels("y")),new BQ(this.getAttribute("x2").getPixels("x"),this.getAttribute("y2").getPixels("y"))]}path(e){var[{x:t,y:A},{x:r,y:n}]=this.getPoints();return e&&(e.beginPath(),e.moveTo(t,A),e.lineTo(r,n)),new VQ(t,A,r,n)}getMarkers(){var[e,t]=this.getPoints(),A=e.angleTo(t);return[[e,A],[t,A]]}}class AU extends zQ{constructor(e,t,A){super(e,t,A),this.type="polyline",this.points=[],this.points=BQ.parsePath(this.getAttribute("points").getString())}path(e){var{points:t}=this,[{x:A,y:r}]=t,n=new VQ(A,r);return e&&(e.beginPath(),e.moveTo(A,r)),t.forEach(t=>{var{x:A,y:r}=t;n.addPoint(A,r),e&&e.lineTo(A,r)}),n}getMarkers(){var{points:e}=this,t=e.length-1,A=[];return e.forEach((r,n)=>{n!==t&&A.push([r,r.angleTo(e[n+1])])}),A.length>0&&A.push([e[e.length-1],A[A.length-1][1]]),A}}class rU extends AU{constructor(){super(...arguments),this.type="polygon"}path(e){var t=super.path(e),[{x:A,y:r}]=this.points;return e&&(e.lineTo(A,r),e.closePath()),t}}class nU extends jQ{constructor(){super(...arguments),this.type="pattern"}createPattern(e,t,A){var r=this.getStyle("width").getPixels("x",!0),n=this.getStyle("height").getPixels("y",!0),i=new JQ(this.document,null);i.attributes.viewBox=new wQ(this.document,"viewBox",this.getAttribute("viewBox").getValue()),i.attributes.width=new wQ(this.document,"width","".concat(r,"px")),i.attributes.height=new wQ(this.document,"height","".concat(n,"px")),i.attributes.transform=new wQ(this.document,"transform",this.getAttribute("patternTransform").getValue()),i.children=this.children;var s=this.document.createCanvas(r,n),a=s.getContext("2d"),o=this.getAttribute("x"),l=this.getAttribute("y");o.hasValue()&&l.hasValue()&&a.translate(o.getPixels("x",!0),l.getPixels("y",!0)),A.hasValue()?this.styles["fill-opacity"]=A:Reflect.deleteProperty(this.styles,"fill-opacity");for(var c=-1;c<=1;c++)for(var u=-1;u<=1;u++)a.save(),i.attributes.x=new wQ(this.document,"x",c*s.width),i.attributes.y=new wQ(this.document,"y",u*s.height),i.render(a),a.restore();return e.createPattern(s,"repeat")}}class iU extends jQ{constructor(){super(...arguments),this.type="marker"}render(e,t,A){if(t){var{x:r,y:n}=t,i=this.getAttribute("orient").getString("auto"),s=this.getAttribute("markerUnits").getString("strokeWidth");e.translate(r,n),"auto"===i&&e.rotate(A),"strokeWidth"===s&&e.scale(e.lineWidth,e.lineWidth),e.save();var a=new JQ(this.document,null);a.type=this.type,a.attributes.viewBox=new wQ(this.document,"viewBox",this.getAttribute("viewBox").getValue()),a.attributes.refX=new wQ(this.document,"refX",this.getAttribute("refX").getValue()),a.attributes.refY=new wQ(this.document,"refY",this.getAttribute("refY").getValue()),a.attributes.width=new wQ(this.document,"width",this.getAttribute("markerWidth").getValue()),a.attributes.height=new wQ(this.document,"height",this.getAttribute("markerHeight").getValue()),a.attributes.overflow=new wQ(this.document,"overflow",this.getAttribute("overflow").getValue()),a.attributes.fill=new wQ(this.document,"fill",this.getAttribute("fill").getColor("black")),a.attributes.stroke=new wQ(this.document,"stroke",this.getAttribute("stroke").getValue("none")),a.children=this.children,a.render(e),e.restore(),"strokeWidth"===s&&e.scale(1/e.lineWidth,1/e.lineWidth),"auto"===i&&e.rotate(-A),e.translate(-r,-n)}}}class sU extends jQ{constructor(){super(...arguments),this.type="defs"}render(){}}class aU extends GQ{constructor(){super(...arguments),this.type="g"}getBoundingBox(e){var t=new VQ;return this.children.forEach(A=>{t.addBoundingBox(A.getBoundingBox(e))}),t}}class oU extends jQ{constructor(e,t,A){super(e,t,A),this.attributesToInherit=["gradientUnits"],this.stops=[];var{stops:r,children:n}=this;n.forEach(e=>{"stop"===e.type&&r.push(e)})}getGradientUnits(){return this.getAttribute("gradientUnits").getString("objectBoundingBox")}createGradient(e,t,A){var r=this;this.getHrefAttribute().hasValue()&&(r=this.getHrefAttribute().getDefinition(),this.inheritStopContainer(r));var{stops:n}=r,i=this.getGradient(e,t);if(!i)return this.addParentOpacity(A,n[n.length-1].color);if(n.forEach(e=>{i.addColorStop(e.offset,this.addParentOpacity(A,e.color))}),this.getAttribute("gradientTransform").hasValue()){var{document:s}=this,{MAX_VIRTUAL_PIXELS:a,viewPort:o}=s.screen,[l]=o.viewPorts,c=new $Q(s,null);c.attributes.x=new wQ(s,"x",-a/3),c.attributes.y=new wQ(s,"y",-a/3),c.attributes.width=new wQ(s,"width",a),c.attributes.height=new wQ(s,"height",a);var u=new aU(s,null);u.attributes.transform=new wQ(s,"transform",this.getAttribute("gradientTransform").getValue()),u.children=[c];var h=new JQ(s,null);h.attributes.x=new wQ(s,"x",0),h.attributes.y=new wQ(s,"y",0),h.attributes.width=new wQ(s,"width",l.width),h.attributes.height=new wQ(s,"height",l.height),h.children=[u];var d=s.createCanvas(l.width,l.height),f=d.getContext("2d");return f.fillStyle=i,h.render(f),f.createPattern(d,"no-repeat")}return i}inheritStopContainer(e){this.attributesToInherit.forEach(t=>{!this.getAttribute(t).hasValue()&&e.getAttribute(t).hasValue()&&this.getAttribute(t,!0).setValue(e.getAttribute(t).getValue())})}addParentOpacity(e,t){return e.hasValue()?new wQ(this.document,"color",t).addOpacity(e).getColor():t}}class lU extends oU{constructor(e,t,A){super(e,t,A),this.type="linearGradient",this.attributesToInherit.push("x1","y1","x2","y2")}getGradient(e,t){var A="objectBoundingBox"===this.getGradientUnits(),r=A?t.getBoundingBox(e):null;if(A&&!r)return null;this.getAttribute("x1").hasValue()||this.getAttribute("y1").hasValue()||this.getAttribute("x2").hasValue()||this.getAttribute("y2").hasValue()||(this.getAttribute("x1",!0).setValue(0),this.getAttribute("y1",!0).setValue(0),this.getAttribute("x2",!0).setValue(1),this.getAttribute("y2",!0).setValue(0));var n=A?r.x+r.width*this.getAttribute("x1").getNumber():this.getAttribute("x1").getPixels("x"),i=A?r.y+r.height*this.getAttribute("y1").getNumber():this.getAttribute("y1").getPixels("y"),s=A?r.x+r.width*this.getAttribute("x2").getNumber():this.getAttribute("x2").getPixels("x"),a=A?r.y+r.height*this.getAttribute("y2").getNumber():this.getAttribute("y2").getPixels("y");return n===s&&i===a?null:e.createLinearGradient(n,i,s,a)}}class cU extends oU{constructor(e,t,A){super(e,t,A),this.type="radialGradient",this.attributesToInherit.push("cx","cy","r","fx","fy","fr")}getGradient(e,t){var A="objectBoundingBox"===this.getGradientUnits(),r=t.getBoundingBox(e);if(A&&!r)return null;this.getAttribute("cx").hasValue()||this.getAttribute("cx",!0).setValue("50%"),this.getAttribute("cy").hasValue()||this.getAttribute("cy",!0).setValue("50%"),this.getAttribute("r").hasValue()||this.getAttribute("r",!0).setValue("50%");var n=A?r.x+r.width*this.getAttribute("cx").getNumber():this.getAttribute("cx").getPixels("x"),i=A?r.y+r.height*this.getAttribute("cy").getNumber():this.getAttribute("cy").getPixels("y"),s=n,a=i;this.getAttribute("fx").hasValue()&&(s=A?r.x+r.width*this.getAttribute("fx").getNumber():this.getAttribute("fx").getPixels("x")),this.getAttribute("fy").hasValue()&&(a=A?r.y+r.height*this.getAttribute("fy").getNumber():this.getAttribute("fy").getPixels("y"));var o=A?(r.width+r.height)/2*this.getAttribute("r").getNumber():this.getAttribute("r").getPixels(),l=this.getAttribute("fr").getPixels();return e.createRadialGradient(s,a,l,n,i,o)}}class uU extends jQ{constructor(e,t,A){super(e,t,A),this.type="stop";var r=Math.max(0,Math.min(1,this.getAttribute("offset").getNumber())),n=this.getStyle("stop-opacity"),i=this.getStyle("stop-color",!0);""===i.getString()&&i.setValue("#000"),n.hasValue()&&(i=i.addOpacity(n)),this.offset=r,this.color=i.getColor()}}class hU extends jQ{constructor(e,t,A){super(e,t,A),this.type="animate",this.duration=0,this.initialValue=null,this.initialUnits="",this.removed=!1,this.frozen=!1,e.screen.animations.push(this),this.begin=this.getAttribute("begin").getMilliseconds(),this.maxDuration=this.begin+this.getAttribute("dur").getMilliseconds(),this.from=this.getAttribute("from"),this.to=this.getAttribute("to"),this.values=new wQ(e,"values",null);var r=this.getAttribute("values");r.hasValue()&&this.values.setValue(r.getString().split(";"))}getProperty(){var e=this.getAttribute("attributeType").getString(),t=this.getAttribute("attributeName").getString();return"CSS"===e?this.parent.getStyle(t,!0):this.parent.getAttribute(t,!0)}calcValue(){var{initialUnits:e}=this,{progress:t,from:A,to:r}=this.getProgress(),n=A.getNumber()+(r.getNumber()-A.getNumber())*t;return"%"===e&&(n*=100),"".concat(n).concat(e)}update(e){var{parent:t}=this,A=this.getProperty();if(this.initialValue||(this.initialValue=A.getString(),this.initialUnits=A.getUnits()),this.duration>this.maxDuration){var r=this.getAttribute("fill").getString("remove");if("indefinite"===this.getAttribute("repeatCount").getString()||"indefinite"===this.getAttribute("repeatDur").getString())this.duration=0;else if("freeze"!==r||this.frozen){if("remove"===r&&!this.removed)return this.removed=!0,A.setValue(t.animationFrozen?t.animationFrozenValue:this.initialValue),!0}else this.frozen=!0,t.animationFrozen=!0,t.animationFrozenValue=A.getString();return!1}this.duration+=e;var n=!1;if(this.begin<this.duration){var i=this.calcValue(),s=this.getAttribute("type");if(s.hasValue()){var a=s.getString();i="".concat(a,"(").concat(i,")")}A.setValue(i),n=!0}return n}getProgress(){var{document:e,values:t}=this,A={progress:(this.duration-this.begin)/(this.maxDuration-this.begin)};if(t.hasValue()){var r=A.progress*(t.getValue().length-1),n=Math.floor(r),i=Math.ceil(r);A.from=new wQ(e,"from",parseFloat(t.getValue()[n])),A.to=new wQ(e,"to",parseFloat(t.getValue()[i])),A.progress=(r-n)/(i-n)}else A.from=this.from,A.to=this.to;return A}}class dU extends hU{constructor(){super(...arguments),this.type="animateColor"}calcValue(){var{progress:e,from:t,to:A}=this.getProgress(),r=new Gx(t.getColor()),n=new Gx(A.getColor());if(r.ok&&n.ok){var i=r.r+(n.r-r.r)*e,s=r.g+(n.g-r.g)*e,a=r.b+(n.b-r.b)*e;return"rgb(".concat(Math.floor(i),", ").concat(Math.floor(s),", ").concat(Math.floor(a),")")}return this.getAttribute("from").getColor()}}class fU extends hU{constructor(){super(...arguments),this.type="animateTransform"}calcValue(){var{progress:e,from:t,to:A}=this.getProgress(),r=WF(t.getString()),n=WF(A.getString()),i=r.map((t,A)=>t+(n[A]-t)*e).join(" ");return i}}class pU extends jQ{constructor(e,t,A){super(e,t,A),this.type="font",this.glyphs=Object.create(null),this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber();var{definitions:r}=e,{children:n}=this;for(var i of n)switch(i.type){case"font-face":this.fontFace=i;var s=i.getStyle("font-family");s.hasValue()&&(r[s.getString()]=this);break;case"missing-glyph":this.missingGlyph=i;break;case"glyph":var a=i;a.arabicForm?(this.isRTL=!0,this.isArabic=!0,void 0===this.glyphs[a.unicode]&&(this.glyphs[a.unicode]=Object.create(null)),this.glyphs[a.unicode][a.arabicForm]=a):this.glyphs[a.unicode]=a}}render(){}}class gU extends jQ{constructor(e,t,A){super(e,t,A),this.type="font-face",this.ascent=this.getAttribute("ascent").getNumber(),this.descent=this.getAttribute("descent").getNumber(),this.unitsPerEm=this.getAttribute("units-per-em").getNumber()}}class mU extends zQ{constructor(){super(...arguments),this.type="missing-glyph",this.horizAdvX=0}}class vU extends WQ{constructor(){super(...arguments),this.type="tref"}getText(){var e=this.getHrefAttribute().getDefinition();if(e){var t=e.children[0];if(t)return t.getText()}return""}}class wU extends WQ{constructor(e,t,A){super(e,t,A),this.type="a";var{childNodes:r}=t,n=r[0],i=r.length>0&&Array.from(r).every(e=>3===e.nodeType);this.hasText=i,this.text=i?this.getTextFromNode(n):""}getText(){return this.text}renderChildren(e){if(this.hasText){super.renderChildren(e);var{document:t,x:A,y:r}=this,{mouse:n}=t.screen,i=new wQ(t,"fontSize",RQ.parse(t.ctx.font).fontSize);n.isWorking()&&n.checkBoundingBox(this,new VQ(A,r-i.getPixels("y"),A+this.measureText(e),r))}else if(this.children.length>0){var s=new aU(this.document,null);s.children=this.children,s.parent=this,s.render(e)}}onClick(){var{window:e}=this.document;e&&e.open(this.getHrefAttribute().getString())}onMouseMove(){this.document.ctx.canvas.style.cursor="pointer"}}function bU(e,t){var A=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),A.push.apply(A,r)}return A}function BU(e){for(var t=1;t<arguments.length;t++){var A=null!=arguments[t]?arguments[t]:{};t%2?bU(Object(A),!0).forEach(function(t){EC(e,t,A[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(A)):bU(Object(A)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(A,t))})}return e}class yU extends WQ{constructor(e,t,A){super(e,t,A),this.type="textPath",this.textWidth=0,this.textHeight=0,this.pathLength=-1,this.glyphInfo=null,this.letterSpacingCache=[],this.measuresCache=new Map([["",0]]);var r=this.getHrefAttribute().getDefinition();this.text=this.getTextFromNode(),this.dataArray=this.parsePathData(r)}getText(){return this.text}path(e){var{dataArray:t}=this;e&&e.beginPath(),t.forEach(t=>{var{type:A,points:r}=t;switch(A){case KQ.LINE_TO:e&&e.lineTo(r[0],r[1]);break;case KQ.MOVE_TO:e&&e.moveTo(r[0],r[1]);break;case KQ.CURVE_TO:e&&e.bezierCurveTo(r[0],r[1],r[2],r[3],r[4],r[5]);break;case KQ.QUAD_TO:e&&e.quadraticCurveTo(r[0],r[1],r[2],r[3]);break;case KQ.ARC:var[n,i,s,a,o,l,c,u]=r,h=s>a?s:a,d=s>a?1:s/a,f=s>a?a/s:1;e&&(e.translate(n,i),e.rotate(c),e.scale(d,f),e.arc(0,0,h,o,o+l,Boolean(1-u)),e.scale(1/d,1/f),e.rotate(-c),e.translate(-n,-i));break;case KQ.CLOSE_PATH:e&&e.closePath()}})}renderChildren(e){this.setTextData(e),e.save();var t=this.parent.getStyle("text-decoration").getString(),A=this.getFontSize(),{glyphInfo:r}=this,n=e.fillStyle;"underline"===t&&e.beginPath(),r.forEach((r,n)=>{var{p0:i,p1:s,rotation:a,text:o}=r;e.save(),e.translate(i.x,i.y),e.rotate(a),e.fillStyle&&e.fillText(o,0,0),e.strokeStyle&&e.strokeText(o,0,0),e.restore(),"underline"===t&&(0===n&&e.moveTo(i.x,i.y+A/8),e.lineTo(s.x,s.y+A/5))}),"underline"===t&&(e.lineWidth=A/20,e.strokeStyle=n,e.stroke(),e.closePath()),e.restore()}getLetterSpacingAt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.letterSpacingCache[e]||0}findSegmentToFitChar(e,t,A,r,n,i,s,a,o){var l=i,c=this.measureText(e,a);" "===a&&"justify"===t&&A<r&&(c+=(r-A)/n),o>-1&&(l+=this.getLetterSpacingAt(o));var u=this.textHeight/20,h=this.getEquidistantPointOnPath(l,u,0),d=this.getEquidistantPointOnPath(l+c,u,0),f={p0:h,p1:d},p=h&&d?Math.atan2(d.y-h.y,d.x-h.x):0;if(s){var g=Math.cos(Math.PI/2+p)*s,m=Math.cos(-p)*s;f.p0=BU(BU({},h),{},{x:h.x+g,y:h.y+m}),f.p1=BU(BU({},d),{},{x:d.x+g,y:d.y+m})}return{offset:l+=c,segment:f,rotation:p}}measureText(e,t){var{measuresCache:A}=this,r=t||this.getText();if(A.has(r))return A.get(r);var n=this.measureTargetText(e,r);return A.set(r,n),n}setTextData(e){if(!this.glyphInfo){var t=this.getText(),A=t.split(""),r=t.split(" ").length-1,n=this.parent.getAttribute("dx").split().map(e=>e.getPixels("x")),i=this.parent.getAttribute("dy").getPixels("y"),s=this.parent.getStyle("text-anchor").getString("start"),a=this.getStyle("letter-spacing"),o=this.parent.getStyle("letter-spacing"),l=0;a.hasValue()&&"inherit"!==a.getValue()?a.hasValue()&&"initial"!==a.getValue()&&"unset"!==a.getValue()&&(l=a.getPixels()):l=o.getPixels();var c=[],u=t.length;this.letterSpacingCache=c;for(var h=0;h<u;h++)c.push(void 0!==n[h]?n[h]:l);var d=c.reduce((e,t,A)=>0===A?0:e+t||0,0),f=this.measureText(e),p=Math.max(f+d,0);this.textWidth=f,this.textHeight=this.getFontSize(),this.glyphInfo=[];var g=this.getPathLength(),m=this.getStyle("startOffset").getNumber(0)*g,v=0;"middle"!==s&&"center"!==s||(v=-p/2),"end"!==s&&"right"!==s||(v=-p),v+=m,A.forEach((t,n)=>{var{offset:a,segment:o,rotation:l}=this.findSegmentToFitChar(e,s,p,g,r,v,i,t,n);v=a,o.p0&&o.p1&&this.glyphInfo.push({text:A[n],p0:o.p0,p1:o.p1,rotation:l})})}}parsePathData(e){if(this.pathLength=-1,!e)return[];var t=[],{pathParser:A}=e;for(A.reset();!A.isEnd();){var{current:r}=A,n=r?r.x:0,i=r?r.y:0,s=A.next(),a=s.type,o=[];switch(s.type){case KQ.MOVE_TO:this.pathM(A,o);break;case KQ.LINE_TO:a=this.pathL(A,o);break;case KQ.HORIZ_LINE_TO:a=this.pathH(A,o);break;case KQ.VERT_LINE_TO:a=this.pathV(A,o);break;case KQ.CURVE_TO:this.pathC(A,o);break;case KQ.SMOOTH_CURVE_TO:a=this.pathS(A,o);break;case KQ.QUAD_TO:this.pathQ(A,o);break;case KQ.SMOOTH_QUAD_TO:a=this.pathT(A,o);break;case KQ.ARC:o=this.pathA(A);break;case KQ.CLOSE_PATH:zQ.pathZ(A)}s.type!==KQ.CLOSE_PATH?t.push({type:a,points:o,start:{x:n,y:i},pathLength:this.calcLength(n,i,a,o)}):t.push({type:KQ.CLOSE_PATH,points:[],pathLength:0})}return t}pathM(e,t){var{x:A,y:r}=zQ.pathM(e).point;t.push(A,r)}pathL(e,t){var{x:A,y:r}=zQ.pathL(e).point;return t.push(A,r),KQ.LINE_TO}pathH(e,t){var{x:A,y:r}=zQ.pathH(e).point;return t.push(A,r),KQ.LINE_TO}pathV(e,t){var{x:A,y:r}=zQ.pathV(e).point;return t.push(A,r),KQ.LINE_TO}pathC(e,t){var{point:A,controlPoint:r,currentPoint:n}=zQ.pathC(e);t.push(A.x,A.y,r.x,r.y,n.x,n.y)}pathS(e,t){var{point:A,controlPoint:r,currentPoint:n}=zQ.pathS(e);return t.push(A.x,A.y,r.x,r.y,n.x,n.y),KQ.CURVE_TO}pathQ(e,t){var{controlPoint:A,currentPoint:r}=zQ.pathQ(e);t.push(A.x,A.y,r.x,r.y)}pathT(e,t){var{controlPoint:A,currentPoint:r}=zQ.pathT(e);return t.push(A.x,A.y,r.x,r.y),KQ.QUAD_TO}pathA(e){var{rX:t,rY:A,sweepFlag:r,xAxisRotation:n,centp:i,a1:s,ad:a}=zQ.pathA(e);return 0===r&&a>0&&(a-=2*Math.PI),1===r&&a<0&&(a+=2*Math.PI),[i.x,i.y,t,A,s,a,n,r]}calcLength(e,t,A,r){var n=0,i=null,s=null,a=0;switch(A){case KQ.LINE_TO:return this.getLineLength(e,t,r[0],r[1]);case KQ.CURVE_TO:for(n=0,i=this.getPointOnCubicBezier(0,e,t,r[0],r[1],r[2],r[3],r[4],r[5]),a=.01;a<=1;a+=.01)s=this.getPointOnCubicBezier(a,e,t,r[0],r[1],r[2],r[3],r[4],r[5]),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;return n;case KQ.QUAD_TO:for(n=0,i=this.getPointOnQuadraticBezier(0,e,t,r[0],r[1],r[2],r[3]),a=.01;a<=1;a+=.01)s=this.getPointOnQuadraticBezier(a,e,t,r[0],r[1],r[2],r[3]),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;return n;case KQ.ARC:n=0;var o=r[4],l=r[5],c=r[4]+l,u=Math.PI/180;if(Math.abs(o-c)<u&&(u=Math.abs(o-c)),i=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],o,0),l<0)for(a=o-u;a>c;a-=u)s=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],a,0),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;else for(a=o+u;a<c;a+=u)s=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],a,0),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;return s=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],c,0),n+=this.getLineLength(i.x,i.y,s.x,s.y)}return 0}getPointOnLine(e,t,A,r,n){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:t,s=arguments.length>6&&void 0!==arguments[6]?arguments[6]:A,a=(n-A)/(r-t+oQ),o=Math.sqrt(e*e/(1+a*a));r<t&&(o*=-1);var l=a*o,c=null;if(r===t)c={x:i,y:s+l};else if((s-A)/(i-t+oQ)===a)c={x:i+o,y:s+l};else{var u,h,d=this.getLineLength(t,A,r,n);if(d<oQ)return null;var f=(i-t)*(r-t)+(s-A)*(n-A);u=t+(f/=d*d)*(r-t),h=A+f*(n-A);var p=this.getLineLength(i,s,u,h),g=Math.sqrt(e*e-p*p);o=Math.sqrt(g*g/(1+a*a)),r<t&&(o*=-1),c={x:u+o,y:h+(l=a*o)}}return c}getPointOnPath(e){var t=this.getPathLength(),A=0,r=null;if(e<-5e-5||e-5e-5>t)return null;var{dataArray:n}=this;for(var i of n){if(!i||!(i.pathLength<5e-5||A+i.pathLength+5e-5<e)){var s=e-A,a=0;switch(i.type){case KQ.LINE_TO:r=this.getPointOnLine(s,i.start.x,i.start.y,i.points[0],i.points[1],i.start.x,i.start.y);break;case KQ.ARC:var o=i.points[4],l=i.points[5],c=i.points[4]+l;if(a=o+s/i.pathLength*l,l<0&&a<c||l>=0&&a>c)break;r=this.getPointOnEllipticalArc(i.points[0],i.points[1],i.points[2],i.points[3],a,i.points[6]);break;case KQ.CURVE_TO:(a=s/i.pathLength)>1&&(a=1),r=this.getPointOnCubicBezier(a,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3],i.points[4],i.points[5]);break;case KQ.QUAD_TO:(a=s/i.pathLength)>1&&(a=1),r=this.getPointOnQuadraticBezier(a,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3])}if(r)return r;break}A+=i.pathLength}return null}getLineLength(e,t,A,r){return Math.sqrt((A-e)*(A-e)+(r-t)*(r-t))}getPathLength(){return-1===this.pathLength&&(this.pathLength=this.dataArray.reduce((e,t)=>t.pathLength>0?e+t.pathLength:e,0)),this.pathLength}getPointOnCubicBezier(e,t,A,r,n,i,s,a,o){return{x:a*hQ(e)+i*dQ(e)+r*fQ(e)+t*pQ(e),y:o*hQ(e)+s*dQ(e)+n*fQ(e)+A*pQ(e)}}getPointOnQuadraticBezier(e,t,A,r,n,i,s){return{x:i*gQ(e)+r*mQ(e)+t*vQ(e),y:s*gQ(e)+n*mQ(e)+A*vQ(e)}}getPointOnEllipticalArc(e,t,A,r,n,i){var s=Math.cos(i),a=Math.sin(i),o=A*Math.cos(n),l=r*Math.sin(n);return{x:e+(o*s-l*a),y:t+(o*a+l*s)}}buildEquidistantCache(e,t){var A=this.getPathLength(),r=t||.25,n=e||A/100;if(!this.equidistantCache||this.equidistantCache.step!==n||this.equidistantCache.precision!==r){this.equidistantCache={step:n,precision:r,points:[]};for(var i=0,s=0;s<=A;s+=r){var a=this.getPointOnPath(s),o=this.getPointOnPath(s+r);a&&o&&((i+=this.getLineLength(a.x,a.y,o.x,o.y))>=n&&(this.equidistantCache.points.push({x:a.x,y:a.y,distance:s}),i-=n))}}}getEquidistantPointOnPath(e,t,A){if(this.buildEquidistantCache(t,A),e<0||e-this.getPathLength()>5e-5)return null;var r=Math.round(e/this.getPathLength()*(this.equidistantCache.points.length-1));return this.equidistantCache.points[r]||null}}var CU=/^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(.*)$/i;class xU extends GQ{constructor(e,t,A){super(e,t,A),this.type="image",this.loaded=!1;var r=this.getHrefAttribute().getString();if(r){var n=r.endsWith(".svg")||/^\s*data:image\/svg\+xml/i.test(r);e.images.push(this),n?this.loadSvg(r):this.loadImage(r),this.isSvg=n}}loadImage(e){var t=this;return Jv(function*(){try{var A=yield t.document.createImage(e);t.image=A}catch(t){console.error('Error while loading image "'.concat(e,'":'),t)}t.loaded=!0})()}loadSvg(e){var t=this;return Jv(function*(){var A=CU.exec(e);if(A){var r=A[5];"base64"===A[4]?t.image=atob(r):t.image=decodeURIComponent(r)}else try{var n=yield t.document.fetch(e),i=yield n.text();t.image=i}catch(t){console.error('Error while loading image "'.concat(e,'":'),t)}t.loaded=!0})()}renderChildren(e){var{document:t,image:A,loaded:r}=this,n=this.getAttribute("x").getPixels("x"),i=this.getAttribute("y").getPixels("y"),s=this.getStyle("width").getPixels("x"),a=this.getStyle("height").getPixels("y");if(r&&A&&s&&a){if(e.save(),e.translate(n,i),this.isSvg){var o=t.canvg.forkString(e,this.image,{ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0,ignoreClear:!0,offsetX:0,offsetY:0,scaleWidth:s,scaleHeight:a});o.document.documentElement.parent=this,o.render()}else{var l=this.image;t.setViewBox({ctx:e,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:s,desiredWidth:l.width,height:a,desiredHeight:l.height}),this.loaded&&(void 0===l.complete||l.complete)&&e.drawImage(l,0,0)}e.restore()}}getBoundingBox(){var e=this.getAttribute("x").getPixels("x"),t=this.getAttribute("y").getPixels("y"),A=this.getStyle("width").getPixels("x"),r=this.getStyle("height").getPixels("y");return new VQ(e,t,e+A,t+r)}}class FU extends GQ{constructor(){super(...arguments),this.type="symbol"}render(e){}}class QU{constructor(e){this.document=e,this.loaded=!1,e.fonts.push(this)}load(e,t){var A=this;return Jv(function*(){try{var{document:r}=A,n=(yield r.canvg.parser.load(t)).getElementsByTagName("font");Array.from(n).forEach(t=>{var A=r.createElement(t);r.definitions[e]=A})}catch(e){console.error('Error while loading font "'.concat(t,'":'),e)}A.loaded=!0})()}}class UU extends jQ{constructor(e,t,A){super(e,t,A),this.type="style";var r=GF(Array.from(t.childNodes).map(e=>e.textContent).join("").replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm,"").replace(/@import.*;/g,""));r.split("}").forEach(t=>{var A=t.trim();if(A){var r=A.split("{"),n=r[0].split(","),i=r[1].split(";");n.forEach(t=>{var A=t.trim();if(A){var r=e.styles[A]||{};if(i.forEach(t=>{var A=t.indexOf(":"),n=t.substr(0,A).trim(),i=t.substr(A+1,t.length-A).trim();n&&i&&(r[n]=new wQ(e,n,i))}),e.styles[A]=r,e.stylesSpecificity[A]=aQ(A),"@font-face"===A){var n=r["font-family"].getString().replace(/"|'/g,"");r.src.getString().split(",").forEach(t=>{if(t.indexOf('format("svg")')>0){var A=JF(t);A&&new QU(e).load(n,A)}})}}})}})}}UU.parseExternalUrl=JF;class EU extends GQ{constructor(){super(...arguments),this.type="use"}setContext(e){super.setContext(e);var t=this.getAttribute("x"),A=this.getAttribute("y");t.hasValue()&&e.translate(t.getPixels("x"),0),A.hasValue()&&e.translate(0,A.getPixels("y"))}path(e){var{element:t}=this;t&&t.path(e)}renderChildren(e){var{document:t,element:A}=this;if(A){var r=A;if("symbol"===A.type&&((r=new JQ(t,null)).attributes.viewBox=new wQ(t,"viewBox",A.getAttribute("viewBox").getString()),r.attributes.preserveAspectRatio=new wQ(t,"preserveAspectRatio",A.getAttribute("preserveAspectRatio").getString()),r.attributes.overflow=new wQ(t,"overflow",A.getAttribute("overflow").getString()),r.children=A.children,A.styles.opacity=new wQ(t,"opacity",this.calculateOpacity())),"svg"===r.type){var n=this.getStyle("width",!1,!0),i=this.getStyle("height",!1,!0);n.hasValue()&&(r.attributes.width=new wQ(t,"width",n.getString())),i.hasValue()&&(r.attributes.height=new wQ(t,"height",i.getString()))}var s=r.parent;r.parent=this,r.render(e),r.parent=s}}getBoundingBox(e){var{element:t}=this;return t?t.getBoundingBox(e):null}elementTransform(){var{document:e,element:t}=this;return TQ.fromElement(e,t)}get element(){return this.cachedElement||(this.cachedElement=this.getHrefAttribute().getDefinition()),this.cachedElement}}function SU(e,t,A,r,n,i){return e[A*r*4+4*t+i]}function NU(e,t,A,r,n,i,s){e[A*r*4+4*t+i]=s}function LU(e,t,A){return e[t]*A}function IU(e,t,A,r){return t+Math.cos(e)*A+Math.sin(e)*r}class _U extends jQ{constructor(e,t,A){super(e,t,A),this.type="feColorMatrix";var r=WF(this.getAttribute("values").getString());switch(this.getAttribute("type").getString("matrix")){case"saturate":var n=r[0];r=[.213+.787*n,.715-.715*n,.072-.072*n,0,0,.213-.213*n,.715+.285*n,.072-.072*n,0,0,.213-.213*n,.715-.715*n,.072+.928*n,0,0,0,0,0,1,0,0,0,0,0,1];break;case"hueRotate":var i=r[0]*Math.PI/180;r=[IU(i,.213,.787,-.213),IU(i,.715,-.715,-.715),IU(i,.072,-.072,.928),0,0,IU(i,.213,-.213,.143),IU(i,.715,.285,.14),IU(i,.072,-.072,-.283),0,0,IU(i,.213,-.213,-.787),IU(i,.715,-.715,.715),IU(i,.072,.928,.072),0,0,0,0,0,1,0,0,0,0,0,1];break;case"luminanceToAlpha":r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.2125,.7154,.0721,0,0,0,0,0,0,1]}this.matrix=r,this.includeOpacity=this.getAttribute("includeOpacity").hasValue()}apply(e,t,A,r,n){for(var{includeOpacity:i,matrix:s}=this,a=e.getImageData(0,0,r,n),o=0;o<n;o++)for(var l=0;l<r;l++){var c=SU(a.data,l,o,r,0,0),u=SU(a.data,l,o,r,0,1),h=SU(a.data,l,o,r,0,2),d=SU(a.data,l,o,r,0,3),f=LU(s,0,c)+LU(s,1,u)+LU(s,2,h)+LU(s,3,d)+LU(s,4,1),p=LU(s,5,c)+LU(s,6,u)+LU(s,7,h)+LU(s,8,d)+LU(s,9,1),g=LU(s,10,c)+LU(s,11,u)+LU(s,12,h)+LU(s,13,d)+LU(s,14,1),m=LU(s,15,c)+LU(s,16,u)+LU(s,17,h)+LU(s,18,d)+LU(s,19,1);i&&(f=0,p=0,g=0,m*=d/255),NU(a.data,l,o,r,0,0,f),NU(a.data,l,o,r,0,1,p),NU(a.data,l,o,r,0,2,g),NU(a.data,l,o,r,0,3,m)}e.clearRect(0,0,r,n),e.putImageData(a,0,0)}}class kU extends jQ{constructor(){super(...arguments),this.type="mask"}apply(e,t){var{document:A}=this,r=this.getAttribute("x").getPixels("x"),n=this.getAttribute("y").getPixels("y"),i=this.getStyle("width").getPixels("x"),s=this.getStyle("height").getPixels("y");if(!i&&!s){var a=new VQ;this.children.forEach(t=>{a.addBoundingBox(t.getBoundingBox(e))}),r=Math.floor(a.x1),n=Math.floor(a.y1),i=Math.floor(a.width),s=Math.floor(a.height)}var o=this.removeStyles(t,kU.ignoreStyles),l=A.createCanvas(r+i,n+s),c=l.getContext("2d");A.screen.setDefaults(c),this.renderChildren(c),new _U(A,{nodeType:1,childNodes:[],attributes:[{nodeName:"type",value:"luminanceToAlpha"},{nodeName:"includeOpacity",value:"true"}]}).apply(c,0,0,r+i,n+s);var u=A.createCanvas(r+i,n+s),h=u.getContext("2d");A.screen.setDefaults(h),t.render(h),h.globalCompositeOperation="destination-in",h.fillStyle=c.createPattern(l,"no-repeat"),h.fillRect(0,0,r+i,n+s),e.fillStyle=h.createPattern(u,"no-repeat"),e.fillRect(0,0,r+i,n+s),this.restoreStyles(t,o)}render(e){}}kU.ignoreStyles=["mask","transform","clip-path"];var OU=()=>{};class TU extends jQ{constructor(){super(...arguments),this.type="clipPath"}apply(e){var{document:t}=this,A=Reflect.getPrototypeOf(e),{beginPath:r,closePath:n}=e;A&&(A.beginPath=OU,A.closePath=OU),Reflect.apply(r,e,[]),this.children.forEach(r=>{if(void 0!==r.path){var i=void 0!==r.elementTransform?r.elementTransform():null;i||(i=TQ.fromElement(t,r)),i&&i.apply(e),r.path(e),A&&(A.closePath=n),i&&i.unapply(e)}}),Reflect.apply(n,e,[]),e.clip(),A&&(A.beginPath=r,A.closePath=n)}render(e){}}class jU extends jQ{constructor(){super(...arguments),this.type="filter"}apply(e,t){var{document:A,children:r}=this,n=t.getBoundingBox(e);if(n){var i=0,s=0;r.forEach(e=>{var t=e.extraFilterDistance||0;i=Math.max(i,t),s=Math.max(s,t)});var a=Math.floor(n.width),o=Math.floor(n.height),l=a+2*i,c=o+2*s;if(!(l<1||c<1)){var u=Math.floor(n.x),h=Math.floor(n.y),d=this.removeStyles(t,jU.ignoreStyles),f=A.createCanvas(l,c),p=f.getContext("2d");A.screen.setDefaults(p),p.translate(-u+i,-h+s),t.render(p),r.forEach(e=>{"function"==typeof e.apply&&e.apply(p,0,0,l,c)}),e.drawImage(f,0,0,l,c,u-i,h-s,l,c),this.restoreStyles(t,d)}}}render(e){}}jU.ignoreStyles=["filter","transform","clip-path"];class HU extends jQ{constructor(e,t,A){super(e,t,A),this.type="feDropShadow",this.addStylesFromStyleDefinition()}apply(e,t,A,r,n){}}class PU extends jQ{constructor(){super(...arguments),this.type="feMorphology"}apply(e,t,A,r,n){}}class DU extends jQ{constructor(){super(...arguments),this.type="feComposite"}apply(e,t,A,r,n){}}class MU extends jQ{constructor(e,t,A){super(e,t,A),this.type="feGaussianBlur",this.blurRadius=Math.floor(this.getAttribute("stdDeviation").getNumber()),this.extraFilterDistance=this.blurRadius}apply(e,t,A,r,n){var{document:i,blurRadius:s}=this,a=i.window?i.window.document.body:null,o=e.canvas;o.id=i.getUniqueId(),a&&(o.style.display="none",a.appendChild(o)),RF(o,t,A,r,n,s),a&&a.removeChild(o)}}class RU extends jQ{constructor(){super(...arguments),this.type="title"}}class VU extends jQ{constructor(){super(...arguments),this.type="desc"}}var KU={svg:JQ,rect:$Q,circle:ZQ,ellipse:eU,line:tU,polyline:AU,polygon:rU,path:zQ,pattern:nU,marker:iU,defs:sU,linearGradient:lU,radialGradient:cU,stop:uU,animate:hU,animateColor:dU,animateTransform:fU,font:pU,"font-face":gU,"missing-glyph":mU,glyph:qQ,text:WQ,tspan:XQ,tref:vU,a:wU,textPath:yU,image:xU,g:aU,symbol:FU,style:UU,use:EU,mask:kU,clipPath:TU,filter:jU,feDropShadow:HU,feMorphology:PU,feComposite:DU,feColorMatrix:_U,feGaussianBlur:MU,title:RU,desc:VU};function GU(e,t){var A=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),A.push.apply(A,r)}return A}function zU(){return zU=Jv(function*(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],A=document.createElement("img");return t&&(A.crossOrigin="Anonymous"),new Promise((t,r)=>{A.onload=()=>{t(A)},A.onerror=(e,t,A,n,i)=>{r(i)},A.src=e})}),zU.apply(this,arguments)}class qU{constructor(e){var{rootEmSize:t=12,emSize:A=12,createCanvas:r=qU.createCanvas,createImage:n=qU.createImage,anonymousCrossOrigin:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.canvg=e,this.definitions=Object.create(null),this.styles=Object.create(null),this.stylesSpecificity=Object.create(null),this.images=[],this.fonts=[],this.emSizeStack=[],this.uniqueId=0,this.screen=e.screen,this.rootEmSize=t,this.emSize=A,this.createCanvas=r,this.createImage=this.bindCreateImage(n,i),this.screen.wait(this.isImagesLoaded.bind(this)),this.screen.wait(this.isFontsLoaded.bind(this))}bindCreateImage(e,t){return"boolean"==typeof t?(A,r)=>e(A,"boolean"==typeof r?r:t):e}get window(){return this.screen.window}get fetch(){return this.screen.fetch}get ctx(){return this.screen.ctx}get emSize(){var{emSizeStack:e}=this;return e[e.length-1]}set emSize(e){var{emSizeStack:t}=this;t.push(e)}popEmSize(){var{emSizeStack:e}=this;e.pop()}getUniqueId(){return"canvg".concat(++this.uniqueId)}isImagesLoaded(){return this.images.every(e=>e.loaded)}isFontsLoaded(){return this.fonts.every(e=>e.loaded)}createDocumentElement(e){var t=this.createElement(e.documentElement);return t.root=!0,t.addStylesFromStyleDefinition(),this.documentElement=t,t}createElement(e){var t=e.nodeName.replace(/^[^:]+:/,""),A=qU.elementTypes[t];return void 0!==A?new A(this,e):new HQ(this,e)}createTextNode(e){return new YQ(this,e)}setViewBox(e){this.screen.setViewBox(function(e){for(var t=1;t<arguments.length;t++){var A=null!=arguments[t]?arguments[t]:{};t%2?GU(Object(A),!0).forEach(function(t){EC(e,t,A[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(A)):GU(Object(A)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(A,t))})}return e}({document:this},e))}}function WU(e,t){var A=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),A.push.apply(A,r)}return A}function XU(e){for(var t=1;t<arguments.length;t++){var A=null!=arguments[t]?arguments[t]:{};t%2?WU(Object(A),!0).forEach(function(t){EC(e,t,A[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(A)):WU(Object(A)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(A,t))})}return e}qU.createCanvas=function(e,t){var A=document.createElement("canvas");return A.width=e,A.height=t,A},qU.createImage=function(e){return zU.apply(this,arguments)},qU.elementTypes=KU;class YU{constructor(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.parser=new EQ(A),this.screen=new FQ(e,A),this.options=A;var r=new qU(this,A),n=r.createDocumentElement(t);this.document=r,this.documentElement=n}static from(e,t){var A=arguments;return Jv(function*(){var r=A.length>2&&void 0!==A[2]?A[2]:{},n=new EQ(r),i=yield n.parse(t);return new YU(e,i,r)})()}static fromString(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=new EQ(A).parseFromString(t);return new YU(e,r,A)}fork(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return YU.from(e,t,XU(XU({},this.options),A))}forkString(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return YU.fromString(e,t,XU(XU({},this.options),A))}ready(){return this.screen.ready()}isReady(){return this.screen.isReady()}render(){var e=arguments,t=this;return Jv(function*(){var A=e.length>0&&void 0!==e[0]?e[0]:{};t.start(XU({enableRedraw:!0,ignoreAnimation:!0,ignoreMouse:!0},A)),yield t.ready(),t.stop()})()}start(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{documentElement:t,screen:A,options:r}=this;A.start(t,XU(XU({enableRedraw:!0},r),e))}stop(){this.screen.stop()}resize(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,A=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this.documentElement.resize(e,t,A)}}var JU=Object.freeze({__proto__:null,AElement:wU,AnimateColorElement:dU,AnimateElement:hU,AnimateTransformElement:fU,BoundingBox:VQ,CB1:hQ,CB2:dQ,CB3:fQ,CB4:pQ,Canvg:YU,CircleElement:ZQ,ClipPathElement:TU,DefsElement:sU,DescElement:VU,Document:qU,Element:jQ,EllipseElement:eU,FeColorMatrixElement:_U,FeCompositeElement:DU,FeDropShadowElement:HU,FeGaussianBlurElement:MU,FeMorphologyElement:PU,FilterElement:jU,Font:RQ,FontElement:pU,FontFaceElement:gU,GElement:aU,GlyphElement:qQ,GradientElement:oU,ImageElement:xU,LineElement:tU,LinearGradientElement:lU,MarkerElement:iU,MaskElement:kU,Matrix:IQ,MissingGlyphElement:mU,Mouse:yQ,PSEUDO_ZERO:oQ,Parser:EQ,PathElement:zQ,PathParser:KQ,PatternElement:nU,Point:BQ,PolygonElement:rU,PolylineElement:AU,Property:wQ,QB1:gQ,QB2:mQ,QB3:vQ,RadialGradientElement:cU,RectElement:$Q,RenderedElement:GQ,Rotate:NQ,SVGElement:JQ,SVGFontLoader:QU,Scale:LQ,Screen:FQ,Skew:_Q,SkewX:kQ,SkewY:OQ,StopElement:uU,StyleElement:UU,SymbolElement:FU,TRefElement:vU,TSpanElement:XQ,TextElement:WQ,TextPathElement:yU,TitleElement:RU,Transform:TQ,Translate:SQ,UnknownElement:HQ,UseElement:EU,ViewPort:bQ,compressSpaces:GF,default:YU,getSelectorSpecificity:aQ,normalizeAttributeName:YF,normalizeColor:$F,parseExternalUrl:JF,presets:KF,toNumbers:WF,trimLeft:zF,trimRight:qF,vectorMagnitude:lQ,vectorsAngle:uQ,vectorsRatio:cQ});exports.ComponentActionFeatures=H,exports.ComponentSubmissionActions=D,exports.DfFormCheckbox=E,exports.DfFormComments=({comment:t="",onSave:A,placeholder:r="Enter your reason...",className:n="",disabled:i=!1})=>{const[s,a]=e.useState(!0),[o,l]=e.useState(t),[c,u]=e.useState(!1);e.useEffect(()=>{l(t),u(!1)},[t]);const h=e.useCallback(e=>{const A=e.target.value;l(A),u(A!==t)},[t]),d=e.useCallback(()=>{c&&A&&!i&&(A(o),u(!1))},[c,A,o,i]),f=e.useCallback(()=>{},[]),g=e.useCallback(()=>{i||a(!s)},[s,i]);return p.jsxs("div",{className:`df-form-comments ${n}`,children:[p.jsxs("div",{className:"df-form-comments__header",children:[p.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),p.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:g,"aria-expanded":s,"aria-label":"Toggle comments section",disabled:i,children:s?p.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):p.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),p.jsx("div",{className:"df-form-comments__content "+(s?"df-form-comments__content--expanded":""),children:p.jsx("div",{className:"df-form-comments__input-container",children:p.jsx("div",{className:"df-form-comments__input-line",children:p.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:o,onChange:h,onBlur:d,onFocus:f,placeholder:r,disabled:i})})})})]})},exports.DfFormDataGrid=z,exports.DfFormDateTime=L,exports.DfFormErrorMsg=w,exports.DfFormFileUpload=_,exports.DfFormHeading=O,exports.DfFormInput=F,exports.DfFormInstruction=T,exports.DfFormLocation=k,exports.DfFormPreview=({formComponents:t=[],currentDevice:A="desktop",isPreviewMode:r=!1,initialFormData:n=[],onSubmit:i,onFormDataChange:s,formTitle:a,formDescription:o,formTemplateId:l,onComponentSelect:c,onComponentDelete:u,onComponentEdit:h,onComponentUpdate:d,selectedComponent:f,workOrderNumber:g,assetNumber:w,isStandalone:b,user:B,onCreateIssue:y,onUpdateIssue:C})=>{const[x,j]=e.useState({}),[P,M]=e.useState({}),[V,K]=e.useState(!1),[G,W]=e.useState({}),[X,Y]=e.useState({}),[J,$]=e.useState(new Set),[Z,ee]=e.useState(new Map),[te,Ae]=e.useState({isValid:!0}),[re,ne]=e.useState({}),[ie,se]=e.useState({});e.useEffect(()=>{oe()},[t,n]);const ae=(e,t)=>{e.forEach(e=>{if(e.id&&(void 0!==t[e.id]||(e.basic&&"value"in e.basic&&void 0!==e.basic.value&&""!==e.basic.value&&null!==e.basic.value?t[e.id]=e.basic.value:e.basic&&"defaultValue"in e.basic&&void 0!==e.basic.defaultValue&&""!==e.basic.defaultValue&&null!==e.basic.defaultValue?t[e.id]=e.basic.defaultValue:"checkbox"===e.name||"select"===e.name?t[e.id]=[]:t[e.id]="")),e.cells&&Array.isArray(e.cells)&&e.cells.forEach((e,A)=>{Array.isArray(e)&&e.forEach((e,A)=>{e&&e.components&&Array.isArray(e.components)&&ae(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,A)=>{e&&e.components&&Array.isArray(e.components)&&ae(e.components,t)}),"file"===e.name&&e.basic){const A=e.basic.files||e.basic.attachments||e.basic.value;A&&(t[e.id]=A)}if(e.id&&e.basic&&e.basic.notes,"instructions"===e.name&&e.basic){e.basic.instructions||(e.basic.instructions=[]);const A=e.basic.value||e.basic.instructions;A&&(t[e.id]=A)}e.children&&Array.isArray(e.children)&&ae(e.children,t)})},oe=e.useCallback(()=>{const e={},A={},r={},i=new Set,s=e=>{e.forEach(e=>{var t,n,i,a,o;e.id&&(((null===(t=e.basic)||void 0===t?void 0:t.notes)||(null===(n=e.basic)||void 0===n?void 0:n.comments))&&(A[e.id]=(null===(i=e.basic)||void 0===i?void 0:i.notes)||(null===(a=e.basic)||void 0===a?void 0:a.comments)),(null===(o=e.basic)||void 0===o?void 0:o.attachments)&&(r[e.id]=e.basic.attachments)),e.children&&s(e.children),e.cells&&e.cells.forEach(e=>e.forEach(e=>{e.components&&s(e.components)})),e.entries&&e.entries.forEach(e=>{e.components&&s(e.components)})})},a=e=>{e.forEach((e,t)=>{var A;if(e.id&&"string"==typeof e.id&&""!==e.id.trim())i.has(e.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${e.id}. Component:`,e),e.id=`${e.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${e.id}`));else{const r=e.name||"component",n=((null===(A=e.basic)||void 0===A?void 0:A.label)||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);e.id=`${r}-${n||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${t}`}i.add(e.id),e.children&&Array.isArray(e.children)&&a(e.children),e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&a(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&a(e.components)})})};t&&t.length>0&&a(t),n&&n.length>0&&a(n),n&&n.length>0&&ae(n,e),n&&n.length>0&&ae(n,e),t&&t.length>0&&(ae(t,e),s(t)),j(t=>Object.assign(Object.assign({},e),t)),ne(e=>Object.assign(Object.assign({},A),e)),se(e=>Object.assign(Object.assign({},r),e)),ce()},[n,t]),le=(e,A)=>{e.forEach(e=>{if(e.id)if("table"===e.name||"datagrid"===e.name)A[e.id]=!0;else if(e.conditional){const r=m.evaluateConditionalLogic(e.conditional,t,x);A[e.id]=r.shouldShow}else A[e.id]=!0;e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{e.forEach(e=>{e.components&&Array.isArray(e.components)&&le(e.components,A)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&le(e.components,A)}),e.children&&Array.isArray(e.children)&&le(e.children,A)})},ce=e.useCallback(()=>{const e={};t&&t.length>0&&le(t,e),Y(e)},[t,x]),ue=e.useCallback(e=>{const A=t.find(t=>t.id===e);if(A&&("table"===A.name||"datagrid"===A.name))return!0;return!1!==X[e]},[X,t]),he=e.useCallback(e=>{if(!e.id||"string"!=typeof e.id||""===e.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",e);const A=t.filter(t=>t.id===e.id);if(A.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${e.id}":`,A.map(e=>{var t;return{id:e.id,name:e.name,label:null===(t=e.basic)||void 0===t?void 0:t.label}}));const n=x[e.id];void 0!==n&&n!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:n,newValue:e.value});const i=Object.assign(Object.assign({},x),{[e.id]:e.value});j(i);const a=t.find(t=>t.id===e.id);if(a){const e=null==a?void 0:a.threshold;e&&e.conditions&&e.conditions.length>0&&$(t=>{const A=new Set(t);return e.conditions.forEach(e=>{A.delete(e.id)}),A})}const o=t=>t.map(t=>{var A;return t.id===e.id&&"defaultValue"in t.basic?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{value:null!==(A=e.value)&&void 0!==A?A:t.basic.defaultValue,defaultValue:e.value})}):"section"===t.name&&t.children?Object.assign(Object.assign({},t),{children:o(t.children)}):"table"===t.name&&t.cells?Object.assign(Object.assign({},t),{cells:t.cells.map(e=>e.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=o(t.components)),t}))}):"datagrid"===t.name&&t.entries?Object.assign(Object.assign({},t),{entries:t.entries.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=o(t.components)),t})}):t}),l=o(t);if(null==s||s(l),P[e.id]&&M(t=>Object.assign(Object.assign({},t),{[e.id]:""})),!r){if(e.isValid)return void M(t=>{const A=t[e.id];return A&&""!==A.trim()?Object.assign(Object.assign({},t),{[e.id]:""}):t});setTimeout(()=>{fe(e.id)},150)}setTimeout(()=>{const e={};t.forEach(A=>{if("table"===A.name||"datagrid"===A.name)e[A.id]=!0;else if(A.conditional){const r=m.evaluateConditionalLogic(A.conditional,t,i);e[A.id]=r.shouldShow}else e[A.id]=!0}),Y(e)},0)},[t,x,P,s]),de=e.useCallback((e,t)=>{for(const A of e){if(A.id===t)return A;if("section"===A.name&&A.children){const e=de(A.children,t);if(e)return e}if("table"===A.name&&A.cells)for(const e of A.cells)for(const A of e)if(A.components){const e=de(A.components,t);if(e)return e}if("datagrid"===A.name&&A.entries)for(const e of A.entries)if(e.components){const A=de(e.components,t);if(A)return A}}return null},[]),fe=e.useCallback(e=>{if(r)return;const A=de(t,e);if(!A)return;const n=x[e]||"";if("number-input"===A.name&&(!n||""===n)){if(A.validation.required){const t=A.validation.customValidationMessage,r=A.basic.label||"This field",n=t||`${r} is required`;M(t=>Object.assign(Object.assign({},t),{[e]:n}))}else M(t=>Object.assign(Object.assign({},t),{[e]:""}));return}let i=!1;i=Array.isArray(n)?n.length>0:"string"==typeof n?""!==n.trim():null!=n;let s="";if(A.validation.required&&!i){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} is required`}else if("email-input"===A.name&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} must be a valid email`}else if(A.validation.minLength&&i&&n.length<A.validation.minLength){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} must be at least ${A.validation.minLength} characters`}else if(A.validation.maxLength&&i&&n.length>A.validation.maxLength){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} must be no more than ${A.validation.maxLength} characters`}else if("number-input"===A.name&&i){const e=String(n).trim(),t=parseFloat(e);if(!isNaN(t)){const e=A.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&t<e.lowerLimit?s="Number is below the lower limit":e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&t>e.upperLimit&&(s="Number is above the upper limit")}}M(t=>Object.assign(Object.assign({},t),{[e]:s}))},[t,r,x,de]),pe=e.useCallback(e=>{W(t=>Object.assign(Object.assign({},t),{[e]:!0})),r||setTimeout(()=>{fe(e)},0)},[r,fe]),ge=e.useCallback(e=>{P[e]&&M(t=>Object.assign(Object.assign({},t),{[e]:""}))},[P]),me=e.useCallback(()=>!Object.values(P).some(e=>e&&"string"==typeof e&&""!==e.trim())&&t.every(e=>{const t=x[e.id]||"";let A=!1;if(A=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!A)return!1;if("number-input"===e.name&&A){const A=String(t).trim(),r=parseFloat(A);if(!isNaN(r)){const t=e.validation;if(t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&r<t.lowerLimit)return!1;if(t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&r>t.upperLimit)return!1}}return!0}),[t,x,P]),ve=e.useCallback((e,t)=>{if(Array.isArray(t))return t.some(t=>ve(e,t));if(null==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))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}const n=String(t).toLowerCase(),i=String(e.value).toLowerCase();switch(e.operator){case"equals":return n===i||String(t)===String(e.value);case"notEquals":return n!==i&&String(t)!==String(e.value);default:return!1}},[]),we=e.useCallback(()=>{if(r)return[];const e=[];return t.forEach(t=>{const A=null==t?void 0:t.condition;if(!A||!A.conditions||0===A.conditions.length)return;const r=x[t.id];null!=r&&""!==r&&!(Array.isArray(r)&&0===r.length)&&A.conditions.forEach(A=>{var n;ve(A,r)&&e.push({componentId:t.id,condition:A,componentLabel:(null===(n=t.basic)||void 0===n?void 0:n.label)||"Field"})})}),e},[t,x,r,ve]),be=e.useCallback(()=>{if(r)return{isValid:!0};const e=we();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:A}of e){const e=Z.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},r=[];if(!0!==t.enableRaiseIssue||J.has(t.id)||r.push("raise an issue"),!0!==t.enableNotes||e.notesCompleted||r.push("add notes"),!0!==t.enableAttachment||e.attachmentsCompleted||r.push("add attachments"),!0!==t.enableSendEmail||e.emailSent||r.push("send email"),r.length>0){return{isValid:!1,errorMessage:`Please ${1===r.length?r[0]:r.slice(0,-1).join(", ")+" and "+r[r.length-1]} for the threshold condition met in "${A}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[r,we,J,Z]),Be=e.useCallback(e=>{e&&$(t=>{const A=new Set(t);return A.add(e),A})},[]),ye=e.useCallback((e,t,A)=>{e&&ee(r=>{const n=new Map(r),i=n.get(e)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===t?n.set(e,Object.assign(Object.assign({},i),{notesCompleted:A})):"attachments"===t?n.set(e,Object.assign(Object.assign({},i),{attachmentsCompleted:A})):"email"===t&&n.set(e,Object.assign(Object.assign({},i),{emailSent:A})),n})},[]);e.useEffect(()=>{if(!r){const e=be();Ae(e)}},[x,J,Z,r,be]);const Ce=e.useCallback(()=>{if(r)return!0;let e=!0;K(!0);const A={};return t.forEach(t=>{const r=x[t.id]||"";let n=!1;if(n=Array.isArray(r)?r.length>0:"string"==typeof r?""!==r.trim():null!=r,t.validation.required&&!n){const r=t.validation.customValidationMessage,n=t.basic.label||"This field",i=r||`${n} is required`;A[t.id]=i,e=!1}else if("number-input"===t.name&&n){const n=String(r).trim(),i=parseFloat(n);if(isNaN(i))A[t.id]="";else{const r=t.validation;r&&"lowerLimit"in r&&void 0!==r.lowerLimit&&null!==r.lowerLimit&&0!==r.lowerLimit&&i<r.lowerLimit?(A[t.id]="Number is below the lower limit",e=!1):r&&"upperLimit"in r&&void 0!==r.upperLimit&&null!==r.upperLimit&&0!==r.upperLimit&&i>r.upperLimit?(A[t.id]="Number is above the upper limit",e=!1):A[t.id]=""}}else A[t.id]="";W(e=>Object.assign(Object.assign({},e),{[t.id]:!0}))}),M(A),e},[t,r,x]),xe=e.useCallback((e="Submitted")=>{if(K(!0),!Ce()){const e=t.find(e=>{const t=x[e.id]||"";let A=!1;return A=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!A});if(e){const t=document.getElementById(e.id);t&&t.focus()}return}const A=be();if(!A.isValid){A.errorMessage&&v.showError(A.errorMessage);const e=we().find(({condition:e})=>!J.has(e.id));if(e){const t=document.getElementById(e.componentId);t&&t.scrollIntoView({behavior:"smooth",block:"center"})}return}const r=e=>e.map(e=>{var t,A,n,i,s,a;let o=x[e.id];"text-input"===e.name&&(null===(t=e.basic)||void 0===t||t.label),void 0===o&&(o="value"in e.basic&&void 0!==e.basic.value?e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?e.basic.defaultValue:""),"text-input"===e.name&&(null===(A=e.basic)||void 0===A||A.label);const l=Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{value:o,defaultValue:o,notes:void 0!==re[e.id]?re[e.id]:null===(n=e.basic)||void 0===n?void 0:n.notes,comments:void 0!==re[e.id]?re[e.id]:(null===(i=e.basic)||void 0===i?void 0:i.comments)||(null===(s=e.basic)||void 0===s?void 0:s.notes),attachments:void 0!==ie[e.id]?ie[e.id]:null===(a=e.basic)||void 0===a?void 0:a.attachments})});return"section"===l.name&&l.children&&(l.children=r(l.children)),"table"===l.name&&l.cells&&(l.cells=l.cells.map(e=>e.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=r(t.components)),t}))),"datagrid"===l.name&&l.entries&&(l.entries=l.entries.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=r(t.components)),t})),l}),n=r(t),s=Object.assign(Object.assign({},x),{status:e});null==i||i(n,s)},[t,x,Ce,i,re,ie]),Fe=e.useCallback(()=>({[`device-${A}`]:!0,readonly:r}),[A,r]),Qe=e.useCallback((e,t)=>{ne(A=>Object.assign(Object.assign({},A),{[e]:t}))},[]),Ue=e.useCallback((e,t)=>{se(A=>Object.assign(Object.assign({},A),{[e]:t||[]}))},[]),Ee=e.useRef(new Map),Se=e.useRef(0),Ne=A=>{var r,n,i,a,o,m,v,b,H,D,M,K,W;let X;if(A.id&&"string"==typeof A.id&&""!==A.id.trim())X=A.id;else{const e=(null===(r=A.basic)||void 0===r?void 0:r.label)||"",t=A.name||"unknown",n=`${t}-${e}`;let i=Ee.current.get(n);i||(Se.current+=1,i=`generated-${t}-${Se.current}-${Math.random().toString(36).substr(2,9)}`,Ee.current.set(n,i),console.warn("[DfFormPreview] Generated and cached ID for component:",i,"key:",n)),X=i,A=Object.assign(Object.assign({},A),{id:X})}const Y=X,$=x[Y];if(void 0!==$){const e=t.filter(e=>e.id!==Y&&x[e.id]===$);e.length>0&&console.warn(`[DfFormPreview] Component ${Y} shares form value with other components:`,e.map(e=>e.id))}const Z={id:Y,validationErrors:P,formValue:$,touchedFields:G,formSubmitted:V,mode:"test",readonly:!1,onValueChange:he,onBlur:()=>pe(Y),onFocus:()=>ge(Y)};switch(A.name){case"text-input":case"number-input":case"email-input":return p.jsx(F,Object.assign({},Z,{properties:A,inputType:"text-input"===A.name?"text":"number-input"===A.name?"number":"email",formTemplateId:l,onThresholdIssueRaised:Be,raisedThresholdIssues:J,workOrderNumber:g,assetNumber:w,user:B}));case"textarea":return p.jsx(Q,Object.assign({},Z,{properties:A}));case"select":const r=Object.assign(Object.assign({},A),{options:(null===(n=A.basic)||void 0===n?void 0:n.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(i=A.basic)||void 0===i?void 0:i.comments)||""})});return p.jsx(U,Object.assign({},Z,{properties:r}));case"checkbox":const X=Object.assign(Object.assign({},A),{options:(null===(a=A.basic)||void 0===a?void 0:a.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(o=A.basic)||void 0===o?void 0:o.comments)||""})});return p.jsx(E,Object.assign({},Z,{properties:X}));case"radio":const Y=Object.assign(Object.assign({},A),{options:(null===(m=A.basic)||void 0===m?void 0:m.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(v=A.basic)||void 0===v?void 0:v.comments)||""})});return p.jsx(S,Object.assign({},Z,{properties:Y}));case"segment":const ee=Object.assign(Object.assign({},A),{options:(null===(b=A.basic)||void 0===b?void 0:b.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(H=A.basic)||void 0===H?void 0:H.comments)||""})});return p.jsx(N,Object.assign({},Z,{properties:ee}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},Z,{properties:A}));case"signature":return p.jsx(I,Object.assign({},Z,{properties:A}));case"heading":return p.jsx(O,Object.assign({},Z,{properties:A}));case"instructions":const te=$||(null===(D=A.basic)||void 0===D?void 0:D.value)||null;return p.jsx(T,Object.assign({},Z,{properties:A,formValue:te}));case"location":return p.jsx(k,Object.assign({},Z,{properties:A}));case"section":return p.jsx(R,Object.assign({},Z,{properties:A,formData:x,formTemplateId:l,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,onNotesChange:Qe,onAttachmentChange:Ue,workOrderNumber:g,assetNumber:w,user:B,onCreateIssue:y,onUpdateIssue:C,renderFormComponent:e=>Ne(e)}));case"table":return p.jsx(e.Suspense,{fallback:p.jsx("div",{children:"Loading table..."}),children:p.jsx(q,Object.assign({},Z,{properties:A,formData:x,formTemplateId:l,mode:Z.mode,validationErrors:P,touchedFields:G,formSubmitted:V,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,workOrderNumber:g,assetNumber:w,onCreateIssue:y,onUpdateIssue:C,onNotesChange:(e,r)=>{const n=t.map(t=>{if(t.id===A.id&&t.cells){const A=t.cells.map(t=>t.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{notes:r})}):t);return Object.assign(Object.assign({},t),{components:A})}return t}));return Object.assign(Object.assign({},t),{cells:A})}return t});null==s||s(n)},onAttachmentChange:(e,r)=>{const n=t.map(t=>{if(t.id===A.id&&t.cells){const A=t.cells.map(t=>t.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{attachments:r||[]})}):t);return Object.assign(Object.assign({},t),{components:A})}return t}));return Object.assign(Object.assign({},t),{cells:A})}return t});null==s||s(n)},renderFormComponent:e=>Ne(e)}))});case"datagrid":return p.jsx(z,Object.assign({},Z,{properties:A,formData:x,formTemplateId:l,mode:Z.mode,validationErrors:P,touchedFields:G,formSubmitted:V,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,workOrderNumber:g,assetNumber:w,user:B,onComponentSelect:c,onComponentDelete:u,onComponentEdit:h,onCreateIssue:y,onUpdateIssue:C,onComponentUpdate:d,selectedComponent:f,onNotesChange:(e,r)=>{Qe(e,r);const n=t.map(t=>{if(t.id===A.id&&t.entries){const A=t.entries.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{notes:r||""})}):t);return Object.assign(Object.assign({},t),{components:A})}return t});return Object.assign(Object.assign({},t),{entries:A})}return t});null==s||s(n)},onAttachmentChange:(e,r)=>{Ue(e,r);const n=t.map(t=>{if(t.id===A.id&&t.entries){const A=t.entries.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{attachments:r||[]})}):t);return Object.assign(Object.assign({},t),{components:A})}return t});return Object.assign(Object.assign({},t),{entries:A})}return t});null==s||s(n)},onValueChange:e=>{if(e.id===A.id&&e.value&&"object"==typeof e.value&&"entries"in e.value){const r=t.map(t=>t.id===A.id?Object.assign(Object.assign({},t),e.value):t);null==s||s(r),e.value.entries&&Array.isArray(e.value.entries)&&e.value.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&e.components.forEach(e=>{var t;if(void 0!==x[e.id]);else{const A=null===(t=e.basic)||void 0===t?void 0:t.defaultValue;void 0!==A&&j(t=>Object.assign(Object.assign({},t),{[e.id]:A}))}})})}else he(e)},onEntryAdd:()=>{const e=t.find(e=>e.id===A.id);if(e&&e.entries){const e=t.map(e=>e.id===A.id?Object.assign(Object.assign({},e),{entries:e.entries||[]}):e);null==s||s(e)}else setTimeout(()=>{const e=x[A.id];if(e&&"object"==typeof e&&"entries"in e){const r=t.map(t=>t.id===A.id?Object.assign(Object.assign({},t),{entries:e.entries}):t);null==s||s(r)}},100)},onEntryRemove:e=>{const r=t.map(t=>{if(t.id===A.id&&t.entries){const A=(t.entries||[]).filter((t,A)=>A!==e).map((e,A)=>{var r;return Object.assign(Object.assign({},e),{index:A,id:`entry-${t.id}-${A}`,components:(null===(r=e.components)||void 0===r?void 0:r.map((e,t)=>{const r=(e.templateComponents||[])[t];return Object.assign(Object.assign({},e),{id:r?`${r.id}-entry-${A}-${t}`:e.id})}))||[]})});return Object.assign(Object.assign({},t),{entries:A})}return t});null==s||s(r)},renderFormComponent:e=>Ne(e)}));case"file":const Ae=$||(null===(M=A.basic)||void 0===M?void 0:M.value)||(null===(K=A.basic)||void 0===K?void 0:K.files)||(null===(W=A.basic)||void 0===W?void 0:W.attachments)||null;return p.jsx(_,Object.assign({},Z,{properties:A,formValue:Ae}));default:return p.jsx("div",{className:"form-group",children:p.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",A.name]})})}};return p.jsx("div",{className:"form-preview-container",children:p.jsx("div",{className:"form-preview-wrapper",children:p.jsxs("div",{className:`form-preview ${Object.entries(Fe()).map(([e,t])=>t?e:"").join(" ")}`,children:[p.jsx("div",{className:"form-canvas-header"}),0===t.length?p.jsx("div",{className:"empty-state",children:p.jsx("div",{className:"empty-state-card",children:p.jsx("div",{className:"empty-state-preview-area",children:p.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):p.jsxs("form",{className:"form-preview-form",onSubmit:e=>{e.preventDefault(),xe()},children:[(a||o)&&p.jsxs("div",{className:"form-header",children:[a&&p.jsx("h1",{className:"form-title",children:a}),o&&p.jsx("p",{className:"form-description",children:o})]}),t.map(e=>{var A,n,i,a;const o=e.basic,c=x[e.id],u=["select","radio","checkbox","segment"].includes(e.name||""),h=e.options||(null==o?void 0:o.options)||[],d=(()=>{var t;const A=null===(t=null==e?void 0:e.styles)||void 0===t?void 0:t.column;return"section"===e.name||"table"===e.name||"datagrid"===e.name?"col-12":3===A?"col-3":6===A?"col-6":9===A?"col-9":"col-12"})();let f=!1;if(!r)if(u&&null!=c&&""!==c)if("checkbox"===e.name){f=(Array.isArray(c)?c:[c]).some(e=>{const t=h.find(t=>t.value===e);return t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)})}else{const e=h.find(e=>e.value===c);f=e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)}else f=(null==o?void 0:o.enableNotes)||(null==o?void 0:o.enableAttachment)||(null==o?void 0:o.enableRaiseIssue)||(null==o?void 0:o.enableSendEmail);const m=r&&((null===(A=e.basic)||void 0===A?void 0:A.notes)&&e.basic.notes.trim().length>0||(null===(n=e.basic)||void 0===n?void 0:n.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return p.jsxs("div",{className:`form-group ${d} ${f||m?"has-action-features":""}`,style:{display:ue(e.id)?"block":"none"},children:[Ne(e),!r&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:r?"preview":"test",formTemplateId:l,formValue:c,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,onNotesChange:A=>{ne(t=>Object.assign(Object.assign({},t),{[e.id]:A}));const r=t.map(t=>t.id===e.id?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{notes:A||""})}):t);null==s||s(r)},onAttachmentChange:A=>{se(t=>Object.assign(Object.assign({},t),{[e.id]:A||[]}));const r=t.map(t=>t.id===e.id?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{attachments:A||[]})}):t);null==s||s(r)},notes:void 0!==re[e.id]?re[e.id]:(null===(i=e.basic)||void 0===i?void 0:i.notes)||"",attachments:void 0!==ie[e.id]?ie[e.id]:(null===(a=e.basic)||void 0===a?void 0:a.attachments)||null,workOrderNumber:g,assetNumber:w,isStandalone:b,user:B,onCreateIssue:y,onUpdateIssue:C}),r&&m&&p.jsx(D,{component:e})]},e.id)}),!r&&p.jsxs("div",{className:"form-actions",children:[p.jsx("button",{type:"button",onClick:()=>xe("Saved"),className:"form-save-button",disabled:V&&!me(),children:"Save"}),p.jsx("button",{type:"button",disabled:!me()||!te.isValid,className:"form-submit-button",title:te.isValid?"":te.errorMessage,onClick:()=>xe("Submitted"),children:"Submit"})]})]})]})})})},exports.DfFormRadio=S,exports.DfFormSection=R,exports.DfFormSegment=N,exports.DfFormSelect=U,exports.DfFormSignature=I,exports.DfFormTable=$,exports.DfFormTextarea=Q,exports.FormSubmissionPdf=oe,exports.RaiseIssueModal=C,exports.ThresholdAlert=x,exports.conditionalLogicService=m,exports.generateFormPdf=e=>b(void 0,void 0,void 0,function*(){return new Promise((t,A)=>b(void 0,void 0,void 0,function*(){var r;let n=null,i=null;try{console.log("[PDF Generator] Generating PDF with options:",{formTitle:e.formTitle,userName:e.userName,componentCount:(null===(r=e.components)||void 0===r?void 0:r.length)||0}),e.components&&e.components.length>0&&console.log("[PDF Generator] Sample components (first 3):",e.components.slice(0,3).map(e=>{var t,A,r,n;return{name:e.name,label:null===(t=e.basic)||void 0===t?void 0:t.label,value:null===(A=e.basic)||void 0===A?void 0:A.value,defaultValue:null===(r=e.basic)||void 0===r?void 0:r.defaultValue,hasValue:void 0!==(null===(n=e.basic)||void 0===n?void 0:n.value)}})),n=document.createElement("div"),n.style.position="absolute",n.style.top="-9999px",n.style.left="-9999px",n.style.width="794px",n.style.backgroundColor="#ffffff",n.style.zIndex="-1000",document.body.appendChild(n),i=le(n),i.render(p.jsx(oe,{formTitle:e.formTitle,formDescription:e.formDescription,userName:e.userName,components:e.components})),yield new Promise(e=>setTimeout(e,1e3));const A=yield fe(n,{scale:2,useCORS:!0,logging:!1,backgroundColor:"#ffffff",windowWidth:794}),s=A.toDataURL("image/jpeg",.95),a=new Xi({orientation:"portrait",unit:"mm",format:"a4"}),o=210,l=297,c=A.height*o/A.width;let u=c,h=0;for(a.addImage(s,"JPEG",0,h,o,c),u-=l;u>0;)h-=l,a.addPage(),a.addImage(s,"JPEG",0,h,o,c),u-=l;const d=a.output("blob");t(d)}catch(e){console.error("Error generating PDF:",e),A(e)}finally{i&&setTimeout(()=>{i.unmount(),n&&n.parentNode&&n.parentNode.removeChild(n)},100)}}))}),exports.toastService=v;
364
+ var DF=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],MF=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function RF(e,t,A,r,n,i){if(!(isNaN(i)||i<1)){i|=0;var s=function(e,t,A,r,n){if("string"==typeof e&&(e=document.getElementById(e)),!e||"object"!==PF(e)||!("getContext"in e))throw new TypeError("Expecting canvas with `getContext` method in processCanvasRGB(A) calls!");var i=e.getContext("2d");try{return i.getImageData(t,A,r,n)}catch(e){throw new Error("unable to access image data: "+e)}}(e,t,A,r,n);s=function(e,t,A,r,n,i){for(var s,a=e.data,o=2*i+1,l=r-1,c=n-1,u=i+1,h=u*(u+1)/2,d=new VF,f=d,p=1;p<o;p++)f=f.next=new VF,p===u&&(s=f);f.next=d;for(var g=null,m=null,v=0,w=0,b=DF[i],B=MF[i],y=0;y<n;y++){f=d;for(var C=a[w],x=a[w+1],F=a[w+2],Q=a[w+3],U=0;U<u;U++)f.r=C,f.g=x,f.b=F,f.a=Q,f=f.next;for(var E=0,S=0,N=0,L=0,I=u*C,_=u*x,k=u*F,O=u*Q,T=h*C,j=h*x,H=h*F,P=h*Q,D=1;D<u;D++){var M=w+((l<D?l:D)<<2),R=a[M],V=a[M+1],K=a[M+2],G=a[M+3],z=u-D;T+=(f.r=R)*z,j+=(f.g=V)*z,H+=(f.b=K)*z,P+=(f.a=G)*z,E+=R,S+=V,N+=K,L+=G,f=f.next}g=d,m=s;for(var q=0;q<r;q++){var W=P*b>>>B;if(a[w+3]=W,0!==W){var X=255/W;a[w]=(T*b>>>B)*X,a[w+1]=(j*b>>>B)*X,a[w+2]=(H*b>>>B)*X}else a[w]=a[w+1]=a[w+2]=0;T-=I,j-=_,H-=k,P-=O,I-=g.r,_-=g.g,k-=g.b,O-=g.a;var Y=q+i+1;Y=v+(Y<l?Y:l)<<2,T+=E+=g.r=a[Y],j+=S+=g.g=a[Y+1],H+=N+=g.b=a[Y+2],P+=L+=g.a=a[Y+3],g=g.next;var J=m,$=J.r,Z=J.g,ee=J.b,te=J.a;I+=$,_+=Z,k+=ee,O+=te,E-=$,S-=Z,N-=ee,L-=te,m=m.next,w+=4}v+=r}for(var Ae=0;Ae<r;Ae++){var re=a[w=Ae<<2],ne=a[w+1],ie=a[w+2],se=a[w+3],ae=u*re,oe=u*ne,le=u*ie,ce=u*se,ue=h*re,he=h*ne,de=h*ie,fe=h*se;f=d;for(var pe=0;pe<u;pe++)f.r=re,f.g=ne,f.b=ie,f.a=se,f=f.next;for(var ge=r,me=0,ve=0,we=0,be=0,Be=1;Be<=i;Be++){w=ge+Ae<<2;var ye=u-Be;ue+=(f.r=re=a[w])*ye,he+=(f.g=ne=a[w+1])*ye,de+=(f.b=ie=a[w+2])*ye,fe+=(f.a=se=a[w+3])*ye,be+=re,me+=ne,ve+=ie,we+=se,f=f.next,Be<c&&(ge+=r)}w=Ae,g=d,m=s;for(var Ce=0;Ce<n;Ce++){var xe=w<<2;a[xe+3]=se=fe*b>>>B,se>0?(se=255/se,a[xe]=(ue*b>>>B)*se,a[xe+1]=(he*b>>>B)*se,a[xe+2]=(de*b>>>B)*se):a[xe]=a[xe+1]=a[xe+2]=0,ue-=ae,he-=oe,de-=le,fe-=ce,ae-=g.r,oe-=g.g,le-=g.b,ce-=g.a,xe=Ae+((xe=Ce+u)<c?xe:c)*r<<2,ue+=be+=g.r=a[xe],he+=me+=g.g=a[xe+1],de+=ve+=g.b=a[xe+2],fe+=we+=g.a=a[xe+3],g=g.next,ae+=re=m.r,oe+=ne=m.g,le+=ie=m.b,ce+=se=m.a,be-=re,me-=ne,ve-=ie,we-=se,m=m.next,w+=r}}return e}(s,0,0,r,n,i),e.getContext("2d").putImageData(s,t,A)}}var VF=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.r=0,this.g=0,this.b=0,this.a=0,this.next=null};var KF=Object.freeze({__proto__:null,offscreen:function(){var{DOMParser:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={window:null,ignoreAnimation:!0,ignoreMouse:!0,DOMParser:e,createCanvas:(e,t)=>new OffscreenCanvas(e,t),createImage:e=>Jv(function*(){var t=yield fetch(e),A=yield t.blob();return yield createImageBitmap(A)})()};return"undefined"==typeof DOMParser&&void 0!==e||Reflect.deleteProperty(t,"DOMParser"),t},node:function(e){var{DOMParser:t,canvas:A,fetch:r}=e;return{window:null,ignoreAnimation:!0,ignoreMouse:!0,DOMParser:t,fetch:r,createCanvas:A.createCanvas,createImage:A.loadImage}}});function GF(e){return e.replace(/(?!\u3000)\s+/gm," ")}function zF(e){return e.replace(/^[\n \t]+/,"")}function qF(e){return e.replace(/[\n \t]+$/,"")}function WF(e){return((e||"").match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm)||[]).map(parseFloat)}var XF=/^[A-Z-]+$/;function YF(e){return XF.test(e)?e.toLowerCase():e}function JF(e){var t=/url\(('([^']+)'|"([^"]+)"|([^'")]+))\)/.exec(e)||[];return t[2]||t[3]||t[4]}function $F(e){if(!e.startsWith("rgb"))return e;var t=3;return e.replace(/\d+(\.\d+)?/g,(e,A)=>t--&&A?String(Math.round(parseFloat(e))):e)}var ZF=/(\[[^\]]+\])/g,eQ=/(#[^\s+>~.[:]+)/g,tQ=/(\.[^\s+>~.[:]+)/g,AQ=/(::[^\s+>~.[:]+|:first-line|:first-letter|:before|:after)/gi,rQ=/(:[\w-]+\([^)]*\))/gi,nQ=/(:[^\s+>~.[:]+)/g,iQ=/([^\s+>~.[:]+)/g;function sQ(e,t){var A=t.exec(e);return A?[e.replace(t," "),A.length]:[e,0]}function aQ(e){var t=[0,0,0],A=e.replace(/:not\(([^)]*)\)/g," $1 ").replace(/{[\s\S]*/gm," "),r=0;return[A,r]=sQ(A,ZF),t[1]+=r,[A,r]=sQ(A,eQ),t[0]+=r,[A,r]=sQ(A,tQ),t[1]+=r,[A,r]=sQ(A,AQ),t[2]+=r,[A,r]=sQ(A,rQ),t[1]+=r,[A,r]=sQ(A,nQ),t[1]+=r,A=A.replace(/[*\s+>~]/g," ").replace(/[#.]/g," "),[A,r]=sQ(A,iQ),t[2]+=r,t.join("")}var oQ=1e-8;function lQ(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2))}function cQ(e,t){return(e[0]*t[0]+e[1]*t[1])/(lQ(e)*lQ(t))}function uQ(e,t){return(e[0]*t[1]<e[1]*t[0]?-1:1)*Math.acos(cQ(e,t))}function hQ(e){return e*e*e}function dQ(e){return 3*e*e*(1-e)}function fQ(e){return 3*e*(1-e)*(1-e)}function pQ(e){return(1-e)*(1-e)*(1-e)}function gQ(e){return e*e}function mQ(e){return 2*e*(1-e)}function vQ(e){return(1-e)*(1-e)}class wQ{constructor(e,t,A){this.document=e,this.name=t,this.value=A,this.isNormalizedColor=!1}static empty(e){return new wQ(e,"EMPTY","")}split(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:" ",{document:t,name:A}=this;return GF(this.getString()).trim().split(e).map(e=>new wQ(t,A,e))}hasValue(e){var{value:t}=this;return null!==t&&""!==t&&(e||0!==t)&&void 0!==t}isString(e){var{value:t}=this,A="string"==typeof t;return A&&e?e.test(t):A}isUrlDefinition(){return this.isString(/^url\(/)}isPixels(){if(!this.hasValue())return!1;var e=this.getString();switch(!0){case e.endsWith("px"):case/^[0-9]+$/.test(e):return!0;default:return!1}}setValue(e){return this.value=e,this}getValue(e){return void 0===e||this.hasValue()?this.value:e}getNumber(e){if(!this.hasValue())return void 0===e?0:parseFloat(e);var{value:t}=this,A=parseFloat(t);return this.isString(/%$/)&&(A/=100),A}getString(e){return void 0===e||this.hasValue()?void 0===this.value?"":String(this.value):String(e)}getColor(e){var t=this.getString(e);return this.isNormalizedColor||(this.isNormalizedColor=!0,t=$F(t),this.value=t),t}getDpi(){return 96}getRem(){return this.document.rootEmSize}getEm(){return this.document.emSize}getUnits(){return this.getString().replace(/[0-9.-]/g,"")}getPixels(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasValue())return 0;var[A,r]="boolean"==typeof e?[void 0,e]:[e],{viewPort:n}=this.document.screen;switch(!0){case this.isString(/vmin$/):return this.getNumber()/100*Math.min(n.computeSize("x"),n.computeSize("y"));case this.isString(/vmax$/):return this.getNumber()/100*Math.max(n.computeSize("x"),n.computeSize("y"));case this.isString(/vw$/):return this.getNumber()/100*n.computeSize("x");case this.isString(/vh$/):return this.getNumber()/100*n.computeSize("y");case this.isString(/rem$/):return this.getNumber()*this.getRem();case this.isString(/em$/):return this.getNumber()*this.getEm();case this.isString(/ex$/):return this.getNumber()*this.getEm()/2;case this.isString(/px$/):return this.getNumber();case this.isString(/pt$/):return this.getNumber()*this.getDpi()*(1/72);case this.isString(/pc$/):return 15*this.getNumber();case this.isString(/cm$/):return this.getNumber()*this.getDpi()/2.54;case this.isString(/mm$/):return this.getNumber()*this.getDpi()/25.4;case this.isString(/in$/):return this.getNumber()*this.getDpi();case this.isString(/%$/)&&r:return this.getNumber()*this.getEm();case this.isString(/%$/):return this.getNumber()*n.computeSize(A);default:var i=this.getNumber();return t&&i<1?i*n.computeSize(A):i}}getMilliseconds(){return this.hasValue()?this.isString(/ms$/)?this.getNumber():1e3*this.getNumber():0}getRadians(){if(!this.hasValue())return 0;switch(!0){case this.isString(/deg$/):return this.getNumber()*(Math.PI/180);case this.isString(/grad$/):return this.getNumber()*(Math.PI/200);case this.isString(/rad$/):return this.getNumber();default:return this.getNumber()*(Math.PI/180)}}getDefinition(){var e=this.getString(),t=/#([^)'"]+)/.exec(e);return t&&(t=t[1]),t||(t=e),this.document.definitions[t]}getFillStyleDefinition(e,t){var A=this.getDefinition();if(!A)return null;if("function"==typeof A.createGradient)return A.createGradient(this.document.ctx,e,t);if("function"==typeof A.createPattern){if(A.getHrefAttribute().hasValue()){var r=A.getAttribute("patternTransform");A=A.getHrefAttribute().getDefinition(),r.hasValue()&&A.getAttribute("patternTransform",!0).setValue(r.value)}return A.createPattern(this.document.ctx,e,t)}return null}getTextBaseline(){return this.hasValue()?wQ.textBaselineMapping[this.getString()]:null}addOpacity(e){for(var t=this.getColor(),A=t.length,r=0,n=0;n<A&&(","===t[n]&&r++,3!==r);n++);if(e.hasValue()&&this.isString()&&3!==r){var i=new Gx(t);i.ok&&(i.alpha=e.getNumber(),t=i.toRGBA())}return new wQ(this.document,this.name,t)}}wQ.textBaselineMapping={baseline:"alphabetic","before-edge":"top","text-before-edge":"top",middle:"middle",central:"middle","after-edge":"bottom","text-after-edge":"bottom",ideographic:"ideographic",alphabetic:"alphabetic",hanging:"hanging",mathematical:"alphabetic"};class bQ{constructor(){this.viewPorts=[]}clear(){this.viewPorts=[]}setCurrent(e,t){this.viewPorts.push({width:e,height:t})}removeCurrent(){this.viewPorts.pop()}getCurrent(){var{viewPorts:e}=this;return e[e.length-1]}get width(){return this.getCurrent().width}get height(){return this.getCurrent().height}computeSize(e){return"number"==typeof e?e:"x"===e?this.width:"y"===e?this.height:Math.sqrt(Math.pow(this.width,2)+Math.pow(this.height,2))/Math.sqrt(2)}}class BQ{constructor(e,t){this.x=e,this.y=t}static parse(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,[A=t,r=t]=WF(e);return new BQ(A,r)}static parseScale(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,[A=t,r=A]=WF(e);return new BQ(A,r)}static parsePath(e){for(var t=WF(e),A=t.length,r=[],n=0;n<A;n+=2)r.push(new BQ(t[n],t[n+1]));return r}angleTo(e){return Math.atan2(e.y-this.y,e.x-this.x)}applyTransform(e){var{x:t,y:A}=this,r=t*e[0]+A*e[2]+e[4],n=t*e[1]+A*e[3]+e[5];this.x=r,this.y=n}}class yQ{constructor(e){this.screen=e,this.working=!1,this.events=[],this.eventElements=[],this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this)}isWorking(){return this.working}start(){if(!this.working){var{screen:e,onClick:t,onMouseMove:A}=this,r=e.ctx.canvas;r.onclick=t,r.onmousemove=A,this.working=!0}}stop(){if(this.working){var e=this.screen.ctx.canvas;this.working=!1,e.onclick=null,e.onmousemove=null}}hasEvents(){return this.working&&this.events.length>0}runEvents(){if(this.working){var{screen:e,events:t,eventElements:A}=this,{style:r}=e.ctx.canvas;r&&(r.cursor=""),t.forEach((e,t)=>{for(var{run:r}=e,n=A[t];n;)r(n),n=n.parent}),this.events=[],this.eventElements=[]}}checkPath(e,t){if(this.working&&t){var{events:A,eventElements:r}=this;A.forEach((A,n)=>{var{x:i,y:s}=A;!r[n]&&t.isPointInPath&&t.isPointInPath(i,s)&&(r[n]=e)})}}checkBoundingBox(e,t){if(this.working&&t){var{events:A,eventElements:r}=this;A.forEach((A,n)=>{var{x:i,y:s}=A;!r[n]&&t.isPointInBox(i,s)&&(r[n]=e)})}}mapXY(e,t){for(var{window:A,ctx:r}=this.screen,n=new BQ(e,t),i=r.canvas;i;)n.x-=i.offsetLeft,n.y-=i.offsetTop,i=i.offsetParent;return A.scrollX&&(n.x+=A.scrollX),A.scrollY&&(n.y+=A.scrollY),n}onClick(e){var{x:t,y:A}=this.mapXY(e.clientX,e.clientY);this.events.push({type:"onclick",x:t,y:A,run(e){e.onClick&&e.onClick()}})}onMouseMove(e){var{x:t,y:A}=this.mapXY(e.clientX,e.clientY);this.events.push({type:"onmousemove",x:t,y:A,run(e){e.onMouseMove&&e.onMouseMove()}})}}var CQ="undefined"!=typeof window?window:null,xQ="undefined"!=typeof fetch?fetch.bind(void 0):null;class FQ{constructor(e){var{fetch:t=xQ,window:A=CQ}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.ctx=e,this.FRAMERATE=30,this.MAX_VIRTUAL_PIXELS=3e4,this.CLIENT_WIDTH=800,this.CLIENT_HEIGHT=600,this.viewPort=new bQ,this.mouse=new yQ(this),this.animations=[],this.waits=[],this.frameDuration=0,this.isReadyLock=!1,this.isFirstRender=!0,this.intervalId=null,this.window=A,this.fetch=t}wait(e){this.waits.push(e)}ready(){return this.readyPromise?this.readyPromise:Promise.resolve()}isReady(){if(this.isReadyLock)return!0;var e=this.waits.every(e=>e());return e&&(this.waits=[],this.resolveReady&&this.resolveReady()),this.isReadyLock=e,e}setDefaults(e){e.strokeStyle="rgba(0,0,0,0)",e.lineCap="butt",e.lineJoin="miter",e.miterLimit=4}setViewBox(e){var{document:t,ctx:A,aspectRatio:r,width:n,desiredWidth:i,height:s,desiredHeight:a,minX:o=0,minY:l=0,refX:c,refY:u,clip:h=!1,clipX:d=0,clipY:f=0}=e,p=GF(r).replace(/^defer\s/,""),[g,m]=p.split(" "),v=g||"xMidYMid",w=m||"meet",b=n/i,B=s/a,y=Math.min(b,B),C=Math.max(b,B),x=i,F=a;"meet"===w&&(x*=y,F*=y),"slice"===w&&(x*=C,F*=C);var Q=new wQ(t,"refX",c),U=new wQ(t,"refY",u),E=Q.hasValue()&&U.hasValue();if(E&&A.translate(-y*Q.getPixels("x"),-y*U.getPixels("y")),h){var S=y*d,N=y*f;A.beginPath(),A.moveTo(S,N),A.lineTo(n,N),A.lineTo(n,s),A.lineTo(S,s),A.closePath(),A.clip()}if(!E){var L="meet"===w&&y===B,I="slice"===w&&C===B,_="meet"===w&&y===b,k="slice"===w&&C===b;v.startsWith("xMid")&&(L||I)&&A.translate(n/2-x/2,0),v.endsWith("YMid")&&(_||k)&&A.translate(0,s/2-F/2),v.startsWith("xMax")&&(L||I)&&A.translate(n-x,0),v.endsWith("YMax")&&(_||k)&&A.translate(0,s-F)}switch(!0){case"none"===v:A.scale(b,B);break;case"meet"===w:A.scale(y,y);break;case"slice"===w:A.scale(C,C)}A.translate(-o,-l)}start(e){var{enableRedraw:t=!1,ignoreMouse:A=!1,ignoreAnimation:r=!1,ignoreDimensions:n=!1,ignoreClear:i=!1,forceRedraw:s,scaleWidth:a,scaleHeight:o,offsetX:l,offsetY:c}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{FRAMERATE:u,mouse:h}=this,d=1e3/u;if(this.frameDuration=d,this.readyPromise=new Promise(e=>{this.resolveReady=e}),this.isReady()&&this.render(e,n,i,a,o,l,c),t){var f=Date.now(),p=f,g=0,m=()=>{f=Date.now(),(g=f-p)>=d&&(p=f-g%d,this.shouldUpdate(r,s)&&(this.render(e,n,i,a,o,l,c),h.runEvents())),this.intervalId=Nx(m)};A||h.start(),this.intervalId=Nx(m)}}stop(){this.intervalId&&(Nx.cancel(this.intervalId),this.intervalId=null),this.mouse.stop()}shouldUpdate(e,t){if(!e){var{frameDuration:A}=this;if(this.animations.reduce((e,t)=>t.update(A)||e,!1))return!0}return!("function"!=typeof t||!t())||(!(this.isReadyLock||!this.isReady())||!!this.mouse.hasEvents())}render(e,t,A,r,n,i,s){var{CLIENT_WIDTH:a,CLIENT_HEIGHT:o,viewPort:l,ctx:c,isFirstRender:u}=this,h=c.canvas;l.clear(),h.width&&h.height?l.setCurrent(h.width,h.height):l.setCurrent(a,o);var d=e.getStyle("width"),f=e.getStyle("height");!t&&(u||"number"!=typeof r&&"number"!=typeof n)&&(d.hasValue()&&(h.width=d.getPixels("x"),h.style&&(h.style.width="".concat(h.width,"px"))),f.hasValue()&&(h.height=f.getPixels("y"),h.style&&(h.style.height="".concat(h.height,"px"))));var p=h.clientWidth||h.width,g=h.clientHeight||h.height;if(t&&d.hasValue()&&f.hasValue()&&(p=d.getPixels("x"),g=f.getPixels("y")),l.setCurrent(p,g),"number"==typeof i&&e.getAttribute("x",!0).setValue(i),"number"==typeof s&&e.getAttribute("y",!0).setValue(s),"number"==typeof r||"number"==typeof n){var m=WF(e.getAttribute("viewBox").getString()),v=0,w=0;if("number"==typeof r){var b=e.getStyle("width");b.hasValue()?v=b.getPixels("x")/r:isNaN(m[2])||(v=m[2]/r)}if("number"==typeof n){var B=e.getStyle("height");B.hasValue()?w=B.getPixels("y")/n:isNaN(m[3])||(w=m[3]/n)}v||(v=w),w||(w=v),e.getAttribute("width",!0).setValue(r),e.getAttribute("height",!0).setValue(n);var y=e.getStyle("transform",!0,!0);y.setValue("".concat(y.getString()," scale(").concat(1/v,", ").concat(1/w,")"))}A||c.clearRect(0,0,p,g),e.render(c),u&&(this.isFirstRender=!1)}}FQ.defaultWindow=CQ,FQ.defaultFetch=xQ;var{defaultFetch:QQ}=FQ,UQ="undefined"!=typeof DOMParser?DOMParser:null;class EQ{constructor(){var{fetch:e=QQ,DOMParser:t=UQ}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.fetch=e,this.DOMParser=t}parse(e){var t=this;return Jv(function*(){return e.startsWith("<")?t.parseFromString(e):t.load(e)})()}parseFromString(e){var t=new this.DOMParser;try{return this.checkDocument(t.parseFromString(e,"image/svg+xml"))}catch(A){return this.checkDocument(t.parseFromString(e,"text/xml"))}}checkDocument(e){var t=e.getElementsByTagName("parsererror")[0];if(t)throw new Error(t.textContent);return e}load(e){var t=this;return Jv(function*(){var A=yield t.fetch(e),r=yield A.text();return t.parseFromString(r)})()}}class SQ{constructor(e,t){this.type="translate",this.point=null,this.point=BQ.parse(t)}apply(e){var{x:t,y:A}=this.point;e.translate(t||0,A||0)}unapply(e){var{x:t,y:A}=this.point;e.translate(-1*t||0,-1*A||0)}applyToPoint(e){var{x:t,y:A}=this.point;e.applyTransform([1,0,0,1,t||0,A||0])}}class NQ{constructor(e,t,A){this.type="rotate",this.angle=null,this.originX=null,this.originY=null,this.cx=0,this.cy=0;var r=WF(t);this.angle=new wQ(e,"angle",r[0]),this.originX=A[0],this.originY=A[1],this.cx=r[1]||0,this.cy=r[2]||0}apply(e){var{cx:t,cy:A,originX:r,originY:n,angle:i}=this,s=t+r.getPixels("x"),a=A+n.getPixels("y");e.translate(s,a),e.rotate(i.getRadians()),e.translate(-s,-a)}unapply(e){var{cx:t,cy:A,originX:r,originY:n,angle:i}=this,s=t+r.getPixels("x"),a=A+n.getPixels("y");e.translate(s,a),e.rotate(-1*i.getRadians()),e.translate(-s,-a)}applyToPoint(e){var{cx:t,cy:A,angle:r}=this,n=r.getRadians();e.applyTransform([1,0,0,1,t||0,A||0]),e.applyTransform([Math.cos(n),Math.sin(n),-Math.sin(n),Math.cos(n),0,0]),e.applyTransform([1,0,0,1,-t||0,-A||0])}}class LQ{constructor(e,t,A){this.type="scale",this.scale=null,this.originX=null,this.originY=null;var r=BQ.parseScale(t);0!==r.x&&0!==r.y||(r.x=oQ,r.y=oQ),this.scale=r,this.originX=A[0],this.originY=A[1]}apply(e){var{scale:{x:t,y:A},originX:r,originY:n}=this,i=r.getPixels("x"),s=n.getPixels("y");e.translate(i,s),e.scale(t,A||t),e.translate(-i,-s)}unapply(e){var{scale:{x:t,y:A},originX:r,originY:n}=this,i=r.getPixels("x"),s=n.getPixels("y");e.translate(i,s),e.scale(1/t,1/A||t),e.translate(-i,-s)}applyToPoint(e){var{x:t,y:A}=this.scale;e.applyTransform([t||0,0,0,A||0,0,0])}}class IQ{constructor(e,t,A){this.type="matrix",this.matrix=[],this.originX=null,this.originY=null,this.matrix=WF(t),this.originX=A[0],this.originY=A[1]}apply(e){var{originX:t,originY:A,matrix:r}=this,n=t.getPixels("x"),i=A.getPixels("y");e.translate(n,i),e.transform(r[0],r[1],r[2],r[3],r[4],r[5]),e.translate(-n,-i)}unapply(e){var{originX:t,originY:A,matrix:r}=this,n=r[0],i=r[2],s=r[4],a=r[1],o=r[3],l=r[5],c=1/(n*(1*o-0*l)-i*(1*a-0*l)+s*(0*a-0*o)),u=t.getPixels("x"),h=A.getPixels("y");e.translate(u,h),e.transform(c*(1*o-0*l),c*(0*l-1*a),c*(0*s-1*i),c*(1*n-0*s),c*(i*l-s*o),c*(s*a-n*l)),e.translate(-u,-h)}applyToPoint(e){e.applyTransform(this.matrix)}}class _Q extends IQ{constructor(e,t,A){super(e,t,A),this.type="skew",this.angle=null,this.angle=new wQ(e,"angle",t)}}class kQ extends _Q{constructor(e,t,A){super(e,t,A),this.type="skewX",this.matrix=[1,0,Math.tan(this.angle.getRadians()),1,0,0]}}class OQ extends _Q{constructor(e,t,A){super(e,t,A),this.type="skewY",this.matrix=[1,Math.tan(this.angle.getRadians()),0,1,0,0]}}class TQ{constructor(e,t,A){this.document=e,this.transforms=[];var r=function(e){return GF(e).trim().replace(/\)([a-zA-Z])/g,") $1").replace(/\)(\s?,\s?)/g,") ").split(/\s(?=[a-z])/)}(t);r.forEach(e=>{if("none"!==e){var[t,r]=function(e){var[t,A]=e.split("(");return[t.trim(),A.trim().replace(")","")]}(e),n=TQ.transformTypes[t];void 0!==n&&this.transforms.push(new n(this.document,r,A))}})}static fromElement(e,t){var A=t.getStyle("transform",!1,!0),[r,n=r]=t.getStyle("transform-origin",!1,!0).split(),i=[r,n];return A.hasValue()?new TQ(e,A.getString(),i):null}apply(e){for(var{transforms:t}=this,A=t.length,r=0;r<A;r++)t[r].apply(e)}unapply(e){for(var{transforms:t}=this,A=t.length-1;A>=0;A--)t[A].unapply(e)}applyToPoint(e){for(var{transforms:t}=this,A=t.length,r=0;r<A;r++)t[r].applyToPoint(e)}}TQ.transformTypes={translate:SQ,rotate:NQ,scale:LQ,matrix:IQ,skewX:kQ,skewY:OQ};class jQ{constructor(e,t){var A=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(this.document=e,this.node=t,this.captureTextNodes=A,this.attributes=Object.create(null),this.styles=Object.create(null),this.stylesSpecificity=Object.create(null),this.animationFrozen=!1,this.animationFrozenValue="",this.parent=null,this.children=[],t&&1===t.nodeType){if(Array.from(t.attributes).forEach(t=>{var A=YF(t.nodeName);this.attributes[A]=new wQ(e,A,t.value)}),this.addStylesFromStyleDefinition(),this.getAttribute("style").hasValue()){var r=this.getAttribute("style").getString().split(";").map(e=>e.trim());r.forEach(t=>{if(t){var[A,r]=t.split(":").map(e=>e.trim());this.styles[A]=new wQ(e,A,r)}})}var{definitions:n}=e,i=this.getAttribute("id");i.hasValue()&&(n[i.getString()]||(n[i.getString()]=this)),Array.from(t.childNodes).forEach(t=>{if(1===t.nodeType)this.addChild(t);else if(A&&(3===t.nodeType||4===t.nodeType)){var r=e.createTextNode(t);r.getText().length>0&&this.addChild(r)}})}}getAttribute(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],A=this.attributes[e];if(!A&&t){var r=new wQ(this.document,e,"");return this.attributes[e]=r,r}return A||wQ.empty(this.document)}getHrefAttribute(){for(var e in this.attributes)if("href"===e||e.endsWith(":href"))return this.attributes[e];return wQ.empty(this.document)}getStyle(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],A=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this.styles[e];if(r)return r;var n=this.getAttribute(e);if(null!=n&&n.hasValue())return this.styles[e]=n,n;if(!A){var{parent:i}=this;if(i){var s=i.getStyle(e);if(null!=s&&s.hasValue())return s}}if(t){var a=new wQ(this.document,e,"");return this.styles[e]=a,a}return r||wQ.empty(this.document)}render(e){if("none"!==this.getStyle("display").getString()&&"hidden"!==this.getStyle("visibility").getString()){if(e.save(),this.getStyle("mask").hasValue()){var t=this.getStyle("mask").getDefinition();t&&(this.applyEffects(e),t.apply(e,this))}else if("none"!==this.getStyle("filter").getValue("none")){var A=this.getStyle("filter").getDefinition();A&&(this.applyEffects(e),A.apply(e,this))}else this.setContext(e),this.renderChildren(e),this.clearContext(e);e.restore()}}setContext(e){}applyEffects(e){var t=TQ.fromElement(this.document,this);t&&t.apply(e);var A=this.getStyle("clip-path",!1,!0);if(A.hasValue()){var r=A.getDefinition();r&&r.apply(e)}}clearContext(e){}renderChildren(e){this.children.forEach(t=>{t.render(e)})}addChild(e){var t=e instanceof jQ?e:this.document.createElement(e);t.parent=this,jQ.ignoreChildTypes.includes(t.type)||this.children.push(t)}matchesSelector(e){var t,{node:A}=this;if("function"==typeof A.matches)return A.matches(e);var r=null===(t=A.getAttribute)||void 0===t?void 0:t.call(A,"class");return!(!r||""===r)&&r.split(" ").some(t=>".".concat(t)===e)}addStylesFromStyleDefinition(){var{styles:e,stylesSpecificity:t}=this.document;for(var A in e)if(!A.startsWith("@")&&this.matchesSelector(A)){var r=e[A],n=t[A];if(r)for(var i in r){var s=this.stylesSpecificity[i];void 0===s&&(s="000"),n>=s&&(this.styles[i]=r[i],this.stylesSpecificity[i]=n)}}}removeStyles(e,t){return t.reduce((t,A)=>{var r=e.getStyle(A);if(!r.hasValue())return t;var n=r.getString();return r.setValue(""),[...t,[A,n]]},[])}restoreStyles(e,t){t.forEach(t=>{var[A,r]=t;e.getStyle(A,!0).setValue(r)})}isFirstChild(){var e;return 0===(null===(e=this.parent)||void 0===e?void 0:e.children.indexOf(this))}}jQ.ignoreChildTypes=["title"];class HQ extends jQ{constructor(e,t,A){super(e,t,A)}}function PQ(e){var t=e.trim();return/^('|")/.test(t)?t:'"'.concat(t,'"')}function DQ(e){if(!e)return"";var t=e.trim().toLowerCase();switch(t){case"normal":case"italic":case"oblique":case"inherit":case"initial":case"unset":return t;default:return/^oblique\s+(-|)\d+deg$/.test(t)?t:""}}function MQ(e){if(!e)return"";var t=e.trim().toLowerCase();switch(t){case"normal":case"bold":case"lighter":case"bolder":case"inherit":case"initial":case"unset":return t;default:return/^[\d.]+$/.test(t)?t:""}}class RQ{constructor(e,t,A,r,n,i){var s=i?"string"==typeof i?RQ.parse(i):i:{};this.fontFamily=n||s.fontFamily,this.fontSize=r||s.fontSize,this.fontStyle=e||s.fontStyle,this.fontWeight=A||s.fontWeight,this.fontVariant=t||s.fontVariant}static parse(){var e=arguments.length>1?arguments[1]:void 0,t="",A="",r="",n="",i="",s=GF(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().split(" "),a={fontSize:!1,fontStyle:!1,fontWeight:!1,fontVariant:!1};return s.forEach(e=>{switch(!0){case!a.fontStyle&&RQ.styles.includes(e):"inherit"!==e&&(t=e),a.fontStyle=!0;break;case!a.fontVariant&&RQ.variants.includes(e):"inherit"!==e&&(A=e),a.fontStyle=!0,a.fontVariant=!0;break;case!a.fontWeight&&RQ.weights.includes(e):"inherit"!==e&&(r=e),a.fontStyle=!0,a.fontVariant=!0,a.fontWeight=!0;break;case!a.fontSize:"inherit"!==e&&([n]=e.split("/")),a.fontStyle=!0,a.fontVariant=!0,a.fontWeight=!0,a.fontSize=!0;break;default:"inherit"!==e&&(i+=e)}}),new RQ(t,A,r,n,i,e)}toString(){return[DQ(this.fontStyle),this.fontVariant,MQ(this.fontWeight),this.fontSize,(e=this.fontFamily,"undefined"==typeof process?e:e.trim().split(",").map(PQ).join(","))].join(" ").trim();var e}}RQ.styles="normal|italic|oblique|inherit",RQ.variants="normal|small-caps|inherit",RQ.weights="normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit";class VQ{constructor(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Number.NaN,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Number.NaN,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Number.NaN,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Number.NaN;this.x1=e,this.y1=t,this.x2=A,this.y2=r,this.addPoint(e,t),this.addPoint(A,r)}get x(){return this.x1}get y(){return this.y1}get width(){return this.x2-this.x1}get height(){return this.y2-this.y1}addPoint(e,t){void 0!==e&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=e,this.x2=e),e<this.x1&&(this.x1=e),e>this.x2&&(this.x2=e)),void 0!==t&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),t<this.y1&&(this.y1=t),t>this.y2&&(this.y2=t))}addX(e){this.addPoint(e,null)}addY(e){this.addPoint(null,e)}addBoundingBox(e){if(e){var{x1:t,y1:A,x2:r,y2:n}=e;this.addPoint(t,A),this.addPoint(r,n)}}sumCubic(e,t,A,r,n){return Math.pow(1-e,3)*t+3*Math.pow(1-e,2)*e*A+3*(1-e)*Math.pow(e,2)*r+Math.pow(e,3)*n}bezierCurveAdd(e,t,A,r,n){var i=6*t-12*A+6*r,s=-3*t+9*A-9*r+3*n,a=3*A-3*t;if(0!==s){var o=Math.pow(i,2)-4*a*s;if(!(o<0)){var l=(-i+Math.sqrt(o))/(2*s);0<l&&l<1&&(e?this.addX(this.sumCubic(l,t,A,r,n)):this.addY(this.sumCubic(l,t,A,r,n)));var c=(-i-Math.sqrt(o))/(2*s);0<c&&c<1&&(e?this.addX(this.sumCubic(c,t,A,r,n)):this.addY(this.sumCubic(c,t,A,r,n)))}}else{if(0===i)return;var u=-a/i;0<u&&u<1&&(e?this.addX(this.sumCubic(u,t,A,r,n)):this.addY(this.sumCubic(u,t,A,r,n)))}}addBezierCurve(e,t,A,r,n,i,s,a){this.addPoint(e,t),this.addPoint(s,a),this.bezierCurveAdd(!0,e,A,n,s),this.bezierCurveAdd(!1,t,r,i,a)}addQuadraticCurve(e,t,A,r,n,i){var s=e+2/3*(A-e),a=t+2/3*(r-t),o=s+1/3*(n-e),l=a+1/3*(i-t);this.addBezierCurve(e,t,s,o,a,l,n,i)}isPointInBox(e,t){var{x1:A,y1:r,x2:n,y2:i}=this;return A<=e&&e<=n&&r<=t&&t<=i}}class KQ extends QF{constructor(e){super(e.replace(/([+\-.])\s+/gm,"$1").replace(/[^MmZzLlHhVvCcSsQqTtAae\d\s.,+-].*/g,"")),this.control=null,this.start=null,this.current=null,this.command=null,this.commands=this.commands,this.i=-1,this.previousCommand=null,this.points=[],this.angles=[]}reset(){this.i=-1,this.command=null,this.previousCommand=null,this.start=new BQ(0,0),this.control=new BQ(0,0),this.current=new BQ(0,0),this.points=[],this.angles=[]}isEnd(){var{i:e,commands:t}=this;return e>=t.length-1}next(){var e=this.commands[++this.i];return this.previousCommand=this.command,this.command=e,e}getPoint(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"x",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"y",A=new BQ(this.command[e],this.command[t]);return this.makeAbsolute(A)}getAsControlPoint(e,t){var A=this.getPoint(e,t);return this.control=A,A}getAsCurrentPoint(e,t){var A=this.getPoint(e,t);return this.current=A,A}getReflectedControlPoint(){var e=this.previousCommand.type;if(e!==QF.CURVE_TO&&e!==QF.SMOOTH_CURVE_TO&&e!==QF.QUAD_TO&&e!==QF.SMOOTH_QUAD_TO)return this.current;var{current:{x:t,y:A},control:{x:r,y:n}}=this;return new BQ(2*t-r,2*A-n)}makeAbsolute(e){if(this.command.relative){var{x:t,y:A}=this.current;e.x+=t,e.y+=A}return e}addMarker(e,t,A){var{points:r,angles:n}=this;A&&n.length>0&&!n[n.length-1]&&(n[n.length-1]=r[r.length-1].angleTo(A)),this.addMarkerAngle(e,t?t.angleTo(e):null)}addMarkerAngle(e,t){this.points.push(e),this.angles.push(t)}getMarkerPoints(){return this.points}getMarkerAngles(){for(var{angles:e}=this,t=e.length,A=0;A<t;A++)if(!e[A])for(var r=A+1;r<t;r++)if(e[r]){e[A]=e[r];break}return e}}class GQ extends jQ{constructor(){super(...arguments),this.modifiedEmSizeStack=!1}calculateOpacity(){for(var e=1,t=this;t;){var A=t.getStyle("opacity",!1,!0);A.hasValue(!0)&&(e*=A.getNumber()),t=t.parent}return e}setContext(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!t){var A=this.getStyle("fill"),r=this.getStyle("fill-opacity"),n=this.getStyle("stroke"),i=this.getStyle("stroke-opacity");if(A.isUrlDefinition()){var s=A.getFillStyleDefinition(this,r);s&&(e.fillStyle=s)}else if(A.hasValue()){"currentColor"===A.getString()&&A.setValue(this.getStyle("color").getColor());var a=A.getColor();"inherit"!==a&&(e.fillStyle="none"===a?"rgba(0,0,0,0)":a)}if(r.hasValue()){var o=new wQ(this.document,"fill",e.fillStyle).addOpacity(r).getColor();e.fillStyle=o}if(n.isUrlDefinition()){var l=n.getFillStyleDefinition(this,i);l&&(e.strokeStyle=l)}else if(n.hasValue()){"currentColor"===n.getString()&&n.setValue(this.getStyle("color").getColor());var c=n.getString();"inherit"!==c&&(e.strokeStyle="none"===c?"rgba(0,0,0,0)":c)}if(i.hasValue()){var u=new wQ(this.document,"stroke",e.strokeStyle).addOpacity(i).getString();e.strokeStyle=u}var h=this.getStyle("stroke-width");if(h.hasValue()){var d=h.getPixels();e.lineWidth=d||oQ}var f=this.getStyle("stroke-linecap"),p=this.getStyle("stroke-linejoin"),g=this.getStyle("stroke-miterlimit"),m=this.getStyle("stroke-dasharray"),v=this.getStyle("stroke-dashoffset");if(f.hasValue()&&(e.lineCap=f.getString()),p.hasValue()&&(e.lineJoin=p.getString()),g.hasValue()&&(e.miterLimit=g.getNumber()),m.hasValue()&&"none"!==m.getString()){var w=WF(m.getString());void 0!==e.setLineDash?e.setLineDash(w):void 0!==e.webkitLineDash?e.webkitLineDash=w:void 0===e.mozDash||1===w.length&&0===w[0]||(e.mozDash=w);var b=v.getPixels();void 0!==e.lineDashOffset?e.lineDashOffset=b:void 0!==e.webkitLineDashOffset?e.webkitLineDashOffset=b:void 0!==e.mozDashOffset&&(e.mozDashOffset=b)}}if(this.modifiedEmSizeStack=!1,void 0!==e.font){var B=this.getStyle("font"),y=this.getStyle("font-style"),C=this.getStyle("font-variant"),x=this.getStyle("font-weight"),F=this.getStyle("font-size"),Q=this.getStyle("font-family"),U=new RQ(y.getString(),C.getString(),x.getString(),F.hasValue()?"".concat(F.getPixels(!0),"px"):"",Q.getString(),RQ.parse(B.getString(),e.font));y.setValue(U.fontStyle),C.setValue(U.fontVariant),x.setValue(U.fontWeight),F.setValue(U.fontSize),Q.setValue(U.fontFamily),e.font=U.toString(),F.isPixels()&&(this.document.emSize=F.getPixels(),this.modifiedEmSizeStack=!0)}t||(this.applyEffects(e),e.globalAlpha=this.calculateOpacity())}clearContext(e){super.clearContext(e),this.modifiedEmSizeStack&&this.document.popEmSize()}}class zQ extends GQ{constructor(e,t,A){super(e,t,A),this.type="path",this.pathParser=null,this.pathParser=new KQ(this.getAttribute("d").getString())}path(e){var{pathParser:t}=this,A=new VQ;for(t.reset(),e&&e.beginPath();!t.isEnd();)switch(t.next().type){case KQ.MOVE_TO:this.pathM(e,A);break;case KQ.LINE_TO:this.pathL(e,A);break;case KQ.HORIZ_LINE_TO:this.pathH(e,A);break;case KQ.VERT_LINE_TO:this.pathV(e,A);break;case KQ.CURVE_TO:this.pathC(e,A);break;case KQ.SMOOTH_CURVE_TO:this.pathS(e,A);break;case KQ.QUAD_TO:this.pathQ(e,A);break;case KQ.SMOOTH_QUAD_TO:this.pathT(e,A);break;case KQ.ARC:this.pathA(e,A);break;case KQ.CLOSE_PATH:this.pathZ(e,A)}return A}getBoundingBox(e){return this.path()}getMarkers(){var{pathParser:e}=this,t=e.getMarkerPoints(),A=e.getMarkerAngles(),r=t.map((e,t)=>[e,A[t]]);return r}renderChildren(e){this.path(e),this.document.screen.mouse.checkPath(this,e);var t=this.getStyle("fill-rule");""!==e.fillStyle&&("inherit"!==t.getString("inherit")?e.fill(t.getString()):e.fill()),""!==e.strokeStyle&&("non-scaling-stroke"===this.getAttribute("vector-effect").getString()?(e.save(),e.setTransform(1,0,0,1,0,0),e.stroke(),e.restore()):e.stroke());var A=this.getMarkers();if(A){var r=A.length-1,n=this.getStyle("marker-start"),i=this.getStyle("marker-mid"),s=this.getStyle("marker-end");if(n.isUrlDefinition()){var a=n.getDefinition(),[o,l]=A[0];a.render(e,o,l)}if(i.isUrlDefinition())for(var c=i.getDefinition(),u=1;u<r;u++){var[h,d]=A[u];c.render(e,h,d)}if(s.isUrlDefinition()){var f=s.getDefinition(),[p,g]=A[r];f.render(e,p,g)}}}static pathM(e){var t=e.getAsCurrentPoint();return e.start=e.current,{point:t}}pathM(e,t){var{pathParser:A}=this,{point:r}=zQ.pathM(A),{x:n,y:i}=r;A.addMarker(r),t.addPoint(n,i),e&&e.moveTo(n,i)}static pathL(e){var{current:t}=e;return{current:t,point:e.getAsCurrentPoint()}}pathL(e,t){var{pathParser:A}=this,{current:r,point:n}=zQ.pathL(A),{x:i,y:s}=n;A.addMarker(n,r),t.addPoint(i,s),e&&e.lineTo(i,s)}static pathH(e){var{current:t,command:A}=e,r=new BQ((A.relative?t.x:0)+A.x,t.y);return e.current=r,{current:t,point:r}}pathH(e,t){var{pathParser:A}=this,{current:r,point:n}=zQ.pathH(A),{x:i,y:s}=n;A.addMarker(n,r),t.addPoint(i,s),e&&e.lineTo(i,s)}static pathV(e){var{current:t,command:A}=e,r=new BQ(t.x,(A.relative?t.y:0)+A.y);return e.current=r,{current:t,point:r}}pathV(e,t){var{pathParser:A}=this,{current:r,point:n}=zQ.pathV(A),{x:i,y:s}=n;A.addMarker(n,r),t.addPoint(i,s),e&&e.lineTo(i,s)}static pathC(e){var{current:t}=e;return{current:t,point:e.getPoint("x1","y1"),controlPoint:e.getAsControlPoint("x2","y2"),currentPoint:e.getAsCurrentPoint()}}pathC(e,t){var{pathParser:A}=this,{current:r,point:n,controlPoint:i,currentPoint:s}=zQ.pathC(A);A.addMarker(s,i,n),t.addBezierCurve(r.x,r.y,n.x,n.y,i.x,i.y,s.x,s.y),e&&e.bezierCurveTo(n.x,n.y,i.x,i.y,s.x,s.y)}static pathS(e){var{current:t}=e;return{current:t,point:e.getReflectedControlPoint(),controlPoint:e.getAsControlPoint("x2","y2"),currentPoint:e.getAsCurrentPoint()}}pathS(e,t){var{pathParser:A}=this,{current:r,point:n,controlPoint:i,currentPoint:s}=zQ.pathS(A);A.addMarker(s,i,n),t.addBezierCurve(r.x,r.y,n.x,n.y,i.x,i.y,s.x,s.y),e&&e.bezierCurveTo(n.x,n.y,i.x,i.y,s.x,s.y)}static pathQ(e){var{current:t}=e;return{current:t,controlPoint:e.getAsControlPoint("x1","y1"),currentPoint:e.getAsCurrentPoint()}}pathQ(e,t){var{pathParser:A}=this,{current:r,controlPoint:n,currentPoint:i}=zQ.pathQ(A);A.addMarker(i,n,n),t.addQuadraticCurve(r.x,r.y,n.x,n.y,i.x,i.y),e&&e.quadraticCurveTo(n.x,n.y,i.x,i.y)}static pathT(e){var{current:t}=e,A=e.getReflectedControlPoint();return e.control=A,{current:t,controlPoint:A,currentPoint:e.getAsCurrentPoint()}}pathT(e,t){var{pathParser:A}=this,{current:r,controlPoint:n,currentPoint:i}=zQ.pathT(A);A.addMarker(i,n,n),t.addQuadraticCurve(r.x,r.y,n.x,n.y,i.x,i.y),e&&e.quadraticCurveTo(n.x,n.y,i.x,i.y)}static pathA(e){var{current:t,command:A}=e,{rX:r,rY:n,xRot:i,lArcFlag:s,sweepFlag:a}=A,o=i*(Math.PI/180),l=e.getAsCurrentPoint(),c=new BQ(Math.cos(o)*(t.x-l.x)/2+Math.sin(o)*(t.y-l.y)/2,-Math.sin(o)*(t.x-l.x)/2+Math.cos(o)*(t.y-l.y)/2),u=Math.pow(c.x,2)/Math.pow(r,2)+Math.pow(c.y,2)/Math.pow(n,2);u>1&&(r*=Math.sqrt(u),n*=Math.sqrt(u));var h=(s===a?-1:1)*Math.sqrt((Math.pow(r,2)*Math.pow(n,2)-Math.pow(r,2)*Math.pow(c.y,2)-Math.pow(n,2)*Math.pow(c.x,2))/(Math.pow(r,2)*Math.pow(c.y,2)+Math.pow(n,2)*Math.pow(c.x,2)));isNaN(h)&&(h=0);var d=new BQ(h*r*c.y/n,h*-n*c.x/r),f=new BQ((t.x+l.x)/2+Math.cos(o)*d.x-Math.sin(o)*d.y,(t.y+l.y)/2+Math.sin(o)*d.x+Math.cos(o)*d.y),p=uQ([1,0],[(c.x-d.x)/r,(c.y-d.y)/n]),g=[(c.x-d.x)/r,(c.y-d.y)/n],m=[(-c.x-d.x)/r,(-c.y-d.y)/n],v=uQ(g,m);return cQ(g,m)<=-1&&(v=Math.PI),cQ(g,m)>=1&&(v=0),{currentPoint:l,rX:r,rY:n,sweepFlag:a,xAxisRotation:o,centp:f,a1:p,ad:v}}pathA(e,t){var{pathParser:A}=this,{currentPoint:r,rX:n,rY:i,sweepFlag:s,xAxisRotation:a,centp:o,a1:l,ad:c}=zQ.pathA(A),u=1-s?1:-1,h=l+u*(c/2),d=new BQ(o.x+n*Math.cos(h),o.y+i*Math.sin(h));if(A.addMarkerAngle(d,h-u*Math.PI/2),A.addMarkerAngle(r,h-u*Math.PI),t.addPoint(r.x,r.y),e&&!isNaN(l)&&!isNaN(c)){var f=n>i?n:i,p=n>i?1:n/i,g=n>i?i/n:1;e.translate(o.x,o.y),e.rotate(a),e.scale(p,g),e.arc(0,0,f,l,l+c,Boolean(1-s)),e.scale(1/p,1/g),e.rotate(-a),e.translate(-o.x,-o.y)}}static pathZ(e){e.current=e.start}pathZ(e,t){zQ.pathZ(this.pathParser),e&&t.x1!==t.x2&&t.y1!==t.y2&&e.closePath()}}class qQ extends zQ{constructor(e,t,A){super(e,t,A),this.type="glyph",this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber(),this.unicode=this.getAttribute("unicode").getString(),this.arabicForm=this.getAttribute("arabic-form").getString()}}class WQ extends GQ{constructor(e,t,A){super(e,t,new.target===WQ||A),this.type="text",this.x=0,this.y=0,this.measureCache=-1}setContext(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];super.setContext(e,t);var A=this.getStyle("dominant-baseline").getTextBaseline()||this.getStyle("alignment-baseline").getTextBaseline();A&&(e.textBaseline=A)}initializeCoordinates(){this.x=0,this.y=0,this.leafTexts=[],this.textChunkStart=0,this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY}getBoundingBox(e){if("text"!==this.type)return this.getTElementBoundingBox(e);this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(e);var t=null;return this.children.forEach((A,r)=>{var n=this.getChildBoundingBox(e,this,this,r);t?t.addBoundingBox(n):t=n}),t}getFontSize(){var{document:e,parent:t}=this,A=RQ.parse(e.ctx.font).fontSize;return t.getStyle("font-size").getNumber(A)}getTElementBoundingBox(e){var t=this.getFontSize();return new VQ(this.x,this.y-t,this.x+this.measureText(e),this.y)}getGlyph(e,t,A){var r=t[A],n=null;if(e.isArabic){var i=t.length,s=t[A-1],a=t[A+1],o="isolated";if((0===A||" "===s)&&A<i-1&&" "!==a&&(o="terminal"),A>0&&" "!==s&&A<i-1&&" "!==a&&(o="medial"),A>0&&" "!==s&&(A===i-1||" "===a)&&(o="initial"),void 0!==e.glyphs[r]){var l=e.glyphs[r];n=l instanceof qQ?l:l[o]}}else n=e.glyphs[r];return n||(n=e.missingGlyph),n}getText(){return""}getTextFromNode(e){var t=e||this.node,A=Array.from(t.parentNode.childNodes),r=A.indexOf(t),n=A.length-1,i=GF(t.textContent||"");return 0===r&&(i=zF(i)),r===n&&(i=qF(i)),i}renderChildren(e){if("text"===this.type){this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(e),this.children.forEach((t,A)=>{this.renderChild(e,this,this,A)});var{mouse:t}=this.document.screen;t.isWorking()&&t.checkBoundingBox(this,this.getBoundingBox(e))}else this.renderTElementChildren(e)}renderTElementChildren(e){var{document:t,parent:A}=this,r=this.getText(),n=A.getStyle("font-family").getDefinition();if(n)for(var{unitsPerEm:i}=n.fontFace,s=RQ.parse(t.ctx.font),a=A.getStyle("font-size").getNumber(s.fontSize),o=A.getStyle("font-style").getString(s.fontStyle),l=a/i,c=n.isRTL?r.split("").reverse().join(""):r,u=WF(A.getAttribute("dx").getString()),h=c.length,d=0;d<h;d++){var f=this.getGlyph(n,c,d);e.translate(this.x,this.y),e.scale(l,-l);var p=e.lineWidth;e.lineWidth=e.lineWidth*i/a,"italic"===o&&e.transform(1,0,.4,1,0,0),f.render(e),"italic"===o&&e.transform(1,0,-.4,1,0,0),e.lineWidth=p,e.scale(1/l,-1/l),e.translate(-this.x,-this.y),this.x+=a*(f.horizAdvX||n.horizAdvX)/i,void 0===u[d]||isNaN(u[d])||(this.x+=u[d])}else{var{x:g,y:m}=this;e.fillStyle&&e.fillText(r,g,m),e.strokeStyle&&e.strokeText(r,g,m)}}applyAnchoring(){if(!(this.textChunkStart>=this.leafTexts.length)){var e=this.leafTexts[this.textChunkStart],t=e.getStyle("text-anchor").getString("start"),A=0;A="start"===t?e.x-this.minX:"end"===t?e.x-this.maxX:e.x-(this.minX+this.maxX)/2;for(var r=this.textChunkStart;r<this.leafTexts.length;r++)this.leafTexts[r].x+=A;this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY,this.textChunkStart=this.leafTexts.length}}adjustChildCoordinatesRecursive(e){this.children.forEach((t,A)=>{this.adjustChildCoordinatesRecursiveCore(e,this,this,A)}),this.applyAnchoring()}adjustChildCoordinatesRecursiveCore(e,t,A,r){var n=A.children[r];n.children.length>0?n.children.forEach((A,r)=>{t.adjustChildCoordinatesRecursiveCore(e,t,n,r)}):this.adjustChildCoordinates(e,t,A,r)}adjustChildCoordinates(e,t,A,r){var n=A.children[r];if("function"!=typeof n.measureText)return n;e.save(),n.setContext(e,!0);var i=n.getAttribute("x"),s=n.getAttribute("y"),a=n.getAttribute("dx"),o=n.getAttribute("dy"),l=n.getStyle("font-family").getDefinition(),c=Boolean(l)&&l.isRTL;0===r&&(i.hasValue()||i.setValue(n.getInheritedAttribute("x")),s.hasValue()||s.setValue(n.getInheritedAttribute("y")),a.hasValue()||a.setValue(n.getInheritedAttribute("dx")),o.hasValue()||o.setValue(n.getInheritedAttribute("dy")));var u=n.measureText(e);return c&&(t.x-=u),i.hasValue()?(t.applyAnchoring(),n.x=i.getPixels("x"),a.hasValue()&&(n.x+=a.getPixels("x"))):(a.hasValue()&&(t.x+=a.getPixels("x")),n.x=t.x),t.x=n.x,c||(t.x+=u),s.hasValue()?(n.y=s.getPixels("y"),o.hasValue()&&(n.y+=o.getPixels("y"))):(o.hasValue()&&(t.y+=o.getPixels("y")),n.y=t.y),t.y=n.y,t.leafTexts.push(n),t.minX=Math.min(t.minX,n.x,n.x+u),t.maxX=Math.max(t.maxX,n.x,n.x+u),n.clearContext(e),e.restore(),n}getChildBoundingBox(e,t,A,r){var n=A.children[r];if("function"!=typeof n.getBoundingBox)return null;var i=n.getBoundingBox(e);return i?(n.children.forEach((A,r)=>{var s=t.getChildBoundingBox(e,t,n,r);i.addBoundingBox(s)}),i):null}renderChild(e,t,A,r){var n=A.children[r];n.render(e),n.children.forEach((A,r)=>{t.renderChild(e,t,n,r)})}measureText(e){var{measureCache:t}=this;if(~t)return t;var A=this.getText(),r=this.measureTargetText(e,A);return this.measureCache=r,r}measureTargetText(e,t){if(!t.length)return 0;var{parent:A}=this,r=A.getStyle("font-family").getDefinition();if(r){for(var n=this.getFontSize(),i=r.isRTL?t.split("").reverse().join(""):t,s=WF(A.getAttribute("dx").getString()),a=i.length,o=0,l=0;l<a;l++){o+=(this.getGlyph(r,i,l).horizAdvX||r.horizAdvX)*n/r.fontFace.unitsPerEm,void 0===s[l]||isNaN(s[l])||(o+=s[l])}return o}if(!e.measureText)return 10*t.length;e.save(),this.setContext(e,!0);var{width:c}=e.measureText(t);return this.clearContext(e),e.restore(),c}getInheritedAttribute(e){for(var t=this;t instanceof WQ&&t.isFirstChild();){var A=t.parent.getAttribute(e);if(A.hasValue(!0))return A.getValue("0");t=t.parent}return null}}class XQ extends WQ{constructor(e,t,A){super(e,t,new.target===XQ||A),this.type="tspan",this.text=this.children.length>0?"":this.getTextFromNode()}getText(){return this.text}}class YQ extends XQ{constructor(){super(...arguments),this.type="textNode"}}class JQ extends GQ{constructor(){super(...arguments),this.type="svg",this.root=!1}setContext(e){var t,{document:A}=this,{screen:r,window:n}=A,i=e.canvas;if(r.setDefaults(e),i.style&&void 0!==e.font&&n&&void 0!==n.getComputedStyle){e.font=n.getComputedStyle(i).getPropertyValue("font");var s=new wQ(A,"fontSize",RQ.parse(e.font).fontSize);s.hasValue()&&(A.rootEmSize=s.getPixels("y"),A.emSize=A.rootEmSize)}this.getAttribute("x").hasValue()||this.getAttribute("x",!0).setValue(0),this.getAttribute("y").hasValue()||this.getAttribute("y",!0).setValue(0);var{width:a,height:o}=r.viewPort;this.getStyle("width").hasValue()||this.getStyle("width",!0).setValue("100%"),this.getStyle("height").hasValue()||this.getStyle("height",!0).setValue("100%"),this.getStyle("color").hasValue()||this.getStyle("color",!0).setValue("black");var l=this.getAttribute("refX"),c=this.getAttribute("refY"),u=this.getAttribute("viewBox"),h=u.hasValue()?WF(u.getString()):null,d=!this.root&&"visible"!==this.getStyle("overflow").getValue("hidden"),f=0,p=0,g=0,m=0;h&&(f=h[0],p=h[1]),this.root||(a=this.getStyle("width").getPixels("x"),o=this.getStyle("height").getPixels("y"),"marker"===this.type&&(g=f,m=p,f=0,p=0)),r.viewPort.setCurrent(a,o),!this.node||this.parent&&"foreignObject"!==(null===(t=this.node.parentNode)||void 0===t?void 0:t.nodeName)||!this.getStyle("transform",!1,!0).hasValue()||this.getStyle("transform-origin",!1,!0).hasValue()||this.getStyle("transform-origin",!0,!0).setValue("50% 50%"),super.setContext(e),e.translate(this.getAttribute("x").getPixels("x"),this.getAttribute("y").getPixels("y")),h&&(a=h[2],o=h[3]),A.setViewBox({ctx:e,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:r.viewPort.width,desiredWidth:a,height:r.viewPort.height,desiredHeight:o,minX:f,minY:p,refX:l.getValue(),refY:c.getValue(),clip:d,clipX:g,clipY:m}),h&&(r.viewPort.removeCurrent(),r.viewPort.setCurrent(a,o))}clearContext(e){super.clearContext(e),this.document.screen.viewPort.removeCurrent()}resize(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,A=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this.getAttribute("width",!0),n=this.getAttribute("height",!0),i=this.getAttribute("viewBox"),s=this.getAttribute("style"),a=r.getNumber(0),o=n.getNumber(0);if(A)if("string"==typeof A)this.getAttribute("preserveAspectRatio",!0).setValue(A);else{var l=this.getAttribute("preserveAspectRatio");l.hasValue()&&l.setValue(l.getString().replace(/^\s*(\S.*\S)\s*$/,"$1"))}if(r.setValue(e),n.setValue(t),i.hasValue()||i.setValue("0 0 ".concat(a||e," ").concat(o||t)),s.hasValue()){var c=this.getStyle("width"),u=this.getStyle("height");c.hasValue()&&c.setValue("".concat(e,"px")),u.hasValue()&&u.setValue("".concat(t,"px"))}}}class $Q extends zQ{constructor(){super(...arguments),this.type="rect"}path(e){var t=this.getAttribute("x").getPixels("x"),A=this.getAttribute("y").getPixels("y"),r=this.getStyle("width",!1,!0).getPixels("x"),n=this.getStyle("height",!1,!0).getPixels("y"),i=this.getAttribute("rx"),s=this.getAttribute("ry"),a=i.getPixels("x"),o=s.getPixels("y");if(i.hasValue()&&!s.hasValue()&&(o=a),s.hasValue()&&!i.hasValue()&&(a=o),a=Math.min(a,r/2),o=Math.min(o,n/2),e){var l=(Math.sqrt(2)-1)/3*4;e.beginPath(),n>0&&r>0&&(e.moveTo(t+a,A),e.lineTo(t+r-a,A),e.bezierCurveTo(t+r-a+l*a,A,t+r,A+o-l*o,t+r,A+o),e.lineTo(t+r,A+n-o),e.bezierCurveTo(t+r,A+n-o+l*o,t+r-a+l*a,A+n,t+r-a,A+n),e.lineTo(t+a,A+n),e.bezierCurveTo(t+a-l*a,A+n,t,A+n-o+l*o,t,A+n-o),e.lineTo(t,A+o),e.bezierCurveTo(t,A+o-l*o,t+a-l*a,A,t+a,A),e.closePath())}return new VQ(t,A,t+r,A+n)}getMarkers(){return null}}class ZQ extends zQ{constructor(){super(...arguments),this.type="circle"}path(e){var t=this.getAttribute("cx").getPixels("x"),A=this.getAttribute("cy").getPixels("y"),r=this.getAttribute("r").getPixels();return e&&r>0&&(e.beginPath(),e.arc(t,A,r,0,2*Math.PI,!1),e.closePath()),new VQ(t-r,A-r,t+r,A+r)}getMarkers(){return null}}class eU extends zQ{constructor(){super(...arguments),this.type="ellipse"}path(e){var t=(Math.sqrt(2)-1)/3*4,A=this.getAttribute("rx").getPixels("x"),r=this.getAttribute("ry").getPixels("y"),n=this.getAttribute("cx").getPixels("x"),i=this.getAttribute("cy").getPixels("y");return e&&A>0&&r>0&&(e.beginPath(),e.moveTo(n+A,i),e.bezierCurveTo(n+A,i+t*r,n+t*A,i+r,n,i+r),e.bezierCurveTo(n-t*A,i+r,n-A,i+t*r,n-A,i),e.bezierCurveTo(n-A,i-t*r,n-t*A,i-r,n,i-r),e.bezierCurveTo(n+t*A,i-r,n+A,i-t*r,n+A,i),e.closePath()),new VQ(n-A,i-r,n+A,i+r)}getMarkers(){return null}}class tU extends zQ{constructor(){super(...arguments),this.type="line"}getPoints(){return[new BQ(this.getAttribute("x1").getPixels("x"),this.getAttribute("y1").getPixels("y")),new BQ(this.getAttribute("x2").getPixels("x"),this.getAttribute("y2").getPixels("y"))]}path(e){var[{x:t,y:A},{x:r,y:n}]=this.getPoints();return e&&(e.beginPath(),e.moveTo(t,A),e.lineTo(r,n)),new VQ(t,A,r,n)}getMarkers(){var[e,t]=this.getPoints(),A=e.angleTo(t);return[[e,A],[t,A]]}}class AU extends zQ{constructor(e,t,A){super(e,t,A),this.type="polyline",this.points=[],this.points=BQ.parsePath(this.getAttribute("points").getString())}path(e){var{points:t}=this,[{x:A,y:r}]=t,n=new VQ(A,r);return e&&(e.beginPath(),e.moveTo(A,r)),t.forEach(t=>{var{x:A,y:r}=t;n.addPoint(A,r),e&&e.lineTo(A,r)}),n}getMarkers(){var{points:e}=this,t=e.length-1,A=[];return e.forEach((r,n)=>{n!==t&&A.push([r,r.angleTo(e[n+1])])}),A.length>0&&A.push([e[e.length-1],A[A.length-1][1]]),A}}class rU extends AU{constructor(){super(...arguments),this.type="polygon"}path(e){var t=super.path(e),[{x:A,y:r}]=this.points;return e&&(e.lineTo(A,r),e.closePath()),t}}class nU extends jQ{constructor(){super(...arguments),this.type="pattern"}createPattern(e,t,A){var r=this.getStyle("width").getPixels("x",!0),n=this.getStyle("height").getPixels("y",!0),i=new JQ(this.document,null);i.attributes.viewBox=new wQ(this.document,"viewBox",this.getAttribute("viewBox").getValue()),i.attributes.width=new wQ(this.document,"width","".concat(r,"px")),i.attributes.height=new wQ(this.document,"height","".concat(n,"px")),i.attributes.transform=new wQ(this.document,"transform",this.getAttribute("patternTransform").getValue()),i.children=this.children;var s=this.document.createCanvas(r,n),a=s.getContext("2d"),o=this.getAttribute("x"),l=this.getAttribute("y");o.hasValue()&&l.hasValue()&&a.translate(o.getPixels("x",!0),l.getPixels("y",!0)),A.hasValue()?this.styles["fill-opacity"]=A:Reflect.deleteProperty(this.styles,"fill-opacity");for(var c=-1;c<=1;c++)for(var u=-1;u<=1;u++)a.save(),i.attributes.x=new wQ(this.document,"x",c*s.width),i.attributes.y=new wQ(this.document,"y",u*s.height),i.render(a),a.restore();return e.createPattern(s,"repeat")}}class iU extends jQ{constructor(){super(...arguments),this.type="marker"}render(e,t,A){if(t){var{x:r,y:n}=t,i=this.getAttribute("orient").getString("auto"),s=this.getAttribute("markerUnits").getString("strokeWidth");e.translate(r,n),"auto"===i&&e.rotate(A),"strokeWidth"===s&&e.scale(e.lineWidth,e.lineWidth),e.save();var a=new JQ(this.document,null);a.type=this.type,a.attributes.viewBox=new wQ(this.document,"viewBox",this.getAttribute("viewBox").getValue()),a.attributes.refX=new wQ(this.document,"refX",this.getAttribute("refX").getValue()),a.attributes.refY=new wQ(this.document,"refY",this.getAttribute("refY").getValue()),a.attributes.width=new wQ(this.document,"width",this.getAttribute("markerWidth").getValue()),a.attributes.height=new wQ(this.document,"height",this.getAttribute("markerHeight").getValue()),a.attributes.overflow=new wQ(this.document,"overflow",this.getAttribute("overflow").getValue()),a.attributes.fill=new wQ(this.document,"fill",this.getAttribute("fill").getColor("black")),a.attributes.stroke=new wQ(this.document,"stroke",this.getAttribute("stroke").getValue("none")),a.children=this.children,a.render(e),e.restore(),"strokeWidth"===s&&e.scale(1/e.lineWidth,1/e.lineWidth),"auto"===i&&e.rotate(-A),e.translate(-r,-n)}}}class sU extends jQ{constructor(){super(...arguments),this.type="defs"}render(){}}class aU extends GQ{constructor(){super(...arguments),this.type="g"}getBoundingBox(e){var t=new VQ;return this.children.forEach(A=>{t.addBoundingBox(A.getBoundingBox(e))}),t}}class oU extends jQ{constructor(e,t,A){super(e,t,A),this.attributesToInherit=["gradientUnits"],this.stops=[];var{stops:r,children:n}=this;n.forEach(e=>{"stop"===e.type&&r.push(e)})}getGradientUnits(){return this.getAttribute("gradientUnits").getString("objectBoundingBox")}createGradient(e,t,A){var r=this;this.getHrefAttribute().hasValue()&&(r=this.getHrefAttribute().getDefinition(),this.inheritStopContainer(r));var{stops:n}=r,i=this.getGradient(e,t);if(!i)return this.addParentOpacity(A,n[n.length-1].color);if(n.forEach(e=>{i.addColorStop(e.offset,this.addParentOpacity(A,e.color))}),this.getAttribute("gradientTransform").hasValue()){var{document:s}=this,{MAX_VIRTUAL_PIXELS:a,viewPort:o}=s.screen,[l]=o.viewPorts,c=new $Q(s,null);c.attributes.x=new wQ(s,"x",-a/3),c.attributes.y=new wQ(s,"y",-a/3),c.attributes.width=new wQ(s,"width",a),c.attributes.height=new wQ(s,"height",a);var u=new aU(s,null);u.attributes.transform=new wQ(s,"transform",this.getAttribute("gradientTransform").getValue()),u.children=[c];var h=new JQ(s,null);h.attributes.x=new wQ(s,"x",0),h.attributes.y=new wQ(s,"y",0),h.attributes.width=new wQ(s,"width",l.width),h.attributes.height=new wQ(s,"height",l.height),h.children=[u];var d=s.createCanvas(l.width,l.height),f=d.getContext("2d");return f.fillStyle=i,h.render(f),f.createPattern(d,"no-repeat")}return i}inheritStopContainer(e){this.attributesToInherit.forEach(t=>{!this.getAttribute(t).hasValue()&&e.getAttribute(t).hasValue()&&this.getAttribute(t,!0).setValue(e.getAttribute(t).getValue())})}addParentOpacity(e,t){return e.hasValue()?new wQ(this.document,"color",t).addOpacity(e).getColor():t}}class lU extends oU{constructor(e,t,A){super(e,t,A),this.type="linearGradient",this.attributesToInherit.push("x1","y1","x2","y2")}getGradient(e,t){var A="objectBoundingBox"===this.getGradientUnits(),r=A?t.getBoundingBox(e):null;if(A&&!r)return null;this.getAttribute("x1").hasValue()||this.getAttribute("y1").hasValue()||this.getAttribute("x2").hasValue()||this.getAttribute("y2").hasValue()||(this.getAttribute("x1",!0).setValue(0),this.getAttribute("y1",!0).setValue(0),this.getAttribute("x2",!0).setValue(1),this.getAttribute("y2",!0).setValue(0));var n=A?r.x+r.width*this.getAttribute("x1").getNumber():this.getAttribute("x1").getPixels("x"),i=A?r.y+r.height*this.getAttribute("y1").getNumber():this.getAttribute("y1").getPixels("y"),s=A?r.x+r.width*this.getAttribute("x2").getNumber():this.getAttribute("x2").getPixels("x"),a=A?r.y+r.height*this.getAttribute("y2").getNumber():this.getAttribute("y2").getPixels("y");return n===s&&i===a?null:e.createLinearGradient(n,i,s,a)}}class cU extends oU{constructor(e,t,A){super(e,t,A),this.type="radialGradient",this.attributesToInherit.push("cx","cy","r","fx","fy","fr")}getGradient(e,t){var A="objectBoundingBox"===this.getGradientUnits(),r=t.getBoundingBox(e);if(A&&!r)return null;this.getAttribute("cx").hasValue()||this.getAttribute("cx",!0).setValue("50%"),this.getAttribute("cy").hasValue()||this.getAttribute("cy",!0).setValue("50%"),this.getAttribute("r").hasValue()||this.getAttribute("r",!0).setValue("50%");var n=A?r.x+r.width*this.getAttribute("cx").getNumber():this.getAttribute("cx").getPixels("x"),i=A?r.y+r.height*this.getAttribute("cy").getNumber():this.getAttribute("cy").getPixels("y"),s=n,a=i;this.getAttribute("fx").hasValue()&&(s=A?r.x+r.width*this.getAttribute("fx").getNumber():this.getAttribute("fx").getPixels("x")),this.getAttribute("fy").hasValue()&&(a=A?r.y+r.height*this.getAttribute("fy").getNumber():this.getAttribute("fy").getPixels("y"));var o=A?(r.width+r.height)/2*this.getAttribute("r").getNumber():this.getAttribute("r").getPixels(),l=this.getAttribute("fr").getPixels();return e.createRadialGradient(s,a,l,n,i,o)}}class uU extends jQ{constructor(e,t,A){super(e,t,A),this.type="stop";var r=Math.max(0,Math.min(1,this.getAttribute("offset").getNumber())),n=this.getStyle("stop-opacity"),i=this.getStyle("stop-color",!0);""===i.getString()&&i.setValue("#000"),n.hasValue()&&(i=i.addOpacity(n)),this.offset=r,this.color=i.getColor()}}class hU extends jQ{constructor(e,t,A){super(e,t,A),this.type="animate",this.duration=0,this.initialValue=null,this.initialUnits="",this.removed=!1,this.frozen=!1,e.screen.animations.push(this),this.begin=this.getAttribute("begin").getMilliseconds(),this.maxDuration=this.begin+this.getAttribute("dur").getMilliseconds(),this.from=this.getAttribute("from"),this.to=this.getAttribute("to"),this.values=new wQ(e,"values",null);var r=this.getAttribute("values");r.hasValue()&&this.values.setValue(r.getString().split(";"))}getProperty(){var e=this.getAttribute("attributeType").getString(),t=this.getAttribute("attributeName").getString();return"CSS"===e?this.parent.getStyle(t,!0):this.parent.getAttribute(t,!0)}calcValue(){var{initialUnits:e}=this,{progress:t,from:A,to:r}=this.getProgress(),n=A.getNumber()+(r.getNumber()-A.getNumber())*t;return"%"===e&&(n*=100),"".concat(n).concat(e)}update(e){var{parent:t}=this,A=this.getProperty();if(this.initialValue||(this.initialValue=A.getString(),this.initialUnits=A.getUnits()),this.duration>this.maxDuration){var r=this.getAttribute("fill").getString("remove");if("indefinite"===this.getAttribute("repeatCount").getString()||"indefinite"===this.getAttribute("repeatDur").getString())this.duration=0;else if("freeze"!==r||this.frozen){if("remove"===r&&!this.removed)return this.removed=!0,A.setValue(t.animationFrozen?t.animationFrozenValue:this.initialValue),!0}else this.frozen=!0,t.animationFrozen=!0,t.animationFrozenValue=A.getString();return!1}this.duration+=e;var n=!1;if(this.begin<this.duration){var i=this.calcValue(),s=this.getAttribute("type");if(s.hasValue()){var a=s.getString();i="".concat(a,"(").concat(i,")")}A.setValue(i),n=!0}return n}getProgress(){var{document:e,values:t}=this,A={progress:(this.duration-this.begin)/(this.maxDuration-this.begin)};if(t.hasValue()){var r=A.progress*(t.getValue().length-1),n=Math.floor(r),i=Math.ceil(r);A.from=new wQ(e,"from",parseFloat(t.getValue()[n])),A.to=new wQ(e,"to",parseFloat(t.getValue()[i])),A.progress=(r-n)/(i-n)}else A.from=this.from,A.to=this.to;return A}}class dU extends hU{constructor(){super(...arguments),this.type="animateColor"}calcValue(){var{progress:e,from:t,to:A}=this.getProgress(),r=new Gx(t.getColor()),n=new Gx(A.getColor());if(r.ok&&n.ok){var i=r.r+(n.r-r.r)*e,s=r.g+(n.g-r.g)*e,a=r.b+(n.b-r.b)*e;return"rgb(".concat(Math.floor(i),", ").concat(Math.floor(s),", ").concat(Math.floor(a),")")}return this.getAttribute("from").getColor()}}class fU extends hU{constructor(){super(...arguments),this.type="animateTransform"}calcValue(){var{progress:e,from:t,to:A}=this.getProgress(),r=WF(t.getString()),n=WF(A.getString()),i=r.map((t,A)=>t+(n[A]-t)*e).join(" ");return i}}class pU extends jQ{constructor(e,t,A){super(e,t,A),this.type="font",this.glyphs=Object.create(null),this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber();var{definitions:r}=e,{children:n}=this;for(var i of n)switch(i.type){case"font-face":this.fontFace=i;var s=i.getStyle("font-family");s.hasValue()&&(r[s.getString()]=this);break;case"missing-glyph":this.missingGlyph=i;break;case"glyph":var a=i;a.arabicForm?(this.isRTL=!0,this.isArabic=!0,void 0===this.glyphs[a.unicode]&&(this.glyphs[a.unicode]=Object.create(null)),this.glyphs[a.unicode][a.arabicForm]=a):this.glyphs[a.unicode]=a}}render(){}}class gU extends jQ{constructor(e,t,A){super(e,t,A),this.type="font-face",this.ascent=this.getAttribute("ascent").getNumber(),this.descent=this.getAttribute("descent").getNumber(),this.unitsPerEm=this.getAttribute("units-per-em").getNumber()}}class mU extends zQ{constructor(){super(...arguments),this.type="missing-glyph",this.horizAdvX=0}}class vU extends WQ{constructor(){super(...arguments),this.type="tref"}getText(){var e=this.getHrefAttribute().getDefinition();if(e){var t=e.children[0];if(t)return t.getText()}return""}}class wU extends WQ{constructor(e,t,A){super(e,t,A),this.type="a";var{childNodes:r}=t,n=r[0],i=r.length>0&&Array.from(r).every(e=>3===e.nodeType);this.hasText=i,this.text=i?this.getTextFromNode(n):""}getText(){return this.text}renderChildren(e){if(this.hasText){super.renderChildren(e);var{document:t,x:A,y:r}=this,{mouse:n}=t.screen,i=new wQ(t,"fontSize",RQ.parse(t.ctx.font).fontSize);n.isWorking()&&n.checkBoundingBox(this,new VQ(A,r-i.getPixels("y"),A+this.measureText(e),r))}else if(this.children.length>0){var s=new aU(this.document,null);s.children=this.children,s.parent=this,s.render(e)}}onClick(){var{window:e}=this.document;e&&e.open(this.getHrefAttribute().getString())}onMouseMove(){this.document.ctx.canvas.style.cursor="pointer"}}function bU(e,t){var A=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),A.push.apply(A,r)}return A}function BU(e){for(var t=1;t<arguments.length;t++){var A=null!=arguments[t]?arguments[t]:{};t%2?bU(Object(A),!0).forEach(function(t){EC(e,t,A[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(A)):bU(Object(A)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(A,t))})}return e}class yU extends WQ{constructor(e,t,A){super(e,t,A),this.type="textPath",this.textWidth=0,this.textHeight=0,this.pathLength=-1,this.glyphInfo=null,this.letterSpacingCache=[],this.measuresCache=new Map([["",0]]);var r=this.getHrefAttribute().getDefinition();this.text=this.getTextFromNode(),this.dataArray=this.parsePathData(r)}getText(){return this.text}path(e){var{dataArray:t}=this;e&&e.beginPath(),t.forEach(t=>{var{type:A,points:r}=t;switch(A){case KQ.LINE_TO:e&&e.lineTo(r[0],r[1]);break;case KQ.MOVE_TO:e&&e.moveTo(r[0],r[1]);break;case KQ.CURVE_TO:e&&e.bezierCurveTo(r[0],r[1],r[2],r[3],r[4],r[5]);break;case KQ.QUAD_TO:e&&e.quadraticCurveTo(r[0],r[1],r[2],r[3]);break;case KQ.ARC:var[n,i,s,a,o,l,c,u]=r,h=s>a?s:a,d=s>a?1:s/a,f=s>a?a/s:1;e&&(e.translate(n,i),e.rotate(c),e.scale(d,f),e.arc(0,0,h,o,o+l,Boolean(1-u)),e.scale(1/d,1/f),e.rotate(-c),e.translate(-n,-i));break;case KQ.CLOSE_PATH:e&&e.closePath()}})}renderChildren(e){this.setTextData(e),e.save();var t=this.parent.getStyle("text-decoration").getString(),A=this.getFontSize(),{glyphInfo:r}=this,n=e.fillStyle;"underline"===t&&e.beginPath(),r.forEach((r,n)=>{var{p0:i,p1:s,rotation:a,text:o}=r;e.save(),e.translate(i.x,i.y),e.rotate(a),e.fillStyle&&e.fillText(o,0,0),e.strokeStyle&&e.strokeText(o,0,0),e.restore(),"underline"===t&&(0===n&&e.moveTo(i.x,i.y+A/8),e.lineTo(s.x,s.y+A/5))}),"underline"===t&&(e.lineWidth=A/20,e.strokeStyle=n,e.stroke(),e.closePath()),e.restore()}getLetterSpacingAt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.letterSpacingCache[e]||0}findSegmentToFitChar(e,t,A,r,n,i,s,a,o){var l=i,c=this.measureText(e,a);" "===a&&"justify"===t&&A<r&&(c+=(r-A)/n),o>-1&&(l+=this.getLetterSpacingAt(o));var u=this.textHeight/20,h=this.getEquidistantPointOnPath(l,u,0),d=this.getEquidistantPointOnPath(l+c,u,0),f={p0:h,p1:d},p=h&&d?Math.atan2(d.y-h.y,d.x-h.x):0;if(s){var g=Math.cos(Math.PI/2+p)*s,m=Math.cos(-p)*s;f.p0=BU(BU({},h),{},{x:h.x+g,y:h.y+m}),f.p1=BU(BU({},d),{},{x:d.x+g,y:d.y+m})}return{offset:l+=c,segment:f,rotation:p}}measureText(e,t){var{measuresCache:A}=this,r=t||this.getText();if(A.has(r))return A.get(r);var n=this.measureTargetText(e,r);return A.set(r,n),n}setTextData(e){if(!this.glyphInfo){var t=this.getText(),A=t.split(""),r=t.split(" ").length-1,n=this.parent.getAttribute("dx").split().map(e=>e.getPixels("x")),i=this.parent.getAttribute("dy").getPixels("y"),s=this.parent.getStyle("text-anchor").getString("start"),a=this.getStyle("letter-spacing"),o=this.parent.getStyle("letter-spacing"),l=0;a.hasValue()&&"inherit"!==a.getValue()?a.hasValue()&&"initial"!==a.getValue()&&"unset"!==a.getValue()&&(l=a.getPixels()):l=o.getPixels();var c=[],u=t.length;this.letterSpacingCache=c;for(var h=0;h<u;h++)c.push(void 0!==n[h]?n[h]:l);var d=c.reduce((e,t,A)=>0===A?0:e+t||0,0),f=this.measureText(e),p=Math.max(f+d,0);this.textWidth=f,this.textHeight=this.getFontSize(),this.glyphInfo=[];var g=this.getPathLength(),m=this.getStyle("startOffset").getNumber(0)*g,v=0;"middle"!==s&&"center"!==s||(v=-p/2),"end"!==s&&"right"!==s||(v=-p),v+=m,A.forEach((t,n)=>{var{offset:a,segment:o,rotation:l}=this.findSegmentToFitChar(e,s,p,g,r,v,i,t,n);v=a,o.p0&&o.p1&&this.glyphInfo.push({text:A[n],p0:o.p0,p1:o.p1,rotation:l})})}}parsePathData(e){if(this.pathLength=-1,!e)return[];var t=[],{pathParser:A}=e;for(A.reset();!A.isEnd();){var{current:r}=A,n=r?r.x:0,i=r?r.y:0,s=A.next(),a=s.type,o=[];switch(s.type){case KQ.MOVE_TO:this.pathM(A,o);break;case KQ.LINE_TO:a=this.pathL(A,o);break;case KQ.HORIZ_LINE_TO:a=this.pathH(A,o);break;case KQ.VERT_LINE_TO:a=this.pathV(A,o);break;case KQ.CURVE_TO:this.pathC(A,o);break;case KQ.SMOOTH_CURVE_TO:a=this.pathS(A,o);break;case KQ.QUAD_TO:this.pathQ(A,o);break;case KQ.SMOOTH_QUAD_TO:a=this.pathT(A,o);break;case KQ.ARC:o=this.pathA(A);break;case KQ.CLOSE_PATH:zQ.pathZ(A)}s.type!==KQ.CLOSE_PATH?t.push({type:a,points:o,start:{x:n,y:i},pathLength:this.calcLength(n,i,a,o)}):t.push({type:KQ.CLOSE_PATH,points:[],pathLength:0})}return t}pathM(e,t){var{x:A,y:r}=zQ.pathM(e).point;t.push(A,r)}pathL(e,t){var{x:A,y:r}=zQ.pathL(e).point;return t.push(A,r),KQ.LINE_TO}pathH(e,t){var{x:A,y:r}=zQ.pathH(e).point;return t.push(A,r),KQ.LINE_TO}pathV(e,t){var{x:A,y:r}=zQ.pathV(e).point;return t.push(A,r),KQ.LINE_TO}pathC(e,t){var{point:A,controlPoint:r,currentPoint:n}=zQ.pathC(e);t.push(A.x,A.y,r.x,r.y,n.x,n.y)}pathS(e,t){var{point:A,controlPoint:r,currentPoint:n}=zQ.pathS(e);return t.push(A.x,A.y,r.x,r.y,n.x,n.y),KQ.CURVE_TO}pathQ(e,t){var{controlPoint:A,currentPoint:r}=zQ.pathQ(e);t.push(A.x,A.y,r.x,r.y)}pathT(e,t){var{controlPoint:A,currentPoint:r}=zQ.pathT(e);return t.push(A.x,A.y,r.x,r.y),KQ.QUAD_TO}pathA(e){var{rX:t,rY:A,sweepFlag:r,xAxisRotation:n,centp:i,a1:s,ad:a}=zQ.pathA(e);return 0===r&&a>0&&(a-=2*Math.PI),1===r&&a<0&&(a+=2*Math.PI),[i.x,i.y,t,A,s,a,n,r]}calcLength(e,t,A,r){var n=0,i=null,s=null,a=0;switch(A){case KQ.LINE_TO:return this.getLineLength(e,t,r[0],r[1]);case KQ.CURVE_TO:for(n=0,i=this.getPointOnCubicBezier(0,e,t,r[0],r[1],r[2],r[3],r[4],r[5]),a=.01;a<=1;a+=.01)s=this.getPointOnCubicBezier(a,e,t,r[0],r[1],r[2],r[3],r[4],r[5]),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;return n;case KQ.QUAD_TO:for(n=0,i=this.getPointOnQuadraticBezier(0,e,t,r[0],r[1],r[2],r[3]),a=.01;a<=1;a+=.01)s=this.getPointOnQuadraticBezier(a,e,t,r[0],r[1],r[2],r[3]),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;return n;case KQ.ARC:n=0;var o=r[4],l=r[5],c=r[4]+l,u=Math.PI/180;if(Math.abs(o-c)<u&&(u=Math.abs(o-c)),i=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],o,0),l<0)for(a=o-u;a>c;a-=u)s=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],a,0),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;else for(a=o+u;a<c;a+=u)s=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],a,0),n+=this.getLineLength(i.x,i.y,s.x,s.y),i=s;return s=this.getPointOnEllipticalArc(r[0],r[1],r[2],r[3],c,0),n+=this.getLineLength(i.x,i.y,s.x,s.y)}return 0}getPointOnLine(e,t,A,r,n){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:t,s=arguments.length>6&&void 0!==arguments[6]?arguments[6]:A,a=(n-A)/(r-t+oQ),o=Math.sqrt(e*e/(1+a*a));r<t&&(o*=-1);var l=a*o,c=null;if(r===t)c={x:i,y:s+l};else if((s-A)/(i-t+oQ)===a)c={x:i+o,y:s+l};else{var u,h,d=this.getLineLength(t,A,r,n);if(d<oQ)return null;var f=(i-t)*(r-t)+(s-A)*(n-A);u=t+(f/=d*d)*(r-t),h=A+f*(n-A);var p=this.getLineLength(i,s,u,h),g=Math.sqrt(e*e-p*p);o=Math.sqrt(g*g/(1+a*a)),r<t&&(o*=-1),c={x:u+o,y:h+(l=a*o)}}return c}getPointOnPath(e){var t=this.getPathLength(),A=0,r=null;if(e<-5e-5||e-5e-5>t)return null;var{dataArray:n}=this;for(var i of n){if(!i||!(i.pathLength<5e-5||A+i.pathLength+5e-5<e)){var s=e-A,a=0;switch(i.type){case KQ.LINE_TO:r=this.getPointOnLine(s,i.start.x,i.start.y,i.points[0],i.points[1],i.start.x,i.start.y);break;case KQ.ARC:var o=i.points[4],l=i.points[5],c=i.points[4]+l;if(a=o+s/i.pathLength*l,l<0&&a<c||l>=0&&a>c)break;r=this.getPointOnEllipticalArc(i.points[0],i.points[1],i.points[2],i.points[3],a,i.points[6]);break;case KQ.CURVE_TO:(a=s/i.pathLength)>1&&(a=1),r=this.getPointOnCubicBezier(a,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3],i.points[4],i.points[5]);break;case KQ.QUAD_TO:(a=s/i.pathLength)>1&&(a=1),r=this.getPointOnQuadraticBezier(a,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3])}if(r)return r;break}A+=i.pathLength}return null}getLineLength(e,t,A,r){return Math.sqrt((A-e)*(A-e)+(r-t)*(r-t))}getPathLength(){return-1===this.pathLength&&(this.pathLength=this.dataArray.reduce((e,t)=>t.pathLength>0?e+t.pathLength:e,0)),this.pathLength}getPointOnCubicBezier(e,t,A,r,n,i,s,a,o){return{x:a*hQ(e)+i*dQ(e)+r*fQ(e)+t*pQ(e),y:o*hQ(e)+s*dQ(e)+n*fQ(e)+A*pQ(e)}}getPointOnQuadraticBezier(e,t,A,r,n,i,s){return{x:i*gQ(e)+r*mQ(e)+t*vQ(e),y:s*gQ(e)+n*mQ(e)+A*vQ(e)}}getPointOnEllipticalArc(e,t,A,r,n,i){var s=Math.cos(i),a=Math.sin(i),o=A*Math.cos(n),l=r*Math.sin(n);return{x:e+(o*s-l*a),y:t+(o*a+l*s)}}buildEquidistantCache(e,t){var A=this.getPathLength(),r=t||.25,n=e||A/100;if(!this.equidistantCache||this.equidistantCache.step!==n||this.equidistantCache.precision!==r){this.equidistantCache={step:n,precision:r,points:[]};for(var i=0,s=0;s<=A;s+=r){var a=this.getPointOnPath(s),o=this.getPointOnPath(s+r);a&&o&&((i+=this.getLineLength(a.x,a.y,o.x,o.y))>=n&&(this.equidistantCache.points.push({x:a.x,y:a.y,distance:s}),i-=n))}}}getEquidistantPointOnPath(e,t,A){if(this.buildEquidistantCache(t,A),e<0||e-this.getPathLength()>5e-5)return null;var r=Math.round(e/this.getPathLength()*(this.equidistantCache.points.length-1));return this.equidistantCache.points[r]||null}}var CU=/^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(.*)$/i;class xU extends GQ{constructor(e,t,A){super(e,t,A),this.type="image",this.loaded=!1;var r=this.getHrefAttribute().getString();if(r){var n=r.endsWith(".svg")||/^\s*data:image\/svg\+xml/i.test(r);e.images.push(this),n?this.loadSvg(r):this.loadImage(r),this.isSvg=n}}loadImage(e){var t=this;return Jv(function*(){try{var A=yield t.document.createImage(e);t.image=A}catch(t){console.error('Error while loading image "'.concat(e,'":'),t)}t.loaded=!0})()}loadSvg(e){var t=this;return Jv(function*(){var A=CU.exec(e);if(A){var r=A[5];"base64"===A[4]?t.image=atob(r):t.image=decodeURIComponent(r)}else try{var n=yield t.document.fetch(e),i=yield n.text();t.image=i}catch(t){console.error('Error while loading image "'.concat(e,'":'),t)}t.loaded=!0})()}renderChildren(e){var{document:t,image:A,loaded:r}=this,n=this.getAttribute("x").getPixels("x"),i=this.getAttribute("y").getPixels("y"),s=this.getStyle("width").getPixels("x"),a=this.getStyle("height").getPixels("y");if(r&&A&&s&&a){if(e.save(),e.translate(n,i),this.isSvg){var o=t.canvg.forkString(e,this.image,{ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0,ignoreClear:!0,offsetX:0,offsetY:0,scaleWidth:s,scaleHeight:a});o.document.documentElement.parent=this,o.render()}else{var l=this.image;t.setViewBox({ctx:e,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:s,desiredWidth:l.width,height:a,desiredHeight:l.height}),this.loaded&&(void 0===l.complete||l.complete)&&e.drawImage(l,0,0)}e.restore()}}getBoundingBox(){var e=this.getAttribute("x").getPixels("x"),t=this.getAttribute("y").getPixels("y"),A=this.getStyle("width").getPixels("x"),r=this.getStyle("height").getPixels("y");return new VQ(e,t,e+A,t+r)}}class FU extends GQ{constructor(){super(...arguments),this.type="symbol"}render(e){}}class QU{constructor(e){this.document=e,this.loaded=!1,e.fonts.push(this)}load(e,t){var A=this;return Jv(function*(){try{var{document:r}=A,n=(yield r.canvg.parser.load(t)).getElementsByTagName("font");Array.from(n).forEach(t=>{var A=r.createElement(t);r.definitions[e]=A})}catch(e){console.error('Error while loading font "'.concat(t,'":'),e)}A.loaded=!0})()}}class UU extends jQ{constructor(e,t,A){super(e,t,A),this.type="style";var r=GF(Array.from(t.childNodes).map(e=>e.textContent).join("").replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm,"").replace(/@import.*;/g,""));r.split("}").forEach(t=>{var A=t.trim();if(A){var r=A.split("{"),n=r[0].split(","),i=r[1].split(";");n.forEach(t=>{var A=t.trim();if(A){var r=e.styles[A]||{};if(i.forEach(t=>{var A=t.indexOf(":"),n=t.substr(0,A).trim(),i=t.substr(A+1,t.length-A).trim();n&&i&&(r[n]=new wQ(e,n,i))}),e.styles[A]=r,e.stylesSpecificity[A]=aQ(A),"@font-face"===A){var n=r["font-family"].getString().replace(/"|'/g,"");r.src.getString().split(",").forEach(t=>{if(t.indexOf('format("svg")')>0){var A=JF(t);A&&new QU(e).load(n,A)}})}}})}})}}UU.parseExternalUrl=JF;class EU extends GQ{constructor(){super(...arguments),this.type="use"}setContext(e){super.setContext(e);var t=this.getAttribute("x"),A=this.getAttribute("y");t.hasValue()&&e.translate(t.getPixels("x"),0),A.hasValue()&&e.translate(0,A.getPixels("y"))}path(e){var{element:t}=this;t&&t.path(e)}renderChildren(e){var{document:t,element:A}=this;if(A){var r=A;if("symbol"===A.type&&((r=new JQ(t,null)).attributes.viewBox=new wQ(t,"viewBox",A.getAttribute("viewBox").getString()),r.attributes.preserveAspectRatio=new wQ(t,"preserveAspectRatio",A.getAttribute("preserveAspectRatio").getString()),r.attributes.overflow=new wQ(t,"overflow",A.getAttribute("overflow").getString()),r.children=A.children,A.styles.opacity=new wQ(t,"opacity",this.calculateOpacity())),"svg"===r.type){var n=this.getStyle("width",!1,!0),i=this.getStyle("height",!1,!0);n.hasValue()&&(r.attributes.width=new wQ(t,"width",n.getString())),i.hasValue()&&(r.attributes.height=new wQ(t,"height",i.getString()))}var s=r.parent;r.parent=this,r.render(e),r.parent=s}}getBoundingBox(e){var{element:t}=this;return t?t.getBoundingBox(e):null}elementTransform(){var{document:e,element:t}=this;return TQ.fromElement(e,t)}get element(){return this.cachedElement||(this.cachedElement=this.getHrefAttribute().getDefinition()),this.cachedElement}}function SU(e,t,A,r,n,i){return e[A*r*4+4*t+i]}function NU(e,t,A,r,n,i,s){e[A*r*4+4*t+i]=s}function LU(e,t,A){return e[t]*A}function IU(e,t,A,r){return t+Math.cos(e)*A+Math.sin(e)*r}class _U extends jQ{constructor(e,t,A){super(e,t,A),this.type="feColorMatrix";var r=WF(this.getAttribute("values").getString());switch(this.getAttribute("type").getString("matrix")){case"saturate":var n=r[0];r=[.213+.787*n,.715-.715*n,.072-.072*n,0,0,.213-.213*n,.715+.285*n,.072-.072*n,0,0,.213-.213*n,.715-.715*n,.072+.928*n,0,0,0,0,0,1,0,0,0,0,0,1];break;case"hueRotate":var i=r[0]*Math.PI/180;r=[IU(i,.213,.787,-.213),IU(i,.715,-.715,-.715),IU(i,.072,-.072,.928),0,0,IU(i,.213,-.213,.143),IU(i,.715,.285,.14),IU(i,.072,-.072,-.283),0,0,IU(i,.213,-.213,-.787),IU(i,.715,-.715,.715),IU(i,.072,.928,.072),0,0,0,0,0,1,0,0,0,0,0,1];break;case"luminanceToAlpha":r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.2125,.7154,.0721,0,0,0,0,0,0,1]}this.matrix=r,this.includeOpacity=this.getAttribute("includeOpacity").hasValue()}apply(e,t,A,r,n){for(var{includeOpacity:i,matrix:s}=this,a=e.getImageData(0,0,r,n),o=0;o<n;o++)for(var l=0;l<r;l++){var c=SU(a.data,l,o,r,0,0),u=SU(a.data,l,o,r,0,1),h=SU(a.data,l,o,r,0,2),d=SU(a.data,l,o,r,0,3),f=LU(s,0,c)+LU(s,1,u)+LU(s,2,h)+LU(s,3,d)+LU(s,4,1),p=LU(s,5,c)+LU(s,6,u)+LU(s,7,h)+LU(s,8,d)+LU(s,9,1),g=LU(s,10,c)+LU(s,11,u)+LU(s,12,h)+LU(s,13,d)+LU(s,14,1),m=LU(s,15,c)+LU(s,16,u)+LU(s,17,h)+LU(s,18,d)+LU(s,19,1);i&&(f=0,p=0,g=0,m*=d/255),NU(a.data,l,o,r,0,0,f),NU(a.data,l,o,r,0,1,p),NU(a.data,l,o,r,0,2,g),NU(a.data,l,o,r,0,3,m)}e.clearRect(0,0,r,n),e.putImageData(a,0,0)}}class kU extends jQ{constructor(){super(...arguments),this.type="mask"}apply(e,t){var{document:A}=this,r=this.getAttribute("x").getPixels("x"),n=this.getAttribute("y").getPixels("y"),i=this.getStyle("width").getPixels("x"),s=this.getStyle("height").getPixels("y");if(!i&&!s){var a=new VQ;this.children.forEach(t=>{a.addBoundingBox(t.getBoundingBox(e))}),r=Math.floor(a.x1),n=Math.floor(a.y1),i=Math.floor(a.width),s=Math.floor(a.height)}var o=this.removeStyles(t,kU.ignoreStyles),l=A.createCanvas(r+i,n+s),c=l.getContext("2d");A.screen.setDefaults(c),this.renderChildren(c),new _U(A,{nodeType:1,childNodes:[],attributes:[{nodeName:"type",value:"luminanceToAlpha"},{nodeName:"includeOpacity",value:"true"}]}).apply(c,0,0,r+i,n+s);var u=A.createCanvas(r+i,n+s),h=u.getContext("2d");A.screen.setDefaults(h),t.render(h),h.globalCompositeOperation="destination-in",h.fillStyle=c.createPattern(l,"no-repeat"),h.fillRect(0,0,r+i,n+s),e.fillStyle=h.createPattern(u,"no-repeat"),e.fillRect(0,0,r+i,n+s),this.restoreStyles(t,o)}render(e){}}kU.ignoreStyles=["mask","transform","clip-path"];var OU=()=>{};class TU extends jQ{constructor(){super(...arguments),this.type="clipPath"}apply(e){var{document:t}=this,A=Reflect.getPrototypeOf(e),{beginPath:r,closePath:n}=e;A&&(A.beginPath=OU,A.closePath=OU),Reflect.apply(r,e,[]),this.children.forEach(r=>{if(void 0!==r.path){var i=void 0!==r.elementTransform?r.elementTransform():null;i||(i=TQ.fromElement(t,r)),i&&i.apply(e),r.path(e),A&&(A.closePath=n),i&&i.unapply(e)}}),Reflect.apply(n,e,[]),e.clip(),A&&(A.beginPath=r,A.closePath=n)}render(e){}}class jU extends jQ{constructor(){super(...arguments),this.type="filter"}apply(e,t){var{document:A,children:r}=this,n=t.getBoundingBox(e);if(n){var i=0,s=0;r.forEach(e=>{var t=e.extraFilterDistance||0;i=Math.max(i,t),s=Math.max(s,t)});var a=Math.floor(n.width),o=Math.floor(n.height),l=a+2*i,c=o+2*s;if(!(l<1||c<1)){var u=Math.floor(n.x),h=Math.floor(n.y),d=this.removeStyles(t,jU.ignoreStyles),f=A.createCanvas(l,c),p=f.getContext("2d");A.screen.setDefaults(p),p.translate(-u+i,-h+s),t.render(p),r.forEach(e=>{"function"==typeof e.apply&&e.apply(p,0,0,l,c)}),e.drawImage(f,0,0,l,c,u-i,h-s,l,c),this.restoreStyles(t,d)}}}render(e){}}jU.ignoreStyles=["filter","transform","clip-path"];class HU extends jQ{constructor(e,t,A){super(e,t,A),this.type="feDropShadow",this.addStylesFromStyleDefinition()}apply(e,t,A,r,n){}}class PU extends jQ{constructor(){super(...arguments),this.type="feMorphology"}apply(e,t,A,r,n){}}class DU extends jQ{constructor(){super(...arguments),this.type="feComposite"}apply(e,t,A,r,n){}}class MU extends jQ{constructor(e,t,A){super(e,t,A),this.type="feGaussianBlur",this.blurRadius=Math.floor(this.getAttribute("stdDeviation").getNumber()),this.extraFilterDistance=this.blurRadius}apply(e,t,A,r,n){var{document:i,blurRadius:s}=this,a=i.window?i.window.document.body:null,o=e.canvas;o.id=i.getUniqueId(),a&&(o.style.display="none",a.appendChild(o)),RF(o,t,A,r,n,s),a&&a.removeChild(o)}}class RU extends jQ{constructor(){super(...arguments),this.type="title"}}class VU extends jQ{constructor(){super(...arguments),this.type="desc"}}var KU={svg:JQ,rect:$Q,circle:ZQ,ellipse:eU,line:tU,polyline:AU,polygon:rU,path:zQ,pattern:nU,marker:iU,defs:sU,linearGradient:lU,radialGradient:cU,stop:uU,animate:hU,animateColor:dU,animateTransform:fU,font:pU,"font-face":gU,"missing-glyph":mU,glyph:qQ,text:WQ,tspan:XQ,tref:vU,a:wU,textPath:yU,image:xU,g:aU,symbol:FU,style:UU,use:EU,mask:kU,clipPath:TU,filter:jU,feDropShadow:HU,feMorphology:PU,feComposite:DU,feColorMatrix:_U,feGaussianBlur:MU,title:RU,desc:VU};function GU(e,t){var A=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),A.push.apply(A,r)}return A}function zU(){return zU=Jv(function*(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],A=document.createElement("img");return t&&(A.crossOrigin="Anonymous"),new Promise((t,r)=>{A.onload=()=>{t(A)},A.onerror=(e,t,A,n,i)=>{r(i)},A.src=e})}),zU.apply(this,arguments)}class qU{constructor(e){var{rootEmSize:t=12,emSize:A=12,createCanvas:r=qU.createCanvas,createImage:n=qU.createImage,anonymousCrossOrigin:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.canvg=e,this.definitions=Object.create(null),this.styles=Object.create(null),this.stylesSpecificity=Object.create(null),this.images=[],this.fonts=[],this.emSizeStack=[],this.uniqueId=0,this.screen=e.screen,this.rootEmSize=t,this.emSize=A,this.createCanvas=r,this.createImage=this.bindCreateImage(n,i),this.screen.wait(this.isImagesLoaded.bind(this)),this.screen.wait(this.isFontsLoaded.bind(this))}bindCreateImage(e,t){return"boolean"==typeof t?(A,r)=>e(A,"boolean"==typeof r?r:t):e}get window(){return this.screen.window}get fetch(){return this.screen.fetch}get ctx(){return this.screen.ctx}get emSize(){var{emSizeStack:e}=this;return e[e.length-1]}set emSize(e){var{emSizeStack:t}=this;t.push(e)}popEmSize(){var{emSizeStack:e}=this;e.pop()}getUniqueId(){return"canvg".concat(++this.uniqueId)}isImagesLoaded(){return this.images.every(e=>e.loaded)}isFontsLoaded(){return this.fonts.every(e=>e.loaded)}createDocumentElement(e){var t=this.createElement(e.documentElement);return t.root=!0,t.addStylesFromStyleDefinition(),this.documentElement=t,t}createElement(e){var t=e.nodeName.replace(/^[^:]+:/,""),A=qU.elementTypes[t];return void 0!==A?new A(this,e):new HQ(this,e)}createTextNode(e){return new YQ(this,e)}setViewBox(e){this.screen.setViewBox(function(e){for(var t=1;t<arguments.length;t++){var A=null!=arguments[t]?arguments[t]:{};t%2?GU(Object(A),!0).forEach(function(t){EC(e,t,A[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(A)):GU(Object(A)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(A,t))})}return e}({document:this},e))}}function WU(e,t){var A=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),A.push.apply(A,r)}return A}function XU(e){for(var t=1;t<arguments.length;t++){var A=null!=arguments[t]?arguments[t]:{};t%2?WU(Object(A),!0).forEach(function(t){EC(e,t,A[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(A)):WU(Object(A)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(A,t))})}return e}qU.createCanvas=function(e,t){var A=document.createElement("canvas");return A.width=e,A.height=t,A},qU.createImage=function(e){return zU.apply(this,arguments)},qU.elementTypes=KU;class YU{constructor(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.parser=new EQ(A),this.screen=new FQ(e,A),this.options=A;var r=new qU(this,A),n=r.createDocumentElement(t);this.document=r,this.documentElement=n}static from(e,t){var A=arguments;return Jv(function*(){var r=A.length>2&&void 0!==A[2]?A[2]:{},n=new EQ(r),i=yield n.parse(t);return new YU(e,i,r)})()}static fromString(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=new EQ(A).parseFromString(t);return new YU(e,r,A)}fork(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return YU.from(e,t,XU(XU({},this.options),A))}forkString(e,t){var A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return YU.fromString(e,t,XU(XU({},this.options),A))}ready(){return this.screen.ready()}isReady(){return this.screen.isReady()}render(){var e=arguments,t=this;return Jv(function*(){var A=e.length>0&&void 0!==e[0]?e[0]:{};t.start(XU({enableRedraw:!0,ignoreAnimation:!0,ignoreMouse:!0},A)),yield t.ready(),t.stop()})()}start(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{documentElement:t,screen:A,options:r}=this;A.start(t,XU(XU({enableRedraw:!0},r),e))}stop(){this.screen.stop()}resize(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,A=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this.documentElement.resize(e,t,A)}}var JU=Object.freeze({__proto__:null,AElement:wU,AnimateColorElement:dU,AnimateElement:hU,AnimateTransformElement:fU,BoundingBox:VQ,CB1:hQ,CB2:dQ,CB3:fQ,CB4:pQ,Canvg:YU,CircleElement:ZQ,ClipPathElement:TU,DefsElement:sU,DescElement:VU,Document:qU,Element:jQ,EllipseElement:eU,FeColorMatrixElement:_U,FeCompositeElement:DU,FeDropShadowElement:HU,FeGaussianBlurElement:MU,FeMorphologyElement:PU,FilterElement:jU,Font:RQ,FontElement:pU,FontFaceElement:gU,GElement:aU,GlyphElement:qQ,GradientElement:oU,ImageElement:xU,LineElement:tU,LinearGradientElement:lU,MarkerElement:iU,MaskElement:kU,Matrix:IQ,MissingGlyphElement:mU,Mouse:yQ,PSEUDO_ZERO:oQ,Parser:EQ,PathElement:zQ,PathParser:KQ,PatternElement:nU,Point:BQ,PolygonElement:rU,PolylineElement:AU,Property:wQ,QB1:gQ,QB2:mQ,QB3:vQ,RadialGradientElement:cU,RectElement:$Q,RenderedElement:GQ,Rotate:NQ,SVGElement:JQ,SVGFontLoader:QU,Scale:LQ,Screen:FQ,Skew:_Q,SkewX:kQ,SkewY:OQ,StopElement:uU,StyleElement:UU,SymbolElement:FU,TRefElement:vU,TSpanElement:XQ,TextElement:WQ,TextPathElement:yU,TitleElement:RU,Transform:TQ,Translate:SQ,UnknownElement:HQ,UseElement:EU,ViewPort:bQ,compressSpaces:GF,default:YU,getSelectorSpecificity:aQ,normalizeAttributeName:YF,normalizeColor:$F,parseExternalUrl:JF,presets:KF,toNumbers:WF,trimLeft:zF,trimRight:qF,vectorMagnitude:lQ,vectorsAngle:uQ,vectorsRatio:cQ});exports.ComponentActionFeatures=H,exports.ComponentSubmissionActions=D,exports.DfFormCheckbox=E,exports.DfFormComments=({comment:t="",onSave:A,placeholder:r="Enter your reason...",className:n="",disabled:i=!1})=>{const[s,a]=e.useState(!0),[o,l]=e.useState(t),[c,u]=e.useState(!1);e.useEffect(()=>{l(t),u(!1)},[t]);const h=e.useCallback(e=>{const A=e.target.value;l(A),u(A!==t)},[t]),d=e.useCallback(()=>{c&&A&&!i&&(A(o),u(!1))},[c,A,o,i]),f=e.useCallback(()=>{},[]),g=e.useCallback(()=>{i||a(!s)},[s,i]);return p.jsxs("div",{className:`df-form-comments ${n}`,children:[p.jsxs("div",{className:"df-form-comments__header",children:[p.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),p.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:g,"aria-expanded":s,"aria-label":"Toggle comments section",disabled:i,children:s?p.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):p.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),p.jsx("div",{className:"df-form-comments__content "+(s?"df-form-comments__content--expanded":""),children:p.jsx("div",{className:"df-form-comments__input-container",children:p.jsx("div",{className:"df-form-comments__input-line",children:p.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:o,onChange:h,onBlur:d,onFocus:f,placeholder:r,disabled:i})})})})]})},exports.DfFormDataGrid=z,exports.DfFormDateTime=L,exports.DfFormErrorMsg=w,exports.DfFormFileUpload=_,exports.DfFormHeading=O,exports.DfFormInput=F,exports.DfFormInstruction=T,exports.DfFormLocation=k,exports.DfFormPreview=({formComponents:t=[],currentDevice:A="desktop",isPreviewMode:r=!1,initialFormData:n=[],onSubmit:i,onFormDataChange:s,formTitle:a,formDescription:o,formTemplateId:l,onComponentSelect:c,onComponentDelete:u,onComponentEdit:h,onComponentUpdate:d,selectedComponent:f,workOrderNumber:g,assetNumber:w,isStandalone:b,user:B,onCreateIssue:y,onUpdateIssue:C})=>{const[x,j]=e.useState({}),[P,M]=e.useState({}),[V,K]=e.useState(!1),[G,W]=e.useState({}),[X,Y]=e.useState({}),[J,$]=e.useState(new Set),[Z,ee]=e.useState(new Map),[te,Ae]=e.useState({isValid:!0}),[re,ne]=e.useState({}),[ie,se]=e.useState({});e.useEffect(()=>{oe()},[t,n]);const ae=(e,t)=>{e.forEach(e=>{if(e.id&&(void 0!==t[e.id]||(e.basic&&"value"in e.basic&&void 0!==e.basic.value&&""!==e.basic.value&&null!==e.basic.value?t[e.id]=e.basic.value:e.basic&&"defaultValue"in e.basic&&void 0!==e.basic.defaultValue&&""!==e.basic.defaultValue&&null!==e.basic.defaultValue?t[e.id]=e.basic.defaultValue:"checkbox"===e.name||"select"===e.name?t[e.id]=[]:t[e.id]="")),e.cells&&Array.isArray(e.cells)&&e.cells.forEach((e,A)=>{Array.isArray(e)&&e.forEach((e,A)=>{e&&e.components&&Array.isArray(e.components)&&ae(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,A)=>{e&&e.components&&Array.isArray(e.components)&&ae(e.components,t)}),"file"===e.name&&e.basic){const A=e.basic.files||e.basic.attachments||e.basic.value;A&&(t[e.id]=A)}if(e.id&&e.basic&&e.basic.notes,"instructions"===e.name&&e.basic){e.basic.instructions||(e.basic.instructions=[]);const A=e.basic.value||e.basic.instructions;A&&(t[e.id]=A)}e.children&&Array.isArray(e.children)&&ae(e.children,t)})},oe=e.useCallback(()=>{const e={},A={},r={},i=new Set,s=e=>{e.forEach(e=>{var t,n,i,a,o;e.id&&(((null===(t=e.basic)||void 0===t?void 0:t.notes)||(null===(n=e.basic)||void 0===n?void 0:n.comments))&&(A[e.id]=(null===(i=e.basic)||void 0===i?void 0:i.notes)||(null===(a=e.basic)||void 0===a?void 0:a.comments)),(null===(o=e.basic)||void 0===o?void 0:o.attachments)&&(r[e.id]=e.basic.attachments)),e.children&&s(e.children),e.cells&&e.cells.forEach(e=>e.forEach(e=>{e.components&&s(e.components)})),e.entries&&e.entries.forEach(e=>{e.components&&s(e.components)})})},a=e=>{e.forEach((e,t)=>{var A;if(e.id&&"string"==typeof e.id&&""!==e.id.trim())i.has(e.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${e.id}. Component:`,e),e.id=`${e.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${e.id}`));else{const r=e.name||"component",n=((null===(A=e.basic)||void 0===A?void 0:A.label)||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);e.id=`${r}-${n||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${t}`}i.add(e.id),e.children&&Array.isArray(e.children)&&a(e.children),e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&a(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&a(e.components)})})};t&&t.length>0&&a(t),n&&n.length>0&&a(n),n&&n.length>0&&ae(n,e),n&&n.length>0&&ae(n,e),t&&t.length>0&&(ae(t,e),s(t)),j(t=>Object.assign(Object.assign({},e),t)),ne(e=>Object.assign(Object.assign({},A),e)),se(e=>Object.assign(Object.assign({},r),e)),ce()},[n,t]),le=(e,A)=>{e.forEach(e=>{if(e.id)if("table"===e.name||"datagrid"===e.name)A[e.id]=!0;else if(e.conditional){const r=m.evaluateConditionalLogic(e.conditional,t,x);A[e.id]=r.shouldShow}else A[e.id]=!0;e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{e.forEach(e=>{e.components&&Array.isArray(e.components)&&le(e.components,A)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&le(e.components,A)}),e.children&&Array.isArray(e.children)&&le(e.children,A)})},ce=e.useCallback(()=>{const e={};t&&t.length>0&&le(t,e),Y(e)},[t,x]),ue=e.useCallback(e=>{const A=t.find(t=>t.id===e);if(A&&("table"===A.name||"datagrid"===A.name))return!0;return!1!==X[e]},[X,t]),he=e.useCallback(e=>{if(!e.id||"string"!=typeof e.id||""===e.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",e);const A=t.filter(t=>t.id===e.id);if(A.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${e.id}":`,A.map(e=>{var t;return{id:e.id,name:e.name,label:null===(t=e.basic)||void 0===t?void 0:t.label}}));const n=x[e.id];void 0!==n&&n!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:n,newValue:e.value});const i=Object.assign(Object.assign({},x),{[e.id]:e.value});j(i);const a=t.find(t=>t.id===e.id);if(a){const e=null==a?void 0:a.threshold;e&&e.conditions&&e.conditions.length>0&&$(t=>{const A=new Set(t);return e.conditions.forEach(e=>{A.delete(e.id)}),A})}const o=t=>t.map(t=>{var A;return t.id===e.id&&"defaultValue"in t.basic?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{value:null!==(A=e.value)&&void 0!==A?A:t.basic.defaultValue,defaultValue:e.value})}):"section"===t.name&&t.children?Object.assign(Object.assign({},t),{children:o(t.children)}):"table"===t.name&&t.cells?Object.assign(Object.assign({},t),{cells:t.cells.map(e=>e.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=o(t.components)),t}))}):"datagrid"===t.name&&t.entries?Object.assign(Object.assign({},t),{entries:t.entries.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=o(t.components)),t})}):t}),l=o(t);if(null==s||s(l),P[e.id]&&M(t=>Object.assign(Object.assign({},t),{[e.id]:""})),!r){if(e.isValid)return void M(t=>{const A=t[e.id];return A&&""!==A.trim()?Object.assign(Object.assign({},t),{[e.id]:""}):t});setTimeout(()=>{fe(e.id)},150)}setTimeout(()=>{const e={};t.forEach(A=>{if("table"===A.name||"datagrid"===A.name)e[A.id]=!0;else if(A.conditional){const r=m.evaluateConditionalLogic(A.conditional,t,i);e[A.id]=r.shouldShow}else e[A.id]=!0}),Y(e)},0)},[t,x,P,s]),de=e.useCallback((e,t)=>{for(const A of e){if(A.id===t)return A;if("section"===A.name&&A.children){const e=de(A.children,t);if(e)return e}if("table"===A.name&&A.cells)for(const e of A.cells)for(const A of e)if(A.components){const e=de(A.components,t);if(e)return e}if("datagrid"===A.name&&A.entries)for(const e of A.entries)if(e.components){const A=de(e.components,t);if(A)return A}}return null},[]),fe=e.useCallback(e=>{if(r)return;const A=de(t,e);if(!A)return;const n=x[e]||"";if("number-input"===A.name&&(!n||""===n)){if(A.validation.required){const t=A.validation.customValidationMessage,r=A.basic.label||"This field",n=t||`${r} is required`;M(t=>Object.assign(Object.assign({},t),{[e]:n}))}else M(t=>Object.assign(Object.assign({},t),{[e]:""}));return}let i=!1;i=Array.isArray(n)?n.length>0:"string"==typeof n?""!==n.trim():null!=n;let s="";if(A.validation.required&&!i){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} is required`}else if("email-input"===A.name&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} must be a valid email`}else if(A.validation.minLength&&i&&n.length<A.validation.minLength){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} must be at least ${A.validation.minLength} characters`}else if(A.validation.maxLength&&i&&n.length>A.validation.maxLength){const e=A.validation.customValidationMessage,t=A.basic.label||"This field";s=e||`${t} must be no more than ${A.validation.maxLength} characters`}else if("number-input"===A.name&&i){const e=String(n).trim(),t=parseFloat(e);if(!isNaN(t)){const e=A.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&t<e.lowerLimit?s="Number is below the lower limit":e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&t>e.upperLimit&&(s="Number is above the upper limit")}}M(t=>Object.assign(Object.assign({},t),{[e]:s}))},[t,r,x,de]),pe=e.useCallback(e=>{W(t=>Object.assign(Object.assign({},t),{[e]:!0})),r||setTimeout(()=>{fe(e)},0)},[r,fe]),ge=e.useCallback(e=>{P[e]&&M(t=>Object.assign(Object.assign({},t),{[e]:""}))},[P]),me=e.useCallback(()=>!Object.values(P).some(e=>e&&"string"==typeof e&&""!==e.trim())&&t.every(e=>{const t=x[e.id]||"";let A=!1;if(A=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!A)return!1;if("number-input"===e.name&&A){const A=String(t).trim(),r=parseFloat(A);if(!isNaN(r)){const t=e.validation;if(t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&r<t.lowerLimit)return!1;if(t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&r>t.upperLimit)return!1}}return!0}),[t,x,P]),ve=e.useCallback((e,t)=>{if(Array.isArray(t))return t.some(t=>ve(e,t));if(null==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))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}const n=String(t).toLowerCase(),i=String(e.value).toLowerCase();switch(e.operator){case"equals":return n===i||String(t)===String(e.value);case"notEquals":return n!==i&&String(t)!==String(e.value);default:return!1}},[]),we=e.useCallback(()=>{if(r)return[];const e=[];return t.forEach(t=>{const A=null==t?void 0:t.condition;if(!A||!A.conditions||0===A.conditions.length)return;const r=x[t.id];null!=r&&""!==r&&!(Array.isArray(r)&&0===r.length)&&A.conditions.forEach(A=>{var n;ve(A,r)&&e.push({componentId:t.id,condition:A,componentLabel:(null===(n=t.basic)||void 0===n?void 0:n.label)||"Field"})})}),e},[t,x,r,ve]),be=e.useCallback(()=>{if(r)return{isValid:!0};const e=we();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:A}of e){const e=Z.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},r=[];if(!0!==t.enableRaiseIssue||J.has(t.id)||r.push("raise an issue"),!0!==t.enableNotes||e.notesCompleted||r.push("add notes"),!0!==t.enableAttachment||e.attachmentsCompleted||r.push("add attachments"),!0!==t.enableSendEmail||e.emailSent||r.push("send email"),r.length>0){return{isValid:!1,errorMessage:`Please ${1===r.length?r[0]:r.slice(0,-1).join(", ")+" and "+r[r.length-1]} for the threshold condition met in "${A}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[r,we,J,Z]),Be=e.useCallback(e=>{e&&$(t=>{const A=new Set(t);return A.add(e),A})},[]),ye=e.useCallback((e,t,A)=>{e&&ee(r=>{const n=new Map(r),i=n.get(e)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===t?n.set(e,Object.assign(Object.assign({},i),{notesCompleted:A})):"attachments"===t?n.set(e,Object.assign(Object.assign({},i),{attachmentsCompleted:A})):"email"===t&&n.set(e,Object.assign(Object.assign({},i),{emailSent:A})),n})},[]);e.useEffect(()=>{if(!r){const e=be();Ae(e)}},[x,J,Z,r,be]);const Ce=e.useCallback(()=>{if(r)return!0;let e=!0;K(!0);const A={};return t.forEach(t=>{const r=x[t.id]||"";let n=!1;if(n=Array.isArray(r)?r.length>0:"string"==typeof r?""!==r.trim():null!=r,t.validation.required&&!n){const r=t.validation.customValidationMessage,n=t.basic.label||"This field",i=r||`${n} is required`;A[t.id]=i,e=!1}else if("number-input"===t.name&&n){const n=String(r).trim(),i=parseFloat(n);if(isNaN(i))A[t.id]="";else{const r=t.validation;r&&"lowerLimit"in r&&void 0!==r.lowerLimit&&null!==r.lowerLimit&&0!==r.lowerLimit&&i<r.lowerLimit?(A[t.id]="Number is below the lower limit",e=!1):r&&"upperLimit"in r&&void 0!==r.upperLimit&&null!==r.upperLimit&&0!==r.upperLimit&&i>r.upperLimit?(A[t.id]="Number is above the upper limit",e=!1):A[t.id]=""}}else A[t.id]="";W(e=>Object.assign(Object.assign({},e),{[t.id]:!0}))}),M(A),e},[t,r,x]),xe=e.useCallback((e="Submitted")=>{if(K(!0),!Ce()){const e=t.find(e=>{const t=x[e.id]||"";let A=!1;return A=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!A});if(e){const t=document.getElementById(e.id);t&&t.focus()}return}const A=be();if(!A.isValid){A.errorMessage&&v.showError(A.errorMessage);const e=we().find(({condition:e})=>!J.has(e.id));if(e){const t=document.getElementById(e.componentId);t&&t.scrollIntoView({behavior:"smooth",block:"center"})}return}const r=e=>e.map(e=>{var t,A,n,i,s,a;let o=x[e.id];"text-input"===e.name&&(null===(t=e.basic)||void 0===t||t.label),void 0===o&&(o="value"in e.basic&&void 0!==e.basic.value?e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?e.basic.defaultValue:""),"text-input"===e.name&&(null===(A=e.basic)||void 0===A||A.label);const l=Object.assign(Object.assign({},e),{basic:Object.assign(Object.assign({},e.basic),{value:o,defaultValue:o,notes:void 0!==re[e.id]?re[e.id]:null===(n=e.basic)||void 0===n?void 0:n.notes,comments:void 0!==re[e.id]?re[e.id]:(null===(i=e.basic)||void 0===i?void 0:i.comments)||(null===(s=e.basic)||void 0===s?void 0:s.notes),attachments:void 0!==ie[e.id]?ie[e.id]:null===(a=e.basic)||void 0===a?void 0:a.attachments})});return"section"===l.name&&l.children&&(l.children=r(l.children)),"table"===l.name&&l.cells&&(l.cells=l.cells.map(e=>e.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=r(t.components)),t}))),"datagrid"===l.name&&l.entries&&(l.entries=l.entries.map(e=>{const t=Object.assign({},e);return t.components&&(t.components=r(t.components)),t})),l}),n=r(t),s=Object.assign(Object.assign({},x),{status:e});null==i||i(n,s)},[t,x,Ce,i,re,ie]),Fe=e.useCallback(()=>({[`device-${A}`]:!0,readonly:r}),[A,r]),Qe=e.useCallback((e,t)=>{ne(A=>Object.assign(Object.assign({},A),{[e]:t}))},[]),Ue=e.useCallback((e,t)=>{se(A=>Object.assign(Object.assign({},A),{[e]:t||[]}))},[]),Ee=e.useRef(new Map),Se=e.useRef(0),Ne=A=>{var r,n,i,a,o,m,v,b,H,D,M,K,W;let X;if(A.id&&"string"==typeof A.id&&""!==A.id.trim())X=A.id;else{const e=(null===(r=A.basic)||void 0===r?void 0:r.label)||"",t=A.name||"unknown",n=`${t}-${e}`;let i=Ee.current.get(n);i||(Se.current+=1,i=`generated-${t}-${Se.current}-${Math.random().toString(36).substr(2,9)}`,Ee.current.set(n,i),console.warn("[DfFormPreview] Generated and cached ID for component:",i,"key:",n)),X=i,A=Object.assign(Object.assign({},A),{id:X})}const Y=X,$=x[Y];if(void 0!==$){const e=t.filter(e=>e.id!==Y&&x[e.id]===$);e.length>0&&console.warn(`[DfFormPreview] Component ${Y} shares form value with other components:`,e.map(e=>e.id))}const Z={id:Y,validationErrors:P,formValue:$,touchedFields:G,formSubmitted:V,mode:"test",readonly:!1,onValueChange:he,onBlur:()=>pe(Y),onFocus:()=>ge(Y)};switch(A.name){case"text-input":case"number-input":case"email-input":return p.jsx(F,Object.assign({},Z,{properties:A,inputType:"text-input"===A.name?"text":"number-input"===A.name?"number":"email",formTemplateId:l,onThresholdIssueRaised:Be,raisedThresholdIssues:J,workOrderNumber:g,assetNumber:w,user:B}));case"textarea":return p.jsx(Q,Object.assign({},Z,{properties:A}));case"select":const r=Object.assign(Object.assign({},A),{options:(null===(n=A.basic)||void 0===n?void 0:n.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(i=A.basic)||void 0===i?void 0:i.comments)||""})});return p.jsx(U,Object.assign({},Z,{properties:r}));case"checkbox":const X=Object.assign(Object.assign({},A),{options:(null===(a=A.basic)||void 0===a?void 0:a.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(o=A.basic)||void 0===o?void 0:o.comments)||""})});return p.jsx(E,Object.assign({},Z,{properties:X}));case"radio":const Y=Object.assign(Object.assign({},A),{options:(null===(m=A.basic)||void 0===m?void 0:m.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(v=A.basic)||void 0===v?void 0:v.comments)||""})});return p.jsx(S,Object.assign({},Z,{properties:Y}));case"segment":const ee=Object.assign(Object.assign({},A),{options:(null===(b=A.basic)||void 0===b?void 0:b.options)||[],basic:Object.assign(Object.assign({},A.basic),{comments:(null===(H=A.basic)||void 0===H?void 0:H.comments)||""})});return p.jsx(N,Object.assign({},Z,{properties:ee}));case"date":case"date-picker":case"datetime-picker":return p.jsx(L,Object.assign({},Z,{properties:A}));case"signature":return p.jsx(I,Object.assign({},Z,{properties:A}));case"heading":return p.jsx(O,Object.assign({},Z,{properties:A}));case"instructions":const te=$||(null===(D=A.basic)||void 0===D?void 0:D.value)||null;return p.jsx(T,Object.assign({},Z,{properties:A,formValue:te}));case"location":return p.jsx(k,Object.assign({},Z,{properties:A}));case"section":return p.jsx(R,Object.assign({},Z,{properties:A,formData:x,formTemplateId:l,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,onNotesChange:Qe,onAttachmentChange:Ue,workOrderNumber:g,assetNumber:w,user:B,onCreateIssue:y,onUpdateIssue:C,renderFormComponent:e=>Ne(e)}));case"table":return p.jsx(e.Suspense,{fallback:p.jsx("div",{children:"Loading table..."}),children:p.jsx(q,Object.assign({},Z,{properties:A,formData:x,formTemplateId:l,mode:Z.mode,validationErrors:P,touchedFields:G,formSubmitted:V,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,workOrderNumber:g,assetNumber:w,onCreateIssue:y,onUpdateIssue:C,onNotesChange:(e,r)=>{const n=t.map(t=>{if(t.id===A.id&&t.cells){const A=t.cells.map(t=>t.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{notes:r})}):t);return Object.assign(Object.assign({},t),{components:A})}return t}));return Object.assign(Object.assign({},t),{cells:A})}return t});null==s||s(n)},onAttachmentChange:(e,r)=>{const n=t.map(t=>{if(t.id===A.id&&t.cells){const A=t.cells.map(t=>t.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{attachments:r||[]})}):t);return Object.assign(Object.assign({},t),{components:A})}return t}));return Object.assign(Object.assign({},t),{cells:A})}return t});null==s||s(n)},renderFormComponent:e=>Ne(e)}))});case"datagrid":return p.jsx(z,Object.assign({},Z,{properties:A,formData:x,formTemplateId:l,mode:Z.mode,validationErrors:P,touchedFields:G,formSubmitted:V,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,workOrderNumber:g,assetNumber:w,user:B,onComponentSelect:c,onComponentDelete:u,onComponentEdit:h,onCreateIssue:y,onUpdateIssue:C,onComponentUpdate:d,selectedComponent:f,onNotesChange:(e,r)=>{Qe(e,r);const n=t.map(t=>{if(t.id===A.id&&t.entries){const A=t.entries.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{notes:r||""})}):t);return Object.assign(Object.assign({},t),{components:A})}return t});return Object.assign(Object.assign({},t),{entries:A})}return t});null==s||s(n)},onAttachmentChange:(e,r)=>{Ue(e,r);const n=t.map(t=>{if(t.id===A.id&&t.entries){const A=t.entries.map(t=>{if(t.components){const A=t.components.map(t=>t.id===e?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{attachments:r||[]})}):t);return Object.assign(Object.assign({},t),{components:A})}return t});return Object.assign(Object.assign({},t),{entries:A})}return t});null==s||s(n)},onValueChange:e=>{if(e.id===A.id&&e.value&&"object"==typeof e.value&&"entries"in e.value){const r=t.map(t=>t.id===A.id?Object.assign(Object.assign({},t),e.value):t);null==s||s(r),e.value.entries&&Array.isArray(e.value.entries)&&e.value.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&e.components.forEach(e=>{var t;if(void 0!==x[e.id]);else{const A=null===(t=e.basic)||void 0===t?void 0:t.defaultValue;void 0!==A&&j(t=>Object.assign(Object.assign({},t),{[e.id]:A}))}})})}else he(e)},onEntryAdd:()=>{const e=t.find(e=>e.id===A.id);if(e&&e.entries){const e=t.map(e=>e.id===A.id?Object.assign(Object.assign({},e),{entries:e.entries||[]}):e);null==s||s(e)}else setTimeout(()=>{const e=x[A.id];if(e&&"object"==typeof e&&"entries"in e){const r=t.map(t=>t.id===A.id?Object.assign(Object.assign({},t),{entries:e.entries}):t);null==s||s(r)}},100)},onEntryRemove:e=>{const r=t.map(t=>{if(t.id===A.id&&t.entries){const A=(t.entries||[]).filter((t,A)=>A!==e).map((e,A)=>{var r;return Object.assign(Object.assign({},e),{index:A,id:`entry-${t.id}-${A}`,components:(null===(r=e.components)||void 0===r?void 0:r.map((e,t)=>{const r=(e.templateComponents||[])[t];return Object.assign(Object.assign({},e),{id:r?`${r.id}-entry-${A}-${t}`:e.id})}))||[]})});return Object.assign(Object.assign({},t),{entries:A})}return t});null==s||s(r)},renderFormComponent:e=>Ne(e)}));case"file":const Ae=$||(null===(M=A.basic)||void 0===M?void 0:M.value)||(null===(K=A.basic)||void 0===K?void 0:K.files)||(null===(W=A.basic)||void 0===W?void 0:W.attachments)||null;return p.jsx(_,Object.assign({},Z,{properties:A,formValue:Ae}));default:return p.jsx("div",{className:"form-group",children:p.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",A.name]})})}};return p.jsx("div",{className:"form-preview-container",children:p.jsx("div",{className:"form-preview-wrapper",children:p.jsxs("div",{className:`form-preview ${Object.entries(Fe()).map(([e,t])=>t?e:"").join(" ")}`,children:[p.jsx("div",{className:"form-canvas-header"}),0===t.length?p.jsx("div",{className:"empty-state",children:p.jsx("div",{className:"empty-state-card",children:p.jsx("div",{className:"empty-state-preview-area",children:p.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):p.jsxs("form",{className:"form-preview-form",onSubmit:e=>{e.preventDefault(),xe()},children:[(a||o)&&p.jsxs("div",{className:"form-header",children:[a&&p.jsx("h1",{className:"form-title",children:a}),o&&p.jsx("p",{className:"form-description",children:o})]}),t.map(e=>{var A,n,i,a;const o=e.basic,c=x[e.id],u=["select","radio","checkbox","segment"].includes(e.name||""),h=e.options||(null==o?void 0:o.options)||[],d=(()=>{var t;const A=null===(t=null==e?void 0:e.styles)||void 0===t?void 0:t.column;return"section"===e.name||"table"===e.name||"datagrid"===e.name?"col-12":3===A?"col-3":6===A?"col-6":9===A?"col-9":"col-12"})();let f=!1;if(!r)if(u&&null!=c&&""!==c)if("checkbox"===e.name){f=(Array.isArray(c)?c:[c]).some(e=>{const t=h.find(t=>t.value===e);return t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)})}else{const e=h.find(e=>e.value===c);f=e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)}else f=(null==o?void 0:o.enableNotes)||(null==o?void 0:o.enableAttachment)||(null==o?void 0:o.enableRaiseIssue)||(null==o?void 0:o.enableSendEmail);const m=r&&((null===(A=e.basic)||void 0===A?void 0:A.notes)&&e.basic.notes.trim().length>0||(null===(n=e.basic)||void 0===n?void 0:n.attachments)&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return p.jsxs("div",{className:`form-group ${d} ${f||m?"has-action-features":""}`,style:{display:ue(e.id)?"block":"none"},children:[Ne(e),!r&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&p.jsx(H,{component:e,mode:r?"preview":"test",formTemplateId:l,formValue:c,onThresholdActionCompletion:ye,onThresholdIssueRaised:Be,onNotesChange:A=>{ne(t=>Object.assign(Object.assign({},t),{[e.id]:A}));const r=t.map(t=>t.id===e.id?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{notes:A||""})}):t);null==s||s(r)},onAttachmentChange:A=>{se(t=>Object.assign(Object.assign({},t),{[e.id]:A||[]}));const r=t.map(t=>t.id===e.id?Object.assign(Object.assign({},t),{basic:Object.assign(Object.assign({},t.basic),{attachments:A||[]})}):t);null==s||s(r)},notes:void 0!==re[e.id]?re[e.id]:(null===(i=e.basic)||void 0===i?void 0:i.notes)||"",attachments:void 0!==ie[e.id]?ie[e.id]:(null===(a=e.basic)||void 0===a?void 0:a.attachments)||null,workOrderNumber:g,assetNumber:w,isStandalone:b,user:B,onCreateIssue:y,onUpdateIssue:C}),r&&m&&p.jsx(D,{component:e})]},e.id)}),!r&&p.jsxs("div",{className:"form-actions",children:[p.jsx("button",{type:"button",onClick:()=>xe("Saved"),className:"form-save-button",disabled:V&&!me(),children:"Save"}),p.jsx("button",{type:"button",disabled:!me()||!te.isValid,className:"form-submit-button",title:te.isValid?"":te.errorMessage,onClick:()=>xe("Submitted"),children:"Submit"})]})]})]})})})},exports.DfFormRadio=S,exports.DfFormSection=R,exports.DfFormSegment=N,exports.DfFormSelect=U,exports.DfFormSignature=I,exports.DfFormTable=$,exports.DfFormTextarea=Q,exports.FormSubmissionPdf=oe,exports.RaiseIssueModal=C,exports.ThresholdAlert=x,exports.conditionalLogicService=m,exports.generateFormPdf=e=>b(void 0,void 0,void 0,function*(){return new Promise((t,A)=>b(void 0,void 0,void 0,function*(){let r=null,n=null;try{r=document.createElement("div"),r.style.position="absolute",r.style.top="-9999px",r.style.left="-9999px",r.style.width="794px",r.style.backgroundColor="#ffffff",r.style.zIndex="-1000",document.body.appendChild(r),n=le(r),n.render(p.jsx(oe,{formTitle:e.formTitle,formDescription:e.formDescription,userName:e.userName,components:e.components})),yield new Promise(e=>setTimeout(e,1e3));const A=yield fe(r,{scale:2,useCORS:!0,logging:!1,backgroundColor:"#ffffff",windowWidth:794}),i=A.toDataURL("image/jpeg",.95),s=new Xi({orientation:"portrait",unit:"mm",format:"a4"}),a=210,o=297,l=A.height*a/A.width;let c=l,u=0;for(s.addImage(i,"JPEG",0,u,a,l),c-=o;c>0;)u-=o,s.addPage(),s.addImage(i,"JPEG",0,u,a,l),c-=o;const h=s.output("blob");t(h)}catch(e){console.error("Error generating PDF:",e),A(e)}finally{n&&setTimeout(()=>{n.unmount(),r&&r.parentNode&&r.parentNode.removeChild(r)},100)}}))}),exports.toastService=v;
365
365
  //# sourceMappingURL=index.js.map