(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function l(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=l(s);fetch(s.href,i)}})();var pu={exports:{}},Si={},fu={exports:{}},re={};/** * @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 es=Symbol.for("react.element"),ag=Symbol.for("react.portal"),og=Symbol.for("react.fragment"),cg=Symbol.for("react.strict_mode"),dg=Symbol.for("react.profiler"),ug=Symbol.for("react.provider"),pg=Symbol.for("react.context"),fg=Symbol.for("react.forward_ref"),hg=Symbol.for("react.suspense"),gg=Symbol.for("react.memo"),xg=Symbol.for("react.lazy"),Bc=Symbol.iterator;function mg(e){return e===null||typeof e!="object"?null:(e=Bc&&e[Bc]||e["@@iterator"],typeof e=="function"?e:null)}var hu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},gu=Object.assign,xu={};function Ul(e,t,l){this.props=e,this.context=t,this.refs=xu,this.updater=l||hu}Ul.prototype.isReactComponent={};Ul.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")};Ul.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function mu(){}mu.prototype=Ul.prototype;function So(e,t,l){this.props=e,this.context=t,this.refs=xu,this.updater=l||hu}var wo=So.prototype=new mu;wo.constructor=So;gu(wo,Ul.prototype);wo.isPureReactComponent=!0;var $c=Array.isArray,yu=Object.prototype.hasOwnProperty,ko={current:null},vu={key:!0,ref:!0,__self:!0,__source:!0};function ju(e,t,l){var r,s={},i=null,a=null;if(t!=null)for(r in t.ref!==void 0&&(a=t.ref),t.key!==void 0&&(i=""+t.key),t)yu.call(t,r)&&!vu.hasOwnProperty(r)&&(s[r]=t[r]);var c=arguments.length-2;if(c===1)s.children=l;else if(1>>1,M=A[q];if(0>>1;q<_e;){var R=2*(q+1)-1,Z=A[R],Te=R+1,Qe=A[Te];if(0>s(Z,H))Tes(Qe,Z)?(A[q]=Qe,A[Te]=H,q=Te):(A[q]=Z,A[R]=H,q=R);else if(Tes(Qe,H))A[q]=Qe,A[Te]=H,q=Te;else break e}}return $}function s(A,$){var H=A.sortIndex-$.sortIndex;return H!==0?H:A.id-$.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var a=Date,c=a.now();e.unstable_now=function(){return a.now()-c}}var u=[],h=[],f=1,p=null,d=3,g=!1,j=!1,m=!1,z=typeof setTimeout=="function"?setTimeout:null,y=typeof clearTimeout=="function"?clearTimeout:null,o=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function x(A){for(var $=l(h);$!==null;){if($.callback===null)r(h);else if($.startTime<=A)r(h),$.sortIndex=$.expirationTime,t(u,$);else break;$=l(h)}}function v(A){if(m=!1,x(A),!j)if(l(u)!==null)j=!0,ee(b);else{var $=l(h);$!==null&&de(v,$.startTime-A)}}function b(A,$){j=!1,m&&(m=!1,y(C),C=-1),g=!0;var H=d;try{for(x($),p=l(u);p!==null&&(!(p.expirationTime>$)||A&&!X());){var q=p.callback;if(typeof q=="function"){p.callback=null,d=p.priorityLevel;var M=q(p.expirationTime<=$);$=e.unstable_now(),typeof M=="function"?p.callback=M:p===l(u)&&r(u),x($)}else r(u);p=l(u)}if(p!==null)var _e=!0;else{var R=l(h);R!==null&&de(v,R.startTime-$),_e=!1}return _e}finally{p=null,d=H,g=!1}}var w=!1,k=null,C=-1,O=5,U=-1;function X(){return!(e.unstable_now()-UA||125q?(A.sortIndex=H,t(h,A),l(u)===null&&A===l(h)&&(m?(y(C),C=-1):m=!0,de(v,H-q))):(A.sortIndex=M,t(u,A),j||g||(j=!0,ee(b))),A},e.unstable_shouldYield=X,e.unstable_wrapCallback=function(A){var $=d;return function(){var H=d;d=$;try{return A.apply(this,arguments)}finally{d=H}}}})(_u);ku.exports=_u;var Tg=ku.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 Ig=S,mt=Tg;function B(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"),za=Object.prototype.hasOwnProperty,Pg=/^[: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]*$/,Fc={},Mc={};function Eg(e){return za.call(Mc,e)?!0:za.call(Fc,e)?!1:Pg.test(e)?Mc[e]=!0:(Fc[e]=!0,!1)}function Ag(e,t,l,r){if(l!==null&&l.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:l!==null?!l.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function Rg(e,t,l,r){if(t===null||typeof t>"u"||Ag(e,t,l,r))return!0;if(r)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 st(e,t,l,r,s,i,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=s,this.mustUseProperty=l,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=a}var Je={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Je[e]=new st(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Je[t]=new st(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Je[e]=new st(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Je[e]=new st(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){Je[e]=new st(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Je[e]=new st(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Je[e]=new st(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Je[e]=new st(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Je[e]=new st(e,5,!1,e.toLowerCase(),null,!1,!1)});var Co=/[\-:]([a-z])/g;function zo(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(Co,zo);Je[t]=new st(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(Co,zo);Je[t]=new st(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(Co,zo);Je[t]=new st(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Je[e]=new st(e,1,!1,e.toLowerCase(),null,!1,!1)});Je.xlinkHref=new st("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Je[e]=new st(e,1,!1,e.toLowerCase(),null,!0,!0)});function To(e,t,l,r){var s=Je.hasOwnProperty(t)?Je[t]:null;(s!==null?s.type!==0:r||!(2c||s[a]!==i[c]){var u=` `+s[a].replace(" at new "," at ");return e.displayName&&u.includes("")&&(u=u.replace("",e.displayName)),u}while(1<=a&&0<=c);break}}}finally{Ji=!1,Error.prepareStackTrace=l}return(e=e?e.displayName||e.name:"")?wr(e):""}function Lg(e){switch(e.tag){case 5:return wr(e.type);case 16:return wr("Lazy");case 13:return wr("Suspense");case 19:return wr("SuspenseList");case 0:case 2:case 15:return e=qi(e.type,!1),e;case 11:return e=qi(e.type.render,!1),e;case 1:return e=qi(e.type,!0),e;default:return""}}function Ea(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 hl:return"Fragment";case fl:return"Portal";case Ta:return"Profiler";case Io:return"StrictMode";case Ia:return"Suspense";case Pa:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Tu:return(e.displayName||"Context")+".Consumer";case zu:return(e._context.displayName||"Context")+".Provider";case Po:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Eo:return t=e.displayName||null,t!==null?t:Ea(e.type)||"Memo";case fn:t=e._payload,e=e._init;try{return Ea(e(t))}catch{}}return null}function Og(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 Ea(t);case 8:return t===Io?"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 Tn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Pu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Dg(e){var t=Pu(e)?"checked":"value",l=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof l<"u"&&typeof l.get=="function"&&typeof l.set=="function"){var s=l.get,i=l.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return s.call(this)},set:function(a){r=""+a,i.call(this,a)}}),Object.defineProperty(e,t,{enumerable:l.enumerable}),{getValue:function(){return r},setValue:function(a){r=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function xs(e){e._valueTracker||(e._valueTracker=Dg(e))}function Eu(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var l=t.getValue(),r="";return e&&(r=Pu(e)?e.checked?"true":"false":e.value),e=r,e!==l?(t.setValue(e),!0):!1}function qs(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 Aa(e,t){var l=t.checked;return Se({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:l??e._wrapperState.initialChecked})}function Kc(e,t){var l=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;l=Tn(t.value!=null?t.value:l),e._wrapperState={initialChecked:r,initialValue:l,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Au(e,t){t=t.checked,t!=null&&To(e,"checked",t,!1)}function Ra(e,t){Au(e,t);var l=Tn(t.value),r=t.type;if(l!=null)r==="number"?(l===0&&e.value===""||e.value!=l)&&(e.value=""+l):e.value!==""+l&&(e.value=""+l);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?La(e,t.type,l):t.hasOwnProperty("defaultValue")&&La(e,t.type,Tn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Qc(e,t,l){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="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 La(e,t,l){(t!=="number"||qs(e.ownerDocument)!==e)&&(l==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+l&&(e.defaultValue=""+l))}var kr=Array.isArray;function Cl(e,t,l,r){if(e=e.options,t){t={};for(var s=0;s"+t.valueOf().toString()+"",t=ms.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Wr(e,t){if(t){var l=e.firstChild;if(l&&l===e.lastChild&&l.nodeType===3){l.nodeValue=t;return}}e.textContent=t}var Tr={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},Ng=["Webkit","ms","Moz","O"];Object.keys(Tr).forEach(function(e){Ng.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Tr[t]=Tr[e]})});function Du(e,t,l){return t==null||typeof t=="boolean"||t===""?"":l||typeof t!="number"||t===0||Tr.hasOwnProperty(e)&&Tr[e]?(""+t).trim():t+"px"}function Nu(e,t){e=e.style;for(var l in t)if(t.hasOwnProperty(l)){var r=l.indexOf("--")===0,s=Du(l,t[l],r);l==="float"&&(l="cssFloat"),r?e.setProperty(l,s):e[l]=s}}var Wg=Se({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 Na(e,t){if(t){if(Wg[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(B(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(B(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(B(61))}if(t.style!=null&&typeof t.style!="object")throw Error(B(62))}}function Wa(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 Ba=null;function Ao(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var $a=null,zl=null,Tl=null;function Xc(e){if(e=ls(e)){if(typeof $a!="function")throw Error(B(280));var t=e.stateNode;t&&(t=zi(t),$a(e.stateNode,e.type,t))}}function Wu(e){zl?Tl?Tl.push(e):Tl=[e]:zl=e}function Bu(){if(zl){var e=zl,t=Tl;if(Tl=zl=null,Xc(e),t)for(e=0;e>>=0,e===0?32:31-(Xg(e)/Jg|0)|0}var ys=64,vs=4194304;function _r(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 ti(e,t){var l=e.pendingLanes;if(l===0)return 0;var r=0,s=e.suspendedLanes,i=e.pingedLanes,a=l&268435455;if(a!==0){var c=a&~s;c!==0?r=_r(c):(i&=a,i!==0&&(r=_r(i)))}else a=l&~s,a!==0?r=_r(a):i!==0&&(r=_r(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&s)&&(s=r&-r,i=t&-t,s>=i||s===16&&(i&4194240)!==0))return t;if(r&4&&(r|=l&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0l;l++)t.push(e);return t}function ts(e,t,l){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-At(t),e[t]=l}function ex(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 r=e.eventTimes;for(e=e.expirationTimes;0=Pr),rd=" ",sd=!1;function sp(e,t){switch(e){case"keyup":return Tx.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function ip(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var gl=!1;function Px(e,t){switch(e){case"compositionend":return ip(t);case"keypress":return t.which!==32?null:(sd=!0,rd);case"textInput":return e=t.data,e===rd&&sd?null:e;default:return null}}function Ex(e,t){if(gl)return e==="compositionend"||!$o&&sp(e,t)?(e=lp(),Fs=No=mn=null,gl=!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=r}e:{for(;l;){if(l.nextSibling){l=l.nextSibling;break e}l=l.parentNode}l=void 0}l=cd(l)}}function dp(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?dp(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function up(){for(var e=window,t=qs();t instanceof e.HTMLIFrameElement;){try{var l=typeof t.contentWindow.location.href=="string"}catch{l=!1}if(l)e=t.contentWindow;else break;t=qs(e.document)}return t}function Uo(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 $x(e){var t=up(),l=e.focusedElem,r=e.selectionRange;if(t!==l&&l&&l.ownerDocument&&dp(l.ownerDocument.documentElement,l)){if(r!==null&&Uo(l)){if(t=r.start,e=r.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 s=l.textContent.length,i=Math.min(r.start,s);r=r.end===void 0?i:Math.min(r.end,s),!e.extend&&i>r&&(s=r,r=i,i=s),s=dd(l,i);var a=dd(l,r);s&&a&&(e.rangeCount!==1||e.anchorNode!==s.node||e.anchorOffset!==s.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(s.node,s.offset),e.removeAllRanges(),i>r?(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,xl=null,Qa=null,Ar=null,Ya=!1;function ud(e,t,l){var r=l.window===l?l.document:l.nodeType===9?l:l.ownerDocument;Ya||xl==null||xl!==qs(r)||(r=xl,"selectionStart"in r&&Uo(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Ar&&Hr(Ar,r)||(Ar=r,r=ri(Qa,"onSelect"),0vl||(e.current=Va[vl],Va[vl]=null,vl--)}function he(e,t){vl++,Va[vl]=e.current,e.current=t}var In={},et=An(In),ct=An(!1),Hn=In;function Rl(e,t){var l=e.type.contextTypes;if(!l)return In;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var s={},i;for(i in l)s[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=s),s}function dt(e){return e=e.childContextTypes,e!=null}function ii(){xe(ct),xe(et)}function yd(e,t,l){if(et.current!==In)throw Error(B(168));he(et,t),he(ct,l)}function jp(e,t,l){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return l;r=r.getChildContext();for(var s in r)if(!(s in t))throw Error(B(108,Og(e)||"Unknown",s));return Se({},l,r)}function ai(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||In,Hn=et.current,he(et,e),he(ct,ct.current),!0}function vd(e,t,l){var r=e.stateNode;if(!r)throw Error(B(169));l?(e=jp(e,t,Hn),r.__reactInternalMemoizedMergedChildContext=e,xe(ct),xe(et),he(et,e)):xe(ct),he(ct,l)}var qt=null,Ti=!1,ua=!1;function bp(e){qt===null?qt=[e]:qt.push(e)}function Zx(e){Ti=!0,bp(e)}function Rn(){if(!ua&&qt!==null){ua=!0;var e=0,t=ue;try{var l=qt;for(ue=1;e>=a,s-=a,Zt=1<<32-At(t)+s|l<C?(O=k,k=null):O=k.sibling;var U=d(y,k,x[C],v);if(U===null){k===null&&(k=O);break}e&&k&&U.alternate===null&&t(y,k),o=i(U,o,C),w===null?b=U:w.sibling=U,w=U,k=O}if(C===x.length)return l(y,k),ve&&Nn(y,C),b;if(k===null){for(;CC?(O=k,k=null):O=k.sibling;var X=d(y,k,U.value,v);if(X===null){k===null&&(k=O);break}e&&k&&X.alternate===null&&t(y,k),o=i(X,o,C),w===null?b=X:w.sibling=X,w=X,k=O}if(U.done)return l(y,k),ve&&Nn(y,C),b;if(k===null){for(;!U.done;C++,U=x.next())U=p(y,U.value,v),U!==null&&(o=i(U,o,C),w===null?b=U:w.sibling=U,w=U);return ve&&Nn(y,C),b}for(k=r(y,k);!U.done;C++,U=x.next())U=g(k,y,C,U.value,v),U!==null&&(e&&U.alternate!==null&&k.delete(U.key===null?C:U.key),o=i(U,o,C),w===null?b=U:w.sibling=U,w=U);return e&&k.forEach(function(V){return t(y,V)}),ve&&Nn(y,C),b}function z(y,o,x,v){if(typeof x=="object"&&x!==null&&x.type===hl&&x.key===null&&(x=x.props.children),typeof x=="object"&&x!==null){switch(x.$$typeof){case gs:e:{for(var b=x.key,w=o;w!==null;){if(w.key===b){if(b=x.type,b===hl){if(w.tag===7){l(y,w.sibling),o=s(w,x.props.children),o.return=y,y=o;break e}}else if(w.elementType===b||typeof b=="object"&&b!==null&&b.$$typeof===fn&&Sd(b)===w.type){l(y,w.sibling),o=s(w,x.props),o.ref=or(y,w,x),o.return=y,y=o;break e}l(y,w);break}else t(y,w);w=w.sibling}x.type===hl?(o=Mn(x.props.children,y.mode,v,x.key),o.return=y,y=o):(v=Js(x.type,x.key,x.props,null,y.mode,v),v.ref=or(y,o,x),v.return=y,y=v)}return a(y);case fl:e:{for(w=x.key;o!==null;){if(o.key===w)if(o.tag===4&&o.stateNode.containerInfo===x.containerInfo&&o.stateNode.implementation===x.implementation){l(y,o.sibling),o=s(o,x.children||[]),o.return=y,y=o;break e}else{l(y,o);break}else t(y,o);o=o.sibling}o=va(x,y.mode,v),o.return=y,y=o}return a(y);case fn:return w=x._init,z(y,o,w(x._payload),v)}if(kr(x))return j(y,o,x,v);if(lr(x))return m(y,o,x,v);Cs(y,x)}return typeof x=="string"&&x!==""||typeof x=="number"?(x=""+x,o!==null&&o.tag===6?(l(y,o.sibling),o=s(o,x),o.return=y,y=o):(l(y,o),o=ya(x,y.mode,v),o.return=y,y=o),a(y)):l(y,o)}return z}var Ol=_p(!0),Cp=_p(!1),di=An(null),ui=null,Sl=null,Ko=null;function Qo(){Ko=Sl=ui=null}function Yo(e){var t=di.current;xe(di),e._currentValue=t}function no(e,t,l){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===l)break;e=e.return}}function Pl(e,t){ui=e,Ko=Sl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(ot=!0),e.firstContext=null)}function kt(e){var t=e._currentValue;if(Ko!==e)if(e={context:e,memoizedValue:t,next:null},Sl===null){if(ui===null)throw Error(B(308));Sl=e,ui.dependencies={lanes:0,firstContext:e}}else Sl=Sl.next=e;return t}var $n=null;function Go(e){$n===null?$n=[e]:$n.push(e)}function zp(e,t,l,r){var s=t.interleaved;return s===null?(l.next=l,Go(t)):(l.next=s.next,s.next=l),t.interleaved=l,ln(e,r)}function ln(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 hn=!1;function Xo(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Tp(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 en(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function kn(e,t,l){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,oe&2){var s=r.pending;return s===null?t.next=t:(t.next=s.next,s.next=t),r.pending=t,ln(e,l)}return s=r.interleaved,s===null?(t.next=t,Go(r)):(t.next=s.next,s.next=t),r.interleaved=t,ln(e,l)}function Hs(e,t,l){if(t=t.updateQueue,t!==null&&(t=t.shared,(l&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,l|=r,t.lanes=l,Lo(e,l)}}function wd(e,t){var l=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,l===r)){var s=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?s=i=a:i=i.next=a,l=l.next}while(l!==null);i===null?s=i=t:i=i.next=t}else s=i=t;l={baseState:r.baseState,firstBaseUpdate:s,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=l;return}e=l.lastBaseUpdate,e===null?l.firstBaseUpdate=t:e.next=t,l.lastBaseUpdate=t}function pi(e,t,l,r){var s=e.updateQueue;hn=!1;var i=s.firstBaseUpdate,a=s.lastBaseUpdate,c=s.shared.pending;if(c!==null){s.shared.pending=null;var u=c,h=u.next;u.next=null,a===null?i=h:a.next=h,a=u;var f=e.alternate;f!==null&&(f=f.updateQueue,c=f.lastBaseUpdate,c!==a&&(c===null?f.firstBaseUpdate=h:c.next=h,f.lastBaseUpdate=u))}if(i!==null){var p=s.baseState;a=0,f=h=u=null,c=i;do{var d=c.lane,g=c.eventTime;if((r&d)===d){f!==null&&(f=f.next={eventTime:g,lane:0,tag:c.tag,payload:c.payload,callback:c.callback,next:null});e:{var j=e,m=c;switch(d=t,g=l,m.tag){case 1:if(j=m.payload,typeof j=="function"){p=j.call(g,p,d);break e}p=j;break e;case 3:j.flags=j.flags&-65537|128;case 0:if(j=m.payload,d=typeof j=="function"?j.call(g,p,d):j,d==null)break e;p=Se({},p,d);break e;case 2:hn=!0}}c.callback!==null&&c.lane!==0&&(e.flags|=64,d=s.effects,d===null?s.effects=[c]:d.push(c))}else g={eventTime:g,lane:d,tag:c.tag,payload:c.payload,callback:c.callback,next:null},f===null?(h=f=g,u=p):f=f.next=g,a|=d;if(c=c.next,c===null){if(c=s.shared.pending,c===null)break;d=c,c=d.next,d.next=null,s.lastBaseUpdate=d,s.shared.pending=null}}while(!0);if(f===null&&(u=p),s.baseState=u,s.firstBaseUpdate=h,s.lastBaseUpdate=f,t=s.shared.interleaved,t!==null){s=t;do a|=s.lane,s=s.next;while(s!==t)}else i===null&&(s.shared.lanes=0);Yn|=a,e.lanes=a,e.memoizedState=p}}function kd(e,t,l){if(e=t.effects,t.effects=null,e!==null)for(t=0;tl?l:4,e(!0);var r=fa.transition;fa.transition={};try{e(!1),t()}finally{ue=l,fa.transition=r}}function Kp(){return _t().memoizedState}function nm(e,t,l){var r=Cn(e);if(l={lane:r,action:l,hasEagerState:!1,eagerState:null,next:null},Qp(e))Yp(t,l);else if(l=zp(e,t,l,r),l!==null){var s=lt();Rt(l,e,r,s),Gp(l,t,r)}}function lm(e,t,l){var r=Cn(e),s={lane:r,action:l,hasEagerState:!1,eagerState:null,next:null};if(Qp(e))Yp(t,s);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var a=t.lastRenderedState,c=i(a,l);if(s.hasEagerState=!0,s.eagerState=c,Lt(c,a)){var u=t.interleaved;u===null?(s.next=s,Go(t)):(s.next=u.next,u.next=s),t.interleaved=s;return}}catch{}finally{}l=zp(e,t,s,r),l!==null&&(s=lt(),Rt(l,e,r,s),Gp(l,t,r))}}function Qp(e){var t=e.alternate;return e===be||t!==null&&t===be}function Yp(e,t){Rr=hi=!0;var l=e.pending;l===null?t.next=t:(t.next=l.next,l.next=t),e.pending=t}function Gp(e,t,l){if(l&4194240){var r=t.lanes;r&=e.pendingLanes,l|=r,t.lanes=l,Lo(e,l)}}var gi={readContext:kt,useCallback:qe,useContext:qe,useEffect:qe,useImperativeHandle:qe,useInsertionEffect:qe,useLayoutEffect:qe,useMemo:qe,useReducer:qe,useRef:qe,useState:qe,useDebugValue:qe,useDeferredValue:qe,useTransition:qe,useMutableSource:qe,useSyncExternalStore:qe,useId:qe,unstable_isNewReconciler:!1},rm={readContext:kt,useCallback:function(e,t){return Wt().memoizedState=[e,t===void 0?null:t],e},useContext:kt,useEffect:Cd,useImperativeHandle:function(e,t,l){return l=l!=null?l.concat([e]):null,Qs(4194308,4,$p.bind(null,t,e),l)},useLayoutEffect:function(e,t){return Qs(4194308,4,e,t)},useInsertionEffect:function(e,t){return Qs(4,2,e,t)},useMemo:function(e,t){var l=Wt();return t=t===void 0?null:t,e=e(),l.memoizedState=[e,t],e},useReducer:function(e,t,l){var r=Wt();return t=l!==void 0?l(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=nm.bind(null,be,e),[r.memoizedState,e]},useRef:function(e){var t=Wt();return e={current:e},t.memoizedState=e},useState:_d,useDebugValue:lc,useDeferredValue:function(e){return Wt().memoizedState=e},useTransition:function(){var e=_d(!1),t=e[0];return e=tm.bind(null,e[1]),Wt().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,l){var r=be,s=Wt();if(ve){if(l===void 0)throw Error(B(407));l=l()}else{if(l=t(),He===null)throw Error(B(349));Qn&30||Ap(r,t,l)}s.memoizedState=l;var i={value:l,getSnapshot:t};return s.queue=i,Cd(Lp.bind(null,r,i,e),[e]),r.flags|=2048,Zr(9,Rp.bind(null,r,i,l,t),void 0,null),l},useId:function(){var e=Wt(),t=He.identifierPrefix;if(ve){var l=Vt,r=Zt;l=(r&~(1<<32-At(r)-1)).toString(32)+l,t=":"+t+"R"+l,l=Jr++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=a.createElement(l,{is:r.is}):(e=a.createElement(l),l==="select"&&(a=e,r.multiple?a.multiple=!0:r.size&&(a.size=r.size))):e=a.createElementNS(e,l),e[Bt]=t,e[Yr]=r,rf(e,t,!1,!1),t.stateNode=e;e:{switch(a=Wa(l,r),l){case"dialog":ge("cancel",e),ge("close",e),s=r;break;case"iframe":case"object":case"embed":ge("load",e),s=r;break;case"video":case"audio":for(s=0;sWl&&(t.flags|=128,r=!0,cr(i,!1),t.lanes=4194304)}else{if(!r)if(e=fi(a),e!==null){if(t.flags|=128,r=!0,l=e.updateQueue,l!==null&&(t.updateQueue=l,t.flags|=4),cr(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!ve)return Ze(t),null}else 2*ze()-i.renderingStartTime>Wl&&l!==1073741824&&(t.flags|=128,r=!0,cr(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=ze(),t.sibling=null,l=je.current,he(je,r?l&1|2:l&1),t):(Ze(t),null);case 22:case 23:return cc(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?ht&1073741824&&(Ze(t),t.subtreeFlags&6&&(t.flags|=8192)):Ze(t),null;case 24:return null;case 25:return null}throw Error(B(156,t.tag))}function pm(e,t){switch(Mo(t),t.tag){case 1:return dt(t.type)&&ii(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Dl(),xe(ct),xe(et),Zo(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return qo(t),null;case 13:if(xe(je),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(B(340));Ll()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return xe(je),null;case 4:return Dl(),null;case 10:return Yo(t.type._context),null;case 22:case 23:return cc(),null;case 24:return null;default:return null}}var Ts=!1,Ve=!1,fm=typeof WeakSet=="function"?WeakSet:Set,K=null;function wl(e,t){var l=e.ref;if(l!==null)if(typeof l=="function")try{l(null)}catch(r){we(e,t,r)}else l.current=null}function po(e,t,l){try{l()}catch(r){we(e,t,r)}}var Nd=!1;function hm(e,t){if(Ga=ni,e=up(),Uo(e)){if("selectionStart"in e)var l={start:e.selectionStart,end:e.selectionEnd};else e:{l=(l=e.ownerDocument)&&l.defaultView||window;var r=l.getSelection&&l.getSelection();if(r&&r.rangeCount!==0){l=r.anchorNode;var s=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{l.nodeType,i.nodeType}catch{l=null;break e}var a=0,c=-1,u=-1,h=0,f=0,p=e,d=null;t:for(;;){for(var g;p!==l||s!==0&&p.nodeType!==3||(c=a+s),p!==i||r!==0&&p.nodeType!==3||(u=a+r),p.nodeType===3&&(a+=p.nodeValue.length),(g=p.firstChild)!==null;)d=p,p=g;for(;;){if(p===e)break t;if(d===l&&++h===s&&(c=a),d===i&&++f===r&&(u=a),(g=p.nextSibling)!==null)break;p=d,d=p.parentNode}p=g}l=c===-1||u===-1?null:{start:c,end:u}}else l=null}l=l||{start:0,end:0}}else l=null;for(Xa={focusedElem:e,selectionRange:l},ni=!1,K=t;K!==null;)if(t=K,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,K=e;else for(;K!==null;){t=K;try{var j=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(j!==null){var m=j.memoizedProps,z=j.memoizedState,y=t.stateNode,o=y.getSnapshotBeforeUpdate(t.elementType===t.type?m:Tt(t.type,m),z);y.__reactInternalSnapshotBeforeUpdate=o}break;case 3:var x=t.stateNode.containerInfo;x.nodeType===1?x.textContent="":x.nodeType===9&&x.documentElement&&x.removeChild(x.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(B(163))}}catch(v){we(t,t.return,v)}if(e=t.sibling,e!==null){e.return=t.return,K=e;break}K=t.return}return j=Nd,Nd=!1,j}function Lr(e,t,l){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var s=r=r.next;do{if((s.tag&e)===e){var i=s.destroy;s.destroy=void 0,i!==void 0&&po(t,l,i)}s=s.next}while(s!==r)}}function Ei(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 r=l.create;l.destroy=r()}l=l.next}while(l!==t)}}function fo(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 of(e){var t=e.alternate;t!==null&&(e.alternate=null,of(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Bt],delete t[Yr],delete t[Za],delete t[Jx],delete t[qx])),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 cf(e){return e.tag===5||e.tag===3||e.tag===4}function Wd(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||cf(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 ho(e,t,l){var r=e.tag;if(r===5||r===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=si));else if(r!==4&&(e=e.child,e!==null))for(ho(e,t,l),e=e.sibling;e!==null;)ho(e,t,l),e=e.sibling}function go(e,t,l){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?l.insertBefore(e,t):l.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(go(e,t,l),e=e.sibling;e!==null;)go(e,t,l),e=e.sibling}var Ge=null,It=!1;function un(e,t,l){for(l=l.child;l!==null;)df(e,t,l),l=l.sibling}function df(e,t,l){if($t&&typeof $t.onCommitFiberUnmount=="function")try{$t.onCommitFiberUnmount(wi,l)}catch{}switch(l.tag){case 5:Ve||wl(l,t);case 6:var r=Ge,s=It;Ge=null,un(e,t,l),Ge=r,It=s,Ge!==null&&(It?(e=Ge,l=l.stateNode,e.nodeType===8?e.parentNode.removeChild(l):e.removeChild(l)):Ge.removeChild(l.stateNode));break;case 18:Ge!==null&&(It?(e=Ge,l=l.stateNode,e.nodeType===8?da(e.parentNode,l):e.nodeType===1&&da(e,l),Fr(e)):da(Ge,l.stateNode));break;case 4:r=Ge,s=It,Ge=l.stateNode.containerInfo,It=!0,un(e,t,l),Ge=r,It=s;break;case 0:case 11:case 14:case 15:if(!Ve&&(r=l.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){s=r=r.next;do{var i=s,a=i.destroy;i=i.tag,a!==void 0&&(i&2||i&4)&&po(l,t,a),s=s.next}while(s!==r)}un(e,t,l);break;case 1:if(!Ve&&(wl(l,t),r=l.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=l.memoizedProps,r.state=l.memoizedState,r.componentWillUnmount()}catch(c){we(l,t,c)}un(e,t,l);break;case 21:un(e,t,l);break;case 22:l.mode&1?(Ve=(r=Ve)||l.memoizedState!==null,un(e,t,l),Ve=r):un(e,t,l);break;default:un(e,t,l)}}function Bd(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var l=e.stateNode;l===null&&(l=e.stateNode=new fm),t.forEach(function(r){var s=wm.bind(null,e,r);l.has(r)||(l.add(r),r.then(s,s))})}}function zt(e,t){var l=t.deletions;if(l!==null)for(var r=0;rs&&(s=a),r&=~i}if(r=s,r=ze()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*xm(r/1960))-r,10e?16:e,yn===null)var r=!1;else{if(e=yn,yn=null,yi=0,oe&6)throw Error(B(331));var s=oe;for(oe|=4,K=e.current;K!==null;){var i=K,a=i.child;if(K.flags&16){var c=i.deletions;if(c!==null){for(var u=0;uze()-ac?Fn(e,0):ic|=l),ut(e,t)}function yf(e,t){t===0&&(e.mode&1?(t=vs,vs<<=1,!(vs&130023424)&&(vs=4194304)):t=1);var l=lt();e=ln(e,t),e!==null&&(ts(e,t,l),ut(e,l))}function Sm(e){var t=e.memoizedState,l=0;t!==null&&(l=t.retryLane),yf(e,l)}function wm(e,t){var l=0;switch(e.tag){case 13:var r=e.stateNode,s=e.memoizedState;s!==null&&(l=s.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(B(314))}r!==null&&r.delete(t),yf(e,l)}var vf;vf=function(e,t,l){if(e!==null)if(e.memoizedProps!==t.pendingProps||ct.current)ot=!0;else{if(!(e.lanes&l)&&!(t.flags&128))return ot=!1,dm(e,t,l);ot=!!(e.flags&131072)}else ot=!1,ve&&t.flags&1048576&&Sp(t,ci,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Ys(e,t),e=t.pendingProps;var s=Rl(t,et.current);Pl(t,l),s=ec(null,t,r,e,s,l);var i=tc();return t.flags|=1,typeof s=="object"&&s!==null&&typeof s.render=="function"&&s.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,dt(r)?(i=!0,ai(t)):i=!1,t.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,Xo(t),s.updater=Pi,t.stateNode=s,s._reactInternals=t,ro(t,r,e,l),t=ao(null,t,r,!0,i,l)):(t.tag=0,ve&&i&&Fo(t),nt(null,t,s,l),t=t.child),t;case 16:r=t.elementType;e:{switch(Ys(e,t),e=t.pendingProps,s=r._init,r=s(r._payload),t.type=r,s=t.tag=_m(r),e=Tt(r,e),s){case 0:t=io(null,t,r,e,l);break e;case 1:t=Ld(null,t,r,e,l);break e;case 11:t=Ad(null,t,r,e,l);break e;case 14:t=Rd(null,t,r,Tt(r.type,e),l);break e}throw Error(B(306,r,""))}return t;case 0:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Tt(r,s),io(e,t,r,s,l);case 1:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Tt(r,s),Ld(e,t,r,s,l);case 3:e:{if(tf(t),e===null)throw Error(B(387));r=t.pendingProps,i=t.memoizedState,s=i.element,Tp(e,t),pi(t,r,null,l);var a=t.memoizedState;if(r=a.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){s=Nl(Error(B(423)),t),t=Od(e,t,r,l,s);break e}else if(r!==s){s=Nl(Error(B(424)),t),t=Od(e,t,r,l,s);break e}else for(gt=wn(t.stateNode.containerInfo.firstChild),xt=t,ve=!0,Pt=null,l=Cp(t,null,r,l),t.child=l;l;)l.flags=l.flags&-3|4096,l=l.sibling;else{if(Ll(),r===s){t=rn(e,t,l);break e}nt(e,t,r,l)}t=t.child}return t;case 5:return Ip(t),e===null&&to(t),r=t.type,s=t.pendingProps,i=e!==null?e.memoizedProps:null,a=s.children,Ja(r,s)?a=null:i!==null&&Ja(r,i)&&(t.flags|=32),ef(e,t),nt(e,t,a,l),t.child;case 6:return e===null&&to(t),null;case 13:return nf(e,t,l);case 4:return Jo(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Ol(t,null,r,l):nt(e,t,r,l),t.child;case 11:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Tt(r,s),Ad(e,t,r,s,l);case 7:return nt(e,t,t.pendingProps,l),t.child;case 8:return nt(e,t,t.pendingProps.children,l),t.child;case 12:return nt(e,t,t.pendingProps.children,l),t.child;case 10:e:{if(r=t.type._context,s=t.pendingProps,i=t.memoizedProps,a=s.value,he(di,r._currentValue),r._currentValue=a,i!==null)if(Lt(i.value,a)){if(i.children===s.children&&!ct.current){t=rn(e,t,l);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var c=i.dependencies;if(c!==null){a=i.child;for(var u=c.firstContext;u!==null;){if(u.context===r){if(i.tag===1){u=en(-1,l&-l),u.tag=2;var h=i.updateQueue;if(h!==null){h=h.shared;var f=h.pending;f===null?u.next=u:(u.next=f.next,f.next=u),h.pending=u}}i.lanes|=l,u=i.alternate,u!==null&&(u.lanes|=l),no(i.return,l,t),c.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(B(341));a.lanes|=l,c=a.alternate,c!==null&&(c.lanes|=l),no(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}nt(e,t,s.children,l),t=t.child}return t;case 9:return s=t.type,r=t.pendingProps.children,Pl(t,l),s=kt(s),r=r(s),t.flags|=1,nt(e,t,r,l),t.child;case 14:return r=t.type,s=Tt(r,t.pendingProps),s=Tt(r.type,s),Rd(e,t,r,s,l);case 15:return Zp(e,t,t.type,t.pendingProps,l);case 17:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Tt(r,s),Ys(e,t),t.tag=1,dt(r)?(e=!0,ai(t)):e=!1,Pl(t,l),Xp(t,r,s),ro(t,r,s,l),ao(null,t,r,!0,e,l);case 19:return lf(e,t,l);case 22:return Vp(e,t,l)}throw Error(B(156,t.tag))};function jf(e,t){return Qu(e,t)}function km(e,t,l,r){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=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function St(e,t,l,r){return new km(e,t,l,r)}function uc(e){return e=e.prototype,!(!e||!e.isReactComponent)}function _m(e){if(typeof e=="function")return uc(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Po)return 11;if(e===Eo)return 14}return 2}function zn(e,t){var l=e.alternate;return l===null?(l=St(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 Js(e,t,l,r,s,i){var a=2;if(r=e,typeof e=="function")uc(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case hl:return Mn(l.children,s,i,t);case Io:a=8,s|=8;break;case Ta:return e=St(12,l,t,s|2),e.elementType=Ta,e.lanes=i,e;case Ia:return e=St(13,l,t,s),e.elementType=Ia,e.lanes=i,e;case Pa:return e=St(19,l,t,s),e.elementType=Pa,e.lanes=i,e;case Iu:return Ri(l,s,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case zu:a=10;break e;case Tu:a=9;break e;case Po:a=11;break e;case Eo:a=14;break e;case fn:a=16,r=null;break e}throw Error(B(130,e==null?e:typeof e,""))}return t=St(a,l,t,s),t.elementType=e,t.type=r,t.lanes=i,t}function Mn(e,t,l,r){return e=St(7,e,r,t),e.lanes=l,e}function Ri(e,t,l,r){return e=St(22,e,r,t),e.elementType=Iu,e.lanes=l,e.stateNode={isHidden:!1},e}function ya(e,t,l){return e=St(6,e,null,t),e.lanes=l,e}function va(e,t,l){return t=St(4,e.children!==null?e.children:[],e.key,t),t.lanes=l,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Cm(e,t,l,r,s){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=Vi(0),this.expirationTimes=Vi(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Vi(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function pc(e,t,l,r,s,i,a,c,u){return e=new Cm(e,t,l,c,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=St(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:l,cache:null,transitions:null,pendingSuspenseBoundaries:null},Xo(i),e}function zm(e,t,l){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(kf)}catch(e){console.error(e)}}kf(),wu.exports=yt;var Am=wu.exports,_f,Yd=Am;_f=Yd.createRoot,Yd.hydrateRoot;const se="",D={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"},N={bg:"#f5f6fa",accent:"#4f46e5",red:"#ef4444",orange:"#f59e0b",green:"#16a34a",purple:"#7c3aed",blue:"#2563eb",teal:"#0d9488",gray:"#94a3b8"},Cf=[{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"}],Rm=[{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"}],Lm=new Set(["users"]);function zf(e){return e!=="Admin"&&e!=="Auditor"?[]:Rm.filter(({id:t})=>e==="Admin"||!Lm.has(t))}const pn=(e=[])=>[{key:"name1",label:"Name"},{key:"status",label:"Status"},...e,{key:"creation_date",label:"Created On"}],Om={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:pn(),defaultColumns:["name1","status","creation_date"]},"idea-types":{label:"Idea Types",columns:pn(),defaultColumns:["name1","status","creation_date"]},"order-types":{label:"Order Types",columns:pn(),defaultColumns:["name1","status","creation_date"]},"process-types":{label:"Process Types",columns:pn(),defaultColumns:["name1","status","creation_date"]},"incident-statuses":{label:"Incident Statuses",columns:pn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"idea-statuses":{label:"Idea Statuses",columns:pn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"order-statuses":{label:"Order Statuses",columns:pn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"process-statuses":{label:"Process Statuses",columns:pn([{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"]}},Dm="modulepreload",Nm=function(e){return"/"+e},Gd={},Wm=function(t,l,r){let s=Promise.resolve();if(l&&l.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),c=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));s=Promise.allSettled(l.map(u=>{if(u=Nm(u),u in Gd)return;Gd[u]=!0;const h=u.endsWith(".css"),f=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":Dm,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((d,g)=>{p.addEventListener("load",d),p.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(a){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=a,window.dispatchEvent(c),!c.defaultPrevented)throw a}return s.then(a=>{for(const c of a||[])c.status==="rejected"&&i(c.reason);return t().catch(i)})};function Tf(e,t){const l=e[t.key];return l==null||l===""?"":typeof l=="object"?JSON.stringify(l):String(l)}function Bm(e,t){const l=URL.createObjectURL(e),r=document.createElement("a");r.href=l,r.download=t,r.click(),URL.revokeObjectURL(l)}function $m(e,t,l){const r=e.map(a=>`"${a.label.replace(/"/g,'""')}"`).join(","),s=t.map(a=>e.map(c=>`"${Tf(a,c).replace(/"/g,'""')}"`).join(",")).join(` `),i=new Blob([r+` `+s],{type:"text/csv;charset=utf-8;"});Bm(i,`${l}.csv`)}async function Um(e,t,l){const r=await Wm(()=>import("./xlsx-D_0l8YDs.js"),[]),s=t.map(c=>{const u={};for(const h of e)u[h.label]=Tf(c,h);return u}),i=r.utils.json_to_sheet(s,{header:e.map(c=>c.label)}),a=r.utils.book_new();r.utils.book_append_sheet(a,i,"Export"),r.writeFile(a,`${l}.xlsx`)}const Es="#16a34a";function Fm({title:e,rows:t,columns:l,defaultColumnKeys:r,orgField:s,organizations:i,filenameBase:a,onClose:c}){const[u,h]=S.useState(""),[f,p]=S.useState("csv"),[d,g]=S.useState(new Set(r)),j=u?t.filter(v=>v[s||"organization"]===u):t,m=l.filter(v=>d.has(v.key)),z=v=>{g(b=>{const w=new Set(b);return w.has(v)?w.delete(v):w.add(v),w})},y=async()=>{m.length===0||j.length===0||(f==="csv"?$m(m,j,a):await Um(m,j,a),c())},o={fontSize:11,fontWeight:700,color:"#9ca3af",letterSpacing:.4,textTransform:"uppercase",marginBottom:10},x={background:"none",border:"none",color:"#2563eb",fontSize:12,fontWeight:600,cursor:"pointer",padding:0,fontFamily:"inherit"};return n.jsx("div",{onClick:c,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:v=>v.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:Es,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:c,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:[s&&i&&i.length>0&&n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:o,children:"Filter by Organization"}),n.jsxs("select",{value:u,onChange:v=>h(v.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(v=>n.jsx("option",{value:v.name,children:v.organization_name||v.name},v.name))]})]}),n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:o,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(v=>n.jsxs("div",{onClick:()=>p(v.id),style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",borderRadius:10,cursor:"pointer",border:`2px solid ${f===v.id?Es:"#e5e7eb"}`,background:f===v.id?"#f0fdf4":"white"},children:[n.jsx("span",{style:{fontSize:20},children:v.id==="csv"?"📄":"📊"}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:v.label}),n.jsx("div",{style:{fontSize:11,color:"#888"},children:v.desc})]})]},v.id))})]}),n.jsxs("div",{children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[n.jsx("div",{style:{...o,marginBottom:0},children:"Columns to Export"}),n.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[n.jsx("button",{onClick:()=>g(new Set(l.map(v=>v.key))),style:x,children:"Select All"}),n.jsx("span",{style:{color:"#d1d5db"},children:"|"}),n.jsx("button",{onClick:()=>g(new Set(r)),style:x,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(v=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:7,fontSize:13,color:"#374151",cursor:"pointer"},children:[n.jsx("input",{type:"checkbox",checked:d.has(v.key),onChange:()=>z(v.key),style:{accentColor:Es,cursor:"pointer"}}),v.label]},v.key))})}),n.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:6},children:[d.size," column",d.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 ${j.length} filtered row${j.length!==1?"s":""}`:`Exporting all ${j.length} row${j.length!==1?"s":""}`}),n.jsxs("div",{style:{display:"flex",gap:10},children:[n.jsx("button",{onClick:c,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:y,disabled:m.length===0||j.length===0,style:{padding:"9px 20px",borderRadius:8,border:"none",background:Es,color:"white",fontWeight:700,fontSize:13,cursor:m.length===0||j.length===0?"not-allowed":"pointer",opacity:m.length===0||j.length===0?.5:1,fontFamily:"inherit",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"})]})]})]})})}const If="sidrah_rtl",jo="sidrah-lang-change";function _l(){try{return localStorage.getItem(If)==="1"}catch{return!1}}function Pf(){const e=!_l();try{localStorage.setItem(If,e?"1":"0")}catch{}document.documentElement.setAttribute("dir",e?"rtl":"ltr"),document.documentElement.setAttribute("lang",e?"ar":"en-GB"),window.dispatchEvent(new CustomEvent(jo))}function J(){const[e,t]=S.useState(_l);return S.useEffect(()=>{const l=()=>t(_l());return window.addEventListener(jo,l),document.documentElement.setAttribute("dir",_l()?"rtl":"ltr"),document.documentElement.setAttribute("lang",_l()?"ar":"en-GB"),()=>window.removeEventListener(jo,l)},[]),e?Hm:Mm}const Mm={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"}},Hm={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:"بواسطة"}},ss=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 Xn="";async function xc(){try{const e=await fetch(`${se}/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 Xn=l,l}}catch(e){console.error("CSRF fetch error:",e)}return Xn}async function an(){return Xn||await xc(),Xn}function Xd(e,t){try{if(e!=null&&e._server_messages){const l=JSON.parse(e._server_messages);if(l.length){const r=JSON.parse(l[0]);if(r!=null&&r.message)return r.message.replace(/<[^>]+>/g,"")}}}catch{}return(e==null?void 0:e.message)||(e==null?void 0:e.exception)||t}async function ft(e,t,l=[]){if(ss.has(e)){const a=`${se}/api/method/sidrah_business.api.get_sb_doc?doctype=${encodeURIComponent(e)}&name=${encodeURIComponent(t)}`,c=await fetch(a,{credentials:"include",headers:{Accept:"application/json"}});if(!c.ok)throw new Error(`API Error: ${c.status}`);return(await c.json()).message}const r=l.length?`?fields=${encodeURIComponent(JSON.stringify(l))}`:"",s=await fetch(`${se}/api/v1/resource/${e}/${encodeURIComponent(t)}${r}`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(!s.ok)throw new Error(`API Error: ${s.status}`);return(await s.json()).data}async function Ef(e,t){const l=await an();if(ss.has(e)){const s=new URLSearchParams({doctype:e,name:t}),i=await fetch(`${se}/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:s.toString()});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(Xd(a,`Error deleting ${t}`))}return}const r=await fetch(`${se}/api/v1/resource/${e}/${encodeURIComponent(t)}`,{method:"DELETE",credentials:"include",headers:{Accept:"application/json","X-Frappe-CSRF-Token":l}});if(!r.ok){const s=await r.json().catch(()=>({}));throw new Error(Xd(s,`Error deleting ${t}`))}return await r.json()}async function ye(e){if(ss.has(e))try{const r=`${se}/api/method/sidrah_business.api.get_sb_list?doctype=${encodeURIComponent(e)}&limit=500`,s=await fetch(r,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}const t=encodeURIComponent('["*"]'),l=`${se}/api/v1/resource/${e}?limit_page_length=500&fields=${t}`;try{const r=await fetch(l,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return r.status===401||r.status===403?[]:r.ok?(await r.json()).data||[]:[]}catch(r){return console.error("Get error:",r),[]}}async function ja(e,t){const l=await an();if(ss.has(e)){const s=new URLSearchParams({doctype:e,data_json:JSON.stringify(t)}),i=await fetch(`${se}/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:s.toString()});if(!i.ok){const c=await i.json().catch(()=>({}));throw new Error(c.message||c.exc||`Error creating ${e}`)}return{data:(await i.json()).message}}const r=`${se}/api/v1/resource/${e}`;try{const s=await fetch(r,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":l},body:JSON.stringify(t)});if(s.status===401||s.status===403)throw new Error("Permission denied - login required");if(!s.ok){const i=await s.json();throw new Error(i.message||i.exc||`API Error: ${s.status}`)}return await s.json()}catch(s){throw console.error("Post error:",s),s}}async function bi(e,t,l){const r=await an();if(ss.has(e)){const i=new URLSearchParams({doctype:e,name:t,data_json:JSON.stringify(l)}),a=await fetch(`${se}/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":r},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 s=`${se}/api/v1/resource/${e}/${encodeURIComponent(t)}`;try{const i=await fetch(s,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":r},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 Km(){const e=`${se}/api/v1/resource/User?limit_page_length=500&fields=["name","full_name"]`;try{const t=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return t.status===401||t.status===403?[]:t.ok?(await t.json()).data||[]:[]}catch(t){return console.error("Get users error:",t),[]}}async function Qm(e,t){const l=new FormData;l.append("usr",e),l.append("pwd",t);const s=await(await fetch(`${se}/api/method/login`,{method:"POST",credentials:"include",body:l})).json();return s.csrf_token?Xn=s.csrf_token:await xc(),s}async function Ym(){const e=await an();try{await fetch(`${se}/api/method/logout`,{method:"POST",credentials:"include",headers:{"X-Frappe-CSRF-Token":e,Accept:"application/json"}})}catch{}Xn=""}function Gm(){return Xn}async function Af(){try{const e=await fetch(`${se}/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 Xm(){const e=JSON.stringify([["name","not in",["Administrator","Guest"]]]),t=`${se}/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 Jm(){const e=`${se}/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 Rf(e,t){await bi("User",e,{new_password:t})}async function qm(e=20){try{const t=`${se}/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 Zm(){const e=await an();try{await fetch(`${se}/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 Vm(e){const t=await an();try{await fetch(`${se}/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 ey(e){const t=await an(),l=new URLSearchParams({name:e});await fetch(`${se}/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 ty(e,t){try{const l=`${se}/api/method/sidrah_business.api.get_doc_comments?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(t)}`,r=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return r.ok?(await r.json()).message||[]:[]}catch{return[]}}async function ny(e,t,l){const r=await an(),s=new URLSearchParams({doctype:e,docname:t,content:l}),i=await fetch(`${se}/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":r},body:s.toString()});if(!i.ok)throw new Error("Failed to post comment");return(await i.json()).message}async function ly(e,t){try{const l=`${se}/api/method/sidrah_business.api.get_doc_versions?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(t)}`,r=await fetch(l,{credentials:"include",headers:{Accept:"application/json"}});return r.ok?(await r.json()).message||[]:[]}catch{return[]}}async function Lf(e){try{const t=`${se}/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 Zn(e,t={}){const l=await an(),r=new URLSearchParams(t),s=await fetch(`${se}/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:r.toString()});if(!s.ok){const a=await s.json().catch(()=>({}));throw new Error(a.message||a.exc||`Error calling ${e}`)}return(await s.json()).message}async function ry(e,t,l="",r,s,i){const a={name:e,action:t,comment:l};return r!==void 0&&(a.stage=r),i!==void 0&&(a.cycle_status=i),Zn("apply_order_workflow",a)}async function sy(e,t,l=""){return Zn("apply_incident_workflow",{name:e,action:t,fields_json:l})}async function iy(e,t,l=""){return Zn("apply_idea_workflow",{name:e,action:t,fields_json:l})}async function ay(e=""){const t=`${se}/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 oy(e,t={}){return Zn("get_report_data",{report_name:e,filters_json:JSON.stringify(t)})}async function cy(){try{const e=`${se}/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 dy(e,t,l="",r=""){return Zn("create_delegation",{manager:e,functions_json:JSON.stringify(t),organization:l,remarks:r})}async function uy(e,t,l=""){return Zn("respond_to_delegation",{name:e,response:t,remarks:l})}async function py(e,t=""){return Zn("revoke_delegation",{name:e,remarks:t})}async function fy(){try{const e=`${se}/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 hy(e){const t=`${se}/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 gy(){try{const e=`${se}/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 xy(){try{const e=`${se}/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 my(){const e=Gm();return e||xc()}async function zr(e){const t=await fetch(`${se}/api/method/sidrah_business.api.get_process?name=${encodeURIComponent(e)}`,{credentials:"include",headers:{Accept:"application/json"}});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.message||`Failed to load process (${t.status})`)}const l=await t.json();return l.message||l.data}async function yy(e,t,l={}){const r=await my(),s=new URLSearchParams({name:e,action:t});l.actor_status&&s.set("actor_status",String(l.actor_status)),l.actor_comment&&s.set("actor_comment",String(l.actor_comment)),l.progress_indicators&&s.set("progress_indicators",JSON.stringify(l.progress_indicators));const i=await fetch(`${se}/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":r},body:s.toString()});if(!i.ok){const c=await i.json().catch(()=>({})),u=c.message||(c.exception?String(c.exception).split(` `).pop():"")||c.exc_type||`Workflow action "${t}" failed (${i.status})`;throw new Error(u)}const a=await i.json();return a.message||a.data}function vy({onLogin:e}){const t=J(),[l,r]=S.useState(""),[s,i]=S.useState(""),[a,c]=S.useState(""),[u,h]=S.useState(!1),[f,p]=S.useState(!1),[d,g]=S.useState(!1),j=async()=>{if(!l||!s){c(t.login.emptyFields);return}h(!0),c("");try{const z=await Qm(l,s);if(z.message==="Logged In"){const o=await Af()||l,x=await Lf(o),v=x.some(b=>["SB Admin","System Manager"].includes(b))?"Admin":x.includes("SB Auditor")?"Auditor":x.includes("SB Owner")?"Owner":x.includes("SB X-Auditor")?"XAuditor":x.includes("SB Manager")?"Manager":"Employee";e({name:o,full_name:z.full_name||l,role:v})}else c(t.login.invalidCreds)}catch(z){c(t.login.connError+(z instanceof Error?z.message:"Unknown"))}h(!1)},m=z=>({width:"100%",padding:"13px 16px",border:`1.5px solid ${z?"#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:z?"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:z=>r(z.target.value),onKeyDown:z=>z.key==="Enter"&&j(),onFocus:()=>p(!0),onBlur:()=>p(!1),style:m(f),placeholder:t.login.usernamePlaceholder,autoComplete:"username"}),n.jsx("input",{type:"password",value:s,onChange:z=>i(z.target.value),onKeyDown:z=>z.key==="Enter"&&j(),onFocus:()=>g(!0),onBlur:()=>g(!1),style:m(d),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:j,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:z=>{u||(z.currentTarget.style.background="#4338ca")},onMouseLeave:z=>{u||(z.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:Pf,style:{fontSize:12,color:"#9ca3af",background:"none",border:"none",cursor:"pointer"},children:t.switchLang})})]})})}function As({title:e,data:t,color:l}){const[,r]=t[0]??["Total",0],s=t.slice(1);return n.jsxs("div",{style:{background:"white",borderRadius:12,padding:"14px 16px",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderTop:`3px solid ${l}`,height:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",minWidth:0},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10,paddingBottom:10,borderBottom:"1px solid #f1f5f9"},children:[n.jsx("span",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:e}),n.jsx("span",{style:{fontSize:20,fontWeight:800,color:l},children:r})]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.map(([i,a])=>n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8},children:[n.jsx("span",{style:{fontSize:12,color:"#64748b",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),n.jsx("span",{style:{background:"#f1f5f9",color:"#334155",padding:"1px 8px",borderRadius:10,fontSize:11,fontWeight:700,minWidth:18,textAlign:"center",flexShrink:0},children:a})]},i))})]})}function Ct({value:e,onChange:t,organizations:l,placeholder:r="-- Choose organization --",disabled:s=!1,small:i=!1}){var p;const[a,c]=S.useState(!1),u=S.useRef(null);S.useEffect(()=>{const d=g=>{u.current&&!u.current.contains(g.target)&&c(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[]);const h=e?((p=l.find(d=>d.organization_name===e||d.name===e))==null?void 0:p.organization_name)??e:r,f=l.filter(d=>!!d.is_active||d.organization_name===e||d.name===e);return n.jsxs("div",{ref:u,style:{position:"relative",width:"100%"},children:[n.jsxs("div",{onClick:()=>!s&&c(d=>!d),style:{width:"100%",padding:i?"4px 8px":"10px 14px",border:"1px solid #d1d5db",borderRadius:6,fontSize:i?11:14,cursor:s?"default":"pointer",height:i?28:void 0,background:s?"#f5f5f5":"white",color:e?"#333":"#aaa",display:"flex",justifyContent:"space-between",alignItems:"center",borderColor:a?"#3498db":"#d1d5db",transition:"border-color 0.2s",userSelect:"none",boxSizing:"border-box",opacity:s?.75:1},children:[n.jsx("span",{children:h}),n.jsx("span",{style:{fontSize:i?9:10,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(Jd,{label:r,selected:!e,active:!0,isPlaceholder:!0,small:i,onClick:()=>{t(""),c(!1)}}),f.length===0&&n.jsx("div",{style:{padding:"12px 16px",color:"#aaa",fontSize:13},children:"No organizations"}),f.map(d=>n.jsx(Jd,{label:d.organization_name,selected:e===d.organization_name||e===d.name,active:!!d.is_active,isPlaceholder:!1,small:i,onClick:()=>{t(d.organization_name),c(!1)}},d.name))]})})]})}function Jd({label:e,selected:t,active:l,isPlaceholder:r,small:s,onClick:i}){const[a,c]=S.useState(!1),u=t?"#2563eb":a?"#f0f4ff":"transparent",h=t?"white":r?"#aaa":l?"#1a2332":"#e74c3c";return n.jsx("div",{onClick:i,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),style:{padding:s?"6px 12px":"10px 16px",cursor:"pointer",fontSize:s?12:14,background:u,color:h,transition:"background 0.1s"},children:e})}function vn({items:e,type:t,onNavigate:l}){const r=J();if(!e.length)return null;const s=t==="process"?"processes-form":"orders-form",i=t==="process"?r.dash.escalatedProcesses:r.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(s,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:[r.dash.level," ",a.escalation_level]})]},a.name))})]})}function jy({kpi:e}){const t=J();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:r})=>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:r})]},l))})]})}function by({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 r=l.pass+l.fail+l.unknown||1,s=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:s,width:32},children:[n.jsx("div",{title:`Pass: ${l.pass}`,style:{height:Math.round(l.pass/t*s),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*s),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*s),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,c)=>`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][+c-1]} ${a}`)}),n.jsx("div",{style:{fontSize:9,color:"#555",textAlign:"center"},children:r>1?Math.round(l.pass/r*100)+"%":"—"})]},l.month)})}),n.jsx("div",{style:{display:"flex",gap:16,marginTop:8},children:[["#27ae60","Pass"],["#e74c3c","Fail"],["#95a5a6","Unknown"]].map(([l,r])=>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:r})]},r))})]})}function Et({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:r=>r.currentTarget.style.boxShadow="0 3px 10px rgba(0,0,0,0.12)",onMouseLeave:r=>r.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 Sy({dashData:e,fi:t,fid:l,fo:r,fp:s,incidentStatuses:i,ideaStatuses:a,orderStatuses:c,processStatuses:u,onNavigate:h}){const f=J(),p=(e==null?void 0:e.escalated_processes)||[],d=(e==null?void 0:e.escalated_orders)||[],g=(e==null?void 0:e.attention_processes)||[],j=(e==null?void 0:e.attention_orders)||[],m=(e==null?void 0:e.untriaged_incidents)||[],z=(e==null?void 0:e.overdue_triage)||[],y=p.length>0||d.length>0,o=g.length>0||j.length>0,x=[["Total",t.length],...i.map(k=>[k.name1||k.name,t.filter(C=>C.status===k.name).length])],v=[["Total",l.length],...a.map(k=>[k.name1||k.name,l.filter(C=>C.status===k.name).length])],b=[["Total",r.length],...c.map(k=>[k.name1||k.name,r.filter(C=>C.status===k.name).length])],w=[["Total",s.length],...u.map(k=>[k.name1||k.name,s.filter(C=>C.status===k.name).length])];return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",marginBottom:4},children:[n.jsx(Et,{label:"Incidents",icon:"⚠️",onClick:()=>h("incidents")}),n.jsx(Et,{label:"Ideas",icon:"💡",onClick:()=>h("ideas")}),n.jsx(Et,{label:"Orders",icon:"📦",onClick:()=>h("orders")}),n.jsx(Et,{label:"Processes",icon:"⚙️",onClick:()=>h("processes")}),n.jsx(Et,{label:"Inbox",icon:"📥",onClick:()=>h("inbox")}),n.jsx(Et,{label:"Reports",icon:"📊",onClick:()=>h("reports")})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:12},children:[n.jsx("div",{onClick:()=>h("incidents"),style:{cursor:"pointer"},children:n.jsx(As,{title:f.dash.incidents,color:N.orange,data:x})}),n.jsx("div",{onClick:()=>h("ideas"),style:{cursor:"pointer"},children:n.jsx(As,{title:f.dash.ideas,color:N.blue,data:v})}),n.jsx("div",{onClick:()=>h("orders"),style:{cursor:"pointer"},children:n.jsx(As,{title:f.dash.orders,color:N.purple,data:b})}),n.jsx("div",{onClick:()=>h("processes"),style:{cursor:"pointer"},children:n.jsx(As,{title:f.dash.processes,color:N.red,data:w})})]}),y&&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:f.dash.level2}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(vn,{items:p,type:"process",onNavigate:h}),n.jsx(vn,{items:d,type:"order",onNavigate:h})]})]}),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:f.dash.level1}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(vn,{items:g,type:"process",onNavigate:h}),n.jsx(vn,{items:j,type:"order",onNavigate:h})]})]}),z.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:[f.dash.overduePrefix,z.length,f.dash.overdueSuffix]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:z.map(k=>n.jsxs("div",{onClick:()=>h("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))})]}),m.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:N.orange,marginBottom:8},children:[f.dash.untriaged," (",m.length,")"]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:m.map(k=>n.jsxs("div",{onClick:()=>h("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 wy({dashData:e,selectedOrg:t,onNavigate:l}){const r=J(),[s,i]=S.useState([]),[a,c]=S.useState([]),[u,h]=S.useState(!1),f=(e==null?void 0:e.escalated_processes)||[],p=(e==null?void 0:e.escalated_orders)||[],d=(e==null?void 0:e.attention_processes)||[],g=(e==null?void 0:e.attention_orders)||[],j=(e==null?void 0:e.kpi_inputs)||[];S.useEffect(()=>{h(!0);const y=new URLSearchParams({months:"6"});t&&y.append("organization",t),fetch(`/api/method/sidrah_business.api.get_process_trend?${y}`,{credentials:"include",headers:{Accept:"application/json"}}).then(o=>o.json()).then(o=>{const x=o.message||[],v={};for(const b of x)v[b.month]||(v[b.month]={pass:0,fail:0,unknown:0}),b.status==="Pass"?v[b.month].pass=b.count:b.status==="Fail"?v[b.month].fail=b.count:b.status==="Unknown"&&(v[b.month].unknown=b.count);i(Object.entries(v).map(([b,w])=>({month:b,...w})))}).catch(()=>{}).finally(()=>h(!1))},[t]),S.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(y=>y.json()).then(y=>{var o;c((((o=y.message)==null?void 0:o.rows)||[]).slice(0,50))}).catch(()=>{})},[t]);const m=f.length>0||p.length>0,z=d.length>0||g.length>0;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:[n.jsx(Et,{label:"Manage Users & Roles",icon:"👥",onClick:()=>l("users")}),n.jsx(Et,{label:"Change Active Cycle",icon:"🔄",onClick:()=>l("cycles")}),n.jsx(Et,{label:"KPI Inputs",icon:"📈",onClick:()=>l("kpi-input")}),n.jsx(Et,{label:"Reports",icon:"📊",onClick:()=>l("reports")}),n.jsx(Et,{label:"Organizations",icon:"🏢",onClick:()=>l("organizations")})]}),j.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:r.dash.recentKpi}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12},children:j.map(y=>n.jsx(jy,{kpi:y},y.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:r.dash.manageKpi})]}),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.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#e74c3c",marginBottom:10},children:["Critical Escalations — Level 2 (",f.length+p.length,")"]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(vn,{items:f,type:"process",onNavigate:l}),n.jsx(vn,{items:p,type:"order",onNavigate:l})]})]}),z&&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 (",d.length+g.length,")"]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsx(vn,{items:d,type:"process",onNavigate:l}),n.jsx(vn,{items:g,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(by,{data:s})]}),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(y=>n.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#999",fontWeight:700,fontSize:11,whiteSpace:"nowrap"},children:y},y))})}),n.jsx("tbody",{children:a.map((y,o)=>n.jsxs("tr",{style:{borderTop:"1px solid #f0f0f0",background:o%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"8px 12px",color:"#555",whiteSpace:"nowrap"},children:y.timestamp?String(y.timestamp).slice(0,16):"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#333"},children:y.user||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:y.entity_type||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#555"},children:y.entity_name||"—"}),n.jsx("td",{style:{padding:"8px 12px",color:"#888",maxWidth:240,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.changes||"—"})]},o))})]})}),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 ky({incidents:e,ideas:t,orders:l,processes:r,organizations:s,incidentStatuses:i,ideaStatuses:a,orderStatuses:c,processStatuses:u,selectedOrg:h,onOrgChange:f,onNavigate:p,userRole:d}){const[g,j]=S.useState(null);S.useEffect(()=>{ay(h).then(j)},[h]);const m=h?e.filter(C=>C.organization===h):e,z=h?t.filter(C=>C.organization===h):t,y=h?l.filter(C=>C.organization===h):l,o=h?r.filter(C=>C.organization===h):r,x=d==="Admin",v=d==="Owner",[b,w]=S.useState("level2"),k=v||x&&b==="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(Ct,{value:h,onChange:f,organizations:s,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:()=>w(C),style:{padding:"4px 10px",borderRadius:5,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:b===C?C==="level2"?N.purple:N.blue:"transparent",color:b===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?N.purple:N.blue,padding:"3px 10px",borderRadius:20,flexShrink:0},children:k?"Level 2 — Owner":"Level 1 — Operational"})]}),k?n.jsx(wy,{dashData:g,selectedOrg:h,onNavigate:p}):n.jsx(Sy,{dashData:g,fi:m,fid:z,fo:y,fp:o,incidentStatuses:i,ideaStatuses:a,orderStatuses:c,processStatuses:u,onNavigate:p})]})}const _y=()=>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"})]}),Cy=()=>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"})]}),zy=()=>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 Ke({onView:e,onEdit:t,onDelete:l}){const[r,s]=S.useState(!1),i=(c,u,h,f,p)=>h?n.jsx("button",{onClick:d=>{d.stopPropagation(),h()},title:p,style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:c,color:u,flexShrink:0,transition:"opacity 0.15s"},onMouseEnter:d=>d.currentTarget.style.opacity="0.75",onMouseLeave:d=>d.currentTarget.style.opacity="1",children:f},p):null,a=l?()=>{r?(s(!1),l()):s(!0)}:void 0;return n.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[i("#e0f7fa","#0891b2",e,n.jsx(_y,{}),"View"),i("#dcfce7","#16a34a",t,n.jsx(Cy,{}),"Edit"),l&&n.jsx("button",{onClick:c=>{c.stopPropagation(),a==null||a()},title:r?"Click again to confirm delete":"Delete",style:{minWidth:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:r?8:"50%",padding:r?"0 8px":0,border:"none",cursor:"pointer",background:r?"#ef4444":"#fee2e2",color:r?"white":"#ef4444",flexShrink:0,fontSize:r?11:14,fontWeight:700,transition:"all 0.15s",gap:4},onMouseEnter:c=>c.currentTarget.style.opacity="0.8",onMouseLeave:c=>c.currentTarget.style.opacity="1",onBlur:()=>s(!1),children:r?"✓ Sure?":n.jsx(zy,{})})]})}const E={width:"100%",padding:"10px 12px",border:"1px solid #ddd",borderRadius:6,fontSize:14,boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif"},T={display:"block",marginBottom:6,fontSize:13,color:"#555",fontWeight:600};function Ty(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 ce(e,t){return e.filter(l=>Ty(l)||l.name===t)}function Bl(e,t,l){return e.filter(r=>{const s=t[r.name]||[];return s.includes("SB Admin")||s.includes("System Manager")?!1:s.includes(l)})}const $l={width:16,height:16,cursor:"pointer",accentColor:"#2563eb",flexShrink:0},Pn=(e,t)=>n.jsx("span",{style:{background:t,color:"white",padding:"4px 12px",borderRadius:12,fontSize:12,fontWeight:600,display:"inline-block"},children:e}),Wi=e=>{switch(e){case"New":return"#e74c3c";case"Under Progress":return"#f39c12";case"Executed":return"#27ae60";case"Overdue":return"#7f1d1d";default:return"#95a5a6"}},Re={fontSize:10,color:"#6b7280",fontWeight:600,marginBottom:3,display:"block",textTransform:"uppercase",letterSpacing:.4},Le={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 Bi({children:e}){const[t,l]=S.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(r=>!r),style:{background:"#4f46e5",color:"white",padding:"9px 18px",cursor:"pointer",display:"flex",alignItems:"center",gap:10,userSelect:"none"},children:[n.jsx("span",{style:{fontSize:13,opacity:.9},children:t?"▲":"▼"}),n.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{fontSize:13,fontWeight:600},children:"Filters"})]}),t&&n.jsx("div",{style:{background:"white",padding:"12px 16px",borderTop:"1px solid #e5e7eb"},children:e})]})}const te=20,qd=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 Oe({page:e,pageSize:t=te,total:l,onPageChange:r}){if(l===0)return null;const s=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:()=>r(e-1),style:qd(e<=1),children:"Previous"}),n.jsx("button",{disabled:e>=s,onClick:()=>r(e+1),style:qd(e>=s),children:"Next"})]})]})}function Iy({incidents:e,organizations:t,departments:l,branches:r,incidentStatuses:s,initialOrg:i,canModify:a,onView:c,onEdit:u,onDelete:h}){const f=J(),[p,d]=S.useState({search:"",organization:i||"",department:"",branch:"",status:""}),g=(o,x)=>d(v=>({...v,[o]:x})),[j,m]=S.useState(1),z=e.filter(o=>!(p.search&&!`${o.number} ${o.title}`.toLowerCase().includes(p.search.toLowerCase())||p.organization&&o.organization!==p.organization||p.department&&o.department!==p.department||p.branch&&o.branch!==p.branch||p.status&&o.status!==p.status));S.useEffect(()=>{m(1)},[p]);const y=z.slice((j-1)*te,j*te);return n.jsxs(n.Fragment,{children:[n.jsx(Bi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.numberTitle}),n.jsx("input",{style:Le,value:p.search,onChange:o=>g("search",o.target.value),placeholder:f.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.organization}),n.jsxs("select",{style:Le,value:p.organization,onChange:o=>g("organization",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.department}),n.jsxs("select",{style:Le,value:p.department,onChange:o=>g("department",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.branch}),n.jsxs("select",{style:Le,value:p.branch,onChange:o=>g("branch",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allBranches}),r.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.status}),n.jsxs("select",{style:Le,value:p.status,onChange:o=>g("status",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allStatuses}),s.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:()=>d({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:f.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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.number}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.title}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.organization}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.type}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.status}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.actions})]})}),n.jsx("tbody",{children:z.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:f.noIncidents})}):y.map((o,x)=>n.jsxs("tr",{onClick:()=>c==null?void 0:c(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.type?Pn(o.type,"#e74c3c"):"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.status?Pn(o.status,Wi(o.status)):"—"}),n.jsx("td",{style:{padding:"10px 18px"},onClick:v=>v.stopPropagation(),children:n.jsx(Ke,{onView:()=>c==null?void 0:c(o),onEdit:a&&u?()=>u(o):void 0,onDelete:a&&h?()=>h(o.name):void 0})})]},o.name))})]})}),n.jsx(Oe,{page:j,total:z.length,onPageChange:m})]})}function Py(e){if(!e)return"";const[t,l,r]=e.split("-");return!t||!l||!r?"":`${r}/${l}/${t}`}function pe({value:e,onChange:t,disabled:l,style:r,min:s,max:i}){return n.jsxs("div",{style:{position:"relative",width:"100%"},children:[n.jsx("input",{type:"text",readOnly:!0,tabIndex:-1,value:Py(e),placeholder:"DD/MM/YYYY",style:{...r,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:s,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 Ey({title:e,children:t}){return n.jsxs("div",{style:{background:"white",borderRadius:10,padding:"22px 24px",marginBottom:16,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[e&&n.jsx("div",{style:{fontSize:18,fontWeight:700,marginBottom:20,color:"#1e1b4b"},children:e}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:16},children:t})]})}function De({title:e,activePage:t,user:l,formStatus:r,buttonText:s,buttonColor:i,viewMode:a,hideSettings:c,rightPanel:u,onSubmit:h,onBack:f,onNavigate:p,onLogout:d,children:g}){const j=J(),m=j.nav[t]||t,z=(l.full_name||l.name||"U").charAt(0).toUpperCase(),y=l.role,o=y==="Admin"||y==="Owner"||y==="Auditor"||y==="Manager",x=y==="Admin"||y==="Owner"||y==="Auditor"||y==="Manager",v=y==="Admin"||y==="Auditor"||y==="Manager",b=o?"dashboard":"inbox",w=c?[]:zf(y),[k,C]=S.useState(()=>localStorage.getItem("sb_sidebar")==="1"),O=()=>C(W=>{const Q=!W;return localStorage.setItem("sb_sidebar",Q?"1":"0"),Q}),[U,X]=S.useState(!1),V=S.useRef(null);return S.useEffect(()=>{const W=Q=>{V.current&&!V.current.contains(Q.target)&&X(!1)};return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[]),n.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:N.bg},children:[n.jsxs("div",{style:{width:k?58:230,background:"linear-gradient(175deg, #1a0f42 0%, #2a1260 45%, #102840 100%)",color:"white",flexShrink:0,display:"flex",flexDirection:"column",transition:"width 0.22s ease",overflow:"hidden"},children:[n.jsxs("div",{style:{padding:k?"16px 0":"16px 20px 14px",borderBottom:"1px solid rgba(255,255,255,0.08)",display:"flex",alignItems:"center",justifyContent:k?"center":"space-between",gap:8,flexShrink:0},children:[!k&&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:j.rtl?"صدرة":"Sidrah"})]}),n.jsx("button",{onClick:O,title:k?j.rtl?"توسيع":"Expand":j.rtl?"طي":"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},children:k?"▶":"✕"})]}),n.jsxs("nav",{style:{padding:"12px 8px",flex:1,overflowY:"auto",overflowX:"hidden"},children:[Cf.filter(({id:W})=>(W!=="dashboard"||o)&&(W!=="reports"||x)&&(W!=="delegations"||v)).map(({id:W,icon:Q})=>{const ne=j.nav[W]||W,ee=W===t;return n.jsxs("div",{onClick:()=>p(W),title:k?ne:void 0,style:{padding:k?"10px 0":"10px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:k?"center":"flex-start",gap:11,background:ee?"rgba(139,92,246,0.28)":"transparent",borderRadius:9,fontSize:14,color:"white",fontWeight:ee?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{fontSize:17,flexShrink:0},children:Q}),!k&&ne]},W)}),w.length>0&&n.jsxs(n.Fragment,{children:[!k&&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:j.nav.settings}),k&&n.jsx("div",{style:{margin:"10px auto",width:28,borderTop:"1px solid rgba(255,255,255,0.12)"}}),w.map(({id:W,icon:Q})=>{const ne=j.nav[W]||W,ee=W===t;return n.jsxs("div",{onClick:()=>p(W),title:k?ne:void 0,style:{padding:k?"8px 0":"8px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:k?"center":"flex-start",gap:9,background:ee?"rgba(139,92,246,0.25)":"transparent",borderRadius:8,fontSize:k?15:12,color:"white",fontWeight:ee?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{flexShrink:0},children:Q}),!k&&ne]},W)})]})]})]}),n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[n.jsxs("div",{style:{background:"white",padding:"12px 24px",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:12},children:[n.jsx("button",{onClick:f,title:j.back,style:{width:34,height:34,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:"16",height:"16",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:18,fontWeight:700,color:"#1e1b4b"},children:e}),n.jsxs("div",{style:{fontSize:12,color:"#9ca3af",marginTop:1},children:[n.jsx("span",{onClick:()=>p(b),style:{cursor:"pointer",color:"#4f46e5"},onMouseEnter:W=>W.currentTarget.style.textDecoration="underline",onMouseLeave:W=>W.currentTarget.style.textDecoration="none",children:j.home}),!c&&n.jsxs(n.Fragment,{children:[n.jsx("span",{style:{margin:"0 4px"},children:"/"}),n.jsx("span",{onClick:f,style:{cursor:"pointer",color:"#4f46e5"},onMouseEnter:W=>W.currentTarget.style.textDecoration="underline",onMouseLeave:W=>W.currentTarget.style.textDecoration="none",children:m})]})]})]})]}),n.jsxs("div",{ref:V,style:{position:"relative"},children:[n.jsxs("div",{onClick:()=>X(W=>!W),style:{display:"flex",alignItems:"center",gap:10,cursor:"pointer",padding:"4px 8px",borderRadius:8,transition:"background 0.15s",background:U?"#f3f4f6":"transparent"},onMouseEnter:W=>W.currentTarget.style.background="#f3f4f6",onMouseLeave:W=>{U||(W.currentTarget.style.background="transparent")},children:[n.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end"},children:[n.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:l.full_name||l.name}),n.jsx("div",{style:{fontSize:11,color:"#9ca3af"},children:y})]}),n.jsx("div",{style:{width:34,height:34,borderRadius:"50%",background:"#4f46e5",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:14,fontWeight:700,flexShrink:0},children:z})]}),U&&n.jsxs("div",{style:{position:"absolute",right:0,top:"calc(100% + 6px)",background:"white",borderRadius:10,boxShadow:"0 8px 24px rgba(0,0,0,0.14)",border:"1px solid #e9eaf0",minWidth:160,zIndex:9999,overflow:"hidden"},children:[n.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid #f3f4f6"},children:[n.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#1e1b4b"},children:l.full_name||l.name}),n.jsx("div",{style:{fontSize:11,color:"#9ca3af"},children:y})]}),n.jsxs("button",{onClick:()=>{X(!1),d()},style:{width:"100%",padding:"10px 14px",display:"flex",alignItems:"center",gap:8,border:"none",background:"none",cursor:"pointer",fontSize:13,color:"#ef4444",fontWeight:600,fontFamily:"inherit",textAlign:"left"},onMouseEnter:W=>W.currentTarget.style.background="#fef2f2",onMouseLeave:W=>W.currentTarget.style.background="none",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:"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"})]}),"Logout"]})]})]})]}),n.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px",display:"grid",gridTemplateColumns:u?"1fr auto":"1fr",gap:14,alignItems:"start"},children:[n.jsx("div",{style:{minWidth:0},children:n.jsxs(Ey,{children:[g,!a&&n.jsxs("div",{style:{display:"flex",gap:12,marginTop:24},children:[n.jsx("button",{onClick:f,style:{padding:"11px 26px",borderRadius:8,border:"1.5px solid #e5e7eb",cursor:"pointer",fontSize:14,fontWeight:600,background:"white",color:"#374151",fontFamily:"Segoe UI"},children:j.cancel}),n.jsx("button",{onClick:h,disabled:r==="loading",style:{padding:"11px 26px",borderRadius:8,background:i,color:"white",border:"none",cursor:"pointer",fontSize:14,fontWeight:600,opacity:r==="loading"?.7:1,boxShadow:"0 2px 10px rgba(79,70,229,0.18)",fontFamily:"Segoe UI"},children:r==="loading"?j.saving:s})]}),r==="success"&&n.jsx("div",{style:{padding:"12px",borderRadius:8,background:"#f0fdf4",border:"1px solid #86efac",color:"#166534",fontSize:14,marginTop:12},children:j.savedOk}),r!=="idle"&&r!=="loading"&&r!=="success"&&n.jsx("div",{style:{padding:"12px",borderRadius:8,background:"#fef2f2",border:"1px solid #fca5a5",color:"#991b1b",fontSize:14,marginTop:12},children:r})]})}),u&&n.jsx("div",{style:{position:"sticky",top:20,alignSelf:"start"},children:u})]})]})]})}function ae({value:e,onChange:t,items:l,placeholder:r="-- Select --",disabled:s=!1}){var p;const[i,a]=S.useState(!1),[c,u]=S.useState(""),h=S.useRef(null);S.useEffect(()=>{const d=g=>{h.current&&!h.current.contains(g.target)&&a(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[]);const f=e?((p=l.find(d=>d.name===e))==null?void 0:p.label)??e:r;return n.jsxs("div",{ref:h,style:{position:"relative",width:"100%"},children:[n.jsxs("div",{onClick:()=>!s&&a(d=>!d),style:{width:"100%",padding:"10px 14px",border:"1px solid",borderColor:i?"#3498db":"#e0e0e0",borderRadius:6,fontSize:14,cursor:s?"default":"pointer",background:s?"#f5f5f5":"white",color:e?"#333":"#aaa",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"border-color 0.2s",userSelect:"none",boxSizing:"border-box",opacity:s?.75:1},children:[n.jsx("span",{children:f}),n.jsx("span",{style:{fontSize:10,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:"10px 16px",cursor:"pointer",fontSize:14,color:"#aaa",background:c==="__placeholder"?"#f5f5f5":"transparent"},children:r}),l.length===0&&n.jsx("div",{style:{padding:"12px 16px",color:"#aaa",fontSize:13},children:"No records found"}),l.map(d=>n.jsx("div",{onClick:()=>{t(d.name),a(!1)},onMouseEnter:()=>u(d.name),onMouseLeave:()=>u(""),style:{padding:"10px 16px",cursor:"pointer",fontSize:14,background:e===d.name?"#2563eb":c===d.name?"#f0f4ff":"transparent",color:e===d.name?"white":"#1a2332",transition:"background 0.1s"},children:d.label},d.name))]})})]})}function Ay(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 Ry(e){return e.replace(/@.*/,"").replace(/[._-]/g," ").split(" ").filter(Boolean).slice(0,2).map(l=>l[0].toUpperCase()).join("")}function $i({doctype:e,docname:t,currentUserName:l}){const r=J(),[s,i]=S.useState([]),[a,c]=S.useState(!1),[u,h]=S.useState(""),[f,p]=S.useState(!1),[d,g]=S.useState(!1),[j,m]=S.useState(!1),[z,y]=S.useState(""),o=5,x=S.useCallback(async()=>{c(!0);const C=await ty(e,t);i(C),c(!1)},[e,t]);S.useEffect(()=>{x()},[x]);const v=async()=>{const C=u.trim();if(!(!C||f)){p(!0),y("");try{await ny(e,t,C),h(""),await x()}catch{y("Failed to post comment. Please try again.")}p(!1)}},b=async C=>{if(window.confirm("Delete this comment?"))try{await Ef("Comment",C),i(O=>O.filter(U=>U.name!==C))}catch{alert("Failed to delete comment.")}},w=j?s:s.slice(-o),k=Math.max(0,s.length-o);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:()=>g(C=>!C),style:{padding:"12px 20px",borderBottom:d?"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:["💬 ",r.comments.title,s.length>0&&n.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:s.length})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("button",{onClick:C=>{C.stopPropagation(),x()},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:d?"▼":"▲"})]})]}),!d&&n.jsxs("div",{style:{padding:"16px 20px"},children:[!j&&k>0&&n.jsxs("button",{onClick:()=>m(!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 ",k," older comment",k!==1?"s":""]}),a&&n.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:r.loading}),!a&&s.length===0&&n.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:r.comments.noComments}),!a&&w.length>0&&n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:16},children:w.map(C=>{const O=C.comment_by||C.comment_email||C.owner||"Unknown",U=C.owner===l||C.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:Ry(O)}),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:O}),n.jsx("span",{style:{fontSize:11,color:"#aaa"},children:Ay(C.creation)})]}),U&&n.jsx("button",{onClick:()=>b(C.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:C.content||""}})]})]},C.name)})}),n.jsxs("div",{style:{borderTop:s.length>0?"1px solid #f0f0f0":"none",paddingTop:s.length>0?14:0},children:[n.jsx("textarea",{value:u,onChange:C=>h(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.ctrlKey||C.metaKey)&&v()},placeholder:r.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"}}),z&&n.jsx("div",{style:{fontSize:12,color:"#e74c3c",marginTop:4},children:z}),n.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:8},children:n.jsx("button",{onClick:v,disabled:!u.trim()||f,style:{padding:"8px 20px",background:"#3498db",color:"white",border:"none",borderRadius:6,cursor:!u.trim()||f?"not-allowed":"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI",opacity:!u.trim()||f?.6:1},children:f?r.saving:r.comments.post})})]})]})]})}function Zd(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 Ly(e){return(e||"").replace(/^custom_/,"").replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function Vd(e){return e==null||e===""?"(empty)":typeof e=="object"?JSON.stringify(e):String(e)}function bo(e){return(e||"Unknown").replace(/@.*/,"").replace(/[._]/g," ")}function eu(e){return bo(e).split(" ").filter(Boolean).slice(0,2).map(t=>t[0].toUpperCase()).join("")}function Oy(e){let t={};try{t=JSON.parse(e.data||"{}")}catch{}const l=(t.changed||[]).map(r=>({field:r[0]||"",oldVal:Vd(r[1]),newVal:Vd(r[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 Ui({doctype:e,docname:t,docCreation:l,docOwner:r}){const s=J(),[i,a]=S.useState([]),[c,u]=S.useState(!1),[h,f]=S.useState(!0),[p,d]=S.useState(!1),g=5,j=S.useCallback(async()=>{u(!0);const o=await ly(e,t);a(o.map(Oy)),u(!1)},[e,t]);S.useEffect(()=>{h||j()},[h,j]);const m=p?i:i.slice(0,g),z=i.length-g,y=(o,x=!1)=>({position:"absolute",left:-14,top:14,width:10,height:10,borderRadius:"50%",background:o,border:"2px solid white",boxShadow:x?`0 0 0 2px ${o}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:()=>f(o=>!o),style:{padding:"12px 20px",borderBottom:h?"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:["📋 ",s.activity.title,!h&&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:[!h&&n.jsx("button",{onClick:o=>{o.stopPropagation(),j()},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:h?"▼":"▲"})]})]}),!h&&n.jsxs("div",{style:{padding:"16px 20px"},children:[c&&n.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:s.loading}),!c&&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:[m.map((o,x)=>n.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[n.jsx("div",{style:y(x===0?"#3498db":"#d1d5db",x===0)}),n.jsxs("div",{style:{background:x===0?"#eff6ff":"#f9fafb",border:`1px solid ${x===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:eu(o.owner)}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:bo(o.owner)}),n.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Zd(o.creation)})]}),o.changes.length>0?n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:o.changes.map((v,b)=>n.jsxs("div",{style:{fontSize:12,lineHeight:1.5},children:[n.jsx("span",{style:{fontWeight:600,color:"#6d28d9"},children:Ly(v.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:v.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:v.newVal})]},b))}):n.jsxs("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic"},children:["Document updated",o.added>0&&n.jsxs("span",{children:[" · +",o.added," row(s)"]}),o.removed>0&&n.jsxs("span",{children:[" · -",o.removed," row(s)"]}),o.rowChanged>0&&n.jsxs("span",{children:[" · ~",o.rowChanged," row(s) modified"]})]})]})]},o.name)),l&&r&&n.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[n.jsx("div",{style:y("#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:eu(r)}),n.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:bo(r)}),n.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Zd(l)})]}),n.jsxs("div",{style:{fontSize:12,color:"#15803d",fontWeight:600},children:["✓ ",s.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"})]})]}),!c&&z>0&&n.jsx("div",{style:{textAlign:"center",marginTop:12},children:n.jsx("button",{onClick:()=>d(o=>!o),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 ur={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},ba={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},Dy={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 Ny(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...Dy[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function Wy({incForm:e,setIncForm:t,organizations:l,managements:r,departments:s,branches:i,incidentTypes:a,incidentClasses:c,incidentFields:u,incidentStatuses:h,users:f,userRoleMap:p={},formStatus:d,viewMode:g,userRole:j,onSubmit:m,onBack:z,onNavigate:y,onLogout:o,user:x,onRefresh:v}){const b=J(),w=P=>t({...e,...P}),k=g?{background:"#f9f9f9"}:{},C=Bl(f,p,"SB Employee"),O=Bl(f,p,"SB Manager"),[U,X]=S.useState(""),[V,W]=S.useState(!1),Q=e.name?g?`${b.formTitle.viewIncident}${e.number||e.name}`:b.formTitle.editIncident:b.formTitle.newIncident,ne=ce(r,e.management).map(P=>({name:P.name,label:P.name1||P.name})),ee=ce(s,e.department).map(P=>({name:P.name,label:P.department_name||P.name})),de=ce(i,e.branch).map(P=>({name:P.name,label:P.branch||P.name})),A=ce(a,e.type).map(P=>({name:P.name,label:P.name1||P.name})),$=c.map(P=>({name:P.name,label:P.name1||P.name})),H=u.map(P=>({name:P.name,label:P.name1||P.name})),q=ce(h,e.status).map(P=>({name:P.name,label:P.name1||P.name})),M=e.workflow_state||"New",_e=j==="Employee",R=j==="Auditor"||j==="Admin",Z=j==="Manager",Te=e.name?M==="New"?[{label:b.wf.submit,action:"Submit",color:"#2563eb"}]:M==="Initial Evaluation"&&R?[{label:b.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:b.wf.reject,action:"Reject",color:"#dc2626"}]:M==="Accept & Under Progress"&&(Z||R)?[{label:b.wf.submitSolution,action:"Submit Solution",color:"#059669"}]:M==="working on resolution"&&(Z||R)?[{label:b.wf.resolutionComplete,action:"Resolution complete",color:"#166534"}]:[]:[];async function Qe(P){if(e.name){W(!0),X("");try{const F={};P==="Assign to Manager"&&(e.assigned_to&&(F.assigned_to=e.assigned_to),e.priority&&(F.priority=e.priority),e.economy_class&&(F.economy_class=e.economy_class),e.entity_scope&&(F.entity_scope=e.entity_scope),e.hses_field&&(F.hses_field=e.hses_field),F.product_relation=String(e.product_relation??0),F.repeated=String(e.repeated??0)),P==="Submit Solution"&&(e.solution&&(F.solution=e.solution),e.summary&&(F.summary=e.summary),e.cost&&(F.cost=String(e.cost))),(P==="Resolution complete"||P==="Submit Solution")&&e.auditor_comment&&(F.auditor_comment=e.auditor_comment),await sy(e.name,P,JSON.stringify(F)),X("Done"),v==null||v()}catch(F){X(F.message||"Error")}finally{W(!1)}}}const I=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:b.wf.workflow}),n.jsx("span",{style:Ny(M),children:M})]}),M==="Initial Evaluation"&&R&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:b.wf.assignToManager}),n.jsxs("select",{style:E,value:e.assigned_to||"",onChange:P=>w({assigned_to:P.target.value}),children:[n.jsx("option",{value:"",children:b.field.selectMgr}),O.map(P=>n.jsx("option",{value:P.name,children:P.full_name||P.name},P.name))]})]}),(M==="Accept & Under Progress"||M==="working on resolution")&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:b.field.solution}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical"},value:e.solution||"",onChange:P=>w({solution:P.target.value}),placeholder:b.field.solutionPlaceholder}),n.jsx("label",{style:{...T,marginTop:8},children:b.field.actualCost}),n.jsx("input",{type:"number",style:E,value:e.cost||"",onChange:P=>w({cost:parseFloat(P.target.value)||0}),placeholder:"0.00"})]}),M==="working on resolution"&&R&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:b.field.auditorComment}),n.jsx("textarea",{style:{...E,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:P=>w({auditor_comment:P.target.value}),placeholder:b.field.commentPlaceholder})]}),Te.length>0?n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:Te.map(P=>n.jsx("button",{onClick:()=>Qe(P.action),disabled:V,style:{padding:"8px 18px",borderRadius:8,border:"none",background:P.color,color:"white",fontWeight:700,cursor:V?"not-allowed":"pointer",opacity:V?.7:1},children:V?b.wf.applying:P.label},P.action))}):n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:b.wf.noActions}),U&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:U==="Done"?N.green:N.red},children:U})]}),n.jsx($i,{doctype:D.incidents,docname:e.name,currentUserName:x.name}),n.jsx(Ui,{doctype:D.incidents,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(De,{title:Q,activePage:"incidents",user:x,formStatus:d,buttonText:b.saveIncident,buttonColor:N.accent,viewMode:g,rightPanel:I,onSubmit:m,onBack:z,onNavigate:y,onLogout:o,children:[n.jsxs("div",{style:ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.organization}),n.jsx(Ct,{value:e.organization,onChange:P=>w({organization:P}),organizations:l,disabled:g})]})]}),n.jsxs("div",{style:ba,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.management}),n.jsx(ae,{value:e.management,onChange:P=>w({management:P}),items:ne,placeholder:b.field.select,disabled:g})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.department}),n.jsx(ae,{value:e.department,onChange:P=>w({department:P}),items:ee,placeholder:b.field.select,disabled:g})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.section}),n.jsx("input",{style:{...E,...k},value:e.section_field||"",disabled:g,onChange:P=>w({section_field:P.target.value})})]})]}),n.jsxs("div",{style:ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.branch}),n.jsx(ae,{value:e.branch,onChange:P=>w({branch:P}),items:de,placeholder:b.field.select,disabled:g})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.hsesField}),n.jsx("input",{style:{...E,...k},value:e.hses_field||"",disabled:g,onChange:P=>w({hses_field:P.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{style:ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.type}),n.jsx(ae,{value:e.type,onChange:P=>w({type:P}),items:A,placeholder:b.field.selectType,disabled:g})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.title}),n.jsx("input",{style:{...E,...k},value:e.title,disabled:g,onChange:P=>w({title:P.target.value})})]})]}),n.jsxs("div",{style:ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.incidentClass}),n.jsx(ae,{value:e.incident_class,onChange:P=>w({incident_class:P}),items:$,placeholder:b.field.selectClass,disabled:g})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.incidentField}),n.jsx(ae,{value:e.incident_field,onChange:P=>w({incident_field:P}),items:H,placeholder:b.field.selectField,disabled:g})]})]}),n.jsxs("div",{style:ba,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.date}),n.jsx(pe,{value:e.date,onChange:P=>w({date:P}),disabled:g,style:{...E,...k}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.time}),n.jsx("input",{type:"time",style:{...E,...k},value:e.time,disabled:g,onChange:P=>w({time:P.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.assignedTo}),n.jsxs("select",{style:{...E,...k},value:e.assigned_to,disabled:g,onChange:P=>w({assigned_to:P.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),C.map(P=>n.jsx("option",{value:P.name,children:P.full_name||P.name},P.name))]})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.status}),n.jsx(ae,{value:e.status,onChange:P=>w({status:P}),items:q,placeholder:b.field.selectStatus,disabled:g})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.description}),n.jsx("textarea",{style:{...E,...k,height:120,resize:"vertical"},value:e.description,disabled:g,onChange:P=>w({description:P.target.value})})]}),!_e&&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:b.steps.auditorTriage}),n.jsxs("div",{style:ba,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.priority}),n.jsxs("select",{style:{...E,...g&&!R?{background:"#f9f9f9"}:{}},value:e.priority||"",disabled:g&&!R,onChange:P=>w({priority:P.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),n.jsx("option",{value:"High",children:b.field.high}),n.jsx("option",{value:"Normal",children:b.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.economyClass}),n.jsxs("select",{style:{...E,...g&&!R?{background:"#f9f9f9"}:{}},value:e.economy_class||"",disabled:g&&!R,onChange:P=>w({economy_class:P.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),n.jsx("option",{value:"Expenses",children:b.field.expenses}),n.jsx("option",{value:"Capital",children:b.field.capital}),n.jsx("option",{value:"Earn",children:b.field.earn}),n.jsx("option",{value:"Pay/Loss",children:b.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.entityScope}),n.jsxs("select",{style:{...E,...g&&!R?{background:"#f9f9f9"}:{}},value:e.entity_scope||"",disabled:g&&!R,onChange:P=>w({entity_scope:P.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),n.jsx("option",{value:"Upstream",children:b.field.upstream}),n.jsx("option",{value:"On-stream",children:b.field.onstream}),n.jsx("option",{value:"Downstream",children:b.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:g&&!R,onChange:P=>w({product_relation:P.target.checked?1:0})})," ",b.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:g&&!R,onChange:P=>w({repeated:P.target.checked?1:0})})," ",b.field.repeatedEvent]})]})]}),!_e&&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:b.steps.managerSolution}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.solution}),n.jsx("textarea",{style:{...E,height:100,resize:"vertical",...g&&!Z&&!R?{background:"#f9f9f9"}:{}},value:e.solution||"",disabled:g&&!Z&&!R,onChange:P=>w({solution:P.target.value}),placeholder:b.field.solutionPlaceholder})]}),n.jsxs("div",{style:ur,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.actualCost}),n.jsx("input",{type:"number",style:{...E,...g&&!Z&&!R?{background:"#f9f9f9"}:{}},value:e.cost||"",disabled:g&&!Z&&!R,onChange:P=>w({cost:parseFloat(P.target.value)||0}),placeholder:"0.00"})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.summary}),n.jsx("input",{style:{...E,...g&&!Z&&!R?{background:"#f9f9f9"}:{}},value:e.summary||"",disabled:g&&!Z&&!R,onChange:P=>w({summary:P.target.value}),placeholder:"Brief summary"})]})]})]}),!_e&&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:b.steps.ownerComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...g&&!R?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:g&&!R,onChange:P=>w({auditor_comment:P.target.value}),placeholder:b.field.commentPlaceholder})]})]})}function By({ideas:e,organizations:t,departments:l,branches:r,ideaStatuses:s,initialOrg:i,canModify:a,onView:c,onEdit:u,onDelete:h}){const f=J(),[p,d]=S.useState({search:"",organization:i||"",department:"",branch:"",status:""}),g=(o,x)=>d(v=>({...v,[o]:x})),[j,m]=S.useState(1),z=e.filter(o=>!(p.search&&!`${o.number} ${o.title}`.toLowerCase().includes(p.search.toLowerCase())||p.organization&&o.organization!==p.organization||p.department&&o.department!==p.department||p.branch&&o.branch!==p.branch||p.status&&o.status!==p.status));S.useEffect(()=>{m(1)},[p]);const y=z.slice((j-1)*te,j*te);return n.jsxs(n.Fragment,{children:[n.jsx(Bi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.numberTitle}),n.jsx("input",{style:Le,value:p.search,onChange:o=>g("search",o.target.value),placeholder:f.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.organization}),n.jsxs("select",{style:Le,value:p.organization,onChange:o=>g("organization",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.department}),n.jsxs("select",{style:Le,value:p.department,onChange:o=>g("department",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.branch}),n.jsxs("select",{style:Le,value:p.branch,onChange:o=>g("branch",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allBranches}),r.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.status}),n.jsxs("select",{style:Le,value:p.status,onChange:o=>g("status",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allStatuses}),s.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:()=>d({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:f.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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.number}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.title}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.organization}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.status}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.actions})]})}),n.jsx("tbody",{children:z.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:f.noIdeas})}):y.map((o,x)=>n.jsxs("tr",{onClick:()=>c==null?void 0:c(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.status?Pn(o.status,Wi(o.status)):"—"}),n.jsx("td",{style:{padding:"10px 18px"},onClick:v=>v.stopPropagation(),children:n.jsx(Ke,{onView:()=>c==null?void 0:c(o),onEdit:a&&u?()=>u(o):void 0,onDelete:a&&h?()=>h(o.name):void 0})})]},o.name))})]})}),n.jsx(Oe,{page:j,total:z.length,onPageChange:m})]})}const tu={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Sa={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},$y={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 Uy(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...$y[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function Fy({ideaForm:e,setIdeaForm:t,organizations:l,managements:r,departments:s,branches:i,ideaTypes:a,ideaStatuses:c,users:u=[],userRoleMap:h={},formStatus:f,viewMode:p,userRole:d,onSubmit:g,onBack:j,onNavigate:m,onLogout:z,user:y,onRefresh:o}){const x=J(),v=R=>t({...e,...R}),b=p?{background:"#f9f9f9"}:{},w=Bl(u,h,"SB Manager"),[k,C]=S.useState(""),[O,U]=S.useState(!1),X=e.name?p?`${x.formTitle.viewIdea}${e.number||e.title||e.name}`:x.formTitle.editIdea:x.formTitle.newIdea,V=ce(r,e.management).map(R=>({name:R.name,label:R.name1||R.name})),W=ce(s,e.department).map(R=>({name:R.name,label:R.department_name||R.name})),Q=ce(i,e.branch).map(R=>({name:R.name,label:R.branch||R.name})),ne=ce(a,e.type).map(R=>({name:R.name,label:R.name1||R.name})),ee=ce(c,e.status).map(R=>({name:R.name,label:R.name1||R.name})),de=e.workflow_state||"New",A=d==="Employee",$=d==="Auditor"||d==="Admin",H=d==="Manager",q=e.name?de==="New"?[{label:x.wf.submit,action:"Submit",color:"#2563eb"}]:de==="Initial Evaluation"&&$?[{label:x.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:x.wf.reject,action:"Reject",color:"#dc2626"}]:de==="Accept & Under Progress"&&(H||$)?[{label:x.wf.submitSolution,action:"Submit Proposal",color:"#059669"}]:de==="working on proposal"&&$?[{label:x.wf.moveToOutsourcing,action:"Move to Outsourcing",color:"#0369a1"},{label:x.wf.reject,action:"Reject",color:"#dc2626"}]:[]:[];async function M(R){if(e.name){U(!0),C("");try{const Z={};R==="Assign to Manager"&&(e.assigned_to&&(Z.assigned_to=e.assigned_to),e.priority&&(Z.priority=e.priority),e.economy_class&&(Z.economy_class=e.economy_class),e.entity_scope&&(Z.entity_scope=e.entity_scope),e.hses_field&&(Z.hses_field=e.hses_field),Z.product_relation=String(e.product_relation??0),Z.repeated=String(e.repeated??0)),R==="Submit Proposal"&&(e.solution&&(Z.solution=e.solution),e.proposed_condition&&(Z.proposed_condition=e.proposed_condition),e.cost&&(Z.cost=String(e.cost))),e.auditor_comment&&(R==="Move to Outsourcing"||R==="Reject")&&(Z.auditor_comment=e.auditor_comment),await iy(e.name,R,JSON.stringify(Z)),C("Done"),o==null||o()}catch(Z){C(Z.message||"Error")}finally{U(!1)}}}const _e=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:x.wf.workflow}),n.jsx("span",{style:Uy(de),children:de})]}),de==="Initial Evaluation"&&$&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:x.wf.assignToManager}),n.jsxs("select",{style:E,value:e.assigned_to||"",onChange:R=>v({assigned_to:R.target.value}),children:[n.jsx("option",{value:"",children:x.field.selectMgr}),w.map(R=>n.jsx("option",{value:R.name,children:R.full_name||R.name},R.name))]})]}),de==="Accept & Under Progress"&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:x.field.solution}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical"},value:e.solution||"",onChange:R=>v({solution:R.target.value}),placeholder:x.field.solutionPlaceholder}),n.jsx("label",{style:{...T,marginTop:8},children:x.field.actualCost}),n.jsx("input",{type:"number",style:E,value:e.cost||"",onChange:R=>v({cost:parseFloat(R.target.value)||0}),placeholder:"0.00"})]}),de==="working on proposal"&&$&&n.jsxs("div",{style:{marginBottom:12},children:[n.jsx("label",{style:T,children:x.field.auditorComment}),n.jsx("textarea",{style:{...E,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:R=>v({auditor_comment:R.target.value}),placeholder:x.field.commentPlaceholder})]}),q.length>0?n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:q.map(R=>n.jsx("button",{onClick:()=>M(R.action),disabled:O,style:{padding:"8px 18px",borderRadius:8,border:"none",background:R.color,color:"white",fontWeight:700,cursor:O?"not-allowed":"pointer",opacity:O?.7:1},children:O?x.wf.applying:R.label},R.action))}):n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:x.wf.noActions}),k&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:k==="Done"?N.green:N.red},children:k})]}),n.jsx($i,{doctype:D.ideas,docname:e.name,currentUserName:y.name}),n.jsx(Ui,{doctype:D.ideas,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(De,{title:X,activePage:"ideas",user:y,formStatus:f,buttonText:x.saveIdea,buttonColor:N.teal,viewMode:p,rightPanel:_e,onSubmit:g,onBack:j,onNavigate:m,onLogout:z,children:[n.jsxs("div",{style:tu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.organization}),n.jsx(Ct,{value:e.organization,onChange:R=>v({organization:R}),organizations:l,disabled:p})]})]}),n.jsxs("div",{style:Sa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.management}),n.jsx(ae,{value:e.management,onChange:R=>v({management:R}),items:V,placeholder:x.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.department}),n.jsx(ae,{value:e.department,onChange:R=>v({department:R}),items:W,placeholder:x.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.section}),n.jsx("input",{style:{...E,...b},value:e.section_field||"",disabled:p,onChange:R=>v({section_field:R.target.value})})]})]}),n.jsxs("div",{style:tu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.branch}),n.jsx(ae,{value:e.branch,onChange:R=>v({branch:R}),items:Q,placeholder:x.field.select,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.date}),n.jsx(pe,{value:e.date||"",onChange:R=>v({date:R}),disabled:p,style:{...E,...b}})]})]}),n.jsxs("div",{style:Sa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.type}),n.jsx(ae,{value:e.type,onChange:R=>v({type:R}),items:ne,placeholder:x.field.selectType,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.ideaClass}),n.jsxs("select",{style:{...E,...b},value:e.idea_class||"",disabled:p,onChange:R=>v({idea_class:R.target.value}),children:[n.jsx("option",{value:"",children:x.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:x.field.hsesField}),n.jsx("input",{style:{...E,...b},value:e.hses_field||"",disabled:p,onChange:R=>v({hses_field:R.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.title}),n.jsx("input",{style:{...E,...b},value:e.title,disabled:p,onChange:R=>v({title:R.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.status}),n.jsx(ae,{value:e.status,onChange:R=>v({status:R}),items:ee,placeholder:x.field.selectStatus,disabled:p})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.currentCondition}),n.jsx("textarea",{style:{...E,...b,height:110,resize:"vertical"},value:e.current_condition,disabled:p,onChange:R=>v({current_condition:R.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.proposedCondition}),n.jsx("textarea",{style:{...E,...b,height:110,resize:"vertical"},value:e.proposed_condition,disabled:p,onChange:R=>v({proposed_condition:R.target.value})})]}),!A&&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:x.steps.auditorEval}),n.jsxs("div",{style:Sa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.priority}),n.jsxs("select",{style:{...E,...p&&!$?{background:"#f9f9f9"}:{}},value:e.priority||"",disabled:p&&!$,onChange:R=>v({priority:R.target.value}),children:[n.jsx("option",{value:"",children:x.field.select}),n.jsx("option",{value:"High",children:x.field.high}),n.jsx("option",{value:"Normal",children:x.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.economyClass}),n.jsxs("select",{style:{...E,...p&&!$?{background:"#f9f9f9"}:{}},value:e.economy_class||"",disabled:p&&!$,onChange:R=>v({economy_class:R.target.value}),children:[n.jsx("option",{value:"",children:x.field.select}),n.jsx("option",{value:"Expenses",children:x.field.expenses}),n.jsx("option",{value:"Capital",children:x.field.capital}),n.jsx("option",{value:"Earn",children:x.field.earn}),n.jsx("option",{value:"Pay/Loss",children:x.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.entityScope}),n.jsxs("select",{style:{...E,...p&&!$?{background:"#f9f9f9"}:{}},value:e.entity_scope||"",disabled:p&&!$,onChange:R=>v({entity_scope:R.target.value}),children:[n.jsx("option",{value:"",children:x.field.select}),n.jsx("option",{value:"Upstream",children:x.field.upstream}),n.jsx("option",{value:"On-stream",children:x.field.onstream}),n.jsx("option",{value:"Downstream",children:x.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&&!$,onChange:R=>v({product_relation:R.target.checked?1:0})})," ",x.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&&!$,onChange:R=>v({repeated:R.target.checked?1:0})})," ",x.field.repeatedEvent]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:x.wf.assignToManager}),n.jsxs("select",{style:{...E,...p&&!$?{background:"#f9f9f9"}:{}},value:e.assigned_to||"",disabled:p&&!$,onChange:R=>v({assigned_to:R.target.value}),children:[n.jsx("option",{value:"",children:x.field.select}),w.map(R=>n.jsx("option",{value:R.name,children:R.full_name||R.name},R.name))]})]})]}),!A&&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:x.steps.managerSolution}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:x.field.solution}),n.jsx("textarea",{style:{...E,height:100,resize:"vertical",...p&&!H&&!$?{background:"#f9f9f9"}:{}},value:e.solution||"",disabled:p&&!H&&!$,onChange:R=>v({solution:R.target.value}),placeholder:x.field.solutionPlaceholder})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:x.field.actualCost}),n.jsx("input",{type:"number",style:{...E,...p&&!H&&!$?{background:"#f9f9f9"}:{}},value:e.cost||"",disabled:p&&!H&&!$,onChange:R=>v({cost:parseFloat(R.target.value)||0}),placeholder:"0.00"})]})]}),!A&&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:x.steps.ownerComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...p&&!$?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:p&&!$,onChange:R=>v({auditor_comment:R.target.value}),placeholder:x.field.commentPlaceholder})]})]})}function My({orders:e,organizations:t,departments:l,branches:r,orderStatuses:s,initialOrg:i,canModify:a,onView:c,onEdit:u,onDelete:h}){const f=J(),[p,d]=S.useState({search:"",organization:i||"",department:"",branch:"",status:""}),g=(o,x)=>d(v=>({...v,[o]:x})),[j,m]=S.useState(1),z=e.filter(o=>!(p.search&&!`${o.number} ${o.title}`.toLowerCase().includes(p.search.toLowerCase())||p.organization&&o.organization!==p.organization||p.department&&o.department!==p.department||p.branch&&o.branch!==p.branch||p.status&&o.status!==p.status));S.useEffect(()=>{m(1)},[p]);const y=z.slice((j-1)*te,j*te);return n.jsxs(n.Fragment,{children:[n.jsx(Bi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.numberTitle}),n.jsx("input",{style:Le,value:p.search,onChange:o=>g("search",o.target.value),placeholder:f.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.organization}),n.jsxs("select",{style:Le,value:p.organization,onChange:o=>g("organization",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.department}),n.jsxs("select",{style:Le,value:p.department,onChange:o=>g("department",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.branch}),n.jsxs("select",{style:Le,value:p.branch,onChange:o=>g("branch",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allBranches}),r.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.status}),n.jsxs("select",{style:Le,value:p.status,onChange:o=>g("status",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allStatuses}),s.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:()=>d({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:f.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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.number}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.title}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.organization}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.type}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.status}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.actions})]})}),n.jsx("tbody",{children:z.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:f.noOrders})}):y.map((o,x)=>n.jsxs("tr",{onClick:()=>c==null?void 0:c(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:o.title||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.type?Pn(o.type,"#8e44ad"):"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.status?Pn(o.status,Wi(o.status)):"—"}),n.jsx("td",{style:{padding:"10px 18px"},onClick:v=>v.stopPropagation(),children:n.jsx(Ke,{onView:()=>c==null?void 0:c(o),onEdit:a&&u?()=>u(o):void 0,onDelete:a&&h?()=>h(o.name):void 0})})]},o.name))})]})}),n.jsx(Oe,{page:j,total:z.length,onPageChange:m})]})}const Rs={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Ls={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20},Hy={1:"Initiation / Bidding",2:"Execution begins",3:"Mid-execution review",4:"Near completion",5:"Closing"},Ky={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 Qy(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...Ky[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function Yy({orderForm:e,setOrderForm:t,organizations:l,managements:r,departments:s,branches:i,orderTypes:a,orderStatuses:c,cycles:u=[],users:h,userRoleMap:f={},formStatus:p,viewMode:d,currentUser:g,userRole:j,onSubmit:m,onBack:z,onNavigate:y,onLogout:o,user:x,onRefresh:v}){var as;const b=J(),w=L=>t({...e,...L}),k=d?{background:"#f9f9f9"}:{},C=Bl(h,f,"SB Employee"),[O,U]=S.useState(""),[X,V]=S.useState(""),[W,Q]=S.useState(!1),[ne,ee]=S.useState("Agree"),de=e.name?d?`${b.formTitle.viewOrder}${e.number||e.title||e.name}`:b.formTitle.editOrder:b.formTitle.newOrder,A=ce(r,e.management).map(L=>({name:L.name,label:L.name1||L.name})),$=ce(s,e.department).map(L=>({name:L.name,label:L.department_name||L.name})),H=ce(i,e.branch).map(L=>({name:L.name,label:L.branch||L.name})),q=ce(a,e.type).map(L=>({name:L.name,label:L.name1||L.name})),M=ce(c,e.status).map(L=>({name:L.name,label:L.name1||L.name})),_e=ce(u,e.cycle).map(L=>({name:L.name,label:L.name1||L.name})),R=!!e.name,Z=e.workflow_state||"Draft",Te=Math.min(5,(e.stage||0)+1),[Qe,I]=S.useState(Te);S.useEffect(()=>{I(Math.min(5,(e.stage||0)+1))},[e.stage]);const P=j==="Auditor"||j==="Admin"||j==="Manager",F=P||j==="Owner",Ln=!!(g&&(e.actor===g||e.assigned_to===g)),on=R?Z==="Closed"?[]:Z==="Draft"&&P?[{label:"Submit for Review",action:"Submit for Review",color:"#2563eb"}]:Z==="Pending Actor"&&(Ln||P)?[{label:"Update Status",action:"Update Status",color:"#d97706"}]:Z==="Review"&&F?[{label:"Move to Study",action:"Move to Study",color:"#059669"},{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}]:Z==="In Study"&&F?[{label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"},{label:"Close Order",action:"Close Order",color:"#475569"}]:[]:[];async function Fi(L){if(e.name){Q(!0),U("");try{let pt;L==="Update Status"&&(pt=ne);const Ft=await ry(e.name,L,X,L==="Update Status"?String(Qe):void 0,void 0,pt);if(V(""),ee("Agree"),U("Done"),Ft){const cn=Ft;t({...e,...cn,stage:cn.stage??e.stage,completion_pct:cn.completion_pct??e.completion_pct,workflow_state:cn.workflow_state??e.workflow_state})}v==null||v()}catch(pt){U(pt.message||"Error")}finally{Q(!1)}}}const On=R?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:b.wf.workflow}),n.jsx("span",{style:Qy(Z),children:Z})]}),Z==="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) — ",Qe*20,"% complete"]}),n.jsx("input",{type:"number",min:1,max:5,style:{...E,maxWidth:80},value:Qe,onChange:L=>I(Math.min(5,Math.max(1,parseInt(L.target.value)||1)))})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Cycle Status"}),n.jsxs("select",{style:{...E,minWidth:140},value:ne,onChange:L=>ee(L.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"&&Z==="Pending Actor"?n.jsx("span",{style:{color:N.red},children:" * required for Deviate"}):"(optional)"]}),n.jsx("textarea",{style:{...E,height:64,resize:"vertical",borderColor:ne==="Deviate"&&!X?"#fca5a5":void 0},value:X,onChange:L=>V(L.target.value),placeholder:"Add a comment…"})]}),n.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:on.map(L=>{const pt=L.action==="Update Status"&&ne==="Deviate"&&!X.trim();return n.jsx("button",{onClick:()=>Fi(L.action),disabled:W||pt,title:pt?"Comment required when status is Deviate":void 0,style:{padding:"8px 18px",borderRadius:8,border:"none",background:L.color,color:"white",fontWeight:700,cursor:W||pt?"not-allowed":"pointer",opacity:W||pt?.5:1},children:W?b.wf.applying:L.label},L.action)})}),O&&n.jsx("p",{style:{marginTop:8,fontSize:13,color:O==="Done"?N.green:N.red},children:O}),on.length===0&&n.jsx("div",{style:{fontSize:12,color:"#94a3b8",fontStyle:"italic"},children:b.wf.noActions})]}),n.jsx($i,{doctype:D.orders,docname:e.name,currentUserName:x.name}),n.jsx(Ui,{doctype:D.orders,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):null;return n.jsxs(De,{title:de,activePage:"orders",user:x,formStatus:p,buttonText:b.saveOrder,buttonColor:N.purple,viewMode:d,rightPanel:On,onSubmit:m,onBack:z,onNavigate:y,onLogout:o,children:[n.jsxs("div",{style:Rs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.organization}),n.jsx(Ct,{value:e.organization,onChange:L=>w({organization:L}),organizations:l,disabled:d})]})]}),n.jsxs("div",{style:Ls,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.management}),n.jsx(ae,{value:e.management,onChange:L=>w({management:L}),items:A,placeholder:b.field.select,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.department}),n.jsx(ae,{value:e.department,onChange:L=>w({department:L}),items:$,placeholder:b.field.select,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.section}),n.jsx("input",{style:{...E,...k},value:e.section_field||"",disabled:d,onChange:L=>w({section_field:L.target.value})})]})]}),n.jsxs("div",{style:Rs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.branch}),n.jsx(ae,{value:e.branch,onChange:L=>w({branch:L}),items:H,placeholder:b.field.select,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.type}),n.jsx(ae,{value:e.type,onChange:L=>w({type:L}),items:q,placeholder:b.field.selectType,disabled:d})]})]}),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:Ls,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.priority}),n.jsxs("select",{style:{...E,...k},value:e.priority||"",disabled:d,onChange:L=>w({priority:L.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),n.jsx("option",{value:"High",children:b.field.high}),n.jsx("option",{value:"Normal",children:b.field.normal})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.economyClass}),n.jsxs("select",{style:{...E,...k},value:e.economy_class||"",disabled:d,onChange:L=>w({economy_class:L.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),n.jsx("option",{value:"Expenses",children:b.field.expenses}),n.jsx("option",{value:"Capital",children:b.field.capital}),n.jsx("option",{value:"Earn",children:b.field.earn}),n.jsx("option",{value:"Pay/Loss",children:b.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.entityScope}),n.jsxs("select",{style:{...E,...k},value:e.entity_scope||"",disabled:d,onChange:L=>w({entity_scope:L.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),n.jsx("option",{value:"Upstream",children:b.field.upstream}),n.jsx("option",{value:"On-stream",children:b.field.onstream}),n.jsx("option",{value:"Downstream",children:b.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:d,onChange:L=>w({planned:L.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:d,onChange:L=>w({product_relation:L.target.checked?1:0})})," ",b.field.productRelation]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:b.field.hsesField}),n.jsx("input",{style:{...E,...k},value:e.hses_field||"",disabled:d,onChange:L=>w({hses_field:L.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.title}),n.jsx("input",{style:{...E,...k},value:e.title,disabled:d,onChange:L=>w({title:L.target.value})})]}),n.jsxs("div",{style:Ls,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.budget}),n.jsx("input",{type:"number",style:{...E,...k},value:e.budget||"",disabled:d,onChange:L=>w({budget:parseFloat(L.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.actualCost}),n.jsx("input",{type:"number",style:{...E,...k},value:e.actual_cost||"",disabled:d,onChange:L=>w({actual_cost:parseFloat(L.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Variance"}),(()=>{const L=(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:L>=0?"#f0fdf4":"#fef2f2",color:L>=0?"#166534":"#dc2626",border:`1px solid ${L>=0?"#bbf7d0":"#fecaca"}`},children:[L>=0?"+":"",L.toFixed(2)]})})()]})]}),n.jsxs("div",{style:Rs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.currency}),n.jsxs("select",{style:{...E,...k},value:e.currency||"",disabled:d,onChange:L=>w({currency:L.target.value}),children:[n.jsx("option",{value:"",children:b.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:b.field.status}),n.jsx(ae,{value:e.status,onChange:L=>w({status:L}),items:M,placeholder:b.field.selectStatus,disabled:d||Z==="Closed"})]})]}),n.jsxs("div",{style:Ls,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.startingDate}),n.jsx(pe,{value:e.starting_date,onChange:L=>w({starting_date:L}),disabled:d,style:{...E,...k}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.endingDate}),n.jsx(pe,{value:e.ending_date,onChange:L=>w({ending_date:L}),disabled:d,style:{...E,...k}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.actor}),n.jsxs("select",{style:{...E,...k},value:e.actor||e.assigned_to||"",disabled:d,onChange:L=>w({actor:L.target.value,assigned_to:L.target.value}),children:[n.jsx("option",{value:"",children:b.field.select}),C.map(L=>n.jsx("option",{value:L.name,children:L.full_name||L.name},L.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:Rs,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.cycle}),n.jsx(ae,{value:e.cycle||"",onChange:L=>w({cycle:L}),items:_e,placeholder:b.field.select,disabled:d})]}),n.jsxs("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.stage}),n.jsx("input",{type:"number",min:1,max:5,style:{...E,background:"#f9f9f9",maxWidth:80},value:e.stage||1,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Completion"}),n.jsx("input",{style:{...E,background:"#f9f9f9",maxWidth:100},value:`${e.completion_pct||(e.stage||1)*20}%`,readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style: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:Hy[e.stage||1]||"—"})]}),(e.escalation_level??0)>0&&n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.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]})]})]})]})]}),R&&((as=e.order_cycle_log)==null?void 0:as.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:13},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8fafc"},children:["Cycle","Date","Stage","Status","Actor","Comment"].map(L=>n.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:600,color:"#475569",borderBottom:"1px solid #e2e8f0"},children:L},L))})}),n.jsx("tbody",{children:(e.order_cycle_log||[]).map((L,pt)=>{const Ft=L.status==="Agree"?"#166534":L.status==="Deviate"?"#c2410c":"#92400e",cn=L.status==="Agree"?"#f0fdf4":L.status==="Deviate"?"#fff7ed":"#fefce8";return n.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:L.cycle||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:L.cycle_date||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155",textAlign:"center"},children:L.stage||"—"}),n.jsx("td",{style:{padding:"6px 10px"},children:n.jsx("span",{style:{background:cn,color:Ft,padding:"2px 8px",borderRadius:12,fontWeight:600,fontSize:12},children:L.status||"—"})}),n.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:L.actor||"—"}),n.jsx("td",{style:{padding:"6px 10px",color:"#64748b",fontStyle:L.comment?"normal":"italic"},children:L.comment||"—"})]},pt)})})]})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.description}),n.jsx("textarea",{style:{...E,...k,height:100,resize:"vertical"},value:e.description,disabled:d,onChange:L=>w({description:L.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:b.field.notes}),n.jsx("textarea",{style:{...E,...k,height:100,resize:"vertical"},value:e.notes,disabled:d,onChange:L=>w({notes:L.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:b.field.auditorComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...d&&Ln&&!P?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:d&&Ln&&!P,onChange:L=>w({auditor_comment:L.target.value}),placeholder:b.field.commentPlaceholder})]})]})}function Gy({processes:e,organizations:t,departments:l,branches:r,processStatuses:s,initialOrg:i,canModify:a,onView:c,onEdit:u,onDelete:h}){const f=J(),[p,d]=S.useState({search:"",organization:i||"",department:"",branch:"",status:""}),g=(o,x)=>d(v=>({...v,[o]:x})),[j,m]=S.useState(1),z=e.filter(o=>!(p.search&&!`${o.number} ${o.title}`.toLowerCase().includes(p.search.toLowerCase())||p.organization&&o.organization!==p.organization||p.department&&o.department!==p.department||p.branch&&o.branch!==p.branch||p.status&&o.status!==p.status));S.useEffect(()=>{m(1)},[p]);const y=z.slice((j-1)*te,j*te);return n.jsxs(n.Fragment,{children:[n.jsx(Bi,{children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"8px 14px"},children:[n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.numberTitle}),n.jsx("input",{style:Le,value:p.search,onChange:o=>g("search",o.target.value),placeholder:f.filter.searchPlaceholder})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.organization}),n.jsxs("select",{style:Le,value:p.organization,onChange:o=>g("organization",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.department}),n.jsxs("select",{style:Le,value:p.department,onChange:o=>g("department",o.target.value),children:[n.jsx("option",{value:"",children:f.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:Re,children:f.filter.branch}),n.jsxs("select",{style:Le,value:p.branch,onChange:o=>g("branch",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allBranches}),r.map(o=>n.jsx("option",{value:o.name,children:o.branch||o.name},o.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:Re,children:f.filter.status}),n.jsxs("select",{style:Le,value:p.status,onChange:o=>g("status",o.target.value),children:[n.jsx("option",{value:"",children:f.filter.allStatuses}),s.map(o=>n.jsx("option",{value:o.name,children:o.name1||o.name},o.name)),n.jsx("option",{value:"Closed",children:"Closed"})]})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:()=>d({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:f.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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.number}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.title}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.organization}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.field.cycleType}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.status}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:f.col.actions})]})}),n.jsx("tbody",{children:z.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:f.noProcesses})}):y.map((o,x)=>n.jsxs("tr",{onClick:()=>c==null?void 0:c(o),style:{borderTop:"1px solid #f0f0f0",background:x%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",color:"#999"},children:o.number||"—"}),n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:o.title||o.name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.organization||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.cycle_type?Pn(o.cycle_type,"#8e44ad"):"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:o.status?Pn(o.status,Wi(o.status)):"—"}),n.jsx("td",{style:{padding:"10px 18px"},onClick:v=>v.stopPropagation(),children:n.jsx(Ke,{onView:()=>c==null?void 0:c(o),onEdit:a&&u?()=>u(o):void 0,onDelete:a&&h?()=>h(o.name):void 0})})]},o.name))})]})}),n.jsx(Oe,{page:j,total:z.length,onPageChange:m})]})}const Xy={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"]}]},Jy={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 nu(e){return{display:"inline-block",padding:"5px 14px",borderRadius:20,fontSize:13,fontWeight:700,...Jy[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}const Os={width:"100%",padding:"6px 8px",border:"1px solid #d1d5db",borderRadius:5,fontSize:12,fontFamily:"Segoe UI",boxSizing:"border-box"};function qy({processName:e,userRole:t,onRefresh:l,canUpdateStatus:r=!0}){const[s,i]=S.useState(null),[a,c]=S.useState(!0),[u,h]=S.useState(""),[f,p]=S.useState(!1),[d,g]=S.useState(""),[j,m]=S.useState(""),[z,y]=S.useState("Pass"),[o,x]=S.useState(""),[v,b]=S.useState({}),w=S.useCallback(async()=>{if(!e){c(!1);return}c(!0),h("");try{const W=await zr(e);i(W);const Q={};for(const ne of W.progress_indicators||[])Q[ne.name]=ne.actual_value!=null?String(ne.actual_value):"";b(Q)}catch(W){h(W instanceof Error?W.message:"Failed to load process")}c(!1)},[e]);if(S.useEffect(()=>{w()},[w]),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||!s)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 k=s.workflow_state||"Draft",C=Xy[k]??[],O=t==="Employee"||t==="Manager",U=t!=="Manager"||r,X=C.filter(W=>(t==="Admin"||W.allowedRoles.includes(t))&&(W.action!=="Update Status"||U)),V=async W=>{p(!0),g(""),m("");try{const Q={};if(W==="Update Status"){Q.actor_status=z,Q.actor_comment=o;const ee=s.progress_indicators||[];ee.length>0&&(Q.progress_indicators=ee.map(de=>({name:de.name,actual_value:v[de.name]??""})))}W==="Add Comment"&&o&&(Q.actor_comment=o);const ne=await yy(s.name,W,Q);i(ne),x(""),m(`Done — now: ${ne.workflow_state||"updated"}`),l==null||l()}catch(Q){g(Q instanceof Error?Q.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:nu(k),children:k})]}),k==="Pending Actor"&&O&&U&&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(s.progress_indicators)&&s.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:s.progress_indicators.map(W=>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:W.name1,children:W.name1||W.name}),n.jsx("input",{type:"number",value:v[W.name]??"",onChange:Q=>b(ne=>({...ne,[W.name]:Q.target.value})),style:{...Os,width:70,flexShrink:0},placeholder:"0"})]},W.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:z,onChange:W=>y(W.target.value),style:Os,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:o,onChange:W=>x(W.target.value),style:{...Os,height:52,resize:"vertical"},placeholder:"Add a comment…"})]})]}),(k==="Pending Comment"||k==="Review")&&!O&&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(s.cycle_logs)&&s.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 W=s.cycle_logs,Q=W[W.length-1],ne=Q.status==="Pass"?"#16a34a":Q.status==="Fail"?"#dc2626":"#9ca3af";return n.jsxs("div",{style:{fontSize:13,fontWeight:700,color:ne},children:[Q.status," ",Q.comment?`— ${Q.comment}`:""]})})()]}),n.jsx("textarea",{value:o,onChange:W=>x(W.target.value),style:{...Os,height:52,resize:"vertical"},placeholder:"Add a comment…"})]}),n.jsxs("div",{style:{padding:"12px 14px",borderBottom:X.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"}),X.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:k}),"."]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:X.map(W=>n.jsxs("button",{onClick:()=>V(W.action),disabled:f,style:{width:"100%",padding:"10px 14px",borderRadius:6,border:"none",background:W.action==="Close Process"?"#64748b":W.action==="Move to Study"?"#8e44ad":"#2563eb",color:"white",cursor:f?"not-allowed":"pointer",fontSize:13,fontWeight:600,opacity:f?.7:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsx("span",{children:f?"Applying…":W.action}),n.jsxs("span",{style:{fontSize:10,opacity:.7},children:["→ ",W.next]})]},W.action))}),d&&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:d}),j&&n.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,fontSize:12,color:"#166534"},children:j})]}),C.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"}),C.map(W=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6,fontSize:11},children:[n.jsx("span",{style:{color:"#555",flex:1},children:W.action}),n.jsx("span",{style:{color:"#bbb"},children:"→"}),n.jsx("span",{style:nu(W.next),children:W.next})]},W.action))]})]})})}const Ds={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:16},al={display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:16};function Zy({processForm:e,setProcessForm:t,organizations:l,managements:r,departments:s,branches:i,processTypes:a,processStatuses:c,cycles:u=[],users:h=[],userRoleMap:f={},formStatus:p,viewMode:d,userRole:g,delegatedFunctions:j=[],delegatedOrgs:m=null,onRefreshProcess:z,onSubmit:y,onBack:o,onNavigate:x,onLogout:v,user:b}){const w=J(),k=I=>t({...e,...I}),C=d?{background:"#f9f9f9"}:{},O=!d&&g==="Manager"&&Array.isArray(m),U=O?l.filter(I=>(m||[]).includes(I.organization_name||I.name)):l,X=O&&(m||[]).length===1,V=ce(r,e.management).map(I=>({name:I.name,label:I.name1||I.name})),W=ce(s,e.department).map(I=>({name:I.name,label:I.department_name||I.name})),Q=ce(i,e.branch).map(I=>({name:I.name,label:I.branch||I.name})),ne=ce(a,e.type).map(I=>({name:I.name,label:I.name1||I.name})),ee=ce(c,e.status).map(I=>({name:I.name,label:I.name1||I.name})),de=ce(u,e.cycle).map(I=>({name:I.name,label:I.name1||I.name})),A=Bl(h,f,"SB Employee").map(I=>({name:I.name,label:I.full_name||I.name})),$=(I,P)=>{const F=[...e.cycle_logs||[]];F[I]={...F[I],...P},k({cycle_logs:F})},H=()=>{k({cycle_logs:[...e.cycle_logs||[],{cycle:"",cycle_date:"",status:"Pass",actor:"",comment:""}]})},q=I=>{const P=[...e.cycle_logs||[]];P.splice(I,1),k({cycle_logs:P})},M=(I,P)=>{const F=[...e.progress_indicators||[]];F[I]={...F[I],...P},k({progress_indicators:F})},_e=()=>{k({progress_indicators:[...e.progress_indicators||[],{name1:"",type:"Nominal",unit:"",cycle:"",target:"",maximum:"",minimum:"",manager:"",order:"",actual_value:"",cycle_status:"",cycle_date:"",cycle_comment:"",status:""}]})},R=I=>{const P=[...e.progress_indicators||[]];P.splice(I,1),k({progress_indicators:P})},Z=e.name?d?`${w.formTitle.viewProcess}${e.title||e.name}`:w.formTitle.editProcess:w.formTitle.newProcess,Te=g!=="Manager"||e.actor===b.name||j.includes("update_process_status"),Qe=e.name?n.jsxs("div",{style:{width:260,display:"flex",flexDirection:"column",gap:14},children:[n.jsx(qy,{processName:e.name,userRole:g||b.role||"Employee",onRefresh:z,canUpdateStatus:Te}),n.jsx($i,{doctype:D.processes,docname:e.name,currentUserName:b.name}),n.jsx(Ui,{doctype:D.processes,docname:e.name,docCreation:e.creation,docOwner:e.owner})]}):void 0;return n.jsxs(De,{title:Z,activePage:"processes",user:b,formStatus:p,buttonText:w.saveProcess,buttonColor:N.blue,viewMode:d,rightPanel:Qe,onSubmit:y,onBack:o,onNavigate:x,onLogout:v,children:[n.jsxs("div",{style:Ds,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.number}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.number||"",readOnly:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.organization}),n.jsx(Ct,{value:e.organization,onChange:I=>k({organization:I}),organizations:U,disabled:d||X}),O&&n.jsx("div",{style:{fontSize:11,color:"#888",marginTop:4},children:(m||[]).length===0?"You have no delegated organization for Processes.":`Restricted to your delegated organization${(m||[]).length>1?"s":""}: ${(m||[]).join(", ")}`})]})]}),n.jsxs("div",{style:Ds,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.title}),n.jsx("input",{style:{...E,...C},value:e.title,disabled:d,onChange:I=>k({title:I.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.type}),n.jsx(ae,{value:e.type,onChange:I=>k({type:I}),items:ne,placeholder:w.field.selectType,disabled:d})]})]}),n.jsxs("div",{style:al,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.management}),n.jsx(ae,{value:e.management,onChange:I=>k({management:I}),items:V,placeholder:w.field.select,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.department}),n.jsx(ae,{value:e.department,onChange:I=>k({department:I}),items:W,placeholder:w.field.select,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.section}),n.jsx("input",{style:{...E,...C},value:e.section_field||"",disabled:d,onChange:I=>k({section_field:I.target.value})})]})]}),n.jsxs("div",{style:Ds,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.branch}),n.jsx(ae,{value:e.branch,onChange:I=>k({branch:I}),items:Q,placeholder:w.field.select,disabled:d})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[w.field.status," ",n.jsx("span",{style:{fontSize:11,color:"#9ca3af",fontWeight:400},children:"(auto-updated from cycle)"})]}),n.jsx(ae,{value:e.status,onChange:I=>k({status:I}),items:ee,placeholder:w.field.selectStatus,disabled:d})]})]}),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:al,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.chainLocation}),n.jsxs("select",{style:{...E,...C},value:e.chain_location||"",disabled:d,onChange:I=>k({chain_location:I.target.value}),children:[n.jsx("option",{value:"",children:w.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:w.field.economyClass}),n.jsxs("select",{style:{...E,...C},value:e.economy_class||"",disabled:d,onChange:I=>k({economy_class:I.target.value}),children:[n.jsx("option",{value:"",children:w.field.select}),n.jsx("option",{value:"Expenses",children:w.field.expenses}),n.jsx("option",{value:"Capital",children:w.field.capital}),n.jsx("option",{value:"Earn",children:w.field.earn}),n.jsx("option",{value:"Pay/Loss",children:w.field.payLoss})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.impactLevel}),n.jsxs("select",{style:{...E,...C},value:e.impact_level||"",disabled:d,onChange:I=>k({impact_level:I.target.value}),children:[n.jsx("option",{value:"",children:w.field.select}),n.jsx("option",{value:"High",children:w.field.high}),n.jsx("option",{value:"Normal",children:w.field.normal})]})]})]}),n.jsxs("div",{style:al,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.entityScope}),n.jsxs("select",{style:{...E,...C},value:e.entity_scope||"",disabled:d,onChange:I=>k({entity_scope:I.target.value}),children:[n.jsx("option",{value:"",children:w.field.select}),n.jsx("option",{value:"Upstream",children:w.field.upstream}),n.jsx("option",{value:"On-stream",children:w.field.onstream}),n.jsx("option",{value:"Downstream",children:w.field.downstream})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.hsesField}),n.jsx("input",{style:{...E,...C},value:e.hses_field||"",disabled:d,onChange:I=>k({hses_field:I.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:d,onChange:I=>k({product_relation:I.target.checked?1:0})})," ",w.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:al,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.kpiName}),n.jsx("input",{style:{...E,...C},value:e.kpi_name||"",disabled:d,onChange:I=>k({kpi_name:I.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.kpiType}),n.jsxs("select",{style:{...E,...C},value:e.kpi_type||"",disabled:d,onChange:I=>k({kpi_type:I.target.value}),children:[n.jsx("option",{value:"",children:w.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:w.field.kpiMeasure}),n.jsx("input",{style:{...E,...C},value:e.kpi_measure||"",disabled:d,onChange:I=>k({kpi_measure:I.target.value}),placeholder:"Unit of measure"})]})]})]}),n.jsxs("div",{style:al,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.dateStart}),n.jsx(pe,{value:e.date_start,onChange:I=>k({date_start:I}),disabled:d,style:{...E,...C}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.dateEnd}),n.jsx(pe,{value:e.date_end,onChange:I=>k({date_end:I}),disabled:d,style:{...E,...C}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.cycleType}),n.jsxs("select",{style:{...E,...C},value:e.cycle_type||"",disabled:d,onChange:I=>k({cycle_type:I.target.value}),children:[n.jsx("option",{value:"",children:w.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:Ds,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 1"}),n.jsx(pe,{value:e.long_cycle_date_1||"",onChange:I=>k({long_cycle_date_1:I}),disabled:d,style:{...E,...C}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 2"}),n.jsx(pe,{value:e.long_cycle_date_2||"",onChange:I=>k({long_cycle_date_2:I}),disabled:d,style:{...E,...C}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 3"}),n.jsx(pe,{value:e.long_cycle_date_3||"",onChange:I=>k({long_cycle_date_3:I}),disabled:d,style:{...E,...C}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:"Milestone 4"}),n.jsx(pe,{value:e.long_cycle_date_4||"",onChange:I=>k({long_cycle_date_4:I}),disabled:d,style:{...E,...C}})]})]})]}),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"}),!d&&n.jsx("button",{type:"button",onClick:_e,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:13,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"}),!d&&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:d?14:15,style:{padding:18,textAlign:"center",color:"#aaa"},children:"No progress indicators"})}),(e.progress_indicators||[]).map((I,P)=>n.jsxs("tr",{style:{background:P%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C,width:60},value:I.order??"",disabled:d,onChange:F=>M(P,{order:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C},value:I.name1,disabled:d,onChange:F=>M(P,{name1:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...C},value:I.type,disabled:d,onChange:F=>M(P,{type:F.target.value}),children:[n.jsx("option",{children:"Nominal"}),n.jsx("option",{children:"Ordinal"}),n.jsx("option",{children:"Interval"}),n.jsx("option",{children:"Ratio"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C,width:70},type:"number",value:I.unit??"",disabled:d,onChange:F=>M(P,{unit:parseFloat(F.target.value)||""})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C},value:I.cycle,disabled:d,onChange:F=>M(P,{cycle:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C,width:80},value:I.target,disabled:d,onChange:F=>M(P,{target:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C,width:80},value:I.minimum,disabled:d,onChange:F=>M(P,{minimum:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C,width:80},value:I.maximum,disabled:d,onChange:F=>M(P,{maximum:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C},value:I.manager,disabled:d,onChange:F=>M(P,{manager:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C,width:90},type:"number",value:I.actual_value??"",disabled:d,onChange:F=>M(P,{actual_value:parseFloat(F.target.value)||""})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...C},value:I.cycle_status??"",disabled:d,onChange:F=>M(P,{cycle_status:F.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(pe,{value:I.cycle_date||"",onChange:F=>M(P,{cycle_date:F}),disabled:d,style:{...E,...C,width:110}})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C},value:I.cycle_comment??"",disabled:d,onChange:F=>M(P,{cycle_comment:F.target.value})})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...C},value:I.status??"",disabled:d,onChange:F=>M(P,{status:F.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"})]})}),!d&&n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("button",{type:"button",onClick:()=>R(P),style:{padding:"6px 10px",border:"1px solid #e74c3c",background:"white",color:"#e74c3c",borderRadius:6,cursor:"pointer"},children:"Remove"})})]},P))]})]})})]}),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:al,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.cycle}),n.jsx(ae,{value:e.cycle||"",onChange:I=>k({cycle:I}),items:de,placeholder:w.field.select,disabled:d})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.actor}),n.jsxs("select",{style:{...E,...C},value:e.actor||"",disabled:d,onChange:I=>k({actor:I.target.value}),children:[n.jsx("option",{value:"",children:w.field.select}),A.map(I=>n.jsx("option",{value:I.name,children:I.label},I.name))]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:w.field.costPerCycle}),n.jsx("input",{style:{...E,...C},type:"number",value:e.cost_per_cycle||"",disabled:d,onChange:I=>k({cost_per_cycle:parseFloat(I.target.value)||0}),placeholder:"0.00"})]})]}),n.jsxs("div",{style:{marginTop:12},children:[n.jsx("label",{style:T,children:w.field.escalationLevel}),n.jsx("input",{style:{...E,...C,maxWidth:120},type:"number",value:e.escalation_level||"",disabled:d,onChange:I=>k({escalation_level:parseInt(I.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"}),!d&&n.jsx("button",{type:"button",onClick:H,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:13,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"}),!d&&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:d?5:6,style:{padding:18,textAlign:"center",color:"#aaa"},children:"No cycle history"})}),(e.cycle_logs||[]).map((I,P)=>n.jsxs("tr",{style:{background:P%2===0?"white":"#fafafa"},children:[n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...C},value:I.cycle||"",disabled:d,onChange:F=>$(P,{cycle:F.target.value}),children:[n.jsx("option",{value:"",children:"-- Select --"}),de.map(F=>n.jsx("option",{value:F.name,children:F.label},F.name))]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx(pe,{value:I.cycle_date||"",onChange:F=>$(P,{cycle_date:F}),disabled:d,style:{...E,...C,width:130}})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...C},value:I.status,disabled:d,onChange:F=>$(P,{status:F.target.value}),children:[n.jsx("option",{value:"Pass",children:"Pass"}),n.jsx("option",{value:"Fail",children:"Fail"}),n.jsx("option",{value:"Unknown",children:"Unknown"})]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsxs("select",{style:{...E,...C},value:I.actor||"",disabled:d,onChange:F=>$(P,{actor:F.target.value}),children:[n.jsx("option",{value:"",children:"-- Select --"}),A.map(F=>n.jsx("option",{value:F.name,children:F.label},F.name))]})}),n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("input",{style:{...E,...C},value:I.comment||"",disabled:d,onChange:F=>$(P,{comment:F.target.value})})}),!d&&n.jsx("td",{style:{padding:"10px 12px"},children:n.jsx("button",{type:"button",onClick:()=>q(P),style:{padding:"6px 10px",border:"1px solid #e74c3c",background:"white",color:"#e74c3c",borderRadius:6,cursor:"pointer"},children:"Remove"})})]},P))]})]})})]}),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:w.field.auditorComment}),n.jsx("textarea",{style:{...E,height:80,resize:"vertical",...d?{background:"#f9f9f9"}:{}},value:e.auditor_comment||"",disabled:d,onChange:I=>k({auditor_comment:I.target.value}),placeholder:w.field.commentPlaceholder})]})]})}const lu={"SB Process":"processes-form","SB Order":"orders-form","SB Incident":"incidents-form","SB Idea":"ideas-form","SB Delegation":"delegations"};function Vy(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 e1({notifCount:e,darkMode:t,onCountChange:l,onToggleDark:r,onViewProfile:s,onLogout:i,onNavigate:a}){const[c,u]=S.useState(!1),[h,f]=S.useState([]),[p,d]=S.useState(!1),g=S.useRef(null);S.useEffect(()=>{const C=O=>{g.current&&!g.current.contains(O.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]);const j=async()=>{d(!0);const C=await qm(30);f(C),d(!1)},m=()=>{const C=!c;u(C),C&&j()},z=async()=>{await Zm(),f(C=>C.map(O=>({...O,read:1}))),l(0)},y=C=>{C.read||(Vm(C.name),f(U=>U.map(X=>X.name===C.name?{...X,read:1}:X)),l(Math.max(0,e-1)));const O=C.document_type?lu[C.document_type]:void 0;O&&a&&(a(O,C.document_type==="SB Delegation"?void 0:C.document_name),u(!1))},o=h.filter(C=>!C.read).length,x=C=>({position:"relative",width:38,height:38,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:t?"#2d3748":"#f3f4f6",color:t?"#e2e8f0":"#6b7280",fontSize:16,transition:"background 0.15s",flexShrink:0,...C}),v=t,b=v?"#1a202c":"white",w=v?"#2d3748":"#e5e7eb",k=v?"#e2e8f0":"#1a2332";return n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("button",{style:x({background:"#4f46e5",color:"white"}),onClick:s,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:g,style:{position:"relative"},children:[n.jsxs("button",{style:x(),onClick:m,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})]}),c&&n.jsxs("div",{style:{position:"absolute",right:0,top:"calc(100% + 8px)",width:340,background:b,borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.2)",zIndex:1e4,border:`1px solid ${w}`,overflow:"hidden"},children:[n.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${w}`,display:"flex",alignItems:"center",justifyContent:"space-between",background:b},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:k},children:["Notifications",o>0&&n.jsxs("span",{style:{background:"#ef4444",color:"white",fontSize:10,fontWeight:700,borderRadius:999,padding:"2px 7px"},children:[o," new"]})]}),o>0&&n.jsx("button",{onClick:z,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&&h.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&&h.map(C=>{const O=!!(C.document_type&&lu[C.document_type]&&a);return n.jsxs("div",{onClick:()=>y(C),style:{padding:"11px 16px",borderBottom:`1px solid ${v?"#2d3748":"#f5f5f5"}`,display:"flex",gap:10,background:C.read?b:v?"#1e3a5f":"#eff6ff",cursor:O?"pointer":"default",transition:"background 0.12s"},onMouseEnter:U=>{O&&(U.currentTarget.style.background=v?"#243244":"#e0ecfd")},onMouseLeave:U=>{U.currentTarget.style.background=C.read?b:v?"#1e3a5f":"#eff6ff"},children:[n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:13,fontWeight:C.read?400:600,color:k,marginBottom:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.subject||`${C.document_type}: ${C.document_name}`}),n.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:C.document_type&&n.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#3b82f6",background:v?"rgba(59,130,246,0.15)":"#eff6ff",padding:"1px 7px",borderRadius:8},children:[C.document_type.replace("SB ",""),C.document_name?` · ${C.document_name}`:""]})}),n.jsx("div",{style:{fontSize:11,color:"#aaa",marginTop:3},children:Vy(C.creation)})]}),!C.read&&n.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:"#3498db",flexShrink:0,marginTop:5}})]},C.name)})]})]})]}),n.jsx("button",{style:x(),onClick:Pf,title:_l()?"Switch to English":"Switch to Arabic",children:n.jsx("span",{style:{fontSize:13,fontWeight:700,fontFamily:"serif"},children:"عA"})}),n.jsx("button",{style:x(),onClick:r,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:x({background:v?"#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"})]})})]})}const t1={Admin:"#7c3aed",Auditor:"#d97706",Owner:"#0369a1",XAuditor:"#0f766e",Manager:"#2563eb",Employee:"#6b7280",Chairman:"#0f766e"};function n1({user:e,profileUser:t,darkMode:l,canModify:r,onBack:s,organizations:i=[],managements:a=[],departments:c=[],branches:u=[]}){const h=t||{},f=!!r&&e.role==="Admin",[p,d]=S.useState({first_name:h.first_name||"",middle_name:h.middle_name||"",last_name:h.last_name||"",mobile_no:h.mobile_no||"",custom_organization:h.custom_organization||"",custom_management:h.custom_management||"",custom_department:h.custom_department||"",custom_branch:h.custom_branch||"",custom_number:h.custom_number||"",custom_category:h.custom_category||""}),[g,j]=S.useState(""),[m,z]=S.useState(!1),[y,o]=S.useState({new:"",confirm:""}),[x,v]=S.useState(""),b=h.email||h.name||"",w=[p.first_name,p.middle_name,p.last_name].filter(Boolean).join(" ")||h.full_name||"",k=h.username||h.name||"",C=p.custom_category||"",O=h.enabled===0?"Inactive":"Active",U=t1[e.role]||"#6b7280",X=l,V=X?"#0f172a":"#f0f2f5",W=X?"#1e293b":"white",Q=X?"#2d3748":"#e5e7eb",ne=X?"#e2e8f0":"#1a2332",ee=X?"#94a3b8":"#6b7280",de=X?"#374151":"white",A=X?"#2d3748":"#f9fafb",$={width:"100%",padding:"9px 12px",borderRadius:8,border:`1px solid ${Q}`,fontSize:13,background:de,color:ne,fontFamily:"inherit",outline:"none"},H={...$,background:A,color:ee},q={...$,cursor:"pointer"},M={fontSize:12,fontWeight:600,color:ee,marginBottom:5,display:"block"},_e={display:"grid",gridTemplateColumns:"1fr 1fr",gap:14},R={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:14},Z=async()=>{if(r){j("saving");try{await bi("User",h.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}),j("saved"),setTimeout(()=>j(""),2e3)}catch{j("error"),setTimeout(()=>j(""),3e3)}}},Te=async()=>{if(!y.new){v("Enter a new password");return}if(y.new!==y.confirm){v("Passwords do not match");return}v("saving");try{await Rf(h.name,y.new),v("done"),o({new:"",confirm:""}),setTimeout(()=>{v(""),z(!1)},2e3)}catch{v("error")}},Qe=({title:I,icon:P,children:F})=>n.jsxs("div",{style:{background:W,borderRadius:12,padding:22,border:`1px solid ${Q}`,boxShadow:`0 1px 4px rgba(0,0,0,${X?.3:.06})`},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:18,paddingBottom:14,borderBottom:`1px solid ${Q}`},children:[P,n.jsx("span",{style:{fontSize:14,fontWeight:700,color:ne},children:I})]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:14},children:F})]});return n.jsxs("div",{style:{background:V,minHeight:"100%",padding:"0 0 32px"},children:[n.jsxs("div",{style:{background:W,borderBottom:`1px solid ${Q}`,padding:"12px 28px",display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[n.jsxs("button",{onClick:s,style:{display:"flex",alignItems:"center",gap:7,background:"none",border:"none",cursor:"pointer",fontSize:15,fontWeight:700,color:ne,fontFamily:"inherit"},children:[n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:n.jsx("polyline",{points:"15,18 9,12 15,6"})}),"User Profile"]}),r&&n.jsxs("button",{onClick:Z,style:{display:"flex",alignItems:"center",gap:8,background:g==="saved"?"#16a34a":g==="error"?"#dc2626":"#16a34a",color:"white",border:"none",borderRadius:8,padding:"9px 22px",fontSize:13,fontWeight:700,cursor:"pointer",fontFamily:"inherit"},children:[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"})]}),g==="saving"?"Saving…":g==="saved"?"Saved!":g==="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:w||b}),n.jsx("div",{style:{fontSize:12,color:"rgba(255,255,255,0.75)",textAlign:"center"},children:b})]}),n.jsx("div",{style:{background:W},children:[{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:U,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:k},{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:U,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:C||"—"},{icon:n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:O==="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:O,valueColor:O==="Active"?"#16a34a":"#dc2626"},{icon:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:U,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:b},{icon:n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:U,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:I,label:P,value:F,valueColor:Ln})=>n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 16px",borderBottom:`1px solid ${Q}`},children:[n.jsx("div",{style:{flexShrink:0,width:18,display:"flex",justifyContent:"center"},children:I}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:11,color:ee,marginBottom:1},children:P}),n.jsx("div",{style:{fontSize:13,fontWeight:600,color:Ln||ne,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:F})]})]},P))})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:18},children:[n.jsxs(Qe,{title:"Basic Information",icon:n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("circle",{cx:"12",cy:"8",r:"4"}),n.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]}),children:[n.jsxs("div",{style:_e,children:[n.jsxs("div",{children:[n.jsxs("label",{style:M,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:{...H,paddingLeft:32},value:b,readOnly:!0})]})]}),n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["Full Name ",n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Auto-generated)"})]}),n.jsx("input",{style:H,value:w,readOnly:!0})]})]}),n.jsxs("div",{style:R,children:[n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["First Name ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{style:r?$:H,value:p.first_name,readOnly:!r,onChange:I=>d(P=>({...P,first_name:I.target.value})),placeholder:"First name"})]}),n.jsxs("div",{children:[n.jsx("label",{style:M,children:"Middle Name"}),n.jsx("input",{style:r?$:H,value:p.middle_name,readOnly:!r,onChange:I=>d(P=>({...P,middle_name:I.target.value})),placeholder:"Middle name"})]}),n.jsxs("div",{children:[n.jsx("label",{style:M,children:"Last Name"}),n.jsx("input",{style:r?$:H,value:p.last_name,readOnly:!r,onChange:I=>d(P=>({...P,last_name:I.target.value})),placeholder:"Last name"})]})]}),n.jsxs("div",{style:_e,children:[n.jsxs("div",{children:[n.jsx("label",{style:M,children:"Phone Number"}),n.jsx("input",{style:r?$:H,value:p.mobile_no,readOnly:!r,onChange:I=>d(P=>({...P,mobile_no:I.target.value})),placeholder:"Phone number"})]}),n.jsxs("div",{children:[n.jsx("label",{style:M,children:"User ID No"}),n.jsxs("div",{style:{position:"relative"},children:[n.jsx("input",{style:{...H,paddingRight:44},value:p.custom_number||h.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:M,children:["Category ",!f&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),f?n.jsxs("select",{style:q,value:p.custom_category,onChange:I=>d(P=>({...P,custom_category:I.target.value})),children:[n.jsx("option",{value:"",children:"Select category"}),["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"].map(I=>n.jsx("option",{value:I,children:I},I))]}):n.jsx("input",{style:H,value:C||"—",readOnly:!0})]})]}),n.jsxs(Qe,{title:"Organization Information",icon:n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#8b5cf6",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),n.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),children:[n.jsxs("div",{style:_e,children:[n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["Organization ",!f&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),f?n.jsxs("select",{style:q,value:p.custom_organization,onChange:I=>d(P=>({...P,custom_organization:I.target.value})),children:[n.jsx("option",{value:"",children:"Select organization"}),ce(i,p.custom_organization).map(I=>n.jsx("option",{value:I.name,children:I.organization_name||I.name},I.name))]}):n.jsx("input",{style:H,value:p.custom_organization||"—",readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["Management ",!f&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),f?n.jsxs("select",{style:q,value:p.custom_management,onChange:I=>d(P=>({...P,custom_management:I.target.value})),children:[n.jsx("option",{value:"",children:"Select management"}),ce(a,p.custom_management).map(I=>n.jsx("option",{value:I.name,children:I.name1||I.name},I.name))]}):n.jsx("input",{style:H,value:p.custom_management||"—",readOnly:!0})]})]}),n.jsxs("div",{style:_e,children:[n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["Department ",!f&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),f?n.jsxs("select",{style:q,value:p.custom_department,onChange:I=>d(P=>({...P,custom_department:I.target.value})),children:[n.jsx("option",{value:"",children:"Select department"}),ce(c,p.custom_department).map(I=>n.jsx("option",{value:I.name,children:I.department_name||I.name},I.name))]}):n.jsx("input",{style:H,value:p.custom_department||"—",readOnly:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["Branch ",!f&&n.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),f?n.jsxs("select",{style:q,value:p.custom_branch,onChange:I=>d(P=>({...P,custom_branch:I.target.value})),children:[n.jsx("option",{value:"",children:"Select branch"}),ce(u,p.custom_branch).map(I=>n.jsx("option",{value:I.name,children:I.branch||I.name},I.name))]}):n.jsx("input",{style:H,value:p.custom_branch||"—",readOnly:!0})]})]})]}),n.jsxs("div",{style:{background:W,borderRadius:12,padding:22,border:`1px solid ${Q}`,boxShadow:`0 1px 4px rgba(0,0,0,${X?.3:.06})`},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[n.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",children:[n.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),n.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),n.jsx("span",{style:{fontSize:14,fontWeight:700,color:ne},children:"Change Password"})]}),r&&n.jsx("button",{onClick:()=>{z(I=>!I),v("")},style:{fontSize:13,color:"#3b82f6",background:"none",border:"none",cursor:"pointer",fontWeight:600,fontFamily:"inherit"},children:m?"Cancel":"Change Password"})]}),m&&n.jsxs("div",{style:{marginTop:18,display:"flex",flexDirection:"column",gap:12},children:[n.jsxs("div",{style:R,children:[n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["New Password ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{type:"password",style:$,value:y.new,onChange:I=>o(P=>({...P,new:I.target.value})),placeholder:"New password"})]}),n.jsxs("div",{children:[n.jsxs("label",{style:M,children:["Confirm Password ",n.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.jsx("input",{type:"password",style:$,value:y.confirm,onChange:I=>o(P=>({...P,confirm:I.target.value})),placeholder:"Confirm password"})]}),n.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:n.jsx("button",{onClick:Te,style:{width:"100%",padding:"9px 0",borderRadius:8,border:"none",background:"#2563eb",color:"white",fontWeight:700,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:x==="saving"?"Saving…":"Update Password"})})]}),x&&x!=="saving"&&n.jsx("div",{style:{fontSize:13,color:x==="done"?"#16a34a":"#dc2626",fontWeight:500},children:x==="done"?"Password updated successfully":x==="error"?"Failed to update password":x})]})]})]})]})]})}function ke({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 Of={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151",boxSizing:"border-box"},l1={...Of,cursor:"pointer"};function it({filters:e,defaultOpen:t=!1}){const[l,r]=S.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:()=>r(s=>!s),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((s,i)=>n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:s.label}),s.type==="search"?n.jsx("input",{style:Of,placeholder:s.placeholder,value:s.value,onChange:a=>s.onChange(a.target.value)}):n.jsx("select",{style:l1,value:s.value,onChange:a=>s.onChange(a.target.value),children:s.options.map(a=>n.jsx("option",{value:a.value,children:a.label},a.value))})]},i))})})]})}function r1(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 s1({organizations:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),[f,p]=S.useState("all"),d={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},g=S.useMemo(()=>e.filter(y=>{const o=[y.organization_name,y.city].filter(Boolean).join(" ").toLowerCase();return!(a&&!o.includes(a.toLowerCase())||u!=="all"&&y.type!==u||f!=="all"&&(y.is_active?"Active":"Inactive")!==f)}),[e,a,u,f]),[j,m]=S.useState(1);S.useEffect(()=>{m(1)},[a,u,f]);const z=g.slice((j-1)*te,j*te);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(ke,{label:"Total",val:g.length,color:"#1a2332"}),n.jsx(ke,{label:"Active",val:g.filter(y=>y.is_active).length,color:N.green}),n.jsx(ke,{label:"Government",val:g.filter(y=>y.type==="Government").length,color:N.blue}),n.jsx(ke,{label:"Private",val:g.filter(y=>y.type==="Private").length,color:N.orange})]}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Name or city…"},{type:"select",label:i.col.type,value:u,onChange:h,options:[{value:"all",label:"All"},{value:"Government",label:"Government"},{value:"Private",label:"Private"}]},{type:"select",label:"Status",value:f,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:d,children:i.col.name}),n.jsx("th",{style:d,children:i.col.type}),n.jsx("th",{style:d,children:i.col.city}),n.jsx("th",{style:d,children:i.field.creationDate}),n.jsx("th",{style:d,children:i.col.status}),n.jsx("th",{style:d,children:i.col.actions})]})}),n.jsx("tbody",{children:g.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):z.map((y,o)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(y),style:{borderTop:"1px solid #f0f0f0",background:o%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:y.organization_name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:y.type||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:y.city||"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:r1(y.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:Pn(y.is_active?i.field.statusActive:i.field.statusInactive,y.is_active?N.green:N.gray)}),n.jsx("td",{style:{padding:"10px 18px"},onClick:x=>x.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(y),onEdit:t&&r?()=>r(y):void 0,onDelete:t&&s?()=>s(y.name):void 0})})]},y.name))})]})}),n.jsx(Oe,{page:j,total:g.length,onPageChange:m})]})}const Qt=e=>({background:e?"#f9f9f9":void 0});function i1({orgForm:e,setOrgForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=e.name?r&&e.organization_name||h.formTitle.editOrg:h.formTitle.newOrg;return n.jsxs(De,{title:f,activePage:"organizations",user:u,formStatus:l,buttonText:h.saveOrg,buttonColor:N.accent,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.orgName}),n.jsx("input",{type:"text",style:{...E,...Qt(r)},value:e.organization_name,disabled:r,onChange:p=>t({...e,organization_name:p.target.value})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.orgAcronym}),n.jsx("input",{type:"text",style:{...E,...Qt(r)},value:e.acronym||"",disabled:r,onChange:p=>t({...e,acronym:p.target.value})})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.organizationType}),n.jsxs("select",{style:{...E,...Qt(r)},value:e.type,disabled:r,onChange:p=>t({...e,type:p.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:h.field.orgCity}),n.jsx("input",{type:"text",style:{...E,...Qt(r)},value:e.city,disabled:r,onChange:p=>t({...e,city:p.target.value})})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.contactEmail}),n.jsx("input",{type:"email",style:{...E,...Qt(r)},value:e.contact_email,disabled:r,onChange:p=>t({...e,contact_email:p.target.value})})]}),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(pe,{value:e.creation_date||"",onChange:p=>t({...e,creation_date:p}),disabled:r,style:{...E,...Qt(r)}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...Qt(r)},value:e.is_active?"Active":"Inactive",disabled:r,onChange:p=>t({...e,is_active:p.target.value==="Active"?1:0}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.incidentTriageWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...E,...Qt(r)},value:e.incident_triage_window_days??3,disabled:r,onChange:p=>t({...e,incident_triage_window_days:parseInt(p.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:h.field.incidentResolutionWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...E,...Qt(r)},value:e.incident_resolution_window_days??5,disabled:r,onChange:p=>t({...e,incident_resolution_window_days:parseInt(p.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 a1(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 o1({managements:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.blue})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:a1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function c1({form:e,setForm:t,organizations:l,formStatus:r,viewMode:s,onSubmit:i,onBack:a,onNavigate:c,onLogout:u,user:h}){const f=J(),p=j=>t(m=>({...m,...j})),d=s?{background:"#f9f9f9"}:{},g=e.name?s?`${f.formTitle.editMgmt}: ${e.name1||e.name}`:f.formTitle.editMgmt:f.formTitle.newMgmt;return n.jsxs(De,{title:g,activePage:"managements",user:h,formStatus:r,buttonText:f.saveMgmt,buttonColor:N.blue,viewMode:s,onSubmit:i,onBack:a,onNavigate:c,onLogout:u,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.organization}),n.jsx(Ct,{value:e.organization,onChange:j=>p({organization:j}),organizations:l,disabled:s})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[f.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...d},value:e.name1,disabled:s,onChange:j=>p({name1:j.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:f.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:j=>p({creation_date:j}),disabled:s,style:{...E,...d}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.status}),n.jsxs("select",{style:{...E,...d},value:e.status||"Active",disabled:s,onChange:j=>p({status:j.target.value}),children:[n.jsx("option",{value:"Active",children:f.field.statusActive}),n.jsx("option",{value:"Inactive",children:f.field.statusInactive})]})]})]})]})}function d1(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 u1({departments:e,managements:t,canModify:l,onView:r,onEdit:s,onDelete:i}){const a=J(),[c,u]=S.useState(""),[h,f]=S.useState(""),[p,d]=S.useState("all"),g=x=>{var v;return((v=t.find(b=>b.name===x))==null?void 0:v.name1)||x||"—"},j={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},m=S.useMemo(()=>e.filter(x=>{const v=(x.department_name||x.name||"").toLowerCase();return!(c&&!v.includes(c.toLowerCase())||h&&x.custom_management!==h||p!=="all"&&(x.custom_status||"Active")!==p)}),[e,c,h,p]),[z,y]=S.useState(1);S.useEffect(()=>{y(1)},[c,h,p]);const o=m.slice((z-1)*te,z*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:m.length,color:N.teal})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:c,onChange:u,placeholder:"Search by name…"},{type:"select",label:a.col.management,value:h,onChange:f,options:[{value:"",label:"All Managements"},...t.map(x=>({value:x.name,label:x.name1||x.name}))]},{type:"select",label:"Status",value:p,onChange:d,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:j,children:a.col.name}),n.jsx("th",{style:j,children:a.col.management}),n.jsx("th",{style:j,children:a.field.creationDate}),n.jsx("th",{style:j,children:a.field.status}),n.jsx("th",{style:j,children:a.col.actions})]})}),n.jsx("tbody",{children:m.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):o.map((x,v)=>n.jsxs("tr",{onClick:()=>r==null?void 0:r(x),style:{borderTop:"1px solid #f0f0f0",background:v%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:x.department_name||x.name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:g(x.custom_management)}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:d1(x.custom_creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:x.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:x.custom_status==="Inactive"?a.field.statusInactive:a.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:b=>b.stopPropagation(),children:n.jsx(Ke,{onView:()=>r==null?void 0:r(x),onEdit:l&&s?()=>s(x):void 0,onDelete:l&&i?()=>i(x.name):void 0})})]},x.name))})]})}),n.jsx(Oe,{page:z,total:m.length,onPageChange:y})]})}const p1={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20};function f1({form:e,setForm:t,organizations:l,managements:r,formStatus:s,viewMode:i,onSubmit:a,onBack:c,onNavigate:u,onLogout:h,user:f}){const p=J(),d=z=>t(y=>({...y,...z})),g=i?{background:"#f9f9f9"}:{},j=e.name?i?`${p.formTitle.editDept}: ${e.department_name||e.name}`:p.formTitle.editDept:p.formTitle.newDept,m=ce(r,e.custom_management).map(z=>({name:z.name,label:z.name1||z.name}));return n.jsxs(De,{title:j,activePage:"departments",user:f,formStatus:s,buttonText:p.saveDept,buttonColor:N.teal,viewMode:i,onSubmit:a,onBack:c,onNavigate:u,onLogout:h,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:p.field.organization}),n.jsx(Ct,{value:e.custom_organization,onChange:z=>d({custom_organization:z}),organizations:l,disabled:i})]}),n.jsxs("div",{style:p1,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[p.field.department," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...g},value:e.department_name,disabled:i,onChange:z=>d({department_name:z.target.value}),placeholder:"Department name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:p.field.management}),n.jsx(ae,{value:e.custom_management,onChange:z=>d({custom_management:z}),items:m,placeholder:p.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:p.field.creationDate}),n.jsx(pe,{value:e.custom_creation_date||"",onChange:z=>d({custom_creation_date:z}),disabled:i,style:{...E,...g}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:p.field.status}),n.jsxs("select",{style:{...E,...g},value:e.custom_status||"Active",disabled:i,onChange:z=>d({custom_status:z.target.value}),children:[n.jsx("option",{value:"Active",children:p.field.statusActive}),n.jsx("option",{value:"Inactive",children:p.field.statusInactive})]})]})]})]})}function h1(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 g1({branches:e,managements:t,departments:l,canModify:r,onView:s,onEdit:i,onDelete:a}){const c=J(),[u,h]=S.useState(""),[f,p]=S.useState(""),[d,g]=S.useState(""),[j,m]=S.useState("all"),z=k=>{var C;return((C=t.find(O=>O.name===k))==null?void 0:C.name1)||k||"—"},y=k=>{var C;return((C=l.find(O=>O.name===k))==null?void 0:C.department_name)||k||"—"},o={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},x=S.useMemo(()=>e.filter(k=>{const C=(k.branch||k.name||"").toLowerCase();return!(u&&!C.includes(u.toLowerCase())||f&&k.management!==f||d&&k.department!==d||j!=="all"&&(k.custom_status||"Active")!==j)}),[e,u,f,d,j]),[v,b]=S.useState(1);S.useEffect(()=>{b(1)},[u,f,d,j]);const w=x.slice((v-1)*te,v*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:x.length,color:N.purple})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:u,onChange:h,placeholder:"Search by name…"},{type:"select",label:c.col.management,value:f,onChange:p,options:[{value:"",label:"All Managements"},...t.map(k=>({value:k.name,label:k.name1||k.name}))]},{type:"select",label:c.col.department,value:d,onChange:g,options:[{value:"",label:"All Departments"},...l.map(k=>({value:k.name,label:k.department_name||k.name}))]},{type:"select",label:"Status",value:j,onChange:m,options:[{value:"all",label:"All"},{value:"Active",label:c.field.statusActive},{value:"Inactive",label:c.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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:o,children:c.col.branch}),n.jsx("th",{style:o,children:c.col.management}),n.jsx("th",{style:o,children:c.col.department}),n.jsx("th",{style:o,children:c.field.creationDate}),n.jsx("th",{style:o,children:c.field.status}),n.jsx("th",{style:o,children:c.col.actions})]})}),n.jsx("tbody",{children:x.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:c.noData})}):w.map((k,C)=>n.jsxs("tr",{onClick:()=>s==null?void 0:s(k),style:{borderTop:"1px solid #f0f0f0",background:C%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:k.branch||k.name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:z(k.management)}),n.jsx("td",{style:{padding:"12px 18px"},children:y(k.department)}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:h1(k.custom_creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:k.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:k.custom_status==="Inactive"?c.field.statusInactive:c.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:O=>O.stopPropagation(),children:n.jsx(Ke,{onView:()=>s==null?void 0:s(k),onEdit:r&&i?()=>i(k):void 0,onDelete:r&&a?()=>a(k.name):void 0})})]},k.name))})]})}),n.jsx(Oe,{page:v,total:x.length,onPageChange:b})]})}const x1={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20};function m1({form:e,setForm:t,organizations:l,managements:r,departments:s,formStatus:i,viewMode:a,onSubmit:c,onBack:u,onNavigate:h,onLogout:f,user:p}){const d=J(),g=o=>t(x=>({...x,...o})),j=a?{background:"#f9f9f9"}:{},m=e.name?a?`${d.formTitle.editBranch}: ${e.branch||e.name}`:d.formTitle.editBranch:d.formTitle.newBranch,z=ce(r,e.management).map(o=>({name:o.name,label:o.name1||o.name})),y=ce(s,e.department).map(o=>({name:o.name,label:o.department_name||o.name}));return n.jsxs(De,{title:m,activePage:"branches",user:p,formStatus:i,buttonText:d.saveBranch,buttonColor:N.purple,viewMode:a,onSubmit:c,onBack:u,onNavigate:h,onLogout:f,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:d.field.organization}),n.jsx(Ct,{value:e.organization,onChange:o=>g({organization:o}),organizations:l,disabled:a})]}),n.jsxs("div",{style:x1,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[d.field.branch," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...j},value:e.branch,disabled:a||!!e.name,onChange:o=>g({branch:o.target.value}),placeholder:"Branch name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:d.field.management}),n.jsx(ae,{value:e.management,onChange:o=>g({management:o}),items:z,placeholder:d.field.select,disabled:a})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:d.field.department}),n.jsx(ae,{value:e.department,onChange:o=>g({department:o}),items:y,placeholder:d.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:d.field.creationDate}),n.jsx(pe,{value:e.custom_creation_date||"",onChange:o=>g({custom_creation_date:o}),disabled:a,style:{...E,...j}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:d.field.status}),n.jsxs("select",{style:{...E,...j},value:e.custom_status||"Active",disabled:a,onChange:o=>g({custom_status:o.target.value}),children:[n.jsx("option",{value:"Active",children:d.field.statusActive}),n.jsx("option",{value:"Inactive",children:d.field.statusInactive})]})]})]})]})}function y1(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 v1({incidentTypes:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.red})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:y1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function j1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Incident Type: ${e.name1||e.name}`:"Edit Incident Type":"New Incident Type";return n.jsxs(De,{title:d,activePage:"incident-types",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.red,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.target.value}),placeholder:"Incident type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}function b1(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 S1({ideaTypes:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.teal})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:b1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function w1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Idea Type: ${e.name1||e.name}`:"Edit Idea Type":"New Idea Type";return n.jsxs(De,{title:d,activePage:"idea-types",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.teal,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.target.value}),placeholder:"Idea type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}function k1(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 _1({orderTypes:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.purple})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:k1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function C1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Order Type: ${e.name1||e.name}`:"Edit Order Type":"New Order Type";return n.jsxs(De,{title:d,activePage:"order-types",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.purple,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.target.value}),placeholder:"Order type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}function z1(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 T1({processTypes:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.blue})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:z1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function I1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Process Type: ${e.name1||e.name}`:"Edit Process Type":"New Process Type";return n.jsxs(De,{title:d,activePage:"process-types",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.blue,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.target.value}),placeholder:"Process type name",required:!0})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}function P1(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({incidentStatuses:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.red})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.notifyManager}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:P1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function A1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Incident Status: ${e.name1||e.name}`:"Edit Incident Status":"New Incident Status";return n.jsxs(De,{title:d,activePage:"incident-statuses",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.red,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.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:r,onChange:g=>f({notify_manager:g.target.checked?1:0}),style:$l}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:r?"default":"pointer"},children:h.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}function R1(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 L1({ideaStatuses:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.teal})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.notifyManager}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:R1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function O1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Idea Status: ${e.name1||e.name}`:"Edit Idea Status":"New Idea Status";return n.jsxs(De,{title:d,activePage:"idea-statuses",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.teal,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.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:r,onChange:g=>f({notify_manager:g.target.checked?1:0}),style:$l}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:r?"default":"pointer"},children:h.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}function D1(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 N1({orderStatuses:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.purple})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.notifyManager}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:D1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function W1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Order Status: ${e.name1||e.name}`:"Edit Order Status":"New Order Status";return n.jsxs(De,{title:d,activePage:"order-statuses",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.purple,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.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:r,onChange:g=>f({notify_manager:g.target.checked?1:0}),style:$l}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:r?"default":"pointer"},children:h.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}function B1(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 $1({processStatuses:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState("all"),f={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},p=S.useMemo(()=>e.filter(m=>{const z=(m.name1||m.name||"").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u!=="all"&&(m.status||"Active")!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total",val:p.length,color:N.blue})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:"Status",value:u,onChange:h,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:f,children:i.col.name}),n.jsx("th",{style:f,children:i.field.notifyManager}),n.jsx("th",{style:f,children:i.field.creationDate}),n.jsx("th",{style:f,children:i.field.status}),n.jsx("th",{style:f,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.name1||m.name||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.notify_manager?i.field.statusActive:"—"}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:B1(m.creation_date)}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{color:m.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:m.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}function U1({form:e,setForm:t,formStatus:l,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,user:u}){const h=J(),f=g=>t(j=>({...j,...g})),p=r?{background:"#f9f9f9"}:{},d=e.name?r?`Process Status: ${e.name1||e.name}`:"Edit Process Status":"New Process Status";return n.jsxs(De,{title:d,activePage:"process-statuses",user:u,formStatus:l,buttonText:h.saveName,buttonColor:N.blue,viewMode:r,onSubmit:s,onBack:i,onNavigate:a,onLogout:c,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[h.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...p},value:e.name1,disabled:r,onChange:g=>f({name1:g.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:r,onChange:g=>f({notify_manager:g.target.checked?1:0}),style:$l}),n.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:r?"default":"pointer"},children:h.field.notifyManager})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.creationDate}),n.jsx(pe,{value:e.creation_date||"",onChange:g=>f({creation_date:g}),disabled:r,style:{...E,...p}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:h.field.status}),n.jsxs("select",{style:{...E,...p},value:e.status||"Active",disabled:r,onChange:g=>f({status:g.target.value}),children:[n.jsx("option",{value:"Active",children:h.field.statusActive}),n.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})}const F1={Admin:"#7c3aed",Chairman:"#0f766e",Auditor:"#d97706","X-Auditor":"#8b5cf6",Manager:"#2563eb",Employee:"#6b7280"};function M1(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 H1({users:e,canModify:t,onView:l,onEdit:r,onDisable:s}){const i=J(),[a,c]=S.useState(!1),[u,h]=S.useState(""),[f,p]=S.useState(""),[d,g]=S.useState(""),[j,m]=S.useState("active"),[z,y]=S.useState(1),[o,x]=S.useState(null),[v,b]=S.useState(""),[w,k]=S.useState("idle"),[C,O]=S.useState(null),U=async()=>{if(!(!o||!v.trim())){k("loading");try{await Rf(o.name,v.trim()),k("success"),setTimeout(()=>{x(null),b(""),k("idle")},1200)}catch{k("error")}}},X=async A=>{if(window.confirm(i.users.disableConfirm)){O(A);try{await(s==null?void 0:s(A))}finally{O(null)}}},V=e.filter(A=>{if(j==="active"&&(A.enabled===0||A.enabled==="0")||j==="inactive"&&A.enabled!==0&&A.enabled!=="0")return!1;const $=A.custom_category||"";if(d&&$!==d)return!1;const H=A.custom_organization||"";if(f&&!H.toLowerCase().includes(f.toLowerCase()))return!1;if(u){const q=u.toLowerCase();if(![A.full_name,A.email,A.name,A.username,A.mobile_no].join(" ").toLowerCase().includes(q))return!1}return!0}),W=[...new Set(e.map(A=>A.custom_organization).filter(Boolean))],Q=["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"];S.useEffect(()=>{y(1)},[u,f,d,j]);const ne=V.slice((z-1)*te,z*te),ee={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151"},de={...ee,cursor:"pointer"};return n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,flex:1},children:[n.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:16},children:["Total: ",V.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:()=>c(A=>!A),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:a?n.jsx("polyline",{points:"18,15 12,9 6,15"}):n.jsx("polyline",{points:"6,9 12,15 18,9"})}),n.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),n.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),a&&n.jsx("div",{style:{padding:"18px 20px",display:"flex",flexDirection:"column",gap:14},children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:14},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Search"}),n.jsx("input",{style:ee,placeholder:"Name, email, username…",value:u,onChange:A=>h(A.target.value)})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Organization"}),n.jsxs("select",{style:de,value:f,onChange:A=>p(A.target.value),children:[n.jsx("option",{value:"",children:"All Organizations"}),W.map(A=>n.jsx("option",{value:A,children:A},A))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Category"}),n.jsxs("select",{style:de,value:d,onChange:A=>g(A.target.value),children:[n.jsx("option",{value:"",children:"All Categories"}),Q.map(A=>n.jsx("option",{value:A,children:A},A))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Status"}),n.jsxs("select",{style:de,value:j,onChange:A=>m(A.target.value),children:[n.jsx("option",{value:"all",children:"All"}),n.jsx("option",{value:"active",children:"Active"}),n.jsx("option",{value:"inactive",children:"Inactive"})]})]})]})})]}),n.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa",borderBottom:"2px solid #f0f0f0"},children:[{label:"Category",w:100},{label:"Number",w:80},{label:"Full Name",w:140},{label:"Username",w:120},{label:"Email Address",w:180},{label:"Phone Number",w:120},{label:"Organization",w:130},{label:"Management",w:120},{label:"Department",w:120},{label:"Branch",w:100},{label:"Since",w:90},{label:"Status",w:80},{label:"Tools",w:200}].map(({label:A,w:$})=>n.jsx("th",{style:{padding:"11px 14px",textAlign:"left",color:"#6b7280",fontSize:11,fontWeight:700,whiteSpace:"nowrap",minWidth:$,letterSpacing:.3,textTransform:"uppercase"},children:A},A))})}),n.jsx("tbody",{children:V.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:13,style:{padding:"48px 20px",textAlign:"center",color:"#aaa",fontSize:14},children:"No users found"})}):ne.map((A,$)=>{const H=A.custom_category||"",q=F1[H]||"#6b7280";return n.jsxs("tr",{onClick:()=>l==null?void 0:l(A),style:{borderBottom:"1px solid #f3f4f6",background:$%2===0?"white":"#fafafa",transition:"background 0.1s",cursor:"pointer"},onMouseEnter:M=>M.currentTarget.style.background="#f0f7ff",onMouseLeave:M=>M.currentTarget.style.background=$%2===0?"white":"#fafafa",children:[n.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:H?n.jsx("span",{style:{background:q+"18",color:q,border:`1px solid ${q}44`,padding:"3px 10px",borderRadius:20,fontSize:11,fontWeight:700},children:H}):n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_number||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",fontWeight:600,color:"#1a2332",whiteSpace:"nowrap"},children:A.full_name||A.first_name||"—"}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:A.username||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:A.email||A.name}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.mobile_no||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:A.custom_organization||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_management||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_department||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:A.custom_branch||n.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),n.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:M1(A.creation)}),n.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:n.jsx("span",{style:{color:A.enabled?"#16a34a":"#dc2626",fontWeight:600},children:A.enabled?i.users.active:i.users.inactive})}),n.jsx("td",{style:{padding:"10px 14px",whiteSpace:"nowrap"},onClick:M=>M.stopPropagation(),children:n.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[n.jsx("button",{onClick:M=>{M.stopPropagation(),l==null||l(A)},title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:n.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),t&&r&&n.jsx("button",{onClick:M=>{M.stopPropagation(),r(A)},title:"Edit",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#dcfce7",color:"#16a34a"},children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),t&&n.jsx("button",{onClick:M=>{M.stopPropagation(),x({name:A.name,email:A.email||A.name}),b(""),k("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:M=>{M.stopPropagation(),X(A.name)},disabled:C===A.name,title:"Disable",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#fee2e2",color:"#ef4444",opacity:C===A.name?.5:1},children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6l-1 14H6L5 6"}),n.jsx("path",{d:"M10 11v6M14 11v6"}),n.jsx("path",{d:"M9 6V4h6v2"})]})})]})})]},A.name)})})]})}),n.jsx(Oe,{page:z,total:V.length,onPageChange:y}),o&&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:o.email})]}),n.jsx("input",{type:"password",value:v,onChange:A=>b(A.target.value),placeholder:i.users.newPassword,style:{width:"100%",padding:"10px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,boxSizing:"border-box",marginBottom:16,fontFamily:"Segoe UI",outline:"none"},onKeyDown:A=>A.key==="Enter"&&U(),autoFocus:!0}),w==="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"}),w==="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:U,disabled:w==="loading"||!v.trim(),style:{flex:1,padding:10,background:"#2563eb",color:"white",border:"none",borderRadius:8,cursor:"pointer",fontSize:13,fontWeight:700,fontFamily:"inherit",opacity:v.trim()?1:.5},children:w==="loading"?"Saving…":i.users.setPassword}),n.jsx("button",{onClick:()=>{x(null),b(""),k("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 pr={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20};function K1({form:e,setForm:t,organizations:l,managements:r,departments:s,branches:i,formStatus:a,viewMode:c,isSelfProfile:u,onSubmit:h,onBack:f,onNavigate:p,onLogout:d,user:g}){const j=J(),m=w=>t(k=>({...k,...w})),z=c?{background:"#f9f9f9"}:{},y=!e.name,o=u?"My Profile":y?"New User":c?`User: ${e.full_name||e.email}`:`Edit User: ${e.full_name||e.email}`,x=ce(r,e.custom_management).map(w=>({name:w.name,label:w.name1||w.name})),v=ce(s,e.custom_department).map(w=>({name:w.name,label:w.department_name||w.name})),b=ce(i,e.custom_branch).map(w=>({name:w.name,label:w.branch||w.name}));return n.jsxs(De,{title:o,activePage:"users",user:g,formStatus:a,buttonText:j.saveUser,buttonColor:N.blue,viewMode:c,hideSettings:u,onSubmit:h,onBack:f,onNavigate:p,onLogout:d,children:[n.jsxs("div",{style:pr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.organization}),n.jsx(Ct,{value:e.custom_organization,onChange:w=>m({custom_organization:w}),organizations:l,disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.management}),n.jsx(ae,{value:e.custom_management,onChange:w=>m({custom_management:w}),items:x,placeholder:"-- Select --",disabled:c})]})]}),n.jsxs("div",{style:pr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.department}),n.jsx(ae,{value:e.custom_department,onChange:w=>m({custom_department:w}),items:v,placeholder:"-- Select --",disabled:c})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.branch}),n.jsx(ae,{value:e.custom_branch,onChange:w=>m({custom_branch:w}),items:b,placeholder:"-- Select --",disabled:c})]})]}),n.jsxs("div",{style:pr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.number}),n.jsx("input",{style:{...E,...z},value:e.custom_number,disabled:c,onChange:w=>m({custom_number:w.target.value}),placeholder:"e.g. 10001"})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[j.field.fullName," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...z},value:e.first_name,disabled:c,onChange:w=>m({first_name:w.target.value}),placeholder:"Full name",required:!0})]})]}),n.jsxs("div",{style:pr,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.username}),n.jsx("input",{style:{...E,...z},value:e.username,disabled:c,onChange:w=>m({username:w.target.value}),placeholder:"Username"})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.phoneNumber}),n.jsx("input",{style:{...E,...z},value:e.mobile_no,disabled:c,onChange:w=>m({mobile_no:w.target.value}),placeholder:"Phone number"})]})]}),n.jsxs("div",{style:pr,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[j.field.emailAddress," ",y&&n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...c||!y?{background:"#f9f9f9"}:{}},value:e.email,disabled:c||!y,onChange:w=>m({email:w.target.value}),placeholder:"user@example.com",type:"email",required:y})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:j.field.category}),n.jsxs("select",{style:{...E,...z},value:e.custom_category,disabled:c,onChange:w=>m({custom_category:w.target.value}),children:[n.jsx("option",{value:"",children:j.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 ru={Active:N.green,Closed:N.gray};function Q1({cycles:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState(""),[f,p]=S.useState("all"),d=S.useMemo(()=>[...new Set(e.map(x=>x.organization).filter(Boolean))],[e]),g=S.useMemo(()=>e.filter(x=>{const v=(x.name1||x.name||"").toLowerCase();return!(a&&!v.includes(a.toLowerCase())||u&&x.organization!==u||f!=="all"&&x.status!==f)}),[e,a,u,f]),[j,m]=S.useState(1);S.useEffect(()=>{m(1)},[a,u,f]);const z=g.slice((j-1)*te,j*te),y=g.filter(x=>x.status==="Active").length,o=g.filter(x=>x.status==="Closed").length;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(ke,{label:"Total",val:g.length,color:N.teal}),n.jsx(ke,{label:"Active",val:y,color:N.green}),n.jsx(ke,{label:"Closed",val:o,color:N.gray})]}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Search by name…"},{type:"select",label:i.col.organization,value:u,onChange:h,options:[{value:"",label:"All Organizations"},...d.map(x=>({value:x,label:x}))]},{type:"select",label:"Status",value:f,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.name}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.organization}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.frequency}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.startDate}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.endDate}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.status}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.actions})]})}),n.jsx("tbody",{children:g.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):z.map((x,v)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(x),style:{borderTop:"1px solid #f0f0f0",background:v%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:x.name1||x.name}),n.jsx("td",{style:{padding:"12px 18px"},children:x.organization||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:x.frequency||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:x.start_date||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:x.end_date||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{padding:"3px 10px",borderRadius:12,fontSize:12,background:ru[x.status]+"22",color:ru[x.status]||"#666"},children:x.status})}),n.jsx("td",{style:{padding:"10px 18px"},onClick:b=>b.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(x),onEdit:t&&r?()=>r(x):void 0,onDelete:t&&s?()=>s(x.name):void 0})})]},x.name))})]})}),n.jsx(Oe,{page:j,total:g.length,onPageChange:m})]})}const wa={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},Y1=["Weekly","Bi-weekly","Monthly","Quarterly","Annually"],G1=["Active","Closed"];function X1({form:e,setForm:t,organizations:l,formStatus:r,viewMode:s,onSubmit:i,onBack:a,onNavigate:c,onLogout:u,user:h}){const f=J(),p=j=>t(m=>({...m,...j})),d=s?{background:"#f9f9f9"}:{},g=e.name?s?`${f.formTitle.editCycle}: ${e.name1||e.name}`:f.formTitle.editCycle:f.formTitle.newCycle;return n.jsxs(De,{title:g,activePage:"cycles",user:h,formStatus:r,buttonText:f.saveCycle,buttonColor:N.teal,viewMode:s,onSubmit:i,onBack:a,onNavigate:c,onLogout:u,children:[n.jsxs("div",{style:wa,children:[n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[f.field.name1," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...d},value:e.name1||"",disabled:s||!!e.name,onChange:j=>p({name1:j.target.value}),placeholder:"e.g. Q1-2026"})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.organization}),n.jsx(Ct,{value:e.organization,onChange:j=>p({organization:j}),organizations:l,disabled:s})]})]}),n.jsxs("div",{style:wa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.col.frequency}),n.jsx(ae,{value:e.frequency,onChange:j=>p({frequency:j}),items:Y1.map(j=>({name:j,label:j})),placeholder:"-- Select Frequency --",disabled:s})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.status}),n.jsx(ae,{value:e.status,onChange:j=>p({status:j}),items:G1.map(j=>({name:j,label:j})),placeholder:"-- Select Status --",disabled:s})]})]}),n.jsxs("div",{style:wa,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.dateStart}),n.jsx(pe,{value:e.start_date||"",onChange:j=>p({start_date:j}),disabled:s,style:{...E,...d}})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.dateEnd}),n.jsx(pe,{value:e.end_date||"",onChange:j=>p({end_date:j}),disabled:s,style:{...E,...d}})]})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.updateWindowDays}),n.jsx("input",{type:"number",min:1,max:30,style:{...E,...d,maxWidth:160},value:e.update_window_days??2,disabled:s,onChange:j=>p({update_window_days:parseInt(j.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 J1({kpiInputs:e,canModify:t,onView:l,onEdit:r,onDelete:s}){const i=J(),[a,c]=S.useState(""),[u,h]=S.useState(""),f=S.useMemo(()=>[...new Set(e.map(m=>m.organization).filter(Boolean))],[e]),p=S.useMemo(()=>e.filter(m=>{const z=[m.organization,m.period].filter(Boolean).join(" ").toLowerCase();return!(a&&!z.includes(a.toLowerCase())||u&&m.organization!==u)}),[e,a,u]),[d,g]=S.useState(1);S.useEffect(()=>{g(1)},[a,u]);const j=p.slice((d-1)*te,d*te);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{display:"flex",gap:16},children:n.jsx(ke,{label:"Total Records",val:p.length,color:N.blue})}),n.jsx(it,{filters:[{type:"search",label:"Search",value:a,onChange:c,placeholder:"Organization or period…"},{type:"select",label:i.col.organization,value:u,onChange:h,options:[{value:"",label:"All Organizations"},...f.map(m=>({value:m,label:m}))]}]}),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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.organization}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.col.period}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.field.revenue_growth}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.field.net_profit}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},children:i.dash.customerSat}),n.jsx("th",{style:{padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,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})}):j.map((m,z)=>n.jsxs("tr",{onClick:()=>l==null?void 0:l(m),style:{borderTop:"1px solid #f0f0f0",background:z%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:m.organization||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.period||"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.revenue_growth!=null?`${m.revenue_growth}%`:"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.net_profit!=null?m.net_profit.toLocaleString():"—"}),n.jsx("td",{style:{padding:"12px 18px"},children:m.customer_satisfaction!=null?m.customer_satisfaction:"—"}),n.jsx("td",{style:{padding:"10px 18px"},onClick:y=>y.stopPropagation(),children:n.jsx(Ke,{onView:()=>l==null?void 0:l(m),onEdit:t&&r?()=>r(m):void 0,onDelete:t&&s?()=>s(m.name):void 0})})]},m.name))})]})}),n.jsx(Oe,{page:d,total:p.length,onPageChange:g})]})}const su={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},iu={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:20};function q1({form:e,setForm:t,organizations:l,formStatus:r,viewMode:s,onSubmit:i,onBack:a,onNavigate:c,onLogout:u,user:h}){const f=J(),p=m=>t(z=>({...z,...m})),d=s?{background:"#f9f9f9"}:{},g=m=>z=>p({[m]:parseFloat(z.target.value)||0}),j=e.name?s?`${f.formTitle.editKpi}: ${e.period||e.name}`:f.formTitle.editKpi:f.formTitle.newKpi;return n.jsxs(De,{title:j,activePage:"kpi-input",user:h,formStatus:r,buttonText:f.saveKpi,buttonColor:N.blue,viewMode:s,onSubmit:i,onBack:a,onNavigate:c,onLogout:u,children:[n.jsxs("div",{style:su,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.organization}),n.jsx(Ct,{value:e.organization,onChange:m=>p({organization:m}),organizations:l,disabled:s})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[f.col.period," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx("input",{style:{...E,...d},value:e.period||"",disabled:s,onChange:m=>p({period:m.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:iu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.revenue_growth}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...d},value:e.revenue_growth||"",disabled:s,onChange:g("revenue_growth")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.net_profit}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...d},value:e.net_profit||"",disabled:s,onChange:g("net_profit")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.cash_flow}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...d},value:e.cash_flow||"",disabled:s,onChange:g("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:iu,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.strategic_goal_pct}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...d},value:e.strategic_goal_pct||"",disabled:s,onChange:g("strategic_goal_pct")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.customer_satisfaction}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...d},value:e.customer_satisfaction||"",disabled:s,onChange:g("customer_satisfaction")})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.employee_turnover_pct}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...d},value:e.employee_turnover_pct||"",disabled:s,onChange:g("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:su,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.open_safety_incidents}),n.jsx("input",{type:"number",min:0,style:{...E,...d},value:e.open_safety_incidents||"",disabled:s,onChange:m=>p({open_safety_incidents:parseInt(m.target.value)||0})})]}),n.jsxs("div",{children:[n.jsx("label",{style:T,children:f.field.compliance_score}),n.jsx("input",{type:"number",step:"0.01",style:{...E,...d},value:e.compliance_score||"",disabled:s,onChange:g("compliance_score")})]})]})]})]})}const Z1={create_processes:"Create Processes",update_process_status:"Update Process Status"},au={Pending:N.orange,Accepted:N.green,Rejected:N.red,Revoked:N.gray};function V1(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 e0(e){const t=[];return e.create_processes&&t.push("create_processes"),e.update_process_status&&t.push("update_process_status"),t}function t0({delegations:e,organizations:t,userRole:l,currentUser:r,onView:s,onRevoke:i}){const a=J(),[c,u]=S.useState(""),[h,f]=S.useState(""),[p,d]=S.useState("all"),g={padding:"12px 18px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700},j=S.useMemo(()=>e.filter(v=>{const b=`${v.auditor} ${v.manager}`.toLowerCase();return!(c&&!b.includes(c.toLowerCase())||h&&v.organization!==h||p!=="all"&&v.status!==p)}),[e,c,h,p]),[m,z]=S.useState(1);S.useEffect(()=>{z(1)},[c,h,p]);const y=j.slice((m-1)*te,m*te),o=j.filter(v=>v.status==="Pending").length,x=j.filter(v=>v.status==="Accepted").length;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{display:"flex",gap:16},children:[n.jsx(ke,{label:"Total",val:j.length,color:N.purple}),n.jsx(ke,{label:"Pending",val:o,color:N.orange}),n.jsx(ke,{label:"Accepted",val:x,color:N.green})]}),n.jsx(it,{filters:[{type:"search",label:"Search",value:c,onChange:u,placeholder:"Auditor or Manager…"},{type:"select",label:a.col.organization,value:h,onChange:f,options:[{value:"",label:"All Organizations"},...t.map(v=>({value:v.organization_name||v.name,label:v.organization_name||v.name}))]},{type:"select",label:"Status",value:p,onChange:d,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:13},children:[n.jsx("thead",{children:n.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[n.jsx("th",{style:g,children:a.col.number}),n.jsx("th",{style:g,children:a.col.auditor}),n.jsx("th",{style:g,children:a.col.manager}),n.jsx("th",{style:g,children:a.col.organization}),n.jsx("th",{style:g,children:a.col.functions}),n.jsx("th",{style:g,children:a.col.status}),n.jsx("th",{style:g,children:a.col.requestedOn}),n.jsx("th",{style:g,children:a.col.actions})]})}),n.jsx("tbody",{children:j.length===0?n.jsx("tr",{children:n.jsx("td",{colSpan:8,style:{padding:40,textAlign:"center",color:"#aaa"},children:a.noData})}):y.map((v,b)=>{const w=!!i&&(v.status==="Pending"||v.status==="Accepted")&&(l==="Admin"||l==="Auditor"&&v.auditor===r);return n.jsxs("tr",{onClick:()=>s==null?void 0:s(v),style:{borderTop:"1px solid #f0f0f0",background:b%2===0?"white":"#fafafa",cursor:"pointer"},children:[n.jsx("td",{style:{padding:"12px 18px",fontWeight:600},children:v.number||v.name}),n.jsx("td",{style:{padding:"12px 18px"},children:v.auditor}),n.jsx("td",{style:{padding:"12px 18px"},children:v.manager}),n.jsx("td",{style:{padding:"12px 18px"},children:v.organization||"All Organizations"}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:e0(v).map(k=>n.jsx("span",{style:{background:"#ede9fe",color:"#6d28d9",padding:"2px 8px",borderRadius:10,fontSize:11,fontWeight:600},children:Z1[k]||k},k))})}),n.jsx("td",{style:{padding:"12px 18px"},children:n.jsx("span",{style:{background:(au[v.status]||N.gray)+"22",color:au[v.status]||N.gray,padding:"3px 10px",borderRadius:12,fontSize:12,fontWeight:700},children:v.status})}),n.jsx("td",{style:{padding:"12px 18px",color:"#666"},children:V1(v.requested_on)}),n.jsx("td",{style:{padding:"10px 18px"},onClick:k=>k.stopPropagation(),children:n.jsxs("div",{style:{display:"flex",gap:6},children:[n.jsx("button",{onClick:()=>s==null?void 0:s(v),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"})]})}),w&&n.jsx("button",{onClick:()=>i==null?void 0:i(v.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"})]})})]},v.name)})})]})}),n.jsx(Oe,{page:m,total:j.length,onPageChange:z})]})}const ou={display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},cu={Pending:N.orange,Accepted:N.green,Rejected:N.red,Revoked:N.gray};function n0(e){if(!e)return"—";const t=new Date(e);return isNaN(t.getTime())?"—":t.toLocaleString()}function l0({form:e,setForm:t,organizations:l,users:r,userRoleMap:s,formStatus:i,viewMode:a,onSubmit:c,onBack:u,onNavigate:h,onLogout:f,user:p}){var y;const d=J(),g=o=>t(x=>({...x,...o})),j=a?{background:"#f9f9f9"}:{},m=Bl(r,s,"SB Manager").map(o=>({name:o.name,label:o.full_name||o.name})),z=e.name?`${d.formTitle.viewDelegation}${e.number||e.name}`:d.formTitle.newDelegation;return n.jsxs(De,{title:z,activePage:"delegations",user:p,formStatus:i,buttonText:d.saveDelegation,buttonColor:N.purple,viewMode:a,onSubmit:c,onBack:u,onNavigate:h,onLogout:f,children:[a&&e.status&&n.jsx("div",{style:{marginBottom:20},children:n.jsx("span",{style:{background:(cu[e.status]||N.gray)+"22",color:cu[e.status]||N.gray,padding:"5px 14px",borderRadius:14,fontSize:13,fontWeight:700},children:e.status})}),n.jsxs("div",{style:ou,children:[n.jsxs("div",{children:[n.jsx("label",{style:T,children:d.col.auditor}),n.jsx("input",{style:{...E,background:"#f9f9f9"},value:e.auditor||p.name,disabled:!0})]}),n.jsxs("div",{children:[n.jsxs("label",{style:T,children:[d.col.manager," ",n.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),n.jsx(ae,{value:e.manager,onChange:o=>g({manager:o}),items:m,placeholder:"-- Select Manager --",disabled:a})]})]}),n.jsx("div",{style:ou,children:n.jsxs("div",{children:[n.jsx("label",{style:T,children:d.col.organization}),n.jsx(Ct,{value:e.organization,onChange:o=>g({organization:o}),organizations:l,placeholder:"-- All Organizations --",disabled:a})]})}),n.jsxs("div",{style:{marginTop:8},children:[n.jsxs("label",{style:T,children:[d.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:$l,checked:!!e.create_processes,disabled:a,onChange:o=>g({create_processes:o.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:$l,checked:!!e.update_process_status,disabled:a,onChange:o=>g({update_process_status:o.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:{...E,...j,minHeight:70,resize:"vertical"},value:e.remarks||"",onChange:o=>g({remarks:o.target.value}),placeholder:"Optional note for the Manager…"})]}),a&&(((y=e.delegation_log)==null?void 0:y.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:13},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((o,x)=>n.jsxs("tr",{style:{borderTop:"1px solid #f0f0f0"},children:[n.jsx("td",{style:{padding:"8px 14px",fontWeight:600},children:o.action}),n.jsx("td",{style:{padding:"8px 14px"},children:o.actor}),n.jsx("td",{style:{padding:"8px 14px",color:"#666"},children:n0(o.timestamp)}),n.jsx("td",{style:{padding:"8px 14px",color:"#666"},children:o.remarks||"—"})]},o.name||x))})]})})]})]})}const du={process:"processes-form",order:"orders-form",incident:"incidents-form",idea:"ideas-form"},ka={process:N.blue,order:N.purple,incident:N.red,idea:N.green,delegation:N.orange};function r0({onNavigate:e,onRefresh:t}){const l=J(),[r,s]=S.useState([]),[i,a]=S.useState(!0),[c,u]=S.useState(""),[h,f]=S.useState(""),p=()=>cy().then(z=>{s(z),a(!1)});S.useEffect(()=>{p()},[]);const d=r.filter(z=>z.requires_action),g=r.filter(z=>!z.requires_action),j=async(z,y)=>{u(z),f("");try{await uy(z,y),await p(),t==null||t()}catch{f(z)}u("")};function m(z,y){return y.length===0?null:n.jsxs("div",{style:{marginBottom:24},children:[n.jsxs("h3",{style:{fontSize:14,fontWeight:700,color:"#555",marginBottom:12,textTransform:"uppercase",letterSpacing:1},children:[z," (",y.length,")"]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:y.map((o,x)=>{const v=o.type!=="delegation";return n.jsxs("div",{onClick:v?()=>e(du[o.type],o.name):void 0,style:{background:"white",borderRadius:10,padding:"14px 18px",boxShadow:"0 1px 4px rgba(0,0,0,0.07)",display:"flex",alignItems:"center",gap:16,borderLeft:`4px solid ${ka[o.type]||N.gray}`,cursor:v?"pointer":"default",transition:"box-shadow 0.15s, transform 0.15s"},onMouseEnter:v?b=>{b.currentTarget.style.boxShadow="0 4px 14px rgba(0,0,0,0.12)",b.currentTarget.style.transform="translateY(-1px)"}:void 0,onMouseLeave:v?b=>{b.currentTarget.style.boxShadow="0 1px 4px rgba(0,0,0,0.07)",b.currentTarget.style.transform="none"}:void 0,children:[n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[n.jsx("span",{style:{fontSize:11,fontWeight:700,color:"white",background:ka[o.type]||N.gray,padding:"2px 8px",borderRadius:10},children:o.type.toUpperCase()}),n.jsx("span",{style:{fontWeight:700,fontSize:14},children:o.number}),n.jsx("span",{style:{fontSize:13,color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o.title})]}),n.jsxs("div",{style:{marginTop:4,fontSize:12,color:"#888"},children:[o.action," ",o.organization?`· ${o.organization}`:""," ",o.date?`· ${o.date}`:""]}),h===o.name&&n.jsx("div",{style:{marginTop:4,fontSize:12,color:"#e74c3c"},children:"Failed to respond — please try again."})]}),o.type==="delegation"?n.jsxs("div",{style:{display:"flex",gap:8,flexShrink:0},children:[n.jsx("button",{onClick:()=>j(o.name,"Accepted"),disabled:c===o.name,style:{padding:"7px 16px",borderRadius:8,border:"none",background:N.green,color:"white",fontWeight:600,fontSize:13,cursor:c===o.name?"wait":"pointer",opacity:c===o.name?.6:1},children:"Accept"}),n.jsx("button",{onClick:()=>j(o.name,"Rejected"),disabled:c===o.name,style:{padding:"7px 16px",borderRadius:8,border:"none",background:N.red,color:"white",fontWeight:600,fontSize:13,cursor:c===o.name?"wait":"pointer",opacity:c===o.name?.6:1},children:"Reject"})]}):n.jsx("button",{onClick:b=>{b.stopPropagation(),e(du[o.type],o.name)},style:{padding:"7px 16px",borderRadius:8,border:"none",background:ka[o.type]||N.accent,color:"white",fontWeight:600,fontSize:13,cursor:"pointer",flexShrink:0},children:o.requires_action?"Act":l.view})]},x)})})]})}return n.jsxs("div",{style:{maxWidth:900,margin:"0 auto"},children:[i&&n.jsx("p",{style:{color:"#888"},children:l.loading}),!i&&r.length===0&&n.jsxs("div",{style:{background:"white",borderRadius:12,padding:48,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:[n.jsx("div",{style:{fontSize:48,marginBottom:12},children:"📥"}),n.jsx("p",{style:{fontSize:16},children:l.inbox.noMessages})]}),!i&&m("Needs Action",d),!i&&m("Informational",g)]})}const s0=[{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"]}],Df={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 i0(e,t){const l=e.map(s=>Df[s]||s).join(","),r=t.map(s=>e.map(i=>`"${s[i]??""}"`).join(",")).join(` `);return l+` `+r}function a0(e,t){const l=new Blob([e],{type:"text/csv"}),r=URL.createObjectURL(l),s=document.createElement("a");s.href=r,s.download=t,s.click(),URL.revokeObjectURL(r)}const Nf="report-print-area",_a="report-print-portal";function o0(){const e=document.getElementById(Nf);if(!e)return;const t=document.createElement("div");t.id=_a,t.innerHTML=e.innerHTML,document.body.appendChild(t);const l=document.createElement("style");l.id="report-print-style",l.textContent=` #${_a} { display: none; } @media print { #root { display: none !important; } #${_a} { display: block !important; } } `,document.head.appendChild(l);const r=()=>{t.remove(),l.remove(),window.removeEventListener("afterprint",r)};window.addEventListener("afterprint",r),window.print()}const uu={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",minWidth:180},Ca={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white"};function c0({organizations:e,userRole:t}){const l=J(),r=s0.filter(O=>O.roles.includes(t)),[s,i]=S.useState(""),[a,c]=S.useState(""),[u,h]=S.useState(""),[f,p]=S.useState(""),[d,g]=S.useState(String(new Date().getFullYear())),[j,m]=S.useState([]),[z,y]=S.useState([]),[o,x]=S.useState(!1),[v,b]=S.useState(""),w=r.find(O=>O.id===s);async function k(){if(s){x(!0),b(""),y([]),m([]);try{const O={};a&&(O.organization=a),u&&(O.from_date=u),f&&(O.to_date=f),(w==null?void 0:w.extraFilter)==="year"&&d&&(O.year=d);const U=await oy(s,O);m(U.columns||[]),y(U.rows||[])}catch(O){b(O.message||"Error running report")}finally{x(!1)}}}const C=(w==null?void 0:w.label)||s;return n.jsxs("div",{children:[n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12,marginBottom:20},children:r.map(O=>n.jsxs("div",{onClick:()=>i(O.id),style:{background:s===O.id?"#ebf5fb":"white",border:s===O.id?`2px solid ${N.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:O.label}),n.jsx("div",{style:{fontSize:12,color:"#888"},children:O.description})]},O.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:uu,value:s,onChange:O=>i(O.target.value),children:[n.jsx("option",{value:"",children:"-- Select Report --"}),r.map(O=>n.jsx("option",{value:O.id,children:O.label},O.id))]})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"ORGANIZATION"}),n.jsxs("select",{style:uu,value:a,onChange:O=>c(O.target.value),children:[n.jsx("option",{value:"",children:l.filter.allOrgs}),e.map(O=>n.jsx("option",{value:O.name,children:O.organization_name||O.name},O.name))]})]}),(w==null?void 0:w.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:{...Ca,width:90},value:d,onChange:O=>g(O.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(pe,{value:u,onChange:h,style:Ca})]}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"TO"}),n.jsx(pe,{value:f,onChange:p,style:Ca})]})]}),n.jsx("button",{onClick:k,disabled:!s||o,style:{padding:"9px 20px",borderRadius:8,border:"none",background:N.accent,color:"white",fontWeight:700,fontSize:13,cursor:s?"pointer":"not-allowed",opacity:s?1:.5},children:o?l.loading:l.reports.generate}),z.length>0&&n.jsx("button",{onClick:()=>a0(i0(j,z),`${s}.csv`),style:{padding:"9px 20px",borderRadius:8,border:"1px solid #27ae60",background:"white",color:"#27ae60",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Export CSV"}),z.length>0&&n.jsx("button",{onClick:o0,style:{padding:"9px 20px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Print / PDF"})]})}),v&&n.jsx("div",{style:{color:"#e74c3c",marginBottom:16},children:v}),z.length>0&&n.jsxs("div",{id:Nf,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:C}),n.jsxs("span",{style:{fontSize:12,color:"#888"},children:[z.length," rows"]})]}),n.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[n.jsx("thead",{children:n.jsx("tr",{style:{background:"#f8f9fa"},children:j.map(O=>n.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700,whiteSpace:"nowrap"},children:Df[O]||O.replace(/_/g," ").toUpperCase()},O))})}),n.jsx("tbody",{children:z.map((O,U)=>n.jsx("tr",{style:{borderTop:"1px solid #f0f0f0",background:U%2===0?"white":"#fafafa"},children:j.map(X=>n.jsx("td",{style:{padding:"10px 14px",color:"#333"},children:O[X]!=null?String(O[X]):"—"},X))},U))})]})]}),!o&&z.length===0&&s&&!v&&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."}),r.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 is=()=>new Date().toISOString().split("T")[0],mc=()=>new Date(Date.now()+30*24*60*60*1e3).toISOString().split("T")[0],Yt=()=>({name:"",number:"",title:"",organization:"",type:"",incident_class:"",incident_field:"",date:is(),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:""}),Gt=()=>({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:is(),priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:""}),Xt=()=>({name:"",number:"",title:"",organization:"",type:"Buy L",management:"",department:"",section_field:"",branch:"",starting_date:is(),ending_date:mc(),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:""}),Ns=()=>({name:"",title:"",date_start:is(),date_end:mc(),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:""}),fr=()=>({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}),ol=()=>({name:"",organization:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),cl=()=>({name:"",custom_organization:"",department_name:"",custom_management:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),dl=()=>({name:"",organization:"",branch:"",management:"",department:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),hr=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),gr=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),xr=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),mr=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),yr=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),vr=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),jr=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),br=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Ws=()=>({name:"",first_name:"",full_name:"",email:"",enabled:1,creation:"",username:"",mobile_no:"",custom_organization:"",custom_management:"",custom_department:"",custom_branch:"",custom_number:"",custom_category:""}),ul=()=>({name:"",name1:"",organization:"",frequency:"Monthly",status:"Active",start_date:is(),end_date:mc(),update_window_days:2}),pl=()=>({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}),Sr=()=>({name:"",number:"",auditor:"",manager:"",organization:"",create_processes:0,update_process_status:0,status:"Pending",requested_on:"",remarks:""}),d0=new Set(["incidents","incidents-form","ideas","ideas-form"]),u0=new Set(["orders","orders-form","incidents","incidents-form","ideas","ideas-form"]),p0=new Set(["Admin","Owner","Auditor","Manager"]),f0=new Set(["Admin","Owner","Auditor","Manager"]),h0=new Set(["Admin","Auditor","Manager"]);function g0({user:e,onLogout:t,darkMode:l,onToggleDark:r}){const s=J(),i=e.role,a=p0.has(i),c=f0.has(i),u=h0.has(i),h=zf(i),f=_=>_==="users"||_==="users-form"?i==="Admin":i==="Admin"||i==="Auditor"?!0:i==="Owner"||i==="XAuditor"?!1:i==="Manager"?!!(u0.has(_)||(_==="processes"||_==="processes-form")&&jc.includes("create_processes")):d0.has(_),p=_=>i==="Employee"&&!!_&&_!=="New",[d,g]=S.useState(a?"dashboard":"inbox"),[j,m]=S.useState(""),[z,y]=S.useState(0),[o,x]=S.useState([]),[v,b]=S.useState([]),[w,k]=S.useState([]),[C,O]=S.useState([]),[U,X]=S.useState([]),[V,W]=S.useState([]),[Q,ne]=S.useState([]),[ee,de]=S.useState([]),[A,$]=S.useState([]),[H,q]=S.useState([]),[M,_e]=S.useState([]),[R,Z]=S.useState([]),[Te,Qe]=S.useState([]),[I,P]=S.useState([]),[F,Ln]=S.useState([]),[on,Fi]=S.useState([]),[On,as]=S.useState([]),[L,pt]=S.useState([]),[Ft,cn]=S.useState([]),[Vn,Wf]=S.useState({}),[Hl,Bf]=S.useState([]),[os,$f]=S.useState([]),[yc,Uf]=S.useState([]),[vc,Ff]=S.useState([]),[jc,Mf]=S.useState([]),[bc,Hf]=S.useState({}),[me,ie]=S.useState(!0),[Ie,le]=S.useState("idle"),[Pe,tt]=S.useState(!1),[Sc,wc]=S.useState(!1),[cs,kc]=S.useState(null),[Ue,Kf]=S.useState(()=>localStorage.getItem("sb_sidebar")==="1"),Qf=()=>Kf(_=>{const Y=!_;return localStorage.setItem("sb_sidebar",Y?"1":"0"),Y}),[Yf,Mi]=S.useState(!1);S.useEffect(()=>{Mi(!1)},[d]);const[Kl,Mt]=S.useState(Yt()),[Ql,Ht]=S.useState(Gt()),[ds,Kt]=S.useState(Xt()),[us,Ot]=S.useState(Ns()),[_c,Yl]=S.useState(fr()),[Cc,el]=S.useState(ol()),[zc,tl]=S.useState(cl()),[Tc,nl]=S.useState(dl()),[Ic,Gl]=S.useState(hr()),[Pc,Xl]=S.useState(gr()),[Ec,Jl]=S.useState(xr()),[Ac,ql]=S.useState(mr()),[Rc,Zl]=S.useState(yr()),[Lc,Vl]=S.useState(vr()),[Oc,er]=S.useState(jr()),[Dc,tr]=S.useState(br()),[ps,fs]=S.useState(Ws()),[Nc,ll]=S.useState(ul()),[Wc,rl]=S.useState(pl()),[sl,nr]=S.useState(Sr()),Dt=async()=>{ie(!0);try{const[_,Y,We,Ye,dn,Ee,Yi,Fh,Mh,Hh,Kh,Qh,Yh,Gh,Xh,Jh,qh,Zh,Vh,eg,tg,ng,lg,rg,sg,ig]=await Promise.all([ye(D.incidents),ye(D.organizations),ye(D.ideas),ye(D.orders),ye(D.processes),Km(),ye(D.managements),ye(D.departments),ye(D.branches),ye(D.incidentTypes),ye(D.incidentClass),ye(D.incidentField),ye(D.ideaTypes),ye(D.orderTypes),ye(D.processTypes),ye(D.incidentStatuses),ye(D.ideaStatuses),ye(D.orderStatuses),ye(D.processStatuses),Xm(),Jm(),ye(D.cycles),ye(D.kpiInput),fy(),gy(),xy()]);x(_||[]),b(Y||[]),k(We||[]),O(Ye||[]),X(dn||[]),Bf(Ee||[]),W(Yi||[]),ne(Fh||[]),de(Mh||[]),$(Hh||[]),q(Kh||[]),_e(Qh||[]),Z(Yh||[]),Qe(Gh||[]),P(Xh||[]),Ln(Jh||[]),Fi(qh||[]),as(Zh||[]),pt(Vh||[]),cn(eg||[]),Wf(tg||{}),$f(ng||[]),Uf(lg||[]),Ff(rg||[]),Mf(sg||[]),Hf(ig||{})}catch(_){console.error("Error loading data:",_)}ie(!1)},Gf=async()=>{try{const _=await fetch("/api/method/sidrah_business.api.get_notification_count",{credentials:"include",headers:{Accept:"application/json"}});if(_.ok){const Y=await _.json();y(Number(Y.message)||0)}}catch{}};S.useEffect(()=>{Dt(),Gf()},[e.name]);const Ne=async(_,Y)=>{if(window.confirm(s.rtl?"هل أنت متأكد من حذف هذا السجل؟":"Are you sure you want to delete this record?")){ie(!0);try{await Ef(_,Y),await Dt()}catch(We){console.error("Delete error:",We),alert((We==null?void 0:We.message)||"Delete failed. Please try again.")}ie(!1)}},Xf=async _=>{try{await ey(_),await Dt()}catch(Y){console.error("Disable user error:",Y)}},Jf=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.incidents,_.name);Mt({...Yt(),...Y})}catch{Mt({...Yt(),..._})}g("incidents-form"),ie(!1)},qf=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.ideas,_.name);Ht({...Gt(),...Y})}catch{Ht({...Gt(),..._})}g("ideas-form"),ie(!1)},Zf=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.orders,_.name);Kt({...Xt(),...Y})}catch{Kt({...Xt(),..._})}g("orders-form"),ie(!1)},Vf=async _=>{tt(!0),ie(!0);try{const Y=await zr(_.name);Ot({...Y,progress_indicators:Y.progress_indicators||[],cycle_logs:Y.cycle_logs||[]}),g("processes-form")}catch{Ot({..._,progress_indicators:_.progress_indicators||[]}),g("processes-form")}ie(!1)},eh=_=>fe(D.organizations,_,Yl,fr(),"organizations-form",!0),th=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.managements,_.name);el({...ol(),...Y})}catch{el({...ol(),..._})}g("managements-form"),ie(!1)},nh=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.departments,_.name);tl({...cl(),...Y})}catch{tl({...cl(),..._})}g("departments-form"),ie(!1)},lh=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.branches,_.name);nl({...dl(),...Y})}catch{nl({...dl(),..._})}g("branches-form"),ie(!1)},rh=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.cycles,_.name);ll({...ul(),...Y})}catch{ll({...ul(),..._})}g("cycles-form"),ie(!1)},sh=async _=>{tt(!0),ie(!0);try{const Y=await ft(D.kpiInput,_.name);rl({...pl(),...Y})}catch{rl({...pl(),..._})}g("kpi-input-form"),ie(!1)},Fe=async(_,Y,We,Ye,dn)=>{le("loading");try{if(Y.name)await bi(_,Y.name,Y),le("success"),Dt(),setTimeout(()=>{le("idle"),g(Ye)},1500);else if(dn){const Ee=await ja(_,Y);dn(Ee),le("success"),Dt(),setTimeout(()=>le("idle"),1500)}else await ja(_,Y),We(),le("success"),Dt(),setTimeout(()=>{le("idle"),g(Ye)},1500)}catch(Ee){console.error("Submit error:",Ee),le(Ee instanceof Error?Ee.message:"Error saving. Please try again.")}},Ce=async()=>{await Ym(),t()},fe=async(_,Y,We,Ye,dn,Ee)=>{tt(Ee),ie(!0);try{const Yi=await ft(_,Y.name);We({...Ye,...Yi})}catch{We({...Ye,...Y})}g(dn),ie(!1)},ih=_=>fe(D.incidents,_,Mt,Yt(),"incidents-form",!1),ah=_=>fe(D.ideas,_,Ht,Gt(),"ideas-form",!1),oh=_=>fe(D.orders,_,Kt,Xt(),"orders-form",!1),ch=_=>{tt(!1),ie(!0),zr(_.name).then(Y=>{Ot({...Y,progress_indicators:Y.progress_indicators||[],cycle_logs:Y.cycle_logs||[]})}).catch(()=>{Ot({..._,progress_indicators:_.progress_indicators||[]})}).finally(()=>{g("processes-form"),ie(!1)})},dh=_=>fe(D.organizations,_,Yl,fr(),"organizations-form",!1),uh=_=>fe(D.managements,_,el,ol(),"managements-form",!1),ph=_=>fe(D.departments,_,tl,cl(),"departments-form",!1),fh=_=>fe(D.branches,_,nl,dl(),"branches-form",!1),hh=_=>fe(D.cycles,_,ll,ul(),"cycles-form",!1),gh=_=>fe(D.kpiInput,_,rl,pl(),"kpi-input-form",!1),xh=async _=>{tt(!0),ie(!0);try{const Y=await hy(_.name);nr({...Sr(),...Y})}catch{nr({...Sr(),..._})}g("delegations-form"),ie(!1)},mh=async()=>{le("loading");try{const _=[];sl.create_processes&&_.push("create_processes"),sl.update_process_status&&_.push("update_process_status"),await dy(sl.manager,_,sl.organization,sl.remarks),nr(Sr()),le("success"),Dt(),setTimeout(()=>{le("idle"),g("delegations")},1500)}catch(_){console.error("Delegation submit error:",_),le(_ instanceof Error?_.message:"Error saving. Please try again.")}},yh=async _=>{if(window.confirm(s.rtl?"هل أنت متأكد من إلغاء هذا التفويض؟":"Are you sure you want to revoke this delegation?")){ie(!0);try{await py(_),await Dt()}catch(Y){console.error("Revoke delegation error:",Y),alert(Y instanceof Error?Y.message:"Revoke failed. Please try again.")}ie(!1)}},vh=_=>fe(D.incidentTypes,_,Gl,hr(),"incident-types-form",!0),jh=_=>fe(D.incidentTypes,_,Gl,hr(),"incident-types-form",!1),bh=_=>fe(D.ideaTypes,_,Xl,gr(),"idea-types-form",!0),Sh=_=>fe(D.ideaTypes,_,Xl,gr(),"idea-types-form",!1),wh=_=>fe(D.orderTypes,_,Jl,xr(),"order-types-form",!0),kh=_=>fe(D.orderTypes,_,Jl,xr(),"order-types-form",!1),_h=_=>fe(D.processTypes,_,ql,mr(),"process-types-form",!0),Ch=_=>fe(D.processTypes,_,ql,mr(),"process-types-form",!1),zh=_=>fe(D.incidentStatuses,_,Zl,yr(),"incident-statuses-form",!0),Th=_=>fe(D.incidentStatuses,_,Zl,yr(),"incident-statuses-form",!1),Ih=_=>fe(D.ideaStatuses,_,Vl,vr(),"idea-statuses-form",!0),Ph=_=>fe(D.ideaStatuses,_,Vl,vr(),"idea-statuses-form",!1),Eh=_=>fe(D.orderStatuses,_,er,jr(),"order-statuses-form",!0),Ah=_=>fe(D.orderStatuses,_,er,jr(),"order-statuses-form",!1),Rh=_=>fe(D.processStatuses,_,tr,br(),"process-statuses-form",!0),Lh=_=>fe(D.processStatuses,_,tr,br(),"process-statuses-form",!1),Oh=async _=>{kc(_),g("profile")},Dh=_=>{tt(!1),wc(!1),fs({...Ws(),..._}),g("users-form")},Nh=async()=>{le("loading");try{if(!ps.name)await ja("User",{...ps,send_welcome_email:0,user_type:"System User"});else{const{name:Y,email:We,creation:Ye,full_name:dn,...Ee}=ps;await bi("User",Y,Ee)}fs(Ws()),le("success"),Dt(),setTimeout(()=>{le("idle"),g("users")},1500)}catch(_){console.error("User submit error:",_),le(_ instanceof Error?_.message:"Error saving. Please try again.")}},Hi=(_,Y)=>{if(Y){const Ye={"processes-form":D.processes,"orders-form":D.orders,"incidents-form":D.incidents,"ideas-form":D.ideas}[_];if(Ye){tt(!0),ie(!0),(_==="processes-form"?zr(Y).then(Ee=>({...Ee,progress_indicators:Ee.progress_indicators||[],cycle_logs:Ee.cycle_logs||[]})):ft(Ye,Y)).then(Ee=>{_==="processes-form"?Ot(Ee):_==="orders-form"?Kt({...Xt(),...Ee}):_==="incidents-form"?Mt({...Yt(),...Ee}):_==="ideas-form"&&Ht({...Gt(),...Ee}),g(_),ie(!1)}).catch(()=>{g(_),ie(!1)});return}}g(_)};if(d==="incidents-form")return n.jsx(Wy,{incForm:Kl,setIncForm:Mt,organizations:v,managements:V,departments:Q,branches:ee,incidentTypes:A,incidentClasses:H,incidentFields:M,incidentStatuses:F,users:Hl,userRoleMap:Vn,formStatus:Ie,viewMode:Pe||!f("incidents-form")||p(Kl.workflow_state),userRole:i,onSubmit:()=>Fe(D.incidents,Kl,()=>Mt(Yt()),"incidents",_=>Mt({...Yt(),..._})),onBack:()=>{g("incidents"),le("idle")},onNavigate:g,onLogout:Ce,user:e,onRefresh:async()=>{if(Kl.name){const _=await ft(D.incidents,Kl.name).catch(()=>null);_&&Mt({...Yt(),..._})}ye(D.incidents).then(_=>x(_||[])).catch(()=>{})}});if(d==="ideas-form")return n.jsx(Fy,{ideaForm:Ql,setIdeaForm:Ht,organizations:v,managements:V,departments:Q,branches:ee,ideaTypes:R,ideaStatuses:on,users:Hl,userRoleMap:Vn,formStatus:Ie,viewMode:Pe||!f("ideas-form")||p(Ql.workflow_state),userRole:i,onSubmit:()=>Fe(D.ideas,Ql,()=>Ht(Gt()),"ideas",_=>Ht({...Gt(),..._})),onBack:()=>{g("ideas"),le("idle")},onNavigate:g,onLogout:Ce,user:e,onRefresh:async()=>{if(Ql.name){const _=await ft(D.ideas,Ql.name).catch(()=>null);_&&Ht({...Gt(),..._})}ye(D.ideas).then(_=>k(_||[])).catch(()=>{})}});if(d==="orders-form")return n.jsx(Yy,{orderForm:ds,setOrderForm:Kt,organizations:v,managements:V,departments:Q,branches:ee,orderTypes:Te,orderStatuses:On,cycles:os,users:Hl,userRoleMap:Vn,formStatus:Ie,viewMode:Pe||!f("orders-form"),currentUser:e.name,userRole:i,onSubmit:()=>Fe(D.orders,ds,()=>Kt(Xt()),"orders",_=>Kt({...Xt(),..._})),onBack:()=>{g("orders"),le("idle")},onNavigate:g,onLogout:Ce,user:e,onRefresh:async()=>{if(ds.name){const _=await ft(D.orders,ds.name).catch(()=>null);_&&Kt({...Xt(),..._})}ye(D.orders).then(_=>O(_||[])).catch(()=>{})}});if(d==="processes-form")return n.jsx(Zy,{processForm:us,setProcessForm:Ot,organizations:v,managements:V,departments:Q,branches:ee,processTypes:I,processStatuses:L,cycles:os,users:Hl,userRoleMap:Vn,formStatus:Ie,viewMode:Pe||!f("processes-form"),userRole:e.role,delegatedFunctions:jc,delegatedOrgs:bc.create_processes,onRefreshProcess:async()=>{if(us.name)try{const _=await zr(us.name);Ot({..._,progress_indicators:_.progress_indicators||[],cycle_logs:_.cycle_logs||[]})}catch{}ye(D.processes).then(_=>X(_||[])).catch(()=>{})},onSubmit:()=>Fe(D.processes,us,()=>Ot(Ns()),"processes",_=>Ot({...Ns(),..._,progress_indicators:_.progress_indicators||[],cycle_logs:_.cycle_logs||[]})),onBack:()=>{g("processes"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="organizations-form")return n.jsx(i1,{orgForm:_c,setOrgForm:Yl,formStatus:Ie,viewMode:Pe||!f("organizations-form"),onSubmit:()=>Fe(D.organizations,_c,()=>Yl(fr()),"organizations"),onBack:()=>{g("organizations"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="managements-form")return n.jsx(c1,{form:Cc,setForm:el,organizations:v,formStatus:Ie,viewMode:Pe||!f("managements-form"),onSubmit:()=>Fe(D.managements,Cc,()=>el(ol()),"managements"),onBack:()=>{g("managements"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="departments-form")return n.jsx(f1,{form:zc,setForm:tl,organizations:v,managements:V,formStatus:Ie,viewMode:Pe||!f("departments-form"),onSubmit:()=>Fe(D.departments,zc,()=>tl(cl()),"departments"),onBack:()=>{g("departments"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="branches-form")return n.jsx(m1,{form:Tc,setForm:nl,organizations:v,managements:V,departments:Q,formStatus:Ie,viewMode:Pe||!f("branches-form"),onSubmit:()=>Fe(D.branches,Tc,()=>nl(dl()),"branches"),onBack:()=>{g("branches"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="cycles-form")return n.jsx(X1,{form:Nc,setForm:ll,organizations:v,formStatus:Ie,viewMode:Pe||!f("cycles-form"),onSubmit:()=>Fe(D.cycles,Nc,()=>ll(ul()),"cycles"),onBack:()=>{g("cycles"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="kpi-input-form")return n.jsx(q1,{form:Wc,setForm:rl,organizations:v,formStatus:Ie,viewMode:Pe||!f("kpi-input-form"),onSubmit:()=>Fe(D.kpiInput,Wc,()=>rl(pl()),"kpi-input"),onBack:()=>{g("kpi-input"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="incident-types-form")return n.jsx(j1,{form:Ic,setForm:Gl,formStatus:Ie,viewMode:Pe||!f("incident-types-form"),onSubmit:()=>Fe(D.incidentTypes,Ic,()=>Gl(hr()),"incident-types"),onBack:()=>{g("incident-types"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="idea-types-form")return n.jsx(w1,{form:Pc,setForm:Xl,formStatus:Ie,viewMode:Pe||!f("idea-types-form"),onSubmit:()=>Fe(D.ideaTypes,Pc,()=>Xl(gr()),"idea-types"),onBack:()=>{g("idea-types"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="order-types-form")return n.jsx(C1,{form:Ec,setForm:Jl,formStatus:Ie,viewMode:Pe||!f("order-types-form"),onSubmit:()=>Fe(D.orderTypes,Ec,()=>Jl(xr()),"order-types"),onBack:()=>{g("order-types"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="process-types-form")return n.jsx(I1,{form:Ac,setForm:ql,formStatus:Ie,viewMode:Pe||!f("process-types-form"),onSubmit:()=>Fe(D.processTypes,Ac,()=>ql(mr()),"process-types"),onBack:()=>{g("process-types"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="incident-statuses-form")return n.jsx(A1,{form:Rc,setForm:Zl,formStatus:Ie,viewMode:Pe||!f("incident-statuses-form"),onSubmit:()=>Fe(D.incidentStatuses,Rc,()=>Zl(yr()),"incident-statuses"),onBack:()=>{g("incident-statuses"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="idea-statuses-form")return n.jsx(O1,{form:Lc,setForm:Vl,formStatus:Ie,viewMode:Pe||!f("idea-statuses-form"),onSubmit:()=>Fe(D.ideaStatuses,Lc,()=>Vl(vr()),"idea-statuses"),onBack:()=>{g("idea-statuses"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="order-statuses-form")return n.jsx(W1,{form:Oc,setForm:er,formStatus:Ie,viewMode:Pe||!f("order-statuses-form"),onSubmit:()=>Fe(D.orderStatuses,Oc,()=>er(jr()),"order-statuses"),onBack:()=>{g("order-statuses"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="process-statuses-form")return n.jsx(U1,{form:Dc,setForm:tr,formStatus:Ie,viewMode:Pe||!f("process-statuses-form"),onSubmit:()=>Fe(D.processStatuses,Dc,()=>tr(br()),"process-statuses"),onBack:()=>{g("process-statuses"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="users-form")return n.jsx(K1,{form:ps,setForm:fs,organizations:v,managements:V,departments:Q,branches:ee,formStatus:Ie,viewMode:Pe||!f("users-form"),isSelfProfile:Sc,onSubmit:Nh,onBack:()=>{g(Sc?a?"dashboard":"inbox":"users"),le("idle")},onNavigate:g,onLogout:Ce,user:e});if(d==="delegations-form")return n.jsx(l0,{form:sl,setForm:nr,organizations:v,users:Hl,userRoleMap:Vn,formStatus:Ie,viewMode:Pe||!f("delegations-form"),onSubmit:mh,onBack:()=>{g("delegations"),le("idle")},onNavigate:g,onLogout:Ce,user:e});const Wh=s.pages,Bh={incidents:{color:N.accent,formPage:"incidents-form",reset:()=>Mt({...Yt(),organization:j})},ideas:{color:N.teal,formPage:"ideas-form",reset:()=>Ht({...Gt(),organization:j})},orders:{color:N.purple,formPage:"orders-form",reset:()=>Kt({...Xt(),organization:j})},processes:{color:N.blue,formPage:"processes-form",reset:()=>{const _=bc.create_processes,Y=i==="Manager"&&_&&_.length===1?_[0]:j;Ot({...Ns(),organization:Y})}},organizations:{color:N.accent,formPage:"organizations-form",reset:()=>Yl(fr())},managements:{color:N.blue,formPage:"managements-form",reset:()=>el({...ol(),organization:j})},departments:{color:N.teal,formPage:"departments-form",reset:()=>tl({...cl(),custom_organization:j})},branches:{color:N.purple,formPage:"branches-form",reset:()=>nl({...dl(),organization:j})},cycles:{color:N.teal,formPage:"cycles-form",reset:()=>ll({...ul(),organization:j})},"kpi-input":{color:N.blue,formPage:"kpi-input-form",reset:()=>rl({...pl(),organization:j})},"incident-types":{color:N.red,formPage:"incident-types-form",reset:()=>Gl(hr())},"idea-types":{color:N.orange,formPage:"idea-types-form",reset:()=>Xl(gr())},"order-types":{color:N.green,formPage:"order-types-form",reset:()=>Jl(xr())},"process-types":{color:N.accent,formPage:"process-types-form",reset:()=>ql(mr())},"incident-statuses":{color:N.red,formPage:"incident-statuses-form",reset:()=>Zl(yr())},"idea-statuses":{color:N.teal,formPage:"idea-statuses-form",reset:()=>Vl(vr())},"order-statuses":{color:N.purple,formPage:"order-statuses-form",reset:()=>er(jr())},"process-statuses":{color:N.blue,formPage:"process-statuses-form",reset:()=>tr(br())},users:{color:N.blue,formPage:"users-form",reset:()=>{fs(Ws()),wc(!1)}},delegations:{color:N.purple,formPage:"delegations-form",reset:()=>nr(Sr())}},$h={incidents:s.formTitle.newIncident,ideas:s.formTitle.newIdea,orders:s.formTitle.newOrder,processes:s.formTitle.newProcess,organizations:s.formTitle.newOrg,managements:s.formTitle.newMgmt,departments:s.formTitle.newDept,branches:s.formTitle.newBranch,users:s.formTitle.newUser,cycles:s.formTitle.newCycle,"kpi-input":s.formTitle.newKpi,delegations:s.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"},Uh={incidents:o,ideas:w,orders:C,processes:U,organizations:v,managements:V,departments:Q,branches:ee,cycles:os,"kpi-input":yc,"incident-types":A,"idea-types":R,"order-types":Te,"process-types":I,"incident-statuses":F,"idea-statuses":on,"order-statuses":On,"process-statuses":L,users:Ft,delegations:vc},Dn=Om[d],Ki=Uh[d],G=f(d),Qi=G?Bh[d]:null;return n.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:l?"#0f172a":N.bg},children:[n.jsxs("div",{style:{width:Ue?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:Ue?"16px 0":"16px 20px 14px",borderBottom:"1px solid rgba(255,255,255,0.08)",display:"flex",alignItems:"center",justifyContent:Ue?"center":"space-between",gap:8,flexShrink:0},children:[!Ue&&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:s.rtl?"صدرة":"Sidrah"})]}),n.jsx("button",{onClick:Qf,title:Ue?"Expand sidebar":"Collapse sidebar",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:Ue?"▶":"✕"})]}),n.jsxs("nav",{style:{padding:"12px 8px",flex:1,overflowY:"auto",overflowX:"hidden"},children:[Cf.filter(({id:_})=>(_!=="dashboard"||a)&&(_!=="reports"||c)&&(_!=="delegations"||u)).map(({id:_,icon:Y})=>{const We=s.nav[_]||_,Ye=d===_;return n.jsxs("div",{onClick:()=>g(_),title:Ue?We:void 0,style:{padding:Ue?"8px 0":"8px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:Ue?"center":"flex-start",gap:9,background:Ye?"rgba(139,92,246,0.28)":"transparent",borderRadius:8,fontSize:Ue?15:12,color:"white",fontWeight:Ye?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{flexShrink:0},children:Y}),!Ue&&We]},_)}),h.length>0&&n.jsxs(n.Fragment,{children:[!Ue&&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:s.nav.settings}),Ue&&n.jsx("div",{style:{margin:"10px auto",width:28,borderTop:"1px solid rgba(255,255,255,0.12)"}}),h.map(({id:_,icon:Y})=>{const We=s.nav[_]||_,Ye=d===_;return n.jsxs("div",{onClick:()=>g(_),title:Ue?We:void 0,style:{padding:Ue?"8px 0":"8px 14px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:Ue?"center":"flex-start",gap:9,background:Ye?"rgba(139,92,246,0.25)":"transparent",borderRadius:8,fontSize:Ue?15:12,color:"white",fontWeight:Ye?600:400,transition:"all 0.15s",whiteSpace:"nowrap",marginBottom:2},children:[n.jsx("span",{style:{flexShrink:0},children:Y}),!Ue&&We]},_)})]})]})]}),n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[n.jsx("div",{style:{background:l?"#1e293b":"#ffffff",padding:"7px 24px",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(e1,{notifCount:z,darkMode:l,onCountChange:y,onToggleDark:r,onNavigate:Hi,onViewProfile:()=>{const _=Ft.find(Y=>Y.name===e.name||Y.username===e.name);kc(_||{name:e.name,full_name:e.full_name,email:e.name,enabled:1}),g("profile")},onLogout:Ce})}),d!=="profile"&&n.jsxs("div",{style:{background:l?"#1e293b":"white",padding:"10px 24px",borderBottom:`1px solid ${l?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[n.jsx("div",{style:{fontSize:18,fontWeight:700,color:l?"#e2e8f0":"#1e1b4b"},children:Wh[d]||d}),n.jsxs("div",{style:{display:"flex",gap:8},children:[Dn&&Ki&&n.jsx("button",{onClick:()=>Mi(!0),style:{background:"#16a34a",color:"white",border:"none",padding:"7px 16px",borderRadius:7,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"}),Qi&&n.jsxs("button",{onClick:()=>{Qi.reset(),tt(!1),le("idle"),g(Qi.formPage)},style:{background:"#4f46e5",color:"white",border:"none",padding:"7px 16px",borderRadius:7,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI"},children:["+ ",$h[d]||s.new]})]})]}),Dn&&Ki&&Yf&&n.jsx(Fm,{title:Dn.label,rows:Ki,columns:Dn.columns,defaultColumnKeys:Dn.defaultColumns,orgField:Dn.orgField,organizations:Dn.orgField?v:void 0,filenameBase:d,onClose:()=>Mi(!1)}),n.jsxs("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",padding:d==="profile"?0:"20px 24px",gap:d==="profile"?0:16},children:[me&&n.jsx("div",{style:{textAlign:"center",paddingTop:60,color:"#aaa",fontSize:15},children:s.loading}),!me&&d==="dashboard"&&a&&n.jsx(ky,{incidents:o,ideas:w,orders:C,processes:U,organizations:v,incidentStatuses:F,ideaStatuses:on,orderStatuses:On,processStatuses:L,selectedOrg:j,onOrgChange:m,onNavigate:Hi,userRole:i}),!me&&d==="inbox"&&n.jsx(r0,{onNavigate:Hi,onRefresh:Dt}),!me&&d==="reports"&&c&&n.jsx(c0,{organizations:v,userRole:i}),!me&&d==="incidents"&&n.jsx(Iy,{incidents:o,organizations:v,departments:Q,branches:ee,incidentStatuses:F,initialOrg:j,onView:Jf,onEdit:G?ih:void 0,onDelete:G?_=>Ne(D.incidents,_):void 0,canModify:G}),!me&&d==="ideas"&&n.jsx(By,{ideas:w,organizations:v,departments:Q,branches:ee,ideaStatuses:on,initialOrg:j,onView:qf,onEdit:G?ah:void 0,onDelete:G?_=>Ne(D.ideas,_):void 0,canModify:G}),!me&&d==="orders"&&n.jsx(My,{orders:C,organizations:v,departments:Q,branches:ee,orderStatuses:On,initialOrg:j,onView:Zf,onEdit:G?oh:void 0,onDelete:G?_=>Ne(D.orders,_):void 0,canModify:G}),!me&&d==="processes"&&n.jsx(Gy,{processes:U,organizations:v,departments:Q,branches:ee,processStatuses:L,initialOrg:j,onView:Vf,onEdit:G?ch:void 0,onDelete:G?_=>Ne(D.processes,_):void 0,canModify:G}),!me&&d==="organizations"&&n.jsx(s1,{organizations:v,onView:eh,onEdit:G?dh:void 0,onDelete:G?_=>Ne(D.organizations,_):void 0,canModify:G}),!me&&d==="managements"&&n.jsx(o1,{managements:V,onView:th,onEdit:G?uh:void 0,onDelete:G?_=>Ne(D.managements,_):void 0,canModify:G}),!me&&d==="departments"&&n.jsx(u1,{departments:Q,managements:V,onView:nh,onEdit:G?ph:void 0,onDelete:G?_=>Ne(D.departments,_):void 0,canModify:G}),!me&&d==="branches"&&n.jsx(g1,{branches:ee,managements:V,departments:Q,onView:lh,onEdit:G?fh:void 0,onDelete:G?_=>Ne(D.branches,_):void 0,canModify:G}),!me&&d==="cycles"&&n.jsx(Q1,{cycles:os,canModify:G,onView:rh,onEdit:G?hh:void 0,onDelete:G?_=>Ne(D.cycles,_):void 0}),!me&&d==="kpi-input"&&n.jsx(J1,{kpiInputs:yc,canModify:G,onView:sh,onEdit:G?gh:void 0,onDelete:G?_=>Ne(D.kpiInput,_):void 0}),!me&&d==="incident-types"&&n.jsx(v1,{incidentTypes:A,onView:vh,onEdit:G?jh:void 0,onDelete:G?_=>Ne(D.incidentTypes,_):void 0,canModify:G}),!me&&d==="idea-types"&&n.jsx(S1,{ideaTypes:R,onView:bh,onEdit:G?Sh:void 0,onDelete:G?_=>Ne(D.ideaTypes,_):void 0,canModify:G}),!me&&d==="order-types"&&n.jsx(_1,{orderTypes:Te,onView:wh,onEdit:G?kh:void 0,onDelete:G?_=>Ne(D.orderTypes,_):void 0,canModify:G}),!me&&d==="process-types"&&n.jsx(T1,{processTypes:I,onView:_h,onEdit:G?Ch:void 0,onDelete:G?_=>Ne(D.processTypes,_):void 0,canModify:G}),!me&&d==="incident-statuses"&&n.jsx(E1,{incidentStatuses:F,onView:zh,onEdit:G?Th:void 0,onDelete:G?_=>Ne(D.incidentStatuses,_):void 0,canModify:G}),!me&&d==="idea-statuses"&&n.jsx(L1,{ideaStatuses:on,onView:Ih,onEdit:G?Ph:void 0,onDelete:G?_=>Ne(D.ideaStatuses,_):void 0,canModify:G}),!me&&d==="order-statuses"&&n.jsx(N1,{orderStatuses:On,onView:Eh,onEdit:G?Ah:void 0,onDelete:G?_=>Ne(D.orderStatuses,_):void 0,canModify:G}),!me&&d==="process-statuses"&&n.jsx($1,{processStatuses:L,onView:Rh,onEdit:G?Lh:void 0,onDelete:G?_=>Ne(D.processStatuses,_):void 0,canModify:G}),!me&&d==="users"&&n.jsx(H1,{users:Ft,roleMap:Vn,onView:Oh,onEdit:G?Dh:void 0,onDelete:G?_=>Ne("User",_):void 0,onDisable:G?Xf:void 0,canModify:G}),!me&&d==="delegations"&&u&&n.jsx(t0,{delegations:vc,organizations:v,userRole:i,currentUser:e.name,onView:xh,onRevoke:G?yh:void 0}),d==="profile"&&(()=>{const _=!!cs&&(cs.name===e.name||cs.email===e.name);return n.jsx(n1,{user:e,profileUser:cs,sbUsers:Ft,organizations:v,managements:V,departments:Q,branches:ee,darkMode:l,canModify:G||_,onBack:()=>g(_?a?"dashboard":"inbox":"users"),onNavigate:g})})()]})]})]})}function x0(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 m0(){const[e,t]=S.useState(()=>{try{const c=localStorage.getItem("sidrah_user");return c?JSON.parse(c):null}catch{return null}}),[l,r]=S.useState(()=>localStorage.getItem("sb_dark")==="1"),s=()=>{const c=!l;r(c),localStorage.setItem("sb_dark",c?"1":"0"),document.documentElement.classList.toggle("dark",c)};S.useEffect(()=>{document.documentElement.classList.toggle("dark",l)},[]),S.useEffect(()=>{e&&Af().then(async c=>{const u=c||e.name,h=await Lf(u);if(!h.length)return;const f=x0(h);if(f!==e.role||u!==e.name){const d={...e,name:u,role:f};t(d),localStorage.setItem("sidrah_user",JSON.stringify(d))}})},[e==null?void 0:e.name]);const i=c=>{t(c),localStorage.setItem("sidrah_user",JSON.stringify(c))},a=()=>{t(null),localStorage.removeItem("sidrah_user")};return e?n.jsx(g0,{user:e,onLogout:a,darkMode:l,onToggleDark:s}):n.jsx(vy,{onLogin:i})}_f(document.getElementById("root")).render(n.jsx(S.StrictMode,{children:n.jsx(m0,{})}));