@jield/solodb-react-components 1.0.25 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -32,7 +32,7 @@ Arguments: `+Array.prototype.slice.call(r).join("")+`
32
32
  `},i),a}function wV(e,t){return e&&"run"in e?async function(n,r){const i=Eg(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Eg(n,{file:r,...e||t})}}function kg(e){if(e)throw e}var pu,Ng;function CV(){if(Ng)return pu;Ng=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},a=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var d=e.call(u,"constructor"),p=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!d&&!p)return!1;var g;for(g in u);return typeof g>"u"||e.call(u,g)},o=function(u,d){n&&d.name==="__proto__"?n(u,d.name,{enumerable:!0,configurable:!0,value:d.newValue,writable:!0}):u[d.name]=d.newValue},l=function(u,d){if(d==="__proto__")if(e.call(u,d)){if(r)return r(u,d).value}else return;return u[d]};return pu=function c(){var u,d,p,g,m,v,I=arguments[0],C=1,b=arguments.length,_=!1;for(typeof I=="boolean"&&(_=I,I=arguments[1]||{},C=2),(I==null||typeof I!="object"&&typeof I!="function")&&(I={});C<b;++C)if(u=arguments[C],u!=null)for(d in u)p=l(I,d),g=l(u,d),I!==g&&(_&&g&&(a(g)||(m=i(g)))?(m?(m=!1,v=p&&i(p)?p:[]):v=p&&a(p)?p:{},o(I,{name:d,newValue:c(_,v,g)})):typeof g<"u"&&o(I,{name:d,newValue:g}));return I},pu}var SV=CV();const mu=Qr(SV);function md(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function jV(){const e=[],t={run:n,use:r};return t;function n(...i){let a=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...i);function l(c,...u){const d=e[++a];let p=-1;if(c){o(c);return}for(;++p<i.length;)(u[p]===null||u[p]===void 0)&&(u[p]=i[p]);i=u,d?IV(d,l)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function IV(e,t){let n;return r;function r(...o){const l=e.length>o.length;let c;l&&o.push(i);try{c=e.apply(this,o)}catch(u){const d=u;if(l&&n)throw d;return i(d)}l||(c&&c.then&&typeof c.then=="function"?c.then(a,i):c instanceof Error?i(c):a(c))}function i(o,...l){n||(n=!0,t(o,...l))}function a(o){i(null,o)}}const Qn={basename:_V,dirname:EV,extname:kV,join:NV,sep:"/"};function _V(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Ya(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function EV(e){if(Ya(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function kV(e){Ya(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function NV(...e){let t=-1,n;for(;++t<e.length;)Ya(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":AV(n)}function AV(e){Ya(e);const t=e.codePointAt(0)===47;let n=RV(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function RV(e,t){let n="",r=0,i=-1,a=0,o=-1,l,c;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||a===1))if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),i=o,a=0;continue}}else if(n.length>0){n="",r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else l===46&&a>-1?a++:a=-1}return n}function Ya(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const DV={cwd:MV};function MV(){return"/"}function hd(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function OV(e){if(typeof e=="string")e=new URL(e);else if(!hd(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return TV(e)}function TV(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const hu=["history","path","basename","stem","extname","dirname"];class L0{constructor(t){let n;t?hd(t)?n={path:t}:typeof t=="string"||FV(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":DV.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<hu.length;){const a=hu[r];a in n&&n[a]!==void 0&&n[a]!==null&&(this[a]=a==="history"?[...n[a]]:n[a])}let i;for(i in n)hu.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Qn.basename(this.path):void 0}set basename(t){xu(t,"basename"),gu(t,"basename"),this.path=Qn.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Qn.dirname(this.path):void 0}set dirname(t){Ag(this.basename,"dirname"),this.path=Qn.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Qn.extname(this.path):void 0}set extname(t){if(gu(t,"extname"),Ag(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=Qn.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){hd(t)&&(t=OV(t)),xu(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Qn.basename(this.path,this.extname):void 0}set stem(t){xu(t,"stem"),gu(t,"stem"),this.path=Qn.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new nn(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function gu(e,t){if(e&&e.includes(Qn.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Qn.sep+"`")}function xu(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Ag(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function FV(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const PV=(function(e){const r=this.constructor.prototype,i=r[e],a=function(){return i.apply(a,arguments)};return Object.setPrototypeOf(a,r),a}),LV={}.hasOwnProperty;class np extends PV{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=jV()}copy(){const t=new np;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(mu(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(bu("data",this.frozen),this.namespace[t]=n,this):LV.call(this.namespace,t)&&this.namespace[t]||void 0:t?(bu("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=wo(t),r=this.parser||this.Parser;return vu("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),vu("process",this.parser||this.Parser),yu("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(a,o){const l=wo(t),c=r.parse(l);r.run(c,l,function(d,p,g){if(d||!p||!g)return u(d);const m=p,v=r.stringify(m,g);BV(v)?g.value=v:g.result=v,u(d,g)});function u(d,p){d||!p?o(d):a?a(p):n(void 0,p)}}}processSync(t){let n=!1,r;return this.freeze(),vu("processSync",this.parser||this.Parser),yu("processSync",this.compiler||this.Compiler),this.process(t,i),Dg("processSync","process",n),r;function i(a,o){n=!0,kg(a),r=o}}run(t,n,r){Rg(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?a(void 0,r):new Promise(a);function a(o,l){const c=wo(n);i.run(t,c,u);function u(d,p,g){const m=p||t;d?l(d):o?o(m):r(void 0,m,g)}}}runSync(t,n){let r=!1,i;return this.run(t,n,a),Dg("runSync","run",r),i;function a(o,l){kg(o),i=l,r=!0}}stringify(t,n){this.freeze();const r=wo(n),i=this.compiler||this.Compiler;return yu("stringify",i),Rg(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(bu("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function a(u){if(typeof u=="function")c(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[d,...p]=u;c(d,p)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(i.settings=mu(!0,i.settings,u.settings))}function l(u){let d=-1;if(u!=null)if(Array.isArray(u))for(;++d<u.length;){const p=u[d];a(p)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function c(u,d){let p=-1,g=-1;for(;++p<r.length;)if(r[p][0]===u){g=p;break}if(g===-1)r.push([u,...d]);else if(d.length>0){let[m,...v]=d;const I=r[g][1];md(I)&&md(m)&&(m=mu(!0,I,m)),r[g]=[u,m,...v]}}}}const VV=new np().freeze();function vu(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function yu(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function bu(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Rg(e){if(!md(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function Dg(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function wo(e){return GV(e)?e:new L0(e)}function GV(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function BV(e){return typeof e=="string"||YV(e)}function YV(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const WV="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Mg=[],Og={allowDangerousHtml:!0},zV=/^(https?|ircs?|mailto|xmpp)$/i,HV=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function Ai(e){const t=UV(e),n=$V(e);return XV(t.runSync(t.parse(n),n),e)}function UV(e){const t=e.rehypePlugins||Mg,n=e.remarkPlugins||Mg,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Og}:Og;return VV().use(_3).use(n).use(wV,r).use(t)}function $V(e){const t=e.children||"",n=new L0;return typeof t=="string"&&(n.value=t),n}function XV(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,c=t.urlTransform||qV;for(const d of HV)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+WV+d.id,void 0);return P0(e,u),sL(e,{Fragment:s.Fragment,components:i,ignoreInvalidStyle:!0,jsx:s.jsx,jsxs:s.jsxs,passKeys:!0,passNode:!0});function u(d,p,g){if(d.type==="raw"&&g&&typeof p=="number")return o?g.children.splice(p,1):g.children[p]={type:"text",value:d.value},p;if(d.type==="element"){let m;for(m in uu)if(Object.hasOwn(uu,m)&&Object.hasOwn(d.properties,m)){const v=d.properties[m],I=uu[m];(I===null||I.includes(d.tagName))&&(d.properties[m]=c(String(v||""),m,d))}}if(d.type==="element"){let m=n?!n.includes(d.tagName):a?a.includes(d.tagName):!1;if(!m&&r&&typeof p=="number"&&(m=!r(d,p,g)),m&&g&&typeof p=="number")return l&&d.children?g.children.splice(p,1,...d.children):g.children.splice(p,1),p}}}function qV(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||zV.test(e.slice(0,t))?e:""}function Tg({ecn:e,equipment:t,ecnAttachments:n,reloadQueryFn:r,expanded:i=!0}){const[a,o]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(e),[p,g]=x.useState(i),m=C=>{r(["ecn","attachment","status_mail"]),d({...u,...C})},v=()=>n.filter(C=>C.ecn.id===e.id),I=()=>{o(s.jsx(Pl,{equipment:t,showModal:!0,onClose:C=>{c(!1),C&&(r(["ecn","attachment","status_mail"]),m(C))},ecn:u,attachments:v()})),c(!0)};return s.jsxs("div",{className:"p-3 mb-4 border-bottom",children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-2",children:[s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(Ft,{bg:"dark",children:"ECN"}),s.jsx("h4",{className:u.date_closed?"text-danger mb-0":"mb-0",children:u.date_closed?s.jsx("s",{children:u.ecn}):u.ecn})]}),s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(ie,{variant:"outline-primary",size:"sm",onClick:()=>g(C=>!C),"aria-label":"Toggle Details",children:p?"Hide Details":"Show Details"}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:I,"aria-label":"Edit ECN",children:"Edit"})]})]}),p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mb-3",children:s.jsx(Ai,{children:u.description})}),s.jsxs("div",{className:"d-flex flex-wrap text-muted",children:[s.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[s.jsx("small",{className:"text-muted",children:"Creator"}),s.jsx("div",{className:"text-body",children:u.owner.full_name})]}),s.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[s.jsx("small",{className:"text-muted",children:"Date Created"}),s.jsx("div",{className:"text-body",children:ye(u.date_created).format("DD MMMM YYYY")})]}),u.date_closed&&s.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[s.jsx("small",{className:"text-muted",children:"Date Closed"}),s.jsx("div",{className:"text-danger",children:ye(u.date_closed).format("DD MMMM YYYY")})]}),s.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[s.jsx("small",{className:"text-muted",children:"Attachments"}),s.jsx("div",{className:"text-body",children:u.attachments})]}),u.updated_by&&s.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[s.jsx("small",{className:"text-muted",children:"Last Update By"}),s.jsx("div",{className:"text-body",children:u.updated_by.full_name})]}),u.last_update&&s.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[s.jsx("small",{className:"text-muted",children:"Last Update"}),s.jsx("div",{className:"text-body",children:ye(u.last_update).format("DD MMMM YYYY")})]})]})]}),l&&a]})}const Wa=({equipment:e,showModal:t,onClose:n,issue:r,attachments:i})=>{const[a,o]=x.useState([]),[l,c]=x.useState([]),{user:u}=x.useContext(hs),[d,p]=x.useState(i),{register:g,handleSubmit:m,reset:v,control:I}=tn({defaultValues:{issue:r?.issue||"",description:r?.description||"",issue_type:r?.issue_type||_r.DEFAULT,status:r?.status||qs.ACTIVE,forecast_up:r?.forecast_up?new Date(r?.forecast_up).toISOString().split("T")[0]:"",actions:r?.actions||"",owner:r?.owner||{}}});x.useEffect(()=>{r&&v({issue:r?.issue||"",description:r?.description||"",issue_type:r?.issue_type||_r.DEFAULT,status:r?.status||qs.ACTIVE,forecast_up:r?.forecast_up?new Date(r?.forecast_up).toISOString().split("T")[0]:"",actions:r?.actions||"",owner:r?.owner||{}})},[r,v]);const{getRootProps:C,getInputProps:b,isDragActive:_}=Ta({accept:{"application/*":[],"image/*":[]},onDrop:A=>{o(F=>[...F,...A])}});x.useEffect(()=>{t&&(async()=>{if(e?.id)try{const F=await xi({equipment:e});c(F.items||[])}catch(F){console.error("Error fetching modules:",F)}})()},[e,t]);async function y(){await te.delete(`/delete/equipment/module/issue/${r?.id}`);const A={...r,date_closed:new Date().toISOString(),last_update:new Date().toISOString(),updated_by:u?.full_name};n(A)}const S=A=>{o(F=>F.filter((L,Y)=>Y!==A))},j=A=>{d&&p(F=>F?.filter((L,Y)=>Y!==A))},N=(A,F)=>new Promise(async(L,Y)=>{try{if(d&&i&&i!=d)for(let G=0;G<i.length;G++){const X=i[G].id;let H=!1;for(let T=0;T<d.length;T++){const V=d[T].id;if(X==V){H=!0;break}}H||await te.delete(`/delete/equipment/module/issue/attachment/${i[G].id}`)}A.length>0&&F&&await Promise.all(A.map(async G=>{const X=await Xg(G),H={issue_id:F,filename:G.name,type:G.type,content:X};await te.post("/create/equipment/module/issue/attachment",H)})),L()}catch(G){Y(G)}}),k=async A=>{try{let F;const L={module_id:A.module_id,issue:A.issue,description:A.description,owner:A?.owner.value||r?.owner,status:A.status,issue_type:A.issue_type,actions:A.actions,forecast_up:A.forecast_up};r?(await N(a,r.id),F=(await te.patch(`/update/equipment/module/issue/${r?.id}`,L)).data):(F=(await te.post("/create/equipment/module/issue",L)).data,N(a,F.id),F.attachments=a.length),n(F)}catch(F){console.error("Error submitting the form:",F)}};return x.useEffect(()=>{t&&(async()=>{if(e?.id)try{const F=await xi({equipment:e});c(F.items||[])}catch(F){console.error("Error fetching modules:",F)}})()},[e,t]),s.jsx(ve,{show:t,size:"lg",centered:!0,onHide:()=>n(r),children:s.jsxs(W,{onSubmit:m(k),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:r?`Edit Issue for ${e.name}`:`Create new Issue for ${e.name}`})}),s.jsxs(ve.Body,{children:[!r&&s.jsxs(W.Group,{controlId:"module",className:"mb-3",children:[s.jsx(W.Label,{children:"Module"}),s.jsxs(W.Select,{...g("module_id",{required:"Module is required"}),children:[s.jsx("option",{value:"",children:"— Select a module"}),l.map(A=>s.jsx("option",{value:A.id,children:A.name},A.id))]})]}),s.jsxs(W.Group,{controlId:"issue",children:[s.jsx(W.Label,{children:"Issue"}),s.jsx(W.Control,{type:"text",...g("issue",{required:"Issue content is required"}),autoFocus:!0})]}),s.jsxs(W.Group,{controlId:"description",className:"mt-3",children:[s.jsx(W.Label,{children:"Description"}),s.jsx(W.Control,{as:"textarea",rows:3,...g("description",{required:"Description is required"})})]}),s.jsxs(W.Group,{controlId:"issueType",className:"mt-3",children:[s.jsx(W.Label,{children:"Issue"}),s.jsxs(W.Control,{as:"select",...g("issue_type",{required:"Issue type is required"}),children:[s.jsx("option",{value:_r.DEFAULT,children:"Default"}),s.jsx("option",{value:_r.PRIORITY,children:"Priority"}),s.jsx("option",{value:_r.ESCALATION,children:"Escalation"})]})]}),s.jsxs(W.Group,{controlId:"status",className:"mt-3",children:[s.jsx(W.Label,{children:"Status"}),s.jsxs(W.Control,{as:"select",...g("status",{required:"Status is required"}),children:[s.jsx("option",{value:qs.ACTIVE,children:"Active"}),s.jsx("option",{value:qs.CLOSED,children:"Closed"})]})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Owner"}),s.jsx(Fa,{control:I,...g("owner",{required:"Owner is required"}),name:"owner"})]}),s.jsxs(W.Group,{controlId:"forecastUp",className:"mt-3",children:[s.jsx(W.Label,{children:"Forecast Up"}),s.jsx(W.Control,{type:"date",...g("forecast_up",{required:"Forecast Up date is required"})})]}),s.jsxs(W.Group,{controlId:"actions",className:"mt-3",children:[s.jsx(W.Label,{children:"Actions"}),s.jsx(W.Control,{as:"textarea",rows:5,...g("actions",{required:!1})})]}),s.jsxs(W.Group,{children:[s.jsx(W.Label,{children:"Attachments"}),s.jsxs("div",{...C({className:`dropzone ${_?"active":""}`,style:{border:"2px dashed #007bff",padding:"10px",textAlign:"center"}}),children:[s.jsx("input",{...b()}),_?s.jsx("p",{children:"Drop the files here..."}):s.jsx("p",{children:"Drag & drop files here, or click to select files"})]}),a.length>0&&s.jsx("ul",{children:a.map((A,F)=>s.jsxs("li",{children:[A.name," ",s.jsx(ie,{variant:"secondary",onClick:()=>S(F),children:"cancel"})]},F))})]}),d&&d.length>0&&s.jsxs(W.Group,{controlId:"uploaded_files",className:"mt-3",children:[s.jsx(W.Label,{children:"Uploaded files"}),s.jsx("ul",{children:d.map((A,F)=>s.jsxs("li",{children:[A.filename," ",s.jsx(ie,{variant:"secondary",onClick:()=>j(F),children:"delete"})]},F))})]})]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{variant:"secondary",onClick:()=>n(r),children:"Cancel"}),s.jsx(ie,{variant:"primary",type:"submit",children:r?"Update Issue":"Create Issue"}),r&&s.jsx(ie,{variant:"danger",onClick:()=>y(),children:"Close Issue"})]})]})})};function ZV(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Oo={exports:{}},JV=Oo.exports,Fg;function QV(){return Fg||(Fg=1,(function(e,t){(function(n,r){e.exports=r()})(JV,(function(){var n;function r(){return n.apply(null,arguments)}function i(f){n=f}function a(f){return f instanceof Array||Object.prototype.toString.call(f)==="[object Array]"}function o(f){return f!=null&&Object.prototype.toString.call(f)==="[object Object]"}function l(f,h){return Object.prototype.hasOwnProperty.call(f,h)}function c(f){if(Object.getOwnPropertyNames)return Object.getOwnPropertyNames(f).length===0;var h;for(h in f)if(l(f,h))return!1;return!0}function u(f){return f===void 0}function d(f){return typeof f=="number"||Object.prototype.toString.call(f)==="[object Number]"}function p(f){return f instanceof Date||Object.prototype.toString.call(f)==="[object Date]"}function g(f,h){var w=[],E,D=f.length;for(E=0;E<D;++E)w.push(h(f[E],E));return w}function m(f,h){for(var w in h)l(h,w)&&(f[w]=h[w]);return l(h,"toString")&&(f.toString=h.toString),l(h,"valueOf")&&(f.valueOf=h.valueOf),f}function v(f,h,w,E){return _p(f,h,w,E,!0).utc()}function I(){return{empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidEra:null,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1,parsedDateParts:[],era:null,meridiem:null,rfc2822:!1,weekdayMismatch:!1}}function C(f){return f._pf==null&&(f._pf=I()),f._pf}var b;Array.prototype.some?b=Array.prototype.some:b=function(f){var h=Object(this),w=h.length>>>0,E;for(E=0;E<w;E++)if(E in h&&f.call(this,h[E],E,h))return!0;return!1};function _(f){var h=null,w=!1,E=f._d&&!isNaN(f._d.getTime());if(E&&(h=C(f),w=b.call(h.parsedDateParts,function(D){return D!=null}),E=h.overflow<0&&!h.empty&&!h.invalidEra&&!h.invalidMonth&&!h.invalidWeekday&&!h.weekdayMismatch&&!h.nullInput&&!h.invalidFormat&&!h.userInvalidated&&(!h.meridiem||h.meridiem&&w),f._strict&&(E=E&&h.charsLeftOver===0&&h.unusedTokens.length===0&&h.bigHour===void 0)),Object.isFrozen==null||!Object.isFrozen(f))f._isValid=E;else return E;return f._isValid}function y(f){var h=v(NaN);return f!=null?m(C(h),f):C(h).userInvalidated=!0,h}var S=r.momentProperties=[],j=!1;function N(f,h){var w,E,D,B=S.length;if(u(h._isAMomentObject)||(f._isAMomentObject=h._isAMomentObject),u(h._i)||(f._i=h._i),u(h._f)||(f._f=h._f),u(h._l)||(f._l=h._l),u(h._strict)||(f._strict=h._strict),u(h._tzm)||(f._tzm=h._tzm),u(h._isUTC)||(f._isUTC=h._isUTC),u(h._offset)||(f._offset=h._offset),u(h._pf)||(f._pf=C(h)),u(h._locale)||(f._locale=h._locale),B>0)for(w=0;w<B;w++)E=S[w],D=h[E],u(D)||(f[E]=D);return f}function k(f){N(this,f),this._d=new Date(f._d!=null?f._d.getTime():NaN),this.isValid()||(this._d=new Date(NaN)),j===!1&&(j=!0,r.updateOffset(this),j=!1)}function A(f){return f instanceof k||f!=null&&f._isAMomentObject!=null}function F(f){r.suppressDeprecationWarnings===!1&&typeof console<"u"&&console.warn&&console.warn("Deprecation warning: "+f)}function L(f,h){var w=!0;return m(function(){if(r.deprecationHandler!=null&&r.deprecationHandler(null,f),w){var E=[],D,B,K,Se=arguments.length;for(B=0;B<Se;B++){if(D="",typeof arguments[B]=="object"){D+=`
33
33
  [`+B+"] ";for(K in arguments[0])l(arguments[0],K)&&(D+=K+": "+arguments[0][K]+", ");D=D.slice(0,-2)}else D=arguments[B];E.push(D)}F(f+`
34
34
  Arguments: `+Array.prototype.slice.call(E).join("")+`
35
- `+new Error().stack),w=!1}return h.apply(this,arguments)},h)}var Y={};function G(f,h){r.deprecationHandler!=null&&r.deprecationHandler(f,h),Y[f]||(F(h),Y[f]=!0)}r.suppressDeprecationWarnings=!1,r.deprecationHandler=null;function X(f){return typeof Function<"u"&&f instanceof Function||Object.prototype.toString.call(f)==="[object Function]"}function H(f){var h,w;for(w in f)l(f,w)&&(h=f[w],X(h)?this[w]=h:this["_"+w]=h);this._config=f,this._dayOfMonthOrdinalParseLenient=new RegExp((this._dayOfMonthOrdinalParse.source||this._ordinalParse.source)+"|"+/\d{1,2}/.source)}function T(f,h){var w=m({},f),E;for(E in h)l(h,E)&&(o(f[E])&&o(h[E])?(w[E]={},m(w[E],f[E]),m(w[E],h[E])):h[E]!=null?w[E]=h[E]:delete w[E]);for(E in f)l(f,E)&&!l(h,E)&&o(f[E])&&(w[E]=m({},w[E]));return w}function V(f){f!=null&&this.set(f)}var Z;Object.keys?Z=Object.keys:Z=function(f){var h,w=[];for(h in f)l(f,h)&&w.push(h);return w};var ne={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"};function de(f,h,w){var E=this._calendar[f]||this._calendar.sameElse;return X(E)?E.call(h,w):E}function R(f,h,w){var E=""+Math.abs(f),D=h-E.length,B=f>=0;return(B?w?"+":"":"-")+Math.pow(10,Math.max(0,D)).toString().substr(1)+E}var ee=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,se=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,O={},ae={};function Q(f,h,w,E){var D=E;typeof E=="string"&&(D=function(){return this[E]()}),f&&(ae[f]=D),h&&(ae[h[0]]=function(){return R(D.apply(this,arguments),h[1],h[2])}),w&&(ae[w]=function(){return this.localeData().ordinal(D.apply(this,arguments),f)})}function pe(f){return f.match(/\[[\s\S]/)?f.replace(/^\[|\]$/g,""):f.replace(/\\/g,"")}function we(f){var h=f.match(ee),w,E;for(w=0,E=h.length;w<E;w++)ae[h[w]]?h[w]=ae[h[w]]:h[w]=pe(h[w]);return function(D){var B="",K;for(K=0;K<E;K++)B+=X(h[K])?h[K].call(D,f):h[K];return B}}function be(f,h){return f.isValid()?(h=Ee(h,f.localeData()),O[h]=O[h]||we(h),O[h](f)):f.localeData().invalidDate()}function Ee(f,h){var w=5;function E(D){return h.longDateFormat(D)||D}for(se.lastIndex=0;w>=0&&se.test(f);)f=f.replace(se,E),se.lastIndex=0,w-=1;return f}var ke={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};function Ve(f){var h=this._longDateFormat[f],w=this._longDateFormat[f.toUpperCase()];return h||!w?h:(this._longDateFormat[f]=w.match(ee).map(function(E){return E==="MMMM"||E==="MM"||E==="DD"||E==="dddd"?E.slice(1):E}).join(""),this._longDateFormat[f])}var le="Invalid date";function We(){return this._invalidDate}var dt="%d",Pe=/\d{1,2}/;function At(f){return this._ordinal.replace("%d",f)}var Rt={future:"in %s",past:"%s ago",s:"a few seconds",ss:"%d seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",w:"a week",ww:"%d weeks",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function jt(f,h,w,E){var D=this._relativeTime[w];return X(D)?D(f,h,w,E):D.replace(/%d/i,f)}function Dt(f,h){var w=this._relativeTime[f>0?"future":"past"];return X(w)?w(h):w.replace(/%s/i,h)}var ze={D:"date",dates:"date",date:"date",d:"day",days:"day",day:"day",e:"weekday",weekdays:"weekday",weekday:"weekday",E:"isoWeekday",isoweekdays:"isoWeekday",isoweekday:"isoWeekday",DDD:"dayOfYear",dayofyears:"dayOfYear",dayofyear:"dayOfYear",h:"hour",hours:"hour",hour:"hour",ms:"millisecond",milliseconds:"millisecond",millisecond:"millisecond",m:"minute",minutes:"minute",minute:"minute",M:"month",months:"month",month:"month",Q:"quarter",quarters:"quarter",quarter:"quarter",s:"second",seconds:"second",second:"second",gg:"weekYear",weekyears:"weekYear",weekyear:"weekYear",GG:"isoWeekYear",isoweekyears:"isoWeekYear",isoweekyear:"isoWeekYear",w:"week",weeks:"week",week:"week",W:"isoWeek",isoweeks:"isoWeek",isoweek:"isoWeek",y:"year",years:"year",year:"year"};function P(f){return typeof f=="string"?ze[f]||ze[f.toLowerCase()]:void 0}function z(f){var h={},w,E;for(E in f)l(f,E)&&(w=P(E),w&&(h[w]=f[E]));return h}var J={date:9,day:11,weekday:11,isoWeekday:11,dayOfYear:4,hour:13,millisecond:16,minute:14,month:8,quarter:7,second:15,weekYear:1,isoWeekYear:1,week:5,isoWeek:5,year:1};function he(f){var h=[],w;for(w in f)l(f,w)&&h.push({unit:w,priority:J[w]});return h.sort(function(E,D){return E.priority-D.priority}),h}var q=/\d/,M=/\d\d/,U=/\d{3}/,re=/\d{4}/,me=/[+-]?\d{6}/,ge=/\d\d?/,Je=/\d\d\d\d?/,Ct=/\d\d\d\d\d\d?/,Mt=/\d{1,3}/,Ut=/\d{1,4}/,Vt=/[+-]?\d{1,6}/,ft=/\d+/,Yt=/[+-]?\d+/,$t=/Z|[+-]\d\d:?\d\d/gi,Vn=/Z|[+-]\d\d(?::?\d\d)?/gi,nc=/[+-]?\d+(\.\d{1,3})?/,Es=/[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,Di=/^[1-9]\d?/,rc=/^([1-9]\d|\d)/,Ha;Ha={};function je(f,h,w){Ha[f]=X(h)?h:function(E,D){return E&&w?w:h}}function _w(f,h){return l(Ha,f)?Ha[f](h._strict,h._locale):new RegExp(Ew(f))}function Ew(f){return fr(f.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(h,w,E,D,B){return w||E||D||B}))}function fr(f){return f.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function En(f){return f<0?Math.ceil(f)||0:Math.floor(f)}function Ue(f){var h=+f,w=0;return h!==0&&isFinite(h)&&(w=En(h)),w}var ic={};function ot(f,h){var w,E=h,D;for(typeof f=="string"&&(f=[f]),d(h)&&(E=function(B,K){K[h]=Ue(B)}),D=f.length,w=0;w<D;w++)ic[f[w]]=E}function ks(f,h){ot(f,function(w,E,D,B){D._w=D._w||{},h(w,D._w,D,B)})}function kw(f,h,w){h!=null&&l(ic,f)&&ic[f](h,w._a,w,f)}function Ua(f){return f%4===0&&f%100!==0||f%400===0}var Zt=0,pr=1,Zn=2,Gt=3,Gn=4,mr=5,ti=6,Nw=7,Aw=8;Q("Y",0,0,function(){var f=this.year();return f<=9999?R(f,4):"+"+f}),Q(0,["YY",2],0,function(){return this.year()%100}),Q(0,["YYYY",4],0,"year"),Q(0,["YYYYY",5],0,"year"),Q(0,["YYYYYY",6,!0],0,"year"),je("Y",Yt),je("YY",ge,M),je("YYYY",Ut,re),je("YYYYY",Vt,me),je("YYYYYY",Vt,me),ot(["YYYYY","YYYYYY"],Zt),ot("YYYY",function(f,h){h[Zt]=f.length===2?r.parseTwoDigitYear(f):Ue(f)}),ot("YY",function(f,h){h[Zt]=r.parseTwoDigitYear(f)}),ot("Y",function(f,h){h[Zt]=parseInt(f,10)});function Ns(f){return Ua(f)?366:365}r.parseTwoDigitYear=function(f){return Ue(f)+(Ue(f)>68?1900:2e3)};var up=Mi("FullYear",!0);function Rw(){return Ua(this.year())}function Mi(f,h){return function(w){return w!=null?(dp(this,f,w),r.updateOffset(this,h),this):As(this,f)}}function As(f,h){if(!f.isValid())return NaN;var w=f._d,E=f._isUTC;switch(h){case"Milliseconds":return E?w.getUTCMilliseconds():w.getMilliseconds();case"Seconds":return E?w.getUTCSeconds():w.getSeconds();case"Minutes":return E?w.getUTCMinutes():w.getMinutes();case"Hours":return E?w.getUTCHours():w.getHours();case"Date":return E?w.getUTCDate():w.getDate();case"Day":return E?w.getUTCDay():w.getDay();case"Month":return E?w.getUTCMonth():w.getMonth();case"FullYear":return E?w.getUTCFullYear():w.getFullYear();default:return NaN}}function dp(f,h,w){var E,D,B,K,Se;if(!(!f.isValid()||isNaN(w))){switch(E=f._d,D=f._isUTC,h){case"Milliseconds":return void(D?E.setUTCMilliseconds(w):E.setMilliseconds(w));case"Seconds":return void(D?E.setUTCSeconds(w):E.setSeconds(w));case"Minutes":return void(D?E.setUTCMinutes(w):E.setMinutes(w));case"Hours":return void(D?E.setUTCHours(w):E.setHours(w));case"Date":return void(D?E.setUTCDate(w):E.setDate(w));case"FullYear":break;default:return}B=w,K=f.month(),Se=f.date(),Se=Se===29&&K===1&&!Ua(B)?28:Se,D?E.setUTCFullYear(B,K,Se):E.setFullYear(B,K,Se)}}function Dw(f){return f=P(f),X(this[f])?this[f]():this}function Mw(f,h){if(typeof f=="object"){f=z(f);var w=he(f),E,D=w.length;for(E=0;E<D;E++)this[w[E].unit](f[w[E].unit])}else if(f=P(f),X(this[f]))return this[f](h);return this}function Ow(f,h){return(f%h+h)%h}var Et;Array.prototype.indexOf?Et=Array.prototype.indexOf:Et=function(f){var h;for(h=0;h<this.length;++h)if(this[h]===f)return h;return-1};function sc(f,h){if(isNaN(f)||isNaN(h))return NaN;var w=Ow(h,12);return f+=(h-w)/12,w===1?Ua(f)?29:28:31-w%7%2}Q("M",["MM",2],"Mo",function(){return this.month()+1}),Q("MMM",0,0,function(f){return this.localeData().monthsShort(this,f)}),Q("MMMM",0,0,function(f){return this.localeData().months(this,f)}),je("M",ge,Di),je("MM",ge,M),je("MMM",function(f,h){return h.monthsShortRegex(f)}),je("MMMM",function(f,h){return h.monthsRegex(f)}),ot(["M","MM"],function(f,h){h[pr]=Ue(f)-1}),ot(["MMM","MMMM"],function(f,h,w,E){var D=w._locale.monthsParse(f,E,w._strict);D!=null?h[pr]=D:C(w).invalidMonth=f});var Tw="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),fp="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),pp=/D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,Fw=Es,Pw=Es;function Lw(f,h){return f?a(this._months)?this._months[f.month()]:this._months[(this._months.isFormat||pp).test(h)?"format":"standalone"][f.month()]:a(this._months)?this._months:this._months.standalone}function Vw(f,h){return f?a(this._monthsShort)?this._monthsShort[f.month()]:this._monthsShort[pp.test(h)?"format":"standalone"][f.month()]:a(this._monthsShort)?this._monthsShort:this._monthsShort.standalone}function Gw(f,h,w){var E,D,B,K=f.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],E=0;E<12;++E)B=v([2e3,E]),this._shortMonthsParse[E]=this.monthsShort(B,"").toLocaleLowerCase(),this._longMonthsParse[E]=this.months(B,"").toLocaleLowerCase();return w?h==="MMM"?(D=Et.call(this._shortMonthsParse,K),D!==-1?D:null):(D=Et.call(this._longMonthsParse,K),D!==-1?D:null):h==="MMM"?(D=Et.call(this._shortMonthsParse,K),D!==-1?D:(D=Et.call(this._longMonthsParse,K),D!==-1?D:null)):(D=Et.call(this._longMonthsParse,K),D!==-1?D:(D=Et.call(this._shortMonthsParse,K),D!==-1?D:null))}function Bw(f,h,w){var E,D,B;if(this._monthsParseExact)return Gw.call(this,f,h,w);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),E=0;E<12;E++){if(D=v([2e3,E]),w&&!this._longMonthsParse[E]&&(this._longMonthsParse[E]=new RegExp("^"+this.months(D,"").replace(".","")+"$","i"),this._shortMonthsParse[E]=new RegExp("^"+this.monthsShort(D,"").replace(".","")+"$","i")),!w&&!this._monthsParse[E]&&(B="^"+this.months(D,"")+"|^"+this.monthsShort(D,""),this._monthsParse[E]=new RegExp(B.replace(".",""),"i")),w&&h==="MMMM"&&this._longMonthsParse[E].test(f))return E;if(w&&h==="MMM"&&this._shortMonthsParse[E].test(f))return E;if(!w&&this._monthsParse[E].test(f))return E}}function mp(f,h){if(!f.isValid())return f;if(typeof h=="string"){if(/^\d+$/.test(h))h=Ue(h);else if(h=f.localeData().monthsParse(h),!d(h))return f}var w=h,E=f.date();return E=E<29?E:Math.min(E,sc(f.year(),w)),f._isUTC?f._d.setUTCMonth(w,E):f._d.setMonth(w,E),f}function hp(f){return f!=null?(mp(this,f),r.updateOffset(this,!0),this):As(this,"Month")}function Yw(){return sc(this.year(),this.month())}function Ww(f){return this._monthsParseExact?(l(this,"_monthsRegex")||gp.call(this),f?this._monthsShortStrictRegex:this._monthsShortRegex):(l(this,"_monthsShortRegex")||(this._monthsShortRegex=Fw),this._monthsShortStrictRegex&&f?this._monthsShortStrictRegex:this._monthsShortRegex)}function zw(f){return this._monthsParseExact?(l(this,"_monthsRegex")||gp.call(this),f?this._monthsStrictRegex:this._monthsRegex):(l(this,"_monthsRegex")||(this._monthsRegex=Pw),this._monthsStrictRegex&&f?this._monthsStrictRegex:this._monthsRegex)}function gp(){function f(Le,Xe){return Xe.length-Le.length}var h=[],w=[],E=[],D,B,K,Se;for(D=0;D<12;D++)B=v([2e3,D]),K=fr(this.monthsShort(B,"")),Se=fr(this.months(B,"")),h.push(K),w.push(Se),E.push(Se),E.push(K);h.sort(f),w.sort(f),E.sort(f),this._monthsRegex=new RegExp("^("+E.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+w.join("|")+")","i"),this._monthsShortStrictRegex=new RegExp("^("+h.join("|")+")","i")}function Hw(f,h,w,E,D,B,K){var Se;return f<100&&f>=0?(Se=new Date(f+400,h,w,E,D,B,K),isFinite(Se.getFullYear())&&Se.setFullYear(f)):Se=new Date(f,h,w,E,D,B,K),Se}function Rs(f){var h,w;return f<100&&f>=0?(w=Array.prototype.slice.call(arguments),w[0]=f+400,h=new Date(Date.UTC.apply(null,w)),isFinite(h.getUTCFullYear())&&h.setUTCFullYear(f)):h=new Date(Date.UTC.apply(null,arguments)),h}function $a(f,h,w){var E=7+h-w,D=(7+Rs(f,0,E).getUTCDay()-h)%7;return-D+E-1}function xp(f,h,w,E,D){var B=(7+w-E)%7,K=$a(f,E,D),Se=1+7*(h-1)+B+K,Le,Xe;return Se<=0?(Le=f-1,Xe=Ns(Le)+Se):Se>Ns(f)?(Le=f+1,Xe=Se-Ns(f)):(Le=f,Xe=Se),{year:Le,dayOfYear:Xe}}function Ds(f,h,w){var E=$a(f.year(),h,w),D=Math.floor((f.dayOfYear()-E-1)/7)+1,B,K;return D<1?(K=f.year()-1,B=D+hr(K,h,w)):D>hr(f.year(),h,w)?(B=D-hr(f.year(),h,w),K=f.year()+1):(K=f.year(),B=D),{week:B,year:K}}function hr(f,h,w){var E=$a(f,h,w),D=$a(f+1,h,w);return(Ns(f)-E+D)/7}Q("w",["ww",2],"wo","week"),Q("W",["WW",2],"Wo","isoWeek"),je("w",ge,Di),je("ww",ge,M),je("W",ge,Di),je("WW",ge,M),ks(["w","ww","W","WW"],function(f,h,w,E){h[E.substr(0,1)]=Ue(f)});function Uw(f){return Ds(f,this._week.dow,this._week.doy).week}var $w={dow:0,doy:6};function Xw(){return this._week.dow}function qw(){return this._week.doy}function Zw(f){var h=this.localeData().week(this);return f==null?h:this.add((f-h)*7,"d")}function Jw(f){var h=Ds(this,1,4).week;return f==null?h:this.add((f-h)*7,"d")}Q("d",0,"do","day"),Q("dd",0,0,function(f){return this.localeData().weekdaysMin(this,f)}),Q("ddd",0,0,function(f){return this.localeData().weekdaysShort(this,f)}),Q("dddd",0,0,function(f){return this.localeData().weekdays(this,f)}),Q("e",0,0,"weekday"),Q("E",0,0,"isoWeekday"),je("d",ge),je("e",ge),je("E",ge),je("dd",function(f,h){return h.weekdaysMinRegex(f)}),je("ddd",function(f,h){return h.weekdaysShortRegex(f)}),je("dddd",function(f,h){return h.weekdaysRegex(f)}),ks(["dd","ddd","dddd"],function(f,h,w,E){var D=w._locale.weekdaysParse(f,E,w._strict);D!=null?h.d=D:C(w).invalidWeekday=f}),ks(["d","e","E"],function(f,h,w,E){h[E]=Ue(f)});function Qw(f,h){return typeof f!="string"?f:isNaN(f)?(f=h.weekdaysParse(f),typeof f=="number"?f:null):parseInt(f,10)}function Kw(f,h){return typeof f=="string"?h.weekdaysParse(f)%7||7:isNaN(f)?null:f}function ac(f,h){return f.slice(h,7).concat(f.slice(0,h))}var eC="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),vp="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),tC="Su_Mo_Tu_We_Th_Fr_Sa".split("_"),nC=Es,rC=Es,iC=Es;function sC(f,h){var w=a(this._weekdays)?this._weekdays:this._weekdays[f&&f!==!0&&this._weekdays.isFormat.test(h)?"format":"standalone"];return f===!0?ac(w,this._week.dow):f?w[f.day()]:w}function aC(f){return f===!0?ac(this._weekdaysShort,this._week.dow):f?this._weekdaysShort[f.day()]:this._weekdaysShort}function oC(f){return f===!0?ac(this._weekdaysMin,this._week.dow):f?this._weekdaysMin[f.day()]:this._weekdaysMin}function lC(f,h,w){var E,D,B,K=f.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],E=0;E<7;++E)B=v([2e3,1]).day(E),this._minWeekdaysParse[E]=this.weekdaysMin(B,"").toLocaleLowerCase(),this._shortWeekdaysParse[E]=this.weekdaysShort(B,"").toLocaleLowerCase(),this._weekdaysParse[E]=this.weekdays(B,"").toLocaleLowerCase();return w?h==="dddd"?(D=Et.call(this._weekdaysParse,K),D!==-1?D:null):h==="ddd"?(D=Et.call(this._shortWeekdaysParse,K),D!==-1?D:null):(D=Et.call(this._minWeekdaysParse,K),D!==-1?D:null):h==="dddd"?(D=Et.call(this._weekdaysParse,K),D!==-1||(D=Et.call(this._shortWeekdaysParse,K),D!==-1)?D:(D=Et.call(this._minWeekdaysParse,K),D!==-1?D:null)):h==="ddd"?(D=Et.call(this._shortWeekdaysParse,K),D!==-1||(D=Et.call(this._weekdaysParse,K),D!==-1)?D:(D=Et.call(this._minWeekdaysParse,K),D!==-1?D:null)):(D=Et.call(this._minWeekdaysParse,K),D!==-1||(D=Et.call(this._weekdaysParse,K),D!==-1)?D:(D=Et.call(this._shortWeekdaysParse,K),D!==-1?D:null))}function cC(f,h,w){var E,D,B;if(this._weekdaysParseExact)return lC.call(this,f,h,w);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),E=0;E<7;E++){if(D=v([2e3,1]).day(E),w&&!this._fullWeekdaysParse[E]&&(this._fullWeekdaysParse[E]=new RegExp("^"+this.weekdays(D,"").replace(".","\\.?")+"$","i"),this._shortWeekdaysParse[E]=new RegExp("^"+this.weekdaysShort(D,"").replace(".","\\.?")+"$","i"),this._minWeekdaysParse[E]=new RegExp("^"+this.weekdaysMin(D,"").replace(".","\\.?")+"$","i")),this._weekdaysParse[E]||(B="^"+this.weekdays(D,"")+"|^"+this.weekdaysShort(D,"")+"|^"+this.weekdaysMin(D,""),this._weekdaysParse[E]=new RegExp(B.replace(".",""),"i")),w&&h==="dddd"&&this._fullWeekdaysParse[E].test(f))return E;if(w&&h==="ddd"&&this._shortWeekdaysParse[E].test(f))return E;if(w&&h==="dd"&&this._minWeekdaysParse[E].test(f))return E;if(!w&&this._weekdaysParse[E].test(f))return E}}function uC(f){if(!this.isValid())return f!=null?this:NaN;var h=As(this,"Day");return f!=null?(f=Qw(f,this.localeData()),this.add(f-h,"d")):h}function dC(f){if(!this.isValid())return f!=null?this:NaN;var h=(this.day()+7-this.localeData()._week.dow)%7;return f==null?h:this.add(f-h,"d")}function fC(f){if(!this.isValid())return f!=null?this:NaN;if(f!=null){var h=Kw(f,this.localeData());return this.day(this.day()%7?h:h-7)}else return this.day()||7}function pC(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||oc.call(this),f?this._weekdaysStrictRegex:this._weekdaysRegex):(l(this,"_weekdaysRegex")||(this._weekdaysRegex=nC),this._weekdaysStrictRegex&&f?this._weekdaysStrictRegex:this._weekdaysRegex)}function mC(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||oc.call(this),f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(l(this,"_weekdaysShortRegex")||(this._weekdaysShortRegex=rC),this._weekdaysShortStrictRegex&&f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function hC(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||oc.call(this),f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(l(this,"_weekdaysMinRegex")||(this._weekdaysMinRegex=iC),this._weekdaysMinStrictRegex&&f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function oc(){function f(sn,br){return br.length-sn.length}var h=[],w=[],E=[],D=[],B,K,Se,Le,Xe;for(B=0;B<7;B++)K=v([2e3,1]).day(B),Se=fr(this.weekdaysMin(K,"")),Le=fr(this.weekdaysShort(K,"")),Xe=fr(this.weekdays(K,"")),h.push(Se),w.push(Le),E.push(Xe),D.push(Se),D.push(Le),D.push(Xe);h.sort(f),w.sort(f),E.sort(f),D.sort(f),this._weekdaysRegex=new RegExp("^("+D.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+E.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+w.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+h.join("|")+")","i")}function lc(){return this.hours()%12||12}function gC(){return this.hours()||24}Q("H",["HH",2],0,"hour"),Q("h",["hh",2],0,lc),Q("k",["kk",2],0,gC),Q("hmm",0,0,function(){return""+lc.apply(this)+R(this.minutes(),2)}),Q("hmmss",0,0,function(){return""+lc.apply(this)+R(this.minutes(),2)+R(this.seconds(),2)}),Q("Hmm",0,0,function(){return""+this.hours()+R(this.minutes(),2)}),Q("Hmmss",0,0,function(){return""+this.hours()+R(this.minutes(),2)+R(this.seconds(),2)});function yp(f,h){Q(f,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),h)})}yp("a",!0),yp("A",!1);function bp(f,h){return h._meridiemParse}je("a",bp),je("A",bp),je("H",ge,rc),je("h",ge,Di),je("k",ge,Di),je("HH",ge,M),je("hh",ge,M),je("kk",ge,M),je("hmm",Je),je("hmmss",Ct),je("Hmm",Je),je("Hmmss",Ct),ot(["H","HH"],Gt),ot(["k","kk"],function(f,h,w){var E=Ue(f);h[Gt]=E===24?0:E}),ot(["a","A"],function(f,h,w){w._isPm=w._locale.isPM(f),w._meridiem=f}),ot(["h","hh"],function(f,h,w){h[Gt]=Ue(f),C(w).bigHour=!0}),ot("hmm",function(f,h,w){var E=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E)),C(w).bigHour=!0}),ot("hmmss",function(f,h,w){var E=f.length-4,D=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E,2)),h[mr]=Ue(f.substr(D)),C(w).bigHour=!0}),ot("Hmm",function(f,h,w){var E=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E))}),ot("Hmmss",function(f,h,w){var E=f.length-4,D=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E,2)),h[mr]=Ue(f.substr(D))});function xC(f){return(f+"").toLowerCase().charAt(0)==="p"}var vC=/[ap]\.?m?\.?/i,yC=Mi("Hours",!0);function bC(f,h,w){return f>11?w?"pm":"PM":w?"am":"AM"}var wp={calendar:ne,longDateFormat:ke,invalidDate:le,ordinal:dt,dayOfMonthOrdinalParse:Pe,relativeTime:Rt,months:Tw,monthsShort:fp,week:$w,weekdays:eC,weekdaysMin:tC,weekdaysShort:vp,meridiemParse:vC},bt={},Ms={},Os;function wC(f,h){var w,E=Math.min(f.length,h.length);for(w=0;w<E;w+=1)if(f[w]!==h[w])return w;return E}function Cp(f){return f&&f.toLowerCase().replace("_","-")}function CC(f){for(var h=0,w,E,D,B;h<f.length;){for(B=Cp(f[h]).split("-"),w=B.length,E=Cp(f[h+1]),E=E?E.split("-"):null;w>0;){if(D=Xa(B.slice(0,w).join("-")),D)return D;if(E&&E.length>=w&&wC(B,E)>=w-1)break;w--}h++}return Os}function SC(f){return!!(f&&f.match("^[^/\\\\]*$"))}function Xa(f){var h=null,w;if(bt[f]===void 0&&e&&e.exports&&SC(f))try{h=Os._abbr,w=ZV,w("./locale/"+f),Vr(h)}catch{bt[f]=null}return bt[f]}function Vr(f,h){var w;return f&&(u(h)?w=gr(f):w=cc(f,h),w?Os=w:typeof console<"u"&&console.warn&&console.warn("Locale "+f+" not found. Did you forget to load it?")),Os._abbr}function cc(f,h){if(h!==null){var w,E=wp;if(h.abbr=f,bt[f]!=null)G("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info."),E=bt[f]._config;else if(h.parentLocale!=null)if(bt[h.parentLocale]!=null)E=bt[h.parentLocale]._config;else if(w=Xa(h.parentLocale),w!=null)E=w._config;else return Ms[h.parentLocale]||(Ms[h.parentLocale]=[]),Ms[h.parentLocale].push({name:f,config:h}),null;return bt[f]=new V(T(E,h)),Ms[f]&&Ms[f].forEach(function(D){cc(D.name,D.config)}),Vr(f),bt[f]}else return delete bt[f],null}function jC(f,h){if(h!=null){var w,E,D=wp;bt[f]!=null&&bt[f].parentLocale!=null?bt[f].set(T(bt[f]._config,h)):(E=Xa(f),E!=null&&(D=E._config),h=T(D,h),E==null&&(h.abbr=f),w=new V(h),w.parentLocale=bt[f],bt[f]=w),Vr(f)}else bt[f]!=null&&(bt[f].parentLocale!=null?(bt[f]=bt[f].parentLocale,f===Vr()&&Vr(f)):bt[f]!=null&&delete bt[f]);return bt[f]}function gr(f){var h;if(f&&f._locale&&f._locale._abbr&&(f=f._locale._abbr),!f)return Os;if(!a(f)){if(h=Xa(f),h)return h;f=[f]}return CC(f)}function IC(){return Z(bt)}function uc(f){var h,w=f._a;return w&&C(f).overflow===-2&&(h=w[pr]<0||w[pr]>11?pr:w[Zn]<1||w[Zn]>sc(w[Zt],w[pr])?Zn:w[Gt]<0||w[Gt]>24||w[Gt]===24&&(w[Gn]!==0||w[mr]!==0||w[ti]!==0)?Gt:w[Gn]<0||w[Gn]>59?Gn:w[mr]<0||w[mr]>59?mr:w[ti]<0||w[ti]>999?ti:-1,C(f)._overflowDayOfYear&&(h<Zt||h>Zn)&&(h=Zn),C(f)._overflowWeeks&&h===-1&&(h=Nw),C(f)._overflowWeekday&&h===-1&&(h=Aw),C(f).overflow=h),f}var _C=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,EC=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,kC=/Z|[+-]\d\d(?::?\d\d)?/,qa=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/],["YYYYMM",/\d{6}/,!1],["YYYY",/\d{4}/,!1]],dc=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],NC=/^\/?Date\((-?\d+)/i,AC=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,RC={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Sp(f){var h,w,E=f._i,D=_C.exec(E)||EC.exec(E),B,K,Se,Le,Xe=qa.length,sn=dc.length;if(D){for(C(f).iso=!0,h=0,w=Xe;h<w;h++)if(qa[h][1].exec(D[1])){K=qa[h][0],B=qa[h][2]!==!1;break}if(K==null){f._isValid=!1;return}if(D[3]){for(h=0,w=sn;h<w;h++)if(dc[h][1].exec(D[3])){Se=(D[2]||" ")+dc[h][0];break}if(Se==null){f._isValid=!1;return}}if(!B&&Se!=null){f._isValid=!1;return}if(D[4])if(kC.exec(D[4]))Le="Z";else{f._isValid=!1;return}f._f=K+(Se||"")+(Le||""),pc(f)}else f._isValid=!1}function DC(f,h,w,E,D,B){var K=[MC(f),fp.indexOf(h),parseInt(w,10),parseInt(E,10),parseInt(D,10)];return B&&K.push(parseInt(B,10)),K}function MC(f){var h=parseInt(f,10);return h<=49?2e3+h:h<=999?1900+h:h}function OC(f){return f.replace(/\([^()]*\)|[\n\t]/g," ").replace(/(\s\s+)/g," ").replace(/^\s\s*/,"").replace(/\s\s*$/,"")}function TC(f,h,w){if(f){var E=vp.indexOf(f),D=new Date(h[0],h[1],h[2]).getDay();if(E!==D)return C(w).weekdayMismatch=!0,w._isValid=!1,!1}return!0}function FC(f,h,w){if(f)return RC[f];if(h)return 0;var E=parseInt(w,10),D=E%100,B=(E-D)/100;return B*60+D}function jp(f){var h=AC.exec(OC(f._i)),w;if(h){if(w=DC(h[4],h[3],h[2],h[5],h[6],h[7]),!TC(h[1],w,f))return;f._a=w,f._tzm=FC(h[8],h[9],h[10]),f._d=Rs.apply(null,f._a),f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),C(f).rfc2822=!0}else f._isValid=!1}function PC(f){var h=NC.exec(f._i);if(h!==null){f._d=new Date(+h[1]);return}if(Sp(f),f._isValid===!1)delete f._isValid;else return;if(jp(f),f._isValid===!1)delete f._isValid;else return;f._strict?f._isValid=!1:r.createFromInputFallback(f)}r.createFromInputFallback=L("value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.",function(f){f._d=new Date(f._i+(f._useUTC?" UTC":""))});function Oi(f,h,w){return f??h??w}function LC(f){var h=new Date(r.now());return f._useUTC?[h.getUTCFullYear(),h.getUTCMonth(),h.getUTCDate()]:[h.getFullYear(),h.getMonth(),h.getDate()]}function fc(f){var h,w,E=[],D,B,K;if(!f._d){for(D=LC(f),f._w&&f._a[Zn]==null&&f._a[pr]==null&&VC(f),f._dayOfYear!=null&&(K=Oi(f._a[Zt],D[Zt]),(f._dayOfYear>Ns(K)||f._dayOfYear===0)&&(C(f)._overflowDayOfYear=!0),w=Rs(K,0,f._dayOfYear),f._a[pr]=w.getUTCMonth(),f._a[Zn]=w.getUTCDate()),h=0;h<3&&f._a[h]==null;++h)f._a[h]=E[h]=D[h];for(;h<7;h++)f._a[h]=E[h]=f._a[h]==null?h===2?1:0:f._a[h];f._a[Gt]===24&&f._a[Gn]===0&&f._a[mr]===0&&f._a[ti]===0&&(f._nextDay=!0,f._a[Gt]=0),f._d=(f._useUTC?Rs:Hw).apply(null,E),B=f._useUTC?f._d.getUTCDay():f._d.getDay(),f._tzm!=null&&f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),f._nextDay&&(f._a[Gt]=24),f._w&&typeof f._w.d<"u"&&f._w.d!==B&&(C(f).weekdayMismatch=!0)}}function VC(f){var h,w,E,D,B,K,Se,Le,Xe;h=f._w,h.GG!=null||h.W!=null||h.E!=null?(B=1,K=4,w=Oi(h.GG,f._a[Zt],Ds(gt(),1,4).year),E=Oi(h.W,1),D=Oi(h.E,1),(D<1||D>7)&&(Le=!0)):(B=f._locale._week.dow,K=f._locale._week.doy,Xe=Ds(gt(),B,K),w=Oi(h.gg,f._a[Zt],Xe.year),E=Oi(h.w,Xe.week),h.d!=null?(D=h.d,(D<0||D>6)&&(Le=!0)):h.e!=null?(D=h.e+B,(h.e<0||h.e>6)&&(Le=!0)):D=B),E<1||E>hr(w,B,K)?C(f)._overflowWeeks=!0:Le!=null?C(f)._overflowWeekday=!0:(Se=xp(w,E,D,B,K),f._a[Zt]=Se.year,f._dayOfYear=Se.dayOfYear)}r.ISO_8601=function(){},r.RFC_2822=function(){};function pc(f){if(f._f===r.ISO_8601){Sp(f);return}if(f._f===r.RFC_2822){jp(f);return}f._a=[],C(f).empty=!0;var h=""+f._i,w,E,D,B,K,Se=h.length,Le=0,Xe,sn;for(D=Ee(f._f,f._locale).match(ee)||[],sn=D.length,w=0;w<sn;w++)B=D[w],E=(h.match(_w(B,f))||[])[0],E&&(K=h.substr(0,h.indexOf(E)),K.length>0&&C(f).unusedInput.push(K),h=h.slice(h.indexOf(E)+E.length),Le+=E.length),ae[B]?(E?C(f).empty=!1:C(f).unusedTokens.push(B),kw(B,E,f)):f._strict&&!E&&C(f).unusedTokens.push(B);C(f).charsLeftOver=Se-Le,h.length>0&&C(f).unusedInput.push(h),f._a[Gt]<=12&&C(f).bigHour===!0&&f._a[Gt]>0&&(C(f).bigHour=void 0),C(f).parsedDateParts=f._a.slice(0),C(f).meridiem=f._meridiem,f._a[Gt]=GC(f._locale,f._a[Gt],f._meridiem),Xe=C(f).era,Xe!==null&&(f._a[Zt]=f._locale.erasConvertYear(Xe,f._a[Zt])),fc(f),uc(f)}function GC(f,h,w){var E;return w==null?h:f.meridiemHour!=null?f.meridiemHour(h,w):(f.isPM!=null&&(E=f.isPM(w),E&&h<12&&(h+=12),!E&&h===12&&(h=0)),h)}function BC(f){var h,w,E,D,B,K,Se=!1,Le=f._f.length;if(Le===0){C(f).invalidFormat=!0,f._d=new Date(NaN);return}for(D=0;D<Le;D++)B=0,K=!1,h=N({},f),f._useUTC!=null&&(h._useUTC=f._useUTC),h._f=f._f[D],pc(h),_(h)&&(K=!0),B+=C(h).charsLeftOver,B+=C(h).unusedTokens.length*10,C(h).score=B,Se?B<E&&(E=B,w=h):(E==null||B<E||K)&&(E=B,w=h,K&&(Se=!0));m(f,w||h)}function YC(f){if(!f._d){var h=z(f._i),w=h.day===void 0?h.date:h.day;f._a=g([h.year,h.month,w,h.hour,h.minute,h.second,h.millisecond],function(E){return E&&parseInt(E,10)}),fc(f)}}function WC(f){var h=new k(uc(Ip(f)));return h._nextDay&&(h.add(1,"d"),h._nextDay=void 0),h}function Ip(f){var h=f._i,w=f._f;return f._locale=f._locale||gr(f._l),h===null||w===void 0&&h===""?y({nullInput:!0}):(typeof h=="string"&&(f._i=h=f._locale.preparse(h)),A(h)?new k(uc(h)):(p(h)?f._d=h:a(w)?BC(f):w?pc(f):zC(f),_(f)||(f._d=null),f))}function zC(f){var h=f._i;u(h)?f._d=new Date(r.now()):p(h)?f._d=new Date(h.valueOf()):typeof h=="string"?PC(f):a(h)?(f._a=g(h.slice(0),function(w){return parseInt(w,10)}),fc(f)):o(h)?YC(f):d(h)?f._d=new Date(h):r.createFromInputFallback(f)}function _p(f,h,w,E,D){var B={};return(h===!0||h===!1)&&(E=h,h=void 0),(w===!0||w===!1)&&(E=w,w=void 0),(o(f)&&c(f)||a(f)&&f.length===0)&&(f=void 0),B._isAMomentObject=!0,B._useUTC=B._isUTC=D,B._l=w,B._i=f,B._f=h,B._strict=E,WC(B)}function gt(f,h,w,E){return _p(f,h,w,E,!1)}var HC=L("moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=gt.apply(null,arguments);return this.isValid()&&f.isValid()?f<this?this:f:y()}),UC=L("moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=gt.apply(null,arguments);return this.isValid()&&f.isValid()?f>this?this:f:y()});function Ep(f,h){var w,E;if(h.length===1&&a(h[0])&&(h=h[0]),!h.length)return gt();for(w=h[0],E=1;E<h.length;++E)(!h[E].isValid()||h[E][f](w))&&(w=h[E]);return w}function $C(){var f=[].slice.call(arguments,0);return Ep("isBefore",f)}function XC(){var f=[].slice.call(arguments,0);return Ep("isAfter",f)}var qC=function(){return Date.now?Date.now():+new Date},Ts=["year","quarter","month","week","day","hour","minute","second","millisecond"];function ZC(f){var h,w=!1,E,D=Ts.length;for(h in f)if(l(f,h)&&!(Et.call(Ts,h)!==-1&&(f[h]==null||!isNaN(f[h]))))return!1;for(E=0;E<D;++E)if(f[Ts[E]]){if(w)return!1;parseFloat(f[Ts[E]])!==Ue(f[Ts[E]])&&(w=!0)}return!0}function JC(){return this._isValid}function QC(){return Bn(NaN)}function Za(f){var h=z(f),w=h.year||0,E=h.quarter||0,D=h.month||0,B=h.week||h.isoWeek||0,K=h.day||0,Se=h.hour||0,Le=h.minute||0,Xe=h.second||0,sn=h.millisecond||0;this._isValid=ZC(h),this._milliseconds=+sn+Xe*1e3+Le*6e4+Se*1e3*60*60,this._days=+K+B*7,this._months=+D+E*3+w*12,this._data={},this._locale=gr(),this._bubble()}function Ja(f){return f instanceof Za}function mc(f){return f<0?Math.round(-1*f)*-1:Math.round(f)}function KC(f,h,w){var E=Math.min(f.length,h.length),D=Math.abs(f.length-h.length),B=0,K;for(K=0;K<E;K++)Ue(f[K])!==Ue(h[K])&&B++;return B+D}function kp(f,h){Q(f,0,0,function(){var w=this.utcOffset(),E="+";return w<0&&(w=-w,E="-"),E+R(~~(w/60),2)+h+R(~~w%60,2)})}kp("Z",":"),kp("ZZ",""),je("Z",Vn),je("ZZ",Vn),ot(["Z","ZZ"],function(f,h,w){w._useUTC=!0,w._tzm=hc(Vn,f)});var eS=/([\+\-]|\d\d)/gi;function hc(f,h){var w=(h||"").match(f),E,D,B;return w===null?null:(E=w[w.length-1]||[],D=(E+"").match(eS)||["-",0,0],B=+(D[1]*60)+Ue(D[2]),B===0?0:D[0]==="+"?B:-B)}function gc(f,h){var w,E;return h._isUTC?(w=h.clone(),E=(A(f)||p(f)?f.valueOf():gt(f).valueOf())-w.valueOf(),w._d.setTime(w._d.valueOf()+E),r.updateOffset(w,!1),w):gt(f).local()}function xc(f){return-Math.round(f._d.getTimezoneOffset())}r.updateOffset=function(){};function tS(f,h,w){var E=this._offset||0,D;if(!this.isValid())return f!=null?this:NaN;if(f!=null){if(typeof f=="string"){if(f=hc(Vn,f),f===null)return this}else Math.abs(f)<16&&!w&&(f=f*60);return!this._isUTC&&h&&(D=xc(this)),this._offset=f,this._isUTC=!0,D!=null&&this.add(D,"m"),E!==f&&(!h||this._changeInProgress?Dp(this,Bn(f-E,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,r.updateOffset(this,!0),this._changeInProgress=null)),this}else return this._isUTC?E:xc(this)}function nS(f,h){return f!=null?(typeof f!="string"&&(f=-f),this.utcOffset(f,h),this):-this.utcOffset()}function rS(f){return this.utcOffset(0,f)}function iS(f){return this._isUTC&&(this.utcOffset(0,f),this._isUTC=!1,f&&this.subtract(xc(this),"m")),this}function sS(){if(this._tzm!=null)this.utcOffset(this._tzm,!1,!0);else if(typeof this._i=="string"){var f=hc($t,this._i);f!=null?this.utcOffset(f):this.utcOffset(0,!0)}return this}function aS(f){return this.isValid()?(f=f?gt(f).utcOffset():0,(this.utcOffset()-f)%60===0):!1}function oS(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function lS(){if(!u(this._isDSTShifted))return this._isDSTShifted;var f={},h;return N(f,this),f=Ip(f),f._a?(h=f._isUTC?v(f._a):gt(f._a),this._isDSTShifted=this.isValid()&&KC(f._a,h.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function cS(){return this.isValid()?!this._isUTC:!1}function uS(){return this.isValid()?this._isUTC:!1}function Np(){return this.isValid()?this._isUTC&&this._offset===0:!1}var dS=/^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,fS=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function Bn(f,h){var w=f,E=null,D,B,K;return Ja(f)?w={ms:f._milliseconds,d:f._days,M:f._months}:d(f)||!isNaN(+f)?(w={},h?w[h]=+f:w.milliseconds=+f):(E=dS.exec(f))?(D=E[1]==="-"?-1:1,w={y:0,d:Ue(E[Zn])*D,h:Ue(E[Gt])*D,m:Ue(E[Gn])*D,s:Ue(E[mr])*D,ms:Ue(mc(E[ti]*1e3))*D}):(E=fS.exec(f))?(D=E[1]==="-"?-1:1,w={y:ni(E[2],D),M:ni(E[3],D),w:ni(E[4],D),d:ni(E[5],D),h:ni(E[6],D),m:ni(E[7],D),s:ni(E[8],D)}):w==null?w={}:typeof w=="object"&&("from"in w||"to"in w)&&(K=pS(gt(w.from),gt(w.to)),w={},w.ms=K.milliseconds,w.M=K.months),B=new Za(w),Ja(f)&&l(f,"_locale")&&(B._locale=f._locale),Ja(f)&&l(f,"_isValid")&&(B._isValid=f._isValid),B}Bn.fn=Za.prototype,Bn.invalid=QC;function ni(f,h){var w=f&&parseFloat(f.replace(",","."));return(isNaN(w)?0:w)*h}function Ap(f,h){var w={};return w.months=h.month()-f.month()+(h.year()-f.year())*12,f.clone().add(w.months,"M").isAfter(h)&&--w.months,w.milliseconds=+h-+f.clone().add(w.months,"M"),w}function pS(f,h){var w;return f.isValid()&&h.isValid()?(h=gc(h,f),f.isBefore(h)?w=Ap(f,h):(w=Ap(h,f),w.milliseconds=-w.milliseconds,w.months=-w.months),w):{milliseconds:0,months:0}}function Rp(f,h){return function(w,E){var D,B;return E!==null&&!isNaN(+E)&&(G(h,"moment()."+h+"(period, number) is deprecated. Please use moment()."+h+"(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info."),B=w,w=E,E=B),D=Bn(w,E),Dp(this,D,f),this}}function Dp(f,h,w,E){var D=h._milliseconds,B=mc(h._days),K=mc(h._months);f.isValid()&&(E=E??!0,K&&mp(f,As(f,"Month")+K*w),B&&dp(f,"Date",As(f,"Date")+B*w),D&&f._d.setTime(f._d.valueOf()+D*w),E&&r.updateOffset(f,B||K))}var mS=Rp(1,"add"),hS=Rp(-1,"subtract");function Mp(f){return typeof f=="string"||f instanceof String}function gS(f){return A(f)||p(f)||Mp(f)||d(f)||vS(f)||xS(f)||f===null||f===void 0}function xS(f){var h=o(f)&&!c(f),w=!1,E=["years","year","y","months","month","M","days","day","d","dates","date","D","hours","hour","h","minutes","minute","m","seconds","second","s","milliseconds","millisecond","ms"],D,B,K=E.length;for(D=0;D<K;D+=1)B=E[D],w=w||l(f,B);return h&&w}function vS(f){var h=a(f),w=!1;return h&&(w=f.filter(function(E){return!d(E)&&Mp(f)}).length===0),h&&w}function yS(f){var h=o(f)&&!c(f),w=!1,E=["sameDay","nextDay","lastDay","nextWeek","lastWeek","sameElse"],D,B;for(D=0;D<E.length;D+=1)B=E[D],w=w||l(f,B);return h&&w}function bS(f,h){var w=f.diff(h,"days",!0);return w<-6?"sameElse":w<-1?"lastWeek":w<0?"lastDay":w<1?"sameDay":w<2?"nextDay":w<7?"nextWeek":"sameElse"}function wS(f,h){arguments.length===1&&(arguments[0]?gS(arguments[0])?(f=arguments[0],h=void 0):yS(arguments[0])&&(h=arguments[0],f=void 0):(f=void 0,h=void 0));var w=f||gt(),E=gc(w,this).startOf("day"),D=r.calendarFormat(this,E)||"sameElse",B=h&&(X(h[D])?h[D].call(this,w):h[D]);return this.format(B||this.localeData().calendar(D,this,gt(w)))}function CS(){return new k(this)}function SS(f,h){var w=A(f)?f:gt(f);return this.isValid()&&w.isValid()?(h=P(h)||"millisecond",h==="millisecond"?this.valueOf()>w.valueOf():w.valueOf()<this.clone().startOf(h).valueOf()):!1}function jS(f,h){var w=A(f)?f:gt(f);return this.isValid()&&w.isValid()?(h=P(h)||"millisecond",h==="millisecond"?this.valueOf()<w.valueOf():this.clone().endOf(h).valueOf()<w.valueOf()):!1}function IS(f,h,w,E){var D=A(f)?f:gt(f),B=A(h)?h:gt(h);return this.isValid()&&D.isValid()&&B.isValid()?(E=E||"()",(E[0]==="("?this.isAfter(D,w):!this.isBefore(D,w))&&(E[1]===")"?this.isBefore(B,w):!this.isAfter(B,w))):!1}function _S(f,h){var w=A(f)?f:gt(f),E;return this.isValid()&&w.isValid()?(h=P(h)||"millisecond",h==="millisecond"?this.valueOf()===w.valueOf():(E=w.valueOf(),this.clone().startOf(h).valueOf()<=E&&E<=this.clone().endOf(h).valueOf())):!1}function ES(f,h){return this.isSame(f,h)||this.isAfter(f,h)}function kS(f,h){return this.isSame(f,h)||this.isBefore(f,h)}function NS(f,h,w){var E,D,B;if(!this.isValid())return NaN;if(E=gc(f,this),!E.isValid())return NaN;switch(D=(E.utcOffset()-this.utcOffset())*6e4,h=P(h),h){case"year":B=Qa(this,E)/12;break;case"month":B=Qa(this,E);break;case"quarter":B=Qa(this,E)/3;break;case"second":B=(this-E)/1e3;break;case"minute":B=(this-E)/6e4;break;case"hour":B=(this-E)/36e5;break;case"day":B=(this-E-D)/864e5;break;case"week":B=(this-E-D)/6048e5;break;default:B=this-E}return w?B:En(B)}function Qa(f,h){if(f.date()<h.date())return-Qa(h,f);var w=(h.year()-f.year())*12+(h.month()-f.month()),E=f.clone().add(w,"months"),D,B;return h-E<0?(D=f.clone().add(w-1,"months"),B=(h-E)/(E-D)):(D=f.clone().add(w+1,"months"),B=(h-E)/(D-E)),-(w+B)||0}r.defaultFormat="YYYY-MM-DDTHH:mm:ssZ",r.defaultFormatUtc="YYYY-MM-DDTHH:mm:ss[Z]";function AS(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function RS(f){if(!this.isValid())return null;var h=f!==!0,w=h?this.clone().utc():this;return w.year()<0||w.year()>9999?be(w,h?"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYYYY-MM-DD[T]HH:mm:ss.SSSZ"):X(Date.prototype.toISOString)?h?this.toDate().toISOString():new Date(this.valueOf()+this.utcOffset()*60*1e3).toISOString().replace("Z",be(w,"Z")):be(w,h?"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYY-MM-DD[T]HH:mm:ss.SSSZ")}function DS(){if(!this.isValid())return"moment.invalid(/* "+this._i+" */)";var f="moment",h="",w,E,D,B;return this.isLocal()||(f=this.utcOffset()===0?"moment.utc":"moment.parseZone",h="Z"),w="["+f+'("]',E=0<=this.year()&&this.year()<=9999?"YYYY":"YYYYYY",D="-MM-DD[T]HH:mm:ss.SSS",B=h+'[")]',this.format(w+E+D+B)}function MS(f){f||(f=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var h=be(this,f);return this.localeData().postformat(h)}function OS(f,h){return this.isValid()&&(A(f)&&f.isValid()||gt(f).isValid())?Bn({to:this,from:f}).locale(this.locale()).humanize(!h):this.localeData().invalidDate()}function TS(f){return this.from(gt(),f)}function FS(f,h){return this.isValid()&&(A(f)&&f.isValid()||gt(f).isValid())?Bn({from:this,to:f}).locale(this.locale()).humanize(!h):this.localeData().invalidDate()}function PS(f){return this.to(gt(),f)}function Op(f){var h;return f===void 0?this._locale._abbr:(h=gr(f),h!=null&&(this._locale=h),this)}var Tp=L("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(f){return f===void 0?this.localeData():this.locale(f)});function Fp(){return this._locale}var Ka=1e3,Ti=60*Ka,eo=60*Ti,Pp=(365*400+97)*24*eo;function Fi(f,h){return(f%h+h)%h}function Lp(f,h,w){return f<100&&f>=0?new Date(f+400,h,w)-Pp:new Date(f,h,w).valueOf()}function Vp(f,h,w){return f<100&&f>=0?Date.UTC(f+400,h,w)-Pp:Date.UTC(f,h,w)}function LS(f){var h,w;if(f=P(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(w=this._isUTC?Vp:Lp,f){case"year":h=w(this.year(),0,1);break;case"quarter":h=w(this.year(),this.month()-this.month()%3,1);break;case"month":h=w(this.year(),this.month(),1);break;case"week":h=w(this.year(),this.month(),this.date()-this.weekday());break;case"isoWeek":h=w(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case"day":case"date":h=w(this.year(),this.month(),this.date());break;case"hour":h=this._d.valueOf(),h-=Fi(h+(this._isUTC?0:this.utcOffset()*Ti),eo);break;case"minute":h=this._d.valueOf(),h-=Fi(h,Ti);break;case"second":h=this._d.valueOf(),h-=Fi(h,Ka);break}return this._d.setTime(h),r.updateOffset(this,!0),this}function VS(f){var h,w;if(f=P(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(w=this._isUTC?Vp:Lp,f){case"year":h=w(this.year()+1,0,1)-1;break;case"quarter":h=w(this.year(),this.month()-this.month()%3+3,1)-1;break;case"month":h=w(this.year(),this.month()+1,1)-1;break;case"week":h=w(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case"isoWeek":h=w(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case"day":case"date":h=w(this.year(),this.month(),this.date()+1)-1;break;case"hour":h=this._d.valueOf(),h+=eo-Fi(h+(this._isUTC?0:this.utcOffset()*Ti),eo)-1;break;case"minute":h=this._d.valueOf(),h+=Ti-Fi(h,Ti)-1;break;case"second":h=this._d.valueOf(),h+=Ka-Fi(h,Ka)-1;break}return this._d.setTime(h),r.updateOffset(this,!0),this}function GS(){return this._d.valueOf()-(this._offset||0)*6e4}function BS(){return Math.floor(this.valueOf()/1e3)}function YS(){return new Date(this.valueOf())}function WS(){var f=this;return[f.year(),f.month(),f.date(),f.hour(),f.minute(),f.second(),f.millisecond()]}function zS(){var f=this;return{years:f.year(),months:f.month(),date:f.date(),hours:f.hours(),minutes:f.minutes(),seconds:f.seconds(),milliseconds:f.milliseconds()}}function HS(){return this.isValid()?this.toISOString():null}function US(){return _(this)}function $S(){return m({},C(this))}function XS(){return C(this).overflow}function qS(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}Q("N",0,0,"eraAbbr"),Q("NN",0,0,"eraAbbr"),Q("NNN",0,0,"eraAbbr"),Q("NNNN",0,0,"eraName"),Q("NNNNN",0,0,"eraNarrow"),Q("y",["y",1],"yo","eraYear"),Q("y",["yy",2],0,"eraYear"),Q("y",["yyy",3],0,"eraYear"),Q("y",["yyyy",4],0,"eraYear"),je("N",vc),je("NN",vc),je("NNN",vc),je("NNNN",aj),je("NNNNN",oj),ot(["N","NN","NNN","NNNN","NNNNN"],function(f,h,w,E){var D=w._locale.erasParse(f,E,w._strict);D?C(w).era=D:C(w).invalidEra=f}),je("y",ft),je("yy",ft),je("yyy",ft),je("yyyy",ft),je("yo",lj),ot(["y","yy","yyy","yyyy"],Zt),ot(["yo"],function(f,h,w,E){var D;w._locale._eraYearOrdinalRegex&&(D=f.match(w._locale._eraYearOrdinalRegex)),w._locale.eraYearOrdinalParse?h[Zt]=w._locale.eraYearOrdinalParse(f,D):h[Zt]=parseInt(f,10)});function ZS(f,h){var w,E,D,B=this._eras||gr("en")._eras;for(w=0,E=B.length;w<E;++w)switch(typeof B[w].since==="string"&&(D=r(B[w].since).startOf("day"),B[w].since=D.valueOf()),typeof B[w].until){case"undefined":B[w].until=1/0;break;case"string":D=r(B[w].until).startOf("day").valueOf(),B[w].until=D.valueOf();break}return B}function JS(f,h,w){var E,D,B=this.eras(),K,Se,Le;for(f=f.toUpperCase(),E=0,D=B.length;E<D;++E)if(K=B[E].name.toUpperCase(),Se=B[E].abbr.toUpperCase(),Le=B[E].narrow.toUpperCase(),w)switch(h){case"N":case"NN":case"NNN":if(Se===f)return B[E];break;case"NNNN":if(K===f)return B[E];break;case"NNNNN":if(Le===f)return B[E];break}else if([K,Se,Le].indexOf(f)>=0)return B[E]}function QS(f,h){var w=f.since<=f.until?1:-1;return h===void 0?r(f.since).year():r(f.since).year()+(h-f.offset)*w}function KS(){var f,h,w,E=this.localeData().eras();for(f=0,h=E.length;f<h;++f)if(w=this.clone().startOf("day").valueOf(),E[f].since<=w&&w<=E[f].until||E[f].until<=w&&w<=E[f].since)return E[f].name;return""}function ej(){var f,h,w,E=this.localeData().eras();for(f=0,h=E.length;f<h;++f)if(w=this.clone().startOf("day").valueOf(),E[f].since<=w&&w<=E[f].until||E[f].until<=w&&w<=E[f].since)return E[f].narrow;return""}function tj(){var f,h,w,E=this.localeData().eras();for(f=0,h=E.length;f<h;++f)if(w=this.clone().startOf("day").valueOf(),E[f].since<=w&&w<=E[f].until||E[f].until<=w&&w<=E[f].since)return E[f].abbr;return""}function nj(){var f,h,w,E,D=this.localeData().eras();for(f=0,h=D.length;f<h;++f)if(w=D[f].since<=D[f].until?1:-1,E=this.clone().startOf("day").valueOf(),D[f].since<=E&&E<=D[f].until||D[f].until<=E&&E<=D[f].since)return(this.year()-r(D[f].since).year())*w+D[f].offset;return this.year()}function rj(f){return l(this,"_erasNameRegex")||yc.call(this),f?this._erasNameRegex:this._erasRegex}function ij(f){return l(this,"_erasAbbrRegex")||yc.call(this),f?this._erasAbbrRegex:this._erasRegex}function sj(f){return l(this,"_erasNarrowRegex")||yc.call(this),f?this._erasNarrowRegex:this._erasRegex}function vc(f,h){return h.erasAbbrRegex(f)}function aj(f,h){return h.erasNameRegex(f)}function oj(f,h){return h.erasNarrowRegex(f)}function lj(f,h){return h._eraYearOrdinalRegex||ft}function yc(){var f=[],h=[],w=[],E=[],D,B,K,Se,Le,Xe=this.eras();for(D=0,B=Xe.length;D<B;++D)K=fr(Xe[D].name),Se=fr(Xe[D].abbr),Le=fr(Xe[D].narrow),h.push(K),f.push(Se),w.push(Le),E.push(K),E.push(Se),E.push(Le);this._erasRegex=new RegExp("^("+E.join("|")+")","i"),this._erasNameRegex=new RegExp("^("+h.join("|")+")","i"),this._erasAbbrRegex=new RegExp("^("+f.join("|")+")","i"),this._erasNarrowRegex=new RegExp("^("+w.join("|")+")","i")}Q(0,["gg",2],0,function(){return this.weekYear()%100}),Q(0,["GG",2],0,function(){return this.isoWeekYear()%100});function to(f,h){Q(0,[f,f.length],0,h)}to("gggg","weekYear"),to("ggggg","weekYear"),to("GGGG","isoWeekYear"),to("GGGGG","isoWeekYear"),je("G",Yt),je("g",Yt),je("GG",ge,M),je("gg",ge,M),je("GGGG",Ut,re),je("gggg",Ut,re),je("GGGGG",Vt,me),je("ggggg",Vt,me),ks(["gggg","ggggg","GGGG","GGGGG"],function(f,h,w,E){h[E.substr(0,2)]=Ue(f)}),ks(["gg","GG"],function(f,h,w,E){h[E]=r.parseTwoDigitYear(f)});function cj(f){return Gp.call(this,f,this.week(),this.weekday()+this.localeData()._week.dow,this.localeData()._week.dow,this.localeData()._week.doy)}function uj(f){return Gp.call(this,f,this.isoWeek(),this.isoWeekday(),1,4)}function dj(){return hr(this.year(),1,4)}function fj(){return hr(this.isoWeekYear(),1,4)}function pj(){var f=this.localeData()._week;return hr(this.year(),f.dow,f.doy)}function mj(){var f=this.localeData()._week;return hr(this.weekYear(),f.dow,f.doy)}function Gp(f,h,w,E,D){var B;return f==null?Ds(this,E,D).year:(B=hr(f,E,D),h>B&&(h=B),hj.call(this,f,h,w,E,D))}function hj(f,h,w,E,D){var B=xp(f,h,w,E,D),K=Rs(B.year,0,B.dayOfYear);return this.year(K.getUTCFullYear()),this.month(K.getUTCMonth()),this.date(K.getUTCDate()),this}Q("Q",0,"Qo","quarter"),je("Q",q),ot("Q",function(f,h){h[pr]=(Ue(f)-1)*3});function gj(f){return f==null?Math.ceil((this.month()+1)/3):this.month((f-1)*3+this.month()%3)}Q("D",["DD",2],"Do","date"),je("D",ge,Di),je("DD",ge,M),je("Do",function(f,h){return f?h._dayOfMonthOrdinalParse||h._ordinalParse:h._dayOfMonthOrdinalParseLenient}),ot(["D","DD"],Zn),ot("Do",function(f,h){h[Zn]=Ue(f.match(ge)[0])});var Bp=Mi("Date",!0);Q("DDD",["DDDD",3],"DDDo","dayOfYear"),je("DDD",Mt),je("DDDD",U),ot(["DDD","DDDD"],function(f,h,w){w._dayOfYear=Ue(f)});function xj(f){var h=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return f==null?h:this.add(f-h,"d")}Q("m",["mm",2],0,"minute"),je("m",ge,rc),je("mm",ge,M),ot(["m","mm"],Gn);var vj=Mi("Minutes",!1);Q("s",["ss",2],0,"second"),je("s",ge,rc),je("ss",ge,M),ot(["s","ss"],mr);var yj=Mi("Seconds",!1);Q("S",0,0,function(){return~~(this.millisecond()/100)}),Q(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),Q(0,["SSS",3],0,"millisecond"),Q(0,["SSSS",4],0,function(){return this.millisecond()*10}),Q(0,["SSSSS",5],0,function(){return this.millisecond()*100}),Q(0,["SSSSSS",6],0,function(){return this.millisecond()*1e3}),Q(0,["SSSSSSS",7],0,function(){return this.millisecond()*1e4}),Q(0,["SSSSSSSS",8],0,function(){return this.millisecond()*1e5}),Q(0,["SSSSSSSSS",9],0,function(){return this.millisecond()*1e6}),je("S",Mt,q),je("SS",Mt,M),je("SSS",Mt,U);var Gr,Yp;for(Gr="SSSS";Gr.length<=9;Gr+="S")je(Gr,ft);function bj(f,h){h[ti]=Ue(("0."+f)*1e3)}for(Gr="S";Gr.length<=9;Gr+="S")ot(Gr,bj);Yp=Mi("Milliseconds",!1),Q("z",0,0,"zoneAbbr"),Q("zz",0,0,"zoneName");function wj(){return this._isUTC?"UTC":""}function Cj(){return this._isUTC?"Coordinated Universal Time":""}var ce=k.prototype;ce.add=mS,ce.calendar=wS,ce.clone=CS,ce.diff=NS,ce.endOf=VS,ce.format=MS,ce.from=OS,ce.fromNow=TS,ce.to=FS,ce.toNow=PS,ce.get=Dw,ce.invalidAt=XS,ce.isAfter=SS,ce.isBefore=jS,ce.isBetween=IS,ce.isSame=_S,ce.isSameOrAfter=ES,ce.isSameOrBefore=kS,ce.isValid=US,ce.lang=Tp,ce.locale=Op,ce.localeData=Fp,ce.max=UC,ce.min=HC,ce.parsingFlags=$S,ce.set=Mw,ce.startOf=LS,ce.subtract=hS,ce.toArray=WS,ce.toObject=zS,ce.toDate=YS,ce.toISOString=RS,ce.inspect=DS,typeof Symbol<"u"&&Symbol.for!=null&&(ce[Symbol.for("nodejs.util.inspect.custom")]=function(){return"Moment<"+this.format()+">"}),ce.toJSON=HS,ce.toString=AS,ce.unix=BS,ce.valueOf=GS,ce.creationData=qS,ce.eraName=KS,ce.eraNarrow=ej,ce.eraAbbr=tj,ce.eraYear=nj,ce.year=up,ce.isLeapYear=Rw,ce.weekYear=cj,ce.isoWeekYear=uj,ce.quarter=ce.quarters=gj,ce.month=hp,ce.daysInMonth=Yw,ce.week=ce.weeks=Zw,ce.isoWeek=ce.isoWeeks=Jw,ce.weeksInYear=pj,ce.weeksInWeekYear=mj,ce.isoWeeksInYear=dj,ce.isoWeeksInISOWeekYear=fj,ce.date=Bp,ce.day=ce.days=uC,ce.weekday=dC,ce.isoWeekday=fC,ce.dayOfYear=xj,ce.hour=ce.hours=yC,ce.minute=ce.minutes=vj,ce.second=ce.seconds=yj,ce.millisecond=ce.milliseconds=Yp,ce.utcOffset=tS,ce.utc=rS,ce.local=iS,ce.parseZone=sS,ce.hasAlignedHourOffset=aS,ce.isDST=oS,ce.isLocal=cS,ce.isUtcOffset=uS,ce.isUtc=Np,ce.isUTC=Np,ce.zoneAbbr=wj,ce.zoneName=Cj,ce.dates=L("dates accessor is deprecated. Use date instead.",Bp),ce.months=L("months accessor is deprecated. Use month instead",hp),ce.years=L("years accessor is deprecated. Use year instead",up),ce.zone=L("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",nS),ce.isDSTShifted=L("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",lS);function Sj(f){return gt(f*1e3)}function jj(){return gt.apply(null,arguments).parseZone()}function Wp(f){return f}var Qe=V.prototype;Qe.calendar=de,Qe.longDateFormat=Ve,Qe.invalidDate=We,Qe.ordinal=At,Qe.preparse=Wp,Qe.postformat=Wp,Qe.relativeTime=jt,Qe.pastFuture=Dt,Qe.set=H,Qe.eras=ZS,Qe.erasParse=JS,Qe.erasConvertYear=QS,Qe.erasAbbrRegex=ij,Qe.erasNameRegex=rj,Qe.erasNarrowRegex=sj,Qe.months=Lw,Qe.monthsShort=Vw,Qe.monthsParse=Bw,Qe.monthsRegex=zw,Qe.monthsShortRegex=Ww,Qe.week=Uw,Qe.firstDayOfYear=qw,Qe.firstDayOfWeek=Xw,Qe.weekdays=sC,Qe.weekdaysMin=oC,Qe.weekdaysShort=aC,Qe.weekdaysParse=cC,Qe.weekdaysRegex=pC,Qe.weekdaysShortRegex=mC,Qe.weekdaysMinRegex=hC,Qe.isPM=xC,Qe.meridiem=bC;function no(f,h,w,E){var D=gr(),B=v().set(E,h);return D[w](B,f)}function zp(f,h,w){if(d(f)&&(h=f,f=void 0),f=f||"",h!=null)return no(f,h,w,"month");var E,D=[];for(E=0;E<12;E++)D[E]=no(f,E,w,"month");return D}function bc(f,h,w,E){typeof f=="boolean"?(d(h)&&(w=h,h=void 0),h=h||""):(h=f,w=h,f=!1,d(h)&&(w=h,h=void 0),h=h||"");var D=gr(),B=f?D._week.dow:0,K,Se=[];if(w!=null)return no(h,(w+B)%7,E,"day");for(K=0;K<7;K++)Se[K]=no(h,(K+B)%7,E,"day");return Se}function Ij(f,h){return zp(f,h,"months")}function _j(f,h){return zp(f,h,"monthsShort")}function Ej(f,h,w){return bc(f,h,w,"weekdays")}function kj(f,h,w){return bc(f,h,w,"weekdaysShort")}function Nj(f,h,w){return bc(f,h,w,"weekdaysMin")}Vr("en",{eras:[{since:"0001-01-01",until:1/0,offset:1,name:"Anno Domini",narrow:"AD",abbr:"AD"},{since:"0000-12-31",until:-1/0,offset:1,name:"Before Christ",narrow:"BC",abbr:"BC"}],dayOfMonthOrdinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(f){var h=f%10,w=Ue(f%100/10)===1?"th":h===1?"st":h===2?"nd":h===3?"rd":"th";return f+w}}),r.lang=L("moment.lang is deprecated. Use moment.locale instead.",Vr),r.langData=L("moment.langData is deprecated. Use moment.localeData instead.",gr);var xr=Math.abs;function Aj(){var f=this._data;return this._milliseconds=xr(this._milliseconds),this._days=xr(this._days),this._months=xr(this._months),f.milliseconds=xr(f.milliseconds),f.seconds=xr(f.seconds),f.minutes=xr(f.minutes),f.hours=xr(f.hours),f.months=xr(f.months),f.years=xr(f.years),this}function Hp(f,h,w,E){var D=Bn(h,w);return f._milliseconds+=E*D._milliseconds,f._days+=E*D._days,f._months+=E*D._months,f._bubble()}function Rj(f,h){return Hp(this,f,h,1)}function Dj(f,h){return Hp(this,f,h,-1)}function Up(f){return f<0?Math.floor(f):Math.ceil(f)}function Mj(){var f=this._milliseconds,h=this._days,w=this._months,E=this._data,D,B,K,Se,Le;return f>=0&&h>=0&&w>=0||f<=0&&h<=0&&w<=0||(f+=Up(wc(w)+h)*864e5,h=0,w=0),E.milliseconds=f%1e3,D=En(f/1e3),E.seconds=D%60,B=En(D/60),E.minutes=B%60,K=En(B/60),E.hours=K%24,h+=En(K/24),Le=En($p(h)),w+=Le,h-=Up(wc(Le)),Se=En(w/12),w%=12,E.days=h,E.months=w,E.years=Se,this}function $p(f){return f*4800/146097}function wc(f){return f*146097/4800}function Oj(f){if(!this.isValid())return NaN;var h,w,E=this._milliseconds;if(f=P(f),f==="month"||f==="quarter"||f==="year")switch(h=this._days+E/864e5,w=this._months+$p(h),f){case"month":return w;case"quarter":return w/3;case"year":return w/12}else switch(h=this._days+Math.round(wc(this._months)),f){case"week":return h/7+E/6048e5;case"day":return h+E/864e5;case"hour":return h*24+E/36e5;case"minute":return h*1440+E/6e4;case"second":return h*86400+E/1e3;case"millisecond":return Math.floor(h*864e5)+E;default:throw new Error("Unknown unit "+f)}}function vr(f){return function(){return this.as(f)}}var Xp=vr("ms"),Tj=vr("s"),Fj=vr("m"),Pj=vr("h"),Lj=vr("d"),Vj=vr("w"),Gj=vr("M"),Bj=vr("Q"),Yj=vr("y"),Wj=Xp;function zj(){return Bn(this)}function Hj(f){return f=P(f),this.isValid()?this[f+"s"]():NaN}function ri(f){return function(){return this.isValid()?this._data[f]:NaN}}var Uj=ri("milliseconds"),$j=ri("seconds"),Xj=ri("minutes"),qj=ri("hours"),Zj=ri("days"),Jj=ri("months"),Qj=ri("years");function Kj(){return En(this.days()/7)}var yr=Math.round,Pi={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function e1(f,h,w,E,D){return D.relativeTime(h||1,!!w,f,E)}function t1(f,h,w,E){var D=Bn(f).abs(),B=yr(D.as("s")),K=yr(D.as("m")),Se=yr(D.as("h")),Le=yr(D.as("d")),Xe=yr(D.as("M")),sn=yr(D.as("w")),br=yr(D.as("y")),Br=B<=w.ss&&["s",B]||B<w.s&&["ss",B]||K<=1&&["m"]||K<w.m&&["mm",K]||Se<=1&&["h"]||Se<w.h&&["hh",Se]||Le<=1&&["d"]||Le<w.d&&["dd",Le];return w.w!=null&&(Br=Br||sn<=1&&["w"]||sn<w.w&&["ww",sn]),Br=Br||Xe<=1&&["M"]||Xe<w.M&&["MM",Xe]||br<=1&&["y"]||["yy",br],Br[2]=h,Br[3]=+f>0,Br[4]=E,e1.apply(null,Br)}function n1(f){return f===void 0?yr:typeof f=="function"?(yr=f,!0):!1}function r1(f,h){return Pi[f]===void 0?!1:h===void 0?Pi[f]:(Pi[f]=h,f==="s"&&(Pi.ss=h-1),!0)}function i1(f,h){if(!this.isValid())return this.localeData().invalidDate();var w=!1,E=Pi,D,B;return typeof f=="object"&&(h=f,f=!1),typeof f=="boolean"&&(w=f),typeof h=="object"&&(E=Object.assign({},Pi,h),h.s!=null&&h.ss==null&&(E.ss=h.s-1)),D=this.localeData(),B=t1(this,!w,E,D),w&&(B=D.pastFuture(+this,B)),D.postformat(B)}var Cc=Math.abs;function Li(f){return(f>0)-(f<0)||+f}function ro(){if(!this.isValid())return this.localeData().invalidDate();var f=Cc(this._milliseconds)/1e3,h=Cc(this._days),w=Cc(this._months),E,D,B,K,Se=this.asSeconds(),Le,Xe,sn,br;return Se?(E=En(f/60),D=En(E/60),f%=60,E%=60,B=En(w/12),w%=12,K=f?f.toFixed(3).replace(/\.?0+$/,""):"",Le=Se<0?"-":"",Xe=Li(this._months)!==Li(Se)?"-":"",sn=Li(this._days)!==Li(Se)?"-":"",br=Li(this._milliseconds)!==Li(Se)?"-":"",Le+"P"+(B?Xe+B+"Y":"")+(w?Xe+w+"M":"")+(h?sn+h+"D":"")+(D||E||f?"T":"")+(D?br+D+"H":"")+(E?br+E+"M":"")+(f?br+K+"S":"")):"P0D"}var qe=Za.prototype;qe.isValid=JC,qe.abs=Aj,qe.add=Rj,qe.subtract=Dj,qe.as=Oj,qe.asMilliseconds=Xp,qe.asSeconds=Tj,qe.asMinutes=Fj,qe.asHours=Pj,qe.asDays=Lj,qe.asWeeks=Vj,qe.asMonths=Gj,qe.asQuarters=Bj,qe.asYears=Yj,qe.valueOf=Wj,qe._bubble=Mj,qe.clone=zj,qe.get=Hj,qe.milliseconds=Uj,qe.seconds=$j,qe.minutes=Xj,qe.hours=qj,qe.days=Zj,qe.weeks=Kj,qe.months=Jj,qe.years=Qj,qe.humanize=i1,qe.toISOString=ro,qe.toString=ro,qe.toJSON=ro,qe.locale=Op,qe.localeData=Fp,qe.toIsoString=L("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",ro),qe.lang=Tp,Q("X",0,0,"unix"),Q("x",0,0,"valueOf"),je("x",Yt),je("X",nc),ot("X",function(f,h,w){w._d=new Date(parseFloat(f)*1e3)}),ot("x",function(f,h,w){w._d=new Date(Ue(f))});return r.version="2.30.1",i(gt),r.fn=ce,r.min=$C,r.max=XC,r.now=qC,r.utc=v,r.unix=Sj,r.months=Ij,r.isDate=p,r.locale=Vr,r.invalid=y,r.duration=Bn,r.isMoment=A,r.weekdays=Ej,r.parseZone=jj,r.localeData=gr,r.isDuration=Ja,r.monthsShort=_j,r.weekdaysMin=Nj,r.defineLocale=cc,r.updateLocale=jC,r.locales=IC,r.weekdaysShort=kj,r.normalizeUnits=P,r.relativeTimeRounding=n1,r.relativeTimeThreshold=r1,r.calendarFormat=bS,r.prototype=ce,r.HTML5_FMT={DATETIME_LOCAL:"YYYY-MM-DDTHH:mm",DATETIME_LOCAL_SECONDS:"YYYY-MM-DDTHH:mm:ss",DATETIME_LOCAL_MS:"YYYY-MM-DDTHH:mm:ss.SSS",DATE:"YYYY-MM-DD",TIME:"HH:mm",TIME_SECONDS:"HH:mm:ss",TIME_MS:"HH:mm:ss.SSS",WEEK:"GGGG-[W]WW",MONTH:"YYYY-MM"},r}))})(Oo)),Oo.exports}var KV=QV();const Co=Qr(KV);function Pg({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r,expanded:i=!0}){const[a,o]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(i),p=v=>{r(["issue","attachment","status_mail"]),r(["issue","status_mail"])},g=()=>n.filter(v=>v.issue.id===e.id),m=()=>{o(s.jsx(Wa,{equipment:t,showModal:!0,onClose:v=>{c(!1),v&&p()},issue:e,attachments:g()})),c(!0)};return s.jsxs("div",{className:"p-3 mb-4 border-bottom",children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-2",children:[s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(Ft,{bg:"dark",children:"Issue"}),s.jsx("h4",{className:e.date_closed?"text-danger mb-0":"mb-0",children:e.date_closed?s.jsx("s",{children:e.issue}):e.issue})]}),s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(ie,{variant:"outline-primary",size:"sm",onClick:()=>d(v=>!v),"aria-label":"Toggle Details",children:u?"Hide Details":"Show Details"}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:m,"aria-label":"Edit Issue",children:"Edit"})]})]}),u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mb-2",children:s.jsx(Ai,{children:e.description})}),s.jsx("p",{className:"mb-3",children:e.actions}),s.jsxs("div",{className:"d-flex flex-wrap gap-4 text-muted",children:[s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Creator"}),s.jsx("div",{className:"text-body",children:e.owner.full_name})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Date Created"}),s.jsx("div",{className:"text-body",children:Co(e.date_created).format("DD MMMM YYYY")})]}),e.date_closed&&s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Date Closed"}),s.jsx("div",{className:"text-body",children:Co(e.date_closed).format("DD MMMM YYYY")})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Forecast Up"}),s.jsx("div",{className:"text-body",children:Co(e.forecast_up).format("DD MMMM YYYY")})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Issue Type"}),s.jsxs("div",{className:"text-body",children:[e.issue_type===_r.DEFAULT&&"Issue",e.issue_type===_r.ESCALATION&&"Escalation",e.issue_type===_r.PRIORITY&&"Priority"]})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Attachments"}),s.jsx("div",{className:"text-body",children:e.attachments})]}),e.updated_by&&s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Last Update By"}),s.jsx("div",{className:"text-body",children:e.updated_by.full_name})]}),e.last_update&&s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Last Update"}),s.jsx("div",{className:"text-body",children:Co(e.last_update).format("DD MMMM YYYY")})]})]})]}),l&&a]})}function Lg({reservations:e}){if(!e||e.length<1)return s.jsx(s.Fragment,{});const t=e[0];return s.jsx(fs,{placement:"top",overlay:s.jsxs(yi,{id:`tooltip-${t.id}`,children:[s.jsx("h5",{children:t.title}),s.jsx("p",{children:e[0].active?"Currently active":`Upcoming in: ${ye(e[0].start).format("DD MMMM YYYY")}`}),s.jsx("p",{children:e[1]?`Next upcoming reservation in: ${ye(e[1].start).format("DD MMMM YYYY")}`:"No next upcoming reservations"})]}),children:s.jsxs(Ft,{bg:e[0].active?"info":"dark",children:["Reserved by: ",e[0].user.full_name]})})}function eG({equipment:e,modules:t,issues:n,issueAttachments:r,ecnNotes:i,ecnAttachments:a,reloadQueryFn:o,showIssues:l,reservations:c}){const[u,d]=x.useState(null),[p,g]=x.useState(!1),[m,v]=x.useState(null),[I,C]=x.useState(!1),[b,_]=x.useState([]),[y,S]=x.useState(void 0),[j,N]=x.useState([]),[k,A]=x.useState([]),F=T=>{o(["ecn","attachment","status_mail"]),N([...j,T])},L=T=>{o(["issue","status_mail"]),o(["issue","attachment","status_mail"]),A([...k,T])};x.useEffect(()=>{N(i),A(n),_(t.filter(T=>T.equipment.id===e.id&&!T.type.is_main_tool)),S(t.findLast(T=>T.equipment.id===e.id&&T.type.is_main_tool))},[i,n,e,t]);const Y=T=>j.filter(V=>V.module_id===T),G=T=>k.filter(V=>V.module_id===T),X=()=>{v(s.jsx(Pl,{equipment:e,showModal:!0,onClose:T=>{C(!1),T&&F(T)}})),C(!0)},H=()=>{d(s.jsx(Wa,{equipment:e,showModal:!0,onClose:T=>{g(!1),T&&L(T)}})),g(!0)};return s.jsxs("div",{className:"card mb-4",children:[s.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsxs("h4",{className:"mb-0",children:[e.number," - ",e.name]}),y&&s.jsx(Jr,{module:y}),y&&s.jsx(Lg,{reservations:c.filter(T=>T.modules.some(V=>V.id===y.id))})]}),s.jsxs(Na,{as:wx,title:"Action",id:"bg-nested-dropdown",children:[s.jsx(at.Item,{eventKey:"1",onClick:X,children:"New ECN"}),l!==1&&s.jsx(at.Item,{eventKey:"1",onClick:H,children:"New Issue"})]})]}),s.jsx("div",{className:"card-body",children:s.jsxs(Un,{children:[y&&s.jsx(Pt,{xs:12,md:b.length>0?6:12,children:s.jsx(Ye,{className:"mb-3",children:s.jsxs(Ye.Body,{children:[s.jsxs(Ye.Title,{className:"d-flex align-items-center",children:[s.jsx("span",{children:"Main module"}),s.jsx("div",{className:"ms-2"})]}),s.jsxs("div",{className:"mt-3",children:[Y(y.id).map((T,V)=>s.jsx(Tg,{ecn:T,equipment:e,ecnAttachments:a,reloadQueryFn:o,expanded:!0},V)),l!==1&&G(y.id).map((T,V)=>s.jsx(Pg,{issue:T,equipment:e,issueAttachments:r,reloadQueryFn:o,expanded:l!==3},V))]})]})})}),b.length>0&&s.jsx(Pt,{xs:12,md:y?6:12,children:b.map((T,V)=>s.jsx(Ye,{className:"mb-3",children:s.jsxs(Ye.Body,{children:[s.jsx(Ye.Title,{className:"d-flex align-items-center",children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("span",{children:T.name}),s.jsx(Jr,{module:T}),s.jsx(Lg,{reservations:c.filter(Z=>Z.modules.some(ne=>ne.id===T.id))})]})}),s.jsxs("div",{className:"mt-3",children:[Y(T.id).map((Z,ne)=>s.jsx(Tg,{ecn:Z,equipment:e,ecnAttachments:a,reloadQueryFn:o,expanded:!0},ne)),l!==1&&G(T.id).map((Z,ne)=>s.jsx(Pg,{issue:Z,equipment:e,issueAttachments:r,reloadQueryFn:o,expanded:l!==3},ne))]})]})},V))})]})}),I&&m,p&&u]})}const V0=({showModal:e,onClose:t,message:n})=>{const{register:r,handleSubmit:i,setValue:a,reset:o,control:l}=tn({defaultValues:{title:n?.title,description:n?.description,rooms:n?.rooms,type:n?.type,owner:n?.owner}}),[c,u]=x.useState([]),[d,p]=x.useState([]),[g,m]=x.useState(""),v=()=>document.documentElement.getAttribute("data-bs-theme")==="dark",I={control:y=>({...y,backgroundColor:v()?"#212529":y.backgroundColor,borderColor:v()?"#495057":y.borderColor,color:v()?"#fff":y.color}),menu:y=>({...y,backgroundColor:v()?"#212529":y.backgroundColor}),option:(y,S)=>({...y,backgroundColor:v()?S.isSelected?"#0d6efd":S.isFocused?"#343a40":"#212529":y.backgroundColor,color:v()?"#fff":y.color}),singleValue:y=>({...y,color:v()?"#fff":y.color}),multiValue:y=>({...y,backgroundColor:v()?"#343a40":y.backgroundColor}),multiValueLabel:y=>({...y,color:v()?"#fff":y.color}),input:y=>({...y,color:v()?"#fff":y.color})};let{statusMail:C}=x.useContext(Tl);x.useEffect(()=>{te.get("/list/room").then(y=>{const j=(y.data._embedded.items||[]).map(N=>({value:N,label:N.name}));u(j)}).catch(y=>{console.error("Error fetching rooms:",y),m("Error fetching rooms:"+y)}),te.get("/list/location/message/type").then(y=>{const S=C.filter.messageType,N=(y.data._embedded.items||[]).filter(k=>S.includes(k.id.toString())).map(k=>({value:k,label:k.type}));p(N),a("type",n?.type||N[0].value)}).catch(y=>{console.error("Error fetching message types:",y),m("Error fetching message types:"+y)})},[]);const b=y=>{if(y.title){if(y?.owner.value===void 0&&n?.owner===void 0)return"owner";if(y.rooms===void 0||y.rooms.map(S=>S.id).length<=0)return"room";if(!y.type)return"type"}else return"title";return""},_=async y=>{const S=b(y);if(S!==""){m("Please fill: "+S);return}try{const j={title:y.title,description:y.description,owner:y?.owner.value||n?.owner.id,type:y.type.id,rooms:y.rooms.map(k=>k.id)};let N;if(n?N=await te.patch(`/update/location/message/${n.id}`,j):N=await te.post("/create/location/message",j),N){t(N?.data),o();return}console.error("No response received"),m("No response received")}catch(j){console.error("Error submitting the form:",j),m("Error submitting the form:"+j)}};return s.jsx(ve,{show:e,size:"lg",centered:!0,onHide:()=>t(n),children:s.jsxs(W,{onSubmit:i(_),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Edit status mail message"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Title"}),s.jsx(W.Control,{type:"text",placeholder:"Enter the title",...r("title")})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Message"}),s.jsx(W.Control,{as:"textarea",rows:3,placeholder:"Give the message",...r("description")})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Owner"}),s.jsx(Fa,{control:l,...r("owner",{required:"Owner is required"}),name:"owner"})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Rooms"}),s.jsx(Fn,{name:"rooms",control:l,render:({field:y})=>s.jsx($u,{isMulti:!0,options:c,classNamePrefix:"react-select",placeholder:"Select one or more rooms",value:c.filter(S=>y.value?.some(j=>j.id===S.value.id)),onChange:S=>y.onChange(S.map(j=>j.value)),styles:I})})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Type"}),s.jsx(Fn,{name:"type",control:l,render:({field:y})=>s.jsx($u,{options:d,classNamePrefix:"react-select",placeholder:"Select a message type",value:d.find(S=>S.value.id===y.value?.id)||null,onChange:S=>y.onChange(S?.value),styles:I})})]})]}),s.jsxs(ve.Footer,{children:[g!=""&&s.jsx("span",{className:"text-danger",children:g}),s.jsx(ie,{variant:"secondary",onClick:()=>t(n),children:"Cancel"}),s.jsx(ie,{variant:"primary",type:"submit",children:n?"Update Message":"Create Message"})]})]})})};function tG({message:e}){const[t,n]=x.useState(null),[r,i]=x.useState(!1),[a,o]=x.useState(e),l=u=>{o({...a,...u})},c=()=>{n(s.jsx(V0,{showModal:!0,onClose:u=>{i(!1),u&&l(u)},message:a})),i(!0)};return s.jsxs("div",{className:"card mb-4",children:[s.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(Ft,{bg:"dark",children:a.type.type}),s.jsx("h5",{className:"mb-0",children:a.title})]}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:c,children:"Edit"})]}),s.jsx("div",{className:"card-body",children:s.jsx(Ai,{children:a.description})}),s.jsx("div",{className:"card-footer bg-transparent",children:s.jsxs("small",{className:"text-muted d-flex flex-wrap gap-3",children:[s.jsxs("span",{children:["Created: ",ye(a.date_created).format("DD MMM YYYY")]}),a.last_update&&s.jsxs("span",{children:["Updated: ",ye(a.last_update).format("DD MMM YYYY")]}),a.rooms.length>0&&s.jsxs("span",{children:["Rooms:"," ",a.rooms.map((u,d)=>s.jsxs(x.Fragment,{children:[d>0&&", ",u.name]},u.id))]}),s.jsxs("span",{children:["Owner: ",a.owner.full_name]})]})}),r&&t]})}function nG({messageList:e,refetchFn:t}){const[n,r]=x.useState(null),[i,a]=x.useState(!1),o=()=>{r(s.jsx(V0,{showModal:!0,onClose:l=>{a(!1),t()}})),a(!0)};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"d-flex gap-3",children:[s.jsx("h2",{children:"Messages"}),s.jsx("div",{children:s.jsx(ie,{variant:"secondary",onClick:o,children:"New message"})})]}),e.map((l,c)=>s.jsx("div",{children:s.jsx(tG,{message:l})},l.id)),i&&n]})}function rG({issue:e,moduleName:t,issueAttachments:n,equipment:r,reloadQueryFn:i}){const[a,o]=x.useState(null),[l,c]=x.useState(!1),u=g=>{i(["issue","status_mail"]),i(["issue","attachment","status_mail"])},d=()=>n.filter(g=>g.issue.id===e.id),p=()=>{if(!r){console.error("equipment is null in the table");return}c(!0),o(s.jsx(Wa,{equipment:r,showModal:!0,onClose:g=>{c(!1),g&&u()},issue:e,attachments:d()}))};return s.jsxs(s.Fragment,{children:[s.jsxs("tr",{className:"align-middle",children:[s.jsx("td",{className:"text-nowrap",children:t??"-"}),s.jsx("td",{children:e.issue}),s.jsx("td",{children:s.jsx(Ai,{children:e.description})}),s.jsx("td",{className:"text-nowrap",children:ye(e.forecast_up).format("DD MMMM YYYY")}),s.jsx("td",{className:"text-nowrap",children:e.owner.full_name}),s.jsx("td",{className:"text-center",children:s.jsx("button",{type:"button",className:"btn btn-sm btn-outline-light",onClick:p,children:"Edit"})})]},e.id),l&&a]})}function iG({issues:e,modules:t,issueAttachments:n,reloadQueryFn:r}){return s.jsx("div",{className:"table-responsive",children:s.jsxs("table",{className:"table table-hover table-striped table-bordered table-sm",children:[s.jsx("thead",{className:"bg-primary text-white",children:s.jsxs("tr",{children:[s.jsx("th",{scope:"col",children:"Module"}),s.jsx("th",{scope:"col",children:"Issue"}),s.jsx("th",{scope:"col",children:"Description"}),s.jsx("th",{scope:"col",children:"Forecast Up"}),s.jsx("th",{scope:"col",children:"Owner"}),s.jsx("th",{scope:"col",className:"text-center",children:"Actions"})]})}),s.jsx("tbody",{children:e.map(i=>s.jsx(rG,{issue:i,moduleName:t.find(a=>a.id===i.module_id)?.name,issueAttachments:n,equipment:t.find(a=>a.id===i.module_id)?.equipment,reloadQueryFn:r},i.id))})]})})}function sG({statusMail:e}){const[t,n]=x.useState(!1),[r,i]=x.useState(!1),a=async()=>{try{if(n(!0),!e.id||e.id<=0)throw new Error("Status Mail ID is not correctly set");const o={status_mail:e.id};await te.post("/send/status-mail",o),i(!0)}catch(o){console.error("Error sending status mail:",o),alert("Error sending status mail. Please try again.")}finally{n(!1)}};return s.jsx(ie,{variant:"primary",size:"sm",onClick:a,disabled:t,"aria-label":"Toggle Details",children:t?"Sending...":r?"Sending successful":"Send Status Mail"})}function aG(){let{statusMail:e}=x.useContext(Tl);const[t,n]=x.useState([]),r=Ae.useQueryClient(),i=Ae.useQueries({queries:[{queryKey:["equipment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Zg({statusMail:e})},{queryKey:["module","status_mail",JSON.stringify(e.filter)],queryFn:()=>xi({statusMail:e})},{queryKey:["ecn","status_mail",JSON.stringify(e.filter)],queryFn:()=>wd({statusMail:e})},{queryKey:["issue","status_mail",JSON.stringify(e.filter)],queryFn:()=>Kg({statusMail:e})},{queryKey:["messages","status_mail",JSON.stringify(e.filter)],queryFn:()=>C1({statusMail:e})},{queryKey:["ecn","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Jg({statusMail:e})},{queryKey:["issue","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Qg({statusMail:e})},{queryKey:["reservation","active","status_mail",JSON.stringify(e.filter)],queryFn:()=>To({which:"active"})},{queryKey:["reservation","upcoming","status_mail",JSON.stringify(e.filter)],queryFn:()=>To({which:"upcoming"})}]}),a=S=>{let j=S;j.push(JSON.stringify(e.filter)),r.refetchQueries({queryKey:j})},[o,l,c,u,d,p,g,m,v]=i,I=i.some(S=>S.isLoading),C=i.some(S=>S.isError),b=i.every(S=>S.isSuccess);x.useEffect(()=>{b&&n(o.data.items)},[b]);const _=()=>{if(!t.length)return s.jsx("p",{children:"No equipment available."});t.sort((k,A)=>e.classification===si.ROOM?k.room.name.localeCompare(A.room.name):k.area&&A.area&&e.classification===si.AREA?k.area.title.localeCompare(A.area.title):k.area&&A.area&&e.classification===si.AREA_PER_FACILITY?k.area.facility.title.localeCompare(A.area.facility.title)||k.area.title.localeCompare(A.area.title):0);let S,j=null,N="";return t.map((k,A)=>{const F=[];return e.classification===si.ROOM?k.room.name!==N&&(F.push(s.jsxs("h2",{children:["Room: ",k.room.name]},`room-${k.room.name}`)),N=k.room.name):e.classification===si.AREA?k.area&&k.area!==j&&(F.push(s.jsxs("h2",{children:["Area: ",k.area.title]},`area-${k.area.id}`)),j=k.area):e.classification===si.AREA_PER_FACILITY&&(k.area&&k.area.facility!==S&&(F.push(s.jsxs("h2",{children:["Facility: ",k.area.facility.title]},`facility-${k.area.facility.id}`)),S=k.area.facility),k.area&&k.area!==j&&(F.push(s.jsxs("h4",{children:["Area: ",k.area.title]},`area-${k.area.id}`)),j=k.area)),F.push(s.jsx(eG,{equipment:k,modules:l.data.items,issues:u.data.items,issueAttachments:g.data.items,ecnNotes:c.data.items,ecnAttachments:p.data.items,reloadQueryFn:a,showIssues:e.show_issues,reservations:e.show_reservations?m.data.items.concat(v.data.items):[]},A)),F})},y=()=>{const S=u.data.items.filter(j=>j.issue_type===2);return S.length===0?s.jsx(s.Fragment,{}):s.jsxs(s.Fragment,{children:[s.jsx("h2",{children:"Issues with priority"}),s.jsx(iG,{issues:S,modules:l.data.items,issueAttachments:g.data.items,reloadQueryFn:a})]})};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center",children:[s.jsxs("h1",{className:"display-4",children:["Status mail ",e.name]}),s.jsx("div",{children:s.jsx(sG,{statusMail:e})})]}),s.jsx("p",{children:e.subject}),I&&s.jsx(St,{variant:"info",children:"Loading status mail"}),C&&s.jsx(St,{variant:"danger",children:"Error loading status mail"}),b&&e.show_issues_with_priority&&y(),b&&d.data&&s.jsx(nG,{messageList:d.data.items,refetchFn:d.refetch}),b&&_()]})}function oG(e){if(!e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;const t=new Date(e);return isNaN(t.getTime())?null:t}function lG(e,t){const n=oG(e);if(!n)return"";const r=o=>o.toString().padStart(2,"0"),i={YYYY:n.getFullYear().toString(),YY:n.getFullYear().toString().slice(-2),MM:r(n.getMonth()+1),DD:r(n.getDate()),HH:r(n.getHours()),mm:r(n.getMinutes()),H:n.getHours().toString(),m:n.getMinutes().toString()};let a=t;return Object.keys(i).sort((o,l)=>l.length-o.length).forEach(o=>{a=a.replace(new RegExp(o,"g"),i[o])}),a}function ln(e,t="DD-MM-YY HH:mm"){return lG(e,t)}function rp({monitor:e}){const{environment:t}=Te.useParams(),[n]=Ae.useQueries({queries:[{queryKey:["requirement",e],queryFn:()=>ex({monitorId:e.id})}]});return n.isLoading?s.jsx("div",{children:"Loading requirements..."}):n.data?.items.map((r,i)=>{let a="bg-secondary-subtle";if(r.latest_result)for(let o=0;o<r.latest_result.values.length;o++){if(r.latest_result.values[o].value_is_valid===!1){a="bg-danger-subtle";break}if(r.latest_result.values[o].value_is_valid===!0){a="bg-success-subtle";break}}return s.jsx(Ye,{className:"mb-2 me-2",children:s.jsxs(Ye.Body,{className:a,children:[s.jsx(Ye.Title,{children:s.jsx(Te.Link,{to:`/${t}/operator/monitor/`+e.id,children:e.name})}),s.jsxs(Ye.Text,{children:[r.title,r.latest_result&&s.jsxs(s.Fragment,{children:["Latest measurement: ",ln(r.latest_result.date_created,"DD-MM-YY HH:mm")]})]})]})},i)})}const G0=({moduleId:e,size:t})=>{const[n,r]=x.useState(!1),[i,a]=x.useState(!1),[o,l]=x.useState("");function c(){te.create().post("create/equipment/module/changelog",{module:e,changelog:o}).finally(()=>{r(!1),a(!0),l("")})}const u=p=>{l(p.target.value)};function d(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>a(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Assist logged"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Assist was logged successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"primary",size:t,onClick:()=>r(!0),children:"Log assist"}),s.jsxs(ve,{show:n,size:"lg",onHide:()=>r(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Log assist"})}),s.jsx(ve.Body,{children:s.jsx(W,{children:s.jsxs(W.Group,{className:"mb-3",controlId:"modal.ControlTextarea1",children:[s.jsx(W.Label,{children:"Describe the assist"}),s.jsx(W.Control,{as:"textarea",rows:3,value:o,onChange:p=>u(p)})]})})}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",variant:"primary",onClick:()=>c(),children:"Log assist"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{r(!1)},children:"Close"})]})]}),s.jsx(d,{})]})},Ql=x.createContext({equipment:{},reloadEquipment:()=>{}});function cG({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r}){const[i,a]=x.useState(null),[o,l]=x.useState(!1),[c,u]=x.useState(e),d=m=>{r(["issue",t.name]),r(["issue","attachment",t.name]),u({...c,...m})},p=()=>n.filter(m=>m.issue.id===e.id),g=()=>{a(s.jsx(Wa,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},issue:c,attachments:p()})),l(!0)};return s.jsxs("div",{children:[s.jsxs(Ye,{className:"my-2",children:[s.jsxs(Ye.Body,{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs(Ye.Title,{children:[s.jsx(Ft,{bg:"dark",children:"Issue"})," ",c.issue]}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:g,children:"Edit"})]}),s.jsx(Ye.Text,{children:s.jsx(Ai,{children:c.description})})]}),s.jsxs(wn,{className:"list-group-flush",children:[c.date_created&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Created:"}),s.jsx("span",{className:"ms-1",children:ln(c.date_created,"DD-MM-YY HH:mm")})]}),c.owner&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Owner:"}),s.jsx("span",{className:"ms-1",children:c.owner.full_name})]}),c.updated_by&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Updated:"}),s.jsx("span",{className:"ms-1",children:c.updated_by.full_name}),s.jsxs("span",{className:"ms-1",children:["(",ln(c.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},c.module_id),o&&i]})}function uG({ecn:e,equipment:t,ecnAttachments:n,reloadQueryFn:r}){const[i,a]=x.useState(null),[o,l]=x.useState(!1),[c,u]=x.useState(e),d=m=>{r(["ecn",t.name]),r(["ecn","attachment",t.name]),u({...c,...m})},p=()=>n.filter(m=>m.ecn.id===e.id),g=()=>{a(s.jsx(Pl,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},ecn:c,attachments:p()})),l(!0)};return s.jsxs("div",{children:[s.jsxs(Ye,{className:"my-2",children:[s.jsxs(Ye.Body,{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs(Ye.Title,{children:[s.jsx(Ft,{bg:"dark",children:"ECN"})," ",e.ecn]}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:g,children:"Edit"})]}),s.jsx(Ye.Text,{children:s.jsx(Ai,{children:e.description})})]}),s.jsxs(wn,{className:"list-group-flush",children:[c.date_created&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Created:"}),s.jsx("span",{className:"ms-1",children:ln(c.date_created,"DD-MM-YY HH:mm")})]}),c.owner&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Owner:"}),s.jsx("span",{className:"ms-1",children:c.owner.full_name})]}),c.updated_by&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Updated:"}),s.jsx("span",{className:"ms-1",children:c.updated_by.full_name}),s.jsxs("span",{className:"ms-1",children:["(",ln(c.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},e.module_id),o&&i]})}function dG(){const{id:e}=Te.useParams(),[t,n]=x.useState([]),r=Ae.useQueries({queries:[{queryKey:["service","equipment",e],queryFn:()=>P1({equipmentId:Number(e)})}]}),[i]=r,a=r.some(u=>u.isLoading),o=r.some(u=>u.isError),l=r.every(u=>u.isSuccess);if(x.useEffect(()=>{l&&n(i.data.items)},[l,i.data]),a)return s.jsx("div",{children:"Loading..."});if(o)return s.jsx("div",{children:"Error loading services."});const c=u=>{if(u<60)return`${u} min`;const d=Math.floor(u/60),p=u%60;return`${d}h ${p>0?`${p}min`:""}`.trim()};return i.data.items.length===0?s.jsxs("div",{children:[s.jsx("h2",{children:"Services"}),s.jsx(St,{variant:"info",children:"No services found"})]}):s.jsxs("div",{children:[s.jsx("h2",{children:"Services"}),s.jsxs(Ht,{striped:!0,bordered:!0,hover:!0,responsive:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Id"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Type"}),s.jsx("th",{children:"Team"}),s.jsx("th",{children:"Department"}),s.jsx("th",{children:"Duration"}),s.jsx("th",{children:"Report2"})]})}),s.jsx("tbody",{children:t.map(u=>s.jsxs("tr",{children:[s.jsx("td",{children:u.id}),s.jsx("td",{children:s.jsx("a",{href:`/${window.location.pathname.split("/")[1]}/service/details/${u.id}/general.html`,children:u.name})}),s.jsx("td",{children:u.type?.name||"N/A"}),s.jsx("td",{children:u.team?.name||"N/A"}),s.jsx("td",{children:u.department?.name||"N/A"}),s.jsx("td",{children:c(u.minutes_needed_for_service)}),s.jsx("td",{children:u.latest_event_report_id&&s.jsx("a",{className:"btn btn-primary btn-sm",href:`/${window.location.pathname.split("/")[1]}/service/event/report/${u.latest_event_report_id}/results`,children:"View Report"})})]},u.id))})]})]})}function fG(){const{environment:e}=Te.useParams(),{equipment:t}=x.useContext(Ql),n=Ae.useQueryClient(),[r,i]=x.useState(null),[a,o]=x.useState(!1),[l,c]=x.useState(null),[u,d]=x.useState(!1),[p,g,m,v,I,C,b]=Ae.useQueries({queries:[{queryKey:["runs",t.name,e],queryFn:()=>R1({firstUnfinishedStepEquipment:t,environment:e})},{queryKey:["monitors",t.name],queryFn:()=>tx({equipment:t})},{queryKey:["ecn",t.name],queryFn:()=>wd({equipment:t})},{queryKey:["issue",t.name],queryFn:()=>Kg({equipment:t})},{queryKey:["module",t.name],queryFn:()=>xi({equipment:t})},{queryKey:["ecn","attachment",t.name],queryFn:()=>Jg({equipment:t})},{queryKey:["issue","attachment",t.name],queryFn:()=>Qg({equipment:t})}]}),_=k=>{n.invalidateQueries({queryKey:k})},y=k=>k?m.data?.items.filter(A=>A.module_id===k):[],S=k=>k?v.data?.items.filter(A=>A.module_id===k):[],j=()=>{c(s.jsx(Pl,{equipment:t,showModal:!0,onClose:()=>{d(!1),setTimeout(()=>{_(["ecn",t.name]),_(["ecn","attachment",t.name])},100)}})),d(!0)},N=()=>{i(s.jsx(Wa,{equipment:t,showModal:!0,onClose:()=>{o(!1),setTimeout(()=>{_(["issue",t.name]),_(["issue","attachment",t.name])},100)}})),o(!0)};return s.jsxs(Ii,{fluid:!0,children:[s.jsx("div",{className:"d-flex justify-content-left",children:g.data?.items&&g.data.items.map((k,A)=>s.jsx(rp,{monitor:k},A))}),s.jsxs(Un,{children:[s.jsxs(Pt,{md:8,children:[s.jsx("h2",{children:"Runs"}),p.isLoading&&s.jsx("div",{children:"Loading..."})," ",p.isError&&s.jsx("div",{children:"Error..."}),p.isFetched&&p.data&&p.data?.items.length===0&&s.jsx(St,{variant:"info",children:"No runs found"}),p.isFetched&&p.data&&p.data?.items.length>0&&s.jsxs(Ht,{striped:!0,bordered:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Run"}),s.jsx("th",{children:"Priority"}),s.jsx("th",{children:"Hold Code"}),s.jsx("th",{children:"Batch Card"}),s.jsx("th",{children:"Project"})]})}),s.jsx("tbody",{children:p.data?.items.map((k,A)=>s.jsxs("tr",{children:[s.jsxs("td",{children:[k.first_unfinished_step&&s.jsx(Te.Link,{to:`/${e}/operator/run/step/${k.first_unfinished_step.id}`,children:k.name}),k.first_unfinished_step===void 0&&k.last_finished_step&&s.jsx(Te.Link,{to:`/${e}/operator/run/step/${k.last_finished_step.id}`,children:k.name})]}),s.jsxs("td",{children:[k.priority&&s.jsx("span",{className:"badge",style:{backgroundColor:k.priority.priority.back_color,color:k.priority.priority.front_color},children:k.priority.priority.code}),!k.priority&&s.jsx("span",{className:"badge bg-info",children:"NORMAL"})]}),s.jsx("td",{children:k.hold_code&&s.jsx("span",{className:"badge handle",style:{backgroundColor:k.hold_code.hold_code.back_color,color:k.hold_code.hold_code.front_color},children:k.hold_code.hold_code.code})}),s.jsx("td",{children:k.batch_card&&k.batch_card.content&&s.jsx("span",{className:"text-danger",children:k.batch_card.content})}),s.jsx("td",{children:k.project.name})]},A))})]}),s.jsx(dG,{})]}),s.jsxs(Pt,{md:4,children:[s.jsx("h2",{children:"Assistance"}),I.data?.items.map((k,A)=>s.jsxs(x.Fragment,{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("h3",{children:k.type.is_main_tool?"Main tool":k.name}),s.jsx("div",{children:s.jsx(Jr,{module:k})})]}),s.jsxs("div",{className:"pb-lg-5",children:[s.jsx("div",{className:"d-flex justify-content-between",children:s.jsxs("div",{className:"d-flex gap-2",children:[s.jsx("div",{children:s.jsx(ie,{variant:"primary",size:"sm",onClick:N,children:"New Issue"})}),s.jsx("div",{children:s.jsx(ie,{variant:"primary",size:"sm",onClick:j,children:"New ECN"})}),s.jsx("div",{children:k.type.is_main_tool&&s.jsx(G0,{size:"sm",moduleId:k.id})})]})}),y(k.id)?.map((F,L)=>s.jsx(uG,{ecn:F,equipment:t,ecnAttachments:C.data?.items??[],reloadQueryFn:_},`ecn-${A}-${L}`)),S(k.id)?.map((F,L)=>s.jsx(cG,{issue:F,equipment:t,issueAttachments:b.data?.items??[],reloadQueryFn:_},`issue-${A}-${L}`))]})]},A))]})]}),u&&l,a&&r]})}const pG=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&qp({id:parseInt(n)}).then(t)},[n,e]);function r(){qp({id:parseInt(n)}).then(t)}return{equipment:e,setEquipment:t,reloadEquipment:r}};function B0({children:e}){const{equipment:t,reloadEquipment:n}=pG();return t===null?s.jsx(jn,{children:s.jsx(zt,{message:"Loading equipment..."})}):s.jsx(jn,{children:s.jsx(Ql.Provider,{value:{equipment:t,reloadEquipment:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function mG(){const{equipment:e}=x.useContext(Ql),t=Ae.useQueries({queries:[{queryKey:["activeReservationQuery",e],queryFn:()=>To({equipment:e,which:"active"})},{queryKey:["upcomingReservationQuery",e],queryFn:()=>To({equipment:e,which:"upcoming"})},{queryKey:["modules",e],queryFn:()=>xi({equipment:e})}]}),[n,r,i]=t,a=t.some(l=>l.isLoading);t.some(l=>l.isError);const o=t.every(l=>l.isSuccess);return a?s.jsx("div",{children:"Loading..."}):(i.data?.items.findLast(l=>l.type.is_main_tool),o&&s.jsxs("div",{className:"d-flex align-items-center justify-content-between mb-3",children:[s.jsxs("h1",{className:"display-4",children:[e.name," Operator Dashboard"]}),s.jsxs("div",{children:[n.data?.items.map((l,c)=>s.jsxs("div",{className:"mx-2 p-2 rounded border-danger",style:{backgroundColor:l.color},children:[s.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Active reservation",s.jsx("br",{}),"Until ",ln(l.end,"DD-MM-YY HH:mm")," by ",l.user.full_name]},c)),r.data?.items.map((l,c)=>s.jsxs("div",{className:"mx-2 p-2 rounded border-success border-2",style:{backgroundColor:l.color},children:[s.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Next reservation",s.jsx("br",{}),ln(l.start,"DD-MM-YY HH:mm"),s.jsx("br",{}),l.user.full_name]},c))]})]}))}function hG(){return s.jsxs(B0,{children:[s.jsx(mG,{}),s.jsx(Te.Outlet,{})]})}function gG({children:e}){const{id:t}=Te.useParams(),n=Ae.useQuery({queryKey:["statusMail",t],queryFn:()=>x1({id:parseInt(t)}),enabled:!!t});return n.isLoading||n.isFetching?s.jsx(jn,{children:s.jsx(zt,{message:"Loading status mail..."})}):s.jsx(jn,{children:s.jsx(Tl.Provider,{value:{statusMail:n.data},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}const Y0=()=>sx();function xG(e){const[t,n]=x.useState(!0),[r,i]=x.useState(null),[a,o]=x.useState(!1),l=()=>{n(!1),o(!0)};return x.useEffect(()=>{if(!document){const p=new Error(`[ScriptLoadingError] document not defined when attempting to load ${e}`);i(p);return}const c=document.querySelector(`script[src="${e}"]`);if(c?.dataset.loaded){l();return}const u=c||document.createElement("script");c||(u.src=e);const d=()=>{u.dataset.loaded="1",l()};u.addEventListener("load",d),u.addEventListener("error",p=>{console.error("Failed to load script:",e,p);const g=new Error(`[ScriptLoadingError] Failed to load script: ${e}`);i(g)}),c||document.head.append(u)},[]),{isLoading:t,error:r,isSuccess:a}}const vG=e=>e&&e.charts,Vg=(e,t)=>{const{controls:n,toolbarItems:r,getChartEditor:i}=e;return t&&t.charts&&t.visualization&&t.visualization.ChartWrapper&&t.visualization.Dashboard&&(!n||t.visualization.ChartWrapper)&&(!i||t.visualization.ChartEditor)&&(!r||t.visualization.drawToolbar)},yG=e=>window.google;function bG(e){const{chartVersion:t="current",chartPackages:n=["corechart","controls"],chartLanguage:r="en",mapsApiKey:i}=e,[a,o]=x.useState(null),[l,c]=x.useState(null),[u,d]=x.useState(null),{isLoading:p,error:g,isSuccess:m}=xG(e.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return x.useEffect(()=>{if(!m)return;const v=yG();if(!vG(v)){const I=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");c(I);return}if(Vg(e,v)){o(v);return}v.charts.load(t,{packages:n,language:r,mapsApiKey:i}),v.charts.setOnLoadCallback(()=>{if(!Vg(e,v)){const I=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(I),d(I);return}o(v)})},[m]),{error:g||l||u,isLoading:p,google:a}}const W0={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},wG=e=>{const{isReady:t,chartControls:n,filter:r}=e;return!t||!n||!n?.length?null:x.createElement(x.Fragment,null,n.filter(i=>{let{controlProp:a,control:o}=i;return r?r({control:o,controlProp:a}):!0}).map(i=>{let{control:a}=i;return x.createElement("div",{key:a.getContainerId(),id:a.getContainerId()})}))};let Gg=0;const z0=()=>(Gg+=1,`reactgooglegraph-${Gg}`),Kn=class Kn{};kn(Kn,"initializeControls",t=>{for(let n=0;n<t.length;n+=1){const{controlType:r,options:i,controlWrapperParams:a}=t[n].controlProp;a&&"state"in a&&t[n].control.setState(a.state),t[n].control.setOptions(i),t[n].control.setControlType(r)}}),kn(Kn,"listenToControlEvents",(t,n)=>{const{google:r}=n;return t.flatMap(i=>{const{control:a,controlProp:o}=i,{controlEvents:l=[]}=o;return l.map(c=>{const{callback:u,eventName:d}=c;return r.visualization.events.addListener(a,d,function(){for(var p=arguments.length,g=new Array(p),m=0;m<p;m++)g[m]=arguments[m];u({chartWrapper:null,controlWrapper:a,props:n,google:r,eventArgs:g})})})})}),kn(Kn,"createControlId",t=>{let n;return typeof t>"u"?n=`googlechart-control-${z0()}`:n=t,n}),kn(Kn,"createChartControls",t=>{const{controls:n,google:r}=t;return n?n.map((i,a)=>{const{controlID:o,controlType:l,options:c,controlWrapperParams:u}=i,d=Kn.createControlId(o);return{controlProp:i,control:new r.visualization.ControlWrapper({containerId:d,controlType:l,options:c,...u})}}):null}),kn(Kn,"addControls",t=>{const{chartWrapper:n,chartDashboard:r}=t,i=Kn.createChartControls(t);return!i||!r||!n?null:(r.bind(i.map(a=>{let{control:o}=a;return o}),n),Kn.initializeControls(i),i)});let fl=Kn;const CG=e=>{const[t,n]=$.useState(null);return[$.useMemo(()=>!t||!e?null:e.map((i,a)=>{const o=t[a];return o?{controlProp:i,control:o}:void 0}).flatMap(i=>i?[i]:[]),[t,e]),n]},SG=(e,t)=>{$.useEffect(()=>{const n=fl.listenToControlEvents(e??[],t);return()=>{n.forEach(r=>{t.google.visualization.events.removeListener(r)})}},[e,t])},jG=e=>{const[t,n]=CG(e.controls);return SG(t??[],e),{addControls:i=>{const a=fl.addControls(i);n(a?.map(o=>o.control)??null)},renderControl:i=>{const{chartWrapper:a,chartDashboard:o}=e;return $.createElement(wG,{...e,isReady:!!(a&&o),chartControls:t,filter:i})}}},IG=e=>{const t=$.useRef(null);return{chartId:(()=>{const{graphID:i,graph_id:a}=e,o=i||a;let l;return o?l=o:l=t.current||z0(),t.current=l,t.current})()}},_G=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],EG=async function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((r,i)=>{const a=`${n.headers?`headers=${n.headers}`:"headers=0"}`,o=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,l=`${n.gid?`&gid=${n.gid}`:""}`,c=`${n.sheet?`&sheet=${n.sheet}`:""}`,u=`${n.access_token?`&access_token=${n.access_token}`:""}`,d=`${a}${l}${c}${o}${u}`,p=`${t}/gviz/tq?${d}`;new e.visualization.Query(p).send(m=>{m.isError()?i(`Error in query: ${m.getMessage()} ${m.getDetailedMessage()}`):r(m.getDataTable())})})},kG="#CCCCCC",An=class An{};kn(An,"grayOutHiddenColumnsLabel",(t,n)=>{const{googleChartWrapper:r,options:i}=t;if(!r){console.error("googleChartWrapper is not defined");return}const a=r.getDataTable();if(!a)return;const o=a.getNumberOfColumns();if(n.length>0===!1)return;const c=Array.from({length:o-1}).map((u,d)=>{const p=An.getColumnId(a,d+1);return n.includes(p)?kG:i&&i.colors?i.colors[d]:_G[d]});r.setOptions({...i,colors:c}),r.draw()}),kn(An,"listenToLegendToggle",(t,n)=>{const[r,i]=n,{google:a,googleChartWrapper:o}=t;if(!o){console.error("googleChartWrapper is not defined");return}return a.visualization.events.addListener(o,"select",()=>{const c=o.getChart().getSelection(),u=o.getDataTable();if(c.length===0||c[0].row!==null||!u)return;const d=c[0].column,p=An.getColumnId(u,d);r?.includes(p)?i(g=>[...g.filter(m=>m!==p)]):i(g=>[...g,p])})}),kn(An,"draw",async t=>{const{data:n,diffdata:r,rows:i,columns:a,options:o,chartType:l,formatters:c,spreadSheetUrl:u,spreadSheetQueryParameters:d,googleChartDashboard:p,googleChartWrapper:g,google:m,hiddenColumns:v,legendToggle:I,legend_toggle:C}=t;if(!g){console.error("draw was called with googleChartWrapper = null");return}let b,_=null;if(r){const k=m.visualization.arrayToDataTable(r.old),A=m.visualization.arrayToDataTable(r.new);_=m.visualization[l].prototype.computeDiff(k,A)}n?n instanceof m.visualization.DataTable?b=n:Array.isArray(n)?b=m.visualization.arrayToDataTable(n):b=new m.visualization.DataTable(n):i&&a?b=m.visualization.arrayToDataTable([a,...i]):u?b=await EG(m,u,d):b=m.visualization.arrayToDataTable([]);const y=b.getNumberOfColumns(),S=Array(y).fill(0).map((k,A)=>{const F=An.getColumnId(b,A);return v.includes(F)?{label:b.getColumnLabel(A),type:b.getColumnType(A),calc:()=>null}:A}),j=g.getChart();g.getChartType()==="Timeline"&&j&&j.clearChart(),g.setChartType(l),g.setOptions(o||{});const N=new m.visualization.DataView(b);N.setColumns(S),g.setDataTable(N),g.draw(),p&&p.draw(b),_&&(g.setDataTable(_),g.draw()),c&&(An.applyFormatters({dataTable:b,formatters:c,google:m}),g.setDataTable(b),g.draw()),(I===!0||C===!0)&&An.grayOutHiddenColumnsLabel(t,v)}),kn(An,"getColumnId",(t,n)=>t.getColumnId(n)||t.getColumnLabel(n)),kn(An,"applyFormatters",t=>{let{dataTable:n,formatters:r,google:i}=t;for(let a of r)switch(a.type){case"ArrowFormat":{new i.visualization.ArrowFormat(a.options).format(n,a.column);return}case"BarFormat":{new i.visualization.BarFormat(a.options).format(n,a.column);return}case"ColorFormat":{const o=new i.visualization.ColorFormat(a.options),{ranges:l}=a;if(l)for(let c of l)o.addRange(...c);o.format(n,a.column);return}case"DateFormat":{new i.visualization.DateFormat(a.options).format(n,a.column);return}case"NumberFormat":{new i.visualization.NumberFormat(a.options).format(n,a.column);return}case"PatternFormat":{new i.visualization.PatternFormat(a.options).format(n,a.column);return}default:{console.warn(`Unknown formatter type: ${a.type}`);return}}});let sa=An;const NG=e=>{const{google:t,googleChartWrapper:n,googleChartDashboard:r}=e,[i,a]=$.useState([]);$.useEffect(()=>{n&&sa.draw({...e,hiddenColumns:i,googleChartWrapper:n,googleChartDashboard:r,google:t})},[i,e.data,e.rows,e.columns,e.options,e.chartLoaderScriptUrl,e.chartType,e.formatters,e.spreadSheetUrl,e.spreadSheetQueryParameters,e.legendToggle,e.legend_toggle]);const o=()=>{const{googleChartWrapper:u}=e;u&&u.draw()},l=u=>{const d=[],{legendToggle:p,legend_toggle:g}=e;if(sa.draw({...e,hiddenColumns:i,googleChartWrapper:u,googleChartDashboard:r,google:t}),window.addEventListener("resize",o),g||p){const m=sa.listenToLegendToggle(e,[i,a]);m&&d.push(m)}return d},c=(u,d)=>{window.removeEventListener("resize",o),d.forEach(p=>{t.visualization.events.removeListener(p)}),u.getChartType()==="Timeline"&&u.getChart()&&u.getChart().clearChart()};$.useEffect(()=>{if(!n)return;const u=l(n);return()=>{c(n,u)}},[n,l,c])},AG=e=>{const{chartEvents:t,google:n,googleChartWrapper:r}=e;if(t){if(!r){console.warn("listenToEvents was called before chart wrapper ready.");return}return t.map(i=>{let{eventName:a,callback:o}=i;return n.visualization.events.addListener(r,a,function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];o({chartWrapper:r,props:e,google:n,eventArgs:c})})})}},RG=e=>{x.useEffect(()=>{if(!e.googleChartWrapper)return;const t=AG(e);return()=>{t?.forEach(n=>{e.google.visualization.events.removeListener(n)})}},[e])},DG=e=>{const[t,n]=$.useState(null),[r,i]=$.useState(null),{addControls:a,renderControl:o}=jG({...e,chartDashboard:r,chartWrapper:t});RG({...e,googleChartWrapper:t});const{chartId:l}=IG(e),c=$.useRef(null),u=$.useRef(null);$.useEffect(()=>{const{options:b,google:_,chartType:y,chartWrapperParams:S,toolbarItems:j,getChartEditor:N,getChartWrapper:k,onLoad:A}=e,F={chartType:y,options:b,containerId:l,...S},L=new _.visualization.ChartWrapper(F);L.setOptions(b||{}),k?.(L,_);const Y=new _.visualization.Dashboard(c.current);j&&_.visualization.drawToolbar(u.current,j);let G=null;N&&(G=new _.visualization.ChartEditor,N({chartEditor:G,chartWrapper:L,google:_})),a({...e,chartDashboard:Y,chartWrapper:L}),n(L),i(Y),A?.(_,{google:_,chartWrapper:L,chartEditor:G,chartDashboard:Y})},[]),NG({...e,googleChartWrapper:t,googleChartDashboard:r});const d=()=>{const{width:b,height:_,options:y,style:S,className:j,rootProps:N,google:k}=e,A={height:_||y&&y.height,width:b||y&&y.width,...S};return $.createElement("div",{id:l,style:A,className:j,...N})},p=()=>e.toolbarItems?$.createElement("div",{ref:u}):null,{width:g,height:m,options:v,style:I}=e,C={height:m||v&&v.height,width:g||v&&v.width,...I};return e.render?$.createElement("div",{ref:c,style:C},$.createElement("div",{ref:u,id:"toolbar"}),e.render({renderChart:d,renderControl:o,renderToolbar:p})):$.createElement("div",{ref:c,style:C},o(b=>{let{controlProp:_}=b;return _.controlPosition!=="bottom"}),d(),o(b=>{let{controlProp:_}=b;return _.controlPosition==="bottom"}),p())},MG=$.createContext(W0),OG=e=>{let{children:t,value:n}=e;return $.createElement(MG.Provider,{value:n},t)},TG=e=>{const{google:t,isLoading:n,error:r}=bG(e);return n?e.loader??null:r?e.errorElement??null:t?x.createElement(DG,{google:t,...e}):null},FG=e=>{const t={...W0,...e};return x.createElement(OG,{value:t},x.createElement(TG,t))};var Bg;(function(e){e.annotation="annotation",e.annotationText="annotationText",e.certainty="certainty",e.emphasis="emphasis",e.interval="interval",e.scope="scope",e.style="style",e.tooltip="tooltip",e.domain="domain"})(Bg||(Bg={}));function PG({target:e,results:t}){const n={title:e.logging_parameter.name,curveType:"function",series:{0:{pointSize:10},1:{},2:{},3:{}},legend:{position:"bottom"}};let r=[[{type:"date",label:"Date"},"Value"]],i=1;return e.target&&(r[0].push("Target"),n.series[i]={color:"#38e22c",lineWidth:2,pointShape:{type:"square"}},i++),e.min_value&&(r[0].push("Min"),n.series[i]={color:"#e2431e",lineWidth:2,pointShape:{type:"triangle"},pointSize:10},i++),e.max_value&&(r[0].push("Max"),n.series[i]={color:"#e2431e",lineWidth:2,pointShape:{type:"triangle",rotation:180},pointSize:10}),t.forEach(a=>{a.values.filter(o=>o.logging_parameter.id===e.logging_parameter.id).filter(o=>o.float_value!==0).forEach(o=>{let l=new Date(a.date_created);r.push([l,o.float_value]),e.target&&r[r.length-1].push(e.target),e.min_value&&r[r.length-1].push(e.min_value),e.max_value&&r[r.length-1].push(e.max_value)})}),r.length===1?s.jsx("div",{className:"text-center",children:"No data available"}):s.jsx(FG,{chartType:"ScatterChart",width:"100%",height:"400px",data:r,options:n})}const za=({data:e,setPage:t,setPageSize:n,pageSize:r,isPlaceholderData:i})=>{if(e===void 0||i)return s.jsx(s.Fragment,{});let a=[];for(let o=1;o<=e.amountOfPages;o++)a.push(s.jsx(Ym.Item,{active:o===e.currentPage,onClick:()=>t(l=>o),children:o},o));return s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs("div",{className:"d-flex gap-2",children:[s.jsx("div",{children:s.jsx(ie,{size:"sm",onClick:()=>t(o=>Math.max(o-1,0)),disabled:e.currentPage===1,children:"Previous Page"})}),s.jsx(Ym,{size:"sm",children:a.map((o,l)=>s.jsx("div",{children:o},l))}),s.jsx("div",{children:s.jsx(ie,{size:"sm",onClick:()=>{!i&&e.hasMore&&t(o=>o+1)},disabled:i||!e.hasMore,children:"Next Page"})})]}),n!==void 0?s.jsx("div",{children:s.jsxs(W.Select,{onChange:o=>{n(l=>parseInt(o.target.value))},value:r,size:"sm",children:[s.jsx("option",{value:10,children:"10"}),s.jsx("option",{value:25,children:"25"}),s.jsx("option",{value:50,children:"50"}),s.jsx("option",{value:100,children:"100"})]})}):null]})},LG=new Date().toISOString().split("T")[0],VG=({requirement:e,targets:t,refetchResults:n})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(!1),[l,c]=x.useState(!1),{control:u,register:d,handleSubmit:p,reset:g,watch:m,formState:{errors:v,isValid:I}}=tn({defaultValues:{date:LG}}),{fields:C,append:b,remove:_}=Zk({control:u,name:"results",rules:{required:!0}});x.useEffect(()=>{_(),t.forEach(N=>{b({id:N.id,label:N.logging_parameter.name,logging_parameter_id:N.logging_parameter.id,value:""})})},[t]);const y=m();x.useEffect(()=>{c(I)},[y,I]);async function S(N){await te.post("create/monitor/requirement/result",{requirement:e.id,date:N.date,values:N.results}),o(!0),i(!1),n(),g()}function j(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>o(!1),show:a,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Results saved"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Measurement results were saved successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"primary",onClick:()=>i(!0),children:"Add manual result"}),s.jsx(ve,{show:r,size:"lg",onHide:()=>i(!1),children:s.jsxs(W,{onSubmit:p(N=>S(N)),validated:l,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Add manual result"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Date"}),s.jsx(W.Control,{type:"date",placeholder:"Date",required:!0,...d("date",{required:"This field is required"})},"date"),v.date&&s.jsx(W.Control.Feedback,{children:v.date.message})]}),C.map((N,k)=>s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:N.label}),s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{type:"number",step:.01,placeholder:N.label,required:!0,...d(`results.${k}.value`,{required:"This field is required"})},N.id),v?.results?.[k]?.value&&s.jsx(W.Control.Feedback,{children:v.results[k].value.message})]})]},k))]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{g(),i(!1)},children:"Close"})]})]})}),s.jsx(j,{})]})},GG=({requirement:e,result:t,refetchMonitorStepParameterValues:n})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(!1),[l,c]=x.useState(!1),[u,d]=x.useState([]),{control:p,register:g,handleSubmit:m,reset:v,watch:I,formState:{errors:C,isValid:b}}=tn({defaultValues:{}});x.useEffect(()=>{async function j(){const N=await nx({result:t}),k=await N1({requirement:e}),A=await w1({module:e.step.process_module.module});k.items=k.items.filter(F=>!N.items.map(L=>L.step_parameter.id).includes(F.id)),k.items=k.items.filter(F=>A.items.map(L=>L.parameter.id).includes(F.parameter.id)),d(k.items)}r&&j()},[r]);const _=I();x.useEffect(()=>{c(b)},[_,b]);async function y(j){await te.post("create/monitor/requirement/result/step-parameter-value",{result:t.id,step_parameter:j.module_step_parameter_id,value:j.value}),o(!0),i(!1),n(),v()}function S(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>o(!1),show:a,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Results saved"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Measurement results were saved successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"primary",size:"sm",onClick:()=>i(!0),children:"+"}),s.jsx(ve,{show:r,size:"lg",onHide:()=>i(!1),children:s.jsxs(W,{onSubmit:m(j=>y(j)),validated:l,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Add process parameter"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Date"}),s.jsx(W.Control,{type:"text",value:t.date_created,readOnly:!0})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Module Step Parameter"}),s.jsxs(W.Select,{...g("module_step_parameter_id",{required:!0}),children:[s.jsx("option",{value:"",children:"— Select a parameter"}),u.map(j=>s.jsx("option",{value:j.id,children:j.parameter.name},j.id))]}),s.jsx(W.Text,{className:"text-muted",children:"Only parameters are shown here which are active on the Equipment Module and in the monitor step. In case parameters are missing you should replace the process in the monitor with the same process from the process library to reload the parameters"})]}),s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{type:"number",step:.01,required:!0,...g("value",{required:"This field is required"})}),C?.value&&s.jsx(W.Control.Feedback,{children:C.value.message})]})]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{v(),i(!1)},children:"Close"})]})]})}),s.jsx(S,{})]})},BG=({monitorResultStepParameterValue:e,refetchMonitorStepParameterValues:t})=>{const[n,r]=x.useState(!1),[i,a]=x.useState(!1),[o,l]=x.useState(!1),{control:c,register:u,handleSubmit:d,reset:p,watch:g,formState:{errors:m,isValid:v}}=tn({defaultValues:{value:e.value.toString()}}),I=g();x.useEffect(()=>{l(v)},[I,v]);async function C(y){await te.patch("update/monitor/requirement/result/step-parameter-value/"+e.id,{value:y.value}),a(!0),r(!1),t(),p()}async function b(){await te.delete("delete/monitor/requirement/result/step-parameter-value/"+e.id,{}),a(!0),r(!1),t(),p()}function _(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>a(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Results saved"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Measurement results were saved successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx("span",{onClick:()=>r(!0),children:e.value}),s.jsx(ve,{show:n,size:"lg",onHide:()=>r(!1),children:s.jsxs(W,{onSubmit:d(y=>C(y)),validated:o,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Add process parameter"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Date"}),s.jsx(W.Control,{type:"text",value:e.date_created,readOnly:!0})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Module Step Parameter"}),s.jsx(W.Control,{type:"text",value:e.step_parameter.parameter.name,readOnly:!0})]}),s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{type:"number",step:.01,required:!0,...u("value",{required:"This field is required"})}),m?.value&&s.jsx(W.Control.Feedback,{children:m.value.message})]})]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",type:"submit",variant:"primary",children:"Update value"}),s.jsx(ie,{className:"float-end",variant:"danger",onClick:()=>b(),children:"Delete value"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{p(),r(!1)},children:"Close"})]})]})}),s.jsx(_,{})]})};function YG({requirement:e}){const[n,r]=x.useState([]),[i,a]=x.useState(""),[o,l]=x.useState(1),[c,u]=x.useState(15),[d,p]=x.useState([]),[g,m,v,I]=Ae.useQueries({queries:[{queryKey:["requirement","files",e.step,11],queryFn:()=>k1({step:e.step,pageSize:11,order:"date-created",direction:"desc"})},{queryKey:["requirement","target",e],queryFn:()=>E1({requirement:e})},{queryKey:["requirement","results",e,o,c],queryFn:()=>_1({requirement:e,pageSize:c,order:"date-created",direction:"desc",page:o}),placeholderData:Ae.keepPreviousData},{queryKey:["requirement","monitor_step_parameters",e,o,c],queryFn:()=>nx({requirement:e,pageSize:c,order:"date-created",direction:"desc",page:o}),placeholderData:Ae.keepPreviousData}]});x.useEffect(()=>{r([]),!g.isLoading&&g.data.items.forEach(k=>{r(A=>[...A,k])})},[g.isLoading]),x.useEffect(()=>{if(!I.data)return;const k=Array.from(new Map(I.data.items.map(A=>[A.step_parameter.id,A.step_parameter])).values());p(k)},[I.isLoading,I.data]);const C=x.useCallback(k=>{k.forEach(A=>{const F=new FileReader;F.onload=async()=>{const L=F.result;try{await te.create().post("update/monitor/requirement/upload-file/"+e.id,{content:L,filename:A.name,type:A.type})}catch(Y){a("Upload failed due to: "+Y.response.data.detail)}await g.refetch(),await v.refetch()},F.readAsDataURL(A)})},[e.id,g,v]),{getRootProps:b,getInputProps:_,isDragActive:y,isDragAccept:S,isDragReject:j}=Ta({onDrop:C}),N=x.useMemo(()=>({...y?{borderColor:"#83afee"}:{},...S?{borderColor:"#00e676"}:{},...j?{borderColor:"#ff1744"}:{}}),[S,j,y]);return m.isLoading||m.isFetching?s.jsx(St,{variant:"info",children:"Loading targets..."}):v.isLoading||v.isFetching?s.jsx(St,{variant:"info",children:"Loading results..."}):s.jsxs(s.Fragment,{children:[s.jsxs("h1",{className:"display-5",children:["Requirement: ",e.title]}),s.jsx("p",{className:"lead",children:e.definition}),s.jsx(Un,{className:"my-3",children:s.jsxs(Pt,{children:[s.jsx("h2",{children:"Charts"}),s.jsx("div",{className:"d-flex",children:m.data?.items.map((k,A)=>s.jsx(PG,{target:k,results:v.data.items},A))})]})}),s.jsxs(Un,{children:[s.jsxs(Pt,{md:8,children:[e.method&&e.method!=="-"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{children:"Method"}),s.jsx("p",{children:e.method})]}),m.data?.items.length===0&&s.jsx(St,{variant:"danger",children:"No targets found"}),s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("h2",{children:"Results"}),s.jsx("div",{children:s.jsx(VG,{requirement:e,targets:m.data.items,refetchResults:v.refetch})})]}),s.jsxs(Ht,{size:"sm",striped:!0,bordered:!0,hover:!0,children:[s.jsxs("thead",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:"ID"}),s.jsx("th",{children:"Date"}),m.data?.items.map((k,A)=>s.jsx("th",{children:k.logging_parameter.name},A)),d.map((k,A)=>s.jsx("th",{children:k.parameter.name},A)),s.jsx("th",{children:"+"})]}),s.jsxs("tr",{children:[s.jsx("th",{colSpan:2}),m.data?.items.map((k,A)=>s.jsxs("td",{children:[k.min_value,k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:"≤"}),!k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:"<"}),k.target??"X",k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:"≥"}),!k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:">"}),k.max_value]},A)),d.map((k,A)=>s.jsx("th",{className:"table-secondary"},A)),s.jsx("th",{})]})]}),s.jsx("tbody",{children:v.data?.items.map((k,A)=>s.jsxs("tr",{children:[s.jsx("th",{children:s.jsx("small",{className:"text-muted",children:k.id})},A),s.jsx("td",{children:ln(k.date_created,"DD-MM-YY HH:mm")}),m.data?.items.map((F,L)=>s.jsx("td",{children:k.values.filter(Y=>Y.logging_parameter.id===F.logging_parameter.id).map((Y,G)=>s.jsx("span",{className:Y.value_is_valid?"text-success":"text-danger",children:Y.float_value},G))},L)),d.map((F,L)=>s.jsx("td",{className:"table-secondary",children:I.data?.items.filter(Y=>Y.step_parameter.id===F.id&&Y.result.id===k.id).map((Y,G)=>s.jsx(BG,{monitorResultStepParameterValue:Y,refetchMonitorStepParameterValues:I.refetch},G))},L)),s.jsx("td",{children:s.jsx(GG,{result:k,requirement:e,refetchMonitorStepParameterValues:I.refetch})})]},A))})]}),s.jsx(za,{data:v.data,setPage:l,setPageSize:u,pageSize:c,isPlaceholderData:v.isPlaceholderData})]}),s.jsxs(Pt,{md:4,children:[s.jsx("h2",{children:"Upload new results"}),s.jsx("p",{children:"Drop your results file here"}),s.jsxs("div",{...b({style:N,className:"dropzone"}),children:[s.jsx("input",{..._()}),y?s.jsx("p",{children:"Drop file(s) here ..."}):s.jsx("p",{children:"Drag and drop file(s) here, or click to select files"}),s.jsx("p",{children:i})]}),n.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{className:"mt-2",children:"Uploaded files"}),s.jsxs("p",{children:["Last ",11," uploaded files"]}),s.jsx("ul",{className:"list-group",children:n.map((k,A)=>s.jsxs("li",{className:"list-group-item",children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs("span",{children:[A+1," ",s.jsx("a",{href:Y0()+k.url,children:k.name}),k.has_monitor_step_loggings&&s.jsx(Ft,{className:"ms-1 bg-primary",children:"Logging"})]}),s.jsxs("span",{children:[Math.round(k.size/1024),"kiB"]})]}),s.jsx("small",{className:"text-muted",children:ln(k.date_created,"DD-MM-YY HH:mm")})]},A))})]})]})]})]})}function WG(){let{id:e}=Te.useParams();const[t,n]=Ae.useQueries({queries:[{queryKey:["monitor",e],queryFn:()=>Cu({id:parseInt(e)})},{queryKey:["requirements",e],queryFn:()=>ex({monitorId:parseInt(e)})}]});return t.isLoading?s.jsx("div",{children:"Loading..."}):s.jsxs("div",{children:[s.jsxs("h1",{className:"display-4",children:["SPC Test ",t.data?.name]}),n.data?.items.map((r,i)=>s.jsx("div",{className:"border border-1 p-3 my-3",children:s.jsx(YG,{requirement:r})},i))]})}function zG(){return s.jsx(Ii,{fluid:!0,children:s.jsx(Te.Outlet,{})})}const HG=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&Cu({id:parseInt(n)}).then(t)},[n,e]);function r(){Cu({id:parseInt(n)}).then(t)}return{monitor:e,setMonitor:t,reloadMonitor:r}},H0=x.createContext({monitor:{},reloadMonitor:()=>{}});function UG({children:e}){const{monitor:t,reloadMonitor:n}=HG();return t===null?s.jsx(jn,{children:s.jsx(zt,{message:"Loading monitor..."})}):s.jsx(jn,{children:s.jsx(H0.Provider,{value:{monitor:t,reloadMonitor:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}const $G=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{(e===null||n!==e.id.toString())&&Fo({id:parseInt(n)}).then(t)},[n,e]);function r(){Fo({id:parseInt(n)}).then(t)}return{run:e,reloadRun:r}},Ri=x.createContext({run:{},reloadRun:()=>{}});function U0({children:e}){const{run:t,reloadRun:n}=$G();return t===null?s.jsx(jn,{children:s.jsx(zt,{message:"Loading run..."})}):s.jsx(jn,{children:s.jsx(Ri.Provider,{value:{run:t,reloadRun:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function XG({text:e}){if(!e)return null;const t=e.split(/\r\n|\n|\r/);return s.jsx(s.Fragment,{children:t.map((n,r)=>s.jsxs(x.Fragment,{children:[n,r<t.length-1&&s.jsx("br",{})]},r))})}const wi=({children:e,format:t="d-M-Y"})=>{const n=Date.parse(e);return s.jsx(s.Fragment,{children:ye(n).format(t)})},ip=({run:e})=>{const[t,n]=x.useState(e.batch_card),[r,i]=x.useState(!1),{register:a,handleSubmit:o,formState:l,resetField:c}=tn({defaultValues:{content:t?.content}}),{isSubmitting:u,errors:d}=l,p=async m=>{await te.create().patch("update/run/batch-card/"+e.id,{content:m.content}),i(!1);const v=await te.get("view/run/"+e.id);n(v.data.batch_card)},g=async()=>{await te.create().delete("delete/run/batch-card/"+e.id),i(!1),n(void 0),c("content")};return r?s.jsxs(W,{onSubmit:o(p),className:"mb-3",children:[s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{as:"textarea",rows:6,...a("content",{required:!0}),isInvalid:d.content!==void 0}),d.content&&s.jsx(W.Control.Feedback,{type:"invalid",children:"This field is required"})]}),s.jsxs("div",{className:"d-flex flex-column flex-md-row gap-2 justify-content-between mt-2",children:[s.jsxs("div",{className:"d-flex flex-wrap gap-2",children:[s.jsxs(ie,{variant:"primary",type:"submit",disabled:u,className:"text-nowrap",children:[u&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save batch card"]}),s.jsx(ie,{variant:"secondary",onClick:()=>i(!1),children:"Cancel"})]}),t&&s.jsx("div",{children:s.jsx(ie,{variant:"outline-danger",className:"text-nowrap",onClick:g,children:"Delete batch card"})})]})]}):t?t&&s.jsxs(Ye,{className:"rounded my-4 shadow-sm border-0",children:[s.jsxs(Ye.Body,{children:[s.jsxs("div",{className:"d-flex align-items-start justify-content-between gap-3",children:[s.jsx(Ye.Title,{className:"text-danger mb-0",children:"Batch card"}),s.jsx(ie,{variant:"outline-primary",size:"sm",className:"text-nowrap",onClick:()=>i(!0),children:"Update batch card"})]}),s.jsx(Ye.Text,{className:"mt-3 mb-2 fs-5 text-body",children:t&&s.jsx(XG,{text:t.content})})]}),s.jsx(Ye.Footer,{className:"bg-transparent border-0 pt-0 pb-3",children:s.jsxs("div",{className:"text-muted small",children:["Created ",s.jsx(wi,{format:"DD-MM-YY",children:t.date_created})," by"," ",t.user.first_name," ",t.user.last_name,t.last_update&&s.jsxs("span",{children:[" (","Updated ",s.jsx(wi,{format:"DD-MM-YY H:m",children:t.last_update}),")"]})]})})]}):s.jsx(ie,{variant:"outline-primary",className:"mb-4",onClick:()=>i(!0),children:"Create Batch Card"})};function qG(){const{run:e}=x.useContext(Ri);return s.jsxs(s.Fragment,{children:[e.run_type===Wn.RESEARCH&&s.jsx("small",{children:"Research run"}),e.run_type===Wn.PRODUCTION&&s.jsx("small",{children:"Production run"}),s.jsx("div",{className:"d-flex justify-content-between align-items-center mb-3",children:s.jsxs("h1",{className:"display-4",children:[e.name," (",e.project.name,")"]})}),s.jsx(ip,{run:e})]})}function ZG(e){const{run:t,reloadRun:n}=x.useContext(Ri),{environment:r}=Te.useParams(),i=window.location.pathname;let a=[{title:"Information",link:`/${r}/operator/run/details/${t.id}/information`}];return a.push({title:"Steps",link:`/${r}/operator/run/details/${t.id}/steps`}),s.jsx(Vm,{variant:"tabs",className:e.className,defaultActiveKey:"/home",activeKey:i,children:a.map((o,l)=>s.jsx(Vm.Item,{children:s.jsx(Te.Link,{to:o.link,className:"nav-link "+(o.link===i?"active":""),children:o.title})},l))})}function JG(){return s.jsx(U0,{children:s.jsxs(Ii,{fluid:!0,children:[s.jsx(qG,{}),s.jsx(ZG,{className:"mb-4"}),s.jsx(Te.Outlet,{})]})})}const Kl=x.createContext({showOnlyEmphasizedParameters:!1,setShowOnlyEmphasizedParameters:()=>{}}),QG=({parameter:e,value:t,refetchFn:n})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(t.value),l=async c=>{const u={value:c};try{t.id!==void 0?await te.patch(`/update/run/step/parameter/value/${t.id}`,u):(u.parameter=e.id,await te.post("/create/run/step/parameter/value",u))}catch(d){console.error("Failed to update parameter value with error: ",d)}n(),i(!1)};return s.jsxs(s.Fragment,{children:[s.jsx("span",{style:{cursor:"pointer",borderBottom:"1px dashed #999",display:r?"none":""},className:t.value==""||t.value==null?"text-muted":"",onClick:()=>{i(!r)},children:t.value!==""&&t.value!==null?t.value:"edit"}),s.jsxs("div",{style:{display:r?"":"none"},className:"btn-group",children:[s.jsx("input",{type:"text",value:a??"",className:"form-control",onChange:c=>o(c.target.value)}),s.jsx("button",{onClick:()=>{l(a)},className:"btn btn-success btn-sm",children:s.jsx("i",{className:"fa fa-check"})}),s.jsx("button",{onClick:()=>{i(!1)},className:"btn btn-danger btn-sm",children:s.jsx("i",{className:"fa fa-times"})})]})]})},ec=({runStep:e,showOnlyEmphasizedParameters:t,editableParameters:n=!0,refetchFn:r})=>{const{data:i,isLoading:a}=Ae.useQuery({queryKey:["runStepParameters",e.id],queryFn:()=>M1({runStep:e})}),o=Ae.useQueryClient(),l=()=>{o.refetchQueries({queryKey:["runStepParameters",e.id]}),r&&r()},c=i?.items??[],u=t?c.filter(d=>d.emphasize):c;return a?s.jsx("div",{children:"Loading..."}):c.length===0?s.jsx(St,{variant:"info",children:"No parameters found"}):s.jsxs(Ht,{children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Pos"}),s.jsx("th",{children:"Parameter"}),c[0].values.map((d,p)=>s.jsx("th",{children:"Value"},p)),s.jsx("th",{children:"Unit"})]})}),s.jsx("tbody",{children:u.length>0?u.map(d=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("small",{className:"text-muted",children:d.sequence})}),s.jsx("td",{children:d.parameter.name}),d.values.map((p,g)=>s.jsx("td",{children:n?s.jsx(QG,{parameter:d,refetchFn:l,value:p}):s.jsx("span",{children:p.value})},g)),s.jsx("td",{children:d.unit?.abbr??""})]},d.id)):s.jsx("tr",{children:s.jsx("td",{colSpan:3+c[0].values.length,children:"No emphasized parameters found."})})})]})},KG=e=>{if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB","TB"],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,r)).toFixed(2))} ${n[r]}`};function tc({runStep:e,refetchFn:t}){const[n,r]=x.useState([]),[i,a]=x.useState(""),{data:o,isLoading:l}=Ae.useQuery({queryKey:["files",e.id],queryFn:()=>D1({step:e})}),c=Ae.useQueryClient(),u=()=>{c.refetchQueries({queryKey:["files",e.id]}),t&&t()},d=o?.items??[],p=async S=>{if(confirm(`Are you sure you want to delete ${S.name}? You can not undo this action`))try{await te.delete(`delete/run/step/file/${S.id}`),u()}catch(j){console.error(j)}},g=S=>{r(j=>[...j,...S]),a(`${S.length} file(s) selected`)},{getRootProps:m,getInputProps:v,isDragActive:I,isDragAccept:C,isDragReject:b}=Ta({onDrop:g}),_=x.useMemo(()=>({...I?{borderColor:"#83afee"}:{},...C?{borderColor:"#00e676"}:{},...b?{borderColor:"#ff1744"}:{}}),[C,b,I]),y=()=>{n.forEach(S=>{const j=new FileReader;j.onload=async()=>{const N=j.result;try{await te.create().post("update/run/step/upload-file/"+e.id,{content:N,filename:S.name,type:S.type})}catch(k){a("Upload failed due to: "+k.response.data.detail)}try{u(),a("Files uploaded succesfully"),r([])}catch(k){a("Error refetching file data"),console.error(k)}},j.readAsDataURL(S)})};return l?s.jsx("div",{children:"Loading..."}):s.jsxs("div",{children:[d&&d.length>0&&s.jsxs(Ht,{hover:!0,striped:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"No"}),s.jsx("th",{children:"File"}),s.jsx("th",{children:"Size"}),s.jsx("th",{children:"Date"})]})}),s.jsx("tbody",{children:d.map((S,j)=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("small",{className:"text-muted",children:j+1})}),s.jsxs("td",{children:[s.jsx("a",{href:`${Y0()}${S.url}`,children:S.name}),S.has_run_step_loggings&&s.jsx(Ft,{className:"ms-1 bg-primary",children:"Logging"})]}),s.jsxs("td",{children:[s.jsx("i",{className:"fa fa-trash-o remove-file handle",style:{cursor:"pointer"},onClick:()=>p(S)})," ",KG(S.size)]}),s.jsx("td",{children:ln(S.date_created,"DD-MM-YY HH:mm")})]},j))})]}),s.jsxs("div",{...m({style:_,className:"dropzone bg-secondary-subtle border rounded dz-clickable"}),children:[s.jsx("input",{...v()}),I?s.jsx("p",{children:"Drop files here..."}):s.jsx("p",{children:"Drag and drop files here or click to select"})]}),n.length>0&&s.jsx(wn,{className:"mt-3",children:n.map((S,j)=>s.jsx(wn.Item,{children:S.name},j))}),s.jsxs("div",{className:"text-start",children:[s.jsx(ie,{className:"mt-3",onClick:y,disabled:n.length===0,children:"Upload Selected Files"}),s.jsx("p",{className:"mt-2 text-muted",children:i})]})]})}const gd=({runStepPart:e,setRunStepPart:t,editable:n=!0})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(e.comment),{register:l,handleSubmit:c,formState:u,resetField:d}=tn({defaultValues:{comment:a}}),{isSubmitting:p,errors:g}=u,m=async v=>{await te.create().patch("update/run/step/part/"+e.id,{comment:v.comment}).then(I=>{t({...e,comment:I.data.comment}),o(I.data.comment),i(!1)})};return n?r?s.jsxs(W,{onSubmit:c(m),children:[s.jsx(W.Group,{className:"mb-3",controlId:"formBasicEmail",children:s.jsx(W.Control,{as:"textarea",...l("comment")})}),s.jsx(ie,{size:"sm",type:"submit",disabled:p,children:"Save"}),s.jsx(ie,{variant:"warning",size:"sm",className:"ms-2",onClick:()=>i(!1),children:"Cancel"})]}):a===null?s.jsx(ie,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Add comment"}):s.jsxs("div",{className:"d-flex align-items-start gap-2",children:[s.jsx("div",{className:"text-break",children:a}),s.jsx(ie,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Edit"})]}):s.jsx("div",{children:a})},eB=(e,t,n)=>{let r={...e,latest_action:n??e.latest_action,actions:e.actions+1};return t===Ne.START_PROCESSING&&(r={...r,started:!0,processed:!1,failed:!1}),t===Ne.FINISH_PROCESSING&&(r={...r,started:!0,processed:!0,failed:!1}),t===Ne.FAILED_PROCESSING&&(r={...r,started:!0,processed:!1,failed:!0}),t===Ne.REWORK&&(r={...r,started:!1,processed:!1,failed:!1}),r},tB=(e,t)=>{const{runStepPart:n,action:r,latestAction:i}=t;return e.map(a=>{const o=r===Ne.FAILED_PROCESSING&&a.part.id===n.part.id,l=a.id===n.id;if(!o&&!l)return a;let c=a;return o&&(c={...c,part:{...c.part,part_processing_failed:!0}}),l&&(c=eB(c,r,i)),c})},Yg=(e,t)=>!e||!Array.isArray(e.items)?e:{...e,items:tB(e.items,t)},sp=(e,t)=>{e.setQueriesData({queryKey:["runStepParts"]},n=>Yg(n,t)),e.setQueriesData({queryKey:["stepParts"]},n=>Yg(n,t))},nB=({runStepPart:e,editable:t=!0,reloadFn:n,partIsSelected:r,setPartAsSelected:i})=>{const a=Ae.useQueryClient(),[o,l]=x.useState(e);x.useEffect(()=>{l(e)},[e]);const c=o.latest_action?.type.id===Ne.FINISH_PROCESSING,u=o.latest_action?.type.id===Ne.FAILED_PROCESSING,d=o.part_processing_failed_in_previous_step?"table-danger":c?"table-success":u?"table-danger":"",p=o.part.part_processing_failed?{label:"Blocked",variant:"danger",description:"Failed in an other step"}:o.part_processing_failed_in_previous_step?{label:"Blocked",variant:"danger",description:"Failed in previous step"}:o.actions===0?{label:"Not started",variant:"secondary",description:"No actions yet"}:o.latest_action?.type.id===Ne.START_PROCESSING?{label:"In progress",variant:"primary",description:"Processing started"}:o.latest_action?.type.id===Ne.FINISH_PROCESSING?{label:"Completed",variant:"success",description:"Processing finished"}:o.latest_action?.type.id===Ne.FAILED_PROCESSING?{label:"Failed",variant:"danger",description:"Processing failed"}:o.latest_action?.type.id===Ne.REWORK?{label:"Rework",variant:"warning",description:"Needs rework"}:{label:"Unknown",variant:"secondary",description:"No status available"},g=o.part.label??o.part.short_label,m=I=>{!i||I.target.closest("button, a, input, textarea, select, option, label")||i(o.part.id)},v=async({runStepPart:I,runStepPartAction:C})=>{const b=await Id(I,C);l(_=>({..._,latest_action:b,actions:_.actions+1})),sp(a,{runStepPart:o,action:C,latestAction:b}),n&&n()};return s.jsxs("tr",{onClick:m,style:t?{cursor:"pointer"}:void 0,children:[s.jsx("td",{className:d}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[g,i&&s.jsx("input",{type:"checkbox",id:`part-select-${o.id}`,name:"tomato",className:"form-check-input m-0",checked:r,onChange:()=>{i(o.part.id)}})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex justify-content-between gap-1",children:[s.jsxs("div",{children:[s.jsx(Ft,{bg:p.variant,children:p.label}),s.jsx("small",{className:"text-muted ms-2",children:p.description})]}),t&&s.jsxs("div",{className:"d-flex gap-1",children:[o.actions===0&&s.jsx(ie,{onClick:()=>v({runStepPart:o,runStepPartAction:Ne.START_PROCESSING}),className:"btn-success btn-sm",children:"Start"}),o.actions>0&&o.latest_action?.type.id!==Ne.FINISH_PROCESSING&&o.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>v({runStepPart:o,runStepPartAction:Ne.FINISH_PROCESSING}),className:"btn-primary btn-sm",children:"Finish"}),o.actions>0&&o.latest_action?.type.id!==Ne.FINISH_PROCESSING&&o.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>v({runStepPart:o,runStepPartAction:Ne.FAILED_PROCESSING}),className:"btn-danger btn-sm",children:"Failed"}),o.actions>0&&o.latest_action?.type.id!==Ne.FINISH_PROCESSING&&s.jsx(ie,{size:"sm",onClick:()=>v({runStepPart:o,runStepPartAction:Ne.REWORK}),children:"Rework"})]})]})}),s.jsx("td",{children:s.jsx(gd,{editable:t,runStepPart:o,setRunStepPart:I=>{l(I),n&&n()}})})]})};function ap({parts:e,getPartId:t,toggleRef:n}){const[r,i]=x.useState(new Map);x.useEffect(()=>{const u=new Map;for(const d of e){const p=t(d);u.set(p,r.get(p)??!1)}u.size!==r.size&&i(()=>u)},[e,t]);const a=x.useCallback(u=>{i(d=>{const p=new Map(d);return p.set(u,!(d.get(u)??!1)),p})},[]);x.useImperativeHandle(n,()=>e.length===0?null:{setPart(u){a(u)},setPartByLabel(u){const d=e.find(p=>p?.short_label===u)?.id;d!==void 0&&a(d)}},[e,a]);const o=x.useCallback(()=>{i(u=>new Map([...u.keys()].map(d=>[d,!0])))},[]),l=x.useCallback(()=>{i(u=>new Map([...u.keys()].map(d=>[d,!1])))},[]),c=Array.from(r.values()).some(u=>u);return{selectedParts:r,setPartAsSelected:a,selectAllParts:o,selectNoneParts:l,hasSelectedParts:c}}function $0({runStep:e,parts:t,selectedParts:n,getPartId:r,getRunStepPart:i,refetchFn:a}){const o=Ae.useQueryClient(),l=x.useCallback(u=>{const d=t.filter(g=>n.get(r(g)));if(d.length===0)return;const p=d.map(g=>i(g)).filter(g=>g!==void 0).filter(g=>Jp(g).some(m=>m===u)).map(g=>Id(g,u).then(m=>{sp(o,{runStepPart:g,action:u,latestAction:m})}));Promise.all(p).then(()=>{o.refetchQueries({queryKey:["stepParts",e.id]}),o.refetchQueries({queryKey:["runStepParts",e.id]}),a&&a()})},[t,n,r,i,o,e.id,a]),c=x.useCallback(()=>{const u=t.filter(p=>n.get(r(p)));if(u.length===0)return new Set;const d=new Set;return u.forEach(p=>{const g=i(p);g&&Jp(g).forEach(v=>d.add(v))}),d},[t,n,r,i]);return{performActionToSelectedParts:l,getAvailableActionsForSelection:c}}const X0=({availableActions:e,onActionSelected:t,showInitAction:n=!1,onInitSelected:r})=>e.size===0&&!n?null:s.jsxs(at,{align:"end",children:[s.jsx(at.Toggle,{size:"sm",variant:"secondary",children:"Actions"}),s.jsxs(at.Menu,{children:[n&&r&&s.jsx(at.Item,{onClick:r,children:"Init"}),e.has(Ne.START_PROCESSING)&&s.jsx(at.Item,{onClick:()=>t(Ne.START_PROCESSING),children:"Start"}),e.has(Ne.FINISH_PROCESSING)&&s.jsx(at.Item,{onClick:()=>t(Ne.FINISH_PROCESSING),children:"Finish"}),e.has(Ne.FAILED_PROCESSING)&&s.jsx(at.Item,{onClick:()=>t(Ne.FAILED_PROCESSING),children:"Failed"}),e.has(Ne.REWORK)&&s.jsx(at.Item,{onClick:()=>t(Ne.REWORK),children:"Rework"})]})]}),q0=({onSelectAll:e,onSelectNone:t,hasSelectedParts:n,actionsDropdown:r})=>s.jsxs("div",{className:"d-flex gap-3",children:[s.jsxs("div",{className:"btn-group btn-group-sm",role:"group",children:[s.jsx("button",{className:"part-check-all btn btn-outline-secondary",onClick:e,children:"All"}),s.jsx("button",{className:"part-check-none btn btn-outline-secondary",onClick:t,children:"None"})]}),n&&r]}),op=({run:e,runStep:t,runStepParts:n,editable:r=!0,refetchFn:i,toggleRunStepPartRef:a})=>{const[o,l]=x.useState(n||[]),c=i??(()=>{}),u=Ae.useQueryClient(),{isLoading:d,isError:p,error:g,data:m}=Ae.useQuery({queryKey:["stepParts",t.id],queryFn:()=>gs({step:t}),enabled:!n});x.useEffect(()=>{p&&console.error("RunPartsResearchRun query error",{error:g,runStep:t})},[p,g,t]),x.useEffect(()=>{!d&&m&&!n&&l(m.items)},[d,m,n]),x.useEffect(()=>{n&&(l(n),Js(t,n))},[o]);const{selectedParts:v,setPartAsSelected:I,selectAllParts:C,selectNoneParts:b,hasSelectedParts:_}=ap({parts:o,getPartId:N=>N.part.id,toggleRef:a});x.useEffect(()=>{const N=Array.from(v.entries()).filter(([,k])=>k).map(([k])=>k);u.setQueryData(["runPartSelection",t.id],N)},[u,t.id,v]);const{performActionToSelectedParts:y,getAvailableActionsForSelection:S}=$0({runStep:t,parts:o,selectedParts:v,getPartId:N=>N.part.id,getRunStepPart:N=>N,refetchFn:c}),j=x.useMemo(()=>S(),[S]);if(d)return s.jsx(zt,{message:"Loading run parts"});if(p)throw new Error("RunPartsResearchRun should not be loading");return o.length===0?null:s.jsx(x.Fragment,{children:o&&o.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{}),s.jsx("th",{children:"Part"}),s.jsx("th",{className:"text-center",children:"Status"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:o.map(N=>{const k=v.get(N.part.id)??!1;return s.jsx(nB,{editable:r,runStepPart:N,reloadFn:c,...r?{partIsSelected:k,setPartAsSelected:I}:{}},N.id)})})]}),r&&s.jsx(q0,{onSelectAll:C,onSelectNone:b,hasSelectedParts:_,actionsDropdown:s.jsx(X0,{availableActions:j,onActionSelected:y})})]})})},Z0=({runPart:e,runStepParts:t,runStep:n,refetchFn:r=()=>{},partIsSelected:i,setPartAsSelected:a,dropdown:o=!0,layout:l="default",onRunStepPartUpdated:c})=>{const[u,d]=x.useState(void 0),p=Ae.useQueryClient();x.useEffect(()=>{const y=t.find(S=>S.part.id===e.id&&S.step.id===n.id);if(!y){d(void 0);return}d(S=>!S||(y.actions??0)>=(S.actions??0)?y:S)},[t,e,n]);const g=()=>{te.post("/create/run/step/part",{run_part_id:e.id,run_step_id:n.id}).then(y=>{const S={...y.data};d(S),c&&c(S),r(),p.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},m=y=>{!a||y.target.closest("button, a, input, textarea, select, option, label")||a(e.id)},v=({runStepPart:y,runStepPartAction:S})=>{Id(y,S).then(j=>{const N=j;d(k=>{if(!k)return k;const A={...k,latest_action:N,actions:k.actions+1};return sp(p,{runStepPart:A,action:S,latestAction:N}),c&&c(A),A})}).then(()=>{r(),p.invalidateQueries({queryKey:["runSteps"]})})};if(!u)return l==="research"?s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,children:[s.jsx("td",{}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("div",{className:"fw-semibold",children:e.label||e.short_label}),a&&s.jsx("input",{type:"checkbox",id:`part-select-${e.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex justify-content-between gap-1",children:[s.jsxs("div",{className:"d-flex flex-column align-items-start gap-1",children:[s.jsx(Ft,{bg:"secondary",children:"Not initialized"}),s.jsx("small",{className:"text-muted",children:"No actions yet"})]}),s.jsx("div",{children:s.jsx(ie,{size:"sm",variant:"outline-info",onClick:()=>g(),children:"Init"})})]})}),s.jsx("td",{})]}):s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,children:[s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("div",{className:"fw-semibold",children:e.label||e.short_label}),a&&s.jsx("input",{type:"checkbox",id:`part-select-${e.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex flex-column align-items-start gap-1",children:[s.jsx(Ft,{bg:"secondary",children:"Not initialized"}),s.jsx("small",{className:"text-muted",children:"No actions yet"})]})}),s.jsx("td",{className:"text-muted",children:"-"}),s.jsx("td",{children:s.jsx(ie,{size:"sm",variant:"outline-info",onClick:()=>g(),children:"Init"})}),s.jsx("td",{})]});const I=u.latest_action?.type.id===Ne.FINISH_PROCESSING,C=u.latest_action?.type.id===Ne.FAILED_PROCESSING,b=u.part.part_processing_failed||u.part_processing_failed_in_previous_step?"table-danger":I?"table-success":C?"table-danger":"",_=u.part.part_processing_failed?{label:"Blocked",variant:"danger",description:"Failed in an other step"}:u.part_processing_failed_in_previous_step?{label:"Blocked",variant:"danger",description:"Failed in previous step"}:u.actions===0?{label:"Not started",variant:"secondary",description:"No actions yet"}:u.latest_action?.type.id===Ne.START_PROCESSING?{label:"In progress",variant:"primary",description:"Processing started"}:u.latest_action?.type.id===Ne.FINISH_PROCESSING?{label:"Completed",variant:"success",description:"Processing finished"}:u.latest_action?.type.id===Ne.FAILED_PROCESSING?{label:"Failed",variant:"danger",description:"Processing failed"}:u.latest_action?.type.id===Ne.REWORK?{label:"Rework",variant:"warning",description:"Needs rework"}:{label:"Unknown",variant:"secondary",description:"No status available"};return l==="research"?s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,children:[s.jsx("td",{className:b}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("div",{className:"fw-semibold",children:u.part.label||u.part.short_label}),a&&s.jsxs(s.Fragment,{children:[s.jsx("input",{type:"checkbox",id:`part-select-${u.part.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}}),s.jsx("label",{className:"visually-hidden",htmlFor:`part-select-${u.part.id}`,children:"Select part"})]})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex justify-content-between gap-1",children:[s.jsxs("div",{children:[s.jsx(Ft,{bg:_.variant,children:_.label}),s.jsx("small",{className:"text-muted ms-2",children:_.description})]}),s.jsx("div",{children:s.jsx(Wg,{runStepPart:u,setRunStepPartAction:v})})]})}),s.jsx("td",{children:s.jsx(gd,{runStepPart:u,setRunStepPart:y=>{d(y),c&&c(y)}})})]}):s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,className:b,children:[s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsxs("div",{className:"fw-semibold",children:["Part ",u.part.short_label,u.part.label&&u.part.label.trim().length>0?` (${u.part.label})`:""]}),a&&s.jsxs(s.Fragment,{children:[s.jsx("input",{type:"checkbox",id:`part-select-${u.part.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}}),s.jsx("label",{className:"visually-hidden",htmlFor:`part-select-${u.part.id}`,children:"Select part"})]})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex flex-column align-items-start gap-1",children:[s.jsx(Ft,{bg:_.variant,children:_.label}),s.jsx("small",{className:"text-muted",children:_.description})]})}),s.jsx("td",{children:s.jsx("span",{className:"text-muted",children:ln(u.latest_action?.date_created,"DD-MM-YY HH:mm")})}),s.jsx("td",{children:o?s.jsx(rB,{runStepPart:u,setRunStepPartAction:v}):s.jsx(Wg,{runStepPart:u,setRunStepPartAction:v})}),s.jsx("td",{children:s.jsx(gd,{runStepPart:u,setRunStepPart:y=>{d(y),c&&c(y)}})})]})},Wg=({runStepPart:e,setRunStepPartAction:t})=>s.jsx("div",{className:"d-flex justify-content-between gap-1",children:s.jsxs("div",{className:"d-flex gap-2",children:[e.actions===0&&s.jsx(ie,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.START_PROCESSING}),className:"btn-success btn-sm",children:"Start"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FINISH_PROCESSING}),className:"btn-primary btn-sm",children:"Finish"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FAILED_PROCESSING}),className:"btn-danger btn-sm",children:"Failed"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&s.jsx(ie,{size:"sm",onClick:()=>t({runStepPart:e,runStepPartAction:Ne.REWORK}),children:"Rework"})]})}),rB=({runStepPart:e,setRunStepPartAction:t})=>s.jsxs(at,{align:"end",children:[s.jsx(at.Toggle,{size:"sm",variant:"outline-secondary",children:"Actions"}),s.jsxs(at.Menu,{children:[e.actions===0&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.START_PROCESSING}),children:"Start"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FINISH_PROCESSING}),children:"Finish"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FAILED_PROCESSING}),children:"Failed"}),e.actions>0&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.REWORK}),children:"Rework"})]})]}),J0=({run:e,runStep:t,runStepParts:n,runParts:r,refetchFn:i=()=>{},toggleRunPartRef:a})=>{const o=Ae.useQueryClient(),[l,c]=x.useState(n||[]),[u,d]=x.useState(r||[]),p=Ae.useQueries({queries:[{queryKey:["runParts",e],queryFn:()=>ba({run:e}),enabled:!r},{queryKey:["runStepParts",t.id],queryFn:()=>gs({step:t}),enabled:!n}]}),[g,m]=p,v=p.some(T=>T.isLoading),I=p.some(T=>T.isError),C=x.useMemo(()=>r??g.data?.items??[],[r,g.data]),b=x.useMemo(()=>n??m.data?.items??[],[n,m.data]);x.useEffect(()=>{const T=n??m.data?.items??[];Js(t,T)},[n,m.data]),x.useEffect(()=>{if(r){d(r);return}!v&&g.data&&d(C)},[r,g.data,C,v]),x.useEffect(()=>{if(n){c(n),Js(t,n);return}!v&&m.data&&(c(b),Js(t,b))},[n,m.data,t,b,v]);const _=x.useMemo(()=>u.filter(T=>T.part_level===t.part_level),[u,t.part_level]),{selectedParts:y,setPartAsSelected:S,selectAllParts:j,selectNoneParts:N,hasSelectedParts:k}=ap({parts:_,getPartId:T=>T.id,toggleRef:a});x.useEffect(()=>{const T=Array.from(y.entries()).filter(([,V])=>V).map(([V])=>V);o.setQueryData(["runPartSelection",t.id],T)},[o,t.id,y]);const{performActionToSelectedParts:A,getAvailableActionsForSelection:F}=$0({runStep:t,parts:_,selectedParts:y,getPartId:T=>T.id,getRunStepPart:T=>l.find(V=>V.part.id===T.id&&V.step.id===t.id),refetchFn:i}),L=x.useMemo(()=>F(),[F]),Y=x.useMemo(()=>_.filter(V=>y.get(V.id)).some(V=>!l.find(Z=>Z.part.id===V.id&&Z.step.id===t.id)),[_,y,l,t.id]),G=(T,V)=>T.findIndex(ne=>ne.id===V.id)===-1?[...T,V]:T.map(ne=>ne.id===V.id?V:ne),X=Ae.useMutation({mutationFn:async T=>T,onSuccess:T=>{c(V=>G(V,T)),o.setQueryData(["runStepParts",t.id],V=>V&&(Array.isArray(V)?G(V,T):Array.isArray(V.items)?{...V,items:G(V.items,T)}:V)),o.setQueryData(["stepParts",t.id],V=>V&&(Array.isArray(V)?G(V,T):Array.isArray(V.items)?{...V,items:G(V.items,T)}:V))}}),H=()=>{const V=_.filter(Z=>y.get(Z.id)).filter(Z=>!l.find(ne=>ne.part.id===Z.id&&ne.step.id===t.id));Promise.all(V.map(Z=>te.post("/create/run/step/part",{run_part_id:Z.id,run_step_id:t.id}))).then(()=>{o.refetchQueries({queryKey:["runStepParts",t.id]}),i&&i()})};if(v)return s.jsx(zt,{message:"Loading run parts"});if(I)throw new Error("RunPartsProductionRun should not be loading");return s.jsx(x.Fragment,{children:_.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{}),s.jsx("th",{children:"Part"}),s.jsx("th",{className:"text-center",children:"Status"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:_.map((T,V)=>s.jsx(Z0,{runStep:t,runPart:T,runStepParts:l,refetchFn:i,partIsSelected:y.get(T.id)??!1,setPartAsSelected:S,layout:"research",onRunStepPartUpdated:Z=>X.mutate(Z)},V))})]}),s.jsx(q0,{onSelectAll:j,onSelectNone:N,hasSelectedParts:k,actionsDropdown:s.jsx(X0,{availableActions:L,onActionSelected:A,showInitAction:Y,onInitSelected:H})})]})})};function Q0({run:e,step:t,stepParts:n,parts:r,refetchFn:i=()=>null}){const{run:a}=x.useContext(Ri),{showOnlyEmphasizedParameters:o}=x.useContext(Kl),l=e??a;return l?s.jsx(Ye,{className:"p-4 my-3",children:s.jsx(Ye.Body,{children:s.jsxs(Un,{children:[s.jsxs(Pt,{md:"6",children:[l.run_type===Wn.RESEARCH&&s.jsx(op,{run:l,runStep:t,runStepParts:n,refetchFn:()=>{i(["runStepParts"])}}),l.run_type===Wn.PRODUCTION&&s.jsx(J0,{run:l,runStep:t,runParts:r,refetchFn:()=>{i(["runStepParts"])}}),t.has_remark&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{children:"Remark"}),s.jsx("span",{dangerouslySetInnerHTML:{__html:t.remark}})]})]}),s.jsxs(Pt,{md:"6",children:[s.jsx("h4",{children:"Parameters"}),s.jsx(ec,{runStep:t,showOnlyEmphasizedParameters:o,refetchFn:()=>{i([JSON.stringify(t),"parameters"])}}),s.jsx("h4",{children:"Files"}),s.jsx(tc,{runStep:t,refetchFn:()=>{i(["runSteps"])}})]})]})})}):null}const wu=({runPart:e,statusClass:t,withTrayCell:n=!1,allowCreate:r=!1,hasStepPart:i=!1,isSelected:a=!1,runStep:o,reloadFn:l=()=>{}})=>{const c=Ae.useQueryClient(),u=()=>{!e||!o||te.post("/create/run/step/part",{run_part_id:e.id,run_step_id:o.id}).then(()=>{l(),c.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},d=(()=>{if(!i||!e)return null;if(r&&!i)return s.jsxs(ie,{size:"sm",variant:"outline-secondary",className:"tray-grid__badge tray-grid__badge--init",onClick:u,children:["Init ",e.label??e.short_label]});const p=`tray-grid__badge ${t??"step-part-inactive"}${a?" step-part-selected":""}`;return s.jsx("span",{className:p,children:e.label??e.short_label})})();return n?s.jsx("div",{className:`tray-grid__cell${e?"":" tray-grid__cell--empty"}`,children:d}):d},K0=({step:e,parts:t,stepParts:n,run:r,reloadFn:i})=>{const a=t.filter(m=>m.part_level===e.part_level).sort((m,v)=>m.root_id&&v.root_id&&m.root_id!==v.root_id?m.root_id-v.root_id:m.left-v.left),o=new Map(n.filter(m=>m.step.id===e.id).map(m=>[m.part.id,m])),l=[...r.run_trays??[]].sort((m,v)=>m.sequence-v.sequence),c=a.reduce((m,v)=>{if(!v.tray)return m;const I=m.get(v.tray.id)??[];return I.push(v),m.set(v.tray.id,I),m},new Map),u=r.run_type===Wn.PRODUCTION,{data:d=[]}=Ae.useQuery({queryKey:["runPartSelection",e.id],queryFn:async()=>[],initialData:[],enabled:!1}),p=m=>{const v=o.get(m.id);return v?v.part_processing_failed_in_previous_step||v.part.part_processing_failed?"step-part-failed-other":v.failed?"step-part-failed":v.processed?"step-part-processed":v.started?"step-part-started":"step-part-inactive":"step-part-inactive"};if(l.length===0){const v=Math.max(a.length,a.reduce((S,j)=>Math.max(S,j.left??0),0)),I=Math.max(1,Math.ceil(v/12)),C=12,b={"--tray-columns":C,"--tray-rows":I},_=Array.from({length:I*C},()=>null),y=[];return a.forEach(S=>{const j=S.left,N=j>=1&&j<=_.length?j-1:null;N!==null&&!_[N]?_[N]=S:y.push(S)}),y.forEach(S=>{const j=_.findIndex(N=>!N);j!==-1&&(_[j]=S)}),s.jsx("div",{className:"tray-grid","data-orientation":"ltr",style:b,children:_.map((S,j)=>s.jsx(wu,{runPart:S,statusClass:S?p(S):void 0,withTrayCell:!0,allowCreate:u,hasStepPart:S?o.has(S.id):!1,isSelected:S?d.includes(S.id):!1,runStep:e,reloadFn:i},`slot-no-tray-${j}`))})}const g=(m,v,I)=>!v||!I||v<1||I<1||v>m.rows||I>m.columns?null:m.orientation==="ttb"?(I-1)*m.rows+(v-1):(v-1)*m.columns+(I-1);return s.jsx("div",{className:"tray-grid-group",children:l.map(m=>{const v=m.tray_type;if(!v?.rows||!v?.columns){const S=c.get(m.id)??[];return s.jsxs("div",{className:"tray-grid-wrapper",children:[s.jsx("div",{className:"tray-grid__label",children:m.name??m.label}),s.jsx("div",{className:"d-flex flex-wrap gap-2",children:S.map(j=>s.jsx(wu,{runPart:j,statusClass:p(j),allowCreate:u,hasStepPart:o.has(j.id),isSelected:d.includes(j.id),runStep:e,reloadFn:i},j.id))})]},`tray-${m.id}`)}const I=v.rows*v.columns,C=v.orientation==="ttb"?"ttb":"ltr",b={"--tray-columns":v.columns,"--tray-rows":v.rows},_=Array.from({length:I},()=>null);return(c.get(m.id)??[]).forEach(S=>{const j=g(v,S.tray_row,S.tray_column);j===null||_[j]||(_[j]=S)}),s.jsxs("div",{className:"tray-grid-wrapper",children:[s.jsx("div",{className:"tray-grid__label",children:m.name??m.label}),s.jsx("div",{className:"tray-grid","data-orientation":C,style:b,children:_.map((S,j)=>{const N=S?p(S):void 0;return s.jsx(wu,{runPart:S,statusClass:N,withTrayCell:!0,allowCreate:u,hasStepPart:S?o.has(S.id):!1,isSelected:S?d.includes(S.id):!1,runStep:e,reloadFn:i},`slot-${m.id}-${j}`)})})]},`tray-${m.id}`)})})};function iB({run:e,step:t,parts:n,stepParts:r,monitoredBy:i,refetchFn:a}){const{environment:o}=Te.useParams(),[l,c]=x.useState(!1),u=()=>{c(!l)},[d,p]=x.useState(t.process_module.module);return x.useEffect(()=>{p(t.process_module.module)},[t.process_module.module]),s.jsxs(s.Fragment,{children:[s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("i",{className:"fa ms-2 "+(l?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:u})}),s.jsx("td",{className:d.latest_module_status&&d.latest_module_status.status.is_down_status?"table-danger":"",children:s.jsx(K0,{step:t,parts:n,stepParts:r,run:e,reloadFn:()=>{a(["runStepParts"])}})}),s.jsxs("td",{children:[i&&s.jsx(fs,{placement:"top",overlay:s.jsx(yi,{id:`tooltip-${i.id}`,children:`Monitored by step: ${i.step.number}`}),children:s.jsx("i",{className:"fa fa-search me-2"})}),t.amount_of_files>0&&s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&s.jsx("i",{className:"fa fa-comment-o text-warning me-3"}),t.is_finished&&s.jsx("i",{className:"fa fa-check text-success me-3"})]}),s.jsxs("td",{className:t.has_step_group?"ps-4":"",children:[t.number," - ",s.jsx(Te.Link,{to:`/${o}/operator/run/step/${t.id}`,children:s.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]}),s.jsxs("td",{children:[s.jsx(Te.Link,{to:`/${o}/operator/equipment/${d.equipment.id}`,className:"me-2",children:d.equipment.name}),s.jsx(Jr,{module:d,refetchFn:()=>{a(["runSteps"])}})]})]}),l&&s.jsx("tr",{children:s.jsx("td",{colSpan:n.length+6,children:s.jsx(Q0,{step:t,stepParts:r,parts:n,refetchFn:a})})})]})}const xd=({requirement:e,result:t,show:n,setShow:r,refetchFn:i,part:a,stepPart:o})=>{const[l,c]=x.useState({}),[u,d]=x.useState(!1),[p,g]=x.useState(null),[m,v]=x.useState(!1);x.useEffect(()=>{if(Object.keys(l).length>0)return;let y={};for(const S of e.targets){let j="";t!==void 0&&(j=t.values.find(N=>N.logging_parameter.id==S.logging_parameter.id)?.string_value??""),y[S.logging_parameter.id]=j}c(y)},[e]),x.useEffect(()=>{v(!1),g(null),d(!1)},[n]);const I=async()=>{try{g(null),v(!1),d(!0),await te.delete(`/delete/run/measurement/result/${t?.id??0}`),v(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(y){console.error(y),g("Update of results failed")}finally{d(!1)}},C=async()=>{try{g(null),v(!1),d(!0);const y=Object.entries(l).map(async([S,j])=>{const N=Number.parseInt(S),k={value:j},A=t?.values.find(F=>F.logging_parameter.id===N)?.id;await te.patch(`/update/run/measurement/result/value/${A??0}`,k)});await Promise.all(y),v(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(y){console.error(y),g("Update of results failed")}finally{d(!1)}},b=async()=>{const y={measurement:e.measurement.id,values:Object.entries(l).flatMap(S=>({logging_parameter:Number.parseInt(S[0]),value:S[1]}))};o&&(y.step_part=o?.id??0,y.part=a?.id??0,y.step=e.step.id??0);try{g(null),v(!1),d(!0),await te.post("/create/run/measurement/result",y),v(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(S){console.error(S),g("Update of results failed")}finally{d(!1)}},_=y=>{y.preventDefault(),t?C():b()};return s.jsxs(ve,{show:n,size:"lg",onHide:()=>r(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:t?s.jsx(s.Fragment,{children:"Update results"}):s.jsx(s.Fragment,{children:"Create result"})})}),s.jsxs(W,{onSubmit:_,children:[s.jsxs(ve.Body,{children:[p&&s.jsx(St,{variant:"danger",children:p}),m&&s.jsx(St,{variant:"success",children:"Results have been updated successfully"}),e.targets.map(y=>(t?.values.find(S=>S.logging_parameter.id===y.logging_parameter.id)?.string_value,s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:y.logging_parameter.name}),s.jsx(W.Control,{type:"number",step:"any",placeholder:"Thickness",value:l[y.logging_parameter.id]??"",onChange:S=>c(j=>({...j,[y.logging_parameter.id]:S.target.value}))})]},y.id)))]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{variant:"warning",onClick:()=>r(!1),children:"Close"}),u?s.jsxs(ie,{type:"submit",variant:"info",disabled:u,children:[s.jsx(Kd,{animation:"border",size:"sm",className:"me-2"})," Updating results..."]}):t?s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"danger",disabled:u,onClick:I,children:"Delete result"}),s.jsx(ie,{type:"submit",variant:"info",disabled:u,children:"Update result"})]}):s.jsx(ie,{type:"submit",variant:"info",disabled:u,children:"Create result"})]})]})]})},rn=x.createContext({runStep:{},setRunStep:e=>{},reloadRunStep:()=>{},run:{},modalProperties:{},setModalProperties:e=>{}});function lp({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:a,editOnly:o=!1}){const{run:l}=x.useContext(rn),[c,u]=x.useState(r??[]),[d,p]=x.useState(n??[]),[g,m]=x.useState(i??[]),v=Ae.useQueryClient(),I=Ae.useQueries({queries:[{queryKey:["runParts",`${l?.id??"unknown"}`],queryFn:async()=>await ba({run:l}),enabled:!r||r.length===0,retry:1},{queryKey:["runStepParts",`${t?.run_id??"unknown"}`,`${t?.id??"unknown"}`],queryFn:async()=>await gs({step:e.requirement_for_step??e.step}),enabled:!n||n.length===0,retry:1},{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await ml({measurement:e.measurement}),enabled:!i||i.length===0,retry:1}]}),C=()=>{v.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[b,_,y]=I;x.useEffect(()=>{r&&r.length>0?u(r):b?.data&&u(b.data.items)},[r,b?.data]),x.useEffect(()=>{n&&n.length>0?p(n):_?.data&&p(_.data.items)},[n,_?.data]),x.useEffect(()=>{i&&i.length>0?m(i):y?.data&&m(y.data.items)},[i,y?.data]);const[S,j]=x.useState(null),N=r&&r.length>0?r:c,A=((n&&n.length>0?n:d)??[]).filter(T=>(N??[]).find(V=>V.id===T.part.id&&V.part_level===t.part_level)!==void 0),F=!r||r.length===0,L=!n||n.length===0,Y=!i||i.length===0,G=F&&b?.isLoading||L&&_?.isLoading||Y&&y?.isLoading,X=F&&b?.isError||L&&_?.isError||Y&&y?.isError;if(G&&A.length===0)return s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(Kd,{animation:"border",size:"sm"})," ",s.jsx("span",{children:"Loading data…"})]});if(X&&A.length===0)return s.jsxs(St,{variant:"danger",className:"d-flex justify-content-between align-items-center",children:[s.jsx("div",{children:"Failed to load required data. Please try again."}),s.jsxs("div",{children:[F&&b?.isError&&s.jsx(ie,{size:"sm",variant:"outline-light",onClick:()=>b.refetch(),children:"Retry parts"})," ",L&&_?.isError&&s.jsx(ie,{size:"sm",variant:"outline-light",onClick:()=>_.refetch(),children:"Retry step parts"})," ",Y&&y?.isError&&s.jsx(ie,{size:"sm",variant:"outline-light",onClick:()=>y.refetch(),children:"Retry results"})]})]});const H=T=>{if(!(T&&!isNaN(parseFloat(T.string_value))))return"";const V=parseFloat(T.string_value),Z=e.targets.find(de=>de.logging_parameter.id===T.logging_parameter.id);return Z?(Z.inclusive?!(Z.min_value<=V&&Z.max_value>=V):!(Z.min_value<V&&Z.max_value>V))?"table-danger":"table-success":""};return s.jsx(s.Fragment,{children:A.length>0?s.jsxs(s.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"26%"},children:"Part"}),s.jsx("th",{children:"Parameter"}),s.jsx("th",{children:"Value"}),s.jsx("th",{children:"Unit"}),!o&&s.jsx("th",{style:{width:"1%"}})]})}),s.jsx("tbody",{children:A.map(T=>{const V=g.find(de=>de.values.some(R=>R.step_part_id===T.id)),Z=(V?.values??[]).filter(de=>de.step_part_id===T.id),ne=e.targets.length;return e.targets.map((de,R)=>{const ee=Z.find(O=>O.logging_parameter.id===de.logging_parameter.id)??null,se=ee?H(ee):"";return s.jsxs("tr",{className:se,children:[R===0&&s.jsxs("td",{rowSpan:ne,children:[T.part.short_label," ",s.jsxs("small",{className:"text-muted",children:["(",T.id,")"]})]}),s.jsx("td",{children:de.logging_parameter.name}),s.jsx("td",{children:ee?ee.string_value:s.jsx("span",{className:"text-muted",children:"not set"})}),s.jsx("td",{children:de.logging_parameter.unit?.abbr??""}),!o&&R===0&&s.jsx("td",{rowSpan:ne,className:"align-middle text-nowrap",children:s.jsxs(ie,{size:"sm",variant:V?"outline-primary":"outline-success",onClick:()=>j(String(T.id)),children:[s.jsx("i",{className:"fa fa-edit"})," ",V?"Edit values":"Add values"]})})]},`${T.id}:${de.logging_parameter.id}`)})})})]}),!o&&A.map(T=>{const V=g.find(Z=>Z.values.some(ne=>ne.step_part_id===T.id));return s.jsx(xd,{requirement:e,...V?{result:V}:{part:T.part,stepPart:T},show:S===String(T.id),setShow:Z=>{Z||j(null)},refetchFn:a??C},`modal:${T.id}`)})]}):s.jsx(St,{variant:"secondary",className:"mb-0",children:"No selected parts"})})}function ew({requirement:e,measurementResults:t,refetchFn:n,editOnly:r=!1}){const[i,a]=x.useState(t??[]),o=Ae.useQueryClient(),l=Ae.useQueries({queries:[{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await ml({measurement:e.measurement}),enabled:!t||t.length===0,retry:1}]}),c=()=>{o.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[u]=l;x.useEffect(()=>{t&&t.length>0?a(t.filter(b=>b.values.some(_=>!_.step_part_id))):u?.data&&a(u.data.items.filter(b=>b.values.some(_=>!_.step_part_id)))},[t,u?.data]);const[d,p]=x.useState(null),[g,m]=x.useState(!1),v=l.some(b=>b.isLoading);if(l.some(b=>b.isError))return l.filter(b=>b.isError).forEach((b,_)=>{console.error("StepDashboard query error",{index:_,error:b.error})}),s.jsx(s.Fragment,{children:"Error fetching data"});if(v)return s.jsx("div",{children:"Loading..."});const C=b=>{if(!(b&&!isNaN(parseFloat(b.string_value))))return"";const _=parseFloat(b.string_value),y=e.targets.find(j=>j.logging_parameter.id===b.logging_parameter.id);return y&&(y.inclusive?!(y.min_value<=_&&y.max_value>=_):!(y.min_value<_&&y.max_value>_))?"table-danger":""};return s.jsxs("div",{className:"d-flex flex-column gap-4",children:[i.map(b=>s.jsxs("div",{className:"border rounded p-3 shadow-sm",children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[s.jsxs("h6",{className:"mb-0",children:["Result ",s.jsxs("small",{className:"text-muted",children:["#",b.id]})]}),!r&&s.jsxs(ie,{size:"sm",variant:"outline-primary",onClick:()=>p(b.id),children:[s.jsx("i",{className:"fa fa-edit"})," Update value"]})]}),s.jsxs("table",{className:"table table-striped table-sm mb-0",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Parameter"}),s.jsx("th",{children:"Value"}),s.jsx("th",{children:"Unit"})]})}),s.jsx("tbody",{children:b.values.map(_=>s.jsxs("tr",{className:_?C(_):"",children:[s.jsx("td",{children:_.logging_parameter.name}),s.jsx("td",{children:_.string_value}),s.jsx("td",{children:_.logging_parameter.unit?.abbr??""})]},`value:${_.id}`))})]}),s.jsx(xd,{requirement:e,result:b,show:d===b.id,setShow:_=>{_||p(null)},refetchFn:n??c})]},b.id)),s.jsx("div",{className:"mt-3",children:s.jsxs(ie,{size:"sm",onClick:()=>m(!g),children:[s.jsx("i",{className:"fa fa-plus"})," Add results"]})}),s.jsx(xd,{requirement:e,show:g,setShow:b=>{b||m(!1)},refetchFn:n??c})]})}function sB({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:a}){const{environment:o}=Te.useParams();return s.jsx(Ye,{className:"p-4 my-3",children:s.jsx(Ye.Body,{children:s.jsxs(Un,{children:[s.jsxs(Pt,{md:"7",children:[s.jsx("h4",{children:"Measurements by part"}),s.jsx(lp,{requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:a}),s.jsx("h4",{children:"Measurements for whole step"}),s.jsx(ew,{requirement:e,measurementResults:i,refetchFn:a})]}),s.jsxs(Pt,{md:"5",children:[s.jsx("h4",{children:"Monitored Step"}),s.jsx(Te.Link,{to:`/${o}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),s.jsx("h4",{children:"Definition"}),s.jsx("span",{children:e.definition}),s.jsx("h4",{children:"Targets"}),s.jsxs(Ht,{size:"sm",striped:!1,bordered:!1,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"parameter"}),s.jsx("th",{children:"min value"}),s.jsx("th",{children:"max value"}),s.jsx("th",{children:"inclusive"})]})}),s.jsx("tbody",{children:e.targets.map(l=>s.jsxs("tr",{children:[s.jsx("td",{children:l.logging_parameter.name}),s.jsx("td",{children:l.min_value}),s.jsx("td",{children:l.max_value}),s.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]}),s.jsx("h4",{children:"Files"}),s.jsx(tc,{runStep:t,refetchFn:()=>{a(["requirements"])}})]})]})})})}const tw=({requirement:e,step:t,measurementResults:n,parts:r,stepParts:i})=>{const a=r.filter(u=>u.part_level===t.part_level).sort((u,d)=>u.root_id&&d.root_id&&u.root_id!==d.root_id?u.root_id-d.root_id:u.left-d.left),o=a.reduce((u,d)=>{const p=d.root_id??d.id;return u[p]||(u[p]=[]),u[p].push(d),u},{}),l=u=>{const d=i.find(g=>g.part.id===u.id);if(!d)return"badge-inactive";const p=n.find(g=>g.values.some(m=>m.step_part_id===d.id));if(!p)return"";for(const g of p.values){const m=parseFloat(g.string_value),v=e.targets.find(I=>I.logging_parameter.id==g.logging_parameter.id);if(v){if(v.inclusive){if(!(v.min_value<=m&&v.max_value>=m))return"badge-failed"}else if(!(v.min_value<m&&v.max_value>m))return"badge-failed"}}return"badge-processed"},c=u=>s.jsx(fs,{placement:"top",overlay:s.jsx(yi,{id:`tooltip-${u.id}`,children:`Level: ${u.part_level}${u.parent?`, Parent: ${u.parent.short_label}`:""}`}),children:s.jsx("span",{className:`badge badge-level-${u.part_level} ${l(u)} me-1`,children:u.short_label},u.id)},u.id);return s.jsxs("div",{children:[a[0].parent?Object.entries(o).map(([u,d])=>s.jsxs("div",{className:"mb-2",children:[s.jsxs("label",{className:"text-muted me-1",children:[d[0].parent?.short_label,":"]})," ",d.map(p=>c(p))]},u)):a.map(u=>c(u)),s.jsx("label",{children:"(measurements)"})]})};function aB({requirement:e,step:t,parts:n,stepParts:r,refetchFn:i}){const{environment:a}=Te.useParams(),[o,l]=x.useState(!1),[c,u]=x.useState(t.process_module.module);x.useEffect(()=>{u(t.process_module.module)},[t.process_module.module]);const d=()=>{l(!o)},p=Ae.useQueryClient(),g=Ae.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>ml({measurement:e.measurement})}]}),m=b=>{b[0]==="requirement"&&p.refetchQueries({queryKey:b}),i(b)},[v]=g,I=g.some(b=>b.isLoading),C=b=>{if(b.length==0)return I?"":"table-info";let _=!1;for(const y of b)if(y.values.some(j=>{if(!(j&&!isNaN(parseFloat(j.string_value))))return!1;const N=parseFloat(j.string_value),k=e.targets.find(A=>A.logging_parameter.id==j.logging_parameter.id);return k?k.inclusive?!(k.min_value<=N&&k.max_value>=N):!(k.min_value<N&&k.max_value>N):!1})){_=!0;break}return _?"table-danger":""};return s.jsxs(s.Fragment,{children:[s.jsxs("tr",{className:C(v.data?.items??[]),children:[s.jsx("td",{children:s.jsx("i",{className:"fa ms-2 "+(o?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:d})}),s.jsx("td",{children:s.jsx(tw,{requirement:e,step:t,measurementResults:v.data?.items??[],parts:n,stepParts:r})}),s.jsxs("td",{children:[s.jsx(Ft,{bg:"info",children:"requirement"}),t.amount_of_files>0&&s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&s.jsx("i",{className:"fa fa-comment-o text-warning"})]}),s.jsx("td",{className:t.has_step_group?"ps-4":"",children:s.jsxs("div",{children:["(",t.number,")"," ",s.jsx(Te.Link,{to:`/${a}/operator/run/step/${t.id}`,children:s.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]})}),s.jsxs("td",{children:[s.jsx(Te.Link,{to:`/${a}/operator/equipment/${c.equipment.id}`,className:"me-2",children:c.equipment.name}),s.jsx(Jr,{module:c,refetchFn:()=>{i(["runSteps"])}})]})]}),o&&s.jsx("tr",{children:s.jsx("td",{colSpan:n.length+5,children:I?"Loading...":s.jsx(sB,{requirement:e,step:t,stepParts:r,parts:n,measurementResults:v.data?.items??[],refetchFn:m})})})]})}function oB(){const{run:e}=x.useContext(Ri),{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n}=x.useContext(Kl),[r,i]=x.useState(1),[a]=x.useState(25),[o,l]=x.useState(new Map),c=Ae.useQueryClient(),u=Ae.useQueries({queries:[{queryKey:["runSteps",JSON.stringify(e),r],queryFn:()=>Sd({run:e,page:r,pageSize:a}),placeholderData:Ae.keepPreviousData},{queryKey:["runParts",JSON.stringify(e)],queryFn:()=>ba({run:e})},{queryKey:["runStepParts",JSON.stringify(e)],queryFn:()=>gs({run:e})},{queryKey:["requirements",JSON.stringify(e)],queryFn:()=>Cd({run:e})}]}),d=L=>{const Y=[...L,JSON.stringify(e)];L[0]==="runSteps"&&Y.push(r),c.refetchQueries({queryKey:Y})},[p,g,m,v]=u,I=u.some(L=>L.isLoading),C=u.some(L=>L.isError);C&&u.filter(L=>L.isError).forEach((L,Y)=>{console.error("RunStepsElement query error",{index:Y,error:L.error,run:e})});const b=x.useMemo(()=>p.data?.items??[],[p.data?.items]),_=x.useMemo(()=>g.data?.items??[],[g.data?.items]),y=x.useMemo(()=>m.data?.items??[],[m.data?.items]),S=x.useMemo(()=>v.data?.items??[],[v.data?.items]);if(x.useEffect(()=>{l(L=>{const Y=new Map(L);return b.forEach(G=>{const X=G.label?.id;X!==void 0&&!Y.has(X)&&Y.set(X,!0)}),Y})},[b]),I)return s.jsx("div",{children:"Loading..."});if(C)return s.jsx("div",{className:"text-danger",children:"Error loading run steps."});const j=new Set,N=b.filter(L=>!L.has_step_group||typeof L.step_group?.id!="number"||j.has(String(L.step_group.id))?!1:(j.add(String(L.step_group.id)),!0)),k={};for(const L of S)L.requirement_for_step!=null&&(k[String(L.requirement_for_step.id)]=L);const A=L=>s.jsx("tr",{style:{pointerEvents:"none"},children:s.jsx("td",{colSpan:5,style:{margin:0},className:"bg-info",children:s.jsx("span",{children:L.step_group?.label})})}),F=L=>{const Y=L.label,G=Y?.id;if(!L.is_own_label||!Y||G===void 0)return null;const X=H=>{l(T=>{const V=new Map(T);return V.set(H,!V.get(H)),V})};return s.jsx("tr",{style:{cursor:"pointer"},onClick:()=>X(G),children:s.jsx("td",{colSpan:5,style:{margin:0},className:"bg-secondary",children:s.jsxs("span",{className:"label-toggle",children:[s.jsx("i",{className:"fa "+(o.get(L.label?.id??-1)?"fa-caret-down":"fa-caret-right")})," ",Y.label]})})})};return s.jsxs("div",{children:[s.jsx("h2",{children:"Run steps"}),s.jsx("div",{className:"d-flex justify-content-between align-items-center",children:s.jsxs("div",{className:"form-check form-switch",children:[s.jsx("input",{type:"checkbox",checked:t,className:"form-check-input","data-toggle":"toggle",onChange:()=>n(!t)}),s.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]})}),s.jsxs(Ht,{borderless:!0,hover:!0,striped:!0,size:"sm",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{}),s.jsx("th",{children:"Parts"}),s.jsx("th",{}),s.jsx("th",{children:"Process"}),s.jsx("th",{children:"Equipment"})]})}),s.jsx("tbody",{children:b.map((L,Y)=>{const G=`step-${L.id}`;return s.jsxs(x.Fragment,{children:[L.has_label&&F(L),(!L.has_label||o.get(L.label?.id??-1))&&s.jsxs(s.Fragment,{children:[L.has_step_group&&N.includes(L)&&A(L),L.has_requirement?(()=>{const X=S.find(H=>H.step.id===L.id);return s.jsx(aB,{requirement:X,step:L,parts:_,stepParts:y.filter(H=>H.step.id===(X.requirement_for_step?.id??X.step.id)),refetchFn:d})})():s.jsx(iB,{run:e,step:L,parts:_,stepParts:y.filter(X=>X.step.id===L.id),monitoredBy:k[L.id],refetchFn:d})]})]},G)})})]}),s.jsx(za,{data:p.data,setPage:i,isPlaceholderData:p.isPlaceholderData})]})}function lB(){const{run:e}=x.useContext(Ri);return s.jsxs("div",{children:[s.jsx("h2",{children:"Run information"}),s.jsx("h3",{children:"Run name"}),s.jsx("p",{children:e.name}),s.jsx("h3",{children:"Project name"}),s.jsx("p",{children:e.project.name})]})}const cB=()=>{const[e,t]=x.useState(null),[n,r]=x.useState(null),{id:i}=Te.useParams();x.useEffect(()=>{(e===null||i!==e.id.toString())&&Zp({id:parseInt(i)}).then(o=>(Fo({id:o.run_id}).then(r),o)).then(t)},[i,e]);function a(){Zp({id:parseInt(i)}).then(o=>(Fo({id:o.run_id}).then(r),o)).then(t)}return{run:n,runStep:e,setRunStep:t,reloadRunStep:a}};function nw({children:e}){const{runStep:t,setRunStep:n,run:r,reloadRunStep:i}=cB(),[a,o]=x.useState({});if(t===null||r===null){let l="Loading run...";return t===null&&r===null?l="Loading run and run step...":r===null&&(l="Loading run step..."),s.jsx(jn,{children:s.jsx(zt,{message:l})})}return s.jsx(jn,{children:s.jsx(rn.Provider,{value:{runStep:t,setRunStep:n,reloadRunStep:i,run:r,modalProperties:a,setModalProperties:o},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function uB(){return s.jsx(nw,{children:s.jsx(Ii,{fluid:!0,children:s.jsx(Te.Outlet,{})})})}const dB=({label:e})=>s.jsx("div",{className:"p-2 h4 mb-1 bg-info text-white",children:e.label}),fB=({runStep:e})=>{const{environment:t}=Te.useParams();return s.jsxs("h2",{children:[" ",e.number," -",e.process_module.process.name," on"," ",s.jsxs(Te.Link,{to:`/${t}/operator/equipment/${e.process_module.module.equipment.id}`,children:[e.process_module.module.equipment.name," (",e.process_module.module.name,")"]})]})},pB=({checklistItem:e,show:t,setModalShow:n,mutation:r})=>{const i=()=>n(!1);return s.jsxs(ve,{show:t,size:"lg",onHide:i,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Checklist item"})}),s.jsxs(ve.Body,{children:[s.jsx("h2",{children:e.task}),s.jsx("span",{dangerouslySetInnerHTML:{__html:e.description}})]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",variant:"primary",onClick:()=>{r.mutate()},children:"Done"}),s.jsx(ie,{variant:"secondary",onClick:()=>n(!1),children:"Close"})]})]})};function mB({checklistItem:e,onOpenModal:t,onMarkDone:n}){return e.can_finish?e.description!==""?s.jsx(ie,{className:"float-end",variant:"primary",onClick:t,children:"Execute checklist step"}):s.jsx(ie,{className:"float-end",size:"sm",variant:"success",onClick:n,children:"Done checklist step"}):null}const rw=({checklistItem:e,refetch:t})=>{const[n,r]=x.useState(!1),i=async()=>(await te.create().patch("update/run/step/checklist/done/"+e.id,{})).data,a=Ae.useMutation({mutationFn:i,onSuccess:o=>{r(!1),t()}});return s.jsxs(wn.Item,{disabled:e.is_executed,className:"d-flex justify-content-between align-items-start",children:[s.jsxs("div",{className:"d-flex flex-column",children:[e.task,e.is_executed&&s.jsxs("small",{children:["Executed on ",s.jsx(wi,{format:"DD-MM-YYYY",children:e.date_executed})]})]}),s.jsx("div",{className:"flex-shrink-0",children:s.jsx(mB,{checklistItem:e,onOpenModal:()=>r(!0),onMarkDone:()=>a.mutate()})}),s.jsx(pB,{checklistItem:e,show:n,setModalShow:r,mutation:a})]})},Nn={movingOut:"Moving out...",skipping:"Skipping...",unskipping:"Unskipping...",operationFinished:"Operation finished",operationSkipped:"Operation skipped",operationUnskipped:"Operation unskipped"};function iw({run:e,runStep:t,reloadRunStep:n}){const r=Te.useNavigate(),{environment:i}=Te.useParams(),[a,o]=x.useState(null),[l,c]=x.useState(!1),{run:u,runStep:d,reloadRunStep:p}=x.useContext(rn);x.useEffect(()=>{if(a){const A=setTimeout(()=>{o(null)},3e3);return()=>clearTimeout(A)}},[a]);const g=e??u,m=t??d,v=n??p??(()=>null),{data:I,error:C,isLoading:b,refetch:_}=Ae.useQuery({queryKey:["checklist",m?.id],queryFn:()=>rx({runStep:m}),enabled:!!m}),y=x.useCallback(async A=>{o(Nn.movingOut),c(!0);try{const F=await jd(A);o(Nn.operationFinished),F.data.next_step_id!==null?r(`/${i}/operator/run/step/${F.data.next_step_id}`):v()}finally{c(!1)}},[i,r,v]),S=x.useCallback(async A=>{o(Nn.skipping),c(!0);try{await te.create().patch(`update/run/step/skip/${A.id}`,{}),o(Nn.operationSkipped),v()}finally{c(!1)}},[v]),j=x.useCallback(async A=>{o(Nn.unskipping),c(!0);try{await te.create().patch(`update/run/step/un-skip/${A.id}`,{}),o(Nn.operationUnskipped),v()}finally{c(!1)}},[v]),{checklistItems:N,canFinishOperation:k}=x.useMemo(()=>{const A=I?.items??[],F=A.findIndex(G=>!G.is_executed),L=A.map((G,X)=>({...G,can_finish:X===F})),Y=!!(m&&!m.is_finished&&F===-1);return{checklistItems:L,canFinishOperation:Y}},[I,m]);return!m||!g?s.jsx(s.Fragment,{children:"Please set RunStepContext in RunStepChecklist"}):b?s.jsx(zt,{message:"Loading..."}):C?s.jsx(St,{variant:"danger",children:"Failed to load checklist."}):s.jsxs(s.Fragment,{children:[N.length===0&&s.jsx(St,{variant:"info",children:"No checklist found"}),N.length>0&&s.jsx(wn,{children:N.map(A=>s.jsx(rw,{checklistItem:A,refetch:_},A.id))}),s.jsxs("div",{className:"d-flex justify-content-between mt-3",children:[s.jsxs("div",{className:"d-flex gap-2 align-items-center",children:[k&&s.jsx("div",{children:s.jsx(ie,{variant:"success",onClick:()=>y(m),disabled:l,children:a===Nn.operationFinished||a===Nn.movingOut?a:"Move out"})}),g.access.edit&&!m.is_skipped&&s.jsx("div",{children:s.jsx(ie,{variant:"primary",onClick:()=>S(m),disabled:l,children:a===Nn.operationSkipped||a===Nn.skipping?a:"Skip operation"})}),g.access.edit&&m.is_skipped&&s.jsx("div",{children:s.jsx(ie,{variant:"warning",onClick:()=>j(m),disabled:l,children:a===Nn.operationUnskipped||a===Nn.unskipping?a:"Unskip operation"})})]}),s.jsx("div",{className:"d-flex gap-2",children:m.next_step_id&&s.jsx("div",{children:s.jsx(Te.Link,{to:`/${i}/operator/run/step/${m.next_step_id}`,className:"btn btn-secondary",children:"Next step"})})})]})]})}const zg=()=>{};function sw({runStep:e,reloadRunStep:t,title:n="Remark",titleClassName:r="mb-2 text-start"}){const{runStep:i,setRunStep:a}=x.useContext(rn),o=e??i,l=t?()=>t():e?zg:a??zg,[c,u]=x.useState(!1),d=o?!o.is_finished:!1,p=!!o?.remark?.trim(),{register:g,handleSubmit:m,formState:v,reset:I}=tn({defaultValues:{remark:o?.remark_unparsed??""}}),{isSubmitting:C}=v;x.useEffect(()=>{I({remark:o?.remark_unparsed??""})},[I,o?.remark_unparsed]);const b=x.useCallback(async _=>{if(!o)return;await te.patch("update/run/step/"+o.id,{remark:_.remark});const y=await te.get("view/run/step/"+o.id);l({...o,remark:y.data.remark,remark_unparsed:y.data.remark_unparsed}),u(!1)},[o,l]);return o?!c||!d?s.jsxs("div",{children:[s.jsx("h3",{className:r,children:n}),!p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-muted",children:"No remark."}),d&&s.jsx(ie,{variant:"primary",className:"ms-auto",size:"sm",onClick:()=>u(!0),children:"Add remark"})]}),p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-success",dangerouslySetInnerHTML:{__html:o.remark}})," ",d&&s.jsx(ie,{variant:"primary",className:"mt-3",onClick:()=>u(!0),children:"Edit remark"})]})]}):s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:r,children:n}),s.jsxs(W,{onSubmit:m(b),children:[s.jsx(W.Control,{as:"textarea",rows:6,...g("remark")}),s.jsx("p",{children:s.jsx("small",{className:"text-muted",children:"If a non-conformity happens, note it here"})}),s.jsxs(ie,{variant:"primary",type:"submit",disabled:C,children:[C&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save remark"]}),s.jsx(ie,{variant:"secondary",className:"ms-2",onClick:()=>u(!1),children:"Cancel"})]})]}):s.jsx(s.Fragment,{children:"Please set RunStepContext for StepRemark"})}const hB=({run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})=>{const[a,o]=x.useState(!1),{register:l,control:c,setValue:u,handleSubmit:d,formState:p}=tn({defaultValues:{holdCode:r?{value:r.hold_code.id,label:r.hold_code.code}:{},description:r?r.description:""}}),{errors:g,isSubmitting:m}=p,v=async C=>{try{const b=await te.patch("update/run/hold-code/"+e.id,{holdcode:a?null:C.holdCode.value,description:C.description});b.data.hold_code?i(b.data):i(void 0),o(!1)}finally{n(!1)}},I=(C,b)=>{te.get("list/run/hold-code").then(_=>{const{data:y}=_;return y._embedded.items}).then(_=>{b(_.map(y=>({value:y.id,label:y.code})))})};return s.jsx(ve,{show:t,size:"lg",onHide:()=>n(!1),children:s.jsxs(W,{onSubmit:d(v),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:a?"Reset hold code":"Update hold code"})}),s.jsxs(ve.Body,{children:[!a&&s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Hold code"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(Fn,{name:"holdCode",control:c,rules:{validate:{required:C=>C.value!==void 0||a||"A hold code is required"}},render:({field:C})=>s.jsx(Fl,{isSearchable:!1,defaultOptions:!0,placeholder:"Select a hold code",loadOptions:I,value:C.value,onChange:b=>{C.onChange(b)}})}),g.holdCode&&s.jsx("span",{className:"text-danger",children:g.holdCode.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Message"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"textarea",rows:3,...l("description",{required:"A message is required"}),isInvalid:g.description!==void 0}),g.description&&s.jsx(W.Control.Feedback,{type:"invalid",children:g.description.message})]})]})]}),s.jsxs(ve.Footer,{children:[s.jsxs(ie,{type:"submit",variant:a?"success":"primary",disabled:m,children:[m&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),a?"Release lot":"Update Hold code"]}),r&&s.jsx(ie,{variant:"outline-danger",onClick:()=>{u("description",a?r.description:""),o(!a)},children:a?"Update hold Code":"Reset hold code"})]})]})})},gB=()=>{const{run:e}=x.useContext(rn),[t,n]=x.useState(!1),[r,i]=x.useState(e.hold_code),a=()=>{n(!0)};return s.jsxs(s.Fragment,{children:[r&&s.jsx("span",{className:"badge handle",style:{backgroundColor:r.hold_code.back_color,color:r.hold_code.front_color,fontSize:"1.5rem",cursor:"pointer"},onClick:()=>a(),children:r.hold_code.code}),!r&&s.jsx(Ft,{bg:"secondary",className:"handle",onClick:()=>a(),style:{fontSize:"1.5rem",cursor:"pointer"},children:"No hold code"}),s.jsx(hB,{run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})]})},xB=()=>{const{run:e}=x.useContext(rn),[t,n]=x.useState(e.priority);return s.jsxs(x.Fragment,{children:[t&&s.jsx("span",{className:"badge",style:{backgroundColor:t.priority.back_color,color:t.priority.front_color,fontSize:"1.5rem"},children:t.priority.code}),!t&&s.jsx("span",{className:"badge bg-info",style:{fontSize:"1.5rem"},children:"NORMAL"})]})},vB=({run:e,runStep:t,showOnlyEmphasizedParameters:n})=>s.jsx(s.Fragment,{children:s.jsx("div",{className:"border rounded px-3 py-3",children:s.jsxs("div",{className:"d-flex flex-wrap gap-3",children:[s.jsx("div",{style:{flexGrow:1,flex:"1 1 360px"},children:s.jsx(op,{run:e,editable:!1,runStep:t})}),s.jsxs("div",{style:{flexGrow:1,flex:"1 1 360px"},children:[n&&s.jsx("h4",{children:"Emphasized parameters"}),!n&&s.jsx("h4",{children:"Parameters"}),s.jsx(ec,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:n})]})]})})}),yB=({run:e,monitoredBy:t,runStep:n,runParts:r,runStepParts:i,hideLabel:a,firstInGroup:o})=>{const{environment:l}=Te.useParams(),[c,u]=x.useState(!1),{runStep:d}=x.useContext(rn);return s.jsxs(s.Fragment,{children:[!a&&n.has_label&&n.is_own_label&&s.jsx("div",{className:"bg-info text-white rounded px-3 py-1",children:n.label?.label}),n.step_group&&o&&s.jsx("div",{className:"bg-secondary text-white rounded px-3 py-1",children:n.step_group?.label}),s.jsxs("div",{className:`d-flex flex-wrap align-items-center gap-3 border rounded px-3 py-2 ${n.has_step_group?"ms-4":""}`,children:[s.jsxs("div",{className:"d-flex align-items-center gap-2 flex-shrink-0",children:[n.id!==d.id&&s.jsx("i",{className:"fa "+(c?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{u(!c)}}),n.id===d.id&&s.jsx("i",{className:"fa fa-chevron-right text-success",style:{cursor:"pointer"},title:"This step is currently running"})]}),s.jsxs("div",{className:"d-flex flex-wrap align-items-center gap-3 flex-grow-1 min-w-0",children:[s.jsx("div",{className:"flex-shrink-0",children:s.jsx(K0,{step:n,parts:r,stepParts:i,run:e})}),s.jsxs("div",{className:"flex-shrink-0 text-nowrap",children:[n.number," ",n.is_skipped&&s.jsx(Ft,{bg:"info",children:"Skipped"})]}),s.jsxs("div",{className:"flex-grow-1 min-w-0",children:[s.jsx(Te.Link,{to:`/${l}/operator/run/step/${n.id}`,dangerouslySetInnerHTML:{__html:n.name}})," ",t&&s.jsx(fs,{placement:"top",overlay:s.jsx(yi,{id:`tooltip-${t.id}`,children:`Monitored by step: ${t.step.number}`}),children:s.jsx("i",{className:"fa fa-search me-2"})})]})]}),s.jsxs("div",{className:"d-flex align-items-center gap-3 flex-shrink-0 ms-auto",children:[s.jsx("span",{className:"text-nowrap",children:n.finish_user?n.finish_user.initials:""}),s.jsx("span",{className:"text-nowrap",children:n.has_rework?s.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),s.jsx("span",{className:"text-nowrap",children:n.is_finished?s.jsx(wi,{format:"DD-MM-YYYY",children:n.finish_date}):""})]})]}),c&&s.jsx(vB,{run:e,runStep:n,showOnlyEmphasizedParameters:!1})]})};function bB({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i}){const a=n.filter(l=>l.step.id===(e.requirement_for_step?.id??e.step.id)),{environment:o}=Te.useParams();return s.jsx(s.Fragment,{children:s.jsx("div",{className:"border rounded px-3 py-3",children:s.jsxs("div",{className:"d-flex flex-wrap gap-3",children:[s.jsxs("div",{style:{flexGrow:1,flex:"1 1 360px"},children:[s.jsx("h4",{children:"Measurement results"}),s.jsx(lp,{requirement:e,step:t,stepParts:a,parts:r,measurementResults:i,editOnly:!0})]}),s.jsxs("div",{style:{flexGrow:1,flex:"1 1 360px"},children:[s.jsx("h4",{children:"Monitored Step"}),s.jsx(Te.Link,{to:`/${o}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),s.jsx("h4",{children:"Definition"}),s.jsx("span",{children:e.definition}),s.jsx("h4",{children:"Targets"}),s.jsxs(Ht,{size:"sm",striped:!1,bordered:!1,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"min value"}),s.jsx("th",{children:"max value"}),s.jsx("th",{children:"inclusive"})]})}),s.jsx("tbody",{children:e.targets.map(l=>s.jsxs("tr",{children:[s.jsx("td",{children:l.min_value}),s.jsx("td",{children:l.max_value}),s.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]})]})]})})})}function wB({requirement:e,runParts:t,runStepParts:n,hideLabel:r,firstInGroup:i}){const a=e.step,{environment:o}=Te.useParams(),{runStep:l}=x.useContext(rn),[c,u]=x.useState(!1),d=Ae.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>ml({measurement:e.measurement})}]}),[p]=d,g=()=>{if(!p.data)return"";let m=!1;for(const v of n){const I=p.data?.items.find(_=>_.values.some(y=>y.step_part_id===v.id))?.values.find(_=>_.step_part_id===v.id);if(!(I&&!isNaN(parseFloat(I.string_value))))return a.id===l.id?"bg-success-subtle":"";const C=parseFloat(I.string_value);if(e.targets.some(_=>_.inclusive?!(_.min_value<=C&&_.max_value>=C):!(_.min_value<C&&_.max_value>C))){m=!0;break}}return m?"bg-danger-subtle":a.id===l.id?"bg-success-subtle":""};return s.jsxs(s.Fragment,{children:[!r&&a.has_label&&a.is_own_label&&s.jsx("div",{className:"bg-info text-white rounded px-3 py-1",children:a.label?.label}),a.step_group&&i&&s.jsx("div",{className:"bg-secondary text-white rounded px-3 py-1",children:a.step_group?.label}),s.jsxs("div",{className:`d-flex flex-wrap align-items-center gap-3 border rounded px-3 py-2 ${g()} ${a.has_step_group?"ms-4":""}`,children:[s.jsx("div",{className:"d-flex align-items-center gap-2 flex-shrink-0",children:a.id!==l.id&&s.jsx("i",{className:"fa "+(c?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{u(!c)}})}),s.jsxs("div",{className:"d-flex flex-wrap align-items-center gap-3 flex-grow-1 min-w-0",children:[s.jsx("div",{className:"flex-shrink-0",children:s.jsx(tw,{requirement:e,step:a,parts:t,stepParts:n,measurementResults:p.data?.items??[]})}),s.jsxs("div",{className:"flex-shrink-0 text-nowrap",children:[a.number," ",a.is_skipped&&s.jsx(Ft,{bg:"info",children:"Skipped"})]}),s.jsxs("div",{className:"flex-grow-1 min-w-0",children:[s.jsx(Ft,{bg:"info",children:"requirement"})," ",s.jsx(Te.Link,{to:`/${o}/operator/run/step/${a.id}`,dangerouslySetInnerHTML:{__html:a.name}})," "]})]}),s.jsxs("div",{className:"d-flex align-items-center gap-3 flex-shrink-0 ms-auto",children:[s.jsx("span",{className:"text-nowrap",children:a.finish_user?a.finish_user.initials:""}),s.jsx("span",{className:"text-nowrap",children:a.has_rework?s.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),s.jsx("span",{className:"text-nowrap",children:a.is_finished?s.jsx(wi,{format:"DD-MM-YYYY",children:a.finish_date}):""})]})]}),c&&s.jsx(bB,{requirement:e,step:a,stepParts:n,parts:t,measurementResults:p.data?.items??[]})]})}const aw=({pageSize:e=25,hideLabel:t=!1})=>{const{runStep:n,run:r}=x.useContext(rn),[i,a]=x.useState(1);x.useEffect(()=>{n?.sequence&&a(Math.max(1,Math.ceil(n.sequence/e)))},[n?.sequence,e]);const o=r?.id??null,l=Ae.useQuery({queryKey:["runParts",`${o}`],queryFn:()=>ba({run:r}),enabled:!!o}),c=Ae.useQuery({queryKey:["runStepParts",`${o}`],queryFn:()=>gs({run:r}),enabled:!!o}),u=Ae.useQuery({queryKey:["runSteps",o,i,e],queryFn:()=>Sd({run:r,page:i,pageSize:e}),enabled:!!o,placeholderData:Ae.keepPreviousData}),d=Ae.useQuery({queryKey:["requirements",o],queryFn:()=>Cd({run:r}),enabled:!!o,placeholderData:Ae.keepPreviousData}),p=l.isLoading||c.isLoading||u.isLoading||d.isLoading,g=l.isError||c.isError||u.isError||d.isError,m=l.error||c.error||u.error||d.error,v=l.data?.items??[],I=c.data?.items??[],C=u.data?.items??[],b=d.data?.items??[],_=new Set,y=C.filter(j=>!j.has_step_group||typeof j.step_group?.id!="number"||_.has(String(j.step_group.id))?!1:(_.add(String(j.step_group.id)),!0)),S={};for(const j of b)j.requirement_for_step!=null&&(S[String(j.requirement_for_step.id)]=j);return x.useEffect(()=>{g&&console.error("RunStepSimpleList query error",{runId:o,errors:[l.error,c.error,u.error,d.error]})},[g,o,l.error,c.error,u.error,d.error]),s.jsxs("div",{children:[p?s.jsx("div",{children:"Loading..."}):g?s.jsxs("div",{children:["Error: ",String(m?.message??m)]}):s.jsx("div",{className:"d-flex flex-column gap-2",children:C.map((j,N)=>s.jsx(x.Fragment,{children:j.has_requirement?(()=>{const k=b.find(A=>A.step.id===j.id);return s.jsx(wB,{requirement:k,runParts:v,runStepParts:I,firstInGroup:y.includes(j)},j.id??j.sequence??N)})():s.jsx(yB,{run:r,monitoredBy:S[j.id],runParts:v,runStepParts:I,hideLabel:t,firstInGroup:y.includes(j),runStep:j},j.id??j.sequence??N)},N))}),s.jsx(za,{data:u.data,setPage:a,isPlaceholderData:u.isPlaceholderData}),u.isFetching?s.jsx("span",{children:" Loading..."}):null]})},CB=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(rn),[r,i]=x.useState(1),{isPending:a,isLoading:o,isError:l,error:c,data:u,isFetching:d,isPlaceholderData:p}=Ae.useQuery({queryKey:["run_changelog",n,r],queryFn:()=>A1({run:n,page:r}),placeholderData:Ae.keepPreviousData});return s.jsxs(ve,{show:e,size:"lg",onHide:()=>t(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsxs(ve.Title,{children:["History of Run ",n.label]})}),s.jsx(ve.Body,{children:s.jsxs("div",{children:[a?s.jsx("div",{children:"Loading..."}):l?s.jsxs("div",{children:["Error: ",c.message]}):s.jsx(Ht,{size:"sm",striped:!0,bordered:!0,hover:!0,children:s.jsx("tbody",{children:u.items.map((g,m)=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(wi,{format:"DD-MM-YYYY",children:g.date_created})}),s.jsx("td",{children:s.jsx("span",{dangerouslySetInnerHTML:{__html:g.message}})}),s.jsxs("td",{children:[g.user.first_name," ",g.user.last_name]})]},m))})}),s.jsx(za,{data:u,setPage:i,isPlaceholderData:p}),d?s.jsx("span",{children:" Loading..."}):null]})}),s.jsx(ve.Footer,{children:s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},SB=({size:e})=>{const[t,n]=x.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(ie,{size:e,variant:"primary",onClick:()=>n(!t),children:"Run history"}),t&&s.jsx(CB,{show:t,setModalShow:n})]})},jB=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(rn);return s.jsxs(ve,{show:e,size:"xl",onHide:()=>t(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsxs(ve.Title,{children:["All steps of run ",n.label]})}),s.jsx(ve.Body,{children:s.jsx(aw,{hideLabel:!1})}),s.jsx(ve.Footer,{children:s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},IB=({size:e})=>{const[t,n]=x.useState(!1);return s.jsxs(x.Fragment,{children:[s.jsx(ie,{size:e,variant:"primary",onClick:()=>n(!0),children:"All run steps"}),t&&s.jsx(jB,{show:t,setModalShow:n})]})},_B=()=>{const{runStep:e,run:t}=x.useContext(rn),[n,r]=x.useState(!1),[i,a]=x.useState({}),[o,l]=x.useState(null),[c,u]=x.useState([]),[d,p]=x.useState([]),[g,m]=x.useState([]),[v,I]=x.useState(""),[C,b]=x.useState(!1);if(!e.has_recipe)return"Reworks are only possible for steps with a recipe";const[_,y,S]=Ae.useQueries({queries:[{queryKey:["templates",g],queryFn:()=>V1({reworkRecipes:g}),enabled:n&&g.length>0},{queryKey:["run_steps",e.id],queryFn:()=>Sd({run:t,page:1,pageSize:1e3}),enabled:n},{queryKey:["template_steps","rework",o,e.id],queryFn:()=>L1({template:o,pageSize:1e3}),enabled:o!==null}]});x.useEffect(()=>{if(y.isSuccess&&c.length>0){let k=y.data.items.filter(A=>c.includes(A.id)).map(A=>A.recipe_version.recipe);m([...k])}},[y.isSuccess,c]);function j(k){let A=_.data.templates.find(F=>F.id===k);A!==void 0&&l(A)}function N(){let k={};a({}),c.length===0&&(k.runStep="Please select at least one step"),a(A=>({...A,...k})),Object.keys(k).length===0&&(b(!0),te.create().patch("/update/run/step/rework/"+e.id,{reworked_run_steps:c,template_steps:d,comment:v}).then(()=>{b(!1),window.location.reload()}))}return s.jsxs(s.Fragment,{children:[n&&s.jsxs(W,{method:"post",onSubmit:()=>N(),children:[s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Template"}),s.jsxs("div",{className:"col-sm-9",children:[g.length===0&&s.jsx(St,{variant:"info",children:"Please select a rework step"}),g.length>0&&s.jsxs(W.Control,{as:"select",name:"template",onChange:k=>j(parseInt(k.target.value)),isInvalid:!!i.template,children:[s.jsx("option",{value:"",children:"— Select a template"}),_.data!==void 0&&_.data.templates.map((k,A)=>s.jsxs("option",{value:k.id,children:[k.label,": ",k.name]},A))]}),i.template&&s.jsx("span",{className:"text-danger",children:i.template})]})]}),o!==null&&s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Include template steps"}),s.jsx("div",{className:"col-sm-9",children:s.jsx("ul",{className:"list-group",children:!S.isLoading&&S.data!==void 0&&S.data.steps.map((k,A)=>s.jsx("li",{className:"list-group-item ",children:s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"checkbox",className:"form-check-input",id:"templateStep"+k.id,name:"templateStep",onChange:F=>{F.target.checked?p([...d,k.id]):p(d.filter(L=>L!==k.id))},value:k.id}),s.jsxs("label",{htmlFor:"templateStep"+k.id,className:"from-check-label",children:[s.jsxs("small",{className:"text-muted pe-2",children:[k.number,":"]}),k.process_module.process.name]})]})},A))})})]}),s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Repeat steps"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsxs("ul",{className:"list-group",children:[y.isLoading&&s.jsx("option",{children:"Loading run steps..."}),!y.isLoading&&y.data.items.map((k,A)=>{if(e.sequence>=k.sequence)return s.jsxs("li",{className:"list-group-item d-flex justify-content-between"+(e.id===k.id?" bg-success-subtle":""),children:[s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"checkbox",className:"form-check-input",id:"runStep"+k.id,name:"runStep",onChange:F=>{F.target.checked?u([...c,k.id]):u(c.filter(L=>L!==k.id))},value:k.id}),s.jsxs("label",{htmlFor:"runStep"+k.id,className:"from-check-label",children:[s.jsxs("small",{className:"text-muted pe-2",children:[k.number,":"]}),k.process_module.process.name]})]}),k.is_finished&&s.jsx("div",{children:s.jsx("span",{className:"badge bg-success",children:"Finished"})})]},A)})]}),i.runStep&&s.jsx("span",{className:"text-danger",children:i.runStep})]})]}),s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Comment"}),s.jsx("div",{className:"col-sm-9",children:s.jsxs(W.Group,{controlId:"runStep.remark",children:[s.jsx(W.Control,{as:"textarea",rows:6,onChange:k=>I(k.target.value),value:v,isInvalid:!!i.comment}),s.jsx("small",{className:"text-muted",children:"Optional comment for the rework"})]})})]}),s.jsx("div",{className:"row mb-3",children:s.jsxs("div",{className:"col-sm-9 offset-sm-3",children:[s.jsxs(ie,{variant:"primary",onClick:()=>N(),disabled:C,children:[C&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create rework"]})," ",s.jsx(ie,{variant:"warning",onClick:()=>r(!1),children:"Cancel"})]})})]}),!n&&s.jsx(ie,{variant:"primary",className:"mt-3",onClick:()=>r(!0),children:"Set Rework"})]})},EB=()=>{const{environment:e}=Te.useParams(),{runStep:t,run:n}=x.useContext(rn),r=Ae.useQueries({queries:[{queryKey:["monitors",t.process_module.module.equipment],queryFn:()=>tx({equipment:t.process_module.module.equipment})},{queryKey:["ecn",t.process_module.module],queryFn:()=>wd({module:t.process_module.module})},{queryKey:["equipmentModule",t.process_module.module],queryFn:()=>b1({id:t.process_module.module.id})},{queryKey:["requirement",t.id],queryFn:()=>Cd({run:n,step:t})}]}),[i,a,o,l]=r,[c,u]=x.useState(!0),d=r.some(m=>m.isLoading);if(r.some(m=>m.isError))return r.filter(m=>m.isError).forEach((m,v)=>{console.error("StepDashboard query error",{index:v,error:m.error,runStep:t,run:n})}),s.jsx(s.Fragment,{children:"Error fetching data"});if(d)return s.jsx("div",{children:"Loading..."});const g=o.data;return s.jsx(Ii,{fluid:!0,children:s.jsxs(Un,{children:[s.jsxs(Pt,{className:"col-9",children:[n.run_type===Wn.RESEARCH&&s.jsx("small",{children:"Research run"}),n.run_type===Wn.PRODUCTION&&s.jsx("small",{children:"Production run"}),s.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[s.jsxs("h1",{className:"display-4",children:[n.name," (",n.project.name,")"]}),s.jsxs("div",{className:"d-flex flex-column flex-lg-row gap-2 flex-wrap justify-content-end",children:[t.has_rework&&s.jsx("span",{style:{fontSize:"1.5rem"},className:"mx-1 badge bg-primary",children:"Rework"}),s.jsx(xB,{}),s.jsx(gB,{}),t.is_skipped&&s.jsx("span",{style:{fontSize:"1.5rem"},className:"badge bg-info",children:"SKIPPED"})]})]}),s.jsx(ip,{run:n}),t.label&&s.jsx(dB,{label:t.label}),s.jsx(fB,{runStep:t}),t.is_finished&&s.jsxs(St,{variant:"success",children:["This step has been finished by ",t.finish_user?.first_name," ",t.finish_user?.last_name]}),t.has_recipe&&s.jsx(Ye,{className:"rounded my-4",children:s.jsxs(Ye.Body,{children:[s.jsx(Ye.Title,{className:"text-muted",children:"Recipe"}),s.jsxs(Ye.Text,{className:"display-5",children:[t.recipe_version.recipe.name," (Version ",t.recipe_version.version,")"]})]})}),l.data?.items.length==1&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{children:"Measurements by part"}),s.jsx(lp,{requirement:l.data.items[0],step:t,editOnly:!1}),s.jsx("h4",{children:"Measurements for whole step"}),s.jsx(ew,{requirement:l.data.items[0],editOnly:!1})]}),l.data?.items.length!=1&&n.run_type===Wn.RESEARCH&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Available parts"}),s.jsx(op,{run:n,runStep:t})]}),l.data?.items.length!=1&&n.run_type===Wn.PRODUCTION&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Available parts"}),s.jsx(J0,{run:n,runStep:t})]}),s.jsxs(Un,{className:"py-4",children:[s.jsxs(Pt,{children:[s.jsx("h3",{children:"Checklist"}),s.jsx(iw,{}),s.jsx("h2",{className:"mt-2",children:"Step files"}),s.jsx(tc,{runStep:t})]}),s.jsxs(Pt,{children:[s.jsx("h2",{children:"Parameters"}),s.jsxs("div",{className:"form-check form-switch",children:[s.jsx("input",{type:"checkbox",checked:c,className:"form-check-input","data-toggle":"toggle",onChange:()=>u(!c)}),s.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]}),s.jsx(ec,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:c}),t.has_instructions&&t.instructions&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Instructions"}),s.jsx("span",{dangerouslySetInnerHTML:{__html:t.instructions}})]}),s.jsx(sw,{}),s.jsx("h3",{className:"pt-3",children:"Rework"}),s.jsx(_B,{})]})]}),s.jsxs("div",{className:"d-flex justify-content-between mb-3",children:[s.jsx("h2",{children:"Run steps"}),s.jsxs("div",{className:"d-flex gap-2 flex-wrap justify-content-end",children:[s.jsx("div",{children:s.jsx(IB,{size:void 0})}),s.jsx("div",{children:s.jsx(SB,{size:void 0})}),s.jsx("div",{children:s.jsx(G0,{size:void 0,moduleId:t.process_module.module.id})})]})]}),s.jsx(aw,{pageSize:n.run_type===Wn.RESEARCH?5:1e3,hideLabel:!0})]}),s.jsx(Pt,{className:"col-3",children:s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx("h2",{children:s.jsxs(Te.Link,{to:`/${e}/operator/equipment/${t.process_module.module.equipment.id}`,children:[t.process_module.module.equipment.name," (",t.process_module.module.name,")"]})}),g&&s.jsx("div",{children:s.jsx("h2",{children:s.jsx(Jr,{module:g})})}),i.data?.items&&i.data.items.map((m,v)=>s.jsx(rp,{monitor:m},v)),a.data?.items.map(function(m,v){return s.jsxs(Ye,{className:"my-2",children:[s.jsxs(Ye.Header,{children:["ECN: ",m.ecn]}),s.jsx(Ye.Body,{children:s.jsx(Ye.Text,{children:s.jsx(Ai,{children:m.description})})}),s.jsxs(Ye.Footer,{children:[m.date_created&&s.jsxs(s.Fragment,{children:["Created by ",ln(m.date_created,"DD-MM-YY H:m")," by ",m.owner.full_name]}),m.last_update&&s.jsxs(s.Fragment,{children:[" ","· Updated by ",ln(m.last_update,"DD-MM-YY H:m")," by ",m.owner.full_name]})]})]},v)})]})})]})})},ow=()=>{const[e,t]=x.useState(!1),{modalProperties:n}=x.useContext(rn),r=()=>{t(!1),n.show=!1};return x.useEffect(()=>{t(n.show)},[n]),s.jsxs(ve,{show:e,size:"xl",onHide:r,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:n.modalTitle})}),s.jsx(ve.Body,{children:n.modalContent}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{variant:"secondary",onClick:r,children:"Save"}),n.modalSaveButton]})]})};function kB(){return s.jsxs(s.Fragment,{children:[s.jsx(EB,{}),s.jsx(ow,{})]})}const Hg={movingOut:"Moving out...",movingIn:"Moving in..."};function NB({run:e,runStep:t,reloadRunStep:n}){const{run:r,runStep:i,reloadRunStep:a}=x.useContext(rn),[o,l]=x.useState(null),[c,u]=x.useState(!1),d=e??r,p=t??i,g=n??a??(()=>null);x.useEffect(()=>{if(o){const _=setTimeout(()=>{l(null)},3e3);return()=>clearTimeout(_)}},[o]);const{data:m,isLoading:v,refetch:I}=Ae.useQuery({queryKey:["checklist",p?.id],queryFn:()=>rx({runStep:p}),enabled:!!p});if(!p||!d)return s.jsx(s.Fragment,{children:"Please set RunStepContext in RunStepChecklist"});if(p.is_finished)return s.jsx("div",{children:"Step is finished"});if(v)return s.jsx(zt,{message:"Loading..."});function C(_){l(Hg.movingOut),u(!0),jd(_).then(()=>{u(!1),l(null),g()})}function b(_){l(Hg.movingIn),u(!0),ix(_).then(()=>{u(!1),l(null),g()})}return s.jsxs(s.Fragment,{children:[m.items.length===0&&s.jsx(St,{variant:"info",children:"No checklist found"}),m.items.length>0&&s.jsx(wn,{children:m.items.map(_=>s.jsx(rw,{checklistItem:_,refetch:I},_.id))}),s.jsx("div",{className:"d-flex justify-content-between mt-3",children:s.jsx("div",{className:"d-flex gap-2 align-items-center",children:p.is_started?s.jsx("div",{children:s.jsx(ie,{variant:"success",onClick:()=>C(p),disabled:c,children:o!==null?o:"Move out"})}):s.jsx("div",{children:s.jsx(ie,{variant:"success",onClick:()=>b(p),disabled:c,children:o!==null?o:"Start processing"})})})})]})}const AB=({run:e,runStep:t,runStepParts:n,runParts:r,refetchFn:i=()=>{},toggleRunPartRef:a})=>{const o=Ae.useQueryClient(),l=Ae.useQueries({queries:[{queryKey:["runParts",e.id,t.part_level],queryFn:()=>ba({run:e,level:t.part_level}),enabled:!r},{queryKey:["runStepParts",t.id],queryFn:()=>gs({step:t}),enabled:!n}]}),[c,u]=l,d=l.some(_=>_.isLoading),p=l.some(_=>_.isError),g=x.useMemo(()=>r??c.data?.items??[],[r,c.data]),m=x.useMemo(()=>n??u.data?.items??[],[n,u.data]);x.useEffect(()=>{const _=n??u.data?.items??[];Js(t,_)},[n,u.data]);const v=x.useMemo(()=>g.filter(_=>_.part_level===t.part_level),[g,t.part_level]),{selectedParts:I}=ap({parts:v,getPartId:_=>_.id,toggleRef:a}),C=x.useMemo(()=>v.filter(_=>I.get(_.id)&&!RB(m,_)),[I,m]),b=()=>{o.invalidateQueries({queryKey:["runParts",e.id,t.part_level]}),o.invalidateQueries({queryKey:["runStepParts",t.id]}),i()};return d?s.jsx("div",{children:"Loading..."}):p?s.jsx("div",{className:"text-danger",children:"Error loading run parts."}):s.jsxs(x.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Part"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Date"}),s.jsx("th",{children:"Actions"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:C.map((_,y)=>s.jsx(Z0,{runStep:t,runPart:_,runStepParts:m,refetchFn:b,partIsSelected:I.get(_.id)??!1,dropdown:!1},y))})]}),s.jsx(DB,{runStepParts:m,selectedPartsLength:C.length})]})},RB=(e,t)=>{const n=e.find(r=>r.part.id==t.id);return n==null?!1:n.latest_action?.type.id===Ne.FINISH_PROCESSING},DB=({runStepParts:e,selectedPartsLength:t})=>{const n=x.useMemo(()=>{let i=0;return e.forEach(a=>a.latest_action?.type.id===Ne.FINISH_PROCESSING?i++:null),i},[e]),r=x.useMemo(()=>e.length-t,[e,t]);return s.jsxs("div",{className:"d-flex flex-column flex-sm-row flex-wrap gap-2 mt-2",children:[s.jsxs("span",{className:"badge rounded-pill bg-warning-subtle text-warning-emphasis border border-warning-subtle px-3 py-2 fw-semibold",children:["This step has ",r," more parts"]}),s.jsxs("span",{className:"badge rounded-pill bg-info-subtle text-info-emphasis border border-info-subtle px-3 py-2 fw-semibold",children:["This step has ",t," scanned parts"]}),s.jsxs("span",{className:"badge rounded-pill bg-success-subtle text-success-emphasis border border-success-subtle px-3 py-2 fw-semibold",children:["This step has ",n," finished parts"]})]})};function MB({run:e,runStep:t,showOnlyEmphasizedParameters:n,reloadRunStepFn:r,toggleRunPartRef:i}){return s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("h3",{className:"mb-2 text-start",children:"Parts"}),s.jsx(AB,{run:e,runStep:t,toggleRunPartRef:i})]}),s.jsx("h3",{className:"mt-2",children:"Parameters"}),s.jsx(ec,{runStep:t,showOnlyEmphasizedParameters:n}),s.jsxs("div",{className:"row row-cols-2",children:[s.jsx("div",{className:"col",children:s.jsx(sw,{runStep:t,reloadRunStep:r})}),s.jsx("div",{className:"col",children:t.has_instructions&&t.instructions&&s.jsxs(x.Fragment,{children:[s.jsx("h3",{className:"mb-2 text-start",children:"Instructions"}),s.jsx("span",{dangerouslySetInnerHTML:{__html:t.instructions}})]})})]}),s.jsxs("div",{className:"row row-cols-2",children:[s.jsxs("div",{className:"col",children:[s.jsx("h3",{className:"mt-2",children:"Checklist"}),s.jsx(NB,{run:e,runStep:t,reloadRunStep:r})]}),s.jsxs("div",{className:"col",children:[s.jsx("h3",{className:"mt-2",children:"Step files"}),s.jsx(tc,{runStep:t})]})]})]})}function OB(e){return e==="Shift"}function TB(e){return/^[a-zA-Z0-9-]$/.test(e)}function FB(e){return e.length===1}function PB(e){return e==="Enter"}function LB(e,t,n,r){let i=0,a="";const o=()=>{i=0,a="",n&&n(a)};return l=>{const c=l.key;if(c==="Escape"){o();return}if(!OB(c)){if(PB(c)){t(a),o();return}switch(a+=c,e[i]){case"/":if(c!="/"){o();return}else i=(i+1)%e.length;break;case"*":if(!FB(c))return;break;default:if(!TB(e[i]))throw new Error("Invalid character expression in makeKeySequenceListener call");if(c!=e[i]){o();return}else i=(i+1)%e.length;break}n&&n(a)}}}function VB({notification:e,setNotification:t}){return s.jsx(bs,{position:"top-end",children:s.jsxs(on,{show:e.show,onClose:()=>t(n=>({...n,show:!1})),delay:3e3,autohide:!0,bg:e.variant,children:[s.jsx(on.Header,{children:s.jsx("span",{children:"Notification"})}),s.jsx(on.Body,{children:e.text})]})})}function lw({runsList:e,setRun:t,setRunPartLabel:n}){const[r,i]=x.useState(""),[a,o]=x.useState({text:"",show:!1,variant:"success"}),l=c=>{const u=c.replace(/_/g,"-").toUpperCase(),d=u.split("-");if(!(d.length==4||d.length==3)){o({text:"Part not found, found "+d.length+" splits in "+u,show:!0,variant:"danger"});return}const p=e.find(m=>m.label===`${d[0]}-${d[1]}`),g=u;if(!p){o({text:"Run not found",show:!0,variant:"danger"});return}if(!g){o({text:"Part label not found",show:!0,variant:"danger"});return}t!==void 0&&(o({text:`Found run ${p.label}`,show:!0,variant:"success"}),t(p)),n!==void 0&&n(g)};return x.useEffect(()=>{const c=LB("*",l,i);return document.addEventListener("keyup",c),()=>{document.removeEventListener("keyup",c)}},[]),s.jsxs("div",{className:"d-flex flex-row gap-3",children:[s.jsx("div",{className:"d-flex flex-column",children:s.jsxs("div",{className:"h3",children:["Reading: ",s.jsx("span",{className:"font-monospace",children:r})]})}),s.jsx(VB,{notification:a,setNotification:o})]})}function GB({children:e}){const[t,n]=x.useState(!1);return s.jsx(jn,{children:s.jsx(Kl.Provider,{value:{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function BB(){return s.jsx(Ii,{fluid:!0,children:s.jsx(Te.Outlet,{})})}function YB({control:e,name:t}){const{environment:n}=Te.useParams(),[r,i]=x.useState([]),[a,o]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const c=await I1({environment:n,withLocations:!0});i(c.items)}catch(c){console.error("Error fetching rooms:",c)}finally{o(!1)}}l()},[]),a?s.jsx("p",{children:"Loading labs..."}):s.jsxs("div",{children:[s.jsx("h3",{children:"Choose a lab"}),s.jsx(W.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:s.jsx(Fn,{name:t,render:({field:{onChange:l,value:c}})=>s.jsxs(W.Select,{"aria-label":"Choose a lab",value:c?.id||"",onChange:u=>{const d=r.find(p=>p.id.toString()===u.target.value);l(d||null)},children:[s.jsx("option",{value:"",children:"— Choose a lab"}),r.map(u=>s.jsx("option",{value:u.id,children:u.name},u.id))]}),control:e})})]})}function WB({control:e}){return s.jsx(W.Group,{className:"mb-3",controlId:"chemical.scanBarcode",children:s.jsx(Fn,{name:"barcode",control:e,render:({field:t})=>s.jsx("input",{...t,id:"chemical.scanBarcodeElement",type:"text",autoFocus:!0,placeholder:"Scan or enter barcode",className:"form-control form-control-lg"})})})}var zB=Object.defineProperty,pl=Object.getOwnPropertySymbols,cw=Object.prototype.hasOwnProperty,uw=Object.prototype.propertyIsEnumerable,Ug=(e,t,n)=>t in e?zB(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,vd=(e,t)=>{for(var n in t||(t={}))cw.call(t,n)&&Ug(e,n,t[n]);if(pl)for(var n of pl(t))uw.call(t,n)&&Ug(e,n,t[n]);return e},yd=(e,t)=>{var n={};for(var r in e)cw.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&pl)for(var r of pl(e))t.indexOf(r)<0&&uw.call(e,r)&&(n[r]=e[r]);return n};var Ci;(e=>{const t=class He{constructor(c,u,d,p){if(this.version=c,this.errorCorrectionLevel=u,this.modules=[],this.isFunction=[],c<He.MIN_VERSION||c>He.MAX_VERSION)throw new RangeError("Version value out of range");if(p<-1||p>7)throw new RangeError("Mask value out of range");this.size=c*4+17;let g=[];for(let v=0;v<this.size;v++)g.push(!1);for(let v=0;v<this.size;v++)this.modules.push(g.slice()),this.isFunction.push(g.slice());this.drawFunctionPatterns();const m=this.addEccAndInterleave(d);if(this.drawCodewords(m),p==-1){let v=1e9;for(let I=0;I<8;I++){this.applyMask(I),this.drawFormatBits(I);const C=this.getPenaltyScore();C<v&&(p=I,v=C),this.applyMask(I)}}i(0<=p&&p<=7),this.mask=p,this.applyMask(p),this.drawFormatBits(p),this.isFunction=[]}static encodeText(c,u){const d=e.QrSegment.makeSegments(c);return He.encodeSegments(d,u)}static encodeBinary(c,u){const d=e.QrSegment.makeBytes(c);return He.encodeSegments([d],u)}static encodeSegments(c,u,d=1,p=40,g=-1,m=!0){if(!(He.MIN_VERSION<=d&&d<=p&&p<=He.MAX_VERSION)||g<-1||g>7)throw new RangeError("Invalid value");let v,I;for(v=d;;v++){const y=He.getNumDataCodewords(v,u)*8,S=o.getTotalBits(c,v);if(S<=y){I=S;break}if(v>=p)throw new RangeError("Data too long")}for(const y of[He.Ecc.MEDIUM,He.Ecc.QUARTILE,He.Ecc.HIGH])m&&I<=He.getNumDataCodewords(v,y)*8&&(u=y);let C=[];for(const y of c){n(y.mode.modeBits,4,C),n(y.numChars,y.mode.numCharCountBits(v),C);for(const S of y.getData())C.push(S)}i(C.length==I);const b=He.getNumDataCodewords(v,u)*8;i(C.length<=b),n(0,Math.min(4,b-C.length),C),n(0,(8-C.length%8)%8,C),i(C.length%8==0);for(let y=236;C.length<b;y^=253)n(y,8,C);let _=[];for(;_.length*8<C.length;)_.push(0);return C.forEach((y,S)=>_[S>>>3]|=y<<7-(S&7)),new He(v,u,_,g)}getModule(c,u){return 0<=c&&c<this.size&&0<=u&&u<this.size&&this.modules[u][c]}getModules(){return this.modules}drawFunctionPatterns(){for(let d=0;d<this.size;d++)this.setFunctionModule(6,d,d%2==0),this.setFunctionModule(d,6,d%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const c=this.getAlignmentPatternPositions(),u=c.length;for(let d=0;d<u;d++)for(let p=0;p<u;p++)d==0&&p==0||d==0&&p==u-1||d==u-1&&p==0||this.drawAlignmentPattern(c[d],c[p]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(c){const u=this.errorCorrectionLevel.formatBits<<3|c;let d=u;for(let g=0;g<10;g++)d=d<<1^(d>>>9)*1335;const p=(u<<10|d)^21522;i(p>>>15==0);for(let g=0;g<=5;g++)this.setFunctionModule(8,g,r(p,g));this.setFunctionModule(8,7,r(p,6)),this.setFunctionModule(8,8,r(p,7)),this.setFunctionModule(7,8,r(p,8));for(let g=9;g<15;g++)this.setFunctionModule(14-g,8,r(p,g));for(let g=0;g<8;g++)this.setFunctionModule(this.size-1-g,8,r(p,g));for(let g=8;g<15;g++)this.setFunctionModule(8,this.size-15+g,r(p,g));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let c=this.version;for(let d=0;d<12;d++)c=c<<1^(c>>>11)*7973;const u=this.version<<12|c;i(u>>>18==0);for(let d=0;d<18;d++){const p=r(u,d),g=this.size-11+d%3,m=Math.floor(d/3);this.setFunctionModule(g,m,p),this.setFunctionModule(m,g,p)}}drawFinderPattern(c,u){for(let d=-4;d<=4;d++)for(let p=-4;p<=4;p++){const g=Math.max(Math.abs(p),Math.abs(d)),m=c+p,v=u+d;0<=m&&m<this.size&&0<=v&&v<this.size&&this.setFunctionModule(m,v,g!=2&&g!=4)}}drawAlignmentPattern(c,u){for(let d=-2;d<=2;d++)for(let p=-2;p<=2;p++)this.setFunctionModule(c+p,u+d,Math.max(Math.abs(p),Math.abs(d))!=1)}setFunctionModule(c,u,d){this.modules[u][c]=d,this.isFunction[u][c]=!0}addEccAndInterleave(c){const u=this.version,d=this.errorCorrectionLevel;if(c.length!=He.getNumDataCodewords(u,d))throw new RangeError("Invalid argument");const p=He.NUM_ERROR_CORRECTION_BLOCKS[d.ordinal][u],g=He.ECC_CODEWORDS_PER_BLOCK[d.ordinal][u],m=Math.floor(He.getNumRawDataModules(u)/8),v=p-m%p,I=Math.floor(m/p);let C=[];const b=He.reedSolomonComputeDivisor(g);for(let y=0,S=0;y<p;y++){let j=c.slice(S,S+I-g+(y<v?0:1));S+=j.length;const N=He.reedSolomonComputeRemainder(j,b);y<v&&j.push(0),C.push(j.concat(N))}let _=[];for(let y=0;y<C[0].length;y++)C.forEach((S,j)=>{(y!=I-g||j>=v)&&_.push(S[y])});return i(_.length==m),_}drawCodewords(c){if(c.length!=Math.floor(He.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let u=0;for(let d=this.size-1;d>=1;d-=2){d==6&&(d=5);for(let p=0;p<this.size;p++)for(let g=0;g<2;g++){const m=d-g,I=(d+1&2)==0?this.size-1-p:p;!this.isFunction[I][m]&&u<c.length*8&&(this.modules[I][m]=r(c[u>>>3],7-(u&7)),u++)}}i(u==c.length*8)}applyMask(c){if(c<0||c>7)throw new RangeError("Mask value out of range");for(let u=0;u<this.size;u++)for(let d=0;d<this.size;d++){let p;switch(c){case 0:p=(d+u)%2==0;break;case 1:p=u%2==0;break;case 2:p=d%3==0;break;case 3:p=(d+u)%3==0;break;case 4:p=(Math.floor(d/3)+Math.floor(u/2))%2==0;break;case 5:p=d*u%2+d*u%3==0;break;case 6:p=(d*u%2+d*u%3)%2==0;break;case 7:p=((d+u)%2+d*u%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[u][d]&&p&&(this.modules[u][d]=!this.modules[u][d])}}getPenaltyScore(){let c=0;for(let g=0;g<this.size;g++){let m=!1,v=0,I=[0,0,0,0,0,0,0];for(let C=0;C<this.size;C++)this.modules[g][C]==m?(v++,v==5?c+=He.PENALTY_N1:v>5&&c++):(this.finderPenaltyAddHistory(v,I),m||(c+=this.finderPenaltyCountPatterns(I)*He.PENALTY_N3),m=this.modules[g][C],v=1);c+=this.finderPenaltyTerminateAndCount(m,v,I)*He.PENALTY_N3}for(let g=0;g<this.size;g++){let m=!1,v=0,I=[0,0,0,0,0,0,0];for(let C=0;C<this.size;C++)this.modules[C][g]==m?(v++,v==5?c+=He.PENALTY_N1:v>5&&c++):(this.finderPenaltyAddHistory(v,I),m||(c+=this.finderPenaltyCountPatterns(I)*He.PENALTY_N3),m=this.modules[C][g],v=1);c+=this.finderPenaltyTerminateAndCount(m,v,I)*He.PENALTY_N3}for(let g=0;g<this.size-1;g++)for(let m=0;m<this.size-1;m++){const v=this.modules[g][m];v==this.modules[g][m+1]&&v==this.modules[g+1][m]&&v==this.modules[g+1][m+1]&&(c+=He.PENALTY_N2)}let u=0;for(const g of this.modules)u=g.reduce((m,v)=>m+(v?1:0),u);const d=this.size*this.size,p=Math.ceil(Math.abs(u*20-d*10)/d)-1;return i(0<=p&&p<=9),c+=p*He.PENALTY_N4,i(0<=c&&c<=2568888),c}getAlignmentPatternPositions(){if(this.version==1)return[];{const c=Math.floor(this.version/7)+2,u=this.version==32?26:Math.ceil((this.version*4+4)/(c*2-2))*2;let d=[6];for(let p=this.size-7;d.length<c;p-=u)d.splice(1,0,p);return d}}static getNumRawDataModules(c){if(c<He.MIN_VERSION||c>He.MAX_VERSION)throw new RangeError("Version number out of range");let u=(16*c+128)*c+64;if(c>=2){const d=Math.floor(c/7)+2;u-=(25*d-10)*d-55,c>=7&&(u-=36)}return i(208<=u&&u<=29648),u}static getNumDataCodewords(c,u){return Math.floor(He.getNumRawDataModules(c)/8)-He.ECC_CODEWORDS_PER_BLOCK[u.ordinal][c]*He.NUM_ERROR_CORRECTION_BLOCKS[u.ordinal][c]}static reedSolomonComputeDivisor(c){if(c<1||c>255)throw new RangeError("Degree out of range");let u=[];for(let p=0;p<c-1;p++)u.push(0);u.push(1);let d=1;for(let p=0;p<c;p++){for(let g=0;g<u.length;g++)u[g]=He.reedSolomonMultiply(u[g],d),g+1<u.length&&(u[g]^=u[g+1]);d=He.reedSolomonMultiply(d,2)}return u}static reedSolomonComputeRemainder(c,u){let d=u.map(p=>0);for(const p of c){const g=p^d.shift();d.push(0),u.forEach((m,v)=>d[v]^=He.reedSolomonMultiply(m,g))}return d}static reedSolomonMultiply(c,u){if(c>>>8||u>>>8)throw new RangeError("Byte out of range");let d=0;for(let p=7;p>=0;p--)d=d<<1^(d>>>7)*285,d^=(u>>>p&1)*c;return i(d>>>8==0),d}finderPenaltyCountPatterns(c){const u=c[1];i(u<=this.size*3);const d=u>0&&c[2]==u&&c[3]==u*3&&c[4]==u&&c[5]==u;return(d&&c[0]>=u*4&&c[6]>=u?1:0)+(d&&c[6]>=u*4&&c[0]>=u?1:0)}finderPenaltyTerminateAndCount(c,u,d){return c&&(this.finderPenaltyAddHistory(u,d),u=0),u+=this.size,this.finderPenaltyAddHistory(u,d),this.finderPenaltyCountPatterns(d)}finderPenaltyAddHistory(c,u){u[0]==0&&(c+=this.size),u.pop(),u.unshift(c)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(l,c,u){if(c<0||c>31||l>>>c)throw new RangeError("Value out of range");for(let d=c-1;d>=0;d--)u.push(l>>>d&1)}function r(l,c){return(l>>>c&1)!=0}function i(l){if(!l)throw new Error("Assertion error")}const a=class It{constructor(c,u,d){if(this.mode=c,this.numChars=u,this.bitData=d,u<0)throw new RangeError("Invalid argument");this.bitData=d.slice()}static makeBytes(c){let u=[];for(const d of c)n(d,8,u);return new It(It.Mode.BYTE,c.length,u)}static makeNumeric(c){if(!It.isNumeric(c))throw new RangeError("String contains non-numeric characters");let u=[];for(let d=0;d<c.length;){const p=Math.min(c.length-d,3);n(parseInt(c.substring(d,d+p),10),p*3+1,u),d+=p}return new It(It.Mode.NUMERIC,c.length,u)}static makeAlphanumeric(c){if(!It.isAlphanumeric(c))throw new RangeError("String contains unencodable characters in alphanumeric mode");let u=[],d;for(d=0;d+2<=c.length;d+=2){let p=It.ALPHANUMERIC_CHARSET.indexOf(c.charAt(d))*45;p+=It.ALPHANUMERIC_CHARSET.indexOf(c.charAt(d+1)),n(p,11,u)}return d<c.length&&n(It.ALPHANUMERIC_CHARSET.indexOf(c.charAt(d)),6,u),new It(It.Mode.ALPHANUMERIC,c.length,u)}static makeSegments(c){return c==""?[]:It.isNumeric(c)?[It.makeNumeric(c)]:It.isAlphanumeric(c)?[It.makeAlphanumeric(c)]:[It.makeBytes(It.toUtf8ByteArray(c))]}static makeEci(c){let u=[];if(c<0)throw new RangeError("ECI assignment value out of range");if(c<128)n(c,8,u);else if(c<16384)n(2,2,u),n(c,14,u);else if(c<1e6)n(6,3,u),n(c,21,u);else throw new RangeError("ECI assignment value out of range");return new It(It.Mode.ECI,0,u)}static isNumeric(c){return It.NUMERIC_REGEX.test(c)}static isAlphanumeric(c){return It.ALPHANUMERIC_REGEX.test(c)}getData(){return this.bitData.slice()}static getTotalBits(c,u){let d=0;for(const p of c){const g=p.mode.numCharCountBits(u);if(p.numChars>=1<<g)return 1/0;d+=4+g+p.bitData.length}return d}static toUtf8ByteArray(c){c=encodeURI(c);let u=[];for(let d=0;d<c.length;d++)c.charAt(d)!="%"?u.push(c.charCodeAt(d)):(u.push(parseInt(c.substring(d+1,d+3),16)),d+=2);return u}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let o=a;e.QrSegment=a})(Ci||(Ci={}));(e=>{(t=>{const n=class{constructor(i,a){this.ordinal=i,this.formatBits=a}};n.LOW=new n(0,1),n.MEDIUM=new n(1,0),n.QUARTILE=new n(2,3),n.HIGH=new n(3,2),t.Ecc=n})(e.QrCode||(e.QrCode={}))})(Ci||(Ci={}));(e=>{(t=>{const n=class{constructor(i,a){this.modeBits=i,this.numBitsCharCount=a}numCharCountBits(i){return this.numBitsCharCount[Math.floor((i+7)/17)]}};n.NUMERIC=new n(1,[10,12,14]),n.ALPHANUMERIC=new n(2,[9,11,13]),n.BYTE=new n(4,[8,16,16]),n.KANJI=new n(8,[8,10,12]),n.ECI=new n(7,[0,0,0]),t.Mode=n})(e.QrSegment||(e.QrSegment={}))})(Ci||(Ci={}));var Qi=Ci;var HB={L:Qi.QrCode.Ecc.LOW,M:Qi.QrCode.Ecc.MEDIUM,Q:Qi.QrCode.Ecc.QUARTILE,H:Qi.QrCode.Ecc.HIGH},dw=128,fw="L",pw="#FFFFFF",mw="#000000",hw=!1,gw=1,UB=4,$B=0,XB=.1;function xw(e,t=0){const n=[];return e.forEach(function(r,i){let a=null;r.forEach(function(o,l){if(!o&&a!==null){n.push(`M${a+t} ${i+t}h${l-a}v1H${a+t}z`),a=null;return}if(l===r.length-1){if(!o)return;a===null?n.push(`M${l+t},${i+t} h1v1H${l+t}z`):n.push(`M${a+t},${i+t} h${l+1-a}v1H${a+t}z`);return}o&&a===null&&(a=l)})}),n.join("")}function vw(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,a)=>a<t.x||a>=t.x+t.w?i:!1))}function qB(e,t,n,r){if(r==null)return null;const i=e.length+n*2,a=Math.floor(t*XB),o=i/t,l=(r.width||a)*o,c=(r.height||a)*o,u=r.x==null?e.length/2-l/2:r.x*o,d=r.y==null?e.length/2-c/2:r.y*o,p=r.opacity==null?1:r.opacity;let g=null;if(r.excavate){let v=Math.floor(u),I=Math.floor(d),C=Math.ceil(l+u-v),b=Math.ceil(c+d-I);g={x:v,y:I,w:C,h:b}}const m=r.crossOrigin;return{x:u,y:d,h:c,w:l,excavation:g,opacity:p,crossOrigin:m}}function ZB(e,t){return t!=null?Math.max(Math.floor(t),0):e?UB:$B}function yw({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:l}){let c=x.useMemo(()=>{const v=(Array.isArray(e)?e:[e]).reduce((I,C)=>(I.push(...Qi.QrSegment.makeSegments(C)),I),[]);return Qi.QrCode.encodeSegments(v,HB[t],n,void 0,void 0,l)},[e,t,n,l]);const{cells:u,margin:d,numCells:p,calculatedImageSettings:g}=x.useMemo(()=>{let m=c.getModules();const v=ZB(r,i),I=m.length+v*2,C=qB(m,o,v,a);return{cells:m,margin:v,numCells:I,calculatedImageSettings:C}},[c,o,a,r,i]);return{qrcode:c,margin:d,cells:u,numCells:p,calculatedImageSettings:g}}var JB=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),QB=x.forwardRef(function(t,n){const r=t,{value:i,size:a=dw,level:o=fw,bgColor:l=pw,fgColor:c=mw,includeMargin:u=hw,minVersion:d=gw,boostLevel:p,marginSize:g,imageSettings:m}=r,I=yd(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:C}=I,b=yd(I,["style"]),_=m?.src,y=x.useRef(null),S=x.useRef(null),j=x.useCallback(H=>{y.current=H,typeof n=="function"?n(H):n&&(n.current=H)},[n]),[N,k]=x.useState(!1),{margin:A,cells:F,numCells:L,calculatedImageSettings:Y}=yw({value:i,level:o,minVersion:d,boostLevel:p,includeMargin:u,marginSize:g,imageSettings:m,size:a});x.useEffect(()=>{if(y.current!=null){const H=y.current,T=H.getContext("2d");if(!T)return;let V=F;const Z=S.current,ne=Y!=null&&Z!==null&&Z.complete&&Z.naturalHeight!==0&&Z.naturalWidth!==0;ne&&Y.excavation!=null&&(V=vw(F,Y.excavation));const de=window.devicePixelRatio||1;H.height=H.width=a*de;const R=a/L*de;T.scale(R,R),T.fillStyle=l,T.fillRect(0,0,L,L),T.fillStyle=c,JB?T.fill(new Path2D(xw(V,A))):F.forEach(function(ee,se){ee.forEach(function(O,ae){O&&T.fillRect(ae+A,se+A,1,1)})}),Y&&(T.globalAlpha=Y.opacity),ne&&T.drawImage(Z,Y.x+A,Y.y+A,Y.w,Y.h)}}),x.useEffect(()=>{k(!1)},[_]);const G=vd({height:a,width:a},C);let X=null;return _!=null&&(X=x.createElement("img",{src:_,key:_,style:{display:"none"},onLoad:()=>{k(!0)},ref:S,crossOrigin:Y?.crossOrigin})),x.createElement(x.Fragment,null,x.createElement("canvas",vd({style:G,height:a,width:a,ref:j,role:"img"},b)),X)});QB.displayName="QRCodeCanvas";var Si=x.forwardRef(function(t,n){const r=t,{value:i,size:a=dw,level:o=fw,bgColor:l=pw,fgColor:c=mw,includeMargin:u=hw,minVersion:d=gw,boostLevel:p,title:g,marginSize:m,imageSettings:v}=r,I=yd(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:C,cells:b,numCells:_,calculatedImageSettings:y}=yw({value:i,level:o,minVersion:d,boostLevel:p,includeMargin:u,marginSize:m,imageSettings:v,size:a});let S=b,j=null;v!=null&&y!=null&&(y.excavation!=null&&(S=vw(b,y.excavation)),j=x.createElement("image",{href:v.src,height:y.h,width:y.w,x:y.x+C,y:y.y+C,preserveAspectRatio:"none",opacity:y.opacity,crossOrigin:y.crossOrigin}));const N=xw(S,C);return x.createElement("svg",vd({height:a,width:a,viewBox:`0 0 ${_} ${_}`,ref:n,role:"img"},I),!!g&&x.createElement("title",null,g),x.createElement("path",{fill:l,d:`M0,0 h${_}v${_}H0z`,shapeRendering:"crispEdges"}),x.createElement("path",{fill:c,d:N,shapeRendering:"crispEdges"}),j)});Si.displayName="QRCodeSVG";function bw({control:e,name:t,room:n}){const[r,i]=x.useState([]),[a,o]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const c=await j1({room:n,pageSize:1e3});i(c.items),o(!1)}catch(c){console.error("Error fetching locations:",c)}}l()},[n]),a?s.jsx("p",{children:"Loading locations..."}):s.jsxs(W.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:[s.jsx(W.Label,{children:"Select a storage location"}),s.jsx(Fn,{name:t,control:e,defaultValue:"",render:({field:{onChange:l,value:c}})=>s.jsx(s.Fragment,{children:s.jsx(Un,{children:r.map(u=>s.jsx(Pt,{xs:4,md:3,className:"mb-3",children:s.jsx(Ye,{onClick:()=>l(u.id.toString()),style:{cursor:"pointer",border:c.toString()===u.id.toString()?"2px solid #007bff":"1px solid #ddd",borderRadius:"8px"},className:"h-100",children:s.jsxs(Ye.Body,{children:[s.jsx(Ye.Title,{children:u.name}),s.jsxs("div",{className:"text-muted small mb-2 d-flex gap-2 justify-content-between",children:[u.code&&s.jsxs("div",{children:["Code: ",u.code]}),u.zone_group&&s.jsxs("div",{children:["Zone group: ",u.zone_group.name]})]}),s.jsxs("div",{style:{textAlign:"center",marginTop:"10px"},children:[s.jsx(Si,{value:"/l/"+u.id.toString(),size:128})," "]})]})})},u.id))})})})]})}const KB=({show:e,setShow:t,onChemicalCreate:n})=>{const{register:r,control:i,setValue:a,handleSubmit:o,formState:{errors:l,isSubmitting:c}}=tn({defaultValues:{}}),u=async d=>{try{const p=await te.post("create/chemical",d);p.data&&n(p.data)}finally{t(!1)}};return s.jsx(ve,{show:e,size:"lg",onHide:()=>t(!1),children:s.jsxs(W,{onSubmit:o(u),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Create new chemical"})}),s.jsxs(ve.Body,{children:[s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"CAS Number"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"input",...r("cas_number",{required:"A cas number is required"}),isInvalid:l.cas_number!==void 0}),l.cas_number&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.cas_number.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Name"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"input",...r("name",{required:"A name is required"}),isInvalid:l.name!==void 0}),l.name&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.name.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Description"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"textarea",rows:3,...r("description")}),l.description&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.description.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Standard product"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsxs(W.Select,{...r("standard_product",{required:"A standard product is required"}),isInvalid:l.standard_product!==void 0,children:[s.jsx("option",{value:Su.NON_STANDARD_PRODUCT,children:"Non standard product"}),s.jsx("option",{value:Su.STANDARD_PRODUCT,children:"Standard product"})]}),l.standard_product&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.standard_product.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Physical state"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsxs(W.Select,{...r("physical_state",{required:"A physical state is required"}),isInvalid:l.physical_state!==void 0,children:[s.jsx("option",{value:Xs.SOLID,children:"Solid"}),s.jsx("option",{value:Xs.LIQUID,children:"Liquid"}),s.jsx("option",{value:Xs.GAS,children:"Gas"}),s.jsx("option",{value:Xs.OTHER,children:"Other"})]}),l.physical_state&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.physical_state.message})]})]})]}),s.jsx(ve.Footer,{children:s.jsxs(ie,{variant:"primary",disabled:c,onClick:()=>o(u)(),children:[c&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create new chemical"]})})]})})};function ww({control:e,name:t,setValue:n,errors:r}){const[i,a]=x.useState({}),[o,l]=x.useState(!1),[c,u]=x.useState(null),d=(m,v)=>{try{h1({query:m}).then(C=>{const b=C.items.map(y=>({value:y.id,label:y.name+(y.cas_number?" ("+y.cas_number+")":"")})),_={...i};b.forEach(y=>{_[y.value]=y}),a(_),v(b)})}catch(I){console.error("Error fetching chemicals:",I)}},p=m=>m&&i[m]?i[m]:c||null,g=async m=>{try{const v=await te.post("create/chemical",m),I={value:v.data.id,label:v.data.name+(v.data.cas_number?` (${v.data.cas_number})`:"")};a(C=>({...C,[I.value]:I})),u(I),l(!1),n(t,v.data.id)}catch(v){console.error("Error creating chemical:",v)}};return s.jsxs(s.Fragment,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Search Existing Chemicals"}),s.jsxs(Un,{children:[s.jsx(Fn,{name:t,control:e,render:({field:m})=>s.jsx(Fl,{isSearchable:!0,isClearable:!0,defaultOptions:!0,placeholder:"— Select a chemical, or start typing",loadOptions:d,value:p(m.value),styles:bf,onChange:v=>{u(null),m.onChange(v?.value)}})}),r.chemical&&s.jsx(W.Control.Feedback,{type:"invalid",children:r.chemical.message}),s.jsx("div",{children:s.jsx(ie,{variant:"primary",className:"mt-2",onClick:()=>l(!0),children:"Create New Chemical"})})]})]}),s.jsx(KB,{show:o,setShow:l,onChemicalCreate:g})]})}function Cw(e){return/\/l\/\d+$/.test(e)}function Sw(e){const t=e.match(/\/l\/(\d+)$/);return t?parseInt(t[1],10):null}const jw=[{value:"g",label:"Gram"},{value:"kg",label:"Kilogram"},{value:"lb",label:"US pound"},{value:"mc",label:"Microgram"},{value:"mg",label:"Milligram"},{value:"oz",label:"Ounce"},{value:"to",label:"Tonnes"},{value:"ton",label:"US ton"},{value:'"3',label:"Cubic inch"},{value:"ccm",label:"Cubic centimeter"},{value:"cl",label:"Centiliter"},{value:"dm3",label:"Cubic decimeter"},{value:"foz",label:"Fluid Ounce Us"},{value:"ft3",label:"Cubic foot"},{value:"gal",label:"US gallon"},{value:"hl",label:"Hectoliter"},{value:"kit",label:"Kit"},{value:"l",label:"Liter"},{value:"m3",label:"Cubic meter"},{value:"ml",label:"Mililiter"},{value:"mm3",label:"Cubic milimeter"},{value:"pc",label:"Item"},{value:"pce",label:"Piece"},{value:"pt",label:"Pint, US liquid"},{value:"qt",label:"Quart, US liquid"},{value:"yd3",label:"Cubic Yard"},{value:"µl",label:"Microliter"}].sort((e,t)=>e.label.localeCompare(t.label));function eY({room:e,barcode:t,resetForm:n,location:r,setLocation:i}){const{user:a}=x.useContext(hs),{environment:o}=Te.useParams(),[l,c]=x.useState(null);let u=new Date;u.setFullYear(u.getFullYear()+5);const{register:d,control:p,handleSubmit:g,watch:m,setValue:v,formState:{errors:I,isSubmitting:C}}=tn({defaultValues:{expire_date:u.toISOString().split("T")[0],owner:{value:a?.id,label:a?.full_name}}}),b=m("location");x.useEffect(()=>{b&&aa({id:b}).then(S=>{i(S)})},[b]),x.useEffect(()=>{let S="";const j=N=>{if(!(N.target instanceof HTMLInputElement||N.target instanceof HTMLTextAreaElement)&&!(N.key.length>1&&N.key!=="Enter"))if(N.key==="Enter"){if(Cw(S)){const k=Sw(S);k!==null&&(aa({id:k}).then(A=>{i(A)}),v("location",k))}S.startsWith("reset-scan-location")&&y(),S=""}else S+=N.key};return window.addEventListener("keydown",j),()=>{window.removeEventListener("keydown",j)}},[v]);const _=async S=>{if(S.user=S.owner.value,(await qg({qrCodeContent:t})).items.length>0){alert("This barcode is already registered to a container");return}const N=await te.post("create/chemical/container",S);c(N.data),await te.post("create/chemical/container/external-label",{container:N.data.id,qr_code_content:t})},y=()=>{i(null),v("location",0)};return s.jsxs(s.Fragment,{children:[s.jsxs(W,{onSubmit:g(_),children:[!r&&s.jsx(bw,{room:e,control:p,name:"location"}),r&&s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Scanned location"}),s.jsx(Pt,{children:s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("span",{className:"h1",children:r.name}),s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx(Si,{value:"reset-scan-location",size:100,onClick:()=>y()}),s.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),r&&s.jsxs(s.Fragment,{children:[s.jsx(ww,{control:p,errors:I,setValue:v,...d("chemical",{required:"Chemical is required"})}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Owner"}),s.jsx(Fa,{control:p,...d("owner",{required:"Owner is required"}),name:"owner"})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Concentration"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...d("concentration",{required:"An concentration is required"}),isInvalid:I.concentration!==void 0}),I.concentration&&s.jsx(W.Control.Feedback,{type:"invalid",children:I.concentration.message})]})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Amount"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...d("amount",{required:"An amount is required"}),isInvalid:I.amount!==void 0}),s.jsx(Fn,{name:"amount_unit",control:p,render:({field:S})=>s.jsxs(Na,{id:"input-group-dropdown-1",title:S.value||"(no unit)",onSelect:j=>S.onChange(j),children:[s.jsx(at.Item,{eventKey:"",children:"(no unit)"},0),jw.map(j=>s.jsxs(at.Item,{eventKey:j.value,children:[j.label," (",j.value,")"]},j.value))]})}),I.amount&&s.jsx(W.Control.Feedback,{type:"invalid",children:I.amount.message})]})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Expire date"}),s.jsx(W.Control,{type:"date",...d("expire_date",{required:"An expire date is required"}),isInvalid:I.expire_date!==void 0}),I.expire_date&&s.jsx(W.Control.Feedback,{type:"invalid",children:I.expire_date.message})]}),s.jsxs(ie,{type:"submit",variant:"primary",disabled:C,children:[C&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),l&&s.jsxs("div",{className:"mt-3",children:[s.jsx(St,{variant:"success",children:"Container registered successfully"}),s.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[s.jsx("div",{children:s.jsx("a",{className:"btn btn-primary",href:`${o}/chemical/container/details/${l.id}/general.html`,children:"Go to container"})}),s.jsx(Si,{value:"reset-form",size:100,className:"float-end",onClick:()=>n()})]})]})]})}function tY({control:e,errors:t}){const[n,r]=x.useState({}),i=(o,l)=>{try{m1({query:o}).then(u=>{const d=u.items.map(g=>({value:g.id,label:g.name})),p={...n};d.forEach(g=>{p[g.value]=g}),r(p),l(d)})}catch(c){console.error("Error fetching types:",c)}},a=o=>n[o]||null;return s.jsx(Fn,{name:"container_type",control:e,render:({field:o})=>s.jsx(Fl,{isSearchable:!0,defaultOptions:!0,placeholder:"— Select a container type",loadOptions:i,value:a(o.value),onChange:l=>{o.onChange(l?.value)},styles:bf})})}function nY({room:e,resetForm:t,location:n,setLocation:r}){const{user:i}=x.useContext(hs),{environment:a}=Te.useParams(),[o,l]=x.useState(null);let c=new Date;c.setFullYear(c.getFullYear()+5);const{register:u,control:d,handleSubmit:p,watch:g,setValue:m,formState:{errors:v,isSubmitting:I}}=tn({defaultValues:{expire_date:c.toISOString().split("T")[0],owner:{value:i?.id,label:i?.full_name}}}),C=g("location");x.useEffect(()=>{C&&aa({id:C}).then(y=>{r(y)})},[C]),x.useEffect(()=>{let y="";const S=j=>{if(!(j.target instanceof HTMLInputElement||j.target instanceof HTMLTextAreaElement)&&!(j.key.length>1&&j.key!=="Enter"))if(j.key==="Enter"){if(Cw(y)){const N=Sw(y);N!==null&&(aa({id:N}).then(k=>{r(k)}),m("location",N))}y.startsWith("reset-scan-location")&&_(),y=""}else y+=j.key};return window.addEventListener("keydown",S),()=>{window.removeEventListener("keydown",S)}},[m]);const b=async y=>{y.user=y.owner.value;const S=await te.post("create/chemical/container",y);l(S.data)},_=()=>{r(null),m("location",0)};return s.jsxs(s.Fragment,{children:[s.jsxs(W,{onSubmit:p(b),children:[!n&&s.jsx(bw,{room:e,control:d,name:"location"}),n&&s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Scanned location"}),s.jsx(Pt,{children:s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("span",{className:"h1",children:n.name}),s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx(Si,{value:"reset-scan-location",size:100,onClick:()=>_()}),s.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),n&&s.jsxs(s.Fragment,{children:[s.jsx(ww,{control:d,errors:v,setValue:m,...u("chemical",{required:"Chemical is required"})}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Owner"}),s.jsx(Fa,{control:d,...u("owner",{required:"Owner is required"}),name:"owner"})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Concentration"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...u("concentration",{required:"An concentration is required"}),isInvalid:v.concentration!==void 0}),v.concentration&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.concentration.message})]})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Amount"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...u("amount",{required:"An amount is required"}),isInvalid:v.amount!==void 0}),s.jsx(Fn,{name:"amount_unit",control:d,render:({field:y})=>s.jsxs(Na,{id:"input-group-dropdown-1",title:y.value||"(no unit)",onSelect:S=>y.onChange(S),children:[s.jsx(at.Item,{eventKey:"",children:"(no unit)"},0),jw.map(S=>s.jsxs(at.Item,{eventKey:S.value,children:[S.label," (",S.value,")"]},S.value))]})}),v.amount&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.amount.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx(W.Label,{children:"Container type"}),s.jsx(tY,{control:d,...u("container_type",{required:"Container type is required"}),errors:v}),v.container_type&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.container_type.message})]}),s.jsxs(W.Group,{className:"mb-3 w-50 w-25-sm",children:[s.jsx(W.Label,{children:"Expire date"}),s.jsx(W.Control,{type:"date",...u("expire_date",{required:"An expire date is required"}),isInvalid:v.expire_date!==void 0}),v.expire_date&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.expire_date.message})]}),s.jsxs(ie,{type:"submit",variant:"primary",disabled:I,children:[I&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),o&&s.jsxs("div",{className:"mt-3",children:[s.jsx(St,{variant:"success",children:"Container registered successfully"}),s.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[s.jsx("div",{children:s.jsx("a",{className:"btn btn-primary",href:`${a}/chemical/container/render/single-${o.id}.pdf`,children:"Print label"})}),s.jsx("div",{children:s.jsx("a",{className:"btn btn-primary",href:`${a}/chemical/container/details/${o.id}/general.html`,children:"Go to container"})}),s.jsx(Si,{value:"reset-form",size:100,className:"float-end",onClick:()=>t()})]})]})]})}function rY(){const{environment:e}=Te.useParams(),[t,n]=x.useState(null),[r,i]=x.useState([]),[a,o]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(!1),[p,g]=x.useState(null),[m,v]=x.useState(null),{control:I,watch:C,reset:b,setValue:_}=tn({defaultValues:{room:p,barcode:""}}),y=C("room");x.useEffect(()=>{y&&(g(y),d(y.building.site.has_external_chemical_labelling))},[y]),x.useEffect(()=>{const k=new URLSearchParams(window.location.search).get("room");k&&S1({id:parseInt(k)}).then(A=>{g(A),d(A.building.site.has_external_chemical_labelling),_("room",A)})},[_]),x.useEffect(()=>{const k=new URLSearchParams(window.location.search).get("location");k&&aa({id:parseInt(k)}).then(A=>{v(A),g(A.zone_group.room),d(A.zone_group.room.building.site.has_external_chemical_labelling),_("room",A.zone_group.room)})},[_]);const S=C("barcode");x.useEffect(()=>{const k=setTimeout(()=>{if(!S?.includes("/l/")){if(S?.includes("/cc/")){n(S);const A=S.split("/cc/")[1];p1({id:parseInt(A)}).then(F=>{o(F)})}S&&(n(S),N({barcode:S}))}},1e3);return()=>{clearTimeout(k)}},[S,b]),x.useEffect(()=>{let k="";const A=F=>{F.target instanceof HTMLInputElement||F.target instanceof HTMLTextAreaElement||F.key.length>1&&F.key!=="Enter"||(F.key==="Enter"?(k==="reset-form"&&j(),k=""):k+=F.key)};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[b]);const j=()=>{b({room:p,barcode:""}),n(null),v(null)};async function N({barcode:k}){try{const A=await qg({qrCodeContent:k});A&&Array.isArray(A.items)&&A.items.length>0?(i(A.items),c(!1)):(c(!0),i([]))}catch(A){console.error("Error fetching chemical container external labels",A),i([]),c(!1)}}return s.jsxs("div",{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx(YB,{control:I,name:"room"}),s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx(Si,{value:"reset-form",size:100,className:"float-end",onClick:()=>j()}),s.jsx("span",{className:"text-muted",children:"Reset form"})]})]}),p&&u&&s.jsxs(St,{children:["Lab ",p.name," has external labels, each chemical material should have a material from the internal supplier/warehouse"]}),p&&!u&&s.jsxs(St,{children:["Lab ",p.name," has no external labels, labels can be printed via the intake form"]}),p!==null&&!t&&u&&s.jsx(WB,{control:I}),t&&a&&s.jsxs(St,{variant:"info d-flex flex-column gap-3",children:["This is already an own chemical material, this is ",a.chemical.name," and should be stored on"," ",a.location.name," in ",a.location.zone_group.room.name,s.jsx("a",{className:"alert-link",href:`${e}/chemical/container/details/${a.id}/general.html`,children:"Go to container"})]}),!a&&t&&s.jsx(s.Fragment,{children:r.length===0?s.jsx(St,{variant:"info d-flex flex-column gap-3",children:s.jsxs("div",{children:["No chemical container external labels found with label ",s.jsx("strong",{children:t})]})}):s.jsxs(Ht,{children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"ID"}),s.jsx("th",{children:"Label"}),s.jsx("th",{children:"Container"}),s.jsx("th",{children:"Location"})]})}),s.jsx("tbody",{children:r.map(k=>s.jsxs("tr",{children:[s.jsx("td",{children:k.id}),s.jsx("td",{children:k.label}),s.jsx("td",{children:s.jsx("a",{href:`/${e}/chemical/container/details/${k.container.id}/general.html`,children:k.container.chemical.name})}),s.jsx("td",{children:s.jsx("a",{href:`/${e}/location/details/${k.container.location.id}/general.html`,children:k.container.location.name})})]},k.id))})]})}),!a&&l&&p&&t&&s.jsx(eY,{room:p,barcode:t,location:m,setLocation:v,resetForm:j}),!a&&p&&!u&&s.jsx(nY,{room:p,location:m,setLocation:v,resetForm:j})]})}function iY({badge_uuid:e}){return s.jsxs("span",{className:"rounded p-2 bg-success",children:["Card read: ",e]})}function sY({user_id:e}){const[t,n]=x.useState("");return x.useEffect(()=>{const r="https://"+cp+`/api/onelab/view/user/${e}`;(async()=>{try{const a=await fetch(r);if(!a.ok)throw new Error(`Response status: ${a.status} with body: ${await a.text()}`);const o=await a.json();n(o.full_name)}catch(a){console.log(a)}})()},[]),s.jsxs("span",{className:"rounded p-2 bg-success",children:["Clients has detected user: ",t||"loading..."]})}function aY(){return s.jsx("div",{})}const bd=["all","equipment","not_set"],cp=document.getElementById("root")?.dataset.goldsteinEndpoint??"",oY="mock-token",lY=10,cY=15;async function uY(e){const t="https://"+cp+"/api/update/client-association",n=prompt("Select the new association for the client:",e);if(n===null){alert("Please enter a not null value");return}const[r,i]=n.split(":"),a=Number(i);if(!r||isNaN(a)||a===0){alert("Please follow the correct format: $item:$id");return}if(!bd.slice(1).includes(r)){alert("Please select a valid $item: (equipment, not_set)");return}const o=await fetch(t,{method:"PATCH",body:JSON.stringify({previous_association:e,new_association:n}),headers:{"Content-type":"application/json; charset=UTF-8"}});if(!o.ok)throw new Error(`Response status: ${o.status} with body: ${await o.text()}`);const l=await o.text();alert(l)}function dY(){const e=x.useRef(null),[t,n]=x.useState(new Map);async function r(u){const d=nb(u.notifications_list,new Date,lY,cY);n(d)}function i(){const d=`
35
+ `+new Error().stack),w=!1}return h.apply(this,arguments)},h)}var Y={};function G(f,h){r.deprecationHandler!=null&&r.deprecationHandler(f,h),Y[f]||(F(h),Y[f]=!0)}r.suppressDeprecationWarnings=!1,r.deprecationHandler=null;function X(f){return typeof Function<"u"&&f instanceof Function||Object.prototype.toString.call(f)==="[object Function]"}function H(f){var h,w;for(w in f)l(f,w)&&(h=f[w],X(h)?this[w]=h:this["_"+w]=h);this._config=f,this._dayOfMonthOrdinalParseLenient=new RegExp((this._dayOfMonthOrdinalParse.source||this._ordinalParse.source)+"|"+/\d{1,2}/.source)}function T(f,h){var w=m({},f),E;for(E in h)l(h,E)&&(o(f[E])&&o(h[E])?(w[E]={},m(w[E],f[E]),m(w[E],h[E])):h[E]!=null?w[E]=h[E]:delete w[E]);for(E in f)l(f,E)&&!l(h,E)&&o(f[E])&&(w[E]=m({},w[E]));return w}function V(f){f!=null&&this.set(f)}var Z;Object.keys?Z=Object.keys:Z=function(f){var h,w=[];for(h in f)l(f,h)&&w.push(h);return w};var ne={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"};function de(f,h,w){var E=this._calendar[f]||this._calendar.sameElse;return X(E)?E.call(h,w):E}function R(f,h,w){var E=""+Math.abs(f),D=h-E.length,B=f>=0;return(B?w?"+":"":"-")+Math.pow(10,Math.max(0,D)).toString().substr(1)+E}var ee=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,se=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,O={},ae={};function Q(f,h,w,E){var D=E;typeof E=="string"&&(D=function(){return this[E]()}),f&&(ae[f]=D),h&&(ae[h[0]]=function(){return R(D.apply(this,arguments),h[1],h[2])}),w&&(ae[w]=function(){return this.localeData().ordinal(D.apply(this,arguments),f)})}function pe(f){return f.match(/\[[\s\S]/)?f.replace(/^\[|\]$/g,""):f.replace(/\\/g,"")}function we(f){var h=f.match(ee),w,E;for(w=0,E=h.length;w<E;w++)ae[h[w]]?h[w]=ae[h[w]]:h[w]=pe(h[w]);return function(D){var B="",K;for(K=0;K<E;K++)B+=X(h[K])?h[K].call(D,f):h[K];return B}}function be(f,h){return f.isValid()?(h=Ee(h,f.localeData()),O[h]=O[h]||we(h),O[h](f)):f.localeData().invalidDate()}function Ee(f,h){var w=5;function E(D){return h.longDateFormat(D)||D}for(se.lastIndex=0;w>=0&&se.test(f);)f=f.replace(se,E),se.lastIndex=0,w-=1;return f}var ke={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};function Ve(f){var h=this._longDateFormat[f],w=this._longDateFormat[f.toUpperCase()];return h||!w?h:(this._longDateFormat[f]=w.match(ee).map(function(E){return E==="MMMM"||E==="MM"||E==="DD"||E==="dddd"?E.slice(1):E}).join(""),this._longDateFormat[f])}var le="Invalid date";function We(){return this._invalidDate}var dt="%d",Pe=/\d{1,2}/;function At(f){return this._ordinal.replace("%d",f)}var Rt={future:"in %s",past:"%s ago",s:"a few seconds",ss:"%d seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",w:"a week",ww:"%d weeks",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function jt(f,h,w,E){var D=this._relativeTime[w];return X(D)?D(f,h,w,E):D.replace(/%d/i,f)}function Dt(f,h){var w=this._relativeTime[f>0?"future":"past"];return X(w)?w(h):w.replace(/%s/i,h)}var ze={D:"date",dates:"date",date:"date",d:"day",days:"day",day:"day",e:"weekday",weekdays:"weekday",weekday:"weekday",E:"isoWeekday",isoweekdays:"isoWeekday",isoweekday:"isoWeekday",DDD:"dayOfYear",dayofyears:"dayOfYear",dayofyear:"dayOfYear",h:"hour",hours:"hour",hour:"hour",ms:"millisecond",milliseconds:"millisecond",millisecond:"millisecond",m:"minute",minutes:"minute",minute:"minute",M:"month",months:"month",month:"month",Q:"quarter",quarters:"quarter",quarter:"quarter",s:"second",seconds:"second",second:"second",gg:"weekYear",weekyears:"weekYear",weekyear:"weekYear",GG:"isoWeekYear",isoweekyears:"isoWeekYear",isoweekyear:"isoWeekYear",w:"week",weeks:"week",week:"week",W:"isoWeek",isoweeks:"isoWeek",isoweek:"isoWeek",y:"year",years:"year",year:"year"};function P(f){return typeof f=="string"?ze[f]||ze[f.toLowerCase()]:void 0}function z(f){var h={},w,E;for(E in f)l(f,E)&&(w=P(E),w&&(h[w]=f[E]));return h}var J={date:9,day:11,weekday:11,isoWeekday:11,dayOfYear:4,hour:13,millisecond:16,minute:14,month:8,quarter:7,second:15,weekYear:1,isoWeekYear:1,week:5,isoWeek:5,year:1};function he(f){var h=[],w;for(w in f)l(f,w)&&h.push({unit:w,priority:J[w]});return h.sort(function(E,D){return E.priority-D.priority}),h}var q=/\d/,M=/\d\d/,U=/\d{3}/,re=/\d{4}/,me=/[+-]?\d{6}/,ge=/\d\d?/,Je=/\d\d\d\d?/,Ct=/\d\d\d\d\d\d?/,Mt=/\d{1,3}/,Ut=/\d{1,4}/,Vt=/[+-]?\d{1,6}/,ft=/\d+/,Yt=/[+-]?\d+/,$t=/Z|[+-]\d\d:?\d\d/gi,Vn=/Z|[+-]\d\d(?::?\d\d)?/gi,nc=/[+-]?\d+(\.\d{1,3})?/,Es=/[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,Di=/^[1-9]\d?/,rc=/^([1-9]\d|\d)/,Ha;Ha={};function je(f,h,w){Ha[f]=X(h)?h:function(E,D){return E&&w?w:h}}function _w(f,h){return l(Ha,f)?Ha[f](h._strict,h._locale):new RegExp(Ew(f))}function Ew(f){return fr(f.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(h,w,E,D,B){return w||E||D||B}))}function fr(f){return f.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function En(f){return f<0?Math.ceil(f)||0:Math.floor(f)}function Ue(f){var h=+f,w=0;return h!==0&&isFinite(h)&&(w=En(h)),w}var ic={};function ot(f,h){var w,E=h,D;for(typeof f=="string"&&(f=[f]),d(h)&&(E=function(B,K){K[h]=Ue(B)}),D=f.length,w=0;w<D;w++)ic[f[w]]=E}function ks(f,h){ot(f,function(w,E,D,B){D._w=D._w||{},h(w,D._w,D,B)})}function kw(f,h,w){h!=null&&l(ic,f)&&ic[f](h,w._a,w,f)}function Ua(f){return f%4===0&&f%100!==0||f%400===0}var Zt=0,pr=1,Zn=2,Gt=3,Gn=4,mr=5,ti=6,Nw=7,Aw=8;Q("Y",0,0,function(){var f=this.year();return f<=9999?R(f,4):"+"+f}),Q(0,["YY",2],0,function(){return this.year()%100}),Q(0,["YYYY",4],0,"year"),Q(0,["YYYYY",5],0,"year"),Q(0,["YYYYYY",6,!0],0,"year"),je("Y",Yt),je("YY",ge,M),je("YYYY",Ut,re),je("YYYYY",Vt,me),je("YYYYYY",Vt,me),ot(["YYYYY","YYYYYY"],Zt),ot("YYYY",function(f,h){h[Zt]=f.length===2?r.parseTwoDigitYear(f):Ue(f)}),ot("YY",function(f,h){h[Zt]=r.parseTwoDigitYear(f)}),ot("Y",function(f,h){h[Zt]=parseInt(f,10)});function Ns(f){return Ua(f)?366:365}r.parseTwoDigitYear=function(f){return Ue(f)+(Ue(f)>68?1900:2e3)};var up=Mi("FullYear",!0);function Rw(){return Ua(this.year())}function Mi(f,h){return function(w){return w!=null?(dp(this,f,w),r.updateOffset(this,h),this):As(this,f)}}function As(f,h){if(!f.isValid())return NaN;var w=f._d,E=f._isUTC;switch(h){case"Milliseconds":return E?w.getUTCMilliseconds():w.getMilliseconds();case"Seconds":return E?w.getUTCSeconds():w.getSeconds();case"Minutes":return E?w.getUTCMinutes():w.getMinutes();case"Hours":return E?w.getUTCHours():w.getHours();case"Date":return E?w.getUTCDate():w.getDate();case"Day":return E?w.getUTCDay():w.getDay();case"Month":return E?w.getUTCMonth():w.getMonth();case"FullYear":return E?w.getUTCFullYear():w.getFullYear();default:return NaN}}function dp(f,h,w){var E,D,B,K,Se;if(!(!f.isValid()||isNaN(w))){switch(E=f._d,D=f._isUTC,h){case"Milliseconds":return void(D?E.setUTCMilliseconds(w):E.setMilliseconds(w));case"Seconds":return void(D?E.setUTCSeconds(w):E.setSeconds(w));case"Minutes":return void(D?E.setUTCMinutes(w):E.setMinutes(w));case"Hours":return void(D?E.setUTCHours(w):E.setHours(w));case"Date":return void(D?E.setUTCDate(w):E.setDate(w));case"FullYear":break;default:return}B=w,K=f.month(),Se=f.date(),Se=Se===29&&K===1&&!Ua(B)?28:Se,D?E.setUTCFullYear(B,K,Se):E.setFullYear(B,K,Se)}}function Dw(f){return f=P(f),X(this[f])?this[f]():this}function Mw(f,h){if(typeof f=="object"){f=z(f);var w=he(f),E,D=w.length;for(E=0;E<D;E++)this[w[E].unit](f[w[E].unit])}else if(f=P(f),X(this[f]))return this[f](h);return this}function Ow(f,h){return(f%h+h)%h}var Et;Array.prototype.indexOf?Et=Array.prototype.indexOf:Et=function(f){var h;for(h=0;h<this.length;++h)if(this[h]===f)return h;return-1};function sc(f,h){if(isNaN(f)||isNaN(h))return NaN;var w=Ow(h,12);return f+=(h-w)/12,w===1?Ua(f)?29:28:31-w%7%2}Q("M",["MM",2],"Mo",function(){return this.month()+1}),Q("MMM",0,0,function(f){return this.localeData().monthsShort(this,f)}),Q("MMMM",0,0,function(f){return this.localeData().months(this,f)}),je("M",ge,Di),je("MM",ge,M),je("MMM",function(f,h){return h.monthsShortRegex(f)}),je("MMMM",function(f,h){return h.monthsRegex(f)}),ot(["M","MM"],function(f,h){h[pr]=Ue(f)-1}),ot(["MMM","MMMM"],function(f,h,w,E){var D=w._locale.monthsParse(f,E,w._strict);D!=null?h[pr]=D:C(w).invalidMonth=f});var Tw="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),fp="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),pp=/D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,Fw=Es,Pw=Es;function Lw(f,h){return f?a(this._months)?this._months[f.month()]:this._months[(this._months.isFormat||pp).test(h)?"format":"standalone"][f.month()]:a(this._months)?this._months:this._months.standalone}function Vw(f,h){return f?a(this._monthsShort)?this._monthsShort[f.month()]:this._monthsShort[pp.test(h)?"format":"standalone"][f.month()]:a(this._monthsShort)?this._monthsShort:this._monthsShort.standalone}function Gw(f,h,w){var E,D,B,K=f.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],E=0;E<12;++E)B=v([2e3,E]),this._shortMonthsParse[E]=this.monthsShort(B,"").toLocaleLowerCase(),this._longMonthsParse[E]=this.months(B,"").toLocaleLowerCase();return w?h==="MMM"?(D=Et.call(this._shortMonthsParse,K),D!==-1?D:null):(D=Et.call(this._longMonthsParse,K),D!==-1?D:null):h==="MMM"?(D=Et.call(this._shortMonthsParse,K),D!==-1?D:(D=Et.call(this._longMonthsParse,K),D!==-1?D:null)):(D=Et.call(this._longMonthsParse,K),D!==-1?D:(D=Et.call(this._shortMonthsParse,K),D!==-1?D:null))}function Bw(f,h,w){var E,D,B;if(this._monthsParseExact)return Gw.call(this,f,h,w);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),E=0;E<12;E++){if(D=v([2e3,E]),w&&!this._longMonthsParse[E]&&(this._longMonthsParse[E]=new RegExp("^"+this.months(D,"").replace(".","")+"$","i"),this._shortMonthsParse[E]=new RegExp("^"+this.monthsShort(D,"").replace(".","")+"$","i")),!w&&!this._monthsParse[E]&&(B="^"+this.months(D,"")+"|^"+this.monthsShort(D,""),this._monthsParse[E]=new RegExp(B.replace(".",""),"i")),w&&h==="MMMM"&&this._longMonthsParse[E].test(f))return E;if(w&&h==="MMM"&&this._shortMonthsParse[E].test(f))return E;if(!w&&this._monthsParse[E].test(f))return E}}function mp(f,h){if(!f.isValid())return f;if(typeof h=="string"){if(/^\d+$/.test(h))h=Ue(h);else if(h=f.localeData().monthsParse(h),!d(h))return f}var w=h,E=f.date();return E=E<29?E:Math.min(E,sc(f.year(),w)),f._isUTC?f._d.setUTCMonth(w,E):f._d.setMonth(w,E),f}function hp(f){return f!=null?(mp(this,f),r.updateOffset(this,!0),this):As(this,"Month")}function Yw(){return sc(this.year(),this.month())}function Ww(f){return this._monthsParseExact?(l(this,"_monthsRegex")||gp.call(this),f?this._monthsShortStrictRegex:this._monthsShortRegex):(l(this,"_monthsShortRegex")||(this._monthsShortRegex=Fw),this._monthsShortStrictRegex&&f?this._monthsShortStrictRegex:this._monthsShortRegex)}function zw(f){return this._monthsParseExact?(l(this,"_monthsRegex")||gp.call(this),f?this._monthsStrictRegex:this._monthsRegex):(l(this,"_monthsRegex")||(this._monthsRegex=Pw),this._monthsStrictRegex&&f?this._monthsStrictRegex:this._monthsRegex)}function gp(){function f(Le,Xe){return Xe.length-Le.length}var h=[],w=[],E=[],D,B,K,Se;for(D=0;D<12;D++)B=v([2e3,D]),K=fr(this.monthsShort(B,"")),Se=fr(this.months(B,"")),h.push(K),w.push(Se),E.push(Se),E.push(K);h.sort(f),w.sort(f),E.sort(f),this._monthsRegex=new RegExp("^("+E.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+w.join("|")+")","i"),this._monthsShortStrictRegex=new RegExp("^("+h.join("|")+")","i")}function Hw(f,h,w,E,D,B,K){var Se;return f<100&&f>=0?(Se=new Date(f+400,h,w,E,D,B,K),isFinite(Se.getFullYear())&&Se.setFullYear(f)):Se=new Date(f,h,w,E,D,B,K),Se}function Rs(f){var h,w;return f<100&&f>=0?(w=Array.prototype.slice.call(arguments),w[0]=f+400,h=new Date(Date.UTC.apply(null,w)),isFinite(h.getUTCFullYear())&&h.setUTCFullYear(f)):h=new Date(Date.UTC.apply(null,arguments)),h}function $a(f,h,w){var E=7+h-w,D=(7+Rs(f,0,E).getUTCDay()-h)%7;return-D+E-1}function xp(f,h,w,E,D){var B=(7+w-E)%7,K=$a(f,E,D),Se=1+7*(h-1)+B+K,Le,Xe;return Se<=0?(Le=f-1,Xe=Ns(Le)+Se):Se>Ns(f)?(Le=f+1,Xe=Se-Ns(f)):(Le=f,Xe=Se),{year:Le,dayOfYear:Xe}}function Ds(f,h,w){var E=$a(f.year(),h,w),D=Math.floor((f.dayOfYear()-E-1)/7)+1,B,K;return D<1?(K=f.year()-1,B=D+hr(K,h,w)):D>hr(f.year(),h,w)?(B=D-hr(f.year(),h,w),K=f.year()+1):(K=f.year(),B=D),{week:B,year:K}}function hr(f,h,w){var E=$a(f,h,w),D=$a(f+1,h,w);return(Ns(f)-E+D)/7}Q("w",["ww",2],"wo","week"),Q("W",["WW",2],"Wo","isoWeek"),je("w",ge,Di),je("ww",ge,M),je("W",ge,Di),je("WW",ge,M),ks(["w","ww","W","WW"],function(f,h,w,E){h[E.substr(0,1)]=Ue(f)});function Uw(f){return Ds(f,this._week.dow,this._week.doy).week}var $w={dow:0,doy:6};function Xw(){return this._week.dow}function qw(){return this._week.doy}function Zw(f){var h=this.localeData().week(this);return f==null?h:this.add((f-h)*7,"d")}function Jw(f){var h=Ds(this,1,4).week;return f==null?h:this.add((f-h)*7,"d")}Q("d",0,"do","day"),Q("dd",0,0,function(f){return this.localeData().weekdaysMin(this,f)}),Q("ddd",0,0,function(f){return this.localeData().weekdaysShort(this,f)}),Q("dddd",0,0,function(f){return this.localeData().weekdays(this,f)}),Q("e",0,0,"weekday"),Q("E",0,0,"isoWeekday"),je("d",ge),je("e",ge),je("E",ge),je("dd",function(f,h){return h.weekdaysMinRegex(f)}),je("ddd",function(f,h){return h.weekdaysShortRegex(f)}),je("dddd",function(f,h){return h.weekdaysRegex(f)}),ks(["dd","ddd","dddd"],function(f,h,w,E){var D=w._locale.weekdaysParse(f,E,w._strict);D!=null?h.d=D:C(w).invalidWeekday=f}),ks(["d","e","E"],function(f,h,w,E){h[E]=Ue(f)});function Qw(f,h){return typeof f!="string"?f:isNaN(f)?(f=h.weekdaysParse(f),typeof f=="number"?f:null):parseInt(f,10)}function Kw(f,h){return typeof f=="string"?h.weekdaysParse(f)%7||7:isNaN(f)?null:f}function ac(f,h){return f.slice(h,7).concat(f.slice(0,h))}var eC="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),vp="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),tC="Su_Mo_Tu_We_Th_Fr_Sa".split("_"),nC=Es,rC=Es,iC=Es;function sC(f,h){var w=a(this._weekdays)?this._weekdays:this._weekdays[f&&f!==!0&&this._weekdays.isFormat.test(h)?"format":"standalone"];return f===!0?ac(w,this._week.dow):f?w[f.day()]:w}function aC(f){return f===!0?ac(this._weekdaysShort,this._week.dow):f?this._weekdaysShort[f.day()]:this._weekdaysShort}function oC(f){return f===!0?ac(this._weekdaysMin,this._week.dow):f?this._weekdaysMin[f.day()]:this._weekdaysMin}function lC(f,h,w){var E,D,B,K=f.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],E=0;E<7;++E)B=v([2e3,1]).day(E),this._minWeekdaysParse[E]=this.weekdaysMin(B,"").toLocaleLowerCase(),this._shortWeekdaysParse[E]=this.weekdaysShort(B,"").toLocaleLowerCase(),this._weekdaysParse[E]=this.weekdays(B,"").toLocaleLowerCase();return w?h==="dddd"?(D=Et.call(this._weekdaysParse,K),D!==-1?D:null):h==="ddd"?(D=Et.call(this._shortWeekdaysParse,K),D!==-1?D:null):(D=Et.call(this._minWeekdaysParse,K),D!==-1?D:null):h==="dddd"?(D=Et.call(this._weekdaysParse,K),D!==-1||(D=Et.call(this._shortWeekdaysParse,K),D!==-1)?D:(D=Et.call(this._minWeekdaysParse,K),D!==-1?D:null)):h==="ddd"?(D=Et.call(this._shortWeekdaysParse,K),D!==-1||(D=Et.call(this._weekdaysParse,K),D!==-1)?D:(D=Et.call(this._minWeekdaysParse,K),D!==-1?D:null)):(D=Et.call(this._minWeekdaysParse,K),D!==-1||(D=Et.call(this._weekdaysParse,K),D!==-1)?D:(D=Et.call(this._shortWeekdaysParse,K),D!==-1?D:null))}function cC(f,h,w){var E,D,B;if(this._weekdaysParseExact)return lC.call(this,f,h,w);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),E=0;E<7;E++){if(D=v([2e3,1]).day(E),w&&!this._fullWeekdaysParse[E]&&(this._fullWeekdaysParse[E]=new RegExp("^"+this.weekdays(D,"").replace(".","\\.?")+"$","i"),this._shortWeekdaysParse[E]=new RegExp("^"+this.weekdaysShort(D,"").replace(".","\\.?")+"$","i"),this._minWeekdaysParse[E]=new RegExp("^"+this.weekdaysMin(D,"").replace(".","\\.?")+"$","i")),this._weekdaysParse[E]||(B="^"+this.weekdays(D,"")+"|^"+this.weekdaysShort(D,"")+"|^"+this.weekdaysMin(D,""),this._weekdaysParse[E]=new RegExp(B.replace(".",""),"i")),w&&h==="dddd"&&this._fullWeekdaysParse[E].test(f))return E;if(w&&h==="ddd"&&this._shortWeekdaysParse[E].test(f))return E;if(w&&h==="dd"&&this._minWeekdaysParse[E].test(f))return E;if(!w&&this._weekdaysParse[E].test(f))return E}}function uC(f){if(!this.isValid())return f!=null?this:NaN;var h=As(this,"Day");return f!=null?(f=Qw(f,this.localeData()),this.add(f-h,"d")):h}function dC(f){if(!this.isValid())return f!=null?this:NaN;var h=(this.day()+7-this.localeData()._week.dow)%7;return f==null?h:this.add(f-h,"d")}function fC(f){if(!this.isValid())return f!=null?this:NaN;if(f!=null){var h=Kw(f,this.localeData());return this.day(this.day()%7?h:h-7)}else return this.day()||7}function pC(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||oc.call(this),f?this._weekdaysStrictRegex:this._weekdaysRegex):(l(this,"_weekdaysRegex")||(this._weekdaysRegex=nC),this._weekdaysStrictRegex&&f?this._weekdaysStrictRegex:this._weekdaysRegex)}function mC(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||oc.call(this),f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(l(this,"_weekdaysShortRegex")||(this._weekdaysShortRegex=rC),this._weekdaysShortStrictRegex&&f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function hC(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||oc.call(this),f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(l(this,"_weekdaysMinRegex")||(this._weekdaysMinRegex=iC),this._weekdaysMinStrictRegex&&f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function oc(){function f(sn,br){return br.length-sn.length}var h=[],w=[],E=[],D=[],B,K,Se,Le,Xe;for(B=0;B<7;B++)K=v([2e3,1]).day(B),Se=fr(this.weekdaysMin(K,"")),Le=fr(this.weekdaysShort(K,"")),Xe=fr(this.weekdays(K,"")),h.push(Se),w.push(Le),E.push(Xe),D.push(Se),D.push(Le),D.push(Xe);h.sort(f),w.sort(f),E.sort(f),D.sort(f),this._weekdaysRegex=new RegExp("^("+D.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+E.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+w.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+h.join("|")+")","i")}function lc(){return this.hours()%12||12}function gC(){return this.hours()||24}Q("H",["HH",2],0,"hour"),Q("h",["hh",2],0,lc),Q("k",["kk",2],0,gC),Q("hmm",0,0,function(){return""+lc.apply(this)+R(this.minutes(),2)}),Q("hmmss",0,0,function(){return""+lc.apply(this)+R(this.minutes(),2)+R(this.seconds(),2)}),Q("Hmm",0,0,function(){return""+this.hours()+R(this.minutes(),2)}),Q("Hmmss",0,0,function(){return""+this.hours()+R(this.minutes(),2)+R(this.seconds(),2)});function yp(f,h){Q(f,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),h)})}yp("a",!0),yp("A",!1);function bp(f,h){return h._meridiemParse}je("a",bp),je("A",bp),je("H",ge,rc),je("h",ge,Di),je("k",ge,Di),je("HH",ge,M),je("hh",ge,M),je("kk",ge,M),je("hmm",Je),je("hmmss",Ct),je("Hmm",Je),je("Hmmss",Ct),ot(["H","HH"],Gt),ot(["k","kk"],function(f,h,w){var E=Ue(f);h[Gt]=E===24?0:E}),ot(["a","A"],function(f,h,w){w._isPm=w._locale.isPM(f),w._meridiem=f}),ot(["h","hh"],function(f,h,w){h[Gt]=Ue(f),C(w).bigHour=!0}),ot("hmm",function(f,h,w){var E=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E)),C(w).bigHour=!0}),ot("hmmss",function(f,h,w){var E=f.length-4,D=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E,2)),h[mr]=Ue(f.substr(D)),C(w).bigHour=!0}),ot("Hmm",function(f,h,w){var E=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E))}),ot("Hmmss",function(f,h,w){var E=f.length-4,D=f.length-2;h[Gt]=Ue(f.substr(0,E)),h[Gn]=Ue(f.substr(E,2)),h[mr]=Ue(f.substr(D))});function xC(f){return(f+"").toLowerCase().charAt(0)==="p"}var vC=/[ap]\.?m?\.?/i,yC=Mi("Hours",!0);function bC(f,h,w){return f>11?w?"pm":"PM":w?"am":"AM"}var wp={calendar:ne,longDateFormat:ke,invalidDate:le,ordinal:dt,dayOfMonthOrdinalParse:Pe,relativeTime:Rt,months:Tw,monthsShort:fp,week:$w,weekdays:eC,weekdaysMin:tC,weekdaysShort:vp,meridiemParse:vC},bt={},Ms={},Os;function wC(f,h){var w,E=Math.min(f.length,h.length);for(w=0;w<E;w+=1)if(f[w]!==h[w])return w;return E}function Cp(f){return f&&f.toLowerCase().replace("_","-")}function CC(f){for(var h=0,w,E,D,B;h<f.length;){for(B=Cp(f[h]).split("-"),w=B.length,E=Cp(f[h+1]),E=E?E.split("-"):null;w>0;){if(D=Xa(B.slice(0,w).join("-")),D)return D;if(E&&E.length>=w&&wC(B,E)>=w-1)break;w--}h++}return Os}function SC(f){return!!(f&&f.match("^[^/\\\\]*$"))}function Xa(f){var h=null,w;if(bt[f]===void 0&&e&&e.exports&&SC(f))try{h=Os._abbr,w=ZV,w("./locale/"+f),Vr(h)}catch{bt[f]=null}return bt[f]}function Vr(f,h){var w;return f&&(u(h)?w=gr(f):w=cc(f,h),w?Os=w:typeof console<"u"&&console.warn&&console.warn("Locale "+f+" not found. Did you forget to load it?")),Os._abbr}function cc(f,h){if(h!==null){var w,E=wp;if(h.abbr=f,bt[f]!=null)G("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info."),E=bt[f]._config;else if(h.parentLocale!=null)if(bt[h.parentLocale]!=null)E=bt[h.parentLocale]._config;else if(w=Xa(h.parentLocale),w!=null)E=w._config;else return Ms[h.parentLocale]||(Ms[h.parentLocale]=[]),Ms[h.parentLocale].push({name:f,config:h}),null;return bt[f]=new V(T(E,h)),Ms[f]&&Ms[f].forEach(function(D){cc(D.name,D.config)}),Vr(f),bt[f]}else return delete bt[f],null}function jC(f,h){if(h!=null){var w,E,D=wp;bt[f]!=null&&bt[f].parentLocale!=null?bt[f].set(T(bt[f]._config,h)):(E=Xa(f),E!=null&&(D=E._config),h=T(D,h),E==null&&(h.abbr=f),w=new V(h),w.parentLocale=bt[f],bt[f]=w),Vr(f)}else bt[f]!=null&&(bt[f].parentLocale!=null?(bt[f]=bt[f].parentLocale,f===Vr()&&Vr(f)):bt[f]!=null&&delete bt[f]);return bt[f]}function gr(f){var h;if(f&&f._locale&&f._locale._abbr&&(f=f._locale._abbr),!f)return Os;if(!a(f)){if(h=Xa(f),h)return h;f=[f]}return CC(f)}function IC(){return Z(bt)}function uc(f){var h,w=f._a;return w&&C(f).overflow===-2&&(h=w[pr]<0||w[pr]>11?pr:w[Zn]<1||w[Zn]>sc(w[Zt],w[pr])?Zn:w[Gt]<0||w[Gt]>24||w[Gt]===24&&(w[Gn]!==0||w[mr]!==0||w[ti]!==0)?Gt:w[Gn]<0||w[Gn]>59?Gn:w[mr]<0||w[mr]>59?mr:w[ti]<0||w[ti]>999?ti:-1,C(f)._overflowDayOfYear&&(h<Zt||h>Zn)&&(h=Zn),C(f)._overflowWeeks&&h===-1&&(h=Nw),C(f)._overflowWeekday&&h===-1&&(h=Aw),C(f).overflow=h),f}var _C=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,EC=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,kC=/Z|[+-]\d\d(?::?\d\d)?/,qa=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/],["YYYYMM",/\d{6}/,!1],["YYYY",/\d{4}/,!1]],dc=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],NC=/^\/?Date\((-?\d+)/i,AC=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,RC={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Sp(f){var h,w,E=f._i,D=_C.exec(E)||EC.exec(E),B,K,Se,Le,Xe=qa.length,sn=dc.length;if(D){for(C(f).iso=!0,h=0,w=Xe;h<w;h++)if(qa[h][1].exec(D[1])){K=qa[h][0],B=qa[h][2]!==!1;break}if(K==null){f._isValid=!1;return}if(D[3]){for(h=0,w=sn;h<w;h++)if(dc[h][1].exec(D[3])){Se=(D[2]||" ")+dc[h][0];break}if(Se==null){f._isValid=!1;return}}if(!B&&Se!=null){f._isValid=!1;return}if(D[4])if(kC.exec(D[4]))Le="Z";else{f._isValid=!1;return}f._f=K+(Se||"")+(Le||""),pc(f)}else f._isValid=!1}function DC(f,h,w,E,D,B){var K=[MC(f),fp.indexOf(h),parseInt(w,10),parseInt(E,10),parseInt(D,10)];return B&&K.push(parseInt(B,10)),K}function MC(f){var h=parseInt(f,10);return h<=49?2e3+h:h<=999?1900+h:h}function OC(f){return f.replace(/\([^()]*\)|[\n\t]/g," ").replace(/(\s\s+)/g," ").replace(/^\s\s*/,"").replace(/\s\s*$/,"")}function TC(f,h,w){if(f){var E=vp.indexOf(f),D=new Date(h[0],h[1],h[2]).getDay();if(E!==D)return C(w).weekdayMismatch=!0,w._isValid=!1,!1}return!0}function FC(f,h,w){if(f)return RC[f];if(h)return 0;var E=parseInt(w,10),D=E%100,B=(E-D)/100;return B*60+D}function jp(f){var h=AC.exec(OC(f._i)),w;if(h){if(w=DC(h[4],h[3],h[2],h[5],h[6],h[7]),!TC(h[1],w,f))return;f._a=w,f._tzm=FC(h[8],h[9],h[10]),f._d=Rs.apply(null,f._a),f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),C(f).rfc2822=!0}else f._isValid=!1}function PC(f){var h=NC.exec(f._i);if(h!==null){f._d=new Date(+h[1]);return}if(Sp(f),f._isValid===!1)delete f._isValid;else return;if(jp(f),f._isValid===!1)delete f._isValid;else return;f._strict?f._isValid=!1:r.createFromInputFallback(f)}r.createFromInputFallback=L("value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.",function(f){f._d=new Date(f._i+(f._useUTC?" UTC":""))});function Oi(f,h,w){return f??h??w}function LC(f){var h=new Date(r.now());return f._useUTC?[h.getUTCFullYear(),h.getUTCMonth(),h.getUTCDate()]:[h.getFullYear(),h.getMonth(),h.getDate()]}function fc(f){var h,w,E=[],D,B,K;if(!f._d){for(D=LC(f),f._w&&f._a[Zn]==null&&f._a[pr]==null&&VC(f),f._dayOfYear!=null&&(K=Oi(f._a[Zt],D[Zt]),(f._dayOfYear>Ns(K)||f._dayOfYear===0)&&(C(f)._overflowDayOfYear=!0),w=Rs(K,0,f._dayOfYear),f._a[pr]=w.getUTCMonth(),f._a[Zn]=w.getUTCDate()),h=0;h<3&&f._a[h]==null;++h)f._a[h]=E[h]=D[h];for(;h<7;h++)f._a[h]=E[h]=f._a[h]==null?h===2?1:0:f._a[h];f._a[Gt]===24&&f._a[Gn]===0&&f._a[mr]===0&&f._a[ti]===0&&(f._nextDay=!0,f._a[Gt]=0),f._d=(f._useUTC?Rs:Hw).apply(null,E),B=f._useUTC?f._d.getUTCDay():f._d.getDay(),f._tzm!=null&&f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),f._nextDay&&(f._a[Gt]=24),f._w&&typeof f._w.d<"u"&&f._w.d!==B&&(C(f).weekdayMismatch=!0)}}function VC(f){var h,w,E,D,B,K,Se,Le,Xe;h=f._w,h.GG!=null||h.W!=null||h.E!=null?(B=1,K=4,w=Oi(h.GG,f._a[Zt],Ds(gt(),1,4).year),E=Oi(h.W,1),D=Oi(h.E,1),(D<1||D>7)&&(Le=!0)):(B=f._locale._week.dow,K=f._locale._week.doy,Xe=Ds(gt(),B,K),w=Oi(h.gg,f._a[Zt],Xe.year),E=Oi(h.w,Xe.week),h.d!=null?(D=h.d,(D<0||D>6)&&(Le=!0)):h.e!=null?(D=h.e+B,(h.e<0||h.e>6)&&(Le=!0)):D=B),E<1||E>hr(w,B,K)?C(f)._overflowWeeks=!0:Le!=null?C(f)._overflowWeekday=!0:(Se=xp(w,E,D,B,K),f._a[Zt]=Se.year,f._dayOfYear=Se.dayOfYear)}r.ISO_8601=function(){},r.RFC_2822=function(){};function pc(f){if(f._f===r.ISO_8601){Sp(f);return}if(f._f===r.RFC_2822){jp(f);return}f._a=[],C(f).empty=!0;var h=""+f._i,w,E,D,B,K,Se=h.length,Le=0,Xe,sn;for(D=Ee(f._f,f._locale).match(ee)||[],sn=D.length,w=0;w<sn;w++)B=D[w],E=(h.match(_w(B,f))||[])[0],E&&(K=h.substr(0,h.indexOf(E)),K.length>0&&C(f).unusedInput.push(K),h=h.slice(h.indexOf(E)+E.length),Le+=E.length),ae[B]?(E?C(f).empty=!1:C(f).unusedTokens.push(B),kw(B,E,f)):f._strict&&!E&&C(f).unusedTokens.push(B);C(f).charsLeftOver=Se-Le,h.length>0&&C(f).unusedInput.push(h),f._a[Gt]<=12&&C(f).bigHour===!0&&f._a[Gt]>0&&(C(f).bigHour=void 0),C(f).parsedDateParts=f._a.slice(0),C(f).meridiem=f._meridiem,f._a[Gt]=GC(f._locale,f._a[Gt],f._meridiem),Xe=C(f).era,Xe!==null&&(f._a[Zt]=f._locale.erasConvertYear(Xe,f._a[Zt])),fc(f),uc(f)}function GC(f,h,w){var E;return w==null?h:f.meridiemHour!=null?f.meridiemHour(h,w):(f.isPM!=null&&(E=f.isPM(w),E&&h<12&&(h+=12),!E&&h===12&&(h=0)),h)}function BC(f){var h,w,E,D,B,K,Se=!1,Le=f._f.length;if(Le===0){C(f).invalidFormat=!0,f._d=new Date(NaN);return}for(D=0;D<Le;D++)B=0,K=!1,h=N({},f),f._useUTC!=null&&(h._useUTC=f._useUTC),h._f=f._f[D],pc(h),_(h)&&(K=!0),B+=C(h).charsLeftOver,B+=C(h).unusedTokens.length*10,C(h).score=B,Se?B<E&&(E=B,w=h):(E==null||B<E||K)&&(E=B,w=h,K&&(Se=!0));m(f,w||h)}function YC(f){if(!f._d){var h=z(f._i),w=h.day===void 0?h.date:h.day;f._a=g([h.year,h.month,w,h.hour,h.minute,h.second,h.millisecond],function(E){return E&&parseInt(E,10)}),fc(f)}}function WC(f){var h=new k(uc(Ip(f)));return h._nextDay&&(h.add(1,"d"),h._nextDay=void 0),h}function Ip(f){var h=f._i,w=f._f;return f._locale=f._locale||gr(f._l),h===null||w===void 0&&h===""?y({nullInput:!0}):(typeof h=="string"&&(f._i=h=f._locale.preparse(h)),A(h)?new k(uc(h)):(p(h)?f._d=h:a(w)?BC(f):w?pc(f):zC(f),_(f)||(f._d=null),f))}function zC(f){var h=f._i;u(h)?f._d=new Date(r.now()):p(h)?f._d=new Date(h.valueOf()):typeof h=="string"?PC(f):a(h)?(f._a=g(h.slice(0),function(w){return parseInt(w,10)}),fc(f)):o(h)?YC(f):d(h)?f._d=new Date(h):r.createFromInputFallback(f)}function _p(f,h,w,E,D){var B={};return(h===!0||h===!1)&&(E=h,h=void 0),(w===!0||w===!1)&&(E=w,w=void 0),(o(f)&&c(f)||a(f)&&f.length===0)&&(f=void 0),B._isAMomentObject=!0,B._useUTC=B._isUTC=D,B._l=w,B._i=f,B._f=h,B._strict=E,WC(B)}function gt(f,h,w,E){return _p(f,h,w,E,!1)}var HC=L("moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=gt.apply(null,arguments);return this.isValid()&&f.isValid()?f<this?this:f:y()}),UC=L("moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=gt.apply(null,arguments);return this.isValid()&&f.isValid()?f>this?this:f:y()});function Ep(f,h){var w,E;if(h.length===1&&a(h[0])&&(h=h[0]),!h.length)return gt();for(w=h[0],E=1;E<h.length;++E)(!h[E].isValid()||h[E][f](w))&&(w=h[E]);return w}function $C(){var f=[].slice.call(arguments,0);return Ep("isBefore",f)}function XC(){var f=[].slice.call(arguments,0);return Ep("isAfter",f)}var qC=function(){return Date.now?Date.now():+new Date},Ts=["year","quarter","month","week","day","hour","minute","second","millisecond"];function ZC(f){var h,w=!1,E,D=Ts.length;for(h in f)if(l(f,h)&&!(Et.call(Ts,h)!==-1&&(f[h]==null||!isNaN(f[h]))))return!1;for(E=0;E<D;++E)if(f[Ts[E]]){if(w)return!1;parseFloat(f[Ts[E]])!==Ue(f[Ts[E]])&&(w=!0)}return!0}function JC(){return this._isValid}function QC(){return Bn(NaN)}function Za(f){var h=z(f),w=h.year||0,E=h.quarter||0,D=h.month||0,B=h.week||h.isoWeek||0,K=h.day||0,Se=h.hour||0,Le=h.minute||0,Xe=h.second||0,sn=h.millisecond||0;this._isValid=ZC(h),this._milliseconds=+sn+Xe*1e3+Le*6e4+Se*1e3*60*60,this._days=+K+B*7,this._months=+D+E*3+w*12,this._data={},this._locale=gr(),this._bubble()}function Ja(f){return f instanceof Za}function mc(f){return f<0?Math.round(-1*f)*-1:Math.round(f)}function KC(f,h,w){var E=Math.min(f.length,h.length),D=Math.abs(f.length-h.length),B=0,K;for(K=0;K<E;K++)Ue(f[K])!==Ue(h[K])&&B++;return B+D}function kp(f,h){Q(f,0,0,function(){var w=this.utcOffset(),E="+";return w<0&&(w=-w,E="-"),E+R(~~(w/60),2)+h+R(~~w%60,2)})}kp("Z",":"),kp("ZZ",""),je("Z",Vn),je("ZZ",Vn),ot(["Z","ZZ"],function(f,h,w){w._useUTC=!0,w._tzm=hc(Vn,f)});var eS=/([\+\-]|\d\d)/gi;function hc(f,h){var w=(h||"").match(f),E,D,B;return w===null?null:(E=w[w.length-1]||[],D=(E+"").match(eS)||["-",0,0],B=+(D[1]*60)+Ue(D[2]),B===0?0:D[0]==="+"?B:-B)}function gc(f,h){var w,E;return h._isUTC?(w=h.clone(),E=(A(f)||p(f)?f.valueOf():gt(f).valueOf())-w.valueOf(),w._d.setTime(w._d.valueOf()+E),r.updateOffset(w,!1),w):gt(f).local()}function xc(f){return-Math.round(f._d.getTimezoneOffset())}r.updateOffset=function(){};function tS(f,h,w){var E=this._offset||0,D;if(!this.isValid())return f!=null?this:NaN;if(f!=null){if(typeof f=="string"){if(f=hc(Vn,f),f===null)return this}else Math.abs(f)<16&&!w&&(f=f*60);return!this._isUTC&&h&&(D=xc(this)),this._offset=f,this._isUTC=!0,D!=null&&this.add(D,"m"),E!==f&&(!h||this._changeInProgress?Dp(this,Bn(f-E,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,r.updateOffset(this,!0),this._changeInProgress=null)),this}else return this._isUTC?E:xc(this)}function nS(f,h){return f!=null?(typeof f!="string"&&(f=-f),this.utcOffset(f,h),this):-this.utcOffset()}function rS(f){return this.utcOffset(0,f)}function iS(f){return this._isUTC&&(this.utcOffset(0,f),this._isUTC=!1,f&&this.subtract(xc(this),"m")),this}function sS(){if(this._tzm!=null)this.utcOffset(this._tzm,!1,!0);else if(typeof this._i=="string"){var f=hc($t,this._i);f!=null?this.utcOffset(f):this.utcOffset(0,!0)}return this}function aS(f){return this.isValid()?(f=f?gt(f).utcOffset():0,(this.utcOffset()-f)%60===0):!1}function oS(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function lS(){if(!u(this._isDSTShifted))return this._isDSTShifted;var f={},h;return N(f,this),f=Ip(f),f._a?(h=f._isUTC?v(f._a):gt(f._a),this._isDSTShifted=this.isValid()&&KC(f._a,h.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function cS(){return this.isValid()?!this._isUTC:!1}function uS(){return this.isValid()?this._isUTC:!1}function Np(){return this.isValid()?this._isUTC&&this._offset===0:!1}var dS=/^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,fS=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function Bn(f,h){var w=f,E=null,D,B,K;return Ja(f)?w={ms:f._milliseconds,d:f._days,M:f._months}:d(f)||!isNaN(+f)?(w={},h?w[h]=+f:w.milliseconds=+f):(E=dS.exec(f))?(D=E[1]==="-"?-1:1,w={y:0,d:Ue(E[Zn])*D,h:Ue(E[Gt])*D,m:Ue(E[Gn])*D,s:Ue(E[mr])*D,ms:Ue(mc(E[ti]*1e3))*D}):(E=fS.exec(f))?(D=E[1]==="-"?-1:1,w={y:ni(E[2],D),M:ni(E[3],D),w:ni(E[4],D),d:ni(E[5],D),h:ni(E[6],D),m:ni(E[7],D),s:ni(E[8],D)}):w==null?w={}:typeof w=="object"&&("from"in w||"to"in w)&&(K=pS(gt(w.from),gt(w.to)),w={},w.ms=K.milliseconds,w.M=K.months),B=new Za(w),Ja(f)&&l(f,"_locale")&&(B._locale=f._locale),Ja(f)&&l(f,"_isValid")&&(B._isValid=f._isValid),B}Bn.fn=Za.prototype,Bn.invalid=QC;function ni(f,h){var w=f&&parseFloat(f.replace(",","."));return(isNaN(w)?0:w)*h}function Ap(f,h){var w={};return w.months=h.month()-f.month()+(h.year()-f.year())*12,f.clone().add(w.months,"M").isAfter(h)&&--w.months,w.milliseconds=+h-+f.clone().add(w.months,"M"),w}function pS(f,h){var w;return f.isValid()&&h.isValid()?(h=gc(h,f),f.isBefore(h)?w=Ap(f,h):(w=Ap(h,f),w.milliseconds=-w.milliseconds,w.months=-w.months),w):{milliseconds:0,months:0}}function Rp(f,h){return function(w,E){var D,B;return E!==null&&!isNaN(+E)&&(G(h,"moment()."+h+"(period, number) is deprecated. Please use moment()."+h+"(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info."),B=w,w=E,E=B),D=Bn(w,E),Dp(this,D,f),this}}function Dp(f,h,w,E){var D=h._milliseconds,B=mc(h._days),K=mc(h._months);f.isValid()&&(E=E??!0,K&&mp(f,As(f,"Month")+K*w),B&&dp(f,"Date",As(f,"Date")+B*w),D&&f._d.setTime(f._d.valueOf()+D*w),E&&r.updateOffset(f,B||K))}var mS=Rp(1,"add"),hS=Rp(-1,"subtract");function Mp(f){return typeof f=="string"||f instanceof String}function gS(f){return A(f)||p(f)||Mp(f)||d(f)||vS(f)||xS(f)||f===null||f===void 0}function xS(f){var h=o(f)&&!c(f),w=!1,E=["years","year","y","months","month","M","days","day","d","dates","date","D","hours","hour","h","minutes","minute","m","seconds","second","s","milliseconds","millisecond","ms"],D,B,K=E.length;for(D=0;D<K;D+=1)B=E[D],w=w||l(f,B);return h&&w}function vS(f){var h=a(f),w=!1;return h&&(w=f.filter(function(E){return!d(E)&&Mp(f)}).length===0),h&&w}function yS(f){var h=o(f)&&!c(f),w=!1,E=["sameDay","nextDay","lastDay","nextWeek","lastWeek","sameElse"],D,B;for(D=0;D<E.length;D+=1)B=E[D],w=w||l(f,B);return h&&w}function bS(f,h){var w=f.diff(h,"days",!0);return w<-6?"sameElse":w<-1?"lastWeek":w<0?"lastDay":w<1?"sameDay":w<2?"nextDay":w<7?"nextWeek":"sameElse"}function wS(f,h){arguments.length===1&&(arguments[0]?gS(arguments[0])?(f=arguments[0],h=void 0):yS(arguments[0])&&(h=arguments[0],f=void 0):(f=void 0,h=void 0));var w=f||gt(),E=gc(w,this).startOf("day"),D=r.calendarFormat(this,E)||"sameElse",B=h&&(X(h[D])?h[D].call(this,w):h[D]);return this.format(B||this.localeData().calendar(D,this,gt(w)))}function CS(){return new k(this)}function SS(f,h){var w=A(f)?f:gt(f);return this.isValid()&&w.isValid()?(h=P(h)||"millisecond",h==="millisecond"?this.valueOf()>w.valueOf():w.valueOf()<this.clone().startOf(h).valueOf()):!1}function jS(f,h){var w=A(f)?f:gt(f);return this.isValid()&&w.isValid()?(h=P(h)||"millisecond",h==="millisecond"?this.valueOf()<w.valueOf():this.clone().endOf(h).valueOf()<w.valueOf()):!1}function IS(f,h,w,E){var D=A(f)?f:gt(f),B=A(h)?h:gt(h);return this.isValid()&&D.isValid()&&B.isValid()?(E=E||"()",(E[0]==="("?this.isAfter(D,w):!this.isBefore(D,w))&&(E[1]===")"?this.isBefore(B,w):!this.isAfter(B,w))):!1}function _S(f,h){var w=A(f)?f:gt(f),E;return this.isValid()&&w.isValid()?(h=P(h)||"millisecond",h==="millisecond"?this.valueOf()===w.valueOf():(E=w.valueOf(),this.clone().startOf(h).valueOf()<=E&&E<=this.clone().endOf(h).valueOf())):!1}function ES(f,h){return this.isSame(f,h)||this.isAfter(f,h)}function kS(f,h){return this.isSame(f,h)||this.isBefore(f,h)}function NS(f,h,w){var E,D,B;if(!this.isValid())return NaN;if(E=gc(f,this),!E.isValid())return NaN;switch(D=(E.utcOffset()-this.utcOffset())*6e4,h=P(h),h){case"year":B=Qa(this,E)/12;break;case"month":B=Qa(this,E);break;case"quarter":B=Qa(this,E)/3;break;case"second":B=(this-E)/1e3;break;case"minute":B=(this-E)/6e4;break;case"hour":B=(this-E)/36e5;break;case"day":B=(this-E-D)/864e5;break;case"week":B=(this-E-D)/6048e5;break;default:B=this-E}return w?B:En(B)}function Qa(f,h){if(f.date()<h.date())return-Qa(h,f);var w=(h.year()-f.year())*12+(h.month()-f.month()),E=f.clone().add(w,"months"),D,B;return h-E<0?(D=f.clone().add(w-1,"months"),B=(h-E)/(E-D)):(D=f.clone().add(w+1,"months"),B=(h-E)/(D-E)),-(w+B)||0}r.defaultFormat="YYYY-MM-DDTHH:mm:ssZ",r.defaultFormatUtc="YYYY-MM-DDTHH:mm:ss[Z]";function AS(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function RS(f){if(!this.isValid())return null;var h=f!==!0,w=h?this.clone().utc():this;return w.year()<0||w.year()>9999?be(w,h?"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYYYY-MM-DD[T]HH:mm:ss.SSSZ"):X(Date.prototype.toISOString)?h?this.toDate().toISOString():new Date(this.valueOf()+this.utcOffset()*60*1e3).toISOString().replace("Z",be(w,"Z")):be(w,h?"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYY-MM-DD[T]HH:mm:ss.SSSZ")}function DS(){if(!this.isValid())return"moment.invalid(/* "+this._i+" */)";var f="moment",h="",w,E,D,B;return this.isLocal()||(f=this.utcOffset()===0?"moment.utc":"moment.parseZone",h="Z"),w="["+f+'("]',E=0<=this.year()&&this.year()<=9999?"YYYY":"YYYYYY",D="-MM-DD[T]HH:mm:ss.SSS",B=h+'[")]',this.format(w+E+D+B)}function MS(f){f||(f=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var h=be(this,f);return this.localeData().postformat(h)}function OS(f,h){return this.isValid()&&(A(f)&&f.isValid()||gt(f).isValid())?Bn({to:this,from:f}).locale(this.locale()).humanize(!h):this.localeData().invalidDate()}function TS(f){return this.from(gt(),f)}function FS(f,h){return this.isValid()&&(A(f)&&f.isValid()||gt(f).isValid())?Bn({from:this,to:f}).locale(this.locale()).humanize(!h):this.localeData().invalidDate()}function PS(f){return this.to(gt(),f)}function Op(f){var h;return f===void 0?this._locale._abbr:(h=gr(f),h!=null&&(this._locale=h),this)}var Tp=L("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(f){return f===void 0?this.localeData():this.locale(f)});function Fp(){return this._locale}var Ka=1e3,Ti=60*Ka,eo=60*Ti,Pp=(365*400+97)*24*eo;function Fi(f,h){return(f%h+h)%h}function Lp(f,h,w){return f<100&&f>=0?new Date(f+400,h,w)-Pp:new Date(f,h,w).valueOf()}function Vp(f,h,w){return f<100&&f>=0?Date.UTC(f+400,h,w)-Pp:Date.UTC(f,h,w)}function LS(f){var h,w;if(f=P(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(w=this._isUTC?Vp:Lp,f){case"year":h=w(this.year(),0,1);break;case"quarter":h=w(this.year(),this.month()-this.month()%3,1);break;case"month":h=w(this.year(),this.month(),1);break;case"week":h=w(this.year(),this.month(),this.date()-this.weekday());break;case"isoWeek":h=w(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case"day":case"date":h=w(this.year(),this.month(),this.date());break;case"hour":h=this._d.valueOf(),h-=Fi(h+(this._isUTC?0:this.utcOffset()*Ti),eo);break;case"minute":h=this._d.valueOf(),h-=Fi(h,Ti);break;case"second":h=this._d.valueOf(),h-=Fi(h,Ka);break}return this._d.setTime(h),r.updateOffset(this,!0),this}function VS(f){var h,w;if(f=P(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(w=this._isUTC?Vp:Lp,f){case"year":h=w(this.year()+1,0,1)-1;break;case"quarter":h=w(this.year(),this.month()-this.month()%3+3,1)-1;break;case"month":h=w(this.year(),this.month()+1,1)-1;break;case"week":h=w(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case"isoWeek":h=w(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case"day":case"date":h=w(this.year(),this.month(),this.date()+1)-1;break;case"hour":h=this._d.valueOf(),h+=eo-Fi(h+(this._isUTC?0:this.utcOffset()*Ti),eo)-1;break;case"minute":h=this._d.valueOf(),h+=Ti-Fi(h,Ti)-1;break;case"second":h=this._d.valueOf(),h+=Ka-Fi(h,Ka)-1;break}return this._d.setTime(h),r.updateOffset(this,!0),this}function GS(){return this._d.valueOf()-(this._offset||0)*6e4}function BS(){return Math.floor(this.valueOf()/1e3)}function YS(){return new Date(this.valueOf())}function WS(){var f=this;return[f.year(),f.month(),f.date(),f.hour(),f.minute(),f.second(),f.millisecond()]}function zS(){var f=this;return{years:f.year(),months:f.month(),date:f.date(),hours:f.hours(),minutes:f.minutes(),seconds:f.seconds(),milliseconds:f.milliseconds()}}function HS(){return this.isValid()?this.toISOString():null}function US(){return _(this)}function $S(){return m({},C(this))}function XS(){return C(this).overflow}function qS(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}Q("N",0,0,"eraAbbr"),Q("NN",0,0,"eraAbbr"),Q("NNN",0,0,"eraAbbr"),Q("NNNN",0,0,"eraName"),Q("NNNNN",0,0,"eraNarrow"),Q("y",["y",1],"yo","eraYear"),Q("y",["yy",2],0,"eraYear"),Q("y",["yyy",3],0,"eraYear"),Q("y",["yyyy",4],0,"eraYear"),je("N",vc),je("NN",vc),je("NNN",vc),je("NNNN",aj),je("NNNNN",oj),ot(["N","NN","NNN","NNNN","NNNNN"],function(f,h,w,E){var D=w._locale.erasParse(f,E,w._strict);D?C(w).era=D:C(w).invalidEra=f}),je("y",ft),je("yy",ft),je("yyy",ft),je("yyyy",ft),je("yo",lj),ot(["y","yy","yyy","yyyy"],Zt),ot(["yo"],function(f,h,w,E){var D;w._locale._eraYearOrdinalRegex&&(D=f.match(w._locale._eraYearOrdinalRegex)),w._locale.eraYearOrdinalParse?h[Zt]=w._locale.eraYearOrdinalParse(f,D):h[Zt]=parseInt(f,10)});function ZS(f,h){var w,E,D,B=this._eras||gr("en")._eras;for(w=0,E=B.length;w<E;++w)switch(typeof B[w].since==="string"&&(D=r(B[w].since).startOf("day"),B[w].since=D.valueOf()),typeof B[w].until){case"undefined":B[w].until=1/0;break;case"string":D=r(B[w].until).startOf("day").valueOf(),B[w].until=D.valueOf();break}return B}function JS(f,h,w){var E,D,B=this.eras(),K,Se,Le;for(f=f.toUpperCase(),E=0,D=B.length;E<D;++E)if(K=B[E].name.toUpperCase(),Se=B[E].abbr.toUpperCase(),Le=B[E].narrow.toUpperCase(),w)switch(h){case"N":case"NN":case"NNN":if(Se===f)return B[E];break;case"NNNN":if(K===f)return B[E];break;case"NNNNN":if(Le===f)return B[E];break}else if([K,Se,Le].indexOf(f)>=0)return B[E]}function QS(f,h){var w=f.since<=f.until?1:-1;return h===void 0?r(f.since).year():r(f.since).year()+(h-f.offset)*w}function KS(){var f,h,w,E=this.localeData().eras();for(f=0,h=E.length;f<h;++f)if(w=this.clone().startOf("day").valueOf(),E[f].since<=w&&w<=E[f].until||E[f].until<=w&&w<=E[f].since)return E[f].name;return""}function ej(){var f,h,w,E=this.localeData().eras();for(f=0,h=E.length;f<h;++f)if(w=this.clone().startOf("day").valueOf(),E[f].since<=w&&w<=E[f].until||E[f].until<=w&&w<=E[f].since)return E[f].narrow;return""}function tj(){var f,h,w,E=this.localeData().eras();for(f=0,h=E.length;f<h;++f)if(w=this.clone().startOf("day").valueOf(),E[f].since<=w&&w<=E[f].until||E[f].until<=w&&w<=E[f].since)return E[f].abbr;return""}function nj(){var f,h,w,E,D=this.localeData().eras();for(f=0,h=D.length;f<h;++f)if(w=D[f].since<=D[f].until?1:-1,E=this.clone().startOf("day").valueOf(),D[f].since<=E&&E<=D[f].until||D[f].until<=E&&E<=D[f].since)return(this.year()-r(D[f].since).year())*w+D[f].offset;return this.year()}function rj(f){return l(this,"_erasNameRegex")||yc.call(this),f?this._erasNameRegex:this._erasRegex}function ij(f){return l(this,"_erasAbbrRegex")||yc.call(this),f?this._erasAbbrRegex:this._erasRegex}function sj(f){return l(this,"_erasNarrowRegex")||yc.call(this),f?this._erasNarrowRegex:this._erasRegex}function vc(f,h){return h.erasAbbrRegex(f)}function aj(f,h){return h.erasNameRegex(f)}function oj(f,h){return h.erasNarrowRegex(f)}function lj(f,h){return h._eraYearOrdinalRegex||ft}function yc(){var f=[],h=[],w=[],E=[],D,B,K,Se,Le,Xe=this.eras();for(D=0,B=Xe.length;D<B;++D)K=fr(Xe[D].name),Se=fr(Xe[D].abbr),Le=fr(Xe[D].narrow),h.push(K),f.push(Se),w.push(Le),E.push(K),E.push(Se),E.push(Le);this._erasRegex=new RegExp("^("+E.join("|")+")","i"),this._erasNameRegex=new RegExp("^("+h.join("|")+")","i"),this._erasAbbrRegex=new RegExp("^("+f.join("|")+")","i"),this._erasNarrowRegex=new RegExp("^("+w.join("|")+")","i")}Q(0,["gg",2],0,function(){return this.weekYear()%100}),Q(0,["GG",2],0,function(){return this.isoWeekYear()%100});function to(f,h){Q(0,[f,f.length],0,h)}to("gggg","weekYear"),to("ggggg","weekYear"),to("GGGG","isoWeekYear"),to("GGGGG","isoWeekYear"),je("G",Yt),je("g",Yt),je("GG",ge,M),je("gg",ge,M),je("GGGG",Ut,re),je("gggg",Ut,re),je("GGGGG",Vt,me),je("ggggg",Vt,me),ks(["gggg","ggggg","GGGG","GGGGG"],function(f,h,w,E){h[E.substr(0,2)]=Ue(f)}),ks(["gg","GG"],function(f,h,w,E){h[E]=r.parseTwoDigitYear(f)});function cj(f){return Gp.call(this,f,this.week(),this.weekday()+this.localeData()._week.dow,this.localeData()._week.dow,this.localeData()._week.doy)}function uj(f){return Gp.call(this,f,this.isoWeek(),this.isoWeekday(),1,4)}function dj(){return hr(this.year(),1,4)}function fj(){return hr(this.isoWeekYear(),1,4)}function pj(){var f=this.localeData()._week;return hr(this.year(),f.dow,f.doy)}function mj(){var f=this.localeData()._week;return hr(this.weekYear(),f.dow,f.doy)}function Gp(f,h,w,E,D){var B;return f==null?Ds(this,E,D).year:(B=hr(f,E,D),h>B&&(h=B),hj.call(this,f,h,w,E,D))}function hj(f,h,w,E,D){var B=xp(f,h,w,E,D),K=Rs(B.year,0,B.dayOfYear);return this.year(K.getUTCFullYear()),this.month(K.getUTCMonth()),this.date(K.getUTCDate()),this}Q("Q",0,"Qo","quarter"),je("Q",q),ot("Q",function(f,h){h[pr]=(Ue(f)-1)*3});function gj(f){return f==null?Math.ceil((this.month()+1)/3):this.month((f-1)*3+this.month()%3)}Q("D",["DD",2],"Do","date"),je("D",ge,Di),je("DD",ge,M),je("Do",function(f,h){return f?h._dayOfMonthOrdinalParse||h._ordinalParse:h._dayOfMonthOrdinalParseLenient}),ot(["D","DD"],Zn),ot("Do",function(f,h){h[Zn]=Ue(f.match(ge)[0])});var Bp=Mi("Date",!0);Q("DDD",["DDDD",3],"DDDo","dayOfYear"),je("DDD",Mt),je("DDDD",U),ot(["DDD","DDDD"],function(f,h,w){w._dayOfYear=Ue(f)});function xj(f){var h=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return f==null?h:this.add(f-h,"d")}Q("m",["mm",2],0,"minute"),je("m",ge,rc),je("mm",ge,M),ot(["m","mm"],Gn);var vj=Mi("Minutes",!1);Q("s",["ss",2],0,"second"),je("s",ge,rc),je("ss",ge,M),ot(["s","ss"],mr);var yj=Mi("Seconds",!1);Q("S",0,0,function(){return~~(this.millisecond()/100)}),Q(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),Q(0,["SSS",3],0,"millisecond"),Q(0,["SSSS",4],0,function(){return this.millisecond()*10}),Q(0,["SSSSS",5],0,function(){return this.millisecond()*100}),Q(0,["SSSSSS",6],0,function(){return this.millisecond()*1e3}),Q(0,["SSSSSSS",7],0,function(){return this.millisecond()*1e4}),Q(0,["SSSSSSSS",8],0,function(){return this.millisecond()*1e5}),Q(0,["SSSSSSSSS",9],0,function(){return this.millisecond()*1e6}),je("S",Mt,q),je("SS",Mt,M),je("SSS",Mt,U);var Gr,Yp;for(Gr="SSSS";Gr.length<=9;Gr+="S")je(Gr,ft);function bj(f,h){h[ti]=Ue(("0."+f)*1e3)}for(Gr="S";Gr.length<=9;Gr+="S")ot(Gr,bj);Yp=Mi("Milliseconds",!1),Q("z",0,0,"zoneAbbr"),Q("zz",0,0,"zoneName");function wj(){return this._isUTC?"UTC":""}function Cj(){return this._isUTC?"Coordinated Universal Time":""}var ce=k.prototype;ce.add=mS,ce.calendar=wS,ce.clone=CS,ce.diff=NS,ce.endOf=VS,ce.format=MS,ce.from=OS,ce.fromNow=TS,ce.to=FS,ce.toNow=PS,ce.get=Dw,ce.invalidAt=XS,ce.isAfter=SS,ce.isBefore=jS,ce.isBetween=IS,ce.isSame=_S,ce.isSameOrAfter=ES,ce.isSameOrBefore=kS,ce.isValid=US,ce.lang=Tp,ce.locale=Op,ce.localeData=Fp,ce.max=UC,ce.min=HC,ce.parsingFlags=$S,ce.set=Mw,ce.startOf=LS,ce.subtract=hS,ce.toArray=WS,ce.toObject=zS,ce.toDate=YS,ce.toISOString=RS,ce.inspect=DS,typeof Symbol<"u"&&Symbol.for!=null&&(ce[Symbol.for("nodejs.util.inspect.custom")]=function(){return"Moment<"+this.format()+">"}),ce.toJSON=HS,ce.toString=AS,ce.unix=BS,ce.valueOf=GS,ce.creationData=qS,ce.eraName=KS,ce.eraNarrow=ej,ce.eraAbbr=tj,ce.eraYear=nj,ce.year=up,ce.isLeapYear=Rw,ce.weekYear=cj,ce.isoWeekYear=uj,ce.quarter=ce.quarters=gj,ce.month=hp,ce.daysInMonth=Yw,ce.week=ce.weeks=Zw,ce.isoWeek=ce.isoWeeks=Jw,ce.weeksInYear=pj,ce.weeksInWeekYear=mj,ce.isoWeeksInYear=dj,ce.isoWeeksInISOWeekYear=fj,ce.date=Bp,ce.day=ce.days=uC,ce.weekday=dC,ce.isoWeekday=fC,ce.dayOfYear=xj,ce.hour=ce.hours=yC,ce.minute=ce.minutes=vj,ce.second=ce.seconds=yj,ce.millisecond=ce.milliseconds=Yp,ce.utcOffset=tS,ce.utc=rS,ce.local=iS,ce.parseZone=sS,ce.hasAlignedHourOffset=aS,ce.isDST=oS,ce.isLocal=cS,ce.isUtcOffset=uS,ce.isUtc=Np,ce.isUTC=Np,ce.zoneAbbr=wj,ce.zoneName=Cj,ce.dates=L("dates accessor is deprecated. Use date instead.",Bp),ce.months=L("months accessor is deprecated. Use month instead",hp),ce.years=L("years accessor is deprecated. Use year instead",up),ce.zone=L("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",nS),ce.isDSTShifted=L("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",lS);function Sj(f){return gt(f*1e3)}function jj(){return gt.apply(null,arguments).parseZone()}function Wp(f){return f}var Qe=V.prototype;Qe.calendar=de,Qe.longDateFormat=Ve,Qe.invalidDate=We,Qe.ordinal=At,Qe.preparse=Wp,Qe.postformat=Wp,Qe.relativeTime=jt,Qe.pastFuture=Dt,Qe.set=H,Qe.eras=ZS,Qe.erasParse=JS,Qe.erasConvertYear=QS,Qe.erasAbbrRegex=ij,Qe.erasNameRegex=rj,Qe.erasNarrowRegex=sj,Qe.months=Lw,Qe.monthsShort=Vw,Qe.monthsParse=Bw,Qe.monthsRegex=zw,Qe.monthsShortRegex=Ww,Qe.week=Uw,Qe.firstDayOfYear=qw,Qe.firstDayOfWeek=Xw,Qe.weekdays=sC,Qe.weekdaysMin=oC,Qe.weekdaysShort=aC,Qe.weekdaysParse=cC,Qe.weekdaysRegex=pC,Qe.weekdaysShortRegex=mC,Qe.weekdaysMinRegex=hC,Qe.isPM=xC,Qe.meridiem=bC;function no(f,h,w,E){var D=gr(),B=v().set(E,h);return D[w](B,f)}function zp(f,h,w){if(d(f)&&(h=f,f=void 0),f=f||"",h!=null)return no(f,h,w,"month");var E,D=[];for(E=0;E<12;E++)D[E]=no(f,E,w,"month");return D}function bc(f,h,w,E){typeof f=="boolean"?(d(h)&&(w=h,h=void 0),h=h||""):(h=f,w=h,f=!1,d(h)&&(w=h,h=void 0),h=h||"");var D=gr(),B=f?D._week.dow:0,K,Se=[];if(w!=null)return no(h,(w+B)%7,E,"day");for(K=0;K<7;K++)Se[K]=no(h,(K+B)%7,E,"day");return Se}function Ij(f,h){return zp(f,h,"months")}function _j(f,h){return zp(f,h,"monthsShort")}function Ej(f,h,w){return bc(f,h,w,"weekdays")}function kj(f,h,w){return bc(f,h,w,"weekdaysShort")}function Nj(f,h,w){return bc(f,h,w,"weekdaysMin")}Vr("en",{eras:[{since:"0001-01-01",until:1/0,offset:1,name:"Anno Domini",narrow:"AD",abbr:"AD"},{since:"0000-12-31",until:-1/0,offset:1,name:"Before Christ",narrow:"BC",abbr:"BC"}],dayOfMonthOrdinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(f){var h=f%10,w=Ue(f%100/10)===1?"th":h===1?"st":h===2?"nd":h===3?"rd":"th";return f+w}}),r.lang=L("moment.lang is deprecated. Use moment.locale instead.",Vr),r.langData=L("moment.langData is deprecated. Use moment.localeData instead.",gr);var xr=Math.abs;function Aj(){var f=this._data;return this._milliseconds=xr(this._milliseconds),this._days=xr(this._days),this._months=xr(this._months),f.milliseconds=xr(f.milliseconds),f.seconds=xr(f.seconds),f.minutes=xr(f.minutes),f.hours=xr(f.hours),f.months=xr(f.months),f.years=xr(f.years),this}function Hp(f,h,w,E){var D=Bn(h,w);return f._milliseconds+=E*D._milliseconds,f._days+=E*D._days,f._months+=E*D._months,f._bubble()}function Rj(f,h){return Hp(this,f,h,1)}function Dj(f,h){return Hp(this,f,h,-1)}function Up(f){return f<0?Math.floor(f):Math.ceil(f)}function Mj(){var f=this._milliseconds,h=this._days,w=this._months,E=this._data,D,B,K,Se,Le;return f>=0&&h>=0&&w>=0||f<=0&&h<=0&&w<=0||(f+=Up(wc(w)+h)*864e5,h=0,w=0),E.milliseconds=f%1e3,D=En(f/1e3),E.seconds=D%60,B=En(D/60),E.minutes=B%60,K=En(B/60),E.hours=K%24,h+=En(K/24),Le=En($p(h)),w+=Le,h-=Up(wc(Le)),Se=En(w/12),w%=12,E.days=h,E.months=w,E.years=Se,this}function $p(f){return f*4800/146097}function wc(f){return f*146097/4800}function Oj(f){if(!this.isValid())return NaN;var h,w,E=this._milliseconds;if(f=P(f),f==="month"||f==="quarter"||f==="year")switch(h=this._days+E/864e5,w=this._months+$p(h),f){case"month":return w;case"quarter":return w/3;case"year":return w/12}else switch(h=this._days+Math.round(wc(this._months)),f){case"week":return h/7+E/6048e5;case"day":return h+E/864e5;case"hour":return h*24+E/36e5;case"minute":return h*1440+E/6e4;case"second":return h*86400+E/1e3;case"millisecond":return Math.floor(h*864e5)+E;default:throw new Error("Unknown unit "+f)}}function vr(f){return function(){return this.as(f)}}var Xp=vr("ms"),Tj=vr("s"),Fj=vr("m"),Pj=vr("h"),Lj=vr("d"),Vj=vr("w"),Gj=vr("M"),Bj=vr("Q"),Yj=vr("y"),Wj=Xp;function zj(){return Bn(this)}function Hj(f){return f=P(f),this.isValid()?this[f+"s"]():NaN}function ri(f){return function(){return this.isValid()?this._data[f]:NaN}}var Uj=ri("milliseconds"),$j=ri("seconds"),Xj=ri("minutes"),qj=ri("hours"),Zj=ri("days"),Jj=ri("months"),Qj=ri("years");function Kj(){return En(this.days()/7)}var yr=Math.round,Pi={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function e1(f,h,w,E,D){return D.relativeTime(h||1,!!w,f,E)}function t1(f,h,w,E){var D=Bn(f).abs(),B=yr(D.as("s")),K=yr(D.as("m")),Se=yr(D.as("h")),Le=yr(D.as("d")),Xe=yr(D.as("M")),sn=yr(D.as("w")),br=yr(D.as("y")),Br=B<=w.ss&&["s",B]||B<w.s&&["ss",B]||K<=1&&["m"]||K<w.m&&["mm",K]||Se<=1&&["h"]||Se<w.h&&["hh",Se]||Le<=1&&["d"]||Le<w.d&&["dd",Le];return w.w!=null&&(Br=Br||sn<=1&&["w"]||sn<w.w&&["ww",sn]),Br=Br||Xe<=1&&["M"]||Xe<w.M&&["MM",Xe]||br<=1&&["y"]||["yy",br],Br[2]=h,Br[3]=+f>0,Br[4]=E,e1.apply(null,Br)}function n1(f){return f===void 0?yr:typeof f=="function"?(yr=f,!0):!1}function r1(f,h){return Pi[f]===void 0?!1:h===void 0?Pi[f]:(Pi[f]=h,f==="s"&&(Pi.ss=h-1),!0)}function i1(f,h){if(!this.isValid())return this.localeData().invalidDate();var w=!1,E=Pi,D,B;return typeof f=="object"&&(h=f,f=!1),typeof f=="boolean"&&(w=f),typeof h=="object"&&(E=Object.assign({},Pi,h),h.s!=null&&h.ss==null&&(E.ss=h.s-1)),D=this.localeData(),B=t1(this,!w,E,D),w&&(B=D.pastFuture(+this,B)),D.postformat(B)}var Cc=Math.abs;function Li(f){return(f>0)-(f<0)||+f}function ro(){if(!this.isValid())return this.localeData().invalidDate();var f=Cc(this._milliseconds)/1e3,h=Cc(this._days),w=Cc(this._months),E,D,B,K,Se=this.asSeconds(),Le,Xe,sn,br;return Se?(E=En(f/60),D=En(E/60),f%=60,E%=60,B=En(w/12),w%=12,K=f?f.toFixed(3).replace(/\.?0+$/,""):"",Le=Se<0?"-":"",Xe=Li(this._months)!==Li(Se)?"-":"",sn=Li(this._days)!==Li(Se)?"-":"",br=Li(this._milliseconds)!==Li(Se)?"-":"",Le+"P"+(B?Xe+B+"Y":"")+(w?Xe+w+"M":"")+(h?sn+h+"D":"")+(D||E||f?"T":"")+(D?br+D+"H":"")+(E?br+E+"M":"")+(f?br+K+"S":"")):"P0D"}var qe=Za.prototype;qe.isValid=JC,qe.abs=Aj,qe.add=Rj,qe.subtract=Dj,qe.as=Oj,qe.asMilliseconds=Xp,qe.asSeconds=Tj,qe.asMinutes=Fj,qe.asHours=Pj,qe.asDays=Lj,qe.asWeeks=Vj,qe.asMonths=Gj,qe.asQuarters=Bj,qe.asYears=Yj,qe.valueOf=Wj,qe._bubble=Mj,qe.clone=zj,qe.get=Hj,qe.milliseconds=Uj,qe.seconds=$j,qe.minutes=Xj,qe.hours=qj,qe.days=Zj,qe.weeks=Kj,qe.months=Jj,qe.years=Qj,qe.humanize=i1,qe.toISOString=ro,qe.toString=ro,qe.toJSON=ro,qe.locale=Op,qe.localeData=Fp,qe.toIsoString=L("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",ro),qe.lang=Tp,Q("X",0,0,"unix"),Q("x",0,0,"valueOf"),je("x",Yt),je("X",nc),ot("X",function(f,h,w){w._d=new Date(parseFloat(f)*1e3)}),ot("x",function(f,h,w){w._d=new Date(Ue(f))});return r.version="2.30.1",i(gt),r.fn=ce,r.min=$C,r.max=XC,r.now=qC,r.utc=v,r.unix=Sj,r.months=Ij,r.isDate=p,r.locale=Vr,r.invalid=y,r.duration=Bn,r.isMoment=A,r.weekdays=Ej,r.parseZone=jj,r.localeData=gr,r.isDuration=Ja,r.monthsShort=_j,r.weekdaysMin=Nj,r.defineLocale=cc,r.updateLocale=jC,r.locales=IC,r.weekdaysShort=kj,r.normalizeUnits=P,r.relativeTimeRounding=n1,r.relativeTimeThreshold=r1,r.calendarFormat=bS,r.prototype=ce,r.HTML5_FMT={DATETIME_LOCAL:"YYYY-MM-DDTHH:mm",DATETIME_LOCAL_SECONDS:"YYYY-MM-DDTHH:mm:ss",DATETIME_LOCAL_MS:"YYYY-MM-DDTHH:mm:ss.SSS",DATE:"YYYY-MM-DD",TIME:"HH:mm",TIME_SECONDS:"HH:mm:ss",TIME_MS:"HH:mm:ss.SSS",WEEK:"GGGG-[W]WW",MONTH:"YYYY-MM"},r}))})(Oo)),Oo.exports}var KV=QV();const Co=Qr(KV);function Pg({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r,expanded:i=!0}){const[a,o]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(i),p=v=>{r(["issue","attachment","status_mail"]),r(["issue","status_mail"])},g=()=>n.filter(v=>v.issue.id===e.id),m=()=>{o(s.jsx(Wa,{equipment:t,showModal:!0,onClose:v=>{c(!1),v&&p()},issue:e,attachments:g()})),c(!0)};return s.jsxs("div",{className:"p-3 mb-4 border-bottom",children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-2",children:[s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(Ft,{bg:"dark",children:"Issue"}),s.jsx("h4",{className:e.date_closed?"text-danger mb-0":"mb-0",children:e.date_closed?s.jsx("s",{children:e.issue}):e.issue})]}),s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(ie,{variant:"outline-primary",size:"sm",onClick:()=>d(v=>!v),"aria-label":"Toggle Details",children:u?"Hide Details":"Show Details"}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:m,"aria-label":"Edit Issue",children:"Edit"})]})]}),u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mb-2",children:s.jsx(Ai,{children:e.description})}),s.jsx("p",{className:"mb-3",children:e.actions}),s.jsxs("div",{className:"d-flex flex-wrap gap-4 text-muted",children:[s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Creator"}),s.jsx("div",{className:"text-body",children:e.owner.full_name})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Date Created"}),s.jsx("div",{className:"text-body",children:Co(e.date_created).format("DD MMMM YYYY")})]}),e.date_closed&&s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Date Closed"}),s.jsx("div",{className:"text-body",children:Co(e.date_closed).format("DD MMMM YYYY")})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Forecast Up"}),s.jsx("div",{className:"text-body",children:Co(e.forecast_up).format("DD MMMM YYYY")})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Issue Type"}),s.jsxs("div",{className:"text-body",children:[e.issue_type===_r.DEFAULT&&"Issue",e.issue_type===_r.ESCALATION&&"Escalation",e.issue_type===_r.PRIORITY&&"Priority"]})]}),s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Attachments"}),s.jsx("div",{className:"text-body",children:e.attachments})]}),e.updated_by&&s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Last Update By"}),s.jsx("div",{className:"text-body",children:e.updated_by.full_name})]}),e.last_update&&s.jsxs("div",{children:[s.jsx("small",{className:"text-muted",children:"Last Update"}),s.jsx("div",{className:"text-body",children:Co(e.last_update).format("DD MMMM YYYY")})]})]})]}),l&&a]})}function Lg({reservations:e}){if(!e||e.length<1)return s.jsx(s.Fragment,{});const t=e[0];return s.jsx(fs,{placement:"top",overlay:s.jsxs(yi,{id:`tooltip-${t.id}`,children:[s.jsx("h5",{children:t.title}),s.jsx("p",{children:e[0].active?"Currently active":`Upcoming in: ${ye(e[0].start).format("DD MMMM YYYY")}`}),s.jsx("p",{children:e[1]?`Next upcoming reservation in: ${ye(e[1].start).format("DD MMMM YYYY")}`:"No next upcoming reservations"})]}),children:s.jsxs(Ft,{bg:e[0].active?"info":"dark",children:["Reserved by: ",e[0].user.full_name]})})}function eG({equipment:e,modules:t,issues:n,issueAttachments:r,ecnNotes:i,ecnAttachments:a,reloadQueryFn:o,showIssues:l,reservations:c}){const[u,d]=x.useState(null),[p,g]=x.useState(!1),[m,v]=x.useState(null),[I,C]=x.useState(!1),[b,_]=x.useState([]),[y,S]=x.useState(void 0),[j,N]=x.useState([]),[k,A]=x.useState([]),F=T=>{o(["ecn","attachment","status_mail"]),N([...j,T])},L=T=>{o(["issue","status_mail"]),o(["issue","attachment","status_mail"]),A([...k,T])};x.useEffect(()=>{N(i),A(n),_(t.filter(T=>T.equipment.id===e.id&&!T.type.is_main_tool)),S(t.findLast(T=>T.equipment.id===e.id&&T.type.is_main_tool))},[i,n,e,t]);const Y=T=>j.filter(V=>V.module_id===T),G=T=>k.filter(V=>V.module_id===T),X=()=>{v(s.jsx(Pl,{equipment:e,showModal:!0,onClose:T=>{C(!1),T&&F(T)}})),C(!0)},H=()=>{d(s.jsx(Wa,{equipment:e,showModal:!0,onClose:T=>{g(!1),T&&L(T)}})),g(!0)};return s.jsxs("div",{className:"card mb-4",children:[s.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsxs("h4",{className:"mb-0",children:[e.number," - ",e.name]}),y&&s.jsx(Jr,{module:y}),y&&s.jsx(Lg,{reservations:c.filter(T=>T.modules.some(V=>V.id===y.id))})]}),s.jsxs(Na,{as:wx,title:"Action",id:"bg-nested-dropdown",children:[s.jsx(at.Item,{eventKey:"1",onClick:X,children:"New ECN"}),l!==1&&s.jsx(at.Item,{eventKey:"1",onClick:H,children:"New Issue"})]})]}),s.jsx("div",{className:"card-body",children:s.jsxs(Un,{children:[y&&s.jsx(Pt,{xs:12,md:b.length>0?6:12,children:s.jsx(Ye,{className:"mb-3",children:s.jsxs(Ye.Body,{children:[s.jsxs(Ye.Title,{className:"d-flex align-items-center",children:[s.jsx("span",{children:"Main module"}),s.jsx("div",{className:"ms-2"})]}),s.jsxs("div",{className:"mt-3",children:[Y(y.id).map((T,V)=>s.jsx(Tg,{ecn:T,equipment:e,ecnAttachments:a,reloadQueryFn:o,expanded:!0},V)),l!==1&&G(y.id).map((T,V)=>s.jsx(Pg,{issue:T,equipment:e,issueAttachments:r,reloadQueryFn:o,expanded:l!==3},V))]})]})})}),b.length>0&&s.jsx(Pt,{xs:12,md:y?6:12,children:b.map((T,V)=>s.jsx(Ye,{className:"mb-3",children:s.jsxs(Ye.Body,{children:[s.jsx(Ye.Title,{className:"d-flex align-items-center",children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("span",{children:T.name}),s.jsx(Jr,{module:T}),s.jsx(Lg,{reservations:c.filter(Z=>Z.modules.some(ne=>ne.id===T.id))})]})}),s.jsxs("div",{className:"mt-3",children:[Y(T.id).map((Z,ne)=>s.jsx(Tg,{ecn:Z,equipment:e,ecnAttachments:a,reloadQueryFn:o,expanded:!0},ne)),l!==1&&G(T.id).map((Z,ne)=>s.jsx(Pg,{issue:Z,equipment:e,issueAttachments:r,reloadQueryFn:o,expanded:l!==3},ne))]})]})},V))})]})}),I&&m,p&&u]})}const V0=({showModal:e,onClose:t,message:n})=>{const{register:r,handleSubmit:i,setValue:a,reset:o,control:l}=tn({defaultValues:{title:n?.title,description:n?.description,rooms:n?.rooms,type:n?.type,owner:n?.owner}}),[c,u]=x.useState([]),[d,p]=x.useState([]),[g,m]=x.useState(""),v=()=>document.documentElement.getAttribute("data-bs-theme")==="dark",I={control:y=>({...y,backgroundColor:v()?"#212529":y.backgroundColor,borderColor:v()?"#495057":y.borderColor,color:v()?"#fff":y.color}),menu:y=>({...y,backgroundColor:v()?"#212529":y.backgroundColor}),option:(y,S)=>({...y,backgroundColor:v()?S.isSelected?"#0d6efd":S.isFocused?"#343a40":"#212529":y.backgroundColor,color:v()?"#fff":y.color}),singleValue:y=>({...y,color:v()?"#fff":y.color}),multiValue:y=>({...y,backgroundColor:v()?"#343a40":y.backgroundColor}),multiValueLabel:y=>({...y,color:v()?"#fff":y.color}),input:y=>({...y,color:v()?"#fff":y.color})};let{statusMail:C}=x.useContext(Tl);x.useEffect(()=>{te.get("/list/room").then(y=>{const j=(y.data._embedded.items||[]).map(N=>({value:N,label:N.name}));u(j)}).catch(y=>{console.error("Error fetching rooms:",y),m("Error fetching rooms:"+y)}),te.get("/list/location/message/type").then(y=>{const S=C.filter.messageType,N=(y.data._embedded.items||[]).filter(k=>S.includes(k.id.toString())).map(k=>({value:k,label:k.type}));p(N),a("type",n?.type||N[0].value)}).catch(y=>{console.error("Error fetching message types:",y),m("Error fetching message types:"+y)})},[]);const b=y=>{if(y.title){if(y?.owner.value===void 0&&n?.owner===void 0)return"owner";if(y.rooms===void 0||y.rooms.map(S=>S.id).length<=0)return"room";if(!y.type)return"type"}else return"title";return""},_=async y=>{const S=b(y);if(S!==""){m("Please fill: "+S);return}try{const j={title:y.title,description:y.description,owner:y?.owner.value||n?.owner.id,type:y.type.id,rooms:y.rooms.map(k=>k.id)};let N;if(n?N=await te.patch(`/update/location/message/${n.id}`,j):N=await te.post("/create/location/message",j),N){t(N?.data),o();return}console.error("No response received"),m("No response received")}catch(j){console.error("Error submitting the form:",j),m("Error submitting the form:"+j)}};return s.jsx(ve,{show:e,size:"lg",centered:!0,onHide:()=>t(n),children:s.jsxs(W,{onSubmit:i(_),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Edit status mail message"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Title"}),s.jsx(W.Control,{type:"text",placeholder:"Enter the title",...r("title")})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Message"}),s.jsx(W.Control,{as:"textarea",rows:3,placeholder:"Give the message",...r("description")})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Owner"}),s.jsx(Fa,{control:l,...r("owner",{required:"Owner is required"}),name:"owner"})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Rooms"}),s.jsx(Fn,{name:"rooms",control:l,render:({field:y})=>s.jsx($u,{isMulti:!0,options:c,classNamePrefix:"react-select",placeholder:"Select one or more rooms",value:c.filter(S=>y.value?.some(j=>j.id===S.value.id)),onChange:S=>y.onChange(S.map(j=>j.value)),styles:I})})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Type"}),s.jsx(Fn,{name:"type",control:l,render:({field:y})=>s.jsx($u,{options:d,classNamePrefix:"react-select",placeholder:"Select a message type",value:d.find(S=>S.value.id===y.value?.id)||null,onChange:S=>y.onChange(S?.value),styles:I})})]})]}),s.jsxs(ve.Footer,{children:[g!=""&&s.jsx("span",{className:"text-danger",children:g}),s.jsx(ie,{variant:"secondary",onClick:()=>t(n),children:"Cancel"}),s.jsx(ie,{variant:"primary",type:"submit",children:n?"Update Message":"Create Message"})]})]})})};function tG({message:e}){const[t,n]=x.useState(null),[r,i]=x.useState(!1),[a,o]=x.useState(e),l=u=>{o({...a,...u})},c=()=>{n(s.jsx(V0,{showModal:!0,onClose:u=>{i(!1),u&&l(u)},message:a})),i(!0)};return s.jsxs("div",{className:"card mb-4",children:[s.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(Ft,{bg:"dark",children:a.type.type}),s.jsx("h5",{className:"mb-0",children:a.title})]}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:c,children:"Edit"})]}),s.jsx("div",{className:"card-body",children:s.jsx(Ai,{children:a.description})}),s.jsx("div",{className:"card-footer bg-transparent",children:s.jsxs("small",{className:"text-muted d-flex flex-wrap gap-3",children:[s.jsxs("span",{children:["Created: ",ye(a.date_created).format("DD MMM YYYY")]}),a.last_update&&s.jsxs("span",{children:["Updated: ",ye(a.last_update).format("DD MMM YYYY")]}),a.rooms.length>0&&s.jsxs("span",{children:["Rooms:"," ",a.rooms.map((u,d)=>s.jsxs(x.Fragment,{children:[d>0&&", ",u.name]},u.id))]}),s.jsxs("span",{children:["Owner: ",a.owner.full_name]})]})}),r&&t]})}function nG({messageList:e,refetchFn:t}){const[n,r]=x.useState(null),[i,a]=x.useState(!1),o=()=>{r(s.jsx(V0,{showModal:!0,onClose:l=>{a(!1),t()}})),a(!0)};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"d-flex gap-3",children:[s.jsx("h2",{children:"Messages"}),s.jsx("div",{children:s.jsx(ie,{variant:"secondary",onClick:o,children:"New message"})})]}),e.map((l,c)=>s.jsx("div",{children:s.jsx(tG,{message:l})},l.id)),i&&n]})}function rG({issue:e,moduleName:t,issueAttachments:n,equipment:r,reloadQueryFn:i}){const[a,o]=x.useState(null),[l,c]=x.useState(!1),u=g=>{i(["issue","status_mail"]),i(["issue","attachment","status_mail"])},d=()=>n.filter(g=>g.issue.id===e.id),p=()=>{if(!r){console.error("equipment is null in the table");return}c(!0),o(s.jsx(Wa,{equipment:r,showModal:!0,onClose:g=>{c(!1),g&&u()},issue:e,attachments:d()}))};return s.jsxs(s.Fragment,{children:[s.jsxs("tr",{className:"align-middle",children:[s.jsx("td",{className:"text-nowrap",children:t??"-"}),s.jsx("td",{children:e.issue}),s.jsx("td",{children:s.jsx(Ai,{children:e.description})}),s.jsx("td",{className:"text-nowrap",children:ye(e.forecast_up).format("DD MMMM YYYY")}),s.jsx("td",{className:"text-nowrap",children:e.owner.full_name}),s.jsx("td",{className:"text-center",children:s.jsx("button",{type:"button",className:"btn btn-sm btn-outline-light",onClick:p,children:"Edit"})})]},e.id),l&&a]})}function iG({issues:e,modules:t,issueAttachments:n,reloadQueryFn:r}){return s.jsx("div",{className:"table-responsive",children:s.jsxs("table",{className:"table table-hover table-striped table-bordered table-sm",children:[s.jsx("thead",{className:"bg-primary text-white",children:s.jsxs("tr",{children:[s.jsx("th",{scope:"col",children:"Module"}),s.jsx("th",{scope:"col",children:"Issue"}),s.jsx("th",{scope:"col",children:"Description"}),s.jsx("th",{scope:"col",children:"Forecast Up"}),s.jsx("th",{scope:"col",children:"Owner"}),s.jsx("th",{scope:"col",className:"text-center",children:"Actions"})]})}),s.jsx("tbody",{children:e.map(i=>s.jsx(rG,{issue:i,moduleName:t.find(a=>a.id===i.module_id)?.name,issueAttachments:n,equipment:t.find(a=>a.id===i.module_id)?.equipment,reloadQueryFn:r},i.id))})]})})}function sG({statusMail:e}){const[t,n]=x.useState(!1),[r,i]=x.useState(!1),a=async()=>{try{if(n(!0),!e.id||e.id<=0)throw new Error("Status Mail ID is not correctly set");const o={status_mail:e.id};await te.post("/send/status-mail",o),i(!0)}catch(o){console.error("Error sending status mail:",o),alert("Error sending status mail. Please try again.")}finally{n(!1)}};return s.jsx(ie,{variant:"primary",size:"sm",onClick:a,disabled:t,"aria-label":"Toggle Details",children:t?"Sending...":r?"Sending successful":"Send Status Mail"})}function aG(){let{statusMail:e}=x.useContext(Tl);const[t,n]=x.useState([]),r=Ae.useQueryClient(),i=Ae.useQueries({queries:[{queryKey:["equipment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Zg({statusMail:e})},{queryKey:["module","status_mail",JSON.stringify(e.filter)],queryFn:()=>xi({statusMail:e})},{queryKey:["ecn","status_mail",JSON.stringify(e.filter)],queryFn:()=>wd({statusMail:e})},{queryKey:["issue","status_mail",JSON.stringify(e.filter)],queryFn:()=>Kg({statusMail:e})},{queryKey:["messages","status_mail",JSON.stringify(e.filter)],queryFn:()=>C1({statusMail:e})},{queryKey:["ecn","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Jg({statusMail:e})},{queryKey:["issue","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Qg({statusMail:e})},{queryKey:["reservation","active","status_mail",JSON.stringify(e.filter)],queryFn:()=>To({which:"active"})},{queryKey:["reservation","upcoming","status_mail",JSON.stringify(e.filter)],queryFn:()=>To({which:"upcoming"})}]}),a=S=>{let j=S;j.push(JSON.stringify(e.filter)),r.refetchQueries({queryKey:j})},[o,l,c,u,d,p,g,m,v]=i,I=i.some(S=>S.isLoading),C=i.some(S=>S.isError),b=i.every(S=>S.isSuccess);x.useEffect(()=>{b&&n(o.data.items)},[b]);const _=()=>{if(!t.length)return s.jsx("p",{children:"No equipment available."});t.sort((k,A)=>e.classification===si.ROOM?k.room.name.localeCompare(A.room.name):k.area&&A.area&&e.classification===si.AREA?k.area.title.localeCompare(A.area.title):k.area&&A.area&&e.classification===si.AREA_PER_FACILITY?k.area.facility.title.localeCompare(A.area.facility.title)||k.area.title.localeCompare(A.area.title):0);let S,j=null,N="";return t.map((k,A)=>{const F=[];return e.classification===si.ROOM?k.room.name!==N&&(F.push(s.jsxs("h2",{children:["Room: ",k.room.name]},`room-${k.room.name}`)),N=k.room.name):e.classification===si.AREA?k.area&&k.area!==j&&(F.push(s.jsxs("h2",{children:["Area: ",k.area.title]},`area-${k.area.id}`)),j=k.area):e.classification===si.AREA_PER_FACILITY&&(k.area&&k.area.facility!==S&&(F.push(s.jsxs("h2",{children:["Facility: ",k.area.facility.title]},`facility-${k.area.facility.id}`)),S=k.area.facility),k.area&&k.area!==j&&(F.push(s.jsxs("h4",{children:["Area: ",k.area.title]},`area-${k.area.id}`)),j=k.area)),F.push(s.jsx(eG,{equipment:k,modules:l.data.items,issues:u.data.items,issueAttachments:g.data.items,ecnNotes:c.data.items,ecnAttachments:p.data.items,reloadQueryFn:a,showIssues:e.show_issues,reservations:e.show_reservations?m.data.items.concat(v.data.items):[]},A)),F})},y=()=>{const S=u.data.items.filter(j=>j.issue_type===2);return S.length===0?s.jsx(s.Fragment,{}):s.jsxs(s.Fragment,{children:[s.jsx("h2",{children:"Issues with priority"}),s.jsx(iG,{issues:S,modules:l.data.items,issueAttachments:g.data.items,reloadQueryFn:a})]})};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center",children:[s.jsxs("h1",{className:"display-4",children:["Status mail ",e.name]}),s.jsx("div",{children:s.jsx(sG,{statusMail:e})})]}),s.jsx("p",{children:e.subject}),I&&s.jsx(St,{variant:"info",children:"Loading status mail"}),C&&s.jsx(St,{variant:"danger",children:"Error loading status mail"}),b&&e.show_issues_with_priority&&y(),b&&d.data&&s.jsx(nG,{messageList:d.data.items,refetchFn:d.refetch}),b&&_()]})}function oG(e){if(!e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;const t=new Date(e);return isNaN(t.getTime())?null:t}function lG(e,t){const n=oG(e);if(!n)return"";const r=o=>o.toString().padStart(2,"0"),i={YYYY:n.getFullYear().toString(),YY:n.getFullYear().toString().slice(-2),MM:r(n.getMonth()+1),DD:r(n.getDate()),HH:r(n.getHours()),mm:r(n.getMinutes()),H:n.getHours().toString(),m:n.getMinutes().toString()};let a=t;return Object.keys(i).sort((o,l)=>l.length-o.length).forEach(o=>{a=a.replace(new RegExp(o,"g"),i[o])}),a}function ln(e,t="DD-MM-YY HH:mm"){return lG(e,t)}function rp({monitor:e}){const{environment:t}=Te.useParams(),[n]=Ae.useQueries({queries:[{queryKey:["requirement",e],queryFn:()=>ex({monitorId:e.id})}]});return n.isLoading?s.jsx("div",{children:"Loading requirements..."}):n.data?.items.map((r,i)=>{let a="bg-secondary-subtle";if(r.latest_result)for(let o=0;o<r.latest_result.values.length;o++){if(r.latest_result.values[o].value_is_valid===!1){a="bg-danger-subtle";break}if(r.latest_result.values[o].value_is_valid===!0){a="bg-success-subtle";break}}return s.jsx(Ye,{className:"mb-2 me-2",children:s.jsxs(Ye.Body,{className:a,children:[s.jsx(Ye.Title,{children:s.jsx(Te.Link,{to:`/${t}/operator/monitor/`+e.id,children:e.name})}),s.jsxs(Ye.Text,{children:[r.title,r.latest_result&&s.jsxs(s.Fragment,{children:["Latest measurement: ",ln(r.latest_result.date_created,"DD-MM-YY HH:mm")]})]})]})},i)})}const G0=({moduleId:e,size:t})=>{const[n,r]=x.useState(!1),[i,a]=x.useState(!1),[o,l]=x.useState("");function c(){te.create().post("create/equipment/module/changelog",{module:e,changelog:o}).finally(()=>{r(!1),a(!0),l("")})}const u=p=>{l(p.target.value)};function d(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>a(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Assist logged"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Assist was logged successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"primary",size:t,onClick:()=>r(!0),children:"Log assist"}),s.jsxs(ve,{show:n,size:"lg",onHide:()=>r(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Log assist"})}),s.jsx(ve.Body,{children:s.jsx(W,{children:s.jsxs(W.Group,{className:"mb-3",controlId:"modal.ControlTextarea1",children:[s.jsx(W.Label,{children:"Describe the assist"}),s.jsx(W.Control,{as:"textarea",rows:3,value:o,onChange:p=>u(p)})]})})}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",variant:"primary",onClick:()=>c(),children:"Log assist"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{r(!1)},children:"Close"})]})]}),s.jsx(d,{})]})},Ql=x.createContext({equipment:{},reloadEquipment:()=>{}});function cG({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r}){const[i,a]=x.useState(null),[o,l]=x.useState(!1),[c,u]=x.useState(e),d=m=>{r(["issue",t.name]),r(["issue","attachment",t.name]),u({...c,...m})},p=()=>n.filter(m=>m.issue.id===e.id),g=()=>{a(s.jsx(Wa,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},issue:c,attachments:p()})),l(!0)};return s.jsxs("div",{children:[s.jsxs(Ye,{className:"my-2",children:[s.jsxs(Ye.Body,{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs(Ye.Title,{children:[s.jsx(Ft,{bg:"dark",children:"Issue"})," ",c.issue]}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:g,children:"Edit"})]}),s.jsx(Ye.Text,{children:s.jsx(Ai,{children:c.description})})]}),s.jsxs(wn,{className:"list-group-flush",children:[c.date_created&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Created:"}),s.jsx("span",{className:"ms-1",children:ln(c.date_created,"DD-MM-YY HH:mm")})]}),c.owner&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Owner:"}),s.jsx("span",{className:"ms-1",children:c.owner.full_name})]}),c.updated_by&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Updated:"}),s.jsx("span",{className:"ms-1",children:c.updated_by.full_name}),s.jsxs("span",{className:"ms-1",children:["(",ln(c.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},c.module_id),o&&i]})}function uG({ecn:e,equipment:t,ecnAttachments:n,reloadQueryFn:r}){const[i,a]=x.useState(null),[o,l]=x.useState(!1),[c,u]=x.useState(e),d=m=>{r(["ecn",t.name]),r(["ecn","attachment",t.name]),u({...c,...m})},p=()=>n.filter(m=>m.ecn.id===e.id),g=()=>{a(s.jsx(Pl,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},ecn:c,attachments:p()})),l(!0)};return s.jsxs("div",{children:[s.jsxs(Ye,{className:"my-2",children:[s.jsxs(Ye.Body,{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs(Ye.Title,{children:[s.jsx(Ft,{bg:"dark",children:"ECN"})," ",e.ecn]}),s.jsx(ie,{variant:"secondary",size:"sm",onClick:g,children:"Edit"})]}),s.jsx(Ye.Text,{children:s.jsx(Ai,{children:e.description})})]}),s.jsxs(wn,{className:"list-group-flush",children:[c.date_created&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Created:"}),s.jsx("span",{className:"ms-1",children:ln(c.date_created,"DD-MM-YY HH:mm")})]}),c.owner&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Owner:"}),s.jsx("span",{className:"ms-1",children:c.owner.full_name})]}),c.updated_by&&s.jsxs(wn.Item,{className:"d-flex align-items-center",children:[s.jsx("span",{className:"text-muted",children:"Updated:"}),s.jsx("span",{className:"ms-1",children:c.updated_by.full_name}),s.jsxs("span",{className:"ms-1",children:["(",ln(c.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},e.module_id),o&&i]})}function dG(){const{id:e}=Te.useParams(),[t,n]=x.useState([]),r=Ae.useQueries({queries:[{queryKey:["service","equipment",e],queryFn:()=>P1({equipmentId:Number(e)})}]}),[i]=r,a=r.some(u=>u.isLoading),o=r.some(u=>u.isError),l=r.every(u=>u.isSuccess);if(x.useEffect(()=>{l&&n(i.data.items)},[l,i.data]),a)return s.jsx("div",{children:"Loading..."});if(o)return s.jsx("div",{children:"Error loading services."});const c=u=>{if(u<60)return`${u} min`;const d=Math.floor(u/60),p=u%60;return`${d}h ${p>0?`${p}min`:""}`.trim()};return i.data.items.length===0?s.jsxs("div",{children:[s.jsx("h2",{children:"Services"}),s.jsx(St,{variant:"info",children:"No services found"})]}):s.jsxs("div",{children:[s.jsx("h2",{children:"Services"}),s.jsxs(Ht,{striped:!0,bordered:!0,hover:!0,responsive:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Id"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Type"}),s.jsx("th",{children:"Team"}),s.jsx("th",{children:"Department"}),s.jsx("th",{children:"Duration"}),s.jsx("th",{children:"Report2"})]})}),s.jsx("tbody",{children:t.map(u=>s.jsxs("tr",{children:[s.jsx("td",{children:u.id}),s.jsx("td",{children:s.jsx("a",{href:`/${window.location.pathname.split("/")[1]}/service/details/${u.id}/general.html`,children:u.name})}),s.jsx("td",{children:u.type?.name||"N/A"}),s.jsx("td",{children:u.team?.name||"N/A"}),s.jsx("td",{children:u.department?.name||"N/A"}),s.jsx("td",{children:c(u.minutes_needed_for_service)}),s.jsx("td",{children:u.latest_event_report_id&&s.jsx("a",{className:"btn btn-primary btn-sm",href:`/${window.location.pathname.split("/")[1]}/service/event/report/${u.latest_event_report_id}/results`,children:"View Report"})})]},u.id))})]})]})}function fG(){const{environment:e}=Te.useParams(),{equipment:t}=x.useContext(Ql),n=Ae.useQueryClient(),[r,i]=x.useState(null),[a,o]=x.useState(!1),[l,c]=x.useState(null),[u,d]=x.useState(!1),[p,g,m,v,I,C,b]=Ae.useQueries({queries:[{queryKey:["runs",t.name,e],queryFn:()=>R1({firstUnfinishedStepEquipment:t,environment:e})},{queryKey:["monitors",t.name],queryFn:()=>tx({equipment:t})},{queryKey:["ecn",t.name],queryFn:()=>wd({equipment:t})},{queryKey:["issue",t.name],queryFn:()=>Kg({equipment:t})},{queryKey:["module",t.name],queryFn:()=>xi({equipment:t})},{queryKey:["ecn","attachment",t.name],queryFn:()=>Jg({equipment:t})},{queryKey:["issue","attachment",t.name],queryFn:()=>Qg({equipment:t})}]}),_=k=>{n.invalidateQueries({queryKey:k})},y=k=>k?m.data?.items.filter(A=>A.module_id===k):[],S=k=>k?v.data?.items.filter(A=>A.module_id===k):[],j=()=>{c(s.jsx(Pl,{equipment:t,showModal:!0,onClose:()=>{d(!1),setTimeout(()=>{_(["ecn",t.name]),_(["ecn","attachment",t.name])},100)}})),d(!0)},N=()=>{i(s.jsx(Wa,{equipment:t,showModal:!0,onClose:()=>{o(!1),setTimeout(()=>{_(["issue",t.name]),_(["issue","attachment",t.name])},100)}})),o(!0)};return s.jsxs(Ii,{fluid:!0,children:[s.jsx("div",{className:"d-flex justify-content-left",children:g.data?.items&&g.data.items.map((k,A)=>s.jsx(rp,{monitor:k},A))}),s.jsxs(Un,{children:[s.jsxs(Pt,{md:8,children:[s.jsx("h2",{children:"Runs"}),p.isLoading&&s.jsx("div",{children:"Loading..."})," ",p.isError&&s.jsx("div",{children:"Error..."}),p.isFetched&&p.data&&p.data?.items.length===0&&s.jsx(St,{variant:"info",children:"No runs found"}),p.isFetched&&p.data&&p.data?.items.length>0&&s.jsxs(Ht,{striped:!0,bordered:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Run"}),s.jsx("th",{children:"Priority"}),s.jsx("th",{children:"Hold Code"}),s.jsx("th",{children:"Batch Card"}),s.jsx("th",{children:"Project"})]})}),s.jsx("tbody",{children:p.data?.items.map((k,A)=>s.jsxs("tr",{children:[s.jsxs("td",{children:[k.first_unfinished_step&&s.jsx(Te.Link,{to:`/${e}/operator/run/step/${k.first_unfinished_step.id}`,children:k.name}),k.first_unfinished_step===void 0&&k.last_finished_step&&s.jsx(Te.Link,{to:`/${e}/operator/run/step/${k.last_finished_step.id}`,children:k.name})]}),s.jsxs("td",{children:[k.priority&&s.jsx("span",{className:"badge",style:{backgroundColor:k.priority.priority.back_color,color:k.priority.priority.front_color},children:k.priority.priority.code}),!k.priority&&s.jsx("span",{className:"badge bg-info",children:"NORMAL"})]}),s.jsx("td",{children:k.hold_code&&s.jsx("span",{className:"badge handle",style:{backgroundColor:k.hold_code.hold_code.back_color,color:k.hold_code.hold_code.front_color},children:k.hold_code.hold_code.code})}),s.jsx("td",{children:k.batch_card&&k.batch_card.content&&s.jsx("span",{className:"text-danger",children:k.batch_card.content})}),s.jsx("td",{children:k.project.name})]},A))})]}),s.jsx(dG,{})]}),s.jsxs(Pt,{md:4,children:[s.jsx("h2",{children:"Assistance"}),I.data?.items.map((k,A)=>s.jsxs(x.Fragment,{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("h3",{children:k.type.is_main_tool?"Main tool":k.name}),s.jsx("div",{children:s.jsx(Jr,{module:k})})]}),s.jsxs("div",{className:"pb-lg-5",children:[s.jsx("div",{className:"d-flex justify-content-between",children:s.jsxs("div",{className:"d-flex gap-2",children:[s.jsx("div",{children:s.jsx(ie,{variant:"primary",size:"sm",onClick:N,children:"New Issue"})}),s.jsx("div",{children:s.jsx(ie,{variant:"primary",size:"sm",onClick:j,children:"New ECN"})}),s.jsx("div",{children:k.type.is_main_tool&&s.jsx(G0,{size:"sm",moduleId:k.id})})]})}),y(k.id)?.map((F,L)=>s.jsx(uG,{ecn:F,equipment:t,ecnAttachments:C.data?.items??[],reloadQueryFn:_},`ecn-${A}-${L}`)),S(k.id)?.map((F,L)=>s.jsx(cG,{issue:F,equipment:t,issueAttachments:b.data?.items??[],reloadQueryFn:_},`issue-${A}-${L}`))]})]},A))]})]}),u&&l,a&&r]})}const pG=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&qp({id:parseInt(n)}).then(t)},[n,e]);function r(){qp({id:parseInt(n)}).then(t)}return{equipment:e,setEquipment:t,reloadEquipment:r}};function B0({children:e}){const{equipment:t,reloadEquipment:n}=pG();return t===null?s.jsx(jn,{children:s.jsx(zt,{message:"Loading equipment..."})}):s.jsx(jn,{children:s.jsx(Ql.Provider,{value:{equipment:t,reloadEquipment:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function mG(){const{equipment:e}=x.useContext(Ql),t=Ae.useQueries({queries:[{queryKey:["activeReservationQuery",e],queryFn:()=>To({equipment:e,which:"active"})},{queryKey:["upcomingReservationQuery",e],queryFn:()=>To({equipment:e,which:"upcoming"})},{queryKey:["modules",e],queryFn:()=>xi({equipment:e})}]}),[n,r,i]=t,a=t.some(l=>l.isLoading);t.some(l=>l.isError);const o=t.every(l=>l.isSuccess);return a?s.jsx("div",{children:"Loading..."}):(i.data?.items.findLast(l=>l.type.is_main_tool),o&&s.jsxs("div",{className:"d-flex align-items-center justify-content-between mb-3",children:[s.jsxs("h1",{className:"display-4",children:[e.name," Operator Dashboard"]}),s.jsxs("div",{children:[n.data?.items.map((l,c)=>s.jsxs("div",{className:"mx-2 p-2 rounded border-danger",style:{backgroundColor:l.color},children:[s.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Active reservation",s.jsx("br",{}),"Until ",ln(l.end,"DD-MM-YY HH:mm")," by ",l.user.full_name]},c)),r.data?.items.map((l,c)=>s.jsxs("div",{className:"mx-2 p-2 rounded border-success border-2",style:{backgroundColor:l.color},children:[s.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Next reservation",s.jsx("br",{}),ln(l.start,"DD-MM-YY HH:mm"),s.jsx("br",{}),l.user.full_name]},c))]})]}))}function hG(){return s.jsxs(B0,{children:[s.jsx(mG,{}),s.jsx(Te.Outlet,{})]})}function gG({children:e}){const{id:t}=Te.useParams(),n=Ae.useQuery({queryKey:["statusMail",t],queryFn:()=>x1({id:parseInt(t)}),enabled:!!t});return n.isLoading||n.isFetching?s.jsx(jn,{children:s.jsx(zt,{message:"Loading status mail..."})}):s.jsx(jn,{children:s.jsx(Tl.Provider,{value:{statusMail:n.data},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}const Y0=()=>sx();function xG(e){const[t,n]=x.useState(!0),[r,i]=x.useState(null),[a,o]=x.useState(!1),l=()=>{n(!1),o(!0)};return x.useEffect(()=>{if(!document){const p=new Error(`[ScriptLoadingError] document not defined when attempting to load ${e}`);i(p);return}const c=document.querySelector(`script[src="${e}"]`);if(c?.dataset.loaded){l();return}const u=c||document.createElement("script");c||(u.src=e);const d=()=>{u.dataset.loaded="1",l()};u.addEventListener("load",d),u.addEventListener("error",p=>{console.error("Failed to load script:",e,p);const g=new Error(`[ScriptLoadingError] Failed to load script: ${e}`);i(g)}),c||document.head.append(u)},[]),{isLoading:t,error:r,isSuccess:a}}const vG=e=>e&&e.charts,Vg=(e,t)=>{const{controls:n,toolbarItems:r,getChartEditor:i}=e;return t&&t.charts&&t.visualization&&t.visualization.ChartWrapper&&t.visualization.Dashboard&&(!n||t.visualization.ChartWrapper)&&(!i||t.visualization.ChartEditor)&&(!r||t.visualization.drawToolbar)},yG=e=>window.google;function bG(e){const{chartVersion:t="current",chartPackages:n=["corechart","controls"],chartLanguage:r="en",mapsApiKey:i}=e,[a,o]=x.useState(null),[l,c]=x.useState(null),[u,d]=x.useState(null),{isLoading:p,error:g,isSuccess:m}=xG(e.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return x.useEffect(()=>{if(!m)return;const v=yG();if(!vG(v)){const I=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");c(I);return}if(Vg(e,v)){o(v);return}v.charts.load(t,{packages:n,language:r,mapsApiKey:i}),v.charts.setOnLoadCallback(()=>{if(!Vg(e,v)){const I=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(I),d(I);return}o(v)})},[m]),{error:g||l||u,isLoading:p,google:a}}const W0={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},wG=e=>{const{isReady:t,chartControls:n,filter:r}=e;return!t||!n||!n?.length?null:x.createElement(x.Fragment,null,n.filter(i=>{let{controlProp:a,control:o}=i;return r?r({control:o,controlProp:a}):!0}).map(i=>{let{control:a}=i;return x.createElement("div",{key:a.getContainerId(),id:a.getContainerId()})}))};let Gg=0;const z0=()=>(Gg+=1,`reactgooglegraph-${Gg}`),Kn=class Kn{};kn(Kn,"initializeControls",t=>{for(let n=0;n<t.length;n+=1){const{controlType:r,options:i,controlWrapperParams:a}=t[n].controlProp;a&&"state"in a&&t[n].control.setState(a.state),t[n].control.setOptions(i),t[n].control.setControlType(r)}}),kn(Kn,"listenToControlEvents",(t,n)=>{const{google:r}=n;return t.flatMap(i=>{const{control:a,controlProp:o}=i,{controlEvents:l=[]}=o;return l.map(c=>{const{callback:u,eventName:d}=c;return r.visualization.events.addListener(a,d,function(){for(var p=arguments.length,g=new Array(p),m=0;m<p;m++)g[m]=arguments[m];u({chartWrapper:null,controlWrapper:a,props:n,google:r,eventArgs:g})})})})}),kn(Kn,"createControlId",t=>{let n;return typeof t>"u"?n=`googlechart-control-${z0()}`:n=t,n}),kn(Kn,"createChartControls",t=>{const{controls:n,google:r}=t;return n?n.map((i,a)=>{const{controlID:o,controlType:l,options:c,controlWrapperParams:u}=i,d=Kn.createControlId(o);return{controlProp:i,control:new r.visualization.ControlWrapper({containerId:d,controlType:l,options:c,...u})}}):null}),kn(Kn,"addControls",t=>{const{chartWrapper:n,chartDashboard:r}=t,i=Kn.createChartControls(t);return!i||!r||!n?null:(r.bind(i.map(a=>{let{control:o}=a;return o}),n),Kn.initializeControls(i),i)});let fl=Kn;const CG=e=>{const[t,n]=$.useState(null);return[$.useMemo(()=>!t||!e?null:e.map((i,a)=>{const o=t[a];return o?{controlProp:i,control:o}:void 0}).flatMap(i=>i?[i]:[]),[t,e]),n]},SG=(e,t)=>{$.useEffect(()=>{const n=fl.listenToControlEvents(e??[],t);return()=>{n.forEach(r=>{t.google.visualization.events.removeListener(r)})}},[e,t])},jG=e=>{const[t,n]=CG(e.controls);return SG(t??[],e),{addControls:i=>{const a=fl.addControls(i);n(a?.map(o=>o.control)??null)},renderControl:i=>{const{chartWrapper:a,chartDashboard:o}=e;return $.createElement(wG,{...e,isReady:!!(a&&o),chartControls:t,filter:i})}}},IG=e=>{const t=$.useRef(null);return{chartId:(()=>{const{graphID:i,graph_id:a}=e,o=i||a;let l;return o?l=o:l=t.current||z0(),t.current=l,t.current})()}},_G=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],EG=async function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((r,i)=>{const a=`${n.headers?`headers=${n.headers}`:"headers=0"}`,o=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,l=`${n.gid?`&gid=${n.gid}`:""}`,c=`${n.sheet?`&sheet=${n.sheet}`:""}`,u=`${n.access_token?`&access_token=${n.access_token}`:""}`,d=`${a}${l}${c}${o}${u}`,p=`${t}/gviz/tq?${d}`;new e.visualization.Query(p).send(m=>{m.isError()?i(`Error in query: ${m.getMessage()} ${m.getDetailedMessage()}`):r(m.getDataTable())})})},kG="#CCCCCC",An=class An{};kn(An,"grayOutHiddenColumnsLabel",(t,n)=>{const{googleChartWrapper:r,options:i}=t;if(!r){console.error("googleChartWrapper is not defined");return}const a=r.getDataTable();if(!a)return;const o=a.getNumberOfColumns();if(n.length>0===!1)return;const c=Array.from({length:o-1}).map((u,d)=>{const p=An.getColumnId(a,d+1);return n.includes(p)?kG:i&&i.colors?i.colors[d]:_G[d]});r.setOptions({...i,colors:c}),r.draw()}),kn(An,"listenToLegendToggle",(t,n)=>{const[r,i]=n,{google:a,googleChartWrapper:o}=t;if(!o){console.error("googleChartWrapper is not defined");return}return a.visualization.events.addListener(o,"select",()=>{const c=o.getChart().getSelection(),u=o.getDataTable();if(c.length===0||c[0].row!==null||!u)return;const d=c[0].column,p=An.getColumnId(u,d);r?.includes(p)?i(g=>[...g.filter(m=>m!==p)]):i(g=>[...g,p])})}),kn(An,"draw",async t=>{const{data:n,diffdata:r,rows:i,columns:a,options:o,chartType:l,formatters:c,spreadSheetUrl:u,spreadSheetQueryParameters:d,googleChartDashboard:p,googleChartWrapper:g,google:m,hiddenColumns:v,legendToggle:I,legend_toggle:C}=t;if(!g){console.error("draw was called with googleChartWrapper = null");return}let b,_=null;if(r){const k=m.visualization.arrayToDataTable(r.old),A=m.visualization.arrayToDataTable(r.new);_=m.visualization[l].prototype.computeDiff(k,A)}n?n instanceof m.visualization.DataTable?b=n:Array.isArray(n)?b=m.visualization.arrayToDataTable(n):b=new m.visualization.DataTable(n):i&&a?b=m.visualization.arrayToDataTable([a,...i]):u?b=await EG(m,u,d):b=m.visualization.arrayToDataTable([]);const y=b.getNumberOfColumns(),S=Array(y).fill(0).map((k,A)=>{const F=An.getColumnId(b,A);return v.includes(F)?{label:b.getColumnLabel(A),type:b.getColumnType(A),calc:()=>null}:A}),j=g.getChart();g.getChartType()==="Timeline"&&j&&j.clearChart(),g.setChartType(l),g.setOptions(o||{});const N=new m.visualization.DataView(b);N.setColumns(S),g.setDataTable(N),g.draw(),p&&p.draw(b),_&&(g.setDataTable(_),g.draw()),c&&(An.applyFormatters({dataTable:b,formatters:c,google:m}),g.setDataTable(b),g.draw()),(I===!0||C===!0)&&An.grayOutHiddenColumnsLabel(t,v)}),kn(An,"getColumnId",(t,n)=>t.getColumnId(n)||t.getColumnLabel(n)),kn(An,"applyFormatters",t=>{let{dataTable:n,formatters:r,google:i}=t;for(let a of r)switch(a.type){case"ArrowFormat":{new i.visualization.ArrowFormat(a.options).format(n,a.column);return}case"BarFormat":{new i.visualization.BarFormat(a.options).format(n,a.column);return}case"ColorFormat":{const o=new i.visualization.ColorFormat(a.options),{ranges:l}=a;if(l)for(let c of l)o.addRange(...c);o.format(n,a.column);return}case"DateFormat":{new i.visualization.DateFormat(a.options).format(n,a.column);return}case"NumberFormat":{new i.visualization.NumberFormat(a.options).format(n,a.column);return}case"PatternFormat":{new i.visualization.PatternFormat(a.options).format(n,a.column);return}default:{console.warn(`Unknown formatter type: ${a.type}`);return}}});let sa=An;const NG=e=>{const{google:t,googleChartWrapper:n,googleChartDashboard:r}=e,[i,a]=$.useState([]);$.useEffect(()=>{n&&sa.draw({...e,hiddenColumns:i,googleChartWrapper:n,googleChartDashboard:r,google:t})},[i,e.data,e.rows,e.columns,e.options,e.chartLoaderScriptUrl,e.chartType,e.formatters,e.spreadSheetUrl,e.spreadSheetQueryParameters,e.legendToggle,e.legend_toggle]);const o=()=>{const{googleChartWrapper:u}=e;u&&u.draw()},l=u=>{const d=[],{legendToggle:p,legend_toggle:g}=e;if(sa.draw({...e,hiddenColumns:i,googleChartWrapper:u,googleChartDashboard:r,google:t}),window.addEventListener("resize",o),g||p){const m=sa.listenToLegendToggle(e,[i,a]);m&&d.push(m)}return d},c=(u,d)=>{window.removeEventListener("resize",o),d.forEach(p=>{t.visualization.events.removeListener(p)}),u.getChartType()==="Timeline"&&u.getChart()&&u.getChart().clearChart()};$.useEffect(()=>{if(!n)return;const u=l(n);return()=>{c(n,u)}},[n,l,c])},AG=e=>{const{chartEvents:t,google:n,googleChartWrapper:r}=e;if(t){if(!r){console.warn("listenToEvents was called before chart wrapper ready.");return}return t.map(i=>{let{eventName:a,callback:o}=i;return n.visualization.events.addListener(r,a,function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];o({chartWrapper:r,props:e,google:n,eventArgs:c})})})}},RG=e=>{x.useEffect(()=>{if(!e.googleChartWrapper)return;const t=AG(e);return()=>{t?.forEach(n=>{e.google.visualization.events.removeListener(n)})}},[e])},DG=e=>{const[t,n]=$.useState(null),[r,i]=$.useState(null),{addControls:a,renderControl:o}=jG({...e,chartDashboard:r,chartWrapper:t});RG({...e,googleChartWrapper:t});const{chartId:l}=IG(e),c=$.useRef(null),u=$.useRef(null);$.useEffect(()=>{const{options:b,google:_,chartType:y,chartWrapperParams:S,toolbarItems:j,getChartEditor:N,getChartWrapper:k,onLoad:A}=e,F={chartType:y,options:b,containerId:l,...S},L=new _.visualization.ChartWrapper(F);L.setOptions(b||{}),k?.(L,_);const Y=new _.visualization.Dashboard(c.current);j&&_.visualization.drawToolbar(u.current,j);let G=null;N&&(G=new _.visualization.ChartEditor,N({chartEditor:G,chartWrapper:L,google:_})),a({...e,chartDashboard:Y,chartWrapper:L}),n(L),i(Y),A?.(_,{google:_,chartWrapper:L,chartEditor:G,chartDashboard:Y})},[]),NG({...e,googleChartWrapper:t,googleChartDashboard:r});const d=()=>{const{width:b,height:_,options:y,style:S,className:j,rootProps:N,google:k}=e,A={height:_||y&&y.height,width:b||y&&y.width,...S};return $.createElement("div",{id:l,style:A,className:j,...N})},p=()=>e.toolbarItems?$.createElement("div",{ref:u}):null,{width:g,height:m,options:v,style:I}=e,C={height:m||v&&v.height,width:g||v&&v.width,...I};return e.render?$.createElement("div",{ref:c,style:C},$.createElement("div",{ref:u,id:"toolbar"}),e.render({renderChart:d,renderControl:o,renderToolbar:p})):$.createElement("div",{ref:c,style:C},o(b=>{let{controlProp:_}=b;return _.controlPosition!=="bottom"}),d(),o(b=>{let{controlProp:_}=b;return _.controlPosition==="bottom"}),p())},MG=$.createContext(W0),OG=e=>{let{children:t,value:n}=e;return $.createElement(MG.Provider,{value:n},t)},TG=e=>{const{google:t,isLoading:n,error:r}=bG(e);return n?e.loader??null:r?e.errorElement??null:t?x.createElement(DG,{google:t,...e}):null},FG=e=>{const t={...W0,...e};return x.createElement(OG,{value:t},x.createElement(TG,t))};var Bg;(function(e){e.annotation="annotation",e.annotationText="annotationText",e.certainty="certainty",e.emphasis="emphasis",e.interval="interval",e.scope="scope",e.style="style",e.tooltip="tooltip",e.domain="domain"})(Bg||(Bg={}));function PG({target:e,results:t}){const n={title:e.logging_parameter.name,curveType:"function",series:{0:{pointSize:10},1:{},2:{},3:{}},legend:{position:"bottom"}};let r=[[{type:"date",label:"Date"},"Value"]],i=1;return e.target&&(r[0].push("Target"),n.series[i]={color:"#38e22c",lineWidth:2,pointShape:{type:"square"}},i++),e.min_value&&(r[0].push("Min"),n.series[i]={color:"#e2431e",lineWidth:2,pointShape:{type:"triangle"},pointSize:10},i++),e.max_value&&(r[0].push("Max"),n.series[i]={color:"#e2431e",lineWidth:2,pointShape:{type:"triangle",rotation:180},pointSize:10}),t.forEach(a=>{a.values.filter(o=>o.logging_parameter.id===e.logging_parameter.id).filter(o=>o.float_value!==0).forEach(o=>{let l=new Date(a.date_created);r.push([l,o.float_value]),e.target&&r[r.length-1].push(e.target),e.min_value&&r[r.length-1].push(e.min_value),e.max_value&&r[r.length-1].push(e.max_value)})}),r.length===1?s.jsx("div",{className:"text-center",children:"No data available"}):s.jsx(FG,{chartType:"ScatterChart",width:"100%",height:"400px",data:r,options:n})}const za=({data:e,setPage:t,setPageSize:n,pageSize:r,isPlaceholderData:i})=>{if(e===void 0||i)return s.jsx(s.Fragment,{});let a=[];for(let o=1;o<=e.amountOfPages;o++)a.push(s.jsx(Ym.Item,{active:o===e.currentPage,onClick:()=>t(l=>o),children:o},o));return s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs("div",{className:"d-flex gap-2",children:[s.jsx("div",{children:s.jsx(ie,{size:"sm",onClick:()=>t(o=>Math.max(o-1,0)),disabled:e.currentPage===1,children:"Previous Page"})}),s.jsx(Ym,{size:"sm",children:a.map((o,l)=>s.jsx("div",{children:o},l))}),s.jsx("div",{children:s.jsx(ie,{size:"sm",onClick:()=>{!i&&e.hasMore&&t(o=>o+1)},disabled:i||!e.hasMore,children:"Next Page"})})]}),n!==void 0?s.jsx("div",{children:s.jsxs(W.Select,{onChange:o=>{n(l=>parseInt(o.target.value))},value:r,size:"sm",children:[s.jsx("option",{value:10,children:"10"}),s.jsx("option",{value:25,children:"25"}),s.jsx("option",{value:50,children:"50"}),s.jsx("option",{value:100,children:"100"})]})}):null]})},LG=new Date().toISOString().split("T")[0],VG=({requirement:e,targets:t,refetchResults:n})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(!1),[l,c]=x.useState(!1),{control:u,register:d,handleSubmit:p,reset:g,watch:m,formState:{errors:v,isValid:I}}=tn({defaultValues:{date:LG}}),{fields:C,append:b,remove:_}=Zk({control:u,name:"results",rules:{required:!0}});x.useEffect(()=>{_(),t.forEach(N=>{b({id:N.id,label:N.logging_parameter.name,logging_parameter_id:N.logging_parameter.id,value:""})})},[t]);const y=m();x.useEffect(()=>{c(I)},[y,I]);async function S(N){await te.post("create/monitor/requirement/result",{requirement:e.id,date:N.date,values:N.results}),o(!0),i(!1),n(),g()}function j(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>o(!1),show:a,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Results saved"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Measurement results were saved successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"primary",onClick:()=>i(!0),children:"Add manual result"}),s.jsx(ve,{show:r,size:"lg",onHide:()=>i(!1),children:s.jsxs(W,{onSubmit:p(N=>S(N)),validated:l,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Add manual result"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Date"}),s.jsx(W.Control,{type:"date",placeholder:"Date",required:!0,...d("date",{required:"This field is required"})},"date"),v.date&&s.jsx(W.Control.Feedback,{children:v.date.message})]}),C.map((N,k)=>s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:N.label}),s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{type:"number",step:.01,placeholder:N.label,required:!0,...d(`results.${k}.value`,{required:"This field is required"})},N.id),v?.results?.[k]?.value&&s.jsx(W.Control.Feedback,{children:v.results[k].value.message})]})]},k))]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{g(),i(!1)},children:"Close"})]})]})}),s.jsx(j,{})]})},GG=({requirement:e,result:t,refetchMonitorStepParameterValues:n})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(!1),[l,c]=x.useState(!1),[u,d]=x.useState([]),{control:p,register:g,handleSubmit:m,reset:v,watch:I,formState:{errors:C,isValid:b}}=tn({defaultValues:{}});x.useEffect(()=>{async function j(){const N=await nx({result:t}),k=await N1({requirement:e}),A=await w1({module:e.step.process_module.module});k.items=k.items.filter(F=>!N.items.map(L=>L.step_parameter.id).includes(F.id)),k.items=k.items.filter(F=>A.items.map(L=>L.parameter.id).includes(F.parameter.id)),d(k.items)}r&&j()},[r]);const _=I();x.useEffect(()=>{c(b)},[_,b]);async function y(j){await te.post("create/monitor/requirement/result/step-parameter-value",{result:t.id,step_parameter:j.module_step_parameter_id,value:j.value}),o(!0),i(!1),n(),v()}function S(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>o(!1),show:a,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Results saved"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Measurement results were saved successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"primary",size:"sm",onClick:()=>i(!0),children:"+"}),s.jsx(ve,{show:r,size:"lg",onHide:()=>i(!1),children:s.jsxs(W,{onSubmit:m(j=>y(j)),validated:l,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Add process parameter"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Date"}),s.jsx(W.Control,{type:"text",value:t.date_created,readOnly:!0})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Module Step Parameter"}),s.jsxs(W.Select,{...g("module_step_parameter_id",{required:!0}),children:[s.jsx("option",{value:"",children:"— Select a parameter"}),u.map(j=>s.jsx("option",{value:j.id,children:j.parameter.name},j.id))]}),s.jsx(W.Text,{className:"text-muted",children:"Only parameters are shown here which are active on the Equipment Module and in the monitor step. In case parameters are missing you should replace the process in the monitor with the same process from the process library to reload the parameters"})]}),s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{type:"number",step:.01,required:!0,...g("value",{required:"This field is required"})}),C?.value&&s.jsx(W.Control.Feedback,{children:C.value.message})]})]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{v(),i(!1)},children:"Close"})]})]})}),s.jsx(S,{})]})},BG=({monitorResultStepParameterValue:e,refetchMonitorStepParameterValues:t})=>{const[n,r]=x.useState(!1),[i,a]=x.useState(!1),[o,l]=x.useState(!1),{control:c,register:u,handleSubmit:d,reset:p,watch:g,formState:{errors:m,isValid:v}}=tn({defaultValues:{value:e.value.toString()}}),I=g();x.useEffect(()=>{l(v)},[I,v]);async function C(y){await te.patch("update/monitor/requirement/result/step-parameter-value/"+e.id,{value:y.value}),a(!0),r(!1),t(),p()}async function b(){await te.delete("delete/monitor/requirement/result/step-parameter-value/"+e.id,{}),a(!0),r(!1),t(),p()}function _(){return s.jsx(bs,{position:"top-end",className:"p-3",children:s.jsxs(on,{onClose:()=>a(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[s.jsxs(on.Header,{children:[s.jsx("strong",{className:"me-auto",children:"Results saved"}),s.jsx("small",{children:"Just now"})]}),s.jsx(on.Body,{children:"Measurement results were saved successfully"})]})})}return s.jsxs(s.Fragment,{children:[s.jsx("span",{onClick:()=>r(!0),children:e.value}),s.jsx(ve,{show:n,size:"lg",onHide:()=>r(!1),children:s.jsxs(W,{onSubmit:d(y=>C(y)),validated:o,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Add process parameter"})}),s.jsxs(ve.Body,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Date"}),s.jsx(W.Control,{type:"text",value:e.date_created,readOnly:!0})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Module Step Parameter"}),s.jsx(W.Control,{type:"text",value:e.step_parameter.parameter.name,readOnly:!0})]}),s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{type:"number",step:.01,required:!0,...u("value",{required:"This field is required"})}),m?.value&&s.jsx(W.Control.Feedback,{children:m.value.message})]})]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",type:"submit",variant:"primary",children:"Update value"}),s.jsx(ie,{className:"float-end",variant:"danger",onClick:()=>b(),children:"Delete value"}),s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{p(),r(!1)},children:"Close"})]})]})}),s.jsx(_,{})]})};function YG({requirement:e}){const[n,r]=x.useState([]),[i,a]=x.useState(""),[o,l]=x.useState(1),[c,u]=x.useState(15),[d,p]=x.useState([]),[g,m,v,I]=Ae.useQueries({queries:[{queryKey:["requirement","files",e.step,11],queryFn:()=>k1({step:e.step,pageSize:11,order:"date-created",direction:"desc"})},{queryKey:["requirement","target",e],queryFn:()=>E1({requirement:e})},{queryKey:["requirement","results",e,o,c],queryFn:()=>_1({requirement:e,pageSize:c,order:"date-created",direction:"desc",page:o}),placeholderData:Ae.keepPreviousData},{queryKey:["requirement","monitor_step_parameters",e,o,c],queryFn:()=>nx({requirement:e,pageSize:c,order:"date-created",direction:"desc",page:o}),placeholderData:Ae.keepPreviousData}]});x.useEffect(()=>{r([]),!g.isLoading&&g.data.items.forEach(k=>{r(A=>[...A,k])})},[g.isLoading]),x.useEffect(()=>{if(!I.data)return;const k=Array.from(new Map(I.data.items.map(A=>[A.step_parameter.id,A.step_parameter])).values());p(k)},[I.isLoading,I.data]);const C=x.useCallback(k=>{k.forEach(A=>{const F=new FileReader;F.onload=async()=>{const L=F.result;try{await te.create().post("update/monitor/requirement/upload-file/"+e.id,{content:L,filename:A.name,type:A.type})}catch(Y){a("Upload failed due to: "+Y.response.data.detail)}await g.refetch(),await v.refetch()},F.readAsDataURL(A)})},[e.id,g,v]),{getRootProps:b,getInputProps:_,isDragActive:y,isDragAccept:S,isDragReject:j}=Ta({onDrop:C}),N=x.useMemo(()=>({...y?{borderColor:"#83afee"}:{},...S?{borderColor:"#00e676"}:{},...j?{borderColor:"#ff1744"}:{}}),[S,j,y]);return m.isLoading||m.isFetching?s.jsx(St,{variant:"info",children:"Loading targets..."}):v.isLoading||v.isFetching?s.jsx(St,{variant:"info",children:"Loading results..."}):s.jsxs(s.Fragment,{children:[s.jsxs("h1",{className:"display-5",children:["Requirement: ",e.title]}),s.jsx("p",{className:"lead",children:e.definition}),s.jsx(Un,{className:"my-3",children:s.jsxs(Pt,{children:[s.jsx("h2",{children:"Charts"}),s.jsx("div",{className:"d-flex",children:m.data?.items.map((k,A)=>s.jsx(PG,{target:k,results:v.data.items},A))})]})}),s.jsxs(Un,{children:[s.jsxs(Pt,{md:8,children:[e.method&&e.method!=="-"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{children:"Method"}),s.jsx("p",{children:e.method})]}),m.data?.items.length===0&&s.jsx(St,{variant:"danger",children:"No targets found"}),s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("h2",{children:"Results"}),s.jsx("div",{children:s.jsx(VG,{requirement:e,targets:m.data.items,refetchResults:v.refetch})})]}),s.jsxs(Ht,{size:"sm",striped:!0,bordered:!0,hover:!0,children:[s.jsxs("thead",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:"ID"}),s.jsx("th",{children:"Date"}),m.data?.items.map((k,A)=>s.jsx("th",{children:k.logging_parameter.name},A)),d.map((k,A)=>s.jsx("th",{children:k.parameter.name},A)),s.jsx("th",{children:"+"})]}),s.jsxs("tr",{children:[s.jsx("th",{colSpan:2}),m.data?.items.map((k,A)=>s.jsxs("td",{children:[k.min_value,k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:"≤"}),!k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:"<"}),k.target??"X",k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:"≥"}),!k.is_value_inclusive&&s.jsx("span",{className:"text-muted px-2",children:">"}),k.max_value]},A)),d.map((k,A)=>s.jsx("th",{className:"table-secondary"},A)),s.jsx("th",{})]})]}),s.jsx("tbody",{children:v.data?.items.map((k,A)=>s.jsxs("tr",{children:[s.jsx("th",{children:s.jsx("small",{className:"text-muted",children:k.id})},A),s.jsx("td",{children:ln(k.date_created,"DD-MM-YY HH:mm")}),m.data?.items.map((F,L)=>s.jsx("td",{children:k.values.filter(Y=>Y.logging_parameter.id===F.logging_parameter.id).map((Y,G)=>s.jsx("span",{className:Y.value_is_valid?"text-success":"text-danger",children:Y.float_value},G))},L)),d.map((F,L)=>s.jsx("td",{className:"table-secondary",children:I.data?.items.filter(Y=>Y.step_parameter.id===F.id&&Y.result.id===k.id).map((Y,G)=>s.jsx(BG,{monitorResultStepParameterValue:Y,refetchMonitorStepParameterValues:I.refetch},G))},L)),s.jsx("td",{children:s.jsx(GG,{result:k,requirement:e,refetchMonitorStepParameterValues:I.refetch})})]},A))})]}),s.jsx(za,{data:v.data,setPage:l,setPageSize:u,pageSize:c,isPlaceholderData:v.isPlaceholderData})]}),s.jsxs(Pt,{md:4,children:[s.jsx("h2",{children:"Upload new results"}),s.jsx("p",{children:"Drop your results file here"}),s.jsxs("div",{...b({style:N,className:"dropzone"}),children:[s.jsx("input",{..._()}),y?s.jsx("p",{children:"Drop file(s) here ..."}):s.jsx("p",{children:"Drag and drop file(s) here, or click to select files"}),s.jsx("p",{children:i})]}),n.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{className:"mt-2",children:"Uploaded files"}),s.jsxs("p",{children:["Last ",11," uploaded files"]}),s.jsx("ul",{className:"list-group",children:n.map((k,A)=>s.jsxs("li",{className:"list-group-item",children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsxs("span",{children:[A+1," ",s.jsx("a",{href:Y0()+k.url,children:k.name}),k.has_monitor_step_loggings&&s.jsx(Ft,{className:"ms-1 bg-primary",children:"Logging"})]}),s.jsxs("span",{children:[Math.round(k.size/1024),"kiB"]})]}),s.jsx("small",{className:"text-muted",children:ln(k.date_created,"DD-MM-YY HH:mm")})]},A))})]})]})]})]})}function WG(){let{id:e}=Te.useParams();const[t,n]=Ae.useQueries({queries:[{queryKey:["monitor",e],queryFn:()=>Cu({id:parseInt(e)})},{queryKey:["requirements",e],queryFn:()=>ex({monitorId:parseInt(e)})}]});return t.isLoading?s.jsx("div",{children:"Loading..."}):s.jsxs("div",{children:[s.jsxs("h1",{className:"display-4",children:["SPC Test ",t.data?.name]}),n.data?.items.map((r,i)=>s.jsx("div",{className:"border border-1 p-3 my-3",children:s.jsx(YG,{requirement:r})},i))]})}function zG(){return s.jsx(Ii,{fluid:!0,children:s.jsx(Te.Outlet,{})})}const HG=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&Cu({id:parseInt(n)}).then(t)},[n,e]);function r(){Cu({id:parseInt(n)}).then(t)}return{monitor:e,setMonitor:t,reloadMonitor:r}},H0=x.createContext({monitor:{},reloadMonitor:()=>{}});function UG({children:e}){const{monitor:t,reloadMonitor:n}=HG();return t===null?s.jsx(jn,{children:s.jsx(zt,{message:"Loading monitor..."})}):s.jsx(jn,{children:s.jsx(H0.Provider,{value:{monitor:t,reloadMonitor:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}const $G=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{(e===null||n!==e.id.toString())&&Fo({id:parseInt(n)}).then(t)},[n,e]);function r(){Fo({id:parseInt(n)}).then(t)}return{run:e,reloadRun:r}},Ri=x.createContext({run:{},reloadRun:()=>{}});function U0({children:e}){const{run:t,reloadRun:n}=$G();return t===null?s.jsx(jn,{children:s.jsx(zt,{message:"Loading run..."})}):s.jsx(jn,{children:s.jsx(Ri.Provider,{value:{run:t,reloadRun:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function XG({text:e}){if(!e)return null;const t=e.split(/\r\n|\n|\r/);return s.jsx(s.Fragment,{children:t.map((n,r)=>s.jsxs(x.Fragment,{children:[n,r<t.length-1&&s.jsx("br",{})]},r))})}const wi=({children:e,format:t="d-M-Y"})=>{const n=Date.parse(e);return s.jsx(s.Fragment,{children:ye(n).format(t)})},ip=({run:e})=>{const[t,n]=x.useState(e.batch_card),[r,i]=x.useState(!1),{register:a,handleSubmit:o,formState:l,resetField:c}=tn({defaultValues:{content:t?.content}}),{isSubmitting:u,errors:d}=l,p=async m=>{await te.create().patch("update/run/batch-card/"+e.id,{content:m.content}),i(!1);const v=await te.get("view/run/"+e.id);n(v.data.batch_card)},g=async()=>{await te.create().delete("delete/run/batch-card/"+e.id),i(!1),n(void 0),c("content")};return r?s.jsxs(W,{onSubmit:o(p),className:"mb-3",children:[s.jsxs(Kt,{hasValidation:!0,children:[s.jsx(W.Control,{as:"textarea",rows:6,...a("content",{required:!0}),isInvalid:d.content!==void 0}),d.content&&s.jsx(W.Control.Feedback,{type:"invalid",children:"This field is required"})]}),s.jsxs("div",{className:"d-flex flex-column flex-md-row gap-2 justify-content-between mt-2",children:[s.jsxs("div",{className:"d-flex flex-wrap gap-2",children:[s.jsxs(ie,{variant:"primary",type:"submit",disabled:u,className:"text-nowrap",children:[u&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save batch card"]}),s.jsx(ie,{variant:"secondary",onClick:()=>i(!1),children:"Cancel"})]}),t&&s.jsx("div",{children:s.jsx(ie,{variant:"outline-danger",className:"text-nowrap",onClick:g,children:"Delete batch card"})})]})]}):t?t&&s.jsxs(Ye,{className:"rounded my-4 shadow-sm border-0",children:[s.jsxs(Ye.Body,{children:[s.jsxs("div",{className:"d-flex align-items-start justify-content-between gap-3",children:[s.jsx(Ye.Title,{className:"text-danger mb-0",children:"Batch card"}),s.jsx(ie,{variant:"outline-primary",size:"sm",className:"text-nowrap",onClick:()=>i(!0),children:"Update batch card"})]}),s.jsx(Ye.Text,{className:"mt-3 mb-2 fs-5 text-body",children:t&&s.jsx(XG,{text:t.content})})]}),s.jsx(Ye.Footer,{className:"bg-transparent border-0 pt-0 pb-3",children:s.jsxs("div",{className:"text-muted small",children:["Created ",s.jsx(wi,{format:"DD-MM-YY",children:t.date_created})," by"," ",t.user.first_name," ",t.user.last_name,t.last_update&&s.jsxs("span",{children:[" (","Updated ",s.jsx(wi,{format:"DD-MM-YY H:m",children:t.last_update}),")"]})]})})]}):s.jsx(ie,{variant:"outline-primary",className:"mb-4",onClick:()=>i(!0),children:"Create Batch Card"})};function qG(){const{run:e}=x.useContext(Ri);return s.jsxs(s.Fragment,{children:[e.run_type===Wn.RESEARCH&&s.jsx("small",{children:"Research run"}),e.run_type===Wn.PRODUCTION&&s.jsx("small",{children:"Production run"}),s.jsx("div",{className:"d-flex justify-content-between align-items-center mb-3",children:s.jsxs("h1",{className:"display-4",children:[e.name," (",e.project.name,")"]})}),s.jsx(ip,{run:e})]})}function ZG(e){const{run:t,reloadRun:n}=x.useContext(Ri),{environment:r}=Te.useParams(),i=window.location.pathname;let a=[{title:"Information",link:`/${r}/operator/run/details/${t.id}/information`}];return a.push({title:"Steps",link:`/${r}/operator/run/details/${t.id}/steps`}),s.jsx(Vm,{variant:"tabs",className:e.className,defaultActiveKey:"/home",activeKey:i,children:a.map((o,l)=>s.jsx(Vm.Item,{children:s.jsx(Te.Link,{to:o.link,className:"nav-link "+(o.link===i?"active":""),children:o.title})},l))})}function JG(){return s.jsx(U0,{children:s.jsxs(Ii,{fluid:!0,children:[s.jsx(qG,{}),s.jsx(ZG,{className:"mb-4"}),s.jsx(Te.Outlet,{})]})})}const Kl=x.createContext({showOnlyEmphasizedParameters:!1,setShowOnlyEmphasizedParameters:()=>{}}),QG=({parameter:e,value:t,refetchFn:n})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(t.value),l=async c=>{const u={value:c};try{t.id!==void 0?await te.patch(`/update/run/step/parameter/value/${t.id}`,u):(u.parameter=e.id,await te.post("/create/run/step/parameter/value",u))}catch(d){console.error("Failed to update parameter value with error: ",d)}n(),i(!1)};return s.jsxs(s.Fragment,{children:[s.jsx("span",{style:{cursor:"pointer",borderBottom:"1px dashed #999",display:r?"none":""},className:t.value==""||t.value==null?"text-muted":"",onClick:()=>{i(!r)},children:t.value!==""&&t.value!==null?t.value:"edit"}),s.jsxs("div",{style:{display:r?"":"none"},className:"btn-group",children:[s.jsx("input",{type:"text",value:a??"",className:"form-control",onChange:c=>o(c.target.value)}),s.jsx("button",{onClick:()=>{l(a)},className:"btn btn-success btn-sm",children:s.jsx("i",{className:"fa fa-check"})}),s.jsx("button",{onClick:()=>{i(!1)},className:"btn btn-danger btn-sm",children:s.jsx("i",{className:"fa fa-times"})})]})]})},ec=({runStep:e,showOnlyEmphasizedParameters:t,editableParameters:n=!0,refetchFn:r})=>{const{data:i,isLoading:a}=Ae.useQuery({queryKey:["runStepParameters",e.id],queryFn:()=>M1({runStep:e})}),o=Ae.useQueryClient(),l=()=>{o.refetchQueries({queryKey:["runStepParameters",e.id]}),r&&r()},c=i?.items??[],u=t?c.filter(d=>d.emphasize):c;return a?s.jsx("div",{children:"Loading..."}):c.length===0?s.jsx(St,{variant:"info",children:"No parameters found"}):s.jsxs(Ht,{children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Pos"}),s.jsx("th",{children:"Parameter"}),c[0].values.map((d,p)=>s.jsx("th",{children:"Value"},p)),s.jsx("th",{children:"Unit"})]})}),s.jsx("tbody",{children:u.length>0?u.map(d=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("small",{className:"text-muted",children:d.sequence})}),s.jsx("td",{children:d.parameter.name}),d.values.map((p,g)=>s.jsx("td",{children:n?s.jsx(QG,{parameter:d,refetchFn:l,value:p}):s.jsx("span",{children:p.value})},g)),s.jsx("td",{children:d.unit?.abbr??""})]},d.id)):s.jsx("tr",{children:s.jsx("td",{colSpan:3+c[0].values.length,children:"No emphasized parameters found."})})})]})},KG=e=>{if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB","TB"],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,r)).toFixed(2))} ${n[r]}`};function tc({runStep:e,refetchFn:t}){const[n,r]=x.useState([]),[i,a]=x.useState(""),{data:o,isLoading:l}=Ae.useQuery({queryKey:["files",e.id],queryFn:()=>D1({step:e})}),c=Ae.useQueryClient(),u=()=>{c.refetchQueries({queryKey:["files",e.id]}),t&&t()},d=o?.items??[],p=async S=>{if(confirm(`Are you sure you want to delete ${S.name}? You can not undo this action`))try{await te.delete(`delete/run/step/file/${S.id}`),u()}catch(j){console.error(j)}},g=S=>{r(j=>[...j,...S]),a(`${S.length} file(s) selected`)},{getRootProps:m,getInputProps:v,isDragActive:I,isDragAccept:C,isDragReject:b}=Ta({onDrop:g}),_=x.useMemo(()=>({...I?{borderColor:"#83afee"}:{},...C?{borderColor:"#00e676"}:{},...b?{borderColor:"#ff1744"}:{}}),[C,b,I]),y=()=>{n.forEach(S=>{const j=new FileReader;j.onload=async()=>{const N=j.result;try{await te.create().post("update/run/step/upload-file/"+e.id,{content:N,filename:S.name,type:S.type})}catch(k){a("Upload failed due to: "+k.response.data.detail)}try{u(),a("Files uploaded succesfully"),r([])}catch(k){a("Error refetching file data"),console.error(k)}},j.readAsDataURL(S)})};return l?s.jsx("div",{children:"Loading..."}):s.jsxs("div",{children:[d&&d.length>0&&s.jsxs(Ht,{hover:!0,striped:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"No"}),s.jsx("th",{children:"File"}),s.jsx("th",{children:"Size"}),s.jsx("th",{children:"Date"})]})}),s.jsx("tbody",{children:d.map((S,j)=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("small",{className:"text-muted",children:j+1})}),s.jsxs("td",{children:[s.jsx("a",{href:`${Y0()}${S.url}`,children:S.name}),S.has_run_step_loggings&&s.jsx(Ft,{className:"ms-1 bg-primary",children:"Logging"})]}),s.jsxs("td",{children:[s.jsx("i",{className:"fa fa-trash-o remove-file handle",style:{cursor:"pointer"},onClick:()=>p(S)})," ",KG(S.size)]}),s.jsx("td",{children:ln(S.date_created,"DD-MM-YY HH:mm")})]},j))})]}),s.jsxs("div",{...m({style:_,className:"dropzone bg-secondary-subtle border rounded dz-clickable"}),children:[s.jsx("input",{...v()}),I?s.jsx("p",{children:"Drop files here..."}):s.jsx("p",{children:"Drag and drop files here or click to select"})]}),n.length>0&&s.jsx(wn,{className:"mt-3",children:n.map((S,j)=>s.jsx(wn.Item,{children:S.name},j))}),s.jsxs("div",{className:"text-start",children:[s.jsx(ie,{className:"mt-3",onClick:y,disabled:n.length===0,children:"Upload Selected Files"}),s.jsx("p",{className:"mt-2 text-muted",children:i})]})]})}const gd=({runStepPart:e,setRunStepPart:t,editable:n=!0})=>{const[r,i]=x.useState(!1),[a,o]=x.useState(e.comment),{register:l,handleSubmit:c,formState:u,resetField:d}=tn({defaultValues:{comment:a}}),{isSubmitting:p,errors:g}=u,m=async v=>{await te.create().patch("update/run/step/part/"+e.id,{comment:v.comment}).then(I=>{t({...e,comment:I.data.comment}),o(I.data.comment),i(!1)})};return n?r?s.jsxs(W,{onSubmit:c(m),children:[s.jsx(W.Group,{className:"mb-3",controlId:"formBasicEmail",children:s.jsx(W.Control,{as:"textarea",...l("comment")})}),s.jsx(ie,{size:"sm",type:"submit",disabled:p,children:"Save"}),s.jsx(ie,{variant:"warning",size:"sm",className:"ms-2",onClick:()=>i(!1),children:"Cancel"})]}):a===null?s.jsx(ie,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Add comment"}):s.jsxs("div",{className:"d-flex align-items-start gap-2",children:[s.jsx("div",{className:"text-break",children:a}),s.jsx(ie,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Edit"})]}):s.jsx("div",{children:a})},eB=(e,t,n)=>{let r={...e,latest_action:n??e.latest_action,actions:e.actions+1};return t===Ne.START_PROCESSING&&(r={...r,started:!0,processed:!1,failed:!1}),t===Ne.FINISH_PROCESSING&&(r={...r,started:!0,processed:!0,failed:!1}),t===Ne.FAILED_PROCESSING&&(r={...r,started:!0,processed:!1,failed:!0}),t===Ne.REWORK&&(r={...r,started:!1,processed:!1,failed:!1}),r},tB=(e,t)=>{const{runStepPart:n,action:r,latestAction:i}=t;return e.map(a=>{const o=r===Ne.FAILED_PROCESSING&&a.part.id===n.part.id,l=a.id===n.id;if(!o&&!l)return a;let c=a;return o&&(c={...c,part:{...c.part,part_processing_failed:!0}}),l&&(c=eB(c,r,i)),c})},Yg=(e,t)=>!e||!Array.isArray(e.items)?e:{...e,items:tB(e.items,t)},sp=(e,t)=>{e.setQueriesData({queryKey:["runStepParts"]},n=>Yg(n,t)),e.setQueriesData({queryKey:["stepParts"]},n=>Yg(n,t))},nB=({runStepPart:e,editable:t=!0,reloadFn:n,partIsSelected:r,setPartAsSelected:i})=>{const a=Ae.useQueryClient(),[o,l]=x.useState(e);x.useEffect(()=>{l(e)},[e]);const c=o.latest_action?.type.id===Ne.FINISH_PROCESSING,u=o.latest_action?.type.id===Ne.FAILED_PROCESSING,d=o.part_processing_failed_in_previous_step?"table-danger":c?"table-success":u?"table-danger":"",p=o.part.part_processing_failed?{label:"Blocked",variant:"danger",description:"Failed in an other step"}:o.part_processing_failed_in_previous_step?{label:"Blocked",variant:"danger",description:"Failed in previous step"}:o.actions===0?{label:"Not started",variant:"secondary",description:"No actions yet"}:o.latest_action?.type.id===Ne.START_PROCESSING?{label:"In progress",variant:"primary",description:"Processing started"}:o.latest_action?.type.id===Ne.FINISH_PROCESSING?{label:"Completed",variant:"success",description:"Processing finished"}:o.latest_action?.type.id===Ne.FAILED_PROCESSING?{label:"Failed",variant:"danger",description:"Processing failed"}:o.latest_action?.type.id===Ne.REWORK?{label:"Rework",variant:"warning",description:"Needs rework"}:{label:"Unknown",variant:"secondary",description:"No status available"},g=o.part.label??o.part.short_label,m=I=>{!i||I.target.closest("button, a, input, textarea, select, option, label")||i(o.part.id)},v=async({runStepPart:I,runStepPartAction:C})=>{const b=await Id(I,C);l(_=>({..._,latest_action:b,actions:_.actions+1})),sp(a,{runStepPart:o,action:C,latestAction:b}),n&&n()};return s.jsxs("tr",{onClick:m,style:t?{cursor:"pointer"}:void 0,children:[s.jsx("td",{className:d}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[g,i&&s.jsx("input",{type:"checkbox",id:`part-select-${o.id}`,name:"tomato",className:"form-check-input m-0",checked:r,onChange:()=>{i(o.part.id)}})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex justify-content-between gap-1",children:[s.jsxs("div",{children:[s.jsx(Ft,{bg:p.variant,children:p.label}),s.jsx("small",{className:"text-muted ms-2",children:p.description})]}),t&&s.jsxs("div",{className:"d-flex gap-1",children:[o.actions===0&&s.jsx(ie,{onClick:()=>v({runStepPart:o,runStepPartAction:Ne.START_PROCESSING}),className:"btn-success btn-sm",children:"Start"}),o.actions>0&&o.latest_action?.type.id!==Ne.FINISH_PROCESSING&&o.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>v({runStepPart:o,runStepPartAction:Ne.FINISH_PROCESSING}),className:"btn-primary btn-sm",children:"Finish"}),o.actions>0&&o.latest_action?.type.id!==Ne.FINISH_PROCESSING&&o.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>v({runStepPart:o,runStepPartAction:Ne.FAILED_PROCESSING}),className:"btn-danger btn-sm",children:"Failed"}),o.actions>0&&o.latest_action?.type.id!==Ne.FINISH_PROCESSING&&s.jsx(ie,{size:"sm",onClick:()=>v({runStepPart:o,runStepPartAction:Ne.REWORK}),children:"Rework"})]})]})}),s.jsx("td",{children:s.jsx(gd,{editable:t,runStepPart:o,setRunStepPart:I=>{l(I),n&&n()}})})]})};function ap({parts:e,getPartId:t,toggleRef:n}){const[r,i]=x.useState(new Map);x.useEffect(()=>{const u=new Map;for(const d of e){const p=t(d);u.set(p,r.get(p)??!1)}u.size!==r.size&&i(()=>u)},[e,t]);const a=x.useCallback(u=>{i(d=>{const p=new Map(d);return p.set(u,!(d.get(u)??!1)),p})},[]);x.useImperativeHandle(n,()=>e.length===0?null:{setPart(u){a(u)},setPartByLabel(u){const d=e.find(p=>p?.short_label===u)?.id;d!==void 0&&a(d)}},[e,a]);const o=x.useCallback(()=>{i(u=>new Map([...u.keys()].map(d=>[d,!0])))},[]),l=x.useCallback(()=>{i(u=>new Map([...u.keys()].map(d=>[d,!1])))},[]),c=Array.from(r.values()).some(u=>u);return{selectedParts:r,setPartAsSelected:a,selectAllParts:o,selectNoneParts:l,hasSelectedParts:c}}function $0({runStep:e,parts:t,selectedParts:n,getPartId:r,getRunStepPart:i,refetchFn:a}){const o=Ae.useQueryClient(),l=x.useCallback(u=>{const d=t.filter(g=>n.get(r(g)));if(d.length===0)return;const p=d.map(g=>i(g)).filter(g=>g!==void 0).filter(g=>Jp(g).some(m=>m===u)).map(g=>Id(g,u).then(m=>{sp(o,{runStepPart:g,action:u,latestAction:m})}));Promise.all(p).then(()=>{o.refetchQueries({queryKey:["stepParts",e.id]}),o.refetchQueries({queryKey:["runStepParts",e.id]}),a&&a()})},[t,n,r,i,o,e.id,a]),c=x.useCallback(()=>{const u=t.filter(p=>n.get(r(p)));if(u.length===0)return new Set;const d=new Set;return u.forEach(p=>{const g=i(p);g&&Jp(g).forEach(v=>d.add(v))}),d},[t,n,r,i]);return{performActionToSelectedParts:l,getAvailableActionsForSelection:c}}const X0=({availableActions:e,onActionSelected:t,showInitAction:n=!1,onInitSelected:r})=>e.size===0&&!n?null:s.jsxs(at,{align:"end",children:[s.jsx(at.Toggle,{size:"sm",variant:"secondary",children:"Actions"}),s.jsxs(at.Menu,{children:[n&&r&&s.jsx(at.Item,{onClick:r,children:"Init"}),e.has(Ne.START_PROCESSING)&&s.jsx(at.Item,{onClick:()=>t(Ne.START_PROCESSING),children:"Start"}),e.has(Ne.FINISH_PROCESSING)&&s.jsx(at.Item,{onClick:()=>t(Ne.FINISH_PROCESSING),children:"Finish"}),e.has(Ne.FAILED_PROCESSING)&&s.jsx(at.Item,{onClick:()=>t(Ne.FAILED_PROCESSING),children:"Failed"}),e.has(Ne.REWORK)&&s.jsx(at.Item,{onClick:()=>t(Ne.REWORK),children:"Rework"})]})]}),q0=({onSelectAll:e,onSelectNone:t,hasSelectedParts:n,actionsDropdown:r})=>s.jsxs("div",{className:"d-flex gap-3",children:[s.jsxs("div",{className:"btn-group btn-group-sm",role:"group",children:[s.jsx("button",{className:"part-check-all btn btn-outline-secondary",onClick:e,children:"All"}),s.jsx("button",{className:"part-check-none btn btn-outline-secondary",onClick:t,children:"None"})]}),n&&r]}),op=({run:e,runStep:t,runStepParts:n,editable:r=!0,refetchFn:i,toggleRunStepPartRef:a})=>{const[o,l]=x.useState(n||[]),c=i??(()=>{}),u=Ae.useQueryClient(),{isLoading:d,isError:p,error:g,data:m}=Ae.useQuery({queryKey:["stepParts",t.id],queryFn:()=>gs({step:t}),enabled:!n});x.useEffect(()=>{p&&console.error("RunPartsResearchRun query error",{error:g,runStep:t})},[p,g,t]),x.useEffect(()=>{!d&&m&&!n&&l(m.items)},[d,m,n]),x.useEffect(()=>{n&&(l(n),Js(t,n))},[o]);const{selectedParts:v,setPartAsSelected:I,selectAllParts:C,selectNoneParts:b,hasSelectedParts:_}=ap({parts:o,getPartId:N=>N.part.id,toggleRef:a});x.useEffect(()=>{const N=Array.from(v.entries()).filter(([,k])=>k).map(([k])=>k);u.setQueryData(["runPartSelection",t.id],N)},[u,t.id,v]);const{performActionToSelectedParts:y,getAvailableActionsForSelection:S}=$0({runStep:t,parts:o,selectedParts:v,getPartId:N=>N.part.id,getRunStepPart:N=>N,refetchFn:c}),j=x.useMemo(()=>S(),[S]);if(d)return s.jsx(zt,{message:"Loading run parts"});if(p)throw new Error("RunPartsResearchRun should not be loading");return o.length===0?null:s.jsx(x.Fragment,{children:o&&o.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{}),s.jsx("th",{children:"Part"}),s.jsx("th",{className:"text-center",children:"Status"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:o.map(N=>{const k=v.get(N.part.id)??!1;return s.jsx(nB,{editable:r,runStepPart:N,reloadFn:c,...r?{partIsSelected:k,setPartAsSelected:I}:{}},N.id)})})]}),r&&s.jsx(q0,{onSelectAll:C,onSelectNone:b,hasSelectedParts:_,actionsDropdown:s.jsx(X0,{availableActions:j,onActionSelected:y})})]})})},Z0=({runPart:e,runStepParts:t,runStep:n,refetchFn:r=()=>{},partIsSelected:i,setPartAsSelected:a,dropdown:o=!0,layout:l="default",onRunStepPartUpdated:c})=>{const[u,d]=x.useState(void 0),p=Ae.useQueryClient();x.useEffect(()=>{const y=t.find(S=>S.part.id===e.id&&S.step.id===n.id);if(!y){d(void 0);return}d(S=>!S||(y.actions??0)>=(S.actions??0)?y:S)},[t,e,n]);const g=()=>{te.post("/create/run/step/part",{run_part_id:e.id,run_step_id:n.id}).then(y=>{const S={...y.data};d(S),c&&c(S),r(),p.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},m=y=>{!a||y.target.closest("button, a, input, textarea, select, option, label")||a(e.id)},v=({runStepPart:y,runStepPartAction:S})=>{Id(y,S).then(j=>{const N=j;d(k=>{if(!k)return k;const A={...k,latest_action:N,actions:k.actions+1};return sp(p,{runStepPart:A,action:S,latestAction:N}),c&&c(A),A})}).then(()=>{r(),p.invalidateQueries({queryKey:["runSteps"]})})};if(!u)return l==="research"?s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,children:[s.jsx("td",{}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("div",{className:"fw-semibold",children:e.label||e.short_label}),a&&s.jsx("input",{type:"checkbox",id:`part-select-${e.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex justify-content-between gap-1",children:[s.jsxs("div",{className:"d-flex flex-column align-items-start gap-1",children:[s.jsx(Ft,{bg:"secondary",children:"Not initialized"}),s.jsx("small",{className:"text-muted",children:"No actions yet"})]}),s.jsx("div",{children:s.jsx(ie,{size:"sm",variant:"outline-info",onClick:()=>g(),children:"Init"})})]})}),s.jsx("td",{})]}):s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,children:[s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("div",{className:"fw-semibold",children:e.label||e.short_label}),a&&s.jsx("input",{type:"checkbox",id:`part-select-${e.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex flex-column align-items-start gap-1",children:[s.jsx(Ft,{bg:"secondary",children:"Not initialized"}),s.jsx("small",{className:"text-muted",children:"No actions yet"})]})}),s.jsx("td",{className:"text-muted",children:"-"}),s.jsx("td",{children:s.jsx(ie,{size:"sm",variant:"outline-info",onClick:()=>g(),children:"Init"})}),s.jsx("td",{})]});const I=u.latest_action?.type.id===Ne.FINISH_PROCESSING,C=u.latest_action?.type.id===Ne.FAILED_PROCESSING,b=u.part.part_processing_failed||u.part_processing_failed_in_previous_step?"table-danger":I?"table-success":C?"table-danger":"",_=u.part.part_processing_failed?{label:"Blocked",variant:"danger",description:"Failed in an other step"}:u.part_processing_failed_in_previous_step?{label:"Blocked",variant:"danger",description:"Failed in previous step"}:u.actions===0?{label:"Not started",variant:"secondary",description:"No actions yet"}:u.latest_action?.type.id===Ne.START_PROCESSING?{label:"In progress",variant:"primary",description:"Processing started"}:u.latest_action?.type.id===Ne.FINISH_PROCESSING?{label:"Completed",variant:"success",description:"Processing finished"}:u.latest_action?.type.id===Ne.FAILED_PROCESSING?{label:"Failed",variant:"danger",description:"Processing failed"}:u.latest_action?.type.id===Ne.REWORK?{label:"Rework",variant:"warning",description:"Needs rework"}:{label:"Unknown",variant:"secondary",description:"No status available"};return l==="research"?s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,children:[s.jsx("td",{className:b}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx("div",{className:"fw-semibold",children:u.part.label||u.part.short_label}),a&&s.jsxs(s.Fragment,{children:[s.jsx("input",{type:"checkbox",id:`part-select-${u.part.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}}),s.jsx("label",{className:"visually-hidden",htmlFor:`part-select-${u.part.id}`,children:"Select part"})]})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex justify-content-between gap-1",children:[s.jsxs("div",{children:[s.jsx(Ft,{bg:_.variant,children:_.label}),s.jsx("small",{className:"text-muted ms-2",children:_.description})]}),s.jsx("div",{children:s.jsx(Wg,{runStepPart:u,setRunStepPartAction:v})})]})}),s.jsx("td",{children:s.jsx(gd,{runStepPart:u,setRunStepPart:y=>{d(y),c&&c(y)}})})]}):s.jsxs("tr",{onClick:m,style:a?{cursor:"pointer"}:void 0,className:b,children:[s.jsx("td",{children:s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsxs("div",{className:"fw-semibold",children:["Part ",u.part.short_label,u.part.label&&u.part.label.trim().length>0?` (${u.part.label})`:""]}),a&&s.jsxs(s.Fragment,{children:[s.jsx("input",{type:"checkbox",id:`part-select-${u.part.id}`,name:"tomato",className:"form-check-input m-0",checked:i,onChange:()=>{a(e.id)}}),s.jsx("label",{className:"visually-hidden",htmlFor:`part-select-${u.part.id}`,children:"Select part"})]})]})}),s.jsx("td",{children:s.jsxs("div",{className:"d-flex flex-column align-items-start gap-1",children:[s.jsx(Ft,{bg:_.variant,children:_.label}),s.jsx("small",{className:"text-muted",children:_.description})]})}),s.jsx("td",{children:s.jsx("span",{className:"text-muted",children:ln(u.latest_action?.date_created,"DD-MM-YY HH:mm")})}),s.jsx("td",{children:o?s.jsx(rB,{runStepPart:u,setRunStepPartAction:v}):s.jsx(Wg,{runStepPart:u,setRunStepPartAction:v})}),s.jsx("td",{children:s.jsx(gd,{runStepPart:u,setRunStepPart:y=>{d(y),c&&c(y)}})})]})},Wg=({runStepPart:e,setRunStepPartAction:t})=>s.jsx("div",{className:"d-flex justify-content-between gap-1",children:s.jsxs("div",{className:"d-flex gap-2",children:[e.actions===0&&s.jsx(ie,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.START_PROCESSING}),className:"btn-success btn-sm",children:"Start"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FINISH_PROCESSING}),className:"btn-primary btn-sm",children:"Finish"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(ie,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FAILED_PROCESSING}),className:"btn-danger btn-sm",children:"Failed"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&s.jsx(ie,{size:"sm",onClick:()=>t({runStepPart:e,runStepPartAction:Ne.REWORK}),children:"Rework"})]})}),rB=({runStepPart:e,setRunStepPartAction:t})=>s.jsxs(at,{align:"end",children:[s.jsx(at.Toggle,{size:"sm",variant:"outline-secondary",children:"Actions"}),s.jsxs(at.Menu,{children:[e.actions===0&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.START_PROCESSING}),children:"Start"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FINISH_PROCESSING}),children:"Finish"}),e.actions>0&&e.latest_action?.type.id!==Ne.FINISH_PROCESSING&&e.latest_action?.type.id!==Ne.FAILED_PROCESSING&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.FAILED_PROCESSING}),children:"Failed"}),e.actions>0&&s.jsx(at.Item,{onClick:()=>t({runStepPart:e,runStepPartAction:Ne.REWORK}),children:"Rework"})]})]}),J0=({run:e,runStep:t,runStepParts:n,runParts:r,refetchFn:i=()=>{},toggleRunPartRef:a})=>{const o=Ae.useQueryClient(),[l,c]=x.useState(n||[]),[u,d]=x.useState(r||[]),p=Ae.useQueries({queries:[{queryKey:["runParts",e],queryFn:()=>ba({run:e}),enabled:!r},{queryKey:["runStepParts",t.id],queryFn:()=>gs({step:t}),enabled:!n}]}),[g,m]=p,v=p.some(T=>T.isLoading),I=p.some(T=>T.isError),C=x.useMemo(()=>r??g.data?.items??[],[r,g.data]),b=x.useMemo(()=>n??m.data?.items??[],[n,m.data]);x.useEffect(()=>{const T=n??m.data?.items??[];Js(t,T)},[n,m.data]),x.useEffect(()=>{if(r){d(r);return}!v&&g.data&&d(C)},[r,g.data,C,v]),x.useEffect(()=>{if(n){c(n),Js(t,n);return}!v&&m.data&&(c(b),Js(t,b))},[n,m.data,t,b,v]);const _=x.useMemo(()=>u.filter(T=>T.part_level===t.part_level),[u,t.part_level]),{selectedParts:y,setPartAsSelected:S,selectAllParts:j,selectNoneParts:N,hasSelectedParts:k}=ap({parts:_,getPartId:T=>T.id,toggleRef:a});x.useEffect(()=>{const T=Array.from(y.entries()).filter(([,V])=>V).map(([V])=>V);o.setQueryData(["runPartSelection",t.id],T)},[o,t.id,y]);const{performActionToSelectedParts:A,getAvailableActionsForSelection:F}=$0({runStep:t,parts:_,selectedParts:y,getPartId:T=>T.id,getRunStepPart:T=>l.find(V=>V.part.id===T.id&&V.step.id===t.id),refetchFn:i}),L=x.useMemo(()=>F(),[F]),Y=x.useMemo(()=>_.filter(V=>y.get(V.id)).some(V=>!l.find(Z=>Z.part.id===V.id&&Z.step.id===t.id)),[_,y,l,t.id]),G=(T,V)=>T.findIndex(ne=>ne.id===V.id)===-1?[...T,V]:T.map(ne=>ne.id===V.id?V:ne),X=Ae.useMutation({mutationFn:async T=>T,onSuccess:T=>{c(V=>G(V,T)),o.setQueryData(["runStepParts",t.id],V=>V&&(Array.isArray(V)?G(V,T):Array.isArray(V.items)?{...V,items:G(V.items,T)}:V)),o.setQueryData(["stepParts",t.id],V=>V&&(Array.isArray(V)?G(V,T):Array.isArray(V.items)?{...V,items:G(V.items,T)}:V))}}),H=()=>{const V=_.filter(Z=>y.get(Z.id)).filter(Z=>!l.find(ne=>ne.part.id===Z.id&&ne.step.id===t.id));Promise.all(V.map(Z=>te.post("/create/run/step/part",{run_part_id:Z.id,run_step_id:t.id}))).then(()=>{o.refetchQueries({queryKey:["runStepParts",t.id]}),i&&i()})};if(v)return s.jsx(zt,{message:"Loading run parts"});if(I)throw new Error("RunPartsProductionRun should not be loading");return s.jsx(x.Fragment,{children:_.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{}),s.jsx("th",{children:"Part"}),s.jsx("th",{className:"text-center",children:"Status"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:_.map((T,V)=>s.jsx(Z0,{runStep:t,runPart:T,runStepParts:l,refetchFn:i,partIsSelected:y.get(T.id)??!1,setPartAsSelected:S,layout:"research",onRunStepPartUpdated:Z=>X.mutate(Z)},V))})]}),s.jsx(q0,{onSelectAll:j,onSelectNone:N,hasSelectedParts:k,actionsDropdown:s.jsx(X0,{availableActions:L,onActionSelected:A,showInitAction:Y,onInitSelected:H})})]})})};function Q0({run:e,step:t,stepParts:n,parts:r,refetchFn:i=()=>null}){const{run:a}=x.useContext(Ri),{showOnlyEmphasizedParameters:o}=x.useContext(Kl),l=e??a;return l?s.jsx(Ye,{className:"p-4 my-3",children:s.jsx(Ye.Body,{children:s.jsxs(Un,{children:[s.jsxs(Pt,{md:"6",children:[l.run_type===Wn.RESEARCH&&s.jsx(op,{run:l,runStep:t,runStepParts:n,refetchFn:()=>{i(["runStepParts"])}}),l.run_type===Wn.PRODUCTION&&s.jsx(J0,{run:l,runStep:t,runParts:r,refetchFn:()=>{i(["runStepParts"])}}),t.has_remark&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{children:"Remark"}),s.jsx("span",{dangerouslySetInnerHTML:{__html:t.remark}})]})]}),s.jsxs(Pt,{md:"6",children:[s.jsx("h4",{children:"Parameters"}),s.jsx(ec,{runStep:t,showOnlyEmphasizedParameters:o,refetchFn:()=>{i([JSON.stringify(t),"parameters"])}}),s.jsx("h4",{children:"Files"}),s.jsx(tc,{runStep:t,refetchFn:()=>{i(["runSteps"])}})]})]})})}):null}const wu=({runPart:e,statusClass:t,withTrayCell:n=!1,allowCreate:r=!1,hasStepPart:i=!1,isSelected:a=!1,runStep:o,reloadFn:l=()=>{}})=>{const c=Ae.useQueryClient(),u=()=>{!e||!o||te.post("/create/run/step/part",{run_part_id:e.id,run_step_id:o.id}).then(()=>{l(),c.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},d=(()=>{if(!i||!e)return null;if(r&&!i)return s.jsxs(ie,{size:"sm",variant:"outline-secondary",className:"tray-grid__badge tray-grid__badge--init",onClick:u,children:["Init ",e.label??e.short_label]});const p=`tray-grid__badge ${t??"step-part-inactive"}${a?" step-part-selected":""}`;return s.jsx("span",{className:p,children:e.label??e.short_label})})();return n?s.jsx("div",{className:`tray-grid__cell${e?"":" tray-grid__cell--empty"}`,children:d}):d},K0=({step:e,parts:t,stepParts:n,run:r,reloadFn:i})=>{const a=t.filter(m=>m.part_level===e.part_level).sort((m,v)=>m.root_id&&v.root_id&&m.root_id!==v.root_id?m.root_id-v.root_id:m.left-v.left),o=new Map(n.filter(m=>m.step.id===e.id).map(m=>[m.part.id,m])),l=[...r.run_trays??[]].sort((m,v)=>m.sequence-v.sequence),c=a.reduce((m,v)=>{if(!v.tray)return m;const I=m.get(v.tray.id)??[];return I.push(v),m.set(v.tray.id,I),m},new Map),u=r.run_type===Wn.PRODUCTION,{data:d=[]}=Ae.useQuery({queryKey:["runPartSelection",e.id],queryFn:async()=>[],initialData:[],enabled:!1}),p=m=>{const v=o.get(m.id);return v?v.part_processing_failed_in_previous_step||v.part.part_processing_failed?"step-part-failed-other":v.failed?"step-part-failed":v.processed?"step-part-processed":v.started?"step-part-started":"step-part-inactive":"step-part-inactive"};if(l.length===0){const v=Math.max(a.length,a.reduce((S,j)=>Math.max(S,j.left??0),0)),I=Math.max(1,Math.ceil(v/12)),C=12,b={"--tray-columns":C,"--tray-rows":I},_=Array.from({length:I*C},()=>null),y=[];return a.forEach(S=>{const j=S.left,N=j>=1&&j<=_.length?j-1:null;N!==null&&!_[N]?_[N]=S:y.push(S)}),y.forEach(S=>{const j=_.findIndex(N=>!N);j!==-1&&(_[j]=S)}),s.jsx("div",{className:"tray-grid","data-orientation":"ltr",style:b,children:_.map((S,j)=>s.jsx(wu,{runPart:S,statusClass:S?p(S):void 0,withTrayCell:!0,allowCreate:u,hasStepPart:S?o.has(S.id):!1,isSelected:S?d.includes(S.id):!1,runStep:e,reloadFn:i},`slot-no-tray-${j}`))})}const g=(m,v,I)=>!v||!I||v<1||I<1||v>m.rows||I>m.columns?null:m.orientation==="ttb"?(I-1)*m.rows+(v-1):(v-1)*m.columns+(I-1);return s.jsx("div",{className:"tray-grid-group",children:l.map(m=>{const v=m.tray_type;if(!v?.rows||!v?.columns){const S=c.get(m.id)??[];return s.jsxs("div",{className:"tray-grid-wrapper",children:[s.jsx("div",{className:"tray-grid__label",children:m.name??m.label}),s.jsx("div",{className:"d-flex flex-wrap gap-2",children:S.map(j=>s.jsx(wu,{runPart:j,statusClass:p(j),allowCreate:u,hasStepPart:o.has(j.id),isSelected:d.includes(j.id),runStep:e,reloadFn:i},j.id))})]},`tray-${m.id}`)}const I=v.rows*v.columns,C=v.orientation==="ttb"?"ttb":"ltr",b={"--tray-columns":v.columns,"--tray-rows":v.rows},_=Array.from({length:I},()=>null);return(c.get(m.id)??[]).forEach(S=>{const j=g(v,S.tray_row,S.tray_column);j===null||_[j]||(_[j]=S)}),s.jsxs("div",{className:"tray-grid-wrapper",children:[s.jsx("div",{className:"tray-grid__label",children:m.name??m.label}),s.jsx("div",{className:"tray-grid","data-orientation":C,style:b,children:_.map((S,j)=>{const N=S?p(S):void 0;return s.jsx(wu,{runPart:S,statusClass:N,withTrayCell:!0,allowCreate:u,hasStepPart:S?o.has(S.id):!1,isSelected:S?d.includes(S.id):!1,runStep:e,reloadFn:i},`slot-${m.id}-${j}`)})})]},`tray-${m.id}`)})})};function iB({run:e,step:t,parts:n,stepParts:r,monitoredBy:i,refetchFn:a}){const{environment:o}=Te.useParams(),[l,c]=x.useState(!1),u=()=>{c(!l)},[d,p]=x.useState(t.process_module.module);return x.useEffect(()=>{p(t.process_module.module)},[t.process_module.module]),s.jsxs(s.Fragment,{children:[s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("i",{className:"fa ms-2 "+(l?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:u})}),s.jsx("td",{className:d.latest_module_status&&d.latest_module_status.status.is_down_status?"table-danger":"",children:s.jsx(K0,{step:t,parts:n,stepParts:r,run:e,reloadFn:()=>{a(["runStepParts"])}})}),s.jsxs("td",{children:[i&&s.jsx(fs,{placement:"top",overlay:s.jsx(yi,{id:`tooltip-${i.id}`,children:`Monitored by step: ${i.step.number}`}),children:s.jsx("i",{className:"fa fa-search me-2"})}),t.amount_of_files>0&&s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&s.jsx("i",{className:"fa fa-comment-o text-warning me-3"}),t.is_finished&&s.jsx("i",{className:"fa fa-check text-success me-3"})]}),s.jsxs("td",{className:t.has_step_group?"ps-4":"",children:[t.number," - ",s.jsx(Te.Link,{to:`/${o}/operator/run/step/${t.id}`,children:s.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]}),s.jsxs("td",{children:[s.jsx(Te.Link,{to:`/${o}/operator/equipment/${d.equipment.id}`,className:"me-2",children:d.equipment.name}),s.jsx(Jr,{module:d,refetchFn:()=>{a(["runSteps"])}})]})]}),l&&s.jsx("tr",{children:s.jsx("td",{colSpan:n.length+6,children:s.jsx(Q0,{step:t,stepParts:r,parts:n,refetchFn:a})})})]})}const xd=({requirement:e,result:t,show:n,setShow:r,refetchFn:i,part:a,stepPart:o})=>{const[l,c]=x.useState({}),[u,d]=x.useState(!1),[p,g]=x.useState(null),[m,v]=x.useState(!1);x.useEffect(()=>{if(Object.keys(l).length>0)return;let y={};for(const S of e.targets){let j="";t!==void 0&&(j=t.values.find(N=>N.logging_parameter.id==S.logging_parameter.id)?.string_value??""),y[S.logging_parameter.id]=j}c(y)},[e]),x.useEffect(()=>{v(!1),g(null),d(!1)},[n]);const I=async()=>{try{g(null),v(!1),d(!0),await te.delete(`/delete/run/measurement/result/${t?.id??0}`),v(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(y){console.error(y),g("Update of results failed")}finally{d(!1)}},C=async()=>{try{g(null),v(!1),d(!0);const y=Object.entries(l).map(async([S,j])=>{const N=Number.parseInt(S),k={value:j},A=t?.values.find(F=>F.logging_parameter.id===N)?.id;await te.patch(`/update/run/measurement/result/value/${A??0}`,k)});await Promise.all(y),v(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(y){console.error(y),g("Update of results failed")}finally{d(!1)}},b=async()=>{const y={measurement:e.measurement.id,values:Object.entries(l).flatMap(S=>({logging_parameter:Number.parseInt(S[0]),value:S[1]}))};o&&(y.step_part=o?.id??0,y.part=a?.id??0,y.step=e.step.id??0);try{g(null),v(!1),d(!0),await te.post("/create/run/measurement/result",y),v(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(S){console.error(S),g("Update of results failed")}finally{d(!1)}},_=y=>{y.preventDefault(),t?C():b()};return s.jsxs(ve,{show:n,size:"lg",onHide:()=>r(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:t?s.jsx(s.Fragment,{children:"Update results"}):s.jsx(s.Fragment,{children:"Create result"})})}),s.jsxs(W,{onSubmit:_,children:[s.jsxs(ve.Body,{children:[p&&s.jsx(St,{variant:"danger",children:p}),m&&s.jsx(St,{variant:"success",children:"Results have been updated successfully"}),e.targets.map(y=>(t?.values.find(S=>S.logging_parameter.id===y.logging_parameter.id)?.string_value,s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:y.logging_parameter.name}),s.jsx(W.Control,{type:"number",step:"any",placeholder:"Thickness",value:l[y.logging_parameter.id]??"",onChange:S=>c(j=>({...j,[y.logging_parameter.id]:S.target.value}))})]},y.id)))]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{variant:"warning",onClick:()=>r(!1),children:"Close"}),u?s.jsxs(ie,{type:"submit",variant:"info",disabled:u,children:[s.jsx(Kd,{animation:"border",size:"sm",className:"me-2"})," Updating results..."]}):t?s.jsxs(s.Fragment,{children:[s.jsx(ie,{variant:"danger",disabled:u,onClick:I,children:"Delete result"}),s.jsx(ie,{type:"submit",variant:"info",disabled:u,children:"Update result"})]}):s.jsx(ie,{type:"submit",variant:"info",disabled:u,children:"Create result"})]})]})]})},rn=x.createContext({runStep:{},setRunStep:e=>{},reloadRunStep:()=>{},run:{},modalProperties:{},setModalProperties:e=>{}});function lp({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:a,editOnly:o=!1}){const{run:l}=x.useContext(rn),[c,u]=x.useState(r??[]),[d,p]=x.useState(n??[]),[g,m]=x.useState(i??[]),v=Ae.useQueryClient(),I=Ae.useQueries({queries:[{queryKey:["runParts",`${l?.id??"unknown"}`],queryFn:async()=>await ba({run:l}),enabled:!r||r.length===0,retry:1},{queryKey:["runStepParts",`${t?.run_id??"unknown"}`,`${t?.id??"unknown"}`],queryFn:async()=>await gs({step:e.requirement_for_step??e.step}),enabled:!n||n.length===0,retry:1},{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await ml({measurement:e.measurement}),enabled:!i||i.length===0,retry:1}]}),C=()=>{v.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[b,_,y]=I;x.useEffect(()=>{r&&r.length>0?u(r):b?.data&&u(b.data.items)},[r,b?.data]),x.useEffect(()=>{n&&n.length>0?p(n):_?.data&&p(_.data.items)},[n,_?.data]),x.useEffect(()=>{i&&i.length>0?m(i):y?.data&&m(y.data.items)},[i,y?.data]);const[S,j]=x.useState(null),N=r&&r.length>0?r:c,A=((n&&n.length>0?n:d)??[]).filter(T=>(N??[]).find(V=>V.id===T.part.id&&V.part_level===t.part_level)!==void 0),F=!r||r.length===0,L=!n||n.length===0,Y=!i||i.length===0,G=F&&b?.isLoading||L&&_?.isLoading||Y&&y?.isLoading,X=F&&b?.isError||L&&_?.isError||Y&&y?.isError;if(G&&A.length===0)return s.jsxs("div",{className:"d-flex align-items-center gap-2",children:[s.jsx(Kd,{animation:"border",size:"sm"})," ",s.jsx("span",{children:"Loading data…"})]});if(X&&A.length===0)return s.jsxs(St,{variant:"danger",className:"d-flex justify-content-between align-items-center",children:[s.jsx("div",{children:"Failed to load required data. Please try again."}),s.jsxs("div",{children:[F&&b?.isError&&s.jsx(ie,{size:"sm",variant:"outline-light",onClick:()=>b.refetch(),children:"Retry parts"})," ",L&&_?.isError&&s.jsx(ie,{size:"sm",variant:"outline-light",onClick:()=>_.refetch(),children:"Retry step parts"})," ",Y&&y?.isError&&s.jsx(ie,{size:"sm",variant:"outline-light",onClick:()=>y.refetch(),children:"Retry results"})]})]});const H=T=>{if(!(T&&!isNaN(parseFloat(T.string_value))))return"";const V=parseFloat(T.string_value),Z=e.targets.find(de=>de.logging_parameter.id===T.logging_parameter.id);return Z?(Z.inclusive?!(Z.min_value<=V&&Z.max_value>=V):!(Z.min_value<V&&Z.max_value>V))?"table-danger":"table-success":""};return s.jsx(s.Fragment,{children:A.length>0?s.jsxs(s.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"26%"},children:"Part"}),s.jsx("th",{children:"Parameter"}),s.jsx("th",{children:"Value"}),s.jsx("th",{children:"Unit"}),!o&&s.jsx("th",{style:{width:"1%"}})]})}),s.jsx("tbody",{children:A.map(T=>{const V=g.find(de=>de.values.some(R=>R.step_part_id===T.id)),Z=(V?.values??[]).filter(de=>de.step_part_id===T.id),ne=e.targets.length;return e.targets.map((de,R)=>{const ee=Z.find(O=>O.logging_parameter.id===de.logging_parameter.id)??null,se=ee?H(ee):"";return s.jsxs("tr",{className:se,children:[R===0&&s.jsxs("td",{rowSpan:ne,children:[T.part.short_label," ",s.jsxs("small",{className:"text-muted",children:["(",T.id,")"]})]}),s.jsx("td",{children:de.logging_parameter.name}),s.jsx("td",{children:ee?ee.string_value:s.jsx("span",{className:"text-muted",children:"not set"})}),s.jsx("td",{children:de.logging_parameter.unit?.abbr??""}),!o&&R===0&&s.jsx("td",{rowSpan:ne,className:"align-middle text-nowrap",children:s.jsxs(ie,{size:"sm",variant:V?"outline-primary":"outline-success",onClick:()=>j(String(T.id)),children:[s.jsx("i",{className:"fa fa-edit"})," ",V?"Edit values":"Add values"]})})]},`${T.id}:${de.logging_parameter.id}`)})})})]}),!o&&A.map(T=>{const V=g.find(Z=>Z.values.some(ne=>ne.step_part_id===T.id));return s.jsx(xd,{requirement:e,...V?{result:V}:{part:T.part,stepPart:T},show:S===String(T.id),setShow:Z=>{Z||j(null)},refetchFn:a??C},`modal:${T.id}`)})]}):s.jsx(St,{variant:"secondary",className:"mb-0",children:"No selected parts"})})}function ew({requirement:e,measurementResults:t,refetchFn:n,editOnly:r=!1}){const[i,a]=x.useState(t??[]),o=Ae.useQueryClient(),l=Ae.useQueries({queries:[{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await ml({measurement:e.measurement}),enabled:!t||t.length===0,retry:1}]}),c=()=>{o.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[u]=l;x.useEffect(()=>{t&&t.length>0?a(t.filter(b=>b.values.some(_=>!_.step_part_id))):u?.data&&a(u.data.items.filter(b=>b.values.some(_=>!_.step_part_id)))},[t,u?.data]);const[d,p]=x.useState(null),[g,m]=x.useState(!1),v=l.some(b=>b.isLoading);if(l.some(b=>b.isError))return l.filter(b=>b.isError).forEach((b,_)=>{console.error("StepDashboard query error",{index:_,error:b.error})}),s.jsx(s.Fragment,{children:"Error fetching data"});if(v)return s.jsx("div",{children:"Loading..."});const C=b=>{if(!(b&&!isNaN(parseFloat(b.string_value))))return"";const _=parseFloat(b.string_value),y=e.targets.find(j=>j.logging_parameter.id===b.logging_parameter.id);return y&&(y.inclusive?!(y.min_value<=_&&y.max_value>=_):!(y.min_value<_&&y.max_value>_))?"table-danger":""};return s.jsxs("div",{className:"d-flex flex-column gap-4",children:[i.map(b=>s.jsxs("div",{className:"border rounded p-3 shadow-sm",children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[s.jsxs("h6",{className:"mb-0",children:["Result ",s.jsxs("small",{className:"text-muted",children:["#",b.id]})]}),!r&&s.jsxs(ie,{size:"sm",variant:"outline-primary",onClick:()=>p(b.id),children:[s.jsx("i",{className:"fa fa-edit"})," Update value"]})]}),s.jsxs("table",{className:"table table-striped table-sm mb-0",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Parameter"}),s.jsx("th",{children:"Value"}),s.jsx("th",{children:"Unit"})]})}),s.jsx("tbody",{children:b.values.map(_=>s.jsxs("tr",{className:_?C(_):"",children:[s.jsx("td",{children:_.logging_parameter.name}),s.jsx("td",{children:_.string_value}),s.jsx("td",{children:_.logging_parameter.unit?.abbr??""})]},`value:${_.id}`))})]}),s.jsx(xd,{requirement:e,result:b,show:d===b.id,setShow:_=>{_||p(null)},refetchFn:n??c})]},b.id)),s.jsx("div",{className:"mt-3",children:s.jsxs(ie,{size:"sm",onClick:()=>m(!g),children:[s.jsx("i",{className:"fa fa-plus"})," Add results"]})}),s.jsx(xd,{requirement:e,show:g,setShow:b=>{b||m(!1)},refetchFn:n??c})]})}function sB({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:a}){const{environment:o}=Te.useParams();return s.jsx(Ye,{className:"p-4 my-3",children:s.jsx(Ye.Body,{children:s.jsxs(Un,{children:[s.jsxs(Pt,{md:"7",children:[s.jsx("h4",{children:"Measurements by part"}),s.jsx(lp,{requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:a}),s.jsx("h4",{children:"Measurements for whole step"}),s.jsx(ew,{requirement:e,measurementResults:i,refetchFn:a})]}),s.jsxs(Pt,{md:"5",children:[s.jsx("h4",{children:"Monitored Step"}),s.jsx(Te.Link,{to:`/${o}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),s.jsx("h4",{children:"Definition"}),s.jsx("span",{children:e.definition}),s.jsx("h4",{children:"Targets"}),s.jsxs(Ht,{size:"sm",striped:!1,bordered:!1,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"parameter"}),s.jsx("th",{children:"min value"}),s.jsx("th",{children:"max value"}),s.jsx("th",{children:"inclusive"})]})}),s.jsx("tbody",{children:e.targets.map(l=>s.jsxs("tr",{children:[s.jsx("td",{children:l.logging_parameter.name}),s.jsx("td",{children:l.min_value}),s.jsx("td",{children:l.max_value}),s.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]}),s.jsx("h4",{children:"Files"}),s.jsx(tc,{runStep:t,refetchFn:()=>{a(["requirements"])}})]})]})})})}const tw=({requirement:e,step:t,measurementResults:n,parts:r,stepParts:i})=>{const a=r.filter(u=>u.part_level===t.part_level).sort((u,d)=>u.root_id&&d.root_id&&u.root_id!==d.root_id?u.root_id-d.root_id:u.left-d.left),o=a.reduce((u,d)=>{const p=d.root_id??d.id;return u[p]||(u[p]=[]),u[p].push(d),u},{}),l=u=>{const d=i.find(g=>g.part.id===u.id);if(!d)return"badge-inactive";const p=n.find(g=>g.values.some(m=>m.step_part_id===d.id));if(!p)return"";for(const g of p.values){const m=parseFloat(g.string_value),v=e.targets.find(I=>I.logging_parameter.id==g.logging_parameter.id);if(v){if(v.inclusive){if(!(v.min_value<=m&&v.max_value>=m))return"badge-failed"}else if(!(v.min_value<m&&v.max_value>m))return"badge-failed"}}return"badge-processed"},c=u=>s.jsx(fs,{placement:"top",overlay:s.jsx(yi,{id:`tooltip-${u.id}`,children:`Level: ${u.part_level}${u.parent?`, Parent: ${u.parent.short_label}`:""}`}),children:s.jsx("span",{className:`badge badge-level-${u.part_level} ${l(u)} me-1`,children:u.short_label},u.id)},u.id);return s.jsxs("div",{children:[a[0].parent?Object.entries(o).map(([u,d])=>s.jsxs("div",{className:"mb-2",children:[s.jsxs("label",{className:"text-muted me-1",children:[d[0].parent?.short_label,":"]})," ",d.map(p=>c(p))]},u)):a.map(u=>c(u)),s.jsx("label",{children:"(measurements)"})]})};function aB({requirement:e,step:t,parts:n,stepParts:r,refetchFn:i}){const{environment:a}=Te.useParams(),[o,l]=x.useState(!1),[c,u]=x.useState(t.process_module.module);x.useEffect(()=>{u(t.process_module.module)},[t.process_module.module]);const d=()=>{l(!o)},p=Ae.useQueryClient(),g=Ae.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>ml({measurement:e.measurement})}]}),m=b=>{b[0]==="requirement"&&p.refetchQueries({queryKey:b}),i(b)},[v]=g,I=g.some(b=>b.isLoading),C=b=>{if(b.length==0)return I?"":"table-info";let _=!1;for(const y of b)if(y.values.some(j=>{if(!(j&&!isNaN(parseFloat(j.string_value))))return!1;const N=parseFloat(j.string_value),k=e.targets.find(A=>A.logging_parameter.id==j.logging_parameter.id);return k?k.inclusive?!(k.min_value<=N&&k.max_value>=N):!(k.min_value<N&&k.max_value>N):!1})){_=!0;break}return _?"table-danger":""};return s.jsxs(s.Fragment,{children:[s.jsxs("tr",{className:C(v.data?.items??[]),children:[s.jsx("td",{children:s.jsx("i",{className:"fa ms-2 "+(o?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:d})}),s.jsx("td",{children:s.jsx(tw,{requirement:e,step:t,measurementResults:v.data?.items??[],parts:n,stepParts:r})}),s.jsxs("td",{children:[s.jsx(Ft,{bg:"info",children:"requirement"}),t.amount_of_files>0&&s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&s.jsx("i",{className:"fa fa-comment-o text-warning"})]}),s.jsx("td",{className:t.has_step_group?"ps-4":"",children:s.jsxs("div",{children:["(",t.number,")"," ",s.jsx(Te.Link,{to:`/${a}/operator/run/step/${t.id}`,children:s.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]})}),s.jsxs("td",{children:[s.jsx(Te.Link,{to:`/${a}/operator/equipment/${c.equipment.id}`,className:"me-2",children:c.equipment.name}),s.jsx(Jr,{module:c,refetchFn:()=>{i(["runSteps"])}})]})]}),o&&s.jsx("tr",{children:s.jsx("td",{colSpan:n.length+5,children:I?"Loading...":s.jsx(sB,{requirement:e,step:t,stepParts:r,parts:n,measurementResults:v.data?.items??[],refetchFn:m})})})]})}function oB(){const{run:e}=x.useContext(Ri),{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n}=x.useContext(Kl),[r,i]=x.useState(1),[a]=x.useState(25),[o,l]=x.useState(new Map),c=Ae.useQueryClient(),u=Ae.useQueries({queries:[{queryKey:["runSteps",JSON.stringify(e),r],queryFn:()=>Sd({run:e,page:r,pageSize:a}),placeholderData:Ae.keepPreviousData},{queryKey:["runParts",JSON.stringify(e)],queryFn:()=>ba({run:e})},{queryKey:["runStepParts",JSON.stringify(e)],queryFn:()=>gs({run:e})},{queryKey:["requirements",JSON.stringify(e)],queryFn:()=>Cd({run:e})}]}),d=L=>{const Y=[...L,JSON.stringify(e)];L[0]==="runSteps"&&Y.push(r),c.refetchQueries({queryKey:Y})},[p,g,m,v]=u,I=u.some(L=>L.isLoading),C=u.some(L=>L.isError);C&&u.filter(L=>L.isError).forEach((L,Y)=>{console.error("RunStepsElement query error",{index:Y,error:L.error,run:e})});const b=x.useMemo(()=>p.data?.items??[],[p.data?.items]),_=x.useMemo(()=>g.data?.items??[],[g.data?.items]),y=x.useMemo(()=>m.data?.items??[],[m.data?.items]),S=x.useMemo(()=>v.data?.items??[],[v.data?.items]);if(x.useEffect(()=>{l(L=>{const Y=new Map(L);return b.forEach(G=>{const X=G.label?.id;X!==void 0&&!Y.has(X)&&Y.set(X,!0)}),Y})},[b]),I)return s.jsx("div",{children:"Loading..."});if(C)return s.jsx("div",{className:"text-danger",children:"Error loading run steps."});const j=new Set,N=b.filter(L=>!L.has_step_group||typeof L.step_group?.id!="number"||j.has(String(L.step_group.id))?!1:(j.add(String(L.step_group.id)),!0)),k={};for(const L of S)L.requirement_for_step!=null&&(k[String(L.requirement_for_step.id)]=L);const A=L=>s.jsx("tr",{style:{pointerEvents:"none"},children:s.jsx("td",{colSpan:5,style:{margin:0},className:"bg-info",children:s.jsx("span",{children:L.step_group?.label})})}),F=L=>{const Y=L.label,G=Y?.id;if(!L.is_own_label||!Y||G===void 0)return null;const X=H=>{l(T=>{const V=new Map(T);return V.set(H,!V.get(H)),V})};return s.jsx("tr",{style:{cursor:"pointer"},onClick:()=>X(G),children:s.jsx("td",{colSpan:5,style:{margin:0},className:"bg-secondary",children:s.jsxs("span",{className:"label-toggle",children:[s.jsx("i",{className:"fa "+(o.get(L.label?.id??-1)?"fa-caret-down":"fa-caret-right")})," ",Y.label]})})})};return s.jsxs("div",{children:[s.jsx("h2",{children:"Run steps"}),s.jsx("div",{className:"d-flex justify-content-between align-items-center",children:s.jsxs("div",{className:"form-check form-switch",children:[s.jsx("input",{type:"checkbox",checked:t,className:"form-check-input","data-toggle":"toggle",onChange:()=>n(!t)}),s.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]})}),s.jsxs(Ht,{borderless:!0,hover:!0,striped:!0,size:"sm",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{}),s.jsx("th",{children:"Parts"}),s.jsx("th",{}),s.jsx("th",{children:"Process"}),s.jsx("th",{children:"Equipment"})]})}),s.jsx("tbody",{children:b.map((L,Y)=>{const G=`step-${L.id}`;return s.jsxs(x.Fragment,{children:[L.has_label&&F(L),(!L.has_label||o.get(L.label?.id??-1))&&s.jsxs(s.Fragment,{children:[L.has_step_group&&N.includes(L)&&A(L),L.has_requirement?(()=>{const X=S.find(H=>H.step.id===L.id);return s.jsx(aB,{requirement:X,step:L,parts:_,stepParts:y.filter(H=>H.step.id===(X.requirement_for_step?.id??X.step.id)),refetchFn:d})})():s.jsx(iB,{run:e,step:L,parts:_,stepParts:y.filter(X=>X.step.id===L.id),monitoredBy:k[L.id],refetchFn:d})]})]},G)})})]}),s.jsx(za,{data:p.data,setPage:i,isPlaceholderData:p.isPlaceholderData})]})}function lB(){const{run:e}=x.useContext(Ri);return s.jsxs("div",{children:[s.jsx("h2",{children:"Run information"}),s.jsx("h3",{children:"Run name"}),s.jsx("p",{children:e.name}),s.jsx("h3",{children:"Project name"}),s.jsx("p",{children:e.project.name})]})}const cB=()=>{const[e,t]=x.useState(null),[n,r]=x.useState(null),{id:i}=Te.useParams();x.useEffect(()=>{(e===null||i!==e.id.toString())&&Zp({id:parseInt(i)}).then(o=>(Fo({id:o.run_id}).then(r),o)).then(t)},[i,e]);function a(){Zp({id:parseInt(i)}).then(o=>(Fo({id:o.run_id}).then(r),o)).then(t)}return{run:n,runStep:e,setRunStep:t,reloadRunStep:a}};function nw({children:e}){const{runStep:t,setRunStep:n,run:r,reloadRunStep:i}=cB(),[a,o]=x.useState({});if(t===null||r===null){let l="Loading run...";return t===null&&r===null?l="Loading run and run step...":r===null&&(l="Loading run step..."),s.jsx(jn,{children:s.jsx(zt,{message:l})})}return s.jsx(jn,{children:s.jsx(rn.Provider,{value:{runStep:t,setRunStep:n,reloadRunStep:i,run:r,modalProperties:a,setModalProperties:o},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function uB(){return s.jsx(nw,{children:s.jsx(Ii,{fluid:!0,children:s.jsx(Te.Outlet,{})})})}const dB=({label:e})=>s.jsx("div",{className:"p-2 h4 mb-1 bg-info text-white",children:e.label}),fB=({runStep:e})=>{const{environment:t}=Te.useParams();return s.jsxs("h2",{children:[" ",e.number," -",e.process_module.process.name," on"," ",s.jsxs(Te.Link,{to:`/${t}/operator/equipment/${e.process_module.module.equipment.id}`,children:[e.process_module.module.equipment.name," (",e.process_module.module.name,")"]})]})},pB=({checklistItem:e,show:t,setModalShow:n,mutation:r})=>{const i=()=>n(!1);return s.jsxs(ve,{show:t,size:"lg",onHide:i,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Checklist item"})}),s.jsxs(ve.Body,{children:[s.jsx("h2",{children:e.task}),s.jsx("span",{dangerouslySetInnerHTML:{__html:e.description}})]}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{className:"float-end",variant:"primary",onClick:()=>{r.mutate()},children:"Done"}),s.jsx(ie,{variant:"secondary",onClick:()=>n(!1),children:"Close"})]})]})};function mB({checklistItem:e,onOpenModal:t,onMarkDone:n}){return e.can_finish?e.description!==""?s.jsx(ie,{className:"float-end",variant:"primary",onClick:t,children:"Execute checklist step"}):s.jsx(ie,{className:"float-end",size:"sm",variant:"success",onClick:n,children:"Done checklist step"}):null}const rw=({checklistItem:e,refetch:t})=>{const[n,r]=x.useState(!1),i=async()=>(await te.create().patch("update/run/step/checklist/done/"+e.id,{})).data,a=Ae.useMutation({mutationFn:i,onSuccess:o=>{r(!1),t()}});return s.jsxs(wn.Item,{disabled:e.is_executed,className:"d-flex justify-content-between align-items-start",children:[s.jsxs("div",{className:"d-flex flex-column",children:[e.task,e.is_executed&&s.jsxs("small",{children:["Executed on ",s.jsx(wi,{format:"DD-MM-YYYY",children:e.date_executed})]})]}),s.jsx("div",{className:"flex-shrink-0",children:s.jsx(mB,{checklistItem:e,onOpenModal:()=>r(!0),onMarkDone:()=>a.mutate()})}),s.jsx(pB,{checklistItem:e,show:n,setModalShow:r,mutation:a})]})},Nn={movingOut:"Moving out...",skipping:"Skipping...",unskipping:"Unskipping...",operationFinished:"Operation finished",operationSkipped:"Operation skipped",operationUnskipped:"Operation unskipped"};function iw({run:e,runStep:t,reloadRunStep:n}){const r=Te.useNavigate(),{environment:i}=Te.useParams(),[a,o]=x.useState(null),[l,c]=x.useState(!1),{run:u,runStep:d,reloadRunStep:p}=x.useContext(rn);x.useEffect(()=>{if(a){const A=setTimeout(()=>{o(null)},3e3);return()=>clearTimeout(A)}},[a]);const g=e??u,m=t??d,v=n??p??(()=>null),{data:I,error:C,isLoading:b,refetch:_}=Ae.useQuery({queryKey:["checklist",m?.id],queryFn:()=>rx({runStep:m}),enabled:!!m}),y=x.useCallback(async A=>{o(Nn.movingOut),c(!0);try{const F=await jd(A);o(Nn.operationFinished),F.data.next_step_id!==null?r(`/${i}/operator/run/step/${F.data.next_step_id}`):v()}finally{c(!1)}},[i,r,v]),S=x.useCallback(async A=>{o(Nn.skipping),c(!0);try{await te.create().patch(`update/run/step/skip/${A.id}`,{}),o(Nn.operationSkipped),v()}finally{c(!1)}},[v]),j=x.useCallback(async A=>{o(Nn.unskipping),c(!0);try{await te.create().patch(`update/run/step/un-skip/${A.id}`,{}),o(Nn.operationUnskipped),v()}finally{c(!1)}},[v]),{checklistItems:N,canFinishOperation:k}=x.useMemo(()=>{const A=I?.items??[],F=A.findIndex(G=>!G.is_executed),L=A.map((G,X)=>({...G,can_finish:X===F})),Y=!!(m&&!m.is_finished&&F===-1);return{checklistItems:L,canFinishOperation:Y}},[I,m]);return!m||!g?s.jsx(s.Fragment,{children:"Please set RunStepContext in RunStepChecklist"}):b?s.jsx(zt,{message:"Loading..."}):C?s.jsx(St,{variant:"danger",children:"Failed to load checklist."}):s.jsxs(s.Fragment,{children:[N.length===0&&s.jsx(St,{variant:"info",children:"No checklist found"}),N.length>0&&s.jsx(wn,{children:N.map(A=>s.jsx(rw,{checklistItem:A,refetch:_},A.id))}),s.jsxs("div",{className:"d-flex justify-content-between mt-3",children:[s.jsxs("div",{className:"d-flex gap-2 align-items-center",children:[k&&s.jsx("div",{children:s.jsx(ie,{variant:"success",onClick:()=>y(m),disabled:l,children:a===Nn.operationFinished||a===Nn.movingOut?a:"Move out"})}),g.access.edit&&!m.is_skipped&&s.jsx("div",{children:s.jsx(ie,{variant:"primary",onClick:()=>S(m),disabled:l,children:a===Nn.operationSkipped||a===Nn.skipping?a:"Skip operation"})}),g.access.edit&&m.is_skipped&&s.jsx("div",{children:s.jsx(ie,{variant:"warning",onClick:()=>j(m),disabled:l,children:a===Nn.operationUnskipped||a===Nn.unskipping?a:"Unskip operation"})})]}),s.jsx("div",{className:"d-flex gap-2",children:m.next_step_id&&s.jsx("div",{children:s.jsx(Te.Link,{to:`/${i}/operator/run/step/${m.next_step_id}`,className:"btn btn-secondary",children:"Next step"})})})]})]})}const zg=()=>{};function sw({runStep:e,reloadRunStep:t,title:n="Remark",titleClassName:r="mb-2 text-start"}){const{runStep:i,setRunStep:a}=x.useContext(rn),o=e??i,l=t?()=>t():e?zg:a??zg,[c,u]=x.useState(!1),d=o?!o.is_finished:!1,p=!!o?.remark?.trim(),{register:g,handleSubmit:m,formState:v,reset:I}=tn({defaultValues:{remark:o?.remark_unparsed??""}}),{isSubmitting:C}=v;x.useEffect(()=>{I({remark:o?.remark_unparsed??""})},[I,o?.remark_unparsed]);const b=x.useCallback(async _=>{if(!o)return;await te.patch("update/run/step/"+o.id,{remark:_.remark});const y=await te.get("view/run/step/"+o.id);l({...o,remark:y.data.remark,remark_unparsed:y.data.remark_unparsed}),u(!1)},[o,l]);return o?!c||!d?s.jsxs("div",{children:[s.jsx("h3",{className:r,children:n}),!p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-muted",children:"No remark."}),d&&s.jsx(ie,{variant:"primary",className:"ms-auto",size:"sm",onClick:()=>u(!0),children:"Add remark"})]}),p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-success",dangerouslySetInnerHTML:{__html:o.remark}})," ",d&&s.jsx(ie,{variant:"primary",className:"mt-3",onClick:()=>u(!0),children:"Edit remark"})]})]}):s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:r,children:n}),s.jsxs(W,{onSubmit:m(b),children:[s.jsx(W.Control,{as:"textarea",rows:6,...g("remark")}),s.jsx("p",{children:s.jsx("small",{className:"text-muted",children:"If a non-conformity happens, note it here"})}),s.jsxs(ie,{variant:"primary",type:"submit",disabled:C,children:[C&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save remark"]}),s.jsx(ie,{variant:"secondary",className:"ms-2",onClick:()=>u(!1),children:"Cancel"})]})]}):s.jsx(s.Fragment,{children:"Please set RunStepContext for StepRemark"})}const hB=({run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})=>{const[a,o]=x.useState(!1),{register:l,control:c,setValue:u,handleSubmit:d,formState:p}=tn({defaultValues:{holdCode:r?{value:r.hold_code.id,label:r.hold_code.code}:{},description:r?r.description:""}}),{errors:g,isSubmitting:m}=p,v=async C=>{try{const b=await te.patch("update/run/hold-code/"+e.id,{holdcode:a?null:C.holdCode.value,description:C.description});b.data.hold_code?i(b.data):i(void 0),o(!1)}finally{n(!1)}},I=(C,b)=>{te.get("list/run/hold-code").then(_=>{const{data:y}=_;return y._embedded.items}).then(_=>{b(_.map(y=>({value:y.id,label:y.code})))})};return s.jsx(ve,{show:t,size:"lg",onHide:()=>n(!1),children:s.jsxs(W,{onSubmit:d(v),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:a?"Reset hold code":"Update hold code"})}),s.jsxs(ve.Body,{children:[!a&&s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Hold code"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(Fn,{name:"holdCode",control:c,rules:{validate:{required:C=>C.value!==void 0||a||"A hold code is required"}},render:({field:C})=>s.jsx(Fl,{isSearchable:!1,defaultOptions:!0,placeholder:"Select a hold code",loadOptions:I,value:C.value,onChange:b=>{C.onChange(b)}})}),g.holdCode&&s.jsx("span",{className:"text-danger",children:g.holdCode.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Message"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"textarea",rows:3,...l("description",{required:"A message is required"}),isInvalid:g.description!==void 0}),g.description&&s.jsx(W.Control.Feedback,{type:"invalid",children:g.description.message})]})]})]}),s.jsxs(ve.Footer,{children:[s.jsxs(ie,{type:"submit",variant:a?"success":"primary",disabled:m,children:[m&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),a?"Release lot":"Update Hold code"]}),r&&s.jsx(ie,{variant:"outline-danger",onClick:()=>{u("description",a?r.description:""),o(!a)},children:a?"Update hold Code":"Reset hold code"})]})]})})},gB=()=>{const{run:e}=x.useContext(rn),[t,n]=x.useState(!1),[r,i]=x.useState(e.hold_code),a=()=>{n(!0)};return s.jsxs(s.Fragment,{children:[r&&s.jsx("span",{className:"badge handle",style:{backgroundColor:r.hold_code.back_color,color:r.hold_code.front_color,fontSize:"1.5rem",cursor:"pointer"},onClick:()=>a(),children:r.hold_code.code}),!r&&s.jsx(Ft,{bg:"secondary",className:"handle",onClick:()=>a(),style:{fontSize:"1.5rem",cursor:"pointer"},children:"No hold code"}),s.jsx(hB,{run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})]})},xB=()=>{const{run:e}=x.useContext(rn),[t,n]=x.useState(e.priority);return s.jsxs(x.Fragment,{children:[t&&s.jsx("span",{className:"badge",style:{backgroundColor:t.priority.back_color,color:t.priority.front_color,fontSize:"1.5rem"},children:t.priority.code}),!t&&s.jsx("span",{className:"badge bg-info",style:{fontSize:"1.5rem"},children:"NORMAL"})]})},vB=({run:e,runStep:t,showOnlyEmphasizedParameters:n})=>s.jsx(s.Fragment,{children:s.jsx("div",{className:"border rounded px-3 py-3",children:s.jsxs("div",{className:"d-flex flex-wrap gap-3",children:[s.jsx("div",{style:{flexGrow:1,flex:"1 1 360px"},children:s.jsx(op,{run:e,editable:!1,runStep:t})}),s.jsxs("div",{style:{flexGrow:1,flex:"1 1 360px"},children:[n&&s.jsx("h4",{children:"Emphasized parameters"}),!n&&s.jsx("h4",{children:"Parameters"}),s.jsx(ec,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:n})]})]})})}),yB=({run:e,monitoredBy:t,runStep:n,runParts:r,runStepParts:i,hideLabel:a,firstInGroup:o})=>{const{environment:l}=Te.useParams(),[c,u]=x.useState(!1),{runStep:d}=x.useContext(rn);return s.jsxs(s.Fragment,{children:[!a&&n.has_label&&n.is_own_label&&s.jsx("div",{className:"bg-info text-white rounded px-3 py-1",children:n.label?.label}),n.step_group&&o&&s.jsx("div",{className:"bg-secondary text-white rounded px-3 py-1",children:n.step_group?.label}),s.jsxs("div",{className:`d-flex flex-wrap align-items-center gap-3 border rounded px-3 py-2 ${n.has_step_group?"ms-4":""}`,children:[s.jsxs("div",{className:"d-flex align-items-center gap-2 flex-shrink-0",children:[n.id!==d.id&&s.jsx("i",{className:"fa "+(c?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{u(!c)}}),n.id===d.id&&s.jsx("i",{className:"fa fa-chevron-right text-success",style:{cursor:"pointer"},title:"This step is currently running"})]}),s.jsxs("div",{className:"d-flex flex-wrap align-items-center gap-3 flex-grow-1 min-w-0",children:[s.jsx("div",{className:"flex-shrink-0",children:s.jsx(K0,{step:n,parts:r,stepParts:i,run:e})}),s.jsxs("div",{className:"flex-shrink-0 text-nowrap",children:[n.number," ",n.is_skipped&&s.jsx(Ft,{bg:"info",children:"Skipped"})]}),s.jsxs("div",{className:"flex-grow-1 min-w-0",children:[s.jsx(Te.Link,{to:`/${l}/operator/run/step/${n.id}`,dangerouslySetInnerHTML:{__html:n.name}})," ",t&&s.jsx(fs,{placement:"top",overlay:s.jsx(yi,{id:`tooltip-${t.id}`,children:`Monitored by step: ${t.step.number}`}),children:s.jsx("i",{className:"fa fa-search me-2"})})]})]}),s.jsxs("div",{className:"d-flex align-items-center gap-3 flex-shrink-0 ms-auto",children:[s.jsx("span",{className:"text-nowrap",children:n.finish_user?n.finish_user.initials:""}),s.jsx("span",{className:"text-nowrap",children:n.has_rework?s.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),s.jsx("span",{className:"text-nowrap",children:n.is_finished?s.jsx(wi,{format:"DD-MM-YYYY",children:n.finish_date}):""})]})]}),c&&s.jsx(vB,{run:e,runStep:n,showOnlyEmphasizedParameters:!1})]})};function bB({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i}){const a=n.filter(l=>l.step.id===(e.requirement_for_step?.id??e.step.id)),{environment:o}=Te.useParams();return s.jsx(s.Fragment,{children:s.jsx("div",{className:"border rounded px-3 py-3",children:s.jsxs("div",{className:"d-flex flex-wrap gap-3",children:[s.jsxs("div",{style:{flexGrow:1,flex:"1 1 360px"},children:[s.jsx("h4",{children:"Measurement results"}),s.jsx(lp,{requirement:e,step:t,stepParts:a,parts:r,measurementResults:i,editOnly:!0})]}),s.jsxs("div",{style:{flexGrow:1,flex:"1 1 360px"},children:[s.jsx("h4",{children:"Monitored Step"}),s.jsx(Te.Link,{to:`/${o}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:s.jsxs("span",{children:[s.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),s.jsx("h4",{children:"Definition"}),s.jsx("span",{children:e.definition}),s.jsx("h4",{children:"Targets"}),s.jsxs(Ht,{size:"sm",striped:!1,bordered:!1,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"min value"}),s.jsx("th",{children:"max value"}),s.jsx("th",{children:"inclusive"})]})}),s.jsx("tbody",{children:e.targets.map(l=>s.jsxs("tr",{children:[s.jsx("td",{children:l.min_value}),s.jsx("td",{children:l.max_value}),s.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]})]})]})})})}function wB({requirement:e,runParts:t,runStepParts:n,hideLabel:r,firstInGroup:i}){const a=e.step,{environment:o}=Te.useParams(),{runStep:l}=x.useContext(rn),[c,u]=x.useState(!1),d=Ae.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>ml({measurement:e.measurement})}]}),[p]=d,g=()=>{if(!p.data)return"";let m=!1;for(const v of n){const I=p.data?.items.find(_=>_.values.some(y=>y.step_part_id===v.id))?.values.find(_=>_.step_part_id===v.id);if(!(I&&!isNaN(parseFloat(I.string_value))))return a.id===l.id?"bg-success-subtle":"";const C=parseFloat(I.string_value);if(e.targets.some(_=>_.inclusive?!(_.min_value<=C&&_.max_value>=C):!(_.min_value<C&&_.max_value>C))){m=!0;break}}return m?"bg-danger-subtle":a.id===l.id?"bg-success-subtle":""};return s.jsxs(s.Fragment,{children:[!r&&a.has_label&&a.is_own_label&&s.jsx("div",{className:"bg-info text-white rounded px-3 py-1",children:a.label?.label}),a.step_group&&i&&s.jsx("div",{className:"bg-secondary text-white rounded px-3 py-1",children:a.step_group?.label}),s.jsxs("div",{className:`d-flex flex-wrap align-items-center gap-3 border rounded px-3 py-2 ${g()} ${a.has_step_group?"ms-4":""}`,children:[s.jsx("div",{className:"d-flex align-items-center gap-2 flex-shrink-0",children:a.id!==l.id&&s.jsx("i",{className:"fa "+(c?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{u(!c)}})}),s.jsxs("div",{className:"d-flex flex-wrap align-items-center gap-3 flex-grow-1 min-w-0",children:[s.jsx("div",{className:"flex-shrink-0",children:s.jsx(tw,{requirement:e,step:a,parts:t,stepParts:n,measurementResults:p.data?.items??[]})}),s.jsxs("div",{className:"flex-shrink-0 text-nowrap",children:[a.number," ",a.is_skipped&&s.jsx(Ft,{bg:"info",children:"Skipped"})]}),s.jsxs("div",{className:"flex-grow-1 min-w-0",children:[s.jsx(Ft,{bg:"info",children:"requirement"})," ",s.jsx(Te.Link,{to:`/${o}/operator/run/step/${a.id}`,dangerouslySetInnerHTML:{__html:a.name}})," "]})]}),s.jsxs("div",{className:"d-flex align-items-center gap-3 flex-shrink-0 ms-auto",children:[s.jsx("span",{className:"text-nowrap",children:a.finish_user?a.finish_user.initials:""}),s.jsx("span",{className:"text-nowrap",children:a.has_rework?s.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),s.jsx("span",{className:"text-nowrap",children:a.is_finished?s.jsx(wi,{format:"DD-MM-YYYY",children:a.finish_date}):""})]})]}),c&&s.jsx(bB,{requirement:e,step:a,stepParts:n,parts:t,measurementResults:p.data?.items??[]})]})}const aw=({pageSize:e=25,hideLabel:t=!1})=>{const{runStep:n,run:r}=x.useContext(rn),[i,a]=x.useState(1);x.useEffect(()=>{n?.sequence&&a(Math.max(1,Math.ceil(n.sequence/e)))},[n?.sequence,e]);const o=r?.id??null,l=Ae.useQuery({queryKey:["runParts",`${o}`],queryFn:()=>ba({run:r}),enabled:!!o}),c=Ae.useQuery({queryKey:["runStepParts",`${o}`],queryFn:()=>gs({run:r}),enabled:!!o}),u=Ae.useQuery({queryKey:["runSteps",o,i,e],queryFn:()=>Sd({run:r,page:i,pageSize:e}),enabled:!!o,placeholderData:Ae.keepPreviousData}),d=Ae.useQuery({queryKey:["requirements",o],queryFn:()=>Cd({run:r}),enabled:!!o,placeholderData:Ae.keepPreviousData}),p=l.isLoading||c.isLoading||u.isLoading||d.isLoading,g=l.isError||c.isError||u.isError||d.isError,m=l.error||c.error||u.error||d.error,v=l.data?.items??[],I=c.data?.items??[],C=u.data?.items??[],b=d.data?.items??[],_=new Set,y=C.filter(j=>!j.has_step_group||typeof j.step_group?.id!="number"||_.has(String(j.step_group.id))?!1:(_.add(String(j.step_group.id)),!0)),S={};for(const j of b)j.requirement_for_step!=null&&(S[String(j.requirement_for_step.id)]=j);return x.useEffect(()=>{g&&console.error("RunStepSimpleList query error",{runId:o,errors:[l.error,c.error,u.error,d.error]})},[g,o,l.error,c.error,u.error,d.error]),s.jsxs("div",{children:[p?s.jsx("div",{children:"Loading..."}):g?s.jsxs("div",{children:["Error: ",String(m?.message??m)]}):s.jsx("div",{className:"d-flex flex-column gap-2",children:C.map((j,N)=>s.jsx(x.Fragment,{children:j.has_requirement?(()=>{const k=b.find(A=>A.step.id===j.id);return s.jsx(wB,{requirement:k,runParts:v,runStepParts:I,firstInGroup:y.includes(j)},j.id??j.sequence??N)})():s.jsx(yB,{run:r,monitoredBy:S[j.id],runParts:v,runStepParts:I,hideLabel:t,firstInGroup:y.includes(j),runStep:j},j.id??j.sequence??N)},N))}),s.jsx(za,{data:u.data,setPage:a,isPlaceholderData:u.isPlaceholderData}),u.isFetching?s.jsx("span",{children:" Loading..."}):null]})},CB=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(rn),[r,i]=x.useState(1),{isPending:a,isLoading:o,isError:l,error:c,data:u,isFetching:d,isPlaceholderData:p}=Ae.useQuery({queryKey:["run_changelog",n,r],queryFn:()=>A1({run:n,page:r}),placeholderData:Ae.keepPreviousData});return s.jsxs(ve,{show:e,size:"lg",onHide:()=>t(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsxs(ve.Title,{children:["History of Run ",n.label]})}),s.jsx(ve.Body,{children:s.jsxs("div",{children:[a?s.jsx("div",{children:"Loading..."}):l?s.jsxs("div",{children:["Error: ",c.message]}):s.jsx(Ht,{size:"sm",striped:!0,bordered:!0,hover:!0,children:s.jsx("tbody",{children:u.items.map((g,m)=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(wi,{format:"DD-MM-YYYY",children:g.date_created})}),s.jsx("td",{children:s.jsx("span",{dangerouslySetInnerHTML:{__html:g.message}})}),s.jsxs("td",{children:[g.user.first_name," ",g.user.last_name]})]},m))})}),s.jsx(za,{data:u,setPage:i,isPlaceholderData:p}),d?s.jsx("span",{children:" Loading..."}):null]})}),s.jsx(ve.Footer,{children:s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},SB=({size:e})=>{const[t,n]=x.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(ie,{size:e,variant:"primary",onClick:()=>n(!t),children:"Run history"}),t&&s.jsx(CB,{show:t,setModalShow:n})]})},jB=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(rn);return s.jsxs(ve,{show:e,size:"xl",onHide:()=>t(!1),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsxs(ve.Title,{children:["All steps of run ",n.label]})}),s.jsx(ve.Body,{children:s.jsx(aw,{hideLabel:!1})}),s.jsx(ve.Footer,{children:s.jsx(ie,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},IB=({size:e})=>{const[t,n]=x.useState(!1);return s.jsxs(x.Fragment,{children:[s.jsx(ie,{size:e,variant:"primary",onClick:()=>n(!0),children:"All run steps"}),t&&s.jsx(jB,{show:t,setModalShow:n})]})},_B=()=>{const{runStep:e,run:t}=x.useContext(rn),[n,r]=x.useState(!1),[i,a]=x.useState({}),[o,l]=x.useState(null),[c,u]=x.useState([]),[d,p]=x.useState([]),[g,m]=x.useState([]),[v,I]=x.useState(""),[C,b]=x.useState(!1);if(!e.has_recipe)return"Reworks are only possible for steps with a recipe";const[_,y,S]=Ae.useQueries({queries:[{queryKey:["templates",g],queryFn:()=>V1({reworkRecipes:g}),enabled:n&&g.length>0},{queryKey:["run_steps",e.id],queryFn:()=>Sd({run:t,page:1,pageSize:1e3}),enabled:n},{queryKey:["template_steps","rework",o,e.id],queryFn:()=>L1({template:o,pageSize:1e3}),enabled:o!==null}]});x.useEffect(()=>{if(y.isSuccess&&c.length>0){let k=y.data.items.filter(A=>c.includes(A.id)).map(A=>A.recipe_version.recipe);m([...k])}},[y.isSuccess,c]);function j(k){let A=_.data.templates.find(F=>F.id===k);A!==void 0&&l(A)}function N(){let k={};a({}),c.length===0&&(k.runStep="Please select at least one step"),a(A=>({...A,...k})),Object.keys(k).length===0&&(b(!0),te.create().patch("/update/run/step/rework/"+e.id,{reworked_run_steps:c,template_steps:d,comment:v}).then(()=>{b(!1),window.location.reload()}))}return s.jsxs(s.Fragment,{children:[n&&s.jsxs(W,{method:"post",onSubmit:()=>N(),children:[s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Template"}),s.jsxs("div",{className:"col-sm-9",children:[g.length===0&&s.jsx(St,{variant:"info",children:"Please select a rework step"}),g.length>0&&s.jsxs(W.Control,{as:"select",name:"template",onChange:k=>j(parseInt(k.target.value)),isInvalid:!!i.template,children:[s.jsx("option",{value:"",children:"— Select a template"}),_.data!==void 0&&_.data.templates.map((k,A)=>s.jsxs("option",{value:k.id,children:[k.label,": ",k.name]},A))]}),i.template&&s.jsx("span",{className:"text-danger",children:i.template})]})]}),o!==null&&s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Include template steps"}),s.jsx("div",{className:"col-sm-9",children:s.jsx("ul",{className:"list-group",children:!S.isLoading&&S.data!==void 0&&S.data.steps.map((k,A)=>s.jsx("li",{className:"list-group-item ",children:s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"checkbox",className:"form-check-input",id:"templateStep"+k.id,name:"templateStep",onChange:F=>{F.target.checked?p([...d,k.id]):p(d.filter(L=>L!==k.id))},value:k.id}),s.jsxs("label",{htmlFor:"templateStep"+k.id,className:"from-check-label",children:[s.jsxs("small",{className:"text-muted pe-2",children:[k.number,":"]}),k.process_module.process.name]})]})},A))})})]}),s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Repeat steps"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsxs("ul",{className:"list-group",children:[y.isLoading&&s.jsx("option",{children:"Loading run steps..."}),!y.isLoading&&y.data.items.map((k,A)=>{if(e.sequence>=k.sequence)return s.jsxs("li",{className:"list-group-item d-flex justify-content-between"+(e.id===k.id?" bg-success-subtle":""),children:[s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"checkbox",className:"form-check-input",id:"runStep"+k.id,name:"runStep",onChange:F=>{F.target.checked?u([...c,k.id]):u(c.filter(L=>L!==k.id))},value:k.id}),s.jsxs("label",{htmlFor:"runStep"+k.id,className:"from-check-label",children:[s.jsxs("small",{className:"text-muted pe-2",children:[k.number,":"]}),k.process_module.process.name]})]}),k.is_finished&&s.jsx("div",{children:s.jsx("span",{className:"badge bg-success",children:"Finished"})})]},A)})]}),i.runStep&&s.jsx("span",{className:"text-danger",children:i.runStep})]})]}),s.jsxs("div",{className:"row mb-3",children:[s.jsx(W.Label,{className:"col-sm-3 col-form-label text-end",children:"Comment"}),s.jsx("div",{className:"col-sm-9",children:s.jsxs(W.Group,{controlId:"runStep.remark",children:[s.jsx(W.Control,{as:"textarea",rows:6,onChange:k=>I(k.target.value),value:v,isInvalid:!!i.comment}),s.jsx("small",{className:"text-muted",children:"Optional comment for the rework"})]})})]}),s.jsx("div",{className:"row mb-3",children:s.jsxs("div",{className:"col-sm-9 offset-sm-3",children:[s.jsxs(ie,{variant:"primary",onClick:()=>N(),disabled:C,children:[C&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create rework"]})," ",s.jsx(ie,{variant:"warning",onClick:()=>r(!1),children:"Cancel"})]})})]}),!n&&s.jsx(ie,{variant:"primary",className:"mt-3",onClick:()=>r(!0),children:"Set Rework"})]})},EB=()=>{const{environment:e}=Te.useParams(),{runStep:t,run:n}=x.useContext(rn),r=Ae.useQueries({queries:[{queryKey:["monitors",t.process_module.module.equipment],queryFn:()=>tx({equipment:t.process_module.module.equipment})},{queryKey:["ecn",t.process_module.module],queryFn:()=>wd({module:t.process_module.module})},{queryKey:["equipmentModule",t.process_module.module],queryFn:()=>b1({id:t.process_module.module.id})},{queryKey:["requirement",t.id],queryFn:()=>Cd({run:n,step:t})}]}),[i,a,o,l]=r,[c,u]=x.useState(!0),d=r.some(m=>m.isLoading);if(r.some(m=>m.isError))return r.filter(m=>m.isError).forEach((m,v)=>{console.error("StepDashboard query error",{index:v,error:m.error,runStep:t,run:n})}),s.jsx(s.Fragment,{children:"Error fetching data"});if(d)return s.jsx("div",{children:"Loading..."});const g=o.data;return s.jsx(Ii,{fluid:!0,children:s.jsxs(Un,{children:[s.jsxs(Pt,{className:"col-9",children:[n.run_type===Wn.RESEARCH&&s.jsx("small",{children:"Research run"}),n.run_type===Wn.PRODUCTION&&s.jsx("small",{children:"Production run"}),s.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[s.jsxs("h1",{className:"display-4",children:[n.name," (",n.project.name,")"]}),s.jsxs("div",{className:"d-flex flex-column flex-lg-row gap-2 flex-wrap justify-content-end",children:[t.has_rework&&s.jsx("span",{style:{fontSize:"1.5rem"},className:"mx-1 badge bg-primary",children:"Rework"}),s.jsx(xB,{}),s.jsx(gB,{}),t.is_skipped&&s.jsx("span",{style:{fontSize:"1.5rem"},className:"badge bg-info",children:"SKIPPED"})]})]}),s.jsx(ip,{run:n}),t.label&&s.jsx(dB,{label:t.label}),s.jsx(fB,{runStep:t}),t.is_finished&&s.jsxs(St,{variant:"success",children:["This step has been finished by ",t.finish_user?.first_name," ",t.finish_user?.last_name]}),t.has_recipe&&s.jsx(Ye,{className:"rounded my-4",children:s.jsxs(Ye.Body,{children:[s.jsx(Ye.Title,{className:"text-muted",children:"Recipe"}),s.jsxs(Ye.Text,{className:"display-5",children:[t.recipe_version.recipe.name," (Version ",t.recipe_version.version,")"]})]})}),l.data?.items.length==1&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{children:"Measurements by part"}),s.jsx(lp,{requirement:l.data.items[0],step:t,editOnly:!1}),s.jsx("h4",{children:"Measurements for whole step"}),s.jsx(ew,{requirement:l.data.items[0],editOnly:!1})]}),l.data?.items.length!=1&&n.run_type===Wn.RESEARCH&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Available parts"}),s.jsx(op,{run:n,runStep:t})]}),l.data?.items.length!=1&&n.run_type===Wn.PRODUCTION&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Available parts"}),s.jsx(J0,{run:n,runStep:t})]}),s.jsxs(Un,{className:"py-4",children:[s.jsxs(Pt,{children:[s.jsx("h3",{children:"Checklist"}),s.jsx(iw,{}),s.jsx("h2",{className:"mt-2",children:"Step files"}),s.jsx(tc,{runStep:t})]}),s.jsxs(Pt,{children:[s.jsx("h2",{children:"Parameters"}),s.jsxs("div",{className:"form-check form-switch",children:[s.jsx("input",{type:"checkbox",checked:c,className:"form-check-input","data-toggle":"toggle",onChange:()=>u(!c)}),s.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]}),s.jsx(ec,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:c}),t.has_instructions&&t.instructions&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Instructions"}),s.jsx("span",{dangerouslySetInnerHTML:{__html:t.instructions}})]}),s.jsx(sw,{}),s.jsx("h3",{className:"pt-3",children:"Rework"}),s.jsx(_B,{})]})]}),s.jsxs("div",{className:"d-flex justify-content-between mb-3",children:[s.jsx("h2",{children:"Run steps"}),s.jsxs("div",{className:"d-flex gap-2 flex-wrap justify-content-end",children:[s.jsx("div",{children:s.jsx(IB,{size:void 0})}),s.jsx("div",{children:s.jsx(SB,{size:void 0})}),s.jsx("div",{children:s.jsx(G0,{size:void 0,moduleId:t.process_module.module.id})})]})]}),s.jsx(aw,{pageSize:n.run_type===Wn.RESEARCH?5:1e3,hideLabel:!0})]}),s.jsx(Pt,{className:"col-3",children:s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx("h2",{children:s.jsxs(Te.Link,{to:`/${e}/operator/equipment/${t.process_module.module.equipment.id}`,children:[t.process_module.module.equipment.name," (",t.process_module.module.name,")"]})}),g&&s.jsx("div",{children:s.jsx("h2",{children:s.jsx(Jr,{module:g})})}),i.data?.items&&i.data.items.map((m,v)=>s.jsx(rp,{monitor:m},v)),a.data?.items.map(function(m,v){return s.jsxs(Ye,{className:"my-2",children:[s.jsxs(Ye.Header,{children:["ECN: ",m.ecn]}),s.jsx(Ye.Body,{children:s.jsx(Ye.Text,{children:s.jsx(Ai,{children:m.description})})}),s.jsxs(Ye.Footer,{children:[m.date_created&&s.jsxs(s.Fragment,{children:["Created by ",ln(m.date_created,"DD-MM-YY H:m")," by ",m.owner.full_name]}),m.last_update&&s.jsxs(s.Fragment,{children:[" ","· Updated by ",ln(m.last_update,"DD-MM-YY H:m")," by ",m.owner.full_name]})]})]},v)})]})})]})})},ow=()=>{const[e,t]=x.useState(!1),{modalProperties:n}=x.useContext(rn),r=()=>{t(!1),n.show=!1};return x.useEffect(()=>{t(n.show)},[n]),s.jsxs(ve,{show:e,size:"xl",onHide:r,children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:n.modalTitle})}),s.jsx(ve.Body,{children:n.modalContent}),s.jsxs(ve.Footer,{children:[s.jsx(ie,{variant:"secondary",onClick:r,children:"Save"}),n.modalSaveButton]})]})};function kB(){return s.jsxs(s.Fragment,{children:[s.jsx(EB,{}),s.jsx(ow,{})]})}const Hg={movingOut:"Moving out...",movingIn:"Moving in..."};function NB({run:e,runStep:t,reloadRunStep:n}){const{run:r,runStep:i,reloadRunStep:a}=x.useContext(rn),[o,l]=x.useState(null),[c,u]=x.useState(!1),d=e??r,p=t??i,g=n??a??(()=>null);x.useEffect(()=>{if(o){const _=setTimeout(()=>{l(null)},3e3);return()=>clearTimeout(_)}},[o]);const{data:m,isLoading:v,refetch:I}=Ae.useQuery({queryKey:["checklist",p?.id],queryFn:()=>rx({runStep:p}),enabled:!!p});if(!p||!d)return s.jsx(s.Fragment,{children:"Please set RunStepContext in RunStepChecklist"});if(p.is_finished)return s.jsx("div",{children:"Step is finished"});if(v)return s.jsx(zt,{message:"Loading..."});function C(_){l(Hg.movingOut),u(!0),jd(_).then(()=>{u(!1),l(null),g()})}function b(_){l(Hg.movingIn),u(!0),ix(_).then(()=>{u(!1),l(null),g()})}return s.jsxs(s.Fragment,{children:[m.items.length===0&&s.jsx(St,{variant:"info",children:"No checklist found"}),m.items.length>0&&s.jsx(wn,{children:m.items.map(_=>s.jsx(rw,{checklistItem:_,refetch:I},_.id))}),s.jsx("div",{className:"d-flex justify-content-between mt-3",children:s.jsx("div",{className:"d-flex gap-2 align-items-center",children:p.is_started?s.jsx("div",{children:s.jsx(ie,{variant:"success",onClick:()=>C(p),disabled:c,children:o!==null?o:"Move out"})}):s.jsx("div",{children:s.jsx(ie,{variant:"success",onClick:()=>b(p),disabled:c,children:o!==null?o:"Start processing"})})})})]})}const AB=({run:e,runStep:t,runStepParts:n,runParts:r,refetchFn:i=()=>{},toggleRunPartRef:a})=>{const o=Ae.useQueryClient(),l=Ae.useQueries({queries:[{queryKey:["runParts",e.id,t.part_level],queryFn:()=>ba({run:e,level:t.part_level}),enabled:!r},{queryKey:["runStepParts",t.id],queryFn:()=>gs({step:t}),enabled:!n}]}),[c,u]=l,d=l.some(_=>_.isLoading),p=l.some(_=>_.isError),g=x.useMemo(()=>r??c.data?.items??[],[r,c.data]),m=x.useMemo(()=>n??u.data?.items??[],[n,u.data]);x.useEffect(()=>{const _=n??u.data?.items??[];Js(t,_)},[n,u.data]);const v=x.useMemo(()=>g.filter(_=>_.part_level===t.part_level),[g,t.part_level]),{selectedParts:I}=ap({parts:v,getPartId:_=>_.id,toggleRef:a}),C=x.useMemo(()=>v.filter(_=>I.get(_.id)&&!RB(m,_)),[I,m]),b=()=>{o.invalidateQueries({queryKey:["runParts",e.id,t.part_level]}),o.invalidateQueries({queryKey:["runStepParts",t.id]}),i()};return d?s.jsx("div",{children:"Loading..."}):p?s.jsx("div",{className:"text-danger",children:"Error loading run parts."}):s.jsxs(x.Fragment,{children:[s.jsxs(Ht,{size:"sm",striped:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Part"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Date"}),s.jsx("th",{children:"Actions"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:C.map((_,y)=>s.jsx(Z0,{runStep:t,runPart:_,runStepParts:m,refetchFn:b,partIsSelected:I.get(_.id)??!1,dropdown:!1},y))})]}),s.jsx(DB,{runStepParts:m,selectedPartsLength:C.length})]})},RB=(e,t)=>{const n=e.find(r=>r.part.id==t.id);return n==null?!1:n.latest_action?.type.id===Ne.FINISH_PROCESSING},DB=({runStepParts:e,selectedPartsLength:t})=>{const n=x.useMemo(()=>{let i=0;return e.forEach(a=>a.latest_action?.type.id===Ne.FINISH_PROCESSING?i++:null),i},[e]),r=x.useMemo(()=>e.length-t,[e,t]);return s.jsxs("div",{className:"d-flex flex-column flex-sm-row flex-wrap gap-2 mt-2",children:[s.jsxs("span",{className:"badge rounded-pill bg-warning-subtle text-warning-emphasis border border-warning-subtle px-3 py-2 fw-semibold",children:["This step has ",r," more parts"]}),s.jsxs("span",{className:"badge rounded-pill bg-info-subtle text-info-emphasis border border-info-subtle px-3 py-2 fw-semibold",children:["This step has ",t," scanned parts"]}),s.jsxs("span",{className:"badge rounded-pill bg-success-subtle text-success-emphasis border border-success-subtle px-3 py-2 fw-semibold",children:["This step has ",n," finished parts"]})]})};function MB({run:e,runStep:t,showOnlyEmphasizedParameters:n,reloadRunStepFn:r,toggleRunPartRef:i}){return s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("h3",{className:"mb-2 text-start",children:"Parts"}),s.jsx(AB,{run:e,runStep:t,toggleRunPartRef:i})]}),s.jsx("h3",{className:"mt-2",children:"Parameters"}),s.jsx(ec,{runStep:t,showOnlyEmphasizedParameters:n}),s.jsxs("div",{className:"row row-cols-2",children:[s.jsx("div",{className:"col",children:s.jsx(sw,{runStep:t,reloadRunStep:r})}),s.jsx("div",{className:"col",children:t.has_instructions&&t.instructions&&s.jsxs(x.Fragment,{children:[s.jsx("h3",{className:"mb-2 text-start",children:"Instructions"}),s.jsx("span",{dangerouslySetInnerHTML:{__html:t.instructions}})]})})]}),s.jsxs("div",{className:"row row-cols-2",children:[s.jsxs("div",{className:"col",children:[s.jsx("h3",{className:"mt-2",children:"Checklist"}),s.jsx(NB,{run:e,runStep:t,reloadRunStep:r})]}),s.jsxs("div",{className:"col",children:[s.jsx("h3",{className:"mt-2",children:"Step files"}),s.jsx(tc,{runStep:t})]})]})]})}function OB(e){return e==="Shift"}function TB(e){return/^[a-zA-Z0-9-]$/.test(e)}function FB(e){return e.length===1}function PB(e){return e==="Enter"}function LB(e,t,n,r){let i=0,a="";const o=()=>{i=0,a="",n&&n(a)};return l=>{const c=l.key;if(c==="Escape"){o();return}if(!OB(c)){if(PB(c)){t(a),o();return}switch(a+=c,e[i]){case"/":if(c!="/"){o();return}else i=(i+1)%e.length;break;case"*":if(!FB(c))return;break;default:if(!TB(e[i]))throw new Error("Invalid character expression in makeKeySequenceListener call");if(c!=e[i]){o();return}else i=(i+1)%e.length;break}n&&n(a)}}}function VB({notification:e,setNotification:t}){return s.jsx(bs,{position:"top-end",children:s.jsxs(on,{show:e.show,onClose:()=>t(n=>({...n,show:!1})),delay:3e3,autohide:!0,bg:e.variant,children:[s.jsx(on.Header,{children:s.jsx("span",{children:"Notification"})}),s.jsx(on.Body,{children:e.text})]})})}function lw({runsList:e,setRun:t,setRunPartLabel:n}){const[r,i]=x.useState(""),[a,o]=x.useState({text:"",show:!1,variant:"success"}),l=c=>{const u=c.replace(/_/g,"-").toUpperCase(),d=u.split("-");if(!(d.length==4||d.length==3)){o({text:"Part not found, found "+d.length+" splits in "+u,show:!0,variant:"danger"});return}const p=e.find(m=>m.label===`${d[0]}-${d[1]}`),g=u;if(!p){o({text:"Run not found",show:!0,variant:"danger"});return}if(!g){o({text:"Part label not found",show:!0,variant:"danger"});return}t!==void 0&&(o({text:`Found run ${p.label}`,show:!0,variant:"success"}),t(p)),n!==void 0&&n(d[2])};return x.useEffect(()=>{const c=LB("*",l,i);return document.addEventListener("keyup",c),()=>{document.removeEventListener("keyup",c)}},[]),s.jsxs("div",{className:"d-flex flex-row gap-3",children:[s.jsx("div",{className:"d-flex flex-column",children:s.jsxs("div",{className:"h3",children:["Reading: ",s.jsx("span",{className:"font-monospace",children:r})]})}),s.jsx(VB,{notification:a,setNotification:o})]})}function GB({children:e}){const[t,n]=x.useState(!1);return s.jsx(jn,{children:s.jsx(Kl.Provider,{value:{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n},children:s.jsx(x.Suspense,{fallback:s.jsx(zt,{message:"Loading..."}),children:e})})})}function BB(){return s.jsx(Ii,{fluid:!0,children:s.jsx(Te.Outlet,{})})}function YB({control:e,name:t}){const{environment:n}=Te.useParams(),[r,i]=x.useState([]),[a,o]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const c=await I1({environment:n,withLocations:!0});i(c.items)}catch(c){console.error("Error fetching rooms:",c)}finally{o(!1)}}l()},[]),a?s.jsx("p",{children:"Loading labs..."}):s.jsxs("div",{children:[s.jsx("h3",{children:"Choose a lab"}),s.jsx(W.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:s.jsx(Fn,{name:t,render:({field:{onChange:l,value:c}})=>s.jsxs(W.Select,{"aria-label":"Choose a lab",value:c?.id||"",onChange:u=>{const d=r.find(p=>p.id.toString()===u.target.value);l(d||null)},children:[s.jsx("option",{value:"",children:"— Choose a lab"}),r.map(u=>s.jsx("option",{value:u.id,children:u.name},u.id))]}),control:e})})]})}function WB({control:e}){return s.jsx(W.Group,{className:"mb-3",controlId:"chemical.scanBarcode",children:s.jsx(Fn,{name:"barcode",control:e,render:({field:t})=>s.jsx("input",{...t,id:"chemical.scanBarcodeElement",type:"text",autoFocus:!0,placeholder:"Scan or enter barcode",className:"form-control form-control-lg"})})})}var zB=Object.defineProperty,pl=Object.getOwnPropertySymbols,cw=Object.prototype.hasOwnProperty,uw=Object.prototype.propertyIsEnumerable,Ug=(e,t,n)=>t in e?zB(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,vd=(e,t)=>{for(var n in t||(t={}))cw.call(t,n)&&Ug(e,n,t[n]);if(pl)for(var n of pl(t))uw.call(t,n)&&Ug(e,n,t[n]);return e},yd=(e,t)=>{var n={};for(var r in e)cw.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&pl)for(var r of pl(e))t.indexOf(r)<0&&uw.call(e,r)&&(n[r]=e[r]);return n};var Ci;(e=>{const t=class He{constructor(c,u,d,p){if(this.version=c,this.errorCorrectionLevel=u,this.modules=[],this.isFunction=[],c<He.MIN_VERSION||c>He.MAX_VERSION)throw new RangeError("Version value out of range");if(p<-1||p>7)throw new RangeError("Mask value out of range");this.size=c*4+17;let g=[];for(let v=0;v<this.size;v++)g.push(!1);for(let v=0;v<this.size;v++)this.modules.push(g.slice()),this.isFunction.push(g.slice());this.drawFunctionPatterns();const m=this.addEccAndInterleave(d);if(this.drawCodewords(m),p==-1){let v=1e9;for(let I=0;I<8;I++){this.applyMask(I),this.drawFormatBits(I);const C=this.getPenaltyScore();C<v&&(p=I,v=C),this.applyMask(I)}}i(0<=p&&p<=7),this.mask=p,this.applyMask(p),this.drawFormatBits(p),this.isFunction=[]}static encodeText(c,u){const d=e.QrSegment.makeSegments(c);return He.encodeSegments(d,u)}static encodeBinary(c,u){const d=e.QrSegment.makeBytes(c);return He.encodeSegments([d],u)}static encodeSegments(c,u,d=1,p=40,g=-1,m=!0){if(!(He.MIN_VERSION<=d&&d<=p&&p<=He.MAX_VERSION)||g<-1||g>7)throw new RangeError("Invalid value");let v,I;for(v=d;;v++){const y=He.getNumDataCodewords(v,u)*8,S=o.getTotalBits(c,v);if(S<=y){I=S;break}if(v>=p)throw new RangeError("Data too long")}for(const y of[He.Ecc.MEDIUM,He.Ecc.QUARTILE,He.Ecc.HIGH])m&&I<=He.getNumDataCodewords(v,y)*8&&(u=y);let C=[];for(const y of c){n(y.mode.modeBits,4,C),n(y.numChars,y.mode.numCharCountBits(v),C);for(const S of y.getData())C.push(S)}i(C.length==I);const b=He.getNumDataCodewords(v,u)*8;i(C.length<=b),n(0,Math.min(4,b-C.length),C),n(0,(8-C.length%8)%8,C),i(C.length%8==0);for(let y=236;C.length<b;y^=253)n(y,8,C);let _=[];for(;_.length*8<C.length;)_.push(0);return C.forEach((y,S)=>_[S>>>3]|=y<<7-(S&7)),new He(v,u,_,g)}getModule(c,u){return 0<=c&&c<this.size&&0<=u&&u<this.size&&this.modules[u][c]}getModules(){return this.modules}drawFunctionPatterns(){for(let d=0;d<this.size;d++)this.setFunctionModule(6,d,d%2==0),this.setFunctionModule(d,6,d%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const c=this.getAlignmentPatternPositions(),u=c.length;for(let d=0;d<u;d++)for(let p=0;p<u;p++)d==0&&p==0||d==0&&p==u-1||d==u-1&&p==0||this.drawAlignmentPattern(c[d],c[p]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(c){const u=this.errorCorrectionLevel.formatBits<<3|c;let d=u;for(let g=0;g<10;g++)d=d<<1^(d>>>9)*1335;const p=(u<<10|d)^21522;i(p>>>15==0);for(let g=0;g<=5;g++)this.setFunctionModule(8,g,r(p,g));this.setFunctionModule(8,7,r(p,6)),this.setFunctionModule(8,8,r(p,7)),this.setFunctionModule(7,8,r(p,8));for(let g=9;g<15;g++)this.setFunctionModule(14-g,8,r(p,g));for(let g=0;g<8;g++)this.setFunctionModule(this.size-1-g,8,r(p,g));for(let g=8;g<15;g++)this.setFunctionModule(8,this.size-15+g,r(p,g));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let c=this.version;for(let d=0;d<12;d++)c=c<<1^(c>>>11)*7973;const u=this.version<<12|c;i(u>>>18==0);for(let d=0;d<18;d++){const p=r(u,d),g=this.size-11+d%3,m=Math.floor(d/3);this.setFunctionModule(g,m,p),this.setFunctionModule(m,g,p)}}drawFinderPattern(c,u){for(let d=-4;d<=4;d++)for(let p=-4;p<=4;p++){const g=Math.max(Math.abs(p),Math.abs(d)),m=c+p,v=u+d;0<=m&&m<this.size&&0<=v&&v<this.size&&this.setFunctionModule(m,v,g!=2&&g!=4)}}drawAlignmentPattern(c,u){for(let d=-2;d<=2;d++)for(let p=-2;p<=2;p++)this.setFunctionModule(c+p,u+d,Math.max(Math.abs(p),Math.abs(d))!=1)}setFunctionModule(c,u,d){this.modules[u][c]=d,this.isFunction[u][c]=!0}addEccAndInterleave(c){const u=this.version,d=this.errorCorrectionLevel;if(c.length!=He.getNumDataCodewords(u,d))throw new RangeError("Invalid argument");const p=He.NUM_ERROR_CORRECTION_BLOCKS[d.ordinal][u],g=He.ECC_CODEWORDS_PER_BLOCK[d.ordinal][u],m=Math.floor(He.getNumRawDataModules(u)/8),v=p-m%p,I=Math.floor(m/p);let C=[];const b=He.reedSolomonComputeDivisor(g);for(let y=0,S=0;y<p;y++){let j=c.slice(S,S+I-g+(y<v?0:1));S+=j.length;const N=He.reedSolomonComputeRemainder(j,b);y<v&&j.push(0),C.push(j.concat(N))}let _=[];for(let y=0;y<C[0].length;y++)C.forEach((S,j)=>{(y!=I-g||j>=v)&&_.push(S[y])});return i(_.length==m),_}drawCodewords(c){if(c.length!=Math.floor(He.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let u=0;for(let d=this.size-1;d>=1;d-=2){d==6&&(d=5);for(let p=0;p<this.size;p++)for(let g=0;g<2;g++){const m=d-g,I=(d+1&2)==0?this.size-1-p:p;!this.isFunction[I][m]&&u<c.length*8&&(this.modules[I][m]=r(c[u>>>3],7-(u&7)),u++)}}i(u==c.length*8)}applyMask(c){if(c<0||c>7)throw new RangeError("Mask value out of range");for(let u=0;u<this.size;u++)for(let d=0;d<this.size;d++){let p;switch(c){case 0:p=(d+u)%2==0;break;case 1:p=u%2==0;break;case 2:p=d%3==0;break;case 3:p=(d+u)%3==0;break;case 4:p=(Math.floor(d/3)+Math.floor(u/2))%2==0;break;case 5:p=d*u%2+d*u%3==0;break;case 6:p=(d*u%2+d*u%3)%2==0;break;case 7:p=((d+u)%2+d*u%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[u][d]&&p&&(this.modules[u][d]=!this.modules[u][d])}}getPenaltyScore(){let c=0;for(let g=0;g<this.size;g++){let m=!1,v=0,I=[0,0,0,0,0,0,0];for(let C=0;C<this.size;C++)this.modules[g][C]==m?(v++,v==5?c+=He.PENALTY_N1:v>5&&c++):(this.finderPenaltyAddHistory(v,I),m||(c+=this.finderPenaltyCountPatterns(I)*He.PENALTY_N3),m=this.modules[g][C],v=1);c+=this.finderPenaltyTerminateAndCount(m,v,I)*He.PENALTY_N3}for(let g=0;g<this.size;g++){let m=!1,v=0,I=[0,0,0,0,0,0,0];for(let C=0;C<this.size;C++)this.modules[C][g]==m?(v++,v==5?c+=He.PENALTY_N1:v>5&&c++):(this.finderPenaltyAddHistory(v,I),m||(c+=this.finderPenaltyCountPatterns(I)*He.PENALTY_N3),m=this.modules[C][g],v=1);c+=this.finderPenaltyTerminateAndCount(m,v,I)*He.PENALTY_N3}for(let g=0;g<this.size-1;g++)for(let m=0;m<this.size-1;m++){const v=this.modules[g][m];v==this.modules[g][m+1]&&v==this.modules[g+1][m]&&v==this.modules[g+1][m+1]&&(c+=He.PENALTY_N2)}let u=0;for(const g of this.modules)u=g.reduce((m,v)=>m+(v?1:0),u);const d=this.size*this.size,p=Math.ceil(Math.abs(u*20-d*10)/d)-1;return i(0<=p&&p<=9),c+=p*He.PENALTY_N4,i(0<=c&&c<=2568888),c}getAlignmentPatternPositions(){if(this.version==1)return[];{const c=Math.floor(this.version/7)+2,u=this.version==32?26:Math.ceil((this.version*4+4)/(c*2-2))*2;let d=[6];for(let p=this.size-7;d.length<c;p-=u)d.splice(1,0,p);return d}}static getNumRawDataModules(c){if(c<He.MIN_VERSION||c>He.MAX_VERSION)throw new RangeError("Version number out of range");let u=(16*c+128)*c+64;if(c>=2){const d=Math.floor(c/7)+2;u-=(25*d-10)*d-55,c>=7&&(u-=36)}return i(208<=u&&u<=29648),u}static getNumDataCodewords(c,u){return Math.floor(He.getNumRawDataModules(c)/8)-He.ECC_CODEWORDS_PER_BLOCK[u.ordinal][c]*He.NUM_ERROR_CORRECTION_BLOCKS[u.ordinal][c]}static reedSolomonComputeDivisor(c){if(c<1||c>255)throw new RangeError("Degree out of range");let u=[];for(let p=0;p<c-1;p++)u.push(0);u.push(1);let d=1;for(let p=0;p<c;p++){for(let g=0;g<u.length;g++)u[g]=He.reedSolomonMultiply(u[g],d),g+1<u.length&&(u[g]^=u[g+1]);d=He.reedSolomonMultiply(d,2)}return u}static reedSolomonComputeRemainder(c,u){let d=u.map(p=>0);for(const p of c){const g=p^d.shift();d.push(0),u.forEach((m,v)=>d[v]^=He.reedSolomonMultiply(m,g))}return d}static reedSolomonMultiply(c,u){if(c>>>8||u>>>8)throw new RangeError("Byte out of range");let d=0;for(let p=7;p>=0;p--)d=d<<1^(d>>>7)*285,d^=(u>>>p&1)*c;return i(d>>>8==0),d}finderPenaltyCountPatterns(c){const u=c[1];i(u<=this.size*3);const d=u>0&&c[2]==u&&c[3]==u*3&&c[4]==u&&c[5]==u;return(d&&c[0]>=u*4&&c[6]>=u?1:0)+(d&&c[6]>=u*4&&c[0]>=u?1:0)}finderPenaltyTerminateAndCount(c,u,d){return c&&(this.finderPenaltyAddHistory(u,d),u=0),u+=this.size,this.finderPenaltyAddHistory(u,d),this.finderPenaltyCountPatterns(d)}finderPenaltyAddHistory(c,u){u[0]==0&&(c+=this.size),u.pop(),u.unshift(c)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(l,c,u){if(c<0||c>31||l>>>c)throw new RangeError("Value out of range");for(let d=c-1;d>=0;d--)u.push(l>>>d&1)}function r(l,c){return(l>>>c&1)!=0}function i(l){if(!l)throw new Error("Assertion error")}const a=class It{constructor(c,u,d){if(this.mode=c,this.numChars=u,this.bitData=d,u<0)throw new RangeError("Invalid argument");this.bitData=d.slice()}static makeBytes(c){let u=[];for(const d of c)n(d,8,u);return new It(It.Mode.BYTE,c.length,u)}static makeNumeric(c){if(!It.isNumeric(c))throw new RangeError("String contains non-numeric characters");let u=[];for(let d=0;d<c.length;){const p=Math.min(c.length-d,3);n(parseInt(c.substring(d,d+p),10),p*3+1,u),d+=p}return new It(It.Mode.NUMERIC,c.length,u)}static makeAlphanumeric(c){if(!It.isAlphanumeric(c))throw new RangeError("String contains unencodable characters in alphanumeric mode");let u=[],d;for(d=0;d+2<=c.length;d+=2){let p=It.ALPHANUMERIC_CHARSET.indexOf(c.charAt(d))*45;p+=It.ALPHANUMERIC_CHARSET.indexOf(c.charAt(d+1)),n(p,11,u)}return d<c.length&&n(It.ALPHANUMERIC_CHARSET.indexOf(c.charAt(d)),6,u),new It(It.Mode.ALPHANUMERIC,c.length,u)}static makeSegments(c){return c==""?[]:It.isNumeric(c)?[It.makeNumeric(c)]:It.isAlphanumeric(c)?[It.makeAlphanumeric(c)]:[It.makeBytes(It.toUtf8ByteArray(c))]}static makeEci(c){let u=[];if(c<0)throw new RangeError("ECI assignment value out of range");if(c<128)n(c,8,u);else if(c<16384)n(2,2,u),n(c,14,u);else if(c<1e6)n(6,3,u),n(c,21,u);else throw new RangeError("ECI assignment value out of range");return new It(It.Mode.ECI,0,u)}static isNumeric(c){return It.NUMERIC_REGEX.test(c)}static isAlphanumeric(c){return It.ALPHANUMERIC_REGEX.test(c)}getData(){return this.bitData.slice()}static getTotalBits(c,u){let d=0;for(const p of c){const g=p.mode.numCharCountBits(u);if(p.numChars>=1<<g)return 1/0;d+=4+g+p.bitData.length}return d}static toUtf8ByteArray(c){c=encodeURI(c);let u=[];for(let d=0;d<c.length;d++)c.charAt(d)!="%"?u.push(c.charCodeAt(d)):(u.push(parseInt(c.substring(d+1,d+3),16)),d+=2);return u}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let o=a;e.QrSegment=a})(Ci||(Ci={}));(e=>{(t=>{const n=class{constructor(i,a){this.ordinal=i,this.formatBits=a}};n.LOW=new n(0,1),n.MEDIUM=new n(1,0),n.QUARTILE=new n(2,3),n.HIGH=new n(3,2),t.Ecc=n})(e.QrCode||(e.QrCode={}))})(Ci||(Ci={}));(e=>{(t=>{const n=class{constructor(i,a){this.modeBits=i,this.numBitsCharCount=a}numCharCountBits(i){return this.numBitsCharCount[Math.floor((i+7)/17)]}};n.NUMERIC=new n(1,[10,12,14]),n.ALPHANUMERIC=new n(2,[9,11,13]),n.BYTE=new n(4,[8,16,16]),n.KANJI=new n(8,[8,10,12]),n.ECI=new n(7,[0,0,0]),t.Mode=n})(e.QrSegment||(e.QrSegment={}))})(Ci||(Ci={}));var Qi=Ci;var HB={L:Qi.QrCode.Ecc.LOW,M:Qi.QrCode.Ecc.MEDIUM,Q:Qi.QrCode.Ecc.QUARTILE,H:Qi.QrCode.Ecc.HIGH},dw=128,fw="L",pw="#FFFFFF",mw="#000000",hw=!1,gw=1,UB=4,$B=0,XB=.1;function xw(e,t=0){const n=[];return e.forEach(function(r,i){let a=null;r.forEach(function(o,l){if(!o&&a!==null){n.push(`M${a+t} ${i+t}h${l-a}v1H${a+t}z`),a=null;return}if(l===r.length-1){if(!o)return;a===null?n.push(`M${l+t},${i+t} h1v1H${l+t}z`):n.push(`M${a+t},${i+t} h${l+1-a}v1H${a+t}z`);return}o&&a===null&&(a=l)})}),n.join("")}function vw(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,a)=>a<t.x||a>=t.x+t.w?i:!1))}function qB(e,t,n,r){if(r==null)return null;const i=e.length+n*2,a=Math.floor(t*XB),o=i/t,l=(r.width||a)*o,c=(r.height||a)*o,u=r.x==null?e.length/2-l/2:r.x*o,d=r.y==null?e.length/2-c/2:r.y*o,p=r.opacity==null?1:r.opacity;let g=null;if(r.excavate){let v=Math.floor(u),I=Math.floor(d),C=Math.ceil(l+u-v),b=Math.ceil(c+d-I);g={x:v,y:I,w:C,h:b}}const m=r.crossOrigin;return{x:u,y:d,h:c,w:l,excavation:g,opacity:p,crossOrigin:m}}function ZB(e,t){return t!=null?Math.max(Math.floor(t),0):e?UB:$B}function yw({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:l}){let c=x.useMemo(()=>{const v=(Array.isArray(e)?e:[e]).reduce((I,C)=>(I.push(...Qi.QrSegment.makeSegments(C)),I),[]);return Qi.QrCode.encodeSegments(v,HB[t],n,void 0,void 0,l)},[e,t,n,l]);const{cells:u,margin:d,numCells:p,calculatedImageSettings:g}=x.useMemo(()=>{let m=c.getModules();const v=ZB(r,i),I=m.length+v*2,C=qB(m,o,v,a);return{cells:m,margin:v,numCells:I,calculatedImageSettings:C}},[c,o,a,r,i]);return{qrcode:c,margin:d,cells:u,numCells:p,calculatedImageSettings:g}}var JB=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),QB=x.forwardRef(function(t,n){const r=t,{value:i,size:a=dw,level:o=fw,bgColor:l=pw,fgColor:c=mw,includeMargin:u=hw,minVersion:d=gw,boostLevel:p,marginSize:g,imageSettings:m}=r,I=yd(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:C}=I,b=yd(I,["style"]),_=m?.src,y=x.useRef(null),S=x.useRef(null),j=x.useCallback(H=>{y.current=H,typeof n=="function"?n(H):n&&(n.current=H)},[n]),[N,k]=x.useState(!1),{margin:A,cells:F,numCells:L,calculatedImageSettings:Y}=yw({value:i,level:o,minVersion:d,boostLevel:p,includeMargin:u,marginSize:g,imageSettings:m,size:a});x.useEffect(()=>{if(y.current!=null){const H=y.current,T=H.getContext("2d");if(!T)return;let V=F;const Z=S.current,ne=Y!=null&&Z!==null&&Z.complete&&Z.naturalHeight!==0&&Z.naturalWidth!==0;ne&&Y.excavation!=null&&(V=vw(F,Y.excavation));const de=window.devicePixelRatio||1;H.height=H.width=a*de;const R=a/L*de;T.scale(R,R),T.fillStyle=l,T.fillRect(0,0,L,L),T.fillStyle=c,JB?T.fill(new Path2D(xw(V,A))):F.forEach(function(ee,se){ee.forEach(function(O,ae){O&&T.fillRect(ae+A,se+A,1,1)})}),Y&&(T.globalAlpha=Y.opacity),ne&&T.drawImage(Z,Y.x+A,Y.y+A,Y.w,Y.h)}}),x.useEffect(()=>{k(!1)},[_]);const G=vd({height:a,width:a},C);let X=null;return _!=null&&(X=x.createElement("img",{src:_,key:_,style:{display:"none"},onLoad:()=>{k(!0)},ref:S,crossOrigin:Y?.crossOrigin})),x.createElement(x.Fragment,null,x.createElement("canvas",vd({style:G,height:a,width:a,ref:j,role:"img"},b)),X)});QB.displayName="QRCodeCanvas";var Si=x.forwardRef(function(t,n){const r=t,{value:i,size:a=dw,level:o=fw,bgColor:l=pw,fgColor:c=mw,includeMargin:u=hw,minVersion:d=gw,boostLevel:p,title:g,marginSize:m,imageSettings:v}=r,I=yd(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:C,cells:b,numCells:_,calculatedImageSettings:y}=yw({value:i,level:o,minVersion:d,boostLevel:p,includeMargin:u,marginSize:m,imageSettings:v,size:a});let S=b,j=null;v!=null&&y!=null&&(y.excavation!=null&&(S=vw(b,y.excavation)),j=x.createElement("image",{href:v.src,height:y.h,width:y.w,x:y.x+C,y:y.y+C,preserveAspectRatio:"none",opacity:y.opacity,crossOrigin:y.crossOrigin}));const N=xw(S,C);return x.createElement("svg",vd({height:a,width:a,viewBox:`0 0 ${_} ${_}`,ref:n,role:"img"},I),!!g&&x.createElement("title",null,g),x.createElement("path",{fill:l,d:`M0,0 h${_}v${_}H0z`,shapeRendering:"crispEdges"}),x.createElement("path",{fill:c,d:N,shapeRendering:"crispEdges"}),j)});Si.displayName="QRCodeSVG";function bw({control:e,name:t,room:n}){const[r,i]=x.useState([]),[a,o]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const c=await j1({room:n,pageSize:1e3});i(c.items),o(!1)}catch(c){console.error("Error fetching locations:",c)}}l()},[n]),a?s.jsx("p",{children:"Loading locations..."}):s.jsxs(W.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:[s.jsx(W.Label,{children:"Select a storage location"}),s.jsx(Fn,{name:t,control:e,defaultValue:"",render:({field:{onChange:l,value:c}})=>s.jsx(s.Fragment,{children:s.jsx(Un,{children:r.map(u=>s.jsx(Pt,{xs:4,md:3,className:"mb-3",children:s.jsx(Ye,{onClick:()=>l(u.id.toString()),style:{cursor:"pointer",border:c.toString()===u.id.toString()?"2px solid #007bff":"1px solid #ddd",borderRadius:"8px"},className:"h-100",children:s.jsxs(Ye.Body,{children:[s.jsx(Ye.Title,{children:u.name}),s.jsxs("div",{className:"text-muted small mb-2 d-flex gap-2 justify-content-between",children:[u.code&&s.jsxs("div",{children:["Code: ",u.code]}),u.zone_group&&s.jsxs("div",{children:["Zone group: ",u.zone_group.name]})]}),s.jsxs("div",{style:{textAlign:"center",marginTop:"10px"},children:[s.jsx(Si,{value:"/l/"+u.id.toString(),size:128})," "]})]})})},u.id))})})})]})}const KB=({show:e,setShow:t,onChemicalCreate:n})=>{const{register:r,control:i,setValue:a,handleSubmit:o,formState:{errors:l,isSubmitting:c}}=tn({defaultValues:{}}),u=async d=>{try{const p=await te.post("create/chemical",d);p.data&&n(p.data)}finally{t(!1)}};return s.jsx(ve,{show:e,size:"lg",onHide:()=>t(!1),children:s.jsxs(W,{onSubmit:o(u),children:[s.jsx(ve.Header,{closeButton:!0,children:s.jsx(ve.Title,{children:"Create new chemical"})}),s.jsxs(ve.Body,{children:[s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"CAS Number"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"input",...r("cas_number",{required:"A cas number is required"}),isInvalid:l.cas_number!==void 0}),l.cas_number&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.cas_number.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Name"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"input",...r("name",{required:"A name is required"}),isInvalid:l.name!==void 0}),l.name&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.name.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Description"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsx(W.Control,{as:"textarea",rows:3,...r("description")}),l.description&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.description.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Standard product"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsxs(W.Select,{...r("standard_product",{required:"A standard product is required"}),isInvalid:l.standard_product!==void 0,children:[s.jsx("option",{value:Su.NON_STANDARD_PRODUCT,children:"Non standard product"}),s.jsx("option",{value:Su.STANDARD_PRODUCT,children:"Standard product"})]}),l.standard_product&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.standard_product.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Physical state"}),s.jsxs("div",{className:"col-sm-9",children:[s.jsxs(W.Select,{...r("physical_state",{required:"A physical state is required"}),isInvalid:l.physical_state!==void 0,children:[s.jsx("option",{value:Xs.SOLID,children:"Solid"}),s.jsx("option",{value:Xs.LIQUID,children:"Liquid"}),s.jsx("option",{value:Xs.GAS,children:"Gas"}),s.jsx("option",{value:Xs.OTHER,children:"Other"})]}),l.physical_state&&s.jsx(W.Control.Feedback,{type:"invalid",children:l.physical_state.message})]})]})]}),s.jsx(ve.Footer,{children:s.jsxs(ie,{variant:"primary",disabled:c,onClick:()=>o(u)(),children:[c&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create new chemical"]})})]})})};function ww({control:e,name:t,setValue:n,errors:r}){const[i,a]=x.useState({}),[o,l]=x.useState(!1),[c,u]=x.useState(null),d=(m,v)=>{try{h1({query:m}).then(C=>{const b=C.items.map(y=>({value:y.id,label:y.name+(y.cas_number?" ("+y.cas_number+")":"")})),_={...i};b.forEach(y=>{_[y.value]=y}),a(_),v(b)})}catch(I){console.error("Error fetching chemicals:",I)}},p=m=>m&&i[m]?i[m]:c||null,g=async m=>{try{const v=await te.post("create/chemical",m),I={value:v.data.id,label:v.data.name+(v.data.cas_number?` (${v.data.cas_number})`:"")};a(C=>({...C,[I.value]:I})),u(I),l(!1),n(t,v.data.id)}catch(v){console.error("Error creating chemical:",v)}};return s.jsxs(s.Fragment,{children:[s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Search Existing Chemicals"}),s.jsxs(Un,{children:[s.jsx(Fn,{name:t,control:e,render:({field:m})=>s.jsx(Fl,{isSearchable:!0,isClearable:!0,defaultOptions:!0,placeholder:"— Select a chemical, or start typing",loadOptions:d,value:p(m.value),styles:bf,onChange:v=>{u(null),m.onChange(v?.value)}})}),r.chemical&&s.jsx(W.Control.Feedback,{type:"invalid",children:r.chemical.message}),s.jsx("div",{children:s.jsx(ie,{variant:"primary",className:"mt-2",onClick:()=>l(!0),children:"Create New Chemical"})})]})]}),s.jsx(KB,{show:o,setShow:l,onChemicalCreate:g})]})}function Cw(e){return/\/l\/\d+$/.test(e)}function Sw(e){const t=e.match(/\/l\/(\d+)$/);return t?parseInt(t[1],10):null}const jw=[{value:"g",label:"Gram"},{value:"kg",label:"Kilogram"},{value:"lb",label:"US pound"},{value:"mc",label:"Microgram"},{value:"mg",label:"Milligram"},{value:"oz",label:"Ounce"},{value:"to",label:"Tonnes"},{value:"ton",label:"US ton"},{value:'"3',label:"Cubic inch"},{value:"ccm",label:"Cubic centimeter"},{value:"cl",label:"Centiliter"},{value:"dm3",label:"Cubic decimeter"},{value:"foz",label:"Fluid Ounce Us"},{value:"ft3",label:"Cubic foot"},{value:"gal",label:"US gallon"},{value:"hl",label:"Hectoliter"},{value:"kit",label:"Kit"},{value:"l",label:"Liter"},{value:"m3",label:"Cubic meter"},{value:"ml",label:"Mililiter"},{value:"mm3",label:"Cubic milimeter"},{value:"pc",label:"Item"},{value:"pce",label:"Piece"},{value:"pt",label:"Pint, US liquid"},{value:"qt",label:"Quart, US liquid"},{value:"yd3",label:"Cubic Yard"},{value:"µl",label:"Microliter"}].sort((e,t)=>e.label.localeCompare(t.label));function eY({room:e,barcode:t,resetForm:n,location:r,setLocation:i}){const{user:a}=x.useContext(hs),{environment:o}=Te.useParams(),[l,c]=x.useState(null);let u=new Date;u.setFullYear(u.getFullYear()+5);const{register:d,control:p,handleSubmit:g,watch:m,setValue:v,formState:{errors:I,isSubmitting:C}}=tn({defaultValues:{expire_date:u.toISOString().split("T")[0],owner:{value:a?.id,label:a?.full_name}}}),b=m("location");x.useEffect(()=>{b&&aa({id:b}).then(S=>{i(S)})},[b]),x.useEffect(()=>{let S="";const j=N=>{if(!(N.target instanceof HTMLInputElement||N.target instanceof HTMLTextAreaElement)&&!(N.key.length>1&&N.key!=="Enter"))if(N.key==="Enter"){if(Cw(S)){const k=Sw(S);k!==null&&(aa({id:k}).then(A=>{i(A)}),v("location",k))}S.startsWith("reset-scan-location")&&y(),S=""}else S+=N.key};return window.addEventListener("keydown",j),()=>{window.removeEventListener("keydown",j)}},[v]);const _=async S=>{if(S.user=S.owner.value,(await qg({qrCodeContent:t})).items.length>0){alert("This barcode is already registered to a container");return}const N=await te.post("create/chemical/container",S);c(N.data),await te.post("create/chemical/container/external-label",{container:N.data.id,qr_code_content:t})},y=()=>{i(null),v("location",0)};return s.jsxs(s.Fragment,{children:[s.jsxs(W,{onSubmit:g(_),children:[!r&&s.jsx(bw,{room:e,control:p,name:"location"}),r&&s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Scanned location"}),s.jsx(Pt,{children:s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("span",{className:"h1",children:r.name}),s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx(Si,{value:"reset-scan-location",size:100,onClick:()=>y()}),s.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),r&&s.jsxs(s.Fragment,{children:[s.jsx(ww,{control:p,errors:I,setValue:v,...d("chemical",{required:"Chemical is required"})}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Owner"}),s.jsx(Fa,{control:p,...d("owner",{required:"Owner is required"}),name:"owner"})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Concentration"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...d("concentration",{required:"An concentration is required"}),isInvalid:I.concentration!==void 0}),I.concentration&&s.jsx(W.Control.Feedback,{type:"invalid",children:I.concentration.message})]})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Amount"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...d("amount",{required:"An amount is required"}),isInvalid:I.amount!==void 0}),s.jsx(Fn,{name:"amount_unit",control:p,render:({field:S})=>s.jsxs(Na,{id:"input-group-dropdown-1",title:S.value||"(no unit)",onSelect:j=>S.onChange(j),children:[s.jsx(at.Item,{eventKey:"",children:"(no unit)"},0),jw.map(j=>s.jsxs(at.Item,{eventKey:j.value,children:[j.label," (",j.value,")"]},j.value))]})}),I.amount&&s.jsx(W.Control.Feedback,{type:"invalid",children:I.amount.message})]})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Expire date"}),s.jsx(W.Control,{type:"date",...d("expire_date",{required:"An expire date is required"}),isInvalid:I.expire_date!==void 0}),I.expire_date&&s.jsx(W.Control.Feedback,{type:"invalid",children:I.expire_date.message})]}),s.jsxs(ie,{type:"submit",variant:"primary",disabled:C,children:[C&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),l&&s.jsxs("div",{className:"mt-3",children:[s.jsx(St,{variant:"success",children:"Container registered successfully"}),s.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[s.jsx("div",{children:s.jsx("a",{className:"btn btn-primary",href:`${o}/chemical/container/details/${l.id}/general.html`,children:"Go to container"})}),s.jsx(Si,{value:"reset-form",size:100,className:"float-end",onClick:()=>n()})]})]})]})}function tY({control:e,errors:t}){const[n,r]=x.useState({}),i=(o,l)=>{try{m1({query:o}).then(u=>{const d=u.items.map(g=>({value:g.id,label:g.name})),p={...n};d.forEach(g=>{p[g.value]=g}),r(p),l(d)})}catch(c){console.error("Error fetching types:",c)}},a=o=>n[o]||null;return s.jsx(Fn,{name:"container_type",control:e,render:({field:o})=>s.jsx(Fl,{isSearchable:!0,defaultOptions:!0,placeholder:"— Select a container type",loadOptions:i,value:a(o.value),onChange:l=>{o.onChange(l?.value)},styles:bf})})}function nY({room:e,resetForm:t,location:n,setLocation:r}){const{user:i}=x.useContext(hs),{environment:a}=Te.useParams(),[o,l]=x.useState(null);let c=new Date;c.setFullYear(c.getFullYear()+5);const{register:u,control:d,handleSubmit:p,watch:g,setValue:m,formState:{errors:v,isSubmitting:I}}=tn({defaultValues:{expire_date:c.toISOString().split("T")[0],owner:{value:i?.id,label:i?.full_name}}}),C=g("location");x.useEffect(()=>{C&&aa({id:C}).then(y=>{r(y)})},[C]),x.useEffect(()=>{let y="";const S=j=>{if(!(j.target instanceof HTMLInputElement||j.target instanceof HTMLTextAreaElement)&&!(j.key.length>1&&j.key!=="Enter"))if(j.key==="Enter"){if(Cw(y)){const N=Sw(y);N!==null&&(aa({id:N}).then(k=>{r(k)}),m("location",N))}y.startsWith("reset-scan-location")&&_(),y=""}else y+=j.key};return window.addEventListener("keydown",S),()=>{window.removeEventListener("keydown",S)}},[m]);const b=async y=>{y.user=y.owner.value;const S=await te.post("create/chemical/container",y);l(S.data)},_=()=>{r(null),m("location",0)};return s.jsxs(s.Fragment,{children:[s.jsxs(W,{onSubmit:p(b),children:[!n&&s.jsx(bw,{room:e,control:d,name:"location"}),n&&s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Scanned location"}),s.jsx(Pt,{children:s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx("span",{className:"h1",children:n.name}),s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx(Si,{value:"reset-scan-location",size:100,onClick:()=>_()}),s.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),n&&s.jsxs(s.Fragment,{children:[s.jsx(ww,{control:d,errors:v,setValue:m,...u("chemical",{required:"Chemical is required"})}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Owner"}),s.jsx(Fa,{control:d,...u("owner",{required:"Owner is required"}),name:"owner"})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Concentration"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...u("concentration",{required:"An concentration is required"}),isInvalid:v.concentration!==void 0}),v.concentration&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.concentration.message})]})]}),s.jsxs(W.Group,{className:"mb-3",children:[s.jsx(W.Label,{children:"Amount"}),s.jsxs(Kt,{className:"mb-3 w-25",hasValidation:!0,children:[s.jsx(W.Control,{as:"input",...u("amount",{required:"An amount is required"}),isInvalid:v.amount!==void 0}),s.jsx(Fn,{name:"amount_unit",control:d,render:({field:y})=>s.jsxs(Na,{id:"input-group-dropdown-1",title:y.value||"(no unit)",onSelect:S=>y.onChange(S),children:[s.jsx(at.Item,{eventKey:"",children:"(no unit)"},0),jw.map(S=>s.jsxs(at.Item,{eventKey:S.value,children:[S.label," (",S.value,")"]},S.value))]})}),v.amount&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.amount.message})]})]}),s.jsxs(Kt,{hasValidation:!0,className:"mb-3 row",children:[s.jsx(W.Label,{children:"Container type"}),s.jsx(tY,{control:d,...u("container_type",{required:"Container type is required"}),errors:v}),v.container_type&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.container_type.message})]}),s.jsxs(W.Group,{className:"mb-3 w-50 w-25-sm",children:[s.jsx(W.Label,{children:"Expire date"}),s.jsx(W.Control,{type:"date",...u("expire_date",{required:"An expire date is required"}),isInvalid:v.expire_date!==void 0}),v.expire_date&&s.jsx(W.Control.Feedback,{type:"invalid",children:v.expire_date.message})]}),s.jsxs(ie,{type:"submit",variant:"primary",disabled:I,children:[I&&s.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),o&&s.jsxs("div",{className:"mt-3",children:[s.jsx(St,{variant:"success",children:"Container registered successfully"}),s.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[s.jsx("div",{children:s.jsx("a",{className:"btn btn-primary",href:`${a}/chemical/container/render/single-${o.id}.pdf`,children:"Print label"})}),s.jsx("div",{children:s.jsx("a",{className:"btn btn-primary",href:`${a}/chemical/container/details/${o.id}/general.html`,children:"Go to container"})}),s.jsx(Si,{value:"reset-form",size:100,className:"float-end",onClick:()=>t()})]})]})]})}function rY(){const{environment:e}=Te.useParams(),[t,n]=x.useState(null),[r,i]=x.useState([]),[a,o]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(!1),[p,g]=x.useState(null),[m,v]=x.useState(null),{control:I,watch:C,reset:b,setValue:_}=tn({defaultValues:{room:p,barcode:""}}),y=C("room");x.useEffect(()=>{y&&(g(y),d(y.building.site.has_external_chemical_labelling))},[y]),x.useEffect(()=>{const k=new URLSearchParams(window.location.search).get("room");k&&S1({id:parseInt(k)}).then(A=>{g(A),d(A.building.site.has_external_chemical_labelling),_("room",A)})},[_]),x.useEffect(()=>{const k=new URLSearchParams(window.location.search).get("location");k&&aa({id:parseInt(k)}).then(A=>{v(A),g(A.zone_group.room),d(A.zone_group.room.building.site.has_external_chemical_labelling),_("room",A.zone_group.room)})},[_]);const S=C("barcode");x.useEffect(()=>{const k=setTimeout(()=>{if(!S?.includes("/l/")){if(S?.includes("/cc/")){n(S);const A=S.split("/cc/")[1];p1({id:parseInt(A)}).then(F=>{o(F)})}S&&(n(S),N({barcode:S}))}},1e3);return()=>{clearTimeout(k)}},[S,b]),x.useEffect(()=>{let k="";const A=F=>{F.target instanceof HTMLInputElement||F.target instanceof HTMLTextAreaElement||F.key.length>1&&F.key!=="Enter"||(F.key==="Enter"?(k==="reset-form"&&j(),k=""):k+=F.key)};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[b]);const j=()=>{b({room:p,barcode:""}),n(null),v(null)};async function N({barcode:k}){try{const A=await qg({qrCodeContent:k});A&&Array.isArray(A.items)&&A.items.length>0?(i(A.items),c(!1)):(c(!0),i([]))}catch(A){console.error("Error fetching chemical container external labels",A),i([]),c(!1)}}return s.jsxs("div",{children:[s.jsxs("div",{className:"d-flex justify-content-between",children:[s.jsx(YB,{control:I,name:"room"}),s.jsxs("div",{className:"d-flex flex-column",children:[s.jsx(Si,{value:"reset-form",size:100,className:"float-end",onClick:()=>j()}),s.jsx("span",{className:"text-muted",children:"Reset form"})]})]}),p&&u&&s.jsxs(St,{children:["Lab ",p.name," has external labels, each chemical material should have a material from the internal supplier/warehouse"]}),p&&!u&&s.jsxs(St,{children:["Lab ",p.name," has no external labels, labels can be printed via the intake form"]}),p!==null&&!t&&u&&s.jsx(WB,{control:I}),t&&a&&s.jsxs(St,{variant:"info d-flex flex-column gap-3",children:["This is already an own chemical material, this is ",a.chemical.name," and should be stored on"," ",a.location.name," in ",a.location.zone_group.room.name,s.jsx("a",{className:"alert-link",href:`${e}/chemical/container/details/${a.id}/general.html`,children:"Go to container"})]}),!a&&t&&s.jsx(s.Fragment,{children:r.length===0?s.jsx(St,{variant:"info d-flex flex-column gap-3",children:s.jsxs("div",{children:["No chemical container external labels found with label ",s.jsx("strong",{children:t})]})}):s.jsxs(Ht,{children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"ID"}),s.jsx("th",{children:"Label"}),s.jsx("th",{children:"Container"}),s.jsx("th",{children:"Location"})]})}),s.jsx("tbody",{children:r.map(k=>s.jsxs("tr",{children:[s.jsx("td",{children:k.id}),s.jsx("td",{children:k.label}),s.jsx("td",{children:s.jsx("a",{href:`/${e}/chemical/container/details/${k.container.id}/general.html`,children:k.container.chemical.name})}),s.jsx("td",{children:s.jsx("a",{href:`/${e}/location/details/${k.container.location.id}/general.html`,children:k.container.location.name})})]},k.id))})]})}),!a&&l&&p&&t&&s.jsx(eY,{room:p,barcode:t,location:m,setLocation:v,resetForm:j}),!a&&p&&!u&&s.jsx(nY,{room:p,location:m,setLocation:v,resetForm:j})]})}function iY({badge_uuid:e}){return s.jsxs("span",{className:"rounded p-2 bg-success",children:["Card read: ",e]})}function sY({user_id:e}){const[t,n]=x.useState("");return x.useEffect(()=>{const r="https://"+cp+`/api/onelab/view/user/${e}`;(async()=>{try{const a=await fetch(r);if(!a.ok)throw new Error(`Response status: ${a.status} with body: ${await a.text()}`);const o=await a.json();n(o.full_name)}catch(a){console.log(a)}})()},[]),s.jsxs("span",{className:"rounded p-2 bg-success",children:["Clients has detected user: ",t||"loading..."]})}function aY(){return s.jsx("div",{})}const bd=["all","equipment","not_set"],cp=document.getElementById("root")?.dataset.goldsteinEndpoint??"",oY="mock-token",lY=10,cY=15;async function uY(e){const t="https://"+cp+"/api/update/client-association",n=prompt("Select the new association for the client:",e);if(n===null){alert("Please enter a not null value");return}const[r,i]=n.split(":"),a=Number(i);if(!r||isNaN(a)||a===0){alert("Please follow the correct format: $item:$id");return}if(!bd.slice(1).includes(r)){alert("Please select a valid $item: (equipment, not_set)");return}const o=await fetch(t,{method:"PATCH",body:JSON.stringify({previous_association:e,new_association:n}),headers:{"Content-type":"application/json; charset=UTF-8"}});if(!o.ok)throw new Error(`Response status: ${o.status} with body: ${await o.text()}`);const l=await o.text();alert(l)}function dY(){const e=x.useRef(null),[t,n]=x.useState(new Map);async function r(u){const d=nb(u.notifications_list,new Date,lY,cY);n(d)}function i(){const d=`
36
36
  SELECT * FROM notifications
37
37
  ${l==="all"?"":`WHERE association_item = "${l}"`}
38
38
  `.trim(),p={listening_association:`${l}:*`,sql_statement:d};let g={package_type:pi.UPDATE_LISTENING_DATA,payload:JSON.stringify(p)};mi(e.current,g),g={package_type:pi.GET_DATA,payload:""},mi(e.current,g)}const a=()=>{setTimeout(()=>{(e.current===null||e.current.readyState===WebSocket.CLOSED||e.current.readyState===WebSocket.CLOSING)&&o()},1e3)},o=()=>{tb("wss://"+cp+"/ws",oY).then(u=>{e.current!==null&&e.current.close(),u.onmessage=p=>{eb(p,r)},u.onclose=()=>{console.log("WebSocket closed"),a()},u.onerror=p=>{console.error("WebSocket error",p),a()},e.current=u,console.log("WebSocket connected"),i();const d={package_type:pi.GET_DATA,payload:""};mi(u,d)}).catch(u=>{console.error("WebSocket connection failed",u),a()})};x.useEffect(()=>(o(),()=>{e.current&&(e.current.close(),console.log("Web socket disconnected"))}),[]);const[l,c]=x.useState(bd[0]);return x.useEffect(()=>{i()},[l]),s.jsxs("div",{children:[s.jsx("h1",{children:"Goldstein Clients"}),s.jsxs("div",{children:[s.jsx("label",{htmlFor:"typeFilter",children:"Filter by type:"}),s.jsx("select",{className:"form-control",id:"typeFilter",value:l,onChange:u=>c(u.target.value),children:bd.map(u=>s.jsx("option",{value:u,children:u},u))})]}),s.jsxs(Ht,{size:"sm",striped:!0,bordered:!0,hover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Client"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Actions"})]})}),s.jsx("tbody",{children:Array.from(t.entries()).map(([u,d])=>s.jsxs("tr",{children:[s.jsx("td",{children:u}),s.jsxs("td",{children:[d.status===hi.CLIENT_CONNECTED&&s.jsx(aY,{}),d.status===hi.CARD_READED&&s.jsx(iY,{badge_uuid:d.message.badgeUUID}),d.status===hi.USER_AUTHENTICATED&&s.jsx(sY,{user_id:d.message.userID})]}),s.jsx("td",{children:s.jsx("button",{className:"btn btn-primary",onClick:()=>uY(u),children:"Edit association"})})]},u))})]})]})}function fY({result:e,status:t,onAutoSave:n,onDirty:r}){const{control:i,formState:a}=Mk(),o=e.criterion_version,l=String(e.id),c=o.criterion.background_color&&o.criterion.has_background_color?{backgroundColor:o.criterion.background_color}:void 0,d=a.errors[l]?.message,p=o.required,g=b=>p?Array.isArray(b)?b.length>0||"This field is required.":typeof b=="boolean"||b!=null&&b!==""?!0:"This field is required.":!0,m=d?"is-invalid":t?.state==="saved"?"is-valid":t?.state==="dirty"?"border-warning":"",v=d?"border border-danger rounded p-2":t?.state==="saved"?"border border-success rounded p-2":t?.state==="dirty"?"border border-warning rounded p-2":"",I=b=>typeof b=="string"?b:"",C=o.criterion.values??{};return s.jsxs("div",{className:`form-group mb-3 rounded ${o.highlighted?"border border-warning":""}`,style:c,children:[s.jsxs("label",{htmlFor:`result-${e.id}`,className:"form-label",children:[o.criterion.criterion,o.required&&s.jsx("span",{className:"text-danger",children:"*"})]}),s.jsx(Fn,{name:l,control:i,rules:{validate:g},render:({field:b})=>{switch(o.criterion.input_type){case"integer":case"float":return s.jsx("input",{id:`result-${e.id}`,type:"number",step:o.criterion.input_type==="float"?"0.01":"1",className:`form-control ${m}`,value:I(b.value),onChange:_=>{b.onChange(_.target.value),r(e.id)},onBlur:()=>{b.onBlur(),n(e)}});case"date":return s.jsx("input",{id:`result-${e.id}`,type:"date",className:`form-control ${m}`,value:I(b.value),onChange:_=>{b.onChange(_.target.value),r(e.id)},onBlur:()=>{b.onBlur(),n(e)}});case"text":return s.jsx("textarea",{id:`result-${e.id}`,className:`form-control ${m}`,rows:3,value:I(b.value),onChange:_=>{b.onChange(_.target.value),r(e.id)},onBlur:()=>{b.onBlur(),n(e)}});case"string":return s.jsx("input",{id:`result-${e.id}`,type:"text",className:`form-control ${m}`,value:I(b.value),onChange:_=>{b.onChange(_.target.value),r(e.id)},onBlur:()=>{b.onBlur(),n(e)}});case"select":return s.jsxs("select",{id:`result-${e.id}`,className:`form-select ${m}`,value:I(b.value),onChange:_=>{b.onChange(_.target.value),r(e.id),n(e)},children:[s.jsx("option",{value:"",children:"-- select --"}),Object.entries(C).map(([_,y])=>s.jsx("option",{value:_,children:y},_))]});case"radio":{const _=String(b.value??"");return s.jsx("div",{className:`form-check ${v}`,children:Object.entries(C).map(([y,S])=>s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"radio",id:`result-${e.id}_${y}`,name:`result-${e.id}`,value:y,checked:_===y,onChange:j=>{b.onChange(j.target.value),r(e.id),n(e)},className:`form-check-input ${m}`}),s.jsx("label",{htmlFor:`result-${e.id}_${y}`,className:"form-check-label",children:S})]},y))})}case"checkbox":{const _=Array.isArray(b.value)?b.value:[],y=(S,j)=>{const N=j?[..._,S]:_.filter(k=>k!==S);b.onChange(N),r(e.id),n(e)};return s.jsx("div",{className:`form-check ${v}`,children:Object.entries(C).map(([S,j])=>s.jsxs("div",{className:"form-check",children:[s.jsx("input",{type:"checkbox",id:`result-${e.id}_${S}`,name:`result-${e.id}`,value:S,checked:_.includes(S),onChange:N=>y(S,N.target.checked),className:`form-check-input ${m}`}),s.jsx("label",{htmlFor:`result-${e.id}_${S}`,className:"form-check-label",children:j})]},S))})}case"bool":return s.jsx("div",{className:`form-check form-switch ${v}`,children:s.jsx("input",{type:"checkbox",id:`result-${e.id}`,checked:!!b.value,onChange:_=>{b.onChange(_.target.checked),r(e.id),n(e)},className:`form-check-input ${m}`})});case"action":return s.jsxs("div",{className:`d-flex align-items-center ${v}`,children:[s.jsx("label",{className:"me-2",children:"Done "}),s.jsxs("div",{role:"group","aria-label":`${e.id}-action`,className:"btn-group btn-group-sm",children:[s.jsx("button",{type:"button",className:`btn ${b.value?"btn-primary":"btn-outline-secondary"}`,onClick:()=>{b.onChange(!0),r(e.id),n(e)},"aria-pressed":!!b.value,children:"Yes"}),s.jsx("button",{type:"button",className:`btn ${b.value?"btn-outline-secondary":"btn-primary"}`,onClick:()=>{b.onChange(!1),r(e.id),n(e)},"aria-pressed":!b.value,children:"No"})]})]});default:return s.jsx(s.Fragment,{})}}}),o.criterion.help_block&&s.jsx("small",{className:"form-text text-muted",children:o.criterion.help_block}),d&&s.jsx("div",{className:"invalid-feedback",children:d})]})}function pY({categoryId:e,label:t,results:n}){const r=x.useRef({}),i=x.useRef({}),[a,o]=x.useState({}),l=x.useCallback(_=>{const y={},S=j=>j===null?null:String(j);return _.forEach(j=>{const N=j.criterion_version;if(N.criterion.input_type==="checkbox"){const k=j.value||N.default_value||"";y[String(j.id)]=k?k.toString().split(", "):[]}else if(N.criterion.input_type==="bool"||N.criterion.input_type==="action"){const k=j.value??N.default_value??"false";y[String(j.id)]=k==="true"}else{const k=j.value??N.default_value??"";y[String(j.id)]=S(k)??""}}),y},[]),c=x.useMemo(()=>l(n),[l,n]),u=tn({defaultValues:c,mode:"onBlur"}),{control:d,getValues:p,reset:g,trigger:m}=u;x.useEffect(()=>{const _=String(e),y=r.current[_];if(y)g(y);else{const S=l(n);r.current[_]=S,g(S)}o({})},[l,e,g,n]);const v=ey({control:d});x.useEffect(()=>{const _=String(e);if(!v)return;const y=Object.entries(v);r.current[_]=y.reduce((S,[j,N])=>(S[j]=N??null,S),{})},[v,e]);const I=x.useCallback(async _=>{const y=String(_.id);if(!await m(y))return;const j=p(y),N=(i.current[_.id]??0)+1;i.current[_.id]=N,o(A=>({...A,[_.id]:{state:"saving"}}));let k=j??"";Array.isArray(j)?k=j.join(", "):typeof j=="boolean"&&(k=j?"true":"false");try{await te.patch(`/update/service/event/report/result/${_.id}`,{value:k}),i.current[_.id]===N&&o(A=>({...A,[_.id]:{state:"saved",savedAt:Date.now()}}))}catch(A){console.error("Failed to save:",A),i.current[_.id]===N&&o(F=>({...F,[_.id]:{state:"error",message:"Save failed. Try again."}}))}},[p,m]),C=x.useCallback(_=>{o(y=>({...y,[_]:{state:"dirty"}}))},[]),b=x.useMemo(()=>Object.values(a).some(_=>_.state==="dirty"||_.state==="saving"||_.state==="error"),[a]);return x.useEffect(()=>{const _=y=>{b&&(y.preventDefault(),y.returnValue="")};return window.addEventListener("beforeunload",_),()=>window.removeEventListener("beforeunload",_)},[b]),s.jsxs(Ok,{...u,children:[s.jsx("legend",{children:t}),n.map(_=>s.jsx(fY,{result:_,status:a[_.id],onAutoSave:I,onDirty:C},_.id))]})}function mY(){const{id:e}=Te.useParams(),t=Te.useLocation(),n=Te.useNavigate(),[r,i]=x.useState(),[a,o]=x.useState({}),[l,c]=x.useState({}),[u,d]=x.useState(0),[p,g]=x.useState(null);x.useEffect(()=>{e&&(T1({id:Number(e)}).then(b=>{const _=b.reduce((j,N)=>{const k=N.criterion_version.type.category,A=String(k.id);return j[A]||(j[A]=[]),j[A].push(N),j},{}),y={},S={};b.forEach(j=>{const N=j.criterion_version.type.category,k=String(N.id);y[k]=N.category,S[k]=typeof N.sequence=="number"?N.sequence:Number.MAX_SAFE_INTEGER}),i(_),o(y),c(S)}),F1({id:Number(e)}).then(b=>g(b)).catch(()=>g(null)))},[e]);const m=x.useMemo(()=>r?Object.keys(r).sort((b,_)=>{const y=l[b]??Number.MAX_SAFE_INTEGER,S=l[_]??Number.MAX_SAFE_INTEGER;return y!==S?y-S:Number(b)-Number(_)}):[],[r,l]),v=m.length;if(x.useEffect(()=>{if(!v)return;const _=new URLSearchParams(t.search).get("category");if(_){const y=m.indexOf(_);if(y!==-1){d(y);return}}d(0)},[v,t.search,m]),x.useEffect(()=>{if(!v)return;const b=m[u],_=new URLSearchParams(t.search);b&&_.get("category")!==b&&(_.set("category",b),n({pathname:t.pathname,search:_.toString()},{replace:!1}))},[u,v,m,t.pathname,t.search,n]),!r)return s.jsx("div",{children:"Loading…"});if(v===0)return s.jsx("div",{children:"No categories found"});const I=()=>{d(b=>Math.max(b-1,0))},C=()=>{d(b=>Math.min(b+1,v-1))};return s.jsxs(x.Fragment,{children:[s.jsxs("div",{className:"d-flex justify-content-center align-items-center gap-3 mb-3",children:[s.jsx("button",{className:"btn btn-sm btn-outline-primary",onClick:I,disabled:u===0,children:"Previous"}),s.jsxs("div",{className:"text-center",children:["Category ",u+1," of ",v]}),s.jsx("button",{className:"btn btn-outline-primary btn-sm",onClick:C,disabled:u===v-1,children:"Next"})]}),s.jsx(pY,{categoryId:m[u],label:a[m[u]],results:r[m[u]]})]})}const $g={active:"text-bg-warning",approved:"text-bg-success",canceled:"text-bg-secondary",cancelled:"text-bg-secondary",completed:"text-bg-success",done:"text-bg-success",error:"text-bg-danger",expired:"text-bg-secondary",failed:"text-bg-danger",pending:"text-bg-warning",processing:"text-bg-warning",queued:"text-bg-warning",rejected:"text-bg-danger",running:"text-bg-warning",skipped:"text-bg-secondary",started:"text-bg-warning",success:"text-bg-success",uploaded:"text-bg-success"};function Iw(e){const t=e.trim().toLowerCase();return t in $g?$g[t]:/(fail|error|reject|invalid|deny)/.test(t)?"text-bg-danger":/(complete|done|success|approve|upload|finish|ready|ok)/.test(t)?"text-bg-success":/(run|process|progress|pending|queue|start|wait|active)/.test(t)?"text-bg-warning":/(cancel|skip|expire|close|stop)/.test(t)?"text-bg-secondary":"text-bg-info"}function hY(e){return e instanceof Map?Array.from(e.entries()):Array.isArray(e)?e.flatMap(t=>Array.isArray(t)&&t.length===2&&typeof t[0]=="string"&&typeof t[1]=="string"?[[t[0],t[1]]]:[]):typeof e=="object"&&e!==null?Object.entries(e).flatMap(([t,n])=>typeof n=="string"?[[t,n]]:[]):[]}const gY={approve:{action:"approve",buttonClassName:"btn-success",label:"Approve",successMessage:"Upload approved."},fail:{action:"fail",buttonClassName:"btn-outline-warning",label:"Mark as failed",successMessage:"Upload marked as failed."},finish:{action:"finish",buttonClassName:"btn-primary",label:"Mark as finished",successMessage:"Upload marked as finished."},reject:{action:"reject",buttonClassName:"btn-outline-danger",label:"Reject",successMessage:"Upload rejected."}},xY={awaiting_approval:["approve","reject","fail"],started:["reject","fail"],syncing:["fail"],uploading:["finish","reject","fail"]};function vY(e){return(xY[e]??[]).map(n=>gY[n])}function yY(e){if(typeof e=="object"&&e!==null&&"response"in e){const t=e.response;if(typeof t?.data?.message=="string")return t.data.message}return e instanceof Error&&e.message!==""?e.message:"Could not process upload action."}function bY({event:e,contentEntries:t,irisEndpoint:n,onEventUpdated:r}){const[i,a]=x.useState(null),[o,l]=x.useState(""),[c,u]=x.useState(""),d=x.useMemo(()=>e?vY(e.state):[],[e]),p=x.useCallback(async g=>{if(e){a(g),l(""),u("");try{const m={fileUploadEventUid:e.uid,irisServerUrl:n};let v;g==="approve"?v=await $1(m):g==="fail"?v=await H1(m):g==="finish"?v=await U1(m):v=await X1(m);const I=d.find(C=>C.action===g);r(v),u(I?.successMessage??"Action completed.")}catch(m){l(yY(m))}finally{a(null)}}},[d,e,n,r]);return s.jsxs("div",{className:"border rounded h-100",children:[s.jsxs("div",{className:"border-bottom px-3 py-2",children:[s.jsx("div",{className:"fw-semibold",children:"Event details"}),s.jsx("div",{className:"small text-secondary",children:"Inspect the current state and attached payload files"})]}),!e&&s.jsx("div",{className:"p-4 text-secondary",children:"Choose an event to inspect its details."}),e&&s.jsxs("div",{className:"p-3 p-lg-4",children:[s.jsxs("div",{className:"d-flex flex-column flex-md-row justify-content-between gap-3 mb-4",children:[s.jsxs("div",{children:[s.jsx("div",{className:"small text-secondary text-uppercase fw-semibold mb-1",children:"Event id"}),s.jsx("code",{className:"text-break",children:e.uid})]}),s.jsx("div",{className:"d-flex align-items-start",children:s.jsx("span",{className:`badge ${Iw(e.state)}`,children:e.state})})]}),s.jsxs("div",{className:"row g-3 mb-4",children:[s.jsx("div",{className:"col-md-6",children:s.jsxs("div",{className:"rounded border p-3 h-100",children:[s.jsx("div",{className:"small text-secondary text-uppercase fw-semibold mb-1",children:"Context"}),s.jsx("div",{className:"fw-semibold text-break",children:e.context})]})}),s.jsx("div",{className:"col-md-6",children:s.jsxs("div",{className:"rounded border p-3 h-100",children:[s.jsx("div",{className:"small text-secondary text-uppercase fw-semibold mb-1",children:"Started"}),s.jsx("div",{className:"fw-semibold",children:ln(e.start)})]})}),s.jsx("div",{className:"col-md-4",children:s.jsxs("div",{className:"rounded border p-3 h-100",children:[s.jsx("div",{className:"small text-secondary text-uppercase fw-semibold mb-1",children:"Completed state"}),s.jsx("div",{className:"fw-semibold text-break",children:e.completedState||"-"})]})}),s.jsx("div",{className:"col-md-4",children:s.jsxs("div",{className:"rounded border p-3 h-100",children:[s.jsx("div",{className:"small text-secondary text-uppercase fw-semibold mb-1",children:"TTL"}),s.jsx("div",{className:"fw-semibold",children:e.TTL})]})}),s.jsx("div",{className:"col-md-4",children:s.jsxs("div",{className:"rounded border p-3 h-100",children:[s.jsx("div",{className:"small text-secondary text-uppercase fw-semibold mb-1",children:"Auto approve"}),s.jsx("div",{className:"fw-semibold",children:e.autoApprove?"Enabled":"Disabled"})]})})]}),s.jsxs("div",{className:"mb-4",children:[s.jsx("div",{className:"d-flex justify-content-between align-items-center mb-2 gap-2",children:s.jsxs("div",{children:[s.jsx("h3",{className:"h6 mb-0",children:"Actions"}),s.jsx("div",{className:"small text-secondary",children:"State transition actions available for this event"})]})}),d.length===0&&s.jsx("div",{className:"rounded border p-3 text-secondary",children:"No manual actions are available for this state."}),d.length>0&&s.jsx("div",{className:"d-flex flex-wrap gap-2",children:d.map(g=>s.jsx("button",{type:"button",className:`btn btn-sm ${g.buttonClassName}`,disabled:i!==null,onClick:()=>p(g.action),children:i===g.action?"Processing...":g.label},g.action))}),o!==""&&s.jsx("div",{className:"alert alert-danger py-2 mt-3 mb-0",children:o}),c!==""&&s.jsx("div",{className:"alert alert-success py-2 mt-3 mb-0",children:c})]}),s.jsxs("div",{children:[s.jsx("div",{className:"d-flex justify-content-between align-items-center mb-2 gap-2",children:s.jsxs("div",{children:[s.jsx("h3",{className:"h6 mb-0",children:"Attached files"}),s.jsxs("div",{className:"small text-secondary",children:[t.length," file entries available"]})]})}),t.length===0&&s.jsx("div",{className:"rounded border p-3 text-secondary",children:"This event does not include attached files."}),t.length>0&&s.jsx("div",{className:"vstack gap-3",children:t.map(([g,m])=>s.jsxs("div",{className:"rounded border overflow-hidden",children:[s.jsxs("div",{className:"px-3 py-2 border-bottom d-flex justify-content-between align-items-center gap-2",children:[s.jsx("code",{className:"text-break",children:g}),s.jsx("span",{className:"badge border",children:"attached"})]}),s.jsx("pre",{className:"m-0 p-3 bg-body-tertiary",style:{maxHeight:220,overflow:"auto"},children:s.jsx("code",{children:m})})]},g))})]})]})]})}function wY({activeContext:e,events:t,selectedEventUid:n,onSelectEvent:r}){return s.jsxs("div",{className:"border rounded overflow-hidden h-100",children:[s.jsxs("div",{className:"border-bottom px-3 py-2",children:[s.jsx("div",{className:"fw-semibold",children:"Incoming upload events"}),s.jsx("div",{className:"small text-secondary",children:"Latest messages for the selected context"})]}),s.jsxs("div",{className:"list-group list-group-flush",children:[t.map(i=>{const a=n===i.uid;return s.jsxs("button",{type:"button",className:`list-group-item list-group-item-action text-start ${a?"active":""}`,onClick:()=>r(i.uid),children:[s.jsxs("div",{className:"d-flex justify-content-between align-items-start gap-2 mb-2",children:[s.jsx("code",{className:a?"text-white":"",children:i.uid}),s.jsx("span",{className:`badge ${Iw(i.state)}`,children:i.state})]}),s.jsxs("div",{className:`small ${a?"text-white-50":"text-secondary"}`,children:[s.jsxs("div",{children:["Context: ",i.context]}),s.jsxs("div",{children:["Started: ",ln(i.start)]})]})]},i.uid)}),e!==""&&t.length===0&&s.jsx("div",{className:"list-group-item text-secondary",children:"Listening for new events..."}),e===""&&s.jsx("div",{className:"list-group-item text-secondary",children:"Select a context to start the live stream."})]})]})}function CY({irisEndpoint:e,context:t,onMessage:n,onError:r}){const i=x.useRef(null),a=x.useRef(null),o=x.useRef(!0),l=x.useRef(0),[c,u]=x.useState(!1);return x.useEffect(()=>{if(!t)return;o.current=!0;const p=()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null)},g=()=>{p();const m=W1({context:t,irisServerUrl:e.endsWith("/")?e:`${e}/`,onOpen:()=>{l.current=0,u(!0)},onEvent:v=>{n(v)},onError:v=>{if(u(!1),r(v),m.close(),!o.current)return;const I=Math.min(1e3*2**l.current,3e4);l.current+=1,a.current=window.setTimeout(()=>{g()},I)}});i.current=m,m.start()};return g(),()=>{o.current=!1,p(),i.current?.close(),i.current=null,u(!1)}},[e,t,n,r]),{isConnected:c,close:()=>{o.current=!1,a.current!==null&&(window.clearTimeout(a.current),a.current=null),i.current?.close(),i.current=null,u(!1)}}}function SY(){const[e,t]=x.useState(""),[n,r]=x.useState(""),[i,a]=x.useState([]),[o,l]=x.useState(""),[c,u]=x.useState(""),d=Z1();x.useEffect(()=>{n&&z1({irisServerUrl:d,context:n}).then(b=>{a(b)})},[n]);const p=x.useCallback(b=>{n!==""&&b.context===n&&(u(""),a(_=>[b,..._.filter(y=>y.uid!==b.uid)]),l(b.uid))},[n]),g=x.useCallback(b=>{if(n===""){u("");return}if(b===null){u("");return}u("Error trying to connect to the server, reconnecting....")},[n]),{isConnected:m}=CY({irisEndpoint:d,context:n,onMessage:p,onError:g}),v=x.useCallback(b=>{b.preventDefault(),r(e),a([]),l(""),u("")},[e]),I=x.useMemo(()=>i.length===0?null:i.find(b=>b.uid===o)??i[0],[i,o]),C=x.useMemo(()=>I?hY(I.content):[],[I]);return s.jsx("div",{className:"w-100",children:s.jsx("div",{className:"card shadow-sm border-0",children:s.jsxs("div",{className:"card-body p-3 p-lg-4",children:[s.jsxs("form",{onSubmit:v,className:"row g-2 align-items-end mb-4",children:[s.jsxs("div",{className:"col-lg-8",children:[s.jsx("label",{className:"form-label fw-semibold",htmlFor:"iris-context-input",children:"Context"}),s.jsx("input",{id:"iris-context-input",className:"form-control",type:"text",value:e,placeholder:"lab-a",onChange:b=>t(b.target.value)})]}),s.jsx("div",{className:"col-lg-4 col-xl-2",children:s.jsx("button",{className:"btn btn-primary w-100",type:"submit",disabled:e.trim()==="",children:"Load context"})})]}),c!==""&&s.jsx("div",{className:"alert alert-danger py-2 mb-4",children:c}),!m&&s.jsx("div",{className:"alert alert-warning py-2 mb-4",children:"Could not connect to the server"}),m&&s.jsxs("div",{className:"row g-3",children:[s.jsx("div",{className:"col-xl-5",children:s.jsx(wY,{activeContext:n,events:i,selectedEventUid:I?.uid||"",onSelectEvent:l})}),s.jsx("div",{className:"col-xl-7",children:s.jsx(bY,{event:I,contentEntries:C,irisEndpoint:d,onEventUpdated:p},I?.uid||"")})]},`${n}${i.length>0?i[0].uid:""}`)]})})})}exports.AuthContext=hs;exports.AuthProvider=J1;exports.BatchCardElement=ip;exports.ChemicalHeaderElement=BB;exports.ChemicalIntakeElement=rY;exports.DateFormat=wi;exports.EmphasizedParametersContext=Kl;exports.EmphasizedParametersProvider=GB;exports.EquipmentContext=Ql;exports.EquipmentDashboard=fG;exports.EquipmentHeaderElement=hG;exports.EquipmentProvider=B0;exports.GoldsteinClientsDashboard=dY;exports.GoldsteinEquipmentDashboard=DM;exports.InputModal=ow;exports.IrisOperatorDashboard=SY;exports.ModuleStatusElement=Jr;exports.MonitorCard=rp;exports.MonitorContext=H0;exports.MonitorHeaderElement=zG;exports.MonitorPage=WG;exports.MonitorProvider=UG;exports.NavigateInRunWithQrScanner=lw;exports.PaginationLinks=za;exports.ReportResults=mY;exports.RunContext=Ri;exports.RunHeaderElement=JG;exports.RunInformationElement=lB;exports.RunProvider=U0;exports.RunStepChecklist=iw;exports.RunStepContext=rn;exports.RunStepExecuteElement=kB;exports.RunStepExecuteMinimal=MB;exports.RunStepHeaderElement=uB;exports.RunStepProvider=nw;exports.RunStepsElement=oB;exports.SelectRunWithQrScanner=lw;exports.SetupUpdateEquipment=lM;exports.StatusMailComponent=aG;exports.StatusMailContext=Tl;exports.StatusMailProvider=gG;exports.StepDetails=Q0;exports.initSolodbComponents=q1;exports.useAuth=ax;