(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))a(r);new MutationObserver(r=>{for(const l of r)if(l.type==="childList")for(const i of l.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&a(i)}).observe(document,{childList:!0,subtree:!0});function s(r){const l={};return r.integrity&&(l.integrity=r.integrity),r.referrerPolicy&&(l.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?l.credentials="include":r.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function a(r){if(r.ep)return;r.ep=!0;const l=s(r);fetch(r.href,l)}})();var Ku={exports:{}},ri={},Xu={exports:{}},ge={};/** * @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 Nr=Symbol.for("react.element"),Bg=Symbol.for("react.portal"),Lg=Symbol.for("react.fragment"),Wg=Symbol.for("react.strict_mode"),Ng=Symbol.for("react.profiler"),$g=Symbol.for("react.provider"),Ug=Symbol.for("react.context"),Mg=Symbol.for("react.forward_ref"),Fg=Symbol.for("react.suspense"),Hg=Symbol.for("react.memo"),Gg=Symbol.for("react.lazy"),_c=Symbol.iterator;function Qg(e){return e===null||typeof e!="object"?null:(e=_c&&e[_c]||e["@@iterator"],typeof e=="function"?e:null)}var Yu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},qu=Object.assign,Ju={};function Ua(e,n,s){this.props=e,this.context=n,this.refs=Ju,this.updater=s||Yu}Ua.prototype.isReactComponent={};Ua.prototype.setState=function(e,n){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,n,"setState")};Ua.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Vu(){}Vu.prototype=Ua.prototype;function yd(e,n,s){this.props=e,this.context=n,this.refs=Ju,this.updater=s||Yu}var vd=yd.prototype=new Vu;vd.constructor=yd;qu(vd,Ua.prototype);vd.isPureReactComponent=!0;var wc=Array.isArray,Zu=Object.prototype.hasOwnProperty,jd={current:null},ep={key:!0,ref:!0,__self:!0,__source:!0};function tp(e,n,s){var a,r={},l=null,i=null;if(n!=null)for(a in n.ref!==void 0&&(i=n.ref),n.key!==void 0&&(l=""+n.key),n)Zu.call(n,a)&&!ep.hasOwnProperty(a)&&(r[a]=n[a]);var d=arguments.length-2;if(d===1)r.children=s;else if(1>>1,O=T[D];if(0>>1;Dr(ie,V))ker(Ie,ie)?(T[D]=Ie,T[ke]=V,D=ke):(T[D]=ie,T[se]=V,D=se);else if(ker(Ie,V))T[D]=Ie,T[ke]=V,D=ke;else break e}}return G}function r(T,G){var V=T.sortIndex-G.sortIndex;return V!==0?V:T.id-G.id}if(typeof performance=="object"&&typeof performance.now=="function"){var l=performance;e.unstable_now=function(){return l.now()}}else{var i=Date,d=i.now();e.unstable_now=function(){return i.now()-d}}var f=[],p=[],C=1,j=null,w=3,c=!1,v=!1,z=!1,k=typeof setTimeout=="function"?setTimeout:null,g=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 h(T){for(var G=s(p);G!==null;){if(G.callback===null)a(p);else if(G.startTime<=T)a(p),G.sortIndex=G.expirationTime,n(f,G);else break;G=s(p)}}function x(T){if(z=!1,h(T),!v)if(s(f)!==null)v=!0,N(y);else{var G=s(p);G!==null&&I(x,G.startTime-T)}}function y(T,G){v=!1,z&&(z=!1,g(b),b=-1),c=!0;var V=w;try{for(h(G),j=s(f);j!==null&&(!(j.expirationTime>G)||T&&!H());){var D=j.callback;if(typeof D=="function"){j.callback=null,w=j.priorityLevel;var O=D(j.expirationTime<=G);G=e.unstable_now(),typeof O=="function"?j.callback=O:j===s(f)&&a(f),h(G)}else a(f);j=s(f)}if(j!==null)var q=!0;else{var se=s(p);se!==null&&I(x,se.startTime-G),q=!1}return q}finally{j=null,w=V,c=!1}}var S=!1,u=null,b=-1,A=5,E=-1;function H(){return!(e.unstable_now()-ET||125D?(T.sortIndex=V,n(p,T),s(f)===null&&T===s(p)&&(z?(g(b),b=-1):z=!0,I(x,V-D))):(T.sortIndex=O,n(f,T),v||c||(v=!0,N(y))),T},e.unstable_shouldYield=H,e.unstable_wrapCallback=function(T){var G=w;return function(){var V=w;w=G;try{return T.apply(this,arguments)}finally{w=V}}}})(lp);rp.exports=lp;var sm=rp.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 am=_,Ht=sm;function X(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),So=Object.prototype.hasOwnProperty,rm=/^[: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]*$/,Cc={},zc={};function lm(e){return So.call(zc,e)?!0:So.call(Cc,e)?!1:rm.test(e)?zc[e]=!0:(Cc[e]=!0,!1)}function im(e,n,s,a){if(s!==null&&s.type===0)return!1;switch(typeof n){case"function":case"symbol":return!0;case"boolean":return a?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function om(e,n,s,a){if(n===null||typeof n>"u"||im(e,n,s,a))return!0;if(a)return!1;if(s!==null)switch(s.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function Tt(e,n,s,a,r,l,i){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=a,this.attributeNamespace=r,this.mustUseProperty=s,this.propertyName=e,this.type=n,this.sanitizeURL=l,this.removeEmptyString=i}var mt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){mt[e]=new Tt(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];mt[n]=new Tt(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){mt[e]=new Tt(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){mt[e]=new Tt(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){mt[e]=new Tt(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){mt[e]=new Tt(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){mt[e]=new Tt(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){mt[e]=new Tt(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){mt[e]=new Tt(e,5,!1,e.toLowerCase(),null,!1,!1)});var Sd=/[\-:]([a-z])/g;function _d(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var n=e.replace(Sd,_d);mt[n]=new Tt(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(Sd,_d);mt[n]=new Tt(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(Sd,_d);mt[n]=new Tt(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){mt[e]=new Tt(e,1,!1,e.toLowerCase(),null,!1,!1)});mt.xlinkHref=new Tt("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){mt[e]=new Tt(e,1,!1,e.toLowerCase(),null,!0,!0)});function wd(e,n,s,a){var r=mt.hasOwnProperty(n)?mt[n]:null;(r!==null?r.type!==0:a||!(2d||r[i]!==l[d]){var f=` `+r[i].replace(" at new "," at ");return e.displayName&&f.includes("")&&(f=f.replace("",e.displayName)),f}while(1<=i&&0<=d);break}}}finally{Ki=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?lr(e):""}function dm(e){switch(e.tag){case 5:return lr(e.type);case 16:return lr("Lazy");case 13:return lr("Suspense");case 19:return lr("SuspenseList");case 0:case 2:case 15:return e=Xi(e.type,!1),e;case 11:return e=Xi(e.type.render,!1),e;case 1:return e=Xi(e.type,!0),e;default:return""}}function Co(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 ha:return"Fragment";case fa:return"Portal";case _o:return"Profiler";case kd:return"StrictMode";case wo:return"Suspense";case ko:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case dp:return(e.displayName||"Context")+".Consumer";case op:return(e._context.displayName||"Context")+".Provider";case Cd:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case zd:return n=e.displayName||null,n!==null?n:Co(e.type)||"Memo";case qn:n=e._payload,e=e._init;try{return Co(e(n))}catch{}}return null}function cm(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Co(n);case 8:return n===kd?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function ps(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function up(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function um(e){var n=up(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),a=""+e[n];if(!e.hasOwnProperty(n)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var r=s.get,l=s.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return r.call(this)},set:function(i){a=""+i,l.call(this,i)}}),Object.defineProperty(e,n,{enumerable:s.enumerable}),{getValue:function(){return a},setValue:function(i){a=""+i},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function tl(e){e._valueTracker||(e._valueTracker=um(e))}function pp(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),a="";return e&&(a=up(e)?e.checked?"true":"false":e.value),e=a,e!==s?(n.setValue(e),!0):!1}function Rl(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 zo(e,n){var s=n.checked;return Ue({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function Ec(e,n){var s=n.defaultValue==null?"":n.defaultValue,a=n.checked!=null?n.checked:n.defaultChecked;s=ps(n.value!=null?n.value:s),e._wrapperState={initialChecked:a,initialValue:s,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function fp(e,n){n=n.checked,n!=null&&wd(e,"checked",n,!1)}function Io(e,n){fp(e,n);var s=ps(n.value),a=n.type;if(s!=null)a==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(a==="submit"||a==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?Eo(e,n.type,s):n.hasOwnProperty("defaultValue")&&Eo(e,n.type,ps(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function Tc(e,n,s){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var a=n.type;if(!(a!=="submit"&&a!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,s||n===e.value||(e.value=n),e.defaultValue=n}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function Eo(e,n,s){(n!=="number"||Rl(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var ir=Array.isArray;function Ca(e,n,s,a){if(e=e.options,n){n={};for(var r=0;r"+n.valueOf().toString()+"",n=nl.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function br(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var ur={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},pm=["Webkit","ms","Moz","O"];Object.keys(ur).forEach(function(e){pm.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),ur[n]=ur[e]})});function xp(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||ur.hasOwnProperty(e)&&ur[e]?(""+n).trim():n+"px"}function yp(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var a=s.indexOf("--")===0,r=xp(s,n[s],a);s==="float"&&(s="cssFloat"),a?e.setProperty(s,r):e[s]=r}}var fm=Ue({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 Po(e,n){if(n){if(fm[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(X(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(X(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(X(61))}if(n.style!=null&&typeof n.style!="object")throw Error(X(62))}}function Ro(e,n){if(e.indexOf("-")===-1)return typeof n.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Oo=null;function Id(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Do=null,za=null,Ia=null;function Rc(e){if(e=Mr(e)){if(typeof Do!="function")throw Error(X(280));var n=e.stateNode;n&&(n=ci(n),Do(e.stateNode,e.type,n))}}function vp(e){za?Ia?Ia.push(e):Ia=[e]:za=e}function jp(){if(za){var e=za,n=Ia;if(Ia=za=null,Rc(e),n)for(e=0;e>>=0,e===0?32:31-(wm(e)/km|0)|0}var sl=64,al=4194304;function or(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 Ll(e,n){var s=e.pendingLanes;if(s===0)return 0;var a=0,r=e.suspendedLanes,l=e.pingedLanes,i=s&268435455;if(i!==0){var d=i&~r;d!==0?a=or(d):(l&=i,l!==0&&(a=or(l)))}else i=s&~r,i!==0?a=or(i):l!==0&&(a=or(l));if(a===0)return 0;if(n!==0&&n!==a&&!(n&r)&&(r=a&-a,l=n&-n,r>=l||r===16&&(l&4194240)!==0))return n;if(a&4&&(a|=s&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=a;0s;s++)n.push(e);return n}function $r(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-xn(n),e[n]=s}function Em(e,n){var s=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var a=e.eventTimes;for(e=e.expirationTimes;0=fr),Mc=" ",Fc=!1;function $p(e,n){switch(e){case"keyup":return sx.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Up(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ga=!1;function rx(e,n){switch(e){case"compositionend":return Up(n);case"keypress":return n.which!==32?null:(Fc=!0,Mc);case"textInput":return e=n.data,e===Mc&&Fc?null:e;default:return null}}function lx(e,n){if(ga)return e==="compositionend"||!Bd&&$p(e,n)?(e=Wp(),_l=Rd=es=null,ga=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1=n)return{node:s,offset:n-e};e=a}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=Kc(s)}}function Gp(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?Gp(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function Qp(){for(var e=window,n=Rl();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=Rl(e.document)}return n}function Ld(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function gx(e){var n=Qp(),s=e.focusedElem,a=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&Gp(s.ownerDocument.documentElement,s)){if(a!==null&&Ld(s)){if(n=a.start,e=a.end,e===void 0&&(e=n),"selectionStart"in s)s.selectionStart=n,s.selectionEnd=Math.min(e,s.value.length);else if(e=(n=s.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var r=s.textContent.length,l=Math.min(a.start,r);a=a.end===void 0?l:Math.min(a.end,r),!e.extend&&l>a&&(r=a,a=l,l=r),r=Xc(s,l);var i=Xc(s,a);r&&i&&(e.rangeCount!==1||e.anchorNode!==r.node||e.anchorOffset!==r.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(n=n.createRange(),n.setStart(r.node,r.offset),e.removeAllRanges(),l>a?(e.addRange(n),e.extend(i.node,i.offset)):(n.setEnd(i.node,i.offset),e.addRange(n)))}}for(n=[],e=s;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s=document.documentMode,ma=null,Uo=null,gr=null,Mo=!1;function Yc(e,n,s){var a=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Mo||ma==null||ma!==Rl(a)||(a=ma,"selectionStart"in a&&Ld(a)?a={start:a.selectionStart,end:a.selectionEnd}:(a=(a.ownerDocument&&a.ownerDocument.defaultView||window).getSelection(),a={anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),gr&&zr(gr,a)||(gr=a,a=$l(Uo,"onSelect"),0va||(e.current=Xo[va],Xo[va]=null,va--)}function Te(e,n){va++,Xo[va]=e.current,e.current=n}var fs={},bt=ms(fs),Dt=ms(!1),Ws=fs;function Ra(e,n){var s=e.type.contextTypes;if(!s)return fs;var a=e.stateNode;if(a&&a.__reactInternalMemoizedUnmaskedChildContext===n)return a.__reactInternalMemoizedMaskedChildContext;var r={},l;for(l in s)r[l]=n[l];return a&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=r),r}function Bt(e){return e=e.childContextTypes,e!=null}function Ml(){Re(Dt),Re(bt)}function nu(e,n,s){if(bt.current!==fs)throw Error(X(168));Te(bt,n),Te(Dt,s)}function tf(e,n,s){var a=e.stateNode;if(n=n.childContextTypes,typeof a.getChildContext!="function")return s;a=a.getChildContext();for(var r in a)if(!(r in n))throw Error(X(108,cm(e)||"Unknown",r));return Ue({},s,a)}function Fl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||fs,Ws=bt.current,Te(bt,e),Te(Dt,Dt.current),!0}function su(e,n,s){var a=e.stateNode;if(!a)throw Error(X(169));s?(e=tf(e,n,Ws),a.__reactInternalMemoizedMergedChildContext=e,Re(Dt),Re(bt),Te(bt,e)):Re(Dt),Te(Dt,s)}var Nn=null,ui=!1,oo=!1;function nf(e){Nn===null?Nn=[e]:Nn.push(e)}function zx(e){ui=!0,nf(e)}function xs(){if(!oo&&Nn!==null){oo=!0;var e=0,n=we;try{var s=Nn;for(we=1;e>=i,r-=i,$n=1<<32-xn(n)+r|s<b?(A=u,u=null):A=u.sibling;var E=w(g,u,h[b],x);if(E===null){u===null&&(u=A);break}e&&u&&E.alternate===null&&n(g,u),o=l(E,o,b),S===null?y=E:S.sibling=E,S=E,u=A}if(b===h.length)return s(g,u),Le&&Ts(g,b),y;if(u===null){for(;bb?(A=u,u=null):A=u.sibling;var H=w(g,u,E.value,x);if(H===null){u===null&&(u=A);break}e&&u&&H.alternate===null&&n(g,u),o=l(H,o,b),S===null?y=H:S.sibling=H,S=H,u=A}if(E.done)return s(g,u),Le&&Ts(g,b),y;if(u===null){for(;!E.done;b++,E=h.next())E=j(g,E.value,x),E!==null&&(o=l(E,o,b),S===null?y=E:S.sibling=E,S=E);return Le&&Ts(g,b),y}for(u=a(g,u);!E.done;b++,E=h.next())E=c(u,g,b,E.value,x),E!==null&&(e&&E.alternate!==null&&u.delete(E.key===null?b:E.key),o=l(E,o,b),S===null?y=E:S.sibling=E,S=E);return e&&u.forEach(function(Y){return n(g,Y)}),Le&&Ts(g,b),y}function k(g,o,h,x){if(typeof h=="object"&&h!==null&&h.type===ha&&h.key===null&&(h=h.props.children),typeof h=="object"&&h!==null){switch(h.$$typeof){case el:e:{for(var y=h.key,S=o;S!==null;){if(S.key===y){if(y=h.type,y===ha){if(S.tag===7){s(g,S.sibling),o=r(S,h.props.children),o.return=g,g=o;break e}}else if(S.elementType===y||typeof y=="object"&&y!==null&&y.$$typeof===qn&&lu(y)===S.type){s(g,S.sibling),o=r(S,h.props),o.ref=tr(g,S,h),o.return=g,g=o;break e}s(g,S);break}else n(g,S);S=S.sibling}h.type===ha?(o=Ls(h.props.children,g.mode,x,h.key),o.return=g,g=o):(x=Al(h.type,h.key,h.props,null,g.mode,x),x.ref=tr(g,o,h),x.return=g,g=x)}return i(g);case fa:e:{for(S=h.key;o!==null;){if(o.key===S)if(o.tag===4&&o.stateNode.containerInfo===h.containerInfo&&o.stateNode.implementation===h.implementation){s(g,o.sibling),o=r(o,h.children||[]),o.return=g,g=o;break e}else{s(g,o);break}else n(g,o);o=o.sibling}o=xo(h,g.mode,x),o.return=g,g=o}return i(g);case qn:return S=h._init,k(g,o,S(h._payload),x)}if(ir(h))return v(g,o,h,x);if(qa(h))return z(g,o,h,x);ul(g,h)}return typeof h=="string"&&h!==""||typeof h=="number"?(h=""+h,o!==null&&o.tag===6?(s(g,o.sibling),o=r(o,h),o.return=g,g=o):(s(g,o),o=mo(h,g.mode,x),o.return=g,g=o),i(g)):s(g,o)}return k}var Da=lf(!0),of=lf(!1),Ql=ms(null),Kl=null,Sa=null,Ud=null;function Md(){Ud=Sa=Kl=null}function Fd(e){var n=Ql.current;Re(Ql),e._currentValue=n}function Jo(e,n,s){for(;e!==null;){var a=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,a!==null&&(a.childLanes|=n)):a!==null&&(a.childLanes&n)!==n&&(a.childLanes|=n),e===s)break;e=e.return}}function Ta(e,n){Kl=e,Ud=Sa=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(Ot=!0),e.firstContext=null)}function sn(e){var n=e._currentValue;if(Ud!==e)if(e={context:e,memoizedValue:n,next:null},Sa===null){if(Kl===null)throw Error(X(308));Sa=e,Kl.dependencies={lanes:0,firstContext:e}}else Sa=Sa.next=e;return n}var Rs=null;function Hd(e){Rs===null?Rs=[e]:Rs.push(e)}function df(e,n,s,a){var r=n.interleaved;return r===null?(s.next=s,Hd(n)):(s.next=r.next,r.next=s),n.interleaved=s,Gn(e,a)}function Gn(e,n){e.lanes|=n;var s=e.alternate;for(s!==null&&(s.lanes|=n),s=e,e=e.return;e!==null;)e.childLanes|=n,s=e.alternate,s!==null&&(s.childLanes|=n),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Jn=!1;function Gd(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function cf(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Mn(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function os(e,n,s){var a=e.updateQueue;if(a===null)return null;if(a=a.shared,ve&2){var r=a.pending;return r===null?n.next=n:(n.next=r.next,r.next=n),a.pending=n,Gn(e,s)}return r=a.interleaved,r===null?(n.next=n,Hd(a)):(n.next=r.next,r.next=n),a.interleaved=n,Gn(e,s)}function kl(e,n,s){if(n=n.updateQueue,n!==null&&(n=n.shared,(s&4194240)!==0)){var a=n.lanes;a&=e.pendingLanes,s|=a,n.lanes=s,Td(e,s)}}function iu(e,n){var s=e.updateQueue,a=e.alternate;if(a!==null&&(a=a.updateQueue,s===a)){var r=null,l=null;if(s=s.firstBaseUpdate,s!==null){do{var i={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};l===null?r=l=i:l=l.next=i,s=s.next}while(s!==null);l===null?r=l=n:l=l.next=n}else r=l=n;s={baseState:a.baseState,firstBaseUpdate:r,lastBaseUpdate:l,shared:a.shared,effects:a.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=n:e.next=n,s.lastBaseUpdate=n}function Xl(e,n,s,a){var r=e.updateQueue;Jn=!1;var l=r.firstBaseUpdate,i=r.lastBaseUpdate,d=r.shared.pending;if(d!==null){r.shared.pending=null;var f=d,p=f.next;f.next=null,i===null?l=p:i.next=p,i=f;var C=e.alternate;C!==null&&(C=C.updateQueue,d=C.lastBaseUpdate,d!==i&&(d===null?C.firstBaseUpdate=p:d.next=p,C.lastBaseUpdate=f))}if(l!==null){var j=r.baseState;i=0,C=p=f=null,d=l;do{var w=d.lane,c=d.eventTime;if((a&w)===w){C!==null&&(C=C.next={eventTime:c,lane:0,tag:d.tag,payload:d.payload,callback:d.callback,next:null});e:{var v=e,z=d;switch(w=n,c=s,z.tag){case 1:if(v=z.payload,typeof v=="function"){j=v.call(c,j,w);break e}j=v;break e;case 3:v.flags=v.flags&-65537|128;case 0:if(v=z.payload,w=typeof v=="function"?v.call(c,j,w):v,w==null)break e;j=Ue({},j,w);break e;case 2:Jn=!0}}d.callback!==null&&d.lane!==0&&(e.flags|=64,w=r.effects,w===null?r.effects=[d]:w.push(d))}else c={eventTime:c,lane:w,tag:d.tag,payload:d.payload,callback:d.callback,next:null},C===null?(p=C=c,f=j):C=C.next=c,i|=w;if(d=d.next,d===null){if(d=r.shared.pending,d===null)break;w=d,d=w.next,w.next=null,r.lastBaseUpdate=w,r.shared.pending=null}}while(!0);if(C===null&&(f=j),r.baseState=f,r.firstBaseUpdate=p,r.lastBaseUpdate=C,n=r.shared.interleaved,n!==null){r=n;do i|=r.lane,r=r.next;while(r!==n)}else l===null&&(r.shared.lanes=0);Us|=i,e.lanes=i,e.memoizedState=j}}function ou(e,n,s){if(e=n.effects,n.effects=null,e!==null)for(n=0;ns?s:4,e(!0);var a=uo.transition;uo.transition={};try{e(!1),n()}finally{we=s,uo.transition=a}}function zf(){return an().memoizedState}function Ax(e,n,s){var a=cs(e);if(s={lane:a,action:s,hasEagerState:!1,eagerState:null,next:null},If(e))Ef(n,s);else if(s=df(e,n,s,a),s!==null){var r=It();yn(s,e,a,r),Tf(s,n,a)}}function Px(e,n,s){var a=cs(e),r={lane:a,action:s,hasEagerState:!1,eagerState:null,next:null};if(If(e))Ef(n,r);else{var l=e.alternate;if(e.lanes===0&&(l===null||l.lanes===0)&&(l=n.lastRenderedReducer,l!==null))try{var i=n.lastRenderedState,d=l(i,s);if(r.hasEagerState=!0,r.eagerState=d,vn(d,i)){var f=n.interleaved;f===null?(r.next=r,Hd(n)):(r.next=f.next,f.next=r),n.interleaved=r;return}}catch{}finally{}s=df(e,n,r,a),s!==null&&(r=It(),yn(s,e,a,r),Tf(s,n,a))}}function If(e){var n=e.alternate;return e===$e||n!==null&&n===$e}function Ef(e,n){mr=ql=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function Tf(e,n,s){if(s&4194240){var a=n.lanes;a&=e.pendingLanes,s|=a,n.lanes=s,Td(e,s)}}var Jl={readContext:sn,useCallback:yt,useContext:yt,useEffect:yt,useImperativeHandle:yt,useInsertionEffect:yt,useLayoutEffect:yt,useMemo:yt,useReducer:yt,useRef:yt,useState:yt,useDebugValue:yt,useDeferredValue:yt,useTransition:yt,useMutableSource:yt,useSyncExternalStore:yt,useId:yt,unstable_isNewReconciler:!1},Rx={readContext:sn,useCallback:function(e,n){return zn().memoizedState=[e,n===void 0?null:n],e},useContext:sn,useEffect:cu,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,zl(4194308,4,Sf.bind(null,n,e),s)},useLayoutEffect:function(e,n){return zl(4194308,4,e,n)},useInsertionEffect:function(e,n){return zl(4,2,e,n)},useMemo:function(e,n){var s=zn();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var a=zn();return n=s!==void 0?s(n):n,a.memoizedState=a.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},a.queue=e,e=e.dispatch=Ax.bind(null,$e,e),[a.memoizedState,e]},useRef:function(e){var n=zn();return e={current:e},n.memoizedState=e},useState:du,useDebugValue:Zd,useDeferredValue:function(e){return zn().memoizedState=e},useTransition:function(){var e=du(!1),n=e[0];return e=Tx.bind(null,e[1]),zn().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var a=$e,r=zn();if(Le){if(s===void 0)throw Error(X(407));s=s()}else{if(s=n(),pt===null)throw Error(X(349));$s&30||hf(a,n,s)}r.memoizedState=s;var l={value:s,getSnapshot:n};return r.queue=l,cu(mf.bind(null,a,l,e),[e]),a.flags|=2048,Dr(9,gf.bind(null,a,l,s,n),void 0,null),s},useId:function(){var e=zn(),n=pt.identifierPrefix;if(Le){var s=Un,a=$n;s=(a&~(1<<32-xn(a)-1)).toString(32)+s,n=":"+n+"R"+s,s=Rr++,0<\/script>",e=e.removeChild(e.firstChild)):typeof a.is=="string"?e=i.createElement(s,{is:a.is}):(e=i.createElement(s),s==="select"&&(i=e,a.multiple?i.multiple=!0:a.size&&(i.size=a.size))):e=i.createElementNS(e,s),e[In]=n,e[Tr]=a,$f(e,n,!1,!1),n.stateNode=e;e:{switch(i=Ro(s,a),s){case"dialog":Pe("cancel",e),Pe("close",e),r=a;break;case"iframe":case"object":case"embed":Pe("load",e),r=a;break;case"video":case"audio":for(r=0;rWa&&(n.flags|=128,a=!0,nr(l,!1),n.lanes=4194304)}else{if(!a)if(e=Yl(i),e!==null){if(n.flags|=128,a=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),nr(l,!0),l.tail===null&&l.tailMode==="hidden"&&!i.alternate&&!Le)return vt(n),null}else 2*Ze()-l.renderingStartTime>Wa&&s!==1073741824&&(n.flags|=128,a=!0,nr(l,!1),n.lanes=4194304);l.isBackwards?(i.sibling=n.child,n.child=i):(s=l.last,s!==null?s.sibling=i:n.child=i,l.last=i)}return l.tail!==null?(n=l.tail,l.rendering=n,l.tail=n.sibling,l.renderingStartTime=Ze(),n.sibling=null,s=Ne.current,Te(Ne,a?s&1|2:s&1),n):(vt(n),null);case 22:case 23:return rc(),a=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==a&&(n.flags|=8192),a&&n.mode&1?Ut&1073741824&&(vt(n),n.subtreeFlags&6&&(n.flags|=8192)):vt(n),null;case 24:return null;case 25:return null}throw Error(X(156,n.tag))}function Ux(e,n){switch(Nd(n),n.tag){case 1:return Bt(n.type)&&Ml(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Ba(),Re(Dt),Re(bt),Xd(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return Kd(n),null;case 13:if(Re(Ne),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(X(340));Oa()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Re(Ne),null;case 4:return Ba(),null;case 10:return Fd(n.type._context),null;case 22:case 23:return rc(),null;case 24:return null;default:return null}}var fl=!1,jt=!1,Mx=typeof WeakSet=="function"?WeakSet:Set,Z=null;function _a(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(a){Xe(e,n,a)}else s.current=null}function ld(e,n,s){try{s()}catch(a){Xe(e,n,a)}}var bu=!1;function Fx(e,n){if(Fo=Wl,e=Qp(),Ld(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var a=s.getSelection&&s.getSelection();if(a&&a.rangeCount!==0){s=a.anchorNode;var r=a.anchorOffset,l=a.focusNode;a=a.focusOffset;try{s.nodeType,l.nodeType}catch{s=null;break e}var i=0,d=-1,f=-1,p=0,C=0,j=e,w=null;t:for(;;){for(var c;j!==s||r!==0&&j.nodeType!==3||(d=i+r),j!==l||a!==0&&j.nodeType!==3||(f=i+a),j.nodeType===3&&(i+=j.nodeValue.length),(c=j.firstChild)!==null;)w=j,j=c;for(;;){if(j===e)break t;if(w===s&&++p===r&&(d=i),w===l&&++C===a&&(f=i),(c=j.nextSibling)!==null)break;j=w,w=j.parentNode}j=c}s=d===-1||f===-1?null:{start:d,end:f}}else s=null}s=s||{start:0,end:0}}else s=null;for(Ho={focusedElem:e,selectionRange:s},Wl=!1,Z=n;Z!==null;)if(n=Z,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,Z=e;else for(;Z!==null;){n=Z;try{var v=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(v!==null){var z=v.memoizedProps,k=v.memoizedState,g=n.stateNode,o=g.getSnapshotBeforeUpdate(n.elementType===n.type?z:hn(n.type,z),k);g.__reactInternalSnapshotBeforeUpdate=o}break;case 3:var h=n.stateNode.containerInfo;h.nodeType===1?h.textContent="":h.nodeType===9&&h.documentElement&&h.removeChild(h.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(X(163))}}catch(x){Xe(n,n.return,x)}if(e=n.sibling,e!==null){e.return=n.return,Z=e;break}Z=n.return}return v=bu,bu=!1,v}function xr(e,n,s){var a=n.updateQueue;if(a=a!==null?a.lastEffect:null,a!==null){var r=a=a.next;do{if((r.tag&e)===e){var l=r.destroy;r.destroy=void 0,l!==void 0&&ld(n,s,l)}r=r.next}while(r!==a)}}function hi(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var s=n=n.next;do{if((s.tag&e)===e){var a=s.create;s.destroy=a()}s=s.next}while(s!==n)}}function id(e){var n=e.ref;if(n!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof n=="function"?n(e):n.current=e}}function Ff(e){var n=e.alternate;n!==null&&(e.alternate=null,Ff(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[In],delete n[Tr],delete n[Ko],delete n[kx],delete n[Cx])),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 Hf(e){return e.tag===5||e.tag===3||e.tag===4}function Su(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Hf(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 od(e,n,s){var a=e.tag;if(a===5||a===6)e=e.stateNode,n?s.nodeType===8?s.parentNode.insertBefore(e,n):s.insertBefore(e,n):(s.nodeType===8?(n=s.parentNode,n.insertBefore(e,s)):(n=s,n.appendChild(e)),s=s._reactRootContainer,s!=null||n.onclick!==null||(n.onclick=Ul));else if(a!==4&&(e=e.child,e!==null))for(od(e,n,s),e=e.sibling;e!==null;)od(e,n,s),e=e.sibling}function dd(e,n,s){var a=e.tag;if(a===5||a===6)e=e.stateNode,n?s.insertBefore(e,n):s.appendChild(e);else if(a!==4&&(e=e.child,e!==null))for(dd(e,n,s),e=e.sibling;e!==null;)dd(e,n,s),e=e.sibling}var ht=null,gn=!1;function Xn(e,n,s){for(s=s.child;s!==null;)Gf(e,n,s),s=s.sibling}function Gf(e,n,s){if(En&&typeof En.onCommitFiberUnmount=="function")try{En.onCommitFiberUnmount(li,s)}catch{}switch(s.tag){case 5:jt||_a(s,n);case 6:var a=ht,r=gn;ht=null,Xn(e,n,s),ht=a,gn=r,ht!==null&&(gn?(e=ht,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):ht.removeChild(s.stateNode));break;case 18:ht!==null&&(gn?(e=ht,s=s.stateNode,e.nodeType===8?io(e.parentNode,s):e.nodeType===1&&io(e,s),kr(e)):io(ht,s.stateNode));break;case 4:a=ht,r=gn,ht=s.stateNode.containerInfo,gn=!0,Xn(e,n,s),ht=a,gn=r;break;case 0:case 11:case 14:case 15:if(!jt&&(a=s.updateQueue,a!==null&&(a=a.lastEffect,a!==null))){r=a=a.next;do{var l=r,i=l.destroy;l=l.tag,i!==void 0&&(l&2||l&4)&&ld(s,n,i),r=r.next}while(r!==a)}Xn(e,n,s);break;case 1:if(!jt&&(_a(s,n),a=s.stateNode,typeof a.componentWillUnmount=="function"))try{a.props=s.memoizedProps,a.state=s.memoizedState,a.componentWillUnmount()}catch(d){Xe(s,n,d)}Xn(e,n,s);break;case 21:Xn(e,n,s);break;case 22:s.mode&1?(jt=(a=jt)||s.memoizedState!==null,Xn(e,n,s),jt=a):Xn(e,n,s);break;default:Xn(e,n,s)}}function _u(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new Mx),n.forEach(function(a){var r=Vx.bind(null,e,a);s.has(a)||(s.add(a),a.then(r,r))})}}function pn(e,n){var s=n.deletions;if(s!==null)for(var a=0;ar&&(r=i),a&=~l}if(a=r,a=Ze()-a,a=(120>a?120:480>a?480:1080>a?1080:1920>a?1920:3e3>a?3e3:4320>a?4320:1960*Gx(a/1960))-a,10e?16:e,ts===null)var a=!1;else{if(e=ts,ts=null,ei=0,ve&6)throw Error(X(331));var r=ve;for(ve|=4,Z=e.current;Z!==null;){var l=Z,i=l.child;if(Z.flags&16){var d=l.deletions;if(d!==null){for(var f=0;fZe()-sc?Bs(e,0):nc|=s),Lt(e,n)}function Zf(e,n){n===0&&(e.mode&1?(n=al,al<<=1,!(al&130023424)&&(al=4194304)):n=1);var s=It();e=Gn(e,n),e!==null&&($r(e,n,s),Lt(e,s))}function Jx(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),Zf(e,s)}function Vx(e,n){var s=0;switch(e.tag){case 13:var a=e.stateNode,r=e.memoizedState;r!==null&&(s=r.retryLane);break;case 19:a=e.stateNode;break;default:throw Error(X(314))}a!==null&&a.delete(n),Zf(e,s)}var eh;eh=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||Dt.current)Ot=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return Ot=!1,Nx(e,n,s);Ot=!!(e.flags&131072)}else Ot=!1,Le&&n.flags&1048576&&sf(n,Gl,n.index);switch(n.lanes=0,n.tag){case 2:var a=n.type;Il(e,n),e=n.pendingProps;var r=Ra(n,bt.current);Ta(n,s),r=qd(null,n,a,e,r,s);var l=Jd();return n.flags|=1,typeof r=="object"&&r!==null&&typeof r.render=="function"&&r.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,Bt(a)?(l=!0,Fl(n)):l=!1,n.memoizedState=r.state!==null&&r.state!==void 0?r.state:null,Gd(n),r.updater=fi,n.stateNode=r,r._reactInternals=n,Zo(n,a,e,s),n=nd(null,n,a,!0,l,s)):(n.tag=0,Le&&l&&Wd(n),zt(null,n,r,s),n=n.child),n;case 16:a=n.elementType;e:{switch(Il(e,n),e=n.pendingProps,r=a._init,a=r(a._payload),n.type=a,r=n.tag=ey(a),e=hn(a,e),r){case 0:n=td(null,n,a,e,s);break e;case 1:n=yu(null,n,a,e,s);break e;case 11:n=mu(null,n,a,e,s);break e;case 14:n=xu(null,n,a,hn(a.type,e),s);break e}throw Error(X(306,a,""))}return n;case 0:return a=n.type,r=n.pendingProps,r=n.elementType===a?r:hn(a,r),td(e,n,a,r,s);case 1:return a=n.type,r=n.pendingProps,r=n.elementType===a?r:hn(a,r),yu(e,n,a,r,s);case 3:e:{if(Lf(n),e===null)throw Error(X(387));a=n.pendingProps,l=n.memoizedState,r=l.element,cf(e,n),Xl(n,a,null,s);var i=n.memoizedState;if(a=i.element,l.isDehydrated)if(l={element:a,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},n.updateQueue.baseState=l,n.memoizedState=l,n.flags&256){r=La(Error(X(423)),n),n=vu(e,n,a,s,r);break e}else if(a!==r){r=La(Error(X(424)),n),n=vu(e,n,a,s,r);break e}else for(Mt=is(n.stateNode.containerInfo.firstChild),Ft=n,Le=!0,mn=null,s=of(n,null,a,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(Oa(),a===r){n=Qn(e,n,s);break e}zt(e,n,a,s)}n=n.child}return n;case 5:return uf(n),e===null&&qo(n),a=n.type,r=n.pendingProps,l=e!==null?e.memoizedProps:null,i=r.children,Go(a,r)?i=null:l!==null&&Go(a,l)&&(n.flags|=32),Bf(e,n),zt(e,n,i,s),n.child;case 6:return e===null&&qo(n),null;case 13:return Wf(e,n,s);case 4:return Qd(n,n.stateNode.containerInfo),a=n.pendingProps,e===null?n.child=Da(n,null,a,s):zt(e,n,a,s),n.child;case 11:return a=n.type,r=n.pendingProps,r=n.elementType===a?r:hn(a,r),mu(e,n,a,r,s);case 7:return zt(e,n,n.pendingProps,s),n.child;case 8:return zt(e,n,n.pendingProps.children,s),n.child;case 12:return zt(e,n,n.pendingProps.children,s),n.child;case 10:e:{if(a=n.type._context,r=n.pendingProps,l=n.memoizedProps,i=r.value,Te(Ql,a._currentValue),a._currentValue=i,l!==null)if(vn(l.value,i)){if(l.children===r.children&&!Dt.current){n=Qn(e,n,s);break e}}else for(l=n.child,l!==null&&(l.return=n);l!==null;){var d=l.dependencies;if(d!==null){i=l.child;for(var f=d.firstContext;f!==null;){if(f.context===a){if(l.tag===1){f=Mn(-1,s&-s),f.tag=2;var p=l.updateQueue;if(p!==null){p=p.shared;var C=p.pending;C===null?f.next=f:(f.next=C.next,C.next=f),p.pending=f}}l.lanes|=s,f=l.alternate,f!==null&&(f.lanes|=s),Jo(l.return,s,n),d.lanes|=s;break}f=f.next}}else if(l.tag===10)i=l.type===n.type?null:l.child;else if(l.tag===18){if(i=l.return,i===null)throw Error(X(341));i.lanes|=s,d=i.alternate,d!==null&&(d.lanes|=s),Jo(i,s,n),i=l.sibling}else i=l.child;if(i!==null)i.return=l;else for(i=l;i!==null;){if(i===n){i=null;break}if(l=i.sibling,l!==null){l.return=i.return,i=l;break}i=i.return}l=i}zt(e,n,r.children,s),n=n.child}return n;case 9:return r=n.type,a=n.pendingProps.children,Ta(n,s),r=sn(r),a=a(r),n.flags|=1,zt(e,n,a,s),n.child;case 14:return a=n.type,r=hn(a,n.pendingProps),r=hn(a.type,r),xu(e,n,a,r,s);case 15:return Of(e,n,n.type,n.pendingProps,s);case 17:return a=n.type,r=n.pendingProps,r=n.elementType===a?r:hn(a,r),Il(e,n),n.tag=1,Bt(a)?(e=!0,Fl(n)):e=!1,Ta(n,s),Af(n,a,r),Zo(n,a,r,s),nd(null,n,a,!0,e,s);case 19:return Nf(e,n,s);case 22:return Df(e,n,s)}throw Error(X(156,n.tag))};function th(e,n){return zp(e,n)}function Zx(e,n,s,a){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=a,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function en(e,n,s,a){return new Zx(e,n,s,a)}function ic(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ey(e){if(typeof e=="function")return ic(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Cd)return 11;if(e===zd)return 14}return 2}function us(e,n){var s=e.alternate;return s===null?(s=en(e.tag,n,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=n,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,n=e.dependencies,s.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function Al(e,n,s,a,r,l){var i=2;if(a=e,typeof e=="function")ic(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case ha:return Ls(s.children,r,l,n);case kd:i=8,r|=8;break;case _o:return e=en(12,s,n,r|2),e.elementType=_o,e.lanes=l,e;case wo:return e=en(13,s,n,r),e.elementType=wo,e.lanes=l,e;case ko:return e=en(19,s,n,r),e.elementType=ko,e.lanes=l,e;case cp:return mi(s,r,l,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case op:i=10;break e;case dp:i=9;break e;case Cd:i=11;break e;case zd:i=14;break e;case qn:i=16,a=null;break e}throw Error(X(130,e==null?e:typeof e,""))}return n=en(i,s,n,r),n.elementType=e,n.type=a,n.lanes=l,n}function Ls(e,n,s,a){return e=en(7,e,a,n),e.lanes=s,e}function mi(e,n,s,a){return e=en(22,e,a,n),e.elementType=cp,e.lanes=s,e.stateNode={isHidden:!1},e}function mo(e,n,s){return e=en(6,e,null,n),e.lanes=s,e}function xo(e,n,s){return n=en(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function ty(e,n,s,a,r){this.tag=n,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=qi(0),this.expirationTimes=qi(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=qi(0),this.identifierPrefix=a,this.onRecoverableError=r,this.mutableSourceEagerHydrationData=null}function oc(e,n,s,a,r,l,i,d,f){return e=new ty(e,n,s,d,f),n===1?(n=1,l===!0&&(n|=8)):n=0,l=en(3,null,null,n),e.current=l,l.stateNode=e,l.memoizedState={element:a,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Gd(l),e}function ny(e,n,s){var a=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(rh)}catch(e){console.error(e)}}rh(),ap.exports=Gt;var iy=ap.exports,lh,Au=iy;lh=Au.createRoot,Au.hydrateRoot;const pe="",P={incidents:"SB Incident",ideas:"SB Idea",orders:"SB Order",organizations:"SB Organization",processes:"SB Process",managements:"Managements",departments:"Department",branches:"Branch",incidentTypes:"Incident Types",ideaTypes:"Idea Types",orderTypes:"Order Types",processTypes:"Process Types",incidentClass:"Incident Class",incidentField:"Incident Field",incidentStatuses:"Incident Statuses",ideaStatuses:"Idea Statuses",orderStatuses:"Order Statuses",processStatuses:"Process Statuses",users:"User",cycles:"SB Cycle",kpiInput:"SB KPI Input",delegations:"SB Delegation",groupCompanies:"SB Group Company",currency:"Currency"},J={bg:"#f5f6fa",accent:"#4f46e5",red:"#ef4444",orange:"#f59e0b",green:"#16a34a",purple:"#7c3aed",blue:"#2563eb",teal:"#0d9488",gray:"#94a3b8"},oy=[{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"}],hd=[{id:"group-companies",icon:"🌐",label:"Group Companies"},{id:"users",icon:"👤",label:"Users"},{id:"organizations",icon:"🏢",label:"Organizations"},{id:"managements",icon:"🏗️",label:"Managements"},{id:"departments",icon:"🗂️",label:"Departments"},{id:"branches",icon:"🌿",label:"Branches"},{id:"cycles",icon:"🔄",label:"Cycles"},{id:"kpi-input",icon:"📊",label:"KPI Input"},{id:"incident-types",icon:"🚨",label:"Incident Types"},{id:"idea-types",icon:"💡",label:"Idea Types"},{id:"order-types",icon:"📦",label:"Order Types"},{id:"process-types",icon:"⚙️",label:"Process Types"},{id:"incident-statuses",icon:"🔴",label:"Incident Statuses"},{id:"idea-statuses",icon:"🟢",label:"Idea Statuses"},{id:"order-statuses",icon:"🟣",label:"Order Statuses"},{id:"process-statuses",icon:"🔵",label:"Process Statuses"}],dy=new Set(["users","group-companies"]);function cy(e){return e==="Business Owner"||e==="Owner"?hd.filter(({id:n})=>n==="organizations"||n==="departments"||n==="users"):e!=="Admin"&&e!=="Auditor"&&e!=="CEO"?[]:hd.filter(({id:n})=>e==="Admin"||e==="CEO"||!dy.has(n))}const Yn=(e=[])=>[{key:"name1",label:"Name"},{key:"status",label:"Status"},...e,{key:"creation_date",label:"Created On"}],uy={incidents:{label:"Incidents",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"date",label:"Date"},{key:"assigned_to",label:"Assigned To"},{key:"priority",label:"Priority"},{key:"economy_class",label:"Economy Class"},{key:"entity_scope",label:"Entity Scope"},{key:"hses_field",label:"HSES Field"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","date","assigned_to"]},ideas:{label:"Ideas",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"date",label:"Date"},{key:"assigned_to",label:"Assigned To"},{key:"priority",label:"Priority"},{key:"economy_class",label:"Economy Class"},{key:"current_condition",label:"Current Condition"},{key:"proposed_condition",label:"Proposed Condition"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","date","assigned_to"]},orders:{label:"Orders",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"starting_date",label:"Start Date"},{key:"ending_date",label:"End Date"},{key:"assigned_to",label:"Assigned To"},{key:"budget",label:"Budget"},{key:"actual_cost",label:"Actual Cost"},{key:"currency",label:"Currency"},{key:"stage",label:"Stage"},{key:"completion_pct",label:"Completion %"},{key:"priority",label:"Priority"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","starting_date","ending_date","assigned_to","budget"]},processes:{label:"Processes",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"title",label:"Title"},{key:"organization",label:"Organization"},{key:"type",label:"Type"},{key:"status",label:"Status"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"branch",label:"Branch"},{key:"date_start",label:"Start Date"},{key:"date_end",label:"End Date"},{key:"actor",label:"Actor"},{key:"cycle_type",label:"Cycle Type"},{key:"kpi_name",label:"KPI Name"},{key:"cost_per_cycle",label:"Cost / Cycle"},{key:"escalation_level",label:"Escalation"},{key:"workflow_state",label:"Workflow State"}],defaultColumns:["number","title","organization","type","status","date_start","date_end","actor"]},organizations:{label:"Organizations",columns:[{key:"name",label:"Code"},{key:"organization_name",label:"Organization Name"},{key:"type",label:"Type"},{key:"city",label:"City"},{key:"contact_email",label:"Contact Email"},{key:"is_active",label:"Active"},{key:"creation_date",label:"Created On"}],defaultColumns:["organization_name","type","city","contact_email","is_active"]},managements:{label:"Managements",orgField:"organization",columns:[{key:"name1",label:"Name"},{key:"organization",label:"Organization"},{key:"status",label:"Status"},{key:"creation_date",label:"Created On"}],defaultColumns:["name1","organization","status"]},departments:{label:"Departments",orgField:"custom_organization",columns:[{key:"department_name",label:"Department Name"},{key:"custom_organization",label:"Organization"},{key:"custom_management",label:"Management"},{key:"custom_status",label:"Status"},{key:"custom_creation_date",label:"Created On"}],defaultColumns:["department_name","custom_organization","custom_management","custom_status"]},branches:{label:"Branches",orgField:"organization",columns:[{key:"branch",label:"Branch"},{key:"organization",label:"Organization"},{key:"management",label:"Management"},{key:"department",label:"Department"},{key:"custom_status",label:"Status"},{key:"custom_creation_date",label:"Created On"}],defaultColumns:["branch","organization","management","department","custom_status"]},cycles:{label:"Cycles",orgField:"organization",columns:[{key:"name1",label:"Name"},{key:"organization",label:"Organization"},{key:"frequency",label:"Frequency"},{key:"status",label:"Status"},{key:"start_date",label:"Start Date"},{key:"end_date",label:"End Date"},{key:"update_window_days",label:"Update Window (days)"}],defaultColumns:["name1","organization","frequency","status","start_date","end_date"]},"kpi-input":{label:"KPI Input",orgField:"organization",columns:[{key:"organization",label:"Organization"},{key:"period",label:"Period"},{key:"revenue_growth",label:"Revenue Growth"},{key:"net_profit",label:"Net Profit"},{key:"cash_flow",label:"Cash Flow"},{key:"strategic_goal_pct",label:"Strategic Goal %"},{key:"customer_satisfaction",label:"Customer Satisfaction"},{key:"employee_turnover_pct",label:"Employee Turnover %"},{key:"open_safety_incidents",label:"Open Safety Incidents"},{key:"compliance_score",label:"Compliance Score"}],defaultColumns:["organization","period","revenue_growth","net_profit","cash_flow"]},"incident-types":{label:"Incident Types",columns:Yn(),defaultColumns:["name1","status","creation_date"]},"idea-types":{label:"Idea Types",columns:Yn(),defaultColumns:["name1","status","creation_date"]},"order-types":{label:"Order Types",columns:Yn(),defaultColumns:["name1","status","creation_date"]},"process-types":{label:"Process Types",columns:Yn(),defaultColumns:["name1","status","creation_date"]},"incident-statuses":{label:"Incident Statuses",columns:Yn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"idea-statuses":{label:"Idea Statuses",columns:Yn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"order-statuses":{label:"Order Statuses",columns:Yn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},"process-statuses":{label:"Process Statuses",columns:Yn([{key:"notify_manager",label:"Notify Manager"}]),defaultColumns:["name1","status","notify_manager"]},users:{label:"Users",orgField:"custom_organization",columns:[{key:"full_name",label:"Full Name"},{key:"email",label:"Email"},{key:"username",label:"Username"},{key:"mobile_no",label:"Phone"},{key:"custom_category",label:"Category"},{key:"custom_organization",label:"Organization"},{key:"custom_management",label:"Management"},{key:"custom_department",label:"Department"},{key:"custom_branch",label:"Branch"},{key:"custom_number",label:"User ID No"},{key:"enabled",label:"Active"},{key:"creation",label:"Created On"}],defaultColumns:["full_name","email","custom_category","custom_organization","enabled"]},delegations:{label:"Delegations",orgField:"organization",columns:[{key:"number",label:"Number"},{key:"auditor",label:"Delegator"},{key:"manager",label:"Manager"},{key:"organization",label:"Organization"},{key:"incident_initial_evaluation",label:"Incident Initial Evaluation"},{key:"idea_initial_evaluation",label:"Idea Initial Evaluation"},{key:"status",label:"Status"},{key:"requested_on",label:"Requested On"},{key:"responded_on",label:"Responded On"}],defaultColumns:["number","auditor","manager","organization","incident_initial_evaluation","idea_initial_evaluation","status","requested_on"]},"group-companies":{label:"Group Companies",columns:[{key:"company_name",label:"Company Name"},{key:"code",label:"Code"},{key:"acronym",label:"Acronym"},{key:"owner_user",label:"Group Co Owner"},{key:"status",label:"Status"}],defaultColumns:["company_name","code","acronym","owner_user","status"]}},py=()=>t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),fy=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),hy=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"}),t.jsx("path",{d:"M10 11v6M14 11v6"}),t.jsx("path",{d:"M9 6V4h6v2"})]});function dt({onView:e,onEdit:n,onDelete:s}){const a=(r,l,i,d,f,p)=>d?t.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),d()},title:p,style:{width:30,height:30,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"1px solid transparent",cursor:"pointer",background:r,color:i,flexShrink:0,transition:"all 0.15s ease"},onMouseEnter:C=>{C.currentTarget.style.background=l,C.currentTarget.style.transform="scale(1.08)"},onMouseLeave:C=>{C.currentTarget.style.background=r,C.currentTarget.style.transform="scale(1)"},children:f},p):null;return t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[a("#f0f9ff","#e0f2fe","#0284c7",e,t.jsx(py,{}),"View"),a("#f0fdf4","#dcfce7","#16a34a",n,t.jsx(fy,{}),"Edit"),s&&a("#fff1f2","#fee2e2","#e11d48",s,t.jsx(hy,{}),"Delete")]})}const B={width:"100%",height:34,padding:"7px 10px",border:"1px solid #ddd",borderRadius:6,fontSize:12,boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif"},R={display:"block",marginBottom:5,fontSize:11,color:"#555",fontWeight:600};function nt(e){return e?e.custom_is_deleted===1||e.custom_is_deleted==="1"||e.custom_is_deleted===!0||e.is_deleted===1||e.is_deleted==="1"||e.is_deleted===!0||e.status==="Deleted"||e.custom_status==="Deleted"||e.enabled===0||e.enabled===!1||e.docstatus===2:!1}function gy(e){return nt(e)?!1:typeof(e==null?void 0:e.is_active)<"u"?!!e.is_active:typeof(e==null?void 0:e.status)<"u"?e.status!=="Inactive":typeof(e==null?void 0:e.custom_status)<"u"?e.custom_status!=="Inactive":!0}function Se(e,n){return(e||[]).filter(s=>!nt(s)&&(gy(s)||s.name===n))}const my={incident:["Rejected","Executed & Closed"],idea:["Rejected","Executed & Closed"],order:["Closed"],process:["Closed"]};function ns(e,n){return!!n&&my[e].includes(n)}function nn(e,n){return(e||[]).filter(s=>{if(!s||nt(s))return!1;const a=s,r=a.organization||a.custom_organization;if(n.organization&&r&&r!==n.organization)return!1;const l=a.management||a.custom_management;if(n.management&&l&&l!==n.management)return!1;const i=a.department||a.custom_department;return!(n.department&&i&&i!==n.department)})}function Na(e,n,s,a){return(e||[]).filter(r=>{if(!r||nt(r)||r.enabled===0||r.enabled===!1)return!1;const l=n[r.name]||[],i=r.custom_category||"",d=s==="SB Manager"&&i==="Manager"||s==="SB Employee"&&i==="Employee"||s==="SB Auditor"&&(i==="Auditor"||i==="X-Auditor")||s==="SB Admin"&&i==="Admin"||(s==="CEO"||s==="SB CEO")&&(i==="CEO"||i==="Chairman");return!((l.includes("SB Admin")||l.includes("System Manager")||i==="Admin")&&s!=="SB Admin"||!l.includes(s)&&!d||a&&r.custom_organization&&r.custom_organization!==a)})}const $a={width:16,height:16,cursor:"pointer",accentColor:"#2563eb",flexShrink:0};function Pl(e){const n=(e||"").trim().toLowerCase();return n==="new"||n==="initial evaluation"||n==="draft"?{bg:"#eff6ff",color:"#1d4ed8",border:"#bfdbfe"}:n.includes("progress")||n.includes("review")||n.includes("proposal")||n.includes("resolution")?{bg:"#fefce8",color:"#a16207",border:"#fef08a"}:n.includes("executed")||n.includes("approved")||n.includes("active")||n.includes("closed")||n.includes("completed")?{bg:"#f0fdf4",color:"#15803d",border:"#bbf7d0"}:n.includes("rejected")||n.includes("overdue")||n.includes("fail")||n.includes("inactive")?{bg:"#fef2f2",color:"#b91c1c",border:"#fecaca"}:n.includes("deleted")?{bg:"#fff1f2",color:"#e11d48",border:"#fecdd3"}:{bg:"#f8fafc",color:"#475569",border:"#e2e8f0"}}function xy(e){const n=(e||"").trim().toLowerCase();return n.includes("incident")?{bg:"#f1f5f9",color:"#334155",border:"#cbd5e1"}:n.includes("complaint")?{bg:"#fff7ed",color:"#c2410c",border:"#fed7aa"}:n.includes("violation")?{bg:"#faf5ff",color:"#7e22ce",border:"#e9d5ff"}:n.includes("process")?{bg:"#f0fdfa",color:"#0f766e",border:"#99f6e4"}:n.includes("asset")?{bg:"#ecfeff",color:"#0e7490",border:"#a5f3fc"}:n.includes("human")?{bg:"#f5f3ff",color:"#6d28d9",border:"#ddd6fe"}:n.includes("idea")?{bg:"#ecfdf5",color:"#047857",border:"#a7f3d0"}:n.includes("study")?{bg:"#eff6ff",color:"#1d4ed8",border:"#bfdbfe"}:{bg:"#f8fafc",color:"#475569",border:"#e2e8f0"}}const Lr=(e,n)=>{let s;return typeof n=="object"&&n!==null?s=n:typeof n=="string"&&n.startsWith("#")?s=Pl(e):typeof n=="string"?s=Pl(n):s=Pl(e),t.jsx("span",{className:"status-badge",style:{background:s.bg,color:s.color,border:`1px solid ${s.border}`,padding:"2px 8px",borderRadius:9999,fontSize:11,fontWeight:600,letterSpacing:"0.2px",display:"inline-flex",alignItems:"center",justifyContent:"center",lineHeight:1.3,whiteSpace:"nowrap",boxSizing:"border-box",transition:"all 0.15s ease"},children:e})},hs=e=>Lr(e,Pl(e)),pc=e=>Lr(e,xy(e));function et({deletedBy:e,deletedOn:n,reason:s,onRestore:a,onPermanentDelete:r,isRestoring:l}){return t.jsxs("div",{style:{background:"#fff1f2",border:"1px solid #fecdd3",borderRadius:8,padding:"7px 14px",marginBottom:12,display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,color:"#9f1239",fontSize:12,flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsxs("div",{style:{fontWeight:700,fontSize:12,display:"flex",alignItems:"center",gap:5,color:"#be123c",whiteSpace:"nowrap"},children:[t.jsx("span",{style:{fontSize:13},children:"⚠️"}),t.jsx("span",{children:"DELETED RECORD / سجل محذوف"})]}),t.jsxs("div",{style:{fontSize:11,color:"#881337",display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e&&t.jsxs("span",{children:[t.jsx("strong",{children:"Deleted By:"})," ",e]}),n&&t.jsxs("span",{children:["| ",t.jsx("strong",{children:"Deleted On:"})," ",n]}),s&&t.jsxs("span",{children:["| ",t.jsx("strong",{children:"Reason:"})," ",s]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[a&&t.jsxs("button",{type:"button",onClick:a,disabled:l,style:{background:"#16a34a",color:"white",border:"none",borderRadius:6,padding:"5px 12px",fontSize:11,fontWeight:700,cursor:l?"not-allowed":"pointer",boxShadow:"0 1px 2px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:5,whiteSpace:"nowrap",transition:"all 0.15s ease"},onMouseEnter:i=>{l||(i.currentTarget.style.background="#15803d")},onMouseLeave:i=>{l||(i.currentTarget.style.background="#16a34a")},children:[t.jsx("span",{children:"↺"}),t.jsx("span",{children:l?"Restoring...":"Restore Record / استعادة"})]}),r&&t.jsxs("button",{type:"button",onClick:r,style:{background:"#dc2626",color:"white",border:"none",borderRadius:6,padding:"5px 12px",fontSize:11,fontWeight:700,cursor:"pointer",boxShadow:"0 1px 2px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:5,whiteSpace:"nowrap",transition:"all 0.15s ease"},onMouseEnter:i=>{i.currentTarget.style.background="#b91c1c"},onMouseLeave:i=>{i.currentTarget.style.background="#dc2626"},children:[t.jsx("span",{children:"🗑️"}),t.jsx("span",{children:"Permanent Delete / حذف نهائي"})]})]})]})}function bi({onDelete:e,disabled:n,title:s="Delete Request",btnText:a="Delete"}){return t.jsxs("div",{style:{background:"#ffffff",borderRadius:10,padding:14,border:"1px solid #fee2e2",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:s}),t.jsxs("button",{type:"button",onClick:e,disabled:n,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:"#dc2626",color:"#ffffff",fontWeight:700,fontSize:12,cursor:n?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:6,boxShadow:"0 1px 3px rgba(220, 38, 38, 0.25)",transition:"all 0.15s ease"},onMouseEnter:r=>{n||(r.currentTarget.style.background="#b91c1c")},onMouseLeave:r=>{n||(r.currentTarget.style.background="#dc2626")},children:[t.jsx("span",{children:"🗑️"}),t.jsx("span",{children:a})]})]})}function ce({title:e,children:n,style:s}){return t.jsxs("div",{className:"form-card",style:{background:"#ffffff",borderRadius:10,border:"1px solid #e2e8f0",padding:"16px 20px",marginBottom:16,boxShadow:"0 1px 3px rgba(0, 0, 0, 0.03)",...s},children:[t.jsx("div",{className:"form-card-title",style:{fontSize:14,fontWeight:700,color:"#1e293b",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:t.jsx("span",{children:e})}),n]})}function Si({title:e="Status Summary",priority:n,createdDate:s,modifiedDate:a,assignedTo:r,status:l}){const i=d=>{if(!d)return"—";try{const f=new Date(d);return isNaN(f.getTime())?d:f.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return d}};return t.jsxs("div",{style:{background:"#ffffff",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:12},children:e}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[n&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Priority"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:n==="High"||n==="Urgent"?"#dc2626":"#1e293b"},children:n})]}),l&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Status"}),t.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#334155"},children:l})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:3},children:"Assigned To"}),t.jsx("div",{style:{fontSize:12,fontWeight:600,color:r?"#334155":"#94a3b8",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r||"—"})]}),s&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:2},children:"Created"}),t.jsx("div",{style:{fontSize:11,color:"#64748b"},children:i(s)})]}),a&&t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:2},children:"Last Modified"}),t.jsx("div",{style:{fontSize:11,color:"#64748b"},children:i(a)})]})]})]})}const yy="modulepreload",vy=function(e){return"/"+e},Pu={},jy=function(n,s,a){let r=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),d=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));r=Promise.allSettled(s.map(f=>{if(f=vy(f),f in Pu)return;Pu[f]=!0;const p=f.endsWith(".css"),C=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${C}`))return;const j=document.createElement("link");if(j.rel=p?"stylesheet":yy,p||(j.as="script"),j.crossOrigin="",j.href=f,d&&j.setAttribute("nonce",d),document.head.appendChild(j),p)return new Promise((w,c)=>{j.addEventListener("load",w),j.addEventListener("error",()=>c(new Error(`Unable to preload CSS for ${f}`)))})}))}function l(i){const d=new Event("vite:preloadError",{cancelable:!0});if(d.payload=i,window.dispatchEvent(d),!d.defaultPrevented)throw i}return r.then(i=>{for(const d of i||[])d.status==="rejected"&&l(d.reason);return n().catch(l)})};function ih(e,n){const s=e[n.key];return s==null||s===""?"":typeof s=="object"?JSON.stringify(s):String(s)}function by(e,n){const s=URL.createObjectURL(e),a=document.createElement("a");a.href=s,a.download=n,a.click(),URL.revokeObjectURL(s)}function Sy(e,n,s){const a=e.map(i=>`"${i.label.replace(/"/g,'""')}"`).join(","),r=n.map(i=>e.map(d=>`"${ih(i,d).replace(/"/g,'""')}"`).join(",")).join(` `),l=new Blob([a+` `+r],{type:"text/csv;charset=utf-8;"});by(l,`${s}.csv`)}async function _y(e,n,s){const a=await jy(()=>import("./xlsx-D_0l8YDs.js"),[]),r=n.map(d=>{const f={};for(const p of e)f[p.label]=ih(d,p);return f}),l=a.utils.json_to_sheet(r,{header:e.map(d=>d.label)}),i=a.utils.book_new();a.utils.book_append_sheet(i,l,"Export"),a.writeFile(i,`${s}.xlsx`)}const wn="#16a34a";function wy({title:e,rows:n,selectedRows:s=[],pageRows:a=[],columns:r,defaultColumnKeys:l,filenameBase:i,onClose:d}){const[f,p]=_.useState(s.length>0?"selected":"all"),[C,j]=_.useState("csv"),[w,c]=_.useState(new Set(l)),[v,z]=_.useState("");_.useEffect(()=>{s&&s.length>0&&p("selected")},[s]);const k=f==="selected"?s:f==="page"?a:n,g=r.filter(b=>w.has(b.key)),o=v?r.filter(b=>b.label.toLowerCase().includes(v.toLowerCase())):r,h=b=>{c(A=>{const E=new Set(A);return E.has(b)?E.delete(b):E.add(b),E})},x=async()=>{g.length===0||k.length===0||(C==="csv"?Sy(g,k,i):await _y(g,k,i),d())},y={fontSize:11,fontWeight:700,color:"#9ca3af",letterSpacing:.4,textTransform:"uppercase",marginBottom:10},S={background:"none",border:"none",color:"#2563eb",fontSize:12,fontWeight:600,cursor:"pointer",padding:0,fontFamily:"inherit"},u=[{id:"selected",label:"Selected rows",sub:`${s.length} row${s.length!==1?"s":""} selected`,count:s.length,disabled:s.length===0},{id:"page",label:"Current page",sub:`${a.length} row${a.length!==1?"s":""} on this page`,count:a.length},{id:"all",label:"All records (current filters)",sub:`${n.length} total matching records`,count:n.length}];return t.jsx("div",{onClick:d,style:{position:"fixed",inset:0,background:"rgba(15,23,42,0.55)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e4},children:t.jsxs("div",{onClick:b=>b.stopPropagation(),style:{width:580,maxWidth:"92vw",maxHeight:"90vh",background:"white",borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{background:wn,color:"white",padding:"16px 22px",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,fontSize:16,fontWeight:700},children:[t.jsx("span",{style:{fontSize:18},children:"📤"})," Export ",e,t.jsxs("span",{style:{fontSize:12,fontWeight:400,opacity:.8},children:[r.length," fields available · ",w.size," selected"]})]}),t.jsx("button",{onClick:d,style:{background:"rgba(255,255,255,0.15)",border:"none",color:"white",width:28,height:28,borderRadius:8,cursor:"pointer",fontSize:15,lineHeight:1},children:"✕"})]}),t.jsxs("div",{style:{padding:"20px 22px",overflowY:"auto",flex:1,display:"flex",flexDirection:"column",gap:20},children:[t.jsxs("div",{children:[t.jsx("div",{style:y,children:"What to export"}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:u.map(b=>t.jsxs("label",{onClick:()=>!b.disabled&&p(b.id),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderRadius:10,cursor:b.disabled?"not-allowed":"pointer",border:`2px solid ${f===b.id?wn:"#e5e7eb"}`,background:f===b.id?"#f0fdf4":b.disabled?"#fafafa":"white",opacity:b.disabled?.5:1,transition:"border-color 0.15s, background 0.15s"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx("div",{style:{width:16,height:16,borderRadius:"50%",border:`2px solid ${f===b.id?wn:"#d1d5db"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:f===b.id&&t.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:wn}})}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#111827"},children:b.label}),t.jsx("div",{style:{fontSize:12,color:"#6b7280",marginTop:1},children:b.sub})]})]}),t.jsx("span",{style:{background:f===b.id?wn:"#e5e7eb",color:f===b.id?"white":"#374151",fontSize:12,fontWeight:700,padding:"2px 10px",borderRadius:9999},children:b.count})]},b.id))})]}),t.jsxs("div",{children:[t.jsx("div",{style:y,children:"File Format"}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[{id:"csv",label:"CSV",desc:"Universal, works everywhere",icon:"📄"},{id:"xlsx",label:"Excel (.xlsx)",desc:"Native Excel workbook",icon:"📊"}].map(b=>t.jsxs("div",{onClick:()=>j(b.id),style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",borderRadius:10,cursor:"pointer",border:`2px solid ${C===b.id?wn:"#e5e7eb"}`,background:C===b.id?"#f0fdf4":"white"},children:[t.jsx("div",{style:{width:16,height:16,borderRadius:"50%",border:`2px solid ${C===b.id?wn:"#d1d5db"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:C===b.id&&t.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:wn}})}),t.jsx("span",{style:{fontSize:20},children:b.icon}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:b.label}),t.jsx("div",{style:{fontSize:11,color:"#888"},children:b.desc})]})]},b.id))})]}),t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[t.jsx("div",{style:{...y,marginBottom:0},children:"Columns to Export"}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("button",{onClick:()=>c(new Set(r.map(b=>b.key))),style:S,children:"All"}),t.jsx("span",{style:{color:"#d1d5db"},children:"|"}),t.jsx("button",{onClick:()=>c(new Set(l)),style:S,children:"Default"}),t.jsx("span",{style:{color:"#d1d5db"},children:"|"}),t.jsx("button",{onClick:()=>c(new Set),style:{...S,color:"#ef4444"},children:"None"})]})]}),t.jsx("div",{style:{marginBottom:8},children:t.jsx("input",{type:"text",placeholder:"Search fields...",value:v,onChange:b=>z(b.target.value),style:{width:"100%",padding:"7px 10px",borderRadius:8,border:"1px solid #e5e7eb",fontSize:12,boxSizing:"border-box",background:"#f9fafb"}})}),t.jsx("div",{style:{border:"1px solid #e5e7eb",borderRadius:8,padding:12,maxHeight:170,overflowY:"auto"},children:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gap:"10px 12px"},children:o.map(b=>t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:7,fontSize:13,color:"#374151",cursor:"pointer",padding:"3px 5px",borderRadius:5,background:w.has(b.key)?"#f0fdf4":"transparent"},children:[t.jsx("input",{type:"checkbox",checked:w.has(b.key),onChange:()=>h(b.key),style:{accentColor:wn,cursor:"pointer"}}),b.label]},b.key))})}),t.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginTop:6},children:[w.size," of ",r.length," fields selected"]})]})]}),t.jsxs("div",{style:{padding:"14px 22px",borderTop:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[t.jsxs("span",{style:{fontSize:12,color:"#888"},children:["Exporting ",k.length," ",f==="selected"?"selected":f==="page"?"page":""," row",k.length!==1?"s":""]}),t.jsxs("div",{style:{display:"flex",gap:10},children:[t.jsx("button",{onClick:d,style:{padding:"9px 18px",borderRadius:8,border:"1px solid #e5e7eb",background:"white",color:"#374151",fontWeight:600,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:"Cancel"}),t.jsx("button",{onClick:x,disabled:g.length===0||k.length===0,style:{padding:"9px 20px",borderRadius:8,border:"none",background:wn,color:"white",fontWeight:700,fontSize:13,cursor:g.length===0||k.length===0?"not-allowed":"pointer",opacity:g.length===0||k.length===0?.5:1,fontFamily:"inherit",display:"flex",alignItems:"center",gap:6},children:"⬇ Export"})]})]})]})})}const oh="sidrah_rtl",gd="sidrah-lang-change";function ka(){try{return localStorage.getItem(oh)==="1"}catch{return!1}}function dh(){const e=!ka();try{localStorage.setItem(oh,e?"1":"0")}catch{}document.documentElement.setAttribute("dir",e?"rtl":"ltr"),document.documentElement.setAttribute("lang",e?"ar":"en-GB"),window.dispatchEvent(new CustomEvent(gd))}function le(){const[e,n]=_.useState(ka);return _.useEffect(()=>{const s=()=>n(ka());return window.addEventListener(gd,s),document.documentElement.setAttribute("dir",ka()?"rtl":"ltr"),document.documentElement.setAttribute("lang",ka()?"ar":"en-GB"),()=>window.removeEventListener(gd,s)},[]),e?Cy:ky}const ky={rtl:!1,nav:{dashboard:"Dashboard",inbox:"Inbox",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",reports:"Reports",users:"Users",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",settings:"Settings"},pages:{dashboard:"Dashboard",inbox:"Inbox",reports:"Reports",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",delegations:"Delegations",organizations:"Organizations",managements:"Managements",departments:"Departments",branches:"Branches",cycles:"Cycles","kpi-input":"KPI Input","incident-types":"Incident Types","idea-types":"Idea Types","order-types":"Order Types","process-types":"Process Types","incident-statuses":"Incident Statuses","idea-statuses":"Idea Statuses","order-statuses":"Order Statuses","process-statuses":"Process Statuses",users:"Users"},new:"+ New",save:"Save",cancel:"Cancel",edit:"Edit",delete:"Delete",deletedBadge:"DELETED",restore:"Restore",restoring:"Restoring...",restoredOk:"Record restored successfully!",deletedBanner:"⚠️ This record has been deleted",deletedBy:"Deleted by",deletedOn:"Deleted on",deletedReason:"Reason",deleteModal:{title:"Confirm Deletion",subtitle:"Are you sure you want to delete this record?",softDeleteTitle:"Delete",softDeleteDesc:"Moves the record to deleted state. It can be restored later by an Administrator.",permanentDeleteTitle:"Permanent Delete",permanentDeleteDesc:"Permanently removes this record from the database. This action cannot be undone.",reasonLabel:"Reason for deletion (optional):",reasonPlaceholder:"Enter deletion reason…",softDeleteBtn:"Delete",permanentDeleteBtn:"Permanent Delete",cancelBtn:"Cancel",deleting:"Deleting…"},view:"View",back:"← Back",clear:"Clear",search:"Search",loading:"Loading...",saving:"Saving...",savedOk:"Saved successfully!",home:"Home",noRecords:"No records found",login:{subtitle:"Sign in to continue",username:"USERNAME",password:"PASSWORD",usernamePlaceholder:"Enter username",passwordPlaceholder:"Enter password",signIn:"Sign In",signingIn:"Signing in...",invalidCreds:"Invalid username or password",emptyFields:"Please enter username and password",connError:"Connection error: "},myProfile:"My Profile",signOut:"Sign Out",switchLang:"العربية (RTL)",filter:{numberTitle:"Number / Title",searchPlaceholder:"Search...",organization:"Organization",department:"Department",branch:"Branch",status:"Status",allOrgs:"All Organizations",allDepts:"All Departments",allBranches:"All Branches",allStatuses:"All Statuses",allTypes:"All Types"},col:{number:"Number",title:"Title",organization:"Organization",type:"Type",status:"Status",actions:"Actions",name:"Name",department:"Department",branch:"Branch",city:"City",email:"Email",management:"Management",organization_type:"Type",frequency:"Frequency",period:"Period",startDate:"Start Date",endDate:"End Date",auditor:"Auditor",manager:"Manager",functions:"Functions",requestedOn:"Requested On"},field:{number:"Number",title:"Title",organization:"Organization",management:"Management",department:"Department",section:"Section",branch:"Branch",type:"Type",date:"Date",time:"Time",status:"Status",description:"Description",assignedTo:"Assigned To",hsesField:"HSES Field",priority:"Priority",economyClass:"Economy Class",entityScope:"Entity Scope",productRelation:"Product Relation",repeatedEvent:"Repeated Event",solution:"Solution / Action Plan",actualCost:"Actual Cost",summary:"Resolution Summary",auditorComment:"Auditor Comment",incidentClass:"Incident Class",incidentField:"Incident Field",currentCondition:"Current Condition",proposedCondition:"Proposed Condition",ideaClass:"Idea Class",startingDate:"Starting Date",endingDate:"Ending Date",budget:"Budget",currency:"Currency",notes:"Notes",cycle:"Cycle",stage:"Stage",completionPct:"Completion %",actor:"Actor",escalationLevel:"Escalation Level",dateStart:"Start Date",dateEnd:"End Date",cycleType:"Cycle Type",progressIndicators:"Progress Indicators",impactLevel:"Impact Level",kpiName:"KPI Name",kpiType:"KPI Type",kpiMeasure:"KPI Measure",costPerCycle:"Cost per Cycle",chainLocation:"Chain Location",notifyManager:"Notify Manager",creationDate:"Creation Date",statusActive:"Active",statusInactive:"Inactive",name1:"Name",fullName:"Full Name",username:"Username",emailAddress:"Email Address",phoneNumber:"Phone Number",category:"Category",since:"Since",active:"Active",inactive:"Inactive",enabled:"Enabled",selectMgr:"-- Select manager --",select:"-- Select --",eventCategory:"Event Category",selectType:"-- Select type --",selectClass:"-- Select class --",selectField:"-- Select field --",selectStatus:"-- Select status --",solutionPlaceholder:"Describe the solution or action taken…",commentPlaceholder:"Optional comment…",high:"High",normal:"Normal",expenses:"Expenses",capital:"Capital",earn:"Earn",payLoss:"Pay/Loss",upstream:"Upstream",onstream:"On-stream",downstream:"Downstream",government:"Government",private:"Private",linkedOrder:"Linked Order",linkedIdea:"Linked Idea",convertedToOrder:"Converted to Order",originatingIdea:"Originating Idea",viewOrder:"View Order",viewIdea:"View Idea",monthly:"Monthly",quarterly:"Quarterly",yearly:"Yearly",cycleActive:"Active",cycleCompleted:"Completed",cyclePaused:"Paused",updateWindowDays:"Update Window (days)",incidentTriageWindowDays:"Triage Window (days)",incidentResolutionWindowDays:"Resolution Window (days)",orgAcronym:"Acronym",contactEmail:"Contact Email",orgCity:"City",orgName:"Organization Name",organizationType:"Organization Type",revenue_growth:"Revenue Growth (%)",net_profit:"Net Profit",cash_flow:"Cash Flow",strategic_goal_pct:"Strategic Goal (%)",customer_satisfaction:"Customer Satisfaction",employee_turnover_pct:"Employee Turnover (%)",open_safety_incidents:"Open Safety Incidents",compliance_score:"Compliance Score"},wf:{workflow:"Workflow",noActions:"No actions available for your role in this state.",applying:"Applying…",submit:"Submit",assignToManager:"Assign to Manager",reject:"Reject",submitSolution:"Submit Solution",resolutionComplete:"Resolution complete",moveToOutsourcing:"Move to Outsourcing",closeIdea:"Close Idea"},steps:{auditorTriage:"Auditor Triage (Step 2)",managerSolution:"Manager Solution (Step 3)",ownerComment:"Owner / Auditor Comment (Step 4)",auditorEval:"Auditor Evaluation (Step 2)",managerReview:"Manager Review (Step 3)"},formTitle:{newIncident:"New Incident",editIncident:"Edit Incident",viewIncident:"Incident: ",newIdea:"New Idea",editIdea:"Edit Idea",viewIdea:"Idea: ",newOrder:"New Order",editOrder:"Edit Order",viewOrder:"Order: ",newProcess:"New Process",editProcess:"Edit Process",viewProcess:"Process: ",newOrg:"New Organization",editOrg:"Edit Organization",newMgmt:"New Management",editMgmt:"Edit Management",newDept:"New Department",editDept:"Edit Department",newBranch:"New Branch",editBranch:"Edit Branch",newUser:"New User",editUser:"Edit User",viewUser:"User Profile",newCycle:"New Cycle",editCycle:"Edit Cycle",newKpi:"New KPI Input",editKpi:"Edit KPI Input",newDelegation:"New Delegation",viewDelegation:"Delegation: "},saveIncident:"Save Incident",saveIdea:"Save Idea",saveOrder:"Save Order",saveProcess:"Save Process",saveOrg:"Save Organization",saveMgmt:"Save Management",saveDept:"Save Department",saveBranch:"Save Branch",saveUser:"Save User",saveCycle:"Save Cycle",saveKpi:"Save KPI Input",saveDelegation:"Send Delegation",saveName:"Save",dash:{allOrgs:"All organizations",incidents:"Incidents",ideas:"Ideas",orders:"Orders",processes:"Processes",level2:"Level 2 — Critical Escalation",level1:"Level 1 — Auditor Review Needed",overduePrefix:"Overdue for Triage — ",overdueSuffix:" incident(s) past 3-day window",untriaged:"Untriaged Incidents",recentKpi:"Recent KPI Inputs",manageKpi:"Manage KPI Inputs",escalatedProcesses:"Escalated Processes",escalatedOrders:"Escalated Orders",level:"Level",revenueGrowth:"Revenue Growth",netProfit:"Net Profit",strategicGoal:"Strategic Goal",customerSat:"Customer Sat.",compliance:"Compliance",safetyInc:"Safety Incidents",total:"Total"},noIncidents:"No incidents found",noIdeas:"No ideas found",noOrders:"No orders found",noProcesses:"No processes found",noUsers:"No users found",noData:"No data found",users:{category:"Category",number:"Number",fullName:"Full Name",username:"Username",email:"Email Address",phone:"Phone Number",organization:"Organization",management:"Management",department:"Department",branch:"Branch",since:"Since",status:"Status",tools:"Tools",active:"Active",inactive:"Inactive",setPassword:"Set Password",newPassword:"New password",passwordUpdated:"Password updated!",passwordFailed:"Failed. Please try again.",disableConfirm:"Delete user? They will no longer appear in the list.",password:"Password"},inbox:{title:"Inbox",noMessages:"No messages"},reports:{title:"Reports",selectOrg:"Select Organization",generate:"Generate Report"},comments:{title:"Comments",placeholder:"Write a comment…",post:"Post",noComments:"No comments yet."},activity:{title:"Activity Log",created:"Created",by:"by"}},Cy={rtl:!0,nav:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",reports:"التقارير",users:"المستخدمون",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",settings:"الإعدادات"},pages:{dashboard:"لوحة التحكم",inbox:"البريد الوارد",reports:"التقارير",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",delegations:"التفويضات",organizations:"المؤسسات",managements:"الإدارات",departments:"الأقسام",branches:"الفروع",cycles:"الدورات","kpi-input":"مؤشرات الأداء","incident-types":"أنواع الحوادث","idea-types":"أنواع الأفكار","order-types":"أنواع الطلبات","process-types":"أنواع العمليات","incident-statuses":"حالات الحوادث","idea-statuses":"حالات الأفكار","order-statuses":"حالات الطلبات","process-statuses":"حالات العمليات",users:"المستخدمون"},new:"+ جديد",save:"حفظ",cancel:"إلغاء",edit:"تعديل",delete:"حذف",deletedBadge:"محذوف",restore:"استعادة",restoring:"جارٍ الاستعادة...",restoredOk:"تمت استعادة السجل بنجاح!",deletedBanner:"⚠️ هذا السجل محذوف",deletedBy:"تم الحذف بواسطة",deletedOn:"تاريخ الحذف",deletedReason:"السبب",deleteModal:{title:"تأكيد الحذف",subtitle:"هل أنت متأكد من رغبتك في حذف هذا السجل؟",softDeleteTitle:"حذف",softDeleteDesc:"يتم نقل السجل إلى سلة المحذوفات. يمكن للمسؤول استعادته لاحقاً.",permanentDeleteTitle:"حذف نهائي",permanentDeleteDesc:"حذف السجل نهائياً من قاعدة البيانات. لا يمكن التراجع عن هذا الإجراء.",reasonLabel:"سبب الحذف (اختياري):",reasonPlaceholder:"أدخل سبب الحذف…",softDeleteBtn:"حذف",permanentDeleteBtn:"حذف نهائي",cancelBtn:"إلغاء",deleting:"جارٍ الحذف…"},view:"عرض",back:"رجوع →",clear:"مسح",search:"بحث",loading:"جارٍ التحميل...",saving:"جارٍ الحفظ...",savedOk:"تم الحفظ بنجاح!",home:"الرئيسية",noRecords:"لا توجد سجلات",login:{subtitle:"تسجيل الدخول للمتابعة",username:"اسم المستخدم",password:"كلمة المرور",usernamePlaceholder:"أدخل اسم المستخدم",passwordPlaceholder:"أدخل كلمة المرور",signIn:"تسجيل الدخول",signingIn:"جارٍ تسجيل الدخول...",invalidCreds:"اسم المستخدم أو كلمة المرور غير صحيحة",emptyFields:"الرجاء إدخال اسم المستخدم وكلمة المرور",connError:"خطأ في الاتصال: "},myProfile:"ملفي الشخصي",signOut:"تسجيل الخروج",switchLang:"English (LTR)",filter:{numberTitle:"الرقم / العنوان",searchPlaceholder:"بحث...",organization:"المؤسسة",department:"القسم",branch:"الفرع",status:"الحالة",allOrgs:"جميع المؤسسات",allDepts:"جميع الأقسام",allBranches:"جميع الفروع",allStatuses:"جميع الحالات",allTypes:"جميع الأنواع"},col:{number:"الرقم",title:"العنوان",organization:"المؤسسة",type:"النوع",status:"الحالة",actions:"الإجراءات",name:"الاسم",department:"القسم",branch:"الفرع",city:"المدينة",email:"البريد الإلكتروني",management:"الإدارة",organization_type:"النوع",frequency:"التكرار",period:"الفترة",startDate:"تاريخ البدء",endDate:"تاريخ الانتهاء",auditor:"المدقق",manager:"المدير",functions:"الوظائف",requestedOn:"تاريخ الطلب"},field:{number:"الرقم",title:"العنوان",organization:"المؤسسة",management:"الإدارة",department:"القسم",section:"القطاع",branch:"الفرع",type:"النوع",date:"التاريخ",time:"الوقت",status:"الحالة",description:"الوصف",assignedTo:"مُسند إلى",hsesField:"مجال السلامة والصحة",priority:"الأولوية",economyClass:"التصنيف الاقتصادي",entityScope:"نطاق الكيان",productRelation:"علاقة المنتج",repeatedEvent:"حدث متكرر",solution:"الحل / خطة العمل",actualCost:"التكلفة الفعلية",summary:"ملخص الحل",auditorComment:"تعليق المدقق",incidentClass:"تصنيف الحادث",incidentField:"مجال الحادث",currentCondition:"الوضع الراهن",proposedCondition:"الوضع المقترح",ideaClass:"تصنيف الفكرة",startingDate:"تاريخ البدء",endingDate:"تاريخ الانتهاء",budget:"الميزانية",currency:"العملة",notes:"الملاحظات",cycle:"الدورة",stage:"المرحلة",completionPct:"نسبة الاكتمال",actor:"المنفذ",escalationLevel:"مستوى التصعيد",dateStart:"تاريخ البدء",dateEnd:"تاريخ الانتهاء",cycleType:"نوع الدورة",progressIndicators:"مؤشرات التقدم",impactLevel:"مستوى التأثير",kpiName:"اسم المؤشر",kpiType:"نوع المؤشر",kpiMeasure:"قياس المؤشر",costPerCycle:"التكلفة لكل دورة",chainLocation:"موقع السلسلة",notifyManager:"إشعار المدير",creationDate:"تاريخ الإنشاء",statusActive:"نشط",statusInactive:"غير نشط",name1:"الاسم",fullName:"الاسم الكامل",username:"اسم المستخدم",emailAddress:"البريد الإلكتروني",phoneNumber:"رقم الهاتف",category:"الفئة",since:"منذ",active:"نشط",inactive:"غير نشط",enabled:"مفعّل",selectMgr:"-- اختر المدير --",select:"-- اختر --",eventCategory:"فئة الحدث",selectType:"-- اختر النوع --",selectClass:"-- اختر التصنيف --",selectField:"-- اختر المجال --",selectStatus:"-- اختر الحالة --",solutionPlaceholder:"صف الحل أو الإجراء المتخذ…",commentPlaceholder:"تعليق اختياري…",high:"عالي",normal:"عادي",expenses:"مصروفات",capital:"رأس مال",earn:"إيرادات",payLoss:"دفع/خسارة",upstream:"مرحلة المنبع",onstream:"على الخط",downstream:"مرحلة المصب",government:"حكومي",private:"خاص",linkedOrder:"الأمر المرتبط",linkedIdea:"الفكرة المرتبطة",convertedToOrder:"تم التحويل إلى أمر",originatingIdea:"الفكرة الأصلية",viewOrder:"عرض الأمر",viewIdea:"عرض الفكرة",monthly:"شهري",quarterly:"ربع سنوي",yearly:"سنوي",cycleActive:"نشط",cycleCompleted:"مكتمل",cyclePaused:"موقوف",updateWindowDays:"نافذة التحديث (أيام)",incidentTriageWindowDays:"نافذة الفرز (أيام)",incidentResolutionWindowDays:"نافذة الحل (أيام)",orgAcronym:"الاختصار",contactEmail:"البريد الإلكتروني للتواصل",orgCity:"المدينة",orgName:"اسم المؤسسة",organizationType:"نوع المؤسسة",revenue_growth:"نمو الإيرادات (%)",net_profit:"صافي الربح",cash_flow:"التدفق النقدي",strategic_goal_pct:"الهدف الاستراتيجي (%)",customer_satisfaction:"رضا العملاء",employee_turnover_pct:"معدل دوران الموظفين (%)",open_safety_incidents:"حوادث السلامة المفتوحة",compliance_score:"درجة الامتثال"},wf:{workflow:"سير العمل",noActions:"لا توجد إجراءات متاحة لدورك في هذه الحالة.",applying:"جارٍ التطبيق...",submit:"إرسال",assignToManager:"تعيين للمدير",reject:"رفض",submitSolution:"إرسال الحل",resolutionComplete:"اكتمال الحل",moveToOutsourcing:"نقل للاستعانة بمصادر خارجية",closeIdea:"إغلاق الفكرة"},steps:{auditorTriage:"فرز المدقق (الخطوة 2)",managerSolution:"حل المدير (الخطوة 3)",ownerComment:"تعليق المالك / المدقق (الخطوة 4)",auditorEval:"تقييم المدقق (الخطوة 2)",managerReview:"مراجعة المدير (الخطوة 3)"},formTitle:{newIncident:"حادث جديد",editIncident:"تعديل الحادث",viewIncident:"الحادث: ",newIdea:"فكرة جديدة",editIdea:"تعديل الفكرة",viewIdea:"الفكرة: ",newOrder:"طلب جديد",editOrder:"تعديل الطلب",viewOrder:"الطلب: ",newProcess:"عملية جديدة",editProcess:"تعديل العملية",viewProcess:"العملية: ",newOrg:"مؤسسة جديدة",editOrg:"تعديل المؤسسة",newMgmt:"إدارة جديدة",editMgmt:"تعديل الإدارة",newDept:"قسم جديد",editDept:"تعديل القسم",newBranch:"فرع جديد",editBranch:"تعديل الفرع",newUser:"مستخدم جديد",editUser:"تعديل المستخدم",viewUser:"ملف المستخدم",newCycle:"دورة جديدة",editCycle:"تعديل الدورة",newKpi:"مؤشر أداء جديد",editKpi:"تعديل مؤشر الأداء",newDelegation:"تفويض جديد",viewDelegation:"التفويض: "},saveIncident:"حفظ الحادث",saveIdea:"حفظ الفكرة",saveOrder:"حفظ الطلب",saveProcess:"حفظ العملية",saveOrg:"حفظ المؤسسة",saveMgmt:"حفظ الإدارة",saveDept:"حفظ القسم",saveBranch:"حفظ الفرع",saveUser:"حفظ المستخدم",saveCycle:"حفظ الدورة",saveKpi:"حفظ مؤشر الأداء",saveDelegation:"إرسال التفويض",saveName:"حفظ",dash:{allOrgs:"جميع المؤسسات",incidents:"الحوادث",ideas:"الأفكار",orders:"الطلبات",processes:"العمليات",level2:"المستوى 2 — تصعيد حرج",level1:"المستوى 1 — مراجعة المدقق مطلوبة",overduePrefix:"متأخر للفرز — ",overdueSuffix:" حادث(ة) تجاوز نافذة 3 أيام",untriaged:"حوادث غير مفرزة",recentKpi:"مؤشرات الأداء الأخيرة",manageKpi:"إدارة مؤشرات الأداء",escalatedProcesses:"عمليات متصاعدة",escalatedOrders:"طلبات متصاعدة",level:"المستوى",revenueGrowth:"نمو الإيرادات",netProfit:"صافي الربح",strategicGoal:"الهدف الاستراتيجي",customerSat:"رضا العملاء",compliance:"الامتثال",safetyInc:"حوادث السلامة",total:"الإجمالي"},noIncidents:"لا توجد حوادث",noIdeas:"لا توجد أفكار",noOrders:"لا توجد طلبات",noProcesses:"لا توجد عمليات",noUsers:"لا يوجد مستخدمون",noData:"لا توجد بيانات",users:{category:"الفئة",number:"الرقم",fullName:"الاسم الكامل",username:"اسم المستخدم",email:"البريد الإلكتروني",phone:"رقم الهاتف",organization:"المؤسسة",management:"الإدارة",department:"القسم",branch:"الفرع",since:"منذ",status:"الحالة",tools:"الأدوات",active:"نشط",inactive:"غير نشط",setPassword:"تعيين كلمة المرور",newPassword:"كلمة مرور جديدة",passwordUpdated:"تم تحديث كلمة المرور!",passwordFailed:"فشل. الرجاء المحاولة مرة أخرى.",disableConfirm:"حذف المستخدم؟ لن يظهر في القائمة بعد الآن.",password:"كلمة المرور"},inbox:{title:"البريد الوارد",noMessages:"لا توجد رسائل"},reports:{title:"التقارير",selectOrg:"اختر المؤسسة",generate:"إنشاء التقرير"},comments:{title:"التعليقات",placeholder:"اكتب تعليقاً…",post:"نشر",noComments:"لا توجد تعليقات بعد."},activity:{title:"سجل النشاط",created:"أُنشئ",by:"بواسطة"}};function Ru({isOpen:e,doctype:n,docname:s,docTitle:a,isAdmin:r,isDeleting:l,onClose:i,onConfirmSoftDelete:d,onConfirmPermanentDelete:f}){const p=le(),[C,j]=_.useState("");if(_.useEffect(()=>{e&&j("")},[e]),_.useEffect(()=>{const c=v=>{v.key==="Escape"&&e&&!l&&i()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e,l,i]),!e)return null;const w=n.replace(/^SB\s+/,"");return t.jsx("div",{style:{position:"fixed",inset:0,zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:"12px",backgroundColor:"rgba(15, 23, 42, 0.6)",backdropFilter:"blur(3px)",animation:"fadeIn 0.15s ease"},onClick:c=>{c.target===c.currentTarget&&!l&&i()},children:t.jsxs("div",{className:"delete-modal-card",style:{background:"white",borderRadius:12,boxShadow:"0 20px 35px -10px rgba(0, 0, 0, 0.22)",maxWidth:390,width:"100%",padding:"16px 18px",boxSizing:"border-box",position:"relative",animation:"scaleIn 0.15s ease",border:"1px solid rgba(226, 232, 240, 0.9)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:12},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"#fee2e2",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#ef4444"},children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M3 6h18m-2 0v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6m3 0V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),t.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),t.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("h3",{style:{margin:0,fontSize:14,fontWeight:700,color:"#1e293b"},children:p.deleteModal.title}),t.jsx("p",{style:{margin:"2px 0 0",fontSize:11,color:"#64748b",lineHeight:1.3},children:p.deleteModal.subtitle})]}),t.jsx("button",{type:"button",onClick:i,disabled:l,style:{background:"transparent",border:"none",color:"#94a3b8",cursor:"pointer",padding:"2px 4px",borderRadius:4,fontSize:14,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"✕"})]}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:6,padding:"6px 10px",marginBottom:12,display:"flex",alignItems:"center",gap:6},children:[t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.4px",flexShrink:0},children:[w,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#1e293b",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a?`${a} (${s})`:s})]}),t.jsxs("div",{style:{marginBottom:14},children:[t.jsx("label",{style:{display:"block",fontSize:11,fontWeight:600,color:"#475569",marginBottom:4},children:p.deleteModal.reasonLabel}),t.jsx("input",{type:"text",value:C,onChange:c=>j(c.target.value),placeholder:p.deleteModal.reasonPlaceholder,disabled:l,style:{width:"100%",height:30,padding:"4px 8px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:12,boxSizing:"border-box",outline:"none"},onFocus:c=>{c.target.style.borderColor="#6366f1",c.target.style.boxShadow="0 0 0 2px rgba(99, 102, 241, 0.15)"},onBlur:c=>{c.target.style.borderColor="#cbd5e1",c.target.style.boxShadow="none"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"row",justifyContent:"flex-end",gap:8,flexWrap:"wrap"},children:[t.jsx("button",{type:"button",onClick:i,disabled:l,style:{padding:"5px 12px",borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#475569",fontSize:12,fontWeight:600,cursor:l?"not-allowed":"pointer",transition:"background 0.15s"},children:p.deleteModal.cancelBtn}),t.jsxs("button",{type:"button",onClick:()=>d(C),disabled:l,title:p.deleteModal.softDeleteDesc,style:{padding:"5px 12px",borderRadius:6,border:"1px solid #fca5a5",background:"#fff1f2",color:"#b91c1c",fontSize:12,fontWeight:600,cursor:l?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:4,transition:"all 0.15s"},onMouseEnter:c=>{l||(c.currentTarget.style.background="#fee2e2")},onMouseLeave:c=>{l||(c.currentTarget.style.background="#fff1f2")},children:[t.jsx("span",{children:"🗑️"}),l?p.deleteModal.deleting:p.deleteModal.softDeleteBtn]}),r&&t.jsxs("button",{type:"button",onClick:()=>f(C),disabled:l,title:p.deleteModal.permanentDeleteDesc,style:{padding:"5px 12px",borderRadius:6,border:"none",background:"#ef4444",color:"#ffffff",fontSize:12,fontWeight:600,cursor:l?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:4,boxShadow:"0 1px 3px rgba(239, 68, 68, 0.25)",transition:"all 0.15s"},onMouseEnter:c=>{l||(c.currentTarget.style.background="#dc2626")},onMouseLeave:c=>{l||(c.currentTarget.style.background="#ef4444")},children:[t.jsx("span",{children:"💥"}),l?p.deleteModal.deleting:p.deleteModal.permanentDeleteBtn]})]})]})})}const ch="/assets/logo-BlYgMyx5.png";function uh({collapsed:e,onToggleCollapsed:n,activePage:s,onNavigate:a,hasDashboard:r,hasReports:l,hasDelegations:i,role:d,hideSettings:f,rtl:p,navLabels:C,settingsLabel:j}){const w=f?[]:cy(d);return t.jsxs("div",{style:{width:e?60:230,background:"linear-gradient(180deg, #0f172a 0%, #1e1b4b 60%, #0b0f19 100%)",color:"white",flexShrink:0,display:"flex",flexDirection:"column",position:"sticky",top:0,height:"100vh",transition:"width 0.22s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden",boxShadow:"2px 0 12px rgba(0, 0, 0, 0.15)",borderRight:"1px solid rgba(255, 255, 255, 0.06)",zIndex:40},children:[t.jsxs("div",{style:{padding:e?"16px 0":"16px 16px 14px",borderBottom:"1px solid rgba(255, 255, 255, 0.08)",display:"flex",alignItems:"center",justifyContent:e?"center":"space-between",gap:8,flexShrink:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,overflow:"hidden"},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"white",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,boxShadow:"0 2px 8px rgba(0, 0, 0, 0.25)",padding:3,boxSizing:"border-box",overflow:"hidden"},children:t.jsx("img",{src:ch,alt:"Logo",style:{width:"100%",height:"100%",objectFit:"contain"},onError:c=>{c.currentTarget.style.display="none"}})}),!e&&t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:t.jsx("span",{style:{fontSize:14,fontWeight:800,whiteSpace:"nowrap",color:"#ffffff",letterSpacing:"-0.2px"},children:p?"صدرة للأعمال":"Sidrah"})})]}),t.jsx("button",{type:"button",onClick:n,title:e?p?"توسيع":"Expand":p?"طي":"Collapse",style:{background:"rgba(255, 255, 255, 0.06)",border:"1px solid rgba(255, 255, 255, 0.1)",borderRadius:6,color:"rgba(255, 255, 255, 0.75)",cursor:"pointer",fontSize:11,padding:"4px 7px",flexShrink:0,lineHeight:1,transition:"all 0.15s ease"},onMouseEnter:c=>{c.currentTarget.style.background="rgba(255, 255, 255, 0.15)",c.currentTarget.style.color="#ffffff"},onMouseLeave:c=>{c.currentTarget.style.background="rgba(255, 255, 255, 0.06)",c.currentTarget.style.color="rgba(255, 255, 255, 0.75)"},children:e?"▶":"✕"})]}),t.jsxs("nav",{style:{padding:"12px 8px",flex:1,overflowY:"auto",overflowX:"hidden"},children:[oy.filter(({id:c})=>d==="Business Owner"||d==="Owner"?c==="dashboard"&&r:(c!=="dashboard"||r)&&(c!=="reports"||l)&&(c!=="delegations"||i)).map(({id:c,icon:v})=>{const z=C[c]||c,k=c===s;return t.jsxs("div",{onClick:()=>a(c),title:e?z:void 0,className:"sidebar-nav-item",style:{padding:e?"8px 0":"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:10,background:k?"rgba(99, 102, 241, 0.28)":"transparent",border:k?"1px solid rgba(129, 140, 248, 0.35)":"1px solid transparent",borderRadius:8,fontSize:e?15:13,color:k?"#ffffff":"rgba(255, 255, 255, 0.78)",fontWeight:k?600:400,transition:"all 0.15s ease",whiteSpace:"nowrap",marginBottom:2,position:"relative"},onMouseEnter:g=>{k||(g.currentTarget.style.background="rgba(255, 255, 255, 0.08)",g.currentTarget.style.color="#ffffff")},onMouseLeave:g=>{k||(g.currentTarget.style.background="transparent",g.currentTarget.style.color="rgba(255, 255, 255, 0.78)")},children:[t.jsx("span",{style:{flexShrink:0,fontSize:e?15:13},children:v}),!e&&t.jsx("span",{children:z})]},c)}),w.length>0&&t.jsxs(t.Fragment,{children:[!e&&t.jsx("div",{style:{padding:"12px 12px 4px",fontSize:10,color:"rgba(255, 255, 255, 0.45)",fontWeight:700,letterSpacing:"0.8px",textTransform:"uppercase",marginTop:8},children:j}),e&&t.jsx("div",{style:{margin:"10px auto",width:26,borderTop:"1px solid rgba(255, 255, 255, 0.12)"}}),w.map(({id:c,icon:v})=>{const z=C[c]||c,k=c===s;return t.jsxs("div",{onClick:()=>a(c),title:e?z:void 0,className:"sidebar-nav-item",style:{padding:e?"8px 0":"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:e?"center":"flex-start",gap:10,background:k?"rgba(99, 102, 241, 0.28)":"transparent",border:k?"1px solid rgba(129, 140, 248, 0.35)":"1px solid transparent",borderRadius:8,fontSize:e?15:13,color:k?"#ffffff":"rgba(255, 255, 255, 0.78)",fontWeight:k?600:400,transition:"all 0.15s ease",whiteSpace:"nowrap",marginBottom:2},onMouseEnter:g=>{k||(g.currentTarget.style.background="rgba(255, 255, 255, 0.08)",g.currentTarget.style.color="#ffffff")},onMouseLeave:g=>{k||(g.currentTarget.style.background="transparent",g.currentTarget.style.color="rgba(255, 255, 255, 0.78)")},children:[t.jsx("span",{style:{flexShrink:0,fontSize:e?15:13},children:v}),!e&&t.jsx("span",{children:z})]},c)})]})]})]})}const Ha=new Set(["SB Incident","SB Idea","SB Order","SB Process","SB Organization","SB Cycle","SB KPI Input","Managements","Department","Branch","Incident Types","Idea Types","Order Types","Process Types","Incident Class","Incident Field","Incident Statuses","Idea Statuses","Order Statuses","Process Statuses","SB Group Company","User"]);let Fs="";async function fc(){try{const e=await fetch(`${pe}/api/method/sidrah_business.api.get_csrf_token`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(e.ok){const s=(await e.json()).message||"";if(s)return Fs=s,s}}catch(e){console.error("CSRF fetch error:",e)}return Fs}async function rn(){return Fs||await fc(),Fs}function Wr(e,n){try{if(e!=null&&e._server_messages){const a=JSON.parse(e._server_messages);if(a.length){const r=JSON.parse(a[0]);if(r!=null&&r.message)return r.message.replace(/<[^>]+>/g,"").trim()}}}catch{}let s=(e==null?void 0:e.message)||(e==null?void 0:e.exception)||(e==null?void 0:e.exc)||n;if(typeof s=="string"&&s.includes("frappe.exceptions.")){const a=s.split(` `).map(l=>l.trim()).filter(l=>l&&!l.startsWith("Traceback")&&!l.startsWith("File "));s=(a[a.length-1]||s).replace(/^frappe\.exceptions\.\w+:\s*/,"").trim()}return s||n}async function $t(e,n,s=[]){if(Ha.has(e)){const i=`${pe}/api/method/sidrah_business.api.get_sb_doc?doctype=${encodeURIComponent(e)}&name=${encodeURIComponent(n)}`,d=await fetch(i,{credentials:"include",headers:{Accept:"application/json"}});if(!d.ok)throw new Error(`API Error: ${d.status}`);return(await d.json()).message}const a=s.length?`?fields=${encodeURIComponent(JSON.stringify(s))}`:"",r=await fetch(`${pe}/api/v1/resource/${e}/${encodeURIComponent(n)}${a}`,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(!r.ok)throw new Error(`API Error: ${r.status}`);return(await r.json()).data}async function md(e,n,s="",a=!1){const r=await rn();if(Ha.has(e)){const d=new URLSearchParams({doctype:e,name:n});s&&d.append("reason",s),a&&d.append("permanent","1");const f=await fetch(`${pe}/api/method/sidrah_business.api.delete_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":r},body:d.toString()});if(!f.ok){const p=await f.json().catch(()=>({}));throw new Error(Wr(p,`Error deleting ${n}`))}return}const l=new URLSearchParams({doctype:e,name:n});s&&l.append("reason",s),a&&l.append("permanent","1");const i=await fetch(`${pe}/api/method/sidrah_business.soft_delete.soft_delete`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":r},body:l.toString()});if(!i.ok){const d=await i.json().catch(()=>({}));throw new Error(Wr(d,`Error deleting ${n}`))}return await i.json()}async function zy(e,n){const s=await rn();if(Ha.has(e)){const l=new URLSearchParams({doctype:e,name:n}),i=await fetch(`${pe}/api/method/sidrah_business.api.restore_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:l.toString()});if(!i.ok){const f=await i.json().catch(()=>({}));throw new Error(Wr(f,`Error restoring ${n}`))}return(await i.json()).message||{success:!0}}const a=new URLSearchParams({doctype:e,name:n}),r=await fetch(`${pe}/api/method/sidrah_business.soft_delete.restore_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:a.toString()});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(Wr(l,`Error restoring ${n}`))}return await r.json()}async function Be(e){if(Ha.has(e))try{const a=`${pe}/api/method/sidrah_business.api.get_sb_list?doctype=${encodeURIComponent(e)}&limit=500`,r=await fetch(a,{credentials:"include",headers:{Accept:"application/json"}});return r.ok?(await r.json()).message||[]:[]}catch{return[]}const n=encodeURIComponent('["*"]'),s=`${pe}/api/v1/resource/${e}?limit_page_length=500&fields=${n}`;try{const a=await fetch(s,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return a.status===401||a.status===403?[]:a.ok?(await a.json()).data||[]:[]}catch(a){return console.error("Get error:",a),[]}}async function si(e,n){const s=await rn();if(Ha.has(e)){const r=new URLSearchParams({doctype:e,data_json:JSON.stringify(n)}),l=await fetch(`${pe}/api/method/sidrah_business.api.create_sb_doc`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:r.toString()});if(!l.ok){const d=await l.json().catch(()=>({}));throw new Error(d.message||d.exc||`Error creating ${e}`)}return{data:(await l.json()).message}}const a=`${pe}/api/v1/resource/${e}`;try{const r=await fetch(a,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":s},body:JSON.stringify(n)});if(r.status===401||r.status===403)throw new Error("Permission denied - login required");if(!r.ok){const l=await r.json();throw new Error(l.message||l.exc||`API Error: ${r.status}`)}return await r.json()}catch(r){throw console.error("Post error:",r),r}}async function Ds(e,n,s){const a=await rn();if(Ha.has(e)){const l=new URLSearchParams({doctype:e,name:n,data_json:JSON.stringify(s)}),i=await fetch(`${pe}/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":a},body:l.toString()});if(!i.ok){const f=await i.json().catch(()=>({}));throw new Error(f.message||f.exc||`Error updating ${e}`)}return{data:(await i.json()).message}}const r=`${pe}/api/v1/resource/${e}/${encodeURIComponent(n)}`;try{const l=await fetch(r,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":a},body:JSON.stringify(s)});if(l.status===401||l.status===403)throw new Error("Permission denied - login required");if(!l.ok){const i=await l.json();throw new Error(i.message||"Update Error")}return await l.json()}catch(l){throw console.error("Update error:",l),l}}async function Iy(){const e=`${pe}/api/method/sidrah_business.api.get_users`;try{const n=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(n.status===401||n.status===403)return[];if(!n.ok)return[];const s=await n.json();return s.message||s.data||[]}catch(n){return console.error("Get users error:",n),[]}}async function Ey(e,n){const s=new FormData;s.append("usr",e),s.append("pwd",n);const r=await(await fetch(`${pe}/api/method/login`,{method:"POST",credentials:"include",body:s})).json();return r.csrf_token?Fs=r.csrf_token:await fc(),r}async function Ty(){const e=await rn();try{await fetch(`${pe}/api/method/logout`,{method:"POST",credentials:"include",headers:{"X-Frappe-CSRF-Token":e,Accept:"application/json"}})}catch{}Fs=""}function Ay(){return Fs}async function ph(){try{const e=await fetch(`${pe}/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 Py(){const e=JSON.stringify([["name","not in",["Administrator","Guest"]]]),n=`${pe}/api/v1/resource/User?limit_page_length=500&fields=${encodeURIComponent('["*"]')}&filters=${encodeURIComponent(e)}`;try{const s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).data||[]:[]}catch{return[]}}async function Ry(){const e=`${pe}/api/method/sidrah_business.api.get_user_role_map`;try{const n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||{}:{}}catch{return{}}}async function ai(e,n){const s=await rn();try{const a=new URLSearchParams({user:e,password:n});(await fetch(`${pe}/api/method/sidrah_business.api.set_user_password`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:a.toString()})).ok||await Ds("User",e,{new_password:n})}catch{await Ds("User",e,{new_password:n})}}async function Oy(e=20){try{const n=`${pe}/api/method/sidrah_business.api.get_notifications?limit=${e}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function Dy(){const e=await rn();try{await fetch(`${pe}/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 By(e){const n=await rn();try{await fetch(`${pe}/api/method/sidrah_business.api.mark_notification_read`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":n},body:new URLSearchParams({name:e}).toString()})}catch{}}async function Ly(e){const n=await rn(),s=new URLSearchParams({name:e});await fetch(`${pe}/api/method/sidrah_business.api.disable_user`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":n},body:s.toString()})}async function Wy(e,n){try{const s=`${pe}/api/method/sidrah_business.api.get_doc_comments?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(n)}`,a=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return a.ok?(await a.json()).message||[]:[]}catch{return[]}}async function Ny(e,n,s){const a=await rn(),r=new URLSearchParams({doctype:e,docname:n,content:s}),l=await fetch(`${pe}/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":a},body:r.toString()});if(!l.ok)throw new Error("Failed to post comment");return(await l.json()).message}async function $y(e,n){try{const s=`${pe}/api/method/sidrah_business.api.get_doc_versions?doctype=${encodeURIComponent(e)}&docname=${encodeURIComponent(n)}`,a=await fetch(s,{credentials:"include",headers:{Accept:"application/json"}});return a.ok?(await a.json()).message||[]:[]}catch{return[]}}async function fh(e){try{const n=`${pe}/api/method/sidrah_business.api.get_user_roles?user=${encodeURIComponent(e)}`,s=await fetch(n,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||[]:[]}catch{return[]}}async function Uy(){try{const e=`${pe}/api/method/sidrah_business.api.get_my_organization`,n=await fetch(e,{method:"GET",credentials:"include",headers:{Accept:"application/json"}});return n.ok&&(await n.json()).message||""}catch{return""}}async function Qs(e,n={}){const s=await rn(),a=new URLSearchParams(n),r=await fetch(`${pe}/api/method/sidrah_business.api.${e}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Frappe-CSRF-Token":s},body:a.toString()});if(!r.ok){const i=await r.json().catch(()=>({}));throw new Error(Wr(i,`Error calling ${e}`))}return(await r.json()).message}async function My(e,n,s="",a,r,l){const i={name:e,action:n,comment:s};return a!==void 0&&(i.stage=a),l!==void 0&&(i.cycle_status=l),Qs("apply_order_workflow",i)}async function Fy(e,n,s=""){return Qs("apply_incident_workflow",{name:e,action:n,fields_json:s})}async function Hy(e,n,s=""){return Qs("apply_idea_workflow",{name:e,action:n,fields_json:s})}async function Gy(e=""){const n=`${pe}/api/method/sidrah_business.api.get_dashboard_data${e?`?organization=${encodeURIComponent(e)}`:""}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});return s.ok?(await s.json()).message||{}:{escalated_processes:[],escalated_orders:[],untriaged_incidents:[],kpi_inputs:[]}}async function Qy(e,n={}){return Qs("get_report_data",{report_name:e,filters_json:JSON.stringify(n)})}async function Ky(){try{const e=`${pe}/api/method/sidrah_business.api.get_inbox_items`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function Xy(e,n,s="",a="",r="",l=""){return Qs("create_delegation",{manager:e,functions_json:JSON.stringify(n),organization:s,remarks:a,incident_name:r,idea_name:l})}async function Yy(e,n,s=""){return Qs("respond_to_delegation",{name:e,response:n,remarks:s})}async function qy(e,n=""){return Qs("revoke_delegation",{name:e,remarks:n})}async function Jy(){try{const e=`${pe}/api/method/sidrah_business.api.get_delegations`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function Vy(e){const n=`${pe}/api/method/sidrah_business.api.get_delegation?name=${encodeURIComponent(e)}`,s=await fetch(n,{credentials:"include",headers:{Accept:"application/json"}});if(!s.ok)throw new Error("Failed to load delegation");return(await s.json()).message}async function Zy(){try{const e=`${pe}/api/method/sidrah_business.api.get_my_delegated_functions`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function e0(){try{const e=`${pe}/api/method/sidrah_business.api.get_my_delegated_organizations`,n=await fetch(e,{credentials:"include",headers:{Accept:"application/json"}});return n.ok?(await n.json()).message||{}:{}}catch{return{}}}async function t0(){try{const e=await rn(),n=await fetch(`${pe}/api/method/sidrah_business.api.get_group_companies`,{method:"GET",credentials:"include",headers:{Accept:"application/json","X-Frappe-CSRF-Token":e}});return n.ok?(await n.json()).message||[]:[]}catch{return[]}}async function n0(){const e=Ay();return e||fc()}async function cr(e){const n=await fetch(`${pe}/api/method/sidrah_business.api.get_process?name=${encodeURIComponent(e)}`,{credentials:"include",headers:{Accept:"application/json"}});if(!n.ok){const a=await n.json().catch(()=>({}));throw new Error(a.message||`Failed to load process (${n.status})`)}const s=await n.json();return s.message||s.data}async function s0(e,n,s={}){const a=await n0(),r=new URLSearchParams({name:e,action:n});s.actor_status&&r.set("actor_status",String(s.actor_status)),s.actor_comment&&r.set("actor_comment",String(s.actor_comment)),s.progress_indicators&&r.set("progress_indicators",JSON.stringify(s.progress_indicators));const l=await fetch(`${pe}/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":a},body:r.toString()});if(!l.ok){const d=await l.json().catch(()=>({})),f=d.message||(d.exception?String(d.exception).split(` `).pop():"")||d.exc_type||`Workflow action "${n}" failed (${l.status})`;throw new Error(f)}const i=await l.json();return i.message||i.data}const a0=["dashboard","incidents","incidents-form","ideas","ideas-form","orders","orders-form","processes","processes-form","processes-workflow","organizations","organizations-form","managements","managements-form","departments","departments-form","branches","branches-form","incident-types","incident-types-form","idea-types","idea-types-form","order-types","order-types-form","process-types","process-types-form","incident-statuses","incident-statuses-form","idea-statuses","idea-statuses-form","order-statuses","order-statuses-form","process-statuses","process-statuses-form","users","users-form","cycles","cycles-form","kpi-input","kpi-input-form","delegations","delegations-form","inbox","reports","profile"],Ou=new Set(a0),r0={"incidents-form":"incidents","ideas-form":"ideas","orders-form":"orders","processes-form":"processes","processes-workflow":"processes","organizations-form":"organizations","managements-form":"managements","departments-form":"departments","branches-form":"branches","incident-types-form":"incident-types","idea-types-form":"idea-types","order-types-form":"order-types","process-types-form":"process-types","incident-statuses-form":"incident-statuses","idea-statuses-form":"idea-statuses","order-statuses-form":"order-statuses","process-statuses-form":"process-statuses","users-form":"users","cycles-form":"cycles","kpi-input-form":"kpi-input","delegations-form":"delegations",profile:"dashboard"};function Du(){const e=window.location.hash.replace(/^#\/?/,"");if(e)return Ou.has(e)?e:null;const n=window.location.pathname.split("/").filter(Boolean).pop()||"";return Ou.has(n)?n:null}function l0(e){return e?r0[e]??e:null}function i0(e){return`#/${e}`}function o0({onLogin:e}){const n=le(),[s,a]=_.useState(""),[r,l]=_.useState(""),[i,d]=_.useState(""),[f,p]=_.useState(!1),[C,j]=_.useState(!1),[w,c]=_.useState(!1),v=async()=>{if(!s||!r){d(n.login.emptyFields);return}p(!0),d("");try{const k=await Ey(s,r);if(k.message==="Logged In"){const o=await ph()||s,h=await fh(o),x=h.some(y=>["CEO","Ceo","SB CEO","Chairman"].includes(y))?"CEO":h.some(y=>["Business Owner","SB Business Owner","SB Owner","Owner"].includes(y))?"Business Owner":h.some(y=>["SB Admin","System Manager","Administrator"].includes(y))?"Admin":h.includes("SB Auditor")?"Auditor":h.includes("SB X-Auditor")?"XAuditor":h.includes("SB Manager")?"Manager":"Employee";e({name:o,full_name:k.full_name||s,role:x})}else d(n.login.invalidCreds)}catch(k){d(n.login.connError+(k instanceof Error?k.message:"Unknown"))}p(!1)},z=k=>({width:"100%",padding:"11px 16px",border:`1.5px solid ${k?"#6366f1":"#e2e8f0"}`,borderRadius:8,fontSize:14,background:k?"#f8faff":"#ffffff",color:"#1e293b",outline:"none",transition:"all 0.18s ease",boxSizing:"border-box",boxShadow:k?"0 0 0 3px rgba(99, 102, 241, 0.15)":"none"});return t.jsx("div",{style:{minHeight:"100vh",background:"#f8fafc",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Segoe UI, system-ui, sans-serif",padding:"20px"},children:t.jsxs("div",{style:{width:380,maxWidth:"100%",display:"flex",flexDirection:"column",alignItems:"center"},children:[t.jsx("div",{style:{width:72,height:72,borderRadius:18,background:"white",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:20,boxShadow:"0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04)",border:"1px solid #f1f5f9",overflow:"hidden",padding:10},children:t.jsx("img",{src:ch,alt:"Logo",style:{width:"100%",height:"100%",objectFit:"contain"},onError:k=>{k.currentTarget.style.display="none"}})}),t.jsxs("div",{style:{textAlign:"center",marginBottom:24},children:[t.jsx("h1",{style:{fontSize:22,fontWeight:800,color:"#0f172a",letterSpacing:"-0.3px",margin:0},children:n.rtl?"صدرة للأعمال":"Sidrah"}),t.jsx("div",{style:{fontSize:13,color:"#6366f1",fontWeight:600,marginTop:4},children:n.rtl?"نظام إدارة العمليات والأعمال":"Asset Management System"}),t.jsx("div",{style:{fontSize:12,color:"#94a3b8",marginTop:6},children:n.login.subtitle})]}),t.jsxs("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:12},children:[t.jsx("div",{children:t.jsx("input",{value:s,onChange:k=>a(k.target.value),onKeyDown:k=>k.key==="Enter"&&v(),onFocus:()=>j(!0),onBlur:()=>j(!1),style:z(C),placeholder:n.login.usernamePlaceholder,autoComplete:"username"})}),t.jsx("div",{children:t.jsx("input",{type:"password",value:r,onChange:k=>l(k.target.value),onKeyDown:k=>k.key==="Enter"&&v(),onFocus:()=>c(!0),onBlur:()=>c(!1),style:z(w),placeholder:n.login.passwordPlaceholder,autoComplete:"current-password"})}),i&&t.jsx("div",{style:{padding:"9px 12px",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:8,color:"#dc2626",fontSize:12,textAlign:"center"},children:i}),t.jsx("button",{type:"button",onClick:v,disabled:f,style:{background:f?"#818cf8":"#4f46e5",color:"white",border:"none",padding:"12px",borderRadius:8,fontSize:14,cursor:f?"not-allowed":"pointer",fontWeight:600,marginTop:4,boxShadow:"0 2px 8px rgba(79, 70, 229, 0.3)",transition:"all 0.18s ease"},onMouseEnter:k=>{f||(k.currentTarget.style.background="#4338ca")},onMouseLeave:k=>{f||(k.currentTarget.style.background="#4f46e5")},children:f?n.login.signingIn:n.login.signIn}),t.jsx("div",{style:{textAlign:"center",marginTop:8},children:t.jsx("button",{type:"button",onClick:dh,style:{fontSize:12,color:"#94a3b8",background:"none",border:"none",cursor:"pointer"},onMouseEnter:k=>k.currentTarget.style.color="#475569",onMouseLeave:k=>k.currentTarget.style.color="#94a3b8",children:n.switchLang})})]})]})})}function d0(e,n){const s=parseInt(e.replace("#",""),16),a=s>>16&255,r=s>>8&255,l=s&255,i=d=>Math.round(d+(255-d)*n);return`rgb(${i(a)}, ${i(r)}, ${i(l)})`}function ar(e,n){const s=parseInt(e.replace("#",""),16),a=s>>16&255,r=s>>8&255,l=s&255;return`rgba(${a}, ${r}, ${l}, ${n})`}function ml({title:e,data:n,color:s,onSelect:a}){const[,r]=n[0]??["Total",0,""],l=n.slice(1),i=l.map((f,p)=>d0(s,Math.min(p*.16,.7))),d=l.map(([f,p,C],j)=>[f,p,C,i[j]]).filter(([,f])=>f>0);return t.jsxs("div",{className:"status-card",style:{borderRadius:18,padding:"16px 18px 18px",height:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",minWidth:0,position:"relative",overflow:"hidden"},children:[t.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",background:`linear-gradient(160deg, ${ar(s,.09)} 0%, transparent 55%)`}}),t.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:3,background:`linear-gradient(90deg, ${s}, ${ar(s,.35)})`}}),t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:14},children:[t.jsx("span",{className:"status-card-title",style:{fontSize:13,fontWeight:700,paddingTop:4},children:e}),t.jsx("span",{style:{fontSize:14,fontWeight:800,color:"white",background:s,lineHeight:1,minWidth:26,textAlign:"center",padding:"6px 9px",borderRadius:10,boxShadow:`0 4px 10px ${ar(s,.35)}`},children:r})]}),r>0&&t.jsx("div",{style:{display:"flex",height:9,borderRadius:999,overflow:"hidden",background:ar(s,.1),marginBottom:13},children:d.map(([f,p,C,j],w)=>t.jsx("div",{title:`${f}: ${p}`,onClick:c=>{c.stopPropagation(),a==null||a(C)},style:{flex:`${p} 0 0`,background:j,borderRight:wt.jsxs("div",{className:"status-card-row",onClick:p>0?w=>{w.stopPropagation(),a==null||a(C)}:void 0,style:{display:"flex",alignItems:"center",gap:9,padding:"4px 6px",borderRadius:8,cursor:p>0&&a?"pointer":"default",transition:"background 0.12s"},children:[t.jsx("span",{style:{width:9,height:9,borderRadius:"50%",background:i[j],flexShrink:0,boxShadow:`0 0 0 3px ${ar(i[j],.18)}`}}),t.jsx("span",{className:"status-card-label",style:{flex:1,fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f}),t.jsx("span",{className:"status-card-count",style:{fontSize:12,fontWeight:700,flexShrink:0},children:p})]},f))})]})}function ln({value:e,onChange:n,organizations:s,placeholder:a="Select organization...",disabled:r=!1,small:l=!1,userRole:i,onCreateNew:d,onQuickCreateSuccess:f}){var W;const[p,C]=_.useState(!1),[j,w]=_.useState(""),[c,v]=_.useState(!1),[z,k]=_.useState(""),[g,o]=_.useState(""),[h,x]=_.useState(!1),[y,S]=_.useState(""),u=_.useRef(null),b=_.useRef(null);_.useEffect(()=>{const N=I=>{u.current&&!u.current.contains(I.target)&&C(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);const A=e?((W=s.find(N=>N.organization_name===e||N.name===e))==null?void 0:W.organization_name)??e:"",H=s.filter(N=>{if(!N)return!1;const I=N;return I.custom_is_deleted===1||I.custom_is_deleted==="1"||I.custom_is_deleted===!0||I.is_deleted===1||I.is_deleted==="1"||I.is_deleted===!0||I.status==="Deleted"||I.custom_status==="Deleted"?!1:!!N.is_active||N.organization_name===e||N.name===e}).filter(N=>{if(!j.trim())return!0;const I=j.toLowerCase().trim();return(N.organization_name||"").toLowerCase().includes(I)||(N.name||"").toLowerCase().includes(I)||(N.acronym||"").toLowerCase().includes(I)}),ne=!(i==="Employee"||i==="SB Employee"),M=async N=>{if(N.preventDefault(),!!z.trim()){x(!0),S("");try{const I={organization_name:z.trim(),acronym:g.trim(),is_active:1},T=await si("SB Organization",I),G=(T==null?void 0:T.data)||T,V=(G==null?void 0:G.organization_name)||z.trim();n(V),f&&f(V),v(!1),k(""),o("")}catch(I){console.error("Quick create org error:",I),S((I==null?void 0:I.message)||"Failed to create organization. Please try again.")}finally{x(!1)}}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:u,className:`custom-select-container ${r?"disabled":""} ${p?"open":""}`,style:{position:"relative",width:"100%"},children:[t.jsxs("div",{className:`custom-select-trigger ${l?"small":""} ${r?"disabled":""} ${p?"open":""} ${!e&&!j?"is-placeholder":""}`,style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingRight:8},onClick:()=>{r||(p||(C(!0),w("")),setTimeout(()=>{var N;return(N=b.current)==null?void 0:N.focus()},0))},children:[t.jsx("input",{ref:b,type:"text",disabled:r,placeholder:a,value:p?j:A,onChange:N=>{p||C(!0),w(N.target.value)},onFocus:()=>{!r&&!p&&(C(!0),w(""))},style:{border:"none",outline:"none",background:"transparent",width:"100%",fontSize:"inherit",fontFamily:"inherit",color:"inherit",cursor:r?"not-allowed":"text",padding:0}}),e&&!r?t.jsx("span",{title:"Clear selection",style:{cursor:"pointer",color:"#94a3b8",fontSize:14,fontWeight:600,padding:"0 4px",lineHeight:1,userSelect:"none",transition:"color 0.15s ease",flexShrink:0},onClick:N=>{N.stopPropagation(),n(""),w(""),C(!1)},onMouseEnter:N=>N.currentTarget.style.color="#475569",onMouseLeave:N=>N.currentTarget.style.color="#94a3b8",children:"✕"}):t.jsx("span",{className:"trigger-arrow",style:{pointerEvents:"none",flexShrink:0},children:"▼"})]}),p&&t.jsx("div",{className:"custom-select-dropdown",children:t.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[H.length===0&&!ne&&t.jsx("div",{className:"custom-select-empty",children:"No matching organizations"}),H.map(N=>t.jsx(c0,{label:N.organization_name,selected:e===N.organization_name||e===N.name,active:!!N.is_active,isPlaceholder:!1,small:l,onClick:()=>{n(N.organization_name),w(""),C(!1)}},N.name)),ne&&t.jsxs("div",{style:{borderTop:"1px solid #e2e8f0",color:"#16a34a",fontWeight:700,fontSize:l?12:13,padding:"10px 14px",display:"flex",alignItems:"center",gap:6,cursor:"pointer",background:"#ffffff",transition:"all 0.15s ease"},onClick:()=>{C(!1),d?d():(k(""),o(""),S(""),v(!0))},onMouseEnter:N=>{N.currentTarget.style.background="#f0fdf4"},onMouseLeave:N=>{N.currentTarget.style.background="#ffffff"},children:[t.jsx("span",{style:{fontSize:16,fontWeight:800,color:"#16a34a",lineHeight:1},children:"+"}),t.jsx("span",{children:"Create New Organization"})]})]})})]}),c&&t.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(15, 23, 42, 0.55)",backdropFilter:"blur(3px)",padding:16},onClick:N=>{N.target===N.currentTarget&&!h&&v(!1)},children:t.jsxs("div",{style:{background:"#ffffff",borderRadius:12,boxShadow:"0 20px 40px rgba(0, 0, 0, 0.2)",maxWidth:440,width:"100%",overflow:"hidden",animation:"scaleIn 0.15s ease"},children:[t.jsxs("div",{style:{padding:"16px 20px",borderBottom:"1px solid #f1f5f9",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:16,fontWeight:700,color:"#1e293b"},children:[t.jsx("span",{style:{color:"#2563eb",fontSize:18,fontWeight:800},children:"+"}),t.jsx("span",{children:"Create New Organization"})]}),t.jsx("button",{type:"button",onClick:()=>!h&&v(!1),style:{background:"none",border:"none",color:"#94a3b8",fontSize:18,cursor:"pointer",padding:"2px 6px",borderRadius:4},children:"✕"})]}),t.jsxs("form",{onSubmit:M,style:{padding:"20px"},children:[y&&t.jsx("div",{style:{background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",padding:"8px 12px",borderRadius:6,fontSize:12,marginBottom:14},children:y}),t.jsxs("div",{style:{marginBottom:14},children:[t.jsxs("label",{style:{display:"block",fontSize:12,fontWeight:700,color:"#334155",marginBottom:6},children:["Organization Name ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"text",value:z,onChange:N=>k(N.target.value),placeholder:"Enter organization name",autoFocus:!0,disabled:h,style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:13,boxSizing:"border-box",outline:"none"}})]}),t.jsxs("div",{style:{marginBottom:16},children:[t.jsx("label",{style:{display:"block",fontSize:12,fontWeight:700,color:"#334155",marginBottom:6},children:"Acronym"}),t.jsx("input",{type:"text",value:g,onChange:N=>o(N.target.value),placeholder:"e.g. KAU",disabled:h,style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:13,boxSizing:"border-box",outline:"none"}})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:10,marginTop:22},children:[t.jsx("button",{type:"button",onClick:()=>v(!1),disabled:h,style:{padding:"8px 16px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#475569",fontWeight:600,fontSize:13,cursor:h?"not-allowed":"pointer"},children:"Cancel"}),t.jsxs("button",{type:"submit",disabled:h||!z.trim(),style:{padding:"8px 18px",borderRadius:8,border:"none",background:"#2563eb",color:"#ffffff",fontWeight:700,fontSize:13,cursor:h||!z.trim()?"not-allowed":"pointer",opacity:h||!z.trim()?.6:1,display:"flex",alignItems:"center",gap:6,boxShadow:"0 2px 4px rgba(37, 99, 235, 0.25)"},children:[t.jsx("span",{style:{fontSize:15,fontWeight:800},children:"+"}),t.jsx("span",{children:h?"Creating...":"Create"})]})]})]})]})})]})}function c0({label:e,selected:n,active:s,isPlaceholder:a,small:r,onClick:l}){const[i,d]=_.useState(!1);return t.jsx("div",{onClick:l,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),className:`custom-select-option ${n?"selected":""} ${i?"hovered":""} ${a?"placeholder-option":""} ${s?"":"inactive-option"} ${r?"small":""}`,children:e})}function fn({label:e,icon:n,onClick:s}){return t.jsxs("button",{onClick:s,className:"hero-quicklink-btn",style:{display:"flex",alignItems:"center",gap:8,padding:"7px 14px",background:"rgba(255, 255, 255, 0.12)",border:"1px solid rgba(255, 255, 255, 0.22)",borderRadius:10,cursor:"pointer",backdropFilter:"blur(8px)",color:"white",fontSize:13,fontWeight:700,boxShadow:"0 2px 6px rgba(0,0,0,0.12)",transition:"all 0.18s cubic-bezier(0.4, 0, 0.2, 1)"},children:[t.jsx("span",{style:{fontSize:15,display:"flex",alignItems:"center"},children:n}),t.jsx("span",{style:{whiteSpace:"nowrap"},children:e})]})}function ss({items:e,type:n,onNavigate:s}){const a=le();if(!e.length)return null;const r=n==="process"?"processes-form":"orders-form",l=n==="process"?a.dash.escalatedProcesses:a.dash.escalatedOrders,i=e.some(d=>d.escalation_level===2||d.escalation_level==="2");return t.jsxs("div",{children:[t.jsxs("h4",{style:{fontWeight:700,fontSize:12,color:i?"#ef4444":"#f59e0b",marginBottom:8,display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{children:i?"🚨":"⚠️"}),t.jsxs("span",{children:[l," (",e.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.map(d=>t.jsxs("div",{onClick:()=>s(r,d.name),className:"dashboard-alert-item",style:{padding:"10px 14px",background:i?"#fef2f2":"#fffbeb",borderRadius:10,border:`1px solid ${i?"#fecaca":"#fed7aa"}`,cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",transition:"all 0.15s ease"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[t.jsx("span",{style:{fontWeight:700,fontSize:12,color:i?"#991b1b":"#92400e",whiteSpace:"nowrap"},children:d.number||d.name}),t.jsx("span",{style:{fontSize:12,color:"#475569",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.title})]}),t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:i?"#b91c1c":"#b45309",background:i?"#fee2e2":"#fef3c7",border:`1px solid ${i?"#fca5a5":"#fde68a"}`,padding:"2px 8px",borderRadius:9999,flexShrink:0},children:[a.dash.level," ",d.escalation_level]})]},d.name))})]})}function u0({kpi:e}){const n=le();return t.jsxs("div",{className:"dashboard-kpi-card",style:{borderRadius:14,padding:"16px 18px",border:"1px solid #e2e8f0",background:"white",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",transition:"all 0.2s ease",display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("div",{style:{fontWeight:800,fontSize:14,color:"#1e293b"},children:e.organization}),t.jsx("span",{style:{fontSize:11,fontWeight:700,color:"#4f46e5",background:"#eff6ff",border:"1px solid #c7d2fe",padding:"2px 9px",borderRadius:9999},children:e.period})]}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[{label:n.dash.revenueGrowth,val:e.revenue_growth!=null?`${e.revenue_growth}%`:"—",color:"#10b981"},{label:n.dash.netProfit,val:e.net_profit!=null?e.net_profit.toLocaleString():"—",color:"#3b82f6"},{label:n.dash.strategicGoal,val:e.strategic_goal_pct!=null?`${e.strategic_goal_pct}%`:"—",color:"#8b5cf6"},{label:n.dash.customerSat,val:e.customer_satisfaction!=null?e.customer_satisfaction:"—",color:"#f59e0b"},{label:n.dash.compliance,val:e.compliance_score!=null?e.compliance_score:"—",color:"#06b6d4"},{label:n.dash.safetyInc,val:e.open_safety_incidents!=null?e.open_safety_incidents:"—",color:"#ef4444"}].map(({label:s,val:a,color:r})=>t.jsxs("div",{style:{background:"#f8fafc",padding:"8px 10px",borderRadius:8,border:"1px solid #f1f5f9"},children:[t.jsx("div",{style:{fontSize:10,color:"#64748b",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.3px"},children:s}),t.jsxs("div",{style:{fontSize:14,fontWeight:800,color:"#1e293b",marginTop:2,display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:r}}),a]})]},s))})]})}function p0({data:e}){if(!e.length)return t.jsx("p",{style:{color:"#94a3b8",fontSize:13},children:"No cycle data available for trend chart."});const n=Math.max(...e.map(s=>s.pass+s.fail+s.unknown),1);return t.jsxs("div",{children:[t.jsx("div",{style:{display:"flex",gap:14,alignItems:"flex-end",overflowX:"auto",paddingBottom:8,paddingTop:10},children:e.map(s=>{const a=s.pass+s.fail+s.unknown||1,r=100;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:6,minWidth:54},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column-reverse",gap:2,height:r,width:36,background:"#f1f5f9",borderRadius:6,padding:2,boxSizing:"border-box"},children:[t.jsx("div",{title:`Pass: ${s.pass}`,style:{height:Math.round(s.pass/n*(r-4)),background:"linear-gradient(180deg, #34d399 0%, #10b981 100%)",borderRadius:"4px 4px 0 0",minHeight:s.pass?4:0}}),t.jsx("div",{title:`Fail: ${s.fail}`,style:{height:Math.round(s.fail/n*(r-4)),background:"linear-gradient(180deg, #f87171 0%, #ef4444 100%)",borderRadius:"4px 4px 0 0",minHeight:s.fail?4:0}}),t.jsx("div",{title:`Unknown: ${s.unknown}`,style:{height:Math.round(s.unknown/n*(r-4)),background:"#94a3b8",borderRadius:"4px 4px 0 0",minHeight:s.unknown?4:0}})]}),t.jsx("div",{style:{fontSize:10,fontWeight:600,color:"#64748b",textAlign:"center",lineHeight:1.2},children:s.month.replace(/^(\d{4})-(\d{2})$/,(l,i,d)=>`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][+d-1]} '${i.slice(2)}`)}),t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#10b981",textAlign:"center"},children:a>1?Math.round(s.pass/a*100)+"%":"—"})]},s.month)})}),t.jsx("div",{style:{display:"flex",gap:20,marginTop:12,borderTop:"1px solid #f1f5f9",paddingTop:10},children:[["#10b981","Pass (Verified)"],["#ef4444","Fail (Action Required)"],["#94a3b8","Unknown / Unrecorded"]].map(([s,a])=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,fontWeight:600},children:[t.jsx("div",{style:{width:10,height:10,background:s,borderRadius:3}}),t.jsx("span",{style:{color:"#64748b"},children:a})]},a))})]})}function f0({dashData:e,fi:n,fid:s,fo:a,fp:r,incidentStatuses:l,ideaStatuses:i,orderStatuses:d,processStatuses:f,onNavigate:p,onNavigateStatus:C}){const j=le(),w=(e==null?void 0:e.escalated_processes)||[],c=(e==null?void 0:e.escalated_orders)||[],v=(e==null?void 0:e.attention_processes)||[],z=(e==null?void 0:e.attention_orders)||[],k=(e==null?void 0:e.untriaged_incidents)||[],g=(e==null?void 0:e.overdue_triage)||[],o=w.length>0||c.length>0,h=v.length>0||z.length>0,x=[["Total",n.length,""],...l.map(b=>[b.name1||b.name,n.filter(A=>A.status===b.name).length,b.name])],y=[["Total",s.length,""],...i.map(b=>[b.name1||b.name,s.filter(A=>A.status===b.name).length,b.name])],S=[["Total",a.length,""],...d.map(b=>[b.name1||b.name,a.filter(A=>A.status===b.name).length,b.name])],u=[["Total",r.length,""],...f.map(b=>[b.name1||b.name,r.filter(A=>A.status===b.name).length,b.name])];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsx("div",{onClick:()=>p("incidents"),style:{cursor:"pointer"},children:t.jsx(ml,{title:j.dash.incidents,color:"#ef4444",data:x,onSelect:b=>C("incidents",b)})}),t.jsx("div",{onClick:()=>p("ideas"),style:{cursor:"pointer"},children:t.jsx(ml,{title:j.dash.ideas,color:"#10b981",data:y,onSelect:b=>C("ideas",b)})}),t.jsx("div",{onClick:()=>p("orders"),style:{cursor:"pointer"},children:t.jsx(ml,{title:j.dash.orders,color:"#8b5cf6",data:S,onSelect:b=>C("orders",b)})}),t.jsx("div",{onClick:()=>p("processes"),style:{cursor:"pointer"},children:t.jsx(ml,{title:j.dash.processes,color:"#3b82f6",data:u,onSelect:b=>C("processes",b)})})]}),(o||h)&&t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:16},children:[o&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fee2e2",borderLeft:"5px solid #ef4444"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#ef4444",margin:0},children:j.dash.level2}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,background:"#fef2f2",color:"#ef4444",padding:"2px 8px",borderRadius:9999},children:[w.length+c.length," Critical"]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(ss,{items:w,type:"process",onNavigate:p}),t.jsx(ss,{items:c,type:"order",onNavigate:p})]})]}),h&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fef3c7",borderLeft:"5px solid #f59e0b"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#b45309",margin:0},children:j.dash.level1}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,background:"#fffbeb",color:"#b45309",padding:"2px 8px",borderRadius:9999},children:[v.length+z.length," Action Needed"]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(ss,{items:v,type:"process",onNavigate:p}),t.jsx(ss,{items:z,type:"order",onNavigate:p})]})]})]}),(g.length>0||k.length>0)&&t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:16},children:[g.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fee2e2",borderLeft:"5px solid #dc2626"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#dc2626",marginBottom:10},children:[j.dash.overduePrefix,g.length,j.dash.overdueSuffix]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:g.map(b=>t.jsxs("div",{onClick:()=>p("incidents-form",b.name),style:{padding:"8px 12px",background:"#fef2f2",borderRadius:8,border:"1px solid #fca5a5",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:12,color:"#991b1b"},children:b.number||b.name}),t.jsx("span",{style:{fontSize:12,color:"#475569"},children:b.title}),t.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:b.date})]},b.name))})]}),k.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #ffedd5",borderLeft:"5px solid #f97316"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:13,color:"#ea580c",marginBottom:10},children:[j.dash.untriaged," (",k.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:k.map(b=>t.jsxs("div",{onClick:()=>p("incidents-form",b.name),style:{padding:"8px 12px",background:"#fff7ed",borderRadius:8,border:"1px solid #fed7aa",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,fontSize:12,color:"#9a3412"},children:b.number||b.name}),t.jsx("span",{style:{fontSize:12,color:"#475569"},children:b.title}),t.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:b.date})]},b.name))})]})]})]})}function h0({dashData:e,selectedOrg:n,onNavigate:s}){const a=le(),[r,l]=_.useState([]),[i,d]=_.useState([]),[f,p]=_.useState(!1),C=(e==null?void 0:e.escalated_processes)||[],j=(e==null?void 0:e.escalated_orders)||[],w=(e==null?void 0:e.attention_processes)||[],c=(e==null?void 0:e.attention_orders)||[],v=(e==null?void 0:e.kpi_inputs)||[];_.useEffect(()=>{p(!0);const g=new URLSearchParams({months:"6"});n&&g.append("organization",n),fetch(`/api/method/sidrah_business.api.get_process_trend?${g}`,{credentials:"include",headers:{Accept:"application/json"}}).then(o=>o.json()).then(o=>{const h=o.message||[],x={};for(const y of h)x[y.month]||(x[y.month]={pass:0,fail:0,unknown:0}),y.status==="Pass"?x[y.month].pass=y.count:y.status==="Fail"?x[y.month].fail=y.count:y.status==="Unknown"&&(x[y.month].unknown=y.count);l(Object.entries(x).map(([y,S])=>({month:y,...S})))}).catch(()=>{}).finally(()=>p(!1))},[n]),_.useEffect(()=>{fetch("/api/method/sidrah_business.api.get_report_data",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json","X-Frappe-CSRF-Token":window.csrf_token||""},body:JSON.stringify({report_name:"user_activity_log",filters_json:"{}"})}).then(g=>g.json()).then(g=>{var o;d((((o=g.message)==null?void 0:o.rows)||[]).slice(0,50))}).catch(()=>{})},[n]);const z=C.length>0||j.length>0,k=w.length>0||c.length>0;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[v.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"18px 20px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #e2e8f0"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:14},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#1e293b",margin:0},children:a.dash.recentKpi}),t.jsxs("button",{onClick:()=>s("kpi-input"),style:{padding:"6px 14px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#334155",fontWeight:600,fontSize:12,cursor:"pointer"},children:[a.dash.manageKpi," →"]})]}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(280px, 1fr))",gap:14},children:v.map(g=>t.jsx(u0,{kpi:g},g.name))})]}),(z||k)&&t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:16},children:[z&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fee2e2",borderLeft:"5px solid #ef4444"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:14,color:"#ef4444",marginBottom:12},children:["Critical Escalations — Level 2 (",C.length+j.length,")"]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(ss,{items:C,type:"process",onNavigate:s}),t.jsx(ss,{items:j,type:"order",onNavigate:s})]})]}),k&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"16px 18px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #fef3c7",borderLeft:"5px solid #f59e0b"},children:[t.jsxs("h3",{style:{fontWeight:800,fontSize:14,color:"#b45309",marginBottom:12},children:["Needs Attention — Level 1 (",w.length+c.length,")"]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(ss,{items:w,type:"process",onNavigate:s}),t.jsx(ss,{items:c,type:"order",onNavigate:s})]})]})]}),t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"18px 20px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #e2e8f0"},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#1e293b",marginBottom:4},children:"Process Execution Trend — Last 6 Months"}),t.jsx("p",{style:{fontSize:12,color:"#64748b",marginBottom:12},children:"Pass / Fail verification metrics across all processes and review cycles."}),f?t.jsx("p",{style:{color:"#94a3b8",fontSize:13},children:"Loading trend analytics…"}):t.jsx(p0,{data:r})]}),i.length>0&&t.jsxs("div",{style:{background:"white",borderRadius:14,padding:"18px 20px",boxShadow:"0 2px 8px rgba(0,0,0,0.04)",border:"1px solid #e2e8f0"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:14},children:[t.jsx("h3",{style:{fontWeight:800,fontSize:14,color:"#1e293b",margin:0},children:"Audit Log Book — Recent Activity"}),t.jsx("button",{onClick:()=>s("reports"),style:{padding:"6px 14px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#334155",fontWeight:600,fontSize:12,cursor:"pointer"},children:"Full Activity Log →"})]}),t.jsx("div",{style:{overflowX:"auto",borderRadius:10,border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8fafc"},children:["Timestamp","User","Entity Type","Entity","Fields Changed"].map(g=>t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#64748b",fontWeight:700,fontSize:11,whiteSpace:"nowrap"},children:g},g))})}),t.jsx("tbody",{children:i.map((g,o)=>t.jsxs("tr",{style:{borderTop:"1px solid #f1f5f9",background:o%2===0?"white":"#fafafa"},children:[t.jsx("td",{style:{padding:"10px 14px",color:"#64748b",whiteSpace:"nowrap"},children:g.timestamp?String(g.timestamp).slice(0,16):"—"}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600,color:"#1e293b"},children:g.user||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#475569"},children:t.jsx("span",{style:{background:"#f1f5f9",padding:"2px 8px",borderRadius:6,fontWeight:600,fontSize:11},children:g.entity_type||"—"})}),t.jsx("td",{style:{padding:"10px 14px",color:"#1e293b",fontWeight:500},children:g.entity_name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#64748b",maxWidth:280,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.changes||"—"})]},o))})]})})]})]})}function g0({incidents:e,ideas:n,orders:s,processes:a,organizations:r,incidentStatuses:l,ideaStatuses:i,orderStatuses:d,processStatuses:f,selectedOrg:p,onOrgChange:C,onNavigate:j,onNavigateStatus:w,userRole:c}){const[v,z]=_.useState(null),[k,g]=_.useState(!1),o=()=>{g(!0),Gy(p).then(z).finally(()=>g(!1))};_.useEffect(()=>{o()},[p]);const h=_.useMemo(()=>p?e.filter(M=>M.organization===p):e,[e,p]),x=_.useMemo(()=>p?n.filter(M=>M.organization===p):n,[n,p]),y=_.useMemo(()=>p?s.filter(M=>M.organization===p):s,[s,p]),S=_.useMemo(()=>p?a.filter(M=>M.organization===p):a,[a,p]),E=c==="Admin"||(c==="Owner"||c==="Business Owner")||(c==="CEO"||c==="Chairman"),[H,Y]=_.useState("level1"),ne=H==="level2";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{style:{background:"linear-gradient(135deg, #1e1b4b 0%, #312e81 45%, #1e3a8a 100%)",borderRadius:16,padding:"22px 26px",color:"white",boxShadow:"0 8px 30px rgba(30, 27, 75, 0.25)",position:"relative",zIndex:20},children:[t.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:"inherit",overflow:"hidden",pointerEvents:"none"},children:[t.jsx("div",{style:{position:"absolute",top:-50,right:-50,width:220,height:220,borderRadius:"50%",background:"rgba(99, 102, 241, 0.25)",filter:"blur(50px)"}}),t.jsx("div",{style:{position:"absolute",bottom:-40,left:"35%",width:180,height:180,borderRadius:"50%",background:"rgba(59, 130, 246, 0.2)",filter:"blur(45px)"}})]}),t.jsxs("div",{style:{position:"relative",zIndex:1},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",flexWrap:"wrap",gap:16,marginBottom:20},children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:4},children:[t.jsx("span",{style:{fontSize:24},children:"⚡"}),t.jsx("h2",{style:{fontSize:22,fontWeight:800,color:"white",margin:0,letterSpacing:-.5},children:ne?"Dashboard 2: Executive Performance":"Dashboard 1: Operational Activity"})]}),t.jsx("p",{style:{fontSize:13,color:"#c7d2fe",margin:0,opacity:.9},children:p?`Real-time analytics for ${p}`:"Enterprise overview across all organizations & business units"})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("div",{style:{minWidth:190,maxWidth:260},children:t.jsx(ln,{value:p,onChange:C,organizations:r,placeholder:"All Organizations",small:!0})}),E&&t.jsxs("div",{style:{display:"flex",background:"rgba(255, 255, 255, 0.12)",borderRadius:10,padding:3,gap:3,backdropFilter:"blur(8px)",border:"1px solid rgba(255, 255, 255, 0.15)"},children:[t.jsx("button",{onClick:()=>Y("level1"),style:{padding:"5px 12px",borderRadius:7,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:H==="level1"?"white":"transparent",color:H==="level1"?"#1e1b4b":"#c7d2fe",boxShadow:H==="level1"?"0 2px 6px rgba(0,0,0,0.15)":"none",transition:"all 0.15s ease"},children:"Dashboard 1 (Ops)"}),t.jsx("button",{onClick:()=>Y("level2"),style:{padding:"5px 12px",borderRadius:7,border:"none",fontWeight:700,fontSize:11,cursor:"pointer",background:H==="level2"?"#8b5cf6":"transparent",color:"white",boxShadow:H==="level2"?"0 2px 6px rgba(0,0,0,0.2)":"none",transition:"all 0.15s ease"},children:"Dashboard 2 (Exec)"})]}),!E&&t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"white",background:"#3b82f6",padding:"5px 14px",borderRadius:9999,border:"1px solid rgba(255, 255, 255, 0.2)",boxShadow:"0 2px 6px rgba(0,0,0,0.15)"},children:"💼 Operations View"}),t.jsx("button",{onClick:o,disabled:k,title:"Refresh Metrics",style:{width:32,height:32,borderRadius:10,background:"rgba(255, 255, 255, 0.15)",border:"1px solid rgba(255, 255, 255, 0.2)",color:"white",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:14,transition:"all 0.15s"},children:t.jsx("span",{style:{display:"inline-block",transform:k?"rotate(180deg)":"none",transition:"transform 0.4s ease"},children:"🔄"})})]})]}),t.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",alignItems:"center"},children:ne?t.jsxs(t.Fragment,{children:[t.jsx(fn,{label:"Manage Users & Roles",icon:"👥",onClick:()=>j("users")}),t.jsx(fn,{label:"Active Review Cycles",icon:"🔄",onClick:()=>j("cycles")}),t.jsx(fn,{label:"Strategic KPI Inputs",icon:"📈",onClick:()=>j("kpi-input")}),t.jsx(fn,{label:"Executive Reports",icon:"📊",onClick:()=>j("reports")}),t.jsx(fn,{label:"Organizations Hierarchy",icon:"🏢",onClick:()=>j("organizations")})]}):t.jsxs(t.Fragment,{children:[t.jsx(fn,{label:"Incidents",icon:"⚠️",onClick:()=>j("incidents")}),t.jsx(fn,{label:"Ideas",icon:"💡",onClick:()=>j("ideas")}),t.jsx(fn,{label:"Orders",icon:"📦",onClick:()=>j("orders")}),t.jsx(fn,{label:"Processes",icon:"⚙️",onClick:()=>j("processes")}),t.jsx(fn,{label:"Inbox",icon:"📥",onClick:()=>j("inbox")}),t.jsx(fn,{label:"Reports",icon:"📊",onClick:()=>j("reports")})]})})]})]}),ne?t.jsx(h0,{dashData:v,selectedOrg:p,onNavigate:j}):t.jsx(f0,{dashData:v,fi:h,fid:x,fo:y,fp:S,incidentStatuses:l,ideaStatuses:i,orderStatuses:d,processStatuses:f,onNavigate:j,onNavigateStatus:w})]})}const at={fontSize:11,color:"#475569",fontWeight:600,marginBottom:4,display:"block",textTransform:"uppercase",letterSpacing:.4},rt={width:"100%",padding:"6px 10px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:12,background:"white",color:"#1e293b",boxSizing:"border-box",fontFamily:"Segoe UI, Arial, sans-serif",height:32,outline:"none"};function _i({children:e}){const[n,s]=_.useState(!1);return t.jsxs("div",{style:{borderRadius:10,overflow:"hidden",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",flexShrink:0,border:"1px solid #e2e8f0",marginBottom:14},children:[t.jsxs("div",{onClick:()=>s(a=>!a),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",color:"white",padding:"10px 18px",cursor:"pointer",display:"flex",alignItems:"center",gap:10,userSelect:"none",fontWeight:600,fontSize:13},children:[t.jsx("span",{style:{fontSize:12,opacity:.9},children:n?"▲":"▼"}),t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{children:"Filters"})]}),n&&t.jsx("div",{style:{background:"#f8fafc",padding:"14px 18px",borderTop:"1px solid #e2e8f0"},children:e})]})}const oe=20;function m0(e,n){if(n<=7)return Array.from({length:n},(a,r)=>r+1);const s=[];if(e<=4){for(let a=1;a<=Math.min(4,n);a++)s.push(a);n>4&&(s.push("ellipsis"),s.push(n))}else if(e>=n-3){s.push(1),s.push("ellipsis");for(let a=n-3;a<=n;a++)s.push(a)}else s.push(1),s.push("ellipsis"),s.push(e-1),s.push(e),s.push(e+1),s.push("ellipsis"),s.push(n);return s}function Me({page:e,pageSize:n=oe,total:s,onPageChange:a,itemLabel:r="results"}){const[l,i]=_.useState("");if(s===0)return null;const d=Math.max(1,Math.ceil(s/n)),f=s===0?0:(e-1)*n+1,p=Math.min(e*n,s),C=w=>{w&&w.preventDefault();const c=parseInt(l.trim(),10);!isNaN(c)&&c>=1&&c<=d&&(a(c),i(""))},j=m0(e,d);return t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"14px 8px",fontSize:13,color:"#475569",flexWrap:"wrap",gap:12,userSelect:"none"},children:[t.jsxs("div",{style:{color:"#475569",fontWeight:500},children:["Showing ",f," to ",p," of ",s," ",r]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>a(e-1),style:{padding:"5px 12px",borderRadius:6,border:"1px solid #e2e8f0",background:"#ffffff",color:e<=1?"#94a3b8":"#475569",fontSize:13,fontWeight:500,cursor:e<=1?"not-allowed":"pointer",transition:"all 0.15s ease",fontFamily:"inherit"},children:"Previous"}),j.map((w,c)=>{if(w==="ellipsis")return t.jsx("span",{style:{padding:"0 4px",color:"#94a3b8",fontSize:13,fontWeight:600},children:"..."},`ellipsis-${c}`);const v=w===e;return t.jsx("button",{type:"button",onClick:()=>a(w),style:{minWidth:32,height:32,padding:"0 6px",borderRadius:6,border:v?"1px solid #2563eb":"1px solid #e2e8f0",background:v?"#2563eb":"#ffffff",color:v?"#ffffff":"#334155",fontSize:13,fontWeight:v?600:500,cursor:v?"default":"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",transition:"all 0.15s ease",fontFamily:"inherit"},children:w},w)}),t.jsx("button",{type:"button",disabled:e>=d,onClick:()=>a(e+1),style:{padding:"5px 12px",borderRadius:6,border:"1px solid #e2e8f0",background:"#ffffff",color:e>=d?"#94a3b8":"#475569",fontSize:13,fontWeight:500,cursor:e>=d?"not-allowed":"pointer",transition:"all 0.15s ease",fontFamily:"inherit"},children:"Next"}),t.jsxs("form",{onSubmit:C,style:{display:"inline-flex",alignItems:"center",gap:6,marginLeft:8},children:[t.jsx("span",{style:{fontSize:13,color:"#64748b"},children:"Go to page:"}),t.jsx("input",{type:"number",min:1,max:d,value:l,onChange:w=>i(w.target.value),style:{width:52,height:30,padding:"0 6px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:13,textAlign:"center",outline:"none",fontFamily:"inherit"}}),t.jsx("button",{type:"submit",style:{background:"none",border:"none",color:"#2563eb",fontWeight:600,fontSize:13,cursor:"pointer",padding:"4px 6px",fontFamily:"inherit"},children:"Go"})]})]})]})}function x0({incidents:e,organizations:n,departments:s,branches:a,incidentStatuses:r,initialOrg:l,initialStatus:i,canModify:d,userRole:f,onView:p,onEdit:C,onDelete:j,onSelectionChange:w}){const c=le(),[v,z]=_.useState(new Set),[k,g]=_.useState({search:"",organization:l||"",department:"",branch:"",status:i||""}),o=(u,b)=>g(A=>({...A,[u]:b})),[h,x]=_.useState(1),y=e.filter(u=>!(k.search&&!`${u.number} ${u.title}`.toLowerCase().includes(k.search.toLowerCase())||k.organization&&u.organization!==k.organization||k.department&&u.department!==k.department||k.branch&&u.branch!==k.branch||k.status&&u.status!==k.status));_.useEffect(()=>{x(1)},[k]);const S=y.slice((h-1)*oe,h*oe);return _.useEffect(()=>{if(w){const u=e.filter(b=>v.has(b.name));w(u,S)}},[v,S,e]),t.jsxs(t.Fragment,{children:[t.jsx(_i,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.numberTitle}),t.jsx("input",{style:rt,value:k.search,onChange:u=>o("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.organization}),t.jsxs("select",{style:rt,value:k.organization,onChange:u=>o("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.department}),t.jsxs("select",{style:rt,value:k.department,onChange:u=>o("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.branch}),t.jsxs("select",{style:rt,value:k.branch,onChange:u=>o("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),a.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.status}),t.jsxs("select",{style:rt,value:k.status,onChange:u=>o("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),r.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:S.length>0&&S.every(u=>v.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...v,...S.map(b=>b.name)]));else{const b=new Set(v);S.forEach(A=>b.delete(A.name)),z(b)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.type}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noIncidents})}):S.map((u,b)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(u),style:{borderTop:"1px solid #f1f5f9",background:v.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":b%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:A=>A.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:v.has(u.name),onChange:()=>{const A=new Set(v);A.has(u.name)?A.delete(u.name):A.add(u.name),z(A)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:u.title||u.name||"—"}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.type?pc(u.type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?hs(c.deletedBadge):u.status?hs(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:A=>A.stopPropagation(),children:t.jsx(dt,{onView:()=>p==null?void 0:p(u),onEdit:d&&C&&!u.custom_is_deleted&&!ns("incident",u.workflow_state)&&!(f==="Employee"&&u.workflow_state&&u.workflow_state!=="New")?()=>C(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Me,{page:h,total:y.length,onPageChange:x})]})}function y0(e){if(!e)return"";const[n,s,a]=e.split("-");return!n||!s||!a?"":`${a}/${s}/${n}`}function je({value:e,onChange:n,disabled:s,style:a,min:r,max:l}){return t.jsxs("div",{style:{position:"relative",width:"100%"},children:[t.jsx("input",{type:"text",readOnly:!0,tabIndex:-1,value:y0(e),placeholder:"DD/MM/YYYY",style:{...a,pointerEvents:"none",paddingRight:30}}),t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:s?"#bbb":"#666",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",pointerEvents:"none"},children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),t.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),t.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),t.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),t.jsx("input",{type:"date",value:e||"",disabled:s,min:r,max:l,onChange:i=>n(i.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0,cursor:s?"default":"pointer",border:"none",padding:0,margin:0}})]})}const Bu={"SB Process":"processes-form","SB Order":"orders-form","SB Incident":"incidents-form","SB Idea":"ideas-form","SB Delegation":"delegations"};function v0(e){const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}function hh({notifCount:e,darkMode:n,onCountChange:s,onToggleDark:a,onViewProfile:r,onLogout:l,onNavigate:i,userName:d,userRole:f}){const[p,C]=_.useState(!1),[j,w]=_.useState([]),[c,v]=_.useState(!1),z=_.useRef(null);_.useEffect(()=>{const E=H=>{z.current&&!z.current.contains(H.target)&&C(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[]);const k=async()=>{v(!0);const E=await Oy(30);w(E),v(!1)},g=()=>{const E=!p;C(E),E&&k()},o=async()=>{await Dy(),w(E=>E.map(H=>({...H,read:1}))),s(0)},h=E=>{E.read||(By(E.name),w(Y=>Y.map(ne=>ne.name===E.name?{...ne,read:1}:ne)),s(Math.max(0,e-1)));const H=E.document_type?Bu[E.document_type]:void 0;H&&i&&(i(H,E.document_type==="SB Delegation"?void 0:E.document_name),C(!1))},x=j.filter(E=>!E.read).length,y=E=>({position:"relative",width:34,height:34,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:n?"#2d3748":"#f3f4f6",color:n?"#e2e8f0":"#6b7280",fontSize:14,transition:"background 0.15s",flexShrink:0,...E}),S=n,u=S?"#1a202c":"white",b=S?"#2d3748":"#e5e7eb",A=S?"#e2e8f0":"#1a2332";return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[d&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",marginRight:4,lineHeight:1.25},children:[t.jsx("span",{style:{fontSize:13,fontWeight:600,color:S?"#e2e8f0":"#1e293b",whiteSpace:"nowrap"},children:d}),f&&t.jsx("span",{style:{fontSize:11,color:S?"#94a3b8":"#6b7280",whiteSpace:"nowrap"},children:f})]}),t.jsx("button",{style:y({background:"#4f46e5",color:"white"}),onClick:r,title:"My Profile",children:t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7",fill:"currentColor"})]})}),t.jsxs("div",{ref:z,style:{position:"relative"},children:[t.jsxs("button",{style:y(),onClick:g,title:"Notifications",children:[t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),t.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),e>0&&t.jsx("span",{style:{position:"absolute",top:2,right:2,background:"#ef4444",color:"white",fontSize:9,fontWeight:700,borderRadius:999,minWidth:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 3px",lineHeight:1},children:e>9?"9+":e})]}),p&&t.jsxs("div",{style:{position:"absolute",right:0,top:"calc(100% + 8px)",width:340,background:u,borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.2)",zIndex:1e4,border:`1px solid ${b}`,overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${b}`,display:"flex",alignItems:"center",justifyContent:"space-between",background:u},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:A},children:["Notifications",x>0&&t.jsxs("span",{style:{background:"#ef4444",color:"white",fontSize:10,fontWeight:700,borderRadius:999,padding:"2px 7px"},children:[x," new"]})]}),x>0&&t.jsx("button",{onClick:o,style:{fontSize:12,color:"#3498db",background:"none",border:"none",cursor:"pointer",fontFamily:"inherit"},children:"Mark all read"})]}),t.jsxs("div",{style:{maxHeight:380,overflowY:"auto"},children:[c&&t.jsx("div",{style:{padding:20,textAlign:"center",color:"#aaa",fontSize:13},children:"Loading…"}),!c&&j.length===0&&t.jsxs("div",{style:{padding:"36px 20px",textAlign:"center",color:"#aaa"},children:[t.jsx("div",{style:{fontSize:28,marginBottom:8},children:"🔔"}),t.jsx("div",{style:{fontSize:13},children:"No notifications"})]}),!c&&j.map(E=>{const H=!!(E.document_type&&Bu[E.document_type]&&i);return t.jsxs("div",{onClick:()=>h(E),style:{padding:"11px 16px",borderBottom:`1px solid ${S?"#2d3748":"#f5f5f5"}`,display:"flex",gap:10,background:E.read?u:S?"#1e3a5f":"#eff6ff",cursor:H?"pointer":"default",transition:"background 0.12s"},onMouseEnter:Y=>{H&&(Y.currentTarget.style.background=S?"#243244":"#e0ecfd")},onMouseLeave:Y=>{Y.currentTarget.style.background=E.read?u:S?"#1e3a5f":"#eff6ff"},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13,fontWeight:E.read?400:600,color:A,marginBottom:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:E.subject||`${E.document_type}: ${E.document_name}`}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:E.document_type&&t.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#3b82f6",background:S?"rgba(59,130,246,0.15)":"#eff6ff",padding:"1px 7px",borderRadius:8},children:[E.document_type.replace("SB ",""),E.document_name?` · ${E.document_name}`:""]})}),t.jsx("div",{style:{fontSize:11,color:"#aaa",marginTop:3},children:v0(E.creation)})]}),!E.read&&t.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:"#3498db",flexShrink:0,marginTop:5}})]},E.name)})]})]})]}),t.jsx("button",{style:y(),onClick:dh,title:ka()?"Switch to English":"Switch to Arabic",children:t.jsx("span",{style:{fontSize:13,fontWeight:700,fontFamily:"serif"},children:"عA"})}),t.jsx("button",{style:y(),onClick:a,title:n?"Light mode":"Dark mode",children:n?t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"5"}),t.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),t.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),t.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),t.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),t.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),t.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),t.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),t.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),t.jsx("button",{style:y({background:S?"#3d1515":"#fee2e2",color:"#ef4444"}),onClick:l,title:"Logout",children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),t.jsx("polyline",{points:"16,17 21,12 16,7"}),t.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]})})]})}function tt({title:e,activePage:n,user:s,formStatus:a,buttonText:r,viewMode:l,statusBadge:i,onEdit:d,onCancel:f,hideSettings:p,rightPanel:C,darkMode:j,notifCount:w,onToggleDark:c,onCountChange:v,onViewProfile:z,onSubmit:k,onBack:g,onNavigate:o,onLogout:h,children:x}){const y=le(),S=s.role,u=S==="Admin"||S==="Owner"||S==="Auditor"||S==="Manager"||S==="CEO"||S==="Chairman"||S==="XAuditor",b=S==="Admin"||S==="Owner"||S==="Auditor"||S==="Manager"||S==="CEO"||S==="Chairman"||S==="XAuditor",A=S==="Admin"||S==="Auditor"||S==="Manager"||S==="CEO"||S==="Chairman",[E,H]=_.useState(()=>localStorage.getItem("sb_sidebar")==="1"),Y=_.useRef(void 0),[ne,M]=_.useState(!1);_.useEffect(()=>{if(Y.current===!0&&l===!1){M(!0);const I=setTimeout(()=>{M(!1)},4e3);return()=>clearTimeout(I)}else M(!1);Y.current=l},[l]);const W=()=>H(I=>{const T=!I;return localStorage.setItem("sb_sidebar",T?"1":"0"),T}),N=f||g;return t.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:j?"#0f172a":"#f8fafc"},children:[t.jsx(uh,{collapsed:E,onToggleCollapsed:W,activePage:n,onNavigate:o,hasDashboard:u,hasReports:b,hasDelegations:A,role:S,hideSettings:p,rtl:y.rtl,navLabels:y.nav,settingsLabel:y.nav.settings}),t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[t.jsx("div",{style:{background:j?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${j?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:j?"none":"0 1px 4px rgba(0,0,0,0.03)"},children:t.jsx(hh,{notifCount:w,darkMode:j,onCountChange:v,onToggleDark:c,onNavigate:o,onViewProfile:z,onLogout:h,userName:s.full_name||s.name,userRole:s.role})}),t.jsxs("div",{style:{background:j?"#1e293b":"#ffffff",padding:"12px 24px",borderBottom:`1px solid ${j?"#2d3748":"#e2e8f0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,position:"relative"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[t.jsx("button",{onClick:g,title:y.back,style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:`1px solid ${j?"#475569":"#e2e8f0"}`,background:j?"#334155":"#ffffff",cursor:"pointer",color:"#2563eb",flexShrink:0,transition:"all 0.15s ease"},onMouseEnter:I=>{I.currentTarget.style.background=j?"#475569":"#eff6ff",I.currentTarget.style.borderColor="#93c5fd"},onMouseLeave:I=>{I.currentTarget.style.background=j?"#334155":"#ffffff",I.currentTarget.style.borderColor=j?"#475569":"#e2e8f0"},children:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("div",{style:{fontSize:17,fontWeight:700,color:j?"#f8fafc":"#0f172a"},children:e}),i&&(typeof i=="string"?t.jsx("span",{style:{padding:"3px 10px",borderRadius:16,fontSize:12,fontWeight:600,background:"#fef3c7",color:"#92400e",border:"1px solid #fde68a"},children:i}):i)]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[l&&d&&t.jsxs("button",{type:"button",onClick:d,style:{display:"flex",alignItems:"center",gap:6,padding:"7px 16px",borderRadius:6,border:"none",background:"#2563eb",color:"#ffffff",cursor:"pointer",fontSize:13,fontWeight:600,boxShadow:"0 1px 3px rgba(37,99,235,0.25)",transition:"all 0.15s ease"},onMouseEnter:I=>I.currentTarget.style.background="#1d4ed8",onMouseLeave:I=>I.currentTarget.style.background="#2563eb",children:[t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),y.edit]}),!l&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("button",{type:"button",onClick:N,style:{padding:"7px 16px",borderRadius:6,border:`1px solid ${j?"#475569":"#cbd5e1"}`,background:j?"#334155":"#ffffff",color:j?"#e2e8f0":"#475569",fontSize:13,fontWeight:600,cursor:"pointer",transition:"all 0.15s ease"},onMouseEnter:I=>{I.currentTarget.style.background=j?"#475569":"#f1f5f9"},onMouseLeave:I=>{I.currentTarget.style.background=j?"#334155":"#ffffff"},children:y.cancel}),t.jsxs("button",{type:"button",onClick:k,disabled:a==="loading",style:{display:"flex",alignItems:"center",gap:6,padding:"7px 18px",borderRadius:6,border:"none",background:"#16a34a",color:"#ffffff",fontSize:13,fontWeight:600,cursor:a==="loading"?"not-allowed":"pointer",boxShadow:"0 1px 3px rgba(22, 163, 74, 0.3)",opacity:a==="loading"?.7:1,transition:"all 0.15s ease"},onMouseEnter:I=>{a!=="loading"&&(I.currentTarget.style.background="#15803d")},onMouseLeave:I=>{a!=="loading"&&(I.currentTarget.style.background="#16a34a")},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),t.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),t.jsx("polyline",{points:"7 3 7 8 15 8"})]}),t.jsx("span",{children:a==="loading"?y.saving:r||"Save Changes"})]})]})]}),!l&&ne&&t.jsxs("div",{style:{position:"absolute",top:-34,right:24,background:"#0284c7",color:"#ffffff",padding:"4px 12px",borderRadius:6,fontSize:12,fontWeight:600,display:"flex",alignItems:"center",gap:8,boxShadow:"0 2px 8px rgba(2, 132, 199, 0.3)",zIndex:10},children:[t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5},children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),"Edit mode enabled"]}),t.jsx("button",{type:"button",onClick:()=>M(!1),title:"Dismiss",style:{background:"transparent",border:"none",color:"white",cursor:"pointer",fontSize:14,padding:0,lineHeight:1,opacity:.85},children:"✕"})]})]}),t.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px",display:"grid",gridTemplateColumns:C?"1fr 240px":"1fr",gap:16,alignItems:"start"},children:[t.jsxs("div",{style:{minWidth:0},children:[x,a==="success"&&t.jsx("div",{style:{padding:"10px 14px",borderRadius:8,background:"#f0fdf4",border:"1px solid #86efac",color:"#166534",fontSize:13,marginTop:14},children:y.savedOk}),a!=="idle"&&a!=="loading"&&a!=="success"&&t.jsx("div",{style:{padding:"10px 14px",borderRadius:8,background:"#fef2f2",border:"1px solid #fca5a5",color:"#991b1b",fontSize:13,marginTop:14},children:a})]}),C&&t.jsx("div",{style:{position:"sticky",top:0,alignSelf:"start",width:240},children:C})]})]})]})}function yo(e){return e?e==="Department"?{key:"department_name",label:"Department Name"}:e==="Branch"?{key:"branch",label:"Branch Name"}:e==="SB Organization"||e==="Organization"?{key:"organization_name",label:"Organization Name"}:e==="SB Group Company"||e==="Group Company"?{key:"company_name",label:"Company Name"}:{key:"name1",label:`${e.replace(/^SB\s+/,"")} Name`}:{key:"name1",label:"Name"}}function xe({value:e,onChange:n,items:s,placeholder:a="Select...",disabled:r=!1,onCreateNew:l,createNewText:i,doctypeName:d,userRole:f,onQuickCreateSuccess:p,extraFields:C={}}){var G,V;const[j,w]=_.useState(!1),[c,v]=_.useState(""),[z,k]=_.useState(""),[g,o]=_.useState(!1),[h,x]=_.useState(""),[y,S]=_.useState(!1),[u,b]=_.useState(""),A=_.useRef(null),E=_.useRef(null);_.useEffect(()=>{const D=O=>{A.current&&!A.current.contains(O.target)&&w(!1)};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]);const H=(s||[]).filter(D=>{if(!D)return!1;const O=D;return!(O.custom_is_deleted===1||O.custom_is_deleted==="1"||O.custom_is_deleted===!0||O.is_deleted===1||O.is_deleted==="1"||O.is_deleted===!0||O.status==="Deleted"||O.custom_status==="Deleted"||O.enabled===0||O.enabled===!1||O.docstatus===2)}),Y=e?((G=H.find(D=>D.name===e))==null?void 0:G.label)??((V=(s||[]).find(D=>D.name===e))==null?void 0:V.label)??e:"",ne=H.filter(D=>{if(!c.trim())return!0;const O=c.toLowerCase().trim();return(D.label||"").toLowerCase().includes(O)||(D.name||"").toLowerCase().includes(O)}),W=!(f==="Employee"||f==="SB Employee")&&(!!l||!!d||!!i),N=d?`Create New ${d.replace(/^SB\s+/,"")}`:"Create New",I=i||N,T=async D=>{if(D.preventDefault(),!(!h.trim()||!d)){S(!0),b("");try{const O=yo(d),q={[O.key]:h.trim(),...C};["Incident Types","Idea Types","Order Types","Process Types"].includes(d)&&(q.status="Active");const se=await si(d,q),ie=(se==null?void 0:se.data)||se,ke=(ie==null?void 0:ie.name)||(ie==null?void 0:ie[O.key])||h.trim();n(ke),p&&p(ke),o(!1),x("")}catch(O){console.error("Quick create error:",O),b((O==null?void 0:O.message)||"Failed to create item. Please try again.")}finally{S(!1)}}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:A,className:`custom-select-container ${r?"disabled":""} ${j?"open":""}`,style:{position:"relative",width:"100%"},children:[t.jsxs("div",{className:`custom-select-trigger ${r?"disabled":""} ${j?"open":""} ${!e&&!c?"is-placeholder":""}`,style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingRight:8},onClick:()=>{r||(j||(w(!0),v("")),setTimeout(()=>{var D;return(D=E.current)==null?void 0:D.focus()},0))},children:[t.jsx("input",{ref:E,type:"text",disabled:r,placeholder:a,value:j?c:Y,onChange:D=>{j||w(!0),v(D.target.value)},onFocus:()=>{!r&&!j&&(w(!0),v(""))},style:{border:"none",outline:"none",background:"transparent",width:"100%",fontSize:"inherit",fontFamily:"inherit",color:"inherit",cursor:r?"not-allowed":"text",padding:0}}),e&&!r?t.jsx("span",{title:"Clear selection",style:{cursor:"pointer",color:"#94a3b8",fontSize:14,fontWeight:600,padding:"0 4px",lineHeight:1,userSelect:"none",transition:"color 0.15s ease",flexShrink:0},onClick:D=>{D.stopPropagation(),n(""),v(""),w(!1)},onMouseEnter:D=>D.currentTarget.style.color="#475569",onMouseLeave:D=>D.currentTarget.style.color="#94a3b8",children:"✕"}):t.jsx("span",{className:"trigger-arrow",style:{pointerEvents:"none",flexShrink:0},children:"▼"})]}),j&&t.jsx("div",{className:"custom-select-dropdown",children:t.jsxs("div",{style:{maxHeight:260,overflowY:"auto"},children:[ne.length===0&&!W&&t.jsx("div",{className:"custom-select-empty",children:"No matching records found"}),ne.map(D=>t.jsx("div",{className:`custom-select-option ${e===D.name?"selected":""} ${z===D.name?"hovered":""}`,onClick:()=>{n(D.name),v(""),w(!1)},onMouseEnter:()=>k(D.name),onMouseLeave:()=>k(""),children:D.label},D.name)),W&&t.jsxs("div",{className:`custom-select-option create-new-option ${z==="__create_new"?"hovered":""}`,style:{borderTop:"1px solid #e2e8f0",color:"#16a34a",fontWeight:700,fontSize:13,padding:"10px 14px",display:"flex",alignItems:"center",gap:6,cursor:"pointer",background:z==="__create_new"?"#f0fdf4":"#ffffff",transition:"all 0.15s ease"},onClick:()=>{w(!1),l?l():(x(""),b(""),o(!0))},onMouseEnter:()=>k("__create_new"),onMouseLeave:()=>k(""),children:[t.jsx("span",{style:{fontSize:16,fontWeight:800,color:"#16a34a",lineHeight:1},children:"+"}),t.jsx("span",{children:I})]})]})})]}),g&&d&&t.jsx("div",{style:{position:"fixed",inset:0,zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(15, 23, 42, 0.55)",backdropFilter:"blur(3px)",padding:16},onClick:D=>{D.target===D.currentTarget&&!y&&o(!1)},children:t.jsxs("div",{style:{background:"#ffffff",borderRadius:12,boxShadow:"0 20px 40px rgba(0, 0, 0, 0.2)",maxWidth:440,width:"100%",overflow:"hidden",animation:"scaleIn 0.15s ease"},children:[t.jsxs("div",{style:{padding:"16px 20px",borderBottom:"1px solid #f1f5f9",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:16,fontWeight:700,color:"#1e293b"},children:[t.jsx("span",{style:{color:"#2563eb",fontSize:18,fontWeight:800},children:"+"}),t.jsx("span",{children:`Create New ${d.replace(/^SB\s+/,"")}`})]}),t.jsx("button",{type:"button",onClick:()=>!y&&o(!1),style:{background:"none",border:"none",color:"#94a3b8",fontSize:18,cursor:"pointer",padding:"2px 6px",borderRadius:4},children:"✕"})]}),t.jsxs("form",{onSubmit:T,style:{padding:"20px"},children:[u&&t.jsx("div",{style:{background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",padding:"8px 12px",borderRadius:6,fontSize:12,marginBottom:14},children:u}),t.jsxs("div",{style:{marginBottom:16},children:[t.jsxs("label",{style:{display:"block",fontSize:12,fontWeight:700,color:"#334155",marginBottom:6},children:[yo(d).label," ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"text",value:h,onChange:D=>x(D.target.value),placeholder:`Enter ${yo(d).label.toLowerCase()}`,autoFocus:!0,disabled:y,style:{width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:13,boxSizing:"border-box",outline:"none"}})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:10,marginTop:22},children:[t.jsx("button",{type:"button",onClick:()=>o(!1),disabled:y,style:{padding:"8px 16px",borderRadius:8,border:"1px solid #cbd5e1",background:"#f8fafc",color:"#475569",fontWeight:600,fontSize:13,cursor:y?"not-allowed":"pointer"},children:"Cancel"}),t.jsxs("button",{type:"submit",disabled:y||!h.trim(),style:{padding:"8px 18px",borderRadius:8,border:"none",background:"#2563eb",color:"#ffffff",fontWeight:700,fontSize:13,cursor:y||!h.trim()?"not-allowed":"pointer",opacity:y||!h.trim()?.6:1,display:"flex",alignItems:"center",gap:6,boxShadow:"0 2px 4px rgba(37, 99, 235, 0.25)"},children:[t.jsx("span",{style:{fontSize:15,fontWeight:800},children:"+"}),t.jsx("span",{children:y?"Creating...":"Create"})]})]})]})]})})]})}function j0(e){const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<86400*7?`${Math.floor(n/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function b0(e){return e.replace(/@.*/,"").replace(/[._-]/g," ").split(" ").filter(Boolean).slice(0,2).map(s=>s[0].toUpperCase()).join("")}function wi({doctype:e,docname:n,currentUserName:s}){const a=le(),[r,l]=_.useState([]),[i,d]=_.useState(!1),[f,p]=_.useState(""),[C,j]=_.useState(!1),[w,c]=_.useState(!1),[v,z]=_.useState(!1),[k,g]=_.useState(""),o=5,h=_.useCallback(async()=>{d(!0);const b=await Wy(e,n);l(b),d(!1)},[e,n]);_.useEffect(()=>{h()},[h]);const x=async()=>{const b=f.trim();if(!(!b||C)){j(!0),g("");try{await Ny(e,n,b),p(""),await h()}catch{g("Failed to post comment. Please try again.")}j(!1)}},y=async b=>{if(window.confirm("Delete this comment?"))try{await md("Comment",b),l(A=>A.filter(E=>E.name!==b))}catch{alert("Failed to delete comment.")}},S=v?r:r.slice(-o),u=Math.max(0,r.length-o);return t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>c(b=>!b),style:{padding:"12px 20px",borderBottom:w?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none",background:"white"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["💬 ",a.comments.title,r.length>0&&t.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:r.length})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("button",{onClick:b=>{b.stopPropagation(),h()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),t.jsx("span",{style:{color:"#ccc",fontSize:11},children:w?"▼":"▲"})]})]}),!w&&t.jsxs("div",{style:{padding:"16px 20px"},children:[!v&&u>0&&t.jsxs("button",{onClick:()=>z(!0),style:{width:"100%",padding:"8px",marginBottom:12,border:"none",background:"#f8f9fa",borderRadius:6,cursor:"pointer",fontSize:12,color:"#3498db",fontFamily:"Segoe UI"},children:["Show ",u," older comment",u!==1?"s":""]}),i&&t.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:a.loading}),!i&&r.length===0&&t.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:a.comments.noComments}),!i&&S.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:16},children:S.map(b=>{const A=b.comment_by||b.comment_email||b.owner||"Unknown",E=b.owner===s||b.comment_by===s;return t.jsxs("div",{style:{display:"flex",gap:10,padding:"12px 14px",background:"#f9fafb",borderRadius:8,border:"1px solid #e8e8e8"},children:[t.jsx("div",{style:{width:34,height:34,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:12,fontWeight:700,flexShrink:0},children:b0(A)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{fontSize:13,fontWeight:700,color:"#1a2332"},children:A}),t.jsx("span",{style:{fontSize:11,color:"#aaa"},children:j0(b.creation)})]}),E&&t.jsx("button",{onClick:()=>y(b.name),style:{background:"none",border:"none",cursor:"pointer",color:"#e74c3c",fontSize:16,padding:"0 2px",lineHeight:1},title:"Delete comment",children:"×"})]}),t.jsx("div",{style:{fontSize:13,color:"#374151",lineHeight:1.55,wordBreak:"break-word",whiteSpace:"pre-wrap"},dangerouslySetInnerHTML:{__html:b.content||""}})]})]},b.name)})}),t.jsxs("div",{style:{borderTop:r.length>0?"1px solid #f0f0f0":"none",paddingTop:r.length>0?14:0},children:[t.jsx("textarea",{value:f,onChange:b=>p(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.ctrlKey||b.metaKey)&&x()},placeholder:a.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"}}),k&&t.jsx("div",{style:{fontSize:12,color:"#e74c3c",marginTop:4},children:k}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:8},children:t.jsx("button",{onClick:x,disabled:!f.trim()||C,style:{padding:"8px 20px",background:"#3498db",color:"white",border:"none",borderRadius:6,cursor:!f.trim()||C?"not-allowed":"pointer",fontSize:13,fontWeight:600,fontFamily:"Segoe UI",opacity:!f.trim()||C?.6:1},children:C?a.saving:a.comments.post})})]})]})]})}function Lu(e){if(!e)return"";const n=(Date.now()-new Date(e).getTime())/1e3;return n<60?`${Math.floor(n)}s ago`:n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:n<86400*7?`${Math.floor(n/86400)}d ago`:new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function S0(e){return(e||"").replace(/^custom_/,"").replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Wu(e){return e==null||e===""?"(empty)":typeof e=="object"?JSON.stringify(e):String(e)}function xd(e){return(e||"Unknown").replace(/@.*/,"").replace(/[._]/g," ")}function Nu(e){return xd(e).split(" ").filter(Boolean).slice(0,2).map(n=>n[0].toUpperCase()).join("")}function _0(e){let n={};try{n=JSON.parse(e.data||"{}")}catch{}const s=(n.changed||[]).map(a=>({field:a[0]||"",oldVal:Wu(a[1]),newVal:Wu(a[2])}));return{name:e.name,owner:e.owner,creation:e.creation,changes:s,added:(n.added||[]).length,removed:(n.removed||[]).length,rowChanged:(n.row_changed||[]).length}}function ki({doctype:e,docname:n,docCreation:s,docOwner:a}){const r=le(),[l,i]=_.useState([]),[d,f]=_.useState(!1),[p,C]=_.useState(!0),[j,w]=_.useState(!1),c=5,v=_.useCallback(async()=>{f(!0);const o=await $y(e,n);i(o.map(_0)),f(!1)},[e,n]);_.useEffect(()=>{p||v()},[p,v]);const z=j?l:l.slice(0,c),k=l.length-c,g=(o,h=!1)=>({position:"absolute",left:-14,top:14,width:10,height:10,borderRadius:"50%",background:o,border:"2px solid white",boxShadow:h?`0 0 0 2px ${o}44`:"none"});return t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>C(o=>!o),style:{padding:"12px 20px",borderBottom:p?"none":"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",userSelect:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:700,color:"#1a2332"},children:["📋 ",r.activity.title,!p&&l.length>0&&t.jsx("span",{style:{background:"#e8f4fd",color:"#2980b9",fontSize:11,fontWeight:700,borderRadius:10,padding:"2px 8px"},children:l.length})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[!p&&t.jsx("button",{onClick:o=>{o.stopPropagation(),v()},style:{background:"none",border:"none",cursor:"pointer",color:"#aaa",fontSize:16,padding:"2px 4px",lineHeight:1},title:"Refresh",children:"↻"}),t.jsx("span",{style:{color:"#ccc",fontSize:11},children:p?"▼":"▲"})]})]}),!p&&t.jsxs("div",{style:{padding:"16px 20px"},children:[d&&t.jsx("div",{style:{textAlign:"center",color:"#aaa",fontSize:13,padding:"16px 0"},children:r.loading}),!d&&t.jsxs("div",{style:{position:"relative",paddingLeft:20},children:[t.jsx("div",{style:{position:"absolute",left:8,top:0,bottom:0,width:2,background:"#e5e7eb"}}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[z.map((o,h)=>t.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[t.jsx("div",{style:g(h===0?"#3498db":"#d1d5db",h===0)}),t.jsxs("div",{style:{background:h===0?"#eff6ff":"#f9fafb",border:`1px solid ${h===0?"#bfdbfe":"#e5e7eb"}`,borderRadius:8,padding:"10px 14px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[t.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#3498db",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:Nu(o.owner)}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:xd(o.owner)}),t.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Lu(o.creation)})]}),o.changes.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:o.changes.map((x,y)=>t.jsxs("div",{style:{fontSize:12,lineHeight:1.5},children:[t.jsx("span",{style:{fontWeight:600,color:"#6d28d9"},children:S0(x.field)}),t.jsx("span",{style:{color:"#6b7280"},children:" changed from "}),t.jsx("span",{style:{padding:"1px 5px",background:"#fee2e2",color:"#dc2626",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:x.oldVal}),t.jsx("span",{style:{color:"#6b7280"},children:" → "}),t.jsx("span",{style:{padding:"1px 5px",background:"#dcfce7",color:"#16a34a",borderRadius:3,fontSize:11,fontFamily:"monospace"},children:x.newVal})]},y))}):t.jsxs("div",{style:{fontSize:12,color:"#9ca3af",fontStyle:"italic"},children:["Document updated",o.added>0&&t.jsxs("span",{children:[" · +",o.added," row(s)"]}),o.removed>0&&t.jsxs("span",{children:[" · -",o.removed," row(s)"]}),o.rowChanged>0&&t.jsxs("span",{children:[" · ~",o.rowChanged," row(s) modified"]})]})]})]},o.name)),s&&a&&t.jsxs("div",{style:{position:"relative",paddingLeft:12},children:[t.jsx("div",{style:g("#22c55e")}),t.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"10px 14px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[t.jsx("div",{style:{width:26,height:26,borderRadius:"50%",background:"#22c55e",color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0},children:Nu(a)}),t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#374151"},children:xd(a)}),t.jsx("span",{style:{fontSize:11,color:"#9ca3af",marginLeft:"auto"},children:Lu(s)})]}),t.jsxs("div",{style:{fontSize:12,color:"#15803d",fontWeight:600},children:["✓ ",r.activity.created]})]})]}),l.length===0&&!s&&t.jsx("div",{style:{textAlign:"center",color:"#bbb",fontSize:13,padding:"12px 0",fontStyle:"italic"},children:"No activity recorded"})]})]}),!d&&k>0&&t.jsx("div",{style:{textAlign:"center",marginTop:12},children:t.jsx("button",{onClick:()=>w(o=>!o),style:{background:"none",border:"none",cursor:"pointer",color:"#3498db",fontSize:12,fontFamily:"Segoe UI",padding:"4px 8px"},children:j?"▲ Show less":`▼ Show all (${l.length})`})})]})]})}const w0={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 k0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...w0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function C0({incForm:e,setIncForm:n,organizations:s,groupCompanies:a=[],managements:r,departments:l,branches:i,incidentTypes:d,incidentClasses:f,incidentFields:p,incidentStatuses:C,users:j,userRoleMap:w={},formStatus:c,viewMode:v,canModify:z,onEdit:k,onDelete:g,onRestore:o,onPermanentDelete:h,darkMode:x,notifCount:y,onToggleDark:S,onCountChange:u,onViewProfile:b,userRole:A,delegatedFunctions:E=[],delegatedOrgs:H={},onSubmit:Y,onBack:ne,onNavigate:M,onLogout:W,user:N,onRefresh:I}){var Ct;const T=le(),G=K=>n({...e,...K}),V=v?{background:"#f9f9f9"}:{},D=Na(j,w,"SB Manager",e.organization),[O,q]=_.useState(""),[se,ie]=_.useState(!1),ke=e.name?v?`${T.formTitle.viewIncident}${e.number||e.name}`:T.formTitle.editIncident:T.formTitle.newIncident,Ie=nn(r,{organization:e.organization}),_t=nn(l,{organization:e.organization,management:e.management}),Kt=nn(i,{organization:e.organization,management:e.management,department:e.department}),wt=Se(Ie,e.management).map(K=>({name:K.name,label:K.name1||K.name})),Wt=Se(_t,e.department).map(K=>({name:K.name,label:K.department_name||K.name})),on=Se(Kt,e.branch).map(K=>({name:K.name,label:K.branch||K.name})),me=Se(d,e.type).map(K=>({name:K.name,label:K.name1||K.name})),Xt=Se(f,e.incident_class).map(K=>({name:K.name,label:K.name1||K.name})),We=Se(p,e.incident_field).map(K=>({name:K.name,label:K.name1||K.name})),Q=e.workflow_state||"New",te=A==="Employee",ue=A==="Auditor"||A==="Admin",Ee=A==="Manager",kt=Ee&&E.includes("incident_initial_evaluation")&&(!H.incident_initial_evaluation||(H.incident_initial_evaluation||[]).includes(e.organization)),he=ue||kt,F=e.name?Q==="New"?[{label:T.wf.submit,action:"Submit",color:"#2563eb"}]:Q==="Initial Evaluation"&&he?[{label:T.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:T.wf.reject,action:"Reject",color:"#dc2626"}]:Q==="Accept & Under Progress"&&(Ee||ue)?[{label:T.wf.submitSolution,action:"Submit Solution",color:"#059669"}]:Q==="working on resolution"&&(Ee||ue)?[{label:T.wf.resolutionComplete,action:"Resolution complete",color:"#166534"}]:[]:[];async function re(K){if(e.name){ie(!0),q("");try{const Fe={};K==="Assign to Manager"&&(e.assigned_to&&(Fe.assigned_to=e.assigned_to),e.priority&&(Fe.priority=e.priority),e.economy_class&&(Fe.economy_class=e.economy_class),e.entity_scope&&(Fe.entity_scope=e.entity_scope),e.hses_field&&(Fe.hses_field=e.hses_field),Fe.product_relation=String(e.product_relation??0),Fe.repeated=String(e.repeated??0)),K==="Submit Solution"&&(e.solution&&(Fe.solution=e.solution),e.summary&&(Fe.summary=e.summary),e.cost&&(Fe.cost=String(e.cost))),(K==="Resolution complete"||K==="Submit Solution")&&e.auditor_comment&&(Fe.auditor_comment=e.auditor_comment),await Fy(e.name,K,JSON.stringify(Fe)),q("Done"),I==null||I()}catch(Fe){q(Fe.message||"Error")}finally{ie(!1)}}}const L=((Ct=D.find(K=>K.name===e.assigned_to))==null?void 0:Ct.full_name)||e.assigned_to,be=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:T.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:Q})]}),Q==="Initial Evaluation"&&he&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:T.wf.assignToManager}),t.jsxs("select",{style:B,value:e.assigned_to||"",onChange:K=>G({assigned_to:K.target.value}),children:[t.jsx("option",{value:"",children:T.field.selectMgr}),D.map(K=>t.jsx("option",{value:K.name,children:K.full_name||K.name},K.name))]})]}),(Q==="Accept & Under Progress"||Q==="working on resolution")&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:T.field.solution}),t.jsx("textarea",{style:{...B,height:75,resize:"vertical"},value:e.solution||"",onChange:K=>G({solution:K.target.value}),placeholder:T.field.solutionPlaceholder}),t.jsx("label",{style:{...R,marginTop:6},children:T.field.actualCost}),t.jsx("input",{type:"number",style:B,value:e.cost||"",onChange:K=>G({cost:parseFloat(K.target.value)||0}),placeholder:"0.00"})]}),Q==="working on resolution"&&ue&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:T.field.auditorComment}),t.jsx("textarea",{style:{...B,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:K=>G({auditor_comment:K.target.value}),placeholder:T.field.commentPlaceholder})]}),F.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:F.map(K=>t.jsx("button",{onClick:()=>re(K.action),disabled:se,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:K.color,color:"white",fontWeight:600,fontSize:12,cursor:se?"not-allowed":"pointer",opacity:se?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:se?T.wf.applying:K.label})},K.action))}):t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:T.wf.noActions}),O&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:O==="Done"?J.green:J.red},children:O})]}),t.jsx(Si,{priority:e.priority,status:Q,assignedTo:L||(e.assigned_to?e.assigned_to:void 0),createdDate:e.date,modifiedDate:e.modified}),t.jsx(wi,{doctype:P.incidents,docname:e.name,currentUserName:N.name}),t.jsx(ki,{doctype:P.incidents,docname:e.name,docCreation:e.creation,docOwner:e.owner}),z&&g&&!e.custom_is_deleted&&t.jsx(bi,{title:"Delete Request",btnText:T.delete,onDelete:()=>g(e.name)})]}):null;return t.jsxs(tt,{title:ke,activePage:"incidents",user:N,formStatus:c,statusBadge:t.jsx("span",{style:k0(Q),children:Q}),buttonText:T.saveIncident,buttonColor:"#16a34a",viewMode:v,onEdit:k,darkMode:x,notifCount:y,onToggleDark:S,onCountChange:u,onViewProfile:b,rightPanel:be,onSubmit:Y,onBack:ne,onNavigate:M,onLogout:W,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:o?()=>o(e.name):void 0,onPermanentDelete:h?()=>h(e.name):void 0}),t.jsx(ce,{title:"Incident Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.number}),t.jsx("input",{style:{...B,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[T.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:K=>{var At;const Fe=(At=s.find(ys=>ys.name===K))==null?void 0:At.group_company;G({organization:K,...N.custom_group_company?{}:{group_company:Fe||e.group_company}})},organizations:s,disabled:v||!!N.custom_organization,userRole:A,onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.title}),t.jsx("input",{style:{...B,...V},value:e.title,disabled:v,onChange:K=>G({title:K.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.management}),t.jsx(xe,{value:e.management,onChange:K=>G({management:K}),items:wt,placeholder:T.field.select,disabled:v,userRole:A,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.department}),t.jsx(xe,{value:e.department,onChange:K=>G({department:K}),items:Wt,placeholder:T.field.select,disabled:v,userRole:A,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.section}),t.jsx("input",{style:{...B,...V},value:e.section_field||"",disabled:v,onChange:K=>G({section_field:K.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.branch}),t.jsx(xe,{value:e.branch,onChange:K=>G({branch:K}),items:on,placeholder:T.field.select,disabled:v,userRole:A,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.eventCategory}),t.jsxs("select",{style:{...B,...V},value:e.event_category||"",disabled:v,onChange:K=>G({event_category:K.target.value}),children:[t.jsx("option",{value:"",children:T.field.select}),e.event_category&&!["Complaint","Accident","Violent"].includes(e.event_category)&&t.jsx("option",{value:e.event_category,children:e.event_category}),t.jsx("option",{value:"Complaint",children:"Complaint"}),t.jsx("option",{value:"Accident",children:"Accident"}),t.jsx("option",{value:"Violent",children:"Violent"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.type}),t.jsx(xe,{value:e.type,onChange:K=>G({type:K}),items:me,placeholder:T.field.selectType,disabled:v,userRole:A,doctypeName:P.incidentTypes,onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.incidentClass}),t.jsx(xe,{value:e.incident_class,onChange:K=>G({incident_class:K}),items:Xt,placeholder:T.field.selectClass,disabled:v,userRole:A,doctypeName:P.incidentClass,onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.incidentField}),t.jsx(xe,{value:e.incident_field,onChange:K=>G({incident_field:K}),items:We,placeholder:T.field.selectField,disabled:v,userRole:A,doctypeName:P.incidentField,onQuickCreateSuccess:I})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.hsesField}),t.jsx("input",{style:{...B,...V},value:e.hses_field||"",disabled:v,onChange:K=>G({hses_field:K.target.value}),placeholder:"Safety, Health, Environment…"})]})]})}),t.jsxs(ce,{title:"Incident Details & Timing",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.date}),t.jsx(je,{value:e.date,onChange:K=>G({date:K}),disabled:!0,style:{...B,background:"#f8fafc"}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.time}),t.jsx("input",{type:"time",style:{...B,background:"#f8fafc"},value:e.time,disabled:!0,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.assignedTo}),v||A==="Employee"?t.jsx("input",{style:{...B,background:"#f8fafc",fontWeight:600,color:"#334155"},value:L||e.assigned_to||"—",readOnly:!0,disabled:!0}):t.jsx(xe,{value:e.assigned_to||"",onChange:K=>G({assigned_to:K}),items:D.map(K=>({name:K.name,label:K.full_name||K.name})),placeholder:T.field.select})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.description}),t.jsx("textarea",{style:{...B,...V,height:100,resize:"vertical"},value:e.description,disabled:v,onChange:K=>G({description:K.target.value}),placeholder:"Detailed description of the incident..."})]})]}),!te&&t.jsxs(ce,{title:T.steps.auditorTriage,children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.priority}),t.jsxs("select",{style:{...B,...v||!he?{background:"#f8fafc"}:{}},value:e.priority||"",disabled:v||!he,onChange:K=>G({priority:K.target.value}),children:[t.jsx("option",{value:"",children:T.field.select}),t.jsx("option",{value:"High",children:T.field.high}),t.jsx("option",{value:"Normal",children:T.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.economyClass}),t.jsxs("select",{style:{...B,...v||!he?{background:"#f8fafc"}:{}},value:e.economy_class||"",disabled:v||!he,onChange:K=>G({economy_class:K.target.value}),children:[t.jsx("option",{value:"",children:T.field.select}),t.jsx("option",{value:"Expenses",children:T.field.expenses}),t.jsx("option",{value:"Capital",children:T.field.capital}),t.jsx("option",{value:"Earn",children:T.field.earn}),t.jsx("option",{value:"Pay/Loss",children:T.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.entityScope}),t.jsxs("select",{style:{...B,...v||!he?{background:"#f8fafc"}:{}},value:e.entity_scope||"",disabled:v||!he,onChange:K=>G({entity_scope:K.target.value}),children:[t.jsx("option",{value:"",children:T.field.select}),t.jsx("option",{value:"Upstream",children:T.field.upstream}),t.jsx("option",{value:"On-stream",children:T.field.onstream}),t.jsx("option",{value:"Downstream",children:T.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:v||!he,onChange:K=>G({product_relation:K.target.checked?1:0})})," ",T.field.productRelation]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:v||!he,onChange:K=>G({repeated:K.target.checked?1:0})})," ",T.field.repeatedEvent]})]})]}),!te&&t.jsxs(ce,{title:T.steps.managerSolution,children:[t.jsxs("div",{style:{marginBottom:12},children:[t.jsx("label",{style:R,children:T.field.solution}),t.jsx("textarea",{style:{...B,height:90,resize:"vertical",...v&&!Ee&&!ue?{background:"#f8fafc"}:{}},value:e.solution||"",disabled:v&&!Ee&&!ue,onChange:K=>G({solution:K.target.value}),placeholder:T.field.solutionPlaceholder})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.actualCost}),t.jsx("input",{type:"number",style:{...B,...v&&!Ee&&!ue?{background:"#f8fafc"}:{}},value:e.cost||"",disabled:v&&!Ee&&!ue,onChange:K=>G({cost:parseFloat(K.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.summary}),t.jsx("input",{style:{...B,...v&&!Ee&&!ue?{background:"#f8fafc"}:{}},value:e.summary||"",disabled:v&&!Ee&&!ue,onChange:K=>G({summary:K.target.value}),placeholder:"Brief summary"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:T.field.auditorComment}),t.jsx("textarea",{style:{...B,height:70,resize:"vertical",...v&&!ue?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:v&&!ue,onChange:K=>G({auditor_comment:K.target.value}),placeholder:T.field.commentPlaceholder})]})]})]})}function z0({ideas:e,organizations:n,departments:s,branches:a,ideaStatuses:r,initialOrg:l,initialStatus:i,canModify:d,userRole:f,onView:p,onEdit:C,onDelete:j,onSelectionChange:w}){const c=le(),[v,z]=_.useState(new Set),[k,g]=_.useState({search:"",organization:l||"",department:"",branch:"",status:i||""}),o=(u,b)=>g(A=>({...A,[u]:b})),[h,x]=_.useState(1),y=e.filter(u=>!(k.search&&!`${u.number} ${u.title}`.toLowerCase().includes(k.search.toLowerCase())||k.organization&&u.organization!==k.organization||k.department&&u.department!==k.department||k.branch&&u.branch!==k.branch||k.status&&u.status!==k.status));_.useEffect(()=>{x(1)},[k]);const S=y.slice((h-1)*oe,h*oe);return _.useEffect(()=>{if(w){const u=e.filter(b=>v.has(b.name));w(u,S)}},[v,S,e]),t.jsxs(t.Fragment,{children:[t.jsx(_i,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.numberTitle}),t.jsx("input",{style:rt,value:k.search,onChange:u=>o("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.organization}),t.jsxs("select",{style:rt,value:k.organization,onChange:u=>o("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.department}),t.jsxs("select",{style:rt,value:k.department,onChange:u=>o("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.branch}),t.jsxs("select",{style:rt,value:k.branch,onChange:u=>o("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),a.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.status}),t.jsxs("select",{style:rt,value:k.status,onChange:u=>o("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),r.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:S.length>0&&S.every(u=>v.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...v,...S.map(b=>b.name)]));else{const b=new Set(v);S.forEach(A=>b.delete(A.name)),z(b)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noIdeas})}):S.map((u,b)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(u),style:{borderTop:"1px solid #f1f5f9",background:v.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":b%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:A=>A.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:v.has(u.name),onChange:()=>{const A=new Set(v);A.has(u.name)?A.delete(u.name):A.add(u.name),z(A)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx("span",{children:u.title||"—"}),u.sb_order&&t.jsxs("span",{style:{fontSize:11,background:"#f0fdf4",color:"#15803d",border:"1px solid #bbf7d0",borderRadius:9999,padding:"2px 8px",fontWeight:600},children:["📦 ",u.sb_order]})]})}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?hs(c.deletedBadge):u.status?hs(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:A=>A.stopPropagation(),children:t.jsx(dt,{onView:()=>p==null?void 0:p(u),onEdit:d&&C&&!u.custom_is_deleted&&!ns("idea",u.workflow_state)&&!(f==="Employee"&&u.workflow_state&&u.workflow_state!=="New")?()=>C(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Me,{page:h,total:y.length,onPageChange:x})]})}const I0={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 E0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...I0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function T0({ideaForm:e,setIdeaForm:n,organizations:s,groupCompanies:a=[],managements:r,departments:l,branches:i,ideaTypes:d,ideaStatuses:f,users:p=[],userRoleMap:C={},formStatus:j,viewMode:w,canModify:c,onEdit:v,onDelete:z,onRestore:k,onPermanentDelete:g,onNavigateToOrder:o,darkMode:h,notifCount:x,onToggleDark:y,onCountChange:S,onViewProfile:u,userRole:b,delegatedFunctions:A=[],delegatedOrgs:E={},onSubmit:H,onBack:Y,onNavigate:ne,onLogout:M,user:W,onRefresh:N}){var re;const I=le(),T=L=>n({...e,...L}),G=w?{background:"#f9f9f9"}:{},V=Na(p,C,"SB Manager",e.organization),[D,O]=_.useState(""),[q,se]=_.useState(!1),ie=e.name?w?`${I.formTitle.viewIdea}${e.number||e.title||e.name}`:I.formTitle.editIdea:I.formTitle.newIdea,ke=nn(r,{organization:e.organization}),Ie=nn(l,{organization:e.organization,management:e.management}),_t=nn(i,{organization:e.organization,management:e.management,department:e.department}),Kt=Se(ke,e.management).map(L=>({name:L.name,label:L.name1||L.name})),wt=Se(Ie,e.department).map(L=>({name:L.name,label:L.department_name||L.name})),Wt=Se(_t,e.branch).map(L=>({name:L.name,label:L.branch||L.name})),on=Se(d,e.type).map(L=>({name:L.name,label:L.name1||L.name})),me=e.workflow_state||"New",Xt=b==="Employee",We=b==="Auditor"||b==="Admin",Q=b==="Manager",te=Q&&A.includes("idea_initial_evaluation")&&(!E.idea_initial_evaluation||(E.idea_initial_evaluation||[]).includes(e.organization)),ue=We||te,Ee=e.name?me==="New"?[{label:I.wf.submit,action:"Submit",color:"#2563eb"}]:me==="Initial Evaluation"&&ue?[{label:I.wf.assignToManager,action:"Assign to Manager",color:"#d97706"},{label:I.wf.reject,action:"Reject",color:"#dc2626"}]:me==="Accept & Under Progress"&&(Q||We)?[{label:I.wf.submitSolution,action:"Submit Proposal",color:"#059669"}]:me==="working on proposal"&&We?[{label:I.wf.moveToOutsourcing,action:"Move to Outsourcing",color:"#0369a1"},{label:I.wf.reject,action:"Reject",color:"#dc2626"}]:[]:[];async function kt(L){if(e.name){se(!0),O("");try{const be={};L==="Assign to Manager"&&(e.assigned_to&&(be.assigned_to=e.assigned_to),e.priority&&(be.priority=e.priority),e.economy_class&&(be.economy_class=e.economy_class),e.entity_scope&&(be.entity_scope=e.entity_scope),e.hses_field&&(be.hses_field=e.hses_field),be.product_relation=String(e.product_relation??0),be.repeated=String(e.repeated??0)),L==="Submit Proposal"&&(e.solution&&(be.solution=e.solution),e.proposed_condition&&(be.proposed_condition=e.proposed_condition),e.cost&&(be.cost=String(e.cost))),e.auditor_comment&&(L==="Move to Outsourcing"||L==="Reject")&&(be.auditor_comment=e.auditor_comment);const Ct=await Hy(e.name,L,JSON.stringify(be));Ct!=null&&Ct.created_order&&T({sb_order:Ct.created_order,workflow_state:"Executed & Closed",status:"Executed & Closed"}),O("Done"),N==null||N()}catch(be){O(be.message||"Error")}finally{se(!1)}}}const he=((re=V.find(L=>L.name===e.assigned_to))==null?void 0:re.full_name)||e.assigned_to,F=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:I.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:me})]}),me==="Initial Evaluation"&&ue&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:I.wf.assignToManager}),t.jsxs("select",{style:B,value:e.assigned_to||"",onChange:L=>T({assigned_to:L.target.value}),children:[t.jsx("option",{value:"",children:I.field.selectMgr}),V.map(L=>t.jsx("option",{value:L.name,children:L.full_name||L.name},L.name))]})]}),me==="Accept & Under Progress"&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:I.field.solution}),t.jsx("textarea",{style:{...B,height:75,resize:"vertical"},value:e.solution||"",onChange:L=>T({solution:L.target.value}),placeholder:I.field.solutionPlaceholder}),t.jsx("label",{style:{...R,marginTop:6},children:I.field.actualCost}),t.jsx("input",{type:"number",style:B,value:e.cost||"",onChange:L=>T({cost:parseFloat(L.target.value)||0}),placeholder:"0.00"})]}),me==="working on proposal"&&We&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("label",{style:R,children:I.field.auditorComment}),t.jsx("textarea",{style:{...B,height:60,resize:"vertical"},value:e.auditor_comment||"",onChange:L=>T({auditor_comment:L.target.value}),placeholder:I.field.commentPlaceholder})]}),Ee.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:Ee.map(L=>t.jsx("button",{onClick:()=>kt(L.action),disabled:q,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:L.color,color:"white",fontWeight:600,fontSize:12,cursor:q?"not-allowed":"pointer",opacity:q?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:q?I.wf.applying:L.label})},L.action))}):t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:I.wf.noActions}),D&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:D==="Done"?J.green:J.red},children:D})]}),t.jsx(Si,{priority:e.priority,status:me,assignedTo:he||(e.assigned_to?e.assigned_to:void 0),createdDate:e.date,modifiedDate:e.modified}),t.jsx(wi,{doctype:P.ideas,docname:e.name,currentUserName:W.name}),t.jsx(ki,{doctype:P.ideas,docname:e.name,docCreation:e.creation,docOwner:e.owner}),c&&z&&!e.custom_is_deleted&&t.jsx(bi,{title:"Delete Request",btnText:I.delete,onDelete:()=>z(e.name)})]}):null;return t.jsxs(tt,{title:ie,activePage:"ideas",user:W,formStatus:j,statusBadge:t.jsx("span",{style:E0(me),children:me}),buttonText:I.saveIdea,buttonColor:"#16a34a",viewMode:w,onEdit:v,darkMode:h,notifCount:x,onToggleDark:y,onCountChange:S,onViewProfile:u,rightPanel:F,onSubmit:H,onBack:Y,onNavigate:ne,onLogout:M,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:k?()=>k(e.name):void 0,onPermanentDelete:g?()=>g(e.name):void 0}),e.sb_order&&t.jsxs("div",{style:{background:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:8,padding:"8px 14px",marginBottom:16,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:12},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden"},children:[t.jsx("span",{style:{fontSize:14,flexShrink:0},children:"📦"}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,color:"#15803d",textTransform:"uppercase",letterSpacing:"0.4px",whiteSpace:"nowrap"},children:[I.field.convertedToOrder,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#14532d",whiteSpace:"nowrap"},children:e.sb_order})]}),o&&t.jsxs("button",{type:"button",onClick:()=>o(e.sb_order),style:{background:"#16a34a",color:"#fff",border:"none",borderRadius:6,padding:"4px 10px",fontWeight:600,fontSize:11,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,transition:"background 0.15s ease"},onMouseEnter:L=>L.currentTarget.style.background="#15803d",onMouseLeave:L=>L.currentTarget.style.background="#16a34a",children:[I.field.viewOrder," →"]})]}),t.jsx(ce,{title:"Idea Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.number}),t.jsx("input",{style:{...B,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[I.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:L=>{var Ct;const be=(Ct=s.find(K=>K.name===L))==null?void 0:Ct.group_company;T({organization:L,...W.custom_group_company?{}:{group_company:be||e.group_company}})},organizations:s,disabled:w||!!W.custom_organization,userRole:b,onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.title}),t.jsx("input",{style:{...B,...G},value:e.title,disabled:w,onChange:L=>T({title:L.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.management}),t.jsx(xe,{value:e.management,onChange:L=>T({management:L}),items:Kt,placeholder:I.field.select,disabled:w,userRole:b,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.department}),t.jsx(xe,{value:e.department,onChange:L=>T({department:L}),items:wt,placeholder:I.field.select,disabled:w,userRole:b,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.section}),t.jsx("input",{style:{...B,...G},value:e.section_field||"",disabled:w,onChange:L=>T({section_field:L.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.branch}),t.jsx(xe,{value:e.branch,onChange:L=>T({branch:L}),items:Wt,placeholder:I.field.select,disabled:w,userRole:b,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.type}),t.jsx(xe,{value:e.type,onChange:L=>T({type:L}),items:on,placeholder:I.field.selectType,disabled:w,userRole:b,doctypeName:P.ideaTypes,onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.ideaClass}),t.jsxs("select",{style:{...B,...G},value:e.idea_class||"",disabled:w,onChange:L=>T({idea_class:L.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),t.jsx("option",{value:"Safety",children:"Safety"}),t.jsx("option",{value:"Non-safety",children:"Non-safety"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.hsesField}),t.jsx("input",{style:{...B,...G},value:e.hses_field||"",disabled:w,onChange:L=>T({hses_field:L.target.value}),placeholder:"Safety, Health, Environment…"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.date}),t.jsx(je,{value:e.date||"",onChange:L=>T({date:L}),disabled:!0,style:{...B,background:"#f8fafc"}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.assignedTo}),w||b==="Employee"?t.jsx("input",{style:{...B,background:"#f8fafc",fontWeight:600,color:"#334155"},value:he||e.assigned_to||"—",readOnly:!0,disabled:!0}):t.jsx(xe,{value:e.assigned_to||"",onChange:L=>T({assigned_to:L}),items:V.map(L=>({name:L.name,label:L.full_name||L.name})),placeholder:I.field.select})]})]})}),t.jsx(ce,{title:"Condition Details & Description",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(280px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.currentCondition}),t.jsx("textarea",{style:{...B,...G,height:100,resize:"vertical"},value:e.current_condition,disabled:w,onChange:L=>T({current_condition:L.target.value}),placeholder:"Describe the current condition or problem..."})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.proposedCondition}),t.jsx("textarea",{style:{...B,...G,height:100,resize:"vertical"},value:e.proposed_condition,disabled:w,onChange:L=>T({proposed_condition:L.target.value}),placeholder:"Describe the proposed solution or improvement..."})]})]})}),!Xt&&t.jsxs(ce,{title:I.steps.auditorEval,children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.priority}),t.jsxs("select",{style:{...B,...w||!ue?{background:"#f8fafc"}:{}},value:e.priority||"",disabled:w||!ue,onChange:L=>T({priority:L.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),t.jsx("option",{value:"High",children:I.field.high}),t.jsx("option",{value:"Normal",children:I.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.economyClass}),t.jsxs("select",{style:{...B,...w||!ue?{background:"#f8fafc"}:{}},value:e.economy_class||"",disabled:w||!ue,onChange:L=>T({economy_class:L.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),t.jsx("option",{value:"Expenses",children:I.field.expenses}),t.jsx("option",{value:"Capital",children:I.field.capital}),t.jsx("option",{value:"Earn",children:I.field.earn}),t.jsx("option",{value:"Pay/Loss",children:I.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.entityScope}),t.jsxs("select",{style:{...B,...w||!ue?{background:"#f8fafc"}:{}},value:e.entity_scope||"",disabled:w||!ue,onChange:L=>T({entity_scope:L.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),t.jsx("option",{value:"Upstream",children:I.field.upstream}),t.jsx("option",{value:"On-stream",children:I.field.onstream}),t.jsx("option",{value:"Downstream",children:I.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:20,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:w||!ue,onChange:L=>T({product_relation:L.target.checked?1:0})})," ",I.field.productRelation]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.repeated,disabled:w||!ue,onChange:L=>T({repeated:L.target.checked?1:0})})," ",I.field.repeatedEvent]})]})]}),!Xt&&t.jsxs(ce,{title:I.steps.managerSolution,children:[t.jsxs("div",{style:{marginBottom:12},children:[t.jsx("label",{style:R,children:I.field.solution}),t.jsx("textarea",{style:{...B,height:90,resize:"vertical",...w&&!Q&&!We?{background:"#f8fafc"}:{}},value:e.solution||"",disabled:w&&!Q&&!We,onChange:L=>T({solution:L.target.value}),placeholder:I.field.solutionPlaceholder})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.actualCost}),t.jsx("input",{type:"number",style:{...B,...w&&!Q&&!We?{background:"#f8fafc"}:{}},value:e.cost||"",disabled:w&&!Q&&!We,onChange:L=>T({cost:parseFloat(L.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.auditorComment}),t.jsx("textarea",{style:{...B,height:60,resize:"vertical",...w&&!We?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:w&&!We,onChange:L=>T({auditor_comment:L.target.value}),placeholder:I.field.commentPlaceholder})]})]})]})]})}function A0({orders:e,organizations:n,departments:s,branches:a,orderStatuses:r,initialOrg:l,initialStatus:i,canModify:d,userRole:f,onView:p,onEdit:C,onDelete:j,onSelectionChange:w}){const c=le(),[v,z]=_.useState(new Set),[k,g]=_.useState({search:"",organization:l||"",department:"",branch:"",status:i||""}),o=(u,b)=>g(A=>({...A,[u]:b})),[h,x]=_.useState(1),y=e.filter(u=>!(k.search&&!`${u.number} ${u.title}`.toLowerCase().includes(k.search.toLowerCase())||k.organization&&u.organization!==k.organization||k.department&&u.department!==k.department||k.branch&&u.branch!==k.branch||k.status&&u.status!==k.status));_.useEffect(()=>{x(1)},[k]);const S=y.slice((h-1)*oe,h*oe);return _.useEffect(()=>{if(w){const u=e.filter(b=>v.has(b.name));w(u,S)}},[v,S,e]),t.jsxs(t.Fragment,{children:[t.jsx(_i,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.numberTitle}),t.jsx("input",{style:rt,value:k.search,onChange:u=>o("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.organization}),t.jsxs("select",{style:rt,value:k.organization,onChange:u=>o("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.department}),t.jsxs("select",{style:rt,value:k.department,onChange:u=>o("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.branch}),t.jsxs("select",{style:rt,value:k.branch,onChange:u=>o("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),a.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.status}),t.jsxs("select",{style:rt,value:k.status,onChange:u=>o("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),r.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:S.length>0&&S.every(u=>v.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...v,...S.map(b=>b.name)]));else{const b=new Set(v);S.forEach(A=>b.delete(A.name)),z(b)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.type}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noOrders})}):S.map((u,b)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(u),style:{borderTop:"1px solid #f1f5f9",background:v.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":b%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:A=>A.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:v.has(u.name),onChange:()=>{const A=new Set(v);A.has(u.name)?A.delete(u.name):A.add(u.name),z(A)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx("span",{children:u.title||u.name||"—"}),u.sb_idea&&t.jsxs("span",{style:{fontSize:11,background:"#eff6ff",color:"#1d4ed8",border:"1px solid #bfdbfe",borderRadius:9999,padding:"2px 8px",fontWeight:600},children:["💡 ",u.sb_idea]})]})}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.type?pc(u.type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?hs(c.deletedBadge):u.status?hs(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:A=>A.stopPropagation(),children:t.jsx(dt,{onView:()=>p==null?void 0:p(u),onEdit:d&&C&&!u.custom_is_deleted&&!ns("order",u.workflow_state)&&f!=="Employee"?()=>C(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Me,{page:h,total:y.length,onPageChange:x})]})}const P0={1:"Initiation / Bidding",2:"Execution begins",3:"Mid-execution review",4:"Near completion",5:"Closing"},R0={Draft:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Pending Actor":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},Review:{background:"#fefce8",color:"#92400e",border:"1px solid #fde68a"},"In Study":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Closed:{background:"#f0fdf4",color:"#166534",border:"1px solid #bbf7d0"}};function O0(e){return{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,...R0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}function D0({orderForm:e,setOrderForm:n,organizations:s,groupCompanies:a=[],managements:r,departments:l,branches:i,orderTypes:d,orderStatuses:f,cycles:p=[],users:C=[],userRoleMap:j={},formStatus:w,viewMode:c,canModify:v,onEdit:z,onDelete:k,onRestore:g,onPermanentDelete:o,onNavigateToIdea:h,darkMode:x,notifCount:y,onToggleDark:S,onCountChange:u,onViewProfile:b,currentUser:A,userRole:E,onSubmit:H,onBack:Y,onNavigate:ne,onLogout:M,user:W,onRefresh:N}){var Yr,Ga;const I=le(),T=U=>n({...e,...U}),G=c?{background:"#f9f9f9"}:{},V=Na(C,j,"SB Employee",e.organization),[D,O]=_.useState(""),[q,se]=_.useState(""),[ie,ke]=_.useState(!1),[Ie,_t]=_.useState("Agree"),Kt=e.name?c?`${I.formTitle.viewOrder}${e.number||e.title||e.name}`:I.formTitle.editOrder:I.formTitle.newOrder,wt=nn(r,{organization:e.organization}),Wt=nn(l,{organization:e.organization,management:e.management}),on=nn(i,{organization:e.organization,management:e.management,department:e.department}),me=Se(wt,e.management).map(U=>({name:U.name,label:U.name1||U.name})),Xt=Se(Wt,e.department).map(U=>({name:U.name,label:U.department_name||U.name})),We=Se(on,e.branch).map(U=>({name:U.name,label:U.branch||U.name})),Q=Se(d,e.type).map(U=>({name:U.name,label:U.name1||U.name})),te=["SAR","USD","EUR","AED","GBP","KWD","BHD","QAR","OMR","EGP"],ue=Array.from(new Set([...te,e.currency].filter(Boolean))).map(U=>({name:U,label:U})),Ee=Se(p,e.cycle).map(U=>({name:U.name,label:U.name1||U.cycle_name||U.name})),kt=!!e.name,he=e.workflow_state||"Draft",F=Math.min(5,(e.stage||0)+1),[re,L]=_.useState(F);_.useEffect(()=>{L(Math.min(5,(e.stage||0)+1))},[e.stage]);const be=E==="Auditor"||E==="Admin"||E==="Manager",Ct=be||E==="Owner",K=!!(A&&(e.actor===A||e.assigned_to===A)),Fe=e.stage===5||e.completion_pct===100||e.status==="Completion"||he==="Completed"||he==="Closed",At=e.order_cycle_log||[],ys=At.length>0?At[At.length-1].status:Ie,vs=ys==="Deviate"||ys==="Deviated"||ys==="Unknown",Gr=(()=>{if(!kt)return[];if(he==="Closed"||he==="Completed")return[];if(he==="Draft"&&be)return[{label:"Submit for Review",action:"Submit for Review",color:"#2563eb"}];if(he==="Pending Actor"&&(K||be))return[{label:"Update Status",action:"Update Status",color:"#d97706"}];if(he==="Review"&&Ct){const U=[{label:"Move to Study",action:"Move to Study",color:"#059669"}];return(!Fe||vs)&&U.push({label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}),Fe&&U.push({label:"Close Order",action:"Close Order",color:"#475569"}),U}if(he==="In Study"&&Ct){const U=[];return(!Fe||vs)&&U.push({label:"Start New Cycle",action:"Start New Cycle",color:"#2563eb"}),U.push({label:"Close Order",action:"Close Order",color:"#475569"}),U}return[]})();async function Qr(U){if(e.name){ke(!0),O("");try{let ft;U==="Update Status"&&(ft=Ie);const An=await My(e.name,U,q,U==="Update Status"?String(re):void 0,void 0,ft);if(se(""),_t("Agree"),O("Done"),An){const De=An;n({...e,...De,stage:De.stage??e.stage,completion_pct:De.completion_pct??e.completion_pct,workflow_state:De.workflow_state??e.workflow_state})}N==null||N()}catch(ft){O(ft.message||"Error")}finally{ke(!1)}}}const Kr=((Yr=V.find(U=>U.name===(e.actor||e.assigned_to)))==null?void 0:Yr.full_name)||e.actor||e.assigned_to,Xr=kt?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{background:"white",borderRadius:10,padding:14,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b",marginBottom:10},children:I.wf.workflow}),t.jsxs("div",{style:{background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",marginBottom:12},children:[t.jsx("div",{style:{fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:"0.4px",marginBottom:4},children:"Current State"}),t.jsx("div",{style:{fontSize:13,fontWeight:700,color:"#1e293b"},children:he})]}),he==="Pending Actor"&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,marginBottom:12},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:["Stage (1–5) — ",re*20,"% complete"]}),t.jsx("input",{type:"number",min:1,max:5,style:{...B,width:"100%"},value:re,onChange:U=>L(Math.min(5,Math.max(1,parseInt(U.target.value)||1)))})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Cycle Status"}),t.jsxs("select",{style:B,value:Ie,onChange:U=>_t(U.target.value),children:[t.jsx("option",{value:"Agree",children:"✅ Agree — on track"}),t.jsx("option",{value:"Deviate",children:"⚠️ Deviate — off plan"}),t.jsx("option",{value:"Unknown",children:"❓ Unknown"})]})]})]}),t.jsxs("div",{style:{marginBottom:12},children:[t.jsxs("label",{style:R,children:["Comment ",Ie==="Deviate"&&he==="Pending Actor"?t.jsx("span",{style:{color:J.red},children:" * required for Deviate"}):"(optional)"]}),t.jsx("textarea",{style:{...B,height:60,resize:"vertical",borderColor:Ie==="Deviate"&&!q?"#fca5a5":void 0},value:q,onChange:U=>se(U.target.value),placeholder:"Add a comment…"})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:Gr.map(U=>{const ft=U.action==="Update Status"&&Ie==="Deviate"&&!q.trim();return t.jsx("button",{onClick:()=>Qr(U.action),disabled:ie||ft,title:ft?"Comment required when status is Deviate":void 0,style:{width:"100%",padding:"8px 12px",borderRadius:6,border:"none",background:U.color,color:"white",fontWeight:600,fontSize:12,cursor:ie||ft?"not-allowed":"pointer",opacity:ie||ft?.5:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:t.jsx("span",{children:ie?I.wf.applying:U.label})},U.action)})}),D&&t.jsx("p",{style:{marginTop:8,fontSize:12,color:D==="Done"?J.green:J.red},children:D}),Gr.length===0&&t.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontStyle:"italic"},children:I.wf.noActions})]}),t.jsx(Si,{priority:e.priority,status:he,assignedTo:E!=="Employee"?Kr:void 0,createdDate:e.starting_date,modifiedDate:e.modified}),t.jsx(wi,{doctype:P.orders,docname:e.name,currentUserName:W.name}),t.jsx(ki,{doctype:P.orders,docname:e.name,docCreation:e.creation,docOwner:e.owner}),v&&k&&!e.custom_is_deleted&&t.jsx(bi,{title:"Delete Request",btnText:I.delete,onDelete:()=>k(e.name)})]}):null;return t.jsxs(tt,{title:Kt,activePage:"orders",user:W,formStatus:w,statusBadge:t.jsx("span",{style:O0(he),children:he}),buttonText:I.saveOrder,buttonColor:"#16a34a",viewMode:c,onEdit:z,darkMode:x,notifCount:y,onToggleDark:S,onCountChange:u,onViewProfile:b,rightPanel:Xr,onSubmit:H,onBack:Y,onNavigate:ne,onLogout:M,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:g?()=>g(e.name):void 0,onPermanentDelete:o?()=>o(e.name):void 0}),e.sb_idea&&t.jsxs("div",{style:{background:"#f0f7ff",border:"1px solid #bfdbfe",borderRadius:8,padding:"8px 14px",marginBottom:16,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:12},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden"},children:[t.jsx("span",{style:{fontSize:14,flexShrink:0},children:"💡"}),t.jsxs("span",{style:{fontSize:11,fontWeight:700,color:"#1e40af",textTransform:"uppercase",letterSpacing:"0.4px",whiteSpace:"nowrap"},children:[I.field.originatingIdea,":"]}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#1e3a8a",whiteSpace:"nowrap"},children:e.sb_idea})]}),h&&t.jsxs("button",{type:"button",onClick:()=>h(e.sb_idea),style:{background:"#2563eb",color:"#fff",border:"none",borderRadius:6,padding:"4px 10px",fontWeight:600,fontSize:11,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4,flexShrink:0,transition:"background 0.15s ease"},onMouseEnter:U=>U.currentTarget.style.background="#1d4ed8",onMouseLeave:U=>U.currentTarget.style.background="#2563eb",children:[I.field.viewIdea," →"]})]}),t.jsx(ce,{title:"Order Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.number}),t.jsx("input",{style:{...B,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number,readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[I.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:U=>{var An;const ft=(An=s.find(De=>De.name===U))==null?void 0:An.group_company;T({organization:U,...W.custom_group_company?{}:{group_company:ft||e.group_company}})},organizations:s,disabled:c||!!W.custom_organization,userRole:E,onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.title}),t.jsx("input",{style:{...B,...G},value:e.title,disabled:c,onChange:U=>T({title:U.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.management}),t.jsx(xe,{value:e.management,onChange:U=>T({management:U}),items:me,placeholder:I.field.select,disabled:c,userRole:E,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.department}),t.jsx(xe,{value:e.department,onChange:U=>T({department:U}),items:Xt,placeholder:I.field.select,disabled:c,userRole:E,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.section}),t.jsx("input",{style:{...B,...G},value:e.section_field||"",disabled:c,onChange:U=>T({section_field:U.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.branch}),t.jsx(xe,{value:e.branch,onChange:U=>T({branch:U}),items:We,placeholder:I.field.select,disabled:c,userRole:E,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.type}),t.jsx(xe,{value:e.type,onChange:U=>T({type:U}),items:Q,placeholder:I.field.selectType,disabled:c,userRole:E,doctypeName:P.orderTypes,onQuickCreateSuccess:N})]})]})}),t.jsxs(ce,{title:"Financial & Schedule",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.budget}),t.jsx("input",{type:"number",style:{...B,...G},value:e.budget||"",disabled:c,onChange:U=>T({budget:parseFloat(U.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.actualCost}),t.jsx("input",{type:"number",style:{...B,...G},value:e.actual_cost||"",disabled:c,onChange:U=>T({actual_cost:parseFloat(U.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Variance"}),(()=>{const U=(e.budget||0)-(e.actual_cost||0);return t.jsxs("div",{style:{padding:"7px 12px",borderRadius:6,fontWeight:700,fontSize:13,background:U>=0?"#f0fdf4":"#fef2f2",color:U>=0?"#166534":"#dc2626",border:`1px solid ${U>=0?"#bbf7d0":"#fecaca"}`,display:"inline-block",width:"100%",boxSizing:"border-box"},children:[U>=0?"+":"",U.toFixed(2)]})})()]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.currency}),t.jsx(xe,{value:e.currency||"",onChange:U=>T({currency:U}),items:ue,placeholder:I.field.select,disabled:c,userRole:E,doctypeName:P.currency,onQuickCreateSuccess:N})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.startingDate}),t.jsx(je,{value:e.starting_date,onChange:U=>T({starting_date:U}),disabled:c,style:{...B,...G}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.endingDate}),t.jsx(je,{value:e.ending_date,onChange:U=>T({ending_date:U}),disabled:c,style:{...B,...G}})]}),E!=="Employee"&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.actor}),c?t.jsx("input",{style:{...B,background:"#f8fafc",fontWeight:600,color:"#334155"},value:Kr||"—",readOnly:!0,disabled:!0}):t.jsxs("select",{style:{...B,background:"#ffffff"},value:e.actor||e.assigned_to||"",onChange:U=>T({actor:U.target.value,assigned_to:U.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),V.map(U=>t.jsx("option",{value:U.name,children:U.full_name||U.name},U.name))]})]})]})]}),t.jsxs(ce,{title:"Classification",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.priority}),t.jsxs("select",{style:{...B,...G},value:e.priority||"",disabled:c,onChange:U=>T({priority:U.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),t.jsx("option",{value:"High",children:I.field.high}),t.jsx("option",{value:"Normal",children:I.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.economyClass}),t.jsxs("select",{style:{...B,...G},value:e.economy_class||"",disabled:c,onChange:U=>T({economy_class:U.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),t.jsx("option",{value:"Expenses",children:I.field.expenses}),t.jsx("option",{value:"Capital",children:I.field.capital}),t.jsx("option",{value:"Earn",children:I.field.earn}),t.jsx("option",{value:"Pay/Loss",children:I.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.entityScope}),t.jsxs("select",{style:{...B,...G},value:e.entity_scope||"",disabled:c,onChange:U=>T({entity_scope:U.target.value}),children:[t.jsx("option",{value:"",children:I.field.select}),t.jsx("option",{value:"Upstream",children:I.field.upstream}),t.jsx("option",{value:"On-stream",children:I.field.onstream}),t.jsx("option",{value:"Downstream",children:I.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:24,marginTop:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.planned,disabled:c,onChange:U=>T({planned:U.target.checked?1:0})})," Planned"]}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:U=>T({product_relation:U.target.checked?1:0})})," ",I.field.productRelation]})]}),t.jsxs("div",{style:{marginTop:12},children:[t.jsx("label",{style:R,children:I.field.hsesField}),t.jsx("input",{style:{...B,...G},value:e.hses_field||"",disabled:c,onChange:U=>T({hses_field:U.target.value}),placeholder:"Safety, Health, Environment…"})]})]}),t.jsxs(ce,{title:"Cycle & Progress Tracking",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.cycle}),t.jsx(xe,{value:e.cycle||"",onChange:U=>T({cycle:U}),items:Ee,placeholder:I.field.select,disabled:c,userRole:E,doctypeName:P.cycles,extraFields:{organization:e.organization},onQuickCreateSuccess:N})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.cycleType}),t.jsxs("select",{style:{...B,...G},value:e.cycle_type||"Normal",disabled:c,onChange:U=>T({cycle_type:U.target.value}),children:[t.jsx("option",{value:"Normal",children:"Normal"}),t.jsx("option",{value:"Long",children:"Long"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.stage}),t.jsx("input",{type:"number",min:1,max:5,style:{...B,background:"#f8fafc",color:"#334155",fontWeight:600},value:e.stage||1,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Completion"}),t.jsx("input",{style:{...B,background:"#f8fafc",color:"#334155",fontWeight:600},value:`${e.completion_pct||(e.stage||1)*20}%`,readOnly:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Stage Description"}),t.jsx("span",{style:{display:"inline-block",padding:"7px 12px",borderRadius:6,fontSize:13,fontWeight:600,background:"#f0f9ff",color:"#0369a1",border:"1px solid #bae6fd",width:"100%",boxSizing:"border-box"},children:P0[e.stage||1]||"—"})]})]}),e.cycle_type==="Long"&&t.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14,marginBottom:14},children:[t.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 1"}),t.jsx(je,{value:e.long_cycle_date_1||"",onChange:U=>T({long_cycle_date_1:U}),disabled:c,style:{...B,...G}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 2"}),t.jsx(je,{value:e.long_cycle_date_2||"",onChange:U=>T({long_cycle_date_2:U}),disabled:c,style:{...B,...G}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 3"}),t.jsx(je,{value:e.long_cycle_date_3||"",onChange:U=>T({long_cycle_date_3:U}),disabled:c,style:{...B,...G}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 4"}),t.jsx(je,{value:e.long_cycle_date_4||"",onChange:U=>T({long_cycle_date_4:U}),disabled:c,style:{...B,...G}})]})]})]}),kt&&((Ga=e.order_cycle_log)==null?void 0:Ga.length)>0&&t.jsxs("div",{style:{borderTop:"1px solid #f1f5f9",paddingTop:14,marginTop:10},children:[t.jsx("p",{style:{fontWeight:700,color:"#334155",fontSize:13,marginBottom:10},children:"Cycle History"}),t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8fafc"},children:["Cycle","Date","Stage","Status","Actor","Comment"].map(U=>t.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:600,color:"#475569",borderBottom:"1px solid #e2e8f0"},children:U},U))})}),t.jsx("tbody",{children:(e.order_cycle_log||[]).map((U,ft)=>{const An=U.status==="Agree"?"#166534":U.status==="Deviate"?"#c2410c":"#92400e",De=U.status==="Agree"?"#f0fdf4":U.status==="Deviate"?"#fff7ed":"#fefce8";return t.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:U.cycle||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:U.cycle_date||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155",textAlign:"center"},children:U.stage||"—"}),t.jsx("td",{style:{padding:"6px 10px"},children:t.jsx("span",{style:{background:De,color:An,padding:"2px 8px",borderRadius:12,fontWeight:600,fontSize:12},children:U.status||"—"})}),t.jsx("td",{style:{padding:"6px 10px",color:"#334155"},children:U.actor||"—"}),t.jsx("td",{style:{padding:"6px 10px",color:"#64748b",fontStyle:U.comment?"normal":"italic"},children:U.comment||"—"})]},ft)})})]})})]})]}),t.jsxs(ce,{title:"Description & Notes",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(280px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.description}),t.jsx("textarea",{style:{...B,...G,height:90,resize:"vertical"},value:e.description,disabled:c,onChange:U=>T({description:U.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.notes}),t.jsx("textarea",{style:{...B,...G,height:90,resize:"vertical"},value:e.notes,disabled:c,onChange:U=>T({notes:U.target.value})})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:I.field.auditorComment}),t.jsx("textarea",{style:{...B,height:70,resize:"vertical",...c&&K&&!be?{background:"#f8fafc"}:{}},value:e.auditor_comment||"",disabled:c&&K&&!be,onChange:U=>T({auditor_comment:U.target.value}),placeholder:I.field.commentPlaceholder})]})]})]})}function B0({processes:e,organizations:n,departments:s,branches:a,processStatuses:r,initialOrg:l,initialStatus:i,canModify:d,userRole:f,onView:p,onEdit:C,onDelete:j,onSelectionChange:w}){const c=le(),[v,z]=_.useState(new Set),[k,g]=_.useState({search:"",organization:l||"",department:"",branch:"",status:i||""}),o=(u,b)=>g(A=>({...A,[u]:b})),[h,x]=_.useState(1),y=e.filter(u=>!(k.search&&!`${u.number} ${u.title}`.toLowerCase().includes(k.search.toLowerCase())||k.organization&&u.organization!==k.organization||k.department&&u.department!==k.department||k.branch&&u.branch!==k.branch||k.status&&u.status!==k.status));_.useEffect(()=>{x(1)},[k]);const S=y.slice((h-1)*oe,h*oe);return _.useEffect(()=>{if(w){const u=e.filter(b=>v.has(b.name));w(u,S)}},[v,S,e]),t.jsxs(t.Fragment,{children:[t.jsx(_i,{children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:"10px 14px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.numberTitle}),t.jsx("input",{style:rt,value:k.search,onChange:u=>o("search",u.target.value),placeholder:c.filter.searchPlaceholder})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.organization}),t.jsxs("select",{style:rt,value:k.organization,onChange:u=>o("organization",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allOrgs}),n.map(u=>t.jsx("option",{value:u.name,children:u.organization_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.department}),t.jsxs("select",{style:rt,value:k.department,onChange:u=>o("department",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allDepts}),s.map(u=>t.jsx("option",{value:u.name,children:u.department_name||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.branch}),t.jsxs("select",{style:rt,value:k.branch,onChange:u=>o("branch",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allBranches}),a.map(u=>t.jsx("option",{value:u.name,children:u.branch||u.name},u.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:at,children:c.filter.status}),t.jsxs("select",{style:rt,value:k.status,onChange:u=>o("status",u.target.value),children:[t.jsx("option",{value:"",children:c.filter.allStatuses}),r.map(u=>t.jsx("option",{value:u.name,children:u.name1||u.name},u.name))]})]})]})}),t.jsx("div",{style:{background:"white",borderRadius:12,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",overflow:"hidden",border:"1px solid #f1f5f9"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc",color:"#64748b",textAlign:"left",borderBottom:"1px solid #e2e8f0"},children:[t.jsx("th",{style:{width:44,padding:"12px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:S.length>0&&S.every(u=>v.has(u.name)),onChange:u=>{if(u.target.checked)z(new Set([...v,...S.map(b=>b.name)]));else{const b=new Set(v);S.forEach(A=>b.delete(A.name)),z(b)}},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.number}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.title}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.organization}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.field.cycleType}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.status}),t.jsx("th",{style:{padding:"12px 16px",fontWeight:600,fontSize:12},children:c.col.actions})]})}),t.jsx("tbody",{children:y.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#94a3b8"},children:c.noProcesses})}):S.map((u,b)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>p==null?void 0:p(u),style:{borderTop:"1px solid #f1f5f9",background:v.has(u.name)?"#eff6ff":u.custom_is_deleted?"#fff1f2":b%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:44,padding:"10px 14px",textAlign:"center"},onClick:A=>A.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:v.has(u.name),onChange:()=>{const A=new Set(v);A.has(u.name)?A.delete(u.name):A.add(u.name),z(A)},style:{width:16,height:16,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"12px 16px",color:"#64748b",fontSize:12,fontWeight:500},children:u.number||"—"}),t.jsx("td",{style:{padding:"12px 16px",fontWeight:600,color:"#1e293b"},children:u.title||u.name||"—"}),t.jsx("td",{style:{padding:"12px 16px",color:"#475569"},children:u.organization||"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.cycle_type?pc(u.cycle_type):"—"}),t.jsx("td",{style:{padding:"12px 16px"},children:u.custom_is_deleted?hs(c.deletedBadge):u.status?hs(u.status):"—"}),t.jsx("td",{style:{padding:"10px 16px"},onClick:A=>A.stopPropagation(),children:t.jsx(dt,{onView:()=>p==null?void 0:p(u),onEdit:d&&C&&!u.custom_is_deleted&&!ns("process",u.workflow_state)&&f!=="Employee"?()=>C(u):void 0,onDelete:d&&j&&!u.custom_is_deleted?()=>j(u.name):void 0})})]},u.name))})]})}),t.jsx(Me,{page:h,total:y.length,onPageChange:x})]})}const L0={Draft:[{action:"Submit for Review",next:"Pending Actor",allowedRoles:["Auditor","Manager"]}],"Pending Actor":[{action:"Update Status",next:"Pending Comment",allowedRoles:["Employee","Manager"]}],"Pending Comment":[{action:"Add Comment",next:"Review",allowedRoles:["Auditor","Manager"]}],Review:[{action:"Start New Cycle",next:"Pending Actor",allowedRoles:["Auditor","Manager"]},{action:"Move to Study",next:"In Study",allowedRoles:["Auditor","Manager"]},{action:"Close Process",next:"Closed",allowedRoles:["Auditor","Manager"]}],"In Study":[{action:"Start New Cycle",next:"Pending Actor",allowedRoles:["Auditor","Manager"]},{action:"Close Process",next:"Closed",allowedRoles:["Auditor","Manager"]}]},W0={Draft:{background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},"Pending Actor":{background:"#fff7ed",color:"#c2410c",border:"1px solid #fed7aa"},"Pending Comment":{background:"#f5f3ff",color:"#6d28d9",border:"1px solid #ddd6fe"},Review:{background:"#f0fdf4",color:"#15803d",border:"1px solid #bbf7d0"},"In Study":{background:"#f1f5f9",color:"#475569",border:"1px solid #cbd5e1"},Completed:{background:"#ecfdf5",color:"#047857",border:"1px solid #a7f3d0"},Closed:{background:"#f3f4f6",color:"#6b7280",border:"1px solid #9ca3af"}};function $u(e){return{display:"inline-block",padding:"5px 14px",borderRadius:20,fontSize:13,fontWeight:700,...W0[e]??{background:"#f3f4f6",color:"#374151",border:"1px solid #e5e7eb"}}}const xl={width:"100%",padding:"6px 8px",border:"1px solid #d1d5db",borderRadius:5,fontSize:12,fontFamily:"Segoe UI",boxSizing:"border-box"};function N0({processName:e,userRole:n,onRefresh:s,canUpdateStatus:a=!0}){const[r,l]=_.useState(null),[i,d]=_.useState(!0),[f,p]=_.useState(""),[C,j]=_.useState(!1),[w,c]=_.useState(""),[v,z]=_.useState(""),[k,g]=_.useState("Pass"),[o,h]=_.useState(""),[x,y]=_.useState({}),S=_.useCallback(async()=>{if(!e){d(!1);return}d(!0),p("");try{const M=await cr(e);l(M);const W={};for(const N of M.progress_indicators||[])W[N.name]=N.actual_value!=null?String(N.actual_value):"";y(W)}catch(M){p(M instanceof Error?M.message:"Failed to load process")}d(!1)},[e]);if(_.useEffect(()=>{S()},[S]),i)return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:24,color:"#aaa",fontSize:13,textAlign:"center"},children:"Loading…"})});if(f||!r)return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",padding:16},children:t.jsx("div",{style:{fontSize:12,color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px"},children:f||"Could not load workflow"})})});const u=r.workflow_state||"Draft",b=L0[u]??[],A=n==="Employee"||n==="Manager",E=n!=="Manager"||a,H=r.completion_pct===100||r.stage===5||r.status==="Completion"||r.status==="Completed"||u==="Completed"||u==="Closed",Y=b.filter(M=>M.action==="Start New Cycle"&&H?!1:(n==="Admin"||M.allowedRoles.includes(n))&&(M.action!=="Update Status"||E)),ne=async M=>{j(!0),c(""),z("");try{const W={};if(M==="Update Status"){W.actor_status=k,W.actor_comment=o;const I=r.progress_indicators||[];I.length>0&&(W.progress_indicators=I.map(T=>({name:T.name,actual_value:x[T.name]??""})))}M==="Add Comment"&&o&&(W.actor_comment=o);const N=await s0(r.name,M,W);l(N),h(""),z(`Done — now: ${N.workflow_state||"updated"}`),s==null||s()}catch(W){c(W instanceof Error?W.message:"Action failed")}j(!1)};return t.jsx("div",{style:{width:"100%",flexShrink:0},children:t.jsxs("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"hidden"},children:[t.jsx("div",{style:{background:"#1a2332",color:"white",padding:"10px 14px",fontSize:12,fontWeight:700,letterSpacing:.3},children:"Workflow"}),t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:8},children:"Current State"}),t.jsx("div",{style:$u(u),children:u})]}),u==="Pending Actor"&&A&&E&&t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Update Status"}),Array.isArray(r.progress_indicators)&&r.progress_indicators.length>0&&t.jsxs("div",{style:{marginBottom:10},children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Actual Value"}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.progress_indicators.map(M=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{fontSize:11,color:"#555",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:M.name1,children:M.name1||M.name}),t.jsx("input",{type:"number",value:x[M.name]??"",onChange:W=>y(N=>({...N,[M.name]:W.target.value})),style:{...xl,width:70,flexShrink:0},placeholder:"0"})]},M.name))})]}),t.jsxs("div",{style:{marginBottom:8},children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Cycle Status"}),t.jsxs("select",{value:k,onChange:M=>g(M.target.value),style:xl,children:[t.jsx("option",{value:"Pass",children:"✅ Pass — on target"}),t.jsx("option",{value:"Fail",children:"❌ Fail — off target"})]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,color:"#555",marginBottom:4},children:"Comment (optional)"}),t.jsx("textarea",{value:o,onChange:M=>h(M.target.value),style:{...xl,height:52,resize:"vertical"},placeholder:"Add a comment…"})]})]}),(u==="Pending Comment"||u==="Review")&&!A&&t.jsxs("div",{style:{padding:"12px 14px",borderBottom:"1px solid #f0f0f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Auditor Comment"}),Array.isArray(r.cycle_logs)&&r.cycle_logs.length>0&&t.jsxs("div",{style:{marginBottom:8,padding:"6px 10px",background:"#f8fafc",borderRadius:6,border:"1px solid #e2e8f0"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",marginBottom:3},children:"Latest cycle status:"}),(()=>{const M=r.cycle_logs,W=M[M.length-1],N=W.status==="Pass"?"#16a34a":W.status==="Fail"?"#dc2626":"#9ca3af";return t.jsxs("div",{style:{fontSize:13,fontWeight:700,color:N},children:[W.status," ",W.comment?`— ${W.comment}`:""]})})()]}),t.jsx("textarea",{value:o,onChange:M=>h(M.target.value),style:{...xl,height:52,resize:"vertical"},placeholder:"Add a comment…"})]}),t.jsxs("div",{style:{padding:"12px 14px",borderBottom:Y.length>0?"1px solid #f0f0f0":"none"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Actions"}),Y.length===0&&t.jsxs("div",{style:{fontSize:12,color:"#aaa",fontStyle:"italic",lineHeight:1.5},children:["No actions for ",t.jsx("strong",{children:n})," in ",t.jsx("strong",{children:u}),"."]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Y.map(M=>t.jsxs("button",{onClick:()=>ne(M.action),disabled:C,style:{width:"100%",padding:"10px 14px",borderRadius:6,border:"none",background:M.action==="Close Process"?"#64748b":M.action==="Move to Study"?"#8e44ad":"#2563eb",color:"white",cursor:C?"not-allowed":"pointer",fontSize:13,fontWeight:600,opacity:C?.7:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("span",{children:C?"Applying…":M.action}),t.jsxs("span",{style:{fontSize:10,opacity:.7},children:["→ ",M.next]})]},M.action))}),w&&t.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,fontSize:12,color:"#991b1b",lineHeight:1.4},children:w}),v&&t.jsx("div",{style:{marginTop:10,padding:"8px 12px",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,fontSize:12,color:"#166534"},children:v})]}),b.length>0&&t.jsxs("div",{style:{padding:"12px 14px"},children:[t.jsx("div",{style:{fontSize:10,color:"#999",fontWeight:700,textTransform:"uppercase",letterSpacing:.8,marginBottom:10},children:"Next States"}),b.map(M=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6,fontSize:11},children:[t.jsx("span",{style:{color:"#555",flex:1},children:M.action}),t.jsx("span",{style:{color:"#bbb"},children:"→"}),t.jsx("span",{style:$u(M.next),children:M.next})]},M.action))]})]})})}function $0({processForm:e,setProcessForm:n,organizations:s,groupCompanies:a=[],managements:r,departments:l,branches:i,processTypes:d,processStatuses:f,cycles:p=[],users:C=[],userRoleMap:j={},formStatus:w,viewMode:c,canModify:v,onEdit:z,onDelete:k,onRestore:g,onPermanentDelete:o,darkMode:h,notifCount:x,onToggleDark:y,onCountChange:S,onViewProfile:u,userRole:b,onRefreshProcess:A,onSubmit:E,onBack:H,onNavigate:Y,onLogout:ne,user:M}){var he;const W=le(),N=F=>n({...e,...F}),I=c?{background:"#f9f9f9"}:{},T=s,G=!!M.custom_organization,V=nn(r,{organization:e.organization}),D=nn(l,{organization:e.organization,management:e.management}),O=nn(i,{organization:e.organization,management:e.management,department:e.department}),q=Se(V,e.management).map(F=>({name:F.name,label:F.name1||F.name})),se=Se(D,e.department).map(F=>({name:F.name,label:F.department_name||F.name})),ie=Se(O,e.branch).map(F=>({name:F.name,label:F.branch||F.name})),ke=Se(d,e.type).map(F=>({name:F.name,label:F.name1||F.name})),Ie=Se(p,e.cycle).map(F=>({name:F.name,label:F.name1||F.name})),_t=Na(C,j,"SB Employee",e.organization).map(F=>({name:F.name,label:F.full_name||F.name})),Kt=Na(C,j,"SB Manager",e.organization).map(F=>({name:F.name,label:F.full_name||F.name})),wt=(F,re)=>{const L=[...e.cycle_logs||[]];L[F]={...L[F],...re},N({cycle_logs:L})},Wt=()=>{N({cycle_logs:[...e.cycle_logs||[],{cycle:"",cycle_date:"",status:"Pass",actor:"",comment:""}]})},on=F=>{const re=[...e.cycle_logs||[]];re.splice(F,1),N({cycle_logs:re})},me=(F,re)=>{const L=[...e.progress_indicators||[]];L[F]={...L[F],...re},N({progress_indicators:L})},Xt=()=>{N({progress_indicators:[...e.progress_indicators||[],{name1:"",type:"",unit:"",cycle:"",target:"",maximum:"",minimum:"",manager:"",order:"",actual_value:"",cycle_status:"Pass",cycle_date:"",cycle_comment:"",status:"Active"}]})},We=F=>{const re=[...e.progress_indicators||[]];re.splice(F,1),N({progress_indicators:re})},Q=e.name?c?`${W.formTitle.viewProcess}${e.title||e.name}`:W.formTitle.editProcess:W.formTitle.newProcess,te=b!=="Manager"||e.actor===M.name,ue=((he=_t.find(F=>F.name===e.actor))==null?void 0:he.label)||e.actor,Ee=e.workflow_state||"Draft",kt=e.name?t.jsxs("div",{style:{width:240,display:"flex",flexDirection:"column",gap:12},children:[t.jsx(N0,{processName:e.name,userRole:b||M.role||"Employee",onRefresh:A,canUpdateStatus:te}),t.jsx(Si,{priority:e.impact_level,status:Ee,assignedTo:ue,createdDate:e.date_start,modifiedDate:e.modified}),t.jsx(wi,{doctype:P.processes,docname:e.name,currentUserName:M.name}),t.jsx(ki,{doctype:P.processes,docname:e.name,docCreation:e.creation,docOwner:e.owner}),v&&k&&!e.custom_is_deleted&&t.jsx(bi,{title:"Delete Request",btnText:W.delete,onDelete:()=>k(e.name)})]}):void 0;return t.jsxs(tt,{title:Q,activePage:"processes",user:M,formStatus:w,statusBadge:t.jsx("span",{style:{display:"inline-block",padding:"4px 12px",borderRadius:20,fontSize:13,fontWeight:700,background:"#eff6ff",color:"#1e40af",border:"1px solid #bfdbfe"},children:Ee}),buttonText:W.saveProcess,buttonColor:"#16a34a",viewMode:c,onEdit:z,darkMode:h,notifCount:x,onToggleDark:y,onCountChange:S,onViewProfile:u,rightPanel:kt,onSubmit:E,onBack:H,onNavigate:Y,onLogout:ne,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:g?()=>g(e.name):void 0,onPermanentDelete:o?()=>o(e.name):void 0}),t.jsx(ce,{title:"Process Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[e.name&&t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.number}),t.jsx("input",{style:{...B,background:"#f8fafc",color:"#475569",fontWeight:600},value:e.number||"",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[W.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:F=>{var L;const re=(L=s.find(be=>be.name===F))==null?void 0:L.group_company;N({organization:F,...M.custom_group_company?{}:{group_company:re||e.group_company}})},organizations:T,disabled:c||G,userRole:b,onQuickCreateSuccess:A})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.title}),t.jsx("input",{style:{...B,...I},value:e.title,disabled:c,onChange:F=>N({title:F.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.type}),t.jsx(xe,{value:e.type,onChange:F=>N({type:F}),items:ke,placeholder:W.field.selectType,disabled:c,userRole:b,doctypeName:P.processTypes,onQuickCreateSuccess:A})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.management}),t.jsx(xe,{value:e.management,onChange:F=>N({management:F}),items:q,placeholder:W.field.select,disabled:c,userRole:b,doctypeName:P.managements,extraFields:{organization:e.organization},onQuickCreateSuccess:A})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.department}),t.jsx(xe,{value:e.department,onChange:F=>N({department:F}),items:se,placeholder:W.field.select,disabled:c,userRole:b,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management},onQuickCreateSuccess:A})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.section}),t.jsx("input",{style:{...B,...I},value:e.section_field||"",disabled:c,onChange:F=>N({section_field:F.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.branch}),t.jsx(xe,{value:e.branch,onChange:F=>N({branch:F}),items:ie,placeholder:W.field.select,disabled:c,userRole:b,doctypeName:P.branches,extraFields:{organization:e.organization,management:e.management,department:e.department},onQuickCreateSuccess:A})]})]})}),t.jsxs(ce,{title:"Classification",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.chainLocation}),t.jsxs("select",{style:{...B,...I},value:e.chain_location||"",disabled:c,onChange:F=>N({chain_location:F.target.value}),children:[t.jsx("option",{value:"",children:W.field.select}),t.jsx("option",{value:"Upstream",children:"Upstream"}),t.jsx("option",{value:"On-stream",children:"On-stream"}),t.jsx("option",{value:"Downstream",children:"Downstream"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.economyClass}),t.jsxs("select",{style:{...B,...I},value:e.economy_class||"",disabled:c,onChange:F=>N({economy_class:F.target.value}),children:[t.jsx("option",{value:"",children:W.field.select}),t.jsx("option",{value:"Expenses",children:W.field.expenses}),t.jsx("option",{value:"Capital",children:W.field.capital}),t.jsx("option",{value:"Earn",children:W.field.earn}),t.jsx("option",{value:"Pay/Loss",children:W.field.payLoss})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.impactLevel}),t.jsxs("select",{style:{...B,...I},value:e.impact_level||"",disabled:c,onChange:F=>N({impact_level:F.target.value}),children:[t.jsx("option",{value:"",children:W.field.select}),t.jsx("option",{value:"High",children:W.field.high}),t.jsx("option",{value:"Normal",children:W.field.normal})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.entityScope}),t.jsxs("select",{style:{...B,...I},value:e.entity_scope||"",disabled:c,onChange:F=>N({entity_scope:F.target.value}),children:[t.jsx("option",{value:"",children:W.field.select}),t.jsx("option",{value:"Upstream",children:W.field.upstream}),t.jsx("option",{value:"On-stream",children:W.field.onstream}),t.jsx("option",{value:"Downstream",children:W.field.downstream})]})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,alignItems:"center"},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.hsesField}),t.jsx("input",{style:{...B,...I},value:e.hses_field||"",disabled:c,onChange:F=>N({hses_field:F.target.value}),placeholder:"Safety, Health, Environment…"})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,paddingTop:18},children:t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13},children:[t.jsx("input",{type:"checkbox",checked:!!e.product_relation,disabled:c,onChange:F=>N({product_relation:F.target.checked?1:0})})," ",W.field.productRelation]})})]})]}),t.jsxs(ce,{title:"KPI & Timeline",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.kpiName}),t.jsx("input",{style:{...B,...I},value:e.kpi_name||"",disabled:c,onChange:F=>N({kpi_name:F.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.kpiType}),t.jsxs("select",{style:{...B,...I},value:e.kpi_type||"",disabled:c,onChange:F=>N({kpi_type:F.target.value}),children:[t.jsx("option",{value:"",children:W.field.select}),t.jsx("option",{value:"Human",children:"Human"}),t.jsx("option",{value:"Substantial",children:"Substantial"}),t.jsx("option",{value:"System",children:"System"}),t.jsx("option",{value:"Value",children:"Value"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.kpiMeasure}),t.jsx("input",{style:{...B,...I},value:e.kpi_measure||"",disabled:c,onChange:F=>N({kpi_measure:F.target.value}),placeholder:"Unit of measure"})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.dateStart}),t.jsx(je,{value:e.date_start,onChange:F=>N({date_start:F}),disabled:c,style:{...B,...I}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.dateEnd}),t.jsx(je,{value:e.date_end,onChange:F=>N({date_end:F}),disabled:c,style:{...B,...I}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.cycleType}),t.jsxs("select",{style:{...B,...I},value:e.cycle_type||"",disabled:c,onChange:F=>N({cycle_type:F.target.value}),children:[t.jsx("option",{value:"",children:W.field.select}),t.jsx("option",{value:"Normal",children:"Normal"}),t.jsx("option",{value:"Long",children:"Long"})]})]})]}),e.cycle_type==="Long"&&t.jsxs("div",{style:{background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:8,padding:14,marginTop:14},children:[t.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#c2410c",marginBottom:10},children:"Long Cycle Milestone Dates"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 1"}),t.jsx(je,{value:e.long_cycle_date_1||"",onChange:F=>N({long_cycle_date_1:F}),disabled:c,style:{...B,...I}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 2"}),t.jsx(je,{value:e.long_cycle_date_2||"",onChange:F=>N({long_cycle_date_2:F}),disabled:c,style:{...B,...I}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 3"}),t.jsx(je,{value:e.long_cycle_date_3||"",onChange:F=>N({long_cycle_date_3:F}),disabled:c,style:{...B,...I}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Milestone 4"}),t.jsx(je,{value:e.long_cycle_date_4||"",onChange:F=>N({long_cycle_date_4:F}),disabled:c,style:{...B,...I}})]})]})]})]}),t.jsxs(ce,{title:"Progress Indicators",children:[t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:!c&&t.jsx("button",{type:"button",onClick:Xt,style:{padding:"7px 14px",border:"none",background:"#2563eb",color:"white",borderRadius:6,fontWeight:600,fontSize:12,cursor:"pointer"},children:"+ Add Row"})}),t.jsx("div",{style:{overflowX:"auto",minWidth:0},children:t.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Order"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Name"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Type"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Unit"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Target"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Min"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Max"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Manager"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actual Value"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Status"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Date"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle Comment"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Status"}),!c&&t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actions"})]})}),t.jsxs("tbody",{children:[(e.progress_indicators||[]).length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:c?14:15,style:{padding:18,textAlign:"center",color:"#94a3b8"},children:"No progress indicators"})}),(e.progress_indicators||[]).map((F,re)=>t.jsxs("tr",{style:{background:re%2===0?"white":"#fafafa",borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I,width:60},value:F.order??"",disabled:c,onChange:L=>me(re,{order:L.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I},value:F.name1,disabled:c,onChange:L=>me(re,{name1:L.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I},value:F.type,disabled:c,onChange:L=>me(re,{type:L.target.value}),children:[t.jsx("option",{children:"Nominal"}),t.jsx("option",{children:"Ordinal"}),t.jsx("option",{children:"Interval"}),t.jsx("option",{children:"Ratio"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I,width:70},type:"text",value:F.unit??"",disabled:c,onChange:L=>me(re,{unit:L.target.value}),placeholder:"e.g. °C, kg, %"})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I,minWidth:120},value:F.cycle,disabled:c,onChange:L=>me(re,{cycle:L.target.value}),children:[t.jsx("option",{value:"",children:"--"}),Ie.map(L=>t.jsx("option",{value:L.name,children:L.label},L.name)),F.cycle&&!Ie.some(L=>L.name===F.cycle)&&t.jsx("option",{value:F.cycle,children:F.cycle})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I,width:80},value:F.target,disabled:c,onChange:L=>me(re,{target:L.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I,width:80},value:F.minimum,disabled:c,onChange:L=>me(re,{minimum:L.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I,width:80},value:F.maximum,disabled:c,onChange:L=>me(re,{maximum:L.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I,minWidth:140},value:F.manager,disabled:c,onChange:L=>me(re,{manager:L.target.value}),children:[t.jsx("option",{value:"",children:"--"}),Kt.map(L=>t.jsx("option",{value:L.name,children:L.label},L.name)),F.manager&&!Kt.some(L=>L.name===F.manager)&&t.jsx("option",{value:F.manager,children:F.manager})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I,width:90},type:"number",value:F.actual_value??"",disabled:c,onChange:L=>me(re,{actual_value:parseFloat(L.target.value)||""})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I},value:F.cycle_status??"",disabled:c,onChange:L=>me(re,{cycle_status:L.target.value}),children:[t.jsx("option",{value:"",children:"--"}),t.jsx("option",{children:"Normal"}),t.jsx("option",{children:"Below Min"}),t.jsx("option",{children:"Above Max"}),t.jsx("option",{children:"At Risk"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx(je,{value:F.cycle_date||"",onChange:L=>me(re,{cycle_date:L}),disabled:c,style:{...B,...I,width:110}})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I},value:F.cycle_comment??"",disabled:c,onChange:L=>me(re,{cycle_comment:L.target.value})})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I},value:F.status??"",disabled:c,onChange:L=>me(re,{status:L.target.value}),children:[t.jsx("option",{value:"",children:"--"}),t.jsx("option",{children:"Normal"}),t.jsx("option",{children:"Below Min"}),t.jsx("option",{children:"Above Max"}),t.jsx("option",{children:"At Risk"})]})}),!c&&t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("button",{type:"button",onClick:()=>We(re),style:{padding:"4px 8px",border:"1px solid #fecaca",background:"#fef2f2",color:"#dc2626",borderRadius:4,cursor:"pointer",fontSize:11,fontWeight:600},children:"Remove"})})]},re))]})]})})]}),t.jsx(ce,{title:"Cycle & Assignment",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16,marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.cycle}),t.jsx(xe,{value:e.cycle||"",onChange:F=>N({cycle:F}),items:Ie,placeholder:W.field.select,disabled:c,userRole:b,doctypeName:P.cycles,extraFields:{organization:e.organization},onQuickCreateSuccess:A})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.actor}),t.jsxs("select",{style:{...B,...I},value:e.actor||"",disabled:c,onChange:F=>N({actor:F.target.value}),children:[t.jsx("option",{value:"",children:W.field.select}),_t.map(F=>t.jsx("option",{value:F.name,children:F.label},F.name))]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.costPerCycle}),t.jsx("input",{style:{...B,...I},type:"number",value:e.cost_per_cycle||"",disabled:c,onChange:F=>N({cost_per_cycle:parseFloat(F.target.value)||0}),placeholder:"0.00"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:W.field.escalationLevel}),t.jsx("input",{style:{...B,...I},type:"number",value:e.escalation_level||"",disabled:c,onChange:F=>N({escalation_level:parseInt(F.target.value)||0})})]})]})}),t.jsxs(ce,{title:"Cycle History",children:[t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:!c&&t.jsx("button",{type:"button",onClick:Wt,style:{padding:"7px 14px",border:"none",background:"#2563eb",color:"white",borderRadius:6,fontWeight:600,fontSize:12,cursor:"pointer"},children:"+ Add Row"})}),t.jsx("div",{style:{overflowX:"auto",minWidth:0},children:t.jsxs("table",{style:{borderCollapse:"collapse",fontSize:12,width:"max-content",minWidth:"100%"},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Cycle"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Date"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Status"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actor"}),t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Comment"}),!c&&t.jsx("th",{style:{padding:"10px 12px",textAlign:"left",color:"#475569",fontWeight:600,borderBottom:"1px solid #e2e8f0"},children:"Actions"})]})}),t.jsxs("tbody",{children:[(e.cycle_logs||[]).length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:c?5:6,style:{padding:18,textAlign:"center",color:"#94a3b8"},children:"No cycle history"})}),(e.cycle_logs||[]).map((F,re)=>t.jsxs("tr",{style:{background:re%2===0?"white":"#fafafa",borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I},value:F.cycle||"",disabled:c,onChange:L=>wt(re,{cycle:L.target.value}),children:[t.jsx("option",{value:"",children:"-- Select --"}),Ie.map(L=>t.jsx("option",{value:L.name,children:L.label},L.name))]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx(je,{value:F.cycle_date||"",onChange:L=>wt(re,{cycle_date:L}),disabled:c,style:{...B,...I,width:130}})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I},value:F.status,disabled:c,onChange:L=>wt(re,{status:L.target.value}),children:[t.jsx("option",{value:"Pass",children:"Pass"}),t.jsx("option",{value:"Fail",children:"Fail"}),t.jsx("option",{value:"Unknown",children:"Unknown"})]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsxs("select",{style:{...B,...I},value:F.actor||"",disabled:c,onChange:L=>wt(re,{actor:L.target.value}),children:[t.jsx("option",{value:"",children:"-- Select --"}),_t.map(L=>t.jsx("option",{value:L.name,children:L.label},L.name))]})}),t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("input",{style:{...B,...I},value:F.comment||"",disabled:c,onChange:L=>wt(re,{comment:L.target.value})})}),!c&&t.jsx("td",{style:{padding:"8px 10px"},children:t.jsx("button",{type:"button",onClick:()=>on(re),style:{padding:"4px 8px",border:"1px solid #fecaca",background:"#fef2f2",color:"#dc2626",borderRadius:4,cursor:"pointer",fontSize:11,fontWeight:600},children:"Remove"})})]},re))]})]})})]}),t.jsx(ce,{title:W.field.auditorComment,children:t.jsx("textarea",{style:{...B,height:70,resize:"vertical",background:"#f8fafc"},value:e.auditor_comment||"",disabled:!0,readOnly:!0,placeholder:W.field.commentPlaceholder})})]})}const U0={CEO:"#8b5cf6",Admin:"#7c3aed",Auditor:"#d97706",Owner:"#0369a1","Business Owner":"#0369a1",XAuditor:"#0f766e",Manager:"#2563eb",Employee:"#6b7280",Chairman:"#0f766e"};function M0({user:e,profileUser:n,darkMode:s,canModify:a,onBack:r,sbUsers:l=[],organizations:i=[],managements:d=[],departments:f=[],branches:p=[],groupCompanies:C=[]}){const j=n||{},w=!!a&&(e.role==="Admin"||e.role==="CEO"||e.role==="Business Owner"||e.role==="Owner"),[c,v]=_.useState({first_name:j.first_name||"",middle_name:j.middle_name||"",last_name:j.last_name||"",mobile_no:j.mobile_no||"",custom_organization:j.custom_organization||"",custom_group_company:j.custom_group_company||"",custom_manager:j.custom_manager||"",custom_management:j.custom_management||"",custom_department:j.custom_department||"",custom_branch:j.custom_branch||"",custom_number:j.custom_number||"",custom_category:j.custom_category||""}),[z,k]=_.useState(""),[g,o]=_.useState(!1),[h,x]=_.useState({new:"",confirm:""}),[y,S]=_.useState(""),u=j.email||j.name||"",b=[c.first_name,c.middle_name,c.last_name].filter(Boolean).join(" ")||j.full_name||"",A=j.username||j.name||"",E=c.custom_category||"",H=j.enabled===0?"Inactive":"Active",Y=U0[e.role]||"#6b7280",ne=s,M=ne?"#0f172a":"#f0f2f5",W=ne?"#1e293b":"white",N=ne?"#2d3748":"#e5e7eb",I=ne?"#e2e8f0":"#1a2332",T=ne?"#94a3b8":"#6b7280",G=ne?"#374151":"white",V=ne?"#2d3748":"#f9fafb",D={width:"100%",padding:"9px 12px",borderRadius:8,border:`1px solid ${N}`,fontSize:13,background:G,color:I,fontFamily:"inherit",outline:"none"},O={...D,background:V,color:T},q={...D,cursor:"pointer"},se={fontSize:12,fontWeight:600,color:T,marginBottom:5,display:"block"},ie={display:"grid",gridTemplateColumns:"1fr 1fr",gap:14},ke={display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:14},Ie=(l||[]).find(Q=>Q.name===c.custom_manager),_t=Ie?Ie.full_name||Ie.email||Ie.name:c.custom_manager,Kt=(l||[]).filter(Q=>{if(!Q||nt(Q)||Q.enabled===0||Q.enabled===!1||Q.name===j.name)return!1;const te=Q.custom_category||"",ue=te==="CEO"||te==="Chairman"||te==="Business Owner"||Q.name==="Administrator";return c.custom_organization&&Q.custom_organization&&Q.custom_organization!==c.custom_organization&&!ue?!1:c.custom_category==="Admin"?te==="CEO"||te==="Chairman"||te==="Business Owner"||Q.name==="Administrator":c.custom_category==="Manager"?te==="Admin":c.custom_category==="Auditor"||c.custom_category==="X-Auditor"?te==="Manager"||te==="Admin"||te==="Business Owner":c.custom_category==="Employee"?te==="Auditor"||te==="X-Auditor"||te==="Manager":!(c.custom_category==="CEO"||c.custom_category==="Chairman"||c.custom_category==="Business Owner")}),wt=c.custom_organization?d.filter(Q=>!nt(Q)&&(!Q.organization||Q.organization===c.custom_organization)):d.filter(Q=>!nt(Q)),Wt=f.filter(Q=>!(nt(Q)||c.custom_organization&&Q.custom_organization&&Q.custom_organization!==c.custom_organization||c.custom_management&&Q.custom_management&&Q.custom_management!==c.custom_management)),on=p.filter(Q=>!(nt(Q)||c.custom_organization&&Q.organization&&Q.organization!==c.custom_organization||c.custom_management&&Q.management&&Q.management!==c.custom_management||c.custom_department&&Q.department&&Q.department!==c.custom_department)),me=async()=>{if(a){if(w){if(!c.custom_group_company){alert("Group Company (Tenant) is required");return}if(!c.custom_organization){alert("Organization is required");return}if(!c.custom_category){alert("Category is required");return}if(c.custom_category!=="CEO"&&c.custom_category!=="Chairman"&&c.custom_category!=="Business Owner"&&!c.custom_manager){alert("Reports To / Supervisor is mandatory.");return}}k("saving");try{await Ds("User",j.name,{first_name:c.first_name,middle_name:c.middle_name,last_name:c.last_name,mobile_no:c.mobile_no,custom_organization:c.custom_organization,custom_group_company:c.custom_group_company,custom_manager:c.custom_manager,custom_management:c.custom_management,custom_department:c.custom_department,custom_branch:c.custom_branch,custom_number:c.custom_number,custom_category:c.custom_category}),k("saved"),setTimeout(()=>k(""),2e3)}catch{k("error"),setTimeout(()=>k(""),3e3)}}},Xt=async()=>{if(!h.new){S("Enter a new password");return}if(h.new!==h.confirm){S("Passwords do not match");return}S("saving");try{await ai(j.name,h.new),S("done"),x({new:"",confirm:""}),setTimeout(()=>{S(""),o(!1)},2e3)}catch{S("error")}},We=({title:Q,icon:te,children:ue})=>t.jsxs("div",{style:{background:W,borderRadius:12,padding:22,border:`1px solid ${N}`,boxShadow:`0 1px 4px rgba(0,0,0,${ne?.3:.06})`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:18,paddingBottom:14,borderBottom:`1px solid ${N}`},children:[te,t.jsx("span",{style:{fontSize:14,fontWeight:700,color:I},children:Q})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:14},children:ue})]});return t.jsxs("div",{style:{background:M,minHeight:"100%",padding:"0 0 32px"},children:[t.jsxs("div",{style:{background:W,borderBottom:`1px solid ${N}`,padding:"12px 28px",display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[t.jsxs("button",{onClick:r,style:{display:"flex",alignItems:"center",gap:7,background:"none",border:"none",cursor:"pointer",fontSize:15,fontWeight:700,color:I,fontFamily:"inherit"},children:[t.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:t.jsx("polyline",{points:"15,18 9,12 15,6"})}),"User Profile"]}),a&&t.jsxs("button",{onClick:me,style:{display:"flex",alignItems:"center",gap:8,background:z==="saved"?"#16a34a":z==="error"?"#dc2626":"#16a34a",color:"white",border:"none",borderRadius:8,padding:"9px 22px",fontSize:13,fontWeight:700,cursor:"pointer",fontFamily:"inherit"},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),t.jsx("polyline",{points:"17,21 17,13 7,13 7,21"}),t.jsx("polyline",{points:"7,3 7,8 15,8"})]}),z==="saving"?"Saving…":z==="saved"?"Saved!":z==="error"?"Error":"Save Changes"]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"280px 1fr",gap:22,padding:"0 28px"},children:[t.jsxs("div",{style:{borderRadius:14,overflow:"hidden",boxShadow:"0 4px 20px rgba(0,0,0,0.12)",alignSelf:"start"},children:[t.jsxs("div",{style:{background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",padding:"32px 20px 28px",display:"flex",flexDirection:"column",alignItems:"center",gap:6},children:[t.jsx("div",{style:{width:78,height:78,borderRadius:"50%",background:"rgba(255,255,255,0.22)",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:4,border:"3px solid rgba(255,255,255,0.3)"},children:t.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"rgba(255,255,255,0.9)",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]})}),t.jsx("div",{style:{fontSize:17,fontWeight:700,color:"white",textAlign:"center",lineHeight:1.3},children:b||u}),t.jsx("div",{style:{fontSize:12,color:"rgba(255,255,255,0.75)",textAlign:"center"},children:u})]}),t.jsx("div",{style:{background:W},children:[{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:Y,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),t.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),t.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),t.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),label:"Username",value:A},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:Y,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),t.jsx("circle",{cx:"9",cy:"7",r:"4"}),t.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),t.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),label:"Role Profile",value:E||"—"},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:Y,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),t.jsx("circle",{cx:"9",cy:"7",r:"4"}),t.jsx("line",{x1:"19",y1:"8",x2:"19",y2:"14"}),t.jsx("line",{x1:"22",y1:"11",x2:"16",y2:"11"})]}),label:"Reports To / Supervisor",value:_t||c.custom_manager||"—"},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:Y,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),t.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),label:"Group Company",value:c.custom_group_company||"—"},{icon:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:H==="Active"?"#16a34a":"#dc2626",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),label:"Status",value:H,valueColor:H==="Active"?"#16a34a":"#dc2626"},{icon:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:Y,strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),t.jsx("path",{d:"m2 7 10 7 10-7"})]}),label:"Email",value:u},{icon:t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:Y,strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 13a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.6 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})}),label:"Phone",value:c.mobile_no||"—"}].map(({icon:Q,label:te,value:ue,valueColor:Ee})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 16px",borderBottom:`1px solid ${N}`},children:[t.jsx("div",{style:{flexShrink:0,width:18,display:"flex",justifyContent:"center"},children:Q}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,color:T,marginBottom:1},children:te}),t.jsx("div",{style:{fontSize:13,fontWeight:600,color:Ee||I,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ue})]})]},te))})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:18},children:[t.jsxs(We,{title:"Basic Information",icon:t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("circle",{cx:"12",cy:"8",r:"4"}),t.jsx("path",{d:"M4 20c0-4 3.6-7 8-7s8 3 8 7"})]}),children:[t.jsxs("div",{style:ie,children:[t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Email ",t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Read-only)"})]}),t.jsxs("div",{style:{position:"relative"},children:[t.jsx("div",{style:{position:"absolute",left:11,top:"50%",transform:"translateY(-50%)"},children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#94a3b8",strokeWidth:"2",children:[t.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),t.jsx("path",{d:"m2 7 10 7 10-7"})]})}),t.jsx("input",{style:{...O,paddingLeft:32},value:u,readOnly:!0})]})]}),t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Full Name ",t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Auto-generated)"})]}),t.jsx("input",{style:O,value:b,readOnly:!0})]})]}),t.jsxs("div",{style:ke,children:[t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["First Name ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{style:a?D:O,value:c.first_name,readOnly:!a,onChange:Q=>v(te=>({...te,first_name:Q.target.value})),placeholder:"First name"})]}),t.jsxs("div",{children:[t.jsx("label",{style:se,children:"Middle Name"}),t.jsx("input",{style:a?D:O,value:c.middle_name,readOnly:!a,onChange:Q=>v(te=>({...te,middle_name:Q.target.value})),placeholder:"Middle name"})]}),t.jsxs("div",{children:[t.jsx("label",{style:se,children:"Last Name"}),t.jsx("input",{style:a?D:O,value:c.last_name,readOnly:!a,onChange:Q=>v(te=>({...te,last_name:Q.target.value})),placeholder:"Last name"})]})]}),t.jsxs("div",{style:ie,children:[t.jsxs("div",{children:[t.jsx("label",{style:se,children:"Phone Number"}),t.jsx("input",{style:a?D:O,value:c.mobile_no,readOnly:!a,onChange:Q=>v(te=>({...te,mobile_no:Q.target.value})),placeholder:"Phone number"})]}),t.jsxs("div",{children:[t.jsx("label",{style:se,children:"User ID No"}),t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{style:{...O,paddingRight:44},value:c.custom_number||j.name||"",readOnly:!0}),t.jsx("div",{style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",background:"#ef4444",borderRadius:5,padding:"3px 7px",cursor:"default",display:"flex",alignItems:"center"},children:t.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"white",children:[t.jsx("circle",{cx:"5",cy:"12",r:"2"}),t.jsx("circle",{cx:"12",cy:"12",r:"2"}),t.jsx("circle",{cx:"19",cy:"12",r:"2"})]})})]})]})]}),t.jsxs("div",{style:ie,children:[t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Category ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})," ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:q,value:c.custom_category,onChange:Q=>v(te=>({...te,custom_category:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select category"}),(()=>{const Q=e.role==="Admin",ue=e.role==="Business Owner"||e.role==="Owner"?["CEO","Auditor","X-Auditor"]:Q?["Admin","Auditor","X-Auditor","Manager","Employee"]:["Admin","Business Owner","CEO","Chairman","Auditor","X-Auditor","Manager","Employee"];return Array.from(new Set([...ue,c.custom_category])).filter(Boolean).map(kt=>t.jsx("option",{value:kt,children:kt},kt))})()]}):t.jsx("input",{style:O,value:E||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Group Company (Tenant) ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})," ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:q,value:c.custom_group_company,onChange:Q=>v(te=>({...te,custom_group_company:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select group company"}),C.filter(Q=>!nt(Q)).map(Q=>t.jsx("option",{value:Q.name,children:Q.company_name||Q.name},Q.name))]}):t.jsx("input",{style:O,value:c.custom_group_company||"—",readOnly:!0})]})]}),c.custom_category!=="CEO"&&c.custom_category!=="Chairman"&&c.custom_category!=="Business Owner"&&t.jsxs("div",{style:{marginTop:14},children:[t.jsxs("label",{style:se,children:["Reports To / Supervisor ",c.custom_category&&t.jsx("span",{style:{color:"#ef4444"},children:"*"})," ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:q,value:c.custom_manager,disabled:!c.custom_category,onChange:Q=>v(te=>({...te,custom_manager:Q.target.value})),children:[t.jsx("option",{value:""}),Kt.map(Q=>{const te=Q.full_name||Q.email||Q.name,ue=Q.custom_category?` [${Q.custom_category}]`:"";return t.jsxs("option",{value:Q.name,children:[te,ue]},Q.name)})]}):t.jsx("input",{style:O,value:_t||c.custom_manager||"—",readOnly:!0})]})]}),t.jsxs(We,{title:"Organization Information",icon:t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#8b5cf6",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),t.jsx("path",{d:"M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"})]}),children:[t.jsxs("div",{style:ie,children:[t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Organization ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})," ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:q,value:c.custom_organization,onChange:Q=>v(te=>({...te,custom_organization:Q.target.value,custom_management:"",custom_department:"",custom_branch:"",custom_manager:""})),children:[t.jsx("option",{value:"",children:"Select organization"}),Se(i,c.custom_organization).map(Q=>t.jsx("option",{value:Q.name,children:Q.organization_name||Q.name},Q.name))]}):t.jsx("input",{style:O,value:c.custom_organization||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Management ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:q,value:c.custom_management,onChange:Q=>v(te=>({...te,custom_management:Q.target.value,custom_department:"",custom_branch:""})),children:[t.jsx("option",{value:"",children:"Select management"}),Se(wt,c.custom_management).map(Q=>t.jsx("option",{value:Q.name,children:Q.name1||Q.name},Q.name))]}):t.jsx("input",{style:O,value:c.custom_management||"—",readOnly:!0})]})]}),t.jsxs("div",{style:ie,children:[t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Department ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:q,value:c.custom_department,onChange:Q=>v(te=>({...te,custom_department:Q.target.value,custom_branch:""})),children:[t.jsx("option",{value:"",children:"Select department"}),Se(Wt,c.custom_department).map(Q=>t.jsx("option",{value:Q.name,children:Q.department_name||Q.name},Q.name))]}):t.jsx("input",{style:O,value:c.custom_department||"—",readOnly:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Branch ",!w&&t.jsx("span",{style:{fontSize:10,fontWeight:400},children:"(Admin only)"})]}),w?t.jsxs("select",{style:q,value:c.custom_branch,onChange:Q=>v(te=>({...te,custom_branch:Q.target.value})),children:[t.jsx("option",{value:"",children:"Select branch"}),Se(on,c.custom_branch).map(Q=>t.jsx("option",{value:Q.name,children:Q.branch||Q.name},Q.name))]}):t.jsx("input",{style:O,value:c.custom_branch||"—",readOnly:!0})]})]})]}),t.jsxs("div",{style:{background:W,borderRadius:12,padding:22,border:`1px solid ${N}`,boxShadow:`0 1px 4px rgba(0,0,0,${ne?.3:.06})`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),t.jsx("span",{style:{fontSize:14,fontWeight:700,color:I},children:"Change Password"})]}),a&&t.jsx("button",{onClick:()=>{o(Q=>!Q),S("")},style:{fontSize:13,color:"#3b82f6",background:"none",border:"none",cursor:"pointer",fontWeight:600,fontFamily:"inherit"},children:g?"Cancel":"Change Password"})]}),g&&t.jsxs("div",{style:{marginTop:18,display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:ke,children:[t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["New Password ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"password",style:D,value:h.new,onChange:Q=>x(te=>({...te,new:Q.target.value})),placeholder:"New password"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:se,children:["Confirm Password ",t.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),t.jsx("input",{type:"password",style:D,value:h.confirm,onChange:Q=>x(te=>({...te,confirm:Q.target.value})),placeholder:"Confirm password"})]}),t.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:t.jsx("button",{onClick:Xt,style:{width:"100%",padding:"9px 0",borderRadius:8,border:"none",background:"#2563eb",color:"white",fontWeight:700,fontSize:13,cursor:"pointer",fontFamily:"inherit"},children:y==="saving"?"Saving…":"Update Password"})})]}),y&&y!=="saving"&&t.jsx("div",{style:{fontSize:13,color:y==="done"?"#16a34a":"#dc2626",fontWeight:500},children:y==="done"?"Password updated successfully":y==="error"?"Failed to update password":y})]})]})]})]})]})}function Oe({label:e,val:n,color:s}){return t.jsxs("div",{style:{background:"white",borderRadius:8,padding:"8px 16px",flex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",borderTop:`3px solid ${s}`,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[t.jsx("div",{style:{fontSize:18,fontWeight:700,color:s},children:n}),t.jsx("div",{style:{fontSize:12,color:"#999"},children:e})]})}const gh={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151",boxSizing:"border-box"},F0={...gh,cursor:"pointer"};function St({filters:e,defaultOpen:n=!1}){const[s,a]=_.useState(n);return t.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[t.jsxs("div",{onClick:()=>a(r=>!r),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:s?t.jsx("polyline",{points:"18,15 12,9 6,15"}):t.jsx("polyline",{points:"6,9 12,15 18,9"})}),t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),s&&t.jsx("div",{style:{padding:"18px 20px"},children:t.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(${Math.min(e.length,4)}, 1fr)`,gap:14},children:e.map((r,l)=>t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:r.label}),r.type==="search"?t.jsx("input",{style:gh,placeholder:r.placeholder,value:r.value,onChange:i=>r.onChange(i.target.value)}):t.jsx("select",{style:F0,value:r.value,onChange:i=>r.onChange(i.target.value),children:r.options.map(i=>t.jsx("option",{value:i.value,children:i.label},i.value))})]},l))})})]})}function H0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function G0({organizations:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),[c,v]=_.useState("all"),z={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},k=_.useMemo(()=>e.filter(x=>{const y=[x.organization_name,x.city].filter(Boolean).join(" ").toLowerCase();return!(p&&!y.includes(p.toLowerCase())||j!=="all"&&x.type!==j||c!=="all"&&(x.is_active?"Active":"Inactive")!==c)}),[e,p,j,c]),[g,o]=_.useState(1);_.useEffect(()=>{o(1)},[p,j,c]);const h=k.slice((g-1)*oe,g*oe);return _.useEffect(()=>{if(l){const x=e.filter(y=>d.has(y.name));l(x,h)}},[d,h]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Oe,{label:"Total",val:k.length,color:"#1a2332"}),t.jsx(Oe,{label:"Active",val:k.filter(x=>x.is_active).length,color:J.green}),t.jsx(Oe,{label:"Government",val:k.filter(x=>x.type==="Government").length,color:J.blue}),t.jsx(Oe,{label:"Private",val:k.filter(x=>x.type==="Private").length,color:J.orange})]}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Name or city…"},{type:"select",label:i.col.type,value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Government",label:"Government"},{value:"Private",label:"Private"}]},{type:"select",label:"Status",value:c,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:h.length>0&&h.every(x=>d.has(x.name)),onChange:x=>{if(x.target.checked)f(new Set([...d,...h.map(y=>y.name)]));else{const y=new Set(d);h.forEach(S=>y.delete(S.name)),f(y)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:z,children:i.col.name}),t.jsx("th",{style:z,children:i.col.type}),t.jsx("th",{style:z,children:i.col.city}),t.jsx("th",{style:z,children:i.field.creationDate}),t.jsx("th",{style:z,children:i.col.status}),t.jsx("th",{style:z,children:i.col.actions})]})}),t.jsx("tbody",{children:k.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):h.map((x,y)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(x),style:{borderTop:"1px solid #f0f0f0",background:d.has(x.name)?"#eff6ff":x.custom_is_deleted?"#fff1f2":y%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:S=>S.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(x.name),onChange:()=>{const S=new Set(d);S.has(x.name)?S.delete(x.name):S.add(x.name),f(S)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:x.organization_name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:x.type||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:x.city||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:H0(x.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:x.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):Lr(x.is_active?i.field.statusActive:i.field.statusInactive,x.is_active?J.green:J.gray)}),t.jsx("td",{style:{padding:"8px 14px"},onClick:S=>S.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(x),onEdit:n&&a&&!x.custom_is_deleted?()=>a(x):void 0,onDelete:n&&r&&!x.custom_is_deleted?()=>r(x.name):void 0})})]},x.name))})]})}),t.jsx(Me,{page:g,total:k.length,onPageChange:o})]})}const Bn=e=>({background:e?"#f9f9f9":void 0});function Q0({orgForm:e,setOrgForm:n,groupCompanies:s=[],formStatus:a,viewMode:r,onEdit:l,onRestore:i,onPermanentDelete:d,darkMode:f,notifCount:p,onToggleDark:C,onCountChange:j,onViewProfile:w,onSubmit:c,onBack:v,onNavigate:z,onLogout:k,user:g}){const o=le(),h=e.name?r&&e.organization_name||o.formTitle.editOrg:o.formTitle.newOrg;return t.jsxs(tt,{title:h,activePage:"organizations",user:g,formStatus:a,buttonText:o.saveOrg,buttonColor:"#16a34a",viewMode:r,onEdit:l,darkMode:f,notifCount:p,onToggleDark:C,onCountChange:j,onViewProfile:w,onSubmit:c,onBack:v,onNavigate:z,onLogout:k,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:i&&e.name?()=>i(e.name):void 0,onPermanentDelete:d&&e.name?()=>d(e.name):void 0}),t.jsx(ce,{title:"Organization Information",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[o.field.orgName," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{type:"text",style:{...B,...Bn(r||!!e.name)},value:e.organization_name,disabled:r||!!e.name,required:!0,onChange:x=>n({...e,organization_name:x.target.value})})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[o.field.orgAcronym," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{type:"text",style:{...B,...Bn(r||!!e.name)},value:e.acronym||"",disabled:r||!!e.name,required:!0,onChange:x=>n({...e,acronym:x.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:o.field.organizationType}),t.jsxs("select",{style:{...B,...Bn(r)},value:e.type,disabled:r,onChange:x=>n({...e,type:x.target.value}),children:[t.jsx("option",{children:"Government"}),t.jsx("option",{children:"Private"}),t.jsx("option",{children:"Non-Profit"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:o.field.orgCity}),t.jsx("input",{type:"text",style:{...B,...Bn(r)},value:e.city,disabled:r,onChange:x=>n({...e,city:x.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:o.field.contactEmail}),t.jsx("input",{type:"email",style:{...B,...Bn(r)},value:e.contact_email,disabled:r,onChange:x=>n({...e,contact_email:x.target.value})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:o.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:x=>n({...e,creation_date:x}),disabled:r,style:{...B,...Bn(r)}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:o.field.status}),t.jsxs("select",{style:{...B,...Bn(r)},value:e.is_active?"Active":"Inactive",disabled:r,onChange:x=>n({...e,is_active:x.target.value==="Active"?1:0}),children:[t.jsx("option",{value:"Active",children:o.field.statusActive}),t.jsx("option",{value:"Inactive",children:o.field.statusInactive})]})]})]})}),t.jsx(ce,{title:"Incident SLA Windows",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:o.field.incidentTriageWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...B,...Bn(r)},value:e.incident_triage_window_days??3,disabled:r,onChange:x=>n({...e,incident_triage_window_days:parseInt(x.target.value)||3})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Days after creation before an untriaged Incident is flagged overdue"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:o.field.incidentResolutionWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...B,...Bn(r)},value:e.incident_resolution_window_days??5,disabled:r,onChange:x=>n({...e,incident_resolution_window_days:parseInt(x.target.value)||5})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Days without an update before an in-progress Incident is flagged overdue"})]})]})})]})}function K0({groupCompanies:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=[o.company_name,o.acronym,o.code,o.owner_user].filter(Boolean).join(" ").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Oe,{label:"Total Group Cos",val:v.length,color:"#1a2332"}),t.jsx(Oe,{label:"Active",val:v.filter(o=>(o.status||"Active")==="Active").length,color:J.green}),t.jsx(Oe,{label:"Inactive",val:v.filter(o=>o.status==="Inactive").length,color:J.orange})]}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Company name, code, owner…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Inactive",label:"Inactive"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{borderBottom:"1px solid #f0f0f0",background:"#fafafa"},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:"Company Name"}),t.jsx("th",{style:c,children:"Code / Acronym"}),t.jsx("th",{style:c,children:"Group Co Owner"}),t.jsx("th",{style:c,children:"Status"}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsxs("tbody",{children:[g.map((o,h)=>{const x=o.custom_is_deleted===1;return t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderBottom:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":x?"#fef2f2":h%2===0?"white":"#fafafa",cursor:"pointer",transition:"background 0.15s ease"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:y=>y.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const y=new Set(d);y.has(o.name)?y.delete(o.name):y.add(o.name),f(y)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsxs("td",{style:{padding:"12px 14px",fontWeight:600},children:[o.company_name,x&&t.jsx("span",{style:{marginLeft:8},children:Lr(i.deletedBadge,"#ef4444")})]}),t.jsx("td",{style:{padding:"12px 14px",color:"#555"},children:[o.code,o.acronym].filter(Boolean).join(" / ")||"—"}),t.jsx("td",{style:{padding:"12px 14px",color:"#555"},children:o.owner_user||"—"}),t.jsx("td",{style:{padding:"12px 14px"},children:Lr(o.status||"Active",(o.status||"Active")==="Active"?J.green:J.orange)}),t.jsx("td",{style:{padding:"12px 14px"},onClick:y=>y.stopPropagation(),children:t.jsx(dt,{onView:s?()=>s(o):void 0,onEdit:n&&a?()=>a(o):void 0,onDelete:n&&r?()=>r(o.name):void 0})})]},o.name)}),v.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:24,textAlign:"center",color:"#aaa"},children:"No Group Companies found"})})]})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function X0({form:e,setForm:n,users:s=[],formStatus:a,viewMode:r,onEdit:l,onRestore:i,onPermanentDelete:d,darkMode:f,notifCount:p,onToggleDark:C,onCountChange:j,onViewProfile:w,onSubmit:c,onBack:v,onNavigate:z,onLogout:k,user:g}){const o=S=>n({...e,...S}),h=r?{background:"#f8fafc"}:{};_.useEffect(()=>{if(!e.owner_user&&!r){const S=s.find(u=>u.custom_group_company===e.name&&(u.role==="Admin"||u.custom_category==="Admin"));S?o({owner_user:S.name}):!e.name&&(g.role==="Admin"||g.role==="CEO")&&o({owner_user:g.name})}},[e.name,e.owner_user,r,s,g.name,g.role]);const x=e.name?r?`View Group Company: ${e.company_name}`:"Edit Group Company":"New Group Company",y=(s||[]).filter(S=>!nt(S)).map(S=>({...S,name:S.name,label:S.full_name?`${S.full_name} (${S.name})`:S.name}));return t.jsxs(tt,{title:x,activePage:"group-companies",user:g,formStatus:a,buttonText:"Save Group Company",buttonColor:"#16a34a",viewMode:r,onEdit:l,darkMode:f,notifCount:p,onToggleDark:C,onCountChange:j,onViewProfile:w,onSubmit:c,onBack:v,onNavigate:z,onLogout:k,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:i?()=>i(e.name):void 0,onPermanentDelete:d?()=>d(e.name):void 0}),t.jsxs(ce,{title:"Group Company Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:["Company Name ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.company_name||"",disabled:r||!!e.name,onChange:S=>o({company_name:S.target.value}),placeholder:"e.g. Company A Group"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Company Code"}),t.jsx("input",{style:{...B,...h},value:e.code||"",disabled:r,onChange:S=>o({code:S.target.value}),placeholder:"e.g. CO-A"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Acronym"}),t.jsx("input",{style:{...B,...h},value:e.acronym||"",disabled:r,onChange:S=>o({acronym:S.target.value}),placeholder:"e.g. CAG"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Status"}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:r,onChange:S=>o({status:S.target.value}),children:[t.jsx("option",{value:"Active",children:"Active"}),t.jsx("option",{value:"Inactive",children:"Inactive"})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Group Co Owner / Admin User"}),t.jsx(xe,{value:e.owner_user||"",onChange:S=>o({owner_user:S}),items:y,placeholder:"Select owner user",disabled:r})]})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:"Notes"}),t.jsx("textarea",{style:{...B,...h,height:75,resize:"vertical"},value:e.notes||"",disabled:r,onChange:S=>o({notes:S.target.value}),placeholder:"Additional details regarding this tenant company…"})]})]})]})}function Y0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function q0({managements:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.blue})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:Y0(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function J0({form:e,setForm:n,organizations:s,groupCompanies:a=[],formStatus:r,viewMode:l,onEdit:i,onRestore:d,onPermanentDelete:f,darkMode:p,notifCount:C,onToggleDark:j,onCountChange:w,onViewProfile:c,onSubmit:v,onBack:z,onNavigate:k,onLogout:g,user:o}){const h=le(),x=u=>n(b=>({...b,...u})),y=l?{background:"#f8fafc"}:{},S=e.name?l?`${h.formTitle.editMgmt}: ${e.name1||e.name}`:h.formTitle.editMgmt:h.formTitle.newMgmt;return t.jsxs(tt,{title:S,activePage:"managements",user:o,formStatus:r,buttonText:h.saveMgmt,buttonColor:"#16a34a",viewMode:l,onEdit:i,darkMode:p,notifCount:C,onToggleDark:j,onCountChange:w,onViewProfile:c,onSubmit:v,onBack:z,onNavigate:k,onLogout:g,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:d&&e.name?()=>d(e.name):void 0,onPermanentDelete:f&&e.name?()=>f(e.name):void 0}),t.jsx(ce,{title:"Management Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:u=>{var A;const b=(A=s.find(E=>E.name===u))==null?void 0:A.group_company;x({organization:u,...o.custom_group_company?{}:{group_company:b||e.group_company}})},organizations:s,disabled:l||!!o.custom_organization,userRole:o.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...y},value:e.name1,disabled:l||!!e.name,onChange:u=>x({name1:u.target.value}),placeholder:"Management name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:u=>x({creation_date:u}),disabled:l,style:{...B,...y}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.status}),t.jsxs("select",{style:{...B,...y},value:e.status||"Active",disabled:l,onChange:u=>x({status:u.target.value}),children:[t.jsx("option",{value:"Active",children:h.field.statusActive}),t.jsx("option",{value:"Inactive",children:h.field.statusInactive})]})]})]})})]})}function V0(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function Z0({departments:e,managements:n,canModify:s,onView:a,onEdit:r,onDelete:l,onSelectionChange:i}){const d=le(),[f,p]=_.useState(new Set),[C,j]=_.useState(""),[w,c]=_.useState(""),[v,z]=_.useState("all"),k=S=>{var u;return((u=n.find(b=>b.name===S))==null?void 0:u.name1)||S||"—"},g={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},o=_.useMemo(()=>e.filter(S=>{const u=(S.department_name||S.name||"").toLowerCase();return!(C&&!u.includes(C.toLowerCase())||w&&S.custom_management!==w||v!=="all"&&(S.custom_status||"Active")!==v)}),[e,C,w,v]),[h,x]=_.useState(1);_.useEffect(()=>{x(1)},[C,w,v]);const y=o.slice((h-1)*oe,h*oe);return _.useEffect(()=>{if(i){const S=e.filter(u=>f.has(u.name));i(S,y)}},[f,y]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:o.length,color:J.teal})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:C,onChange:j,placeholder:"Search by name…"},{type:"select",label:d.col.management,value:w,onChange:c,options:[{value:"",label:"All Managements"},...n.map(S=>({value:S.name,label:S.name1||S.name}))]},{type:"select",label:"Status",value:v,onChange:z,options:[{value:"all",label:"All"},{value:"Active",label:d.field.statusActive},{value:"Inactive",label:d.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:y.length>0&&y.every(S=>f.has(S.name)),onChange:S=>{if(S.target.checked)p(new Set([...f,...y.map(u=>u.name)]));else{const u=new Set(f);y.forEach(b=>u.delete(b.name)),p(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:g,children:d.col.name}),t.jsx("th",{style:g,children:d.col.management}),t.jsx("th",{style:g,children:d.field.creationDate}),t.jsx("th",{style:g,children:d.field.status}),t.jsx("th",{style:g,children:d.col.actions})]})}),t.jsx("tbody",{children:o.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:d.noData})}):y.map((S,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>a==null?void 0:a(S),style:{borderTop:"1px solid #f0f0f0",background:f.has(S.name)?"#eff6ff":S.custom_is_deleted?"#fff1f2":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:b=>b.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:f.has(S.name),onChange:()=>{const b=new Set(f);b.has(S.name)?b.delete(S.name):b.add(S.name),p(b)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:S.department_name||S.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:k(S.custom_management)}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:V0(S.custom_creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:S.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:d.deletedBadge}):t.jsx("span",{style:{color:S.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:S.custom_status==="Inactive"?d.field.statusInactive:d.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:b=>b.stopPropagation(),children:t.jsx(dt,{onView:()=>a==null?void 0:a(S),onEdit:s&&r&&!S.custom_is_deleted?()=>r(S):void 0,onDelete:s&&l&&!S.custom_is_deleted?()=>l(S.name):void 0})})]},S.name))})]})}),t.jsx(Me,{page:h,total:o.length,onPageChange:x})]})}function e1({form:e,setForm:n,organizations:s,groupCompanies:a=[],managements:r,formStatus:l,viewMode:i,onEdit:d,onRestore:f,onPermanentDelete:p,darkMode:C,notifCount:j,onToggleDark:w,onCountChange:c,onViewProfile:v,onSubmit:z,onBack:k,onNavigate:g,onLogout:o,user:h}){const x=le(),y=A=>n(E=>({...E,...A})),S=i?{background:"#f8fafc"}:{},u=e.name?i?`${x.formTitle.editDept}: ${e.department_name||e.name}`:x.formTitle.editDept:x.formTitle.newDept,b=Se(r,e.custom_management).map(A=>({name:A.name,label:A.name1||A.name}));return t.jsxs(tt,{title:u,activePage:"departments",user:h,formStatus:l,buttonText:x.saveDept,buttonColor:"#16a34a",viewMode:i,onEdit:d,darkMode:C,notifCount:j,onToggleDark:w,onCountChange:c,onViewProfile:v,onSubmit:z,onBack:k,onNavigate:g,onLogout:o,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:f&&e.name?()=>f(e.name):void 0,onPermanentDelete:p&&e.name?()=>p(e.name):void 0}),t.jsx(ce,{title:"Department Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[x.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.custom_organization,onChange:A=>{var H;const E=(H=s.find(Y=>Y.name===A))==null?void 0:H.group_company;y({custom_organization:A,...h.custom_group_company?{}:{group_company:E||e.group_company}})},organizations:s,disabled:i||!!h.custom_organization,userRole:h.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[x.field.department," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...S},value:e.department_name,disabled:i||!!e.name,onChange:A=>y({department_name:A.target.value}),placeholder:"Department name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:x.field.management}),t.jsx(xe,{value:e.custom_management,onChange:A=>y({custom_management:A}),items:b,placeholder:x.field.select,disabled:i,userRole:h.role,doctypeName:P.managements,extraFields:{organization:e.custom_organization}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:x.field.creationDate}),t.jsx(je,{value:e.custom_creation_date||"",onChange:A=>y({custom_creation_date:A}),disabled:i,style:{...B,...S}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:x.field.status}),t.jsxs("select",{style:{...B,...S},value:e.custom_status||"Active",disabled:i,onChange:A=>y({custom_status:A.target.value}),children:[t.jsx("option",{value:"Active",children:x.field.statusActive}),t.jsx("option",{value:"Inactive",children:x.field.statusInactive})]})]})]})})]})}function t1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function n1({branches:e,managements:n,departments:s,canModify:a,onView:r,onEdit:l,onDelete:i,onSelectionChange:d}){const f=le(),[p,C]=_.useState(new Set),[j,w]=_.useState(""),[c,v]=_.useState(""),[z,k]=_.useState(""),[g,o]=_.useState("all"),h=E=>{var H;return((H=n.find(Y=>Y.name===E))==null?void 0:H.name1)||E||"—"},x=E=>{var H;return((H=s.find(Y=>Y.name===E))==null?void 0:H.department_name)||E||"—"},y={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},S=_.useMemo(()=>e.filter(E=>{const H=(E.branch||E.name||"").toLowerCase();return!(j&&!H.includes(j.toLowerCase())||c&&E.management!==c||z&&E.department!==z||g!=="all"&&(E.custom_status||"Active")!==g)}),[e,j,c,z,g]),[u,b]=_.useState(1);_.useEffect(()=>{b(1)},[j,c,z,g]);const A=S.slice((u-1)*oe,u*oe);return _.useEffect(()=>{if(d){const E=e.filter(H=>p.has(H.name));d(E,A)}},[p,A]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:S.length,color:J.purple})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:j,onChange:w,placeholder:"Search by name…"},{type:"select",label:f.col.management,value:c,onChange:v,options:[{value:"",label:"All Managements"},...n.map(E=>({value:E.name,label:E.name1||E.name}))]},{type:"select",label:f.col.department,value:z,onChange:k,options:[{value:"",label:"All Departments"},...s.map(E=>({value:E.name,label:E.department_name||E.name}))]},{type:"select",label:"Status",value:g,onChange:o,options:[{value:"all",label:"All"},{value:"Active",label:f.field.statusActive},{value:"Inactive",label:f.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:A.length>0&&A.every(E=>p.has(E.name)),onChange:E=>{if(E.target.checked)C(new Set([...p,...A.map(H=>H.name)]));else{const H=new Set(p);A.forEach(Y=>H.delete(Y.name)),C(H)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:y,children:f.col.branch}),t.jsx("th",{style:y,children:f.col.management}),t.jsx("th",{style:y,children:f.col.department}),t.jsx("th",{style:y,children:f.field.creationDate}),t.jsx("th",{style:y,children:f.field.status}),t.jsx("th",{style:y,children:f.col.actions})]})}),t.jsx("tbody",{children:S.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:f.noData})}):A.map((E,H)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>r==null?void 0:r(E),style:{borderTop:"1px solid #f0f0f0",background:p.has(E.name)?"#eff6ff":E.custom_is_deleted?"#fff1f2":H%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:Y=>Y.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:p.has(E.name),onChange:()=>{const Y=new Set(p);Y.has(E.name)?Y.delete(E.name):Y.add(E.name),C(Y)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:E.branch||E.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:h(E.management)}),t.jsx("td",{style:{padding:"10px 14px"},children:x(E.department)}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:t1(E.custom_creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:E.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:f.deletedBadge}):t.jsx("span",{style:{color:E.custom_status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:E.custom_status==="Inactive"?f.field.statusInactive:f.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:Y=>Y.stopPropagation(),children:t.jsx(dt,{onView:()=>r==null?void 0:r(E),onEdit:a&&l&&!E.custom_is_deleted?()=>l(E):void 0,onDelete:a&&i&&!E.custom_is_deleted?()=>i(E.name):void 0})})]},E.name))})]})}),t.jsx(Me,{page:u,total:S.length,onPageChange:b})]})}function s1({form:e,setForm:n,organizations:s,groupCompanies:a=[],managements:r,departments:l,formStatus:i,viewMode:d,onEdit:f,onRestore:p,onPermanentDelete:C,darkMode:j,notifCount:w,onToggleDark:c,onCountChange:v,onViewProfile:z,onSubmit:k,onBack:g,onNavigate:o,onLogout:h,user:x}){const y=le(),S=H=>n(Y=>({...Y,...H})),u=d?{background:"#f8fafc"}:{},b=Se(r,e.management).map(H=>({name:H.name,label:H.name1||H.name})),A=Se(l,e.department).map(H=>({name:H.name,label:H.department_name||H.name})),E=e.name?d?`${y.formTitle.editBranch}: ${e.branch||e.name}`:y.formTitle.editBranch:y.formTitle.newBranch;return t.jsxs(tt,{title:E,activePage:"branches",user:x,formStatus:i,buttonText:y.saveBranch,buttonColor:"#16a34a",viewMode:d,onEdit:f,darkMode:j,notifCount:w,onToggleDark:c,onCountChange:v,onViewProfile:z,onSubmit:k,onBack:g,onNavigate:o,onLogout:h,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:p&&e.name?()=>p(e.name):void 0,onPermanentDelete:C&&e.name?()=>C(e.name):void 0}),t.jsx(ce,{title:"Branch Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[y.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:H=>{var ne;const Y=(ne=s.find(M=>M.name===H))==null?void 0:ne.group_company;S({organization:H,...x.custom_group_company?{}:{group_company:Y||e.group_company}})},organizations:s,disabled:d||!!x.custom_organization,userRole:x.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[y.field.branch," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...u},value:e.branch,disabled:d||!!e.name,onChange:H=>S({branch:H.target.value}),placeholder:"Branch name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:y.field.management}),t.jsx(xe,{value:e.management,onChange:H=>S({management:H}),items:b,placeholder:y.field.select,disabled:d,userRole:x.role,doctypeName:P.managements,extraFields:{organization:e.organization}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:y.field.department}),t.jsx(xe,{value:e.department,onChange:H=>S({department:H}),items:A,placeholder:y.field.select,disabled:d,userRole:x.role,doctypeName:P.departments,extraFields:{organization:e.organization,management:e.management}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:y.field.creationDate}),t.jsx(je,{value:e.custom_creation_date||"",onChange:H=>S({custom_creation_date:H}),disabled:d,style:{...B,...u}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:y.field.status}),t.jsxs("select",{style:{...B,...u},value:e.custom_status||"Active",disabled:d,onChange:H=>S({custom_status:H.target.value}),children:[t.jsx("option",{value:"Active",children:y.field.statusActive}),t.jsx("option",{value:"Inactive",children:y.field.statusInactive})]})]})]})})]})}function a1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function r1({incidentTypes:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.red})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:a1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function l1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Incident Type: ${e.name1||e.name}`:"Edit Incident Type":"New Incident Type";return t.jsxs(tt,{title:x,activePage:"incident-types",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsx(ce,{title:"Incident Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Incident type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function i1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function o1({ideaTypes:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.teal})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:i1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function d1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Idea Type: ${e.name1||e.name}`:"Edit Idea Type":"New Idea Type";return t.jsxs(tt,{title:x,activePage:"idea-types",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsx(ce,{title:"Idea Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Idea type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function c1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function u1({orderTypes:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.purple})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:c1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function p1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Order Type: ${e.name1||e.name}`:"Edit Order Type":"New Order Type";return t.jsxs(tt,{title:x,activePage:"order-types",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsx(ce,{title:"Order Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Order type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function f1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function h1({processTypes:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.blue})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:5,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:f1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function g1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Process Type: ${e.name1||e.name}`:"Edit Process Type":"New Process Type";return t.jsxs(tt,{title:x,activePage:"process-types",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsx(ce,{title:"Process Type Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Process type name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]})})]})}function m1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function x1({incidentStatuses:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.red})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.notifyManager}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?i.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:m1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function y1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Incident Status: ${e.name1||e.name}`:"Edit Incident Status":"New Incident Status";return t.jsxs(tt,{title:x,activePage:"incident-statuses",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsxs(ce,{title:"Incident Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Incident status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:a,onChange:y=>o({notify_manager:y.target.checked?1:0}),style:$a}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:a?"default":"pointer"},children:g.field.notifyManager})]})]})]})}function v1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function j1({ideaStatuses:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.teal})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.notifyManager}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?i.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:v1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function b1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Idea Status: ${e.name1||e.name}`:"Edit Idea Status":"New Idea Status";return t.jsxs(tt,{title:x,activePage:"idea-statuses",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsxs(ce,{title:"Idea Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Idea status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:a,onChange:y=>o({notify_manager:y.target.checked?1:0}),style:$a}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:a?"default":"pointer"},children:g.field.notifyManager})]})]})]})}function S1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function _1({orderStatuses:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.purple})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.notifyManager}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?i.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:S1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function w1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Order Status: ${e.name1||e.name}`:"Edit Order Status":"New Order Status";return t.jsxs(tt,{title:x,activePage:"order-statuses",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsxs(ce,{title:"Order Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Order status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:a,onChange:y=>o({notify_manager:y.target.checked?1:0}),style:$a}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:a?"default":"pointer"},children:g.field.notifyManager})]})]})]})}function k1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function C1({processStatuses:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState("all"),c={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},v=_.useMemo(()=>e.filter(o=>{const h=(o.name1||o.name||"").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j!=="all"&&(o.status||"Active")!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total",val:v.length,color:J.blue})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:"Status",value:j,onChange:w,options:[{value:"all",label:"All"},{value:"Active",label:i.field.statusActive},{value:"Inactive",label:i.field.statusInactive}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:c,children:i.col.name}),t.jsx("th",{style:c,children:i.field.notifyManager}),t.jsx("th",{style:c,children:i.field.creationDate}),t.jsx("th",{style:c,children:i.field.status}),t.jsx("th",{style:c,children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:6,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.name1||o.name||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.notify_manager?i.field.statusActive:"—"}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:k1(o.creation_date)}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{color:o.status==="Inactive"?"#e74c3c":"#16a34a",fontWeight:600},children:o.status==="Inactive"?i.field.statusInactive:i.field.statusActive})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function z1({form:e,setForm:n,formStatus:s,viewMode:a,onEdit:r,onRestore:l,onPermanentDelete:i,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,user:k}){const g=le(),o=y=>n(S=>({...S,...y})),h=a?{background:"#f8fafc"}:{},x=e.name?a?`Process Status: ${e.name1||e.name}`:"Edit Process Status":"New Process Status";return t.jsxs(tt,{title:x,activePage:"process-statuses",user:k,formStatus:s,buttonText:g.saveName,buttonColor:"#16a34a",viewMode:a,onEdit:r,darkMode:d,notifCount:f,onToggleDark:p,onCountChange:C,onViewProfile:j,onSubmit:w,onBack:c,onNavigate:v,onLogout:z,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:l&&e.name?()=>l(e.name):void 0,onPermanentDelete:i&&e.name?()=>i(e.name):void 0}),t.jsxs(ce,{title:"Process Status Details",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[g.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...h},value:e.name1,disabled:a||!!e.name,onChange:y=>o({name1:y.target.value}),placeholder:"Process status name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.creationDate}),t.jsx(je,{value:e.creation_date||"",onChange:y=>o({creation_date:y}),disabled:a,style:{...B,...h}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:g.field.status}),t.jsxs("select",{style:{...B,...h},value:e.status||"Active",disabled:a,onChange:y=>o({status:y.target.value}),children:[t.jsx("option",{value:"Active",children:g.field.statusActive}),t.jsx("option",{value:"Inactive",children:g.field.statusInactive})]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("input",{type:"checkbox",id:"notify_manager",checked:!!e.notify_manager,disabled:a,onChange:y=>o({notify_manager:y.target.checked?1:0}),style:$a}),t.jsx("label",{htmlFor:"notify_manager",style:{fontSize:13,cursor:a?"default":"pointer"},children:g.field.notifyManager})]})]})]})}const I1={Admin:"#7c3aed",Chairman:"#0f766e",Auditor:"#d97706","X-Auditor":"#8b5cf6",Manager:"#2563eb",Employee:"#6b7280"};function E1(e){if(!e)return"—";const n=new Date(e);return`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function T1({users:e,canModify:n,onView:s,onEdit:a,onDisable:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(!1),[j,w]=_.useState(""),[c,v]=_.useState(""),[z,k]=_.useState(""),[g,o]=_.useState("active"),[h,x]=_.useState(1),[y,S]=_.useState(null),[u,b]=_.useState(""),[A,E]=_.useState("idle"),[H,Y]=_.useState(null),ne=async()=>{if(!(!y||!u.trim())){E("loading");try{await ai(y.name,u.trim()),E("success"),setTimeout(()=>{S(null),b(""),E("idle")},1200)}catch{E("error")}}},M=async D=>{if(window.confirm(i.users.disableConfirm)){Y(D);try{await(r==null?void 0:r(D))}finally{Y(null)}}},W=e.filter(D=>{if(g==="active"&&(D.enabled===0||D.enabled==="0")||g==="inactive"&&D.enabled!==0&&D.enabled!=="0")return!1;const O=D.custom_category||"";if(z&&O!==z)return!1;const q=D.custom_organization||"";if(c&&!q.toLowerCase().includes(c.toLowerCase()))return!1;if(j){const se=j.toLowerCase();if(![D.full_name,D.email,D.name,D.username,D.mobile_no].join(" ").toLowerCase().includes(se))return!1}return!0}),N=[...new Set(e.map(D=>D.custom_organization).filter(Boolean))],I=["Admin","Chairman","Auditor","X-Auditor","Manager","Employee"];_.useEffect(()=>{x(1)},[j,c,z,g]);const T=W.slice((h-1)*oe,h*oe);_.useEffect(()=>{if(l){const D=W.filter(O=>d.has(O.name));l(D,T)}},[d,T]);const G={padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:8,fontSize:13,background:"white",width:"100%",fontFamily:"inherit",outline:"none",color:"#374151"},V={...G,cursor:"pointer"};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,flex:1},children:[t.jsxs("div",{style:{background:"white",borderRadius:12,overflow:"hidden",boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:16},children:[t.jsxs("div",{onClick:()=>C(D=>!D),style:{background:"linear-gradient(90deg, #3b82f6 0%, #2563eb 100%)",padding:"12px 18px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",userSelect:"none"},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",children:p?t.jsx("polyline",{points:"18,15 12,9 6,15"}):t.jsx("polyline",{points:"6,9 12,15 18,9"})}),t.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{style:{color:"white",fontWeight:700,fontSize:14},children:"Filters"})]}),p&&t.jsx("div",{style:{padding:"18px 20px",display:"flex",flexDirection:"column",gap:14},children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:14},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Search"}),t.jsx("input",{style:G,placeholder:"Name, email, username…",value:j,onChange:D=>{w(D.target.value),x(1)}})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Organization"}),t.jsxs("select",{style:V,value:c,onChange:D=>{v(D.target.value),x(1)},children:[t.jsx("option",{value:"",children:"All Organizations"}),N.map(D=>t.jsx("option",{value:D,children:D},D))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Category"}),t.jsxs("select",{style:V,value:z,onChange:D=>{k(D.target.value),x(1)},children:[t.jsx("option",{value:"",children:"All Categories"}),I.map(D=>t.jsx("option",{value:D,children:D},D))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#9ca3af",marginBottom:5,textTransform:"uppercase",letterSpacing:.5},children:"Status"}),t.jsxs("select",{style:V,value:g,onChange:D=>{o(D.target.value),x(1)},children:[t.jsx("option",{value:"all",children:"All"}),t.jsx("option",{value:"active",children:"Active"}),t.jsx("option",{value:"inactive",children:"Inactive"})]})]})]})})]}),t.jsx("div",{style:{background:"white",borderRadius:10,border:"1px solid #e5e7eb",overflow:"auto",flex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.05)"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f9fafb",borderBottom:"2px solid #e5e7eb",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"11px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:T.length>0&&T.every(D=>d.has(D.name)),onChange:D=>{if(D.target.checked)f(new Set([...d,...T.map(O=>O.name)]));else{const O=new Set(d);T.forEach(q=>O.delete(q.name)),f(O)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),[{label:"Category",w:110},{label:"Number",w:90},{label:i.col.name,w:160},{label:"Username",w:130},{label:"Email",w:180},{label:"Phone",w:110},{label:i.col.organization,w:140},{label:i.col.management,w:120},{label:i.col.department,w:120},{label:"Branch",w:100},{label:"Since",w:90},{label:"Status",w:80},{label:"Tools",w:200}].map(({label:D,w:O})=>t.jsx("th",{style:{padding:"11px 14px",textAlign:"left",color:"#6b7280",fontSize:11,fontWeight:700,whiteSpace:"nowrap",minWidth:O,letterSpacing:.3,textTransform:"uppercase"},children:D},D))]})}),t.jsx("tbody",{children:W.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:14,style:{padding:"48px 20px",textAlign:"center",color:"#aaa",fontSize:14},children:"No users found"})}):T.map((D,O)=>{const q=D.custom_category||"",se=I1[q]||"#6b7280";return t.jsxs("tr",{onClick:()=>s==null?void 0:s(D),style:{borderBottom:"1px solid #f3f4f6",background:d.has(D.name)?"#eff6ff":O%2===0?"white":"#fafafa",transition:"background 0.1s",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"11px 14px",textAlign:"center"},onClick:ie=>ie.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(D.name),onChange:()=>{const ie=new Set(d);ie.has(D.name)?ie.delete(D.name):ie.add(D.name),f(ie)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:q?t.jsx("span",{style:{background:se+"18",color:se,border:`1px solid ${se}44`,padding:"3px 10px",borderRadius:20,fontSize:11,fontWeight:700},children:q}):t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:D.custom_number||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",fontWeight:600,color:"#1a2332",whiteSpace:"nowrap"},children:D.full_name||D.first_name||"—"}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:D.username||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:D.email||D.name}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:D.mobile_no||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#4b5563",whiteSpace:"nowrap"},children:D.custom_organization||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:D.custom_management||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:D.custom_department||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:D.custom_branch||t.jsx("span",{style:{color:"#d1d5db"},children:"—"})}),t.jsx("td",{style:{padding:"11px 14px",color:"#6b7280",whiteSpace:"nowrap"},children:E1(D.creation)}),t.jsx("td",{style:{padding:"11px 14px",whiteSpace:"nowrap"},children:t.jsx("span",{style:{color:D.enabled?"#16a34a":"#dc2626",fontWeight:600},children:D.enabled?i.users.active:i.users.inactive})}),t.jsx("td",{style:{padding:"10px 14px",whiteSpace:"nowrap"},onClick:ie=>ie.stopPropagation(),children:t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[t.jsx("button",{onClick:ie=>{ie.stopPropagation(),s==null||s(D)},title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),n&&a&&t.jsx("button",{onClick:ie=>{ie.stopPropagation(),a(D)},title:"Edit",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#dcfce7",color:"#16a34a"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),n&&t.jsx("button",{onClick:ie=>{ie.stopPropagation(),S({name:D.name,email:D.email||D.name}),b(""),E("idle")},title:"Set Password",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#fef3c7",color:"#d97706"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),n&&t.jsx("button",{onClick:ie=>{ie.stopPropagation(),M(D.name)},disabled:H===D.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:H===D.name?.5:1},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14H6L5 6"}),t.jsx("path",{d:"M10 11v6M14 11v6"}),t.jsx("path",{d:"M9 6V4h6v2"})]})})]})})]},D.name)})})]})}),t.jsx(Me,{page:h,total:W.length,onPageChange:x}),y&&t.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center"},children:t.jsxs("div",{style:{background:"white",borderRadius:14,padding:32,width:390,boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[t.jsx("div",{style:{fontSize:17,fontWeight:700,marginBottom:6,color:"#1a2332"},children:i.users.setPassword}),t.jsxs("div",{style:{fontSize:13,color:"#6b7280",marginBottom:20},children:["User: ",t.jsx("strong",{children:y.email})]}),t.jsx("input",{type:"password",value:u,onChange:D=>b(D.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:D=>D.key==="Enter"&&ne(),autoFocus:!0}),A==="success"&&t.jsx("div",{style:{color:"#166534",background:"#f0fdf4",border:"1px solid #86efac",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Password updated successfully"}),A==="error"&&t.jsx("div",{style:{color:"#991b1b",background:"#fef2f2",border:"1px solid #fca5a5",borderRadius:6,padding:"8px 12px",marginBottom:12,fontSize:13},children:"Failed to update password"}),t.jsxs("div",{style:{display:"flex",gap:10},children:[t.jsx("button",{onClick:ne,disabled:A==="loading"||!u.trim(),style:{flex:1,padding:10,background:"#2563eb",color:"white",border:"none",borderRadius:8,cursor:"pointer",fontSize:13,fontWeight:700,fontFamily:"inherit",opacity:u.trim()?1:.5},children:A==="loading"?"Saving…":i.users.setPassword}),t.jsx("button",{onClick:()=>{S(null),b(""),E("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})]})]})})]})}function A1({form:e,setForm:n,groupCompanies:s=[],organizations:a,managements:r,departments:l,branches:i,users:d=[],formStatus:f,viewMode:p,onEdit:C,onRestore:j,onPermanentDelete:w,darkMode:c,notifCount:v,onToggleDark:z,onCountChange:k,onViewProfile:g,isSelfProfile:o,onSubmit:h,onBack:x,onNavigate:y,onLogout:S,user:u}){const b=le(),A=O=>n(q=>({...q,...O})),E=p?{background:"#f8fafc"}:{},H=s.filter(O=>!nt(O)).map(O=>({...O,name:O.name,label:O.company_name||O.name})),Y=e.custom_organization?r.filter(O=>!nt(O)&&(!O.organization||O.organization===e.custom_organization)):r.filter(O=>!nt(O)),ne=l.filter(O=>!(nt(O)||e.custom_organization&&O.custom_organization&&O.custom_organization!==e.custom_organization||e.custom_management&&O.custom_management&&O.custom_management!==e.custom_management)),M=i.filter(O=>!(nt(O)||e.custom_organization&&O.organization&&O.organization!==e.custom_organization||e.custom_management&&O.management&&O.management!==e.custom_management||e.custom_department&&O.department&&O.department!==e.custom_department)),W=Se(Y,e.custom_management).map(O=>({...O,name:O.name,label:O.name1||O.name})),N=Se(ne,e.custom_department).map(O=>({...O,name:O.name,label:O.department_name||O.name})),I=Se(M,e.custom_branch).map(O=>({...O,name:O.name,label:O.branch||O.name})),T=d.filter(O=>{if(!O||nt(O)||O.enabled===0||O.enabled===!1||O.name===e.name)return!1;const q=O.custom_category||"",se=q==="CEO"||q==="Chairman"||q==="Business Owner"||O.name==="Administrator";return e.custom_organization&&O.custom_organization&&O.custom_organization!==e.custom_organization&&!se?!1:e.custom_category==="Admin"?q==="CEO"||q==="Chairman"||q==="Business Owner"||O.name==="Administrator":e.custom_category==="Manager"?q==="Admin":e.custom_category==="Auditor"||e.custom_category==="X-Auditor"?q==="Manager"||q==="Admin"||q==="Business Owner":e.custom_category==="Employee"?q==="Auditor"||q==="X-Auditor"||q==="Manager":!(e.custom_category==="CEO"||e.custom_category==="Chairman"||e.custom_category==="Business Owner")}),G=!e.name||e.name.startsWith("new-user-"),V=o?b.formTitle.viewUser:G?b.formTitle.newUser:b.formTitle.editUser,D=O=>{if(O&&O.preventDefault(),!e.first_name){alert(b.field.fullName+" is required");return}if(G&&!e.email){alert(b.field.emailAddress+" is required");return}const q=e.custom_group_company||u.custom_group_company;if(!q){alert("Group Company (Tenant) is required");return}if(!e.custom_organization){alert(b.field.organization+" is required");return}if(!e.custom_category){alert(b.field.category+" is required");return}if(e.custom_category&&e.custom_category!=="CEO"&&e.custom_category!=="Chairman"&&e.custom_category!=="Business Owner"&&!e.custom_manager){alert("Reports To / Supervisor is mandatory.");return}!e.custom_group_company&&q&&A({custom_group_company:q}),h()};return t.jsxs(tt,{title:V,activePage:"users",user:u,formStatus:f,buttonText:b.saveUser,buttonColor:"#16a34a",viewMode:p,onEdit:C,darkMode:c,notifCount:v,onToggleDark:z,onCountChange:k,onViewProfile:g,onSubmit:D,onBack:x,onNavigate:y,onLogout:S,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:j&&e.name?()=>j(e.name):void 0,onPermanentDelete:w&&e.name?()=>w(e.name):void 0}),t.jsx(ce,{title:"User Organization & Assignment",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[(u.role==="Admin"||u.role==="CEO")&&!u.custom_group_company&&t.jsxs("div",{children:[t.jsxs("label",{style:R,children:["Group Company (Tenant) ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(xe,{value:e.custom_group_company||"",onChange:O=>A({custom_group_company:O}),items:H,placeholder:"-- Select Group Company --",disabled:p,userRole:u.role,doctypeName:P.groupCompanies})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[b.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.custom_organization,onChange:O=>A({custom_organization:O,custom_management:"",custom_department:"",custom_branch:"",custom_manager:""}),organizations:a,disabled:p,userRole:u.role})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:b.field.management}),t.jsx(xe,{value:e.custom_management,onChange:O=>A({custom_management:O,custom_department:"",custom_branch:""}),items:W,placeholder:"-- Select --",disabled:p,userRole:u.role,doctypeName:P.managements,extraFields:{organization:e.custom_organization}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:b.field.department}),t.jsx(xe,{value:e.custom_department,onChange:O=>A({custom_department:O,custom_branch:""}),items:N,placeholder:"-- Select --",disabled:p,userRole:u.role,doctypeName:P.departments,extraFields:{organization:e.custom_organization,management:e.custom_management}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:b.field.branch}),t.jsx(xe,{value:e.custom_branch,onChange:O=>A({custom_branch:O}),items:I,placeholder:"-- Select --",disabled:p,userRole:u.role,doctypeName:P.branches,extraFields:{organization:e.custom_organization,management:e.custom_management,department:e.custom_department}})]})]})}),t.jsx(ce,{title:"User Profile Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:b.field.number}),t.jsx("input",{style:{...B,...E},value:e.custom_number,disabled:p,onChange:O=>A({custom_number:O.target.value}),placeholder:"e.g. 10001"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[b.field.fullName," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...E},value:e.first_name,disabled:p,onChange:O=>A({first_name:O.target.value}),placeholder:"Full name",required:!0})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:b.field.username}),t.jsx("input",{style:{...B,...E},value:e.username,disabled:p,onChange:O=>A({username:O.target.value}),placeholder:"Username"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:b.field.phoneNumber}),t.jsx("input",{style:{...B,...E},value:e.mobile_no,disabled:p,onChange:O=>A({mobile_no:O.target.value}),placeholder:"Phone number"})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[b.field.emailAddress," ",G&&t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...p||!G?{background:"#f8fafc"}:{}},value:e.email,disabled:p||!G,onChange:O=>A({email:O.target.value}),placeholder:"user@example.com",type:"email",required:G})]}),G&&t.jsxs("div",{children:[t.jsxs("label",{style:R,children:["Password ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...E},type:"password",value:e.new_password||"",disabled:p,onChange:O=>A({new_password:O.target.value}),placeholder:"Initial password",required:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[b.field.category," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsxs("select",{style:{...B,...E},value:e.custom_category,disabled:p,onChange:O=>{const q=O.target.value;A({custom_category:q,custom_manager:""})},children:[t.jsx("option",{value:"",children:b.field.select}),(()=>{const O=u.role==="Admin",se=u.role==="Business Owner"||u.role==="Owner"?["CEO","Auditor","X-Auditor"]:O?["Admin","Auditor","X-Auditor","Manager","Employee"]:["Admin","Business Owner","CEO","Chairman","Auditor","X-Auditor","Manager","Employee"];return Array.from(new Set([...se,e.custom_category])).filter(Boolean).map(ke=>t.jsx("option",{value:ke,children:ke},ke))})()]})]}),e.custom_category!=="CEO"&&e.custom_category!=="Chairman"&&e.custom_category!=="Business Owner"&&t.jsxs("div",{children:[t.jsxs("label",{style:R,children:["Reports To / Supervisor"," ",e.custom_category&&t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsxs("select",{style:{...B,...E,...e.custom_category?{}:{background:"#f1f5f9",cursor:"not-allowed",color:"#94a3b8"}},value:e.custom_manager||"",disabled:p||!e.custom_category,onChange:O=>A({custom_manager:O.target.value}),required:!!e.custom_category,children:[t.jsx("option",{value:""}),T.map(O=>{const q=O.full_name||O.email||O.name,se=O.custom_category?` [${O.custom_category}]`:"";return t.jsxs("option",{value:O.name,children:[q,se]},O.name)})]})]})]})})]})}const Uu={Active:J.green,Closed:J.gray};function P1({cycles:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState(""),[c,v]=_.useState("all"),z=_.useMemo(()=>[...new Set(e.map(S=>S.organization).filter(Boolean))],[e]),k=_.useMemo(()=>e.filter(S=>{const u=(S.name1||S.name||"").toLowerCase();return!(p&&!u.includes(p.toLowerCase())||j&&S.organization!==j||c!=="all"&&S.status!==c)}),[e,p,j,c]),[g,o]=_.useState(1);_.useEffect(()=>{o(1)},[p,j,c]);const h=k.slice((g-1)*oe,g*oe);_.useEffect(()=>{if(l){const S=e.filter(u=>d.has(u.name));l(S,h)}},[d,h]);const x=k.filter(S=>S.status==="Active").length,y=k.filter(S=>S.status==="Closed").length;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Oe,{label:"Total",val:k.length,color:J.teal}),t.jsx(Oe,{label:"Active",val:x,color:J.green}),t.jsx(Oe,{label:"Closed",val:y,color:J.gray})]}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Search by name…"},{type:"select",label:i.col.organization,value:j,onChange:w,options:[{value:"",label:"All Organizations"},...z.map(S=>({value:S,label:S}))]},{type:"select",label:"Status",value:c,onChange:v,options:[{value:"all",label:"All"},{value:"Active",label:"Active"},{value:"Closed",label:"Closed"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:h.length>0&&h.every(S=>d.has(S.name)),onChange:S=>{if(S.target.checked)f(new Set([...d,...h.map(u=>u.name)]));else{const u=new Set(d);h.forEach(b=>u.delete(b.name)),f(u)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.name}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.organization}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.frequency}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.startDate}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.endDate}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.status}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.actions})]})}),t.jsx("tbody",{children:k.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:8,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):h.map((S,u)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(S),style:{borderTop:"1px solid #f0f0f0",background:d.has(S.name)?"#eff6ff":S.custom_is_deleted?"#fff1f2":u%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:b=>b.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(S.name),onChange:()=>{const b=new Set(d);b.has(S.name)?b.delete(S.name):b.add(S.name),f(b)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:S.name1||S.name}),t.jsx("td",{style:{padding:"10px 14px"},children:S.organization||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:S.frequency||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:S.start_date||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:S.end_date||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:S.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):t.jsx("span",{style:{padding:"3px 10px",borderRadius:12,fontSize:12,background:Uu[S.status]+"22",color:Uu[S.status]||"#666"},children:S.status})}),t.jsx("td",{style:{padding:"8px 14px"},onClick:b=>b.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(S),onEdit:n&&a&&!S.custom_is_deleted?()=>a(S):void 0,onDelete:n&&r&&!S.custom_is_deleted?()=>r(S.name):void 0})})]},S.name))})]})}),t.jsx(Me,{page:g,total:k.length,onPageChange:o})]})}const R1=["Weekly","Bi-weekly","Monthly","Quarterly","Annually"],O1=["Active","Closed"];function D1({form:e,setForm:n,organizations:s,groupCompanies:a=[],formStatus:r,viewMode:l,onEdit:i,onRestore:d,onPermanentDelete:f,darkMode:p,notifCount:C,onToggleDark:j,onCountChange:w,onViewProfile:c,onSubmit:v,onBack:z,onNavigate:k,onLogout:g,user:o}){const h=le(),x=u=>n(b=>({...b,...u})),y=l?{background:"#f8fafc"}:{},S=e.name?l?`${h.formTitle.editCycle}: ${e.name1||e.name}`:h.formTitle.editCycle:h.formTitle.newCycle;return t.jsxs(tt,{title:S,activePage:"cycles",user:o,formStatus:r,buttonText:h.saveCycle,buttonColor:"#16a34a",viewMode:l,onEdit:i,darkMode:p,notifCount:C,onToggleDark:j,onCountChange:w,onViewProfile:c,onSubmit:v,onBack:z,onNavigate:k,onLogout:g,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:d&&e.name?()=>d(e.name):void 0,onPermanentDelete:f&&e.name?()=>f(e.name):void 0}),t.jsx(ce,{title:"Cycle Details",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:u=>{var A;const b=(A=s.find(E=>E.name===u))==null?void 0:A.group_company;x({organization:u,...o.custom_group_company?{}:{group_company:b||e.group_company}})},organizations:s,disabled:l||!!o.custom_organization,userRole:o.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.name1," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...y},value:e.name1||"",disabled:l||!!e.name,onChange:u=>x({name1:u.target.value}),placeholder:"e.g. Q1-2026"})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.col.frequency}),t.jsx(xe,{value:e.frequency,onChange:u=>x({frequency:u}),items:R1.map(u=>({name:u,label:u})),placeholder:"-- Select Frequency --",disabled:l})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.status}),t.jsx(xe,{value:e.status,onChange:u=>x({status:u}),items:O1.map(u=>({name:u,label:u})),placeholder:"-- Select Status --",disabled:l})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.dateStart}),t.jsx(je,{value:e.start_date||"",onChange:u=>x({start_date:u}),disabled:l,style:{...B,...y}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.dateEnd}),t.jsx(je,{value:e.end_date||"",onChange:u=>x({end_date:u}),disabled:l,style:{...B,...y}})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.updateWindowDays}),t.jsx("input",{type:"number",min:1,max:30,style:{...B,...y},value:e.update_window_days??2,disabled:l,onChange:u=>x({update_window_days:parseInt(u.target.value)||2})}),t.jsx("span",{style:{fontSize:11,color:"#64748b",display:"block",marginTop:4},children:"Grace period before Unknown is auto-assigned"})]})]})})]})}function B1({kpiInputs:e,canModify:n,onView:s,onEdit:a,onDelete:r,onSelectionChange:l}){const i=le(),[d,f]=_.useState(new Set),[p,C]=_.useState(""),[j,w]=_.useState(""),c=_.useMemo(()=>[...new Set(e.map(o=>o.organization).filter(Boolean))],[e]),v=_.useMemo(()=>e.filter(o=>{const h=[o.organization,o.period].filter(Boolean).join(" ").toLowerCase();return!(p&&!h.includes(p.toLowerCase())||j&&o.organization!==j)}),[e,p,j]),[z,k]=_.useState(1);_.useEffect(()=>{k(1)},[p,j]);const g=v.slice((z-1)*oe,z*oe);return _.useEffect(()=>{if(l){const o=e.filter(h=>d.has(h.name));l(o,g)}},[d,g]),t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",gap:16},children:t.jsx(Oe,{label:"Total Records",val:v.length,color:J.blue})}),t.jsx(St,{filters:[{type:"search",label:"Search",value:p,onChange:C,placeholder:"Organization or period…"},{type:"select",label:i.col.organization,value:j,onChange:w,options:[{value:"",label:"All Organizations"},...c.map(o=>({value:o,label:o}))]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:g.length>0&&g.every(o=>d.has(o.name)),onChange:o=>{if(o.target.checked)f(new Set([...d,...g.map(h=>h.name)]));else{const h=new Set(d);g.forEach(x=>h.delete(x.name)),f(h)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.organization}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.period}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.field.revenue_growth}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.field.net_profit}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.dash.customerSat}),t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},children:i.col.actions})]})}),t.jsx("tbody",{children:v.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:7,style:{padding:40,textAlign:"center",color:"#aaa"},children:i.noData})}):g.map((o,h)=>t.jsxs("tr",{className:"app-table-row",onClick:()=>s==null?void 0:s(o),style:{borderTop:"1px solid #f0f0f0",background:d.has(o.name)?"#eff6ff":o.custom_is_deleted?"#fff1f2":h%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:x=>x.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:d.has(o.name),onChange:()=>{const x=new Set(d);x.has(o.name)?x.delete(o.name):x.add(o.name),f(x)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:o.organization||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.period||"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.revenue_growth!=null?`${o.revenue_growth}%`:"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.net_profit!=null?o.net_profit.toLocaleString():"—"}),t.jsx("td",{style:{padding:"10px 14px"},children:o.custom_is_deleted?t.jsx("span",{style:{background:"#fee2e2",color:"#991b1b",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:700},children:i.deletedBadge}):o.customer_satisfaction!=null?o.customer_satisfaction:"—"}),t.jsx("td",{style:{padding:"8px 14px"},onClick:x=>x.stopPropagation(),children:t.jsx(dt,{onView:()=>s==null?void 0:s(o),onEdit:n&&a&&!o.custom_is_deleted?()=>a(o):void 0,onDelete:n&&r&&!o.custom_is_deleted?()=>r(o.name):void 0})})]},o.name))})]})}),t.jsx(Me,{page:z,total:v.length,onPageChange:k})]})}function L1({form:e,setForm:n,organizations:s,groupCompanies:a=[],formStatus:r,viewMode:l,onEdit:i,onRestore:d,onPermanentDelete:f,darkMode:p,notifCount:C,onToggleDark:j,onCountChange:w,onViewProfile:c,onSubmit:v,onBack:z,onNavigate:k,onLogout:g,user:o}){const h=le(),x=b=>n(A=>({...A,...b})),y=l?{background:"#f8fafc"}:{},S=b=>A=>x({[b]:parseFloat(A.target.value)||0}),u=e.name?l?`${h.formTitle.editKpi}: ${e.period||e.name}`:h.formTitle.editKpi:h.formTitle.newKpi;return t.jsxs(tt,{title:u,activePage:"kpi-input",user:o,formStatus:r,buttonText:h.saveKpi,buttonColor:"#16a34a",viewMode:l,onEdit:i,darkMode:p,notifCount:C,onToggleDark:j,onCountChange:w,onViewProfile:c,onSubmit:v,onBack:z,onNavigate:k,onLogout:g,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:d&&e.name?()=>d(e.name):void 0,onPermanentDelete:f&&e.name?()=>f(e.name):void 0}),t.jsx(ce,{title:"Period & Organization",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.field.organization," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(ln,{value:e.organization,onChange:b=>{var E;const A=(E=s.find(H=>H.name===b))==null?void 0:E.group_company;x({organization:b,...o.custom_group_company?{}:{group_company:A||e.group_company}})},organizations:s,disabled:l||!!o.custom_organization,userRole:o.role})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[h.col.period," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx("input",{style:{...B,...y},value:e.period||"",disabled:l,onChange:b=>x({period:b.target.value}),placeholder:"e.g. Q1 2026"})]})]})}),t.jsx(ce,{title:"Financial KPIs",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.revenue_growth}),t.jsx("input",{type:"number",step:"0.01",style:{...B,...y},value:e.revenue_growth||"",disabled:l,onChange:S("revenue_growth")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.net_profit}),t.jsx("input",{type:"number",step:"0.01",style:{...B,...y},value:e.net_profit||"",disabled:l,onChange:S("net_profit")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.cash_flow}),t.jsx("input",{type:"number",step:"0.01",style:{...B,...y},value:e.cash_flow||"",disabled:l,onChange:S("cash_flow")})]})]})}),t.jsx(ce,{title:"Operational KPIs",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.strategic_goal_pct}),t.jsx("input",{type:"number",step:"0.01",style:{...B,...y},value:e.strategic_goal_pct||"",disabled:l,onChange:S("strategic_goal_pct")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.customer_satisfaction}),t.jsx("input",{type:"number",step:"0.01",style:{...B,...y},value:e.customer_satisfaction||"",disabled:l,onChange:S("customer_satisfaction")})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.employee_turnover_pct}),t.jsx("input",{type:"number",step:"0.01",style:{...B,...y},value:e.employee_turnover_pct||"",disabled:l,onChange:S("employee_turnover_pct")})]})]})}),t.jsx(ce,{title:"Safety & Compliance",children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:16},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.open_safety_incidents}),t.jsx("input",{type:"number",min:0,style:{...B,...y},value:e.open_safety_incidents||"",disabled:l,onChange:b=>x({open_safety_incidents:parseInt(b.target.value)||0})})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:h.field.compliance_score}),t.jsx("input",{type:"number",step:"0.01",style:{...B,...y},value:e.compliance_score||"",disabled:l,onChange:S("compliance_score")})]})]})})]})}const W1={incident_initial_evaluation:"Incident Initial Evaluation",idea_initial_evaluation:"Idea Initial Evaluation"},Mu={Pending:J.orange,Accepted:J.green,Rejected:J.red,Revoked:J.gray};function N1(e){if(!e)return"—";const n=new Date(e);return isNaN(n.getTime())?"—":`${String(n.getDate()).padStart(2,"0")}/${String(n.getMonth()+1).padStart(2,"0")}/${n.getFullYear()}`}function $1(e){const n=[];return e.incident_initial_evaluation&&n.push("incident_initial_evaluation"),e.idea_initial_evaluation&&n.push("idea_initial_evaluation"),n}function U1({delegations:e,organizations:n,userRole:s,currentUser:a,onView:r,onRevoke:l,onSelectionChange:i}){const d=le(),[f,p]=_.useState(new Set),[C,j]=_.useState(""),[w,c]=_.useState(""),[v,z]=_.useState("all"),k={padding:"10px 14px",textAlign:"left",color:"#999",fontSize:10,fontWeight:700},g=_.useMemo(()=>e.filter(u=>{if(u.custom_is_deleted===1||u.custom_is_deleted==="1"||u.custom_is_deleted===!0||u.is_deleted===1||u.status==="Deleted")return!1;const b=`${u.auditor} ${u.manager}`.toLowerCase();return!(C&&!b.includes(C.toLowerCase())||w&&u.organization!==w||v!=="all"&&u.status!==v)}),[e,C,w,v]),[o,h]=_.useState(1);_.useEffect(()=>{h(1)},[C,w,v]);const x=g.slice((o-1)*oe,o*oe);_.useEffect(()=>{if(i){const u=e.filter(b=>f.has(b.name));i(u,x)}},[f,x]);const y=g.filter(u=>u.status==="Pending").length,S=g.filter(u=>u.status==="Accepted").length;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(Oe,{label:"Total",val:g.length,color:J.purple}),t.jsx(Oe,{label:"Pending",val:y,color:J.orange}),t.jsx(Oe,{label:"Accepted",val:S,color:J.green})]}),t.jsx(St,{filters:[{type:"search",label:"Search",value:C,onChange:j,placeholder:"Auditor or Manager…"},{type:"select",label:d.col.organization,value:w,onChange:c,options:[{value:"",label:"All Organizations"},...n.map(u=>({value:u.organization_name||u.name,label:u.organization_name||u.name}))]},{type:"select",label:"Status",value:v,onChange:z,options:[{value:"all",label:"All"},{value:"Pending",label:"Pending"},{value:"Accepted",label:"Accepted"},{value:"Rejected",label:"Rejected"},{value:"Revoked",label:"Revoked"}]}]}),t.jsx("div",{style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto",flex:1},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8f9fa",position:"sticky",top:0},children:[t.jsx("th",{style:{width:40,padding:"10px 14px",textAlign:"center"},children:t.jsx("input",{type:"checkbox",checked:x.length>0&&x.every(u=>f.has(u.name)),onChange:u=>{if(u.target.checked)p(new Set([...f,...x.map(b=>b.name)]));else{const b=new Set(f);x.forEach(A=>b.delete(A.name)),p(b)}},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("th",{style:k,children:d.col.number}),t.jsx("th",{style:k,children:d.col.auditor}),t.jsx("th",{style:k,children:d.col.manager}),t.jsx("th",{style:k,children:d.col.organization}),t.jsx("th",{style:k,children:d.col.functions}),t.jsx("th",{style:k,children:d.col.status}),t.jsx("th",{style:k,children:d.col.requestedOn}),t.jsx("th",{style:k,children:d.col.actions})]})}),t.jsx("tbody",{children:g.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:9,style:{padding:40,textAlign:"center",color:"#aaa"},children:d.noData})}):x.map((u,b)=>{const A=!!l&&(u.status==="Pending"||u.status==="Accepted")&&(s==="Admin"||u.auditor===a);return t.jsxs("tr",{className:"app-table-row",onClick:()=>r==null?void 0:r(u),style:{borderTop:"1px solid #f0f0f0",background:f.has(u.name)?"#eff6ff":b%2===0?"white":"#fafafa",cursor:"pointer"},children:[t.jsx("td",{style:{width:40,padding:"10px 14px",textAlign:"center"},onClick:E=>E.stopPropagation(),children:t.jsx("input",{type:"checkbox",checked:f.has(u.name),onChange:()=>{const E=new Set(f);E.has(u.name)?E.delete(u.name):E.add(u.name),p(E)},style:{width:15,height:15,cursor:"pointer",accentColor:"#2563eb"}})}),t.jsx("td",{style:{padding:"10px 14px",fontWeight:600},children:u.number||u.name}),t.jsx("td",{style:{padding:"10px 14px"},children:u.auditor}),t.jsx("td",{style:{padding:"10px 14px"},children:u.manager}),t.jsx("td",{style:{padding:"10px 14px"},children:u.organization||"All Organizations"}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:$1(u).map(E=>t.jsx("span",{style:{background:"#ede9fe",color:"#6d28d9",padding:"2px 8px",borderRadius:10,fontSize:11,fontWeight:600},children:W1[E]||E},E))})}),t.jsx("td",{style:{padding:"10px 14px"},children:t.jsx("span",{style:{background:(Mu[u.status]||J.gray)+"22",color:Mu[u.status]||J.gray,padding:"3px 10px",borderRadius:12,fontSize:12,fontWeight:700},children:u.status})}),t.jsx("td",{style:{padding:"10px 14px",color:"#666"},children:N1(u.requested_on)}),t.jsx("td",{style:{padding:"8px 14px"},onClick:E=>E.stopPropagation(),children:t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{onClick:()=>r==null?void 0:r(u),title:"View",style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"none",cursor:"pointer",background:"#e0f7fa",color:"#0891b2"},children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),A&&t.jsx("button",{onClick:()=>l==null?void 0:l(u.name),title:"Revoke",style:{padding:"0 12px",height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:"none",cursor:"pointer",background:"#fee2e2",color:"#ef4444",fontSize:12,fontWeight:700},children:"Revoke"})]})})]},u.name)})})]})}),t.jsx(Me,{page:o,total:g.length,onPageChange:h})]})}const vo={Pending:J.orange,Accepted:J.green,Rejected:J.red,Revoked:J.gray};function M1(e){if(!e)return"—";const n=new Date(e);return isNaN(n.getTime())?"—":n.toLocaleString()}function F1({form:e,setForm:n,organizations:s,users:a,userRoleMap:r,incidents:l=[],ideas:i=[],formStatus:d,viewMode:f,onEdit:p,onRestore:C,onPermanentDelete:j,darkMode:w,notifCount:c,onToggleDark:v,onCountChange:z,onViewProfile:k,onSubmit:g,onBack:o,onNavigate:h,onLogout:x,user:y}){var ne;const S=le(),u=M=>n(W=>({...W,...M})),b=f?{background:"#f8fafc"}:{},A=Na(a,r,"SB Manager",e.organization).filter(M=>!nt(M)&&M.name!==y.name).map(M=>({...M,name:M.name,label:M.full_name||M.name})),E=(l||[]).filter(M=>!nt(M)&&(!e.organization||M.organization===e.organization)&&(M.workflow_state==="Initial Evaluation"||M.status==="Initial Evaluation")).map(M=>({...M,name:M.name,label:`${M.number||M.name} — ${M.title}`})),H=(i||[]).filter(M=>!nt(M)&&(!e.organization||M.organization===e.organization)&&(M.workflow_state==="Initial Evaluation"||M.status==="Initial Evaluation")).map(M=>({...M,name:M.name,label:`${M.number||M.name} — ${M.title}`})),Y=e.name?`${S.formTitle.viewDelegation}${e.name}`:S.formTitle.newDelegation;return t.jsxs(tt,{title:Y,activePage:"delegations",user:y,formStatus:d,statusBadge:e.status?t.jsx("span",{style:{display:"inline-block",padding:"3px 10px",borderRadius:20,fontSize:12,fontWeight:700,background:`${vo[e.status]||J.gray}18`,color:vo[e.status]||J.gray,border:`1px solid ${vo[e.status]||J.gray}40`},children:e.status}):void 0,buttonText:S.saveDelegation,buttonColor:"#16a34a",viewMode:f,onEdit:p,darkMode:w,notifCount:c,onToggleDark:v,onCountChange:z,onViewProfile:k,onSubmit:g,onBack:o,onNavigate:h,onLogout:x,children:[e.custom_is_deleted===1&&t.jsx(et,{deletedBy:e.custom_deleted_by,deletedOn:e.custom_deleted_on,reason:e.custom_deleted_reason,onRestore:C&&e.name?()=>C(e.name):void 0,onPermanentDelete:j&&e.name?()=>j(e.name):void 0}),e.status==="Revoked"&&t.jsxs("div",{style:{padding:"10px 14px",borderRadius:8,background:"#f8fafc",border:"1px solid #cbd5e1",color:"#475569",fontSize:13,fontWeight:600,marginBottom:14,display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontSize:16},children:"🚫"})," This delegation has been Revoked and is closed for further edits or re-delegation."]}),t.jsxs(ce,{title:"Delegation Information",children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:16,marginBottom:14},children:[t.jsxs("div",{children:[t.jsx("label",{style:R,children:S.col.auditor}),t.jsx("input",{style:{...B,background:"#f8fafc",fontWeight:600,color:"#334155"},value:e.auditor||y.name,disabled:!0})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[S.col.manager," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsx(xe,{value:e.manager,onChange:M=>u({manager:M}),items:A,placeholder:"-- Select Manager --",disabled:f})]}),t.jsxs("div",{children:[t.jsx("label",{style:R,children:S.col.organization}),t.jsx(ln,{value:e.organization,onChange:M=>u({organization:M,incident_name:"",idea_name:""}),organizations:s,placeholder:"-- All Organizations --",disabled:f,userRole:y.role})]})]}),t.jsxs("div",{children:[t.jsxs("label",{style:R,children:[S.col.functions," ",t.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,marginTop:6},children:[t.jsxs("div",{className:`delegation-func-box ${e.incident_initial_evaluation?"checked":""}`,children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:f?"default":"pointer",fontSize:13,fontWeight:600},children:[t.jsx("input",{type:"checkbox",style:$a,checked:!!e.incident_initial_evaluation,disabled:f,onChange:M=>u({incident_initial_evaluation:M.target.checked?1:0,incident_name:M.target.checked?e.incident_name:""})}),t.jsx("span",{className:"func-title",children:"Initial Evaluation (Incidents)"})]}),!!e.incident_initial_evaluation&&t.jsxs("div",{style:{marginTop:10},children:[t.jsxs("label",{style:{...R,fontSize:11},className:"func-sublabel",children:["Specific Incident ",t.jsx("span",{style:{fontWeight:400},className:"func-hint",children:"(optional — leave blank to delegate all)"})]}),f?t.jsx("input",{style:{...B,background:"#f8fafc"},value:e.incident_name||"— All Incidents in Initial Evaluation",readOnly:!0,disabled:!0}):t.jsx(xe,{value:e.incident_name||"",onChange:M=>u({incident_name:M}),items:E,placeholder:`-- Any Incident in Initial Evaluation (${E.length} available) --`,disabled:f})]})]}),t.jsxs("div",{className:`delegation-func-box ${e.idea_initial_evaluation?"checked":""}`,children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:f?"default":"pointer",fontSize:13,fontWeight:600},children:[t.jsx("input",{type:"checkbox",style:$a,checked:!!e.idea_initial_evaluation,disabled:f,onChange:M=>u({idea_initial_evaluation:M.target.checked?1:0,idea_name:M.target.checked?e.idea_name:""})}),t.jsx("span",{className:"func-title",children:"Initial Evaluation (Ideas)"})]}),!!e.idea_initial_evaluation&&t.jsxs("div",{style:{marginTop:10},children:[t.jsxs("label",{style:{...R,fontSize:11},className:"func-sublabel",children:["Specific Idea ",t.jsx("span",{style:{fontWeight:400},className:"func-hint",children:"(optional — leave blank to delegate all)"})]}),f?t.jsx("input",{style:{...B,background:"#f8fafc"},value:e.idea_name||"— All Ideas in Initial Evaluation",readOnly:!0,disabled:!0}):t.jsx(xe,{value:e.idea_name||"",onChange:M=>u({idea_name:M}),items:H,placeholder:`-- Any Idea in Initial Evaluation (${H.length} available) --`,disabled:f})]})]})]})]}),!f&&t.jsxs("div",{style:{marginTop:14},children:[t.jsx("label",{style:R,children:"Remarks"}),t.jsx("textarea",{style:{...B,...b,minHeight:70,resize:"vertical"},value:e.remarks||"",onChange:M=>u({remarks:M.target.value}),placeholder:"Optional note for the Manager…"})]})]}),f&&(((ne=e.delegation_log)==null?void 0:ne.length)??0)>0&&t.jsx(ce,{title:"Audit Trail",children:t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"#f8fafc"},children:[t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Action"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Actor"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Timestamp"}),t.jsx("th",{style:{padding:"8px 12px",textAlign:"left",color:"#475569",fontSize:11,fontWeight:700,borderBottom:"1px solid #e2e8f0"},children:"Remarks"})]})}),t.jsx("tbody",{children:(e.delegation_log||[]).map((M,W)=>t.jsxs("tr",{style:{borderBottom:"1px solid #f1f5f9"},children:[t.jsx("td",{style:{padding:"8px 12px",fontWeight:600,color:"#334155"},children:M.action}),t.jsx("td",{style:{padding:"8px 12px",color:"#334155"},children:M.actor}),t.jsx("td",{style:{padding:"8px 12px",color:"#64748b"},children:M1(M.timestamp)}),t.jsx("td",{style:{padding:"8px 12px",color:"#64748b"},children:M.remarks||"—"})]},M.name||W))})]})})})]})}const Fu={process:"processes-form",order:"orders-form",incident:"incidents-form",idea:"ideas-form"},H1={process:"#3b82f6",order:"#8b5cf6",incident:"#ef4444",idea:"#10b981",delegation:"#f59e0b"},G1={process:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",order:"linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%)",incident:"linear-gradient(135deg, #ef4444 0%, #b91c1c 100%)",idea:"linear-gradient(135deg, #10b981 0%, #047857 100%)",delegation:"linear-gradient(135deg, #f59e0b 0%, #b45309 100%)"},Q1={process:"⚙️",order:"📦",incident:"🚨",idea:"💡",delegation:"🤝"};function K1({onNavigate:e,onRefresh:n}){const[s,a]=_.useState([]),[r,l]=_.useState(!0),[i,d]=_.useState(""),[f,p]=_.useState(""),[C,j]=_.useState(""),[w,c]=_.useState("all"),[v,z]=_.useState(1),k=()=>{l(!0),Ky().then(y=>{a(y||[]),l(!1)}).catch(()=>l(!1))};_.useEffect(()=>{k()},[]);const g=_.useMemo(()=>{const y={all:s.length,action:0,info:0};for(const S of s)S.requires_action?y.action=(y.action||0)+1:y.info=(y.info||0)+1,y[S.type]=(y[S.type]||0)+1;return y},[s]),o=_.useMemo(()=>s.filter(y=>{if(w==="action"&&!y.requires_action||w==="info"&&y.requires_action||w!=="all"&&w!=="action"&&w!=="info"&&y.type!==w)return!1;if(C.trim()){const S=C.toLowerCase();if(![y.number,y.title,y.action,y.organization,y.type].filter(Boolean).join(" ").toLowerCase().includes(S))return!1}return!0}),[s,w,C]);_.useEffect(()=>{z(1)},[w,C]);const h=o.slice((v-1)*oe,v*oe),x=async(y,S)=>{d(y),p("");try{await Yy(y,S),await k(),n==null||n()}catch{p(y)}finally{d("")}};return t.jsxs("div",{style:{maxWidth:1100,margin:"0 auto",display:"flex",flexDirection:"column",gap:20},children:[t.jsxs("div",{style:{background:"linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e293b 100%)",borderRadius:16,padding:"24px 28px",color:"#ffffff",boxShadow:"0 10px 25px -5px rgba(30, 27, 75, 0.25), 0 8px 10px -6px rgba(30, 27, 75, 0.2)",display:"flex",flexDirection:"column",gap:18,position:"relative",overflow:"hidden"},children:[t.jsx("div",{style:{position:"absolute",top:-40,right:-40,width:180,height:180,borderRadius:"50%",background:"radial-gradient(circle, rgba(99, 102, 241, 0.35) 0%, transparent 70%)",pointerEvents:"none"}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:14},children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx("span",{style:{fontSize:24},children:"📬"}),t.jsx("h2",{style:{fontSize:20,fontWeight:800,color:"#ffffff",margin:0,letterSpacing:"-0.3px"},children:"Unified Activity Inbox"})]}),t.jsx("p",{style:{margin:"4px 0 0",fontSize:13,color:"#c7d2fe",opacity:.9},children:"Real-time tasks, approvals, delegations, and workflow actions requiring your attention."})]}),t.jsxs("button",{type:"button",onClick:k,disabled:r,style:{background:"rgba(255, 255, 255, 0.15)",backdropFilter:"blur(8px)",border:"1px solid rgba(255, 255, 255, 0.25)",color:"white",borderRadius:10,padding:"8px 16px",fontSize:13,fontWeight:600,cursor:r?"wait":"pointer",display:"flex",alignItems:"center",gap:8,transition:"all 0.15s ease"},onMouseEnter:y=>{y.currentTarget.style.background="rgba(255, 255, 255, 0.25)"},onMouseLeave:y=>{y.currentTarget.style.background="rgba(255, 255, 255, 0.15)"},children:[t.jsx("span",{style:{transform:r?"rotate(180deg)":"none",transition:"transform 0.5s",display:"inline-block"},children:"🔄"}),r?"Refreshing…":"Refresh"]})]}),t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:[t.jsxs("div",{style:{background:"rgba(255, 255, 255, 0.1)",backdropFilter:"blur(6px)",borderRadius:10,padding:"8px 14px",display:"flex",alignItems:"center",gap:10,border:"1px solid rgba(255, 255, 255, 0.15)"},children:[t.jsx("span",{style:{fontSize:12,color:"#e0e7ff",fontWeight:500},children:"Total Items"}),t.jsx("span",{style:{background:"white",color:"#1e1b4b",fontWeight:800,fontSize:12,padding:"2px 8px",borderRadius:999},children:g.all||0})]}),t.jsxs("div",{style:{background:"rgba(239, 68, 68, 0.2)",backdropFilter:"blur(6px)",borderRadius:10,padding:"8px 14px",display:"flex",alignItems:"center",gap:10,border:"1px solid rgba(239, 68, 68, 0.35)"},children:[t.jsx("span",{style:{fontSize:12,color:"#fecaca",fontWeight:600},children:"Action Required"}),t.jsx("span",{style:{background:"#ef4444",color:"white",fontWeight:800,fontSize:12,padding:"2px 8px",borderRadius:999},children:g.action||0})]}),t.jsxs("div",{style:{background:"rgba(59, 130, 246, 0.2)",backdropFilter:"blur(6px)",borderRadius:10,padding:"8px 14px",display:"flex",alignItems:"center",gap:10,border:"1px solid rgba(59, 130, 246, 0.35)"},children:[t.jsx("span",{style:{fontSize:12,color:"#bfdbfe",fontWeight:500},children:"Informational"}),t.jsx("span",{style:{background:"#3b82f6",color:"white",fontWeight:800,fontSize:12,padding:"2px 8px",borderRadius:999},children:g.info||0})]})]})]}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:14,background:"white",padding:"12px 16px",borderRadius:12,border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)"},className:"form-card",children:[t.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[{id:"all",label:"All",icon:"📋",count:g.all},{id:"action",label:"Needs Action",icon:"🚨",count:g.action,badgeColor:"#ef4444"},{id:"info",label:"Info",icon:"ℹ️",count:g.info},{id:"incident",label:"Incidents",icon:"⚠️",count:g.incident},{id:"idea",label:"Ideas",icon:"💡",count:g.idea},{id:"order",label:"Orders",icon:"📦",count:g.order},{id:"process",label:"Processes",icon:"⚙️",count:g.process},{id:"delegation",label:"Delegations",icon:"🤝",count:g.delegation}].map(y=>{const S=w===y.id;return y.id!=="all"&&y.id!=="action"&&y.id!=="info"&&(!y.count||y.count===0)?null:t.jsxs("button",{type:"button",onClick:()=>c(y.id),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:999,border:S?"1px solid #4f46e5":"1px solid #e2e8f0",background:S?"#4f46e5":"#f8fafc",color:S?"#ffffff":"#475569",fontSize:12,fontWeight:600,cursor:"pointer",transition:"all 0.15s ease"},children:[t.jsx("span",{children:y.icon}),t.jsx("span",{children:y.label}),y.count!=null&&y.count>0&&t.jsx("span",{style:{fontSize:10,fontWeight:700,padding:"1px 6px",borderRadius:999,background:S?"rgba(255,255,255,0.25)":y.badgeColor||"#e2e8f0",color:S?"#ffffff":y.badgeColor?"white":"#475569"},children:y.count})]},y.id)})}),t.jsx("div",{style:{minWidth:200,flex:"1 1 200px",maxWidth:300},children:t.jsx("input",{type:"text",placeholder:"Search items, titles, IDs…",value:C,onChange:y=>j(y.target.value),style:{width:"100%",padding:"7px 12px",borderRadius:8,border:"1px solid #cbd5e1",fontSize:12,boxSizing:"border-box",background:"#f8fafc",color:"#334155"}})})]}),r?t.jsxs("div",{style:{textAlign:"center",padding:"60px 20px",color:"#94a3b8",fontSize:14},children:[t.jsx("div",{style:{fontSize:28,marginBottom:8,animation:"spin 1s linear infinite"},children:"⏳"}),"Loading inbox updates…"]}):o.length===0?t.jsxs("div",{style:{background:"white",borderRadius:16,padding:"60px 24px",textAlign:"center",border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.03)"},className:"form-card",children:[t.jsx("div",{style:{fontSize:44,marginBottom:12},children:"✨"}),t.jsx("h3",{style:{fontSize:16,fontWeight:700,color:"#1e293b",margin:0},children:C||w!=="all"?"No matching inbox items":"You are all caught up!"}),t.jsx("p",{style:{fontSize:13,color:"#64748b",marginTop:6,maxWidth:420,margin:"6px auto 0"},children:C||w!=="all"?"Try changing your filter pills or searching for a different keyword.":"There are no active pending approvals or tasks requiring your action right now."}),(C||w!=="all")&&t.jsx("button",{type:"button",onClick:()=>{j(""),c("all")},style:{marginTop:16,padding:"7px 16px",borderRadius:8,background:"#4f46e5",color:"white",border:"none",fontWeight:600,fontSize:12,cursor:"pointer"},children:"Reset Filters"})]}):t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(330px, 1fr))",gap:14},children:h.map((y,S)=>{const u=H1[y.type]||J.gray,b=G1[y.type]||"linear-gradient(135deg, #64748b 0%, #475569 100%)",A=y.type!=="delegation";return t.jsxs("div",{className:"inbox-card form-card",onClick:A?()=>e(Fu[y.type],y.name):void 0,style:{background:"white",borderRadius:14,padding:"16px 18px",border:"1px solid #e2e8f0",boxShadow:"0 1px 3px rgba(0,0,0,0.04)",display:"flex",flexDirection:"column",justifyContent:"space-between",gap:14,cursor:A?"pointer":"default",position:"relative",overflow:"hidden",transition:"transform 0.15s ease, box-shadow 0.15s ease"},onMouseEnter:E=>{A&&(E.currentTarget.style.transform="translateY(-2px)",E.currentTarget.style.boxShadow="0 10px 20px -5px rgba(0,0,0,0.08)")},onMouseLeave:E=>{A&&(E.currentTarget.style.transform="none",E.currentTarget.style.boxShadow="0 1px 3px rgba(0,0,0,0.04)")},children:[t.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:4,background:b}}),t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,marginBottom:10},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("div",{style:{width:32,height:32,borderRadius:8,background:b,color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:15,flexShrink:0,boxShadow:`0 3px 8px -1px ${u}66`},children:Q1[y.type]||"📌"}),t.jsx("span",{style:{fontSize:12,fontWeight:700,color:u,letterSpacing:"0.3px"},children:y.number||y.name})]}),y.requires_action?t.jsxs("span",{style:{fontSize:10,fontWeight:800,color:"#ef4444",background:"#fef2f2",border:"1px solid #fecaca",padding:"2px 8px",borderRadius:999,textTransform:"uppercase",letterSpacing:"0.4px",display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#ef4444"}}),"Action"]}):t.jsx("span",{style:{fontSize:10,fontWeight:700,color:"#64748b",background:"#f1f5f9",padding:"2px 8px",borderRadius:999,textTransform:"uppercase",letterSpacing:"0.3px"},children:y.type})]}),t.jsx("div",{className:"inbox-card-title",style:{fontSize:14,fontWeight:700,color:"#1e293b",lineHeight:1.35,marginBottom:6,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:y.title||y.action||"Untitled Item"}),t.jsx("div",{style:{fontSize:12,color:"#475569",lineHeight:1.4,marginBottom:8},children:y.action}),t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[y.organization&&t.jsxs("span",{style:{fontSize:11,color:"#64748b",background:"#f8fafc",border:"1px solid #e2e8f0",padding:"2px 7px",borderRadius:6,display:"flex",alignItems:"center",gap:4},children:["🏢 ",y.organization]}),y.date&&t.jsxs("span",{style:{fontSize:11,color:"#64748b",background:"#f8fafc",border:"1px solid #e2e8f0",padding:"2px 7px",borderRadius:6},children:["📅 ",y.date]})]}),f===y.name&&t.jsx("div",{style:{marginTop:8,fontSize:11,color:"#ef4444",fontWeight:600},children:"⚠️ Failed to process response. Please try again."})]}),t.jsx("div",{children:y.type==="delegation"?t.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[t.jsx("button",{type:"button",onClick:()=>x(y.name,"Accepted"),disabled:i===y.name,style:{flex:1,padding:"7px 0",borderRadius:8,border:"none",background:"#16a34a",color:"white",fontWeight:700,fontSize:12,cursor:i===y.name?"wait":"pointer",opacity:i===y.name?.6:1,transition:"background 0.15s ease"},children:"✓ Accept"}),t.jsx("button",{type:"button",onClick:()=>x(y.name,"Rejected"),disabled:i===y.name,style:{flex:1,padding:"7px 0",borderRadius:8,border:"none",background:"#ef4444",color:"white",fontWeight:700,fontSize:12,cursor:i===y.name?"wait":"pointer",opacity:i===y.name?.6:1,transition:"background 0.15s ease"},children:"✕ Reject"})]}):t.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),e(Fu[y.type],y.name)},style:{width:"100%",padding:"7px 12px",borderRadius:8,border:y.requires_action?"none":"1px solid #cbd5e1",background:y.requires_action?b:"#f8fafc",color:y.requires_action?"#ffffff":"#334155",fontWeight:700,fontSize:12,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:6,transition:"all 0.15s ease"},children:[t.jsx("span",{children:y.requires_action?"Review & Act Now":"View Details"}),t.jsx("span",{style:{fontSize:13},children:"→"})]})})]},y.name||S)})}),t.jsx(Me,{page:v,total:o.length,onPageChange:z})]})}const Hu=[{id:"process_status_history",label:"Process Status History",description:"Full cycle-by-cycle status for any process, with actor, date, and escalation level",roles:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","Owner"]},{id:"order_tracker",label:"Outsourcing Order Tracker",description:"Stage-by-stage progress for all orders, with cost variance",roles:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","Owner"]},{id:"incident_register",label:"Incident Register",description:"All incidents with type, status, assigned manager, and resolution timeline",roles:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","Owner"]},{id:"ideas_pipeline",label:"Ideas Pipeline",description:"All ideas by status and type, conversion rate to Study",roles:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","Owner"]},{id:"department_performance",label:"Department Performance",description:"Aggregate Pass/Fail/Unknown per department per cycle",roles:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","Owner"]},{id:"escalation_report",label:"Escalation Report",description:"All Level 2 escalations with entity type and current status",roles:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","Owner"]},{id:"cost_summary",label:"Cost Summary",description:"Total cost per order, per department — budget vs actual",roles:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","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:["CEO","Chairman","Admin","Auditor","XAuditor","Manager","Owner"],extraFilter:"year"},{id:"user_activity_log",label:"User Activity Log",description:"All actions by user with timestamp and entity reference",roles:["CEO","Chairman","Admin","Auditor","Owner"]}],hc={number:"Number",title:"Title",organization:"Organization",department:"Department",status:"Status",actor:"Actor",cycle:"Cycle",date_start:"Start Date",date_end:"End Date",escalation_level:"Escalation",stage:"Stage",completion_pct:"Completion %",budget:"Budget",starting_date:"Start",ending_date:"End",date:"Date",assigned_to:"Assigned To",type:"Type",entity_type:"Entity",pass_count:"Pass",fail_count:"Fail",unknown_count:"Unknown",total:"Total",cycle_type:"Cycle Type",cost_per_cycle:"Cost/Cycle",total_cycles:"Total Cycles",total_cost:"Total Cost",timestamp:"Timestamp",user:"User",entity_name:"Entity",changes:"Fields Changed"};function X1(e,n){const s=e.map(r=>hc[r]||r).join(","),a=n.map(r=>e.map(l=>`"${r[l]??""}"`).join(",")).join(` `);return s+` `+a}function Y1(e,n){const s=new Blob([e],{type:"text/csv"}),a=URL.createObjectURL(s),r=document.createElement("a");r.href=a,r.download=n,r.click(),URL.revokeObjectURL(a)}const Gu=e=>String(e??"").replace(/&/g,"&").replace(//g,">");function q1(e,n,s){const a=e.map(p=>`${Gu(hc[p]||p)}`).join(""),r=n.map(p=>`${e.map(C=>`${Gu(p[C])}`).join("")}`).join(""),l=`${a}${r}
`,i=new Blob(["\uFEFF"+l],{type:"application/vnd.ms-excel"}),d=URL.createObjectURL(i),f=document.createElement("a");f.href=d,f.download=s,f.click(),URL.revokeObjectURL(d)}const mh="report-print-area",jo="report-print-portal";function J1(){const e=document.getElementById(mh);if(!e)return;const n=document.createElement("div");n.id=jo,n.innerHTML=e.innerHTML,document.body.appendChild(n);const s=document.createElement("style");s.id="report-print-style",s.textContent=` #${jo} { display: none; } @media print { #root { display: none !important; } #${jo} { display: block !important; } } `,document.head.appendChild(s);const a=()=>{n.remove(),s.remove(),window.removeEventListener("afterprint",a)};window.addEventListener("afterprint",a),window.print()}const Qu={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white",minWidth:180},bo={padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:13,background:"white"};function V1({organizations:e,userRole:n}){const s=le(),a=(n||"").trim().toLowerCase(),r=!a||["admin","ceo","chairman","owner","system manager","administrator"].includes(a),l=Hu.filter(W=>r?!0:W.roles.some(N=>N.toLowerCase()===a)),i=l.length>0?l:Hu,[d,f]=_.useState(""),[p,C]=_.useState(""),[j,w]=_.useState(""),[c,v]=_.useState(""),[z,k]=_.useState(String(new Date().getFullYear())),[g,o]=_.useState([]),[h,x]=_.useState([]),[y,S]=_.useState(!1),[u,b]=_.useState(""),[A,E]=_.useState(1);_.useEffect(()=>{E(1)},[d,p,z]);const H=h.slice((A-1)*oe,A*oe),Y=i.find(W=>W.id===d);async function ne(){if(d){S(!0),b(""),x([]),o([]);try{const W={};p&&(W.organization=p),j&&(W.from_date=j),c&&(W.to_date=c),(Y==null?void 0:Y.extraFilter)==="year"&&z&&(W.year=z);const N=await Qy(d,W);o(N.columns||[]),x(N.rows||[])}catch(W){b(W.message||"Error running report")}finally{S(!1)}}}const M=(Y==null?void 0:Y.label)||d;return t.jsxs("div",{children:[t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:12,marginBottom:20},children:i.map(W=>t.jsxs("div",{onClick:()=>f(W.id),style:{background:d===W.id?"#ebf5fb":"white",border:d===W.id?`2px solid ${J.accent}`:"2px solid transparent",borderRadius:10,padding:"14px 16px",cursor:"pointer",boxShadow:"0 1px 4px rgba(0,0,0,0.07)"},children:[t.jsx("div",{style:{fontWeight:700,fontSize:14,color:"#1a2332",marginBottom:4},children:W.label}),t.jsx("div",{style:{fontSize:12,color:"#888"},children:W.description})]},W.id))}),t.jsx("div",{style:{background:"white",borderRadius:12,padding:20,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",marginBottom:20},children:t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"REPORT"}),t.jsxs("select",{style:Qu,value:d,onChange:W=>f(W.target.value),children:[t.jsx("option",{value:"",children:"-- Select Report --"}),i.map(W=>t.jsx("option",{value:W.id,children:W.label},W.id))]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"ORGANIZATION"}),t.jsxs("select",{style:Qu,value:p,onChange:W=>C(W.target.value),children:[t.jsx("option",{value:"",children:s.filter.allOrgs}),e.map(W=>t.jsx("option",{value:W.name,children:W.organization_name||W.name},W.name))]})]}),(Y==null?void 0:Y.extraFilter)==="year"?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"YEAR"}),t.jsx("input",{type:"number",style:{...bo,width:90},value:z,onChange:W=>k(W.target.value),min:2020,max:2099})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"FROM"}),t.jsx(je,{value:j,onChange:w,style:bo})]}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:"#999",marginBottom:4},children:"TO"}),t.jsx(je,{value:c,onChange:v,style:bo})]})]}),t.jsx("button",{onClick:ne,disabled:!d||y,style:{padding:"9px 20px",borderRadius:8,border:"none",background:J.accent,color:"white",fontWeight:700,fontSize:13,cursor:d?"pointer":"not-allowed",opacity:d?1:.5},children:y?s.loading:s.reports.generate}),h.length>0&&t.jsx("button",{onClick:()=>Y1(X1(g,h),`${d}.csv`),style:{padding:"9px 20px",borderRadius:8,border:"1px solid #27ae60",background:"white",color:"#27ae60",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Export CSV"}),h.length>0&&t.jsx("button",{onClick:()=>q1(g,h,`${d}.xls`),style:{padding:"9px 20px",borderRadius:8,border:"1px solid #107c41",background:"white",color:"#107c41",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Export Excel"}),h.length>0&&t.jsx("button",{onClick:J1,style:{padding:"9px 20px",borderRadius:8,border:"1px solid #888",background:"white",color:"#555",fontWeight:700,fontSize:13,cursor:"pointer"},children:"Print / PDF"})]})}),u&&t.jsx("div",{style:{color:"#e74c3c",marginBottom:16},children:u}),h.length>0&&t.jsxs("div",{id:mh,style:{background:"white",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.08)",overflow:"auto"},children:[t.jsxs("div",{style:{padding:"14px 18px",borderBottom:"1px solid #f0f0f0",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{style:{fontWeight:700,color:"#333"},children:M}),t.jsxs("span",{style:{fontSize:12,color:"#888"},children:[h.length," rows"]})]}),t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsx("tr",{style:{background:"#f8f9fa"},children:g.map(W=>t.jsx("th",{style:{padding:"10px 14px",textAlign:"left",color:"#999",fontSize:11,fontWeight:700,whiteSpace:"nowrap"},children:hc[W]||W.replace(/_/g," ").toUpperCase()},W))})}),t.jsx("tbody",{children:H.map((W,N)=>t.jsx("tr",{style:{borderTop:"1px solid #f0f0f0",background:N%2===0?"white":"#fafafa"},children:g.map(I=>t.jsx("td",{style:{padding:"10px 14px",color:"#333"},children:W[I]!=null?String(W[I]):"—"},I))},N))})]}),t.jsx(Me,{page:A,total:h.length,onPageChange:E})]}),!y&&h.length===0&&d&&!u&&t.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"Select a report and click Run Report to see results."}),i.length===0&&t.jsx("div",{style:{background:"white",borderRadius:12,padding:40,textAlign:"center",color:"#aaa",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},children:"No reports are available for your role."})]})}const Hr=()=>new Date().toISOString().split("T")[0],gc=()=>new Date(Date.now()+30*24*60*60*1e3).toISOString().split("T")[0],Z1=()=>new Date().toTimeString().slice(0,5),Ln=()=>({name:"",number:"",title:"",organization:"",group_company:"",event_category:"",type:"",incident_class:"",incident_field:"",date:Hr(),time:Z1(),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:""}),kn=()=>({name:"",number:"",title:"",organization:"",group_company:"",type:"",management:"",department:"",section_field:"",branch:"",current_condition:"",proposed_condition:"",status:"",assigned_to:"",workflow_state:"New",idea_class:"",hses_field:"",date:Hr(),priority:"",economy_class:"",product_relation:0,repeated:0,entity_scope:"",solution:"",cost:0,auditor_comment:"",sb_order:""}),Cn=()=>({name:"",number:"",title:"",organization:"",group_company:"",type:"Buy L",management:"",department:"",section_field:"",branch:"",starting_date:Hr(),ending_date:gc(),assigned_to:"",actor:"",status:"",budget:0,actual_cost:0,currency:"SAR",description:"",notes:"",cycle:"",stage:1,completion_pct:0,escalation_level:0,workflow_state:"Draft",planned:0,priority:"",product_relation:0,entity_scope:"",economy_class:"",hses_field:"",auditor_comment:"",sb_idea:"",cycle_type:"Normal",long_cycle_date_1:"",long_cycle_date_2:"",long_cycle_date_3:"",long_cycle_date_4:""}),yl=()=>({name:"",title:"",date_start:Hr(),date_end:gc(),number:"",status:"",cycle_type:"Normal",organization:"",group_company:"",type:"",management:"",department:"",section_field:"",branch:"",progress_indicators:[],cycle:"",actor:"",escalation_level:0,workflow_state:"",chain_location:"",economy_class:"",impact_level:"",product_relation:0,entity_scope:"",hses_field:"",kpi_name:"",kpi_type:"",kpi_measure:"",cost_per_cycle:0,auditor_comment:""}),aa=()=>({name:"",organization_name:"",group_company:"",type:"Government",city:"",contact_email:"",creation_date:new Date().toISOString().slice(0,10),is_active:1,acronym:"",incident_triage_window_days:3,incident_resolution_window_days:5}),ks=()=>({name:"",organization:"",group_company:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),Cs=()=>({name:"",custom_organization:"",group_company:"",department_name:"",custom_management:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),zs=()=>({name:"",organization:"",group_company:"",branch:"",management:"",department:"",custom_creation_date:new Date().toISOString().slice(0,10),custom_status:"Active"}),ra=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),la=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),ia=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),oa=()=>({name:"",name1:"",creation_date:new Date().toISOString().slice(0,10),status:"Active"}),da=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),ca=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),ua=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),pa=()=>({name:"",name1:"",notify_manager:0,creation_date:new Date().toISOString().slice(0,10),status:"Active"}),vl=()=>({name:"",first_name:"",full_name:"",email:"",enabled:1,creation:"",username:"",mobile_no:"",custom_organization:"",custom_group_company:"",custom_manager:"",custom_management:"",custom_department:"",custom_branch:"",custom_number:"",custom_category:""}),Is=()=>({name:"",name1:"",organization:"",group_company:"",frequency:"Monthly",status:"Active",start_date:Hr(),end_date:gc(),update_window_days:2}),Es=()=>({name:"",organization:"",group_company:"",period:"",revenue_growth:0,net_profit:0,cash_flow:0,strategic_goal_pct:0,customer_satisfaction:0,employee_turnover_pct:0,open_safety_incidents:0,compliance_score:0}),rr=()=>({name:"",number:"",auditor:"",manager:"",organization:"",incident_initial_evaluation:0,idea_initial_evaluation:0,status:"Pending",requested_on:"",remarks:""}),ev=new Set(["incidents","incidents-form","ideas","ideas-form"]),tv=new Set(["orders","orders-form","incidents","incidents-form","ideas","ideas-form"]),nv=new Set(hd.flatMap(({id:e})=>[e,`${e}-form`])),sv=new Set(["Admin","Owner","Business Owner","Auditor","Manager","CEO","Chairman","XAuditor"]),av=new Set(["Admin","Auditor","Manager","CEO","Chairman","XAuditor"]),rv=new Set(["Admin","Auditor","Manager","CEO","Chairman"]);function lv({user:e,onLogout:n,darkMode:s,onToggleDark:a}){const r=le(),l=e.role,i=sv.has(l),d=av.has(l),f=rv.has(l),p=m=>l==="CEO"?!0:l==="Business Owner"||l==="Owner"?m==="organizations"||m==="organizations-form"||m==="departments"||m==="departments-form"||m==="users"||m==="users-form":m==="users"||m==="users-form"?l==="Admin":l==="Admin"||l==="Auditor"?!0:l==="XAuditor"?!1:l==="Manager"?!!tv.has(m):ev.has(m),C=m=>l==="Employee"&&!!m&&m!=="New",j=i?"dashboard":"inbox",w=m=>l==="CEO"?!0:l==="Business Owner"||l==="Owner"?m==="dashboard"||m==="organizations"||m==="organizations-form"||m==="departments"||m==="departments-form"||m==="users"||m==="users-form"||m==="profile"||m==="incidents-form"||m==="ideas-form"||m==="orders-form"||m==="processes-form":m==="dashboard"?i:m==="reports"?d:m==="delegations"||m==="delegations-form"?f:m==="users"||m==="users-form"?l==="Admin":nv.has(m)?l==="Admin"||l==="Auditor":!0,[c,v]=_.useState(()=>{const m=l0(Du());return m&&w(m)?m:j});_.useEffect(()=>{const m=i0(c);window.location.hash!==m&&window.history.pushState(null,"",m)},[c]),_.useEffect(()=>{const m=()=>{const $=Du();v($&&w($)?$:j)};return window.addEventListener("popstate",m),()=>window.removeEventListener("popstate",m)},[]);const z=e.custom_organization||"",k=e.custom_group_company||"",g=m=>{var $;return(($=H.find(_e=>_e.name===m))==null?void 0:$.group_company)||""},[o,h]=_.useState(""),[x,y]=_.useState("");_.useEffect(()=>{if(!x)return;const m=setTimeout(()=>y(""),0);return()=>clearTimeout(m)},[x]);const S=(m,$)=>{y($),v(m)},[u,b]=_.useState(0),[A,E]=_.useState([]),[H,Y]=_.useState([]),[ne,M]=_.useState([]),[W,N]=_.useState([]),[I,T]=_.useState([]),[G,V]=_.useState([]),[D,O]=_.useState([]),[q,se]=_.useState([]),[ie,ke]=_.useState([]),[Ie,_t]=_.useState([]),[Kt,wt]=_.useState([]),[Wt,on]=_.useState([]),[me,Xt]=_.useState([]),[We,Q]=_.useState([]),[te,ue]=_.useState([]),[Ee,kt]=_.useState([]),[he,F]=_.useState([]),[re,L]=_.useState([]),[be,Ct]=_.useState([]),[K,Fe]=_.useState({}),[At,ys]=_.useState([]),[vs,Gr]=_.useState([]),[Qr,Kr]=_.useState([]),[Xr,Yr]=_.useState([]),[Ga,U]=_.useState([]),[ft,An]=_.useState({}),[De,xh]=_.useState([]),qr=()=>({name:"",company_name:"",acronym:"",code:"",status:"Active",owner_user:"",notes:""}),[Ci,Ks]=_.useState(qr()),[Ae,ye]=_.useState(!0),[Ye,fe]=_.useState("idle"),[qe,ae]=_.useState(!1),[mc,xc]=_.useState(!1),[Jr,yc]=_.useState(null),[yh,vh]=_.useState(()=>localStorage.getItem("sb_sidebar")==="1"),jh=()=>vh(m=>{const $=!m;return localStorage.setItem("sb_sidebar",$?"1":"0"),$}),[bh,zi]=_.useState(!1),[Sh,He]=_.useState([]),[_h,Ge]=_.useState([]);_.useEffect(()=>{zi(!1),He([]),Ge([])},[c]);const[dn,Pn]=_.useState(Ln()),[cn,jn]=_.useState(kn()),[Rn,bn]=_.useState(Cn()),[On,Sn]=_.useState(yl()),[Ii,Xs]=_.useState(aa()),[Ei,js]=_.useState(ks()),[Ti,bs]=_.useState(Cs()),[Ai,Ss]=_.useState(zs()),[Pi,Ys]=_.useState(ra()),[Ri,qs]=_.useState(la()),[Oi,Js]=_.useState(ia()),[Di,Vs]=_.useState(oa()),[Bi,Zs]=_.useState(da()),[Li,ea]=_.useState(ca()),[Wi,ta]=_.useState(ua()),[Ni,na]=_.useState(pa()),[Pt,Vr]=_.useState(vl()),[$i,_s]=_.useState(Is()),[Ui,ws]=_.useState(Es()),[Yt,Qa]=_.useState(rr()),qt=async()=>{ye(!0);try{const[m,$,_e,ct,Jt,ze,Nt,un,Ya,yg,vg,jg,bg,Sg,_g,wg,kg,Cg,zg,Ig,Eg,Tg,Ag,Pg,Rg,Og,Dg]=await Promise.all([Be(P.incidents),Be(P.organizations),Be(P.ideas),Be(P.orders),Be(P.processes),Iy(),Be(P.managements),Be(P.departments),Be(P.branches),Be(P.incidentTypes),Be(P.incidentClass),Be(P.incidentField),Be(P.ideaTypes),Be(P.orderTypes),Be(P.processTypes),Be(P.incidentStatuses),Be(P.ideaStatuses),Be(P.orderStatuses),Be(P.processStatuses),Py(),Ry(),Be(P.cycles),Be(P.kpiInput),Jy(),Zy(),e0(),t0()]);E(m||[]),Y($||[]),M(_e||[]),N(ct||[]),T(Jt||[]),ys(ze||[]),V(Nt||[]),O(un||[]),se(Ya||[]),ke(yg||[]),_t(vg||[]),wt(jg||[]),on(bg||[]),Xt(Sg||[]),Q(_g||[]),ue(wg||[]),kt(kg||[]),F(Cg||[]),L(zg||[]),Ct(Ig||[]),Fe(Eg||{}),Gr(Tg||[]),Kr(Ag||[]),Yr(Pg||[]),U(Rg||[]),An(Og||{}),xh(Dg||[])}catch(m){console.error("Error loading data:",m)}ye(!1)},vc=async()=>{try{const m=await fetch("/api/method/sidrah_business.api.get_notification_count",{credentials:"include",headers:{Accept:"application/json"}});if(m.ok){const $=await m.json();b(Number($.message)||0)}}catch{}};_.useEffect(()=>{qt(),vc();const m=setInterval(vc,6e4);return()=>clearInterval(m)},[e.name]);const[xt,Dn]=_.useState({isOpen:!1,doctype:"",name:"",title:"",isDeleting:!1}),de=(m,$,_e)=>{Dn({isOpen:!0,doctype:m,name:$,title:_e||$,isDeleting:!1})},jc=m=>{const _e={[P.incidents]:"incidents",[P.ideas]:"ideas",[P.orders]:"orders",[P.processes]:"processes",[P.organizations]:"organizations",[P.managements]:"managements",[P.departments]:"departments",[P.branches]:"branches",[P.cycles]:"cycles",[P.kpiInput]:"kpi-input",[P.incidentTypes]:"incident-types",[P.ideaTypes]:"idea-types",[P.orderTypes]:"order-types",[P.processTypes]:"process-types",[P.incidentStatuses]:"incident-statuses",[P.ideaStatuses]:"idea-statuses",[P.orderStatuses]:"order-statuses",[P.processStatuses]:"process-statuses",[P.groupCompanies]:"group-companies"}[m];_e&&v(_e)},bc=async m=>{Dn($=>({...$,isDeleting:!0}));try{const $=xt.doctype;await md(xt.doctype,xt.name,m,!1),Dn(_e=>({..._e,isOpen:!1,isDeleting:!1})),alert(r.rtl?"تم نقل السجل إلى المحذوفات بنجاح!":"Record moved to Deleted successfully!"),await qt(),c.endsWith("-form")&&jc($)}catch($){console.error("Delete error:",$),alert(($==null?void 0:$.message)||"Delete failed. Please try again."),Dn(_e=>({..._e,isDeleting:!1}))}},Sc=async m=>{Dn($=>({...$,isDeleting:!0}));try{const $=xt.doctype;await md(xt.doctype,xt.name,m,!0),Dn(_e=>({..._e,isOpen:!1,isDeleting:!1})),alert(r.rtl?"تم حذف السجل نهائياً بنجاح!":"Record permanently deleted successfully!"),await qt(),c.endsWith("-form")&&jc($)}catch($){console.error("Permanent delete error:",$),alert(($==null?void 0:$.message)||"Permanent delete failed. Please try again."),Dn(_e=>({..._e,isDeleting:!1}))}},Je=async(m,$)=>{if(window.confirm(r.rtl?"هل أنت متأكد من استعادة هذا السجل؟":"Are you sure you want to restore this record?")){ye(!0);try{await zy(m,$),alert(r.restoredOk||"Record restored successfully!"),await qt()}catch(_e){console.error("Restore error:",_e),alert((_e==null?void 0:_e.message)||"Restore failed. Please try again.")}ye(!1)}},wh=async m=>{try{await Ly(m),await qt()}catch($){console.error("Disable user error:",$)}},kh=async m=>{ae(!0),ye(!0);try{const $=await $t(P.incidents,m.name);Pn({...Ln(),...$})}catch{Pn({...Ln(),...m})}v("incidents-form"),ye(!1)},Ch=async m=>{ae(!0),ye(!0);try{const $=await $t(P.ideas,m.name);jn({...kn(),...$})}catch{jn({...kn(),...m})}v("ideas-form"),ye(!1)},zh=async m=>{ae(!0),ye(!0);try{const $=await $t(P.orders,m.name);bn({...Cn(),...$})}catch{bn({...Cn(),...m})}v("orders-form"),ye(!1)},Ih=async m=>{ae(!0),ye(!0);try{const $=await cr(m.name);Sn({...$,progress_indicators:$.progress_indicators||[],cycle_logs:$.cycle_logs||[]}),v("processes-form")}catch{Sn({...m,progress_indicators:m.progress_indicators||[]}),v("processes-form")}ye(!1)},Eh=m=>Ce(P.organizations,m,Xs,aa(),"organizations-form",!0),Th=m=>{ae(!0),Ks(m),v("group-companies-form")},Ah=m=>{ae(!1),Ks(m),v("group-companies-form")},Ph=async m=>{ae(!0),ye(!0);try{const $=await $t(P.managements,m.name);js({...ks(),...$})}catch{js({...ks(),...m})}v("managements-form"),ye(!1)},Rh=async m=>{ae(!0),ye(!0);try{const $=await $t(P.departments,m.name);bs({...Cs(),...$})}catch{bs({...Cs(),...m})}v("departments-form"),ye(!1)},Oh=async m=>{ae(!0),ye(!0);try{const $=await $t(P.branches,m.name);Ss({...zs(),...$})}catch{Ss({...zs(),...m})}v("branches-form"),ye(!1)},Dh=async m=>{ae(!0),ye(!0);try{const $=await $t(P.cycles,m.name);_s({...Is(),...$})}catch{_s({...Is(),...m})}v("cycles-form"),ye(!1)},Bh=async m=>{ae(!0),ye(!0);try{const $=await $t(P.kpiInput,m.name);ws({...Es(),...$})}catch{ws({...Es(),...m})}v("kpi-input-form"),ye(!1)},lt=async(m,$,_e,ct,Jt)=>{fe("loading");try{if($.name)await Ds(m,$.name,$),fe("success"),qt(),setTimeout(()=>fe("idle"),1500);else{const ze=await si(m,$),Nt=(ze==null?void 0:ze.data)??ze;Jt&&Jt(Nt),fe("success"),qt(),setTimeout(()=>fe("idle"),1500)}}catch(ze){console.error("Submit error:",ze),fe(ze instanceof Error?ze.message:"Error saving. Please try again.")}},Qe=async()=>{await Ty(),n()},Ce=async(m,$,_e,ct,Jt,ze)=>{ae(ze),ye(!0);try{const Nt=await $t(m,$.name);_e({...ct,...Nt})}catch{_e({...ct,...$})}v(Jt),ye(!1)},Lh=m=>Ce(P.incidents,m,Pn,Ln(),"incidents-form",!1),Wh=m=>Ce(P.ideas,m,jn,kn(),"ideas-form",!1),Nh=m=>Ce(P.orders,m,bn,Cn(),"orders-form",!1),$h=m=>{ae(!1),ye(!0),cr(m.name).then($=>{Sn({...$,progress_indicators:$.progress_indicators||[],cycle_logs:$.cycle_logs||[]})}).catch(()=>{Sn({...m,progress_indicators:m.progress_indicators||[]})}).finally(()=>{v("processes-form"),ye(!1)})},Uh=m=>Ce(P.organizations,m,Xs,aa(),"organizations-form",!1),Mh=m=>Ce(P.managements,m,js,ks(),"managements-form",!1),Fh=m=>Ce(P.departments,m,bs,Cs(),"departments-form",!1),Hh=m=>Ce(P.branches,m,Ss,zs(),"branches-form",!1),Gh=m=>Ce(P.cycles,m,_s,Is(),"cycles-form",!1),Qh=m=>Ce(P.kpiInput,m,ws,Es(),"kpi-input-form",!1),Kh=async m=>{ae(!0),ye(!0);try{const $=await Vy(m.name);Qa({...rr(),...$})}catch{Qa({...rr(),...m})}v("delegations-form"),ye(!1)},Xh=async()=>{fe("loading");try{const m=[];Yt.incident_initial_evaluation&&m.push("incident_initial_evaluation"),Yt.idea_initial_evaluation&&m.push("idea_initial_evaluation"),await Xy(Yt.manager,m,Yt.organization,Yt.remarks||"",Yt.incident_name||"",Yt.idea_name||""),Qa(rr()),fe("success"),qt(),setTimeout(()=>{fe("idle"),v("delegations")},1500)}catch(m){console.error("Delegation submit error:",m),fe(m instanceof Error?m.message:"Error saving. Please try again.")}},Yh=async m=>{if(window.confirm(r.rtl?"هل أنت متأكد من إلغاء هذا التفويض؟":"Are you sure you want to revoke this delegation?")){ye(!0);try{await qy(m),await qt()}catch($){console.error("Revoke delegation error:",$),alert($ instanceof Error?$.message:"Revoke failed. Please try again.")}ye(!1)}},qh=m=>Ce(P.incidentTypes,m,Ys,ra(),"incident-types-form",!0),Jh=m=>Ce(P.incidentTypes,m,Ys,ra(),"incident-types-form",!1),Vh=m=>Ce(P.ideaTypes,m,qs,la(),"idea-types-form",!0),Zh=m=>Ce(P.ideaTypes,m,qs,la(),"idea-types-form",!1),eg=m=>Ce(P.orderTypes,m,Js,ia(),"order-types-form",!0),tg=m=>Ce(P.orderTypes,m,Js,ia(),"order-types-form",!1),ng=m=>Ce(P.processTypes,m,Vs,oa(),"process-types-form",!0),sg=m=>Ce(P.processTypes,m,Vs,oa(),"process-types-form",!1),ag=m=>Ce(P.incidentStatuses,m,Zs,da(),"incident-statuses-form",!0),rg=m=>Ce(P.incidentStatuses,m,Zs,da(),"incident-statuses-form",!1),lg=m=>Ce(P.ideaStatuses,m,ea,ca(),"idea-statuses-form",!0),ig=m=>Ce(P.ideaStatuses,m,ea,ca(),"idea-statuses-form",!1),og=m=>Ce(P.orderStatuses,m,ta,ua(),"order-statuses-form",!0),dg=m=>Ce(P.orderStatuses,m,ta,ua(),"order-statuses-form",!1),cg=m=>Ce(P.processStatuses,m,na,pa(),"process-statuses-form",!0),ug=m=>Ce(P.processStatuses,m,na,pa(),"process-statuses-form",!1),pg=async m=>{yc(m),v("profile")},fg=m=>{ae(!1),xc(!1),Vr({...vl(),...m}),v("users-form")},hg=async()=>{fe("loading");try{if(!Pt.name){const{new_password:$,..._e}=Pt,ct=await si("User",{..._e,send_welcome_email:0,user_type:"System User"}),Jt=(ct==null?void 0:ct.data)??ct,ze=(Jt==null?void 0:Jt.name)||Pt.email;if($&&ze)try{await ai(ze,$)}catch(Nt){console.error("Password set error:",Nt)}if(Pt.custom_category==="Admin"&&Pt.custom_group_company){const Nt=De.find(un=>un.name===Pt.custom_group_company);if(Nt&&!Nt.owner_user)try{await Ds("SB Group Company",Nt.name,{owner_user:ze})}catch(un){console.error("GC owner sync error:",un)}}Vr({...vl(),...Pt,...(ct==null?void 0:ct.data)??ct}),ae(!0),fe("success"),qt(),setTimeout(()=>fe("idle"),1500)}else{const{name:$,email:_e,creation:ct,full_name:Jt,new_password:ze,...Nt}=Pt;if(await Ds("User",$,Nt),ze)try{await ai($,ze)}catch(un){console.error("Password set error:",un)}if(Pt.custom_category==="Admin"&&Pt.custom_group_company){const un=De.find(Ya=>Ya.name===Pt.custom_group_company);if(un&&!un.owner_user)try{await Ds("SB Group Company",un.name,{owner_user:$})}catch(Ya){console.error("GC owner sync error:",Ya)}}fe("success"),qt(),setTimeout(()=>fe("idle"),1500)}}catch(m){console.error("User submit error:",m),fe(m instanceof Error?m.message:"Error saving. Please try again.")}},Ke=()=>{const m=be.find($=>$.name===e.name||$.username===e.name);yc(m||{name:e.name,full_name:e.full_name,email:e.name,enabled:1}),v("profile")},Mi=(m,$)=>{if($){const ct={"processes-form":P.processes,"orders-form":P.orders,"incidents-form":P.incidents,"ideas-form":P.ideas}[m];if(ct){ae(!0),ye(!0),(m==="processes-form"?cr($).then(ze=>({...ze,progress_indicators:ze.progress_indicators||[],cycle_logs:ze.cycle_logs||[]})):$t(ct,$)).then(ze=>{m==="processes-form"?Sn(ze):m==="orders-form"?bn({...Cn(),...ze}):m==="incidents-form"?Pn({...Ln(),...ze}):m==="ideas-form"&&jn({...kn(),...ze}),v(m),ye(!1)}).catch(()=>{v(m),ye(!1)});return}}v(m)},Ve=m=>t.jsxs(t.Fragment,{children:[m,t.jsx(Ru,{isOpen:xt.isOpen,doctype:xt.doctype,docname:xt.name,docTitle:xt.title,isAdmin:l==="Admin"||e.name==="Administrator",isDeleting:xt.isDeleting,onClose:()=>Dn($=>({...$,isOpen:!1})),onConfirmSoftDelete:bc,onConfirmPermanentDelete:Sc})]});if(c==="incidents-form")return Ve(t.jsx(C0,{incForm:dn,setIncForm:Pn,organizations:H,groupCompanies:De,managements:G,departments:D,branches:q,incidentTypes:ie,incidentClasses:Ie,incidentFields:Kt,incidentStatuses:te,users:At,userRoleMap:K,formStatus:Ye,viewMode:qe||!p("incidents-form")||C(dn.workflow_state),canModify:p("incidents-form"),onEdit:p("incidents-form")&&!C(dn.workflow_state)&&!ns("incident",dn.workflow_state)?()=>ae(!1):void 0,onDelete:p("incidents-form")?m=>de(P.incidents,m,dn.title||dn.number):void 0,onRestore:l==="Admin"?m=>Je(P.incidents,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.incidents,m,dn.title||dn.number):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,userRole:l,delegatedFunctions:Ga,delegatedOrgs:ft,onSubmit:()=>lt(P.incidents,dn,()=>Pn(Ln()),"incidents",m=>Pn({...Ln(),...m})),onBack:()=>{v("incidents"),fe("idle")},onNavigate:v,onLogout:Qe,user:e,onRefresh:async()=>{if(dn.name){const m=await $t(P.incidents,dn.name).catch(()=>null);m&&Pn({...Ln(),...m})}Be(P.incidents).then(m=>E(m||[])).catch(()=>{})}}));if(c==="ideas-form")return Ve(t.jsx(T0,{ideaForm:cn,setIdeaForm:jn,organizations:H,groupCompanies:De,managements:G,departments:D,branches:q,ideaTypes:Wt,ideaStatuses:Ee,users:At,userRoleMap:K,formStatus:Ye,viewMode:qe||!p("ideas-form")||C(cn.workflow_state),canModify:p("ideas-form"),onEdit:p("ideas-form")&&!C(cn.workflow_state)&&!ns("idea",cn.workflow_state)?()=>ae(!1):void 0,onDelete:p("ideas-form")?m=>de(P.ideas,m,cn.title||cn.number):void 0,onRestore:l==="Admin"?m=>Je(P.ideas,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.ideas,m,cn.title||cn.number):void 0,onNavigateToOrder:m=>Ce(P.orders,{name:m},bn,Cn(),"orders-form",!0),darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,userRole:l,delegatedFunctions:Ga,delegatedOrgs:ft,onSubmit:()=>lt(P.ideas,cn,()=>jn(kn()),"ideas",m=>jn({...kn(),...m})),onBack:()=>{v("ideas"),fe("idle")},onNavigate:v,onLogout:Qe,user:e,onRefresh:async()=>{if(cn.name){const m=await $t(P.ideas,cn.name).catch(()=>null);m&&jn({...kn(),...m})}Be(P.ideas).then(m=>M(m||[])).catch(()=>{})}}));if(c==="orders-form")return Ve(t.jsx(D0,{orderForm:Rn,setOrderForm:bn,organizations:H,groupCompanies:De,managements:G,departments:D,branches:q,orderTypes:me,orderStatuses:he,cycles:vs,users:At,userRoleMap:K,formStatus:Ye,viewMode:qe||!p("orders-form"),canModify:p("orders-form"),onEdit:p("orders-form")&&!ns("order",Rn.workflow_state)?()=>ae(!1):void 0,onDelete:p("orders-form")?m=>de(P.orders,m,Rn.title||Rn.number):void 0,onRestore:l==="Admin"?m=>Je(P.orders,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.orders,m,Rn.title||Rn.number):void 0,onNavigateToIdea:m=>Ce(P.ideas,{name:m},jn,kn(),"ideas-form",!0),darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,currentUser:e.name,userRole:l,onSubmit:()=>lt(P.orders,Rn,()=>bn(Cn()),"orders",m=>bn({...Cn(),...m})),onBack:()=>{v("orders"),fe("idle")},onNavigate:v,onLogout:Qe,user:e,onRefresh:async()=>{if(Rn.name){const m=await $t(P.orders,Rn.name).catch(()=>null);m&&bn({...Cn(),...m})}Be(P.orders).then(m=>N(m||[])).catch(()=>{})}}));if(c==="processes-form")return Ve(t.jsx($0,{processForm:On,setProcessForm:Sn,organizations:H,groupCompanies:De,managements:G,departments:D,branches:q,processTypes:We,processStatuses:re,cycles:vs,users:At,userRoleMap:K,formStatus:Ye,viewMode:qe||!p("processes-form"),canModify:p("processes-form"),onEdit:p("processes-form")&&!ns("process",On.workflow_state)?()=>ae(!1):void 0,onDelete:p("processes-form")?m=>de(P.processes,m,On.title||On.number):void 0,onRestore:l==="Admin"?m=>Je(P.processes,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.processes,m,On.title||On.number):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,userRole:e.role,onRefreshProcess:async()=>{if(On.name)try{const m=await cr(On.name);Sn({...m,progress_indicators:m.progress_indicators||[],cycle_logs:m.cycle_logs||[]})}catch{}Be(P.processes).then(m=>T(m||[])).catch(()=>{})},onSubmit:()=>lt(P.processes,On,()=>Sn(yl()),"processes",m=>Sn({...yl(),...m,progress_indicators:m.progress_indicators||[],cycle_logs:m.cycle_logs||[]})),onBack:()=>{v("processes"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="organizations-form")return Ve(t.jsx(Q0,{orgForm:Ii,setOrgForm:Xs,groupCompanies:De,formStatus:Ye,viewMode:qe||!p("organizations-form"),onEdit:p("organizations-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.organizations,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.organizations,m,Ii.organization_name):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.organizations,Ii,()=>Xs(aa()),"organizations",m=>{Xs({...aa(),...m}),ae(!0)}),onBack:()=>{v("organizations"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="managements-form")return Ve(t.jsx(J0,{form:Ei,setForm:js,organizations:H,groupCompanies:De,formStatus:Ye,viewMode:qe||!p("managements-form"),onEdit:p("managements-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.managements,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.managements,m,Ei.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.managements,Ei,()=>js(ks()),"managements",m=>{js({...ks(),...m}),ae(!0)}),onBack:()=>{v("managements"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="departments-form")return Ve(t.jsx(e1,{form:Ti,setForm:bs,organizations:H,groupCompanies:De,managements:G,formStatus:Ye,viewMode:qe||!p("departments-form"),onEdit:p("departments-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.departments,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.departments,m,Ti.department_name):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.departments,Ti,()=>bs(Cs()),"departments",m=>{bs({...Cs(),...m}),ae(!0)}),onBack:()=>{v("departments"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="branches-form")return Ve(t.jsx(s1,{form:Ai,setForm:Ss,organizations:H,groupCompanies:De,managements:G,departments:D,formStatus:Ye,viewMode:qe||!p("branches-form"),onEdit:p("branches-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.branches,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.branches,m,Ai.branch):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.branches,Ai,()=>Ss(zs()),"branches",m=>{Ss({...zs(),...m}),ae(!0)}),onBack:()=>{v("branches"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="cycles-form")return Ve(t.jsx(D1,{form:$i,setForm:_s,organizations:H,groupCompanies:De,formStatus:Ye,viewMode:qe||!p("cycles-form"),onEdit:p("cycles-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.cycles,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.cycles,m,$i.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.cycles,$i,()=>_s(Is()),"cycles",m=>{_s({...Is(),...m}),ae(!0)}),onBack:()=>{v("cycles"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="kpi-input-form")return Ve(t.jsx(L1,{form:Ui,setForm:ws,organizations:H,groupCompanies:De,formStatus:Ye,viewMode:qe||!p("kpi-input-form"),onEdit:p("kpi-input-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.kpiInput,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.kpiInput,m,Ui.period):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.kpiInput,Ui,()=>ws(Es()),"kpi-input",m=>{ws({...Es(),...m}),ae(!0)}),onBack:()=>{v("kpi-input"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="incident-types-form")return Ve(t.jsx(l1,{form:Pi,setForm:Ys,formStatus:Ye,viewMode:qe||!p("incident-types-form"),onEdit:p("incident-types-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.incidentTypes,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.incidentTypes,m,Pi.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.incidentTypes,Pi,()=>Ys(ra()),"incident-types",m=>{Ys({...ra(),...m}),ae(!0)}),onBack:()=>{v("incident-types"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="idea-types-form")return Ve(t.jsx(d1,{form:Ri,setForm:qs,formStatus:Ye,viewMode:qe||!p("idea-types-form"),onEdit:p("idea-types-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.ideaTypes,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.ideaTypes,m,Ri.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.ideaTypes,Ri,()=>qs(la()),"idea-types",m=>{qs({...la(),...m}),ae(!0)}),onBack:()=>{v("idea-types"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="order-types-form")return Ve(t.jsx(p1,{form:Oi,setForm:Js,formStatus:Ye,viewMode:qe||!p("order-types-form"),onEdit:p("order-types-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.orderTypes,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.orderTypes,m,Oi.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.orderTypes,Oi,()=>Js(ia()),"order-types",m=>{Js({...ia(),...m}),ae(!0)}),onBack:()=>{v("order-types"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="process-types-form")return Ve(t.jsx(g1,{form:Di,setForm:Vs,formStatus:Ye,viewMode:qe||!p("process-types-form"),onEdit:p("process-types-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.processTypes,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.processTypes,m,Di.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.processTypes,Di,()=>Vs(oa()),"process-types",m=>{Vs({...oa(),...m}),ae(!0)}),onBack:()=>{v("process-types"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="incident-statuses-form")return Ve(t.jsx(y1,{form:Bi,setForm:Zs,formStatus:Ye,viewMode:qe||!p("incident-statuses-form"),onEdit:p("incident-statuses-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.incidentStatuses,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.incidentStatuses,m,Bi.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.incidentStatuses,Bi,()=>Zs(da()),"incident-statuses",m=>{Zs({...da(),...m}),ae(!0)}),onBack:()=>{v("incident-statuses"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="idea-statuses-form")return Ve(t.jsx(b1,{form:Li,setForm:ea,formStatus:Ye,viewMode:qe||!p("idea-statuses-form"),onEdit:p("idea-statuses-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.ideaStatuses,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.ideaStatuses,m,Li.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.ideaStatuses,Li,()=>ea(ca()),"idea-statuses",m=>{ea({...ca(),...m}),ae(!0)}),onBack:()=>{v("idea-statuses"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="order-statuses-form")return Ve(t.jsx(w1,{form:Wi,setForm:ta,formStatus:Ye,viewMode:qe||!p("order-statuses-form"),onEdit:p("order-statuses-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.orderStatuses,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.orderStatuses,m,Wi.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.orderStatuses,Wi,()=>ta(ua()),"order-statuses",m=>{ta({...ua(),...m}),ae(!0)}),onBack:()=>{v("order-statuses"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="process-statuses-form")return Ve(t.jsx(z1,{form:Ni,setForm:na,formStatus:Ye,viewMode:qe||!p("process-statuses-form"),onEdit:p("process-statuses-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.processStatuses,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.processStatuses,m,Ni.name1):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.processStatuses,Ni,()=>na(pa()),"process-statuses",m=>{na({...pa(),...m}),ae(!0)}),onBack:()=>{v("process-statuses"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="users-form")return Ve(t.jsx(A1,{form:Pt,setForm:Vr,groupCompanies:De,organizations:H,managements:G,departments:D,branches:q,users:At,formStatus:Ye,viewMode:qe||!p("users-form"),onEdit:p("users-form")?()=>ae(!1):void 0,onRestore:l==="Admin"||l==="CEO"||l==="Business Owner"?m=>Je(P.users,m):void 0,onPermanentDelete:l==="Admin"||l==="CEO"||l==="Business Owner"?m=>de(P.users,m,Pt.full_name||Pt.email):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,isSelfProfile:mc,onSubmit:hg,onBack:()=>{v(mc?i?"dashboard":"inbox":"users"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));if(c==="delegations-form"){const m=Yt.status==="Revoked"||Yt.status==="Accepted"||Yt.status==="Rejected";return Ve(t.jsx(F1,{form:Yt,setForm:Qa,organizations:H,users:At,userRoleMap:K,incidents:A,ideas:ne,formStatus:Ye,viewMode:qe||!p("delegations-form")||m,onEdit:p("delegations-form")&&!m?()=>ae(!1):void 0,onRestore:l==="Admin"?$=>Je(P.delegations,$):void 0,onPermanentDelete:l==="Admin"?$=>de(P.delegations,$,Yt.name):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:Xh,onBack:()=>{v("delegations"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}))}if(c==="group-companies-form")return Ve(t.jsx(X0,{form:Ci,setForm:Ks,users:At,formStatus:Ye,viewMode:qe||!p("group-companies-form"),onEdit:p("group-companies-form")?()=>ae(!1):void 0,onRestore:l==="Admin"?m=>Je(P.groupCompanies,m):void 0,onPermanentDelete:l==="Admin"?m=>de(P.groupCompanies,m,Ci.company_name):void 0,darkMode:s,notifCount:u,onToggleDark:a,onCountChange:b,onViewProfile:Ke,onSubmit:()=>lt(P.groupCompanies,Ci,()=>Ks(qr()),"group-companies",m=>{Ks({...qr(),...m}),ae(!0)}),onBack:()=>{v("group-companies"),fe("idle")},onNavigate:v,onLogout:Qe,user:e}));const Fi={...r.pages,"group-companies":"Group Companies","group-companies-form":"Group Company Form"},gg={"group-companies":{color:J.purple,formPage:"group-companies-form",reset:()=>Ks(qr())},incidents:{color:J.accent,formPage:"incidents-form",reset:()=>{const m=z||o;Pn({...Ln(),organization:m,group_company:k||g(m)})}},ideas:{color:J.teal,formPage:"ideas-form",reset:()=>{const m=z||o;jn({...kn(),organization:m,group_company:k||g(m)})}},orders:{color:J.purple,formPage:"orders-form",reset:()=>{const m=z||o;bn({...Cn(),organization:m,group_company:k||g(m)})}},processes:{color:J.blue,formPage:"processes-form",reset:()=>{const m=ft.create_processes,$=z||(l==="Manager"&&m&&m.length===1?m[0]:o);Sn({...yl(),organization:$,group_company:k||g($)})}},organizations:{color:J.accent,formPage:"organizations-form",reset:()=>Xs({...aa(),group_company:k})},managements:{color:J.blue,formPage:"managements-form",reset:()=>{const m=z||o;js({...ks(),organization:m,group_company:k||g(m)})}},departments:{color:J.teal,formPage:"departments-form",reset:()=>{const m=z||o;bs({...Cs(),custom_organization:m,group_company:k||g(m)})}},branches:{color:J.purple,formPage:"branches-form",reset:()=>{const m=z||o;Ss({...zs(),organization:m,group_company:k||g(m)})}},cycles:{color:J.teal,formPage:"cycles-form",reset:()=>{const m=z||o;_s({...Is(),organization:m,group_company:k||g(m)})}},"kpi-input":{color:J.blue,formPage:"kpi-input-form",reset:()=>{const m=z||o;ws({...Es(),organization:m,group_company:k||g(m)})}},"incident-types":{color:J.red,formPage:"incident-types-form",reset:()=>Ys(ra())},"idea-types":{color:J.orange,formPage:"idea-types-form",reset:()=>qs(la())},"order-types":{color:J.green,formPage:"order-types-form",reset:()=>Js(ia())},"process-types":{color:J.accent,formPage:"process-types-form",reset:()=>Vs(oa())},"incident-statuses":{color:J.red,formPage:"incident-statuses-form",reset:()=>Zs(da())},"idea-statuses":{color:J.teal,formPage:"idea-statuses-form",reset:()=>ea(ca())},"order-statuses":{color:J.purple,formPage:"order-statuses-form",reset:()=>ta(ua())},"process-statuses":{color:J.blue,formPage:"process-statuses-form",reset:()=>na(pa())},users:{color:J.blue,formPage:"users-form",reset:()=>{Vr({...vl(),custom_group_company:k}),xc(!1)}},delegations:{color:J.purple,formPage:"delegations-form",reset:()=>Qa(rr())}},mg={"group-companies":"New Group Company",incidents:r.formTitle.newIncident,ideas:r.formTitle.newIdea,orders:r.formTitle.newOrder,processes:r.formTitle.newProcess,organizations:r.formTitle.newOrg,managements:r.formTitle.newMgmt,departments:r.formTitle.newDept,branches:r.formTitle.newBranch,users:r.formTitle.newUser,cycles:r.formTitle.newCycle,"kpi-input":r.formTitle.newKpi,delegations:r.formTitle.newDelegation,"incident-types":"New Incident Type","idea-types":"New Idea Type","order-types":"New Order Type","process-types":"New Process Type","incident-statuses":"New Incident Status","idea-statuses":"New Idea Status","order-statuses":"New Order Status","process-statuses":"New Process Status"},xg={incidents:A,ideas:ne,orders:W,processes:I,organizations:H,managements:G,departments:D,branches:q,cycles:vs,"kpi-input":Qr,"incident-types":ie,"idea-types":Wt,"order-types":me,"process-types":We,"incident-statuses":te,"idea-statuses":Ee,"order-statuses":he,"process-statuses":re,users:be,delegations:Xr},Ka=uy[c],Xa=xg[c],ee=p(c),Hi=ee?gg[c]:null;return t.jsxs("div",{style:{display:"flex",minHeight:"100vh",fontFamily:"Segoe UI",background:s?"#0f172a":J.bg},children:[t.jsx(uh,{collapsed:yh,onToggleCollapsed:jh,activePage:c,onNavigate:m=>v(m),hasDashboard:i,hasReports:d,hasDelegations:f,role:l,rtl:r.rtl,navLabels:r.nav,settingsLabel:r.nav.settings}),t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0},children:[t.jsx("div",{style:{background:s?"#1e293b":"#ffffff",padding:"6px 20px",borderBottom:`1px solid ${s?"#2d3748":"#e9eaf0"}`,display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,flexShrink:0,boxShadow:s?"none":"0 1px 4px rgba(0,0,0,0.04)"},children:t.jsx(hh,{notifCount:u,darkMode:s,onCountChange:b,onToggleDark:a,onNavigate:Mi,onViewProfile:Ke,onLogout:Qe,userName:e.full_name||e.name,userRole:l})}),c!=="profile"&&t.jsxs("div",{style:{background:s?"#1e293b":"white",padding:"12px 24px",borderBottom:`1px solid ${s?"#2d3748":"#e2e8f0"}`,display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:18,fontWeight:700,color:s?"#e2e8f0":"#0f172a"},children:Fi[c]||c}),Xa&&t.jsxs("div",{style:{fontSize:12,color:"#64748b",marginTop:2,fontWeight:500},children:["Total: ",Xa.length," ",Fi[c]?Fi[c].toLowerCase():"records"]})]}),t.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[Ka&&Xa&&t.jsx("button",{onClick:()=>zi(!0),style:{background:"#16a34a",color:"white",border:"none",padding:"7px 16px",borderRadius:8,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6,boxShadow:"0 1px 2px rgba(0,0,0,0.06)"},children:"📊 Export"}),Hi&&t.jsxs("button",{onClick:()=>{Hi.reset(),ae(!1),fe("idle"),v(Hi.formPage)},style:{background:"#2563eb",color:"white",border:"none",padding:"7px 16px",borderRadius:8,fontSize:13,cursor:"pointer",fontWeight:600,whiteSpace:"nowrap",fontFamily:"Segoe UI",display:"flex",alignItems:"center",gap:6,boxShadow:"0 1px 2px rgba(0,0,0,0.06)"},children:["+ ",mg[c]||r.new]})]})]}),Ka&&Xa&&bh&&t.jsx(wy,{title:Ka.label,rows:Xa,selectedRows:Sh,pageRows:_h,columns:Ka.columns,defaultColumnKeys:Ka.defaultColumns,filenameBase:c,onClose:()=>zi(!1)}),t.jsxs("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",padding:c==="profile"?0:"20px 24px",gap:c==="profile"?0:16},children:[Ae&&t.jsx("div",{style:{textAlign:"center",paddingTop:60,color:"#aaa",fontSize:15},children:r.loading}),!Ae&&c==="dashboard"&&i&&t.jsx(g0,{incidents:A,ideas:ne,orders:W,processes:I,organizations:H,incidentStatuses:te,ideaStatuses:Ee,orderStatuses:he,processStatuses:re,selectedOrg:o,onOrgChange:h,onNavigate:Mi,onNavigateStatus:S,userRole:l}),!Ae&&c==="inbox"&&t.jsx(K1,{onNavigate:Mi,onRefresh:qt}),!Ae&&c==="reports"&&d&&t.jsx(V1,{organizations:H,userRole:l}),!Ae&&c==="incidents"&&t.jsx(x0,{incidents:A,organizations:H,departments:D,branches:q,incidentStatuses:te,initialOrg:o,initialStatus:x,onView:kh,onEdit:ee?Lh:void 0,onDelete:ee?m=>de(P.incidents,m):void 0,canModify:ee,userRole:l,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="ideas"&&t.jsx(z0,{ideas:ne,organizations:H,departments:D,branches:q,ideaStatuses:Ee,initialOrg:o,initialStatus:x,onView:Ch,onEdit:ee?Wh:void 0,onDelete:ee?m=>de(P.ideas,m):void 0,canModify:ee,userRole:l,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="orders"&&t.jsx(A0,{orders:W,organizations:H,departments:D,branches:q,orderStatuses:he,initialOrg:o,initialStatus:x,onView:zh,onEdit:ee?Nh:void 0,onDelete:ee?m=>de(P.orders,m):void 0,canModify:ee,userRole:l,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="processes"&&t.jsx(B0,{processes:I,organizations:H,departments:D,branches:q,processStatuses:re,initialOrg:o,initialStatus:x,onView:Ih,onEdit:ee?$h:void 0,onDelete:ee?m=>de(P.processes,m):void 0,canModify:ee,userRole:l,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="organizations"&&t.jsx(G0,{organizations:H,onView:Eh,onEdit:ee?Uh:void 0,onDelete:ee?m=>de(P.organizations,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="group-companies"&&t.jsx(K0,{groupCompanies:De,onView:Th,onEdit:ee?Ah:void 0,onDelete:ee?m=>de(P.groupCompanies,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="managements"&&t.jsx(q0,{managements:G,onView:Ph,onEdit:ee?Mh:void 0,onDelete:ee?m=>de(P.managements,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="departments"&&t.jsx(Z0,{departments:D,managements:G,onView:Rh,onEdit:ee?Fh:void 0,onDelete:ee?m=>de(P.departments,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="branches"&&t.jsx(n1,{branches:q,managements:G,departments:D,onView:Oh,onEdit:ee?Hh:void 0,onDelete:ee?m=>de(P.branches,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="cycles"&&t.jsx(P1,{cycles:vs,canModify:ee,onView:Dh,onEdit:ee?Gh:void 0,onDelete:ee?m=>de(P.cycles,m):void 0,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="kpi-input"&&t.jsx(B1,{kpiInputs:Qr,canModify:ee,onView:Bh,onEdit:ee?Qh:void 0,onDelete:ee?m=>de(P.kpiInput,m):void 0,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="incident-types"&&t.jsx(r1,{incidentTypes:ie,onView:qh,onEdit:ee?Jh:void 0,onDelete:ee?m=>de(P.incidentTypes,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="idea-types"&&t.jsx(o1,{ideaTypes:Wt,onView:Vh,onEdit:ee?Zh:void 0,onDelete:ee?m=>de(P.ideaTypes,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="order-types"&&t.jsx(u1,{orderTypes:me,onView:eg,onEdit:ee?tg:void 0,onDelete:ee?m=>de(P.orderTypes,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="process-types"&&t.jsx(h1,{processTypes:We,onView:ng,onEdit:ee?sg:void 0,onDelete:ee?m=>de(P.processTypes,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="incident-statuses"&&t.jsx(x1,{incidentStatuses:te,onView:ag,onEdit:ee?rg:void 0,onDelete:ee?m=>de(P.incidentStatuses,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="idea-statuses"&&t.jsx(j1,{ideaStatuses:Ee,onView:lg,onEdit:ee?ig:void 0,onDelete:ee?m=>de(P.ideaStatuses,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="order-statuses"&&t.jsx(_1,{orderStatuses:he,onView:og,onEdit:ee?dg:void 0,onDelete:ee?m=>de(P.orderStatuses,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="process-statuses"&&t.jsx(C1,{processStatuses:re,onView:cg,onEdit:ee?ug:void 0,onDelete:ee?m=>de(P.processStatuses,m):void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="users"&&t.jsx(T1,{users:be,roleMap:K,onView:pg,onEdit:ee?fg:void 0,onDelete:ee?m=>de("User",m):void 0,onDisable:ee?wh:void 0,canModify:ee,onSelectionChange:(m,$)=>{He(m),Ge($)}}),!Ae&&c==="delegations"&&f&&t.jsx(U1,{delegations:Xr,organizations:H,userRole:l,currentUser:e.name,onView:Kh,onRevoke:ee?Yh:void 0,onSelectionChange:(m,$)=>{He(m),Ge($)}}),c==="profile"&&(()=>{const m=!!Jr&&(Jr.name===e.name||Jr.email===e.name);return t.jsx(M0,{user:e,profileUser:Jr,sbUsers:be,organizations:H,groupCompanies:De,managements:G,departments:D,branches:q,darkMode:s,canModify:ee||m,onBack:()=>v(m?i?"dashboard":"inbox":"users"),onNavigate:v})})()]})]}),t.jsx(Ru,{isOpen:xt.isOpen,doctype:xt.doctype,docname:xt.name,docTitle:xt.title,isAdmin:l==="Admin"||e.name==="Administrator",isDeleting:xt.isDeleting,onClose:()=>Dn(m=>({...m,isOpen:!1})),onConfirmSoftDelete:bc,onConfirmPermanentDelete:Sc})]})}function iv(e){return e.some(n=>["CEO","Ceo","SB CEO","Chairman"].includes(n))?"CEO":e.some(n=>["Business Owner","SB Business Owner","SB Owner","Owner"].includes(n))?"Business Owner":e.some(n=>["SB Admin","System Manager","Administrator"].includes(n))?"Admin":e.includes("SB Manager")?"Manager":e.includes("SB Auditor")?"Auditor":e.includes("SB X-Auditor")?"XAuditor":"Employee"}function ov(){const[e,n]=_.useState(()=>{try{const d=localStorage.getItem("sidrah_user");return d?JSON.parse(d):null}catch{return null}}),[s,a]=_.useState(()=>localStorage.getItem("sb_dark")==="1"),r=()=>{const d=!s;a(d),localStorage.setItem("sb_dark",d?"1":"0"),document.documentElement.classList.toggle("dark",d)};_.useEffect(()=>{document.documentElement.classList.toggle("dark",s)},[]),_.useEffect(()=>{e&&ph().then(async d=>{const f=d||e.name,p=await fh(f);if(!p.length)return;const C=iv(p),j=await Uy();if(C!==e.role||f!==e.name||j!==(e.custom_organization||"")){const c={...e,name:f,role:C,custom_organization:j};n(c),localStorage.setItem("sidrah_user",JSON.stringify(c))}})},[e==null?void 0:e.name]);const l=d=>{n(d),localStorage.setItem("sidrah_user",JSON.stringify(d))},i=()=>{n(null),localStorage.removeItem("sidrah_user")};return e?t.jsx(lv,{user:e,onLogout:i,darkMode:s,onToggleDark:r}):t.jsx(o0,{onLogin:l})}lh(document.getElementById("root")).render(t.jsx(_.StrictMode,{children:t.jsx(ov,{})}));