(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&s(a)}).observe(document,{childList:!0,subtree:!0});function l(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(r){if(r.ep)return;r.ep=!0;const i=l(r);fetch(r.href,i)}})();var xu={exports:{}},Ci={},mu={exports:{}},ae={};/** * @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 sr=Symbol.for("react.element"),dg=Symbol.for("react.portal"),ug=Symbol.for("react.fragment"),pg=Symbol.for("react.strict_mode"),fg=Symbol.for("react.profiler"),hg=Symbol.for("react.provider"),gg=Symbol.for("react.context"),xg=Symbol.for("react.forward_ref"),mg=Symbol.for("react.suspense"),yg=Symbol.for("react.memo"),vg=Symbol.for("react.lazy"),Mc=Symbol.iterator;function jg(e){return e===null||typeof e!="object"?null:(e=Mc&&e[Mc]||e["@@iterator"],typeof e=="function"?e:null)}var yu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},vu=Object.assign,ju={};function Gl(e,t,l){this.props=e,this.context=t,this.refs=ju,this.updater=l||yu}Gl.prototype.isReactComponent={};Gl.prototype.setState=function(e,t){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,t,"setState")};Gl.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function bu(){}bu.prototype=Gl.prototype;function Co(e,t,l){this.props=e,this.context=t,this.refs=ju,this.updater=l||yu}var zo=Co.prototype=new bu;zo.constructor=Co;vu(zo,Gl.prototype);zo.isPureReactComponent=!0;var Hc=Array.isArray,Su=Object.prototype.hasOwnProperty,To={current:null},wu={key:!0,ref:!0,__self:!0,__source:!0};function ku(e,t,l){var s,r={},i=null,a=null;if(t!=null)for(s in t.ref!==void 0&&(a=t.ref),t.key!==void 0&&(i=""+t.key),t)Su.call(t,s)&&!wu.hasOwnProperty(s)&&(r[s]=t[s]);var d=arguments.length-2;if(d===1)r.children=l;else if(1>>1,q=A[V];if(0>>1;Vr(se,G))jer(Qe,se)?(A[V]=Qe,A[je]=G,V=je):(A[V]=se,A[Ce]=G,V=Ce);else if(jer(Qe,G))A[V]=Qe,A[je]=G,V=je;else break e}}return Q}function r(A,Q){var G=A.sortIndex-Q.sortIndex;return G!==0?G:A.id-Q.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var a=Date,d=a.now();e.unstable_now=function(){return a.now()-d}}var u=[],f=[],y=1,p=null,c=3,v=!1,w=!1,g=!1,b=typeof setTimeout=="function"?setTimeout:null,x=typeof clearTimeout=="function"?clearTimeout:null,h=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function o(A){for(var Q=l(f);Q!==null;){if(Q.callback===null)s(f);else if(Q.startTime<=A)s(f),Q.sortIndex=Q.expirationTime,t(u,Q);else break;Q=l(f)}}function m(A){if(g=!1,o(A),!w)if(l(u)!==null)w=!0,ee(C);else{var Q=l(f);Q!==null&&me(m,Q.startTime-A)}}function C(A,Q){w=!1,g&&(g=!1,x(S),S=-1),v=!0;var G=c;try{for(o(Q),p=l(u);p!==null&&(!(p.expirationTime>Q)||A&&!T());){var V=p.callback;if(typeof V=="function"){p.callback=null,c=p.priorityLevel;var q=V(p.expirationTime<=Q);Q=e.unstable_now(),typeof q=="function"?p.callback=q:p===l(u)&&s(u),o(Q)}else s(u);p=l(u)}if(p!==null)var ge=!0;else{var Ce=l(f);Ce!==null&&me(m,Ce.startTime-Q),ge=!1}return ge}finally{p=null,c=G,v=!1}}var P=!1,R=null,S=-1,_=5,$=-1;function T(){return!(e.unstable_now()-$<_)}function I(){if(R!==null){var A=e.unstable_now();$=A;var Q=!0;try{Q=R(!0,A)}finally{Q?N():(P=!1,R=null)}}else P=!1}var N;if(typeof h=="function")N=function(){h(I)};else if(typeof MessageChannel<"u"){var F=new MessageChannel,ne=F.port2;F.port1.onmessage=I,N=function(){ne.postMessage(null)}}else N=function(){b(I,0)};function ee(A){R=A,P||(P=!0,N())}function me(A,Q){S=b(function(){A(e.unstable_now())},Q)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(A){A.callback=null},e.unstable_continueExecution=function(){w||v||(w=!0,ee(C))},e.unstable_forceFrameRate=function(A){0>A||125V?(A.sortIndex=G,t(f,A),l(u)===null&&A===l(f)&&(g?(x(S),S=-1):g=!0,me(m,G-V))):(A.sortIndex=q,t(u,A),w||v||(w=!0,ee(C))),A},e.unstable_shouldYield=T,e.unstable_wrapCallback=function(A){var Q=c;return function(){var G=c;c=Q;try{return A.apply(this,arguments)}finally{c=G}}}})(Pu);Tu.exports=Pu;var Eg=Tu.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 Ag=j,jt=Eg;function M(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,l=1;l"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ea=Object.prototype.hasOwnProperty,Rg=/^[: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]*$/,Qc={},Gc={};function Lg(e){return Ea.call(Gc,e)?!0:Ea.call(Qc,e)?!1:Rg.test(e)?Gc[e]=!0:(Qc[e]=!0,!1)}function Og(e,t,l,s){if(l!==null&&l.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return s?!1:l!==null?!l.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function Dg(e,t,l,s){if(t===null||typeof t>"u"||Og(e,t,l,s))return!0;if(s)return!1;if(l!==null)switch(l.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function at(e,t,l,s,r,i,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=s,this.attributeNamespace=r,this.mustUseProperty=l,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=a}var Ve={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Ve[e]=new at(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Ve[t]=new at(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Ve[e]=new at(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Ve[e]=new at(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){Ve[e]=new at(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Ve[e]=new at(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Ve[e]=new at(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Ve[e]=new at(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Ve[e]=new at(e,5,!1,e.toLowerCase(),null,!1,!1)});var Io=/[\-:]([a-z])/g;function Eo(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 t=e.replace(Io,Eo);Ve[t]=new at(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(Io,Eo);Ve[t]=new at(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(Io,Eo);Ve[t]=new at(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Ve[e]=new at(e,1,!1,e.toLowerCase(),null,!1,!1)});Ve.xlinkHref=new at("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Ve[e]=new at(e,1,!1,e.toLowerCase(),null,!0,!0)});function Ao(e,t,l,s){var r=Ve.hasOwnProperty(t)?Ve[t]:null;(r!==null?r.type!==0:s||!(2d||r[a]!==i[d]){var u=` `+r[a].replace(" at new "," at ");return e.displayName&&u.includes("")&&(u=u.replace("",e.displayName)),u}while(1<=a&&0<=d);break}}}finally{ea=!1,Error.prepareStackTrace=l}return(e=e?e.displayName||e.name:"")?zs(e):""}function Ng(e){switch(e.tag){case 5:return zs(e.type);case 16:return zs("Lazy");case 13:return zs("Suspense");case 19:return zs("SuspenseList");case 0:case 2:case 15:return e=ta(e.type,!1),e;case 11:return e=ta(e.type.render,!1),e;case 1:return e=ta(e.type,!0),e;default:return""}}function Oa(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 jl:return"Fragment";case vl:return"Portal";case Aa:return"Profiler";case Ro:return"StrictMode";case Ra:return"Suspense";case La:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Au:return(e.displayName||"Context")+".Consumer";case Eu:return(e._context.displayName||"Context")+".Provider";case Lo:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Oo:return t=e.displayName||null,t!==null?t:Oa(e.type)||"Memo";case vn:t=e._payload,e=e._init;try{return Oa(e(t))}catch{}}return null}function Wg(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Oa(t);case 8:return t===Ro?"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 t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Ln(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Lu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Bg(e){var t=Lu(e)?"checked":"value",l=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),s=""+e[t];if(!e.hasOwnProperty(t)&&typeof l<"u"&&typeof l.get=="function"&&typeof l.set=="function"){var r=l.get,i=l.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return r.call(this)},set:function(a){s=""+a,i.call(this,a)}}),Object.defineProperty(e,t,{enumerable:l.enumerable}),{getValue:function(){return s},setValue:function(a){s=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function jr(e){e._valueTracker||(e._valueTracker=Bg(e))}function Ou(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var l=t.getValue(),s="";return e&&(s=Lu(e)?e.checked?"true":"false":e.value),e=s,e!==l?(t.setValue(e),!0):!1}function ti(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 Da(e,t){var l=t.checked;return Pe({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:l??e._wrapperState.initialChecked})}function Xc(e,t){var l=t.defaultValue==null?"":t.defaultValue,s=t.checked!=null?t.checked:t.defaultChecked;l=Ln(t.value!=null?t.value:l),e._wrapperState={initialChecked:s,initialValue:l,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Du(e,t){t=t.checked,t!=null&&Ao(e,"checked",t,!1)}function Na(e,t){Du(e,t);var l=Ln(t.value),s=t.type;if(l!=null)s==="number"?(l===0&&e.value===""||e.value!=l)&&(e.value=""+l):e.value!==""+l&&(e.value=""+l);else if(s==="submit"||s==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Wa(e,t.type,l):t.hasOwnProperty("defaultValue")&&Wa(e,t.type,Ln(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Jc(e,t,l){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var s=t.type;if(!(s!=="submit"&&s!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,l||t===e.value||(e.value=t),e.defaultValue=t}l=e.name,l!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,l!==""&&(e.name=l)}function Wa(e,t,l){(t!=="number"||ti(e.ownerDocument)!==e)&&(l==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+l&&(e.defaultValue=""+l))}var Ts=Array.isArray;function Al(e,t,l,s){if(e=e.options,t){t={};for(var r=0;r"+t.valueOf().toString()+"",t=br.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Fs(e,t){if(t){var l=e.firstChild;if(l&&l===e.lastChild&&l.nodeType===3){l.nodeValue=t;return}}e.textContent=t}var As={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},$g=["Webkit","ms","Moz","O"];Object.keys(As).forEach(function(e){$g.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),As[t]=As[e]})});function $u(e,t,l){return t==null||typeof t=="boolean"||t===""?"":l||typeof t!="number"||t===0||As.hasOwnProperty(e)&&As[e]?(""+t).trim():t+"px"}function Uu(e,t){e=e.style;for(var l in t)if(t.hasOwnProperty(l)){var s=l.indexOf("--")===0,r=$u(l,t[l],s);l==="float"&&(l="cssFloat"),s?e.setProperty(l,r):e[l]=r}}var Ug=Pe({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 Ua(e,t){if(t){if(Ug[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(M(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(M(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(M(61))}if(t.style!=null&&typeof t.style!="object")throw Error(M(62))}}function Fa(e,t){if(e.indexOf("-")===-1)return typeof t.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 Ma=null;function Do(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Ha=null,Rl=null,Ll=null;function Vc(e){if(e=ar(e)){if(typeof Ha!="function")throw Error(M(280));var t=e.stateNode;t&&(t=Ei(t),Ha(e.stateNode,e.type,t))}}function Fu(e){Rl?Ll?Ll.push(e):Ll=[e]:Rl=e}function Mu(){if(Rl){var e=Rl,t=Ll;if(Ll=Rl=null,Vc(e),t)for(e=0;e>>=0,e===0?32:31-(Zg(e)/Vg|0)|0}var Sr=64,wr=4194304;function Ps(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 ri(e,t){var l=e.pendingLanes;if(l===0)return 0;var s=0,r=e.suspendedLanes,i=e.pingedLanes,a=l&268435455;if(a!==0){var d=a&~r;d!==0?s=Ps(d):(i&=a,i!==0&&(s=Ps(i)))}else a=l&~r,a!==0?s=Ps(a):i!==0&&(s=Ps(i));if(s===0)return 0;if(t!==0&&t!==s&&!(t&r)&&(r=s&-s,i=t&-t,r>=i||r===16&&(i&4194240)!==0))return t;if(s&4&&(s|=l&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=s;0l;l++)t.push(e);return t}function rr(e,t,l){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Nt(t),e[t]=l}function lx(e,t){var l=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var s=e.eventTimes;for(e=e.expirationTimes;0=Ls),od=" ",cd=!1;function cp(e,t){switch(e){case"keyup":return Ex.indexOf(t.keyCode)!==-1;case"keydown":return t.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 bl=!1;function Rx(e,t){switch(e){case"compositionend":return dp(t);case"keypress":return t.which!==32?null:(cd=!0,od);case"textInput":return e=t.data,e===od&&cd?null:e;default:return null}}function Lx(e,t){if(bl)return e==="compositionend"||!Ho&&cp(e,t)?(e=ap(),Qr=Uo=wn=null,bl=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:l,offset:t-e};e=s}e:{for(;l;){if(l.nextSibling){l=l.nextSibling;break e}l=l.parentNode}l=void 0}l=fd(l)}}function hp(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?hp(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function gp(){for(var e=window,t=ti();t instanceof e.HTMLIFrameElement;){try{var l=typeof t.contentWindow.location.href=="string"}catch{l=!1}if(l)e=t.contentWindow;else break;t=ti(e.document)}return t}function Ko(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function Mx(e){var t=gp(),l=e.focusedElem,s=e.selectionRange;if(t!==l&&l&&l.ownerDocument&&hp(l.ownerDocument.documentElement,l)){if(s!==null&&Ko(l)){if(t=s.start,e=s.end,e===void 0&&(e=t),"selectionStart"in l)l.selectionStart=t,l.selectionEnd=Math.min(e,l.value.length);else if(e=(t=l.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var r=l.textContent.length,i=Math.min(s.start,r);s=s.end===void 0?i:Math.min(s.end,r),!e.extend&&i>s&&(r=s,s=i,i=r),r=hd(l,i);var a=hd(l,s);r&&a&&(e.rangeCount!==1||e.anchorNode!==r.node||e.anchorOffset!==r.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(r.node,r.offset),e.removeAllRanges(),i>s?(e.addRange(t),e.extend(a.node,a.offset)):(t.setEnd(a.node,a.offset),e.addRange(t)))}}for(t=[],e=l;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof l.focus=="function"&&l.focus(),l=0;l=document.documentMode,Sl=null,Ja=null,Ds=null,qa=!1;function gd(e,t,l){var s=l.window===l?l.document:l.nodeType===9?l:l.ownerDocument;qa||Sl==null||Sl!==ti(s)||(s=Sl,"selectionStart"in s&&Ko(s)?s={start:s.selectionStart,end:s.selectionEnd}:(s=(s.ownerDocument&&s.ownerDocument.defaultView||window).getSelection(),s={anchorNode:s.anchorNode,anchorOffset:s.anchorOffset,focusNode:s.focusNode,focusOffset:s.focusOffset}),Ds&&Ys(Ds,s)||(Ds=s,s=oi(Ja,"onSelect"),0_l||(e.current=lo[_l],lo[_l]=null,_l--)}function ve(e,t){_l++,lo[_l]=e.current,e.current=t}var On={},lt=Wn(On),ut=Wn(!1),Yn=On;function Bl(e,t){var l=e.type.contextTypes;if(!l)return On;var s=e.stateNode;if(s&&s.__reactInternalMemoizedUnmaskedChildContext===t)return s.__reactInternalMemoizedMaskedChildContext;var r={},i;for(i in l)r[i]=t[i];return s&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=r),r}function pt(e){return e=e.childContextTypes,e!=null}function di(){Se(ut),Se(lt)}function Sd(e,t,l){if(lt.current!==On)throw Error(M(168));ve(lt,t),ve(ut,l)}function kp(e,t,l){var s=e.stateNode;if(t=t.childContextTypes,typeof s.getChildContext!="function")return l;s=s.getChildContext();for(var r in s)if(!(r in t))throw Error(M(108,Wg(e)||"Unknown",r));return Pe({},l,s)}function ui(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||On,Yn=lt.current,ve(lt,e),ve(ut,ut.current),!0}function wd(e,t,l){var s=e.stateNode;if(!s)throw Error(M(169));l?(e=kp(e,t,Yn),s.__reactInternalMemoizedMergedChildContext=e,Se(ut),Se(lt),ve(lt,e)):Se(ut),ve(ut,l)}var ln=null,Ai=!1,ga=!1;function _p(e){ln===null?ln=[e]:ln.push(e)}function tm(e){Ai=!0,_p(e)}function Bn(){if(!ga&&ln!==null){ga=!0;var e=0,t=he;try{var l=ln;for(he=1;e>=a,r-=a,sn=1<<32-Nt(t)+r|l<S?(_=R,R=null):_=R.sibling;var $=c(x,R,o[S],m);if($===null){R===null&&(R=_);break}e&&R&&$.alternate===null&&t(x,R),h=i($,h,S),P===null?C=$:P.sibling=$,P=$,R=_}if(S===o.length)return l(x,R),_e&&Un(x,S),C;if(R===null){for(;SS?(_=R,R=null):_=R.sibling;var T=c(x,R,$.value,m);if(T===null){R===null&&(R=_);break}e&&R&&T.alternate===null&&t(x,R),h=i(T,h,S),P===null?C=T:P.sibling=T,P=T,R=_}if($.done)return l(x,R),_e&&Un(x,S),C;if(R===null){for(;!$.done;S++,$=o.next())$=p(x,$.value,m),$!==null&&(h=i($,h,S),P===null?C=$:P.sibling=$,P=$);return _e&&Un(x,S),C}for(R=s(x,R);!$.done;S++,$=o.next())$=v(R,x,S,$.value,m),$!==null&&(e&&$.alternate!==null&&R.delete($.key===null?S:$.key),h=i($,h,S),P===null?C=$:P.sibling=$,P=$);return e&&R.forEach(function(I){return t(x,I)}),_e&&Un(x,S),C}function b(x,h,o,m){if(typeof o=="object"&&o!==null&&o.type===jl&&o.key===null&&(o=o.props.children),typeof o=="object"&&o!==null){switch(o.$$typeof){case vr:e:{for(var C=o.key,P=h;P!==null;){if(P.key===C){if(C=o.type,C===jl){if(P.tag===7){l(x,P.sibling),h=r(P,o.props.children),h.return=x,x=h;break e}}else if(P.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===vn&&Cd(C)===P.type){l(x,P.sibling),h=r(P,o.props),h.ref=ps(x,P,o),h.return=x,x=h;break e}l(x,P);break}else t(x,P);P=P.sibling}o.type===jl?(h=Gn(o.props.children,x.mode,m,o.key),h.return=x,x=h):(m=ei(o.type,o.key,o.props,null,x.mode,m),m.ref=ps(x,h,o),m.return=x,x=m)}return a(x);case vl:e:{for(P=o.key;h!==null;){if(h.key===P)if(h.tag===4&&h.stateNode.containerInfo===o.containerInfo&&h.stateNode.implementation===o.implementation){l(x,h.sibling),h=r(h,o.children||[]),h.return=x,x=h;break e}else{l(x,h);break}else t(x,h);h=h.sibling}h=wa(o,x.mode,m),h.return=x,x=h}return a(x);case vn:return P=o._init,b(x,h,P(o._payload),m)}if(Ts(o))return w(x,h,o,m);if(as(o))return g(x,h,o,m);Ir(x,o)}return typeof o=="string"&&o!==""||typeof o=="number"?(o=""+o,h!==null&&h.tag===6?(l(x,h.sibling),h=r(h,o),h.return=x,x=h):(l(x,h),h=Sa(o,x.mode,m),h.return=x,x=h),a(x)):l(x,h)}return b}var Ul=Pp(!0),Ip=Pp(!1),hi=Wn(null),gi=null,Tl=null,Xo=null;function Jo(){Xo=Tl=gi=null}function qo(e){var t=hi.current;Se(hi),e._currentValue=t}function io(e,t,l){for(;e!==null;){var s=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,s!==null&&(s.childLanes|=t)):s!==null&&(s.childLanes&t)!==t&&(s.childLanes|=t),e===l)break;e=e.return}}function Dl(e,t){gi=e,Xo=Tl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(dt=!0),e.firstContext=null)}function Tt(e){var t=e._currentValue;if(Xo!==e)if(e={context:e,memoizedValue:t,next:null},Tl===null){if(gi===null)throw Error(M(308));Tl=e,gi.dependencies={lanes:0,firstContext:e}}else Tl=Tl.next=e;return t}var Hn=null;function Zo(e){Hn===null?Hn=[e]:Hn.push(e)}function Ep(e,t,l,s){var r=t.interleaved;return r===null?(l.next=l,Zo(t)):(l.next=r.next,r.next=l),t.interleaved=l,dn(e,s)}function dn(e,t){e.lanes|=t;var l=e.alternate;for(l!==null&&(l.lanes|=t),l=e,e=e.return;e!==null;)e.childLanes|=t,l=e.alternate,l!==null&&(l.childLanes|=t),l=e,e=e.return;return l.tag===3?l.stateNode:null}var jn=!1;function Vo(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Ap(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function an(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function In(e,t,l){var s=e.updateQueue;if(s===null)return null;if(s=s.shared,pe&2){var r=s.pending;return r===null?t.next=t:(t.next=r.next,r.next=t),s.pending=t,dn(e,l)}return r=s.interleaved,r===null?(t.next=t,Zo(s)):(t.next=r.next,r.next=t),s.interleaved=t,dn(e,l)}function Yr(e,t,l){if(t=t.updateQueue,t!==null&&(t=t.shared,(l&4194240)!==0)){var s=t.lanes;s&=e.pendingLanes,l|=s,t.lanes=l,Wo(e,l)}}function zd(e,t){var l=e.updateQueue,s=e.alternate;if(s!==null&&(s=s.updateQueue,l===s)){var r=null,i=null;if(l=l.firstBaseUpdate,l!==null){do{var a={eventTime:l.eventTime,lane:l.lane,tag:l.tag,payload:l.payload,callback:l.callback,next:null};i===null?r=i=a:i=i.next=a,l=l.next}while(l!==null);i===null?r=i=t:i=i.next=t}else r=i=t;l={baseState:s.baseState,firstBaseUpdate:r,lastBaseUpdate:i,shared:s.shared,effects:s.effects},e.updateQueue=l;return}e=l.lastBaseUpdate,e===null?l.firstBaseUpdate=t:e.next=t,l.lastBaseUpdate=t}function xi(e,t,l,s){var r=e.updateQueue;jn=!1;var i=r.firstBaseUpdate,a=r.lastBaseUpdate,d=r.shared.pending;if(d!==null){r.shared.pending=null;var u=d,f=u.next;u.next=null,a===null?i=f:a.next=f,a=u;var y=e.alternate;y!==null&&(y=y.updateQueue,d=y.lastBaseUpdate,d!==a&&(d===null?y.firstBaseUpdate=f:d.next=f,y.lastBaseUpdate=u))}if(i!==null){var p=r.baseState;a=0,y=f=u=null,d=i;do{var c=d.lane,v=d.eventTime;if((s&c)===c){y!==null&&(y=y.next={eventTime:v,lane:0,tag:d.tag,payload:d.payload,callback:d.callback,next:null});e:{var w=e,g=d;switch(c=t,v=l,g.tag){case 1:if(w=g.payload,typeof w=="function"){p=w.call(v,p,c);break e}p=w;break e;case 3:w.flags=w.flags&-65537|128;case 0:if(w=g.payload,c=typeof w=="function"?w.call(v,p,c):w,c==null)break e;p=Pe({},p,c);break e;case 2:jn=!0}}d.callback!==null&&d.lane!==0&&(e.flags|=64,c=r.effects,c===null?r.effects=[d]:c.push(d))}else v={eventTime:v,lane:c,tag:d.tag,payload:d.payload,callback:d.callback,next:null},y===null?(f=y=v,u=p):y=y.next=v,a|=c;if(d=d.next,d===null){if(d=r.shared.pending,d===null)break;c=d,d=c.next,c.next=null,r.lastBaseUpdate=c,r.shared.pending=null}}while(!0);if(y===null&&(u=p),r.baseState=u,r.firstBaseUpdate=f,r.lastBaseUpdate=y,t=r.shared.interleaved,t!==null){r=t;do a|=r.lane,r=r.next;while(r!==t)}else i===null&&(r.shared.lanes=0);qn|=a,e.lanes=a,e.memoizedState=p}}function Td(e,t,l){if(e=t.effects,t.effects=null,e!==null)for(t=0;tl?l:4,e(!0);var s=ma.transition;ma.transition={};try{e(!1),t()}finally{he=l,ma.transition=s}}function Xp(){return Pt().memoizedState}function rm(e,t,l){var s=An(e);if(l={lane:s,action:l,hasEagerState:!1,eagerState:null,next:null},Jp(e))qp(t,l);else if(l=Ep(e,t,l,s),l!==null){var r=rt();Wt(l,e,s,r),Zp(l,t,s)}}function im(e,t,l){var s=An(e),r={lane:s,action:l,hasEagerState:!1,eagerState:null,next:null};if(Jp(e))qp(t,r);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var a=t.lastRenderedState,d=i(a,l);if(r.hasEagerState=!0,r.eagerState=d,Bt(d,a)){var u=t.interleaved;u===null?(r.next=r,Zo(t)):(r.next=u.next,u.next=r),t.interleaved=r;return}}catch{}finally{}l=Ep(e,t,r,s),l!==null&&(r=rt(),Wt(l,e,s,r),Zp(l,t,s))}}function Jp(e){var t=e.alternate;return e===Te||t!==null&&t===Te}function qp(e,t){Ns=yi=!0;var l=e.pending;l===null?t.next=t:(t.next=l.next,l.next=t),e.pending=t}function Zp(e,t,l){if(l&4194240){var s=t.lanes;s&=e.pendingLanes,l|=s,t.lanes=l,Wo(e,l)}}var vi={readContext:Tt,useCallback:et,useContext:et,useEffect:et,useImperativeHandle:et,useInsertionEffect:et,useLayoutEffect:et,useMemo:et,useReducer:et,useRef:et,useState:et,useDebugValue:et,useDeferredValue:et,useTransition:et,useMutableSource:et,useSyncExternalStore:et,useId:et,unstable_isNewReconciler:!1},am={readContext:Tt,useCallback:function(e,t){return Ht().memoizedState=[e,t===void 0?null:t],e},useContext:Tt,useEffect:Id,useImperativeHandle:function(e,t,l){return l=l!=null?l.concat([e]):null,Jr(4194308,4,Hp.bind(null,t,e),l)},useLayoutEffect:function(e,t){return Jr(4194308,4,e,t)},useInsertionEffect:function(e,t){return Jr(4,2,e,t)},useMemo:function(e,t){var l=Ht();return t=t===void 0?null:t,e=e(),l.memoizedState=[e,t],e},useReducer:function(e,t,l){var s=Ht();return t=l!==void 0?l(t):t,s.memoizedState=s.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},s.queue=e,e=e.dispatch=rm.bind(null,Te,e),[s.memoizedState,e]},useRef:function(e){var t=Ht();return e={current:e},t.memoizedState=e},useState:Pd,useDebugValue:ac,useDeferredValue:function(e){return Ht().memoizedState=e},useTransition:function(){var e=Pd(!1),t=e[0];return e=sm.bind(null,e[1]),Ht().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,l){var s=Te,r=Ht();if(_e){if(l===void 0)throw Error(M(407));l=l()}else{if(l=t(),Xe===null)throw Error(M(349));Jn&30||Dp(s,t,l)}r.memoizedState=l;var i={value:l,getSnapshot:t};return r.queue=i,Id(Wp.bind(null,s,i,e),[e]),s.flags|=2048,nr(9,Np.bind(null,s,i,l,t),void 0,null),l},useId:function(){var e=Ht(),t=Xe.identifierPrefix;if(_e){var l=rn,s=sn;l=(s&~(1<<32-Nt(s)-1)).toString(32)+l,t=":"+t+"R"+l,l=er++,0<\/script>",e=e.removeChild(e.firstChild)):typeof s.is=="string"?e=a.createElement(l,{is:s.is}):(e=a.createElement(l),l==="select"&&(a=e,s.multiple?a.multiple=!0:s.size&&(a.size=s.size))):e=a.createElementNS(e,l),e[Kt]=t,e[qs]=s,cf(e,t,!1,!1),t.stateNode=e;e:{switch(a=Fa(l,s),l){case"dialog":be("cancel",e),be("close",e),r=s;break;case"iframe":case"object":case"embed":be("load",e),r=s;break;case"video":case"audio":for(r=0;rHl&&(t.flags|=128,s=!0,fs(i,!1),t.lanes=4194304)}else{if(!s)if(e=mi(a),e!==null){if(t.flags|=128,s=!0,l=e.updateQueue,l!==null&&(t.updateQueue=l,t.flags|=4),fs(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!_e)return tt(t),null}else 2*Le()-i.renderingStartTime>Hl&&l!==1073741824&&(t.flags|=128,s=!0,fs(i,!1),t.lanes=4194304);i.isBackwards?(a.sibling=t.child,t.child=a):(l=i.last,l!==null?l.sibling=a:t.child=a,i.last=a)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=Le(),t.sibling=null,l=ze.current,ve(ze,s?l&1|2:l&1),t):(tt(t),null);case 22:case 23:return fc(),s=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==s&&(t.flags|=8192),s&&t.mode&1?mt&1073741824&&(tt(t),t.subtreeFlags&6&&(t.flags|=8192)):tt(t),null;case 24:return null;case 25:return null}throw Error(M(156,t.tag))}function gm(e,t){switch(Go(t),t.tag){case 1:return pt(t.type)&&di(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Fl(),Se(ut),Se(lt),nc(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return tc(t),null;case 13:if(Se(ze),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(M(340));$l()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Se(ze),null;case 4:return Fl(),null;case 10:return qo(t.type._context),null;case 22:case 23:return fc(),null;case 24:return null;default:return null}}var Ar=!1,nt=!1,xm=typeof WeakSet=="function"?WeakSet:Set,Y=null;function Pl(e,t){var l=e.ref;if(l!==null)if(typeof l=="function")try{l(null)}catch(s){Ie(e,t,s)}else l.current=null}function xo(e,t,l){try{l()}catch(s){Ie(e,t,s)}}var Ud=!1;function mm(e,t){if(Za=ii,e=gp(),Ko(e)){if("selectionStart"in e)var l={start:e.selectionStart,end:e.selectionEnd};else e:{l=(l=e.ownerDocument)&&l.defaultView||window;var s=l.getSelection&&l.getSelection();if(s&&s.rangeCount!==0){l=s.anchorNode;var r=s.anchorOffset,i=s.focusNode;s=s.focusOffset;try{l.nodeType,i.nodeType}catch{l=null;break e}var a=0,d=-1,u=-1,f=0,y=0,p=e,c=null;t:for(;;){for(var v;p!==l||r!==0&&p.nodeType!==3||(d=a+r),p!==i||s!==0&&p.nodeType!==3||(u=a+s),p.nodeType===3&&(a+=p.nodeValue.length),(v=p.firstChild)!==null;)c=p,p=v;for(;;){if(p===e)break t;if(c===l&&++f===r&&(d=a),c===i&&++y===s&&(u=a),(v=p.nextSibling)!==null)break;p=c,c=p.parentNode}p=v}l=d===-1||u===-1?null:{start:d,end:u}}else l=null}l=l||{start:0,end:0}}else l=null;for(Va={focusedElem:e,selectionRange:l},ii=!1,Y=t;Y!==null;)if(t=Y,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Y=e;else for(;Y!==null;){t=Y;try{var w=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(w!==null){var g=w.memoizedProps,b=w.memoizedState,x=t.stateNode,h=x.getSnapshotBeforeUpdate(t.elementType===t.type?g:Rt(t.type,g),b);x.__reactInternalSnapshotBeforeUpdate=h}break;case 3:var o=t.stateNode.containerInfo;o.nodeType===1?o.textContent="":o.nodeType===9&&o.documentElement&&o.removeChild(o.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(M(163))}}catch(m){Ie(t,t.return,m)}if(e=t.sibling,e!==null){e.return=t.return,Y=e;break}Y=t.return}return w=Ud,Ud=!1,w}function Ws(e,t,l){var s=t.updateQueue;if(s=s!==null?s.lastEffect:null,s!==null){var r=s=s.next;do{if((r.tag&e)===e){var i=r.destroy;r.destroy=void 0,i!==void 0&&xo(t,l,i)}r=r.next}while(r!==s)}}function Oi(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var l=t=t.next;do{if((l.tag&e)===e){var s=l.create;l.destroy=s()}l=l.next}while(l!==t)}}function mo(e){var t=e.ref;if(t!==null){var l=e.stateNode;switch(e.tag){case 5:e=l;break;default:e=l}typeof t=="function"?t(e):t.current=e}}function pf(e){var t=e.alternate;t!==null&&(e.alternate=null,pf(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Kt],delete t[qs],delete t[no],delete t[Vx],delete t[em])),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 ff(e){return e.tag===5||e.tag===3||e.tag===4}function Fd(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||ff(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 yo(e,t,l){var s=e.tag;if(s===5||s===6)e=e.stateNode,t?l.nodeType===8?l.parentNode.insertBefore(e,t):l.insertBefore(e,t):(l.nodeType===8?(t=l.parentNode,t.insertBefore(e,l)):(t=l,t.appendChild(e)),l=l._reactRootContainer,l!=null||t.onclick!==null||(t.onclick=ci));else if(s!==4&&(e=e.child,e!==null))for(yo(e,t,l),e=e.sibling;e!==null;)yo(e,t,l),e=e.sibling}function vo(e,t,l){var s=e.tag;if(s===5||s===6)e=e.stateNode,t?l.insertBefore(e,t):l.appendChild(e);else if(s!==4&&(e=e.child,e!==null))for(vo(e,t,l),e=e.sibling;e!==null;)vo(e,t,l),e=e.sibling}var qe=null,Lt=!1;function mn(e,t,l){for(l=l.child;l!==null;)hf(e,t,l),l=l.sibling}function hf(e,t,l){if(Qt&&typeof Qt.onCommitFiberUnmount=="function")try{Qt.onCommitFiberUnmount(zi,l)}catch{}switch(l.tag){case 5:nt||Pl(l,t);case 6:var s=qe,r=Lt;qe=null,mn(e,t,l),qe=s,Lt=r,qe!==null&&(Lt?(e=qe,l=l.stateNode,e.nodeType===8?e.parentNode.removeChild(l):e.removeChild(l)):qe.removeChild(l.stateNode));break;case 18:qe!==null&&(Lt?(e=qe,l=l.stateNode,e.nodeType===8?ha(e.parentNode,l):e.nodeType===1&&ha(e,l),Qs(e)):ha(qe,l.stateNode));break;case 4:s=qe,r=Lt,qe=l.stateNode.containerInfo,Lt=!0,mn(e,t,l),qe=s,Lt=r;break;case 0:case 11:case 14:case 15:if(!nt&&(s=l.updateQueue,s!==null&&(s=s.lastEffect,s!==null))){r=s=s.next;do{var i=r,a=i.destroy;i=i.tag,a!==void 0&&(i&2||i&4)&&xo(l,t,a),r=r.next}while(r!==s)}mn(e,t,l);break;case 1:if(!nt&&(Pl(l,t),s=l.stateNode,typeof s.componentWillUnmount=="function"))try{s.props=l.memoizedProps,s.state=l.memoizedState,s.componentWillUnmount()}catch(d){Ie(l,t,d)}mn(e,t,l);break;case 21:mn(e,t,l);break;case 22:l.mode&1?(nt=(s=nt)||l.memoizedState!==null,mn(e,t,l),nt=s):mn(e,t,l);break;default:mn(e,t,l)}}function Md(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var l=e.stateNode;l===null&&(l=e.stateNode=new xm),t.forEach(function(s){var r=Cm.bind(null,e,s);l.has(s)||(l.add(s),s.then(r,r))})}}function At(e,t){var l=t.deletions;if(l!==null)for(var s=0;sr&&(r=a),s&=~i}if(s=r,s=Le()-s,s=(120>s?120:480>s?480:1080>s?1080:1920>s?1920:3e3>s?3e3:4320>s?4320:1960*vm(s/1960))-s,10e?16:e,kn===null)var s=!1;else{if(e=kn,kn=null,Si=0,pe&6)throw Error(M(331));var r=pe;for(pe|=4,Y=e.current;Y!==null;){var i=Y,a=i.child;if(Y.flags&16){var d=i.deletions;if(d!==null){for(var u=0;uLe()-uc?Qn(e,0):dc|=l),ft(e,t)}function Sf(e,t){t===0&&(e.mode&1?(t=wr,wr<<=1,!(wr&130023424)&&(wr=4194304)):t=1);var l=rt();e=dn(e,t),e!==null&&(rr(e,t,l),ft(e,l))}function _m(e){var t=e.memoizedState,l=0;t!==null&&(l=t.retryLane),Sf(e,l)}function Cm(e,t){var l=0;switch(e.tag){case 13:var s=e.stateNode,r=e.memoizedState;r!==null&&(l=r.retryLane);break;case 19:s=e.stateNode;break;default:throw Error(M(314))}s!==null&&s.delete(t),Sf(e,l)}var wf;wf=function(e,t,l){if(e!==null)if(e.memoizedProps!==t.pendingProps||ut.current)dt=!0;else{if(!(e.lanes&l)&&!(t.flags&128))return dt=!1,fm(e,t,l);dt=!!(e.flags&131072)}else dt=!1,_e&&t.flags&1048576&&Cp(t,fi,t.index);switch(t.lanes=0,t.tag){case 2:var s=t.type;qr(e,t),e=t.pendingProps;var r=Bl(t,lt.current);Dl(t,l),r=sc(null,t,s,e,r,l);var i=rc();return t.flags|=1,typeof r=="object"&&r!==null&&typeof r.render=="function"&&r.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,pt(s)?(i=!0,ui(t)):i=!1,t.memoizedState=r.state!==null&&r.state!==void 0?r.state:null,Vo(t),r.updater=Li,t.stateNode=r,r._reactInternals=t,oo(t,s,e,l),t=po(null,t,s,!0,i,l)):(t.tag=0,_e&&i&&Qo(t),st(null,t,r,l),t=t.child),t;case 16:s=t.elementType;e:{switch(qr(e,t),e=t.pendingProps,r=s._init,s=r(s._payload),t.type=s,r=t.tag=Tm(s),e=Rt(s,e),r){case 0:t=uo(null,t,s,e,l);break e;case 1:t=Wd(null,t,s,e,l);break e;case 11:t=Dd(null,t,s,e,l);break e;case 14:t=Nd(null,t,s,Rt(s.type,e),l);break e}throw Error(M(306,s,""))}return t;case 0:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Rt(s,r),uo(e,t,s,r,l);case 1:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Rt(s,r),Wd(e,t,s,r,l);case 3:e:{if(rf(t),e===null)throw Error(M(387));s=t.pendingProps,i=t.memoizedState,r=i.element,Ap(e,t),xi(t,s,null,l);var a=t.memoizedState;if(s=a.element,i.isDehydrated)if(i={element:s,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){r=Ml(Error(M(423)),t),t=Bd(e,t,s,l,r);break e}else if(s!==r){r=Ml(Error(M(424)),t),t=Bd(e,t,s,l,r);break e}else for(yt=Pn(t.stateNode.containerInfo.firstChild),vt=t,_e=!0,Ot=null,l=Ip(t,null,s,l),t.child=l;l;)l.flags=l.flags&-3|4096,l=l.sibling;else{if($l(),s===r){t=un(e,t,l);break e}st(e,t,s,l)}t=t.child}return t;case 5:return Rp(t),e===null&&ro(t),s=t.type,r=t.pendingProps,i=e!==null?e.memoizedProps:null,a=r.children,eo(s,r)?a=null:i!==null&&eo(s,i)&&(t.flags|=32),sf(e,t),st(e,t,a,l),t.child;case 6:return e===null&&ro(t),null;case 13:return af(e,t,l);case 4:return ec(t,t.stateNode.containerInfo),s=t.pendingProps,e===null?t.child=Ul(t,null,s,l):st(e,t,s,l),t.child;case 11:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Rt(s,r),Dd(e,t,s,r,l);case 7:return st(e,t,t.pendingProps,l),t.child;case 8:return st(e,t,t.pendingProps.children,l),t.child;case 12:return st(e,t,t.pendingProps.children,l),t.child;case 10:e:{if(s=t.type._context,r=t.pendingProps,i=t.memoizedProps,a=r.value,ve(hi,s._currentValue),s._currentValue=a,i!==null)if(Bt(i.value,a)){if(i.children===r.children&&!ut.current){t=un(e,t,l);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var d=i.dependencies;if(d!==null){a=i.child;for(var u=d.firstContext;u!==null;){if(u.context===s){if(i.tag===1){u=an(-1,l&-l),u.tag=2;var f=i.updateQueue;if(f!==null){f=f.shared;var y=f.pending;y===null?u.next=u:(u.next=y.next,y.next=u),f.pending=u}}i.lanes|=l,u=i.alternate,u!==null&&(u.lanes|=l),io(i.return,l,t),d.lanes|=l;break}u=u.next}}else if(i.tag===10)a=i.type===t.type?null:i.child;else if(i.tag===18){if(a=i.return,a===null)throw Error(M(341));a.lanes|=l,d=a.alternate,d!==null&&(d.lanes|=l),io(a,l,t),a=i.sibling}else a=i.child;if(a!==null)a.return=i;else for(a=i;a!==null;){if(a===t){a=null;break}if(i=a.sibling,i!==null){i.return=a.return,a=i;break}a=a.return}i=a}st(e,t,r.children,l),t=t.child}return t;case 9:return r=t.type,s=t.pendingProps.children,Dl(t,l),r=Tt(r),s=s(r),t.flags|=1,st(e,t,s,l),t.child;case 14:return s=t.type,r=Rt(s,t.pendingProps),r=Rt(s.type,r),Nd(e,t,s,r,l);case 15:return nf(e,t,t.type,t.pendingProps,l);case 17:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Rt(s,r),qr(e,t),t.tag=1,pt(s)?(e=!0,ui(t)):e=!1,Dl(t,l),Vp(t,s,r),oo(t,s,r,l),po(null,t,s,!0,e,l);case 19:return of(e,t,l);case 22:return lf(e,t,l)}throw Error(M(156,t.tag))};function kf(e,t){return Ju(e,t)}function zm(e,t,l,s){this.tag=e,this.key=l,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=s,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ct(e,t,l,s){return new zm(e,t,l,s)}function gc(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Tm(e){if(typeof e=="function")return gc(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Lo)return 11;if(e===Oo)return 14}return 2}function Rn(e,t){var l=e.alternate;return l===null?(l=Ct(e.tag,t,e.key,e.mode),l.elementType=e.elementType,l.type=e.type,l.stateNode=e.stateNode,l.alternate=e,e.alternate=l):(l.pendingProps=t,l.type=e.type,l.flags=0,l.subtreeFlags=0,l.deletions=null),l.flags=e.flags&14680064,l.childLanes=e.childLanes,l.lanes=e.lanes,l.child=e.child,l.memoizedProps=e.memoizedProps,l.memoizedState=e.memoizedState,l.updateQueue=e.updateQueue,t=e.dependencies,l.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},l.sibling=e.sibling,l.index=e.index,l.ref=e.ref,l}function ei(e,t,l,s,r,i){var a=2;if(s=e,typeof e=="function")gc(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case jl:return Gn(l.children,r,i,t);case Ro:a=8,r|=8;break;case Aa:return e=Ct(12,l,t,r|2),e.elementType=Aa,e.lanes=i,e;case Ra:return e=Ct(13,l,t,r),e.elementType=Ra,e.lanes=i,e;case La:return e=Ct(19,l,t,r),e.elementType=La,e.lanes=i,e;case Ru:return Ni(l,r,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Eu:a=10;break e;case Au:a=9;break e;case Lo:a=11;break e;case Oo:a=14;break e;case vn:a=16,s=null;break e}throw Error(M(130,e==null?e:typeof e,""))}return t=Ct(a,l,t,r),t.elementType=e,t.type=s,t.lanes=i,t}function Gn(e,t,l,s){return e=Ct(7,e,s,t),e.lanes=l,e}function Ni(e,t,l,s){return e=Ct(22,e,s,t),e.elementType=Ru,e.lanes=l,e.stateNode={isHidden:!1},e}function Sa(e,t,l){return e=Ct(6,e,null,t),e.lanes=l,e}function wa(e,t,l){return t=Ct(4,e.children!==null?e.children:[],e.key,t),t.lanes=l,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Pm(e,t,l,s,r){this.tag=t,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=la(0),this.expirationTimes=la(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=la(0),this.identifierPrefix=s,this.onRecoverableError=r,this.mutableSourceEagerHydrationData=null}function xc(e,t,l,s,r,i,a,d,u){return e=new Pm(e,t,l,d,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=Ct(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:s,isDehydrated:l,cache:null,transitions:null,pendingSuspenseBoundaries:null},Vo(i),e}function Im(e,t,l){var s=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Tf)}catch(e){console.error(e)}}Tf(),zu.exports=bt;var Om=zu.exports,Pf,qd=Om;Pf=qd.createRoot,qd.hydrateRoot;const ce="",B={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"},U={bg:"#f5f6fa",accent:"#4f46e5",red:"#ef4444",orange:"#f59e0b",green:"#16a34a",purple:"#7c3aed",blue:"#2563eb",teal:"#0d9488",gray:"#94a3b8"},Dm=[{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"}],Nm=[{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"}],Wm=new Set(["users"]);function Bm(e){return e!=="Admin"&&e!=="Auditor"?[]:Nm.filter(({id:t})=>e==="Admin"||!Wm.has(t))}const yn=(e=[])=>[{key:"name1",label:"Name"},{key:"status",label:"Status"},...e,{key:"creation_date",label:"Created On"}],$m={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:yn(),defaultColumns:["name1","status","creation_date"]},"idea-types":{label:"Idea Types",columns:yn(),defaultColumns:["name1","status","creation_date"]},"order-types":{label:"Order Types",columns:yn(),defaultColumns:["name1","status","creation_date"]},"process-types":{label:"Process Types",columns:yn(),defaultColumns:["name1","status","creation_date"]},"incident-statuses":{label:"Incident Statuses",columns:yn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"idea-statuses":{label:"Idea Statuses",columns:yn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"order-statuses":{label:"Order Statuses",columns:yn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"process-statuses":{label:"Process Statuses",columns:yn([{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:"Auditor"},{key:"manager",label:"Manager"},{key:"organization",label:"Organization"},{key:"create_processes",label:"Create Processes"},{key:"update_process_status",label:"Update Process Status"},{key:"status",label:"Status"},{key:"requested_on",label:"Requested On"},{key:"responded_on",label:"Responded On"}],defaultColumns:["number","auditor","manager","organization","status","requested_on"]}},Um="modulepreload",Fm=function(e){return"/"+e},Zd={},Mm=function(t,l,s){let r=Promise.resolve();if(l&&l.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),d=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));r=Promise.allSettled(l.map(u=>{if(u=Fm(u),u in Zd)return;Zd[u]=!0;const f=u.endsWith(".css"),y=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${y}`))return;const p=document.createElement("link");if(p.rel=f?"stylesheet":Um,f||(p.as="script"),p.crossOrigin="",p.href=u,d&&p.setAttribute("nonce",d),document.head.appendChild(p),f)return new Promise((c,v)=>{p.addEventListener("load",c),p.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(a){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=a,window.dispatchEvent(d),!d.defaultPrevented)throw a}return r.then(a=>{for(const d of a||[])d.status==="rejected"&&i(d.reason);return t().catch(i)})};function If(e,t){const l=e[t.key];return l==null||l===""?"":typeof l=="object"?JSON.stringify(l):String(l)}function Hm(e,t){const l=URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download=t,s.click(),URL.revokeObjectURL(l)}function Km(e,t,l){const s=e.map(a=>`"${a.label.replace(/"/g,'""')}"`).join(","),r=t.map(a=>e.map(d=>`"${If(a,d).replace(/"/g,'""')}"`).join(",")).join(` `),i=new Blob([s+` `+r],{type:"text/csv;charset=utf-8;"});Hm(i,`${l}.csv`)}async function Qm(e,t,l){const s=await Mm(()=>import("./xlsx-D_0l8YDs.js"),[]),r=t.map(d=>{const u={};for(const f of e)u[f.label]=If(d,f);return u}),i=s.utils.json_to_sheet(r,{header:e.map(d=>d.label)}),a=s.utils.book_new();s.utils.book_append_sheet(a,i,"Export"),s.writeFile(a,`${l}.xlsx`)}const Or="#16a34a";function Gm({title:e,rows:t,columns:l,defaultColumnKeys:s,orgField:r,organizations:i,filenameBase:a,onClose:d}){const[u,f]=j.useState(""),[y,p]=j.useState("csv"),[c,v]=j.useState(new Set(s)),w=u?t.filter(m=>m[r||"organization"]===u):t,g=l.filter(m=>c.has(m.key)),b=m=>{v(C=>{const P=new Set(C);return P.has(m)?P.delete(m):P.add(m),P})},x=async()=>{g.length===0||w.length===0||(y==="csv"?Km(g,w,a):await Qm(g,w,a),d())},h={fontSize:11,fontWeight:700,color:"#9ca3af",letterSpacing:.4,textTransform:"uppercase",marginBottom:10},o={background:"none",border:"none",color:"#2563eb",fontSize:12,fontWeight:600,cursor:"pointer",padding:0,fontFamily:"inherit"};return n.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:n.jsxs("div",{onClick:m=>m.stopPropagation(),style:{width:560,maxWidth:"92vw",maxHeight:"86vh",background:"white",borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[n.jsxs("div",{style:{background:Or,color:"white",padding:"16px 22px",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,fontSize:16,fontWeight:700},children:[n.jsx("span",{style:{fontSize:18},children:"📤"})," Export ",e]}),n.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:"✕"})]}),n.jsxs("div",{style:{padding:"20px 22px",overflowY:"auto",flex:1},children:[r&&i&&i.length>0&&n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:h,children:"Filter by Organization"}),n.jsxs("select",{value:u,onChange:m=>f(m.target.value),style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",boxSizing:"border-box"},children:[n.jsxs("option",{value:"",children:["All Organizations (",t.length," total)"]}),i.map(m=>n.jsx("option",{value:m.name,children:m.organization_name||m.name},m.name))]})]}),n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:h,children:"File Format"}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[{id:"csv",label:"CSV",desc:"Comma-separated values"},{id:"xlsx",label:"Excel",desc:"XLSX spreadsheet"}].map(m=>n.jsxs("div",{onClick:()=>p(m.id),style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",borderRadius:10,cursor:"pointer",border:`2px solid ${y===m.id?Or:"#e5e7eb"}`,background:y===m.id?"#f0fdf4":"white"},children:[n.jsx("span",{style:{fontSize:20},children:m.id==="csv"?"📄":"📊"}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:m.label}),n.jsx("div",{style:{fontSize:11,color:"#888"},children:m.desc})]})]},m.id))})]}),n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[n.jsx("div",{style:{...h,marginBottom:0},children:"Columns to Export"}),n.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[n.jsx("button",{onClick:()=>v(new Set(l.map(m=>m.key))),style:o,children:"Select All"}),n.jsx("span",{style:{color:"#d1d5db"},children:"|"}),n.jsx("button",{onClick:()=>v(new Set(s)),style:o,children:"Reset to Default"})]})]}),n.jsx("div",{style:{border:"1px solid #e5e7eb",borderRadius:8,padding:12,maxHeight:170,overflowY:"auto"},children:n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:"10px 12px"},children:l.map(m=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:7,fontSize:13,color:"#374151",cursor:"pointer"},children:[n.jsx("input",{type:"checkbox",checked:c.has(m.key),onChange:()=>b(m.key),style:{accentColor:Or,cursor:"pointer"}}),m.label]},m.key))})}),n.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:6},children:[c.size," column",c.size!==1?"s":""," selected"]})]})]}),n.jsxs("div",{style:{padding:"14px 22px",borderTop:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[n.jsx("span",{style:{fontSize:12,color:"#888"},children:u?`Exporting ${w.length} filtered row${w.length!==1?"s":""}`:`Exporting all ${w.length} row${w.length!==1?"s":""}`}),n.jsxs("div",{style:{display:"flex",gap:10},children:[n.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"}),n.jsx("button",{onClick:x,disabled:g.length===0||w.length===0,style:{padding:"9px 20px",borderRadius:8,border:"none",background:Or,color:"white",fontWeight:700,fontSize:13,cursor:g.length===0||w.length===0?"not-allowed":"pointer",opacity:g.length===0||w.length===0?.5:1,fontFamily:"inherit",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"})]})]})]})})}function Ef({collapsed:e,onToggleCollapsed:t,activePage:l,onNavigate:s,hasDashboard:r,hasReports:i,hasDelegations:a,role:d,hideSettings:u,rtl:f,navLabels:y,settingsLabel:p}){const c=u?[]:Bm(d);return n.jsxs("div",{style:{width:e?58:230,background:"linear-gradient(175deg, #1a0f42 0%, #2a1260 45%, #102840 100%)",color:"white",flexShrink:0,display:"flex",flexDirection:"column",position:"sticky",top:0,height:"100vh",transition:"width 0.22s ease",overflow:"hidden"},children:[n.jsxs("div",{style:{padding:e?"16px 0":"16px 20px 14px",borderBottom:"1px solid rgba(255,255,255,0.08)",display:"flex",alignItems:"center",justifyContent:e?"center":"space-between",gap:8,flexShrink:0},children:[!e&&n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,overflow:"hidden"},children:[n.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"linear-gradient(135deg, #312e81 0%, #4f46e5 100%)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:n.jsx("span",{style:{fontSize:16,color:"white",fontWeight:800,fontFamily:"serif"},children:"S"})}),n.jsx("span",{style:{fontSize:16,fontWeight:700,whiteSpace:"nowrap",color:"white"},children:f?"صدرة":"Sidrah"})]}),n.jsx("button",{onClick:t,title:e?f?"توسيع":"Expand":f?"طي":"Collapse",style:{background:"rgba(255,255,255,0.08)",border:"none",borderRadius:7,color:"rgba(255,255,255,0.7)",cursor:"pointer",fontSize:12,padding:"5px 8px",flexShrink:0,lineHeight:1,transition:"background 0.15s"},children:e?"▶":"✕"})]}),n.jsxs("nav",{style:{padding:"12px 8px",flex:1,overflowY:"auto",overflowX:"hidden"},children:[Dm.filter(({id:v})=>(v!=="dashboard"||r)&&(v!=="reports"||i)&&(v!=="delegations"||a)).map(({id:v,icon:w})=>{const g=y[v]||v,b=v===l;return n.jsxs("div",{onClick:()=>s(v),title:e?g:void 0,style:{padding:e?"8px 0":"8px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:9,background:b?"rgba(139,92,246,0.28)":"transparent",borderRadius:8,fontSize:e?15:12,color:"white",fontWeight:b?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{flexShrink:0},children:w}),!e&&g]},v)}),c.length>0&&n.jsxs(n.Fragment,{children:[!e&&n.jsx("div",{style:{padding:"10px 14px 4px",fontSize:10,color:"rgba(255,255,255,0.6)",fontWeight:700,letterSpacing:1,textTransform:"uppercase",marginTop:8},children:p}),e&&n.jsx("div",{style:{margin:"10px auto",width:28,borderTop:"1px solid rgba(255,255,255,0.12)"}}),c.map(({id:v,icon:w})=>{const g=y[v]||v,b=v===l;return n.jsxs("div",{onClick:()=>s(v),title:e?g:void 0,style:{padding:e?"8px 0":"8px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:9,background:b?"rgba(139,92,246,0.25)":"transparent",borderRadius:8,fontSize:e?15:12,color:"white",fontWeight:b?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{flexShrink:0},children:w}),!e&&g]},v)})]})]})]})}const Af="sidrah_rtl",ko="sidrah-lang-change";function El(){try{return localStorage.getItem(Af)==="1"}catch{return!1}}function Rf(){const e=!El();try{localStorage.setItem(Af,e?"1":"0")}catch{}document.documentElement.setAttribute("dir",e?"rtl":"ltr"),document.documentElement.setAttribute("lang",e?"ar":"en-GB"),window.dispatchEvent(new CustomEvent(ko))}function Z(){const[e,t]=j.useState(El);return j.useEffect(()=>{const l=()=>t(El());return window.addEventListener(ko,l),document.documentElement.setAttribute("dir",El()?"rtl":"ltr"),document.documentElement.setAttribute("lang",El()?"ar":"en-GB"),()=>window.removeEventListener(ko,l)},[]),e?Xm:Ym}const Ym={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",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 --",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",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"}},Xm={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:"حذف",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:"-- اختر --",selectType:"-- اختر النوع --",selectClass:"-- اختر التصنيف --",selectField:"-- اختر المجال --",selectStatus:"-- اختر الحالة --",solutionPlaceholder:"صف الحل أو الإجراء المتخذ…",commentPlaceholder:"تعليق اختياري…",high:"عالي",normal:"عادي",expenses:"مصروفات",capital:"رأس مال",earn:"إيرادات",payLoss:"دفع/خسارة",upstream:"مرحلة المنبع",onstream:"على الخط",downstream:"مرحلة المصب",government:"حكومي",private:"خاص",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:"بواسطة"}},cr=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"]);let Vn="";async function jc(){try{const e=await fetch(`${ce}/api/method/sidrah_business.api.get_csrf_token`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(e.ok){const l=(await e.json()).message||"";if(l)return Vn=l,l}}catch(e){console.error("CSRF fetch error:",e)}return Vn}async function fn(){return Vn||await jc(),Vn}function Vd(e,t){try{if(e!=null&&e._server_messages){const l=JSON.parse(e._server_messages);if(l.length){const s=JSON.parse(l[0]);if(s!=null&&s.message)return s.message.replace(/<[^>]+>/g,"")}}}catch{}return(e==null?void 0:e.message)||(e==null?void 0:e.exception)||t}async function xt(e,t,l=[]){if(cr.has(e)){const a=`${ce}/api/method/sidrah_business.api.get_sb_doc?doctype=${encodeURIComponent(e)}&name=${encodeURIComponent(t)}`,d=await fetch(a,{credentials:"include",headers:{Accept:"application/json"}});if(!d.ok)throw new Error(`API Error: ${d.status}`);return(await d.json()).message}const s=l.length?`?fields=${encodeURIComponent(JSON.stringify(l))}`:"",r=await fetch(`${ce}/api/v1/resource/${e}/${encodeURIComponent(t)}${s}`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(!r.ok)throw new Error(`API Error: ${r.status}`);return(await r.json()).data}async function Lf(e,t){const l=await fn();if(cr.has(e)){const r=new URLSearchParams({doctype:e,name:t}),i=await fetch(`${ce}/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":l},body:r.toString()});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(Vd(a,`Error deleting ${t}`))}return}const s=await fetch(`${ce}/api/v1/resource/${e}/${encodeURIComponent(t)}`,{method:"DELETE",credentials:"include",headers:{Accept:"application/json","X-Frappe-CSRF-Token":l}});if(!s.ok){const r=await s.json().catch(()=>({}));throw new Error(Vd(r,`Error deleting ${t}`))}return await s.json()}async function ke(e){if(cr.has(e))try{const s=`${ce}/api/method/sidrah_business.api.get_sb_list?doctype=${encodeURIComponent(e)}&limit=500`,r=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return r.ok?(await r.json()).message||[]:[]}catch{return[]}const t=encodeURIComponent('["*"]'),l=`${ce}/api/v1/resource/${e}?limit_page_length=500&fields=${t}`;try{const s=await fetch(l,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return s.status===401||s.status===403?[]:s.ok?(await s.json()).data||[]:[]}catch(s){return console.error("Get error:",s),[]}}async function ka(e,t){const l=await fn();if(cr.has(e)){const r=new URLSearchParams({doctype:e,data_json:JSON.stringify(t)}),i=await fetch(`${ce}/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":l},body:r.toString()});if(!i.ok){const d=await i.json().catch(()=>({}));throw new Error(d.message||d.exc||`Error creating ${e}`)}return{data:(await i.json()).message}}const s=`${ce}/api/v1/resource/${e}`;try{const r=await fetch(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":l},body:JSON.stringify(t)});if(r.status===401||r.status===403)throw new Error("Permission denied - login required");if(!r.ok){const i=await r.json();throw new Error(i.message||i.exc||`API Error: ${r.status}`)}return await r.json()}catch(r){throw console.error("Post error:",r),r}}async function _i(e,t,l){const s=await fn();if(cr.has(e)){const i=new URLSearchParams({doctype:e,name:t,data_json:JSON.stringify(l)}),a=await fetch(`${ce}/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":s},body:i.toString()});if(!a.ok){const u=await a.json().catch(()=>({}));throw new Error(u.message||u.exc||`Error updating ${e}`)}return{data:(await a.json()).message}}const r=`${ce}/api/v1/resource/${e}/${encodeURIComponent(t)}`;try{const i=await fetch(r,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":s},body:JSON.stringify(l)});if(i.status===401||i.status===403)throw new Error("Permission denied - login required");if(!i.ok){const a=await i.json();throw new Error(a.message||"Update Error")}return await i.json()}catch(i){throw console.error("Update error:",i),i}}async function Jm(){const e=`${ce}/api/v1/resource/User?limit_page_length=500&fields=["name","full_name"]`;try{const t=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return t.status===401||t.status===403?[]:t.ok?(await t.json()).data||[]:[]}catch(t){return console.error("Get users error:",t),[]}}async function qm(e,t){const l=new FormData;l.append("usr",e),l.append("pwd",t);const r=await(await fetch(`${ce}/api/method/login`,{method:"POST",credentials:"include",body:l})).json();return r.csrf_token?Vn=r.csrf_token:await jc(),r}async function Zm(){const e=await fn();try{await fetch(`${ce}/api/method/logout`,{method:"POST",credentials:"include",headers:{"X-Frappe-CSRF-Token":e,Accept:"application/json"}})}catch{}Vn=""}function Vm(){return Vn}async function Of(){try{const e=await fetch(`${ce}/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 ey(){const e=JSON.stringify([["name","not in",["Administrator","Guest"]]]),t=`${ce}/api/v1/resource/User?limit_page_length=500&fields=${encodeURIComponent('["*"]')}&filters=${encodeURIComponent(e)}`;try{const l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).data||[]:[]}catch{return[]}}async function ty(){const e=`${ce}/api/method/sidrah_business.api.get_user_role_map`;try{const t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||{}:{}}catch{return{}}}async function Df(e,t){await _i("User",e,{new_password:t})}async function ny(e=20){try{const t=`${ce}/api/method/sidrah_business.api.get_notifications?limit=${e}`,l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function ly(){const e=await fn();try{await fetch(`${ce}/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 sy(e){const t=await fn();try{await fetch(`${ce}/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":t},body:new URLSearchParams({name:e}).toString()})}catch{}}async function ry(e){const t=await fn(),l=new URLSearchParams({name:e});await fetch(`${ce}/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":t},body:l.toString()})}async function iy(e,t){try{const l=`${ce}/api/method/sidrah_business.api.get_doc_comments?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(t)}`,s=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function ay(e,t,l){const s=await fn(),r=new URLSearchParams({doctype:e,docname:t,content:l}),i=await fetch(`${ce}/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":s},body:r.toString()});if(!i.ok)throw new Error("Failed to post comment");return(await i.json()).message}async function oy(e,t){try{const l=`${ce}/api/method/sidrah_business.api.get_doc_versions?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(t)}`,s=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function Nf(e){try{const t=`${ce}/api/method/sidrah_business.api.get_user_roles?user=${encodeURIComponent(e)}`,l=await fetch(t,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function nl(e,t={}){const l=await fn(),s=new URLSearchParams(t),r=await fetch(`${ce}/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":l},body:s.toString()});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.message||a.exc||`Error calling ${e}`)}return(await r.json()).message}async function cy(e,t,l="",s,r,i){const a={name:e,action:t,comment:l};return s!==void 0&&(a.stage=s),i!==void 0&&(a.cycle_status=i),nl("apply_order_workflow",a)}async function dy(e,t,l=""){return nl("apply_incident_workflow",{name:e,action:t,fields_json:l})}async function uy(e,t,l=""){return nl("apply_idea_workflow",{name:e,action:t,fields_json:l})}async function py(e=""){const t=`${ce}/api/method/sidrah_business.api.get_dashboard_data${e?`?organization=${encodeURIComponent(e)}`:""}`,l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||{}:{escalated_processes:[],escalated_orders:[],untriaged_incidents:[],kpi_inputs:[]}}async function fy(e,t={}){return nl("get_report_data",{report_name:e,filters_json:JSON.stringify(t)})}async function hy(){try{const e=`${ce}/api/method/sidrah_business.api.get_inbox_items`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||[]:[]}catch{return[]}}async function gy(e,t,l="",s=""){return nl("create_delegation",{manager:e,functions_json:JSON.stringify(t),organization:l,remarks:s})}async function xy(e,t,l=""){return nl("respond_to_delegation",{name:e,response:t,remarks:l})}async function my(e,t=""){return nl("revoke_delegation",{name:e,remarks:t})}async function yy(){try{const e=`${ce}/api/method/sidrah_business.api.get_delegations`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||[]:[]}catch{return[]}}async function vy(e){const t=`${ce}/api/method/sidrah_business.api.get_delegation?name=${encodeURIComponent(e)}`,l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});if(!l.ok)throw new Error("Failed to load delegation");return(await l.json()).message}async function jy(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_delegated_functions`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||[]:[]}catch{return[]}}async function by(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_delegated_organizations`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||{}:{}}catch{return{}}}async function Sy(){const e=Vm();return e||jc()}async function Es(e){const t=await fetch(`${ce}/api/method/sidrah_business.api.get_process?name=${encodeURIComponent(e)}`,{credentials:"include",headers:{Accept:"application/json"}});if(!t.ok){const s=await t.json().catch(()=>({}));throw new Error(s.message||`Failed to load process (${t.status})`)}const l=await t.json();return l.message||l.data}async function wy(e,t,l={}){const s=await Sy(),r=new URLSearchParams({name:e,action:t});l.actor_status&&r.set("actor_status",String(l.actor_status)),l.actor_comment&&r.set("actor_comment",String(l.actor_comment)),l.progress_indicators&&r.set("progress_indicators",JSON.stringify(l.progress_indicators));const i=await fetch(`${ce}/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":s},body:r.toString()});if(!i.ok){const d=await i.json().catch(()=>({})),u=d.message||(d.exception?String(d.exception).split(` `).pop():"")||d.exc_type||`Workflow action "${t}" failed (${i.status})`;throw new Error(u)}const a=await i.json();return a.message||a.data}function ky({onLogin:e}){const t=Z(),[l,s]=j.useState(""),[r,i]=j.useState(""),[a,d]=j.useState(""),[u,f]=j.useState(!1),[y,p]=j.useState(!1),[c,v]=j.useState(!1),w=async()=>{if(!l||!r){d(t.login.emptyFields);return}f(!0),d("");try{const b=await qm(l,r);if(b.message==="Logged In"){const h=await Of()||l,o=await Nf(h),m=o.some(C=>["SB Admin","System Manager"].includes(C))?"Admin":o.includes("SB Auditor")?"Auditor":o.includes("SB Owner")?"Owner":o.includes("SB X-Auditor")?"XAuditor":o.includes("SB Manager")?"Manager":"Employee";e({name:h,full_name:b.full_name||l,role:m})}else d(t.login.invalidCreds)}catch(b){d(t.login.connError+(b instanceof Error?b.message:"Unknown"))}f(!1)},g=b=>({width:"100%",padding:"13px 16px",border:`1.5px solid ${b?"#4f46e5":"#e5e7eb"}`,borderRadius:10,fontSize:15,background:"#ffffff",color:"#374151",outline:"none",transition:"border-color 0.2s, box-shadow 0.2s",boxSizing:"border-box",boxShadow:b?"0 0 0 3px rgba(79,70,229,0.12)":"none"});return n.jsx("div",{style:{minHeight:"100vh",background:"#f3f4f6",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Segoe UI, system-ui, sans-serif"},children:n.jsxs("div",{style:{background:"white",borderRadius:20,padding:"48px 44px 40px",width:420,boxShadow:"0 4px 32px rgba(0,0,0,0.10)"},children:[n.jsxs("div",{style:{textAlign:"center",marginBottom:28},children:[n.jsx("div",{style:{width:72,height:72,borderRadius:18,background:"linear-gradient(135deg, #312e81 0%, #4f46e5 100%)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 18px",boxShadow:"0 4px 16px rgba(79,70,229,0.3)"},children:n.jsx("span",{style:{fontSize:32,color:"white",fontWeight:800,fontFamily:"serif"},children:"S"})}),n.jsx("div",{style:{fontSize:24,fontWeight:700,color:"#1e1b4b"},children:t.rtl?"صدرة للأعمال":"Sidrah Business"}),n.jsx("div",{style:{fontSize:13,color:"#6b7280",marginTop:6},children:t.login.subtitle})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[n.jsx("input",{value:l,onChange:b=>s(b.target.value),onKeyDown:b=>b.key==="Enter"&&w(),onFocus:()=>p(!0),onBlur:()=>p(!1),style:g(y),placeholder:t.login.usernamePlaceholder,autoComplete:"username"}),n.jsx("input",{type:"password",value:r,onChange:b=>i(b.target.value),onKeyDown:b=>b.key==="Enter"&&w(),onFocus:()=>v(!0),onBlur:()=>v(!1),style:g(c),placeholder:t.login.passwordPlaceholder,autoComplete:"current-password"}),a&&n.jsx("div",{style:{padding:"10px 14px",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:8,color:"#dc2626",fontSize:13},children:a}),n.jsx("button",{onClick:w,disabled:u,style:{background:u?"#a5b4fc":"#4f46e5",color:"white",border:"none",padding:"14px",borderRadius:10,fontSize:15,cursor:u?"not-allowed":"pointer",fontWeight:700,marginTop:4,transition:"background 0.2s, transform 0.1s",letterSpacing:"0.01em"},onMouseEnter:b=>{u||(b.currentTarget.style.background="#4338ca")},onMouseLeave:b=>{u||(b.currentTarget.style.background="#4f46e5")},children:u?t.login.signingIn:t.login.signIn})]}),n.jsx("div",{style:{textAlign:"center",marginTop:14},children:n.jsx("button",{onClick:Rf,style:{fontSize:12,color:"#9ca3af",background:"none",border:"none",cursor:"pointer"},children:t.switchLang})})]})})}function _y(e,t){const l=parseInt(e.replace("#",""),16),s=l>>16&255,r=l>>8&255,i=l&255,a=d=>Math.round(d+(255-d)*t);return`rgb(${a(s)}, ${a(r)}, ${a(i)})`}function Dr({title:e,data:t,color:l,onSelect:s}){const[,r]=t[0]??["Total",0,""],i=t.slice(1),a=i.map((u,f)=>_y(l,Math.min(f*.16,.7))),d=i.map(([u,f,y],p)=>[u,f,y,a[p]]).filter(([,u])=>u>0);return n.jsxs("div",{style:{background:"white",borderRadius:12,padding:"14px 16px",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderTop:`3px solid ${l}`,height:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",minWidth:0},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10,paddingBottom:10,borderBottom:"1px solid #f1f5f9"},children:[n.jsx("span",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:e}),n.jsx("span",{style:{fontSize:20,fontWeight:800,color:l},children:r})]}),r>0&&n.jsx("div",{style:{display:"flex",height:10,borderRadius:5,overflow:"hidden",background:"#f1f5f9",marginBottom:12},children:d.map(([u,f,y,p],c)=>n.jsx("div",{title:`${u}: ${f}`,onClick:v=>{v.stopPropagation(),s==null||s(y)},style:{flex:`${f} 0 0`,background:p,borderRight:cn.jsxs("div",{onClick:f>0?c=>{c.stopPropagation(),s==null||s(y)}:void 0,style:{display:"flex",alignItems:"center",gap:8,padding:"2px 4px",borderRadius:4,cursor:f>0&&s?"pointer":"default",transition:"background 0.12s"},onMouseEnter:c=>{f>0&&s&&(c.currentTarget.style.background="#f8fafc")},onMouseLeave:c=>{c.currentTarget.style.background="transparent"},children:[n.jsx("span",{style:{width:8,height:8,borderRadius:2,background:a[p],flexShrink:0}}),n.jsx("span",{style:{flex:1,fontSize:12,color:"#64748b",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}),n.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#334155",flexShrink:0},children:f})]},u))})]})}function It({value:e,onChange:t,organizations:l,placeholder:s="-- Choose organization --",disabled:r=!1,small:i=!1}){var p;const[a,d]=j.useState(!1),u=j.useRef(null);j.useEffect(()=>{const c=v=>{u.current&&!u.current.contains(v.target)&&d(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]);const f=e?((p=l.find(c=>c.organization_name===e||c.name===e))==null?void 0:p.organization_name)??e:s,y=l.filter(c=>!!c.is_active||c.organization_name===e||c.name===e);return n.jsxs("div",{ref:u,style:{position:"relative",width:"100%"},children:[n.jsxs("div",{onClick:()=>!r&&d(c=>!c),style:{width:"100%",padding:i?"4px 8px":"7px 10px",border:"1px solid #ddd",borderRadius:6,fontSize:i?11:12,cursor:r?"default":"pointer",height:i?28:34,background:r?"#f5f5f5":"white",color:e?"#333":"#aaa",display:"flex",justifyContent:"space-between",alignItems:"center",borderColor:a?"#3498db":"#ddd",transition:"border-color 0.2s",userSelect:"none",boxSizing:"border-box",opacity:r?.75:1},children:[n.jsx("span",{children:f}),n.jsx("span",{style:{fontSize:9,color:"#999",transform:a?"rotate(180deg)":"none",transition:"transform 0.2s"},children:"▼"})]}),a&&n.jsx("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:9999,background:"white",border:"1px solid #e0e0e0",borderRadius:6,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",overflow:"hidden"},children:n.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[n.jsx(eu,{label:s,selected:!e,active:!0,isPlaceholder:!0,small:i,onClick:()=>{t(""),d(!1)}}),y.length===0&&n.jsx("div",{style:{padding:"12px 16px",color:"#aaa",fontSize:13},children:"No organizations"}),y.map(c=>n.jsx(eu,{label:c.organization_name,selected:e===c.organization_name||e===c.name,active:!!c.is_active,isPlaceholder:!1,small:i,onClick:()=>{t(c.organization_name),d(!1)}},c.name))]})})]})}function eu({label:e,selected:t,active:l,isPlaceholder:s,small:r,onClick:i}){const[a,d]=j.useState(!1),u=t?"#2563eb":a?"#f0f4ff":"transparent",f=t?"white":s?"#aaa":l?"#1a2332":"#e74c3c";return n.jsx("div",{onClick:i,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),style:{padding:r?"6px 12px":"8px 14px",cursor:"pointer",fontSize:12,background:u,color:f,transition:"background 0.1s"},children:e})}function _n({items:e,type:t,onNavigate:l}){const s=Z();if(!e.length)return null;const r=t==="process"?"processes-form":"orders-form",i=t==="process"?s.dash.escalatedProcesses:s.dash.escalatedOrders;return n.jsxs("div",{children:[n.jsxs("h4",{style:{fontWeight:700,fontSize:12,color:"#e74c3c",marginBottom:6},children:[i," (",e.length,")"]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:e.map(a=>n.jsxs("div",{onClick:()=>l(r,a.name),style:{padding:"8px 12px",background:"#fff5f5",borderRadius:7,border:"1px solid #fecaca",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsxs("div",{children:[n.jsx("span",{style:{fontWeight:700,fontSize:12},children:a.number||a.name}),n.jsx("span",{style:{fontSize:11,color:"#666",marginLeft:8},children:a.title})]}),n.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#e74c3c",background:"#fecaca",padding:"2px 8px",borderRadius:10},children:[s.dash.level," ",a.escalation_level]})]},a.name))})]})}function Cy({kpi:e}){const t=Z();return n.jsxs("div",{style:{background:"white",borderRadius:8,padding:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("div",{style:{fontWeight:700,fontSize:13,marginBottom:2},children:e.organization}),n.jsx("div",{style:{fontSize:11,color:"#888",marginBottom:8},children:e.period}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[{label:t.dash.revenueGrowth,val:e.revenue_growth!=null?`${e.revenue_growth}%`:"—"},{label:t.dash.netProfit,val:e.net_profit!=null?e.net_profit.toLocaleString():"—"},{label:t.dash.strategicGoal,val:e.strategic_goal_pct!=null?`${e.strategic_goal_pct}%`:"—"},{label:t.dash.customerSat,val:e.customer_satisfaction!=null?e.customer_satisfaction:"—"},{label:t.dash.compliance,val:e.compliance_score!=null?e.compliance_score:"—"},{label:t.dash.safetyInc,val:e.open_safety_incidents!=null?e.open_safety_incidents:"—"}].map(({label:l,val:s})=>n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700},children:l}),n.jsx("div",{style:{fontSize:15,fontWeight:700,color:"#1a2332"},children:s})]},l))})]})}function zy({data:e}){if(!e.length)return n.jsx("p",{style:{color:"#aaa",fontSize:13},children:"No cycle data available for trend chart."});const t=Math.max(...e.map(l=>l.pass+l.fail+l.unknown),1);return n.jsxs("div",{children:[n.jsx("div",{style:{display:"flex",gap:10,alignItems:"flex-end",overflowX:"auto",paddingBottom:4},children:e.map(l=>{const s=l.pass+l.fail+l.unknown||1,r=80;return n.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:3,minWidth:48},children:[n.jsxs("div",{style:{display:"flex",flexDirection:"column-reverse",gap:1,height:r,width:32},children:[n.jsx("div",{title:`Pass: ${l.pass}`,style:{height:Math.round(l.pass/t*r),background:"#27ae60",borderRadius:"2px 2px 0 0",minHeight:l.pass?2:0}}),n.jsx("div",{title:`Fail: ${l.fail}`,style:{height:Math.round(l.fail/t*r),background:"#e74c3c",borderRadius:"2px 2px 0 0",minHeight:l.fail?2:0}}),n.jsx("div",{title:`Unknown: ${l.unknown}`,style:{height:Math.round(l.unknown/t*r),background:"#95a5a6",borderRadius:"2px 2px 0 0",minHeight:l.unknown?2:0}})]}),n.jsx("div",{style:{fontSize:9,color:"#999",textAlign:"center",lineHeight:1.2},children:l.month.replace(/^(\d{4})-(\d{2})$/,(i,a,d)=>`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][+d-1]} ${a}`)}),n.jsx("div",{style:{fontSize:9,color:"#555",textAlign:"center"},children:s>1?Math.round(l.pass/s*100)+"%":"—"})]},l.month)})}),n.jsx("div",{style:{display:"flex",gap:16,marginTop:8},children:[["#27ae60","Pass"],["#e74c3c","Fail"],["#95a5a6","Unknown"]].map(([l,s])=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,fontSize:11},children:[n.jsx("div",{style:{width:10,height:10,background:l,borderRadius:2}}),n.jsx("span",{style:{color:"#666"},children:s})]},s))})]})}function Dt({label:e,icon:t,onClick:l}){return n.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",gap:7,padding:"7px 12px",background:"white",border:"1px solid #e8e8e8",borderRadius:8,cursor:"pointer",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",transition:"box-shadow 0.15s"},onMouseEnter:s=>s.currentTarget.style.boxShadow="0 3px 10px rgba(0,0,0,0.12)",onMouseLeave:s=>s.currentTarget.style.boxShadow="0 1px 3px rgba(0,0,0,0.06)",children:[n.jsx("span",{style:{fontSize:15},children:t}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#444",whiteSpace:"nowrap"},children:e})]})}function Ty({dashData:e,fi:t,fid:l,fo:s,fp:r,incidentStatuses:i,ideaStatuses:a,orderStatuses:d,processStatuses:u,onNavigate:f,onNavigateStatus:y}){const p=Z(),c=(e==null?void 0:e.escalated_processes)||[],v=(e==null?void 0:e.escalated_orders)||[],w=(e==null?void 0:e.attention_processes)||[],g=(e==null?void 0:e.attention_orders)||[],b=(e==null?void 0:e.untriaged_incidents)||[],x=(e==null?void 0:e.overdue_triage)||[],h=c.length>0||v.length>0,o=w.length>0||g.length>0,m=[["Total",t.length,""],...i.map(S=>[S.name1||S.name,t.filter(_=>_.status===S.name).length,S.name])],C=[["Total",l.length,""],...a.map(S=>[S.name1||S.name,l.filter(_=>_.status===S.name).length,S.name])],P=[["Total",s.length,""],...d.map(S=>[S.name1||S.name,s.filter(_=>_.status===S.name).length,S.name])],R=[["Total",r.length,""],...u.map(S=>[S.name1||S.name,r.filter(_=>_.status===S.name).length,S.name])];return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",marginBottom:4},children:[n.jsx(Dt,{label:"Incidents",icon:"⚠️",onClick:()=>f("incidents")}),n.jsx(Dt,{label:"Ideas",icon:"💡",onClick:()=>f("ideas")}),n.jsx(Dt,{label:"Orders",icon:"📦",onClick:()=>f("orders")}),n.jsx(Dt,{label:"Processes",icon:"⚙️",onClick:()=>f("processes")}),n.jsx(Dt,{label:"Inbox",icon:"📥",onClick:()=>f("inbox")}),n.jsx(Dt,{label:"Reports",icon:"📊",onClick:()=>f("reports")})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:12},children:[n.jsx("div",{onClick:()=>f("incidents"),style:{cursor:"pointer"},children:n.jsx(Dr,{title:p.dash.incidents,color:U.orange,data:m,onSelect:S=>y("incidents",S)})}),n.jsx("div",{onClick:()=>f("ideas"),style:{cursor:"pointer"},children:n.jsx(Dr,{title:p.dash.ideas,color:U.blue,data:C,onSelect:S=>y("ideas",S)})}),n.jsx("div",{onClick:()=>f("orders"),style:{cursor:"pointer"},children:n.jsx(Dr,{title:p.dash.orders,color:U.purple,data:P,onSelect:S=>y("orders",S)})}),n.jsx("div",{onClick:()=>f("processes"),style:{cursor:"pointer"},children:n.jsx(Dr,{title:p.dash.processes,color:U.red,data:R,onSelect:S=>y("processes",S)})})]}),h&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:10},children:p.dash.level2}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(_n,{items:c,type:"process",onNavigate:f}),n.jsx(_n,{items:v,type:"order",onNavigate:f})]})]}),o&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#b45309",marginBottom:10},children:p.dash.level1}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(_n,{items:w,type:"process",onNavigate:f}),n.jsx(_n,{items:g,type:"order",onNavigate:f})]})]}),x.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:8},children:[p.dash.overduePrefix,x.length,p.dash.overdueSuffix]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:x.map(S=>n.jsxs("div",{onClick:()=>f("incidents-form",S.name),style:{padding:"8px 12px",background:"#fef2f2",borderRadius:8,border:"1px solid #fca5a5",cursor:"pointer",display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{fontWeight:700,fontSize:13},children:S.number||S.name}),n.jsx("span",{style:{fontSize:12,color:"#666"},children:S.title}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:S.date})]},S.name))})]}),b.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:U.orange,marginBottom:8},children:[p.dash.untriaged," (",b.length,")"]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:b.map(S=>n.jsxs("div",{onClick:()=>f("incidents-form",S.name),style:{padding:"8px 12px",background:"#fffbeb",borderRadius:8,border:"1px solid #fed7aa",cursor:"pointer",display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{fontWeight:700,fontSize:13},children:S.number||S.name}),n.jsx("span",{style:{fontSize:12,color:"#666"},children:S.title}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:S.date})]},S.name))})]})]})}function Py({dashData:e,selectedOrg:t,onNavigate:l}){const s=Z(),[r,i]=j.useState([]),[a,d]=j.useState([]),[u,f]=j.useState(!1),y=(e==null?void 0:e.escalated_processes)||[],p=(e==null?void 0:e.escalated_orders)||[],c=(e==null?void 0:e.attention_processes)||[],v=(e==null?void 0:e.attention_orders)||[],w=(e==null?void 0:e.kpi_inputs)||[];j.useEffect(()=>{f(!0);const x=new URLSearchParams({months:"6"});t&&x.append("organization",t),fetch(`/api/method/sidrah_business.api.get_process_trend?${x}`,{credentials:"include",headers:{Accept:"application/json"}}).then(h=>h.json()).then(h=>{const o=h.message||[],m={};for(const C of o)m[C.month]||(m[C.month]={pass:0,fail:0,unknown:0}),C.status==="Pass"?m[C.month].pass=C.count:C.status==="Fail"?m[C.month].fail=C.count:C.status==="Unknown"&&(m[C.month].unknown=C.count);i(Object.entries(m).map(([C,P])=>({month:C,...P})))}).catch(()=>{}).finally(()=>f(!1))},[t]),j.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(x=>x.json()).then(x=>{var h;d((((h=x.message)==null?void 0:h.rows)||[]).slice(0,50))}).catch(()=>{})},[t]);const g=y.length>0||p.length>0,b=c.length>0||v.length>0;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:[n.jsx(Dt,{label:"Manage Users & Roles",icon:"👥",onClick:()=>l("users")}),n.jsx(Dt,{label:"Change Active Cycle",icon:"🔄",onClick:()=>l("cycles")}),n.jsx(Dt,{label:"KPI Inputs",icon:"📈",onClick:()=>l("kpi-input")}),n.jsx(Dt,{label:"Reports",icon:"📊",onClick:()=>l("reports")}),n.jsx(Dt,{label:"Organizations",icon:"🏢",onClick:()=>l("organizations")})]}),w.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:10},children:s.dash.recentKpi}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12},children:w.map(x=>n.jsx(Cy,{kpi:x},x.name))}),n.jsx("button",{onClick:()=>l("kpi-input"),style:{marginTop:10,padding:"6px 14px",borderRadius:7,border:"1px solid #2980b9",background:"white",color:"#2980b9",fontWeight:600,fontSize:12,cursor:"pointer"},children:s.dash.manageKpi})]}),g&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:10},children:["Critical Escalations — Level 2 (",y.length+p.length,")"]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(_n,{items:y,type:"process",onNavigate:l}),n.jsx(_n,{items:p,type:"order",onNavigate:l})]})]}),b&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#b45309",marginBottom:10},children:["Needs Attention — Level 1 (",c.length+v.length,")"]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(_n,{items:c,type:"process",onNavigate:l}),n.jsx(_n,{items:v,type:"order",onNavigate:l})]})]}),n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:4},children:"Process Trend — Last 6 Months"}),n.jsx("p",{style:{fontSize:11,color:"#888",marginBottom:10},children:"Pass/Fail/Unknown ratio per month across all processes. Pass % shown at bottom of each bar."}),u?n.jsx("p",{style:{color:"#aaa",fontSize:13},children:"Loading trend data…"}):n.jsx(zy,{data:r})]}),a.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:10},children:"Log Book — Recent Activity"}),n.jsx("div",{style:{overflowX:"auto"},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa"},children:["Timestamp","User","Entity Type","Entity","Fields Changed"].map(x=>n.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#999",fontWeight:700,fontSize:11,whiteSpace:"nowrap"},children:x},x))})}),n.jsx("tbody",{children:a.map((x,h)=>n.jsxs("tr",{style:{borderTop:"1px solid #f0f0f0",background:h%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"8px 12px",color:"#555",whiteSpace:"nowrap"},children:x.timestamp?String(x.timestamp).slice(0,16):"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#333"},children:x.user||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:x.entity_type||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:x.entity_name||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#888",maxWidth:240,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.changes||"—"})]},h))})]})}),n.jsx("button",{onClick:()=>l("reports"),style:{marginTop:12,padding:"7px 16px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:600,fontSize:12,cursor:"pointer"},children:"Full Activity Log (Reports →)"})]})]})}function Iy({incidents:e,ideas:t,orders:l,processes:s,organizations:r,incidentStatuses:i,ideaStatuses:a,orderStatuses:d,processStatuses:u,selectedOrg:f,onOrgChange:y,onNavigate:p,onNavigateStatus:c,userRole:v}){const[w,g]=j.useState(null);j.useEffect(()=>{py(f).then(g)},[f]);const b=f?e.filter(_=>_.organization===f):e,x=f?t.filter(_=>_.organization===f):t,h=f?l.filter(_=>_.organization===f):l,o=f?s.filter(_=>_.organization===f):s,m=v==="Admin",C=v==="Owner",[P,R]=j.useState("level2"),S=C||m&&P==="level2";return n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"white",borderRadius:10,padding:"8px 14px",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#4f46e5",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#1e1b4b",whiteSpace:"nowrap"},children:"Filter"})]}),n.jsx("div",{style:{flex:1,minWidth:160,maxWidth:260},children:n.jsx(It,{value:f,onChange:y,organizations:r,placeholder:"All Organizations",small:!0})}),m&&n.jsx("div",{style:{display:"flex",background:"#f1f0fe",borderRadius:7,padding:2,gap:2,flexShrink:0},children:["level1","level2"].map(_=>n.jsx("button",{onClick:()=>R(_),style:{padding:"4px 10px",borderRadius:5,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:P===_?_==="level2"?U.purple:U.blue:"transparent",color:P===_?"white":"#6b7280",transition:"all 0.15s"},children:_==="level1"?"Level 1":"Level 2"},_))}),!m&&n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"white",background:S?U.purple:U.blue,padding:"3px 10px",borderRadius:20,flexShrink:0},children:S?"Level 2 — Owner":"Level 1 — Operational"})]}),S?n.jsx(Py,{dashData:w,selectedOrg:f,onNavigate:p}):n.jsx(Ty,{dashData:w,fi:b,fid:x,fo:h,fp:o,incidentStatuses:i,ideaStatuses:a,orderStatuses:d,processStatuses:u,onNavigate:p,onNavigateStatus:c})]})}const Ey=()=>n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),Ay=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),Ry=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6l-1 14H6L5 6"}),n.jsx("path",{d:"M10 11v6M14 11v6"}),n.jsx("path",{d:"M9 6V4h6v2"})]});function Je({onView:e,onEdit:t,onDelete:l}){const[s,r]=j.useState(!1),i=(d,u,f,y,p)=>f?n.jsx("button",{onClick:c=>{c.stopPropagation(),f()},title:p,style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:d,color:u,flexShrink:0,transition:"opacity 0.15s"},onMouseEnter:c=>c.currentTarget.style.opacity="0.75",onMouseLeave:c=>c.currentTarget.style.opacity="1",children:y},p):null,a=l?()=>{s?(r(!1),l()):r(!0)}:void 0;return n.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[i("#e0f7fa","#0891b2",e,n.jsx(Ey,{}),"View"),i("#dcfce7","#16a34a",t,n.jsx(Ay,{}),"Edit"),l&&n.jsx("button",{onClick:d=>{d.stopPropagation(),a==null||a()},title:s?"Click again to confirm delete":"Delete",style:{minWidth:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:s?8:"50%",padding:s?"0 8px":0,border:"none",cursor:"pointer",background:s?"#ef4444":"#fee2e2",color:s?"white":"#ef4444",flexShrink:0,fontSize:s?11:14,fontWeight:700,transition:"all 0.15s",gap:4},onMouseEnter:d=>d.currentTarget.style.opacity="0.8",onMouseLeave:d=>d.currentTarget.style.opacity="1",onBlur:()=>r(!1),children:s?"✓ Sure?":n.jsx(Ry,{})})]})}const E={width:"100%",height:34,padding:"7px 10px",border:"1px solid #ddd",borderRadius:6,fontSize:12,boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif"},z={display:"block",marginBottom:5,fontSize:11,color:"#555",fontWeight:600};function Ly(e){return 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 fe(e,t){return e.filter(l=>Ly(l)||l.name===t)}function Kl(e,t,l){return e.filter(s=>{const r=t[s.name]||[];return r.includes("SB Admin")||r.includes("System Manager")?!1:r.includes(l)})}const Ql={width:16,height:16,cursor:"pointer",accentColor:"#2563eb",flexShrink:0},Dn=(e,t)=>n.jsx("span",{style:{background:t,color:"white",padding:"4px 12px",borderRadius:12,fontSize:12,fontWeight:600,display:"inline-block"},children:e}),Fi=e=>{switch(e){case"New":return"#e74c3c";case"Under Progress":return"#f39c12";case"Executed":return"#27ae60";case"Overdue":return"#7f1d1d";default:return"#95a5a6"}},Be={fontSize:10,color:"#6b7280",fontWeight:600,marginBottom:3,display:"block",textTransform:"uppercase",letterSpacing:.4},$e={width:"100%",padding:"4px 8px",border:"1px solid #d1d5db",borderRadius:6,fontSize:11,background:"white",color:"#374151",boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif",height:28};function Mi({children:e}){const[t,l]=j.useState(!1);return n.jsxs("div",{style:{borderRadius:8,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",flexShrink:0},children:[n.jsxs("div",{onClick:()=>l(s=>!s),style:{background:"#4f46e5",color:"white",padding:"9px 18px",cursor:"pointer",display:"flex",alignItems:"center",gap:10,userSelect:"none"},children:[n.jsx("span",{style:{fontSize:13,opacity:.9},children:t?"▲":"▼"}),n.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{fontSize:13,fontWeight:600},children:"Filters"})]}),t&&n.jsx("div",{style:{background:"white",padding:"12px 16px",borderTop:"1px solid #e5e7eb"},children:e})]})}const te=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 Ue({page:e,pageSize:t=te,total:l,onPageChange:s}){if(l===0)return null;const r=Math.max(1,Math.ceil(l/t)),i=(e-1)*t+1,a=Math.min(e*t,l);return n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 4px",fontSize:12,color:"#6b7280",flexShrink:0},children:[n.jsxs("span",{children:["Showing ",i," to ",a," of ",l," results"]}),n.jsxs("div",{style:{display:"flex",gap:8},children:[n.jsx("button",{disabled:e<=1,onClick:()=>s(e-1),style:tu(e<=1),children:"Previous"}),n.jsx("button",{disabled:e>=r,onClick:()=>s(e+1),style:tu(e>=r),children:"Next"})]})]})}function Oy({incidents:e,organizations:t,departments:l,branches:s,incidentStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=Z(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),w=(o,m)=>v(C=>({...C,[o]:m})),[g,b]=j.useState(1),x=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{b(1)},[c]);const h=x.slice((g-1)*te,g*te);return n.jsxs(n.Fragment,{children:[n.jsx(Mi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.numberTitle}),n.jsx("input",{style:$e,value:c.search,onChange:o=>w("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.organization}),n.jsxs("select",{style:$e,value:c.organization,onChange:o=>w("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.department}),n.jsxs("select",{style:$e,value:c.department,onChange:o=>w("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.branch}),n.jsxs("select",{style:$e,value:c.branch,onChange:o=>w("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.status}),n.jsxs("select",{style:$e,value:c.status,onChange:o=>w("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name))]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.type}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:x.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noIncidents})}):h.map((o,m)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.type?Dn(o.type,"#e74c3c"):"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Dn(o.status,Fi(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:C=>C.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Ue,{page:g,total:x.length,onPageChange:b})]})}function Dy(e){if(!e)return"";const[t,l,s]=e.split("-");return!t||!l||!s?"":`${s}/${l}/${t}`}function xe({value:e,onChange:t,disabled:l,style:s,min:r,max:i}){return n.jsxs("div",{style:{position:"relative",width:"100%"},children:[n.jsx("input",{type:"text",readOnly:!0,tabIndex:-1,value:Dy(e),placeholder:"DD/MM/YYYY",style:{...s,pointerEvents:"none",paddingRight:30}}),n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:l?"#bbb":"#666",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",pointerEvents:"none"},children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),n.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),n.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),n.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),n.jsx("input",{type:"date",value:e||"",disabled:l,min:r,max:i,onChange:a=>t(a.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0,cursor:l?"default":"pointer",border:"none",padding:0,margin:0}})]})}function Ny({title:e,children:t}){return n.jsxs("div",{style:{background:"white",borderRadius:10,padding:"18px 20px",marginBottom:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[e&&n.jsx("div",{style:{fontSize:15,fontWeight:700,marginBottom:16,color:"#1e1b4b"},children:e}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:13},children:t})]})}const nu={"SB Process":"processes-form","SB Order":"orders-form","SB Incident":"incidents-form","SB Idea":"ideas-form","SB Delegation":"delegations"};function Wy(e){const t=(Date.now()-new Date(e).getTime())/1e3;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function Wf({notifCount:e,darkMode:t,onCountChange:l,onToggleDark:s,onViewProfile:r,onLogout:i,onNavigate:a}){const[d,u]=j.useState(!1),[f,y]=j.useState([]),[p,c]=j.useState(!1),v=j.useRef(null);j.useEffect(()=>{const S=_=>{v.current&&!v.current.contains(_.target)&&u(!1)};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[]);const w=async()=>{c(!0);const S=await ny(30);y(S),c(!1)},g=()=>{const S=!d;u(S),S&&w()},b=async()=>{await ly(),y(S=>S.map(_=>({..._,read:1}))),l(0)},x=S=>{S.read||(sy(S.name),y($=>$.map(T=>T.name===S.name?{...T,read:1}:T)),l(Math.max(0,e-1)));const _=S.document_type?nu[S.document_type]:void 0;_&&a&&(a(_,S.document_type==="SB Delegation"?void 0:S.document_name),u(!1))},h=f.filter(S=>!S.read).length,o=S=>({position:"relative",width:34,height:34,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:t?"#2d3748":"#f3f4f6",color:t?"#e2e8f0":"#6b7280",fontSize:14,transition:"background 0.15s",flexShrink:0,...S}),m=t,C=m?"#1a202c":"white",P=m?"#2d3748":"#e5e7eb",R=m?"#e2e8f0":"#1a2332";return n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("button",{style:o({background:"#4f46e5",color:"white"}),onClick:r,title:"My Profile",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:[n.jsx("circle",{cx:"12",cy:"8",r:"4"}),n.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7",fill:"currentColor"})]})}),n.jsxs("div",{ref:v,style:{position:"relative"},children:[n.jsxs("button",{style:o(),onClick:g,title:"Notifications",children:[n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),n.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),e>0&&n.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})]}),d&&n.jsxs("div",{style:{position:"absolute",right:0,top:"calc(100% + 8px)",width:340,background:C,borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.2)",zIndex:1e4,border:`1px solid ${P}`,overflow:"hidden"},children:[n.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${P}`,display:"flex",alignItems:"center",justifyContent:"space-between",background:C},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:R},children:["Notifications",h>0&&n.jsxs("span",{style:{background:"#ef4444",color:"white",fontSize:10,fontWeight:700,borderRadius:999,padding:"2px 7px"},children:[h," new"]})]}),h>0&&n.jsx("button",{onClick:b,style:{fontSize:12,color:"#3498db",background:"none",border:"none",cursor:"pointer",fontFamily:"inherit"},children:"Mark all read"})]}),n.jsxs("div",{style:{maxHeight:380,overflowY:"auto"},children:[p&&n.jsx("div",{style:{padding:20,textAlign:"center",color:"#aaa",fontSize:13},children:"Loading…"}),!p&&f.length===0&&n.jsxs("div",{style:{padding:"36px 20px",textAlign:"center",color:"#aaa"},children:[n.jsx("div",{style:{fontSize:28,marginBottom:8},children:"🔔"}),n.jsx("div",{style:{fontSize:13},children:"No notifications"})]}),!p&&f.map(S=>{const _=!!(S.document_type&&nu[S.document_type]&&a);return n.jsxs("div",{onClick:()=>x(S),style:{padding:"11px 16px",borderBottom:`1px solid ${m?"#2d3748":"#f5f5f5"}`,display:"flex",gap:10,background:S.read?C:m?"#1e3a5f":"#eff6ff",cursor:_?"pointer":"default",transition:"background 0.12s"},onMouseEnter:$=>{_&&($.currentTarget.style.background=m?"#243244":"#e0ecfd")},onMouseLeave:$=>{$.currentTarget.style.background=S.read?C:m?"#1e3a5f":"#eff6ff"},children:[n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:13,fontWeight:S.read?400:600,color:R,marginBottom:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S.subject||`${S.document_type}: ${S.document_name}`}),n.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:S.document_type&&n.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#3b82f6",background:m?"rgba(59,130,246,0.15)":"#eff6ff",padding:"1px 7px",borderRadius:8},children:[S.document_type.replace("SB ",""),S.document_name?` · ${S.document_name}`:""]})}),n.jsx("div",{style:{fontSize:11,color:"#aaa",marginTop:3},children:Wy(S.creation)})]}),!S.read&&n.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:"#3498db",flexShrink:0,marginTop:5}})]},S.name)})]})]})]}),n.jsx("button",{style:o(),onClick:Rf,title:El()?"Switch to English":"Switch to Arabic",children:n.jsx("span",{style:{fontSize:13,fontWeight:700,fontFamily:"serif"},children:"عA"})}),n.jsx("button",{style:o(),onClick:s,title:t?"Light mode":"Dark mode",children:t?n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"5"}),n.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),n.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),n.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),n.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),n.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),n.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),n.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),n.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),n.jsx("button",{style:o({background:m?"#3d1515":"#fee2e2",color:"#ef4444"}),onClick:i,title:"Logout",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),n.jsx("polyline",{points:"16,17 21,12 16,7"}),n.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})}function Fe({title:e,activePage:t,user:l,formStatus:s,buttonText:r,buttonColor:i,viewMode:a,onEdit:d,hideSettings:u,rightPanel:f,darkMode:y,notifCount:p,onToggleDark:c,onCountChange:v,onViewProfile:w,onSubmit:g,onBack:b,onNavigate:x,onLogout:h,children:o}){const m=Z(),C=m.nav[t]||t,P=l.role,R=P==="Admin"||P==="Owner"||P==="Auditor"||P==="Manager",S=P==="Admin"||P==="Owner"||P==="Auditor"||P==="Manager",_=P==="Admin"||P==="Auditor"||P==="Manager",$=R?"dashboard":"inbox",[T,I]=j.useState(()=>localStorage.getItem("sb_sidebar")==="1"),N=()=>I(F=>{const ne=!F;return localStorage.setItem("sb_sidebar",ne?"1":"0"),ne});return n.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:U.bg},children:[n.jsx(Ef,{collapsed:T,onToggleCollapsed:N,activePage:t,onNavigate:x,hasDashboard:R,hasReports:S,hasDelegations:_,role:P,hideSettings:u,rtl:m.rtl,navLabels:m.nav,settingsLabel:m.nav.settings}),n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[n.jsxs("div",{style:{background:"white",padding:"10px 20px",borderBottom:"1px solid #e9eaf0",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,boxShadow:"0 1px 4px rgba(0,0,0,0.04)"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[n.jsx("button",{onClick:b,title:m.back,style:{width:30,height:30,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"1.5px solid #e5e7eb",background:"white",cursor:"pointer",color:"#4f46e5",flexShrink:0},children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:15,fontWeight:700,color:"#1e1b4b"},children:e}),n.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:1},children:[n.jsx("span",{onClick:()=>x($),style:{cursor:"pointer",color:"#4f46e5"},onMouseEnter:F=>F.currentTarget.style.textDecoration="underline",onMouseLeave:F=>F.currentTarget.style.textDecoration="none",children:m.home}),!u&&n.jsxs(n.Fragment,{children:[n.jsx("span",{style:{margin:"0 4px"},children:"/"}),n.jsx("span",{onClick:b,style:{cursor:"pointer",color:"#4f46e5"},onMouseEnter:F=>F.currentTarget.style.textDecoration="underline",onMouseLeave:F=>F.currentTarget.style.textDecoration="none",children:C})]})]})]})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[a&&d&&n.jsxs("button",{onClick:d,style:{display:"flex",alignItems:"center",gap:6,padding:"7px 16px",borderRadius:7,border:"none",background:"#4f46e5",color:"white",cursor:"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI"},children:[n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),m.edit]}),n.jsx(Wf,{notifCount:p,darkMode:y,onCountChange:v,onToggleDark:c,onNavigate:x,onViewProfile:w,onLogout:h})]})]}),n.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px",display:"grid",gridTemplateColumns:f?"1fr auto":"1fr",gap:14,alignItems:"start"},children:[n.jsx("div",{style:{minWidth:0},children:n.jsxs(Ny,{children:[o,!a&&n.jsxs("div",{style:{display:"flex",gap:10,marginTop:20},children:[n.jsx("button",{onClick:b,style:{padding:"9px 22px",borderRadius:8,border:"1.5px solid #e5e7eb",cursor:"pointer",fontSize:13,fontWeight:600,background:"white",color:"#374151",fontFamily:"Segoe UI"},children:m.cancel}),n.jsx("button",{onClick:g,disabled:s==="loading",style:{padding:"9px 22px",borderRadius:8,background:i,color:"white",border:"none",cursor:"pointer",fontSize:13,fontWeight:600,opacity:s==="loading"?.7:1,boxShadow:"0 2px 10px rgba(79,70,229,0.18)",fontFamily:"Segoe UI"},children:s==="loading"?m.saving:r})]}),s==="success"&&n.jsx("div",{style:{padding:"10px",borderRadius:8,background:"#f0fdf4",border:"1px solid #86efac",color:"#166534",fontSize:13,marginTop:10},children:m.savedOk}),s!=="idle"&&s!=="loading"&&s!=="success"&&n.jsx("div",{style:{padding:"10px",borderRadius:8,background:"#fef2f2",border:"1px solid #fca5a5",color:"#991b1b",fontSize:13,marginTop:10},children:s})]})}),f&&n.jsx("div",{style:{position:"sticky",top:0,alignSelf:"start"},children:f})]})]})]})}function ue({value:e,onChange:t,items:l,placeholder:s="-- Select --",disabled:r=!1}){var p;const[i,a]=j.useState(!1),[d,u]=j.useState(""),f=j.useRef(null);j.useEffect(()=>{const c=v=>{f.current&&!f.current.contains(v.target)&&a(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]);const y=e?((p=l.find(c=>c.name===e))==null?void 0:p.label)??e:s;return n.jsxs("div",{ref:f,style:{position:"relative",width:"100%"},children:[n.jsxs("div",{onClick:()=>!r&&a(c=>!c),style:{width:"100%",height:34,padding:"7px 10px",border:"1px solid",borderColor:i?"#3498db":"#ddd",borderRadius:6,fontSize:12,cursor:r?"default":"pointer",background:r?"#f5f5f5":"white",color:e?"#333":"#aaa",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"border-color 0.2s",userSelect:"none",boxSizing:"border-box",opacity:r?.75:1},children:[n.jsx("span",{children:y}),n.jsx("span",{style:{fontSize:9,color:"#999",transform:i?"rotate(180deg)":"none",transition:"transform 0.2s"},children:"▼"})]}),i&&n.jsx("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:9999,background:"white",border:"1px solid #e0e0e0",borderRadius:6,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",overflow:"hidden"},children:n.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[n.jsx("div",{onClick:()=>{t(""),a(!1)},onMouseEnter:()=>u("__placeholder"),onMouseLeave:()=>u(""),style:{padding:"8px 14px",cursor:"pointer",fontSize:12,color:"#aaa",background:d==="__placeholder"?"#f5f5f5":"transparent"},children:s}),l.length===0&&n.jsx("div",{style:{padding:"10px 14px",color:"#aaa",fontSize:12},children:"No records found"}),l.map(c=>n.jsx("div",{onClick:()=>{t(c.name),a(!1)},onMouseEnter:()=>u(c.name),onMouseLeave:()=>u(""),style:{padding:"8px 14px",cursor:"pointer",fontSize:12,background:e===c.name?"#2563eb":d===c.name?"#f0f4ff":"transparent",color:e===c.name?"white":"#1a2332",transition:"background 0.1s"},children:c.label},c.name))]})})]})}function By(e){const t=(Date.now()-new Date(e).getTime())/1e3;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:t<86400*7?`${Math.floor(t/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function $y(e){return e.replace(/@.*/,"").replace(/[._-]/g," ").split(" ").filter(Boolean).slice(0,2).map(l=>l[0].toUpperCase()).join("")}function Hi({doctype:e,docname:t,currentUserName:l}){const s=Z(),[r,i]=j.useState([]),[a,d]=j.useState(!1),[u,f]=j.useState(""),[y,p]=j.useState(!1),[c,v]=j.useState(!1),[w,g]=j.useState(!1),[b,x]=j.useState(""),h=5,o=j.useCallback(async()=>{d(!0);const S=await iy(e,t);i(S),d(!1)},[e,t]);j.useEffect(()=>{o()},[o]);const m=async()=>{const S=u.trim();if(!(!S||y)){p(!0),x("");try{await ay(e,t,S),f(""),await o()}catch{x("Failed to post comment. Please try again.")}p(!1)}},C=async S=>{if(window.confirm("Delete this comment?"))try{await Lf("Comment",S),i(_=>_.filter($=>$.name!==S))}catch{alert("Failed to delete comment.")}},P=w?r:r.slice(-h),R=Math.max(0,r.length-h);return n.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[n.jsxs("div",{onClick:()=>v(S=>!S),style:{padding:"12px 20px",borderBottom:c?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none",background:"white"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["💬 ",s.comments.title,r.length>0&&n.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:r.length})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("button",{onClick:S=>{S.stopPropagation(),o()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),n.jsx("span",{style:{color:"#ccc",fontSize:11},children:c?"▼":"▲"})]})]}),!c&&n.jsxs("div",{style:{padding:"16px 20px"},children:[!w&&R>0&&n.jsxs("button",{onClick:()=>g(!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 ",R," older comment",R!==1?"s":""]}),a&&n.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:s.loading}),!a&&r.length===0&&n.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:s.comments.noComments}),!a&&P.length>0&&n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:16},children:P.map(S=>{const _=S.comment_by||S.comment_email||S.owner||"Unknown",$=S.owner===l||S.comment_by===l;return n.jsxs("div",{style:{display:"flex",gap:10,padding:"12px 14px",background:"#f9fafb",borderRadius:8,border:"1px solid #e8e8e8"},children:[n.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:$y(_)}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("span",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:_}),n.jsx("span",{style:{fontSize:11,color:"#aaa"},children:By(S.creation)})]}),$&&n.jsx("button",{onClick:()=>C(S.name),style:{background:"none",border:"none",cursor:"pointer",color:"#e74c3c",fontSize:16,padding:"0 2px",lineHeight:1},title:"Delete comment",children:"×"})]}),n.jsx("div",{style:{fontSize:13,color:"#374151",lineHeight:1.55,wordBreak:"break-word",whiteSpace:"pre-wrap"},dangerouslySetInnerHTML:{__html:S.content||""}})]})]},S.name)})}),n.jsxs("div",{style:{borderTop:r.length>0?"1px solid #f0f0f0":"none",paddingTop:r.length>0?14:0},children:[n.jsx("textarea",{value:u,onChange:S=>f(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.ctrlKey||S.metaKey)&&m()},placeholder:s.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"}}),b&&n.jsx("div",{style:{fontSize:12,color:"#e74c3c",marginTop:4},children:b}),n.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:8},children:n.jsx("button",{onClick:m,disabled:!u.trim()||y,style:{padding:"8px 20px",background:"#3498db",color:"white",border:"none",borderRadius:6,cursor:!u.trim()||y?"not-allowed":"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI",opacity:!u.trim()||y?.6:1},children:y?s.saving:s.comments.post})})]})]})]})}function lu(e){if(!e)return"";const t=(Date.now()-new Date(e).getTime())/1e3;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:t<86400*7?`${Math.floor(t/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Uy(e){return(e||"").replace(/^custom_/,"").replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function su(e){return e==null||e===""?"(empty)":typeof e=="object"?JSON.stringify(e):String(e)}function _o(e){return(e||"Unknown").replace(/@.*/,"").replace(/[._]/g," ")}function ru(e){return _o(e).split(" ").filter(Boolean).slice(0,2).map(t=>t[0].toUpperCase()).join("")}function Fy(e){let t={};try{t=JSON.parse(e.data||"{}")}catch{}const l=(t.changed||[]).map(s=>({field:s[0]||"",oldVal:su(s[1]),newVal:su(s[2])}));return{name:e.name,owner:e.owner,creation:e.creation,changes:l,added:(t.added||[]).length,removed:(t.removed||[]).length,rowChanged:(t.row_changed||[]).length}}function Ki({doctype:e,docname:t,docCreation:l,docOwner:s}){const r=Z(),[i,a]=j.useState([]),[d,u]=j.useState(!1),[f,y]=j.useState(!0),[p,c]=j.useState(!1),v=5,w=j.useCallback(async()=>{u(!0);const h=await oy(e,t);a(h.map(Fy)),u(!1)},[e,t]);j.useEffect(()=>{f||w()},[f,w]);const g=p?i:i.slice(0,v),b=i.length-v,x=(h,o=!1)=>({position:"absolute",left:-14,top:14,width:10,height:10,borderRadius:"50%",background:h,border:"2px solid white",boxShadow:o?`0 0 0 2px ${h}44`:"none"});return n.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[n.jsxs("div",{onClick:()=>y(h=>!h),style:{padding:"12px 20px",borderBottom:f?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["📋 ",r.activity.title,!f&&i.length>0&&n.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:i.length})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[!f&&n.jsx("button",{onClick:h=>{h.stopPropagation(),w()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),n.jsx("span",{style:{color:"#ccc",fontSize:11},children:f?"▼":"▲"})]})]}),!f&&n.jsxs("div",{style:{padding:"16px 20px"},children:[d&&n.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:r.loading}),!d&&n.jsxs("div",{style:{position:"relative",paddingLeft:20},children:[n.jsx("div",{style:{position:"absolute",left:8,top:0,bottom:0,width:2,background:"#e5e7eb"}}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[g.map((h,o)=>n.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[n.jsx("div",{style:x(o===0?"#3498db":"#d1d5db",o===0)}),n.jsxs("div",{style:{background:o===0?"#eff6ff":"#f9fafb",border:`1px solid ${o===0?"#bfdbfe":"#e5e7eb"}`,borderRadius:8,padding:"10px 14px"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[n.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(h.owner)}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:_o(h.owner)}),n.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:lu(h.creation)})]}),h.changes.length>0?n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:h.changes.map((m,C)=>n.jsxs("div",{style:{fontSize:12,lineHeight:1.5},children:[n.jsx("span",{style:{fontWeight:600,color:"#6d28d9"},children:Uy(m.field)}),n.jsx("span",{style:{color:"#6b7280"},children:" changed from "}),n.jsx("span",{style:{padding:"1px 5px",background:"#fee2e2",color:"#dc2626",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:m.oldVal}),n.jsx("span",{style:{color:"#6b7280"},children:" → "}),n.jsx("span",{style:{padding:"1px 5px",background:"#dcfce7",color:"#16a34a",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:m.newVal})]},C))}):n.jsxs("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic"},children:["Document updated",h.added>0&&n.jsxs("span",{children:[" · +",h.added," row(s)"]}),h.removed>0&&n.jsxs("span",{children:[" · -",h.removed," row(s)"]}),h.rowChanged>0&&n.jsxs("span",{children:[" · ~",h.rowChanged," row(s) modified"]})]})]})]},h.name)),l&&s&&n.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[n.jsx("div",{style:x("#22c55e")}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"10px 14px"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[n.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(s)}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:_o(s)}),n.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:lu(l)})]}),n.jsxs("div",{style:{fontSize:12,color:"#15803d",fontWeight:600},children:["✓ ",r.activity.created]})]})]}),i.length===0&&!l&&n.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:"No activity recorded"})]})]}),!d&&b>0&&n.jsx("div",{style:{textAlign:"center",marginTop:12},children:n.jsx("button",{onClick:()=>c(h=>!h),style:{background:"none",border:"none",cursor:"pointer",color:"#3498db",fontSize:12,fontFamily:"Segoe UI",padding:"4px 8px"},children:p?"▲ Show less":`▼ Show all (${i.length})`})})]})]})}const gs={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},_a={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},My={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 Hy(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...My[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function Ky({incForm:e,setIncForm:t,organizations:l,managements:s,departments:r,branches:i,incidentTypes:a,incidentClasses:d,incidentFields:u,incidentStatuses:f,users:y,userRoleMap:p={},formStatus:c,viewMode:v,onEdit:w,darkMode:g,notifCount:b,onToggleDark:x,onCountChange:h,onViewProfile:o,userRole:m,onSubmit:C,onBack:P,onNavigate:R,onLogout:S,user:_,onRefresh:$}){const T=Z(),I=L=>t({...e,...L}),N=v?{background:"#f9f9f9"}:{},F=Kl(y,p,"SB Employee"),ne=Kl(y,p,"SB Manager"),[ee,me]=j.useState(""),[A,Q]=j.useState(!1),G=e.name?v?`${T.formTitle.viewIncident}${e.number||e.name}`:T.formTitle.editIncident:T.formTitle.newIncident,V=fe(s,e.management).map(L=>({name:L.name,label:L.name1||L.name})),q=fe(r,e.department).map(L=>({name:L.name,label:L.department_name||L.name})),ge=fe(i,e.branch).map(L=>({name:L.name,label:L.branch||L.name})),Ce=fe(a,e.type).map(L=>({name:L.name,label:L.name1||L.name})),se=d.map(L=>({name:L.name,label:L.name1||L.name})),je=u.map(L=>({name:L.name,label:L.name1||L.name})),Qe=fe(f,e.status).map(L=>({name:L.name,label:L.name1||L.name})),H=e.workflow_state||"New",re=m==="Employee",D=m==="Auditor"||m==="Admin",le=m==="Manager",wt=e.name?H==="New"?[{label:T.wf.submit,action:"Submit",color:"#2563eb"}]:H==="Initial Evaluation"&&D?[{label:T.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:T.wf.reject,action:"Reject",color:"#dc2626"}]:H==="Accept & Under Progress"&&(le||D)?[{label:T.wf.submitSolution,action:"Submit Solution",color:"#059669"}]:H==="working on resolution"&&(le||D)?[{label:T.wf.resolutionComplete,action:"Resolution complete",color:"#166534"}]:[]:[];async function Yt(L){if(e.name){Q(!0),me("");try{const K={};L==="Assign to Manager"&&(e.assigned_to&&(K.assigned_to=e.assigned_to),e.priority&&(K.priority=e.priority),e.economy_class&&(K.economy_class=e.economy_class),e.entity_scope&&(K.entity_scope=e.entity_scope),e.hses_field&&(K.hses_field=e.hses_field),K.product_relation=String(e.product_relation??0),K.repeated=String(e.repeated??0)),L==="Submit Solution"&&(e.solution&&(K.solution=e.solution),e.summary&&(K.summary=e.summary),e.cost&&(K.cost=String(e.cost))),(L==="Resolution complete"||L==="Submit Solution")&&e.auditor_comment&&(K.auditor_comment=e.auditor_comment),await dy(e.name,L,JSON.stringify(K)),me("Done"),$==null||$()}catch(K){me(K.message||"Error")}finally{Q(!1)}}}const O=e.name?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"#f8fafc",borderRadius:10,padding:16,border:"1px solid #e2e8f0"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[n.jsx("h4",{style:{fontWeight:700,color:"#1e293b",margin:0,fontSize:14},children:T.wf.workflow}),n.jsx("span",{style:Hy(H),children:H})]}),H==="Initial Evaluation"&&D&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:z,children:T.wf.assignToManager}),n.jsxs("select",{style:E,value:e.assigned_to||"",onChange:L=>I({assigned_to:L.target.value}),children:[n.jsx("option",{value:"",children:T.field.selectMgr}),ne.map(L=>n.jsx("option",{value:L.name,children:L.full_name||L.name},L.name))]})]}),(H==="Accept & Under Progress"||H==="working on resolution")&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:z,children:T.field.solution}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical"},value:e.solution||"",onChange:L=>I({solution:L.target.value}),placeholder:T.field.solutionPlaceholder}),n.jsx("label",{style:{...z,marginTop:8},children:T.field.actualCost}),n.jsx("input",{type:"number",style:E,value:e.cost||"",onChange:L=>I({cost:parseFloat(L.target.value)||0}),placeholder:"0.00"})]}),H==="working on resolution"&&D&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:z,children:T.field.auditorComment}),n.jsx("textarea",{style:{...E,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:L=>I({auditor_comment:L.target.value}),placeholder:T.field.commentPlaceholder})]}),wt.length>0?n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:wt.map(L=>n.jsx("button",{onClick:()=>Yt(L.action),disabled:A,style:{padding:"8px 18px",borderRadius:8,border:"none",background:L.color,color:"white",fontWeight:700,cursor:A?"not-allowed":"pointer",opacity:A?.7:1},children:A?T.wf.applying:L.label},L.action))}):n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:T.wf.noActions}),ee&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:ee==="Done"?U.green:U.red},children:ee})]}),n.jsx(Hi,{doctype:B.incidents,docname:e.name,currentUserName:_.name}),n.jsx(Ki,{doctype:B.incidents,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(Fe,{title:G,activePage:"incidents",user:_,formStatus:c,buttonText:T.saveIncident,buttonColor:U.accent,viewMode:v,onEdit:w,darkMode:g,notifCount:b,onToggleDark:x,onCountChange:h,onViewProfile:o,rightPanel:O,onSubmit:C,onBack:P,onNavigate:R,onLogout:S,children:[n.jsxs("div",{style:gs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.organization}),n.jsx(It,{value:e.organization,onChange:L=>I({organization:L}),organizations:l,disabled:v})]})]}),n.jsxs("div",{style:_a,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.management}),n.jsx(ue,{value:e.management,onChange:L=>I({management:L}),items:V,placeholder:T.field.select,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.department}),n.jsx(ue,{value:e.department,onChange:L=>I({department:L}),items:q,placeholder:T.field.select,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.section}),n.jsx("input",{style:{...E,...N},value:e.section_field||"",disabled:v,onChange:L=>I({section_field:L.target.value})})]})]}),n.jsxs("div",{style:gs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.branch}),n.jsx(ue,{value:e.branch,onChange:L=>I({branch:L}),items:ge,placeholder:T.field.select,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.hsesField}),n.jsx("input",{style:{...E,...N},value:e.hses_field||"",disabled:v,onChange:L=>I({hses_field:L.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{style:gs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.type}),n.jsx(ue,{value:e.type,onChange:L=>I({type:L}),items:Ce,placeholder:T.field.selectType,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.title}),n.jsx("input",{style:{...E,...N},value:e.title,disabled:v,onChange:L=>I({title:L.target.value})})]})]}),n.jsxs("div",{style:gs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.incidentClass}),n.jsx(ue,{value:e.incident_class,onChange:L=>I({incident_class:L}),items:se,placeholder:T.field.selectClass,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.incidentField}),n.jsx(ue,{value:e.incident_field,onChange:L=>I({incident_field:L}),items:je,placeholder:T.field.selectField,disabled:v})]})]}),n.jsxs("div",{style:_a,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.date}),n.jsx(xe,{value:e.date,onChange:L=>I({date:L}),disabled:v,style:{...E,...N}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.time}),n.jsx("input",{type:"time",style:{...E,...N},value:e.time,disabled:v,onChange:L=>I({time:L.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.assignedTo}),n.jsxs("select",{style:{...E,...N},value:e.assigned_to,disabled:v,onChange:L=>I({assigned_to:L.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),F.map(L=>n.jsx("option",{value:L.name,children:L.full_name||L.name},L.name))]})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.status}),n.jsx(ue,{value:e.status,onChange:L=>I({status:L}),items:Qe,placeholder:T.field.selectStatus,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.description}),n.jsx("textarea",{style:{...E,...N,height:120,resize:"vertical"},value:e.description,disabled:v,onChange:L=>I({description:L.target.value})})]}),!re&&n.jsxs("div",{style:{background:"#fffbeb",border:"1px solid #fde68a",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#92400e",marginBottom:10},children:T.steps.auditorTriage}),n.jsxs("div",{style:_a,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.priority}),n.jsxs("select",{style:{...E,...v&&!D?{background:"#f9f9f9"}:{}},value:e.priority||"",disabled:v&&!D,onChange:L=>I({priority:L.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),n.jsx("option",{value:"High",children:T.field.high}),n.jsx("option",{value:"Normal",children:T.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.economyClass}),n.jsxs("select",{style:{...E,...v&&!D?{background:"#f9f9f9"}:{}},value:e.economy_class||"",disabled:v&&!D,onChange:L=>I({economy_class:L.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),n.jsx("option",{value:"Expenses",children:T.field.expenses}),n.jsx("option",{value:"Capital",children:T.field.capital}),n.jsx("option",{value:"Earn",children:T.field.earn}),n.jsx("option",{value:"Pay/Loss",children:T.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.entityScope}),n.jsxs("select",{style:{...E,...v&&!D?{background:"#f9f9f9"}:{}},value:e.entity_scope||"",disabled:v&&!D,onChange:L=>I({entity_scope:L.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),n.jsx("option",{value:"Upstream",children:T.field.upstream}),n.jsx("option",{value:"On-stream",children:T.field.onstream}),n.jsx("option",{value:"Downstream",children:T.field.downstream})]})]})]}),n.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center"},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:v&&!D,onChange:L=>I({product_relation:L.target.checked?1:0})})," ",T.field.productRelation]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:v&&!D,onChange:L=>I({repeated:L.target.checked?1:0})})," ",T.field.repeatedEvent]})]})]}),!re&&n.jsxs("div",{style:{background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#1e40af",marginBottom:10},children:T.steps.managerSolution}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.solution}),n.jsx("textarea",{style:{...E,height:100,resize:"vertical",...v&&!le&&!D?{background:"#f9f9f9"}:{}},value:e.solution||"",disabled:v&&!le&&!D,onChange:L=>I({solution:L.target.value}),placeholder:T.field.solutionPlaceholder})]}),n.jsxs("div",{style:gs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.actualCost}),n.jsx("input",{type:"number",style:{...E,...v&&!le&&!D?{background:"#f9f9f9"}:{}},value:e.cost||"",disabled:v&&!le&&!D,onChange:L=>I({cost:parseFloat(L.target.value)||0}),placeholder:"0.00"})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.summary}),n.jsx("input",{style:{...E,...v&&!le&&!D?{background:"#f9f9f9"}:{}},value:e.summary||"",disabled:v&&!le&&!D,onChange:L=>I({summary:L.target.value}),placeholder:"Brief summary"})]})]})]}),!re&&n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:10},children:T.steps.ownerComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...v&&!D?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:v&&!D,onChange:L=>I({auditor_comment:L.target.value}),placeholder:T.field.commentPlaceholder})]})]})}function Qy({ideas:e,organizations:t,departments:l,branches:s,ideaStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=Z(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),w=(o,m)=>v(C=>({...C,[o]:m})),[g,b]=j.useState(1),x=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{b(1)},[c]);const h=x.slice((g-1)*te,g*te);return n.jsxs(n.Fragment,{children:[n.jsx(Mi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.numberTitle}),n.jsx("input",{style:$e,value:c.search,onChange:o=>w("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.organization}),n.jsxs("select",{style:$e,value:c.organization,onChange:o=>w("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.department}),n.jsxs("select",{style:$e,value:c.department,onChange:o=>w("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.branch}),n.jsxs("select",{style:$e,value:c.branch,onChange:o=>w("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.status}),n.jsxs("select",{style:$e,value:c.status,onChange:o=>w("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name))]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:x.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noIdeas})}):h.map((o,m)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Dn(o.status,Fi(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:C=>C.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Ue,{page:g,total:x.length,onPageChange:b})]})}const iu={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Ca={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},Gy={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 Yy(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...Gy[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function Xy({ideaForm:e,setIdeaForm:t,organizations:l,managements:s,departments:r,branches:i,ideaTypes:a,ideaStatuses:d,users:u=[],userRoleMap:f={},formStatus:y,viewMode:p,onEdit:c,darkMode:v,notifCount:w,onToggleDark:g,onCountChange:b,onViewProfile:x,userRole:h,onSubmit:o,onBack:m,onNavigate:C,onLogout:P,user:R,onRefresh:S}){const _=Z(),$=D=>t({...e,...D}),T=p?{background:"#f9f9f9"}:{},I=Kl(u,f,"SB Manager"),[N,F]=j.useState(""),[ne,ee]=j.useState(!1),me=e.name?p?`${_.formTitle.viewIdea}${e.number||e.title||e.name}`:_.formTitle.editIdea:_.formTitle.newIdea,A=fe(s,e.management).map(D=>({name:D.name,label:D.name1||D.name})),Q=fe(r,e.department).map(D=>({name:D.name,label:D.department_name||D.name})),G=fe(i,e.branch).map(D=>({name:D.name,label:D.branch||D.name})),V=fe(a,e.type).map(D=>({name:D.name,label:D.name1||D.name})),q=fe(d,e.status).map(D=>({name:D.name,label:D.name1||D.name})),ge=e.workflow_state||"New",Ce=h==="Employee",se=h==="Auditor"||h==="Admin",je=h==="Manager",Qe=e.name?ge==="New"?[{label:_.wf.submit,action:"Submit",color:"#2563eb"}]:ge==="Initial Evaluation"&&se?[{label:_.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:_.wf.reject,action:"Reject",color:"#dc2626"}]:ge==="Accept & Under Progress"&&(je||se)?[{label:_.wf.submitSolution,action:"Submit Proposal",color:"#059669"}]:ge==="working on proposal"&&se?[{label:_.wf.moveToOutsourcing,action:"Move to Outsourcing",color:"#0369a1"},{label:_.wf.reject,action:"Reject",color:"#dc2626"}]:[]:[];async function H(D){if(e.name){ee(!0),F("");try{const le={};D==="Assign to Manager"&&(e.assigned_to&&(le.assigned_to=e.assigned_to),e.priority&&(le.priority=e.priority),e.economy_class&&(le.economy_class=e.economy_class),e.entity_scope&&(le.entity_scope=e.entity_scope),e.hses_field&&(le.hses_field=e.hses_field),le.product_relation=String(e.product_relation??0),le.repeated=String(e.repeated??0)),D==="Submit Proposal"&&(e.solution&&(le.solution=e.solution),e.proposed_condition&&(le.proposed_condition=e.proposed_condition),e.cost&&(le.cost=String(e.cost))),e.auditor_comment&&(D==="Move to Outsourcing"||D==="Reject")&&(le.auditor_comment=e.auditor_comment),await uy(e.name,D,JSON.stringify(le)),F("Done"),S==null||S()}catch(le){F(le.message||"Error")}finally{ee(!1)}}}const re=e.name?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"#f8fafc",borderRadius:10,padding:16,border:"1px solid #e2e8f0"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[n.jsx("h4",{style:{fontWeight:700,color:"#1e293b",margin:0,fontSize:14},children:_.wf.workflow}),n.jsx("span",{style:Yy(ge),children:ge})]}),ge==="Initial Evaluation"&&se&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:z,children:_.wf.assignToManager}),n.jsxs("select",{style:E,value:e.assigned_to||"",onChange:D=>$({assigned_to:D.target.value}),children:[n.jsx("option",{value:"",children:_.field.selectMgr}),I.map(D=>n.jsx("option",{value:D.name,children:D.full_name||D.name},D.name))]})]}),ge==="Accept & Under Progress"&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:z,children:_.field.solution}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical"},value:e.solution||"",onChange:D=>$({solution:D.target.value}),placeholder:_.field.solutionPlaceholder}),n.jsx("label",{style:{...z,marginTop:8},children:_.field.actualCost}),n.jsx("input",{type:"number",style:E,value:e.cost||"",onChange:D=>$({cost:parseFloat(D.target.value)||0}),placeholder:"0.00"})]}),ge==="working on proposal"&&se&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:z,children:_.field.auditorComment}),n.jsx("textarea",{style:{...E,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:D=>$({auditor_comment:D.target.value}),placeholder:_.field.commentPlaceholder})]}),Qe.length>0?n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:Qe.map(D=>n.jsx("button",{onClick:()=>H(D.action),disabled:ne,style:{padding:"8px 18px",borderRadius:8,border:"none",background:D.color,color:"white",fontWeight:700,cursor:ne?"not-allowed":"pointer",opacity:ne?.7:1},children:ne?_.wf.applying:D.label},D.action))}):n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:_.wf.noActions}),N&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:N==="Done"?U.green:U.red},children:N})]}),n.jsx(Hi,{doctype:B.ideas,docname:e.name,currentUserName:R.name}),n.jsx(Ki,{doctype:B.ideas,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(Fe,{title:me,activePage:"ideas",user:R,formStatus:y,buttonText:_.saveIdea,buttonColor:U.teal,viewMode:p,onEdit:c,darkMode:v,notifCount:w,onToggleDark:g,onCountChange:b,onViewProfile:x,rightPanel:re,onSubmit:o,onBack:m,onNavigate:C,onLogout:P,children:[n.jsxs("div",{style:iu,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.organization}),n.jsx(It,{value:e.organization,onChange:D=>$({organization:D}),organizations:l,disabled:p})]})]}),n.jsxs("div",{style:Ca,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.management}),n.jsx(ue,{value:e.management,onChange:D=>$({management:D}),items:A,placeholder:_.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.department}),n.jsx(ue,{value:e.department,onChange:D=>$({department:D}),items:Q,placeholder:_.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.section}),n.jsx("input",{style:{...E,...T},value:e.section_field||"",disabled:p,onChange:D=>$({section_field:D.target.value})})]})]}),n.jsxs("div",{style:iu,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.branch}),n.jsx(ue,{value:e.branch,onChange:D=>$({branch:D}),items:G,placeholder:_.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.date}),n.jsx(xe,{value:e.date||"",onChange:D=>$({date:D}),disabled:p,style:{...E,...T}})]})]}),n.jsxs("div",{style:Ca,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.type}),n.jsx(ue,{value:e.type,onChange:D=>$({type:D}),items:V,placeholder:_.field.selectType,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.ideaClass}),n.jsxs("select",{style:{...E,...T},value:e.idea_class||"",disabled:p,onChange:D=>$({idea_class:D.target.value}),children:[n.jsx("option",{value:"",children:_.field.select}),n.jsx("option",{value:"Safety",children:"Safety"}),n.jsx("option",{value:"Non-safety",children:"Non-safety"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.hsesField}),n.jsx("input",{style:{...E,...T},value:e.hses_field||"",disabled:p,onChange:D=>$({hses_field:D.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.title}),n.jsx("input",{style:{...E,...T},value:e.title,disabled:p,onChange:D=>$({title:D.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.status}),n.jsx(ue,{value:e.status,onChange:D=>$({status:D}),items:q,placeholder:_.field.selectStatus,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.currentCondition}),n.jsx("textarea",{style:{...E,...T,height:110,resize:"vertical"},value:e.current_condition,disabled:p,onChange:D=>$({current_condition:D.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.proposedCondition}),n.jsx("textarea",{style:{...E,...T,height:110,resize:"vertical"},value:e.proposed_condition,disabled:p,onChange:D=>$({proposed_condition:D.target.value})})]}),!Ce&&n.jsxs("div",{style:{background:"#fffbeb",border:"1px solid #fde68a",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#92400e",marginBottom:10},children:_.steps.auditorEval}),n.jsxs("div",{style:Ca,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.priority}),n.jsxs("select",{style:{...E,...p&&!se?{background:"#f9f9f9"}:{}},value:e.priority||"",disabled:p&&!se,onChange:D=>$({priority:D.target.value}),children:[n.jsx("option",{value:"",children:_.field.select}),n.jsx("option",{value:"High",children:_.field.high}),n.jsx("option",{value:"Normal",children:_.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.economyClass}),n.jsxs("select",{style:{...E,...p&&!se?{background:"#f9f9f9"}:{}},value:e.economy_class||"",disabled:p&&!se,onChange:D=>$({economy_class:D.target.value}),children:[n.jsx("option",{value:"",children:_.field.select}),n.jsx("option",{value:"Expenses",children:_.field.expenses}),n.jsx("option",{value:"Capital",children:_.field.capital}),n.jsx("option",{value:"Earn",children:_.field.earn}),n.jsx("option",{value:"Pay/Loss",children:_.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.entityScope}),n.jsxs("select",{style:{...E,...p&&!se?{background:"#f9f9f9"}:{}},value:e.entity_scope||"",disabled:p&&!se,onChange:D=>$({entity_scope:D.target.value}),children:[n.jsx("option",{value:"",children:_.field.select}),n.jsx("option",{value:"Upstream",children:_.field.upstream}),n.jsx("option",{value:"On-stream",children:_.field.onstream}),n.jsx("option",{value:"Downstream",children:_.field.downstream})]})]})]}),n.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center"},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:p&&!se,onChange:D=>$({product_relation:D.target.checked?1:0})})," ",_.field.productRelation]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:p&&!se,onChange:D=>$({repeated:D.target.checked?1:0})})," ",_.field.repeatedEvent]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:z,children:_.wf.assignToManager}),n.jsxs("select",{style:{...E,...p&&!se?{background:"#f9f9f9"}:{}},value:e.assigned_to||"",disabled:p&&!se,onChange:D=>$({assigned_to:D.target.value}),children:[n.jsx("option",{value:"",children:_.field.select}),I.map(D=>n.jsx("option",{value:D.name,children:D.full_name||D.name},D.name))]})]})]}),!Ce&&n.jsxs("div",{style:{background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#1e40af",marginBottom:10},children:_.steps.managerSolution}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:_.field.solution}),n.jsx("textarea",{style:{...E,height:100,resize:"vertical",...p&&!je&&!se?{background:"#f9f9f9"}:{}},value:e.solution||"",disabled:p&&!je&&!se,onChange:D=>$({solution:D.target.value}),placeholder:_.field.solutionPlaceholder})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:z,children:_.field.actualCost}),n.jsx("input",{type:"number",style:{...E,...p&&!je&&!se?{background:"#f9f9f9"}:{}},value:e.cost||"",disabled:p&&!je&&!se,onChange:D=>$({cost:parseFloat(D.target.value)||0}),placeholder:"0.00"})]})]}),!Ce&&n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:10},children:_.steps.ownerComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...p&&!se?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:p&&!se,onChange:D=>$({auditor_comment:D.target.value}),placeholder:_.field.commentPlaceholder})]})]})}function Jy({orders:e,organizations:t,departments:l,branches:s,orderStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=Z(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),w=(o,m)=>v(C=>({...C,[o]:m})),[g,b]=j.useState(1),x=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{b(1)},[c]);const h=x.slice((g-1)*te,g*te);return n.jsxs(n.Fragment,{children:[n.jsx(Mi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.numberTitle}),n.jsx("input",{style:$e,value:c.search,onChange:o=>w("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.organization}),n.jsxs("select",{style:$e,value:c.organization,onChange:o=>w("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.department}),n.jsxs("select",{style:$e,value:c.department,onChange:o=>w("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.branch}),n.jsxs("select",{style:$e,value:c.branch,onChange:o=>w("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.status}),n.jsxs("select",{style:$e,value:c.status,onChange:o=>w("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name))]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.type}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:x.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noOrders})}):h.map((o,m)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.type?Dn(o.type,"#8e44ad"):"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Dn(o.status,Fi(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:C=>C.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Ue,{page:g,total:x.length,onPageChange:b})]})}const Nr={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Wr={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},qy={1:"Initiation / Bidding",2:"Execution begins",3:"Mid-execution review",4:"Near completion",5:"Closing"},Zy={Draft:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Pending Actor":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},Review:{background:"#f0fdf4",color:"#15803d",border:"1px solid #bbf7d0"},"In Study":{background:"#f1f5f9",color:"#475569",border:"1px solid #cbd5e1"},Closed:{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function Vy(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...Zy[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function e0({orderForm:e,setOrderForm:t,organizations:l,managements:s,departments:r,branches:i,orderTypes:a,orderStatuses:d,cycles:u=[],users:f,userRoleMap:y={},formStatus:p,viewMode:c,onEdit:v,darkMode:w,notifCount:g,onToggleDark:b,onCountChange:x,onViewProfile:h,currentUser:o,userRole:m,onSubmit:C,onBack:P,onNavigate:R,onLogout:S,user:_,onRefresh:$}){var ur;const T=Z(),I=W=>t({...e,...W}),N=c?{background:"#f9f9f9"}:{},F=Kl(f,y,"SB Employee"),[ne,ee]=j.useState(""),[me,A]=j.useState(""),[Q,G]=j.useState(!1),[V,q]=j.useState("Agree"),ge=e.name?c?`${T.formTitle.viewOrder}${e.number||e.title||e.name}`:T.formTitle.editOrder:T.formTitle.newOrder,Ce=fe(s,e.management).map(W=>({name:W.name,label:W.name1||W.name})),se=fe(r,e.department).map(W=>({name:W.name,label:W.department_name||W.name})),je=fe(i,e.branch).map(W=>({name:W.name,label:W.branch||W.name})),Qe=fe(a,e.type).map(W=>({name:W.name,label:W.name1||W.name})),H=fe(d,e.status).map(W=>({name:W.name,label:W.name1||W.name})),re=fe(u,e.cycle).map(W=>({name:W.name,label:W.name1||W.name})),D=!!e.name,le=e.workflow_state||"Draft",wt=Math.min(5,(e.stage||0)+1),[Yt,O]=j.useState(wt);j.useEffect(()=>{O(Math.min(5,(e.stage||0)+1))},[e.stage]);const L=m==="Auditor"||m==="Admin"||m==="Manager",K=L||m==="Owner",Jl=!!(o&&(e.actor===o||e.assigned_to===o)),hn=D?le==="Closed"?[]:le==="Draft"&&L?[{label:"Submit for Review",action:"Submit for Review",color:"#2563eb"}]:le==="Pending Actor"&&(Jl||L)?[{label:"Update Status",action:"Update Status",color:"#d97706"}]:le==="Review"&&K?[{label:"Move to Study",action:"Move to Study",color:"#059669"},{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}]:le==="In Study"&&K?[{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"},{label:"Close Order",action:"Close Order",color:"#475569"}]:[]:[];async function Qi(W){if(e.name){G(!0),ee("");try{let ht;W==="Update Status"&&(ht=V);const $t=await cy(e.name,W,me,W==="Update Status"?String(Yt):void 0,void 0,ht);if(A(""),q("Agree"),ee("Done"),$t){const gn=$t;t({...e,...gn,stage:gn.stage??e.stage,completion_pct:gn.completion_pct??e.completion_pct,workflow_state:gn.workflow_state??e.workflow_state})}$==null||$()}catch(ht){ee(ht.message||"Error")}finally{G(!1)}}}const ll=D?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"#f8fafc",borderRadius:10,padding:16,border:"1px solid #e2e8f0"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[n.jsx("h4",{style:{fontWeight:700,color:"#1e293b",margin:0,fontSize:14},children:T.wf.workflow}),n.jsx("span",{style:Vy(le),children:le})]}),le==="Pending Actor"&&n.jsxs("div",{style:{display:"flex",gap:16,marginBottom:14,flexWrap:"wrap"},children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:["Stage (1–5) — ",Yt*20,"% complete"]}),n.jsx("input",{type:"number",min:1,max:5,style:{...E,maxWidth:80},value:Yt,onChange:W=>O(Math.min(5,Math.max(1,parseInt(W.target.value)||1)))})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Cycle Status"}),n.jsxs("select",{style:{...E,minWidth:140},value:V,onChange:W=>q(W.target.value),children:[n.jsx("option",{value:"Agree",children:"✅ Agree — on track"}),n.jsx("option",{value:"Deviate",children:"⚠️ Deviate — off plan"}),n.jsx("option",{value:"Unknown",children:"❓ Unknown"})]})]})]}),n.jsxs("div",{style:{marginBottom:14},children:[n.jsxs("label",{style:z,children:["Comment ",V==="Deviate"&&le==="Pending Actor"?n.jsx("span",{style:{color:U.red},children:" * required for Deviate"}):"(optional)"]}),n.jsx("textarea",{style:{...E,height:64,resize:"vertical",borderColor:V==="Deviate"&&!me?"#fca5a5":void 0},value:me,onChange:W=>A(W.target.value),placeholder:"Add a comment…"})]}),n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:hn.map(W=>{const ht=W.action==="Update Status"&&V==="Deviate"&&!me.trim();return n.jsx("button",{onClick:()=>Qi(W.action),disabled:Q||ht,title:ht?"Comment required when status is Deviate":void 0,style:{padding:"8px 18px",borderRadius:8,border:"none",background:W.color,color:"white",fontWeight:700,cursor:Q||ht?"not-allowed":"pointer",opacity:Q||ht?.5:1},children:Q?T.wf.applying:W.label},W.action)})}),ne&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:ne==="Done"?U.green:U.red},children:ne}),hn.length===0&&n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:T.wf.noActions})]}),n.jsx(Hi,{doctype:B.orders,docname:e.name,currentUserName:_.name}),n.jsx(Ki,{doctype:B.orders,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(Fe,{title:ge,activePage:"orders",user:_,formStatus:p,buttonText:T.saveOrder,buttonColor:U.purple,viewMode:c,onEdit:v,darkMode:w,notifCount:g,onToggleDark:b,onCountChange:x,onViewProfile:h,rightPanel:ll,onSubmit:C,onBack:P,onNavigate:R,onLogout:S,children:[n.jsxs("div",{style:Nr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.organization}),n.jsx(It,{value:e.organization,onChange:W=>I({organization:W}),organizations:l,disabled:c})]})]}),n.jsxs("div",{style:Wr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.management}),n.jsx(ue,{value:e.management,onChange:W=>I({management:W}),items:Ce,placeholder:T.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.department}),n.jsx(ue,{value:e.department,onChange:W=>I({department:W}),items:se,placeholder:T.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.section}),n.jsx("input",{style:{...E,...N},value:e.section_field||"",disabled:c,onChange:W=>I({section_field:W.target.value})})]})]}),n.jsxs("div",{style:Nr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.branch}),n.jsx(ue,{value:e.branch,onChange:W=>I({branch:W}),items:je,placeholder:T.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.type}),n.jsx(ue,{value:e.type,onChange:W=>I({type:W}),items:Qe,placeholder:T.field.selectType,disabled:c})]})]}),n.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:14,marginTop:4},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#475569",marginBottom:10},children:"Classification"}),n.jsxs("div",{style:Wr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.priority}),n.jsxs("select",{style:{...E,...N},value:e.priority||"",disabled:c,onChange:W=>I({priority:W.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),n.jsx("option",{value:"High",children:T.field.high}),n.jsx("option",{value:"Normal",children:T.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.economyClass}),n.jsxs("select",{style:{...E,...N},value:e.economy_class||"",disabled:c,onChange:W=>I({economy_class:W.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),n.jsx("option",{value:"Expenses",children:T.field.expenses}),n.jsx("option",{value:"Capital",children:T.field.capital}),n.jsx("option",{value:"Earn",children:T.field.earn}),n.jsx("option",{value:"Pay/Loss",children:T.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.entityScope}),n.jsxs("select",{style:{...E,...N},value:e.entity_scope||"",disabled:c,onChange:W=>I({entity_scope:W.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),n.jsx("option",{value:"Upstream",children:T.field.upstream}),n.jsx("option",{value:"On-stream",children:T.field.onstream}),n.jsx("option",{value:"Downstream",children:T.field.downstream})]})]})]}),n.jsxs("div",{style:{display:"flex",gap:24,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.planned,disabled:c,onChange:W=>I({planned:W.target.checked?1:0})})," Planned"]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:W=>I({product_relation:W.target.checked?1:0})})," ",T.field.productRelation]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:z,children:T.field.hsesField}),n.jsx("input",{style:{...E,...N},value:e.hses_field||"",disabled:c,onChange:W=>I({hses_field:W.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.title}),n.jsx("input",{style:{...E,...N},value:e.title,disabled:c,onChange:W=>I({title:W.target.value})})]}),n.jsxs("div",{style:Wr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.budget}),n.jsx("input",{type:"number",style:{...E,...N},value:e.budget||"",disabled:c,onChange:W=>I({budget:parseFloat(W.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.actualCost}),n.jsx("input",{type:"number",style:{...E,...N},value:e.actual_cost||"",disabled:c,onChange:W=>I({actual_cost:parseFloat(W.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Variance"}),(()=>{const W=(e.budget||0)-(e.actual_cost||0);return n.jsxs("span",{style:{display:"inline-block",padding:"6px 12px",borderRadius:8,fontWeight:700,fontSize:13,background:W>=0?"#f0fdf4":"#fef2f2",color:W>=0?"#166534":"#dc2626",border:`1px solid ${W>=0?"#bbf7d0":"#fecaca"}`},children:[W>=0?"+":"",W.toFixed(2)]})})()]})]}),n.jsxs("div",{style:Nr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.currency}),n.jsxs("select",{style:{...E,...N},value:e.currency||"",disabled:c,onChange:W=>I({currency:W.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),n.jsx("option",{value:"SAR",children:"SAR"}),n.jsx("option",{value:"USD",children:"USD"}),n.jsx("option",{value:"EUR",children:"EUR"}),n.jsx("option",{value:"AED",children:"AED"}),n.jsx("option",{value:"GBP",children:"GBP"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.status}),n.jsx(ue,{value:e.status,onChange:W=>I({status:W}),items:H,placeholder:T.field.selectStatus,disabled:c||le==="Closed"})]})]}),n.jsxs("div",{style:Wr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.startingDate}),n.jsx(xe,{value:e.starting_date,onChange:W=>I({starting_date:W}),disabled:c,style:{...E,...N}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.endingDate}),n.jsx(xe,{value:e.ending_date,onChange:W=>I({ending_date:W}),disabled:c,style:{...E,...N}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.actor}),n.jsxs("select",{style:{...E,...N},value:e.actor||e.assigned_to||"",disabled:c,onChange:W=>I({actor:W.target.value,assigned_to:W.target.value}),children:[n.jsx("option",{value:"",children:T.field.select}),F.map(W=>n.jsx("option",{value:W.name,children:W.full_name||W.name},W.name))]})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",fontSize:13,marginBottom:12},children:"Cycle & Progress"}),n.jsxs("div",{style:Nr,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.cycle}),n.jsx(ue,{value:e.cycle||"",onChange:W=>I({cycle:W}),items:re,placeholder:T.field.select,disabled:c})]}),n.jsxs("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.stage}),n.jsx("input",{type:"number",min:1,max:5,style:{...E,background:"#f9f9f9",maxWidth:80},value:e.stage||1,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Completion"}),n.jsx("input",{style:{...E,background:"#f9f9f9",maxWidth:100},value:`${e.completion_pct||(e.stage||1)*20}%`,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Stage Description"}),n.jsx("span",{style:{display:"inline-block",padding:"6px 12px",borderRadius:8,fontSize:13,fontWeight:600,background:"#f0f9ff",color:"#0369a1",border:"1px solid #bae6fd"},children:qy[e.stage||1]||"—"})]}),(e.escalation_level??0)>0&&n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.escalationLevel}),n.jsxs("span",{style:{display:"inline-block",padding:"6px 12px",background:"#fecaca",color:"#e74c3c",borderRadius:8,fontWeight:700,fontSize:13},children:["Level ",e.escalation_level]})]})]})]})]}),D&&((ur=e.order_cycle_log)==null?void 0:ur.length)>0&&n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",fontSize:13,marginBottom:10},children:"Cycle History"}),n.jsx("div",{style:{overflowX:"auto"},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8fafc"},children:["Cycle","Date","Stage","Status","Actor","Comment"].map(W=>n.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:600,color:"#475569",borderBottom:"1px solid #e2e8f0"},children:W},W))})}),n.jsx("tbody",{children:(e.order_cycle_log||[]).map((W,ht)=>{const $t=W.status==="Agree"?"#166534":W.status==="Deviate"?"#c2410c":"#92400e",gn=W.status==="Agree"?"#f0fdf4":W.status==="Deviate"?"#fff7ed":"#fefce8";return n.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:W.cycle||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:W.cycle_date||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155",textAlign:"center"},children:W.stage||"—"}),n.jsx("td",{style:{padding:"6px 10px"},children:n.jsx("span",{style:{background:gn,color:$t,padding:"2px 8px",borderRadius:12,fontWeight:600,fontSize:12},children:W.status||"—"})}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:W.actor||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#64748b",fontStyle:W.comment?"normal":"italic"},children:W.comment||"—"})]},ht)})})]})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.description}),n.jsx("textarea",{style:{...E,...N,height:100,resize:"vertical"},value:e.description,disabled:c,onChange:W=>I({description:W.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:T.field.notes}),n.jsx("textarea",{style:{...E,...N,height:100,resize:"vertical"},value:e.notes,disabled:c,onChange:W=>I({notes:W.target.value})})]}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:4},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:8},children:T.field.auditorComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...c&&Jl&&!L?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:c&&Jl&&!L,onChange:W=>I({auditor_comment:W.target.value}),placeholder:T.field.commentPlaceholder})]})]})}function t0({processes:e,organizations:t,departments:l,branches:s,processStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=Z(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),w=(o,m)=>v(C=>({...C,[o]:m})),[g,b]=j.useState(1),x=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{b(1)},[c]);const h=x.slice((g-1)*te,g*te);return n.jsxs(n.Fragment,{children:[n.jsx(Mi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.numberTitle}),n.jsx("input",{style:$e,value:c.search,onChange:o=>w("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.organization}),n.jsxs("select",{style:$e,value:c.organization,onChange:o=>w("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.department}),n.jsxs("select",{style:$e,value:c.department,onChange:o=>w("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.branch}),n.jsxs("select",{style:$e,value:c.branch,onChange:o=>w("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Be,children:p.filter.status}),n.jsxs("select",{style:$e,value:c.status,onChange:o=>w("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name)),n.jsx("option",{value:"Closed",children:"Closed"})]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.field.cycleType}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:x.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noProcesses})}):h.map((o,m)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||o.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.cycle_type?Dn(o.cycle_type,"#8e44ad"):"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Dn(o.status,Fi(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:C=>C.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Ue,{page:g,total:x.length,onPageChange:b})]})}const n0={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"]}],"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"},Closed:{background:"#f3f4f6",color:"#6b7280",border:"1px solid #9ca3af"}};function au(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 Br={width:"100%",padding:"6px 8px",border:"1px solid #d1d5db",borderRadius:5,fontSize:12,fontFamily:"Segoe UI",boxSizing:"border-box"};function s0({processName:e,userRole:t,onRefresh:l,canUpdateStatus:s=!0}){const[r,i]=j.useState(null),[a,d]=j.useState(!0),[u,f]=j.useState(""),[y,p]=j.useState(!1),[c,v]=j.useState(""),[w,g]=j.useState(""),[b,x]=j.useState("Pass"),[h,o]=j.useState(""),[m,C]=j.useState({}),P=j.useCallback(async()=>{if(!e){d(!1);return}d(!0),f("");try{const N=await Es(e);i(N);const F={};for(const ne of N.progress_indicators||[])F[ne.name]=ne.actual_value!=null?String(ne.actual_value):"";C(F)}catch(N){f(N instanceof Error?N.message:"Failed to load process")}d(!1)},[e]);if(j.useEffect(()=>{P()},[P]),a)return n.jsx("div",{style:{width:260,flexShrink:0},children:n.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(u||!r)return n.jsx("div",{style:{width:260,flexShrink:0},children:n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:16},children:n.jsx("div",{style:{fontSize:12,color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px"},children:u||"Could not load workflow"})})});const R=r.workflow_state||"Draft",S=n0[R]??[],_=t==="Employee"||t==="Manager",$=t!=="Manager"||s,T=S.filter(N=>(t==="Admin"||N.allowedRoles.includes(t))&&(N.action!=="Update Status"||$)),I=async N=>{p(!0),v(""),g("");try{const F={};if(N==="Update Status"){F.actor_status=b,F.actor_comment=h;const ee=r.progress_indicators||[];ee.length>0&&(F.progress_indicators=ee.map(me=>({name:me.name,actual_value:m[me.name]??""})))}N==="Add Comment"&&h&&(F.actor_comment=h);const ne=await wy(r.name,N,F);i(ne),o(""),g(`Done — now: ${ne.workflow_state||"updated"}`),l==null||l()}catch(F){v(F instanceof Error?F.message:"Action failed")}p(!1)};return n.jsx("div",{style:{width:260,flexShrink:0},children:n.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[n.jsx("div",{style:{background:"#1a2332",color:"white",padding:"10px 14px",fontSize:12,fontWeight:700,letterSpacing:.3},children:"Workflow"}),n.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:8},children:"Current State"}),n.jsx("div",{style:au(R),children:R})]}),R==="Pending Actor"&&_&&$&&n.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Update Status"}),Array.isArray(r.progress_indicators)&&r.progress_indicators.length>0&&n.jsxs("div",{style:{marginBottom:10},children:[n.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Actual Value"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.progress_indicators.map(N=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("span",{style:{fontSize:11,color:"#555",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:N.name1,children:N.name1||N.name}),n.jsx("input",{type:"number",value:m[N.name]??"",onChange:F=>C(ne=>({...ne,[N.name]:F.target.value})),style:{...Br,width:70,flexShrink:0},placeholder:"0"})]},N.name))})]}),n.jsxs("div",{style:{marginBottom:8},children:[n.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Cycle Status"}),n.jsxs("select",{value:b,onChange:N=>x(N.target.value),style:Br,children:[n.jsx("option",{value:"Pass",children:"✅ Pass — on target"}),n.jsx("option",{value:"Fail",children:"❌ Fail — off target"})]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Comment (optional)"}),n.jsx("textarea",{value:h,onChange:N=>o(N.target.value),style:{...Br,height:52,resize:"vertical"},placeholder:"Add a comment…"})]})]}),(R==="Pending Comment"||R==="Review")&&!_&&n.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Auditor Comment"}),Array.isArray(r.cycle_logs)&&r.cycle_logs.length>0&&n.jsxs("div",{style:{marginBottom:8,padding:"6px 10px",background:"#f8fafc",borderRadius:6,border:"1px solid #e2e8f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",marginBottom:3},children:"Latest cycle status:"}),(()=>{const N=r.cycle_logs,F=N[N.length-1],ne=F.status==="Pass"?"#16a34a":F.status==="Fail"?"#dc2626":"#9ca3af";return n.jsxs("div",{style:{fontSize:13,fontWeight:700,color:ne},children:[F.status," ",F.comment?`— ${F.comment}`:""]})})()]}),n.jsx("textarea",{value:h,onChange:N=>o(N.target.value),style:{...Br,height:52,resize:"vertical"},placeholder:"Add a comment…"})]}),n.jsxs("div",{style:{padding:"12px 14px",borderBottom:T.length>0?"1px solid #f0f0f0":"none"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Actions"}),T.length===0&&n.jsxs("div",{style:{fontSize:12,color:"#aaa",fontStyle:"italic",lineHeight:1.5},children:["No actions for ",n.jsx("strong",{children:t})," in ",n.jsx("strong",{children:R}),"."]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:T.map(N=>n.jsxs("button",{onClick:()=>I(N.action),disabled:y,style:{width:"100%",padding:"10px 14px",borderRadius:6,border:"none",background:N.action==="Close Process"?"#64748b":N.action==="Move to Study"?"#8e44ad":"#2563eb",color:"white",cursor:y?"not-allowed":"pointer",fontSize:13,fontWeight:600,opacity:y?.7:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsx("span",{children:y?"Applying…":N.action}),n.jsxs("span",{style:{fontSize:10,opacity:.7},children:["→ ",N.next]})]},N.action))}),c&&n.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,fontSize:12,color:"#991b1b",lineHeight:1.4},children:c}),w&&n.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,fontSize:12,color:"#166534"},children:w})]}),S.length>0&&n.jsxs("div",{style:{padding:"12px 14px"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Next States"}),S.map(N=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6,fontSize:11},children:[n.jsx("span",{style:{color:"#555",flex:1},children:N.action}),n.jsx("span",{style:{color:"#bbb"},children:"→"}),n.jsx("span",{style:au(N.next),children:N.next})]},N.action))]})]})})}const $r={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:16},fl={display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:16};function r0({processForm:e,setProcessForm:t,organizations:l,managements:s,departments:r,branches:i,processTypes:a,processStatuses:d,cycles:u=[],users:f=[],userRoleMap:y={},formStatus:p,viewMode:c,onEdit:v,darkMode:w,notifCount:g,onToggleDark:b,onCountChange:x,onViewProfile:h,userRole:o,delegatedFunctions:m=[],delegatedOrgs:C=null,onRefreshProcess:P,onSubmit:R,onBack:S,onNavigate:_,onLogout:$,user:T}){const I=Z(),N=O=>t({...e,...O}),F=c?{background:"#f9f9f9"}:{},ne=!c&&o==="Manager"&&Array.isArray(C),ee=ne?l.filter(O=>(C||[]).includes(O.organization_name||O.name)):l,me=ne&&(C||[]).length===1,A=fe(s,e.management).map(O=>({name:O.name,label:O.name1||O.name})),Q=fe(r,e.department).map(O=>({name:O.name,label:O.department_name||O.name})),G=fe(i,e.branch).map(O=>({name:O.name,label:O.branch||O.name})),V=fe(a,e.type).map(O=>({name:O.name,label:O.name1||O.name})),q=fe(d,e.status).map(O=>({name:O.name,label:O.name1||O.name})),ge=fe(u,e.cycle).map(O=>({name:O.name,label:O.name1||O.name})),Ce=Kl(f,y,"SB Employee").map(O=>({name:O.name,label:O.full_name||O.name})),se=(O,L)=>{const K=[...e.cycle_logs||[]];K[O]={...K[O],...L},N({cycle_logs:K})},je=()=>{N({cycle_logs:[...e.cycle_logs||[],{cycle:"",cycle_date:"",status:"Pass",actor:"",comment:""}]})},Qe=O=>{const L=[...e.cycle_logs||[]];L.splice(O,1),N({cycle_logs:L})},H=(O,L)=>{const K=[...e.progress_indicators||[]];K[O]={...K[O],...L},N({progress_indicators:K})},re=()=>{N({progress_indicators:[...e.progress_indicators||[],{name1:"",type:"Nominal",unit:"",cycle:"",target:"",maximum:"",minimum:"",manager:"",order:"",actual_value:"",cycle_status:"",cycle_date:"",cycle_comment:"",status:""}]})},D=O=>{const L=[...e.progress_indicators||[]];L.splice(O,1),N({progress_indicators:L})},le=e.name?c?`${I.formTitle.viewProcess}${e.title||e.name}`:I.formTitle.editProcess:I.formTitle.newProcess,wt=o!=="Manager"||e.actor===T.name||m.includes("update_process_status"),Yt=e.name?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsx(s0,{processName:e.name,userRole:o||T.role||"Employee",onRefresh:P,canUpdateStatus:wt}),n.jsx(Hi,{doctype:B.processes,docname:e.name,currentUserName:T.name}),n.jsx(Ki,{doctype:B.processes,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):void 0;return n.jsxs(Fe,{title:le,activePage:"processes",user:T,formStatus:p,buttonText:I.saveProcess,buttonColor:U.blue,viewMode:c,onEdit:v,darkMode:w,notifCount:g,onToggleDark:b,onCountChange:x,onViewProfile:h,rightPanel:Yt,onSubmit:R,onBack:S,onNavigate:_,onLogout:$,children:[n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number||"",readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.organization}),n.jsx(It,{value:e.organization,onChange:O=>N({organization:O}),organizations:ee,disabled:c||me}),ne&&n.jsx("div",{style:{fontSize:11,color:"#888",marginTop:4},children:(C||[]).length===0?"You have no delegated organization for Processes.":`Restricted to your delegated organization${(C||[]).length>1?"s":""}: ${(C||[]).join(", ")}`})]})]}),n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.title}),n.jsx("input",{style:{...E,...F},value:e.title,disabled:c,onChange:O=>N({title:O.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.type}),n.jsx(ue,{value:e.type,onChange:O=>N({type:O}),items:V,placeholder:I.field.selectType,disabled:c})]})]}),n.jsxs("div",{style:fl,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.management}),n.jsx(ue,{value:e.management,onChange:O=>N({management:O}),items:A,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.department}),n.jsx(ue,{value:e.department,onChange:O=>N({department:O}),items:Q,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.section}),n.jsx("input",{style:{...E,...F},value:e.section_field||"",disabled:c,onChange:O=>N({section_field:O.target.value})})]})]}),n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.branch}),n.jsx(ue,{value:e.branch,onChange:O=>N({branch:O}),items:G,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[I.field.status," ",n.jsx("span",{style:{fontSize:11,color:"#9ca3af",fontWeight:400},children:"(auto-updated from cycle)"})]}),n.jsx(ue,{value:e.status,onChange:O=>N({status:O}),items:q,placeholder:I.field.selectStatus,disabled:c})]})]}),n.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:14},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#475569",marginBottom:10},children:"Classification"}),n.jsxs("div",{style:fl,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.chainLocation}),n.jsxs("select",{style:{...E,...F},value:e.chain_location||"",disabled:c,onChange:O=>N({chain_location:O.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Upstream",children:"Upstream"}),n.jsx("option",{value:"On-stream",children:"On-stream"}),n.jsx("option",{value:"Downstream",children:"Downstream"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.economyClass}),n.jsxs("select",{style:{...E,...F},value:e.economy_class||"",disabled:c,onChange:O=>N({economy_class:O.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Expenses",children:I.field.expenses}),n.jsx("option",{value:"Capital",children:I.field.capital}),n.jsx("option",{value:"Earn",children:I.field.earn}),n.jsx("option",{value:"Pay/Loss",children:I.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.impactLevel}),n.jsxs("select",{style:{...E,...F},value:e.impact_level||"",disabled:c,onChange:O=>N({impact_level:O.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"High",children:I.field.high}),n.jsx("option",{value:"Normal",children:I.field.normal})]})]})]}),n.jsxs("div",{style:fl,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.entityScope}),n.jsxs("select",{style:{...E,...F},value:e.entity_scope||"",disabled:c,onChange:O=>N({entity_scope:O.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Upstream",children:I.field.upstream}),n.jsx("option",{value:"On-stream",children:I.field.onstream}),n.jsx("option",{value:"Downstream",children:I.field.downstream})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.hsesField}),n.jsx("input",{style:{...E,...F},value:e.hses_field||"",disabled:c,onChange:O=>N({hses_field:O.target.value}),placeholder:"Safety, Health, Environment…"})]}),n.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,paddingTop:22},children:n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:O=>N({product_relation:O.target.checked?1:0})})," ",I.field.productRelation]})})]})]}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:14},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:10},children:"KPI"}),n.jsxs("div",{style:fl,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.kpiName}),n.jsx("input",{style:{...E,...F},value:e.kpi_name||"",disabled:c,onChange:O=>N({kpi_name:O.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.kpiType}),n.jsxs("select",{style:{...E,...F},value:e.kpi_type||"",disabled:c,onChange:O=>N({kpi_type:O.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Human",children:"Human"}),n.jsx("option",{value:"Substantial",children:"Substantial"}),n.jsx("option",{value:"System",children:"System"}),n.jsx("option",{value:"Value",children:"Value"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.kpiMeasure}),n.jsx("input",{style:{...E,...F},value:e.kpi_measure||"",disabled:c,onChange:O=>N({kpi_measure:O.target.value}),placeholder:"Unit of measure"})]})]})]}),n.jsxs("div",{style:fl,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.dateStart}),n.jsx(xe,{value:e.date_start,onChange:O=>N({date_start:O}),disabled:c,style:{...E,...F}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.dateEnd}),n.jsx(xe,{value:e.date_end,onChange:O=>N({date_end:O}),disabled:c,style:{...E,...F}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.cycleType}),n.jsxs("select",{style:{...E,...F},value:e.cycle_type||"",disabled:c,onChange:O=>N({cycle_type:O.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Normal",children:"Normal"}),n.jsx("option",{value:"Long",children:"Long"})]})]})]}),e.cycle_type==="Long"&&n.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Milestone 1"}),n.jsx(xe,{value:e.long_cycle_date_1||"",onChange:O=>N({long_cycle_date_1:O}),disabled:c,style:{...E,...F}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Milestone 2"}),n.jsx(xe,{value:e.long_cycle_date_2||"",onChange:O=>N({long_cycle_date_2:O}),disabled:c,style:{...E,...F}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Milestone 3"}),n.jsx(xe,{value:e.long_cycle_date_3||"",onChange:O=>N({long_cycle_date_3:O}),disabled:c,style:{...E,...F}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:"Milestone 4"}),n.jsx(xe,{value:e.long_cycle_date_4||"",onChange:O=>N({long_cycle_date_4:O}),disabled:c,style:{...E,...F}})]})]})]}),n.jsxs("div",{style:{marginTop:24,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[n.jsx("div",{style:{...z,margin:0,fontSize:15},children:"Progress Indicators"}),!c&&n.jsx("button",{type:"button",onClick:re,style:{padding:"8px 14px",border:"1px solid #3498db",background:"#3498db",color:"white",borderRadius:6,cursor:"pointer"},children:"Add row"})]}),n.jsx("div",{style:{overflowX:"auto",minWidth:0},children:n.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa"},children:[n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Order"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Name"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Type"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Unit"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Target"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Min"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Max"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Manager"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actual Value"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle Status"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle Date"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle Comment"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Status"}),!c&&n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actions"})]})}),n.jsxs("tbody",{children:[(e.progress_indicators||[]).length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:c?14:15,style:{padding:18,textAlign:"center",color:"#aaa"},children:"No progress indicators"})}),(e.progress_indicators||[]).map((O,L)=>n.jsxs("tr",{style:{background:L%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F,width:60},value:O.order??"",disabled:c,onChange:K=>H(L,{order:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F},value:O.name1,disabled:c,onChange:K=>H(L,{name1:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...F},value:O.type,disabled:c,onChange:K=>H(L,{type:K.target.value}),children:[n.jsx("option",{children:"Nominal"}),n.jsx("option",{children:"Ordinal"}),n.jsx("option",{children:"Interval"}),n.jsx("option",{children:"Ratio"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F,width:70},type:"number",value:O.unit??"",disabled:c,onChange:K=>H(L,{unit:parseFloat(K.target.value)||""})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F},value:O.cycle,disabled:c,onChange:K=>H(L,{cycle:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F,width:80},value:O.target,disabled:c,onChange:K=>H(L,{target:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F,width:80},value:O.minimum,disabled:c,onChange:K=>H(L,{minimum:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F,width:80},value:O.maximum,disabled:c,onChange:K=>H(L,{maximum:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F},value:O.manager,disabled:c,onChange:K=>H(L,{manager:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F,width:90},type:"number",value:O.actual_value??"",disabled:c,onChange:K=>H(L,{actual_value:parseFloat(K.target.value)||""})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...F},value:O.cycle_status??"",disabled:c,onChange:K=>H(L,{cycle_status:K.target.value}),children:[n.jsx("option",{value:"",children:"--"}),n.jsx("option",{children:"Normal"}),n.jsx("option",{children:"Below Min"}),n.jsx("option",{children:"Above Max"}),n.jsx("option",{children:"At Risk"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx(xe,{value:O.cycle_date||"",onChange:K=>H(L,{cycle_date:K}),disabled:c,style:{...E,...F,width:110}})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F},value:O.cycle_comment??"",disabled:c,onChange:K=>H(L,{cycle_comment:K.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...F},value:O.status??"",disabled:c,onChange:K=>H(L,{status:K.target.value}),children:[n.jsx("option",{value:"",children:"--"}),n.jsx("option",{children:"Normal"}),n.jsx("option",{children:"Below Min"}),n.jsx("option",{children:"Above Max"}),n.jsx("option",{children:"At Risk"})]})}),!c&&n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("button",{type:"button",onClick:()=>D(L),style:{padding:"6px 10px",border:"1px solid #e74c3c",background:"white",color:"#e74c3c",borderRadius:6,cursor:"pointer"},children:"Remove"})})]},L))]})]})})]}),n.jsxs("div",{style:{marginTop:28,borderTop:"1px solid #e9ecef",paddingTop:20},children:[n.jsx("div",{style:{...z,fontSize:15,marginBottom:14},children:"Cycle & Assignment"}),n.jsxs("div",{style:fl,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.cycle}),n.jsx(ue,{value:e.cycle||"",onChange:O=>N({cycle:O}),items:ge,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.actor}),n.jsxs("select",{style:{...E,...F},value:e.actor||"",disabled:c,onChange:O=>N({actor:O.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),Ce.map(O=>n.jsx("option",{value:O.name,children:O.label},O.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:I.field.costPerCycle}),n.jsx("input",{style:{...E,...F},type:"number",value:e.cost_per_cycle||"",disabled:c,onChange:O=>N({cost_per_cycle:parseFloat(O.target.value)||0}),placeholder:"0.00"})]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:z,children:I.field.escalationLevel}),n.jsx("input",{style:{...E,...F,maxWidth:120},type:"number",value:e.escalation_level||"",disabled:c,onChange:O=>N({escalation_level:parseInt(O.target.value)||0})})]})]}),n.jsxs("div",{style:{marginTop:28,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[n.jsx("div",{style:{...z,margin:0,fontSize:15},children:"Cycle History"}),!c&&n.jsx("button",{type:"button",onClick:je,style:{padding:"8px 14px",border:"1px solid #3498db",background:"#3498db",color:"white",borderRadius:6,cursor:"pointer"},children:"Add row"})]}),n.jsx("div",{style:{overflowX:"auto",minWidth:0},children:n.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa"},children:[n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Date"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Status"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actor"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Comment"}),!c&&n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actions"})]})}),n.jsxs("tbody",{children:[(e.cycle_logs||[]).length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:c?5:6,style:{padding:18,textAlign:"center",color:"#aaa"},children:"No cycle history"})}),(e.cycle_logs||[]).map((O,L)=>n.jsxs("tr",{style:{background:L%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...F},value:O.cycle||"",disabled:c,onChange:K=>se(L,{cycle:K.target.value}),children:[n.jsx("option",{value:"",children:"-- Select --"}),ge.map(K=>n.jsx("option",{value:K.name,children:K.label},K.name))]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx(xe,{value:O.cycle_date||"",onChange:K=>se(L,{cycle_date:K}),disabled:c,style:{...E,...F,width:130}})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...F},value:O.status,disabled:c,onChange:K=>se(L,{status:K.target.value}),children:[n.jsx("option",{value:"Pass",children:"Pass"}),n.jsx("option",{value:"Fail",children:"Fail"}),n.jsx("option",{value:"Unknown",children:"Unknown"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...F},value:O.actor||"",disabled:c,onChange:K=>se(L,{actor:K.target.value}),children:[n.jsx("option",{value:"",children:"-- Select --"}),Ce.map(K=>n.jsx("option",{value:K.name,children:K.label},K.name))]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...F},value:O.comment||"",disabled:c,onChange:K=>se(L,{comment:K.target.value})})}),!c&&n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("button",{type:"button",onClick:()=>Qe(L),style:{padding:"6px 10px",border:"1px solid #e74c3c",background:"white",color:"#e74c3c",borderRadius:6,cursor:"pointer"},children:"Remove"})})]},L))]})]})})]}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:16},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:8},children:I.field.auditorComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...c?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:c,onChange:O=>N({auditor_comment:O.target.value}),placeholder:I.field.commentPlaceholder})]})]})}const i0={Admin:"#7c3aed",Auditor:"#d97706",Owner:"#0369a1",XAuditor:"#0f766e",Manager:"#2563eb",Employee:"#6b7280",Chairman:"#0f766e"};function a0({user:e,profileUser:t,darkMode:l,canModify:s,onBack:r,organizations:i=[],managements:a=[],departments:d=[],branches:u=[]}){const f=t||{},y=!!s&&e.role==="Admin",[p,c]=j.useState({first_name:f.first_name||"",middle_name:f.middle_name||"",last_name:f.last_name||"",mobile_no:f.mobile_no||"",custom_organization:f.custom_organization||"",custom_management:f.custom_management||"",custom_department:f.custom_department||"",custom_branch:f.custom_branch||"",custom_number:f.custom_number||"",custom_category:f.custom_category||""}),[v,w]=j.useState(""),[g,b]=j.useState(!1),[x,h]=j.useState({new:"",confirm:""}),[o,m]=j.useState(""),C=f.email||f.name||"",P=[p.first_name,p.middle_name,p.last_name].filter(Boolean).join(" ")||f.full_name||"",R=f.username||f.name||"",S=p.custom_category||"",_=f.enabled===0?"Inactive":"Active",$=i0[e.role]||"#6b7280",T=l,I=T?"#0f172a":"#f0f2f5",N=T?"#1e293b":"white",F=T?"#2d3748":"#e5e7eb",ne=T?"#e2e8f0":"#1a2332",ee=T?"#94a3b8":"#6b7280",me=T?"#374151":"white",A=T?"#2d3748":"#f9fafb",Q={width:"100%",padding:"9px 12px",borderRadius:8,border:`1px solid ${F}`,fontSize:13,background:me,color:ne,fontFamily:"inherit",outline:"none"},G={...Q,background:A,color:ee},V={...Q,cursor:"pointer"},q={fontSize:12,fontWeight:600,color:ee,marginBottom:5,display:"block"},ge={display:"grid",gridTemplateColumns:"1fr 1fr",gap:14},Ce={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:14},se=async()=>{if(s){w("saving");try{await _i("User",f.name,{first_name:p.first_name,middle_name:p.middle_name,last_name:p.last_name,mobile_no:p.mobile_no,custom_organization:p.custom_organization,custom_management:p.custom_management,custom_department:p.custom_department,custom_branch:p.custom_branch,custom_number:p.custom_number,custom_category:p.custom_category}),w("saved"),setTimeout(()=>w(""),2e3)}catch{w("error"),setTimeout(()=>w(""),3e3)}}},je=async()=>{if(!x.new){m("Enter a new password");return}if(x.new!==x.confirm){m("Passwords do not match");return}m("saving");try{await Df(f.name,x.new),m("done"),h({new:"",confirm:""}),setTimeout(()=>{m(""),b(!1)},2e3)}catch{m("error")}},Qe=({title:H,icon:re,children:D})=>n.jsxs("div",{style:{background:N,borderRadius:12,padding:22,border:`1px solid ${F}`,boxShadow:`0 1px 4px rgba(0,0,0,${T?.3:.06})`},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:18,paddingBottom:14,borderBottom:`1px solid ${F}`},children:[re,n.jsx("span",{style:{fontSize:14,fontWeight:700,color:ne},children:H})]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:14},children:D})]});return n.jsxs("div",{style:{background:I,minHeight:"100%",padding:"0 0 32px"},children:[n.jsxs("div",{style:{background:N,borderBottom:`1px solid ${F}`,padding:"12px 28px",display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[n.jsxs("button",{onClick:r,style:{display:"flex",alignItems:"center",gap:7,background:"none",border:"none",cursor:"pointer",fontSize:15,fontWeight:700,color:ne,fontFamily:"inherit"},children:[n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polyline",{points:"15,18 9,12 15,6"})}),"User Profile"]}),s&&n.jsxs("button",{onClick:se,style:{display:"flex",alignItems:"center",gap:8,background:v==="saved"?"#16a34a":v==="error"?"#dc2626":"#16a34a",color:"white",border:"none",borderRadius:8,padding:"9px 22px",fontSize:13,fontWeight:700,cursor:"pointer",fontFamily:"inherit"},children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),n.jsx("polyline",{points:"17,21 17,13 7,13 7,21"}),n.jsx("polyline",{points:"7,3 7,8 15,8"})]}),v==="saving"?"Saving…":v==="saved"?"Saved!":v==="error"?"Error":"Save Changes"]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"280px 1fr",gap:22,padding:"0 28px"},children:[n.jsxs("div",{style:{borderRadius:14,overflow:"hidden",boxShadow:"0 4px 20px rgba(0,0,0,0.12)",alignSelf:"start"},children:[n.jsxs("div",{style:{background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",padding:"32px 20px 28px",display:"flex",flexDirection:"column",alignItems:"center",gap:6},children:[n.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:n.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"rgba(255,255,255,0.9)",children:[n.jsx("circle",{cx:"12",cy:"8",r:"4"}),n.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]})}),n.jsx("div",{style:{fontSize:17,fontWeight:700,color:"white",textAlign:"center",lineHeight:1.3},children:P||C}),n.jsx("div",{style:{fontSize:12,color:"rgba(255,255,255,0.75)",textAlign:"center"},children:C})]}),n.jsx("div",{style:{background:N},children:[{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),n.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),n.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),n.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),label:"Username",value:R},{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),label:"Role Profile",value:S||"—"},{icon:n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:_==="Active"?"#16a34a":"#dc2626",strokeWidth:"2",strokeLinecap:"round",children:n.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),label:"Status",value:_,valueColor:_==="Active"?"#16a34a":"#dc2626"},{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),n.jsx("path",{d:"m2 7 10 7 10-7"})]}),label:"Email",value:C},{icon:n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:n.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:p.mobile_no||"—"}].map(({icon:H,label:re,value:D,valueColor:le})=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 16px",borderBottom:`1px solid ${F}`},children:[n.jsx("div",{style:{flexShrink:0,width:18,display:"flex",justifyContent:"center"},children:H}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:11,color:ee,marginBottom:1},children:re}),n.jsx("div",{style:{fontSize:13,fontWeight:600,color:le||ne,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:D})]})]},re))})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:18},children:[n.jsxs(Qe,{title:"Basic Information",icon:n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("circle",{cx:"12",cy:"8",r:"4"}),n.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]}),children:[n.jsxs("div",{style:ge,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Email ",n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Read-only)"})]}),n.jsxs("div",{style:{position:"relative"},children:[n.jsx("div",{style:{position:"absolute",left:11,top:"50%",transform:"translateY(-50%)"},children:n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#94a3b8",strokeWidth:"2",children:[n.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),n.jsx("path",{d:"m2 7 10 7 10-7"})]})}),n.jsx("input",{style:{...G,paddingLeft:32},value:C,readOnly:!0})]})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Full Name ",n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Auto-generated)"})]}),n.jsx("input",{style:G,value:P,readOnly:!0})]})]}),n.jsxs("div",{style:Ce,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["First Name ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{style:s?Q:G,value:p.first_name,readOnly:!s,onChange:H=>c(re=>({...re,first_name:H.target.value})),placeholder:"First name"})]}),n.jsxs("div",{children:[n.jsx("label",{style:q,children:"Middle Name"}),n.jsx("input",{style:s?Q:G,value:p.middle_name,readOnly:!s,onChange:H=>c(re=>({...re,middle_name:H.target.value})),placeholder:"Middle name"})]}),n.jsxs("div",{children:[n.jsx("label",{style:q,children:"Last Name"}),n.jsx("input",{style:s?Q:G,value:p.last_name,readOnly:!s,onChange:H=>c(re=>({...re,last_name:H.target.value})),placeholder:"Last name"})]})]}),n.jsxs("div",{style:ge,children:[n.jsxs("div",{children:[n.jsx("label",{style:q,children:"Phone Number"}),n.jsx("input",{style:s?Q:G,value:p.mobile_no,readOnly:!s,onChange:H=>c(re=>({...re,mobile_no:H.target.value})),placeholder:"Phone number"})]}),n.jsxs("div",{children:[n.jsx("label",{style:q,children:"User ID No"}),n.jsxs("div",{style:{position:"relative"},children:[n.jsx("input",{style:{...G,paddingRight:44},value:p.custom_number||f.name||"",readOnly:!0}),n.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:n.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"white",children:[n.jsx("circle",{cx:"5",cy:"12",r:"2"}),n.jsx("circle",{cx:"12",cy:"12",r:"2"}),n.jsx("circle",{cx:"19",cy:"12",r:"2"})]})})]})]})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Category ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:V,value:p.custom_category,onChange:H=>c(re=>({...re,custom_category:H.target.value})),children:[n.jsx("option",{value:"",children:"Select category"}),["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"].map(H=>n.jsx("option",{value:H,children:H},H))]}):n.jsx("input",{style:G,value:S||"—",readOnly:!0})]})]}),n.jsxs(Qe,{title:"Organization Information",icon:n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#8b5cf6",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),n.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),children:[n.jsxs("div",{style:ge,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Organization ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:V,value:p.custom_organization,onChange:H=>c(re=>({...re,custom_organization:H.target.value})),children:[n.jsx("option",{value:"",children:"Select organization"}),fe(i,p.custom_organization).map(H=>n.jsx("option",{value:H.name,children:H.organization_name||H.name},H.name))]}):n.jsx("input",{style:G,value:p.custom_organization||"—",readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Management ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:V,value:p.custom_management,onChange:H=>c(re=>({...re,custom_management:H.target.value})),children:[n.jsx("option",{value:"",children:"Select management"}),fe(a,p.custom_management).map(H=>n.jsx("option",{value:H.name,children:H.name1||H.name},H.name))]}):n.jsx("input",{style:G,value:p.custom_management||"—",readOnly:!0})]})]}),n.jsxs("div",{style:ge,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Department ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:V,value:p.custom_department,onChange:H=>c(re=>({...re,custom_department:H.target.value})),children:[n.jsx("option",{value:"",children:"Select department"}),fe(d,p.custom_department).map(H=>n.jsx("option",{value:H.name,children:H.department_name||H.name},H.name))]}):n.jsx("input",{style:G,value:p.custom_department||"—",readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Branch ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:V,value:p.custom_branch,onChange:H=>c(re=>({...re,custom_branch:H.target.value})),children:[n.jsx("option",{value:"",children:"Select branch"}),fe(u,p.custom_branch).map(H=>n.jsx("option",{value:H.name,children:H.branch||H.name},H.name))]}):n.jsx("input",{style:G,value:p.custom_branch||"—",readOnly:!0})]})]})]}),n.jsxs("div",{style:{background:N,borderRadius:12,padding:22,border:`1px solid ${F}`,boxShadow:`0 1px 4px rgba(0,0,0,${T?.3:.06})`},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),n.jsx("span",{style:{fontSize:14,fontWeight:700,color:ne},children:"Change Password"})]}),s&&n.jsx("button",{onClick:()=>{b(H=>!H),m("")},style:{fontSize:13,color:"#3b82f6",background:"none",border:"none",cursor:"pointer",fontWeight:600,fontFamily:"inherit"},children:g?"Cancel":"Change Password"})]}),g&&n.jsxs("div",{style:{marginTop:18,display:"flex",flexDirection:"column",gap:12},children:[n.jsxs("div",{style:Ce,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["New Password ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{type:"password",style:Q,value:x.new,onChange:H=>h(re=>({...re,new:H.target.value})),placeholder:"New password"})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Confirm Password ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{type:"password",style:Q,value:x.confirm,onChange:H=>h(re=>({...re,confirm:H.target.value})),placeholder:"Confirm password"})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:je,style:{width:"100%",padding:"9px 0",borderRadius:8,border:"none",background:"#2563eb",color:"white",fontWeight:700,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:o==="saving"?"Saving…":"Update Password"})})]}),o&&o!=="saving"&&n.jsx("div",{style:{fontSize:13,color:o==="done"?"#16a34a":"#dc2626",fontWeight:500},children:o==="done"?"Password updated successfully":o==="error"?"Failed to update password":o})]})]})]})]})]})}function Ee({label:e,val:t,color:l}){return n.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 ${l}`,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[n.jsx("div",{style:{fontSize:18,fontWeight:700,color:l},children:t}),n.jsx("div",{style:{fontSize:12,color:"#999"},children:e})]})}const Bf={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151",boxSizing:"border-box"},o0={...Bf,cursor:"pointer"};function ot({filters:e,defaultOpen:t=!1}){const[l,s]=j.useState(t);return n.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[n.jsxs("div",{onClick:()=>s(r=>!r),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:l?n.jsx("polyline",{points:"18,15 12,9 6,15"}):n.jsx("polyline",{points:"6,9 12,15 18,9"})}),n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),l&&n.jsx("div",{style:{padding:"18px 20px"},children:n.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(${Math.min(e.length,4)}, 1fr)`,gap:14},children:e.map((r,i)=>n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:r.label}),r.type==="search"?n.jsx("input",{style:Bf,placeholder:r.placeholder,value:r.value,onChange:a=>r.onChange(a.target.value)}):n.jsx("select",{style:o0,value:r.value,onChange:a=>r.onChange(a.target.value),children:r.options.map(a=>n.jsx("option",{value:a.value,children:a.label},a.value))})]},i))})})]})}function c0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function d0({organizations:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),[y,p]=j.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=j.useMemo(()=>e.filter(x=>{const h=[x.organization_name,x.city].filter(Boolean).join(" ").toLowerCase();return!(a&&!h.includes(a.toLowerCase())||u!=="all"&&x.type!==u||y!=="all"&&(x.is_active?"Active":"Inactive")!==y)}),[e,a,u,y]),[w,g]=j.useState(1);j.useEffect(()=>{g(1)},[a,u,y]);const b=v.slice((w-1)*te,w*te);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(Ee,{label:"Total",val:v.length,color:"#1a2332"}),n.jsx(Ee,{label:"Active",val:v.filter(x=>x.is_active).length,color:U.green}),n.jsx(Ee,{label:"Government",val:v.filter(x=>x.type==="Government").length,color:U.blue}),n.jsx(Ee,{label:"Private",val:v.filter(x=>x.type==="Private").length,color:U.orange})]}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Name or city…"},{type:"select",label:i.col.type,value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Government",label:"Government"},{value:"Private",label:"Private"}]},{type:"select",label:"Status",value:y,onChange:p,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:c,children:i.col.name}),n.jsx("th",{style:c,children:i.col.type}),n.jsx("th",{style:c,children:i.col.city}),n.jsx("th",{style:c,children:i.field.creationDate}),n.jsx("th",{style:c,children:i.col.status}),n.jsx("th",{style:c,children:i.col.actions})]})}),n.jsx("tbody",{children:v.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((x,h)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(x),style:{borderTop:"1px solid #f0f0f0",background:h%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:x.organization_name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:x.type||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:x.city||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:c0(x.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:Dn(x.is_active?i.field.statusActive:i.field.statusInactive,x.is_active?U.green:U.gray)}),n.jsx("td",{style:{padding:"8px 14px"},onClick:o=>o.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(x),onEdit:t&&s?()=>s(x):void 0,onDelete:t&&r?()=>r(x.name):void 0})})]},x.name))})]})}),n.jsx(Ue,{page:w,total:v.length,onPageChange:g})]})}const Zt=e=>({background:e?"#f9f9f9":void 0});function u0({orgForm:e,setOrgForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=e.name?s&&e.organization_name||g.formTitle.editOrg:g.formTitle.newOrg;return n.jsxs(Fe,{title:b,activePage:"organizations",user:w,formStatus:l,buttonText:g.saveOrg,buttonColor:U.accent,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.orgName}),n.jsx("input",{type:"text",style:{...E,...Zt(s)},value:e.organization_name,disabled:s,onChange:x=>t({...e,organization_name:x.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.orgAcronym}),n.jsx("input",{type:"text",style:{...E,...Zt(s)},value:e.acronym||"",disabled:s,onChange:x=>t({...e,acronym:x.target.value})})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.organizationType}),n.jsxs("select",{style:{...E,...Zt(s)},value:e.type,disabled:s,onChange:x=>t({...e,type:x.target.value}),children:[n.jsx("option",{children:"Government"}),n.jsx("option",{children:"Private"}),n.jsx("option",{children:"Non-Profit"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.orgCity}),n.jsx("input",{type:"text",style:{...E,...Zt(s)},value:e.city,disabled:s,onChange:x=>t({...e,city:x.target.value})})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.contactEmail}),n.jsx("input",{type:"email",style:{...E,...Zt(s)},value:e.contact_email,disabled:s,onChange:x=>t({...e,contact_email:x.target.value})})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:x=>t({...e,creation_date:x}),disabled:s,style:{...E,...Zt(s)}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...Zt(s)},value:e.is_active?"Active":"Inactive",disabled:s,onChange:x=>t({...e,is_active:x.target.value==="Active"?1:0}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.incidentTriageWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...E,...Zt(s)},value:e.incident_triage_window_days??3,disabled:s,onChange:x=>t({...e,incident_triage_window_days:parseInt(x.target.value)||3})}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:"Days after creation before an untriaged Incident is flagged overdue"})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.incidentResolutionWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...E,...Zt(s)},value:e.incident_resolution_window_days??5,disabled:s,onChange:x=>t({...e,incident_resolution_window_days:parseInt(x.target.value)||5})}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:"Days without an update before an in-progress Incident is flagged overdue"})]})]})]})}function p0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function f0({managements:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.blue})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:p0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function h0({form:e,setForm:t,organizations:l,formStatus:s,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:w,user:g}){const b=Z(),x=m=>t(C=>({...C,...m})),h=r?{background:"#f9f9f9"}:{},o=e.name?r?`${b.formTitle.editMgmt}: ${e.name1||e.name}`:b.formTitle.editMgmt:b.formTitle.newMgmt;return n.jsxs(Fe,{title:o,activePage:"managements",user:g,formStatus:s,buttonText:b.saveMgmt,buttonColor:U.blue,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:w,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.organization}),n.jsx(It,{value:e.organization,onChange:m=>x({organization:m}),organizations:l,disabled:r})]}),n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[b.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...h},value:e.name1,disabled:r,onChange:m=>x({name1:m.target.value}),placeholder:"Management name",required:!0})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:m=>x({creation_date:m}),disabled:r,style:{...E,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.status}),n.jsxs("select",{style:{...E,...h},value:e.status||"Active",disabled:r,onChange:m=>x({status:m.target.value}),children:[n.jsx("option",{value:"Active",children:b.field.statusActive}),n.jsx("option",{value:"Inactive",children:b.field.statusInactive})]})]})]})]})}function g0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function x0({departments:e,managements:t,canModify:l,onView:s,onEdit:r,onDelete:i}){const a=Z(),[d,u]=j.useState(""),[f,y]=j.useState(""),[p,c]=j.useState("all"),v=o=>{var m;return((m=t.find(C=>C.name===o))==null?void 0:m.name1)||o||"—"},w={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=j.useMemo(()=>e.filter(o=>{const m=(o.department_name||o.name||"").toLowerCase();return!(d&&!m.includes(d.toLowerCase())||f&&o.custom_management!==f||p!=="all"&&(o.custom_status||"Active")!==p)}),[e,d,f,p]),[b,x]=j.useState(1);j.useEffect(()=>{x(1)},[d,f,p]);const h=g.slice((b-1)*te,b*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:g.length,color:U.teal})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:d,onChange:u,placeholder:"Search by name…"},{type:"select",label:a.col.management,value:f,onChange:y,options:[{value:"",label:"All Managements"},...t.map(o=>({value:o.name,label:o.name1||o.name}))]},{type:"select",label:"Status",value:p,onChange:c,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:w,children:a.col.name}),n.jsx("th",{style:w,children:a.col.management}),n.jsx("th",{style:w,children:a.field.creationDate}),n.jsx("th",{style:w,children:a.field.status}),n.jsx("th",{style:w,children:a.col.actions})]})}),n.jsx("tbody",{children:g.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):h.map((o,m)=>n.jsxs("tr",{onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.department_name||o.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:v(o.custom_management)}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:g0(o.custom_creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:o.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.custom_status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:C=>C.stopPropagation(),children:n.jsx(Je,{onView:()=>s==null?void 0:s(o),onEdit:l&&r?()=>r(o):void 0,onDelete:l&&i?()=>i(o.name):void 0})})]},o.name))})]})}),n.jsx(Ue,{page:b,total:g.length,onPageChange:x})]})}const m0={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20};function y0({form:e,setForm:t,organizations:l,managements:s,formStatus:r,viewMode:i,onEdit:a,darkMode:d,notifCount:u,onToggleDark:f,onCountChange:y,onViewProfile:p,onSubmit:c,onBack:v,onNavigate:w,onLogout:g,user:b}){const x=Z(),h=P=>t(R=>({...R,...P})),o=i?{background:"#f9f9f9"}:{},m=e.name?i?`${x.formTitle.editDept}: ${e.department_name||e.name}`:x.formTitle.editDept:x.formTitle.newDept,C=fe(s,e.custom_management).map(P=>({name:P.name,label:P.name1||P.name}));return n.jsxs(Fe,{title:m,activePage:"departments",user:b,formStatus:r,buttonText:x.saveDept,buttonColor:U.teal,viewMode:i,onEdit:a,darkMode:d,notifCount:u,onToggleDark:f,onCountChange:y,onViewProfile:p,onSubmit:c,onBack:v,onNavigate:w,onLogout:g,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:x.field.organization}),n.jsx(It,{value:e.custom_organization,onChange:P=>h({custom_organization:P}),organizations:l,disabled:i})]}),n.jsxs("div",{style:m0,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[x.field.department," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...o},value:e.department_name,disabled:i,onChange:P=>h({department_name:P.target.value}),placeholder:"Department name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:x.field.management}),n.jsx(ue,{value:e.custom_management,onChange:P=>h({custom_management:P}),items:C,placeholder:x.field.select,disabled:i})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:x.field.creationDate}),n.jsx(xe,{value:e.custom_creation_date||"",onChange:P=>h({custom_creation_date:P}),disabled:i,style:{...E,...o}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:x.field.status}),n.jsxs("select",{style:{...E,...o},value:e.custom_status||"Active",disabled:i,onChange:P=>h({custom_status:P.target.value}),children:[n.jsx("option",{value:"Active",children:x.field.statusActive}),n.jsx("option",{value:"Inactive",children:x.field.statusInactive})]})]})]})]})}function v0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function j0({branches:e,managements:t,departments:l,canModify:s,onView:r,onEdit:i,onDelete:a}){const d=Z(),[u,f]=j.useState(""),[y,p]=j.useState(""),[c,v]=j.useState(""),[w,g]=j.useState("all"),b=R=>{var S;return((S=t.find(_=>_.name===R))==null?void 0:S.name1)||R||"—"},x=R=>{var S;return((S=l.find(_=>_.name===R))==null?void 0:S.department_name)||R||"—"},h={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},o=j.useMemo(()=>e.filter(R=>{const S=(R.branch||R.name||"").toLowerCase();return!(u&&!S.includes(u.toLowerCase())||y&&R.management!==y||c&&R.department!==c||w!=="all"&&(R.custom_status||"Active")!==w)}),[e,u,y,c,w]),[m,C]=j.useState(1);j.useEffect(()=>{C(1)},[u,y,c,w]);const P=o.slice((m-1)*te,m*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:o.length,color:U.purple})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:u,onChange:f,placeholder:"Search by name…"},{type:"select",label:d.col.management,value:y,onChange:p,options:[{value:"",label:"All Managements"},...t.map(R=>({value:R.name,label:R.name1||R.name}))]},{type:"select",label:d.col.department,value:c,onChange:v,options:[{value:"",label:"All Departments"},...l.map(R=>({value:R.name,label:R.department_name||R.name}))]},{type:"select",label:"Status",value:w,onChange:g,options:[{value:"all",label:"All"},{value:"Active",label:d.field.statusActive},{value:"Inactive",label:d.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:h,children:d.col.branch}),n.jsx("th",{style:h,children:d.col.management}),n.jsx("th",{style:h,children:d.col.department}),n.jsx("th",{style:h,children:d.field.creationDate}),n.jsx("th",{style:h,children:d.field.status}),n.jsx("th",{style:h,children:d.col.actions})]})}),n.jsx("tbody",{children:o.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:d.noData})}):P.map((R,S)=>n.jsxs("tr",{onClick:()=>r==null?void 0:r(R),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:R.branch||R.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:b(R.management)}),n.jsx("td",{style:{padding:"10px 14px"},children:x(R.department)}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:v0(R.custom_creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:R.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:R.custom_status==="Inactive"?d.field.statusInactive:d.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:_=>_.stopPropagation(),children:n.jsx(Je,{onView:()=>r==null?void 0:r(R),onEdit:s&&i?()=>i(R):void 0,onDelete:s&&a?()=>a(R.name):void 0})})]},R.name))})]})}),n.jsx(Ue,{page:m,total:o.length,onPageChange:C})]})}const b0={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20};function S0({form:e,setForm:t,organizations:l,managements:s,departments:r,formStatus:i,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:w,onNavigate:g,onLogout:b,user:x}){const h=Z(),o=S=>t(_=>({..._,...S})),m=a?{background:"#f9f9f9"}:{},C=e.name?a?`${h.formTitle.editBranch}: ${e.branch||e.name}`:h.formTitle.editBranch:h.formTitle.newBranch,P=fe(s,e.management).map(S=>({name:S.name,label:S.name1||S.name})),R=fe(r,e.department).map(S=>({name:S.name,label:S.department_name||S.name}));return n.jsxs(Fe,{title:C,activePage:"branches",user:x,formStatus:i,buttonText:h.saveBranch,buttonColor:U.purple,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:w,onNavigate:g,onLogout:b,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:h.field.organization}),n.jsx(It,{value:e.organization,onChange:S=>o({organization:S}),organizations:l,disabled:a})]}),n.jsxs("div",{style:b0,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[h.field.branch," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...m},value:e.branch,disabled:a||!!e.name,onChange:S=>o({branch:S.target.value}),placeholder:"Branch name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:h.field.management}),n.jsx(ue,{value:e.management,onChange:S=>o({management:S}),items:P,placeholder:h.field.select,disabled:a})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:h.field.department}),n.jsx(ue,{value:e.department,onChange:S=>o({department:S}),items:R,placeholder:h.field.select,disabled:a})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:h.field.creationDate}),n.jsx(xe,{value:e.custom_creation_date||"",onChange:S=>o({custom_creation_date:S}),disabled:a,style:{...E,...m}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:h.field.status}),n.jsxs("select",{style:{...E,...m},value:e.custom_status||"Active",disabled:a,onChange:S=>o({custom_status:S.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})]})}function w0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function k0({incidentTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.red})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:w0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function _0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Incident Type: ${e.name1||e.name}`:"Edit Incident Type":"New Incident Type";return n.jsxs(Fe,{title:h,activePage:"incident-types",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.red,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Incident type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function C0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function z0({ideaTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.teal})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:C0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function T0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Idea Type: ${e.name1||e.name}`:"Edit Idea Type":"New Idea Type";return n.jsxs(Fe,{title:h,activePage:"idea-types",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.teal,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Idea type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function P0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function I0({orderTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.purple})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:P0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function E0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Order Type: ${e.name1||e.name}`:"Edit Order Type":"New Order Type";return n.jsxs(Fe,{title:h,activePage:"order-types",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.purple,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Order type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function A0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function R0({processTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.blue})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:A0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function L0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Process Type: ${e.name1||e.name}`:"Edit Process Type":"New Process Type";return n.jsxs(Fe,{title:h,activePage:"process-types",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.blue,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Process type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function O0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function D0({incidentStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.red})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:O0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function N0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Incident Status: ${e.name1||e.name}`:"Edit Incident Status":"New Incident Status";return n.jsxs(Fe,{title:h,activePage:"incident-statuses",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.red,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Incident status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>b({notify_manager:o.target.checked?1:0}),style:Ql}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function W0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function B0({ideaStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.teal})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:W0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function $0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Idea Status: ${e.name1||e.name}`:"Edit Idea Status":"New Idea Status";return n.jsxs(Fe,{title:h,activePage:"idea-statuses",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.teal,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Idea status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>b({notify_manager:o.target.checked?1:0}),style:Ql}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function U0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function F0({orderStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.purple})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:U0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function M0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Order Status: ${e.name1||e.name}`:"Edit Order Status":"New Order Status";return n.jsxs(Fe,{title:h,activePage:"order-statuses",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.purple,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Order status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>b({notify_manager:o.target.checked?1:0}),style:Ql}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function H0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function K0({processStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const b=(g.name1||g.name||"").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total",val:p.length,color:U.blue})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:H0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}function Q0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:w}){const g=Z(),b=o=>t(m=>({...m,...o})),x=s?{background:"#f9f9f9"}:{},h=e.name?s?`Process Status: ${e.name1||e.name}`:"Edit Process Status":"New Process Status";return n.jsxs(Fe,{title:h,activePage:"process-statuses",user:w,formStatus:l,buttonText:g.saveName,buttonColor:U.blue,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...x},value:e.name1,disabled:s,onChange:o=>b({name1:o.target.value}),placeholder:"Process status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>b({notify_manager:o.target.checked?1:0}),style:Ql}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.creationDate}),n.jsx(xe,{value:e.creation_date||"",onChange:o=>b({creation_date:o}),disabled:s,style:{...E,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:g.field.status}),n.jsxs("select",{style:{...E,...x},value:e.status||"Active",disabled:s,onChange:o=>b({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}const G0={Admin:"#7c3aed",Chairman:"#0f766e",Auditor:"#d97706","X-Auditor":"#8b5cf6",Manager:"#2563eb",Employee:"#6b7280"};function Y0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function X0({users:e,canModify:t,onView:l,onEdit:s,onDisable:r}){const i=Z(),[a,d]=j.useState(!1),[u,f]=j.useState(""),[y,p]=j.useState(""),[c,v]=j.useState(""),[w,g]=j.useState("active"),[b,x]=j.useState(1),[h,o]=j.useState(null),[m,C]=j.useState(""),[P,R]=j.useState("idle"),[S,_]=j.useState(null),$=async()=>{if(!(!h||!m.trim())){R("loading");try{await Df(h.name,m.trim()),R("success"),setTimeout(()=>{o(null),C(""),R("idle")},1200)}catch{R("error")}}},T=async A=>{if(window.confirm(i.users.disableConfirm)){_(A);try{await(r==null?void 0:r(A))}finally{_(null)}}},I=e.filter(A=>{if(w==="active"&&(A.enabled===0||A.enabled==="0")||w==="inactive"&&A.enabled!==0&&A.enabled!=="0")return!1;const Q=A.custom_category||"";if(c&&Q!==c)return!1;const G=A.custom_organization||"";if(y&&!G.toLowerCase().includes(y.toLowerCase()))return!1;if(u){const V=u.toLowerCase();if(![A.full_name,A.email,A.name,A.username,A.mobile_no].join(" ").toLowerCase().includes(V))return!1}return!0}),N=[...new Set(e.map(A=>A.custom_organization).filter(Boolean))],F=["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"];j.useEffect(()=>{x(1)},[u,y,c,w]);const ne=I.slice((b-1)*te,b*te),ee={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151"},me={...ee,cursor:"pointer"};return n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,flex:1},children:[n.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:16},children:["Total: ",I.length," users"]}),n.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[n.jsxs("div",{onClick:()=>d(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:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:a?n.jsx("polyline",{points:"18,15 12,9 6,15"}):n.jsx("polyline",{points:"6,9 12,15 18,9"})}),n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),a&&n.jsx("div",{style:{padding:"18px 20px",display:"flex",flexDirection:"column",gap:14},children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:14},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Search"}),n.jsx("input",{style:ee,placeholder:"Name, email, username…",value:u,onChange:A=>f(A.target.value)})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Organization"}),n.jsxs("select",{style:me,value:y,onChange:A=>p(A.target.value),children:[n.jsx("option",{value:"",children:"All Organizations"}),N.map(A=>n.jsx("option",{value:A,children:A},A))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Category"}),n.jsxs("select",{style:me,value:c,onChange:A=>v(A.target.value),children:[n.jsx("option",{value:"",children:"All Categories"}),F.map(A=>n.jsx("option",{value:A,children:A},A))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Status"}),n.jsxs("select",{style:me,value:w,onChange:A=>g(A.target.value),children:[n.jsx("option",{value:"all",children:"All"}),n.jsx("option",{value:"active",children:"Active"}),n.jsx("option",{value:"inactive",children:"Inactive"})]})]})]})})]}),n.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa",borderBottom:"2px solid #f0f0f0"},children:[{label:"Category",w:100},{label:"Number",w:80},{label:"Full Name",w:140},{label:"Username",w:120},{label:"Email Address",w:180},{label:"Phone Number",w:120},{label:"Organization",w:130},{label:"Management",w:120},{label:"Department",w:120},{label:"Branch",w:100},{label:"Since",w:90},{label:"Status",w:80},{label:"Tools",w:200}].map(({label:A,w:Q})=>n.jsx("th",{style:{padding:"11px 14px",textAlign:"left",color:"#6b7280",fontSize:11,fontWeight:700,whiteSpace:"nowrap",minWidth:Q,letterSpacing:.3,textTransform:"uppercase"},children:A},A))})}),n.jsx("tbody",{children:I.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:13,style:{padding:"48px 20px",textAlign:"center",color:"#aaa",fontSize:14},children:"No users found"})}):ne.map((A,Q)=>{const G=A.custom_category||"",V=G0[G]||"#6b7280";return n.jsxs("tr",{onClick:()=>l==null?void 0:l(A),style:{borderBottom:"1px solid #f3f4f6",background:Q%2===0?"white":"#fafafa",transition:"background 0.1s",cursor:"pointer"},onMouseEnter:q=>q.currentTarget.style.background="#f0f7ff",onMouseLeave:q=>q.currentTarget.style.background=Q%2===0?"white":"#fafafa",children:[n.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:G?n.jsx("span",{style:{background:V+"18",color:V,border:`1px solid ${V}44`,padding:"3px 10px",borderRadius:20,fontSize:11,fontWeight:700},children:G}):n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_number||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",fontWeight:600,color:"#1a2332",whiteSpace:"nowrap"},children:A.full_name||A.first_name||"—"}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:A.username||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:A.email||A.name}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.mobile_no||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:A.custom_organization||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_management||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_department||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_branch||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:Y0(A.creation)}),n.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:n.jsx("span",{style:{color:A.enabled?"#16a34a":"#dc2626",fontWeight:600},children:A.enabled?i.users.active:i.users.inactive})}),n.jsx("td",{style:{padding:"10px 14px",whiteSpace:"nowrap"},onClick:q=>q.stopPropagation(),children:n.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[n.jsx("button",{onClick:q=>{q.stopPropagation(),l==null||l(A)},title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),t&&s&&n.jsx("button",{onClick:q=>{q.stopPropagation(),s(A)},title:"Edit",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#dcfce7",color:"#16a34a"},children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),t&&n.jsx("button",{onClick:q=>{q.stopPropagation(),o({name:A.name,email:A.email||A.name}),C(""),R("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:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),t&&n.jsx("button",{onClick:q=>{q.stopPropagation(),T(A.name)},disabled:S===A.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:S===A.name?.5:1},children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6l-1 14H6L5 6"}),n.jsx("path",{d:"M10 11v6M14 11v6"}),n.jsx("path",{d:"M9 6V4h6v2"})]})})]})})]},A.name)})})]})}),n.jsx(Ue,{page:b,total:I.length,onPageChange:x}),h&&n.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsxs("div",{style:{background:"white",borderRadius:14,padding:32,width:390,boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[n.jsx("div",{style:{fontSize:17,fontWeight:700,marginBottom:6,color:"#1a2332"},children:i.users.setPassword}),n.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:20},children:["User: ",n.jsx("strong",{children:h.email})]}),n.jsx("input",{type:"password",value:m,onChange:A=>C(A.target.value),placeholder:i.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:A=>A.key==="Enter"&&$(),autoFocus:!0}),P==="success"&&n.jsx("div",{style:{color:"#166534",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Password updated successfully"}),P==="error"&&n.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"}),n.jsxs("div",{style:{display:"flex",gap:10},children:[n.jsx("button",{onClick:$,disabled:P==="loading"||!m.trim(),style:{flex:1,padding:10,background:"#2563eb",color:"white",border:"none",borderRadius:8,cursor:"pointer",fontSize:13,fontWeight:700,fontFamily:"inherit",opacity:m.trim()?1:.5},children:P==="loading"?"Saving…":i.users.setPassword}),n.jsx("button",{onClick:()=>{o(null),C(""),R("idle")},style:{flex:1,padding:10,background:"#f5f5f5",color:"#374151",border:"1px solid #e5e7eb",borderRadius:8,cursor:"pointer",fontSize:13,fontFamily:"inherit"},children:i.cancel})]})]})})]})}const xs={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20};function J0({form:e,setForm:t,organizations:l,managements:s,departments:r,branches:i,formStatus:a,viewMode:d,onEdit:u,darkMode:f,notifCount:y,onToggleDark:p,onCountChange:c,onViewProfile:v,isSelfProfile:w,onSubmit:g,onBack:b,onNavigate:x,onLogout:h,user:o}){const m=Z(),C=I=>t(N=>({...N,...I})),P=d?{background:"#f9f9f9"}:{},R=!e.name,S=w?"My Profile":R?"New User":d?`User: ${e.full_name||e.email}`:`Edit User: ${e.full_name||e.email}`,_=fe(s,e.custom_management).map(I=>({name:I.name,label:I.name1||I.name})),$=fe(r,e.custom_department).map(I=>({name:I.name,label:I.department_name||I.name})),T=fe(i,e.custom_branch).map(I=>({name:I.name,label:I.branch||I.name}));return n.jsxs(Fe,{title:S,activePage:"users",user:o,formStatus:a,buttonText:m.saveUser,buttonColor:U.blue,viewMode:d,onEdit:u,darkMode:f,notifCount:y,onToggleDark:p,onCountChange:c,onViewProfile:v,hideSettings:w,onSubmit:g,onBack:b,onNavigate:x,onLogout:h,children:[n.jsxs("div",{style:xs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.organization}),n.jsx(It,{value:e.custom_organization,onChange:I=>C({custom_organization:I}),organizations:l,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.management}),n.jsx(ue,{value:e.custom_management,onChange:I=>C({custom_management:I}),items:_,placeholder:"-- Select --",disabled:d})]})]}),n.jsxs("div",{style:xs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.department}),n.jsx(ue,{value:e.custom_department,onChange:I=>C({custom_department:I}),items:$,placeholder:"-- Select --",disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.branch}),n.jsx(ue,{value:e.custom_branch,onChange:I=>C({custom_branch:I}),items:T,placeholder:"-- Select --",disabled:d})]})]}),n.jsxs("div",{style:xs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.number}),n.jsx("input",{style:{...E,...P},value:e.custom_number,disabled:d,onChange:I=>C({custom_number:I.target.value}),placeholder:"e.g. 10001"})]}),n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[m.field.fullName," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...P},value:e.first_name,disabled:d,onChange:I=>C({first_name:I.target.value}),placeholder:"Full name",required:!0})]})]}),n.jsxs("div",{style:xs,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.username}),n.jsx("input",{style:{...E,...P},value:e.username,disabled:d,onChange:I=>C({username:I.target.value}),placeholder:"Username"})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.phoneNumber}),n.jsx("input",{style:{...E,...P},value:e.mobile_no,disabled:d,onChange:I=>C({mobile_no:I.target.value}),placeholder:"Phone number"})]})]}),n.jsxs("div",{style:xs,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[m.field.emailAddress," ",R&&n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...d||!R?{background:"#f9f9f9"}:{}},value:e.email,disabled:d||!R,onChange:I=>C({email:I.target.value}),placeholder:"user@example.com",type:"email",required:R})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:m.field.category}),n.jsxs("select",{style:{...E,...P},value:e.custom_category,disabled:d,onChange:I=>C({custom_category:I.target.value}),children:[n.jsx("option",{value:"",children:m.field.select}),n.jsx("option",{children:"Admin"}),n.jsx("option",{children:"Chairman"}),n.jsx("option",{children:"Auditor"}),n.jsx("option",{children:"X-Auditor"}),n.jsx("option",{children:"Manager"}),n.jsx("option",{children:"Employee"})]})]})]})]})}const ou={Active:U.green,Closed:U.gray};function q0({cycles:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState(""),[y,p]=j.useState("all"),c=j.useMemo(()=>[...new Set(e.map(o=>o.organization).filter(Boolean))],[e]),v=j.useMemo(()=>e.filter(o=>{const m=(o.name1||o.name||"").toLowerCase();return!(a&&!m.includes(a.toLowerCase())||u&&o.organization!==u||y!=="all"&&o.status!==y)}),[e,a,u,y]),[w,g]=j.useState(1);j.useEffect(()=>{g(1)},[a,u,y]);const b=v.slice((w-1)*te,w*te),x=v.filter(o=>o.status==="Active").length,h=v.filter(o=>o.status==="Closed").length;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(Ee,{label:"Total",val:v.length,color:U.teal}),n.jsx(Ee,{label:"Active",val:x,color:U.green}),n.jsx(Ee,{label:"Closed",val:h,color:U.gray})]}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:i.col.organization,value:u,onChange:f,options:[{value:"",label:"All Organizations"},...c.map(o=>({value:o,label:o}))]},{type:"select",label:"Status",value:y,onChange:p,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Closed",label:"Closed"}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.name}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.frequency}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.startDate}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.endDate}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.actions})]})}),n.jsx("tbody",{children:v.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((o,m)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(o),style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.frequency||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.start_date||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.end_date||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{padding:"3px 10px",borderRadius:12,fontSize:12,background:ou[o.status]+"22",color:ou[o.status]||"#666"},children:o.status})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:C=>C.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(o),onEdit:t&&s?()=>s(o):void 0,onDelete:t&&r?()=>r(o.name):void 0})})]},o.name))})]})}),n.jsx(Ue,{page:w,total:v.length,onPageChange:g})]})}const za={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Z0=["Weekly","Bi-weekly","Monthly","Quarterly","Annually"],V0=["Active","Closed"];function e1({form:e,setForm:t,organizations:l,formStatus:s,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:w,user:g}){const b=Z(),x=m=>t(C=>({...C,...m})),h=r?{background:"#f9f9f9"}:{},o=e.name?r?`${b.formTitle.editCycle}: ${e.name1||e.name}`:b.formTitle.editCycle:b.formTitle.newCycle;return n.jsxs(Fe,{title:o,activePage:"cycles",user:g,formStatus:s,buttonText:b.saveCycle,buttonColor:U.teal,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:w,children:[n.jsxs("div",{style:za,children:[n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[b.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...h},value:e.name1||"",disabled:r||!!e.name,onChange:m=>x({name1:m.target.value}),placeholder:"e.g. Q1-2026"})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.organization}),n.jsx(It,{value:e.organization,onChange:m=>x({organization:m}),organizations:l,disabled:r})]})]}),n.jsxs("div",{style:za,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.col.frequency}),n.jsx(ue,{value:e.frequency,onChange:m=>x({frequency:m}),items:Z0.map(m=>({name:m,label:m})),placeholder:"-- Select Frequency --",disabled:r})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.status}),n.jsx(ue,{value:e.status,onChange:m=>x({status:m}),items:V0.map(m=>({name:m,label:m})),placeholder:"-- Select Status --",disabled:r})]})]}),n.jsxs("div",{style:za,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.dateStart}),n.jsx(xe,{value:e.start_date||"",onChange:m=>x({start_date:m}),disabled:r,style:{...E,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.dateEnd}),n.jsx(xe,{value:e.end_date||"",onChange:m=>x({end_date:m}),disabled:r,style:{...E,...h}})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.updateWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...E,...h,maxWidth:160},value:e.update_window_days??2,disabled:r,onChange:m=>x({update_window_days:parseInt(m.target.value)||2})}),n.jsx("span",{style:{fontSize:12,color:"#888",marginLeft:8},children:"Grace period after cycle ends before Unknown is auto-assigned"})]})]})}function t1({kpiInputs:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=Z(),[a,d]=j.useState(""),[u,f]=j.useState(""),y=j.useMemo(()=>[...new Set(e.map(g=>g.organization).filter(Boolean))],[e]),p=j.useMemo(()=>e.filter(g=>{const b=[g.organization,g.period].filter(Boolean).join(" ").toLowerCase();return!(a&&!b.includes(a.toLowerCase())||u&&g.organization!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const w=p.slice((c-1)*te,c*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ee,{label:"Total Records",val:p.length,color:U.blue})}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Organization or period…"},{type:"select",label:i.col.organization,value:u,onChange:f,options:[{value:"",label:"All Organizations"},...y.map(g=>({value:g,label:g}))]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.period}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.field.revenue_growth}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.field.net_profit}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.dash.customerSat}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):w.map((g,b)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.period||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.revenue_growth!=null?`${g.revenue_growth}%`:"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.net_profit!=null?g.net_profit.toLocaleString():"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.customer_satisfaction!=null?g.customer_satisfaction:"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Ue,{page:c,total:p.length,onPageChange:v})]})}const cu={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},du={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20};function n1({form:e,setForm:t,organizations:l,formStatus:s,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:w,user:g}){const b=Z(),x=C=>t(P=>({...P,...C})),h=r?{background:"#f9f9f9"}:{},o=C=>P=>x({[C]:parseFloat(P.target.value)||0}),m=e.name?r?`${b.formTitle.editKpi}: ${e.period||e.name}`:b.formTitle.editKpi:b.formTitle.newKpi;return n.jsxs(Fe,{title:m,activePage:"kpi-input",user:g,formStatus:s,buttonText:b.saveKpi,buttonColor:U.blue,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:w,children:[n.jsxs("div",{style:cu,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.organization}),n.jsx(It,{value:e.organization,onChange:C=>x({organization:C}),organizations:l,disabled:r})]}),n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[b.col.period," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...h},value:e.period||"",disabled:r,onChange:C=>x({period:C.target.value}),placeholder:"e.g. Q1 2026"})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",marginBottom:12},children:"Financial KPIs"}),n.jsxs("div",{style:du,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.revenue_growth}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...h},value:e.revenue_growth||"",disabled:r,onChange:o("revenue_growth")})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.net_profit}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...h},value:e.net_profit||"",disabled:r,onChange:o("net_profit")})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.cash_flow}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...h},value:e.cash_flow||"",disabled:r,onChange:o("cash_flow")})]})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",marginBottom:12},children:"Operational KPIs"}),n.jsxs("div",{style:du,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.strategic_goal_pct}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...h},value:e.strategic_goal_pct||"",disabled:r,onChange:o("strategic_goal_pct")})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.customer_satisfaction}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...h},value:e.customer_satisfaction||"",disabled:r,onChange:o("customer_satisfaction")})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.employee_turnover_pct}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...h},value:e.employee_turnover_pct||"",disabled:r,onChange:o("employee_turnover_pct")})]})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",marginBottom:12},children:"Safety & Compliance"}),n.jsxs("div",{style:cu,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.open_safety_incidents}),n.jsx("input",{type:"number",min:0,style:{...E,...h},value:e.open_safety_incidents||"",disabled:r,onChange:C=>x({open_safety_incidents:parseInt(C.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:z,children:b.field.compliance_score}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...h},value:e.compliance_score||"",disabled:r,onChange:o("compliance_score")})]})]})]})]})}const l1={create_processes:"Create Processes",update_process_status:"Update Process Status"},uu={Pending:U.orange,Accepted:U.green,Rejected:U.red,Revoked:U.gray};function s1(e){if(!e)return"—";const t=new Date(e);return isNaN(t.getTime())?"—":`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function r1(e){const t=[];return e.create_processes&&t.push("create_processes"),e.update_process_status&&t.push("update_process_status"),t}function i1({delegations:e,organizations:t,userRole:l,currentUser:s,onView:r,onRevoke:i}){const a=Z(),[d,u]=j.useState(""),[f,y]=j.useState(""),[p,c]=j.useState("all"),v={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},w=j.useMemo(()=>e.filter(m=>{const C=`${m.auditor} ${m.manager}`.toLowerCase();return!(d&&!C.includes(d.toLowerCase())||f&&m.organization!==f||p!=="all"&&m.status!==p)}),[e,d,f,p]),[g,b]=j.useState(1);j.useEffect(()=>{b(1)},[d,f,p]);const x=w.slice((g-1)*te,g*te),h=w.filter(m=>m.status==="Pending").length,o=w.filter(m=>m.status==="Accepted").length;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(Ee,{label:"Total",val:w.length,color:U.purple}),n.jsx(Ee,{label:"Pending",val:h,color:U.orange}),n.jsx(Ee,{label:"Accepted",val:o,color:U.green})]}),n.jsx(ot,{filters:[{type:"search",label:"Search",value:d,onChange:u,placeholder:"Auditor or Manager…"},{type:"select",label:a.col.organization,value:f,onChange:y,options:[{value:"",label:"All Organizations"},...t.map(m=>({value:m.organization_name||m.name,label:m.organization_name||m.name}))]},{type:"select",label:"Status",value:p,onChange:c,options:[{value:"all",label:"All"},{value:"Pending",label:"Pending"},{value:"Accepted",label:"Accepted"},{value:"Rejected",label:"Rejected"},{value:"Revoked",label:"Revoked"}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:v,children:a.col.number}),n.jsx("th",{style:v,children:a.col.auditor}),n.jsx("th",{style:v,children:a.col.manager}),n.jsx("th",{style:v,children:a.col.organization}),n.jsx("th",{style:v,children:a.col.functions}),n.jsx("th",{style:v,children:a.col.status}),n.jsx("th",{style:v,children:a.col.requestedOn}),n.jsx("th",{style:v,children:a.col.actions})]})}),n.jsx("tbody",{children:w.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:8,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):x.map((m,C)=>{const P=!!i&&(m.status==="Pending"||m.status==="Accepted")&&(l==="Admin"||l==="Auditor"&&m.auditor===s);return n.jsxs("tr",{onClick:()=>r==null?void 0:r(m),style:{borderTop:"1px solid #f0f0f0",background:C%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:m.number||m.name}),n.jsx("td",{style:{padding:"10px 14px"},children:m.auditor}),n.jsx("td",{style:{padding:"10px 14px"},children:m.manager}),n.jsx("td",{style:{padding:"10px 14px"},children:m.organization||"All Organizations"}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:r1(m).map(R=>n.jsx("span",{style:{background:"#ede9fe",color:"#6d28d9",padding:"2px 8px",borderRadius:10,fontSize:11,fontWeight:600},children:l1[R]||R},R))})}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{background:(uu[m.status]||U.gray)+"22",color:uu[m.status]||U.gray,padding:"3px 10px",borderRadius:12,fontSize:12,fontWeight:700},children:m.status})}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:s1(m.requested_on)}),n.jsx("td",{style:{padding:"8px 14px"},onClick:R=>R.stopPropagation(),children:n.jsxs("div",{style:{display:"flex",gap:6},children:[n.jsx("button",{onClick:()=>r==null?void 0:r(m),title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),P&&n.jsx("button",{onClick:()=>i==null?void 0:i(m.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"})]})})]},m.name)})})]})}),n.jsx(Ue,{page:g,total:w.length,onPageChange:b})]})}const pu={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},fu={Pending:U.orange,Accepted:U.green,Rejected:U.red,Revoked:U.gray};function a1(e){if(!e)return"—";const t=new Date(e);return isNaN(t.getTime())?"—":t.toLocaleString()}function o1({form:e,setForm:t,organizations:l,users:s,userRoleMap:r,formStatus:i,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:w,onNavigate:g,onLogout:b,user:x}){var R;const h=Z(),o=S=>t(_=>({..._,...S})),m=a?{background:"#f9f9f9"}:{},C=Kl(s,r,"SB Manager").map(S=>({name:S.name,label:S.full_name||S.name})),P=e.name?`${h.formTitle.viewDelegation}${e.number||e.name}`:h.formTitle.newDelegation;return n.jsxs(Fe,{title:P,activePage:"delegations",user:x,formStatus:i,buttonText:h.saveDelegation,buttonColor:U.purple,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:w,onNavigate:g,onLogout:b,children:[a&&e.status&&n.jsx("div",{style:{marginBottom:20},children:n.jsx("span",{style:{background:(fu[e.status]||U.gray)+"22",color:fu[e.status]||U.gray,padding:"5px 14px",borderRadius:14,fontSize:13,fontWeight:700},children:e.status})}),n.jsxs("div",{style:pu,children:[n.jsxs("div",{children:[n.jsx("label",{style:z,children:h.col.auditor}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.auditor||x.name,disabled:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:z,children:[h.col.manager," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(ue,{value:e.manager,onChange:S=>o({manager:S}),items:C,placeholder:"-- Select Manager --",disabled:a})]})]}),n.jsx("div",{style:pu,children:n.jsxs("div",{children:[n.jsx("label",{style:z,children:h.col.organization}),n.jsx(It,{value:e.organization,onChange:S=>o({organization:S}),organizations:l,placeholder:"-- All Organizations --",disabled:a})]})}),n.jsxs("div",{style:{marginTop:8},children:[n.jsxs("label",{style:z,children:[h.col.functions," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,marginTop:6},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,cursor:a?"default":"pointer"},children:[n.jsx("input",{type:"checkbox",style:Ql,checked:!!e.create_processes,disabled:a,onChange:S=>o({create_processes:S.target.checked?1:0})}),n.jsx("span",{style:{fontSize:14},children:"Create Processes"})]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,cursor:a?"default":"pointer"},children:[n.jsx("input",{type:"checkbox",style:Ql,checked:!!e.update_process_status,disabled:a,onChange:S=>o({update_process_status:S.target.checked?1:0})}),n.jsx("span",{style:{fontSize:14},children:"Update Process Status"})]})]})]}),!a&&n.jsxs("div",{style:{marginTop:20},children:[n.jsx("label",{style:z,children:"Remarks"}),n.jsx("textarea",{style:{...E,...m,minHeight:70,resize:"vertical"},value:e.remarks||"",onChange:S=>o({remarks:S.target.value}),placeholder:"Optional note for the Manager…"})]}),a&&(((R=e.delegation_log)==null?void 0:R.length)??0)>0&&n.jsxs("div",{style:{marginTop:28},children:[n.jsx("label",{style:z,children:"Audit Trail"}),n.jsx("div",{style:{background:"white",borderRadius:8,border:"1px solid #eee",overflow:"hidden"},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa"},children:[n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Action"}),n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Actor"}),n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Timestamp"}),n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Remarks"})]})}),n.jsx("tbody",{children:(e.delegation_log||[]).map((S,_)=>n.jsxs("tr",{style:{borderTop:"1px solid #f0f0f0"},children:[n.jsx("td",{style:{padding:"8px 14px",fontWeight:600},children:S.action}),n.jsx("td",{style:{padding:"8px 14px"},children:S.actor}),n.jsx("td",{style:{padding:"8px 14px",color:"#666"},children:a1(S.timestamp)}),n.jsx("td",{style:{padding:"8px 14px",color:"#666"},children:S.remarks||"—"})]},S.name||_))})]})})]})]})}const hu={process:"processes-form",order:"orders-form",incident:"incidents-form",idea:"ideas-form"},Ta={process:U.blue,order:U.purple,incident:U.red,idea:U.green,delegation:U.orange};function c1({onNavigate:e,onRefresh:t}){const l=Z(),[s,r]=j.useState([]),[i,a]=j.useState(!0),[d,u]=j.useState(""),[f,y]=j.useState(""),p=()=>hy().then(b=>{r(b),a(!1)});j.useEffect(()=>{p()},[]);const c=s.filter(b=>b.requires_action),v=s.filter(b=>!b.requires_action),w=async(b,x)=>{u(b),y("");try{await xy(b,x),await p(),t==null||t()}catch{y(b)}u("")};function g(b,x){return x.length===0?null:n.jsxs("div",{style:{marginBottom:24},children:[n.jsxs("h3",{style:{fontSize:14,fontWeight:700,color:"#555",marginBottom:12,textTransform:"uppercase",letterSpacing:1},children:[b," (",x.length,")"]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:x.map((h,o)=>{const m=h.type!=="delegation";return n.jsxs("div",{onClick:m?()=>e(hu[h.type],h.name):void 0,style:{background:"white",borderRadius:10,padding:"14px 18px",boxShadow:"0 1px 4px rgba(0,0,0,0.07)",display:"flex",alignItems:"center",gap:16,borderLeft:`4px solid ${Ta[h.type]||U.gray}`,cursor:m?"pointer":"default",transition:"box-shadow 0.15s, transform 0.15s"},onMouseEnter:m?C=>{C.currentTarget.style.boxShadow="0 4px 14px rgba(0,0,0,0.12)",C.currentTarget.style.transform="translateY(-1px)"}:void 0,onMouseLeave:m?C=>{C.currentTarget.style.boxShadow="0 1px 4px rgba(0,0,0,0.07)",C.currentTarget.style.transform="none"}:void 0,children:[n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[n.jsx("span",{style:{fontSize:11,fontWeight:700,color:"white",background:Ta[h.type]||U.gray,padding:"2px 8px",borderRadius:10},children:h.type.toUpperCase()}),n.jsx("span",{style:{fontWeight:700,fontSize:14},children:h.number}),n.jsx("span",{style:{fontSize:13,color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.title})]}),n.jsxs("div",{style:{marginTop:4,fontSize:12,color:"#888"},children:[h.action," ",h.organization?`· ${h.organization}`:""," ",h.date?`· ${h.date}`:""]}),f===h.name&&n.jsx("div",{style:{marginTop:4,fontSize:12,color:"#e74c3c"},children:"Failed to respond — please try again."})]}),h.type==="delegation"?n.jsxs("div",{style:{display:"flex",gap:8,flexShrink:0},children:[n.jsx("button",{onClick:()=>w(h.name,"Accepted"),disabled:d===h.name,style:{padding:"7px 16px",borderRadius:8,border:"none",background:U.green,color:"white",fontWeight:600,fontSize:13,cursor:d===h.name?"wait":"pointer",opacity:d===h.name?.6:1},children:"Accept"}),n.jsx("button",{onClick:()=>w(h.name,"Rejected"),disabled:d===h.name,style:{padding:"7px 16px",borderRadius:8,border:"none",background:U.red,color:"white",fontWeight:600,fontSize:13,cursor:d===h.name?"wait":"pointer",opacity:d===h.name?.6:1},children:"Reject"})]}):n.jsx("button",{onClick:C=>{C.stopPropagation(),e(hu[h.type],h.name)},style:{padding:"7px 16px",borderRadius:8,border:"none",background:Ta[h.type]||U.accent,color:"white",fontWeight:600,fontSize:13,cursor:"pointer",flexShrink:0},children:h.requires_action?"Act":l.view})]},o)})})]})}return n.jsxs("div",{style:{maxWidth:900,margin:"0 auto"},children:[i&&n.jsx("p",{style:{color:"#888"},children:l.loading}),!i&&s.length===0&&n.jsxs("div",{style:{background:"white",borderRadius:12,padding:48,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("div",{style:{fontSize:48,marginBottom:12},children:"📥"}),n.jsx("p",{style:{fontSize:16},children:l.inbox.noMessages})]}),!i&&g("Needs Action",c),!i&&g("Informational",v)]})}const d1=[{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"]}],$f={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 u1(e,t){const l=e.map(r=>$f[r]||r).join(","),s=t.map(r=>e.map(i=>`"${r[i]??""}"`).join(",")).join(` `);return l+` `+s}function p1(e,t){const l=new Blob([e],{type:"text/csv"}),s=URL.createObjectURL(l),r=document.createElement("a");r.href=s,r.download=t,r.click(),URL.revokeObjectURL(s)}const Uf="report-print-area",Pa="report-print-portal";function f1(){const e=document.getElementById(Uf);if(!e)return;const t=document.createElement("div");t.id=Pa,t.innerHTML=e.innerHTML,document.body.appendChild(t);const l=document.createElement("style");l.id="report-print-style",l.textContent=` #${Pa} { display: none; } @media print { #root { display: none !important; } #${Pa} { display: block !important; } } `,document.head.appendChild(l);const s=()=>{t.remove(),l.remove(),window.removeEventListener("afterprint",s)};window.addEventListener("afterprint",s),window.print()}const gu={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",minWidth:180},Ia={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white"};function h1({organizations:e,userRole:t}){const l=Z(),s=d1.filter(_=>_.roles.includes(t)),[r,i]=j.useState(""),[a,d]=j.useState(""),[u,f]=j.useState(""),[y,p]=j.useState(""),[c,v]=j.useState(String(new Date().getFullYear())),[w,g]=j.useState([]),[b,x]=j.useState([]),[h,o]=j.useState(!1),[m,C]=j.useState(""),P=s.find(_=>_.id===r);async function R(){if(r){o(!0),C(""),x([]),g([]);try{const _={};a&&(_.organization=a),u&&(_.from_date=u),y&&(_.to_date=y),(P==null?void 0:P.extraFilter)==="year"&&c&&(_.year=c);const $=await fy(r,_);g($.columns||[]),x($.rows||[])}catch(_){C(_.message||"Error running report")}finally{o(!1)}}}const S=(P==null?void 0:P.label)||r;return n.jsxs("div",{children:[n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12,marginBottom:20},children:s.map(_=>n.jsxs("div",{onClick:()=>i(_.id),style:{background:r===_.id?"#ebf5fb":"white",border:r===_.id?`2px solid ${U.accent}`:"2px solid transparent",borderRadius:10,padding:"14px 16px",cursor:"pointer",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[n.jsx("div",{style:{fontWeight:700,fontSize:14,color:"#1a2332",marginBottom:4},children:_.label}),n.jsx("div",{style:{fontSize:12,color:"#888"},children:_.description})]},_.id))}),n.jsx("div",{style:{background:"white",borderRadius:12,padding:20,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:20},children:n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"REPORT"}),n.jsxs("select",{style:gu,value:r,onChange:_=>i(_.target.value),children:[n.jsx("option",{value:"",children:"-- Select Report --"}),s.map(_=>n.jsx("option",{value:_.id,children:_.label},_.id))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"ORGANIZATION"}),n.jsxs("select",{style:gu,value:a,onChange:_=>d(_.target.value),children:[n.jsx("option",{value:"",children:l.filter.allOrgs}),e.map(_=>n.jsx("option",{value:_.name,children:_.organization_name||_.name},_.name))]})]}),(P==null?void 0:P.extraFilter)==="year"?n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"YEAR"}),n.jsx("input",{type:"number",style:{...Ia,width:90},value:c,onChange:_=>v(_.target.value),min:2020,max:2099})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"FROM"}),n.jsx(xe,{value:u,onChange:f,style:Ia})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"TO"}),n.jsx(xe,{value:y,onChange:p,style:Ia})]})]}),n.jsx("button",{onClick:R,disabled:!r||h,style:{padding:"9px 20px",borderRadius:8,border:"none",background:U.accent,color:"white",fontWeight:700,fontSize:13,cursor:r?"pointer":"not-allowed",opacity:r?1:.5},children:h?l.loading:l.reports.generate}),b.length>0&&n.jsx("button",{onClick:()=>p1(u1(w,b),`${r}.csv`),style:{padding:"9px 20px",borderRadius:8,border:"1px solid #27ae60",background:"white",color:"#27ae60",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Export CSV"}),b.length>0&&n.jsx("button",{onClick:f1,style:{padding:"9px 20px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Print / PDF"})]})}),m&&n.jsx("div",{style:{color:"#e74c3c",marginBottom:16},children:m}),b.length>0&&n.jsxs("div",{id:Uf,style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto"},children:[n.jsxs("div",{style:{padding:"14px 18px",borderBottom:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("span",{style:{fontWeight:700,color:"#333"},children:S}),n.jsxs("span",{style:{fontSize:12,color:"#888"},children:[b.length," rows"]})]}),n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa"},children:w.map(_=>n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700,whiteSpace:"nowrap"},children:$f[_]||_.replace(/_/g," ").toUpperCase()},_))})}),n.jsx("tbody",{children:b.map((_,$)=>n.jsx("tr",{style:{borderTop:"1px solid #f0f0f0",background:$%2===0?"white":"#fafafa"},children:w.map(T=>n.jsx("td",{style:{padding:"10px 14px",color:"#333"},children:_[T]!=null?String(_[T]):"—"},T))},$))})]})]}),!h&&b.length===0&&r&&!m&&n.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."}),s.length===0&&n.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 dr=()=>new Date().toISOString().split("T")[0],bc=()=>new Date(Date.now()+30*24*60*60*1e3).toISOString().split("T")[0],Vt=()=>({name:"",number:"",title:"",organization:"",type:"",incident_class:"",incident_field:"",date:dr(),time:"",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:""}),en=()=>({name:"",number:"",title:"",organization:"",type:"",management:"",department:"",section_field:"",branch:"",current_condition:"",proposed_condition:"",status:"",assigned_to:"",workflow_state:"New",idea_class:"",hses_field:"",date:dr(),priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:""}),tn=()=>({name:"",number:"",title:"",organization:"",type:"Buy L",management:"",department:"",section_field:"",branch:"",starting_date:dr(),ending_date:bc(),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:""}),Ur=()=>({name:"",title:"",date_start:dr(),date_end:bc(),number:"",status:"",cycle_type:"Normal",organization:"",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:""}),ms=()=>({name:"",organization_name:"",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}),hl=()=>({name:"",organization:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),gl=()=>({name:"",custom_organization:"",department_name:"",custom_management:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),xl=()=>({name:"",organization:"",branch:"",management:"",department:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),ys=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),vs=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),js=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),bs=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Ss=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),ws=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),ks=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),_s=()=>({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_management:"",custom_department:"",custom_branch:"",custom_number:"",custom_category:""}),ml=()=>({name:"",name1:"",organization:"",frequency:"Monthly",status:"Active",start_date:dr(),end_date:bc(),update_window_days:2}),yl=()=>({name:"",organization:"",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}),Cs=()=>({name:"",number:"",auditor:"",manager:"",organization:"",create_processes:0,update_process_status:0,status:"Pending",requested_on:"",remarks:""}),g1=new Set(["incidents","incidents-form","ideas","ideas-form"]),x1=new Set(["orders","orders-form","incidents","incidents-form","ideas","ideas-form"]),m1=new Set(["Admin","Owner","Auditor","Manager"]),y1=new Set(["Admin","Owner","Auditor","Manager"]),v1=new Set(["Admin","Auditor","Manager"]);function j1({user:e,onLogout:t,darkMode:l,onToggleDark:s}){const r=Z(),i=e.role,a=m1.has(i),d=y1.has(i),u=v1.has(i),f=k=>k==="users"||k==="users-form"?i==="Admin":i==="Admin"||i==="Auditor"?!0:i==="Owner"||i==="XAuditor"?!1:i==="Manager"?!!(x1.has(k)||(k==="processes"||k==="processes-form")&&kc.includes("create_processes")):g1.has(k),y=k=>i==="Employee"&&!!k&&k!=="New",[p,c]=j.useState(a?"dashboard":"inbox"),[v,w]=j.useState(""),[g,b]=j.useState("");j.useEffect(()=>{if(!g)return;const k=setTimeout(()=>b(""),0);return()=>clearTimeout(k)},[g]);const x=(k,X)=>{b(X),c(k)},[h,o]=j.useState(0),[m,C]=j.useState([]),[P,R]=j.useState([]),[S,_]=j.useState([]),[$,T]=j.useState([]),[I,N]=j.useState([]),[F,ne]=j.useState([]),[ee,me]=j.useState([]),[A,Q]=j.useState([]),[G,V]=j.useState([]),[q,ge]=j.useState([]),[Ce,se]=j.useState([]),[je,Qe]=j.useState([]),[H,re]=j.useState([]),[D,le]=j.useState([]),[wt,Yt]=j.useState([]),[O,L]=j.useState([]),[K,Jl]=j.useState([]),[hn,Qi]=j.useState([]),[ll,ur]=j.useState([]),[W,ht]=j.useState({}),[$t,gn]=j.useState([]),[pr,Ff]=j.useState([]),[Sc,Mf]=j.useState([]),[wc,Hf]=j.useState([]),[kc,Kf]=j.useState([]),[_c,Qf]=j.useState({}),[we,de]=j.useState(!0),[Oe,ie]=j.useState("idle"),[De,oe]=j.useState(!1),[Cc,zc]=j.useState(!1),[fr,Tc]=j.useState(null),[Gf,Yf]=j.useState(()=>localStorage.getItem("sb_sidebar")==="1"),Xf=()=>Yf(k=>{const X=!k;return localStorage.setItem("sb_sidebar",X?"1":"0"),X}),[Jf,Gi]=j.useState(!1);j.useEffect(()=>{Gi(!1)},[p]);const[sl,Xt]=j.useState(Vt()),[rl,Jt]=j.useState(en()),[hr,qt]=j.useState(tn()),[gr,Ut]=j.useState(Ur()),[Pc,ql]=j.useState(ms()),[Ic,il]=j.useState(hl()),[Ec,al]=j.useState(gl()),[Ac,ol]=j.useState(xl()),[Rc,Zl]=j.useState(ys()),[Lc,Vl]=j.useState(vs()),[Oc,es]=j.useState(js()),[Dc,ts]=j.useState(bs()),[Nc,ns]=j.useState(Ss()),[Wc,ls]=j.useState(ws()),[Bc,ss]=j.useState(ks()),[$c,rs]=j.useState(_s()),[xr,mr]=j.useState(Fr()),[Uc,cl]=j.useState(ml()),[Fc,dl]=j.useState(yl()),[ul,is]=j.useState(Cs()),Ft=async()=>{de(!0);try{const[k,X,gt,Et,xn,Ne,qi,Kh,Qh,Gh,Yh,Xh,Jh,qh,Zh,Vh,eg,tg,ng,lg,sg,rg,ig,ag,og,cg]=await Promise.all([ke(B.incidents),ke(B.organizations),ke(B.ideas),ke(B.orders),ke(B.processes),Jm(),ke(B.managements),ke(B.departments),ke(B.branches),ke(B.incidentTypes),ke(B.incidentClass),ke(B.incidentField),ke(B.ideaTypes),ke(B.orderTypes),ke(B.processTypes),ke(B.incidentStatuses),ke(B.ideaStatuses),ke(B.orderStatuses),ke(B.processStatuses),ey(),ty(),ke(B.cycles),ke(B.kpiInput),yy(),jy(),by()]);C(k||[]),R(X||[]),_(gt||[]),T(Et||[]),N(xn||[]),gn(Ne||[]),ne(qi||[]),me(Kh||[]),Q(Qh||[]),V(Gh||[]),ge(Yh||[]),se(Xh||[]),Qe(Jh||[]),re(qh||[]),le(Zh||[]),Yt(Vh||[]),L(eg||[]),Jl(tg||[]),Qi(ng||[]),ur(lg||[]),ht(sg||{}),Ff(rg||[]),Mf(ig||[]),Hf(ag||[]),Kf(og||[]),Qf(cg||{})}catch(k){console.error("Error loading data:",k)}de(!1)},qf=async()=>{try{const k=await fetch("/api/method/sidrah_business.api.get_notification_count",{credentials:"include",headers:{Accept:"application/json"}});if(k.ok){const X=await k.json();o(Number(X.message)||0)}}catch{}};j.useEffect(()=>{Ft(),qf()},[e.name]);const Me=async(k,X)=>{if(window.confirm(r.rtl?"هل أنت متأكد من حذف هذا السجل؟":"Are you sure you want to delete this record?")){de(!0);try{await Lf(k,X),await Ft()}catch(gt){console.error("Delete error:",gt),alert((gt==null?void 0:gt.message)||"Delete failed. Please try again.")}de(!1)}},Zf=async k=>{try{await ry(k),await Ft()}catch(X){console.error("Disable user error:",X)}},Vf=async k=>{oe(!0),de(!0);try{const X=await xt(B.incidents,k.name);Xt({...Vt(),...X})}catch{Xt({...Vt(),...k})}c("incidents-form"),de(!1)},eh=async k=>{oe(!0),de(!0);try{const X=await xt(B.ideas,k.name);Jt({...en(),...X})}catch{Jt({...en(),...k})}c("ideas-form"),de(!1)},th=async k=>{oe(!0),de(!0);try{const X=await xt(B.orders,k.name);qt({...tn(),...X})}catch{qt({...tn(),...k})}c("orders-form"),de(!1)},nh=async k=>{oe(!0),de(!0);try{const X=await Es(k.name);Ut({...X,progress_indicators:X.progress_indicators||[],cycle_logs:X.cycle_logs||[]}),c("processes-form")}catch{Ut({...k,progress_indicators:k.progress_indicators||[]}),c("processes-form")}de(!1)},lh=k=>ye(B.organizations,k,ql,ms(),"organizations-form",!0),sh=async k=>{oe(!0),de(!0);try{const X=await xt(B.managements,k.name);il({...hl(),...X})}catch{il({...hl(),...k})}c("managements-form"),de(!1)},rh=async k=>{oe(!0),de(!0);try{const X=await xt(B.departments,k.name);al({...gl(),...X})}catch{al({...gl(),...k})}c("departments-form"),de(!1)},ih=async k=>{oe(!0),de(!0);try{const X=await xt(B.branches,k.name);ol({...xl(),...X})}catch{ol({...xl(),...k})}c("branches-form"),de(!1)},ah=async k=>{oe(!0),de(!0);try{const X=await xt(B.cycles,k.name);cl({...ml(),...X})}catch{cl({...ml(),...k})}c("cycles-form"),de(!1)},oh=async k=>{oe(!0),de(!0);try{const X=await xt(B.kpiInput,k.name);dl({...yl(),...X})}catch{dl({...yl(),...k})}c("kpi-input-form"),de(!1)},Ge=async(k,X,gt,Et,xn)=>{ie("loading");try{if(X.name)await _i(k,X.name,X),ie("success"),Ft(),setTimeout(()=>{ie("idle"),c(Et)},1500);else if(xn){const Ne=await ka(k,X);xn(Ne),ie("success"),Ft(),setTimeout(()=>ie("idle"),1500)}else await ka(k,X),gt(),ie("success"),Ft(),setTimeout(()=>{ie("idle"),c(Et)},1500)}catch(Ne){console.error("Submit error:",Ne),ie(Ne instanceof Error?Ne.message:"Error saving. Please try again.")}},Ae=async()=>{await Zm(),t()},ye=async(k,X,gt,Et,xn,Ne)=>{oe(Ne),de(!0);try{const qi=await xt(k,X.name);gt({...Et,...qi})}catch{gt({...Et,...X})}c(xn),de(!1)},ch=k=>ye(B.incidents,k,Xt,Vt(),"incidents-form",!1),dh=k=>ye(B.ideas,k,Jt,en(),"ideas-form",!1),uh=k=>ye(B.orders,k,qt,tn(),"orders-form",!1),ph=k=>{oe(!1),de(!0),Es(k.name).then(X=>{Ut({...X,progress_indicators:X.progress_indicators||[],cycle_logs:X.cycle_logs||[]})}).catch(()=>{Ut({...k,progress_indicators:k.progress_indicators||[]})}).finally(()=>{c("processes-form"),de(!1)})},fh=k=>ye(B.organizations,k,ql,ms(),"organizations-form",!1),hh=k=>ye(B.managements,k,il,hl(),"managements-form",!1),gh=k=>ye(B.departments,k,al,gl(),"departments-form",!1),xh=k=>ye(B.branches,k,ol,xl(),"branches-form",!1),mh=k=>ye(B.cycles,k,cl,ml(),"cycles-form",!1),yh=k=>ye(B.kpiInput,k,dl,yl(),"kpi-input-form",!1),vh=async k=>{oe(!0),de(!0);try{const X=await vy(k.name);is({...Cs(),...X})}catch{is({...Cs(),...k})}c("delegations-form"),de(!1)},jh=async()=>{ie("loading");try{const k=[];ul.create_processes&&k.push("create_processes"),ul.update_process_status&&k.push("update_process_status"),await gy(ul.manager,k,ul.organization,ul.remarks),is(Cs()),ie("success"),Ft(),setTimeout(()=>{ie("idle"),c("delegations")},1500)}catch(k){console.error("Delegation submit error:",k),ie(k instanceof Error?k.message:"Error saving. Please try again.")}},bh=async k=>{if(window.confirm(r.rtl?"هل أنت متأكد من إلغاء هذا التفويض؟":"Are you sure you want to revoke this delegation?")){de(!0);try{await my(k),await Ft()}catch(X){console.error("Revoke delegation error:",X),alert(X instanceof Error?X.message:"Revoke failed. Please try again.")}de(!1)}},Sh=k=>ye(B.incidentTypes,k,Zl,ys(),"incident-types-form",!0),wh=k=>ye(B.incidentTypes,k,Zl,ys(),"incident-types-form",!1),kh=k=>ye(B.ideaTypes,k,Vl,vs(),"idea-types-form",!0),_h=k=>ye(B.ideaTypes,k,Vl,vs(),"idea-types-form",!1),Ch=k=>ye(B.orderTypes,k,es,js(),"order-types-form",!0),zh=k=>ye(B.orderTypes,k,es,js(),"order-types-form",!1),Th=k=>ye(B.processTypes,k,ts,bs(),"process-types-form",!0),Ph=k=>ye(B.processTypes,k,ts,bs(),"process-types-form",!1),Ih=k=>ye(B.incidentStatuses,k,ns,Ss(),"incident-statuses-form",!0),Eh=k=>ye(B.incidentStatuses,k,ns,Ss(),"incident-statuses-form",!1),Ah=k=>ye(B.ideaStatuses,k,ls,ws(),"idea-statuses-form",!0),Rh=k=>ye(B.ideaStatuses,k,ls,ws(),"idea-statuses-form",!1),Lh=k=>ye(B.orderStatuses,k,ss,ks(),"order-statuses-form",!0),Oh=k=>ye(B.orderStatuses,k,ss,ks(),"order-statuses-form",!1),Dh=k=>ye(B.processStatuses,k,rs,_s(),"process-statuses-form",!0),Nh=k=>ye(B.processStatuses,k,rs,_s(),"process-statuses-form",!1),Wh=async k=>{Tc(k),c("profile")},Bh=k=>{oe(!1),zc(!1),mr({...Fr(),...k}),c("users-form")},$h=async()=>{ie("loading");try{if(!xr.name)await ka("User",{...xr,send_welcome_email:0,user_type:"System User"});else{const{name:X,email:gt,creation:Et,full_name:xn,...Ne}=xr;await _i("User",X,Ne)}mr(Fr()),ie("success"),Ft(),setTimeout(()=>{ie("idle"),c("users")},1500)}catch(k){console.error("User submit error:",k),ie(k instanceof Error?k.message:"Error saving. Please try again.")}},Re=()=>{const k=ll.find(X=>X.name===e.name||X.username===e.name);Tc(k||{name:e.name,full_name:e.full_name,email:e.name,enabled:1}),c("profile")},Yi=(k,X)=>{if(X){const Et={"processes-form":B.processes,"orders-form":B.orders,"incidents-form":B.incidents,"ideas-form":B.ideas}[k];if(Et){oe(!0),de(!0),(k==="processes-form"?Es(X).then(Ne=>({...Ne,progress_indicators:Ne.progress_indicators||[],cycle_logs:Ne.cycle_logs||[]})):xt(Et,X)).then(Ne=>{k==="processes-form"?Ut(Ne):k==="orders-form"?qt({...tn(),...Ne}):k==="incidents-form"?Xt({...Vt(),...Ne}):k==="ideas-form"&&Jt({...en(),...Ne}),c(k),de(!1)}).catch(()=>{c(k),de(!1)});return}}c(k)};if(p==="incidents-form")return n.jsx(Ky,{incForm:sl,setIncForm:Xt,organizations:P,managements:F,departments:ee,branches:A,incidentTypes:G,incidentClasses:q,incidentFields:Ce,incidentStatuses:wt,users:$t,userRoleMap:W,formStatus:Oe,viewMode:De||!f("incidents-form")||y(sl.workflow_state),onEdit:f("incidents-form")&&!y(sl.workflow_state)?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,userRole:i,onSubmit:()=>Ge(B.incidents,sl,()=>Xt(Vt()),"incidents",k=>Xt({...Vt(),...k})),onBack:()=>{c("incidents"),ie("idle")},onNavigate:c,onLogout:Ae,user:e,onRefresh:async()=>{if(sl.name){const k=await xt(B.incidents,sl.name).catch(()=>null);k&&Xt({...Vt(),...k})}ke(B.incidents).then(k=>C(k||[])).catch(()=>{})}});if(p==="ideas-form")return n.jsx(Xy,{ideaForm:rl,setIdeaForm:Jt,organizations:P,managements:F,departments:ee,branches:A,ideaTypes:je,ideaStatuses:O,users:$t,userRoleMap:W,formStatus:Oe,viewMode:De||!f("ideas-form")||y(rl.workflow_state),onEdit:f("ideas-form")&&!y(rl.workflow_state)?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,userRole:i,onSubmit:()=>Ge(B.ideas,rl,()=>Jt(en()),"ideas",k=>Jt({...en(),...k})),onBack:()=>{c("ideas"),ie("idle")},onNavigate:c,onLogout:Ae,user:e,onRefresh:async()=>{if(rl.name){const k=await xt(B.ideas,rl.name).catch(()=>null);k&&Jt({...en(),...k})}ke(B.ideas).then(k=>_(k||[])).catch(()=>{})}});if(p==="orders-form")return n.jsx(e0,{orderForm:hr,setOrderForm:qt,organizations:P,managements:F,departments:ee,branches:A,orderTypes:H,orderStatuses:K,cycles:pr,users:$t,userRoleMap:W,formStatus:Oe,viewMode:De||!f("orders-form"),onEdit:f("orders-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,currentUser:e.name,userRole:i,onSubmit:()=>Ge(B.orders,hr,()=>qt(tn()),"orders",k=>qt({...tn(),...k})),onBack:()=>{c("orders"),ie("idle")},onNavigate:c,onLogout:Ae,user:e,onRefresh:async()=>{if(hr.name){const k=await xt(B.orders,hr.name).catch(()=>null);k&&qt({...tn(),...k})}ke(B.orders).then(k=>T(k||[])).catch(()=>{})}});if(p==="processes-form")return n.jsx(r0,{processForm:gr,setProcessForm:Ut,organizations:P,managements:F,departments:ee,branches:A,processTypes:D,processStatuses:hn,cycles:pr,users:$t,userRoleMap:W,formStatus:Oe,viewMode:De||!f("processes-form"),onEdit:f("processes-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,userRole:e.role,delegatedFunctions:kc,delegatedOrgs:_c.create_processes,onRefreshProcess:async()=>{if(gr.name)try{const k=await Es(gr.name);Ut({...k,progress_indicators:k.progress_indicators||[],cycle_logs:k.cycle_logs||[]})}catch{}ke(B.processes).then(k=>N(k||[])).catch(()=>{})},onSubmit:()=>Ge(B.processes,gr,()=>Ut(Ur()),"processes",k=>Ut({...Ur(),...k,progress_indicators:k.progress_indicators||[],cycle_logs:k.cycle_logs||[]})),onBack:()=>{c("processes"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="organizations-form")return n.jsx(u0,{orgForm:Pc,setOrgForm:ql,formStatus:Oe,viewMode:De||!f("organizations-form"),onEdit:f("organizations-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.organizations,Pc,()=>ql(ms()),"organizations"),onBack:()=>{c("organizations"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="managements-form")return n.jsx(h0,{form:Ic,setForm:il,organizations:P,formStatus:Oe,viewMode:De||!f("managements-form"),onEdit:f("managements-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.managements,Ic,()=>il(hl()),"managements"),onBack:()=>{c("managements"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="departments-form")return n.jsx(y0,{form:Ec,setForm:al,organizations:P,managements:F,formStatus:Oe,viewMode:De||!f("departments-form"),onEdit:f("departments-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.departments,Ec,()=>al(gl()),"departments"),onBack:()=>{c("departments"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="branches-form")return n.jsx(S0,{form:Ac,setForm:ol,organizations:P,managements:F,departments:ee,formStatus:Oe,viewMode:De||!f("branches-form"),onEdit:f("branches-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.branches,Ac,()=>ol(xl()),"branches"),onBack:()=>{c("branches"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="cycles-form")return n.jsx(e1,{form:Uc,setForm:cl,organizations:P,formStatus:Oe,viewMode:De||!f("cycles-form"),onEdit:f("cycles-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.cycles,Uc,()=>cl(ml()),"cycles"),onBack:()=>{c("cycles"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="kpi-input-form")return n.jsx(n1,{form:Fc,setForm:dl,organizations:P,formStatus:Oe,viewMode:De||!f("kpi-input-form"),onEdit:f("kpi-input-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.kpiInput,Fc,()=>dl(yl()),"kpi-input"),onBack:()=>{c("kpi-input"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="incident-types-form")return n.jsx(_0,{form:Rc,setForm:Zl,formStatus:Oe,viewMode:De||!f("incident-types-form"),onEdit:f("incident-types-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.incidentTypes,Rc,()=>Zl(ys()),"incident-types"),onBack:()=>{c("incident-types"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="idea-types-form")return n.jsx(T0,{form:Lc,setForm:Vl,formStatus:Oe,viewMode:De||!f("idea-types-form"),onEdit:f("idea-types-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.ideaTypes,Lc,()=>Vl(vs()),"idea-types"),onBack:()=>{c("idea-types"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="order-types-form")return n.jsx(E0,{form:Oc,setForm:es,formStatus:Oe,viewMode:De||!f("order-types-form"),onEdit:f("order-types-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.orderTypes,Oc,()=>es(js()),"order-types"),onBack:()=>{c("order-types"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="process-types-form")return n.jsx(L0,{form:Dc,setForm:ts,formStatus:Oe,viewMode:De||!f("process-types-form"),onEdit:f("process-types-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.processTypes,Dc,()=>ts(bs()),"process-types"),onBack:()=>{c("process-types"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="incident-statuses-form")return n.jsx(N0,{form:Nc,setForm:ns,formStatus:Oe,viewMode:De||!f("incident-statuses-form"),onEdit:f("incident-statuses-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.incidentStatuses,Nc,()=>ns(Ss()),"incident-statuses"),onBack:()=>{c("incident-statuses"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="idea-statuses-form")return n.jsx($0,{form:Wc,setForm:ls,formStatus:Oe,viewMode:De||!f("idea-statuses-form"),onEdit:f("idea-statuses-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.ideaStatuses,Wc,()=>ls(ws()),"idea-statuses"),onBack:()=>{c("idea-statuses"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="order-statuses-form")return n.jsx(M0,{form:Bc,setForm:ss,formStatus:Oe,viewMode:De||!f("order-statuses-form"),onEdit:f("order-statuses-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.orderStatuses,Bc,()=>ss(ks()),"order-statuses"),onBack:()=>{c("order-statuses"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="process-statuses-form")return n.jsx(Q0,{form:$c,setForm:rs,formStatus:Oe,viewMode:De||!f("process-statuses-form"),onEdit:f("process-statuses-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:()=>Ge(B.processStatuses,$c,()=>rs(_s()),"process-statuses"),onBack:()=>{c("process-statuses"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="users-form")return n.jsx(J0,{form:xr,setForm:mr,organizations:P,managements:F,departments:ee,branches:A,formStatus:Oe,viewMode:De||!f("users-form"),onEdit:f("users-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,isSelfProfile:Cc,onSubmit:$h,onBack:()=>{c(Cc?a?"dashboard":"inbox":"users"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});if(p==="delegations-form")return n.jsx(o1,{form:ul,setForm:is,organizations:P,users:$t,userRoleMap:W,formStatus:Oe,viewMode:De||!f("delegations-form"),onEdit:f("delegations-form")?()=>oe(!1):void 0,darkMode:l,notifCount:h,onToggleDark:s,onCountChange:o,onViewProfile:Re,onSubmit:jh,onBack:()=>{c("delegations"),ie("idle")},onNavigate:c,onLogout:Ae,user:e});const Uh=r.pages,Fh={incidents:{color:U.accent,formPage:"incidents-form",reset:()=>Xt({...Vt(),organization:v})},ideas:{color:U.teal,formPage:"ideas-form",reset:()=>Jt({...en(),organization:v})},orders:{color:U.purple,formPage:"orders-form",reset:()=>qt({...tn(),organization:v})},processes:{color:U.blue,formPage:"processes-form",reset:()=>{const k=_c.create_processes,X=i==="Manager"&&k&&k.length===1?k[0]:v;Ut({...Ur(),organization:X})}},organizations:{color:U.accent,formPage:"organizations-form",reset:()=>ql(ms())},managements:{color:U.blue,formPage:"managements-form",reset:()=>il({...hl(),organization:v})},departments:{color:U.teal,formPage:"departments-form",reset:()=>al({...gl(),custom_organization:v})},branches:{color:U.purple,formPage:"branches-form",reset:()=>ol({...xl(),organization:v})},cycles:{color:U.teal,formPage:"cycles-form",reset:()=>cl({...ml(),organization:v})},"kpi-input":{color:U.blue,formPage:"kpi-input-form",reset:()=>dl({...yl(),organization:v})},"incident-types":{color:U.red,formPage:"incident-types-form",reset:()=>Zl(ys())},"idea-types":{color:U.orange,formPage:"idea-types-form",reset:()=>Vl(vs())},"order-types":{color:U.green,formPage:"order-types-form",reset:()=>es(js())},"process-types":{color:U.accent,formPage:"process-types-form",reset:()=>ts(bs())},"incident-statuses":{color:U.red,formPage:"incident-statuses-form",reset:()=>ns(Ss())},"idea-statuses":{color:U.teal,formPage:"idea-statuses-form",reset:()=>ls(ws())},"order-statuses":{color:U.purple,formPage:"order-statuses-form",reset:()=>ss(ks())},"process-statuses":{color:U.blue,formPage:"process-statuses-form",reset:()=>rs(_s())},users:{color:U.blue,formPage:"users-form",reset:()=>{mr(Fr()),zc(!1)}},delegations:{color:U.purple,formPage:"delegations-form",reset:()=>is(Cs())}},Mh={incidents:r.formTitle.newIncident,ideas:r.formTitle.newIdea,orders:r.formTitle.newOrder,processes:r.formTitle.newProcess,organizations:r.formTitle.newOrg,managements:r.formTitle.newMgmt,departments:r.formTitle.newDept,branches:r.formTitle.newBranch,users:r.formTitle.newUser,cycles:r.formTitle.newCycle,"kpi-input":r.formTitle.newKpi,delegations:r.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"},Hh={incidents:m,ideas:S,orders:$,processes:I,organizations:P,managements:F,departments:ee,branches:A,cycles:pr,"kpi-input":Sc,"incident-types":G,"idea-types":je,"order-types":H,"process-types":D,"incident-statuses":wt,"idea-statuses":O,"order-statuses":K,"process-statuses":hn,users:ll,delegations:wc},$n=$m[p],Xi=Hh[p],J=f(p),Ji=J?Fh[p]:null;return n.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:l?"#0f172a":U.bg},children:[n.jsx(Ef,{collapsed:Gf,onToggleCollapsed:Xf,activePage:p,onNavigate:k=>c(k),hasDashboard:a,hasReports:d,hasDelegations:u,role:i,rtl:r.rtl,navLabels:r.nav,settingsLabel:r.nav.settings}),n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[n.jsx("div",{style:{background:l?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${l?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:l?"none":"0 1px 4px rgba(0,0,0,0.04)"},children:n.jsx(Wf,{notifCount:h,darkMode:l,onCountChange:o,onToggleDark:s,onNavigate:Yi,onViewProfile:Re,onLogout:Ae})}),p!=="profile"&&n.jsxs("div",{style:{background:l?"#1e293b":"white",padding:"9px 20px",borderBottom:`1px solid ${l?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[n.jsx("div",{style:{fontSize:15,fontWeight:700,color:l?"#e2e8f0":"#1e1b4b"},children:Uh[p]||p}),n.jsxs("div",{style:{display:"flex",gap:8},children:[$n&&Xi&&n.jsx("button",{onClick:()=>Gi(!0),style:{background:"#16a34a",color:"white",border:"none",padding:"6px 14px",borderRadius:7,fontSize:12,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"}),Ji&&n.jsxs("button",{onClick:()=>{Ji.reset(),oe(!1),ie("idle"),c(Ji.formPage)},style:{background:"#4f46e5",color:"white",border:"none",padding:"6px 14px",borderRadius:7,fontSize:12,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI"},children:["+ ",Mh[p]||r.new]})]})]}),$n&&Xi&&Jf&&n.jsx(Gm,{title:$n.label,rows:Xi,columns:$n.columns,defaultColumnKeys:$n.defaultColumns,orgField:$n.orgField,organizations:$n.orgField?P:void 0,filenameBase:p,onClose:()=>Gi(!1)}),n.jsxs("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",padding:p==="profile"?0:"20px 24px",gap:p==="profile"?0:16},children:[we&&n.jsx("div",{style:{textAlign:"center",paddingTop:60,color:"#aaa",fontSize:15},children:r.loading}),!we&&p==="dashboard"&&a&&n.jsx(Iy,{incidents:m,ideas:S,orders:$,processes:I,organizations:P,incidentStatuses:wt,ideaStatuses:O,orderStatuses:K,processStatuses:hn,selectedOrg:v,onOrgChange:w,onNavigate:Yi,onNavigateStatus:x,userRole:i}),!we&&p==="inbox"&&n.jsx(c1,{onNavigate:Yi,onRefresh:Ft}),!we&&p==="reports"&&d&&n.jsx(h1,{organizations:P,userRole:i}),!we&&p==="incidents"&&n.jsx(Oy,{incidents:m,organizations:P,departments:ee,branches:A,incidentStatuses:wt,initialOrg:v,initialStatus:g,onView:Vf,onEdit:J?ch:void 0,onDelete:J?k=>Me(B.incidents,k):void 0,canModify:J}),!we&&p==="ideas"&&n.jsx(Qy,{ideas:S,organizations:P,departments:ee,branches:A,ideaStatuses:O,initialOrg:v,initialStatus:g,onView:eh,onEdit:J?dh:void 0,onDelete:J?k=>Me(B.ideas,k):void 0,canModify:J}),!we&&p==="orders"&&n.jsx(Jy,{orders:$,organizations:P,departments:ee,branches:A,orderStatuses:K,initialOrg:v,initialStatus:g,onView:th,onEdit:J?uh:void 0,onDelete:J?k=>Me(B.orders,k):void 0,canModify:J}),!we&&p==="processes"&&n.jsx(t0,{processes:I,organizations:P,departments:ee,branches:A,processStatuses:hn,initialOrg:v,initialStatus:g,onView:nh,onEdit:J?ph:void 0,onDelete:J?k=>Me(B.processes,k):void 0,canModify:J}),!we&&p==="organizations"&&n.jsx(d0,{organizations:P,onView:lh,onEdit:J?fh:void 0,onDelete:J?k=>Me(B.organizations,k):void 0,canModify:J}),!we&&p==="managements"&&n.jsx(f0,{managements:F,onView:sh,onEdit:J?hh:void 0,onDelete:J?k=>Me(B.managements,k):void 0,canModify:J}),!we&&p==="departments"&&n.jsx(x0,{departments:ee,managements:F,onView:rh,onEdit:J?gh:void 0,onDelete:J?k=>Me(B.departments,k):void 0,canModify:J}),!we&&p==="branches"&&n.jsx(j0,{branches:A,managements:F,departments:ee,onView:ih,onEdit:J?xh:void 0,onDelete:J?k=>Me(B.branches,k):void 0,canModify:J}),!we&&p==="cycles"&&n.jsx(q0,{cycles:pr,canModify:J,onView:ah,onEdit:J?mh:void 0,onDelete:J?k=>Me(B.cycles,k):void 0}),!we&&p==="kpi-input"&&n.jsx(t1,{kpiInputs:Sc,canModify:J,onView:oh,onEdit:J?yh:void 0,onDelete:J?k=>Me(B.kpiInput,k):void 0}),!we&&p==="incident-types"&&n.jsx(k0,{incidentTypes:G,onView:Sh,onEdit:J?wh:void 0,onDelete:J?k=>Me(B.incidentTypes,k):void 0,canModify:J}),!we&&p==="idea-types"&&n.jsx(z0,{ideaTypes:je,onView:kh,onEdit:J?_h:void 0,onDelete:J?k=>Me(B.ideaTypes,k):void 0,canModify:J}),!we&&p==="order-types"&&n.jsx(I0,{orderTypes:H,onView:Ch,onEdit:J?zh:void 0,onDelete:J?k=>Me(B.orderTypes,k):void 0,canModify:J}),!we&&p==="process-types"&&n.jsx(R0,{processTypes:D,onView:Th,onEdit:J?Ph:void 0,onDelete:J?k=>Me(B.processTypes,k):void 0,canModify:J}),!we&&p==="incident-statuses"&&n.jsx(D0,{incidentStatuses:wt,onView:Ih,onEdit:J?Eh:void 0,onDelete:J?k=>Me(B.incidentStatuses,k):void 0,canModify:J}),!we&&p==="idea-statuses"&&n.jsx(B0,{ideaStatuses:O,onView:Ah,onEdit:J?Rh:void 0,onDelete:J?k=>Me(B.ideaStatuses,k):void 0,canModify:J}),!we&&p==="order-statuses"&&n.jsx(F0,{orderStatuses:K,onView:Lh,onEdit:J?Oh:void 0,onDelete:J?k=>Me(B.orderStatuses,k):void 0,canModify:J}),!we&&p==="process-statuses"&&n.jsx(K0,{processStatuses:hn,onView:Dh,onEdit:J?Nh:void 0,onDelete:J?k=>Me(B.processStatuses,k):void 0,canModify:J}),!we&&p==="users"&&n.jsx(X0,{users:ll,roleMap:W,onView:Wh,onEdit:J?Bh:void 0,onDelete:J?k=>Me("User",k):void 0,onDisable:J?Zf:void 0,canModify:J}),!we&&p==="delegations"&&u&&n.jsx(i1,{delegations:wc,organizations:P,userRole:i,currentUser:e.name,onView:vh,onRevoke:J?bh:void 0}),p==="profile"&&(()=>{const k=!!fr&&(fr.name===e.name||fr.email===e.name);return n.jsx(a0,{user:e,profileUser:fr,sbUsers:ll,organizations:P,managements:F,departments:ee,branches:A,darkMode:l,canModify:J||k,onBack:()=>c(k?a?"dashboard":"inbox":"users"),onNavigate:c})})()]})]})]})}function b1(e){return e.some(t=>["SB Admin","System Manager"].includes(t))?"Admin":e.includes("SB Auditor")?"Auditor":e.includes("SB Owner")?"Owner":e.includes("SB X-Auditor")?"XAuditor":e.includes("SB Manager")?"Manager":"Employee"}function S1(){const[e,t]=j.useState(()=>{try{const d=localStorage.getItem("sidrah_user");return d?JSON.parse(d):null}catch{return null}}),[l,s]=j.useState(()=>localStorage.getItem("sb_dark")==="1"),r=()=>{const d=!l;s(d),localStorage.setItem("sb_dark",d?"1":"0"),document.documentElement.classList.toggle("dark",d)};j.useEffect(()=>{document.documentElement.classList.toggle("dark",l)},[]),j.useEffect(()=>{e&&Of().then(async d=>{const u=d||e.name,f=await Nf(u);if(!f.length)return;const y=b1(f);if(y!==e.role||u!==e.name){const c={...e,name:u,role:y};t(c),localStorage.setItem("sidrah_user",JSON.stringify(c))}})},[e==null?void 0:e.name]);const i=d=>{t(d),localStorage.setItem("sidrah_user",JSON.stringify(d))},a=()=>{t(null),localStorage.removeItem("sidrah_user")};return e?n.jsx(j1,{user:e,onLogout:a,darkMode:l,onToggleDark:r}):n.jsx(ky,{onLogin:i})}Pf(document.getElementById("root")).render(n.jsx(j.StrictMode,{children:n.jsx(S1,{})}));