(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))l(r);new MutationObserver(r=>{for(const a of r)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&l(i)}).observe(document,{childList:!0,subtree:!0});function s(r){const a={};return r.integrity&&(a.integrity=r.integrity),r.referrerPolicy&&(a.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?a.credentials="include":r.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function l(r){if(r.ep)return;r.ep=!0;const a=s(r);fetch(r.href,a)}})();var Fu={exports:{}},Ha={},Mu={exports:{}},ue={};/** * @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 zr=Symbol.for("react.element"),Bg=Symbol.for("react.portal"),$g=Symbol.for("react.fragment"),Ug=Symbol.for("react.strict_mode"),Fg=Symbol.for("react.profiler"),Mg=Symbol.for("react.provider"),Hg=Symbol.for("react.context"),Gg=Symbol.for("react.forward_ref"),Kg=Symbol.for("react.suspense"),Qg=Symbol.for("react.memo"),Yg=Symbol.for("react.lazy"),gc=Symbol.iterator;function Xg(e){return e===null||typeof e!="object"?null:(e=gc&&e[gc]||e["@@iterator"],typeof e=="function"?e:null)}var Hu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Gu=Object.assign,Ku={};function Il(e,n,s){this.props=e,this.context=n,this.refs=Ku,this.updater=s||Hu}Il.prototype.isReactComponent={};Il.prototype.setState=function(e,n){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,n,"setState")};Il.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Qu(){}Qu.prototype=Il.prototype;function Ko(e,n,s){this.props=e,this.context=n,this.refs=Ku,this.updater=s||Hu}var Qo=Ko.prototype=new Qu;Qo.constructor=Ko;Gu(Qo,Il.prototype);Qo.isPureReactComponent=!0;var xc=Array.isArray,Yu=Object.prototype.hasOwnProperty,Yo={current:null},Xu={key:!0,ref:!0,__self:!0,__source:!0};function qu(e,n,s){var l,r={},a=null,i=null;if(n!=null)for(l in n.ref!==void 0&&(i=n.ref),n.key!==void 0&&(a=""+n.key),n)Yu.call(n,l)&&!Xu.hasOwnProperty(l)&&(r[l]=n[l]);var d=arguments.length-2;if(d===1)r.children=s;else if(1>>1,V=X[W];if(0>>1;Wr(le,J))Ver(dt,le)?(X[W]=dt,X[Ve]=J,W=Ve):(X[W]=le,X[me]=J,W=me);else if(Ver(dt,J))X[W]=dt,X[Ve]=J,W=Ve;else break e}}return q}function r(X,q){var J=X.sortIndex-q.sortIndex;return J!==0?J:X.id-q.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var i=Date,d=i.now();e.unstable_now=function(){return i.now()-d}}var c=[],p=[],w=1,v=null,f=3,g=!1,S=!1,k=!1,y=typeof setTimeout=="function"?setTimeout:null,m=typeof clearTimeout=="function"?clearTimeout:null,o=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function u(X){for(var q=s(p);q!==null;){if(q.callback===null)l(p);else if(q.startTime<=X)l(p),q.sortIndex=q.expirationTime,n(c,q);else break;q=s(p)}}function h(X){if(k=!1,u(X),!S)if(s(c)!==null)S=!0,D(z);else{var q=s(p);q!==null&&Y(h,q.startTime-X)}}function z(X,q){S=!1,k&&(k=!1,m(x),x=-1),g=!0;var J=f;try{for(u(q),v=s(c);v!==null&&(!(v.expirationTime>q)||X&&!F());){var W=v.callback;if(typeof W=="function"){v.callback=null,f=v.priorityLevel;var V=W(v.expirationTime<=q);q=e.unstable_now(),typeof V=="function"?v.callback=V:v===s(c)&&l(c),u(q)}else l(c);v=s(c)}if(v!==null)var de=!0;else{var me=s(p);me!==null&&Y(h,me.startTime-q),de=!1}return de}finally{v=null,f=J,g=!1}}var j=!1,b=null,x=-1,I=5,E=-1;function F(){return!(e.unstable_now()-EX||125W?(X.sortIndex=J,n(p,X),s(c)===null&&X===s(p)&&(k?(m(x),x=-1):k=!0,Y(h,J-W))):(X.sortIndex=V,n(c,X),S||g||(S=!0,D(z))),X},e.unstable_shouldYield=F,e.unstable_wrapCallback=function(X){var q=f;return function(){var J=f;f=q;try{return X.apply(this,arguments)}finally{f=J}}}})(tp);ep.exports=tp;var ax=ep.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 ix=C,Ot=ax;function K(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),qi=Object.prototype.hasOwnProperty,ox=/^[: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]*$/,yc={},vc={};function dx(e){return qi.call(vc,e)?!0:qi.call(yc,e)?!1:ox.test(e)?vc[e]=!0:(yc[e]=!0,!1)}function cx(e,n,s,l){if(s!==null&&s.type===0)return!1;switch(typeof n){case"function":case"symbol":return!0;case"boolean":return l?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function ux(e,n,s,l){if(n===null||typeof n>"u"||cx(e,n,s,l))return!0;if(l)return!1;if(s!==null)switch(s.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function wt(e,n,s,l,r,a,i){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=l,this.attributeNamespace=r,this.mustUseProperty=s,this.propertyName=e,this.type=n,this.sanitizeURL=a,this.removeEmptyString=i}var pt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){pt[e]=new wt(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];pt[n]=new wt(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){pt[e]=new wt(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){pt[e]=new wt(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){pt[e]=new wt(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){pt[e]=new wt(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){pt[e]=new wt(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){pt[e]=new wt(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){pt[e]=new wt(e,5,!1,e.toLowerCase(),null,!1,!1)});var qo=/[\-:]([a-z])/g;function Jo(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var n=e.replace(qo,Jo);pt[n]=new wt(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(qo,Jo);pt[n]=new wt(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(qo,Jo);pt[n]=new wt(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){pt[e]=new wt(e,1,!1,e.toLowerCase(),null,!1,!1)});pt.xlinkHref=new wt("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){pt[e]=new wt(e,1,!1,e.toLowerCase(),null,!0,!0)});function Zo(e,n,s,l){var r=pt.hasOwnProperty(n)?pt[n]:null;(r!==null?r.type!==0:l||!(2d||r[i]!==a[d]){var c=` `+r[i].replace(" at new "," at ");return e.displayName&&c.includes("")&&(c=c.replace("",e.displayName)),c}while(1<=i&&0<=d);break}}}finally{wi=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?Xl(e):""}function px(e){switch(e.tag){case 5:return Xl(e.type);case 16:return Xl("Lazy");case 13:return Xl("Suspense");case 19:return Xl("SuspenseList");case 0:case 2:case 15:return e=ki(e.type,!1),e;case 11:return e=ki(e.type.render,!1),e;case 1:return e=ki(e.type,!0),e;default:return""}}function eo(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 tl:return"Fragment";case el:return"Portal";case Ji:return"Profiler";case Vo:return"StrictMode";case Zi:return"Suspense";case Vi:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case lp:return(e.displayName||"Context")+".Consumer";case sp:return(e._context.displayName||"Context")+".Provider";case ed:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case td:return n=e.displayName||null,n!==null?n:eo(e.type)||"Memo";case Wn:n=e._payload,e=e._init;try{return eo(e(n))}catch{}}return null}function fx(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return eo(n);case 8:return n===Vo?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function es(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function ap(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function hx(e){var n=ap(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),l=""+e[n];if(!e.hasOwnProperty(n)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var r=s.get,a=s.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return r.call(this)},set:function(i){l=""+i,a.call(this,i)}}),Object.defineProperty(e,n,{enumerable:s.enumerable}),{getValue:function(){return l},setValue:function(i){l=""+i},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function $r(e){e._valueTracker||(e._valueTracker=hx(e))}function ip(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),l="";return e&&(l=ap(e)?e.checked?"true":"false":e.value),e=l,e!==s?(n.setValue(e),!0):!1}function ya(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 to(e,n){var s=n.checked;return Le({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function bc(e,n){var s=n.defaultValue==null?"":n.defaultValue,l=n.checked!=null?n.checked:n.defaultChecked;s=es(n.value!=null?n.value:s),e._wrapperState={initialChecked:l,initialValue:s,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function op(e,n){n=n.checked,n!=null&&Zo(e,"checked",n,!1)}function no(e,n){op(e,n);var s=es(n.value),l=n.type;if(s!=null)l==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(l==="submit"||l==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?so(e,n.type,s):n.hasOwnProperty("defaultValue")&&so(e,n.type,es(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function Sc(e,n,s){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var l=n.type;if(!(l!=="submit"&&l!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,s||n===e.value||(e.value=n),e.defaultValue=n}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function so(e,n,s){(n!=="number"||ya(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var ql=Array.isArray;function fl(e,n,s,l){if(e=e.options,n){n={};for(var r=0;r"+n.valueOf().toString()+"",n=Ur.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function cr(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var er={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},gx=["Webkit","ms","Moz","O"];Object.keys(er).forEach(function(e){gx.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),er[n]=er[e]})});function pp(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||er.hasOwnProperty(e)&&er[e]?(""+n).trim():n+"px"}function fp(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var l=s.indexOf("--")===0,r=pp(s,n[s],l);s==="float"&&(s="cssFloat"),l?e.setProperty(s,r):e[s]=r}}var xx=Le({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 ao(e,n){if(n){if(xx[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(K(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(K(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(K(61))}if(n.style!=null&&typeof n.style!="object")throw Error(K(62))}}function io(e,n){if(e.indexOf("-")===-1)return typeof n.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var oo=null;function nd(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var co=null,hl=null,gl=null;function _c(e){if(e=Tr(e)){if(typeof co!="function")throw Error(K(280));var n=e.stateNode;n&&(n=Xa(n),co(e.stateNode,e.type,n))}}function hp(e){hl?gl?gl.push(e):gl=[e]:hl=e}function gp(){if(hl){var e=hl,n=gl;if(gl=hl=null,_c(e),n)for(e=0;e>>=0,e===0?32:31-(zx(e)/Ix|0)|0}var Fr=64,Mr=4194304;function Jl(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 Sa(e,n){var s=e.pendingLanes;if(s===0)return 0;var l=0,r=e.suspendedLanes,a=e.pingedLanes,i=s&268435455;if(i!==0){var d=i&~r;d!==0?l=Jl(d):(a&=i,a!==0&&(l=Jl(a)))}else i=s&~r,i!==0?l=Jl(i):a!==0&&(l=Jl(a));if(l===0)return 0;if(n!==0&&n!==l&&!(n&r)&&(r=l&-l,a=n&-n,r>=a||r===16&&(a&4194240)!==0))return n;if(l&4&&(l|=s&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=l;0s;s++)n.push(e);return n}function Ir(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-Zt(n),e[n]=s}function Ax(e,n){var s=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var l=e.eventTimes;for(e=e.expirationTimes;0=nr),Dc=" ",Lc=!1;function Lp(e,n){switch(e){case"keyup":return am.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Op(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var nl=!1;function om(e,n){switch(e){case"compositionend":return Op(n);case"keypress":return n.which!==32?null:(Lc=!0,Dc);case"textInput":return e=n.data,e===Dc&&Lc?null:e;default:return null}}function dm(e,n){if(nl)return e==="compositionend"||!cd&&Lp(e,n)?(e=Rp(),oa=id=Fn=null,nl=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1=n)return{node:s,offset:n-e};e=l}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=Bc(s)}}function $p(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?$p(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function Up(){for(var e=window,n=ya();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=ya(e.document)}return n}function ud(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function ym(e){var n=Up(),s=e.focusedElem,l=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&$p(s.ownerDocument.documentElement,s)){if(l!==null&&ud(s)){if(n=l.start,e=l.end,e===void 0&&(e=n),"selectionStart"in s)s.selectionStart=n,s.selectionEnd=Math.min(e,s.value.length);else if(e=(n=s.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var r=s.textContent.length,a=Math.min(l.start,r);l=l.end===void 0?a:Math.min(l.end,r),!e.extend&&a>l&&(r=l,l=a,a=r),r=$c(s,a);var i=$c(s,l);r&&i&&(e.rangeCount!==1||e.anchorNode!==r.node||e.anchorOffset!==r.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(n=n.createRange(),n.setStart(r.node,r.offset),e.removeAllRanges(),a>l?(e.addRange(n),e.extend(i.node,i.offset)):(n.setEnd(i.node,i.offset),e.addRange(n)))}}for(n=[],e=s;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s=document.documentMode,sl=null,xo=null,lr=null,mo=!1;function Uc(e,n,s){var l=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;mo||sl==null||sl!==ya(l)||(l=sl,"selectionStart"in l&&ud(l)?l={start:l.selectionStart,end:l.selectionEnd}:(l=(l.ownerDocument&&l.ownerDocument.defaultView||window).getSelection(),l={anchorNode:l.anchorNode,anchorOffset:l.anchorOffset,focusNode:l.focusNode,focusOffset:l.focusOffset}),lr&&xr(lr,l)||(lr=l,l=_a(xo,"onSelect"),0al||(e.current=wo[al],wo[al]=null,al--)}function ke(e,n){al++,wo[al]=e.current,e.current=n}var ts={},yt=ls(ts),Ct=ls(!1),_s=ts;function jl(e,n){var s=e.type.contextTypes;if(!s)return ts;var l=e.stateNode;if(l&&l.__reactInternalMemoizedUnmaskedChildContext===n)return l.__reactInternalMemoizedMaskedChildContext;var r={},a;for(a in s)r[a]=n[a];return l&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=r),r}function zt(e){return e=e.childContextTypes,e!=null}function za(){ze(Ct),ze(yt)}function Yc(e,n,s){if(yt.current!==ts)throw Error(K(168));ke(yt,n),ke(Ct,s)}function qp(e,n,s){var l=e.stateNode;if(n=n.childContextTypes,typeof l.getChildContext!="function")return s;l=l.getChildContext();for(var r in l)if(!(r in n))throw Error(K(108,fx(e)||"Unknown",r));return Le({},s,l)}function Ia(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||ts,_s=yt.current,ke(yt,e),ke(Ct,Ct.current),!0}function Xc(e,n,s){var l=e.stateNode;if(!l)throw Error(K(169));s?(e=qp(e,n,_s),l.__reactInternalMemoizedMergedChildContext=e,ze(Ct),ze(yt),ke(yt,e)):ze(Ct),ke(Ct,s)}var kn=null,qa=!1,Wi=!1;function Jp(e){kn===null?kn=[e]:kn.push(e)}function Tm(e){qa=!0,Jp(e)}function rs(){if(!Wi&&kn!==null){Wi=!0;var e=0,n=be;try{var s=kn;for(be=1;e>=i,r-=i,_n=1<<32-Zt(n)+r|s<x?(I=b,b=null):I=b.sibling;var E=f(m,b,u[x],h);if(E===null){b===null&&(b=I);break}e&&b&&E.alternate===null&&n(m,b),o=a(E,o,x),j===null?z=E:j.sibling=E,j=E,b=I}if(x===u.length)return s(m,b),Pe&&ys(m,x),z;if(b===null){for(;xx?(I=b,b=null):I=b.sibling;var F=f(m,b,E.value,h);if(F===null){b===null&&(b=I);break}e&&b&&F.alternate===null&&n(m,b),o=a(F,o,x),j===null?z=F:j.sibling=F,j=F,b=I}if(E.done)return s(m,b),Pe&&ys(m,x),z;if(b===null){for(;!E.done;x++,E=u.next())E=v(m,E.value,h),E!==null&&(o=a(E,o,x),j===null?z=E:j.sibling=E,j=E);return Pe&&ys(m,x),z}for(b=l(m,b);!E.done;x++,E=u.next())E=g(b,m,x,E.value,h),E!==null&&(e&&E.alternate!==null&&b.delete(E.key===null?x:E.key),o=a(E,o,x),j===null?z=E:j.sibling=E,j=E);return e&&b.forEach(function(U){return n(m,U)}),Pe&&ys(m,x),z}function y(m,o,u,h){if(typeof u=="object"&&u!==null&&u.type===tl&&u.key===null&&(u=u.props.children),typeof u=="object"&&u!==null){switch(u.$$typeof){case Br:e:{for(var z=u.key,j=o;j!==null;){if(j.key===z){if(z=u.type,z===tl){if(j.tag===7){s(m,j.sibling),o=r(j,u.props.children),o.return=m,m=o;break e}}else if(j.elementType===z||typeof z=="object"&&z!==null&&z.$$typeof===Wn&&Zc(z)===j.type){s(m,j.sibling),o=r(j,u.props),o.ref=Fl(m,j,u),o.return=m,m=o;break e}s(m,j);break}else n(m,j);j=j.sibling}u.type===tl?(o=ks(u.props.children,m.mode,h,u.key),o.return=m,m=o):(h=xa(u.type,u.key,u.props,null,m.mode,h),h.ref=Fl(m,o,u),h.return=m,m=h)}return i(m);case el:e:{for(j=u.key;o!==null;){if(o.key===j)if(o.tag===4&&o.stateNode.containerInfo===u.containerInfo&&o.stateNode.implementation===u.implementation){s(m,o.sibling),o=r(o,u.children||[]),o.return=m,m=o;break e}else{s(m,o);break}else n(m,o);o=o.sibling}o=Ki(u,m.mode,h),o.return=m,m=o}return i(m);case Wn:return j=u._init,y(m,o,j(u._payload),h)}if(ql(u))return S(m,o,u,h);if(Nl(u))return k(m,o,u,h);qr(m,u)}return typeof u=="string"&&u!==""||typeof u=="number"?(u=""+u,o!==null&&o.tag===6?(s(m,o.sibling),o=r(o,u),o.return=m,m=o):(s(m,o),o=Gi(u,m.mode,h),o.return=m,m=o),i(m)):s(m,o)}return y}var Sl=tf(!0),nf=tf(!1),Pa=ls(null),Aa=null,dl=null,gd=null;function xd(){gd=dl=Aa=null}function md(e){var n=Pa.current;ze(Pa),e._currentValue=n}function Co(e,n,s){for(;e!==null;){var l=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,l!==null&&(l.childLanes|=n)):l!==null&&(l.childLanes&n)!==n&&(l.childLanes|=n),e===s)break;e=e.return}}function ml(e,n){Aa=e,gd=dl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(_t=!0),e.firstContext=null)}function Mt(e){var n=e._currentValue;if(gd!==e)if(e={context:e,memoizedValue:n,next:null},dl===null){if(Aa===null)throw Error(K(308));dl=e,Aa.dependencies={lanes:0,firstContext:e}}else dl=dl.next=e;return n}var bs=null;function yd(e){bs===null?bs=[e]:bs.push(e)}function sf(e,n,s,l){var r=n.interleaved;return r===null?(s.next=s,yd(n)):(s.next=r.next,r.next=s),n.interleaved=s,Tn(e,l)}function Tn(e,n){e.lanes|=n;var s=e.alternate;for(s!==null&&(s.lanes|=n),s=e,e=e.return;e!==null;)e.childLanes|=n,s=e.alternate,s!==null&&(s.childLanes|=n),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Bn=!1;function vd(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function lf(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function zn(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function qn(e,n,s){var l=e.updateQueue;if(l===null)return null;if(l=l.shared,ge&2){var r=l.pending;return r===null?n.next=n:(n.next=r.next,r.next=n),l.pending=n,Tn(e,s)}return r=l.interleaved,r===null?(n.next=n,yd(l)):(n.next=r.next,r.next=n),l.interleaved=n,Tn(e,s)}function ca(e,n,s){if(n=n.updateQueue,n!==null&&(n=n.shared,(s&4194240)!==0)){var l=n.lanes;l&=e.pendingLanes,s|=l,n.lanes=s,ld(e,s)}}function Vc(e,n){var s=e.updateQueue,l=e.alternate;if(l!==null&&(l=l.updateQueue,s===l)){var r=null,a=null;if(s=s.firstBaseUpdate,s!==null){do{var i={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};a===null?r=a=i:a=a.next=i,s=s.next}while(s!==null);a===null?r=a=n:a=a.next=n}else r=a=n;s={baseState:l.baseState,firstBaseUpdate:r,lastBaseUpdate:a,shared:l.shared,effects:l.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=n:e.next=n,s.lastBaseUpdate=n}function Ra(e,n,s,l){var r=e.updateQueue;Bn=!1;var a=r.firstBaseUpdate,i=r.lastBaseUpdate,d=r.shared.pending;if(d!==null){r.shared.pending=null;var c=d,p=c.next;c.next=null,i===null?a=p:i.next=p,i=c;var w=e.alternate;w!==null&&(w=w.updateQueue,d=w.lastBaseUpdate,d!==i&&(d===null?w.firstBaseUpdate=p:d.next=p,w.lastBaseUpdate=c))}if(a!==null){var v=r.baseState;i=0,w=p=c=null,d=a;do{var f=d.lane,g=d.eventTime;if((l&f)===f){w!==null&&(w=w.next={eventTime:g,lane:0,tag:d.tag,payload:d.payload,callback:d.callback,next:null});e:{var S=e,k=d;switch(f=n,g=s,k.tag){case 1:if(S=k.payload,typeof S=="function"){v=S.call(g,v,f);break e}v=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=k.payload,f=typeof S=="function"?S.call(g,v,f):S,f==null)break e;v=Le({},v,f);break e;case 2:Bn=!0}}d.callback!==null&&d.lane!==0&&(e.flags|=64,f=r.effects,f===null?r.effects=[d]:f.push(d))}else g={eventTime:g,lane:f,tag:d.tag,payload:d.payload,callback:d.callback,next:null},w===null?(p=w=g,c=v):w=w.next=g,i|=f;if(d=d.next,d===null){if(d=r.shared.pending,d===null)break;f=d,d=f.next,f.next=null,r.lastBaseUpdate=f,r.shared.pending=null}}while(!0);if(w===null&&(c=v),r.baseState=c,r.firstBaseUpdate=p,r.lastBaseUpdate=w,n=r.shared.interleaved,n!==null){r=n;do i|=r.lane,r=r.next;while(r!==n)}else a===null&&(r.shared.lanes=0);Is|=i,e.lanes=i,e.memoizedState=v}}function eu(e,n,s){if(e=n.effects,n.effects=null,e!==null)for(n=0;ns?s:4,e(!0);var l=$i.transition;$i.transition={};try{e(!1),n()}finally{be=s,$i.transition=l}}function Sf(){return Ht().memoizedState}function Dm(e,n,s){var l=Zn(e);if(s={lane:l,action:s,hasEagerState:!1,eagerState:null,next:null},wf(e))kf(n,s);else if(s=sf(e,n,s,l),s!==null){var r=bt();Vt(s,e,l,r),_f(s,n,l)}}function Lm(e,n,s){var l=Zn(e),r={lane:l,action:s,hasEagerState:!1,eagerState:null,next:null};if(wf(e))kf(n,r);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=n.lastRenderedReducer,a!==null))try{var i=n.lastRenderedState,d=a(i,s);if(r.hasEagerState=!0,r.eagerState=d,en(d,i)){var c=n.interleaved;c===null?(r.next=r,yd(n)):(r.next=c.next,c.next=r),n.interleaved=r;return}}catch{}finally{}s=sf(e,n,r,l),s!==null&&(r=bt(),Vt(s,e,l,r),_f(s,n,l))}}function wf(e){var n=e.alternate;return e===De||n!==null&&n===De}function kf(e,n){rr=La=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function _f(e,n,s){if(s&4194240){var l=n.lanes;l&=e.pendingLanes,s|=l,n.lanes=s,ld(e,s)}}var Oa={readContext:Mt,useCallback:gt,useContext:gt,useEffect:gt,useImperativeHandle:gt,useInsertionEffect:gt,useLayoutEffect:gt,useMemo:gt,useReducer:gt,useRef:gt,useState:gt,useDebugValue:gt,useDeferredValue:gt,useTransition:gt,useMutableSource:gt,useSyncExternalStore:gt,useId:gt,unstable_isNewReconciler:!1},Om={readContext:Mt,useCallback:function(e,n){return un().memoizedState=[e,n===void 0?null:n],e},useContext:Mt,useEffect:nu,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,pa(4194308,4,mf.bind(null,n,e),s)},useLayoutEffect:function(e,n){return pa(4194308,4,e,n)},useInsertionEffect:function(e,n){return pa(4,2,e,n)},useMemo:function(e,n){var s=un();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var l=un();return n=s!==void 0?s(n):n,l.memoizedState=l.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},l.queue=e,e=e.dispatch=Dm.bind(null,De,e),[l.memoizedState,e]},useRef:function(e){var n=un();return e={current:e},n.memoizedState=e},useState:tu,useDebugValue:zd,useDeferredValue:function(e){return un().memoizedState=e},useTransition:function(){var e=tu(!1),n=e[0];return e=Rm.bind(null,e[1]),un().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var l=De,r=un();if(Pe){if(s===void 0)throw Error(K(407));s=s()}else{if(s=n(),ot===null)throw Error(K(349));zs&30||df(l,n,s)}r.memoizedState=s;var a={value:s,getSnapshot:n};return r.queue=a,nu(uf.bind(null,l,a,e),[e]),l.flags|=2048,kr(9,cf.bind(null,l,a,s,n),void 0,null),s},useId:function(){var e=un(),n=ot.identifierPrefix;if(Pe){var s=Cn,l=_n;s=(l&~(1<<32-Zt(l)-1)).toString(32)+s,n=":"+n+"R"+s,s=Sr++,0<\/script>",e=e.removeChild(e.firstChild)):typeof l.is=="string"?e=i.createElement(s,{is:l.is}):(e=i.createElement(s),s==="select"&&(i=e,l.multiple?i.multiple=!0:l.size&&(i.size=l.size))):e=i.createElementNS(e,s),e[pn]=n,e[vr]=l,Lf(e,n,!1,!1),n.stateNode=e;e:{switch(i=io(s,l),s){case"dialog":Ce("cancel",e),Ce("close",e),r=l;break;case"iframe":case"object":case"embed":Ce("load",e),r=l;break;case"video":case"audio":for(r=0;r_l&&(n.flags|=128,l=!0,Ml(a,!1),n.lanes=4194304)}else{if(!l)if(e=Da(i),e!==null){if(n.flags|=128,l=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),Ml(a,!0),a.tail===null&&a.tailMode==="hidden"&&!i.alternate&&!Pe)return xt(n),null}else 2*Xe()-a.renderingStartTime>_l&&s!==1073741824&&(n.flags|=128,l=!0,Ml(a,!1),n.lanes=4194304);a.isBackwards?(i.sibling=n.child,n.child=i):(s=a.last,s!==null?s.sibling=i:n.child=i,a.last=i)}return a.tail!==null?(n=a.tail,a.rendering=n,a.tail=n.sibling,a.renderingStartTime=Xe(),n.sibling=null,s=Re.current,ke(Re,l?s&1|2:s&1),n):(xt(n),null);case 22:case 23:return Rd(),l=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==l&&(n.flags|=8192),l&&n.mode&1?Rt&1073741824&&(xt(n),n.subtreeFlags&6&&(n.flags|=8192)):xt(n),null;case 24:return null;case 25:return null}throw Error(K(156,n.tag))}function Hm(e,n){switch(fd(n),n.tag){case 1:return zt(n.type)&&za(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return wl(),ze(Ct),ze(yt),Sd(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return bd(n),null;case 13:if(ze(Re),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(K(340));bl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return ze(Re),null;case 4:return wl(),null;case 10:return md(n.type._context),null;case 22:case 23:return Rd(),null;case 24:return null;default:return null}}var Zr=!1,mt=!1,Gm=typeof WeakSet=="function"?WeakSet:Set,Z=null;function cl(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(l){Fe(e,n,l)}else s.current=null}function Lo(e,n,s){try{s()}catch(l){Fe(e,n,l)}}var fu=!1;function Km(e,n){if(yo=wa,e=Up(),ud(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var l=s.getSelection&&s.getSelection();if(l&&l.rangeCount!==0){s=l.anchorNode;var r=l.anchorOffset,a=l.focusNode;l=l.focusOffset;try{s.nodeType,a.nodeType}catch{s=null;break e}var i=0,d=-1,c=-1,p=0,w=0,v=e,f=null;t:for(;;){for(var g;v!==s||r!==0&&v.nodeType!==3||(d=i+r),v!==a||l!==0&&v.nodeType!==3||(c=i+l),v.nodeType===3&&(i+=v.nodeValue.length),(g=v.firstChild)!==null;)f=v,v=g;for(;;){if(v===e)break t;if(f===s&&++p===r&&(d=i),f===a&&++w===l&&(c=i),(g=v.nextSibling)!==null)break;v=f,f=v.parentNode}v=g}s=d===-1||c===-1?null:{start:d,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(vo={focusedElem:e,selectionRange:s},wa=!1,Z=n;Z!==null;)if(n=Z,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,Z=e;else for(;Z!==null;){n=Z;try{var S=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var k=S.memoizedProps,y=S.memoizedState,m=n.stateNode,o=m.getSnapshotBeforeUpdate(n.elementType===n.type?k:Yt(n.type,k),y);m.__reactInternalSnapshotBeforeUpdate=o}break;case 3:var u=n.stateNode.containerInfo;u.nodeType===1?u.textContent="":u.nodeType===9&&u.documentElement&&u.removeChild(u.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(K(163))}}catch(h){Fe(n,n.return,h)}if(e=n.sibling,e!==null){e.return=n.return,Z=e;break}Z=n.return}return S=fu,fu=!1,S}function ar(e,n,s){var l=n.updateQueue;if(l=l!==null?l.lastEffect:null,l!==null){var r=l=l.next;do{if((r.tag&e)===e){var a=r.destroy;r.destroy=void 0,a!==void 0&&Lo(n,s,a)}r=r.next}while(r!==l)}}function Va(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var s=n=n.next;do{if((s.tag&e)===e){var l=s.create;s.destroy=l()}s=s.next}while(s!==n)}}function Oo(e){var n=e.ref;if(n!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof n=="function"?n(e):n.current=e}}function Wf(e){var n=e.alternate;n!==null&&(e.alternate=null,Wf(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[pn],delete n[vr],delete n[So],delete n[Im],delete n[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 Bf(e){return e.tag===5||e.tag===3||e.tag===4}function hu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Bf(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 No(e,n,s){var l=e.tag;if(l===5||l===6)e=e.stateNode,n?s.nodeType===8?s.parentNode.insertBefore(e,n):s.insertBefore(e,n):(s.nodeType===8?(n=s.parentNode,n.insertBefore(e,s)):(n=s,n.appendChild(e)),s=s._reactRootContainer,s!=null||n.onclick!==null||(n.onclick=Ca));else if(l!==4&&(e=e.child,e!==null))for(No(e,n,s),e=e.sibling;e!==null;)No(e,n,s),e=e.sibling}function Wo(e,n,s){var l=e.tag;if(l===5||l===6)e=e.stateNode,n?s.insertBefore(e,n):s.appendChild(e);else if(l!==4&&(e=e.child,e!==null))for(Wo(e,n,s),e=e.sibling;e!==null;)Wo(e,n,s),e=e.sibling}var ct=null,Xt=!1;function On(e,n,s){for(s=s.child;s!==null;)$f(e,n,s),s=s.sibling}function $f(e,n,s){if(fn&&typeof fn.onCommitFiberUnmount=="function")try{fn.onCommitFiberUnmount(Ga,s)}catch{}switch(s.tag){case 5:mt||cl(s,n);case 6:var l=ct,r=Xt;ct=null,On(e,n,s),ct=l,Xt=r,ct!==null&&(Xt?(e=ct,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):ct.removeChild(s.stateNode));break;case 18:ct!==null&&(Xt?(e=ct,s=s.stateNode,e.nodeType===8?Ni(e.parentNode,s):e.nodeType===1&&Ni(e,s),hr(e)):Ni(ct,s.stateNode));break;case 4:l=ct,r=Xt,ct=s.stateNode.containerInfo,Xt=!0,On(e,n,s),ct=l,Xt=r;break;case 0:case 11:case 14:case 15:if(!mt&&(l=s.updateQueue,l!==null&&(l=l.lastEffect,l!==null))){r=l=l.next;do{var a=r,i=a.destroy;a=a.tag,i!==void 0&&(a&2||a&4)&&Lo(s,n,i),r=r.next}while(r!==l)}On(e,n,s);break;case 1:if(!mt&&(cl(s,n),l=s.stateNode,typeof l.componentWillUnmount=="function"))try{l.props=s.memoizedProps,l.state=s.memoizedState,l.componentWillUnmount()}catch(d){Fe(s,n,d)}On(e,n,s);break;case 21:On(e,n,s);break;case 22:s.mode&1?(mt=(l=mt)||s.memoizedState!==null,On(e,n,s),mt=l):On(e,n,s);break;default:On(e,n,s)}}function gu(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new Gm),n.forEach(function(l){var r=ty.bind(null,e,l);s.has(l)||(s.add(l),l.then(r,r))})}}function Qt(e,n){var s=n.deletions;if(s!==null)for(var l=0;lr&&(r=i),l&=~a}if(l=r,l=Xe()-l,l=(120>l?120:480>l?480:1080>l?1080:1920>l?1920:3e3>l?3e3:4320>l?4320:1960*Ym(l/1960))-l,10e?16:e,Mn===null)var l=!1;else{if(e=Mn,Mn=null,Ba=0,ge&6)throw Error(K(331));var r=ge;for(ge|=4,Z=e.current;Z!==null;){var a=Z,i=a.child;if(Z.flags&16){var d=a.deletions;if(d!==null){for(var c=0;cXe()-Pd?ws(e,0):Td|=s),It(e,n)}function Yf(e,n){n===0&&(e.mode&1?(n=Mr,Mr<<=1,!(Mr&130023424)&&(Mr=4194304)):n=1);var s=bt();e=Tn(e,n),e!==null&&(Ir(e,n,s),It(e,s))}function ey(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),Yf(e,s)}function ty(e,n){var s=0;switch(e.tag){case 13:var l=e.stateNode,r=e.memoizedState;r!==null&&(s=r.retryLane);break;case 19:l=e.stateNode;break;default:throw Error(K(314))}l!==null&&l.delete(n),Yf(e,s)}var Xf;Xf=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||Ct.current)_t=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return _t=!1,Fm(e,n,s);_t=!!(e.flags&131072)}else _t=!1,Pe&&n.flags&1048576&&Zp(n,Ta,n.index);switch(n.lanes=0,n.tag){case 2:var l=n.type;fa(e,n),e=n.pendingProps;var r=jl(n,yt.current);ml(n,s),r=kd(null,n,l,e,r,s);var a=_d();return n.flags|=1,typeof r=="object"&&r!==null&&typeof r.render=="function"&&r.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,zt(l)?(a=!0,Ia(n)):a=!1,n.memoizedState=r.state!==null&&r.state!==void 0?r.state:null,vd(n),r.updater=Za,n.stateNode=r,r._reactInternals=n,Io(n,l,e,s),n=Po(null,n,l,!0,a,s)):(n.tag=0,Pe&&a&&pd(n),jt(null,n,r,s),n=n.child),n;case 16:l=n.elementType;e:{switch(fa(e,n),e=n.pendingProps,r=l._init,l=r(l._payload),n.type=l,r=n.tag=sy(l),e=Yt(l,e),r){case 0:n=To(null,n,l,e,s);break e;case 1:n=cu(null,n,l,e,s);break e;case 11:n=ou(null,n,l,e,s);break e;case 14:n=du(null,n,l,Yt(l.type,e),s);break e}throw Error(K(306,l,""))}return n;case 0:return l=n.type,r=n.pendingProps,r=n.elementType===l?r:Yt(l,r),To(e,n,l,r,s);case 1:return l=n.type,r=n.pendingProps,r=n.elementType===l?r:Yt(l,r),cu(e,n,l,r,s);case 3:e:{if(Af(n),e===null)throw Error(K(387));l=n.pendingProps,a=n.memoizedState,r=a.element,lf(e,n),Ra(n,l,null,s);var i=n.memoizedState;if(l=i.element,a.isDehydrated)if(a={element:l,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},n.updateQueue.baseState=a,n.memoizedState=a,n.flags&256){r=kl(Error(K(423)),n),n=uu(e,n,l,s,r);break e}else if(l!==r){r=kl(Error(K(424)),n),n=uu(e,n,l,s,r);break e}else for(Dt=Xn(n.stateNode.containerInfo.firstChild),Lt=n,Pe=!0,qt=null,s=nf(n,null,l,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(bl(),l===r){n=Pn(e,n,s);break e}jt(e,n,l,s)}n=n.child}return n;case 5:return rf(n),e===null&&_o(n),l=n.type,r=n.pendingProps,a=e!==null?e.memoizedProps:null,i=r.children,jo(l,r)?i=null:a!==null&&jo(l,a)&&(n.flags|=32),Pf(e,n),jt(e,n,i,s),n.child;case 6:return e===null&&_o(n),null;case 13:return Rf(e,n,s);case 4:return jd(n,n.stateNode.containerInfo),l=n.pendingProps,e===null?n.child=Sl(n,null,l,s):jt(e,n,l,s),n.child;case 11:return l=n.type,r=n.pendingProps,r=n.elementType===l?r:Yt(l,r),ou(e,n,l,r,s);case 7:return jt(e,n,n.pendingProps,s),n.child;case 8:return jt(e,n,n.pendingProps.children,s),n.child;case 12:return jt(e,n,n.pendingProps.children,s),n.child;case 10:e:{if(l=n.type._context,r=n.pendingProps,a=n.memoizedProps,i=r.value,ke(Pa,l._currentValue),l._currentValue=i,a!==null)if(en(a.value,i)){if(a.children===r.children&&!Ct.current){n=Pn(e,n,s);break e}}else for(a=n.child,a!==null&&(a.return=n);a!==null;){var d=a.dependencies;if(d!==null){i=a.child;for(var c=d.firstContext;c!==null;){if(c.context===l){if(a.tag===1){c=zn(-1,s&-s),c.tag=2;var p=a.updateQueue;if(p!==null){p=p.shared;var w=p.pending;w===null?c.next=c:(c.next=w.next,w.next=c),p.pending=c}}a.lanes|=s,c=a.alternate,c!==null&&(c.lanes|=s),Co(a.return,s,n),d.lanes|=s;break}c=c.next}}else if(a.tag===10)i=a.type===n.type?null:a.child;else if(a.tag===18){if(i=a.return,i===null)throw Error(K(341));i.lanes|=s,d=i.alternate,d!==null&&(d.lanes|=s),Co(i,s,n),i=a.sibling}else i=a.child;if(i!==null)i.return=a;else for(i=a;i!==null;){if(i===n){i=null;break}if(a=i.sibling,a!==null){a.return=i.return,i=a;break}i=i.return}a=i}jt(e,n,r.children,s),n=n.child}return n;case 9:return r=n.type,l=n.pendingProps.children,ml(n,s),r=Mt(r),l=l(r),n.flags|=1,jt(e,n,l,s),n.child;case 14:return l=n.type,r=Yt(l,n.pendingProps),r=Yt(l.type,r),du(e,n,l,r,s);case 15:return Ef(e,n,n.type,n.pendingProps,s);case 17:return l=n.type,r=n.pendingProps,r=n.elementType===l?r:Yt(l,r),fa(e,n),n.tag=1,zt(l)?(e=!0,Ia(n)):e=!1,ml(n,s),Cf(n,l,r),Io(n,l,r,s),Po(null,n,l,!0,e,s);case 19:return Df(e,n,s);case 22:return Tf(e,n,s)}throw Error(K(156,n.tag))};function qf(e,n){return Sp(e,n)}function ny(e,n,s,l){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=l,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ut(e,n,s,l){return new ny(e,n,s,l)}function Ld(e){return e=e.prototype,!(!e||!e.isReactComponent)}function sy(e){if(typeof e=="function")return Ld(e)?1:0;if(e!=null){if(e=e.$$typeof,e===ed)return 11;if(e===td)return 14}return 2}function Vn(e,n){var s=e.alternate;return s===null?(s=Ut(e.tag,n,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=n,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,n=e.dependencies,s.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function xa(e,n,s,l,r,a){var i=2;if(l=e,typeof e=="function")Ld(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case tl:return ks(s.children,r,a,n);case Vo:i=8,r|=8;break;case Ji:return e=Ut(12,s,n,r|2),e.elementType=Ji,e.lanes=a,e;case Zi:return e=Ut(13,s,n,r),e.elementType=Zi,e.lanes=a,e;case Vi:return e=Ut(19,s,n,r),e.elementType=Vi,e.lanes=a,e;case rp:return ti(s,r,a,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case sp:i=10;break e;case lp:i=9;break e;case ed:i=11;break e;case td:i=14;break e;case Wn:i=16,l=null;break e}throw Error(K(130,e==null?e:typeof e,""))}return n=Ut(i,s,n,r),n.elementType=e,n.type=l,n.lanes=a,n}function ks(e,n,s,l){return e=Ut(7,e,l,n),e.lanes=s,e}function ti(e,n,s,l){return e=Ut(22,e,l,n),e.elementType=rp,e.lanes=s,e.stateNode={isHidden:!1},e}function Gi(e,n,s){return e=Ut(6,e,null,n),e.lanes=s,e}function Ki(e,n,s){return n=Ut(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function ly(e,n,s,l,r){this.tag=n,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ci(0),this.expirationTimes=Ci(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ci(0),this.identifierPrefix=l,this.onRecoverableError=r,this.mutableSourceEagerHydrationData=null}function Od(e,n,s,l,r,a,i,d,c){return e=new ly(e,n,s,d,c),n===1?(n=1,a===!0&&(n|=8)):n=0,a=Ut(3,null,null,n),e.current=a,a.stateNode=e,a.memoizedState={element:l,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},vd(a),e}function ry(e,n,s){var l=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(eh)}catch(e){console.error(e)}}eh(),Vu.exports=Nt;var cy=Vu.exports,th,wu=cy;th=wu.createRoot,wu.hydrateRoot;const ce="",O={incidents:"SB Incident",ideas:"SB Idea",orders:"SB Order",organizations:"SB Organization",processes:"SB Process",managements:"Managements",departments:"Department",branches:"Branch",incidentTypes:"Incident Types",ideaTypes:"Idea Types",orderTypes:"Order Types",processTypes:"Process Types",incidentClass:"Incident Class",incidentField:"Incident Field",incidentStatuses:"Incident Statuses",ideaStatuses:"Idea Statuses",orderStatuses:"Order Statuses",processStatuses:"Process Statuses",users:"User",cycles:"SB Cycle",kpiInput:"SB KPI Input",delegations:"SB Delegation",groupCompanies:"SB Group Company"},G={bg:"#f5f6fa",accent:"#4f46e5",red:"#ef4444",orange:"#f59e0b",green:"#16a34a",purple:"#7c3aed",blue:"#2563eb",teal:"#0d9488",gray:"#94a3b8"},uy=[{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"}],nh=[{id:"group-companies",icon:"🌐",label:"Group Companies"},{id:"users",icon:"👤",label:"Users"},{id:"organizations",icon:"🏢",label:"Organizations"},{id:"managements",icon:"🏗️",label:"Managements"},{id:"departments",icon:"🗂️",label:"Departments"},{id:"branches",icon:"🌿",label:"Branches"},{id:"cycles",icon:"🔄",label:"Cycles"},{id:"kpi-input",icon:"📊",label:"KPI Input"},{id:"incident-types",icon:"🚨",label:"Incident Types"},{id:"idea-types",icon:"💡",label:"Idea Types"},{id:"order-types",icon:"📦",label:"Order Types"},{id:"process-types",icon:"⚙️",label:"Process Types"},{id:"incident-statuses",icon:"🔴",label:"Incident Statuses"},{id:"idea-statuses",icon:"🟢",label:"Idea Statuses"},{id:"order-statuses",icon:"🟣",label:"Order Statuses"},{id:"process-statuses",icon:"🔵",label:"Process Statuses"}],py=new Set(["users","group-companies"]);function fy(e){return e!=="Admin"&&e!=="Auditor"?[]:nh.filter(({id:n})=>e==="Admin"||!py.has(n))}const Nn=(e=[])=>[{key:"name1",label:"Name"},{key:"status",label:"Status"},...e,{key:"creation_date",label:"Created On"}],Me={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:Nn(),defaultColumns:["name1","status","creation_date"]},"idea-types":{label:"Idea Types",columns:Nn(),defaultColumns:["name1","status","creation_date"]},"order-types":{label:"Order Types",columns:Nn(),defaultColumns:["name1","status","creation_date"]},"process-types":{label:"Process Types",columns:Nn(),defaultColumns:["name1","status","creation_date"]},"incident-statuses":{label:"Incident Statuses",columns:Nn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"idea-statuses":{label:"Idea Statuses",columns:Nn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"order-statuses":{label:"Order Statuses",columns:Nn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"process-statuses":{label:"Process Statuses",columns:Nn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},users:{label:"Users",orgField:"custom_organization",columns:[{key:"full_name",label:"Full Name"},{key:"email",label:"Email"},{key:"username",label:"Username"},{key:"mobile_no",label:"Phone"},{key:"custom_category",label:"Category"},{key:"custom_organization",label:"Organization"},{key:"custom_management",label:"Management"},{key:"custom_department",label:"Department"},{key:"custom_branch",label:"Branch"},{key:"custom_number",label:"User ID No"},{key:"enabled",label:"Active"},{key:"creation",label:"Created On"}],defaultColumns:["full_name","email","custom_category","custom_organization","enabled"]},delegations:{label:"Delegations",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"auditor",label:"Delegator"},{key:"manager",label:"Manager"},{key:"organization",label:"Organization"},{key:"incident_initial_evaluation",label:"Incident Initial Evaluation"},{key:"idea_initial_evaluation",label:"Idea Initial Evaluation"},{key:"status",label:"Status"},{key:"requested_on",label:"Requested On"},{key:"responded_on",label:"Responded On"}],defaultColumns:["number","auditor","manager","organization","incident_initial_evaluation","idea_initial_evaluation","status","requested_on"]},"group-companies":{label:"Group Companies",columns:[{key:"company_name",label:"Company Name"},{key:"code",label:"Code"},{key:"acronym",label:"Acronym"},{key:"owner_user",label:"Group Co Owner"},{key:"status",label:"Status"}],defaultColumns:["company_name","code","acronym","owner_user","status"]}},hy=()=>t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),gy=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),xy=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"}),t.jsx("path",{d:"M10 11v6M14 11v6"}),t.jsx("path",{d:"M9 6V4h6v2"})]});function at({onView:e,onEdit:n,onDelete:s}){const l=(r,a,i,d,c,p)=>d?t.jsx("button",{type:"button",onClick:w=>{w.stopPropagation(),d()},title:p,style:{width:30,height:30,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid transparent",cursor:"pointer",background:r,color:i,flexShrink:0,transition:"all 0.15s ease"},onMouseEnter:w=>{w.currentTarget.style.background=a,w.currentTarget.style.transform="scale(1.08)"},onMouseLeave:w=>{w.currentTarget.style.background=r,w.currentTarget.style.transform="scale(1)"},children:c},p):null;return t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[l("#f0f9ff","#e0f2fe","#0284c7",e,t.jsx(hy,{}),"View"),l("#f0fdf4","#dcfce7","#16a34a",n,t.jsx(gy,{}),"Edit"),s&&l("#fff1f2","#fee2e2","#e11d48",s,t.jsx(xy,{}),"Delete")]})}const A={width:"100%",height:34,padding:"7px 10px",border:"1px solid #ddd",borderRadius:6,fontSize:12,boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif"},T={display:"block",marginBottom:5,fontSize:11,color:"#555",fontWeight:600};function my(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 ye(e,n){return e.filter(s=>my(s)||s.name===n)}const yy={incident:["Rejected","Executed & Closed"],idea:["Rejected","Executed & Closed"],order:["Closed"],process:["Closed"]};function Hn(e,n){return!!n&&yy[e].includes(n)}function Cl(e,n,s,l){return e.filter(r=>{const a=n[r.name]||[];return!(a.includes("SB Admin")||a.includes("System Manager")||!a.includes(s)||l&&r.custom_organization&&r.custom_organization!==l)})}const zl={width:16,height:16,cursor:"pointer",accentColor:"#2563eb",flexShrink:0};function ma(e){const n=(e||"").trim().toLowerCase();return n==="new"||n==="initial evaluation"||n==="draft"?{bg:"#eff6ff",color:"#1d4ed8",border:"#bfdbfe"}:n.includes("progress")||n.includes("review")||n.includes("proposal")||n.includes("resolution")?{bg:"#fefce8",color:"#a16207",border:"#fef08a"}:n.includes("executed")||n.includes("approved")||n.includes("active")||n.includes("closed")||n.includes("completed")?{bg:"#f0fdf4",color:"#15803d",border:"#bbf7d0"}:n.includes("rejected")||n.includes("overdue")||n.includes("fail")||n.includes("inactive")?{bg:"#fef2f2",color:"#b91c1c",border:"#fecaca"}:n.includes("deleted")?{bg:"#fff1f2",color:"#e11d48",border:"#fecdd3"}:{bg:"#f8fafc",color:"#475569",border:"#e2e8f0"}}function vy(e){const n=(e||"").trim().toLowerCase();return n.includes("incident")?{bg:"#f1f5f9",color:"#334155",border:"#cbd5e1"}:n.includes("complaint")?{bg:"#fff7ed",color:"#c2410c",border:"#fed7aa"}:n.includes("violation")?{bg:"#faf5ff",color:"#7e22ce",border:"#e9d5ff"}:n.includes("process")?{bg:"#f0fdfa",color:"#0f766e",border:"#99f6e4"}:n.includes("asset")?{bg:"#ecfeff",color:"#0e7490",border:"#a5f3fc"}:n.includes("human")?{bg:"#f5f3ff",color:"#6d28d9",border:"#ddd6fe"}:n.includes("idea")?{bg:"#ecfdf5",color:"#047857",border:"#a7f3d0"}:n.includes("study")?{bg:"#eff6ff",color:"#1d4ed8",border:"#bfdbfe"}:{bg:"#f8fafc",color:"#475569",border:"#e2e8f0"}}const Cr=(e,n)=>{let s;return typeof n=="object"&&n!==null?s=n:typeof n=="string"&&n.startsWith("#")?s=ma(e):typeof n=="string"?s=ma(n):s=ma(e),t.jsx("span",{className:"status-badge",style:{background:s.bg,color:s.color,border:`1px solid ${s.border}`,padding:"2px 8px",borderRadius:9999,fontSize:11,fontWeight:600,letterSpacing:"0.2px",display:"inline-flex",alignItems:"center",justifyContent:"center",lineHeight:1.3,whiteSpace:"nowrap",boxSizing:"border-box",transition:"all 0.15s ease"},children:e})},ns=e=>Cr(e,ma(e)),$d=e=>Cr(e,vy(e));function Ar({deletedBy:e,deletedOn:n,reason:s,onRestore:l,isRestoring:r}){return t.jsxs("div",{style:{background:"#fff1f2",border:"1px solid #fecdd3",borderRadius:8,padding:"7px 14px",marginBottom:12,display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,color:"#9f1239",fontSize:12,flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsxs("div",{style:{fontWeight:700,fontSize:12,display:"flex",alignItems:"center",gap:5,color:"#be123c",whiteSpace:"nowrap"},children:[t.jsx("span",{style:{fontSize:13},children:"⚠️"}),t.jsx("span",{children:"DELETED RECORD / سجل محذوف"})]}),t.jsxs("div",{style:{fontSize:11,color:"#881337",display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e&&t.jsxs("span",{children:[t.jsx("strong",{children:"Deleted By:"})," ",e]}),n&&t.jsxs("span",{children:["| ",t.jsx("strong",{children:"Deleted On:"})," ",n]}),s&&t.jsxs("span",{children:["| ",t.jsx("strong",{children:"Reason:"})," ",s]})]})]}),l&&t.jsxs("button",{type:"button",onClick:l,disabled:r,style:{background:"#e11d48",color:"white",border:"none",borderRadius:6,padding:"5px 12px",fontSize:11,fontWeight:700,cursor:r?"not-allowed":"pointer",boxShadow:"0 1px 2px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:5,whiteSpace:"nowrap",transition:"all 0.15s ease"},onMouseEnter:a=>{r||(a.currentTarget.style.background="#be123c")},onMouseLeave:a=>{r||(a.currentTarget.style.background="#e11d48")},children:[t.jsx("span",{children:"↺"}),t.jsx("span",{children:r?"Restoring...":"Restore Record / استعادة"})]})]})}function ai({onDelete:e,disabled:n,title:s="Delete Request",btnText:l="Delete"}){return t.jsxs("div",{style:{background:"#ffffff",borderRadius:10,padding:14,border:"1px solid #fee2e2",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:s}),t.jsxs("button",{type:"button",onClick:e,disabled:n,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:"#dc2626",color:"#ffffff",fontWeight:700,fontSize:12,cursor:n?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:6,boxShadow:"0 1px 3px rgba(220, 38, 38, 0.25)",transition:"all 0.15s ease"},onMouseEnter:r=>{n||(r.currentTarget.style.background="#b91c1c")},onMouseLeave:r=>{n||(r.currentTarget.style.background="#dc2626")},children:[t.jsx("span",{children:"🗑️"}),t.jsx("span",{children:l})]})]})}function re({title:e,children:n,style:s}){return t.jsxs("div",{className:"form-card",style:{background:"#ffffff",borderRadius:10,border:"1px solid #e2e8f0",padding:"16px 20px",marginBottom:16,boxShadow:"0 1px 3px rgba(0, 0, 0, 0.03)",...s},children:[t.jsx("div",{className:"form-card-title",style:{fontSize:14,fontWeight:700,color:"#1e293b",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:t.jsx("span",{children:e})}),n]})}function ii({title:e="Status Summary",priority:n,createdDate:s,modifiedDate:l,assignedTo:r,status:a}){const i=d=>{if(!d)return"—";try{const c=new Date(d);return isNaN(c.getTime())?d:c.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return d}};return t.jsxs("div",{style:{background:"#ffffff",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:12},children:e}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[n&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Priority"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:n==="High"||n==="Urgent"?"#dc2626":"#1e293b"},children:n})]}),a&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Status"}),t.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#334155"},children:a})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Assigned To"}),t.jsx("div",{style:{fontSize:12,fontWeight:600,color:r?"#334155":"#94a3b8",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r||"—"})]}),s&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:2},children:"Created"}),t.jsx("div",{style:{fontSize:11,color:"#64748b"},children:i(s)})]}),l&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:2},children:"Last Modified"}),t.jsx("div",{style:{fontSize:11,color:"#64748b"},children:i(l)})]})]})]})}const jy="modulepreload",by=function(e){return"/"+e},ku={},Sy=function(n,s,l){let r=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),d=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));r=Promise.allSettled(s.map(c=>{if(c=by(c),c in ku)return;ku[c]=!0;const p=c.endsWith(".css"),w=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${w}`))return;const v=document.createElement("link");if(v.rel=p?"stylesheet":jy,p||(v.as="script"),v.crossOrigin="",v.href=c,d&&v.setAttribute("nonce",d),document.head.appendChild(v),p)return new Promise((f,g)=>{v.addEventListener("load",f),v.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${c}`)))})}))}function a(i){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=i,window.dispatchEvent(d),!d.defaultPrevented)throw i}return r.then(i=>{for(const d of i||[])d.status==="rejected"&&a(d.reason);return n().catch(a)})};function sh(e,n){const s=e[n.key];return s==null||s===""?"":typeof s=="object"?JSON.stringify(s):String(s)}function wy(e,n){const s=URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download=n,l.click(),URL.revokeObjectURL(s)}function He(e,n,s){const l=e.map(i=>`"${i.label.replace(/"/g,'""')}"`).join(","),r=n.map(i=>e.map(d=>`"${sh(i,d).replace(/"/g,'""')}"`).join(",")).join(` `),a=new Blob([l+` `+r],{type:"text/csv;charset=utf-8;"});wy(a,`${s}.csv`)}async function Ge(e,n,s){const l=await Sy(()=>import("./xlsx-D_0l8YDs.js"),[]),r=n.map(d=>{const c={};for(const p of e)c[p.label]=sh(d,p);return c}),a=l.utils.json_to_sheet(r,{header:e.map(d=>d.label)}),i=l.utils.book_new();l.utils.book_append_sheet(i,a,"Export"),l.writeFile(i,`${s}.xlsx`)}const on="#16a34a";function ky({title:e,rows:n,selectedRows:s=[],pageRows:l=[],columns:r,defaultColumnKeys:a,filenameBase:i,onClose:d}){const c=s.length>0?"selected":"all",[p,w]=C.useState(c),[v,f]=C.useState("csv"),[g,S]=C.useState(new Set(a)),[k,y]=C.useState(""),m=p==="selected"?s:p==="page"?l:n,o=r.filter(I=>g.has(I.key)),u=k?r.filter(I=>I.label.toLowerCase().includes(k.toLowerCase())):r,h=I=>{S(E=>{const F=new Set(E);return F.has(I)?F.delete(I):F.add(I),F})},z=async()=>{o.length===0||m.length===0||(v==="csv"?He(o,m,i):await Ge(o,m,i),d())},j={fontSize:11,fontWeight:700,color:"#9ca3af",letterSpacing:.4,textTransform:"uppercase",marginBottom:10},b={background:"none",border:"none",color:"#2563eb",fontSize:12,fontWeight:600,cursor:"pointer",padding:0,fontFamily:"inherit"},x=[{id:"selected",label:"Selected rows",sub:`${s.length} row${s.length!==1?"s":""} selected`,count:s.length,disabled:s.length===0},{id:"page",label:"Current page",sub:`${l.length} row${l.length!==1?"s":""} on this page`,count:l.length},{id:"all",label:"All records (current filters)",sub:`${n.length} total matching records`,count:n.length}];return t.jsx("div",{onClick:d,style:{position:"fixed",inset:0,background:"rgba(15,23,42,0.55)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e4},children:t.jsxs("div",{onClick:I=>I.stopPropagation(),style:{width:580,maxWidth:"92vw",maxHeight:"90vh",background:"white",borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{background:on,color:"white",padding:"16px 22px",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,fontSize:16,fontWeight:700},children:[t.jsx("span",{style:{fontSize:18},children:"📤"})," Export ",e,t.jsxs("span",{style:{fontSize:12,fontWeight:400,opacity:.8},children:[r.length," fields available · ",g.size," selected"]})]}),t.jsx("button",{onClick:d,style:{background:"rgba(255,255,255,0.15)",border:"none",color:"white",width:28,height:28,borderRadius:8,cursor:"pointer",fontSize:15,lineHeight:1},children:"✕"})]}),t.jsxs("div",{style:{padding:"20px 22px",overflowY:"auto",flex:1,display:"flex",flexDirection:"column",gap:20},children:[t.jsxs("div",{children:[t.jsx("div",{style:j,children:"What to export"}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:x.map(I=>t.jsxs("label",{onClick:()=>!I.disabled&&w(I.id),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderRadius:10,cursor:I.disabled?"not-allowed":"pointer",border:`2px solid ${p===I.id?on:"#e5e7eb"}`,background:p===I.id?"#f0fdf4":I.disabled?"#fafafa":"white",opacity:I.disabled?.5:1,transition:"border-color 0.15s, background 0.15s"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx("div",{style:{width:16,height:16,borderRadius:"50%",border:`2px solid ${p===I.id?on:"#d1d5db"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:p===I.id&&t.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:on}})}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#111827"},children:I.label}),t.jsx("div",{style:{fontSize:12,color:"#6b7280",marginTop:1},children:I.sub})]})]}),t.jsx("span",{style:{background:p===I.id?on:"#e5e7eb",color:p===I.id?"white":"#374151",fontSize:12,fontWeight:700,padding:"2px 10px",borderRadius:9999},children:I.count})]},I.id))})]}),t.jsxs("div",{children:[t.jsx("div",{style:j,children:"File Format"}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[{id:"csv",label:"CSV",desc:"Universal, works everywhere",icon:"📄"},{id:"xlsx",label:"Excel (.xlsx)",desc:"Native Excel workbook",icon:"📊"}].map(I=>t.jsxs("div",{onClick:()=>f(I.id),style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",borderRadius:10,cursor:"pointer",border:`2px solid ${v===I.id?on:"#e5e7eb"}`,background:v===I.id?"#f0fdf4":"white"},children:[t.jsx("div",{style:{width:16,height:16,borderRadius:"50%",border:`2px solid ${v===I.id?on:"#d1d5db"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:v===I.id&&t.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:on}})}),t.jsx("span",{style:{fontSize:20},children:I.icon}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:I.label}),t.jsx("div",{style:{fontSize:11,color:"#888"},children:I.desc})]})]},I.id))})]}),t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[t.jsx("div",{style:{...j,marginBottom:0},children:"Columns to Export"}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("button",{onClick:()=>S(new Set(r.map(I=>I.key))),style:b,children:"All"}),t.jsx("span",{style:{color:"#d1d5db"},children:"|"}),t.jsx("button",{onClick:()=>S(new Set(a)),style:b,children:"Default"}),t.jsx("span",{style:{color:"#d1d5db"},children:"|"}),t.jsx("button",{onClick:()=>S(new Set),style:{...b,color:"#ef4444"},children:"None"})]})]}),t.jsx("div",{style:{marginBottom:8},children:t.jsx("input",{type:"text",placeholder:"Search fields...",value:k,onChange:I=>y(I.target.value),style:{width:"100%",padding:"7px 10px",borderRadius:8,border:"1px solid #e5e7eb",fontSize:12,boxSizing:"border-box",background:"#f9fafb"}})}),t.jsx("div",{style:{border:"1px solid #e5e7eb",borderRadius:8,padding:12,maxHeight:170,overflowY:"auto"},children:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gap:"10px 12px"},children:u.map(I=>t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:7,fontSize:13,color:"#374151",cursor:"pointer",padding:"3px 5px",borderRadius:5,background:g.has(I.key)?"#f0fdf4":"transparent"},children:[t.jsx("input",{type:"checkbox",checked:g.has(I.key),onChange:()=>h(I.key),style:{accentColor:on,cursor:"pointer"}}),I.label]},I.key))})}),t.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:6},children:[g.size," of ",r.length," fields selected"]})]})]}),t.jsxs("div",{style:{padding:"14px 22px",borderTop:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[t.jsxs("span",{style:{fontSize:12,color:"#888"},children:["Exporting ",m.length," ",p==="selected"?"selected":p==="page"?"page":""," row",m.length!==1?"s":""]}),t.jsxs("div",{style:{display:"flex",gap:10},children:[t.jsx("button",{onClick:d,style:{padding:"9px 18px",borderRadius:8,border:"1px solid #e5e7eb",background:"white",color:"#374151",fontWeight:600,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:"Cancel"}),t.jsx("button",{onClick:z,disabled:o.length===0||m.length===0,style:{padding:"9px 20px",borderRadius:8,border:"none",background:on,color:"white",fontWeight:700,fontSize:13,cursor:o.length===0||m.length===0?"not-allowed":"pointer",opacity:o.length===0||m.length===0?.5:1,fontFamily:"inherit",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"})]})]})]})})}const lh="sidrah_rtl",Mo="sidrah-lang-change";function pl(){try{return localStorage.getItem(lh)==="1"}catch{return!1}}function rh(){const e=!pl();try{localStorage.setItem(lh,e?"1":"0")}catch{}document.documentElement.setAttribute("dir",e?"rtl":"ltr"),document.documentElement.setAttribute("lang",e?"ar":"en-GB"),window.dispatchEvent(new CustomEvent(Mo))}function ne(){const[e,n]=C.useState(pl);return C.useEffect(()=>{const s=()=>n(pl());return window.addEventListener(Mo,s),document.documentElement.setAttribute("dir",pl()?"rtl":"ltr"),document.documentElement.setAttribute("lang",pl()?"ar":"en-GB"),()=>window.removeEventListener(Mo,s)},[]),e?Cy:_y}const _y={rtl:!1,nav:{dashboard:"Dashboard",inbox:"Inbox",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",reports:"Reports",users:"Users",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",settings:"Settings"},pages:{dashboard:"Dashboard",inbox:"Inbox",reports:"Reports",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",users:"Users"},new:"+ New",save:"Save",cancel:"Cancel",edit:"Edit",delete:"Delete",deletedBadge:"DELETED",restore:"Restore",restoring:"Restoring...",restoredOk:"Record restored successfully!",deletedBanner:"⚠️ This record has been deleted",deletedBy:"Deleted by",deletedOn:"Deleted on",deletedReason:"Reason",deleteModal:{title:"Confirm Deletion",subtitle:"Are you sure you want to delete this record?",softDeleteTitle:"Delete",softDeleteDesc:"Moves the record to deleted state. It can be restored later by an Administrator.",permanentDeleteTitle:"Permanent Delete",permanentDeleteDesc:"Permanently removes this record from the database. This action cannot be undone.",reasonLabel:"Reason for deletion (optional):",reasonPlaceholder:"Enter deletion reason…",softDeleteBtn:"Delete",permanentDeleteBtn:"Permanent Delete",cancelBtn:"Cancel",deleting:"Deleting…"},view:"View",back:"← Back",clear:"Clear",search:"Search",loading:"Loading...",saving:"Saving...",savedOk:"Saved successfully!",home:"Home",noRecords:"No records found",login:{subtitle:"Sign in to continue",username:"USERNAME",password:"PASSWORD",usernamePlaceholder:"Enter username",passwordPlaceholder:"Enter password",signIn:"Sign In",signingIn:"Signing in...",invalidCreds:"Invalid username or password",emptyFields:"Please enter username and password",connError:"Connection error: "},myProfile:"My Profile",signOut:"Sign Out",switchLang:"العربية (RTL)",filter:{numberTitle:"Number / Title",searchPlaceholder:"Search...",organization:"Organization",department:"Department",branch:"Branch",status:"Status",allOrgs:"All Organizations",allDepts:"All Departments",allBranches:"All Branches",allStatuses:"All Statuses",allTypes:"All Types"},col:{number:"Number",title:"Title",organization:"Organization",type:"Type",status:"Status",actions:"Actions",name:"Name",department:"Department",branch:"Branch",city:"City",email:"Email",management:"Management",organization_type:"Type",frequency:"Frequency",period:"Period",startDate:"Start Date",endDate:"End Date",auditor:"Auditor",manager:"Manager",functions:"Functions",requestedOn:"Requested On"},field:{number:"Number",title:"Title",organization:"Organization",management:"Management",department:"Department",section:"Section",branch:"Branch",type:"Type",date:"Date",time:"Time",status:"Status",description:"Description",assignedTo:"Assigned To",hsesField:"HSES Field",priority:"Priority",economyClass:"Economy Class",entityScope:"Entity Scope",productRelation:"Product Relation",repeatedEvent:"Repeated Event",solution:"Solution / Action Plan",actualCost:"Actual Cost",summary:"Resolution Summary",auditorComment:"Auditor Comment",incidentClass:"Incident Class",incidentField:"Incident Field",currentCondition:"Current Condition",proposedCondition:"Proposed Condition",ideaClass:"Idea Class",startingDate:"Starting Date",endingDate:"Ending Date",budget:"Budget",currency:"Currency",notes:"Notes",cycle:"Cycle",stage:"Stage",completionPct:"Completion %",actor:"Actor",escalationLevel:"Escalation Level",dateStart:"Start Date",dateEnd:"End Date",cycleType:"Cycle Type",progressIndicators:"Progress Indicators",impactLevel:"Impact Level",kpiName:"KPI Name",kpiType:"KPI Type",kpiMeasure:"KPI Measure",costPerCycle:"Cost per Cycle",chainLocation:"Chain Location",notifyManager:"Notify Manager",creationDate:"Creation Date",statusActive:"Active",statusInactive:"Inactive",name1:"Name",fullName:"Full Name",username:"Username",emailAddress:"Email Address",phoneNumber:"Phone Number",category:"Category",since:"Since",active:"Active",inactive:"Inactive",enabled:"Enabled",selectMgr:"-- Select manager --",select:"-- Select --",selectType:"-- Select type --",selectClass:"-- Select class --",selectField:"-- Select field --",selectStatus:"-- Select status --",solutionPlaceholder:"Describe the solution or action taken…",commentPlaceholder:"Optional comment…",high:"High",normal:"Normal",expenses:"Expenses",capital:"Capital",earn:"Earn",payLoss:"Pay/Loss",upstream:"Upstream",onstream:"On-stream",downstream:"Downstream",government:"Government",private:"Private",linkedOrder:"Linked Order",linkedIdea:"Linked Idea",convertedToOrder:"Converted to Order",originatingIdea:"Originating Idea",viewOrder:"View Order",viewIdea:"View Idea",monthly:"Monthly",quarterly:"Quarterly",yearly:"Yearly",cycleActive:"Active",cycleCompleted:"Completed",cyclePaused:"Paused",updateWindowDays:"Update Window (days)",incidentTriageWindowDays:"Triage Window (days)",incidentResolutionWindowDays:"Resolution Window (days)",orgAcronym:"Acronym",contactEmail:"Contact Email",orgCity:"City",orgName:"Organization Name",organizationType:"Organization Type",revenue_growth:"Revenue Growth (%)",net_profit:"Net Profit",cash_flow:"Cash Flow",strategic_goal_pct:"Strategic Goal (%)",customer_satisfaction:"Customer Satisfaction",employee_turnover_pct:"Employee Turnover (%)",open_safety_incidents:"Open Safety Incidents",compliance_score:"Compliance Score"},wf:{workflow:"Workflow",noActions:"No actions available for your role in this state.",applying:"Applying…",submit:"Submit",assignToManager:"Assign to Manager",reject:"Reject",submitSolution:"Submit Solution",resolutionComplete:"Resolution complete",moveToOutsourcing:"Move to Outsourcing",closeIdea:"Close Idea"},steps:{auditorTriage:"Auditor Triage (Step 2)",managerSolution:"Manager Solution (Step 3)",ownerComment:"Owner / Auditor Comment (Step 4)",auditorEval:"Auditor Evaluation (Step 2)",managerReview:"Manager Review (Step 3)"},formTitle:{newIncident:"New Incident",editIncident:"Edit Incident",viewIncident:"Incident: ",newIdea:"New Idea",editIdea:"Edit Idea",viewIdea:"Idea: ",newOrder:"New Order",editOrder:"Edit Order",viewOrder:"Order: ",newProcess:"New Process",editProcess:"Edit Process",viewProcess:"Process: ",newOrg:"New Organization",editOrg:"Edit Organization",newMgmt:"New Management",editMgmt:"Edit Management",newDept:"New Department",editDept:"Edit Department",newBranch:"New Branch",editBranch:"Edit Branch",newUser:"New User",editUser:"Edit User",viewUser:"User Profile",newCycle:"New Cycle",editCycle:"Edit Cycle",newKpi:"New KPI Input",editKpi:"Edit KPI Input",newDelegation:"New Delegation",viewDelegation:"Delegation: "},saveIncident:"Save Incident",saveIdea:"Save Idea",saveOrder:"Save Order",saveProcess:"Save Process",saveOrg:"Save Organization",saveMgmt:"Save Management",saveDept:"Save Department",saveBranch:"Save Branch",saveUser:"Save User",saveCycle:"Save Cycle",saveKpi:"Save KPI Input",saveDelegation:"Send Delegation",saveName:"Save",dash:{allOrgs:"All organizations",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",level2:"Level 2 — Critical Escalation",level1:"Level 1 — Auditor Review Needed",overduePrefix:"Overdue for Triage — ",overdueSuffix:" incident(s) past 3-day window",untriaged:"Untriaged Incidents",recentKpi:"Recent KPI Inputs",manageKpi:"Manage KPI Inputs",escalatedProcesses:"Escalated Processes",escalatedOrders:"Escalated Orders",level:"Level",revenueGrowth:"Revenue Growth",netProfit:"Net Profit",strategicGoal:"Strategic Goal",customerSat:"Customer Sat.",compliance:"Compliance",safetyInc:"Safety Incidents",total:"Total"},noIncidents:"No incidents found",noIdeas:"No ideas found",noOrders:"No orders found",noProcesses:"No processes found",noUsers:"No users found",noData:"No data found",users:{category:"Category",number:"Number",fullName:"Full Name",username:"Username",email:"Email Address",phone:"Phone Number",organization:"Organization",management:"Management",department:"Department",branch:"Branch",since:"Since",status:"Status",tools:"Tools",active:"Active",inactive:"Inactive",setPassword:"Set Password",newPassword:"New password",passwordUpdated:"Password updated!",passwordFailed:"Failed. Please try again.",disableConfirm:"Delete user? They will no longer appear in the list.",password:"Password"},inbox:{title:"Inbox",noMessages:"No messages"},reports:{title:"Reports",selectOrg:"Select Organization",generate:"Generate Report"},comments:{title:"Comments",placeholder:"Write a comment…",post:"Post",noComments:"No comments yet."},activity:{title:"Activity Log",created:"Created",by:"by"}},Cy={rtl:!0,nav:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",reports:"التقارير",users:"المستخدمون",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",settings:"الإعدادات"},pages:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",reports:"التقارير",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",users:"المستخدمون"},new:"+ جديد",save:"حفظ",cancel:"إلغاء",edit:"تعديل",delete:"حذف",deletedBadge:"محذوف",restore:"استعادة",restoring:"جارٍ الاستعادة...",restoredOk:"تمت استعادة السجل بنجاح!",deletedBanner:"⚠️ هذا السجل محذوف",deletedBy:"تم الحذف بواسطة",deletedOn:"تاريخ الحذف",deletedReason:"السبب",deleteModal:{title:"تأكيد الحذف",subtitle:"هل أنت متأكد من رغبتك في حذف هذا السجل؟",softDeleteTitle:"حذف",softDeleteDesc:"يتم نقل السجل إلى سلة المحذوفات. يمكن للمسؤول استعادته لاحقاً.",permanentDeleteTitle:"حذف نهائي",permanentDeleteDesc:"حذف السجل نهائياً من قاعدة البيانات. لا يمكن التراجع عن هذا الإجراء.",reasonLabel:"سبب الحذف (اختياري):",reasonPlaceholder:"أدخل سبب الحذف…",softDeleteBtn:"حذف",permanentDeleteBtn:"حذف نهائي",cancelBtn:"إلغاء",deleting:"جارٍ الحذف…"},view:"عرض",back:"رجوع →",clear:"مسح",search:"بحث",loading:"جارٍ التحميل...",saving:"جارٍ الحفظ...",savedOk:"تم الحفظ بنجاح!",home:"الرئيسية",noRecords:"لا توجد سجلات",login:{subtitle:"تسجيل الدخول للمتابعة",username:"اسم المستخدم",password:"كلمة المرور",usernamePlaceholder:"أدخل اسم المستخدم",passwordPlaceholder:"أدخل كلمة المرور",signIn:"تسجيل الدخول",signingIn:"جارٍ تسجيل الدخول...",invalidCreds:"اسم المستخدم أو كلمة المرور غير صحيحة",emptyFields:"الرجاء إدخال اسم المستخدم وكلمة المرور",connError:"خطأ في الاتصال: "},myProfile:"ملفي الشخصي",signOut:"تسجيل الخروج",switchLang:"English (LTR)",filter:{numberTitle:"الرقم / العنوان",searchPlaceholder:"بحث...",organization:"المؤسسة",department:"القسم",branch:"الفرع",status:"الحالة",allOrgs:"جميع المؤسسات",allDepts:"جميع الأقسام",allBranches:"جميع الفروع",allStatuses:"جميع الحالات",allTypes:"جميع الأنواع"},col:{number:"الرقم",title:"العنوان",organization:"المؤسسة",type:"النوع",status:"الحالة",actions:"الإجراءات",name:"الاسم",department:"القسم",branch:"الفرع",city:"المدينة",email:"البريد الإلكتروني",management:"الإدارة",organization_type:"النوع",frequency:"التكرار",period:"الفترة",startDate:"تاريخ البدء",endDate:"تاريخ الانتهاء",auditor:"المدقق",manager:"المدير",functions:"الوظائف",requestedOn:"تاريخ الطلب"},field:{number:"الرقم",title:"العنوان",organization:"المؤسسة",management:"الإدارة",department:"القسم",section:"القطاع",branch:"الفرع",type:"النوع",date:"التاريخ",time:"الوقت",status:"الحالة",description:"الوصف",assignedTo:"مُسند إلى",hsesField:"مجال السلامة والصحة",priority:"الأولوية",economyClass:"التصنيف الاقتصادي",entityScope:"نطاق الكيان",productRelation:"علاقة المنتج",repeatedEvent:"حدث متكرر",solution:"الحل / خطة العمل",actualCost:"التكلفة الفعلية",summary:"ملخص الحل",auditorComment:"تعليق المدقق",incidentClass:"تصنيف الحادث",incidentField:"مجال الحادث",currentCondition:"الوضع الراهن",proposedCondition:"الوضع المقترح",ideaClass:"تصنيف الفكرة",startingDate:"تاريخ البدء",endingDate:"تاريخ الانتهاء",budget:"الميزانية",currency:"العملة",notes:"الملاحظات",cycle:"الدورة",stage:"المرحلة",completionPct:"نسبة الاكتمال",actor:"المنفذ",escalationLevel:"مستوى التصعيد",dateStart:"تاريخ البدء",dateEnd:"تاريخ الانتهاء",cycleType:"نوع الدورة",progressIndicators:"مؤشرات التقدم",impactLevel:"مستوى التأثير",kpiName:"اسم المؤشر",kpiType:"نوع المؤشر",kpiMeasure:"قياس المؤشر",costPerCycle:"التكلفة لكل دورة",chainLocation:"موقع السلسلة",notifyManager:"إشعار المدير",creationDate:"تاريخ الإنشاء",statusActive:"نشط",statusInactive:"غير نشط",name1:"الاسم",fullName:"الاسم الكامل",username:"اسم المستخدم",emailAddress:"البريد الإلكتروني",phoneNumber:"رقم الهاتف",category:"الفئة",since:"منذ",active:"نشط",inactive:"غير نشط",enabled:"مفعّل",selectMgr:"-- اختر المدير --",select:"-- اختر --",selectType:"-- اختر النوع --",selectClass:"-- اختر التصنيف --",selectField:"-- اختر المجال --",selectStatus:"-- اختر الحالة --",solutionPlaceholder:"صف الحل أو الإجراء المتخذ…",commentPlaceholder:"تعليق اختياري…",high:"عالي",normal:"عادي",expenses:"مصروفات",capital:"رأس مال",earn:"إيرادات",payLoss:"دفع/خسارة",upstream:"مرحلة المنبع",onstream:"على الخط",downstream:"مرحلة المصب",government:"حكومي",private:"خاص",linkedOrder:"الأمر المرتبط",linkedIdea:"الفكرة المرتبطة",convertedToOrder:"تم التحويل إلى أمر",originatingIdea:"الفكرة الأصلية",viewOrder:"عرض الأمر",viewIdea:"عرض الفكرة",monthly:"شهري",quarterly:"ربع سنوي",yearly:"سنوي",cycleActive:"نشط",cycleCompleted:"مكتمل",cyclePaused:"موقوف",updateWindowDays:"نافذة التحديث (أيام)",incidentTriageWindowDays:"نافذة الفرز (أيام)",incidentResolutionWindowDays:"نافذة الحل (أيام)",orgAcronym:"الاختصار",contactEmail:"البريد الإلكتروني للتواصل",orgCity:"المدينة",orgName:"اسم المؤسسة",organizationType:"نوع المؤسسة",revenue_growth:"نمو الإيرادات (%)",net_profit:"صافي الربح",cash_flow:"التدفق النقدي",strategic_goal_pct:"الهدف الاستراتيجي (%)",customer_satisfaction:"رضا العملاء",employee_turnover_pct:"معدل دوران الموظفين (%)",open_safety_incidents:"حوادث السلامة المفتوحة",compliance_score:"درجة الامتثال"},wf:{workflow:"سير العمل",noActions:"لا توجد إجراءات متاحة لدورك في هذه الحالة.",applying:"جارٍ التطبيق...",submit:"إرسال",assignToManager:"تعيين للمدير",reject:"رفض",submitSolution:"إرسال الحل",resolutionComplete:"اكتمال الحل",moveToOutsourcing:"نقل للاستعانة بمصادر خارجية",closeIdea:"إغلاق الفكرة"},steps:{auditorTriage:"فرز المدقق (الخطوة 2)",managerSolution:"حل المدير (الخطوة 3)",ownerComment:"تعليق المالك / المدقق (الخطوة 4)",auditorEval:"تقييم المدقق (الخطوة 2)",managerReview:"مراجعة المدير (الخطوة 3)"},formTitle:{newIncident:"حادث جديد",editIncident:"تعديل الحادث",viewIncident:"الحادث: ",newIdea:"فكرة جديدة",editIdea:"تعديل الفكرة",viewIdea:"الفكرة: ",newOrder:"طلب جديد",editOrder:"تعديل الطلب",viewOrder:"الطلب: ",newProcess:"عملية جديدة",editProcess:"تعديل العملية",viewProcess:"العملية: ",newOrg:"مؤسسة جديدة",editOrg:"تعديل المؤسسة",newMgmt:"إدارة جديدة",editMgmt:"تعديل الإدارة",newDept:"قسم جديد",editDept:"تعديل القسم",newBranch:"فرع جديد",editBranch:"تعديل الفرع",newUser:"مستخدم جديد",editUser:"تعديل المستخدم",viewUser:"ملف المستخدم",newCycle:"دورة جديدة",editCycle:"تعديل الدورة",newKpi:"مؤشر أداء جديد",editKpi:"تعديل مؤشر الأداء",newDelegation:"تفويض جديد",viewDelegation:"التفويض: "},saveIncident:"حفظ الحادث",saveIdea:"حفظ الفكرة",saveOrder:"حفظ الطلب",saveProcess:"حفظ العملية",saveOrg:"حفظ المؤسسة",saveMgmt:"حفظ الإدارة",saveDept:"حفظ القسم",saveBranch:"حفظ الفرع",saveUser:"حفظ المستخدم",saveCycle:"حفظ الدورة",saveKpi:"حفظ مؤشر الأداء",saveDelegation:"إرسال التفويض",saveName:"حفظ",dash:{allOrgs:"جميع المؤسسات",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",level2:"المستوى 2 — تصعيد حرج",level1:"المستوى 1 — مراجعة المدقق مطلوبة",overduePrefix:"متأخر للفرز — ",overdueSuffix:" حادث(ة) تجاوز نافذة 3 أيام",untriaged:"حوادث غير مفرزة",recentKpi:"مؤشرات الأداء الأخيرة",manageKpi:"إدارة مؤشرات الأداء",escalatedProcesses:"عمليات متصاعدة",escalatedOrders:"طلبات متصاعدة",level:"المستوى",revenueGrowth:"نمو الإيرادات",netProfit:"صافي الربح",strategicGoal:"الهدف الاستراتيجي",customerSat:"رضا العملاء",compliance:"الامتثال",safetyInc:"حوادث السلامة",total:"الإجمالي"},noIncidents:"لا توجد حوادث",noIdeas:"لا توجد أفكار",noOrders:"لا توجد طلبات",noProcesses:"لا توجد عمليات",noUsers:"لا يوجد مستخدمون",noData:"لا توجد بيانات",users:{category:"الفئة",number:"الرقم",fullName:"الاسم الكامل",username:"اسم المستخدم",email:"البريد الإلكتروني",phone:"رقم الهاتف",organization:"المؤسسة",management:"الإدارة",department:"القسم",branch:"الفرع",since:"منذ",status:"الحالة",tools:"الأدوات",active:"نشط",inactive:"غير نشط",setPassword:"تعيين كلمة المرور",newPassword:"كلمة مرور جديدة",passwordUpdated:"تم تحديث كلمة المرور!",passwordFailed:"فشل. الرجاء المحاولة مرة أخرى.",disableConfirm:"حذف المستخدم؟ لن يظهر في القائمة بعد الآن.",password:"كلمة المرور"},inbox:{title:"البريد الوارد",noMessages:"لا توجد رسائل"},reports:{title:"التقارير",selectOrg:"اختر المؤسسة",generate:"إنشاء التقرير"},comments:{title:"التعليقات",placeholder:"اكتب تعليقاً…",post:"نشر",noComments:"لا توجد تعليقات بعد."},activity:{title:"سجل النشاط",created:"أُنشئ",by:"بواسطة"}};function _u({isOpen:e,doctype:n,docname:s,docTitle:l,isAdmin:r,isDeleting:a,onClose:i,onConfirmSoftDelete:d,onConfirmPermanentDelete:c}){const p=ne(),[w,v]=C.useState("");if(C.useEffect(()=>{e&&v("")},[e]),C.useEffect(()=>{const g=S=>{S.key==="Escape"&&e&&!a&&i()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[e,a,i]),!e)return null;const f=n.replace(/^SB\s+/,"");return t.jsx("div",{style:{position:"fixed",inset:0,zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:"12px",backgroundColor:"rgba(15, 23, 42, 0.6)",backdropFilter:"blur(3px)",animation:"fadeIn 0.15s ease"},onClick:g=>{g.target===g.currentTarget&&!a&&i()},children:t.jsxs("div",{className:"delete-modal-card",style:{background:"white",borderRadius:12,boxShadow:"0 20px 35px -10px rgba(0, 0, 0, 0.22)",maxWidth:390,width:"100%",padding:"16px 18px",boxSizing:"border-box",position:"relative",animation:"scaleIn 0.15s ease",border:"1px solid rgba(226, 232, 240, 0.9)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:12},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"#fee2e2",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#ef4444"},children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M3 6h18m-2 0v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6m3 0V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),t.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),t.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("h3",{style:{margin:0,fontSize:14,fontWeight:700,color:"#1e293b"},children:p.deleteModal.title}),t.jsx("p",{style:{margin:"2px 0 0",fontSize:11,color:"#64748b",lineHeight:1.3},children:p.deleteModal.subtitle})]}),t.jsx("button",{type:"button",onClick:i,disabled:a,style:{background:"transparent",border:"none",color:"#94a3b8",cursor:"pointer",padding:"2px 4px",borderRadius:4,fontSize:14,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"✕"})]}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:6,padding:"6px 10px",marginBottom:12,display:"flex",alignItems:"center",gap:6},children:[t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.4px",flexShrink:0},children:[f,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#1e293b",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l?`${l} (${s})`:s})]}),t.jsxs("div",{style:{marginBottom:14},children:[t.jsx("label",{style:{display:"block",fontSize:11,fontWeight:600,color:"#475569",marginBottom:4},children:p.deleteModal.reasonLabel}),t.jsx("input",{type:"text",value:w,onChange:g=>v(g.target.value),placeholder:p.deleteModal.reasonPlaceholder,disabled:a,style:{width:"100%",height:30,padding:"4px 8px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:12,boxSizing:"border-box",outline:"none"},onFocus:g=>{g.target.style.borderColor="#6366f1",g.target.style.boxShadow="0 0 0 2px rgba(99, 102, 241, 0.15)"},onBlur:g=>{g.target.style.borderColor="#cbd5e1",g.target.style.boxShadow="none"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"row",justifyContent:"flex-end",gap:8,flexWrap:"wrap"},children:[t.jsx("button",{type:"button",onClick:i,disabled:a,style:{padding:"5px 12px",borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#475569",fontSize:12,fontWeight:600,cursor:a?"not-allowed":"pointer",transition:"background 0.15s"},children:p.deleteModal.cancelBtn}),t.jsxs("button",{type:"button",onClick:()=>d(w),disabled:a,title:p.deleteModal.softDeleteDesc,style:{padding:"5px 12px",borderRadius:6,border:"1px solid #fca5a5",background:"#fff1f2",color:"#b91c1c",fontSize:12,fontWeight:600,cursor:a?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:4,transition:"all 0.15s"},onMouseEnter:g=>{a||(g.currentTarget.style.background="#fee2e2")},onMouseLeave:g=>{a||(g.currentTarget.style.background="#fff1f2")},children:[t.jsx("span",{children:"🗑️"}),a?p.deleteModal.deleting:p.deleteModal.softDeleteBtn]}),r&&t.jsxs("button",{type:"button",onClick:()=>c(w),disabled:a,title:p.deleteModal.permanentDeleteDesc,style:{padding:"5px 12px",borderRadius:6,border:"none",background:"#ef4444",color:"#ffffff",fontSize:12,fontWeight:600,cursor:a?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:4,boxShadow:"0 1px 3px rgba(239, 68, 68, 0.25)",transition:"all 0.15s"},onMouseEnter:g=>{a||(g.currentTarget.style.background="#dc2626")},onMouseLeave:g=>{a||(g.currentTarget.style.background="#ef4444")},children:[t.jsx("span",{children:"💥"}),a?p.deleteModal.deleting:p.deleteModal.permanentDeleteBtn]})]})]})})}const ah="/assets/logo-BlYgMyx5.png";function ih({collapsed:e,onToggleCollapsed:n,activePage:s,onNavigate:l,hasDashboard:r,hasReports:a,hasDelegations:i,role:d,hideSettings:c,rtl:p,navLabels:w,settingsLabel:v}){const f=c?[]:fy(d);return t.jsxs("div",{style:{width:e?60:230,background:"linear-gradient(180deg, #0f172a 0%, #1e1b4b 60%, #0b0f19 100%)",color:"white",flexShrink:0,display:"flex",flexDirection:"column",position:"sticky",top:0,height:"100vh",transition:"width 0.22s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden",boxShadow:"2px 0 12px rgba(0, 0, 0, 0.15)",borderRight:"1px solid rgba(255, 255, 255, 0.06)",zIndex:40},children:[t.jsxs("div",{style:{padding:e?"16px 0":"16px 16px 14px",borderBottom:"1px solid rgba(255, 255, 255, 0.08)",display:"flex",alignItems:"center",justifyContent:e?"center":"space-between",gap:8,flexShrink:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,overflow:"hidden"},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"white",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,boxShadow:"0 2px 8px rgba(0, 0, 0, 0.25)",padding:3,boxSizing:"border-box",overflow:"hidden"},children:t.jsx("img",{src:ah,alt:"Logo",style:{width:"100%",height:"100%",objectFit:"contain"},onError:g=>{g.currentTarget.style.display="none"}})}),!e&&t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:t.jsx("span",{style:{fontSize:14,fontWeight:800,whiteSpace:"nowrap",color:"#ffffff",letterSpacing:"-0.2px"},children:p?"صدرة للأعمال":"Sidrah"})})]}),t.jsx("button",{type:"button",onClick:n,title:e?p?"توسيع":"Expand":p?"طي":"Collapse",style:{background:"rgba(255, 255, 255, 0.06)",border:"1px solid rgba(255, 255, 255, 0.1)",borderRadius:6,color:"rgba(255, 255, 255, 0.75)",cursor:"pointer",fontSize:11,padding:"4px 7px",flexShrink:0,lineHeight:1,transition:"all 0.15s ease"},onMouseEnter:g=>{g.currentTarget.style.background="rgba(255, 255, 255, 0.15)",g.currentTarget.style.color="#ffffff"},onMouseLeave:g=>{g.currentTarget.style.background="rgba(255, 255, 255, 0.06)",g.currentTarget.style.color="rgba(255, 255, 255, 0.75)"},children:e?"▶":"✕"})]}),t.jsxs("nav",{style:{padding:"12px 8px",flex:1,overflowY:"auto",overflowX:"hidden"},children:[uy.filter(({id:g})=>(g!=="dashboard"||r)&&(g!=="reports"||a)&&(g!=="delegations"||i)).map(({id:g,icon:S})=>{const k=w[g]||g,y=g===s;return t.jsxs("div",{onClick:()=>l(g),title:e?k:void 0,className:"sidebar-nav-item",style:{padding:e?"8px 0":"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:10,background:y?"rgba(99, 102, 241, 0.28)":"transparent",border:y?"1px solid rgba(129, 140, 248, 0.35)":"1px solid transparent",borderRadius:8,fontSize:e?15:13,color:y?"#ffffff":"rgba(255, 255, 255, 0.78)",fontWeight:y?600:400,transition:"all 0.15s ease",whiteSpace:"nowrap",marginBottom:2,position:"relative"},onMouseEnter:m=>{y||(m.currentTarget.style.background="rgba(255, 255, 255, 0.08)",m.currentTarget.style.color="#ffffff")},onMouseLeave:m=>{y||(m.currentTarget.style.background="transparent",m.currentTarget.style.color="rgba(255, 255, 255, 0.78)")},children:[t.jsx("span",{style:{flexShrink:0,fontSize:e?15:13},children:S}),!e&&t.jsx("span",{children:k})]},g)}),f.length>0&&t.jsxs(t.Fragment,{children:[!e&&t.jsx("div",{style:{padding:"12px 12px 4px",fontSize:10,color:"rgba(255, 255, 255, 0.45)",fontWeight:700,letterSpacing:"0.8px",textTransform:"uppercase",marginTop:8},children:v}),e&&t.jsx("div",{style:{margin:"10px auto",width:26,borderTop:"1px solid rgba(255, 255, 255, 0.12)"}}),f.map(({id:g,icon:S})=>{const k=w[g]||g,y=g===s;return t.jsxs("div",{onClick:()=>l(g),title:e?k:void 0,className:"sidebar-nav-item",style:{padding:e?"8px 0":"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:10,background:y?"rgba(99, 102, 241, 0.28)":"transparent",border:y?"1px solid rgba(129, 140, 248, 0.35)":"1px solid transparent",borderRadius:8,fontSize:e?15:13,color:y?"#ffffff":"rgba(255, 255, 255, 0.78)",fontWeight:y?600:400,transition:"all 0.15s ease",whiteSpace:"nowrap",marginBottom:2},onMouseEnter:m=>{y||(m.currentTarget.style.background="rgba(255, 255, 255, 0.08)",m.currentTarget.style.color="#ffffff")},onMouseLeave:m=>{y||(m.currentTarget.style.background="transparent",m.currentTarget.style.color="rgba(255, 255, 255, 0.78)")},children:[t.jsx("span",{style:{flexShrink:0,fontSize:e?15:13},children:S}),!e&&t.jsx("span",{children:k})]},g)})]})]})]})}const Pl=new Set(["SB Incident","SB Idea","SB Order","SB Process","SB Organization","SB Cycle","SB KPI Input","Managements","Department","Branch","Incident Types","Idea Types","Order Types","Process Types","Incident Class","Incident Field","Incident Statuses","Idea Statuses","Order Statuses","Process Statuses","SB Group Company"]);let Ts="";async function Ud(){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 s=(await e.json()).message||"";if(s)return Ts=s,s}}catch(e){console.error("CSRF fetch error:",e)}return Ts}async function tn(){return Ts||await Ud(),Ts}function Fa(e,n){try{if(e!=null&&e._server_messages){const s=JSON.parse(e._server_messages);if(s.length){const l=JSON.parse(s[0]);if(l!=null&&l.message)return l.message.replace(/<[^>]+>/g,"")}}}catch{}return(e==null?void 0:e.message)||(e==null?void 0:e.exception)||n}async function At(e,n,s=[]){if(Pl.has(e)){const i=`${ce}/api/method/sidrah_business.api.get_sb_doc?doctype=${encodeURIComponent(e)}&name=${encodeURIComponent(n)}`,d=await fetch(i,{credentials:"include",headers:{Accept:"application/json"}});if(!d.ok)throw new Error(`API Error: ${d.status}`);return(await d.json()).message}const l=s.length?`?fields=${encodeURIComponent(JSON.stringify(s))}`:"",r=await fetch(`${ce}/api/v1/resource/${e}/${encodeURIComponent(n)}${l}`,{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 Ho(e,n,s="",l=!1){const r=await tn();if(Pl.has(e)){const d=new URLSearchParams({doctype:e,name:n});s&&d.append("reason",s),l&&d.append("permanent","1");const c=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":r},body:d.toString()});if(!c.ok){const p=await c.json().catch(()=>({}));throw new Error(Fa(p,`Error deleting ${n}`))}return}const a=new URLSearchParams({doctype:e,name:n});s&&a.append("reason",s),l&&a.append("permanent","1");const i=await fetch(`${ce}/api/method/sidrah_business.soft_delete.soft_delete`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":r},body:a.toString()});if(!i.ok){const d=await i.json().catch(()=>({}));throw new Error(Fa(d,`Error deleting ${n}`))}return await i.json()}async function zy(e,n){const s=await tn();if(Pl.has(e)){const a=new URLSearchParams({doctype:e,name:n}),i=await fetch(`${ce}/api/method/sidrah_business.api.restore_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:a.toString()});if(!i.ok){const c=await i.json().catch(()=>({}));throw new Error(Fa(c,`Error restoring ${n}`))}return(await i.json()).message||{success:!0}}const l=new URLSearchParams({doctype:e,name:n}),r=await fetch(`${ce}/api/method/sidrah_business.soft_delete.restore_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:l.toString()});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(Fa(a,`Error restoring ${n}`))}return await r.json()}async function Te(e){if(Pl.has(e))try{const l=`${ce}/api/method/sidrah_business.api.get_sb_list?doctype=${encodeURIComponent(e)}&limit=500`,r=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return r.ok?(await r.json()).message||[]:[]}catch{return[]}const n=encodeURIComponent('["*"]'),s=`${ce}/api/v1/resource/${e}?limit_page_length=500&fields=${n}`;try{const l=await fetch(s,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return l.status===401||l.status===403?[]:l.ok?(await l.json()).data||[]:[]}catch(l){return console.error("Get error:",l),[]}}async function Qi(e,n){const s=await tn();if(Pl.has(e)){const r=new URLSearchParams({doctype:e,data_json:JSON.stringify(n)}),a=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":s},body:r.toString()});if(!a.ok){const d=await a.json().catch(()=>({}));throw new Error(d.message||d.exc||`Error creating ${e}`)}return{data:(await a.json()).message}}const l=`${ce}/api/v1/resource/${e}`;try{const r=await fetch(l,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":s},body:JSON.stringify(n)});if(r.status===401||r.status===403)throw new Error("Permission denied - login required");if(!r.ok){const a=await r.json();throw new Error(a.message||a.exc||`API Error: ${r.status}`)}return await r.json()}catch(r){throw console.error("Post error:",r),r}}async function Ma(e,n,s){const l=await tn();if(Pl.has(e)){const a=new URLSearchParams({doctype:e,name:n,data_json:JSON.stringify(s)}),i=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":l},body:a.toString()});if(!i.ok){const c=await i.json().catch(()=>({}));throw new Error(c.message||c.exc||`Error updating ${e}`)}return{data:(await i.json()).message}}const r=`${ce}/api/v1/resource/${e}/${encodeURIComponent(n)}`;try{const a=await fetch(r,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":l},body:JSON.stringify(s)});if(a.status===401||a.status===403)throw new Error("Permission denied - login required");if(!a.ok){const i=await a.json();throw new Error(i.message||"Update Error")}return await a.json()}catch(a){throw console.error("Update error:",a),a}}async function Iy(){const e=`${ce}/api/v1/resource/User?limit_page_length=500&fields=["name","full_name"]`;try{const n=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return n.status===401||n.status===403?[]:n.ok?(await n.json()).data||[]:[]}catch(n){return console.error("Get users error:",n),[]}}async function Ey(e,n){const s=new FormData;s.append("usr",e),s.append("pwd",n);const r=await(await fetch(`${ce}/api/method/login`,{method:"POST",credentials:"include",body:s})).json();return r.csrf_token?Ts=r.csrf_token:await Ud(),r}async function Ty(){const e=await tn();try{await fetch(`${ce}/api/method/logout`,{method:"POST",credentials:"include",headers:{"X-Frappe-CSRF-Token":e,Accept:"application/json"}})}catch{}Ts=""}function Py(){return Ts}async function oh(){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 Ay(){const e=JSON.stringify([["name","not in",["Administrator","Guest"]]]),n=`${ce}/api/v1/resource/User?limit_page_length=500&fields=${encodeURIComponent('["*"]')}&filters=${encodeURIComponent(e)}`;try{const s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).data||[]:[]}catch{return[]}}async function Ry(){const e=`${ce}/api/method/sidrah_business.api.get_user_role_map`;try{const n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||{}:{}}catch{return{}}}async function dh(e,n){await Ma("User",e,{new_password:n})}async function Dy(e=20){try{const n=`${ce}/api/method/sidrah_business.api.get_notifications?limit=${e}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function Ly(){const e=await tn();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 Oy(e){const n=await tn();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":n},body:new URLSearchParams({name:e}).toString()})}catch{}}async function Ny(e){const n=await tn(),s=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":n},body:s.toString()})}async function Wy(e,n){try{const s=`${ce}/api/method/sidrah_business.api.get_doc_comments?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(n)}`,l=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function By(e,n,s){const l=await tn(),r=new URLSearchParams({doctype:e,docname:n,content:s}),a=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":l},body:r.toString()});if(!a.ok)throw new Error("Failed to post comment");return(await a.json()).message}async function $y(e,n){try{const s=`${ce}/api/method/sidrah_business.api.get_doc_versions?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(n)}`,l=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function ch(e){try{const n=`${ce}/api/method/sidrah_business.api.get_user_roles?user=${encodeURIComponent(e)}`,s=await fetch(n,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function Uy(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_organization`,n=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return n.ok&&(await n.json()).message||""}catch{return""}}async function Rs(e,n={}){const s=await tn(),l=new URLSearchParams(n),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":s},body:l.toString()});if(!r.ok){const i=await r.json().catch(()=>({}));throw new Error(i.message||i.exc||`Error calling ${e}`)}return(await r.json()).message}async function Fy(e,n,s="",l,r,a){const i={name:e,action:n,comment:s};return l!==void 0&&(i.stage=l),a!==void 0&&(i.cycle_status=a),Rs("apply_order_workflow",i)}async function My(e,n,s=""){return Rs("apply_incident_workflow",{name:e,action:n,fields_json:s})}async function Hy(e,n,s=""){return Rs("apply_idea_workflow",{name:e,action:n,fields_json:s})}async function Gy(e=""){const n=`${ce}/api/method/sidrah_business.api.get_dashboard_data${e?`?organization=${encodeURIComponent(e)}`:""}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||{}:{escalated_processes:[],escalated_orders:[],untriaged_incidents:[],kpi_inputs:[]}}async function Ky(e,n={}){return Rs("get_report_data",{report_name:e,filters_json:JSON.stringify(n)})}async function Qy(){try{const e=`${ce}/api/method/sidrah_business.api.get_inbox_items`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function Yy(e,n,s="",l="",r="",a=""){return Rs("create_delegation",{manager:e,functions_json:JSON.stringify(n),organization:s,remarks:l,incident_name:r,idea_name:a})}async function Xy(e,n,s=""){return Rs("respond_to_delegation",{name:e,response:n,remarks:s})}async function qy(e,n=""){return Rs("revoke_delegation",{name:e,remarks:n})}async function Jy(){try{const e=`${ce}/api/method/sidrah_business.api.get_delegations`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function Zy(e){const n=`${ce}/api/method/sidrah_business.api.get_delegation?name=${encodeURIComponent(e)}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});if(!s.ok)throw new Error("Failed to load delegation");return(await s.json()).message}async function Vy(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_delegated_functions`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function e0(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_delegated_organizations`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||{}:{}}catch{return{}}}async function t0(){try{const e=await tn(),n=await fetch(`${ce}/api/method/sidrah_business.api.get_group_companies`,{method:"GET",credentials:"include",headers:{Accept:"application/json","X-Frappe-CSRF-Token":e}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function n0(){const e=Py();return e||Ud()}async function Vl(e){const n=await fetch(`${ce}/api/method/sidrah_business.api.get_process?name=${encodeURIComponent(e)}`,{credentials:"include",headers:{Accept:"application/json"}});if(!n.ok){const l=await n.json().catch(()=>({}));throw new Error(l.message||`Failed to load process (${n.status})`)}const s=await n.json();return s.message||s.data}async function s0(e,n,s={}){const l=await n0(),r=new URLSearchParams({name:e,action:n});s.actor_status&&r.set("actor_status",String(s.actor_status)),s.actor_comment&&r.set("actor_comment",String(s.actor_comment)),s.progress_indicators&&r.set("progress_indicators",JSON.stringify(s.progress_indicators));const a=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":l},body:r.toString()});if(!a.ok){const d=await a.json().catch(()=>({})),c=d.message||(d.exception?String(d.exception).split(` `).pop():"")||d.exc_type||`Workflow action "${n}" failed (${a.status})`;throw new Error(c)}const i=await a.json();return i.message||i.data}const l0=["dashboard","incidents","incidents-form","ideas","ideas-form","orders","orders-form","processes","processes-form","processes-workflow","organizations","organizations-form","managements","managements-form","departments","departments-form","branches","branches-form","incident-types","incident-types-form","idea-types","idea-types-form","order-types","order-types-form","process-types","process-types-form","incident-statuses","incident-statuses-form","idea-statuses","idea-statuses-form","order-statuses","order-statuses-form","process-statuses","process-statuses-form","users","users-form","cycles","cycles-form","kpi-input","kpi-input-form","delegations","delegations-form","inbox","reports","profile"],Cu=new Set(l0),r0={"incidents-form":"incidents","ideas-form":"ideas","orders-form":"orders","processes-form":"processes","processes-workflow":"processes","organizations-form":"organizations","managements-form":"managements","departments-form":"departments","branches-form":"branches","incident-types-form":"incident-types","idea-types-form":"idea-types","order-types-form":"order-types","process-types-form":"process-types","incident-statuses-form":"incident-statuses","idea-statuses-form":"idea-statuses","order-statuses-form":"order-statuses","process-statuses-form":"process-statuses","users-form":"users","cycles-form":"cycles","kpi-input-form":"kpi-input","delegations-form":"delegations",profile:"dashboard"};function zu(){const e=window.location.hash.replace(/^#\/?/,"");if(e)return Cu.has(e)?e:null;const n=window.location.pathname.split("/").filter(Boolean).pop()||"";return Cu.has(n)?n:null}function a0(e){return e?r0[e]??e:null}function i0(e){return`#/${e}`}function o0({onLogin:e}){const n=ne(),[s,l]=C.useState(""),[r,a]=C.useState(""),[i,d]=C.useState(""),[c,p]=C.useState(!1),[w,v]=C.useState(!1),[f,g]=C.useState(!1),S=async()=>{if(!s||!r){d(n.login.emptyFields);return}p(!0),d("");try{const y=await Ey(s,r);if(y.message==="Logged In"){const o=await oh()||s,u=await ch(o),h=u.some(z=>["SB Admin","System Manager"].includes(z))?"Admin":u.includes("SB Auditor")?"Auditor":u.includes("SB Owner")?"Owner":u.includes("SB X-Auditor")?"XAuditor":u.includes("SB Manager")?"Manager":"Employee";e({name:o,full_name:y.full_name||s,role:h})}else d(n.login.invalidCreds)}catch(y){d(n.login.connError+(y instanceof Error?y.message:"Unknown"))}p(!1)},k=y=>({width:"100%",padding:"11px 16px",border:`1.5px solid ${y?"#6366f1":"#e2e8f0"}`,borderRadius:8,fontSize:14,background:y?"#f8faff":"#ffffff",color:"#1e293b",outline:"none",transition:"all 0.18s ease",boxSizing:"border-box",boxShadow:y?"0 0 0 3px rgba(99, 102, 241, 0.15)":"none"});return t.jsx("div",{style:{minHeight:"100vh",background:"#f8fafc",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Segoe UI, system-ui, sans-serif",padding:"20px"},children:t.jsxs("div",{style:{width:380,maxWidth:"100%",display:"flex",flexDirection:"column",alignItems:"center"},children:[t.jsx("div",{style:{width:72,height:72,borderRadius:18,background:"white",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:20,boxShadow:"0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04)",border:"1px solid #f1f5f9",overflow:"hidden",padding:10},children:t.jsx("img",{src:ah,alt:"Logo",style:{width:"100%",height:"100%",objectFit:"contain"},onError:y=>{y.currentTarget.style.display="none"}})}),t.jsxs("div",{style:{textAlign:"center",marginBottom:24},children:[t.jsx("h1",{style:{fontSize:22,fontWeight:800,color:"#0f172a",letterSpacing:"-0.3px",margin:0},children:n.rtl?"صدرة للأعمال":"Sidrah"}),t.jsx("div",{style:{fontSize:13,color:"#6366f1",fontWeight:600,marginTop:4},children:n.rtl?"نظام إدارة العمليات والأعمال":"Asset Management System"}),t.jsx("div",{style:{fontSize:12,color:"#94a3b8",marginTop:6},children:n.login.subtitle})]}),t.jsxs("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:12},children:[t.jsx("div",{children:t.jsx("input",{value:s,onChange:y=>l(y.target.value),onKeyDown:y=>y.key==="Enter"&&S(),onFocus:()=>v(!0),onBlur:()=>v(!1),style:k(w),placeholder:n.login.usernamePlaceholder,autoComplete:"username"})}),t.jsx("div",{children:t.jsx("input",{type:"password",value:r,onChange:y=>a(y.target.value),onKeyDown:y=>y.key==="Enter"&&S(),onFocus:()=>g(!0),onBlur:()=>g(!1),style:k(f),placeholder:n.login.passwordPlaceholder,autoComplete:"current-password"})}),i&&t.jsx("div",{style:{padding:"9px 12px",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:8,color:"#dc2626",fontSize:12,textAlign:"center"},children:i}),t.jsx("button",{type:"button",onClick:S,disabled:c,style:{background:c?"#818cf8":"#4f46e5",color:"white",border:"none",padding:"12px",borderRadius:8,fontSize:14,cursor:c?"not-allowed":"pointer",fontWeight:600,marginTop:4,boxShadow:"0 2px 8px rgba(79, 70, 229, 0.3)",transition:"all 0.18s ease"},onMouseEnter:y=>{c||(y.currentTarget.style.background="#4338ca")},onMouseLeave:y=>{c||(y.currentTarget.style.background="#4f46e5")},children:c?n.login.signingIn:n.login.signIn}),t.jsx("div",{style:{textAlign:"center",marginTop:8},children:t.jsx("button",{type:"button",onClick:rh,style:{fontSize:12,color:"#94a3b8",background:"none",border:"none",cursor:"pointer"},onMouseEnter:y=>y.currentTarget.style.color="#475569",onMouseLeave:y=>y.currentTarget.style.color="#94a3b8",children:n.switchLang})})]})]})})}function d0(e,n){const s=parseInt(e.replace("#",""),16),l=s>>16&255,r=s>>8&255,a=s&255,i=d=>Math.round(d+(255-d)*n);return`rgb(${i(l)}, ${i(r)}, ${i(a)})`}function Gl(e,n){const s=parseInt(e.replace("#",""),16),l=s>>16&255,r=s>>8&255,a=s&255;return`rgba(${l}, ${r}, ${a}, ${n})`}function ta({title:e,data:n,color:s,onSelect:l}){const[,r]=n[0]??["Total",0,""],a=n.slice(1),i=a.map((c,p)=>d0(s,Math.min(p*.16,.7))),d=a.map(([c,p,w],v)=>[c,p,w,i[v]]).filter(([,c])=>c>0);return t.jsxs("div",{className:"status-card",style:{borderRadius:18,padding:"16px 18px 18px",height:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",minWidth:0,position:"relative",overflow:"hidden"},children:[t.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",background:`linear-gradient(160deg, ${Gl(s,.09)} 0%, transparent 55%)`}}),t.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:3,background:`linear-gradient(90deg, ${s}, ${Gl(s,.35)})`}}),t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:14},children:[t.jsx("span",{className:"status-card-title",style:{fontSize:13,fontWeight:700,paddingTop:4},children:e}),t.jsx("span",{style:{fontSize:14,fontWeight:800,color:"white",background:s,lineHeight:1,minWidth:26,textAlign:"center",padding:"6px 9px",borderRadius:10,boxShadow:`0 4px 10px ${Gl(s,.35)}`},children:r})]}),r>0&&t.jsx("div",{style:{display:"flex",height:9,borderRadius:999,overflow:"hidden",background:Gl(s,.1),marginBottom:13},children:d.map(([c,p,w,v],f)=>t.jsx("div",{title:`${c}: ${p}`,onClick:g=>{g.stopPropagation(),l==null||l(w)},style:{flex:`${p} 0 0`,background:v,borderRight:ft.jsxs("div",{className:"status-card-row",onClick:p>0?f=>{f.stopPropagation(),l==null||l(w)}:void 0,style:{display:"flex",alignItems:"center",gap:9,padding:"4px 6px",borderRadius:8,cursor:p>0&&l?"pointer":"default",transition:"background 0.12s"},children:[t.jsx("span",{style:{width:9,height:9,borderRadius:"50%",background:i[v],flexShrink:0,boxShadow:`0 0 0 3px ${Gl(i[v],.18)}`}}),t.jsx("span",{className:"status-card-label",style:{flex:1,fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c}),t.jsx("span",{className:"status-card-count",style:{fontSize:12,fontWeight:700,flexShrink:0},children:p})]},c))})]})}function Gt({value:e,onChange:n,organizations:s,placeholder:l="-- Choose organization --",disabled:r=!1,small:a=!1}){var v;const[i,d]=C.useState(!1),c=C.useRef(null);C.useEffect(()=>{const f=g=>{c.current&&!c.current.contains(g.target)&&d(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[]);const p=e?((v=s.find(f=>f.organization_name===e||f.name===e))==null?void 0:v.organization_name)??e:l,w=s.filter(f=>!!f.is_active||f.organization_name===e||f.name===e);return t.jsxs("div",{ref:c,style:{position:"relative",width:"100%"},children:[t.jsxs("div",{onClick:()=>!r&&d(f=>!f),style:{width:"100%",padding:a?"4px 8px":"7px 10px",border:"1px solid #ddd",borderRadius:6,fontSize:a?11:12,cursor:r?"default":"pointer",height:a?28:34,background:r?"#f5f5f5":"white",color:e?"#333":"#aaa",display:"flex",justifyContent:"space-between",alignItems:"center",borderColor:i?"#3498db":"#ddd",transition:"border-color 0.2s",userSelect:"none",boxSizing:"border-box",opacity:r?.75:1},children:[t.jsx("span",{children:p}),t.jsx("span",{style:{fontSize:9,color:"#999",transform:i?"rotate(180deg)":"none",transition:"transform 0.2s"},children:"▼"})]}),i&&t.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:t.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[t.jsx(Iu,{label:l,selected:!e,active:!0,isPlaceholder:!0,small:a,onClick:()=>{n(""),d(!1)}}),w.length===0&&t.jsx("div",{style:{padding:"12px 16px",color:"#aaa",fontSize:13},children:"No organizations"}),w.map(f=>t.jsx(Iu,{label:f.organization_name,selected:e===f.organization_name||e===f.name,active:!!f.is_active,isPlaceholder:!1,small:a,onClick:()=>{n(f.organization_name),d(!1)}},f.name))]})})]})}function Iu({label:e,selected:n,active:s,isPlaceholder:l,small:r,onClick:a}){const[i,d]=C.useState(!1),c=n?"#2563eb":i?"#f0f4ff":"transparent",p=n?"white":l?"#aaa":s?"#1a2332":"#e74c3c";return t.jsx("div",{onClick:a,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),style:{padding:r?"6px 12px":"8px 14px",cursor:"pointer",fontSize:12,background:c,color:p,transition:"background 0.1s"},children:e})}function Gn({items:e,type:n,onNavigate:s}){const l=ne();if(!e.length)return null;const r=n==="process"?"processes-form":"orders-form",a=n==="process"?l.dash.escalatedProcesses:l.dash.escalatedOrders;return t.jsxs("div",{children:[t.jsxs("h4",{style:{fontWeight:700,fontSize:12,color:"#e74c3c",marginBottom:6},children:[a," (",e.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:e.map(i=>t.jsxs("div",{onClick:()=>s(r,i.name),style:{padding:"8px 12px",background:"#fff5f5",borderRadius:7,border:"1px solid #fecaca",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsxs("div",{children:[t.jsx("span",{style:{fontWeight:700,fontSize:12},children:i.number||i.name}),t.jsx("span",{style:{fontSize:11,color:"#666",marginLeft:8},children:i.title})]}),t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#e74c3c",background:"#fecaca",padding:"2px 8px",borderRadius:10},children:[l.dash.level," ",i.escalation_level]})]},i.name))})]})}function c0({kpi:e}){const n=ne();return t.jsxs("div",{className:"dashboard-kpi-card",style:{borderRadius:12,padding:14,border:"1px solid #e2e8f0"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:8},children:[t.jsx("div",{style:{fontWeight:700,fontSize:13,color:"#1e293b"},children:e.organization}),t.jsx("span",{style:{fontSize:11,fontWeight:600,color:"#6366f1",background:"#eff6ff",border:"1px solid #bfdbfe",padding:"1px 7px",borderRadius:12},children:e.period})]}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:6},children:[{label:n.dash.revenueGrowth,val:e.revenue_growth!=null?`${e.revenue_growth}%`:"—"},{label:n.dash.netProfit,val:e.net_profit!=null?e.net_profit.toLocaleString():"—"},{label:n.dash.strategicGoal,val:e.strategic_goal_pct!=null?`${e.strategic_goal_pct}%`:"—"},{label:n.dash.customerSat,val:e.customer_satisfaction!=null?e.customer_satisfaction:"—"},{label:n.dash.compliance,val:e.compliance_score!=null?e.compliance_score:"—"},{label:n.dash.safetyInc,val:e.open_safety_incidents!=null?e.open_safety_incidents:"—"}].map(({label:s,val:l})=>t.jsxs("div",{style:{background:"#f8fafc",padding:"6px 8px",borderRadius:6,border:"1px solid #f1f5f9"},children:[t.jsx("div",{style:{fontSize:10,color:"#64748b",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.2px"},children:s}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginTop:1},children:l})]},s))})]})}function u0({data:e}){if(!e.length)return t.jsx("p",{style:{color:"#aaa",fontSize:13},children:"No cycle data available for trend chart."});const n=Math.max(...e.map(s=>s.pass+s.fail+s.unknown),1);return t.jsxs("div",{children:[t.jsx("div",{style:{display:"flex",gap:10,alignItems:"flex-end",overflowX:"auto",paddingBottom:4},children:e.map(s=>{const l=s.pass+s.fail+s.unknown||1,r=80;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:3,minWidth:48},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column-reverse",gap:1,height:r,width:32},children:[t.jsx("div",{title:`Pass: ${s.pass}`,style:{height:Math.round(s.pass/n*r),background:"#27ae60",borderRadius:"2px 2px 0 0",minHeight:s.pass?2:0}}),t.jsx("div",{title:`Fail: ${s.fail}`,style:{height:Math.round(s.fail/n*r),background:"#e74c3c",borderRadius:"2px 2px 0 0",minHeight:s.fail?2:0}}),t.jsx("div",{title:`Unknown: ${s.unknown}`,style:{height:Math.round(s.unknown/n*r),background:"#95a5a6",borderRadius:"2px 2px 0 0",minHeight:s.unknown?2:0}})]}),t.jsx("div",{style:{fontSize:9,color:"#999",textAlign:"center",lineHeight:1.2},children:s.month.replace(/^(\d{4})-(\d{2})$/,(a,i,d)=>`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][+d-1]} ${i}`)}),t.jsx("div",{style:{fontSize:9,color:"#555",textAlign:"center"},children:l>1?Math.round(s.pass/l*100)+"%":"—"})]},s.month)})}),t.jsx("div",{style:{display:"flex",gap:16,marginTop:8},children:[["#27ae60","Pass"],["#e74c3c","Fail"],["#95a5a6","Unknown"]].map(([s,l])=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,fontSize:11},children:[t.jsx("div",{style:{width:10,height:10,background:s,borderRadius:2}}),t.jsx("span",{style:{color:"#666"},children:l})]},l))})]})}function Jt({label:e,icon:n,onClick:s}){return t.jsxs("button",{onClick:s,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:l=>l.currentTarget.style.boxShadow="0 3px 10px rgba(0,0,0,0.12)",onMouseLeave:l=>l.currentTarget.style.boxShadow="0 1px 3px rgba(0,0,0,0.06)",children:[t.jsx("span",{style:{fontSize:15},children:n}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#444",whiteSpace:"nowrap"},children:e})]})}function p0({dashData:e,fi:n,fid:s,fo:l,fp:r,incidentStatuses:a,ideaStatuses:i,orderStatuses:d,processStatuses:c,onNavigate:p,onNavigateStatus:w}){const v=ne(),f=(e==null?void 0:e.escalated_processes)||[],g=(e==null?void 0:e.escalated_orders)||[],S=(e==null?void 0:e.attention_processes)||[],k=(e==null?void 0:e.attention_orders)||[],y=(e==null?void 0:e.untriaged_incidents)||[],m=(e==null?void 0:e.overdue_triage)||[],o=f.length>0||g.length>0,u=S.length>0||k.length>0,h=[["Total",n.length,""],...a.map(x=>[x.name1||x.name,n.filter(I=>I.status===x.name).length,x.name])],z=[["Total",s.length,""],...i.map(x=>[x.name1||x.name,s.filter(I=>I.status===x.name).length,x.name])],j=[["Total",l.length,""],...d.map(x=>[x.name1||x.name,l.filter(I=>I.status===x.name).length,x.name])],b=[["Total",r.length,""],...c.map(x=>[x.name1||x.name,r.filter(I=>I.status===x.name).length,x.name])];return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",marginBottom:4},children:[t.jsx(Jt,{label:"Incidents",icon:"⚠️",onClick:()=>p("incidents")}),t.jsx(Jt,{label:"Ideas",icon:"💡",onClick:()=>p("ideas")}),t.jsx(Jt,{label:"Orders",icon:"📦",onClick:()=>p("orders")}),t.jsx(Jt,{label:"Processes",icon:"⚙️",onClick:()=>p("processes")}),t.jsx(Jt,{label:"Inbox",icon:"📥",onClick:()=>p("inbox")}),t.jsx(Jt,{label:"Reports",icon:"📊",onClick:()=>p("reports")})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:12},children:[t.jsx("div",{onClick:()=>p("incidents"),style:{cursor:"pointer"},children:t.jsx(ta,{title:v.dash.incidents,color:G.orange,data:h,onSelect:x=>w("incidents",x)})}),t.jsx("div",{onClick:()=>p("ideas"),style:{cursor:"pointer"},children:t.jsx(ta,{title:v.dash.ideas,color:G.blue,data:z,onSelect:x=>w("ideas",x)})}),t.jsx("div",{onClick:()=>p("orders"),style:{cursor:"pointer"},children:t.jsx(ta,{title:v.dash.orders,color:G.purple,data:j,onSelect:x=>w("orders",x)})}),t.jsx("div",{onClick:()=>p("processes"),style:{cursor:"pointer"},children:t.jsx(ta,{title:v.dash.processes,color:G.red,data:b,onSelect:x=>w("processes",x)})})]}),o&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:10},children:v.dash.level2}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[t.jsx(Gn,{items:f,type:"process",onNavigate:p}),t.jsx(Gn,{items:g,type:"order",onNavigate:p})]})]}),u&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#b45309",marginBottom:10},children:v.dash.level1}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[t.jsx(Gn,{items:S,type:"process",onNavigate:p}),t.jsx(Gn,{items:k,type:"order",onNavigate:p})]})]}),m.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:8},children:[v.dash.overduePrefix,m.length,v.dash.overdueSuffix]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:m.map(x=>t.jsxs("div",{onClick:()=>p("incidents-form",x.name),style:{padding:"8px 12px",background:"#fef2f2",borderRadius:8,border:"1px solid #fca5a5",cursor:"pointer",display:"flex",justifyContent:"space-between"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:13},children:x.number||x.name}),t.jsx("span",{style:{fontSize:12,color:"#666"},children:x.title}),t.jsx("span",{style:{fontSize:11,color:"#888"},children:x.date})]},x.name))})]}),y.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:G.orange,marginBottom:8},children:[v.dash.untriaged," (",y.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:y.map(x=>t.jsxs("div",{onClick:()=>p("incidents-form",x.name),style:{padding:"8px 12px",background:"#fffbeb",borderRadius:8,border:"1px solid #fed7aa",cursor:"pointer",display:"flex",justifyContent:"space-between"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:13},children:x.number||x.name}),t.jsx("span",{style:{fontSize:12,color:"#666"},children:x.title}),t.jsx("span",{style:{fontSize:11,color:"#888"},children:x.date})]},x.name))})]})]})}function f0({dashData:e,selectedOrg:n,onNavigate:s}){const l=ne(),[r,a]=C.useState([]),[i,d]=C.useState([]),[c,p]=C.useState(!1),w=(e==null?void 0:e.escalated_processes)||[],v=(e==null?void 0:e.escalated_orders)||[],f=(e==null?void 0:e.attention_processes)||[],g=(e==null?void 0:e.attention_orders)||[],S=(e==null?void 0:e.kpi_inputs)||[];C.useEffect(()=>{p(!0);const m=new URLSearchParams({months:"6"});n&&m.append("organization",n),fetch(`/api/method/sidrah_business.api.get_process_trend?${m}`,{credentials:"include",headers:{Accept:"application/json"}}).then(o=>o.json()).then(o=>{const u=o.message||[],h={};for(const z of u)h[z.month]||(h[z.month]={pass:0,fail:0,unknown:0}),z.status==="Pass"?h[z.month].pass=z.count:z.status==="Fail"?h[z.month].fail=z.count:z.status==="Unknown"&&(h[z.month].unknown=z.count);a(Object.entries(h).map(([z,j])=>({month:z,...j})))}).catch(()=>{}).finally(()=>p(!1))},[n]),C.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(m=>m.json()).then(m=>{var o;d((((o=m.message)==null?void 0:o.rows)||[]).slice(0,50))}).catch(()=>{})},[n]);const k=w.length>0||v.length>0,y=f.length>0||g.length>0;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:[t.jsx(Jt,{label:"Manage Users & Roles",icon:"👥",onClick:()=>s("users")}),t.jsx(Jt,{label:"Change Active Cycle",icon:"🔄",onClick:()=>s("cycles")}),t.jsx(Jt,{label:"KPI Inputs",icon:"📈",onClick:()=>s("kpi-input")}),t.jsx(Jt,{label:"Reports",icon:"📊",onClick:()=>s("reports")}),t.jsx(Jt,{label:"Organizations",icon:"🏢",onClick:()=>s("organizations")})]}),S.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:10},children:l.dash.recentKpi}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12},children:S.map(m=>t.jsx(c0,{kpi:m},m.name))}),t.jsx("button",{onClick:()=>s("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:l.dash.manageKpi})]}),k&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:10},children:["Critical Escalations — Level 2 (",w.length+v.length,")"]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[t.jsx(Gn,{items:w,type:"process",onNavigate:s}),t.jsx(Gn,{items:v,type:"order",onNavigate:s})]})]}),y&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#b45309",marginBottom:10},children:["Needs Attention — Level 1 (",f.length+g.length,")"]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[t.jsx(Gn,{items:f,type:"process",onNavigate:s}),t.jsx(Gn,{items:g,type:"order",onNavigate:s})]})]}),t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:4},children:"Process Trend — Last 6 Months"}),t.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."}),c?t.jsx("p",{style:{color:"#aaa",fontSize:13},children:"Loading trend data…"}):t.jsx(u0,{data:r})]}),i.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:10},children:"Log Book — Recent Activity"}),t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8f9fa"},children:["Timestamp","User","Entity Type","Entity","Fields Changed"].map(m=>t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#999",fontWeight:700,fontSize:11,whiteSpace:"nowrap"},children:m},m))})}),t.jsx("tbody",{children:i.map((m,o)=>t.jsxs("tr",{style:{borderTop:"1px solid #f0f0f0",background:o%2===0?"white":"#fafafa"},children:[t.jsx("td",{style:{padding:"8px 12px",color:"#555",whiteSpace:"nowrap"},children:m.timestamp?String(m.timestamp).slice(0,16):"—"}),t.jsx("td",{style:{padding:"8px 12px",color:"#333"},children:m.user||"—"}),t.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:m.entity_type||"—"}),t.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:m.entity_name||"—"}),t.jsx("td",{style:{padding:"8px 12px",color:"#888",maxWidth:240,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.changes||"—"})]},o))})]})}),t.jsx("button",{onClick:()=>s("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 h0({incidents:e,ideas:n,orders:s,processes:l,organizations:r,incidentStatuses:a,ideaStatuses:i,orderStatuses:d,processStatuses:c,selectedOrg:p,onOrgChange:w,onNavigate:v,onNavigateStatus:f,userRole:g}){const[S,k]=C.useState(null);C.useEffect(()=>{Gy(p).then(k)},[p]);const y=p?e.filter(I=>I.organization===p):e,m=p?n.filter(I=>I.organization===p):n,o=p?s.filter(I=>I.organization===p):s,u=p?l.filter(I=>I.organization===p):l,h=g==="Admin",z=g==="Owner",[j,b]=C.useState("level1"),x=z||h&&j==="level2";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[t.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:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#4f46e5",strokeWidth:"2.5",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#1e1b4b",whiteSpace:"nowrap"},children:"Filter"})]}),t.jsx("div",{style:{flex:1,minWidth:160,maxWidth:260},children:t.jsx(Gt,{value:p,onChange:w,organizations:r,placeholder:"All Organizations",small:!0})}),h&&t.jsx("div",{style:{display:"flex",background:"#f1f0fe",borderRadius:7,padding:2,gap:2,flexShrink:0},children:["level1","level2"].map(I=>t.jsx("button",{onClick:()=>b(I),style:{padding:"4px 10px",borderRadius:5,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:j===I?I==="level2"?G.purple:G.blue:"transparent",color:j===I?"white":"#6b7280",transition:"all 0.15s"},children:I==="level1"?"Level 1":"Level 2"},I))}),!h&&t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"white",background:x?G.purple:G.blue,padding:"3px 10px",borderRadius:20,flexShrink:0},children:x?"Level 2 — Owner":"Level 1 — Operational"})]}),x?t.jsx(f0,{dashData:S,selectedOrg:p,onNavigate:v}):t.jsx(p0,{dashData:S,fi:y,fid:m,fo:o,fp:u,incidentStatuses:a,ideaStatuses:i,orderStatuses:d,processStatuses:c,onNavigate:v,onNavigateStatus:f})]})}const tt={fontSize:11,color:"#475569",fontWeight:600,marginBottom:4,display:"block",textTransform:"uppercase",letterSpacing:.4},nt={width:"100%",padding:"6px 10px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:12,background:"white",color:"#1e293b",boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif",height:32,outline:"none"};function oi({children:e}){const[n,s]=C.useState(!1);return t.jsxs("div",{style:{borderRadius:10,overflow:"hidden",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",flexShrink:0,border:"1px solid #e2e8f0",marginBottom:14},children:[t.jsxs("div",{onClick:()=>s(l=>!l),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",color:"white",padding:"10px 18px",cursor:"pointer",display:"flex",alignItems:"center",gap:10,userSelect:"none",fontWeight:600,fontSize:13},children:[t.jsx("span",{style:{fontSize:12,opacity:.9},children:n?"▲":"▼"}),t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{children:"Filters"})]}),n&&t.jsx("div",{style:{background:"#f8fafc",padding:"14px 18px",borderTop:"1px solid #e2e8f0"},children:e})]})}const ae=20,Eu=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 qe({page:e,pageSize:n=ae,total:s,onPageChange:l}){if(s===0)return null;const r=Math.max(1,Math.ceil(s/n)),a=(e-1)*n+1,i=Math.min(e*n,s);return t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 4px",fontSize:12,color:"#6b7280",flexShrink:0},children:[t.jsxs("span",{children:["Showing ",a," to ",i," of ",s," results"]}),t.jsxs("div",{style:{display:"flex",gap:8},children:[t.jsx("button",{disabled:e<=1,onClick:()=>l(e-1),style:Eu(e<=1),children:"Previous"}),t.jsx("button",{disabled:e>=r,onClick:()=>l(e+1),style:Eu(e>=r),children:"Next"})]})]})}function Je({count:e,onClear:n,onExport:s}){return e===0?null:t.jsxs("div",{style:{position:"sticky",bottom:20,zIndex:50,margin:"0 auto",width:"fit-content",maxWidth:"92%",background:"#0f172a",color:"#f8fafc",padding:"8px 18px",borderRadius:9999,boxShadow:"0 12px 32px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",gap:14,fontSize:13,animation:"fadeIn 0.2s ease",border:"1px solid #334155"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontWeight:700,color:"#38bdf8"},children:[t.jsx("span",{style:{fontSize:14},children:"✓"}),t.jsxs("span",{children:[e," selected"]})]}),s&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsxs("button",{type:"button",onClick:()=>s("csv"),style:{background:"#16a34a",color:"white",border:"none",borderRadius:20,padding:"5px 12px",fontSize:12,fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",gap:5,transition:"background 0.15s ease"},onMouseEnter:l=>{l.currentTarget.style.background="#15803d"},onMouseLeave:l=>{l.currentTarget.style.background="#16a34a"},children:[t.jsx("span",{children:"📤"})," Export CSV"]}),t.jsxs("button",{type:"button",onClick:()=>s("xlsx"),style:{background:"#0284c7",color:"white",border:"none",borderRadius:20,padding:"5px 12px",fontSize:12,fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",gap:5,transition:"background 0.15s ease"},onMouseEnter:l=>{l.currentTarget.style.background="#0369a1"},onMouseLeave:l=>{l.currentTarget.style.background="#0284c7"},children:[t.jsx("span",{children:"📊"})," Export Excel"]})]}),t.jsx("button",{type:"button",onClick:n,style:{background:"transparent",color:"#94a3b8",border:"none",fontSize:12,fontWeight:600,cursor:"pointer",padding:"4px 6px",transition:"color 0.15s ease"},onMouseEnter:l=>{l.currentTarget.style.color="#f1f5f9"},onMouseLeave:l=>{l.currentTarget.style.color="#94a3b8"},children:"Clear"})]})}function g0({incidents:e,organizations:n,departments:s,branches:l,incidentStatuses:r,initialOrg:a,initialStatus:i,canModify:d,userRole:c,onView:p,onEdit:w,onDelete:v,onSelectionChange:f}){const g=ne(),[S,k]=C.useState(new Set),[y,m]=C.useState({search:"",organization:a||"",department:"",branch:"",status:i||""}),o=(x,I)=>m(E=>({...E,[x]:I})),[u,h]=C.useState(1),z=e.filter(x=>!(y.search&&!`${x.number} ${x.title}`.toLowerCase().includes(y.search.toLowerCase())||y.organization&&x.organization!==y.organization||y.department&&x.department!==y.department||y.branch&&x.branch!==y.branch||y.status&&x.status!==y.status));C.useEffect(()=>{h(1)},[y]);const j=z.slice((u-1)*ae,u*ae);C.useEffect(()=>{if(f){const x=e.filter(I=>S.has(I.name));f(x,j)}},[S]);const b=x=>{const I=e.filter(U=>S.has(U.name)),E=Me.incidents,F=E.columns.filter(U=>E.defaultColumns.includes(U.key));x==="csv"?He(F,I,"incidents_selected"):Ge(F,I,"incidents_selected")};return t.jsxs(t.Fragment,{children:[t.jsx(oi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.numberTitle}),t.jsx("input",{style:nt,value:y.search,onChange:x=>o("search",x.target.value),placeholder:g.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.organization}),t.jsxs("select",{style:nt,value:y.organization,onChange:x=>o("organization",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allOrgs}),n.map(x=>t.jsx("option",{value:x.name,children:x.organization_name||x.name},x.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.department}),t.jsxs("select",{style:nt,value:y.department,onChange:x=>o("department",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allDepts}),s.map(x=>t.jsx("option",{value:x.name,children:x.department_name||x.name},x.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.branch}),t.jsxs("select",{style:nt,value:y.branch,onChange:x=>o("branch",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allBranches}),l.map(x=>t.jsx("option",{value:x.name,children:x.branch||x.name},x.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.status}),t.jsxs("select",{style:nt,value:y.status,onChange:x=>o("status",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allStatuses}),r.map(x=>t.jsx("option",{value:x.name,children:x.name1||x.name},x.name))]})]}),t.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:t.jsx("button",{onClick:()=>m({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"7px 14px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#475569",fontWeight:500},children:g.clear})})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:j.length>0&&j.every(x=>S.has(x.name)),onChange:x=>{if(x.target.checked)k(new Set([...S,...j.map(I=>I.name)]));else{const I=new Set(S);j.forEach(E=>I.delete(E.name)),k(I)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.type}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.actions})]})}),t.jsx("tbody",{children:z.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:g.noIncidents})}):j.map((x,I)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(x),style:{borderTop:"1px solid #f1f5f9",background:S.has(x.name)?"#eff6ff":x.custom_is_deleted?"#fff1f2":I%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:E=>E.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:S.has(x.name),onChange:()=>{const E=new Set(S);E.has(x.name)?E.delete(x.name):E.add(x.name),k(E)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:x.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:x.title||"—"}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:x.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:x.type?$d(x.type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:x.custom_is_deleted?ns(g.deletedBadge):x.status?ns(x.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:E=>E.stopPropagation(),children:t.jsx(at,{onView:()=>p==null?void 0:p(x),onEdit:d&&w&&!x.custom_is_deleted&&!Hn("incident",x.workflow_state)&&!(c==="Employee"&&x.workflow_state&&x.workflow_state!=="New")?()=>w(x):void 0,onDelete:d&&v&&!x.custom_is_deleted?()=>v(x.name):void 0})})]},x.name))})]})}),t.jsx(Je,{count:S.size,onClear:()=>k(new Set),onExport:b}),t.jsx(qe,{page:u,total:z.length,onPageChange:h})]})}function x0(e){if(!e)return"";const[n,s,l]=e.split("-");return!n||!s||!l?"":`${l}/${s}/${n}`}function xe({value:e,onChange:n,disabled:s,style:l,min:r,max:a}){return t.jsxs("div",{style:{position:"relative",width:"100%"},children:[t.jsx("input",{type:"text",readOnly:!0,tabIndex:-1,value:x0(e),placeholder:"DD/MM/YYYY",style:{...l,pointerEvents:"none",paddingRight:30}}),t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:s?"#bbb":"#666",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",pointerEvents:"none"},children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),t.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),t.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),t.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),t.jsx("input",{type:"date",value:e||"",disabled:s,min:r,max:a,onChange:i=>n(i.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0,cursor:s?"default":"pointer",border:"none",padding:0,margin:0}})]})}const Tu={"SB Process":"processes-form","SB Order":"orders-form","SB Incident":"incidents-form","SB Idea":"ideas-form","SB Delegation":"delegations"};function m0(e){const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}function uh({notifCount:e,darkMode:n,onCountChange:s,onToggleDark:l,onViewProfile:r,onLogout:a,onNavigate:i,userName:d,userRole:c}){const[p,w]=C.useState(!1),[v,f]=C.useState([]),[g,S]=C.useState(!1),k=C.useRef(null);C.useEffect(()=>{const E=F=>{k.current&&!k.current.contains(F.target)&&w(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[]);const y=async()=>{S(!0);const E=await Dy(30);f(E),S(!1)},m=()=>{const E=!p;w(E),E&&y()},o=async()=>{await Ly(),f(E=>E.map(F=>({...F,read:1}))),s(0)},u=E=>{E.read||(Oy(E.name),f(U=>U.map(N=>N.name===E.name?{...N,read:1}:N)),s(Math.max(0,e-1)));const F=E.document_type?Tu[E.document_type]:void 0;F&&i&&(i(F,E.document_type==="SB Delegation"?void 0:E.document_name),w(!1))},h=v.filter(E=>!E.read).length,z=E=>({position:"relative",width:34,height:34,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:n?"#2d3748":"#f3f4f6",color:n?"#e2e8f0":"#6b7280",fontSize:14,transition:"background 0.15s",flexShrink:0,...E}),j=n,b=j?"#1a202c":"white",x=j?"#2d3748":"#e5e7eb",I=j?"#e2e8f0":"#1a2332";return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[d&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",marginRight:4,lineHeight:1.25},children:[t.jsx("span",{style:{fontSize:13,fontWeight:600,color:j?"#e2e8f0":"#1e293b",whiteSpace:"nowrap"},children:d}),c&&t.jsx("span",{style:{fontSize:11,color:j?"#94a3b8":"#6b7280",whiteSpace:"nowrap"},children:c})]}),t.jsx("button",{style:z({background:"#4f46e5",color:"white"}),onClick:r,title:"My Profile",children:t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7",fill:"currentColor"})]})}),t.jsxs("div",{ref:k,style:{position:"relative"},children:[t.jsxs("button",{style:z(),onClick:m,title:"Notifications",children:[t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),t.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),e>0&&t.jsx("span",{style:{position:"absolute",top:2,right:2,background:"#ef4444",color:"white",fontSize:9,fontWeight:700,borderRadius:999,minWidth:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 3px",lineHeight:1},children:e>9?"9+":e})]}),p&&t.jsxs("div",{style:{position:"absolute",right:0,top:"calc(100% + 8px)",width:340,background:b,borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.2)",zIndex:1e4,border:`1px solid ${x}`,overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${x}`,display:"flex",alignItems:"center",justifyContent:"space-between",background:b},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:I},children:["Notifications",h>0&&t.jsxs("span",{style:{background:"#ef4444",color:"white",fontSize:10,fontWeight:700,borderRadius:999,padding:"2px 7px"},children:[h," new"]})]}),h>0&&t.jsx("button",{onClick:o,style:{fontSize:12,color:"#3498db",background:"none",border:"none",cursor:"pointer",fontFamily:"inherit"},children:"Mark all read"})]}),t.jsxs("div",{style:{maxHeight:380,overflowY:"auto"},children:[g&&t.jsx("div",{style:{padding:20,textAlign:"center",color:"#aaa",fontSize:13},children:"Loading…"}),!g&&v.length===0&&t.jsxs("div",{style:{padding:"36px 20px",textAlign:"center",color:"#aaa"},children:[t.jsx("div",{style:{fontSize:28,marginBottom:8},children:"🔔"}),t.jsx("div",{style:{fontSize:13},children:"No notifications"})]}),!g&&v.map(E=>{const F=!!(E.document_type&&Tu[E.document_type]&&i);return t.jsxs("div",{onClick:()=>u(E),style:{padding:"11px 16px",borderBottom:`1px solid ${j?"#2d3748":"#f5f5f5"}`,display:"flex",gap:10,background:E.read?b:j?"#1e3a5f":"#eff6ff",cursor:F?"pointer":"default",transition:"background 0.12s"},onMouseEnter:U=>{F&&(U.currentTarget.style.background=j?"#243244":"#e0ecfd")},onMouseLeave:U=>{U.currentTarget.style.background=E.read?b:j?"#1e3a5f":"#eff6ff"},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13,fontWeight:E.read?400:600,color:I,marginBottom:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:E.subject||`${E.document_type}: ${E.document_name}`}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:E.document_type&&t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#3b82f6",background:j?"rgba(59,130,246,0.15)":"#eff6ff",padding:"1px 7px",borderRadius:8},children:[E.document_type.replace("SB ",""),E.document_name?` · ${E.document_name}`:""]})}),t.jsx("div",{style:{fontSize:11,color:"#aaa",marginTop:3},children:m0(E.creation)})]}),!E.read&&t.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:"#3498db",flexShrink:0,marginTop:5}})]},E.name)})]})]})]}),t.jsx("button",{style:z(),onClick:rh,title:pl()?"Switch to English":"Switch to Arabic",children:t.jsx("span",{style:{fontSize:13,fontWeight:700,fontFamily:"serif"},children:"عA"})}),t.jsx("button",{style:z(),onClick:l,title:n?"Light mode":"Dark mode",children:n?t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"5"}),t.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),t.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),t.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),t.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),t.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),t.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),t.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),t.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),t.jsx("button",{style:z({background:j?"#3d1515":"#fee2e2",color:"#ef4444"}),onClick:a,title:"Logout",children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),t.jsx("polyline",{points:"16,17 21,12 16,7"}),t.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})}function Ze({title:e,activePage:n,user:s,formStatus:l,buttonText:r,viewMode:a,statusBadge:i,onEdit:d,onCancel:c,hideSettings:p,rightPanel:w,darkMode:v,notifCount:f,onToggleDark:g,onCountChange:S,onViewProfile:k,onSubmit:y,onBack:m,onNavigate:o,onLogout:u,children:h}){const z=ne(),j=s.role,b=j==="Admin"||j==="Owner"||j==="Auditor"||j==="Manager",x=j==="Admin"||j==="Owner"||j==="Auditor"||j==="Manager",I=j==="Admin"||j==="Auditor"||j==="Manager",[E,F]=C.useState(()=>localStorage.getItem("sb_sidebar")==="1"),[U,N]=C.useState(!a);C.useEffect(()=>{if(a)N(!1);else{N(!0);const D=setTimeout(()=>{N(!1)},5e3);return()=>clearTimeout(D)}},[a]);const $=()=>F(D=>{const Y=!D;return localStorage.setItem("sb_sidebar",Y?"1":"0"),Y}),P=c||m;return t.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:v?"#0f172a":"#f8fafc"},children:[t.jsx(ih,{collapsed:E,onToggleCollapsed:$,activePage:n,onNavigate:o,hasDashboard:b,hasReports:x,hasDelegations:I,role:j,hideSettings:p,rtl:z.rtl,navLabels:z.nav,settingsLabel:z.nav.settings}),t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[t.jsx("div",{style:{background:v?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${v?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:v?"none":"0 1px 4px rgba(0,0,0,0.03)"},children:t.jsx(uh,{notifCount:f,darkMode:v,onCountChange:S,onToggleDark:g,onNavigate:o,onViewProfile:k,onLogout:u,userName:s.full_name||s.name,userRole:s.role})}),t.jsxs("div",{style:{background:v?"#1e293b":"#ffffff",padding:"12px 24px",borderBottom:`1px solid ${v?"#2d3748":"#e2e8f0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,position:"relative"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[t.jsx("button",{onClick:m,title:z.back,style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:`1px solid ${v?"#475569":"#e2e8f0"}`,background:v?"#334155":"#ffffff",cursor:"pointer",color:"#2563eb",flexShrink:0,transition:"all 0.15s ease"},onMouseEnter:D=>{D.currentTarget.style.background=v?"#475569":"#eff6ff",D.currentTarget.style.borderColor="#93c5fd"},onMouseLeave:D=>{D.currentTarget.style.background=v?"#334155":"#ffffff",D.currentTarget.style.borderColor=v?"#475569":"#e2e8f0"},children:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("div",{style:{fontSize:17,fontWeight:700,color:v?"#f8fafc":"#0f172a"},children:e}),i&&(typeof i=="string"?t.jsx("span",{style:{padding:"3px 10px",borderRadius:16,fontSize:12,fontWeight:600,background:"#fef3c7",color:"#92400e",border:"1px solid #fde68a"},children:i}):i)]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&d&&t.jsxs("button",{type:"button",onClick:d,style:{display:"flex",alignItems:"center",gap:6,padding:"7px 16px",borderRadius:6,border:"none",background:"#2563eb",color:"#ffffff",cursor:"pointer",fontSize:13,fontWeight:600,boxShadow:"0 1px 3px rgba(37,99,235,0.25)",transition:"all 0.15s ease"},onMouseEnter:D=>D.currentTarget.style.background="#1d4ed8",onMouseLeave:D=>D.currentTarget.style.background="#2563eb",children:[t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),z.edit]}),!a&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("button",{type:"button",onClick:P,style:{padding:"7px 16px",borderRadius:6,border:`1px solid ${v?"#475569":"#cbd5e1"}`,background:v?"#334155":"#ffffff",color:v?"#e2e8f0":"#475569",fontSize:13,fontWeight:600,cursor:"pointer",transition:"all 0.15s ease"},onMouseEnter:D=>{D.currentTarget.style.background=v?"#475569":"#f1f5f9"},onMouseLeave:D=>{D.currentTarget.style.background=v?"#334155":"#ffffff"},children:z.cancel}),t.jsxs("button",{type:"button",onClick:y,disabled:l==="loading",style:{display:"flex",alignItems:"center",gap:6,padding:"7px 18px",borderRadius:6,border:"none",background:"#16a34a",color:"#ffffff",fontSize:13,fontWeight:600,cursor:l==="loading"?"not-allowed":"pointer",boxShadow:"0 1px 3px rgba(22, 163, 74, 0.3)",opacity:l==="loading"?.7:1,transition:"all 0.15s ease"},onMouseEnter:D=>{l!=="loading"&&(D.currentTarget.style.background="#15803d")},onMouseLeave:D=>{l!=="loading"&&(D.currentTarget.style.background="#16a34a")},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),t.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),t.jsx("polyline",{points:"7 3 7 8 15 8"})]}),t.jsx("span",{children:l==="loading"?z.saving:r||"Save Changes"})]})]})]}),!a&&U&&t.jsxs("div",{style:{position:"absolute",top:-34,right:24,background:"#0284c7",color:"#ffffff",padding:"4px 12px",borderRadius:6,fontSize:12,fontWeight:600,display:"flex",alignItems:"center",gap:8,boxShadow:"0 2px 8px rgba(2, 132, 199, 0.3)",zIndex:10},children:[t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5},children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),"Edit mode enabled"]}),t.jsx("button",{type:"button",onClick:()=>N(!1),title:"Dismiss",style:{background:"transparent",border:"none",color:"white",cursor:"pointer",fontSize:14,padding:0,lineHeight:1,opacity:.85},children:"✕"})]})]}),t.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px",display:"grid",gridTemplateColumns:w?"1fr 240px":"1fr",gap:16,alignItems:"start"},children:[t.jsxs("div",{style:{minWidth:0},children:[h,l==="success"&&t.jsx("div",{style:{padding:"10px 14px",borderRadius:8,background:"#f0fdf4",border:"1px solid #86efac",color:"#166534",fontSize:13,marginTop:14},children:z.savedOk}),l!=="idle"&&l!=="loading"&&l!=="success"&&t.jsx("div",{style:{padding:"10px 14px",borderRadius:8,background:"#fef2f2",border:"1px solid #fca5a5",color:"#991b1b",fontSize:13,marginTop:14},children:l})]}),w&&t.jsx("div",{style:{position:"sticky",top:0,alignSelf:"start",width:240},children:w})]})]})]})}function pe({value:e,onChange:n,items:s,placeholder:l="-- Select --",disabled:r=!1}){var v;const[a,i]=C.useState(!1),[d,c]=C.useState(""),p=C.useRef(null);C.useEffect(()=>{const f=g=>{p.current&&!p.current.contains(g.target)&&i(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[]);const w=e?((v=s.find(f=>f.name===e))==null?void 0:v.label)??e:l;return t.jsxs("div",{ref:p,style:{position:"relative",width:"100%"},children:[t.jsxs("div",{onClick:()=>!r&&i(f=>!f),style:{width:"100%",height:34,padding:"7px 10px",border:"1px solid",borderColor:a?"#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:[t.jsx("span",{children:w}),t.jsx("span",{style:{fontSize:9,color:"#999",transform:a?"rotate(180deg)":"none",transition:"transform 0.2s"},children:"▼"})]}),a&&t.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:t.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[t.jsx("div",{onClick:()=>{n(""),i(!1)},onMouseEnter:()=>c("__placeholder"),onMouseLeave:()=>c(""),style:{padding:"8px 14px",cursor:"pointer",fontSize:12,color:"#aaa",background:d==="__placeholder"?"#f5f5f5":"transparent"},children:l}),s.length===0&&t.jsx("div",{style:{padding:"10px 14px",color:"#aaa",fontSize:12},children:"No records found"}),s.map(f=>t.jsx("div",{onClick:()=>{n(f.name),i(!1)},onMouseEnter:()=>c(f.name),onMouseLeave:()=>c(""),style:{padding:"8px 14px",cursor:"pointer",fontSize:12,background:e===f.name?"#2563eb":d===f.name?"#f0f4ff":"transparent",color:e===f.name?"white":"#1a2332",transition:"background 0.1s"},children:f.label},f.name))]})})]})}function y0(e){const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<86400*7?`${Math.floor(n/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function v0(e){return e.replace(/@.*/,"").replace(/[._-]/g," ").split(" ").filter(Boolean).slice(0,2).map(s=>s[0].toUpperCase()).join("")}function di({doctype:e,docname:n,currentUserName:s}){const l=ne(),[r,a]=C.useState([]),[i,d]=C.useState(!1),[c,p]=C.useState(""),[w,v]=C.useState(!1),[f,g]=C.useState(!1),[S,k]=C.useState(!1),[y,m]=C.useState(""),o=5,u=C.useCallback(async()=>{d(!0);const x=await Wy(e,n);a(x),d(!1)},[e,n]);C.useEffect(()=>{u()},[u]);const h=async()=>{const x=c.trim();if(!(!x||w)){v(!0),m("");try{await By(e,n,x),p(""),await u()}catch{m("Failed to post comment. Please try again.")}v(!1)}},z=async x=>{if(window.confirm("Delete this comment?"))try{await Ho("Comment",x),a(I=>I.filter(E=>E.name!==x))}catch{alert("Failed to delete comment.")}},j=S?r:r.slice(-o),b=Math.max(0,r.length-o);return t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>g(x=>!x),style:{padding:"12px 20px",borderBottom:f?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none",background:"white"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["💬 ",l.comments.title,r.length>0&&t.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:r.length})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("button",{onClick:x=>{x.stopPropagation(),u()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),t.jsx("span",{style:{color:"#ccc",fontSize:11},children:f?"▼":"▲"})]})]}),!f&&t.jsxs("div",{style:{padding:"16px 20px"},children:[!S&&b>0&&t.jsxs("button",{onClick:()=>k(!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 ",b," older comment",b!==1?"s":""]}),i&&t.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:l.loading}),!i&&r.length===0&&t.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:l.comments.noComments}),!i&&j.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:16},children:j.map(x=>{const I=x.comment_by||x.comment_email||x.owner||"Unknown",E=x.owner===s||x.comment_by===s;return t.jsxs("div",{style:{display:"flex",gap:10,padding:"12px 14px",background:"#f9fafb",borderRadius:8,border:"1px solid #e8e8e8"},children:[t.jsx("div",{style:{width:34,height:34,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:700,flexShrink:0},children:v0(I)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:I}),t.jsx("span",{style:{fontSize:11,color:"#aaa"},children:y0(x.creation)})]}),E&&t.jsx("button",{onClick:()=>z(x.name),style:{background:"none",border:"none",cursor:"pointer",color:"#e74c3c",fontSize:16,padding:"0 2px",lineHeight:1},title:"Delete comment",children:"×"})]}),t.jsx("div",{style:{fontSize:13,color:"#374151",lineHeight:1.55,wordBreak:"break-word",whiteSpace:"pre-wrap"},dangerouslySetInnerHTML:{__html:x.content||""}})]})]},x.name)})}),t.jsxs("div",{style:{borderTop:r.length>0?"1px solid #f0f0f0":"none",paddingTop:r.length>0?14:0},children:[t.jsx("textarea",{value:c,onChange:x=>p(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&h()},placeholder:l.comments.placeholder,rows:3,style:{width:"100%",padding:"10px 12px",border:"1px solid #ddd",borderRadius:8,fontSize:13,fontFamily:"Segoe UI",resize:"vertical",boxSizing:"border-box",outline:"none",color:"#1a2332"}}),y&&t.jsx("div",{style:{fontSize:12,color:"#e74c3c",marginTop:4},children:y}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:8},children:t.jsx("button",{onClick:h,disabled:!c.trim()||w,style:{padding:"8px 20px",background:"#3498db",color:"white",border:"none",borderRadius:6,cursor:!c.trim()||w?"not-allowed":"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI",opacity:!c.trim()||w?.6:1},children:w?l.saving:l.comments.post})})]})]})]})}function Pu(e){if(!e)return"";const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<86400*7?`${Math.floor(n/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function j0(e){return(e||"").replace(/^custom_/,"").replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Au(e){return e==null||e===""?"(empty)":typeof e=="object"?JSON.stringify(e):String(e)}function Go(e){return(e||"Unknown").replace(/@.*/,"").replace(/[._]/g," ")}function Ru(e){return Go(e).split(" ").filter(Boolean).slice(0,2).map(n=>n[0].toUpperCase()).join("")}function b0(e){let n={};try{n=JSON.parse(e.data||"{}")}catch{}const s=(n.changed||[]).map(l=>({field:l[0]||"",oldVal:Au(l[1]),newVal:Au(l[2])}));return{name:e.name,owner:e.owner,creation:e.creation,changes:s,added:(n.added||[]).length,removed:(n.removed||[]).length,rowChanged:(n.row_changed||[]).length}}function ci({doctype:e,docname:n,docCreation:s,docOwner:l}){const r=ne(),[a,i]=C.useState([]),[d,c]=C.useState(!1),[p,w]=C.useState(!0),[v,f]=C.useState(!1),g=5,S=C.useCallback(async()=>{c(!0);const o=await $y(e,n);i(o.map(b0)),c(!1)},[e,n]);C.useEffect(()=>{p||S()},[p,S]);const k=v?a:a.slice(0,g),y=a.length-g,m=(o,u=!1)=>({position:"absolute",left:-14,top:14,width:10,height:10,borderRadius:"50%",background:o,border:"2px solid white",boxShadow:u?`0 0 0 2px ${o}44`:"none"});return t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>w(o=>!o),style:{padding:"12px 20px",borderBottom:p?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["📋 ",r.activity.title,!p&&a.length>0&&t.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:a.length})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[!p&&t.jsx("button",{onClick:o=>{o.stopPropagation(),S()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),t.jsx("span",{style:{color:"#ccc",fontSize:11},children:p?"▼":"▲"})]})]}),!p&&t.jsxs("div",{style:{padding:"16px 20px"},children:[d&&t.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:r.loading}),!d&&t.jsxs("div",{style:{position:"relative",paddingLeft:20},children:[t.jsx("div",{style:{position:"absolute",left:8,top:0,bottom:0,width:2,background:"#e5e7eb"}}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[k.map((o,u)=>t.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[t.jsx("div",{style:m(u===0?"#3498db":"#d1d5db",u===0)}),t.jsxs("div",{style:{background:u===0?"#eff6ff":"#f9fafb",border:`1px solid ${u===0?"#bfdbfe":"#e5e7eb"}`,borderRadius:8,padding:"10px 14px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[t.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:Ru(o.owner)}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:Go(o.owner)}),t.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Pu(o.creation)})]}),o.changes.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:o.changes.map((h,z)=>t.jsxs("div",{style:{fontSize:12,lineHeight:1.5},children:[t.jsx("span",{style:{fontWeight:600,color:"#6d28d9"},children:j0(h.field)}),t.jsx("span",{style:{color:"#6b7280"},children:" changed from "}),t.jsx("span",{style:{padding:"1px 5px",background:"#fee2e2",color:"#dc2626",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:h.oldVal}),t.jsx("span",{style:{color:"#6b7280"},children:" → "}),t.jsx("span",{style:{padding:"1px 5px",background:"#dcfce7",color:"#16a34a",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:h.newVal})]},z))}):t.jsxs("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic"},children:["Document updated",o.added>0&&t.jsxs("span",{children:[" · +",o.added," row(s)"]}),o.removed>0&&t.jsxs("span",{children:[" · -",o.removed," row(s)"]}),o.rowChanged>0&&t.jsxs("span",{children:[" · ~",o.rowChanged," row(s) modified"]})]})]})]},o.name)),s&&l&&t.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[t.jsx("div",{style:m("#22c55e")}),t.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"10px 14px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[t.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#22c55e",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:Ru(l)}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:Go(l)}),t.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Pu(s)})]}),t.jsxs("div",{style:{fontSize:12,color:"#15803d",fontWeight:600},children:["✓ ",r.activity.created]})]})]}),a.length===0&&!s&&t.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:"No activity recorded"})]})]}),!d&&y>0&&t.jsx("div",{style:{textAlign:"center",marginTop:12},children:t.jsx("button",{onClick:()=>f(o=>!o),style:{background:"none",border:"none",cursor:"pointer",color:"#3498db",fontSize:12,fontFamily:"Segoe UI",padding:"4px 8px"},children:v?"▲ Show less":`▼ Show all (${a.length})`})})]})]})}const S0={New:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Initial Evaluation":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},"Accept & Under Progress":{background:"#fefce8",color:"#92400e",border:"1px solid #fde68a"},"working on resolution":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Rejected:{background:"#fef2f2",color:"#dc2626",border:"1px solid #fecaca"},"Executed & Closed":{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function w0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...S0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function k0({incForm:e,setIncForm:n,organizations:s,managements:l,departments:r,branches:a,incidentTypes:i,incidentClasses:d,incidentFields:c,incidentStatuses:p,users:w,userRoleMap:v={},formStatus:f,viewMode:g,canModify:S,onEdit:k,onDelete:y,onRestore:m,darkMode:o,notifCount:u,onToggleDark:h,onCountChange:z,onViewProfile:j,userRole:b,delegatedFunctions:x=[],delegatedOrgs:I={},onSubmit:E,onBack:F,onNavigate:U,onLogout:N,user:$,onRefresh:P}){var ft;const D=ne(),Y=M=>n({...e,...M}),X=g?{background:"#f9f9f9"}:{},q=Cl(w,v,"SB Manager",e.organization),[J,W]=C.useState(""),[V,de]=C.useState(!1),me=e.name?g?`${D.formTitle.viewIncident}${e.number||e.name}`:D.formTitle.editIncident:D.formTitle.newIncident,le=ye(l,e.management).map(M=>({name:M.name,label:M.name1||M.name})),Ve=ye(r,e.department).map(M=>({name:M.name,label:M.department_name||M.name})),dt=ye(a,e.branch).map(M=>({name:M.name,label:M.branch||M.name})),Q=ye(i,e.type).map(M=>({name:M.name,label:M.name1||M.name})),oe=ye(d,e.incident_class).map(M=>({name:M.name,label:M.name1||M.name})),Oe=ye(c,e.incident_field).map(M=>({name:M.name,label:M.name1||M.name})),ve=e.workflow_state||"New",nn=b==="Employee",fe=b==="Auditor"||b==="Admin",je=b==="Manager",Et=je&&x.includes("incident_initial_evaluation")&&(!I.incident_initial_evaluation||(I.incident_initial_evaluation||[]).includes(e.organization)),Ne=fe||Et,L=e.name?ve==="New"?[{label:D.wf.submit,action:"Submit",color:"#2563eb"}]:ve==="Initial Evaluation"&&Ne?[{label:D.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:D.wf.reject,action:"Reject",color:"#dc2626"}]:ve==="Accept & Under Progress"&&(je||fe)?[{label:D.wf.submitSolution,action:"Submit Solution",color:"#059669"}]:ve==="working on resolution"&&(je||fe)?[{label:D.wf.resolutionComplete,action:"Resolution complete",color:"#166534"}]:[]:[];async function se(M){if(e.name){de(!0),W("");try{const Be={};M==="Assign to Manager"&&(e.assigned_to&&(Be.assigned_to=e.assigned_to),e.priority&&(Be.priority=e.priority),e.economy_class&&(Be.economy_class=e.economy_class),e.entity_scope&&(Be.entity_scope=e.entity_scope),e.hses_field&&(Be.hses_field=e.hses_field),Be.product_relation=String(e.product_relation??0),Be.repeated=String(e.repeated??0)),M==="Submit Solution"&&(e.solution&&(Be.solution=e.solution),e.summary&&(Be.summary=e.summary),e.cost&&(Be.cost=String(e.cost))),(M==="Resolution complete"||M==="Submit Solution")&&e.auditor_comment&&(Be.auditor_comment=e.auditor_comment),await My(e.name,M,JSON.stringify(Be)),W("Done"),P==null||P()}catch(Be){W(Be.message||"Error")}finally{de(!1)}}}const R=((ft=q.find(M=>M.name===e.assigned_to))==null?void 0:ft.full_name)||e.assigned_to,We=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:D.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:ve})]}),ve==="Initial Evaluation"&&Ne&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:T,children:D.wf.assignToManager}),t.jsxs("select",{style:A,value:e.assigned_to||"",onChange:M=>Y({assigned_to:M.target.value}),children:[t.jsx("option",{value:"",children:D.field.selectMgr}),q.map(M=>t.jsx("option",{value:M.name,children:M.full_name||M.name},M.name))]})]}),(ve==="Accept & Under Progress"||ve==="working on resolution")&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:T,children:D.field.solution}),t.jsx("textarea",{style:{...A,height:75,resize:"vertical"},value:e.solution||"",onChange:M=>Y({solution:M.target.value}),placeholder:D.field.solutionPlaceholder}),t.jsx("label",{style:{...T,marginTop:6},children:D.field.actualCost}),t.jsx("input",{type:"number",style:A,value:e.cost||"",onChange:M=>Y({cost:parseFloat(M.target.value)||0}),placeholder:"0.00"})]}),ve==="working on resolution"&&fe&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:T,children:D.field.auditorComment}),t.jsx("textarea",{style:{...A,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:M=>Y({auditor_comment:M.target.value}),placeholder:D.field.commentPlaceholder})]}),L.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:L.map(M=>t.jsx("button",{onClick:()=>se(M.action),disabled:V,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:M.color,color:"white",fontWeight:600,fontSize:12,cursor:V?"not-allowed":"pointer",opacity:V?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:V?D.wf.applying:M.label})},M.action))}):t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:D.wf.noActions}),J&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:J==="Done"?G.green:G.red},children:J})]}),t.jsx(ii,{priority:e.priority,status:ve,assignedTo:b!=="Employee"?R:void 0,createdDate:e.date,modifiedDate:e.modified}),t.jsx(di,{doctype:O.incidents,docname:e.name,currentUserName:$.name}),t.jsx(ci,{doctype:O.incidents,docname:e.name,docCreation:e.creation,docOwner:e.owner}),S&&y&&!e.custom_is_deleted&&t.jsx(ai,{title:"Delete Request",btnText:D.delete,onDelete:()=>y(e.name)})]}):null;return t.jsxs(Ze,{title:me,activePage:"incidents",user:$,formStatus:f,statusBadge:t.jsx("span",{style:w0(ve),children:ve}),buttonText:D.saveIncident,buttonColor:"#16a34a",viewMode:g,onEdit:k,darkMode:o,notifCount:u,onToggleDark:h,onCountChange:z,onViewProfile:j,rightPanel:We,onSubmit:E,onBack:F,onNavigate:U,onLogout:N,children:[e.custom_is_deleted===1&&t.jsx(Ar,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:m?()=>m(e.name):void 0}),t.jsx(re,{title:"Incident Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.number}),t.jsx("input",{style:{...A,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[D.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:M=>Y({organization:M}),organizations:s,disabled:g||!!$.custom_organization})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.title}),t.jsx("input",{style:{...A,...X},value:e.title,disabled:g,onChange:M=>Y({title:M.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.management}),t.jsx(pe,{value:e.management,onChange:M=>Y({management:M}),items:le,placeholder:D.field.select,disabled:g})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.department}),t.jsx(pe,{value:e.department,onChange:M=>Y({department:M}),items:Ve,placeholder:D.field.select,disabled:g})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.section}),t.jsx("input",{style:{...A,...X},value:e.section_field||"",disabled:g,onChange:M=>Y({section_field:M.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.branch}),t.jsx(pe,{value:e.branch,onChange:M=>Y({branch:M}),items:dt,placeholder:D.field.select,disabled:g})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.type}),t.jsx(pe,{value:e.type,onChange:M=>Y({type:M}),items:Q,placeholder:D.field.selectType,disabled:g})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.incidentClass}),t.jsx(pe,{value:e.incident_class,onChange:M=>Y({incident_class:M}),items:oe,placeholder:D.field.selectClass,disabled:g})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.incidentField}),t.jsx(pe,{value:e.incident_field,onChange:M=>Y({incident_field:M}),items:Oe,placeholder:D.field.selectField,disabled:g})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.hsesField}),t.jsx("input",{style:{...A,...X},value:e.hses_field||"",disabled:g,onChange:M=>Y({hses_field:M.target.value}),placeholder:"Safety, Health, Environment…"})]})]})}),t.jsxs(re,{title:"Incident Details & Timing",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.date}),t.jsx(xe,{value:e.date,onChange:M=>Y({date:M}),disabled:!0,style:{...A,background:"#f8fafc"}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.time}),t.jsx("input",{type:"time",style:{...A,background:"#f8fafc"},value:e.time,disabled:!0,readOnly:!0})]}),b!=="Employee"&&t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.assignedTo}),g?t.jsx("input",{style:{...A,background:"#f8fafc",fontWeight:600,color:"#334155"},value:R||"—",readOnly:!0,disabled:!0}):t.jsx(pe,{value:e.assigned_to||"",onChange:M=>Y({assigned_to:M}),items:q.map(M=>({name:M.name,label:M.full_name||M.name})),placeholder:D.field.select})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.description}),t.jsx("textarea",{style:{...A,...X,height:100,resize:"vertical"},value:e.description,disabled:g,onChange:M=>Y({description:M.target.value}),placeholder:"Detailed description of the incident..."})]})]}),!nn&&t.jsxs(re,{title:D.steps.auditorTriage,children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.priority}),t.jsxs("select",{style:{...A,...g||!Ne?{background:"#f8fafc"}:{}},value:e.priority||"",disabled:g||!Ne,onChange:M=>Y({priority:M.target.value}),children:[t.jsx("option",{value:"",children:D.field.select}),t.jsx("option",{value:"High",children:D.field.high}),t.jsx("option",{value:"Normal",children:D.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.economyClass}),t.jsxs("select",{style:{...A,...g||!Ne?{background:"#f8fafc"}:{}},value:e.economy_class||"",disabled:g||!Ne,onChange:M=>Y({economy_class:M.target.value}),children:[t.jsx("option",{value:"",children:D.field.select}),t.jsx("option",{value:"Expenses",children:D.field.expenses}),t.jsx("option",{value:"Capital",children:D.field.capital}),t.jsx("option",{value:"Earn",children:D.field.earn}),t.jsx("option",{value:"Pay/Loss",children:D.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.entityScope}),t.jsxs("select",{style:{...A,...g||!Ne?{background:"#f8fafc"}:{}},value:e.entity_scope||"",disabled:g||!Ne,onChange:M=>Y({entity_scope:M.target.value}),children:[t.jsx("option",{value:"",children:D.field.select}),t.jsx("option",{value:"Upstream",children:D.field.upstream}),t.jsx("option",{value:"On-stream",children:D.field.onstream}),t.jsx("option",{value:"Downstream",children:D.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:g||!Ne,onChange:M=>Y({product_relation:M.target.checked?1:0})})," ",D.field.productRelation]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:g||!Ne,onChange:M=>Y({repeated:M.target.checked?1:0})})," ",D.field.repeatedEvent]})]})]}),!nn&&t.jsxs(re,{title:D.steps.managerSolution,children:[t.jsxs("div",{style:{marginBottom:12},children:[t.jsx("label",{style:T,children:D.field.solution}),t.jsx("textarea",{style:{...A,height:90,resize:"vertical",...g&&!je&&!fe?{background:"#f8fafc"}:{}},value:e.solution||"",disabled:g&&!je&&!fe,onChange:M=>Y({solution:M.target.value}),placeholder:D.field.solutionPlaceholder})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.actualCost}),t.jsx("input",{type:"number",style:{...A,...g&&!je&&!fe?{background:"#f8fafc"}:{}},value:e.cost||"",disabled:g&&!je&&!fe,onChange:M=>Y({cost:parseFloat(M.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.summary}),t.jsx("input",{style:{...A,...g&&!je&&!fe?{background:"#f8fafc"}:{}},value:e.summary||"",disabled:g&&!je&&!fe,onChange:M=>Y({summary:M.target.value}),placeholder:"Brief summary"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:D.field.auditorComment}),t.jsx("textarea",{style:{...A,height:70,resize:"vertical",...g&&!fe?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:g&&!fe,onChange:M=>Y({auditor_comment:M.target.value}),placeholder:D.field.commentPlaceholder})]})]})]})}function _0({ideas:e,organizations:n,departments:s,branches:l,ideaStatuses:r,initialOrg:a,initialStatus:i,canModify:d,userRole:c,onView:p,onEdit:w,onDelete:v,onSelectionChange:f}){const g=ne(),[S,k]=C.useState(new Set),[y,m]=C.useState({search:"",organization:a||"",department:"",branch:"",status:i||""}),o=(x,I)=>m(E=>({...E,[x]:I})),[u,h]=C.useState(1),z=e.filter(x=>!(y.search&&!`${x.number} ${x.title}`.toLowerCase().includes(y.search.toLowerCase())||y.organization&&x.organization!==y.organization||y.department&&x.department!==y.department||y.branch&&x.branch!==y.branch||y.status&&x.status!==y.status));C.useEffect(()=>{h(1)},[y]);const j=z.slice((u-1)*ae,u*ae);C.useEffect(()=>{if(f){const x=e.filter(I=>S.has(I.name));f(x,j)}},[S]);const b=x=>{const I=e.filter(U=>S.has(U.name)),E=Me.ideas,F=E.columns.filter(U=>E.defaultColumns.includes(U.key));x==="csv"?He(F,I,"ideas_selected"):Ge(F,I,"ideas_selected")};return t.jsxs(t.Fragment,{children:[t.jsx(oi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.numberTitle}),t.jsx("input",{style:nt,value:y.search,onChange:x=>o("search",x.target.value),placeholder:g.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.organization}),t.jsxs("select",{style:nt,value:y.organization,onChange:x=>o("organization",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allOrgs}),n.map(x=>t.jsx("option",{value:x.name,children:x.organization_name||x.name},x.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.department}),t.jsxs("select",{style:nt,value:y.department,onChange:x=>o("department",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allDepts}),s.map(x=>t.jsx("option",{value:x.name,children:x.department_name||x.name},x.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.branch}),t.jsxs("select",{style:nt,value:y.branch,onChange:x=>o("branch",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allBranches}),l.map(x=>t.jsx("option",{value:x.name,children:x.branch||x.name},x.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:g.filter.status}),t.jsxs("select",{style:nt,value:y.status,onChange:x=>o("status",x.target.value),children:[t.jsx("option",{value:"",children:g.filter.allStatuses}),r.map(x=>t.jsx("option",{value:x.name,children:x.name1||x.name},x.name))]})]}),t.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:t.jsx("button",{onClick:()=>m({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"7px 14px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#475569",fontWeight:500},children:g.clear})})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:j.length>0&&j.every(x=>S.has(x.name)),onChange:x=>{if(x.target.checked)k(new Set([...S,...j.map(I=>I.name)]));else{const I=new Set(S);j.forEach(E=>I.delete(E.name)),k(I)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:g.col.actions})]})}),t.jsx("tbody",{children:z.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:g.noIdeas})}):j.map((x,I)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(x),style:{borderTop:"1px solid #f1f5f9",background:S.has(x.name)?"#eff6ff":x.custom_is_deleted?"#fff1f2":I%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:E=>E.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:S.has(x.name),onChange:()=>{const E=new Set(S);E.has(x.name)?E.delete(x.name):E.add(x.name),k(E)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:x.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx("span",{children:x.title||"—"}),x.sb_order&&t.jsxs("span",{style:{fontSize:11,background:"#f0fdf4",color:"#15803d",border:"1px solid #bbf7d0",borderRadius:9999,padding:"2px 8px",fontWeight:600},children:["📦 ",x.sb_order]})]})}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:x.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:x.custom_is_deleted?ns(g.deletedBadge):x.status?ns(x.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:E=>E.stopPropagation(),children:t.jsx(at,{onView:()=>p==null?void 0:p(x),onEdit:d&&w&&!x.custom_is_deleted&&!Hn("idea",x.workflow_state)&&!(c==="Employee"&&x.workflow_state&&x.workflow_state!=="New")?()=>w(x):void 0,onDelete:d&&v&&!x.custom_is_deleted?()=>v(x.name):void 0})})]},x.name))})]})}),t.jsx(Je,{count:S.size,onClear:()=>k(new Set),onExport:b}),t.jsx(qe,{page:u,total:z.length,onPageChange:h})]})}const C0={New:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Initial Evaluation":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},"Accept & Under Progress":{background:"#fefce8",color:"#92400e",border:"1px solid #fde68a"},"working on proposal":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Rejected:{background:"#fef2f2",color:"#dc2626",border:"1px solid #fecaca"},"Executed & Closed":{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function z0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...C0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function I0({ideaForm:e,setIdeaForm:n,organizations:s,managements:l,departments:r,branches:a,ideaTypes:i,ideaStatuses:d,users:c=[],userRoleMap:p={},formStatus:w,viewMode:v,canModify:f,onEdit:g,onDelete:S,onRestore:k,onNavigateToOrder:y,darkMode:m,notifCount:o,onToggleDark:u,onCountChange:h,onViewProfile:z,userRole:j,delegatedFunctions:b=[],delegatedOrgs:x={},onSubmit:I,onBack:E,onNavigate:F,onLogout:U,user:N,onRefresh:$}){var se;const P=ne(),D=R=>n({...e,...R}),Y=v?{background:"#f9f9f9"}:{},X=Cl(c,p,"SB Manager",e.organization),[q,J]=C.useState(""),[W,V]=C.useState(!1),de=e.name?v?`${P.formTitle.viewIdea}${e.number||e.title||e.name}`:P.formTitle.editIdea:P.formTitle.newIdea,me=ye(l,e.management).map(R=>({name:R.name,label:R.name1||R.name})),le=ye(r,e.department).map(R=>({name:R.name,label:R.department_name||R.name})),Ve=ye(a,e.branch).map(R=>({name:R.name,label:R.branch||R.name})),dt=ye(i,e.type).map(R=>({name:R.name,label:R.name1||R.name})),Q=e.workflow_state||"New",oe=j==="Employee",Oe=j==="Auditor"||j==="Admin",ve=j==="Manager",nn=ve&&b.includes("idea_initial_evaluation")&&(!x.idea_initial_evaluation||(x.idea_initial_evaluation||[]).includes(e.organization)),fe=Oe||nn,je=e.name?Q==="New"?[{label:P.wf.submit,action:"Submit",color:"#2563eb"}]:Q==="Initial Evaluation"&&fe?[{label:P.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:P.wf.reject,action:"Reject",color:"#dc2626"}]:Q==="Accept & Under Progress"&&(ve||Oe)?[{label:P.wf.submitSolution,action:"Submit Proposal",color:"#059669"}]:Q==="working on proposal"&&Oe?[{label:P.wf.moveToOutsourcing,action:"Move to Outsourcing",color:"#0369a1"},{label:P.wf.reject,action:"Reject",color:"#dc2626"}]:[]:[];async function Et(R){if(e.name){V(!0),J("");try{const We={};R==="Assign to Manager"&&(e.assigned_to&&(We.assigned_to=e.assigned_to),e.priority&&(We.priority=e.priority),e.economy_class&&(We.economy_class=e.economy_class),e.entity_scope&&(We.entity_scope=e.entity_scope),e.hses_field&&(We.hses_field=e.hses_field),We.product_relation=String(e.product_relation??0),We.repeated=String(e.repeated??0)),R==="Submit Proposal"&&(e.solution&&(We.solution=e.solution),e.proposed_condition&&(We.proposed_condition=e.proposed_condition),e.cost&&(We.cost=String(e.cost))),e.auditor_comment&&(R==="Move to Outsourcing"||R==="Reject")&&(We.auditor_comment=e.auditor_comment);const ft=await Hy(e.name,R,JSON.stringify(We));ft!=null&&ft.created_order&&D({sb_order:ft.created_order,workflow_state:"Executed & Closed",status:"Executed & Closed"}),J("Done"),$==null||$()}catch(We){J(We.message||"Error")}finally{V(!1)}}}const Ne=((se=X.find(R=>R.name===e.assigned_to))==null?void 0:se.full_name)||e.assigned_to,L=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:P.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:Q})]}),Q==="Initial Evaluation"&&fe&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:T,children:P.wf.assignToManager}),t.jsxs("select",{style:A,value:e.assigned_to||"",onChange:R=>D({assigned_to:R.target.value}),children:[t.jsx("option",{value:"",children:P.field.selectMgr}),X.map(R=>t.jsx("option",{value:R.name,children:R.full_name||R.name},R.name))]})]}),Q==="Accept & Under Progress"&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:T,children:P.field.solution}),t.jsx("textarea",{style:{...A,height:75,resize:"vertical"},value:e.solution||"",onChange:R=>D({solution:R.target.value}),placeholder:P.field.solutionPlaceholder}),t.jsx("label",{style:{...T,marginTop:6},children:P.field.actualCost}),t.jsx("input",{type:"number",style:A,value:e.cost||"",onChange:R=>D({cost:parseFloat(R.target.value)||0}),placeholder:"0.00"})]}),Q==="working on proposal"&&Oe&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:T,children:P.field.auditorComment}),t.jsx("textarea",{style:{...A,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:R=>D({auditor_comment:R.target.value}),placeholder:P.field.commentPlaceholder})]}),je.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:je.map(R=>t.jsx("button",{onClick:()=>Et(R.action),disabled:W,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:R.color,color:"white",fontWeight:600,fontSize:12,cursor:W?"not-allowed":"pointer",opacity:W?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:W?P.wf.applying:R.label})},R.action))}):t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:P.wf.noActions}),q&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:q==="Done"?G.green:G.red},children:q})]}),t.jsx(ii,{priority:e.priority,status:Q,assignedTo:j!=="Employee"?Ne:void 0,createdDate:e.date,modifiedDate:e.modified}),t.jsx(di,{doctype:O.ideas,docname:e.name,currentUserName:N.name}),t.jsx(ci,{doctype:O.ideas,docname:e.name,docCreation:e.creation,docOwner:e.owner}),f&&S&&!e.custom_is_deleted&&t.jsx(ai,{title:"Delete Request",btnText:P.delete,onDelete:()=>S(e.name)})]}):null;return t.jsxs(Ze,{title:de,activePage:"ideas",user:N,formStatus:w,statusBadge:t.jsx("span",{style:z0(Q),children:Q}),buttonText:P.saveIdea,buttonColor:"#16a34a",viewMode:v,onEdit:g,darkMode:m,notifCount:o,onToggleDark:u,onCountChange:h,onViewProfile:z,rightPanel:L,onSubmit:I,onBack:E,onNavigate:F,onLogout:U,children:[e.custom_is_deleted===1&&t.jsx(Ar,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:k?()=>k(e.name):void 0}),e.sb_order&&t.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"8px 14px",marginBottom:16,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:12},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden"},children:[t.jsx("span",{style:{fontSize:14,flexShrink:0},children:"📦"}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,color:"#15803d",textTransform:"uppercase",letterSpacing:"0.4px",whiteSpace:"nowrap"},children:[P.field.convertedToOrder,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#14532d",whiteSpace:"nowrap"},children:e.sb_order})]}),y&&t.jsxs("button",{type:"button",onClick:()=>y(e.sb_order),style:{background:"#16a34a",color:"#fff",border:"none",borderRadius:6,padding:"4px 10px",fontWeight:600,fontSize:11,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,transition:"background 0.15s ease"},onMouseEnter:R=>R.currentTarget.style.background="#15803d",onMouseLeave:R=>R.currentTarget.style.background="#16a34a",children:[P.field.viewOrder," →"]})]}),t.jsx(re,{title:"Idea Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.number}),t.jsx("input",{style:{...A,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[P.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:R=>D({organization:R}),organizations:s,disabled:v||!!N.custom_organization})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.title}),t.jsx("input",{style:{...A,...Y},value:e.title,disabled:v,onChange:R=>D({title:R.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.management}),t.jsx(pe,{value:e.management,onChange:R=>D({management:R}),items:me,placeholder:P.field.select,disabled:v})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.department}),t.jsx(pe,{value:e.department,onChange:R=>D({department:R}),items:le,placeholder:P.field.select,disabled:v})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.section}),t.jsx("input",{style:{...A,...Y},value:e.section_field||"",disabled:v,onChange:R=>D({section_field:R.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.branch}),t.jsx(pe,{value:e.branch,onChange:R=>D({branch:R}),items:Ve,placeholder:P.field.select,disabled:v})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.type}),t.jsx(pe,{value:e.type,onChange:R=>D({type:R}),items:dt,placeholder:P.field.selectType,disabled:v})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.ideaClass}),t.jsxs("select",{style:{...A,...Y},value:e.idea_class||"",disabled:v,onChange:R=>D({idea_class:R.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"Safety",children:"Safety"}),t.jsx("option",{value:"Non-safety",children:"Non-safety"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.hsesField}),t.jsx("input",{style:{...A,...Y},value:e.hses_field||"",disabled:v,onChange:R=>D({hses_field:R.target.value}),placeholder:"Safety, Health, Environment…"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.date}),t.jsx(xe,{value:e.date||"",onChange:R=>D({date:R}),disabled:!0,style:{...A,background:"#f8fafc"}})]}),j!=="Employee"&&t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.assignedTo}),v?t.jsx("input",{style:{...A,background:"#f8fafc",fontWeight:600,color:"#334155"},value:Ne||"—",readOnly:!0,disabled:!0}):t.jsx(pe,{value:e.assigned_to||"",onChange:R=>D({assigned_to:R}),items:X.map(R=>({name:R.name,label:R.full_name||R.name})),placeholder:P.field.select})]})]})}),t.jsx(re,{title:"Condition Details & Description",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(280px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.currentCondition}),t.jsx("textarea",{style:{...A,...Y,height:100,resize:"vertical"},value:e.current_condition,disabled:v,onChange:R=>D({current_condition:R.target.value}),placeholder:"Describe the current condition or problem..."})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.proposedCondition}),t.jsx("textarea",{style:{...A,...Y,height:100,resize:"vertical"},value:e.proposed_condition,disabled:v,onChange:R=>D({proposed_condition:R.target.value}),placeholder:"Describe the proposed solution or improvement..."})]})]})}),!oe&&t.jsxs(re,{title:P.steps.auditorEval,children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.priority}),t.jsxs("select",{style:{...A,...v||!fe?{background:"#f8fafc"}:{}},value:e.priority||"",disabled:v||!fe,onChange:R=>D({priority:R.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"High",children:P.field.high}),t.jsx("option",{value:"Normal",children:P.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.economyClass}),t.jsxs("select",{style:{...A,...v||!fe?{background:"#f8fafc"}:{}},value:e.economy_class||"",disabled:v||!fe,onChange:R=>D({economy_class:R.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"Expenses",children:P.field.expenses}),t.jsx("option",{value:"Capital",children:P.field.capital}),t.jsx("option",{value:"Earn",children:P.field.earn}),t.jsx("option",{value:"Pay/Loss",children:P.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.entityScope}),t.jsxs("select",{style:{...A,...v||!fe?{background:"#f8fafc"}:{}},value:e.entity_scope||"",disabled:v||!fe,onChange:R=>D({entity_scope:R.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"Upstream",children:P.field.upstream}),t.jsx("option",{value:"On-stream",children:P.field.onstream}),t.jsx("option",{value:"Downstream",children:P.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:v||!fe,onChange:R=>D({product_relation:R.target.checked?1:0})})," ",P.field.productRelation]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:v||!fe,onChange:R=>D({repeated:R.target.checked?1:0})})," ",P.field.repeatedEvent]})]})]}),!oe&&t.jsxs(re,{title:P.steps.managerSolution,children:[t.jsxs("div",{style:{marginBottom:12},children:[t.jsx("label",{style:T,children:P.field.solution}),t.jsx("textarea",{style:{...A,height:90,resize:"vertical",...v&&!ve&&!Oe?{background:"#f8fafc"}:{}},value:e.solution||"",disabled:v&&!ve&&!Oe,onChange:R=>D({solution:R.target.value}),placeholder:P.field.solutionPlaceholder})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.actualCost}),t.jsx("input",{type:"number",style:{...A,...v&&!ve&&!Oe?{background:"#f8fafc"}:{}},value:e.cost||"",disabled:v&&!ve&&!Oe,onChange:R=>D({cost:parseFloat(R.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.auditorComment}),t.jsx("textarea",{style:{...A,height:60,resize:"vertical",...v&&!Oe?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:v&&!Oe,onChange:R=>D({auditor_comment:R.target.value}),placeholder:P.field.commentPlaceholder})]})]})]})]})}function E0({orders:e,organizations:n,departments:s,branches:l,orderStatuses:r,initialOrg:a,initialStatus:i,canModify:d,userRole:c,onView:p,onEdit:w,onDelete:v}){const f=ne(),[g,S]=C.useState(new Set),[k,y]=C.useState({search:"",organization:a||"",department:"",branch:"",status:i||""}),m=(b,x)=>y(I=>({...I,[b]:x})),[o,u]=C.useState(1),h=e.filter(b=>!(k.search&&!`${b.number} ${b.title}`.toLowerCase().includes(k.search.toLowerCase())||k.organization&&b.organization!==k.organization||k.department&&b.department!==k.department||k.branch&&b.branch!==k.branch||k.status&&b.status!==k.status));C.useEffect(()=>{u(1)},[k]);const z=h.slice((o-1)*ae,o*ae),j=b=>{const x=e.filter(F=>g.has(F.name)),I=Me.orders,E=I.columns.filter(F=>I.defaultColumns.includes(F.key));b==="csv"?He(E,x,"orders_selected"):Ge(E,x,"orders_selected")};return t.jsxs(t.Fragment,{children:[t.jsx(oi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.numberTitle}),t.jsx("input",{style:nt,value:k.search,onChange:b=>m("search",b.target.value),placeholder:f.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.organization}),t.jsxs("select",{style:nt,value:k.organization,onChange:b=>m("organization",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allOrgs}),n.map(b=>t.jsx("option",{value:b.name,children:b.organization_name},b.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.department}),t.jsxs("select",{style:nt,value:k.department,onChange:b=>m("department",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allDepts}),s.map(b=>t.jsx("option",{value:b.name,children:b.department_name},b.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.branch}),t.jsxs("select",{style:nt,value:k.branch,onChange:b=>m("branch",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allBranches}),l.map(b=>t.jsx("option",{value:b.name,children:b.branch},b.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.status}),t.jsxs("select",{style:nt,value:k.status,onChange:b=>m("status",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allStatuses}),r.map(b=>t.jsx("option",{value:b.name,children:b.name1||b.name},b.name))]})]}),t.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:t.jsx("button",{type:"button",onClick:()=>{y({search:"",organization:a||"",department:"",branch:"",status:""}),u(1)},style:{height:38,padding:"0 16px",border:"1px solid #d1d5db",borderRadius:8,background:"#fff",color:"#374151",fontSize:13,fontWeight:500,cursor:"pointer",width:"100%"},children:f.clear})})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:z.length>0&&z.every(b=>g.has(b.name)),onChange:b=>{if(b.target.checked)S(new Set([...g,...z.map(x=>x.name)]));else{const x=new Set(g);z.forEach(I=>x.delete(I.name)),S(x)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.type}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.actions})]})}),t.jsx("tbody",{children:h.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:f.noOrders})}):z.map((b,x)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(b),style:{borderTop:"1px solid #f1f5f9",background:g.has(b.name)?"#eff6ff":b.custom_is_deleted?"#fff1f2":x%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:I=>I.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:g.has(b.name),onChange:()=>{const I=new Set(g);I.has(b.name)?I.delete(b.name):I.add(b.name),S(I)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:b.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx("span",{children:b.title||"—"}),b.sb_idea&&t.jsxs("span",{style:{fontSize:11,background:"#eff6ff",color:"#1d4ed8",border:"1px solid #bfdbfe",borderRadius:9999,padding:"2px 8px",fontWeight:600},children:["💡 ",b.sb_idea]})]})}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:b.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:b.type?$d(b.type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:b.custom_is_deleted?ns(f.deletedBadge):b.status?ns(b.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:I=>I.stopPropagation(),children:t.jsx(at,{onView:()=>p==null?void 0:p(b),onEdit:d&&w&&!b.custom_is_deleted&&!Hn("order",b.workflow_state)&&c!=="Employee"?()=>w(b):void 0,onDelete:d&&v&&!b.custom_is_deleted?()=>v(b.name):void 0})})]},b.name))})]})}),t.jsx(Je,{count:g.size,onClear:()=>S(new Set),onExport:j}),t.jsx(qe,{page:o,total:h.length,onPageChange:u})]})}const T0={1:"Initiation / Bidding",2:"Execution begins",3:"Mid-execution review",4:"Near completion",5:"Closing"},P0={Draft:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Pending Actor":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},Review:{background:"#fefce8",color:"#92400e",border:"1px solid #fde68a"},"In Study":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Closed:{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function A0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...P0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function R0({orderForm:e,setOrderForm:n,organizations:s,managements:l,departments:r,branches:a,orderTypes:i,orderStatuses:d,cycles:c=[],users:p=[],userRoleMap:w={},formStatus:v,viewMode:f,canModify:g,onEdit:S,onDelete:k,onRestore:y,onNavigateToIdea:m,darkMode:o,notifCount:u,onToggleDark:h,onCountChange:z,onViewProfile:j,currentUser:b,userRole:x,onSubmit:I,onBack:E,onNavigate:F,onLogout:U,user:N,onRefresh:$}){var gn,Dr;const P=ne(),D=B=>n({...e,...B}),Y=f?{background:"#f9f9f9"}:{},X=Cl(p,w,"SB Employee",e.organization),[q,J]=C.useState(""),[W,V]=C.useState(""),[de,me]=C.useState(!1),[le,Ve]=C.useState("Agree"),dt=e.name?f?`${P.formTitle.viewOrder}${e.number||e.title||e.name}`:P.formTitle.editOrder:P.formTitle.newOrder,Q=ye(l,e.management).map(B=>({name:B.name,label:B.name1||B.name})),oe=ye(r,e.department).map(B=>({name:B.name,label:B.department_name||B.name})),Oe=ye(a,e.branch).map(B=>({name:B.name,label:B.branch||B.name})),ve=ye(i,e.type).map(B=>({name:B.name,label:B.name1||B.name})),nn=ye(c,e.cycle).map(B=>({name:B.name,label:B.name1||B.cycle_name||B.name})),fe=!!e.name,je=e.workflow_state||"Draft",Et=Math.min(5,(e.stage||0)+1),[Ne,L]=C.useState(Et);C.useEffect(()=>{L(Math.min(5,(e.stage||0)+1))},[e.stage]);const se=x==="Auditor"||x==="Admin"||x==="Manager",R=se||x==="Owner",We=!!(b&&(e.actor===b||e.assigned_to===b)),ft=fe?je==="Closed"?[]:je==="Draft"&&se?[{label:"Submit for Review",action:"Submit for Review",color:"#2563eb"}]:je==="Pending Actor"&&(We||se)?[{label:"Update Status",action:"Update Status",color:"#d97706"}]:je==="Review"&&R?[{label:"Move to Study",action:"Move to Study",color:"#059669"},{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}]:je==="In Study"&&R?[{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"},{label:"Close Order",action:"Close Order",color:"#475569"}]:[]:[];async function M(B){if(e.name){me(!0),J("");try{let Tt;B==="Update Status"&&(Tt=le);const xn=await Fy(e.name,B,W,B==="Update Status"?String(Ne):void 0,void 0,Tt);if(V(""),Ve("Agree"),J("Done"),xn){const Rn=xn;n({...e,...Rn,stage:Rn.stage??e.stage,completion_pct:Rn.completion_pct??e.completion_pct,workflow_state:Rn.workflow_state??e.workflow_state})}$==null||$()}catch(Tt){J(Tt.message||"Error")}finally{me(!1)}}}const Be=((gn=X.find(B=>B.name===(e.actor||e.assigned_to)))==null?void 0:gn.full_name)||e.actor||e.assigned_to,ui=fe?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:P.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:je})]}),je==="Pending Actor"&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:12},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:["Stage (1–5) — ",Ne*20,"% complete"]}),t.jsx("input",{type:"number",min:1,max:5,style:{...A,width:"100%"},value:Ne,onChange:B=>L(Math.min(5,Math.max(1,parseInt(B.target.value)||1)))})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Cycle Status"}),t.jsxs("select",{style:A,value:le,onChange:B=>Ve(B.target.value),children:[t.jsx("option",{value:"Agree",children:"✅ Agree — on track"}),t.jsx("option",{value:"Deviate",children:"⚠️ Deviate — off plan"}),t.jsx("option",{value:"Unknown",children:"❓ Unknown"})]})]})]}),t.jsxs("div",{style:{marginBottom:12},children:[t.jsxs("label",{style:T,children:["Comment ",le==="Deviate"&&je==="Pending Actor"?t.jsx("span",{style:{color:G.red},children:" * required for Deviate"}):"(optional)"]}),t.jsx("textarea",{style:{...A,height:60,resize:"vertical",borderColor:le==="Deviate"&&!W?"#fca5a5":void 0},value:W,onChange:B=>V(B.target.value),placeholder:"Add a comment…"})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:ft.map(B=>{const Tt=B.action==="Update Status"&&le==="Deviate"&&!W.trim();return t.jsx("button",{onClick:()=>M(B.action),disabled:de||Tt,title:Tt?"Comment required when status is Deviate":void 0,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:B.color,color:"white",fontWeight:600,fontSize:12,cursor:de||Tt?"not-allowed":"pointer",opacity:de||Tt?.5:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:de?P.wf.applying:B.label})},B.action)})}),q&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:q==="Done"?G.green:G.red},children:q}),ft.length===0&&t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:P.wf.noActions})]}),t.jsx(ii,{priority:e.priority,status:je,assignedTo:x!=="Employee"?Be:void 0,createdDate:e.starting_date,modifiedDate:e.modified}),t.jsx(di,{doctype:O.orders,docname:e.name,currentUserName:N.name}),t.jsx(ci,{doctype:O.orders,docname:e.name,docCreation:e.creation,docOwner:e.owner}),g&&k&&!e.custom_is_deleted&&t.jsx(ai,{title:"Delete Request",btnText:P.delete,onDelete:()=>k(e.name)})]}):null;return t.jsxs(Ze,{title:dt,activePage:"orders",user:N,formStatus:v,statusBadge:t.jsx("span",{style:A0(je),children:je}),buttonText:P.saveOrder,buttonColor:"#16a34a",viewMode:f,onEdit:S,darkMode:o,notifCount:u,onToggleDark:h,onCountChange:z,onViewProfile:j,rightPanel:ui,onSubmit:I,onBack:E,onNavigate:F,onLogout:U,children:[e.custom_is_deleted===1&&t.jsx(Ar,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:y?()=>y(e.name):void 0}),e.sb_idea&&t.jsxs("div",{style:{background:"#f0f7ff",border:"1px solid #bfdbfe",borderRadius:8,padding:"8px 14px",marginBottom:16,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:12},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden"},children:[t.jsx("span",{style:{fontSize:14,flexShrink:0},children:"💡"}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,color:"#1e40af",textTransform:"uppercase",letterSpacing:"0.4px",whiteSpace:"nowrap"},children:[P.field.originatingIdea,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#1e3a8a",whiteSpace:"nowrap"},children:e.sb_idea})]}),m&&t.jsxs("button",{type:"button",onClick:()=>m(e.sb_idea),style:{background:"#2563eb",color:"#fff",border:"none",borderRadius:6,padding:"4px 10px",fontWeight:600,fontSize:11,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,transition:"background 0.15s ease"},onMouseEnter:B=>B.currentTarget.style.background="#1d4ed8",onMouseLeave:B=>B.currentTarget.style.background="#2563eb",children:[P.field.viewIdea," →"]})]}),t.jsx(re,{title:"Order Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.number}),t.jsx("input",{style:{...A,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[P.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:B=>D({organization:B}),organizations:s,disabled:f||!!N.custom_organization})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.title}),t.jsx("input",{style:{...A,...Y},value:e.title,disabled:f,onChange:B=>D({title:B.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.management}),t.jsx(pe,{value:e.management,onChange:B=>D({management:B}),items:Q,placeholder:P.field.select,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.department}),t.jsx(pe,{value:e.department,onChange:B=>D({department:B}),items:oe,placeholder:P.field.select,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.section}),t.jsx("input",{style:{...A,...Y},value:e.section_field||"",disabled:f,onChange:B=>D({section_field:B.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.branch}),t.jsx(pe,{value:e.branch,onChange:B=>D({branch:B}),items:Oe,placeholder:P.field.select,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.type}),t.jsx(pe,{value:e.type,onChange:B=>D({type:B}),items:ve,placeholder:P.field.selectType,disabled:f})]})]})}),t.jsxs(re,{title:"Financial & Schedule",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.budget}),t.jsx("input",{type:"number",style:{...A,...Y},value:e.budget||"",disabled:f,onChange:B=>D({budget:parseFloat(B.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.actualCost}),t.jsx("input",{type:"number",style:{...A,...Y},value:e.actual_cost||"",disabled:f,onChange:B=>D({actual_cost:parseFloat(B.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Variance"}),(()=>{const B=(e.budget||0)-(e.actual_cost||0);return t.jsxs("div",{style:{padding:"7px 12px",borderRadius:6,fontWeight:700,fontSize:13,background:B>=0?"#f0fdf4":"#fef2f2",color:B>=0?"#166534":"#dc2626",border:`1px solid ${B>=0?"#bbf7d0":"#fecaca"}`,display:"inline-block",width:"100%",boxSizing:"border-box"},children:[B>=0?"+":"",B.toFixed(2)]})})()]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.currency}),t.jsxs("select",{style:{...A,...Y},value:e.currency||"",disabled:f,onChange:B=>D({currency:B.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"SAR",children:"SAR"}),t.jsx("option",{value:"USD",children:"USD"}),t.jsx("option",{value:"EUR",children:"EUR"}),t.jsx("option",{value:"AED",children:"AED"}),t.jsx("option",{value:"GBP",children:"GBP"})]})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.startingDate}),t.jsx(xe,{value:e.starting_date,onChange:B=>D({starting_date:B}),disabled:f,style:{...A,...Y}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.endingDate}),t.jsx(xe,{value:e.ending_date,onChange:B=>D({ending_date:B}),disabled:f,style:{...A,...Y}})]}),x!=="Employee"&&t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.actor}),f?t.jsx("input",{style:{...A,background:"#f8fafc",fontWeight:600,color:"#334155"},value:Be||"—",readOnly:!0,disabled:!0}):t.jsxs("select",{style:{...A,background:"#ffffff"},value:e.actor||e.assigned_to||"",onChange:B=>D({actor:B.target.value,assigned_to:B.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),X.map(B=>t.jsx("option",{value:B.name,children:B.full_name||B.name},B.name))]})]})]})]}),t.jsxs(re,{title:"Classification",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.priority}),t.jsxs("select",{style:{...A,...Y},value:e.priority||"",disabled:f,onChange:B=>D({priority:B.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"High",children:P.field.high}),t.jsx("option",{value:"Normal",children:P.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.economyClass}),t.jsxs("select",{style:{...A,...Y},value:e.economy_class||"",disabled:f,onChange:B=>D({economy_class:B.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"Expenses",children:P.field.expenses}),t.jsx("option",{value:"Capital",children:P.field.capital}),t.jsx("option",{value:"Earn",children:P.field.earn}),t.jsx("option",{value:"Pay/Loss",children:P.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.entityScope}),t.jsxs("select",{style:{...A,...Y},value:e.entity_scope||"",disabled:f,onChange:B=>D({entity_scope:B.target.value}),children:[t.jsx("option",{value:"",children:P.field.select}),t.jsx("option",{value:"Upstream",children:P.field.upstream}),t.jsx("option",{value:"On-stream",children:P.field.onstream}),t.jsx("option",{value:"Downstream",children:P.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:24,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.planned,disabled:f,onChange:B=>D({planned:B.target.checked?1:0})})," Planned"]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:f,onChange:B=>D({product_relation:B.target.checked?1:0})})," ",P.field.productRelation]})]}),t.jsxs("div",{style:{marginTop:12},children:[t.jsx("label",{style:T,children:P.field.hsesField}),t.jsx("input",{style:{...A,...Y},value:e.hses_field||"",disabled:f,onChange:B=>D({hses_field:B.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),t.jsxs(re,{title:"Cycle & Progress Tracking",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.cycle}),t.jsx(pe,{value:e.cycle||"",onChange:B=>D({cycle:B}),items:nn,placeholder:P.field.select,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.cycleType}),t.jsxs("select",{style:{...A,...Y},value:e.cycle_type||"Normal",disabled:f,onChange:B=>D({cycle_type:B.target.value}),children:[t.jsx("option",{value:"Normal",children:"Normal"}),t.jsx("option",{value:"Long",children:"Long"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.stage}),t.jsx("input",{type:"number",min:1,max:5,style:{...A,background:"#f8fafc",color:"#334155",fontWeight:600},value:e.stage||1,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Completion"}),t.jsx("input",{style:{...A,background:"#f8fafc",color:"#334155",fontWeight:600},value:`${e.completion_pct||(e.stage||1)*20}%`,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Stage Description"}),t.jsx("span",{style:{display:"inline-block",padding:"7px 12px",borderRadius:6,fontSize:13,fontWeight:600,background:"#f0f9ff",color:"#0369a1",border:"1px solid #bae6fd",width:"100%",boxSizing:"border-box"},children:T0[e.stage||1]||"—"})]})]}),e.cycle_type==="Long"&&t.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14,marginBottom:14},children:[t.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 1"}),t.jsx(xe,{value:e.long_cycle_date_1||"",onChange:B=>D({long_cycle_date_1:B}),disabled:f,style:{...A,...Y}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 2"}),t.jsx(xe,{value:e.long_cycle_date_2||"",onChange:B=>D({long_cycle_date_2:B}),disabled:f,style:{...A,...Y}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 3"}),t.jsx(xe,{value:e.long_cycle_date_3||"",onChange:B=>D({long_cycle_date_3:B}),disabled:f,style:{...A,...Y}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 4"}),t.jsx(xe,{value:e.long_cycle_date_4||"",onChange:B=>D({long_cycle_date_4:B}),disabled:f,style:{...A,...Y}})]})]})]}),fe&&((Dr=e.order_cycle_log)==null?void 0:Dr.length)>0&&t.jsxs("div",{style:{borderTop:"1px solid #f1f5f9",paddingTop:14,marginTop:10},children:[t.jsx("p",{style:{fontWeight:700,color:"#334155",fontSize:13,marginBottom:10},children:"Cycle History"}),t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8fafc"},children:["Cycle","Date","Stage","Status","Actor","Comment"].map(B=>t.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:600,color:"#475569",borderBottom:"1px solid #e2e8f0"},children:B},B))})}),t.jsx("tbody",{children:(e.order_cycle_log||[]).map((B,Tt)=>{const xn=B.status==="Agree"?"#166534":B.status==="Deviate"?"#c2410c":"#92400e",Rn=B.status==="Agree"?"#f0fdf4":B.status==="Deviate"?"#fff7ed":"#fefce8";return t.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:B.cycle||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:B.cycle_date||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155",textAlign:"center"},children:B.stage||"—"}),t.jsx("td",{style:{padding:"6px 10px"},children:t.jsx("span",{style:{background:Rn,color:xn,padding:"2px 8px",borderRadius:12,fontWeight:600,fontSize:12},children:B.status||"—"})}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:B.actor||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#64748b",fontStyle:B.comment?"normal":"italic"},children:B.comment||"—"})]},Tt)})})]})})]})]}),t.jsxs(re,{title:"Description & Notes",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(280px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.description}),t.jsx("textarea",{style:{...A,...Y,height:90,resize:"vertical"},value:e.description,disabled:f,onChange:B=>D({description:B.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.notes}),t.jsx("textarea",{style:{...A,...Y,height:90,resize:"vertical"},value:e.notes,disabled:f,onChange:B=>D({notes:B.target.value})})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:P.field.auditorComment}),t.jsx("textarea",{style:{...A,height:70,resize:"vertical",...f&&We&&!se?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:f&&We&&!se,onChange:B=>D({auditor_comment:B.target.value}),placeholder:P.field.commentPlaceholder})]})]})]})}function D0({processes:e,organizations:n,departments:s,branches:l,processStatuses:r,initialOrg:a,initialStatus:i,canModify:d,userRole:c,onView:p,onEdit:w,onDelete:v}){const f=ne(),[g,S]=C.useState(new Set),[k,y]=C.useState({search:"",organization:a||"",department:"",branch:"",status:i||""}),m=(b,x)=>y(I=>({...I,[b]:x})),[o,u]=C.useState(1),h=e.filter(b=>!(k.search&&!`${b.number} ${b.title}`.toLowerCase().includes(k.search.toLowerCase())||k.organization&&b.organization!==k.organization||k.department&&b.department!==k.department||k.branch&&b.branch!==k.branch||k.status&&b.status!==k.status));C.useEffect(()=>{u(1)},[k]);const z=h.slice((o-1)*ae,o*ae),j=b=>{const x=e.filter(F=>g.has(F.name)),I=Me.processes,E=I.columns.filter(F=>I.defaultColumns.includes(F.key));b==="csv"?He(E,x,"processes_selected"):Ge(E,x,"processes_selected")};return t.jsxs(t.Fragment,{children:[t.jsx(oi,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.numberTitle}),t.jsx("input",{style:nt,value:k.search,onChange:b=>m("search",b.target.value),placeholder:f.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.organization}),t.jsxs("select",{style:nt,value:k.organization,onChange:b=>m("organization",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allOrgs}),n.map(b=>t.jsx("option",{value:b.name,children:b.organization_name},b.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.department}),t.jsxs("select",{style:nt,value:k.department,onChange:b=>m("department",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allDepts}),s.map(b=>t.jsx("option",{value:b.name,children:b.department_name},b.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.branch}),t.jsxs("select",{style:nt,value:k.branch,onChange:b=>m("branch",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allBranches}),l.map(b=>t.jsx("option",{value:b.name,children:b.branch},b.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:tt,children:f.filter.status}),t.jsxs("select",{style:nt,value:k.status,onChange:b=>m("status",b.target.value),children:[t.jsx("option",{value:"",children:f.filter.allStatuses}),r.map(b=>t.jsx("option",{value:b.name,children:b.name1||b.name},b.name))]})]}),t.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:t.jsx("button",{type:"button",onClick:()=>{y({search:"",organization:a||"",department:"",branch:"",status:""}),u(1)},style:{height:38,padding:"0 16px",border:"1px solid #d1d5db",borderRadius:8,background:"#fff",color:"#374151",fontSize:13,fontWeight:500,cursor:"pointer",width:"100%"},children:f.clear})})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:z.length>0&&z.every(b=>g.has(b.name)),onChange:b=>{if(b.target.checked)S(new Set([...g,...z.map(x=>x.name)]));else{const x=new Set(g);z.forEach(I=>x.delete(I.name)),S(x)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.field.cycleType}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:f.col.actions})]})}),t.jsx("tbody",{children:h.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:f.noProcesses})}):z.map((b,x)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(b),style:{borderTop:"1px solid #f1f5f9",background:g.has(b.name)?"#eff6ff":b.custom_is_deleted?"#fff1f2":x%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:I=>I.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:g.has(b.name),onChange:()=>{const I=new Set(g);I.has(b.name)?I.delete(b.name):I.add(b.name),S(I)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:b.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:b.title||b.name||"—"}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:b.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:b.cycle_type?$d(b.cycle_type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:b.custom_is_deleted?ns(f.deletedBadge):b.status?ns(b.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:I=>I.stopPropagation(),children:t.jsx(at,{onView:()=>p==null?void 0:p(b),onEdit:d&&w&&!b.custom_is_deleted&&!Hn("process",b.workflow_state)&&c!=="Employee"?()=>w(b):void 0,onDelete:d&&v&&!b.custom_is_deleted?()=>v(b.name):void 0})})]},b.name))})]})}),t.jsx(Je,{count:g.size,onClear:()=>S(new Set),onExport:j}),t.jsx(qe,{page:o,total:h.length,onPageChange:u})]})}const L0={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"]}]},O0={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 Du(e){return{display:"inline-block",padding:"5px 14px",borderRadius:20,fontSize:13,fontWeight:700,...O0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}const na={width:"100%",padding:"6px 8px",border:"1px solid #d1d5db",borderRadius:5,fontSize:12,fontFamily:"Segoe UI",boxSizing:"border-box"};function N0({processName:e,userRole:n,onRefresh:s,canUpdateStatus:l=!0}){const[r,a]=C.useState(null),[i,d]=C.useState(!0),[c,p]=C.useState(""),[w,v]=C.useState(!1),[f,g]=C.useState(""),[S,k]=C.useState(""),[y,m]=C.useState("Pass"),[o,u]=C.useState(""),[h,z]=C.useState({}),j=C.useCallback(async()=>{if(!e){d(!1);return}d(!0),p("");try{const N=await Vl(e);a(N);const $={};for(const P of N.progress_indicators||[])$[P.name]=P.actual_value!=null?String(P.actual_value):"";z($)}catch(N){p(N instanceof Error?N.message:"Failed to load process")}d(!1)},[e]);if(C.useEffect(()=>{j()},[j]),i)return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:24,color:"#aaa",fontSize:13,textAlign:"center"},children:"Loading…"})});if(c||!r)return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:16},children:t.jsx("div",{style:{fontSize:12,color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px"},children:c||"Could not load workflow"})})});const b=r.workflow_state||"Draft",x=L0[b]??[],I=n==="Employee"||n==="Manager",E=n!=="Manager"||l,F=x.filter(N=>(n==="Admin"||N.allowedRoles.includes(n))&&(N.action!=="Update Status"||E)),U=async N=>{v(!0),g(""),k("");try{const $={};if(N==="Update Status"){$.actor_status=y,$.actor_comment=o;const D=r.progress_indicators||[];D.length>0&&($.progress_indicators=D.map(Y=>({name:Y.name,actual_value:h[Y.name]??""})))}N==="Add Comment"&&o&&($.actor_comment=o);const P=await s0(r.name,N,$);a(P),u(""),k(`Done — now: ${P.workflow_state||"updated"}`),s==null||s()}catch($){g($ instanceof Error?$.message:"Action failed")}v(!1)};return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsx("div",{style:{background:"#1a2332",color:"white",padding:"10px 14px",fontSize:12,fontWeight:700,letterSpacing:.3},children:"Workflow"}),t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:8},children:"Current State"}),t.jsx("div",{style:Du(b),children:b})]}),b==="Pending Actor"&&I&&E&&t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Update Status"}),Array.isArray(r.progress_indicators)&&r.progress_indicators.length>0&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Actual Value"}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.progress_indicators.map(N=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{fontSize:11,color:"#555",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:N.name1,children:N.name1||N.name}),t.jsx("input",{type:"number",value:h[N.name]??"",onChange:$=>z(P=>({...P,[N.name]:$.target.value})),style:{...na,width:70,flexShrink:0},placeholder:"0"})]},N.name))})]}),t.jsxs("div",{style:{marginBottom:8},children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Cycle Status"}),t.jsxs("select",{value:y,onChange:N=>m(N.target.value),style:na,children:[t.jsx("option",{value:"Pass",children:"✅ Pass — on target"}),t.jsx("option",{value:"Fail",children:"❌ Fail — off target"})]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Comment (optional)"}),t.jsx("textarea",{value:o,onChange:N=>u(N.target.value),style:{...na,height:52,resize:"vertical"},placeholder:"Add a comment…"})]})]}),(b==="Pending Comment"||b==="Review")&&!I&&t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Auditor Comment"}),Array.isArray(r.cycle_logs)&&r.cycle_logs.length>0&&t.jsxs("div",{style:{marginBottom:8,padding:"6px 10px",background:"#f8fafc",borderRadius:6,border:"1px solid #e2e8f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",marginBottom:3},children:"Latest cycle status:"}),(()=>{const N=r.cycle_logs,$=N[N.length-1],P=$.status==="Pass"?"#16a34a":$.status==="Fail"?"#dc2626":"#9ca3af";return t.jsxs("div",{style:{fontSize:13,fontWeight:700,color:P},children:[$.status," ",$.comment?`— ${$.comment}`:""]})})()]}),t.jsx("textarea",{value:o,onChange:N=>u(N.target.value),style:{...na,height:52,resize:"vertical"},placeholder:"Add a comment…"})]}),t.jsxs("div",{style:{padding:"12px 14px",borderBottom:F.length>0?"1px solid #f0f0f0":"none"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Actions"}),F.length===0&&t.jsxs("div",{style:{fontSize:12,color:"#aaa",fontStyle:"italic",lineHeight:1.5},children:["No actions for ",t.jsx("strong",{children:n})," in ",t.jsx("strong",{children:b}),"."]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:F.map(N=>t.jsxs("button",{onClick:()=>U(N.action),disabled:w,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:w?"not-allowed":"pointer",fontSize:13,fontWeight:600,opacity:w?.7:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("span",{children:w?"Applying…":N.action}),t.jsxs("span",{style:{fontSize:10,opacity:.7},children:["→ ",N.next]})]},N.action))}),f&&t.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,fontSize:12,color:"#991b1b",lineHeight:1.4},children:f}),S&&t.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,fontSize:12,color:"#166534"},children:S})]}),x.length>0&&t.jsxs("div",{style:{padding:"12px 14px"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Next States"}),x.map(N=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6,fontSize:11},children:[t.jsx("span",{style:{color:"#555",flex:1},children:N.action}),t.jsx("span",{style:{color:"#bbb"},children:"→"}),t.jsx("span",{style:Du(N.next),children:N.next})]},N.action))]})]})})}function W0({processForm:e,setProcessForm:n,organizations:s,managements:l,departments:r,branches:a,processTypes:i,processStatuses:d,cycles:c=[],users:p=[],userRoleMap:w={},formStatus:v,viewMode:f,canModify:g,onEdit:S,onDelete:k,onRestore:y,darkMode:m,notifCount:o,onToggleDark:u,onCountChange:h,onViewProfile:z,userRole:j,onRefreshProcess:b,onSubmit:x,onBack:I,onNavigate:E,onLogout:F,user:U}){var Ne;const N=ne(),$=L=>n({...e,...L}),P=f?{background:"#f9f9f9"}:{},D=s,Y=!!U.custom_organization,X=ye(l,e.management).map(L=>({name:L.name,label:L.name1||L.name})),q=ye(r,e.department).map(L=>({name:L.name,label:L.department_name||L.name})),J=ye(a,e.branch).map(L=>({name:L.name,label:L.branch||L.name})),W=ye(i,e.type).map(L=>({name:L.name,label:L.name1||L.name})),V=ye(c,e.cycle).map(L=>({name:L.name,label:L.name1||L.name})),de=Cl(p,w,"SB Employee",e.organization).map(L=>({name:L.name,label:L.full_name||L.name})),me=Cl(p,w,"SB Manager",e.organization).map(L=>({name:L.name,label:L.full_name||L.name})),le=(L,se)=>{const R=[...e.cycle_logs||[]];R[L]={...R[L],...se},$({cycle_logs:R})},Ve=()=>{$({cycle_logs:[...e.cycle_logs||[],{cycle:"",cycle_date:"",status:"Pass",actor:"",comment:""}]})},dt=L=>{const se=[...e.cycle_logs||[]];se.splice(L,1),$({cycle_logs:se})},Q=(L,se)=>{const R=[...e.progress_indicators||[]];R[L]={...R[L],...se},$({progress_indicators:R})},oe=()=>{$({progress_indicators:[...e.progress_indicators||[],{name1:"",type:"",unit:"",cycle:"",target:"",maximum:"",minimum:"",manager:"",order:"",actual_value:"",cycle_status:"Pass",cycle_date:"",cycle_comment:"",status:"Active"}]})},Oe=L=>{const se=[...e.progress_indicators||[]];se.splice(L,1),$({progress_indicators:se})},ve=e.name?f?`${N.formTitle.viewProcess}${e.title||e.name}`:N.formTitle.editProcess:N.formTitle.newProcess,nn=j!=="Manager"||e.actor===U.name,fe=((Ne=de.find(L=>L.name===e.actor))==null?void 0:Ne.label)||e.actor,je=e.workflow_state||"Draft",Et=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsx(N0,{processName:e.name,userRole:j||U.role||"Employee",onRefresh:b,canUpdateStatus:nn}),t.jsx(ii,{priority:e.impact_level,status:je,assignedTo:fe,createdDate:e.date_start,modifiedDate:e.modified}),t.jsx(di,{doctype:O.processes,docname:e.name,currentUserName:U.name}),t.jsx(ci,{doctype:O.processes,docname:e.name,docCreation:e.creation,docOwner:e.owner}),g&&k&&!e.custom_is_deleted&&t.jsx(ai,{title:"Delete Request",btnText:N.delete,onDelete:()=>k(e.name)})]}):void 0;return t.jsxs(Ze,{title:ve,activePage:"processes",user:U,formStatus:v,statusBadge:t.jsx("span",{style:{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},children:je}),buttonText:N.saveProcess,buttonColor:"#16a34a",viewMode:f,onEdit:S,darkMode:m,notifCount:o,onToggleDark:u,onCountChange:h,onViewProfile:z,rightPanel:Et,onSubmit:x,onBack:I,onNavigate:E,onLogout:F,children:[e.custom_is_deleted===1&&t.jsx(Ar,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:y?()=>y(e.name):void 0}),t.jsx(re,{title:"Process Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.number}),t.jsx("input",{style:{...A,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number||"",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[N.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:L=>$({organization:L}),organizations:D,disabled:f||Y})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.title}),t.jsx("input",{style:{...A,...P},value:e.title,disabled:f,onChange:L=>$({title:L.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.type}),t.jsx(pe,{value:e.type,onChange:L=>$({type:L}),items:W,placeholder:N.field.selectType,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.management}),t.jsx(pe,{value:e.management,onChange:L=>$({management:L}),items:X,placeholder:N.field.select,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.department}),t.jsx(pe,{value:e.department,onChange:L=>$({department:L}),items:q,placeholder:N.field.select,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.section}),t.jsx("input",{style:{...A,...P},value:e.section_field||"",disabled:f,onChange:L=>$({section_field:L.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.branch}),t.jsx(pe,{value:e.branch,onChange:L=>$({branch:L}),items:J,placeholder:N.field.select,disabled:f})]})]})}),t.jsxs(re,{title:"Classification",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.chainLocation}),t.jsxs("select",{style:{...A,...P},value:e.chain_location||"",disabled:f,onChange:L=>$({chain_location:L.target.value}),children:[t.jsx("option",{value:"",children:N.field.select}),t.jsx("option",{value:"Upstream",children:"Upstream"}),t.jsx("option",{value:"On-stream",children:"On-stream"}),t.jsx("option",{value:"Downstream",children:"Downstream"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.economyClass}),t.jsxs("select",{style:{...A,...P},value:e.economy_class||"",disabled:f,onChange:L=>$({economy_class:L.target.value}),children:[t.jsx("option",{value:"",children:N.field.select}),t.jsx("option",{value:"Expenses",children:N.field.expenses}),t.jsx("option",{value:"Capital",children:N.field.capital}),t.jsx("option",{value:"Earn",children:N.field.earn}),t.jsx("option",{value:"Pay/Loss",children:N.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.impactLevel}),t.jsxs("select",{style:{...A,...P},value:e.impact_level||"",disabled:f,onChange:L=>$({impact_level:L.target.value}),children:[t.jsx("option",{value:"",children:N.field.select}),t.jsx("option",{value:"High",children:N.field.high}),t.jsx("option",{value:"Normal",children:N.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.entityScope}),t.jsxs("select",{style:{...A,...P},value:e.entity_scope||"",disabled:f,onChange:L=>$({entity_scope:L.target.value}),children:[t.jsx("option",{value:"",children:N.field.select}),t.jsx("option",{value:"Upstream",children:N.field.upstream}),t.jsx("option",{value:"On-stream",children:N.field.onstream}),t.jsx("option",{value:"Downstream",children:N.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,alignItems:"center"},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.hsesField}),t.jsx("input",{style:{...A,...P},value:e.hses_field||"",disabled:f,onChange:L=>$({hses_field:L.target.value}),placeholder:"Safety, Health, Environment…"})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,paddingTop:18},children:t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:f,onChange:L=>$({product_relation:L.target.checked?1:0})})," ",N.field.productRelation]})})]})]}),t.jsxs(re,{title:"KPI & Timeline",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.kpiName}),t.jsx("input",{style:{...A,...P},value:e.kpi_name||"",disabled:f,onChange:L=>$({kpi_name:L.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.kpiType}),t.jsxs("select",{style:{...A,...P},value:e.kpi_type||"",disabled:f,onChange:L=>$({kpi_type:L.target.value}),children:[t.jsx("option",{value:"",children:N.field.select}),t.jsx("option",{value:"Human",children:"Human"}),t.jsx("option",{value:"Substantial",children:"Substantial"}),t.jsx("option",{value:"System",children:"System"}),t.jsx("option",{value:"Value",children:"Value"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.kpiMeasure}),t.jsx("input",{style:{...A,...P},value:e.kpi_measure||"",disabled:f,onChange:L=>$({kpi_measure:L.target.value}),placeholder:"Unit of measure"})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.dateStart}),t.jsx(xe,{value:e.date_start,onChange:L=>$({date_start:L}),disabled:f,style:{...A,...P}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.dateEnd}),t.jsx(xe,{value:e.date_end,onChange:L=>$({date_end:L}),disabled:f,style:{...A,...P}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.cycleType}),t.jsxs("select",{style:{...A,...P},value:e.cycle_type||"",disabled:f,onChange:L=>$({cycle_type:L.target.value}),children:[t.jsx("option",{value:"",children:N.field.select}),t.jsx("option",{value:"Normal",children:"Normal"}),t.jsx("option",{value:"Long",children:"Long"})]})]})]}),e.cycle_type==="Long"&&t.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14,marginTop:14},children:[t.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 1"}),t.jsx(xe,{value:e.long_cycle_date_1||"",onChange:L=>$({long_cycle_date_1:L}),disabled:f,style:{...A,...P}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 2"}),t.jsx(xe,{value:e.long_cycle_date_2||"",onChange:L=>$({long_cycle_date_2:L}),disabled:f,style:{...A,...P}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 3"}),t.jsx(xe,{value:e.long_cycle_date_3||"",onChange:L=>$({long_cycle_date_3:L}),disabled:f,style:{...A,...P}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Milestone 4"}),t.jsx(xe,{value:e.long_cycle_date_4||"",onChange:L=>$({long_cycle_date_4:L}),disabled:f,style:{...A,...P}})]})]})]})]}),t.jsxs(re,{title:"Progress Indicators",children:[t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:!f&&t.jsx("button",{type:"button",onClick:oe,style:{padding:"7px 14px",border:"none",background:"#2563eb",color:"white",borderRadius:6,fontWeight:600,fontSize:12,cursor:"pointer"},children:"+ Add Row"})}),t.jsx("div",{style:{overflowX:"auto",minWidth:0},children:t.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Order"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Name"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Type"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Unit"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Target"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Min"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Max"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Manager"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actual Value"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Status"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Date"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Comment"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Status"}),!f&&t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actions"})]})}),t.jsxs("tbody",{children:[(e.progress_indicators||[]).length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:f?14:15,style:{padding:18,textAlign:"center",color:"#94a3b8"},children:"No progress indicators"})}),(e.progress_indicators||[]).map((L,se)=>t.jsxs("tr",{style:{background:se%2===0?"white":"#fafafa",borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P,width:60},value:L.order??"",disabled:f,onChange:R=>Q(se,{order:R.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P},value:L.name1,disabled:f,onChange:R=>Q(se,{name1:R.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P},value:L.type,disabled:f,onChange:R=>Q(se,{type:R.target.value}),children:[t.jsx("option",{children:"Nominal"}),t.jsx("option",{children:"Ordinal"}),t.jsx("option",{children:"Interval"}),t.jsx("option",{children:"Ratio"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P,width:70},type:"text",value:L.unit??"",disabled:f,onChange:R=>Q(se,{unit:R.target.value}),placeholder:"e.g. °C, kg, %"})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P,minWidth:120},value:L.cycle,disabled:f,onChange:R=>Q(se,{cycle:R.target.value}),children:[t.jsx("option",{value:"",children:"--"}),V.map(R=>t.jsx("option",{value:R.name,children:R.label},R.name)),L.cycle&&!V.some(R=>R.name===L.cycle)&&t.jsx("option",{value:L.cycle,children:L.cycle})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P,width:80},value:L.target,disabled:f,onChange:R=>Q(se,{target:R.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P,width:80},value:L.minimum,disabled:f,onChange:R=>Q(se,{minimum:R.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P,width:80},value:L.maximum,disabled:f,onChange:R=>Q(se,{maximum:R.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P,minWidth:140},value:L.manager,disabled:f,onChange:R=>Q(se,{manager:R.target.value}),children:[t.jsx("option",{value:"",children:"--"}),me.map(R=>t.jsx("option",{value:R.name,children:R.label},R.name)),L.manager&&!me.some(R=>R.name===L.manager)&&t.jsx("option",{value:L.manager,children:L.manager})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P,width:90},type:"number",value:L.actual_value??"",disabled:f,onChange:R=>Q(se,{actual_value:parseFloat(R.target.value)||""})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P},value:L.cycle_status??"",disabled:f,onChange:R=>Q(se,{cycle_status:R.target.value}),children:[t.jsx("option",{value:"",children:"--"}),t.jsx("option",{children:"Normal"}),t.jsx("option",{children:"Below Min"}),t.jsx("option",{children:"Above Max"}),t.jsx("option",{children:"At Risk"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx(xe,{value:L.cycle_date||"",onChange:R=>Q(se,{cycle_date:R}),disabled:f,style:{...A,...P,width:110}})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P},value:L.cycle_comment??"",disabled:f,onChange:R=>Q(se,{cycle_comment:R.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P},value:L.status??"",disabled:f,onChange:R=>Q(se,{status:R.target.value}),children:[t.jsx("option",{value:"",children:"--"}),t.jsx("option",{children:"Normal"}),t.jsx("option",{children:"Below Min"}),t.jsx("option",{children:"Above Max"}),t.jsx("option",{children:"At Risk"})]})}),!f&&t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("button",{type:"button",onClick:()=>Oe(se),style:{padding:"4px 8px",border:"1px solid #fecaca",background:"#fef2f2",color:"#dc2626",borderRadius:4,cursor:"pointer",fontSize:11,fontWeight:600},children:"Remove"})})]},se))]})]})})]}),t.jsx(re,{title:"Cycle & Assignment",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.cycle}),t.jsx(pe,{value:e.cycle||"",onChange:L=>$({cycle:L}),items:V,placeholder:N.field.select,disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.actor}),t.jsxs("select",{style:{...A,...P},value:e.actor||"",disabled:f,onChange:L=>$({actor:L.target.value}),children:[t.jsx("option",{value:"",children:N.field.select}),de.map(L=>t.jsx("option",{value:L.name,children:L.label},L.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.costPerCycle}),t.jsx("input",{style:{...A,...P},type:"number",value:e.cost_per_cycle||"",disabled:f,onChange:L=>$({cost_per_cycle:parseFloat(L.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:N.field.escalationLevel}),t.jsx("input",{style:{...A,...P},type:"number",value:e.escalation_level||"",disabled:f,onChange:L=>$({escalation_level:parseInt(L.target.value)||0})})]})]})}),t.jsxs(re,{title:"Cycle History",children:[t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:!f&&t.jsx("button",{type:"button",onClick:Ve,style:{padding:"7px 14px",border:"none",background:"#2563eb",color:"white",borderRadius:6,fontWeight:600,fontSize:12,cursor:"pointer"},children:"+ Add Row"})}),t.jsx("div",{style:{overflowX:"auto",minWidth:0},children:t.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Date"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Status"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actor"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Comment"}),!f&&t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actions"})]})}),t.jsxs("tbody",{children:[(e.cycle_logs||[]).length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:f?5:6,style:{padding:18,textAlign:"center",color:"#94a3b8"},children:"No cycle history"})}),(e.cycle_logs||[]).map((L,se)=>t.jsxs("tr",{style:{background:se%2===0?"white":"#fafafa",borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P},value:L.cycle||"",disabled:f,onChange:R=>le(se,{cycle:R.target.value}),children:[t.jsx("option",{value:"",children:"-- Select --"}),V.map(R=>t.jsx("option",{value:R.name,children:R.label},R.name))]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx(xe,{value:L.cycle_date||"",onChange:R=>le(se,{cycle_date:R}),disabled:f,style:{...A,...P,width:130}})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P},value:L.status,disabled:f,onChange:R=>le(se,{status:R.target.value}),children:[t.jsx("option",{value:"Pass",children:"Pass"}),t.jsx("option",{value:"Fail",children:"Fail"}),t.jsx("option",{value:"Unknown",children:"Unknown"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...A,...P},value:L.actor||"",disabled:f,onChange:R=>le(se,{actor:R.target.value}),children:[t.jsx("option",{value:"",children:"-- Select --"}),de.map(R=>t.jsx("option",{value:R.name,children:R.label},R.name))]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...A,...P},value:L.comment||"",disabled:f,onChange:R=>le(se,{comment:R.target.value})})}),!f&&t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("button",{type:"button",onClick:()=>dt(se),style:{padding:"4px 8px",border:"1px solid #fecaca",background:"#fef2f2",color:"#dc2626",borderRadius:4,cursor:"pointer",fontSize:11,fontWeight:600},children:"Remove"})})]},se))]})]})})]}),t.jsx(re,{title:N.field.auditorComment,children:t.jsx("textarea",{style:{...A,height:70,resize:"vertical",background:"#f8fafc"},value:e.auditor_comment||"",disabled:!0,readOnly:!0,placeholder:N.field.commentPlaceholder})})]})}const B0={Admin:"#7c3aed",Auditor:"#d97706",Owner:"#0369a1",XAuditor:"#0f766e",Manager:"#2563eb",Employee:"#6b7280",Chairman:"#0f766e"};function $0({user:e,profileUser:n,darkMode:s,canModify:l,onBack:r,organizations:a=[],managements:i=[],departments:d=[],branches:c=[]}){const p=n||{},w=!!l&&e.role==="Admin",[v,f]=C.useState({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||""}),[g,S]=C.useState(""),[k,y]=C.useState(!1),[m,o]=C.useState({new:"",confirm:""}),[u,h]=C.useState(""),z=p.email||p.name||"",j=[v.first_name,v.middle_name,v.last_name].filter(Boolean).join(" ")||p.full_name||"",b=p.username||p.name||"",x=v.custom_category||"",I=p.enabled===0?"Inactive":"Active",E=B0[e.role]||"#6b7280",F=s,U=F?"#0f172a":"#f0f2f5",N=F?"#1e293b":"white",$=F?"#2d3748":"#e5e7eb",P=F?"#e2e8f0":"#1a2332",D=F?"#94a3b8":"#6b7280",Y=F?"#374151":"white",X=F?"#2d3748":"#f9fafb",q={width:"100%",padding:"9px 12px",borderRadius:8,border:`1px solid ${$}`,fontSize:13,background:Y,color:P,fontFamily:"inherit",outline:"none"},J={...q,background:X,color:D},W={...q,cursor:"pointer"},V={fontSize:12,fontWeight:600,color:D,marginBottom:5,display:"block"},de={display:"grid",gridTemplateColumns:"1fr 1fr",gap:14},me={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:14},le=async()=>{if(l){S("saving");try{await Ma("User",p.name,{first_name:v.first_name,middle_name:v.middle_name,last_name:v.last_name,mobile_no:v.mobile_no,custom_organization:v.custom_organization,custom_management:v.custom_management,custom_department:v.custom_department,custom_branch:v.custom_branch,custom_number:v.custom_number,custom_category:v.custom_category}),S("saved"),setTimeout(()=>S(""),2e3)}catch{S("error"),setTimeout(()=>S(""),3e3)}}},Ve=async()=>{if(!m.new){h("Enter a new password");return}if(m.new!==m.confirm){h("Passwords do not match");return}h("saving");try{await dh(p.name,m.new),h("done"),o({new:"",confirm:""}),setTimeout(()=>{h(""),y(!1)},2e3)}catch{h("error")}},dt=({title:Q,icon:oe,children:Oe})=>t.jsxs("div",{style:{background:N,borderRadius:12,padding:22,border:`1px solid ${$}`,boxShadow:`0 1px 4px rgba(0,0,0,${F?.3:.06})`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:18,paddingBottom:14,borderBottom:`1px solid ${$}`},children:[oe,t.jsx("span",{style:{fontSize:14,fontWeight:700,color:P},children:Q})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:14},children:Oe})]});return t.jsxs("div",{style:{background:U,minHeight:"100%",padding:"0 0 32px"},children:[t.jsxs("div",{style:{background:N,borderBottom:`1px solid ${$}`,padding:"12px 28px",display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[t.jsxs("button",{onClick:r,style:{display:"flex",alignItems:"center",gap:7,background:"none",border:"none",cursor:"pointer",fontSize:15,fontWeight:700,color:P,fontFamily:"inherit"},children:[t.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:t.jsx("polyline",{points:"15,18 9,12 15,6"})}),"User Profile"]}),l&&t.jsxs("button",{onClick:le,style:{display:"flex",alignItems:"center",gap:8,background:g==="saved"?"#16a34a":g==="error"?"#dc2626":"#16a34a",color:"white",border:"none",borderRadius:8,padding:"9px 22px",fontSize:13,fontWeight:700,cursor:"pointer",fontFamily:"inherit"},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),t.jsx("polyline",{points:"17,21 17,13 7,13 7,21"}),t.jsx("polyline",{points:"7,3 7,8 15,8"})]}),g==="saving"?"Saving…":g==="saved"?"Saved!":g==="error"?"Error":"Save Changes"]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"280px 1fr",gap:22,padding:"0 28px"},children:[t.jsxs("div",{style:{borderRadius:14,overflow:"hidden",boxShadow:"0 4px 20px rgba(0,0,0,0.12)",alignSelf:"start"},children:[t.jsxs("div",{style:{background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",padding:"32px 20px 28px",display:"flex",flexDirection:"column",alignItems:"center",gap:6},children:[t.jsx("div",{style:{width:78,height:78,borderRadius:"50%",background:"rgba(255,255,255,0.22)",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:4,border:"3px solid rgba(255,255,255,0.3)"},children:t.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"rgba(255,255,255,0.9)",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]})}),t.jsx("div",{style:{fontSize:17,fontWeight:700,color:"white",textAlign:"center",lineHeight:1.3},children:j||z}),t.jsx("div",{style:{fontSize:12,color:"rgba(255,255,255,0.75)",textAlign:"center"},children:z})]}),t.jsx("div",{style:{background:N},children:[{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:E,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),t.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),t.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),t.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),label:"Username",value:b},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:E,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),t.jsx("circle",{cx:"9",cy:"7",r:"4"}),t.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),t.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),label:"Role Profile",value:x||"—"},{icon:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:I==="Active"?"#16a34a":"#dc2626",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),label:"Status",value:I,valueColor:I==="Active"?"#16a34a":"#dc2626"},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:E,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),t.jsx("path",{d:"m2 7 10 7 10-7"})]}),label:"Email",value:z},{icon:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:E,strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 13a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.6 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})}),label:"Phone",value:v.mobile_no||"—"}].map(({icon:Q,label:oe,value:Oe,valueColor:ve})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 16px",borderBottom:`1px solid ${$}`},children:[t.jsx("div",{style:{flexShrink:0,width:18,display:"flex",justifyContent:"center"},children:Q}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,color:D,marginBottom:1},children:oe}),t.jsx("div",{style:{fontSize:13,fontWeight:600,color:ve||P,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Oe})]})]},oe))})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:18},children:[t.jsxs(dt,{title:"Basic Information",icon:t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]}),children:[t.jsxs("div",{style:de,children:[t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Email ",t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Read-only)"})]}),t.jsxs("div",{style:{position:"relative"},children:[t.jsx("div",{style:{position:"absolute",left:11,top:"50%",transform:"translateY(-50%)"},children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#94a3b8",strokeWidth:"2",children:[t.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),t.jsx("path",{d:"m2 7 10 7 10-7"})]})}),t.jsx("input",{style:{...J,paddingLeft:32},value:z,readOnly:!0})]})]}),t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Full Name ",t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Auto-generated)"})]}),t.jsx("input",{style:J,value:j,readOnly:!0})]})]}),t.jsxs("div",{style:me,children:[t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["First Name ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{style:l?q:J,value:v.first_name,readOnly:!l,onChange:Q=>f(oe=>({...oe,first_name:Q.target.value})),placeholder:"First name"})]}),t.jsxs("div",{children:[t.jsx("label",{style:V,children:"Middle Name"}),t.jsx("input",{style:l?q:J,value:v.middle_name,readOnly:!l,onChange:Q=>f(oe=>({...oe,middle_name:Q.target.value})),placeholder:"Middle name"})]}),t.jsxs("div",{children:[t.jsx("label",{style:V,children:"Last Name"}),t.jsx("input",{style:l?q:J,value:v.last_name,readOnly:!l,onChange:Q=>f(oe=>({...oe,last_name:Q.target.value})),placeholder:"Last name"})]})]}),t.jsxs("div",{style:de,children:[t.jsxs("div",{children:[t.jsx("label",{style:V,children:"Phone Number"}),t.jsx("input",{style:l?q:J,value:v.mobile_no,readOnly:!l,onChange:Q=>f(oe=>({...oe,mobile_no:Q.target.value})),placeholder:"Phone number"})]}),t.jsxs("div",{children:[t.jsx("label",{style:V,children:"User ID No"}),t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{style:{...J,paddingRight:44},value:v.custom_number||p.name||"",readOnly:!0}),t.jsx("div",{style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",background:"#ef4444",borderRadius:5,padding:"3px 7px",cursor:"default",display:"flex",alignItems:"center"},children:t.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"white",children:[t.jsx("circle",{cx:"5",cy:"12",r:"2"}),t.jsx("circle",{cx:"12",cy:"12",r:"2"}),t.jsx("circle",{cx:"19",cy:"12",r:"2"})]})})]})]})]}),t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Category ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:W,value:v.custom_category,onChange:Q=>f(oe=>({...oe,custom_category:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select category"}),["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"].map(Q=>t.jsx("option",{value:Q,children:Q},Q))]}):t.jsx("input",{style:J,value:x||"—",readOnly:!0})]})]}),t.jsxs(dt,{title:"Organization Information",icon:t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#8b5cf6",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),t.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),children:[t.jsxs("div",{style:de,children:[t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Organization ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:W,value:v.custom_organization,onChange:Q=>f(oe=>({...oe,custom_organization:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select organization"}),ye(a,v.custom_organization).map(Q=>t.jsx("option",{value:Q.name,children:Q.organization_name||Q.name},Q.name))]}):t.jsx("input",{style:J,value:v.custom_organization||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Management ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:W,value:v.custom_management,onChange:Q=>f(oe=>({...oe,custom_management:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select management"}),ye(i,v.custom_management).map(Q=>t.jsx("option",{value:Q.name,children:Q.name1||Q.name},Q.name))]}):t.jsx("input",{style:J,value:v.custom_management||"—",readOnly:!0})]})]}),t.jsxs("div",{style:de,children:[t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Department ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:W,value:v.custom_department,onChange:Q=>f(oe=>({...oe,custom_department:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select department"}),ye(d,v.custom_department).map(Q=>t.jsx("option",{value:Q.name,children:Q.department_name||Q.name},Q.name))]}):t.jsx("input",{style:J,value:v.custom_department||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Branch ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:W,value:v.custom_branch,onChange:Q=>f(oe=>({...oe,custom_branch:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select branch"}),ye(c,v.custom_branch).map(Q=>t.jsx("option",{value:Q.name,children:Q.branch||Q.name},Q.name))]}):t.jsx("input",{style:J,value:v.custom_branch||"—",readOnly:!0})]})]})]}),t.jsxs("div",{style:{background:N,borderRadius:12,padding:22,border:`1px solid ${$}`,boxShadow:`0 1px 4px rgba(0,0,0,${F?.3:.06})`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),t.jsx("span",{style:{fontSize:14,fontWeight:700,color:P},children:"Change Password"})]}),l&&t.jsx("button",{onClick:()=>{y(Q=>!Q),h("")},style:{fontSize:13,color:"#3b82f6",background:"none",border:"none",cursor:"pointer",fontWeight:600,fontFamily:"inherit"},children:k?"Cancel":"Change Password"})]}),k&&t.jsxs("div",{style:{marginTop:18,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:me,children:[t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["New Password ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"password",style:q,value:m.new,onChange:Q=>o(oe=>({...oe,new:Q.target.value})),placeholder:"New password"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:V,children:["Confirm Password ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"password",style:q,value:m.confirm,onChange:Q=>o(oe=>({...oe,confirm:Q.target.value})),placeholder:"Confirm password"})]}),t.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:t.jsx("button",{onClick:Ve,style:{width:"100%",padding:"9px 0",borderRadius:8,border:"none",background:"#2563eb",color:"white",fontWeight:700,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:u==="saving"?"Saving…":"Update Password"})})]}),u&&u!=="saving"&&t.jsx("div",{style:{fontSize:13,color:u==="done"?"#16a34a":"#dc2626",fontWeight:500},children:u==="done"?"Password updated successfully":u==="error"?"Failed to update password":u})]})]})]})]})]})}function Ie({label:e,val:n,color:s}){return t.jsxs("div",{style:{background:"white",borderRadius:8,padding:"8px 16px",flex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderTop:`3px solid ${s}`,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[t.jsx("div",{style:{fontSize:18,fontWeight:700,color:s},children:n}),t.jsx("div",{style:{fontSize:12,color:"#999"},children:e})]})}const ph={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151",boxSizing:"border-box"},U0={...ph,cursor:"pointer"};function vt({filters:e,defaultOpen:n=!1}){const[s,l]=C.useState(n);return t.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[t.jsxs("div",{onClick:()=>l(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:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:s?t.jsx("polyline",{points:"18,15 12,9 6,15"}):t.jsx("polyline",{points:"6,9 12,15 18,9"})}),t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),s&&t.jsx("div",{style:{padding:"18px 20px"},children:t.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(${Math.min(e.length,4)}, 1fr)`,gap:14},children:e.map((r,a)=>t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:r.label}),r.type==="search"?t.jsx("input",{style:ph,placeholder:r.placeholder,value:r.value,onChange:i=>r.onChange(i.target.value)}):t.jsx("select",{style:U0,value:r.value,onChange:i=>r.onChange(i.target.value),children:r.options.map(i=>t.jsx("option",{value:i.value,children:i.label},i.value))})]},a))})})]})}function F0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function M0({organizations:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),[f,g]=C.useState("all"),S={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},k=C.useMemo(()=>e.filter(h=>{const z=[h.organization_name,h.city].filter(Boolean).join(" ").toLowerCase();return!(c&&!z.includes(c.toLowerCase())||w!=="all"&&h.type!==w||f!=="all"&&(h.is_active?"Active":"Inactive")!==f)}),[e,c,w,f]),[y,m]=C.useState(1);C.useEffect(()=>{m(1)},[c,w,f]);const o=k.slice((y-1)*ae,y*ae),u=h=>{const z=e.filter(x=>i.has(x.name)),j=Me.organizations,b=j.columns.filter(x=>j.defaultColumns.includes(x.key));h==="csv"?He(b,z,"organizations_selected"):Ge(b,z,"organizations_selected")};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ie,{label:"Total",val:k.length,color:"#1a2332"}),t.jsx(Ie,{label:"Active",val:k.filter(h=>h.is_active).length,color:G.green}),t.jsx(Ie,{label:"Government",val:k.filter(h=>h.type==="Government").length,color:G.blue}),t.jsx(Ie,{label:"Private",val:k.filter(h=>h.type==="Private").length,color:G.orange})]}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Name or city…"},{type:"select",label:a.col.type,value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Government",label:"Government"},{value:"Private",label:"Private"}]},{type:"select",label:"Status",value:f,onChange:g,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:o.length>0&&o.every(h=>i.has(h.name)),onChange:h=>{if(h.target.checked)d(new Set([...i,...o.map(z=>z.name)]));else{const z=new Set(i);o.forEach(j=>z.delete(j.name)),d(z)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:S,children:a.col.name}),t.jsx("th",{style:S,children:a.col.type}),t.jsx("th",{style:S,children:a.col.city}),t.jsx("th",{style:S,children:a.field.creationDate}),t.jsx("th",{style:S,children:a.col.status}),t.jsx("th",{style:S,children:a.col.actions})]})}),t.jsx("tbody",{children:k.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):o.map((h,z)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(h),style:{borderTop:"1px solid #f0f0f0",background:i.has(h.name)?"#eff6ff":z%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:j=>j.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(h.name),onChange:()=>{const j=new Set(i);j.has(h.name)?j.delete(h.name):j.add(h.name),d(j)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:h.organization_name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:h.type||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:h.city||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:F0(h.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:Cr(h.is_active?a.field.statusActive:a.field.statusInactive,h.is_active?G.green:G.gray)}),t.jsx("td",{style:{padding:"8px 14px"},onClick:j=>j.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(h),onEdit:n&&l?()=>l(h):void 0,onDelete:n&&r?()=>r(h.name):void 0})})]},h.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:u}),t.jsx(qe,{page:y,total:k.length,onPageChange:m})]})}const bn=e=>({background:e?"#f9f9f9":void 0});function H0({orgForm:e,setOrgForm:n,groupCompanies:s=[],formStatus:l,viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,user:k}){const y=ne(),m=e.name?r&&e.organization_name||y.formTitle.editOrg:y.formTitle.newOrg,o=s.map(u=>({name:u.name,label:u.company_name?`${u.company_name} (${u.name})`:u.name}));return t.jsxs(Ze,{title:m,activePage:"organizations",user:k,formStatus:l,buttonText:y.saveOrg,buttonColor:"#16a34a",viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,children:[t.jsx(re,{title:"Organization Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.field.orgName," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{type:"text",style:{...A,...bn(r||!!e.name)},value:e.organization_name,disabled:r||!!e.name,required:!0,onChange:u=>n({...e,organization_name:u.target.value})})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.field.orgAcronym," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{type:"text",style:{...A,...bn(r||!!e.name)},value:e.acronym||"",disabled:r||!!e.name,required:!0,onChange:u=>n({...e,acronym:u.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Group Company (Tenant)"}),t.jsx(pe,{value:e.group_company||"",onChange:u=>n({...e,group_company:u}),items:o,placeholder:"Select Group Company",disabled:r||!!k.custom_group_company})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.organizationType}),t.jsxs("select",{style:{...A,...bn(r)},value:e.type,disabled:r,onChange:u=>n({...e,type:u.target.value}),children:[t.jsx("option",{children:"Government"}),t.jsx("option",{children:"Private"}),t.jsx("option",{children:"Non-Profit"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.orgCity}),t.jsx("input",{type:"text",style:{...A,...bn(r)},value:e.city,disabled:r,onChange:u=>n({...e,city:u.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.contactEmail}),t.jsx("input",{type:"email",style:{...A,...bn(r)},value:e.contact_email,disabled:r,onChange:u=>n({...e,contact_email:u.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>n({...e,creation_date:u}),disabled:r,style:{...A,...bn(r)}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.status}),t.jsxs("select",{style:{...A,...bn(r)},value:e.is_active?"Active":"Inactive",disabled:r,onChange:u=>n({...e,is_active:u.target.value==="Active"?1:0}),children:[t.jsx("option",{value:"Active",children:y.field.statusActive}),t.jsx("option",{value:"Inactive",children:y.field.statusInactive})]})]})]})}),t.jsx(re,{title:"Incident SLA Windows",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.incidentTriageWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...A,...bn(r)},value:e.incident_triage_window_days??3,disabled:r,onChange:u=>n({...e,incident_triage_window_days:parseInt(u.target.value)||3})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Days after creation before an untriaged Incident is flagged overdue"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.incidentResolutionWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...A,...bn(r)},value:e.incident_resolution_window_days??5,disabled:r,onChange:u=>n({...e,incident_resolution_window_days:parseInt(u.target.value)||5})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Days without an update before an in-progress Incident is flagged overdue"})]})]})})]})}function G0({groupCompanies:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=[o.company_name,o.acronym,o.code,o.owner_user].filter(Boolean).join(" ").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["group-companies"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"group_companies_selected"):Ge(z,u,"group_companies_selected")};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ie,{label:"Total Group Cos",val:g.length,color:"#1a2332"}),t.jsx(Ie,{label:"Active",val:g.filter(o=>(o.status||"Active")==="Active").length,color:G.green}),t.jsx(Ie,{label:"Inactive",val:g.filter(o=>o.status==="Inactive").length,color:G.orange})]}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Company name, code, owner…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Inactive",label:"Inactive"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{borderBottom:"1px solid #f0f0f0",background:"#fafafa"},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:"Company Name"}),t.jsx("th",{style:f,children:"Code / Acronym"}),t.jsx("th",{style:f,children:"Group Co Owner"}),t.jsx("th",{style:f,children:"Status"}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsxs("tbody",{children:[y.map((o,u)=>{const h=o.custom_is_deleted===1;return t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderBottom:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":h?"#fef2f2":u%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:z=>z.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const z=new Set(i);z.has(o.name)?z.delete(o.name):z.add(o.name),d(z)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsxs("td",{style:{padding:"12px 14px",fontWeight:600},children:[o.company_name,h&&t.jsx("span",{style:{marginLeft:8},children:Cr(a.deletedBadge,"#ef4444")})]}),t.jsx("td",{style:{padding:"12px 14px",color:"#555"},children:[o.code,o.acronym].filter(Boolean).join(" / ")||"—"}),t.jsx("td",{style:{padding:"12px 14px",color:"#555"},children:o.owner_user||"—"}),t.jsx("td",{style:{padding:"12px 14px"},children:Cr(o.status||"Active",(o.status||"Active")==="Active"?G.green:G.orange)}),t.jsx("td",{style:{padding:"12px 14px"},onClick:z=>z.stopPropagation(),children:t.jsx(at,{onView:s?()=>s(o):void 0,onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name)}),g.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:24,textAlign:"center",color:"#aaa"},children:"No Group Companies found"})})]})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function K0({form:e,setForm:n,users:s=[],formStatus:l,viewMode:r,onEdit:a,onRestore:i,darkMode:d,notifCount:c,onToggleDark:p,onCountChange:w,onViewProfile:v,onSubmit:f,onBack:g,onNavigate:S,onLogout:k,user:y}){const m=z=>n({...e,...z}),o=r?{background:"#f8fafc"}:{},u=e.name?r?`View Group Company: ${e.company_name}`:"Edit Group Company":"New Group Company",h=s.map(z=>({name:z.name,label:z.full_name?`${z.full_name} (${z.name})`:z.name}));return t.jsxs(Ze,{title:u,activePage:"group-companies",user:y,formStatus:l,buttonText:"Save Group Company",buttonColor:"#16a34a",viewMode:r,onEdit:a,darkMode:d,notifCount:c,onToggleDark:p,onCountChange:w,onViewProfile:v,onSubmit:f,onBack:g,onNavigate:S,onLogout:k,children:[e.custom_is_deleted===1&&t.jsx(Ar,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:i?()=>i(e.name):void 0}),t.jsxs(re,{title:"Group Company Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:["Company Name ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...o},value:e.company_name||"",disabled:r||!!e.name,onChange:z=>m({company_name:z.target.value}),placeholder:"e.g. Company A Group"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Company Code"}),t.jsx("input",{style:{...A,...o},value:e.code||"",disabled:r,onChange:z=>m({code:z.target.value}),placeholder:"e.g. CO-A"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Acronym"}),t.jsx("input",{style:{...A,...o},value:e.acronym||"",disabled:r,onChange:z=>m({acronym:z.target.value}),placeholder:"e.g. CAG"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Status"}),t.jsxs("select",{style:{...A,...o},value:e.status||"Active",disabled:r,onChange:z=>m({status:z.target.value}),children:[t.jsx("option",{value:"Active",children:"Active"}),t.jsx("option",{value:"Inactive",children:"Inactive"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Group Co Owner / Admin User"}),t.jsx(pe,{value:e.owner_user||"",onChange:z=>m({owner_user:z}),items:h,placeholder:"Select owner user",disabled:r})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Notes"}),t.jsx("textarea",{style:{...A,...o,height:75,resize:"vertical"},value:e.notes||"",disabled:r,onChange:z=>m({notes:z.target.value}),placeholder:"Additional details regarding this tenant company…"})]})]})]})}function Q0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function Y0({managements:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me.managements,z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"managements_selected"):Ge(z,u,"managements_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.blue})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:Q0(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function X0({form:e,setForm:n,organizations:s,formStatus:l,viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,user:k}){const y=ne(),m=h=>n(z=>({...z,...h})),o=r?{background:"#f8fafc"}:{},u=e.name?r?`${y.formTitle.editMgmt}: ${e.name1||e.name}`:y.formTitle.editMgmt:y.formTitle.newMgmt;return t.jsx(Ze,{title:u,activePage:"managements",user:k,formStatus:l,buttonText:y.saveMgmt,buttonColor:"#16a34a",viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,children:t.jsx(re,{title:"Management Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:h=>m({organization:h}),organizations:s,disabled:r||!!k.custom_organization})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...o},value:e.name1,disabled:r||!!e.name,onChange:h=>m({name1:h.target.value}),placeholder:"Management name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:h=>m({creation_date:h}),disabled:r,style:{...A,...o}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.status}),t.jsxs("select",{style:{...A,...o},value:e.status||"Active",disabled:r,onChange:h=>m({status:h.target.value}),children:[t.jsx("option",{value:"Active",children:y.field.statusActive}),t.jsx("option",{value:"Inactive",children:y.field.statusInactive})]})]})]})})})}function q0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function J0({departments:e,managements:n,canModify:s,onView:l,onEdit:r,onDelete:a}){const i=ne(),[d,c]=C.useState(new Set),[p,w]=C.useState(""),[v,f]=C.useState(""),[g,S]=C.useState("all"),k=j=>{var b;return((b=n.find(x=>x.name===j))==null?void 0:b.name1)||j||"—"},y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},m=C.useMemo(()=>e.filter(j=>{const b=(j.department_name||j.name||"").toLowerCase();return!(p&&!b.includes(p.toLowerCase())||v&&j.custom_management!==v||g!=="all"&&(j.custom_status||"Active")!==g)}),[e,p,v,g]),[o,u]=C.useState(1);C.useEffect(()=>{u(1)},[p,v,g]);const h=m.slice((o-1)*ae,o*ae),z=j=>{const b=e.filter(E=>d.has(E.name)),x=Me.departments,I=x.columns.filter(E=>x.defaultColumns.includes(E.key));j==="csv"?He(I,b,"departments_selected"):Ge(I,b,"departments_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:m.length,color:G.teal})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:p,onChange:w,placeholder:"Search by name…"},{type:"select",label:i.col.management,value:v,onChange:f,options:[{value:"",label:"All Managements"},...n.map(j=>({value:j.name,label:j.name1||j.name}))]},{type:"select",label:"Status",value:g,onChange:S,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:h.length>0&&h.every(j=>d.has(j.name)),onChange:j=>{if(j.target.checked)c(new Set([...d,...h.map(b=>b.name)]));else{const b=new Set(d);h.forEach(x=>b.delete(x.name)),c(b)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:y,children:i.col.name}),t.jsx("th",{style:y,children:i.col.management}),t.jsx("th",{style:y,children:i.field.creationDate}),t.jsx("th",{style:y,children:i.field.status}),t.jsx("th",{style:y,children:i.col.actions})]})}),t.jsx("tbody",{children:m.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):h.map((j,b)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>l==null?void 0:l(j),style:{borderTop:"1px solid #f0f0f0",background:d.has(j.name)?"#eff6ff":b%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(j.name),onChange:()=>{const x=new Set(d);x.has(j.name)?x.delete(j.name):x.add(j.name),c(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:j.department_name||j.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:k(j.custom_management)}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:q0(j.custom_creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:j.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:j.custom_status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(at,{onView:()=>l==null?void 0:l(j),onEdit:s&&r?()=>r(j):void 0,onDelete:s&&a?()=>a(j.name):void 0})})]},j.name))})]})}),t.jsx(Je,{count:d.size,onClear:()=>c(new Set),onExport:z}),t.jsx(qe,{page:o,total:m.length,onPageChange:u})]})}function Z0({form:e,setForm:n,organizations:s,managements:l,formStatus:r,viewMode:a,onEdit:i,darkMode:d,notifCount:c,onToggleDark:p,onCountChange:w,onViewProfile:v,onSubmit:f,onBack:g,onNavigate:S,onLogout:k,user:y}){const m=ne(),o=j=>n(b=>({...b,...j})),u=a?{background:"#f8fafc"}:{},h=e.name?a?`${m.formTitle.editDept}: ${e.department_name||e.name}`:m.formTitle.editDept:m.formTitle.newDept,z=ye(l,e.custom_management).map(j=>({name:j.name,label:j.name1||j.name}));return t.jsx(Ze,{title:h,activePage:"departments",user:y,formStatus:r,buttonText:m.saveDept,buttonColor:"#16a34a",viewMode:a,onEdit:i,darkMode:d,notifCount:c,onToggleDark:p,onCountChange:w,onViewProfile:v,onSubmit:f,onBack:g,onNavigate:S,onLogout:k,children:t.jsx(re,{title:"Department Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[m.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.custom_organization,onChange:j=>o({custom_organization:j}),organizations:s,disabled:a||!!y.custom_organization})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[m.field.department," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...u},value:e.department_name,disabled:a||!!e.name,onChange:j=>o({department_name:j.target.value}),placeholder:"Department name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:m.field.management}),t.jsx(pe,{value:e.custom_management,onChange:j=>o({custom_management:j}),items:z,placeholder:m.field.select,disabled:a})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:m.field.creationDate}),t.jsx(xe,{value:e.custom_creation_date||"",onChange:j=>o({custom_creation_date:j}),disabled:a,style:{...A,...u}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:m.field.status}),t.jsxs("select",{style:{...A,...u},value:e.custom_status||"Active",disabled:a,onChange:j=>o({custom_status:j.target.value}),children:[t.jsx("option",{value:"Active",children:m.field.statusActive}),t.jsx("option",{value:"Inactive",children:m.field.statusInactive})]})]})]})})})}function V0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function e1({branches:e,managements:n,departments:s,canModify:l,onView:r,onEdit:a,onDelete:i}){const d=ne(),[c,p]=C.useState(new Set),[w,v]=C.useState(""),[f,g]=C.useState(""),[S,k]=C.useState(""),[y,m]=C.useState("all"),o=E=>{var F;return((F=n.find(U=>U.name===E))==null?void 0:F.name1)||E||"—"},u=E=>{var F;return((F=s.find(U=>U.name===E))==null?void 0:F.department_name)||E||"—"},h={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},z=C.useMemo(()=>e.filter(E=>{const F=(E.branch||E.name||"").toLowerCase();return!(w&&!F.includes(w.toLowerCase())||f&&E.management!==f||S&&E.department!==S||y!=="all"&&(E.custom_status||"Active")!==y)}),[e,w,f,S,y]),[j,b]=C.useState(1);C.useEffect(()=>{b(1)},[w,f,S,y]);const x=z.slice((j-1)*ae,j*ae),I=E=>{const F=e.filter($=>c.has($.name)),U=Me.branches,N=U.columns.filter($=>U.defaultColumns.includes($.key));E==="csv"?He(N,F,"branches_selected"):Ge(N,F,"branches_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:z.length,color:G.purple})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:w,onChange:v,placeholder:"Search by name…"},{type:"select",label:d.col.management,value:f,onChange:g,options:[{value:"",label:"All Managements"},...n.map(E=>({value:E.name,label:E.name1||E.name}))]},{type:"select",label:d.col.department,value:S,onChange:k,options:[{value:"",label:"All Departments"},...s.map(E=>({value:E.name,label:E.department_name||E.name}))]},{type:"select",label:"Status",value:y,onChange:m,options:[{value:"all",label:"All"},{value:"Active",label:d.field.statusActive},{value:"Inactive",label:d.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:x.length>0&&x.every(E=>c.has(E.name)),onChange:E=>{if(E.target.checked)p(new Set([...c,...x.map(F=>F.name)]));else{const F=new Set(c);x.forEach(U=>F.delete(U.name)),p(F)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:h,children:d.col.branch}),t.jsx("th",{style:h,children:d.col.management}),t.jsx("th",{style:h,children:d.col.department}),t.jsx("th",{style:h,children:d.field.creationDate}),t.jsx("th",{style:h,children:d.field.status}),t.jsx("th",{style:h,children:d.col.actions})]})}),t.jsx("tbody",{children:z.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:d.noData})}):x.map((E,F)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>r==null?void 0:r(E),style:{borderTop:"1px solid #f0f0f0",background:c.has(E.name)?"#eff6ff":F%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:U=>U.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:c.has(E.name),onChange:()=>{const U=new Set(c);U.has(E.name)?U.delete(E.name):U.add(E.name),p(U)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:E.branch||E.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o(E.management)}),t.jsx("td",{style:{padding:"10px 14px"},children:u(E.department)}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:V0(E.custom_creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:E.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:E.custom_status==="Inactive"?d.field.statusInactive:d.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:U=>U.stopPropagation(),children:t.jsx(at,{onView:()=>r==null?void 0:r(E),onEdit:l&&a?()=>a(E):void 0,onDelete:l&&i?()=>i(E.name):void 0})})]},E.name))})]})}),t.jsx(Je,{count:c.size,onClear:()=>p(new Set),onExport:I}),t.jsx(qe,{page:j,total:z.length,onPageChange:b})]})}function t1({form:e,setForm:n,organizations:s,managements:l,departments:r,formStatus:a,viewMode:i,onEdit:d,darkMode:c,notifCount:p,onToggleDark:w,onCountChange:v,onViewProfile:f,onSubmit:g,onBack:S,onNavigate:k,onLogout:y,user:m}){const o=ne(),u=x=>n(I=>({...I,...x})),h=i?{background:"#f8fafc"}:{},z=e.name?i?`${o.formTitle.editBranch}: ${e.branch||e.name}`:o.formTitle.editBranch:o.formTitle.newBranch,j=ye(l,e.management).map(x=>({name:x.name,label:x.name1||x.name})),b=ye(r,e.department).map(x=>({name:x.name,label:x.department_name||x.name}));return t.jsx(Ze,{title:z,activePage:"branches",user:m,formStatus:a,buttonText:o.saveBranch,buttonColor:"#16a34a",viewMode:i,onEdit:d,darkMode:c,notifCount:p,onToggleDark:w,onCountChange:v,onViewProfile:f,onSubmit:g,onBack:S,onNavigate:k,onLogout:y,children:t.jsx(re,{title:"Branch Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[o.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:x=>u({organization:x}),organizations:s,disabled:i||!!m.custom_organization})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[o.field.branch," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...h},value:e.branch,disabled:i||!!e.name,onChange:x=>u({branch:x.target.value}),placeholder:"Branch name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:o.field.management}),t.jsx(pe,{value:e.management,onChange:x=>u({management:x}),items:j,placeholder:o.field.select,disabled:i})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:o.field.department}),t.jsx(pe,{value:e.department,onChange:x=>u({department:x}),items:b,placeholder:o.field.select,disabled:i})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:o.field.creationDate}),t.jsx(xe,{value:e.custom_creation_date||"",onChange:x=>u({custom_creation_date:x}),disabled:i,style:{...A,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:o.field.status}),t.jsxs("select",{style:{...A,...h},value:e.custom_status||"Active",disabled:i,onChange:x=>u({custom_status:x.target.value}),children:[t.jsx("option",{value:"Active",children:o.field.statusActive}),t.jsx("option",{value:"Inactive",children:o.field.statusInactive})]})]})]})})})}function n1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function s1({incidentTypes:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["incident-types"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"incident_types_selected"):Ge(z,u,"incident_types_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.red})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:n1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function l1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Incident Type: ${e.name1||e.name}`:"Edit Incident Type":"New Incident Type";return t.jsx(Ze,{title:o,activePage:"incident-types",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsx(re,{title:"Incident Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Incident type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]})})})}function r1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function a1({ideaTypes:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["idea-types"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"idea_types_selected"):Ge(z,u,"idea_types_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.teal})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:r1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function i1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Idea Type: ${e.name1||e.name}`:"Edit Idea Type":"New Idea Type";return t.jsx(Ze,{title:o,activePage:"idea-types",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsx(re,{title:"Idea Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Idea type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]})})})}function o1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function d1({orderTypes:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["order-types"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"order_types_selected"):Ge(z,u,"order_types_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.purple})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:o1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function c1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Order Type: ${e.name1||e.name}`:"Edit Order Type":"New Order Type";return t.jsx(Ze,{title:o,activePage:"order-types",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsx(re,{title:"Order Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Order type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]})})})}function u1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function p1({processTypes:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["process-types"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"process_types_selected"):Ge(z,u,"process_types_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.blue})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:u1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function f1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Process Type: ${e.name1||e.name}`:"Edit Process Type":"New Process Type";return t.jsx(Ze,{title:o,activePage:"process-types",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsx(re,{title:"Process Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Process type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]})})})}function h1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function g1({incidentStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["incident-statuses"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"incident_statuses_selected"):Ge(z,u,"incident_statuses_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.red})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.notifyManager}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?a.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:h1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function x1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Incident Status: ${e.name1||e.name}`:"Edit Incident Status":"New Incident Status";return t.jsx(Ze,{title:o,activePage:"incident-statuses",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsxs(re,{title:"Incident Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Incident status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:u=>y({notify_manager:u.target.checked?1:0}),style:zl}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:k.field.notifyManager})]})]})})}function m1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function y1({ideaStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["idea-statuses"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"idea_statuses_selected"):Ge(z,u,"idea_statuses_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.teal})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.notifyManager}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?a.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:m1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function v1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Idea Status: ${e.name1||e.name}`:"Edit Idea Status":"New Idea Status";return t.jsx(Ze,{title:o,activePage:"idea-statuses",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsxs(re,{title:"Idea Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Idea status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:u=>y({notify_manager:u.target.checked?1:0}),style:zl}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:k.field.notifyManager})]})]})})}function j1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function b1({orderStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["order-statuses"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"order_statuses_selected"):Ge(z,u,"order_statuses_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.purple})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.notifyManager}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?a.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:j1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function S1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Order Status: ${e.name1||e.name}`:"Edit Order Status":"New Order Status";return t.jsx(Ze,{title:o,activePage:"order-statuses",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsxs(re,{title:"Order Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Order status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:u=>y({notify_manager:u.target.checked?1:0}),style:zl}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:k.field.notifyManager})]})]})})}function w1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function k1({processStatuses:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState("all"),f={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=C.useMemo(()=>e.filter(o=>{const u=(o.name1||o.name||"").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w!=="all"&&(o.status||"Active")!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["process-statuses"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"process_statuses_selected"):Ge(z,u,"process_statuses_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total",val:g.length,color:G.blue})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:"Status",value:w,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:f,children:a.col.name}),t.jsx("th",{style:f,children:a.field.notifyManager}),t.jsx("th",{style:f,children:a.field.creationDate}),t.jsx("th",{style:f,children:a.field.status}),t.jsx("th",{style:f,children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?a.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:w1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function _1({form:e,setForm:n,formStatus:s,viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,user:S}){const k=ne(),y=u=>n(h=>({...h,...u})),m=l?{background:"#f8fafc"}:{},o=e.name?l?`Process Status: ${e.name1||e.name}`:"Edit Process Status":"New Process Status";return t.jsx(Ze,{title:o,activePage:"process-statuses",user:S,formStatus:s,buttonText:k.saveName,buttonColor:"#16a34a",viewMode:l,onEdit:r,darkMode:a,notifCount:i,onToggleDark:d,onCountChange:c,onViewProfile:p,onSubmit:w,onBack:v,onNavigate:f,onLogout:g,children:t.jsxs(re,{title:"Process Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[k.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...m},value:e.name1,disabled:l||!!e.name,onChange:u=>y({name1:u.target.value}),placeholder:"Process status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.creationDate}),t.jsx(xe,{value:e.creation_date||"",onChange:u=>y({creation_date:u}),disabled:l,style:{...A,...m}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:k.field.status}),t.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:l,onChange:u=>y({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:k.field.statusActive}),t.jsx("option",{value:"Inactive",children:k.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:l,onChange:u=>y({notify_manager:u.target.checked?1:0}),style:zl}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:l?"default":"pointer"},children:k.field.notifyManager})]})]})})}const C1={Admin:"#7c3aed",Chairman:"#0f766e",Auditor:"#d97706","X-Auditor":"#8b5cf6",Manager:"#2563eb",Employee:"#6b7280"};function z1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function I1({users:e,canModify:n,onView:s,onEdit:l,onDisable:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(!1),[w,v]=C.useState(""),[f,g]=C.useState(""),[S,k]=C.useState(""),[y,m]=C.useState("active"),[o,u]=C.useState(1),[h,z]=C.useState(null),[j,b]=C.useState(""),[x,I]=C.useState("idle"),[E,F]=C.useState(null),U=async()=>{if(!(!h||!j.trim())){I("loading");try{await dh(h.name,j.trim()),I("success"),setTimeout(()=>{z(null),b(""),I("idle")},1200)}catch{I("error")}}},N=async W=>{if(window.confirm(a.users.disableConfirm)){F(W);try{await(r==null?void 0:r(W))}finally{F(null)}}},$=e.filter(W=>{if(y==="active"&&(W.enabled===0||W.enabled==="0")||y==="inactive"&&W.enabled!==0&&W.enabled!=="0")return!1;const V=W.custom_category||"";if(S&&V!==S)return!1;const de=W.custom_organization||"";if(f&&!de.toLowerCase().includes(f.toLowerCase()))return!1;if(w){const me=w.toLowerCase();if(![W.full_name,W.email,W.name,W.username,W.mobile_no].join(" ").toLowerCase().includes(me))return!1}return!0}),P=[...new Set(e.map(W=>W.custom_organization).filter(Boolean))],D=["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"];C.useEffect(()=>{u(1)},[w,f,S,y]);const Y=$.slice((o-1)*ae,o*ae),X={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151"},q={...X,cursor:"pointer"},J=W=>{const V=$.filter(le=>i.has(le.name)),de=Me.users,me=de.columns.filter(le=>de.defaultColumns.includes(le.key));W==="csv"?He(me,V,"users_selected"):Ge(me,V,"users_selected")};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,flex:1},children:[t.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[t.jsxs("div",{onClick:()=>p(W=>!W),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:c?t.jsx("polyline",{points:"18,15 12,9 6,15"}):t.jsx("polyline",{points:"6,9 12,15 18,9"})}),t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),c&&t.jsxs("div",{style:{padding:"18px 20px",display:"flex",flexDirection:"column",gap:14},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:14},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Search"}),t.jsx("input",{style:X,placeholder:"Name, email, username…",value:w,onChange:W=>{v(W.target.value),u(1)}})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Organization"}),t.jsxs("select",{style:q,value:f,onChange:W=>{g(W.target.value),u(1)},children:[t.jsx("option",{value:"",children:"All Organizations"}),P.map(W=>t.jsx("option",{value:W,children:W},W))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Category"}),t.jsxs("select",{style:q,value:S,onChange:W=>{k(W.target.value),u(1)},children:[t.jsx("option",{value:"",children:"All Categories"}),D.map(W=>t.jsx("option",{value:W,children:W},W))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Status"}),t.jsxs("select",{style:q,value:y,onChange:W=>{m(W.target.value),u(1)},children:[t.jsx("option",{value:"all",children:"All"}),t.jsx("option",{value:"active",children:"Active"}),t.jsx("option",{value:"inactive",children:"Inactive"})]})]})]}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{type:"button",onClick:()=>{g(""),k(""),m("active"),v(""),u(1)},style:{padding:"7px 16px",background:"#f3f4f6",color:"#374151",border:"1px solid #d1d5db",borderRadius:6,cursor:"pointer",fontSize:12,fontWeight:600},children:"Clear Filters"})})]})]}),t.jsx("div",{style:{background:"white",borderRadius:10,border:"1px solid #e5e7eb",overflow:"auto",flex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.05)"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f9fafb",borderBottom:"2px solid #e5e7eb",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"11px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:Y.length>0&&Y.every(W=>i.has(W.name)),onChange:W=>{if(W.target.checked)d(new Set([...i,...Y.map(V=>V.name)]));else{const V=new Set(i);Y.forEach(de=>V.delete(de.name)),d(V)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),[{label:"Category",w:110},{label:"Number",w:90},{label:a.col.name,w:160},{label:"Username",w:130},{label:"Email",w:180},{label:"Phone",w:110},{label:a.col.organization,w:140},{label:a.col.management,w:120},{label:a.col.department,w:120},{label:"Branch",w:100},{label:"Since",w:90},{label:"Status",w:80},{label:"Tools",w:200}].map(({label:W,w:V})=>t.jsx("th",{style:{padding:"11px 14px",textAlign:"left",color:"#6b7280",fontSize:11,fontWeight:700,whiteSpace:"nowrap",minWidth:V,letterSpacing:.3,textTransform:"uppercase"},children:W},W))]})}),t.jsx("tbody",{children:$.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:14,style:{padding:"48px 20px",textAlign:"center",color:"#aaa",fontSize:14},children:"No users found"})}):Y.map((W,V)=>{const de=W.custom_category||"",me=C1[de]||"#6b7280";return t.jsxs("tr",{onClick:()=>s==null?void 0:s(W),style:{borderBottom:"1px solid #f3f4f6",background:i.has(W.name)?"#eff6ff":V%2===0?"white":"#fafafa",transition:"background 0.1s",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"11px 14px",textAlign:"center"},onClick:le=>le.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(W.name),onChange:()=>{const le=new Set(i);le.has(W.name)?le.delete(W.name):le.add(W.name),d(le)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:de?t.jsx("span",{style:{background:me+"18",color:me,border:`1px solid ${me}44`,padding:"3px 10px",borderRadius:20,fontSize:11,fontWeight:700},children:de}):t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:W.custom_number||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",fontWeight:600,color:"#1a2332",whiteSpace:"nowrap"},children:W.full_name||W.first_name||"—"}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:W.username||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:W.email||W.name}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:W.mobile_no||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:W.custom_organization||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:W.custom_management||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:W.custom_department||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:W.custom_branch||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:z1(W.creation)}),t.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:t.jsx("span",{style:{color:W.enabled?"#16a34a":"#dc2626",fontWeight:600},children:W.enabled?a.users.active:a.users.inactive})}),t.jsx("td",{style:{padding:"10px 14px",whiteSpace:"nowrap"},onClick:le=>le.stopPropagation(),children:t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[t.jsx("button",{onClick:le=>{le.stopPropagation(),s==null||s(W)},title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),n&&l&&t.jsx("button",{onClick:le=>{le.stopPropagation(),l(W)},title:"Edit",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#dcfce7",color:"#16a34a"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),n&&t.jsx("button",{onClick:le=>{le.stopPropagation(),z({name:W.name,email:W.email||W.name}),b(""),I("idle")},title:"Set Password",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#fef3c7",color:"#d97706"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),n&&t.jsx("button",{onClick:le=>{le.stopPropagation(),N(W.name)},disabled:E===W.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:E===W.name?.5:1},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"}),t.jsx("path",{d:"M10 11v6M14 11v6"}),t.jsx("path",{d:"M9 6V4h6v2"})]})})]})})]},W.name)})})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:J}),t.jsx(qe,{page:o,total:$.length,onPageChange:u}),h&&t.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center"},children:t.jsxs("div",{style:{background:"white",borderRadius:14,padding:32,width:390,boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[t.jsx("div",{style:{fontSize:17,fontWeight:700,marginBottom:6,color:"#1a2332"},children:a.users.setPassword}),t.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:20},children:["User: ",t.jsx("strong",{children:h.email})]}),t.jsx("input",{type:"password",value:j,onChange:W=>b(W.target.value),placeholder:a.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:W=>W.key==="Enter"&&U(),autoFocus:!0}),x==="success"&&t.jsx("div",{style:{color:"#166534",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Password updated successfully"}),x==="error"&&t.jsx("div",{style:{color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Failed to update password"}),t.jsxs("div",{style:{display:"flex",gap:10},children:[t.jsx("button",{onClick:U,disabled:x==="loading"||!j.trim(),style:{flex:1,padding:10,background:"#2563eb",color:"white",border:"none",borderRadius:8,cursor:"pointer",fontSize:13,fontWeight:700,fontFamily:"inherit",opacity:j.trim()?1:.5},children:x==="loading"?"Saving…":a.users.setPassword}),t.jsx("button",{onClick:()=>{z(null),b(""),I("idle")},style:{flex:1,padding:10,background:"#f5f5f5",color:"#374151",border:"1px solid #e5e7eb",borderRadius:8,cursor:"pointer",fontSize:13,fontFamily:"inherit"},children:a.cancel})]})]})})]})}function E1({form:e,setForm:n,groupCompanies:s=[],organizations:l,managements:r,departments:a,branches:i,formStatus:d,viewMode:c,onEdit:p,darkMode:w,notifCount:v,onToggleDark:f,onCountChange:g,onViewProfile:S,isSelfProfile:k,onSubmit:y,onBack:m,onNavigate:o,onLogout:u,user:h}){const z=ne(),j=$=>n(P=>({...P,...$})),b=c?{background:"#f8fafc"}:{},x=!e.name,I=k?"My Profile":x?"New User":c?`User: ${e.full_name||e.email}`:`Edit User: ${e.full_name||e.email}`,E=s.map($=>({name:$.name,label:$.company_name?`${$.company_name} (${$.name})`:$.name})),F=ye(r,e.custom_management).map($=>({name:$.name,label:$.name1||$.name})),U=ye(a,e.custom_department).map($=>({name:$.name,label:$.department_name||$.name})),N=ye(i,e.custom_branch).map($=>({name:$.name,label:$.branch||$.name}));return t.jsxs(Ze,{title:I,activePage:"users",user:h,formStatus:d,buttonText:z.saveUser,buttonColor:"#16a34a",viewMode:c,onEdit:p,darkMode:w,notifCount:v,onToggleDark:f,onCountChange:g,onViewProfile:S,hideSettings:k,onSubmit:y,onBack:m,onNavigate:o,onLogout:u,children:[t.jsx(re,{title:"User Organization & Assignment",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:"Group Company (Tenant)"}),t.jsx(pe,{value:e.custom_group_company||"",onChange:$=>j({custom_group_company:$}),items:E,placeholder:"-- Select Group Company --",disabled:c||!!h.custom_group_company})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.organization}),t.jsx(Gt,{value:e.custom_organization,onChange:$=>j({custom_organization:$}),organizations:l,disabled:c})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.management}),t.jsx(pe,{value:e.custom_management,onChange:$=>j({custom_management:$}),items:F,placeholder:"-- Select --",disabled:c})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.department}),t.jsx(pe,{value:e.custom_department,onChange:$=>j({custom_department:$}),items:U,placeholder:"-- Select --",disabled:c})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.branch}),t.jsx(pe,{value:e.custom_branch,onChange:$=>j({custom_branch:$}),items:N,placeholder:"-- Select --",disabled:c})]})]})}),t.jsx(re,{title:"User Profile Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.number}),t.jsx("input",{style:{...A,...b},value:e.custom_number,disabled:c,onChange:$=>j({custom_number:$.target.value}),placeholder:"e.g. 10001"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[z.field.fullName," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...b},value:e.first_name,disabled:c,onChange:$=>j({first_name:$.target.value}),placeholder:"Full name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.username}),t.jsx("input",{style:{...A,...b},value:e.username,disabled:c,onChange:$=>j({username:$.target.value}),placeholder:"Username"})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.phoneNumber}),t.jsx("input",{style:{...A,...b},value:e.mobile_no,disabled:c,onChange:$=>j({mobile_no:$.target.value}),placeholder:"Phone number"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[z.field.emailAddress," ",x&&t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...c||!x?{background:"#f8fafc"}:{}},value:e.email,disabled:c||!x,onChange:$=>j({email:$.target.value}),placeholder:"user@example.com",type:"email",required:x})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:z.field.category}),t.jsxs("select",{style:{...A,...b},value:e.custom_category,disabled:c,onChange:$=>j({custom_category:$.target.value}),children:[t.jsx("option",{value:"",children:z.field.select}),t.jsx("option",{children:"Admin"}),t.jsx("option",{children:"Chairman"}),t.jsx("option",{children:"Auditor"}),t.jsx("option",{children:"X-Auditor"}),t.jsx("option",{children:"Manager"}),t.jsx("option",{children:"Employee"})]})]})]})})]})}const Lu={Active:G.green,Closed:G.gray};function T1({cycles:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState(""),[f,g]=C.useState("all"),S=C.useMemo(()=>[...new Set(e.map(j=>j.organization).filter(Boolean))],[e]),k=C.useMemo(()=>e.filter(j=>{const b=(j.name1||j.name||"").toLowerCase();return!(c&&!b.includes(c.toLowerCase())||w&&j.organization!==w||f!=="all"&&j.status!==f)}),[e,c,w,f]),[y,m]=C.useState(1);C.useEffect(()=>{m(1)},[c,w,f]);const o=k.slice((y-1)*ae,y*ae),u=j=>{const b=e.filter(E=>i.has(E.name)),x=Me.cycles,I=x.columns.filter(E=>x.defaultColumns.includes(E.key));j==="csv"?He(I,b,"cycles_selected"):Ge(I,b,"cycles_selected")},h=k.filter(j=>j.status==="Active").length,z=k.filter(j=>j.status==="Closed").length;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ie,{label:"Total",val:k.length,color:G.teal}),t.jsx(Ie,{label:"Active",val:h,color:G.green}),t.jsx(Ie,{label:"Closed",val:z,color:G.gray})]}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Search by name…"},{type:"select",label:a.col.organization,value:w,onChange:v,options:[{value:"",label:"All Organizations"},...S.map(j=>({value:j,label:j}))]},{type:"select",label:"Status",value:f,onChange:g,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Closed",label:"Closed"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:o.length>0&&o.every(j=>i.has(j.name)),onChange:j=>{if(j.target.checked)d(new Set([...i,...o.map(b=>b.name)]));else{const b=new Set(i);o.forEach(x=>b.delete(x.name)),d(b)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.name}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.organization}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.frequency}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.startDate}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.endDate}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.status}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.actions})]})}),t.jsx("tbody",{children:k.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:8,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):o.map((j,b)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(j),style:{borderTop:"1px solid #f0f0f0",background:i.has(j.name)?"#eff6ff":b%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(j.name),onChange:()=>{const x=new Set(i);x.has(j.name)?x.delete(j.name):x.add(j.name),d(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:j.name1||j.name}),t.jsx("td",{style:{padding:"10px 14px"},children:j.organization||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:j.frequency||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:j.start_date||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:j.end_date||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{padding:"3px 10px",borderRadius:12,fontSize:12,background:Lu[j.status]+"22",color:Lu[j.status]||"#666"},children:j.status})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(j),onEdit:n&&l?()=>l(j):void 0,onDelete:n&&r?()=>r(j.name):void 0})})]},j.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:u}),t.jsx(qe,{page:y,total:k.length,onPageChange:m})]})}const P1=["Weekly","Bi-weekly","Monthly","Quarterly","Annually"],A1=["Active","Closed"];function R1({form:e,setForm:n,organizations:s,formStatus:l,viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,user:k}){const y=ne(),m=h=>n(z=>({...z,...h})),o=r?{background:"#f8fafc"}:{},u=e.name?r?`${y.formTitle.editCycle}: ${e.name1||e.name}`:y.formTitle.editCycle:y.formTitle.newCycle;return t.jsx(Ze,{title:u,activePage:"cycles",user:k,formStatus:l,buttonText:y.saveCycle,buttonColor:"#16a34a",viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,children:t.jsx(re,{title:"Cycle Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...o},value:e.name1||"",disabled:r||!!e.name,onChange:h=>m({name1:h.target.value}),placeholder:"e.g. Q1-2026"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:h=>m({organization:h}),organizations:s,disabled:r||!!k.custom_organization})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.col.frequency}),t.jsx(pe,{value:e.frequency,onChange:h=>m({frequency:h}),items:P1.map(h=>({name:h,label:h})),placeholder:"-- Select Frequency --",disabled:r})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.status}),t.jsx(pe,{value:e.status,onChange:h=>m({status:h}),items:A1.map(h=>({name:h,label:h})),placeholder:"-- Select Status --",disabled:r})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.dateStart}),t.jsx(xe,{value:e.start_date||"",onChange:h=>m({start_date:h}),disabled:r,style:{...A,...o}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.dateEnd}),t.jsx(xe,{value:e.end_date||"",onChange:h=>m({end_date:h}),disabled:r,style:{...A,...o}})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.updateWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...A,...o},value:e.update_window_days??2,disabled:r,onChange:h=>m({update_window_days:parseInt(h.target.value)||2})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Grace period before Unknown is auto-assigned"})]})]})})})}function D1({kpiInputs:e,canModify:n,onView:s,onEdit:l,onDelete:r}){const a=ne(),[i,d]=C.useState(new Set),[c,p]=C.useState(""),[w,v]=C.useState(""),f=C.useMemo(()=>[...new Set(e.map(o=>o.organization).filter(Boolean))],[e]),g=C.useMemo(()=>e.filter(o=>{const u=[o.organization,o.period].filter(Boolean).join(" ").toLowerCase();return!(c&&!u.includes(c.toLowerCase())||w&&o.organization!==w)}),[e,c,w]),[S,k]=C.useState(1);C.useEffect(()=>{k(1)},[c,w]);const y=g.slice((S-1)*ae,S*ae),m=o=>{const u=e.filter(j=>i.has(j.name)),h=Me["kpi-input"],z=h.columns.filter(j=>h.defaultColumns.includes(j.key));o==="csv"?He(z,u,"kpi_input_selected"):Ge(z,u,"kpi_input_selected")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Ie,{label:"Total Records",val:g.length,color:G.blue})}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:c,onChange:p,placeholder:"Organization or period…"},{type:"select",label:a.col.organization,value:w,onChange:v,options:[{value:"",label:"All Organizations"},...f.map(o=>({value:o,label:o}))]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(o=>i.has(o.name)),onChange:o=>{if(o.target.checked)d(new Set([...i,...y.map(u=>u.name)]));else{const u=new Set(i);y.forEach(h=>u.delete(h.name)),d(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.organization}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.period}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.field.revenue_growth}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.field.net_profit}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.dash.customerSat}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:a.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((o,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:i.has(o.name)?"#eff6ff":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:h=>h.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:i.has(o.name),onChange:()=>{const h=new Set(i);h.has(o.name)?h.delete(o.name):h.add(o.name),d(h)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.organization||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.period||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.revenue_growth!=null?`${o.revenue_growth}%`:"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.net_profit!=null?o.net_profit.toLocaleString():"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.customer_satisfaction!=null?o.customer_satisfaction:"—"}),t.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:t.jsx(at,{onView:()=>s==null?void 0:s(o),onEdit:n&&l?()=>l(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Je,{count:i.size,onClear:()=>d(new Set),onExport:m}),t.jsx(qe,{page:S,total:g.length,onPageChange:k})]})}function L1({form:e,setForm:n,organizations:s,formStatus:l,viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,user:k}){const y=ne(),m=z=>n(j=>({...j,...z})),o=r?{background:"#f8fafc"}:{},u=z=>j=>m({[z]:parseFloat(j.target.value)||0}),h=e.name?r?`${y.formTitle.editKpi}: ${e.period||e.name}`:y.formTitle.editKpi:y.formTitle.newKpi;return t.jsxs(Ze,{title:h,activePage:"kpi-input",user:k,formStatus:l,buttonText:y.saveKpi,buttonColor:"#16a34a",viewMode:r,onEdit:a,darkMode:i,notifCount:d,onToggleDark:c,onCountChange:p,onViewProfile:w,onSubmit:v,onBack:f,onNavigate:g,onLogout:S,children:[t.jsx(re,{title:"Period & Organization",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(Gt,{value:e.organization,onChange:z=>m({organization:z}),organizations:s,disabled:r||!!k.custom_organization})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[y.col.period," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...A,...o},value:e.period||"",disabled:r,onChange:z=>m({period:z.target.value}),placeholder:"e.g. Q1 2026"})]})]})}),t.jsx(re,{title:"Financial KPIs",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.revenue_growth}),t.jsx("input",{type:"number",step:"0.01",style:{...A,...o},value:e.revenue_growth||"",disabled:r,onChange:u("revenue_growth")})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.net_profit}),t.jsx("input",{type:"number",step:"0.01",style:{...A,...o},value:e.net_profit||"",disabled:r,onChange:u("net_profit")})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.cash_flow}),t.jsx("input",{type:"number",step:"0.01",style:{...A,...o},value:e.cash_flow||"",disabled:r,onChange:u("cash_flow")})]})]})}),t.jsx(re,{title:"Operational KPIs",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.strategic_goal_pct}),t.jsx("input",{type:"number",step:"0.01",style:{...A,...o},value:e.strategic_goal_pct||"",disabled:r,onChange:u("strategic_goal_pct")})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.customer_satisfaction}),t.jsx("input",{type:"number",step:"0.01",style:{...A,...o},value:e.customer_satisfaction||"",disabled:r,onChange:u("customer_satisfaction")})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.employee_turnover_pct}),t.jsx("input",{type:"number",step:"0.01",style:{...A,...o},value:e.employee_turnover_pct||"",disabled:r,onChange:u("employee_turnover_pct")})]})]})}),t.jsx(re,{title:"Safety & Compliance",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.open_safety_incidents}),t.jsx("input",{type:"number",min:0,style:{...A,...o},value:e.open_safety_incidents||"",disabled:r,onChange:z=>m({open_safety_incidents:parseInt(z.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:y.field.compliance_score}),t.jsx("input",{type:"number",step:"0.01",style:{...A,...o},value:e.compliance_score||"",disabled:r,onChange:u("compliance_score")})]})]})})]})}const O1={incident_initial_evaluation:"Incident Initial Evaluation",idea_initial_evaluation:"Idea Initial Evaluation"},Ou={Pending:G.orange,Accepted:G.green,Rejected:G.red,Revoked:G.gray};function N1(e){if(!e)return"—";const n=new Date(e);return isNaN(n.getTime())?"—":`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function W1(e){const n=[];return e.incident_initial_evaluation&&n.push("incident_initial_evaluation"),e.idea_initial_evaluation&&n.push("idea_initial_evaluation"),n}function B1({delegations:e,organizations:n,userRole:s,currentUser:l,onView:r,onRevoke:a}){const i=ne(),[d,c]=C.useState(new Set),[p,w]=C.useState(""),[v,f]=C.useState(""),[g,S]=C.useState("all"),k={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},y=C.useMemo(()=>e.filter(b=>{const x=`${b.auditor} ${b.manager}`.toLowerCase();return!(p&&!x.includes(p.toLowerCase())||v&&b.organization!==v||g!=="all"&&b.status!==g)}),[e,p,v,g]),[m,o]=C.useState(1);C.useEffect(()=>{o(1)},[p,v,g]);const u=y.slice((m-1)*ae,m*ae),h=b=>{const x=e.filter(F=>d.has(F.name)),I=Me.delegations,E=I.columns.filter(F=>I.defaultColumns.includes(F.key));b==="csv"?He(E,x,"delegations_selected"):Ge(E,x,"delegations_selected")},z=y.filter(b=>b.status==="Pending").length,j=y.filter(b=>b.status==="Accepted").length;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Ie,{label:"Total",val:y.length,color:G.purple}),t.jsx(Ie,{label:"Pending",val:z,color:G.orange}),t.jsx(Ie,{label:"Accepted",val:j,color:G.green})]}),t.jsx(vt,{filters:[{type:"search",label:"Search",value:p,onChange:w,placeholder:"Auditor or Manager…"},{type:"select",label:i.col.organization,value:v,onChange:f,options:[{value:"",label:"All Organizations"},...n.map(b=>({value:b.organization_name||b.name,label:b.organization_name||b.name}))]},{type:"select",label:"Status",value:g,onChange:S,options:[{value:"all",label:"All"},{value:"Pending",label:"Pending"},{value:"Accepted",label:"Accepted"},{value:"Rejected",label:"Rejected"},{value:"Revoked",label:"Revoked"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:u.length>0&&u.every(b=>d.has(b.name)),onChange:b=>{if(b.target.checked)c(new Set([...d,...u.map(x=>x.name)]));else{const x=new Set(d);u.forEach(I=>x.delete(I.name)),c(x)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:k,children:i.col.number}),t.jsx("th",{style:k,children:i.col.auditor}),t.jsx("th",{style:k,children:i.col.manager}),t.jsx("th",{style:k,children:i.col.organization}),t.jsx("th",{style:k,children:i.col.functions}),t.jsx("th",{style:k,children:i.col.status}),t.jsx("th",{style:k,children:i.col.requestedOn}),t.jsx("th",{style:k,children:i.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:9,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):u.map((b,x)=>{const I=!!a&&(b.status==="Pending"||b.status==="Accepted")&&(s==="Admin"||b.auditor===l);return t.jsxs("tr",{className:"app-table-row",onClick:()=>r==null?void 0:r(b),style:{borderTop:"1px solid #f0f0f0",background:d.has(b.name)?"#eff6ff":x%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:E=>E.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(b.name),onChange:()=>{const E=new Set(d);E.has(b.name)?E.delete(b.name):E.add(b.name),c(E)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:b.number||b.name}),t.jsx("td",{style:{padding:"10px 14px"},children:b.auditor}),t.jsx("td",{style:{padding:"10px 14px"},children:b.manager}),t.jsx("td",{style:{padding:"10px 14px"},children:b.organization||"All Organizations"}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:W1(b).map(E=>t.jsx("span",{style:{background:"#ede9fe",color:"#6d28d9",padding:"2px 8px",borderRadius:10,fontSize:11,fontWeight:600},children:O1[E]||E},E))})}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{background:(Ou[b.status]||G.gray)+"22",color:Ou[b.status]||G.gray,padding:"3px 10px",borderRadius:12,fontSize:12,fontWeight:700},children:b.status})}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:N1(b.requested_on)}),t.jsx("td",{style:{padding:"8px 14px"},onClick:E=>E.stopPropagation(),children:t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{onClick:()=>r==null?void 0:r(b),title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),I&&t.jsx("button",{onClick:()=>a==null?void 0:a(b.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"})]})})]},b.name)})})]})}),t.jsx(Je,{count:d.size,onClear:()=>c(new Set),onExport:h}),t.jsx(qe,{page:m,total:y.length,onPageChange:o})]})}const Nu={Pending:G.orange,Accepted:G.green,Rejected:G.red,Revoked:G.gray};function $1(e){if(!e)return"—";const n=new Date(e);return isNaN(n.getTime())?"—":n.toLocaleString()}function U1({form:e,setForm:n,organizations:s,users:l,userRoleMap:r,incidents:a=[],ideas:i=[],formStatus:d,viewMode:c,onEdit:p,darkMode:w,notifCount:v,onToggleDark:f,onCountChange:g,onViewProfile:S,onSubmit:k,onBack:y,onNavigate:m,onLogout:o,user:u}){var F;const h=ne(),z=U=>n(N=>({...N,...U})),j=c?{background:"#f8fafc"}:{},b=Cl(l,r,"SB Manager",e.organization).filter(U=>U.name!==(e.auditor||u.name)).map(U=>({name:U.name,label:U.full_name||U.name})),x=a.filter(U=>U.workflow_state==="Initial Evaluation"||U.status==="Initial Evaluation").map(U=>({name:U.name,label:`${U.number||U.name} — ${U.title||""}`.trim()})),I=i.filter(U=>U.workflow_state==="Initial Evaluation"||U.status==="Initial Evaluation").map(U=>({name:U.name,label:`${U.number||U.name} — ${U.title||""}`.trim()})),E=e.name?`${h.formTitle.viewDelegation}${e.number||e.name}`:h.formTitle.newDelegation;return t.jsxs(Ze,{title:E,activePage:"delegations",user:u,formStatus:d,statusBadge:e.status?t.jsx("span",{style:{background:(Nu[e.status]||G.gray)+"22",color:Nu[e.status]||G.gray,padding:"4px 12px",borderRadius:14,fontSize:13,fontWeight:700},children:e.status}):void 0,buttonText:h.saveDelegation,buttonColor:"#16a34a",viewMode:c,onEdit:p,darkMode:w,notifCount:v,onToggleDark:f,onCountChange:g,onViewProfile:S,onSubmit:k,onBack:y,onNavigate:m,onLogout:o,children:[t.jsxs(re,{title:"Delegation Information",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:T,children:h.col.auditor}),t.jsx("input",{style:{...A,background:"#f8fafc",fontWeight:600,color:"#334155"},value:e.auditor||u.name,disabled:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[h.col.manager," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(pe,{value:e.manager,onChange:U=>z({manager:U}),items:b,placeholder:"-- Select Manager --",disabled:c})]}),t.jsxs("div",{children:[t.jsx("label",{style:T,children:h.col.organization}),t.jsx(Gt,{value:e.organization,onChange:U=>z({organization:U}),organizations:s,placeholder:"-- All Organizations --",disabled:c})]})]}),t.jsxs("div",{children:[t.jsxs("label",{style:T,children:[h.col.functions," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,marginTop:6},children:[t.jsxs("div",{style:{border:"1px solid #e5e7eb",borderRadius:8,padding:"12px 14px",background:e.incident_initial_evaluation?"#f0fdf4":"#fafafa",transition:"background 0.15s"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:c?"default":"pointer",fontSize:13,fontWeight:600},children:[t.jsx("input",{type:"checkbox",style:zl,checked:!!e.incident_initial_evaluation,disabled:c,onChange:U=>z({incident_initial_evaluation:U.target.checked?1:0,incident_name:U.target.checked?e.incident_name:""})}),t.jsx("span",{children:"Initial Evaluation (Events / Incidents)"})]}),!!e.incident_initial_evaluation&&t.jsxs("div",{style:{marginTop:10},children:[t.jsxs("label",{style:{...T,color:"#6b7280",fontSize:11},children:["Specific Incident ",t.jsx("span",{style:{fontWeight:400,color:"#9ca3af"},children:"(optional — leave blank to delegate all)"})]}),c?t.jsx("input",{style:{...A,background:"#f8fafc"},value:e.incident_name||"— All Incidents in Initial Evaluation",readOnly:!0,disabled:!0}):t.jsx(pe,{value:e.incident_name||"",onChange:U=>z({incident_name:U}),items:x,placeholder:`-- Any Incident in Initial Evaluation (${x.length} available) --`,disabled:c})]})]}),t.jsxs("div",{style:{border:"1px solid #e5e7eb",borderRadius:8,padding:"12px 14px",background:e.idea_initial_evaluation?"#f0fdf4":"#fafafa",transition:"background 0.15s"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:c?"default":"pointer",fontSize:13,fontWeight:600},children:[t.jsx("input",{type:"checkbox",style:zl,checked:!!e.idea_initial_evaluation,disabled:c,onChange:U=>z({idea_initial_evaluation:U.target.checked?1:0,idea_name:U.target.checked?e.idea_name:""})}),t.jsx("span",{children:"Initial Evaluation (Ideas)"})]}),!!e.idea_initial_evaluation&&t.jsxs("div",{style:{marginTop:10},children:[t.jsxs("label",{style:{...T,color:"#6b7280",fontSize:11},children:["Specific Idea ",t.jsx("span",{style:{fontWeight:400,color:"#9ca3af"},children:"(optional — leave blank to delegate all)"})]}),c?t.jsx("input",{style:{...A,background:"#f8fafc"},value:e.idea_name||"— All Ideas in Initial Evaluation",readOnly:!0,disabled:!0}):t.jsx(pe,{value:e.idea_name||"",onChange:U=>z({idea_name:U}),items:I,placeholder:`-- Any Idea in Initial Evaluation (${I.length} available) --`,disabled:c})]})]})]})]}),!c&&t.jsxs("div",{style:{marginTop:14},children:[t.jsx("label",{style:T,children:"Remarks"}),t.jsx("textarea",{style:{...A,...j,minHeight:70,resize:"vertical"},value:e.remarks||"",onChange:U=>z({remarks:U.target.value}),placeholder:"Optional note for the Manager…"})]})]}),c&&(((F=e.delegation_log)==null?void 0:F.length)??0)>0&&t.jsx(re,{title:"Audit Trail",children:t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Action"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Actor"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Timestamp"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Remarks"})]})}),t.jsx("tbody",{children:(e.delegation_log||[]).map((U,N)=>t.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 12px",fontWeight:600,color:"#334155"},children:U.action}),t.jsx("td",{style:{padding:"8px 12px",color:"#334155"},children:U.actor}),t.jsx("td",{style:{padding:"8px 12px",color:"#64748b"},children:$1(U.timestamp)}),t.jsx("td",{style:{padding:"8px 12px",color:"#64748b"},children:U.remarks||"—"})]},U.name||N))})]})})})]})}const Wu={process:"processes-form",order:"orders-form",incident:"incidents-form",idea:"ideas-form"},Kl={process:G.blue,order:G.purple,incident:G.red,idea:G.green,delegation:G.orange},Bu={process:"🔄",order:"📦",incident:"🚨",idea:"💡",delegation:"🤝"};function Ql(e,n){const s=e.replace("#",""),l=parseInt(s.substring(0,2),16),r=parseInt(s.substring(2,4),16),a=parseInt(s.substring(4,6),16);return`rgba(${l}, ${r}, ${a}, ${n})`}function F1({onNavigate:e,onRefresh:n}){const s=ne(),[l,r]=C.useState([]),[a,i]=C.useState(!0),[d,c]=C.useState(""),[p,w]=C.useState(""),v=()=>Qy().then(m=>{r(m),i(!1)});C.useEffect(()=>{v()},[]);const f=l.filter(m=>m.requires_action),g=l.filter(m=>!m.requires_action),S={};for(const m of l)S[m.type]=(S[m.type]||0)+1;const k=async(m,o)=>{c(m),w("");try{await Xy(m,o),await v(),n==null||n()}catch{w(m)}c("")};function y(m,o,u){return o.length===0?null:t.jsxs("div",{style:{marginBottom:28},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[t.jsx("span",{style:{fontSize:12,fontWeight:800,letterSpacing:.6,textTransform:"uppercase",color:u?G.accent:"#8a8fa3"},children:m}),t.jsx("span",{style:{fontSize:11,fontWeight:700,minWidth:22,textAlign:"center",padding:"2px 7px",borderRadius:999,color:u?"white":"#6b7280",background:u?G.accent:"#e9eaf2"},children:o.length}),t.jsx("div",{style:{flex:1,height:1,background:"linear-gradient(90deg, #e6e7f0, transparent)"}})]}),t.jsx("div",{className:"inbox-card-grid",children:o.map((h,z)=>{const j=h.type!=="delegation",b=Kl[h.type]||G.gray;return t.jsxs("div",{className:"inbox-card",onClick:j?()=>e(Wu[h.type],h.name):void 0,style:{borderTop:`3px solid ${b}`,cursor:j?"pointer":"default"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:14},children:[t.jsx("div",{style:{width:38,height:38,borderRadius:12,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:17,background:Ql(b,.14)},children:Bu[h.type]||"📌"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:13,color:b,letterSpacing:.3},children:h.number}),h.requires_action&&t.jsx("span",{style:{fontSize:10,fontWeight:700,color:G.red,background:Ql(G.red,.12),padding:"1px 7px",borderRadius:999,textTransform:"uppercase",letterSpacing:.4},children:"Action"})]}),t.jsx("div",{className:"inbox-card-title",style:{fontSize:14,fontWeight:600,marginTop:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.title}),t.jsxs("div",{className:"inbox-card-meta",style:{marginTop:5,fontSize:12},children:[h.action,h.organization&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{opacity:.5},children:" · "}),h.organization]}),h.date&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{opacity:.5},children:" · "}),h.date]})]}),p===h.name&&t.jsx("div",{style:{marginTop:6,fontSize:12,color:G.red,fontWeight:600},children:"Failed to respond — please try again."})]})]}),h.type==="delegation"?t.jsxs("div",{style:{display:"flex",gap:8,marginTop:14},children:[t.jsx("button",{onClick:()=>k(h.name,"Accepted"),disabled:d===h.name,style:{flex:1,padding:"8px 0",borderRadius:9,border:"none",background:G.green,color:"white",fontWeight:700,fontSize:13,cursor:d===h.name?"wait":"pointer",opacity:d===h.name?.6:1},children:"Accept"}),t.jsx("button",{onClick:()=>k(h.name,"Rejected"),disabled:d===h.name,style:{flex:1,padding:"8px 0",borderRadius:9,border:"none",background:G.red,color:"white",fontWeight:700,fontSize:13,cursor:d===h.name?"wait":"pointer",opacity:d===h.name?.6:1},children:"Reject"})]}):t.jsx("button",{onClick:x=>{x.stopPropagation(),e(Wu[h.type],h.name)},style:{marginTop:14,width:"100%",padding:"8px 0",borderRadius:9,border:"none",background:h.requires_action?b:Ql(b,.12),color:h.requires_action?"white":b,fontWeight:700,fontSize:13,cursor:"pointer"},children:h.requires_action?"Act Now →":s.view})]},z)})})]})}return t.jsxs("div",{style:{maxWidth:1040,margin:"0 auto"},children:[!a&&l.length>0&&t.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",marginBottom:24},children:Object.entries(S).map(([m,o])=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"6px 12px 6px 9px",borderRadius:999,background:Ql(Kl[m]||G.gray,.1),border:`1px solid ${Ql(Kl[m]||G.gray,.25)}`},children:[t.jsx("span",{style:{fontSize:13},children:Bu[m]}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:Kl[m]||G.gray,textTransform:"capitalize"},children:m}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:Kl[m]||G.gray,opacity:.7},children:o})]},m))}),a&&t.jsx("p",{style:{color:"#888"},children:s.loading}),!a&&l.length===0&&t.jsxs("div",{className:"inbox-empty",children:[t.jsx("div",{style:{fontSize:46,marginBottom:10},children:"✨"}),t.jsx("p",{style:{fontSize:16,fontWeight:600},children:s.inbox.noMessages}),t.jsx("p",{style:{fontSize:13,marginTop:4,opacity:.7},children:"You're all caught up — nothing needs your attention right now."})]}),!a&&y("Needs Action",f,!0),!a&&y("Informational",g,!1)]})}const M1=[{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"]}],Fd={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 H1(e,n){const s=e.map(r=>Fd[r]||r).join(","),l=n.map(r=>e.map(a=>`"${r[a]??""}"`).join(",")).join(` `);return s+` `+l}function G1(e,n){const s=new Blob([e],{type:"text/csv"}),l=URL.createObjectURL(s),r=document.createElement("a");r.href=l,r.download=n,r.click(),URL.revokeObjectURL(l)}const $u=e=>String(e??"").replace(/&/g,"&").replace(//g,">");function K1(e,n,s){const l=e.map(p=>`${$u(Fd[p]||p)}`).join(""),r=n.map(p=>`${e.map(w=>`${$u(p[w])}`).join("")}`).join(""),a=`${l}${r}
`,i=new Blob(["\uFEFF"+a],{type:"application/vnd.ms-excel"}),d=URL.createObjectURL(i),c=document.createElement("a");c.href=d,c.download=s,c.click(),URL.revokeObjectURL(d)}const fh="report-print-area",Yi="report-print-portal";function Q1(){const e=document.getElementById(fh);if(!e)return;const n=document.createElement("div");n.id=Yi,n.innerHTML=e.innerHTML,document.body.appendChild(n);const s=document.createElement("style");s.id="report-print-style",s.textContent=` #${Yi} { display: none; } @media print { #root { display: none !important; } #${Yi} { display: block !important; } } `,document.head.appendChild(s);const l=()=>{n.remove(),s.remove(),window.removeEventListener("afterprint",l)};window.addEventListener("afterprint",l),window.print()}const Uu={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",minWidth:180},Xi={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white"};function Y1({organizations:e,userRole:n}){const s=ne(),l=M1.filter(I=>I.roles.includes(n)),[r,a]=C.useState(""),[i,d]=C.useState(""),[c,p]=C.useState(""),[w,v]=C.useState(""),[f,g]=C.useState(String(new Date().getFullYear())),[S,k]=C.useState([]),[y,m]=C.useState([]),[o,u]=C.useState(!1),[h,z]=C.useState(""),j=l.find(I=>I.id===r);async function b(){if(r){u(!0),z(""),m([]),k([]);try{const I={};i&&(I.organization=i),c&&(I.from_date=c),w&&(I.to_date=w),(j==null?void 0:j.extraFilter)==="year"&&f&&(I.year=f);const E=await Ky(r,I);k(E.columns||[]),m(E.rows||[])}catch(I){z(I.message||"Error running report")}finally{u(!1)}}}const x=(j==null?void 0:j.label)||r;return t.jsxs("div",{children:[t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12,marginBottom:20},children:l.map(I=>t.jsxs("div",{onClick:()=>a(I.id),style:{background:r===I.id?"#ebf5fb":"white",border:r===I.id?`2px solid ${G.accent}`:"2px solid transparent",borderRadius:10,padding:"14px 16px",cursor:"pointer",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[t.jsx("div",{style:{fontWeight:700,fontSize:14,color:"#1a2332",marginBottom:4},children:I.label}),t.jsx("div",{style:{fontSize:12,color:"#888"},children:I.description})]},I.id))}),t.jsx("div",{style:{background:"white",borderRadius:12,padding:20,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:20},children:t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"REPORT"}),t.jsxs("select",{style:Uu,value:r,onChange:I=>a(I.target.value),children:[t.jsx("option",{value:"",children:"-- Select Report --"}),l.map(I=>t.jsx("option",{value:I.id,children:I.label},I.id))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"ORGANIZATION"}),t.jsxs("select",{style:Uu,value:i,onChange:I=>d(I.target.value),children:[t.jsx("option",{value:"",children:s.filter.allOrgs}),e.map(I=>t.jsx("option",{value:I.name,children:I.organization_name||I.name},I.name))]})]}),(j==null?void 0:j.extraFilter)==="year"?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"YEAR"}),t.jsx("input",{type:"number",style:{...Xi,width:90},value:f,onChange:I=>g(I.target.value),min:2020,max:2099})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"FROM"}),t.jsx(xe,{value:c,onChange:p,style:Xi})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"TO"}),t.jsx(xe,{value:w,onChange:v,style:Xi})]})]}),t.jsx("button",{onClick:b,disabled:!r||o,style:{padding:"9px 20px",borderRadius:8,border:"none",background:G.accent,color:"white",fontWeight:700,fontSize:13,cursor:r?"pointer":"not-allowed",opacity:r?1:.5},children:o?s.loading:s.reports.generate}),y.length>0&&t.jsx("button",{onClick:()=>G1(H1(S,y),`${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"}),y.length>0&&t.jsx("button",{onClick:()=>K1(S,y,`${r}.xls`),style:{padding:"9px 20px",borderRadius:8,border:"1px solid #107c41",background:"white",color:"#107c41",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Export Excel"}),y.length>0&&t.jsx("button",{onClick:Q1,style:{padding:"9px 20px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Print / PDF"})]})}),h&&t.jsx("div",{style:{color:"#e74c3c",marginBottom:16},children:h}),y.length>0&&t.jsxs("div",{id:fh,style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto"},children:[t.jsxs("div",{style:{padding:"14px 18px",borderBottom:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,color:"#333"},children:x}),t.jsxs("span",{style:{fontSize:12,color:"#888"},children:[y.length," rows"]})]}),t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8f9fa"},children:S.map(I=>t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700,whiteSpace:"nowrap"},children:Fd[I]||I.replace(/_/g," ").toUpperCase()},I))})}),t.jsx("tbody",{children:y.map((I,E)=>t.jsx("tr",{style:{borderTop:"1px solid #f0f0f0",background:E%2===0?"white":"#fafafa"},children:S.map(F=>t.jsx("td",{style:{padding:"10px 14px",color:"#333"},children:I[F]!=null?String(I[F]):"—"},F))},E))})]})]}),!o&&y.length===0&&r&&!h&&t.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"Select a report and click Run Report to see results."}),l.length===0&&t.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"No reports are available for your role."})]})}const Rr=()=>new Date().toISOString().split("T")[0],Md=()=>new Date(Date.now()+30*24*60*60*1e3).toISOString().split("T")[0],X1=()=>new Date().toTimeString().slice(0,5),Sn=()=>({name:"",number:"",title:"",organization:"",type:"",incident_class:"",incident_field:"",date:Rr(),time:X1(),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:""}),dn=()=>({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:Rr(),priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:"",sb_order:""}),cn=()=>({name:"",number:"",title:"",organization:"",type:"Buy L",management:"",department:"",section_field:"",branch:"",starting_date:Rr(),ending_date:Md(),assigned_to:"",actor:"",status:"",budget:0,actual_cost:0,currency:"SAR",description:"",notes:"",cycle:"",stage:1,completion_pct:0,escalation_level:0,workflow_state:"Draft",planned:0,priority:"",product_relation:0,entity_scope:"",economy_class:"",hses_field:"",auditor_comment:"",sb_idea:"",cycle_type:"Normal",long_cycle_date_1:"",long_cycle_date_2:"",long_cycle_date_3:"",long_cycle_date_4:""}),sa=()=>({name:"",title:"",date_start:Rr(),date_end:Md(),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:""}),Gs=()=>({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}),fs=()=>({name:"",organization:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),hs=()=>({name:"",custom_organization:"",department_name:"",custom_management:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),gs=()=>({name:"",organization:"",branch:"",management:"",department:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),Ks=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Qs=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Ys=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Xs=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),qs=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Js=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Zs=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Vs=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),la=()=>({name:"",first_name:"",full_name:"",email:"",enabled:1,creation:"",username:"",mobile_no:"",custom_organization:"",custom_management:"",custom_department:"",custom_branch:"",custom_number:"",custom_category:""}),xs=()=>({name:"",name1:"",organization:"",frequency:"Monthly",status:"Active",start_date:Rr(),end_date:Md(),update_window_days:2}),ms=()=>({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}),Yl=()=>({name:"",number:"",auditor:"",manager:"",organization:"",incident_initial_evaluation:0,idea_initial_evaluation:0,status:"Pending",requested_on:"",remarks:""}),q1=new Set(["incidents","incidents-form","ideas","ideas-form"]),J1=new Set(["orders","orders-form","incidents","incidents-form","ideas","ideas-form"]),Z1=new Set(nh.flatMap(({id:e})=>[e,`${e}-form`])),V1=new Set(["Admin","Owner","Auditor","Manager"]),ev=new Set(["Admin","Owner","Auditor","Manager"]),tv=new Set(["Admin","Auditor","Manager"]);function nv({user:e,onLogout:n,darkMode:s,onToggleDark:l}){const r=ne(),a=e.role,i=V1.has(a),d=ev.has(a),c=tv.has(a),p=_=>_==="users"||_==="users-form"?a==="Admin":a==="Admin"||a==="Auditor"?!0:a==="Owner"||a==="XAuditor"?!1:a==="Manager"?!!J1.has(_):q1.has(_),w=_=>a==="Employee"&&!!_&&_!=="New",v=i?"dashboard":"inbox",f=_=>_==="dashboard"?i:_==="reports"?d:_==="delegations"||_==="delegations-form"?c:_==="users"||_==="users-form"?a==="Admin":Z1.has(_)?a==="Admin"||a==="Auditor":!0,[g,S]=C.useState(()=>{const _=a0(zu());return _&&f(_)?_:v});C.useEffect(()=>{const _=i0(g);window.location.hash!==_&&window.history.pushState(null,"",_)},[g]),C.useEffect(()=>{const _=()=>{const H=zu();S(H&&f(H)?H:v)};return window.addEventListener("popstate",_),()=>window.removeEventListener("popstate",_)},[]);const k=e.custom_organization||"",[y,m]=C.useState(""),[o,u]=C.useState("");C.useEffect(()=>{if(!o)return;const _=setTimeout(()=>u(""),0);return()=>clearTimeout(_)},[o]);const h=(_,H)=>{u(H),S(_)},[z,j]=C.useState(0),[b,x]=C.useState([]),[I,E]=C.useState([]),[F,U]=C.useState([]),[N,$]=C.useState([]),[P,D]=C.useState([]),[Y,X]=C.useState([]),[q,J]=C.useState([]),[W,V]=C.useState([]),[de,me]=C.useState([]),[le,Ve]=C.useState([]),[dt,Q]=C.useState([]),[oe,Oe]=C.useState([]),[ve,nn]=C.useState([]),[fe,je]=C.useState([]),[Et,Ne]=C.useState([]),[L,se]=C.useState([]),[R,We]=C.useState([]),[ft,M]=C.useState([]),[Be,ui]=C.useState([]),[gn,Dr]=C.useState({}),[B,Tt]=C.useState([]),[xn,Rn]=C.useState([]),[Hd,hh]=C.useState([]),[Gd,gh]=C.useState([]),[Kd,xh]=C.useState([]),[pi,mh]=C.useState({}),[fi,yh]=C.useState([]),Lr=()=>({name:"",company_name:"",acronym:"",code:"",status:"Active",owner_user:"",notes:""}),[Qd,Ds]=C.useState(Lr()),[_e,he]=C.useState(!0),[Ke,ie]=C.useState("idle"),[Qe,te]=C.useState(!1),[Yd,Xd]=C.useState(!1),[Or,qd]=C.useState(null),[vh,jh]=C.useState(()=>localStorage.getItem("sb_sidebar")==="1"),bh=()=>jh(_=>{const H=!_;return localStorage.setItem("sb_sidebar",H?"1":"0"),H}),[Sh,hi]=C.useState(!1),[wh,gi]=C.useState([]),[kh,xi]=C.useState([]);C.useEffect(()=>{hi(!1),gi([]),xi([])},[g]);const[mn,yn]=C.useState(Sn()),[vn,sn]=C.useState(dn()),[as,ln]=C.useState(cn()),[is,rn]=C.useState(sa()),[Jd,Ls]=C.useState(Gs()),[Zd,os]=C.useState(fs()),[Vd,ds]=C.useState(hs()),[ec,cs]=C.useState(gs()),[tc,Os]=C.useState(Ks()),[nc,Ns]=C.useState(Qs()),[sc,Ws]=C.useState(Ys()),[lc,Bs]=C.useState(Xs()),[rc,$s]=C.useState(qs()),[ac,Us]=C.useState(Js()),[ic,Fs]=C.useState(Zs()),[oc,Ms]=C.useState(Vs()),[Al,Nr]=C.useState(la()),[dc,us]=C.useState(xs()),[cc,ps]=C.useState(ms()),[Dn,Rl]=C.useState(Yl()),Pt=async()=>{he(!0);try{const[_,H,we,Kt,Ln,Ae,ji,vg,jg,bg,Sg,wg,kg,_g,Cg,zg,Ig,Eg,Tg,Pg,Ag,Rg,Dg,Lg,Og,Ng,Wg]=await Promise.all([Te(O.incidents),Te(O.organizations),Te(O.ideas),Te(O.orders),Te(O.processes),Iy(),Te(O.managements),Te(O.departments),Te(O.branches),Te(O.incidentTypes),Te(O.incidentClass),Te(O.incidentField),Te(O.ideaTypes),Te(O.orderTypes),Te(O.processTypes),Te(O.incidentStatuses),Te(O.ideaStatuses),Te(O.orderStatuses),Te(O.processStatuses),Ay(),Ry(),Te(O.cycles),Te(O.kpiInput),Jy(),Vy(),e0(),t0()]);x(_||[]),E(H||[]),U(we||[]),$(Kt||[]),D(Ln||[]),Tt(Ae||[]),X(ji||[]),J(vg||[]),V(jg||[]),me(bg||[]),Ve(Sg||[]),Q(wg||[]),Oe(kg||[]),nn(_g||[]),je(Cg||[]),Ne(zg||[]),se(Ig||[]),We(Eg||[]),M(Tg||[]),ui(Pg||[]),Dr(Ag||{}),Rn(Rg||[]),hh(Dg||[]),gh(Lg||[]),xh(Og||[]),mh(Ng||{}),yh(Wg||[])}catch(_){console.error("Error loading data:",_)}he(!1)},uc=async()=>{try{const _=await fetch("/api/method/sidrah_business.api.get_notification_count",{credentials:"include",headers:{Accept:"application/json"}});if(_.ok){const H=await _.json();j(Number(H.message)||0)}}catch{}};C.useEffect(()=>{Pt(),uc();const _=setInterval(uc,6e4);return()=>clearInterval(_)},[e.name]);const[ht,jn]=C.useState({isOpen:!1,doctype:"",name:"",title:"",isDeleting:!1}),Ee=(_,H,we)=>{jn({isOpen:!0,doctype:_,name:H,title:we||H,isDeleting:!1})},pc=_=>{const we={[O.incidents]:"incidents",[O.ideas]:"ideas",[O.orders]:"orders",[O.processes]:"processes",[O.organizations]:"organizations",[O.managements]:"managements",[O.departments]:"departments",[O.branches]:"branches",[O.cycles]:"cycles",[O.kpiInput]:"kpi-input",[O.incidentTypes]:"incident-types",[O.ideaTypes]:"idea-types",[O.orderTypes]:"order-types",[O.processTypes]:"process-types",[O.incidentStatuses]:"incident-statuses",[O.ideaStatuses]:"idea-statuses",[O.orderStatuses]:"order-statuses",[O.processStatuses]:"process-statuses",[O.groupCompanies]:"group-companies"}[_];we&&S(we)},fc=async _=>{jn(H=>({...H,isDeleting:!0}));try{const H=ht.doctype;await Ho(ht.doctype,ht.name,_,!1),jn(we=>({...we,isOpen:!1,isDeleting:!1})),await Pt(),g.endsWith("-form")&&pc(H)}catch(H){console.error("Delete error:",H),alert((H==null?void 0:H.message)||"Delete failed. Please try again."),jn(we=>({...we,isDeleting:!1}))}},hc=async _=>{jn(H=>({...H,isDeleting:!0}));try{const H=ht.doctype;await Ho(ht.doctype,ht.name,_,!0),jn(we=>({...we,isOpen:!1,isDeleting:!1})),await Pt(),g.endsWith("-form")&&pc(H)}catch(H){console.error("Permanent delete error:",H),alert((H==null?void 0:H.message)||"Permanent delete failed. Please try again."),jn(we=>({...we,isDeleting:!1}))}},Dl=async(_,H)=>{if(window.confirm(r.rtl?"هل أنت متأكد من استعادة هذا السجل؟":"Are you sure you want to restore this record?")){he(!0);try{await zy(_,H),alert(r.restoredOk||"Record restored successfully!"),await Pt()}catch(we){console.error("Restore error:",we),alert((we==null?void 0:we.message)||"Restore failed. Please try again.")}he(!1)}},_h=async _=>{try{await Ny(_),await Pt()}catch(H){console.error("Disable user error:",H)}},Ch=async _=>{te(!0),he(!0);try{const H=await At(O.incidents,_.name);yn({...Sn(),...H})}catch{yn({...Sn(),..._})}S("incidents-form"),he(!1)},zh=async _=>{te(!0),he(!0);try{const H=await At(O.ideas,_.name);sn({...dn(),...H})}catch{sn({...dn(),..._})}S("ideas-form"),he(!1)},Ih=async _=>{te(!0),he(!0);try{const H=await At(O.orders,_.name);ln({...cn(),...H})}catch{ln({...cn(),..._})}S("orders-form"),he(!1)},Eh=async _=>{te(!0),he(!0);try{const H=await Vl(_.name);rn({...H,progress_indicators:H.progress_indicators||[],cycle_logs:H.cycle_logs||[]}),S("processes-form")}catch{rn({..._,progress_indicators:_.progress_indicators||[]}),S("processes-form")}he(!1)},Th=_=>Se(O.organizations,_,Ls,Gs(),"organizations-form",!0),Ph=_=>{te(!0),Ds(_),S("group-companies-form")},Ah=_=>{te(!1),Ds(_),S("group-companies-form")},Rh=async _=>{te(!0),he(!0);try{const H=await At(O.managements,_.name);os({...fs(),...H})}catch{os({...fs(),..._})}S("managements-form"),he(!1)},Dh=async _=>{te(!0),he(!0);try{const H=await At(O.departments,_.name);ds({...hs(),...H})}catch{ds({...hs(),..._})}S("departments-form"),he(!1)},Lh=async _=>{te(!0),he(!0);try{const H=await At(O.branches,_.name);cs({...gs(),...H})}catch{cs({...gs(),..._})}S("branches-form"),he(!1)},Oh=async _=>{te(!0),he(!0);try{const H=await At(O.cycles,_.name);us({...xs(),...H})}catch{us({...xs(),..._})}S("cycles-form"),he(!1)},Nh=async _=>{te(!0),he(!0);try{const H=await At(O.kpiInput,_.name);ps({...ms(),...H})}catch{ps({...ms(),..._})}S("kpi-input-form"),he(!1)},st=async(_,H,we,Kt,Ln)=>{ie("loading");try{if(H.name)await Ma(_,H.name,H),ie("success"),Pt(),setTimeout(()=>{ie("idle"),S(Kt)},1500);else if(Ln){const Ae=await Qi(_,H);Ln((Ae==null?void 0:Ae.data)??Ae),ie("success"),Pt(),setTimeout(()=>ie("idle"),1500)}else await Qi(_,H),we(),ie("success"),Pt(),setTimeout(()=>{ie("idle"),S(Kt)},1500)}catch(Ae){console.error("Submit error:",Ae),ie(Ae instanceof Error?Ae.message:"Error saving. Please try again.")}},$e=async()=>{await Ty(),n()},Se=async(_,H,we,Kt,Ln,Ae)=>{te(Ae),he(!0);try{const ji=await At(_,H.name);we({...Kt,...ji})}catch{we({...Kt,...H})}S(Ln),he(!1)},Wh=_=>Se(O.incidents,_,yn,Sn(),"incidents-form",!1),Bh=_=>Se(O.ideas,_,sn,dn(),"ideas-form",!1),$h=_=>Se(O.orders,_,ln,cn(),"orders-form",!1),Uh=_=>{te(!1),he(!0),Vl(_.name).then(H=>{rn({...H,progress_indicators:H.progress_indicators||[],cycle_logs:H.cycle_logs||[]})}).catch(()=>{rn({..._,progress_indicators:_.progress_indicators||[]})}).finally(()=>{S("processes-form"),he(!1)})},Fh=_=>Se(O.organizations,_,Ls,Gs(),"organizations-form",!1),Mh=_=>Se(O.managements,_,os,fs(),"managements-form",!1),Hh=_=>Se(O.departments,_,ds,hs(),"departments-form",!1),Gh=_=>Se(O.branches,_,cs,gs(),"branches-form",!1),Kh=_=>Se(O.cycles,_,us,xs(),"cycles-form",!1),Qh=_=>Se(O.kpiInput,_,ps,ms(),"kpi-input-form",!1),Yh=async _=>{te(!0),he(!0);try{const H=await Zy(_.name);Rl({...Yl(),...H})}catch{Rl({...Yl(),..._})}S("delegations-form"),he(!1)},Xh=async()=>{ie("loading");try{const _=[];Dn.incident_initial_evaluation&&_.push("incident_initial_evaluation"),Dn.idea_initial_evaluation&&_.push("idea_initial_evaluation"),await Yy(Dn.manager,_,Dn.organization,Dn.remarks||"",Dn.incident_name||"",Dn.idea_name||""),Rl(Yl()),ie("success"),Pt(),setTimeout(()=>{ie("idle"),S("delegations")},1500)}catch(_){console.error("Delegation submit error:",_),ie(_ instanceof Error?_.message:"Error saving. Please try again.")}},qh=async _=>{if(window.confirm(r.rtl?"هل أنت متأكد من إلغاء هذا التفويض؟":"Are you sure you want to revoke this delegation?")){he(!0);try{await qy(_),await Pt()}catch(H){console.error("Revoke delegation error:",H),alert(H instanceof Error?H.message:"Revoke failed. Please try again.")}he(!1)}},Jh=_=>Se(O.incidentTypes,_,Os,Ks(),"incident-types-form",!0),Zh=_=>Se(O.incidentTypes,_,Os,Ks(),"incident-types-form",!1),Vh=_=>Se(O.ideaTypes,_,Ns,Qs(),"idea-types-form",!0),eg=_=>Se(O.ideaTypes,_,Ns,Qs(),"idea-types-form",!1),tg=_=>Se(O.orderTypes,_,Ws,Ys(),"order-types-form",!0),ng=_=>Se(O.orderTypes,_,Ws,Ys(),"order-types-form",!1),sg=_=>Se(O.processTypes,_,Bs,Xs(),"process-types-form",!0),lg=_=>Se(O.processTypes,_,Bs,Xs(),"process-types-form",!1),rg=_=>Se(O.incidentStatuses,_,$s,qs(),"incident-statuses-form",!0),ag=_=>Se(O.incidentStatuses,_,$s,qs(),"incident-statuses-form",!1),ig=_=>Se(O.ideaStatuses,_,Us,Js(),"idea-statuses-form",!0),og=_=>Se(O.ideaStatuses,_,Us,Js(),"idea-statuses-form",!1),dg=_=>Se(O.orderStatuses,_,Fs,Zs(),"order-statuses-form",!0),cg=_=>Se(O.orderStatuses,_,Fs,Zs(),"order-statuses-form",!1),ug=_=>Se(O.processStatuses,_,Ms,Vs(),"process-statuses-form",!0),pg=_=>Se(O.processStatuses,_,Ms,Vs(),"process-statuses-form",!1),fg=async _=>{qd(_),S("profile")},hg=_=>{te(!1),Xd(!1),Nr({...la(),..._}),S("users-form")},gg=async()=>{ie("loading");try{if(!Al.name){const H=await Qi("User",{...Al,send_welcome_email:0,user_type:"System User"});Nr({...la(),...Al,...(H==null?void 0:H.data)??H}),te(!0),ie("success"),Pt(),setTimeout(()=>ie("idle"),1500)}else{const{name:H,email:we,creation:Kt,full_name:Ln,...Ae}=Al;await Ma("User",H,Ae),ie("success"),Pt(),setTimeout(()=>{ie("idle"),S("users")},1500)}}catch(_){console.error("User submit error:",_),ie(_ instanceof Error?_.message:"Error saving. Please try again.")}},Ue=()=>{const _=Be.find(H=>H.name===e.name||H.username===e.name);qd(_||{name:e.name,full_name:e.full_name,email:e.name,enabled:1}),S("profile")},mi=(_,H)=>{if(H){const Kt={"processes-form":O.processes,"orders-form":O.orders,"incidents-form":O.incidents,"ideas-form":O.ideas}[_];if(Kt){te(!0),he(!0),(_==="processes-form"?Vl(H).then(Ae=>({...Ae,progress_indicators:Ae.progress_indicators||[],cycle_logs:Ae.cycle_logs||[]})):At(Kt,H)).then(Ae=>{_==="processes-form"?rn(Ae):_==="orders-form"?ln({...cn(),...Ae}):_==="incidents-form"?yn({...Sn(),...Ae}):_==="ideas-form"&&sn({...dn(),...Ae}),S(_),he(!1)}).catch(()=>{S(_),he(!1)});return}}S(_)},Ye=_=>t.jsxs(t.Fragment,{children:[_,t.jsx(_u,{isOpen:ht.isOpen,doctype:ht.doctype,docname:ht.name,docTitle:ht.title,isAdmin:a==="Admin"||e.name==="Administrator",isDeleting:ht.isDeleting,onClose:()=>jn(H=>({...H,isOpen:!1})),onConfirmSoftDelete:fc,onConfirmPermanentDelete:hc})]});if(g==="incidents-form")return Ye(t.jsx(k0,{incForm:mn,setIncForm:yn,organizations:I,managements:Y,departments:q,branches:W,incidentTypes:de,incidentClasses:le,incidentFields:dt,incidentStatuses:Et,users:B,userRoleMap:gn,formStatus:Ke,viewMode:Qe||!p("incidents-form")||w(mn.workflow_state),canModify:p("incidents-form"),onEdit:p("incidents-form")&&!w(mn.workflow_state)&&!Hn("incident",mn.workflow_state)?()=>te(!1):void 0,onDelete:p("incidents-form")?_=>Ee(O.incidents,_,mn.title||mn.number):void 0,onRestore:a==="Admin"?_=>Dl(O.incidents,_):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,userRole:a,delegatedFunctions:Kd,delegatedOrgs:pi,onSubmit:()=>st(O.incidents,mn,()=>yn(Sn()),"incidents",_=>yn({...Sn(),..._})),onBack:()=>{S("incidents"),ie("idle")},onNavigate:S,onLogout:$e,user:e,onRefresh:async()=>{if(mn.name){const _=await At(O.incidents,mn.name).catch(()=>null);_&&yn({...Sn(),..._})}Te(O.incidents).then(_=>x(_||[])).catch(()=>{})}}));if(g==="ideas-form")return Ye(t.jsx(I0,{ideaForm:vn,setIdeaForm:sn,organizations:I,managements:Y,departments:q,branches:W,ideaTypes:oe,ideaStatuses:L,users:B,userRoleMap:gn,formStatus:Ke,viewMode:Qe||!p("ideas-form")||w(vn.workflow_state),canModify:p("ideas-form"),onEdit:p("ideas-form")&&!w(vn.workflow_state)&&!Hn("idea",vn.workflow_state)?()=>te(!1):void 0,onDelete:p("ideas-form")?_=>Ee(O.ideas,_,vn.title||vn.number):void 0,onRestore:a==="Admin"?_=>Dl(O.ideas,_):void 0,onNavigateToOrder:_=>Se(O.orders,{name:_},ln,cn(),"orders-form",!0),darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,userRole:a,delegatedFunctions:Kd,delegatedOrgs:pi,onSubmit:()=>st(O.ideas,vn,()=>sn(dn()),"ideas",_=>sn({...dn(),..._})),onBack:()=>{S("ideas"),ie("idle")},onNavigate:S,onLogout:$e,user:e,onRefresh:async()=>{if(vn.name){const _=await At(O.ideas,vn.name).catch(()=>null);_&&sn({...dn(),..._})}Te(O.ideas).then(_=>U(_||[])).catch(()=>{})}}));if(g==="orders-form")return Ye(t.jsx(R0,{orderForm:as,setOrderForm:ln,organizations:I,managements:Y,departments:q,branches:W,orderTypes:ve,orderStatuses:R,cycles:xn,users:B,userRoleMap:gn,formStatus:Ke,viewMode:Qe||!p("orders-form"),canModify:p("orders-form"),onEdit:p("orders-form")&&!Hn("order",as.workflow_state)?()=>te(!1):void 0,onDelete:p("orders-form")?_=>Ee(O.orders,_,as.title||as.number):void 0,onRestore:a==="Admin"?_=>Dl(O.orders,_):void 0,onNavigateToIdea:_=>Se(O.ideas,{name:_},sn,dn(),"ideas-form",!0),darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,currentUser:e.name,userRole:a,onSubmit:()=>st(O.orders,as,()=>ln(cn()),"orders",_=>ln({...cn(),..._})),onBack:()=>{S("orders"),ie("idle")},onNavigate:S,onLogout:$e,user:e,onRefresh:async()=>{if(as.name){const _=await At(O.orders,as.name).catch(()=>null);_&&ln({...cn(),..._})}Te(O.orders).then(_=>$(_||[])).catch(()=>{})}}));if(g==="processes-form")return Ye(t.jsx(W0,{processForm:is,setProcessForm:rn,organizations:I,managements:Y,departments:q,branches:W,processTypes:fe,processStatuses:ft,cycles:xn,users:B,userRoleMap:gn,formStatus:Ke,viewMode:Qe||!p("processes-form"),canModify:p("processes-form"),onEdit:p("processes-form")&&!Hn("process",is.workflow_state)?()=>te(!1):void 0,onDelete:p("processes-form")?_=>Ee(O.processes,_,is.title||is.number):void 0,onRestore:a==="Admin"?_=>Dl(O.processes,_):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,userRole:e.role,onRefreshProcess:async()=>{if(is.name)try{const _=await Vl(is.name);rn({..._,progress_indicators:_.progress_indicators||[],cycle_logs:_.cycle_logs||[]})}catch{}Te(O.processes).then(_=>D(_||[])).catch(()=>{})},onSubmit:()=>st(O.processes,is,()=>rn(sa()),"processes",_=>rn({...sa(),..._,progress_indicators:_.progress_indicators||[],cycle_logs:_.cycle_logs||[]})),onBack:()=>{S("processes"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="organizations-form")return Ye(t.jsx(H0,{orgForm:Jd,setOrgForm:Ls,groupCompanies:fi,formStatus:Ke,viewMode:Qe||!p("organizations-form"),onEdit:p("organizations-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.organizations,Jd,()=>Ls(Gs()),"organizations",_=>{Ls({...Gs(),..._}),te(!0)}),onBack:()=>{S("organizations"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="managements-form")return Ye(t.jsx(X0,{form:Zd,setForm:os,organizations:I,formStatus:Ke,viewMode:Qe||!p("managements-form"),onEdit:p("managements-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.managements,Zd,()=>os(fs()),"managements",_=>{os({...fs(),..._}),te(!0)}),onBack:()=>{S("managements"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="departments-form")return Ye(t.jsx(Z0,{form:Vd,setForm:ds,organizations:I,managements:Y,formStatus:Ke,viewMode:Qe||!p("departments-form"),onEdit:p("departments-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.departments,Vd,()=>ds(hs()),"departments",_=>{ds({...hs(),..._}),te(!0)}),onBack:()=>{S("departments"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="branches-form")return Ye(t.jsx(t1,{form:ec,setForm:cs,organizations:I,managements:Y,departments:q,formStatus:Ke,viewMode:Qe||!p("branches-form"),onEdit:p("branches-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.branches,ec,()=>cs(gs()),"branches",_=>{cs({...gs(),..._}),te(!0)}),onBack:()=>{S("branches"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="cycles-form")return Ye(t.jsx(R1,{form:dc,setForm:us,organizations:I,formStatus:Ke,viewMode:Qe||!p("cycles-form"),onEdit:p("cycles-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.cycles,dc,()=>us(xs()),"cycles",_=>{us({...xs(),..._}),te(!0)}),onBack:()=>{S("cycles"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="kpi-input-form")return Ye(t.jsx(L1,{form:cc,setForm:ps,organizations:I,formStatus:Ke,viewMode:Qe||!p("kpi-input-form"),onEdit:p("kpi-input-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.kpiInput,cc,()=>ps(ms()),"kpi-input",_=>{ps({...ms(),..._}),te(!0)}),onBack:()=>{S("kpi-input"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="incident-types-form")return Ye(t.jsx(l1,{form:tc,setForm:Os,formStatus:Ke,viewMode:Qe||!p("incident-types-form"),onEdit:p("incident-types-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.incidentTypes,tc,()=>Os(Ks()),"incident-types",_=>{Os({...Ks(),..._}),te(!0)}),onBack:()=>{S("incident-types"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="idea-types-form")return Ye(t.jsx(i1,{form:nc,setForm:Ns,formStatus:Ke,viewMode:Qe||!p("idea-types-form"),onEdit:p("idea-types-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.ideaTypes,nc,()=>Ns(Qs()),"idea-types",_=>{Ns({...Qs(),..._}),te(!0)}),onBack:()=>{S("idea-types"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="order-types-form")return Ye(t.jsx(c1,{form:sc,setForm:Ws,formStatus:Ke,viewMode:Qe||!p("order-types-form"),onEdit:p("order-types-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.orderTypes,sc,()=>Ws(Ys()),"order-types",_=>{Ws({...Ys(),..._}),te(!0)}),onBack:()=>{S("order-types"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="process-types-form")return Ye(t.jsx(f1,{form:lc,setForm:Bs,formStatus:Ke,viewMode:Qe||!p("process-types-form"),onEdit:p("process-types-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.processTypes,lc,()=>Bs(Xs()),"process-types",_=>{Bs({...Xs(),..._}),te(!0)}),onBack:()=>{S("process-types"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="incident-statuses-form")return Ye(t.jsx(x1,{form:rc,setForm:$s,formStatus:Ke,viewMode:Qe||!p("incident-statuses-form"),onEdit:p("incident-statuses-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.incidentStatuses,rc,()=>$s(qs()),"incident-statuses",_=>{$s({...qs(),..._}),te(!0)}),onBack:()=>{S("incident-statuses"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="idea-statuses-form")return Ye(t.jsx(v1,{form:ac,setForm:Us,formStatus:Ke,viewMode:Qe||!p("idea-statuses-form"),onEdit:p("idea-statuses-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.ideaStatuses,ac,()=>Us(Js()),"idea-statuses",_=>{Us({...Js(),..._}),te(!0)}),onBack:()=>{S("idea-statuses"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="order-statuses-form")return Ye(t.jsx(S1,{form:ic,setForm:Fs,formStatus:Ke,viewMode:Qe||!p("order-statuses-form"),onEdit:p("order-statuses-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.orderStatuses,ic,()=>Fs(Zs()),"order-statuses",_=>{Fs({...Zs(),..._}),te(!0)}),onBack:()=>{S("order-statuses"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="process-statuses-form")return Ye(t.jsx(_1,{form:oc,setForm:Ms,formStatus:Ke,viewMode:Qe||!p("process-statuses-form"),onEdit:p("process-statuses-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.processStatuses,oc,()=>Ms(Vs()),"process-statuses",_=>{Ms({...Vs(),..._}),te(!0)}),onBack:()=>{S("process-statuses"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="users-form")return Ye(t.jsx(E1,{form:Al,setForm:Nr,groupCompanies:fi,organizations:I,managements:Y,departments:q,branches:W,formStatus:Ke,viewMode:Qe||!p("users-form"),onEdit:p("users-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,isSelfProfile:Yd,onSubmit:gg,onBack:()=>{S(Yd?i?"dashboard":"inbox":"users"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="delegations-form")return Ye(t.jsx(U1,{form:Dn,setForm:Rl,organizations:I,users:B,userRoleMap:gn,incidents:b,ideas:F,formStatus:Ke,viewMode:Qe||!p("delegations-form"),onEdit:p("delegations-form")?()=>te(!1):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:Xh,onBack:()=>{S("delegations"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));if(g==="group-companies-form")return Ye(t.jsx(K0,{form:Qd,setForm:Ds,users:B,formStatus:Ke,viewMode:Qe||!p("group-companies-form"),onEdit:p("group-companies-form")?()=>te(!1):void 0,onRestore:a==="Admin"?_=>Dl(O.groupCompanies,_):void 0,darkMode:s,notifCount:z,onToggleDark:l,onCountChange:j,onViewProfile:Ue,onSubmit:()=>st(O.groupCompanies,Qd,()=>Ds(Lr()),"group-companies",_=>{Ds({...Lr(),..._}),te(!0)}),onBack:()=>{S("group-companies"),ie("idle")},onNavigate:S,onLogout:$e,user:e}));const yi={...r.pages,"group-companies":"Group Companies","group-companies-form":"Group Company Form"},xg={"group-companies":{color:G.purple,formPage:"group-companies-form",reset:()=>Ds(Lr())},incidents:{color:G.accent,formPage:"incidents-form",reset:()=>yn({...Sn(),organization:k||y})},ideas:{color:G.teal,formPage:"ideas-form",reset:()=>sn({...dn(),organization:k||y})},orders:{color:G.purple,formPage:"orders-form",reset:()=>ln({...cn(),organization:k||y})},processes:{color:G.blue,formPage:"processes-form",reset:()=>{const _=pi.create_processes,H=k||(a==="Manager"&&_&&_.length===1?_[0]:y);rn({...sa(),organization:H})}},organizations:{color:G.accent,formPage:"organizations-form",reset:()=>Ls(Gs())},managements:{color:G.blue,formPage:"managements-form",reset:()=>os({...fs(),organization:k||y})},departments:{color:G.teal,formPage:"departments-form",reset:()=>ds({...hs(),custom_organization:k||y})},branches:{color:G.purple,formPage:"branches-form",reset:()=>cs({...gs(),organization:k||y})},cycles:{color:G.teal,formPage:"cycles-form",reset:()=>us({...xs(),organization:k||y})},"kpi-input":{color:G.blue,formPage:"kpi-input-form",reset:()=>ps({...ms(),organization:k||y})},"incident-types":{color:G.red,formPage:"incident-types-form",reset:()=>Os(Ks())},"idea-types":{color:G.orange,formPage:"idea-types-form",reset:()=>Ns(Qs())},"order-types":{color:G.green,formPage:"order-types-form",reset:()=>Ws(Ys())},"process-types":{color:G.accent,formPage:"process-types-form",reset:()=>Bs(Xs())},"incident-statuses":{color:G.red,formPage:"incident-statuses-form",reset:()=>$s(qs())},"idea-statuses":{color:G.teal,formPage:"idea-statuses-form",reset:()=>Us(Js())},"order-statuses":{color:G.purple,formPage:"order-statuses-form",reset:()=>Fs(Zs())},"process-statuses":{color:G.blue,formPage:"process-statuses-form",reset:()=>Ms(Vs())},users:{color:G.blue,formPage:"users-form",reset:()=>{Nr(la()),Xd(!1)}},delegations:{color:G.purple,formPage:"delegations-form",reset:()=>Rl(Yl())}},mg={"group-companies":"New Group Company",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"},yg={incidents:b,ideas:F,orders:N,processes:P,organizations:I,managements:Y,departments:q,branches:W,cycles:xn,"kpi-input":Hd,"incident-types":de,"idea-types":oe,"order-types":ve,"process-types":fe,"incident-statuses":Et,"idea-statuses":L,"order-statuses":R,"process-statuses":ft,users:Be,delegations:Gd},Ll=Me[g],Ol=yg[g],ee=p(g),vi=ee?xg[g]:null;return t.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:s?"#0f172a":G.bg},children:[t.jsx(ih,{collapsed:vh,onToggleCollapsed:bh,activePage:g,onNavigate:_=>S(_),hasDashboard:i,hasReports:d,hasDelegations:c,role:a,rtl:r.rtl,navLabels:r.nav,settingsLabel:r.nav.settings}),t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[t.jsx("div",{style:{background:s?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${s?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:s?"none":"0 1px 4px rgba(0,0,0,0.04)"},children:t.jsx(uh,{notifCount:z,darkMode:s,onCountChange:j,onToggleDark:l,onNavigate:mi,onViewProfile:Ue,onLogout:$e,userName:e.full_name||e.name,userRole:a})}),g!=="profile"&&t.jsxs("div",{style:{background:s?"#1e293b":"white",padding:"12px 24px",borderBottom:`1px solid ${s?"#2d3748":"#e2e8f0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:18,fontWeight:700,color:s?"#e2e8f0":"#0f172a"},children:yi[g]||g}),Ol&&t.jsxs("div",{style:{fontSize:12,color:"#64748b",marginTop:2,fontWeight:500},children:["Total: ",Ol.length," ",yi[g]?yi[g].toLowerCase():"records"]})]}),t.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[Ll&&Ol&&t.jsx("button",{onClick:()=>hi(!0),style:{background:"#16a34a",color:"white",border:"none",padding:"7px 16px",borderRadius:8,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6,boxShadow:"0 1px 2px rgba(0,0,0,0.06)"},children:"📊 Export"}),vi&&t.jsxs("button",{onClick:()=>{vi.reset(),te(!1),ie("idle"),S(vi.formPage)},style:{background:"#2563eb",color:"white",border:"none",padding:"7px 16px",borderRadius:8,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6,boxShadow:"0 1px 2px rgba(0,0,0,0.06)"},children:["+ ",mg[g]||r.new]})]})]}),Ll&&Ol&&Sh&&t.jsx(ky,{title:Ll.label,rows:Ol,selectedRows:wh,pageRows:kh,columns:Ll.columns,defaultColumnKeys:Ll.defaultColumns,filenameBase:g,onClose:()=>hi(!1)}),t.jsxs("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",padding:g==="profile"?0:"20px 24px",gap:g==="profile"?0:16},children:[_e&&t.jsx("div",{style:{textAlign:"center",paddingTop:60,color:"#aaa",fontSize:15},children:r.loading}),!_e&&g==="dashboard"&&i&&t.jsx(h0,{incidents:b,ideas:F,orders:N,processes:P,organizations:I,incidentStatuses:Et,ideaStatuses:L,orderStatuses:R,processStatuses:ft,selectedOrg:y,onOrgChange:m,onNavigate:mi,onNavigateStatus:h,userRole:a}),!_e&&g==="inbox"&&t.jsx(F1,{onNavigate:mi,onRefresh:Pt}),!_e&&g==="reports"&&d&&t.jsx(Y1,{organizations:I,userRole:a}),!_e&&g==="incidents"&&t.jsx(g0,{incidents:b,organizations:I,departments:q,branches:W,incidentStatuses:Et,initialOrg:y,initialStatus:o,onView:Ch,onEdit:ee?Wh:void 0,onDelete:ee?_=>Ee(O.incidents,_):void 0,canModify:ee,userRole:a,onSelectionChange:(_,H)=>{gi(_),xi(H)}}),!_e&&g==="ideas"&&t.jsx(_0,{ideas:F,organizations:I,departments:q,branches:W,ideaStatuses:L,initialOrg:y,initialStatus:o,onView:zh,onEdit:ee?Bh:void 0,onDelete:ee?_=>Ee(O.ideas,_):void 0,canModify:ee,userRole:a,onSelectionChange:(_,H)=>{gi(_),xi(H)}}),!_e&&g==="orders"&&t.jsx(E0,{orders:N,organizations:I,departments:q,branches:W,orderStatuses:R,initialOrg:y,initialStatus:o,onView:Ih,onEdit:ee?$h:void 0,onDelete:ee?_=>Ee(O.orders,_):void 0,canModify:ee,userRole:a}),!_e&&g==="processes"&&t.jsx(D0,{processes:P,organizations:I,departments:q,branches:W,processStatuses:ft,initialOrg:y,initialStatus:o,onView:Eh,onEdit:ee?Uh:void 0,onDelete:ee?_=>Ee(O.processes,_):void 0,canModify:ee,userRole:a}),!_e&&g==="organizations"&&t.jsx(M0,{organizations:I,onView:Th,onEdit:ee?Fh:void 0,onDelete:ee?_=>Ee(O.organizations,_):void 0,canModify:ee}),!_e&&g==="group-companies"&&t.jsx(G0,{groupCompanies:fi,onView:Ph,onEdit:ee?Ah:void 0,onDelete:ee?_=>Ee(O.groupCompanies,_):void 0,canModify:ee}),!_e&&g==="managements"&&t.jsx(Y0,{managements:Y,onView:Rh,onEdit:ee?Mh:void 0,onDelete:ee?_=>Ee(O.managements,_):void 0,canModify:ee}),!_e&&g==="departments"&&t.jsx(J0,{departments:q,managements:Y,onView:Dh,onEdit:ee?Hh:void 0,onDelete:ee?_=>Ee(O.departments,_):void 0,canModify:ee}),!_e&&g==="branches"&&t.jsx(e1,{branches:W,managements:Y,departments:q,onView:Lh,onEdit:ee?Gh:void 0,onDelete:ee?_=>Ee(O.branches,_):void 0,canModify:ee}),!_e&&g==="cycles"&&t.jsx(T1,{cycles:xn,canModify:ee,onView:Oh,onEdit:ee?Kh:void 0,onDelete:ee?_=>Ee(O.cycles,_):void 0}),!_e&&g==="kpi-input"&&t.jsx(D1,{kpiInputs:Hd,canModify:ee,onView:Nh,onEdit:ee?Qh:void 0,onDelete:ee?_=>Ee(O.kpiInput,_):void 0}),!_e&&g==="incident-types"&&t.jsx(s1,{incidentTypes:de,onView:Jh,onEdit:ee?Zh:void 0,onDelete:ee?_=>Ee(O.incidentTypes,_):void 0,canModify:ee}),!_e&&g==="idea-types"&&t.jsx(a1,{ideaTypes:oe,onView:Vh,onEdit:ee?eg:void 0,onDelete:ee?_=>Ee(O.ideaTypes,_):void 0,canModify:ee}),!_e&&g==="order-types"&&t.jsx(d1,{orderTypes:ve,onView:tg,onEdit:ee?ng:void 0,onDelete:ee?_=>Ee(O.orderTypes,_):void 0,canModify:ee}),!_e&&g==="process-types"&&t.jsx(p1,{processTypes:fe,onView:sg,onEdit:ee?lg:void 0,onDelete:ee?_=>Ee(O.processTypes,_):void 0,canModify:ee}),!_e&&g==="incident-statuses"&&t.jsx(g1,{incidentStatuses:Et,onView:rg,onEdit:ee?ag:void 0,onDelete:ee?_=>Ee(O.incidentStatuses,_):void 0,canModify:ee}),!_e&&g==="idea-statuses"&&t.jsx(y1,{ideaStatuses:L,onView:ig,onEdit:ee?og:void 0,onDelete:ee?_=>Ee(O.ideaStatuses,_):void 0,canModify:ee}),!_e&&g==="order-statuses"&&t.jsx(b1,{orderStatuses:R,onView:dg,onEdit:ee?cg:void 0,onDelete:ee?_=>Ee(O.orderStatuses,_):void 0,canModify:ee}),!_e&&g==="process-statuses"&&t.jsx(k1,{processStatuses:ft,onView:ug,onEdit:ee?pg:void 0,onDelete:ee?_=>Ee(O.processStatuses,_):void 0,canModify:ee}),!_e&&g==="users"&&t.jsx(I1,{users:Be,roleMap:gn,onView:fg,onEdit:ee?hg:void 0,onDelete:ee?_=>Ee("User",_):void 0,onDisable:ee?_h:void 0,canModify:ee}),!_e&&g==="delegations"&&c&&t.jsx(B1,{delegations:Gd,organizations:I,userRole:a,currentUser:e.name,onView:Yh,onRevoke:ee?qh:void 0}),g==="profile"&&(()=>{const _=!!Or&&(Or.name===e.name||Or.email===e.name);return t.jsx($0,{user:e,profileUser:Or,sbUsers:Be,organizations:I,managements:Y,departments:q,branches:W,darkMode:s,canModify:ee||_,onBack:()=>S(_?i?"dashboard":"inbox":"users"),onNavigate:S})})()]})]}),t.jsx(_u,{isOpen:ht.isOpen,doctype:ht.doctype,docname:ht.name,docTitle:ht.title,isAdmin:a==="Admin"||e.name==="Administrator",isDeleting:ht.isDeleting,onClose:()=>jn(_=>({..._,isOpen:!1})),onConfirmSoftDelete:fc,onConfirmPermanentDelete:hc})]})}function sv(e){return e.some(n=>["SB Admin","System Manager"].includes(n))?"Admin":e.includes("SB Auditor")?"Auditor":e.includes("SB Owner")?"Owner":e.includes("SB X-Auditor")?"XAuditor":e.includes("SB Manager")?"Manager":"Employee"}function lv(){const[e,n]=C.useState(()=>{try{const d=localStorage.getItem("sidrah_user");return d?JSON.parse(d):null}catch{return null}}),[s,l]=C.useState(()=>localStorage.getItem("sb_dark")==="1"),r=()=>{const d=!s;l(d),localStorage.setItem("sb_dark",d?"1":"0"),document.documentElement.classList.toggle("dark",d)};C.useEffect(()=>{document.documentElement.classList.toggle("dark",s)},[]),C.useEffect(()=>{e&&oh().then(async d=>{const c=d||e.name,p=await ch(c);if(!p.length)return;const w=sv(p),v=await Uy();if(w!==e.role||c!==e.name||v!==(e.custom_organization||"")){const g={...e,name:c,role:w,custom_organization:v};n(g),localStorage.setItem("sidrah_user",JSON.stringify(g))}})},[e==null?void 0:e.name]);const a=d=>{n(d),localStorage.setItem("sidrah_user",JSON.stringify(d))},i=()=>{n(null),localStorage.removeItem("sidrah_user")};return e?t.jsx(nv,{user:e,onLogout:i,darkMode:s,onToggleDark:r}):t.jsx(o0,{onLogin:a})}th(document.getElementById("root")).render(t.jsx(C.StrictMode,{children:t.jsx(lv,{})}));