(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&s(a)}).observe(document,{childList:!0,subtree:!0});function l(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(r){if(r.ep)return;r.ep=!0;const i=l(r);fetch(r.href,i)}})();var vu={exports:{}},Pi={},ju={exports:{}},ae={};/** * @license React * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ar=Symbol.for("react.element"),hg=Symbol.for("react.portal"),gg=Symbol.for("react.fragment"),xg=Symbol.for("react.strict_mode"),mg=Symbol.for("react.profiler"),yg=Symbol.for("react.provider"),vg=Symbol.for("react.context"),jg=Symbol.for("react.forward_ref"),bg=Symbol.for("react.suspense"),Sg=Symbol.for("react.memo"),wg=Symbol.for("react.lazy"),Kc=Symbol.iterator;function kg(e){return e===null||typeof e!="object"?null:(e=Kc&&e[Kc]||e["@@iterator"],typeof e=="function"?e:null)}var bu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Su=Object.assign,wu={};function us(e,t,l){this.props=e,this.context=t,this.refs=wu,this.updater=l||bu}us.prototype.isReactComponent={};us.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};us.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function ku(){}ku.prototype=us.prototype;function To(e,t,l){this.props=e,this.context=t,this.refs=wu,this.updater=l||bu}var Po=To.prototype=new ku;Po.constructor=To;Su(Po,us.prototype);Po.isPureReactComponent=!0;var Qc=Array.isArray,_u=Object.prototype.hasOwnProperty,Io={current:null},Cu={key:!0,ref:!0,__self:!0,__source:!0};function zu(e,t,l){var s,r={},i=null,a=null;if(t!=null)for(s in t.ref!==void 0&&(a=t.ref),t.key!==void 0&&(i=""+t.key),t)_u.call(t,s)&&!Cu.hasOwnProperty(s)&&(r[s]=t[s]);var d=arguments.length-2;if(d===1)r.children=l;else if(1>>1,q=L[ne];if(0>>1;ner(re,K))zer(he,re)?(L[ne]=he,L[ze]=K,ne=ze):(L[ne]=re,L[Ce]=K,ne=Ce);else if(zer(he,K))L[ne]=he,L[ze]=K,ne=ze;else break e}}return M}function r(L,M){var K=L.sortIndex-M.sortIndex;return K!==0?K:L.id-M.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var a=Date,d=a.now();e.unstable_now=function(){return a.now()-d}}var u=[],f=[],y=1,p=null,c=3,v=!1,b=!1,g=!1,S=typeof setTimeout=="function"?setTimeout:null,h=typeof clearTimeout=="function"?clearTimeout:null,m=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function o(L){for(var M=l(f);M!==null;){if(M.callback===null)s(f);else if(M.startTime<=L)s(f),M.sortIndex=M.expirationTime,t(u,M);else break;M=l(f)}}function x(L){if(g=!1,o(L),!b)if(l(u)!==null)b=!0,xe(z);else{var M=l(f);M!==null&&le(x,M.startTime-L)}}function z(L,M){b=!1,g&&(g=!1,h(k),k=-1),v=!0;var K=c;try{for(o(M),p=l(u);p!==null&&(!(p.expirationTime>M)||L&&!I());){var ne=p.callback;if(typeof ne=="function"){p.callback=null,c=p.priorityLevel;var q=ne(p.expirationTime<=M);M=e.unstable_now(),typeof q=="function"?p.callback=q:p===l(u)&&s(u),o(M)}else s(u);p=l(u)}if(p!==null)var me=!0;else{var Ce=l(f);Ce!==null&&le(x,Ce.startTime-M),me=!1}return me}finally{p=null,c=K,v=!1}}var R=!1,P=null,k=-1,C=5,$=-1;function I(){return!(e.unstable_now()-$L||125ne?(L.sortIndex=K,t(f,L),l(u)===null&&L===l(f)&&(g?(h(k),k=-1):g=!0,le(x,K-ne))):(L.sortIndex=q,t(u,L),b||v||(b=!0,xe(z))),L},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(L){var M=c;return function(){var K=c;c=M;try{return L.apply(this,arguments)}finally{c=K}}}})(Au);Eu.exports=Au;var Og=Eu.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 Dg=j,bt=Og;function F(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,l=1;l"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ra=Object.prototype.hasOwnProperty,Ng=/^[: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={},Xc={};function Wg(e){return Ra.call(Xc,e)?!0:Ra.call(Yc,e)?!1:Ng.test(e)?Xc[e]=!0:(Yc[e]=!0,!1)}function Bg(e,t,l,s){if(l!==null&&l.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return s?!1:l!==null?!l.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function $g(e,t,l,s){if(t===null||typeof t>"u"||Bg(e,t,l,s))return!0;if(s)return!1;if(l!==null)switch(l.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function ot(e,t,l,s,r,i,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=s,this.attributeNamespace=r,this.mustUseProperty=l,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=a}var et={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){et[e]=new ot(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];et[t]=new ot(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){et[e]=new ot(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){et[e]=new ot(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){et[e]=new ot(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){et[e]=new ot(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){et[e]=new ot(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){et[e]=new ot(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){et[e]=new ot(e,5,!1,e.toLowerCase(),null,!1,!1)});var Ao=/[\-:]([a-z])/g;function Ro(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(Ao,Ro);et[t]=new ot(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(Ao,Ro);et[t]=new ot(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(Ao,Ro);et[t]=new ot(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){et[e]=new ot(e,1,!1,e.toLowerCase(),null,!1,!1)});et.xlinkHref=new ot("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){et[e]=new ot(e,1,!1,e.toLowerCase(),null,!0,!0)});function Lo(e,t,l,s){var r=et.hasOwnProperty(t)?et[t]:null;(r!==null?r.type!==0:s||!(2d||r[a]!==i[d]){var u=` `+r[a].replace(" at new "," at ");return e.displayName&&u.includes("")&&(u=u.replace("",e.displayName)),u}while(1<=a&&0<=d);break}}}finally{la=!1,Error.prepareStackTrace=l}return(e=e?e.displayName||e.name:"")?Is(e):""}function Ug(e){switch(e.tag){case 5:return Is(e.type);case 16:return Is("Lazy");case 13:return Is("Suspense");case 19:return Is("SuspenseList");case 0:case 2:case 15:return e=sa(e.type,!1),e;case 11:return e=sa(e.type.render,!1),e;case 1:return e=sa(e.type,!0),e;default:return""}}function Na(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 Bl:return"Fragment";case Wl:return"Portal";case La:return"Profiler";case Oo:return"StrictMode";case Oa:return"Suspense";case Da:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Ou:return(e.displayName||"Context")+".Consumer";case Lu:return(e._context.displayName||"Context")+".Provider";case Do:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case No:return t=e.displayName||null,t!==null?t:Na(e.type)||"Memo";case mn:t=e._payload,e=e._init;try{return Na(e(t))}catch{}}return null}function Fg(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Na(t);case 8:return t===Oo?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function An(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Nu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Mg(e){var t=Nu(e)?"checked":"value",l=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),s=""+e[t];if(!e.hasOwnProperty(t)&&typeof l<"u"&&typeof l.get=="function"&&typeof l.set=="function"){var r=l.get,i=l.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return r.call(this)},set:function(a){s=""+a,i.call(this,a)}}),Object.defineProperty(e,t,{enumerable:l.enumerable}),{getValue:function(){return s},setValue:function(a){s=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function wr(e){e._valueTracker||(e._valueTracker=Mg(e))}function Wu(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var l=t.getValue(),s="";return e&&(s=Nu(e)?e.checked?"true":"false":e.value),e=s,e!==l?(t.setValue(e),!0):!1}function si(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 Wa(e,t){var l=t.checked;return Ie({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:l??e._wrapperState.initialChecked})}function Jc(e,t){var l=t.defaultValue==null?"":t.defaultValue,s=t.checked!=null?t.checked:t.defaultChecked;l=An(t.value!=null?t.value:l),e._wrapperState={initialChecked:s,initialValue:l,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Bu(e,t){t=t.checked,t!=null&&Lo(e,"checked",t,!1)}function Ba(e,t){Bu(e,t);var l=An(t.value),s=t.type;if(l!=null)s==="number"?(l===0&&e.value===""||e.value!=l)&&(e.value=""+l):e.value!==""+l&&(e.value=""+l);else if(s==="submit"||s==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?$a(e,t.type,l):t.hasOwnProperty("defaultValue")&&$a(e,t.type,An(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Zc(e,t,l){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var s=t.type;if(!(s!=="submit"&&s!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,l||t===e.value||(e.value=t),e.defaultValue=t}l=e.name,l!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,l!==""&&(e.name=l)}function $a(e,t,l){(t!=="number"||si(e.ownerDocument)!==e)&&(l==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+l&&(e.defaultValue=""+l))}var Es=Array.isArray;function Jl(e,t,l,s){if(e=e.options,t){t={};for(var r=0;r"+t.valueOf().toString()+"",t=kr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Ks(e,t){if(t){var l=e.firstChild;if(l&&l===e.lastChild&&l.nodeType===3){l.nodeValue=t;return}}e.textContent=t}var Os={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},Hg=["Webkit","ms","Moz","O"];Object.keys(Os).forEach(function(e){Hg.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Os[t]=Os[e]})});function Mu(e,t,l){return t==null||typeof t=="boolean"||t===""?"":l||typeof t!="number"||t===0||Os.hasOwnProperty(e)&&Os[e]?(""+t).trim():t+"px"}function Hu(e,t){e=e.style;for(var l in t)if(t.hasOwnProperty(l)){var s=l.indexOf("--")===0,r=Mu(l,t[l],s);l==="float"&&(l="cssFloat"),s?e.setProperty(l,r):e[l]=r}}var Kg=Ie({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 Ma(e,t){if(t){if(Kg[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(F(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(F(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(F(61))}if(t.style!=null&&typeof t.style!="object")throw Error(F(62))}}function Ha(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Ka=null;function Wo(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Qa=null,Zl=null,Vl=null;function td(e){if(e=dr(e)){if(typeof Qa!="function")throw Error(F(280));var t=e.stateNode;t&&(t=Li(t),Qa(e.stateNode,e.type,t))}}function Ku(e){Zl?Vl?Vl.push(e):Vl=[e]:Zl=e}function Qu(){if(Zl){var e=Zl,t=Vl;if(Vl=Zl=null,td(e),t)for(e=0;e>>=0,e===0?32:31-(nx(e)/lx|0)|0}var _r=64,Cr=4194304;function As(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 oi(e,t){var l=e.pendingLanes;if(l===0)return 0;var s=0,r=e.suspendedLanes,i=e.pingedLanes,a=l&268435455;if(a!==0){var d=a&~r;d!==0?s=As(d):(i&=a,i!==0&&(s=As(i)))}else a=l&~r,a!==0?s=As(a):i!==0&&(s=As(i));if(s===0)return 0;if(t!==0&&t!==s&&!(t&r)&&(r=s&-s,i=t&-t,r>=i||r===16&&(i&4194240)!==0))return t;if(s&4&&(s|=l&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=s;0l;l++)t.push(e);return t}function or(e,t,l){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Bt(t),e[t]=l}function ax(e,t){var l=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var s=e.eventTimes;for(e=e.expirationTimes;0=Ns),dd=" ",ud=!1;function pp(e,t){switch(e){case"keyup":return Ox.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function fp(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var $l=!1;function Nx(e,t){switch(e){case"compositionend":return fp(t);case"keypress":return t.which!==32?null:(ud=!0,dd);case"textInput":return e=t.data,e===dd&&ud?null:e;default:return null}}function Wx(e,t){if($l)return e==="compositionend"||!Qo&&pp(e,t)?(e=dp(),Xr=Mo=bn=null,$l=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:l,offset:t-e};e=s}e:{for(;l;){if(l.nextSibling){l=l.nextSibling;break e}l=l.parentNode}l=void 0}l=gd(l)}}function mp(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?mp(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function yp(){for(var e=window,t=si();t instanceof e.HTMLIFrameElement;){try{var l=typeof t.contentWindow.location.href=="string"}catch{l=!1}if(l)e=t.contentWindow;else break;t=si(e.document)}return t}function Go(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function Gx(e){var t=yp(),l=e.focusedElem,s=e.selectionRange;if(t!==l&&l&&l.ownerDocument&&mp(l.ownerDocument.documentElement,l)){if(s!==null&&Go(l)){if(t=s.start,e=s.end,e===void 0&&(e=t),"selectionStart"in l)l.selectionStart=t,l.selectionEnd=Math.min(e,l.value.length);else if(e=(t=l.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var r=l.textContent.length,i=Math.min(s.start,r);s=s.end===void 0?i:Math.min(s.end,r),!e.extend&&i>s&&(r=s,s=i,i=r),r=xd(l,i);var a=xd(l,s);r&&a&&(e.rangeCount!==1||e.anchorNode!==r.node||e.anchorOffset!==r.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(r.node,r.offset),e.removeAllRanges(),i>s?(e.addRange(t),e.extend(a.node,a.offset)):(t.setEnd(a.node,a.offset),e.addRange(t)))}}for(t=[],e=l;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof l.focus=="function"&&l.focus(),l=0;l=document.documentMode,Ul=null,Za=null,Bs=null,Va=!1;function md(e,t,l){var s=l.window===l?l.document:l.nodeType===9?l:l.ownerDocument;Va||Ul==null||Ul!==si(s)||(s=Ul,"selectionStart"in s&&Go(s)?s={start:s.selectionStart,end:s.selectionEnd}:(s=(s.ownerDocument&&s.ownerDocument.defaultView||window).getSelection(),s={anchorNode:s.anchorNode,anchorOffset:s.anchorOffset,focusNode:s.focusNode,focusOffset:s.focusOffset}),Bs&&Js(Bs,s)||(Bs=s,s=ui(Za,"onSelect"),0Hl||(e.current=ro[Hl],ro[Hl]=null,Hl--)}function je(e,t){Hl++,ro[Hl]=e.current,e.current=t}var Rn={},st=Dn(Rn),pt=Dn(!1),rl=Rn;function ss(e,t){var l=e.type.contextTypes;if(!l)return Rn;var s=e.stateNode;if(s&&s.__reactInternalMemoizedUnmaskedChildContext===t)return s.__reactInternalMemoizedMaskedChildContext;var r={},i;for(i in l)r[i]=t[i];return s&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=r),r}function ft(e){return e=e.childContextTypes,e!=null}function fi(){Se(pt),Se(st)}function kd(e,t,l){if(st.current!==Rn)throw Error(F(168));je(st,t),je(pt,l)}function zp(e,t,l){var s=e.stateNode;if(t=t.childContextTypes,typeof s.getChildContext!="function")return l;s=s.getChildContext();for(var r in s)if(!(r in t))throw Error(F(108,Fg(e)||"Unknown",r));return Ie({},l,s)}function hi(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Rn,rl=st.current,je(st,e),je(pt,pt.current),!0}function _d(e,t,l){var s=e.stateNode;if(!s)throw Error(F(169));l?(e=zp(e,t,rl),s.__reactInternalMemoizedMergedChildContext=e,Se(pt),Se(st),je(st,e)):Se(pt),je(pt,l)}var ln=null,Oi=!1,ya=!1;function Tp(e){ln===null?ln=[e]:ln.push(e)}function rm(e){Oi=!0,Tp(e)}function Nn(){if(!ya&&ln!==null){ya=!0;var e=0,t=ge;try{var l=ln;for(ge=1;e>=a,r-=a,sn=1<<32-Bt(t)+r|l<k?(C=P,P=null):C=P.sibling;var $=c(h,P,o[k],x);if($===null){P===null&&(P=C);break}e&&P&&$.alternate===null&&t(h,P),m=i($,m,k),R===null?z=$:R.sibling=$,R=$,P=C}if(k===o.length)return l(h,P),_e&&Zn(h,k),z;if(P===null){for(;kk?(C=P,P=null):C=P.sibling;var I=c(h,P,$.value,x);if(I===null){P===null&&(P=C);break}e&&P&&I.alternate===null&&t(h,P),m=i(I,m,k),R===null?z=I:R.sibling=I,R=I,P=C}if($.done)return l(h,P),_e&&Zn(h,k),z;if(P===null){for(;!$.done;k++,$=o.next())$=p(h,$.value,x),$!==null&&(m=i($,m,k),R===null?z=$:R.sibling=$,R=$);return _e&&Zn(h,k),z}for(P=s(h,P);!$.done;k++,$=o.next())$=v(P,h,k,$.value,x),$!==null&&(e&&$.alternate!==null&&P.delete($.key===null?k:$.key),m=i($,m,k),R===null?z=$:R.sibling=$,R=$);return e&&P.forEach(function(E){return t(h,E)}),_e&&Zn(h,k),z}function S(h,m,o,x){if(typeof o=="object"&&o!==null&&o.type===Bl&&o.key===null&&(o=o.props.children),typeof o=="object"&&o!==null){switch(o.$$typeof){case Sr:e:{for(var z=o.key,R=m;R!==null;){if(R.key===z){if(z=o.type,z===Bl){if(R.tag===7){l(h,R.sibling),m=r(R,o.props.children),m.return=h,h=m;break e}}else if(R.elementType===z||typeof z=="object"&&z!==null&&z.$$typeof===mn&&Td(z)===R.type){l(h,R.sibling),m=r(R,o.props),m.ref=bs(h,R,o),m.return=h,h=m;break e}l(h,R);break}else t(h,R);R=R.sibling}o.type===Bl?(m=sl(o.props.children,h.mode,x,o.key),m.return=h,h=m):(x=li(o.type,o.key,o.props,null,h.mode,x),x.ref=bs(h,m,o),x.return=h,h=x)}return a(h);case Wl:e:{for(R=o.key;m!==null;){if(m.key===R)if(m.tag===4&&m.stateNode.containerInfo===o.containerInfo&&m.stateNode.implementation===o.implementation){l(h,m.sibling),m=r(m,o.children||[]),m.return=h,h=m;break e}else{l(h,m);break}else t(h,m);m=m.sibling}m=Ca(o,h.mode,x),m.return=h,h=m}return a(h);case mn:return R=o._init,S(h,m,R(o._payload),x)}if(Es(o))return b(h,m,o,x);if(xs(o))return g(h,m,o,x);Rr(h,o)}return typeof o=="string"&&o!==""||typeof o=="number"?(o=""+o,m!==null&&m.tag===6?(l(h,m.sibling),m=r(m,o),m.return=h,h=m):(l(h,m),m=_a(o,h.mode,x),m.return=h,h=m),a(h)):l(h,m)}return S}var is=Ap(!0),Rp=Ap(!1),mi=Dn(null),yi=null,Gl=null,Jo=null;function Zo(){Jo=Gl=yi=null}function Vo(e){var t=mi.current;Se(mi),e._currentValue=t}function oo(e,t,l){for(;e!==null;){var s=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,s!==null&&(s.childLanes|=t)):s!==null&&(s.childLanes&t)!==t&&(s.childLanes|=t),e===l)break;e=e.return}}function ts(e,t){yi=e,Jo=Gl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(ut=!0),e.firstContext=null)}function Pt(e){var t=e._currentValue;if(Jo!==e)if(e={context:e,memoizedValue:t,next:null},Gl===null){if(yi===null)throw Error(F(308));Gl=e,yi.dependencies={lanes:0,firstContext:e}}else Gl=Gl.next=e;return t}var tl=null;function ec(e){tl===null?tl=[e]:tl.push(e)}function Lp(e,t,l,s){var r=t.interleaved;return r===null?(l.next=l,ec(t)):(l.next=r.next,r.next=l),t.interleaved=l,dn(e,s)}function dn(e,t){e.lanes|=t;var l=e.alternate;for(l!==null&&(l.lanes|=t),l=e,e=e.return;e!==null;)e.childLanes|=t,l=e.alternate,l!==null&&(l.childLanes|=t),l=e,e=e.return;return l.tag===3?l.stateNode:null}var yn=!1;function tc(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Op(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function an(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Tn(e,t,l){var s=e.updateQueue;if(s===null)return null;if(s=s.shared,pe&2){var r=s.pending;return r===null?t.next=t:(t.next=r.next,r.next=t),s.pending=t,dn(e,l)}return r=s.interleaved,r===null?(t.next=t,ec(s)):(t.next=r.next,r.next=t),s.interleaved=t,dn(e,l)}function Jr(e,t,l){if(t=t.updateQueue,t!==null&&(t=t.shared,(l&4194240)!==0)){var s=t.lanes;s&=e.pendingLanes,l|=s,t.lanes=l,$o(e,l)}}function Pd(e,t){var l=e.updateQueue,s=e.alternate;if(s!==null&&(s=s.updateQueue,l===s)){var r=null,i=null;if(l=l.firstBaseUpdate,l!==null){do{var a={eventTime:l.eventTime,lane:l.lane,tag:l.tag,payload:l.payload,callback:l.callback,next:null};i===null?r=i=a:i=i.next=a,l=l.next}while(l!==null);i===null?r=i=t:i=i.next=t}else r=i=t;l={baseState:s.baseState,firstBaseUpdate:r,lastBaseUpdate:i,shared:s.shared,effects:s.effects},e.updateQueue=l;return}e=l.lastBaseUpdate,e===null?l.firstBaseUpdate=t:e.next=t,l.lastBaseUpdate=t}function vi(e,t,l,s){var r=e.updateQueue;yn=!1;var i=r.firstBaseUpdate,a=r.lastBaseUpdate,d=r.shared.pending;if(d!==null){r.shared.pending=null;var u=d,f=u.next;u.next=null,a===null?i=f:a.next=f,a=u;var y=e.alternate;y!==null&&(y=y.updateQueue,d=y.lastBaseUpdate,d!==a&&(d===null?y.firstBaseUpdate=f:d.next=f,y.lastBaseUpdate=u))}if(i!==null){var p=r.baseState;a=0,y=f=u=null,d=i;do{var c=d.lane,v=d.eventTime;if((s&c)===c){y!==null&&(y=y.next={eventTime:v,lane:0,tag:d.tag,payload:d.payload,callback:d.callback,next:null});e:{var b=e,g=d;switch(c=t,v=l,g.tag){case 1:if(b=g.payload,typeof b=="function"){p=b.call(v,p,c);break e}p=b;break e;case 3:b.flags=b.flags&-65537|128;case 0:if(b=g.payload,c=typeof b=="function"?b.call(v,p,c):b,c==null)break e;p=Ie({},p,c);break e;case 2:yn=!0}}d.callback!==null&&d.lane!==0&&(e.flags|=64,c=r.effects,c===null?r.effects=[d]:c.push(d))}else v={eventTime:v,lane:c,tag:d.tag,payload:d.payload,callback:d.callback,next:null},y===null?(f=y=v,u=p):y=y.next=v,a|=c;if(d=d.next,d===null){if(d=r.shared.pending,d===null)break;c=d,d=c.next,c.next=null,r.lastBaseUpdate=c,r.shared.pending=null}}while(!0);if(y===null&&(u=p),r.baseState=u,r.firstBaseUpdate=f,r.lastBaseUpdate=y,t=r.shared.interleaved,t!==null){r=t;do a|=r.lane,r=r.next;while(r!==t)}else i===null&&(r.shared.lanes=0);ol|=a,e.lanes=a,e.memoizedState=p}}function Id(e,t,l){if(e=t.effects,t.effects=null,e!==null)for(t=0;tl?l:4,e(!0);var s=ja.transition;ja.transition={};try{e(!1),t()}finally{ge=l,ja.transition=s}}function Zp(){return It().memoizedState}function cm(e,t,l){var s=In(e);if(l={lane:s,action:l,hasEagerState:!1,eagerState:null,next:null},Vp(e))ef(t,l);else if(l=Lp(e,t,l,s),l!==null){var r=it();$t(l,e,s,r),tf(l,t,s)}}function dm(e,t,l){var s=In(e),r={lane:s,action:l,hasEagerState:!1,eagerState:null,next:null};if(Vp(e))ef(t,r);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var a=t.lastRenderedState,d=i(a,l);if(r.hasEagerState=!0,r.eagerState=d,Ut(d,a)){var u=t.interleaved;u===null?(r.next=r,ec(t)):(r.next=u.next,u.next=r),t.interleaved=r;return}}catch{}finally{}l=Lp(e,t,r,s),l!==null&&(r=it(),$t(l,e,s,r),tf(l,t,s))}}function Vp(e){var t=e.alternate;return e===Pe||t!==null&&t===Pe}function ef(e,t){$s=bi=!0;var l=e.pending;l===null?t.next=t:(t.next=l.next,l.next=t),e.pending=t}function tf(e,t,l){if(l&4194240){var s=t.lanes;s&=e.pendingLanes,l|=s,t.lanes=l,$o(e,l)}}var Si={readContext:Pt,useCallback:tt,useContext:tt,useEffect:tt,useImperativeHandle:tt,useInsertionEffect:tt,useLayoutEffect:tt,useMemo:tt,useReducer:tt,useRef:tt,useState:tt,useDebugValue:tt,useDeferredValue:tt,useTransition:tt,useMutableSource:tt,useSyncExternalStore:tt,useId:tt,unstable_isNewReconciler:!1},um={readContext:Pt,useCallback:function(e,t){return Ht().memoizedState=[e,t===void 0?null:t],e},useContext:Pt,useEffect:Ad,useImperativeHandle:function(e,t,l){return l=l!=null?l.concat([e]):null,Vr(4194308,4,Gp.bind(null,t,e),l)},useLayoutEffect:function(e,t){return Vr(4194308,4,e,t)},useInsertionEffect:function(e,t){return Vr(4,2,e,t)},useMemo:function(e,t){var l=Ht();return t=t===void 0?null:t,e=e(),l.memoizedState=[e,t],e},useReducer:function(e,t,l){var s=Ht();return t=l!==void 0?l(t):t,s.memoizedState=s.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},s.queue=e,e=e.dispatch=cm.bind(null,Pe,e),[s.memoizedState,e]},useRef:function(e){var t=Ht();return e={current:e},t.memoizedState=e},useState:Ed,useDebugValue:cc,useDeferredValue:function(e){return Ht().memoizedState=e},useTransition:function(){var e=Ed(!1),t=e[0];return e=om.bind(null,e[1]),Ht().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,l){var s=Pe,r=Ht();if(_e){if(l===void 0)throw Error(F(407));l=l()}else{if(l=t(),qe===null)throw Error(F(349));al&30||Bp(s,t,l)}r.memoizedState=l;var i={value:l,getSnapshot:t};return r.queue=i,Ad(Up.bind(null,s,i,e),[e]),s.flags|=2048,rr(9,$p.bind(null,s,i,l,t),void 0,null),l},useId:function(){var e=Ht(),t=qe.identifierPrefix;if(_e){var l=rn,s=sn;l=(s&~(1<<32-Bt(s)-1)).toString(32)+l,t=":"+t+"R"+l,l=lr++,0<\/script>",e=e.removeChild(e.firstChild)):typeof s.is=="string"?e=a.createElement(l,{is:s.is}):(e=a.createElement(l),l==="select"&&(a=e,s.multiple?a.multiple=!0:s.size&&(a.size=s.size))):e=a.createElementNS(e,l),e[Kt]=t,e[er]=s,pf(e,t,!1,!1),t.stateNode=e;e:{switch(a=Ha(l,s),l){case"dialog":be("cancel",e),be("close",e),r=s;break;case"iframe":case"object":case"embed":be("load",e),r=s;break;case"video":case"audio":for(r=0;rcs&&(t.flags|=128,s=!0,Ss(i,!1),t.lanes=4194304)}else{if(!s)if(e=ji(a),e!==null){if(t.flags|=128,s=!0,l=e.updateQueue,l!==null&&(t.updateQueue=l,t.flags|=4),Ss(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!_e)return nt(t),null}else 2*Oe()-i.renderingStartTime>cs&&l!==1073741824&&(t.flags|=128,s=!0,Ss(i,!1),t.lanes=4194304);i.isBackwards?(a.sibling=t.child,t.child=a):(l=i.last,l!==null?l.sibling=a:t.child=a,i.last=a)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=Oe(),t.sibling=null,l=Te.current,je(Te,s?l&1|2:l&1),t):(nt(t),null);case 22:case 23:return gc(),s=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==s&&(t.flags|=8192),s&&t.mode&1?yt&1073741824&&(nt(t),t.subtreeFlags&6&&(t.flags|=8192)):nt(t),null;case 24:return null;case 25:return null}throw Error(F(156,t.tag))}function vm(e,t){switch(Xo(t),t.tag){case 1:return ft(t.type)&&fi(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return as(),Se(pt),Se(st),sc(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return lc(t),null;case 13:if(Se(Te),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(F(340));rs()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Se(Te),null;case 4:return as(),null;case 10:return Vo(t.type._context),null;case 22:case 23:return gc(),null;case 24:return null;default:return null}}var Or=!1,lt=!1,jm=typeof WeakSet=="function"?WeakSet:Set,Q=null;function Yl(e,t){var l=e.ref;if(l!==null)if(typeof l=="function")try{l(null)}catch(s){Ee(e,t,s)}else l.current=null}function yo(e,t,l){try{l()}catch(s){Ee(e,t,s)}}var Md=!1;function bm(e,t){if(eo=ci,e=yp(),Go(e)){if("selectionStart"in e)var l={start:e.selectionStart,end:e.selectionEnd};else e:{l=(l=e.ownerDocument)&&l.defaultView||window;var s=l.getSelection&&l.getSelection();if(s&&s.rangeCount!==0){l=s.anchorNode;var r=s.anchorOffset,i=s.focusNode;s=s.focusOffset;try{l.nodeType,i.nodeType}catch{l=null;break e}var a=0,d=-1,u=-1,f=0,y=0,p=e,c=null;t:for(;;){for(var v;p!==l||r!==0&&p.nodeType!==3||(d=a+r),p!==i||s!==0&&p.nodeType!==3||(u=a+s),p.nodeType===3&&(a+=p.nodeValue.length),(v=p.firstChild)!==null;)c=p,p=v;for(;;){if(p===e)break t;if(c===l&&++f===r&&(d=a),c===i&&++y===s&&(u=a),(v=p.nextSibling)!==null)break;p=c,c=p.parentNode}p=v}l=d===-1||u===-1?null:{start:d,end:u}}else l=null}l=l||{start:0,end:0}}else l=null;for(to={focusedElem:e,selectionRange:l},ci=!1,Q=t;Q!==null;)if(t=Q,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Q=e;else for(;Q!==null;){t=Q;try{var b=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(b!==null){var g=b.memoizedProps,S=b.memoizedState,h=t.stateNode,m=h.getSnapshotBeforeUpdate(t.elementType===t.type?g:Ot(t.type,g),S);h.__reactInternalSnapshotBeforeUpdate=m}break;case 3:var o=t.stateNode.containerInfo;o.nodeType===1?o.textContent="":o.nodeType===9&&o.documentElement&&o.removeChild(o.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(F(163))}}catch(x){Ee(t,t.return,x)}if(e=t.sibling,e!==null){e.return=t.return,Q=e;break}Q=t.return}return b=Md,Md=!1,b}function Us(e,t,l){var s=t.updateQueue;if(s=s!==null?s.lastEffect:null,s!==null){var r=s=s.next;do{if((r.tag&e)===e){var i=r.destroy;r.destroy=void 0,i!==void 0&&yo(t,l,i)}r=r.next}while(r!==s)}}function Wi(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var l=t=t.next;do{if((l.tag&e)===e){var s=l.create;l.destroy=s()}l=l.next}while(l!==t)}}function vo(e){var t=e.ref;if(t!==null){var l=e.stateNode;switch(e.tag){case 5:e=l;break;default:e=l}typeof t=="function"?t(e):t.current=e}}function gf(e){var t=e.alternate;t!==null&&(e.alternate=null,gf(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Kt],delete t[er],delete t[so],delete t[lm],delete t[sm])),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 xf(e){return e.tag===5||e.tag===3||e.tag===4}function Hd(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||xf(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 jo(e,t,l){var s=e.tag;if(s===5||s===6)e=e.stateNode,t?l.nodeType===8?l.parentNode.insertBefore(e,t):l.insertBefore(e,t):(l.nodeType===8?(t=l.parentNode,t.insertBefore(e,l)):(t=l,t.appendChild(e)),l=l._reactRootContainer,l!=null||t.onclick!==null||(t.onclick=pi));else if(s!==4&&(e=e.child,e!==null))for(jo(e,t,l),e=e.sibling;e!==null;)jo(e,t,l),e=e.sibling}function bo(e,t,l){var s=e.tag;if(s===5||s===6)e=e.stateNode,t?l.insertBefore(e,t):l.appendChild(e);else if(s!==4&&(e=e.child,e!==null))for(bo(e,t,l),e=e.sibling;e!==null;)bo(e,t,l),e=e.sibling}var Ze=null,Dt=!1;function gn(e,t,l){for(l=l.child;l!==null;)mf(e,t,l),l=l.sibling}function mf(e,t,l){if(Qt&&typeof Qt.onCommitFiberUnmount=="function")try{Qt.onCommitFiberUnmount(Ii,l)}catch{}switch(l.tag){case 5:lt||Yl(l,t);case 6:var s=Ze,r=Dt;Ze=null,gn(e,t,l),Ze=s,Dt=r,Ze!==null&&(Dt?(e=Ze,l=l.stateNode,e.nodeType===8?e.parentNode.removeChild(l):e.removeChild(l)):Ze.removeChild(l.stateNode));break;case 18:Ze!==null&&(Dt?(e=Ze,l=l.stateNode,e.nodeType===8?ma(e.parentNode,l):e.nodeType===1&&ma(e,l),Xs(e)):ma(Ze,l.stateNode));break;case 4:s=Ze,r=Dt,Ze=l.stateNode.containerInfo,Dt=!0,gn(e,t,l),Ze=s,Dt=r;break;case 0:case 11:case 14:case 15:if(!lt&&(s=l.updateQueue,s!==null&&(s=s.lastEffect,s!==null))){r=s=s.next;do{var i=r,a=i.destroy;i=i.tag,a!==void 0&&(i&2||i&4)&&yo(l,t,a),r=r.next}while(r!==s)}gn(e,t,l);break;case 1:if(!lt&&(Yl(l,t),s=l.stateNode,typeof s.componentWillUnmount=="function"))try{s.props=l.memoizedProps,s.state=l.memoizedState,s.componentWillUnmount()}catch(d){Ee(l,t,d)}gn(e,t,l);break;case 21:gn(e,t,l);break;case 22:l.mode&1?(lt=(s=lt)||l.memoizedState!==null,gn(e,t,l),lt=s):gn(e,t,l);break;default:gn(e,t,l)}}function Kd(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var l=e.stateNode;l===null&&(l=e.stateNode=new jm),t.forEach(function(s){var r=Im.bind(null,e,s);l.has(s)||(l.add(s),s.then(r,r))})}}function Lt(e,t){var l=t.deletions;if(l!==null)for(var s=0;sr&&(r=a),s&=~i}if(s=r,s=Oe()-s,s=(120>s?120:480>s?480:1080>s?1080:1920>s?1920:3e3>s?3e3:4320>s?4320:1960*wm(s/1960))-s,10e?16:e,Sn===null)var s=!1;else{if(e=Sn,Sn=null,_i=0,pe&6)throw Error(F(331));var r=pe;for(pe|=4,Q=e.current;Q!==null;){var i=Q,a=i.child;if(Q.flags&16){var d=i.deletions;if(d!==null){for(var u=0;uOe()-fc?ll(e,0):pc|=l),ht(e,t)}function _f(e,t){t===0&&(e.mode&1?(t=Cr,Cr<<=1,!(Cr&130023424)&&(Cr=4194304)):t=1);var l=it();e=dn(e,t),e!==null&&(or(e,t,l),ht(e,l))}function Pm(e){var t=e.memoizedState,l=0;t!==null&&(l=t.retryLane),_f(e,l)}function Im(e,t){var l=0;switch(e.tag){case 13:var s=e.stateNode,r=e.memoizedState;r!==null&&(l=r.retryLane);break;case 19:s=e.stateNode;break;default:throw Error(F(314))}s!==null&&s.delete(t),_f(e,l)}var Cf;Cf=function(e,t,l){if(e!==null)if(e.memoizedProps!==t.pendingProps||pt.current)ut=!0;else{if(!(e.lanes&l)&&!(t.flags&128))return ut=!1,mm(e,t,l);ut=!!(e.flags&131072)}else ut=!1,_e&&t.flags&1048576&&Pp(t,xi,t.index);switch(t.lanes=0,t.tag){case 2:var s=t.type;ei(e,t),e=t.pendingProps;var r=ss(t,st.current);ts(t,l),r=ic(null,t,s,e,r,l);var i=ac();return t.flags|=1,typeof r=="object"&&r!==null&&typeof r.render=="function"&&r.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,ft(s)?(i=!0,hi(t)):i=!1,t.memoizedState=r.state!==null&&r.state!==void 0?r.state:null,tc(t),r.updater=Ni,t.stateNode=r,r._reactInternals=t,uo(t,s,e,l),t=ho(null,t,s,!0,i,l)):(t.tag=0,_e&&i&&Yo(t),rt(null,t,r,l),t=t.child),t;case 16:s=t.elementType;e:{switch(ei(e,t),e=t.pendingProps,r=s._init,s=r(s._payload),t.type=s,r=t.tag=Am(s),e=Ot(s,e),r){case 0:t=fo(null,t,s,e,l);break e;case 1:t=$d(null,t,s,e,l);break e;case 11:t=Wd(null,t,s,e,l);break e;case 14:t=Bd(null,t,s,Ot(s.type,e),l);break e}throw Error(F(306,s,""))}return t;case 0:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Ot(s,r),fo(e,t,s,r,l);case 1:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Ot(s,r),$d(e,t,s,r,l);case 3:e:{if(cf(t),e===null)throw Error(F(387));s=t.pendingProps,i=t.memoizedState,r=i.element,Op(e,t),vi(t,s,null,l);var a=t.memoizedState;if(s=a.element,i.isDehydrated)if(i={element:s,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){r=os(Error(F(423)),t),t=Ud(e,t,s,l,r);break e}else if(s!==r){r=os(Error(F(424)),t),t=Ud(e,t,s,l,r);break e}else for(vt=zn(t.stateNode.containerInfo.firstChild),jt=t,_e=!0,Nt=null,l=Rp(t,null,s,l),t.child=l;l;)l.flags=l.flags&-3|4096,l=l.sibling;else{if(rs(),s===r){t=un(e,t,l);break e}rt(e,t,s,l)}t=t.child}return t;case 5:return Dp(t),e===null&&ao(t),s=t.type,r=t.pendingProps,i=e!==null?e.memoizedProps:null,a=r.children,no(s,r)?a=null:i!==null&&no(s,i)&&(t.flags|=32),of(e,t),rt(e,t,a,l),t.child;case 6:return e===null&&ao(t),null;case 13:return df(e,t,l);case 4:return nc(t,t.stateNode.containerInfo),s=t.pendingProps,e===null?t.child=is(t,null,s,l):rt(e,t,s,l),t.child;case 11:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Ot(s,r),Wd(e,t,s,r,l);case 7:return rt(e,t,t.pendingProps,l),t.child;case 8:return rt(e,t,t.pendingProps.children,l),t.child;case 12:return rt(e,t,t.pendingProps.children,l),t.child;case 10:e:{if(s=t.type._context,r=t.pendingProps,i=t.memoizedProps,a=r.value,je(mi,s._currentValue),s._currentValue=a,i!==null)if(Ut(i.value,a)){if(i.children===r.children&&!pt.current){t=un(e,t,l);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var d=i.dependencies;if(d!==null){a=i.child;for(var u=d.firstContext;u!==null;){if(u.context===s){if(i.tag===1){u=an(-1,l&-l),u.tag=2;var f=i.updateQueue;if(f!==null){f=f.shared;var y=f.pending;y===null?u.next=u:(u.next=y.next,y.next=u),f.pending=u}}i.lanes|=l,u=i.alternate,u!==null&&(u.lanes|=l),oo(i.return,l,t),d.lanes|=l;break}u=u.next}}else if(i.tag===10)a=i.type===t.type?null:i.child;else if(i.tag===18){if(a=i.return,a===null)throw Error(F(341));a.lanes|=l,d=a.alternate,d!==null&&(d.lanes|=l),oo(a,l,t),a=i.sibling}else a=i.child;if(a!==null)a.return=i;else for(a=i;a!==null;){if(a===t){a=null;break}if(i=a.sibling,i!==null){i.return=a.return,a=i;break}a=a.return}i=a}rt(e,t,r.children,l),t=t.child}return t;case 9:return r=t.type,s=t.pendingProps.children,ts(t,l),r=Pt(r),s=s(r),t.flags|=1,rt(e,t,s,l),t.child;case 14:return s=t.type,r=Ot(s,t.pendingProps),r=Ot(s.type,r),Bd(e,t,s,r,l);case 15:return rf(e,t,t.type,t.pendingProps,l);case 17:return s=t.type,r=t.pendingProps,r=t.elementType===s?r:Ot(s,r),ei(e,t),t.tag=1,ft(s)?(e=!0,hi(t)):e=!1,ts(t,l),nf(t,s,r),uo(t,s,r,l),ho(null,t,s,!0,e,l);case 19:return uf(e,t,l);case 22:return af(e,t,l)}throw Error(F(156,t.tag))};function zf(e,t){return Vu(e,t)}function Em(e,t,l,s){this.tag=e,this.key=l,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=s,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function zt(e,t,l,s){return new Em(e,t,l,s)}function mc(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Am(e){if(typeof e=="function")return mc(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Do)return 11;if(e===No)return 14}return 2}function En(e,t){var l=e.alternate;return l===null?(l=zt(e.tag,t,e.key,e.mode),l.elementType=e.elementType,l.type=e.type,l.stateNode=e.stateNode,l.alternate=e,e.alternate=l):(l.pendingProps=t,l.type=e.type,l.flags=0,l.subtreeFlags=0,l.deletions=null),l.flags=e.flags&14680064,l.childLanes=e.childLanes,l.lanes=e.lanes,l.child=e.child,l.memoizedProps=e.memoizedProps,l.memoizedState=e.memoizedState,l.updateQueue=e.updateQueue,t=e.dependencies,l.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},l.sibling=e.sibling,l.index=e.index,l.ref=e.ref,l}function li(e,t,l,s,r,i){var a=2;if(s=e,typeof e=="function")mc(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Bl:return sl(l.children,r,i,t);case Oo:a=8,r|=8;break;case La:return e=zt(12,l,t,r|2),e.elementType=La,e.lanes=i,e;case Oa:return e=zt(13,l,t,r),e.elementType=Oa,e.lanes=i,e;case Da:return e=zt(19,l,t,r),e.elementType=Da,e.lanes=i,e;case Du:return $i(l,r,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Lu:a=10;break e;case Ou:a=9;break e;case Do:a=11;break e;case No:a=14;break e;case mn:a=16,s=null;break e}throw Error(F(130,e==null?e:typeof e,""))}return t=zt(a,l,t,r),t.elementType=e,t.type=s,t.lanes=i,t}function sl(e,t,l,s){return e=zt(7,e,s,t),e.lanes=l,e}function $i(e,t,l,s){return e=zt(22,e,s,t),e.elementType=Du,e.lanes=l,e.stateNode={isHidden:!1},e}function _a(e,t,l){return e=zt(6,e,null,t),e.lanes=l,e}function Ca(e,t,l){return t=zt(4,e.children!==null?e.children:[],e.key,t),t.lanes=l,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Rm(e,t,l,s,r){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=ia(0),this.expirationTimes=ia(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ia(0),this.identifierPrefix=s,this.onRecoverableError=r,this.mutableSourceEagerHydrationData=null}function yc(e,t,l,s,r,i,a,d,u){return e=new Rm(e,t,l,d,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=zt(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:s,isDehydrated:l,cache:null,transitions:null,pendingSuspenseBoundaries:null},tc(i),e}function Lm(e,t,l){var s=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Ef)}catch(e){console.error(e)}}Ef(),Iu.exports=St;var Bm=Iu.exports,Af,Vd=Bm;Af=Vd.createRoot,Vd.hydrateRoot;const ce="",B={incidents:"SB Incident",ideas:"SB Idea",orders:"SB Order",organizations:"SB Organization",processes:"SB Process",managements:"Managements",departments:"Department",branches:"Branch",incidentTypes:"Incident Types",ideaTypes:"Idea Types",orderTypes:"Order Types",processTypes:"Process Types",incidentClass:"Incident Class",incidentField:"Incident Field",incidentStatuses:"Incident Statuses",ideaStatuses:"Idea Statuses",orderStatuses:"Order Statuses",processStatuses:"Process Statuses",users:"User",cycles:"SB Cycle",kpiInput:"SB KPI Input",delegations:"SB Delegation"},W={bg:"#f5f6fa",accent:"#4f46e5",red:"#ef4444",orange:"#f59e0b",green:"#16a34a",purple:"#7c3aed",blue:"#2563eb",teal:"#0d9488",gray:"#94a3b8"},$m=[{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"}],Um=[{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"}],Fm=new Set(["users"]);function Mm(e){return e!=="Admin"&&e!=="Auditor"?[]:Um.filter(({id:t})=>e==="Admin"||!Fm.has(t))}const xn=(e=[])=>[{key:"name1",label:"Name"},{key:"status",label:"Status"},...e,{key:"creation_date",label:"Created On"}],Hm={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:xn(),defaultColumns:["name1","status","creation_date"]},"idea-types":{label:"Idea Types",columns:xn(),defaultColumns:["name1","status","creation_date"]},"order-types":{label:"Order Types",columns:xn(),defaultColumns:["name1","status","creation_date"]},"process-types":{label:"Process Types",columns:xn(),defaultColumns:["name1","status","creation_date"]},"incident-statuses":{label:"Incident Statuses",columns:xn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"idea-statuses":{label:"Idea Statuses",columns:xn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"order-statuses":{label:"Order Statuses",columns:xn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"process-statuses":{label:"Process Statuses",columns:xn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},users:{label:"Users",orgField:"custom_organization",columns:[{key:"full_name",label:"Full Name"},{key:"email",label:"Email"},{key:"username",label:"Username"},{key:"mobile_no",label:"Phone"},{key:"custom_category",label:"Category"},{key:"custom_organization",label:"Organization"},{key:"custom_management",label:"Management"},{key:"custom_department",label:"Department"},{key:"custom_branch",label:"Branch"},{key:"custom_number",label:"User ID No"},{key:"enabled",label:"Active"},{key:"creation",label:"Created On"}],defaultColumns:["full_name","email","custom_category","custom_organization","enabled"]},delegations:{label:"Delegations",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"auditor",label:"Auditor"},{key:"manager",label:"Manager"},{key:"organization",label:"Organization"},{key:"create_processes",label:"Create Processes"},{key:"update_process_status",label:"Update Process Status"},{key:"status",label:"Status"},{key:"requested_on",label:"Requested On"},{key:"responded_on",label:"Responded On"}],defaultColumns:["number","auditor","manager","organization","status","requested_on"]}},Km="modulepreload",Qm=function(e){return"/"+e},eu={},Gm=function(t,l,s){let r=Promise.resolve();if(l&&l.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),d=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));r=Promise.allSettled(l.map(u=>{if(u=Qm(u),u in eu)return;eu[u]=!0;const f=u.endsWith(".css"),y=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${y}`))return;const p=document.createElement("link");if(p.rel=f?"stylesheet":Km,f||(p.as="script"),p.crossOrigin="",p.href=u,d&&p.setAttribute("nonce",d),document.head.appendChild(p),f)return new Promise((c,v)=>{p.addEventListener("load",c),p.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(a){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=a,window.dispatchEvent(d),!d.defaultPrevented)throw a}return r.then(a=>{for(const d of a||[])d.status==="rejected"&&i(d.reason);return t().catch(i)})};function Rf(e,t){const l=e[t.key];return l==null||l===""?"":typeof l=="object"?JSON.stringify(l):String(l)}function Ym(e,t){const l=URL.createObjectURL(e),s=document.createElement("a");s.href=l,s.download=t,s.click(),URL.revokeObjectURL(l)}function Xm(e,t,l){const s=e.map(a=>`"${a.label.replace(/"/g,'""')}"`).join(","),r=t.map(a=>e.map(d=>`"${Rf(a,d).replace(/"/g,'""')}"`).join(",")).join(` `),i=new Blob([s+` `+r],{type:"text/csv;charset=utf-8;"});Ym(i,`${l}.csv`)}async function qm(e,t,l){const s=await Gm(()=>import("./xlsx-D_0l8YDs.js"),[]),r=t.map(d=>{const u={};for(const f of e)u[f.label]=Rf(d,f);return u}),i=s.utils.json_to_sheet(r,{header:e.map(d=>d.label)}),a=s.utils.book_new();s.utils.book_append_sheet(a,i,"Export"),s.writeFile(a,`${l}.xlsx`)}const Wr="#16a34a";function Jm({title:e,rows:t,columns:l,defaultColumnKeys:s,orgField:r,organizations:i,filenameBase:a,onClose:d}){const[u,f]=j.useState(""),[y,p]=j.useState("csv"),[c,v]=j.useState(new Set(s)),b=u?t.filter(x=>x[r||"organization"]===u):t,g=l.filter(x=>c.has(x.key)),S=x=>{v(z=>{const R=new Set(z);return R.has(x)?R.delete(x):R.add(x),R})},h=async()=>{g.length===0||b.length===0||(y==="csv"?Xm(g,b,a):await qm(g,b,a),d())},m={fontSize:11,fontWeight:700,color:"#9ca3af",letterSpacing:.4,textTransform:"uppercase",marginBottom:10},o={background:"none",border:"none",color:"#2563eb",fontSize:12,fontWeight:600,cursor:"pointer",padding:0,fontFamily:"inherit"};return n.jsx("div",{onClick:d,style:{position:"fixed",inset:0,background:"rgba(15,23,42,0.55)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e4},children:n.jsxs("div",{onClick:x=>x.stopPropagation(),style:{width:560,maxWidth:"92vw",maxHeight:"86vh",background:"white",borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[n.jsxs("div",{style:{background:Wr,color:"white",padding:"16px 22px",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,fontSize:16,fontWeight:700},children:[n.jsx("span",{style:{fontSize:18},children:"📤"})," Export ",e]}),n.jsx("button",{onClick:d,style:{background:"rgba(255,255,255,0.15)",border:"none",color:"white",width:28,height:28,borderRadius:8,cursor:"pointer",fontSize:15,lineHeight:1},children:"✕"})]}),n.jsxs("div",{style:{padding:"20px 22px",overflowY:"auto",flex:1},children:[r&&i&&i.length>0&&n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:m,children:"Filter by Organization"}),n.jsxs("select",{value:u,onChange:x=>f(x.target.value),style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",boxSizing:"border-box"},children:[n.jsxs("option",{value:"",children:["All Organizations (",t.length," total)"]}),i.map(x=>n.jsx("option",{value:x.name,children:x.organization_name||x.name},x.name))]})]}),n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:m,children:"File Format"}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[{id:"csv",label:"CSV",desc:"Comma-separated values"},{id:"xlsx",label:"Excel",desc:"XLSX spreadsheet"}].map(x=>n.jsxs("div",{onClick:()=>p(x.id),style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",borderRadius:10,cursor:"pointer",border:`2px solid ${y===x.id?Wr:"#e5e7eb"}`,background:y===x.id?"#f0fdf4":"white"},children:[n.jsx("span",{style:{fontSize:20},children:x.id==="csv"?"📄":"📊"}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:x.label}),n.jsx("div",{style:{fontSize:11,color:"#888"},children:x.desc})]})]},x.id))})]}),n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[n.jsx("div",{style:{...m,marginBottom:0},children:"Columns to Export"}),n.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[n.jsx("button",{onClick:()=>v(new Set(l.map(x=>x.key))),style:o,children:"Select All"}),n.jsx("span",{style:{color:"#d1d5db"},children:"|"}),n.jsx("button",{onClick:()=>v(new Set(s)),style:o,children:"Reset to Default"})]})]}),n.jsx("div",{style:{border:"1px solid #e5e7eb",borderRadius:8,padding:12,maxHeight:170,overflowY:"auto"},children:n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:"10px 12px"},children:l.map(x=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:7,fontSize:13,color:"#374151",cursor:"pointer"},children:[n.jsx("input",{type:"checkbox",checked:c.has(x.key),onChange:()=>S(x.key),style:{accentColor:Wr,cursor:"pointer"}}),x.label]},x.key))})}),n.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:6},children:[c.size," column",c.size!==1?"s":""," selected"]})]})]}),n.jsxs("div",{style:{padding:"14px 22px",borderTop:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[n.jsx("span",{style:{fontSize:12,color:"#888"},children:u?`Exporting ${b.length} filtered row${b.length!==1?"s":""}`:`Exporting all ${b.length} row${b.length!==1?"s":""}`}),n.jsxs("div",{style:{display:"flex",gap:10},children:[n.jsx("button",{onClick:d,style:{padding:"9px 18px",borderRadius:8,border:"1px solid #e5e7eb",background:"white",color:"#374151",fontWeight:600,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:"Cancel"}),n.jsx("button",{onClick:h,disabled:g.length===0||b.length===0,style:{padding:"9px 20px",borderRadius:8,border:"none",background:Wr,color:"white",fontWeight:700,fontSize:13,cursor:g.length===0||b.length===0?"not-allowed":"pointer",opacity:g.length===0||b.length===0?.5:1,fontFamily:"inherit",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"})]})]})]})})}function Lf({collapsed:e,onToggleCollapsed:t,activePage:l,onNavigate:s,hasDashboard:r,hasReports:i,hasDelegations:a,role:d,hideSettings:u,rtl:f,navLabels:y,settingsLabel:p}){const c=u?[]:Mm(d);return n.jsxs("div",{style:{width:e?58:230,background:"linear-gradient(175deg, #1a0f42 0%, #2a1260 45%, #102840 100%)",color:"white",flexShrink:0,display:"flex",flexDirection:"column",position:"sticky",top:0,height:"100vh",transition:"width 0.22s ease",overflow:"hidden"},children:[n.jsxs("div",{style:{padding:e?"16px 0":"16px 20px 14px",borderBottom:"1px solid rgba(255,255,255,0.08)",display:"flex",alignItems:"center",justifyContent:e?"center":"space-between",gap:8,flexShrink:0},children:[!e&&n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,overflow:"hidden"},children:[n.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"linear-gradient(135deg, #312e81 0%, #4f46e5 100%)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:n.jsx("span",{style:{fontSize:16,color:"white",fontWeight:800,fontFamily:"serif"},children:"S"})}),n.jsx("span",{style:{fontSize:16,fontWeight:700,whiteSpace:"nowrap",color:"white"},children:f?"صدرة":"Sidrah"})]}),n.jsx("button",{onClick:t,title:e?f?"توسيع":"Expand":f?"طي":"Collapse",style:{background:"rgba(255,255,255,0.08)",border:"none",borderRadius:7,color:"rgba(255,255,255,0.7)",cursor:"pointer",fontSize:12,padding:"5px 8px",flexShrink:0,lineHeight:1,transition:"background 0.15s"},children:e?"▶":"✕"})]}),n.jsxs("nav",{style:{padding:"12px 8px",flex:1,overflowY:"auto",overflowX:"hidden"},children:[$m.filter(({id:v})=>(v!=="dashboard"||r)&&(v!=="reports"||i)&&(v!=="delegations"||a)).map(({id:v,icon:b})=>{const g=y[v]||v,S=v===l;return n.jsxs("div",{onClick:()=>s(v),title:e?g:void 0,style:{padding:e?"8px 0":"8px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:9,background:S?"rgba(139,92,246,0.28)":"transparent",borderRadius:8,fontSize:e?15:12,color:"white",fontWeight:S?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{flexShrink:0},children:b}),!e&&g]},v)}),c.length>0&&n.jsxs(n.Fragment,{children:[!e&&n.jsx("div",{style:{padding:"10px 14px 4px",fontSize:10,color:"rgba(255,255,255,0.6)",fontWeight:700,letterSpacing:1,textTransform:"uppercase",marginTop:8},children:p}),e&&n.jsx("div",{style:{margin:"10px auto",width:28,borderTop:"1px solid rgba(255,255,255,0.12)"}}),c.map(({id:v,icon:b})=>{const g=y[v]||v,S=v===l;return n.jsxs("div",{onClick:()=>s(v),title:e?g:void 0,style:{padding:e?"8px 0":"8px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:9,background:S?"rgba(139,92,246,0.25)":"transparent",borderRadius:8,fontSize:e?15:12,color:"white",fontWeight:S?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{flexShrink:0},children:b}),!e&&g]},v)})]})]})]})}const Of="sidrah_rtl",Co="sidrah-lang-change";function ql(){try{return localStorage.getItem(Of)==="1"}catch{return!1}}function Df(){const e=!ql();try{localStorage.setItem(Of,e?"1":"0")}catch{}document.documentElement.setAttribute("dir",e?"rtl":"ltr"),document.documentElement.setAttribute("lang",e?"ar":"en-GB"),window.dispatchEvent(new CustomEvent(Co))}function ee(){const[e,t]=j.useState(ql);return j.useEffect(()=>{const l=()=>t(ql());return window.addEventListener(Co,l),document.documentElement.setAttribute("dir",ql()?"rtl":"ltr"),document.documentElement.setAttribute("lang",ql()?"ar":"en-GB"),()=>window.removeEventListener(Co,l)},[]),e?Vm:Zm}const Zm={rtl:!1,nav:{dashboard:"Dashboard",inbox:"Inbox",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",reports:"Reports",users:"Users",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",settings:"Settings"},pages:{dashboard:"Dashboard",inbox:"Inbox",reports:"Reports",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",users:"Users"},new:"+ New",save:"Save",cancel:"Cancel",edit:"Edit",delete:"Delete",view:"View",back:"← Back",clear:"Clear",search:"Search",loading:"Loading...",saving:"Saving...",savedOk:"Saved successfully!",home:"Home",noRecords:"No records found",login:{subtitle:"Sign in to continue",username:"USERNAME",password:"PASSWORD",usernamePlaceholder:"Enter username",passwordPlaceholder:"Enter password",signIn:"Sign In",signingIn:"Signing in...",invalidCreds:"Invalid username or password",emptyFields:"Please enter username and password",connError:"Connection error: "},myProfile:"My Profile",signOut:"Sign Out",switchLang:"العربية (RTL)",filter:{numberTitle:"Number / Title",searchPlaceholder:"Search...",organization:"Organization",department:"Department",branch:"Branch",status:"Status",allOrgs:"All Organizations",allDepts:"All Departments",allBranches:"All Branches",allStatuses:"All Statuses",allTypes:"All Types"},col:{number:"Number",title:"Title",organization:"Organization",type:"Type",status:"Status",actions:"Actions",name:"Name",department:"Department",branch:"Branch",city:"City",email:"Email",management:"Management",organization_type:"Type",frequency:"Frequency",period:"Period",startDate:"Start Date",endDate:"End Date",auditor:"Auditor",manager:"Manager",functions:"Functions",requestedOn:"Requested On"},field:{number:"Number",title:"Title",organization:"Organization",management:"Management",department:"Department",section:"Section",branch:"Branch",type:"Type",date:"Date",time:"Time",status:"Status",description:"Description",assignedTo:"Assigned To",hsesField:"HSES Field",priority:"Priority",economyClass:"Economy Class",entityScope:"Entity Scope",productRelation:"Product Relation",repeatedEvent:"Repeated Event",solution:"Solution / Action Plan",actualCost:"Actual Cost",summary:"Resolution Summary",auditorComment:"Auditor Comment",incidentClass:"Incident Class",incidentField:"Incident Field",currentCondition:"Current Condition",proposedCondition:"Proposed Condition",ideaClass:"Idea Class",startingDate:"Starting Date",endingDate:"Ending Date",budget:"Budget",currency:"Currency",notes:"Notes",cycle:"Cycle",stage:"Stage",completionPct:"Completion %",actor:"Actor",escalationLevel:"Escalation Level",dateStart:"Start Date",dateEnd:"End Date",cycleType:"Cycle Type",progressIndicators:"Progress Indicators",impactLevel:"Impact Level",kpiName:"KPI Name",kpiType:"KPI Type",kpiMeasure:"KPI Measure",costPerCycle:"Cost per Cycle",chainLocation:"Chain Location",notifyManager:"Notify Manager",creationDate:"Creation Date",statusActive:"Active",statusInactive:"Inactive",name1:"Name",fullName:"Full Name",username:"Username",emailAddress:"Email Address",phoneNumber:"Phone Number",category:"Category",since:"Since",active:"Active",inactive:"Inactive",enabled:"Enabled",selectMgr:"-- Select manager --",select:"-- Select --",selectType:"-- Select type --",selectClass:"-- Select class --",selectField:"-- Select field --",selectStatus:"-- Select status --",solutionPlaceholder:"Describe the solution or action taken…",commentPlaceholder:"Optional comment…",high:"High",normal:"Normal",expenses:"Expenses",capital:"Capital",earn:"Earn",payLoss:"Pay/Loss",upstream:"Upstream",onstream:"On-stream",downstream:"Downstream",government:"Government",private:"Private",monthly:"Monthly",quarterly:"Quarterly",yearly:"Yearly",cycleActive:"Active",cycleCompleted:"Completed",cyclePaused:"Paused",updateWindowDays:"Update Window (days)",incidentTriageWindowDays:"Triage Window (days)",incidentResolutionWindowDays:"Resolution Window (days)",orgAcronym:"Acronym",contactEmail:"Contact Email",orgCity:"City",orgName:"Organization Name",organizationType:"Organization Type",revenue_growth:"Revenue Growth (%)",net_profit:"Net Profit",cash_flow:"Cash Flow",strategic_goal_pct:"Strategic Goal (%)",customer_satisfaction:"Customer Satisfaction",employee_turnover_pct:"Employee Turnover (%)",open_safety_incidents:"Open Safety Incidents",compliance_score:"Compliance Score"},wf:{workflow:"Workflow",noActions:"No actions available for your role in this state.",applying:"Applying…",submit:"Submit",assignToManager:"Assign to Manager",reject:"Reject",submitSolution:"Submit Solution",resolutionComplete:"Resolution complete",moveToOutsourcing:"Move to Outsourcing",closeIdea:"Close Idea"},steps:{auditorTriage:"Auditor Triage (Step 2)",managerSolution:"Manager Solution (Step 3)",ownerComment:"Owner / Auditor Comment (Step 4)",auditorEval:"Auditor Evaluation (Step 2)",managerReview:"Manager Review (Step 3)"},formTitle:{newIncident:"New Incident",editIncident:"Edit Incident",viewIncident:"Incident: ",newIdea:"New Idea",editIdea:"Edit Idea",viewIdea:"Idea: ",newOrder:"New Order",editOrder:"Edit Order",viewOrder:"Order: ",newProcess:"New Process",editProcess:"Edit Process",viewProcess:"Process: ",newOrg:"New Organization",editOrg:"Edit Organization",newMgmt:"New Management",editMgmt:"Edit Management",newDept:"New Department",editDept:"Edit Department",newBranch:"New Branch",editBranch:"Edit Branch",newUser:"New User",editUser:"Edit User",viewUser:"User Profile",newCycle:"New Cycle",editCycle:"Edit Cycle",newKpi:"New KPI Input",editKpi:"Edit KPI Input",newDelegation:"New Delegation",viewDelegation:"Delegation: "},saveIncident:"Save Incident",saveIdea:"Save Idea",saveOrder:"Save Order",saveProcess:"Save Process",saveOrg:"Save Organization",saveMgmt:"Save Management",saveDept:"Save Department",saveBranch:"Save Branch",saveUser:"Save User",saveCycle:"Save Cycle",saveKpi:"Save KPI Input",saveDelegation:"Send Delegation",saveName:"Save",dash:{allOrgs:"All organizations",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",level2:"Level 2 — Critical Escalation",level1:"Level 1 — Auditor Review Needed",overduePrefix:"Overdue for Triage — ",overdueSuffix:" incident(s) past 3-day window",untriaged:"Untriaged Incidents",recentKpi:"Recent KPI Inputs",manageKpi:"Manage KPI Inputs",escalatedProcesses:"Escalated Processes",escalatedOrders:"Escalated Orders",level:"Level",revenueGrowth:"Revenue Growth",netProfit:"Net Profit",strategicGoal:"Strategic Goal",customerSat:"Customer Sat.",compliance:"Compliance",safetyInc:"Safety Incidents",total:"Total"},noIncidents:"No incidents found",noIdeas:"No ideas found",noOrders:"No orders found",noProcesses:"No processes found",noUsers:"No users found",noData:"No data found",users:{category:"Category",number:"Number",fullName:"Full Name",username:"Username",email:"Email Address",phone:"Phone Number",organization:"Organization",management:"Management",department:"Department",branch:"Branch",since:"Since",status:"Status",tools:"Tools",active:"Active",inactive:"Inactive",setPassword:"Set Password",newPassword:"New password",passwordUpdated:"Password updated!",passwordFailed:"Failed. Please try again.",disableConfirm:"Delete user? They will no longer appear in the list.",password:"Password"},inbox:{title:"Inbox",noMessages:"No messages"},reports:{title:"Reports",selectOrg:"Select Organization",generate:"Generate Report"},comments:{title:"Comments",placeholder:"Write a comment…",post:"Post",noComments:"No comments yet."},activity:{title:"Activity Log",created:"Created",by:"by"}},Vm={rtl:!0,nav:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",reports:"التقارير",users:"المستخدمون",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",settings:"الإعدادات"},pages:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",reports:"التقارير",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",users:"المستخدمون"},new:"+ جديد",save:"حفظ",cancel:"إلغاء",edit:"تعديل",delete:"حذف",view:"عرض",back:"رجوع →",clear:"مسح",search:"بحث",loading:"جارٍ التحميل...",saving:"جارٍ الحفظ...",savedOk:"تم الحفظ بنجاح!",home:"الرئيسية",noRecords:"لا توجد سجلات",login:{subtitle:"تسجيل الدخول للمتابعة",username:"اسم المستخدم",password:"كلمة المرور",usernamePlaceholder:"أدخل اسم المستخدم",passwordPlaceholder:"أدخل كلمة المرور",signIn:"تسجيل الدخول",signingIn:"جارٍ تسجيل الدخول...",invalidCreds:"اسم المستخدم أو كلمة المرور غير صحيحة",emptyFields:"الرجاء إدخال اسم المستخدم وكلمة المرور",connError:"خطأ في الاتصال: "},myProfile:"ملفي الشخصي",signOut:"تسجيل الخروج",switchLang:"English (LTR)",filter:{numberTitle:"الرقم / العنوان",searchPlaceholder:"بحث...",organization:"المؤسسة",department:"القسم",branch:"الفرع",status:"الحالة",allOrgs:"جميع المؤسسات",allDepts:"جميع الأقسام",allBranches:"جميع الفروع",allStatuses:"جميع الحالات",allTypes:"جميع الأنواع"},col:{number:"الرقم",title:"العنوان",organization:"المؤسسة",type:"النوع",status:"الحالة",actions:"الإجراءات",name:"الاسم",department:"القسم",branch:"الفرع",city:"المدينة",email:"البريد الإلكتروني",management:"الإدارة",organization_type:"النوع",frequency:"التكرار",period:"الفترة",startDate:"تاريخ البدء",endDate:"تاريخ الانتهاء",auditor:"المدقق",manager:"المدير",functions:"الوظائف",requestedOn:"تاريخ الطلب"},field:{number:"الرقم",title:"العنوان",organization:"المؤسسة",management:"الإدارة",department:"القسم",section:"القطاع",branch:"الفرع",type:"النوع",date:"التاريخ",time:"الوقت",status:"الحالة",description:"الوصف",assignedTo:"مُسند إلى",hsesField:"مجال السلامة والصحة",priority:"الأولوية",economyClass:"التصنيف الاقتصادي",entityScope:"نطاق الكيان",productRelation:"علاقة المنتج",repeatedEvent:"حدث متكرر",solution:"الحل / خطة العمل",actualCost:"التكلفة الفعلية",summary:"ملخص الحل",auditorComment:"تعليق المدقق",incidentClass:"تصنيف الحادث",incidentField:"مجال الحادث",currentCondition:"الوضع الراهن",proposedCondition:"الوضع المقترح",ideaClass:"تصنيف الفكرة",startingDate:"تاريخ البدء",endingDate:"تاريخ الانتهاء",budget:"الميزانية",currency:"العملة",notes:"الملاحظات",cycle:"الدورة",stage:"المرحلة",completionPct:"نسبة الاكتمال",actor:"المنفذ",escalationLevel:"مستوى التصعيد",dateStart:"تاريخ البدء",dateEnd:"تاريخ الانتهاء",cycleType:"نوع الدورة",progressIndicators:"مؤشرات التقدم",impactLevel:"مستوى التأثير",kpiName:"اسم المؤشر",kpiType:"نوع المؤشر",kpiMeasure:"قياس المؤشر",costPerCycle:"التكلفة لكل دورة",chainLocation:"موقع السلسلة",notifyManager:"إشعار المدير",creationDate:"تاريخ الإنشاء",statusActive:"نشط",statusInactive:"غير نشط",name1:"الاسم",fullName:"الاسم الكامل",username:"اسم المستخدم",emailAddress:"البريد الإلكتروني",phoneNumber:"رقم الهاتف",category:"الفئة",since:"منذ",active:"نشط",inactive:"غير نشط",enabled:"مفعّل",selectMgr:"-- اختر المدير --",select:"-- اختر --",selectType:"-- اختر النوع --",selectClass:"-- اختر التصنيف --",selectField:"-- اختر المجال --",selectStatus:"-- اختر الحالة --",solutionPlaceholder:"صف الحل أو الإجراء المتخذ…",commentPlaceholder:"تعليق اختياري…",high:"عالي",normal:"عادي",expenses:"مصروفات",capital:"رأس مال",earn:"إيرادات",payLoss:"دفع/خسارة",upstream:"مرحلة المنبع",onstream:"على الخط",downstream:"مرحلة المصب",government:"حكومي",private:"خاص",monthly:"شهري",quarterly:"ربع سنوي",yearly:"سنوي",cycleActive:"نشط",cycleCompleted:"مكتمل",cyclePaused:"موقوف",updateWindowDays:"نافذة التحديث (أيام)",incidentTriageWindowDays:"نافذة الفرز (أيام)",incidentResolutionWindowDays:"نافذة الحل (أيام)",orgAcronym:"الاختصار",contactEmail:"البريد الإلكتروني للتواصل",orgCity:"المدينة",orgName:"اسم المؤسسة",organizationType:"نوع المؤسسة",revenue_growth:"نمو الإيرادات (%)",net_profit:"صافي الربح",cash_flow:"التدفق النقدي",strategic_goal_pct:"الهدف الاستراتيجي (%)",customer_satisfaction:"رضا العملاء",employee_turnover_pct:"معدل دوران الموظفين (%)",open_safety_incidents:"حوادث السلامة المفتوحة",compliance_score:"درجة الامتثال"},wf:{workflow:"سير العمل",noActions:"لا توجد إجراءات متاحة لدورك في هذه الحالة.",applying:"جارٍ التطبيق...",submit:"إرسال",assignToManager:"تعيين للمدير",reject:"رفض",submitSolution:"إرسال الحل",resolutionComplete:"اكتمال الحل",moveToOutsourcing:"نقل للاستعانة بمصادر خارجية",closeIdea:"إغلاق الفكرة"},steps:{auditorTriage:"فرز المدقق (الخطوة 2)",managerSolution:"حل المدير (الخطوة 3)",ownerComment:"تعليق المالك / المدقق (الخطوة 4)",auditorEval:"تقييم المدقق (الخطوة 2)",managerReview:"مراجعة المدير (الخطوة 3)"},formTitle:{newIncident:"حادث جديد",editIncident:"تعديل الحادث",viewIncident:"الحادث: ",newIdea:"فكرة جديدة",editIdea:"تعديل الفكرة",viewIdea:"الفكرة: ",newOrder:"طلب جديد",editOrder:"تعديل الطلب",viewOrder:"الطلب: ",newProcess:"عملية جديدة",editProcess:"تعديل العملية",viewProcess:"العملية: ",newOrg:"مؤسسة جديدة",editOrg:"تعديل المؤسسة",newMgmt:"إدارة جديدة",editMgmt:"تعديل الإدارة",newDept:"قسم جديد",editDept:"تعديل القسم",newBranch:"فرع جديد",editBranch:"تعديل الفرع",newUser:"مستخدم جديد",editUser:"تعديل المستخدم",viewUser:"ملف المستخدم",newCycle:"دورة جديدة",editCycle:"تعديل الدورة",newKpi:"مؤشر أداء جديد",editKpi:"تعديل مؤشر الأداء",newDelegation:"تفويض جديد",viewDelegation:"التفويض: "},saveIncident:"حفظ الحادث",saveIdea:"حفظ الفكرة",saveOrder:"حفظ الطلب",saveProcess:"حفظ العملية",saveOrg:"حفظ المؤسسة",saveMgmt:"حفظ الإدارة",saveDept:"حفظ القسم",saveBranch:"حفظ الفرع",saveUser:"حفظ المستخدم",saveCycle:"حفظ الدورة",saveKpi:"حفظ مؤشر الأداء",saveDelegation:"إرسال التفويض",saveName:"حفظ",dash:{allOrgs:"جميع المؤسسات",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",level2:"المستوى 2 — تصعيد حرج",level1:"المستوى 1 — مراجعة المدقق مطلوبة",overduePrefix:"متأخر للفرز — ",overdueSuffix:" حادث(ة) تجاوز نافذة 3 أيام",untriaged:"حوادث غير مفرزة",recentKpi:"مؤشرات الأداء الأخيرة",manageKpi:"إدارة مؤشرات الأداء",escalatedProcesses:"عمليات متصاعدة",escalatedOrders:"طلبات متصاعدة",level:"المستوى",revenueGrowth:"نمو الإيرادات",netProfit:"صافي الربح",strategicGoal:"الهدف الاستراتيجي",customerSat:"رضا العملاء",compliance:"الامتثال",safetyInc:"حوادث السلامة",total:"الإجمالي"},noIncidents:"لا توجد حوادث",noIdeas:"لا توجد أفكار",noOrders:"لا توجد طلبات",noProcesses:"لا توجد عمليات",noUsers:"لا يوجد مستخدمون",noData:"لا توجد بيانات",users:{category:"الفئة",number:"الرقم",fullName:"الاسم الكامل",username:"اسم المستخدم",email:"البريد الإلكتروني",phone:"رقم الهاتف",organization:"المؤسسة",management:"الإدارة",department:"القسم",branch:"الفرع",since:"منذ",status:"الحالة",tools:"الأدوات",active:"نشط",inactive:"غير نشط",setPassword:"تعيين كلمة المرور",newPassword:"كلمة مرور جديدة",passwordUpdated:"تم تحديث كلمة المرور!",passwordFailed:"فشل. الرجاء المحاولة مرة أخرى.",disableConfirm:"حذف المستخدم؟ لن يظهر في القائمة بعد الآن.",password:"كلمة المرور"},inbox:{title:"البريد الوارد",noMessages:"لا توجد رسائل"},reports:{title:"التقارير",selectOrg:"اختر المؤسسة",generate:"إنشاء التقرير"},comments:{title:"التعليقات",placeholder:"اكتب تعليقاً…",post:"نشر",noComments:"لا توجد تعليقات بعد."},activity:{title:"سجل النشاط",created:"أُنشئ",by:"بواسطة"}},pr=new Set(["SB Incident","SB Idea","SB Order","SB Process","SB Organization","SB Cycle","SB KPI Input","Managements","Department","Branch","Incident Types","Idea Types","Order Types","Process Types","Incident Class","Incident Field","Incident Statuses","Idea Statuses","Order Statuses","Process Statuses"]);let dl="";async function Sc(){try{const e=await fetch(`${ce}/api/method/sidrah_business.api.get_csrf_token`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(e.ok){const l=(await e.json()).message||"";if(l)return dl=l,l}}catch(e){console.error("CSRF fetch error:",e)}return dl}async function fn(){return dl||await Sc(),dl}function tu(e,t){try{if(e!=null&&e._server_messages){const l=JSON.parse(e._server_messages);if(l.length){const s=JSON.parse(l[0]);if(s!=null&&s.message)return s.message.replace(/<[^>]+>/g,"")}}}catch{}return(e==null?void 0:e.message)||(e==null?void 0:e.exception)||t}async function mt(e,t,l=[]){if(pr.has(e)){const a=`${ce}/api/method/sidrah_business.api.get_sb_doc?doctype=${encodeURIComponent(e)}&name=${encodeURIComponent(t)}`,d=await fetch(a,{credentials:"include",headers:{Accept:"application/json"}});if(!d.ok)throw new Error(`API Error: ${d.status}`);return(await d.json()).message}const s=l.length?`?fields=${encodeURIComponent(JSON.stringify(l))}`:"",r=await fetch(`${ce}/api/v1/resource/${e}/${encodeURIComponent(t)}${s}`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(!r.ok)throw new Error(`API Error: ${r.status}`);return(await r.json()).data}async function Nf(e,t){const l=await fn();if(pr.has(e)){const r=new URLSearchParams({doctype:e,name:t}),i=await fetch(`${ce}/api/method/sidrah_business.api.delete_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":l},body:r.toString()});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(tu(a,`Error deleting ${t}`))}return}const s=await fetch(`${ce}/api/v1/resource/${e}/${encodeURIComponent(t)}`,{method:"DELETE",credentials:"include",headers:{Accept:"application/json","X-Frappe-CSRF-Token":l}});if(!s.ok){const r=await s.json().catch(()=>({}));throw new Error(tu(r,`Error deleting ${t}`))}return await s.json()}async function ke(e){if(pr.has(e))try{const s=`${ce}/api/method/sidrah_business.api.get_sb_list?doctype=${encodeURIComponent(e)}&limit=500`,r=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return r.ok?(await r.json()).message||[]:[]}catch{return[]}const t=encodeURIComponent('["*"]'),l=`${ce}/api/v1/resource/${e}?limit_page_length=500&fields=${t}`;try{const s=await fetch(l,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return s.status===401||s.status===403?[]:s.ok?(await s.json()).data||[]:[]}catch(s){return console.error("Get error:",s),[]}}async function za(e,t){const l=await fn();if(pr.has(e)){const r=new URLSearchParams({doctype:e,data_json:JSON.stringify(t)}),i=await fetch(`${ce}/api/method/sidrah_business.api.create_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":l},body:r.toString()});if(!i.ok){const d=await i.json().catch(()=>({}));throw new Error(d.message||d.exc||`Error creating ${e}`)}return{data:(await i.json()).message}}const s=`${ce}/api/v1/resource/${e}`;try{const r=await fetch(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":l},body:JSON.stringify(t)});if(r.status===401||r.status===403)throw new Error("Permission denied - login required");if(!r.ok){const i=await r.json();throw new Error(i.message||i.exc||`API Error: ${r.status}`)}return await r.json()}catch(r){throw console.error("Post error:",r),r}}async function Ti(e,t,l){const s=await fn();if(pr.has(e)){const i=new URLSearchParams({doctype:e,name:t,data_json:JSON.stringify(l)}),a=await fetch(`${ce}/api/method/sidrah_business.api.update_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:i.toString()});if(!a.ok){const u=await a.json().catch(()=>({}));throw new Error(u.message||u.exc||`Error updating ${e}`)}return{data:(await a.json()).message}}const r=`${ce}/api/v1/resource/${e}/${encodeURIComponent(t)}`;try{const i=await fetch(r,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":s},body:JSON.stringify(l)});if(i.status===401||i.status===403)throw new Error("Permission denied - login required");if(!i.ok){const a=await i.json();throw new Error(a.message||"Update Error")}return await i.json()}catch(i){throw console.error("Update error:",i),i}}async function ey(){const e=`${ce}/api/v1/resource/User?limit_page_length=500&fields=["name","full_name"]`;try{const t=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return t.status===401||t.status===403?[]:t.ok?(await t.json()).data||[]:[]}catch(t){return console.error("Get users error:",t),[]}}async function ty(e,t){const l=new FormData;l.append("usr",e),l.append("pwd",t);const r=await(await fetch(`${ce}/api/method/login`,{method:"POST",credentials:"include",body:l})).json();return r.csrf_token?dl=r.csrf_token:await Sc(),r}async function ny(){const e=await fn();try{await fetch(`${ce}/api/method/logout`,{method:"POST",credentials:"include",headers:{"X-Frappe-CSRF-Token":e,Accept:"application/json"}})}catch{}dl=""}function ly(){return dl}async function Wf(){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 sy(){const e=JSON.stringify([["name","not in",["Administrator","Guest"]]]),t=`${ce}/api/v1/resource/User?limit_page_length=500&fields=${encodeURIComponent('["*"]')}&filters=${encodeURIComponent(e)}`;try{const l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).data||[]:[]}catch{return[]}}async function ry(){const e=`${ce}/api/method/sidrah_business.api.get_user_role_map`;try{const t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||{}:{}}catch{return{}}}async function Bf(e,t){await Ti("User",e,{new_password:t})}async function iy(e=20){try{const t=`${ce}/api/method/sidrah_business.api.get_notifications?limit=${e}`,l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function ay(){const e=await fn();try{await fetch(`${ce}/api/method/sidrah_business.api.mark_notifications_read`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":e}})}catch{}}async function oy(e){const t=await fn();try{await fetch(`${ce}/api/method/sidrah_business.api.mark_notification_read`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":t},body:new URLSearchParams({name:e}).toString()})}catch{}}async function cy(e){const t=await fn(),l=new URLSearchParams({name:e});await fetch(`${ce}/api/method/sidrah_business.api.disable_user`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":t},body:l.toString()})}async function dy(e,t){try{const l=`${ce}/api/method/sidrah_business.api.get_doc_comments?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(t)}`,s=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function uy(e,t,l){const s=await fn(),r=new URLSearchParams({doctype:e,docname:t,content:l}),i=await fetch(`${ce}/api/method/sidrah_business.api.post_doc_comment`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:r.toString()});if(!i.ok)throw new Error("Failed to post comment");return(await i.json()).message}async function py(e,t){try{const l=`${ce}/api/method/sidrah_business.api.get_doc_versions?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(t)}`,s=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function $f(e){try{const t=`${ce}/api/method/sidrah_business.api.get_user_roles?user=${encodeURIComponent(e)}`,l=await fetch(t,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||[]:[]}catch{return[]}}async function fy(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_organization`,t=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return t.ok&&(await t.json()).message||""}catch{return""}}async function fl(e,t={}){const l=await fn(),s=new URLSearchParams(t),r=await fetch(`${ce}/api/method/sidrah_business.api.${e}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":l},body:s.toString()});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.message||a.exc||`Error calling ${e}`)}return(await r.json()).message}async function hy(e,t,l="",s,r,i){const a={name:e,action:t,comment:l};return s!==void 0&&(a.stage=s),i!==void 0&&(a.cycle_status=i),fl("apply_order_workflow",a)}async function gy(e,t,l=""){return fl("apply_incident_workflow",{name:e,action:t,fields_json:l})}async function xy(e,t,l=""){return fl("apply_idea_workflow",{name:e,action:t,fields_json:l})}async function my(e=""){const t=`${ce}/api/method/sidrah_business.api.get_dashboard_data${e?`?organization=${encodeURIComponent(e)}`:""}`,l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});return l.ok?(await l.json()).message||{}:{escalated_processes:[],escalated_orders:[],untriaged_incidents:[],kpi_inputs:[]}}async function yy(e,t={}){return fl("get_report_data",{report_name:e,filters_json:JSON.stringify(t)})}async function vy(){try{const e=`${ce}/api/method/sidrah_business.api.get_inbox_items`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||[]:[]}catch{return[]}}async function jy(e,t,l="",s=""){return fl("create_delegation",{manager:e,functions_json:JSON.stringify(t),organization:l,remarks:s})}async function by(e,t,l=""){return fl("respond_to_delegation",{name:e,response:t,remarks:l})}async function Sy(e,t=""){return fl("revoke_delegation",{name:e,remarks:t})}async function wy(){try{const e=`${ce}/api/method/sidrah_business.api.get_delegations`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||[]:[]}catch{return[]}}async function ky(e){const t=`${ce}/api/method/sidrah_business.api.get_delegation?name=${encodeURIComponent(e)}`,l=await fetch(t,{credentials:"include",headers:{Accept:"application/json"}});if(!l.ok)throw new Error("Failed to load delegation");return(await l.json()).message}async function _y(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_delegated_functions`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||[]:[]}catch{return[]}}async function Cy(){try{const e=`${ce}/api/method/sidrah_business.api.get_my_delegated_organizations`,t=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return t.ok?(await t.json()).message||{}:{}}catch{return{}}}async function zy(){const e=ly();return e||Sc()}async function Ls(e){const t=await fetch(`${ce}/api/method/sidrah_business.api.get_process?name=${encodeURIComponent(e)}`,{credentials:"include",headers:{Accept:"application/json"}});if(!t.ok){const s=await t.json().catch(()=>({}));throw new Error(s.message||`Failed to load process (${t.status})`)}const l=await t.json();return l.message||l.data}async function Ty(e,t,l={}){const s=await zy(),r=new URLSearchParams({name:e,action:t});l.actor_status&&r.set("actor_status",String(l.actor_status)),l.actor_comment&&r.set("actor_comment",String(l.actor_comment)),l.progress_indicators&&r.set("progress_indicators",JSON.stringify(l.progress_indicators));const i=await fetch(`${ce}/api/method/sidrah_business.api.apply_process_workflow`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:r.toString()});if(!i.ok){const d=await i.json().catch(()=>({})),u=d.message||(d.exception?String(d.exception).split(` `).pop():"")||d.exc_type||`Workflow action "${t}" failed (${i.status})`;throw new Error(u)}const a=await i.json();return a.message||a.data}function Py({onLogin:e}){const t=ee(),[l,s]=j.useState(""),[r,i]=j.useState(""),[a,d]=j.useState(""),[u,f]=j.useState(!1),[y,p]=j.useState(!1),[c,v]=j.useState(!1),b=async()=>{if(!l||!r){d(t.login.emptyFields);return}f(!0),d("");try{const S=await ty(l,r);if(S.message==="Logged In"){const m=await Wf()||l,o=await $f(m),x=o.some(z=>["SB Admin","System Manager"].includes(z))?"Admin":o.includes("SB Auditor")?"Auditor":o.includes("SB Owner")?"Owner":o.includes("SB X-Auditor")?"XAuditor":o.includes("SB Manager")?"Manager":"Employee";e({name:m,full_name:S.full_name||l,role:x})}else d(t.login.invalidCreds)}catch(S){d(t.login.connError+(S instanceof Error?S.message:"Unknown"))}f(!1)},g=S=>({width:"100%",padding:"13px 16px",border:`1.5px solid ${S?"#4f46e5":"#e5e7eb"}`,borderRadius:10,fontSize:15,background:"#ffffff",color:"#374151",outline:"none",transition:"border-color 0.2s, box-shadow 0.2s",boxSizing:"border-box",boxShadow:S?"0 0 0 3px rgba(79,70,229,0.12)":"none"});return n.jsx("div",{style:{minHeight:"100vh",background:"#f3f4f6",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Segoe UI, system-ui, sans-serif"},children:n.jsxs("div",{style:{background:"white",borderRadius:20,padding:"48px 44px 40px",width:420,boxShadow:"0 4px 32px rgba(0,0,0,0.10)"},children:[n.jsxs("div",{style:{textAlign:"center",marginBottom:28},children:[n.jsx("div",{style:{width:72,height:72,borderRadius:18,background:"linear-gradient(135deg, #312e81 0%, #4f46e5 100%)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 18px",boxShadow:"0 4px 16px rgba(79,70,229,0.3)"},children:n.jsx("span",{style:{fontSize:32,color:"white",fontWeight:800,fontFamily:"serif"},children:"S"})}),n.jsx("div",{style:{fontSize:24,fontWeight:700,color:"#1e1b4b"},children:t.rtl?"صدرة للأعمال":"Sidrah Business"}),n.jsx("div",{style:{fontSize:13,color:"#6b7280",marginTop:6},children:t.login.subtitle})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[n.jsx("input",{value:l,onChange:S=>s(S.target.value),onKeyDown:S=>S.key==="Enter"&&b(),onFocus:()=>p(!0),onBlur:()=>p(!1),style:g(y),placeholder:t.login.usernamePlaceholder,autoComplete:"username"}),n.jsx("input",{type:"password",value:r,onChange:S=>i(S.target.value),onKeyDown:S=>S.key==="Enter"&&b(),onFocus:()=>v(!0),onBlur:()=>v(!1),style:g(c),placeholder:t.login.passwordPlaceholder,autoComplete:"current-password"}),a&&n.jsx("div",{style:{padding:"10px 14px",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:8,color:"#dc2626",fontSize:13},children:a}),n.jsx("button",{onClick:b,disabled:u,style:{background:u?"#a5b4fc":"#4f46e5",color:"white",border:"none",padding:"14px",borderRadius:10,fontSize:15,cursor:u?"not-allowed":"pointer",fontWeight:700,marginTop:4,transition:"background 0.2s, transform 0.1s",letterSpacing:"0.01em"},onMouseEnter:S=>{u||(S.currentTarget.style.background="#4338ca")},onMouseLeave:S=>{u||(S.currentTarget.style.background="#4f46e5")},children:u?t.login.signingIn:t.login.signIn})]}),n.jsx("div",{style:{textAlign:"center",marginTop:14},children:n.jsx("button",{onClick:Df,style:{fontSize:12,color:"#9ca3af",background:"none",border:"none",cursor:"pointer"},children:t.switchLang})})]})})}function Iy(e,t){const l=parseInt(e.replace("#",""),16),s=l>>16&255,r=l>>8&255,i=l&255,a=d=>Math.round(d+(255-d)*t);return`rgb(${a(s)}, ${a(r)}, ${a(i)})`}function ks(e,t){const l=parseInt(e.replace("#",""),16),s=l>>16&255,r=l>>8&255,i=l&255;return`rgba(${s}, ${r}, ${i}, ${t})`}function Br({title:e,data:t,color:l,onSelect:s}){const[,r]=t[0]??["Total",0,""],i=t.slice(1),a=i.map((u,f)=>Iy(l,Math.min(f*.16,.7))),d=i.map(([u,f,y],p)=>[u,f,y,a[p]]).filter(([,u])=>u>0);return n.jsxs("div",{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:[n.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",background:`linear-gradient(160deg, ${ks(l,.09)} 0%, transparent 55%)`}}),n.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:3,background:`linear-gradient(90deg, ${l}, ${ks(l,.35)})`}}),n.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:14},children:[n.jsx("span",{className:"status-card-title",style:{fontSize:13,fontWeight:700,paddingTop:4},children:e}),n.jsx("span",{style:{fontSize:14,fontWeight:800,color:"white",background:l,lineHeight:1,minWidth:26,textAlign:"center",padding:"6px 9px",borderRadius:10,boxShadow:`0 4px 10px ${ks(l,.35)}`},children:r})]}),r>0&&n.jsx("div",{style:{display:"flex",height:9,borderRadius:999,overflow:"hidden",background:ks(l,.1),marginBottom:13},children:d.map(([u,f,y,p],c)=>n.jsx("div",{title:`${u}: ${f}`,onClick:v=>{v.stopPropagation(),s==null||s(y)},style:{flex:`${f} 0 0`,background:p,borderRight:cn.jsxs("div",{className:"status-card-row",onClick:f>0?c=>{c.stopPropagation(),s==null||s(y)}:void 0,style:{display:"flex",alignItems:"center",gap:9,padding:"4px 6px",borderRadius:8,cursor:f>0&&s?"pointer":"default",transition:"background 0.12s"},children:[n.jsx("span",{style:{width:9,height:9,borderRadius:"50%",background:a[p],flexShrink:0,boxShadow:`0 0 0 3px ${ks(a[p],.18)}`}}),n.jsx("span",{className:"status-card-label",style:{flex:1,fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}),n.jsx("span",{className:"status-card-count",style:{fontSize:12,fontWeight:700,flexShrink:0},children:f})]},u))})]})}function Et({value:e,onChange:t,organizations:l,placeholder:s="-- Choose organization --",disabled:r=!1,small:i=!1}){var p;const[a,d]=j.useState(!1),u=j.useRef(null);j.useEffect(()=>{const c=v=>{u.current&&!u.current.contains(v.target)&&d(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]);const f=e?((p=l.find(c=>c.organization_name===e||c.name===e))==null?void 0:p.organization_name)??e:s,y=l.filter(c=>!!c.is_active||c.organization_name===e||c.name===e);return n.jsxs("div",{ref:u,style:{position:"relative",width:"100%"},children:[n.jsxs("div",{onClick:()=>!r&&d(c=>!c),style:{width:"100%",padding:i?"4px 8px":"7px 10px",border:"1px solid #ddd",borderRadius:6,fontSize:i?11:12,cursor:r?"default":"pointer",height:i?28:34,background:r?"#f5f5f5":"white",color:e?"#333":"#aaa",display:"flex",justifyContent:"space-between",alignItems:"center",borderColor:a?"#3498db":"#ddd",transition:"border-color 0.2s",userSelect:"none",boxSizing:"border-box",opacity:r?.75:1},children:[n.jsx("span",{children:f}),n.jsx("span",{style:{fontSize:9,color:"#999",transform:a?"rotate(180deg)":"none",transition:"transform 0.2s"},children:"▼"})]}),a&&n.jsx("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:9999,background:"white",border:"1px solid #e0e0e0",borderRadius:6,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",overflow:"hidden"},children:n.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[n.jsx(nu,{label:s,selected:!e,active:!0,isPlaceholder:!0,small:i,onClick:()=>{t(""),d(!1)}}),y.length===0&&n.jsx("div",{style:{padding:"12px 16px",color:"#aaa",fontSize:13},children:"No organizations"}),y.map(c=>n.jsx(nu,{label:c.organization_name,selected:e===c.organization_name||e===c.name,active:!!c.is_active,isPlaceholder:!1,small:i,onClick:()=>{t(c.organization_name),d(!1)}},c.name))]})})]})}function nu({label:e,selected:t,active:l,isPlaceholder:s,small:r,onClick:i}){const[a,d]=j.useState(!1),u=t?"#2563eb":a?"#f0f4ff":"transparent",f=t?"white":s?"#aaa":l?"#1a2332":"#e74c3c";return n.jsx("div",{onClick:i,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),style:{padding:r?"6px 12px":"8px 14px",cursor:"pointer",fontSize:12,background:u,color:f,transition:"background 0.1s"},children:e})}function wn({items:e,type:t,onNavigate:l}){const s=ee();if(!e.length)return null;const r=t==="process"?"processes-form":"orders-form",i=t==="process"?s.dash.escalatedProcesses:s.dash.escalatedOrders;return n.jsxs("div",{children:[n.jsxs("h4",{style:{fontWeight:700,fontSize:12,color:"#e74c3c",marginBottom:6},children:[i," (",e.length,")"]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:e.map(a=>n.jsxs("div",{onClick:()=>l(r,a.name),style:{padding:"8px 12px",background:"#fff5f5",borderRadius:7,border:"1px solid #fecaca",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsxs("div",{children:[n.jsx("span",{style:{fontWeight:700,fontSize:12},children:a.number||a.name}),n.jsx("span",{style:{fontSize:11,color:"#666",marginLeft:8},children:a.title})]}),n.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#e74c3c",background:"#fecaca",padding:"2px 8px",borderRadius:10},children:[s.dash.level," ",a.escalation_level]})]},a.name))})]})}function Ey({kpi:e}){const t=ee();return n.jsxs("div",{style:{background:"white",borderRadius:8,padding:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("div",{style:{fontWeight:700,fontSize:13,marginBottom:2},children:e.organization}),n.jsx("div",{style:{fontSize:11,color:"#888",marginBottom:8},children:e.period}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[{label:t.dash.revenueGrowth,val:e.revenue_growth!=null?`${e.revenue_growth}%`:"—"},{label:t.dash.netProfit,val:e.net_profit!=null?e.net_profit.toLocaleString():"—"},{label:t.dash.strategicGoal,val:e.strategic_goal_pct!=null?`${e.strategic_goal_pct}%`:"—"},{label:t.dash.customerSat,val:e.customer_satisfaction!=null?e.customer_satisfaction:"—"},{label:t.dash.compliance,val:e.compliance_score!=null?e.compliance_score:"—"},{label:t.dash.safetyInc,val:e.open_safety_incidents!=null?e.open_safety_incidents:"—"}].map(({label:l,val:s})=>n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700},children:l}),n.jsx("div",{style:{fontSize:15,fontWeight:700,color:"#1a2332"},children:s})]},l))})]})}function Ay({data:e}){if(!e.length)return n.jsx("p",{style:{color:"#aaa",fontSize:13},children:"No cycle data available for trend chart."});const t=Math.max(...e.map(l=>l.pass+l.fail+l.unknown),1);return n.jsxs("div",{children:[n.jsx("div",{style:{display:"flex",gap:10,alignItems:"flex-end",overflowX:"auto",paddingBottom:4},children:e.map(l=>{const s=l.pass+l.fail+l.unknown||1,r=80;return n.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:3,minWidth:48},children:[n.jsxs("div",{style:{display:"flex",flexDirection:"column-reverse",gap:1,height:r,width:32},children:[n.jsx("div",{title:`Pass: ${l.pass}`,style:{height:Math.round(l.pass/t*r),background:"#27ae60",borderRadius:"2px 2px 0 0",minHeight:l.pass?2:0}}),n.jsx("div",{title:`Fail: ${l.fail}`,style:{height:Math.round(l.fail/t*r),background:"#e74c3c",borderRadius:"2px 2px 0 0",minHeight:l.fail?2:0}}),n.jsx("div",{title:`Unknown: ${l.unknown}`,style:{height:Math.round(l.unknown/t*r),background:"#95a5a6",borderRadius:"2px 2px 0 0",minHeight:l.unknown?2:0}})]}),n.jsx("div",{style:{fontSize:9,color:"#999",textAlign:"center",lineHeight:1.2},children:l.month.replace(/^(\d{4})-(\d{2})$/,(i,a,d)=>`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][+d-1]} ${a}`)}),n.jsx("div",{style:{fontSize:9,color:"#555",textAlign:"center"},children:s>1?Math.round(l.pass/s*100)+"%":"—"})]},l.month)})}),n.jsx("div",{style:{display:"flex",gap:16,marginTop:8},children:[["#27ae60","Pass"],["#e74c3c","Fail"],["#95a5a6","Unknown"]].map(([l,s])=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,fontSize:11},children:[n.jsx("div",{style:{width:10,height:10,background:l,borderRadius:2}}),n.jsx("span",{style:{color:"#666"},children:s})]},s))})]})}function Wt({label:e,icon:t,onClick:l}){return n.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",gap:7,padding:"7px 12px",background:"white",border:"1px solid #e8e8e8",borderRadius:8,cursor:"pointer",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",transition:"box-shadow 0.15s"},onMouseEnter:s=>s.currentTarget.style.boxShadow="0 3px 10px rgba(0,0,0,0.12)",onMouseLeave:s=>s.currentTarget.style.boxShadow="0 1px 3px rgba(0,0,0,0.06)",children:[n.jsx("span",{style:{fontSize:15},children:t}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#444",whiteSpace:"nowrap"},children:e})]})}function Ry({dashData:e,fi:t,fid:l,fo:s,fp:r,incidentStatuses:i,ideaStatuses:a,orderStatuses:d,processStatuses:u,onNavigate:f,onNavigateStatus:y}){const p=ee(),c=(e==null?void 0:e.escalated_processes)||[],v=(e==null?void 0:e.escalated_orders)||[],b=(e==null?void 0:e.attention_processes)||[],g=(e==null?void 0:e.attention_orders)||[],S=(e==null?void 0:e.untriaged_incidents)||[],h=(e==null?void 0:e.overdue_triage)||[],m=c.length>0||v.length>0,o=b.length>0||g.length>0,x=[["Total",t.length,""],...i.map(k=>[k.name1||k.name,t.filter(C=>C.status===k.name).length,k.name])],z=[["Total",l.length,""],...a.map(k=>[k.name1||k.name,l.filter(C=>C.status===k.name).length,k.name])],R=[["Total",s.length,""],...d.map(k=>[k.name1||k.name,s.filter(C=>C.status===k.name).length,k.name])],P=[["Total",r.length,""],...u.map(k=>[k.name1||k.name,r.filter(C=>C.status===k.name).length,k.name])];return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",marginBottom:4},children:[n.jsx(Wt,{label:"Incidents",icon:"⚠️",onClick:()=>f("incidents")}),n.jsx(Wt,{label:"Ideas",icon:"💡",onClick:()=>f("ideas")}),n.jsx(Wt,{label:"Orders",icon:"📦",onClick:()=>f("orders")}),n.jsx(Wt,{label:"Processes",icon:"⚙️",onClick:()=>f("processes")}),n.jsx(Wt,{label:"Inbox",icon:"📥",onClick:()=>f("inbox")}),n.jsx(Wt,{label:"Reports",icon:"📊",onClick:()=>f("reports")})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:12},children:[n.jsx("div",{onClick:()=>f("incidents"),style:{cursor:"pointer"},children:n.jsx(Br,{title:p.dash.incidents,color:W.orange,data:x,onSelect:k=>y("incidents",k)})}),n.jsx("div",{onClick:()=>f("ideas"),style:{cursor:"pointer"},children:n.jsx(Br,{title:p.dash.ideas,color:W.blue,data:z,onSelect:k=>y("ideas",k)})}),n.jsx("div",{onClick:()=>f("orders"),style:{cursor:"pointer"},children:n.jsx(Br,{title:p.dash.orders,color:W.purple,data:R,onSelect:k=>y("orders",k)})}),n.jsx("div",{onClick:()=>f("processes"),style:{cursor:"pointer"},children:n.jsx(Br,{title:p.dash.processes,color:W.red,data:P,onSelect:k=>y("processes",k)})})]}),m&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:10},children:p.dash.level2}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(wn,{items:c,type:"process",onNavigate:f}),n.jsx(wn,{items:v,type:"order",onNavigate:f})]})]}),o&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#b45309",marginBottom:10},children:p.dash.level1}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(wn,{items:b,type:"process",onNavigate:f}),n.jsx(wn,{items:g,type:"order",onNavigate:f})]})]}),h.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:8},children:[p.dash.overduePrefix,h.length,p.dash.overdueSuffix]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:h.map(k=>n.jsxs("div",{onClick:()=>f("incidents-form",k.name),style:{padding:"8px 12px",background:"#fef2f2",borderRadius:8,border:"1px solid #fca5a5",cursor:"pointer",display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{fontWeight:700,fontSize:13},children:k.number||k.name}),n.jsx("span",{style:{fontSize:12,color:"#666"},children:k.title}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:k.date})]},k.name))})]}),S.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:W.orange,marginBottom:8},children:[p.dash.untriaged," (",S.length,")"]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:S.map(k=>n.jsxs("div",{onClick:()=>f("incidents-form",k.name),style:{padding:"8px 12px",background:"#fffbeb",borderRadius:8,border:"1px solid #fed7aa",cursor:"pointer",display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{fontWeight:700,fontSize:13},children:k.number||k.name}),n.jsx("span",{style:{fontSize:12,color:"#666"},children:k.title}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:k.date})]},k.name))})]})]})}function Ly({dashData:e,selectedOrg:t,onNavigate:l}){const s=ee(),[r,i]=j.useState([]),[a,d]=j.useState([]),[u,f]=j.useState(!1),y=(e==null?void 0:e.escalated_processes)||[],p=(e==null?void 0:e.escalated_orders)||[],c=(e==null?void 0:e.attention_processes)||[],v=(e==null?void 0:e.attention_orders)||[],b=(e==null?void 0:e.kpi_inputs)||[];j.useEffect(()=>{f(!0);const h=new URLSearchParams({months:"6"});t&&h.append("organization",t),fetch(`/api/method/sidrah_business.api.get_process_trend?${h}`,{credentials:"include",headers:{Accept:"application/json"}}).then(m=>m.json()).then(m=>{const o=m.message||[],x={};for(const z of o)x[z.month]||(x[z.month]={pass:0,fail:0,unknown:0}),z.status==="Pass"?x[z.month].pass=z.count:z.status==="Fail"?x[z.month].fail=z.count:z.status==="Unknown"&&(x[z.month].unknown=z.count);i(Object.entries(x).map(([z,R])=>({month:z,...R})))}).catch(()=>{}).finally(()=>f(!1))},[t]),j.useEffect(()=>{fetch("/api/method/sidrah_business.api.get_report_data",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":window.csrf_token||""},body:JSON.stringify({report_name:"user_activity_log",filters_json:"{}"})}).then(h=>h.json()).then(h=>{var m;d((((m=h.message)==null?void 0:m.rows)||[]).slice(0,50))}).catch(()=>{})},[t]);const g=y.length>0||p.length>0,S=c.length>0||v.length>0;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:[n.jsx(Wt,{label:"Manage Users & Roles",icon:"👥",onClick:()=>l("users")}),n.jsx(Wt,{label:"Change Active Cycle",icon:"🔄",onClick:()=>l("cycles")}),n.jsx(Wt,{label:"KPI Inputs",icon:"📈",onClick:()=>l("kpi-input")}),n.jsx(Wt,{label:"Reports",icon:"📊",onClick:()=>l("reports")}),n.jsx(Wt,{label:"Organizations",icon:"🏢",onClick:()=>l("organizations")})]}),b.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:10},children:s.dash.recentKpi}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12},children:b.map(h=>n.jsx(Ey,{kpi:h},h.name))}),n.jsx("button",{onClick:()=>l("kpi-input"),style:{marginTop:10,padding:"6px 14px",borderRadius:7,border:"1px solid #2980b9",background:"white",color:"#2980b9",fontWeight:600,fontSize:12,cursor:"pointer"},children:s.dash.manageKpi})]}),g&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #e74c3c"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:10},children:["Critical Escalations — Level 2 (",y.length+p.length,")"]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(wn,{items:y,type:"process",onNavigate:l}),n.jsx(wn,{items:p,type:"order",onNavigate:l})]})]}),S&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderLeft:"4px solid #f59e0b"},children:[n.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#b45309",marginBottom:10},children:["Needs Attention — Level 1 (",c.length+v.length,")"]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(wn,{items:c,type:"process",onNavigate:l}),n.jsx(wn,{items:v,type:"order",onNavigate:l})]})]}),n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:4},children:"Process Trend — Last 6 Months"}),n.jsx("p",{style:{fontSize:11,color:"#888",marginBottom:10},children:"Pass/Fail/Unknown ratio per month across all processes. Pass % shown at bottom of each bar."}),u?n.jsx("p",{style:{color:"#aaa",fontSize:13},children:"Loading trend data…"}):n.jsx(Ay,{data:r})]}),a.length>0&&n.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("h3",{style:{fontWeight:800,fontSize:13,color:"#1a2332",marginBottom:10},children:"Log Book — Recent Activity"}),n.jsx("div",{style:{overflowX:"auto"},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa"},children:["Timestamp","User","Entity Type","Entity","Fields Changed"].map(h=>n.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#999",fontWeight:700,fontSize:11,whiteSpace:"nowrap"},children:h},h))})}),n.jsx("tbody",{children:a.map((h,m)=>n.jsxs("tr",{style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"8px 12px",color:"#555",whiteSpace:"nowrap"},children:h.timestamp?String(h.timestamp).slice(0,16):"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#333"},children:h.user||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:h.entity_type||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:h.entity_name||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#888",maxWidth:240,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.changes||"—"})]},m))})]})}),n.jsx("button",{onClick:()=>l("reports"),style:{marginTop:12,padding:"7px 16px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:600,fontSize:12,cursor:"pointer"},children:"Full Activity Log (Reports →)"})]})]})}function Oy({incidents:e,ideas:t,orders:l,processes:s,organizations:r,incidentStatuses:i,ideaStatuses:a,orderStatuses:d,processStatuses:u,selectedOrg:f,onOrgChange:y,onNavigate:p,onNavigateStatus:c,userRole:v}){const[b,g]=j.useState(null);j.useEffect(()=>{my(f).then(g)},[f]);const S=f?e.filter(C=>C.organization===f):e,h=f?t.filter(C=>C.organization===f):t,m=f?l.filter(C=>C.organization===f):l,o=f?s.filter(C=>C.organization===f):s,x=v==="Admin",z=v==="Owner",[R,P]=j.useState("level1"),k=z||x&&R==="level2";return n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"white",borderRadius:10,padding:"8px 14px",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#4f46e5",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#1e1b4b",whiteSpace:"nowrap"},children:"Filter"})]}),n.jsx("div",{style:{flex:1,minWidth:160,maxWidth:260},children:n.jsx(Et,{value:f,onChange:y,organizations:r,placeholder:"All Organizations",small:!0})}),x&&n.jsx("div",{style:{display:"flex",background:"#f1f0fe",borderRadius:7,padding:2,gap:2,flexShrink:0},children:["level1","level2"].map(C=>n.jsx("button",{onClick:()=>P(C),style:{padding:"4px 10px",borderRadius:5,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:R===C?C==="level2"?W.purple:W.blue:"transparent",color:R===C?"white":"#6b7280",transition:"all 0.15s"},children:C==="level1"?"Level 1":"Level 2"},C))}),!x&&n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"white",background:k?W.purple:W.blue,padding:"3px 10px",borderRadius:20,flexShrink:0},children:k?"Level 2 — Owner":"Level 1 — Operational"})]}),k?n.jsx(Ly,{dashData:b,selectedOrg:f,onNavigate:p}):n.jsx(Ry,{dashData:b,fi:S,fid:h,fo:m,fp:o,incidentStatuses:i,ideaStatuses:a,orderStatuses:d,processStatuses:u,onNavigate:p,onNavigateStatus:c})]})}const Dy=()=>n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),Ny=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),Wy=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6l-1 14H6L5 6"}),n.jsx("path",{d:"M10 11v6M14 11v6"}),n.jsx("path",{d:"M9 6V4h6v2"})]});function Je({onView:e,onEdit:t,onDelete:l}){const[s,r]=j.useState(!1),i=(d,u,f,y,p)=>f?n.jsx("button",{onClick:c=>{c.stopPropagation(),f()},title:p,style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:d,color:u,flexShrink:0,transition:"opacity 0.15s"},onMouseEnter:c=>c.currentTarget.style.opacity="0.75",onMouseLeave:c=>c.currentTarget.style.opacity="1",children:y},p):null,a=l?()=>{s?(r(!1),l()):r(!0)}:void 0;return n.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[i("#e0f7fa","#0891b2",e,n.jsx(Dy,{}),"View"),i("#dcfce7","#16a34a",t,n.jsx(Ny,{}),"Edit"),l&&n.jsx("button",{onClick:d=>{d.stopPropagation(),a==null||a()},title:s?"Click again to confirm delete":"Delete",style:{minWidth:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:s?8:"50%",padding:s?"0 8px":0,border:"none",cursor:"pointer",background:s?"#ef4444":"#fee2e2",color:s?"white":"#ef4444",flexShrink:0,fontSize:s?11:14,fontWeight:700,transition:"all 0.15s",gap:4},onMouseEnter:d=>d.currentTarget.style.opacity="0.8",onMouseLeave:d=>d.currentTarget.style.opacity="1",onBlur:()=>r(!1),children:s?"✓ Sure?":n.jsx(Wy,{})})]})}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 By(e){return typeof(e==null?void 0:e.is_active)<"u"?!!e.is_active:typeof(e==null?void 0:e.status)<"u"?e.status!=="Inactive":typeof(e==null?void 0:e.custom_status)<"u"?e.custom_status!=="Inactive":!0}function fe(e,t){return e.filter(l=>By(l)||l.name===t)}function fr(e,t,l,s){return e.filter(r=>{const i=t[r.name]||[];return!(i.includes("SB Admin")||i.includes("System Manager")||!i.includes(l)||s&&r.custom_organization&&r.custom_organization!==s)})}const ds={width:16,height:16,cursor:"pointer",accentColor:"#2563eb",flexShrink:0},Ln=(e,t)=>n.jsx("span",{style:{background:t,color:"white",padding:"4px 12px",borderRadius:12,fontSize:12,fontWeight:600,display:"inline-block"},children:e}),Ki=e=>{switch(e){case"New":return"#e74c3c";case"Under Progress":return"#f39c12";case"Executed":return"#27ae60";case"Overdue":return"#7f1d1d";default:return"#95a5a6"}},$e={fontSize:10,color:"#6b7280",fontWeight:600,marginBottom:3,display:"block",textTransform:"uppercase",letterSpacing:.4},Ue={width:"100%",padding:"4px 8px",border:"1px solid #d1d5db",borderRadius:6,fontSize:11,background:"white",color:"#374151",boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif",height:28};function Qi({children:e}){const[t,l]=j.useState(!1);return n.jsxs("div",{style:{borderRadius:8,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",flexShrink:0},children:[n.jsxs("div",{onClick:()=>l(s=>!s),style:{background:"#4f46e5",color:"white",padding:"9px 18px",cursor:"pointer",display:"flex",alignItems:"center",gap:10,userSelect:"none"},children:[n.jsx("span",{style:{fontSize:13,opacity:.9},children:t?"▲":"▼"}),n.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{fontSize:13,fontWeight:600},children:"Filters"})]}),t&&n.jsx("div",{style:{background:"white",padding:"12px 16px",borderTop:"1px solid #e5e7eb"},children:e})]})}const se=20,lu=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 Fe({page:e,pageSize:t=se,total:l,onPageChange:s}){if(l===0)return null;const r=Math.max(1,Math.ceil(l/t)),i=(e-1)*t+1,a=Math.min(e*t,l);return n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 4px",fontSize:12,color:"#6b7280",flexShrink:0},children:[n.jsxs("span",{children:["Showing ",i," to ",a," of ",l," results"]}),n.jsxs("div",{style:{display:"flex",gap:8},children:[n.jsx("button",{disabled:e<=1,onClick:()=>s(e-1),style:lu(e<=1),children:"Previous"}),n.jsx("button",{disabled:e>=r,onClick:()=>s(e+1),style:lu(e>=r),children:"Next"})]})]})}function $y({incidents:e,organizations:t,departments:l,branches:s,incidentStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=ee(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),b=(o,x)=>v(z=>({...z,[o]:x})),[g,S]=j.useState(1),h=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{S(1)},[c]);const m=h.slice((g-1)*se,g*se);return n.jsxs(n.Fragment,{children:[n.jsx(Qi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.numberTitle}),n.jsx("input",{style:Ue,value:c.search,onChange:o=>b("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.organization}),n.jsxs("select",{style:Ue,value:c.organization,onChange:o=>b("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.department}),n.jsxs("select",{style:Ue,value:c.department,onChange:o=>b("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.branch}),n.jsxs("select",{style:Ue,value:c.branch,onChange:o=>b("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.status}),n.jsxs("select",{style:Ue,value:c.status,onChange:o=>b("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name))]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.type}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:h.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noIncidents})}):m.map((o,x)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.type?Ln(o.type,"#e74c3c"):"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Ln(o.status,Ki(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:z=>z.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Fe,{page:g,total:h.length,onPageChange:S})]})}function Uy(e){if(!e)return"";const[t,l,s]=e.split("-");return!t||!l||!s?"":`${s}/${l}/${t}`}function ye({value:e,onChange:t,disabled:l,style:s,min:r,max:i}){return n.jsxs("div",{style:{position:"relative",width:"100%"},children:[n.jsx("input",{type:"text",readOnly:!0,tabIndex:-1,value:Uy(e),placeholder:"DD/MM/YYYY",style:{...s,pointerEvents:"none",paddingRight:30}}),n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:l?"#bbb":"#666",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",pointerEvents:"none"},children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),n.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),n.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),n.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),n.jsx("input",{type:"date",value:e||"",disabled:l,min:r,max:i,onChange:a=>t(a.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0,cursor:l?"default":"pointer",border:"none",padding:0,margin:0}})]})}function Fy({title:e,children:t}){return n.jsxs("div",{style:{background:"white",borderRadius:10,padding:"18px 20px",marginBottom:14,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[e&&n.jsx("div",{style:{fontSize:15,fontWeight:700,marginBottom:16,color:"#1e1b4b"},children:e}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:13},children:t})]})}const su={"SB Process":"processes-form","SB Order":"orders-form","SB Incident":"incidents-form","SB Idea":"ideas-form","SB Delegation":"delegations"};function My(e){const t=(Date.now()-new Date(e).getTime())/1e3;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function Uf({notifCount:e,darkMode:t,onCountChange:l,onToggleDark:s,onViewProfile:r,onLogout:i,onNavigate:a}){const[d,u]=j.useState(!1),[f,y]=j.useState([]),[p,c]=j.useState(!1),v=j.useRef(null);j.useEffect(()=>{const k=C=>{v.current&&!v.current.contains(C.target)&&u(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);const b=async()=>{c(!0);const k=await iy(30);y(k),c(!1)},g=()=>{const k=!d;u(k),k&&b()},S=async()=>{await ay(),y(k=>k.map(C=>({...C,read:1}))),l(0)},h=k=>{k.read||(oy(k.name),y($=>$.map(I=>I.name===k.name?{...I,read:1}:I)),l(Math.max(0,e-1)));const C=k.document_type?su[k.document_type]:void 0;C&&a&&(a(C,k.document_type==="SB Delegation"?void 0:k.document_name),u(!1))},m=f.filter(k=>!k.read).length,o=k=>({position:"relative",width:34,height:34,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:t?"#2d3748":"#f3f4f6",color:t?"#e2e8f0":"#6b7280",fontSize:14,transition:"background 0.15s",flexShrink:0,...k}),x=t,z=x?"#1a202c":"white",R=x?"#2d3748":"#e5e7eb",P=x?"#e2e8f0":"#1a2332";return n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("button",{style:o({background:"#4f46e5",color:"white"}),onClick:r,title:"My Profile",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:[n.jsx("circle",{cx:"12",cy:"8",r:"4"}),n.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7",fill:"currentColor"})]})}),n.jsxs("div",{ref:v,style:{position:"relative"},children:[n.jsxs("button",{style:o(),onClick:g,title:"Notifications",children:[n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),n.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),e>0&&n.jsx("span",{style:{position:"absolute",top:2,right:2,background:"#ef4444",color:"white",fontSize:9,fontWeight:700,borderRadius:999,minWidth:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 3px",lineHeight:1},children:e>9?"9+":e})]}),d&&n.jsxs("div",{style:{position:"absolute",right:0,top:"calc(100% + 8px)",width:340,background:z,borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.2)",zIndex:1e4,border:`1px solid ${R}`,overflow:"hidden"},children:[n.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${R}`,display:"flex",alignItems:"center",justifyContent:"space-between",background:z},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:P},children:["Notifications",m>0&&n.jsxs("span",{style:{background:"#ef4444",color:"white",fontSize:10,fontWeight:700,borderRadius:999,padding:"2px 7px"},children:[m," new"]})]}),m>0&&n.jsx("button",{onClick:S,style:{fontSize:12,color:"#3498db",background:"none",border:"none",cursor:"pointer",fontFamily:"inherit"},children:"Mark all read"})]}),n.jsxs("div",{style:{maxHeight:380,overflowY:"auto"},children:[p&&n.jsx("div",{style:{padding:20,textAlign:"center",color:"#aaa",fontSize:13},children:"Loading…"}),!p&&f.length===0&&n.jsxs("div",{style:{padding:"36px 20px",textAlign:"center",color:"#aaa"},children:[n.jsx("div",{style:{fontSize:28,marginBottom:8},children:"🔔"}),n.jsx("div",{style:{fontSize:13},children:"No notifications"})]}),!p&&f.map(k=>{const C=!!(k.document_type&&su[k.document_type]&&a);return n.jsxs("div",{onClick:()=>h(k),style:{padding:"11px 16px",borderBottom:`1px solid ${x?"#2d3748":"#f5f5f5"}`,display:"flex",gap:10,background:k.read?z:x?"#1e3a5f":"#eff6ff",cursor:C?"pointer":"default",transition:"background 0.12s"},onMouseEnter:$=>{C&&($.currentTarget.style.background=x?"#243244":"#e0ecfd")},onMouseLeave:$=>{$.currentTarget.style.background=k.read?z:x?"#1e3a5f":"#eff6ff"},children:[n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:13,fontWeight:k.read?400:600,color:P,marginBottom:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.subject||`${k.document_type}: ${k.document_name}`}),n.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:k.document_type&&n.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#3b82f6",background:x?"rgba(59,130,246,0.15)":"#eff6ff",padding:"1px 7px",borderRadius:8},children:[k.document_type.replace("SB ",""),k.document_name?` · ${k.document_name}`:""]})}),n.jsx("div",{style:{fontSize:11,color:"#aaa",marginTop:3},children:My(k.creation)})]}),!k.read&&n.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:"#3498db",flexShrink:0,marginTop:5}})]},k.name)})]})]})]}),n.jsx("button",{style:o(),onClick:Df,title:ql()?"Switch to English":"Switch to Arabic",children:n.jsx("span",{style:{fontSize:13,fontWeight:700,fontFamily:"serif"},children:"عA"})}),n.jsx("button",{style:o(),onClick:s,title:t?"Light mode":"Dark mode",children:t?n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"5"}),n.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),n.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),n.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),n.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),n.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),n.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),n.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),n.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),n.jsx("button",{style:o({background:x?"#3d1515":"#fee2e2",color:"#ef4444"}),onClick:i,title:"Logout",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),n.jsx("polyline",{points:"16,17 21,12 16,7"}),n.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})}function Me({title:e,activePage:t,user:l,formStatus:s,buttonText:r,buttonColor:i,viewMode:a,onEdit:d,hideSettings:u,rightPanel:f,darkMode:y,notifCount:p,onToggleDark:c,onCountChange:v,onViewProfile:b,onSubmit:g,onBack:S,onNavigate:h,onLogout:m,children:o}){const x=ee(),z=x.nav[t]||t,R=l.role,P=R==="Admin"||R==="Owner"||R==="Auditor"||R==="Manager",k=R==="Admin"||R==="Owner"||R==="Auditor"||R==="Manager",C=R==="Admin"||R==="Auditor"||R==="Manager",$=P?"dashboard":"inbox",[I,E]=j.useState(()=>localStorage.getItem("sb_sidebar")==="1"),O=()=>E(U=>{const V=!U;return localStorage.setItem("sb_sidebar",V?"1":"0"),V});return n.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:W.bg},children:[n.jsx(Lf,{collapsed:I,onToggleCollapsed:O,activePage:t,onNavigate:h,hasDashboard:P,hasReports:k,hasDelegations:C,role:R,hideSettings:u,rtl:x.rtl,navLabels:x.nav,settingsLabel:x.nav.settings}),n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[n.jsxs("div",{style:{background:"white",padding:"10px 20px",borderBottom:"1px solid #e9eaf0",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,boxShadow:"0 1px 4px rgba(0,0,0,0.04)"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[n.jsx("button",{onClick:S,title:x.back,style:{width:30,height:30,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"1.5px solid #e5e7eb",background:"white",cursor:"pointer",color:"#4f46e5",flexShrink:0},children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:15,fontWeight:700,color:"#1e1b4b"},children:e}),n.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:1},children:[n.jsx("span",{onClick:()=>h($),style:{cursor:"pointer",color:"#4f46e5"},onMouseEnter:U=>U.currentTarget.style.textDecoration="underline",onMouseLeave:U=>U.currentTarget.style.textDecoration="none",children:x.home}),!u&&n.jsxs(n.Fragment,{children:[n.jsx("span",{style:{margin:"0 4px"},children:"/"}),n.jsx("span",{onClick:S,style:{cursor:"pointer",color:"#4f46e5"},onMouseEnter:U=>U.currentTarget.style.textDecoration="underline",onMouseLeave:U=>U.currentTarget.style.textDecoration="none",children:z})]})]})]})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[a&&d&&n.jsxs("button",{onClick:d,style:{display:"flex",alignItems:"center",gap:6,padding:"7px 16px",borderRadius:7,border:"none",background:"#4f46e5",color:"white",cursor:"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI"},children:[n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),x.edit]}),n.jsx(Uf,{notifCount:p,darkMode:y,onCountChange:v,onToggleDark:c,onNavigate:h,onViewProfile:b,onLogout:m})]})]}),n.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px",display:"grid",gridTemplateColumns:f?"1fr auto":"1fr",gap:14,alignItems:"start"},children:[n.jsx("div",{style:{minWidth:0},children:n.jsxs(Fy,{children:[o,!a&&n.jsxs("div",{style:{display:"flex",gap:10,marginTop:20},children:[n.jsx("button",{onClick:S,style:{padding:"9px 22px",borderRadius:8,border:"1.5px solid #e5e7eb",cursor:"pointer",fontSize:13,fontWeight:600,background:"white",color:"#374151",fontFamily:"Segoe UI"},children:x.cancel}),n.jsx("button",{onClick:g,disabled:s==="loading",style:{padding:"9px 22px",borderRadius:8,background:i,color:"white",border:"none",cursor:"pointer",fontSize:13,fontWeight:600,opacity:s==="loading"?.7:1,boxShadow:"0 2px 10px rgba(79,70,229,0.18)",fontFamily:"Segoe UI"},children:s==="loading"?x.saving:r})]}),s==="success"&&n.jsx("div",{style:{padding:"10px",borderRadius:8,background:"#f0fdf4",border:"1px solid #86efac",color:"#166534",fontSize:13,marginTop:10},children:x.savedOk}),s!=="idle"&&s!=="loading"&&s!=="success"&&n.jsx("div",{style:{padding:"10px",borderRadius:8,background:"#fef2f2",border:"1px solid #fca5a5",color:"#991b1b",fontSize:13,marginTop:10},children:s})]})}),f&&n.jsx("div",{style:{position:"sticky",top:0,alignSelf:"start"},children:f})]})]})]})}function ue({value:e,onChange:t,items:l,placeholder:s="-- Select --",disabled:r=!1}){var p;const[i,a]=j.useState(!1),[d,u]=j.useState(""),f=j.useRef(null);j.useEffect(()=>{const c=v=>{f.current&&!f.current.contains(v.target)&&a(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]);const y=e?((p=l.find(c=>c.name===e))==null?void 0:p.label)??e:s;return n.jsxs("div",{ref:f,style:{position:"relative",width:"100%"},children:[n.jsxs("div",{onClick:()=>!r&&a(c=>!c),style:{width:"100%",height:34,padding:"7px 10px",border:"1px solid",borderColor:i?"#3498db":"#ddd",borderRadius:6,fontSize:12,cursor:r?"default":"pointer",background:r?"#f5f5f5":"white",color:e?"#333":"#aaa",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"border-color 0.2s",userSelect:"none",boxSizing:"border-box",opacity:r?.75:1},children:[n.jsx("span",{children:y}),n.jsx("span",{style:{fontSize:9,color:"#999",transform:i?"rotate(180deg)":"none",transition:"transform 0.2s"},children:"▼"})]}),i&&n.jsx("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:9999,background:"white",border:"1px solid #e0e0e0",borderRadius:6,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",overflow:"hidden"},children:n.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[n.jsx("div",{onClick:()=>{t(""),a(!1)},onMouseEnter:()=>u("__placeholder"),onMouseLeave:()=>u(""),style:{padding:"8px 14px",cursor:"pointer",fontSize:12,color:"#aaa",background:d==="__placeholder"?"#f5f5f5":"transparent"},children:s}),l.length===0&&n.jsx("div",{style:{padding:"10px 14px",color:"#aaa",fontSize:12},children:"No records found"}),l.map(c=>n.jsx("div",{onClick:()=>{t(c.name),a(!1)},onMouseEnter:()=>u(c.name),onMouseLeave:()=>u(""),style:{padding:"8px 14px",cursor:"pointer",fontSize:12,background:e===c.name?"#2563eb":d===c.name?"#f0f4ff":"transparent",color:e===c.name?"white":"#1a2332",transition:"background 0.1s"},children:c.label},c.name))]})})]})}function Hy(e){const t=(Date.now()-new Date(e).getTime())/1e3;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:t<86400*7?`${Math.floor(t/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Ky(e){return e.replace(/@.*/,"").replace(/[._-]/g," ").split(" ").filter(Boolean).slice(0,2).map(l=>l[0].toUpperCase()).join("")}function Gi({doctype:e,docname:t,currentUserName:l}){const s=ee(),[r,i]=j.useState([]),[a,d]=j.useState(!1),[u,f]=j.useState(""),[y,p]=j.useState(!1),[c,v]=j.useState(!1),[b,g]=j.useState(!1),[S,h]=j.useState(""),m=5,o=j.useCallback(async()=>{d(!0);const k=await dy(e,t);i(k),d(!1)},[e,t]);j.useEffect(()=>{o()},[o]);const x=async()=>{const k=u.trim();if(!(!k||y)){p(!0),h("");try{await uy(e,t,k),f(""),await o()}catch{h("Failed to post comment. Please try again.")}p(!1)}},z=async k=>{if(window.confirm("Delete this comment?"))try{await Nf("Comment",k),i(C=>C.filter($=>$.name!==k))}catch{alert("Failed to delete comment.")}},R=b?r:r.slice(-m),P=Math.max(0,r.length-m);return n.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[n.jsxs("div",{onClick:()=>v(k=>!k),style:{padding:"12px 20px",borderBottom:c?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none",background:"white"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["💬 ",s.comments.title,r.length>0&&n.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:r.length})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("button",{onClick:k=>{k.stopPropagation(),o()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),n.jsx("span",{style:{color:"#ccc",fontSize:11},children:c?"▼":"▲"})]})]}),!c&&n.jsxs("div",{style:{padding:"16px 20px"},children:[!b&&P>0&&n.jsxs("button",{onClick:()=>g(!0),style:{width:"100%",padding:"8px",marginBottom:12,border:"none",background:"#f8f9fa",borderRadius:6,cursor:"pointer",fontSize:12,color:"#3498db",fontFamily:"Segoe UI"},children:["Show ",P," older comment",P!==1?"s":""]}),a&&n.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:s.loading}),!a&&r.length===0&&n.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:s.comments.noComments}),!a&&R.length>0&&n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:16},children:R.map(k=>{const C=k.comment_by||k.comment_email||k.owner||"Unknown",$=k.owner===l||k.comment_by===l;return n.jsxs("div",{style:{display:"flex",gap:10,padding:"12px 14px",background:"#f9fafb",borderRadius:8,border:"1px solid #e8e8e8"},children:[n.jsx("div",{style:{width:34,height:34,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:700,flexShrink:0},children:Ky(C)}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("span",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:C}),n.jsx("span",{style:{fontSize:11,color:"#aaa"},children:Hy(k.creation)})]}),$&&n.jsx("button",{onClick:()=>z(k.name),style:{background:"none",border:"none",cursor:"pointer",color:"#e74c3c",fontSize:16,padding:"0 2px",lineHeight:1},title:"Delete comment",children:"×"})]}),n.jsx("div",{style:{fontSize:13,color:"#374151",lineHeight:1.55,wordBreak:"break-word",whiteSpace:"pre-wrap"},dangerouslySetInnerHTML:{__html:k.content||""}})]})]},k.name)})}),n.jsxs("div",{style:{borderTop:r.length>0?"1px solid #f0f0f0":"none",paddingTop:r.length>0?14:0},children:[n.jsx("textarea",{value:u,onChange:k=>f(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.ctrlKey||k.metaKey)&&x()},placeholder:s.comments.placeholder,rows:3,style:{width:"100%",padding:"10px 12px",border:"1px solid #ddd",borderRadius:8,fontSize:13,fontFamily:"Segoe UI",resize:"vertical",boxSizing:"border-box",outline:"none",color:"#1a2332"}}),S&&n.jsx("div",{style:{fontSize:12,color:"#e74c3c",marginTop:4},children:S}),n.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:8},children:n.jsx("button",{onClick:x,disabled:!u.trim()||y,style:{padding:"8px 20px",background:"#3498db",color:"white",border:"none",borderRadius:6,cursor:!u.trim()||y?"not-allowed":"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI",opacity:!u.trim()||y?.6:1},children:y?s.saving:s.comments.post})})]})]})]})}function ru(e){if(!e)return"";const t=(Date.now()-new Date(e).getTime())/1e3;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:t<86400*7?`${Math.floor(t/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Qy(e){return(e||"").replace(/^custom_/,"").replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function iu(e){return e==null||e===""?"(empty)":typeof e=="object"?JSON.stringify(e):String(e)}function zo(e){return(e||"Unknown").replace(/@.*/,"").replace(/[._]/g," ")}function au(e){return zo(e).split(" ").filter(Boolean).slice(0,2).map(t=>t[0].toUpperCase()).join("")}function Gy(e){let t={};try{t=JSON.parse(e.data||"{}")}catch{}const l=(t.changed||[]).map(s=>({field:s[0]||"",oldVal:iu(s[1]),newVal:iu(s[2])}));return{name:e.name,owner:e.owner,creation:e.creation,changes:l,added:(t.added||[]).length,removed:(t.removed||[]).length,rowChanged:(t.row_changed||[]).length}}function Yi({doctype:e,docname:t,docCreation:l,docOwner:s}){const r=ee(),[i,a]=j.useState([]),[d,u]=j.useState(!1),[f,y]=j.useState(!0),[p,c]=j.useState(!1),v=5,b=j.useCallback(async()=>{u(!0);const m=await py(e,t);a(m.map(Gy)),u(!1)},[e,t]);j.useEffect(()=>{f||b()},[f,b]);const g=p?i:i.slice(0,v),S=i.length-v,h=(m,o=!1)=>({position:"absolute",left:-14,top:14,width:10,height:10,borderRadius:"50%",background:m,border:"2px solid white",boxShadow:o?`0 0 0 2px ${m}44`:"none"});return n.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[n.jsxs("div",{onClick:()=>y(m=>!m),style:{padding:"12px 20px",borderBottom:f?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["📋 ",r.activity.title,!f&&i.length>0&&n.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:i.length})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[!f&&n.jsx("button",{onClick:m=>{m.stopPropagation(),b()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),n.jsx("span",{style:{color:"#ccc",fontSize:11},children:f?"▼":"▲"})]})]}),!f&&n.jsxs("div",{style:{padding:"16px 20px"},children:[d&&n.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:r.loading}),!d&&n.jsxs("div",{style:{position:"relative",paddingLeft:20},children:[n.jsx("div",{style:{position:"absolute",left:8,top:0,bottom:0,width:2,background:"#e5e7eb"}}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[g.map((m,o)=>n.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[n.jsx("div",{style:h(o===0?"#3498db":"#d1d5db",o===0)}),n.jsxs("div",{style:{background:o===0?"#eff6ff":"#f9fafb",border:`1px solid ${o===0?"#bfdbfe":"#e5e7eb"}`,borderRadius:8,padding:"10px 14px"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[n.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:au(m.owner)}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:zo(m.owner)}),n.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:ru(m.creation)})]}),m.changes.length>0?n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:m.changes.map((x,z)=>n.jsxs("div",{style:{fontSize:12,lineHeight:1.5},children:[n.jsx("span",{style:{fontWeight:600,color:"#6d28d9"},children:Qy(x.field)}),n.jsx("span",{style:{color:"#6b7280"},children:" changed from "}),n.jsx("span",{style:{padding:"1px 5px",background:"#fee2e2",color:"#dc2626",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:x.oldVal}),n.jsx("span",{style:{color:"#6b7280"},children:" → "}),n.jsx("span",{style:{padding:"1px 5px",background:"#dcfce7",color:"#16a34a",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:x.newVal})]},z))}):n.jsxs("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic"},children:["Document updated",m.added>0&&n.jsxs("span",{children:[" · +",m.added," row(s)"]}),m.removed>0&&n.jsxs("span",{children:[" · -",m.removed," row(s)"]}),m.rowChanged>0&&n.jsxs("span",{children:[" · ~",m.rowChanged," row(s) modified"]})]})]})]},m.name)),l&&s&&n.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[n.jsx("div",{style:h("#22c55e")}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"10px 14px"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[n.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#22c55e",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:au(s)}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:zo(s)}),n.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:ru(l)})]}),n.jsxs("div",{style:{fontSize:12,color:"#15803d",fontWeight:600},children:["✓ ",r.activity.created]})]})]}),i.length===0&&!l&&n.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:"No activity recorded"})]})]}),!d&&S>0&&n.jsx("div",{style:{textAlign:"center",marginTop:12},children:n.jsx("button",{onClick:()=>c(m=>!m),style:{background:"none",border:"none",cursor:"pointer",color:"#3498db",fontSize:12,fontFamily:"Segoe UI",padding:"4px 8px"},children:p?"▲ Show less":`▼ Show all (${i.length})`})})]})]})}const _s={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Ta={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},Yy={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 Xy(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...Yy[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function qy({incForm:e,setIncForm:t,organizations:l,managements:s,departments:r,branches:i,incidentTypes:a,incidentClasses:d,incidentFields:u,incidentStatuses:f,users:y,userRoleMap:p={},formStatus:c,viewMode:v,onEdit:b,darkMode:g,notifCount:S,onToggleDark:h,onCountChange:m,onViewProfile:o,userRole:x,onSubmit:z,onBack:R,onNavigate:P,onLogout:k,user:C,onRefresh:$}){const I=ee(),E=_=>t({...e,..._}),O=v?{background:"#f9f9f9"}:{},U=fr(y,p,"SB Manager",e.organization),[V,xe]=j.useState(""),[le,L]=j.useState(!1),M=e.name?v?`${I.formTitle.viewIncident}${e.number||e.name}`:I.formTitle.editIncident:I.formTitle.newIncident,K=fe(s,e.management).map(_=>({name:_.name,label:_.name1||_.name})),ne=fe(r,e.department).map(_=>({name:_.name,label:_.department_name||_.name})),q=fe(i,e.branch).map(_=>({name:_.name,label:_.branch||_.name})),me=fe(a,e.type).map(_=>({name:_.name,label:_.name1||_.name})),Ce=d.map(_=>({name:_.name,label:_.name1||_.name})),re=u.map(_=>({name:_.name,label:_.name1||_.name})),ze=fe(f,e.status).map(_=>({name:_.name,label:_.name1||_.name})),he=e.workflow_state||"New",H=x==="Employee",J=x==="Auditor"||x==="Admin",N=x==="Manager",oe=e.name?he==="New"?[{label:I.wf.submit,action:"Submit",color:"#2563eb"}]:he==="Initial Evaluation"&&J?[{label:I.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:I.wf.reject,action:"Reject",color:"#dc2626"}]:he==="Accept & Under Progress"&&(N||J)?[{label:I.wf.submitSolution,action:"Submit Solution",color:"#059669"}]:he==="working on resolution"&&(N||J)?[{label:I.wf.resolutionComplete,action:"Resolution complete",color:"#166534"}]:[]:[];async function Wn(_){if(e.name){L(!0),xe("");try{const Y={};_==="Assign to Manager"&&(e.assigned_to&&(Y.assigned_to=e.assigned_to),e.priority&&(Y.priority=e.priority),e.economy_class&&(Y.economy_class=e.economy_class),e.entity_scope&&(Y.entity_scope=e.entity_scope),e.hses_field&&(Y.hses_field=e.hses_field),Y.product_relation=String(e.product_relation??0),Y.repeated=String(e.repeated??0)),_==="Submit Solution"&&(e.solution&&(Y.solution=e.solution),e.summary&&(Y.summary=e.summary),e.cost&&(Y.cost=String(e.cost))),(_==="Resolution complete"||_==="Submit Solution")&&e.auditor_comment&&(Y.auditor_comment=e.auditor_comment),await gy(e.name,_,JSON.stringify(Y)),xe("Done"),$==null||$()}catch(Y){xe(Y.message||"Error")}finally{L(!1)}}}const gt=e.name?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"#f8fafc",borderRadius:10,padding:16,border:"1px solid #e2e8f0"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[n.jsx("h4",{style:{fontWeight:700,color:"#1e293b",margin:0,fontSize:14},children:I.wf.workflow}),n.jsx("span",{style:Xy(he),children:he})]}),he==="Initial Evaluation"&&J&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:I.wf.assignToManager}),n.jsxs("select",{style:A,value:e.assigned_to||"",onChange:_=>E({assigned_to:_.target.value}),children:[n.jsx("option",{value:"",children:I.field.selectMgr}),U.map(_=>n.jsx("option",{value:_.name,children:_.full_name||_.name},_.name))]})]}),(he==="Accept & Under Progress"||he==="working on resolution")&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:I.field.solution}),n.jsx("textarea",{style:{...A,height:80,resize:"vertical"},value:e.solution||"",onChange:_=>E({solution:_.target.value}),placeholder:I.field.solutionPlaceholder}),n.jsx("label",{style:{...T,marginTop:8},children:I.field.actualCost}),n.jsx("input",{type:"number",style:A,value:e.cost||"",onChange:_=>E({cost:parseFloat(_.target.value)||0}),placeholder:"0.00"})]}),he==="working on resolution"&&J&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:I.field.auditorComment}),n.jsx("textarea",{style:{...A,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:_=>E({auditor_comment:_.target.value}),placeholder:I.field.commentPlaceholder})]}),oe.length>0?n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:oe.map(_=>n.jsx("button",{onClick:()=>Wn(_.action),disabled:le,style:{padding:"8px 18px",borderRadius:8,border:"none",background:_.color,color:"white",fontWeight:700,cursor:le?"not-allowed":"pointer",opacity:le?.7:1},children:le?I.wf.applying:_.label},_.action))}):n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:I.wf.noActions}),V&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:V==="Done"?W.green:W.red},children:V})]}),n.jsx(Gi,{doctype:B.incidents,docname:e.name,currentUserName:C.name}),n.jsx(Yi,{doctype:B.incidents,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(Me,{title:M,activePage:"incidents",user:C,formStatus:c,buttonText:I.saveIncident,buttonColor:W.accent,viewMode:v,onEdit:b,darkMode:g,notifCount:S,onToggleDark:h,onCountChange:m,onViewProfile:o,rightPanel:gt,onSubmit:z,onBack:R,onNavigate:P,onLogout:k,children:[n.jsxs("div",{style:_s,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.number}),n.jsx("input",{style:{...A,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[I.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:_=>E({organization:_}),organizations:l,disabled:v||!!C.custom_organization})]})]}),n.jsxs("div",{style:Ta,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.management}),n.jsx(ue,{value:e.management,onChange:_=>E({management:_}),items:K,placeholder:I.field.select,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.department}),n.jsx(ue,{value:e.department,onChange:_=>E({department:_}),items:ne,placeholder:I.field.select,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.section}),n.jsx("input",{style:{...A,...O},value:e.section_field||"",disabled:v,onChange:_=>E({section_field:_.target.value})})]})]}),n.jsxs("div",{style:_s,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.branch}),n.jsx(ue,{value:e.branch,onChange:_=>E({branch:_}),items:q,placeholder:I.field.select,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.hsesField}),n.jsx("input",{style:{...A,...O},value:e.hses_field||"",disabled:v,onChange:_=>E({hses_field:_.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{style:_s,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.type}),n.jsx(ue,{value:e.type,onChange:_=>E({type:_}),items:me,placeholder:I.field.selectType,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.title}),n.jsx("input",{style:{...A,...O},value:e.title,disabled:v,onChange:_=>E({title:_.target.value})})]})]}),n.jsxs("div",{style:_s,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.incidentClass}),n.jsx(ue,{value:e.incident_class,onChange:_=>E({incident_class:_}),items:Ce,placeholder:I.field.selectClass,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.incidentField}),n.jsx(ue,{value:e.incident_field,onChange:_=>E({incident_field:_}),items:re,placeholder:I.field.selectField,disabled:v})]})]}),n.jsxs("div",{style:Ta,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.date}),n.jsx(ye,{value:e.date,onChange:_=>E({date:_}),disabled:v,style:{...A,...O}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.time}),n.jsx("input",{type:"time",style:{...A,...O},value:e.time,disabled:v,onChange:_=>E({time:_.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.assignedTo}),n.jsxs("select",{style:{...A,...O},value:e.assigned_to,disabled:v,onChange:_=>E({assigned_to:_.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),U.map(_=>n.jsx("option",{value:_.name,children:_.full_name||_.name},_.name))]})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.status}),n.jsx(ue,{value:e.status,onChange:_=>E({status:_}),items:ze,placeholder:I.field.selectStatus,disabled:v})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.description}),n.jsx("textarea",{style:{...A,...O,height:120,resize:"vertical"},value:e.description,disabled:v,onChange:_=>E({description:_.target.value})})]}),!H&&n.jsxs("div",{style:{background:"#fffbeb",border:"1px solid #fde68a",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#92400e",marginBottom:10},children:I.steps.auditorTriage}),n.jsxs("div",{style:Ta,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.priority}),n.jsxs("select",{style:{...A,...v&&!J?{background:"#f9f9f9"}:{}},value:e.priority||"",disabled:v&&!J,onChange:_=>E({priority:_.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"High",children:I.field.high}),n.jsx("option",{value:"Normal",children:I.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.economyClass}),n.jsxs("select",{style:{...A,...v&&!J?{background:"#f9f9f9"}:{}},value:e.economy_class||"",disabled:v&&!J,onChange:_=>E({economy_class:_.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Expenses",children:I.field.expenses}),n.jsx("option",{value:"Capital",children:I.field.capital}),n.jsx("option",{value:"Earn",children:I.field.earn}),n.jsx("option",{value:"Pay/Loss",children:I.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.entityScope}),n.jsxs("select",{style:{...A,...v&&!J?{background:"#f9f9f9"}:{}},value:e.entity_scope||"",disabled:v&&!J,onChange:_=>E({entity_scope:_.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Upstream",children:I.field.upstream}),n.jsx("option",{value:"On-stream",children:I.field.onstream}),n.jsx("option",{value:"Downstream",children:I.field.downstream})]})]})]}),n.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center"},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:v&&!J,onChange:_=>E({product_relation:_.target.checked?1:0})})," ",I.field.productRelation]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:v&&!J,onChange:_=>E({repeated:_.target.checked?1:0})})," ",I.field.repeatedEvent]})]})]}),!H&&n.jsxs("div",{style:{background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#1e40af",marginBottom:10},children:I.steps.managerSolution}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.solution}),n.jsx("textarea",{style:{...A,height:100,resize:"vertical",...v&&!N&&!J?{background:"#f9f9f9"}:{}},value:e.solution||"",disabled:v&&!N&&!J,onChange:_=>E({solution:_.target.value}),placeholder:I.field.solutionPlaceholder})]}),n.jsxs("div",{style:_s,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.actualCost}),n.jsx("input",{type:"number",style:{...A,...v&&!N&&!J?{background:"#f9f9f9"}:{}},value:e.cost||"",disabled:v&&!N&&!J,onChange:_=>E({cost:parseFloat(_.target.value)||0}),placeholder:"0.00"})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.summary}),n.jsx("input",{style:{...A,...v&&!N&&!J?{background:"#f9f9f9"}:{}},value:e.summary||"",disabled:v&&!N&&!J,onChange:_=>E({summary:_.target.value}),placeholder:"Brief summary"})]})]})]}),!H&&n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:10},children:I.steps.ownerComment}),n.jsx("textarea",{style:{...A,height:80,resize:"vertical",...v&&!J?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:v&&!J,onChange:_=>E({auditor_comment:_.target.value}),placeholder:I.field.commentPlaceholder})]})]})}function Jy({ideas:e,organizations:t,departments:l,branches:s,ideaStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=ee(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),b=(o,x)=>v(z=>({...z,[o]:x})),[g,S]=j.useState(1),h=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{S(1)},[c]);const m=h.slice((g-1)*se,g*se);return n.jsxs(n.Fragment,{children:[n.jsx(Qi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.numberTitle}),n.jsx("input",{style:Ue,value:c.search,onChange:o=>b("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.organization}),n.jsxs("select",{style:Ue,value:c.organization,onChange:o=>b("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.department}),n.jsxs("select",{style:Ue,value:c.department,onChange:o=>b("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.branch}),n.jsxs("select",{style:Ue,value:c.branch,onChange:o=>b("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.status}),n.jsxs("select",{style:Ue,value:c.status,onChange:o=>b("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name))]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:h.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noIdeas})}):m.map((o,x)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Ln(o.status,Ki(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:z=>z.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Fe,{page:g,total:h.length,onPageChange:S})]})}const ou={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Pa={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},Zy={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 Vy(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...Zy[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function e0({ideaForm:e,setIdeaForm:t,organizations:l,managements:s,departments:r,branches:i,ideaTypes:a,ideaStatuses:d,users:u=[],userRoleMap:f={},formStatus:y,viewMode:p,onEdit:c,darkMode:v,notifCount:b,onToggleDark:g,onCountChange:S,onViewProfile:h,userRole:m,onSubmit:o,onBack:x,onNavigate:z,onLogout:R,user:P,onRefresh:k}){const C=ee(),$=N=>t({...e,...N}),I=p?{background:"#f9f9f9"}:{},E=fr(u,f,"SB Manager",e.organization),[O,U]=j.useState(""),[V,xe]=j.useState(!1),le=e.name?p?`${C.formTitle.viewIdea}${e.number||e.title||e.name}`:C.formTitle.editIdea:C.formTitle.newIdea,L=fe(s,e.management).map(N=>({name:N.name,label:N.name1||N.name})),M=fe(r,e.department).map(N=>({name:N.name,label:N.department_name||N.name})),K=fe(i,e.branch).map(N=>({name:N.name,label:N.branch||N.name})),ne=fe(a,e.type).map(N=>({name:N.name,label:N.name1||N.name})),q=fe(d,e.status).map(N=>({name:N.name,label:N.name1||N.name})),me=e.workflow_state||"New",Ce=m==="Employee",re=m==="Auditor"||m==="Admin",ze=m==="Manager",he=e.name?me==="New"?[{label:C.wf.submit,action:"Submit",color:"#2563eb"}]:me==="Initial Evaluation"&&re?[{label:C.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:C.wf.reject,action:"Reject",color:"#dc2626"}]:me==="Accept & Under Progress"&&(ze||re)?[{label:C.wf.submitSolution,action:"Submit Proposal",color:"#059669"}]:me==="working on proposal"&&re?[{label:C.wf.moveToOutsourcing,action:"Move to Outsourcing",color:"#0369a1"},{label:C.wf.reject,action:"Reject",color:"#dc2626"}]:[]:[];async function H(N){if(e.name){xe(!0),U("");try{const oe={};N==="Assign to Manager"&&(e.assigned_to&&(oe.assigned_to=e.assigned_to),e.priority&&(oe.priority=e.priority),e.economy_class&&(oe.economy_class=e.economy_class),e.entity_scope&&(oe.entity_scope=e.entity_scope),e.hses_field&&(oe.hses_field=e.hses_field),oe.product_relation=String(e.product_relation??0),oe.repeated=String(e.repeated??0)),N==="Submit Proposal"&&(e.solution&&(oe.solution=e.solution),e.proposed_condition&&(oe.proposed_condition=e.proposed_condition),e.cost&&(oe.cost=String(e.cost))),e.auditor_comment&&(N==="Move to Outsourcing"||N==="Reject")&&(oe.auditor_comment=e.auditor_comment),await xy(e.name,N,JSON.stringify(oe)),U("Done"),k==null||k()}catch(oe){U(oe.message||"Error")}finally{xe(!1)}}}const J=e.name?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"#f8fafc",borderRadius:10,padding:16,border:"1px solid #e2e8f0"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[n.jsx("h4",{style:{fontWeight:700,color:"#1e293b",margin:0,fontSize:14},children:C.wf.workflow}),n.jsx("span",{style:Vy(me),children:me})]}),me==="Initial Evaluation"&&re&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:C.wf.assignToManager}),n.jsxs("select",{style:A,value:e.assigned_to||"",onChange:N=>$({assigned_to:N.target.value}),children:[n.jsx("option",{value:"",children:C.field.selectMgr}),E.map(N=>n.jsx("option",{value:N.name,children:N.full_name||N.name},N.name))]})]}),me==="Accept & Under Progress"&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:C.field.solution}),n.jsx("textarea",{style:{...A,height:80,resize:"vertical"},value:e.solution||"",onChange:N=>$({solution:N.target.value}),placeholder:C.field.solutionPlaceholder}),n.jsx("label",{style:{...T,marginTop:8},children:C.field.actualCost}),n.jsx("input",{type:"number",style:A,value:e.cost||"",onChange:N=>$({cost:parseFloat(N.target.value)||0}),placeholder:"0.00"})]}),me==="working on proposal"&&re&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:C.field.auditorComment}),n.jsx("textarea",{style:{...A,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:N=>$({auditor_comment:N.target.value}),placeholder:C.field.commentPlaceholder})]}),he.length>0?n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:he.map(N=>n.jsx("button",{onClick:()=>H(N.action),disabled:V,style:{padding:"8px 18px",borderRadius:8,border:"none",background:N.color,color:"white",fontWeight:700,cursor:V?"not-allowed":"pointer",opacity:V?.7:1},children:V?C.wf.applying:N.label},N.action))}):n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:C.wf.noActions}),O&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:O==="Done"?W.green:W.red},children:O})]}),n.jsx(Gi,{doctype:B.ideas,docname:e.name,currentUserName:P.name}),n.jsx(Yi,{doctype:B.ideas,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(Me,{title:le,activePage:"ideas",user:P,formStatus:y,buttonText:C.saveIdea,buttonColor:W.teal,viewMode:p,onEdit:c,darkMode:v,notifCount:b,onToggleDark:g,onCountChange:S,onViewProfile:h,rightPanel:J,onSubmit:o,onBack:x,onNavigate:z,onLogout:R,children:[n.jsxs("div",{style:ou,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.number}),n.jsx("input",{style:{...A,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[C.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:N=>$({organization:N}),organizations:l,disabled:p||!!P.custom_organization})]})]}),n.jsxs("div",{style:Pa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.management}),n.jsx(ue,{value:e.management,onChange:N=>$({management:N}),items:L,placeholder:C.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.department}),n.jsx(ue,{value:e.department,onChange:N=>$({department:N}),items:M,placeholder:C.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.section}),n.jsx("input",{style:{...A,...I},value:e.section_field||"",disabled:p,onChange:N=>$({section_field:N.target.value})})]})]}),n.jsxs("div",{style:ou,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.branch}),n.jsx(ue,{value:e.branch,onChange:N=>$({branch:N}),items:K,placeholder:C.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.date}),n.jsx(ye,{value:e.date||"",onChange:N=>$({date:N}),disabled:p,style:{...A,...I}})]})]}),n.jsxs("div",{style:Pa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.type}),n.jsx(ue,{value:e.type,onChange:N=>$({type:N}),items:ne,placeholder:C.field.selectType,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.ideaClass}),n.jsxs("select",{style:{...A,...I},value:e.idea_class||"",disabled:p,onChange:N=>$({idea_class:N.target.value}),children:[n.jsx("option",{value:"",children:C.field.select}),n.jsx("option",{value:"Safety",children:"Safety"}),n.jsx("option",{value:"Non-safety",children:"Non-safety"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.hsesField}),n.jsx("input",{style:{...A,...I},value:e.hses_field||"",disabled:p,onChange:N=>$({hses_field:N.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.title}),n.jsx("input",{style:{...A,...I},value:e.title,disabled:p,onChange:N=>$({title:N.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.status}),n.jsx(ue,{value:e.status,onChange:N=>$({status:N}),items:q,placeholder:C.field.selectStatus,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.currentCondition}),n.jsx("textarea",{style:{...A,...I,height:110,resize:"vertical"},value:e.current_condition,disabled:p,onChange:N=>$({current_condition:N.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.proposedCondition}),n.jsx("textarea",{style:{...A,...I,height:110,resize:"vertical"},value:e.proposed_condition,disabled:p,onChange:N=>$({proposed_condition:N.target.value})})]}),!Ce&&n.jsxs("div",{style:{background:"#fffbeb",border:"1px solid #fde68a",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#92400e",marginBottom:10},children:C.steps.auditorEval}),n.jsxs("div",{style:Pa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.priority}),n.jsxs("select",{style:{...A,...p&&!re?{background:"#f9f9f9"}:{}},value:e.priority||"",disabled:p&&!re,onChange:N=>$({priority:N.target.value}),children:[n.jsx("option",{value:"",children:C.field.select}),n.jsx("option",{value:"High",children:C.field.high}),n.jsx("option",{value:"Normal",children:C.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.economyClass}),n.jsxs("select",{style:{...A,...p&&!re?{background:"#f9f9f9"}:{}},value:e.economy_class||"",disabled:p&&!re,onChange:N=>$({economy_class:N.target.value}),children:[n.jsx("option",{value:"",children:C.field.select}),n.jsx("option",{value:"Expenses",children:C.field.expenses}),n.jsx("option",{value:"Capital",children:C.field.capital}),n.jsx("option",{value:"Earn",children:C.field.earn}),n.jsx("option",{value:"Pay/Loss",children:C.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.entityScope}),n.jsxs("select",{style:{...A,...p&&!re?{background:"#f9f9f9"}:{}},value:e.entity_scope||"",disabled:p&&!re,onChange:N=>$({entity_scope:N.target.value}),children:[n.jsx("option",{value:"",children:C.field.select}),n.jsx("option",{value:"Upstream",children:C.field.upstream}),n.jsx("option",{value:"On-stream",children:C.field.onstream}),n.jsx("option",{value:"Downstream",children:C.field.downstream})]})]})]}),n.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center"},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:p&&!re,onChange:N=>$({product_relation:N.target.checked?1:0})})," ",C.field.productRelation]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:p&&!re,onChange:N=>$({repeated:N.target.checked?1:0})})," ",C.field.repeatedEvent]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:C.wf.assignToManager}),n.jsxs("select",{style:{...A,...p&&!re?{background:"#f9f9f9"}:{}},value:e.assigned_to||"",disabled:p&&!re,onChange:N=>$({assigned_to:N.target.value}),children:[n.jsx("option",{value:"",children:C.field.select}),E.map(N=>n.jsx("option",{value:N.name,children:N.full_name||N.name},N.name))]})]})]}),!Ce&&n.jsxs("div",{style:{background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#1e40af",marginBottom:10},children:C.steps.managerSolution}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:C.field.solution}),n.jsx("textarea",{style:{...A,height:100,resize:"vertical",...p&&!ze&&!re?{background:"#f9f9f9"}:{}},value:e.solution||"",disabled:p&&!ze&&!re,onChange:N=>$({solution:N.target.value}),placeholder:C.field.solutionPlaceholder})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:C.field.actualCost}),n.jsx("input",{type:"number",style:{...A,...p&&!ze&&!re?{background:"#f9f9f9"}:{}},value:e.cost||"",disabled:p&&!ze&&!re,onChange:N=>$({cost:parseFloat(N.target.value)||0}),placeholder:"0.00"})]})]}),!Ce&&n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:10},children:C.steps.ownerComment}),n.jsx("textarea",{style:{...A,height:80,resize:"vertical",...p&&!re?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:p&&!re,onChange:N=>$({auditor_comment:N.target.value}),placeholder:C.field.commentPlaceholder})]})]})}function t0({orders:e,organizations:t,departments:l,branches:s,orderStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=ee(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),b=(o,x)=>v(z=>({...z,[o]:x})),[g,S]=j.useState(1),h=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{S(1)},[c]);const m=h.slice((g-1)*se,g*se);return n.jsxs(n.Fragment,{children:[n.jsx(Qi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.numberTitle}),n.jsx("input",{style:Ue,value:c.search,onChange:o=>b("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.organization}),n.jsxs("select",{style:Ue,value:c.organization,onChange:o=>b("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.department}),n.jsxs("select",{style:Ue,value:c.department,onChange:o=>b("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.branch}),n.jsxs("select",{style:Ue,value:c.branch,onChange:o=>b("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.status}),n.jsxs("select",{style:Ue,value:c.status,onChange:o=>b("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name))]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.type}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:h.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noOrders})}):m.map((o,x)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.type?Ln(o.type,"#8e44ad"):"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Ln(o.status,Ki(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:z=>z.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Fe,{page:g,total:h.length,onPageChange:S})]})}const $r={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Ur={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},n0={1:"Initiation / Bidding",2:"Execution begins",3:"Mid-execution review",4:"Near completion",5:"Closing"},l0={Draft:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Pending Actor":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},Review:{background:"#f0fdf4",color:"#15803d",border:"1px solid #bbf7d0"},"In Study":{background:"#f1f5f9",color:"#475569",border:"1px solid #cbd5e1"},Closed:{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function s0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...l0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function r0({orderForm:e,setOrderForm:t,organizations:l,managements:s,departments:r,branches:i,orderTypes:a,orderStatuses:d,cycles:u=[],users:f,userRoleMap:y={},formStatus:p,viewMode:c,onEdit:v,darkMode:b,notifCount:g,onToggleDark:S,onCountChange:h,onViewProfile:m,currentUser:o,userRole:x,onSubmit:z,onBack:R,onNavigate:P,onLogout:k,user:C,onRefresh:$}){var $n;const I=ee(),E=D=>t({...e,...D}),O=c?{background:"#f9f9f9"}:{},U=fr(f,y,"SB Employee",e.organization),[V,xe]=j.useState(""),[le,L]=j.useState(""),[M,K]=j.useState(!1),[ne,q]=j.useState("Agree"),me=e.name?c?`${I.formTitle.viewOrder}${e.number||e.title||e.name}`:I.formTitle.editOrder:I.formTitle.newOrder,Ce=fe(s,e.management).map(D=>({name:D.name,label:D.name1||D.name})),re=fe(r,e.department).map(D=>({name:D.name,label:D.department_name||D.name})),ze=fe(i,e.branch).map(D=>({name:D.name,label:D.branch||D.name})),he=fe(a,e.type).map(D=>({name:D.name,label:D.name1||D.name})),H=fe(d,e.status).map(D=>({name:D.name,label:D.name1||D.name})),J=fe(u,e.cycle).map(D=>({name:D.name,label:D.name1||D.name})),N=!!e.name,oe=e.workflow_state||"Draft",Wn=Math.min(5,(e.stage||0)+1),[gt,_]=j.useState(Wn);j.useEffect(()=>{_(Math.min(5,(e.stage||0)+1))},[e.stage]);const Y=x==="Auditor"||x==="Admin"||x==="Manager",Z=Y||x==="Owner",Yt=!!(o&&(e.actor===o||e.assigned_to===o)),gr=N?oe==="Closed"?[]:oe==="Draft"&&Y?[{label:"Submit for Review",action:"Submit for Review",color:"#2563eb"}]:oe==="Pending Actor"&&(Yt||Y)?[{label:"Update Status",action:"Update Status",color:"#d97706"}]:oe==="Review"&&Z?[{label:"Move to Study",action:"Move to Study",color:"#059669"},{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}]:oe==="In Study"&&Z?[{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"},{label:"Close Order",action:"Close Order",color:"#475569"}]:[]:[];async function Bn(D){if(e.name){K(!0),xe("");try{let Ge;D==="Update Status"&&(Ge=ne);const hl=await hy(e.name,D,le,D==="Update Status"?String(gt):void 0,void 0,Ge);if(L(""),q("Agree"),xe("Done"),hl){const kt=hl;t({...e,...kt,stage:kt.stage??e.stage,completion_pct:kt.completion_pct??e.completion_pct,workflow_state:kt.workflow_state??e.workflow_state})}$==null||$()}catch(Ge){xe(Ge.message||"Error")}finally{K(!1)}}}const Xi=N?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsxs("div",{style:{background:"#f8fafc",borderRadius:10,padding:16,border:"1px solid #e2e8f0"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[n.jsx("h4",{style:{fontWeight:700,color:"#1e293b",margin:0,fontSize:14},children:I.wf.workflow}),n.jsx("span",{style:s0(oe),children:oe})]}),oe==="Pending Actor"&&n.jsxs("div",{style:{display:"flex",gap:16,marginBottom:14,flexWrap:"wrap"},children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:["Stage (1–5) — ",gt*20,"% complete"]}),n.jsx("input",{type:"number",min:1,max:5,style:{...A,maxWidth:80},value:gt,onChange:D=>_(Math.min(5,Math.max(1,parseInt(D.target.value)||1)))})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Cycle Status"}),n.jsxs("select",{style:{...A,minWidth:140},value:ne,onChange:D=>q(D.target.value),children:[n.jsx("option",{value:"Agree",children:"✅ Agree — on track"}),n.jsx("option",{value:"Deviate",children:"⚠️ Deviate — off plan"}),n.jsx("option",{value:"Unknown",children:"❓ Unknown"})]})]})]}),n.jsxs("div",{style:{marginBottom:14},children:[n.jsxs("label",{style:T,children:["Comment ",ne==="Deviate"&&oe==="Pending Actor"?n.jsx("span",{style:{color:W.red},children:" * required for Deviate"}):"(optional)"]}),n.jsx("textarea",{style:{...A,height:64,resize:"vertical",borderColor:ne==="Deviate"&&!le?"#fca5a5":void 0},value:le,onChange:D=>L(D.target.value),placeholder:"Add a comment…"})]}),n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:gr.map(D=>{const Ge=D.action==="Update Status"&&ne==="Deviate"&&!le.trim();return n.jsx("button",{onClick:()=>Bn(D.action),disabled:M||Ge,title:Ge?"Comment required when status is Deviate":void 0,style:{padding:"8px 18px",borderRadius:8,border:"none",background:D.color,color:"white",fontWeight:700,cursor:M||Ge?"not-allowed":"pointer",opacity:M||Ge?.5:1},children:M?I.wf.applying:D.label},D.action)})}),V&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:V==="Done"?W.green:W.red},children:V}),gr.length===0&&n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:I.wf.noActions})]}),n.jsx(Gi,{doctype:B.orders,docname:e.name,currentUserName:C.name}),n.jsx(Yi,{doctype:B.orders,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(Me,{title:me,activePage:"orders",user:C,formStatus:p,buttonText:I.saveOrder,buttonColor:W.purple,viewMode:c,onEdit:v,darkMode:b,notifCount:g,onToggleDark:S,onCountChange:h,onViewProfile:m,rightPanel:Xi,onSubmit:z,onBack:R,onNavigate:P,onLogout:k,children:[n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.number}),n.jsx("input",{style:{...A,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[I.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:D=>E({organization:D}),organizations:l,disabled:c||!!C.custom_organization})]})]}),n.jsxs("div",{style:Ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.management}),n.jsx(ue,{value:e.management,onChange:D=>E({management:D}),items:Ce,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.department}),n.jsx(ue,{value:e.department,onChange:D=>E({department:D}),items:re,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.section}),n.jsx("input",{style:{...A,...O},value:e.section_field||"",disabled:c,onChange:D=>E({section_field:D.target.value})})]})]}),n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.branch}),n.jsx(ue,{value:e.branch,onChange:D=>E({branch:D}),items:ze,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.type}),n.jsx(ue,{value:e.type,onChange:D=>E({type:D}),items:he,placeholder:I.field.selectType,disabled:c})]})]}),n.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:14,marginTop:4},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#475569",marginBottom:10},children:"Classification"}),n.jsxs("div",{style:Ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.priority}),n.jsxs("select",{style:{...A,...O},value:e.priority||"",disabled:c,onChange:D=>E({priority:D.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"High",children:I.field.high}),n.jsx("option",{value:"Normal",children:I.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.economyClass}),n.jsxs("select",{style:{...A,...O},value:e.economy_class||"",disabled:c,onChange:D=>E({economy_class:D.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Expenses",children:I.field.expenses}),n.jsx("option",{value:"Capital",children:I.field.capital}),n.jsx("option",{value:"Earn",children:I.field.earn}),n.jsx("option",{value:"Pay/Loss",children:I.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.entityScope}),n.jsxs("select",{style:{...A,...O},value:e.entity_scope||"",disabled:c,onChange:D=>E({entity_scope:D.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"Upstream",children:I.field.upstream}),n.jsx("option",{value:"On-stream",children:I.field.onstream}),n.jsx("option",{value:"Downstream",children:I.field.downstream})]})]})]}),n.jsxs("div",{style:{display:"flex",gap:24,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.planned,disabled:c,onChange:D=>E({planned:D.target.checked?1:0})})," Planned"]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:D=>E({product_relation:D.target.checked?1:0})})," ",I.field.productRelation]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:I.field.hsesField}),n.jsx("input",{style:{...A,...O},value:e.hses_field||"",disabled:c,onChange:D=>E({hses_field:D.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.title}),n.jsx("input",{style:{...A,...O},value:e.title,disabled:c,onChange:D=>E({title:D.target.value})})]}),n.jsxs("div",{style:Ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.budget}),n.jsx("input",{type:"number",style:{...A,...O},value:e.budget||"",disabled:c,onChange:D=>E({budget:parseFloat(D.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.actualCost}),n.jsx("input",{type:"number",style:{...A,...O},value:e.actual_cost||"",disabled:c,onChange:D=>E({actual_cost:parseFloat(D.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Variance"}),(()=>{const D=(e.budget||0)-(e.actual_cost||0);return n.jsxs("span",{style:{display:"inline-block",padding:"6px 12px",borderRadius:8,fontWeight:700,fontSize:13,background:D>=0?"#f0fdf4":"#fef2f2",color:D>=0?"#166534":"#dc2626",border:`1px solid ${D>=0?"#bbf7d0":"#fecaca"}`},children:[D>=0?"+":"",D.toFixed(2)]})})()]})]}),n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.currency}),n.jsxs("select",{style:{...A,...O},value:e.currency||"",disabled:c,onChange:D=>E({currency:D.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),n.jsx("option",{value:"SAR",children:"SAR"}),n.jsx("option",{value:"USD",children:"USD"}),n.jsx("option",{value:"EUR",children:"EUR"}),n.jsx("option",{value:"AED",children:"AED"}),n.jsx("option",{value:"GBP",children:"GBP"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.status}),n.jsx(ue,{value:e.status,onChange:D=>E({status:D}),items:H,placeholder:I.field.selectStatus,disabled:c||oe==="Closed"})]})]}),n.jsxs("div",{style:Ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.startingDate}),n.jsx(ye,{value:e.starting_date,onChange:D=>E({starting_date:D}),disabled:c,style:{...A,...O}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.endingDate}),n.jsx(ye,{value:e.ending_date,onChange:D=>E({ending_date:D}),disabled:c,style:{...A,...O}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.actor}),n.jsxs("select",{style:{...A,...O},value:e.actor||e.assigned_to||"",disabled:c,onChange:D=>E({actor:D.target.value,assigned_to:D.target.value}),children:[n.jsx("option",{value:"",children:I.field.select}),U.map(D=>n.jsx("option",{value:D.name,children:D.full_name||D.name},D.name))]})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",fontSize:13,marginBottom:12},children:"Cycle & Progress"}),n.jsxs("div",{style:$r,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.cycle}),n.jsx(ue,{value:e.cycle||"",onChange:D=>E({cycle:D}),items:J,placeholder:I.field.select,disabled:c})]}),n.jsxs("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.stage}),n.jsx("input",{type:"number",min:1,max:5,style:{...A,background:"#f9f9f9",maxWidth:80},value:e.stage||1,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Completion"}),n.jsx("input",{style:{...A,background:"#f9f9f9",maxWidth:100},value:`${e.completion_pct||(e.stage||1)*20}%`,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Stage Description"}),n.jsx("span",{style:{display:"inline-block",padding:"6px 12px",borderRadius:8,fontSize:13,fontWeight:600,background:"#f0f9ff",color:"#0369a1",border:"1px solid #bae6fd"},children:n0[e.stage||1]||"—"})]}),(e.escalation_level??0)>0&&n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.escalationLevel}),n.jsxs("span",{style:{display:"inline-block",padding:"6px 12px",background:"#fecaca",color:"#e74c3c",borderRadius:8,fontWeight:700,fontSize:13},children:["Level ",e.escalation_level]})]})]})]})]}),N&&(($n=e.order_cycle_log)==null?void 0:$n.length)>0&&n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",fontSize:13,marginBottom:10},children:"Cycle History"}),n.jsx("div",{style:{overflowX:"auto"},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8fafc"},children:["Cycle","Date","Stage","Status","Actor","Comment"].map(D=>n.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:600,color:"#475569",borderBottom:"1px solid #e2e8f0"},children:D},D))})}),n.jsx("tbody",{children:(e.order_cycle_log||[]).map((D,Ge)=>{const hl=D.status==="Agree"?"#166534":D.status==="Deviate"?"#c2410c":"#92400e",kt=D.status==="Agree"?"#f0fdf4":D.status==="Deviate"?"#fff7ed":"#fefce8";return n.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:D.cycle||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:D.cycle_date||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155",textAlign:"center"},children:D.stage||"—"}),n.jsx("td",{style:{padding:"6px 10px"},children:n.jsx("span",{style:{background:kt,color:hl,padding:"2px 8px",borderRadius:12,fontWeight:600,fontSize:12},children:D.status||"—"})}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:D.actor||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#64748b",fontStyle:D.comment?"normal":"italic"},children:D.comment||"—"})]},Ge)})})]})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.description}),n.jsx("textarea",{style:{...A,...O,height:100,resize:"vertical"},value:e.description,disabled:c,onChange:D=>E({description:D.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:I.field.notes}),n.jsx("textarea",{style:{...A,...O,height:100,resize:"vertical"},value:e.notes,disabled:c,onChange:D=>E({notes:D.target.value})})]}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:4},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:8},children:I.field.auditorComment}),n.jsx("textarea",{style:{...A,height:80,resize:"vertical",...c&&Yt&&!Y?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:c&&Yt&&!Y,onChange:D=>E({auditor_comment:D.target.value}),placeholder:I.field.commentPlaceholder})]})]})}function i0({processes:e,organizations:t,departments:l,branches:s,processStatuses:r,initialOrg:i,initialStatus:a,canModify:d,onView:u,onEdit:f,onDelete:y}){const p=ee(),[c,v]=j.useState({search:"",organization:i||"",department:"",branch:"",status:a||""}),b=(o,x)=>v(z=>({...z,[o]:x})),[g,S]=j.useState(1),h=e.filter(o=>!(c.search&&!`${o.number} ${o.title}`.toLowerCase().includes(c.search.toLowerCase())||c.organization&&o.organization!==c.organization||c.department&&o.department!==c.department||c.branch&&o.branch!==c.branch||c.status&&o.status!==c.status));j.useEffect(()=>{S(1)},[c]);const m=h.slice((g-1)*se,g*se);return n.jsxs(n.Fragment,{children:[n.jsx(Qi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.numberTitle}),n.jsx("input",{style:Ue,value:c.search,onChange:o=>b("search",o.target.value),placeholder:p.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.organization}),n.jsxs("select",{style:Ue,value:c.organization,onChange:o=>b("organization",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allOrgs}),t.map(o=>n.jsx("option",{value:o.name,children:o.organization_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.department}),n.jsxs("select",{style:Ue,value:c.department,onChange:o=>b("department",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allDepts}),l.map(o=>n.jsx("option",{value:o.name,children:o.department_name||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.branch}),n.jsxs("select",{style:Ue,value:c.branch,onChange:o=>b("branch",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allBranches}),s.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:$e,children:p.filter.status}),n.jsxs("select",{style:Ue,value:c.status,onChange:o=>b("status",o.target.value),children:[n.jsx("option",{value:"",children:p.filter.allStatuses}),r.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name))]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>v({search:"",organization:"",department:"",branch:"",status:""}),style:{padding:"5px 12px",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:12,color:"#6b7280",fontFamily:"Segoe UI"},children:p.clear})})]})}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.number}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.title}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.field.cycleType}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:p.col.actions})]})}),n.jsx("tbody",{children:h.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:p.noProcesses})}):m.map((o,x)=>n.jsxs("tr",{onClick:()=>u==null?void 0:u(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.title||o.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.cycle_type?Ln(o.cycle_type,"#8e44ad"):"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.status?Ln(o.status,Ki(o.status)):"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:z=>z.stopPropagation(),children:n.jsx(Je,{onView:()=>u==null?void 0:u(o),onEdit:d&&f?()=>f(o):void 0,onDelete:d&&y?()=>y(o.name):void 0})})]},o.name))})]})}),n.jsx(Fe,{page:g,total:h.length,onPageChange:S})]})}const a0={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 cu(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 Fr={width:"100%",padding:"6px 8px",border:"1px solid #d1d5db",borderRadius:5,fontSize:12,fontFamily:"Segoe UI",boxSizing:"border-box"};function c0({processName:e,userRole:t,onRefresh:l,canUpdateStatus:s=!0}){const[r,i]=j.useState(null),[a,d]=j.useState(!0),[u,f]=j.useState(""),[y,p]=j.useState(!1),[c,v]=j.useState(""),[b,g]=j.useState(""),[S,h]=j.useState("Pass"),[m,o]=j.useState(""),[x,z]=j.useState({}),R=j.useCallback(async()=>{if(!e){d(!1);return}d(!0),f("");try{const O=await Ls(e);i(O);const U={};for(const V of O.progress_indicators||[])U[V.name]=V.actual_value!=null?String(V.actual_value):"";z(U)}catch(O){f(O instanceof Error?O.message:"Failed to load process")}d(!1)},[e]);if(j.useEffect(()=>{R()},[R]),a)return n.jsx("div",{style:{width:260,flexShrink:0},children:n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:24,color:"#aaa",fontSize:13,textAlign:"center"},children:"Loading…"})});if(u||!r)return n.jsx("div",{style:{width:260,flexShrink:0},children:n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:16},children:n.jsx("div",{style:{fontSize:12,color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px"},children:u||"Could not load workflow"})})});const P=r.workflow_state||"Draft",k=a0[P]??[],C=t==="Employee"||t==="Manager",$=t!=="Manager"||s,I=k.filter(O=>(t==="Admin"||O.allowedRoles.includes(t))&&(O.action!=="Update Status"||$)),E=async O=>{p(!0),v(""),g("");try{const U={};if(O==="Update Status"){U.actor_status=S,U.actor_comment=m;const xe=r.progress_indicators||[];xe.length>0&&(U.progress_indicators=xe.map(le=>({name:le.name,actual_value:x[le.name]??""})))}O==="Add Comment"&&m&&(U.actor_comment=m);const V=await Ty(r.name,O,U);i(V),o(""),g(`Done — now: ${V.workflow_state||"updated"}`),l==null||l()}catch(U){v(U instanceof Error?U.message:"Action failed")}p(!1)};return n.jsx("div",{style:{width:260,flexShrink:0},children:n.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[n.jsx("div",{style:{background:"#1a2332",color:"white",padding:"10px 14px",fontSize:12,fontWeight:700,letterSpacing:.3},children:"Workflow"}),n.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:8},children:"Current State"}),n.jsx("div",{style:cu(P),children:P})]}),P==="Pending Actor"&&C&&$&&n.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Update Status"}),Array.isArray(r.progress_indicators)&&r.progress_indicators.length>0&&n.jsxs("div",{style:{marginBottom:10},children:[n.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Actual Value"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.progress_indicators.map(O=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("span",{style:{fontSize:11,color:"#555",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:O.name1,children:O.name1||O.name}),n.jsx("input",{type:"number",value:x[O.name]??"",onChange:U=>z(V=>({...V,[O.name]:U.target.value})),style:{...Fr,width:70,flexShrink:0},placeholder:"0"})]},O.name))})]}),n.jsxs("div",{style:{marginBottom:8},children:[n.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Cycle Status"}),n.jsxs("select",{value:S,onChange:O=>h(O.target.value),style:Fr,children:[n.jsx("option",{value:"Pass",children:"✅ Pass — on target"}),n.jsx("option",{value:"Fail",children:"❌ Fail — off target"})]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Comment (optional)"}),n.jsx("textarea",{value:m,onChange:O=>o(O.target.value),style:{...Fr,height:52,resize:"vertical"},placeholder:"Add a comment…"})]})]}),(P==="Pending Comment"||P==="Review")&&!C&&n.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Auditor Comment"}),Array.isArray(r.cycle_logs)&&r.cycle_logs.length>0&&n.jsxs("div",{style:{marginBottom:8,padding:"6px 10px",background:"#f8fafc",borderRadius:6,border:"1px solid #e2e8f0"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",marginBottom:3},children:"Latest cycle status:"}),(()=>{const O=r.cycle_logs,U=O[O.length-1],V=U.status==="Pass"?"#16a34a":U.status==="Fail"?"#dc2626":"#9ca3af";return n.jsxs("div",{style:{fontSize:13,fontWeight:700,color:V},children:[U.status," ",U.comment?`— ${U.comment}`:""]})})()]}),n.jsx("textarea",{value:m,onChange:O=>o(O.target.value),style:{...Fr,height:52,resize:"vertical"},placeholder:"Add a comment…"})]}),n.jsxs("div",{style:{padding:"12px 14px",borderBottom:I.length>0?"1px solid #f0f0f0":"none"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Actions"}),I.length===0&&n.jsxs("div",{style:{fontSize:12,color:"#aaa",fontStyle:"italic",lineHeight:1.5},children:["No actions for ",n.jsx("strong",{children:t})," in ",n.jsx("strong",{children:P}),"."]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:I.map(O=>n.jsxs("button",{onClick:()=>E(O.action),disabled:y,style:{width:"100%",padding:"10px 14px",borderRadius:6,border:"none",background:O.action==="Close Process"?"#64748b":O.action==="Move to Study"?"#8e44ad":"#2563eb",color:"white",cursor:y?"not-allowed":"pointer",fontSize:13,fontWeight:600,opacity:y?.7:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsx("span",{children:y?"Applying…":O.action}),n.jsxs("span",{style:{fontSize:10,opacity:.7},children:["→ ",O.next]})]},O.action))}),c&&n.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,fontSize:12,color:"#991b1b",lineHeight:1.4},children:c}),b&&n.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,fontSize:12,color:"#166534"},children:b})]}),k.length>0&&n.jsxs("div",{style:{padding:"12px 14px"},children:[n.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Next States"}),k.map(O=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6,fontSize:11},children:[n.jsx("span",{style:{color:"#555",flex:1},children:O.action}),n.jsx("span",{style:{color:"#bbb"},children:"→"}),n.jsx("span",{style:cu(O.next),children:O.next})]},O.action))]})]})})}const Mr={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:16},Tl={display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:16};function d0({processForm:e,setProcessForm:t,organizations:l,managements:s,departments:r,branches:i,processTypes:a,processStatuses:d,cycles:u=[],users:f=[],userRoleMap:y={},formStatus:p,viewMode:c,onEdit:v,darkMode:b,notifCount:g,onToggleDark:S,onCountChange:h,onViewProfile:m,userRole:o,delegatedFunctions:x=[],delegatedOrgs:z=null,onRefreshProcess:R,onSubmit:P,onBack:k,onNavigate:C,onLogout:$,user:I}){const E=ee(),O=_=>t({...e,..._}),U=c?{background:"#f9f9f9"}:{},V=!c&&o==="Manager"&&Array.isArray(z),xe=V?l.filter(_=>(z||[]).includes(_.organization_name||_.name)):l,le=V&&(z||[]).length===1||!!I.custom_organization,L=fe(s,e.management).map(_=>({name:_.name,label:_.name1||_.name})),M=fe(r,e.department).map(_=>({name:_.name,label:_.department_name||_.name})),K=fe(i,e.branch).map(_=>({name:_.name,label:_.branch||_.name})),ne=fe(a,e.type).map(_=>({name:_.name,label:_.name1||_.name})),q=fe(d,e.status).map(_=>({name:_.name,label:_.name1||_.name})),me=fe(u,e.cycle).map(_=>({name:_.name,label:_.name1||_.name})),Ce=fr(f,y,"SB Employee",e.organization).map(_=>({name:_.name,label:_.full_name||_.name})),re=(_,Y)=>{const Z=[...e.cycle_logs||[]];Z[_]={...Z[_],...Y},O({cycle_logs:Z})},ze=()=>{O({cycle_logs:[...e.cycle_logs||[],{cycle:"",cycle_date:"",status:"Pass",actor:"",comment:""}]})},he=_=>{const Y=[...e.cycle_logs||[]];Y.splice(_,1),O({cycle_logs:Y})},H=(_,Y)=>{const Z=[...e.progress_indicators||[]];Z[_]={...Z[_],...Y},O({progress_indicators:Z})},J=()=>{O({progress_indicators:[...e.progress_indicators||[],{name1:"",type:"Nominal",unit:"",cycle:"",target:"",maximum:"",minimum:"",manager:"",order:"",actual_value:"",cycle_status:"",cycle_date:"",cycle_comment:"",status:""}]})},N=_=>{const Y=[...e.progress_indicators||[]];Y.splice(_,1),O({progress_indicators:Y})},oe=e.name?c?`${E.formTitle.viewProcess}${e.title||e.name}`:E.formTitle.editProcess:E.formTitle.newProcess,Wn=o!=="Manager"||e.actor===I.name||x.includes("update_process_status"),gt=e.name?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsx(c0,{processName:e.name,userRole:o||I.role||"Employee",onRefresh:R,canUpdateStatus:Wn}),n.jsx(Gi,{doctype:B.processes,docname:e.name,currentUserName:I.name}),n.jsx(Yi,{doctype:B.processes,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):void 0;return n.jsxs(Me,{title:oe,activePage:"processes",user:I,formStatus:p,buttonText:E.saveProcess,buttonColor:W.blue,viewMode:c,onEdit:v,darkMode:b,notifCount:g,onToggleDark:S,onCountChange:h,onViewProfile:m,rightPanel:gt,onSubmit:P,onBack:k,onNavigate:C,onLogout:$,children:[n.jsxs("div",{style:Mr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.number}),n.jsx("input",{style:{...A,background:"#f9f9f9"},value:e.number||"",readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[E.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:_=>O({organization:_}),organizations:xe,disabled:c||le}),V&&n.jsx("div",{style:{fontSize:11,color:"#888",marginTop:4},children:(z||[]).length===0?"You have no delegated organization for Processes.":`Restricted to your delegated organization${(z||[]).length>1?"s":""}: ${(z||[]).join(", ")}`})]})]}),n.jsxs("div",{style:Mr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.title}),n.jsx("input",{style:{...A,...U},value:e.title,disabled:c,onChange:_=>O({title:_.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.type}),n.jsx(ue,{value:e.type,onChange:_=>O({type:_}),items:ne,placeholder:E.field.selectType,disabled:c})]})]}),n.jsxs("div",{style:Tl,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.management}),n.jsx(ue,{value:e.management,onChange:_=>O({management:_}),items:L,placeholder:E.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.department}),n.jsx(ue,{value:e.department,onChange:_=>O({department:_}),items:M,placeholder:E.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.section}),n.jsx("input",{style:{...A,...U},value:e.section_field||"",disabled:c,onChange:_=>O({section_field:_.target.value})})]})]}),n.jsxs("div",{style:Mr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.branch}),n.jsx(ue,{value:e.branch,onChange:_=>O({branch:_}),items:K,placeholder:E.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[E.field.status," ",n.jsx("span",{style:{fontSize:11,color:"#9ca3af",fontWeight:400},children:"(auto-updated from cycle)"})]}),n.jsx(ue,{value:e.status,onChange:_=>O({status:_}),items:q,placeholder:E.field.selectStatus,disabled:c})]})]}),n.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:14},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#475569",marginBottom:10},children:"Classification"}),n.jsxs("div",{style:Tl,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.chainLocation}),n.jsxs("select",{style:{...A,...U},value:e.chain_location||"",disabled:c,onChange:_=>O({chain_location:_.target.value}),children:[n.jsx("option",{value:"",children:E.field.select}),n.jsx("option",{value:"Upstream",children:"Upstream"}),n.jsx("option",{value:"On-stream",children:"On-stream"}),n.jsx("option",{value:"Downstream",children:"Downstream"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.economyClass}),n.jsxs("select",{style:{...A,...U},value:e.economy_class||"",disabled:c,onChange:_=>O({economy_class:_.target.value}),children:[n.jsx("option",{value:"",children:E.field.select}),n.jsx("option",{value:"Expenses",children:E.field.expenses}),n.jsx("option",{value:"Capital",children:E.field.capital}),n.jsx("option",{value:"Earn",children:E.field.earn}),n.jsx("option",{value:"Pay/Loss",children:E.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.impactLevel}),n.jsxs("select",{style:{...A,...U},value:e.impact_level||"",disabled:c,onChange:_=>O({impact_level:_.target.value}),children:[n.jsx("option",{value:"",children:E.field.select}),n.jsx("option",{value:"High",children:E.field.high}),n.jsx("option",{value:"Normal",children:E.field.normal})]})]})]}),n.jsxs("div",{style:Tl,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.entityScope}),n.jsxs("select",{style:{...A,...U},value:e.entity_scope||"",disabled:c,onChange:_=>O({entity_scope:_.target.value}),children:[n.jsx("option",{value:"",children:E.field.select}),n.jsx("option",{value:"Upstream",children:E.field.upstream}),n.jsx("option",{value:"On-stream",children:E.field.onstream}),n.jsx("option",{value:"Downstream",children:E.field.downstream})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.hsesField}),n.jsx("input",{style:{...A,...U},value:e.hses_field||"",disabled:c,onChange:_=>O({hses_field:_.target.value}),placeholder:"Safety, Health, Environment…"})]}),n.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,paddingTop:22},children:n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[n.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:_=>O({product_relation:_.target.checked?1:0})})," ",E.field.productRelation]})})]})]}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:14},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:10},children:"KPI"}),n.jsxs("div",{style:Tl,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.kpiName}),n.jsx("input",{style:{...A,...U},value:e.kpi_name||"",disabled:c,onChange:_=>O({kpi_name:_.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.kpiType}),n.jsxs("select",{style:{...A,...U},value:e.kpi_type||"",disabled:c,onChange:_=>O({kpi_type:_.target.value}),children:[n.jsx("option",{value:"",children:E.field.select}),n.jsx("option",{value:"Human",children:"Human"}),n.jsx("option",{value:"Substantial",children:"Substantial"}),n.jsx("option",{value:"System",children:"System"}),n.jsx("option",{value:"Value",children:"Value"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.kpiMeasure}),n.jsx("input",{style:{...A,...U},value:e.kpi_measure||"",disabled:c,onChange:_=>O({kpi_measure:_.target.value}),placeholder:"Unit of measure"})]})]})]}),n.jsxs("div",{style:Tl,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.dateStart}),n.jsx(ye,{value:e.date_start,onChange:_=>O({date_start:_}),disabled:c,style:{...A,...U}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.dateEnd}),n.jsx(ye,{value:e.date_end,onChange:_=>O({date_end:_}),disabled:c,style:{...A,...U}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.cycleType}),n.jsxs("select",{style:{...A,...U},value:e.cycle_type||"",disabled:c,onChange:_=>O({cycle_type:_.target.value}),children:[n.jsx("option",{value:"",children:E.field.select}),n.jsx("option",{value:"Normal",children:"Normal"}),n.jsx("option",{value:"Long",children:"Long"})]})]})]}),e.cycle_type==="Long"&&n.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),n.jsxs("div",{style:Mr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 1"}),n.jsx(ye,{value:e.long_cycle_date_1||"",onChange:_=>O({long_cycle_date_1:_}),disabled:c,style:{...A,...U}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 2"}),n.jsx(ye,{value:e.long_cycle_date_2||"",onChange:_=>O({long_cycle_date_2:_}),disabled:c,style:{...A,...U}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 3"}),n.jsx(ye,{value:e.long_cycle_date_3||"",onChange:_=>O({long_cycle_date_3:_}),disabled:c,style:{...A,...U}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 4"}),n.jsx(ye,{value:e.long_cycle_date_4||"",onChange:_=>O({long_cycle_date_4:_}),disabled:c,style:{...A,...U}})]})]})]}),n.jsxs("div",{style:{marginTop:24,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[n.jsx("div",{style:{...T,margin:0,fontSize:15},children:"Progress Indicators"}),!c&&n.jsx("button",{type:"button",onClick:J,style:{padding:"8px 14px",border:"1px solid #3498db",background:"#3498db",color:"white",borderRadius:6,cursor:"pointer"},children:"Add row"})]}),n.jsx("div",{style:{overflowX:"auto",minWidth:0},children:n.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa"},children:[n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Order"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Name"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Type"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Unit"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Target"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Min"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Max"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Manager"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actual Value"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle Status"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle Date"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle Comment"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Status"}),!c&&n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actions"})]})}),n.jsxs("tbody",{children:[(e.progress_indicators||[]).length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:c?14:15,style:{padding:18,textAlign:"center",color:"#aaa"},children:"No progress indicators"})}),(e.progress_indicators||[]).map((_,Y)=>n.jsxs("tr",{style:{background:Y%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U,width:60},value:_.order??"",disabled:c,onChange:Z=>H(Y,{order:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U},value:_.name1,disabled:c,onChange:Z=>H(Y,{name1:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...A,...U},value:_.type,disabled:c,onChange:Z=>H(Y,{type:Z.target.value}),children:[n.jsx("option",{children:"Nominal"}),n.jsx("option",{children:"Ordinal"}),n.jsx("option",{children:"Interval"}),n.jsx("option",{children:"Ratio"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U,width:70},type:"text",value:_.unit??"",disabled:c,onChange:Z=>H(Y,{unit:Z.target.value}),placeholder:"e.g. °C, kg, %"})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U},value:_.cycle,disabled:c,onChange:Z=>H(Y,{cycle:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U,width:80},value:_.target,disabled:c,onChange:Z=>H(Y,{target:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U,width:80},value:_.minimum,disabled:c,onChange:Z=>H(Y,{minimum:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U,width:80},value:_.maximum,disabled:c,onChange:Z=>H(Y,{maximum:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U},value:_.manager,disabled:c,onChange:Z=>H(Y,{manager:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U,width:90},type:"number",value:_.actual_value??"",disabled:c,onChange:Z=>H(Y,{actual_value:parseFloat(Z.target.value)||""})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...A,...U},value:_.cycle_status??"",disabled:c,onChange:Z=>H(Y,{cycle_status:Z.target.value}),children:[n.jsx("option",{value:"",children:"--"}),n.jsx("option",{children:"Normal"}),n.jsx("option",{children:"Below Min"}),n.jsx("option",{children:"Above Max"}),n.jsx("option",{children:"At Risk"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx(ye,{value:_.cycle_date||"",onChange:Z=>H(Y,{cycle_date:Z}),disabled:c,style:{...A,...U,width:110}})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U},value:_.cycle_comment??"",disabled:c,onChange:Z=>H(Y,{cycle_comment:Z.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...A,...U},value:_.status??"",disabled:c,onChange:Z=>H(Y,{status:Z.target.value}),children:[n.jsx("option",{value:"",children:"--"}),n.jsx("option",{children:"Normal"}),n.jsx("option",{children:"Below Min"}),n.jsx("option",{children:"Above Max"}),n.jsx("option",{children:"At Risk"})]})}),!c&&n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("button",{type:"button",onClick:()=>N(Y),style:{padding:"6px 10px",border:"1px solid #e74c3c",background:"white",color:"#e74c3c",borderRadius:6,cursor:"pointer"},children:"Remove"})})]},Y))]})]})})]}),n.jsxs("div",{style:{marginTop:28,borderTop:"1px solid #e9ecef",paddingTop:20},children:[n.jsx("div",{style:{...T,fontSize:15,marginBottom:14},children:"Cycle & Assignment"}),n.jsxs("div",{style:Tl,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.cycle}),n.jsx(ue,{value:e.cycle||"",onChange:_=>O({cycle:_}),items:me,placeholder:E.field.select,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.actor}),n.jsxs("select",{style:{...A,...U},value:e.actor||"",disabled:c,onChange:_=>O({actor:_.target.value}),children:[n.jsx("option",{value:"",children:E.field.select}),Ce.map(_=>n.jsx("option",{value:_.name,children:_.label},_.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:E.field.costPerCycle}),n.jsx("input",{style:{...A,...U},type:"number",value:e.cost_per_cycle||"",disabled:c,onChange:_=>O({cost_per_cycle:parseFloat(_.target.value)||0}),placeholder:"0.00"})]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:E.field.escalationLevel}),n.jsx("input",{style:{...A,...U,maxWidth:120},type:"number",value:e.escalation_level||"",disabled:c,onChange:_=>O({escalation_level:parseInt(_.target.value)||0})})]})]}),n.jsxs("div",{style:{marginTop:28,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[n.jsx("div",{style:{...T,margin:0,fontSize:15},children:"Cycle History"}),!c&&n.jsx("button",{type:"button",onClick:ze,style:{padding:"8px 14px",border:"1px solid #3498db",background:"#3498db",color:"white",borderRadius:6,cursor:"pointer"},children:"Add row"})]}),n.jsx("div",{style:{overflowX:"auto",minWidth:0},children:n.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa"},children:[n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Cycle"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Date"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Status"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actor"}),n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Comment"}),!c&&n.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#555"},children:"Actions"})]})}),n.jsxs("tbody",{children:[(e.cycle_logs||[]).length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:c?5:6,style:{padding:18,textAlign:"center",color:"#aaa"},children:"No cycle history"})}),(e.cycle_logs||[]).map((_,Y)=>n.jsxs("tr",{style:{background:Y%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...A,...U},value:_.cycle||"",disabled:c,onChange:Z=>re(Y,{cycle:Z.target.value}),children:[n.jsx("option",{value:"",children:"-- Select --"}),me.map(Z=>n.jsx("option",{value:Z.name,children:Z.label},Z.name))]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx(ye,{value:_.cycle_date||"",onChange:Z=>re(Y,{cycle_date:Z}),disabled:c,style:{...A,...U,width:130}})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...A,...U},value:_.status,disabled:c,onChange:Z=>re(Y,{status:Z.target.value}),children:[n.jsx("option",{value:"Pass",children:"Pass"}),n.jsx("option",{value:"Fail",children:"Fail"}),n.jsx("option",{value:"Unknown",children:"Unknown"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...A,...U},value:_.actor||"",disabled:c,onChange:Z=>re(Y,{actor:Z.target.value}),children:[n.jsx("option",{value:"",children:"-- Select --"}),Ce.map(Z=>n.jsx("option",{value:Z.name,children:Z.label},Z.name))]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...A,...U},value:_.comment||"",disabled:c,onChange:Z=>re(Y,{comment:Z.target.value})})}),!c&&n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("button",{type:"button",onClick:()=>he(Y),style:{padding:"6px 10px",border:"1px solid #e74c3c",background:"white",color:"#e74c3c",borderRadius:6,cursor:"pointer"},children:"Remove"})})]},Y))]})]})})]}),n.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:16,marginTop:16},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#166534",marginBottom:8},children:E.field.auditorComment}),n.jsx("textarea",{style:{...A,height:80,resize:"vertical",...c?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:c,onChange:_=>O({auditor_comment:_.target.value}),placeholder:E.field.commentPlaceholder})]})]})}const u0={Admin:"#7c3aed",Auditor:"#d97706",Owner:"#0369a1",XAuditor:"#0f766e",Manager:"#2563eb",Employee:"#6b7280",Chairman:"#0f766e"};function p0({user:e,profileUser:t,darkMode:l,canModify:s,onBack:r,organizations:i=[],managements:a=[],departments:d=[],branches:u=[]}){const f=t||{},y=!!s&&e.role==="Admin",[p,c]=j.useState({first_name:f.first_name||"",middle_name:f.middle_name||"",last_name:f.last_name||"",mobile_no:f.mobile_no||"",custom_organization:f.custom_organization||"",custom_management:f.custom_management||"",custom_department:f.custom_department||"",custom_branch:f.custom_branch||"",custom_number:f.custom_number||"",custom_category:f.custom_category||""}),[v,b]=j.useState(""),[g,S]=j.useState(!1),[h,m]=j.useState({new:"",confirm:""}),[o,x]=j.useState(""),z=f.email||f.name||"",R=[p.first_name,p.middle_name,p.last_name].filter(Boolean).join(" ")||f.full_name||"",P=f.username||f.name||"",k=p.custom_category||"",C=f.enabled===0?"Inactive":"Active",$=u0[e.role]||"#6b7280",I=l,E=I?"#0f172a":"#f0f2f5",O=I?"#1e293b":"white",U=I?"#2d3748":"#e5e7eb",V=I?"#e2e8f0":"#1a2332",xe=I?"#94a3b8":"#6b7280",le=I?"#374151":"white",L=I?"#2d3748":"#f9fafb",M={width:"100%",padding:"9px 12px",borderRadius:8,border:`1px solid ${U}`,fontSize:13,background:le,color:V,fontFamily:"inherit",outline:"none"},K={...M,background:L,color:xe},ne={...M,cursor:"pointer"},q={fontSize:12,fontWeight:600,color:xe,marginBottom:5,display:"block"},me={display:"grid",gridTemplateColumns:"1fr 1fr",gap:14},Ce={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:14},re=async()=>{if(s){b("saving");try{await Ti("User",f.name,{first_name:p.first_name,middle_name:p.middle_name,last_name:p.last_name,mobile_no:p.mobile_no,custom_organization:p.custom_organization,custom_management:p.custom_management,custom_department:p.custom_department,custom_branch:p.custom_branch,custom_number:p.custom_number,custom_category:p.custom_category}),b("saved"),setTimeout(()=>b(""),2e3)}catch{b("error"),setTimeout(()=>b(""),3e3)}}},ze=async()=>{if(!h.new){x("Enter a new password");return}if(h.new!==h.confirm){x("Passwords do not match");return}x("saving");try{await Bf(f.name,h.new),x("done"),m({new:"",confirm:""}),setTimeout(()=>{x(""),S(!1)},2e3)}catch{x("error")}},he=({title:H,icon:J,children:N})=>n.jsxs("div",{style:{background:O,borderRadius:12,padding:22,border:`1px solid ${U}`,boxShadow:`0 1px 4px rgba(0,0,0,${I?.3:.06})`},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:18,paddingBottom:14,borderBottom:`1px solid ${U}`},children:[J,n.jsx("span",{style:{fontSize:14,fontWeight:700,color:V},children:H})]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:14},children:N})]});return n.jsxs("div",{style:{background:E,minHeight:"100%",padding:"0 0 32px"},children:[n.jsxs("div",{style:{background:O,borderBottom:`1px solid ${U}`,padding:"12px 28px",display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[n.jsxs("button",{onClick:r,style:{display:"flex",alignItems:"center",gap:7,background:"none",border:"none",cursor:"pointer",fontSize:15,fontWeight:700,color:V,fontFamily:"inherit"},children:[n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polyline",{points:"15,18 9,12 15,6"})}),"User Profile"]}),s&&n.jsxs("button",{onClick:re,style:{display:"flex",alignItems:"center",gap:8,background:v==="saved"?"#16a34a":v==="error"?"#dc2626":"#16a34a",color:"white",border:"none",borderRadius:8,padding:"9px 22px",fontSize:13,fontWeight:700,cursor:"pointer",fontFamily:"inherit"},children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),n.jsx("polyline",{points:"17,21 17,13 7,13 7,21"}),n.jsx("polyline",{points:"7,3 7,8 15,8"})]}),v==="saving"?"Saving…":v==="saved"?"Saved!":v==="error"?"Error":"Save Changes"]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"280px 1fr",gap:22,padding:"0 28px"},children:[n.jsxs("div",{style:{borderRadius:14,overflow:"hidden",boxShadow:"0 4px 20px rgba(0,0,0,0.12)",alignSelf:"start"},children:[n.jsxs("div",{style:{background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",padding:"32px 20px 28px",display:"flex",flexDirection:"column",alignItems:"center",gap:6},children:[n.jsx("div",{style:{width:78,height:78,borderRadius:"50%",background:"rgba(255,255,255,0.22)",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:4,border:"3px solid rgba(255,255,255,0.3)"},children:n.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"rgba(255,255,255,0.9)",children:[n.jsx("circle",{cx:"12",cy:"8",r:"4"}),n.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]})}),n.jsx("div",{style:{fontSize:17,fontWeight:700,color:"white",textAlign:"center",lineHeight:1.3},children:R||z}),n.jsx("div",{style:{fontSize:12,color:"rgba(255,255,255,0.75)",textAlign:"center"},children:z})]}),n.jsx("div",{style:{background:O},children:[{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),n.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),n.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),n.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),label:"Username",value:P},{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),label:"Role Profile",value:k||"—"},{icon:n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:C==="Active"?"#16a34a":"#dc2626",strokeWidth:"2",strokeLinecap:"round",children:n.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),label:"Status",value:C,valueColor:C==="Active"?"#16a34a":"#dc2626"},{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),n.jsx("path",{d:"m2 7 10 7 10-7"})]}),label:"Email",value:z},{icon:n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:$,strokeWidth:"2",strokeLinecap:"round",children:n.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 13a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.6 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})}),label:"Phone",value:p.mobile_no||"—"}].map(({icon:H,label:J,value:N,valueColor:oe})=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 16px",borderBottom:`1px solid ${U}`},children:[n.jsx("div",{style:{flexShrink:0,width:18,display:"flex",justifyContent:"center"},children:H}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:11,color:xe,marginBottom:1},children:J}),n.jsx("div",{style:{fontSize:13,fontWeight:600,color:oe||V,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N})]})]},J))})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:18},children:[n.jsxs(he,{title:"Basic Information",icon:n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("circle",{cx:"12",cy:"8",r:"4"}),n.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]}),children:[n.jsxs("div",{style:me,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Email ",n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Read-only)"})]}),n.jsxs("div",{style:{position:"relative"},children:[n.jsx("div",{style:{position:"absolute",left:11,top:"50%",transform:"translateY(-50%)"},children:n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#94a3b8",strokeWidth:"2",children:[n.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),n.jsx("path",{d:"m2 7 10 7 10-7"})]})}),n.jsx("input",{style:{...K,paddingLeft:32},value:z,readOnly:!0})]})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Full Name ",n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Auto-generated)"})]}),n.jsx("input",{style:K,value:R,readOnly:!0})]})]}),n.jsxs("div",{style:Ce,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["First Name ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{style:s?M:K,value:p.first_name,readOnly:!s,onChange:H=>c(J=>({...J,first_name:H.target.value})),placeholder:"First name"})]}),n.jsxs("div",{children:[n.jsx("label",{style:q,children:"Middle Name"}),n.jsx("input",{style:s?M:K,value:p.middle_name,readOnly:!s,onChange:H=>c(J=>({...J,middle_name:H.target.value})),placeholder:"Middle name"})]}),n.jsxs("div",{children:[n.jsx("label",{style:q,children:"Last Name"}),n.jsx("input",{style:s?M:K,value:p.last_name,readOnly:!s,onChange:H=>c(J=>({...J,last_name:H.target.value})),placeholder:"Last name"})]})]}),n.jsxs("div",{style:me,children:[n.jsxs("div",{children:[n.jsx("label",{style:q,children:"Phone Number"}),n.jsx("input",{style:s?M:K,value:p.mobile_no,readOnly:!s,onChange:H=>c(J=>({...J,mobile_no:H.target.value})),placeholder:"Phone number"})]}),n.jsxs("div",{children:[n.jsx("label",{style:q,children:"User ID No"}),n.jsxs("div",{style:{position:"relative"},children:[n.jsx("input",{style:{...K,paddingRight:44},value:p.custom_number||f.name||"",readOnly:!0}),n.jsx("div",{style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",background:"#ef4444",borderRadius:5,padding:"3px 7px",cursor:"default",display:"flex",alignItems:"center"},children:n.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"white",children:[n.jsx("circle",{cx:"5",cy:"12",r:"2"}),n.jsx("circle",{cx:"12",cy:"12",r:"2"}),n.jsx("circle",{cx:"19",cy:"12",r:"2"})]})})]})]})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Category ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:ne,value:p.custom_category,onChange:H=>c(J=>({...J,custom_category:H.target.value})),children:[n.jsx("option",{value:"",children:"Select category"}),["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"].map(H=>n.jsx("option",{value:H,children:H},H))]}):n.jsx("input",{style:K,value:k||"—",readOnly:!0})]})]}),n.jsxs(he,{title:"Organization Information",icon:n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#8b5cf6",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),n.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),children:[n.jsxs("div",{style:me,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Organization ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:ne,value:p.custom_organization,onChange:H=>c(J=>({...J,custom_organization:H.target.value})),children:[n.jsx("option",{value:"",children:"Select organization"}),fe(i,p.custom_organization).map(H=>n.jsx("option",{value:H.name,children:H.organization_name||H.name},H.name))]}):n.jsx("input",{style:K,value:p.custom_organization||"—",readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Management ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:ne,value:p.custom_management,onChange:H=>c(J=>({...J,custom_management:H.target.value})),children:[n.jsx("option",{value:"",children:"Select management"}),fe(a,p.custom_management).map(H=>n.jsx("option",{value:H.name,children:H.name1||H.name},H.name))]}):n.jsx("input",{style:K,value:p.custom_management||"—",readOnly:!0})]})]}),n.jsxs("div",{style:me,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Department ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:ne,value:p.custom_department,onChange:H=>c(J=>({...J,custom_department:H.target.value})),children:[n.jsx("option",{value:"",children:"Select department"}),fe(d,p.custom_department).map(H=>n.jsx("option",{value:H.name,children:H.department_name||H.name},H.name))]}):n.jsx("input",{style:K,value:p.custom_department||"—",readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Branch ",!y&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),y?n.jsxs("select",{style:ne,value:p.custom_branch,onChange:H=>c(J=>({...J,custom_branch:H.target.value})),children:[n.jsx("option",{value:"",children:"Select branch"}),fe(u,p.custom_branch).map(H=>n.jsx("option",{value:H.name,children:H.branch||H.name},H.name))]}):n.jsx("input",{style:K,value:p.custom_branch||"—",readOnly:!0})]})]})]}),n.jsxs("div",{style:{background:O,borderRadius:12,padding:22,border:`1px solid ${U}`,boxShadow:`0 1px 4px rgba(0,0,0,${I?.3:.06})`},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),n.jsx("span",{style:{fontSize:14,fontWeight:700,color:V},children:"Change Password"})]}),s&&n.jsx("button",{onClick:()=>{S(H=>!H),x("")},style:{fontSize:13,color:"#3b82f6",background:"none",border:"none",cursor:"pointer",fontWeight:600,fontFamily:"inherit"},children:g?"Cancel":"Change Password"})]}),g&&n.jsxs("div",{style:{marginTop:18,display:"flex",flexDirection:"column",gap:12},children:[n.jsxs("div",{style:Ce,children:[n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["New Password ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{type:"password",style:M,value:h.new,onChange:H=>m(J=>({...J,new:H.target.value})),placeholder:"New password"})]}),n.jsxs("div",{children:[n.jsxs("label",{style:q,children:["Confirm Password ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{type:"password",style:M,value:h.confirm,onChange:H=>m(J=>({...J,confirm:H.target.value})),placeholder:"Confirm password"})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:ze,style:{width:"100%",padding:"9px 0",borderRadius:8,border:"none",background:"#2563eb",color:"white",fontWeight:700,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:o==="saving"?"Saving…":"Update Password"})})]}),o&&o!=="saving"&&n.jsx("div",{style:{fontSize:13,color:o==="done"?"#16a34a":"#dc2626",fontWeight:500},children:o==="done"?"Password updated successfully":o==="error"?"Failed to update password":o})]})]})]})]})]})}function Ae({label:e,val:t,color:l}){return n.jsxs("div",{style:{background:"white",borderRadius:8,padding:"8px 16px",flex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderTop:`3px solid ${l}`,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[n.jsx("div",{style:{fontSize:18,fontWeight:700,color:l},children:t}),n.jsx("div",{style:{fontSize:12,color:"#999"},children:e})]})}const Ff={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151",boxSizing:"border-box"},f0={...Ff,cursor:"pointer"};function ct({filters:e,defaultOpen:t=!1}){const[l,s]=j.useState(t);return n.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[n.jsxs("div",{onClick:()=>s(r=>!r),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:l?n.jsx("polyline",{points:"18,15 12,9 6,15"}):n.jsx("polyline",{points:"6,9 12,15 18,9"})}),n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),l&&n.jsx("div",{style:{padding:"18px 20px"},children:n.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(${Math.min(e.length,4)}, 1fr)`,gap:14},children:e.map((r,i)=>n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:r.label}),r.type==="search"?n.jsx("input",{style:Ff,placeholder:r.placeholder,value:r.value,onChange:a=>r.onChange(a.target.value)}):n.jsx("select",{style:f0,value:r.value,onChange:a=>r.onChange(a.target.value),children:r.options.map(a=>n.jsx("option",{value:a.value,children:a.label},a.value))})]},i))})})]})}function h0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function g0({organizations:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),[y,p]=j.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=j.useMemo(()=>e.filter(h=>{const m=[h.organization_name,h.city].filter(Boolean).join(" ").toLowerCase();return!(a&&!m.includes(a.toLowerCase())||u!=="all"&&h.type!==u||y!=="all"&&(h.is_active?"Active":"Inactive")!==y)}),[e,a,u,y]),[b,g]=j.useState(1);j.useEffect(()=>{g(1)},[a,u,y]);const S=v.slice((b-1)*se,b*se);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(Ae,{label:"Total",val:v.length,color:"#1a2332"}),n.jsx(Ae,{label:"Active",val:v.filter(h=>h.is_active).length,color:W.green}),n.jsx(Ae,{label:"Government",val:v.filter(h=>h.type==="Government").length,color:W.blue}),n.jsx(Ae,{label:"Private",val:v.filter(h=>h.type==="Private").length,color:W.orange})]}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Name or city…"},{type:"select",label:i.col.type,value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Government",label:"Government"},{value:"Private",label:"Private"}]},{type:"select",label:"Status",value:y,onChange:p,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:c,children:i.col.name}),n.jsx("th",{style:c,children:i.col.type}),n.jsx("th",{style:c,children:i.col.city}),n.jsx("th",{style:c,children:i.field.creationDate}),n.jsx("th",{style:c,children:i.col.status}),n.jsx("th",{style:c,children:i.col.actions})]})}),n.jsx("tbody",{children:v.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):S.map((h,m)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(h),style:{borderTop:"1px solid #f0f0f0",background:m%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:h.organization_name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:h.type||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:h.city||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:h0(h.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:Ln(h.is_active?i.field.statusActive:i.field.statusInactive,h.is_active?W.green:W.gray)}),n.jsx("td",{style:{padding:"8px 14px"},onClick:o=>o.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(h),onEdit:t&&s?()=>s(h):void 0,onDelete:t&&r?()=>r(h.name):void 0})})]},h.name))})]})}),n.jsx(Fe,{page:b,total:v.length,onPageChange:g})]})}const Zt=e=>({background:e?"#f9f9f9":void 0});function x0({orgForm:e,setOrgForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=e.name?s&&e.organization_name||g.formTitle.editOrg:g.formTitle.newOrg;return n.jsxs(Me,{title:S,activePage:"organizations",user:b,formStatus:l,buttonText:g.saveOrg,buttonColor:W.accent,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.orgName," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{type:"text",style:{...A,...Zt(s||!!e.name)},value:e.organization_name,disabled:s||!!e.name,required:!0,onChange:h=>t({...e,organization_name:h.target.value})})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.orgAcronym," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{type:"text",style:{...A,...Zt(s||!!e.name)},value:e.acronym||"",disabled:s||!!e.name,required:!0,onChange:h=>t({...e,acronym:h.target.value})})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.organizationType}),n.jsxs("select",{style:{...A,...Zt(s)},value:e.type,disabled:s,onChange:h=>t({...e,type:h.target.value}),children:[n.jsx("option",{children:"Government"}),n.jsx("option",{children:"Private"}),n.jsx("option",{children:"Non-Profit"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.orgCity}),n.jsx("input",{type:"text",style:{...A,...Zt(s)},value:e.city,disabled:s,onChange:h=>t({...e,city:h.target.value})})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.contactEmail}),n.jsx("input",{type:"email",style:{...A,...Zt(s)},value:e.contact_email,disabled:s,onChange:h=>t({...e,contact_email:h.target.value})})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:h=>t({...e,creation_date:h}),disabled:s,style:{...A,...Zt(s)}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...Zt(s)},value:e.is_active?"Active":"Inactive",disabled:s,onChange:h=>t({...e,is_active:h.target.value==="Active"?1:0}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.incidentTriageWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...A,...Zt(s)},value:e.incident_triage_window_days??3,disabled:s,onChange:h=>t({...e,incident_triage_window_days:parseInt(h.target.value)||3})}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:"Days after creation before an untriaged Incident is flagged overdue"})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.incidentResolutionWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...A,...Zt(s)},value:e.incident_resolution_window_days??5,disabled:s,onChange:h=>t({...e,incident_resolution_window_days:parseInt(h.target.value)||5})}),n.jsx("span",{style:{fontSize:11,color:"#888"},children:"Days without an update before an in-progress Incident is flagged overdue"})]})]})]})}function m0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function y0({managements:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.blue})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:m0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function v0({form:e,setForm:t,organizations:l,formStatus:s,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:b,user:g}){const S=ee(),h=x=>t(z=>({...z,...x})),m=r?{background:"#f9f9f9"}:{},o=e.name?r?`${S.formTitle.editMgmt}: ${e.name1||e.name}`:S.formTitle.editMgmt:S.formTitle.newMgmt;return n.jsxs(Me,{title:o,activePage:"managements",user:g,formStatus:s,buttonText:S.saveMgmt,buttonColor:W.blue,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:b,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[S.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:x=>h({organization:x}),organizations:l,disabled:r||!!g.custom_organization})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[S.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...m},value:e.name1,disabled:r||!!e.name,onChange:x=>h({name1:x.target.value}),placeholder:"Management name",required:!0})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:x=>h({creation_date:x}),disabled:r,style:{...A,...m}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.status}),n.jsxs("select",{style:{...A,...m},value:e.status||"Active",disabled:r,onChange:x=>h({status:x.target.value}),children:[n.jsx("option",{value:"Active",children:S.field.statusActive}),n.jsx("option",{value:"Inactive",children:S.field.statusInactive})]})]})]})]})}function j0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function b0({departments:e,managements:t,canModify:l,onView:s,onEdit:r,onDelete:i}){const a=ee(),[d,u]=j.useState(""),[f,y]=j.useState(""),[p,c]=j.useState("all"),v=o=>{var x;return((x=t.find(z=>z.name===o))==null?void 0:x.name1)||o||"—"},b={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=j.useMemo(()=>e.filter(o=>{const x=(o.department_name||o.name||"").toLowerCase();return!(d&&!x.includes(d.toLowerCase())||f&&o.custom_management!==f||p!=="all"&&(o.custom_status||"Active")!==p)}),[e,d,f,p]),[S,h]=j.useState(1);j.useEffect(()=>{h(1)},[d,f,p]);const m=g.slice((S-1)*se,S*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:g.length,color:W.teal})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:d,onChange:u,placeholder:"Search by name…"},{type:"select",label:a.col.management,value:f,onChange:y,options:[{value:"",label:"All Managements"},...t.map(o=>({value:o.name,label:o.name1||o.name}))]},{type:"select",label:"Status",value:p,onChange:c,options:[{value:"all",label:"All"},{value:"Active",label:a.field.statusActive},{value:"Inactive",label:a.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:b,children:a.col.name}),n.jsx("th",{style:b,children:a.col.management}),n.jsx("th",{style:b,children:a.field.creationDate}),n.jsx("th",{style:b,children:a.field.status}),n.jsx("th",{style:b,children:a.col.actions})]})}),n.jsx("tbody",{children:g.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):m.map((o,x)=>n.jsxs("tr",{onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.department_name||o.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:v(o.custom_management)}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:j0(o.custom_creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:o.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.custom_status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:z=>z.stopPropagation(),children:n.jsx(Je,{onView:()=>s==null?void 0:s(o),onEdit:l&&r?()=>r(o):void 0,onDelete:l&&i?()=>i(o.name):void 0})})]},o.name))})]})}),n.jsx(Fe,{page:S,total:g.length,onPageChange:h})]})}const S0={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20};function w0({form:e,setForm:t,organizations:l,managements:s,formStatus:r,viewMode:i,onEdit:a,darkMode:d,notifCount:u,onToggleDark:f,onCountChange:y,onViewProfile:p,onSubmit:c,onBack:v,onNavigate:b,onLogout:g,user:S}){const h=ee(),m=R=>t(P=>({...P,...R})),o=i?{background:"#f9f9f9"}:{},x=e.name?i?`${h.formTitle.editDept}: ${e.department_name||e.name}`:h.formTitle.editDept:h.formTitle.newDept,z=fe(s,e.custom_management).map(R=>({name:R.name,label:R.name1||R.name}));return n.jsxs(Me,{title:x,activePage:"departments",user:S,formStatus:r,buttonText:h.saveDept,buttonColor:W.teal,viewMode:i,onEdit:a,darkMode:d,notifCount:u,onToggleDark:f,onCountChange:y,onViewProfile:p,onSubmit:c,onBack:v,onNavigate:b,onLogout:g,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.custom_organization,onChange:R=>m({custom_organization:R}),organizations:l,disabled:i||!!S.custom_organization})]}),n.jsxs("div",{style:S0,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.department," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...o},value:e.department_name,disabled:i||!!e.name,onChange:R=>m({department_name:R.target.value}),placeholder:"Department name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.management}),n.jsx(ue,{value:e.custom_management,onChange:R=>m({custom_management:R}),items:z,placeholder:h.field.select,disabled:i})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(ye,{value:e.custom_creation_date||"",onChange:R=>m({custom_creation_date:R}),disabled:i,style:{...A,...o}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...A,...o},value:e.custom_status||"Active",disabled:i,onChange:R=>m({custom_status:R.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})]})}function k0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function _0({branches:e,managements:t,departments:l,canModify:s,onView:r,onEdit:i,onDelete:a}){const d=ee(),[u,f]=j.useState(""),[y,p]=j.useState(""),[c,v]=j.useState(""),[b,g]=j.useState("all"),S=P=>{var k;return((k=t.find(C=>C.name===P))==null?void 0:k.name1)||P||"—"},h=P=>{var k;return((k=l.find(C=>C.name===P))==null?void 0:k.department_name)||P||"—"},m={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},o=j.useMemo(()=>e.filter(P=>{const k=(P.branch||P.name||"").toLowerCase();return!(u&&!k.includes(u.toLowerCase())||y&&P.management!==y||c&&P.department!==c||b!=="all"&&(P.custom_status||"Active")!==b)}),[e,u,y,c,b]),[x,z]=j.useState(1);j.useEffect(()=>{z(1)},[u,y,c,b]);const R=o.slice((x-1)*se,x*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:o.length,color:W.purple})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:u,onChange:f,placeholder:"Search by name…"},{type:"select",label:d.col.management,value:y,onChange:p,options:[{value:"",label:"All Managements"},...t.map(P=>({value:P.name,label:P.name1||P.name}))]},{type:"select",label:d.col.department,value:c,onChange:v,options:[{value:"",label:"All Departments"},...l.map(P=>({value:P.name,label:P.department_name||P.name}))]},{type:"select",label:"Status",value:b,onChange:g,options:[{value:"all",label:"All"},{value:"Active",label:d.field.statusActive},{value:"Inactive",label:d.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:m,children:d.col.branch}),n.jsx("th",{style:m,children:d.col.management}),n.jsx("th",{style:m,children:d.col.department}),n.jsx("th",{style:m,children:d.field.creationDate}),n.jsx("th",{style:m,children:d.field.status}),n.jsx("th",{style:m,children:d.col.actions})]})}),n.jsx("tbody",{children:o.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:d.noData})}):R.map((P,k)=>n.jsxs("tr",{onClick:()=>r==null?void 0:r(P),style:{borderTop:"1px solid #f0f0f0",background:k%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:P.branch||P.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:S(P.management)}),n.jsx("td",{style:{padding:"10px 14px"},children:h(P.department)}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:k0(P.custom_creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:P.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:P.custom_status==="Inactive"?d.field.statusInactive:d.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:C=>C.stopPropagation(),children:n.jsx(Je,{onView:()=>r==null?void 0:r(P),onEdit:s&&i?()=>i(P):void 0,onDelete:s&&a?()=>a(P.name):void 0})})]},P.name))})]})}),n.jsx(Fe,{page:x,total:o.length,onPageChange:z})]})}const C0={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20};function z0({form:e,setForm:t,organizations:l,managements:s,departments:r,formStatus:i,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:b,onNavigate:g,onLogout:S,user:h}){const m=ee(),o=k=>t(C=>({...C,...k})),x=a?{background:"#f9f9f9"}:{},z=e.name?a?`${m.formTitle.editBranch}: ${e.branch||e.name}`:m.formTitle.editBranch:m.formTitle.newBranch,R=fe(s,e.management).map(k=>({name:k.name,label:k.name1||k.name})),P=fe(r,e.department).map(k=>({name:k.name,label:k.department_name||k.name}));return n.jsxs(Me,{title:z,activePage:"branches",user:h,formStatus:i,buttonText:m.saveBranch,buttonColor:W.purple,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:b,onNavigate:g,onLogout:S,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[m.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:k=>o({organization:k}),organizations:l,disabled:a||!!h.custom_organization})]}),n.jsxs("div",{style:C0,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[m.field.branch," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...x},value:e.branch,disabled:a||!!e.name,onChange:k=>o({branch:k.target.value}),placeholder:"Branch name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:m.field.management}),n.jsx(ue,{value:e.management,onChange:k=>o({management:k}),items:R,placeholder:m.field.select,disabled:a})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:m.field.department}),n.jsx(ue,{value:e.department,onChange:k=>o({department:k}),items:P,placeholder:m.field.select,disabled:a})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:m.field.creationDate}),n.jsx(ye,{value:e.custom_creation_date||"",onChange:k=>o({custom_creation_date:k}),disabled:a,style:{...A,...x}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:m.field.status}),n.jsxs("select",{style:{...A,...x},value:e.custom_status||"Active",disabled:a,onChange:k=>o({custom_status:k.target.value}),children:[n.jsx("option",{value:"Active",children:m.field.statusActive}),n.jsx("option",{value:"Inactive",children:m.field.statusInactive})]})]})]})]})}function T0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function P0({incidentTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.red})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:T0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function I0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Incident Type: ${e.name1||e.name}`:"Edit Incident Type":"New Incident Type";return n.jsxs(Me,{title:m,activePage:"incident-types",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.red,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Incident type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function E0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function A0({ideaTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.teal})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:E0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function R0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Idea Type: ${e.name1||e.name}`:"Edit Idea Type":"New Idea Type";return n.jsxs(Me,{title:m,activePage:"idea-types",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.teal,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Idea type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function L0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function O0({orderTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.purple})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:L0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function D0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Order Type: ${e.name1||e.name}`:"Edit Order Type":"New Order Type";return n.jsxs(Me,{title:m,activePage:"order-types",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.purple,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Order type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function N0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function W0({processTypes:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.blue})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:4,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:N0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function B0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Process Type: ${e.name1||e.name}`:"Edit Process Type":"New Process Type";return n.jsxs(Me,{title:m,activePage:"process-types",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.blue,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Process type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function $0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function U0({incidentStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.red})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:$0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function F0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Incident Status: ${e.name1||e.name}`:"Edit Incident Status":"New Incident Status";return n.jsxs(Me,{title:m,activePage:"incident-statuses",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.red,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Incident status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>S({notify_manager:o.target.checked?1:0}),style:ds}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function M0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function H0({ideaStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.teal})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:M0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function K0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Idea Status: ${e.name1||e.name}`:"Edit Idea Status":"New Idea Status";return n.jsxs(Me,{title:m,activePage:"idea-statuses",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.teal,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Idea status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>S({notify_manager:o.target.checked?1:0}),style:ds}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function Q0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function G0({orderStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.purple})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:Q0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function Y0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Order Status: ${e.name1||e.name}`:"Edit Order Status":"New Order Status";return n.jsxs(Me,{title:m,activePage:"order-statuses",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.purple,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Order status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>S({notify_manager:o.target.checked?1:0}),style:ds}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}function X0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function q0({processStatuses:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState("all"),y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},p=j.useMemo(()=>e.filter(g=>{const S=(g.name1||g.name||"").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u!=="all"&&(g.status||"Active")!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total",val:p.length,color:W.blue})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:f,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:y,children:i.col.name}),n.jsx("th",{style:y,children:i.field.notifyManager}),n.jsx("th",{style:y,children:i.field.creationDate}),n.jsx("th",{style:y,children:i.field.status}),n.jsx("th",{style:y,children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.name1||g.name||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:X0(g.creation_date)}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{color:g.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:g.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}function J0({form:e,setForm:t,formStatus:l,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,user:b}){const g=ee(),S=o=>t(x=>({...x,...o})),h=s?{background:"#f9f9f9"}:{},m=e.name?s?`Process Status: ${e.name1||e.name}`:"Edit Process Status":"New Process Status";return n.jsxs(Me,{title:m,activePage:"process-statuses",user:b,formStatus:l,buttonText:g.saveName,buttonColor:W.blue,viewMode:s,onEdit:r,darkMode:i,notifCount:a,onToggleDark:d,onCountChange:u,onViewProfile:f,onSubmit:y,onBack:p,onNavigate:c,onLogout:v,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[g.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...h},value:e.name1,disabled:s||!!e.name,onChange:o=>S({name1:o.target.value}),placeholder:"Process status name",required:!0})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:8},children:[n.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:s,onChange:o=>S({notify_manager:o.target.checked?1:0}),style:ds}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:s?"default":"pointer"},children:g.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.creationDate}),n.jsx(ye,{value:e.creation_date||"",onChange:o=>S({creation_date:o}),disabled:s,style:{...A,...h}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:g.field.status}),n.jsxs("select",{style:{...A,...h},value:e.status||"Active",disabled:s,onChange:o=>S({status:o.target.value}),children:[n.jsx("option",{value:"Active",children:g.field.statusActive}),n.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})}const Z0={Admin:"#7c3aed",Chairman:"#0f766e",Auditor:"#d97706","X-Auditor":"#8b5cf6",Manager:"#2563eb",Employee:"#6b7280"};function V0(e){if(!e)return"—";const t=new Date(e);return`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function e1({users:e,canModify:t,onView:l,onEdit:s,onDisable:r}){const i=ee(),[a,d]=j.useState(!1),[u,f]=j.useState(""),[y,p]=j.useState(""),[c,v]=j.useState(""),[b,g]=j.useState("active"),[S,h]=j.useState(1),[m,o]=j.useState(null),[x,z]=j.useState(""),[R,P]=j.useState("idle"),[k,C]=j.useState(null),$=async()=>{if(!(!m||!x.trim())){P("loading");try{await Bf(m.name,x.trim()),P("success"),setTimeout(()=>{o(null),z(""),P("idle")},1200)}catch{P("error")}}},I=async L=>{if(window.confirm(i.users.disableConfirm)){C(L);try{await(r==null?void 0:r(L))}finally{C(null)}}},E=e.filter(L=>{if(b==="active"&&(L.enabled===0||L.enabled==="0")||b==="inactive"&&L.enabled!==0&&L.enabled!=="0")return!1;const M=L.custom_category||"";if(c&&M!==c)return!1;const K=L.custom_organization||"";if(y&&!K.toLowerCase().includes(y.toLowerCase()))return!1;if(u){const ne=u.toLowerCase();if(![L.full_name,L.email,L.name,L.username,L.mobile_no].join(" ").toLowerCase().includes(ne))return!1}return!0}),O=[...new Set(e.map(L=>L.custom_organization).filter(Boolean))],U=["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"];j.useEffect(()=>{h(1)},[u,y,c,b]);const V=E.slice((S-1)*se,S*se),xe={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151"},le={...xe,cursor:"pointer"};return n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,flex:1},children:[n.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:16},children:["Total: ",E.length," users"]}),n.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[n.jsxs("div",{onClick:()=>d(L=>!L),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:a?n.jsx("polyline",{points:"18,15 12,9 6,15"}):n.jsx("polyline",{points:"6,9 12,15 18,9"})}),n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),a&&n.jsx("div",{style:{padding:"18px 20px",display:"flex",flexDirection:"column",gap:14},children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:14},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Search"}),n.jsx("input",{style:xe,placeholder:"Name, email, username…",value:u,onChange:L=>f(L.target.value)})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Organization"}),n.jsxs("select",{style:le,value:y,onChange:L=>p(L.target.value),children:[n.jsx("option",{value:"",children:"All Organizations"}),O.map(L=>n.jsx("option",{value:L,children:L},L))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Category"}),n.jsxs("select",{style:le,value:c,onChange:L=>v(L.target.value),children:[n.jsx("option",{value:"",children:"All Categories"}),U.map(L=>n.jsx("option",{value:L,children:L},L))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Status"}),n.jsxs("select",{style:le,value:b,onChange:L=>g(L.target.value),children:[n.jsx("option",{value:"all",children:"All"}),n.jsx("option",{value:"active",children:"Active"}),n.jsx("option",{value:"inactive",children:"Inactive"})]})]})]})})]}),n.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa",borderBottom:"2px solid #f0f0f0"},children:[{label:"Category",w:100},{label:"Number",w:80},{label:"Full Name",w:140},{label:"Username",w:120},{label:"Email Address",w:180},{label:"Phone Number",w:120},{label:"Organization",w:130},{label:"Management",w:120},{label:"Department",w:120},{label:"Branch",w:100},{label:"Since",w:90},{label:"Status",w:80},{label:"Tools",w:200}].map(({label:L,w:M})=>n.jsx("th",{style:{padding:"11px 14px",textAlign:"left",color:"#6b7280",fontSize:11,fontWeight:700,whiteSpace:"nowrap",minWidth:M,letterSpacing:.3,textTransform:"uppercase"},children:L},L))})}),n.jsx("tbody",{children:E.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:13,style:{padding:"48px 20px",textAlign:"center",color:"#aaa",fontSize:14},children:"No users found"})}):V.map((L,M)=>{const K=L.custom_category||"",ne=Z0[K]||"#6b7280";return n.jsxs("tr",{onClick:()=>l==null?void 0:l(L),style:{borderBottom:"1px solid #f3f4f6",background:M%2===0?"white":"#fafafa",transition:"background 0.1s",cursor:"pointer"},onMouseEnter:q=>q.currentTarget.style.background="#f0f7ff",onMouseLeave:q=>q.currentTarget.style.background=M%2===0?"white":"#fafafa",children:[n.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:K?n.jsx("span",{style:{background:ne+"18",color:ne,border:`1px solid ${ne}44`,padding:"3px 10px",borderRadius:20,fontSize:11,fontWeight:700},children:K}):n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:L.custom_number||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",fontWeight:600,color:"#1a2332",whiteSpace:"nowrap"},children:L.full_name||L.first_name||"—"}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:L.username||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:L.email||L.name}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:L.mobile_no||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:L.custom_organization||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:L.custom_management||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:L.custom_department||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:L.custom_branch||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:V0(L.creation)}),n.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:n.jsx("span",{style:{color:L.enabled?"#16a34a":"#dc2626",fontWeight:600},children:L.enabled?i.users.active:i.users.inactive})}),n.jsx("td",{style:{padding:"10px 14px",whiteSpace:"nowrap"},onClick:q=>q.stopPropagation(),children:n.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[n.jsx("button",{onClick:q=>{q.stopPropagation(),l==null||l(L)},title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),t&&s&&n.jsx("button",{onClick:q=>{q.stopPropagation(),s(L)},title:"Edit",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#dcfce7",color:"#16a34a"},children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),t&&n.jsx("button",{onClick:q=>{q.stopPropagation(),o({name:L.name,email:L.email||L.name}),z(""),P("idle")},title:"Set Password",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#fef3c7",color:"#d97706"},children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),t&&n.jsx("button",{onClick:q=>{q.stopPropagation(),I(L.name)},disabled:k===L.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:k===L.name?.5:1},children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6l-1 14H6L5 6"}),n.jsx("path",{d:"M10 11v6M14 11v6"}),n.jsx("path",{d:"M9 6V4h6v2"})]})})]})})]},L.name)})})]})}),n.jsx(Fe,{page:S,total:E.length,onPageChange:h}),m&&n.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsxs("div",{style:{background:"white",borderRadius:14,padding:32,width:390,boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[n.jsx("div",{style:{fontSize:17,fontWeight:700,marginBottom:6,color:"#1a2332"},children:i.users.setPassword}),n.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:20},children:["User: ",n.jsx("strong",{children:m.email})]}),n.jsx("input",{type:"password",value:x,onChange:L=>z(L.target.value),placeholder:i.users.newPassword,style:{width:"100%",padding:"10px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,boxSizing:"border-box",marginBottom:16,fontFamily:"Segoe UI",outline:"none"},onKeyDown:L=>L.key==="Enter"&&$(),autoFocus:!0}),R==="success"&&n.jsx("div",{style:{color:"#166534",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Password updated successfully"}),R==="error"&&n.jsx("div",{style:{color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Failed to update password"}),n.jsxs("div",{style:{display:"flex",gap:10},children:[n.jsx("button",{onClick:$,disabled:R==="loading"||!x.trim(),style:{flex:1,padding:10,background:"#2563eb",color:"white",border:"none",borderRadius:8,cursor:"pointer",fontSize:13,fontWeight:700,fontFamily:"inherit",opacity:x.trim()?1:.5},children:R==="loading"?"Saving…":i.users.setPassword}),n.jsx("button",{onClick:()=>{o(null),z(""),P("idle")},style:{flex:1,padding:10,background:"#f5f5f5",color:"#374151",border:"1px solid #e5e7eb",borderRadius:8,cursor:"pointer",fontSize:13,fontFamily:"inherit"},children:i.cancel})]})]})})]})}const Cs={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20};function t1({form:e,setForm:t,organizations:l,managements:s,departments:r,branches:i,formStatus:a,viewMode:d,onEdit:u,darkMode:f,notifCount:y,onToggleDark:p,onCountChange:c,onViewProfile:v,isSelfProfile:b,onSubmit:g,onBack:S,onNavigate:h,onLogout:m,user:o}){const x=ee(),z=E=>t(O=>({...O,...E})),R=d?{background:"#f9f9f9"}:{},P=!e.name,k=b?"My Profile":P?"New User":d?`User: ${e.full_name||e.email}`:`Edit User: ${e.full_name||e.email}`,C=fe(s,e.custom_management).map(E=>({name:E.name,label:E.name1||E.name})),$=fe(r,e.custom_department).map(E=>({name:E.name,label:E.department_name||E.name})),I=fe(i,e.custom_branch).map(E=>({name:E.name,label:E.branch||E.name}));return n.jsxs(Me,{title:k,activePage:"users",user:o,formStatus:a,buttonText:x.saveUser,buttonColor:W.blue,viewMode:d,onEdit:u,darkMode:f,notifCount:y,onToggleDark:p,onCountChange:c,onViewProfile:v,hideSettings:b,onSubmit:g,onBack:S,onNavigate:h,onLogout:m,children:[n.jsxs("div",{style:Cs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.organization}),n.jsx(Et,{value:e.custom_organization,onChange:E=>z({custom_organization:E}),organizations:l,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.management}),n.jsx(ue,{value:e.custom_management,onChange:E=>z({custom_management:E}),items:C,placeholder:"-- Select --",disabled:d})]})]}),n.jsxs("div",{style:Cs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.department}),n.jsx(ue,{value:e.custom_department,onChange:E=>z({custom_department:E}),items:$,placeholder:"-- Select --",disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.branch}),n.jsx(ue,{value:e.custom_branch,onChange:E=>z({custom_branch:E}),items:I,placeholder:"-- Select --",disabled:d})]})]}),n.jsxs("div",{style:Cs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.number}),n.jsx("input",{style:{...A,...R},value:e.custom_number,disabled:d,onChange:E=>z({custom_number:E.target.value}),placeholder:"e.g. 10001"})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[x.field.fullName," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...R},value:e.first_name,disabled:d,onChange:E=>z({first_name:E.target.value}),placeholder:"Full name",required:!0})]})]}),n.jsxs("div",{style:Cs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.username}),n.jsx("input",{style:{...A,...R},value:e.username,disabled:d,onChange:E=>z({username:E.target.value}),placeholder:"Username"})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.phoneNumber}),n.jsx("input",{style:{...A,...R},value:e.mobile_no,disabled:d,onChange:E=>z({mobile_no:E.target.value}),placeholder:"Phone number"})]})]}),n.jsxs("div",{style:Cs,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[x.field.emailAddress," ",P&&n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...d||!P?{background:"#f9f9f9"}:{}},value:e.email,disabled:d||!P,onChange:E=>z({email:E.target.value}),placeholder:"user@example.com",type:"email",required:P})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.category}),n.jsxs("select",{style:{...A,...R},value:e.custom_category,disabled:d,onChange:E=>z({custom_category:E.target.value}),children:[n.jsx("option",{value:"",children:x.field.select}),n.jsx("option",{children:"Admin"}),n.jsx("option",{children:"Chairman"}),n.jsx("option",{children:"Auditor"}),n.jsx("option",{children:"X-Auditor"}),n.jsx("option",{children:"Manager"}),n.jsx("option",{children:"Employee"})]})]})]})]})}const du={Active:W.green,Closed:W.gray};function n1({cycles:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState(""),[y,p]=j.useState("all"),c=j.useMemo(()=>[...new Set(e.map(o=>o.organization).filter(Boolean))],[e]),v=j.useMemo(()=>e.filter(o=>{const x=(o.name1||o.name||"").toLowerCase();return!(a&&!x.includes(a.toLowerCase())||u&&o.organization!==u||y!=="all"&&o.status!==y)}),[e,a,u,y]),[b,g]=j.useState(1);j.useEffect(()=>{g(1)},[a,u,y]);const S=v.slice((b-1)*se,b*se),h=v.filter(o=>o.status==="Active").length,m=v.filter(o=>o.status==="Closed").length;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(Ae,{label:"Total",val:v.length,color:W.teal}),n.jsx(Ae,{label:"Active",val:h,color:W.green}),n.jsx(Ae,{label:"Closed",val:m,color:W.gray})]}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Search by name…"},{type:"select",label:i.col.organization,value:u,onChange:f,options:[{value:"",label:"All Organizations"},...c.map(o=>({value:o,label:o}))]},{type:"select",label:"Status",value:y,onChange:p,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Closed",label:"Closed"}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.name}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.frequency}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.startDate}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.endDate}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.status}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.actions})]})}),n.jsx("tbody",{children:v.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):S.map((o,x)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name}),n.jsx("td",{style:{padding:"10px 14px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.frequency||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.start_date||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:o.end_date||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{padding:"3px 10px",borderRadius:12,fontSize:12,background:du[o.status]+"22",color:du[o.status]||"#666"},children:o.status})}),n.jsx("td",{style:{padding:"8px 14px"},onClick:z=>z.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(o),onEdit:t&&s?()=>s(o):void 0,onDelete:t&&r?()=>r(o.name):void 0})})]},o.name))})]})}),n.jsx(Fe,{page:b,total:v.length,onPageChange:g})]})}const Ia={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},l1=["Weekly","Bi-weekly","Monthly","Quarterly","Annually"],s1=["Active","Closed"];function r1({form:e,setForm:t,organizations:l,formStatus:s,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:b,user:g}){const S=ee(),h=x=>t(z=>({...z,...x})),m=r?{background:"#f9f9f9"}:{},o=e.name?r?`${S.formTitle.editCycle}: ${e.name1||e.name}`:S.formTitle.editCycle:S.formTitle.newCycle;return n.jsxs(Me,{title:o,activePage:"cycles",user:g,formStatus:s,buttonText:S.saveCycle,buttonColor:W.teal,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:b,children:[n.jsxs("div",{style:Ia,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[S.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...m},value:e.name1||"",disabled:r||!!e.name,onChange:x=>h({name1:x.target.value}),placeholder:"e.g. Q1-2026"})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[S.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:x=>h({organization:x}),organizations:l,disabled:r||!!g.custom_organization})]})]}),n.jsxs("div",{style:Ia,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.col.frequency}),n.jsx(ue,{value:e.frequency,onChange:x=>h({frequency:x}),items:l1.map(x=>({name:x,label:x})),placeholder:"-- Select Frequency --",disabled:r})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.status}),n.jsx(ue,{value:e.status,onChange:x=>h({status:x}),items:s1.map(x=>({name:x,label:x})),placeholder:"-- Select Status --",disabled:r})]})]}),n.jsxs("div",{style:Ia,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.dateStart}),n.jsx(ye,{value:e.start_date||"",onChange:x=>h({start_date:x}),disabled:r,style:{...A,...m}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.dateEnd}),n.jsx(ye,{value:e.end_date||"",onChange:x=>h({end_date:x}),disabled:r,style:{...A,...m}})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.updateWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...A,...m,maxWidth:160},value:e.update_window_days??2,disabled:r,onChange:x=>h({update_window_days:parseInt(x.target.value)||2})}),n.jsx("span",{style:{fontSize:12,color:"#888",marginLeft:8},children:"Grace period after cycle ends before Unknown is auto-assigned"})]})]})}function i1({kpiInputs:e,canModify:t,onView:l,onEdit:s,onDelete:r}){const i=ee(),[a,d]=j.useState(""),[u,f]=j.useState(""),y=j.useMemo(()=>[...new Set(e.map(g=>g.organization).filter(Boolean))],[e]),p=j.useMemo(()=>e.filter(g=>{const S=[g.organization,g.period].filter(Boolean).join(" ").toLowerCase();return!(a&&!S.includes(a.toLowerCase())||u&&g.organization!==u)}),[e,a,u]),[c,v]=j.useState(1);j.useEffect(()=>{v(1)},[a,u]);const b=p.slice((c-1)*se,c*se);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(Ae,{label:"Total Records",val:p.length,color:W.blue})}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:a,onChange:d,placeholder:"Organization or period…"},{type:"select",label:i.col.organization,value:u,onChange:f,options:[{value:"",label:"All Organizations"},...y.map(g=>({value:g,label:g}))]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.organization}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.period}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.field.revenue_growth}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.field.net_profit}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.dash.customerSat}),n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.actions})]})}),n.jsx("tbody",{children:p.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):b.map((g,S)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(g),style:{borderTop:"1px solid #f0f0f0",background:S%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:g.organization||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.period||"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.revenue_growth!=null?`${g.revenue_growth}%`:"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.net_profit!=null?g.net_profit.toLocaleString():"—"}),n.jsx("td",{style:{padding:"10px 14px"},children:g.customer_satisfaction!=null?g.customer_satisfaction:"—"}),n.jsx("td",{style:{padding:"8px 14px"},onClick:h=>h.stopPropagation(),children:n.jsx(Je,{onView:()=>l==null?void 0:l(g),onEdit:t&&s?()=>s(g):void 0,onDelete:t&&r?()=>r(g.name):void 0})})]},g.name))})]})}),n.jsx(Fe,{page:c,total:p.length,onPageChange:v})]})}const uu={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},pu={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20};function a1({form:e,setForm:t,organizations:l,formStatus:s,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:b,user:g}){const S=ee(),h=z=>t(R=>({...R,...z})),m=r?{background:"#f9f9f9"}:{},o=z=>R=>h({[z]:parseFloat(R.target.value)||0}),x=e.name?r?`${S.formTitle.editKpi}: ${e.period||e.name}`:S.formTitle.editKpi:S.formTitle.newKpi;return n.jsxs(Me,{title:x,activePage:"kpi-input",user:g,formStatus:s,buttonText:S.saveKpi,buttonColor:W.blue,viewMode:r,onEdit:i,darkMode:a,notifCount:d,onToggleDark:u,onCountChange:f,onViewProfile:y,onSubmit:p,onBack:c,onNavigate:v,onLogout:b,children:[n.jsxs("div",{style:uu,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[S.field.organization," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(Et,{value:e.organization,onChange:z=>h({organization:z}),organizations:l,disabled:r||!!g.custom_organization})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[S.col.period," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...A,...m},value:e.period||"",disabled:r,onChange:z=>h({period:z.target.value}),placeholder:"e.g. Q1 2026"})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",marginBottom:12},children:"Financial KPIs"}),n.jsxs("div",{style:pu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.revenue_growth}),n.jsx("input",{type:"number",step:"0.01",style:{...A,...m},value:e.revenue_growth||"",disabled:r,onChange:o("revenue_growth")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.net_profit}),n.jsx("input",{type:"number",step:"0.01",style:{...A,...m},value:e.net_profit||"",disabled:r,onChange:o("net_profit")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.cash_flow}),n.jsx("input",{type:"number",step:"0.01",style:{...A,...m},value:e.cash_flow||"",disabled:r,onChange:o("cash_flow")})]})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",marginBottom:12},children:"Operational KPIs"}),n.jsxs("div",{style:pu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.strategic_goal_pct}),n.jsx("input",{type:"number",step:"0.01",style:{...A,...m},value:e.strategic_goal_pct||"",disabled:r,onChange:o("strategic_goal_pct")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.customer_satisfaction}),n.jsx("input",{type:"number",step:"0.01",style:{...A,...m},value:e.customer_satisfaction||"",disabled:r,onChange:o("customer_satisfaction")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.employee_turnover_pct}),n.jsx("input",{type:"number",step:"0.01",style:{...A,...m},value:e.employee_turnover_pct||"",disabled:r,onChange:o("employee_turnover_pct")})]})]})]}),n.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",paddingTop:16},children:[n.jsx("p",{style:{fontWeight:700,color:"#555",marginBottom:12},children:"Safety & Compliance"}),n.jsxs("div",{style:uu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.open_safety_incidents}),n.jsx("input",{type:"number",min:0,style:{...A,...m},value:e.open_safety_incidents||"",disabled:r,onChange:z=>h({open_safety_incidents:parseInt(z.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:S.field.compliance_score}),n.jsx("input",{type:"number",step:"0.01",style:{...A,...m},value:e.compliance_score||"",disabled:r,onChange:o("compliance_score")})]})]})]})]})}const o1={create_processes:"Create Processes",update_process_status:"Update Process Status"},fu={Pending:W.orange,Accepted:W.green,Rejected:W.red,Revoked:W.gray};function c1(e){if(!e)return"—";const t=new Date(e);return isNaN(t.getTime())?"—":`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${t.getFullYear()}`}function d1(e){const t=[];return e.create_processes&&t.push("create_processes"),e.update_process_status&&t.push("update_process_status"),t}function u1({delegations:e,organizations:t,userRole:l,currentUser:s,onView:r,onRevoke:i}){const a=ee(),[d,u]=j.useState(""),[f,y]=j.useState(""),[p,c]=j.useState("all"),v={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},b=j.useMemo(()=>e.filter(x=>{const z=`${x.auditor} ${x.manager}`.toLowerCase();return!(d&&!z.includes(d.toLowerCase())||f&&x.organization!==f||p!=="all"&&x.status!==p)}),[e,d,f,p]),[g,S]=j.useState(1);j.useEffect(()=>{S(1)},[d,f,p]);const h=b.slice((g-1)*se,g*se),m=b.filter(x=>x.status==="Pending").length,o=b.filter(x=>x.status==="Accepted").length;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(Ae,{label:"Total",val:b.length,color:W.purple}),n.jsx(Ae,{label:"Pending",val:m,color:W.orange}),n.jsx(Ae,{label:"Accepted",val:o,color:W.green})]}),n.jsx(ct,{filters:[{type:"search",label:"Search",value:d,onChange:u,placeholder:"Auditor or Manager…"},{type:"select",label:a.col.organization,value:f,onChange:y,options:[{value:"",label:"All Organizations"},...t.map(x=>({value:x.organization_name||x.name,label:x.organization_name||x.name}))]},{type:"select",label:"Status",value:p,onChange:c,options:[{value:"all",label:"All"},{value:"Pending",label:"Pending"},{value:"Accepted",label:"Accepted"},{value:"Rejected",label:"Rejected"},{value:"Revoked",label:"Revoked"}]}]}),n.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:v,children:a.col.number}),n.jsx("th",{style:v,children:a.col.auditor}),n.jsx("th",{style:v,children:a.col.manager}),n.jsx("th",{style:v,children:a.col.organization}),n.jsx("th",{style:v,children:a.col.functions}),n.jsx("th",{style:v,children:a.col.status}),n.jsx("th",{style:v,children:a.col.requestedOn}),n.jsx("th",{style:v,children:a.col.actions})]})}),n.jsx("tbody",{children:b.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:8,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):h.map((x,z)=>{const R=!!i&&(x.status==="Pending"||x.status==="Accepted")&&(l==="Admin"||l==="Auditor"&&x.auditor===s);return n.jsxs("tr",{onClick:()=>r==null?void 0:r(x),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:x.number||x.name}),n.jsx("td",{style:{padding:"10px 14px"},children:x.auditor}),n.jsx("td",{style:{padding:"10px 14px"},children:x.manager}),n.jsx("td",{style:{padding:"10px 14px"},children:x.organization||"All Organizations"}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:d1(x).map(P=>n.jsx("span",{style:{background:"#ede9fe",color:"#6d28d9",padding:"2px 8px",borderRadius:10,fontSize:11,fontWeight:600},children:o1[P]||P},P))})}),n.jsx("td",{style:{padding:"10px 14px"},children:n.jsx("span",{style:{background:(fu[x.status]||W.gray)+"22",color:fu[x.status]||W.gray,padding:"3px 10px",borderRadius:12,fontSize:12,fontWeight:700},children:x.status})}),n.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:c1(x.requested_on)}),n.jsx("td",{style:{padding:"8px 14px"},onClick:P=>P.stopPropagation(),children:n.jsxs("div",{style:{display:"flex",gap:6},children:[n.jsx("button",{onClick:()=>r==null?void 0:r(x),title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),R&&n.jsx("button",{onClick:()=>i==null?void 0:i(x.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"})]})})]},x.name)})})]})}),n.jsx(Fe,{page:g,total:b.length,onPageChange:S})]})}const hu={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},gu={Pending:W.orange,Accepted:W.green,Rejected:W.red,Revoked:W.gray};function p1(e){if(!e)return"—";const t=new Date(e);return isNaN(t.getTime())?"—":t.toLocaleString()}function f1({form:e,setForm:t,organizations:l,users:s,userRoleMap:r,formStatus:i,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:b,onNavigate:g,onLogout:S,user:h}){var P;const m=ee(),o=k=>t(C=>({...C,...k})),x=a?{background:"#f9f9f9"}:{},z=fr(s,r,"SB Manager").map(k=>({name:k.name,label:k.full_name||k.name})),R=e.name?`${m.formTitle.viewDelegation}${e.number||e.name}`:m.formTitle.newDelegation;return n.jsxs(Me,{title:R,activePage:"delegations",user:h,formStatus:i,buttonText:m.saveDelegation,buttonColor:W.purple,viewMode:a,onEdit:d,darkMode:u,notifCount:f,onToggleDark:y,onCountChange:p,onViewProfile:c,onSubmit:v,onBack:b,onNavigate:g,onLogout:S,children:[a&&e.status&&n.jsx("div",{style:{marginBottom:20},children:n.jsx("span",{style:{background:(gu[e.status]||W.gray)+"22",color:gu[e.status]||W.gray,padding:"5px 14px",borderRadius:14,fontSize:13,fontWeight:700},children:e.status})}),n.jsxs("div",{style:hu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:m.col.auditor}),n.jsx("input",{style:{...A,background:"#f9f9f9"},value:e.auditor||h.name,disabled:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[m.col.manager," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(ue,{value:e.manager,onChange:k=>o({manager:k}),items:z,placeholder:"-- Select Manager --",disabled:a})]})]}),n.jsx("div",{style:hu,children:n.jsxs("div",{children:[n.jsx("label",{style:T,children:m.col.organization}),n.jsx(Et,{value:e.organization,onChange:k=>o({organization:k}),organizations:l,placeholder:"-- All Organizations --",disabled:a})]})}),n.jsxs("div",{style:{marginTop:8},children:[n.jsxs("label",{style:T,children:[m.col.functions," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,marginTop:6},children:[n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,cursor:a?"default":"pointer"},children:[n.jsx("input",{type:"checkbox",style:ds,checked:!!e.create_processes,disabled:a,onChange:k=>o({create_processes:k.target.checked?1:0})}),n.jsx("span",{style:{fontSize:14},children:"Create Processes"})]}),n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,cursor:a?"default":"pointer"},children:[n.jsx("input",{type:"checkbox",style:ds,checked:!!e.update_process_status,disabled:a,onChange:k=>o({update_process_status:k.target.checked?1:0})}),n.jsx("span",{style:{fontSize:14},children:"Update Process Status"})]})]})]}),!a&&n.jsxs("div",{style:{marginTop:20},children:[n.jsx("label",{style:T,children:"Remarks"}),n.jsx("textarea",{style:{...A,...x,minHeight:70,resize:"vertical"},value:e.remarks||"",onChange:k=>o({remarks:k.target.value}),placeholder:"Optional note for the Manager…"})]}),a&&(((P=e.delegation_log)==null?void 0:P.length)??0)>0&&n.jsxs("div",{style:{marginTop:28},children:[n.jsx("label",{style:T,children:"Audit Trail"}),n.jsx("div",{style:{background:"white",borderRadius:8,border:"1px solid #eee",overflow:"hidden"},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa"},children:[n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Action"}),n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Actor"}),n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Timestamp"}),n.jsx("th",{style:{padding:"8px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:"Remarks"})]})}),n.jsx("tbody",{children:(e.delegation_log||[]).map((k,C)=>n.jsxs("tr",{style:{borderTop:"1px solid #f0f0f0"},children:[n.jsx("td",{style:{padding:"8px 14px",fontWeight:600},children:k.action}),n.jsx("td",{style:{padding:"8px 14px"},children:k.actor}),n.jsx("td",{style:{padding:"8px 14px",color:"#666"},children:p1(k.timestamp)}),n.jsx("td",{style:{padding:"8px 14px",color:"#666"},children:k.remarks||"—"})]},k.name||C))})]})})]})]})}const xu={process:"processes-form",order:"orders-form",incident:"incidents-form",idea:"ideas-form"},zs={process:W.blue,order:W.purple,incident:W.red,idea:W.green,delegation:W.orange},mu={process:"🔄",order:"📦",incident:"🚨",idea:"💡",delegation:"🤝"};function Ts(e,t){const l=e.replace("#",""),s=parseInt(l.substring(0,2),16),r=parseInt(l.substring(2,4),16),i=parseInt(l.substring(4,6),16);return`rgba(${s}, ${r}, ${i}, ${t})`}function h1({onNavigate:e,onRefresh:t}){const l=ee(),[s,r]=j.useState([]),[i,a]=j.useState(!0),[d,u]=j.useState(""),[f,y]=j.useState(""),p=()=>vy().then(h=>{r(h),a(!1)});j.useEffect(()=>{p()},[]);const c=s.filter(h=>h.requires_action),v=s.filter(h=>!h.requires_action),b={};for(const h of s)b[h.type]=(b[h.type]||0)+1;const g=async(h,m)=>{u(h),y("");try{await by(h,m),await p(),t==null||t()}catch{y(h)}u("")};function S(h,m,o){return m.length===0?null:n.jsxs("div",{style:{marginBottom:28},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[n.jsx("span",{style:{fontSize:12,fontWeight:800,letterSpacing:.6,textTransform:"uppercase",color:o?W.accent:"#8a8fa3"},children:h}),n.jsx("span",{style:{fontSize:11,fontWeight:700,minWidth:22,textAlign:"center",padding:"2px 7px",borderRadius:999,color:o?"white":"#6b7280",background:o?W.accent:"#e9eaf2"},children:m.length}),n.jsx("div",{style:{flex:1,height:1,background:"linear-gradient(90deg, #e6e7f0, transparent)"}})]}),n.jsx("div",{className:"inbox-card-grid",children:m.map((x,z)=>{const R=x.type!=="delegation",P=zs[x.type]||W.gray;return n.jsxs("div",{className:"inbox-card",onClick:R?()=>e(xu[x.type],x.name):void 0,style:{borderTop:`3px solid ${P}`,cursor:R?"pointer":"default"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:14},children:[n.jsx("div",{style:{width:38,height:38,borderRadius:12,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:17,background:Ts(P,.14)},children:mu[x.type]||"📌"}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[n.jsx("span",{style:{fontWeight:700,fontSize:13,color:P,letterSpacing:.3},children:x.number}),x.requires_action&&n.jsx("span",{style:{fontSize:10,fontWeight:700,color:W.red,background:Ts(W.red,.12),padding:"1px 7px",borderRadius:999,textTransform:"uppercase",letterSpacing:.4},children:"Action"})]}),n.jsx("div",{className:"inbox-card-title",style:{fontSize:14,fontWeight:600,marginTop:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.title}),n.jsxs("div",{className:"inbox-card-meta",style:{marginTop:5,fontSize:12},children:[x.action,x.organization&&n.jsxs(n.Fragment,{children:[n.jsx("span",{style:{opacity:.5},children:" · "}),x.organization]}),x.date&&n.jsxs(n.Fragment,{children:[n.jsx("span",{style:{opacity:.5},children:" · "}),x.date]})]}),f===x.name&&n.jsx("div",{style:{marginTop:6,fontSize:12,color:W.red,fontWeight:600},children:"Failed to respond — please try again."})]})]}),x.type==="delegation"?n.jsxs("div",{style:{display:"flex",gap:8,marginTop:14},children:[n.jsx("button",{onClick:()=>g(x.name,"Accepted"),disabled:d===x.name,style:{flex:1,padding:"8px 0",borderRadius:9,border:"none",background:W.green,color:"white",fontWeight:700,fontSize:13,cursor:d===x.name?"wait":"pointer",opacity:d===x.name?.6:1},children:"Accept"}),n.jsx("button",{onClick:()=>g(x.name,"Rejected"),disabled:d===x.name,style:{flex:1,padding:"8px 0",borderRadius:9,border:"none",background:W.red,color:"white",fontWeight:700,fontSize:13,cursor:d===x.name?"wait":"pointer",opacity:d===x.name?.6:1},children:"Reject"})]}):n.jsx("button",{onClick:k=>{k.stopPropagation(),e(xu[x.type],x.name)},style:{marginTop:14,width:"100%",padding:"8px 0",borderRadius:9,border:"none",background:x.requires_action?P:Ts(P,.12),color:x.requires_action?"white":P,fontWeight:700,fontSize:13,cursor:"pointer"},children:x.requires_action?"Act Now →":l.view})]},z)})})]})}return n.jsxs("div",{style:{maxWidth:1040,margin:"0 auto"},children:[!i&&s.length>0&&n.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",marginBottom:24},children:Object.entries(b).map(([h,m])=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"6px 12px 6px 9px",borderRadius:999,background:Ts(zs[h]||W.gray,.1),border:`1px solid ${Ts(zs[h]||W.gray,.25)}`},children:[n.jsx("span",{style:{fontSize:13},children:mu[h]}),n.jsx("span",{style:{fontSize:12,fontWeight:700,color:zs[h]||W.gray,textTransform:"capitalize"},children:h}),n.jsx("span",{style:{fontSize:12,fontWeight:700,color:zs[h]||W.gray,opacity:.7},children:m})]},h))}),i&&n.jsx("p",{style:{color:"#888"},children:l.loading}),!i&&s.length===0&&n.jsxs("div",{className:"inbox-empty",children:[n.jsx("div",{style:{fontSize:46,marginBottom:10},children:"✨"}),n.jsx("p",{style:{fontSize:16,fontWeight:600},children:l.inbox.noMessages}),n.jsx("p",{style:{fontSize:13,marginTop:4,opacity:.7},children:"You're all caught up — nothing needs your attention right now."})]}),!i&&S("Needs Action",c,!0),!i&&S("Informational",v,!1)]})}const g1=[{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"]}],Mf={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 x1(e,t){const l=e.map(r=>Mf[r]||r).join(","),s=t.map(r=>e.map(i=>`"${r[i]??""}"`).join(",")).join(` `);return l+` `+s}function m1(e,t){const l=new Blob([e],{type:"text/csv"}),s=URL.createObjectURL(l),r=document.createElement("a");r.href=s,r.download=t,r.click(),URL.revokeObjectURL(s)}const Hf="report-print-area",Ea="report-print-portal";function y1(){const e=document.getElementById(Hf);if(!e)return;const t=document.createElement("div");t.id=Ea,t.innerHTML=e.innerHTML,document.body.appendChild(t);const l=document.createElement("style");l.id="report-print-style",l.textContent=` #${Ea} { display: none; } @media print { #root { display: none !important; } #${Ea} { display: block !important; } } `,document.head.appendChild(l);const s=()=>{t.remove(),l.remove(),window.removeEventListener("afterprint",s)};window.addEventListener("afterprint",s),window.print()}const yu={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",minWidth:180},Aa={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white"};function v1({organizations:e,userRole:t}){const l=ee(),s=g1.filter(C=>C.roles.includes(t)),[r,i]=j.useState(""),[a,d]=j.useState(""),[u,f]=j.useState(""),[y,p]=j.useState(""),[c,v]=j.useState(String(new Date().getFullYear())),[b,g]=j.useState([]),[S,h]=j.useState([]),[m,o]=j.useState(!1),[x,z]=j.useState(""),R=s.find(C=>C.id===r);async function P(){if(r){o(!0),z(""),h([]),g([]);try{const C={};a&&(C.organization=a),u&&(C.from_date=u),y&&(C.to_date=y),(R==null?void 0:R.extraFilter)==="year"&&c&&(C.year=c);const $=await yy(r,C);g($.columns||[]),h($.rows||[])}catch(C){z(C.message||"Error running report")}finally{o(!1)}}}const k=(R==null?void 0:R.label)||r;return n.jsxs("div",{children:[n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12,marginBottom:20},children:s.map(C=>n.jsxs("div",{onClick:()=>i(C.id),style:{background:r===C.id?"#ebf5fb":"white",border:r===C.id?`2px solid ${W.accent}`:"2px solid transparent",borderRadius:10,padding:"14px 16px",cursor:"pointer",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[n.jsx("div",{style:{fontWeight:700,fontSize:14,color:"#1a2332",marginBottom:4},children:C.label}),n.jsx("div",{style:{fontSize:12,color:"#888"},children:C.description})]},C.id))}),n.jsx("div",{style:{background:"white",borderRadius:12,padding:20,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:20},children:n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"REPORT"}),n.jsxs("select",{style:yu,value:r,onChange:C=>i(C.target.value),children:[n.jsx("option",{value:"",children:"-- Select Report --"}),s.map(C=>n.jsx("option",{value:C.id,children:C.label},C.id))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"ORGANIZATION"}),n.jsxs("select",{style:yu,value:a,onChange:C=>d(C.target.value),children:[n.jsx("option",{value:"",children:l.filter.allOrgs}),e.map(C=>n.jsx("option",{value:C.name,children:C.organization_name||C.name},C.name))]})]}),(R==null?void 0:R.extraFilter)==="year"?n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"YEAR"}),n.jsx("input",{type:"number",style:{...Aa,width:90},value:c,onChange:C=>v(C.target.value),min:2020,max:2099})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"FROM"}),n.jsx(ye,{value:u,onChange:f,style:Aa})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"TO"}),n.jsx(ye,{value:y,onChange:p,style:Aa})]})]}),n.jsx("button",{onClick:P,disabled:!r||m,style:{padding:"9px 20px",borderRadius:8,border:"none",background:W.accent,color:"white",fontWeight:700,fontSize:13,cursor:r?"pointer":"not-allowed",opacity:r?1:.5},children:m?l.loading:l.reports.generate}),S.length>0&&n.jsx("button",{onClick:()=>m1(x1(b,S),`${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"}),S.length>0&&n.jsx("button",{onClick:y1,style:{padding:"9px 20px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Print / PDF"})]})}),x&&n.jsx("div",{style:{color:"#e74c3c",marginBottom:16},children:x}),S.length>0&&n.jsxs("div",{id:Hf,style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto"},children:[n.jsxs("div",{style:{padding:"14px 18px",borderBottom:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n.jsx("span",{style:{fontWeight:700,color:"#333"},children:k}),n.jsxs("span",{style:{fontSize:12,color:"#888"},children:[S.length," rows"]})]}),n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa"},children:b.map(C=>n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700,whiteSpace:"nowrap"},children:Mf[C]||C.replace(/_/g," ").toUpperCase()},C))})}),n.jsx("tbody",{children:S.map((C,$)=>n.jsx("tr",{style:{borderTop:"1px solid #f0f0f0",background:$%2===0?"white":"#fafafa"},children:b.map(I=>n.jsx("td",{style:{padding:"10px 14px",color:"#333"},children:C[I]!=null?String(C[I]):"—"},I))},$))})]})]}),!m&&S.length===0&&r&&!x&&n.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"Select a report and click Run Report to see results."}),s.length===0&&n.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"No reports are available for your role."})]})}const hr=()=>new Date().toISOString().split("T")[0],wc=()=>new Date(Date.now()+30*24*60*60*1e3).toISOString().split("T")[0],Vt=()=>({name:"",number:"",title:"",organization:"",type:"",incident_class:"",incident_field:"",date:hr(),time:"",management:"",department:"",section_field:"",branch:"",assigned_to:"",status:"",description:"",summary:"",workflow_state:"New",hses_field:"",priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:""}),en=()=>({name:"",number:"",title:"",organization:"",type:"",management:"",department:"",section_field:"",branch:"",current_condition:"",proposed_condition:"",status:"",assigned_to:"",workflow_state:"New",idea_class:"",hses_field:"",date:hr(),priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:""}),tn=()=>({name:"",number:"",title:"",organization:"",type:"Buy L",management:"",department:"",section_field:"",branch:"",starting_date:hr(),ending_date:wc(),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:""}),Hr=()=>({name:"",title:"",date_start:hr(),date_end:wc(),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:""}),Pl=()=>({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}),Gn=()=>({name:"",organization:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Yn=()=>({name:"",custom_organization:"",department_name:"",custom_management:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),Xn=()=>({name:"",organization:"",branch:"",management:"",department:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),Il=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),El=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Al=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Rl=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Ll=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Ol=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Dl=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Nl=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Kr=()=>({name:"",first_name:"",full_name:"",email:"",enabled:1,creation:"",username:"",mobile_no:"",custom_organization:"",custom_management:"",custom_department:"",custom_branch:"",custom_number:"",custom_category:""}),qn=()=>({name:"",name1:"",organization:"",frequency:"Monthly",status:"Active",start_date:hr(),end_date:wc(),update_window_days:2}),Jn=()=>({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}),Ps=()=>({name:"",number:"",auditor:"",manager:"",organization:"",create_processes:0,update_process_status:0,status:"Pending",requested_on:"",remarks:""}),j1=new Set(["incidents","incidents-form","ideas","ideas-form"]),b1=new Set(["orders","orders-form","incidents","incidents-form","ideas","ideas-form"]),S1=new Set(["Admin","Owner","Auditor","Manager"]),w1=new Set(["Admin","Owner","Auditor","Manager"]),k1=new Set(["Admin","Auditor","Manager"]);function _1({user:e,onLogout:t,darkMode:l,onToggleDark:s}){const r=ee(),i=e.role,a=S1.has(i),d=w1.has(i),u=k1.has(i),f=w=>w==="users"||w==="users-form"?i==="Admin":i==="Admin"||i==="Auditor"?!0:i==="Owner"||i==="XAuditor"?!1:i==="Manager"?!!(b1.has(w)||(w==="processes"||w==="processes-form")&&Cc.includes("create_processes")):j1.has(w),y=w=>i==="Employee"&&!!w&&w!=="New",[p,c]=j.useState(a?"dashboard":"inbox"),v=e.custom_organization||"",[b,g]=j.useState(""),[S,h]=j.useState("");j.useEffect(()=>{if(!S)return;const w=setTimeout(()=>h(""),0);return()=>clearTimeout(w)},[S]);const m=(w,G)=>{h(G),c(w)},[o,x]=j.useState(0),[z,R]=j.useState([]),[P,k]=j.useState([]),[C,$]=j.useState([]),[I,E]=j.useState([]),[O,U]=j.useState([]),[V,xe]=j.useState([]),[le,L]=j.useState([]),[M,K]=j.useState([]),[ne,q]=j.useState([]),[me,Ce]=j.useState([]),[re,ze]=j.useState([]),[he,H]=j.useState([]),[J,N]=j.useState([]),[oe,Wn]=j.useState([]),[gt,_]=j.useState([]),[Y,Z]=j.useState([]),[Yt,gr]=j.useState([]),[Bn,Xi]=j.useState([]),[$n,D]=j.useState([]),[Ge,hl]=j.useState({}),[kt,Kf]=j.useState([]),[xr,Qf]=j.useState([]),[kc,Gf]=j.useState([]),[_c,Yf]=j.useState([]),[Cc,Xf]=j.useState([]),[zc,qf]=j.useState({}),[we,de]=j.useState(!0),[De,ie]=j.useState("idle"),[Ne,te]=j.useState(!1),[Tc,Pc]=j.useState(!1),[mr,Ic]=j.useState(null),[Jf,Zf]=j.useState(()=>localStorage.getItem("sb_sidebar")==="1"),Vf=()=>Zf(w=>{const G=!w;return localStorage.setItem("sb_sidebar",G?"1":"0"),G}),[eh,qi]=j.useState(!1);j.useEffect(()=>{qi(!1)},[p]);const[gl,Xt]=j.useState(Vt()),[xl,qt]=j.useState(en()),[yr,Jt]=j.useState(tn()),[vr,Ft]=j.useState(Hr()),[Ec,ml]=j.useState(Pl()),[Ac,Un]=j.useState(Gn()),[Rc,Fn]=j.useState(Yn()),[Lc,Mn]=j.useState(Xn()),[Oc,yl]=j.useState(Il()),[Dc,vl]=j.useState(El()),[Nc,jl]=j.useState(Al()),[Wc,bl]=j.useState(Rl()),[Bc,Sl]=j.useState(Ll()),[$c,wl]=j.useState(Ol()),[Uc,kl]=j.useState(Dl()),[Fc,_l]=j.useState(Nl()),[hs,jr]=j.useState(Kr()),[Mc,Hn]=j.useState(qn()),[Hc,Kn]=j.useState(Jn()),[Cl,gs]=j.useState(Ps()),At=async()=>{de(!0);try{const[w,G,xt,Rt,hn,We,ea,Xh,qh,Jh,Zh,Vh,eg,tg,ng,lg,sg,rg,ig,ag,og,cg,dg,ug,pg,fg]=await Promise.all([ke(B.incidents),ke(B.organizations),ke(B.ideas),ke(B.orders),ke(B.processes),ey(),ke(B.managements),ke(B.departments),ke(B.branches),ke(B.incidentTypes),ke(B.incidentClass),ke(B.incidentField),ke(B.ideaTypes),ke(B.orderTypes),ke(B.processTypes),ke(B.incidentStatuses),ke(B.ideaStatuses),ke(B.orderStatuses),ke(B.processStatuses),sy(),ry(),ke(B.cycles),ke(B.kpiInput),wy(),_y(),Cy()]);R(w||[]),k(G||[]),$(xt||[]),E(Rt||[]),U(hn||[]),Kf(We||[]),xe(ea||[]),L(Xh||[]),K(qh||[]),q(Jh||[]),Ce(Zh||[]),ze(Vh||[]),H(eg||[]),N(tg||[]),Wn(ng||[]),_(lg||[]),Z(sg||[]),gr(rg||[]),Xi(ig||[]),D(ag||[]),hl(og||{}),Qf(cg||[]),Gf(dg||[]),Yf(ug||[]),Xf(pg||[]),qf(fg||{})}catch(w){console.error("Error loading data:",w)}de(!1)},th=async()=>{try{const w=await fetch("/api/method/sidrah_business.api.get_notification_count",{credentials:"include",headers:{Accept:"application/json"}});if(w.ok){const G=await w.json();x(Number(G.message)||0)}}catch{}};j.useEffect(()=>{At(),th()},[e.name]);const He=async(w,G)=>{if(window.confirm(r.rtl?"هل أنت متأكد من حذف هذا السجل؟":"Are you sure you want to delete this record?")){de(!0);try{await Nf(w,G),await At()}catch(xt){console.error("Delete error:",xt),alert((xt==null?void 0:xt.message)||"Delete failed. Please try again.")}de(!1)}},nh=async w=>{try{await cy(w),await At()}catch(G){console.error("Disable user error:",G)}},lh=async w=>{te(!0),de(!0);try{const G=await mt(B.incidents,w.name);Xt({...Vt(),...G})}catch{Xt({...Vt(),...w})}c("incidents-form"),de(!1)},sh=async w=>{te(!0),de(!0);try{const G=await mt(B.ideas,w.name);qt({...en(),...G})}catch{qt({...en(),...w})}c("ideas-form"),de(!1)},rh=async w=>{te(!0),de(!0);try{const G=await mt(B.orders,w.name);Jt({...tn(),...G})}catch{Jt({...tn(),...w})}c("orders-form"),de(!1)},ih=async w=>{te(!0),de(!0);try{const G=await Ls(w.name);Ft({...G,progress_indicators:G.progress_indicators||[],cycle_logs:G.cycle_logs||[]}),c("processes-form")}catch{Ft({...w,progress_indicators:w.progress_indicators||[]}),c("processes-form")}de(!1)},ah=w=>ve(B.organizations,w,ml,Pl(),"organizations-form",!0),oh=async w=>{te(!0),de(!0);try{const G=await mt(B.managements,w.name);Un({...Gn(),...G})}catch{Un({...Gn(),...w})}c("managements-form"),de(!1)},ch=async w=>{te(!0),de(!0);try{const G=await mt(B.departments,w.name);Fn({...Yn(),...G})}catch{Fn({...Yn(),...w})}c("departments-form"),de(!1)},dh=async w=>{te(!0),de(!0);try{const G=await mt(B.branches,w.name);Mn({...Xn(),...G})}catch{Mn({...Xn(),...w})}c("branches-form"),de(!1)},uh=async w=>{te(!0),de(!0);try{const G=await mt(B.cycles,w.name);Hn({...qn(),...G})}catch{Hn({...qn(),...w})}c("cycles-form"),de(!1)},ph=async w=>{te(!0),de(!0);try{const G=await mt(B.kpiInput,w.name);Kn({...Jn(),...G})}catch{Kn({...Jn(),...w})}c("kpi-input-form"),de(!1)},Ye=async(w,G,xt,Rt,hn)=>{ie("loading");try{if(G.name)await Ti(w,G.name,G),ie("success"),At(),setTimeout(()=>{ie("idle"),c(Rt)},1500);else if(hn){const We=await za(w,G);hn(We),ie("success"),At(),setTimeout(()=>ie("idle"),1500)}else await za(w,G),xt(),ie("success"),At(),setTimeout(()=>{ie("idle"),c(Rt)},1500)}catch(We){console.error("Submit error:",We),ie(We instanceof Error?We.message:"Error saving. Please try again.")}},Re=async()=>{await ny(),t()},ve=async(w,G,xt,Rt,hn,We)=>{te(We),de(!0);try{const ea=await mt(w,G.name);xt({...Rt,...ea})}catch{xt({...Rt,...G})}c(hn),de(!1)},fh=w=>ve(B.incidents,w,Xt,Vt(),"incidents-form",!1),hh=w=>ve(B.ideas,w,qt,en(),"ideas-form",!1),gh=w=>ve(B.orders,w,Jt,tn(),"orders-form",!1),xh=w=>{te(!1),de(!0),Ls(w.name).then(G=>{Ft({...G,progress_indicators:G.progress_indicators||[],cycle_logs:G.cycle_logs||[]})}).catch(()=>{Ft({...w,progress_indicators:w.progress_indicators||[]})}).finally(()=>{c("processes-form"),de(!1)})},mh=w=>ve(B.organizations,w,ml,Pl(),"organizations-form",!1),yh=w=>ve(B.managements,w,Un,Gn(),"managements-form",!1),vh=w=>ve(B.departments,w,Fn,Yn(),"departments-form",!1),jh=w=>ve(B.branches,w,Mn,Xn(),"branches-form",!1),bh=w=>ve(B.cycles,w,Hn,qn(),"cycles-form",!1),Sh=w=>ve(B.kpiInput,w,Kn,Jn(),"kpi-input-form",!1),wh=async w=>{te(!0),de(!0);try{const G=await ky(w.name);gs({...Ps(),...G})}catch{gs({...Ps(),...w})}c("delegations-form"),de(!1)},kh=async()=>{ie("loading");try{const w=[];Cl.create_processes&&w.push("create_processes"),Cl.update_process_status&&w.push("update_process_status"),await jy(Cl.manager,w,Cl.organization,Cl.remarks),gs(Ps()),ie("success"),At(),setTimeout(()=>{ie("idle"),c("delegations")},1500)}catch(w){console.error("Delegation submit error:",w),ie(w instanceof Error?w.message:"Error saving. Please try again.")}},_h=async w=>{if(window.confirm(r.rtl?"هل أنت متأكد من إلغاء هذا التفويض؟":"Are you sure you want to revoke this delegation?")){de(!0);try{await Sy(w),await At()}catch(G){console.error("Revoke delegation error:",G),alert(G instanceof Error?G.message:"Revoke failed. Please try again.")}de(!1)}},Ch=w=>ve(B.incidentTypes,w,yl,Il(),"incident-types-form",!0),zh=w=>ve(B.incidentTypes,w,yl,Il(),"incident-types-form",!1),Th=w=>ve(B.ideaTypes,w,vl,El(),"idea-types-form",!0),Ph=w=>ve(B.ideaTypes,w,vl,El(),"idea-types-form",!1),Ih=w=>ve(B.orderTypes,w,jl,Al(),"order-types-form",!0),Eh=w=>ve(B.orderTypes,w,jl,Al(),"order-types-form",!1),Ah=w=>ve(B.processTypes,w,bl,Rl(),"process-types-form",!0),Rh=w=>ve(B.processTypes,w,bl,Rl(),"process-types-form",!1),Lh=w=>ve(B.incidentStatuses,w,Sl,Ll(),"incident-statuses-form",!0),Oh=w=>ve(B.incidentStatuses,w,Sl,Ll(),"incident-statuses-form",!1),Dh=w=>ve(B.ideaStatuses,w,wl,Ol(),"idea-statuses-form",!0),Nh=w=>ve(B.ideaStatuses,w,wl,Ol(),"idea-statuses-form",!1),Wh=w=>ve(B.orderStatuses,w,kl,Dl(),"order-statuses-form",!0),Bh=w=>ve(B.orderStatuses,w,kl,Dl(),"order-statuses-form",!1),$h=w=>ve(B.processStatuses,w,_l,Nl(),"process-statuses-form",!0),Uh=w=>ve(B.processStatuses,w,_l,Nl(),"process-statuses-form",!1),Fh=async w=>{Ic(w),c("profile")},Mh=w=>{te(!1),Pc(!1),jr({...Kr(),...w}),c("users-form")},Hh=async()=>{ie("loading");try{if(!hs.name){const G=await za("User",{...hs,send_welcome_email:0,user_type:"System User"});jr({...Kr(),...hs,...G}),te(!0),ie("success"),At(),setTimeout(()=>ie("idle"),1500)}else{const{name:G,email:xt,creation:Rt,full_name:hn,...We}=hs;await Ti("User",G,We),ie("success"),At(),setTimeout(()=>{ie("idle"),c("users")},1500)}}catch(w){console.error("User submit error:",w),ie(w instanceof Error?w.message:"Error saving. Please try again.")}},Le=()=>{const w=$n.find(G=>G.name===e.name||G.username===e.name);Ic(w||{name:e.name,full_name:e.full_name,email:e.name,enabled:1}),c("profile")},Ji=(w,G)=>{if(G){const Rt={"processes-form":B.processes,"orders-form":B.orders,"incidents-form":B.incidents,"ideas-form":B.ideas}[w];if(Rt){te(!0),de(!0),(w==="processes-form"?Ls(G).then(We=>({...We,progress_indicators:We.progress_indicators||[],cycle_logs:We.cycle_logs||[]})):mt(Rt,G)).then(We=>{w==="processes-form"?Ft(We):w==="orders-form"?Jt({...tn(),...We}):w==="incidents-form"?Xt({...Vt(),...We}):w==="ideas-form"&&qt({...en(),...We}),c(w),de(!1)}).catch(()=>{c(w),de(!1)});return}}c(w)};if(p==="incidents-form")return n.jsx(qy,{incForm:gl,setIncForm:Xt,organizations:P,managements:V,departments:le,branches:M,incidentTypes:ne,incidentClasses:me,incidentFields:re,incidentStatuses:gt,users:kt,userRoleMap:Ge,formStatus:De,viewMode:Ne||!f("incidents-form")||y(gl.workflow_state),onEdit:f("incidents-form")&&!y(gl.workflow_state)?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,userRole:i,onSubmit:()=>Ye(B.incidents,gl,()=>Xt(Vt()),"incidents",w=>Xt({...Vt(),...w})),onBack:()=>{c("incidents"),ie("idle")},onNavigate:c,onLogout:Re,user:e,onRefresh:async()=>{if(gl.name){const w=await mt(B.incidents,gl.name).catch(()=>null);w&&Xt({...Vt(),...w})}ke(B.incidents).then(w=>R(w||[])).catch(()=>{})}});if(p==="ideas-form")return n.jsx(e0,{ideaForm:xl,setIdeaForm:qt,organizations:P,managements:V,departments:le,branches:M,ideaTypes:he,ideaStatuses:Y,users:kt,userRoleMap:Ge,formStatus:De,viewMode:Ne||!f("ideas-form")||y(xl.workflow_state),onEdit:f("ideas-form")&&!y(xl.workflow_state)?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,userRole:i,onSubmit:()=>Ye(B.ideas,xl,()=>qt(en()),"ideas",w=>qt({...en(),...w})),onBack:()=>{c("ideas"),ie("idle")},onNavigate:c,onLogout:Re,user:e,onRefresh:async()=>{if(xl.name){const w=await mt(B.ideas,xl.name).catch(()=>null);w&&qt({...en(),...w})}ke(B.ideas).then(w=>$(w||[])).catch(()=>{})}});if(p==="orders-form")return n.jsx(r0,{orderForm:yr,setOrderForm:Jt,organizations:P,managements:V,departments:le,branches:M,orderTypes:J,orderStatuses:Yt,cycles:xr,users:kt,userRoleMap:Ge,formStatus:De,viewMode:Ne||!f("orders-form"),onEdit:f("orders-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,currentUser:e.name,userRole:i,onSubmit:()=>Ye(B.orders,yr,()=>Jt(tn()),"orders",w=>Jt({...tn(),...w})),onBack:()=>{c("orders"),ie("idle")},onNavigate:c,onLogout:Re,user:e,onRefresh:async()=>{if(yr.name){const w=await mt(B.orders,yr.name).catch(()=>null);w&&Jt({...tn(),...w})}ke(B.orders).then(w=>E(w||[])).catch(()=>{})}});if(p==="processes-form")return n.jsx(d0,{processForm:vr,setProcessForm:Ft,organizations:P,managements:V,departments:le,branches:M,processTypes:oe,processStatuses:Bn,cycles:xr,users:kt,userRoleMap:Ge,formStatus:De,viewMode:Ne||!f("processes-form"),onEdit:f("processes-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,userRole:e.role,delegatedFunctions:Cc,delegatedOrgs:zc.create_processes,onRefreshProcess:async()=>{if(vr.name)try{const w=await Ls(vr.name);Ft({...w,progress_indicators:w.progress_indicators||[],cycle_logs:w.cycle_logs||[]})}catch{}ke(B.processes).then(w=>U(w||[])).catch(()=>{})},onSubmit:()=>Ye(B.processes,vr,()=>Ft(Hr()),"processes",w=>Ft({...Hr(),...w,progress_indicators:w.progress_indicators||[],cycle_logs:w.cycle_logs||[]})),onBack:()=>{c("processes"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="organizations-form")return n.jsx(x0,{orgForm:Ec,setOrgForm:ml,formStatus:De,viewMode:Ne||!f("organizations-form"),onEdit:f("organizations-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.organizations,Ec,()=>ml(Pl()),"organizations",w=>{ml({...Pl(),...w}),te(!0)}),onBack:()=>{c("organizations"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="managements-form")return n.jsx(v0,{form:Ac,setForm:Un,organizations:P,formStatus:De,viewMode:Ne||!f("managements-form"),onEdit:f("managements-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.managements,Ac,()=>Un(Gn()),"managements",w=>{Un({...Gn(),...w}),te(!0)}),onBack:()=>{c("managements"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="departments-form")return n.jsx(w0,{form:Rc,setForm:Fn,organizations:P,managements:V,formStatus:De,viewMode:Ne||!f("departments-form"),onEdit:f("departments-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.departments,Rc,()=>Fn(Yn()),"departments",w=>{Fn({...Yn(),...w}),te(!0)}),onBack:()=>{c("departments"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="branches-form")return n.jsx(z0,{form:Lc,setForm:Mn,organizations:P,managements:V,departments:le,formStatus:De,viewMode:Ne||!f("branches-form"),onEdit:f("branches-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.branches,Lc,()=>Mn(Xn()),"branches",w=>{Mn({...Xn(),...w}),te(!0)}),onBack:()=>{c("branches"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="cycles-form")return n.jsx(r1,{form:Mc,setForm:Hn,organizations:P,formStatus:De,viewMode:Ne||!f("cycles-form"),onEdit:f("cycles-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.cycles,Mc,()=>Hn(qn()),"cycles",w=>{Hn({...qn(),...w}),te(!0)}),onBack:()=>{c("cycles"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="kpi-input-form")return n.jsx(a1,{form:Hc,setForm:Kn,organizations:P,formStatus:De,viewMode:Ne||!f("kpi-input-form"),onEdit:f("kpi-input-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.kpiInput,Hc,()=>Kn(Jn()),"kpi-input",w=>{Kn({...Jn(),...w}),te(!0)}),onBack:()=>{c("kpi-input"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="incident-types-form")return n.jsx(I0,{form:Oc,setForm:yl,formStatus:De,viewMode:Ne||!f("incident-types-form"),onEdit:f("incident-types-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.incidentTypes,Oc,()=>yl(Il()),"incident-types",w=>{yl({...Il(),...w}),te(!0)}),onBack:()=>{c("incident-types"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="idea-types-form")return n.jsx(R0,{form:Dc,setForm:vl,formStatus:De,viewMode:Ne||!f("idea-types-form"),onEdit:f("idea-types-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.ideaTypes,Dc,()=>vl(El()),"idea-types",w=>{vl({...El(),...w}),te(!0)}),onBack:()=>{c("idea-types"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="order-types-form")return n.jsx(D0,{form:Nc,setForm:jl,formStatus:De,viewMode:Ne||!f("order-types-form"),onEdit:f("order-types-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.orderTypes,Nc,()=>jl(Al()),"order-types",w=>{jl({...Al(),...w}),te(!0)}),onBack:()=>{c("order-types"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="process-types-form")return n.jsx(B0,{form:Wc,setForm:bl,formStatus:De,viewMode:Ne||!f("process-types-form"),onEdit:f("process-types-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.processTypes,Wc,()=>bl(Rl()),"process-types",w=>{bl({...Rl(),...w}),te(!0)}),onBack:()=>{c("process-types"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="incident-statuses-form")return n.jsx(F0,{form:Bc,setForm:Sl,formStatus:De,viewMode:Ne||!f("incident-statuses-form"),onEdit:f("incident-statuses-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.incidentStatuses,Bc,()=>Sl(Ll()),"incident-statuses",w=>{Sl({...Ll(),...w}),te(!0)}),onBack:()=>{c("incident-statuses"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="idea-statuses-form")return n.jsx(K0,{form:$c,setForm:wl,formStatus:De,viewMode:Ne||!f("idea-statuses-form"),onEdit:f("idea-statuses-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.ideaStatuses,$c,()=>wl(Ol()),"idea-statuses",w=>{wl({...Ol(),...w}),te(!0)}),onBack:()=>{c("idea-statuses"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="order-statuses-form")return n.jsx(Y0,{form:Uc,setForm:kl,formStatus:De,viewMode:Ne||!f("order-statuses-form"),onEdit:f("order-statuses-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.orderStatuses,Uc,()=>kl(Dl()),"order-statuses",w=>{kl({...Dl(),...w}),te(!0)}),onBack:()=>{c("order-statuses"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="process-statuses-form")return n.jsx(J0,{form:Fc,setForm:_l,formStatus:De,viewMode:Ne||!f("process-statuses-form"),onEdit:f("process-statuses-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:()=>Ye(B.processStatuses,Fc,()=>_l(Nl()),"process-statuses",w=>{_l({...Nl(),...w}),te(!0)}),onBack:()=>{c("process-statuses"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="users-form")return n.jsx(t1,{form:hs,setForm:jr,organizations:P,managements:V,departments:le,branches:M,formStatus:De,viewMode:Ne||!f("users-form"),onEdit:f("users-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,isSelfProfile:Tc,onSubmit:Hh,onBack:()=>{c(Tc?a?"dashboard":"inbox":"users"),ie("idle")},onNavigate:c,onLogout:Re,user:e});if(p==="delegations-form")return n.jsx(f1,{form:Cl,setForm:gs,organizations:P,users:kt,userRoleMap:Ge,formStatus:De,viewMode:Ne||!f("delegations-form"),onEdit:f("delegations-form")?()=>te(!1):void 0,darkMode:l,notifCount:o,onToggleDark:s,onCountChange:x,onViewProfile:Le,onSubmit:kh,onBack:()=>{c("delegations"),ie("idle")},onNavigate:c,onLogout:Re,user:e});const Kh=r.pages,Qh={incidents:{color:W.accent,formPage:"incidents-form",reset:()=>Xt({...Vt(),organization:v||b})},ideas:{color:W.teal,formPage:"ideas-form",reset:()=>qt({...en(),organization:v||b})},orders:{color:W.purple,formPage:"orders-form",reset:()=>Jt({...tn(),organization:v||b})},processes:{color:W.blue,formPage:"processes-form",reset:()=>{const w=zc.create_processes,G=v||(i==="Manager"&&w&&w.length===1?w[0]:b);Ft({...Hr(),organization:G})}},organizations:{color:W.accent,formPage:"organizations-form",reset:()=>ml(Pl())},managements:{color:W.blue,formPage:"managements-form",reset:()=>Un({...Gn(),organization:v||b})},departments:{color:W.teal,formPage:"departments-form",reset:()=>Fn({...Yn(),custom_organization:v||b})},branches:{color:W.purple,formPage:"branches-form",reset:()=>Mn({...Xn(),organization:v||b})},cycles:{color:W.teal,formPage:"cycles-form",reset:()=>Hn({...qn(),organization:v||b})},"kpi-input":{color:W.blue,formPage:"kpi-input-form",reset:()=>Kn({...Jn(),organization:v||b})},"incident-types":{color:W.red,formPage:"incident-types-form",reset:()=>yl(Il())},"idea-types":{color:W.orange,formPage:"idea-types-form",reset:()=>vl(El())},"order-types":{color:W.green,formPage:"order-types-form",reset:()=>jl(Al())},"process-types":{color:W.accent,formPage:"process-types-form",reset:()=>bl(Rl())},"incident-statuses":{color:W.red,formPage:"incident-statuses-form",reset:()=>Sl(Ll())},"idea-statuses":{color:W.teal,formPage:"idea-statuses-form",reset:()=>wl(Ol())},"order-statuses":{color:W.purple,formPage:"order-statuses-form",reset:()=>kl(Dl())},"process-statuses":{color:W.blue,formPage:"process-statuses-form",reset:()=>_l(Nl())},users:{color:W.blue,formPage:"users-form",reset:()=>{jr(Kr()),Pc(!1)}},delegations:{color:W.purple,formPage:"delegations-form",reset:()=>gs(Ps())}},Gh={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"},Yh={incidents:z,ideas:C,orders:I,processes:O,organizations:P,managements:V,departments:le,branches:M,cycles:xr,"kpi-input":kc,"incident-types":ne,"idea-types":he,"order-types":J,"process-types":oe,"incident-statuses":gt,"idea-statuses":Y,"order-statuses":Yt,"process-statuses":Bn,users:$n,delegations:_c},Qn=Hm[p],Zi=Yh[p],X=f(p),Vi=X?Qh[p]:null;return n.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:l?"#0f172a":W.bg},children:[n.jsx(Lf,{collapsed:Jf,onToggleCollapsed:Vf,activePage:p,onNavigate:w=>c(w),hasDashboard:a,hasReports:d,hasDelegations:u,role:i,rtl:r.rtl,navLabels:r.nav,settingsLabel:r.nav.settings}),n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[n.jsx("div",{style:{background:l?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${l?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:l?"none":"0 1px 4px rgba(0,0,0,0.04)"},children:n.jsx(Uf,{notifCount:o,darkMode:l,onCountChange:x,onToggleDark:s,onNavigate:Ji,onViewProfile:Le,onLogout:Re})}),p!=="profile"&&n.jsxs("div",{style:{background:l?"#1e293b":"white",padding:"9px 20px",borderBottom:`1px solid ${l?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[n.jsx("div",{style:{fontSize:15,fontWeight:700,color:l?"#e2e8f0":"#1e1b4b"},children:Kh[p]||p}),n.jsxs("div",{style:{display:"flex",gap:8},children:[Qn&&Zi&&n.jsx("button",{onClick:()=>qi(!0),style:{background:"#16a34a",color:"white",border:"none",padding:"6px 14px",borderRadius:7,fontSize:12,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"}),Vi&&n.jsxs("button",{onClick:()=>{Vi.reset(),te(!1),ie("idle"),c(Vi.formPage)},style:{background:"#4f46e5",color:"white",border:"none",padding:"6px 14px",borderRadius:7,fontSize:12,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI"},children:["+ ",Gh[p]||r.new]})]})]}),Qn&&Zi&&eh&&n.jsx(Jm,{title:Qn.label,rows:Zi,columns:Qn.columns,defaultColumnKeys:Qn.defaultColumns,orgField:Qn.orgField,organizations:Qn.orgField?P:void 0,filenameBase:p,onClose:()=>qi(!1)}),n.jsxs("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",padding:p==="profile"?0:"20px 24px",gap:p==="profile"?0:16},children:[we&&n.jsx("div",{style:{textAlign:"center",paddingTop:60,color:"#aaa",fontSize:15},children:r.loading}),!we&&p==="dashboard"&&a&&n.jsx(Oy,{incidents:z,ideas:C,orders:I,processes:O,organizations:P,incidentStatuses:gt,ideaStatuses:Y,orderStatuses:Yt,processStatuses:Bn,selectedOrg:b,onOrgChange:g,onNavigate:Ji,onNavigateStatus:m,userRole:i}),!we&&p==="inbox"&&n.jsx(h1,{onNavigate:Ji,onRefresh:At}),!we&&p==="reports"&&d&&n.jsx(v1,{organizations:P,userRole:i}),!we&&p==="incidents"&&n.jsx($y,{incidents:z,organizations:P,departments:le,branches:M,incidentStatuses:gt,initialOrg:b,initialStatus:S,onView:lh,onEdit:X?fh:void 0,onDelete:X?w=>He(B.incidents,w):void 0,canModify:X}),!we&&p==="ideas"&&n.jsx(Jy,{ideas:C,organizations:P,departments:le,branches:M,ideaStatuses:Y,initialOrg:b,initialStatus:S,onView:sh,onEdit:X?hh:void 0,onDelete:X?w=>He(B.ideas,w):void 0,canModify:X}),!we&&p==="orders"&&n.jsx(t0,{orders:I,organizations:P,departments:le,branches:M,orderStatuses:Yt,initialOrg:b,initialStatus:S,onView:rh,onEdit:X?gh:void 0,onDelete:X?w=>He(B.orders,w):void 0,canModify:X}),!we&&p==="processes"&&n.jsx(i0,{processes:O,organizations:P,departments:le,branches:M,processStatuses:Bn,initialOrg:b,initialStatus:S,onView:ih,onEdit:X?xh:void 0,onDelete:X?w=>He(B.processes,w):void 0,canModify:X}),!we&&p==="organizations"&&n.jsx(g0,{organizations:P,onView:ah,onEdit:X?mh:void 0,onDelete:X?w=>He(B.organizations,w):void 0,canModify:X}),!we&&p==="managements"&&n.jsx(y0,{managements:V,onView:oh,onEdit:X?yh:void 0,onDelete:X?w=>He(B.managements,w):void 0,canModify:X}),!we&&p==="departments"&&n.jsx(b0,{departments:le,managements:V,onView:ch,onEdit:X?vh:void 0,onDelete:X?w=>He(B.departments,w):void 0,canModify:X}),!we&&p==="branches"&&n.jsx(_0,{branches:M,managements:V,departments:le,onView:dh,onEdit:X?jh:void 0,onDelete:X?w=>He(B.branches,w):void 0,canModify:X}),!we&&p==="cycles"&&n.jsx(n1,{cycles:xr,canModify:X,onView:uh,onEdit:X?bh:void 0,onDelete:X?w=>He(B.cycles,w):void 0}),!we&&p==="kpi-input"&&n.jsx(i1,{kpiInputs:kc,canModify:X,onView:ph,onEdit:X?Sh:void 0,onDelete:X?w=>He(B.kpiInput,w):void 0}),!we&&p==="incident-types"&&n.jsx(P0,{incidentTypes:ne,onView:Ch,onEdit:X?zh:void 0,onDelete:X?w=>He(B.incidentTypes,w):void 0,canModify:X}),!we&&p==="idea-types"&&n.jsx(A0,{ideaTypes:he,onView:Th,onEdit:X?Ph:void 0,onDelete:X?w=>He(B.ideaTypes,w):void 0,canModify:X}),!we&&p==="order-types"&&n.jsx(O0,{orderTypes:J,onView:Ih,onEdit:X?Eh:void 0,onDelete:X?w=>He(B.orderTypes,w):void 0,canModify:X}),!we&&p==="process-types"&&n.jsx(W0,{processTypes:oe,onView:Ah,onEdit:X?Rh:void 0,onDelete:X?w=>He(B.processTypes,w):void 0,canModify:X}),!we&&p==="incident-statuses"&&n.jsx(U0,{incidentStatuses:gt,onView:Lh,onEdit:X?Oh:void 0,onDelete:X?w=>He(B.incidentStatuses,w):void 0,canModify:X}),!we&&p==="idea-statuses"&&n.jsx(H0,{ideaStatuses:Y,onView:Dh,onEdit:X?Nh:void 0,onDelete:X?w=>He(B.ideaStatuses,w):void 0,canModify:X}),!we&&p==="order-statuses"&&n.jsx(G0,{orderStatuses:Yt,onView:Wh,onEdit:X?Bh:void 0,onDelete:X?w=>He(B.orderStatuses,w):void 0,canModify:X}),!we&&p==="process-statuses"&&n.jsx(q0,{processStatuses:Bn,onView:$h,onEdit:X?Uh:void 0,onDelete:X?w=>He(B.processStatuses,w):void 0,canModify:X}),!we&&p==="users"&&n.jsx(e1,{users:$n,roleMap:Ge,onView:Fh,onEdit:X?Mh:void 0,onDelete:X?w=>He("User",w):void 0,onDisable:X?nh:void 0,canModify:X}),!we&&p==="delegations"&&u&&n.jsx(u1,{delegations:_c,organizations:P,userRole:i,currentUser:e.name,onView:wh,onRevoke:X?_h:void 0}),p==="profile"&&(()=>{const w=!!mr&&(mr.name===e.name||mr.email===e.name);return n.jsx(p0,{user:e,profileUser:mr,sbUsers:$n,organizations:P,managements:V,departments:le,branches:M,darkMode:l,canModify:X||w,onBack:()=>c(w?a?"dashboard":"inbox":"users"),onNavigate:c})})()]})]})]})}function C1(e){return e.some(t=>["SB Admin","System Manager"].includes(t))?"Admin":e.includes("SB Auditor")?"Auditor":e.includes("SB Owner")?"Owner":e.includes("SB X-Auditor")?"XAuditor":e.includes("SB Manager")?"Manager":"Employee"}function z1(){const[e,t]=j.useState(()=>{try{const d=localStorage.getItem("sidrah_user");return d?JSON.parse(d):null}catch{return null}}),[l,s]=j.useState(()=>localStorage.getItem("sb_dark")==="1"),r=()=>{const d=!l;s(d),localStorage.setItem("sb_dark",d?"1":"0"),document.documentElement.classList.toggle("dark",d)};j.useEffect(()=>{document.documentElement.classList.toggle("dark",l)},[]),j.useEffect(()=>{e&&Wf().then(async d=>{const u=d||e.name,f=await $f(u);if(!f.length)return;const y=C1(f),p=await fy();if(y!==e.role||u!==e.name||p!==(e.custom_organization||"")){const v={...e,name:u,role:y,custom_organization:p};t(v),localStorage.setItem("sidrah_user",JSON.stringify(v))}})},[e==null?void 0:e.name]);const i=d=>{t(d),localStorage.setItem("sidrah_user",JSON.stringify(d))},a=()=>{t(null),localStorage.removeItem("sidrah_user")};return e?n.jsx(_1,{user:e,onLogout:a,darkMode:l,onToggleDark:r}):n.jsx(Py,{onLogin:i})}Af(document.getElementById("root")).render(n.jsx(j.StrictMode,{children:n.jsx(z1,{})}));