df-ae-forms-package 1.0.31 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -7,5 +7,5 @@ import e,{useState as t,useEffect as n,useCallback as i,useRef as r,useMemo as s
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */"production"===process.env.NODE_ENV?q.exports=function(){if(M)return P;M=1;var t=e,n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,s=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,i){var a,l={},c=null,d=null;for(a in void 0!==i&&(c=""+i),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(d=t.ref),t)r.call(t,a)&&!o.hasOwnProperty(a)&&(l[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===l[a]&&(l[a]=t[a]);return{$$typeof:n,type:e,key:c,ref:d,props:l,_owner:s.current}}return P.Fragment=i,P.jsx=a,P.jsxs=a,P}():q.exports=(W||(W=1,"production"!==process.env.NODE_ENV&&function(){var t,n=e,i=Symbol.for("react.element"),r=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),c=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),f=Symbol.for("react.offscreen"),g=Symbol.iterator,b=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];!function(e,t,n){var i=b.ReactDebugCurrentFrame.getStackAddendum();""!==i&&(t+="%s",n=n.concat([i]));var r=n.map(function(e){return String(e)});r.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,r)}("error",e,n)}function y(e){return e.displayName||"Context"}function v(e){if(null==e)return null;if("number"==typeof e.tag&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case s:return"Fragment";case r:return"Portal";case a:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case m:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case c:return y(e)+".Consumer";case l:return y(e._context)+".Provider";case d:return function(e,t,n){var i=e.displayName;if(i)return i;var r=t.displayName||t.name||"";return""!==r?n+"("+r+")":n}(e,e.render,"ForwardRef");case p:var t=e.displayName||null;return null!==t?t:v(e.type)||"Memo";case h:var n=e,i=n._payload,f=n._init;try{return v(f(i))}catch(e){return null}}return null}t=Symbol.for("react.module.reference");var j,N,C,w,S,k,$,A=Object.assign,E=0;function T(){}T.__reactDisabledLog=!0;var L,I=b.ReactCurrentDispatcher;function R(e,t,n){if(void 0===L)try{throw Error()}catch(e){var i=e.stack.trim().match(/\n( *(at )?)/);L=i&&i[1]||""}return"\n"+L+e}var D,V=!1,F="function"==typeof WeakMap?WeakMap:Map;function O(e,t){if(!e||V)return"";var n,i=D.get(e);if(void 0!==i)return i;V=!0;var r,s=Error.prepareStackTrace;Error.prepareStackTrace=void 0,r=I.current,I.current=null,function(){if(0===E){j=console.log,N=console.info,C=console.warn,w=console.error,S=console.group,k=console.groupCollapsed,$=console.groupEnd;var e={configurable:!0,enumerable:!0,value:T,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}E++}();try{if(t){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(o,[])}catch(e){n=e}Reflect.construct(e,[],o)}else{try{o.call()}catch(e){n=e}e.call(o.prototype)}}else{try{throw Error()}catch(e){n=e}e()}}catch(t){if(t&&n&&"string"==typeof t.stack){for(var a=t.stack.split("\n"),l=n.stack.split("\n"),c=a.length-1,d=l.length-1;c>=1&&d>=0&&a[c]!==l[d];)d--;for(;c>=1&&d>=0;c--,d--)if(a[c]!==l[d]){if(1!==c||1!==d)do{if(c--,--d<0||a[c]!==l[d]){var u="\n"+a[c].replace(" at new "," at ");return e.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,u),u}}while(c>=1&&d>=0);break}}}finally{V=!1,I.current=r,function(){if(0===--E){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:A({},e,{value:j}),info:A({},e,{value:N}),warn:A({},e,{value:C}),error:A({},e,{value:w}),group:A({},e,{value:S}),groupCollapsed:A({},e,{value:k}),groupEnd:A({},e,{value:$})})}E<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=s}var m=e?e.displayName||e.name:"",p=m?R(m):"";return"function"==typeof e&&D.set(e,p),p}function z(e,t,n){if(null==e)return"";if("function"==typeof e)return O(e,!(!(i=e.prototype)||!i.isReactComponent));var i;if("string"==typeof e)return R(e);switch(e){case u:return R("Suspense");case m:return R("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case d:return O(e.render,!1);case p:return z(e.type,t,n);case h:var r=e,s=r._payload,o=r._init;try{return z(o(s),t,n)}catch(e){}}return""}D=new F;var M=Object.prototype.hasOwnProperty,q={},P=b.ReactDebugCurrentFrame;function W(e){if(e){var t=e._owner,n=z(e.type,e._source,t?t.type:null);P.setExtraStackFrame(n)}else P.setExtraStackFrame(null)}var B=Array.isArray;function U(e){return B(e)}function G(e){return""+e}function H(e){if(function(e){try{return G(e),!1}catch(e){return!0}}(e))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),G(e)}var J,Y,K,X=b.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,n,r,s){var o,a={},l=null,c=null;for(o in void 0!==n&&(H(n),l=""+n),function(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(H(t.key),l=""+t.key),function(e){if(M.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e,t){if("string"==typeof e.ref&&X.current&&t&&X.current.stateNode!==t){var n=v(X.current.type);K[n]||(x('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',v(X.current.type),e.ref),K[n]=!0)}}(t,s)),t)M.call(t,o)&&!Z.hasOwnProperty(o)&&(a[o]=t[o]);if(e&&e.defaultProps){var d=e.defaultProps;for(o in d)void 0===a[o]&&(a[o]=d[o])}if(l||c){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;l&&function(e,t){var n=function(){J||(J=!0,x("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(a,u),c&&function(e,t){var n=function(){Y||(Y=!0,x("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}(a,u)}return function(e,t,n,r,s,o,a){var l={$$typeof:i,type:e,key:t,ref:n,props:a,_owner:o,_store:{}};return Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:r}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l}(e,l,c,s,r,X.current,a)}K={};var ee,te=b.ReactCurrentOwner,ne=b.ReactDebugCurrentFrame;function ie(e){if(e){var t=e._owner,n=z(e.type,e._source,t?t.type:null);ne.setExtraStackFrame(n)}else ne.setExtraStackFrame(null)}function re(e){return"object"==typeof e&&null!==e&&e.$$typeof===i}function se(){if(te.current){var e=v(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var oe={};function ae(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var n=function(e){var t=se();if(!t){var n="string"==typeof e?e:e.displayName||e.name;n&&(t="\n\nCheck the top-level render call using <"+n+">.")}return t}(t);if(!oe[n]){oe[n]=!0;var i="";e&&e._owner&&e._owner!==te.current&&(i=" It was passed a child from "+v(e._owner.type)+"."),ie(e),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,i),ie(null)}}}function le(e,t){if("object"==typeof e)if(U(e))for(var n=0;n<e.length;n++){var i=e[n];re(i)&&ae(i,t)}else if(re(e))e._store&&(e._store.validated=!0);else if(e){var r=function(e){if(null===e||"object"!=typeof e)return null;var t=g&&e[g]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof r&&r!==e.entries)for(var s,o=r.call(e);!(s=o.next()).done;)re(s.value)&&ae(s.value,t)}}function ce(e){var t,n=e.type;if(null!=n&&"string"!=typeof n){if("function"==typeof n)t=n.propTypes;else{if("object"!=typeof n||n.$$typeof!==d&&n.$$typeof!==p)return;t=n.propTypes}if(t){var i=v(n);!function(e,t,n,i,r){var s=Function.call.bind(M);for(var o in e)if(s(e,o)){var a=void 0;try{if("function"!=typeof e[o]){var l=Error((i||"React class")+": "+n+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw l.name="Invariant Violation",l}a=e[o](t,o,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){a=e}!a||a instanceof Error||(W(r),x("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",i||"React class",n,o,typeof a),W(null)),a instanceof Error&&!(a.message in q)&&(q[a.message]=!0,W(r),x("Failed %s type: %s",n,a.message),W(null))}}(t,e.props,"prop",i,e)}else void 0===n.PropTypes||ee||(ee=!0,x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v(n)||"Unknown"));"function"!=typeof n.getDefaultProps||n.getDefaultProps.isReactClassApproved||x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var de={};function ue(e,n,r,g,b,y){var j=function(e){return"string"==typeof e||"function"==typeof e||e===s||e===a||e===o||e===u||e===m||e===f||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===p||e.$$typeof===l||e.$$typeof===c||e.$$typeof===d||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!j){var N="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(N+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var C,w=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(b);N+=w||se(),null===e?C="null":U(e)?C="array":void 0!==e&&e.$$typeof===i?(C="<"+(v(e.type)||"Unknown")+" />",N=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,N)}var S=Q(e,n,r,b,y);if(null==S)return S;if(j){var k=n.children;if(void 0!==k)if(g)if(U(k)){for(var $=0;$<k.length;$++)le(k[$],e);Object.freeze&&Object.freeze(k)}else x("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else le(k,e)}if(M.call(n,"key")){var A=v(e),E=Object.keys(n).filter(function(e){return"key"!==e}),T=E.length>0?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}";de[A+T]||(x('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',T,A,E.length>0?"{"+E.join(": ..., ")+": ...}":"{}",A),de[A+T]=!0)}return e===s?function(e){for(var t=Object.keys(e.props),n=0;n<t.length;n++){var i=t[n];if("children"!==i&&"key"!==i){ie(e),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),ie(null);break}}null!==e.ref&&(ie(e),x("Invalid attribute `ref` supplied to `React.Fragment`."),ie(null))}(S):ce(S),S}var me=function(e,t,n){return ue(e,t,n,!1)},pe=function(e,t,n){return ue(e,t,n,!0)};_.Fragment=s,_.jsx=me,_.jsxs=pe}()),_);var B=q.exports;class U{constructor(){}static getInstance(){return U.instance||(U.instance=new U),U.instance}getAvailableComponentsForConditional(e,t){if(!e||!Array.isArray(e))return[];return e.filter(e=>!t||e.id!==t).map(e=>({id:e.id,label:e.basic?.label||e.id,type:e.name,key:e.id})).sort((e,t)=>e.label.localeCompare(t.label))}getApplicableOperators(e){switch(e){case"text-input":case"email-input":case"textarea":return["equals","notEquals","contains","notContains","isEmpty","isNotEmpty"];case"number-input":case"date-picker":case"datetime-picker":return["equals","notEquals","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual","isEmpty","isNotEmpty"];case"select":case"radio":case"segment":default:return["equals","notEquals","isEmpty","isNotEmpty"];case"checkbox":return["contains","notContains","isEmpty","isNotEmpty"]}}validateConditionalLogic(e,t){const n=[];return e?(["show","hide","always"].includes(e.action)||n.push("Invalid conditional action"),["all","any"].includes(e.when)||n.push("Invalid when condition"),e.conditions&&0!==e.conditions.length?e.conditions.forEach((e,i)=>{const r=t.find(t=>t.id===e.when);if(!r)return void n.push(`Condition ${i+1}: Component not found`);this.getApplicableOperators(r.name).includes(e.operator)||n.push(`Condition ${i+1}: Operator not applicable for component type`),this.isValidConditionValue(e.value,r.name,e.operator)||n.push(`Condition ${i+1}: Invalid condition value`)}):n.push("At least one condition is required"),{isValid:0===n.length,errors:n}):{isValid:!0,errors:[]}}evaluateConditionalLogic(e,t,n){if("always"===e.action)return{shouldShow:!0,evaluatedConditions:[]};if(!e||!e.conditions||0===e.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const i=e.conditions.map(e=>{const i=this.getComponentValue(e.when,t,n);return{condition:e,result:this.evaluateCondition(e,i),componentValue:i}});return{shouldShow:this.determineFinalResult(e,i),evaluatedConditions:i}}getComponentValue(e,t,n){if(n&&void 0!==n[e])return n[e];const i=t.find(t=>t.id===e);return i&&"defaultValue"in i.basic?i.basic.defaultValue:void 0}evaluateCondition(e,t){const{operator:n,value:i}=e;if("checked"===i||"notChecked"===i)return this.evaluateCheckboxCondition(t,i);switch(n){case"equals":return this.isEqual(t,i);case"notEquals":return!this.isEqual(t,i);case"isEmpty":return this.isEmpty(t);case"isNotEmpty":return!this.isEmpty(t);case"contains":return this.contains(t,i);case"notContains":return!this.contains(t,i);case"greaterThan":return this.isGreaterThan(t,i);case"lessThan":return this.isLessThan(t,i);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(t,i);case"lessThanOrEqual":return this.isLessThanOrEqual(t,i);default:return!1}}evaluateCheckboxCondition(e,t){const n=this.isCheckboxChecked(e);return"checked"===t?n:"notChecked"===t&&!n}isCheckboxChecked(e){return null!=e&&("boolean"==typeof e?e:"string"==typeof e?"true"===e.toLowerCase()||"1"===e:Array.isArray(e)?e.length>0:"number"==typeof e&&e>0)}determineFinalResult(e,t){let n,i;return n="all"===e.when?t.every(e=>e.result):"any"===e.when&&t.some(e=>e.result),i="show"===e.action?n:"hide"===e.action?!n:(e.action,!0),i}isEqual(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>this.isEqual(e,t[n]));if("object"==typeof e&&"object"==typeof t){const n=Object.keys(e),i=Object.keys(t);return n.length===i.length&&n.every(n=>this.isEqual(e[n],t[n]))}return!1}isEmpty(e){return null==e||void 0===e||("string"==typeof e?""===e.trim():Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}contains(e,t){return null!=e&&null!=t&&("string"==typeof e?e.toLowerCase().includes(String(t).toLowerCase()):!!Array.isArray(e)&&e.some(e=>this.isEqual(e,t)))}isGreaterThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>i}isLessThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<i}isGreaterThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>=i}isLessThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<=i}isValidConditionValue(e,t,n){if(null==e)return["isEmpty","isNotEmpty"].includes(n);switch(t){case"number-input":return!isNaN(Number(e))||["isEmpty","isNotEmpty"].includes(n);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(e))||["isEmpty","isNotEmpty"].includes(n);case"checkbox":return Array.isArray(e)||"string"==typeof e||"number"==typeof e;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(e){return{equals:"Is Equal To",notEquals:"Is Not Equal To",contains:"Contains",notContains:"Does Not Contain",isEmpty:"Is Empty",isNotEmpty:"Is Not Empty",greaterThan:"Is Greater Than",lessThan:"Is Less Than",greaterThanOrEqual:"Is Greater Than Or Equal To",lessThanOrEqual:"Is Less Than Or Equal To"}[e]||e}getActionDisplayText(e){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[e]||e}getConditionalLogicSummary(e,t){if(!e||0===e.conditions.length)return"No conditions";if("always"===e.action)return"Always show";const n=this.getActionDisplayText(e.action),i=e.conditions.map(e=>{const n=t.find(t=>t.id===e.when);return`${n?.basic.label||"Unknown component"} ${this.getOperatorDisplayText(e.operator)} ${this.formatConditionValue(e.value)}`}),r="all"===e.when?" and ":" or ";return`${n} ${i.join(r)}`}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const G=U.getInstance();const H=new class{constructor(){this.toasts=[],this.listeners=[],this.defaultDuration=3e3,this.timeouts={}}generateId(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}notifyListeners(){this.listeners.forEach(e=>e([...this.toasts]))}addToast(e){try{this.toasts.push(e),this.notifyListeners(),this.timeouts[e.id]=setTimeout(()=>{this.removeToast(e.id)},e.duration||this.defaultDuration)}catch(e){console.error("Error displaying toast message:",e)}}removeToast(e){this.timeouts[e]&&(clearTimeout(this.timeouts[e]),delete this.timeouts[e]),this.toasts=this.toasts.filter(t=>t.id!==e),this.notifyListeners()}showSuccess(e,t=3e3){const n={id:this.generateId(),message:e,type:"success",duration:t};this.addToast(n)}showError(e,t=5e3){const n={id:this.generateId(),message:e,type:"danger",duration:t};this.addToast(n)}showWarning(e,t){const n={id:this.generateId(),message:e,type:"warning",duration:t};this.addToast(n)}showInfo(e,t){const n={id:this.generateId(),message:e,type:"info",duration:t};this.addToast(n)}show(e,t="success",n){const i={id:this.generateId(),message:e,type:t,duration:n};this.addToast(i)}clearAll(){Object.values(this.timeouts).forEach(e=>clearTimeout(e)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}getToasts(){return[...this.toasts]}},J=({validationErrors:e,fieldId:t,touchedFields:n,formSubmitted:i,properties:r,localValidation:s,isTouched:o,mode:a})=>{const l=e=>{const t=r.basic.label||"This field",n=r.name||"",i=r.validation?.customValidationMessage;if("number-input"===n)switch(e){case"required":return`${t} is required`;case"lowerLimit":return"Number is below the lower limit";case"upperLimit":return"Number is above the upper limit";default:return""}if(i)return i;const s="date-picker"===n||"datetime-picker"===n?r.basic?.dateTimeMode||("datetime-picker"===n?"datetime":"date"):null;switch(e){case"required":return`${t} is required`;case"invalidDate":return"time"===s?"Please select a valid time":"datetime"===s?"Please select a valid date and time":"date"===s?"Please select a valid date":`${t} is invalid`;case"minLength":return`${t} must be at least ${r.validation.minLength} characters long`;case"maxLength":return`${t} must be no more than ${r.validation.maxLength} characters long`;case"min":return`${t} must be at least ${r.validation.min}`;case"max":return`${t} must be no more than ${r.validation.max}`;case"lowerLimit":const e=r.validation,n=e?.lowerLimit;return`You are under the limit. ${t} must be at least ${n}`;case"upperLimit":const i=r.validation,o=i?.upperLimit;return`You crossed the limit. ${t} must be no more than ${o}`;case"pattern":return`${t} format is invalid`;case"email":return`${t} must be a valid email address`;default:return`${t} is invalid`}},c=(()=>{if("test"!==a)return"";if(!(o||n[t]||i))return"";if(s&&s.isValid)return"";if(s&&!s.isValid&&Object.keys(s.errors).length>0){const e=Object.keys(s.errors).filter(e=>!0===s.errors[e]);if(e.length>0){const t=e[0],n=r.name||"";return"pattern"===t&&"number-input"===n?"":l(t)}}const c=e[t];if(c&&"string"==typeof c&&""!==c.trim()){const e=r.name||"";if("number-input"===e&&s){const e=r.validation,t=e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit,n=e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||t||n?(s.isValid,""):""}if(("date-picker"===e||"datetime-picker"===e)&&c.includes("valid date")){const t=r.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("time"===t)return"Please select a valid time";if("datetime"===t)return"Please select a valid date and time"}return c}return""})();return c?B.jsx("div",{className:"form-error-msg",children:c}):null};var Y;!function(e){e.OPEN="Open",e.IN_PROGRESS="In-Progress",e.REJECTED="Rejected",e.RESOLVE="Resolve"}(Y||(Y={}));const K=({isOpen:e,onClose:i,onSuccess:r,component:s,formTemplateId:u,notes:m="",attachments:p=null,issue:h=null,onCreateIssue:f,onUpdateIssue:g,user:b,availableUsers:x=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:y,assetNumber:v})=>{const[j,N]=t(""),[C,w]=t(""),[S,k]=t(""),[$,A]=t(""),[E,T]=t("Medium"),[I,R]=t(Y.OPEN),[D,V]=t(""),[F,O]=t(""),[z,M]=t(!1),q=!!h;n(()=>{if(e)if(h){N(h.title||""),w(h.description||""),k(h.workOrderNumber||""),A(h.assetNumber||""),T(h.priority||"Medium");const e=h.status||Y.OPEN,t=e===Y.OPEN||e===Y.IN_PROGRESS||e===Y.REJECTED||e===Y.RESOLVE?e:Y.OPEN;R(t),V(h.assignee||""),O(h.comments||"")}else if(s){const e=s.basic?.label||"Component";N(`${e} - Issue`);let t=`Issue raised for component: ${e}`;s.basic&&"value"in s.basic&&s.basic.value&&(t+=`\nComponent Value: ${s.basic.value}`),m&&(t+=`\nNotes: ${m}`),w(t),O(m||""),y&&k(y),v&&A(v)}},[e,s,m,h,y,v]);const P=async e=>{if(h){M(!0);try{const t={title:String(j||"").trim(),description:String(C||"").trim(),workOrderNumber:String(S||"").trim()||"",assetNumber:String($||"").trim()||"",formTemplateId:h.formTemplateId||"",component:h.component||{},priority:E,assignee:String(D||"").trim()||void 0,status:e,comments:String(F||"").trim()||""};g&&h._id&&await g(h._id,t),R(e);const n={[Y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[Y.RESOLVE]:"Issue resolved successfully",[Y.REJECTED]:"Issue rejected"};H.showSuccess(n[e]||"Issue status updated successfully"),r&&r(),i()}catch(e){const t=e?.message||e?.error?.message||"Failed to update issue status. Please try again.";H.showError(t)}finally{M(!1)}}};if(!e)return null;const W=B.jsx("div",{className:"raise-issue-modal-overlay",onClick:i,children:B.jsxs("div",{className:"raise-issue-modal",onClick:e=>e.stopPropagation(),children:[B.jsxs("div",{className:"raise-issue-modal-header",children:[B.jsxs("div",{className:"raise-issue-modal-header-left",children:[B.jsx(o,{className:"raise-issue-modal-icon",size:20}),B.jsx("div",{className:"raise-issue-modal-header-text",children:B.jsx("div",{className:"raise-issue-modal-title-main",children:"Issue Details"})})]}),B.jsx("button",{className:"raise-issue-modal-close",onClick:i,"aria-label":"Close",children:B.jsx(a,{size:18})})]}),B.jsx("div",{className:"raise-issue-modal-content",children:B.jsxs("div",{className:"raise-issue-fields-grid",children:[q&&h?.issueNumber&&B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),B.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:h.issueNumber,readOnly:!0})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Title ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:j,onChange:e=>N(e.target.value),placeholder:"Enter issue title",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:S,onChange:e=>k(e.target.value),placeholder:"N/A",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:$,onChange:e=>A(e.target.value),placeholder:"Enter asset number",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Raised By"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(l,{size:16}),B.jsx("span",{children:b&&`${b.firstName||""} ${b.lastName||""}`.trim()||"User"})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(c,{size:16}),B.jsx("span",{children:q&&h?.createdAt?new Date(h.createdAt).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0}):(new Date).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Description ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("textarea",{className:"raise-issue-field-textarea "+(q?"raise-issue-field-readonly":""),value:C,onChange:e=>w(e.target.value),placeholder:"Enter issue description",rows:4,readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Status ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select "+(q?"":"raise-issue-field-readonly"),value:I,onChange:e=>R(e.target.value),disabled:!q,children:[B.jsx("option",{value:Y.OPEN,children:Y.OPEN}),B.jsx("option",{value:Y.IN_PROGRESS,children:Y.IN_PROGRESS}),B.jsx("option",{value:Y.REJECTED,children:Y.REJECTED}),B.jsx("option",{value:Y.RESOLVE,children:Y.RESOLVE})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Assignee ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select",value:D,onChange:e=>V(e.target.value),children:[B.jsx("option",{value:"",children:"Unassigned"}),x.map(e=>B.jsx("option",{value:e,children:e},e))]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("div",{className:"raise-issue-priority-buttons",children:[B.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===E?"active":""),onClick:()=>T("Low"),children:"Low"}),B.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===E?"active":""),onClick:()=>T("Medium"),children:"Medium"}),B.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===E?"active":""),onClick:()=>T("High"),children:"High"})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[B.jsx(d,{size:16}),B.jsx("span",{children:"Comments"})]}),!F&&B.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),B.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(q?"raise-issue-field-readonly":""),value:F,onChange:e=>O(e.target.value),placeholder:"Add a comment...",rows:4,readOnly:q})]})]})}),B.jsx("div",{className:"raise-issue-modal-actions",children:B.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[q&&h&&B.jsxs(B.Fragment,{children:[I===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:async()=>{await P(Y.IN_PROGRESS)},disabled:z,children:z?"Processing...":"Accept"}),I===Y.IN_PROGRESS&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:async()=>{await P(Y.RESOLVE)},disabled:z,children:z?"Processing...":"Resolve"}),I===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:async()=>{await P(Y.REJECTED)},disabled:z,children:z?"Processing...":"Reject"})]}),!q&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save",onClick:async()=>{if(String(j||"").trim())if(String(C||"").trim())if(String(S||"").trim())if(String($||"").trim())if(String(D||"").trim()){M(!0);try{if(q&&h){const e={title:String(j||"").trim(),description:String(C||"").trim(),workOrderNumber:String(S||"").trim()||"",assetNumber:String($||"").trim()||void 0,formTemplateId:h.formTemplateId||"",component:h.component||{},priority:E,assignee:String(D||"").trim()||void 0,status:I,comments:String(F||"").trim()||""};g&&h._id&&await g(h._id,e),H.showSuccess("Issue updated successfully"),r&&r(),i()}else{if(!s)return H.showError("Component is required"),void M(!1);if(!u||""===String(u||"").trim())return H.showError("Form template is required"),void M(!1);const e={...s,basic:{...s.basic,comments:String(m||"")}},t={title:String(j||"").trim(),workOrderNumber:String(S||"").trim()||void 0,assetNumber:String($||"").trim()||void 0,component:e,description:String(C||"").trim(),formTemplateId:u,assignee:String(D||"").trim()||void 0,priority:E,status:I,comments:String(F||"").trim()||""};let n;f&&(n=await f(t,p||[])),H.showSuccess("Issue raised successfully"),r&&r(n),i()}}catch(e){const t=e?.message||e?.error?.message||(q?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");H.showError(t)}finally{M(!1)}}else H.showError("Assignee is required");else H.showError("Asset Number is required");else H.showError("Work Order is required");else H.showError("Description is required");else H.showError("Title is required")},disabled:z||!String(j||"").trim()||!String(C||"").trim()||!String(S||"").trim()||!String($||"").trim()||!String(D||"").trim(),children:z?"Saving...":"Save Changes"})]})})]})});return L(W,document.body)},X=({component:e,condition:r,currentValue:s,thresholdValue:a,formTemplateId:l,workOrderNumber:c,assetNumber:d,onIssueRaised:u,isIssueRaised:m=!1,compact:p=!1})=>{const[h,f]=t(!1),[g,b]=t(null),[x,y]=t(!1),[v,j]=t(!1);n(()=>{m&&j(!0)},[m]),n(()=>{j(!1)},[r?.id]);const N=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),C=i(async()=>{if(m||v){if(g)return void f(!0);y(!0);try{b(null),f(!0)}catch(e){console.error("Error fetching issue:",e),H.showError("Failed to load issue details")}finally{y(!1)}}else b(null),f(!0)},[m,v,l,e,g]),w=i(()=>{f(!1),m||v||b(null)},[m,v]),S=i(e=>{f(!1),b(e||null),j(!0),u&&r?.id&&u(r.id)},[u,r]);return m||v?B.jsx(B.Fragment,{children:h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})}):p?B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content-compact",children:[B.jsx(o,{className:"threshold-alert-icon-compact",size:14}),B.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${N(r.operator)} ${a}`}),B.jsx("button",{type:"button",onClick:C,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})]}):B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content",children:[B.jsx("div",{className:"threshold-alert-header",children:B.jsxs("div",{className:"threshold-alert-title-group",children:[B.jsx(o,{className:"threshold-alert-icon",size:20}),B.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),B.jsxs("div",{className:"threshold-alert-message",children:[(()=>{const t=N(r.operator);return`${e.basic?.label||"Value"}: Value ${s} exceeds threshold ${t} ${a}`})(),B.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),B.jsx("div",{className:"threshold-alert-buttons",children:B.jsx("button",{type:"button",onClick:C,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})]})},Z=({id:e,properties:o,validationErrors:a={},formValue:l="",inputType:c="text",readonly:d=!1,disabled:u=!1,touchedFields:m={},formSubmitted:p=!1,mode:h="test",onValueChange:f,onBlur:g,onFocus:b,className:x="",hideLabel:y=!1,formTemplateId:v,onThresholdIssueRaised:j,raisedThresholdIssues:N=new Set,workOrderNumber:C,assetNumber:w})=>{const S=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?S(e.value):"label"in e?S(e.label):"":String(e||""),k=r(e),$=r(null);n(()=>{e!==k.current&&(console.warn(`[DfFormInput] Component ID changed from ${k.current} to ${e}`),k.current=e)},[e]);const A=S(l||o?.basic?.defaultValue||""),[E,T]=t(A),[L,I]=t(!1),[R,D]=t(!1),[V,F]=t(new Set),[O,z]=t(A),M=()=>{if(c)return c;const e=o?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},q=i(e=>{const t=(()=>{const e={};if(o?.validation?.required&&(e.required=!0),"email"===M()&&(e.email=!0),"text"===M()){const t=o.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===M()){const t=o.validation;t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&(e.lowerLimit=t.lowerLimit),t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&(e.upperLimit=t.upperLimit)}return e})(),n={};let i=!0;const r="string"==typeof e?e:null!=e?String(e):"";if(!t.required||r&&""!==r.trim()||(n.required=!0,i=!1),t.email&&r&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(r)&&(n.email=!0,i=!1),t.minLength&&r&&r.length<t.minLength&&(n.minLength=!0,i=!1),t.maxLength&&r&&r.length>t.maxLength&&(n.maxLength=!0,i=!1),"number"===M())if(delete n.pattern,delete n.min,delete n.max,r&&""!==r.trim()){const e=r.trim(),s=parseFloat(e);isNaN(s)||("lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&s<t.lowerLimit&&(n.lowerLimit=!0,i=!1),"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&s>t.upperLimit&&(n.upperLimit=!0,i=!1))}else delete n.lowerLimit,delete n.upperLimit;return{isValid:i,errors:n}},[o,M]),P=i(t=>{const n="string"==typeof t?t:null!=t?String(t):"";if(T(n),f){const t=q(n),i=k.current,r={id:i,value:n,isValid:t.isValid,errors:t.errors};i!==e&&console.error(`[DfFormInput] ID mismatch in handleValueChange! ref: ${i}, prop: ${e}`),f(r)}},[e,f,q,k]);n(()=>{L&&(m[e]=!0)},[L,e,m]),n(()=>{if("edit"===h){I(!1);T(o?.basic?.defaultValue||"")}else"test"===h&&(I(!1),T(""))},[h,o?.basic?.defaultValue]),n(()=>{const t=k.current,n=S(l||o?.basic?.defaultValue||"");n===E||R||""===n&&""!==String(E||"").trim()?""===n&&String(E||"").trim():null!=l&&(t===e?T(n):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${t}, prop id: ${e}`))},[l,E,R,o?.basic?.defaultValue,e]),n(()=>{p&&I(!0)},[p]),n(()=>{"test"!==h&&T("")},[h]);const W=i((e,t)=>{if(!t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(isNaN(n)||isNaN(i))return!1;switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}},[]),_=s(()=>o?.condition?.conditions||[],[o?.condition]);n(()=>{E!==O&&(F(new Set),z(E))},[E,O]);const U=s(()=>{if("test"!==h||!E||""===E)return null;const e=_.filter(e=>W(e,E));if(0===e.length)return null;for(const t of e)if(!V.has(t.id))return t;return null},[E,_,V,h,W,N]),G=i(e=>{F(t=>new Set(t).add(e))},[]),H=M(),Y=u||d||o?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:`form-group ${(()=>{const e=o?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!y&&o.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[o.basic.label,o.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",ref:$,children:[B.jsx("input",{type:H,id:e,value:E,onChange:e=>{const t=e.target.value;P(t)},onFocus:()=>{D(!0),b&&b()},onBlur:()=>{if(D(!1),I(!0),"test"===h&&f){const t="string"==typeof E?E:null!=E?String(E):"",n=q(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};f(i)}g&&g()},placeholder:o.basic.placeholder,disabled:Y,readOnly:d||o?.validation?.readonly,className:(()=>{const t="form-control";if("test"===h){const n="string"==typeof E?E:null!=E?String(E):"",i=q(n);if(i.isValid)return`${t} ${x}`.trim();const r=!i.isValid&&L,s=a[e]&&(L||p)&&!i;return`${t} ${r||s?"is-invalid":""} ${x}`.trim()}return`${t} ${x}`.trim()})()}),B.jsx(J,{validationErrors:a,fieldId:e,touchedFields:m,formSubmitted:p,properties:o,localValidation:q(E),isTouched:L,mode:h})]})]}),U&&"test"===h&&(()=>{const e=N?.has(U.id)||!1,t=null!==$.current?.closest(".table-cell")||null!==$.current?.closest(".cell-content")||null!==$.current?.closest(".datagrid-table-view")||null!==$.current?.closest(".datagrid-list-view")||x.includes("table-cell")||x.includes("cell-content");return B.jsx(X,{component:o,condition:U,currentValue:E,thresholdValue:U.value,formTemplateId:v,workOrderNumber:C,assetNumber:w,onDismiss:()=>G(U.id),onIssueRaised:j,isIssueRaised:e,compact:t},`${U.id}-${e}`)})()]})},Q=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),r?.validation?.minLength&&e&&e.length<r.validation.minLength&&(t.minLength=!0,n=!1),r?.validation?.maxLength&&e&&e.length>r.validation.maxLength&&(t.maxLength=!0,n=!1),{isValid:n,errors:t}},[r]),N=i(t=>{if(x(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{""===b&&""!==o&&x(o)},[o]),n(()=>{d&&v(!0)},[d]),n(()=>{"test"!==u&&x("")},[u]);const C=l||a||r?.validation?.readonly,w=r?.validation?.rows||4;return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("textarea",{id:e,value:b,onChange:e=>{const t=e.target.value;N(t)},onFocus:()=>{h&&h()},onBlur:()=>{v(!0),p&&p()},placeholder:r.basic.placeholder,disabled:C,readOnly:a||r?.validation?.readonly,rows:w,className:`form-textarea ${!j(b).isValid&&y?"is-invalid":""} ${f}`.trim()}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})]})},ee=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=r?.validation?.multiple||!1,N=i(e=>{const t={};let n=!0;return r?.validation?.required&&(j?Array.isArray(e)&&0!==e.length||(t.required=!0,n=!1):(!e||"string"==typeof e&&""===e.trim())&&(t.required=!0,n=!1)),{isValid:n,errors:t}},[r,j]),C=i(t=>{if(x(t),m){const n=N(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,N]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{JSON.stringify(o)!==JSON.stringify(b)&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const w=l||a||r?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("select",{id:e,value:b,onChange:e=>{if(j){const t=Array.from(e.target.selectedOptions,e=>e.value);C(t)}else C(e.target.value)},onFocus:()=>{h&&h()},onBlur:()=>{v(!0),p&&p()},disabled:w,multiple:j,className:`form-select ${!N(b).isValid&&y?"is-invalid":""} ${f}`.trim(),children:[!j&&B.jsx("option",{value:"",children:r.basic.placeholder||"Select an option"}),(r.options||[]).map((e,t)=>B.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:N(b),isTouched:y,mode:u})]})]})},te=({id:e,properties:r,validationErrors:s={},formValue:o=[],readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(!1),y=Array.isArray(o)?o:[],v=i(e=>{const t={};let n=!0;return r?.validation?.required&&0===e.length&&(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),j=i(t=>{if(m){const n=v(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,v,y]),N=(e,t)=>{let n;n=t?[...y,e]:y.filter(t=>t!==e),j(n)},C=()=>{h&&h()},w=()=>{x(!0),p&&p()};n(()=>{b&&(c[e]=!0)},[b,e,c]),n(()=>{},[o,e,y]),n(()=>{d&&x(!0)},[d]);const S=l||a||r?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group checkbox-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${r?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!g&&r.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:v(y),isTouched:b,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:v(y),isTouched:b,mode:u})]})})})},ne=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),N=i(t=>{if(x(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=e=>{N(e)},w=()=>{h&&h()},S=()=>{v(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{o!==b&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const k=l||a||r?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group radio-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${r?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!g&&r.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:b===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:b===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})})})},ie=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),N=i(t=>{if(x(t),v(!0),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=()=>{h&&h()},w=()=>{v(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{o!==b&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const S=()=>r?.basic?.inlineLayout?"inline-layout":"grid-layout",k=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},$=e=>{if(void 0!==e?.icon&&""!==e.icon)return e.icon;return"pass"===k(e?.value||e)?"✓":"×"},A=(e,t)=>e?.color||e?.backgroundColor?{color:t?"#ffffff":e.color||"#00814b",backgroundColor:t?e.color||"#00814b":e.backgroundColor||"#34bd4914",borderColor:e.color||"#00814b"}:{},E=e=>{if(e?.color||e?.backgroundColor)return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===k(e?.value||e)?"pass-button":"fail-button")},T=l||a||r?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsx("div",{className:`form-group segment-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${f}`,children:!g&&r.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(r.options||[]).map((t,n)=>{const i=b===t.value,r=A(t,i),s=E(t),o=$(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!T&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:T||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:s,style:Object.keys(r).length>0?r:void 0,children:[o&&B.jsx("span",{className:"segment-icon",children:o}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})]}):B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(r.options||[]).map((t,n)=>{const i=b===t.value,r=A(t,i),s=E(t),o=$(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!T&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:T||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:s,style:Object.keys(r).length>0?r:void 0,children:[o&&B.jsx("span",{className:"segment-icon",children:o}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})},re=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const b=i(e=>{if(!e)return"";if("string"==typeof e){if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e))return e;const t=new Date(e);if(!isNaN(t.getTime())){const e=r.name||"",n=r.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("datetime"===n){return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}T${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}return e}if(e instanceof Date){if(isNaN(e.getTime()))return"";const t=r.name||"",n=r.basic?.dateTimeMode||("datetime-picker"===t?"datetime":"date");if("datetime"===n){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}T${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}if("object"==typeof e&&null!==e){if("value"in e&&e.value)return b(e.value);if("date"in e&&e.date)return b(e.date);try{const t=String(e),n=new Date(t);if(!isNaN(n.getTime()))return b(n)}catch(e){}return""}return""},[r]),x=b(o),[y,v]=t(x),[j,N]=t(!1),[C,w]=t(!1),S=i(e=>{const t={};let n=!0;const i=r.name||"",s=r.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"),o=e?String(e).trim():"";if(r?.validation?.required&&(!o||""===o))return t.required=!0,n=!1,{isValid:n,errors:t};if(o&&""!==o)if("time"===s){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(o))return t.invalidDate=!0,n=!1,{isValid:n,errors:t}}else if("datetime"===s){const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(r?.validation?.minDate){const i=new Date(r.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date and time must be on or after ${i.toLocaleDateString()}`,n=!1)}if(r?.validation?.maxDate){const i=new Date(r.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date and time must be on or before ${i.toLocaleDateString()}`,n=!1)}}else{const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(r?.validation?.minDate){const i=new Date(r.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date must be on or after ${i.toLocaleDateString()}`,n=!1)}if(r?.validation?.maxDate){const i=new Date(r.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date must be on or before ${i.toLocaleDateString()}`,n=!1)}}return{isValid:n,errors:t}},[r]),k=i(t=>{if(v(t),m){const n=S(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,S]);n(()=>{j&&(c[e]=!0)},[j,e,c]),n(()=>{const e=b(o);e===y||C||v(e)},[o,y,C,b]),n(()=>{d&&N(!0)},[d]);const $=l||a||r?.validation?.readonly,A=r.name||"",E=r.basic?.dateTimeMode||("datetime-picker"===A?"datetime":"date"),T=(()=>{switch(E){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("input",{type:T,id:e,value:y,onChange:e=>{const t=e.target.value;k(t)},onFocus:()=>{w(!0),h&&h()},onBlur:()=>{if(w(!1),N(!0),m){const t=S(y),n={id:e,value:y,isValid:t.isValid,errors:t.errors};m(n)}p&&p()},disabled:$,readOnly:a||r?.validation?.readonly,min:r?.validation?.minDate,max:r?.validation?.maxDate,className:`form-date ${!S(y).isValid&&j?"is-invalid":""} ${f}`.trim()}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:S(y),isTouched:j,mode:u})]})]})},se=({id:e,properties:s,validationErrors:o={},formValue:a="",readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="preview",onValueChange:p,onBlur:h,onFocus:f,className:g="",hideLabel:b=!1})=>{const x=r(null),[y,v]=t(!1),[j,N]=t(!1),[C,w]=t(a),[S,k]=t(!1),$=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),A=i(t=>{if(w(t),p){const n=$(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};p(i)}},[e,p,$]),E=i(()=>{const e=document.documentElement.classList.contains("dark")||"dark"===document.documentElement.getAttribute("data-theme");let t=getComputedStyle(document.documentElement).getPropertyValue("--df-color-fb-input-bg").trim();t||(t=e?"#2c2e34":"#ffffff");return{strokeColor:e?"#ffffff":"#000000",backgroundColor:t}},[]),T=i(t=>{if(!t)return;const n=x.current;if(!n)return;const i=n.getContext("2d");if(!i)return;const r=new Image;r.onload=()=>{i.clearRect(0,0,n.width,n.height);const e=E();i.fillStyle=e.backgroundColor,i.fillRect(0,0,n.width,n.height);const t=n.width/n.height,s=r.width/r.height;let o=n.width,a=n.height,l=0,c=0;s>t?(a=n.width/s,c=(n.height-a)/2):(o=n.height*s,l=(n.width-o)/2),i.drawImage(r,l,c,o,a)},r.onerror=n=>{console.error("DfFormSignature: error loading image",{id:e,error:n,dataURL:t.substring(0,50)+"..."})},r.src=t},[E,e]),L=i(()=>{const e=x.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height,e.style.width=n.width+"px",e.style.height=n.height+"px";const i=E();t.strokeStyle=i.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?T(C):(t.fillStyle=i.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,E,T]),I=i(()=>{setTimeout(()=>{L()},100)},[L]);n(()=>{const e=()=>{I()},t=new MutationObserver(e=>{e.forEach(e=>{if("attributes"===e.type&&"class"===e.attributeName){const t=e.target;t.classList.contains("form-canvas-container")&&(t.classList.contains("mobile-view")||t.classList.contains("tablet-view")||t.classList.contains("desktop-view"))&&I()}})});return t.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[I]);const R=i(e=>{const t=x.current;if(!t)return{x:0,y:0};const n=t.getBoundingClientRect(),i=t.width/n.width,r=t.height/n.height,s=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,o=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(s-n.left)*i,y:(o-n.top)*r}},[]),D=e=>{if(l||c||s?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),v(!0),N(!0);const t=x.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:r}=R(e),o=E();n.strokeStyle=o.strokeColor,n.lineWidth=2,n.lineCap="round",n.lineJoin="round",n.beginPath(),n.moveTo(i,r)},V=e=>{if(!y)return;e.preventDefault(),e.stopPropagation();const t=x.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:r}=R(e);n.lineTo(i,r),n.stroke()},F=()=>{if(!y)return;v(!1),k(!0);const e=x.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const n=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<n.length;e+=4){const t=n[e],i=n[e+1],r=n[e+2];if(n[e+3]>0&&(t<255||i<255||r<255))return!0}})(e);const t=e.toDataURL("image/png");w(t),A(t),setTimeout(()=>{k(!1)},100)}else k(!1)},O=i(()=>{const e=x.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=E();if(t.strokeStyle=n.strokeColor,C){const i=C,r=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,r.width,r.height),i&&T(i)}else{const i=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,i.width,i.height)}},[E,C,T]);n(()=>{const e=new MutationObserver(e=>{e.forEach(e=>{"attributes"!==e.type||"class"!==e.attributeName&&"data-theme"!==e.attributeName||O()})});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{e.disconnect()}},[O]);n(()=>{j&&(d[e]=!0)},[j,e,d]),n(()=>{if(!(a===C||y||S||""!==C&&""===a)){if(a===C)return;w(a),a&&T(a)}},[a,C,y,S]),n(()=>{u&&N(!0)},[u]),n(()=>{if("test"!==m){w("");const e=x.current;if(e){const t=e.getContext("2d");if(t){const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height;const i=E();t.fillStyle=i.backgroundColor,t.fillRect(0,0,n.width,n.height)}}}},[m]),n(()=>{L()},[m]);const z=c||l||s?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[B.jsx("canvas",{ref:x,id:e,className:`form-signature ${!$(C).isValid&&j?"is-invalid":""} ${g}`.trim(),onMouseDown:D,onMouseMove:V,onMouseUp:F,onMouseLeave:F,onTouchStart:D,onTouchMove:V,onTouchEnd:F,onFocus:()=>{f&&f()},onBlur:()=>{h&&h()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:z?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!z&&B.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=x.current;if(!t)return;const n=t.getBoundingClientRect();t.width=n.width,t.height=n.height;const i=t.getContext("2d");if(!i)return;const r=E();i.fillStyle=r.backgroundColor,i.fillRect(0,0,n.width,n.height),i.strokeStyle=r.strokeColor,i.lineWidth=2,i.lineCap="round",i.lineJoin="round",w(""),A("")})(e),className:"clear-signature-btn",style:{position:"absolute",bottom:"8px",right:"8px",padding:"4px 8px",backgroundColor:"var(--df-color-error-primary)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"0.75rem",fontWeight:"500",zIndex:10,transition:"all 0.2s ease",minWidth:"60px",minHeight:"28px"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-dark, #dc2626)",e.currentTarget.style.transform="scale(1.05)"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-primary)",e.currentTarget.style.transform="scale(1)"},children:"Clear"})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:s,localValidation:$(C),isTouched:j,mode:m})]})]})},oe=({id:e,properties:s,validationErrors:o={},formValue:a=null,readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="test",onValueChange:p,onBlur:h,onFocus:f,className:g="",hideLabel:b=!1})=>{const[x,y]=t([]),[v,j]=t(!1),[N,C]=t(!1),w=r(null),S=i(t=>{if(!t)return[];const n=Array.isArray(t)?t:Array.from(t),i=[];return n.forEach((t,n)=>{if(t&&"object"==typeof t&&!(t instanceof File)&&!(t instanceof Blob)){const r=t;if(r.data||r.url||r.name&&r.type){const t=r.name||r.fileName||`file-${n}`,s=r.size||r.fileSize||0,o=r.type||r.fileType||r.mimeType||"";let a;if(r.url)a=r.url;else if(r.data){const e=r.data;if("string"==typeof e)if(e.startsWith("data:"))a=e;else{const t=e.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>10){let e=o;e||(e=t.startsWith("/9j/")||t.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":t.startsWith("iVBORw0KGgo")?"image/png":t.startsWith("R0lGOD")?"image/gif":t.startsWith("UklGR")?"image/webp":"image/png"),a=`data:${e};base64,${t}`}else a=e}}const l=new File([],t,{type:o});return void i.push({file:l,id:`${e}-file-${n}`,size:s,type:o,name:t,preview:a})}}let r,s,o=0,a="",l="";if(t instanceof File||t instanceof Blob){const e=t;if(o=e.size||0,a=e.type||"",l=e.name||`file-${n}`,s=e,a.startsWith("image/"))try{r=URL.createObjectURL(e)}catch(e){console.error("Error creating object URL:",e),r=void 0}}else if("string"==typeof t){const e=t,i=e.replace(/\s/g,""),o=i.length>50&&/^[A-Za-z0-9+/=]+$/.test(i)&&!e.startsWith("http")&&!e.startsWith("https")&&!e.startsWith("data:")&&!e.startsWith("blob:")&&!e.startsWith("/");let c=e;if(o){let e="image/png";i.startsWith("/9j/")||i.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?e="image/jpeg":i.startsWith("iVBORw0KGgo")?e="image/png":i.startsWith("R0lGOD")?e="image/gif":i.startsWith("UklGR")&&(e="image/webp"),c=`data:${e};base64,${i}`}let d="";if(c.startsWith("data:")){const e=c.match(/filename=([^;]+)/i);if(e)d=decodeURIComponent(e[1]);else{const e=c.match(/data:([^;]+)/);if(e){const t=e[1];d=`file-${n+1}.${t.includes("image")?t.includes("jpeg")?"jpg":"png":t.includes("pdf")?"pdf":t.includes("word")?"doc":t.includes("excel")?"xls":"file"}`}else d=`file-${n+1}`}}else if(c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))try{const t=new URL(e),i=t.pathname.split("/").pop()||"";if(i&&i.includes("."))d=decodeURIComponent(i);else{const e=t.searchParams.get("filename")||t.searchParams.get("name");d=e?decodeURIComponent(e):`file-${n+1}`}}catch(t){const i=e.lastIndexOf("/"),r=i>=0?e.substring(i+1):e,s=r.indexOf("?"),o=s>=0?r.substring(0,s):r;d=o&&o.includes(".")?decodeURIComponent(o):`file-${n+1}`}else d=`file-${n+1}`;if(l=d||`file-${n+1}`,c.startsWith("data:")){const e=c.indexOf(";");a=e>5?c.substring(5,e):"application/octet-stream"}else{const e=c.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i)||l.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(e){a={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",zip:"application/zip",rar:"application/x-rar-compressed"}[e[1].toLowerCase()]||"application/octet-stream"}else a=o?"image/png":"application/octet-stream"}(c.startsWith("data:image")||c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))&&(r=c),s=new File([],l,{type:a})}else{if(!t||"object"!=typeof t)return;{const e=t;if(l=e.name||e.fileName||`file-${n}`,o=e.size||e.fileSize||0,a=e.type||e.fileType||e.mimeType||"",e.url||e.path)r=e.url||e.path;else if(a.startsWith("image/")&&e.data){const t=e.data;if("string"==typeof t)if(t.startsWith("data:"))r=t;else{const e=t.replace(/\s/g,"");r=/^[A-Za-z0-9+/=]+$/.test(e)&&e.length>50?`data:${a};base64,${e}`:t}else r=void 0}s=new File([],l,{type:a})}}i.push({file:s,id:`${e}-file-${n}`,size:o,type:a,name:l,preview:r})}),i},[e]),k=i(()=>({isValid:!0,errors:{}}),[]),$=i(t=>{if(l||c)return;const n=S(t),i=x.length>0?[...x,...n]:n,r=s?.validation?.maxFiles||1/0,o=i.slice(0,r);if(y(o),C(!0),p){const t=k(),n={id:e,value:o.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}},[x,s,l,c,p,k,S,e]),A=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]},E=e=>e.startsWith("image/")?"🖼️":e.startsWith("video/")?"🎥":e.startsWith("audio/")?"🎵":e.includes("pdf")?"📄":e.includes("word")||e.includes("document")?"📝":e.includes("excel")||e.includes("spreadsheet")?"📊":e.includes("zip")||e.includes("rar")?"📦":"📁";n(()=>{N&&(d[e]=!0)},[N,e,d]),n(()=>{("edit"===m||"test"===m)&&C(!1)},[m]),n(()=>{const e=S(a);null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==String(a).trim()||"object"==typeof a&&!Array.isArray(a)&&Object.keys(a).length>0)||0===x.length&&null!=a?y(e):(null==a||Array.isArray(a)&&0===a.length)&&x.length>0&&y([])},[a,S,x.length]),n(()=>{u&&C(!0)},[u]),n(()=>()=>{x.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[x]);const T=()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"},L=c||l||s?.validation?.readonly,I=s?.validation?.multiple||!1,R=s?.validation?.accept||"*/*",D=s?.validation?.maxFiles||1/0,V=x.length<D&&(I||D>1),F="edit"===m,O="preview"===m||"test"===m,z=x.filter(e=>e.type.startsWith("image/")),M=x.filter(e=>!e.type.startsWith("image/")),q=z.length>0;return O&&q?B.jsxs("div",{className:`form-group ${T()}`,children:[!b&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic?.label||"Attachments",s.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:"file-image-display",children:[z.map(e=>B.jsxs("div",{className:"file-image-container",children:[e.preview&&B.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),B.jsxs("div",{className:"file-image-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:A(e.size)})]})]},e.id)),M.length>0&&B.jsxs("div",{className:"file-other-files",children:[B.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),M.map(e=>B.jsxs("div",{className:"file-item-minimal",children:[B.jsx("div",{className:"file-icon",children:E(e.type)}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:A(e.size)})]})]},e.id))]})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:s,localValidation:k(),isTouched:N,mode:m})]})]}):B.jsxs("div",{className:`form-group ${T()}`,children:[!b&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic?.label||"Attachments",s.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:`file-upload-area ${v?"drag-over":""} ${l?"readonly":""} ${c?"disabled":""} ${g}`.trim(),onDragOver:e=>{e.preventDefault(),l||c||j(!0)},onDragLeave:e=>{e.preventDefault(),j(!1)},onDrop:e=>{if(e.preventDefault(),j(!1),l||c)return;const t=e.dataTransfer.files;t.length>0&&$(t)},onClick:e=>{const t=e.target,n=null!==t.closest(".file-item"),i=null!==t.closest(".file-remove");!F||L||0!==x.length||n||i||w.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(C(!0),"test"===m&&p){const t=k(),n={id:e,value:x.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}h&&h()},tabIndex:L?-1:0,children:[B.jsx("input",{ref:w,type:"file",id:e,multiple:I,accept:R,onChange:e=>{const t=e.target.files;t&&t.length>0&&($(t),e.target.value="")},disabled:L,style:{display:"none"}}),0===x.length?B.jsxs("div",{className:"upload-placeholder",onClick:e=>{e.stopPropagation(),F&&!L&&w.current?.click()},children:[B.jsx("div",{className:"upload-icon",children:"📁"}),B.jsx("div",{className:"upload-text",children:s.basic.placeholder&&B.jsx("p",{className:"upload-hint",children:s.basic.placeholder})})]}):B.jsx("div",{className:"file-list",children:x.map(t=>B.jsxs("div",{className:"file-item",children:[B.jsx("div",{className:"file-preview",children:t.preview?B.jsx("img",{src:t.preview,alt:t.name,className:"file-image"}):B.jsx("div",{className:"file-icon",children:E(t.type)})}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:t.name,children:t.name}),B.jsx("div",{className:"file-size",children:A(t.size)})]}),F&&!L&&B.jsx("button",{type:"button",className:"file-remove",onClick:n=>{n.stopPropagation(),(t=>{if(l||c)return;const n=x.filter(e=>e.id!==t);if(y(n),C(!0),p){const t=k(),i={id:e,value:n.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(i)}})(t.id)},"aria-label":`Remove ${t.name}`,children:"✕"})]},t.id))})]}),x.length>0&&V&&!L&&F&&B.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!L&&w.current&&F&&(w.current.value="",w.current.click())},"aria-label":"Add more files",children:[B.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B.jsx("path",{d:"M12 5v14M5 12h14"})}),B.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:s,localValidation:k(),isTouched:N,mode:m})]})]})},ae=({id:e,properties:s,validationErrors:o={},formValue:l=null,readonly:c=!1,disabled:d=!1,touchedFields:h={},formSubmitted:f=!1,mode:g="test",onValueChange:b,onBlur:x,onFocus:y,className:v="",hideLabel:j=!1})=>{const[N,C]=t(l),[w,S]=t(!1),[k,$]=t(""),[A,E]=t(!1),[T,L]=t(!1),[I,R]=t({lat:40.7128,lng:-74.006}),[D,V]=t(null),[F,O]=t(10),[z,M]=t(""),[q,P]=t(!1),W=r(null),[_,U]=t(!1),[G,H]=t(null),[Y,K]=t(!1);n(()=>{if(l&&l.latitude&&l.longitude){40.7128===l.latitude&&-74.006===l.longitude||(C(l),V({lat:l.latitude,lng:l.longitude,isCurrentLocation:!1}),R({lat:l.latitude,lng:l.longitude}))}else null==l&&(C(null),V(null))},[l]),n(()=>{T&&40.7128===I.lat&&I.lng},[T,I]),n(()=>{(c||d)&&(T&&L(!1),z&&M(""),_&&(U(!1),H(null)))},[c,d]);const X=i(async(e,t)=>{K(!0);try{const n=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),i=await n.json();if(i&&i.address){const e=i.address;return{placeName:i.display_name||"",city:e.city||e.town||e.village||e.municipality||"",country:e.country||""}}}catch(e){console.error("Reverse geocoding failed:",e)}finally{K(!1)}return{placeName:"",city:"",country:""}},[]),Z=i(async(t,n,i)=>{const r=await X(t,n),s={latitude:t,longitude:n,timestamp:Date.now(),placeName:r.placeName,city:r.city,country:r.country,address:r.placeName,...i};if(C(s),V({lat:t,lng:n,isCurrentLocation:!1}),E(!0),b){b({id:e,value:s,isValid:!0,errors:{}})}},[X,e,b]),Q=i(async()=>{if(c||d)return;S(!0),$("");if(void 0!==window.Capacitor)try{const{Geolocation:e}=window.Capacitor.Plugins;if(e)try{if("granted"!==(await e.requestPermissions()).location)return S(!1),void $("Location permission is required. Please enable location access in your device settings.");const t=await e.getCurrentPosition({enableHighAccuracy:s.validation?.enableHighAccuracy??!0,timeout:s.validation?.timeout??1e4,maximumAge:s.validation?.maximumAge??3e5}),n=t.coords.latitude,i=t.coords.longitude;return V({lat:n,lng:i,isCurrentLocation:!0}),R({lat:n,lng:i}),E(!0),await Z(n,i,{accuracy:t.coords.accuracy,timestamp:Date.now()}),S(!1),void $("")}catch(e){return S(!1),void(e.message?.includes("permission")||e.message?.includes("denied")?$("Location permission is required. Please enable location access in your device settings."):e.message?.includes("timeout")?$("Location request timed out. Please try again."):$("Unable to retrieve your location. Please try again."))}}catch(e){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return S(!1),void $("Geolocation is not supported by this browser.");const e={enableHighAccuracy:s.validation?.enableHighAccuracy??!0,timeout:s.validation?.timeout??1e4,maximumAge:s.validation?.maximumAge??3e5};navigator.geolocation.getCurrentPosition(async e=>{const t=e.coords.latitude,n=e.coords.longitude;V({lat:t,lng:n,isCurrentLocation:!0}),R({lat:t,lng:n}),E(!0),await Z(t,n,{accuracy:e.coords.accuracy,timestamp:e.timestamp}),S(!1),$("")},e=>{S(!1);let t="Unable to retrieve your location.";switch(e.code){case e.PERMISSION_DENIED:t="Location access denied by user. Please enable location access in your browser/device settings.";break;case e.POSITION_UNAVAILABLE:t="Location information is unavailable.";break;case e.TIMEOUT:t="Location request timed out. Please try again."}$(t)},e)},[c,d,s,Z]),ee=i(()=>{if(!c&&!d&&(C(null),V(null),$(""),E(!0),b)){b({id:e,value:null,isValid:!0,errors:{}})}},[c,d,e,b]),te=i(()=>{c||d||L(!T)},[c,d,T]),ne=i((e,t,n,i,r,s)=>{const o=e-r/2,a=t-s/2,l=156543.03392*Math.cos(n.lat*Math.PI/180)/Math.pow(2,i),c=o*l,d=a*l;return{lat:n.lat+d/111320,lng:n.lng+c/(111320*Math.cos(n.lat*Math.PI/180))}},[]),ie=i(e=>{c||d||!W.current||0===e.button&&(U(!0),H({x:e.clientX,y:e.clientY}),e.preventDefault())},[c,d]),re=i(e=>{if(!_||!G||!W.current)return;const t=e.clientX-G.x,n=e.clientY-G.y,i=156543.03392*Math.cos(I.lat*Math.PI/180)/Math.pow(2,F),r=-n*i/111320,s=t*i/(111320*Math.cos(I.lat*Math.PI/180));R({lat:I.lat+r,lng:I.lng+s}),H({x:e.clientX,y:e.clientY})},[_,G,I,F]),se=i(async e=>{if(!W.current)return;if(_&&G){const t=Math.abs(e.clientX-G.x),n=Math.abs(e.clientY-G.y);if(t>5||n>5)return U(!1),void H(null)}if(c||d)return U(!1),void H(null);const t=W.current.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,{lat:r,lng:s}=ne(n,i,I,F,t.width,t.height);await Z(r,s),U(!1),H(null)},[c,d,W,I,F,ne,Z,_,G]),oe=i(async t=>{if(t.trim()&&!c&&!d){P(!0),$("");try{const n=await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(t)}&limit=5&addressdetails=1`),i=await n.json();if(i&&i.length>0){const t=i[0],n=parseFloat(t.lat),r=parseFloat(t.lon),s=t.address||{},o={latitude:n,longitude:r,address:t.display_name,placeName:t.display_name,city:s.city||s.town||s.village||s.municipality||"",country:s.country||"",timestamp:Date.now()};if(C(o),V({lat:n,lng:r,isCurrentLocation:!1}),R({lat:n,lng:r}),E(!0),b){b({id:e,value:o,isValid:!0,errors:{}})}}else $("No locations found for your search.")}catch(e){$("Failed to search for location. Please try again.")}finally{P(!1)}}},[c,d,e,b]),ae=()=>{y&&y()},le=()=>{E(!0),x&&x()},ce=d||c||s?.validation?.readonly,de=s?.basic?.label||"Location",ue=s?.basic?.description||"";return B.jsxs("div",{className:`form-group ${j?"no-label":""} ${v}`,children:[!j&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[de,s?.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),ue&&B.jsx("div",{className:"form-group-description",children:ue}),B.jsxs("div",{className:"location-wrapper",children:[!(c&&N)&&B.jsxs("div",{className:"location-controls",children:[B.jsx("button",{type:"button",className:"location-btn "+(w?"loading":""),onClick:Q,disabled:ce||w,onFocus:ae,onBlur:le,tabIndex:ce?-1:0,children:w?B.jsxs(B.Fragment,{children:[B.jsx(u,{size:16,className:"loading-spinner"}),"Getting Location..."]}):B.jsxs(B.Fragment,{children:[B.jsx(m,{size:16}),"Get Current Location"]})}),B.jsxs("button",{type:"button",className:"location-btn secondary",onClick:te,disabled:ce,onFocus:ae,onBlur:le,tabIndex:ce?-1:0,children:[B.jsx(p,{size:16}),T?"Hide Map":"Choose on Map"]})]}),N&&B.jsxs("div",{className:"location-display",children:[!c&&B.jsx("button",{type:"button",className:"location-clear-btn",onClick:ee,disabled:ce,title:"Clear location",children:B.jsx(a,{size:16})}),N.placeName&&B.jsxs("div",{className:"location-place-name",children:[B.jsx("strong",{children:"Place:"})," ",N.placeName]}),(N.city||N.country)&&B.jsxs("div",{className:"location-address",children:[B.jsx("strong",{children:"Address:"})," ",[N.city,N.country].filter(Boolean).join(", ")]}),B.jsxs("div",{className:"location-coordinates",children:[B.jsx("strong",{children:"Coordinates:"})," ",(pe=N.latitude,he=N.longitude,void 0===pe||void 0===he||isNaN(pe)||isNaN(he)?"":`${Number(pe).toFixed(6)}, ${Number(he).toFixed(6)}`)]}),N.accuracy&&B.jsxs("div",{className:"location-accuracy",children:[B.jsx("strong",{children:"Accuracy:"})," ",(me=N.accuracy,me?`±${Math.round(me)}m`:"")]}),N.timestamp&&B.jsxs("div",{className:"location-timestamp",children:[B.jsx("strong",{children:"Captured:"})," ",new Date(N.timestamp).toLocaleString()]})]}),T&&!c&&B.jsxs("div",{className:"location-map-container",children:[B.jsxs("div",{className:"location-map-header",children:[B.jsx("h4",{children:"Select Location on Map"}),B.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),B.jsx("div",{className:"location-search",children:B.jsx("form",{onSubmit:e=>{e.preventDefault(),z.trim()&&oe(z)},className:"search-form",children:B.jsxs("div",{className:"search-input-group",children:[B.jsx("input",{type:"text",value:z,onChange:e=>{M(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:ce||q}),B.jsx("button",{type:"submit",className:"search-btn",disabled:ce||q||!z.trim(),children:q?B.jsx(u,{size:16,className:"loading-spinner"}):"Search"})]})})}),B.jsxs("div",{ref:W,className:"location-map "+(_?"dragging":""),onMouseDown:ie,onMouseMove:re,onMouseUp:se,onMouseLeave:()=>{U(!1),H(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:_?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${F}/${Math.floor((I.lng+180)/360*Math.pow(2,F))}/${Math.floor((1-Math.log(Math.tan(I.lat*Math.PI/180)+1/Math.cos(I.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,F))}.png) center/cover no-repeat`,userSelect:"none"},children:[D&&B.jsx("div",{className:"map-marker "+(D.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:B.jsx(p,{size:24})}),B.jsx("div",{className:"map-center-indicator",style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"4px",backgroundColor:"var(--df-color-primary)",borderRadius:"50%",zIndex:5}}),B.jsxs("div",{className:"map-controls",children:[B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.min(18,e+1)),disabled:F>=18,children:"+"}),B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.max(1,e-1)),disabled:F<=1,children:"−"})]})]}),B.jsxs("div",{className:"location-map-instructions",children:[B.jsx("p",{children:B.jsx("strong",{children:"Instructions:"})}),B.jsxs("ul",{children:[B.jsx("li",{children:"Search for a place using the search box above"}),B.jsx("li",{children:"Click anywhere on the map to select a location"}),B.jsx("li",{children:"Drag the map to pan around"}),B.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),B.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),Y&&B.jsxs("div",{className:"location-loading",children:[B.jsx(u,{size:16,className:"loading-spinner"}),B.jsx("span",{children:"Loading address details..."})]})]}),k&&B.jsx("div",{className:"location-error",children:k})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:h,formSubmitted:f,properties:s,localValidation:{isValid:!0,errors:{}},isTouched:A,mode:g})]});var me,pe,he},le=({id:e,properties:t,className:n="",hideLabel:i=!1})=>{const r=t.styles?.level??t.basic.level??1,s=t.basic.label,o=()=>{const e={};return t?.styles?.fontSize&&(e.fontSize=t.styles.fontSize),t?.styles?.color&&(e.color=t.styles.color),e};return i?null:(()=>{const i={id:e,className:`form-heading h${r} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${n}`.trim(),style:o()};switch(r){case 1:default:return B.jsx("h1",{...i,children:s});case 2:return B.jsx("h2",{...i,children:s});case 3:return B.jsx("h3",{...i,children:s});case 4:return B.jsx("h4",{...i,children:s});case 5:return B.jsx("h5",{...i,children:s});case 6:return B.jsx("h6",{...i,children:s})}})()},ce=({id:e,properties:s,mode:o="preview",formValue:a,onValueChange:l,className:c="",hideLabel:d=!1})=>{const[u,m]=t(""),[p,y]=t(s.validation?.listStyle||"numbers"),[v,j]=t("#000000"),N=r(null),C=r(null),w=r(!1),S="edit"===o,k=r({instructions:[],listStyle:"numbers",formValue:void 0}),$=r(o);n(()=>{let e=[],t="numbers";if(null!=a&&("object"==typeof a&&a.instructions?(Array.isArray(a.instructions)?e=a.instructions:"string"==typeof a.instructions&&(e=[a.instructions]),a.listStyle&&(t=a.listStyle)):Array.isArray(a)?e=a:"string"==typeof a&&(e=[a])),0===e.length&&s.basic?.value){const n=s.basic.value;n&&"object"==typeof n&&!Array.isArray(n)&&n.instructions?(Array.isArray(n.instructions)?e=n.instructions:"string"==typeof n.instructions&&(e=[n.instructions]),n.listStyle&&"string"==typeof n.listStyle&&(t=n.listStyle)):Array.isArray(n)?e=n:"string"==typeof n&&(e=[n])}0===e.length&&s.basic?.instructions&&(Array.isArray(s.basic.instructions)?e=s.basic.instructions:"string"==typeof s.basic.instructions&&(e=[s.basic.instructions])),t&&"numbers"!==t||(t=s.validation?.listStyle||s.basic?.value?.listStyle||"numbers");const n=JSON.stringify(e)!==JSON.stringify(k.current.instructions)||t!==k.current.listStyle,i=o!==$.current,r=JSON.stringify(a)!==JSON.stringify(k.current.formValue),l=!k.current.formValue||Array.isArray(k.current.formValue)&&0===k.current.formValue.length||"string"==typeof k.current.formValue&&""===k.current.formValue.trim(),c=null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==a.trim()||"object"==typeof a&&Object.keys(a).length>0);if(n||i||r||l&&c){const r=e=>"string"!=typeof e?e:e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))),s=e.map(e=>"string"==typeof e?r(e):e),l=s.some(e=>"string"==typeof e&&/<[^>]+>/.test(e));let c="";if(s.length>0)if(l)c=s.join("");else{const e="numbers"===t?"ol":"bullets"===t?"ul":"div",n=s.filter(e=>e&&"string"==typeof e).map(e=>`<li>${e.replace(/\n/g,"<br>")}</li>`).join("");c="div"===e?s.filter(e=>e&&"string"==typeof e).map(e=>`<div>${e.replace(/\n/g,"<br>")}</div>`).join(""):`<${e}>${n}</${e}>`}y(t),m(c),S&&N.current&&(i||n&&N.current.innerHTML.trim()!==c.trim())&&(N.current.innerHTML=c),k.current={instructions:e,listStyle:t,formValue:a},$.current=o}},[a,s.basic?.instructions,s.validation?.listStyle,o,S]),n(()=>{if(S&&N.current){const e=N.current.innerHTML.trim();u.trim()===e||w.current||(N.current.innerHTML=u)}if(w.current){const e=setTimeout(()=>{w.current=!1},200);return()=>clearTimeout(e)}},[u,S]);const A=i(()=>{if(!N.current)return;w.current=!0;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}t!==u&&m(t)},[e,p,l,u]),E=i(()=>{if(!N.current)return;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}m(t),w.current=!1},[e,p,l]),T=i((e,t)=>{document.execCommand(e,!1,t),N.current?.focus(),A()},[A]),L=i(()=>{T("bold")},[T]),I=i(()=>{T("italic")},[T]),R=i(e=>{const t=e.target.value;j(t),T("foreColor",t)},[T]),D=i(t=>{if(y(t),!N.current)return;const n=window.getSelection(),i=n&&n.rangeCount>0?n.getRangeAt(0):null;let r=N.current.innerHTML;if("numbers"===t){if(r=r.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!r.includes("<ol>")&&!r.includes("<ul>")){const e=r.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(r="<ol>"+e.map(e=>`<li>${e}</li>`).join("")+"</ol>")}}else if("bullets"===t){if(r=r.replace(/<ol>/gi,"<ul>").replace(/<\/ol>/gi,"</ul>"),!r.includes("<ol>")&&!r.includes("<ul>")){const e=r.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(r="<ul>"+e.map(e=>`<li>${e}</li>`).join("")+"</ul>")}}else r=r.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(N.current.innerHTML=r,m(r),i&&n)try{n.removeAllRanges(),n.addRange(i)}catch(e){}if(A(),l){l({id:e,value:{instructions:r?[r]:[],listStyle:t},isValid:!0,errors:{}})}},[e,A,l]),V=i(e=>{const t=e.target.files?.[0];if(!t||!t.type.startsWith("image/"))return;const n=new FileReader;n.onload=e=>{const t=e.target?.result;if(t&&N.current){const e=document.createElement("img");e.src=t,e.style.maxWidth="100%",e.style.height="auto";const n=window.getSelection();if(n&&n.rangeCount>0){const t=n.getRangeAt(0);t.deleteContents(),t.insertNode(e)}else N.current.appendChild(e);A()}},n.readAsDataURL(t),C.current&&(C.current.value="")},[A]),F=i(e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain"),n=window.getSelection();if(n&&n.rangeCount>0){const e=n.getRangeAt(0);e.deleteContents();const i=document.createTextNode(t);e.insertNode(i),e.setStartAfter(i),e.collapse(!0),n.removeAllRanges(),n.addRange(e)}A()},[A]),O=i(e=>document.queryCommandState(e),[]);return B.jsxs("div",{className:`form-group instruction-group ${c}`,children:[!d&&B.jsx("label",{htmlFor:e,className:"instruction-label",children:"Instructions"}),S?B.jsxs("div",{className:"instruction-rich-editor",children:[B.jsxs("div",{className:"instruction-toolbar",children:[B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+(O("bold")?"active":""),onClick:L,title:"Bold","aria-label":"Bold",children:B.jsx(h,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+(O("italic")?"active":""),onClick:I,title:"Italic","aria-label":"Italic",children:B.jsx(f,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsx("div",{className:"toolbar-group",children:B.jsxs("div",{className:"color-picker-wrapper",children:[B.jsx("input",{type:"color",value:v,onChange:R,className:"color-picker-input",title:"Text Color"}),B.jsx("label",{className:"color-picker-label",title:"Text Color",children:B.jsx("span",{style:{color:v},children:"A"})})]})}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===p?"active":""),onClick:()=>D("bullets"),title:"Bullet List","aria-label":"Bullet List",children:B.jsx(g,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===p?"active":""),onClick:()=>D("numbers"),title:"Numbered List","aria-label":"Numbered List",children:B.jsx(b,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>C.current?.click(),title:"Insert Image","aria-label":"Insert Image",children:B.jsx(x,{size:16})}),B.jsx("input",{ref:C,type:"file",accept:"image/*",onChange:V,style:{display:"none"}})]})]}),B.jsx("div",{ref:N,contentEditable:!0,className:"instruction-editor-content",onInput:A,onBlur:E,onPaste:F,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):B.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===p?"instruction-list-numbers":"bullets"===p?"instruction-list-bullets":""),children:u?B.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:u}}):B.jsx("div",{className:"instruction-empty",children:B.jsx("p",{children:"No instructions provided"})})})]})},de=({attachments:e,onRemove:i})=>{const[r,s]=t(new Map);return n(()=>{if(!e)return void s(e=>(e.forEach(e=>URL.revokeObjectURL(e)),new Map));const t=new Map;return e.forEach((e,n)=>{if(e.type.startsWith("image/")){const i=URL.createObjectURL(e);t.set(n,i)}}),s(e=>(e.forEach((e,n)=>{t.has(n)||URL.revokeObjectURL(e)}),t)),()=>{t.forEach(e=>URL.revokeObjectURL(e))}},[e]),e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type.startsWith("image/"),s=r.get(t);return B.jsx("div",{className:"attachment-thumbnail",children:n&&s?B.jsxs(B.Fragment,{children:[B.jsx("img",{src:s,alt:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(a,{size:14})})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"file-icon-placeholder",children:B.jsx(y,{size:20})}),B.jsx("span",{className:"file-name",children:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(a,{size:14})})]})},t)})}):null},ue=({component:e,mode:s,formTemplateId:o,formValue:a,onNotesChange:l,onAttachmentChange:c,notes:u="",attachments:m=null,onThresholdActionCompletion:p,onThresholdIssueRaised:h,onBasicPropertyActionCompletion:f})=>{const[g,b]=t(u||""),[x,S]=t(m||null),[k,$]=t(!1),[A,E]=t(!1),[T,L]=t(!1),[I,R]=t(!1),[D,V]=t(!1),F=r(null),O=r(a),z=r(!1),M=r(!1);n(()=>{if(!z.current&&null!=u){const e="string"==typeof u?u:String(u||"");b(e),z.current=!0}},[u]),n(()=>{M.current||void 0===m||(S(m),M.current=!0)},[m]),n(()=>{if(z.current&&!k&&null!=u){const e="string"==typeof u?u:String(u||"");g&&""!==String(g||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==g&&b(e):b(e)}},[u,k,g]),n(()=>{M.current&&void 0!==m&&(!x||m&&m.length>0&&m!==x)&&S(m)},[m,x]),n(()=>{const t=["select","radio","checkbox","segment"].includes(e.name||"");if(t){const t=O.current,n=a;let i=!1;if("checkbox"===e.name){const e=Array.isArray(t)?t:t?[t]:[],r=Array.isArray(n)?n:n?[n]:[];i=JSON.stringify(e.sort())!==JSON.stringify(r.sort())}else i=t!==n&&void 0!==t;if(i){L(!1),R(!1),E(!1),$(!1),V(!1);const e="string"==typeof u?u:String(u||"");e&&""!==e.trim()?b(e):b(""),m&&0!==m.length?S(m):S(null)}O.current=n}t||(O.current=a)},[a,e.name,u,m]);const q=i((e,t)=>{const{operator:n,value:i}=e,r=String(t).toLowerCase(),s=String(i).toLowerCase();switch(n){case"equals":return r===s||String(t)===String(i);case"notEquals":return r!==s&&String(t)!==String(i);case"greaterThan":return Number(t)>Number(i);case"lessThan":return Number(t)<Number(i);case"greaterThanOrEqual":return Number(t)>=Number(i);case"lessThanOrEqual":return Number(t)<=Number(i);default:return!1}},[]),P=i(()=>{if(!(null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length)))return[];const t=e.condition;if(!t||!t.conditions||0===t.conditions.length)return[];const n=[];if("checkbox"===e.name&&Array.isArray(a))a.forEach(e=>{const i=t.conditions.find(t=>q(t,e));i&&!n.find(e=>e.id===i.id)&&n.push(i)});else{const e=t.conditions.find(e=>q(e,a));e&&n.push(e)}return n},[e,a,q]),W=i(t=>{const n=t.target.value;b(n),l&&l(n);const i=P(),r=String(n||"").trim().length>0;i.forEach(e=>{!0===e.enableNotes&&p&&p(e.id,"notes",r)});const s=e.condition;!(s&&s.conditions&&s.conditions.length>0)&&f&&f("notes",r)},[l,P,p,e,f]),_=i(()=>{if(l){const e="string"==typeof g?g:String(g||"");l(e),setTimeout(()=>{$(!1)},0)}else $(!1)},[g,l]),U=i(()=>{_()},[_]),G=i(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),_())},[_]),H=i(()=>{$(!0)},[]),J=i(()=>{$(!0)},[]),Y=i(()=>{F.current?.click()},[]),X=i(t=>{const n=t.target.files;if(n&&n.length>0){const t=Array.from(n);S(t),c&&c(t);P().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!0)});const i=e.condition;!(i&&i.conditions&&i.conditions.length>0)&&f&&f("attachments",!0)}F.current&&(F.current.value="")},[c,P,p,e,f]),Z=i(t=>{if(x){const n=x.filter((e,n)=>n!==t);if(0===n.length){S(null),c&&c(null);P().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!1)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("attachments",!1)}else S(n),c&&c(n)}},[x,c,P,p,e,f]),Q=i(()=>{L(!0);P().forEach(e=>{!0===e.enableSendEmail&&p&&p(e.id,"email",!0)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("email",!0),setTimeout(()=>{L(!1)},3e3)},[P,p,e,f]),ee=i(()=>{E(!0)},[]),te=i(()=>{E(!1)},[]),ne=i(()=>{E(!1),R(!0);const t=e.condition;if(t&&t.conditions&&t.conditions.length>0){P().forEach(e=>{!0===e.enableRaiseIssue&&h&&h(e.id)})}else f&&f("issue",!0)},[e,f,P,h]);if("test"!==s)return null;const ie=["select","radio","checkbox","segment"].includes(e.name||""),re=e.basic?.options||e.options||[];let se=!1,oe=!1,ae=!1,le=!1,ce=null;const ue=null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length),me=e.condition,pe=me&&me.conditions&&me.conditions.length>0;if(pe&&ue)if("checkbox"===e.name&&Array.isArray(a)){const e=a;for(const t of e){const e=me.conditions.find(e=>q(e,t));e&&(se=se||!0===e.enableNotes,oe=oe||!0===e.enableAttachment,ae=ae||!0===e.enableRaiseIssue,le=le||!0===e.enableSendEmail)}}else if(ie){const e=me.conditions.find(e=>q(e,a));e&&(se=!0===e.enableNotes,oe=!0===e.enableAttachment,ae=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}else{const e=me.conditions.find(e=>q(e,a));e&&(se=!0===e.enableNotes,oe=!0===e.enableAttachment,ae=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}if(!pe){const t=e.basic,n=!0===t?.enableNotes,i=!0===t?.enableAttachment,r=!0===t?.enableRaiseIssue,s=!0===t?.enableSendEmail;if(ie)if(ue)if("checkbox"===e.name){(Array.isArray(a)?a:[a]).forEach(e=>{const t=re.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(se=se||!0===t.enableNotes,oe=oe||!0===t.enableAttachment,ae=ae||!0===t.enableRaiseIssue,le=le||!0===t.enableSendEmail,ce||(ce=t))}),se=se||n,oe=oe||i,ae=ae||r,le=le||s}else if(ce=re.find(e=>!(!e||!e.value)&&(e.value===a||(String(e.value)===String(a)||(e.label===a||String(e.label)===String(a))))),ce){const e=!0===ce.enableNotes,t=!0===ce.enableAttachment,o=!0===ce.enableRaiseIssue,a=!0===ce.enableSendEmail;se=e||n,oe=t||i,ae=o||r,le=a||s}else se=n,oe=i,ae=r,le=s;else se=n,oe=i,ae=r,le=s;else se=n,oe=i,ae=r,le=s}if(!(se||oe||ae||le))return null;const he=P(),fe=e.condition,ge=fe&&fe.conditions&&fe.conditions.length>0,be=!!ge&&he.some(e=>!0===e.enableNotes),xe=!!ge&&he.some(e=>!0===e.enableAttachment),ye=!!ge&&he.some(e=>!0===e.enableSendEmail),ve=!!ge&&he.some(e=>!0===e.enableRaiseIssue),je=String(g||"").trim().length>0,Ne=x&&x.length>0,Ce=x?x.length:0;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"component-action-features",children:[B.jsxs("div",{className:"action-icons-toolbar",children:[se&&B.jsxs("button",{type:"button",className:`action-icon-button ${je?"active":""} ${be?"mandatory":""}`,onClick:H,title:"Add Notes",children:[B.jsx(d,{size:14,fill:je?"currentColor":"none"}),be&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),oe&&B.jsxs("button",{type:"button",className:`action-icon-button ${Ne?"active":""} ${xe?"mandatory":""}`,onClick:Y,title:"Add Attachment",children:[B.jsx(y,{size:14,fill:Ne?"currentColor":"none"}),Ce>0&&B.jsx("span",{className:"attachment-count-badge",children:Ce}),xe&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),le&&B.jsxs("button",{type:"button",className:`action-icon-button ${T?"active sent":""} ${ye?"mandatory":""}`,onClick:Q,disabled:T,title:"Send Email",children:[T?B.jsx(B.Fragment,{children:B.jsx(v,{size:14})}):B.jsx(j,{size:14,fill:T?"currentColor":"none"}),ye&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ae&&B.jsxs("button",{type:"button",className:`action-icon-button ${I?"active":""} ${ve?"mandatory":""}`,onClick:ee,title:"Raise an Issue",children:[B.jsx(N,{size:14,fill:I?"currentColor":"none"}),ve&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(je&&se||Ne&&oe)&&B.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>V(!D),title:D?"Collapse":"Expand",children:D?B.jsx(C,{size:14}):B.jsx(w,{size:14})})]}),k&&se&&B.jsxs("div",{className:"notes-input-overlay",children:[B.jsx("textarea",{className:"action-notes-textarea",value:g,onChange:W,onBlur:U,onKeyDown:G,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),B.jsxs("div",{className:"notes-input-actions",children:[B.jsx("button",{type:"button",className:"notes-save-button",onClick:_,title:"Save notes (Ctrl+Enter)",children:"Save"}),B.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{$(!1)},title:"Cancel",children:"Cancel"})]})]}),D&&B.jsxs("div",{className:"actions-content",children:[!k&&je&&se&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",onClick:J,children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",g]})}),Ne&&oe&&B.jsx("div",{className:"attachments-section",children:B.jsx(de,{attachments:x,onRemove:Z})})]}),oe&&B.jsx("input",{ref:F,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:X,style:{display:"none"}})]}),A&&B.jsx(K,{isOpen:A,onClose:te,onSuccess:ne,component:ce?{...e,basic:{...e.basic,label:`${e.basic?.label||"Component"} - ${ce.label||ce.value}`,value:ce.value||e.basic?.value||""}}:e,formTemplateId:o||"",notes:g,attachments:x})]})},me=({attachments:e})=>e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type?.startsWith("image/")||!1,i=n?(e=>e.data?e.data.startsWith("data:")?e.data:`data:${e.type||"image/png"};base64,${e.data}`:"")(e):"";return B.jsx("div",{className:"attachment-thumbnail",children:n&&i?B.jsx("img",{src:i,alt:e.name||`Attachment ${t+1}`}):B.jsxs("div",{className:"file-icon-placeholder",children:[B.jsx(y,{size:20}),B.jsx("span",{className:"file-name",children:e.name||`File ${t+1}`})]})},t)})}):null,pe=({component:e})=>{const t=e.basic?.notes||"",n=e.basic?.attachments||[],i=t&&t.trim().length>0,r=n&&n.length>0;return i||r?B.jsx("div",{className:"component-submission-actions",children:B.jsxs("div",{className:"actions-content",children:[i&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",t]})}),r&&B.jsx("div",{className:"attachments-section",children:B.jsx(me,{attachments:n})})]})}):null},he=({child:e,selectedChild:t,mode:n,onChildSelect:i,onChildDelete:r,renderFormComponent:s,isOverlay:o=!1,isChildrenEditMode:a=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:g,listeners:b,setNodeRef:x,transform:y,transition:v,isDragging:j,isSorting:N}=V({id:e.id,disabled:o||"edit"!==n}),C={transform:O.Transform.toString(y),transition:v,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:x,style:C,className:`form-component section-child ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""} ${a?"children-edit-active":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:[("edit"===n||a)&&B.jsx("div",{className:"child-drag-handle",...b,...g,onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:B.jsx(k,{size:14})}),B.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===n||a)&&B.jsxs("div",{className:"component-actions child-actions",children:[B.jsx("button",{className:"btn edit-btn",onClick:t=>{t.stopPropagation(),i(e)},onMouseDown:e=>e.stopPropagation(),title:"Edit properties",children:B.jsx($,{size:12})}),B.jsx("button",{className:"btn delete-btn",onClick:t=>r(e,t),onMouseDown:e=>e.stopPropagation(),title:"Delete component",children:B.jsx(A,{size:12})})]}),B.jsxs("div",{className:"component-preview child-preview",children:[s(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]})]})]})},fe=({id:e,properties:r,mode:s="edit",formData:o={},onValueChange:a,onSelect:l,isSelected:c=!1,className:d="",onSectionSelect:u,onChildSelect:m,onChildDelete:p,selectedChild:h,renderFormComponent:f,formTemplateId:g,onThresholdActionCompletion:b,onThresholdIssueRaised:x,onNotesChange:y,onAttachmentChange:v})=>{const[j,N]=t(r.basic.collapsed),[C,k]=t(!1),[$,A]=t(!1),[E,T]=t(r.basic.label),[L,V]=t(r.basic.description),[F,O]=t(r.children||[]),[z,M]=t(!1);n(()=>{O(r.children||[])},[r.children]),n(()=>{T(r.basic.label),V(r.basic.description)},[r.basic.label,r.basic.description]);const{setNodeRef:q,isOver:P}=I({id:`section-${e}`,disabled:"edit"!==s}),W=!("preview"!==s&&"test"!==s||r.children&&r.children.length>0),_=i(t=>{T(t),a?.({id:e,value:{...r,basic:{...r.basic,label:t}}})},[e,r,a]),U=i(t=>{V(t),a?.({id:e,value:{...r,basic:{...r.basic,description:t}}})},[e,r,a]),G=i(e=>{m?.(e)},[m]),H=i((e,t)=>{t.stopPropagation();const n=F.filter(t=>t.id!==e.id);O(n),p?.(e.id)},[p,F,e]),J=i(()=>{u?.(r),l?.()},[u,l,r]),Y=i(e=>{e.stopPropagation(),"edit"===s&&F.length>0&&M(!z)},[s,F.length,z]),K=i(t=>{t.stopPropagation(),N(!j),a?.({id:e,value:{...r,basic:{...r.basic,collapsed:!j}}})},[j,e,r,a]),X=f||i(e=>{const t=o[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let n=t;"number-input"===e.name&&"number"==typeof t?n=String(t):"number-input"===e.name&&null==t&&(n="");const i={id:e.id,properties:e,validationErrors:{},formValue:n,touchedFields:{},formSubmitted:!1,mode:s,onValueChange:a,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...i,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...i,properties:e,readonly:!1,disabled:!1});case"select":const t={...e,options:e.basic?.options||[]};return B.jsx(ee,{...i,properties:t,disabled:!1});case"checkbox":const n={...e,options:e.basic?.options||[]};return B.jsx(te,{...i,properties:n,formValue:[],disabled:!1});case"radio":const r={...e,options:e.basic?.options||[]};return B.jsx(ne,{...i,properties:r,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...i,properties:e,readonly:!1,disabled:!1});case"signature":return B.jsx(se,{...i,properties:e});case"heading":return B.jsx(le,{...i,properties:e});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}},[s,a,o]);if(W)return null;const ie={backgroundColor:r.styles?.backgroundColor||"var(--df-color-fb-container)",borderColor:r.styles?.borderColor||"var(--df-color-fb-border)",borderWidth:r.styles?.borderWidth||"2px",borderRadius:r.styles?.borderRadius||"8px",padding:r.styles?.padding||"16px",margin:r.styles?.margin||"16px 0"};return B.jsxs("div",{ref:q,className:`df-form-section ${c?"selected":""} ${P?"drag-over":""} ${d}`,style:ie,children:[B.jsxs("div",{className:"section-header "+(z?"children-edit-mode":""),onClick:J,onDoubleClick:Y,children:[B.jsx("div",{className:"section-header-content",children:B.jsxs("div",{className:"section-title",children:[B.jsx("span",{className:"section-toggle",title:j?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),K(e)},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),K(e))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:j?B.jsx(S,{size:18}):B.jsx(w,{size:18})}),"edit"===s&&C?B.jsx("input",{type:"text",value:E,onChange:e=>T(e.target.value),onBlur:()=>{k(!1),_(E)},onKeyDown:e=>{"Enter"===e.key&&(k(!1),_(E))},className:"section-title-input",autoFocus:!0}):B.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===s&&k(!0),style:{display:"inline",margin:0},children:E||"Untitled Section"})]})}),(L||"edit"===s)&&B.jsx("div",{className:"section-description",children:"edit"===s&&$?B.jsx("textarea",{value:L,onChange:e=>V(e.target.value),onBlur:()=>{A(!1),U(L)},onKeyDown:e=>{"Enter"===e.key&&e.ctrlKey&&(A(!1),U(L))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):B.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===s&&A(!0),children:L||"Section description"})})]}),!j&&B.jsx("div",{className:`section-content ${P?"drag-over":""} ${0===F.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&J()},children:B.jsx(R,{items:F.map(e=>e.id),strategy:D,children:0===F.length?B.jsxs("div",{className:"section-empty-state",onClick:J,style:{textAlign:"center",color:"#6b7280",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",cursor:"pointer",border:"2px dotted #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",transition:"all 0.3s ease",margin:"16px 0"},children:[B.jsx("div",{style:{fontWeight:"500",color:P?"#3b82f6":"#374151"},children:P?"Drop components here":"Empty Section"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):F.map(e=>B.jsx(he,{child:e,selectedChild:h||null,mode:s,onChildSelect:G,onChildDelete:H,renderFormComponent:X,isChildrenEditMode:z,formData:o,formTemplateId:g,onNotesChange:y,onAttachmentChange:v,onThresholdActionCompletion:b,onThresholdIssueRaised:x},e.id))})})]})},ge=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:r,onComponentEdit:s,renderFormComponent:o,isOverlay:a=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:g,listeners:b,setNodeRef:x,transform:y,transition:v,isDragging:j,isSorting:N}=V({id:e.id,disabled:a}),C={transform:O.Transform.toString(y),transition:v,opacity:j?.3:1,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:x,style:{...C,border:t?.id===e.id?"2px solid #3b82f6":"1px solid var(--df-color-fb-border)",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",padding:"12px",position:"relative",minHeight:"80px",transition:"all 0.2s ease",boxShadow:t?.id===e.id?"0 4px 12px rgba(59, 130, 246, 0.15)":"0 1px 3px rgba(0, 0, 0, 0.1)",cursor:"pointer"},className:`form-component grid-component ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...b,...g,onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"50%",left:"4px",transform:"translateY(-50%)",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"4px",cursor:"grab",opacity:1,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:B.jsx(k,{size:12,color:"var(--df-color-text-light)"})}),B.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===n?"24px":"0",paddingLeft:"edit"===n?"28px":"0",minHeight:"60px"},children:[o(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[s&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),s(e)},type:"button",title:"Edit Component",style:{padding:"4px",backgroundColor:"#3b82f6",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#3b82f6"},children:B.jsx($,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),r(e,t)},type:"button",title:"Delete Component",style:{padding:"4px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#ef4444"},children:B.jsx(A,{size:12})})]})]})},be=({gridComponents:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,onComponentUpdate:s,selectedComponent:o,renderFormComponent:a,gridId:l,formData:c={},formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})=>{const{setNodeRef:f,isOver:g}=I({id:`grid-drop-zone-${l}`,disabled:"edit"!==t});return B.jsx("div",{ref:f,className:"grid-drop-zone",style:{border:g?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:g?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?B.jsxs(B.Fragment,{children:[B.jsx(R,{items:e.map(e=>e.id),strategy:F,children:B.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:e.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:e.map(e=>B.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:B.jsx(ge,{component:e,selectedComponent:o,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,onComponentUpdate:s,renderFormComponent:a,formData:c,formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})},e.id))})}),B.jsx("div",{style:{border:g?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:g?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:g?B.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):B.jsx("span",{children:"+ Drop more components here"})})]}):B.jsxs("div",{style:{textAlign:"center",color:"var(--df-color-text-light)",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed var(--df-color-fb-border)",borderRadius:"8px"},children:[B.jsx("div",{style:{fontWeight:"500",color:g?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:g?"Drop components here":"Empty DataGrid"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},xe=({templateComponents:e,dataEntries:t,renderFormComponent:n,renderComponent:i,mode:r="preview",allowAddRemoveEntries:s=!0,addAnotherText:o="Add Another",removeText:a="Remove",maxEntries:l=10,minEntries:c=1,displayAsGrid:d=!0,onAddEntry:u,onRemoveEntry:m,formData:p={},formTemplateId:h,onThresholdActionCompletion:f,onThresholdIssueRaised:g,onNotesChange:b,onAttachmentChange:x,datagridId:y=""})=>0===e.length?B.jsxs("div",{style:{textAlign:"center",padding:"40px",color:"var(--df-color-text-light)",border:"1px dashed #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)"},children:["No components defined. Add components to see the ",d?"table":"list"," view."]}):d?B.jsxs("div",{className:"datagrid-table-view",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",backgroundColor:"var(--df-color-fb-container)",maxWidth:"100%"},children:[B.jsx("div",{style:{position:"absolute",top:"8px",right:"8px",zIndex:10,fontSize:"12px",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",padding:"4px 8px",borderRadius:"4px",border:"1px solid var(--df-color-fb-border)",opacity:e.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),B.jsxs("div",{className:"table-scroll-container",style:{overflowX:"auto",overflowY:"hidden",maxWidth:"100%",scrollbarWidth:"thin",scrollbarColor:"var(--df-color-fb-border) var(--df-color-fb-icon-bg)",position:"relative"},children:[B.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*e.length+"px"},children:e.map((t,n)=>B.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:n<e.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.basic?.label||`Column ${n+1}`},`header-${t.id}`))}),t.length>0?t.map((r,o)=>B.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:o<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:o%2==0?"var(--df-color-fb-container)":"var(--df-color-fb-bg)",position:"relative",minWidth:150*e.length+"px",isolation:"isolate"},children:[e.map((t,s)=>{let a=r.components?.[s];const l=`${t.id||`component-${s}`}-entry-${y}-${o}-${s}`;return a=a?a.id!==l?{...a,id:l,basic:{...a.basic,showLabel:!1}}:{...a,id:a.id,basic:{...a.basic,showLabel:!1}}:{...t,id:l,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsx("div",{style:{padding:"12px 16px",borderRight:s<e.length-1?"1px solid var(--df-color-fb-border)":"none",minHeight:"60px",minWidth:"150px",display:"flex",alignItems:"center",overflow:"visible",position:"relative",zIndex:1},children:B.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:i?i(a,!0):n(a,!0)})},`${r.id}-${s}`)}),s&&t.length>c&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(o)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",zIndex:1e3,minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto"},title:a,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},r.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",borderTop:"1px solid var(--df-color-fb-border)"},children:["No data entries. ",s?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]})]}),s&&B.jsx("div",{style:{padding:"16px",backgroundColor:"var(--df-color-fb-bg)",borderTop:"1px solid var(--df-color-fb-border)",display:"flex",justifyContent:"center",position:"sticky",bottom:0,zIndex:5},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{style:{fontSize:"16px"},children:"+"}),o]})})]}):B.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[t.length>0?t.map((o,l)=>B.jsxs("div",{className:"list-entry",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",padding:"16px",backgroundColor:"var(--df-color-fb-container)",position:"relative",transition:"all 0.2s ease"},children:[B.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[B.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",l+1]}),s&&t.length>1&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(l)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},title:a,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),B.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:e.map((e,t)=>{let s=o.components?.[t];const a=`${e.id||`component-${t}`}-entry-${y}-${l}-${t}`;return s||(s=o.components?.find(t=>t.name===e.name&&t.basic?.label===e.basic?.label)),s=s?s.id!==a?{...s,id:a,basic:{...s.basic,showLabel:!1}}:{...s,id:s.id,basic:{...s.basic,showLabel:!1}}:{...e,id:a,basic:{...e.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[B.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:e.basic?.label||`Field ${t+1}`}),B.jsxs("div",{style:{minHeight:"40px",display:"flex",alignItems:"center",flexDirection:"column",width:"100%"},children:[i?i(s):n(s),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(s.name)&&B.jsx(ue,{component:s,mode:"test",formTemplateId:h,formValue:p[s.id],onThresholdActionCompletion:f,onThresholdIssueRaised:g,onNotesChange:b?e=>b(s.id,e):void 0,onAttachmentChange:x?e=>x(s.id,e):void 0}),"preview"===r&&(s.basic?.notes&&s.basic.notes.trim().length>0||s.basic?.attachments&&Array.isArray(s.basic.attachments)&&s.basic.attachments.length>0?B.jsx(pe,{component:s}):null)]})]},`${o.id}-${t}`)})})]},o.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed #d1d5db",borderRadius:"8px"},children:["No data entries. ",s?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]}),"test"===r&&s&&B.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{children:"+"}),o]})})]}),ye=({id:e,properties:s,mode:o="edit",formData:a={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onDataGridSelect:f,onComponentSelect:g,onComponentDelete:b,onComponentEdit:x,onComponentUpdate:y,selectedComponent:v,renderFormComponent:j,onEntryAdd:N,onEntryRemove:C,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L})=>{const[I,R]=t(!1),D=r(!1);let V=s.templateComponents||[];const F=s.entries||[];0===V.length&&F.length>0&&F[0].components&&(V=F[0].components.map(e=>({...e,id:e.id?.replace(/-entry-\d+$/,"")||e.id,basic:{...e.basic,showLabel:!0}}))),n(()=>{if("edit"===o&&!s.templateComponents&&u&&D.current){const t={...s,templateComponents:[]};JSON.stringify(t)!==JSON.stringify(s)&&u({id:e,value:t})}D.current=!0},[s.templateComponents,e,u,s,o]),n(()=>{if(V.length>0){if("test"===o&&0===F.length&&D.current){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...s,entries:[t]};JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n})}return}if("edit"!==o||!D.current)return;if(F.some(e=>e.components?.some((t,n)=>{const i=`${V[n]?.id}-entry-${e.index}-${n}`;return t.id!==i}))&&u){const t=F.map(e=>({...e,components:e.components?.map((t,n)=>({...t,id:`${V[n]?.id}-entry-${e.index}-${n}`}))||[]})),n={...s,entries:t};return void(JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n}))}if(0===F.length&&"edit"===o){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...s,entries:[t]};JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n})}}else if(F.length>0){if(F.some(e=>V.some((t,n)=>{const i=e.components?.[n];if(!i)return!0;const r=`${t.id}-entry-${e.index}-${n}`,s=i.id===r,o=JSON.stringify(i.basic?.options)!==JSON.stringify(t.basic?.options)||i.basic?.placeholder!==t.basic?.placeholder||i.basic?.defaultValue!==t.basic?.defaultValue||i.basic?.label!==t.basic?.label||i.validation?.required!==t.validation?.required;return!s||o}))&&u){const t=F.map(t=>{const n=V.map((n,i)=>{let r=t.components?.[i];r||(r=t.components?.find(e=>e.name===n.name&&e.basic?.label===n.basic?.label));const s=`${n.id||`component-${i}`}-entry-${e}-${t.index}-${i}`;if(r){return{...n,id:s,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}return{...n,id:s,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}});return{...t,components:n}}),n={...s,entries:t};JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n})}}}},[V,F,e,u,s,o,s.templateComponents]);const O=i(e=>{e.stopPropagation(),m?.(),f?.(s)},[m,f,s]),z=i((t,n)=>{n.stopPropagation(),b&&b(t,n);const i=V.filter(e=>e.id!==t.id),r=F.map(e=>({...e,components:e.components?.filter(e=>!(e.name===t.name&&e.basic?.label===t.basic?.label))||[]}));u&&u({id:e,value:{...s,templateComponents:i,entries:r}})},[b,s,u,e,V,F]),M=i((t,n)=>{y&&y(t,n);const i=V.map(e=>e.id===t?{...e,...n}:e);u&&u({id:e,value:{...s,templateComponents:i}})},[y,s,u,e,V]),q=i(e=>{"test"===o&&u&&u({id:e.id,value:e.value})},[u]),P=i(()=>{const t=s.entries||[],n=t.length,i={id:`entry-${e}-${n}`,index:n,components:V.map((t,i)=>{const r=`${t.id||`component-${i}`}-entry-${e}-${n}-${i}`;return{...t,id:r,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}},r=[...t,i];u&&u({id:e,value:{...s,entries:r}}),N?.()},[s,u,e,N,V]),W=i(t=>{const n=s.entries.filter((e,n)=>n!==t).map((t,n)=>({...t,index:n,id:`entry-${e}-${n}`}));u&&u({id:e,value:{...s,entries:n}})},[s,u,e,C]),_=i((e,t=!1)=>{const n=a[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let i=n;"number-input"===e.name&&"number"==typeof n?i=String(n):"number-input"===e.name&&null==n&&(i="");const r={id:e.id,properties:e,validationErrors:l||{},formValue:i,touchedFields:c||{},formSubmitted:d||!1,mode:o,hideLabel:t,onValueChange:q,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...r,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1,hideLabel:t});case"textarea":return B.jsx(Q,{...r,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"select":const n={...e,options:e.basic?.options||[]};return B.jsx(ee,{...r,properties:n,disabled:!1,hideLabel:t});case"checkbox":const i={...e,options:e.basic?.options||[]};return B.jsx(te,{...r,properties:i,formValue:[],disabled:!1,hideLabel:t});case"radio":const s={...e,options:e.basic?.options||[]};return B.jsx(ne,{...r,properties:s,readonly:!1,disabled:!1,hideLabel:t});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...r,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"signature":return B.jsx(se,{...r,properties:e,hideLabel:t});case"heading":return B.jsx(le,{...r,properties:e,hideLabel:t});case"instructions":return B.jsx(ce,{...r,properties:e,hideLabel:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",e.name]})}},[o,q,a,l,c,d]),U={backgroundColor:s.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:s.styles.borderColor||"var(--df-color-fb-border)",borderWidth:s.styles.borderWidth||"2px",borderRadius:s.styles.borderRadius||"8px",padding:s.styles.padding||"16px",margin:s.styles.margin||"16px 0"};return B.jsxs("div",{className:`form-group df-form-datagrid ${p?"selected":""} ${h}`,onClick:O,style:U,children:[B.jsx("div",{className:"grid-header",children:B.jsx("div",{className:"grid-title",onClick:t=>{t.stopPropagation(),R(!I),u?.({id:e,value:{...s,basic:{...s.basic,collapsed:!I}}})},children:B.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[I?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(E,{size:16}),B.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:s.basic.label}),s.validation.required&&B.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),s.basic.description&&!I&&B.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:s.basic.description}),!I&&B.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===o?B.jsx(be,{gridComponents:V,mode:o,onComponentSelect:g||(()=>{}),onComponentDelete:z,onComponentEdit:x,onComponentUpdate:M,selectedComponent:v||null,renderFormComponent:j||_,gridId:e,formData:a,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L}):B.jsx(xe,{templateComponents:V,dataEntries:F,renderFormComponent:j||_,mode:o,allowAddRemoveEntries:s.datagrid?.allowAddRemoveEntries??!0,addAnotherText:s.datagrid?.addAnotherText??"Add Entry",removeText:s.datagrid?.removeText??"Remove",maxEntries:s.datagrid?.maxEntries??10,minEntries:s.datagrid?.minEntries??1,displayAsGrid:s.datagrid?.displayAsGrid??!0,onAddEntry:N||P,onRemoveEntry:C||W,formData:a,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L,datagridId:e})})]})},ve=e.lazy(()=>Promise.resolve().then(function(){return Ae})),je=({formComponents:s=[],currentDevice:o="desktop",isPreviewMode:a=!1,initialFormData:l=[],onSubmit:c,onFormDataChange:d,formTitle:u,formDescription:m,formTemplateId:p,onComponentSelect:h,onComponentDelete:f,onComponentEdit:g,onComponentUpdate:b,selectedComponent:x,workOrderNumber:y,assetNumber:v})=>{const[j,N]=t({}),[C,w]=t({}),[S,k]=t(!1),[$,A]=t({}),[E,T]=t({}),[L,I]=t(new Set),[R,D]=t(new Map),[V,F]=t({isValid:!0});n(()=>{z()},[s,l]);const O=(e,t)=>{e.forEach(e=>{if(e.id&&("value"in e.basic&&void 0!==e.basic.value?t[e.id]=e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?t[e.id]=e.basic.defaultValue:"checkbox"===e.name||"select"===e.name?t[e.id]=[]:t[e.id]=""),e.cells&&Array.isArray(e.cells)&&e.cells.forEach((e,n)=>{Array.isArray(e)&&e.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&O(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&O(e.components,t)}),"file"===e.name&&e.basic){const n=e.basic.files||e.basic.attachments||e.basic.value;n&&(t[e.id]=n)}if("instructions"===e.name&&e.basic){e.basic.instructions||(e.basic.instructions=[]);const n=e.basic.value||e.basic.instructions;n&&(t[e.id]=n)}e.children&&Array.isArray(e.children)&&O(e.children,t)})},z=i(()=>{const e={},t=new Set,n=e=>{e.forEach((e,i)=>{if(e.id&&"string"==typeof e.id&&""!==e.id.trim())t.has(e.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${e.id}. Component:`,e),e.id=`${e.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${e.id}`));else{const t=e.name||"component",n=(e.basic?.label||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);e.id=`${t}-${n||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${i}`}t.add(e.id),e.children&&Array.isArray(e.children)&&n(e.children),e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})})};s&&s.length>0&&n(s),l&&l.length>0&&n(l),l&&l.length>0&&O(l,e),s&&s.length>0&&O(s,e),N(e),q()},[l,s]),M=(e,t)=>{e.forEach(e=>{if(e.id)if("table"===e.name||"datagrid"===e.name)t[e.id]=!0;else if(e.conditional){const n=G.evaluateConditionalLogic(e.conditional,s,j);t[e.id]=n.shouldShow}else t[e.id]=!0;e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{e.forEach(e=>{e.components&&Array.isArray(e.components)&&M(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&M(e.components,t)}),e.children&&Array.isArray(e.children)&&M(e.children,t)})},q=i(()=>{const e={};s&&s.length>0&&M(s,e),T(e)},[s,j]),P=i(e=>{const t=s.find(t=>t.id===e);if(t&&("table"===t.name||"datagrid"===t.name))return!0;return!1!==E[e]},[E,s]),W=i(e=>{if(!e.id||"string"!=typeof e.id||""===e.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",e);const t=s.filter(t=>t.id===e.id);if(t.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${e.id}":`,t.map(e=>({id:e.id,name:e.name,label:e.basic?.label})));const n=j[e.id];void 0!==n&&n!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:n,newValue:e.value});const i={...j,[e.id]:e.value};N(i);const r=s.find(t=>t.id===e.id);if(r){const e=r?.threshold;e&&e.conditions&&e.conditions.length>0&&I(t=>{const n=new Set(t);return e.conditions.forEach(e=>{n.delete(e.id)}),n})}const o=t=>t.map(t=>t.id===e.id&&"defaultValue"in t.basic?{...t,basic:{...t.basic,value:e.value??t.basic.defaultValue,defaultValue:e.value}}:"section"===t.name&&t.children?{...t,children:o(t.children)}:"table"===t.name&&t.cells?{...t,cells:t.cells.map(e=>e.map(e=>{const t={...e};return t.components&&(t.components=o(t.components)),t}))}:"datagrid"===t.name&&t.entries?{...t,entries:t.entries.map(e=>{const t={...e};return t.components&&(t.components=o(t.components)),t})}:t),l=o(s);if(d?.(l),C[e.id]&&w(t=>({...t,[e.id]:""})),!a){if(e.isValid)return void w(t=>{const n=t[e.id];return n&&""!==n.trim()?{...t,[e.id]:""}:t});setTimeout(()=>{U(e.id)},150)}setTimeout(()=>{const e={};s.forEach(t=>{if("table"===t.name||"datagrid"===t.name)e[t.id]=!0;else if(t.conditional){const n=G.evaluateConditionalLogic(t.conditional,s,i);e[t.id]=n.shouldShow}else e[t.id]=!0}),T(e)},0)},[s,j,C,d]),_=i((e,t)=>{for(const n of e){if(n.id===t)return n;if("section"===n.name&&n.children){const e=_(n.children,t);if(e)return e}if("table"===n.name&&n.cells)for(const e of n.cells)for(const n of e)if(n.components){const e=_(n.components,t);if(e)return e}if("datagrid"===n.name&&n.entries)for(const e of n.entries)if(e.components){const n=_(e.components,t);if(n)return n}}return null},[]),U=i(e=>{if(a)return;const t=_(s,e);if(!t)return;const n=j[e]||"";if("number-input"===t.name&&(!n||""===n)){if(t.validation.required){const n=t.validation.customValidationMessage,i=t.basic.label||"This field",r=n||`${i} is required`;w(t=>({...t,[e]:r}))}else w(t=>({...t,[e]:""}));return}let i=!1;i=Array.isArray(n)?n.length>0:"string"==typeof n?""!==n.trim():null!=n;let r="";if(t.validation.required&&!i){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} is required`}else if("email-input"===t.name&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} must be a valid email`}else if(t.validation.minLength&&i&&n.length<t.validation.minLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} must be at least ${t.validation.minLength} characters`}else if(t.validation.maxLength&&i&&n.length>t.validation.maxLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} must be no more than ${t.validation.maxLength} characters`}else if("number-input"===t.name&&i){const e=String(n).trim(),i=parseFloat(e);if(!isNaN(i)){const e=t.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&i<e.lowerLimit?r="Number is below the lower limit":e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&i>e.upperLimit&&(r="Number is above the upper limit")}}w(t=>({...t,[e]:r}))},[s,a,j,_]),J=i(e=>{A(t=>({...t,[e]:!0})),a||setTimeout(()=>{U(e)},0)},[a,U]),Y=i(e=>{C[e]&&w(t=>({...t,[e]:""}))},[C]),K=i(()=>!Object.values(C).some(e=>e&&"string"==typeof e&&""!==e.trim())&&s.every(e=>{const t=j[e.id]||"";let n=!1;if(n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!n)return!1;if("number-input"===e.name&&n){const n=String(t).trim(),i=parseFloat(n);if(!isNaN(i)){const t=e.validation;if(t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&i<t.lowerLimit)return!1;if(t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&i>t.upperLimit)return!1}}return!0}),[s,j,C]),X=i((e,t)=>{if(Array.isArray(t))return t.some(t=>X(e,t));if(null==t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(!isNaN(n)&&!isNaN(i))switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}const r=String(t).toLowerCase(),s=String(e.value).toLowerCase();switch(e.operator){case"equals":return r===s||String(t)===String(e.value);case"notEquals":return r!==s&&String(t)!==String(e.value);default:return!1}},[]),de=i(()=>{if(a)return[];const e=[];return s.forEach(t=>{const n=t?.condition;if(!n||!n.conditions||0===n.conditions.length)return;const i=j[t.id];null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length)&&n.conditions.forEach(n=>{X(n,i)&&e.push({componentId:t.id,condition:n,componentLabel:t.basic?.label||"Field"})})}),e},[s,j,a,X]),me=i(()=>{if(a)return{isValid:!0};const e=de();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:n}of e){const e=R.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},i=[];if(!0!==t.enableRaiseIssue||L.has(t.id)||i.push("raise an issue"),!0!==t.enableNotes||e.notesCompleted||i.push("add notes"),!0!==t.enableAttachment||e.attachmentsCompleted||i.push("add attachments"),!0!==t.enableSendEmail||e.emailSent||i.push("send email"),i.length>0){return{isValid:!1,errorMessage:`Please ${1===i.length?i[0]:i.slice(0,-1).join(", ")+" and "+i[i.length-1]} for the threshold condition met in "${n}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[a,de,L,R]),he=i(e=>{e&&I(t=>{const n=new Set(t);return n.add(e),n})},[]),ge=i((e,t,n)=>{e&&D(i=>{const r=new Map(i),s=r.get(e)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===t?r.set(e,{...s,notesCompleted:n}):"attachments"===t?r.set(e,{...s,attachmentsCompleted:n}):"email"===t&&r.set(e,{...s,emailSent:n}),r})},[]);n(()=>{if(!a){const e=me();F(e)}},[j,L,R,a,me]);const be=i(()=>{if(a)return!0;let e=!0;k(!0);const t={};return s.forEach(n=>{const i=j[n.id]||"";let r=!1;if(r=Array.isArray(i)?i.length>0:"string"==typeof i?""!==i.trim():null!=i,n.validation.required&&!r){const i=n.validation.customValidationMessage,r=n.basic.label||"This field",s=i||`${r} is required`;t[n.id]=s,e=!1}else if("number-input"===n.name&&r){const r=String(i).trim(),s=parseFloat(r);if(isNaN(s))t[n.id]="";else{const i=n.validation;i&&"lowerLimit"in i&&void 0!==i.lowerLimit&&null!==i.lowerLimit&&0!==i.lowerLimit&&s<i.lowerLimit?(t[n.id]="Number is below the lower limit",e=!1):i&&"upperLimit"in i&&void 0!==i.upperLimit&&null!==i.upperLimit&&0!==i.upperLimit&&s>i.upperLimit?(t[n.id]="Number is above the upper limit",e=!1):t[n.id]=""}}else t[n.id]="";A(e=>({...e,[n.id]:!0}))}),w(t),e},[s,a,j]),xe=i(()=>{if(k(!0),!be()){const e=s.find(e=>{const t=j[e.id]||"";let n=!1;return n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!n});if(e){const t=document.getElementById(e.id);t&&t.focus()}return}const e=me();if(!e.isValid){e.errorMessage&&H.showError(e.errorMessage);const t=de().find(({condition:e})=>!L.has(e.id));if(t){const e=document.getElementById(t.componentId);e&&e.scrollIntoView({behavior:"smooth",block:"center"})}return}const t=e=>e.map(e=>{let n=j[e.id];"text-input"===e.name&&e.basic,void 0===n&&(n="value"in e.basic&&void 0!==e.basic.value?e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?e.basic.defaultValue:""),"text-input"===e.name&&e.basic;const i={...e,basic:{...e.basic,value:n,defaultValue:n}};return"section"===i.name&&i.children&&(i.children=t(i.children)),"table"===i.name&&i.cells&&(i.cells=i.cells.map(e=>e.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n}))),"datagrid"===i.name&&i.entries&&(i.entries=i.entries.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n})),i}),n=t(s),i={...j};c?.(n,i)},[s,j,be,c]),je=i(()=>({[`device-${o}`]:!0,readonly:a}),[o,a]),Ne=r(new Map),Ce=r(0),we=t=>{let n;if(t.id&&"string"==typeof t.id&&""!==t.id.trim())n=t.id;else{const e=t.basic?.label||"",i=t.name||"unknown",r=`${i}-${e}`;let s=Ne.current.get(r);s||(Ce.current+=1,s=`generated-${i}-${Ce.current}-${Math.random().toString(36).substr(2,9)}`,Ne.current.set(r,s),console.warn("[DfFormPreview] Generated and cached ID for component:",s,"key:",r)),n=s,t={...t,id:n}}const i=n,r=j[i];if(void 0!==r){const e=s.filter(e=>e.id!==i&&j[e.id]===r);e.length>0&&console.warn(`[DfFormPreview] Component ${i} shares form value with other components:`,e.map(e=>e.id))}const o={id:i,validationErrors:C,formValue:r,touchedFields:$,formSubmitted:S,mode:"test",readonly:!1,onValueChange:W,onBlur:()=>J(i),onFocus:()=>Y(i)};switch(t.name){case"text-input":case"number-input":case"email-input":return B.jsx(Z,{...o,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",formTemplateId:p,onThresholdIssueRaised:he,raisedThresholdIssues:L,workOrderNumber:y,assetNumber:v});case"textarea":return B.jsx(Q,{...o,properties:t});case"select":const n={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ee,{...o,properties:n});case"checkbox":const i={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(te,{...o,properties:i});case"radio":const a={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ne,{...o,properties:a});case"segment":const l={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ie,{...o,properties:l});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...o,properties:t});case"signature":return B.jsx(se,{...o,properties:t});case"heading":return B.jsx(le,{...o,properties:t});case"instructions":const c=r||t.basic?.value||null;return B.jsx(ce,{...o,properties:t,formValue:c});case"location":return B.jsx(ae,{...o,properties:t});case"section":return B.jsx(fe,{...o,properties:t,formData:j,formTemplateId:p,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,renderFormComponent:e=>we(e)});case"table":return B.jsx(e.Suspense,{fallback:B.jsx("div",{children:"Loading table..."}),children:B.jsx(ve,{...o,properties:t,formData:j,formTemplateId:p,mode:o.mode,validationErrors:C,touchedFields:$,formSubmitted:S,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,onNotesChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},renderFormComponent:e=>we(e)})});case"datagrid":return B.jsx(ye,{...o,properties:t,formData:j,formTemplateId:p,mode:o.mode,validationErrors:C,touchedFields:$,formSubmitted:S,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,onComponentSelect:h,onComponentDelete:f,onComponentEdit:g,onComponentUpdate:b,selectedComponent:x,onValueChange:e=>{if(e.id===t.id&&e.value&&"object"==typeof e.value&&"entries"in e.value){const n=s.map(n=>n.id===t.id?{...n,...e.value}:n);d?.(n),e.value.entries&&Array.isArray(e.value.entries)&&e.value.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&e.components.forEach(e=>{if(void 0!==j[e.id]);else{const t=e.basic?.defaultValue;void 0!==t&&N(n=>({...n,[e.id]:t}))}})})}else W(e)},onEntryAdd:()=>{const e=s.find(e=>e.id===t.id);if(e&&e.entries){const e=s.map(e=>e.id===t.id?{...e,entries:e.entries||[]}:e);d?.(e)}else setTimeout(()=>{const e=j[t.id];if(e&&"object"==typeof e&&"entries"in e){const n=s.map(n=>n.id===t.id?{...n,entries:e.entries}:n);d?.(n)}},100)},onEntryRemove:e=>{const n=s.map(n=>{if(n.id===t.id&&n.entries){const t=(n.entries||[]).filter((t,n)=>n!==e).map((e,t)=>({...e,index:t,id:`entry-${n.id}-${t}`,components:e.components?.map((e,n)=>{const i=(e.templateComponents||[])[n];return{...e,id:i?`${i.id}-entry-${t}-${n}`:e.id}})||[]}));return{...n,entries:t}}return n});d?.(n)},onNotesChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},renderFormComponent:e=>we(e)});case"file":const u=r||t.basic?.value||t.basic?.files||t.basic?.attachments||null;return B.jsx(oe,{...o,properties:t,formValue:u});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",t.name]})})}};return B.jsx("div",{className:"form-preview-container",children:B.jsx("div",{className:"form-preview-wrapper",children:B.jsxs("div",{className:`form-preview ${Object.entries(je()).map(([e,t])=>t?e:"").join(" ")}`,children:[B.jsx("div",{className:"form-canvas-header"}),0===s.length?B.jsx("div",{className:"empty-state",children:B.jsx("div",{className:"empty-state-card",children:B.jsx("div",{className:"empty-state-preview-area",children:B.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):B.jsxs("form",{className:"form-preview-form",onSubmit:e=>{e.preventDefault(),xe()},children:[(u||m)&&B.jsxs("div",{className:"form-header",children:[u&&B.jsx("h1",{className:"form-title",children:u}),m&&B.jsx("p",{className:"form-description",children:m})]}),s.map(e=>{const t=e.basic,n=j[e.id],i=["select","radio","checkbox","segment"].includes(e.name||""),r=e.options||t?.options||[],o=(()=>{const t=e?.styles?.column;return"section"===e.name||"table"===e.name||"datagrid"===e.name?"col-12":3===t?"col-3":6===t?"col-6":9===t?"col-9":"col-12"})();let l=!1;if(!a)if(i&&null!=n&&""!==n)if("checkbox"===e.name){l=(Array.isArray(n)?n:[n]).some(e=>{const t=r.find(t=>t.value===e);return t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)})}else{const e=r.find(e=>e.value===n);l=e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)}else l=t?.enableNotes||t?.enableAttachment||t?.enableRaiseIssue||t?.enableSendEmail;const c=a&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:`form-group ${o} ${l||c?"has-action-features":""}`,style:{display:P(e.id)?"block":"none"},children:[we(e),!a&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:a?"preview":"test",formTemplateId:p,formValue:n,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,onNotesChange:t=>{const n=s.map(n=>n.id===e.id?{...n,basic:{...n.basic,notes:t||""}}:n);d?.(n)},onAttachmentChange:t=>{const n=s.map(n=>n.id===e.id?{...n,basic:{...n.basic,attachments:t||[]}}:n);d?.(n)},notes:e.basic?.notes||"",attachments:e.basic?.attachments||null}),a&&c&&B.jsx(pe,{component:e})]},e.id)}),!a&&B.jsx("div",{className:"form-actions",children:B.jsx("button",{type:"submit",disabled:!K()||!V.isValid,className:"form-submit-button",title:V.isValid?"":V.errorMessage,children:"Submit"})})]})]})})})},Ne=({comment:e="",onSave:r,placeholder:s="Enter your reason...",className:o="",disabled:a=!1})=>{const[l,c]=t(!0),[d,u]=t(e),[m,p]=t(!1);n(()=>{u(e),p(!1)},[e]);const h=i(t=>{const n=t.target.value;u(n),p(n!==e)},[e]),f=i(()=>{m&&r&&!a&&(r(d),p(!1))},[m,r,d,a]),g=i(()=>{},[]),b=i(()=>{a||c(!l)},[l,a]);return B.jsxs("div",{className:`df-form-comments ${o}`,children:[B.jsxs("div",{className:"df-form-comments__header",children:[B.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),B.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:b,"aria-expanded":l,"aria-label":"Toggle comments section",disabled:a,children:l?B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),B.jsx("div",{className:"df-form-comments__content "+(l?"df-form-comments__content--expanded":""),children:B.jsx("div",{className:"df-form-comments__input-container",children:B.jsx("div",{className:"df-form-comments__input-line",children:B.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:d,onChange:h,onBlur:f,onFocus:g,placeholder:s,disabled:a})})})})]})},Ce=e=>e.id?e:{...e,id:z()},we=({component:e,mode:t,renderFormComponent:n,formData:i={},formTemplateId:r,onThresholdActionCompletion:s,onThresholdIssueRaised:o,onNotesChange:a,onAttachmentChange:l})=>{const c=i[e.id],d="preview"===t&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:"simple-table-component",children:[n(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:r,formValue:c,onThresholdActionCompletion:s,onThresholdIssueRaised:o,onNotesChange:a?t=>a(e.id,t):void 0,onAttachmentChange:l?t=>l(e.id,t):void 0}),d&&B.jsx(pe,{component:e})]})},Se=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:r,onComponentEdit:s,renderFormComponent:o,isOverlay:a=!1})=>{const{attributes:l,listeners:c,setNodeRef:d,transform:u,transition:m,isDragging:p,isSorting:h}=V({id:e.id,disabled:a}),f={transform:O.Transform.toString(u),transition:m,opacity:p?.3:1,zIndex:p?1e3:"auto"};return B.jsxs("div",{ref:d,style:f,className:`form-component table-component ${t?.id===e.id?"selected":""} ${p?"dragging":""} ${h?"sorting":""}`,onClick:()=>!p&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...c,...l,onClick:e=>e.stopPropagation(),style:{opacity:1},children:B.jsx(k,{size:14})}),B.jsx("div",{className:"component-content",children:o(e)}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{opacity:1},children:[s&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),s(e)},type:"button",title:"Edit Component",children:B.jsx($,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),r(e,t)},type:"button",title:"Delete Component",children:B.jsx(A,{size:12})})]})]})},ke=({cell:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,selectedComponent:s,renderFormComponent:o,formData:a={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,tableId:u,onNotesChange:m,onAttachmentChange:p})=>{const h=`table-cell-${u}-${e.row}-${e.column}`,{setNodeRef:f,isOver:g}=I({id:h,disabled:"edit"!==t,data:{type:"table-cell",tableId:u,cell:e,row:e.row,column:e.column}}),b={...e.styles,backgroundColor:g?"var(--df-color-primary-light)":e.styles?.backgroundColor||"transparent",minHeight:e.styles?.minHeight||"preview"===t||"test"===t?"40px":"60px",padding:(e.styles,"8px"),border:"preview"===t||"test"===t?"none":g?"2px dashed var(--df-color-primary)":e.styles?.borderColor?`1px solid ${e.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===t||"test"===t?"0":"4px",position:"relative",verticalAlign:e.styles?.verticalAlign||"top"};return B.jsx("td",{ref:f,style:b,className:"table-cell "+(g?"drag-over":""),children:B.jsx("div",{className:"cell-content",children:e.components&&Array.isArray(e.components)&&e.components.length>0?"edit"===t?B.jsx(R,{items:e.components.map(e=>e.id||z()),strategy:D,children:e.components.map(e=>{const a=Ce(e);return B.jsx(Se,{component:a,selectedComponent:s,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,renderFormComponent:o},a.id)})}):e.components.map(e=>{const n=e.id?e:Ce(e);return B.jsx(we,{component:n,mode:t,renderFormComponent:o,formData:a,formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,onNotesChange:m,onAttachmentChange:p},n.id)}):"edit"===t?B.jsx("div",{className:"empty-cell-placeholder",children:B.jsxs("div",{className:"cell-info",children:[B.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),B.jsxs("span",{className:"cell-coordinates",children:["Cell (",e.row+1,", ",e.column+1,")"]})]})}):B.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},$e=({id:e,properties:r,mode:o="edit",formData:a={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onTableSelect:f,onComponentSelect:g,onComponentDelete:b,onComponentEdit:x,selectedComponent:y,renderFormComponent:v,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,onNotesChange:k,onAttachmentChange:$})=>{const[A,E]=t(!1),L=r.cells?.some(e=>e.some(e=>e.components&&e.components.length>0))||!1;n(()=>{},[r.table?.rows,r.table?.columns,r.basic?.rows,r.basic?.columns,r.cells,e,u]);const I=i(e=>{e.stopPropagation(),m?.(),f?.(r)},[m,f,r]),R=i((t,n)=>{n.stopPropagation();const i=r.cells.map(e=>e.map(e=>{if(e.components&&e.components.some(e=>e.id===t.id)){const n=e.components.filter(e=>e.id!==t.id);return{...e,components:n}}return e}));u&&u({id:e,value:{...r,cells:i}})},[b,r,u,e]),D=s(()=>r.cells?r.cells.map((t,n)=>t.map((t,i)=>({...t,components:t.components&&Array.isArray(t.components)?t.components.map((t,r)=>{if(t.id&&"string"==typeof t.id&&""!==t.id.trim())return t;const s=`${t.name||"component"}-table-${e}-row-${n}-cell-${i}-comp-${r}`;return{...t,id:s}}):[]}))):[],[r.cells,e]),V=v||i(e=>{const t=e.id?e:Ce(e),n=a[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let i=n;"number-input"===t.name&&"number"==typeof n?i=String(n):"number-input"===t.name&&null==n&&(i="");const r={id:t.id,properties:t,validationErrors:{},formValue:i,touchedFields:{},formSubmitted:!1,mode:o,onValueChange:e=>{u?.(e)},onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...r,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...r,properties:t,readonly:!1,disabled:!1});case"select":const e={...t,options:t.basic?.options||[]};return B.jsx(ee,{...r,properties:e,disabled:!1});case"checkbox":const n={...t,options:t.basic?.options||[]};return B.jsx(te,{...r,properties:n,formValue:[],disabled:!1});case"radio":const i={...t,options:t.basic?.options||[]};return B.jsx(ne,{...r,properties:i,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...r,properties:t,readonly:!1,disabled:!1});case"signature":return B.jsx(se,{...r,properties:t});case"heading":return B.jsx(le,{...r,properties:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",t.name]})}},[v,o,a,u]),F={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"},O={width:"100%",minWidth:"600px",borderCollapse:"preview"===o||"test"===o?"separate":"collapse",tableLayout:"fixed",border:"preview"===o||"test"===o?"1px solid var(--df-color-fb-border)":"none"};return L||"preview"!==o?B.jsxs("div",{className:`form-group df-form-table ${p?"selected":""} ${"preview"===o?"preview-mode":"test"===o?"test-mode":""} ${h}`,onClick:I,style:F,children:[B.jsx("div",{className:"table-header",children:B.jsx("div",{className:"table-title",onClick:t=>{t.stopPropagation(),E(!A),u?.({id:e,value:{...r,basic:{...r.basic||{},collapsed:!A}}})},children:B.jsxs("div",{className:"title-content",children:[A?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(T,{size:16}),B.jsx("span",{className:"table-label",children:r.basic?.label||"Table"}),r.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]})})}),r.basic?.description&&!A&&B.jsx("div",{className:"table-description",children:r.basic.description}),!A&&B.jsxs("div",{className:"table-content",children:[null,B.jsxs("table",{style:O,children:[r.table?.displayAsTable&&("edit"===o||r.table?.showColumns)&&B.jsx("thead",{children:B.jsx("tr",{className:"table-header-row",children:Array.from({length:r.table?.columns||r.basic?.columns||3},(e,t)=>{const n=(r.table?.columnNames?.split(",").map(e=>e.trim())||[])[t]||`Column ${t+1}`;return B.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:n},`header-${t}`)})})}),B.jsx("tbody",{children:D.map((t,n)=>B.jsx("tr",{className:"table-row",children:t.map(t=>B.jsx(ke,{cell:t,mode:o,onComponentSelect:g||(()=>{}),onComponentDelete:R,onComponentEdit:x,selectedComponent:y||null,renderFormComponent:V,formData:a,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,tableId:e,onNotesChange:k,onAttachmentChange:$},t.id))},n))})]})]})]}):null};var Ae=Object.freeze({__proto__:null,DfFormTable:$e,default:$e});const Ee={page:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',padding:"30px",backgroundColor:"#ffffff",color:"#000000",lineHeight:"1.4"},header:{marginBottom:"30px",paddingBottom:"15px",borderBottom:"2px solid #303992",display:"flex",justifyContent:"space-between",alignItems:"flex-end"},title:{margin:"0 0 5px 0",fontSize:"24px",fontWeight:"bold",color:"#303992"},description:{margin:"0",fontSize:"14px",color:"#666666"},submittedBy:{fontSize:"14px",color:"#333",textAlign:"right",whiteSpace:"nowrap",marginBottom:"2px"},formGroup:{marginBottom:"20px",breakInside:"avoid"},label:{fontWeight:"400",display:"block",marginBottom:"8px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",fontColor:"var(--df-color-text-dark)"},labelLeft:{fontWeight:"400",display:"block",marginRight:"10px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",width:"60%",fontColor:"var(--df-color-text-dark)"},valueContainer:{border:"1px solid #e2e8f0",borderRadius:"6px",padding:"8px 12px",backgroundColor:"#ffffff",minHeight:"20px",fontSize:"14px",flex:1},value:{fontSize:"14px",color:"#000000"},gridRow:{display:"flex",flexWrap:"wrap",gap:"16px",marginBottom:"20px"},gridCol:e=>({flex:`0 0 calc(${e/12*100}% - 8px)`,minWidth:"0"}),img:{maxWidth:"100%",maxHeight:"300px",border:"1px solid #ddd",borderRadius:"4px",display:"block",marginTop:"5px"},table:{width:"100%",borderCollapse:"collapse",border:"1px solid #ddd",marginTop:"10px",tableLayout:"fixed"},th:{border:"1px solid #ddd",padding:"8px",backgroundColor:"#f5f5f5",fontWeight:"bold",textAlign:"left",fontSize:"13px"},td:{border:"1px solid #ddd",padding:"8px",fontSize:"13px",verticalAlign:"top"},section:{marginBottom:"25px",breakInside:"avoid"},sectionHeader:{fontSize:"18px",marginBottom:"15px",display:"block",fontWeight:"600"},sectionChildren:{marginLeft:"20px",paddingLeft:"20px",borderLeft:"2px solid #3b82f6",marginTop:"15px"},notesSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",fontSize:"13px",boxSizing:"border-box"},notesLabel:{fontWeight:"bold",color:"#303992",marginRight:"5px"},attachmentsSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",display:"flex",flexWrap:"wrap",gap:"10px",boxSizing:"border-box"},attachmentThumbnail:{width:"60px",height:"60px",border:"1px solid #e5e7eb",borderRadius:"4px",overflow:"hidden",backgroundColor:"#fff",display:"flex",alignItems:"center",justifyContent:"center"},attachmentImg:{width:"100%",height:"100%",objectFit:"cover"},segmentContainer:{display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center"},segmentButton:{display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",borderRadius:"6px",border:"1px solid #e0e0e0",backgroundColor:"#ffffff",fontSize:"10px",fontWeight:600,minWidth:"30px",color:"#666"},segmentIcon:{marginRight:"4px",fontSize:"9px",fontWeight:"bold",display:"inline-block",lineHeight:"1"},checkboxItem:{display:"flex",alignItems:"center",padding:"10px 14px",backgroundColor:"#f8f9fa",borderRadius:"6px",marginBottom:"8px",width:"100%",boxSizing:"border-box"}},Te=e=>{if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.startsWith("data:image")||t.startsWith("iVBORw0KGgo")||t.startsWith("/9j/4AAQ")||t.startsWith("UklGR")||t.startsWith("R0lGOD")},Le=(e,t)=>{if(!e)return"";const n=e.trim();return n.startsWith("data:")||n.startsWith("http")||n.startsWith("blob:")||n.startsWith("/")?n:n.startsWith("iVBORw0KGgo")?`data:image/png;base64,${n}`:n.startsWith("/9j/4AAQ")?`data:image/jpeg;base64,${n}`:n.startsWith("UklGR")?`data:image/webp;base64,${n}`:n.startsWith("R0lGOD")?`data:image/gif;base64,${n}`:t&&t.startsWith("image/")?`data:${t};base64,${n}`:n},Ie=e=>{if(null!=e?.icon)return e.icon;return"pass"===(e=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"})(e?.value||e)?"✓":"×"},Re=({component:e})=>{const t=e.basic?.notes||"",n=e.basic?.attachments||[];return t.trim()||0!==n.length?B.jsxs("div",{style:{marginTop:"5px"},children:[t.trim().length>0&&B.jsxs("div",{style:Ee.notesSection,children:[B.jsx("span",{style:Ee.notesLabel,children:"Notes:"}),t]}),n.length>0&&B.jsx("div",{style:Ee.attachmentsSection,children:n.map((e,t)=>{const n=!(!e.data&&!e.url),i=(e.type?.startsWith("image/")||Te(e.data||e.url||""))&&n?Le(e.data||e.url||"",e.type):null;return B.jsx("div",{style:Ee.attachmentThumbnail,children:i?B.jsx("img",{src:i,alt:e.name||"Attachment",style:Ee.attachmentImg}):B.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},t)})})]}):null},De=({component:e})=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue,{name:n}=e;if("signature"===n)return t&&Te(t)?B.jsx("div",{style:{marginTop:"5px"},children:B.jsx("img",{src:Le(t),alt:"Signature",style:{...Ee.img,maxHeight:"100px",width:"auto"}})}):B.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===n){const n=e.basic?.options||[],i=Array.isArray(t)?t:[t];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:n.map((e,t)=>{const n=i.includes(e.value);return B.jsxs("div",{style:Ee.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(n?"#303992":"#cbd5e1"),borderRadius:"4px",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:n?"#303992":"#ffffff"},children:n&&B.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("radio"===n){const n=e.basic?.options||[];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:n.map((e,n)=>{const i=t===e.value;return B.jsxs("div",{style:Ee.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(i?"#303992":"#cbd5e1"),borderRadius:"50%",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#ffffff"},children:i&&B.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},n)})})}if("segment"===n){const n=e.basic?.options||[],i=t;return B.jsx("div",{style:Ee.segmentContainer,children:n.map((e,t)=>{const n=i===e.value,r=Ie(e),s=e.color||"#666";let o={...Ee.segmentButton};return o=n?{...o,backgroundColor:s,color:"#ffffff",borderColor:s}:{...o,backgroundColor:"#ffffff",color:s,borderColor:s},B.jsxs("div",{style:o,children:[B.jsx("span",{style:Ee.segmentIcon,children:r}),B.jsx("span",{children:e.value})]},t)})})}if("file"===n){const e=(Array.isArray(t)?t:t?[t]:[]).filter(e=>{const t=!(!e.data&&!e.url),n=e.type&&e.type.startsWith("image/"),i=t&&Te(e.data||e.url);return n||i});return e.length>0?B.jsx("div",{style:{marginTop:"10px"},children:e.map((e,t)=>{const n=Le(e.data||e.url,e.type);return n?B.jsx("img",{src:n,alt:e.name||"File",style:{...Ee.img,marginBottom:"10px"}},t):null})}):B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===n){if(t&&"object"==typeof t){const e=t;return B.jsxs("div",{style:{fontSize:"14px"},children:[e.placeName&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Place:"})," ",e.placeName]}),(e.city||e.country)&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Address:"})," ",[e.city,e.country].filter(Boolean).join(", ")]}),e.latitude&&e.longitude&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Coordinates:"})," ",e.latitude.toFixed(6),", ",e.longitude.toFixed(6)]}),e.timestamp&&B.jsxs("div",{children:[B.jsx("strong",{children:"Captured:"})," ",new Date(e.timestamp).toLocaleString()]})]})}return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===n){const t=e.basic?.instructions||[],n=e.validation?.listStyle||"numbers";if(!Array.isArray(t)||0===t.length)return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const i=()=>B.jsx("div",{dangerouslySetInnerHTML:{__html:t.join("")}});return"numbers"===n?B.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(i,{})}):"bullets"===n?B.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(i,{})}):B.jsx("div",{style:{margin:"10px 0"},children:B.jsx(i,{})})}const i="object"==typeof t?JSON.stringify(t):String(t);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid"].includes(n)){const e="textarea"===n;return B.jsx("div",{style:{...Ee.valueContainer,...e?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}},children:B.jsx("div",{style:Ee.value,children:i})})}return B.jsx("div",{style:Ee.value,children:i})},Ve=({component:e})=>{const{name:t,basic:n,styles:i,validation:r}=e,s=n?.label,o=r?.required,a="left"===(i?.labelAlignment||"top");if("section"===t){const t=i?.headerBackgroundColor,r=i?.headerTextColor,a={...Ee.sectionHeader,...t?{backgroundColor:t,padding:"8px",borderRadius:"4px"}:{},...r?{color:r}:{},display:"flex",alignItems:"center"};return B.jsxs("div",{style:Ee.section,children:[s&&B.jsx("label",{style:a,children:B.jsxs("span",{style:{flex:1},children:[s,o&&" *"]})}),n?.description&&B.jsx("p",{style:{...Ee.description,marginBottom:"15px"},children:n.description}),B.jsx(Re,{component:e}),B.jsx("div",{style:Ee.sectionChildren,children:B.jsx(Fe,{components:e.children||[]})})]})}if("heading"===t){const e=`h${Math.max(1,Math.min(6,i?.level??n?.level??1))}`,t={...i?.headerBackgroundColor?{backgroundColor:i.headerBackgroundColor,padding:"8px",borderRadius:"4px"}:{},...i?.headerTextColor?{color:i.headerTextColor}:{},...i?.fontSize?{fontSize:i.fontSize}:{},...i?.textAlign?{textAlign:i.textAlign}:{},marginTop:0,marginBottom:"15px"};return B.jsx("div",{style:Ee.formGroup,children:B.jsx(e,{style:t,children:n?.label||n?.value})})}if("table"===t){const t=e.cells||[],n=Math.max(0,...t.map(e=>e?e.length:0)),r=n>0?100/n:100,a=i?.headerBackgroundColor,l=i?.headerTextColor,c={...Ee.label,...a?{backgroundColor:a,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...l?{color:l}:{}};return B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:c,children:[s,o&&" *"]}),B.jsx("table",{style:Ee.table,children:B.jsx("tbody",{children:t.map((e,t)=>B.jsx("tr",{children:e&&e.map((e,t)=>B.jsx("td",{style:{...Ee.td,width:`${r}%`},children:e.components&&e.components.map((e,t)=>B.jsxs("div",{style:{marginBottom:"8px"},children:[e.basic?.label&&B.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[e.basic.label,":"]}),B.jsx(De,{component:e}),B.jsx(Re,{component:e})]},t))},t))},t))})})]})}if("datagrid"===t){const t=e.entries||[];let n=e.templateComponents||[];0===n.length&&t.length>0&&t[0]?.components&&(n=t[0].components.map(e=>({...e,basic:{...e.basic,label:e.basic?.label||e.name}})));const r=i?.headerBackgroundColor,a=i?.headerTextColor,l={...Ee.label,...r?{backgroundColor:r,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...a?{color:a}:{}},c=t.filter(e=>!(!e.components||0===e.components.length)&&e.components.some(e=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue;return Array.isArray(t)?t.length>0:null!=t&&""!==String(t).trim()}));return 0===c.length?B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:l,children:[s,o&&" *"]}),B.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:l,children:[s,o&&" *"]}),B.jsxs("table",{style:Ee.table,children:[B.jsx("thead",{children:B.jsx("tr",{children:n.map((e,t)=>B.jsx("th",{style:Ee.th,children:e.basic?.label||e.name},t))})}),B.jsx("tbody",{children:c.map((e,t)=>B.jsx("tr",{children:n.map((t,n)=>{const i=e.components[n];return B.jsx("td",{style:Ee.td,children:i?B.jsxs(B.Fragment,{children:[B.jsx(De,{component:i}),B.jsx(Re,{component:i})]}):"N/A"},n)})},t))})]})]})}if(a&&"instructions"!==t){const n=["segment"].includes(t);return B.jsxs("div",{style:Ee.formGroup,children:[B.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[s&&B.jsxs("label",{style:Ee.labelLeft,children:[s,o&&" *"]}),B.jsx("div",{style:{flex:1,...n?{display:"flex",justifyContent:"flex-end"}:{}},children:B.jsx(De,{component:e})})]}),B.jsx(Re,{component:e})]})}return B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:Ee.label,children:[s,o&&" *"]}),B.jsx(De,{component:e}),B.jsx(Re,{component:e})]})},Fe=({components:e})=>{if(!e||0===e.length)return null;const t=[];let n=[],i=0;return e.forEach(e=>{const r=["section","table","datagrid","heading","instructions"].includes(e.name),s=r?12:e.styles?.column||12;i+s>12&&n.length>0&&(t.push(n),n=[],i=0),n.push(e),i+=s,(r||i>=12)&&i>0&&(t.push(n),n=[],i=0)}),n.length>0&&t.push(n),B.jsx(B.Fragment,{children:t.map((e,t)=>1===e.length?B.jsx(Ve,{component:e[0]},e[0].id||t):B.jsx("div",{style:Ee.gridRow,children:e.map((e,t)=>{const n=e.styles?.column||12;return B.jsx("div",{style:Ee.gridCol(n),children:B.jsx(Ve,{component:e})},e.id||t)})},t))})},Oe=({formTitle:e,formDescription:t,userName:n,components:i})=>B.jsxs("div",{className:"pdf-container",style:Ee.page,children:[B.jsxs("div",{style:Ee.header,children:[B.jsxs("div",{children:[B.jsx("h1",{style:Ee.title,children:e}),t&&B.jsx("p",{style:Ee.description,children:t})]}),n&&B.jsxs("div",{style:Ee.submittedBy,children:[B.jsx("strong",{children:"Submitted By:"})," ",n]})]}),B.jsx("div",{className:"form-content",children:B.jsx(Fe,{components:i})})]});var ze;!function(e){e.Top="top",e.Left="left"}(ze||(ze={}));export{ue as ComponentActionFeatures,pe as ComponentSubmissionActions,te as DfFormCheckbox,Ne as DfFormComments,ye as DfFormDataGrid,re as DfFormDateTime,J as DfFormErrorMsg,oe as DfFormFileUpload,le as DfFormHeading,Z as DfFormInput,ce as DfFormInstruction,ae as DfFormLocation,je as DfFormPreview,ne as DfFormRadio,fe as DfFormSection,ie as DfFormSegment,ee as DfFormSelect,se as DfFormSignature,$e as DfFormTable,Q as DfFormTextarea,ze as ELabelAlignment,Oe as FormSubmissionPdf,K as RaiseIssueModal,X as ThresholdAlert,G as conditionalLogicService,H as toastService};
10
+ */"production"===process.env.NODE_ENV?q.exports=function(){if(M)return P;M=1;var t=e,n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,s=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,i){var a,l={},c=null,d=null;for(a in void 0!==i&&(c=""+i),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(d=t.ref),t)r.call(t,a)&&!o.hasOwnProperty(a)&&(l[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===l[a]&&(l[a]=t[a]);return{$$typeof:n,type:e,key:c,ref:d,props:l,_owner:s.current}}return P.Fragment=i,P.jsx=a,P.jsxs=a,P}():q.exports=(W||(W=1,"production"!==process.env.NODE_ENV&&function(){var t,n=e,i=Symbol.for("react.element"),r=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),c=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),f=Symbol.for("react.offscreen"),g=Symbol.iterator,b=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];!function(e,t,n){var i=b.ReactDebugCurrentFrame.getStackAddendum();""!==i&&(t+="%s",n=n.concat([i]));var r=n.map(function(e){return String(e)});r.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,r)}("error",e,n)}function y(e){return e.displayName||"Context"}function v(e){if(null==e)return null;if("number"==typeof e.tag&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case s:return"Fragment";case r:return"Portal";case a:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case m:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case c:return y(e)+".Consumer";case l:return y(e._context)+".Provider";case d:return function(e,t,n){var i=e.displayName;if(i)return i;var r=t.displayName||t.name||"";return""!==r?n+"("+r+")":n}(e,e.render,"ForwardRef");case p:var t=e.displayName||null;return null!==t?t:v(e.type)||"Memo";case h:var n=e,i=n._payload,f=n._init;try{return v(f(i))}catch(e){return null}}return null}t=Symbol.for("react.module.reference");var j,N,C,w,S,k,$,A=Object.assign,E=0;function T(){}T.__reactDisabledLog=!0;var L,I=b.ReactCurrentDispatcher;function R(e,t,n){if(void 0===L)try{throw Error()}catch(e){var i=e.stack.trim().match(/\n( *(at )?)/);L=i&&i[1]||""}return"\n"+L+e}var D,V=!1,F="function"==typeof WeakMap?WeakMap:Map;function O(e,t){if(!e||V)return"";var n,i=D.get(e);if(void 0!==i)return i;V=!0;var r,s=Error.prepareStackTrace;Error.prepareStackTrace=void 0,r=I.current,I.current=null,function(){if(0===E){j=console.log,N=console.info,C=console.warn,w=console.error,S=console.group,k=console.groupCollapsed,$=console.groupEnd;var e={configurable:!0,enumerable:!0,value:T,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}E++}();try{if(t){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(o,[])}catch(e){n=e}Reflect.construct(e,[],o)}else{try{o.call()}catch(e){n=e}e.call(o.prototype)}}else{try{throw Error()}catch(e){n=e}e()}}catch(t){if(t&&n&&"string"==typeof t.stack){for(var a=t.stack.split("\n"),l=n.stack.split("\n"),c=a.length-1,d=l.length-1;c>=1&&d>=0&&a[c]!==l[d];)d--;for(;c>=1&&d>=0;c--,d--)if(a[c]!==l[d]){if(1!==c||1!==d)do{if(c--,--d<0||a[c]!==l[d]){var u="\n"+a[c].replace(" at new "," at ");return e.displayName&&u.includes("<anonymous>")&&(u=u.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,u),u}}while(c>=1&&d>=0);break}}}finally{V=!1,I.current=r,function(){if(0===--E){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:A({},e,{value:j}),info:A({},e,{value:N}),warn:A({},e,{value:C}),error:A({},e,{value:w}),group:A({},e,{value:S}),groupCollapsed:A({},e,{value:k}),groupEnd:A({},e,{value:$})})}E<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=s}var m=e?e.displayName||e.name:"",p=m?R(m):"";return"function"==typeof e&&D.set(e,p),p}function z(e,t,n){if(null==e)return"";if("function"==typeof e)return O(e,!(!(i=e.prototype)||!i.isReactComponent));var i;if("string"==typeof e)return R(e);switch(e){case u:return R("Suspense");case m:return R("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case d:return O(e.render,!1);case p:return z(e.type,t,n);case h:var r=e,s=r._payload,o=r._init;try{return z(o(s),t,n)}catch(e){}}return""}D=new F;var M=Object.prototype.hasOwnProperty,q={},P=b.ReactDebugCurrentFrame;function W(e){if(e){var t=e._owner,n=z(e.type,e._source,t?t.type:null);P.setExtraStackFrame(n)}else P.setExtraStackFrame(null)}var B=Array.isArray;function U(e){return B(e)}function G(e){return""+e}function H(e){if(function(e){try{return G(e),!1}catch(e){return!0}}(e))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),G(e)}var J,Y,K,X=b.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,n,r,s){var o,a={},l=null,c=null;for(o in void 0!==n&&(H(n),l=""+n),function(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(H(t.key),l=""+t.key),function(e){if(M.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e,t){if("string"==typeof e.ref&&X.current&&t&&X.current.stateNode!==t){var n=v(X.current.type);K[n]||(x('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',v(X.current.type),e.ref),K[n]=!0)}}(t,s)),t)M.call(t,o)&&!Z.hasOwnProperty(o)&&(a[o]=t[o]);if(e&&e.defaultProps){var d=e.defaultProps;for(o in d)void 0===a[o]&&(a[o]=d[o])}if(l||c){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;l&&function(e,t){var n=function(){J||(J=!0,x("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(a,u),c&&function(e,t){var n=function(){Y||(Y=!0,x("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}(a,u)}return function(e,t,n,r,s,o,a){var l={$$typeof:i,type:e,key:t,ref:n,props:a,_owner:o,_store:{}};return Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:r}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l}(e,l,c,s,r,X.current,a)}K={};var ee,te=b.ReactCurrentOwner,ne=b.ReactDebugCurrentFrame;function ie(e){if(e){var t=e._owner,n=z(e.type,e._source,t?t.type:null);ne.setExtraStackFrame(n)}else ne.setExtraStackFrame(null)}function re(e){return"object"==typeof e&&null!==e&&e.$$typeof===i}function se(){if(te.current){var e=v(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var oe={};function ae(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var n=function(e){var t=se();if(!t){var n="string"==typeof e?e:e.displayName||e.name;n&&(t="\n\nCheck the top-level render call using <"+n+">.")}return t}(t);if(!oe[n]){oe[n]=!0;var i="";e&&e._owner&&e._owner!==te.current&&(i=" It was passed a child from "+v(e._owner.type)+"."),ie(e),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,i),ie(null)}}}function le(e,t){if("object"==typeof e)if(U(e))for(var n=0;n<e.length;n++){var i=e[n];re(i)&&ae(i,t)}else if(re(e))e._store&&(e._store.validated=!0);else if(e){var r=function(e){if(null===e||"object"!=typeof e)return null;var t=g&&e[g]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof r&&r!==e.entries)for(var s,o=r.call(e);!(s=o.next()).done;)re(s.value)&&ae(s.value,t)}}function ce(e){var t,n=e.type;if(null!=n&&"string"!=typeof n){if("function"==typeof n)t=n.propTypes;else{if("object"!=typeof n||n.$$typeof!==d&&n.$$typeof!==p)return;t=n.propTypes}if(t){var i=v(n);!function(e,t,n,i,r){var s=Function.call.bind(M);for(var o in e)if(s(e,o)){var a=void 0;try{if("function"!=typeof e[o]){var l=Error((i||"React class")+": "+n+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw l.name="Invariant Violation",l}a=e[o](t,o,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){a=e}!a||a instanceof Error||(W(r),x("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",i||"React class",n,o,typeof a),W(null)),a instanceof Error&&!(a.message in q)&&(q[a.message]=!0,W(r),x("Failed %s type: %s",n,a.message),W(null))}}(t,e.props,"prop",i,e)}else void 0===n.PropTypes||ee||(ee=!0,x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v(n)||"Unknown"));"function"!=typeof n.getDefaultProps||n.getDefaultProps.isReactClassApproved||x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var de={};function ue(e,n,r,g,b,y){var j=function(e){return"string"==typeof e||"function"==typeof e||e===s||e===a||e===o||e===u||e===m||e===f||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===p||e.$$typeof===l||e.$$typeof===c||e.$$typeof===d||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!j){var N="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(N+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var C,w=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(b);N+=w||se(),null===e?C="null":U(e)?C="array":void 0!==e&&e.$$typeof===i?(C="<"+(v(e.type)||"Unknown")+" />",N=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,N)}var S=Q(e,n,r,b,y);if(null==S)return S;if(j){var k=n.children;if(void 0!==k)if(g)if(U(k)){for(var $=0;$<k.length;$++)le(k[$],e);Object.freeze&&Object.freeze(k)}else x("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else le(k,e)}if(M.call(n,"key")){var A=v(e),E=Object.keys(n).filter(function(e){return"key"!==e}),T=E.length>0?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}";de[A+T]||(x('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',T,A,E.length>0?"{"+E.join(": ..., ")+": ...}":"{}",A),de[A+T]=!0)}return e===s?function(e){for(var t=Object.keys(e.props),n=0;n<t.length;n++){var i=t[n];if("children"!==i&&"key"!==i){ie(e),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),ie(null);break}}null!==e.ref&&(ie(e),x("Invalid attribute `ref` supplied to `React.Fragment`."),ie(null))}(S):ce(S),S}var me=function(e,t,n){return ue(e,t,n,!1)},pe=function(e,t,n){return ue(e,t,n,!0)};_.Fragment=s,_.jsx=me,_.jsxs=pe}()),_);var B=q.exports;class U{constructor(){}static getInstance(){return U.instance||(U.instance=new U),U.instance}getAvailableComponentsForConditional(e,t){if(!e||!Array.isArray(e))return[];return e.filter(e=>!t||e.id!==t).map(e=>({id:e.id,label:e.basic?.label||e.id,type:e.name,key:e.id})).sort((e,t)=>e.label.localeCompare(t.label))}getApplicableOperators(e){switch(e){case"text-input":case"email-input":case"textarea":return["equals","notEquals","contains","notContains","isEmpty","isNotEmpty"];case"number-input":case"date-picker":case"datetime-picker":return["equals","notEquals","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual","isEmpty","isNotEmpty"];case"select":case"radio":case"segment":default:return["equals","notEquals","isEmpty","isNotEmpty"];case"checkbox":return["contains","notContains","isEmpty","isNotEmpty"]}}validateConditionalLogic(e,t){const n=[];return e?(["show","hide","always"].includes(e.action)||n.push("Invalid conditional action"),["all","any"].includes(e.when)||n.push("Invalid when condition"),e.conditions&&0!==e.conditions.length?e.conditions.forEach((e,i)=>{const r=t.find(t=>t.id===e.when);if(!r)return void n.push(`Condition ${i+1}: Component not found`);this.getApplicableOperators(r.name).includes(e.operator)||n.push(`Condition ${i+1}: Operator not applicable for component type`),this.isValidConditionValue(e.value,r.name,e.operator)||n.push(`Condition ${i+1}: Invalid condition value`)}):n.push("At least one condition is required"),{isValid:0===n.length,errors:n}):{isValid:!0,errors:[]}}evaluateConditionalLogic(e,t,n){if("always"===e.action)return{shouldShow:!0,evaluatedConditions:[]};if(!e||!e.conditions||0===e.conditions.length)return{shouldShow:!0,evaluatedConditions:[]};const i=e.conditions.map(e=>{const i=this.getComponentValue(e.when,t,n);return{condition:e,result:this.evaluateCondition(e,i),componentValue:i}});return{shouldShow:this.determineFinalResult(e,i),evaluatedConditions:i}}getComponentValue(e,t,n){if(n&&void 0!==n[e])return n[e];const i=t.find(t=>t.id===e);return i&&"defaultValue"in i.basic?i.basic.defaultValue:void 0}evaluateCondition(e,t){const{operator:n,value:i}=e;if("checked"===i||"notChecked"===i)return this.evaluateCheckboxCondition(t,i);switch(n){case"equals":return this.isEqual(t,i);case"notEquals":return!this.isEqual(t,i);case"isEmpty":return this.isEmpty(t);case"isNotEmpty":return!this.isEmpty(t);case"contains":return this.contains(t,i);case"notContains":return!this.contains(t,i);case"greaterThan":return this.isGreaterThan(t,i);case"lessThan":return this.isLessThan(t,i);case"greaterThanOrEqual":return this.isGreaterThanOrEqual(t,i);case"lessThanOrEqual":return this.isLessThanOrEqual(t,i);default:return!1}}evaluateCheckboxCondition(e,t){const n=this.isCheckboxChecked(e);return"checked"===t?n:"notChecked"===t&&!n}isCheckboxChecked(e){return null!=e&&("boolean"==typeof e?e:"string"==typeof e?"true"===e.toLowerCase()||"1"===e:Array.isArray(e)?e.length>0:"number"==typeof e&&e>0)}determineFinalResult(e,t){let n,i;return n="all"===e.when?t.every(e=>e.result):"any"===e.when&&t.some(e=>e.result),i="show"===e.action?n:"hide"===e.action?!n:(e.action,!0),i}isEqual(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>this.isEqual(e,t[n]));if("object"==typeof e&&"object"==typeof t){const n=Object.keys(e),i=Object.keys(t);return n.length===i.length&&n.every(n=>this.isEqual(e[n],t[n]))}return!1}isEmpty(e){return null==e||void 0===e||("string"==typeof e?""===e.trim():Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}contains(e,t){return null!=e&&null!=t&&("string"==typeof e?e.toLowerCase().includes(String(t).toLowerCase()):!!Array.isArray(e)&&e.some(e=>this.isEqual(e,t)))}isGreaterThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>i}isLessThan(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<i}isGreaterThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n>=i}isLessThanOrEqual(e,t){const n=Number(e),i=Number(t);return!isNaN(n)&&!isNaN(i)&&n<=i}isValidConditionValue(e,t,n){if(null==e)return["isEmpty","isNotEmpty"].includes(n);switch(t){case"number-input":return!isNaN(Number(e))||["isEmpty","isNotEmpty"].includes(n);case"date-picker":case"datetime-picker":return!isNaN(Date.parse(e))||["isEmpty","isNotEmpty"].includes(n);case"checkbox":return Array.isArray(e)||"string"==typeof e||"number"==typeof e;default:return!0}}createDefaultConditionalLogic(){return{action:"show",when:"all",conditions:[]}}getOperatorDisplayText(e){return{equals:"Is Equal To",notEquals:"Is Not Equal To",contains:"Contains",notContains:"Does Not Contain",isEmpty:"Is Empty",isNotEmpty:"Is Not Empty",greaterThan:"Is Greater Than",lessThan:"Is Less Than",greaterThanOrEqual:"Is Greater Than Or Equal To",lessThanOrEqual:"Is Less Than Or Equal To"}[e]||e}getActionDisplayText(e){return{show:"Show this field when",hide:"Hide this field when",always:"Always show this field"}[e]||e}getConditionalLogicSummary(e,t){if(!e||0===e.conditions.length)return"No conditions";if("always"===e.action)return"Always show";const n=this.getActionDisplayText(e.action),i=e.conditions.map(e=>{const n=t.find(t=>t.id===e.when);return`${n?.basic.label||"Unknown component"} ${this.getOperatorDisplayText(e.operator)} ${this.formatConditionValue(e.value)}`}),r="all"===e.when?" and ":" or ";return`${n} ${i.join(r)}`}formatConditionValue(e){return null==e?"empty":Array.isArray(e)?`[${e.join(", ")}]`:"string"==typeof e?`"${e}"`:String(e)}}const G=U.getInstance();const H=new class{constructor(){this.toasts=[],this.listeners=[],this.defaultDuration=3e3,this.timeouts={}}generateId(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}notifyListeners(){this.listeners.forEach(e=>e([...this.toasts]))}addToast(e){try{this.toasts.push(e),this.notifyListeners(),this.timeouts[e.id]=setTimeout(()=>{this.removeToast(e.id)},e.duration||this.defaultDuration)}catch(e){console.error("Error displaying toast message:",e)}}removeToast(e){this.timeouts[e]&&(clearTimeout(this.timeouts[e]),delete this.timeouts[e]),this.toasts=this.toasts.filter(t=>t.id!==e),this.notifyListeners()}showSuccess(e,t=3e3){const n={id:this.generateId(),message:e,type:"success",duration:t};this.addToast(n)}showError(e,t=5e3){const n={id:this.generateId(),message:e,type:"danger",duration:t};this.addToast(n)}showWarning(e,t){const n={id:this.generateId(),message:e,type:"warning",duration:t};this.addToast(n)}showInfo(e,t){const n={id:this.generateId(),message:e,type:"info",duration:t};this.addToast(n)}show(e,t="success",n){const i={id:this.generateId(),message:e,type:t,duration:n};this.addToast(i)}clearAll(){Object.values(this.timeouts).forEach(e=>clearTimeout(e)),this.timeouts={},this.toasts=[],this.notifyListeners()}subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}getToasts(){return[...this.toasts]}},J=({validationErrors:e,fieldId:t,touchedFields:n,formSubmitted:i,properties:r,localValidation:s,isTouched:o,mode:a})=>{const l=e=>{const t=r.basic.label||"This field",n=r.name||"",i=r.validation?.customValidationMessage;if("number-input"===n)switch(e){case"required":return`${t} is required`;case"lowerLimit":return"Number is below the lower limit";case"upperLimit":return"Number is above the upper limit";default:return""}if(i)return i;const s="date-picker"===n||"datetime-picker"===n?r.basic?.dateTimeMode||("datetime-picker"===n?"datetime":"date"):null;switch(e){case"required":return`${t} is required`;case"invalidDate":return"time"===s?"Please select a valid time":"datetime"===s?"Please select a valid date and time":"date"===s?"Please select a valid date":`${t} is invalid`;case"minLength":return`${t} must be at least ${r.validation.minLength} characters long`;case"maxLength":return`${t} must be no more than ${r.validation.maxLength} characters long`;case"min":return`${t} must be at least ${r.validation.min}`;case"max":return`${t} must be no more than ${r.validation.max}`;case"lowerLimit":const e=r.validation,n=e?.lowerLimit;return`You are under the limit. ${t} must be at least ${n}`;case"upperLimit":const i=r.validation,o=i?.upperLimit;return`You crossed the limit. ${t} must be no more than ${o}`;case"pattern":return`${t} format is invalid`;case"email":return`${t} must be a valid email address`;default:return`${t} is invalid`}},c=(()=>{if("test"!==a)return"";if(!(o||n[t]||i))return"";if(s&&s.isValid)return"";if(s&&!s.isValid&&Object.keys(s.errors).length>0){const e=Object.keys(s.errors).filter(e=>!0===s.errors[e]);if(e.length>0){const t=e[0],n=r.name||"";return"pattern"===t&&"number-input"===n?"":l(t)}}const c=e[t];if(c&&"string"==typeof c&&""!==c.trim()){const e=r.name||"";if("number-input"===e&&s){const e=r.validation,t=e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit,n=e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit;return!c.includes("limit")&&!c.includes("Limit")||t||n?(s.isValid,""):""}if(("date-picker"===e||"datetime-picker"===e)&&c.includes("valid date")){const t=r.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("time"===t)return"Please select a valid time";if("datetime"===t)return"Please select a valid date and time"}return c}return""})();return c?B.jsx("div",{className:"form-error-msg",children:c}):null};var Y;!function(e){e.OPEN="Open",e.IN_PROGRESS="In-Progress",e.REJECTED="Rejected",e.RESOLVE="Resolve"}(Y||(Y={}));const K=({isOpen:e,onClose:i,onSuccess:r,component:s,formTemplateId:u,notes:m="",attachments:p=null,issue:h=null,onCreateIssue:f,onUpdateIssue:g,user:b,availableUsers:x=["Priya Das","Maria Garcia","John Smith","Sarah Johnson"],workOrderNumber:y,assetNumber:v})=>{const[j,N]=t(""),[C,w]=t(""),[S,k]=t(""),[$,A]=t(""),[E,T]=t("Medium"),[I,R]=t(Y.OPEN),[D,V]=t(""),[F,O]=t(""),[z,M]=t(!1),q=!!h;n(()=>{if(e)if(h){N(h.title||""),w(h.description||""),k(h.workOrderNumber||""),A(h.assetNumber||""),T(h.priority||"Medium");const e=h.status||Y.OPEN,t=e===Y.OPEN||e===Y.IN_PROGRESS||e===Y.REJECTED||e===Y.RESOLVE?e:Y.OPEN;R(t),V(h.assignee||""),O(h.comments||"")}else if(s){const e=s.basic?.label||"Component";N(`${e} - Issue`);let t=`Issue raised for component: ${e}`;s.basic&&"value"in s.basic&&s.basic.value&&(t+=`\nComponent Value: ${s.basic.value}`),m&&(t+=`\nNotes: ${m}`),w(t),O(m||""),y&&k(y),v&&A(v)}},[e,s,m,h,y,v]);const P=async e=>{if(h){M(!0);try{const t={title:String(j||"").trim(),description:String(C||"").trim(),workOrderNumber:String(S||"").trim()||"",assetNumber:String($||"").trim()||"",formTemplateId:h.formTemplateId||"",component:h.component||{},priority:E,assignee:String(D||"").trim()||void 0,status:e,comments:String(F||"").trim()||""};g&&h._id&&await g(h._id,t),R(e);const n={[Y.IN_PROGRESS]:"Issue accepted and moved to In-Progress",[Y.RESOLVE]:"Issue resolved successfully",[Y.REJECTED]:"Issue rejected"};H.showSuccess(n[e]||"Issue status updated successfully"),r&&r(),i()}catch(e){const t=e?.message||e?.error?.message||"Failed to update issue status. Please try again.";H.showError(t)}finally{M(!1)}}};if(!e)return null;const W=B.jsx("div",{className:"raise-issue-modal-overlay",onClick:i,children:B.jsxs("div",{className:"raise-issue-modal",onClick:e=>e.stopPropagation(),children:[B.jsxs("div",{className:"raise-issue-modal-header",children:[B.jsxs("div",{className:"raise-issue-modal-header-left",children:[B.jsx(o,{className:"raise-issue-modal-icon",size:20}),B.jsx("div",{className:"raise-issue-modal-header-text",children:B.jsx("div",{className:"raise-issue-modal-title-main",children:"Issue Details"})})]}),B.jsx("button",{className:"raise-issue-modal-close",onClick:i,"aria-label":"Close",children:B.jsx(a,{size:18})})]}),B.jsx("div",{className:"raise-issue-modal-content",children:B.jsxs("div",{className:"raise-issue-fields-grid",children:[q&&h?.issueNumber&&B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Issue ID"}),B.jsx("input",{type:"text",className:"raise-issue-field-input raise-issue-field-readonly",value:h.issueNumber,readOnly:!0})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Title ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:j,onChange:e=>N(e.target.value),placeholder:"Enter issue title",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Work Order ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:S,onChange:e=>k(e.target.value),placeholder:"N/A",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Asset Number ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("input",{type:"text",className:"raise-issue-field-input "+(q?"raise-issue-field-readonly":""),value:$,onChange:e=>A(e.target.value),placeholder:"Enter asset number",readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Raised By"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(l,{size:16}),B.jsx("span",{children:b&&`${b.firstName||""} ${b.lastName||""}`.trim()||"User"})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsx("label",{className:"raise-issue-field-label",children:"Created On"}),B.jsxs("div",{className:"raise-issue-field-value-with-icon",children:[B.jsx(c,{size:16}),B.jsx("span",{children:q&&h?.createdAt?new Date(h.createdAt).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0}):(new Date).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Description ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsx("textarea",{className:"raise-issue-field-textarea "+(q?"raise-issue-field-readonly":""),value:C,onChange:e=>w(e.target.value),placeholder:"Enter issue description",rows:4,readOnly:q})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Status ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select "+(q?"":"raise-issue-field-readonly"),value:I,onChange:e=>R(e.target.value),disabled:!q,children:[B.jsx("option",{value:Y.OPEN,children:Y.OPEN}),B.jsx("option",{value:Y.IN_PROGRESS,children:Y.IN_PROGRESS}),B.jsx("option",{value:Y.REJECTED,children:Y.REJECTED}),B.jsx("option",{value:Y.RESOLVE,children:Y.RESOLVE})]})]}),B.jsxs("div",{className:"raise-issue-field",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Assignee ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("select",{className:"raise-issue-field-select",value:D,onChange:e=>V(e.target.value),children:[B.jsx("option",{value:"",children:"Unassigned"}),x.map(e=>B.jsx("option",{value:e,children:e},e))]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label",children:["Priority ",B.jsx("span",{className:"raise-issue-required",children:"*"})]}),B.jsxs("div",{className:"raise-issue-priority-buttons",children:[B.jsx("button",{type:"button",className:"priority-button priority-low "+("Low"===E?"active":""),onClick:()=>T("Low"),children:"Low"}),B.jsx("button",{type:"button",className:"priority-button priority-medium "+("Medium"===E?"active":""),onClick:()=>T("Medium"),children:"Medium"}),B.jsx("button",{type:"button",className:"priority-button priority-high "+("High"===E?"active":""),onClick:()=>T("High"),children:"High"})]})]}),B.jsxs("div",{className:"raise-issue-field raise-issue-field-full-width",children:[B.jsxs("label",{className:"raise-issue-field-label-with-icon",children:[B.jsx(d,{size:16}),B.jsx("span",{children:"Comments"})]}),!F&&B.jsx("div",{className:"raise-issue-no-comments",children:"No comments yet"}),B.jsx("textarea",{className:"raise-issue-field-textarea raise-issue-comments-textarea "+(q?"raise-issue-field-readonly":""),value:F,onChange:e=>O(e.target.value),placeholder:"Add a comment...",rows:4,readOnly:q})]})]})}),B.jsx("div",{className:"raise-issue-modal-actions",children:B.jsxs("div",{className:"raise-issue-modal-actions-buttons",children:[q&&h&&B.jsxs(B.Fragment,{children:[I===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-accept",onClick:async()=>{await P(Y.IN_PROGRESS)},disabled:z,children:z?"Processing...":"Accept"}),I===Y.IN_PROGRESS&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-resolve",onClick:async()=>{await P(Y.RESOLVE)},disabled:z,children:z?"Processing...":"Resolve"}),I===Y.OPEN&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-reject",onClick:async()=>{await P(Y.REJECTED)},disabled:z,children:z?"Processing...":"Reject"})]}),!q&&B.jsx("button",{className:"raise-issue-modal-button raise-issue-modal-button-save",onClick:async()=>{if(String(j||"").trim())if(String(C||"").trim())if(String(S||"").trim())if(String($||"").trim())if(String(D||"").trim()){M(!0);try{if(q&&h){const e={title:String(j||"").trim(),description:String(C||"").trim(),workOrderNumber:String(S||"").trim()||"",assetNumber:String($||"").trim()||void 0,formTemplateId:h.formTemplateId||"",component:h.component||{},priority:E,assignee:String(D||"").trim()||void 0,status:I,comments:String(F||"").trim()||""};g&&h._id&&await g(h._id,e),H.showSuccess("Issue updated successfully"),r&&r(),i()}else{if(!s)return H.showError("Component is required"),void M(!1);if(!u||""===String(u||"").trim())return H.showError("Form template is required"),void M(!1);const e={...s,basic:{...s.basic,comments:String(m||"")}},t={title:String(j||"").trim(),workOrderNumber:String(S||"").trim()||void 0,assetNumber:String($||"").trim()||void 0,component:e,description:String(C||"").trim(),formTemplateId:u,assignee:String(D||"").trim()||void 0,priority:E,status:I,comments:String(F||"").trim()||""};let n;f&&(n=await f(t,p||[])),H.showSuccess("Issue raised successfully"),r&&r(n),i()}}catch(e){const t=e?.message||e?.error?.message||(q?"Failed to update issue. Please try again.":"Failed to raise issue. Please try again.");H.showError(t)}finally{M(!1)}}else H.showError("Assignee is required");else H.showError("Asset Number is required");else H.showError("Work Order is required");else H.showError("Description is required");else H.showError("Title is required")},disabled:z||!String(j||"").trim()||!String(C||"").trim()||!String(S||"").trim()||!String($||"").trim()||!String(D||"").trim(),children:z?"Saving...":"Save Changes"})]})})]})});return L(W,document.body)},X=({component:e,condition:r,currentValue:s,thresholdValue:a,formTemplateId:l,workOrderNumber:c,assetNumber:d,onIssueRaised:u,isIssueRaised:m=!1,compact:p=!1})=>{const[h,f]=t(!1),[g,b]=t(null),[x,y]=t(!1),[v,j]=t(!1);n(()=>{m&&j(!0)},[m]),n(()=>{j(!1)},[r?.id]);const N=e=>({greaterThan:">",lessThan:"<",greaterThanOrEqual:"≥",lessThanOrEqual:"≤",equals:"=",notEquals:"≠"}[e]||e),C=i(async()=>{if(m||v){if(g)return void f(!0);y(!0);try{b(null),f(!0)}catch(e){console.error("Error fetching issue:",e),H.showError("Failed to load issue details")}finally{y(!1)}}else b(null),f(!0)},[m,v,l,e,g]),w=i(()=>{f(!1),m||v||b(null)},[m,v]),S=i(e=>{f(!1),b(e||null),j(!0),u&&r?.id&&u(r.id)},[u,r]);return m||v?B.jsx(B.Fragment,{children:h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})}):p?B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved threshold-alert-compact",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content-compact",children:[B.jsx(o,{className:"threshold-alert-icon-compact",size:14}),B.jsx("span",{className:"threshold-alert-message-compact",children:`Threshold ${N(r.operator)} ${a}`}),B.jsx("button",{type:"button",onClick:C,className:"threshold-alert-raise-issue-btn-compact",title:"Raise Issue",children:"Raise Issue"})]})]}),h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})]}):B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"threshold-alert threshold-alert-unresolved",children:[B.jsx("div",{className:"threshold-alert-border"}),B.jsxs("div",{className:"threshold-alert-content",children:[B.jsx("div",{className:"threshold-alert-header",children:B.jsxs("div",{className:"threshold-alert-title-group",children:[B.jsx(o,{className:"threshold-alert-icon",size:20}),B.jsx("span",{className:"threshold-alert-title",children:"Threshold Condition Met - Action Required"})]})}),B.jsxs("div",{className:"threshold-alert-message",children:[(()=>{const t=N(r.operator);return`${e.basic?.label||"Value"}: Value ${s} exceeds threshold ${t} ${a}`})(),B.jsx("span",{className:"threshold-alert-warning",children:" You must raise an issue before submitting the form."})]}),B.jsx("div",{className:"threshold-alert-buttons",children:B.jsx("button",{type:"button",onClick:C,className:"threshold-alert-raise-issue-btn",children:"Raise Issue Now"})})]})]}),h&&B.jsx(K,{isOpen:h,onClose:w,onSuccess:S,component:e,formTemplateId:l,workOrderNumber:c,assetNumber:d,notes:"",attachments:null,issue:g})]})},Z=({id:e,properties:o,validationErrors:a={},formValue:l="",inputType:c="text",readonly:d=!1,disabled:u=!1,touchedFields:m={},formSubmitted:p=!1,mode:h="test",onValueChange:f,onBlur:g,onFocus:b,className:x="",hideLabel:y=!1,formTemplateId:v,onThresholdIssueRaised:j,raisedThresholdIssues:N=new Set,workOrderNumber:C,assetNumber:w})=>{const S=e=>null==e?"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"object"==typeof e?Array.isArray(e)?"":"value"in e?S(e.value):"label"in e?S(e.label):"":String(e||""),k=r(e),$=r(null);n(()=>{e!==k.current&&(console.warn(`[DfFormInput] Component ID changed from ${k.current} to ${e}`),k.current=e)},[e]);const A=S(l||o?.basic?.defaultValue||""),[E,T]=t(A),[L,I]=t(!1),[R,D]=t(!1),[V,F]=t(new Set),[O,z]=t(A),M=()=>{if(c)return c;const e=o?.name;return"text-input"===e?"text":"number-input"===e?"number":"email-input"===e?"email":"text"},q=i(e=>{const t=(()=>{const e={};if(o?.validation?.required&&(e.required=!0),"email"===M()&&(e.email=!0),"text"===M()){const t=o.validation;t?.minLength&&(e.minLength=t.minLength),t?.maxLength&&(e.maxLength=t.maxLength)}if("number"===M()){const t=o.validation;t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&(e.lowerLimit=t.lowerLimit),t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&(e.upperLimit=t.upperLimit)}return e})(),n={};let i=!0;const r="string"==typeof e?e:null!=e?String(e):"";if(!t.required||r&&""!==r.trim()||(n.required=!0,i=!1),t.email&&r&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(r)&&(n.email=!0,i=!1),t.minLength&&r&&r.length<t.minLength&&(n.minLength=!0,i=!1),t.maxLength&&r&&r.length>t.maxLength&&(n.maxLength=!0,i=!1),"number"===M())if(delete n.pattern,delete n.min,delete n.max,r&&""!==r.trim()){const e=r.trim(),s=parseFloat(e);isNaN(s)||("lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&s<t.lowerLimit&&(n.lowerLimit=!0,i=!1),"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&s>t.upperLimit&&(n.upperLimit=!0,i=!1))}else delete n.lowerLimit,delete n.upperLimit;return{isValid:i,errors:n}},[o,M]),P=i(t=>{const n="string"==typeof t?t:null!=t?String(t):"";if(T(n),f){const t=q(n),i=k.current,r={id:i,value:n,isValid:t.isValid,errors:t.errors};i!==e&&console.error(`[DfFormInput] ID mismatch in handleValueChange! ref: ${i}, prop: ${e}`),f(r)}},[e,f,q,k]);n(()=>{L&&(m[e]=!0)},[L,e,m]),n(()=>{if("edit"===h){I(!1);T(o?.basic?.defaultValue||"")}else"test"===h&&(I(!1),T(""))},[h,o?.basic?.defaultValue]),n(()=>{const t=k.current,n=S(l||o?.basic?.defaultValue||"");n===E||R||""===n&&""!==String(E||"").trim()?""===n&&String(E||"").trim():null!=l&&(t===e?T(n):console.error(`[DfFormInput] ID mismatch! componentIdRef: ${t}, prop id: ${e}`))},[l,E,R,o?.basic?.defaultValue,e]),n(()=>{p&&I(!0)},[p]),n(()=>{"test"!==h&&T("")},[h]);const W=i((e,t)=>{if(!t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(isNaN(n)||isNaN(i))return!1;switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}},[]),_=s(()=>o?.condition?.conditions||[],[o?.condition]);n(()=>{E!==O&&(F(new Set),z(E))},[E,O]);const U=s(()=>{if("test"!==h||!E||""===E)return null;const e=_.filter(e=>W(e,E));if(0===e.length)return null;for(const t of e)if(!V.has(t.id))return t;return null},[E,_,V,h,W,N]),G=i(e=>{F(t=>new Set(t).add(e))},[]),H=M(),Y=u||d||o?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:`form-group ${(()=>{const e=o?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!y&&o.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[o.basic.label,o.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",ref:$,children:[B.jsx("input",{type:H,id:e,value:E,onChange:e=>{const t=e.target.value;P(t)},onFocus:()=>{D(!0),b&&b()},onBlur:()=>{if(D(!1),I(!0),"test"===h&&f){const t="string"==typeof E?E:null!=E?String(E):"",n=q(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};f(i)}g&&g()},placeholder:o.basic.placeholder,disabled:Y,readOnly:d||o?.validation?.readonly,className:(()=>{const t="form-control";if("test"===h){const n="string"==typeof E?E:null!=E?String(E):"",i=q(n);if(i.isValid)return`${t} ${x}`.trim();const r=!i.isValid&&L,s=a[e]&&(L||p)&&!i;return`${t} ${r||s?"is-invalid":""} ${x}`.trim()}return`${t} ${x}`.trim()})()}),B.jsx(J,{validationErrors:a,fieldId:e,touchedFields:m,formSubmitted:p,properties:o,localValidation:q(E),isTouched:L,mode:h})]})]}),U&&"test"===h&&(()=>{const e=N?.has(U.id)||!1,t=null!==$.current?.closest(".table-cell")||null!==$.current?.closest(".cell-content")||null!==$.current?.closest(".datagrid-table-view")||null!==$.current?.closest(".datagrid-list-view")||x.includes("table-cell")||x.includes("cell-content");return B.jsx(X,{component:o,condition:U,currentValue:E,thresholdValue:U.value,formTemplateId:v,workOrderNumber:C,assetNumber:w,onDismiss:()=>G(U.id),onIssueRaised:j,isIssueRaised:e,compact:t},`${U.id}-${e}`)})()]})},Q=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),r?.validation?.minLength&&e&&e.length<r.validation.minLength&&(t.minLength=!0,n=!1),r?.validation?.maxLength&&e&&e.length>r.validation.maxLength&&(t.maxLength=!0,n=!1),{isValid:n,errors:t}},[r]),N=i(t=>{if(x(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{""===b&&""!==o&&x(o)},[o]),n(()=>{d&&v(!0)},[d]),n(()=>{"test"!==u&&x("")},[u]);const C=l||a||r?.validation?.readonly,w=r?.validation?.rows||4;return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("textarea",{id:e,value:b,onChange:e=>{const t=e.target.value;N(t)},onFocus:()=>{h&&h()},onBlur:()=>{v(!0),p&&p()},placeholder:r.basic.placeholder,disabled:C,readOnly:a||r?.validation?.readonly,rows:w,className:`form-textarea ${!j(b).isValid&&y?"is-invalid":""} ${f}`.trim()}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})]})},ee=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=r?.validation?.multiple||!1,N=i(e=>{const t={};let n=!0;return r?.validation?.required&&(j?Array.isArray(e)&&0!==e.length||(t.required=!0,n=!1):(!e||"string"==typeof e&&""===e.trim())&&(t.required=!0,n=!1)),{isValid:n,errors:t}},[r,j]),C=i(t=>{if(x(t),m){const n=N(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,N]);n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{JSON.stringify(o)!==JSON.stringify(b)&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const w=l||a||r?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("select",{id:e,value:b,onChange:e=>{if(j){const t=Array.from(e.target.selectedOptions,e=>e.value);C(t)}else C(e.target.value)},onFocus:()=>{h&&h()},onBlur:()=>{v(!0),p&&p()},disabled:w,multiple:j,className:`form-select ${!N(b).isValid&&y?"is-invalid":""} ${f}`.trim(),children:[!j&&B.jsx("option",{value:"",children:r.basic.placeholder||"Select an option"}),(r.options||[]).map((e,t)=>B.jsx("option",{value:e.value,disabled:e.disabled,children:e.label},t))]}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:N(b),isTouched:y,mode:u})]})]})},te=({id:e,properties:r,validationErrors:s={},formValue:o=[],readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(!1),y=Array.isArray(o)?o:[],v=i(e=>{const t={};let n=!0;return r?.validation?.required&&0===e.length&&(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),j=i(t=>{if(m){const n=v(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,v,y]),N=(e,t)=>{let n;n=t?[...y,e]:y.filter(t=>t!==e),j(n)},C=()=>{h&&h()},w=()=>{x(!0),p&&p()};n(()=>{b&&(c[e]=!0)},[b,e,c]),n(()=>{},[o,e,y]),n(()=>{d&&x(!0)},[d]);const S=l||a||r?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group checkbox-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${r?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!g&&r.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:v(y),isTouched:b,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"checkbox",id:`${e}-${n}`,name:e,value:t.value,checked:y.includes(t.value),onChange:e=>{N(t.value,e.target.checked)},onFocus:C,onBlur:w,disabled:S||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:v(y),isTouched:b,mode:u})]})})})},ne=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),N=i(t=>{if(x(t),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=e=>{N(e)},w=()=>{h&&h()},S=()=>{v(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{o!==b&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const k=l||a||r?.validation?.readonly;return B.jsx(B.Fragment,{children:B.jsx("div",{className:`form-group radio-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${r?.basic?.inlineLayout?"inline-layout":"vertical-layout"} ${f}`,children:!g&&r.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:b===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})]}):B.jsxs("div",{className:"input-wrapper",children:[B.jsx("div",{className:"mt-2 "+(r?.basic?.inlineLayout?"inline-options-grid":"space-y-2"),children:(r.options||[]).map((t,n)=>B.jsxs("div",{className:"form-check",children:[B.jsx("input",{type:"radio",id:`${e}-${n}`,name:e,value:t.value,checked:b===t.value,onChange:()=>C(t.value),onFocus:w,onBlur:S,disabled:k||t.disabled,className:"form-check-input"}),B.jsx("label",{htmlFor:`${e}-${n}`,className:"form-check-label",children:t.label})]},n))}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})})})},ie=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const[b,x]=t(o),[y,v]=t(!1),j=i(e=>{const t={};let n=!0;return!r?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[r]),N=i(t=>{if(x(t),v(!0),m){const n=j(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,j]),C=()=>{h&&h()},w=()=>{v(!0),p&&p()};n(()=>{y&&(c[e]=!0)},[y,e,c]),n(()=>{o!==b&&x(o)},[o,b]),n(()=>{d&&v(!0)},[d]);const S=()=>r?.basic?.inlineLayout?"inline-layout":"grid-layout",k=e=>{const t=e?.toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"},$=e=>{if(void 0!==e?.icon&&""!==e.icon)return e.icon;return"pass"===k(e?.value||e)?"✓":"×"},A=(e,t)=>e?.color||e?.backgroundColor?{color:t?"#ffffff":e.color||"#00814b",backgroundColor:t?e.color||"#00814b":e.backgroundColor||"#34bd4914",borderColor:e.color||"#00814b"}:{},E=e=>{if(e?.color||e?.backgroundColor)return"segment-button-label segment-button-custom";return"segment-button-label "+("pass"===k(e?.value||e)?"pass-button":"fail-button")},T=l||a||r?.validation?.readonly;return B.jsxs(B.Fragment,{children:[B.jsx("div",{className:`form-group segment-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()} ${f}`,children:!g&&r.basic.label?B.jsxs(B.Fragment,{children:[B.jsxs("label",{className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(r.options||[]).map((t,n)=>{const i=b===t.value,r=A(t,i),s=E(t),o=$(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!T&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:T||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:s,style:Object.keys(r).length>0?r:void 0,children:[o&&B.jsx("span",{className:"segment-icon",children:o}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})]}):B.jsx("div",{className:"form-segment-wrapper",children:B.jsx("div",{className:`form-segment-container ${S()}`,children:(r.options||[]).map((t,n)=>{const i=b===t.value,r=A(t,i),s=E(t),o=$(t);return B.jsxs("div",{className:"form-segment-option "+(i?"selected":""),children:[B.jsx("input",{type:"radio",id:`${e}_option_${n}`,name:e,value:t.value,checked:i,onChange:()=>!T&&!t.disabled&&N(t.value),onFocus:C,onBlur:w,disabled:T||t.disabled,className:"form-segment-radio"}),B.jsxs("label",{htmlFor:`${e}_option_${n}`,className:s,style:Object.keys(r).length>0?r:void 0,children:[o&&B.jsx("span",{className:"segment-icon",children:o}),B.jsx("span",{className:"segment-text",children:t.value})]})]},n)})})})}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:j(b),isTouched:y,mode:u})]})},re=({id:e,properties:r,validationErrors:s={},formValue:o="",readonly:a=!1,disabled:l=!1,touchedFields:c={},formSubmitted:d=!1,mode:u="preview",onValueChange:m,onBlur:p,onFocus:h,className:f="",hideLabel:g=!1})=>{const b=i(e=>{if(!e)return"";if("string"==typeof e){if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e))return e;const t=new Date(e);if(!isNaN(t.getTime())){const e=r.name||"",n=r.basic?.dateTimeMode||("datetime-picker"===e?"datetime":"date");if("datetime"===n){return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}T${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}return e}if(e instanceof Date){if(isNaN(e.getTime()))return"";const t=r.name||"",n=r.basic?.dateTimeMode||("datetime-picker"===t?"datetime":"date");if("datetime"===n){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}T${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}if("time"===n){return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}if("object"==typeof e&&null!==e){if("value"in e&&e.value)return b(e.value);if("date"in e&&e.date)return b(e.date);try{const t=String(e),n=new Date(t);if(!isNaN(n.getTime()))return b(n)}catch(e){}return""}return""},[r]),x=b(o),[y,v]=t(x),[j,N]=t(!1),[C,w]=t(!1),S=i(e=>{const t={};let n=!0;const i=r.name||"",s=r.basic?.dateTimeMode||("datetime-picker"===i?"datetime":"date"),o=e?String(e).trim():"";if(r?.validation?.required&&(!o||""===o))return t.required=!0,n=!1,{isValid:n,errors:t};if(o&&""!==o)if("time"===s){if(!/^([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/.test(o))return t.invalidDate=!0,n=!1,{isValid:n,errors:t}}else if("datetime"===s){const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(r?.validation?.minDate){const i=new Date(r.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date and time must be on or after ${i.toLocaleDateString()}`,n=!1)}if(r?.validation?.maxDate){const i=new Date(r.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date and time must be on or before ${i.toLocaleDateString()}`,n=!1)}}else{const e=new Date(o);if(isNaN(e.getTime()))return t.invalidDate=!0,n=!1,{isValid:n,errors:t};if(r?.validation?.minDate){const i=new Date(r.validation.minDate);e<i&&(t.minDate=!0,t.minDateMessage=`Date must be on or after ${i.toLocaleDateString()}`,n=!1)}if(r?.validation?.maxDate){const i=new Date(r.validation.maxDate);e>i&&(t.maxDate=!0,t.maxDateMessage=`Date must be on or before ${i.toLocaleDateString()}`,n=!1)}}return{isValid:n,errors:t}},[r]),k=i(t=>{if(v(t),m){const n=S(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};m(i)}},[e,m,S]);n(()=>{j&&(c[e]=!0)},[j,e,c]),n(()=>{const e=b(o);e===y||C||v(e)},[o,y,C,b]),n(()=>{d&&N(!0)},[d]);const $=l||a||r?.validation?.readonly,A=r.name||"",E=r.basic?.dateTimeMode||("datetime-picker"===A?"datetime":"date"),T=(()=>{switch(E){case"time":return"time";case"datetime":return"datetime-local";default:return"date"}})();return B.jsxs("div",{className:`form-group ${(()=>{const e=r?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!g&&r.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[r.basic.label,r.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsx("input",{type:T,id:e,value:y,onChange:e=>{const t=e.target.value;k(t)},onFocus:()=>{w(!0),h&&h()},onBlur:()=>{if(w(!1),N(!0),m){const t=S(y),n={id:e,value:y,isValid:t.isValid,errors:t.errors};m(n)}p&&p()},disabled:$,readOnly:a||r?.validation?.readonly,min:r?.validation?.minDate,max:r?.validation?.maxDate,className:`form-date ${!S(y).isValid&&j?"is-invalid":""} ${f}`.trim()}),B.jsx(J,{validationErrors:s,fieldId:e,touchedFields:c,formSubmitted:d,properties:r,localValidation:S(y),isTouched:j,mode:u})]})]})},se=({id:e,properties:s,validationErrors:o={},formValue:a="",readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="preview",onValueChange:p,onBlur:h,onFocus:f,className:g="",hideLabel:b=!1})=>{const x=r(null),[y,v]=t(!1),[j,N]=t(!1),[C,w]=t(a),[S,k]=t(!1),$=i(e=>{const t={};let n=!0;return!s?.validation?.required||e&&""!==e.trim()||(t.required=!0,n=!1),{isValid:n,errors:t}},[s]),A=i(t=>{if(w(t),p){const n=$(t),i={id:e,value:t,isValid:n.isValid,errors:n.errors};p(i)}},[e,p,$]),E=i(()=>{const e=document.documentElement.classList.contains("dark")||"dark"===document.documentElement.getAttribute("data-theme");let t=getComputedStyle(document.documentElement).getPropertyValue("--df-color-fb-input-bg").trim();t||(t=e?"#2c2e34":"#ffffff");return{strokeColor:e?"#ffffff":"#000000",backgroundColor:t}},[]),T=i(t=>{if(!t)return;const n=x.current;if(!n)return;const i=n.getContext("2d");if(!i)return;const r=new Image;r.onload=()=>{i.clearRect(0,0,n.width,n.height);const e=E();i.fillStyle=e.backgroundColor,i.fillRect(0,0,n.width,n.height);const t=n.width/n.height,s=r.width/r.height;let o=n.width,a=n.height,l=0,c=0;s>t?(a=n.width/s,c=(n.height-a)/2):(o=n.height*s,l=(n.width-o)/2),i.drawImage(r,l,c,o,a)},r.onerror=n=>{console.error("DfFormSignature: error loading image",{id:e,error:n,dataURL:t.substring(0,50)+"..."})},r.src=t},[E,e]),L=i(()=>{const e=x.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height,e.style.width=n.width+"px",e.style.height=n.height+"px";const i=E();t.strokeStyle=i.strokeColor,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",C?T(C):(t.fillStyle=i.backgroundColor,t.fillRect(0,0,e.width,e.height))},[C,E,T]),I=i(()=>{setTimeout(()=>{L()},100)},[L]);n(()=>{const e=()=>{I()},t=new MutationObserver(e=>{e.forEach(e=>{if("attributes"===e.type&&"class"===e.attributeName){const t=e.target;t.classList.contains("form-canvas-container")&&(t.classList.contains("mobile-view")||t.classList.contains("tablet-view")||t.classList.contains("desktop-view"))&&I()}})});return t.observe(document.body,{attributes:!0,attributeFilter:["class"],subtree:!0}),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[I]);const R=i(e=>{const t=x.current;if(!t)return{x:0,y:0};const n=t.getBoundingClientRect(),i=t.width/n.width,r=t.height/n.height,s=e.type.includes("mouse")?e.clientX:e.touches[0].clientX,o=e.type.includes("mouse")?e.clientY:e.touches[0].clientY;return{x:(s-n.left)*i,y:(o-n.top)*r}},[]),D=e=>{if(l||c||s?.validation?.readonly)return;if(e.target.closest(".clear-signature-btn"))return;e.preventDefault(),e.stopPropagation(),v(!0),N(!0);const t=x.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:r}=R(e),o=E();n.strokeStyle=o.strokeColor,n.lineWidth=2,n.lineCap="round",n.lineJoin="round",n.beginPath(),n.moveTo(i,r)},V=e=>{if(!y)return;e.preventDefault(),e.stopPropagation();const t=x.current;if(!t)return;const n=t.getContext("2d");if(!n)return;const{x:i,y:r}=R(e);n.lineTo(i,r),n.stroke()},F=()=>{if(!y)return;v(!1),k(!0);const e=x.current;if(e){(e=>{const t=e.getContext("2d");if(!t)return!1;const n=t.getImageData(0,0,e.width,e.height).data;for(let e=0;e<n.length;e+=4){const t=n[e],i=n[e+1],r=n[e+2];if(n[e+3]>0&&(t<255||i<255||r<255))return!0}})(e);const t=e.toDataURL("image/png");w(t),A(t),setTimeout(()=>{k(!1)},100)}else k(!1)},O=i(()=>{const e=x.current;if(!e)return;const t=e.getContext("2d");if(!t)return;const n=E();if(t.strokeStyle=n.strokeColor,C){const i=C,r=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,r.width,r.height),i&&T(i)}else{const i=e.getBoundingClientRect();t.fillStyle=n.backgroundColor,t.fillRect(0,0,i.width,i.height)}},[E,C,T]);n(()=>{const e=new MutationObserver(e=>{e.forEach(e=>{"attributes"!==e.type||"class"!==e.attributeName&&"data-theme"!==e.attributeName||O()})});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>{e.disconnect()}},[O]);n(()=>{j&&(d[e]=!0)},[j,e,d]),n(()=>{if(!(a===C||y||S||""!==C&&""===a)){if(a===C)return;w(a),a&&T(a)}},[a,C,y,S]),n(()=>{u&&N(!0)},[u]),n(()=>{if("test"!==m){w("");const e=x.current;if(e){const t=e.getContext("2d");if(t){const n=e.getBoundingClientRect();e.width=n.width,e.height=n.height;const i=E();t.fillStyle=i.backgroundColor,t.fillRect(0,0,n.width,n.height)}}}},[m]),n(()=>{L()},[m]);const z=c||l||s?.validation?.readonly;return B.jsxs("div",{className:`form-group ${(()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"})()}`,children:[!b&&s.basic.label&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic.label,s.validation.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"input-wrapper",children:[B.jsxs("div",{className:"signature-container",style:{position:"relative",width:"100%",maxWidth:"100%",overflow:"hidden"},children:[B.jsx("canvas",{ref:x,id:e,className:`form-signature ${!$(C).isValid&&j?"is-invalid":""} ${g}`.trim(),onMouseDown:D,onMouseMove:V,onMouseUp:F,onMouseLeave:F,onTouchStart:D,onTouchMove:V,onTouchEnd:F,onFocus:()=>{f&&f()},onBlur:()=>{h&&h()},style:{width:"100%",height:"150px",border:"2px solid var(--df-color-primary-border)",borderRadius:"6px",cursor:z?"not-allowed":"crosshair",backgroundColor:"var(--df-color-fb-input-bg)",touchAction:"none",userSelect:"none"}}),!z&&B.jsx("button",{type:"button",onClick:e=>(e=>{e?.preventDefault(),e?.stopPropagation();const t=x.current;if(!t)return;const n=t.getBoundingClientRect();t.width=n.width,t.height=n.height;const i=t.getContext("2d");if(!i)return;const r=E();i.fillStyle=r.backgroundColor,i.fillRect(0,0,n.width,n.height),i.strokeStyle=r.strokeColor,i.lineWidth=2,i.lineCap="round",i.lineJoin="round",w(""),A("")})(e),className:"clear-signature-btn",style:{position:"absolute",bottom:"8px",right:"8px",padding:"4px 8px",backgroundColor:"var(--df-color-error-primary)",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",fontSize:"0.75rem",fontWeight:"500",zIndex:10,transition:"all 0.2s ease",minWidth:"60px",minHeight:"28px"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-dark, #dc2626)",e.currentTarget.style.transform="scale(1.05)"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="var(--df-color-error-primary)",e.currentTarget.style.transform="scale(1)"},children:"Clear"})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:s,localValidation:$(C),isTouched:j,mode:m})]})]})},oe=({id:e,properties:s,validationErrors:o={},formValue:a=null,readonly:l=!1,disabled:c=!1,touchedFields:d={},formSubmitted:u=!1,mode:m="test",onValueChange:p,onBlur:h,onFocus:f,className:g="",hideLabel:b=!1})=>{const[x,y]=t([]),[v,j]=t(!1),[N,C]=t(!1),w=r(null),S=i(t=>{if(!t)return[];const n=Array.isArray(t)?t:Array.from(t),i=[];return n.forEach((t,n)=>{if(t&&"object"==typeof t&&!(t instanceof File)&&!(t instanceof Blob)){const r=t;if(r.data||r.url||r.name&&r.type){const t=r.name||r.fileName||`file-${n}`,s=r.size||r.fileSize||0,o=r.type||r.fileType||r.mimeType||"";let a;if(r.url)a=r.url;else if(r.data){const e=r.data;if("string"==typeof e)if(e.startsWith("data:"))a=e;else{const t=e.replace(/\s/g,"");if(/^[A-Za-z0-9+/=]+$/.test(t)&&t.length>10){let e=o;e||(e=t.startsWith("/9j/")||t.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?"image/jpeg":t.startsWith("iVBORw0KGgo")?"image/png":t.startsWith("R0lGOD")?"image/gif":t.startsWith("UklGR")?"image/webp":"image/png"),a=`data:${e};base64,${t}`}else a=e}}const l=new File([],t,{type:o});return void i.push({file:l,id:`${e}-file-${n}`,size:s,type:o,name:t,preview:a})}}let r,s,o=0,a="",l="";if(t instanceof File||t instanceof Blob){const e=t;if(o=e.size||0,a=e.type||"",l=e.name||`file-${n}`,s=e,a.startsWith("image/"))try{r=URL.createObjectURL(e)}catch(e){console.error("Error creating object URL:",e),r=void 0}}else if("string"==typeof t){const e=t,i=e.replace(/\s/g,""),o=i.length>50&&/^[A-Za-z0-9+/=]+$/.test(i)&&!e.startsWith("http")&&!e.startsWith("https")&&!e.startsWith("data:")&&!e.startsWith("blob:")&&!e.startsWith("/");let c=e;if(o){let e="image/png";i.startsWith("/9j/")||i.startsWith("iVBORw0KGgoAAAANSUhEUgAA")?e="image/jpeg":i.startsWith("iVBORw0KGgo")?e="image/png":i.startsWith("R0lGOD")?e="image/gif":i.startsWith("UklGR")&&(e="image/webp"),c=`data:${e};base64,${i}`}let d="";if(c.startsWith("data:")){const e=c.match(/filename=([^;]+)/i);if(e)d=decodeURIComponent(e[1]);else{const e=c.match(/data:([^;]+)/);if(e){const t=e[1];d=`file-${n+1}.${t.includes("image")?t.includes("jpeg")?"jpg":"png":t.includes("pdf")?"pdf":t.includes("word")?"doc":t.includes("excel")?"xls":"file"}`}else d=`file-${n+1}`}}else if(c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))try{const t=new URL(e),i=t.pathname.split("/").pop()||"";if(i&&i.includes("."))d=decodeURIComponent(i);else{const e=t.searchParams.get("filename")||t.searchParams.get("name");d=e?decodeURIComponent(e):`file-${n+1}`}}catch(t){const i=e.lastIndexOf("/"),r=i>=0?e.substring(i+1):e,s=r.indexOf("?"),o=s>=0?r.substring(0,s):r;d=o&&o.includes(".")?decodeURIComponent(o):`file-${n+1}`}else d=`file-${n+1}`;if(l=d||`file-${n+1}`,c.startsWith("data:")){const e=c.indexOf(";");a=e>5?c.substring(5,e):"application/octet-stream"}else{const e=c.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i)||l.match(/\.(jpg|jpeg|png|gif|webp|svg|pdf|doc|docx|xls|xlsx|zip|rar)$/i);if(e){a={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",zip:"application/zip",rar:"application/x-rar-compressed"}[e[1].toLowerCase()]||"application/octet-stream"}else a=o?"image/png":"application/octet-stream"}(c.startsWith("data:image")||c.startsWith("http://")||c.startsWith("https://")||c.startsWith("blob:"))&&(r=c),s=new File([],l,{type:a})}else{if(!t||"object"!=typeof t)return;{const e=t;if(l=e.name||e.fileName||`file-${n}`,o=e.size||e.fileSize||0,a=e.type||e.fileType||e.mimeType||"",e.url||e.path)r=e.url||e.path;else if(a.startsWith("image/")&&e.data){const t=e.data;if("string"==typeof t)if(t.startsWith("data:"))r=t;else{const e=t.replace(/\s/g,"");r=/^[A-Za-z0-9+/=]+$/.test(e)&&e.length>50?`data:${a};base64,${e}`:t}else r=void 0}s=new File([],l,{type:a})}}i.push({file:s,id:`${e}-file-${n}`,size:o,type:a,name:l,preview:r})}),i},[e]),k=i(()=>({isValid:!0,errors:{}}),[]),$=i(t=>{if(l||c)return;const n=S(t),i=x.length>0?[...x,...n]:n,r=s?.validation?.maxFiles||1/0,o=i.slice(0,r);if(y(o),C(!0),p){const t=k(),n={id:e,value:o.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}},[x,s,l,c,p,k,S,e]),A=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]},E=e=>e.startsWith("image/")?"🖼️":e.startsWith("video/")?"🎥":e.startsWith("audio/")?"🎵":e.includes("pdf")?"📄":e.includes("word")||e.includes("document")?"📝":e.includes("excel")||e.includes("spreadsheet")?"📊":e.includes("zip")||e.includes("rar")?"📦":"📁";n(()=>{N&&(d[e]=!0)},[N,e,d]),n(()=>{("edit"===m||"test"===m)&&C(!1)},[m]),n(()=>{const e=S(a);null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==String(a).trim()||"object"==typeof a&&!Array.isArray(a)&&Object.keys(a).length>0)||0===x.length&&null!=a?y(e):(null==a||Array.isArray(a)&&0===a.length)&&x.length>0&&y([])},[a,S,x.length]),n(()=>{u&&C(!0)},[u]),n(()=>()=>{x.forEach(e=>{if(e.preview&&e.preview.startsWith("blob:"))try{URL.revokeObjectURL(e.preview)}catch(e){console.error("Error revoking object URL:",e)}})},[x]);const T=()=>{const e=s?.styles?.labelAlignment;return"left"===e?"label-left":"label-top"},L=c||l||s?.validation?.readonly,I=s?.validation?.multiple||!1,R=s?.validation?.accept||"*/*",D=s?.validation?.maxFiles||1/0,V=x.length<D&&(I||D>1),F="edit"===m,O="preview"===m||"test"===m,z=x.filter(e=>e.type.startsWith("image/")),M=x.filter(e=>!e.type.startsWith("image/")),q=z.length>0;return O&&q?B.jsxs("div",{className:`form-group ${T()}`,children:[!b&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic?.label||"Attachments",s.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:"file-image-display",children:[z.map(e=>B.jsxs("div",{className:"file-image-container",children:[e.preview&&B.jsx("img",{src:e.preview,alt:e.name,className:"file-image-preview"}),B.jsxs("div",{className:"file-image-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:A(e.size)})]})]},e.id)),M.length>0&&B.jsxs("div",{className:"file-other-files",children:[B.jsx("div",{className:"file-other-files-label",children:"Other Files:"}),M.map(e=>B.jsxs("div",{className:"file-item-minimal",children:[B.jsx("div",{className:"file-icon",children:E(e.type)}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:e.name,children:e.name}),B.jsx("div",{className:"file-size",children:A(e.size)})]})]},e.id))]})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:s,localValidation:k(),isTouched:N,mode:m})]})]}):B.jsxs("div",{className:`form-group ${T()}`,children:[!b&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[s.basic?.label||"Attachments",s.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),B.jsxs("div",{className:"file-upload-wrapper",children:[B.jsxs("div",{className:`file-upload-area ${v?"drag-over":""} ${l?"readonly":""} ${c?"disabled":""} ${g}`.trim(),onDragOver:e=>{e.preventDefault(),l||c||j(!0)},onDragLeave:e=>{e.preventDefault(),j(!1)},onDrop:e=>{if(e.preventDefault(),j(!1),l||c)return;const t=e.dataTransfer.files;t.length>0&&$(t)},onClick:e=>{const t=e.target,n=null!==t.closest(".file-item"),i=null!==t.closest(".file-remove");!F||L||0!==x.length||n||i||w.current?.click()},onFocus:()=>{f&&f()},onBlur:()=>{if(C(!0),"test"===m&&p){const t=k(),n={id:e,value:x.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(n)}h&&h()},tabIndex:L?-1:0,children:[B.jsx("input",{ref:w,type:"file",id:e,multiple:I,accept:R,onChange:e=>{const t=e.target.files;t&&t.length>0&&($(t),e.target.value="")},disabled:L,style:{display:"none"}}),0===x.length?B.jsxs("div",{className:"upload-placeholder",onClick:e=>{e.stopPropagation(),F&&!L&&w.current?.click()},children:[B.jsx("div",{className:"upload-icon",children:"📁"}),B.jsx("div",{className:"upload-text",children:s.basic.placeholder&&B.jsx("p",{className:"upload-hint",children:s.basic.placeholder})})]}):B.jsx("div",{className:"file-list",children:x.map(t=>B.jsxs("div",{className:"file-item",children:[B.jsx("div",{className:"file-preview",children:t.preview?B.jsx("img",{src:t.preview,alt:t.name,className:"file-image"}):B.jsx("div",{className:"file-icon",children:E(t.type)})}),B.jsxs("div",{className:"file-info",children:[B.jsx("div",{className:"file-name",title:t.name,children:t.name}),B.jsx("div",{className:"file-size",children:A(t.size)})]}),F&&!L&&B.jsx("button",{type:"button",className:"file-remove",onClick:n=>{n.stopPropagation(),(t=>{if(l||c)return;const n=x.filter(e=>e.id!==t);if(y(n),C(!0),p){const t=k(),i={id:e,value:n.map(e=>e.file),isValid:t.isValid,errors:t.errors};p(i)}})(t.id)},"aria-label":`Remove ${t.name}`,children:"✕"})]},t.id))})]}),x.length>0&&V&&!L&&F&&B.jsxs("button",{type:"button",className:"file-add-more",onClick:e=>{e.stopPropagation(),!L&&w.current&&F&&(w.current.value="",w.current.click())},"aria-label":"Add more files",children:[B.jsx("svg",{className:"file-add-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B.jsx("path",{d:"M12 5v14M5 12h14"})}),B.jsx("span",{className:"file-add-text",children:"Add More Files"})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:d,formSubmitted:u,properties:s,localValidation:k(),isTouched:N,mode:m})]})]})},ae=({id:e,properties:s,validationErrors:o={},formValue:l=null,readonly:c=!1,disabled:d=!1,touchedFields:h={},formSubmitted:f=!1,mode:g="test",onValueChange:b,onBlur:x,onFocus:y,className:v="",hideLabel:j=!1})=>{const[N,C]=t(l),[w,S]=t(!1),[k,$]=t(""),[A,E]=t(!1),[T,L]=t(!1),[I,R]=t({lat:40.7128,lng:-74.006}),[D,V]=t(null),[F,O]=t(10),[z,M]=t(""),[q,P]=t(!1),W=r(null),[_,U]=t(!1),[G,H]=t(null),[Y,K]=t(!1);n(()=>{if(l&&l.latitude&&l.longitude){40.7128===l.latitude&&-74.006===l.longitude||(C(l),V({lat:l.latitude,lng:l.longitude,isCurrentLocation:!1}),R({lat:l.latitude,lng:l.longitude}))}else null==l&&(C(null),V(null))},[l]),n(()=>{T&&40.7128===I.lat&&I.lng},[T,I]),n(()=>{(c||d)&&(T&&L(!1),z&&M(""),_&&(U(!1),H(null)))},[c,d]);const X=i(async(e,t)=>{K(!0);try{const n=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e}&lon=${t}&addressdetails=1&zoom=18`),i=await n.json();if(i&&i.address){const e=i.address;return{placeName:i.display_name||"",city:e.city||e.town||e.village||e.municipality||"",country:e.country||""}}}catch(e){console.error("Reverse geocoding failed:",e)}finally{K(!1)}return{placeName:"",city:"",country:""}},[]),Z=i(async(t,n,i)=>{const r=await X(t,n),s={latitude:t,longitude:n,timestamp:Date.now(),placeName:r.placeName,city:r.city,country:r.country,address:r.placeName,...i};if(C(s),V({lat:t,lng:n,isCurrentLocation:!1}),E(!0),b){b({id:e,value:s,isValid:!0,errors:{}})}},[X,e,b]),Q=i(async()=>{if(c||d)return;S(!0),$("");if(void 0!==window.Capacitor)try{const{Geolocation:e}=window.Capacitor.Plugins;if(e)try{if("granted"!==(await e.requestPermissions()).location)return S(!1),void $("Location permission is required. Please enable location access in your device settings.");const t=await e.getCurrentPosition({enableHighAccuracy:s.validation?.enableHighAccuracy??!0,timeout:s.validation?.timeout??1e4,maximumAge:s.validation?.maximumAge??3e5}),n=t.coords.latitude,i=t.coords.longitude;return V({lat:n,lng:i,isCurrentLocation:!0}),R({lat:n,lng:i}),E(!0),await Z(n,i,{accuracy:t.coords.accuracy,timestamp:Date.now()}),S(!1),void $("")}catch(e){return S(!1),void(e.message?.includes("permission")||e.message?.includes("denied")?$("Location permission is required. Please enable location access in your device settings."):e.message?.includes("timeout")?$("Location request timed out. Please try again."):$("Unable to retrieve your location. Please try again."))}}catch(e){console.warn("Capacitor Geolocation not available, falling back to web geolocation")}if(!navigator.geolocation)return S(!1),void $("Geolocation is not supported by this browser.");const e={enableHighAccuracy:s.validation?.enableHighAccuracy??!0,timeout:s.validation?.timeout??1e4,maximumAge:s.validation?.maximumAge??3e5};navigator.geolocation.getCurrentPosition(async e=>{const t=e.coords.latitude,n=e.coords.longitude;V({lat:t,lng:n,isCurrentLocation:!0}),R({lat:t,lng:n}),E(!0),await Z(t,n,{accuracy:e.coords.accuracy,timestamp:e.timestamp}),S(!1),$("")},e=>{S(!1);let t="Unable to retrieve your location.";switch(e.code){case e.PERMISSION_DENIED:t="Location access denied by user. Please enable location access in your browser/device settings.";break;case e.POSITION_UNAVAILABLE:t="Location information is unavailable.";break;case e.TIMEOUT:t="Location request timed out. Please try again."}$(t)},e)},[c,d,s,Z]),ee=i(()=>{if(!c&&!d&&(C(null),V(null),$(""),E(!0),b)){b({id:e,value:null,isValid:!0,errors:{}})}},[c,d,e,b]),te=i(()=>{c||d||L(!T)},[c,d,T]),ne=i((e,t,n,i,r,s)=>{const o=e-r/2,a=t-s/2,l=156543.03392*Math.cos(n.lat*Math.PI/180)/Math.pow(2,i),c=o*l,d=a*l;return{lat:n.lat+d/111320,lng:n.lng+c/(111320*Math.cos(n.lat*Math.PI/180))}},[]),ie=i(e=>{c||d||!W.current||0===e.button&&(U(!0),H({x:e.clientX,y:e.clientY}),e.preventDefault())},[c,d]),re=i(e=>{if(!_||!G||!W.current)return;const t=e.clientX-G.x,n=e.clientY-G.y,i=156543.03392*Math.cos(I.lat*Math.PI/180)/Math.pow(2,F),r=-n*i/111320,s=t*i/(111320*Math.cos(I.lat*Math.PI/180));R({lat:I.lat+r,lng:I.lng+s}),H({x:e.clientX,y:e.clientY})},[_,G,I,F]),se=i(async e=>{if(!W.current)return;if(_&&G){const t=Math.abs(e.clientX-G.x),n=Math.abs(e.clientY-G.y);if(t>5||n>5)return U(!1),void H(null)}if(c||d)return U(!1),void H(null);const t=W.current.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,{lat:r,lng:s}=ne(n,i,I,F,t.width,t.height);await Z(r,s),U(!1),H(null)},[c,d,W,I,F,ne,Z,_,G]),oe=i(async t=>{if(t.trim()&&!c&&!d){P(!0),$("");try{const n=await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(t)}&limit=5&addressdetails=1`),i=await n.json();if(i&&i.length>0){const t=i[0],n=parseFloat(t.lat),r=parseFloat(t.lon),s=t.address||{},o={latitude:n,longitude:r,address:t.display_name,placeName:t.display_name,city:s.city||s.town||s.village||s.municipality||"",country:s.country||"",timestamp:Date.now()};if(C(o),V({lat:n,lng:r,isCurrentLocation:!1}),R({lat:n,lng:r}),E(!0),b){b({id:e,value:o,isValid:!0,errors:{}})}}else $("No locations found for your search.")}catch(e){$("Failed to search for location. Please try again.")}finally{P(!1)}}},[c,d,e,b]),ae=()=>{y&&y()},le=()=>{E(!0),x&&x()},ce=d||c||s?.validation?.readonly,de=s?.basic?.label||"Location",ue=s?.basic?.description||"";return B.jsxs("div",{className:`form-group ${j?"no-label":""} ${v}`,children:[!j&&B.jsxs("label",{htmlFor:e,className:"form-label",children:[de,s?.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]}),ue&&B.jsx("div",{className:"form-group-description",children:ue}),B.jsxs("div",{className:"location-wrapper",children:[!(c&&N)&&B.jsxs("div",{className:"location-controls",children:[B.jsx("button",{type:"button",className:"location-btn "+(w?"loading":""),onClick:Q,disabled:ce||w,onFocus:ae,onBlur:le,tabIndex:ce?-1:0,children:w?B.jsxs(B.Fragment,{children:[B.jsx(u,{size:16,className:"loading-spinner"}),"Getting Location..."]}):B.jsxs(B.Fragment,{children:[B.jsx(m,{size:16}),"Get Current Location"]})}),B.jsxs("button",{type:"button",className:"location-btn secondary",onClick:te,disabled:ce,onFocus:ae,onBlur:le,tabIndex:ce?-1:0,children:[B.jsx(p,{size:16}),T?"Hide Map":"Choose on Map"]})]}),N&&B.jsxs("div",{className:"location-display",children:[!c&&B.jsx("button",{type:"button",className:"location-clear-btn",onClick:ee,disabled:ce,title:"Clear location",children:B.jsx(a,{size:16})}),N.placeName&&B.jsxs("div",{className:"location-place-name",children:[B.jsx("strong",{children:"Place:"})," ",N.placeName]}),(N.city||N.country)&&B.jsxs("div",{className:"location-address",children:[B.jsx("strong",{children:"Address:"})," ",[N.city,N.country].filter(Boolean).join(", ")]}),B.jsxs("div",{className:"location-coordinates",children:[B.jsx("strong",{children:"Coordinates:"})," ",(pe=N.latitude,he=N.longitude,void 0===pe||void 0===he||isNaN(pe)||isNaN(he)?"":`${Number(pe).toFixed(6)}, ${Number(he).toFixed(6)}`)]}),N.accuracy&&B.jsxs("div",{className:"location-accuracy",children:[B.jsx("strong",{children:"Accuracy:"})," ",(me=N.accuracy,me?`±${Math.round(me)}m`:"")]}),N.timestamp&&B.jsxs("div",{className:"location-timestamp",children:[B.jsx("strong",{children:"Captured:"})," ",new Date(N.timestamp).toLocaleString()]})]}),T&&!c&&B.jsxs("div",{className:"location-map-container",children:[B.jsxs("div",{className:"location-map-header",children:[B.jsx("h4",{children:"Select Location on Map"}),B.jsx("p",{children:"Search for a place or click on the map to select a location"})]}),B.jsx("div",{className:"location-search",children:B.jsx("form",{onSubmit:e=>{e.preventDefault(),z.trim()&&oe(z)},className:"search-form",children:B.jsxs("div",{className:"search-input-group",children:[B.jsx("input",{type:"text",value:z,onChange:e=>{M(e.target.value)},placeholder:"Search for a place (e.g., New York, Paris, Tokyo)",className:"search-input",disabled:ce||q}),B.jsx("button",{type:"submit",className:"search-btn",disabled:ce||q||!z.trim(),children:q?B.jsx(u,{size:16,className:"loading-spinner"}):"Search"})]})})}),B.jsxs("div",{ref:W,className:"location-map "+(_?"dragging":""),onMouseDown:ie,onMouseMove:re,onMouseUp:se,onMouseLeave:()=>{U(!1),H(null)},style:{position:"relative",height:"400px",border:"2px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",cursor:_?"grabbing":"grab",background:`url(https://tile.openstreetmap.org/${F}/${Math.floor((I.lng+180)/360*Math.pow(2,F))}/${Math.floor((1-Math.log(Math.tan(I.lat*Math.PI/180)+1/Math.cos(I.lat*Math.PI/180))/Math.PI)/2*Math.pow(2,F))}.png) center/cover no-repeat`,userSelect:"none"},children:[D&&B.jsx("div",{className:"map-marker "+(D.isCurrentLocation?"current-location":"selected-location"),style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -100%)",zIndex:10},children:B.jsx(p,{size:24})}),B.jsx("div",{className:"map-center-indicator",style:{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"4px",backgroundColor:"var(--df-color-primary)",borderRadius:"50%",zIndex:5}}),B.jsxs("div",{className:"map-controls",children:[B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.min(18,e+1)),disabled:F>=18,children:"+"}),B.jsx("button",{type:"button",className:"map-zoom-btn",onClick:()=>O(e=>Math.max(1,e-1)),disabled:F<=1,children:"−"})]})]}),B.jsxs("div",{className:"location-map-instructions",children:[B.jsx("p",{children:B.jsx("strong",{children:"Instructions:"})}),B.jsxs("ul",{children:[B.jsx("li",{children:"Search for a place using the search box above"}),B.jsx("li",{children:"Click anywhere on the map to select a location"}),B.jsx("li",{children:"Drag the map to pan around"}),B.jsx("li",{children:"Use the zoom buttons (+/−) to zoom in/out"}),B.jsx("li",{children:'Use "Get Current Location" to automatically detect your position'})]})]}),Y&&B.jsxs("div",{className:"location-loading",children:[B.jsx(u,{size:16,className:"loading-spinner"}),B.jsx("span",{children:"Loading address details..."})]})]}),k&&B.jsx("div",{className:"location-error",children:k})]}),B.jsx(J,{validationErrors:o,fieldId:e,touchedFields:h,formSubmitted:f,properties:s,localValidation:{isValid:!0,errors:{}},isTouched:A,mode:g})]});var me,pe,he},le=({id:e,properties:t,className:n="",hideLabel:i=!1})=>{const r=t.styles?.level??t.basic.level??1,s=t.basic.label,o=()=>{const e={};return t?.styles?.fontSize&&(e.fontSize=t.styles.fontSize),t?.styles?.color&&(e.color=t.styles.color),e};return i?null:(()=>{const i={id:e,className:`form-heading h${r} ${t?.styles?.textAlign?`text-${t.styles.textAlign}`:""} ${n}`.trim(),style:o()};switch(r){case 1:default:return B.jsx("h1",{...i,children:s});case 2:return B.jsx("h2",{...i,children:s});case 3:return B.jsx("h3",{...i,children:s});case 4:return B.jsx("h4",{...i,children:s});case 5:return B.jsx("h5",{...i,children:s});case 6:return B.jsx("h6",{...i,children:s})}})()},ce=({id:e,properties:s,mode:o="preview",formValue:a,onValueChange:l,className:c="",hideLabel:d=!1})=>{const[u,m]=t(""),[p,y]=t(s.validation?.listStyle||"numbers"),[v,j]=t("#000000"),N=r(null),C=r(null),w=r(!1),S="edit"===o,k=r({instructions:[],listStyle:"numbers",formValue:void 0}),$=r(o);n(()=>{let e=[],t="numbers";if(null!=a&&("object"==typeof a&&a.instructions?(Array.isArray(a.instructions)?e=a.instructions:"string"==typeof a.instructions&&(e=[a.instructions]),a.listStyle&&(t=a.listStyle)):Array.isArray(a)?e=a:"string"==typeof a&&(e=[a])),0===e.length&&s.basic?.value){const n=s.basic.value;n&&"object"==typeof n&&!Array.isArray(n)&&n.instructions?(Array.isArray(n.instructions)?e=n.instructions:"string"==typeof n.instructions&&(e=[n.instructions]),n.listStyle&&"string"==typeof n.listStyle&&(t=n.listStyle)):Array.isArray(n)?e=n:"string"==typeof n&&(e=[n])}0===e.length&&s.basic?.instructions&&(Array.isArray(s.basic.instructions)?e=s.basic.instructions:"string"==typeof s.basic.instructions&&(e=[s.basic.instructions])),t&&"numbers"!==t||(t=s.validation?.listStyle||s.basic?.value?.listStyle||"numbers");const n=JSON.stringify(e)!==JSON.stringify(k.current.instructions)||t!==k.current.listStyle,i=o!==$.current,r=JSON.stringify(a)!==JSON.stringify(k.current.formValue),l=!k.current.formValue||Array.isArray(k.current.formValue)&&0===k.current.formValue.length||"string"==typeof k.current.formValue&&""===k.current.formValue.trim(),c=null!=a&&(Array.isArray(a)&&a.length>0||"string"==typeof a&&""!==a.trim()||"object"==typeof a&&Object.keys(a).length>0);if(n||i||r||l&&c){const r=e=>"string"!=typeof e?e:e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))),s=e.map(e=>"string"==typeof e?r(e):e),l=s.some(e=>"string"==typeof e&&/<[^>]+>/.test(e));let c="";if(s.length>0)if(l)c=s.join("");else{const e="numbers"===t?"ol":"bullets"===t?"ul":"div",n=s.filter(e=>e&&"string"==typeof e).map(e=>`<li>${e.replace(/\n/g,"<br>")}</li>`).join("");c="div"===e?s.filter(e=>e&&"string"==typeof e).map(e=>`<div>${e.replace(/\n/g,"<br>")}</div>`).join(""):`<${e}>${n}</${e}>`}y(t),m(c),S&&N.current&&(i||n&&N.current.innerHTML.trim()!==c.trim())&&(N.current.innerHTML=c),k.current={instructions:e,listStyle:t,formValue:a},$.current=o}},[a,s.basic?.instructions,s.validation?.listStyle,o,S]),n(()=>{if(S&&N.current){const e=N.current.innerHTML.trim();u.trim()===e||w.current||(N.current.innerHTML=u)}if(w.current){const e=setTimeout(()=>{w.current=!1},200);return()=>clearTimeout(e)}},[u,S]);const A=i(()=>{if(!N.current)return;w.current=!0;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}t!==u&&m(t)},[e,p,l,u]),E=i(()=>{if(!N.current)return;const t=N.current.innerHTML.trim();if(l){l({id:e,value:{instructions:t?[t]:[],listStyle:p},isValid:!0,errors:{}})}m(t),w.current=!1},[e,p,l]),T=i((e,t)=>{document.execCommand(e,!1,t),N.current?.focus(),A()},[A]),L=i(()=>{T("bold")},[T]),I=i(()=>{T("italic")},[T]),R=i(e=>{const t=e.target.value;j(t),T("foreColor",t)},[T]),D=i(t=>{if(y(t),!N.current)return;const n=window.getSelection(),i=n&&n.rangeCount>0?n.getRangeAt(0):null;let r=N.current.innerHTML;if("numbers"===t){if(r=r.replace(/<ul>/gi,"<ol>").replace(/<\/ul>/gi,"</ol>"),!r.includes("<ol>")&&!r.includes("<ul>")){const e=r.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(r="<ol>"+e.map(e=>`<li>${e}</li>`).join("")+"</ol>")}}else if("bullets"===t){if(r=r.replace(/<ol>/gi,"<ul>").replace(/<\/ol>/gi,"</ul>"),!r.includes("<ol>")&&!r.includes("<ul>")){const e=r.split(/<br\s*\/?>/i).filter(e=>e.trim());e.length>0&&(r="<ul>"+e.map(e=>`<li>${e}</li>`).join("")+"</ul>")}}else r=r.replace(/<\/?[ou]l>/gi,"").replace(/<li>/gi,"<div>").replace(/<\/li>/gi,"</div>");if(N.current.innerHTML=r,m(r),i&&n)try{n.removeAllRanges(),n.addRange(i)}catch(e){}if(A(),l){l({id:e,value:{instructions:r?[r]:[],listStyle:t},isValid:!0,errors:{}})}},[e,A,l]),V=i(e=>{const t=e.target.files?.[0];if(!t||!t.type.startsWith("image/"))return;const n=new FileReader;n.onload=e=>{const t=e.target?.result;if(t&&N.current){const e=document.createElement("img");e.src=t,e.style.maxWidth="100%",e.style.height="auto";const n=window.getSelection();if(n&&n.rangeCount>0){const t=n.getRangeAt(0);t.deleteContents(),t.insertNode(e)}else N.current.appendChild(e);A()}},n.readAsDataURL(t),C.current&&(C.current.value="")},[A]),F=i(e=>{e.preventDefault();const t=e.clipboardData.getData("text/plain"),n=window.getSelection();if(n&&n.rangeCount>0){const e=n.getRangeAt(0);e.deleteContents();const i=document.createTextNode(t);e.insertNode(i),e.setStartAfter(i),e.collapse(!0),n.removeAllRanges(),n.addRange(e)}A()},[A]),O=i(e=>document.queryCommandState(e),[]);return B.jsxs("div",{className:`form-group instruction-group ${c}`,children:[!d&&B.jsx("label",{htmlFor:e,className:"instruction-label",children:"Instructions"}),S?B.jsxs("div",{className:"instruction-rich-editor",children:[B.jsxs("div",{className:"instruction-toolbar",children:[B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+(O("bold")?"active":""),onClick:L,title:"Bold","aria-label":"Bold",children:B.jsx(h,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+(O("italic")?"active":""),onClick:I,title:"Italic","aria-label":"Italic",children:B.jsx(f,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsx("div",{className:"toolbar-group",children:B.jsxs("div",{className:"color-picker-wrapper",children:[B.jsx("input",{type:"color",value:v,onChange:R,className:"color-picker-input",title:"Text Color"}),B.jsx("label",{className:"color-picker-label",title:"Text Color",children:B.jsx("span",{style:{color:v},children:"A"})})]})}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn "+("bullets"===p?"active":""),onClick:()=>D("bullets"),title:"Bullet List","aria-label":"Bullet List",children:B.jsx(g,{size:16})}),B.jsx("button",{type:"button",className:"toolbar-btn "+("numbers"===p?"active":""),onClick:()=>D("numbers"),title:"Numbered List","aria-label":"Numbered List",children:B.jsx(b,{size:16})})]}),B.jsx("div",{className:"toolbar-separator"}),B.jsxs("div",{className:"toolbar-group",children:[B.jsx("button",{type:"button",className:"toolbar-btn",onClick:()=>C.current?.click(),title:"Insert Image","aria-label":"Insert Image",children:B.jsx(x,{size:16})}),B.jsx("input",{ref:C,type:"file",accept:"image/*",onChange:V,style:{display:"none"}})]})]}),B.jsx("div",{ref:N,contentEditable:!0,className:"instruction-editor-content",onInput:A,onBlur:E,onPaste:F,"data-placeholder":"Enter instructions (press Enter for a new line)...",suppressContentEditableWarning:!0})]}):B.jsx("div",{className:"instruction-preview-wrapper "+("numbers"===p?"instruction-list-numbers":"bullets"===p?"instruction-list-bullets":""),children:u?B.jsx("div",{className:"instruction-preview-content",dangerouslySetInnerHTML:{__html:u}}):B.jsx("div",{className:"instruction-empty",children:B.jsx("p",{children:"No instructions provided"})})})]})},de=({attachments:e,onRemove:i})=>{const[r,s]=t(new Map);return n(()=>{if(!e)return void s(e=>(e.forEach(e=>URL.revokeObjectURL(e)),new Map));const t=new Map;return e.forEach((e,n)=>{if(e.type.startsWith("image/")){const i=URL.createObjectURL(e);t.set(n,i)}}),s(e=>(e.forEach((e,n)=>{t.has(n)||URL.revokeObjectURL(e)}),t)),()=>{t.forEach(e=>URL.revokeObjectURL(e))}},[e]),e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type.startsWith("image/"),s=r.get(t);return B.jsx("div",{className:"attachment-thumbnail",children:n&&s?B.jsxs(B.Fragment,{children:[B.jsx("img",{src:s,alt:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(a,{size:14})})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"file-icon-placeholder",children:B.jsx(y,{size:20})}),B.jsx("span",{className:"file-name",children:e.name}),B.jsx("button",{type:"button",className:"thumbnail-remove-btn",onClick:()=>i(t),title:"Remove attachment",children:B.jsx(a,{size:14})})]})},t)})}):null},ue=({component:e,mode:s,formTemplateId:o,formValue:a,onNotesChange:l,onAttachmentChange:c,notes:u="",attachments:m=null,onThresholdActionCompletion:p,onThresholdIssueRaised:h,onBasicPropertyActionCompletion:f})=>{const[g,b]=t(u||""),[x,S]=t(m||null),[k,$]=t(!1),[A,E]=t(!1),[T,L]=t(!1),[I,R]=t(!1),[D,V]=t(!1),F=r(null),O=r(a),z=r(!1),M=r(!1);n(()=>{if(!z.current&&null!=u){const e="string"==typeof u?u:String(u||"");b(e),z.current=!0}},[u]),n(()=>{M.current||void 0===m||(S(m),M.current=!0)},[m]),n(()=>{if(z.current&&!k&&null!=u){const e="string"==typeof u?u:String(u||"");g&&""!==String(g||"").trim()||!e||""===e.trim()?e&&""!==e.trim()&&e!==g&&b(e):b(e)}},[u,k,g]),n(()=>{M.current&&void 0!==m&&(!x||m&&m.length>0&&m!==x)&&S(m)},[m,x]),n(()=>{const t=["select","radio","checkbox","segment"].includes(e.name||"");if(t){const t=O.current,n=a;let i=!1;if("checkbox"===e.name){const e=Array.isArray(t)?t:t?[t]:[],r=Array.isArray(n)?n:n?[n]:[];i=JSON.stringify(e.sort())!==JSON.stringify(r.sort())}else i=t!==n&&void 0!==t;if(i){L(!1),R(!1),E(!1),$(!1),V(!1);const e="string"==typeof u?u:String(u||"");e&&""!==e.trim()?b(e):b(""),m&&0!==m.length?S(m):S(null)}O.current=n}t||(O.current=a)},[a,e.name,u,m]);const q=i((e,t)=>{const{operator:n,value:i}=e,r=String(t).toLowerCase(),s=String(i).toLowerCase();switch(n){case"equals":return r===s||String(t)===String(i);case"notEquals":return r!==s&&String(t)!==String(i);case"greaterThan":return Number(t)>Number(i);case"lessThan":return Number(t)<Number(i);case"greaterThanOrEqual":return Number(t)>=Number(i);case"lessThanOrEqual":return Number(t)<=Number(i);default:return!1}},[]),P=i(()=>{if(!(null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length)))return[];const t=e.condition;if(!t||!t.conditions||0===t.conditions.length)return[];const n=[];if("checkbox"===e.name&&Array.isArray(a))a.forEach(e=>{const i=t.conditions.find(t=>q(t,e));i&&!n.find(e=>e.id===i.id)&&n.push(i)});else{const e=t.conditions.find(e=>q(e,a));e&&n.push(e)}return n},[e,a,q]),W=i(t=>{const n=t.target.value;b(n),l&&l(n);const i=P(),r=String(n||"").trim().length>0;i.forEach(e=>{!0===e.enableNotes&&p&&p(e.id,"notes",r)});const s=e.condition;!(s&&s.conditions&&s.conditions.length>0)&&f&&f("notes",r)},[l,P,p,e,f]),_=i(()=>{if(l){const e="string"==typeof g?g:String(g||"");l(e),setTimeout(()=>{$(!1)},0)}else $(!1)},[g,l]),U=i(()=>{_()},[_]),G=i(e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),_())},[_]),H=i(()=>{$(!0)},[]),J=i(()=>{$(!0)},[]),Y=i(()=>{F.current?.click()},[]),X=i(t=>{const n=t.target.files;if(n&&n.length>0){const t=Array.from(n);S(t),c&&c(t);P().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!0)});const i=e.condition;!(i&&i.conditions&&i.conditions.length>0)&&f&&f("attachments",!0)}F.current&&(F.current.value="")},[c,P,p,e,f]),Z=i(t=>{if(x){const n=x.filter((e,n)=>n!==t);if(0===n.length){S(null),c&&c(null);P().forEach(e=>{!0===e.enableAttachment&&p&&p(e.id,"attachments",!1)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("attachments",!1)}else S(n),c&&c(n)}},[x,c,P,p,e,f]),Q=i(()=>{L(!0);P().forEach(e=>{!0===e.enableSendEmail&&p&&p(e.id,"email",!0)});const t=e.condition;!(t&&t.conditions&&t.conditions.length>0)&&f&&f("email",!0),setTimeout(()=>{L(!1)},3e3)},[P,p,e,f]),ee=i(()=>{E(!0)},[]),te=i(()=>{E(!1)},[]),ne=i(()=>{E(!1),R(!0);const t=e.condition;if(t&&t.conditions&&t.conditions.length>0){P().forEach(e=>{!0===e.enableRaiseIssue&&h&&h(e.id)})}else f&&f("issue",!0)},[e,f,P,h]);if("test"!==s)return null;const ie=["select","radio","checkbox","segment"].includes(e.name||""),re=e.basic?.options||e.options||[];let se=!1,oe=!1,ae=!1,le=!1,ce=null;const ue=null!=a&&""!==a&&!(Array.isArray(a)&&0===a.length),me=e.condition,pe=me&&me.conditions&&me.conditions.length>0;if(pe&&ue)if("checkbox"===e.name&&Array.isArray(a)){const e=a;for(const t of e){const e=me.conditions.find(e=>q(e,t));e&&(se=se||!0===e.enableNotes,oe=oe||!0===e.enableAttachment,ae=ae||!0===e.enableRaiseIssue,le=le||!0===e.enableSendEmail)}}else if(ie){const e=me.conditions.find(e=>q(e,a));e&&(se=!0===e.enableNotes,oe=!0===e.enableAttachment,ae=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}else{const e=me.conditions.find(e=>q(e,a));e&&(se=!0===e.enableNotes,oe=!0===e.enableAttachment,ae=!0===e.enableRaiseIssue,le=!0===e.enableSendEmail)}if(!pe){const t=e.basic,n=!0===t?.enableNotes,i=!0===t?.enableAttachment,r=!0===t?.enableRaiseIssue,s=!0===t?.enableSendEmail;if(ie)if(ue)if("checkbox"===e.name){(Array.isArray(a)?a:[a]).forEach(e=>{const t=re.find(t=>!(!t||!t.value)&&(t.value===e||(String(t.value)===String(e)||(t.label===e||String(t.label)===String(e)))));t&&(se=se||!0===t.enableNotes,oe=oe||!0===t.enableAttachment,ae=ae||!0===t.enableRaiseIssue,le=le||!0===t.enableSendEmail,ce||(ce=t))}),se=se||n,oe=oe||i,ae=ae||r,le=le||s}else if(ce=re.find(e=>!(!e||!e.value)&&(e.value===a||(String(e.value)===String(a)||(e.label===a||String(e.label)===String(a))))),ce){const e=!0===ce.enableNotes,t=!0===ce.enableAttachment,o=!0===ce.enableRaiseIssue,a=!0===ce.enableSendEmail;se=e||n,oe=t||i,ae=o||r,le=a||s}else se=n,oe=i,ae=r,le=s;else se=n,oe=i,ae=r,le=s;else se=n,oe=i,ae=r,le=s}if(!(se||oe||ae||le))return null;const he=P(),fe=e.condition,ge=fe&&fe.conditions&&fe.conditions.length>0,be=!!ge&&he.some(e=>!0===e.enableNotes),xe=!!ge&&he.some(e=>!0===e.enableAttachment),ye=!!ge&&he.some(e=>!0===e.enableSendEmail),ve=!!ge&&he.some(e=>!0===e.enableRaiseIssue),je=String(g||"").trim().length>0,Ne=x&&x.length>0,Ce=x?x.length:0;return B.jsxs(B.Fragment,{children:[B.jsxs("div",{className:"component-action-features",children:[B.jsxs("div",{className:"action-icons-toolbar",children:[se&&B.jsxs("button",{type:"button",className:`action-icon-button ${je?"active":""} ${be?"mandatory":""}`,onClick:H,title:"Add Notes",children:[B.jsx(d,{size:14,fill:je?"currentColor":"none"}),be&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),oe&&B.jsxs("button",{type:"button",className:`action-icon-button ${Ne?"active":""} ${xe?"mandatory":""}`,onClick:Y,title:"Add Attachment",children:[B.jsx(y,{size:14,fill:Ne?"currentColor":"none"}),Ce>0&&B.jsx("span",{className:"attachment-count-badge",children:Ce}),xe&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),le&&B.jsxs("button",{type:"button",className:`action-icon-button ${T?"active sent":""} ${ye?"mandatory":""}`,onClick:Q,disabled:T,title:"Send Email",children:[T?B.jsx(B.Fragment,{children:B.jsx(v,{size:14})}):B.jsx(j,{size:14,fill:T?"currentColor":"none"}),ye&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),ae&&B.jsxs("button",{type:"button",className:`action-icon-button ${I?"active":""} ${ve?"mandatory":""}`,onClick:ee,title:"Raise an Issue",children:[B.jsx(N,{size:14,fill:I?"currentColor":"none"}),ve&&B.jsx("span",{className:"mandatory-indicator",children:"*"})]}),(je&&se||Ne&&oe)&&B.jsx("button",{type:"button",className:"action-icon-button accordion-toggle",onClick:()=>V(!D),title:D?"Collapse":"Expand",children:D?B.jsx(C,{size:14}):B.jsx(w,{size:14})})]}),k&&se&&B.jsxs("div",{className:"notes-input-overlay",children:[B.jsx("textarea",{className:"action-notes-textarea",value:g,onChange:W,onBlur:U,onKeyDown:G,placeholder:"Explain which protocols were not followed (Press Ctrl+Enter to save)",rows:4,autoFocus:!0}),B.jsxs("div",{className:"notes-input-actions",children:[B.jsx("button",{type:"button",className:"notes-save-button",onClick:_,title:"Save notes (Ctrl+Enter)",children:"Save"}),B.jsx("button",{type:"button",className:"notes-cancel-button",onClick:()=>{$(!1)},title:"Cancel",children:"Cancel"})]})]}),D&&B.jsxs("div",{className:"actions-content",children:[!k&&je&&se&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",onClick:J,children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",g]})}),Ne&&oe&&B.jsx("div",{className:"attachments-section",children:B.jsx(de,{attachments:x,onRemove:Z})})]}),oe&&B.jsx("input",{ref:F,type:"file",multiple:!0,accept:"image/*,.pdf",onChange:X,style:{display:"none"}})]}),A&&B.jsx(K,{isOpen:A,onClose:te,onSuccess:ne,component:ce?{...e,basic:{...e.basic,label:`${e.basic?.label||"Component"} - ${ce.label||ce.value}`,value:ce.value||e.basic?.value||""}}:e,formTemplateId:o||"",notes:g,attachments:x})]})},me=({attachments:e})=>e&&0!==e.length?B.jsx("div",{className:"attachment-thumbnails-container",children:e.map((e,t)=>{const n=e.type?.startsWith("image/")||!1,i=n?(e=>e.data?e.data.startsWith("data:")?e.data:`data:${e.type||"image/png"};base64,${e.data}`:"")(e):"";return B.jsx("div",{className:"attachment-thumbnail",children:n&&i?B.jsx("img",{src:i,alt:e.name||`Attachment ${t+1}`}):B.jsxs("div",{className:"file-icon-placeholder",children:[B.jsx(y,{size:20}),B.jsx("span",{className:"file-name",children:e.name||`File ${t+1}`})]})},t)})}):null,pe=({component:e})=>{const t=e.basic?.notes||"",n=e.basic?.attachments||[],i=t&&t.trim().length>0,r=n&&n.length>0;return i||r?B.jsx("div",{className:"component-submission-actions",children:B.jsxs("div",{className:"actions-content",children:[i&&B.jsx("div",{className:"notes-summary-section",children:B.jsxs("div",{className:"notes-full-text",children:[B.jsx("span",{className:"notes-label",children:"Notes:"})," ",t]})}),r&&B.jsx("div",{className:"attachments-section",children:B.jsx(me,{attachments:n})})]})}):null},he=({child:e,selectedChild:t,mode:n,onChildSelect:i,onChildDelete:r,renderFormComponent:s,isOverlay:o=!1,isChildrenEditMode:a=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:g,listeners:b,setNodeRef:x,transform:y,transition:v,isDragging:j,isSorting:N}=V({id:e.id,disabled:o||"edit"!==n}),C={transform:O.Transform.toString(y),transition:v,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:x,style:C,className:`form-component section-child ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""} ${a?"children-edit-active":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:[("edit"===n||a)&&B.jsx("div",{className:"child-drag-handle",...b,...g,onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:B.jsx(k,{size:14})}),B.jsxs("div",{className:"form-component-content section-child-content",children:[("edit"===n||a)&&B.jsxs("div",{className:"component-actions child-actions",children:[B.jsx("button",{className:"btn edit-btn",onClick:t=>{t.stopPropagation(),i(e)},onMouseDown:e=>e.stopPropagation(),title:"Edit properties",children:B.jsx($,{size:12})}),B.jsx("button",{className:"btn delete-btn",onClick:t=>r(e,t),onMouseDown:e=>e.stopPropagation(),title:"Delete component",children:B.jsx(A,{size:12})})]}),B.jsxs("div",{className:"component-preview child-preview",children:[s(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]})]})]})},fe=({id:e,properties:r,mode:s="edit",formData:o={},onValueChange:a,onSelect:l,isSelected:c=!1,className:d="",onSectionSelect:u,onChildSelect:m,onChildDelete:p,selectedChild:h,renderFormComponent:f,formTemplateId:g,onThresholdActionCompletion:b,onThresholdIssueRaised:x,onNotesChange:y,onAttachmentChange:v})=>{const[j,N]=t(r.basic.collapsed),[C,k]=t(!1),[$,A]=t(!1),[E,T]=t(r.basic.label),[L,V]=t(r.basic.description),[F,O]=t(r.children||[]),[z,M]=t(!1);n(()=>{O(r.children||[])},[r.children]),n(()=>{T(r.basic.label),V(r.basic.description)},[r.basic.label,r.basic.description]);const{setNodeRef:q,isOver:P}=I({id:`section-${e}`,disabled:"edit"!==s}),W=!("preview"!==s&&"test"!==s||r.children&&r.children.length>0),_=i(t=>{T(t),a?.({id:e,value:{...r,basic:{...r.basic,label:t}}})},[e,r,a]),U=i(t=>{V(t),a?.({id:e,value:{...r,basic:{...r.basic,description:t}}})},[e,r,a]),G=i(e=>{m?.(e)},[m]),H=i((e,t)=>{t.stopPropagation();const n=F.filter(t=>t.id!==e.id);O(n),p?.(e.id)},[p,F,e]),J=i(()=>{u?.(r),l?.()},[u,l,r]),Y=i(e=>{e.stopPropagation(),"edit"===s&&F.length>0&&M(!z)},[s,F.length,z]),K=i(t=>{t.stopPropagation(),N(!j),a?.({id:e,value:{...r,basic:{...r.basic,collapsed:!j}}})},[j,e,r,a]),X=f||i(e=>{const t=o[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let n=t;"number-input"===e.name&&"number"==typeof t?n=String(t):"number-input"===e.name&&null==t&&(n="");const i={id:e.id,properties:e,validationErrors:{},formValue:n,touchedFields:{},formSubmitted:!1,mode:s,onValueChange:a,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...i,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...i,properties:e,readonly:!1,disabled:!1});case"select":const t={...e,options:e.basic?.options||[]};return B.jsx(ee,{...i,properties:t,disabled:!1});case"checkbox":const n={...e,options:e.basic?.options||[]};return B.jsx(te,{...i,properties:n,formValue:[],disabled:!1});case"radio":const r={...e,options:e.basic?.options||[]};return B.jsx(ne,{...i,properties:r,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...i,properties:e,readonly:!1,disabled:!1});case"signature":return B.jsx(se,{...i,properties:e});case"heading":return B.jsx(le,{...i,properties:e});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",e.name]})})}},[s,a,o]);if(W)return null;const ie={backgroundColor:r.styles?.backgroundColor||"var(--df-color-fb-container)",borderColor:r.styles?.borderColor||"var(--df-color-fb-border)",borderWidth:r.styles?.borderWidth||"2px",borderRadius:r.styles?.borderRadius||"8px",padding:r.styles?.padding||"16px",margin:r.styles?.margin||"16px 0"};return B.jsxs("div",{ref:q,className:`df-form-section ${c?"selected":""} ${P?"drag-over":""} ${d}`,style:ie,children:[B.jsxs("div",{className:"section-header "+(z?"children-edit-mode":""),onClick:J,onDoubleClick:Y,children:[B.jsx("div",{className:"section-header-content",children:B.jsxs("div",{className:"section-title",children:[B.jsx("span",{className:"section-toggle",title:j?"Expand section":"Collapse section",role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),K(e)},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),K(e))},style:{marginRight:"8px",display:"inline-flex",alignItems:"center"},children:j?B.jsx(S,{size:18}):B.jsx(w,{size:18})}),"edit"===s&&C?B.jsx("input",{type:"text",value:E,onChange:e=>T(e.target.value),onBlur:()=>{k(!1),_(E)},onKeyDown:e=>{"Enter"===e.key&&(k(!1),_(E))},className:"section-title-input",autoFocus:!0}):B.jsx("h3",{className:"section-title-text",onDoubleClick:()=>"edit"===s&&k(!0),style:{display:"inline",margin:0},children:E||"Untitled Section"})]})}),(L||"edit"===s)&&B.jsx("div",{className:"section-description",children:"edit"===s&&$?B.jsx("textarea",{value:L,onChange:e=>V(e.target.value),onBlur:()=>{A(!1),U(L)},onKeyDown:e=>{"Enter"===e.key&&e.ctrlKey&&(A(!1),U(L))},className:"section-description-input",placeholder:"Section description (optional)",autoFocus:!0}):B.jsx("p",{className:"section-description-text",onDoubleClick:()=>"edit"===s&&A(!0),children:L||"Section description"})})]}),!j&&B.jsx("div",{className:`section-content ${P?"drag-over":""} ${0===F.length?"empty":"has-children"}`,onClick:e=>{e.target===e.currentTarget&&J()},children:B.jsx(R,{items:F.map(e=>e.id),strategy:D,children:0===F.length?B.jsxs("div",{className:"section-empty-state",onClick:J,style:{textAlign:"center",color:"#6b7280",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",cursor:"pointer",border:"2px dotted #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",transition:"all 0.3s ease",margin:"16px 0"},children:[B.jsx("div",{style:{fontWeight:"500",color:P?"#3b82f6":"#374151"},children:P?"Drop components here":"Empty Section"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your section"})]}):F.map(e=>B.jsx(he,{child:e,selectedChild:h||null,mode:s,onChildSelect:G,onChildDelete:H,renderFormComponent:X,isChildrenEditMode:z,formData:o,formTemplateId:g,onNotesChange:y,onAttachmentChange:v,onThresholdActionCompletion:b,onThresholdIssueRaised:x},e.id))})})]})},ge=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:r,onComponentEdit:s,renderFormComponent:o,isOverlay:a=!1,formData:l={},formTemplateId:c,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m,onAttachmentChange:p})=>{const h=l[e.id],f="preview"===n&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0),{attributes:g,listeners:b,setNodeRef:x,transform:y,transition:v,isDragging:j,isSorting:N}=V({id:e.id,disabled:a}),C={transform:O.Transform.toString(y),transition:v,opacity:j?.3:1,zIndex:j?1e3:"auto"};return B.jsxs("div",{ref:x,style:{...C,border:t?.id===e.id?"2px solid #3b82f6":"1px solid var(--df-color-fb-border)",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)",padding:"12px",position:"relative",minHeight:"80px",transition:"all 0.2s ease",boxShadow:t?.id===e.id?"0 4px 12px rgba(59, 130, 246, 0.15)":"0 1px 3px rgba(0, 0, 0, 0.1)",cursor:"pointer"},className:`form-component grid-component ${t?.id===e.id?"selected":""} ${j?"dragging":""} ${N?"sorting":""}`,onClick:()=>!j&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...b,...g,onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"50%",left:"4px",transform:"translateY(-50%)",padding:"4px",backgroundColor:"#f3f4f6",borderRadius:"4px",cursor:"grab",opacity:1,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center"},children:B.jsx(k,{size:12,color:"var(--df-color-text-light)"})}),B.jsxs("div",{className:"component-content",style:{paddingTop:"edit"===n?"24px":"0",paddingLeft:"edit"===n?"28px":"0",minHeight:"60px"},children:[o(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:c,formValue:h,onThresholdActionCompletion:d,onThresholdIssueRaised:u,onNotesChange:m?t=>m(e.id,t):void 0,onAttachmentChange:p?t=>p(e.id,t):void 0}),f&&B.jsx(pe,{component:e})]}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{position:"absolute",top:"4px",right:"4px",display:"flex",gap:"4px",opacity:1,zIndex:10},children:[s&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),s(e)},type:"button",title:"Edit Component",style:{padding:"4px",backgroundColor:"#3b82f6",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#2563eb"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#3b82f6"},children:B.jsx($,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),r(e,t)},type:"button",title:"Delete Component",style:{padding:"4px",backgroundColor:"#ef4444",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor="#dc2626"},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="#ef4444"},children:B.jsx(A,{size:12})})]})]})},be=({gridComponents:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,onComponentUpdate:s,selectedComponent:o,renderFormComponent:a,gridId:l,formData:c={},formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})=>{const{setNodeRef:f,isOver:g}=I({id:`grid-drop-zone-${l}`,disabled:"edit"!==t});return B.jsx("div",{ref:f,className:"grid-drop-zone",style:{border:g?"2px dashed #3b82f6":"2px dashed #d1d5db",borderRadius:"8px",padding:"16px",backgroundColor:g?"var(--df-color-primary-light)":"var(--df-color-fb-container)",minHeight:"120px",transition:"all 0.2s ease",position:"relative"},children:e.length>0?B.jsxs(B.Fragment,{children:[B.jsx(R,{items:e.map(e=>e.id),strategy:F,children:B.jsx("div",{style:{display:"flex",flexDirection:"row",flexWrap:"nowrap",gap:"12px",alignItems:"start",marginBottom:e.length>0?"12px":"0",overflowX:"auto",width:"100%"},children:e.map(e=>B.jsx("div",{style:{flex:"1 1 0",minWidth:"200px",maxWidth:"100%"},children:B.jsx(ge,{component:e,selectedComponent:o,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,onComponentUpdate:s,renderFormComponent:a,formData:c,formTemplateId:d,onThresholdActionCompletion:u,onThresholdIssueRaised:m,onNotesChange:p,onAttachmentChange:h})},e.id))})}),B.jsx("div",{style:{border:g?"2px dashed #3b82f6":"1px dashed var(--df-color-fb-border)",borderRadius:"6px",padding:"12px",backgroundColor:g?"var(--df-color-primary-light)":"var(--df-color-fb-container)",textAlign:"center",color:"var(--df-color-text-light)",fontSize:"12px",transition:"all 0.2s ease",minHeight:"40px",display:"flex",alignItems:"center",justifyContent:"center"},children:g?B.jsx("span",{style:{color:"#3b82f6",fontWeight:"500"},children:"Drop component here to add to grid"}):B.jsx("span",{children:"+ Drop more components here"})})]}):B.jsxs("div",{style:{textAlign:"center",color:"var(--df-color-text-light)",fontSize:"14px",padding:"40px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed var(--df-color-fb-border)",borderRadius:"8px"},children:[B.jsx("div",{style:{fontWeight:"500",color:g?"var(--df-color-primary)":"var(--df-color-text-dark)"},children:g?"Drop components here":"Empty DataGrid"}),B.jsx("div",{style:{fontSize:"12px",color:"#9ca3af"},children:"Drag and drop components here to create your grid"})]})})},xe=({templateComponents:e,dataEntries:t,renderFormComponent:n,renderComponent:i,mode:r="preview",allowAddRemoveEntries:s=!0,addAnotherText:o="Add Another",removeText:a="Remove",maxEntries:l=10,minEntries:c=1,displayAsGrid:d=!0,onAddEntry:u,onRemoveEntry:m,formData:p={},formTemplateId:h,onThresholdActionCompletion:f,onThresholdIssueRaised:g,onNotesChange:b,onAttachmentChange:x,datagridId:y=""})=>0===e.length?B.jsxs("div",{style:{textAlign:"center",padding:"40px",color:"var(--df-color-text-light)",border:"1px dashed #d1d5db",borderRadius:"8px",backgroundColor:"var(--df-color-fb-container)"},children:["No components defined. Add components to see the ",d?"table":"list"," view."]}):d?B.jsxs("div",{className:"datagrid-table-view",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",overflow:"hidden",backgroundColor:"var(--df-color-fb-container)",maxWidth:"100%"},children:[B.jsx("div",{style:{position:"absolute",top:"8px",right:"8px",zIndex:10,fontSize:"12px",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",padding:"4px 8px",borderRadius:"4px",border:"1px solid var(--df-color-fb-border)",opacity:e.length>4?1:0,transition:"opacity 0.2s ease"},children:"← Scroll →"}),B.jsxs("div",{className:"table-scroll-container",style:{overflowX:"auto",overflowY:"hidden",maxWidth:"100%",scrollbarWidth:"thin",scrollbarColor:"var(--df-color-fb-border) var(--df-color-fb-icon-bg)",position:"relative"},children:[B.jsx("div",{className:"table-headers",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,backgroundColor:"var(--df-color-fb-container)",borderBottom:"2px solid var(--df-color-fb-border)",minWidth:150*e.length+"px"},children:e.map((t,n)=>B.jsx("div",{style:{padding:"12px 16px",fontWeight:"600",color:"var(--df-color-text-dark)",borderRight:n<e.length-1?"1px solid var(--df-color-fb-border)":"none",fontSize:"14px",minWidth:"150px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.basic?.label||`Column ${n+1}`},`header-${t.id}`))}),t.length>0?t.map((r,o)=>B.jsxs("div",{className:"table-row",style:{display:"grid",gridTemplateColumns:`repeat(${e.length}, minmax(150px, 1fr))`,borderBottom:o<t.length-1?"1px solid var(--df-color-fb-border)":"none",backgroundColor:o%2==0?"var(--df-color-fb-container)":"var(--df-color-fb-bg)",position:"relative",minWidth:150*e.length+"px",isolation:"isolate"},children:[e.map((t,s)=>{let a=r.components?.[s];const l=`${t.id||`component-${s}`}-entry-${y}-${o}-${s}`;return a=a?a.id!==l?{...a,id:l,basic:{...a.basic,showLabel:!1}}:{...a,id:a.id,basic:{...a.basic,showLabel:!1}}:{...t,id:l,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsx("div",{style:{padding:"12px 16px",borderRight:s<e.length-1?"1px solid var(--df-color-fb-border)":"none",minHeight:"60px",minWidth:"150px",display:"flex",alignItems:"center",overflow:"visible",position:"relative",zIndex:1},children:B.jsx("div",{style:{width:"100%",minWidth:"120px",overflow:"hidden",position:"relative",zIndex:1},children:i?i(a,!0):n(a,!0)})},`${r.id}-${s}`)}),s&&t.length>c&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(o)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{position:"absolute",top:"8px",right:"8px",padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",zIndex:1e3,minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto"},title:a,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]},r.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",borderTop:"1px solid var(--df-color-fb-border)"},children:["No data entries. ",s?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]})]}),s&&B.jsx("div",{style:{padding:"16px",backgroundColor:"var(--df-color-fb-bg)",borderTop:"1px solid var(--df-color-fb-border)",display:"flex",justifyContent:"center",position:"sticky",bottom:0,zIndex:5},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{style:{fontSize:"16px"},children:"+"}),o]})})]}):B.jsxs("div",{className:"datagrid-list-view",style:{display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"var(--df-color-fb-container)"},children:[t.length>0?t.map((o,l)=>B.jsxs("div",{className:"list-entry",style:{border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",padding:"16px",backgroundColor:"var(--df-color-fb-container)",position:"relative",transition:"all 0.2s ease"},children:[B.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--df-color-fb-border)"},children:[B.jsxs("span",{style:{fontWeight:"600",color:"var(--df-color-text-dark)",fontSize:"14px"},children:["Entry #",l+1]}),s&&t.length>1&&B.jsx("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length<=c)&&m)try{m(l)}catch(e){console.error("Error removing entry:",e)}},disabled:t.length<=c,style:{padding:"4px 8px",backgroundColor:t.length<=c?"#f3f4f6":"#ef4444",color:t.length<=c?"#9ca3af":"#ffffff",border:"none",borderRadius:"4px",fontSize:"12px",fontWeight:"500",cursor:t.length<=c?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"4px",minWidth:"24px",height:"24px",justifyContent:"center",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},title:a,onMouseEnter:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#dc2626")},onMouseLeave:e=>{t.length>c&&(e.currentTarget.style.backgroundColor="#ef4444")},children:B.jsx("span",{style:{fontSize:"14px"},children:"×"})})]}),B.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"16px"},children:e.map((e,t)=>{let s=o.components?.[t];const a=`${e.id||`component-${t}`}-entry-${y}-${l}-${t}`;return s||(s=o.components?.find(t=>t.name===e.name&&t.basic?.label===e.basic?.label)),s=s?s.id!==a?{...s,id:a,basic:{...s.basic,showLabel:!1}}:{...s,id:s.id,basic:{...s.basic,showLabel:!1}}:{...e,id:a,basic:{...e.basic,showLabel:!1,defaultValue:void 0,value:void 0}},B.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[B.jsx("label",{style:{fontSize:"12px",fontWeight:"500",color:"var(--df-color-text-light)",textTransform:"uppercase",letterSpacing:"0.05em"},children:e.basic?.label||`Field ${t+1}`}),B.jsxs("div",{style:{minHeight:"40px",display:"flex",alignItems:"center",flexDirection:"column",width:"100%"},children:[i?i(s):n(s),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(s.name)&&B.jsx(ue,{component:s,mode:"test",formTemplateId:h,formValue:p[s.id],onThresholdActionCompletion:f,onThresholdIssueRaised:g,onNotesChange:b?e=>b(s.id,e):void 0,onAttachmentChange:x?e=>x(s.id,e):void 0}),"preview"===r&&(s.basic?.notes&&s.basic.notes.trim().length>0||s.basic?.attachments&&Array.isArray(s.basic.attachments)&&s.basic.attachments.length>0?B.jsx(pe,{component:s}):null)]})]},`${o.id}-${t}`)})})]},o.id)):B.jsxs("div",{style:{padding:"40px",textAlign:"center",color:"var(--df-color-text-light)",backgroundColor:"var(--df-color-fb-container)",border:"1px dashed #d1d5db",borderRadius:"8px"},children:["No data entries. ",s?'Click "Add Another" to add entries.':"Use the properties panel to add entries."]}),"test"===r&&s&&B.jsx("div",{style:{padding:"16px",backgroundColor:"#f8f9fa",border:"1px solid var(--df-color-fb-border)",borderRadius:"8px",display:"flex",justifyContent:"center"},children:B.jsxs("button",{type:"button",onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!(t.length>=l)&&u)try{u()}catch(e){console.error("Error adding entry:",e)}},disabled:t.length>=l,style:{padding:"8px 16px",backgroundColor:t.length>=l?"#f3f4f6":"#10b981",color:t.length>=l?"#9ca3af":"#ffffff",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",cursor:t.length>=l?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:"8px",transition:"all 0.2s ease",pointerEvents:"auto",zIndex:1e3},onMouseEnter:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#059669")},onMouseLeave:e=>{t.length<l&&(e.currentTarget.style.backgroundColor="#10b981")},children:[B.jsx("span",{children:"+"}),o]})})]}),ye=({id:e,properties:s,mode:o="edit",formData:a={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onDataGridSelect:f,onComponentSelect:g,onComponentDelete:b,onComponentEdit:x,onComponentUpdate:y,selectedComponent:v,renderFormComponent:j,onEntryAdd:N,onEntryRemove:C,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L})=>{const[I,R]=t(!1),D=r(!1);let V=s.templateComponents||[];const F=s.entries||[];0===V.length&&F.length>0&&F[0].components&&(V=F[0].components.map(e=>({...e,id:e.id?.replace(/-entry-\d+$/,"")||e.id,basic:{...e.basic,showLabel:!0}}))),n(()=>{if("edit"===o&&!s.templateComponents&&u&&D.current){const t={...s,templateComponents:[]};JSON.stringify(t)!==JSON.stringify(s)&&u({id:e,value:t})}D.current=!0},[s.templateComponents,e,u,s,o]),n(()=>{if(V.length>0){if("test"===o&&0===F.length&&D.current){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...s,entries:[t]};JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n})}return}if("edit"!==o||!D.current)return;if(F.some(e=>e.components?.some((t,n)=>{const i=`${V[n]?.id}-entry-${e.index}-${n}`;return t.id!==i}))&&u){const t=F.map(e=>({...e,components:e.components?.map((t,n)=>({...t,id:`${V[n]?.id}-entry-${e.index}-${n}`}))||[]})),n={...s,entries:t};return void(JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n}))}if(0===F.length&&"edit"===o){const t={id:`entry-${e}-0`,index:0,components:V.map((t,n)=>{const i=t.id||`component-${n}`;return{...t,id:`${i}-entry-${e}-0-${n}`,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}};if(u){const n={...s,entries:[t]};JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n})}}else if(F.length>0){if(F.some(e=>V.some((t,n)=>{const i=e.components?.[n];if(!i)return!0;const r=`${t.id}-entry-${e.index}-${n}`,s=i.id===r,o=JSON.stringify(i.basic?.options)!==JSON.stringify(t.basic?.options)||i.basic?.placeholder!==t.basic?.placeholder||i.basic?.defaultValue!==t.basic?.defaultValue||i.basic?.label!==t.basic?.label||i.validation?.required!==t.validation?.required;return!s||o}))&&u){const t=F.map(t=>{const n=V.map((n,i)=>{let r=t.components?.[i];r||(r=t.components?.find(e=>e.name===n.name&&e.basic?.label===n.basic?.label));const s=`${n.id||`component-${i}`}-entry-${e}-${t.index}-${i}`;if(r){return{...n,id:s,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}return{...n,id:s,basic:{...n.basic,showLabel:!1,defaultValue:void 0,value:void 0}}});return{...t,components:n}}),n={...s,entries:t};JSON.stringify(n)!==JSON.stringify(s)&&u({id:e,value:n})}}}},[V,F,e,u,s,o,s.templateComponents]);const O=i(e=>{e.stopPropagation(),m?.(),f?.(s)},[m,f,s]),z=i((t,n)=>{n.stopPropagation(),b&&b(t,n);const i=V.filter(e=>e.id!==t.id),r=F.map(e=>({...e,components:e.components?.filter(e=>!(e.name===t.name&&e.basic?.label===t.basic?.label))||[]}));u&&u({id:e,value:{...s,templateComponents:i,entries:r}})},[b,s,u,e,V,F]),M=i((t,n)=>{y&&y(t,n);const i=V.map(e=>e.id===t?{...e,...n}:e);u&&u({id:e,value:{...s,templateComponents:i}})},[y,s,u,e,V]),q=i(e=>{"test"===o&&u&&u({id:e.id,value:e.value})},[u]),P=i(()=>{const t=s.entries||[],n=t.length,i={id:`entry-${e}-${n}`,index:n,components:V.map((t,i)=>{const r=`${t.id||`component-${i}`}-entry-${e}-${n}-${i}`;return{...t,id:r,basic:{...t.basic,showLabel:!1,defaultValue:void 0,value:void 0}}}),styles:{}},r=[...t,i];u&&u({id:e,value:{...s,entries:r}}),N?.()},[s,u,e,N,V]),W=i(t=>{const n=s.entries.filter((e,n)=>n!==t).map((t,n)=>({...t,index:n,id:`entry-${e}-${n}`}));u&&u({id:e,value:{...s,entries:n}})},[s,u,e,C]),_=i((e,t=!1)=>{const n=a[e.id]||"defaultValue"in e.basic&&e.basic.defaultValue||"";let i=n;"number-input"===e.name&&"number"==typeof n?i=String(n):"number-input"===e.name&&null==n&&(i="");const r={id:e.id,properties:e,validationErrors:l||{},formValue:i,touchedFields:c||{},formSubmitted:d||!1,mode:o,hideLabel:t,onValueChange:q,onBlur:()=>{},onFocus:()=>{}};switch(e.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...r,properties:e,inputType:"text-input"===e.name?"text":"number-input"===e.name?"number":"email",readonly:!1,disabled:!1,hideLabel:t});case"textarea":return B.jsx(Q,{...r,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"select":const n={...e,options:e.basic?.options||[]};return B.jsx(ee,{...r,properties:n,disabled:!1,hideLabel:t});case"checkbox":const i={...e,options:e.basic?.options||[]};return B.jsx(te,{...r,properties:i,formValue:[],disabled:!1,hideLabel:t});case"radio":const s={...e,options:e.basic?.options||[]};return B.jsx(ne,{...r,properties:s,readonly:!1,disabled:!1,hideLabel:t});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...r,properties:e,readonly:!1,disabled:!1,hideLabel:t});case"signature":return B.jsx(se,{...r,properties:e,hideLabel:t});case"heading":return B.jsx(le,{...r,properties:e,hideLabel:t});case"instructions":return B.jsx(ce,{...r,properties:e,hideLabel:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",e.name]})}},[o,q,a,l,c,d]),U={backgroundColor:s.styles.backgroundColor||"var(--df-color-fb-container)",borderColor:s.styles.borderColor||"var(--df-color-fb-border)",borderWidth:s.styles.borderWidth||"2px",borderRadius:s.styles.borderRadius||"8px",padding:s.styles.padding||"16px",margin:s.styles.margin||"16px 0"};return B.jsxs("div",{className:`form-group df-form-datagrid ${p?"selected":""} ${h}`,onClick:O,style:U,children:[B.jsx("div",{className:"grid-header",children:B.jsx("div",{className:"grid-title",onClick:t=>{t.stopPropagation(),R(!I),u?.({id:e,value:{...s,basic:{...s.basic,collapsed:!I}}})},children:B.jsxs("div",{className:"title-content",style:{display:"flex",alignItems:"center",gap:"8px"},children:[I?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(E,{size:16}),B.jsx("span",{className:"grid-label",style:{fontWeight:"600"},children:s.basic.label}),s.validation.required&&B.jsx("span",{className:"required-indicator",style:{color:"#ef4444"},children:"*"})]})})}),s.basic.description&&!I&&B.jsx("div",{className:"grid-description",style:{marginTop:"8px",color:"var(--df-color-text-light)",fontSize:"14px"},children:s.basic.description}),!I&&B.jsx("div",{className:"grid-content",style:{marginTop:"16px"},children:"edit"===o?B.jsx(be,{gridComponents:V,mode:o,onComponentSelect:g||(()=>{}),onComponentDelete:z,onComponentEdit:x,onComponentUpdate:M,selectedComponent:v||null,renderFormComponent:j||_,gridId:e,formData:a,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L}):B.jsx(xe,{templateComponents:V,dataEntries:F,renderFormComponent:j||_,mode:o,allowAddRemoveEntries:s.datagrid?.allowAddRemoveEntries??!0,addAnotherText:s.datagrid?.addAnotherText??"Add Entry",removeText:s.datagrid?.removeText??"Remove",maxEntries:s.datagrid?.maxEntries??10,minEntries:s.datagrid?.minEntries??1,displayAsGrid:s.datagrid?.displayAsGrid??!0,onAddEntry:N||P,onRemoveEntry:C||W,formData:a,formTemplateId:k,onThresholdActionCompletion:$,onThresholdIssueRaised:A,onNotesChange:T,onAttachmentChange:L,datagridId:e})})]})},ve=e.lazy(()=>Promise.resolve().then(function(){return Ae})),je=({formComponents:s=[],currentDevice:o="desktop",isPreviewMode:a=!1,initialFormData:l=[],onSubmit:c,onFormDataChange:d,formTitle:u,formDescription:m,formTemplateId:p,onComponentSelect:h,onComponentDelete:f,onComponentEdit:g,onComponentUpdate:b,selectedComponent:x,workOrderNumber:y,assetNumber:v})=>{const[j,N]=t({}),[C,w]=t({}),[S,k]=t(!1),[$,A]=t({}),[E,T]=t({}),[L,I]=t(new Set),[R,D]=t(new Map),[V,F]=t({isValid:!0});n(()=>{z()},[s,l]);const O=(e,t)=>{e.forEach(e=>{if(e.id&&(void 0!==t[e.id]||(e.basic&&"value"in e.basic&&void 0!==e.basic.value&&""!==e.basic.value&&null!==e.basic.value?t[e.id]=e.basic.value:e.basic&&"defaultValue"in e.basic&&void 0!==e.basic.defaultValue&&""!==e.basic.defaultValue&&null!==e.basic.defaultValue?t[e.id]=e.basic.defaultValue:"checkbox"===e.name||"select"===e.name?t[e.id]=[]:t[e.id]="")),e.cells&&Array.isArray(e.cells)&&e.cells.forEach((e,n)=>{Array.isArray(e)&&e.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&O(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach((e,n)=>{e&&e.components&&Array.isArray(e.components)&&O(e.components,t)}),"file"===e.name&&e.basic){const n=e.basic.files||e.basic.attachments||e.basic.value;n&&(t[e.id]=n)}if("instructions"===e.name&&e.basic){e.basic.instructions||(e.basic.instructions=[]);const n=e.basic.value||e.basic.instructions;n&&(t[e.id]=n)}e.children&&Array.isArray(e.children)&&O(e.children,t)})},z=i(()=>{const e={},t=new Set,n=e=>{e.forEach((e,i)=>{if(e.id&&"string"==typeof e.id&&""!==e.id.trim())t.has(e.id)&&(console.error(`[DfFormPreview] Duplicate component ID detected: ${e.id}. Component:`,e),e.id=`${e.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,console.warn(`[DfFormPreview] Generated new unique ID: ${e.id}`));else{const t=e.name||"component",n=(e.basic?.label||"").replace(/[^a-zA-Z0-9]/g,"").toLowerCase().substring(0,10);e.id=`${t}-${n||"gen"}-${Date.now()}-${Math.random().toString(36).substr(2,6)}-${i}`}t.add(e.id),e.children&&Array.isArray(e.children)&&n(e.children),e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{Array.isArray(e)&&e.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e&&e.components&&Array.isArray(e.components)&&n(e.components)})})};s&&s.length>0&&n(s),l&&l.length>0&&n(l),l&&l.length>0&&O(l,e),l&&l.length>0&&O(l,e),s&&s.length>0&&O(s,e),N(t=>({...e,...t})),q()},[l,s]),M=(e,t)=>{e.forEach(e=>{if(e.id)if("table"===e.name||"datagrid"===e.name)t[e.id]=!0;else if(e.conditional){const n=G.evaluateConditionalLogic(e.conditional,s,j);t[e.id]=n.shouldShow}else t[e.id]=!0;e.cells&&Array.isArray(e.cells)&&e.cells.forEach(e=>{e.forEach(e=>{e.components&&Array.isArray(e.components)&&M(e.components,t)})}),e.entries&&Array.isArray(e.entries)&&e.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&M(e.components,t)}),e.children&&Array.isArray(e.children)&&M(e.children,t)})},q=i(()=>{const e={};s&&s.length>0&&M(s,e),T(e)},[s,j]),P=i(e=>{const t=s.find(t=>t.id===e);if(t&&("table"===t.name||"datagrid"===t.name))return!0;return!1!==E[e]},[E,s]),W=i(e=>{if(!e.id||"string"!=typeof e.id||""===e.id.trim())return void console.error("[DfFormPreview] Invalid component ID in onFormValueChange:",e);const t=s.filter(t=>t.id===e.id);if(t.length>1)return void console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${e.id}":`,t.map(e=>({id:e.id,name:e.name,label:e.basic?.label})));const n=j[e.id];void 0!==n&&n!==e.value&&console.log("[DfFormPreview] Updating form value:",{id:e.id,oldValue:n,newValue:e.value});const i={...j,[e.id]:e.value};N(i);const r=s.find(t=>t.id===e.id);if(r){const e=r?.threshold;e&&e.conditions&&e.conditions.length>0&&I(t=>{const n=new Set(t);return e.conditions.forEach(e=>{n.delete(e.id)}),n})}const o=t=>t.map(t=>t.id===e.id&&"defaultValue"in t.basic?{...t,basic:{...t.basic,value:e.value??t.basic.defaultValue,defaultValue:e.value}}:"section"===t.name&&t.children?{...t,children:o(t.children)}:"table"===t.name&&t.cells?{...t,cells:t.cells.map(e=>e.map(e=>{const t={...e};return t.components&&(t.components=o(t.components)),t}))}:"datagrid"===t.name&&t.entries?{...t,entries:t.entries.map(e=>{const t={...e};return t.components&&(t.components=o(t.components)),t})}:t),l=o(s);if(d?.(l),C[e.id]&&w(t=>({...t,[e.id]:""})),!a){if(e.isValid)return void w(t=>{const n=t[e.id];return n&&""!==n.trim()?{...t,[e.id]:""}:t});setTimeout(()=>{U(e.id)},150)}setTimeout(()=>{const e={};s.forEach(t=>{if("table"===t.name||"datagrid"===t.name)e[t.id]=!0;else if(t.conditional){const n=G.evaluateConditionalLogic(t.conditional,s,i);e[t.id]=n.shouldShow}else e[t.id]=!0}),T(e)},0)},[s,j,C,d]),_=i((e,t)=>{for(const n of e){if(n.id===t)return n;if("section"===n.name&&n.children){const e=_(n.children,t);if(e)return e}if("table"===n.name&&n.cells)for(const e of n.cells)for(const n of e)if(n.components){const e=_(n.components,t);if(e)return e}if("datagrid"===n.name&&n.entries)for(const e of n.entries)if(e.components){const n=_(e.components,t);if(n)return n}}return null},[]),U=i(e=>{if(a)return;const t=_(s,e);if(!t)return;const n=j[e]||"";if("number-input"===t.name&&(!n||""===n)){if(t.validation.required){const n=t.validation.customValidationMessage,i=t.basic.label||"This field",r=n||`${i} is required`;w(t=>({...t,[e]:r}))}else w(t=>({...t,[e]:""}));return}let i=!1;i=Array.isArray(n)?n.length>0:"string"==typeof n?""!==n.trim():null!=n;let r="";if(t.validation.required&&!i){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} is required`}else if("email-input"===t.name&&i&&!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(n)){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} must be a valid email`}else if(t.validation.minLength&&i&&n.length<t.validation.minLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} must be at least ${t.validation.minLength} characters`}else if(t.validation.maxLength&&i&&n.length>t.validation.maxLength){const e=t.validation.customValidationMessage,n=t.basic.label||"This field";r=e||`${n} must be no more than ${t.validation.maxLength} characters`}else if("number-input"===t.name&&i){const e=String(n).trim(),i=parseFloat(e);if(!isNaN(i)){const e=t.validation;e&&"lowerLimit"in e&&void 0!==e.lowerLimit&&null!==e.lowerLimit&&0!==e.lowerLimit&&i<e.lowerLimit?r="Number is below the lower limit":e&&"upperLimit"in e&&void 0!==e.upperLimit&&null!==e.upperLimit&&0!==e.upperLimit&&i>e.upperLimit&&(r="Number is above the upper limit")}}w(t=>({...t,[e]:r}))},[s,a,j,_]),J=i(e=>{A(t=>({...t,[e]:!0})),a||setTimeout(()=>{U(e)},0)},[a,U]),Y=i(e=>{C[e]&&w(t=>({...t,[e]:""}))},[C]),K=i(()=>!Object.values(C).some(e=>e&&"string"==typeof e&&""!==e.trim())&&s.every(e=>{const t=j[e.id]||"";let n=!1;if(n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!n)return!1;if("number-input"===e.name&&n){const n=String(t).trim(),i=parseFloat(n);if(!isNaN(i)){const t=e.validation;if(t&&"lowerLimit"in t&&void 0!==t.lowerLimit&&null!==t.lowerLimit&&0!==t.lowerLimit&&i<t.lowerLimit)return!1;if(t&&"upperLimit"in t&&void 0!==t.upperLimit&&null!==t.upperLimit&&0!==t.upperLimit&&i>t.upperLimit)return!1}}return!0}),[s,j,C]),X=i((e,t)=>{if(Array.isArray(t))return t.some(t=>X(e,t));if(null==t||""===t)return!1;const n="string"==typeof t?parseFloat(t):t,i="string"==typeof e.value?parseFloat(e.value):e.value;if(!isNaN(n)&&!isNaN(i))switch(e.operator){case"greaterThan":return n>i;case"lessThan":return n<i;case"greaterThanOrEqual":return n>=i;case"lessThanOrEqual":return n<=i;case"equals":return n===i;case"notEquals":return n!==i;default:return!1}const r=String(t).toLowerCase(),s=String(e.value).toLowerCase();switch(e.operator){case"equals":return r===s||String(t)===String(e.value);case"notEquals":return r!==s&&String(t)!==String(e.value);default:return!1}},[]),de=i(()=>{if(a)return[];const e=[];return s.forEach(t=>{const n=t?.condition;if(!n||!n.conditions||0===n.conditions.length)return;const i=j[t.id];null!=i&&""!==i&&!(Array.isArray(i)&&0===i.length)&&n.conditions.forEach(n=>{X(n,i)&&e.push({componentId:t.id,condition:n,componentLabel:t.basic?.label||"Field"})})}),e},[s,j,a,X]),me=i(()=>{if(a)return{isValid:!0};const e=de();if(0===e.length)return{isValid:!0};for(const{condition:t,componentLabel:n}of e){const e=R.get(t.id)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1},i=[];if(!0!==t.enableRaiseIssue||L.has(t.id)||i.push("raise an issue"),!0!==t.enableNotes||e.notesCompleted||i.push("add notes"),!0!==t.enableAttachment||e.attachmentsCompleted||i.push("add attachments"),!0!==t.enableSendEmail||e.emailSent||i.push("send email"),i.length>0){return{isValid:!1,errorMessage:`Please ${1===i.length?i[0]:i.slice(0,-1).join(", ")+" and "+i[i.length-1]} for the threshold condition met in "${n}". You cannot submit the form until all required actions are completed.`}}}return{isValid:!0}},[a,de,L,R]),he=i(e=>{e&&I(t=>{const n=new Set(t);return n.add(e),n})},[]),ge=i((e,t,n)=>{e&&D(i=>{const r=new Map(i),s=r.get(e)||{notesCompleted:!1,attachmentsCompleted:!1,emailSent:!1};return"notes"===t?r.set(e,{...s,notesCompleted:n}):"attachments"===t?r.set(e,{...s,attachmentsCompleted:n}):"email"===t&&r.set(e,{...s,emailSent:n}),r})},[]);n(()=>{if(!a){const e=me();F(e)}},[j,L,R,a,me]);const be=i(()=>{if(a)return!0;let e=!0;k(!0);const t={};return s.forEach(n=>{const i=j[n.id]||"";let r=!1;if(r=Array.isArray(i)?i.length>0:"string"==typeof i?""!==i.trim():null!=i,n.validation.required&&!r){const i=n.validation.customValidationMessage,r=n.basic.label||"This field",s=i||`${r} is required`;t[n.id]=s,e=!1}else if("number-input"===n.name&&r){const r=String(i).trim(),s=parseFloat(r);if(isNaN(s))t[n.id]="";else{const i=n.validation;i&&"lowerLimit"in i&&void 0!==i.lowerLimit&&null!==i.lowerLimit&&0!==i.lowerLimit&&s<i.lowerLimit?(t[n.id]="Number is below the lower limit",e=!1):i&&"upperLimit"in i&&void 0!==i.upperLimit&&null!==i.upperLimit&&0!==i.upperLimit&&s>i.upperLimit?(t[n.id]="Number is above the upper limit",e=!1):t[n.id]=""}}else t[n.id]="";A(e=>({...e,[n.id]:!0}))}),w(t),e},[s,a,j]),xe=i(()=>{if(k(!0),!be()){const e=s.find(e=>{const t=j[e.id]||"";let n=!1;return n=Array.isArray(t)?t.length>0:"string"==typeof t?""!==t.trim():null!=t,e.validation.required&&!n});if(e){const t=document.getElementById(e.id);t&&t.focus()}return}const e=me();if(!e.isValid){e.errorMessage&&H.showError(e.errorMessage);const t=de().find(({condition:e})=>!L.has(e.id));if(t){const e=document.getElementById(t.componentId);e&&e.scrollIntoView({behavior:"smooth",block:"center"})}return}const t=e=>e.map(e=>{let n=j[e.id];"text-input"===e.name&&e.basic,void 0===n&&(n="value"in e.basic&&void 0!==e.basic.value?e.basic.value:"defaultValue"in e.basic&&void 0!==e.basic.defaultValue?e.basic.defaultValue:""),"text-input"===e.name&&e.basic;const i={...e,basic:{...e.basic,value:n,defaultValue:n}};return"section"===i.name&&i.children&&(i.children=t(i.children)),"table"===i.name&&i.cells&&(i.cells=i.cells.map(e=>e.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n}))),"datagrid"===i.name&&i.entries&&(i.entries=i.entries.map(e=>{const n={...e};return n.components&&(n.components=t(n.components)),n})),i}),n=t(s),i={...j};c?.(n,i)},[s,j,be,c]),je=i(()=>({[`device-${o}`]:!0,readonly:a}),[o,a]),Ne=r(new Map),Ce=r(0),we=t=>{let n;if(t.id&&"string"==typeof t.id&&""!==t.id.trim())n=t.id;else{const e=t.basic?.label||"",i=t.name||"unknown",r=`${i}-${e}`;let s=Ne.current.get(r);s||(Ce.current+=1,s=`generated-${i}-${Ce.current}-${Math.random().toString(36).substr(2,9)}`,Ne.current.set(r,s),console.warn("[DfFormPreview] Generated and cached ID for component:",s,"key:",r)),n=s,t={...t,id:n}}const i=n,r=j[i];if(void 0!==r){const e=s.filter(e=>e.id!==i&&j[e.id]===r);e.length>0&&console.warn(`[DfFormPreview] Component ${i} shares form value with other components:`,e.map(e=>e.id))}const o={id:i,validationErrors:C,formValue:r,touchedFields:$,formSubmitted:S,mode:"test",readonly:!1,onValueChange:W,onBlur:()=>J(i),onFocus:()=>Y(i)};switch(t.name){case"text-input":case"number-input":case"email-input":return B.jsx(Z,{...o,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",formTemplateId:p,onThresholdIssueRaised:he,raisedThresholdIssues:L,workOrderNumber:y,assetNumber:v});case"textarea":return B.jsx(Q,{...o,properties:t});case"select":const n={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ee,{...o,properties:n});case"checkbox":const i={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(te,{...o,properties:i});case"radio":const a={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ne,{...o,properties:a});case"segment":const l={...t,options:t.basic?.options||[],basic:{...t.basic,comments:t.basic?.comments||""}};return B.jsx(ie,{...o,properties:l});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...o,properties:t});case"signature":return B.jsx(se,{...o,properties:t});case"heading":return B.jsx(le,{...o,properties:t});case"instructions":const c=r||t.basic?.value||null;return B.jsx(ce,{...o,properties:t,formValue:c});case"location":return B.jsx(ae,{...o,properties:t});case"section":return B.jsx(fe,{...o,properties:t,formData:j,formTemplateId:p,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,renderFormComponent:e=>we(e)});case"table":return B.jsx(e.Suspense,{fallback:B.jsx("div",{children:"Loading table..."}),children:B.jsx(ve,{...o,properties:t,formData:j,formTemplateId:p,mode:o.mode,validationErrors:C,touchedFields:$,formSubmitted:S,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,onNotesChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.cells){const t=i.cells.map(t=>t.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t}));return{...i,cells:t}}return i});d?.(i)},renderFormComponent:e=>we(e)})});case"datagrid":return B.jsx(ye,{...o,properties:t,formData:j,formTemplateId:p,mode:o.mode,validationErrors:C,touchedFields:$,formSubmitted:S,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,onComponentSelect:h,onComponentDelete:f,onComponentEdit:g,onComponentUpdate:b,selectedComponent:x,onValueChange:e=>{if(e.id===t.id&&e.value&&"object"==typeof e.value&&"entries"in e.value){const n=s.map(n=>n.id===t.id?{...n,...e.value}:n);d?.(n),e.value.entries&&Array.isArray(e.value.entries)&&e.value.entries.forEach(e=>{e.components&&Array.isArray(e.components)&&e.components.forEach(e=>{if(void 0!==j[e.id]);else{const t=e.basic?.defaultValue;void 0!==t&&N(n=>({...n,[e.id]:t}))}})})}else W(e)},onEntryAdd:()=>{const e=s.find(e=>e.id===t.id);if(e&&e.entries){const e=s.map(e=>e.id===t.id?{...e,entries:e.entries||[]}:e);d?.(e)}else setTimeout(()=>{const e=j[t.id];if(e&&"object"==typeof e&&"entries"in e){const n=s.map(n=>n.id===t.id?{...n,entries:e.entries}:n);d?.(n)}},100)},onEntryRemove:e=>{const n=s.map(n=>{if(n.id===t.id&&n.entries){const t=(n.entries||[]).filter((t,n)=>n!==e).map((e,t)=>({...e,index:t,id:`entry-${n.id}-${t}`,components:e.components?.map((e,n)=>{const i=(e.templateComponents||[])[n];return{...e,id:i?`${i.id}-entry-${t}-${n}`:e.id}})||[]}));return{...n,entries:t}}return n});d?.(n)},onNotesChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,notes:n}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},onAttachmentChange:(e,n)=>{const i=s.map(i=>{if(i.id===t.id&&i.entries){const t=i.entries.map(t=>{if(t.components){const i=t.components.map(t=>t.id===e?{...t,basic:{...t.basic,attachments:n||[]}}:t);return{...t,components:i}}return t});return{...i,entries:t}}return i});d?.(i)},renderFormComponent:e=>we(e)});case"file":const u=r||t.basic?.value||t.basic?.files||t.basic?.attachments||null;return B.jsx(oe,{...o,properties:t,formValue:u});default:return B.jsx("div",{className:"form-group",children:B.jsxs("div",{className:"form-group-label",children:["Unsupported Component: ",t.name]})})}};return B.jsx("div",{className:"form-preview-container",children:B.jsx("div",{className:"form-preview-wrapper",children:B.jsxs("div",{className:`form-preview ${Object.entries(je()).map(([e,t])=>t?e:"").join(" ")}`,children:[B.jsx("div",{className:"form-canvas-header"}),0===s.length?B.jsx("div",{className:"empty-state",children:B.jsx("div",{className:"empty-state-card",children:B.jsx("div",{className:"empty-state-preview-area",children:B.jsx("span",{className:"empty-state-placeholder",children:"Add components to see the form preview"})})})}):B.jsxs("form",{className:"form-preview-form",onSubmit:e=>{e.preventDefault(),xe()},children:[(u||m)&&B.jsxs("div",{className:"form-header",children:[u&&B.jsx("h1",{className:"form-title",children:u}),m&&B.jsx("p",{className:"form-description",children:m})]}),s.map(e=>{const t=e.basic,n=j[e.id],i=["select","radio","checkbox","segment"].includes(e.name||""),r=e.options||t?.options||[],o=(()=>{const t=e?.styles?.column;return"section"===e.name||"table"===e.name||"datagrid"===e.name?"col-12":3===t?"col-3":6===t?"col-6":9===t?"col-9":"col-12"})();let l=!1;if(!a)if(i&&null!=n&&""!==n)if("checkbox"===e.name){l=(Array.isArray(n)?n:[n]).some(e=>{const t=r.find(t=>t.value===e);return t&&(t.enableNotes||t.enableAttachment||t.enableRaiseIssue||t.enableSendEmail)})}else{const e=r.find(e=>e.value===n);l=e&&(e.enableNotes||e.enableAttachment||e.enableRaiseIssue||e.enableSendEmail)}else l=t?.enableNotes||t?.enableAttachment||t?.enableRaiseIssue||t?.enableSendEmail;const c=a&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:`form-group ${o} ${l||c?"has-action-features":""}`,style:{display:P(e.id)?"block":"none"},children:[we(e),!a&&!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:a?"preview":"test",formTemplateId:p,formValue:n,onThresholdActionCompletion:ge,onThresholdIssueRaised:he,onNotesChange:t=>{const n=s.map(n=>n.id===e.id?{...n,basic:{...n.basic,notes:t||""}}:n);d?.(n)},onAttachmentChange:t=>{const n=s.map(n=>n.id===e.id?{...n,basic:{...n.basic,attachments:t||[]}}:n);d?.(n)},notes:e.basic?.notes||"",attachments:e.basic?.attachments||null}),a&&c&&B.jsx(pe,{component:e})]},e.id)}),!a&&B.jsx("div",{className:"form-actions",children:B.jsx("button",{type:"submit",disabled:!K()||!V.isValid,className:"form-submit-button",title:V.isValid?"":V.errorMessage,children:"Submit"})})]})]})})})},Ne=({comment:e="",onSave:r,placeholder:s="Enter your reason...",className:o="",disabled:a=!1})=>{const[l,c]=t(!0),[d,u]=t(e),[m,p]=t(!1);n(()=>{u(e),p(!1)},[e]);const h=i(t=>{const n=t.target.value;u(n),p(n!==e)},[e]),f=i(()=>{m&&r&&!a&&(r(d),p(!1))},[m,r,d,a]),g=i(()=>{},[]),b=i(()=>{a||c(!l)},[l,a]);return B.jsxs("div",{className:`df-form-comments ${o}`,children:[B.jsxs("div",{className:"df-form-comments__header",children:[B.jsx("h3",{className:"df-form-comments__title",children:"Comments"}),B.jsx("button",{className:"df-form-comments__toggle",type:"button",onClick:b,"aria-expanded":l,"aria-label":"Toggle comments section",disabled:a,children:l?B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▼"}):B.jsx("span",{className:"df-form-comments__toggle-icon",children:"▶"})})]}),B.jsx("div",{className:"df-form-comments__content "+(l?"df-form-comments__content--expanded":""),children:B.jsx("div",{className:"df-form-comments__input-container",children:B.jsx("div",{className:"df-form-comments__input-line",children:B.jsx("input",{type:"text",id:"comment-input",className:"df-form-comments__input",value:d,onChange:h,onBlur:f,onFocus:g,placeholder:s,disabled:a})})})})]})},Ce=e=>e.id?e:{...e,id:z()},we=({component:e,mode:t,renderFormComponent:n,formData:i={},formTemplateId:r,onThresholdActionCompletion:s,onThresholdIssueRaised:o,onNotesChange:a,onAttachmentChange:l})=>{const c=i[e.id],d="preview"===t&&(e.basic?.notes&&e.basic.notes.trim().length>0||e.basic?.attachments&&Array.isArray(e.basic.attachments)&&e.basic.attachments.length>0);return B.jsxs("div",{className:"simple-table-component",children:[n(e),!["section","table","heading","file","instructions","signature","location","datagrid"].includes(e.name)&&B.jsx(ue,{component:e,mode:"test",formTemplateId:r,formValue:c,onThresholdActionCompletion:s,onThresholdIssueRaised:o,onNotesChange:a?t=>a(e.id,t):void 0,onAttachmentChange:l?t=>l(e.id,t):void 0}),d&&B.jsx(pe,{component:e})]})},Se=({component:e,selectedComponent:t,mode:n,onComponentSelect:i,onComponentDelete:r,onComponentEdit:s,renderFormComponent:o,isOverlay:a=!1})=>{const{attributes:l,listeners:c,setNodeRef:d,transform:u,transition:m,isDragging:p,isSorting:h}=V({id:e.id,disabled:a}),f={transform:O.Transform.toString(u),transition:m,opacity:p?.3:1,zIndex:p?1e3:"auto"};return B.jsxs("div",{ref:d,style:f,className:`form-component table-component ${t?.id===e.id?"selected":""} ${p?"dragging":""} ${h?"sorting":""}`,onClick:()=>!p&&i(e),role:"button",tabIndex:0,children:["edit"===n&&B.jsx("div",{className:"component-drag-handle",...c,...l,onClick:e=>e.stopPropagation(),style:{opacity:1},children:B.jsx(k,{size:14})}),B.jsx("div",{className:"component-content",children:o(e)}),"edit"===n&&B.jsxs("div",{className:"component-actions",style:{opacity:1},children:[s&&B.jsx("button",{className:"component-edit-btn",onClick:t=>{t.stopPropagation(),s(e)},type:"button",title:"Edit Component",children:B.jsx($,{size:12})}),B.jsx("button",{className:"component-delete-btn",onClick:t=>{t.stopPropagation(),r(e,t)},type:"button",title:"Delete Component",children:B.jsx(A,{size:12})})]})]})},ke=({cell:e,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,selectedComponent:s,renderFormComponent:o,formData:a={},formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,tableId:u,onNotesChange:m,onAttachmentChange:p})=>{const h=`table-cell-${u}-${e.row}-${e.column}`,{setNodeRef:f,isOver:g}=I({id:h,disabled:"edit"!==t,data:{type:"table-cell",tableId:u,cell:e,row:e.row,column:e.column}}),b={...e.styles,backgroundColor:g?"var(--df-color-primary-light)":e.styles?.backgroundColor||"transparent",minHeight:e.styles?.minHeight||"preview"===t||"test"===t?"40px":"60px",padding:(e.styles,"8px"),border:"preview"===t||"test"===t?"none":g?"2px dashed var(--df-color-primary)":e.styles?.borderColor?`1px solid ${e.styles.borderColor}`:"1px solid var(--df-color-fb-border)",borderRadius:"preview"===t||"test"===t?"0":"4px",position:"relative",verticalAlign:e.styles?.verticalAlign||"top"};return B.jsx("td",{ref:f,style:b,className:"table-cell "+(g?"drag-over":""),children:B.jsx("div",{className:"cell-content",children:e.components&&Array.isArray(e.components)&&e.components.length>0?"edit"===t?B.jsx(R,{items:e.components.map(e=>e.id||z()),strategy:D,children:e.components.map(e=>{const a=Ce(e);return B.jsx(Se,{component:a,selectedComponent:s,mode:t,onComponentSelect:n,onComponentDelete:i,onComponentEdit:r,renderFormComponent:o},a.id)})}):e.components.map(e=>{const n=e.id?e:Ce(e);return B.jsx(we,{component:n,mode:t,renderFormComponent:o,formData:a,formTemplateId:l,onThresholdActionCompletion:c,onThresholdIssueRaised:d,onNotesChange:m,onAttachmentChange:p},n.id)}):"edit"===t?B.jsx("div",{className:"empty-cell-placeholder",children:B.jsxs("div",{className:"cell-info",children:[B.jsx("span",{className:"drop-zone-text",children:"Drag and Drop a form component"}),B.jsxs("span",{className:"cell-coordinates",children:["Cell (",e.row+1,", ",e.column+1,")"]})]})}):B.jsx("div",{style:{minHeight:"20px",backgroundColor:"transparent",visibility:"hidden"},children:" "})})})},$e=({id:e,properties:r,mode:o="edit",formData:a={},validationErrors:l={},touchedFields:c={},formSubmitted:d=!1,onValueChange:u,onSelect:m,isSelected:p=!1,className:h="",onTableSelect:f,onComponentSelect:g,onComponentDelete:b,onComponentEdit:x,selectedComponent:y,renderFormComponent:v,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,onNotesChange:k,onAttachmentChange:$})=>{const[A,E]=t(!1),L=r.cells?.some(e=>e.some(e=>e.components&&e.components.length>0))||!1;n(()=>{},[r.table?.rows,r.table?.columns,r.basic?.rows,r.basic?.columns,r.cells,e,u]);const I=i(e=>{e.stopPropagation(),m?.(),f?.(r)},[m,f,r]),R=i((t,n)=>{n.stopPropagation();const i=r.cells.map(e=>e.map(e=>{if(e.components&&e.components.some(e=>e.id===t.id)){const n=e.components.filter(e=>e.id!==t.id);return{...e,components:n}}return e}));u&&u({id:e,value:{...r,cells:i}})},[b,r,u,e]),D=s(()=>r.cells?r.cells.map((t,n)=>t.map((t,i)=>({...t,components:t.components&&Array.isArray(t.components)?t.components.map((t,r)=>{if(t.id&&"string"==typeof t.id&&""!==t.id.trim())return t;const s=`${t.name||"component"}-table-${e}-row-${n}-cell-${i}-comp-${r}`;return{...t,id:s}}):[]}))):[],[r.cells,e]),V=v||i(e=>{const t=e.id?e:Ce(e),n=a[t.id]||"defaultValue"in t.basic&&t.basic.defaultValue||"";let i=n;"number-input"===t.name&&"number"==typeof n?i=String(n):"number-input"===t.name&&null==n&&(i="");const r={id:t.id,properties:t,validationErrors:{},formValue:i,touchedFields:{},formSubmitted:!1,mode:o,onValueChange:e=>{u?.(e)},onBlur:()=>{},onFocus:()=>{}};switch(t.name){case"text-input":case"email-input":case"number-input":return B.jsx(Z,{...r,properties:t,inputType:"text-input"===t.name?"text":"number-input"===t.name?"number":"email",readonly:!1,disabled:!1});case"textarea":return B.jsx(Q,{...r,properties:t,readonly:!1,disabled:!1});case"select":const e={...t,options:t.basic?.options||[]};return B.jsx(ee,{...r,properties:e,disabled:!1});case"checkbox":const n={...t,options:t.basic?.options||[]};return B.jsx(te,{...r,properties:n,formValue:[],disabled:!1});case"radio":const i={...t,options:t.basic?.options||[]};return B.jsx(ne,{...r,properties:i,readonly:!1,disabled:!1});case"date":case"date-picker":case"datetime-picker":return B.jsx(re,{...r,properties:t,readonly:!1,disabled:!1});case"signature":return B.jsx(se,{...r,properties:t});case"heading":return B.jsx(le,{...r,properties:t});default:return B.jsxs("div",{className:"unknown-component",children:["Unknown component: ",t.name]})}},[v,o,a,u]),F={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"},O={width:"100%",minWidth:"600px",borderCollapse:"preview"===o||"test"===o?"separate":"collapse",tableLayout:"fixed",border:"preview"===o||"test"===o?"1px solid var(--df-color-fb-border)":"none"};return L||"preview"!==o?B.jsxs("div",{className:`form-group df-form-table ${p?"selected":""} ${"preview"===o?"preview-mode":"test"===o?"test-mode":""} ${h}`,onClick:I,style:F,children:[B.jsx("div",{className:"table-header",children:B.jsx("div",{className:"table-title",onClick:t=>{t.stopPropagation(),E(!A),u?.({id:e,value:{...r,basic:{...r.basic||{},collapsed:!A}}})},children:B.jsxs("div",{className:"title-content",children:[A?B.jsx(S,{size:16}):B.jsx(w,{size:16}),B.jsx(T,{size:16}),B.jsx("span",{className:"table-label",children:r.basic?.label||"Table"}),r.validation?.required&&B.jsx("span",{className:"required-indicator",children:"*"})]})})}),r.basic?.description&&!A&&B.jsx("div",{className:"table-description",children:r.basic.description}),!A&&B.jsxs("div",{className:"table-content",children:[null,B.jsxs("table",{style:O,children:[r.table?.displayAsTable&&("edit"===o||r.table?.showColumns)&&B.jsx("thead",{children:B.jsx("tr",{className:"table-header-row",children:Array.from({length:r.table?.columns||r.basic?.columns||3},(e,t)=>{const n=(r.table?.columnNames?.split(",").map(e=>e.trim())||[])[t]||`Column ${t+1}`;return B.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:n},`header-${t}`)})})}),B.jsx("tbody",{children:D.map((t,n)=>B.jsx("tr",{className:"table-row",children:t.map(t=>B.jsx(ke,{cell:t,mode:o,onComponentSelect:g||(()=>{}),onComponentDelete:R,onComponentEdit:x,selectedComponent:y||null,renderFormComponent:V,formData:a,formTemplateId:j,onThresholdActionCompletion:N,onThresholdIssueRaised:C,tableId:e,onNotesChange:k,onAttachmentChange:$},t.id))},n))})]})]})]}):null};var Ae=Object.freeze({__proto__:null,DfFormTable:$e,default:$e});const Ee={page:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',padding:"30px",backgroundColor:"#ffffff",color:"#000000",lineHeight:"1.4"},header:{marginBottom:"30px",paddingBottom:"15px",borderBottom:"2px solid #303992",display:"flex",justifyContent:"space-between",alignItems:"flex-end"},title:{margin:"0 0 5px 0",fontSize:"24px",fontWeight:"bold",color:"#303992"},description:{margin:"0",fontSize:"14px",color:"#666666"},submittedBy:{fontSize:"14px",color:"#333",textAlign:"right",whiteSpace:"nowrap",marginBottom:"2px"},formGroup:{marginBottom:"20px",breakInside:"avoid"},label:{fontWeight:"400",display:"block",marginBottom:"8px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",fontColor:"var(--df-color-text-dark)"},labelLeft:{fontWeight:"400",display:"block",marginRight:"10px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',fontSize:"14px",lineHeight:"1.5",width:"60%",fontColor:"var(--df-color-text-dark)"},valueContainer:{border:"1px solid #e2e8f0",borderRadius:"6px",padding:"8px 12px",backgroundColor:"#ffffff",minHeight:"20px",fontSize:"14px",flex:1},value:{fontSize:"14px",color:"#000000"},gridRow:{display:"flex",flexWrap:"wrap",gap:"16px",marginBottom:"20px"},gridCol:e=>({flex:`0 0 calc(${e/12*100}% - 8px)`,minWidth:"0"}),img:{maxWidth:"100%",maxHeight:"300px",border:"1px solid #ddd",borderRadius:"4px",display:"block",marginTop:"5px"},table:{width:"100%",borderCollapse:"collapse",border:"1px solid #ddd",marginTop:"10px",tableLayout:"fixed"},th:{border:"1px solid #ddd",padding:"8px",backgroundColor:"#f5f5f5",fontWeight:"bold",textAlign:"left",fontSize:"13px"},td:{border:"1px solid #ddd",padding:"8px",fontSize:"13px",verticalAlign:"top"},section:{marginBottom:"25px",breakInside:"avoid"},sectionHeader:{fontSize:"18px",marginBottom:"15px",display:"block",fontWeight:"600"},sectionChildren:{marginLeft:"20px",paddingLeft:"20px",borderLeft:"2px solid #3b82f6",marginTop:"15px"},notesSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",fontSize:"13px",boxSizing:"border-box"},notesLabel:{fontWeight:"bold",color:"#303992",marginRight:"5px"},attachmentsSection:{marginTop:"10px",padding:"10px",backgroundColor:"rgba(48, 57, 146, 0.05)",borderLeft:"3px solid #303992",borderRadius:"4px",display:"flex",flexWrap:"wrap",gap:"10px",boxSizing:"border-box"},attachmentThumbnail:{width:"60px",height:"60px",border:"1px solid #e5e7eb",borderRadius:"4px",overflow:"hidden",backgroundColor:"#fff",display:"flex",alignItems:"center",justifyContent:"center"},attachmentImg:{width:"100%",height:"100%",objectFit:"cover"},segmentContainer:{display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center"},segmentButton:{display:"flex",alignItems:"center",justifyContent:"center",padding:"4px 6px",borderRadius:"6px",border:"1px solid #e0e0e0",backgroundColor:"#ffffff",fontSize:"10px",fontWeight:600,minWidth:"30px",color:"#666"},segmentIcon:{marginRight:"4px",fontSize:"9px",fontWeight:"bold",display:"inline-block",lineHeight:"1"},checkboxItem:{display:"flex",alignItems:"center",padding:"10px 14px",backgroundColor:"#f8f9fa",borderRadius:"6px",marginBottom:"8px",width:"100%",boxSizing:"border-box"}},Te=e=>{if(!e||"string"!=typeof e)return!1;const t=e.trim();return t.startsWith("data:image")||t.startsWith("iVBORw0KGgo")||t.startsWith("/9j/4AAQ")||t.startsWith("UklGR")||t.startsWith("R0lGOD")},Le=(e,t)=>{if(!e)return"";const n=e.trim();return n.startsWith("data:")||n.startsWith("http")||n.startsWith("blob:")||n.startsWith("/")?n:n.startsWith("iVBORw0KGgo")?`data:image/png;base64,${n}`:n.startsWith("/9j/4AAQ")?`data:image/jpeg;base64,${n}`:n.startsWith("UklGR")?`data:image/webp;base64,${n}`:n.startsWith("R0lGOD")?`data:image/gif;base64,${n}`:t&&t.startsWith("image/")?`data:${t};base64,${n}`:n},Ie=e=>{if(null!=e?.icon)return e.icon;return"pass"===(e=>{const t=String(e||"").toLowerCase();return"pass"===t||"yes"===t?"pass":"fail"===t||"no"===t?"fail":"pass"})(e?.value||e)?"✓":"×"},Re=({component:e})=>{const t=e.basic?.notes||"",n=e.basic?.attachments||[];return t.trim()||0!==n.length?B.jsxs("div",{style:{marginTop:"5px"},children:[t.trim().length>0&&B.jsxs("div",{style:Ee.notesSection,children:[B.jsx("span",{style:Ee.notesLabel,children:"Notes:"}),t]}),n.length>0&&B.jsx("div",{style:Ee.attachmentsSection,children:n.map((e,t)=>{const n=!(!e.data&&!e.url),i=(e.type?.startsWith("image/")||Te(e.data||e.url||""))&&n?Le(e.data||e.url||"",e.type):null;return B.jsx("div",{style:Ee.attachmentThumbnail,children:i?B.jsx("img",{src:i,alt:e.name||"Attachment",style:Ee.attachmentImg}):B.jsx("span",{style:{fontSize:"20px",color:"#999"},children:"📎"})},t)})})]}):null},De=({component:e})=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue,{name:n}=e;if("signature"===n)return t&&Te(t)?B.jsx("div",{style:{marginTop:"5px"},children:B.jsx("img",{src:Le(t),alt:"Signature",style:{...Ee.img,maxHeight:"100px",width:"auto"}})}):B.jsx("span",{style:{color:"#999",fontStyle:"italic"},children:"No signature"});if("checkbox"===n){const n=e.basic?.options||[],i=Array.isArray(t)?t:[t];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:n.map((e,t)=>{const n=i.includes(e.value);return B.jsxs("div",{style:Ee.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(n?"#303992":"#cbd5e1"),borderRadius:"4px",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:n?"#303992":"#ffffff"},children:n&&B.jsx("span",{style:{color:"#ffffff",fontSize:"12px",fontWeight:"bold",lineHeight:1},children:"✓"})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},t)})})}if("radio"===n){const n=e.basic?.options||[];return B.jsx("div",{style:{marginTop:"5px",width:"100%"},children:n.map((e,n)=>{const i=t===e.value;return B.jsxs("div",{style:Ee.checkboxItem,children:[B.jsx("div",{style:{width:"18px",height:"18px",minWidth:"18px",border:"2px solid "+(i?"#303992":"#cbd5e1"),borderRadius:"50%",marginRight:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#ffffff"},children:i&&B.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#303992"}})}),B.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"#334155"},children:e.label})]},n)})})}if("segment"===n){const n=e.basic?.options||[],i=t;return B.jsx("div",{style:Ee.segmentContainer,children:n.map((e,t)=>{const n=i===e.value,r=Ie(e),s=e.color||"#666";let o={...Ee.segmentButton};return o=n?{...o,backgroundColor:s,color:"#ffffff",borderColor:s}:{...o,backgroundColor:"#ffffff",color:s,borderColor:s},B.jsxs("div",{style:o,children:[B.jsx("span",{style:Ee.segmentIcon,children:r}),B.jsx("span",{children:e.value})]},t)})})}if("file"===n){const e=(Array.isArray(t)?t:t?[t]:[]).filter(e=>{const t=!(!e.data&&!e.url),n=e.type&&e.type.startsWith("image/"),i=t&&Te(e.data||e.url);return n||i});return e.length>0?B.jsx("div",{style:{marginTop:"10px"},children:e.map((e,t)=>{const n=Le(e.data||e.url,e.type);return n?B.jsx("img",{src:n,alt:e.name||"File",style:{...Ee.img,marginBottom:"10px"}},t):null})}):B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No images uploaded"})}if("location"===n){if(t&&"object"==typeof t){const e=t;return B.jsxs("div",{style:{fontSize:"14px"},children:[e.placeName&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Place:"})," ",e.placeName]}),(e.city||e.country)&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Address:"})," ",[e.city,e.country].filter(Boolean).join(", ")]}),e.latitude&&e.longitude&&B.jsxs("div",{style:{marginBottom:"4px"},children:[B.jsx("strong",{children:"Coordinates:"})," ",e.latitude.toFixed(6),", ",e.longitude.toFixed(6)]}),e.timestamp&&B.jsxs("div",{children:[B.jsx("strong",{children:"Captured:"})," ",new Date(e.timestamp).toLocaleString()]})]})}return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No location data"})}if("instructions"===n){const t=e.basic?.instructions||[],n=e.validation?.listStyle||"numbers";if(!Array.isArray(t)||0===t.length)return B.jsx("div",{style:{color:"#999",fontStyle:"italic"},children:"No instructions"});const i=()=>B.jsx("div",{dangerouslySetInnerHTML:{__html:t.join("")}});return"numbers"===n?B.jsx("ol",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(i,{})}):"bullets"===n?B.jsx("ul",{style:{margin:"10px 0",paddingLeft:"25px"},children:B.jsx(i,{})}):B.jsx("div",{style:{margin:"10px 0"},children:B.jsx(i,{})})}const i="object"==typeof t?JSON.stringify(t):String(t);if(!["signature","checkbox","radio","segment","file","instructions","heading","section","table","datagrid"].includes(n)){const e="textarea"===n;return B.jsx("div",{style:{...Ee.valueContainer,...e?{minHeight:"60px",whiteSpace:"pre-wrap"}:{}},children:B.jsx("div",{style:Ee.value,children:i})})}return B.jsx("div",{style:Ee.value,children:i})},Ve=({component:e})=>{const{name:t,basic:n,styles:i,validation:r}=e,s=n?.label,o=r?.required,a="left"===(i?.labelAlignment||"top");if("section"===t){const t=i?.headerBackgroundColor,r=i?.headerTextColor,a={...Ee.sectionHeader,...t?{backgroundColor:t,padding:"8px",borderRadius:"4px"}:{},...r?{color:r}:{},display:"flex",alignItems:"center"};return B.jsxs("div",{style:Ee.section,children:[s&&B.jsx("label",{style:a,children:B.jsxs("span",{style:{flex:1},children:[s,o&&" *"]})}),n?.description&&B.jsx("p",{style:{...Ee.description,marginBottom:"15px"},children:n.description}),B.jsx(Re,{component:e}),B.jsx("div",{style:Ee.sectionChildren,children:B.jsx(Fe,{components:e.children||[]})})]})}if("heading"===t){const e=`h${Math.max(1,Math.min(6,i?.level??n?.level??1))}`,t={...i?.headerBackgroundColor?{backgroundColor:i.headerBackgroundColor,padding:"8px",borderRadius:"4px"}:{},...i?.headerTextColor?{color:i.headerTextColor}:{},...i?.fontSize?{fontSize:i.fontSize}:{},...i?.textAlign?{textAlign:i.textAlign}:{},marginTop:0,marginBottom:"15px"};return B.jsx("div",{style:Ee.formGroup,children:B.jsx(e,{style:t,children:n?.label||n?.value})})}if("table"===t){const t=e.cells||[],n=Math.max(0,...t.map(e=>e?e.length:0)),r=n>0?100/n:100,a=i?.headerBackgroundColor,l=i?.headerTextColor,c={...Ee.label,...a?{backgroundColor:a,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...l?{color:l}:{}};return B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:c,children:[s,o&&" *"]}),B.jsx("table",{style:Ee.table,children:B.jsx("tbody",{children:t.map((e,t)=>B.jsx("tr",{children:e&&e.map((e,t)=>B.jsx("td",{style:{...Ee.td,width:`${r}%`},children:e.components&&e.components.map((e,t)=>B.jsxs("div",{style:{marginBottom:"8px"},children:[e.basic?.label&&B.jsxs("span",{style:{fontWeight:"bold",marginRight:"5px",fontSize:"12px"},children:[e.basic.label,":"]}),B.jsx(De,{component:e}),B.jsx(Re,{component:e})]},t))},t))},t))})})]})}if("datagrid"===t){const t=e.entries||[];let n=e.templateComponents||[];0===n.length&&t.length>0&&t[0]?.components&&(n=t[0].components.map(e=>({...e,basic:{...e.basic,label:e.basic?.label||e.name}})));const r=i?.headerBackgroundColor,a=i?.headerTextColor,l={...Ee.label,...r?{backgroundColor:r,padding:"8px",borderRadius:"4px",marginBottom:"10px"}:{},...a?{color:a}:{}},c=t.filter(e=>!(!e.components||0===e.components.length)&&e.components.some(e=>{const t=void 0!==e.basic?.value?e.basic.value:e.basic?.defaultValue;return Array.isArray(t)?t.length>0:null!=t&&""!==String(t).trim()}));return 0===c.length?B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:l,children:[s,o&&" *"]}),B.jsx("div",{style:{fontStyle:"italic",color:"#999"},children:"No data"})]}):B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:l,children:[s,o&&" *"]}),B.jsxs("table",{style:Ee.table,children:[B.jsx("thead",{children:B.jsx("tr",{children:n.map((e,t)=>B.jsx("th",{style:Ee.th,children:e.basic?.label||e.name},t))})}),B.jsx("tbody",{children:c.map((e,t)=>B.jsx("tr",{children:n.map((t,n)=>{const i=e.components[n];return B.jsx("td",{style:Ee.td,children:i?B.jsxs(B.Fragment,{children:[B.jsx(De,{component:i}),B.jsx(Re,{component:i})]}):"N/A"},n)})},t))})]})]})}if(a&&"instructions"!==t){const n=["segment"].includes(t);return B.jsxs("div",{style:Ee.formGroup,children:[B.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[s&&B.jsxs("label",{style:Ee.labelLeft,children:[s,o&&" *"]}),B.jsx("div",{style:{flex:1,...n?{display:"flex",justifyContent:"flex-end"}:{}},children:B.jsx(De,{component:e})})]}),B.jsx(Re,{component:e})]})}return B.jsxs("div",{style:Ee.formGroup,children:[s&&B.jsxs("label",{style:Ee.label,children:[s,o&&" *"]}),B.jsx(De,{component:e}),B.jsx(Re,{component:e})]})},Fe=({components:e})=>{if(!e||0===e.length)return null;const t=[];let n=[],i=0;return e.forEach(e=>{const r=["section","table","datagrid","heading","instructions"].includes(e.name),s=r?12:e.styles?.column||12;i+s>12&&n.length>0&&(t.push(n),n=[],i=0),n.push(e),i+=s,(r||i>=12)&&i>0&&(t.push(n),n=[],i=0)}),n.length>0&&t.push(n),B.jsx(B.Fragment,{children:t.map((e,t)=>1===e.length?B.jsx(Ve,{component:e[0]},e[0].id||t):B.jsx("div",{style:Ee.gridRow,children:e.map((e,t)=>{const n=e.styles?.column||12;return B.jsx("div",{style:Ee.gridCol(n),children:B.jsx(Ve,{component:e})},e.id||t)})},t))})},Oe=({formTitle:e,formDescription:t,userName:n,components:i})=>B.jsxs("div",{className:"pdf-container",style:Ee.page,children:[B.jsxs("div",{style:Ee.header,children:[B.jsxs("div",{children:[B.jsx("h1",{style:Ee.title,children:e}),t&&B.jsx("p",{style:Ee.description,children:t})]}),n&&B.jsxs("div",{style:Ee.submittedBy,children:[B.jsx("strong",{children:"Submitted By:"})," ",n]})]}),B.jsx("div",{className:"form-content",children:B.jsx(Fe,{components:i})})]});var ze;!function(e){e.Top="top",e.Left="left"}(ze||(ze={}));export{ue as ComponentActionFeatures,pe as ComponentSubmissionActions,te as DfFormCheckbox,Ne as DfFormComments,ye as DfFormDataGrid,re as DfFormDateTime,J as DfFormErrorMsg,oe as DfFormFileUpload,le as DfFormHeading,Z as DfFormInput,ce as DfFormInstruction,ae as DfFormLocation,je as DfFormPreview,ne as DfFormRadio,fe as DfFormSection,ie as DfFormSegment,ee as DfFormSelect,se as DfFormSignature,$e as DfFormTable,Q as DfFormTextarea,ze as ELabelAlignment,Oe as FormSubmissionPdf,K as RaiseIssueModal,X as ThresholdAlert,G as conditionalLogicService,H as toastService};
11
11
  //# sourceMappingURL=index.esm.js.map