(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))l(a);new MutationObserver(a=>{for(const r of a)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&l(o)}).observe(document,{childList:!0,subtree:!0});function s(a){const r={};return a.integrity&&(r.integrity=a.integrity),a.referrerPolicy&&(r.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?r.credentials="include":a.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function l(a){if(a.ep)return;a.ep=!0;const r=s(a);fetch(a.href,r)}})();var $u={exports:{}},Zr={},Uu={exports:{}},me={};/** * @license React * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Da=Symbol.for("react.element"),Og=Symbol.for("react.portal"),Lg=Symbol.for("react.fragment"),Ng=Symbol.for("react.strict_mode"),Wg=Symbol.for("react.profiler"),Bg=Symbol.for("react.provider"),$g=Symbol.for("react.context"),Ug=Symbol.for("react.forward_ref"),Mg=Symbol.for("react.suspense"),Fg=Symbol.for("react.memo"),Hg=Symbol.for("react.lazy"),mc=Symbol.iterator;function Gg(e){return e===null||typeof e!="object"?null:(e=mc&&e[mc]||e["@@iterator"],typeof e=="function"?e:null)}var Mu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Fu=Object.assign,Hu={};function Ll(e,n,s){this.props=e,this.context=n,this.refs=Hu,this.updater=s||Mu}Ll.prototype.isReactComponent={};Ll.prototype.setState=function(e,n){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,n,"setState")};Ll.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Gu(){}Gu.prototype=Ll.prototype;function ud(e,n,s){this.props=e,this.context=n,this.refs=Hu,this.updater=s||Mu}var pd=ud.prototype=new Gu;pd.constructor=ud;Fu(pd,Ll.prototype);pd.isPureReactComponent=!0;var xc=Array.isArray,Qu=Object.prototype.hasOwnProperty,fd={current:null},Ku={key:!0,ref:!0,__self:!0,__source:!0};function Yu(e,n,s){var l,a={},r=null,o=null;if(n!=null)for(l in n.ref!==void 0&&(o=n.ref),n.key!==void 0&&(r=""+n.key),n)Qu.call(n,l)&&!Ku.hasOwnProperty(l)&&(a[l]=n[l]);var d=arguments.length-2;if(d===1)a.children=s;else if(1>>1,ee=A[N];if(0>>1;Na(ae,Q))Bea($e,ae)?(A[N]=$e,A[Be]=Q,N=Be):(A[N]=ae,A[ce]=Q,N=ce);else if(Bea($e,Q))A[N]=$e,A[Be]=Q,N=Be;else break e}}return M}function a(A,M){var Q=A.sortIndex-M.sortIndex;return Q!==0?Q:A.id-M.id}if(typeof performance=="object"&&typeof performance.now=="function"){var r=performance;e.unstable_now=function(){return r.now()}}else{var o=Date,d=o.now();e.unstable_now=function(){return o.now()-d}}var p=[],f=[],k=1,j=null,b=3,c=!1,y=!1,z=!1,C=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,i=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function h(A){for(var M=s(f);M!==null;){if(M.callback===null)l(f);else if(M.startTime<=A)l(f),M.sortIndex=M.expirationTime,n(p,M);else break;M=s(f)}}function x(A){if(z=!1,h(A),!y)if(s(p)!==null)y=!0,D(S);else{var M=s(f);M!==null&&E(x,M.startTime-A)}}function S(A,M){y=!1,z&&(z=!1,g(v),v=-1),c=!0;var Q=b;try{for(h(M),j=s(p);j!==null&&(!(j.expirationTime>M)||A&&!G());){var N=j.callback;if(typeof N=="function"){j.callback=null,b=j.priorityLevel;var ee=N(j.expirationTime<=M);M=e.unstable_now(),typeof ee=="function"?j.callback=ee:j===s(p)&&l(p),h(M)}else l(p);j=s(p)}if(j!==null)var Z=!0;else{var ce=s(f);ce!==null&&E(x,ce.startTime-M),Z=!1}return Z}finally{j=null,b=Q,c=!1}}var w=!1,u=null,v=-1,I=5,T=-1;function G(){return!(e.unstable_now()-TA||125N?(A.sortIndex=Q,n(f,A),s(p)===null&&A===s(f)&&(z?(g(v),v=-1):z=!0,E(x,Q-N))):(A.sortIndex=ee,n(p,A),y||c||(y=!0,D(S))),A},e.unstable_shouldYield=G,e.unstable_wrapCallback=function(A){var M=b;return function(){var Q=b;b=M;try{return A.apply(this,arguments)}finally{b=Q}}}})(Zu);Vu.exports=Zu;var nm=Vu.exports;/** * @license React * react-dom.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var sm=_,Wt=nm;function Y(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),mo=Object.prototype.hasOwnProperty,lm=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,vc={},jc={};function am(e){return mo.call(jc,e)?!0:mo.call(vc,e)?!1:lm.test(e)?jc[e]=!0:(vc[e]=!0,!1)}function rm(e,n,s,l){if(s!==null&&s.type===0)return!1;switch(typeof n){case"function":case"symbol":return!0;case"boolean":return l?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function im(e,n,s,l){if(n===null||typeof n>"u"||rm(e,n,s,l))return!0;if(l)return!1;if(s!==null)switch(s.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function Ct(e,n,s,l,a,r,o){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=l,this.attributeNamespace=a,this.mustUseProperty=s,this.propertyName=e,this.type=n,this.sanitizeURL=r,this.removeEmptyString=o}var ht={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){ht[e]=new Ct(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];ht[n]=new Ct(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){ht[e]=new Ct(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){ht[e]=new Ct(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){ht[e]=new Ct(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){ht[e]=new Ct(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){ht[e]=new Ct(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){ht[e]=new Ct(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){ht[e]=new Ct(e,5,!1,e.toLowerCase(),null,!1,!1)});var gd=/[\-:]([a-z])/g;function md(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var n=e.replace(gd,md);ht[n]=new Ct(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(gd,md);ht[n]=new Ct(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(gd,md);ht[n]=new Ct(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){ht[e]=new Ct(e,1,!1,e.toLowerCase(),null,!1,!1)});ht.xlinkHref=new Ct("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){ht[e]=new Ct(e,1,!1,e.toLowerCase(),null,!0,!0)});function xd(e,n,s,l){var a=ht.hasOwnProperty(n)?ht[n]:null;(a!==null?a.type!==0:l||!(2d||a[o]!==r[d]){var p=` `+a[o].replace(" at new "," at ");return e.displayName&&p.includes("")&&(p=p.replace("",e.displayName)),p}while(1<=o&&0<=d);break}}}finally{Ui=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?ta(e):""}function om(e){switch(e.tag){case 5:return ta(e.type);case 16:return ta("Lazy");case 13:return ta("Suspense");case 19:return ta("SuspenseList");case 0:case 2:case 15:return e=Mi(e.type,!1),e;case 11:return e=Mi(e.type.render,!1),e;case 1:return e=Mi(e.type,!0),e;default:return""}}function jo(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case dl:return"Fragment";case ol:return"Portal";case xo:return"Profiler";case yd:return"StrictMode";case yo:return"Suspense";case vo:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case np:return(e.displayName||"Context")+".Consumer";case tp:return(e._context.displayName||"Context")+".Provider";case vd:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case jd:return n=e.displayName||null,n!==null?n:jo(e.type)||"Memo";case Gn:n=e._payload,e=e._init;try{return jo(e(n))}catch{}}return null}function dm(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return jo(n);case 8:return n===yd?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function is(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function lp(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function cm(e){var n=lp(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),l=""+e[n];if(!e.hasOwnProperty(n)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var a=s.get,r=s.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return a.call(this)},set:function(o){l=""+o,r.call(this,o)}}),Object.defineProperty(e,n,{enumerable:s.enumerable}),{getValue:function(){return l},setValue:function(o){l=""+o},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function Xa(e){e._valueTracker||(e._valueTracker=cm(e))}function ap(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),l="";return e&&(l=lp(e)?e.checked?"true":"false":e.value),e=l,e!==s?(n.setValue(e),!0):!1}function zr(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function bo(e,n){var s=n.checked;return We({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function Sc(e,n){var s=n.defaultValue==null?"":n.defaultValue,l=n.checked!=null?n.checked:n.defaultChecked;s=is(n.value!=null?n.value:s),e._wrapperState={initialChecked:l,initialValue:s,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function rp(e,n){n=n.checked,n!=null&&xd(e,"checked",n,!1)}function So(e,n){rp(e,n);var s=is(n.value),l=n.type;if(s!=null)l==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(l==="submit"||l==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?_o(e,n.type,s):n.hasOwnProperty("defaultValue")&&_o(e,n.type,is(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function _c(e,n,s){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var l=n.type;if(!(l!=="submit"&&l!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,s||n===e.value||(e.value=n),e.defaultValue=n}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function _o(e,n,s){(n!=="number"||zr(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var na=Array.isArray;function bl(e,n,s,l){if(e=e.options,n){n={};for(var a=0;a"+n.valueOf().toString()+"",n=qa.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function ma(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var ra={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},um=["Webkit","ms","Moz","O"];Object.keys(ra).forEach(function(e){um.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),ra[n]=ra[e]})});function cp(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||ra.hasOwnProperty(e)&&ra[e]?(""+n).trim():n+"px"}function up(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var l=s.indexOf("--")===0,a=cp(s,n[s],l);s==="float"&&(s="cssFloat"),l?e.setProperty(s,a):e[s]=a}}var pm=We({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Co(e,n){if(n){if(pm[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(Y(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(Y(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(Y(61))}if(n.style!=null&&typeof n.style!="object")throw Error(Y(62))}}function zo(e,n){if(e.indexOf("-")===-1)return typeof n.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Io=null;function bd(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var To=null,Sl=null,_l=null;function Cc(e){if(e=Na(e)){if(typeof To!="function")throw Error(Y(280));var n=e.stateNode;n&&(n=li(n),To(e.stateNode,e.type,n))}}function pp(e){Sl?_l?_l.push(e):_l=[e]:Sl=e}function fp(){if(Sl){var e=Sl,n=_l;if(_l=Sl=null,Cc(e),n)for(e=0;e>>=0,e===0?32:31-(_m(e)/wm|0)|0}var Ja=64,Va=4194304;function sa(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Ar(e,n){var s=e.pendingLanes;if(s===0)return 0;var l=0,a=e.suspendedLanes,r=e.pingedLanes,o=s&268435455;if(o!==0){var d=o&~a;d!==0?l=sa(d):(r&=o,r!==0&&(l=sa(r)))}else o=s&~a,o!==0?l=sa(o):r!==0&&(l=sa(r));if(l===0)return 0;if(n!==0&&n!==l&&!(n&a)&&(a=l&-l,r=n&-n,a>=r||a===16&&(r&4194240)!==0))return n;if(l&4&&(l|=s&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=l;0s;s++)n.push(e);return n}function Oa(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-on(n),e[n]=s}function Im(e,n){var s=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var l=e.eventTimes;for(e=e.expirationTimes;0=oa),Oc=" ",Lc=!1;function Rp(e,n){switch(e){case"keyup":return nx.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Dp(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var cl=!1;function lx(e,n){switch(e){case"compositionend":return Dp(n);case"keypress":return n.which!==32?null:(Lc=!0,Oc);case"textInput":return e=n.data,e===Oc&&Lc?null:e;default:return null}}function ax(e,n){if(cl)return e==="compositionend"||!Td&&Rp(e,n)?(e=Ap(),xr=Cd=Xn=null,cl=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1=n)return{node:s,offset:n-e};e=l}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=$c(s)}}function Wp(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?Wp(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function Bp(){for(var e=window,n=zr();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=zr(e.document)}return n}function Ed(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function hx(e){var n=Bp(),s=e.focusedElem,l=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&Wp(s.ownerDocument.documentElement,s)){if(l!==null&&Ed(s)){if(n=l.start,e=l.end,e===void 0&&(e=n),"selectionStart"in s)s.selectionStart=n,s.selectionEnd=Math.min(e,s.value.length);else if(e=(n=s.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var a=s.textContent.length,r=Math.min(l.start,a);l=l.end===void 0?r:Math.min(l.end,a),!e.extend&&r>l&&(a=l,l=r,r=a),a=Uc(s,r);var o=Uc(s,l);a&&o&&(e.rangeCount!==1||e.anchorNode!==a.node||e.anchorOffset!==a.offset||e.focusNode!==o.node||e.focusOffset!==o.offset)&&(n=n.createRange(),n.setStart(a.node,a.offset),e.removeAllRanges(),r>l?(e.addRange(n),e.extend(o.node,o.offset)):(n.setEnd(o.node,o.offset),e.addRange(n)))}}for(n=[],e=s;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s=document.documentMode,ul=null,Oo=null,ca=null,Lo=!1;function Mc(e,n,s){var l=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Lo||ul==null||ul!==zr(l)||(l=ul,"selectionStart"in l&&Ed(l)?l={start:l.selectionStart,end:l.selectionEnd}:(l=(l.ownerDocument&&l.ownerDocument.defaultView||window).getSelection(),l={anchorNode:l.anchorNode,anchorOffset:l.anchorOffset,focusNode:l.focusNode,focusOffset:l.focusOffset}),ca&&Sa(ca,l)||(ca=l,l=Dr(Oo,"onSelect"),0hl||(e.current=Mo[hl],Mo[hl]=null,hl--)}function Ce(e,n){hl++,Mo[hl]=e.current,e.current=n}var os={},jt=us(os),Tt=us(!1),Ps=os;function Il(e,n){var s=e.type.contextTypes;if(!s)return os;var l=e.stateNode;if(l&&l.__reactInternalMemoizedUnmaskedChildContext===n)return l.__reactInternalMemoizedMaskedChildContext;var a={},r;for(r in s)a[r]=n[r];return l&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=a),a}function Et(e){return e=e.childContextTypes,e!=null}function Lr(){Ee(Tt),Ee(jt)}function Xc(e,n,s){if(jt.current!==os)throw Error(Y(168));Ce(jt,n),Ce(Tt,s)}function Yp(e,n,s){var l=e.stateNode;if(n=n.childContextTypes,typeof l.getChildContext!="function")return s;l=l.getChildContext();for(var a in l)if(!(a in n))throw Error(Y(108,dm(e)||"Unknown",a));return We({},s,l)}function Nr(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||os,Ps=jt.current,Ce(jt,e),Ce(Tt,Tt.current),!0}function qc(e,n,s){var l=e.stateNode;if(!l)throw Error(Y(169));s?(e=Yp(e,n,Ps),l.__reactInternalMemoizedMergedChildContext=e,Ee(Tt),Ee(jt),Ce(jt,e)):Ee(Tt),Ce(Tt,s)}var Rn=null,ai=!1,no=!1;function Xp(e){Rn===null?Rn=[e]:Rn.push(e)}function Cx(e){ai=!0,Xp(e)}function ps(){if(!no&&Rn!==null){no=!0;var e=0,n=_e;try{var s=Rn;for(_e=1;e>=o,a-=o,Dn=1<<32-on(n)+a|s<v?(I=u,u=null):I=u.sibling;var T=b(g,u,h[v],x);if(T===null){u===null&&(u=I);break}e&&u&&T.alternate===null&&n(g,u),i=r(T,i,v),w===null?S=T:w.sibling=T,w=T,u=I}if(v===h.length)return s(g,u),Re&&ks(g,v),S;if(u===null){for(;vv?(I=u,u=null):I=u.sibling;var G=b(g,u,T.value,x);if(G===null){u===null&&(u=I);break}e&&u&&G.alternate===null&&n(g,u),i=r(G,i,v),w===null?S=G:w.sibling=G,w=G,u=I}if(T.done)return s(g,u),Re&&ks(g,v),S;if(u===null){for(;!T.done;v++,T=h.next())T=j(g,T.value,x),T!==null&&(i=r(T,i,v),w===null?S=T:w.sibling=T,w=T);return Re&&ks(g,v),S}for(u=l(g,u);!T.done;v++,T=h.next())T=c(u,g,v,T.value,x),T!==null&&(e&&T.alternate!==null&&u.delete(T.key===null?v:T.key),i=r(T,i,v),w===null?S=T:w.sibling=T,w=T);return e&&u.forEach(function(K){return n(g,K)}),Re&&ks(g,v),S}function C(g,i,h,x){if(typeof h=="object"&&h!==null&&h.type===dl&&h.key===null&&(h=h.props.children),typeof h=="object"&&h!==null){switch(h.$$typeof){case Ya:e:{for(var S=h.key,w=i;w!==null;){if(w.key===S){if(S=h.type,S===dl){if(w.tag===7){s(g,w.sibling),i=a(w,h.props.children),i.return=g,g=i;break e}}else if(w.elementType===S||typeof S=="object"&&S!==null&&S.$$typeof===Gn&&Zc(S)===w.type){s(g,w.sibling),i=a(w,h.props),i.ref=ql(g,w,h),i.return=g,g=i;break e}s(g,w);break}else n(g,w);w=w.sibling}h.type===dl?(i=As(h.props.children,g.mode,x,h.key),i.return=g,g=i):(x=kr(h.type,h.key,h.props,null,g.mode,x),x.ref=ql(g,i,h),x.return=g,g=x)}return o(g);case ol:e:{for(w=h.key;i!==null;){if(i.key===w)if(i.tag===4&&i.stateNode.containerInfo===h.containerInfo&&i.stateNode.implementation===h.implementation){s(g,i.sibling),i=a(i,h.children||[]),i.return=g,g=i;break e}else{s(g,i);break}else n(g,i);i=i.sibling}i=uo(h,g.mode,x),i.return=g,g=i}return o(g);case Gn:return w=h._init,C(g,i,w(h._payload),x)}if(na(h))return y(g,i,h,x);if(Gl(h))return z(g,i,h,x);ar(g,h)}return typeof h=="string"&&h!==""||typeof h=="number"?(h=""+h,i!==null&&i.tag===6?(s(g,i.sibling),i=a(i,h),i.return=g,g=i):(s(g,i),i=co(h,g.mode,x),i.return=g,g=i),o(g)):s(g,i)}return C}var El=Zp(!0),ef=Zp(!1),$r=us(null),Ur=null,xl=null,Dd=null;function Od(){Dd=xl=Ur=null}function Ld(e){var n=$r.current;Ee($r),e._currentValue=n}function Go(e,n,s){for(;e!==null;){var l=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,l!==null&&(l.childLanes|=n)):l!==null&&(l.childLanes&n)!==n&&(l.childLanes|=n),e===s)break;e=e.return}}function kl(e,n){Ur=e,Dd=xl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(It=!0),e.firstContext=null)}function qt(e){var n=e._currentValue;if(Dd!==e)if(e={context:e,memoizedValue:n,next:null},xl===null){if(Ur===null)throw Error(Y(308));xl=e,Ur.dependencies={lanes:0,firstContext:e}}else xl=xl.next=e;return n}var Is=null;function Nd(e){Is===null?Is=[e]:Is.push(e)}function tf(e,n,s,l){var a=n.interleaved;return a===null?(s.next=s,Nd(n)):(s.next=a.next,a.next=s),n.interleaved=s,Bn(e,l)}function Bn(e,n){e.lanes|=n;var s=e.alternate;for(s!==null&&(s.lanes|=n),s=e,e=e.return;e!==null;)e.childLanes|=n,s=e.alternate,s!==null&&(s.childLanes|=n),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Qn=!1;function Wd(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function nf(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Ln(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function ss(e,n,s){var l=e.updateQueue;if(l===null)return null;if(l=l.shared,ye&2){var a=l.pending;return a===null?n.next=n:(n.next=a.next,a.next=n),l.pending=n,Bn(e,s)}return a=l.interleaved,a===null?(n.next=n,Nd(l)):(n.next=a.next,a.next=n),l.interleaved=n,Bn(e,s)}function vr(e,n,s){if(n=n.updateQueue,n!==null&&(n=n.shared,(s&4194240)!==0)){var l=n.lanes;l&=e.pendingLanes,s|=l,n.lanes=s,_d(e,s)}}function eu(e,n){var s=e.updateQueue,l=e.alternate;if(l!==null&&(l=l.updateQueue,s===l)){var a=null,r=null;if(s=s.firstBaseUpdate,s!==null){do{var o={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};r===null?a=r=o:r=r.next=o,s=s.next}while(s!==null);r===null?a=r=n:r=r.next=n}else a=r=n;s={baseState:l.baseState,firstBaseUpdate:a,lastBaseUpdate:r,shared:l.shared,effects:l.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=n:e.next=n,s.lastBaseUpdate=n}function Mr(e,n,s,l){var a=e.updateQueue;Qn=!1;var r=a.firstBaseUpdate,o=a.lastBaseUpdate,d=a.shared.pending;if(d!==null){a.shared.pending=null;var p=d,f=p.next;p.next=null,o===null?r=f:o.next=f,o=p;var k=e.alternate;k!==null&&(k=k.updateQueue,d=k.lastBaseUpdate,d!==o&&(d===null?k.firstBaseUpdate=f:d.next=f,k.lastBaseUpdate=p))}if(r!==null){var j=a.baseState;o=0,k=f=p=null,d=r;do{var b=d.lane,c=d.eventTime;if((l&b)===b){k!==null&&(k=k.next={eventTime:c,lane:0,tag:d.tag,payload:d.payload,callback:d.callback,next:null});e:{var y=e,z=d;switch(b=n,c=s,z.tag){case 1:if(y=z.payload,typeof y=="function"){j=y.call(c,j,b);break e}j=y;break e;case 3:y.flags=y.flags&-65537|128;case 0:if(y=z.payload,b=typeof y=="function"?y.call(c,j,b):y,b==null)break e;j=We({},j,b);break e;case 2:Qn=!0}}d.callback!==null&&d.lane!==0&&(e.flags|=64,b=a.effects,b===null?a.effects=[d]:b.push(d))}else c={eventTime:c,lane:b,tag:d.tag,payload:d.payload,callback:d.callback,next:null},k===null?(f=k=c,p=j):k=k.next=c,o|=b;if(d=d.next,d===null){if(d=a.shared.pending,d===null)break;b=d,d=b.next,b.next=null,a.lastBaseUpdate=b,a.shared.pending=null}}while(!0);if(k===null&&(p=j),a.baseState=p,a.firstBaseUpdate=f,a.lastBaseUpdate=k,n=a.shared.interleaved,n!==null){a=n;do o|=a.lane,a=a.next;while(a!==n)}else r===null&&(a.shared.lanes=0);Os|=o,e.lanes=o,e.memoizedState=j}}function tu(e,n,s){if(e=n.effects,n.effects=null,e!==null)for(n=0;ns?s:4,e(!0);var l=lo.transition;lo.transition={};try{e(!1),n()}finally{_e=s,lo.transition=l}}function jf(){return Jt().memoizedState}function Ex(e,n,s){var l=as(e);if(s={lane:l,action:s,hasEagerState:!1,eagerState:null,next:null},bf(e))Sf(n,s);else if(s=tf(e,n,s,l),s!==null){var a=wt();dn(s,e,l,a),_f(s,n,l)}}function Ax(e,n,s){var l=as(e),a={lane:l,action:s,hasEagerState:!1,eagerState:null,next:null};if(bf(e))Sf(n,a);else{var r=e.alternate;if(e.lanes===0&&(r===null||r.lanes===0)&&(r=n.lastRenderedReducer,r!==null))try{var o=n.lastRenderedState,d=r(o,s);if(a.hasEagerState=!0,a.eagerState=d,cn(d,o)){var p=n.interleaved;p===null?(a.next=a,Nd(n)):(a.next=p.next,p.next=a),n.interleaved=a;return}}catch{}finally{}s=tf(e,n,a,l),s!==null&&(a=wt(),dn(s,e,l,a),_f(s,n,l))}}function bf(e){var n=e.alternate;return e===Ne||n!==null&&n===Ne}function Sf(e,n){ua=Hr=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function _f(e,n,s){if(s&4194240){var l=n.lanes;l&=e.pendingLanes,s|=l,n.lanes=s,_d(e,s)}}var Gr={readContext:qt,useCallback:xt,useContext:xt,useEffect:xt,useImperativeHandle:xt,useInsertionEffect:xt,useLayoutEffect:xt,useMemo:xt,useReducer:xt,useRef:xt,useState:xt,useDebugValue:xt,useDeferredValue:xt,useTransition:xt,useMutableSource:xt,useSyncExternalStore:xt,useId:xt,unstable_isNewReconciler:!1},Px={readContext:qt,useCallback:function(e,n){return vn().memoizedState=[e,n===void 0?null:n],e},useContext:qt,useEffect:su,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,br(4194308,4,gf.bind(null,n,e),s)},useLayoutEffect:function(e,n){return br(4194308,4,e,n)},useInsertionEffect:function(e,n){return br(4,2,e,n)},useMemo:function(e,n){var s=vn();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var l=vn();return n=s!==void 0?s(n):n,l.memoizedState=l.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},l.queue=e,e=e.dispatch=Ex.bind(null,Ne,e),[l.memoizedState,e]},useRef:function(e){var n=vn();return e={current:e},n.memoizedState=e},useState:nu,useDebugValue:Qd,useDeferredValue:function(e){return vn().memoizedState=e},useTransition:function(){var e=nu(!1),n=e[0];return e=Tx.bind(null,e[1]),vn().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var l=Ne,a=vn();if(Re){if(s===void 0)throw Error(Y(407));s=s()}else{if(s=n(),ct===null)throw Error(Y(349));Ds&30||rf(l,n,s)}a.memoizedState=s;var r={value:s,getSnapshot:n};return a.queue=r,su(df.bind(null,l,r,e),[e]),l.flags|=2048,Ea(9,of.bind(null,l,r,s,n),void 0,null),s},useId:function(){var e=vn(),n=ct.identifierPrefix;if(Re){var s=On,l=Dn;s=(l&~(1<<32-on(l)-1)).toString(32)+s,n=":"+n+"R"+s,s=Ia++,0<\/script>",e=e.removeChild(e.firstChild)):typeof l.is=="string"?e=o.createElement(s,{is:l.is}):(e=o.createElement(s),s==="select"&&(o=e,l.multiple?o.multiple=!0:l.size&&(o.size=l.size))):e=o.createElementNS(e,s),e[jn]=n,e[ka]=l,Rf(e,n,!1,!1),n.stateNode=e;e:{switch(o=zo(s,l),s){case"dialog":Te("cancel",e),Te("close",e),a=l;break;case"iframe":case"object":case"embed":Te("load",e),a=l;break;case"video":case"audio":for(a=0;aRl&&(n.flags|=128,l=!0,Jl(r,!1),n.lanes=4194304)}else{if(!l)if(e=Fr(o),e!==null){if(n.flags|=128,l=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),Jl(r,!0),r.tail===null&&r.tailMode==="hidden"&&!o.alternate&&!Re)return yt(n),null}else 2*Je()-r.renderingStartTime>Rl&&s!==1073741824&&(n.flags|=128,l=!0,Jl(r,!1),n.lanes=4194304);r.isBackwards?(o.sibling=n.child,n.child=o):(s=r.last,s!==null?s.sibling=o:n.child=o,r.last=o)}return r.tail!==null?(n=r.tail,r.rendering=n,r.tail=n.sibling,r.renderingStartTime=Je(),n.sibling=null,s=Le.current,Ce(Le,l?s&1|2:s&1),n):(yt(n),null);case 22:case 23:return Vd(),l=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==l&&(n.flags|=8192),l&&n.mode&1?Ot&1073741824&&(yt(n),n.subtreeFlags&6&&(n.flags|=8192)):yt(n),null;case 24:return null;case 25:return null}throw Error(Y(156,n.tag))}function $x(e,n){switch(Pd(n),n.tag){case 1:return Et(n.type)&&Lr(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Al(),Ee(Tt),Ee(jt),Ud(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return $d(n),null;case 13:if(Ee(Le),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(Y(340));Tl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Ee(Le),null;case 4:return Al(),null;case 10:return Ld(n.type._context),null;case 22:case 23:return Vd(),null;case 24:return null;default:return null}}var ir=!1,vt=!1,Ux=typeof WeakSet=="function"?WeakSet:Set,J=null;function yl(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(l){Qe(e,n,l)}else s.current=null}function ed(e,n,s){try{s()}catch(l){Qe(e,n,l)}}var hu=!1;function Mx(e,n){if(No=Pr,e=Bp(),Ed(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var l=s.getSelection&&s.getSelection();if(l&&l.rangeCount!==0){s=l.anchorNode;var a=l.anchorOffset,r=l.focusNode;l=l.focusOffset;try{s.nodeType,r.nodeType}catch{s=null;break e}var o=0,d=-1,p=-1,f=0,k=0,j=e,b=null;t:for(;;){for(var c;j!==s||a!==0&&j.nodeType!==3||(d=o+a),j!==r||l!==0&&j.nodeType!==3||(p=o+l),j.nodeType===3&&(o+=j.nodeValue.length),(c=j.firstChild)!==null;)b=j,j=c;for(;;){if(j===e)break t;if(b===s&&++f===a&&(d=o),b===r&&++k===l&&(p=o),(c=j.nextSibling)!==null)break;j=b,b=j.parentNode}j=c}s=d===-1||p===-1?null:{start:d,end:p}}else s=null}s=s||{start:0,end:0}}else s=null;for(Wo={focusedElem:e,selectionRange:s},Pr=!1,J=n;J!==null;)if(n=J,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,J=e;else for(;J!==null;){n=J;try{var y=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(y!==null){var z=y.memoizedProps,C=y.memoizedState,g=n.stateNode,i=g.getSnapshotBeforeUpdate(n.elementType===n.type?z:ln(n.type,z),C);g.__reactInternalSnapshotBeforeUpdate=i}break;case 3:var h=n.stateNode.containerInfo;h.nodeType===1?h.textContent="":h.nodeType===9&&h.documentElement&&h.removeChild(h.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Y(163))}}catch(x){Qe(n,n.return,x)}if(e=n.sibling,e!==null){e.return=n.return,J=e;break}J=n.return}return y=hu,hu=!1,y}function pa(e,n,s){var l=n.updateQueue;if(l=l!==null?l.lastEffect:null,l!==null){var a=l=l.next;do{if((a.tag&e)===e){var r=a.destroy;a.destroy=void 0,r!==void 0&&ed(n,s,r)}a=a.next}while(a!==l)}}function oi(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var s=n=n.next;do{if((s.tag&e)===e){var l=s.create;s.destroy=l()}s=s.next}while(s!==n)}}function td(e){var n=e.ref;if(n!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof n=="function"?n(e):n.current=e}}function Lf(e){var n=e.alternate;n!==null&&(e.alternate=null,Lf(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[jn],delete n[ka],delete n[Uo],delete n[wx],delete n[kx])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Nf(e){return e.tag===5||e.tag===3||e.tag===4}function gu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Nf(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function nd(e,n,s){var l=e.tag;if(l===5||l===6)e=e.stateNode,n?s.nodeType===8?s.parentNode.insertBefore(e,n):s.insertBefore(e,n):(s.nodeType===8?(n=s.parentNode,n.insertBefore(e,s)):(n=s,n.appendChild(e)),s=s._reactRootContainer,s!=null||n.onclick!==null||(n.onclick=Or));else if(l!==4&&(e=e.child,e!==null))for(nd(e,n,s),e=e.sibling;e!==null;)nd(e,n,s),e=e.sibling}function sd(e,n,s){var l=e.tag;if(l===5||l===6)e=e.stateNode,n?s.insertBefore(e,n):s.appendChild(e);else if(l!==4&&(e=e.child,e!==null))for(sd(e,n,s),e=e.sibling;e!==null;)sd(e,n,s),e=e.sibling}var pt=null,an=!1;function Fn(e,n,s){for(s=s.child;s!==null;)Wf(e,n,s),s=s.sibling}function Wf(e,n,s){if(bn&&typeof bn.onCommitFiberUnmount=="function")try{bn.onCommitFiberUnmount(ei,s)}catch{}switch(s.tag){case 5:vt||yl(s,n);case 6:var l=pt,a=an;pt=null,Fn(e,n,s),pt=l,an=a,pt!==null&&(an?(e=pt,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):pt.removeChild(s.stateNode));break;case 18:pt!==null&&(an?(e=pt,s=s.stateNode,e.nodeType===8?to(e.parentNode,s):e.nodeType===1&&to(e,s),ja(e)):to(pt,s.stateNode));break;case 4:l=pt,a=an,pt=s.stateNode.containerInfo,an=!0,Fn(e,n,s),pt=l,an=a;break;case 0:case 11:case 14:case 15:if(!vt&&(l=s.updateQueue,l!==null&&(l=l.lastEffect,l!==null))){a=l=l.next;do{var r=a,o=r.destroy;r=r.tag,o!==void 0&&(r&2||r&4)&&ed(s,n,o),a=a.next}while(a!==l)}Fn(e,n,s);break;case 1:if(!vt&&(yl(s,n),l=s.stateNode,typeof l.componentWillUnmount=="function"))try{l.props=s.memoizedProps,l.state=s.memoizedState,l.componentWillUnmount()}catch(d){Qe(s,n,d)}Fn(e,n,s);break;case 21:Fn(e,n,s);break;case 22:s.mode&1?(vt=(l=vt)||s.memoizedState!==null,Fn(e,n,s),vt=l):Fn(e,n,s);break;default:Fn(e,n,s)}}function mu(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new Ux),n.forEach(function(l){var a=Jx.bind(null,e,l);s.has(l)||(s.add(l),l.then(a,a))})}}function nn(e,n){var s=n.deletions;if(s!==null)for(var l=0;la&&(a=o),l&=~r}if(l=a,l=Je()-l,l=(120>l?120:480>l?480:1080>l?1080:1920>l?1920:3e3>l?3e3:4320>l?4320:1960*Hx(l/1960))-l,10e?16:e,qn===null)var l=!1;else{if(e=qn,qn=null,Yr=0,ye&6)throw Error(Y(331));var a=ye;for(ye|=4,J=e.current;J!==null;){var r=J,o=r.child;if(J.flags&16){var d=r.deletions;if(d!==null){for(var p=0;pJe()-qd?Es(e,0):Xd|=s),At(e,n)}function Qf(e,n){n===0&&(e.mode&1?(n=Va,Va<<=1,!(Va&130023424)&&(Va=4194304)):n=1);var s=wt();e=Bn(e,n),e!==null&&(Oa(e,n,s),At(e,s))}function qx(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),Qf(e,s)}function Jx(e,n){var s=0;switch(e.tag){case 13:var l=e.stateNode,a=e.memoizedState;a!==null&&(s=a.retryLane);break;case 19:l=e.stateNode;break;default:throw Error(Y(314))}l!==null&&l.delete(n),Qf(e,s)}var Kf;Kf=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||Tt.current)It=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return It=!1,Wx(e,n,s);It=!!(e.flags&131072)}else It=!1,Re&&n.flags&1048576&&qp(n,Br,n.index);switch(n.lanes=0,n.tag){case 2:var l=n.type;Sr(e,n),e=n.pendingProps;var a=Il(n,jt.current);kl(n,s),a=Fd(null,n,l,e,a,s);var r=Hd();return n.flags|=1,typeof a=="object"&&a!==null&&typeof a.render=="function"&&a.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,Et(l)?(r=!0,Nr(n)):r=!1,n.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,Wd(n),a.updater=ii,n.stateNode=a,a._reactInternals=n,Ko(n,l,e,s),n=qo(null,n,l,!0,r,s)):(n.tag=0,Re&&r&&Ad(n),_t(null,n,a,s),n=n.child),n;case 16:l=n.elementType;e:{switch(Sr(e,n),e=n.pendingProps,a=l._init,l=a(l._payload),n.type=l,a=n.tag=Zx(l),e=ln(l,e),a){case 0:n=Xo(null,n,l,e,s);break e;case 1:n=uu(null,n,l,e,s);break e;case 11:n=du(null,n,l,e,s);break e;case 14:n=cu(null,n,l,ln(l.type,e),s);break e}throw Error(Y(306,l,""))}return n;case 0:return l=n.type,a=n.pendingProps,a=n.elementType===l?a:ln(l,a),Xo(e,n,l,a,s);case 1:return l=n.type,a=n.pendingProps,a=n.elementType===l?a:ln(l,a),uu(e,n,l,a,s);case 3:e:{if(Ef(n),e===null)throw Error(Y(387));l=n.pendingProps,r=n.memoizedState,a=r.element,nf(e,n),Mr(n,l,null,s);var o=n.memoizedState;if(l=o.element,r.isDehydrated)if(r={element:l,isDehydrated:!1,cache:o.cache,pendingSuspenseBoundaries:o.pendingSuspenseBoundaries,transitions:o.transitions},n.updateQueue.baseState=r,n.memoizedState=r,n.flags&256){a=Pl(Error(Y(423)),n),n=pu(e,n,l,s,a);break e}else if(l!==a){a=Pl(Error(Y(424)),n),n=pu(e,n,l,s,a);break e}else for(Lt=ns(n.stateNode.containerInfo.firstChild),Nt=n,Re=!0,rn=null,s=ef(n,null,l,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(Tl(),l===a){n=$n(e,n,s);break e}_t(e,n,l,s)}n=n.child}return n;case 5:return sf(n),e===null&&Ho(n),l=n.type,a=n.pendingProps,r=e!==null?e.memoizedProps:null,o=a.children,Bo(l,a)?o=null:r!==null&&Bo(l,r)&&(n.flags|=32),Tf(e,n),_t(e,n,o,s),n.child;case 6:return e===null&&Ho(n),null;case 13:return Af(e,n,s);case 4:return Bd(n,n.stateNode.containerInfo),l=n.pendingProps,e===null?n.child=El(n,null,l,s):_t(e,n,l,s),n.child;case 11:return l=n.type,a=n.pendingProps,a=n.elementType===l?a:ln(l,a),du(e,n,l,a,s);case 7:return _t(e,n,n.pendingProps,s),n.child;case 8:return _t(e,n,n.pendingProps.children,s),n.child;case 12:return _t(e,n,n.pendingProps.children,s),n.child;case 10:e:{if(l=n.type._context,a=n.pendingProps,r=n.memoizedProps,o=a.value,Ce($r,l._currentValue),l._currentValue=o,r!==null)if(cn(r.value,o)){if(r.children===a.children&&!Tt.current){n=$n(e,n,s);break e}}else for(r=n.child,r!==null&&(r.return=n);r!==null;){var d=r.dependencies;if(d!==null){o=r.child;for(var p=d.firstContext;p!==null;){if(p.context===l){if(r.tag===1){p=Ln(-1,s&-s),p.tag=2;var f=r.updateQueue;if(f!==null){f=f.shared;var k=f.pending;k===null?p.next=p:(p.next=k.next,k.next=p),f.pending=p}}r.lanes|=s,p=r.alternate,p!==null&&(p.lanes|=s),Go(r.return,s,n),d.lanes|=s;break}p=p.next}}else if(r.tag===10)o=r.type===n.type?null:r.child;else if(r.tag===18){if(o=r.return,o===null)throw Error(Y(341));o.lanes|=s,d=o.alternate,d!==null&&(d.lanes|=s),Go(o,s,n),o=r.sibling}else o=r.child;if(o!==null)o.return=r;else for(o=r;o!==null;){if(o===n){o=null;break}if(r=o.sibling,r!==null){r.return=o.return,o=r;break}o=o.return}r=o}_t(e,n,a.children,s),n=n.child}return n;case 9:return a=n.type,l=n.pendingProps.children,kl(n,s),a=qt(a),l=l(a),n.flags|=1,_t(e,n,l,s),n.child;case 14:return l=n.type,a=ln(l,n.pendingProps),a=ln(l.type,a),cu(e,n,l,a,s);case 15:return zf(e,n,n.type,n.pendingProps,s);case 17:return l=n.type,a=n.pendingProps,a=n.elementType===l?a:ln(l,a),Sr(e,n),n.tag=1,Et(l)?(e=!0,Nr(n)):e=!1,kl(n,s),wf(n,l,a),Ko(n,l,a,s),qo(null,n,l,!0,e,s);case 19:return Pf(e,n,s);case 22:return If(e,n,s)}throw Error(Y(156,n.tag))};function Yf(e,n){return jp(e,n)}function Vx(e,n,s,l){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=l,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Yt(e,n,s,l){return new Vx(e,n,s,l)}function ec(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Zx(e){if(typeof e=="function")return ec(e)?1:0;if(e!=null){if(e=e.$$typeof,e===vd)return 11;if(e===jd)return 14}return 2}function rs(e,n){var s=e.alternate;return s===null?(s=Yt(e.tag,n,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=n,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,n=e.dependencies,s.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function kr(e,n,s,l,a,r){var o=2;if(l=e,typeof e=="function")ec(e)&&(o=1);else if(typeof e=="string")o=5;else e:switch(e){case dl:return As(s.children,a,r,n);case yd:o=8,a|=8;break;case xo:return e=Yt(12,s,n,a|2),e.elementType=xo,e.lanes=r,e;case yo:return e=Yt(13,s,n,a),e.elementType=yo,e.lanes=r,e;case vo:return e=Yt(19,s,n,a),e.elementType=vo,e.lanes=r,e;case sp:return ci(s,a,r,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case tp:o=10;break e;case np:o=9;break e;case vd:o=11;break e;case jd:o=14;break e;case Gn:o=16,l=null;break e}throw Error(Y(130,e==null?e:typeof e,""))}return n=Yt(o,s,n,a),n.elementType=e,n.type=l,n.lanes=r,n}function As(e,n,s,l){return e=Yt(7,e,l,n),e.lanes=s,e}function ci(e,n,s,l){return e=Yt(22,e,l,n),e.elementType=sp,e.lanes=s,e.stateNode={isHidden:!1},e}function co(e,n,s){return e=Yt(6,e,null,n),e.lanes=s,e}function uo(e,n,s){return n=Yt(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function ey(e,n,s,l,a){this.tag=n,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Hi(0),this.expirationTimes=Hi(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Hi(0),this.identifierPrefix=l,this.onRecoverableError=a,this.mutableSourceEagerHydrationData=null}function tc(e,n,s,l,a,r,o,d,p){return e=new ey(e,n,s,d,p),n===1?(n=1,r===!0&&(n|=8)):n=0,r=Yt(3,null,null,n),e.current=r,r.stateNode=e,r.memoizedState={element:l,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Wd(r),e}function ty(e,n,s){var l=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Vf)}catch(e){console.error(e)}}Vf(),Ju.exports=Bt;var ry=Ju.exports,Zf,wu=ry;Zf=wu.createRoot,wu.hydrateRoot;const he="",P={incidents:"SB Incident",ideas:"SB Idea",orders:"SB Order",organizations:"SB Organization",processes:"SB Process",managements:"Managements",departments:"Department",branches:"Branch",incidentTypes:"Incident Types",ideaTypes:"Idea Types",orderTypes:"Order Types",processTypes:"Process Types",incidentClass:"Incident Class",incidentField:"Incident Field",incidentStatuses:"Incident Statuses",ideaStatuses:"Idea Statuses",orderStatuses:"Order Statuses",processStatuses:"Process Statuses",users:"User",cycles:"SB Cycle",kpiInput:"SB KPI Input",delegations:"SB Delegation",groupCompanies:"SB Group Company",currency:"Currency"},X={bg:"#f5f6fa",accent:"#4f46e5",red:"#ef4444",orange:"#f59e0b",green:"#16a34a",purple:"#7c3aed",blue:"#2563eb",teal:"#0d9488",gray:"#94a3b8"},iy=[{id:"dashboard",icon:"📊",label:"Dashboard"},{id:"inbox",icon:"📥",label:"Inbox"},{id:"incidents",icon:"📋",label:"Incidents"},{id:"ideas",icon:"💡",label:"Ideas"},{id:"orders",icon:"📦",label:"Orders"},{id:"processes",icon:"⚙️",label:"Processes"},{id:"delegations",icon:"🤝",label:"Delegations"},{id:"reports",icon:"📈",label:"Reports"}],eh=[{id:"group-companies",icon:"🌐",label:"Group Companies"},{id:"users",icon:"👤",label:"Users"},{id:"organizations",icon:"🏢",label:"Organizations"},{id:"managements",icon:"🏗️",label:"Managements"},{id:"departments",icon:"🗂️",label:"Departments"},{id:"branches",icon:"🌿",label:"Branches"},{id:"cycles",icon:"🔄",label:"Cycles"},{id:"kpi-input",icon:"📊",label:"KPI Input"},{id:"incident-types",icon:"🚨",label:"Incident Types"},{id:"idea-types",icon:"💡",label:"Idea Types"},{id:"order-types",icon:"📦",label:"Order Types"},{id:"process-types",icon:"⚙️",label:"Process Types"},{id:"incident-statuses",icon:"🔴",label:"Incident Statuses"},{id:"idea-statuses",icon:"🟢",label:"Idea Statuses"},{id:"order-statuses",icon:"🟣",label:"Order Statuses"},{id:"process-statuses",icon:"🔵",label:"Process Statuses"}],oy=new Set(["users","group-companies"]);function dy(e){return e!=="Admin"&&e!=="Auditor"?[]:eh.filter(({id:n})=>e==="Admin"||!oy.has(n))}const Hn=(e=[])=>[{key:"name1",label:"Name"},{key:"status",label:"Status"},...e,{key:"creation_date",label:"Created On"}],cy={incidents:{label:"Incidents",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"date",label:"Date"},{key:"assigned_to",label:"Assigned To"},{key:"priority",label:"Priority"},{key:"economy_class",label:"Economy Class"},{key:"entity_scope",label:"Entity Scope"},{key:"hses_field",label:"HSES Field"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","date","assigned_to"]},ideas:{label:"Ideas",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"date",label:"Date"},{key:"assigned_to",label:"Assigned To"},{key:"priority",label:"Priority"},{key:"economy_class",label:"Economy Class"},{key:"current_condition",label:"Current Condition"},{key:"proposed_condition",label:"Proposed Condition"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","date","assigned_to"]},orders:{label:"Orders",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"starting_date",label:"Start Date"},{key:"ending_date",label:"End Date"},{key:"assigned_to",label:"Assigned To"},{key:"budget",label:"Budget"},{key:"actual_cost",label:"Actual Cost"},{key:"currency",label:"Currency"},{key:"stage",label:"Stage"},{key:"completion_pct",label:"Completion %"},{key:"priority",label:"Priority"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","starting_date","ending_date","assigned_to","budget"]},processes:{label:"Processes",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"date_start",label:"Start Date"},{key:"date_end",label:"End Date"},{key:"actor",label:"Actor"},{key:"cycle_type",label:"Cycle Type"},{key:"kpi_name",label:"KPI Name"},{key:"cost_per_cycle",label:"Cost / Cycle"},{key:"escalation_level",label:"Escalation"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","date_start","date_end","actor"]},organizations:{label:"Organizations",columns:[{key:"name",label:"Code"},{key:"organization_name",label:"Organization Name"},{key:"type",label:"Type"},{key:"city",label:"City"},{key:"contact_email",label:"Contact Email"},{key:"is_active",label:"Active"},{key:"creation_date",label:"Created On"}],defaultColumns:["organization_name","type","city","contact_email","is_active"]},managements:{label:"Managements",orgField:"organization",columns:[{key:"name1",label:"Name"},{key:"organization",label:"Organization"},{key:"status",label:"Status"},{key:"creation_date",label:"Created On"}],defaultColumns:["name1","organization","status"]},departments:{label:"Departments",orgField:"custom_organization",columns:[{key:"department_name",label:"Department Name"},{key:"custom_organization",label:"Organization"},{key:"custom_management",label:"Management"},{key:"custom_status",label:"Status"},{key:"custom_creation_date",label:"Created On"}],defaultColumns:["department_name","custom_organization","custom_management","custom_status"]},branches:{label:"Branches",orgField:"organization",columns:[{key:"branch",label:"Branch"},{key:"organization",label:"Organization"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"custom_status",label:"Status"},{key:"custom_creation_date",label:"Created On"}],defaultColumns:["branch","organization","management","department","custom_status"]},cycles:{label:"Cycles",orgField:"organization",columns:[{key:"name1",label:"Name"},{key:"organization",label:"Organization"},{key:"frequency",label:"Frequency"},{key:"status",label:"Status"},{key:"start_date",label:"Start Date"},{key:"end_date",label:"End Date"},{key:"update_window_days",label:"Update Window (days)"}],defaultColumns:["name1","organization","frequency","status","start_date","end_date"]},"kpi-input":{label:"KPI Input",orgField:"organization",columns:[{key:"organization",label:"Organization"},{key:"period",label:"Period"},{key:"revenue_growth",label:"Revenue Growth"},{key:"net_profit",label:"Net Profit"},{key:"cash_flow",label:"Cash Flow"},{key:"strategic_goal_pct",label:"Strategic Goal %"},{key:"customer_satisfaction",label:"Customer Satisfaction"},{key:"employee_turnover_pct",label:"Employee Turnover %"},{key:"open_safety_incidents",label:"Open Safety Incidents"},{key:"compliance_score",label:"Compliance Score"}],defaultColumns:["organization","period","revenue_growth","net_profit","cash_flow"]},"incident-types":{label:"Incident Types",columns:Hn(),defaultColumns:["name1","status","creation_date"]},"idea-types":{label:"Idea Types",columns:Hn(),defaultColumns:["name1","status","creation_date"]},"order-types":{label:"Order Types",columns:Hn(),defaultColumns:["name1","status","creation_date"]},"process-types":{label:"Process Types",columns:Hn(),defaultColumns:["name1","status","creation_date"]},"incident-statuses":{label:"Incident Statuses",columns:Hn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"idea-statuses":{label:"Idea Statuses",columns:Hn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"order-statuses":{label:"Order Statuses",columns:Hn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"process-statuses":{label:"Process Statuses",columns:Hn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},users:{label:"Users",orgField:"custom_organization",columns:[{key:"full_name",label:"Full Name"},{key:"email",label:"Email"},{key:"username",label:"Username"},{key:"mobile_no",label:"Phone"},{key:"custom_category",label:"Category"},{key:"custom_organization",label:"Organization"},{key:"custom_management",label:"Management"},{key:"custom_department",label:"Department"},{key:"custom_branch",label:"Branch"},{key:"custom_number",label:"User ID No"},{key:"enabled",label:"Active"},{key:"creation",label:"Created On"}],defaultColumns:["full_name","email","custom_category","custom_organization","enabled"]},delegations:{label:"Delegations",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"auditor",label:"Delegator"},{key:"manager",label:"Manager"},{key:"organization",label:"Organization"},{key:"incident_initial_evaluation",label:"Incident Initial Evaluation"},{key:"idea_initial_evaluation",label:"Idea Initial Evaluation"},{key:"status",label:"Status"},{key:"requested_on",label:"Requested On"},{key:"responded_on",label:"Responded On"}],defaultColumns:["number","auditor","manager","organization","incident_initial_evaluation","idea_initial_evaluation","status","requested_on"]},"group-companies":{label:"Group Companies",columns:[{key:"company_name",label:"Company Name"},{key:"code",label:"Code"},{key:"acronym",label:"Acronym"},{key:"owner_user",label:"Group Co Owner"},{key:"status",label:"Status"}],defaultColumns:["company_name","code","acronym","owner_user","status"]}},uy=()=>t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),py=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),fy=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"}),t.jsx("path",{d:"M10 11v6M14 11v6"}),t.jsx("path",{d:"M9 6V4h6v2"})]});function ot({onView:e,onEdit:n,onDelete:s}){const l=(a,r,o,d,p,f)=>d?t.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),d()},title:f,style:{width:30,height:30,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid transparent",cursor:"pointer",background:a,color:o,flexShrink:0,transition:"all 0.15s ease"},onMouseEnter:k=>{k.currentTarget.style.background=r,k.currentTarget.style.transform="scale(1.08)"},onMouseLeave:k=>{k.currentTarget.style.background=a,k.currentTarget.style.transform="scale(1)"},children:p},f):null;return t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[l("#f0f9ff","#e0f2fe","#0284c7",e,t.jsx(uy,{}),"View"),l("#f0fdf4","#dcfce7","#16a34a",n,t.jsx(py,{}),"Edit"),s&&l("#fff1f2","#fee2e2","#e11d48",s,t.jsx(fy,{}),"Delete")]})}const L={width:"100%",height:34,padding:"7px 10px",border:"1px solid #ddd",borderRadius:6,fontSize:12,boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif"},R={display:"block",marginBottom:5,fontSize:11,color:"#555",fontWeight:600};function th(e){return e?e.custom_is_deleted===1||e.custom_is_deleted==="1"||e.custom_is_deleted===!0||e.is_deleted===1||e.is_deleted==="1"||e.is_deleted===!0||e.status==="Deleted"||e.custom_status==="Deleted":!1}function hy(e){return th(e)?!1:typeof(e==null?void 0:e.is_active)<"u"?!!e.is_active:typeof(e==null?void 0:e.status)<"u"?e.status!=="Inactive":typeof(e==null?void 0:e.custom_status)<"u"?e.custom_status!=="Inactive":!0}function be(e,n){return(e||[]).filter(s=>!th(s)&&(hy(s)||s.name===n))}const gy={incident:["Rejected","Executed & Closed"],idea:["Rejected","Executed & Closed"],order:["Closed"],process:["Closed"]};function Jn(e,n){return!!n&&gy[e].includes(n)}function Dl(e,n,s,l){return e.filter(a=>{const r=n[a.name]||[];return!(r.includes("SB Admin")||r.includes("System Manager")||!r.includes(s)||l&&a.custom_organization&&a.custom_organization!==l)})}const Ol={width:16,height:16,cursor:"pointer",accentColor:"#2563eb",flexShrink:0};function Cr(e){const n=(e||"").trim().toLowerCase();return n==="new"||n==="initial evaluation"||n==="draft"?{bg:"#eff6ff",color:"#1d4ed8",border:"#bfdbfe"}:n.includes("progress")||n.includes("review")||n.includes("proposal")||n.includes("resolution")?{bg:"#fefce8",color:"#a16207",border:"#fef08a"}:n.includes("executed")||n.includes("approved")||n.includes("active")||n.includes("closed")||n.includes("completed")?{bg:"#f0fdf4",color:"#15803d",border:"#bbf7d0"}:n.includes("rejected")||n.includes("overdue")||n.includes("fail")||n.includes("inactive")?{bg:"#fef2f2",color:"#b91c1c",border:"#fecaca"}:n.includes("deleted")?{bg:"#fff1f2",color:"#e11d48",border:"#fecdd3"}:{bg:"#f8fafc",color:"#475569",border:"#e2e8f0"}}function my(e){const n=(e||"").trim().toLowerCase();return n.includes("incident")?{bg:"#f1f5f9",color:"#334155",border:"#cbd5e1"}:n.includes("complaint")?{bg:"#fff7ed",color:"#c2410c",border:"#fed7aa"}:n.includes("violation")?{bg:"#faf5ff",color:"#7e22ce",border:"#e9d5ff"}:n.includes("process")?{bg:"#f0fdfa",color:"#0f766e",border:"#99f6e4"}:n.includes("asset")?{bg:"#ecfeff",color:"#0e7490",border:"#a5f3fc"}:n.includes("human")?{bg:"#f5f3ff",color:"#6d28d9",border:"#ddd6fe"}:n.includes("idea")?{bg:"#ecfdf5",color:"#047857",border:"#a7f3d0"}:n.includes("study")?{bg:"#eff6ff",color:"#1d4ed8",border:"#bfdbfe"}:{bg:"#f8fafc",color:"#475569",border:"#e2e8f0"}}const Pa=(e,n)=>{let s;return typeof n=="object"&&n!==null?s=n:typeof n=="string"&&n.startsWith("#")?s=Cr(e):typeof n=="string"?s=Cr(n):s=Cr(e),t.jsx("span",{className:"status-badge",style:{background:s.bg,color:s.color,border:`1px solid ${s.border}`,padding:"2px 8px",borderRadius:9999,fontSize:11,fontWeight:600,letterSpacing:"0.2px",display:"inline-flex",alignItems:"center",justifyContent:"center",lineHeight:1.3,whiteSpace:"nowrap",boxSizing:"border-box",transition:"all 0.15s ease"},children:e})},ds=e=>Pa(e,Cr(e)),ac=e=>Pa(e,my(e));function Ve({deletedBy:e,deletedOn:n,reason:s,onRestore:l,onPermanentDelete:a,isRestoring:r}){return t.jsxs("div",{style:{background:"#fff1f2",border:"1px solid #fecdd3",borderRadius:8,padding:"7px 14px",marginBottom:12,display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,color:"#9f1239",fontSize:12,flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsxs("div",{style:{fontWeight:700,fontSize:12,display:"flex",alignItems:"center",gap:5,color:"#be123c",whiteSpace:"nowrap"},children:[t.jsx("span",{style:{fontSize:13},children:"⚠️"}),t.jsx("span",{children:"DELETED RECORD / سجل محذوف"})]}),t.jsxs("div",{style:{fontSize:11,color:"#881337",display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e&&t.jsxs("span",{children:[t.jsx("strong",{children:"Deleted By:"})," ",e]}),n&&t.jsxs("span",{children:["| ",t.jsx("strong",{children:"Deleted On:"})," ",n]}),s&&t.jsxs("span",{children:["| ",t.jsx("strong",{children:"Reason:"})," ",s]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[l&&t.jsxs("button",{type:"button",onClick:l,disabled:r,style:{background:"#16a34a",color:"white",border:"none",borderRadius:6,padding:"5px 12px",fontSize:11,fontWeight:700,cursor:r?"not-allowed":"pointer",boxShadow:"0 1px 2px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:5,whiteSpace:"nowrap",transition:"all 0.15s ease"},onMouseEnter:o=>{r||(o.currentTarget.style.background="#15803d")},onMouseLeave:o=>{r||(o.currentTarget.style.background="#16a34a")},children:[t.jsx("span",{children:"↺"}),t.jsx("span",{children:r?"Restoring...":"Restore Record / استعادة"})]}),a&&t.jsxs("button",{type:"button",onClick:a,style:{background:"#dc2626",color:"white",border:"none",borderRadius:6,padding:"5px 12px",fontSize:11,fontWeight:700,cursor:"pointer",boxShadow:"0 1px 2px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:5,whiteSpace:"nowrap",transition:"all 0.15s ease"},onMouseEnter:o=>{o.currentTarget.style.background="#b91c1c"},onMouseLeave:o=>{o.currentTarget.style.background="#dc2626"},children:[t.jsx("span",{children:"🗑️"}),t.jsx("span",{children:"Permanent Delete / حذف نهائي"})]})]})]})}function gi({onDelete:e,disabled:n,title:s="Delete Request",btnText:l="Delete"}){return t.jsxs("div",{style:{background:"#ffffff",borderRadius:10,padding:14,border:"1px solid #fee2e2",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:s}),t.jsxs("button",{type:"button",onClick:e,disabled:n,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:"#dc2626",color:"#ffffff",fontWeight:700,fontSize:12,cursor:n?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:6,boxShadow:"0 1px 3px rgba(220, 38, 38, 0.25)",transition:"all 0.15s ease"},onMouseEnter:a=>{n||(a.currentTarget.style.background="#b91c1c")},onMouseLeave:a=>{n||(a.currentTarget.style.background="#dc2626")},children:[t.jsx("span",{children:"🗑️"}),t.jsx("span",{children:l})]})]})}function oe({title:e,children:n,style:s}){return t.jsxs("div",{className:"form-card",style:{background:"#ffffff",borderRadius:10,border:"1px solid #e2e8f0",padding:"16px 20px",marginBottom:16,boxShadow:"0 1px 3px rgba(0, 0, 0, 0.03)",...s},children:[t.jsx("div",{className:"form-card-title",style:{fontSize:14,fontWeight:700,color:"#1e293b",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:t.jsx("span",{children:e})}),n]})}function mi({title:e="Status Summary",priority:n,createdDate:s,modifiedDate:l,assignedTo:a,status:r}){const o=d=>{if(!d)return"—";try{const p=new Date(d);return isNaN(p.getTime())?d:p.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return d}};return t.jsxs("div",{style:{background:"#ffffff",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:12},children:e}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[n&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Priority"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:n==="High"||n==="Urgent"?"#dc2626":"#1e293b"},children:n})]}),r&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Status"}),t.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#334155"},children:r})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Assigned To"}),t.jsx("div",{style:{fontSize:12,fontWeight:600,color:a?"#334155":"#94a3b8",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a||"—"})]}),s&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:2},children:"Created"}),t.jsx("div",{style:{fontSize:11,color:"#64748b"},children:o(s)})]}),l&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:2},children:"Last Modified"}),t.jsx("div",{style:{fontSize:11,color:"#64748b"},children:o(l)})]})]})]})}const xy="modulepreload",yy=function(e){return"/"+e},ku={},vy=function(n,s,l){let a=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),d=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));a=Promise.allSettled(s.map(p=>{if(p=yy(p),p in ku)return;ku[p]=!0;const f=p.endsWith(".css"),k=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${k}`))return;const j=document.createElement("link");if(j.rel=f?"stylesheet":xy,f||(j.as="script"),j.crossOrigin="",j.href=p,d&&j.setAttribute("nonce",d),document.head.appendChild(j),f)return new Promise((b,c)=>{j.addEventListener("load",b),j.addEventListener("error",()=>c(new Error(`Unable to preload CSS for ${p}`)))})}))}function r(o){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=o,window.dispatchEvent(d),!d.defaultPrevented)throw o}return a.then(o=>{for(const d of o||[])d.status==="rejected"&&r(d.reason);return n().catch(r)})};function nh(e,n){const s=e[n.key];return s==null||s===""?"":typeof s=="object"?JSON.stringify(s):String(s)}function jy(e,n){const s=URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download=n,l.click(),URL.revokeObjectURL(s)}function by(e,n,s){const l=e.map(o=>`"${o.label.replace(/"/g,'""')}"`).join(","),a=n.map(o=>e.map(d=>`"${nh(o,d).replace(/"/g,'""')}"`).join(",")).join(` `),r=new Blob([l+` `+a],{type:"text/csv;charset=utf-8;"});jy(r,`${s}.csv`)}async function Sy(e,n,s){const l=await vy(()=>import("./xlsx-D_0l8YDs.js"),[]),a=n.map(d=>{const p={};for(const f of e)p[f.label]=nh(d,f);return p}),r=l.utils.json_to_sheet(a,{header:e.map(d=>d.label)}),o=l.utils.book_new();l.utils.book_append_sheet(o,r,"Export"),l.writeFile(o,`${s}.xlsx`)}const mn="#16a34a";function _y({title:e,rows:n,selectedRows:s=[],pageRows:l=[],columns:a,defaultColumnKeys:r,filenameBase:o,onClose:d}){const[p,f]=_.useState(s.length>0?"selected":"all"),[k,j]=_.useState("csv"),[b,c]=_.useState(new Set(r)),[y,z]=_.useState("");_.useEffect(()=>{s&&s.length>0&&f("selected")},[s]);const C=p==="selected"?s:p==="page"?l:n,g=a.filter(v=>b.has(v.key)),i=y?a.filter(v=>v.label.toLowerCase().includes(y.toLowerCase())):a,h=v=>{c(I=>{const T=new Set(I);return T.has(v)?T.delete(v):T.add(v),T})},x=async()=>{g.length===0||C.length===0||(k==="csv"?by(g,C,o):await Sy(g,C,o),d())},S={fontSize:11,fontWeight:700,color:"#9ca3af",letterSpacing:.4,textTransform:"uppercase",marginBottom:10},w={background:"none",border:"none",color:"#2563eb",fontSize:12,fontWeight:600,cursor:"pointer",padding:0,fontFamily:"inherit"},u=[{id:"selected",label:"Selected rows",sub:`${s.length} row${s.length!==1?"s":""} selected`,count:s.length,disabled:s.length===0},{id:"page",label:"Current page",sub:`${l.length} row${l.length!==1?"s":""} on this page`,count:l.length},{id:"all",label:"All records (current filters)",sub:`${n.length} total matching records`,count:n.length}];return t.jsx("div",{onClick:d,style:{position:"fixed",inset:0,background:"rgba(15,23,42,0.55)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e4},children:t.jsxs("div",{onClick:v=>v.stopPropagation(),style:{width:580,maxWidth:"92vw",maxHeight:"90vh",background:"white",borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{background:mn,color:"white",padding:"16px 22px",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,fontSize:16,fontWeight:700},children:[t.jsx("span",{style:{fontSize:18},children:"📤"})," Export ",e,t.jsxs("span",{style:{fontSize:12,fontWeight:400,opacity:.8},children:[a.length," fields available · ",b.size," selected"]})]}),t.jsx("button",{onClick:d,style:{background:"rgba(255,255,255,0.15)",border:"none",color:"white",width:28,height:28,borderRadius:8,cursor:"pointer",fontSize:15,lineHeight:1},children:"✕"})]}),t.jsxs("div",{style:{padding:"20px 22px",overflowY:"auto",flex:1,display:"flex",flexDirection:"column",gap:20},children:[t.jsxs("div",{children:[t.jsx("div",{style:S,children:"What to export"}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:u.map(v=>t.jsxs("label",{onClick:()=>!v.disabled&&f(v.id),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderRadius:10,cursor:v.disabled?"not-allowed":"pointer",border:`2px solid ${p===v.id?mn:"#e5e7eb"}`,background:p===v.id?"#f0fdf4":v.disabled?"#fafafa":"white",opacity:v.disabled?.5:1,transition:"border-color 0.15s, background 0.15s"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx("div",{style:{width:16,height:16,borderRadius:"50%",border:`2px solid ${p===v.id?mn:"#d1d5db"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:p===v.id&&t.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:mn}})}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#111827"},children:v.label}),t.jsx("div",{style:{fontSize:12,color:"#6b7280",marginTop:1},children:v.sub})]})]}),t.jsx("span",{style:{background:p===v.id?mn:"#e5e7eb",color:p===v.id?"white":"#374151",fontSize:12,fontWeight:700,padding:"2px 10px",borderRadius:9999},children:v.count})]},v.id))})]}),t.jsxs("div",{children:[t.jsx("div",{style:S,children:"File Format"}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[{id:"csv",label:"CSV",desc:"Universal, works everywhere",icon:"📄"},{id:"xlsx",label:"Excel (.xlsx)",desc:"Native Excel workbook",icon:"📊"}].map(v=>t.jsxs("div",{onClick:()=>j(v.id),style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",borderRadius:10,cursor:"pointer",border:`2px solid ${k===v.id?mn:"#e5e7eb"}`,background:k===v.id?"#f0fdf4":"white"},children:[t.jsx("div",{style:{width:16,height:16,borderRadius:"50%",border:`2px solid ${k===v.id?mn:"#d1d5db"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:k===v.id&&t.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:mn}})}),t.jsx("span",{style:{fontSize:20},children:v.icon}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:v.label}),t.jsx("div",{style:{fontSize:11,color:"#888"},children:v.desc})]})]},v.id))})]}),t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[t.jsx("div",{style:{...S,marginBottom:0},children:"Columns to Export"}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("button",{onClick:()=>c(new Set(a.map(v=>v.key))),style:w,children:"All"}),t.jsx("span",{style:{color:"#d1d5db"},children:"|"}),t.jsx("button",{onClick:()=>c(new Set(r)),style:w,children:"Default"}),t.jsx("span",{style:{color:"#d1d5db"},children:"|"}),t.jsx("button",{onClick:()=>c(new Set),style:{...w,color:"#ef4444"},children:"None"})]})]}),t.jsx("div",{style:{marginBottom:8},children:t.jsx("input",{type:"text",placeholder:"Search fields...",value:y,onChange:v=>z(v.target.value),style:{width:"100%",padding:"7px 10px",borderRadius:8,border:"1px solid #e5e7eb",fontSize:12,boxSizing:"border-box",background:"#f9fafb"}})}),t.jsx("div",{style:{border:"1px solid #e5e7eb",borderRadius:8,padding:12,maxHeight:170,overflowY:"auto"},children:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gap:"10px 12px"},children:i.map(v=>t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:7,fontSize:13,color:"#374151",cursor:"pointer",padding:"3px 5px",borderRadius:5,background:b.has(v.key)?"#f0fdf4":"transparent"},children:[t.jsx("input",{type:"checkbox",checked:b.has(v.key),onChange:()=>h(v.key),style:{accentColor:mn,cursor:"pointer"}}),v.label]},v.key))})}),t.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:6},children:[b.size," of ",a.length," fields selected"]})]})]}),t.jsxs("div",{style:{padding:"14px 22px",borderTop:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[t.jsxs("span",{style:{fontSize:12,color:"#888"},children:["Exporting ",C.length," ",p==="selected"?"selected":p==="page"?"page":""," row",C.length!==1?"s":""]}),t.jsxs("div",{style:{display:"flex",gap:10},children:[t.jsx("button",{onClick:d,style:{padding:"9px 18px",borderRadius:8,border:"1px solid #e5e7eb",background:"white",color:"#374151",fontWeight:600,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:"Cancel"}),t.jsx("button",{onClick:x,disabled:g.length===0||C.length===0,style:{padding:"9px 20px",borderRadius:8,border:"none",background:mn,color:"white",fontWeight:700,fontSize:13,cursor:g.length===0||C.length===0?"not-allowed":"pointer",opacity:g.length===0||C.length===0?.5:1,fontFamily:"inherit",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"})]})]})]})})}const sh="sidrah_rtl",od="sidrah-lang-change";function jl(){try{return localStorage.getItem(sh)==="1"}catch{return!1}}function lh(){const e=!jl();try{localStorage.setItem(sh,e?"1":"0")}catch{}document.documentElement.setAttribute("dir",e?"rtl":"ltr"),document.documentElement.setAttribute("lang",e?"ar":"en-GB"),window.dispatchEvent(new CustomEvent(od))}function se(){const[e,n]=_.useState(jl);return _.useEffect(()=>{const s=()=>n(jl());return window.addEventListener(od,s),document.documentElement.setAttribute("dir",jl()?"rtl":"ltr"),document.documentElement.setAttribute("lang",jl()?"ar":"en-GB"),()=>window.removeEventListener(od,s)},[]),e?ky:wy}const wy={rtl:!1,nav:{dashboard:"Dashboard",inbox:"Inbox",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",reports:"Reports",users:"Users",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",settings:"Settings"},pages:{dashboard:"Dashboard",inbox:"Inbox",reports:"Reports",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",users:"Users"},new:"+ New",save:"Save",cancel:"Cancel",edit:"Edit",delete:"Delete",deletedBadge:"DELETED",restore:"Restore",restoring:"Restoring...",restoredOk:"Record restored successfully!",deletedBanner:"⚠️ This record has been deleted",deletedBy:"Deleted by",deletedOn:"Deleted on",deletedReason:"Reason",deleteModal:{title:"Confirm Deletion",subtitle:"Are you sure you want to delete this record?",softDeleteTitle:"Delete",softDeleteDesc:"Moves the record to deleted state. It can be restored later by an Administrator.",permanentDeleteTitle:"Permanent Delete",permanentDeleteDesc:"Permanently removes this record from the database. This action cannot be undone.",reasonLabel:"Reason for deletion (optional):",reasonPlaceholder:"Enter deletion reason…",softDeleteBtn:"Delete",permanentDeleteBtn:"Permanent Delete",cancelBtn:"Cancel",deleting:"Deleting…"},view:"View",back:"← Back",clear:"Clear",search:"Search",loading:"Loading...",saving:"Saving...",savedOk:"Saved successfully!",home:"Home",noRecords:"No records found",login:{subtitle:"Sign in to continue",username:"USERNAME",password:"PASSWORD",usernamePlaceholder:"Enter username",passwordPlaceholder:"Enter password",signIn:"Sign In",signingIn:"Signing in...",invalidCreds:"Invalid username or password",emptyFields:"Please enter username and password",connError:"Connection error: "},myProfile:"My Profile",signOut:"Sign Out",switchLang:"العربية (RTL)",filter:{numberTitle:"Number / Title",searchPlaceholder:"Search...",organization:"Organization",department:"Department",branch:"Branch",status:"Status",allOrgs:"All Organizations",allDepts:"All Departments",allBranches:"All Branches",allStatuses:"All Statuses",allTypes:"All Types"},col:{number:"Number",title:"Title",organization:"Organization",type:"Type",status:"Status",actions:"Actions",name:"Name",department:"Department",branch:"Branch",city:"City",email:"Email",management:"Management",organization_type:"Type",frequency:"Frequency",period:"Period",startDate:"Start Date",endDate:"End Date",auditor:"Auditor",manager:"Manager",functions:"Functions",requestedOn:"Requested On"},field:{number:"Number",title:"Title",organization:"Organization",management:"Management",department:"Department",section:"Section",branch:"Branch",type:"Type",date:"Date",time:"Time",status:"Status",description:"Description",assignedTo:"Assigned To",hsesField:"HSES Field",priority:"Priority",economyClass:"Economy Class",entityScope:"Entity Scope",productRelation:"Product Relation",repeatedEvent:"Repeated Event",solution:"Solution / Action Plan",actualCost:"Actual Cost",summary:"Resolution Summary",auditorComment:"Auditor Comment",incidentClass:"Incident Class",incidentField:"Incident Field",currentCondition:"Current Condition",proposedCondition:"Proposed Condition",ideaClass:"Idea Class",startingDate:"Starting Date",endingDate:"Ending Date",budget:"Budget",currency:"Currency",notes:"Notes",cycle:"Cycle",stage:"Stage",completionPct:"Completion %",actor:"Actor",escalationLevel:"Escalation Level",dateStart:"Start Date",dateEnd:"End Date",cycleType:"Cycle Type",progressIndicators:"Progress Indicators",impactLevel:"Impact Level",kpiName:"KPI Name",kpiType:"KPI Type",kpiMeasure:"KPI Measure",costPerCycle:"Cost per Cycle",chainLocation:"Chain Location",notifyManager:"Notify Manager",creationDate:"Creation Date",statusActive:"Active",statusInactive:"Inactive",name1:"Name",fullName:"Full Name",username:"Username",emailAddress:"Email Address",phoneNumber:"Phone Number",category:"Category",since:"Since",active:"Active",inactive:"Inactive",enabled:"Enabled",selectMgr:"-- Select manager --",select:"-- Select --",eventCategory:"Event Category",selectType:"-- Select type --",selectClass:"-- Select class --",selectField:"-- Select field --",selectStatus:"-- Select status --",solutionPlaceholder:"Describe the solution or action taken…",commentPlaceholder:"Optional comment…",high:"High",normal:"Normal",expenses:"Expenses",capital:"Capital",earn:"Earn",payLoss:"Pay/Loss",upstream:"Upstream",onstream:"On-stream",downstream:"Downstream",government:"Government",private:"Private",linkedOrder:"Linked Order",linkedIdea:"Linked Idea",convertedToOrder:"Converted to Order",originatingIdea:"Originating Idea",viewOrder:"View Order",viewIdea:"View Idea",monthly:"Monthly",quarterly:"Quarterly",yearly:"Yearly",cycleActive:"Active",cycleCompleted:"Completed",cyclePaused:"Paused",updateWindowDays:"Update Window (days)",incidentTriageWindowDays:"Triage Window (days)",incidentResolutionWindowDays:"Resolution Window (days)",orgAcronym:"Acronym",contactEmail:"Contact Email",orgCity:"City",orgName:"Organization Name",organizationType:"Organization Type",revenue_growth:"Revenue Growth (%)",net_profit:"Net Profit",cash_flow:"Cash Flow",strategic_goal_pct:"Strategic Goal (%)",customer_satisfaction:"Customer Satisfaction",employee_turnover_pct:"Employee Turnover (%)",open_safety_incidents:"Open Safety Incidents",compliance_score:"Compliance Score"},wf:{workflow:"Workflow",noActions:"No actions available for your role in this state.",applying:"Applying…",submit:"Submit",assignToManager:"Assign to Manager",reject:"Reject",submitSolution:"Submit Solution",resolutionComplete:"Resolution complete",moveToOutsourcing:"Move to Outsourcing",closeIdea:"Close Idea"},steps:{auditorTriage:"Auditor Triage (Step 2)",managerSolution:"Manager Solution (Step 3)",ownerComment:"Owner / Auditor Comment (Step 4)",auditorEval:"Auditor Evaluation (Step 2)",managerReview:"Manager Review (Step 3)"},formTitle:{newIncident:"New Incident",editIncident:"Edit Incident",viewIncident:"Incident: ",newIdea:"New Idea",editIdea:"Edit Idea",viewIdea:"Idea: ",newOrder:"New Order",editOrder:"Edit Order",viewOrder:"Order: ",newProcess:"New Process",editProcess:"Edit Process",viewProcess:"Process: ",newOrg:"New Organization",editOrg:"Edit Organization",newMgmt:"New Management",editMgmt:"Edit Management",newDept:"New Department",editDept:"Edit Department",newBranch:"New Branch",editBranch:"Edit Branch",newUser:"New User",editUser:"Edit User",viewUser:"User Profile",newCycle:"New Cycle",editCycle:"Edit Cycle",newKpi:"New KPI Input",editKpi:"Edit KPI Input",newDelegation:"New Delegation",viewDelegation:"Delegation: "},saveIncident:"Save Incident",saveIdea:"Save Idea",saveOrder:"Save Order",saveProcess:"Save Process",saveOrg:"Save Organization",saveMgmt:"Save Management",saveDept:"Save Department",saveBranch:"Save Branch",saveUser:"Save User",saveCycle:"Save Cycle",saveKpi:"Save KPI Input",saveDelegation:"Send Delegation",saveName:"Save",dash:{allOrgs:"All organizations",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",level2:"Level 2 — Critical Escalation",level1:"Level 1 — Auditor Review Needed",overduePrefix:"Overdue for Triage — ",overdueSuffix:" incident(s) past 3-day window",untriaged:"Untriaged Incidents",recentKpi:"Recent KPI Inputs",manageKpi:"Manage KPI Inputs",escalatedProcesses:"Escalated Processes",escalatedOrders:"Escalated Orders",level:"Level",revenueGrowth:"Revenue Growth",netProfit:"Net Profit",strategicGoal:"Strategic Goal",customerSat:"Customer Sat.",compliance:"Compliance",safetyInc:"Safety Incidents",total:"Total"},noIncidents:"No incidents found",noIdeas:"No ideas found",noOrders:"No orders found",noProcesses:"No processes found",noUsers:"No users found",noData:"No data found",users:{category:"Category",number:"Number",fullName:"Full Name",username:"Username",email:"Email Address",phone:"Phone Number",organization:"Organization",management:"Management",department:"Department",branch:"Branch",since:"Since",status:"Status",tools:"Tools",active:"Active",inactive:"Inactive",setPassword:"Set Password",newPassword:"New password",passwordUpdated:"Password updated!",passwordFailed:"Failed. Please try again.",disableConfirm:"Delete user? They will no longer appear in the list.",password:"Password"},inbox:{title:"Inbox",noMessages:"No messages"},reports:{title:"Reports",selectOrg:"Select Organization",generate:"Generate Report"},comments:{title:"Comments",placeholder:"Write a comment…",post:"Post",noComments:"No comments yet."},activity:{title:"Activity Log",created:"Created",by:"by"}},ky={rtl:!0,nav:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",reports:"التقارير",users:"المستخدمون",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",settings:"الإعدادات"},pages:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",reports:"التقارير",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",users:"المستخدمون"},new:"+ جديد",save:"حفظ",cancel:"إلغاء",edit:"تعديل",delete:"حذف",deletedBadge:"محذوف",restore:"استعادة",restoring:"جارٍ الاستعادة...",restoredOk:"تمت استعادة السجل بنجاح!",deletedBanner:"⚠️ هذا السجل محذوف",deletedBy:"تم الحذف بواسطة",deletedOn:"تاريخ الحذف",deletedReason:"السبب",deleteModal:{title:"تأكيد الحذف",subtitle:"هل أنت متأكد من رغبتك في حذف هذا السجل؟",softDeleteTitle:"حذف",softDeleteDesc:"يتم نقل السجل إلى سلة المحذوفات. يمكن للمسؤول استعادته لاحقاً.",permanentDeleteTitle:"حذف نهائي",permanentDeleteDesc:"حذف السجل نهائياً من قاعدة البيانات. لا يمكن التراجع عن هذا الإجراء.",reasonLabel:"سبب الحذف (اختياري):",reasonPlaceholder:"أدخل سبب الحذف…",softDeleteBtn:"حذف",permanentDeleteBtn:"حذف نهائي",cancelBtn:"إلغاء",deleting:"جارٍ الحذف…"},view:"عرض",back:"رجوع →",clear:"مسح",search:"بحث",loading:"جارٍ التحميل...",saving:"جارٍ الحفظ...",savedOk:"تم الحفظ بنجاح!",home:"الرئيسية",noRecords:"لا توجد سجلات",login:{subtitle:"تسجيل الدخول للمتابعة",username:"اسم المستخدم",password:"كلمة المرور",usernamePlaceholder:"أدخل اسم المستخدم",passwordPlaceholder:"أدخل كلمة المرور",signIn:"تسجيل الدخول",signingIn:"جارٍ تسجيل الدخول...",invalidCreds:"اسم المستخدم أو كلمة المرور غير صحيحة",emptyFields:"الرجاء إدخال اسم المستخدم وكلمة المرور",connError:"خطأ في الاتصال: "},myProfile:"ملفي الشخصي",signOut:"تسجيل الخروج",switchLang:"English (LTR)",filter:{numberTitle:"الرقم / العنوان",searchPlaceholder:"بحث...",organization:"المؤسسة",department:"القسم",branch:"الفرع",status:"الحالة",allOrgs:"جميع المؤسسات",allDepts:"جميع الأقسام",allBranches:"جميع الفروع",allStatuses:"جميع الحالات",allTypes:"جميع الأنواع"},col:{number:"الرقم",title:"العنوان",organization:"المؤسسة",type:"النوع",status:"الحالة",actions:"الإجراءات",name:"الاسم",department:"القسم",branch:"الفرع",city:"المدينة",email:"البريد الإلكتروني",management:"الإدارة",organization_type:"النوع",frequency:"التكرار",period:"الفترة",startDate:"تاريخ البدء",endDate:"تاريخ الانتهاء",auditor:"المدقق",manager:"المدير",functions:"الوظائف",requestedOn:"تاريخ الطلب"},field:{number:"الرقم",title:"العنوان",organization:"المؤسسة",management:"الإدارة",department:"القسم",section:"القطاع",branch:"الفرع",type:"النوع",date:"التاريخ",time:"الوقت",status:"الحالة",description:"الوصف",assignedTo:"مُسند إلى",hsesField:"مجال السلامة والصحة",priority:"الأولوية",economyClass:"التصنيف الاقتصادي",entityScope:"نطاق الكيان",productRelation:"علاقة المنتج",repeatedEvent:"حدث متكرر",solution:"الحل / خطة العمل",actualCost:"التكلفة الفعلية",summary:"ملخص الحل",auditorComment:"تعليق المدقق",incidentClass:"تصنيف الحادث",incidentField:"مجال الحادث",currentCondition:"الوضع الراهن",proposedCondition:"الوضع المقترح",ideaClass:"تصنيف الفكرة",startingDate:"تاريخ البدء",endingDate:"تاريخ الانتهاء",budget:"الميزانية",currency:"العملة",notes:"الملاحظات",cycle:"الدورة",stage:"المرحلة",completionPct:"نسبة الاكتمال",actor:"المنفذ",escalationLevel:"مستوى التصعيد",dateStart:"تاريخ البدء",dateEnd:"تاريخ الانتهاء",cycleType:"نوع الدورة",progressIndicators:"مؤشرات التقدم",impactLevel:"مستوى التأثير",kpiName:"اسم المؤشر",kpiType:"نوع المؤشر",kpiMeasure:"قياس المؤشر",costPerCycle:"التكلفة لكل دورة",chainLocation:"موقع السلسلة",notifyManager:"إشعار المدير",creationDate:"تاريخ الإنشاء",statusActive:"نشط",statusInactive:"غير نشط",name1:"الاسم",fullName:"الاسم الكامل",username:"اسم المستخدم",emailAddress:"البريد الإلكتروني",phoneNumber:"رقم الهاتف",category:"الفئة",since:"منذ",active:"نشط",inactive:"غير نشط",enabled:"مفعّل",selectMgr:"-- اختر المدير --",select:"-- اختر --",eventCategory:"فئة الحدث",selectType:"-- اختر النوع --",selectClass:"-- اختر التصنيف --",selectField:"-- اختر المجال --",selectStatus:"-- اختر الحالة --",solutionPlaceholder:"صف الحل أو الإجراء المتخذ…",commentPlaceholder:"تعليق اختياري…",high:"عالي",normal:"عادي",expenses:"مصروفات",capital:"رأس مال",earn:"إيرادات",payLoss:"دفع/خسارة",upstream:"مرحلة المنبع",onstream:"على الخط",downstream:"مرحلة المصب",government:"حكومي",private:"خاص",linkedOrder:"الأمر المرتبط",linkedIdea:"الفكرة المرتبطة",convertedToOrder:"تم التحويل إلى أمر",originatingIdea:"الفكرة الأصلية",viewOrder:"عرض الأمر",viewIdea:"عرض الفكرة",monthly:"شهري",quarterly:"ربع سنوي",yearly:"سنوي",cycleActive:"نشط",cycleCompleted:"مكتمل",cyclePaused:"موقوف",updateWindowDays:"نافذة التحديث (أيام)",incidentTriageWindowDays:"نافذة الفرز (أيام)",incidentResolutionWindowDays:"نافذة الحل (أيام)",orgAcronym:"الاختصار",contactEmail:"البريد الإلكتروني للتواصل",orgCity:"المدينة",orgName:"اسم المؤسسة",organizationType:"نوع المؤسسة",revenue_growth:"نمو الإيرادات (%)",net_profit:"صافي الربح",cash_flow:"التدفق النقدي",strategic_goal_pct:"الهدف الاستراتيجي (%)",customer_satisfaction:"رضا العملاء",employee_turnover_pct:"معدل دوران الموظفين (%)",open_safety_incidents:"حوادث السلامة المفتوحة",compliance_score:"درجة الامتثال"},wf:{workflow:"سير العمل",noActions:"لا توجد إجراءات متاحة لدورك في هذه الحالة.",applying:"جارٍ التطبيق...",submit:"إرسال",assignToManager:"تعيين للمدير",reject:"رفض",submitSolution:"إرسال الحل",resolutionComplete:"اكتمال الحل",moveToOutsourcing:"نقل للاستعانة بمصادر خارجية",closeIdea:"إغلاق الفكرة"},steps:{auditorTriage:"فرز المدقق (الخطوة 2)",managerSolution:"حل المدير (الخطوة 3)",ownerComment:"تعليق المالك / المدقق (الخطوة 4)",auditorEval:"تقييم المدقق (الخطوة 2)",managerReview:"مراجعة المدير (الخطوة 3)"},formTitle:{newIncident:"حادث جديد",editIncident:"تعديل الحادث",viewIncident:"الحادث: ",newIdea:"فكرة جديدة",editIdea:"تعديل الفكرة",viewIdea:"الفكرة: ",newOrder:"طلب جديد",editOrder:"تعديل الطلب",viewOrder:"الطلب: ",newProcess:"عملية جديدة",editProcess:"تعديل العملية",viewProcess:"العملية: ",newOrg:"مؤسسة جديدة",editOrg:"تعديل المؤسسة",newMgmt:"إدارة جديدة",editMgmt:"تعديل الإدارة",newDept:"قسم جديد",editDept:"تعديل القسم",newBranch:"فرع جديد",editBranch:"تعديل الفرع",newUser:"مستخدم جديد",editUser:"تعديل المستخدم",viewUser:"ملف المستخدم",newCycle:"دورة جديدة",editCycle:"تعديل الدورة",newKpi:"مؤشر أداء جديد",editKpi:"تعديل مؤشر الأداء",newDelegation:"تفويض جديد",viewDelegation:"التفويض: "},saveIncident:"حفظ الحادث",saveIdea:"حفظ الفكرة",saveOrder:"حفظ الطلب",saveProcess:"حفظ العملية",saveOrg:"حفظ المؤسسة",saveMgmt:"حفظ الإدارة",saveDept:"حفظ القسم",saveBranch:"حفظ الفرع",saveUser:"حفظ المستخدم",saveCycle:"حفظ الدورة",saveKpi:"حفظ مؤشر الأداء",saveDelegation:"إرسال التفويض",saveName:"حفظ",dash:{allOrgs:"جميع المؤسسات",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",level2:"المستوى 2 — تصعيد حرج",level1:"المستوى 1 — مراجعة المدقق مطلوبة",overduePrefix:"متأخر للفرز — ",overdueSuffix:" حادث(ة) تجاوز نافذة 3 أيام",untriaged:"حوادث غير مفرزة",recentKpi:"مؤشرات الأداء الأخيرة",manageKpi:"إدارة مؤشرات الأداء",escalatedProcesses:"عمليات متصاعدة",escalatedOrders:"طلبات متصاعدة",level:"المستوى",revenueGrowth:"نمو الإيرادات",netProfit:"صافي الربح",strategicGoal:"الهدف الاستراتيجي",customerSat:"رضا العملاء",compliance:"الامتثال",safetyInc:"حوادث السلامة",total:"الإجمالي"},noIncidents:"لا توجد حوادث",noIdeas:"لا توجد أفكار",noOrders:"لا توجد طلبات",noProcesses:"لا توجد عمليات",noUsers:"لا يوجد مستخدمون",noData:"لا توجد بيانات",users:{category:"الفئة",number:"الرقم",fullName:"الاسم الكامل",username:"اسم المستخدم",email:"البريد الإلكتروني",phone:"رقم الهاتف",organization:"المؤسسة",management:"الإدارة",department:"القسم",branch:"الفرع",since:"منذ",status:"الحالة",tools:"الأدوات",active:"نشط",inactive:"غير نشط",setPassword:"تعيين كلمة المرور",newPassword:"كلمة مرور جديدة",passwordUpdated:"تم تحديث كلمة المرور!",passwordFailed:"فشل. الرجاء المحاولة مرة أخرى.",disableConfirm:"حذف المستخدم؟ لن يظهر في القائمة بعد الآن.",password:"كلمة المرور"},inbox:{title:"البريد الوارد",noMessages:"لا توجد رسائل"},reports:{title:"التقارير",selectOrg:"اختر المؤسسة",generate:"إنشاء التقرير"},comments:{title:"التعليقات",placeholder:"اكتب تعليقاً…",post:"نشر",noComments:"لا توجد تعليقات بعد."},activity:{title:"سجل النشاط",created:"أُنشئ",by:"بواسطة"}};function Cu({isOpen:e,doctype:n,docname:s,docTitle:l,isAdmin:a,isDeleting:r,onClose:o,onConfirmSoftDelete:d,onConfirmPermanentDelete:p}){const f=se(),[k,j]=_.useState("");if(_.useEffect(()=>{e&&j("")},[e]),_.useEffect(()=>{const c=y=>{y.key==="Escape"&&e&&!r&&o()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e,r,o]),!e)return null;const b=n.replace(/^SB\s+/,"");return t.jsx("div",{style:{position:"fixed",inset:0,zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:"12px",backgroundColor:"rgba(15, 23, 42, 0.6)",backdropFilter:"blur(3px)",animation:"fadeIn 0.15s ease"},onClick:c=>{c.target===c.currentTarget&&!r&&o()},children:t.jsxs("div",{className:"delete-modal-card",style:{background:"white",borderRadius:12,boxShadow:"0 20px 35px -10px rgba(0, 0, 0, 0.22)",maxWidth:390,width:"100%",padding:"16px 18px",boxSizing:"border-box",position:"relative",animation:"scaleIn 0.15s ease",border:"1px solid rgba(226, 232, 240, 0.9)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:12},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"#fee2e2",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#ef4444"},children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M3 6h18m-2 0v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6m3 0V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),t.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),t.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("h3",{style:{margin:0,fontSize:14,fontWeight:700,color:"#1e293b"},children:f.deleteModal.title}),t.jsx("p",{style:{margin:"2px 0 0",fontSize:11,color:"#64748b",lineHeight:1.3},children:f.deleteModal.subtitle})]}),t.jsx("button",{type:"button",onClick:o,disabled:r,style:{background:"transparent",border:"none",color:"#94a3b8",cursor:"pointer",padding:"2px 4px",borderRadius:4,fontSize:14,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"✕"})]}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:6,padding:"6px 10px",marginBottom:12,display:"flex",alignItems:"center",gap:6},children:[t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.4px",flexShrink:0},children:[b,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#1e293b",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l?`${l} (${s})`:s})]}),t.jsxs("div",{style:{marginBottom:14},children:[t.jsx("label",{style:{display:"block",fontSize:11,fontWeight:600,color:"#475569",marginBottom:4},children:f.deleteModal.reasonLabel}),t.jsx("input",{type:"text",value:k,onChange:c=>j(c.target.value),placeholder:f.deleteModal.reasonPlaceholder,disabled:r,style:{width:"100%",height:30,padding:"4px 8px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:12,boxSizing:"border-box",outline:"none"},onFocus:c=>{c.target.style.borderColor="#6366f1",c.target.style.boxShadow="0 0 0 2px rgba(99, 102, 241, 0.15)"},onBlur:c=>{c.target.style.borderColor="#cbd5e1",c.target.style.boxShadow="none"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"row",justifyContent:"flex-end",gap:8,flexWrap:"wrap"},children:[t.jsx("button",{type:"button",onClick:o,disabled:r,style:{padding:"5px 12px",borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#475569",fontSize:12,fontWeight:600,cursor:r?"not-allowed":"pointer",transition:"background 0.15s"},children:f.deleteModal.cancelBtn}),t.jsxs("button",{type:"button",onClick:()=>d(k),disabled:r,title:f.deleteModal.softDeleteDesc,style:{padding:"5px 12px",borderRadius:6,border:"1px solid #fca5a5",background:"#fff1f2",color:"#b91c1c",fontSize:12,fontWeight:600,cursor:r?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:4,transition:"all 0.15s"},onMouseEnter:c=>{r||(c.currentTarget.style.background="#fee2e2")},onMouseLeave:c=>{r||(c.currentTarget.style.background="#fff1f2")},children:[t.jsx("span",{children:"🗑️"}),r?f.deleteModal.deleting:f.deleteModal.softDeleteBtn]}),a&&t.jsxs("button",{type:"button",onClick:()=>p(k),disabled:r,title:f.deleteModal.permanentDeleteDesc,style:{padding:"5px 12px",borderRadius:6,border:"none",background:"#ef4444",color:"#ffffff",fontSize:12,fontWeight:600,cursor:r?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:4,boxShadow:"0 1px 3px rgba(239, 68, 68, 0.25)",transition:"all 0.15s"},onMouseEnter:c=>{r||(c.currentTarget.style.background="#dc2626")},onMouseLeave:c=>{r||(c.currentTarget.style.background="#ef4444")},children:[t.jsx("span",{children:"💥"}),r?f.deleteModal.deleting:f.deleteModal.permanentDeleteBtn]})]})]})})}const ah="/assets/logo-BlYgMyx5.png";function rh({collapsed:e,onToggleCollapsed:n,activePage:s,onNavigate:l,hasDashboard:a,hasReports:r,hasDelegations:o,role:d,hideSettings:p,rtl:f,navLabels:k,settingsLabel:j}){const b=p?[]:dy(d);return t.jsxs("div",{style:{width:e?60:230,background:"linear-gradient(180deg, #0f172a 0%, #1e1b4b 60%, #0b0f19 100%)",color:"white",flexShrink:0,display:"flex",flexDirection:"column",position:"sticky",top:0,height:"100vh",transition:"width 0.22s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden",boxShadow:"2px 0 12px rgba(0, 0, 0, 0.15)",borderRight:"1px solid rgba(255, 255, 255, 0.06)",zIndex:40},children:[t.jsxs("div",{style:{padding:e?"16px 0":"16px 16px 14px",borderBottom:"1px solid rgba(255, 255, 255, 0.08)",display:"flex",alignItems:"center",justifyContent:e?"center":"space-between",gap:8,flexShrink:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,overflow:"hidden"},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"white",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,boxShadow:"0 2px 8px rgba(0, 0, 0, 0.25)",padding:3,boxSizing:"border-box",overflow:"hidden"},children:t.jsx("img",{src:ah,alt:"Logo",style:{width:"100%",height:"100%",objectFit:"contain"},onError:c=>{c.currentTarget.style.display="none"}})}),!e&&t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:t.jsx("span",{style:{fontSize:14,fontWeight:800,whiteSpace:"nowrap",color:"#ffffff",letterSpacing:"-0.2px"},children:f?"صدرة للأعمال":"Sidrah"})})]}),t.jsx("button",{type:"button",onClick:n,title:e?f?"توسيع":"Expand":f?"طي":"Collapse",style:{background:"rgba(255, 255, 255, 0.06)",border:"1px solid rgba(255, 255, 255, 0.1)",borderRadius:6,color:"rgba(255, 255, 255, 0.75)",cursor:"pointer",fontSize:11,padding:"4px 7px",flexShrink:0,lineHeight:1,transition:"all 0.15s ease"},onMouseEnter:c=>{c.currentTarget.style.background="rgba(255, 255, 255, 0.15)",c.currentTarget.style.color="#ffffff"},onMouseLeave:c=>{c.currentTarget.style.background="rgba(255, 255, 255, 0.06)",c.currentTarget.style.color="rgba(255, 255, 255, 0.75)"},children:e?"▶":"✕"})]}),t.jsxs("nav",{style:{padding:"12px 8px",flex:1,overflowY:"auto",overflowX:"hidden"},children:[iy.filter(({id:c})=>(c!=="dashboard"||a)&&(c!=="reports"||r)&&(c!=="delegations"||o)).map(({id:c,icon:y})=>{const z=k[c]||c,C=c===s;return t.jsxs("div",{onClick:()=>l(c),title:e?z:void 0,className:"sidebar-nav-item",style:{padding:e?"8px 0":"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:10,background:C?"rgba(99, 102, 241, 0.28)":"transparent",border:C?"1px solid rgba(129, 140, 248, 0.35)":"1px solid transparent",borderRadius:8,fontSize:e?15:13,color:C?"#ffffff":"rgba(255, 255, 255, 0.78)",fontWeight:C?600:400,transition:"all 0.15s ease",whiteSpace:"nowrap",marginBottom:2,position:"relative"},onMouseEnter:g=>{C||(g.currentTarget.style.background="rgba(255, 255, 255, 0.08)",g.currentTarget.style.color="#ffffff")},onMouseLeave:g=>{C||(g.currentTarget.style.background="transparent",g.currentTarget.style.color="rgba(255, 255, 255, 0.78)")},children:[t.jsx("span",{style:{flexShrink:0,fontSize:e?15:13},children:y}),!e&&t.jsx("span",{children:z})]},c)}),b.length>0&&t.jsxs(t.Fragment,{children:[!e&&t.jsx("div",{style:{padding:"12px 12px 4px",fontSize:10,color:"rgba(255, 255, 255, 0.45)",fontWeight:700,letterSpacing:"0.8px",textTransform:"uppercase",marginTop:8},children:j}),e&&t.jsx("div",{style:{margin:"10px auto",width:26,borderTop:"1px solid rgba(255, 255, 255, 0.12)"}}),b.map(({id:c,icon:y})=>{const z=k[c]||c,C=c===s;return t.jsxs("div",{onClick:()=>l(c),title:e?z:void 0,className:"sidebar-nav-item",style:{padding:e?"8px 0":"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:10,background:C?"rgba(99, 102, 241, 0.28)":"transparent",border:C?"1px solid rgba(129, 140, 248, 0.35)":"1px solid transparent",borderRadius:8,fontSize:e?15:13,color:C?"#ffffff":"rgba(255, 255, 255, 0.78)",fontWeight:C?600:400,transition:"all 0.15s ease",whiteSpace:"nowrap",marginBottom:2},onMouseEnter:g=>{C||(g.currentTarget.style.background="rgba(255, 255, 255, 0.08)",g.currentTarget.style.color="#ffffff")},onMouseLeave:g=>{C||(g.currentTarget.style.background="transparent",g.currentTarget.style.color="rgba(255, 255, 255, 0.78)")},children:[t.jsx("span",{style:{flexShrink:0,fontSize:e?15:13},children:y}),!e&&t.jsx("span",{children:z})]},c)})]})]})]})}const Bl=new Set(["SB Incident","SB Idea","SB Order","SB Process","SB Organization","SB Cycle","SB KPI Input","Managements","Department","Branch","Incident Types","Idea Types","Order Types","Process Types","Incident Class","Incident Field","Incident Statuses","Idea Statuses","Order Statuses","Process Statuses","SB Group Company"]);let Ns="";async function rc(){try{const e=await fetch(`${he}/api/method/sidrah_business.api.get_csrf_token`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(e.ok){const s=(await e.json()).message||"";if(s)return Ns=s,s}}catch(e){console.error("CSRF fetch error:",e)}return Ns}async function un(){return Ns||await rc(),Ns}function Ra(e,n){try{if(e!=null&&e._server_messages){const l=JSON.parse(e._server_messages);if(l.length){const a=JSON.parse(l[0]);if(a!=null&&a.message)return a.message.replace(/<[^>]+>/g,"").trim()}}}catch{}let s=(e==null?void 0:e.message)||(e==null?void 0:e.exception)||(e==null?void 0:e.exc)||n;if(typeof s=="string"&&s.includes("frappe.exceptions.")){const l=s.split(` `).map(r=>r.trim()).filter(r=>r&&!r.startsWith("Traceback")&&!r.startsWith("File "));s=(l[l.length-1]||s).replace(/^frappe\.exceptions\.\w+:\s*/,"").trim()}return s||n}async function Dt(e,n,s=[]){if(Bl.has(e)){const o=`${he}/api/method/sidrah_business.api.get_sb_doc?doctype=${encodeURIComponent(e)}&name=${encodeURIComponent(n)}`,d=await fetch(o,{credentials:"include",headers:{Accept:"application/json"}});if(!d.ok)throw new Error(`API Error: ${d.status}`);return(await d.json()).message}const l=s.length?`?fields=${encodeURIComponent(JSON.stringify(s))}`:"",a=await fetch(`${he}/api/v1/resource/${e}/${encodeURIComponent(n)}${l}`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(!a.ok)throw new Error(`API Error: ${a.status}`);return(await a.json()).data}async function dd(e,n,s="",l=!1){const a=await un();if(Bl.has(e)){const d=new URLSearchParams({doctype:e,name:n});s&&d.append("reason",s),l&&d.append("permanent","1");const p=await fetch(`${he}/api/method/sidrah_business.api.delete_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":a},body:d.toString()});if(!p.ok){const f=await p.json().catch(()=>({}));throw new Error(Ra(f,`Error deleting ${n}`))}return}const r=new URLSearchParams({doctype:e,name:n});s&&r.append("reason",s),l&&r.append("permanent","1");const o=await fetch(`${he}/api/method/sidrah_business.soft_delete.soft_delete`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":a},body:r.toString()});if(!o.ok){const d=await o.json().catch(()=>({}));throw new Error(Ra(d,`Error deleting ${n}`))}return await o.json()}async function Cy(e,n){const s=await un();if(Bl.has(e)){const r=new URLSearchParams({doctype:e,name:n}),o=await fetch(`${he}/api/method/sidrah_business.api.restore_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:r.toString()});if(!o.ok){const p=await o.json().catch(()=>({}));throw new Error(Ra(p,`Error restoring ${n}`))}return(await o.json()).message||{success:!0}}const l=new URLSearchParams({doctype:e,name:n}),a=await fetch(`${he}/api/method/sidrah_business.soft_delete.restore_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:l.toString()});if(!a.ok){const r=await a.json().catch(()=>({}));throw new Error(Ra(r,`Error restoring ${n}`))}return await a.json()}async function Pe(e){if(Bl.has(e))try{const l=`${he}/api/method/sidrah_business.api.get_sb_list?doctype=${encodeURIComponent(e)}&limit=500`,a=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return a.ok?(await a.json()).message||[]:[]}catch{return[]}const n=encodeURIComponent('["*"]'),s=`${he}/api/v1/resource/${e}?limit_page_length=500&fields=${n}`;try{const l=await fetch(s,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return l.status===401||l.status===403?[]:l.ok?(await l.json()).data||[]:[]}catch(l){return console.error("Get error:",l),[]}}async function Jr(e,n){const s=await un();if(Bl.has(e)){const a=new URLSearchParams({doctype:e,data_json:JSON.stringify(n)}),r=await fetch(`${he}/api/method/sidrah_business.api.create_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:a.toString()});if(!r.ok){const d=await r.json().catch(()=>({}));throw new Error(d.message||d.exc||`Error creating ${e}`)}return{data:(await r.json()).message}}const l=`${he}/api/v1/resource/${e}`;try{const a=await fetch(l,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":s},body:JSON.stringify(n)});if(a.status===401||a.status===403)throw new Error("Permission denied - login required");if(!a.ok){const r=await a.json();throw new Error(r.message||r.exc||`API Error: ${a.status}`)}return await a.json()}catch(a){throw console.error("Post error:",a),a}}async function Vr(e,n,s){const l=await un();if(Bl.has(e)){const r=new URLSearchParams({doctype:e,name:n,data_json:JSON.stringify(s)}),o=await fetch(`${he}/api/method/sidrah_business.api.update_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":l},body:r.toString()});if(!o.ok){const p=await o.json().catch(()=>({}));throw new Error(p.message||p.exc||`Error updating ${e}`)}return{data:(await o.json()).message}}const a=`${he}/api/v1/resource/${e}/${encodeURIComponent(n)}`;try{const r=await fetch(a,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":l},body:JSON.stringify(s)});if(r.status===401||r.status===403)throw new Error("Permission denied - login required");if(!r.ok){const o=await r.json();throw new Error(o.message||"Update Error")}return await r.json()}catch(r){throw console.error("Update error:",r),r}}async function zy(){const e=`${he}/api/v1/resource/User?limit_page_length=500&fields=["name","full_name"]`;try{const n=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return n.status===401||n.status===403?[]:n.ok?(await n.json()).data||[]:[]}catch(n){return console.error("Get users error:",n),[]}}async function Iy(e,n){const s=new FormData;s.append("usr",e),s.append("pwd",n);const a=await(await fetch(`${he}/api/method/login`,{method:"POST",credentials:"include",body:s})).json();return a.csrf_token?Ns=a.csrf_token:await rc(),a}async function Ty(){const e=await un();try{await fetch(`${he}/api/method/logout`,{method:"POST",credentials:"include",headers:{"X-Frappe-CSRF-Token":e,Accept:"application/json"}})}catch{}Ns=""}function Ey(){return Ns}async function ih(){try{const e=await fetch(`${he}/api/method/frappe.auth.get_logged_user`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return e.ok&&(await e.json()).message||""}catch{return""}}async function Ay(){const e=JSON.stringify([["name","not in",["Administrator","Guest"]]]),n=`${he}/api/v1/resource/User?limit_page_length=500&fields=${encodeURIComponent('["*"]')}&filters=${encodeURIComponent(e)}`;try{const s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).data||[]:[]}catch{return[]}}async function Py(){const e=`${he}/api/method/sidrah_business.api.get_user_role_map`;try{const n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||{}:{}}catch{return{}}}async function oh(e,n){await Vr("User",e,{new_password:n})}async function Ry(e=20){try{const n=`${he}/api/method/sidrah_business.api.get_notifications?limit=${e}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function Dy(){const e=await un();try{await fetch(`${he}/api/method/sidrah_business.api.mark_notifications_read`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":e}})}catch{}}async function Oy(e){const n=await un();try{await fetch(`${he}/api/method/sidrah_business.api.mark_notification_read`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":n},body:new URLSearchParams({name:e}).toString()})}catch{}}async function Ly(e){const n=await un(),s=new URLSearchParams({name:e});await fetch(`${he}/api/method/sidrah_business.api.disable_user`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":n},body:s.toString()})}async function Ny(e,n){try{const s=`${he}/api/method/sidrah_business.api.get_doc_comments?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(n)}`,l=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function Wy(e,n,s){const l=await un(),a=new URLSearchParams({doctype:e,docname:n,content:s}),r=await fetch(`${he}/api/method/sidrah_business.api.post_doc_comment`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":l},body:a.toString()});if(!r.ok)throw new Error("Failed to post comment");return(await r.json()).message}async function By(e,n){try{const s=`${he}/api/method/sidrah_business.api.get_doc_versions?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(n)}`,l=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function dh(e){try{const n=`${he}/api/method/sidrah_business.api.get_user_roles?user=${encodeURIComponent(e)}`,s=await fetch(n,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function $y(){try{const e=`${he}/api/method/sidrah_business.api.get_my_organization`,n=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return n.ok&&(await n.json()).message||""}catch{return""}}async function $s(e,n={}){const s=await un(),l=new URLSearchParams(n),a=await fetch(`${he}/api/method/sidrah_business.api.${e}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:l.toString()});if(!a.ok){const o=await a.json().catch(()=>({}));throw new Error(Ra(o,`Error calling ${e}`))}return(await a.json()).message}async function Uy(e,n,s="",l,a,r){const o={name:e,action:n,comment:s};return l!==void 0&&(o.stage=l),r!==void 0&&(o.cycle_status=r),$s("apply_order_workflow",o)}async function My(e,n,s=""){return $s("apply_incident_workflow",{name:e,action:n,fields_json:s})}async function Fy(e,n,s=""){return $s("apply_idea_workflow",{name:e,action:n,fields_json:s})}async function Hy(e=""){const n=`${he}/api/method/sidrah_business.api.get_dashboard_data${e?`?organization=${encodeURIComponent(e)}`:""}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||{}:{escalated_processes:[],escalated_orders:[],untriaged_incidents:[],kpi_inputs:[]}}async function Gy(e,n={}){return $s("get_report_data",{report_name:e,filters_json:JSON.stringify(n)})}async function Qy(){try{const e=`${he}/api/method/sidrah_business.api.get_inbox_items`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function Ky(e,n,s="",l="",a="",r=""){return $s("create_delegation",{manager:e,functions_json:JSON.stringify(n),organization:s,remarks:l,incident_name:a,idea_name:r})}async function Yy(e,n,s=""){return $s("respond_to_delegation",{name:e,response:n,remarks:s})}async function Xy(e,n=""){return $s("revoke_delegation",{name:e,remarks:n})}async function qy(){try{const e=`${he}/api/method/sidrah_business.api.get_delegations`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function Jy(e){const n=`${he}/api/method/sidrah_business.api.get_delegation?name=${encodeURIComponent(e)}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});if(!s.ok)throw new Error("Failed to load delegation");return(await s.json()).message}async function Vy(){try{const e=`${he}/api/method/sidrah_business.api.get_my_delegated_functions`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function Zy(){try{const e=`${he}/api/method/sidrah_business.api.get_my_delegated_organizations`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||{}:{}}catch{return{}}}async function e0(){try{const e=await un(),n=await fetch(`${he}/api/method/sidrah_business.api.get_group_companies`,{method:"GET",credentials:"include",headers:{Accept:"application/json","X-Frappe-CSRF-Token":e}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function t0(){const e=Ey();return e||rc()}async function aa(e){const n=await fetch(`${he}/api/method/sidrah_business.api.get_process?name=${encodeURIComponent(e)}`,{credentials:"include",headers:{Accept:"application/json"}});if(!n.ok){const l=await n.json().catch(()=>({}));throw new Error(l.message||`Failed to load process (${n.status})`)}const s=await n.json();return s.message||s.data}async function n0(e,n,s={}){const l=await t0(),a=new URLSearchParams({name:e,action:n});s.actor_status&&a.set("actor_status",String(s.actor_status)),s.actor_comment&&a.set("actor_comment",String(s.actor_comment)),s.progress_indicators&&a.set("progress_indicators",JSON.stringify(s.progress_indicators));const r=await fetch(`${he}/api/method/sidrah_business.api.apply_process_workflow`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":l},body:a.toString()});if(!r.ok){const d=await r.json().catch(()=>({})),p=d.message||(d.exception?String(d.exception).split(` `).pop():"")||d.exc_type||`Workflow action "${n}" failed (${r.status})`;throw new Error(p)}const o=await r.json();return o.message||o.data}const s0=["dashboard","incidents","incidents-form","ideas","ideas-form","orders","orders-form","processes","processes-form","processes-workflow","organizations","organizations-form","managements","managements-form","departments","departments-form","branches","branches-form","incident-types","incident-types-form","idea-types","idea-types-form","order-types","order-types-form","process-types","process-types-form","incident-statuses","incident-statuses-form","idea-statuses","idea-statuses-form","order-statuses","order-statuses-form","process-statuses","process-statuses-form","users","users-form","cycles","cycles-form","kpi-input","kpi-input-form","delegations","delegations-form","inbox","reports","profile"],zu=new Set(s0),l0={"incidents-form":"incidents","ideas-form":"ideas","orders-form":"orders","processes-form":"processes","processes-workflow":"processes","organizations-form":"organizations","managements-form":"managements","departments-form":"departments","branches-form":"branches","incident-types-form":"incident-types","idea-types-form":"idea-types","order-types-form":"order-types","process-types-form":"process-types","incident-statuses-form":"incident-statuses","idea-statuses-form":"idea-statuses","order-statuses-form":"order-statuses","process-statuses-form":"process-statuses","users-form":"users","cycles-form":"cycles","kpi-input-form":"kpi-input","delegations-form":"delegations",profile:"dashboard"};function Iu(){const e=window.location.hash.replace(/^#\/?/,"");if(e)return zu.has(e)?e:null;const n=window.location.pathname.split("/").filter(Boolean).pop()||"";return zu.has(n)?n:null}function a0(e){return e?l0[e]??e:null}function r0(e){return`#/${e}`}function i0({onLogin:e}){const n=se(),[s,l]=_.useState(""),[a,r]=_.useState(""),[o,d]=_.useState(""),[p,f]=_.useState(!1),[k,j]=_.useState(!1),[b,c]=_.useState(!1),y=async()=>{if(!s||!a){d(n.login.emptyFields);return}f(!0),d("");try{const C=await Iy(s,a);if(C.message==="Logged In"){const i=await ih()||s,h=await dh(i),x=h.some(S=>["SB Admin","System Manager"].includes(S))?"Admin":h.includes("SB Auditor")?"Auditor":h.includes("SB Owner")?"Owner":h.includes("SB X-Auditor")?"XAuditor":h.includes("SB Manager")?"Manager":"Employee";e({name:i,full_name:C.full_name||s,role:x})}else d(n.login.invalidCreds)}catch(C){d(n.login.connError+(C instanceof Error?C.message:"Unknown"))}f(!1)},z=C=>({width:"100%",padding:"11px 16px",border:`1.5px solid ${C?"#6366f1":"#e2e8f0"}`,borderRadius:8,fontSize:14,background:C?"#f8faff":"#ffffff",color:"#1e293b",outline:"none",transition:"all 0.18s ease",boxSizing:"border-box",boxShadow:C?"0 0 0 3px rgba(99, 102, 241, 0.15)":"none"});return t.jsx("div",{style:{minHeight:"100vh",background:"#f8fafc",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Segoe UI, system-ui, sans-serif",padding:"20px"},children:t.jsxs("div",{style:{width:380,maxWidth:"100%",display:"flex",flexDirection:"column",alignItems:"center"},children:[t.jsx("div",{style:{width:72,height:72,borderRadius:18,background:"white",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:20,boxShadow:"0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04)",border:"1px solid #f1f5f9",overflow:"hidden",padding:10},children:t.jsx("img",{src:ah,alt:"Logo",style:{width:"100%",height:"100%",objectFit:"contain"},onError:C=>{C.currentTarget.style.display="none"}})}),t.jsxs("div",{style:{textAlign:"center",marginBottom:24},children:[t.jsx("h1",{style:{fontSize:22,fontWeight:800,color:"#0f172a",letterSpacing:"-0.3px",margin:0},children:n.rtl?"صدرة للأعمال":"Sidrah"}),t.jsx("div",{style:{fontSize:13,color:"#6366f1",fontWeight:600,marginTop:4},children:n.rtl?"نظام إدارة العمليات والأعمال":"Asset Management System"}),t.jsx("div",{style:{fontSize:12,color:"#94a3b8",marginTop:6},children:n.login.subtitle})]}),t.jsxs("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:12},children:[t.jsx("div",{children:t.jsx("input",{value:s,onChange:C=>l(C.target.value),onKeyDown:C=>C.key==="Enter"&&y(),onFocus:()=>j(!0),onBlur:()=>j(!1),style:z(k),placeholder:n.login.usernamePlaceholder,autoComplete:"username"})}),t.jsx("div",{children:t.jsx("input",{type:"password",value:a,onChange:C=>r(C.target.value),onKeyDown:C=>C.key==="Enter"&&y(),onFocus:()=>c(!0),onBlur:()=>c(!1),style:z(b),placeholder:n.login.passwordPlaceholder,autoComplete:"current-password"})}),o&&t.jsx("div",{style:{padding:"9px 12px",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:8,color:"#dc2626",fontSize:12,textAlign:"center"},children:o}),t.jsx("button",{type:"button",onClick:y,disabled:p,style:{background:p?"#818cf8":"#4f46e5",color:"white",border:"none",padding:"12px",borderRadius:8,fontSize:14,cursor:p?"not-allowed":"pointer",fontWeight:600,marginTop:4,boxShadow:"0 2px 8px rgba(79, 70, 229, 0.3)",transition:"all 0.18s ease"},onMouseEnter:C=>{p||(C.currentTarget.style.background="#4338ca")},onMouseLeave:C=>{p||(C.currentTarget.style.background="#4f46e5")},children:p?n.login.signingIn:n.login.signIn}),t.jsx("div",{style:{textAlign:"center",marginTop:8},children:t.jsx("button",{type:"button",onClick:lh,style:{fontSize:12,color:"#94a3b8",background:"none",border:"none",cursor:"pointer"},onMouseEnter:C=>C.currentTarget.style.color="#475569",onMouseLeave:C=>C.currentTarget.style.color="#94a3b8",children:n.switchLang})})]})]})})}function o0(e,n){const s=parseInt(e.replace("#",""),16),l=s>>16&255,a=s>>8&255,r=s&255,o=d=>Math.round(d+(255-d)*n);return`rgb(${o(l)}, ${o(a)}, ${o(r)})`}function Zl(e,n){const s=parseInt(e.replace("#",""),16),l=s>>16&255,a=s>>8&255,r=s&255;return`rgba(${l}, ${a}, ${r}, ${n})`}function cr({title:e,data:n,color:s,onSelect:l}){const[,a]=n[0]??["Total",0,""],r=n.slice(1),o=r.map((p,f)=>o0(s,Math.min(f*.16,.7))),d=r.map(([p,f,k],j)=>[p,f,k,o[j]]).filter(([,p])=>p>0);return t.jsxs("div",{className:"status-card",style:{borderRadius:18,padding:"16px 18px 18px",height:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",minWidth:0,position:"relative",overflow:"hidden"},children:[t.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",background:`linear-gradient(160deg, ${Zl(s,.09)} 0%, transparent 55%)`}}),t.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:3,background:`linear-gradient(90deg, ${s}, ${Zl(s,.35)})`}}),t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:14},children:[t.jsx("span",{className:"status-card-title",style:{fontSize:13,fontWeight:700,paddingTop:4},children:e}),t.jsx("span",{style:{fontSize:14,fontWeight:800,color:"white",background:s,lineHeight:1,minWidth:26,textAlign:"center",padding:"6px 9px",borderRadius:10,boxShadow:`0 4px 10px ${Zl(s,.35)}`},children:a})]}),a>0&&t.jsx("div",{style:{display:"flex",height:9,borderRadius:999,overflow:"hidden",background:Zl(s,.1),marginBottom:13},children:d.map(([p,f,k,j],b)=>t.jsx("div",{title:`${p}: ${f}`,onClick:c=>{c.stopPropagation(),l==null||l(k)},style:{flex:`${f} 0 0`,background:j,borderRight:bt.jsxs("div",{className:"status-card-row",onClick:f>0?b=>{b.stopPropagation(),l==null||l(k)}:void 0,style:{display:"flex",alignItems:"center",gap:9,padding:"4px 6px",borderRadius:8,cursor:f>0&&l?"pointer":"default",transition:"background 0.12s"},children:[t.jsx("span",{style:{width:9,height:9,borderRadius:"50%",background:o[j],flexShrink:0,boxShadow:`0 0 0 3px ${Zl(o[j],.18)}`}}),t.jsx("span",{className:"status-card-label",style:{flex:1,fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p}),t.jsx("span",{className:"status-card-count",style:{fontSize:12,fontWeight:700,flexShrink:0},children:f})]},p))})]})}function Vt({value:e,onChange:n,organizations:s,placeholder:l="Select organization...",disabled:a=!1,small:r=!1,userRole:o,onCreateNew:d,onQuickCreateSuccess:p}){var F;const[f,k]=_.useState(!1),[j,b]=_.useState(""),[c,y]=_.useState(!1),[z,C]=_.useState(""),[g,i]=_.useState(""),[h,x]=_.useState(!1),[S,w]=_.useState(""),u=_.useRef(null),v=_.useRef(null);_.useEffect(()=>{const D=E=>{u.current&&!u.current.contains(E.target)&&k(!1)};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]);const I=e?((F=s.find(D=>D.organization_name===e||D.name===e))==null?void 0:F.organization_name)??e:"",G=s.filter(D=>{if(!D)return!1;const E=D;return E.custom_is_deleted===1||E.custom_is_deleted==="1"||E.custom_is_deleted===!0||E.is_deleted===1||E.is_deleted==="1"||E.is_deleted===!0||E.status==="Deleted"||E.custom_status==="Deleted"?!1:!!D.is_active||D.organization_name===e||D.name===e}).filter(D=>{if(!j.trim())return!0;const E=j.toLowerCase().trim();return(D.organization_name||"").toLowerCase().includes(E)||(D.name||"").toLowerCase().includes(E)||(D.acronym||"").toLowerCase().includes(E)}),le=!(o==="Employee"||o==="SB Employee"),U=async D=>{if(D.preventDefault(),!!z.trim()){x(!0),w("");try{const E={organization_name:z.trim(),acronym:g.trim(),is_active:1},A=await Jr("SB Organization",E),M=(A==null?void 0:A.data)||A,Q=(M==null?void 0:M.organization_name)||z.trim();n(Q),p&&p(Q),y(!1),C(""),i("")}catch(E){console.error("Quick create org error:",E),w((E==null?void 0:E.message)||"Failed to create organization. Please try again.")}finally{x(!1)}}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:u,className:`custom-select-container ${a?"disabled":""} ${f?"open":""}`,style:{position:"relative",width:"100%"},children:[t.jsxs("div",{className:`custom-select-trigger ${r?"small":""} ${a?"disabled":""} ${f?"open":""} ${!e&&!j?"is-placeholder":""}`,style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingRight:8},onClick:()=>{a||(f||(k(!0),b("")),setTimeout(()=>{var D;return(D=v.current)==null?void 0:D.focus()},0))},children:[t.jsx("input",{ref:v,type:"text",disabled:a,placeholder:l,value:f?j:I,onChange:D=>{f||k(!0),b(D.target.value)},onFocus:()=>{!a&&!f&&(k(!0),b(""))},style:{border:"none",outline:"none",background:"transparent",width:"100%",fontSize:"inherit",fontFamily:"inherit",color:"inherit",cursor:a?"not-allowed":"text",padding:0}}),e&&!a?t.jsx("span",{title:"Clear selection",style:{cursor:"pointer",color:"#94a3b8",fontSize:14,fontWeight:600,padding:"0 4px",lineHeight:1,userSelect:"none",transition:"color 0.15s ease",flexShrink:0},onClick:D=>{D.stopPropagation(),n(""),b(""),k(!1)},onMouseEnter:D=>D.currentTarget.style.color="#475569",onMouseLeave:D=>D.currentTarget.style.color="#94a3b8",children:"✕"}):t.jsx("span",{className:"trigger-arrow",style:{pointerEvents:"none",flexShrink:0},children:"▼"})]}),f&&t.jsx("div",{className:"custom-select-dropdown",children:t.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[G.length===0&&!le&&t.jsx("div",{className:"custom-select-empty",children:"No matching organizations"}),G.map(D=>t.jsx(d0,{label:D.organization_name,selected:e===D.organization_name||e===D.name,active:!!D.is_active,isPlaceholder:!1,small:r,onClick:()=>{n(D.organization_name),b(""),k(!1)}},D.name)),le&&t.jsxs("div",{style:{borderTop:"1px solid #e2e8f0",color:"#16a34a",fontWeight:700,fontSize:r?12:13,padding:"10px 14px",display:"flex",alignItems:"center",gap:6,cursor:"pointer",background:"#ffffff",transition:"all 0.15s ease"},onClick:()=>{k(!1),d?d():(C(""),i(""),w(""),y(!0))},onMouseEnter:D=>{D.currentTarget.style.background="#f0fdf4"},onMouseLeave:D=>{D.currentTarget.style.background="#ffffff"},children:[t.jsx("span",{style:{fontSize:16,fontWeight:800,color:"#16a34a",lineHeight:1},children:"+"}),t.jsx("span",{children:"Create New Organization"})]})]})})]}),c&&t.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(15, 23, 42, 0.55)",backdropFilter:"blur(3px)",padding:16},onClick:D=>{D.target===D.currentTarget&&!h&&y(!1)},children:t.jsxs("div",{style:{background:"#ffffff",borderRadius:12,boxShadow:"0 20px 40px rgba(0, 0, 0, 0.2)",maxWidth:440,width:"100%",overflow:"hidden",animation:"scaleIn 0.15s ease"},children:[t.jsxs("div",{style:{padding:"16px 20px",borderBottom:"1px solid #f1f5f9",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:16,fontWeight:700,color:"#1e293b"},children:[t.jsx("span",{style:{color:"#2563eb",fontSize:18,fontWeight:800},children:"+"}),t.jsx("span",{children:"Create New Organization"})]}),t.jsx("button",{type:"button",onClick:()=>!h&&y(!1),style:{background:"none",border:"none",color:"#94a3b8",fontSize:18,cursor:"pointer",padding:"2px 6px",borderRadius:4},children:"✕"})]}),t.jsxs("form",{onSubmit:U,style:{padding:"20px"},children:[S&&t.jsx("div",{style:{background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",padding:"8px 12px",borderRadius:6,fontSize:12,marginBottom:14},children:S}),t.jsxs("div",{style:{marginBottom:14},children:[t.jsxs("label",{style:{display:"block",fontSize:12,fontWeight:700,color:"#334155",marginBottom:6},children:["Organization Name ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"text",value:z,onChange:D=>C(D.target.value),placeholder:"Enter organization name",autoFocus:!0,disabled:h,style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:13,boxSizing:"border-box",outline:"none"}})]}),t.jsxs("div",{style:{marginBottom:16},children:[t.jsx("label",{style:{display:"block",fontSize:12,fontWeight:700,color:"#334155",marginBottom:6},children:"Acronym"}),t.jsx("input",{type:"text",value:g,onChange:D=>i(D.target.value),placeholder:"e.g. KAU",disabled:h,style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:13,boxSizing:"border-box",outline:"none"}})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:10,marginTop:22},children:[t.jsx("button",{type:"button",onClick:()=>y(!1),disabled:h,style:{padding:"8px 16px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#475569",fontWeight:600,fontSize:13,cursor:h?"not-allowed":"pointer"},children:"Cancel"}),t.jsxs("button",{type:"submit",disabled:h||!z.trim(),style:{padding:"8px 18px",borderRadius:8,border:"none",background:"#2563eb",color:"#ffffff",fontWeight:700,fontSize:13,cursor:h||!z.trim()?"not-allowed":"pointer",opacity:h||!z.trim()?.6:1,display:"flex",alignItems:"center",gap:6,boxShadow:"0 2px 4px rgba(37, 99, 235, 0.25)"},children:[t.jsx("span",{style:{fontSize:15,fontWeight:800},children:"+"}),t.jsx("span",{children:h?"Creating...":"Create"})]})]})]})]})})]})}function d0({label:e,selected:n,active:s,isPlaceholder:l,small:a,onClick:r}){const[o,d]=_.useState(!1);return t.jsx("div",{onClick:r,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),className:`custom-select-option ${n?"selected":""} ${o?"hovered":""} ${l?"placeholder-option":""} ${s?"":"inactive-option"} ${a?"small":""}`,children:e})}function sn({label:e,icon:n,onClick:s}){return t.jsxs("button",{onClick:s,className:"hero-quicklink-btn",style:{display:"flex",alignItems:"center",gap:8,padding:"7px 14px",background:"rgba(255, 255, 255, 0.12)",border:"1px solid rgba(255, 255, 255, 0.22)",borderRadius:10,cursor:"pointer",backdropFilter:"blur(8px)",color:"white",fontSize:13,fontWeight:700,boxShadow:"0 2px 6px rgba(0,0,0,0.12)",transition:"all 0.18s cubic-bezier(0.4, 0, 0.2, 1)"},children:[t.jsx("span",{style:{fontSize:15,display:"flex",alignItems:"center"},children:n}),t.jsx("span",{style:{whiteSpace:"nowrap"},children:e})]})}function Vn({items:e,type:n,onNavigate:s}){const l=se();if(!e.length)return null;const a=n==="process"?"processes-form":"orders-form",r=n==="process"?l.dash.escalatedProcesses:l.dash.escalatedOrders,o=e.some(d=>d.escalation_level===2||d.escalation_level==="2");return t.jsxs("div",{children:[t.jsxs("h4",{style:{fontWeight:700,fontSize:12,color:o?"#ef4444":"#f59e0b",marginBottom:8,display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{children:o?"🚨":"⚠️"}),t.jsxs("span",{children:[r," (",e.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.map(d=>t.jsxs("div",{onClick:()=>s(a,d.name),className:"dashboard-alert-item",style:{padding:"10px 14px",background:o?"#fef2f2":"#fffbeb",borderRadius:10,border:`1px solid ${o?"#fecaca":"#fed7aa"}`,cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"all 0.15s ease"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[t.jsx("span",{style:{fontWeight:700,fontSize:12,color:o?"#991b1b":"#92400e",whiteSpace:"nowrap"},children:d.number||d.name}),t.jsx("span",{style:{fontSize:12,color:"#475569",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.title})]}),t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:o?"#b91c1c":"#b45309",background:o?"#fee2e2":"#fef3c7",border:`1px solid ${o?"#fca5a5":"#fde68a"}`,padding:"2px 8px",borderRadius:9999,flexShrink:0},children:[l.dash.level," ",d.escalation_level]})]},d.name))})]})}function c0({kpi:e}){const n=se();return t.jsxs("div",{className:"dashboard-kpi-card",style:{borderRadius:14,padding:"16px 18px",border:"1px solid #e2e8f0",background:"white",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",transition:"all 0.2s ease",display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("div",{style:{fontWeight:800,fontSize:14,color:"#1e293b"},children:e.organization}),t.jsx("span",{style:{fontSize:11,fontWeight:700,color:"#4f46e5",background:"#eff6ff",border:"1px solid #c7d2fe",padding:"2px 9px",borderRadius:9999},children:e.period})]}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[{label:n.dash.revenueGrowth,val:e.revenue_growth!=null?`${e.revenue_growth}%`:"—",color:"#10b981"},{label:n.dash.netProfit,val:e.net_profit!=null?e.net_profit.toLocaleString():"—",color:"#3b82f6"},{label:n.dash.strategicGoal,val:e.strategic_goal_pct!=null?`${e.strategic_goal_pct}%`:"—",color:"#8b5cf6"},{label:n.dash.customerSat,val:e.customer_satisfaction!=null?e.customer_satisfaction:"—",color:"#f59e0b"},{label:n.dash.compliance,val:e.compliance_score!=null?e.compliance_score:"—",color:"#06b6d4"},{label:n.dash.safetyInc,val:e.open_safety_incidents!=null?e.open_safety_incidents:"—",color:"#ef4444"}].map(({label:s,val:l,color:a})=>t.jsxs("div",{style:{background:"#f8fafc",padding:"8px 10px",borderRadius:8,border:"1px solid #f1f5f9"},children:[t.jsx("div",{style:{fontSize:10,color:"#64748b",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.3px"},children:s}),t.jsxs("div",{style:{fontSize:14,fontWeight:800,color:"#1e293b",marginTop:2,display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:a}}),l]})]},s))})]})}function u0({data:e}){if(!e.length)return t.jsx("p",{style:{color:"#94a3b8",fontSize:13},children:"No cycle data available for trend chart."});const n=Math.max(...e.map(s=>s.pass+s.fail+s.unknown),1);return t.jsxs("div",{children:[t.jsx("div",{style:{display:"flex",gap:14,alignItems:"flex-end",overflowX:"auto",paddingBottom:8,paddingTop:10},children:e.map(s=>{const l=s.pass+s.fail+s.unknown||1,a=100;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:6,minWidth:54},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column-reverse",gap:2,height:a,width:36,background:"#f1f5f9",borderRadius:6,padding:2,boxSizing:"border-box"},children:[t.jsx("div",{title:`Pass: ${s.pass}`,style:{height:Math.round(s.pass/n*(a-4)),background:"linear-gradient(180deg, #34d399 0%, #10b981 100%)",borderRadius:"4px 4px 0 0",minHeight:s.pass?4:0}}),t.jsx("div",{title:`Fail: ${s.fail}`,style:{height:Math.round(s.fail/n*(a-4)),background:"linear-gradient(180deg, #f87171 0%, #ef4444 100%)",borderRadius:"4px 4px 0 0",minHeight:s.fail?4:0}}),t.jsx("div",{title:`Unknown: ${s.unknown}`,style:{height:Math.round(s.unknown/n*(a-4)),background:"#94a3b8",borderRadius:"4px 4px 0 0",minHeight:s.unknown?4:0}})]}),t.jsx("div",{style:{fontSize:10,fontWeight:600,color:"#64748b",textAlign:"center",lineHeight:1.2},children:s.month.replace(/^(\d{4})-(\d{2})$/,(r,o,d)=>`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][+d-1]} '${o.slice(2)}`)}),t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#10b981",textAlign:"center"},children:l>1?Math.round(s.pass/l*100)+"%":"—"})]},s.month)})}),t.jsx("div",{style:{display:"flex",gap:20,marginTop:12,borderTop:"1px solid #f1f5f9",paddingTop:10},children:[["#10b981","Pass (Verified)"],["#ef4444","Fail (Action Required)"],["#94a3b8","Unknown / Unrecorded"]].map(([s,l])=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,fontWeight:600},children:[t.jsx("div",{style:{width:10,height:10,background:s,borderRadius:3}}),t.jsx("span",{style:{color:"#64748b"},children:l})]},l))})]})}function p0({dashData:e,fi:n,fid:s,fo:l,fp:a,incidentStatuses:r,ideaStatuses:o,orderStatuses:d,processStatuses:p,onNavigate:f,onNavigateStatus:k}){const j=se(),b=(e==null?void 0:e.escalated_processes)||[],c=(e==null?void 0:e.escalated_orders)||[],y=(e==null?void 0:e.attention_processes)||[],z=(e==null?void 0:e.attention_orders)||[],C=(e==null?void 0:e.untriaged_incidents)||[],g=(e==null?void 0:e.overdue_triage)||[],i=b.length>0||c.length>0,h=y.length>0||z.length>0,x=[["Total",n.length,""],...r.map(v=>[v.name1||v.name,n.filter(I=>I.status===v.name).length,v.name])],S=[["Total",s.length,""],...o.map(v=>[v.name1||v.name,s.filter(I=>I.status===v.name).length,v.name])],w=[["Total",l.length,""],...d.map(v=>[v.name1||v.name,l.filter(I=>I.status===v.name).length,v.name])],u=[["Total",a.length,""],...p.map(v=>[v.name1||v.name,a.filter(I=>I.status===v.name).length,v.name])];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsx("div",{onClick:()=>f("incidents"),style:{cursor:"pointer"},children:t.jsx(cr,{title:j.dash.incidents,color:"#ef4444",data:x,onSelect:v=>k("incidents",v)})}),t.jsx("div",{onClick:()=>f("ideas"),style:{cursor:"pointer"},children:t.jsx(cr,{title:j.dash.ideas,color:"#10b981",data:S,onSelect:v=>k("ideas",v)})}),t.jsx("div",{onClick:()=>f("orders"),style:{cursor:"pointer"},children:t.jsx(cr,{title:j.dash.orders,color:"#8b5cf6",data:w,onSelect:v=>k("orders",v)})}),t.jsx("div",{onClick:()=>f("processes"),style:{cursor:"pointer"},children:t.jsx(cr,{title:j.dash.processes,color:"#3b82f6",data:u,onSelect:v=>k("processes",v)})})]}),(i||h)&&t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:16},children:[i&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fee2e2",borderLeft:"5px solid #ef4444"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#ef4444",margin:0},children:j.dash.level2}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,background:"#fef2f2",color:"#ef4444",padding:"2px 8px",borderRadius:9999},children:[b.length+c.length," Critical"]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(Vn,{items:b,type:"process",onNavigate:f}),t.jsx(Vn,{items:c,type:"order",onNavigate:f})]})]}),h&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fef3c7",borderLeft:"5px solid #f59e0b"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#b45309",margin:0},children:j.dash.level1}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,background:"#fffbeb",color:"#b45309",padding:"2px 8px",borderRadius:9999},children:[y.length+z.length," Action Needed"]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(Vn,{items:y,type:"process",onNavigate:f}),t.jsx(Vn,{items:z,type:"order",onNavigate:f})]})]})]}),(g.length>0||C.length>0)&&t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:16},children:[g.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fee2e2",borderLeft:"5px solid #dc2626"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#dc2626",marginBottom:10},children:[j.dash.overduePrefix,g.length,j.dash.overdueSuffix]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:g.map(v=>t.jsxs("div",{onClick:()=>f("incidents-form",v.name),style:{padding:"8px 12px",background:"#fef2f2",borderRadius:8,border:"1px solid #fca5a5",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:12,color:"#991b1b"},children:v.number||v.name}),t.jsx("span",{style:{fontSize:12,color:"#475569"},children:v.title}),t.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:v.date})]},v.name))})]}),C.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #ffedd5",borderLeft:"5px solid #f97316"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#ea580c",marginBottom:10},children:[j.dash.untriaged," (",C.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:C.map(v=>t.jsxs("div",{onClick:()=>f("incidents-form",v.name),style:{padding:"8px 12px",background:"#fff7ed",borderRadius:8,border:"1px solid #fed7aa",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:12,color:"#9a3412"},children:v.number||v.name}),t.jsx("span",{style:{fontSize:12,color:"#475569"},children:v.title}),t.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:v.date})]},v.name))})]})]})]})}function f0({dashData:e,selectedOrg:n,onNavigate:s}){const l=se(),[a,r]=_.useState([]),[o,d]=_.useState([]),[p,f]=_.useState(!1),k=(e==null?void 0:e.escalated_processes)||[],j=(e==null?void 0:e.escalated_orders)||[],b=(e==null?void 0:e.attention_processes)||[],c=(e==null?void 0:e.attention_orders)||[],y=(e==null?void 0:e.kpi_inputs)||[];_.useEffect(()=>{f(!0);const g=new URLSearchParams({months:"6"});n&&g.append("organization",n),fetch(`/api/method/sidrah_business.api.get_process_trend?${g}`,{credentials:"include",headers:{Accept:"application/json"}}).then(i=>i.json()).then(i=>{const h=i.message||[],x={};for(const S of h)x[S.month]||(x[S.month]={pass:0,fail:0,unknown:0}),S.status==="Pass"?x[S.month].pass=S.count:S.status==="Fail"?x[S.month].fail=S.count:S.status==="Unknown"&&(x[S.month].unknown=S.count);r(Object.entries(x).map(([S,w])=>({month:S,...w})))}).catch(()=>{}).finally(()=>f(!1))},[n]),_.useEffect(()=>{fetch("/api/method/sidrah_business.api.get_report_data",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":window.csrf_token||""},body:JSON.stringify({report_name:"user_activity_log",filters_json:"{}"})}).then(g=>g.json()).then(g=>{var i;d((((i=g.message)==null?void 0:i.rows)||[]).slice(0,50))}).catch(()=>{})},[n]);const z=k.length>0||j.length>0,C=b.length>0||c.length>0;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[y.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"18px 20px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #e2e8f0"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:14},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#1e293b",margin:0},children:l.dash.recentKpi}),t.jsxs("button",{onClick:()=>s("kpi-input"),style:{padding:"6px 14px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#334155",fontWeight:600,fontSize:12,cursor:"pointer"},children:[l.dash.manageKpi," →"]})]}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(280px, 1fr))",gap:14},children:y.map(g=>t.jsx(c0,{kpi:g},g.name))})]}),(z||C)&&t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:16},children:[z&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fee2e2",borderLeft:"5px solid #ef4444"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:14,color:"#ef4444",marginBottom:12},children:["Critical Escalations — Level 2 (",k.length+j.length,")"]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(Vn,{items:k,type:"process",onNavigate:s}),t.jsx(Vn,{items:j,type:"order",onNavigate:s})]})]}),C&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fef3c7",borderLeft:"5px solid #f59e0b"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:14,color:"#b45309",marginBottom:12},children:["Needs Attention — Level 1 (",b.length+c.length,")"]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(Vn,{items:b,type:"process",onNavigate:s}),t.jsx(Vn,{items:c,type:"order",onNavigate:s})]})]})]}),t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"18px 20px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #e2e8f0"},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#1e293b",marginBottom:4},children:"Process Execution Trend — Last 6 Months"}),t.jsx("p",{style:{fontSize:12,color:"#64748b",marginBottom:12},children:"Pass / Fail verification metrics across all processes and review cycles."}),p?t.jsx("p",{style:{color:"#94a3b8",fontSize:13},children:"Loading trend analytics…"}):t.jsx(u0,{data:a})]}),o.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"18px 20px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #e2e8f0"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:14},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#1e293b",margin:0},children:"Audit Log Book — Recent Activity"}),t.jsx("button",{onClick:()=>s("reports"),style:{padding:"6px 14px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#334155",fontWeight:600,fontSize:12,cursor:"pointer"},children:"Full Activity Log →"})]}),t.jsx("div",{style:{overflowX:"auto",borderRadius:10,border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8fafc"},children:["Timestamp","User","Entity Type","Entity","Fields Changed"].map(g=>t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#64748b",fontWeight:700,fontSize:11,whiteSpace:"nowrap"},children:g},g))})}),t.jsx("tbody",{children:o.map((g,i)=>t.jsxs("tr",{style:{borderTop:"1px solid #f1f5f9",background:i%2===0?"white":"#fafafa"},children:[t.jsx("td",{style:{padding:"10px 14px",color:"#64748b",whiteSpace:"nowrap"},children:g.timestamp?String(g.timestamp).slice(0,16):"—"}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600,color:"#1e293b"},children:g.user||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#475569"},children:t.jsx("span",{style:{background:"#f1f5f9",padding:"2px 8px",borderRadius:6,fontWeight:600,fontSize:11},children:g.entity_type||"—"})}),t.jsx("td",{style:{padding:"10px 14px",color:"#1e293b",fontWeight:500},children:g.entity_name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#64748b",maxWidth:280,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.changes||"—"})]},i))})]})})]})]})}function h0({incidents:e,ideas:n,orders:s,processes:l,organizations:a,incidentStatuses:r,ideaStatuses:o,orderStatuses:d,processStatuses:p,selectedOrg:f,onOrgChange:k,onNavigate:j,onNavigateStatus:b,userRole:c}){const[y,z]=_.useState(null),[C,g]=_.useState(!1),i=()=>{g(!0),Hy(f).then(z).finally(()=>g(!1))};_.useEffect(()=>{i()},[f]);const h=_.useMemo(()=>f?e.filter(K=>K.organization===f):e,[e,f]),x=_.useMemo(()=>f?n.filter(K=>K.organization===f):n,[n,f]),S=_.useMemo(()=>f?s.filter(K=>K.organization===f):s,[s,f]),w=_.useMemo(()=>f?l.filter(K=>K.organization===f):l,[l,f]),u=c==="Admin",v=c==="Owner",[I,T]=_.useState("level1"),G=v||u&&I==="level2";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{style:{background:"linear-gradient(135deg, #1e1b4b 0%, #312e81 45%, #1e3a8a 100%)",borderRadius:16,padding:"22px 26px",color:"white",boxShadow:"0 8px 30px rgba(30, 27, 75, 0.25)",position:"relative",zIndex:20},children:[t.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:"inherit",overflow:"hidden",pointerEvents:"none"},children:[t.jsx("div",{style:{position:"absolute",top:-50,right:-50,width:220,height:220,borderRadius:"50%",background:"rgba(99, 102, 241, 0.25)",filter:"blur(50px)"}}),t.jsx("div",{style:{position:"absolute",bottom:-40,left:"35%",width:180,height:180,borderRadius:"50%",background:"rgba(59, 130, 246, 0.2)",filter:"blur(45px)"}})]}),t.jsxs("div",{style:{position:"relative",zIndex:1},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",flexWrap:"wrap",gap:16,marginBottom:20},children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:4},children:[t.jsx("span",{style:{fontSize:24},children:"⚡"}),t.jsx("h2",{style:{fontSize:22,fontWeight:800,color:"white",margin:0,letterSpacing:-.5},children:G?"Executive Performance Dashboard":"Operational Activity Dashboard"})]}),t.jsx("p",{style:{fontSize:13,color:"#c7d2fe",margin:0,opacity:.9},children:f?`Real-time analytics for ${f}`:"Enterprise overview across all organizations & business units"})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("div",{style:{minWidth:190,maxWidth:260},children:t.jsx(Vt,{value:f,onChange:k,organizations:a,placeholder:"All Organizations",small:!0})}),u&&t.jsxs("div",{style:{display:"flex",background:"rgba(255, 255, 255, 0.12)",borderRadius:10,padding:3,gap:3,backdropFilter:"blur(8px)",border:"1px solid rgba(255, 255, 255, 0.15)"},children:[t.jsx("button",{onClick:()=>T("level1"),style:{padding:"5px 12px",borderRadius:7,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:I==="level1"?"white":"transparent",color:I==="level1"?"#1e1b4b":"#c7d2fe",boxShadow:I==="level1"?"0 2px 6px rgba(0,0,0,0.15)":"none",transition:"all 0.15s ease"},children:"Level 1 (Ops)"}),t.jsx("button",{onClick:()=>T("level2"),style:{padding:"5px 12px",borderRadius:7,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:I==="level2"?"#8b5cf6":"transparent",color:"white",boxShadow:I==="level2"?"0 2px 6px rgba(0,0,0,0.2)":"none",transition:"all 0.15s ease"},children:"Level 2 (Exec)"})]}),!u&&t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"white",background:G?"#8b5cf6":"#3b82f6",padding:"5px 14px",borderRadius:9999,border:"1px solid rgba(255, 255, 255, 0.2)",boxShadow:"0 2px 6px rgba(0,0,0,0.15)"},children:G?"👑 Owner View":"💼 Operations View"}),t.jsx("button",{onClick:i,disabled:C,title:"Refresh Metrics",style:{width:32,height:32,borderRadius:10,background:"rgba(255, 255, 255, 0.15)",border:"1px solid rgba(255, 255, 255, 0.2)",color:"white",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:14,transition:"all 0.15s"},children:t.jsx("span",{style:{display:"inline-block",transform:C?"rotate(180deg)":"none",transition:"transform 0.4s ease"},children:"🔄"})})]})]}),t.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",alignItems:"center"},children:G?t.jsxs(t.Fragment,{children:[t.jsx(sn,{label:"Manage Users & Roles",icon:"👥",onClick:()=>j("users")}),t.jsx(sn,{label:"Active Review Cycles",icon:"🔄",onClick:()=>j("cycles")}),t.jsx(sn,{label:"Strategic KPI Inputs",icon:"📈",onClick:()=>j("kpi-input")}),t.jsx(sn,{label:"Executive Reports",icon:"📊",onClick:()=>j("reports")}),t.jsx(sn,{label:"Organizations Hierarchy",icon:"🏢",onClick:()=>j("organizations")})]}):t.jsxs(t.Fragment,{children:[t.jsx(sn,{label:"Incidents",icon:"⚠️",onClick:()=>j("incidents")}),t.jsx(sn,{label:"Ideas",icon:"💡",onClick:()=>j("ideas")}),t.jsx(sn,{label:"Orders",icon:"📦",onClick:()=>j("orders")}),t.jsx(sn,{label:"Processes",icon:"⚙️",onClick:()=>j("processes")}),t.jsx(sn,{label:"Inbox",icon:"📥",onClick:()=>j("inbox")}),t.jsx(sn,{label:"Reports",icon:"📊",onClick:()=>j("reports")})]})})]})]}),G?t.jsx(f0,{dashData:y,selectedOrg:f,onNavigate:j}):t.jsx(p0,{dashData:y,fi:h,fid:x,fo:S,fp:w,incidentStatuses:r,ideaStatuses:o,orderStatuses:d,processStatuses:p,onNavigate:j,onNavigateStatus:b})]})}const st={fontSize:11,color:"#475569",fontWeight:600,marginBottom:4,display:"block",textTransform:"uppercase",letterSpacing:.4},lt={width:"100%",padding:"6px 10px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:12,background:"white",color:"#1e293b",boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif",height:32,outline:"none"};function xi({children:e}){const[n,s]=_.useState(!1);return t.jsxs("div",{style:{borderRadius:10,overflow:"hidden",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",flexShrink:0,border:"1px solid #e2e8f0",marginBottom:14},children:[t.jsxs("div",{onClick:()=>s(l=>!l),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",color:"white",padding:"10px 18px",cursor:"pointer",display:"flex",alignItems:"center",gap:10,userSelect:"none",fontWeight:600,fontSize:13},children:[t.jsx("span",{style:{fontSize:12,opacity:.9},children:n?"▲":"▼"}),t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{children:"Filters"})]}),n&&t.jsx("div",{style:{background:"#f8fafc",padding:"14px 18px",borderTop:"1px solid #e2e8f0"},children:e})]})}const de=20,Tu=e=>({padding:"6px 16px",borderRadius:6,border:"1px solid #d1d5db",fontSize:12,fontWeight:600,background:e?"#f3f4f6":"white",color:e?"#c1c5cc":"#374151",cursor:e?"not-allowed":"pointer",fontFamily:"inherit"});function Ze({page:e,pageSize:n=de,total:s,onPageChange:l}){if(s===0)return null;const a=Math.max(1,Math.ceil(s/n)),r=(e-1)*n+1,o=Math.min(e*n,s);return t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 4px",fontSize:12,color:"#6b7280",flexShrink:0},children:[t.jsxs("span",{children:["Showing ",r," to ",o," of ",s," results"]}),t.jsxs("div",{style:{display:"flex",gap:8},children:[t.jsx("button",{disabled:e<=1,onClick:()=>l(e-1),style:Tu(e<=1),children:"Previous"}),t.jsx("button",{disabled:e>=a,onClick:()=>l(e+1),style:Tu(e>=a),children:"Next"})]})]})}function g0({incidents:e,organizations:n,departments:s,branches:l,incidentStatuses:a,initialOrg:r,initialStatus:o,canModify:d,userRole:p,onView:f,onEdit:k,onDelete:j,onSelectionChange:b}){const c=se(),[y,z]=_.useState(new Set),[C,g]=_.useState({search:"",organization:r||"",department:"",branch:"",status:o||""}),i=(u,v)=>g(I=>({...I,[u]:v})),[h,x]=_.useState(1),S=e.filter(u=>!(C.search&&!`${u.number} ${u.title}`.toLowerCase().includes(C.search.toLowerCase())||C.organization&&u.organization!==C.organization||C.department&&u.department!==C.department||C.branch&&u.branch!==C.branch||C.status&&u.status!==C.status));_.useEffect(()=>{x(1)},[C]);const w=S.slice((h-1)*de,h*de);return _.useEffect(()=>{if(b){const u=e.filter(v=>y.has(v.name));b(u,w)}},[y,w,e]),t.jsxs(t.Fragment,{children:[t.jsx(xi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.numberTitle}),t.jsx("input",{style:lt,value:C.search,onChange:u=>i("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.organization}),t.jsxs("select",{style:lt,value:C.organization,onChange:u=>i("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.department}),t.jsxs("select",{style:lt,value:C.department,onChange:u=>i("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.branch}),t.jsxs("select",{style:lt,value:C.branch,onChange:u=>i("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),l.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.status}),t.jsxs("select",{style:lt,value:C.status,onChange:u=>i("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),a.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:w.length>0&&w.every(u=>y.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...y,...w.map(v=>v.name)]));else{const v=new Set(y);w.forEach(I=>v.delete(I.name)),z(v)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.type}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:S.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noIncidents})}):w.map((u,v)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>f==null?void 0:f(u),style:{borderTop:"1px solid #f1f5f9",background:y.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":v%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:I=>I.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:y.has(u.name),onChange:()=>{const I=new Set(y);I.has(u.name)?I.delete(u.name):I.add(u.name),z(I)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:u.title||u.name||"—"}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.type?ac(u.type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?ds(c.deletedBadge):u.status?ds(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:I=>I.stopPropagation(),children:t.jsx(ot,{onView:()=>f==null?void 0:f(u),onEdit:d&&k&&!u.custom_is_deleted&&!Jn("incident",u.workflow_state)&&!(p==="Employee"&&u.workflow_state&&u.workflow_state!=="New")?()=>k(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Ze,{page:h,total:S.length,onPageChange:x})]})}function m0(e){if(!e)return"";const[n,s,l]=e.split("-");return!n||!s||!l?"":`${l}/${s}/${n}`}function je({value:e,onChange:n,disabled:s,style:l,min:a,max:r}){return t.jsxs("div",{style:{position:"relative",width:"100%"},children:[t.jsx("input",{type:"text",readOnly:!0,tabIndex:-1,value:m0(e),placeholder:"DD/MM/YYYY",style:{...l,pointerEvents:"none",paddingRight:30}}),t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:s?"#bbb":"#666",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",pointerEvents:"none"},children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),t.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),t.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),t.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),t.jsx("input",{type:"date",value:e||"",disabled:s,min:a,max:r,onChange:o=>n(o.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0,cursor:s?"default":"pointer",border:"none",padding:0,margin:0}})]})}const Eu={"SB Process":"processes-form","SB Order":"orders-form","SB Incident":"incidents-form","SB Idea":"ideas-form","SB Delegation":"delegations"};function x0(e){const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}function ch({notifCount:e,darkMode:n,onCountChange:s,onToggleDark:l,onViewProfile:a,onLogout:r,onNavigate:o,userName:d,userRole:p}){const[f,k]=_.useState(!1),[j,b]=_.useState([]),[c,y]=_.useState(!1),z=_.useRef(null);_.useEffect(()=>{const T=G=>{z.current&&!z.current.contains(G.target)&&k(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]);const C=async()=>{y(!0);const T=await Ry(30);b(T),y(!1)},g=()=>{const T=!f;k(T),T&&C()},i=async()=>{await Dy(),b(T=>T.map(G=>({...G,read:1}))),s(0)},h=T=>{T.read||(Oy(T.name),b(K=>K.map(le=>le.name===T.name?{...le,read:1}:le)),s(Math.max(0,e-1)));const G=T.document_type?Eu[T.document_type]:void 0;G&&o&&(o(G,T.document_type==="SB Delegation"?void 0:T.document_name),k(!1))},x=j.filter(T=>!T.read).length,S=T=>({position:"relative",width:34,height:34,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:n?"#2d3748":"#f3f4f6",color:n?"#e2e8f0":"#6b7280",fontSize:14,transition:"background 0.15s",flexShrink:0,...T}),w=n,u=w?"#1a202c":"white",v=w?"#2d3748":"#e5e7eb",I=w?"#e2e8f0":"#1a2332";return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[d&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",marginRight:4,lineHeight:1.25},children:[t.jsx("span",{style:{fontSize:13,fontWeight:600,color:w?"#e2e8f0":"#1e293b",whiteSpace:"nowrap"},children:d}),p&&t.jsx("span",{style:{fontSize:11,color:w?"#94a3b8":"#6b7280",whiteSpace:"nowrap"},children:p})]}),t.jsx("button",{style:S({background:"#4f46e5",color:"white"}),onClick:a,title:"My Profile",children:t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7",fill:"currentColor"})]})}),t.jsxs("div",{ref:z,style:{position:"relative"},children:[t.jsxs("button",{style:S(),onClick:g,title:"Notifications",children:[t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),t.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),e>0&&t.jsx("span",{style:{position:"absolute",top:2,right:2,background:"#ef4444",color:"white",fontSize:9,fontWeight:700,borderRadius:999,minWidth:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 3px",lineHeight:1},children:e>9?"9+":e})]}),f&&t.jsxs("div",{style:{position:"absolute",right:0,top:"calc(100% + 8px)",width:340,background:u,borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.2)",zIndex:1e4,border:`1px solid ${v}`,overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${v}`,display:"flex",alignItems:"center",justifyContent:"space-between",background:u},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:I},children:["Notifications",x>0&&t.jsxs("span",{style:{background:"#ef4444",color:"white",fontSize:10,fontWeight:700,borderRadius:999,padding:"2px 7px"},children:[x," new"]})]}),x>0&&t.jsx("button",{onClick:i,style:{fontSize:12,color:"#3498db",background:"none",border:"none",cursor:"pointer",fontFamily:"inherit"},children:"Mark all read"})]}),t.jsxs("div",{style:{maxHeight:380,overflowY:"auto"},children:[c&&t.jsx("div",{style:{padding:20,textAlign:"center",color:"#aaa",fontSize:13},children:"Loading…"}),!c&&j.length===0&&t.jsxs("div",{style:{padding:"36px 20px",textAlign:"center",color:"#aaa"},children:[t.jsx("div",{style:{fontSize:28,marginBottom:8},children:"🔔"}),t.jsx("div",{style:{fontSize:13},children:"No notifications"})]}),!c&&j.map(T=>{const G=!!(T.document_type&&Eu[T.document_type]&&o);return t.jsxs("div",{onClick:()=>h(T),style:{padding:"11px 16px",borderBottom:`1px solid ${w?"#2d3748":"#f5f5f5"}`,display:"flex",gap:10,background:T.read?u:w?"#1e3a5f":"#eff6ff",cursor:G?"pointer":"default",transition:"background 0.12s"},onMouseEnter:K=>{G&&(K.currentTarget.style.background=w?"#243244":"#e0ecfd")},onMouseLeave:K=>{K.currentTarget.style.background=T.read?u:w?"#1e3a5f":"#eff6ff"},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13,fontWeight:T.read?400:600,color:I,marginBottom:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T.subject||`${T.document_type}: ${T.document_name}`}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:T.document_type&&t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#3b82f6",background:w?"rgba(59,130,246,0.15)":"#eff6ff",padding:"1px 7px",borderRadius:8},children:[T.document_type.replace("SB ",""),T.document_name?` · ${T.document_name}`:""]})}),t.jsx("div",{style:{fontSize:11,color:"#aaa",marginTop:3},children:x0(T.creation)})]}),!T.read&&t.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:"#3498db",flexShrink:0,marginTop:5}})]},T.name)})]})]})]}),t.jsx("button",{style:S(),onClick:lh,title:jl()?"Switch to English":"Switch to Arabic",children:t.jsx("span",{style:{fontSize:13,fontWeight:700,fontFamily:"serif"},children:"عA"})}),t.jsx("button",{style:S(),onClick:l,title:n?"Light mode":"Dark mode",children:n?t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"5"}),t.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),t.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),t.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),t.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),t.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),t.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),t.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),t.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),t.jsx("button",{style:S({background:w?"#3d1515":"#fee2e2",color:"#ef4444"}),onClick:r,title:"Logout",children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),t.jsx("polyline",{points:"16,17 21,12 16,7"}),t.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})}function et({title:e,activePage:n,user:s,formStatus:l,buttonText:a,viewMode:r,statusBadge:o,onEdit:d,onCancel:p,hideSettings:f,rightPanel:k,darkMode:j,notifCount:b,onToggleDark:c,onCountChange:y,onViewProfile:z,onSubmit:C,onBack:g,onNavigate:i,onLogout:h,children:x}){const S=se(),w=s.role,u=w==="Admin"||w==="Owner"||w==="Auditor"||w==="Manager",v=w==="Admin"||w==="Owner"||w==="Auditor"||w==="Manager",I=w==="Admin"||w==="Auditor"||w==="Manager",[T,G]=_.useState(()=>localStorage.getItem("sb_sidebar")==="1"),K=_.useRef(void 0),[le,U]=_.useState(!1);_.useEffect(()=>{if(K.current===!0&&r===!1){U(!0);const E=setTimeout(()=>{U(!1)},4e3);return()=>clearTimeout(E)}else U(!1);K.current=r},[r]);const F=()=>G(E=>{const A=!E;return localStorage.setItem("sb_sidebar",A?"1":"0"),A}),D=p||g;return t.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:j?"#0f172a":"#f8fafc"},children:[t.jsx(rh,{collapsed:T,onToggleCollapsed:F,activePage:n,onNavigate:i,hasDashboard:u,hasReports:v,hasDelegations:I,role:w,hideSettings:f,rtl:S.rtl,navLabels:S.nav,settingsLabel:S.nav.settings}),t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[t.jsx("div",{style:{background:j?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${j?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:j?"none":"0 1px 4px rgba(0,0,0,0.03)"},children:t.jsx(ch,{notifCount:b,darkMode:j,onCountChange:y,onToggleDark:c,onNavigate:i,onViewProfile:z,onLogout:h,userName:s.full_name||s.name,userRole:s.role})}),t.jsxs("div",{style:{background:j?"#1e293b":"#ffffff",padding:"12px 24px",borderBottom:`1px solid ${j?"#2d3748":"#e2e8f0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,position:"relative"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[t.jsx("button",{onClick:g,title:S.back,style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:`1px solid ${j?"#475569":"#e2e8f0"}`,background:j?"#334155":"#ffffff",cursor:"pointer",color:"#2563eb",flexShrink:0,transition:"all 0.15s ease"},onMouseEnter:E=>{E.currentTarget.style.background=j?"#475569":"#eff6ff",E.currentTarget.style.borderColor="#93c5fd"},onMouseLeave:E=>{E.currentTarget.style.background=j?"#334155":"#ffffff",E.currentTarget.style.borderColor=j?"#475569":"#e2e8f0"},children:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("div",{style:{fontSize:17,fontWeight:700,color:j?"#f8fafc":"#0f172a"},children:e}),o&&(typeof o=="string"?t.jsx("span",{style:{padding:"3px 10px",borderRadius:16,fontSize:12,fontWeight:600,background:"#fef3c7",color:"#92400e",border:"1px solid #fde68a"},children:o}):o)]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[r&&d&&t.jsxs("button",{type:"button",onClick:d,style:{display:"flex",alignItems:"center",gap:6,padding:"7px 16px",borderRadius:6,border:"none",background:"#2563eb",color:"#ffffff",cursor:"pointer",fontSize:13,fontWeight:600,boxShadow:"0 1px 3px rgba(37,99,235,0.25)",transition:"all 0.15s ease"},onMouseEnter:E=>E.currentTarget.style.background="#1d4ed8",onMouseLeave:E=>E.currentTarget.style.background="#2563eb",children:[t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),S.edit]}),!r&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("button",{type:"button",onClick:D,style:{padding:"7px 16px",borderRadius:6,border:`1px solid ${j?"#475569":"#cbd5e1"}`,background:j?"#334155":"#ffffff",color:j?"#e2e8f0":"#475569",fontSize:13,fontWeight:600,cursor:"pointer",transition:"all 0.15s ease"},onMouseEnter:E=>{E.currentTarget.style.background=j?"#475569":"#f1f5f9"},onMouseLeave:E=>{E.currentTarget.style.background=j?"#334155":"#ffffff"},children:S.cancel}),t.jsxs("button",{type:"button",onClick:C,disabled:l==="loading",style:{display:"flex",alignItems:"center",gap:6,padding:"7px 18px",borderRadius:6,border:"none",background:"#16a34a",color:"#ffffff",fontSize:13,fontWeight:600,cursor:l==="loading"?"not-allowed":"pointer",boxShadow:"0 1px 3px rgba(22, 163, 74, 0.3)",opacity:l==="loading"?.7:1,transition:"all 0.15s ease"},onMouseEnter:E=>{l!=="loading"&&(E.currentTarget.style.background="#15803d")},onMouseLeave:E=>{l!=="loading"&&(E.currentTarget.style.background="#16a34a")},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),t.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),t.jsx("polyline",{points:"7 3 7 8 15 8"})]}),t.jsx("span",{children:l==="loading"?S.saving:a||"Save Changes"})]})]})]}),!r&&le&&t.jsxs("div",{style:{position:"absolute",top:-34,right:24,background:"#0284c7",color:"#ffffff",padding:"4px 12px",borderRadius:6,fontSize:12,fontWeight:600,display:"flex",alignItems:"center",gap:8,boxShadow:"0 2px 8px rgba(2, 132, 199, 0.3)",zIndex:10},children:[t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5},children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),"Edit mode enabled"]}),t.jsx("button",{type:"button",onClick:()=>U(!1),title:"Dismiss",style:{background:"transparent",border:"none",color:"white",cursor:"pointer",fontSize:14,padding:0,lineHeight:1,opacity:.85},children:"✕"})]})]}),t.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px",display:"grid",gridTemplateColumns:k?"1fr 240px":"1fr",gap:16,alignItems:"start"},children:[t.jsxs("div",{style:{minWidth:0},children:[x,l==="success"&&t.jsx("div",{style:{padding:"10px 14px",borderRadius:8,background:"#f0fdf4",border:"1px solid #86efac",color:"#166534",fontSize:13,marginTop:14},children:S.savedOk}),l!=="idle"&&l!=="loading"&&l!=="success"&&t.jsx("div",{style:{padding:"10px 14px",borderRadius:8,background:"#fef2f2",border:"1px solid #fca5a5",color:"#991b1b",fontSize:13,marginTop:14},children:l})]}),k&&t.jsx("div",{style:{position:"sticky",top:0,alignSelf:"start",width:240},children:k})]})]})]})}function po(e){return e?e==="Department"?{key:"department_name",label:"Department Name"}:e==="Branch"?{key:"branch",label:"Branch Name"}:e==="SB Organization"||e==="Organization"?{key:"organization_name",label:"Organization Name"}:e==="SB Group Company"||e==="Group Company"?{key:"company_name",label:"Company Name"}:{key:"name1",label:`${e.replace(/^SB\s+/,"")} Name`}:{key:"name1",label:"Name"}}function re({value:e,onChange:n,items:s,placeholder:l="Select...",disabled:a=!1,onCreateNew:r,createNewText:o,doctypeName:d,userRole:p,onQuickCreateSuccess:f,extraFields:k={}}){var M;const[j,b]=_.useState(!1),[c,y]=_.useState(""),[z,C]=_.useState(""),[g,i]=_.useState(!1),[h,x]=_.useState(""),[S,w]=_.useState(!1),[u,v]=_.useState(""),I=_.useRef(null),T=_.useRef(null);_.useEffect(()=>{const Q=N=>{I.current&&!I.current.contains(N.target)&&b(!1)};return document.addEventListener("mousedown",Q),()=>document.removeEventListener("mousedown",Q)},[]);const G=(s||[]).filter(Q=>{if(!Q)return!1;const N=Q;return!(N.custom_is_deleted===1||N.custom_is_deleted==="1"||N.custom_is_deleted===!0||N.is_deleted===1||N.is_deleted==="1"||N.is_deleted===!0||N.status==="Deleted"||N.custom_status==="Deleted")}),K=e?((M=G.find(Q=>Q.name===e))==null?void 0:M.label)??e:"",le=G.filter(Q=>{if(!c.trim())return!0;const N=c.toLowerCase().trim();return(Q.label||"").toLowerCase().includes(N)||(Q.name||"").toLowerCase().includes(N)}),F=!(p==="Employee"||p==="SB Employee")&&(!!r||!!d||!!o),D=d?`Create New ${d.replace(/^SB\s+/,"")}`:"Create New",E=o||D,A=async Q=>{if(Q.preventDefault(),!(!h.trim()||!d)){w(!0),v("");try{const N=po(d),ee={[N.key]:h.trim(),...k};["Incident Types","Idea Types","Order Types","Process Types"].includes(d)&&(ee.status="Active");const Z=await Jr(d,ee),ce=(Z==null?void 0:Z.data)||Z,ae=(ce==null?void 0:ce.name)||(ce==null?void 0:ce[N.key])||h.trim();n(ae),f&&f(ae),i(!1),x("")}catch(N){console.error("Quick create error:",N),v((N==null?void 0:N.message)||"Failed to create item. Please try again.")}finally{w(!1)}}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:I,className:`custom-select-container ${a?"disabled":""} ${j?"open":""}`,style:{position:"relative",width:"100%"},children:[t.jsxs("div",{className:`custom-select-trigger ${a?"disabled":""} ${j?"open":""} ${!e&&!c?"is-placeholder":""}`,style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingRight:8},onClick:()=>{a||(j||(b(!0),y("")),setTimeout(()=>{var Q;return(Q=T.current)==null?void 0:Q.focus()},0))},children:[t.jsx("input",{ref:T,type:"text",disabled:a,placeholder:l,value:j?c:K,onChange:Q=>{j||b(!0),y(Q.target.value)},onFocus:()=>{!a&&!j&&(b(!0),y(""))},style:{border:"none",outline:"none",background:"transparent",width:"100%",fontSize:"inherit",fontFamily:"inherit",color:"inherit",cursor:a?"not-allowed":"text",padding:0}}),e&&!a?t.jsx("span",{title:"Clear selection",style:{cursor:"pointer",color:"#94a3b8",fontSize:14,fontWeight:600,padding:"0 4px",lineHeight:1,userSelect:"none",transition:"color 0.15s ease",flexShrink:0},onClick:Q=>{Q.stopPropagation(),n(""),y(""),b(!1)},onMouseEnter:Q=>Q.currentTarget.style.color="#475569",onMouseLeave:Q=>Q.currentTarget.style.color="#94a3b8",children:"✕"}):t.jsx("span",{className:"trigger-arrow",style:{pointerEvents:"none",flexShrink:0},children:"▼"})]}),j&&t.jsx("div",{className:"custom-select-dropdown",children:t.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[le.length===0&&!F&&t.jsx("div",{className:"custom-select-empty",children:"No matching records found"}),le.map(Q=>t.jsx("div",{className:`custom-select-option ${e===Q.name?"selected":""} ${z===Q.name?"hovered":""}`,onClick:()=>{n(Q.name),y(""),b(!1)},onMouseEnter:()=>C(Q.name),onMouseLeave:()=>C(""),children:Q.label},Q.name)),F&&t.jsxs("div",{className:`custom-select-option create-new-option ${z==="__create_new"?"hovered":""}`,style:{borderTop:"1px solid #e2e8f0",color:"#16a34a",fontWeight:700,fontSize:13,padding:"10px 14px",display:"flex",alignItems:"center",gap:6,cursor:"pointer",background:z==="__create_new"?"#f0fdf4":"#ffffff",transition:"all 0.15s ease"},onClick:()=>{b(!1),r?r():(x(""),v(""),i(!0))},onMouseEnter:()=>C("__create_new"),onMouseLeave:()=>C(""),children:[t.jsx("span",{style:{fontSize:16,fontWeight:800,color:"#16a34a",lineHeight:1},children:"+"}),t.jsx("span",{children:E})]})]})})]}),g&&d&&t.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(15, 23, 42, 0.55)",backdropFilter:"blur(3px)",padding:16},onClick:Q=>{Q.target===Q.currentTarget&&!S&&i(!1)},children:t.jsxs("div",{style:{background:"#ffffff",borderRadius:12,boxShadow:"0 20px 40px rgba(0, 0, 0, 0.2)",maxWidth:440,width:"100%",overflow:"hidden",animation:"scaleIn 0.15s ease"},children:[t.jsxs("div",{style:{padding:"16px 20px",borderBottom:"1px solid #f1f5f9",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:16,fontWeight:700,color:"#1e293b"},children:[t.jsx("span",{style:{color:"#2563eb",fontSize:18,fontWeight:800},children:"+"}),t.jsx("span",{children:`Create New ${d.replace(/^SB\s+/,"")}`})]}),t.jsx("button",{type:"button",onClick:()=>!S&&i(!1),style:{background:"none",border:"none",color:"#94a3b8",fontSize:18,cursor:"pointer",padding:"2px 6px",borderRadius:4},children:"✕"})]}),t.jsxs("form",{onSubmit:A,style:{padding:"20px"},children:[u&&t.jsx("div",{style:{background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",padding:"8px 12px",borderRadius:6,fontSize:12,marginBottom:14},children:u}),t.jsxs("div",{style:{marginBottom:16},children:[t.jsxs("label",{style:{display:"block",fontSize:12,fontWeight:700,color:"#334155",marginBottom:6},children:[po(d).label," ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"text",value:h,onChange:Q=>x(Q.target.value),placeholder:`Enter ${po(d).label.toLowerCase()}`,autoFocus:!0,disabled:S,style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:13,boxSizing:"border-box",outline:"none"}})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:10,marginTop:22},children:[t.jsx("button",{type:"button",onClick:()=>i(!1),disabled:S,style:{padding:"8px 16px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#475569",fontWeight:600,fontSize:13,cursor:S?"not-allowed":"pointer"},children:"Cancel"}),t.jsxs("button",{type:"submit",disabled:S||!h.trim(),style:{padding:"8px 18px",borderRadius:8,border:"none",background:"#2563eb",color:"#ffffff",fontWeight:700,fontSize:13,cursor:S||!h.trim()?"not-allowed":"pointer",opacity:S||!h.trim()?.6:1,display:"flex",alignItems:"center",gap:6,boxShadow:"0 2px 4px rgba(37, 99, 235, 0.25)"},children:[t.jsx("span",{style:{fontSize:15,fontWeight:800},children:"+"}),t.jsx("span",{children:S?"Creating...":"Create"})]})]})]})]})})]})}function y0(e){const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<86400*7?`${Math.floor(n/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function v0(e){return e.replace(/@.*/,"").replace(/[._-]/g," ").split(" ").filter(Boolean).slice(0,2).map(s=>s[0].toUpperCase()).join("")}function yi({doctype:e,docname:n,currentUserName:s}){const l=se(),[a,r]=_.useState([]),[o,d]=_.useState(!1),[p,f]=_.useState(""),[k,j]=_.useState(!1),[b,c]=_.useState(!1),[y,z]=_.useState(!1),[C,g]=_.useState(""),i=5,h=_.useCallback(async()=>{d(!0);const v=await Ny(e,n);r(v),d(!1)},[e,n]);_.useEffect(()=>{h()},[h]);const x=async()=>{const v=p.trim();if(!(!v||k)){j(!0),g("");try{await Wy(e,n,v),f(""),await h()}catch{g("Failed to post comment. Please try again.")}j(!1)}},S=async v=>{if(window.confirm("Delete this comment?"))try{await dd("Comment",v),r(I=>I.filter(T=>T.name!==v))}catch{alert("Failed to delete comment.")}},w=y?a:a.slice(-i),u=Math.max(0,a.length-i);return t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>c(v=>!v),style:{padding:"12px 20px",borderBottom:b?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none",background:"white"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["💬 ",l.comments.title,a.length>0&&t.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:a.length})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("button",{onClick:v=>{v.stopPropagation(),h()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),t.jsx("span",{style:{color:"#ccc",fontSize:11},children:b?"▼":"▲"})]})]}),!b&&t.jsxs("div",{style:{padding:"16px 20px"},children:[!y&&u>0&&t.jsxs("button",{onClick:()=>z(!0),style:{width:"100%",padding:"8px",marginBottom:12,border:"none",background:"#f8f9fa",borderRadius:6,cursor:"pointer",fontSize:12,color:"#3498db",fontFamily:"Segoe UI"},children:["Show ",u," older comment",u!==1?"s":""]}),o&&t.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:l.loading}),!o&&a.length===0&&t.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:l.comments.noComments}),!o&&w.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:16},children:w.map(v=>{const I=v.comment_by||v.comment_email||v.owner||"Unknown",T=v.owner===s||v.comment_by===s;return t.jsxs("div",{style:{display:"flex",gap:10,padding:"12px 14px",background:"#f9fafb",borderRadius:8,border:"1px solid #e8e8e8"},children:[t.jsx("div",{style:{width:34,height:34,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:700,flexShrink:0},children:v0(I)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:I}),t.jsx("span",{style:{fontSize:11,color:"#aaa"},children:y0(v.creation)})]}),T&&t.jsx("button",{onClick:()=>S(v.name),style:{background:"none",border:"none",cursor:"pointer",color:"#e74c3c",fontSize:16,padding:"0 2px",lineHeight:1},title:"Delete comment",children:"×"})]}),t.jsx("div",{style:{fontSize:13,color:"#374151",lineHeight:1.55,wordBreak:"break-word",whiteSpace:"pre-wrap"},dangerouslySetInnerHTML:{__html:v.content||""}})]})]},v.name)})}),t.jsxs("div",{style:{borderTop:a.length>0?"1px solid #f0f0f0":"none",paddingTop:a.length>0?14:0},children:[t.jsx("textarea",{value:p,onChange:v=>f(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.ctrlKey||v.metaKey)&&x()},placeholder:l.comments.placeholder,rows:3,style:{width:"100%",padding:"10px 12px",border:"1px solid #ddd",borderRadius:8,fontSize:13,fontFamily:"Segoe UI",resize:"vertical",boxSizing:"border-box",outline:"none",color:"#1a2332"}}),C&&t.jsx("div",{style:{fontSize:12,color:"#e74c3c",marginTop:4},children:C}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:8},children:t.jsx("button",{onClick:x,disabled:!p.trim()||k,style:{padding:"8px 20px",background:"#3498db",color:"white",border:"none",borderRadius:6,cursor:!p.trim()||k?"not-allowed":"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI",opacity:!p.trim()||k?.6:1},children:k?l.saving:l.comments.post})})]})]})]})}function Au(e){if(!e)return"";const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<86400*7?`${Math.floor(n/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function j0(e){return(e||"").replace(/^custom_/,"").replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Pu(e){return e==null||e===""?"(empty)":typeof e=="object"?JSON.stringify(e):String(e)}function cd(e){return(e||"Unknown").replace(/@.*/,"").replace(/[._]/g," ")}function Ru(e){return cd(e).split(" ").filter(Boolean).slice(0,2).map(n=>n[0].toUpperCase()).join("")}function b0(e){let n={};try{n=JSON.parse(e.data||"{}")}catch{}const s=(n.changed||[]).map(l=>({field:l[0]||"",oldVal:Pu(l[1]),newVal:Pu(l[2])}));return{name:e.name,owner:e.owner,creation:e.creation,changes:s,added:(n.added||[]).length,removed:(n.removed||[]).length,rowChanged:(n.row_changed||[]).length}}function vi({doctype:e,docname:n,docCreation:s,docOwner:l}){const a=se(),[r,o]=_.useState([]),[d,p]=_.useState(!1),[f,k]=_.useState(!0),[j,b]=_.useState(!1),c=5,y=_.useCallback(async()=>{p(!0);const i=await By(e,n);o(i.map(b0)),p(!1)},[e,n]);_.useEffect(()=>{f||y()},[f,y]);const z=j?r:r.slice(0,c),C=r.length-c,g=(i,h=!1)=>({position:"absolute",left:-14,top:14,width:10,height:10,borderRadius:"50%",background:i,border:"2px solid white",boxShadow:h?`0 0 0 2px ${i}44`:"none"});return t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>k(i=>!i),style:{padding:"12px 20px",borderBottom:f?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["📋 ",a.activity.title,!f&&r.length>0&&t.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:r.length})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[!f&&t.jsx("button",{onClick:i=>{i.stopPropagation(),y()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),t.jsx("span",{style:{color:"#ccc",fontSize:11},children:f?"▼":"▲"})]})]}),!f&&t.jsxs("div",{style:{padding:"16px 20px"},children:[d&&t.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:a.loading}),!d&&t.jsxs("div",{style:{position:"relative",paddingLeft:20},children:[t.jsx("div",{style:{position:"absolute",left:8,top:0,bottom:0,width:2,background:"#e5e7eb"}}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[z.map((i,h)=>t.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[t.jsx("div",{style:g(h===0?"#3498db":"#d1d5db",h===0)}),t.jsxs("div",{style:{background:h===0?"#eff6ff":"#f9fafb",border:`1px solid ${h===0?"#bfdbfe":"#e5e7eb"}`,borderRadius:8,padding:"10px 14px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[t.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:Ru(i.owner)}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:cd(i.owner)}),t.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Au(i.creation)})]}),i.changes.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:i.changes.map((x,S)=>t.jsxs("div",{style:{fontSize:12,lineHeight:1.5},children:[t.jsx("span",{style:{fontWeight:600,color:"#6d28d9"},children:j0(x.field)}),t.jsx("span",{style:{color:"#6b7280"},children:" changed from "}),t.jsx("span",{style:{padding:"1px 5px",background:"#fee2e2",color:"#dc2626",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:x.oldVal}),t.jsx("span",{style:{color:"#6b7280"},children:" → "}),t.jsx("span",{style:{padding:"1px 5px",background:"#dcfce7",color:"#16a34a",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:x.newVal})]},S))}):t.jsxs("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic"},children:["Document updated",i.added>0&&t.jsxs("span",{children:[" · +",i.added," row(s)"]}),i.removed>0&&t.jsxs("span",{children:[" · -",i.removed," row(s)"]}),i.rowChanged>0&&t.jsxs("span",{children:[" · ~",i.rowChanged," row(s) modified"]})]})]})]},i.name)),s&&l&&t.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[t.jsx("div",{style:g("#22c55e")}),t.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"10px 14px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[t.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#22c55e",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:Ru(l)}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:cd(l)}),t.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Au(s)})]}),t.jsxs("div",{style:{fontSize:12,color:"#15803d",fontWeight:600},children:["✓ ",a.activity.created]})]})]}),r.length===0&&!s&&t.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:"No activity recorded"})]})]}),!d&&C>0&&t.jsx("div",{style:{textAlign:"center",marginTop:12},children:t.jsx("button",{onClick:()=>b(i=>!i),style:{background:"none",border:"none",cursor:"pointer",color:"#3498db",fontSize:12,fontFamily:"Segoe UI",padding:"4px 8px"},children:j?"▲ Show less":`▼ Show all (${r.length})`})})]})]})}const S0={New:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Initial Evaluation":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},"Accept & Under Progress":{background:"#fefce8",color:"#92400e",border:"1px solid #fde68a"},"working on resolution":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Rejected:{background:"#fef2f2",color:"#dc2626",border:"1px solid #fecaca"},"Executed & Closed":{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function _0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...S0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function w0({incForm:e,setIncForm:n,organizations:s,groupCompanies:l=[],managements:a,departments:r,branches:o,incidentTypes:d,incidentClasses:p,incidentFields:f,incidentStatuses:k,users:j,userRoleMap:b={},formStatus:c,viewMode:y,canModify:z,onEdit:C,onDelete:g,onRestore:i,onPermanentDelete:h,darkMode:x,notifCount:S,onToggleDark:w,onCountChange:u,onViewProfile:v,userRole:I,delegatedFunctions:T=[],delegatedOrgs:G={},onSubmit:K,onBack:le,onNavigate:U,onLogout:F,user:D,onRefresh:E}){var St;const A=se(),M=H=>n({...e,...H}),Q=y?{background:"#f9f9f9"}:{},N=Dl(j,b,"SB Manager",e.organization),[ee,Z]=_.useState(""),[ce,ae]=_.useState(!1),Be=e.name?y?`${A.formTitle.viewIncident}${e.number||e.name}`:A.formTitle.editIncident:A.formTitle.newIncident,$e=l.map(H=>({name:H.name,label:H.company_name||H.name})),ut=be(a,e.management).map(H=>({name:H.name,label:H.name1||H.name})),q=be(r,e.department).map(H=>({name:H.name,label:H.department_name||H.name})),ue=be(o,e.branch).map(H=>({name:H.name,label:H.branch||H.name})),pe=be(d,e.type).map(H=>({name:H.name,label:H.name1||H.name})),Ut=be(p,e.incident_class).map(H=>({name:H.name,label:H.name1||H.name})),tt=be(f,e.incident_field).map(H=>({name:H.name,label:H.name1||H.name})),ze=e.workflow_state||"New",Mt=I==="Employee",Se=I==="Auditor"||I==="Admin",De=I==="Manager",Zt=De&&T.includes("incident_initial_evaluation")&&(!G.incident_initial_evaluation||(G.incident_initial_evaluation||[]).includes(e.organization)),ge=Se||Zt,B=e.name?ze==="New"?[{label:A.wf.submit,action:"Submit",color:"#2563eb"}]:ze==="Initial Evaluation"&&ge?[{label:A.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:A.wf.reject,action:"Reject",color:"#dc2626"}]:ze==="Accept & Under Progress"&&(De||Se)?[{label:A.wf.submitSolution,action:"Submit Solution",color:"#059669"}]:ze==="working on resolution"&&(De||Se)?[{label:A.wf.resolutionComplete,action:"Resolution complete",color:"#166534"}]:[]:[];async function ne(H){if(e.name){ae(!0),Z("");try{const Ue={};H==="Assign to Manager"&&(e.assigned_to&&(Ue.assigned_to=e.assigned_to),e.priority&&(Ue.priority=e.priority),e.economy_class&&(Ue.economy_class=e.economy_class),e.entity_scope&&(Ue.entity_scope=e.entity_scope),e.hses_field&&(Ue.hses_field=e.hses_field),Ue.product_relation=String(e.product_relation??0),Ue.repeated=String(e.repeated??0)),H==="Submit Solution"&&(e.solution&&(Ue.solution=e.solution),e.summary&&(Ue.summary=e.summary),e.cost&&(Ue.cost=String(e.cost))),(H==="Resolution complete"||H==="Submit Solution")&&e.auditor_comment&&(Ue.auditor_comment=e.auditor_comment),await My(e.name,H,JSON.stringify(Ue)),Z("Done"),E==null||E()}catch(Ue){Z(Ue.message||"Error")}finally{ae(!1)}}}const O=((St=N.find(H=>H.name===e.assigned_to))==null?void 0:St.full_name)||e.assigned_to,ve=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:A.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:ze})]}),ze==="Initial Evaluation"&&ge&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:A.wf.assignToManager}),t.jsxs("select",{style:L,value:e.assigned_to||"",onChange:H=>M({assigned_to:H.target.value}),children:[t.jsx("option",{value:"",children:A.field.selectMgr}),N.map(H=>t.jsx("option",{value:H.name,children:H.full_name||H.name},H.name))]})]}),(ze==="Accept & Under Progress"||ze==="working on resolution")&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:A.field.solution}),t.jsx("textarea",{style:{...L,height:75,resize:"vertical"},value:e.solution||"",onChange:H=>M({solution:H.target.value}),placeholder:A.field.solutionPlaceholder}),t.jsx("label",{style:{...R,marginTop:6},children:A.field.actualCost}),t.jsx("input",{type:"number",style:L,value:e.cost||"",onChange:H=>M({cost:parseFloat(H.target.value)||0}),placeholder:"0.00"})]}),ze==="working on resolution"&&Se&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:A.field.auditorComment}),t.jsx("textarea",{style:{...L,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:H=>M({auditor_comment:H.target.value}),placeholder:A.field.commentPlaceholder})]}),B.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:B.map(H=>t.jsx("button",{onClick:()=>ne(H.action),disabled:ce,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:H.color,color:"white",fontWeight:600,fontSize:12,cursor:ce?"not-allowed":"pointer",opacity:ce?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:ce?A.wf.applying:H.label})},H.action))}):t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:A.wf.noActions}),ee&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:ee==="Done"?X.green:X.red},children:ee})]}),t.jsx(mi,{priority:e.priority,status:ze,assignedTo:O||(e.assigned_to?e.assigned_to:void 0),createdDate:e.date,modifiedDate:e.modified}),t.jsx(yi,{doctype:P.incidents,docname:e.name,currentUserName:D.name}),t.jsx(vi,{doctype:P.incidents,docname:e.name,docCreation:e.creation,docOwner:e.owner}),z&&g&&!e.custom_is_deleted&&t.jsx(gi,{title:"Delete Request",btnText:A.delete,onDelete:()=>g(e.name)})]}):null;return t.jsxs(et,{title:Be,activePage:"incidents",user:D,formStatus:c,statusBadge:t.jsx("span",{style:_0(ze),children:ze}),buttonText:A.saveIncident,buttonColor:"#16a34a",viewMode:y,onEdit:C,darkMode:x,notifCount:S,onToggleDark:w,onCountChange:u,onViewProfile:v,rightPanel:ve,onSubmit:K,onBack:le,onNavigate:U,onLogout:F,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:i?()=>i(e.name):void 0,onPermanentDelete:h?()=>h(e.name):void 0}),t.jsx(oe,{title:"Incident Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.number}),t.jsx("input",{style:{...L,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:H=>M({group_company:H}),items:$e,placeholder:"Select Group Company",disabled:y||!!D.custom_group_company,userRole:I,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[A.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:H=>{var Pt;const Ue=(Pt=s.find(fs=>fs.name===H))==null?void 0:Pt.group_company;M({organization:H,...D.custom_group_company?{}:{group_company:Ue||e.group_company}})},organizations:s,disabled:y||!!D.custom_organization,userRole:I,onQuickCreateSuccess:E})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.title}),t.jsx("input",{style:{...L,...Q},value:e.title,disabled:y,onChange:H=>M({title:H.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.management}),t.jsx(re,{value:e.management,onChange:H=>M({management:H}),items:ut,placeholder:A.field.select,disabled:y,userRole:I,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:E})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.department}),t.jsx(re,{value:e.department,onChange:H=>M({department:H}),items:q,placeholder:A.field.select,disabled:y,userRole:I,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:E})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.section}),t.jsx("input",{style:{...L,...Q},value:e.section_field||"",disabled:y,onChange:H=>M({section_field:H.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.branch}),t.jsx(re,{value:e.branch,onChange:H=>M({branch:H}),items:ue,placeholder:A.field.select,disabled:y,userRole:I,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:E})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.eventCategory}),t.jsxs("select",{style:{...L,...Q},value:e.event_category||"",disabled:y,onChange:H=>M({event_category:H.target.value}),children:[t.jsx("option",{value:"",children:A.field.select}),e.event_category&&!["Complaint","Accident","Violent"].includes(e.event_category)&&t.jsx("option",{value:e.event_category,children:e.event_category}),t.jsx("option",{value:"Complaint",children:"Complaint"}),t.jsx("option",{value:"Accident",children:"Accident"}),t.jsx("option",{value:"Violent",children:"Violent"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.type}),t.jsx(re,{value:e.type,onChange:H=>M({type:H}),items:pe,placeholder:A.field.selectType,disabled:y,userRole:I,doctypeName:P.incidentTypes,onQuickCreateSuccess:E})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.incidentClass}),t.jsx(re,{value:e.incident_class,onChange:H=>M({incident_class:H}),items:Ut,placeholder:A.field.selectClass,disabled:y,userRole:I,doctypeName:P.incidentClass,onQuickCreateSuccess:E})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.incidentField}),t.jsx(re,{value:e.incident_field,onChange:H=>M({incident_field:H}),items:tt,placeholder:A.field.selectField,disabled:y,userRole:I,doctypeName:P.incidentField,onQuickCreateSuccess:E})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.hsesField}),t.jsx("input",{style:{...L,...Q},value:e.hses_field||"",disabled:y,onChange:H=>M({hses_field:H.target.value}),placeholder:"Safety, Health, Environment…"})]})]})}),t.jsxs(oe,{title:"Incident Details & Timing",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.date}),t.jsx(je,{value:e.date,onChange:H=>M({date:H}),disabled:!0,style:{...L,background:"#f8fafc"}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.time}),t.jsx("input",{type:"time",style:{...L,background:"#f8fafc"},value:e.time,disabled:!0,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.assignedTo}),y||I==="Employee"?t.jsx("input",{style:{...L,background:"#f8fafc",fontWeight:600,color:"#334155"},value:O||e.assigned_to||"—",readOnly:!0,disabled:!0}):t.jsx(re,{value:e.assigned_to||"",onChange:H=>M({assigned_to:H}),items:N.map(H=>({name:H.name,label:H.full_name||H.name})),placeholder:A.field.select})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.description}),t.jsx("textarea",{style:{...L,...Q,height:100,resize:"vertical"},value:e.description,disabled:y,onChange:H=>M({description:H.target.value}),placeholder:"Detailed description of the incident..."})]})]}),!Mt&&t.jsxs(oe,{title:A.steps.auditorTriage,children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.priority}),t.jsxs("select",{style:{...L,...y||!ge?{background:"#f8fafc"}:{}},value:e.priority||"",disabled:y||!ge,onChange:H=>M({priority:H.target.value}),children:[t.jsx("option",{value:"",children:A.field.select}),t.jsx("option",{value:"High",children:A.field.high}),t.jsx("option",{value:"Normal",children:A.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.economyClass}),t.jsxs("select",{style:{...L,...y||!ge?{background:"#f8fafc"}:{}},value:e.economy_class||"",disabled:y||!ge,onChange:H=>M({economy_class:H.target.value}),children:[t.jsx("option",{value:"",children:A.field.select}),t.jsx("option",{value:"Expenses",children:A.field.expenses}),t.jsx("option",{value:"Capital",children:A.field.capital}),t.jsx("option",{value:"Earn",children:A.field.earn}),t.jsx("option",{value:"Pay/Loss",children:A.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.entityScope}),t.jsxs("select",{style:{...L,...y||!ge?{background:"#f8fafc"}:{}},value:e.entity_scope||"",disabled:y||!ge,onChange:H=>M({entity_scope:H.target.value}),children:[t.jsx("option",{value:"",children:A.field.select}),t.jsx("option",{value:"Upstream",children:A.field.upstream}),t.jsx("option",{value:"On-stream",children:A.field.onstream}),t.jsx("option",{value:"Downstream",children:A.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:y||!ge,onChange:H=>M({product_relation:H.target.checked?1:0})})," ",A.field.productRelation]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:y||!ge,onChange:H=>M({repeated:H.target.checked?1:0})})," ",A.field.repeatedEvent]})]})]}),!Mt&&t.jsxs(oe,{title:A.steps.managerSolution,children:[t.jsxs("div",{style:{marginBottom:12},children:[t.jsx("label",{style:R,children:A.field.solution}),t.jsx("textarea",{style:{...L,height:90,resize:"vertical",...y&&!De&&!Se?{background:"#f8fafc"}:{}},value:e.solution||"",disabled:y&&!De&&!Se,onChange:H=>M({solution:H.target.value}),placeholder:A.field.solutionPlaceholder})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.actualCost}),t.jsx("input",{type:"number",style:{...L,...y&&!De&&!Se?{background:"#f8fafc"}:{}},value:e.cost||"",disabled:y&&!De&&!Se,onChange:H=>M({cost:parseFloat(H.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.summary}),t.jsx("input",{style:{...L,...y&&!De&&!Se?{background:"#f8fafc"}:{}},value:e.summary||"",disabled:y&&!De&&!Se,onChange:H=>M({summary:H.target.value}),placeholder:"Brief summary"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:A.field.auditorComment}),t.jsx("textarea",{style:{...L,height:70,resize:"vertical",...y&&!Se?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:y&&!Se,onChange:H=>M({auditor_comment:H.target.value}),placeholder:A.field.commentPlaceholder})]})]})]})}function k0({ideas:e,organizations:n,departments:s,branches:l,ideaStatuses:a,initialOrg:r,initialStatus:o,canModify:d,userRole:p,onView:f,onEdit:k,onDelete:j,onSelectionChange:b}){const c=se(),[y,z]=_.useState(new Set),[C,g]=_.useState({search:"",organization:r||"",department:"",branch:"",status:o||""}),i=(u,v)=>g(I=>({...I,[u]:v})),[h,x]=_.useState(1),S=e.filter(u=>!(C.search&&!`${u.number} ${u.title}`.toLowerCase().includes(C.search.toLowerCase())||C.organization&&u.organization!==C.organization||C.department&&u.department!==C.department||C.branch&&u.branch!==C.branch||C.status&&u.status!==C.status));_.useEffect(()=>{x(1)},[C]);const w=S.slice((h-1)*de,h*de);return _.useEffect(()=>{if(b){const u=e.filter(v=>y.has(v.name));b(u,w)}},[y,w,e]),t.jsxs(t.Fragment,{children:[t.jsx(xi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.numberTitle}),t.jsx("input",{style:lt,value:C.search,onChange:u=>i("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.organization}),t.jsxs("select",{style:lt,value:C.organization,onChange:u=>i("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.department}),t.jsxs("select",{style:lt,value:C.department,onChange:u=>i("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.branch}),t.jsxs("select",{style:lt,value:C.branch,onChange:u=>i("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),l.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.status}),t.jsxs("select",{style:lt,value:C.status,onChange:u=>i("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),a.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:w.length>0&&w.every(u=>y.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...y,...w.map(v=>v.name)]));else{const v=new Set(y);w.forEach(I=>v.delete(I.name)),z(v)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:S.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noIdeas})}):w.map((u,v)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>f==null?void 0:f(u),style:{borderTop:"1px solid #f1f5f9",background:y.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":v%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:I=>I.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:y.has(u.name),onChange:()=>{const I=new Set(y);I.has(u.name)?I.delete(u.name):I.add(u.name),z(I)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx("span",{children:u.title||"—"}),u.sb_order&&t.jsxs("span",{style:{fontSize:11,background:"#f0fdf4",color:"#15803d",border:"1px solid #bbf7d0",borderRadius:9999,padding:"2px 8px",fontWeight:600},children:["📦 ",u.sb_order]})]})}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?ds(c.deletedBadge):u.status?ds(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:I=>I.stopPropagation(),children:t.jsx(ot,{onView:()=>f==null?void 0:f(u),onEdit:d&&k&&!u.custom_is_deleted&&!Jn("idea",u.workflow_state)&&!(p==="Employee"&&u.workflow_state&&u.workflow_state!=="New")?()=>k(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Ze,{page:h,total:S.length,onPageChange:x})]})}const C0={New:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Initial Evaluation":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},"Accept & Under Progress":{background:"#fefce8",color:"#92400e",border:"1px solid #fde68a"},"working on proposal":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Rejected:{background:"#fef2f2",color:"#dc2626",border:"1px solid #fecaca"},"Executed & Closed":{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function z0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...C0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function I0({ideaForm:e,setIdeaForm:n,organizations:s,groupCompanies:l=[],managements:a,departments:r,branches:o,ideaTypes:d,ideaStatuses:p,users:f=[],userRoleMap:k={},formStatus:j,viewMode:b,canModify:c,onEdit:y,onDelete:z,onRestore:C,onPermanentDelete:g,onNavigateToOrder:i,darkMode:h,notifCount:x,onToggleDark:S,onCountChange:w,onViewProfile:u,userRole:v,delegatedFunctions:I=[],delegatedOrgs:T={},onSubmit:G,onBack:K,onNavigate:le,onLogout:U,user:F,onRefresh:D}){var ne;const E=se(),A=O=>n({...e,...O}),M=b?{background:"#f9f9f9"}:{},Q=Dl(f,k,"SB Manager",e.organization),[N,ee]=_.useState(""),[Z,ce]=_.useState(!1),ae=e.name?b?`${E.formTitle.viewIdea}${e.number||e.title||e.name}`:E.formTitle.editIdea:E.formTitle.newIdea,Be=l.map(O=>({name:O.name,label:O.company_name||O.name})),$e=be(a,e.management).map(O=>({name:O.name,label:O.name1||O.name})),ut=be(r,e.department).map(O=>({name:O.name,label:O.department_name||O.name})),q=be(o,e.branch).map(O=>({name:O.name,label:O.branch||O.name})),ue=be(d,e.type).map(O=>({name:O.name,label:O.name1||O.name})),pe=e.workflow_state||"New",Ut=v==="Employee",tt=v==="Auditor"||v==="Admin",ze=v==="Manager",Mt=ze&&I.includes("idea_initial_evaluation")&&(!T.idea_initial_evaluation||(T.idea_initial_evaluation||[]).includes(e.organization)),Se=tt||Mt,De=e.name?pe==="New"?[{label:E.wf.submit,action:"Submit",color:"#2563eb"}]:pe==="Initial Evaluation"&&Se?[{label:E.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:E.wf.reject,action:"Reject",color:"#dc2626"}]:pe==="Accept & Under Progress"&&(ze||tt)?[{label:E.wf.submitSolution,action:"Submit Proposal",color:"#059669"}]:pe==="working on proposal"&&tt?[{label:E.wf.moveToOutsourcing,action:"Move to Outsourcing",color:"#0369a1"},{label:E.wf.reject,action:"Reject",color:"#dc2626"}]:[]:[];async function Zt(O){if(e.name){ce(!0),ee("");try{const ve={};O==="Assign to Manager"&&(e.assigned_to&&(ve.assigned_to=e.assigned_to),e.priority&&(ve.priority=e.priority),e.economy_class&&(ve.economy_class=e.economy_class),e.entity_scope&&(ve.entity_scope=e.entity_scope),e.hses_field&&(ve.hses_field=e.hses_field),ve.product_relation=String(e.product_relation??0),ve.repeated=String(e.repeated??0)),O==="Submit Proposal"&&(e.solution&&(ve.solution=e.solution),e.proposed_condition&&(ve.proposed_condition=e.proposed_condition),e.cost&&(ve.cost=String(e.cost))),e.auditor_comment&&(O==="Move to Outsourcing"||O==="Reject")&&(ve.auditor_comment=e.auditor_comment);const St=await Fy(e.name,O,JSON.stringify(ve));St!=null&&St.created_order&&A({sb_order:St.created_order,workflow_state:"Executed & Closed",status:"Executed & Closed"}),ee("Done"),D==null||D()}catch(ve){ee(ve.message||"Error")}finally{ce(!1)}}}const ge=((ne=Q.find(O=>O.name===e.assigned_to))==null?void 0:ne.full_name)||e.assigned_to,B=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:E.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:pe})]}),pe==="Initial Evaluation"&&Se&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:E.wf.assignToManager}),t.jsxs("select",{style:L,value:e.assigned_to||"",onChange:O=>A({assigned_to:O.target.value}),children:[t.jsx("option",{value:"",children:E.field.selectMgr}),Q.map(O=>t.jsx("option",{value:O.name,children:O.full_name||O.name},O.name))]})]}),pe==="Accept & Under Progress"&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:E.field.solution}),t.jsx("textarea",{style:{...L,height:75,resize:"vertical"},value:e.solution||"",onChange:O=>A({solution:O.target.value}),placeholder:E.field.solutionPlaceholder}),t.jsx("label",{style:{...R,marginTop:6},children:E.field.actualCost}),t.jsx("input",{type:"number",style:L,value:e.cost||"",onChange:O=>A({cost:parseFloat(O.target.value)||0}),placeholder:"0.00"})]}),pe==="working on proposal"&&tt&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:E.field.auditorComment}),t.jsx("textarea",{style:{...L,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:O=>A({auditor_comment:O.target.value}),placeholder:E.field.commentPlaceholder})]}),De.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:De.map(O=>t.jsx("button",{onClick:()=>Zt(O.action),disabled:Z,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:O.color,color:"white",fontWeight:600,fontSize:12,cursor:Z?"not-allowed":"pointer",opacity:Z?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:Z?E.wf.applying:O.label})},O.action))}):t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:E.wf.noActions}),N&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:N==="Done"?X.green:X.red},children:N})]}),t.jsx(mi,{priority:e.priority,status:pe,assignedTo:ge||(e.assigned_to?e.assigned_to:void 0),createdDate:e.date,modifiedDate:e.modified}),t.jsx(yi,{doctype:P.ideas,docname:e.name,currentUserName:F.name}),t.jsx(vi,{doctype:P.ideas,docname:e.name,docCreation:e.creation,docOwner:e.owner}),c&&z&&!e.custom_is_deleted&&t.jsx(gi,{title:"Delete Request",btnText:E.delete,onDelete:()=>z(e.name)})]}):null;return t.jsxs(et,{title:ae,activePage:"ideas",user:F,formStatus:j,statusBadge:t.jsx("span",{style:z0(pe),children:pe}),buttonText:E.saveIdea,buttonColor:"#16a34a",viewMode:b,onEdit:y,darkMode:h,notifCount:x,onToggleDark:S,onCountChange:w,onViewProfile:u,rightPanel:B,onSubmit:G,onBack:K,onNavigate:le,onLogout:U,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:C?()=>C(e.name):void 0,onPermanentDelete:g?()=>g(e.name):void 0}),e.sb_order&&t.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"8px 14px",marginBottom:16,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:12},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden"},children:[t.jsx("span",{style:{fontSize:14,flexShrink:0},children:"📦"}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,color:"#15803d",textTransform:"uppercase",letterSpacing:"0.4px",whiteSpace:"nowrap"},children:[E.field.convertedToOrder,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#14532d",whiteSpace:"nowrap"},children:e.sb_order})]}),i&&t.jsxs("button",{type:"button",onClick:()=>i(e.sb_order),style:{background:"#16a34a",color:"#fff",border:"none",borderRadius:6,padding:"4px 10px",fontWeight:600,fontSize:11,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,transition:"background 0.15s ease"},onMouseEnter:O=>O.currentTarget.style.background="#15803d",onMouseLeave:O=>O.currentTarget.style.background="#16a34a",children:[E.field.viewOrder," →"]})]}),t.jsx(oe,{title:"Idea Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.number}),t.jsx("input",{style:{...L,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:O=>A({group_company:O}),items:Be,placeholder:"Select Group Company",disabled:b||!!F.custom_group_company,userRole:v,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[E.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:O=>{var St;const ve=(St=s.find(H=>H.name===O))==null?void 0:St.group_company;A({organization:O,...F.custom_group_company?{}:{group_company:ve||e.group_company}})},organizations:s,disabled:b||!!F.custom_organization,userRole:v,onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.title}),t.jsx("input",{style:{...L,...M},value:e.title,disabled:b,onChange:O=>A({title:O.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.management}),t.jsx(re,{value:e.management,onChange:O=>A({management:O}),items:$e,placeholder:E.field.select,disabled:b,userRole:v,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.department}),t.jsx(re,{value:e.department,onChange:O=>A({department:O}),items:ut,placeholder:E.field.select,disabled:b,userRole:v,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.section}),t.jsx("input",{style:{...L,...M},value:e.section_field||"",disabled:b,onChange:O=>A({section_field:O.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.branch}),t.jsx(re,{value:e.branch,onChange:O=>A({branch:O}),items:q,placeholder:E.field.select,disabled:b,userRole:v,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.type}),t.jsx(re,{value:e.type,onChange:O=>A({type:O}),items:ue,placeholder:E.field.selectType,disabled:b,userRole:v,doctypeName:P.ideaTypes,onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.ideaClass}),t.jsxs("select",{style:{...L,...M},value:e.idea_class||"",disabled:b,onChange:O=>A({idea_class:O.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),t.jsx("option",{value:"Safety",children:"Safety"}),t.jsx("option",{value:"Non-safety",children:"Non-safety"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.hsesField}),t.jsx("input",{style:{...L,...M},value:e.hses_field||"",disabled:b,onChange:O=>A({hses_field:O.target.value}),placeholder:"Safety, Health, Environment…"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.date}),t.jsx(je,{value:e.date||"",onChange:O=>A({date:O}),disabled:!0,style:{...L,background:"#f8fafc"}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.assignedTo}),b||v==="Employee"?t.jsx("input",{style:{...L,background:"#f8fafc",fontWeight:600,color:"#334155"},value:ge||e.assigned_to||"—",readOnly:!0,disabled:!0}):t.jsx(re,{value:e.assigned_to||"",onChange:O=>A({assigned_to:O}),items:Q.map(O=>({name:O.name,label:O.full_name||O.name})),placeholder:E.field.select})]})]})}),t.jsx(oe,{title:"Condition Details & Description",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(280px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.currentCondition}),t.jsx("textarea",{style:{...L,...M,height:100,resize:"vertical"},value:e.current_condition,disabled:b,onChange:O=>A({current_condition:O.target.value}),placeholder:"Describe the current condition or problem..."})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.proposedCondition}),t.jsx("textarea",{style:{...L,...M,height:100,resize:"vertical"},value:e.proposed_condition,disabled:b,onChange:O=>A({proposed_condition:O.target.value}),placeholder:"Describe the proposed solution or improvement..."})]})]})}),!Ut&&t.jsxs(oe,{title:E.steps.auditorEval,children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.priority}),t.jsxs("select",{style:{...L,...b||!Se?{background:"#f8fafc"}:{}},value:e.priority||"",disabled:b||!Se,onChange:O=>A({priority:O.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),t.jsx("option",{value:"High",children:E.field.high}),t.jsx("option",{value:"Normal",children:E.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.economyClass}),t.jsxs("select",{style:{...L,...b||!Se?{background:"#f8fafc"}:{}},value:e.economy_class||"",disabled:b||!Se,onChange:O=>A({economy_class:O.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),t.jsx("option",{value:"Expenses",children:E.field.expenses}),t.jsx("option",{value:"Capital",children:E.field.capital}),t.jsx("option",{value:"Earn",children:E.field.earn}),t.jsx("option",{value:"Pay/Loss",children:E.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.entityScope}),t.jsxs("select",{style:{...L,...b||!Se?{background:"#f8fafc"}:{}},value:e.entity_scope||"",disabled:b||!Se,onChange:O=>A({entity_scope:O.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),t.jsx("option",{value:"Upstream",children:E.field.upstream}),t.jsx("option",{value:"On-stream",children:E.field.onstream}),t.jsx("option",{value:"Downstream",children:E.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:b||!Se,onChange:O=>A({product_relation:O.target.checked?1:0})})," ",E.field.productRelation]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:b||!Se,onChange:O=>A({repeated:O.target.checked?1:0})})," ",E.field.repeatedEvent]})]})]}),!Ut&&t.jsxs(oe,{title:E.steps.managerSolution,children:[t.jsxs("div",{style:{marginBottom:12},children:[t.jsx("label",{style:R,children:E.field.solution}),t.jsx("textarea",{style:{...L,height:90,resize:"vertical",...b&&!ze&&!tt?{background:"#f8fafc"}:{}},value:e.solution||"",disabled:b&&!ze&&!tt,onChange:O=>A({solution:O.target.value}),placeholder:E.field.solutionPlaceholder})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.actualCost}),t.jsx("input",{type:"number",style:{...L,...b&&!ze&&!tt?{background:"#f8fafc"}:{}},value:e.cost||"",disabled:b&&!ze&&!tt,onChange:O=>A({cost:parseFloat(O.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.auditorComment}),t.jsx("textarea",{style:{...L,height:60,resize:"vertical",...b&&!tt?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:b&&!tt,onChange:O=>A({auditor_comment:O.target.value}),placeholder:E.field.commentPlaceholder})]})]})]})]})}function T0({orders:e,organizations:n,departments:s,branches:l,orderStatuses:a,initialOrg:r,initialStatus:o,canModify:d,userRole:p,onView:f,onEdit:k,onDelete:j,onSelectionChange:b}){const c=se(),[y,z]=_.useState(new Set),[C,g]=_.useState({search:"",organization:r||"",department:"",branch:"",status:o||""}),i=(u,v)=>g(I=>({...I,[u]:v})),[h,x]=_.useState(1),S=e.filter(u=>!(C.search&&!`${u.number} ${u.title}`.toLowerCase().includes(C.search.toLowerCase())||C.organization&&u.organization!==C.organization||C.department&&u.department!==C.department||C.branch&&u.branch!==C.branch||C.status&&u.status!==C.status));_.useEffect(()=>{x(1)},[C]);const w=S.slice((h-1)*de,h*de);return _.useEffect(()=>{if(b){const u=e.filter(v=>y.has(v.name));b(u,w)}},[y,w,e]),t.jsxs(t.Fragment,{children:[t.jsx(xi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.numberTitle}),t.jsx("input",{style:lt,value:C.search,onChange:u=>i("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.organization}),t.jsxs("select",{style:lt,value:C.organization,onChange:u=>i("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.department}),t.jsxs("select",{style:lt,value:C.department,onChange:u=>i("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.branch}),t.jsxs("select",{style:lt,value:C.branch,onChange:u=>i("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),l.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.status}),t.jsxs("select",{style:lt,value:C.status,onChange:u=>i("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),a.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:w.length>0&&w.every(u=>y.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...y,...w.map(v=>v.name)]));else{const v=new Set(y);w.forEach(I=>v.delete(I.name)),z(v)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.type}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:S.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noOrders})}):w.map((u,v)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>f==null?void 0:f(u),style:{borderTop:"1px solid #f1f5f9",background:y.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":v%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:I=>I.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:y.has(u.name),onChange:()=>{const I=new Set(y);I.has(u.name)?I.delete(u.name):I.add(u.name),z(I)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx("span",{children:u.title||u.name||"—"}),u.sb_idea&&t.jsxs("span",{style:{fontSize:11,background:"#eff6ff",color:"#1d4ed8",border:"1px solid #bfdbfe",borderRadius:9999,padding:"2px 8px",fontWeight:600},children:["💡 ",u.sb_idea]})]})}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.type?ac(u.type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?ds(c.deletedBadge):u.status?ds(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:I=>I.stopPropagation(),children:t.jsx(ot,{onView:()=>f==null?void 0:f(u),onEdit:d&&k&&!u.custom_is_deleted&&!Jn("order",u.workflow_state)&&p!=="Employee"?()=>k(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Ze,{page:h,total:S.length,onPageChange:x})]})}const E0={1:"Initiation / Bidding",2:"Execution begins",3:"Mid-execution review",4:"Near completion",5:"Closing"},A0={Draft:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Pending Actor":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},Review:{background:"#fefce8",color:"#92400e",border:"1px solid #fde68a"},"In Study":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Closed:{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function P0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...A0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function R0({orderForm:e,setOrderForm:n,organizations:s,groupCompanies:l=[],managements:a,departments:r,branches:o,orderTypes:d,orderStatuses:p,cycles:f=[],users:k=[],userRoleMap:j={},formStatus:b,viewMode:c,canModify:y,onEdit:z,onDelete:C,onRestore:g,onPermanentDelete:i,onNavigateToIdea:h,darkMode:x,notifCount:S,onToggleDark:w,onCountChange:u,onViewProfile:v,currentUser:I,userRole:T,onSubmit:G,onBack:K,onNavigate:le,onLogout:U,user:F,onRefresh:D}){var Fa,$l;const E=se(),A=W=>n({...e,...W}),M=c?{background:"#f9f9f9"}:{},Q=Dl(k,j,"SB Employee",e.organization),[N,ee]=_.useState(""),[Z,ce]=_.useState(""),[ae,Be]=_.useState(!1),[$e,ut]=_.useState("Agree"),q=e.name?c?`${E.formTitle.viewOrder}${e.number||e.title||e.name}`:E.formTitle.editOrder:E.formTitle.newOrder,ue=l.map(W=>({name:W.name,label:W.company_name||W.name})),pe=be(a,e.management).map(W=>({name:W.name,label:W.name1||W.name})),Ut=be(r,e.department).map(W=>({name:W.name,label:W.department_name||W.name})),tt=be(o,e.branch).map(W=>({name:W.name,label:W.branch||W.name})),ze=be(d,e.type).map(W=>({name:W.name,label:W.name1||W.name})),Mt=["SAR","USD","EUR","AED","GBP","KWD","BHD","QAR","OMR","EGP"],Se=Array.from(new Set([...Mt,e.currency].filter(Boolean))).map(W=>({name:W,label:W})),De=be(f,e.cycle).map(W=>({name:W.name,label:W.name1||W.cycle_name||W.name})),Zt=!!e.name,ge=e.workflow_state||"Draft",B=Math.min(5,(e.stage||0)+1),[ne,O]=_.useState(B);_.useEffect(()=>{O(Math.min(5,(e.stage||0)+1))},[e.stage]);const ve=T==="Auditor"||T==="Admin"||T==="Manager",St=ve||T==="Owner",H=!!(I&&(e.actor===I||e.assigned_to===I)),Ue=e.stage===5||e.completion_pct===100||e.status==="Completion"||ge==="Completed"||ge==="Closed",Pt=e.order_cycle_log||[],fs=Pt.length>0?Pt[Pt.length-1].status:$e,_n=fs==="Deviate"||fs==="Deviated"||fs==="Unknown",$a=(()=>{if(!Zt)return[];if(ge==="Closed"||ge==="Completed")return[];if(ge==="Draft"&&ve)return[{label:"Submit for Review",action:"Submit for Review",color:"#2563eb"}];if(ge==="Pending Actor"&&(H||ve))return[{label:"Update Status",action:"Update Status",color:"#d97706"}];if(ge==="Review"&&St){const W=[{label:"Move to Study",action:"Move to Study",color:"#059669"}];return(!Ue||_n)&&W.push({label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}),Ue&&W.push({label:"Close Order",action:"Close Order",color:"#475569"}),W}if(ge==="In Study"&&St){const W=[];return(!Ue||_n)&&W.push({label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}),W.push({label:"Close Order",action:"Close Order",color:"#475569"}),W}return[]})();async function Us(W){if(e.name){Be(!0),ee("");try{let gt;W==="Update Status"&&(gt=$e);const wn=await Uy(e.name,W,Z,W==="Update Status"?String(ne):void 0,void 0,gt);if(ce(""),ut("Agree"),ee("Done"),wn){const Ft=wn;n({...e,...Ft,stage:Ft.stage??e.stage,completion_pct:Ft.completion_pct??e.completion_pct,workflow_state:Ft.workflow_state??e.workflow_state})}D==null||D()}catch(gt){ee(gt.message||"Error")}finally{Be(!1)}}}const Ua=((Fa=Q.find(W=>W.name===(e.actor||e.assigned_to)))==null?void 0:Fa.full_name)||e.actor||e.assigned_to,Ma=Zt?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:E.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:ge})]}),ge==="Pending Actor"&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:12},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:["Stage (1–5) — ",ne*20,"% complete"]}),t.jsx("input",{type:"number",min:1,max:5,style:{...L,width:"100%"},value:ne,onChange:W=>O(Math.min(5,Math.max(1,parseInt(W.target.value)||1)))})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Cycle Status"}),t.jsxs("select",{style:L,value:$e,onChange:W=>ut(W.target.value),children:[t.jsx("option",{value:"Agree",children:"✅ Agree — on track"}),t.jsx("option",{value:"Deviate",children:"⚠️ Deviate — off plan"}),t.jsx("option",{value:"Unknown",children:"❓ Unknown"})]})]})]}),t.jsxs("div",{style:{marginBottom:12},children:[t.jsxs("label",{style:R,children:["Comment ",$e==="Deviate"&&ge==="Pending Actor"?t.jsx("span",{style:{color:X.red},children:" * required for Deviate"}):"(optional)"]}),t.jsx("textarea",{style:{...L,height:60,resize:"vertical",borderColor:$e==="Deviate"&&!Z?"#fca5a5":void 0},value:Z,onChange:W=>ce(W.target.value),placeholder:"Add a comment…"})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:$a.map(W=>{const gt=W.action==="Update Status"&&$e==="Deviate"&&!Z.trim();return t.jsx("button",{onClick:()=>Us(W.action),disabled:ae||gt,title:gt?"Comment required when status is Deviate":void 0,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:W.color,color:"white",fontWeight:600,fontSize:12,cursor:ae||gt?"not-allowed":"pointer",opacity:ae||gt?.5:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:ae?E.wf.applying:W.label})},W.action)})}),N&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:N==="Done"?X.green:X.red},children:N}),$a.length===0&&t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:E.wf.noActions})]}),t.jsx(mi,{priority:e.priority,status:ge,assignedTo:T!=="Employee"?Ua:void 0,createdDate:e.starting_date,modifiedDate:e.modified}),t.jsx(yi,{doctype:P.orders,docname:e.name,currentUserName:F.name}),t.jsx(vi,{doctype:P.orders,docname:e.name,docCreation:e.creation,docOwner:e.owner}),y&&C&&!e.custom_is_deleted&&t.jsx(gi,{title:"Delete Request",btnText:E.delete,onDelete:()=>C(e.name)})]}):null;return t.jsxs(et,{title:q,activePage:"orders",user:F,formStatus:b,statusBadge:t.jsx("span",{style:P0(ge),children:ge}),buttonText:E.saveOrder,buttonColor:"#16a34a",viewMode:c,onEdit:z,darkMode:x,notifCount:S,onToggleDark:w,onCountChange:u,onViewProfile:v,rightPanel:Ma,onSubmit:G,onBack:K,onNavigate:le,onLogout:U,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:g?()=>g(e.name):void 0,onPermanentDelete:i?()=>i(e.name):void 0}),e.sb_idea&&t.jsxs("div",{style:{background:"#f0f7ff",border:"1px solid #bfdbfe",borderRadius:8,padding:"8px 14px",marginBottom:16,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:12},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden"},children:[t.jsx("span",{style:{fontSize:14,flexShrink:0},children:"💡"}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,color:"#1e40af",textTransform:"uppercase",letterSpacing:"0.4px",whiteSpace:"nowrap"},children:[E.field.originatingIdea,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#1e3a8a",whiteSpace:"nowrap"},children:e.sb_idea})]}),h&&t.jsxs("button",{type:"button",onClick:()=>h(e.sb_idea),style:{background:"#2563eb",color:"#fff",border:"none",borderRadius:6,padding:"4px 10px",fontWeight:600,fontSize:11,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,transition:"background 0.15s ease"},onMouseEnter:W=>W.currentTarget.style.background="#1d4ed8",onMouseLeave:W=>W.currentTarget.style.background="#2563eb",children:[E.field.viewIdea," →"]})]}),t.jsx(oe,{title:"Order Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.number}),t.jsx("input",{style:{...L,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:W=>A({group_company:W}),items:ue,placeholder:"Select Group Company",disabled:c||!!F.custom_group_company,userRole:T,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[E.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:W=>{var wn;const gt=(wn=s.find(Ft=>Ft.name===W))==null?void 0:wn.group_company;A({organization:W,...F.custom_group_company?{}:{group_company:gt||e.group_company}})},organizations:s,disabled:c||!!F.custom_organization,userRole:T,onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.title}),t.jsx("input",{style:{...L,...M},value:e.title,disabled:c,onChange:W=>A({title:W.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.management}),t.jsx(re,{value:e.management,onChange:W=>A({management:W}),items:pe,placeholder:E.field.select,disabled:c,userRole:T,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.department}),t.jsx(re,{value:e.department,onChange:W=>A({department:W}),items:Ut,placeholder:E.field.select,disabled:c,userRole:T,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.section}),t.jsx("input",{style:{...L,...M},value:e.section_field||"",disabled:c,onChange:W=>A({section_field:W.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.branch}),t.jsx(re,{value:e.branch,onChange:W=>A({branch:W}),items:tt,placeholder:E.field.select,disabled:c,userRole:T,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.type}),t.jsx(re,{value:e.type,onChange:W=>A({type:W}),items:ze,placeholder:E.field.selectType,disabled:c,userRole:T,doctypeName:P.orderTypes,onQuickCreateSuccess:D})]})]})}),t.jsxs(oe,{title:"Financial & Schedule",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.budget}),t.jsx("input",{type:"number",style:{...L,...M},value:e.budget||"",disabled:c,onChange:W=>A({budget:parseFloat(W.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.actualCost}),t.jsx("input",{type:"number",style:{...L,...M},value:e.actual_cost||"",disabled:c,onChange:W=>A({actual_cost:parseFloat(W.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Variance"}),(()=>{const W=(e.budget||0)-(e.actual_cost||0);return t.jsxs("div",{style:{padding:"7px 12px",borderRadius:6,fontWeight:700,fontSize:13,background:W>=0?"#f0fdf4":"#fef2f2",color:W>=0?"#166534":"#dc2626",border:`1px solid ${W>=0?"#bbf7d0":"#fecaca"}`,display:"inline-block",width:"100%",boxSizing:"border-box"},children:[W>=0?"+":"",W.toFixed(2)]})})()]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.currency}),t.jsx(re,{value:e.currency||"",onChange:W=>A({currency:W}),items:Se,placeholder:E.field.select,disabled:c,userRole:T,doctypeName:P.currency,onQuickCreateSuccess:D})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.startingDate}),t.jsx(je,{value:e.starting_date,onChange:W=>A({starting_date:W}),disabled:c,style:{...L,...M}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.endingDate}),t.jsx(je,{value:e.ending_date,onChange:W=>A({ending_date:W}),disabled:c,style:{...L,...M}})]}),T!=="Employee"&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.actor}),c?t.jsx("input",{style:{...L,background:"#f8fafc",fontWeight:600,color:"#334155"},value:Ua||"—",readOnly:!0,disabled:!0}):t.jsxs("select",{style:{...L,background:"#ffffff"},value:e.actor||e.assigned_to||"",onChange:W=>A({actor:W.target.value,assigned_to:W.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),Q.map(W=>t.jsx("option",{value:W.name,children:W.full_name||W.name},W.name))]})]})]})]}),t.jsxs(oe,{title:"Classification",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.priority}),t.jsxs("select",{style:{...L,...M},value:e.priority||"",disabled:c,onChange:W=>A({priority:W.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),t.jsx("option",{value:"High",children:E.field.high}),t.jsx("option",{value:"Normal",children:E.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.economyClass}),t.jsxs("select",{style:{...L,...M},value:e.economy_class||"",disabled:c,onChange:W=>A({economy_class:W.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),t.jsx("option",{value:"Expenses",children:E.field.expenses}),t.jsx("option",{value:"Capital",children:E.field.capital}),t.jsx("option",{value:"Earn",children:E.field.earn}),t.jsx("option",{value:"Pay/Loss",children:E.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.entityScope}),t.jsxs("select",{style:{...L,...M},value:e.entity_scope||"",disabled:c,onChange:W=>A({entity_scope:W.target.value}),children:[t.jsx("option",{value:"",children:E.field.select}),t.jsx("option",{value:"Upstream",children:E.field.upstream}),t.jsx("option",{value:"On-stream",children:E.field.onstream}),t.jsx("option",{value:"Downstream",children:E.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:24,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.planned,disabled:c,onChange:W=>A({planned:W.target.checked?1:0})})," Planned"]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:W=>A({product_relation:W.target.checked?1:0})})," ",E.field.productRelation]})]}),t.jsxs("div",{style:{marginTop:12},children:[t.jsx("label",{style:R,children:E.field.hsesField}),t.jsx("input",{style:{...L,...M},value:e.hses_field||"",disabled:c,onChange:W=>A({hses_field:W.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),t.jsxs(oe,{title:"Cycle & Progress Tracking",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.cycle}),t.jsx(re,{value:e.cycle||"",onChange:W=>A({cycle:W}),items:De,placeholder:E.field.select,disabled:c,userRole:T,doctypeName:P.cycles,extraFields:{organization:e.organization},onQuickCreateSuccess:D})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.cycleType}),t.jsxs("select",{style:{...L,...M},value:e.cycle_type||"Normal",disabled:c,onChange:W=>A({cycle_type:W.target.value}),children:[t.jsx("option",{value:"Normal",children:"Normal"}),t.jsx("option",{value:"Long",children:"Long"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.stage}),t.jsx("input",{type:"number",min:1,max:5,style:{...L,background:"#f8fafc",color:"#334155",fontWeight:600},value:e.stage||1,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Completion"}),t.jsx("input",{style:{...L,background:"#f8fafc",color:"#334155",fontWeight:600},value:`${e.completion_pct||(e.stage||1)*20}%`,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Stage Description"}),t.jsx("span",{style:{display:"inline-block",padding:"7px 12px",borderRadius:6,fontSize:13,fontWeight:600,background:"#f0f9ff",color:"#0369a1",border:"1px solid #bae6fd",width:"100%",boxSizing:"border-box"},children:E0[e.stage||1]||"—"})]})]}),e.cycle_type==="Long"&&t.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14,marginBottom:14},children:[t.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 1"}),t.jsx(je,{value:e.long_cycle_date_1||"",onChange:W=>A({long_cycle_date_1:W}),disabled:c,style:{...L,...M}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 2"}),t.jsx(je,{value:e.long_cycle_date_2||"",onChange:W=>A({long_cycle_date_2:W}),disabled:c,style:{...L,...M}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 3"}),t.jsx(je,{value:e.long_cycle_date_3||"",onChange:W=>A({long_cycle_date_3:W}),disabled:c,style:{...L,...M}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 4"}),t.jsx(je,{value:e.long_cycle_date_4||"",onChange:W=>A({long_cycle_date_4:W}),disabled:c,style:{...L,...M}})]})]})]}),Zt&&(($l=e.order_cycle_log)==null?void 0:$l.length)>0&&t.jsxs("div",{style:{borderTop:"1px solid #f1f5f9",paddingTop:14,marginTop:10},children:[t.jsx("p",{style:{fontWeight:700,color:"#334155",fontSize:13,marginBottom:10},children:"Cycle History"}),t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8fafc"},children:["Cycle","Date","Stage","Status","Actor","Comment"].map(W=>t.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:600,color:"#475569",borderBottom:"1px solid #e2e8f0"},children:W},W))})}),t.jsx("tbody",{children:(e.order_cycle_log||[]).map((W,gt)=>{const wn=W.status==="Agree"?"#166534":W.status==="Deviate"?"#c2410c":"#92400e",Ft=W.status==="Agree"?"#f0fdf4":W.status==="Deviate"?"#fff7ed":"#fefce8";return t.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:W.cycle||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:W.cycle_date||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155",textAlign:"center"},children:W.stage||"—"}),t.jsx("td",{style:{padding:"6px 10px"},children:t.jsx("span",{style:{background:Ft,color:wn,padding:"2px 8px",borderRadius:12,fontWeight:600,fontSize:12},children:W.status||"—"})}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:W.actor||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#64748b",fontStyle:W.comment?"normal":"italic"},children:W.comment||"—"})]},gt)})})]})})]})]}),t.jsxs(oe,{title:"Description & Notes",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(280px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.description}),t.jsx("textarea",{style:{...L,...M,height:90,resize:"vertical"},value:e.description,disabled:c,onChange:W=>A({description:W.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.notes}),t.jsx("textarea",{style:{...L,...M,height:90,resize:"vertical"},value:e.notes,disabled:c,onChange:W=>A({notes:W.target.value})})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:E.field.auditorComment}),t.jsx("textarea",{style:{...L,height:70,resize:"vertical",...c&&H&&!ve?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:c&&H&&!ve,onChange:W=>A({auditor_comment:W.target.value}),placeholder:E.field.commentPlaceholder})]})]})]})}function D0({processes:e,organizations:n,departments:s,branches:l,processStatuses:a,initialOrg:r,initialStatus:o,canModify:d,userRole:p,onView:f,onEdit:k,onDelete:j,onSelectionChange:b}){const c=se(),[y,z]=_.useState(new Set),[C,g]=_.useState({search:"",organization:r||"",department:"",branch:"",status:o||""}),i=(u,v)=>g(I=>({...I,[u]:v})),[h,x]=_.useState(1),S=e.filter(u=>!(C.search&&!`${u.number} ${u.title}`.toLowerCase().includes(C.search.toLowerCase())||C.organization&&u.organization!==C.organization||C.department&&u.department!==C.department||C.branch&&u.branch!==C.branch||C.status&&u.status!==C.status));_.useEffect(()=>{x(1)},[C]);const w=S.slice((h-1)*de,h*de);return _.useEffect(()=>{if(b){const u=e.filter(v=>y.has(v.name));b(u,w)}},[y,w,e]),t.jsxs(t.Fragment,{children:[t.jsx(xi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.numberTitle}),t.jsx("input",{style:lt,value:C.search,onChange:u=>i("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.organization}),t.jsxs("select",{style:lt,value:C.organization,onChange:u=>i("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.department}),t.jsxs("select",{style:lt,value:C.department,onChange:u=>i("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.branch}),t.jsxs("select",{style:lt,value:C.branch,onChange:u=>i("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),l.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:st,children:c.filter.status}),t.jsxs("select",{style:lt,value:C.status,onChange:u=>i("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),a.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:w.length>0&&w.every(u=>y.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...y,...w.map(v=>v.name)]));else{const v=new Set(y);w.forEach(I=>v.delete(I.name)),z(v)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.field.cycleType}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:S.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noProcesses})}):w.map((u,v)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>f==null?void 0:f(u),style:{borderTop:"1px solid #f1f5f9",background:y.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":v%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:I=>I.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:y.has(u.name),onChange:()=>{const I=new Set(y);I.has(u.name)?I.delete(u.name):I.add(u.name),z(I)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:u.title||u.name||"—"}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.cycle_type?ac(u.cycle_type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?ds(c.deletedBadge):u.status?ds(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:I=>I.stopPropagation(),children:t.jsx(ot,{onView:()=>f==null?void 0:f(u),onEdit:d&&k&&!u.custom_is_deleted&&!Jn("process",u.workflow_state)&&p!=="Employee"?()=>k(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Ze,{page:h,total:S.length,onPageChange:x})]})}const O0={Draft:[{action:"Submit for Review",next:"Pending Actor",allowedRoles:["Auditor","Manager"]}],"Pending Actor":[{action:"Update Status",next:"Pending Comment",allowedRoles:["Employee","Manager"]}],"Pending Comment":[{action:"Add Comment",next:"Review",allowedRoles:["Auditor","Manager"]}],Review:[{action:"Start New Cycle",next:"Pending Actor",allowedRoles:["Auditor","Manager"]},{action:"Move to Study",next:"In Study",allowedRoles:["Auditor","Manager"]},{action:"Close Process",next:"Closed",allowedRoles:["Auditor","Manager"]}],"In Study":[{action:"Start New Cycle",next:"Pending Actor",allowedRoles:["Auditor","Manager"]},{action:"Close Process",next:"Closed",allowedRoles:["Auditor","Manager"]}]},L0={Draft:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Pending Actor":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},"Pending Comment":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Review:{background:"#f0fdf4",color:"#15803d",border:"1px solid #bbf7d0"},"In Study":{background:"#f1f5f9",color:"#475569",border:"1px solid #cbd5e1"},Completed:{background:"#ecfdf5",color:"#047857",border:"1px solid #a7f3d0"},Closed:{background:"#f3f4f6",color:"#6b7280",border:"1px solid #9ca3af"}};function Du(e){return{display:"inline-block",padding:"5px 14px",borderRadius:20,fontSize:13,fontWeight:700,...L0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}const ur={width:"100%",padding:"6px 8px",border:"1px solid #d1d5db",borderRadius:5,fontSize:12,fontFamily:"Segoe UI",boxSizing:"border-box"};function N0({processName:e,userRole:n,onRefresh:s,canUpdateStatus:l=!0}){const[a,r]=_.useState(null),[o,d]=_.useState(!0),[p,f]=_.useState(""),[k,j]=_.useState(!1),[b,c]=_.useState(""),[y,z]=_.useState(""),[C,g]=_.useState("Pass"),[i,h]=_.useState(""),[x,S]=_.useState({}),w=_.useCallback(async()=>{if(!e){d(!1);return}d(!0),f("");try{const U=await aa(e);r(U);const F={};for(const D of U.progress_indicators||[])F[D.name]=D.actual_value!=null?String(D.actual_value):"";S(F)}catch(U){f(U instanceof Error?U.message:"Failed to load process")}d(!1)},[e]);if(_.useEffect(()=>{w()},[w]),o)return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:24,color:"#aaa",fontSize:13,textAlign:"center"},children:"Loading…"})});if(p||!a)return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:16},children:t.jsx("div",{style:{fontSize:12,color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px"},children:p||"Could not load workflow"})})});const u=a.workflow_state||"Draft",v=O0[u]??[],I=n==="Employee"||n==="Manager",T=n!=="Manager"||l,G=a.completion_pct===100||a.stage===5||a.status==="Completion"||a.status==="Completed"||u==="Completed"||u==="Closed",K=v.filter(U=>U.action==="Start New Cycle"&&G?!1:(n==="Admin"||U.allowedRoles.includes(n))&&(U.action!=="Update Status"||T)),le=async U=>{j(!0),c(""),z("");try{const F={};if(U==="Update Status"){F.actor_status=C,F.actor_comment=i;const E=a.progress_indicators||[];E.length>0&&(F.progress_indicators=E.map(A=>({name:A.name,actual_value:x[A.name]??""})))}U==="Add Comment"&&i&&(F.actor_comment=i);const D=await n0(a.name,U,F);r(D),h(""),z(`Done — now: ${D.workflow_state||"updated"}`),s==null||s()}catch(F){c(F instanceof Error?F.message:"Action failed")}j(!1)};return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsx("div",{style:{background:"#1a2332",color:"white",padding:"10px 14px",fontSize:12,fontWeight:700,letterSpacing:.3},children:"Workflow"}),t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:8},children:"Current State"}),t.jsx("div",{style:Du(u),children:u})]}),u==="Pending Actor"&&I&&T&&t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Update Status"}),Array.isArray(a.progress_indicators)&&a.progress_indicators.length>0&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Actual Value"}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:a.progress_indicators.map(U=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{fontSize:11,color:"#555",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:U.name1,children:U.name1||U.name}),t.jsx("input",{type:"number",value:x[U.name]??"",onChange:F=>S(D=>({...D,[U.name]:F.target.value})),style:{...ur,width:70,flexShrink:0},placeholder:"0"})]},U.name))})]}),t.jsxs("div",{style:{marginBottom:8},children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Cycle Status"}),t.jsxs("select",{value:C,onChange:U=>g(U.target.value),style:ur,children:[t.jsx("option",{value:"Pass",children:"✅ Pass — on target"}),t.jsx("option",{value:"Fail",children:"❌ Fail — off target"})]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Comment (optional)"}),t.jsx("textarea",{value:i,onChange:U=>h(U.target.value),style:{...ur,height:52,resize:"vertical"},placeholder:"Add a comment…"})]})]}),(u==="Pending Comment"||u==="Review")&&!I&&t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Auditor Comment"}),Array.isArray(a.cycle_logs)&&a.cycle_logs.length>0&&t.jsxs("div",{style:{marginBottom:8,padding:"6px 10px",background:"#f8fafc",borderRadius:6,border:"1px solid #e2e8f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",marginBottom:3},children:"Latest cycle status:"}),(()=>{const U=a.cycle_logs,F=U[U.length-1],D=F.status==="Pass"?"#16a34a":F.status==="Fail"?"#dc2626":"#9ca3af";return t.jsxs("div",{style:{fontSize:13,fontWeight:700,color:D},children:[F.status," ",F.comment?`— ${F.comment}`:""]})})()]}),t.jsx("textarea",{value:i,onChange:U=>h(U.target.value),style:{...ur,height:52,resize:"vertical"},placeholder:"Add a comment…"})]}),t.jsxs("div",{style:{padding:"12px 14px",borderBottom:K.length>0?"1px solid #f0f0f0":"none"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Actions"}),K.length===0&&t.jsxs("div",{style:{fontSize:12,color:"#aaa",fontStyle:"italic",lineHeight:1.5},children:["No actions for ",t.jsx("strong",{children:n})," in ",t.jsx("strong",{children:u}),"."]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:K.map(U=>t.jsxs("button",{onClick:()=>le(U.action),disabled:k,style:{width:"100%",padding:"10px 14px",borderRadius:6,border:"none",background:U.action==="Close Process"?"#64748b":U.action==="Move to Study"?"#8e44ad":"#2563eb",color:"white",cursor:k?"not-allowed":"pointer",fontSize:13,fontWeight:600,opacity:k?.7:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("span",{children:k?"Applying…":U.action}),t.jsxs("span",{style:{fontSize:10,opacity:.7},children:["→ ",U.next]})]},U.action))}),b&&t.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,fontSize:12,color:"#991b1b",lineHeight:1.4},children:b}),y&&t.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,fontSize:12,color:"#166534"},children:y})]}),v.length>0&&t.jsxs("div",{style:{padding:"12px 14px"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Next States"}),v.map(U=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6,fontSize:11},children:[t.jsx("span",{style:{color:"#555",flex:1},children:U.action}),t.jsx("span",{style:{color:"#bbb"},children:"→"}),t.jsx("span",{style:Du(U.next),children:U.next})]},U.action))]})]})})}function W0({processForm:e,setProcessForm:n,organizations:s,groupCompanies:l=[],managements:a,departments:r,branches:o,processTypes:d,processStatuses:p,cycles:f=[],users:k=[],userRoleMap:j={},formStatus:b,viewMode:c,canModify:y,onEdit:z,onDelete:C,onRestore:g,onPermanentDelete:i,darkMode:h,notifCount:x,onToggleDark:S,onCountChange:w,onViewProfile:u,userRole:v,onRefreshProcess:I,onSubmit:T,onBack:G,onNavigate:K,onLogout:le,user:U}){var ge;const F=se(),D=B=>n({...e,...B}),E=c?{background:"#f9f9f9"}:{},A=s,M=!!U.custom_organization,Q=l.map(B=>({name:B.name,label:B.company_name||B.name})),N=be(a,e.management).map(B=>({name:B.name,label:B.name1||B.name})),ee=be(r,e.department).map(B=>({name:B.name,label:B.department_name||B.name})),Z=be(o,e.branch).map(B=>({name:B.name,label:B.branch||B.name})),ce=be(d,e.type).map(B=>({name:B.name,label:B.name1||B.name})),ae=be(f,e.cycle).map(B=>({name:B.name,label:B.name1||B.name})),Be=Dl(k,j,"SB Employee",e.organization).map(B=>({name:B.name,label:B.full_name||B.name})),$e=Dl(k,j,"SB Manager",e.organization).map(B=>({name:B.name,label:B.full_name||B.name})),ut=(B,ne)=>{const O=[...e.cycle_logs||[]];O[B]={...O[B],...ne},D({cycle_logs:O})},q=()=>{D({cycle_logs:[...e.cycle_logs||[],{cycle:"",cycle_date:"",status:"Pass",actor:"",comment:""}]})},ue=B=>{const ne=[...e.cycle_logs||[]];ne.splice(B,1),D({cycle_logs:ne})},pe=(B,ne)=>{const O=[...e.progress_indicators||[]];O[B]={...O[B],...ne},D({progress_indicators:O})},Ut=()=>{D({progress_indicators:[...e.progress_indicators||[],{name1:"",type:"",unit:"",cycle:"",target:"",maximum:"",minimum:"",manager:"",order:"",actual_value:"",cycle_status:"Pass",cycle_date:"",cycle_comment:"",status:"Active"}]})},tt=B=>{const ne=[...e.progress_indicators||[]];ne.splice(B,1),D({progress_indicators:ne})},ze=e.name?c?`${F.formTitle.viewProcess}${e.title||e.name}`:F.formTitle.editProcess:F.formTitle.newProcess,Mt=v!=="Manager"||e.actor===U.name,Se=((ge=Be.find(B=>B.name===e.actor))==null?void 0:ge.label)||e.actor,De=e.workflow_state||"Draft",Zt=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsx(N0,{processName:e.name,userRole:v||U.role||"Employee",onRefresh:I,canUpdateStatus:Mt}),t.jsx(mi,{priority:e.impact_level,status:De,assignedTo:Se,createdDate:e.date_start,modifiedDate:e.modified}),t.jsx(yi,{doctype:P.processes,docname:e.name,currentUserName:U.name}),t.jsx(vi,{doctype:P.processes,docname:e.name,docCreation:e.creation,docOwner:e.owner}),y&&C&&!e.custom_is_deleted&&t.jsx(gi,{title:"Delete Request",btnText:F.delete,onDelete:()=>C(e.name)})]}):void 0;return t.jsxs(et,{title:ze,activePage:"processes",user:U,formStatus:b,statusBadge:t.jsx("span",{style:{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},children:De}),buttonText:F.saveProcess,buttonColor:"#16a34a",viewMode:c,onEdit:z,darkMode:h,notifCount:x,onToggleDark:S,onCountChange:w,onViewProfile:u,rightPanel:Zt,onSubmit:T,onBack:G,onNavigate:K,onLogout:le,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:g?()=>g(e.name):void 0,onPermanentDelete:i?()=>i(e.name):void 0}),t.jsx(oe,{title:"Process Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.number}),t.jsx("input",{style:{...L,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number||"",readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:B=>D({group_company:B}),items:Q,placeholder:"Select Group Company",disabled:c||!!U.custom_group_company,userRole:v,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[F.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:B=>{var O;const ne=(O=s.find(ve=>ve.name===B))==null?void 0:O.group_company;D({organization:B,...U.custom_group_company?{}:{group_company:ne||e.group_company}})},organizations:A,disabled:c||M,userRole:v,onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.title}),t.jsx("input",{style:{...L,...E},value:e.title,disabled:c,onChange:B=>D({title:B.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.type}),t.jsx(re,{value:e.type,onChange:B=>D({type:B}),items:ce,placeholder:F.field.selectType,disabled:c,userRole:v,doctypeName:P.processTypes,onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.management}),t.jsx(re,{value:e.management,onChange:B=>D({management:B}),items:N,placeholder:F.field.select,disabled:c,userRole:v,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.department}),t.jsx(re,{value:e.department,onChange:B=>D({department:B}),items:ee,placeholder:F.field.select,disabled:c,userRole:v,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.section}),t.jsx("input",{style:{...L,...E},value:e.section_field||"",disabled:c,onChange:B=>D({section_field:B.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.branch}),t.jsx(re,{value:e.branch,onChange:B=>D({branch:B}),items:Z,placeholder:F.field.select,disabled:c,userRole:v,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:I})]})]})}),t.jsxs(oe,{title:"Classification",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.chainLocation}),t.jsxs("select",{style:{...L,...E},value:e.chain_location||"",disabled:c,onChange:B=>D({chain_location:B.target.value}),children:[t.jsx("option",{value:"",children:F.field.select}),t.jsx("option",{value:"Upstream",children:"Upstream"}),t.jsx("option",{value:"On-stream",children:"On-stream"}),t.jsx("option",{value:"Downstream",children:"Downstream"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.economyClass}),t.jsxs("select",{style:{...L,...E},value:e.economy_class||"",disabled:c,onChange:B=>D({economy_class:B.target.value}),children:[t.jsx("option",{value:"",children:F.field.select}),t.jsx("option",{value:"Expenses",children:F.field.expenses}),t.jsx("option",{value:"Capital",children:F.field.capital}),t.jsx("option",{value:"Earn",children:F.field.earn}),t.jsx("option",{value:"Pay/Loss",children:F.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.impactLevel}),t.jsxs("select",{style:{...L,...E},value:e.impact_level||"",disabled:c,onChange:B=>D({impact_level:B.target.value}),children:[t.jsx("option",{value:"",children:F.field.select}),t.jsx("option",{value:"High",children:F.field.high}),t.jsx("option",{value:"Normal",children:F.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.entityScope}),t.jsxs("select",{style:{...L,...E},value:e.entity_scope||"",disabled:c,onChange:B=>D({entity_scope:B.target.value}),children:[t.jsx("option",{value:"",children:F.field.select}),t.jsx("option",{value:"Upstream",children:F.field.upstream}),t.jsx("option",{value:"On-stream",children:F.field.onstream}),t.jsx("option",{value:"Downstream",children:F.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,alignItems:"center"},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.hsesField}),t.jsx("input",{style:{...L,...E},value:e.hses_field||"",disabled:c,onChange:B=>D({hses_field:B.target.value}),placeholder:"Safety, Health, Environment…"})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,paddingTop:18},children:t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:B=>D({product_relation:B.target.checked?1:0})})," ",F.field.productRelation]})})]})]}),t.jsxs(oe,{title:"KPI & Timeline",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.kpiName}),t.jsx("input",{style:{...L,...E},value:e.kpi_name||"",disabled:c,onChange:B=>D({kpi_name:B.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.kpiType}),t.jsxs("select",{style:{...L,...E},value:e.kpi_type||"",disabled:c,onChange:B=>D({kpi_type:B.target.value}),children:[t.jsx("option",{value:"",children:F.field.select}),t.jsx("option",{value:"Human",children:"Human"}),t.jsx("option",{value:"Substantial",children:"Substantial"}),t.jsx("option",{value:"System",children:"System"}),t.jsx("option",{value:"Value",children:"Value"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.kpiMeasure}),t.jsx("input",{style:{...L,...E},value:e.kpi_measure||"",disabled:c,onChange:B=>D({kpi_measure:B.target.value}),placeholder:"Unit of measure"})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.dateStart}),t.jsx(je,{value:e.date_start,onChange:B=>D({date_start:B}),disabled:c,style:{...L,...E}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.dateEnd}),t.jsx(je,{value:e.date_end,onChange:B=>D({date_end:B}),disabled:c,style:{...L,...E}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.cycleType}),t.jsxs("select",{style:{...L,...E},value:e.cycle_type||"",disabled:c,onChange:B=>D({cycle_type:B.target.value}),children:[t.jsx("option",{value:"",children:F.field.select}),t.jsx("option",{value:"Normal",children:"Normal"}),t.jsx("option",{value:"Long",children:"Long"})]})]})]}),e.cycle_type==="Long"&&t.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14,marginTop:14},children:[t.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 1"}),t.jsx(je,{value:e.long_cycle_date_1||"",onChange:B=>D({long_cycle_date_1:B}),disabled:c,style:{...L,...E}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 2"}),t.jsx(je,{value:e.long_cycle_date_2||"",onChange:B=>D({long_cycle_date_2:B}),disabled:c,style:{...L,...E}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 3"}),t.jsx(je,{value:e.long_cycle_date_3||"",onChange:B=>D({long_cycle_date_3:B}),disabled:c,style:{...L,...E}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 4"}),t.jsx(je,{value:e.long_cycle_date_4||"",onChange:B=>D({long_cycle_date_4:B}),disabled:c,style:{...L,...E}})]})]})]})]}),t.jsxs(oe,{title:"Progress Indicators",children:[t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:!c&&t.jsx("button",{type:"button",onClick:Ut,style:{padding:"7px 14px",border:"none",background:"#2563eb",color:"white",borderRadius:6,fontWeight:600,fontSize:12,cursor:"pointer"},children:"+ Add Row"})}),t.jsx("div",{style:{overflowX:"auto",minWidth:0},children:t.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Order"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Name"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Type"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Unit"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Target"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Min"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Max"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Manager"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actual Value"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Status"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Date"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Comment"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Status"}),!c&&t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actions"})]})}),t.jsxs("tbody",{children:[(e.progress_indicators||[]).length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:c?14:15,style:{padding:18,textAlign:"center",color:"#94a3b8"},children:"No progress indicators"})}),(e.progress_indicators||[]).map((B,ne)=>t.jsxs("tr",{style:{background:ne%2===0?"white":"#fafafa",borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E,width:60},value:B.order??"",disabled:c,onChange:O=>pe(ne,{order:O.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E},value:B.name1,disabled:c,onChange:O=>pe(ne,{name1:O.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E},value:B.type,disabled:c,onChange:O=>pe(ne,{type:O.target.value}),children:[t.jsx("option",{children:"Nominal"}),t.jsx("option",{children:"Ordinal"}),t.jsx("option",{children:"Interval"}),t.jsx("option",{children:"Ratio"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E,width:70},type:"text",value:B.unit??"",disabled:c,onChange:O=>pe(ne,{unit:O.target.value}),placeholder:"e.g. °C, kg, %"})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E,minWidth:120},value:B.cycle,disabled:c,onChange:O=>pe(ne,{cycle:O.target.value}),children:[t.jsx("option",{value:"",children:"--"}),ae.map(O=>t.jsx("option",{value:O.name,children:O.label},O.name)),B.cycle&&!ae.some(O=>O.name===B.cycle)&&t.jsx("option",{value:B.cycle,children:B.cycle})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E,width:80},value:B.target,disabled:c,onChange:O=>pe(ne,{target:O.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E,width:80},value:B.minimum,disabled:c,onChange:O=>pe(ne,{minimum:O.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E,width:80},value:B.maximum,disabled:c,onChange:O=>pe(ne,{maximum:O.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E,minWidth:140},value:B.manager,disabled:c,onChange:O=>pe(ne,{manager:O.target.value}),children:[t.jsx("option",{value:"",children:"--"}),$e.map(O=>t.jsx("option",{value:O.name,children:O.label},O.name)),B.manager&&!$e.some(O=>O.name===B.manager)&&t.jsx("option",{value:B.manager,children:B.manager})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E,width:90},type:"number",value:B.actual_value??"",disabled:c,onChange:O=>pe(ne,{actual_value:parseFloat(O.target.value)||""})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E},value:B.cycle_status??"",disabled:c,onChange:O=>pe(ne,{cycle_status:O.target.value}),children:[t.jsx("option",{value:"",children:"--"}),t.jsx("option",{children:"Normal"}),t.jsx("option",{children:"Below Min"}),t.jsx("option",{children:"Above Max"}),t.jsx("option",{children:"At Risk"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx(je,{value:B.cycle_date||"",onChange:O=>pe(ne,{cycle_date:O}),disabled:c,style:{...L,...E,width:110}})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E},value:B.cycle_comment??"",disabled:c,onChange:O=>pe(ne,{cycle_comment:O.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E},value:B.status??"",disabled:c,onChange:O=>pe(ne,{status:O.target.value}),children:[t.jsx("option",{value:"",children:"--"}),t.jsx("option",{children:"Normal"}),t.jsx("option",{children:"Below Min"}),t.jsx("option",{children:"Above Max"}),t.jsx("option",{children:"At Risk"})]})}),!c&&t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("button",{type:"button",onClick:()=>tt(ne),style:{padding:"4px 8px",border:"1px solid #fecaca",background:"#fef2f2",color:"#dc2626",borderRadius:4,cursor:"pointer",fontSize:11,fontWeight:600},children:"Remove"})})]},ne))]})]})})]}),t.jsx(oe,{title:"Cycle & Assignment",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.cycle}),t.jsx(re,{value:e.cycle||"",onChange:B=>D({cycle:B}),items:ae,placeholder:F.field.select,disabled:c,userRole:v,doctypeName:P.cycles,extraFields:{organization:e.organization},onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.actor}),t.jsxs("select",{style:{...L,...E},value:e.actor||"",disabled:c,onChange:B=>D({actor:B.target.value}),children:[t.jsx("option",{value:"",children:F.field.select}),Be.map(B=>t.jsx("option",{value:B.name,children:B.label},B.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.costPerCycle}),t.jsx("input",{style:{...L,...E},type:"number",value:e.cost_per_cycle||"",disabled:c,onChange:B=>D({cost_per_cycle:parseFloat(B.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:F.field.escalationLevel}),t.jsx("input",{style:{...L,...E},type:"number",value:e.escalation_level||"",disabled:c,onChange:B=>D({escalation_level:parseInt(B.target.value)||0})})]})]})}),t.jsxs(oe,{title:"Cycle History",children:[t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:!c&&t.jsx("button",{type:"button",onClick:q,style:{padding:"7px 14px",border:"none",background:"#2563eb",color:"white",borderRadius:6,fontWeight:600,fontSize:12,cursor:"pointer"},children:"+ Add Row"})}),t.jsx("div",{style:{overflowX:"auto",minWidth:0},children:t.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Date"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Status"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actor"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Comment"}),!c&&t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actions"})]})}),t.jsxs("tbody",{children:[(e.cycle_logs||[]).length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:c?5:6,style:{padding:18,textAlign:"center",color:"#94a3b8"},children:"No cycle history"})}),(e.cycle_logs||[]).map((B,ne)=>t.jsxs("tr",{style:{background:ne%2===0?"white":"#fafafa",borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E},value:B.cycle||"",disabled:c,onChange:O=>ut(ne,{cycle:O.target.value}),children:[t.jsx("option",{value:"",children:"-- Select --"}),ae.map(O=>t.jsx("option",{value:O.name,children:O.label},O.name))]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx(je,{value:B.cycle_date||"",onChange:O=>ut(ne,{cycle_date:O}),disabled:c,style:{...L,...E,width:130}})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E},value:B.status,disabled:c,onChange:O=>ut(ne,{status:O.target.value}),children:[t.jsx("option",{value:"Pass",children:"Pass"}),t.jsx("option",{value:"Fail",children:"Fail"}),t.jsx("option",{value:"Unknown",children:"Unknown"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...L,...E},value:B.actor||"",disabled:c,onChange:O=>ut(ne,{actor:O.target.value}),children:[t.jsx("option",{value:"",children:"-- Select --"}),Be.map(O=>t.jsx("option",{value:O.name,children:O.label},O.name))]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...L,...E},value:B.comment||"",disabled:c,onChange:O=>ut(ne,{comment:O.target.value})})}),!c&&t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("button",{type:"button",onClick:()=>ue(ne),style:{padding:"4px 8px",border:"1px solid #fecaca",background:"#fef2f2",color:"#dc2626",borderRadius:4,cursor:"pointer",fontSize:11,fontWeight:600},children:"Remove"})})]},ne))]})]})})]}),t.jsx(oe,{title:F.field.auditorComment,children:t.jsx("textarea",{style:{...L,height:70,resize:"vertical",background:"#f8fafc"},value:e.auditor_comment||"",disabled:!0,readOnly:!0,placeholder:F.field.commentPlaceholder})})]})}const B0={Admin:"#7c3aed",Auditor:"#d97706",Owner:"#0369a1",XAuditor:"#0f766e",Manager:"#2563eb",Employee:"#6b7280",Chairman:"#0f766e"};function $0({user:e,profileUser:n,darkMode:s,canModify:l,onBack:a,organizations:r=[],managements:o=[],departments:d=[],branches:p=[],groupCompanies:f=[]}){const k=n||{},j=!!l&&e.role==="Admin",[b,c]=_.useState({first_name:k.first_name||"",middle_name:k.middle_name||"",last_name:k.last_name||"",mobile_no:k.mobile_no||"",custom_organization:k.custom_organization||"",custom_group_company:k.custom_group_company||"",custom_management:k.custom_management||"",custom_department:k.custom_department||"",custom_branch:k.custom_branch||"",custom_number:k.custom_number||"",custom_category:k.custom_category||""}),[y,z]=_.useState(""),[C,g]=_.useState(!1),[i,h]=_.useState({new:"",confirm:""}),[x,S]=_.useState(""),w=k.email||k.name||"",u=[b.first_name,b.middle_name,b.last_name].filter(Boolean).join(" ")||k.full_name||"",v=k.username||k.name||"",I=b.custom_category||"",T=k.enabled===0?"Inactive":"Active",G=B0[e.role]||"#6b7280",K=s,le=K?"#0f172a":"#f0f2f5",U=K?"#1e293b":"white",F=K?"#2d3748":"#e5e7eb",D=K?"#e2e8f0":"#1a2332",E=K?"#94a3b8":"#6b7280",A=K?"#374151":"white",M=K?"#2d3748":"#f9fafb",Q={width:"100%",padding:"9px 12px",borderRadius:8,border:`1px solid ${F}`,fontSize:13,background:A,color:D,fontFamily:"inherit",outline:"none"},N={...Q,background:M,color:E},ee={...Q,cursor:"pointer"},Z={fontSize:12,fontWeight:600,color:E,marginBottom:5,display:"block"},ce={display:"grid",gridTemplateColumns:"1fr 1fr",gap:14},ae={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:14},Be=async()=>{if(l){z("saving");try{await Vr("User",k.name,{first_name:b.first_name,middle_name:b.middle_name,last_name:b.last_name,mobile_no:b.mobile_no,custom_organization:b.custom_organization,custom_group_company:b.custom_group_company,custom_management:b.custom_management,custom_department:b.custom_department,custom_branch:b.custom_branch,custom_number:b.custom_number,custom_category:b.custom_category}),z("saved"),setTimeout(()=>z(""),2e3)}catch{z("error"),setTimeout(()=>z(""),3e3)}}},$e=async()=>{if(!i.new){S("Enter a new password");return}if(i.new!==i.confirm){S("Passwords do not match");return}S("saving");try{await oh(k.name,i.new),S("done"),h({new:"",confirm:""}),setTimeout(()=>{S(""),g(!1)},2e3)}catch{S("error")}},ut=({title:q,icon:ue,children:pe})=>t.jsxs("div",{style:{background:U,borderRadius:12,padding:22,border:`1px solid ${F}`,boxShadow:`0 1px 4px rgba(0,0,0,${K?.3:.06})`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:18,paddingBottom:14,borderBottom:`1px solid ${F}`},children:[ue,t.jsx("span",{style:{fontSize:14,fontWeight:700,color:D},children:q})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:14},children:pe})]});return t.jsxs("div",{style:{background:le,minHeight:"100%",padding:"0 0 32px"},children:[t.jsxs("div",{style:{background:U,borderBottom:`1px solid ${F}`,padding:"12px 28px",display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[t.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",gap:7,background:"none",border:"none",cursor:"pointer",fontSize:15,fontWeight:700,color:D,fontFamily:"inherit"},children:[t.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:t.jsx("polyline",{points:"15,18 9,12 15,6"})}),"User Profile"]}),l&&t.jsxs("button",{onClick:Be,style:{display:"flex",alignItems:"center",gap:8,background:y==="saved"?"#16a34a":y==="error"?"#dc2626":"#16a34a",color:"white",border:"none",borderRadius:8,padding:"9px 22px",fontSize:13,fontWeight:700,cursor:"pointer",fontFamily:"inherit"},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),t.jsx("polyline",{points:"17,21 17,13 7,13 7,21"}),t.jsx("polyline",{points:"7,3 7,8 15,8"})]}),y==="saving"?"Saving…":y==="saved"?"Saved!":y==="error"?"Error":"Save Changes"]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"280px 1fr",gap:22,padding:"0 28px"},children:[t.jsxs("div",{style:{borderRadius:14,overflow:"hidden",boxShadow:"0 4px 20px rgba(0,0,0,0.12)",alignSelf:"start"},children:[t.jsxs("div",{style:{background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",padding:"32px 20px 28px",display:"flex",flexDirection:"column",alignItems:"center",gap:6},children:[t.jsx("div",{style:{width:78,height:78,borderRadius:"50%",background:"rgba(255,255,255,0.22)",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:4,border:"3px solid rgba(255,255,255,0.3)"},children:t.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"rgba(255,255,255,0.9)",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]})}),t.jsx("div",{style:{fontSize:17,fontWeight:700,color:"white",textAlign:"center",lineHeight:1.3},children:u||w}),t.jsx("div",{style:{fontSize:12,color:"rgba(255,255,255,0.75)",textAlign:"center"},children:w})]}),t.jsx("div",{style:{background:U},children:[{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:G,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),t.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),t.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),t.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),label:"Username",value:v},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:G,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),t.jsx("circle",{cx:"9",cy:"7",r:"4"}),t.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),t.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),label:"Role Profile",value:I||"—"},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:G,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),t.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),label:"Group Company",value:b.custom_group_company||"—"},{icon:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:T==="Active"?"#16a34a":"#dc2626",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),label:"Status",value:T,valueColor:T==="Active"?"#16a34a":"#dc2626"},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:G,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),t.jsx("path",{d:"m2 7 10 7 10-7"})]}),label:"Email",value:w},{icon:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:G,strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 13a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.6 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})}),label:"Phone",value:b.mobile_no||"—"}].map(({icon:q,label:ue,value:pe,valueColor:Ut})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 16px",borderBottom:`1px solid ${F}`},children:[t.jsx("div",{style:{flexShrink:0,width:18,display:"flex",justifyContent:"center"},children:q}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,color:E,marginBottom:1},children:ue}),t.jsx("div",{style:{fontSize:13,fontWeight:600,color:Ut||D,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:pe})]})]},ue))})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:18},children:[t.jsxs(ut,{title:"Basic Information",icon:t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]}),children:[t.jsxs("div",{style:ce,children:[t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Email ",t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Read-only)"})]}),t.jsxs("div",{style:{position:"relative"},children:[t.jsx("div",{style:{position:"absolute",left:11,top:"50%",transform:"translateY(-50%)"},children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#94a3b8",strokeWidth:"2",children:[t.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),t.jsx("path",{d:"m2 7 10 7 10-7"})]})}),t.jsx("input",{style:{...N,paddingLeft:32},value:w,readOnly:!0})]})]}),t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Full Name ",t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Auto-generated)"})]}),t.jsx("input",{style:N,value:u,readOnly:!0})]})]}),t.jsxs("div",{style:ae,children:[t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["First Name ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{style:l?Q:N,value:b.first_name,readOnly:!l,onChange:q=>c(ue=>({...ue,first_name:q.target.value})),placeholder:"First name"})]}),t.jsxs("div",{children:[t.jsx("label",{style:Z,children:"Middle Name"}),t.jsx("input",{style:l?Q:N,value:b.middle_name,readOnly:!l,onChange:q=>c(ue=>({...ue,middle_name:q.target.value})),placeholder:"Middle name"})]}),t.jsxs("div",{children:[t.jsx("label",{style:Z,children:"Last Name"}),t.jsx("input",{style:l?Q:N,value:b.last_name,readOnly:!l,onChange:q=>c(ue=>({...ue,last_name:q.target.value})),placeholder:"Last name"})]})]}),t.jsxs("div",{style:ce,children:[t.jsxs("div",{children:[t.jsx("label",{style:Z,children:"Phone Number"}),t.jsx("input",{style:l?Q:N,value:b.mobile_no,readOnly:!l,onChange:q=>c(ue=>({...ue,mobile_no:q.target.value})),placeholder:"Phone number"})]}),t.jsxs("div",{children:[t.jsx("label",{style:Z,children:"User ID No"}),t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{style:{...N,paddingRight:44},value:b.custom_number||k.name||"",readOnly:!0}),t.jsx("div",{style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",background:"#ef4444",borderRadius:5,padding:"3px 7px",cursor:"default",display:"flex",alignItems:"center"},children:t.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"white",children:[t.jsx("circle",{cx:"5",cy:"12",r:"2"}),t.jsx("circle",{cx:"12",cy:"12",r:"2"}),t.jsx("circle",{cx:"19",cy:"12",r:"2"})]})})]})]})]}),t.jsxs("div",{style:ce,children:[t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Category ",!j&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),j?t.jsxs("select",{style:ee,value:b.custom_category,onChange:q=>c(ue=>({...ue,custom_category:q.target.value})),children:[t.jsx("option",{value:"",children:"Select category"}),["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"].map(q=>t.jsx("option",{value:q,children:q},q))]}):t.jsx("input",{style:N,value:I||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Group Company ",!j&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),j?t.jsxs("select",{style:ee,value:b.custom_group_company,onChange:q=>c(ue=>({...ue,custom_group_company:q.target.value})),children:[t.jsx("option",{value:"",children:"Select group company"}),f.map(q=>t.jsx("option",{value:q.name,children:q.company_name||q.name},q.name))]}):t.jsx("input",{style:N,value:b.custom_group_company||"—",readOnly:!0})]})]})]}),t.jsxs(ut,{title:"Organization Information",icon:t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#8b5cf6",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),t.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),children:[t.jsxs("div",{style:ce,children:[t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Organization ",!j&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),j?t.jsxs("select",{style:ee,value:b.custom_organization,onChange:q=>c(ue=>({...ue,custom_organization:q.target.value})),children:[t.jsx("option",{value:"",children:"Select organization"}),be(r,b.custom_organization).map(q=>t.jsx("option",{value:q.name,children:q.organization_name||q.name},q.name))]}):t.jsx("input",{style:N,value:b.custom_organization||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Management ",!j&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),j?t.jsxs("select",{style:ee,value:b.custom_management,onChange:q=>c(ue=>({...ue,custom_management:q.target.value})),children:[t.jsx("option",{value:"",children:"Select management"}),be(o,b.custom_management).map(q=>t.jsx("option",{value:q.name,children:q.name1||q.name},q.name))]}):t.jsx("input",{style:N,value:b.custom_management||"—",readOnly:!0})]})]}),t.jsxs("div",{style:ce,children:[t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Department ",!j&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),j?t.jsxs("select",{style:ee,value:b.custom_department,onChange:q=>c(ue=>({...ue,custom_department:q.target.value})),children:[t.jsx("option",{value:"",children:"Select department"}),be(d,b.custom_department).map(q=>t.jsx("option",{value:q.name,children:q.department_name||q.name},q.name))]}):t.jsx("input",{style:N,value:b.custom_department||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Branch ",!j&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),j?t.jsxs("select",{style:ee,value:b.custom_branch,onChange:q=>c(ue=>({...ue,custom_branch:q.target.value})),children:[t.jsx("option",{value:"",children:"Select branch"}),be(p,b.custom_branch).map(q=>t.jsx("option",{value:q.name,children:q.branch||q.name},q.name))]}):t.jsx("input",{style:N,value:b.custom_branch||"—",readOnly:!0})]})]})]}),t.jsxs("div",{style:{background:U,borderRadius:12,padding:22,border:`1px solid ${F}`,boxShadow:`0 1px 4px rgba(0,0,0,${K?.3:.06})`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),t.jsx("span",{style:{fontSize:14,fontWeight:700,color:D},children:"Change Password"})]}),l&&t.jsx("button",{onClick:()=>{g(q=>!q),S("")},style:{fontSize:13,color:"#3b82f6",background:"none",border:"none",cursor:"pointer",fontWeight:600,fontFamily:"inherit"},children:C?"Cancel":"Change Password"})]}),C&&t.jsxs("div",{style:{marginTop:18,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:ae,children:[t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["New Password ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"password",style:Q,value:i.new,onChange:q=>h(ue=>({...ue,new:q.target.value})),placeholder:"New password"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:Z,children:["Confirm Password ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"password",style:Q,value:i.confirm,onChange:q=>h(ue=>({...ue,confirm:q.target.value})),placeholder:"Confirm password"})]}),t.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:t.jsx("button",{onClick:$e,style:{width:"100%",padding:"9px 0",borderRadius:8,border:"none",background:"#2563eb",color:"white",fontWeight:700,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:x==="saving"?"Saving…":"Update Password"})})]}),x&&x!=="saving"&&t.jsx("div",{style:{fontSize:13,color:x==="done"?"#16a34a":"#dc2626",fontWeight:500},children:x==="done"?"Password updated successfully":x==="error"?"Failed to update password":x})]})]})]})]})]})}function Ae({label:e,val:n,color:s}){return t.jsxs("div",{style:{background:"white",borderRadius:8,padding:"8px 16px",flex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderTop:`3px solid ${s}`,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[t.jsx("div",{style:{fontSize:18,fontWeight:700,color:s},children:n}),t.jsx("div",{style:{fontSize:12,color:"#999"},children:e})]})}const uh={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151",boxSizing:"border-box"},U0={...uh,cursor:"pointer"};function bt({filters:e,defaultOpen:n=!1}){const[s,l]=_.useState(n);return t.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[t.jsxs("div",{onClick:()=>l(a=>!a),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:s?t.jsx("polyline",{points:"18,15 12,9 6,15"}):t.jsx("polyline",{points:"6,9 12,15 18,9"})}),t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),s&&t.jsx("div",{style:{padding:"18px 20px"},children:t.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(${Math.min(e.length,4)}, 1fr)`,gap:14},children:e.map((a,r)=>t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:a.label}),a.type==="search"?t.jsx("input",{style:uh,placeholder:a.placeholder,value:a.value,onChange:o=>a.onChange(o.target.value)}):t.jsx("select",{style:U0,value:a.value,onChange:o=>a.onChange(o.target.value),children:a.options.map(o=>t.jsx("option",{value:o.value,children:o.label},o.value))})]},r))})})]})}function M0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function F0({organizations:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),[c,y]=_.useState("all"),z={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},C=_.useMemo(()=>e.filter(x=>{const S=[x.organization_name,x.city].filter(Boolean).join(" ").toLowerCase();return!(f&&!S.includes(f.toLowerCase())||j!=="all"&&x.type!==j||c!=="all"&&(x.is_active?"Active":"Inactive")!==c)}),[e,f,j,c]),[g,i]=_.useState(1);_.useEffect(()=>{i(1)},[f,j,c]);const h=C.slice((g-1)*de,g*de);return _.useEffect(()=>{if(r){const x=e.filter(S=>d.has(S.name));r(x,h)}},[d,h]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ae,{label:"Total",val:C.length,color:"#1a2332"}),t.jsx(Ae,{label:"Active",val:C.filter(x=>x.is_active).length,color:X.green}),t.jsx(Ae,{label:"Government",val:C.filter(x=>x.type==="Government").length,color:X.blue}),t.jsx(Ae,{label:"Private",val:C.filter(x=>x.type==="Private").length,color:X.orange})]}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Name or city…"},{type:"select",label:o.col.type,value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Government",label:"Government"},{value:"Private",label:"Private"}]},{type:"select",label:"Status",value:c,onChange:y,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:h.length>0&&h.every(x=>d.has(x.name)),onChange:x=>{if(x.target.checked)p(new Set([...d,...h.map(S=>S.name)]));else{const S=new Set(d);h.forEach(w=>S.delete(w.name)),p(S)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:z,children:o.col.name}),t.jsx("th",{style:z,children:o.col.type}),t.jsx("th",{style:z,children:o.col.city}),t.jsx("th",{style:z,children:o.field.creationDate}),t.jsx("th",{style:z,children:o.col.status}),t.jsx("th",{style:z,children:o.col.actions})]})}),t.jsx("tbody",{children:C.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):h.map((x,S)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(x),style:{borderTop:"1px solid #f0f0f0",background:d.has(x.name)?"#eff6ff":x.custom_is_deleted?"#fff1f2":S%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:w=>w.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(x.name),onChange:()=>{const w=new Set(d);w.has(x.name)?w.delete(x.name):w.add(x.name),p(w)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:x.organization_name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:x.type||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:x.city||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:M0(x.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:x.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):Pa(x.is_active?o.field.statusActive:o.field.statusInactive,x.is_active?X.green:X.gray)}),t.jsx("td",{style:{padding:"8px 14px"},onClick:w=>w.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(x),onEdit:n&&l&&!x.custom_is_deleted?()=>l(x):void 0,onDelete:n&&a&&!x.custom_is_deleted?()=>a(x.name):void 0})})]},x.name))})]})}),t.jsx(Ze,{page:g,total:C.length,onPageChange:i})]})}const En=e=>({background:e?"#f9f9f9":void 0});function H0({orgForm:e,setOrgForm:n,groupCompanies:s=[],formStatus:l,viewMode:a,onEdit:r,onRestore:o,onPermanentDelete:d,darkMode:p,notifCount:f,onToggleDark:k,onCountChange:j,onViewProfile:b,onSubmit:c,onBack:y,onNavigate:z,onLogout:C,user:g}){const i=se(),h=e.name?a&&e.organization_name||i.formTitle.editOrg:i.formTitle.newOrg,x=s.map(S=>({name:S.name,label:S.company_name?`${S.company_name} (${S.name})`:S.name}));return t.jsxs(et,{title:h,activePage:"organizations",user:g,formStatus:l,buttonText:i.saveOrg,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:p,notifCount:f,onToggleDark:k,onCountChange:j,onViewProfile:b,onSubmit:c,onBack:y,onNavigate:z,onLogout:C,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:o&&e.name?()=>o(e.name):void 0,onPermanentDelete:d&&e.name?()=>d(e.name):void 0}),t.jsx(oe,{title:"Organization Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[i.field.orgName," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{type:"text",style:{...L,...En(a||!!e.name)},value:e.organization_name,disabled:a||!!e.name,required:!0,onChange:S=>n({...e,organization_name:S.target.value})})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[i.field.orgAcronym," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{type:"text",style:{...L,...En(a||!!e.name)},value:e.acronym||"",disabled:a||!!e.name,required:!0,onChange:S=>n({...e,acronym:S.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:S=>n({...e,group_company:S}),items:x,placeholder:"Select Group Company",disabled:a||!!g.custom_group_company,userRole:g.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:i.field.organizationType}),t.jsxs("select",{style:{...L,...En(a)},value:e.type,disabled:a,onChange:S=>n({...e,type:S.target.value}),children:[t.jsx("option",{children:"Government"}),t.jsx("option",{children:"Private"}),t.jsx("option",{children:"Non-Profit"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:i.field.orgCity}),t.jsx("input",{type:"text",style:{...L,...En(a)},value:e.city,disabled:a,onChange:S=>n({...e,city:S.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:i.field.contactEmail}),t.jsx("input",{type:"email",style:{...L,...En(a)},value:e.contact_email,disabled:a,onChange:S=>n({...e,contact_email:S.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:i.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>n({...e,creation_date:S}),disabled:a,style:{...L,...En(a)}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:i.field.status}),t.jsxs("select",{style:{...L,...En(a)},value:e.is_active?"Active":"Inactive",disabled:a,onChange:S=>n({...e,is_active:S.target.value==="Active"?1:0}),children:[t.jsx("option",{value:"Active",children:i.field.statusActive}),t.jsx("option",{value:"Inactive",children:i.field.statusInactive})]})]})]})}),t.jsx(oe,{title:"Incident SLA Windows",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:i.field.incidentTriageWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...L,...En(a)},value:e.incident_triage_window_days??3,disabled:a,onChange:S=>n({...e,incident_triage_window_days:parseInt(S.target.value)||3})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Days after creation before an untriaged Incident is flagged overdue"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:i.field.incidentResolutionWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...L,...En(a)},value:e.incident_resolution_window_days??5,disabled:a,onChange:S=>n({...e,incident_resolution_window_days:parseInt(S.target.value)||5})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Days without an update before an in-progress Incident is flagged overdue"})]})]})})]})}function G0({groupCompanies:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=[i.company_name,i.acronym,i.code,i.owner_user].filter(Boolean).join(" ").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ae,{label:"Total Group Cos",val:y.length,color:"#1a2332"}),t.jsx(Ae,{label:"Active",val:y.filter(i=>(i.status||"Active")==="Active").length,color:X.green}),t.jsx(Ae,{label:"Inactive",val:y.filter(i=>i.status==="Inactive").length,color:X.orange})]}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Company name, code, owner…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Inactive",label:"Inactive"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{borderBottom:"1px solid #f0f0f0",background:"#fafafa"},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:"Company Name"}),t.jsx("th",{style:c,children:"Code / Acronym"}),t.jsx("th",{style:c,children:"Group Co Owner"}),t.jsx("th",{style:c,children:"Status"}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsxs("tbody",{children:[g.map((i,h)=>{const x=i.custom_is_deleted===1;return t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderBottom:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":x?"#fef2f2":h%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:S=>S.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const S=new Set(d);S.has(i.name)?S.delete(i.name):S.add(i.name),p(S)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsxs("td",{style:{padding:"12px 14px",fontWeight:600},children:[i.company_name,x&&t.jsx("span",{style:{marginLeft:8},children:Pa(o.deletedBadge,"#ef4444")})]}),t.jsx("td",{style:{padding:"12px 14px",color:"#555"},children:[i.code,i.acronym].filter(Boolean).join(" / ")||"—"}),t.jsx("td",{style:{padding:"12px 14px",color:"#555"},children:i.owner_user||"—"}),t.jsx("td",{style:{padding:"12px 14px"},children:Pa(i.status||"Active",(i.status||"Active")==="Active"?X.green:X.orange)}),t.jsx("td",{style:{padding:"12px 14px"},onClick:S=>S.stopPropagation(),children:t.jsx(ot,{onView:s?()=>s(i):void 0,onEdit:n&&l?()=>l(i):void 0,onDelete:n&&a?()=>a(i.name):void 0})})]},i.name)}),y.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:24,textAlign:"center",color:"#aaa"},children:"No Group Companies found"})})]})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function Q0({form:e,setForm:n,users:s=[],formStatus:l,viewMode:a,onEdit:r,onRestore:o,onPermanentDelete:d,darkMode:p,notifCount:f,onToggleDark:k,onCountChange:j,onViewProfile:b,onSubmit:c,onBack:y,onNavigate:z,onLogout:C,user:g}){const i=w=>n({...e,...w}),h=a?{background:"#f8fafc"}:{},x=e.name?a?`View Group Company: ${e.company_name}`:"Edit Group Company":"New Group Company",S=s.map(w=>({name:w.name,label:w.full_name?`${w.full_name} (${w.name})`:w.name}));return t.jsxs(et,{title:x,activePage:"group-companies",user:g,formStatus:l,buttonText:"Save Group Company",buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:p,notifCount:f,onToggleDark:k,onCountChange:j,onViewProfile:b,onSubmit:c,onBack:y,onNavigate:z,onLogout:C,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:o?()=>o(e.name):void 0,onPermanentDelete:d?()=>d(e.name):void 0}),t.jsxs(oe,{title:"Group Company Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:["Company Name ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.company_name||"",disabled:a||!!e.name,onChange:w=>i({company_name:w.target.value}),placeholder:"e.g. Company A Group"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Company Code"}),t.jsx("input",{style:{...L,...h},value:e.code||"",disabled:a,onChange:w=>i({code:w.target.value}),placeholder:"e.g. CO-A"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Acronym"}),t.jsx("input",{style:{...L,...h},value:e.acronym||"",disabled:a,onChange:w=>i({acronym:w.target.value}),placeholder:"e.g. CAG"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Status"}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:a,onChange:w=>i({status:w.target.value}),children:[t.jsx("option",{value:"Active",children:"Active"}),t.jsx("option",{value:"Inactive",children:"Inactive"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Co Owner / Admin User"}),t.jsx(re,{value:e.owner_user||"",onChange:w=>i({owner_user:w}),items:S,placeholder:"Select owner user",disabled:a})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Notes"}),t.jsx("textarea",{style:{...L,...h,height:75,resize:"vertical"},value:e.notes||"",disabled:a,onChange:w=>i({notes:w.target.value}),placeholder:"Additional details regarding this tenant company…"})]})]})]})}function K0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function Y0({managements:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.blue})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:K0(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function X0({form:e,setForm:n,organizations:s,groupCompanies:l=[],formStatus:a,viewMode:r,onEdit:o,onRestore:d,onPermanentDelete:p,darkMode:f,notifCount:k,onToggleDark:j,onCountChange:b,onViewProfile:c,onSubmit:y,onBack:z,onNavigate:C,onLogout:g,user:i}){const h=se(),x=v=>n(I=>({...I,...v})),S=r?{background:"#f8fafc"}:{},w=l.map(v=>({name:v.name,label:v.company_name||v.name})),u=e.name?r?`${h.formTitle.editMgmt}: ${e.name1||e.name}`:h.formTitle.editMgmt:h.formTitle.newMgmt;return t.jsxs(et,{title:u,activePage:"managements",user:i,formStatus:a,buttonText:h.saveMgmt,buttonColor:"#16a34a",viewMode:r,onEdit:o,darkMode:f,notifCount:k,onToggleDark:j,onCountChange:b,onViewProfile:c,onSubmit:y,onBack:z,onNavigate:C,onLogout:g,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:d&&e.name?()=>d(e.name):void 0,onPermanentDelete:p&&e.name?()=>p(e.name):void 0}),t.jsx(oe,{title:"Management Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:v=>x({group_company:v}),items:w,placeholder:"Select Group Company",disabled:r||!!i.custom_group_company,userRole:i.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:v=>{var T;const I=(T=s.find(G=>G.name===v))==null?void 0:T.group_company;x({organization:v,...i.custom_group_company?{}:{group_company:I||e.group_company}})},organizations:s,disabled:r||!!i.custom_organization,userRole:i.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...S},value:e.name1,disabled:r||!!e.name,onChange:v=>x({name1:v.target.value}),placeholder:"Management name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:v=>x({creation_date:v}),disabled:r,style:{...L,...S}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.status}),t.jsxs("select",{style:{...L,...S},value:e.status||"Active",disabled:r,onChange:v=>x({status:v.target.value}),children:[t.jsx("option",{value:"Active",children:h.field.statusActive}),t.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})})]})}function q0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function J0({departments:e,managements:n,canModify:s,onView:l,onEdit:a,onDelete:r,onSelectionChange:o}){const d=se(),[p,f]=_.useState(new Set),[k,j]=_.useState(""),[b,c]=_.useState(""),[y,z]=_.useState("all"),C=w=>{var u;return((u=n.find(v=>v.name===w))==null?void 0:u.name1)||w||"—"},g={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},i=_.useMemo(()=>e.filter(w=>{const u=(w.department_name||w.name||"").toLowerCase();return!(k&&!u.includes(k.toLowerCase())||b&&w.custom_management!==b||y!=="all"&&(w.custom_status||"Active")!==y)}),[e,k,b,y]),[h,x]=_.useState(1);_.useEffect(()=>{x(1)},[k,b,y]);const S=i.slice((h-1)*de,h*de);return _.useEffect(()=>{if(o){const w=e.filter(u=>p.has(u.name));o(w,S)}},[p,S]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:i.length,color:X.teal})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:k,onChange:j,placeholder:"Search by name…"},{type:"select",label:d.col.management,value:b,onChange:c,options:[{value:"",label:"All Managements"},...n.map(w=>({value:w.name,label:w.name1||w.name}))]},{type:"select",label:"Status",value:y,onChange:z,options:[{value:"all",label:"All"},{value:"Active",label:d.field.statusActive},{value:"Inactive",label:d.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:S.length>0&&S.every(w=>p.has(w.name)),onChange:w=>{if(w.target.checked)f(new Set([...p,...S.map(u=>u.name)]));else{const u=new Set(p);S.forEach(v=>u.delete(v.name)),f(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:g,children:d.col.name}),t.jsx("th",{style:g,children:d.col.management}),t.jsx("th",{style:g,children:d.field.creationDate}),t.jsx("th",{style:g,children:d.field.status}),t.jsx("th",{style:g,children:d.col.actions})]})}),t.jsx("tbody",{children:i.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:d.noData})}):S.map((w,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>l==null?void 0:l(w),style:{borderTop:"1px solid #f0f0f0",background:p.has(w.name)?"#eff6ff":w.custom_is_deleted?"#fff1f2":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:v=>v.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:p.has(w.name),onChange:()=>{const v=new Set(p);v.has(w.name)?v.delete(w.name):v.add(w.name),f(v)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:w.department_name||w.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:C(w.custom_management)}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:q0(w.custom_creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:w.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:d.deletedBadge}):t.jsx("span",{style:{color:w.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:w.custom_status==="Inactive"?d.field.statusInactive:d.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:v=>v.stopPropagation(),children:t.jsx(ot,{onView:()=>l==null?void 0:l(w),onEdit:s&&a&&!w.custom_is_deleted?()=>a(w):void 0,onDelete:s&&r&&!w.custom_is_deleted?()=>r(w.name):void 0})})]},w.name))})]})}),t.jsx(Ze,{page:h,total:i.length,onPageChange:x})]})}function V0({form:e,setForm:n,organizations:s,groupCompanies:l=[],managements:a,formStatus:r,viewMode:o,onEdit:d,onRestore:p,onPermanentDelete:f,darkMode:k,notifCount:j,onToggleDark:b,onCountChange:c,onViewProfile:y,onSubmit:z,onBack:C,onNavigate:g,onLogout:i,user:h}){const x=se(),S=T=>n(G=>({...G,...T})),w=o?{background:"#f8fafc"}:{},u=l.map(T=>({name:T.name,label:T.company_name||T.name})),v=e.name?o?`${x.formTitle.editDept}: ${e.department_name||e.name}`:x.formTitle.editDept:x.formTitle.newDept,I=be(a,e.custom_management).map(T=>({name:T.name,label:T.name1||T.name}));return t.jsxs(et,{title:v,activePage:"departments",user:h,formStatus:r,buttonText:x.saveDept,buttonColor:"#16a34a",viewMode:o,onEdit:d,darkMode:k,notifCount:j,onToggleDark:b,onCountChange:c,onViewProfile:y,onSubmit:z,onBack:C,onNavigate:g,onLogout:i,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:p&&e.name?()=>p(e.name):void 0,onPermanentDelete:f&&e.name?()=>f(e.name):void 0}),t.jsx(oe,{title:"Department Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:T=>S({group_company:T}),items:u,placeholder:"Select Group Company",disabled:o||!!h.custom_group_company,userRole:h.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[x.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.custom_organization,onChange:T=>{var K;const G=(K=s.find(le=>le.name===T))==null?void 0:K.group_company;S({custom_organization:T,...h.custom_group_company?{}:{group_company:G||e.group_company}})},organizations:s,disabled:o||!!h.custom_organization,userRole:h.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[x.field.department," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...w},value:e.department_name,disabled:o||!!e.name,onChange:T=>S({department_name:T.target.value}),placeholder:"Department name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:x.field.management}),t.jsx(re,{value:e.custom_management,onChange:T=>S({custom_management:T}),items:I,placeholder:x.field.select,disabled:o,userRole:h.role,doctypeName:P.managements,extraFields:{organization:e.custom_organization}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:x.field.creationDate}),t.jsx(je,{value:e.custom_creation_date||"",onChange:T=>S({custom_creation_date:T}),disabled:o,style:{...L,...w}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:x.field.status}),t.jsxs("select",{style:{...L,...w},value:e.custom_status||"Active",disabled:o,onChange:T=>S({custom_status:T.target.value}),children:[t.jsx("option",{value:"Active",children:x.field.statusActive}),t.jsx("option",{value:"Inactive",children:x.field.statusInactive})]})]})]})})]})}function Z0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function e1({branches:e,managements:n,departments:s,canModify:l,onView:a,onEdit:r,onDelete:o,onSelectionChange:d}){const p=se(),[f,k]=_.useState(new Set),[j,b]=_.useState(""),[c,y]=_.useState(""),[z,C]=_.useState(""),[g,i]=_.useState("all"),h=T=>{var G;return((G=n.find(K=>K.name===T))==null?void 0:G.name1)||T||"—"},x=T=>{var G;return((G=s.find(K=>K.name===T))==null?void 0:G.department_name)||T||"—"},S={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},w=_.useMemo(()=>e.filter(T=>{const G=(T.branch||T.name||"").toLowerCase();return!(j&&!G.includes(j.toLowerCase())||c&&T.management!==c||z&&T.department!==z||g!=="all"&&(T.custom_status||"Active")!==g)}),[e,j,c,z,g]),[u,v]=_.useState(1);_.useEffect(()=>{v(1)},[j,c,z,g]);const I=w.slice((u-1)*de,u*de);return _.useEffect(()=>{if(d){const T=e.filter(G=>f.has(G.name));d(T,I)}},[f,I]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:w.length,color:X.purple})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:j,onChange:b,placeholder:"Search by name…"},{type:"select",label:p.col.management,value:c,onChange:y,options:[{value:"",label:"All Managements"},...n.map(T=>({value:T.name,label:T.name1||T.name}))]},{type:"select",label:p.col.department,value:z,onChange:C,options:[{value:"",label:"All Departments"},...s.map(T=>({value:T.name,label:T.department_name||T.name}))]},{type:"select",label:"Status",value:g,onChange:i,options:[{value:"all",label:"All"},{value:"Active",label:p.field.statusActive},{value:"Inactive",label:p.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:I.length>0&&I.every(T=>f.has(T.name)),onChange:T=>{if(T.target.checked)k(new Set([...f,...I.map(G=>G.name)]));else{const G=new Set(f);I.forEach(K=>G.delete(K.name)),k(G)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:S,children:p.col.branch}),t.jsx("th",{style:S,children:p.col.management}),t.jsx("th",{style:S,children:p.col.department}),t.jsx("th",{style:S,children:p.field.creationDate}),t.jsx("th",{style:S,children:p.field.status}),t.jsx("th",{style:S,children:p.col.actions})]})}),t.jsx("tbody",{children:w.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noData})}):I.map((T,G)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>a==null?void 0:a(T),style:{borderTop:"1px solid #f0f0f0",background:f.has(T.name)?"#eff6ff":T.custom_is_deleted?"#fff1f2":G%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:K=>K.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:f.has(T.name),onChange:()=>{const K=new Set(f);K.has(T.name)?K.delete(T.name):K.add(T.name),k(K)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:T.branch||T.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:h(T.management)}),t.jsx("td",{style:{padding:"10px 14px"},children:x(T.department)}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:Z0(T.custom_creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:T.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:p.deletedBadge}):t.jsx("span",{style:{color:T.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:T.custom_status==="Inactive"?p.field.statusInactive:p.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:K=>K.stopPropagation(),children:t.jsx(ot,{onView:()=>a==null?void 0:a(T),onEdit:l&&r&&!T.custom_is_deleted?()=>r(T):void 0,onDelete:l&&o&&!T.custom_is_deleted?()=>o(T.name):void 0})})]},T.name))})]})}),t.jsx(Ze,{page:u,total:w.length,onPageChange:v})]})}function t1({form:e,setForm:n,organizations:s,groupCompanies:l=[],managements:a,departments:r,formStatus:o,viewMode:d,onEdit:p,onRestore:f,onPermanentDelete:k,darkMode:j,notifCount:b,onToggleDark:c,onCountChange:y,onViewProfile:z,onSubmit:C,onBack:g,onNavigate:i,onLogout:h,user:x}){const S=se(),w=K=>n(le=>({...le,...K})),u=d?{background:"#f8fafc"}:{},v=l.map(K=>({name:K.name,label:K.company_name||K.name})),I=be(a,e.management).map(K=>({name:K.name,label:K.name1||K.name})),T=be(r,e.department).map(K=>({name:K.name,label:K.department_name||K.name})),G=e.name?d?`${S.formTitle.editBranch}: ${e.branch||e.name}`:S.formTitle.editBranch:S.formTitle.newBranch;return t.jsxs(et,{title:G,activePage:"branches",user:x,formStatus:o,buttonText:S.saveBranch,buttonColor:"#16a34a",viewMode:d,onEdit:p,darkMode:j,notifCount:b,onToggleDark:c,onCountChange:y,onViewProfile:z,onSubmit:C,onBack:g,onNavigate:i,onLogout:h,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:f&&e.name?()=>f(e.name):void 0,onPermanentDelete:k&&e.name?()=>k(e.name):void 0}),t.jsx(oe,{title:"Branch Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:K=>w({group_company:K}),items:v,placeholder:"Select Group Company",disabled:d||!!x.custom_group_company,userRole:x.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[S.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:K=>{var U;const le=(U=s.find(F=>F.name===K))==null?void 0:U.group_company;w({organization:K,...x.custom_group_company?{}:{group_company:le||e.group_company}})},organizations:s,disabled:d||!!x.custom_organization,userRole:x.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[S.field.branch," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...u},value:e.branch,disabled:d||!!e.name,onChange:K=>w({branch:K.target.value}),placeholder:"Branch name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:S.field.management}),t.jsx(re,{value:e.management,onChange:K=>w({management:K}),items:I,placeholder:S.field.select,disabled:d,userRole:x.role,doctypeName:P.managements,extraFields:{organization:e.organization}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:S.field.department}),t.jsx(re,{value:e.department,onChange:K=>w({department:K}),items:T,placeholder:S.field.select,disabled:d,userRole:x.role,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:S.field.creationDate}),t.jsx(je,{value:e.custom_creation_date||"",onChange:K=>w({custom_creation_date:K}),disabled:d,style:{...L,...u}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:S.field.status}),t.jsxs("select",{style:{...L,...u},value:e.custom_status||"Active",disabled:d,onChange:K=>w({custom_status:K.target.value}),children:[t.jsx("option",{value:"Active",children:S.field.statusActive}),t.jsx("option",{value:"Inactive",children:S.field.statusInactive})]})]})]})})]})}function n1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function s1({incidentTypes:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.red})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:n1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function l1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Incident Type: ${e.name1||e.name}`:"Edit Incident Type":"New Incident Type";return t.jsxs(et,{title:x,activePage:"incident-types",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsx(oe,{title:"Incident Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Incident type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function a1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function r1({ideaTypes:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.teal})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:a1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function i1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Idea Type: ${e.name1||e.name}`:"Edit Idea Type":"New Idea Type";return t.jsxs(et,{title:x,activePage:"idea-types",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsx(oe,{title:"Idea Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Idea type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function o1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function d1({orderTypes:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.purple})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:o1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function c1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Order Type: ${e.name1||e.name}`:"Edit Order Type":"New Order Type";return t.jsxs(et,{title:x,activePage:"order-types",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsx(oe,{title:"Order Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Order type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function u1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function p1({processTypes:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.blue})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:u1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function f1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Process Type: ${e.name1||e.name}`:"Edit Process Type":"New Process Type";return t.jsxs(et,{title:x,activePage:"process-types",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsx(oe,{title:"Process Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Process type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function h1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function g1({incidentStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.red})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.notifyManager}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.notify_manager?o.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:h1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function m1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Incident Status: ${e.name1||e.name}`:"Edit Incident Status":"New Incident Status";return t.jsxs(et,{title:x,activePage:"incident-statuses",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsxs(oe,{title:"Incident Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Incident status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:S=>i({notify_manager:S.target.checked?1:0}),style:Ol}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:g.field.notifyManager})]})]})]})}function x1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function y1({ideaStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.teal})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.notifyManager}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.notify_manager?o.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:x1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function v1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Idea Status: ${e.name1||e.name}`:"Edit Idea Status":"New Idea Status";return t.jsxs(et,{title:x,activePage:"idea-statuses",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsxs(oe,{title:"Idea Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Idea status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:S=>i({notify_manager:S.target.checked?1:0}),style:Ol}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:g.field.notifyManager})]})]})]})}function j1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function b1({orderStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.purple})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.notifyManager}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.notify_manager?o.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:j1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function S1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Order Status: ${e.name1||e.name}`:"Edit Order Status":"New Order Status";return t.jsxs(et,{title:x,activePage:"order-statuses",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsxs(oe,{title:"Order Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Order status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:S=>i({notify_manager:S.target.checked?1:0}),style:Ol}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:g.field.notifyManager})]})]})]})}function _1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function w1({processStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=_.useMemo(()=>e.filter(i=>{const h=(i.name1||i.name||"").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j!=="all"&&(i.status||"Active")!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total",val:y.length,color:X.blue})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:b,options:[{value:"all",label:"All"},{value:"Active",label:o.field.statusActive},{value:"Inactive",label:o.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:o.col.name}),t.jsx("th",{style:c,children:o.field.notifyManager}),t.jsx("th",{style:c,children:o.field.creationDate}),t.jsx("th",{style:c,children:o.field.status}),t.jsx("th",{style:c,children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.name1||i.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.notify_manager?o.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:_1(i.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{color:i.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:i.status==="Inactive"?o.field.statusInactive:o.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function k1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:a,onRestore:r,onPermanentDelete:o,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,user:C}){const g=se(),i=S=>n(w=>({...w,...S})),h=l?{background:"#f8fafc"}:{},x=e.name?l?`Process Status: ${e.name1||e.name}`:"Edit Process Status":"New Process Status";return t.jsxs(et,{title:x,activePage:"process-statuses",user:C,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:a,darkMode:d,notifCount:p,onToggleDark:f,onCountChange:k,onViewProfile:j,onSubmit:b,onBack:c,onNavigate:y,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:r&&e.name?()=>r(e.name):void 0,onPermanentDelete:o&&e.name?()=>o(e.name):void 0}),t.jsxs(oe,{title:"Process Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...h},value:e.name1,disabled:l||!!e.name,onChange:S=>i({name1:S.target.value}),placeholder:"Process status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:S=>i({creation_date:S}),disabled:l,style:{...L,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...L,...h},value:e.status||"Active",disabled:l,onChange:S=>i({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:S=>i({notify_manager:S.target.checked?1:0}),style:Ol}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:g.field.notifyManager})]})]})]})}const C1={Admin:"#7c3aed",Chairman:"#0f766e",Auditor:"#d97706","X-Auditor":"#8b5cf6",Manager:"#2563eb",Employee:"#6b7280"};function z1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function I1({users:e,canModify:n,onView:s,onEdit:l,onDisable:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(!1),[j,b]=_.useState(""),[c,y]=_.useState(""),[z,C]=_.useState(""),[g,i]=_.useState("active"),[h,x]=_.useState(1),[S,w]=_.useState(null),[u,v]=_.useState(""),[I,T]=_.useState("idle"),[G,K]=_.useState(null),le=async()=>{if(!(!S||!u.trim())){T("loading");try{await oh(S.name,u.trim()),T("success"),setTimeout(()=>{w(null),v(""),T("idle")},1200)}catch{T("error")}}},U=async N=>{if(window.confirm(o.users.disableConfirm)){K(N);try{await(a==null?void 0:a(N))}finally{K(null)}}},F=e.filter(N=>{if(g==="active"&&(N.enabled===0||N.enabled==="0")||g==="inactive"&&N.enabled!==0&&N.enabled!=="0")return!1;const ee=N.custom_category||"";if(z&&ee!==z)return!1;const Z=N.custom_organization||"";if(c&&!Z.toLowerCase().includes(c.toLowerCase()))return!1;if(j){const ce=j.toLowerCase();if(![N.full_name,N.email,N.name,N.username,N.mobile_no].join(" ").toLowerCase().includes(ce))return!1}return!0}),D=[...new Set(e.map(N=>N.custom_organization).filter(Boolean))],E=["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"];_.useEffect(()=>{x(1)},[j,c,z,g]);const A=F.slice((h-1)*de,h*de);_.useEffect(()=>{if(r){const N=F.filter(ee=>d.has(ee.name));r(N,A)}},[d,A]);const M={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151"},Q={...M,cursor:"pointer"};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,flex:1},children:[t.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[t.jsxs("div",{onClick:()=>k(N=>!N),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:f?t.jsx("polyline",{points:"18,15 12,9 6,15"}):t.jsx("polyline",{points:"6,9 12,15 18,9"})}),t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),f&&t.jsx("div",{style:{padding:"18px 20px",display:"flex",flexDirection:"column",gap:14},children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:14},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Search"}),t.jsx("input",{style:M,placeholder:"Name, email, username…",value:j,onChange:N=>{b(N.target.value),x(1)}})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Organization"}),t.jsxs("select",{style:Q,value:c,onChange:N=>{y(N.target.value),x(1)},children:[t.jsx("option",{value:"",children:"All Organizations"}),D.map(N=>t.jsx("option",{value:N,children:N},N))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Category"}),t.jsxs("select",{style:Q,value:z,onChange:N=>{C(N.target.value),x(1)},children:[t.jsx("option",{value:"",children:"All Categories"}),E.map(N=>t.jsx("option",{value:N,children:N},N))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Status"}),t.jsxs("select",{style:Q,value:g,onChange:N=>{i(N.target.value),x(1)},children:[t.jsx("option",{value:"all",children:"All"}),t.jsx("option",{value:"active",children:"Active"}),t.jsx("option",{value:"inactive",children:"Inactive"})]})]})]})})]}),t.jsx("div",{style:{background:"white",borderRadius:10,border:"1px solid #e5e7eb",overflow:"auto",flex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.05)"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f9fafb",borderBottom:"2px solid #e5e7eb",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"11px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:A.length>0&&A.every(N=>d.has(N.name)),onChange:N=>{if(N.target.checked)p(new Set([...d,...A.map(ee=>ee.name)]));else{const ee=new Set(d);A.forEach(Z=>ee.delete(Z.name)),p(ee)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),[{label:"Category",w:110},{label:"Number",w:90},{label:o.col.name,w:160},{label:"Username",w:130},{label:"Email",w:180},{label:"Phone",w:110},{label:o.col.organization,w:140},{label:o.col.management,w:120},{label:o.col.department,w:120},{label:"Branch",w:100},{label:"Since",w:90},{label:"Status",w:80},{label:"Tools",w:200}].map(({label:N,w:ee})=>t.jsx("th",{style:{padding:"11px 14px",textAlign:"left",color:"#6b7280",fontSize:11,fontWeight:700,whiteSpace:"nowrap",minWidth:ee,letterSpacing:.3,textTransform:"uppercase"},children:N},N))]})}),t.jsx("tbody",{children:F.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:14,style:{padding:"48px 20px",textAlign:"center",color:"#aaa",fontSize:14},children:"No users found"})}):A.map((N,ee)=>{const Z=N.custom_category||"",ce=C1[Z]||"#6b7280";return t.jsxs("tr",{onClick:()=>s==null?void 0:s(N),style:{borderBottom:"1px solid #f3f4f6",background:d.has(N.name)?"#eff6ff":ee%2===0?"white":"#fafafa",transition:"background 0.1s",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"11px 14px",textAlign:"center"},onClick:ae=>ae.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(N.name),onChange:()=>{const ae=new Set(d);ae.has(N.name)?ae.delete(N.name):ae.add(N.name),p(ae)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:Z?t.jsx("span",{style:{background:ce+"18",color:ce,border:`1px solid ${ce}44`,padding:"3px 10px",borderRadius:20,fontSize:11,fontWeight:700},children:Z}):t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:N.custom_number||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",fontWeight:600,color:"#1a2332",whiteSpace:"nowrap"},children:N.full_name||N.first_name||"—"}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:N.username||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:N.email||N.name}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:N.mobile_no||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:N.custom_organization||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:N.custom_management||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:N.custom_department||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:N.custom_branch||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:z1(N.creation)}),t.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:t.jsx("span",{style:{color:N.enabled?"#16a34a":"#dc2626",fontWeight:600},children:N.enabled?o.users.active:o.users.inactive})}),t.jsx("td",{style:{padding:"10px 14px",whiteSpace:"nowrap"},onClick:ae=>ae.stopPropagation(),children:t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[t.jsx("button",{onClick:ae=>{ae.stopPropagation(),s==null||s(N)},title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),n&&l&&t.jsx("button",{onClick:ae=>{ae.stopPropagation(),l(N)},title:"Edit",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#dcfce7",color:"#16a34a"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),n&&t.jsx("button",{onClick:ae=>{ae.stopPropagation(),w({name:N.name,email:N.email||N.name}),v(""),T("idle")},title:"Set Password",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#fef3c7",color:"#d97706"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),n&&t.jsx("button",{onClick:ae=>{ae.stopPropagation(),U(N.name)},disabled:G===N.name,title:"Disable",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#fee2e2",color:"#ef4444",opacity:G===N.name?.5:1},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"}),t.jsx("path",{d:"M10 11v6M14 11v6"}),t.jsx("path",{d:"M9 6V4h6v2"})]})})]})})]},N.name)})})]})}),t.jsx(Ze,{page:h,total:F.length,onPageChange:x}),S&&t.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center"},children:t.jsxs("div",{style:{background:"white",borderRadius:14,padding:32,width:390,boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[t.jsx("div",{style:{fontSize:17,fontWeight:700,marginBottom:6,color:"#1a2332"},children:o.users.setPassword}),t.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:20},children:["User: ",t.jsx("strong",{children:S.email})]}),t.jsx("input",{type:"password",value:u,onChange:N=>v(N.target.value),placeholder:o.users.newPassword,style:{width:"100%",padding:"10px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,boxSizing:"border-box",marginBottom:16,fontFamily:"Segoe UI",outline:"none"},onKeyDown:N=>N.key==="Enter"&&le(),autoFocus:!0}),I==="success"&&t.jsx("div",{style:{color:"#166534",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Password updated successfully"}),I==="error"&&t.jsx("div",{style:{color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Failed to update password"}),t.jsxs("div",{style:{display:"flex",gap:10},children:[t.jsx("button",{onClick:le,disabled:I==="loading"||!u.trim(),style:{flex:1,padding:10,background:"#2563eb",color:"white",border:"none",borderRadius:8,cursor:"pointer",fontSize:13,fontWeight:700,fontFamily:"inherit",opacity:u.trim()?1:.5},children:I==="loading"?"Saving…":o.users.setPassword}),t.jsx("button",{onClick:()=>{w(null),v(""),T("idle")},style:{flex:1,padding:10,background:"#f5f5f5",color:"#374151",border:"1px solid #e5e7eb",borderRadius:8,cursor:"pointer",fontSize:13,fontFamily:"inherit"},children:o.cancel})]})]})})]})}function T1({form:e,setForm:n,groupCompanies:s=[],organizations:l,managements:a,departments:r,branches:o,formStatus:d,viewMode:p,onEdit:f,onRestore:k,onPermanentDelete:j,darkMode:b,notifCount:c,onToggleDark:y,onCountChange:z,onViewProfile:C,isSelfProfile:g,onSubmit:i,onBack:h,onNavigate:x,onLogout:S,user:w}){const u=se(),v=D=>n(E=>({...E,...D})),I=p?{background:"#f8fafc"}:{},T=s.map(D=>({name:D.name,label:D.company_name||D.name})),G=be(a,e.custom_management).map(D=>({name:D.name,label:D.name1||D.name})),K=be(r,e.custom_department).map(D=>({name:D.name,label:D.department_name||D.name})),le=be(o,e.custom_branch).map(D=>({name:D.name,label:D.branch||D.name})),U=!e.name||e.name.startsWith("new-user-"),F=g?u.formTitle.viewUser:U?u.formTitle.newUser:u.formTitle.editUser;return t.jsxs(et,{title:F,activePage:"users",user:w,formStatus:d,buttonText:u.saveUser,buttonColor:"#16a34a",viewMode:p,onEdit:f,darkMode:b,notifCount:c,onToggleDark:y,onCountChange:z,onViewProfile:C,onSubmit:i,onBack:h,onNavigate:x,onLogout:S,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:k&&e.name?()=>k(e.name):void 0,onPermanentDelete:j&&e.name?()=>j(e.name):void 0}),t.jsx(oe,{title:"User Organization & Assignment",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.custom_group_company||"",onChange:D=>v({custom_group_company:D}),items:T,placeholder:"-- Select Group Company --",disabled:p||!!w.custom_group_company,userRole:w.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.organization}),t.jsx(Vt,{value:e.custom_organization,onChange:D=>v({custom_organization:D}),organizations:l,disabled:p,userRole:w.role})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.management}),t.jsx(re,{value:e.custom_management,onChange:D=>v({custom_management:D}),items:G,placeholder:"-- Select --",disabled:p,userRole:w.role,doctypeName:P.managements,extraFields:{organization:e.custom_organization}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.department}),t.jsx(re,{value:e.custom_department,onChange:D=>v({custom_department:D}),items:K,placeholder:"-- Select --",disabled:p,userRole:w.role,doctypeName:P.departments,extraFields:{organization:e.custom_organization,management:e.custom_management}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.branch}),t.jsx(re,{value:e.custom_branch,onChange:D=>v({custom_branch:D}),items:le,placeholder:"-- Select --",disabled:p,userRole:w.role,doctypeName:P.branches,extraFields:{organization:e.custom_organization,management:e.custom_management,department:e.custom_department}})]})]})}),t.jsx(oe,{title:"User Profile Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.number}),t.jsx("input",{style:{...L,...I},value:e.custom_number,disabled:p,onChange:D=>v({custom_number:D.target.value}),placeholder:"e.g. 10001"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[u.field.fullName," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...I},value:e.first_name,disabled:p,onChange:D=>v({first_name:D.target.value}),placeholder:"Full name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.username}),t.jsx("input",{style:{...L,...I},value:e.username,disabled:p,onChange:D=>v({username:D.target.value}),placeholder:"Username"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.phoneNumber}),t.jsx("input",{style:{...L,...I},value:e.mobile_no,disabled:p,onChange:D=>v({mobile_no:D.target.value}),placeholder:"Phone number"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[u.field.emailAddress," ",U&&t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...p||!U?{background:"#f8fafc"}:{}},value:e.email,disabled:p||!U,onChange:D=>v({email:D.target.value}),placeholder:"user@example.com",type:"email",required:U})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:u.field.category}),t.jsxs("select",{style:{...L,...I},value:e.custom_category,disabled:p,onChange:D=>v({custom_category:D.target.value}),children:[t.jsx("option",{value:"",children:u.field.select}),t.jsx("option",{children:"Admin"}),t.jsx("option",{children:"Chairman"}),t.jsx("option",{children:"Auditor"}),t.jsx("option",{children:"X-Auditor"}),t.jsx("option",{children:"Manager"}),t.jsx("option",{children:"Employee"})]})]})]})})]})}const Ou={Active:X.green,Closed:X.gray};function E1({cycles:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState(""),[c,y]=_.useState("all"),z=_.useMemo(()=>[...new Set(e.map(w=>w.organization).filter(Boolean))],[e]),C=_.useMemo(()=>e.filter(w=>{const u=(w.name1||w.name||"").toLowerCase();return!(f&&!u.includes(f.toLowerCase())||j&&w.organization!==j||c!=="all"&&w.status!==c)}),[e,f,j,c]),[g,i]=_.useState(1);_.useEffect(()=>{i(1)},[f,j,c]);const h=C.slice((g-1)*de,g*de);_.useEffect(()=>{if(r){const w=e.filter(u=>d.has(u.name));r(w,h)}},[d,h]);const x=C.filter(w=>w.status==="Active").length,S=C.filter(w=>w.status==="Closed").length;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ae,{label:"Total",val:C.length,color:X.teal}),t.jsx(Ae,{label:"Active",val:x,color:X.green}),t.jsx(Ae,{label:"Closed",val:S,color:X.gray})]}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Search by name…"},{type:"select",label:o.col.organization,value:j,onChange:b,options:[{value:"",label:"All Organizations"},...z.map(w=>({value:w,label:w}))]},{type:"select",label:"Status",value:c,onChange:y,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Closed",label:"Closed"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:h.length>0&&h.every(w=>d.has(w.name)),onChange:w=>{if(w.target.checked)p(new Set([...d,...h.map(u=>u.name)]));else{const u=new Set(d);h.forEach(v=>u.delete(v.name)),p(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.name}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.organization}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.frequency}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.startDate}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.endDate}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.status}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.actions})]})}),t.jsx("tbody",{children:C.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:8,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):h.map((w,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(w),style:{borderTop:"1px solid #f0f0f0",background:d.has(w.name)?"#eff6ff":w.custom_is_deleted?"#fff1f2":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:v=>v.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(w.name),onChange:()=>{const v=new Set(d);v.has(w.name)?v.delete(w.name):v.add(w.name),p(v)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:w.name1||w.name}),t.jsx("td",{style:{padding:"10px 14px"},children:w.organization||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:w.frequency||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:w.start_date||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:w.end_date||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:w.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):t.jsx("span",{style:{padding:"3px 10px",borderRadius:12,fontSize:12,background:Ou[w.status]+"22",color:Ou[w.status]||"#666"},children:w.status})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:v=>v.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(w),onEdit:n&&l&&!w.custom_is_deleted?()=>l(w):void 0,onDelete:n&&a&&!w.custom_is_deleted?()=>a(w.name):void 0})})]},w.name))})]})}),t.jsx(Ze,{page:g,total:C.length,onPageChange:i})]})}const A1=["Weekly","Bi-weekly","Monthly","Quarterly","Annually"],P1=["Active","Closed"];function R1({form:e,setForm:n,organizations:s,groupCompanies:l=[],formStatus:a,viewMode:r,onEdit:o,onRestore:d,onPermanentDelete:p,darkMode:f,notifCount:k,onToggleDark:j,onCountChange:b,onViewProfile:c,onSubmit:y,onBack:z,onNavigate:C,onLogout:g,user:i}){const h=se(),x=v=>n(I=>({...I,...v})),S=r?{background:"#f8fafc"}:{},w=l.map(v=>({name:v.name,label:v.company_name||v.name})),u=e.name?r?`${h.formTitle.editCycle}: ${e.name1||e.name}`:h.formTitle.editCycle:h.formTitle.newCycle;return t.jsxs(et,{title:u,activePage:"cycles",user:i,formStatus:a,buttonText:h.saveCycle,buttonColor:"#16a34a",viewMode:r,onEdit:o,darkMode:f,notifCount:k,onToggleDark:j,onCountChange:b,onViewProfile:c,onSubmit:y,onBack:z,onNavigate:C,onLogout:g,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:d&&e.name?()=>d(e.name):void 0,onPermanentDelete:p&&e.name?()=>p(e.name):void 0}),t.jsx(oe,{title:"Cycle Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:v=>x({group_company:v}),items:w,placeholder:"Select Group Company",disabled:r||!!i.custom_group_company,userRole:i.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:v=>{var T;const I=(T=s.find(G=>G.name===v))==null?void 0:T.group_company;x({organization:v,...i.custom_group_company?{}:{group_company:I||e.group_company}})},organizations:s,disabled:r||!!i.custom_organization,userRole:i.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...S},value:e.name1||"",disabled:r||!!e.name,onChange:v=>x({name1:v.target.value}),placeholder:"e.g. Q1-2026"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.col.frequency}),t.jsx(re,{value:e.frequency,onChange:v=>x({frequency:v}),items:A1.map(v=>({name:v,label:v})),placeholder:"-- Select Frequency --",disabled:r})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.status}),t.jsx(re,{value:e.status,onChange:v=>x({status:v}),items:P1.map(v=>({name:v,label:v})),placeholder:"-- Select Status --",disabled:r})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.dateStart}),t.jsx(je,{value:e.start_date||"",onChange:v=>x({start_date:v}),disabled:r,style:{...L,...S}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.dateEnd}),t.jsx(je,{value:e.end_date||"",onChange:v=>x({end_date:v}),disabled:r,style:{...L,...S}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.updateWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...L,...S},value:e.update_window_days??2,disabled:r,onChange:v=>x({update_window_days:parseInt(v.target.value)||2})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Grace period before Unknown is auto-assigned"})]})]})})]})}function D1({kpiInputs:e,canModify:n,onView:s,onEdit:l,onDelete:a,onSelectionChange:r}){const o=se(),[d,p]=_.useState(new Set),[f,k]=_.useState(""),[j,b]=_.useState(""),c=_.useMemo(()=>[...new Set(e.map(i=>i.organization).filter(Boolean))],[e]),y=_.useMemo(()=>e.filter(i=>{const h=[i.organization,i.period].filter(Boolean).join(" ").toLowerCase();return!(f&&!h.includes(f.toLowerCase())||j&&i.organization!==j)}),[e,f,j]),[z,C]=_.useState(1);_.useEffect(()=>{C(1)},[f,j]);const g=y.slice((z-1)*de,z*de);return _.useEffect(()=>{if(r){const i=e.filter(h=>d.has(h.name));r(i,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ae,{label:"Total Records",val:y.length,color:X.blue})}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:f,onChange:k,placeholder:"Organization or period…"},{type:"select",label:o.col.organization,value:j,onChange:b,options:[{value:"",label:"All Organizations"},...c.map(i=>({value:i,label:i}))]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(i=>d.has(i.name)),onChange:i=>{if(i.target.checked)p(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),p(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.organization}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.period}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.field.revenue_growth}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.field.net_profit}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.dash.customerSat}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:o.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:o.noData})}):g.map((i,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(i),style:{borderTop:"1px solid #f0f0f0",background:d.has(i.name)?"#eff6ff":i.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(i.name),onChange:()=>{const x=new Set(d);x.has(i.name)?x.delete(i.name):x.add(i.name),p(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:i.organization||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.period||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.revenue_growth!=null?`${i.revenue_growth}%`:"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.net_profit!=null?i.net_profit.toLocaleString():"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:i.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:o.deletedBadge}):i.customer_satisfaction!=null?i.customer_satisfaction:"—"}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(ot,{onView:()=>s==null?void 0:s(i),onEdit:n&&l&&!i.custom_is_deleted?()=>l(i):void 0,onDelete:n&&a&&!i.custom_is_deleted?()=>a(i.name):void 0})})]},i.name))})]})}),t.jsx(Ze,{page:z,total:y.length,onPageChange:C})]})}function O1({form:e,setForm:n,organizations:s,groupCompanies:l=[],formStatus:a,viewMode:r,onEdit:o,onRestore:d,onPermanentDelete:p,darkMode:f,notifCount:k,onToggleDark:j,onCountChange:b,onViewProfile:c,onSubmit:y,onBack:z,onNavigate:C,onLogout:g,user:i}){const h=se(),x=I=>n(T=>({...T,...I})),S=r?{background:"#f8fafc"}:{},w=l.map(I=>({name:I.name,label:I.company_name||I.name})),u=I=>T=>x({[I]:parseFloat(T.target.value)||0}),v=e.name?r?`${h.formTitle.editKpi}: ${e.period||e.name}`:h.formTitle.editKpi:h.formTitle.newKpi;return t.jsxs(et,{title:v,activePage:"kpi-input",user:i,formStatus:a,buttonText:h.saveKpi,buttonColor:"#16a34a",viewMode:r,onEdit:o,darkMode:f,notifCount:k,onToggleDark:j,onCountChange:b,onViewProfile:c,onSubmit:y,onBack:z,onNavigate:C,onLogout:g,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:d&&e.name?()=>d(e.name):void 0,onPermanentDelete:p&&e.name?()=>p(e.name):void 0}),t.jsx(oe,{title:"Period & Organization",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Company (Tenant)"}),t.jsx(re,{value:e.group_company||"",onChange:I=>x({group_company:I}),items:w,placeholder:"Select Group Company",disabled:r||!!i.custom_group_company,userRole:i.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Vt,{value:e.organization,onChange:I=>{var G;const T=(G=s.find(K=>K.name===I))==null?void 0:G.group_company;x({organization:I,...i.custom_group_company?{}:{group_company:T||e.group_company}})},organizations:s,disabled:r||!!i.custom_organization,userRole:i.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.col.period," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...L,...S},value:e.period||"",disabled:r,onChange:I=>x({period:I.target.value}),placeholder:"e.g. Q1 2026"})]})]})}),t.jsx(oe,{title:"Financial KPIs",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.revenue_growth}),t.jsx("input",{type:"number",step:"0.01",style:{...L,...S},value:e.revenue_growth||"",disabled:r,onChange:u("revenue_growth")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.net_profit}),t.jsx("input",{type:"number",step:"0.01",style:{...L,...S},value:e.net_profit||"",disabled:r,onChange:u("net_profit")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.cash_flow}),t.jsx("input",{type:"number",step:"0.01",style:{...L,...S},value:e.cash_flow||"",disabled:r,onChange:u("cash_flow")})]})]})}),t.jsx(oe,{title:"Operational KPIs",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.strategic_goal_pct}),t.jsx("input",{type:"number",step:"0.01",style:{...L,...S},value:e.strategic_goal_pct||"",disabled:r,onChange:u("strategic_goal_pct")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.customer_satisfaction}),t.jsx("input",{type:"number",step:"0.01",style:{...L,...S},value:e.customer_satisfaction||"",disabled:r,onChange:u("customer_satisfaction")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.employee_turnover_pct}),t.jsx("input",{type:"number",step:"0.01",style:{...L,...S},value:e.employee_turnover_pct||"",disabled:r,onChange:u("employee_turnover_pct")})]})]})}),t.jsx(oe,{title:"Safety & Compliance",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.open_safety_incidents}),t.jsx("input",{type:"number",min:0,style:{...L,...S},value:e.open_safety_incidents||"",disabled:r,onChange:I=>x({open_safety_incidents:parseInt(I.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.compliance_score}),t.jsx("input",{type:"number",step:"0.01",style:{...L,...S},value:e.compliance_score||"",disabled:r,onChange:u("compliance_score")})]})]})})]})}const L1={incident_initial_evaluation:"Incident Initial Evaluation",idea_initial_evaluation:"Idea Initial Evaluation"},Lu={Pending:X.orange,Accepted:X.green,Rejected:X.red,Revoked:X.gray};function N1(e){if(!e)return"—";const n=new Date(e);return isNaN(n.getTime())?"—":`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function W1(e){const n=[];return e.incident_initial_evaluation&&n.push("incident_initial_evaluation"),e.idea_initial_evaluation&&n.push("idea_initial_evaluation"),n}function B1({delegations:e,organizations:n,userRole:s,currentUser:l,onView:a,onRevoke:r,onSelectionChange:o}){const d=se(),[p,f]=_.useState(new Set),[k,j]=_.useState(""),[b,c]=_.useState(""),[y,z]=_.useState("all"),C={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=_.useMemo(()=>e.filter(u=>{const v=`${u.auditor} ${u.manager}`.toLowerCase();return!(k&&!v.includes(k.toLowerCase())||b&&u.organization!==b||y!=="all"&&u.status!==y)}),[e,k,b,y]),[i,h]=_.useState(1);_.useEffect(()=>{h(1)},[k,b,y]);const x=g.slice((i-1)*de,i*de);_.useEffect(()=>{if(o){const u=e.filter(v=>p.has(v.name));o(u,x)}},[p,x]);const S=g.filter(u=>u.status==="Pending").length,w=g.filter(u=>u.status==="Accepted").length;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ae,{label:"Total",val:g.length,color:X.purple}),t.jsx(Ae,{label:"Pending",val:S,color:X.orange}),t.jsx(Ae,{label:"Accepted",val:w,color:X.green})]}),t.jsx(bt,{filters:[{type:"search",label:"Search",value:k,onChange:j,placeholder:"Auditor or Manager…"},{type:"select",label:d.col.organization,value:b,onChange:c,options:[{value:"",label:"All Organizations"},...n.map(u=>({value:u.organization_name||u.name,label:u.organization_name||u.name}))]},{type:"select",label:"Status",value:y,onChange:z,options:[{value:"all",label:"All"},{value:"Pending",label:"Pending"},{value:"Accepted",label:"Accepted"},{value:"Rejected",label:"Rejected"},{value:"Revoked",label:"Revoked"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:x.length>0&&x.every(u=>p.has(u.name)),onChange:u=>{if(u.target.checked)f(new Set([...p,...x.map(v=>v.name)]));else{const v=new Set(p);x.forEach(I=>v.delete(I.name)),f(v)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:C,children:d.col.number}),t.jsx("th",{style:C,children:d.col.auditor}),t.jsx("th",{style:C,children:d.col.manager}),t.jsx("th",{style:C,children:d.col.organization}),t.jsx("th",{style:C,children:d.col.functions}),t.jsx("th",{style:C,children:d.col.status}),t.jsx("th",{style:C,children:d.col.requestedOn}),t.jsx("th",{style:C,children:d.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:9,style:{padding:40,textAlign:"center",color:"#aaa"},children:d.noData})}):x.map((u,v)=>{const I=!!r&&(u.status==="Pending"||u.status==="Accepted")&&(s==="Admin"||u.auditor===l);return t.jsxs("tr",{className:"app-table-row",onClick:()=>a==null?void 0:a(u),style:{borderTop:"1px solid #f0f0f0",background:p.has(u.name)?"#eff6ff":v%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:T=>T.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:p.has(u.name),onChange:()=>{const T=new Set(p);T.has(u.name)?T.delete(u.name):T.add(u.name),f(T)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:u.number||u.name}),t.jsx("td",{style:{padding:"10px 14px"},children:u.auditor}),t.jsx("td",{style:{padding:"10px 14px"},children:u.manager}),t.jsx("td",{style:{padding:"10px 14px"},children:u.organization||"All Organizations"}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:W1(u).map(T=>t.jsx("span",{style:{background:"#ede9fe",color:"#6d28d9",padding:"2px 8px",borderRadius:10,fontSize:11,fontWeight:600},children:L1[T]||T},T))})}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{background:(Lu[u.status]||X.gray)+"22",color:Lu[u.status]||X.gray,padding:"3px 10px",borderRadius:12,fontSize:12,fontWeight:700},children:u.status})}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:N1(u.requested_on)}),t.jsx("td",{style:{padding:"8px 14px"},onClick:T=>T.stopPropagation(),children:t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{onClick:()=>a==null?void 0:a(u),title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),I&&t.jsx("button",{onClick:()=>r==null?void 0:r(u.name),title:"Revoke",style:{padding:"0 12px",height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"none",cursor:"pointer",background:"#fee2e2",color:"#ef4444",fontSize:12,fontWeight:700},children:"Revoke"})]})})]},u.name)})})]})}),t.jsx(Ze,{page:i,total:g.length,onPageChange:h})]})}const fo={Pending:X.orange,Accepted:X.green,Rejected:X.red,Revoked:X.gray};function $1(e){if(!e)return"—";const n=new Date(e);return isNaN(n.getTime())?"—":n.toLocaleString()}function U1({form:e,setForm:n,organizations:s,users:l,userRoleMap:a,incidents:r=[],ideas:o=[],formStatus:d,viewMode:p,onEdit:f,onRestore:k,onPermanentDelete:j,darkMode:b,notifCount:c,onToggleDark:y,onCountChange:z,onViewProfile:C,onSubmit:g,onBack:i,onNavigate:h,onLogout:x,user:S}){var le;const w=se(),u=U=>n(F=>({...F,...U})),v=p?{background:"#f8fafc"}:{},I=Dl(l,a,"SB Manager",e.organization).filter(U=>U.name!==S.name).map(U=>({name:U.name,label:U.full_name||U.name})),T=(r||[]).filter(U=>(!e.organization||U.organization===e.organization)&&(U.workflow_state==="Initial Evaluation"||U.status==="Initial Evaluation")).map(U=>({name:U.name,label:`${U.number||U.name} — ${U.title}`})),G=(o||[]).filter(U=>(!e.organization||U.organization===e.organization)&&(U.workflow_state==="Initial Evaluation"||U.status==="Initial Evaluation")).map(U=>({name:U.name,label:`${U.number||U.name} — ${U.title}`})),K=e.name?`${w.formTitle.viewDelegation}${e.name}`:w.formTitle.newDelegation;return t.jsxs(et,{title:K,activePage:"delegations",user:S,formStatus:d,statusBadge:e.status?t.jsx("span",{style:{display:"inline-block",padding:"3px 10px",borderRadius:20,fontSize:12,fontWeight:700,background:`${fo[e.status]||X.gray}18`,color:fo[e.status]||X.gray,border:`1px solid ${fo[e.status]||X.gray}40`},children:e.status}):void 0,buttonText:w.saveDelegation,buttonColor:"#16a34a",viewMode:p,onEdit:f,darkMode:b,notifCount:c,onToggleDark:y,onCountChange:z,onViewProfile:C,onSubmit:g,onBack:i,onNavigate:h,onLogout:x,children:[e.custom_is_deleted===1&&t.jsx(Ve,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:k&&e.name?()=>k(e.name):void 0,onPermanentDelete:j&&e.name?()=>j(e.name):void 0}),e.status==="Revoked"&&t.jsxs("div",{style:{padding:"10px 14px",borderRadius:8,background:"#f8fafc",border:"1px solid #cbd5e1",color:"#475569",fontSize:13,fontWeight:600,marginBottom:14,display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontSize:16},children:"🚫"})," This delegation has been Revoked and is closed for further edits or re-delegation."]}),t.jsxs(oe,{title:"Delegation Information",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:w.col.auditor}),t.jsx("input",{style:{...L,background:"#f8fafc",fontWeight:600,color:"#334155"},value:e.auditor||S.name,disabled:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[w.col.manager," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(re,{value:e.manager,onChange:U=>u({manager:U}),items:I,placeholder:"-- Select Manager --",disabled:p})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:w.col.organization}),t.jsx(Vt,{value:e.organization,onChange:U=>u({organization:U,incident_name:"",idea_name:""}),organizations:s,placeholder:"-- All Organizations --",disabled:p,userRole:S.role})]})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[w.col.functions," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,marginTop:6},children:[t.jsxs("div",{className:`delegation-func-box ${e.incident_initial_evaluation?"checked":""}`,children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:p?"default":"pointer",fontSize:13,fontWeight:600},children:[t.jsx("input",{type:"checkbox",style:Ol,checked:!!e.incident_initial_evaluation,disabled:p,onChange:U=>u({incident_initial_evaluation:U.target.checked?1:0,incident_name:U.target.checked?e.incident_name:""})}),t.jsx("span",{className:"func-title",children:"Initial Evaluation (Incidents)"})]}),!!e.incident_initial_evaluation&&t.jsxs("div",{style:{marginTop:10},children:[t.jsxs("label",{style:{...R,fontSize:11},className:"func-sublabel",children:["Specific Incident ",t.jsx("span",{style:{fontWeight:400},className:"func-hint",children:"(optional — leave blank to delegate all)"})]}),p?t.jsx("input",{style:{...L,background:"#f8fafc"},value:e.incident_name||"— All Incidents in Initial Evaluation",readOnly:!0,disabled:!0}):t.jsx(re,{value:e.incident_name||"",onChange:U=>u({incident_name:U}),items:T,placeholder:`-- Any Incident in Initial Evaluation (${T.length} available) --`,disabled:p})]})]}),t.jsxs("div",{className:`delegation-func-box ${e.idea_initial_evaluation?"checked":""}`,children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:p?"default":"pointer",fontSize:13,fontWeight:600},children:[t.jsx("input",{type:"checkbox",style:Ol,checked:!!e.idea_initial_evaluation,disabled:p,onChange:U=>u({idea_initial_evaluation:U.target.checked?1:0,idea_name:U.target.checked?e.idea_name:""})}),t.jsx("span",{className:"func-title",children:"Initial Evaluation (Ideas)"})]}),!!e.idea_initial_evaluation&&t.jsxs("div",{style:{marginTop:10},children:[t.jsxs("label",{style:{...R,fontSize:11},className:"func-sublabel",children:["Specific Idea ",t.jsx("span",{style:{fontWeight:400},className:"func-hint",children:"(optional — leave blank to delegate all)"})]}),p?t.jsx("input",{style:{...L,background:"#f8fafc"},value:e.idea_name||"— All Ideas in Initial Evaluation",readOnly:!0,disabled:!0}):t.jsx(re,{value:e.idea_name||"",onChange:U=>u({idea_name:U}),items:G,placeholder:`-- Any Idea in Initial Evaluation (${G.length} available) --`,disabled:p})]})]})]})]}),!p&&t.jsxs("div",{style:{marginTop:14},children:[t.jsx("label",{style:R,children:"Remarks"}),t.jsx("textarea",{style:{...L,...v,minHeight:70,resize:"vertical"},value:e.remarks||"",onChange:U=>u({remarks:U.target.value}),placeholder:"Optional note for the Manager…"})]})]}),p&&(((le=e.delegation_log)==null?void 0:le.length)??0)>0&&t.jsx(oe,{title:"Audit Trail",children:t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Action"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Actor"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Timestamp"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Remarks"})]})}),t.jsx("tbody",{children:(e.delegation_log||[]).map((U,F)=>t.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 12px",fontWeight:600,color:"#334155"},children:U.action}),t.jsx("td",{style:{padding:"8px 12px",color:"#334155"},children:U.actor}),t.jsx("td",{style:{padding:"8px 12px",color:"#64748b"},children:$1(U.timestamp)}),t.jsx("td",{style:{padding:"8px 12px",color:"#64748b"},children:U.remarks||"—"})]},U.name||F))})]})})})]})}const Nu={process:"processes-form",order:"orders-form",incident:"incidents-form",idea:"ideas-form"},M1={process:"#3b82f6",order:"#8b5cf6",incident:"#ef4444",idea:"#10b981",delegation:"#f59e0b"},F1={process:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",order:"linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%)",incident:"linear-gradient(135deg, #ef4444 0%, #b91c1c 100%)",idea:"linear-gradient(135deg, #10b981 0%, #047857 100%)",delegation:"linear-gradient(135deg, #f59e0b 0%, #b45309 100%)"},H1={process:"⚙️",order:"📦",incident:"🚨",idea:"💡",delegation:"🤝"};function G1({onNavigate:e,onRefresh:n}){const[s,l]=_.useState([]),[a,r]=_.useState(!0),[o,d]=_.useState(""),[p,f]=_.useState(""),[k,j]=_.useState(""),[b,c]=_.useState("all"),y=()=>{r(!0),Qy().then(i=>{l(i||[]),r(!1)}).catch(()=>r(!1))};_.useEffect(()=>{y()},[]);const z=_.useMemo(()=>{const i={all:s.length,action:0,info:0};for(const h of s)h.requires_action?i.action=(i.action||0)+1:i.info=(i.info||0)+1,i[h.type]=(i[h.type]||0)+1;return i},[s]),C=_.useMemo(()=>s.filter(i=>{if(b==="action"&&!i.requires_action||b==="info"&&i.requires_action||b!=="all"&&b!=="action"&&b!=="info"&&i.type!==b)return!1;if(k.trim()){const h=k.toLowerCase();if(![i.number,i.title,i.action,i.organization,i.type].filter(Boolean).join(" ").toLowerCase().includes(h))return!1}return!0}),[s,b,k]),g=async(i,h)=>{d(i),f("");try{await Yy(i,h),await y(),n==null||n()}catch{f(i)}finally{d("")}};return t.jsxs("div",{style:{maxWidth:1100,margin:"0 auto",display:"flex",flexDirection:"column",gap:20},children:[t.jsxs("div",{style:{background:"linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e293b 100%)",borderRadius:16,padding:"24px 28px",color:"#ffffff",boxShadow:"0 10px 25px -5px rgba(30, 27, 75, 0.25), 0 8px 10px -6px rgba(30, 27, 75, 0.2)",display:"flex",flexDirection:"column",gap:18,position:"relative",overflow:"hidden"},children:[t.jsx("div",{style:{position:"absolute",top:-40,right:-40,width:180,height:180,borderRadius:"50%",background:"radial-gradient(circle, rgba(99, 102, 241, 0.35) 0%, transparent 70%)",pointerEvents:"none"}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:14},children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx("span",{style:{fontSize:24},children:"📬"}),t.jsx("h2",{style:{fontSize:20,fontWeight:800,color:"#ffffff",margin:0,letterSpacing:"-0.3px"},children:"Unified Activity Inbox"})]}),t.jsx("p",{style:{margin:"4px 0 0",fontSize:13,color:"#c7d2fe",opacity:.9},children:"Real-time tasks, approvals, delegations, and workflow actions requiring your attention."})]}),t.jsxs("button",{type:"button",onClick:y,disabled:a,style:{background:"rgba(255, 255, 255, 0.15)",backdropFilter:"blur(8px)",border:"1px solid rgba(255, 255, 255, 0.25)",color:"white",borderRadius:10,padding:"8px 16px",fontSize:13,fontWeight:600,cursor:a?"wait":"pointer",display:"flex",alignItems:"center",gap:8,transition:"all 0.15s ease"},onMouseEnter:i=>{i.currentTarget.style.background="rgba(255, 255, 255, 0.25)"},onMouseLeave:i=>{i.currentTarget.style.background="rgba(255, 255, 255, 0.15)"},children:[t.jsx("span",{style:{transform:a?"rotate(180deg)":"none",transition:"transform 0.5s",display:"inline-block"},children:"🔄"}),a?"Refreshing…":"Refresh"]})]}),t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:[t.jsxs("div",{style:{background:"rgba(255, 255, 255, 0.1)",backdropFilter:"blur(6px)",borderRadius:10,padding:"8px 14px",display:"flex",alignItems:"center",gap:10,border:"1px solid rgba(255, 255, 255, 0.15)"},children:[t.jsx("span",{style:{fontSize:12,color:"#e0e7ff",fontWeight:500},children:"Total Items"}),t.jsx("span",{style:{background:"white",color:"#1e1b4b",fontWeight:800,fontSize:12,padding:"2px 8px",borderRadius:999},children:z.all||0})]}),t.jsxs("div",{style:{background:"rgba(239, 68, 68, 0.2)",backdropFilter:"blur(6px)",borderRadius:10,padding:"8px 14px",display:"flex",alignItems:"center",gap:10,border:"1px solid rgba(239, 68, 68, 0.35)"},children:[t.jsx("span",{style:{fontSize:12,color:"#fecaca",fontWeight:600},children:"Action Required"}),t.jsx("span",{style:{background:"#ef4444",color:"white",fontWeight:800,fontSize:12,padding:"2px 8px",borderRadius:999},children:z.action||0})]}),t.jsxs("div",{style:{background:"rgba(59, 130, 246, 0.2)",backdropFilter:"blur(6px)",borderRadius:10,padding:"8px 14px",display:"flex",alignItems:"center",gap:10,border:"1px solid rgba(59, 130, 246, 0.35)"},children:[t.jsx("span",{style:{fontSize:12,color:"#bfdbfe",fontWeight:500},children:"Informational"}),t.jsx("span",{style:{background:"#3b82f6",color:"white",fontWeight:800,fontSize:12,padding:"2px 8px",borderRadius:999},children:z.info||0})]})]})]}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:14,background:"white",padding:"12px 16px",borderRadius:12,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},className:"form-card",children:[t.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[{id:"all",label:"All",icon:"📋",count:z.all},{id:"action",label:"Needs Action",icon:"🚨",count:z.action,badgeColor:"#ef4444"},{id:"info",label:"Info",icon:"ℹ️",count:z.info},{id:"incident",label:"Incidents",icon:"⚠️",count:z.incident},{id:"idea",label:"Ideas",icon:"💡",count:z.idea},{id:"order",label:"Orders",icon:"📦",count:z.order},{id:"process",label:"Processes",icon:"⚙️",count:z.process},{id:"delegation",label:"Delegations",icon:"🤝",count:z.delegation}].map(i=>{const h=b===i.id;return i.id!=="all"&&i.id!=="action"&&i.id!=="info"&&(!i.count||i.count===0)?null:t.jsxs("button",{type:"button",onClick:()=>c(i.id),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:999,border:h?"1px solid #4f46e5":"1px solid #e2e8f0",background:h?"#4f46e5":"#f8fafc",color:h?"#ffffff":"#475569",fontSize:12,fontWeight:600,cursor:"pointer",transition:"all 0.15s ease"},children:[t.jsx("span",{children:i.icon}),t.jsx("span",{children:i.label}),i.count!=null&&i.count>0&&t.jsx("span",{style:{fontSize:10,fontWeight:700,padding:"1px 6px",borderRadius:999,background:h?"rgba(255,255,255,0.25)":i.badgeColor||"#e2e8f0",color:h?"#ffffff":i.badgeColor?"white":"#475569"},children:i.count})]},i.id)})}),t.jsx("div",{style:{minWidth:200,flex:"1 1 200px",maxWidth:300},children:t.jsx("input",{type:"text",placeholder:"Search items, titles, IDs…",value:k,onChange:i=>j(i.target.value),style:{width:"100%",padding:"7px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:12,boxSizing:"border-box",background:"#f8fafc",color:"#334155"}})})]}),a?t.jsxs("div",{style:{textAlign:"center",padding:"60px 20px",color:"#94a3b8",fontSize:14},children:[t.jsx("div",{style:{fontSize:28,marginBottom:8,animation:"spin 1s linear infinite"},children:"⏳"}),"Loading inbox updates…"]}):C.length===0?t.jsxs("div",{style:{background:"white",borderRadius:16,padding:"60px 24px",textAlign:"center",border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.03)"},className:"form-card",children:[t.jsx("div",{style:{fontSize:44,marginBottom:12},children:"✨"}),t.jsx("h3",{style:{fontSize:16,fontWeight:700,color:"#1e293b",margin:0},children:k||b!=="all"?"No matching inbox items":"You are all caught up!"}),t.jsx("p",{style:{fontSize:13,color:"#64748b",marginTop:6,maxWidth:420,margin:"6px auto 0"},children:k||b!=="all"?"Try changing your filter pills or searching for a different keyword.":"There are no active pending approvals or tasks requiring your action right now."}),(k||b!=="all")&&t.jsx("button",{type:"button",onClick:()=>{j(""),c("all")},style:{marginTop:16,padding:"7px 16px",borderRadius:8,background:"#4f46e5",color:"white",border:"none",fontWeight:600,fontSize:12,cursor:"pointer"},children:"Reset Filters"})]}):t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(330px, 1fr))",gap:14},children:C.map((i,h)=>{const x=M1[i.type]||X.gray,S=F1[i.type]||"linear-gradient(135deg, #64748b 0%, #475569 100%)",w=i.type!=="delegation";return t.jsxs("div",{className:"inbox-card form-card",onClick:w?()=>e(Nu[i.type],i.name):void 0,style:{background:"white",borderRadius:14,padding:"16px 18px",border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)",display:"flex",flexDirection:"column",justifyContent:"space-between",gap:14,cursor:w?"pointer":"default",position:"relative",overflow:"hidden",transition:"transform 0.15s ease, box-shadow 0.15s ease"},onMouseEnter:u=>{w&&(u.currentTarget.style.transform="translateY(-2px)",u.currentTarget.style.boxShadow="0 10px 20px -5px rgba(0,0,0,0.08)")},onMouseLeave:u=>{w&&(u.currentTarget.style.transform="none",u.currentTarget.style.boxShadow="0 1px 3px rgba(0,0,0,0.04)")},children:[t.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:4,background:S}}),t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,marginBottom:10},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:S,color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:15,flexShrink:0,boxShadow:`0 3px 8px -1px ${x}66`},children:H1[i.type]||"📌"}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:x,letterSpacing:"0.3px"},children:i.number||i.name})]}),i.requires_action?t.jsxs("span",{style:{fontSize:10,fontWeight:800,color:"#ef4444",background:"#fef2f2",border:"1px solid #fecaca",padding:"2px 8px",borderRadius:999,textTransform:"uppercase",letterSpacing:"0.4px",display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#ef4444"}}),"Action"]}):t.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#64748b",background:"#f1f5f9",padding:"2px 8px",borderRadius:999,textTransform:"uppercase",letterSpacing:"0.3px"},children:i.type})]}),t.jsx("div",{className:"inbox-card-title",style:{fontSize:14,fontWeight:700,color:"#1e293b",lineHeight:1.35,marginBottom:6,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:i.title||i.action||"Untitled Item"}),t.jsx("div",{style:{fontSize:12,color:"#475569",lineHeight:1.4,marginBottom:8},children:i.action}),t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[i.organization&&t.jsxs("span",{style:{fontSize:11,color:"#64748b",background:"#f8fafc",border:"1px solid #e2e8f0",padding:"2px 7px",borderRadius:6,display:"flex",alignItems:"center",gap:4},children:["🏢 ",i.organization]}),i.date&&t.jsxs("span",{style:{fontSize:11,color:"#64748b",background:"#f8fafc",border:"1px solid #e2e8f0",padding:"2px 7px",borderRadius:6},children:["📅 ",i.date]})]}),p===i.name&&t.jsx("div",{style:{marginTop:8,fontSize:11,color:"#ef4444",fontWeight:600},children:"⚠️ Failed to process response. Please try again."})]}),t.jsx("div",{children:i.type==="delegation"?t.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[t.jsx("button",{type:"button",onClick:()=>g(i.name,"Accepted"),disabled:o===i.name,style:{flex:1,padding:"7px 0",borderRadius:8,border:"none",background:"#16a34a",color:"white",fontWeight:700,fontSize:12,cursor:o===i.name?"wait":"pointer",opacity:o===i.name?.6:1,transition:"background 0.15s ease"},children:"✓ Accept"}),t.jsx("button",{type:"button",onClick:()=>g(i.name,"Rejected"),disabled:o===i.name,style:{flex:1,padding:"7px 0",borderRadius:8,border:"none",background:"#ef4444",color:"white",fontWeight:700,fontSize:12,cursor:o===i.name?"wait":"pointer",opacity:o===i.name?.6:1,transition:"background 0.15s ease"},children:"✕ Reject"})]}):t.jsxs("button",{type:"button",onClick:u=>{u.stopPropagation(),e(Nu[i.type],i.name)},style:{width:"100%",padding:"7px 12px",borderRadius:8,border:i.requires_action?"none":"1px solid #cbd5e1",background:i.requires_action?S:"#f8fafc",color:i.requires_action?"#ffffff":"#334155",fontWeight:700,fontSize:12,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:6,transition:"all 0.15s ease"},children:[t.jsx("span",{children:i.requires_action?"Review & Act Now":"View Details"}),t.jsx("span",{style:{fontSize:13},children:"→"})]})})]},i.name||h)})})]})}const Q1=[{id:"process_status_history",label:"Process Status History",description:"Full cycle-by-cycle status for any process, with actor, date, and escalation level",roles:["Admin","Auditor","Owner"]},{id:"order_tracker",label:"Outsourcing Order Tracker",description:"Stage-by-stage progress for all orders, with cost variance",roles:["Admin","Auditor","Manager","Owner"]},{id:"incident_register",label:"Incident Register",description:"All incidents with type, status, assigned manager, and resolution timeline",roles:["Admin","Auditor","Manager","Owner"]},{id:"ideas_pipeline",label:"Ideas Pipeline",description:"All ideas by status and type, conversion rate to Study",roles:["Admin","Auditor","Manager","Owner"]},{id:"department_performance",label:"Department Performance",description:"Aggregate Pass/Fail/Unknown per department per cycle",roles:["Admin","Auditor","Owner"]},{id:"escalation_report",label:"Escalation Report",description:"All Level 2 escalations with entity type and current status",roles:["Admin","Owner"]},{id:"cost_summary",label:"Cost Summary",description:"Total cost per order, per department — budget vs actual",roles:["Admin","Owner"]},{id:"process_year_end",label:"Process Year-End Summary",description:"Full status history and accumulated cost per process for a given year (Rule 11.1-6)",roles:["Admin","Auditor","Owner"],extraFilter:"year"},{id:"user_activity_log",label:"User Activity Log",description:"All actions by user with timestamp and entity reference — Admin only",roles:["Admin"]}],ic={number:"Number",title:"Title",organization:"Organization",department:"Department",status:"Status",actor:"Actor",cycle:"Cycle",date_start:"Start Date",date_end:"End Date",escalation_level:"Escalation",stage:"Stage",completion_pct:"Completion %",budget:"Budget",starting_date:"Start",ending_date:"End",date:"Date",assigned_to:"Assigned To",type:"Type",entity_type:"Entity",pass_count:"Pass",fail_count:"Fail",unknown_count:"Unknown",total:"Total",cycle_type:"Cycle Type",cost_per_cycle:"Cost/Cycle",total_cycles:"Total Cycles",total_cost:"Total Cost",timestamp:"Timestamp",user:"User",entity_name:"Entity",changes:"Fields Changed"};function K1(e,n){const s=e.map(a=>ic[a]||a).join(","),l=n.map(a=>e.map(r=>`"${a[r]??""}"`).join(",")).join(` `);return s+` `+l}function Y1(e,n){const s=new Blob([e],{type:"text/csv"}),l=URL.createObjectURL(s),a=document.createElement("a");a.href=l,a.download=n,a.click(),URL.revokeObjectURL(l)}const Wu=e=>String(e??"").replace(/&/g,"&").replace(//g,">");function X1(e,n,s){const l=e.map(f=>`${Wu(ic[f]||f)}`).join(""),a=n.map(f=>`${e.map(k=>`${Wu(f[k])}`).join("")}`).join(""),r=`${l}${a}
`,o=new Blob(["\uFEFF"+r],{type:"application/vnd.ms-excel"}),d=URL.createObjectURL(o),p=document.createElement("a");p.href=d,p.download=s,p.click(),URL.revokeObjectURL(d)}const ph="report-print-area",ho="report-print-portal";function q1(){const e=document.getElementById(ph);if(!e)return;const n=document.createElement("div");n.id=ho,n.innerHTML=e.innerHTML,document.body.appendChild(n);const s=document.createElement("style");s.id="report-print-style",s.textContent=` #${ho} { display: none; } @media print { #root { display: none !important; } #${ho} { display: block !important; } } `,document.head.appendChild(s);const l=()=>{n.remove(),s.remove(),window.removeEventListener("afterprint",l)};window.addEventListener("afterprint",l),window.print()}const Bu={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",minWidth:180},go={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white"};function J1({organizations:e,userRole:n}){const s=se(),l=Q1.filter(I=>I.roles.includes(n)),[a,r]=_.useState(""),[o,d]=_.useState(""),[p,f]=_.useState(""),[k,j]=_.useState(""),[b,c]=_.useState(String(new Date().getFullYear())),[y,z]=_.useState([]),[C,g]=_.useState([]),[i,h]=_.useState(!1),[x,S]=_.useState(""),w=l.find(I=>I.id===a);async function u(){if(a){h(!0),S(""),g([]),z([]);try{const I={};o&&(I.organization=o),p&&(I.from_date=p),k&&(I.to_date=k),(w==null?void 0:w.extraFilter)==="year"&&b&&(I.year=b);const T=await Gy(a,I);z(T.columns||[]),g(T.rows||[])}catch(I){S(I.message||"Error running report")}finally{h(!1)}}}const v=(w==null?void 0:w.label)||a;return t.jsxs("div",{children:[t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12,marginBottom:20},children:l.map(I=>t.jsxs("div",{onClick:()=>r(I.id),style:{background:a===I.id?"#ebf5fb":"white",border:a===I.id?`2px solid ${X.accent}`:"2px solid transparent",borderRadius:10,padding:"14px 16px",cursor:"pointer",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[t.jsx("div",{style:{fontWeight:700,fontSize:14,color:"#1a2332",marginBottom:4},children:I.label}),t.jsx("div",{style:{fontSize:12,color:"#888"},children:I.description})]},I.id))}),t.jsx("div",{style:{background:"white",borderRadius:12,padding:20,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:20},children:t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"REPORT"}),t.jsxs("select",{style:Bu,value:a,onChange:I=>r(I.target.value),children:[t.jsx("option",{value:"",children:"-- Select Report --"}),l.map(I=>t.jsx("option",{value:I.id,children:I.label},I.id))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"ORGANIZATION"}),t.jsxs("select",{style:Bu,value:o,onChange:I=>d(I.target.value),children:[t.jsx("option",{value:"",children:s.filter.allOrgs}),e.map(I=>t.jsx("option",{value:I.name,children:I.organization_name||I.name},I.name))]})]}),(w==null?void 0:w.extraFilter)==="year"?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"YEAR"}),t.jsx("input",{type:"number",style:{...go,width:90},value:b,onChange:I=>c(I.target.value),min:2020,max:2099})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"FROM"}),t.jsx(je,{value:p,onChange:f,style:go})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"TO"}),t.jsx(je,{value:k,onChange:j,style:go})]})]}),t.jsx("button",{onClick:u,disabled:!a||i,style:{padding:"9px 20px",borderRadius:8,border:"none",background:X.accent,color:"white",fontWeight:700,fontSize:13,cursor:a?"pointer":"not-allowed",opacity:a?1:.5},children:i?s.loading:s.reports.generate}),C.length>0&&t.jsx("button",{onClick:()=>Y1(K1(y,C),`${a}.csv`),style:{padding:"9px 20px",borderRadius:8,border:"1px solid #27ae60",background:"white",color:"#27ae60",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Export CSV"}),C.length>0&&t.jsx("button",{onClick:()=>X1(y,C,`${a}.xls`),style:{padding:"9px 20px",borderRadius:8,border:"1px solid #107c41",background:"white",color:"#107c41",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Export Excel"}),C.length>0&&t.jsx("button",{onClick:q1,style:{padding:"9px 20px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Print / PDF"})]})}),x&&t.jsx("div",{style:{color:"#e74c3c",marginBottom:16},children:x}),C.length>0&&t.jsxs("div",{id:ph,style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto"},children:[t.jsxs("div",{style:{padding:"14px 18px",borderBottom:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,color:"#333"},children:v}),t.jsxs("span",{style:{fontSize:12,color:"#888"},children:[C.length," rows"]})]}),t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8f9fa"},children:y.map(I=>t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700,whiteSpace:"nowrap"},children:ic[I]||I.replace(/_/g," ").toUpperCase()},I))})}),t.jsx("tbody",{children:C.map((I,T)=>t.jsx("tr",{style:{borderTop:"1px solid #f0f0f0",background:T%2===0?"white":"#fafafa"},children:y.map(G=>t.jsx("td",{style:{padding:"10px 14px",color:"#333"},children:I[G]!=null?String(I[G]):"—"},G))},T))})]})]}),!i&&C.length===0&&a&&!x&&t.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"Select a report and click Run Report to see results."}),l.length===0&&t.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"No reports are available for your role."})]})}const Ba=()=>new Date().toISOString().split("T")[0],oc=()=>new Date(Date.now()+30*24*60*60*1e3).toISOString().split("T")[0],V1=()=>new Date().toTimeString().slice(0,5),An=()=>({name:"",number:"",title:"",organization:"",group_company:"",event_category:"",type:"",incident_class:"",incident_field:"",date:Ba(),time:V1(),management:"",department:"",section_field:"",branch:"",assigned_to:"",status:"",description:"",summary:"",workflow_state:"New",hses_field:"",priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:""}),xn=()=>({name:"",number:"",title:"",organization:"",group_company:"",type:"",management:"",department:"",section_field:"",branch:"",current_condition:"",proposed_condition:"",status:"",assigned_to:"",workflow_state:"New",idea_class:"",hses_field:"",date:Ba(),priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:"",sb_order:""}),yn=()=>({name:"",number:"",title:"",organization:"",group_company:"",type:"Buy L",management:"",department:"",section_field:"",branch:"",starting_date:Ba(),ending_date:oc(),assigned_to:"",actor:"",status:"",budget:0,actual_cost:0,currency:"SAR",description:"",notes:"",cycle:"",stage:1,completion_pct:0,escalation_level:0,workflow_state:"Draft",planned:0,priority:"",product_relation:0,entity_scope:"",economy_class:"",hses_field:"",auditor_comment:"",sb_idea:"",cycle_type:"Normal",long_cycle_date_1:"",long_cycle_date_2:"",long_cycle_date_3:"",long_cycle_date_4:""}),pr=()=>({name:"",title:"",date_start:Ba(),date_end:oc(),number:"",status:"",cycle_type:"Normal",organization:"",group_company:"",type:"",management:"",department:"",section_field:"",branch:"",progress_indicators:[],cycle:"",actor:"",escalation_level:0,workflow_state:"",chain_location:"",economy_class:"",impact_level:"",product_relation:0,entity_scope:"",hses_field:"",kpi_name:"",kpi_type:"",kpi_measure:"",cost_per_cycle:0,auditor_comment:""}),Zs=()=>({name:"",organization_name:"",group_company:"",type:"Government",city:"",contact_email:"",creation_date:new Date().toISOString().slice(0,10),is_active:1,acronym:"",incident_triage_window_days:3,incident_resolution_window_days:5}),js=()=>({name:"",organization:"",group_company:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),bs=()=>({name:"",custom_organization:"",group_company:"",department_name:"",custom_management:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),Ss=()=>({name:"",organization:"",group_company:"",branch:"",management:"",department:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),el=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),tl=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),nl=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),sl=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),ll=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),al=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),rl=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),il=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),fr=()=>({name:"",first_name:"",full_name:"",email:"",enabled:1,creation:"",username:"",mobile_no:"",custom_organization:"",custom_group_company:"",custom_management:"",custom_department:"",custom_branch:"",custom_number:"",custom_category:""}),_s=()=>({name:"",name1:"",organization:"",group_company:"",frequency:"Monthly",status:"Active",start_date:Ba(),end_date:oc(),update_window_days:2}),ws=()=>({name:"",organization:"",group_company:"",period:"",revenue_growth:0,net_profit:0,cash_flow:0,strategic_goal_pct:0,customer_satisfaction:0,employee_turnover_pct:0,open_safety_incidents:0,compliance_score:0}),ea=()=>({name:"",number:"",auditor:"",manager:"",organization:"",incident_initial_evaluation:0,idea_initial_evaluation:0,status:"Pending",requested_on:"",remarks:""}),Z1=new Set(["incidents","incidents-form","ideas","ideas-form"]),ev=new Set(["orders","orders-form","incidents","incidents-form","ideas","ideas-form"]),tv=new Set(eh.flatMap(({id:e})=>[e,`${e}-form`])),nv=new Set(["Admin","Owner","Auditor","Manager"]),sv=new Set(["Admin","Owner","Auditor","Manager"]),lv=new Set(["Admin","Auditor","Manager"]);function av({user:e,onLogout:n,darkMode:s,onToggleDark:l}){const a=se(),r=e.role,o=nv.has(r),d=sv.has(r),p=lv.has(r),f=m=>m==="users"||m==="users-form"?r==="Admin":r==="Admin"||r==="Auditor"?!0:r==="Owner"||r==="XAuditor"?!1:r==="Manager"?!!ev.has(m):Z1.has(m),k=m=>r==="Employee"&&!!m&&m!=="New",j=o?"dashboard":"inbox",b=m=>m==="dashboard"?o:m==="reports"?d:m==="delegations"||m==="delegations-form"?p:m==="users"||m==="users-form"?r==="Admin":tv.has(m)?r==="Admin"||r==="Auditor":!0,[c,y]=_.useState(()=>{const m=a0(Iu());return m&&b(m)?m:j});_.useEffect(()=>{const m=r0(c);window.location.hash!==m&&window.history.pushState(null,"",m)},[c]),_.useEffect(()=>{const m=()=>{const $=Iu();y($&&b($)?$:j)};return window.addEventListener("popstate",m),()=>window.removeEventListener("popstate",m)},[]);const z=e.custom_organization||"",C=e.custom_group_company||"",g=m=>{var $;return(($=G.find(ke=>ke.name===m))==null?void 0:$.group_company)||""},[i,h]=_.useState(""),[x,S]=_.useState("");_.useEffect(()=>{if(!x)return;const m=setTimeout(()=>S(""),0);return()=>clearTimeout(m)},[x]);const w=(m,$)=>{S($),y(m)},[u,v]=_.useState(0),[I,T]=_.useState([]),[G,K]=_.useState([]),[le,U]=_.useState([]),[F,D]=_.useState([]),[E,A]=_.useState([]),[M,Q]=_.useState([]),[N,ee]=_.useState([]),[Z,ce]=_.useState([]),[ae,Be]=_.useState([]),[$e,ut]=_.useState([]),[q,ue]=_.useState([]),[pe,Ut]=_.useState([]),[tt,ze]=_.useState([]),[Mt,Se]=_.useState([]),[De,Zt]=_.useState([]),[ge,B]=_.useState([]),[ne,O]=_.useState([]),[ve,St]=_.useState([]),[H,Ue]=_.useState([]),[Pt,fs]=_.useState({}),[_n,$a]=_.useState([]),[Us,Ua]=_.useState([]),[Ma,Fa]=_.useState([]),[$l,W]=_.useState([]),[gt,wn]=_.useState([]),[Ft,fh]=_.useState({}),[Rt,hh]=_.useState([]),Ha=()=>({name:"",company_name:"",acronym:"",code:"",status:"Active",owner_user:"",notes:""}),[ji,Ms]=_.useState(Ha()),[Ie,xe]=_.useState(!0),[Ke,fe]=_.useState("idle"),[Ye,te]=_.useState(!1),[dc,cc]=_.useState(!1),[Ga,uc]=_.useState(null),[gh,mh]=_.useState(()=>localStorage.getItem("sb_sidebar")==="1"),xh=()=>mh(m=>{const $=!m;return localStorage.setItem("sb_sidebar",$?"1":"0"),$}),[yh,bi]=_.useState(!1),[vh,Me]=_.useState([]),[jh,Fe]=_.useState([]);_.useEffect(()=>{bi(!1),Me([]),Fe([])},[c]);const[en,kn]=_.useState(An()),[tn,pn]=_.useState(xn()),[Cn,fn]=_.useState(yn()),[zn,hn]=_.useState(pr()),[Si,Fs]=_.useState(Zs()),[_i,hs]=_.useState(js()),[wi,gs]=_.useState(bs()),[ki,ms]=_.useState(Ss()),[Ci,Hs]=_.useState(el()),[zi,Gs]=_.useState(tl()),[Ii,Qs]=_.useState(nl()),[Ti,Ks]=_.useState(sl()),[Ei,Ys]=_.useState(ll()),[Ai,Xs]=_.useState(al()),[Pi,qs]=_.useState(rl()),[Ri,Js]=_.useState(il()),[xs,Qa]=_.useState(fr()),[Di,ys]=_.useState(_s()),[Oi,vs]=_.useState(ws()),[Ht,Ul]=_.useState(ea()),Gt=async()=>{xe(!0);try{const[m,$,ke,Tn,Mn,Oe,Hl,gg,mg,xg,yg,vg,jg,bg,Sg,_g,wg,kg,Cg,zg,Ig,Tg,Eg,Ag,Pg,Rg,Dg]=await Promise.all([Pe(P.incidents),Pe(P.organizations),Pe(P.ideas),Pe(P.orders),Pe(P.processes),zy(),Pe(P.managements),Pe(P.departments),Pe(P.branches),Pe(P.incidentTypes),Pe(P.incidentClass),Pe(P.incidentField),Pe(P.ideaTypes),Pe(P.orderTypes),Pe(P.processTypes),Pe(P.incidentStatuses),Pe(P.ideaStatuses),Pe(P.orderStatuses),Pe(P.processStatuses),Ay(),Py(),Pe(P.cycles),Pe(P.kpiInput),qy(),Vy(),Zy(),e0()]);T(m||[]),K($||[]),U(ke||[]),D(Tn||[]),A(Mn||[]),$a(Oe||[]),Q(Hl||[]),ee(gg||[]),ce(mg||[]),Be(xg||[]),ut(yg||[]),ue(vg||[]),Ut(jg||[]),ze(bg||[]),Se(Sg||[]),Zt(_g||[]),B(wg||[]),O(kg||[]),St(Cg||[]),Ue(zg||[]),fs(Ig||{}),Ua(Tg||[]),Fa(Eg||[]),W(Ag||[]),wn(Pg||[]),fh(Rg||{}),hh(Dg||[])}catch(m){console.error("Error loading data:",m)}xe(!1)},pc=async()=>{try{const m=await fetch("/api/method/sidrah_business.api.get_notification_count",{credentials:"include",headers:{Accept:"application/json"}});if(m.ok){const $=await m.json();v(Number($.message)||0)}}catch{}};_.useEffect(()=>{Gt(),pc();const m=setInterval(pc,6e4);return()=>clearInterval(m)},[e.name]);const[mt,In]=_.useState({isOpen:!1,doctype:"",name:"",title:"",isDeleting:!1}),ie=(m,$,ke)=>{In({isOpen:!0,doctype:m,name:$,title:ke||$,isDeleting:!1})},fc=m=>{const ke={[P.incidents]:"incidents",[P.ideas]:"ideas",[P.orders]:"orders",[P.processes]:"processes",[P.organizations]:"organizations",[P.managements]:"managements",[P.departments]:"departments",[P.branches]:"branches",[P.cycles]:"cycles",[P.kpiInput]:"kpi-input",[P.incidentTypes]:"incident-types",[P.ideaTypes]:"idea-types",[P.orderTypes]:"order-types",[P.processTypes]:"process-types",[P.incidentStatuses]:"incident-statuses",[P.ideaStatuses]:"idea-statuses",[P.orderStatuses]:"order-statuses",[P.processStatuses]:"process-statuses",[P.groupCompanies]:"group-companies"}[m];ke&&y(ke)},hc=async m=>{In($=>({...$,isDeleting:!0}));try{const $=mt.doctype;await dd(mt.doctype,mt.name,m,!1),In(ke=>({...ke,isOpen:!1,isDeleting:!1})),alert(a.rtl?"تم نقل السجل إلى المحذوفات بنجاح!":"Record moved to Deleted successfully!"),await Gt(),c.endsWith("-form")&&fc($)}catch($){console.error("Delete error:",$),alert(($==null?void 0:$.message)||"Delete failed. Please try again."),In(ke=>({...ke,isDeleting:!1}))}},gc=async m=>{In($=>({...$,isDeleting:!0}));try{const $=mt.doctype;await dd(mt.doctype,mt.name,m,!0),In(ke=>({...ke,isOpen:!1,isDeleting:!1})),alert(a.rtl?"تم حذف السجل نهائياً بنجاح!":"Record permanently deleted successfully!"),await Gt(),c.endsWith("-form")&&fc($)}catch($){console.error("Permanent delete error:",$),alert(($==null?void 0:$.message)||"Permanent delete failed. Please try again."),In(ke=>({...ke,isDeleting:!1}))}},Xe=async(m,$)=>{if(window.confirm(a.rtl?"هل أنت متأكد من استعادة هذا السجل؟":"Are you sure you want to restore this record?")){xe(!0);try{await Cy(m,$),alert(a.restoredOk||"Record restored successfully!"),await Gt()}catch(ke){console.error("Restore error:",ke),alert((ke==null?void 0:ke.message)||"Restore failed. Please try again.")}xe(!1)}},bh=async m=>{try{await Ly(m),await Gt()}catch($){console.error("Disable user error:",$)}},Sh=async m=>{te(!0),xe(!0);try{const $=await Dt(P.incidents,m.name);kn({...An(),...$})}catch{kn({...An(),...m})}y("incidents-form"),xe(!1)},_h=async m=>{te(!0),xe(!0);try{const $=await Dt(P.ideas,m.name);pn({...xn(),...$})}catch{pn({...xn(),...m})}y("ideas-form"),xe(!1)},wh=async m=>{te(!0),xe(!0);try{const $=await Dt(P.orders,m.name);fn({...yn(),...$})}catch{fn({...yn(),...m})}y("orders-form"),xe(!1)},kh=async m=>{te(!0),xe(!0);try{const $=await aa(m.name);hn({...$,progress_indicators:$.progress_indicators||[],cycle_logs:$.cycle_logs||[]}),y("processes-form")}catch{hn({...m,progress_indicators:m.progress_indicators||[]}),y("processes-form")}xe(!1)},Ch=m=>we(P.organizations,m,Fs,Zs(),"organizations-form",!0),zh=m=>{te(!0),Ms(m),y("group-companies-form")},Ih=m=>{te(!1),Ms(m),y("group-companies-form")},Th=async m=>{te(!0),xe(!0);try{const $=await Dt(P.managements,m.name);hs({...js(),...$})}catch{hs({...js(),...m})}y("managements-form"),xe(!1)},Eh=async m=>{te(!0),xe(!0);try{const $=await Dt(P.departments,m.name);gs({...bs(),...$})}catch{gs({...bs(),...m})}y("departments-form"),xe(!1)},Ah=async m=>{te(!0),xe(!0);try{const $=await Dt(P.branches,m.name);ms({...Ss(),...$})}catch{ms({...Ss(),...m})}y("branches-form"),xe(!1)},Ph=async m=>{te(!0),xe(!0);try{const $=await Dt(P.cycles,m.name);ys({..._s(),...$})}catch{ys({..._s(),...m})}y("cycles-form"),xe(!1)},Rh=async m=>{te(!0),xe(!0);try{const $=await Dt(P.kpiInput,m.name);vs({...ws(),...$})}catch{vs({...ws(),...m})}y("kpi-input-form"),xe(!1)},at=async(m,$,ke,Tn,Mn)=>{fe("loading");try{if($.name)await Vr(m,$.name,$),fe("success"),Gt(),setTimeout(()=>fe("idle"),1500);else{const Oe=await Jr(m,$),Hl=(Oe==null?void 0:Oe.data)??Oe;Mn&&Mn(Hl),fe("success"),Gt(),setTimeout(()=>fe("idle"),1500)}}catch(Oe){console.error("Submit error:",Oe),fe(Oe instanceof Error?Oe.message:"Error saving. Please try again.")}},He=async()=>{await Ty(),n()},we=async(m,$,ke,Tn,Mn,Oe)=>{te(Oe),xe(!0);try{const Hl=await Dt(m,$.name);ke({...Tn,...Hl})}catch{ke({...Tn,...$})}y(Mn),xe(!1)},Dh=m=>we(P.incidents,m,kn,An(),"incidents-form",!1),Oh=m=>we(P.ideas,m,pn,xn(),"ideas-form",!1),Lh=m=>we(P.orders,m,fn,yn(),"orders-form",!1),Nh=m=>{te(!1),xe(!0),aa(m.name).then($=>{hn({...$,progress_indicators:$.progress_indicators||[],cycle_logs:$.cycle_logs||[]})}).catch(()=>{hn({...m,progress_indicators:m.progress_indicators||[]})}).finally(()=>{y("processes-form"),xe(!1)})},Wh=m=>we(P.organizations,m,Fs,Zs(),"organizations-form",!1),Bh=m=>we(P.managements,m,hs,js(),"managements-form",!1),$h=m=>we(P.departments,m,gs,bs(),"departments-form",!1),Uh=m=>we(P.branches,m,ms,Ss(),"branches-form",!1),Mh=m=>we(P.cycles,m,ys,_s(),"cycles-form",!1),Fh=m=>we(P.kpiInput,m,vs,ws(),"kpi-input-form",!1),Hh=async m=>{te(!0),xe(!0);try{const $=await Jy(m.name);Ul({...ea(),...$})}catch{Ul({...ea(),...m})}y("delegations-form"),xe(!1)},Gh=async()=>{fe("loading");try{const m=[];Ht.incident_initial_evaluation&&m.push("incident_initial_evaluation"),Ht.idea_initial_evaluation&&m.push("idea_initial_evaluation"),await Ky(Ht.manager,m,Ht.organization,Ht.remarks||"",Ht.incident_name||"",Ht.idea_name||""),Ul(ea()),fe("success"),Gt(),setTimeout(()=>{fe("idle"),y("delegations")},1500)}catch(m){console.error("Delegation submit error:",m),fe(m instanceof Error?m.message:"Error saving. Please try again.")}},Qh=async m=>{if(window.confirm(a.rtl?"هل أنت متأكد من إلغاء هذا التفويض؟":"Are you sure you want to revoke this delegation?")){xe(!0);try{await Xy(m),await Gt()}catch($){console.error("Revoke delegation error:",$),alert($ instanceof Error?$.message:"Revoke failed. Please try again.")}xe(!1)}},Kh=m=>we(P.incidentTypes,m,Hs,el(),"incident-types-form",!0),Yh=m=>we(P.incidentTypes,m,Hs,el(),"incident-types-form",!1),Xh=m=>we(P.ideaTypes,m,Gs,tl(),"idea-types-form",!0),qh=m=>we(P.ideaTypes,m,Gs,tl(),"idea-types-form",!1),Jh=m=>we(P.orderTypes,m,Qs,nl(),"order-types-form",!0),Vh=m=>we(P.orderTypes,m,Qs,nl(),"order-types-form",!1),Zh=m=>we(P.processTypes,m,Ks,sl(),"process-types-form",!0),eg=m=>we(P.processTypes,m,Ks,sl(),"process-types-form",!1),tg=m=>we(P.incidentStatuses,m,Ys,ll(),"incident-statuses-form",!0),ng=m=>we(P.incidentStatuses,m,Ys,ll(),"incident-statuses-form",!1),sg=m=>we(P.ideaStatuses,m,Xs,al(),"idea-statuses-form",!0),lg=m=>we(P.ideaStatuses,m,Xs,al(),"idea-statuses-form",!1),ag=m=>we(P.orderStatuses,m,qs,rl(),"order-statuses-form",!0),rg=m=>we(P.orderStatuses,m,qs,rl(),"order-statuses-form",!1),ig=m=>we(P.processStatuses,m,Js,il(),"process-statuses-form",!0),og=m=>we(P.processStatuses,m,Js,il(),"process-statuses-form",!1),dg=async m=>{uc(m),y("profile")},cg=m=>{te(!1),cc(!1),Qa({...fr(),...m}),y("users-form")},ug=async()=>{fe("loading");try{if(!xs.name){const $=await Jr("User",{...xs,send_welcome_email:0,user_type:"System User"});Qa({...fr(),...xs,...($==null?void 0:$.data)??$}),te(!0),fe("success"),Gt(),setTimeout(()=>fe("idle"),1500)}else{const{name:$,email:ke,creation:Tn,full_name:Mn,...Oe}=xs;await Vr("User",$,Oe),fe("success"),Gt(),setTimeout(()=>fe("idle"),1500)}}catch(m){console.error("User submit error:",m),fe(m instanceof Error?m.message:"Error saving. Please try again.")}},Ge=()=>{const m=H.find($=>$.name===e.name||$.username===e.name);uc(m||{name:e.name,full_name:e.full_name,email:e.name,enabled:1}),y("profile")},Li=(m,$)=>{if($){const Tn={"processes-form":P.processes,"orders-form":P.orders,"incidents-form":P.incidents,"ideas-form":P.ideas}[m];if(Tn){te(!0),xe(!0),(m==="processes-form"?aa($).then(Oe=>({...Oe,progress_indicators:Oe.progress_indicators||[],cycle_logs:Oe.cycle_logs||[]})):Dt(Tn,$)).then(Oe=>{m==="processes-form"?hn(Oe):m==="orders-form"?fn({...yn(),...Oe}):m==="incidents-form"?kn({...An(),...Oe}):m==="ideas-form"&&pn({...xn(),...Oe}),y(m),xe(!1)}).catch(()=>{y(m),xe(!1)});return}}y(m)},qe=m=>t.jsxs(t.Fragment,{children:[m,t.jsx(Cu,{isOpen:mt.isOpen,doctype:mt.doctype,docname:mt.name,docTitle:mt.title,isAdmin:r==="Admin"||e.name==="Administrator",isDeleting:mt.isDeleting,onClose:()=>In($=>({...$,isOpen:!1})),onConfirmSoftDelete:hc,onConfirmPermanentDelete:gc})]});if(c==="incidents-form")return qe(t.jsx(w0,{incForm:en,setIncForm:kn,organizations:G,groupCompanies:Rt,managements:M,departments:N,branches:Z,incidentTypes:ae,incidentClasses:$e,incidentFields:q,incidentStatuses:De,users:_n,userRoleMap:Pt,formStatus:Ke,viewMode:Ye||!f("incidents-form")||k(en.workflow_state),canModify:f("incidents-form"),onEdit:f("incidents-form")&&!k(en.workflow_state)&&!Jn("incident",en.workflow_state)?()=>te(!1):void 0,onDelete:f("incidents-form")?m=>ie(P.incidents,m,en.title||en.number):void 0,onRestore:r==="Admin"?m=>Xe(P.incidents,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.incidents,m,en.title||en.number):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,userRole:r,delegatedFunctions:gt,delegatedOrgs:Ft,onSubmit:()=>at(P.incidents,en,()=>kn(An()),"incidents",m=>kn({...An(),...m})),onBack:()=>{y("incidents"),fe("idle")},onNavigate:y,onLogout:He,user:e,onRefresh:async()=>{if(en.name){const m=await Dt(P.incidents,en.name).catch(()=>null);m&&kn({...An(),...m})}Pe(P.incidents).then(m=>T(m||[])).catch(()=>{})}}));if(c==="ideas-form")return qe(t.jsx(I0,{ideaForm:tn,setIdeaForm:pn,organizations:G,groupCompanies:Rt,managements:M,departments:N,branches:Z,ideaTypes:pe,ideaStatuses:ge,users:_n,userRoleMap:Pt,formStatus:Ke,viewMode:Ye||!f("ideas-form")||k(tn.workflow_state),canModify:f("ideas-form"),onEdit:f("ideas-form")&&!k(tn.workflow_state)&&!Jn("idea",tn.workflow_state)?()=>te(!1):void 0,onDelete:f("ideas-form")?m=>ie(P.ideas,m,tn.title||tn.number):void 0,onRestore:r==="Admin"?m=>Xe(P.ideas,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.ideas,m,tn.title||tn.number):void 0,onNavigateToOrder:m=>we(P.orders,{name:m},fn,yn(),"orders-form",!0),darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,userRole:r,delegatedFunctions:gt,delegatedOrgs:Ft,onSubmit:()=>at(P.ideas,tn,()=>pn(xn()),"ideas",m=>pn({...xn(),...m})),onBack:()=>{y("ideas"),fe("idle")},onNavigate:y,onLogout:He,user:e,onRefresh:async()=>{if(tn.name){const m=await Dt(P.ideas,tn.name).catch(()=>null);m&&pn({...xn(),...m})}Pe(P.ideas).then(m=>U(m||[])).catch(()=>{})}}));if(c==="orders-form")return qe(t.jsx(R0,{orderForm:Cn,setOrderForm:fn,organizations:G,groupCompanies:Rt,managements:M,departments:N,branches:Z,orderTypes:tt,orderStatuses:ne,cycles:Us,users:_n,userRoleMap:Pt,formStatus:Ke,viewMode:Ye||!f("orders-form"),canModify:f("orders-form"),onEdit:f("orders-form")&&!Jn("order",Cn.workflow_state)?()=>te(!1):void 0,onDelete:f("orders-form")?m=>ie(P.orders,m,Cn.title||Cn.number):void 0,onRestore:r==="Admin"?m=>Xe(P.orders,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.orders,m,Cn.title||Cn.number):void 0,onNavigateToIdea:m=>we(P.ideas,{name:m},pn,xn(),"ideas-form",!0),darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,currentUser:e.name,userRole:r,onSubmit:()=>at(P.orders,Cn,()=>fn(yn()),"orders",m=>fn({...yn(),...m})),onBack:()=>{y("orders"),fe("idle")},onNavigate:y,onLogout:He,user:e,onRefresh:async()=>{if(Cn.name){const m=await Dt(P.orders,Cn.name).catch(()=>null);m&&fn({...yn(),...m})}Pe(P.orders).then(m=>D(m||[])).catch(()=>{})}}));if(c==="processes-form")return qe(t.jsx(W0,{processForm:zn,setProcessForm:hn,organizations:G,groupCompanies:Rt,managements:M,departments:N,branches:Z,processTypes:Mt,processStatuses:ve,cycles:Us,users:_n,userRoleMap:Pt,formStatus:Ke,viewMode:Ye||!f("processes-form"),canModify:f("processes-form"),onEdit:f("processes-form")&&!Jn("process",zn.workflow_state)?()=>te(!1):void 0,onDelete:f("processes-form")?m=>ie(P.processes,m,zn.title||zn.number):void 0,onRestore:r==="Admin"?m=>Xe(P.processes,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.processes,m,zn.title||zn.number):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,userRole:e.role,onRefreshProcess:async()=>{if(zn.name)try{const m=await aa(zn.name);hn({...m,progress_indicators:m.progress_indicators||[],cycle_logs:m.cycle_logs||[]})}catch{}Pe(P.processes).then(m=>A(m||[])).catch(()=>{})},onSubmit:()=>at(P.processes,zn,()=>hn(pr()),"processes",m=>hn({...pr(),...m,progress_indicators:m.progress_indicators||[],cycle_logs:m.cycle_logs||[]})),onBack:()=>{y("processes"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="organizations-form")return qe(t.jsx(H0,{orgForm:Si,setOrgForm:Fs,groupCompanies:Rt,formStatus:Ke,viewMode:Ye||!f("organizations-form"),onEdit:f("organizations-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.organizations,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.organizations,m,Si.organization_name):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.organizations,Si,()=>Fs(Zs()),"organizations",m=>{Fs({...Zs(),...m}),te(!0)}),onBack:()=>{y("organizations"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="managements-form")return qe(t.jsx(X0,{form:_i,setForm:hs,organizations:G,groupCompanies:Rt,formStatus:Ke,viewMode:Ye||!f("managements-form"),onEdit:f("managements-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.managements,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.managements,m,_i.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.managements,_i,()=>hs(js()),"managements",m=>{hs({...js(),...m}),te(!0)}),onBack:()=>{y("managements"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="departments-form")return qe(t.jsx(V0,{form:wi,setForm:gs,organizations:G,groupCompanies:Rt,managements:M,formStatus:Ke,viewMode:Ye||!f("departments-form"),onEdit:f("departments-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.departments,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.departments,m,wi.department_name):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.departments,wi,()=>gs(bs()),"departments",m=>{gs({...bs(),...m}),te(!0)}),onBack:()=>{y("departments"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="branches-form")return qe(t.jsx(t1,{form:ki,setForm:ms,organizations:G,groupCompanies:Rt,managements:M,departments:N,formStatus:Ke,viewMode:Ye||!f("branches-form"),onEdit:f("branches-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.branches,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.branches,m,ki.branch):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.branches,ki,()=>ms(Ss()),"branches",m=>{ms({...Ss(),...m}),te(!0)}),onBack:()=>{y("branches"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="cycles-form")return qe(t.jsx(R1,{form:Di,setForm:ys,organizations:G,groupCompanies:Rt,formStatus:Ke,viewMode:Ye||!f("cycles-form"),onEdit:f("cycles-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.cycles,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.cycles,m,Di.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.cycles,Di,()=>ys(_s()),"cycles",m=>{ys({..._s(),...m}),te(!0)}),onBack:()=>{y("cycles"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="kpi-input-form")return qe(t.jsx(O1,{form:Oi,setForm:vs,organizations:G,groupCompanies:Rt,formStatus:Ke,viewMode:Ye||!f("kpi-input-form"),onEdit:f("kpi-input-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.kpiInput,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.kpiInput,m,Oi.period):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.kpiInput,Oi,()=>vs(ws()),"kpi-input",m=>{vs({...ws(),...m}),te(!0)}),onBack:()=>{y("kpi-input"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="incident-types-form")return qe(t.jsx(l1,{form:Ci,setForm:Hs,formStatus:Ke,viewMode:Ye||!f("incident-types-form"),onEdit:f("incident-types-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.incidentTypes,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.incidentTypes,m,Ci.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.incidentTypes,Ci,()=>Hs(el()),"incident-types",m=>{Hs({...el(),...m}),te(!0)}),onBack:()=>{y("incident-types"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="idea-types-form")return qe(t.jsx(i1,{form:zi,setForm:Gs,formStatus:Ke,viewMode:Ye||!f("idea-types-form"),onEdit:f("idea-types-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.ideaTypes,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.ideaTypes,m,zi.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.ideaTypes,zi,()=>Gs(tl()),"idea-types",m=>{Gs({...tl(),...m}),te(!0)}),onBack:()=>{y("idea-types"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="order-types-form")return qe(t.jsx(c1,{form:Ii,setForm:Qs,formStatus:Ke,viewMode:Ye||!f("order-types-form"),onEdit:f("order-types-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.orderTypes,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.orderTypes,m,Ii.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.orderTypes,Ii,()=>Qs(nl()),"order-types",m=>{Qs({...nl(),...m}),te(!0)}),onBack:()=>{y("order-types"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="process-types-form")return qe(t.jsx(f1,{form:Ti,setForm:Ks,formStatus:Ke,viewMode:Ye||!f("process-types-form"),onEdit:f("process-types-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.processTypes,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.processTypes,m,Ti.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.processTypes,Ti,()=>Ks(sl()),"process-types",m=>{Ks({...sl(),...m}),te(!0)}),onBack:()=>{y("process-types"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="incident-statuses-form")return qe(t.jsx(m1,{form:Ei,setForm:Ys,formStatus:Ke,viewMode:Ye||!f("incident-statuses-form"),onEdit:f("incident-statuses-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.incidentStatuses,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.incidentStatuses,m,Ei.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.incidentStatuses,Ei,()=>Ys(ll()),"incident-statuses",m=>{Ys({...ll(),...m}),te(!0)}),onBack:()=>{y("incident-statuses"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="idea-statuses-form")return qe(t.jsx(v1,{form:Ai,setForm:Xs,formStatus:Ke,viewMode:Ye||!f("idea-statuses-form"),onEdit:f("idea-statuses-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.ideaStatuses,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.ideaStatuses,m,Ai.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.ideaStatuses,Ai,()=>Xs(al()),"idea-statuses",m=>{Xs({...al(),...m}),te(!0)}),onBack:()=>{y("idea-statuses"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="order-statuses-form")return qe(t.jsx(S1,{form:Pi,setForm:qs,formStatus:Ke,viewMode:Ye||!f("order-statuses-form"),onEdit:f("order-statuses-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.orderStatuses,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.orderStatuses,m,Pi.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.orderStatuses,Pi,()=>qs(rl()),"order-statuses",m=>{qs({...rl(),...m}),te(!0)}),onBack:()=>{y("order-statuses"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="process-statuses-form")return qe(t.jsx(k1,{form:Ri,setForm:Js,formStatus:Ke,viewMode:Ye||!f("process-statuses-form"),onEdit:f("process-statuses-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.processStatuses,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.processStatuses,m,Ri.name1):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.processStatuses,Ri,()=>Js(il()),"process-statuses",m=>{Js({...il(),...m}),te(!0)}),onBack:()=>{y("process-statuses"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="users-form")return qe(t.jsx(T1,{form:xs,setForm:Qa,groupCompanies:Rt,organizations:G,managements:M,departments:N,branches:Z,formStatus:Ke,viewMode:Ye||!f("users-form"),onEdit:f("users-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.users,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.users,m,xs.full_name||xs.email):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,isSelfProfile:dc,onSubmit:ug,onBack:()=>{y(dc?o?"dashboard":"inbox":"users"),fe("idle")},onNavigate:y,onLogout:He,user:e}));if(c==="delegations-form"){const m=Ht.status==="Revoked"||Ht.status==="Accepted"||Ht.status==="Rejected";return qe(t.jsx(U1,{form:Ht,setForm:Ul,organizations:G,users:_n,userRoleMap:Pt,incidents:I,ideas:le,formStatus:Ke,viewMode:Ye||!f("delegations-form")||m,onEdit:f("delegations-form")&&!m?()=>te(!1):void 0,onRestore:r==="Admin"?$=>Xe(P.delegations,$):void 0,onPermanentDelete:r==="Admin"?$=>ie(P.delegations,$,Ht.name):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:Gh,onBack:()=>{y("delegations"),fe("idle")},onNavigate:y,onLogout:He,user:e}))}if(c==="group-companies-form")return qe(t.jsx(Q0,{form:ji,setForm:Ms,users:_n,formStatus:Ke,viewMode:Ye||!f("group-companies-form"),onEdit:f("group-companies-form")?()=>te(!1):void 0,onRestore:r==="Admin"?m=>Xe(P.groupCompanies,m):void 0,onPermanentDelete:r==="Admin"?m=>ie(P.groupCompanies,m,ji.company_name):void 0,darkMode:s,notifCount:u,onToggleDark:l,onCountChange:v,onViewProfile:Ge,onSubmit:()=>at(P.groupCompanies,ji,()=>Ms(Ha()),"group-companies",m=>{Ms({...Ha(),...m}),te(!0)}),onBack:()=>{y("group-companies"),fe("idle")},onNavigate:y,onLogout:He,user:e}));const Ni={...a.pages,"group-companies":"Group Companies","group-companies-form":"Group Company Form"},pg={"group-companies":{color:X.purple,formPage:"group-companies-form",reset:()=>Ms(Ha())},incidents:{color:X.accent,formPage:"incidents-form",reset:()=>{const m=z||i;kn({...An(),organization:m,group_company:C||g(m)})}},ideas:{color:X.teal,formPage:"ideas-form",reset:()=>{const m=z||i;pn({...xn(),organization:m,group_company:C||g(m)})}},orders:{color:X.purple,formPage:"orders-form",reset:()=>{const m=z||i;fn({...yn(),organization:m,group_company:C||g(m)})}},processes:{color:X.blue,formPage:"processes-form",reset:()=>{const m=Ft.create_processes,$=z||(r==="Manager"&&m&&m.length===1?m[0]:i);hn({...pr(),organization:$,group_company:C||g($)})}},organizations:{color:X.accent,formPage:"organizations-form",reset:()=>Fs({...Zs(),group_company:C})},managements:{color:X.blue,formPage:"managements-form",reset:()=>{const m=z||i;hs({...js(),organization:m,group_company:C||g(m)})}},departments:{color:X.teal,formPage:"departments-form",reset:()=>{const m=z||i;gs({...bs(),custom_organization:m,group_company:C||g(m)})}},branches:{color:X.purple,formPage:"branches-form",reset:()=>{const m=z||i;ms({...Ss(),organization:m,group_company:C||g(m)})}},cycles:{color:X.teal,formPage:"cycles-form",reset:()=>{const m=z||i;ys({..._s(),organization:m,group_company:C||g(m)})}},"kpi-input":{color:X.blue,formPage:"kpi-input-form",reset:()=>{const m=z||i;vs({...ws(),organization:m,group_company:C||g(m)})}},"incident-types":{color:X.red,formPage:"incident-types-form",reset:()=>Hs(el())},"idea-types":{color:X.orange,formPage:"idea-types-form",reset:()=>Gs(tl())},"order-types":{color:X.green,formPage:"order-types-form",reset:()=>Qs(nl())},"process-types":{color:X.accent,formPage:"process-types-form",reset:()=>Ks(sl())},"incident-statuses":{color:X.red,formPage:"incident-statuses-form",reset:()=>Ys(ll())},"idea-statuses":{color:X.teal,formPage:"idea-statuses-form",reset:()=>Xs(al())},"order-statuses":{color:X.purple,formPage:"order-statuses-form",reset:()=>qs(rl())},"process-statuses":{color:X.blue,formPage:"process-statuses-form",reset:()=>Js(il())},users:{color:X.blue,formPage:"users-form",reset:()=>{Qa({...fr(),custom_group_company:C}),cc(!1)}},delegations:{color:X.purple,formPage:"delegations-form",reset:()=>Ul(ea())}},fg={"group-companies":"New Group Company",incidents:a.formTitle.newIncident,ideas:a.formTitle.newIdea,orders:a.formTitle.newOrder,processes:a.formTitle.newProcess,organizations:a.formTitle.newOrg,managements:a.formTitle.newMgmt,departments:a.formTitle.newDept,branches:a.formTitle.newBranch,users:a.formTitle.newUser,cycles:a.formTitle.newCycle,"kpi-input":a.formTitle.newKpi,delegations:a.formTitle.newDelegation,"incident-types":"New Incident Type","idea-types":"New Idea Type","order-types":"New Order Type","process-types":"New Process Type","incident-statuses":"New Incident Status","idea-statuses":"New Idea Status","order-statuses":"New Order Status","process-statuses":"New Process Status"},hg={incidents:I,ideas:le,orders:F,processes:E,organizations:G,managements:M,departments:N,branches:Z,cycles:Us,"kpi-input":Ma,"incident-types":ae,"idea-types":pe,"order-types":tt,"process-types":Mt,"incident-statuses":De,"idea-statuses":ge,"order-statuses":ne,"process-statuses":ve,users:H,delegations:$l},Ml=cy[c],Fl=hg[c],V=f(c),Wi=V?pg[c]:null;return t.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:s?"#0f172a":X.bg},children:[t.jsx(rh,{collapsed:gh,onToggleCollapsed:xh,activePage:c,onNavigate:m=>y(m),hasDashboard:o,hasReports:d,hasDelegations:p,role:r,rtl:a.rtl,navLabels:a.nav,settingsLabel:a.nav.settings}),t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[t.jsx("div",{style:{background:s?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${s?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:s?"none":"0 1px 4px rgba(0,0,0,0.04)"},children:t.jsx(ch,{notifCount:u,darkMode:s,onCountChange:v,onToggleDark:l,onNavigate:Li,onViewProfile:Ge,onLogout:He,userName:e.full_name||e.name,userRole:r})}),c!=="profile"&&t.jsxs("div",{style:{background:s?"#1e293b":"white",padding:"12px 24px",borderBottom:`1px solid ${s?"#2d3748":"#e2e8f0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:18,fontWeight:700,color:s?"#e2e8f0":"#0f172a"},children:Ni[c]||c}),Fl&&t.jsxs("div",{style:{fontSize:12,color:"#64748b",marginTop:2,fontWeight:500},children:["Total: ",Fl.length," ",Ni[c]?Ni[c].toLowerCase():"records"]})]}),t.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[Ml&&Fl&&t.jsx("button",{onClick:()=>bi(!0),style:{background:"#16a34a",color:"white",border:"none",padding:"7px 16px",borderRadius:8,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6,boxShadow:"0 1px 2px rgba(0,0,0,0.06)"},children:"📊 Export"}),Wi&&t.jsxs("button",{onClick:()=>{Wi.reset(),te(!1),fe("idle"),y(Wi.formPage)},style:{background:"#2563eb",color:"white",border:"none",padding:"7px 16px",borderRadius:8,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6,boxShadow:"0 1px 2px rgba(0,0,0,0.06)"},children:["+ ",fg[c]||a.new]})]})]}),Ml&&Fl&&yh&&t.jsx(_y,{title:Ml.label,rows:Fl,selectedRows:vh,pageRows:jh,columns:Ml.columns,defaultColumnKeys:Ml.defaultColumns,filenameBase:c,onClose:()=>bi(!1)}),t.jsxs("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",padding:c==="profile"?0:"20px 24px",gap:c==="profile"?0:16},children:[Ie&&t.jsx("div",{style:{textAlign:"center",paddingTop:60,color:"#aaa",fontSize:15},children:a.loading}),!Ie&&c==="dashboard"&&o&&t.jsx(h0,{incidents:I,ideas:le,orders:F,processes:E,organizations:G,incidentStatuses:De,ideaStatuses:ge,orderStatuses:ne,processStatuses:ve,selectedOrg:i,onOrgChange:h,onNavigate:Li,onNavigateStatus:w,userRole:r}),!Ie&&c==="inbox"&&t.jsx(G1,{onNavigate:Li,onRefresh:Gt}),!Ie&&c==="reports"&&d&&t.jsx(J1,{organizations:G,userRole:r}),!Ie&&c==="incidents"&&t.jsx(g0,{incidents:I,organizations:G,departments:N,branches:Z,incidentStatuses:De,initialOrg:i,initialStatus:x,onView:Sh,onEdit:V?Dh:void 0,onDelete:V?m=>ie(P.incidents,m):void 0,canModify:V,userRole:r,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="ideas"&&t.jsx(k0,{ideas:le,organizations:G,departments:N,branches:Z,ideaStatuses:ge,initialOrg:i,initialStatus:x,onView:_h,onEdit:V?Oh:void 0,onDelete:V?m=>ie(P.ideas,m):void 0,canModify:V,userRole:r,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="orders"&&t.jsx(T0,{orders:F,organizations:G,departments:N,branches:Z,orderStatuses:ne,initialOrg:i,initialStatus:x,onView:wh,onEdit:V?Lh:void 0,onDelete:V?m=>ie(P.orders,m):void 0,canModify:V,userRole:r,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="processes"&&t.jsx(D0,{processes:E,organizations:G,departments:N,branches:Z,processStatuses:ve,initialOrg:i,initialStatus:x,onView:kh,onEdit:V?Nh:void 0,onDelete:V?m=>ie(P.processes,m):void 0,canModify:V,userRole:r,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="organizations"&&t.jsx(F0,{organizations:G,onView:Ch,onEdit:V?Wh:void 0,onDelete:V?m=>ie(P.organizations,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="group-companies"&&t.jsx(G0,{groupCompanies:Rt,onView:zh,onEdit:V?Ih:void 0,onDelete:V?m=>ie(P.groupCompanies,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="managements"&&t.jsx(Y0,{managements:M,onView:Th,onEdit:V?Bh:void 0,onDelete:V?m=>ie(P.managements,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="departments"&&t.jsx(J0,{departments:N,managements:M,onView:Eh,onEdit:V?$h:void 0,onDelete:V?m=>ie(P.departments,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="branches"&&t.jsx(e1,{branches:Z,managements:M,departments:N,onView:Ah,onEdit:V?Uh:void 0,onDelete:V?m=>ie(P.branches,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="cycles"&&t.jsx(E1,{cycles:Us,canModify:V,onView:Ph,onEdit:V?Mh:void 0,onDelete:V?m=>ie(P.cycles,m):void 0,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="kpi-input"&&t.jsx(D1,{kpiInputs:Ma,canModify:V,onView:Rh,onEdit:V?Fh:void 0,onDelete:V?m=>ie(P.kpiInput,m):void 0,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="incident-types"&&t.jsx(s1,{incidentTypes:ae,onView:Kh,onEdit:V?Yh:void 0,onDelete:V?m=>ie(P.incidentTypes,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="idea-types"&&t.jsx(r1,{ideaTypes:pe,onView:Xh,onEdit:V?qh:void 0,onDelete:V?m=>ie(P.ideaTypes,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="order-types"&&t.jsx(d1,{orderTypes:tt,onView:Jh,onEdit:V?Vh:void 0,onDelete:V?m=>ie(P.orderTypes,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="process-types"&&t.jsx(p1,{processTypes:Mt,onView:Zh,onEdit:V?eg:void 0,onDelete:V?m=>ie(P.processTypes,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="incident-statuses"&&t.jsx(g1,{incidentStatuses:De,onView:tg,onEdit:V?ng:void 0,onDelete:V?m=>ie(P.incidentStatuses,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="idea-statuses"&&t.jsx(y1,{ideaStatuses:ge,onView:sg,onEdit:V?lg:void 0,onDelete:V?m=>ie(P.ideaStatuses,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="order-statuses"&&t.jsx(b1,{orderStatuses:ne,onView:ag,onEdit:V?rg:void 0,onDelete:V?m=>ie(P.orderStatuses,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="process-statuses"&&t.jsx(w1,{processStatuses:ve,onView:ig,onEdit:V?og:void 0,onDelete:V?m=>ie(P.processStatuses,m):void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="users"&&t.jsx(I1,{users:H,roleMap:Pt,onView:dg,onEdit:V?cg:void 0,onDelete:V?m=>ie("User",m):void 0,onDisable:V?bh:void 0,canModify:V,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),!Ie&&c==="delegations"&&p&&t.jsx(B1,{delegations:$l,organizations:G,userRole:r,currentUser:e.name,onView:Hh,onRevoke:V?Qh:void 0,onSelectionChange:(m,$)=>{Me(m),Fe($)}}),c==="profile"&&(()=>{const m=!!Ga&&(Ga.name===e.name||Ga.email===e.name);return t.jsx($0,{user:e,profileUser:Ga,sbUsers:H,organizations:G,groupCompanies:Rt,managements:M,departments:N,branches:Z,darkMode:s,canModify:V||m,onBack:()=>y(m?o?"dashboard":"inbox":"users"),onNavigate:y})})()]})]}),t.jsx(Cu,{isOpen:mt.isOpen,doctype:mt.doctype,docname:mt.name,docTitle:mt.title,isAdmin:r==="Admin"||e.name==="Administrator",isDeleting:mt.isDeleting,onClose:()=>In(m=>({...m,isOpen:!1})),onConfirmSoftDelete:hc,onConfirmPermanentDelete:gc})]})}function rv(e){return e.some(n=>["SB Admin","System Manager"].includes(n))?"Admin":e.includes("SB Manager")?"Manager":e.includes("SB Auditor")?"Auditor":e.includes("SB Owner")?"Owner":e.includes("SB X-Auditor")?"XAuditor":"Employee"}function iv(){const[e,n]=_.useState(()=>{try{const d=localStorage.getItem("sidrah_user");return d?JSON.parse(d):null}catch{return null}}),[s,l]=_.useState(()=>localStorage.getItem("sb_dark")==="1"),a=()=>{const d=!s;l(d),localStorage.setItem("sb_dark",d?"1":"0"),document.documentElement.classList.toggle("dark",d)};_.useEffect(()=>{document.documentElement.classList.toggle("dark",s)},[]),_.useEffect(()=>{e&&ih().then(async d=>{const p=d||e.name,f=await dh(p);if(!f.length)return;const k=rv(f),j=await $y();if(k!==e.role||p!==e.name||j!==(e.custom_organization||"")){const c={...e,name:p,role:k,custom_organization:j};n(c),localStorage.setItem("sidrah_user",JSON.stringify(c))}})},[e==null?void 0:e.name]);const r=d=>{n(d),localStorage.setItem("sidrah_user",JSON.stringify(d))},o=()=>{n(null),localStorage.removeItem("sidrah_user")};return e?t.jsx(av,{user:e,onLogout:o,darkMode:s,onToggleDark:a}):t.jsx(i0,{onLogin:r})}Zf(document.getElementById("root")).render(t.jsx(_.StrictMode,{children:t.jsx(iv,{})}));