@jield/solodb-react-components 1.0.3 → 1.0.5

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
@@ -42,7 +42,7 @@ Arguments: `+Array.prototype.slice.call(r).join("")+`
42
42
  `},i),s}function SW(e,t){return e&&"run"in e?async function(n,r){const i=Jx(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Jx(n,{file:r,...e||t})}}function Qx(e){if(e)throw e}var Pd,Kx;function CW(){if(Kx)return Pd;Kx=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(c){return typeof Array.isArray=="function"?Array.isArray(c):t.call(c)==="[object Array]"},s=function(c){if(!c||t.call(c)!=="[object Object]")return!1;var d=e.call(c,"constructor"),p=c.constructor&&c.constructor.prototype&&e.call(c.constructor.prototype,"isPrototypeOf");if(c.constructor&&!d&&!p)return!1;var h;for(h in c);return typeof h>"u"||e.call(c,h)},a=function(c,d){n&&d.name==="__proto__"?n(c,d.name,{enumerable:!0,configurable:!0,value:d.newValue,writable:!0}):c[d.name]=d.newValue},l=function(c,d){if(d==="__proto__")if(e.call(c,d)){if(r)return r(c,d).value}else return;return c[d]};return Pd=function u(){var c,d,p,h,m,g,y=arguments[0],b=1,S=arguments.length,R=!1;for(typeof y=="boolean"&&(R=y,y=arguments[1]||{},b=2),(y==null||typeof y!="object"&&typeof y!="function")&&(y={});b<S;++b)if(c=arguments[b],c!=null)for(d in c)p=l(y,d),h=l(c,d),y!==h&&(R&&h&&(s(h)||(m=i(h)))?(m?(m=!1,g=p&&i(p)?p:[]):g=p&&s(p)?p:{},a(y,{name:d,newValue:u(R,g,h)})):typeof h<"u"&&a(y,{name:d,newValue:h}));return y},Pd}var _W=CW();const Ld=bi(_W);function Jf(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 EW(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const a=i.pop();if(typeof a!="function")throw new TypeError("Expected function as last argument, not "+a);l(null,...i);function l(u,...c){const d=e[++s];let p=-1;if(u){a(u);return}for(;++p<i.length;)(c[p]===null||c[p]===void 0)&&(c[p]=i[p]);i=c,d?IW(d,l)(...c):a(null,...c)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function IW(e,t){let n;return r;function r(...a){const l=e.length>a.length;let u;l&&a.push(i);try{u=e.apply(this,a)}catch(c){const d=c;if(l&&n)throw d;return i(d)}l||(u&&u.then&&typeof u.then=="function"?u.then(s,i):u instanceof Error?i(u):s(u))}function i(a,...l){n||(n=!0,t(a,...l))}function s(a){i(null,a)}}const gr={basename:jW,dirname:RW,extname:kW,join:AW,sep:"/"};function jW(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Ao(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let a=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else a<0&&(s=!0,a=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=a));return n===r?r=a:r<0&&(r=e.length),e.slice(n,r)}function RW(e){if(Ao(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 kW(e){Ao(e);let t=e.length,n=-1,r=0,i=-1,s=0,a;for(;t--;){const l=e.codePointAt(t);if(l===47){if(a){r=t+1;break}continue}n<0&&(a=!0,n=t+1),l===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function AW(...e){let t=-1,n;for(;++t<e.length;)Ao(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":NW(n)}function NW(e){Ao(e);const t=e.codePointAt(0)===47;let n=OW(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function OW(e,t){let n="",r=0,i=-1,s=0,a=-1,l,u;for(;++a<=e.length;){if(a<e.length)l=e.codePointAt(a);else{if(l===47)break;l=47}if(l===47){if(!(i===a-1||s===1))if(i!==a-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(u=n.lastIndexOf("/"),u!==n.length-1){u<0?(n="",r=0):(n=n.slice(0,u),r=n.length-1-n.lastIndexOf("/")),i=a,s=0;continue}}else if(n.length>0){n="",r=0,i=a,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,a):n=e.slice(i+1,a),r=a-i-1;i=a,s=0}else l===46&&s>-1?s++:s=-1}return n}function Ao(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const DW={cwd:MW};function MW(){return"/"}function Qf(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function FW(e){if(typeof e=="string")e=new URL(e);else if(!Qf(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 TW(e)}function TW(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 Vd=["history","path","basename","stem","extname","dirname"];class a1{constructor(t){let n;t?Qf(t)?n={path:t}:typeof t=="string"||PW(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":DW.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Vd.length;){const s=Vd[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)Vd.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?gr.basename(this.path):void 0}set basename(t){Gd(t,"basename"),Bd(t,"basename"),this.path=gr.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?gr.dirname(this.path):void 0}set dirname(t){ey(this.basename,"dirname"),this.path=gr.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?gr.extname(this.path):void 0}set extname(t){if(Bd(t,"extname"),ey(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=gr.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Qf(t)&&(t=FW(t)),Gd(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?gr.basename(this.path,this.extname):void 0}set stem(t){Gd(t,"stem"),Bd(t,"stem"),this.path=gr.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 fn(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 Bd(e,t){if(e&&e.includes(gr.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+gr.sep+"`")}function Gd(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function ey(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function PW(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const LW=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),VW={}.hasOwnProperty;class Wm extends LW{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=EW()}copy(){const t=new Wm;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Ld(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Hd("data",this.frozen),this.namespace[t]=n,this):VW.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Hd("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=hl(t),r=this.parser||this.Parser;return zd("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),zd("process",this.parser||this.Parser),Yd("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,a){const l=hl(t),u=r.parse(l);r.run(u,l,function(d,p,h){if(d||!p||!h)return c(d);const m=p,g=r.stringify(m,h);zW(g)?h.value=g:h.result=g,c(d,h)});function c(d,p){d||!p?a(d):s?s(p):n(void 0,p)}}}processSync(t){let n=!1,r;return this.freeze(),zd("processSync",this.parser||this.Parser),Yd("processSync",this.compiler||this.Compiler),this.process(t,i),ny("processSync","process",n),r;function i(s,a){n=!0,Qx(s),r=a}}run(t,n,r){ty(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(a,l){const u=hl(n);i.run(t,u,c);function c(d,p,h){const m=p||t;d?l(d):a?a(m):r(void 0,m,h)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),ny("runSync","run",r),i;function s(a,l){Qx(a),i=l,r=!0}}stringify(t,n){this.freeze();const r=hl(n),i=this.compiler||this.Compiler;return Yd("stringify",i),ty(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Hd("use",this.frozen),t!=null)if(typeof t=="function")u(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):a(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(c){if(typeof c=="function")u(c,[]);else if(typeof c=="object")if(Array.isArray(c)){const[d,...p]=c;u(d,p)}else a(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function a(c){if(!("plugins"in c)&&!("settings"in c))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(c.plugins),c.settings&&(i.settings=Ld(!0,i.settings,c.settings))}function l(c){let d=-1;if(c!=null)if(Array.isArray(c))for(;++d<c.length;){const p=c[d];s(p)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function u(c,d){let p=-1,h=-1;for(;++p<r.length;)if(r[p][0]===c){h=p;break}if(h===-1)r.push([c,...d]);else if(d.length>0){let[m,...g]=d;const y=r[h][1];Jf(y)&&Jf(m)&&(m=Ld(!0,y,m)),r[h]=[c,m,...g]}}}}const BW=new Wm().freeze();function zd(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Yd(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Hd(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 ty(e){if(!Jf(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function ny(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function hl(e){return GW(e)?e:new a1(e)}function GW(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function zW(e){return typeof e=="string"||YW(e)}function YW(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const HW="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",ry=[],iy={allowDangerousHtml:!0},$W=/^(https?|ircs?|mailto|xmpp)$/i,WW=[{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 ss(e){const t=UW(e),n=qW(e);return XW(t.runSync(t.parse(n),n),e)}function UW(e){const t=e.rehypePlugins||ry,n=e.remarkPlugins||ry,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...iy}:iy;return BW().use(j$).use(n).use(SW,r).use(t)}function qW(e){const t=e.children||"",n=new a1;return typeof t=="string"&&(n.value=t),n}function XW(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,a=t.skipHtml,l=t.unwrapDisallowed,u=t.urlTransform||ZW;for(const d of WW)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+HW+d.id,void 0);return s1(e,c),aY(e,{Fragment:o.Fragment,components:i,ignoreInvalidStyle:!0,jsx:o.jsx,jsxs:o.jsxs,passKeys:!0,passNode:!0});function c(d,p,h){if(d.type==="raw"&&h&&typeof p=="number")return a?h.children.splice(p,1):h.children[p]={type:"text",value:d.value},p;if(d.type==="element"){let m;for(m in Md)if(Object.hasOwn(Md,m)&&Object.hasOwn(d.properties,m)){const g=d.properties[m],y=Md[m];(y===null||y.includes(d.tagName))&&(d.properties[m]=u(String(g||""),m,d))}}if(d.type==="element"){let m=n?!n.includes(d.tagName):s?s.includes(d.tagName):!1;if(!m&&r&&typeof p=="number"&&(m=!r(d,p,h)),m&&h&&typeof p=="number")return l&&d.children?h.children.splice(p,1,...d.children):h.children.splice(p,1),p}}}function ZW(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||$W.test(e.slice(0,t))?e:""}function sy({ecn:e,equipment:t,ecnAttachments:n,reloadQueryFn:r,expanded:i=!0}){const[s,a]=x.useState(null),[l,u]=x.useState(!1),[c,d]=x.useState(e),[p,h]=x.useState(i),m=b=>{r(["ecn","attachment","status_mail"]),d({...c,...b})},g=()=>n.filter(b=>b.ecn.id===e.id),y=()=>{a(o.jsx(Ju,{equipment:t,showModal:!0,onClose:b=>{u(!1),b&&(r(["ecn","attachment","status_mail"]),m(b))},ecn:c,attachments:g()})),u(!0)};return o.jsxs("div",{className:"p-3 mb-4 border-bottom",children:[o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-2",children:[o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(hn,{bg:"dark",children:"ECN"}),o.jsx("h4",{className:c.date_closed?"text-danger mb-0":"mb-0",children:c.date_closed?o.jsx("s",{children:c.ecn}):c.ecn})]}),o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(de,{variant:"outline-primary",size:"sm",onClick:()=>h(b=>!b),"aria-label":"Toggle Details",children:p?"Hide Details":"Show Details"}),o.jsx(de,{variant:"secondary",size:"sm",onClick:y,"aria-label":"Edit ECN",children:"Edit"})]})]}),p&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"mb-3",children:o.jsx(ss,{children:c.description})}),o.jsxs("div",{className:"d-flex flex-wrap text-muted",children:[o.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[o.jsx("small",{className:"text-muted",children:"Creator"}),o.jsx("div",{className:"text-body",children:c.owner.full_name})]}),o.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[o.jsx("small",{className:"text-muted",children:"Date Created"}),o.jsx("div",{className:"text-body",children:ye(c.date_created).format("DD MMMM YYYY")})]}),c.date_closed&&o.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[o.jsx("small",{className:"text-muted",children:"Date Closed"}),o.jsx("div",{className:"text-danger",children:ye(c.date_closed).format("DD MMMM YYYY")})]}),o.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[o.jsx("small",{className:"text-muted",children:"Attachments"}),o.jsx("div",{className:"text-body",children:c.attachments})]}),c.updated_by&&o.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[o.jsx("small",{className:"text-muted",children:"Last Update By"}),o.jsx("div",{className:"text-body",children:c.updated_by.full_name})]}),c.last_update&&o.jsxs("div",{className:"flex-fill pe-3 mb-2",children:[o.jsx("small",{className:"text-muted",children:"Last Update"}),o.jsx("div",{className:"text-body",children:ye(c.last_update).format("DD MMMM YYYY")})]})]})]}),l&&s]})}const No=({equipment:e,showModal:t,onClose:n,issue:r,attachments:i})=>{const[s,a]=x.useState([]),[l,u]=x.useState([]),{user:c}=x.useContext($s),[d,p]=x.useState(i),{register:h,handleSubmit:m,reset:g,control:y}=gn({defaultValues:{issue:r?.issue||"",description:r?.description||"",issue_type:r?.issue_type||Wr.DEFAULT,status:r?.status||Ra.ACTIVE,forecast_up:r?.forecast_up?new Date(r?.forecast_up).toISOString().split("T")[0]:"",actions:r?.actions||"",owner:r?.owner||{}}});x.useEffect(()=>{r&&g({issue:r?.issue||"",description:r?.description||"",issue_type:r?.issue_type||Wr.DEFAULT,status:r?.status||Ra.ACTIVE,forecast_up:r?.forecast_up?new Date(r?.forecast_up).toISOString().split("T")[0]:"",actions:r?.actions||"",owner:r?.owner||{}})},[r,g]);const{getRootProps:b,getInputProps:S,isDragActive:R}=Co({accept:{"application/*":[],"image/*":[]},onDrop:A=>{a(F=>[...F,...A])}});x.useEffect(()=>{t&&(async()=>{if(e?.id)try{const F=await Hi({equipment:e});u(F.items||[])}catch(F){console.error("Error fetching modules:",F)}})()},[e,t]);async function w(){await Ee.delete(`/delete/equipment/module/issue/${r?.id}`);const A={...r,date_closed:new Date().toISOString(),last_update:new Date().toISOString(),updated_by:c?.full_name};n(A)}const E=A=>{a(F=>F.filter((P,B)=>B!==A))},C=A=>{d&&p(F=>F?.filter((P,B)=>B!==A))},k=(A,F)=>new Promise(async(P,B)=>{try{if(d&&i&&i!=d)for(let V=0;V<i.length;V++){const z=i[V].id;let Y=!1;for(let T=0;T<d.length;T++){const U=d[T].id;if(z==U){Y=!0;break}}Y||await Ee.delete(`/delete/equipment/module/issue/attachment/${i[V].id}`)}A.length>0&&F&&await Promise.all(A.map(async V=>{const z=await Py(V),Y={issue_id:F,filename:V.name,type:V.type,content:z};await Ee.post("/create/equipment/module/issue/attachment",Y)})),P()}catch(V){B(V)}}),I=async A=>{try{let F;const P={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 k(s,r.id),F=(await Ee.patch(`/update/equipment/module/issue/${r?.id}`,P)).data):(F=(await Ee.post("/create/equipment/module/issue",P)).data,k(s,F.id),F.attachments=s.length),n(F)}catch(F){console.error("Error submitting the form:",F)}};return x.useEffect(()=>{t&&(async()=>{if(e?.id)try{const F=await Hi({equipment:e});u(F.items||[])}catch(F){console.error("Error fetching modules:",F)}})()},[e,t]),o.jsx(xe,{show:t,size:"lg",centered:!0,onHide:()=>n(r),children:o.jsxs(H,{onSubmit:m(I),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:r?`Edit Issue for ${e.name}`:`Create new Issue for ${e.name}`})}),o.jsxs(xe.Body,{children:[!r&&o.jsxs(H.Group,{controlId:"module",className:"mb-3",children:[o.jsx(H.Label,{children:"Module"}),o.jsxs(H.Select,{...h("module_id",{required:"Module is required"}),children:[o.jsx("option",{value:"",children:"— Select a module"}),l.map(A=>o.jsx("option",{value:A.id,children:A.name},A.id))]})]}),o.jsxs(H.Group,{controlId:"issue",children:[o.jsx(H.Label,{children:"Issue"}),o.jsx(H.Control,{type:"text",...h("issue",{required:"Issue content is required"}),autoFocus:!0})]}),o.jsxs(H.Group,{controlId:"description",className:"mt-3",children:[o.jsx(H.Label,{children:"Description"}),o.jsx(H.Control,{as:"textarea",rows:3,...h("description",{required:"Description is required"})})]}),o.jsxs(H.Group,{controlId:"issueType",className:"mt-3",children:[o.jsx(H.Label,{children:"Issue"}),o.jsxs(H.Control,{as:"select",...h("issue_type",{required:"Issue type is required"}),children:[o.jsx("option",{value:Wr.DEFAULT,children:"Default"}),o.jsx("option",{value:Wr.PRIORITY,children:"Priority"}),o.jsx("option",{value:Wr.ESCALATION,children:"Escalation"})]})]}),o.jsxs(H.Group,{controlId:"status",className:"mt-3",children:[o.jsx(H.Label,{children:"Status"}),o.jsxs(H.Control,{as:"select",...h("status",{required:"Status is required"}),children:[o.jsx("option",{value:Ra.ACTIVE,children:"Active"}),o.jsx("option",{value:Ra.CLOSED,children:"Closed"})]})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Owner"}),o.jsx(_o,{control:y,...h("owner",{required:"Owner is required"}),name:"owner"})]}),o.jsxs(H.Group,{controlId:"forecastUp",className:"mt-3",children:[o.jsx(H.Label,{children:"Forecast Up"}),o.jsx(H.Control,{type:"date",...h("forecast_up",{required:"Forecast Up date is required"})})]}),o.jsxs(H.Group,{controlId:"actions",className:"mt-3",children:[o.jsx(H.Label,{children:"Actions"}),o.jsx(H.Control,{as:"textarea",rows:5,...h("actions",{required:!1})})]}),o.jsxs(H.Group,{children:[o.jsx(H.Label,{children:"Attachments"}),o.jsxs("div",{...b({className:`dropzone ${R?"active":""}`,style:{border:"2px dashed #007bff",padding:"10px",textAlign:"center"}}),children:[o.jsx("input",{...S()}),R?o.jsx("p",{children:"Drop the files here..."}):o.jsx("p",{children:"Drag & drop files here, or click to select files"})]}),s.length>0&&o.jsx("ul",{children:s.map((A,F)=>o.jsxs("li",{children:[A.name," ",o.jsx(de,{variant:"secondary",onClick:()=>E(F),children:"cancel"})]},F))})]}),d&&d.length>0&&o.jsxs(H.Group,{controlId:"uploaded_files",className:"mt-3",children:[o.jsx(H.Label,{children:"Uploaded files"}),o.jsx("ul",{children:d.map((A,F)=>o.jsxs("li",{children:[A.filename," ",o.jsx(de,{variant:"secondary",onClick:()=>C(F),children:"delete"})]},F))})]})]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{variant:"secondary",onClick:()=>n(r),children:"Cancel"}),o.jsx(de,{variant:"primary",type:"submit",children:r?"Update Issue":"Create Issue"}),r&&o.jsx(de,{variant:"danger",onClick:()=>w(),children:"Close Issue"})]})]})})};function JW(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 Ml={exports:{}},QW=Ml.exports,ay;function KW(){return ay||(ay=1,(function(e,t){(function(n,r){e.exports=r()})(QW,(function(){var n;function r(){return n.apply(null,arguments)}function i(f){n=f}function s(f){return f instanceof Array||Object.prototype.toString.call(f)==="[object Array]"}function a(f){return f!=null&&Object.prototype.toString.call(f)==="[object Object]"}function l(f,v){return Object.prototype.hasOwnProperty.call(f,v)}function u(f){if(Object.getOwnPropertyNames)return Object.getOwnPropertyNames(f).length===0;var v;for(v in f)if(l(f,v))return!1;return!0}function c(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 h(f,v){var _=[],j,O=f.length;for(j=0;j<O;++j)_.push(v(f[j],j));return _}function m(f,v){for(var _ in v)l(v,_)&&(f[_]=v[_]);return l(v,"toString")&&(f.toString=v.toString),l(v,"valueOf")&&(f.valueOf=v.valueOf),f}function g(f,v,_,j){return hh(f,v,_,j,!0).utc()}function y(){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 b(f){return f._pf==null&&(f._pf=y()),f._pf}var S;Array.prototype.some?S=Array.prototype.some:S=function(f){var v=Object(this),_=v.length>>>0,j;for(j=0;j<_;j++)if(j in v&&f.call(this,v[j],j,v))return!0;return!1};function R(f){var v=null,_=!1,j=f._d&&!isNaN(f._d.getTime());if(j&&(v=b(f),_=S.call(v.parsedDateParts,function(O){return O!=null}),j=v.overflow<0&&!v.empty&&!v.invalidEra&&!v.invalidMonth&&!v.invalidWeekday&&!v.weekdayMismatch&&!v.nullInput&&!v.invalidFormat&&!v.userInvalidated&&(!v.meridiem||v.meridiem&&_),f._strict&&(j=j&&v.charsLeftOver===0&&v.unusedTokens.length===0&&v.bigHour===void 0)),Object.isFrozen==null||!Object.isFrozen(f))f._isValid=j;else return j;return f._isValid}function w(f){var v=g(NaN);return f!=null?m(b(v),f):b(v).userInvalidated=!0,v}var E=r.momentProperties=[],C=!1;function k(f,v){var _,j,O,G=E.length;if(c(v._isAMomentObject)||(f._isAMomentObject=v._isAMomentObject),c(v._i)||(f._i=v._i),c(v._f)||(f._f=v._f),c(v._l)||(f._l=v._l),c(v._strict)||(f._strict=v._strict),c(v._tzm)||(f._tzm=v._tzm),c(v._isUTC)||(f._isUTC=v._isUTC),c(v._offset)||(f._offset=v._offset),c(v._pf)||(f._pf=b(v)),c(v._locale)||(f._locale=v._locale),G>0)for(_=0;_<G;_++)j=E[_],O=v[j],c(O)||(f[j]=O);return f}function I(f){k(this,f),this._d=new Date(f._d!=null?f._d.getTime():NaN),this.isValid()||(this._d=new Date(NaN)),C===!1&&(C=!0,r.updateOffset(this),C=!1)}function A(f){return f instanceof I||f!=null&&f._isAMomentObject!=null}function F(f){r.suppressDeprecationWarnings===!1&&typeof console<"u"&&console.warn&&console.warn("Deprecation warning: "+f)}function P(f,v){var _=!0;return m(function(){if(r.deprecationHandler!=null&&r.deprecationHandler(null,f),_){var j=[],O,G,re,Ie=arguments.length;for(G=0;G<Ie;G++){if(O="",typeof arguments[G]=="object"){O+=`
43
43
  [`+G+"] ";for(re in arguments[0])l(arguments[0],re)&&(O+=re+": "+arguments[0][re]+", ");O=O.slice(0,-2)}else O=arguments[G];j.push(O)}F(f+`
44
44
  Arguments: `+Array.prototype.slice.call(j).join("")+`
45
- `+new Error().stack),_=!1}return v.apply(this,arguments)},v)}var B={};function V(f,v){r.deprecationHandler!=null&&r.deprecationHandler(f,v),B[f]||(F(v),B[f]=!0)}r.suppressDeprecationWarnings=!1,r.deprecationHandler=null;function z(f){return typeof Function<"u"&&f instanceof Function||Object.prototype.toString.call(f)==="[object Function]"}function Y(f){var v,_;for(_ in f)l(f,_)&&(v=f[_],z(v)?this[_]=v:this["_"+_]=v);this._config=f,this._dayOfMonthOrdinalParseLenient=new RegExp((this._dayOfMonthOrdinalParse.source||this._ordinalParse.source)+"|"+/\d{1,2}/.source)}function T(f,v){var _=m({},f),j;for(j in v)l(v,j)&&(a(f[j])&&a(v[j])?(_[j]={},m(_[j],f[j]),m(_[j],v[j])):v[j]!=null?_[j]=v[j]:delete _[j]);for(j in f)l(f,j)&&!l(v,j)&&a(f[j])&&(_[j]=m({},_[j]));return _}function U(f){f!=null&&this.set(f)}var ie;Object.keys?ie=Object.keys:ie=function(f){var v,_=[];for(v in f)l(f,v)&&_.push(v);return _};var oe={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"};function he(f,v,_){var j=this._calendar[f]||this._calendar.sameElse;return z(j)?j.call(v,_):j}function N(f,v,_){var j=""+Math.abs(f),O=v-j.length,G=f>=0;return(G?_?"+":"":"-")+Math.pow(10,Math.max(0,O)).toString().substr(1)+j}var ne=/(\[[^\[]*\])|(\\)?([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,D={},ae={};function K(f,v,_,j){var O=j;typeof j=="string"&&(O=function(){return this[j]()}),f&&(ae[f]=O),v&&(ae[v[0]]=function(){return N(O.apply(this,arguments),v[1],v[2])}),_&&(ae[_]=function(){return this.localeData().ordinal(O.apply(this,arguments),f)})}function ce(f){return f.match(/\[[\s\S]/)?f.replace(/^\[|\]$/g,""):f.replace(/\\/g,"")}function Ce(f){var v=f.match(ne),_,j;for(_=0,j=v.length;_<j;_++)ae[v[_]]?v[_]=ae[v[_]]:v[_]=ce(v[_]);return function(O){var G="",re;for(re=0;re<j;re++)G+=z(v[re])?v[re].call(O,f):v[re];return G}}function ge(f,v){return f.isValid()?(v=Ae(v,f.localeData()),D[v]=D[v]||Ce(v),D[v](f)):f.localeData().invalidDate()}function Ae(f,v){var _=5;function j(O){return v.longDateFormat(O)||O}for(se.lastIndex=0;_>=0&&se.test(f);)f=f.replace(se,j),se.lastIndex=0,_-=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 Ye(f){var v=this._longDateFormat[f],_=this._longDateFormat[f.toUpperCase()];return v||!_?v:(this._longDateFormat[f]=_.match(ne).map(function(j){return j==="MMMM"||j==="MM"||j==="DD"||j==="dddd"?j.slice(1):j}).join(""),this._longDateFormat[f])}var Z="Invalid date";function Je(){return this._invalidDate}var st="%d",Le=/\d{1,2}/;function Gt(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 Wt(f,v,_,j){var O=this._relativeTime[_];return z(O)?O(f,v,_,j):O.replace(/%d/i,f)}function Tt(f,v){var _=this._relativeTime[f>0?"future":"past"];return z(_)?_(v):_.replace(/%s/i,v)}var Qe={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 L(f){return typeof f=="string"?Qe[f]||Qe[f.toLowerCase()]:void 0}function W(f){var v={},_,j;for(j in f)l(f,j)&&(_=L(j),_&&(v[_]=f[j]));return v}var te={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 X(f){var v=[],_;for(_ in f)l(f,_)&&v.push({unit:_,priority:te[_]});return v.sort(function(j,O){return j.priority-O.priority}),v}var ee=/\d/,M=/\d\d/,q=/\d{3}/,le=/\d{4}/,be=/[+-]?\d{6}/,we=/\d\d?/,bt=/\d\d\d\d?/,Nt=/\d\d\d\d\d\d?/,zt=/\d{1,3}/,Xt=/\d{1,4}/,Zt=/[+-]?\d{1,6}/,wt=/\d+/,Jt=/[+-]?\d+/,en=/Z|[+-]\d\d:?\d\d/gi,Ar=/Z|[+-]\d\d(?::?\d\d)?/gi,L1=/[+-]?\d+(\.\d{1,3})?/,sa=/[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,os=/^[1-9]\d?/,mc=/^([1-9]\d|\d)/,Do;Do={};function je(f,v,_){Do[f]=z(v)?v:function(j,O){return j&&_?_:v}}function V1(f,v){return l(Do,f)?Do[f](v._strict,v._locale):new RegExp(B1(f))}function B1(f){return Nr(f.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(v,_,j,O,G){return _||j||O||G}))}function Nr(f){return f.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function Bn(f){return f<0?Math.ceil(f)||0:Math.floor(f)}function et(f){var v=+f,_=0;return v!==0&&isFinite(v)&&(_=Bn(v)),_}var hc={};function gt(f,v){var _,j=v,O;for(typeof f=="string"&&(f=[f]),d(v)&&(j=function(G,re){re[v]=et(G)}),O=f.length,_=0;_<O;_++)hc[f[_]]=j}function aa(f,v){gt(f,function(_,j,O,G){O._w=O._w||{},v(_,O._w,O,G)})}function G1(f,v,_){v!=null&&l(hc,f)&&hc[f](v,_._a,_,f)}function Mo(f){return f%4===0&&f%100!==0||f%400===0}var rn=0,Or=1,fr=2,Ut=3,Kn=4,Dr=5,Ci=6,z1=7,Y1=8;K("Y",0,0,function(){var f=this.year();return f<=9999?N(f,4):"+"+f}),K(0,["YY",2],0,function(){return this.year()%100}),K(0,["YYYY",4],0,"year"),K(0,["YYYYY",5],0,"year"),K(0,["YYYYYY",6,!0],0,"year"),je("Y",Jt),je("YY",we,M),je("YYYY",Xt,le),je("YYYYY",Zt,be),je("YYYYYY",Zt,be),gt(["YYYYY","YYYYYY"],rn),gt("YYYY",function(f,v){v[rn]=f.length===2?r.parseTwoDigitYear(f):et(f)}),gt("YY",function(f,v){v[rn]=r.parseTwoDigitYear(f)}),gt("Y",function(f,v){v[rn]=parseInt(f,10)});function oa(f){return Mo(f)?366:365}r.parseTwoDigitYear=function(f){return et(f)+(et(f)>68?1900:2e3)};var Km=ls("FullYear",!0);function H1(){return Mo(this.year())}function ls(f,v){return function(_){return _!=null?(eh(this,f,_),r.updateOffset(this,v),this):la(this,f)}}function la(f,v){if(!f.isValid())return NaN;var _=f._d,j=f._isUTC;switch(v){case"Milliseconds":return j?_.getUTCMilliseconds():_.getMilliseconds();case"Seconds":return j?_.getUTCSeconds():_.getSeconds();case"Minutes":return j?_.getUTCMinutes():_.getMinutes();case"Hours":return j?_.getUTCHours():_.getHours();case"Date":return j?_.getUTCDate():_.getDate();case"Day":return j?_.getUTCDay():_.getDay();case"Month":return j?_.getUTCMonth():_.getMonth();case"FullYear":return j?_.getUTCFullYear():_.getFullYear();default:return NaN}}function eh(f,v,_){var j,O,G,re,Ie;if(!(!f.isValid()||isNaN(_))){switch(j=f._d,O=f._isUTC,v){case"Milliseconds":return void(O?j.setUTCMilliseconds(_):j.setMilliseconds(_));case"Seconds":return void(O?j.setUTCSeconds(_):j.setSeconds(_));case"Minutes":return void(O?j.setUTCMinutes(_):j.setMinutes(_));case"Hours":return void(O?j.setUTCHours(_):j.setHours(_));case"Date":return void(O?j.setUTCDate(_):j.setDate(_));case"FullYear":break;default:return}G=_,re=f.month(),Ie=f.date(),Ie=Ie===29&&re===1&&!Mo(G)?28:Ie,O?j.setUTCFullYear(G,re,Ie):j.setFullYear(G,re,Ie)}}function $1(f){return f=L(f),z(this[f])?this[f]():this}function W1(f,v){if(typeof f=="object"){f=W(f);var _=X(f),j,O=_.length;for(j=0;j<O;j++)this[_[j].unit](f[_[j].unit])}else if(f=L(f),z(this[f]))return this[f](v);return this}function U1(f,v){return(f%v+v)%v}var Pt;Array.prototype.indexOf?Pt=Array.prototype.indexOf:Pt=function(f){var v;for(v=0;v<this.length;++v)if(this[v]===f)return v;return-1};function gc(f,v){if(isNaN(f)||isNaN(v))return NaN;var _=U1(v,12);return f+=(v-_)/12,_===1?Mo(f)?29:28:31-_%7%2}K("M",["MM",2],"Mo",function(){return this.month()+1}),K("MMM",0,0,function(f){return this.localeData().monthsShort(this,f)}),K("MMMM",0,0,function(f){return this.localeData().months(this,f)}),je("M",we,os),je("MM",we,M),je("MMM",function(f,v){return v.monthsShortRegex(f)}),je("MMMM",function(f,v){return v.monthsRegex(f)}),gt(["M","MM"],function(f,v){v[Or]=et(f)-1}),gt(["MMM","MMMM"],function(f,v,_,j){var O=_._locale.monthsParse(f,j,_._strict);O!=null?v[Or]=O:b(_).invalidMonth=f});var q1="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),th="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),nh=/D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,X1=sa,Z1=sa;function J1(f,v){return f?s(this._months)?this._months[f.month()]:this._months[(this._months.isFormat||nh).test(v)?"format":"standalone"][f.month()]:s(this._months)?this._months:this._months.standalone}function Q1(f,v){return f?s(this._monthsShort)?this._monthsShort[f.month()]:this._monthsShort[nh.test(v)?"format":"standalone"][f.month()]:s(this._monthsShort)?this._monthsShort:this._monthsShort.standalone}function K1(f,v,_){var j,O,G,re=f.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],j=0;j<12;++j)G=g([2e3,j]),this._shortMonthsParse[j]=this.monthsShort(G,"").toLocaleLowerCase(),this._longMonthsParse[j]=this.months(G,"").toLocaleLowerCase();return _?v==="MMM"?(O=Pt.call(this._shortMonthsParse,re),O!==-1?O:null):(O=Pt.call(this._longMonthsParse,re),O!==-1?O:null):v==="MMM"?(O=Pt.call(this._shortMonthsParse,re),O!==-1?O:(O=Pt.call(this._longMonthsParse,re),O!==-1?O:null)):(O=Pt.call(this._longMonthsParse,re),O!==-1?O:(O=Pt.call(this._shortMonthsParse,re),O!==-1?O:null))}function e_(f,v,_){var j,O,G;if(this._monthsParseExact)return K1.call(this,f,v,_);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),j=0;j<12;j++){if(O=g([2e3,j]),_&&!this._longMonthsParse[j]&&(this._longMonthsParse[j]=new RegExp("^"+this.months(O,"").replace(".","")+"$","i"),this._shortMonthsParse[j]=new RegExp("^"+this.monthsShort(O,"").replace(".","")+"$","i")),!_&&!this._monthsParse[j]&&(G="^"+this.months(O,"")+"|^"+this.monthsShort(O,""),this._monthsParse[j]=new RegExp(G.replace(".",""),"i")),_&&v==="MMMM"&&this._longMonthsParse[j].test(f))return j;if(_&&v==="MMM"&&this._shortMonthsParse[j].test(f))return j;if(!_&&this._monthsParse[j].test(f))return j}}function rh(f,v){if(!f.isValid())return f;if(typeof v=="string"){if(/^\d+$/.test(v))v=et(v);else if(v=f.localeData().monthsParse(v),!d(v))return f}var _=v,j=f.date();return j=j<29?j:Math.min(j,gc(f.year(),_)),f._isUTC?f._d.setUTCMonth(_,j):f._d.setMonth(_,j),f}function ih(f){return f!=null?(rh(this,f),r.updateOffset(this,!0),this):la(this,"Month")}function t_(){return gc(this.year(),this.month())}function n_(f){return this._monthsParseExact?(l(this,"_monthsRegex")||sh.call(this),f?this._monthsShortStrictRegex:this._monthsShortRegex):(l(this,"_monthsShortRegex")||(this._monthsShortRegex=X1),this._monthsShortStrictRegex&&f?this._monthsShortStrictRegex:this._monthsShortRegex)}function r_(f){return this._monthsParseExact?(l(this,"_monthsRegex")||sh.call(this),f?this._monthsStrictRegex:this._monthsRegex):(l(this,"_monthsRegex")||(this._monthsRegex=Z1),this._monthsStrictRegex&&f?this._monthsStrictRegex:this._monthsRegex)}function sh(){function f(He,nt){return nt.length-He.length}var v=[],_=[],j=[],O,G,re,Ie;for(O=0;O<12;O++)G=g([2e3,O]),re=Nr(this.monthsShort(G,"")),Ie=Nr(this.months(G,"")),v.push(re),_.push(Ie),j.push(Ie),j.push(re);v.sort(f),_.sort(f),j.sort(f),this._monthsRegex=new RegExp("^("+j.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+_.join("|")+")","i"),this._monthsShortStrictRegex=new RegExp("^("+v.join("|")+")","i")}function i_(f,v,_,j,O,G,re){var Ie;return f<100&&f>=0?(Ie=new Date(f+400,v,_,j,O,G,re),isFinite(Ie.getFullYear())&&Ie.setFullYear(f)):Ie=new Date(f,v,_,j,O,G,re),Ie}function ua(f){var v,_;return f<100&&f>=0?(_=Array.prototype.slice.call(arguments),_[0]=f+400,v=new Date(Date.UTC.apply(null,_)),isFinite(v.getUTCFullYear())&&v.setUTCFullYear(f)):v=new Date(Date.UTC.apply(null,arguments)),v}function Fo(f,v,_){var j=7+v-_,O=(7+ua(f,0,j).getUTCDay()-v)%7;return-O+j-1}function ah(f,v,_,j,O){var G=(7+_-j)%7,re=Fo(f,j,O),Ie=1+7*(v-1)+G+re,He,nt;return Ie<=0?(He=f-1,nt=oa(He)+Ie):Ie>oa(f)?(He=f+1,nt=Ie-oa(f)):(He=f,nt=Ie),{year:He,dayOfYear:nt}}function ca(f,v,_){var j=Fo(f.year(),v,_),O=Math.floor((f.dayOfYear()-j-1)/7)+1,G,re;return O<1?(re=f.year()-1,G=O+Mr(re,v,_)):O>Mr(f.year(),v,_)?(G=O-Mr(f.year(),v,_),re=f.year()+1):(re=f.year(),G=O),{week:G,year:re}}function Mr(f,v,_){var j=Fo(f,v,_),O=Fo(f+1,v,_);return(oa(f)-j+O)/7}K("w",["ww",2],"wo","week"),K("W",["WW",2],"Wo","isoWeek"),je("w",we,os),je("ww",we,M),je("W",we,os),je("WW",we,M),aa(["w","ww","W","WW"],function(f,v,_,j){v[j.substr(0,1)]=et(f)});function s_(f){return ca(f,this._week.dow,this._week.doy).week}var a_={dow:0,doy:6};function o_(){return this._week.dow}function l_(){return this._week.doy}function u_(f){var v=this.localeData().week(this);return f==null?v:this.add((f-v)*7,"d")}function c_(f){var v=ca(this,1,4).week;return f==null?v:this.add((f-v)*7,"d")}K("d",0,"do","day"),K("dd",0,0,function(f){return this.localeData().weekdaysMin(this,f)}),K("ddd",0,0,function(f){return this.localeData().weekdaysShort(this,f)}),K("dddd",0,0,function(f){return this.localeData().weekdays(this,f)}),K("e",0,0,"weekday"),K("E",0,0,"isoWeekday"),je("d",we),je("e",we),je("E",we),je("dd",function(f,v){return v.weekdaysMinRegex(f)}),je("ddd",function(f,v){return v.weekdaysShortRegex(f)}),je("dddd",function(f,v){return v.weekdaysRegex(f)}),aa(["dd","ddd","dddd"],function(f,v,_,j){var O=_._locale.weekdaysParse(f,j,_._strict);O!=null?v.d=O:b(_).invalidWeekday=f}),aa(["d","e","E"],function(f,v,_,j){v[j]=et(f)});function d_(f,v){return typeof f!="string"?f:isNaN(f)?(f=v.weekdaysParse(f),typeof f=="number"?f:null):parseInt(f,10)}function f_(f,v){return typeof f=="string"?v.weekdaysParse(f)%7||7:isNaN(f)?null:f}function vc(f,v){return f.slice(v,7).concat(f.slice(0,v))}var p_="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),oh="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),m_="Su_Mo_Tu_We_Th_Fr_Sa".split("_"),h_=sa,g_=sa,v_=sa;function x_(f,v){var _=s(this._weekdays)?this._weekdays:this._weekdays[f&&f!==!0&&this._weekdays.isFormat.test(v)?"format":"standalone"];return f===!0?vc(_,this._week.dow):f?_[f.day()]:_}function y_(f){return f===!0?vc(this._weekdaysShort,this._week.dow):f?this._weekdaysShort[f.day()]:this._weekdaysShort}function b_(f){return f===!0?vc(this._weekdaysMin,this._week.dow):f?this._weekdaysMin[f.day()]:this._weekdaysMin}function w_(f,v,_){var j,O,G,re=f.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],j=0;j<7;++j)G=g([2e3,1]).day(j),this._minWeekdaysParse[j]=this.weekdaysMin(G,"").toLocaleLowerCase(),this._shortWeekdaysParse[j]=this.weekdaysShort(G,"").toLocaleLowerCase(),this._weekdaysParse[j]=this.weekdays(G,"").toLocaleLowerCase();return _?v==="dddd"?(O=Pt.call(this._weekdaysParse,re),O!==-1?O:null):v==="ddd"?(O=Pt.call(this._shortWeekdaysParse,re),O!==-1?O:null):(O=Pt.call(this._minWeekdaysParse,re),O!==-1?O:null):v==="dddd"?(O=Pt.call(this._weekdaysParse,re),O!==-1||(O=Pt.call(this._shortWeekdaysParse,re),O!==-1)?O:(O=Pt.call(this._minWeekdaysParse,re),O!==-1?O:null)):v==="ddd"?(O=Pt.call(this._shortWeekdaysParse,re),O!==-1||(O=Pt.call(this._weekdaysParse,re),O!==-1)?O:(O=Pt.call(this._minWeekdaysParse,re),O!==-1?O:null)):(O=Pt.call(this._minWeekdaysParse,re),O!==-1||(O=Pt.call(this._weekdaysParse,re),O!==-1)?O:(O=Pt.call(this._shortWeekdaysParse,re),O!==-1?O:null))}function S_(f,v,_){var j,O,G;if(this._weekdaysParseExact)return w_.call(this,f,v,_);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),j=0;j<7;j++){if(O=g([2e3,1]).day(j),_&&!this._fullWeekdaysParse[j]&&(this._fullWeekdaysParse[j]=new RegExp("^"+this.weekdays(O,"").replace(".","\\.?")+"$","i"),this._shortWeekdaysParse[j]=new RegExp("^"+this.weekdaysShort(O,"").replace(".","\\.?")+"$","i"),this._minWeekdaysParse[j]=new RegExp("^"+this.weekdaysMin(O,"").replace(".","\\.?")+"$","i")),this._weekdaysParse[j]||(G="^"+this.weekdays(O,"")+"|^"+this.weekdaysShort(O,"")+"|^"+this.weekdaysMin(O,""),this._weekdaysParse[j]=new RegExp(G.replace(".",""),"i")),_&&v==="dddd"&&this._fullWeekdaysParse[j].test(f))return j;if(_&&v==="ddd"&&this._shortWeekdaysParse[j].test(f))return j;if(_&&v==="dd"&&this._minWeekdaysParse[j].test(f))return j;if(!_&&this._weekdaysParse[j].test(f))return j}}function C_(f){if(!this.isValid())return f!=null?this:NaN;var v=la(this,"Day");return f!=null?(f=d_(f,this.localeData()),this.add(f-v,"d")):v}function __(f){if(!this.isValid())return f!=null?this:NaN;var v=(this.day()+7-this.localeData()._week.dow)%7;return f==null?v:this.add(f-v,"d")}function E_(f){if(!this.isValid())return f!=null?this:NaN;if(f!=null){var v=f_(f,this.localeData());return this.day(this.day()%7?v:v-7)}else return this.day()||7}function I_(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||xc.call(this),f?this._weekdaysStrictRegex:this._weekdaysRegex):(l(this,"_weekdaysRegex")||(this._weekdaysRegex=h_),this._weekdaysStrictRegex&&f?this._weekdaysStrictRegex:this._weekdaysRegex)}function j_(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||xc.call(this),f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(l(this,"_weekdaysShortRegex")||(this._weekdaysShortRegex=g_),this._weekdaysShortStrictRegex&&f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function R_(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||xc.call(this),f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(l(this,"_weekdaysMinRegex")||(this._weekdaysMinRegex=v_),this._weekdaysMinStrictRegex&&f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function xc(){function f(pn,Vr){return Vr.length-pn.length}var v=[],_=[],j=[],O=[],G,re,Ie,He,nt;for(G=0;G<7;G++)re=g([2e3,1]).day(G),Ie=Nr(this.weekdaysMin(re,"")),He=Nr(this.weekdaysShort(re,"")),nt=Nr(this.weekdays(re,"")),v.push(Ie),_.push(He),j.push(nt),O.push(Ie),O.push(He),O.push(nt);v.sort(f),_.sort(f),j.sort(f),O.sort(f),this._weekdaysRegex=new RegExp("^("+O.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+j.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+_.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+v.join("|")+")","i")}function yc(){return this.hours()%12||12}function k_(){return this.hours()||24}K("H",["HH",2],0,"hour"),K("h",["hh",2],0,yc),K("k",["kk",2],0,k_),K("hmm",0,0,function(){return""+yc.apply(this)+N(this.minutes(),2)}),K("hmmss",0,0,function(){return""+yc.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),K("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),K("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)});function lh(f,v){K(f,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),v)})}lh("a",!0),lh("A",!1);function uh(f,v){return v._meridiemParse}je("a",uh),je("A",uh),je("H",we,mc),je("h",we,os),je("k",we,os),je("HH",we,M),je("hh",we,M),je("kk",we,M),je("hmm",bt),je("hmmss",Nt),je("Hmm",bt),je("Hmmss",Nt),gt(["H","HH"],Ut),gt(["k","kk"],function(f,v,_){var j=et(f);v[Ut]=j===24?0:j}),gt(["a","A"],function(f,v,_){_._isPm=_._locale.isPM(f),_._meridiem=f}),gt(["h","hh"],function(f,v,_){v[Ut]=et(f),b(_).bigHour=!0}),gt("hmm",function(f,v,_){var j=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j)),b(_).bigHour=!0}),gt("hmmss",function(f,v,_){var j=f.length-4,O=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j,2)),v[Dr]=et(f.substr(O)),b(_).bigHour=!0}),gt("Hmm",function(f,v,_){var j=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j))}),gt("Hmmss",function(f,v,_){var j=f.length-4,O=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j,2)),v[Dr]=et(f.substr(O))});function A_(f){return(f+"").toLowerCase().charAt(0)==="p"}var N_=/[ap]\.?m?\.?/i,O_=ls("Hours",!0);function D_(f,v,_){return f>11?_?"pm":"PM":_?"am":"AM"}var ch={calendar:oe,longDateFormat:ke,invalidDate:Z,ordinal:st,dayOfMonthOrdinalParse:Le,relativeTime:Rt,months:q1,monthsShort:th,week:a_,weekdays:p_,weekdaysMin:m_,weekdaysShort:oh,meridiemParse:N_},kt={},da={},fa;function M_(f,v){var _,j=Math.min(f.length,v.length);for(_=0;_<j;_+=1)if(f[_]!==v[_])return _;return j}function dh(f){return f&&f.toLowerCase().replace("_","-")}function F_(f){for(var v=0,_,j,O,G;v<f.length;){for(G=dh(f[v]).split("-"),_=G.length,j=dh(f[v+1]),j=j?j.split("-"):null;_>0;){if(O=To(G.slice(0,_).join("-")),O)return O;if(j&&j.length>=_&&M_(G,j)>=_-1)break;_--}v++}return fa}function T_(f){return!!(f&&f.match("^[^/\\\\]*$"))}function To(f){var v=null,_;if(kt[f]===void 0&&e&&e.exports&&T_(f))try{v=fa._abbr,_=JW,_("./locale/"+f),si(v)}catch{kt[f]=null}return kt[f]}function si(f,v){var _;return f&&(c(v)?_=Fr(f):_=bc(f,v),_?fa=_:typeof console<"u"&&console.warn&&console.warn("Locale "+f+" not found. Did you forget to load it?")),fa._abbr}function bc(f,v){if(v!==null){var _,j=ch;if(v.abbr=f,kt[f]!=null)V("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."),j=kt[f]._config;else if(v.parentLocale!=null)if(kt[v.parentLocale]!=null)j=kt[v.parentLocale]._config;else if(_=To(v.parentLocale),_!=null)j=_._config;else return da[v.parentLocale]||(da[v.parentLocale]=[]),da[v.parentLocale].push({name:f,config:v}),null;return kt[f]=new U(T(j,v)),da[f]&&da[f].forEach(function(O){bc(O.name,O.config)}),si(f),kt[f]}else return delete kt[f],null}function P_(f,v){if(v!=null){var _,j,O=ch;kt[f]!=null&&kt[f].parentLocale!=null?kt[f].set(T(kt[f]._config,v)):(j=To(f),j!=null&&(O=j._config),v=T(O,v),j==null&&(v.abbr=f),_=new U(v),_.parentLocale=kt[f],kt[f]=_),si(f)}else kt[f]!=null&&(kt[f].parentLocale!=null?(kt[f]=kt[f].parentLocale,f===si()&&si(f)):kt[f]!=null&&delete kt[f]);return kt[f]}function Fr(f){var v;if(f&&f._locale&&f._locale._abbr&&(f=f._locale._abbr),!f)return fa;if(!s(f)){if(v=To(f),v)return v;f=[f]}return F_(f)}function L_(){return ie(kt)}function wc(f){var v,_=f._a;return _&&b(f).overflow===-2&&(v=_[Or]<0||_[Or]>11?Or:_[fr]<1||_[fr]>gc(_[rn],_[Or])?fr:_[Ut]<0||_[Ut]>24||_[Ut]===24&&(_[Kn]!==0||_[Dr]!==0||_[Ci]!==0)?Ut:_[Kn]<0||_[Kn]>59?Kn:_[Dr]<0||_[Dr]>59?Dr:_[Ci]<0||_[Ci]>999?Ci:-1,b(f)._overflowDayOfYear&&(v<rn||v>fr)&&(v=fr),b(f)._overflowWeeks&&v===-1&&(v=z1),b(f)._overflowWeekday&&v===-1&&(v=Y1),b(f).overflow=v),f}var V_=/^\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)?)?$/,B_=/^\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)?)?$/,G_=/Z|[+-]\d\d(?::?\d\d)?/,Po=[["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]],Sc=[["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/]],z_=/^\/?Date\((-?\d+)/i,Y_=/^(?:(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}))$/,H_={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function fh(f){var v,_,j=f._i,O=V_.exec(j)||B_.exec(j),G,re,Ie,He,nt=Po.length,pn=Sc.length;if(O){for(b(f).iso=!0,v=0,_=nt;v<_;v++)if(Po[v][1].exec(O[1])){re=Po[v][0],G=Po[v][2]!==!1;break}if(re==null){f._isValid=!1;return}if(O[3]){for(v=0,_=pn;v<_;v++)if(Sc[v][1].exec(O[3])){Ie=(O[2]||" ")+Sc[v][0];break}if(Ie==null){f._isValid=!1;return}}if(!G&&Ie!=null){f._isValid=!1;return}if(O[4])if(G_.exec(O[4]))He="Z";else{f._isValid=!1;return}f._f=re+(Ie||"")+(He||""),_c(f)}else f._isValid=!1}function $_(f,v,_,j,O,G){var re=[W_(f),th.indexOf(v),parseInt(_,10),parseInt(j,10),parseInt(O,10)];return G&&re.push(parseInt(G,10)),re}function W_(f){var v=parseInt(f,10);return v<=49?2e3+v:v<=999?1900+v:v}function U_(f){return f.replace(/\([^()]*\)|[\n\t]/g," ").replace(/(\s\s+)/g," ").replace(/^\s\s*/,"").replace(/\s\s*$/,"")}function q_(f,v,_){if(f){var j=oh.indexOf(f),O=new Date(v[0],v[1],v[2]).getDay();if(j!==O)return b(_).weekdayMismatch=!0,_._isValid=!1,!1}return!0}function X_(f,v,_){if(f)return H_[f];if(v)return 0;var j=parseInt(_,10),O=j%100,G=(j-O)/100;return G*60+O}function ph(f){var v=Y_.exec(U_(f._i)),_;if(v){if(_=$_(v[4],v[3],v[2],v[5],v[6],v[7]),!q_(v[1],_,f))return;f._a=_,f._tzm=X_(v[8],v[9],v[10]),f._d=ua.apply(null,f._a),f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),b(f).rfc2822=!0}else f._isValid=!1}function Z_(f){var v=z_.exec(f._i);if(v!==null){f._d=new Date(+v[1]);return}if(fh(f),f._isValid===!1)delete f._isValid;else return;if(ph(f),f._isValid===!1)delete f._isValid;else return;f._strict?f._isValid=!1:r.createFromInputFallback(f)}r.createFromInputFallback=P("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 us(f,v,_){return f??v??_}function J_(f){var v=new Date(r.now());return f._useUTC?[v.getUTCFullYear(),v.getUTCMonth(),v.getUTCDate()]:[v.getFullYear(),v.getMonth(),v.getDate()]}function Cc(f){var v,_,j=[],O,G,re;if(!f._d){for(O=J_(f),f._w&&f._a[fr]==null&&f._a[Or]==null&&Q_(f),f._dayOfYear!=null&&(re=us(f._a[rn],O[rn]),(f._dayOfYear>oa(re)||f._dayOfYear===0)&&(b(f)._overflowDayOfYear=!0),_=ua(re,0,f._dayOfYear),f._a[Or]=_.getUTCMonth(),f._a[fr]=_.getUTCDate()),v=0;v<3&&f._a[v]==null;++v)f._a[v]=j[v]=O[v];for(;v<7;v++)f._a[v]=j[v]=f._a[v]==null?v===2?1:0:f._a[v];f._a[Ut]===24&&f._a[Kn]===0&&f._a[Dr]===0&&f._a[Ci]===0&&(f._nextDay=!0,f._a[Ut]=0),f._d=(f._useUTC?ua:i_).apply(null,j),G=f._useUTC?f._d.getUTCDay():f._d.getDay(),f._tzm!=null&&f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),f._nextDay&&(f._a[Ut]=24),f._w&&typeof f._w.d<"u"&&f._w.d!==G&&(b(f).weekdayMismatch=!0)}}function Q_(f){var v,_,j,O,G,re,Ie,He,nt;v=f._w,v.GG!=null||v.W!=null||v.E!=null?(G=1,re=4,_=us(v.GG,f._a[rn],ca(Et(),1,4).year),j=us(v.W,1),O=us(v.E,1),(O<1||O>7)&&(He=!0)):(G=f._locale._week.dow,re=f._locale._week.doy,nt=ca(Et(),G,re),_=us(v.gg,f._a[rn],nt.year),j=us(v.w,nt.week),v.d!=null?(O=v.d,(O<0||O>6)&&(He=!0)):v.e!=null?(O=v.e+G,(v.e<0||v.e>6)&&(He=!0)):O=G),j<1||j>Mr(_,G,re)?b(f)._overflowWeeks=!0:He!=null?b(f)._overflowWeekday=!0:(Ie=ah(_,j,O,G,re),f._a[rn]=Ie.year,f._dayOfYear=Ie.dayOfYear)}r.ISO_8601=function(){},r.RFC_2822=function(){};function _c(f){if(f._f===r.ISO_8601){fh(f);return}if(f._f===r.RFC_2822){ph(f);return}f._a=[],b(f).empty=!0;var v=""+f._i,_,j,O,G,re,Ie=v.length,He=0,nt,pn;for(O=Ae(f._f,f._locale).match(ne)||[],pn=O.length,_=0;_<pn;_++)G=O[_],j=(v.match(V1(G,f))||[])[0],j&&(re=v.substr(0,v.indexOf(j)),re.length>0&&b(f).unusedInput.push(re),v=v.slice(v.indexOf(j)+j.length),He+=j.length),ae[G]?(j?b(f).empty=!1:b(f).unusedTokens.push(G),G1(G,j,f)):f._strict&&!j&&b(f).unusedTokens.push(G);b(f).charsLeftOver=Ie-He,v.length>0&&b(f).unusedInput.push(v),f._a[Ut]<=12&&b(f).bigHour===!0&&f._a[Ut]>0&&(b(f).bigHour=void 0),b(f).parsedDateParts=f._a.slice(0),b(f).meridiem=f._meridiem,f._a[Ut]=K_(f._locale,f._a[Ut],f._meridiem),nt=b(f).era,nt!==null&&(f._a[rn]=f._locale.erasConvertYear(nt,f._a[rn])),Cc(f),wc(f)}function K_(f,v,_){var j;return _==null?v:f.meridiemHour!=null?f.meridiemHour(v,_):(f.isPM!=null&&(j=f.isPM(_),j&&v<12&&(v+=12),!j&&v===12&&(v=0)),v)}function eE(f){var v,_,j,O,G,re,Ie=!1,He=f._f.length;if(He===0){b(f).invalidFormat=!0,f._d=new Date(NaN);return}for(O=0;O<He;O++)G=0,re=!1,v=k({},f),f._useUTC!=null&&(v._useUTC=f._useUTC),v._f=f._f[O],_c(v),R(v)&&(re=!0),G+=b(v).charsLeftOver,G+=b(v).unusedTokens.length*10,b(v).score=G,Ie?G<j&&(j=G,_=v):(j==null||G<j||re)&&(j=G,_=v,re&&(Ie=!0));m(f,_||v)}function tE(f){if(!f._d){var v=W(f._i),_=v.day===void 0?v.date:v.day;f._a=h([v.year,v.month,_,v.hour,v.minute,v.second,v.millisecond],function(j){return j&&parseInt(j,10)}),Cc(f)}}function nE(f){var v=new I(wc(mh(f)));return v._nextDay&&(v.add(1,"d"),v._nextDay=void 0),v}function mh(f){var v=f._i,_=f._f;return f._locale=f._locale||Fr(f._l),v===null||_===void 0&&v===""?w({nullInput:!0}):(typeof v=="string"&&(f._i=v=f._locale.preparse(v)),A(v)?new I(wc(v)):(p(v)?f._d=v:s(_)?eE(f):_?_c(f):rE(f),R(f)||(f._d=null),f))}function rE(f){var v=f._i;c(v)?f._d=new Date(r.now()):p(v)?f._d=new Date(v.valueOf()):typeof v=="string"?Z_(f):s(v)?(f._a=h(v.slice(0),function(_){return parseInt(_,10)}),Cc(f)):a(v)?tE(f):d(v)?f._d=new Date(v):r.createFromInputFallback(f)}function hh(f,v,_,j,O){var G={};return(v===!0||v===!1)&&(j=v,v=void 0),(_===!0||_===!1)&&(j=_,_=void 0),(a(f)&&u(f)||s(f)&&f.length===0)&&(f=void 0),G._isAMomentObject=!0,G._useUTC=G._isUTC=O,G._l=_,G._i=f,G._f=v,G._strict=j,nE(G)}function Et(f,v,_,j){return hh(f,v,_,j,!1)}var iE=P("moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=Et.apply(null,arguments);return this.isValid()&&f.isValid()?f<this?this:f:w()}),sE=P("moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=Et.apply(null,arguments);return this.isValid()&&f.isValid()?f>this?this:f:w()});function gh(f,v){var _,j;if(v.length===1&&s(v[0])&&(v=v[0]),!v.length)return Et();for(_=v[0],j=1;j<v.length;++j)(!v[j].isValid()||v[j][f](_))&&(_=v[j]);return _}function aE(){var f=[].slice.call(arguments,0);return gh("isBefore",f)}function oE(){var f=[].slice.call(arguments,0);return gh("isAfter",f)}var lE=function(){return Date.now?Date.now():+new Date},pa=["year","quarter","month","week","day","hour","minute","second","millisecond"];function uE(f){var v,_=!1,j,O=pa.length;for(v in f)if(l(f,v)&&!(Pt.call(pa,v)!==-1&&(f[v]==null||!isNaN(f[v]))))return!1;for(j=0;j<O;++j)if(f[pa[j]]){if(_)return!1;parseFloat(f[pa[j]])!==et(f[pa[j]])&&(_=!0)}return!0}function cE(){return this._isValid}function dE(){return er(NaN)}function Lo(f){var v=W(f),_=v.year||0,j=v.quarter||0,O=v.month||0,G=v.week||v.isoWeek||0,re=v.day||0,Ie=v.hour||0,He=v.minute||0,nt=v.second||0,pn=v.millisecond||0;this._isValid=uE(v),this._milliseconds=+pn+nt*1e3+He*6e4+Ie*1e3*60*60,this._days=+re+G*7,this._months=+O+j*3+_*12,this._data={},this._locale=Fr(),this._bubble()}function Vo(f){return f instanceof Lo}function Ec(f){return f<0?Math.round(-1*f)*-1:Math.round(f)}function fE(f,v,_){var j=Math.min(f.length,v.length),O=Math.abs(f.length-v.length),G=0,re;for(re=0;re<j;re++)et(f[re])!==et(v[re])&&G++;return G+O}function vh(f,v){K(f,0,0,function(){var _=this.utcOffset(),j="+";return _<0&&(_=-_,j="-"),j+N(~~(_/60),2)+v+N(~~_%60,2)})}vh("Z",":"),vh("ZZ",""),je("Z",Ar),je("ZZ",Ar),gt(["Z","ZZ"],function(f,v,_){_._useUTC=!0,_._tzm=Ic(Ar,f)});var pE=/([\+\-]|\d\d)/gi;function Ic(f,v){var _=(v||"").match(f),j,O,G;return _===null?null:(j=_[_.length-1]||[],O=(j+"").match(pE)||["-",0,0],G=+(O[1]*60)+et(O[2]),G===0?0:O[0]==="+"?G:-G)}function jc(f,v){var _,j;return v._isUTC?(_=v.clone(),j=(A(f)||p(f)?f.valueOf():Et(f).valueOf())-_.valueOf(),_._d.setTime(_._d.valueOf()+j),r.updateOffset(_,!1),_):Et(f).local()}function Rc(f){return-Math.round(f._d.getTimezoneOffset())}r.updateOffset=function(){};function mE(f,v,_){var j=this._offset||0,O;if(!this.isValid())return f!=null?this:NaN;if(f!=null){if(typeof f=="string"){if(f=Ic(Ar,f),f===null)return this}else Math.abs(f)<16&&!_&&(f=f*60);return!this._isUTC&&v&&(O=Rc(this)),this._offset=f,this._isUTC=!0,O!=null&&this.add(O,"m"),j!==f&&(!v||this._changeInProgress?wh(this,er(f-j,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,r.updateOffset(this,!0),this._changeInProgress=null)),this}else return this._isUTC?j:Rc(this)}function hE(f,v){return f!=null?(typeof f!="string"&&(f=-f),this.utcOffset(f,v),this):-this.utcOffset()}function gE(f){return this.utcOffset(0,f)}function vE(f){return this._isUTC&&(this.utcOffset(0,f),this._isUTC=!1,f&&this.subtract(Rc(this),"m")),this}function xE(){if(this._tzm!=null)this.utcOffset(this._tzm,!1,!0);else if(typeof this._i=="string"){var f=Ic(en,this._i);f!=null?this.utcOffset(f):this.utcOffset(0,!0)}return this}function yE(f){return this.isValid()?(f=f?Et(f).utcOffset():0,(this.utcOffset()-f)%60===0):!1}function bE(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function wE(){if(!c(this._isDSTShifted))return this._isDSTShifted;var f={},v;return k(f,this),f=mh(f),f._a?(v=f._isUTC?g(f._a):Et(f._a),this._isDSTShifted=this.isValid()&&fE(f._a,v.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function SE(){return this.isValid()?!this._isUTC:!1}function CE(){return this.isValid()?this._isUTC:!1}function xh(){return this.isValid()?this._isUTC&&this._offset===0:!1}var _E=/^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,EE=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function er(f,v){var _=f,j=null,O,G,re;return Vo(f)?_={ms:f._milliseconds,d:f._days,M:f._months}:d(f)||!isNaN(+f)?(_={},v?_[v]=+f:_.milliseconds=+f):(j=_E.exec(f))?(O=j[1]==="-"?-1:1,_={y:0,d:et(j[fr])*O,h:et(j[Ut])*O,m:et(j[Kn])*O,s:et(j[Dr])*O,ms:et(Ec(j[Ci]*1e3))*O}):(j=EE.exec(f))?(O=j[1]==="-"?-1:1,_={y:_i(j[2],O),M:_i(j[3],O),w:_i(j[4],O),d:_i(j[5],O),h:_i(j[6],O),m:_i(j[7],O),s:_i(j[8],O)}):_==null?_={}:typeof _=="object"&&("from"in _||"to"in _)&&(re=IE(Et(_.from),Et(_.to)),_={},_.ms=re.milliseconds,_.M=re.months),G=new Lo(_),Vo(f)&&l(f,"_locale")&&(G._locale=f._locale),Vo(f)&&l(f,"_isValid")&&(G._isValid=f._isValid),G}er.fn=Lo.prototype,er.invalid=dE;function _i(f,v){var _=f&&parseFloat(f.replace(",","."));return(isNaN(_)?0:_)*v}function yh(f,v){var _={};return _.months=v.month()-f.month()+(v.year()-f.year())*12,f.clone().add(_.months,"M").isAfter(v)&&--_.months,_.milliseconds=+v-+f.clone().add(_.months,"M"),_}function IE(f,v){var _;return f.isValid()&&v.isValid()?(v=jc(v,f),f.isBefore(v)?_=yh(f,v):(_=yh(v,f),_.milliseconds=-_.milliseconds,_.months=-_.months),_):{milliseconds:0,months:0}}function bh(f,v){return function(_,j){var O,G;return j!==null&&!isNaN(+j)&&(V(v,"moment()."+v+"(period, number) is deprecated. Please use moment()."+v+"(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info."),G=_,_=j,j=G),O=er(_,j),wh(this,O,f),this}}function wh(f,v,_,j){var O=v._milliseconds,G=Ec(v._days),re=Ec(v._months);f.isValid()&&(j=j??!0,re&&rh(f,la(f,"Month")+re*_),G&&eh(f,"Date",la(f,"Date")+G*_),O&&f._d.setTime(f._d.valueOf()+O*_),j&&r.updateOffset(f,G||re))}var jE=bh(1,"add"),RE=bh(-1,"subtract");function Sh(f){return typeof f=="string"||f instanceof String}function kE(f){return A(f)||p(f)||Sh(f)||d(f)||NE(f)||AE(f)||f===null||f===void 0}function AE(f){var v=a(f)&&!u(f),_=!1,j=["years","year","y","months","month","M","days","day","d","dates","date","D","hours","hour","h","minutes","minute","m","seconds","second","s","milliseconds","millisecond","ms"],O,G,re=j.length;for(O=0;O<re;O+=1)G=j[O],_=_||l(f,G);return v&&_}function NE(f){var v=s(f),_=!1;return v&&(_=f.filter(function(j){return!d(j)&&Sh(f)}).length===0),v&&_}function OE(f){var v=a(f)&&!u(f),_=!1,j=["sameDay","nextDay","lastDay","nextWeek","lastWeek","sameElse"],O,G;for(O=0;O<j.length;O+=1)G=j[O],_=_||l(f,G);return v&&_}function DE(f,v){var _=f.diff(v,"days",!0);return _<-6?"sameElse":_<-1?"lastWeek":_<0?"lastDay":_<1?"sameDay":_<2?"nextDay":_<7?"nextWeek":"sameElse"}function ME(f,v){arguments.length===1&&(arguments[0]?kE(arguments[0])?(f=arguments[0],v=void 0):OE(arguments[0])&&(v=arguments[0],f=void 0):(f=void 0,v=void 0));var _=f||Et(),j=jc(_,this).startOf("day"),O=r.calendarFormat(this,j)||"sameElse",G=v&&(z(v[O])?v[O].call(this,_):v[O]);return this.format(G||this.localeData().calendar(O,this,Et(_)))}function FE(){return new I(this)}function TE(f,v){var _=A(f)?f:Et(f);return this.isValid()&&_.isValid()?(v=L(v)||"millisecond",v==="millisecond"?this.valueOf()>_.valueOf():_.valueOf()<this.clone().startOf(v).valueOf()):!1}function PE(f,v){var _=A(f)?f:Et(f);return this.isValid()&&_.isValid()?(v=L(v)||"millisecond",v==="millisecond"?this.valueOf()<_.valueOf():this.clone().endOf(v).valueOf()<_.valueOf()):!1}function LE(f,v,_,j){var O=A(f)?f:Et(f),G=A(v)?v:Et(v);return this.isValid()&&O.isValid()&&G.isValid()?(j=j||"()",(j[0]==="("?this.isAfter(O,_):!this.isBefore(O,_))&&(j[1]===")"?this.isBefore(G,_):!this.isAfter(G,_))):!1}function VE(f,v){var _=A(f)?f:Et(f),j;return this.isValid()&&_.isValid()?(v=L(v)||"millisecond",v==="millisecond"?this.valueOf()===_.valueOf():(j=_.valueOf(),this.clone().startOf(v).valueOf()<=j&&j<=this.clone().endOf(v).valueOf())):!1}function BE(f,v){return this.isSame(f,v)||this.isAfter(f,v)}function GE(f,v){return this.isSame(f,v)||this.isBefore(f,v)}function zE(f,v,_){var j,O,G;if(!this.isValid())return NaN;if(j=jc(f,this),!j.isValid())return NaN;switch(O=(j.utcOffset()-this.utcOffset())*6e4,v=L(v),v){case"year":G=Bo(this,j)/12;break;case"month":G=Bo(this,j);break;case"quarter":G=Bo(this,j)/3;break;case"second":G=(this-j)/1e3;break;case"minute":G=(this-j)/6e4;break;case"hour":G=(this-j)/36e5;break;case"day":G=(this-j-O)/864e5;break;case"week":G=(this-j-O)/6048e5;break;default:G=this-j}return _?G:Bn(G)}function Bo(f,v){if(f.date()<v.date())return-Bo(v,f);var _=(v.year()-f.year())*12+(v.month()-f.month()),j=f.clone().add(_,"months"),O,G;return v-j<0?(O=f.clone().add(_-1,"months"),G=(v-j)/(j-O)):(O=f.clone().add(_+1,"months"),G=(v-j)/(O-j)),-(_+G)||0}r.defaultFormat="YYYY-MM-DDTHH:mm:ssZ",r.defaultFormatUtc="YYYY-MM-DDTHH:mm:ss[Z]";function YE(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function HE(f){if(!this.isValid())return null;var v=f!==!0,_=v?this.clone().utc():this;return _.year()<0||_.year()>9999?ge(_,v?"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYYYY-MM-DD[T]HH:mm:ss.SSSZ"):z(Date.prototype.toISOString)?v?this.toDate().toISOString():new Date(this.valueOf()+this.utcOffset()*60*1e3).toISOString().replace("Z",ge(_,"Z")):ge(_,v?"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYY-MM-DD[T]HH:mm:ss.SSSZ")}function $E(){if(!this.isValid())return"moment.invalid(/* "+this._i+" */)";var f="moment",v="",_,j,O,G;return this.isLocal()||(f=this.utcOffset()===0?"moment.utc":"moment.parseZone",v="Z"),_="["+f+'("]',j=0<=this.year()&&this.year()<=9999?"YYYY":"YYYYYY",O="-MM-DD[T]HH:mm:ss.SSS",G=v+'[")]',this.format(_+j+O+G)}function WE(f){f||(f=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var v=ge(this,f);return this.localeData().postformat(v)}function UE(f,v){return this.isValid()&&(A(f)&&f.isValid()||Et(f).isValid())?er({to:this,from:f}).locale(this.locale()).humanize(!v):this.localeData().invalidDate()}function qE(f){return this.from(Et(),f)}function XE(f,v){return this.isValid()&&(A(f)&&f.isValid()||Et(f).isValid())?er({from:this,to:f}).locale(this.locale()).humanize(!v):this.localeData().invalidDate()}function ZE(f){return this.to(Et(),f)}function Ch(f){var v;return f===void 0?this._locale._abbr:(v=Fr(f),v!=null&&(this._locale=v),this)}var _h=P("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 Eh(){return this._locale}var Go=1e3,cs=60*Go,zo=60*cs,Ih=(365*400+97)*24*zo;function ds(f,v){return(f%v+v)%v}function jh(f,v,_){return f<100&&f>=0?new Date(f+400,v,_)-Ih:new Date(f,v,_).valueOf()}function Rh(f,v,_){return f<100&&f>=0?Date.UTC(f+400,v,_)-Ih:Date.UTC(f,v,_)}function JE(f){var v,_;if(f=L(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(_=this._isUTC?Rh:jh,f){case"year":v=_(this.year(),0,1);break;case"quarter":v=_(this.year(),this.month()-this.month()%3,1);break;case"month":v=_(this.year(),this.month(),1);break;case"week":v=_(this.year(),this.month(),this.date()-this.weekday());break;case"isoWeek":v=_(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case"day":case"date":v=_(this.year(),this.month(),this.date());break;case"hour":v=this._d.valueOf(),v-=ds(v+(this._isUTC?0:this.utcOffset()*cs),zo);break;case"minute":v=this._d.valueOf(),v-=ds(v,cs);break;case"second":v=this._d.valueOf(),v-=ds(v,Go);break}return this._d.setTime(v),r.updateOffset(this,!0),this}function QE(f){var v,_;if(f=L(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(_=this._isUTC?Rh:jh,f){case"year":v=_(this.year()+1,0,1)-1;break;case"quarter":v=_(this.year(),this.month()-this.month()%3+3,1)-1;break;case"month":v=_(this.year(),this.month()+1,1)-1;break;case"week":v=_(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case"isoWeek":v=_(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case"day":case"date":v=_(this.year(),this.month(),this.date()+1)-1;break;case"hour":v=this._d.valueOf(),v+=zo-ds(v+(this._isUTC?0:this.utcOffset()*cs),zo)-1;break;case"minute":v=this._d.valueOf(),v+=cs-ds(v,cs)-1;break;case"second":v=this._d.valueOf(),v+=Go-ds(v,Go)-1;break}return this._d.setTime(v),r.updateOffset(this,!0),this}function KE(){return this._d.valueOf()-(this._offset||0)*6e4}function eI(){return Math.floor(this.valueOf()/1e3)}function tI(){return new Date(this.valueOf())}function nI(){var f=this;return[f.year(),f.month(),f.date(),f.hour(),f.minute(),f.second(),f.millisecond()]}function rI(){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 iI(){return this.isValid()?this.toISOString():null}function sI(){return R(this)}function aI(){return m({},b(this))}function oI(){return b(this).overflow}function lI(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}K("N",0,0,"eraAbbr"),K("NN",0,0,"eraAbbr"),K("NNN",0,0,"eraAbbr"),K("NNNN",0,0,"eraName"),K("NNNNN",0,0,"eraNarrow"),K("y",["y",1],"yo","eraYear"),K("y",["yy",2],0,"eraYear"),K("y",["yyy",3],0,"eraYear"),K("y",["yyyy",4],0,"eraYear"),je("N",kc),je("NN",kc),je("NNN",kc),je("NNNN",yI),je("NNNNN",bI),gt(["N","NN","NNN","NNNN","NNNNN"],function(f,v,_,j){var O=_._locale.erasParse(f,j,_._strict);O?b(_).era=O:b(_).invalidEra=f}),je("y",wt),je("yy",wt),je("yyy",wt),je("yyyy",wt),je("yo",wI),gt(["y","yy","yyy","yyyy"],rn),gt(["yo"],function(f,v,_,j){var O;_._locale._eraYearOrdinalRegex&&(O=f.match(_._locale._eraYearOrdinalRegex)),_._locale.eraYearOrdinalParse?v[rn]=_._locale.eraYearOrdinalParse(f,O):v[rn]=parseInt(f,10)});function uI(f,v){var _,j,O,G=this._eras||Fr("en")._eras;for(_=0,j=G.length;_<j;++_)switch(typeof G[_].since==="string"&&(O=r(G[_].since).startOf("day"),G[_].since=O.valueOf()),typeof G[_].until){case"undefined":G[_].until=1/0;break;case"string":O=r(G[_].until).startOf("day").valueOf(),G[_].until=O.valueOf();break}return G}function cI(f,v,_){var j,O,G=this.eras(),re,Ie,He;for(f=f.toUpperCase(),j=0,O=G.length;j<O;++j)if(re=G[j].name.toUpperCase(),Ie=G[j].abbr.toUpperCase(),He=G[j].narrow.toUpperCase(),_)switch(v){case"N":case"NN":case"NNN":if(Ie===f)return G[j];break;case"NNNN":if(re===f)return G[j];break;case"NNNNN":if(He===f)return G[j];break}else if([re,Ie,He].indexOf(f)>=0)return G[j]}function dI(f,v){var _=f.since<=f.until?1:-1;return v===void 0?r(f.since).year():r(f.since).year()+(v-f.offset)*_}function fI(){var f,v,_,j=this.localeData().eras();for(f=0,v=j.length;f<v;++f)if(_=this.clone().startOf("day").valueOf(),j[f].since<=_&&_<=j[f].until||j[f].until<=_&&_<=j[f].since)return j[f].name;return""}function pI(){var f,v,_,j=this.localeData().eras();for(f=0,v=j.length;f<v;++f)if(_=this.clone().startOf("day").valueOf(),j[f].since<=_&&_<=j[f].until||j[f].until<=_&&_<=j[f].since)return j[f].narrow;return""}function mI(){var f,v,_,j=this.localeData().eras();for(f=0,v=j.length;f<v;++f)if(_=this.clone().startOf("day").valueOf(),j[f].since<=_&&_<=j[f].until||j[f].until<=_&&_<=j[f].since)return j[f].abbr;return""}function hI(){var f,v,_,j,O=this.localeData().eras();for(f=0,v=O.length;f<v;++f)if(_=O[f].since<=O[f].until?1:-1,j=this.clone().startOf("day").valueOf(),O[f].since<=j&&j<=O[f].until||O[f].until<=j&&j<=O[f].since)return(this.year()-r(O[f].since).year())*_+O[f].offset;return this.year()}function gI(f){return l(this,"_erasNameRegex")||Ac.call(this),f?this._erasNameRegex:this._erasRegex}function vI(f){return l(this,"_erasAbbrRegex")||Ac.call(this),f?this._erasAbbrRegex:this._erasRegex}function xI(f){return l(this,"_erasNarrowRegex")||Ac.call(this),f?this._erasNarrowRegex:this._erasRegex}function kc(f,v){return v.erasAbbrRegex(f)}function yI(f,v){return v.erasNameRegex(f)}function bI(f,v){return v.erasNarrowRegex(f)}function wI(f,v){return v._eraYearOrdinalRegex||wt}function Ac(){var f=[],v=[],_=[],j=[],O,G,re,Ie,He,nt=this.eras();for(O=0,G=nt.length;O<G;++O)re=Nr(nt[O].name),Ie=Nr(nt[O].abbr),He=Nr(nt[O].narrow),v.push(re),f.push(Ie),_.push(He),j.push(re),j.push(Ie),j.push(He);this._erasRegex=new RegExp("^("+j.join("|")+")","i"),this._erasNameRegex=new RegExp("^("+v.join("|")+")","i"),this._erasAbbrRegex=new RegExp("^("+f.join("|")+")","i"),this._erasNarrowRegex=new RegExp("^("+_.join("|")+")","i")}K(0,["gg",2],0,function(){return this.weekYear()%100}),K(0,["GG",2],0,function(){return this.isoWeekYear()%100});function Yo(f,v){K(0,[f,f.length],0,v)}Yo("gggg","weekYear"),Yo("ggggg","weekYear"),Yo("GGGG","isoWeekYear"),Yo("GGGGG","isoWeekYear"),je("G",Jt),je("g",Jt),je("GG",we,M),je("gg",we,M),je("GGGG",Xt,le),je("gggg",Xt,le),je("GGGGG",Zt,be),je("ggggg",Zt,be),aa(["gggg","ggggg","GGGG","GGGGG"],function(f,v,_,j){v[j.substr(0,2)]=et(f)}),aa(["gg","GG"],function(f,v,_,j){v[j]=r.parseTwoDigitYear(f)});function SI(f){return kh.call(this,f,this.week(),this.weekday()+this.localeData()._week.dow,this.localeData()._week.dow,this.localeData()._week.doy)}function CI(f){return kh.call(this,f,this.isoWeek(),this.isoWeekday(),1,4)}function _I(){return Mr(this.year(),1,4)}function EI(){return Mr(this.isoWeekYear(),1,4)}function II(){var f=this.localeData()._week;return Mr(this.year(),f.dow,f.doy)}function jI(){var f=this.localeData()._week;return Mr(this.weekYear(),f.dow,f.doy)}function kh(f,v,_,j,O){var G;return f==null?ca(this,j,O).year:(G=Mr(f,j,O),v>G&&(v=G),RI.call(this,f,v,_,j,O))}function RI(f,v,_,j,O){var G=ah(f,v,_,j,O),re=ua(G.year,0,G.dayOfYear);return this.year(re.getUTCFullYear()),this.month(re.getUTCMonth()),this.date(re.getUTCDate()),this}K("Q",0,"Qo","quarter"),je("Q",ee),gt("Q",function(f,v){v[Or]=(et(f)-1)*3});function kI(f){return f==null?Math.ceil((this.month()+1)/3):this.month((f-1)*3+this.month()%3)}K("D",["DD",2],"Do","date"),je("D",we,os),je("DD",we,M),je("Do",function(f,v){return f?v._dayOfMonthOrdinalParse||v._ordinalParse:v._dayOfMonthOrdinalParseLenient}),gt(["D","DD"],fr),gt("Do",function(f,v){v[fr]=et(f.match(we)[0])});var Ah=ls("Date",!0);K("DDD",["DDDD",3],"DDDo","dayOfYear"),je("DDD",zt),je("DDDD",q),gt(["DDD","DDDD"],function(f,v,_){_._dayOfYear=et(f)});function AI(f){var v=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return f==null?v:this.add(f-v,"d")}K("m",["mm",2],0,"minute"),je("m",we,mc),je("mm",we,M),gt(["m","mm"],Kn);var NI=ls("Minutes",!1);K("s",["ss",2],0,"second"),je("s",we,mc),je("ss",we,M),gt(["s","ss"],Dr);var OI=ls("Seconds",!1);K("S",0,0,function(){return~~(this.millisecond()/100)}),K(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),K(0,["SSS",3],0,"millisecond"),K(0,["SSSS",4],0,function(){return this.millisecond()*10}),K(0,["SSSSS",5],0,function(){return this.millisecond()*100}),K(0,["SSSSSS",6],0,function(){return this.millisecond()*1e3}),K(0,["SSSSSSS",7],0,function(){return this.millisecond()*1e4}),K(0,["SSSSSSSS",8],0,function(){return this.millisecond()*1e5}),K(0,["SSSSSSSSS",9],0,function(){return this.millisecond()*1e6}),je("S",zt,ee),je("SS",zt,M),je("SSS",zt,q);var ai,Nh;for(ai="SSSS";ai.length<=9;ai+="S")je(ai,wt);function DI(f,v){v[Ci]=et(("0."+f)*1e3)}for(ai="S";ai.length<=9;ai+="S")gt(ai,DI);Nh=ls("Milliseconds",!1),K("z",0,0,"zoneAbbr"),K("zz",0,0,"zoneName");function MI(){return this._isUTC?"UTC":""}function FI(){return this._isUTC?"Coordinated Universal Time":""}var fe=I.prototype;fe.add=jE,fe.calendar=ME,fe.clone=FE,fe.diff=zE,fe.endOf=QE,fe.format=WE,fe.from=UE,fe.fromNow=qE,fe.to=XE,fe.toNow=ZE,fe.get=$1,fe.invalidAt=oI,fe.isAfter=TE,fe.isBefore=PE,fe.isBetween=LE,fe.isSame=VE,fe.isSameOrAfter=BE,fe.isSameOrBefore=GE,fe.isValid=sI,fe.lang=_h,fe.locale=Ch,fe.localeData=Eh,fe.max=sE,fe.min=iE,fe.parsingFlags=aI,fe.set=W1,fe.startOf=JE,fe.subtract=RE,fe.toArray=nI,fe.toObject=rI,fe.toDate=tI,fe.toISOString=HE,fe.inspect=$E,typeof Symbol<"u"&&Symbol.for!=null&&(fe[Symbol.for("nodejs.util.inspect.custom")]=function(){return"Moment<"+this.format()+">"}),fe.toJSON=iI,fe.toString=YE,fe.unix=eI,fe.valueOf=KE,fe.creationData=lI,fe.eraName=fI,fe.eraNarrow=pI,fe.eraAbbr=mI,fe.eraYear=hI,fe.year=Km,fe.isLeapYear=H1,fe.weekYear=SI,fe.isoWeekYear=CI,fe.quarter=fe.quarters=kI,fe.month=ih,fe.daysInMonth=t_,fe.week=fe.weeks=u_,fe.isoWeek=fe.isoWeeks=c_,fe.weeksInYear=II,fe.weeksInWeekYear=jI,fe.isoWeeksInYear=_I,fe.isoWeeksInISOWeekYear=EI,fe.date=Ah,fe.day=fe.days=C_,fe.weekday=__,fe.isoWeekday=E_,fe.dayOfYear=AI,fe.hour=fe.hours=O_,fe.minute=fe.minutes=NI,fe.second=fe.seconds=OI,fe.millisecond=fe.milliseconds=Nh,fe.utcOffset=mE,fe.utc=gE,fe.local=vE,fe.parseZone=xE,fe.hasAlignedHourOffset=yE,fe.isDST=bE,fe.isLocal=SE,fe.isUtcOffset=CE,fe.isUtc=xh,fe.isUTC=xh,fe.zoneAbbr=MI,fe.zoneName=FI,fe.dates=P("dates accessor is deprecated. Use date instead.",Ah),fe.months=P("months accessor is deprecated. Use month instead",ih),fe.years=P("years accessor is deprecated. Use year instead",Km),fe.zone=P("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",hE),fe.isDSTShifted=P("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",wE);function TI(f){return Et(f*1e3)}function PI(){return Et.apply(null,arguments).parseZone()}function Oh(f){return f}var at=U.prototype;at.calendar=he,at.longDateFormat=Ye,at.invalidDate=Je,at.ordinal=Gt,at.preparse=Oh,at.postformat=Oh,at.relativeTime=Wt,at.pastFuture=Tt,at.set=Y,at.eras=uI,at.erasParse=cI,at.erasConvertYear=dI,at.erasAbbrRegex=vI,at.erasNameRegex=gI,at.erasNarrowRegex=xI,at.months=J1,at.monthsShort=Q1,at.monthsParse=e_,at.monthsRegex=r_,at.monthsShortRegex=n_,at.week=s_,at.firstDayOfYear=l_,at.firstDayOfWeek=o_,at.weekdays=x_,at.weekdaysMin=b_,at.weekdaysShort=y_,at.weekdaysParse=S_,at.weekdaysRegex=I_,at.weekdaysShortRegex=j_,at.weekdaysMinRegex=R_,at.isPM=A_,at.meridiem=D_;function Ho(f,v,_,j){var O=Fr(),G=g().set(j,v);return O[_](G,f)}function Dh(f,v,_){if(d(f)&&(v=f,f=void 0),f=f||"",v!=null)return Ho(f,v,_,"month");var j,O=[];for(j=0;j<12;j++)O[j]=Ho(f,j,_,"month");return O}function Nc(f,v,_,j){typeof f=="boolean"?(d(v)&&(_=v,v=void 0),v=v||""):(v=f,_=v,f=!1,d(v)&&(_=v,v=void 0),v=v||"");var O=Fr(),G=f?O._week.dow:0,re,Ie=[];if(_!=null)return Ho(v,(_+G)%7,j,"day");for(re=0;re<7;re++)Ie[re]=Ho(v,(re+G)%7,j,"day");return Ie}function LI(f,v){return Dh(f,v,"months")}function VI(f,v){return Dh(f,v,"monthsShort")}function BI(f,v,_){return Nc(f,v,_,"weekdays")}function GI(f,v,_){return Nc(f,v,_,"weekdaysShort")}function zI(f,v,_){return Nc(f,v,_,"weekdaysMin")}si("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 v=f%10,_=et(f%100/10)===1?"th":v===1?"st":v===2?"nd":v===3?"rd":"th";return f+_}}),r.lang=P("moment.lang is deprecated. Use moment.locale instead.",si),r.langData=P("moment.langData is deprecated. Use moment.localeData instead.",Fr);var Tr=Math.abs;function YI(){var f=this._data;return this._milliseconds=Tr(this._milliseconds),this._days=Tr(this._days),this._months=Tr(this._months),f.milliseconds=Tr(f.milliseconds),f.seconds=Tr(f.seconds),f.minutes=Tr(f.minutes),f.hours=Tr(f.hours),f.months=Tr(f.months),f.years=Tr(f.years),this}function Mh(f,v,_,j){var O=er(v,_);return f._milliseconds+=j*O._milliseconds,f._days+=j*O._days,f._months+=j*O._months,f._bubble()}function HI(f,v){return Mh(this,f,v,1)}function $I(f,v){return Mh(this,f,v,-1)}function Fh(f){return f<0?Math.floor(f):Math.ceil(f)}function WI(){var f=this._milliseconds,v=this._days,_=this._months,j=this._data,O,G,re,Ie,He;return f>=0&&v>=0&&_>=0||f<=0&&v<=0&&_<=0||(f+=Fh(Oc(_)+v)*864e5,v=0,_=0),j.milliseconds=f%1e3,O=Bn(f/1e3),j.seconds=O%60,G=Bn(O/60),j.minutes=G%60,re=Bn(G/60),j.hours=re%24,v+=Bn(re/24),He=Bn(Th(v)),_+=He,v-=Fh(Oc(He)),Ie=Bn(_/12),_%=12,j.days=v,j.months=_,j.years=Ie,this}function Th(f){return f*4800/146097}function Oc(f){return f*146097/4800}function UI(f){if(!this.isValid())return NaN;var v,_,j=this._milliseconds;if(f=L(f),f==="month"||f==="quarter"||f==="year")switch(v=this._days+j/864e5,_=this._months+Th(v),f){case"month":return _;case"quarter":return _/3;case"year":return _/12}else switch(v=this._days+Math.round(Oc(this._months)),f){case"week":return v/7+j/6048e5;case"day":return v+j/864e5;case"hour":return v*24+j/36e5;case"minute":return v*1440+j/6e4;case"second":return v*86400+j/1e3;case"millisecond":return Math.floor(v*864e5)+j;default:throw new Error("Unknown unit "+f)}}function Pr(f){return function(){return this.as(f)}}var Ph=Pr("ms"),qI=Pr("s"),XI=Pr("m"),ZI=Pr("h"),JI=Pr("d"),QI=Pr("w"),KI=Pr("M"),ej=Pr("Q"),tj=Pr("y"),nj=Ph;function rj(){return er(this)}function ij(f){return f=L(f),this.isValid()?this[f+"s"]():NaN}function Ei(f){return function(){return this.isValid()?this._data[f]:NaN}}var sj=Ei("milliseconds"),aj=Ei("seconds"),oj=Ei("minutes"),lj=Ei("hours"),uj=Ei("days"),cj=Ei("months"),dj=Ei("years");function fj(){return Bn(this.days()/7)}var Lr=Math.round,fs={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function pj(f,v,_,j,O){return O.relativeTime(v||1,!!_,f,j)}function mj(f,v,_,j){var O=er(f).abs(),G=Lr(O.as("s")),re=Lr(O.as("m")),Ie=Lr(O.as("h")),He=Lr(O.as("d")),nt=Lr(O.as("M")),pn=Lr(O.as("w")),Vr=Lr(O.as("y")),oi=G<=_.ss&&["s",G]||G<_.s&&["ss",G]||re<=1&&["m"]||re<_.m&&["mm",re]||Ie<=1&&["h"]||Ie<_.h&&["hh",Ie]||He<=1&&["d"]||He<_.d&&["dd",He];return _.w!=null&&(oi=oi||pn<=1&&["w"]||pn<_.w&&["ww",pn]),oi=oi||nt<=1&&["M"]||nt<_.M&&["MM",nt]||Vr<=1&&["y"]||["yy",Vr],oi[2]=v,oi[3]=+f>0,oi[4]=j,pj.apply(null,oi)}function hj(f){return f===void 0?Lr:typeof f=="function"?(Lr=f,!0):!1}function gj(f,v){return fs[f]===void 0?!1:v===void 0?fs[f]:(fs[f]=v,f==="s"&&(fs.ss=v-1),!0)}function vj(f,v){if(!this.isValid())return this.localeData().invalidDate();var _=!1,j=fs,O,G;return typeof f=="object"&&(v=f,f=!1),typeof f=="boolean"&&(_=f),typeof v=="object"&&(j=Object.assign({},fs,v),v.s!=null&&v.ss==null&&(j.ss=v.s-1)),O=this.localeData(),G=mj(this,!_,j,O),_&&(G=O.pastFuture(+this,G)),O.postformat(G)}var Dc=Math.abs;function ps(f){return(f>0)-(f<0)||+f}function $o(){if(!this.isValid())return this.localeData().invalidDate();var f=Dc(this._milliseconds)/1e3,v=Dc(this._days),_=Dc(this._months),j,O,G,re,Ie=this.asSeconds(),He,nt,pn,Vr;return Ie?(j=Bn(f/60),O=Bn(j/60),f%=60,j%=60,G=Bn(_/12),_%=12,re=f?f.toFixed(3).replace(/\.?0+$/,""):"",He=Ie<0?"-":"",nt=ps(this._months)!==ps(Ie)?"-":"",pn=ps(this._days)!==ps(Ie)?"-":"",Vr=ps(this._milliseconds)!==ps(Ie)?"-":"",He+"P"+(G?nt+G+"Y":"")+(_?nt+_+"M":"")+(v?pn+v+"D":"")+(O||j||f?"T":"")+(O?Vr+O+"H":"")+(j?Vr+j+"M":"")+(f?Vr+re+"S":"")):"P0D"}var rt=Lo.prototype;rt.isValid=cE,rt.abs=YI,rt.add=HI,rt.subtract=$I,rt.as=UI,rt.asMilliseconds=Ph,rt.asSeconds=qI,rt.asMinutes=XI,rt.asHours=ZI,rt.asDays=JI,rt.asWeeks=QI,rt.asMonths=KI,rt.asQuarters=ej,rt.asYears=tj,rt.valueOf=nj,rt._bubble=WI,rt.clone=rj,rt.get=ij,rt.milliseconds=sj,rt.seconds=aj,rt.minutes=oj,rt.hours=lj,rt.days=uj,rt.weeks=fj,rt.months=cj,rt.years=dj,rt.humanize=vj,rt.toISOString=$o,rt.toString=$o,rt.toJSON=$o,rt.locale=Ch,rt.localeData=Eh,rt.toIsoString=P("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",$o),rt.lang=_h,K("X",0,0,"unix"),K("x",0,0,"valueOf"),je("x",Jt),je("X",L1),gt("X",function(f,v,_){_._d=new Date(parseFloat(f)*1e3)}),gt("x",function(f,v,_){_._d=new Date(et(f))});return r.version="2.30.1",i(Et),r.fn=fe,r.min=aE,r.max=oE,r.now=lE,r.utc=g,r.unix=TI,r.months=LI,r.isDate=p,r.locale=si,r.invalid=w,r.duration=er,r.isMoment=A,r.weekdays=BI,r.parseZone=PI,r.localeData=Fr,r.isDuration=Vo,r.monthsShort=VI,r.weekdaysMin=zI,r.defineLocale=bc,r.updateLocale=P_,r.locales=L_,r.weekdaysShort=GI,r.normalizeUnits=L,r.relativeTimeRounding=hj,r.relativeTimeThreshold=gj,r.calendarFormat=DE,r.prototype=fe,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}))})(Ml)),Ml.exports}var eU=KW();const gl=bi(eU);function oy({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r,expanded:i=!0}){const[s,a]=x.useState(null),[l,u]=x.useState(!1),[c,d]=x.useState(i),p=g=>{r(["issue","attachment","status_mail"]),r(["issue","status_mail"])},h=()=>n.filter(g=>g.issue.id===e.id),m=()=>{a(o.jsx(No,{equipment:t,showModal:!0,onClose:g=>{u(!1),g&&p()},issue:e,attachments:h()})),u(!0)};return o.jsxs("div",{className:"p-3 mb-4 border-bottom",children:[o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-2",children:[o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(hn,{bg:"dark",children:"Issue"}),o.jsx("h4",{className:e.date_closed?"text-danger mb-0":"mb-0",children:e.date_closed?o.jsx("s",{children:e.issue}):e.issue})]}),o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(de,{variant:"outline-primary",size:"sm",onClick:()=>d(g=>!g),"aria-label":"Toggle Details",children:c?"Hide Details":"Show Details"}),o.jsx(de,{variant:"secondary",size:"sm",onClick:m,"aria-label":"Edit Issue",children:"Edit"})]})]}),c&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"mb-2",children:o.jsx(ss,{children:e.description})}),o.jsx("p",{className:"mb-3",children:e.actions}),o.jsxs("div",{className:"d-flex flex-wrap gap-4 text-muted",children:[o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Creator"}),o.jsx("div",{className:"text-body",children:e.owner.full_name})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Date Created"}),o.jsx("div",{className:"text-body",children:gl(e.date_created).format("DD MMMM YYYY")})]}),e.date_closed&&o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Date Closed"}),o.jsx("div",{className:"text-body",children:gl(e.date_closed).format("DD MMMM YYYY")})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Forecast Up"}),o.jsx("div",{className:"text-body",children:gl(e.forecast_up).format("DD MMMM YYYY")})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Issue Type"}),o.jsxs("div",{className:"text-body",children:[e.issue_type===Wr.DEFAULT&&"Issue",e.issue_type===Wr.ESCALATION&&"Escalation",e.issue_type===Wr.PRIORITY&&"Priority"]})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Attachments"}),o.jsx("div",{className:"text-body",children:e.attachments})]}),e.updated_by&&o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Last Update By"}),o.jsx("div",{className:"text-body",children:e.updated_by.full_name})]}),e.last_update&&o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Last Update"}),o.jsx("div",{className:"text-body",children:gl(e.last_update).format("DD MMMM YYYY")})]})]})]}),l&&s]})}function ly({reservations:e}){if(!e||e.length<1)return o.jsx(o.Fragment,{});const t=e[0];return o.jsx(Wi,{placement:"top",overlay:o.jsxs(xi,{id:`tooltip-${t.id}`,children:[o.jsx("h5",{children:t.title}),o.jsx("p",{children:e[0].active?"Currently active":`Upcoming in: ${ye(e[0].start).format("DD MMMM YYYY")}`}),o.jsx("p",{children:e[1]?`Next upcoming reservation in: ${ye(e[1].start).format("DD MMMM YYYY")}`:"No next upcoming reservations"})]}),children:o.jsxs(hn,{bg:e[0].active?"info":"dark",children:["Reserved by: ",e[0].user.full_name]})})}function tU({equipment:e,modules:t,issues:n,issueAttachments:r,ecnNotes:i,ecnAttachments:s,reloadQueryFn:a,showIssues:l,reservations:u}){const[c,d]=x.useState(null),[p,h]=x.useState(!1),[m,g]=x.useState(null),[y,b]=x.useState(!1),[S,R]=x.useState([]),[w,E]=x.useState(void 0),[C,k]=x.useState([]),[I,A]=x.useState([]),F=T=>{a(["ecn","attachment","status_mail"]),k([...C,T])},P=T=>{a(["issue","status_mail"]),a(["issue","attachment","status_mail"]),A([...I,T])};x.useEffect(()=>{k(i),A(n),R(t.filter(T=>T.equipment.id===e.id&&!T.type.is_main_tool)),E(t.findLast(T=>T.equipment.id===e.id&&T.type.is_main_tool))},[i,n,e,t]);const B=T=>C.filter(U=>U.module_id===T),V=T=>I.filter(U=>U.module_id===T),z=()=>{g(o.jsx(Ju,{equipment:e,showModal:!0,onClose:T=>{b(!1),T&&F(T)}})),b(!0)},Y=()=>{d(o.jsx(No,{equipment:e,showModal:!0,onClose:T=>{h(!1),T&&P(T)}})),h(!0)};return o.jsxs("div",{className:"card mb-4",children:[o.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsxs("h4",{className:"mb-0",children:[e.number," - ",e.name]}),w&&o.jsx(qi,{module:w}),w&&o.jsx(ly,{reservations:u.filter(T=>T.modules.some(U=>U.id===w.id))})]}),o.jsxs(fo,{as:cb,title:"Action",id:"bg-nested-dropdown",children:[o.jsx(Ue.Item,{eventKey:"1",onClick:z,children:"New ECN"}),l!==1&&o.jsx(Ue.Item,{eventKey:"1",onClick:Y,children:"New Issue"})]})]}),o.jsx("div",{className:"card-body",children:o.jsxs(Un,{children:[w&&o.jsx(Mt,{xs:12,md:S.length>0?6:12,children:o.jsx(Ze,{className:"mb-3",children:o.jsxs(Ze.Body,{children:[o.jsxs(Ze.Title,{className:"d-flex align-items-center",children:[o.jsx("span",{children:"Main module"}),o.jsx("div",{className:"ms-2"})]}),o.jsxs("div",{className:"mt-3",children:[B(w.id).map((T,U)=>o.jsx(sy,{ecn:T,equipment:e,ecnAttachments:s,reloadQueryFn:a,expanded:!0},U)),l!==1&&V(w.id).map((T,U)=>o.jsx(oy,{issue:T,equipment:e,issueAttachments:r,reloadQueryFn:a,expanded:l!==3},U))]})]})})}),S.length>0&&o.jsx(Mt,{xs:12,md:w?6:12,children:S.map((T,U)=>o.jsx(Ze,{className:"mb-3",children:o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{className:"d-flex align-items-center",children:o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx("span",{children:T.name}),o.jsx(qi,{module:T}),o.jsx(ly,{reservations:u.filter(ie=>ie.modules.some(oe=>oe.id===T.id))})]})}),o.jsxs("div",{className:"mt-3",children:[B(T.id).map((ie,oe)=>o.jsx(sy,{ecn:ie,equipment:e,ecnAttachments:s,reloadQueryFn:a,expanded:!0},oe)),l!==1&&V(T.id).map((ie,oe)=>o.jsx(oy,{issue:ie,equipment:e,issueAttachments:r,reloadQueryFn:a,expanded:l!==3},oe))]})]})},U))})]})}),y&&m,p&&c]})}const o1=({showModal:e,onClose:t,message:n})=>{const{register:r,handleSubmit:i,setValue:s,reset:a,control:l}=gn({defaultValues:{title:n?.title,description:n?.description,rooms:n?.rooms,type:n?.type,owner:n?.owner}}),[u,c]=x.useState([]),[d,p]=x.useState([]),[h,m]=x.useState(""),g=()=>document.documentElement.getAttribute("data-bs-theme")==="dark",y={control:w=>({...w,backgroundColor:g()?"#212529":w.backgroundColor,borderColor:g()?"#495057":w.borderColor,color:g()?"#fff":w.color}),menu:w=>({...w,backgroundColor:g()?"#212529":w.backgroundColor}),option:(w,E)=>({...w,backgroundColor:g()?E.isSelected?"#0d6efd":E.isFocused?"#343a40":"#212529":w.backgroundColor,color:g()?"#fff":w.color}),singleValue:w=>({...w,color:g()?"#fff":w.color}),multiValue:w=>({...w,backgroundColor:g()?"#343a40":w.backgroundColor}),multiValueLabel:w=>({...w,color:g()?"#fff":w.color}),input:w=>({...w,color:g()?"#fff":w.color})};let{statusMail:b}=x.useContext(Xu);x.useEffect(()=>{Ee.get("/list/room").then(w=>{const C=(w.data._embedded.items||[]).map(k=>({value:k,label:k.name}));c(C)}).catch(w=>{console.error("Error fetching rooms:",w),m("Error fetching rooms:"+w)}),Ee.get("/list/location/message/type").then(w=>{const E=b.filter.messageType,k=(w.data._embedded.items||[]).filter(I=>E.includes(I.id.toString())).map(I=>({value:I,label:I.type}));p(k),s("type",n?.type||k[0].value)}).catch(w=>{console.error("Error fetching message types:",w),m("Error fetching message types:"+w)})},[]);const S=w=>{if(w.title){if(w?.owner.value===void 0&&n?.owner===void 0)return"owner";if(w.rooms===void 0||w.rooms.map(E=>E.id).length<=0)return"room";if(!w.type)return"type"}else return"title";return""},R=async w=>{const E=S(w);if(E!==""){m("Please fill: "+E);return}try{const C={title:w.title,description:w.description,owner:w?.owner.value||n?.owner.id,type:w.type.id,rooms:w.rooms.map(I=>I.id)};let k;if(n?k=await Ee.patch(`/update/location/message/${n.id}`,C):k=await Ee.post("/create/location/message",C),k){t(k?.data),a();return}console.error("No response received"),m("No response received")}catch(C){console.error("Error submitting the form:",C),m("Error submitting the form:"+C)}};return o.jsx(xe,{show:e,size:"lg",centered:!0,onHide:()=>t(n),children:o.jsxs(H,{onSubmit:i(R),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Edit status mail message"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Title"}),o.jsx(H.Control,{type:"text",placeholder:"Enter the title",...r("title")})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Message"}),o.jsx(H.Control,{as:"textarea",rows:3,placeholder:"Give the message",...r("description")})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Owner"}),o.jsx(_o,{control:l,...r("owner",{required:"Owner is required"}),name:"owner"})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Rooms"}),o.jsx(ar,{name:"rooms",control:l,render:({field:w})=>o.jsx(Af,{isMulti:!0,options:u,classNamePrefix:"react-select",placeholder:"Select one or more rooms",value:u.filter(E=>w.value?.some(C=>C.id===E.value.id)),onChange:E=>w.onChange(E.map(C=>C.value)),styles:y})})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Type"}),o.jsx(ar,{name:"type",control:l,render:({field:w})=>o.jsx(Af,{options:d,classNamePrefix:"react-select",placeholder:"Select a message type",value:d.find(E=>E.value.id===w.value?.id)||null,onChange:E=>w.onChange(E?.value),styles:y})})]})]}),o.jsxs(xe.Footer,{children:[h!=""&&o.jsx("span",{className:"text-danger",children:h}),o.jsx(de,{variant:"secondary",onClick:()=>t(n),children:"Cancel"}),o.jsx(de,{variant:"primary",type:"submit",children:n?"Update Message":"Create Message"})]})]})})};function nU({message:e}){const[t,n]=x.useState(null),[r,i]=x.useState(!1),[s,a]=x.useState(e),l=c=>{a({...s,...c})},u=()=>{n(o.jsx(o1,{showModal:!0,onClose:c=>{i(!1),c&&l(c)},message:s})),i(!0)};return o.jsxs("div",{className:"card mb-4",children:[o.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(hn,{bg:"dark",children:s.type.type}),o.jsx("h5",{className:"mb-0",children:s.title})]}),o.jsx(de,{variant:"secondary",size:"sm",onClick:u,children:"Edit"})]}),o.jsx("div",{className:"card-body",children:o.jsx(ss,{children:s.description})}),o.jsx("div",{className:"card-footer bg-transparent",children:o.jsxs("small",{className:"text-muted d-flex flex-wrap gap-3",children:[o.jsxs("span",{children:["Created: ",ye(s.date_created).format("DD MMM YYYY")]}),s.last_update&&o.jsxs("span",{children:["Updated: ",ye(s.last_update).format("DD MMM YYYY")]}),s.rooms.length>0&&o.jsxs("span",{children:["Rooms:"," ",s.rooms.map((c,d)=>o.jsxs(x.Fragment,{children:[d>0&&", ",c.name]},c.id))]}),o.jsxs("span",{children:["Owner: ",s.owner.full_name]})]})}),r&&t]})}function rU({messageList:e,refetchFn:t}){const[n,r]=x.useState(null),[i,s]=x.useState(!1),a=()=>{r(o.jsx(o1,{showModal:!0,onClose:l=>{s(!1),t()}})),s(!0)};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"d-flex gap-3",children:[o.jsx("h2",{children:"Messages"}),o.jsx("div",{children:o.jsx(de,{variant:"secondary",onClick:a,children:"New message"})})]}),e.map((l,u)=>o.jsx("div",{children:o.jsx(nU,{message:l})},l.id)),i&&n]})}function iU({issue:e,moduleName:t,issueAttachments:n,equipment:r,reloadQueryFn:i}){const[s,a]=x.useState(null),[l,u]=x.useState(!1),c=h=>{i(["issue","status_mail"]),i(["issue","attachment","status_mail"])},d=()=>n.filter(h=>h.issue.id===e.id),p=()=>{if(!r){console.error("equipment is null in the table");return}u(!0),a(o.jsx(No,{equipment:r,showModal:!0,onClose:h=>{u(!1),h&&c()},issue:e,attachments:d()}))};return o.jsxs(o.Fragment,{children:[o.jsxs("tr",{className:"align-middle",children:[o.jsx("td",{className:"text-nowrap",children:t??"-"}),o.jsx("td",{children:e.issue}),o.jsx("td",{children:o.jsx(ss,{children:e.description})}),o.jsx("td",{className:"text-nowrap",children:ye(e.forecast_up).format("DD MMMM YYYY")}),o.jsx("td",{className:"text-nowrap",children:e.owner.full_name}),o.jsx("td",{className:"text-center",children:o.jsx("button",{type:"button",className:"btn btn-sm btn-outline-light",onClick:p,children:"Edit"})})]},e.id),l&&s]})}function sU({issues:e,modules:t,issueAttachments:n,reloadQueryFn:r}){return o.jsx("div",{className:"table-responsive",children:o.jsxs("table",{className:"table table-hover table-striped table-bordered table-sm",children:[o.jsx("thead",{className:"bg-primary text-white",children:o.jsxs("tr",{children:[o.jsx("th",{scope:"col",children:"Module"}),o.jsx("th",{scope:"col",children:"Issue"}),o.jsx("th",{scope:"col",children:"Description"}),o.jsx("th",{scope:"col",children:"Forecast Up"}),o.jsx("th",{scope:"col",children:"Owner"}),o.jsx("th",{scope:"col",className:"text-center",children:"Actions"})]})}),o.jsx("tbody",{children:e.map(i=>o.jsx(iU,{issue:i,moduleName:t.find(s=>s.id===i.module_id)?.name,issueAttachments:n,equipment:t.find(s=>s.id===i.module_id)?.equipment,reloadQueryFn:r},i.id))})]})})}function aU({statusMail:e}){const[t,n]=x.useState(!1),[r,i]=x.useState(!1),s=async()=>{try{if(n(!0),!e.id||e.id<=0)throw new Error("Status Mail ID is not correctly set");const a={status_mail:e.id};await Ee.post("/send/status-mail",a),i(!0)}catch(a){console.error("Error sending status mail:",a),alert("Error sending status mail. Please try again.")}finally{n(!1)}};return o.jsx(de,{variant:"primary",size:"sm",onClick:s,disabled:t,"aria-label":"Toggle Details",children:t?"Sending...":r?"Sending successful":"Send Status Mail"})}function oU(){let{statusMail:e}=x.useContext(Xu);const[t,n]=x.useState([]),r=Pe.useQueryClient(),i=Pe.useQueries({queries:[{queryKey:["equipment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Vy({statusMail:e})},{queryKey:["module","status_mail",JSON.stringify(e.filter)],queryFn:()=>Hi({statusMail:e})},{queryKey:["ecn","status_mail",JSON.stringify(e.filter)],queryFn:()=>up({statusMail:e})},{queryKey:["issue","status_mail",JSON.stringify(e.filter)],queryFn:()=>zy({statusMail:e})},{queryKey:["messages","status_mail",JSON.stringify(e.filter)],queryFn:()=>ck({statusMail:e})},{queryKey:["ecn","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>By({statusMail:e})},{queryKey:["issue","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Gy({statusMail:e})},{queryKey:["reservation","active","status_mail",JSON.stringify(e.filter)],queryFn:()=>Tl({which:"active"})},{queryKey:["reservation","upcoming","status_mail",JSON.stringify(e.filter)],queryFn:()=>Tl({which:"upcoming"})}]}),s=E=>{let C=E;C.push(JSON.stringify(e.filter)),r.refetchQueries({queryKey:C})},[a,l,u,c,d,p,h,m,g]=i,y=i.some(E=>E.isLoading),b=i.some(E=>E.isError),S=i.every(E=>E.isSuccess);x.useEffect(()=>{S&&n(a.data.items)},[S]);const R=()=>{if(!t.length)return o.jsx("p",{children:"No equipment available."});t.sort((I,A)=>e.classification===ji.ROOM?I.room.name.localeCompare(A.room.name):e.classification===ji.AREA?I.area.localeCompare(A.area):e.classification===ji.AREA_PER_FACILITY?I.facility.localeCompare(A.facility)||I.area.localeCompare(A.area):0);let E="",C="",k="";return t.map((I,A)=>{const F=[];return e.classification===ji.ROOM?I.room.name!==k&&(F.push(o.jsxs("h2",{children:["Room: ",I.room.name]},`room-${I.room.name}`)),k=I.room.name):e.classification===ji.AREA?I.area!==C&&(F.push(o.jsxs("h2",{children:["Area: ",I.area]},`area-${I.area}`)),C=I.area):e.classification===ji.AREA_PER_FACILITY&&(I.facility!==E&&(F.push(o.jsxs("h2",{children:["Facility: ",I.facility]},`facility-${I.facility}`)),E=I.facility),I.area!==C&&(F.push(o.jsxs("h4",{children:["Area: ",I.area]},`area-${I.area}`)),C=I.area)),F.push(o.jsx(tU,{equipment:I,modules:l.data.items,issues:c.data.items,issueAttachments:h.data.items,ecnNotes:u.data.items,ecnAttachments:p.data.items,reloadQueryFn:s,showIssues:e.show_issues,reservations:e.show_reservations?m.data.items.concat(g.data.items):[]},A)),F})},w=()=>{const E=c.data.items.filter(C=>C.issue_type===2);return E.length===0?o.jsx(o.Fragment,{}):o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:"Issues with priority"}),o.jsx(sU,{issues:E,modules:l.data.items,issueAttachments:h.data.items,reloadQueryFn:s})]})};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"d-flex justify-content-between align-items-center",children:[o.jsxs("h1",{className:"display-4",children:["Status mail ",e.name]}),o.jsx("div",{children:o.jsx(aU,{statusMail:e})})]}),o.jsx("p",{children:e.subject}),y&&o.jsx(Bt,{variant:"info",children:"Loading status mail"}),b&&o.jsx(Bt,{variant:"danger",children:"Error loading status mail"}),S&&e.show_issues_with_priority&&w(),S&&d.data&&o.jsx(rU,{messageList:d.data.items,refetchFn:d.refetch}),S&&R()]})}function lU(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 uU(e,t){const n=lU(e);if(!n)return"";const r=a=>a.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 s=t;return Object.keys(i).sort((a,l)=>l.length-a.length).forEach(a=>{s=s.replace(new RegExp(a,"g"),i[a])}),s}function Ln(e,t="DD-MM-YY HH:mm"){return uU(e,t)}function Um({monitor:e}){const{environment:t}=Te.useParams(),[n]=Pe.useQueries({queries:[{queryKey:["requirement",e],queryFn:()=>Yy({monitorId:e.id})}]});return n.isLoading?o.jsx("div",{children:"Loading requirements..."}):n.data?.items.map((r,i)=>{let s="bg-secondary-subtle";if(r.latest_result)for(let a=0;a<r.latest_result.values.length;a++){if(r.latest_result.values[a].value_is_valid===!1){s="bg-danger-subtle";break}if(r.latest_result.values[a].value_is_valid===!0){s="bg-success-subtle";break}}return o.jsx(Ze,{className:"mb-2 me-2",children:o.jsxs(Ze.Body,{className:s,children:[o.jsx(Ze.Title,{children:o.jsx(Te.Link,{to:`/${t}/operator/monitor/`+e.id,children:e.name})}),o.jsxs(Ze.Text,{children:[r.title,r.latest_result&&o.jsxs(o.Fragment,{children:["Latest measurement: ",Ln(r.latest_result.date_created,"DD-MM-YY HH:mm")]})]})]})},i)})}const l1=({moduleId:e,size:t})=>{const[n,r]=x.useState(!1),[i,s]=x.useState(!1),[a,l]=x.useState("");function u(){Ee.create().post("create/equipment/module/changelog",{module:e,changelog:a}).finally(()=>{r(!1),s(!0),l("")})}const c=p=>{l(p.target.value)};function d(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>s(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Assist logged"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Assist was logged successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"primary",size:t,onClick:()=>r(!0),children:"Log assist"}),o.jsxs(xe,{show:n,size:"lg",onHide:()=>r(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Log assist"})}),o.jsx(xe.Body,{children:o.jsx(H,{children:o.jsxs(H.Group,{className:"mb-3",controlId:"modal.ControlTextarea1",children:[o.jsx(H.Label,{children:"Describe the assist"}),o.jsx(H.Control,{as:"textarea",rows:3,value:a,onChange:p=>c(p)})]})})}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",variant:"primary",onClick:()=>u(),children:"Log assist"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{r(!1)},children:"Close"})]})]}),o.jsx(d,{})]})},fc=x.createContext({equipment:{},reloadEquipment:()=>{}});function cU({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r}){const[i,s]=x.useState(null),[a,l]=x.useState(!1),[u,c]=x.useState(e),d=m=>{r(["issue",t.name]),r(["issue","attachment",t.name]),c({...u,...m})},p=()=>n.filter(m=>m.issue.id===e.id),h=()=>{s(o.jsx(No,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},issue:u,attachments:p()})),l(!0)};return o.jsxs("div",{children:[o.jsxs(Ze,{className:"my-2",children:[o.jsxs(Ze.Body,{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs(Ze.Title,{children:[o.jsx(hn,{bg:"dark",children:"Issue"})," ",u.issue]}),o.jsx(de,{variant:"secondary",size:"sm",onClick:h,children:"Edit"})]}),o.jsx(Ze.Text,{children:o.jsx(ss,{children:u.description})})]}),o.jsxs(Wn,{className:"list-group-flush",children:[u.date_created&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Created:"}),o.jsx("span",{className:"ms-1",children:Ln(u.date_created,"DD-MM-YY HH:mm")})]}),u.owner&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Owner:"}),o.jsx("span",{className:"ms-1",children:u.owner.full_name})]}),u.updated_by&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Updated:"}),o.jsx("span",{className:"ms-1",children:u.updated_by.full_name}),o.jsxs("span",{className:"ms-1",children:["(",Ln(u.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},u.module_id),a&&i]})}function dU({ecn:e,equipment:t,ecnAttachments:n,reloadQueryFn:r}){const[i,s]=x.useState(null),[a,l]=x.useState(!1),[u,c]=x.useState(e),d=m=>{r(["ecn",t.name]),r(["ecn","attachment",t.name]),c({...u,...m})},p=()=>n.filter(m=>m.ecn.id===e.id),h=()=>{s(o.jsx(Ju,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},ecn:u,attachments:p()})),l(!0)};return o.jsxs("div",{children:[o.jsxs(Ze,{className:"my-2",children:[o.jsxs(Ze.Body,{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs(Ze.Title,{children:[o.jsx(hn,{bg:"dark",children:"ECN"})," ",e.ecn]}),o.jsx(de,{variant:"secondary",size:"sm",onClick:h,children:"Edit"})]}),o.jsx(Ze.Text,{children:o.jsx(ss,{children:e.description})})]}),o.jsxs(Wn,{className:"list-group-flush",children:[u.date_created&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Created:"}),o.jsx("span",{className:"ms-1",children:Ln(u.date_created,"DD-MM-YY HH:mm")})]}),u.owner&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Owner:"}),o.jsx("span",{className:"ms-1",children:u.owner.full_name})]}),u.updated_by&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Updated:"}),o.jsx("span",{className:"ms-1",children:u.updated_by.full_name}),o.jsxs("span",{className:"ms-1",children:["(",Ln(u.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},e.module_id),a&&i]})}function fU(){const{id:e}=Te.useParams(),[t,n]=x.useState([]),r=Pe.useQueries({queries:[{queryKey:["service","equipment",e],queryFn:()=>Ek({equipmentId:Number(e)})}]}),[i]=r,s=r.some(c=>c.isLoading),a=r.some(c=>c.isError),l=r.every(c=>c.isSuccess);if(x.useEffect(()=>{l&&n(i.data.items)},[l,i.data]),s)return o.jsx("div",{children:"Loading..."});if(a)return o.jsx("div",{children:"Error loading services."});const u=c=>{if(c<60)return`${c} min`;const d=Math.floor(c/60),p=c%60;return`${d}h ${p>0?`${p}min`:""}`.trim()};return i.data.items.length===0?o.jsxs("div",{children:[o.jsx("h2",{children:"Services"}),o.jsx(Bt,{variant:"info",children:"No services found"})]}):o.jsxs("div",{children:[o.jsx("h2",{children:"Services"}),o.jsxs(Kt,{striped:!0,bordered:!0,hover:!0,responsive:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Id"}),o.jsx("th",{children:"Name"}),o.jsx("th",{children:"Type"}),o.jsx("th",{children:"Team"}),o.jsx("th",{children:"Department"}),o.jsx("th",{children:"Duration"}),o.jsx("th",{children:"Report2"})]})}),o.jsx("tbody",{children:t.map(c=>o.jsxs("tr",{children:[o.jsx("td",{children:c.id}),o.jsx("td",{children:o.jsx("a",{href:`/${window.location.pathname.split("/")[1]}/service/details/${c.id}/general.html`,children:c.name})}),o.jsx("td",{children:c.type?.name||"N/A"}),o.jsx("td",{children:c.team?.name||"N/A"}),o.jsx("td",{children:c.department?.name||"N/A"}),o.jsx("td",{children:u(c.minutes_needed_for_service)}),o.jsx("td",{children:c.latest_event_report_id&&o.jsx("a",{className:"btn btn-primary btn-sm",href:`/${window.location.pathname.split("/")[1]}/service/event/report/${c.latest_event_report_id}/results`,children:"View Report"})})]},c.id))})]})]})}function pU(){const{environment:e}=Te.useParams(),{equipment:t}=x.useContext(fc),n=Pe.useQueryClient(),[r,i]=x.useState(null),[s,a]=x.useState(!1),[l,u]=x.useState(null),[c,d]=x.useState(!1),[p,h,m,g,y,b,S]=Pe.useQueries({queries:[{queryKey:["runs",t.name,e],queryFn:()=>yk({firstUnfinishedStepEquipment:t,environment:e})},{queryKey:["monitors",t.name],queryFn:()=>Hy({equipment:t})},{queryKey:["ecn",t.name],queryFn:()=>up({equipment:t})},{queryKey:["issue",t.name],queryFn:()=>zy({equipment:t})},{queryKey:["module",t.name],queryFn:()=>Hi({equipment:t})},{queryKey:["ecn","attachment",t.name],queryFn:()=>By({equipment:t})},{queryKey:["issue","attachment",t.name],queryFn:()=>Gy({equipment:t})}]}),R=I=>{n.invalidateQueries({queryKey:I})},w=I=>I?m.data?.items.filter(A=>A.module_id===I):[],E=I=>I?g.data?.items.filter(A=>A.module_id===I):[],C=()=>{u(o.jsx(Ju,{equipment:t,showModal:!0,onClose:()=>{d(!1),setTimeout(()=>{R(["ecn",t.name]),R(["ecn","attachment",t.name])},100)}})),d(!0)},k=()=>{i(o.jsx(No,{equipment:t,showModal:!0,onClose:()=>{a(!1),setTimeout(()=>{R(["issue",t.name]),R(["issue","attachment",t.name])},100)}})),a(!0)};return o.jsxs(es,{fluid:!0,children:[o.jsx("div",{className:"d-flex justify-content-left",children:h.data?.items&&h.data.items.map((I,A)=>o.jsx(Um,{monitor:I},A))}),o.jsxs(Un,{children:[o.jsxs(Mt,{md:8,children:[o.jsx("h2",{children:"Runs"}),p.isLoading&&o.jsx("div",{children:"Loading..."})," ",p.isError&&o.jsx("div",{children:"Error..."}),p.isFetched&&p.data&&p.data?.items.length===0&&o.jsx(Bt,{variant:"info",children:"No runs found"}),p.isFetched&&p.data&&p.data?.items.length>0&&o.jsxs(Kt,{striped:!0,bordered:!0,hover:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Run"}),o.jsx("th",{children:"Priority"}),o.jsx("th",{children:"Hold Code"}),o.jsx("th",{children:"Batch Card"}),o.jsx("th",{children:"Project"})]})}),o.jsx("tbody",{children:p.data?.items.map((I,A)=>o.jsxs("tr",{children:[o.jsxs("td",{children:[I.first_unfinished_step&&o.jsx(Te.Link,{to:`/${e}/operator/run/step/${I.first_unfinished_step.id}`,children:I.name}),I.first_unfinished_step===void 0&&I.last_finished_step&&o.jsx(Te.Link,{to:`/${e}/operator/run/step/${I.last_finished_step.id}`,children:I.name})]}),o.jsxs("td",{children:[I.priority&&o.jsx("span",{className:"badge",style:{backgroundColor:I.priority.priority.back_color,color:I.priority.priority.front_color},children:I.priority.priority.code}),!I.priority&&o.jsx("span",{className:"badge bg-info",children:"NORMAL"})]}),o.jsx("td",{children:I.hold_code&&o.jsx("span",{className:"badge handle",style:{backgroundColor:I.hold_code.hold_code.back_color,color:I.hold_code.hold_code.front_color},children:I.hold_code.hold_code.code})}),o.jsx("td",{children:I.batch_card&&I.batch_card.content&&o.jsx("span",{className:"text-danger",children:I.batch_card.content})}),o.jsx("td",{children:I.project.name})]},A))})]}),o.jsx(fU,{})]}),o.jsxs(Mt,{md:4,children:[o.jsx("h2",{children:"Assistance"}),y.data?.items.map((I,A)=>o.jsxs(x.Fragment,{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("h3",{children:I.type.is_main_tool?"Main tool":I.name}),o.jsx("div",{children:o.jsx(qi,{module:I})})]}),o.jsxs("div",{className:"pb-lg-5",children:[o.jsx("div",{className:"d-flex justify-content-between",children:o.jsxs("div",{className:"d-flex gap-2",children:[o.jsx("div",{children:o.jsx(de,{variant:"primary",size:"sm",onClick:k,children:"New Issue"})}),o.jsx("div",{children:o.jsx(de,{variant:"primary",size:"sm",onClick:C,children:"New ECN"})}),o.jsx("div",{children:I.type.is_main_tool&&o.jsx(l1,{size:"sm",moduleId:I.id})})]})}),w(I.id)?.map((F,P)=>o.jsx(dU,{ecn:F,equipment:t,ecnAttachments:b.data?.items??[],reloadQueryFn:R},`ecn-${A}-${P}`)),E(I.id)?.map((F,P)=>o.jsx(cU,{issue:F,equipment:t,issueAttachments:S.data?.items??[],reloadQueryFn:R},`issue-${A}-${P}`))]})]},A))]})]}),c&&l,s&&r]})}const mU=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&eg({id:parseInt(n)}).then(t)},[n,e]);function r(){eg({id:parseInt(n)}).then(t)}return{equipment:e,setEquipment:t,reloadEquipment:r}};function u1({children:e}){const{equipment:t,reloadEquipment:n}=mU();return t===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading Equipment"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading equipment"})})]})}):o.jsx(fc.Provider,{value:{equipment:t,reloadEquipment:n},children:e})}function hU(){const{equipment:e}=x.useContext(fc),t=Pe.useQueries({queries:[{queryKey:["activeReservationQuery",e],queryFn:()=>Tl({equipment:e,which:"active"})},{queryKey:["upcomingReservationQuery",e],queryFn:()=>Tl({equipment:e,which:"upcoming"})},{queryKey:["modules",e],queryFn:()=>Hi({equipment:e})}]}),[n,r,i]=t,s=t.some(l=>l.isLoading);t.some(l=>l.isError);const a=t.every(l=>l.isSuccess);return s?o.jsx("div",{children:"Loading..."}):(i.data?.items.findLast(l=>l.type.is_main_tool),a&&o.jsxs("div",{className:"d-flex align-items-center justify-content-between mb-3",children:[o.jsxs("h1",{className:"display-4",children:[e.name," Operator Dashboard"]}),o.jsxs("div",{children:[n.data?.items.map((l,u)=>o.jsxs("div",{className:"mx-2 p-2 rounded border-danger",style:{backgroundColor:l.color},children:[o.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Active reservation",o.jsx("br",{}),"Until ",Ln(l.end,"DD-MM-YY HH:mm")," by ",l.user.full_name]},u)),r.data?.items.map((l,u)=>o.jsxs("div",{className:"mx-2 p-2 rounded border-success border-2",style:{backgroundColor:l.color},children:[o.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Next reservation",o.jsx("br",{}),Ln(l.start,"DD-MM-YY HH:mm"),o.jsx("br",{}),l.user.full_name]},u))]})]}))}function gU(){return o.jsxs(u1,{children:[o.jsx(hU,{}),o.jsx(Te.Outlet,{})]})}function vU({children:e}){const{id:t}=Te.useParams(),n=Pe.useQuery({queryKey:["statusMail",t],queryFn:()=>sk({id:parseInt(t)}),enabled:!!t});return n.isLoading||n.isFetching?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading statusMail"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading status Mail"})})]})}):o.jsx(Xu.Provider,{value:{statusMail:n.data},children:e})}function xU(e){const[t,n]=x.useState(!0),[r,i]=x.useState(null),[s,a]=x.useState(!1),l=()=>{n(!1),a(!0)};return x.useEffect(()=>{if(!document){const p=new Error(`[ScriptLoadingError] document not defined when attempting to load ${e}`);i(p);return}const u=document.querySelector(`script[src="${e}"]`);if(u?.dataset.loaded){l();return}const c=u||document.createElement("script");u||(c.src=e);const d=()=>{c.dataset.loaded="1",l()};c.addEventListener("load",d),c.addEventListener("error",p=>{console.error("Failed to load script:",e,p);const h=new Error(`[ScriptLoadingError] Failed to load script: ${e}`);i(h)}),u||document.head.append(c)},[]),{isLoading:t,error:r,isSuccess:s}}const yU=e=>e&&e.charts,uy=(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)},bU=e=>window.google;function wU(e){const{chartVersion:t="current",chartPackages:n=["corechart","controls"],chartLanguage:r="en",mapsApiKey:i}=e,[s,a]=x.useState(null),[l,u]=x.useState(null),[c,d]=x.useState(null),{isLoading:p,error:h,isSuccess:m}=xU(e.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return x.useEffect(()=>{if(!m)return;const g=bU();if(!yU(g)){const y=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");u(y);return}if(uy(e,g)){a(g);return}g.charts.load(t,{packages:n,language:r,mapsApiKey:i}),g.charts.setOnLoadCallback(()=>{if(!uy(e,g)){const y=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(y),d(y);return}a(g)})},[m]),{error:h||l||c,isLoading:p,google:s}}const c1={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},SU=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:s,control:a}=i;return r?r({control:a,controlProp:s}):!0}).map(i=>{let{control:s}=i;return x.createElement("div",{key:s.getContainerId(),id:s.getContainerId()})}))};let cy=0;const d1=()=>(cy+=1,`reactgooglegraph-${cy}`),vr=class vr{};tr(vr,"initializeControls",t=>{for(let n=0;n<t.length;n+=1){const{controlType:r,options:i,controlWrapperParams:s}=t[n].controlProp;s&&"state"in s&&t[n].control.setState(s.state),t[n].control.setOptions(i),t[n].control.setControlType(r)}}),tr(vr,"listenToControlEvents",(t,n)=>{const{google:r}=n;return t.flatMap(i=>{const{control:s,controlProp:a}=i,{controlEvents:l=[]}=a;return l.map(u=>{const{callback:c,eventName:d}=u;return r.visualization.events.addListener(s,d,function(){for(var p=arguments.length,h=new Array(p),m=0;m<p;m++)h[m]=arguments[m];c({chartWrapper:null,controlWrapper:s,props:n,google:r,eventArgs:h})})})})}),tr(vr,"createControlId",t=>{let n;return typeof t>"u"?n=`googlechart-control-${d1()}`:n=t,n}),tr(vr,"createChartControls",t=>{const{controls:n,google:r}=t;return n?n.map((i,s)=>{const{controlID:a,controlType:l,options:u,controlWrapperParams:c}=i,d=vr.createControlId(a);return{controlProp:i,control:new r.visualization.ControlWrapper({containerId:d,controlType:l,options:u,...c})}}):null}),tr(vr,"addControls",t=>{const{chartWrapper:n,chartDashboard:r}=t,i=vr.createChartControls(t);return!i||!r||!n?null:(r.bind(i.map(s=>{let{control:a}=s;return a}),n),vr.initializeControls(i),i)});let pu=vr;const CU=e=>{const[t,n]=$.useState(null);return[$.useMemo(()=>!t||!e?null:e.map((i,s)=>{const a=t[s];return a?{controlProp:i,control:a}:void 0}).flatMap(i=>i?[i]:[]),[t,e]),n]},_U=(e,t)=>{$.useEffect(()=>{const n=pu.listenToControlEvents(e??[],t);return()=>{n.forEach(r=>{t.google.visualization.events.removeListener(r)})}},[e,t])},EU=e=>{const[t,n]=CU(e.controls);return _U(t??[],e),{addControls:i=>{const s=pu.addControls(i);n(s?.map(a=>a.control)??null)},renderControl:i=>{const{chartWrapper:s,chartDashboard:a}=e;return $.createElement(SU,{...e,isReady:!!(s&&a),chartControls:t,filter:i})}}},IU=e=>{const t=$.useRef(null);return{chartId:(()=>{const{graphID:i,graph_id:s}=e,a=i||s;let l;return a?l=a:l=t.current||d1(),t.current=l,t.current})()}},jU=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],RU=async function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((r,i)=>{const s=`${n.headers?`headers=${n.headers}`:"headers=0"}`,a=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,l=`${n.gid?`&gid=${n.gid}`:""}`,u=`${n.sheet?`&sheet=${n.sheet}`:""}`,c=`${n.access_token?`&access_token=${n.access_token}`:""}`,d=`${s}${l}${u}${a}${c}`,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())})})},kU="#CCCCCC",Gn=class Gn{};tr(Gn,"grayOutHiddenColumnsLabel",(t,n)=>{const{googleChartWrapper:r,options:i}=t;if(!r){console.error("googleChartWrapper is not defined");return}const s=r.getDataTable();if(!s)return;const a=s.getNumberOfColumns();if(n.length>0===!1)return;const u=Array.from({length:a-1}).map((c,d)=>{const p=Gn.getColumnId(s,d+1);return n.includes(p)?kU:i&&i.colors?i.colors[d]:jU[d]});r.setOptions({...i,colors:u}),r.draw()}),tr(Gn,"listenToLegendToggle",(t,n)=>{const[r,i]=n,{google:s,googleChartWrapper:a}=t;if(!a){console.error("googleChartWrapper is not defined");return}return s.visualization.events.addListener(a,"select",()=>{const u=a.getChart().getSelection(),c=a.getDataTable();if(u.length===0||u[0].row!==null||!c)return;const d=u[0].column,p=Gn.getColumnId(c,d);r?.includes(p)?i(h=>[...h.filter(m=>m!==p)]):i(h=>[...h,p])})}),tr(Gn,"draw",async t=>{const{data:n,diffdata:r,rows:i,columns:s,options:a,chartType:l,formatters:u,spreadSheetUrl:c,spreadSheetQueryParameters:d,googleChartDashboard:p,googleChartWrapper:h,google:m,hiddenColumns:g,legendToggle:y,legend_toggle:b}=t;if(!h){console.error("draw was called with googleChartWrapper = null");return}let S,R=null;if(r){const I=m.visualization.arrayToDataTable(r.old),A=m.visualization.arrayToDataTable(r.new);R=m.visualization[l].prototype.computeDiff(I,A)}n?n instanceof m.visualization.DataTable?S=n:Array.isArray(n)?S=m.visualization.arrayToDataTable(n):S=new m.visualization.DataTable(n):i&&s?S=m.visualization.arrayToDataTable([s,...i]):c?S=await RU(m,c,d):S=m.visualization.arrayToDataTable([]);const w=S.getNumberOfColumns(),E=Array(w).fill(0).map((I,A)=>{const F=Gn.getColumnId(S,A);return g.includes(F)?{label:S.getColumnLabel(A),type:S.getColumnType(A),calc:()=>null}:A}),C=h.getChart();h.getChartType()==="Timeline"&&C&&C.clearChart(),h.setChartType(l),h.setOptions(a||{});const k=new m.visualization.DataView(S);k.setColumns(E),h.setDataTable(k),h.draw(),p&&p.draw(S),R&&(h.setDataTable(R),h.draw()),u&&(Gn.applyFormatters({dataTable:S,formatters:u,google:m}),h.setDataTable(S),h.draw()),(y===!0||b===!0)&&Gn.grayOutHiddenColumnsLabel(t,g)}),tr(Gn,"getColumnId",(t,n)=>t.getColumnId(n)||t.getColumnLabel(n)),tr(Gn,"applyFormatters",t=>{let{dataTable:n,formatters:r,google:i}=t;for(let s of r)switch(s.type){case"ArrowFormat":{new i.visualization.ArrowFormat(s.options).format(n,s.column);return}case"BarFormat":{new i.visualization.BarFormat(s.options).format(n,s.column);return}case"ColorFormat":{const a=new i.visualization.ColorFormat(s.options),{ranges:l}=s;if(l)for(let u of l)a.addRange(...u);a.format(n,s.column);return}case"DateFormat":{new i.visualization.DateFormat(s.options).format(n,s.column);return}case"NumberFormat":{new i.visualization.NumberFormat(s.options).format(n,s.column);return}case"PatternFormat":{new i.visualization.PatternFormat(s.options).format(n,s.column);return}default:{console.warn(`Unknown formatter type: ${s.type}`);return}}});let La=Gn;const AU=e=>{const{google:t,googleChartWrapper:n,googleChartDashboard:r}=e,[i,s]=$.useState([]);$.useEffect(()=>{n&&La.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 a=()=>{const{googleChartWrapper:c}=e;c&&c.draw()},l=c=>{const d=[],{legendToggle:p,legend_toggle:h}=e;if(La.draw({...e,hiddenColumns:i,googleChartWrapper:c,googleChartDashboard:r,google:t}),window.addEventListener("resize",a),h||p){const m=La.listenToLegendToggle(e,[i,s]);m&&d.push(m)}return d},u=(c,d)=>{window.removeEventListener("resize",a),d.forEach(p=>{t.visualization.events.removeListener(p)}),c.getChartType()==="Timeline"&&c.getChart()&&c.getChart().clearChart()};$.useEffect(()=>{if(!n)return;const c=l(n);return()=>{u(n,c)}},[n,l,u])},NU=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:s,callback:a}=i;return n.visualization.events.addListener(r,s,function(){for(var l=arguments.length,u=new Array(l),c=0;c<l;c++)u[c]=arguments[c];a({chartWrapper:r,props:e,google:n,eventArgs:u})})})}},OU=e=>{x.useEffect(()=>{if(!e.googleChartWrapper)return;const t=NU(e);return()=>{t?.forEach(n=>{e.google.visualization.events.removeListener(n)})}},[e])},DU=e=>{const[t,n]=$.useState(null),[r,i]=$.useState(null),{addControls:s,renderControl:a}=EU({...e,chartDashboard:r,chartWrapper:t});OU({...e,googleChartWrapper:t});const{chartId:l}=IU(e),u=$.useRef(null),c=$.useRef(null);$.useEffect(()=>{const{options:S,google:R,chartType:w,chartWrapperParams:E,toolbarItems:C,getChartEditor:k,getChartWrapper:I,onLoad:A}=e,F={chartType:w,options:S,containerId:l,...E},P=new R.visualization.ChartWrapper(F);P.setOptions(S||{}),I?.(P,R);const B=new R.visualization.Dashboard(u.current);C&&R.visualization.drawToolbar(c.current,C);let V=null;k&&(V=new R.visualization.ChartEditor,k({chartEditor:V,chartWrapper:P,google:R})),s({...e,chartDashboard:B,chartWrapper:P}),n(P),i(B),A?.(R,{google:R,chartWrapper:P,chartEditor:V,chartDashboard:B})},[]),AU({...e,googleChartWrapper:t,googleChartDashboard:r});const d=()=>{const{width:S,height:R,options:w,style:E,className:C,rootProps:k,google:I}=e,A={height:R||w&&w.height,width:S||w&&w.width,...E};return $.createElement("div",{id:l,style:A,className:C,...k})},p=()=>e.toolbarItems?$.createElement("div",{ref:c}):null,{width:h,height:m,options:g,style:y}=e,b={height:m||g&&g.height,width:h||g&&g.width,...y};return e.render?$.createElement("div",{ref:u,style:b},$.createElement("div",{ref:c,id:"toolbar"}),e.render({renderChart:d,renderControl:a,renderToolbar:p})):$.createElement("div",{ref:u,style:b},a(S=>{let{controlProp:R}=S;return R.controlPosition!=="bottom"}),d(),a(S=>{let{controlProp:R}=S;return R.controlPosition==="bottom"}),p())},MU=$.createContext(c1),FU=e=>{let{children:t,value:n}=e;return $.createElement(MU.Provider,{value:n},t)},TU=e=>{const{google:t,isLoading:n,error:r}=wU(e);return n?e.loader??null:r?e.errorElement??null:t?x.createElement(DU,{google:t,...e}):null},PU=e=>{const t={...c1,...e};return x.createElement(FU,{value:t},x.createElement(TU,t))};var dy;(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"})(dy||(dy={}));function LU({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(s=>{s.values.filter(a=>a.logging_parameter.id===e.logging_parameter.id).filter(a=>a.float_value!==0).forEach(a=>{let l=new Date(s.date_created);r.push([l,a.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?o.jsx("div",{className:"text-center",children:"No data available"}):o.jsx(PU,{chartType:"ScatterChart",width:"100%",height:"400px",data:r,options:n})}const Oo=({data:e,setPage:t,setPageSize:n,pageSize:r,isPlaceholderData:i})=>{if(e===void 0||i)return o.jsx(o.Fragment,{});let s=[];for(let a=1;a<=e.amountOfPages;a++)s.push(o.jsx($g.Item,{active:a===e.currentPage,onClick:()=>t(l=>a),children:a},a));return o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs("div",{className:"d-flex gap-2",children:[o.jsx("div",{children:o.jsx(de,{size:"sm",onClick:()=>t(a=>Math.max(a-1,0)),disabled:e.currentPage===1,children:"Previous Page"})}),o.jsx($g,{size:"sm",children:s.map((a,l)=>o.jsx("div",{children:a},l))}),o.jsx("div",{children:o.jsx(de,{size:"sm",onClick:()=>{!i&&e.hasMore&&t(a=>a+1)},disabled:i||!e.hasMore,children:"Next Page"})})]}),n!==void 0?o.jsx("div",{children:o.jsxs(H.Select,{onChange:a=>{n(l=>parseInt(a.target.value))},value:r,size:"sm",children:[o.jsx("option",{value:10,children:"10"}),o.jsx("option",{value:25,children:"25"}),o.jsx("option",{value:50,children:"50"}),o.jsx("option",{value:100,children:"100"})]})}):null]})},VU=new Date().toISOString().split("T")[0],BU=({requirement:e,targets:t,refetchResults:n})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(!1),[l,u]=x.useState(!1),{control:c,register:d,handleSubmit:p,reset:h,watch:m,formState:{errors:g,isValid:y}}=gn({defaultValues:{date:VU}}),{fields:b,append:S,remove:R}=jD({control:c,name:"results",rules:{required:!0}});x.useEffect(()=>{R(),t.forEach(k=>{S({id:k.id,label:k.logging_parameter.name,logging_parameter_id:k.logging_parameter.id,value:""})})},[t]);const w=m();x.useEffect(()=>{u(y)},[w,y]);async function E(k){await Ee.post("create/monitor/requirement/result",{requirement:e.id,date:k.date,values:k.results}),a(!0),i(!1),n(),h()}function C(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>a(!1),show:s,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Results saved"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Measurement results were saved successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"primary",onClick:()=>i(!0),children:"Add manual result"}),o.jsx(xe,{show:r,size:"lg",onHide:()=>i(!1),children:o.jsxs(H,{onSubmit:p(k=>E(k)),validated:l,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Add manual result"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Date"}),o.jsx(H.Control,{type:"date",placeholder:"Date",required:!0,...d("date",{required:"This field is required"})},"date"),g.date&&o.jsx(H.Control.Feedback,{children:g.date.message})]}),b.map((k,I)=>o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:k.label}),o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{type:"number",step:.01,placeholder:k.label,required:!0,...d(`results.${I}.value`,{required:"This field is required"})},k.id),g?.results?.[I]?.value&&o.jsx(H.Control.Feedback,{children:g.results[I].value.message})]})]},I))]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{h(),i(!1)},children:"Close"})]})]})}),o.jsx(C,{})]})},GU=({requirement:e,result:t,refetchMonitorStepParameterValues:n})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(!1),[l,u]=x.useState(!1),[c,d]=x.useState([]),{control:p,register:h,handleSubmit:m,reset:g,watch:y,formState:{errors:b,isValid:S}}=gn({defaultValues:{}});x.useEffect(()=>{async function C(){const k=await $y({result:t}),I=await vk({requirement:e}),A=await uk({module:e.step.process_module.module});I.items=I.items.filter(F=>!k.items.map(P=>P.step_parameter.id).includes(F.id)),I.items=I.items.filter(F=>A.items.map(P=>P.parameter.id).includes(F.parameter.id)),d(I.items)}r&&C()},[r]);const R=y();x.useEffect(()=>{u(S)},[R,S]);async function w(C){await Ee.post("create/monitor/requirement/result/step-parameter-value",{result:t.id,step_parameter:C.module_step_parameter_id,value:C.value}),a(!0),i(!1),n(),g()}function E(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>a(!1),show:s,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Results saved"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Measurement results were saved successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"primary",size:"sm",onClick:()=>i(!0),children:"+"}),o.jsx(xe,{show:r,size:"lg",onHide:()=>i(!1),children:o.jsxs(H,{onSubmit:m(C=>w(C)),validated:l,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Add process parameter"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Date"}),o.jsx(H.Control,{type:"text",value:t.date_created,readOnly:!0})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Module Step Parameter"}),o.jsxs(H.Select,{...h("module_step_parameter_id",{required:!0}),children:[o.jsx("option",{value:"",children:"— Select a parameter"}),c.map(C=>o.jsx("option",{value:C.id,children:C.parameter.name},C.id))]}),o.jsx(H.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"})]}),o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{type:"number",step:.01,required:!0,...h("value",{required:"This field is required"})}),b?.value&&o.jsx(H.Control.Feedback,{children:b.value.message})]})]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{g(),i(!1)},children:"Close"})]})]})}),o.jsx(E,{})]})},zU=({monitorResultStepParameterValue:e,refetchMonitorStepParameterValues:t})=>{const[n,r]=x.useState(!1),[i,s]=x.useState(!1),[a,l]=x.useState(!1),{control:u,register:c,handleSubmit:d,reset:p,watch:h,formState:{errors:m,isValid:g}}=gn({defaultValues:{value:e.value.toString()}}),y=h();x.useEffect(()=>{l(g)},[y,g]);async function b(w){await Ee.patch("update/monitor/requirement/result/step-parameter-value/"+e.id,{value:w.value}),s(!0),r(!1),t(),p()}async function S(){await Ee.delete("delete/monitor/requirement/result/step-parameter-value/"+e.id,{}),s(!0),r(!1),t(),p()}function R(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>s(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Results saved"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Measurement results were saved successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx("span",{onClick:()=>r(!0),children:e.value}),o.jsx(xe,{show:n,size:"lg",onHide:()=>r(!1),children:o.jsxs(H,{onSubmit:d(w=>b(w)),validated:a,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Add process parameter"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Date"}),o.jsx(H.Control,{type:"text",value:e.date_created,readOnly:!0})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Module Step Parameter"}),o.jsx(H.Control,{type:"text",value:e.step_parameter.parameter.name,readOnly:!0})]}),o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{type:"number",step:.01,required:!0,...c("value",{required:"This field is required"})}),m?.value&&o.jsx(H.Control.Feedback,{children:m.value.message})]})]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",type:"submit",variant:"primary",children:"Update value"}),o.jsx(de,{className:"float-end",variant:"danger",onClick:()=>S(),children:"Delete value"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{p(),r(!1)},children:"Close"})]})]})}),o.jsx(R,{})]})};function YU({requirement:e}){const[n,r]=x.useState([]),[i,s]=x.useState(""),[a,l]=x.useState(1),[u,c]=x.useState(15),[d,p]=x.useState([]),[h,m,g,y]=Pe.useQueries({queries:[{queryKey:["requirement","files",e.step,11],queryFn:()=>gk({step:e.step,pageSize:11,order:"date-created",direction:"desc"})},{queryKey:["requirement","target",e],queryFn:()=>hk({requirement:e})},{queryKey:["requirement","results",e,a,u],queryFn:()=>mk({requirement:e,pageSize:u,order:"date-created",direction:"desc",page:a}),placeholderData:Pe.keepPreviousData},{queryKey:["requirement","monitor_step_parameters",e,a,u],queryFn:()=>$y({requirement:e,pageSize:u,order:"date-created",direction:"desc",page:a}),placeholderData:Pe.keepPreviousData}]});x.useEffect(()=>{r([]),!h.isLoading&&h.data.items.forEach(I=>{r(A=>[...A,I])})},[h.isLoading]),x.useEffect(()=>{if(!y.data)return;const I=Array.from(new Map(y.data.items.map(A=>[A.step_parameter.id,A.step_parameter])).values());p(I)},[y.isLoading,y.data]);const b=x.useCallback(I=>{I.forEach(A=>{const F=new FileReader;F.onload=async()=>{const P=F.result;try{await Ee.create().post("update/monitor/requirement/upload-file/"+e.id,{content:P,filename:A.name,type:A.type})}catch(B){s("Upload failed due to: "+B.response.data.detail)}await h.refetch(),await g.refetch()},F.readAsDataURL(A)})},[e.id,h,g]),{getRootProps:S,getInputProps:R,isDragActive:w,isDragAccept:E,isDragReject:C}=Co({onDrop:b}),k=x.useMemo(()=>({...w?{borderColor:"#83afee"}:{},...E?{borderColor:"#00e676"}:{},...C?{borderColor:"#ff1744"}:{}}),[E,C,w]);return m.isLoading||m.isFetching?o.jsx(Bt,{variant:"info",children:"Loading targets..."}):g.isLoading||g.isFetching?o.jsx(Bt,{variant:"info",children:"Loading results..."}):o.jsxs(o.Fragment,{children:[o.jsxs("h1",{className:"display-5",children:["Requirement: ",e.title]}),o.jsx("p",{className:"lead",children:e.definition}),o.jsx(Un,{className:"my-3",children:o.jsxs(Mt,{children:[o.jsx("h2",{children:"Charts"}),o.jsx("div",{className:"d-flex",children:m.data?.items.map((I,A)=>o.jsx(LU,{target:I,results:g.data.items},A))})]})}),o.jsxs(Un,{children:[o.jsxs(Mt,{md:8,children:[e.method&&e.method!=="-"&&o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:"Method"}),o.jsx("p",{children:e.method})]}),m.data?.items.length===0&&o.jsx(Bt,{variant:"danger",children:"No targets found"}),o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("h2",{children:"Results"}),o.jsx("div",{children:o.jsx(BU,{requirement:e,targets:m.data.items,refetchResults:g.refetch})})]}),o.jsxs(Kt,{size:"sm",striped:!0,bordered:!0,hover:!0,children:[o.jsxs("thead",{children:[o.jsxs("tr",{children:[o.jsx("th",{children:"ID"}),o.jsx("th",{children:"Date"}),m.data?.items.map((I,A)=>o.jsx("th",{children:I.logging_parameter.name},A)),d.map((I,A)=>o.jsx("th",{children:I.parameter.name},A)),o.jsx("th",{children:"+"})]}),o.jsxs("tr",{children:[o.jsx("th",{colSpan:2}),m.data?.items.map((I,A)=>o.jsxs("td",{children:[I.min_value,I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:"≤"}),!I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:"<"}),I.target??"X",I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:"≥"}),!I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:">"}),I.max_value]},A)),d.map((I,A)=>o.jsx("th",{className:"table-secondary"},A)),o.jsx("th",{})]})]}),o.jsx("tbody",{children:g.data?.items.map((I,A)=>o.jsxs("tr",{children:[o.jsx("th",{children:o.jsx("small",{className:"text-muted",children:I.id})},A),o.jsx("td",{children:Ln(I.date_created,"DD-MM-YY HH:mm")}),m.data?.items.map((F,P)=>o.jsx("td",{children:I.values.filter(B=>B.logging_parameter.id===F.logging_parameter.id).map((B,V)=>o.jsx("span",{className:B.value_is_valid?"text-success":"text-danger",children:B.float_value},V))},P)),d.map((F,P)=>o.jsx("td",{className:"table-secondary",children:y.data?.items.filter(B=>B.step_parameter.id===F.id&&B.result.id===I.id).map((B,V)=>o.jsx(zU,{monitorResultStepParameterValue:B,refetchMonitorStepParameterValues:y.refetch},V))},P)),o.jsx("td",{children:o.jsx(GU,{result:I,requirement:e,refetchMonitorStepParameterValues:y.refetch})})]},A))})]}),o.jsx(Oo,{data:g.data,setPage:l,setPageSize:c,pageSize:u,isPlaceholderData:g.isPlaceholderData})]}),o.jsxs(Mt,{md:4,children:[o.jsx("h2",{children:"Upload new results"}),o.jsx("p",{children:"Drop your results file here"}),o.jsxs("div",{...S({style:k,className:"dropzone"}),children:[o.jsx("input",{...R()}),w?o.jsx("p",{children:"Drop file(s) here ..."}):o.jsx("p",{children:"Drag and drop file(s) here, or click to select files"}),o.jsx("p",{children:i})]}),n.length>0&&o.jsxs(o.Fragment,{children:[o.jsx("h2",{className:"mt-2",children:"Uploaded files"}),o.jsxs("p",{children:["Last ",11," uploaded files"]}),o.jsx("ul",{className:"list-group",children:n.map((I,A)=>o.jsxs("li",{className:"list-group-item",children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs("span",{children:[A+1," ",o.jsx("a",{href:lm()+I.url,children:I.name}),I.has_monitor_step_loggings&&o.jsx(hn,{className:"ms-1 bg-primary",children:"Logging"})]}),o.jsxs("span",{children:[Math.round(I.size/1024),"kiB"]})]}),o.jsx("small",{className:"text-muted",children:Ln(I.date_created,"DD-MM-YY HH:mm")})]},A))})]})]})]})]})}function HU(){let{id:e}=Te.useParams();const[t,n]=Pe.useQueries({queries:[{queryKey:["monitor",e],queryFn:()=>Xd({id:parseInt(e)})},{queryKey:["requirements",e],queryFn:()=>Yy({monitorId:parseInt(e)})}]});return t.isLoading?o.jsx("div",{children:"Loading..."}):o.jsxs("div",{children:[o.jsxs("h1",{className:"display-4",children:["SPC Test ",t.data?.name]}),n.data?.items.map((r,i)=>o.jsx("div",{className:"border border-1 p-3 my-3",children:o.jsx(YU,{requirement:r})},i))]})}function $U(){return o.jsx(es,{fluid:!0,children:o.jsx(Te.Outlet,{})})}const WU=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&Xd({id:parseInt(n)}).then(t)},[n,e]);function r(){Xd({id:parseInt(n)}).then(t)}return{monitor:e,setMonitor:t,reloadMonitor:r}},f1=x.createContext({monitor:{},reloadMonitor:()=>{}});function UU({children:e}){const{monitor:t,reloadMonitor:n}=WU();return t===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading Monitor"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading monitor"})})]})}):o.jsx(f1.Provider,{value:{monitor:t,reloadMonitor:n},children:e})}const qU=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{(e===null||n!==e.id.toString())&&Pl({id:parseInt(n)}).then(t)},[n,e]);function r(){Pl({id:parseInt(n)}).then(t)}return{run:e,reloadRun:r}},as=x.createContext({run:{},reloadRun:()=>{}});function p1({children:e}){const{run:t,reloadRun:n}=qU();return t===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading run"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading run"})})]})}):o.jsx(as.Provider,{value:{run:t,reloadRun:n},children:e})}function XU({text:e}){if(!e)return null;const t=e.split(/\r\n|\n|\r/);return o.jsx(o.Fragment,{children:t.map((n,r)=>o.jsxs(x.Fragment,{children:[n,r<t.length-1&&o.jsx("br",{})]},r))})}const Zi=({children:e,format:t="d-M-Y"})=>{const n=Date.parse(e);return o.jsx(o.Fragment,{children:ye(n).format(t)})},m1=({run:e})=>{const[t,n]=x.useState(e.batch_card),[r,i]=x.useState(!1),{register:s,handleSubmit:a,formState:l,resetField:u}=gn({defaultValues:{content:t?.content}}),{isSubmitting:c,errors:d}=l,p=async m=>{await Ee.create().patch("update/run/batch-card/"+e.id,{content:m.content}),i(!1);const g=await Ee.get("view/run/"+e.id);n(g.data.batch_card)},h=async m=>{await Ee.create().delete("delete/run/batch-card/"+e.id),i(!1),n(void 0),u("content")};return r?o.jsxs(H,{onSubmit:a(p),className:"mb-3",children:[o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{as:"textarea",rows:6,...s("content",{required:!0}),isInvalid:d.content!==void 0}),d.content&&o.jsx(H.Control.Feedback,{type:"invalid",children:"This field is required"})]}),o.jsxs("div",{className:"d-flex gap-2 justify-content-between mt-2",children:[o.jsxs("div",{children:[o.jsxs(de,{variant:"primary",type:"submit",disabled:c,children:[c&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save batch card"]}),o.jsx(de,{variant:"secondary",className:"ms-2",onClick:()=>i(!1),children:"Cancel"})]}),t&&o.jsx("div",{children:o.jsx(de,{variant:"danger",className:"ms-auto",onClick:()=>h(),children:"Delete batch card"})})]})]}):t?t&&o.jsxs(Ze,{className:"rounded my-4",children:[o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{className:"text-muted",children:"Batch card"}),o.jsx(Ze.Text,{children:t&&o.jsx("span",{className:"text-danger fs-3",children:o.jsx(XU,{text:t.content})})})]}),o.jsxs(Ze.Footer,{className:"d-flex justify-content-between align-items-center",children:[o.jsxs("div",{children:["Created by ",t.user.first_name," ",t.user.last_name," on"," ",o.jsx(Zi,{format:"DD-MM-YY",children:t.date_created}),t.last_update&&o.jsxs("span",{children:[" ","- Updated on ",o.jsx(Zi,{format:"DD-MM-YY H:m",children:t.last_update})]})]}),o.jsx("div",{children:o.jsx(de,{variant:"primary",size:"sm",onClick:()=>i(!0),children:"Update Batch Card"})})]})]}):o.jsx(de,{variant:"primary",className:"mb-4",onClick:()=>i(!0),children:"Create Batch Card"})};function ZU(){const{run:e}=x.useContext(as);return o.jsxs(o.Fragment,{children:[e.run_type===Hn.RESEARCH&&o.jsx("small",{children:"Research run"}),e.run_type===Hn.PRODUCTION&&o.jsx("small",{children:"Production run"}),o.jsx("div",{className:"d-flex justify-content-between align-items-center mb-3",children:o.jsxs("h1",{className:"display-4",children:[e.name," (",e.project.name,")"]})}),o.jsx(m1,{run:e})]})}function JU(e){const{run:t,reloadRun:n}=x.useContext(as),{environment:r}=Te.useParams(),i=window.location.pathname;let s=[{title:"Information",link:`/${r}/operator/run/details/${t.id}/information`}];return s.push({title:"Steps",link:`/${r}/operator/run/details/${t.id}/steps`}),o.jsx(zg,{variant:"tabs",className:e.className,defaultActiveKey:"/home",activeKey:i,children:s.map((a,l)=>o.jsx(zg.Item,{children:o.jsx(Te.Link,{to:a.link,className:"nav-link "+(a.link===i?"active":""),children:a.title})},l))})}function QU(){return o.jsx(p1,{children:o.jsxs(es,{fluid:!0,children:[o.jsx(ZU,{}),o.jsx(JU,{className:"mb-4"}),o.jsx(Te.Outlet,{})]})})}const pc=x.createContext({showOnlyEmphasizedParameters:!1,setShowOnlyEmphasizedParameters:()=>{}}),KU=({parameter:e,value:t,refetchFn:n})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(t.value),l=async u=>{const c={value:u};try{t.id!==void 0?await Ee.patch(`/update/run/step/parameter/value/${t.id}`,c):(c.parameter=e.id,await Ee.post("/create/run/step/parameter/value",c))}catch(d){console.error("Failed to update parameter value with error: ",d)}n(),i(!1)};return o.jsxs(o.Fragment,{children:[o.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"}),o.jsxs("div",{style:{display:r?"":"none"},className:"btn-group",children:[o.jsx("input",{type:"text",value:s??"",className:"form-control",onChange:u=>a(u.target.value)}),o.jsx("button",{onClick:()=>{l(s)},className:"btn btn-success btn-sm",children:o.jsx("i",{className:"fa fa-check"})}),o.jsx("button",{onClick:()=>{i(!1)},className:"btn btn-danger btn-sm",children:o.jsx("i",{className:"fa fa-times"})})]})]})},qm=({runStep:e,showOnlyEmphasizedParameters:t,editableParameters:n=!0,refetchFn:r})=>{const{data:i,isLoading:s}=Pe.useQuery({queryKey:["runStepParameters",e.id],queryFn:()=>Sk({runStep:e})}),a=Pe.useQueryClient(),l=()=>{a.refetchQueries({queryKey:["runStepParameters",e.id]}),r&&r()},u=i?.items??[],c=t?u.filter(d=>d.emphasize):u;return s?o.jsx("div",{children:"Loading..."}):u.length===0?o.jsx(Bt,{variant:"info",children:"No parameters found"}):o.jsxs(Kt,{children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Pos"}),o.jsx("th",{children:"Parameter"}),u[0].values.map((d,p)=>o.jsx("th",{children:"Value"},p)),o.jsx("th",{children:"Unit"})]})}),o.jsx("tbody",{children:c.length>0?c.map(d=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("small",{className:"text-muted",children:d.sequence})}),o.jsx("td",{children:d.parameter.name}),d.values.map((p,h)=>o.jsx("td",{children:n?o.jsx(KU,{parameter:d,refetchFn:l,value:p}):o.jsx("span",{children:p.value})},h)),o.jsx("td",{children:d.unit?.abbr??""})]},d.id)):o.jsx("tr",{children:o.jsx("td",{colSpan:3+u[0].values.length,children:"No emphasized parameters found."})})})]})},e9=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 Xm({runStep:e,refetchFn:t}){const[n,r]=x.useState([]),[i,s]=x.useState(""),{data:a,isLoading:l}=Pe.useQuery({queryKey:["files",e.id],queryFn:()=>wk({step:e})}),u=Pe.useQueryClient(),c=()=>{u.refetchQueries({queryKey:["files",e.id]}),t&&t()},d=a?.items??[],p=async E=>{if(confirm(`Are you sure you want to delete ${E.name}? You can not undo this action`))try{await Ee.delete(`delete/run/step/file/${E.id}`),c()}catch(C){console.error(C)}},h=E=>{r(C=>[...C,...E]),s(`${E.length} file(s) selected`)},{getRootProps:m,getInputProps:g,isDragActive:y,isDragAccept:b,isDragReject:S}=Co({onDrop:h}),R=x.useMemo(()=>({...y?{borderColor:"#83afee"}:{},...b?{borderColor:"#00e676"}:{},...S?{borderColor:"#ff1744"}:{}}),[b,S,y]),w=()=>{n.forEach(E=>{const C=new FileReader;C.onload=async()=>{const k=C.result;try{await Ee.create().post("update/run/step/upload-file/"+e.id,{content:k,filename:E.name,type:E.type})}catch(I){s("Upload failed due to: "+I.response.data.detail)}try{c(),s("Files uploaded succesfully"),r([])}catch(I){s("Error refetching file data"),console.error(I)}},C.readAsDataURL(E)})};return l?o.jsx("div",{children:"Loading..."}):o.jsxs("div",{children:[d&&d.length>0&&o.jsxs(Kt,{hover:!0,striped:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"No"}),o.jsx("th",{children:"File"}),o.jsx("th",{children:"Size"}),o.jsx("th",{children:"Date"})]})}),o.jsx("tbody",{children:d.map((E,C)=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("small",{className:"text-muted",children:C+1})}),o.jsxs("td",{children:[o.jsx("a",{href:`${lm()}${E.url}`,children:E.name}),E.has_run_step_loggings&&o.jsx(hn,{className:"ms-1 bg-primary",children:"Logging"})]}),o.jsxs("td",{children:[o.jsx("i",{className:"fa fa-trash-o remove-file handle",style:{cursor:"pointer"},onClick:()=>p(E)})," ",e9(E.size)]}),o.jsx("td",{children:Ln(E.date_created,"DD-MM-YY HH:mm")})]},C))})]}),o.jsxs("div",{...m({style:R,className:"dropzone bg-secondary-subtle border rounded dz-clickable"}),children:[o.jsx("input",{...g()}),y?o.jsx("p",{children:"Drop files here..."}):o.jsx("p",{children:"Drag and drop files here or click to select"})]}),n.length>0&&o.jsx(Wn,{className:"mt-3",children:n.map((E,C)=>o.jsx(Wn.Item,{children:E.name},C))}),o.jsx(de,{className:"mt-3",onClick:w,disabled:n.length===0,children:"Upload Selected Files"}),o.jsx("p",{className:"mt-2 text-muted",children:i})]})}const Kf=({runStepPart:e,setRunStepPart:t,editable:n=!0})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(e.comment),{register:l,handleSubmit:u,formState:c,resetField:d}=gn({defaultValues:{comment:s}}),{isSubmitting:p,errors:h}=c,m=async g=>{await Ee.create().patch("update/run/step/part/"+e.id,{comment:g.comment}).then(y=>{t({...e,comment:y.data.comment}),a(y.data.comment),i(!1)})};return n?r?o.jsxs(H,{onSubmit:u(m),children:[o.jsx(H.Group,{className:"mb-3",controlId:"formBasicEmail",children:o.jsx(H.Control,{as:"textarea",...l("comment")})}),o.jsx(de,{size:"sm",type:"submit",disabled:p,children:"Save"}),o.jsx(de,{variant:"warning",size:"sm",className:"ms-2",onClick:()=>i(!1),children:"Cancel"})]}):s===null?o.jsx(de,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Add comment"}):o.jsxs("div",{className:"d-flex align-items-start gap-2",children:[o.jsx("div",{className:"text-break",children:s}),o.jsx(de,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Edit"})]}):o.jsx("div",{children:s})},t9=({runStepPart:e,editable:t=!0,reloadFn:n,partIsSelected:r,setPartAsSelected:i})=>{const[s,a]=x.useState(e);x.useEffect(()=>{a(e)},[e]);const l=s.latest_action?.type.id===Ge.FINISH_PROCESSING,u=s.latest_action?.type.id===Ge.FAILED_PROCESSING,c=({runStepPart:d,runStepPartAction:p})=>{Su({runStepPart:d,runStepPartAction:p}).then(h=>{a({...d,latest_action:h,actions:d.actions+1})}).then(()=>{n&&n()})};return e.part_processing_failed_in_previous_step?o.jsxs("tr",{className:"table-danger",children:[o.jsxs("td",{children:[e.part.short_label,e.part.label&&e.part.label.trim().length>0?` (${e.part.label})`:""]}),o.jsx("td",{colSpan:t?3:2,children:o.jsx("span",{children:"Processing failed in a previous step"})}),o.jsx("td",{children:o.jsx(Kf,{runStepPart:e,setRunStepPart:a})})]}):o.jsxs("tr",{className:l?"table-success":u?"table-danger":"",children:[o.jsxs("td",{children:[s.part.short_label,s.part.label&&s.part.label.trim().length>0?` (${s.part.label})`:""," ",i&&r!==void 0&&o.jsx("input",{type:"checkbox",name:"tomato",checked:r,onChange:()=>{i(s.id)}})]}),o.jsx("td",{className:"text-center",children:s.latest_action?.type.name}),t&&o.jsx("td",{className:"text-center",children:o.jsxs("div",{className:" d-flex gap-2 justify-content-center",children:[s.actions===0&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.START_PROCESSING}),className:"btn-success btn-sm",children:"Start"}),s.actions>0&&s.latest_action?.type.id!==Ge.FINISH_PROCESSING&&s.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.FINISH_PROCESSING}),className:"btn-primary btn-sm",children:"Finish"}),s.actions>0&&s.latest_action?.type.id!==Ge.FINISH_PROCESSING&&s.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.FAILED_PROCESSING}),className:"btn-danger btn-sm",children:"Failed"}),s.actions>0&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.REWORK}),className:"btn-info btn-sm",children:"Rework"})]})}),o.jsx("td",{children:o.jsx(Kf,{editable:t,runStepPart:e,setRunStepPart:a})})]})},Zm=({run:e,runStep:t,runStepParts:n,editable:r=!0,refetchFn:i=()=>{}})=>{const[s,a]=x.useState(n||[]),{isLoading:l,isError:u,error:c,data:d}=Pe.useQuery({queryKey:["stepParts",t],queryFn:()=>ro({step:t}),enabled:!n}),[p,h]=x.useState(new Map);if(x.useEffect(()=>{for(const S of s)h(R=>{const w=new Map(R);return w.set(S.id,!1),w})},[s]),x.useEffect(()=>{u&&console.error("RunPartsResearchRun query error",{error:c,runStep:t})},[u,c,t]),x.useEffect(()=>{!l&&d&&!n&&a(d.items)},[l,d,n]),x.useEffect(()=>{n&&a(n)},[n]),l)return o.jsx("div",{children:"Loading..."});if(u)return o.jsx("div",{className:"text-danger",children:"Error loading run parts."});if(s.length===0)return null;const m=S=>{h(R=>{const w=new Map(R);return w.set(S,!R.get(S)),w})},g=()=>{h(S=>{const R=new Map(S);for(const w of R.keys())R.set(w,!0);return R})},y=()=>{h(S=>{const R=new Map(S);for(const w of R.keys())R.set(w,!1);return R})},b=()=>{const S=n?.filter(w=>p.get(w.id));if(!S||S.length===0)return null;const R=new Set;return S.forEach(w=>{ep(w).forEach(C=>R.add(C))}),R.size===0?null:o.jsxs(Ue,{align:"end",children:[o.jsx(Ue.Toggle,{size:"sm",variant:"outline-secondary",children:"Actions"}),o.jsxs(Ue.Menu,{children:[R.has(Ge.START_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Start"}),R.has(Ge.FINISH_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Finish"}),R.has(Ge.FAILED_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Failed"}),R.has(Ge.REWORK)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Rework"})]})]})};return o.jsx(x.Fragment,{children:s&&s.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs(Kt,{size:"sm",striped:!0,bordered:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Part"}),o.jsx("th",{className:"text-center",children:"Status"}),r&&o.jsx("th",{className:"text-center",children:"Operation"}),o.jsx("th",{children:"Comment"})]})}),o.jsx("tbody",{children:s.map((S,R)=>o.jsx(t9,{editable:r,runStepPart:S,reloadFn:i,...r?{partIsSelected:p.get(S.id),setPartAsSelected:m}:{}},R))})]}),r&&o.jsxs("div",{children:[o.jsxs("div",{className:"btn-group",children:[o.jsx("button",{className:"part-check-all btn btn-sm btn-outline-secondary",onClick:g,children:"All"}),o.jsx("button",{className:"part-check-none btn btn-sm btn-outline-secondary",onClick:y,children:"None"})]}),p.values().some(S=>S)&&b()]})]})})},ep=e=>{if(e.part_processing_failed_in_previous_step)return[];const t=e.latest_action?.type.id,n=[];return e.actions===0&&n.push(Ge.START_PROCESSING),e.actions>0&&t!==Ge.FINISH_PROCESSING&&t!==Ge.FAILED_PROCESSING&&n.push(Ge.FINISH_PROCESSING,Ge.FAILED_PROCESSING),e.actions>0&&n.push(Ge.REWORK),n},n9=({runPart:e,runStepParts:t,runStep:n,refetchFn:r=()=>{},partIsSelected:i,setPartAsSelected:s})=>{const[a,l]=x.useState(void 0),u=Pe.useQueryClient();x.useEffect(()=>{l(t.find(m=>m.part.id===e.id&&m.step.id===n.id))},[t,e,n]);const c=()=>{Ee.post("/create/run/step/part",{run_part_id:e.id,run_step_id:n.id}).then(m=>{l({...m.data}),r(),u.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},d=({runStepPart:m,runStepPartAction:g})=>{Su({runStepPart:m,runStepPartAction:g}).then(y=>{l({...m,latest_action:y,actions:m.actions+1})}).then(()=>{r(),u.invalidateQueries({queryKey:["runSteps"]})})};if(!a)return o.jsxs("tr",{children:[o.jsxs("td",{children:["Part ",e.short_label,e.label&&e.label.trim().length>0?` (${e.label})`:""]}),o.jsx("td",{colSpan:2}),o.jsx("td",{children:o.jsx(de,{size:"sm",variant:"outline-info",onClick:()=>c(),children:"Init"})}),o.jsx("td",{})]});const p=a.latest_action?.type.id===Ge.FINISH_PROCESSING,h=a.latest_action?.type.id===Ge.FAILED_PROCESSING;return o.jsxs("tr",{className:p?"table-success":h?"table-danger":"",children:[o.jsxs("td",{children:["Part ",a.part.short_label,a.part.label&&a.part.label.trim().length>0?` (${a.part.label})`:"",s&&i!==void 0&&o.jsx("input",{type:"checkbox",name:"tomato",checked:i,onChange:()=>{s(a.id)}})]}),o.jsx("td",{children:a.latest_action?.type.name}),o.jsx("td",{children:o.jsx(o.Fragment,{children:Ln(a.latest_action?.date_created,"DD-MM-YY HH:mm")})}),o.jsx("td",{children:o.jsxs(Ue,{align:"end",children:[o.jsx(Ue.Toggle,{size:"sm",variant:"outline-secondary",children:"Actions"}),o.jsxs(Ue.Menu,{children:[a.actions===0&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.START_PROCESSING}),children:"Start"}),a.actions>0&&a.latest_action?.type.id!==Ge.FINISH_PROCESSING&&a.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.FINISH_PROCESSING}),children:"Finish"}),a.actions>0&&a.latest_action?.type.id!==Ge.FINISH_PROCESSING&&a.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.FAILED_PROCESSING}),children:"Failed"}),a.actions>0&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.REWORK}),children:"Rework"})]})]})}),o.jsx("td",{children:o.jsx(Kf,{runStepPart:a,setRunStepPart:l})})]})},h1=({run:e,runStep:t,runStepParts:n,runParts:r,refetchFn:i=()=>{}})=>{const s=Pe.useQueryClient(),a=Pe.useQueries({queries:[{queryKey:["runParts",e],queryFn:()=>bu({run:e}),enabled:!r},{queryKey:["runStepParts",t.id],queryFn:()=>ro({step:t}),enabled:!n}]}),[l,u]=a,c=a.some(C=>C.isLoading),d=a.some(C=>C.isError),p=x.useMemo(()=>r??l.data?.items??[],[r,l.data]),h=x.useMemo(()=>n??u.data?.items??[],[n,u.data]),[m,g]=x.useState(new Map);x.useEffect(()=>{for(const C of h)g(k=>{const I=new Map(k);return I.set(C.id,!1),I})},[h]);const y=C=>{g(k=>{const I=new Map(k);return I.set(C,!k.get(C)),I})},b=()=>{g(C=>{const k=new Map(C);for(const I of k.keys())k.set(I,!0);return k})},S=()=>{g(C=>{const k=new Map(C);for(const I of k.keys())k.set(I,!1);return k})};if(c)return o.jsx("div",{children:"Loading..."});if(d)return o.jsx("div",{className:"text-danger",children:"Error loading run parts."});const R=p.filter(C=>C.part_level===t.part_level),w=C=>{h.filter(I=>R.find(A=>A.id==I.part.id)).filter(I=>m.get(I.id)).forEach(I=>{ep(I).some(A=>A===C)&&Su({runStepPart:I,runStepPartAction:C}).then(()=>{s.refetchQueries({queryKey:["runStepParts",t.id]}),i&&i()})})},E=()=>{const C=h.filter(I=>R.find(A=>A.id==I.part.id)).filter(I=>m.get(I.id));if(!C||C.length===0)return null;const k=new Set;return C.forEach(I=>{ep(I).forEach(F=>k.add(F))}),k.size===0?null:o.jsxs(Ue,{align:"end",children:[o.jsx(Ue.Toggle,{size:"sm",variant:"secondary",children:"Actions"}),o.jsxs(Ue.Menu,{children:[k.has(Ge.START_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.START_PROCESSING)},children:"Start"}),k.has(Ge.FINISH_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.FINISH_PROCESSING)},children:"Finish"}),k.has(Ge.FAILED_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.FAILED_PROCESSING)},children:"Failed"}),k.has(Ge.REWORK)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.REWORK)},children:"Rework"})]})]})};return o.jsx(x.Fragment,{children:R.length>0&&o.jsxs(o.Fragment,{children:[o.jsx("h3",{children:"Available parts"}),o.jsxs(Kt,{size:"sm",striped:!0,hover:!0,responsive:!0,className:"align-middle",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Part"}),o.jsx("th",{children:"Status"}),o.jsx("th",{children:"Date"}),o.jsx("th",{children:"Actions"}),o.jsx("th",{children:"Comment"})]})}),o.jsx("tbody",{children:R.map((C,k)=>o.jsx(n9,{runStep:t,runPart:C,runStepParts:h,refetchFn:i,partIsSelected:m.get(h?.find(I=>I.part.id===C.id&&I.step.id===t.id)?.id??0),setPartAsSelected:y},k))})]}),o.jsxs("div",{className:"d-flex gap-3",children:[o.jsxs("div",{className:"btn-group",children:[o.jsx("button",{className:"part-check-all btn btn-sm btn-outline-secondary",onClick:b,children:"All"}),o.jsx("button",{className:"part-check-none btn btn-sm btn-outline-secondary",onClick:S,children:"None"})]}),m.values().some(C=>C)&&E()]})]})})};function r9({step:e,stepParts:t,parts:n,refetchFn:r}){const{showOnlyEmphasizedParameters:i}=x.useContext(pc),{run:s}=x.useContext(as);return o.jsx(Ze,{className:"p-4 my-3",children:o.jsx(Ze.Body,{children:o.jsxs(Un,{children:[o.jsxs(Mt,{md:"6",children:[s.run_type===Hn.RESEARCH&&o.jsx(Zm,{run:s,runStep:e,runStepParts:t,refetchFn:()=>{r(["runStepParts"])}}),s.run_type===Hn.PRODUCTION&&o.jsx(h1,{run:s,runStep:e,runParts:n,refetchFn:()=>{r(["runStepParts"])}}),e.has_remark&&o.jsxs(o.Fragment,{children:[o.jsx("h4",{children:"Remark"}),o.jsx("span",{dangerouslySetInnerHTML:{__html:e.remark}})]})]}),o.jsxs(Mt,{md:"6",children:[o.jsx("h4",{children:"Parameters"}),o.jsx(qm,{runStep:e,showOnlyEmphasizedParameters:i,refetchFn:()=>{r([JSON.stringify(e),"parameters"])}}),o.jsx("h4",{children:"Files"}),o.jsx(Xm,{runStep:e,refetchFn:()=>{r(["runSteps"])}})]})]})})})}const g1=({step:e,parts:t,stepParts:n})=>{const r=t.filter(l=>l.part_level===e.part_level).sort((l,u)=>l.root_id&&u.root_id&&l.root_id!==u.root_id?l.root_id-u.root_id:l.left-u.left),i=r.reduce((l,u)=>{const c=u.root_id??u.id;return l[c]||(l[c]=[]),l[c].push(u),l},{}),s=l=>{const u=n.find(c=>c.part.id===l.id&&c.step.id===e.id);return u?u.part_processing_failed_in_previous_step?"badge-failed-previous":u.failed?"badge-failed":u.processed?"badge-processed":u.started?"badge-started":"":"badge-inactive"},a=l=>o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${l.id}`,children:`Level: ${l.part_level}${l.parent?`, Parent: ${l.parent.short_label}`:""}`}),children:o.jsx("span",{className:`badge badge-level-${l.part_level} ${s(l)} me-1`,children:l.label??l.short_label},l.id)},l.id);return o.jsx(o.Fragment,{children:r[0]&&r[0].parent?Object.entries(i).map(([l,u])=>o.jsxs("div",{className:"mb-2",children:[o.jsxs("label",{className:"text-muted me-1",children:[u[0].parent?.short_label,":"]})," ",u.map(c=>a(c))]},l)):r.map(l=>a(l))})},i9=({runPart:e,runStepParts:t,runStep:n,reloadFn:r=()=>{}})=>{const[i,s]=x.useState(void 0),a=Pe.useQueryClient();x.useEffect(()=>{s(t.find(d=>d.part.id===e.id&&d.step.id===n.id))},[t,e,n]);const l=()=>{Ee.post("/create/run/step/part",{run_part_id:e.id,run_step_id:n.id}).then(d=>{s({...d.data}),r(),a.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},u=({runStepPart:d,runStepPartAction:p})=>{Su({runStepPart:d,runStepPartAction:p}).then(h=>{s({...d,latest_action:h,actions:d.actions+1})}).then(()=>{r(),a.invalidateQueries({queryKey:["runSteps"]})})},c=d=>{const p=t.find(h=>h.part.id===d.id&&h.step.id===n.id);return p?p.part_processing_failed_in_previous_step?"badge-failed-previous":p.failed?"badge-failed":p.processed?"badge-processed":p.started?"badge-started":"":"badge-inactive"};return i?o.jsx("div",{style:{minWidth:"100px"},children:o.jsxs(Ue,{children:[o.jsxs(Ue.Toggle,{size:"sm",variant:"outline-secondary",className:"border-2 w-100 "+c(e),children:["Part ",i.part.label??i.part.short_label]}),o.jsxs(Ue.Menu,{children:[i.actions===0&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.START_PROCESSING}),children:"Start"}),i.actions>0&&i.latest_action?.type.id!==Ge.FINISH_PROCESSING&&i.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.FINISH_PROCESSING}),children:"Finish"}),i.actions>0&&i.latest_action?.type.id!==Ge.FINISH_PROCESSING&&i.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.FAILED_PROCESSING}),children:"Failed"}),i.actions>0&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.REWORK}),children:"Rework"})]})]})}):o.jsxs(de,{size:"sm",variant:"outline-secondary",style:{minWidth:"100px"},onClick:()=>l(),children:["Init ",e.label??e.short_label]})},s9=({runStep:e,parts:t,runStepParts:n,reloadFn:r})=>{const i=t.filter(l=>l.part_level===e.part_level).sort((l,u)=>l.root_id&&u.root_id&&l.root_id!==u.root_id?l.root_id-u.root_id:l.left-u.left),s=i.reduce((l,u)=>{const c=u.root_id??u.id;return l[c]||(l[c]=[]),l[c].push(u),l},{}),a=l=>o.jsx(i9,{runStep:e,runPart:l,runStepParts:n,reloadFn:r},l.id);return o.jsx("div",{className:"d-flex flex-wrap gap-2",children:i[0]&&i[0].parent?Object.entries(s).map(([l,u])=>o.jsxs("div",{className:"mb-2",children:[o.jsxs("label",{className:"text-muted me-1",children:[u[0].parent?.short_label,":"]})," ",u.map(c=>a(c))]},l)):i.map(l=>a(l))})};function a9({run:e,step:t,parts:n,stepParts:r,monitoredBy:i,refetchFn:s}){const{environment:a}=Te.useParams(),[l,u]=x.useState(!1),c=()=>{u(!l)},[d,p]=x.useState(t.process_module.module);return x.useEffect(()=>{p(t.process_module.module)},[t.process_module.module]),o.jsxs(o.Fragment,{children:[o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("i",{className:"fa ms-2 "+(l?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:c})}),o.jsxs("td",{className:d.latest_module_status&&d.latest_module_status.status.is_down_status?"table-danger":"",children:[e.run_type===Hn.RESEARCH&&o.jsx(g1,{step:t,parts:n,stepParts:r}),e.run_type===Hn.PRODUCTION&&o.jsx(s9,{runStep:t,parts:n,runStepParts:r,reloadFn:()=>{s(["runStepParts"])}})]}),o.jsxs("td",{children:[i&&o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${i.id}`,children:`Monitored by step: ${i.step.number}`}),children:o.jsx("i",{className:"fa fa-search me-2"})}),t.amount_of_files>0&&o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&o.jsx("i",{className:"fa fa-comment-o text-warning me-3"}),t.is_finished&&o.jsx("i",{className:"fa fa-check text-success me-3"})]}),o.jsxs("td",{className:t.has_step_group?"ps-4":"",children:[t.number," - ",o.jsx(Te.Link,{to:`/${a}/operator/run/step/${t.id}`,children:o.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]}),o.jsxs("td",{children:[o.jsx(Te.Link,{to:`/${a}/operator/equipment/${d.equipment.id}`,className:"me-2",children:d.equipment.name}),o.jsx(qi,{module:d,refetchFn:()=>{s(["runSteps"])}})]})]}),l&&o.jsx("tr",{children:o.jsx("td",{colSpan:n.length+6,children:o.jsx(r9,{step:t,stepParts:r,parts:n,refetchFn:s})})})]})}const tp=({requirement:e,result:t,show:n,setShow:r,refetchFn:i,part:s,stepPart:a})=>{const[l,u]=x.useState({}),[c,d]=x.useState(!1),[p,h]=x.useState(null),[m,g]=x.useState(!1);x.useEffect(()=>{if(Object.keys(l).length>0)return;let w={};for(const E of e.targets){let C="";t!==void 0&&(C=t.values.find(k=>k.logging_parameter.id==E.logging_parameter.id)?.string_value??""),w[E.logging_parameter.id]=C}u(w)},[e]),x.useEffect(()=>{g(!1),h(null),d(!1)},[n]);const y=async()=>{try{h(null),g(!1),d(!0),await Ee.delete(`/delete/run/measurement/result/${t?.id??0}`),g(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(w){console.error(w),h("Update of results failed")}finally{d(!1)}},b=async()=>{try{h(null),g(!1),d(!0);const w=Object.entries(l).map(async([E,C])=>{const k=Number.parseInt(E),I={value:C},A=t?.values.find(F=>F.logging_parameter.id===k)?.id;await Ee.patch(`/update/run/measurement/result/value/${A??0}`,I)});await Promise.all(w),g(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(w){console.error(w),h("Update of results failed")}finally{d(!1)}},S=async()=>{const w={measurement:e.measurement.id,values:Object.entries(l).flatMap(E=>({logging_parameter:Number.parseInt(E[0]),value:E[1]}))};a&&(w.step_part=a?.id??0,w.part=s?.id??0,w.step=e.step.id??0);try{h(null),g(!1),d(!0),await Ee.post("/create/run/measurement/result",w),g(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(E){console.error(E),h("Update of results failed")}finally{d(!1)}},R=w=>{w.preventDefault(),t?b():S()};return o.jsxs(xe,{show:n,size:"lg",onHide:()=>r(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:t?o.jsx(o.Fragment,{children:"Update results"}):o.jsx(o.Fragment,{children:"Create result"})})}),o.jsxs(H,{onSubmit:R,children:[o.jsxs(xe.Body,{children:[p&&o.jsx(Bt,{variant:"danger",children:p}),m&&o.jsx(Bt,{variant:"success",children:"Results have been updated successfully"}),e.targets.map(w=>(t?.values.find(E=>E.logging_parameter.id===w.logging_parameter.id)?.string_value,o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:w.logging_parameter.name}),o.jsx(H.Control,{type:"number",step:"any",placeholder:"Thickness",value:l[w.logging_parameter.id]??"",onChange:E=>u(C=>({...C,[w.logging_parameter.id]:E.target.value}))})]},w.id)))]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{variant:"warning",onClick:()=>r(!1),children:"Close"}),c?o.jsxs(de,{type:"submit",variant:"info",disabled:c,children:[o.jsx(Lp,{animation:"border",size:"sm",className:"me-2"})," Updating results..."]}):t?o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"danger",disabled:c,onClick:y,children:"Delete result"}),o.jsx(de,{type:"submit",variant:"info",disabled:c,children:"Update result"})]}):o.jsx(de,{type:"submit",variant:"info",disabled:c,children:"Create result"})]})]})]})},vn=x.createContext({runStep:{},setRunStep:e=>{},reloadRunStep:()=>{},run:{},modalProperties:{},setModalProperties:e=>{}});function Jm({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:s,editOnly:a=!1}){const{run:l}=x.useContext(vn),[u,c]=x.useState(r??[]),[d,p]=x.useState(n??[]),[h,m]=x.useState(i??[]),g=Pe.useQueryClient(),y=Pe.useQueries({queries:[{queryKey:["runParts",`${l?.id??"unknown"}`],queryFn:async()=>await bu({run:l}),enabled:!r||r.length===0,retry:1},{queryKey:["runStepParts",`${t?.run_id??"unknown"}`,`${t?.id??"unknown"}`],queryFn:async()=>await ro({step:e.requirement_for_step??e.step}),enabled:!n||n.length===0,retry:1},{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await wu({measurement:e.measurement}),enabled:!i||i.length===0,retry:1}]}),b=()=>{g.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[S,R,w]=y;x.useEffect(()=>{r&&r.length>0?c(r):S?.data&&c(S.data.items)},[r,S?.data]),x.useEffect(()=>{n&&n.length>0?p(n):R?.data&&p(R.data.items)},[n,R?.data]),x.useEffect(()=>{i&&i.length>0?m(i):w?.data&&m(w.data.items)},[i,w?.data]);const[E,C]=x.useState(null),k=r&&r.length>0?r:u,A=((n&&n.length>0?n:d)??[]).filter(T=>(k??[]).find(U=>U.id===T.part.id&&U.part_level===t.part_level)!==void 0),F=!r||r.length===0,P=!n||n.length===0,B=!i||i.length===0,V=F&&S?.isLoading||P&&R?.isLoading||B&&w?.isLoading,z=F&&S?.isError||P&&R?.isError||B&&w?.isError;if(V&&A.length===0)return o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(Lp,{animation:"border",size:"sm"})," ",o.jsx("span",{children:"Loading data…"})]});if(z&&A.length===0)return o.jsxs(Bt,{variant:"danger",className:"d-flex justify-content-between align-items-center",children:[o.jsx("div",{children:"Failed to load required data. Please try again."}),o.jsxs("div",{children:[F&&S?.isError&&o.jsx(de,{size:"sm",variant:"outline-light",onClick:()=>S.refetch(),children:"Retry parts"})," ",P&&R?.isError&&o.jsx(de,{size:"sm",variant:"outline-light",onClick:()=>R.refetch(),children:"Retry step parts"})," ",B&&w?.isError&&o.jsx(de,{size:"sm",variant:"outline-light",onClick:()=>w.refetch(),children:"Retry results"})]})]});const Y=T=>{if(!(T&&!isNaN(parseFloat(T.string_value))))return"";const U=parseFloat(T.string_value),ie=e.targets.find(he=>he.logging_parameter.id===T.logging_parameter.id);return ie?(ie.inclusive?!(ie.min_value<=U&&ie.max_value>=U):!(ie.min_value<U&&ie.max_value>U))?"table-danger":"table-success":""};return o.jsx(o.Fragment,{children:A.length>0?o.jsxs(o.Fragment,{children:[o.jsxs(Kt,{size:"sm",striped:!0,hover:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{style:{width:"26%"},children:"Part"}),o.jsx("th",{children:"Parameter"}),o.jsx("th",{children:"Value"}),o.jsx("th",{children:"Unit"}),!a&&o.jsx("th",{style:{width:"1%"}})]})}),o.jsx("tbody",{children:A.map(T=>{const U=h.find(he=>he.values.some(N=>N.step_part_id===T.id)),ie=(U?.values??[]).filter(he=>he.step_part_id===T.id),oe=e.targets.length;return e.targets.map((he,N)=>{const ne=ie.find(D=>D.logging_parameter.id===he.logging_parameter.id)??null,se=ne?Y(ne):"";return o.jsxs("tr",{className:se,children:[N===0&&o.jsxs("td",{rowSpan:oe,children:[T.part.short_label," ",o.jsxs("small",{className:"text-muted",children:["(",T.id,")"]})]}),o.jsx("td",{children:he.logging_parameter.name}),o.jsx("td",{children:ne?ne.string_value:o.jsx("span",{className:"text-muted",children:"not set"})}),o.jsx("td",{children:he.logging_parameter.unit?.abbr??""}),!a&&N===0&&o.jsx("td",{rowSpan:oe,className:"align-middle text-nowrap",children:o.jsxs(de,{size:"sm",variant:U?"outline-primary":"outline-success",onClick:()=>C(String(T.id)),children:[o.jsx("i",{className:"fa fa-edit"})," ",U?"Edit values":"Add values"]})})]},`${T.id}:${he.logging_parameter.id}`)})})})]}),!a&&A.map(T=>{const U=h.find(ie=>ie.values.some(oe=>oe.step_part_id===T.id));return o.jsx(tp,{requirement:e,...U?{result:U}:{part:T.part,stepPart:T},show:E===String(T.id),setShow:ie=>{ie||C(null)},refetchFn:s??b},`modal:${T.id}`)})]}):o.jsx(Bt,{variant:"secondary",className:"mb-0",children:"No selected parts"})})}function v1({requirement:e,measurementResults:t,refetchFn:n,editOnly:r=!1}){const[i,s]=x.useState(t??[]),a=Pe.useQueryClient(),l=Pe.useQueries({queries:[{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await wu({measurement:e.measurement}),enabled:!t||t.length===0,retry:1}]}),u=()=>{a.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[c]=l;x.useEffect(()=>{t&&t.length>0?s(t.filter(S=>S.values.some(R=>!R.step_part_id))):c?.data&&s(c.data.items.filter(S=>S.values.some(R=>!R.step_part_id)))},[t,c?.data]);const[d,p]=x.useState(null),[h,m]=x.useState(!1),g=l.some(S=>S.isLoading);if(l.some(S=>S.isError))return l.filter(S=>S.isError).forEach((S,R)=>{console.error("StepDashboard query error",{index:R,error:S.error})}),o.jsx(o.Fragment,{children:"Error fetching data"});if(g)return o.jsx("div",{children:"Loading..."});const b=S=>{if(!(S&&!isNaN(parseFloat(S.string_value))))return"";const R=parseFloat(S.string_value),w=e.targets.find(C=>C.logging_parameter.id===S.logging_parameter.id);return w&&(w.inclusive?!(w.min_value<=R&&w.max_value>=R):!(w.min_value<R&&w.max_value>R))?"table-danger":""};return o.jsxs("div",{className:"d-flex flex-column gap-4",children:[i.map(S=>o.jsxs("div",{className:"border rounded p-3 shadow-sm",children:[o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[o.jsxs("h6",{className:"mb-0",children:["Result ",o.jsxs("small",{className:"text-muted",children:["#",S.id]})]}),!r&&o.jsxs(de,{size:"sm",variant:"outline-primary",onClick:()=>p(S.id),children:[o.jsx("i",{className:"fa fa-edit"})," Update value"]})]}),o.jsxs("table",{className:"table table-striped table-sm mb-0",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Parameter"}),o.jsx("th",{children:"Value"}),o.jsx("th",{children:"Unit"})]})}),o.jsx("tbody",{children:S.values.map(R=>o.jsxs("tr",{className:R?b(R):"",children:[o.jsx("td",{children:R.logging_parameter.name}),o.jsx("td",{children:R.string_value}),o.jsx("td",{children:R.logging_parameter.unit?.abbr??""})]},`value:${R.id}`))})]}),o.jsx(tp,{requirement:e,result:S,show:d===S.id,setShow:R=>{R||p(null)},refetchFn:n??u})]},S.id)),o.jsx("div",{className:"mt-3",children:o.jsxs(de,{size:"sm",onClick:()=>m(!h),children:[o.jsx("i",{className:"fa fa-plus"})," Add results"]})}),o.jsx(tp,{requirement:e,show:h,setShow:S=>{S||m(!1)},refetchFn:n??u})]})}function o9({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:s}){const{environment:a}=Te.useParams();return o.jsx(Ze,{className:"p-4 my-3",children:o.jsx(Ze.Body,{children:o.jsxs(Un,{children:[o.jsxs(Mt,{md:"7",children:[o.jsx("h4",{children:"Measurements by part"}),o.jsx(Jm,{requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:s}),o.jsx("h4",{children:"Measurements for whole step"}),o.jsx(v1,{requirement:e,measurementResults:i,refetchFn:s})]}),o.jsxs(Mt,{md:"5",children:[o.jsx("h4",{children:"Monitored Step"}),o.jsx(Te.Link,{to:`/${a}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),o.jsx("h4",{children:"Definition"}),o.jsx("span",{children:e.definition}),o.jsx("h4",{children:"Targets"}),o.jsxs(Kt,{size:"sm",striped:!1,bordered:!1,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"parameter"}),o.jsx("th",{children:"min value"}),o.jsx("th",{children:"max value"}),o.jsx("th",{children:"inclusive"})]})}),o.jsx("tbody",{children:e.targets.map(l=>o.jsxs("tr",{children:[o.jsx("td",{children:l.logging_parameter.name}),o.jsx("td",{children:l.min_value}),o.jsx("td",{children:l.max_value}),o.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]}),o.jsx("h4",{children:"Files"}),o.jsx(Xm,{runStep:t,refetchFn:()=>{s(["requirements"])}})]})]})})})}const x1=({requirement:e,step:t,measurementResults:n,parts:r,stepParts:i})=>{const s=r.filter(c=>c.part_level===t.part_level).sort((c,d)=>c.root_id&&d.root_id&&c.root_id!==d.root_id?c.root_id-d.root_id:c.left-d.left),a=s.reduce((c,d)=>{const p=d.root_id??d.id;return c[p]||(c[p]=[]),c[p].push(d),c},{}),l=c=>{const d=i.find(h=>h.part.id===c.id);if(!d)return"badge-inactive";const p=n.find(h=>h.values.some(m=>m.step_part_id===d.id));if(!p)return"";for(const h of p.values){const m=parseFloat(h.string_value),g=e.targets.find(y=>y.logging_parameter.id==h.logging_parameter.id);if(g){if(g.inclusive){if(!(g.min_value<=m&&g.max_value>=m))return"badge-failed"}else if(!(g.min_value<m&&g.max_value>m))return"badge-failed"}}return"badge-processed"},u=c=>o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${c.id}`,children:`Level: ${c.part_level}${c.parent?`, Parent: ${c.parent.short_label}`:""}`}),children:o.jsx("span",{className:`badge badge-level-${c.part_level} ${l(c)} me-1`,children:c.short_label},c.id)},c.id);return o.jsxs("div",{children:[s[0].parent?Object.entries(a).map(([c,d])=>o.jsxs("div",{className:"mb-2",children:[o.jsxs("label",{className:"text-muted me-1",children:[d[0].parent?.short_label,":"]})," ",d.map(p=>u(p))]},c)):s.map(c=>u(c)),o.jsx("label",{children:"(measurements)"})]})};function l9({requirement:e,step:t,parts:n,stepParts:r,refetchFn:i}){const{environment:s}=Te.useParams(),[a,l]=x.useState(!1),[u,c]=x.useState(t.process_module.module);x.useEffect(()=>{c(t.process_module.module)},[t.process_module.module]);const d=()=>{l(!a)},p=Pe.useQueryClient(),h=Pe.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>wu({measurement:e.measurement})}]}),m=S=>{S[0]==="requirement"&&p.refetchQueries({queryKey:S}),i(S)},[g]=h,y=h.some(S=>S.isLoading),b=S=>{if(S.length==0)return y?"":"table-info";let R=!1;for(const w of S)if(w.values.some(C=>{if(!(C&&!isNaN(parseFloat(C.string_value))))return!1;const k=parseFloat(C.string_value),I=e.targets.find(A=>A.logging_parameter.id==C.logging_parameter.id);return I?I.inclusive?!(I.min_value<=k&&I.max_value>=k):!(I.min_value<k&&I.max_value>k):!1})){R=!0;break}return R?"table-danger":""};return o.jsxs(o.Fragment,{children:[o.jsxs("tr",{className:b(g.data?.items??[]),children:[o.jsx("td",{children:o.jsx("i",{className:"fa ms-2 "+(a?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:d})}),o.jsx("td",{children:o.jsx(x1,{requirement:e,step:t,measurementResults:g.data?.items??[],parts:n,stepParts:r})}),o.jsxs("td",{children:[o.jsx(hn,{bg:"info",children:"requirement"}),t.amount_of_files>0&&o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&o.jsx("i",{className:"fa fa-comment-o text-warning"})]}),o.jsx("td",{className:t.has_step_group?"ps-4":"",children:o.jsxs("div",{children:["(",t.number,")"," ",o.jsx(Te.Link,{to:`/${s}/operator/run/step/${t.id}`,children:o.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]})}),o.jsxs("td",{children:[o.jsx(Te.Link,{to:`/${s}/operator/equipment/${u.equipment.id}`,className:"me-2",children:u.equipment.name}),o.jsx(qi,{module:u,refetchFn:()=>{i(["runSteps"])}})]})]}),a&&o.jsx("tr",{children:o.jsx("td",{colSpan:n.length+5,children:y?"Loading...":o.jsx(o9,{requirement:e,step:t,stepParts:r,parts:n,measurementResults:g.data?.items??[],refetchFn:m})})})]})}function u9(){const{run:e}=x.useContext(as),{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n}=x.useContext(pc),[r,i]=x.useState(1),[s]=x.useState(25),[a,l]=x.useState(new Map),u=Pe.useQueryClient(),c=Pe.useQueries({queries:[{queryKey:["runSteps",JSON.stringify(e),r],queryFn:()=>dp({run:e,page:r,pageSize:s}),placeholderData:Pe.keepPreviousData},{queryKey:["runParts",JSON.stringify(e)],queryFn:()=>bu({run:e})},{queryKey:["runStepParts",JSON.stringify(e)],queryFn:()=>ro({run:e})},{queryKey:["requirements",JSON.stringify(e)],queryFn:()=>cp({run:e})}]}),d=P=>{const B=[...P,JSON.stringify(e)];P[0]==="runSteps"&&B.push(r),u.refetchQueries({queryKey:B})},[p,h,m,g]=c,y=c.some(P=>P.isLoading),b=c.some(P=>P.isError);b&&c.filter(P=>P.isError).forEach((P,B)=>{console.error("RunStepsElement query error",{index:B,error:P.error,run:e})});const S=x.useMemo(()=>p.data?.items??[],[p.data?.items]),R=x.useMemo(()=>h.data?.items??[],[h.data?.items]),w=x.useMemo(()=>m.data?.items??[],[m.data?.items]),E=x.useMemo(()=>g.data?.items??[],[g.data?.items]);if(x.useEffect(()=>{l(P=>{const B=new Map(P);return S.forEach(V=>{const z=V.label?.id;z!==void 0&&!B.has(z)&&B.set(z,!0)}),B})},[S]),y)return o.jsx("div",{children:"Loading..."});if(b)return o.jsx("div",{className:"text-danger",children:"Error loading run steps."});const C=new Set,k=S.filter(P=>!P.has_step_group||typeof P.step_group?.id!="number"||C.has(String(P.step_group.id))?!1:(C.add(String(P.step_group.id)),!0)),I={};for(const P of E)P.requirement_for_step!=null&&(I[String(P.requirement_for_step.id)]=P);const A=P=>o.jsx("tr",{style:{pointerEvents:"none"},children:o.jsx("td",{colSpan:5,style:{margin:0},className:"bg-info",children:o.jsx("span",{children:P.step_group?.label})})}),F=P=>{const B=P.label,V=B?.id;if(!P.is_own_label||!B||V===void 0)return null;const z=Y=>{l(T=>{const U=new Map(T);return U.set(Y,!U.get(Y)),U})};return o.jsx("tr",{style:{cursor:"pointer"},onClick:()=>z(V),children:o.jsx("td",{colSpan:5,style:{margin:0},className:"bg-secondary",children:o.jsxs("span",{className:"label-toggle",children:[o.jsx("i",{className:"fa "+(a.get(P.label?.id??-1)?"fa-caret-down":"fa-caret-right")})," ",B.label]})})})};return o.jsxs("div",{children:[o.jsx("h2",{children:"Run steps"}),o.jsx("div",{className:"d-flex justify-content-between align-items-center",children:o.jsxs("div",{className:"form-check form-switch",children:[o.jsx("input",{type:"checkbox",checked:t,className:"form-check-input","data-toggle":"toggle",onChange:()=>n(!t)}),o.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]})}),o.jsxs(Kt,{borderless:!0,hover:!0,striped:!0,size:"sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{}),o.jsx("th",{children:"Parts"}),o.jsx("th",{}),o.jsx("th",{children:"Process"}),o.jsx("th",{children:"Equipment"})]})}),o.jsx("tbody",{children:S.map((P,B)=>{const V=`step-${P.id}`;return o.jsxs(x.Fragment,{children:[P.has_label&&F(P),(!P.has_label||a.get(P.label?.id??-1))&&o.jsxs(o.Fragment,{children:[P.has_step_group&&k.includes(P)&&A(P),P.has_requirement?(()=>{const z=E.find(Y=>Y.step.id===P.id);return o.jsx(l9,{requirement:z,step:P,parts:R,stepParts:w.filter(Y=>Y.step.id===(z.requirement_for_step?.id??z.step.id)),refetchFn:d})})():o.jsx(a9,{run:e,step:P,parts:R,stepParts:w.filter(z=>z.step.id===P.id),monitoredBy:I[P.id],refetchFn:d})]})]},V)})})]}),o.jsx(Oo,{data:p.data,setPage:i,isPlaceholderData:p.isPlaceholderData})]})}function c9(){const{run:e}=x.useContext(as);return o.jsxs("div",{children:[o.jsx("h2",{children:"Run information"}),o.jsx("h3",{children:"Run name"}),o.jsx("p",{children:e.name}),o.jsx("h3",{children:"Project name"}),o.jsx("p",{children:e.project.name})]})}const d9=()=>{const[e,t]=x.useState(null),[n,r]=x.useState(null),{id:i}=Te.useParams();x.useEffect(()=>{(e===null||i!==e.id.toString())&&tg({id:parseInt(i)}).then(a=>(Pl({id:a.run_id}).then(r),a)).then(t)},[i,e]);function s(){tg({id:parseInt(i)}).then(a=>(Pl({id:a.run_id}).then(r),a)).then(t)}return{run:n,runStep:e,setRunStep:t,reloadRunStep:s}};function y1({children:e}){const{runStep:t,setRunStep:n,run:r,reloadRunStep:i}=d9(),[s,a]=x.useState({});return t===null||r===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[t===null&&o.jsx("h1",{children:"Loading run..."}),r===null&&o.jsx("h1",{children:"Loading run step..."}),o.jsxs("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:[t===null&&o.jsx("span",{className:"visually-hidden",children:"Loading run step..."}),r===null&&o.jsx("span",{className:"visually-hidden",children:"Loading run..."})]})]})}):o.jsx(vn.Provider,{value:{runStep:t,setRunStep:n,reloadRunStep:i,run:r,modalProperties:s,setModalProperties:a},children:e})}function f9(){return o.jsx(y1,{children:o.jsx(es,{fluid:!0,children:o.jsx(Te.Outlet,{})})})}const p9=({label:e})=>o.jsx("div",{className:"p-2 h4 mb-1 bg-info text-white",children:e.label}),m9=({runStep:e})=>{const{environment:t}=Te.useParams();return o.jsxs("h2",{children:[" ",e.number," -",e.process_module.process.name," on"," ",o.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,")"]})]})},h9=({checklistItem:e,show:t,setModalShow:n,mutation:r})=>{const i=()=>n(!1);return o.jsxs(xe,{show:t,size:"lg",onHide:i,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Checklist item"})}),o.jsxs(xe.Body,{children:[o.jsx("h2",{children:e.task}),o.jsx("span",{dangerouslySetInnerHTML:{__html:e.description}})]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",variant:"primary",onClick:()=>{r.mutate()},children:"Done"}),o.jsx(de,{variant:"secondary",onClick:()=>n(!1),children:"Close"})]})]})},g9=({checklistItem:e,refetch:t})=>{const[n,r]=x.useState(!1),i=async()=>(await Ee.create().patch("update/run/step/checklist/done/"+e.id,{})).data,s=Pe.useMutation({mutationFn:i,onSuccess:l=>{r(!1),t()}}),a=()=>e.can_finish?e.description!==""?o.jsx(de,{className:"float-end",variant:"primary",onClick:()=>r(!0),children:"Execute checklist step"}):o.jsx(de,{className:"float-end",variant:"success",onClick:()=>{s.mutate()},children:"Done checklist step"}):null;return o.jsxs(Wn.Item,{disabled:e.is_executed,className:"d-flex justify-content-between align-items-start",children:[o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx("span",{className:"h5",children:e.task}),e.is_executed&&o.jsxs("small",{children:["Executed on ",o.jsx(Zi,{format:"DD-MM-YYYY",children:e.date_executed})]})]}),o.jsx("div",{className:"flex-shrink-0",children:o.jsx(a,{})}),o.jsx(h9,{checklistItem:e,show:n,setModalShow:r,mutation:s})]})},v9=()=>{let e=Te.useNavigate();const{environment:t}=Te.useParams(),{runStep:n,reloadRunStep:r,run:i}=x.useContext(vn);let s=x.useRef(!1);const{data:a,error:l,isLoading:u,refetch:c}=Pe.useQuery({queryKey:["checklist",n.id],queryFn:()=>bk({runStep:n})});if(u)return o.jsx("div",{children:"Loading..."});function d(g){Ee.create().patch("update/run/step/finish/"+g.id,{}).then(y=>{y.data.next_step_id!==null&&e(`/${t}/operator/run/step/${y.data.next_step_id}`)})}function p(g){Ee.create().patch("update/run/step/skip/"+g.id,{}).then(()=>{r(),g.next_step_id})}function h(g){Ee.create().patch("update/run/step/un-skip/"+g.id,{}).then(()=>{r()})}let m=!1;return s.current=!n.is_finished,a.items.forEach(g=>{let y=!g.is_executed&&!m;g.can_finish=y,y&&(m=!0,s.current=!1)}),o.jsxs(o.Fragment,{children:[a.items.length===0&&o.jsx(Bt,{variant:"info",children:"No checklist found"}),a.items.length>0&&o.jsx(Wn,{children:a.items.map((g,y)=>o.jsx(g9,{checklistItem:g,refetch:c},y))}),o.jsxs("div",{className:"d-flex justify-content-between mt-3",children:[o.jsxs("div",{className:"d-flex gap-2",children:[s.current&&o.jsx("div",{children:o.jsx(de,{variant:"success",onClick:()=>d(n),children:"Move out"})}),i.access.edit&&!n.is_skipped&&o.jsx("div",{children:o.jsx(de,{variant:"primary",onClick:()=>p(n),children:"Skip operation"})}),i.access.edit&&n.is_skipped&&o.jsx("div",{children:o.jsx(de,{variant:"warning",onClick:()=>h(n),children:"Unskip operation"})})]}),o.jsx("div",{className:"d-flex gap-2",children:n.next_step_id&&o.jsx("div",{children:o.jsx(Te.Link,{to:`/${t}/operator/run/step/${n.next_step_id}`,className:"btn btn-secondary",children:"Next step"})})})]})]})},x9=()=>{const{runStep:e,setRunStep:t}=x.useContext(vn),[n,r]=x.useState(!1),[i,s]=x.useState(!e.is_finished),{register:a,handleSubmit:l,formState:u}=gn({defaultValues:{remark:e.remark_unparsed}}),{isSubmitting:c}=u,d=async p=>{await Ee.create().patch("update/run/step/"+e.id,{remark:p.remark});const h=await Ee.get("view/run/step/"+e.id);t({...e,remark:h.data.remark,remark_unparsed:h.data.remark_unparsed}),r(!1)};return!n||!i?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"text-success",dangerouslySetInnerHTML:{__html:e.remark}}),i&&o.jsx(de,{variant:"primary",className:"mt-3",onClick:()=>r(!0),children:"Edit Remark"})]}):o.jsxs(H,{onSubmit:l(d),children:[o.jsx(H.Control,{as:"textarea",rows:6,...a("remark")}),o.jsx("p",{children:o.jsx("small",{className:"text-muted",children:"If a non-conformity happens during the process, write it down in the form field below"})}),o.jsxs(de,{variant:"primary",type:"submit",disabled:c,children:[c&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save remark"]}),o.jsx(de,{variant:"secondary",className:"ms-2",onClick:()=>r(!1),children:"Cancel"})]})},y9=({run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})=>{const[s,a]=x.useState(!1),{register:l,control:u,setValue:c,handleSubmit:d,formState:p}=gn({defaultValues:{holdCode:r?{value:r.hold_code.id,label:r.hold_code.code}:{},description:r?r.description:""}}),{errors:h,isSubmitting:m}=p,g=async b=>{try{const S=await Ee.patch("update/run/hold-code/"+e.id,{holdcode:s?null:b.holdCode.value,description:b.description});S.data.hold_code?i(S.data):i(void 0),a(!1)}finally{n(!1)}},y=(b,S)=>{Ee.get("list/run/hold-code").then(R=>{const{data:w}=R;return w._embedded.items}).then(R=>{S(R.map(w=>({value:w.id,label:w.code})))})};return o.jsx(xe,{show:t,size:"lg",onHide:()=>n(!1),children:o.jsxs(H,{onSubmit:d(g),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:s?"Reset hold code":"Update hold code"})}),o.jsxs(xe.Body,{children:[!s&&o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Hold code"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(ar,{name:"holdCode",control:u,rules:{validate:{required:b=>b.value!==void 0||s||"A hold code is required"}},render:({field:b})=>o.jsx(Zu,{isSearchable:!1,defaultOptions:!0,placeholder:"Select a hold code",loadOptions:y,value:b.value,onChange:S=>{b.onChange(S)}})}),h.holdCode&&o.jsx("span",{className:"text-danger",children:h.holdCode.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Message"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"textarea",rows:3,...l("description",{required:"A message is required"}),isInvalid:h.description!==void 0}),h.description&&o.jsx(H.Control.Feedback,{type:"invalid",children:h.description.message})]})]})]}),o.jsxs(xe.Footer,{children:[o.jsxs(de,{type:"submit",variant:s?"success":"primary",disabled:m,children:[m&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),s?"Release lot":"Update Hold code"]}),r&&o.jsx(de,{variant:"outline-danger",onClick:()=>{c("description",s?r.description:""),a(!s)},children:s?"Update hold Code":"Reset hold code"})]})]})})},b9=()=>{const{run:e}=x.useContext(vn),[t,n]=x.useState(!1),[r,i]=x.useState(e.hold_code),s=()=>{n(!0)};return o.jsxs(o.Fragment,{children:[r&&o.jsx("span",{className:"badge handle",style:{backgroundColor:r.hold_code.back_color,color:r.hold_code.front_color,fontSize:"1.5rem",cursor:"pointer"},onClick:()=>s(),children:r.hold_code.code}),!r&&o.jsx(hn,{bg:"secondary",className:"handle",onClick:()=>s(),style:{fontSize:"1.5rem",cursor:"pointer"},children:"No hold code"}),o.jsx(y9,{run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})]})},w9=()=>{const{run:e}=x.useContext(vn),[t,n]=x.useState(e.priority);return o.jsxs(x.Fragment,{children:[t&&o.jsx("span",{className:"badge",style:{backgroundColor:t.priority.back_color,color:t.priority.front_color,fontSize:"1.5rem"},children:t.priority.code}),!t&&o.jsx("span",{className:"badge bg-info",style:{fontSize:"1.5rem"},children:"NORMAL"})]})},S9=({run:e,runStep:t,showOnlyEmphasizedParameters:n})=>o.jsx(o.Fragment,{children:o.jsx("tr",{children:o.jsx("td",{colSpan:6,children:o.jsxs("div",{className:"d-flex gap-2",children:[o.jsx("div",{style:{flexGrow:1,flex:"1 1 50%"},children:o.jsx(Zm,{run:e,editable:!1,runStep:t})}),o.jsxs("div",{style:{flexGrow:1,flex:"1 1 50%"},children:[n&&o.jsx("h4",{children:"Emphasized parameters"}),!n&&o.jsx("h4",{children:"Parameters"}),o.jsx(qm,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:n})]})]})})})}),C9=({run:e,monitoredBy:t,runStep:n,runParts:r,runStepParts:i,hideLabel:s,firstInGroup:a})=>{const{environment:l}=Te.useParams(),[u,c]=x.useState(!1),{runStep:d}=x.useContext(vn);return o.jsxs(o.Fragment,{children:[!s&&n.has_label&&n.is_own_label&&o.jsx("tr",{children:o.jsx("td",{className:"bg-info",colSpan:7,children:n.label?.label})}),n.step_group&&a&&o.jsx("tr",{children:o.jsx("td",{className:"bg-secondary",colSpan:7,children:n.step_group?.label})}),o.jsxs("tr",{children:[o.jsxs("td",{className:n.has_step_group?"ps-4":"",children:[n.id!==d.id&&o.jsx("i",{className:"fa "+(u?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{c(!u)}}),n.id===d.id&&o.jsx("i",{className:"fa fa-chevron-right text-success",style:{cursor:"pointer"},title:"This step is currently running"})]}),o.jsx("td",{children:o.jsx(g1,{step:n,parts:r,stepParts:i})}),o.jsxs("td",{children:[n.number," ",n.is_skipped&&o.jsx(hn,{bg:"info",children:"Skipped"})]}),o.jsxs("td",{children:[o.jsx(Te.Link,{to:`/${l}/operator/run/step/${n.id}`,dangerouslySetInnerHTML:{__html:n.name}})," ",t&&o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${t.id}`,children:`Monitored by step: ${t.step.number}`}),children:o.jsx("i",{className:"fa fa-search me-2"})})]}),o.jsx("td",{children:n.finish_user?n.finish_user.initials:""}),o.jsx("td",{children:n.has_rework?o.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),o.jsx("td",{children:n.is_finished?o.jsx(Zi,{format:"DD-MM-YYYY",children:n.finish_date}):""})]}),u&&o.jsx(S9,{run:e,runStep:n,showOnlyEmphasizedParameters:!1})]})};function _9({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i}){const s=n.filter(l=>l.step.id===(e.requirement_for_step?.id??e.step.id)),{environment:a}=Te.useParams();return o.jsx(o.Fragment,{children:o.jsx("tr",{children:o.jsx("td",{colSpan:7,children:o.jsxs("div",{className:"d-flex gap-2",children:[o.jsxs("div",{style:{flexGrow:1,flex:"1 1 50%"},children:[o.jsx("h4",{children:"Measurement results"}),o.jsx(Jm,{requirement:e,step:t,stepParts:s,parts:r,measurementResults:i,editOnly:!0})]}),o.jsxs("div",{style:{flexGrow:1,flex:"1 1 50%"},children:[" ",o.jsx("h4",{children:"Monitored Step"}),o.jsx(Te.Link,{to:`/${a}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),o.jsx("h4",{children:"Definition"}),o.jsx("span",{children:e.definition}),o.jsx("h4",{children:"Targets"}),o.jsxs(Kt,{size:"sm",striped:!1,bordered:!1,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"min value"}),o.jsx("th",{children:"max value"}),o.jsx("th",{children:"inclusive"})]})}),o.jsx("tbody",{children:e.targets.map(l=>o.jsxs("tr",{children:[o.jsx("td",{children:l.min_value}),o.jsx("td",{children:l.max_value}),o.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]})]})]})})})})}function E9({requirement:e,runParts:t,runStepParts:n,hideLabel:r,firstInGroup:i}){const s=e.step,{environment:a}=Te.useParams(),{runStep:l}=x.useContext(vn),[u,c]=x.useState(!1),d=Pe.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>wu({measurement:e.measurement})}]}),[p]=d,h=()=>{if(!p.data)return"";let m=!1;for(const g of n){const y=p.data?.items.find(R=>R.values.some(w=>w.step_part_id===g.id))?.values.find(R=>R.step_part_id===g.id);if(!(y&&!isNaN(parseFloat(y.string_value))))return s.id===l.id?"table-success":"";const b=parseFloat(y.string_value);if(e.targets.some(R=>R.inclusive?!(R.min_value<=b&&R.max_value>=b):!(R.min_value<b&&R.max_value>b))){m=!0;break}}return m?"table-danger":s.id===l.id?"table-success":""};return o.jsxs(o.Fragment,{children:[!r&&s.has_label&&s.is_own_label&&o.jsx("tr",{children:o.jsx("td",{className:"bg-info",colSpan:7,children:s.label?.label})}),s.step_group&&i&&o.jsx("tr",{children:o.jsx("td",{className:"bg-secondary",colSpan:7,children:s.step_group?.label})}),o.jsxs("tr",{className:h(),children:[o.jsx("td",{className:s.has_step_group?"ps-4":"",children:s.id!==l.id&&o.jsx("i",{className:"fa "+(u?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{c(!u)}})}),o.jsx("td",{children:o.jsx(x1,{requirement:e,step:s,parts:t,stepParts:n,measurementResults:p.data?.items??[]})}),o.jsxs("td",{children:[s.number," ",s.is_skipped&&o.jsx(hn,{bg:"info",children:"Skipped"})]}),o.jsxs("td",{children:[o.jsx(hn,{bg:"info",children:"requirement"})," ",o.jsx(Te.Link,{to:`/${a}/operator/run/step/${s.id}`,dangerouslySetInnerHTML:{__html:s.name}})," "]}),o.jsx("td",{children:s.finish_user?s.finish_user.initials:""}),o.jsx("td",{children:s.has_rework?o.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),o.jsx("td",{children:s.is_finished?o.jsx(Zi,{format:"DD-MM-YYYY",children:s.finish_date}):""})]}),u&&o.jsx(_9,{requirement:e,step:s,stepParts:n,parts:t,measurementResults:p.data?.items??[]})]})}const b1=({pageSize:e=25,hideLabel:t=!1})=>{const{runStep:n,run:r}=x.useContext(vn),[i,s]=x.useState(1);x.useEffect(()=>{n?.sequence&&s(Math.max(1,Math.ceil(n.sequence/e)))},[n?.sequence,e]);const a=r?.id??null,l=Pe.useQuery({queryKey:["runParts",`${a}`],queryFn:()=>bu({run:r}),enabled:!!a}),u=Pe.useQuery({queryKey:["runStepParts",`${a}`],queryFn:()=>ro({run:r}),enabled:!!a}),c=Pe.useQuery({queryKey:["runSteps",a,i,e],queryFn:()=>dp({run:r,page:i,pageSize:e}),enabled:!!a,placeholderData:Pe.keepPreviousData}),d=Pe.useQuery({queryKey:["requirements",a],queryFn:()=>cp({run:r}),enabled:!!a,placeholderData:Pe.keepPreviousData}),p=l.isLoading||u.isLoading||c.isLoading||d.isLoading,h=l.isError||u.isError||c.isError||d.isError,m=l.error||u.error||c.error||d.error,g=l.data?.items??[],y=u.data?.items??[],b=c.data?.items??[],S=d.data?.items??[],R=new Set,w=b.filter(C=>!C.has_step_group||typeof C.step_group?.id!="number"||R.has(String(C.step_group.id))?!1:(R.add(String(C.step_group.id)),!0)),E={};for(const C of S)C.requirement_for_step!=null&&(E[String(C.requirement_for_step.id)]=C);return x.useEffect(()=>{h&&console.error("RunStepSimpleList query error",{runId:a,errors:[l.error,u.error,c.error,d.error]})},[h,a,l.error,u.error,c.error,d.error]),o.jsxs("div",{children:[p?o.jsx("div",{children:"Loading..."}):h?o.jsxs("div",{children:["Error: ",String(m?.message??m)]}):o.jsx(Kt,{size:"sm",striped:!0,bordered:!0,hover:!0,children:o.jsx("tbody",{children:b.map((C,k)=>o.jsx(x.Fragment,{children:C.has_requirement?(()=>{const I=S.find(A=>A.step.id===C.id);return o.jsx(E9,{requirement:I,runParts:g,runStepParts:y,firstInGroup:w.includes(C)},C.id??C.sequence??k)})():o.jsx(C9,{run:r,monitoredBy:E[C.id],runParts:g,runStepParts:y,hideLabel:t,firstInGroup:w.includes(C),runStep:C},C.id??C.sequence??k)},k))})}),o.jsx(Oo,{data:c.data,setPage:s,isPlaceholderData:c.isPlaceholderData}),c.isFetching?o.jsx("span",{children:" Loading..."}):null]})},I9=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(vn),[r,i]=x.useState(1),{isPending:s,isLoading:a,isError:l,error:u,data:c,isFetching:d,isPlaceholderData:p}=Pe.useQuery({queryKey:["run_changelog",n,r],queryFn:()=>xk({run:n,page:r}),placeholderData:Pe.keepPreviousData});return o.jsxs(xe,{show:e,size:"lg",onHide:()=>t(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsxs(xe.Title,{children:["History of Run ",n.label]})}),o.jsx(xe.Body,{children:o.jsxs("div",{children:[s?o.jsx("div",{children:"Loading..."}):l?o.jsxs("div",{children:["Error: ",u.message]}):o.jsx(Kt,{size:"sm",striped:!0,bordered:!0,hover:!0,children:o.jsx("tbody",{children:c.items.map((h,m)=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx(Zi,{format:"DD-MM-YYYY",children:h.date_created})}),o.jsx("td",{children:o.jsx("span",{dangerouslySetInnerHTML:{__html:h.message}})}),o.jsxs("td",{children:[h.user.first_name," ",h.user.last_name]})]},m))})}),o.jsx(Oo,{data:c,setPage:i,isPlaceholderData:p}),d?o.jsx("span",{children:" Loading..."}):null]})}),o.jsx(xe.Footer,{children:o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},j9=({size:e})=>{const[t,n]=x.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx(de,{size:e,variant:"primary",onClick:()=>n(!t),children:"Run history"}),t&&o.jsx(I9,{show:t,setModalShow:n})]})},R9=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(vn);return o.jsxs(xe,{show:e,size:"xl",onHide:()=>t(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsxs(xe.Title,{children:["All steps of run ",n.label]})}),o.jsx(xe.Body,{children:o.jsx(b1,{hideLabel:!1})}),o.jsx(xe.Footer,{children:o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},k9=({size:e})=>{const[t,n]=x.useState(!1);return o.jsxs(x.Fragment,{children:[o.jsx(de,{size:e,variant:"primary",onClick:()=>n(!0),children:"All run steps"}),t&&o.jsx(R9,{show:t,setModalShow:n})]})},A9=()=>{const{runStep:e,run:t}=x.useContext(vn),[n,r]=x.useState(!1),[i,s]=x.useState({}),[a,l]=x.useState(null),[u,c]=x.useState([]),[d,p]=x.useState([]),[h,m]=x.useState([]),[g,y]=x.useState(""),[b,S]=x.useState(!1);if(!e.has_recipe)return"Reworks are only possible for steps with a recipe";const[R,w,E]=Pe.useQueries({queries:[{queryKey:["templates",h],queryFn:()=>jk({reworkRecipes:h}),enabled:n&&h.length>0},{queryKey:["run_steps",e.id],queryFn:()=>dp({run:t,page:1,pageSize:1e3}),enabled:n},{queryKey:["template_steps","rework",a,e.id],queryFn:()=>Ik({template:a,pageSize:1e3}),enabled:a!==null}]});x.useEffect(()=>{if(w.isSuccess&&u.length>0){let I=w.data.items.filter(A=>u.includes(A.id)).map(A=>A.recipe_version.recipe);m([...I])}},[w.isSuccess,u]);function C(I){let A=R.data.templates.find(F=>F.id===I);A!==void 0&&l(A)}function k(){let I={};s({}),u.length===0&&(I.runStep="Please select at least one step"),s(A=>({...A,...I})),Object.keys(I).length===0&&(S(!0),Ee.create().patch("/update/run/step/rework/"+e.id,{reworked_run_steps:u,template_steps:d,comment:g}).then(()=>{S(!1),window.location.reload()}))}return o.jsxs(o.Fragment,{children:[n&&o.jsxs(H,{method:"post",onSubmit:()=>k(),children:[o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Template"}),o.jsxs("div",{className:"col-sm-9",children:[h.length===0&&o.jsx(Bt,{variant:"info",children:"Please select a rework step"}),h.length>0&&o.jsxs(H.Control,{as:"select",name:"template",onChange:I=>C(parseInt(I.target.value)),isInvalid:!!i.template,children:[o.jsx("option",{value:"",children:"— Select a template"}),R.data!==void 0&&R.data.templates.map((I,A)=>o.jsxs("option",{value:I.id,children:[I.label,": ",I.name]},A))]}),i.template&&o.jsx("span",{className:"text-danger",children:i.template})]})]}),a!==null&&o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Include template steps"}),o.jsx("div",{className:"col-sm-9",children:o.jsx("ul",{className:"list-group",children:!E.isLoading&&E.data!==void 0&&E.data.steps.map((I,A)=>o.jsx("li",{className:"list-group-item ",children:o.jsxs("div",{className:"form-check",children:[o.jsx("input",{type:"checkbox",className:"form-check-input",id:"templateStep"+I.id,name:"templateStep",onChange:F=>{F.target.checked?p([...d,I.id]):p(d.filter(P=>P!==I.id))},value:I.id}),o.jsxs("label",{htmlFor:"templateStep"+I.id,className:"from-check-label",children:[o.jsxs("small",{className:"text-muted pe-2",children:[I.number,":"]}),I.process_module.process.name]})]})},A))})})]}),o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Repeat steps"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsxs("ul",{className:"list-group",children:[w.isLoading&&o.jsx("option",{children:"Loading run steps..."}),!w.isLoading&&w.data.items.map((I,A)=>{if(e.sequence>=I.sequence)return o.jsxs("li",{className:"list-group-item d-flex justify-content-between"+(e.id===I.id?" bg-success-subtle":""),children:[o.jsxs("div",{className:"form-check",children:[o.jsx("input",{type:"checkbox",className:"form-check-input",id:"runStep"+I.id,name:"runStep",onChange:F=>{F.target.checked?c([...u,I.id]):c(u.filter(P=>P!==I.id))},value:I.id}),o.jsxs("label",{htmlFor:"runStep"+I.id,className:"from-check-label",children:[o.jsxs("small",{className:"text-muted pe-2",children:[I.number,":"]}),I.process_module.process.name]})]}),I.is_finished&&o.jsx("div",{children:o.jsx("span",{className:"badge bg-success",children:"Finished"})})]},A)})]}),i.runStep&&o.jsx("span",{className:"text-danger",children:i.runStep})]})]}),o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Comment"}),o.jsx("div",{className:"col-sm-9",children:o.jsxs(H.Group,{controlId:"runStep.remark",children:[o.jsx(H.Control,{as:"textarea",rows:6,onChange:I=>y(I.target.value),value:g,isInvalid:!!i.comment}),o.jsx("small",{className:"text-muted",children:"Optional comment for the rework"})]})})]}),o.jsx("div",{className:"row mb-3",children:o.jsxs("div",{className:"col-sm-9 offset-sm-3",children:[o.jsxs(de,{variant:"primary",onClick:()=>k(),disabled:b,children:[b&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create rework"]})," ",o.jsx(de,{variant:"warning",onClick:()=>r(!1),children:"Cancel"})]})})]}),!n&&o.jsx(de,{variant:"primary",className:"mt-3",onClick:()=>r(!0),children:"Set Rework"})]})},N9=()=>{const{environment:e}=Te.useParams(),{runStep:t,run:n}=x.useContext(vn),r=Pe.useQueries({queries:[{queryKey:["monitors",t.process_module.module.equipment],queryFn:()=>Hy({equipment:t.process_module.module.equipment})},{queryKey:["ecn",t.process_module.module],queryFn:()=>up({module:t.process_module.module})},{queryKey:["equipmentModule",t.process_module.module],queryFn:()=>lk({id:t.process_module.module.id})},{queryKey:["requirement",t.id],queryFn:()=>cp({run:n,step:t})}]}),[i,s,a,l]=r,[u,c]=x.useState(!0),d=r.some(m=>m.isLoading);if(r.some(m=>m.isError))return r.filter(m=>m.isError).forEach((m,g)=>{console.error("StepDashboard query error",{index:g,error:m.error,runStep:t,run:n})}),o.jsx(o.Fragment,{children:"Error fetching data"});if(d)return o.jsx("div",{children:"Loading..."});const h=a.data;return o.jsx(es,{fluid:!0,children:o.jsxs(Un,{children:[o.jsxs(Mt,{className:"col-9",children:[n.run_type===Hn.RESEARCH&&o.jsx("small",{children:"Research run"}),n.run_type===Hn.PRODUCTION&&o.jsx("small",{children:"Production run"}),o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[o.jsxs("h1",{className:"display-4",children:[n.name," (",n.project.name,")"]}),o.jsxs("div",{className:"d-flex flex-column flex-lg-row gap-2 flex-wrap justify-content-end",children:[t.has_rework&&o.jsx("span",{style:{fontSize:"1.5rem"},className:"mx-1 badge bg-primary",children:"Rework"}),o.jsx(w9,{}),o.jsx(b9,{}),t.is_skipped&&o.jsx("span",{style:{fontSize:"1.5rem"},className:"badge bg-info",children:"SKIPPED"})]})]}),o.jsx(m1,{run:n}),t.label&&o.jsx(p9,{label:t.label}),o.jsx(m9,{runStep:t}),t.is_finished&&o.jsxs(Bt,{variant:"success",children:["This step has been finished by ",t.finish_user?.first_name," ",t.finish_user?.last_name]}),t.has_recipe&&o.jsx(Ze,{className:"rounded my-4",children:o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{className:"text-muted",children:"Recipe"}),o.jsxs(Ze.Text,{className:"display-5",children:[t.recipe_version.recipe.name," (Version ",t.recipe_version.version,")"]})]})}),l.data?.items.length==1&&o.jsxs(o.Fragment,{children:[o.jsx("h4",{children:"Measurements by part"}),o.jsx(Jm,{requirement:l.data.items[0],step:t,editOnly:!1}),o.jsx("h4",{children:"Measurements for whole step"}),o.jsx(v1,{requirement:l.data.items[0],editOnly:!1})]}),l.data?.items.length!=1&&n.run_type===Hn.RESEARCH&&o.jsx(Zm,{run:n,runStep:t}),l.data?.items.length!=1&&n.run_type===Hn.PRODUCTION&&o.jsx(h1,{run:n,runStep:t}),o.jsxs(Un,{className:"py-4",children:[o.jsxs(Mt,{children:[o.jsx("h3",{children:"Checklist"}),o.jsx(v9,{})]}),o.jsxs(Mt,{children:[o.jsx("h2",{children:"Parameters"}),o.jsxs("div",{className:"form-check form-switch",children:[o.jsx("input",{type:"checkbox",checked:u,className:"form-check-input","data-toggle":"toggle",onChange:()=>c(!u)}),o.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]}),o.jsx(qm,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:u}),t.has_instructions&&t.instructions&&o.jsxs(o.Fragment,{children:[o.jsx("h3",{children:"Instructions"}),o.jsx("span",{dangerouslySetInnerHTML:{__html:t.instructions}})]}),o.jsx("h3",{children:"Remark"}),o.jsx(x9,{}),o.jsx("h3",{className:"pt-3",children:"Rework"}),o.jsx(A9,{})]})]}),o.jsxs(Un,{children:[o.jsxs(Mt,{children:[o.jsx("h2",{children:"Step files"}),o.jsx(Xm,{runStep:t})]}),o.jsxs(Mt,{children:[o.jsxs("div",{className:"d-flex justify-content-between mb-3",children:[o.jsx("h2",{children:"Run steps"}),o.jsxs("div",{className:"d-flex gap-2 flex-wrap justify-content-end",children:[o.jsx("div",{children:o.jsx(k9,{size:void 0})}),o.jsx("div",{children:o.jsx(j9,{size:void 0})}),o.jsx("div",{children:o.jsx(l1,{size:void 0,moduleId:t.process_module.module.id})})]})]}),o.jsx(b1,{pageSize:n.run_type===Hn.RESEARCH?5:1e3,hideLabel:!0})]})]})]}),o.jsx(Mt,{className:"col-3",children:o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx("h2",{children:o.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,")"]})}),h&&o.jsx("div",{children:o.jsx("h2",{children:o.jsx(qi,{module:h})})}),i.data?.items&&i.data.items.map((m,g)=>o.jsx(Um,{monitor:m},g)),s.data?.items.map(function(m,g){return o.jsxs(Ze,{className:"my-2",children:[o.jsxs(Ze.Header,{children:["ECN: ",m.ecn]}),o.jsx(Ze.Body,{children:o.jsx(Ze.Text,{children:o.jsx(ss,{children:m.description})})}),o.jsxs(Ze.Footer,{children:[m.date_created&&o.jsxs(o.Fragment,{children:["Created by ",Ln(m.date_created,"DD-MM-YY H:m")," by ",m.owner.full_name]}),m.last_update&&o.jsxs(o.Fragment,{children:[" ","· Updated by ",Ln(m.last_update,"DD-MM-YY H:m")," by"," ",m.owner.full_name]})]})]},g)})]})})]})})},w1=()=>{const[e,t]=x.useState(!1),{modalProperties:n}=x.useContext(vn),r=()=>{t(!1),n.show=!1};return x.useEffect(()=>{t(n.show)},[n]),o.jsxs(xe,{show:e,size:"xl",onHide:r,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:n.modalTitle})}),o.jsx(xe.Body,{children:n.modalContent}),o.jsxs(xe.Footer,{children:[o.jsx(de,{variant:"secondary",onClick:r,children:"Save"}),n.modalSaveButton]})]})};function O9(){return o.jsxs(o.Fragment,{children:[o.jsx(N9,{}),o.jsx(w1,{})]})}function D9({children:e}){const[t,n]=x.useState(!1);return o.jsx(pc.Provider,{value:{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n},children:e})}function M9(){return o.jsx(es,{fluid:!0,children:o.jsx(Te.Outlet,{})})}function F9({control:e,name:t}){const{environment:n}=Te.useParams(),[r,i]=x.useState([]),[s,a]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const u=await pk({environment:n,withLocations:!0});i(u.items)}catch(u){console.error("Error fetching rooms:",u)}finally{a(!1)}}l()},[]),s?o.jsx("p",{children:"Loading labs..."}):o.jsxs("div",{children:[o.jsx("h3",{children:"Choose a lab"}),o.jsx(H.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:o.jsx(ar,{name:t,render:({field:{onChange:l,value:u}})=>o.jsxs(H.Select,{"aria-label":"Choose a lab",value:u?.id||"",onChange:c=>{const d=r.find(p=>p.id.toString()===c.target.value);l(d||null)},children:[o.jsx("option",{value:"",children:"— Choose a lab"}),r.map(c=>o.jsx("option",{value:c.id,children:c.name},c.id))]}),control:e})})]})}function T9({control:e}){return o.jsx(H.Group,{className:"mb-3",controlId:"chemical.scanBarcode",children:o.jsx(ar,{name:"barcode",control:e,render:({field:t})=>o.jsx("input",{...t,id:"chemical.scanBarcodeElement",type:"text",autoFocus:!0,placeholder:"Scan or enter barcode",className:"form-control form-control-lg"})})})}var P9=Object.defineProperty,mu=Object.getOwnPropertySymbols,S1=Object.prototype.hasOwnProperty,C1=Object.prototype.propertyIsEnumerable,fy=(e,t,n)=>t in e?P9(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,np=(e,t)=>{for(var n in t||(t={}))S1.call(t,n)&&fy(e,n,t[n]);if(mu)for(var n of mu(t))C1.call(t,n)&&fy(e,n,t[n]);return e},rp=(e,t)=>{var n={};for(var r in e)S1.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&mu)for(var r of mu(e))t.indexOf(r)<0&&C1.call(e,r)&&(n[r]=e[r]);return n};var Ji;(e=>{const t=class Ke{constructor(u,c,d,p){if(this.version=u,this.errorCorrectionLevel=c,this.modules=[],this.isFunction=[],u<Ke.MIN_VERSION||u>Ke.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=u*4+17;let h=[];for(let g=0;g<this.size;g++)h.push(!1);for(let g=0;g<this.size;g++)this.modules.push(h.slice()),this.isFunction.push(h.slice());this.drawFunctionPatterns();const m=this.addEccAndInterleave(d);if(this.drawCodewords(m),p==-1){let g=1e9;for(let y=0;y<8;y++){this.applyMask(y),this.drawFormatBits(y);const b=this.getPenaltyScore();b<g&&(p=y,g=b),this.applyMask(y)}}i(0<=p&&p<=7),this.mask=p,this.applyMask(p),this.drawFormatBits(p),this.isFunction=[]}static encodeText(u,c){const d=e.QrSegment.makeSegments(u);return Ke.encodeSegments(d,c)}static encodeBinary(u,c){const d=e.QrSegment.makeBytes(u);return Ke.encodeSegments([d],c)}static encodeSegments(u,c,d=1,p=40,h=-1,m=!0){if(!(Ke.MIN_VERSION<=d&&d<=p&&p<=Ke.MAX_VERSION)||h<-1||h>7)throw new RangeError("Invalid value");let g,y;for(g=d;;g++){const w=Ke.getNumDataCodewords(g,c)*8,E=a.getTotalBits(u,g);if(E<=w){y=E;break}if(g>=p)throw new RangeError("Data too long")}for(const w of[Ke.Ecc.MEDIUM,Ke.Ecc.QUARTILE,Ke.Ecc.HIGH])m&&y<=Ke.getNumDataCodewords(g,w)*8&&(c=w);let b=[];for(const w of u){n(w.mode.modeBits,4,b),n(w.numChars,w.mode.numCharCountBits(g),b);for(const E of w.getData())b.push(E)}i(b.length==y);const S=Ke.getNumDataCodewords(g,c)*8;i(b.length<=S),n(0,Math.min(4,S-b.length),b),n(0,(8-b.length%8)%8,b),i(b.length%8==0);for(let w=236;b.length<S;w^=253)n(w,8,b);let R=[];for(;R.length*8<b.length;)R.push(0);return b.forEach((w,E)=>R[E>>>3]|=w<<7-(E&7)),new Ke(g,c,R,h)}getModule(u,c){return 0<=u&&u<this.size&&0<=c&&c<this.size&&this.modules[c][u]}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 u=this.getAlignmentPatternPositions(),c=u.length;for(let d=0;d<c;d++)for(let p=0;p<c;p++)d==0&&p==0||d==0&&p==c-1||d==c-1&&p==0||this.drawAlignmentPattern(u[d],u[p]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(u){const c=this.errorCorrectionLevel.formatBits<<3|u;let d=c;for(let h=0;h<10;h++)d=d<<1^(d>>>9)*1335;const p=(c<<10|d)^21522;i(p>>>15==0);for(let h=0;h<=5;h++)this.setFunctionModule(8,h,r(p,h));this.setFunctionModule(8,7,r(p,6)),this.setFunctionModule(8,8,r(p,7)),this.setFunctionModule(7,8,r(p,8));for(let h=9;h<15;h++)this.setFunctionModule(14-h,8,r(p,h));for(let h=0;h<8;h++)this.setFunctionModule(this.size-1-h,8,r(p,h));for(let h=8;h<15;h++)this.setFunctionModule(8,this.size-15+h,r(p,h));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let u=this.version;for(let d=0;d<12;d++)u=u<<1^(u>>>11)*7973;const c=this.version<<12|u;i(c>>>18==0);for(let d=0;d<18;d++){const p=r(c,d),h=this.size-11+d%3,m=Math.floor(d/3);this.setFunctionModule(h,m,p),this.setFunctionModule(m,h,p)}}drawFinderPattern(u,c){for(let d=-4;d<=4;d++)for(let p=-4;p<=4;p++){const h=Math.max(Math.abs(p),Math.abs(d)),m=u+p,g=c+d;0<=m&&m<this.size&&0<=g&&g<this.size&&this.setFunctionModule(m,g,h!=2&&h!=4)}}drawAlignmentPattern(u,c){for(let d=-2;d<=2;d++)for(let p=-2;p<=2;p++)this.setFunctionModule(u+p,c+d,Math.max(Math.abs(p),Math.abs(d))!=1)}setFunctionModule(u,c,d){this.modules[c][u]=d,this.isFunction[c][u]=!0}addEccAndInterleave(u){const c=this.version,d=this.errorCorrectionLevel;if(u.length!=Ke.getNumDataCodewords(c,d))throw new RangeError("Invalid argument");const p=Ke.NUM_ERROR_CORRECTION_BLOCKS[d.ordinal][c],h=Ke.ECC_CODEWORDS_PER_BLOCK[d.ordinal][c],m=Math.floor(Ke.getNumRawDataModules(c)/8),g=p-m%p,y=Math.floor(m/p);let b=[];const S=Ke.reedSolomonComputeDivisor(h);for(let w=0,E=0;w<p;w++){let C=u.slice(E,E+y-h+(w<g?0:1));E+=C.length;const k=Ke.reedSolomonComputeRemainder(C,S);w<g&&C.push(0),b.push(C.concat(k))}let R=[];for(let w=0;w<b[0].length;w++)b.forEach((E,C)=>{(w!=y-h||C>=g)&&R.push(E[w])});return i(R.length==m),R}drawCodewords(u){if(u.length!=Math.floor(Ke.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let c=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 h=0;h<2;h++){const m=d-h,y=(d+1&2)==0?this.size-1-p:p;!this.isFunction[y][m]&&c<u.length*8&&(this.modules[y][m]=r(u[c>>>3],7-(c&7)),c++)}}i(c==u.length*8)}applyMask(u){if(u<0||u>7)throw new RangeError("Mask value out of range");for(let c=0;c<this.size;c++)for(let d=0;d<this.size;d++){let p;switch(u){case 0:p=(d+c)%2==0;break;case 1:p=c%2==0;break;case 2:p=d%3==0;break;case 3:p=(d+c)%3==0;break;case 4:p=(Math.floor(d/3)+Math.floor(c/2))%2==0;break;case 5:p=d*c%2+d*c%3==0;break;case 6:p=(d*c%2+d*c%3)%2==0;break;case 7:p=((d+c)%2+d*c%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[c][d]&&p&&(this.modules[c][d]=!this.modules[c][d])}}getPenaltyScore(){let u=0;for(let h=0;h<this.size;h++){let m=!1,g=0,y=[0,0,0,0,0,0,0];for(let b=0;b<this.size;b++)this.modules[h][b]==m?(g++,g==5?u+=Ke.PENALTY_N1:g>5&&u++):(this.finderPenaltyAddHistory(g,y),m||(u+=this.finderPenaltyCountPatterns(y)*Ke.PENALTY_N3),m=this.modules[h][b],g=1);u+=this.finderPenaltyTerminateAndCount(m,g,y)*Ke.PENALTY_N3}for(let h=0;h<this.size;h++){let m=!1,g=0,y=[0,0,0,0,0,0,0];for(let b=0;b<this.size;b++)this.modules[b][h]==m?(g++,g==5?u+=Ke.PENALTY_N1:g>5&&u++):(this.finderPenaltyAddHistory(g,y),m||(u+=this.finderPenaltyCountPatterns(y)*Ke.PENALTY_N3),m=this.modules[b][h],g=1);u+=this.finderPenaltyTerminateAndCount(m,g,y)*Ke.PENALTY_N3}for(let h=0;h<this.size-1;h++)for(let m=0;m<this.size-1;m++){const g=this.modules[h][m];g==this.modules[h][m+1]&&g==this.modules[h+1][m]&&g==this.modules[h+1][m+1]&&(u+=Ke.PENALTY_N2)}let c=0;for(const h of this.modules)c=h.reduce((m,g)=>m+(g?1:0),c);const d=this.size*this.size,p=Math.ceil(Math.abs(c*20-d*10)/d)-1;return i(0<=p&&p<=9),u+=p*Ke.PENALTY_N4,i(0<=u&&u<=2568888),u}getAlignmentPatternPositions(){if(this.version==1)return[];{const u=Math.floor(this.version/7)+2,c=this.version==32?26:Math.ceil((this.version*4+4)/(u*2-2))*2;let d=[6];for(let p=this.size-7;d.length<u;p-=c)d.splice(1,0,p);return d}}static getNumRawDataModules(u){if(u<Ke.MIN_VERSION||u>Ke.MAX_VERSION)throw new RangeError("Version number out of range");let c=(16*u+128)*u+64;if(u>=2){const d=Math.floor(u/7)+2;c-=(25*d-10)*d-55,u>=7&&(c-=36)}return i(208<=c&&c<=29648),c}static getNumDataCodewords(u,c){return Math.floor(Ke.getNumRawDataModules(u)/8)-Ke.ECC_CODEWORDS_PER_BLOCK[c.ordinal][u]*Ke.NUM_ERROR_CORRECTION_BLOCKS[c.ordinal][u]}static reedSolomonComputeDivisor(u){if(u<1||u>255)throw new RangeError("Degree out of range");let c=[];for(let p=0;p<u-1;p++)c.push(0);c.push(1);let d=1;for(let p=0;p<u;p++){for(let h=0;h<c.length;h++)c[h]=Ke.reedSolomonMultiply(c[h],d),h+1<c.length&&(c[h]^=c[h+1]);d=Ke.reedSolomonMultiply(d,2)}return c}static reedSolomonComputeRemainder(u,c){let d=c.map(p=>0);for(const p of u){const h=p^d.shift();d.push(0),c.forEach((m,g)=>d[g]^=Ke.reedSolomonMultiply(m,h))}return d}static reedSolomonMultiply(u,c){if(u>>>8||c>>>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^=(c>>>p&1)*u;return i(d>>>8==0),d}finderPenaltyCountPatterns(u){const c=u[1];i(c<=this.size*3);const d=c>0&&u[2]==c&&u[3]==c*3&&u[4]==c&&u[5]==c;return(d&&u[0]>=c*4&&u[6]>=c?1:0)+(d&&u[6]>=c*4&&u[0]>=c?1:0)}finderPenaltyTerminateAndCount(u,c,d){return u&&(this.finderPenaltyAddHistory(c,d),c=0),c+=this.size,this.finderPenaltyAddHistory(c,d),this.finderPenaltyCountPatterns(d)}finderPenaltyAddHistory(u,c){c[0]==0&&(u+=this.size),c.pop(),c.unshift(u)}};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,u,c){if(u<0||u>31||l>>>u)throw new RangeError("Value out of range");for(let d=u-1;d>=0;d--)c.push(l>>>d&1)}function r(l,u){return(l>>>u&1)!=0}function i(l){if(!l)throw new Error("Assertion error")}const s=class Dt{constructor(u,c,d){if(this.mode=u,this.numChars=c,this.bitData=d,c<0)throw new RangeError("Invalid argument");this.bitData=d.slice()}static makeBytes(u){let c=[];for(const d of u)n(d,8,c);return new Dt(Dt.Mode.BYTE,u.length,c)}static makeNumeric(u){if(!Dt.isNumeric(u))throw new RangeError("String contains non-numeric characters");let c=[];for(let d=0;d<u.length;){const p=Math.min(u.length-d,3);n(parseInt(u.substring(d,d+p),10),p*3+1,c),d+=p}return new Dt(Dt.Mode.NUMERIC,u.length,c)}static makeAlphanumeric(u){if(!Dt.isAlphanumeric(u))throw new RangeError("String contains unencodable characters in alphanumeric mode");let c=[],d;for(d=0;d+2<=u.length;d+=2){let p=Dt.ALPHANUMERIC_CHARSET.indexOf(u.charAt(d))*45;p+=Dt.ALPHANUMERIC_CHARSET.indexOf(u.charAt(d+1)),n(p,11,c)}return d<u.length&&n(Dt.ALPHANUMERIC_CHARSET.indexOf(u.charAt(d)),6,c),new Dt(Dt.Mode.ALPHANUMERIC,u.length,c)}static makeSegments(u){return u==""?[]:Dt.isNumeric(u)?[Dt.makeNumeric(u)]:Dt.isAlphanumeric(u)?[Dt.makeAlphanumeric(u)]:[Dt.makeBytes(Dt.toUtf8ByteArray(u))]}static makeEci(u){let c=[];if(u<0)throw new RangeError("ECI assignment value out of range");if(u<128)n(u,8,c);else if(u<16384)n(2,2,c),n(u,14,c);else if(u<1e6)n(6,3,c),n(u,21,c);else throw new RangeError("ECI assignment value out of range");return new Dt(Dt.Mode.ECI,0,c)}static isNumeric(u){return Dt.NUMERIC_REGEX.test(u)}static isAlphanumeric(u){return Dt.ALPHANUMERIC_REGEX.test(u)}getData(){return this.bitData.slice()}static getTotalBits(u,c){let d=0;for(const p of u){const h=p.mode.numCharCountBits(c);if(p.numChars>=1<<h)return 1/0;d+=4+h+p.bitData.length}return d}static toUtf8ByteArray(u){u=encodeURI(u);let c=[];for(let d=0;d<u.length;d++)u.charAt(d)!="%"?c.push(u.charCodeAt(d)):(c.push(parseInt(u.substring(d+1,d+3),16)),d+=2);return c}};s.NUMERIC_REGEX=/^[0-9]*$/,s.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,s.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=s;e.QrSegment=s})(Ji||(Ji={}));(e=>{(t=>{const n=class{constructor(i,s){this.ordinal=i,this.formatBits=s}};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={}))})(Ji||(Ji={}));(e=>{(t=>{const n=class{constructor(i,s){this.modeBits=i,this.numBitsCharCount=s}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={}))})(Ji||(Ji={}));var js=Ji;var L9={L:js.QrCode.Ecc.LOW,M:js.QrCode.Ecc.MEDIUM,Q:js.QrCode.Ecc.QUARTILE,H:js.QrCode.Ecc.HIGH},_1=128,E1="L",I1="#FFFFFF",j1="#000000",R1=!1,k1=1,V9=4,B9=0,G9=.1;function A1(e,t=0){const n=[];return e.forEach(function(r,i){let s=null;r.forEach(function(a,l){if(!a&&s!==null){n.push(`M${s+t} ${i+t}h${l-s}v1H${s+t}z`),s=null;return}if(l===r.length-1){if(!a)return;s===null?n.push(`M${l+t},${i+t} h1v1H${l+t}z`):n.push(`M${s+t},${i+t} h${l+1-s}v1H${s+t}z`);return}a&&s===null&&(s=l)})}),n.join("")}function N1(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,s)=>s<t.x||s>=t.x+t.w?i:!1))}function z9(e,t,n,r){if(r==null)return null;const i=e.length+n*2,s=Math.floor(t*G9),a=i/t,l=(r.width||s)*a,u=(r.height||s)*a,c=r.x==null?e.length/2-l/2:r.x*a,d=r.y==null?e.length/2-u/2:r.y*a,p=r.opacity==null?1:r.opacity;let h=null;if(r.excavate){let g=Math.floor(c),y=Math.floor(d),b=Math.ceil(l+c-g),S=Math.ceil(u+d-y);h={x:g,y,w:b,h:S}}const m=r.crossOrigin;return{x:c,y:d,h:u,w:l,excavation:h,opacity:p,crossOrigin:m}}function Y9(e,t){return t!=null?Math.max(Math.floor(t),0):e?V9:B9}function O1({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:s,size:a,boostLevel:l}){let u=x.useMemo(()=>{const g=(Array.isArray(e)?e:[e]).reduce((y,b)=>(y.push(...js.QrSegment.makeSegments(b)),y),[]);return js.QrCode.encodeSegments(g,L9[t],n,void 0,void 0,l)},[e,t,n,l]);const{cells:c,margin:d,numCells:p,calculatedImageSettings:h}=x.useMemo(()=>{let m=u.getModules();const g=Y9(r,i),y=m.length+g*2,b=z9(m,a,g,s);return{cells:m,margin:g,numCells:y,calculatedImageSettings:b}},[u,a,s,r,i]);return{qrcode:u,margin:d,cells:c,numCells:p,calculatedImageSettings:h}}var H9=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),$9=x.forwardRef(function(t,n){const r=t,{value:i,size:s=_1,level:a=E1,bgColor:l=I1,fgColor:u=j1,includeMargin:c=R1,minVersion:d=k1,boostLevel:p,marginSize:h,imageSettings:m}=r,y=rp(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:b}=y,S=rp(y,["style"]),R=m?.src,w=x.useRef(null),E=x.useRef(null),C=x.useCallback(Y=>{w.current=Y,typeof n=="function"?n(Y):n&&(n.current=Y)},[n]),[k,I]=x.useState(!1),{margin:A,cells:F,numCells:P,calculatedImageSettings:B}=O1({value:i,level:a,minVersion:d,boostLevel:p,includeMargin:c,marginSize:h,imageSettings:m,size:s});x.useEffect(()=>{if(w.current!=null){const Y=w.current,T=Y.getContext("2d");if(!T)return;let U=F;const ie=E.current,oe=B!=null&&ie!==null&&ie.complete&&ie.naturalHeight!==0&&ie.naturalWidth!==0;oe&&B.excavation!=null&&(U=N1(F,B.excavation));const he=window.devicePixelRatio||1;Y.height=Y.width=s*he;const N=s/P*he;T.scale(N,N),T.fillStyle=l,T.fillRect(0,0,P,P),T.fillStyle=u,H9?T.fill(new Path2D(A1(U,A))):F.forEach(function(ne,se){ne.forEach(function(D,ae){D&&T.fillRect(ae+A,se+A,1,1)})}),B&&(T.globalAlpha=B.opacity),oe&&T.drawImage(ie,B.x+A,B.y+A,B.w,B.h)}}),x.useEffect(()=>{I(!1)},[R]);const V=np({height:s,width:s},b);let z=null;return R!=null&&(z=x.createElement("img",{src:R,key:R,style:{display:"none"},onLoad:()=>{I(!0)},ref:E,crossOrigin:B?.crossOrigin})),x.createElement(x.Fragment,null,x.createElement("canvas",np({style:V,height:s,width:s,ref:C,role:"img"},S)),z)});$9.displayName="QRCodeCanvas";var Qi=x.forwardRef(function(t,n){const r=t,{value:i,size:s=_1,level:a=E1,bgColor:l=I1,fgColor:u=j1,includeMargin:c=R1,minVersion:d=k1,boostLevel:p,title:h,marginSize:m,imageSettings:g}=r,y=rp(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:b,cells:S,numCells:R,calculatedImageSettings:w}=O1({value:i,level:a,minVersion:d,boostLevel:p,includeMargin:c,marginSize:m,imageSettings:g,size:s});let E=S,C=null;g!=null&&w!=null&&(w.excavation!=null&&(E=N1(S,w.excavation)),C=x.createElement("image",{href:g.src,height:w.h,width:w.w,x:w.x+b,y:w.y+b,preserveAspectRatio:"none",opacity:w.opacity,crossOrigin:w.crossOrigin}));const k=A1(E,b);return x.createElement("svg",np({height:s,width:s,viewBox:`0 0 ${R} ${R}`,ref:n,role:"img"},y),!!h&&x.createElement("title",null,h),x.createElement("path",{fill:l,d:`M0,0 h${R}v${R}H0z`,shapeRendering:"crispEdges"}),x.createElement("path",{fill:u,d:k,shapeRendering:"crispEdges"}),C)});Qi.displayName="QRCodeSVG";function D1({control:e,name:t,room:n}){const[r,i]=x.useState([]),[s,a]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const u=await fk({room:n,pageSize:1e3});i(u.items),a(!1)}catch(u){console.error("Error fetching locations:",u)}}l()},[n]),s?o.jsx("p",{children:"Loading locations..."}):o.jsxs(H.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:[o.jsx(H.Label,{children:"Select a storage location"}),o.jsx(ar,{name:t,control:e,defaultValue:"",render:({field:{onChange:l,value:u}})=>o.jsx(o.Fragment,{children:o.jsx(Un,{children:r.map(c=>o.jsx(Mt,{xs:4,md:3,className:"mb-3",children:o.jsx(Ze,{onClick:()=>l(c.id.toString()),style:{cursor:"pointer",border:u.toString()===c.id.toString()?"2px solid #007bff":"1px solid #ddd",borderRadius:"8px"},className:"h-100",children:o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{children:c.name}),o.jsxs("div",{className:"text-muted small mb-2 d-flex gap-2 justify-content-between",children:[c.code&&o.jsxs("div",{children:["Code: ",c.code]}),c.zone_group&&o.jsxs("div",{children:["Zone group: ",c.zone_group.name]})]}),o.jsxs("div",{style:{textAlign:"center",marginTop:"10px"},children:[o.jsx(Qi,{value:"/l/"+c.id.toString(),size:128})," "]})]})})},c.id))})})})]})}const W9=({show:e,setShow:t,onChemicalCreate:n})=>{const{register:r,control:i,setValue:s,handleSubmit:a,formState:{errors:l,isSubmitting:u}}=gn({defaultValues:{}}),c=async d=>{try{const p=await Ee.post("create/chemical",d);p.data&&n(p.data)}finally{t(!1)}};return o.jsx(xe,{show:e,size:"lg",onHide:()=>t(!1),children:o.jsxs(H,{onSubmit:a(c),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Create new chemical"})}),o.jsxs(xe.Body,{children:[o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"CAS Number"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"input",...r("cas_number",{required:"A cas number is required"}),isInvalid:l.cas_number!==void 0}),l.cas_number&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.cas_number.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Name"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"input",...r("name",{required:"A name is required"}),isInvalid:l.name!==void 0}),l.name&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.name.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Description"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"textarea",rows:3,...r("description")}),l.description&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.description.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Standard product"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsxs(H.Select,{...r("standard_product",{required:"A standard product is required"}),isInvalid:l.standard_product!==void 0,children:[o.jsx("option",{value:Zd.NON_STANDARD_PRODUCT,children:"Non standard product"}),o.jsx("option",{value:Zd.STANDARD_PRODUCT,children:"Standard product"})]}),l.standard_product&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.standard_product.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Physical state"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsxs(H.Select,{...r("physical_state",{required:"A physical state is required"}),isInvalid:l.physical_state!==void 0,children:[o.jsx("option",{value:ja.SOLID,children:"Solid"}),o.jsx("option",{value:ja.LIQUID,children:"Liquid"}),o.jsx("option",{value:ja.GAS,children:"Gas"}),o.jsx("option",{value:ja.OTHER,children:"Other"})]}),l.physical_state&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.physical_state.message})]})]})]}),o.jsx(xe.Footer,{children:o.jsxs(de,{variant:"primary",disabled:u,onClick:()=>a(c)(),children:[u&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create new chemical"]})})]})})};function M1({control:e,name:t,setValue:n,errors:r}){const[i,s]=x.useState({}),[a,l]=x.useState(!1),[u,c]=x.useState(null),d=(m,g)=>{try{rk({query:m}).then(b=>{const S=b.items.map(w=>({value:w.id,label:w.name+(w.cas_number?" ("+w.cas_number+")":"")})),R={...i};S.forEach(w=>{R[w.value]=w}),s(R),g(S)})}catch(y){console.error("Error fetching chemicals:",y)}},p=m=>m&&i[m]?i[m]:u||null,h=async m=>{try{const g=await Ee.post("create/chemical",m),y={value:g.data.id,label:g.data.name+(g.data.cas_number?` (${g.data.cas_number})`:"")};s(b=>({...b,[y.value]:y})),c(y),l(!1),n(t,g.data.id)}catch(g){console.error("Error creating chemical:",g)}};return o.jsxs(o.Fragment,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Search Existing Chemicals"}),o.jsxs(Un,{children:[o.jsx(ar,{name:t,control:e,render:({field:m})=>o.jsx(Zu,{isSearchable:!0,isClearable:!0,defaultOptions:!0,placeholder:"— Select a chemical, or start typing",loadOptions:d,value:p(m.value),styles:cm,onChange:g=>{c(null),m.onChange(g?.value)}})}),r.chemical&&o.jsx(H.Control.Feedback,{type:"invalid",children:r.chemical.message}),o.jsx("div",{children:o.jsx(de,{variant:"primary",className:"mt-2",onClick:()=>l(!0),children:"Create New Chemical"})})]})]}),o.jsx(W9,{show:a,setShow:l,onChemicalCreate:h})]})}function F1(e){return/\/l\/\d+$/.test(e)}function T1(e){const t=e.match(/\/l\/(\d+)$/);return t?parseInt(t[1],10):null}const P1=[{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 U9({room:e,barcode:t,resetForm:n,location:r,setLocation:i}){const{user:s}=x.useContext($s),{environment:a}=Te.useParams(),[l,u]=x.useState(null);let c=new Date;c.setFullYear(c.getFullYear()+5);const{register:d,control:p,handleSubmit:h,watch:m,setValue:g,formState:{errors:y,isSubmitting:b}}=gn({defaultValues:{expire_date:c.toISOString().split("T")[0],owner:{value:s?.id,label:s?.full_name}}}),S=m("location");x.useEffect(()=>{S&&Va({id:S}).then(E=>{i(E)})},[S]),x.useEffect(()=>{let E="";const C=k=>{if(!(k.target instanceof HTMLInputElement||k.target instanceof HTMLTextAreaElement)&&!(k.key.length>1&&k.key!=="Enter"))if(k.key==="Enter"){if(F1(E)){const I=T1(E);I!==null&&(Va({id:I}).then(A=>{i(A)}),g("location",I))}E.startsWith("reset-scan-location")&&w(),E=""}else E+=k.key};return window.addEventListener("keydown",C),()=>{window.removeEventListener("keydown",C)}},[g]);const R=async E=>{if(E.user=E.owner.value,(await Ly({qrCodeContent:t})).items.length>0){alert("This barcode is already registered to a container");return}const k=await Ee.post("create/chemical/container",E);u(k.data),await Ee.post("create/chemical/container/external-label",{container:k.data.id,qr_code_content:t})},w=()=>{i(null),g("location",0)};return o.jsxs(o.Fragment,{children:[o.jsxs(H,{onSubmit:h(R),children:[!r&&o.jsx(D1,{room:e,control:p,name:"location"}),r&&o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Scanned location"}),o.jsx(Mt,{children:o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("span",{className:"h1",children:r.name}),o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx(Qi,{value:"reset-scan-location",size:100,onClick:()=>w()}),o.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),r&&o.jsxs(o.Fragment,{children:[o.jsx(M1,{control:p,errors:y,setValue:g,...d("chemical",{required:"Chemical is required"})}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Owner"}),o.jsx(_o,{control:p,...d("owner",{required:"Owner is required"}),name:"owner"})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Concentration"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...d("concentration",{required:"An concentration is required"}),isInvalid:y.concentration!==void 0}),y.concentration&&o.jsx(H.Control.Feedback,{type:"invalid",children:y.concentration.message})]})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Amount"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...d("amount",{required:"An amount is required"}),isInvalid:y.amount!==void 0}),o.jsx(ar,{name:"amount_unit",control:p,render:({field:E})=>o.jsxs(fo,{id:"input-group-dropdown-1",title:E.value||"(no unit)",onSelect:C=>E.onChange(C),children:[o.jsx(Ue.Item,{eventKey:"",children:"(no unit)"},0),P1.map(C=>o.jsxs(Ue.Item,{eventKey:C.value,children:[C.label," (",C.value,")"]},C.value))]})}),y.amount&&o.jsx(H.Control.Feedback,{type:"invalid",children:y.amount.message})]})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Expire date"}),o.jsx(H.Control,{type:"date",...d("expire_date",{required:"An expire date is required"}),isInvalid:y.expire_date!==void 0}),y.expire_date&&o.jsx(H.Control.Feedback,{type:"invalid",children:y.expire_date.message})]}),o.jsxs(de,{type:"submit",variant:"primary",disabled:b,children:[b&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),l&&o.jsxs("div",{className:"mt-3",children:[o.jsx(Bt,{variant:"success",children:"Container registered successfully"}),o.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[o.jsx("div",{children:o.jsx("a",{className:"btn btn-primary",href:`${a}/chemical/container/details/${l.id}/general.html`,children:"Go to container"})}),o.jsx(Qi,{value:"reset-form",size:100,className:"float-end",onClick:()=>n()})]})]})]})}function q9({control:e,errors:t}){const[n,r]=x.useState({}),i=(a,l)=>{try{nk({query:a}).then(c=>{const d=c.items.map(h=>({value:h.id,label:h.name})),p={...n};d.forEach(h=>{p[h.value]=h}),r(p),l(d)})}catch(u){console.error("Error fetching types:",u)}},s=a=>n[a]||null;return o.jsx(ar,{name:"container_type",control:e,render:({field:a})=>o.jsx(Zu,{isSearchable:!0,defaultOptions:!0,placeholder:"— Select a container type",loadOptions:i,value:s(a.value),onChange:l=>{a.onChange(l?.value)},styles:cm})})}function X9({room:e,resetForm:t,location:n,setLocation:r}){const{user:i}=x.useContext($s),{environment:s}=Te.useParams(),[a,l]=x.useState(null);let u=new Date;u.setFullYear(u.getFullYear()+5);const{register:c,control:d,handleSubmit:p,watch:h,setValue:m,formState:{errors:g,isSubmitting:y}}=gn({defaultValues:{expire_date:u.toISOString().split("T")[0],owner:{value:i?.id,label:i?.full_name}}}),b=h("location");x.useEffect(()=>{b&&Va({id:b}).then(w=>{r(w)})},[b]),x.useEffect(()=>{let w="";const E=C=>{if(!(C.target instanceof HTMLInputElement||C.target instanceof HTMLTextAreaElement)&&!(C.key.length>1&&C.key!=="Enter"))if(C.key==="Enter"){if(F1(w)){const k=T1(w);k!==null&&(Va({id:k}).then(I=>{r(I)}),m("location",k))}w.startsWith("reset-scan-location")&&R(),w=""}else w+=C.key};return window.addEventListener("keydown",E),()=>{window.removeEventListener("keydown",E)}},[m]);const S=async w=>{w.user=w.owner.value;const E=await Ee.post("create/chemical/container",w);l(E.data)},R=()=>{r(null),m("location",0)};return o.jsxs(o.Fragment,{children:[o.jsxs(H,{onSubmit:p(S),children:[!n&&o.jsx(D1,{room:e,control:d,name:"location"}),n&&o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Scanned location"}),o.jsx(Mt,{children:o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("span",{className:"h1",children:n.name}),o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx(Qi,{value:"reset-scan-location",size:100,onClick:()=>R()}),o.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),n&&o.jsxs(o.Fragment,{children:[o.jsx(M1,{control:d,errors:g,setValue:m,...c("chemical",{required:"Chemical is required"})}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Owner"}),o.jsx(_o,{control:d,...c("owner",{required:"Owner is required"}),name:"owner"})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Concentration"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...c("concentration",{required:"An concentration is required"}),isInvalid:g.concentration!==void 0}),g.concentration&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.concentration.message})]})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Amount"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...c("amount",{required:"An amount is required"}),isInvalid:g.amount!==void 0}),o.jsx(ar,{name:"amount_unit",control:d,render:({field:w})=>o.jsxs(fo,{id:"input-group-dropdown-1",title:w.value||"(no unit)",onSelect:E=>w.onChange(E),children:[o.jsx(Ue.Item,{eventKey:"",children:"(no unit)"},0),P1.map(E=>o.jsxs(Ue.Item,{eventKey:E.value,children:[E.label," (",E.value,")"]},E.value))]})}),g.amount&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.amount.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx(H.Label,{children:"Container type"}),o.jsx(q9,{control:d,...c("container_type",{required:"Container type is required"}),errors:g}),g.container_type&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.container_type.message})]}),o.jsxs(H.Group,{className:"mb-3 w-50 w-25-sm",children:[o.jsx(H.Label,{children:"Expire date"}),o.jsx(H.Control,{type:"date",...c("expire_date",{required:"An expire date is required"}),isInvalid:g.expire_date!==void 0}),g.expire_date&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.expire_date.message})]}),o.jsxs(de,{type:"submit",variant:"primary",disabled:y,children:[y&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),a&&o.jsxs("div",{className:"mt-3",children:[o.jsx(Bt,{variant:"success",children:"Container registered successfully"}),o.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[o.jsx("div",{children:o.jsx("a",{className:"btn btn-primary",href:`${s}/chemical/container/render/single-${a.id}.pdf`,children:"Print label"})}),o.jsx("div",{children:o.jsx("a",{className:"btn btn-primary",href:`${s}/chemical/container/details/${a.id}/general.html`,children:"Go to container"})}),o.jsx(Qi,{value:"reset-form",size:100,className:"float-end",onClick:()=>t()})]})]})]})}function Z9(){const{environment:e}=Te.useParams(),[t,n]=x.useState(null),[r,i]=x.useState([]),[s,a]=x.useState(null),[l,u]=x.useState(!1),[c,d]=x.useState(!1),[p,h]=x.useState(null),[m,g]=x.useState(null),{control:y,watch:b,reset:S,setValue:R}=gn({defaultValues:{room:p,barcode:""}}),w=b("room");x.useEffect(()=>{w&&(h(w),d(w.building.site.has_external_chemical_labelling))},[w]),x.useEffect(()=>{const I=new URLSearchParams(window.location.search).get("room");I&&dk({id:parseInt(I)}).then(A=>{h(A),d(A.building.site.has_external_chemical_labelling),R("room",A)})},[R]),x.useEffect(()=>{const I=new URLSearchParams(window.location.search).get("location");I&&Va({id:parseInt(I)}).then(A=>{g(A),h(A.zone_group.room),d(A.zone_group.room.building.site.has_external_chemical_labelling),R("room",A.zone_group.room)})},[R]);const E=b("barcode");x.useEffect(()=>{const I=setTimeout(()=>{if(!E?.includes("/l/")){if(E?.includes("/cc/")){n(E);const A=E.split("/cc/")[1];tk({id:parseInt(A)}).then(F=>{a(F)})}E&&(n(E),k({barcode:E}))}},1e3);return()=>{clearTimeout(I)}},[E,S]),x.useEffect(()=>{let I="";const A=F=>{F.target instanceof HTMLInputElement||F.target instanceof HTMLTextAreaElement||F.key.length>1&&F.key!=="Enter"||(F.key==="Enter"?(I==="reset-form"&&C(),I=""):I+=F.key)};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[S]);const C=()=>{S({room:p,barcode:""}),n(null),g(null)};async function k({barcode:I}){try{const A=await Ly({qrCodeContent:I});A&&Array.isArray(A.items)&&A.items.length>0?(i(A.items),u(!1)):(u(!0),i([]))}catch(A){console.error("Error fetching chemical container external labels",A),i([]),u(!1)}}return o.jsxs("div",{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx(F9,{control:y,name:"room"}),o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx(Qi,{value:"reset-form",size:100,className:"float-end",onClick:()=>C()}),o.jsx("span",{className:"text-muted",children:"Reset form"})]})]}),p&&c&&o.jsxs(Bt,{children:["Lab ",p.name," has external labels, each chemical material should have a material from the internal supplier/warehouse"]}),p&&!c&&o.jsxs(Bt,{children:["Lab ",p.name," has no external labels, labels can be printed via the intake form"]}),p!==null&&!t&&c&&o.jsx(T9,{control:y}),t&&s&&o.jsxs(Bt,{variant:"info d-flex flex-column gap-3",children:["This is already an own chemical material, this is ",s.chemical.name," and should be stored on"," ",s.location.name," in ",s.location.zone_group.room.name,o.jsx("a",{className:"alert-link",href:`${e}/chemical/container/details/${s.id}/general.html`,children:"Go to container"})]}),!s&&t&&o.jsx(o.Fragment,{children:r.length===0?o.jsx(Bt,{variant:"info d-flex flex-column gap-3",children:o.jsxs("div",{children:["No chemical container external labels found with label ",o.jsx("strong",{children:t})]})}):o.jsxs(Kt,{children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"ID"}),o.jsx("th",{children:"Label"}),o.jsx("th",{children:"Container"}),o.jsx("th",{children:"Location"})]})}),o.jsx("tbody",{children:r.map(I=>o.jsxs("tr",{children:[o.jsx("td",{children:I.id}),o.jsx("td",{children:I.label}),o.jsx("td",{children:o.jsx("a",{href:`/${e}/chemical/container/details/${I.container.id}/general.html`,children:I.container.chemical.name})}),o.jsx("td",{children:o.jsx("a",{href:`/${e}/location/details/${I.container.location.id}/general.html`,children:I.container.location.name})})]},I.id))})]})}),!s&&l&&p&&t&&o.jsx(U9,{room:p,barcode:t,location:m,setLocation:g,resetForm:C}),!s&&p&&!c&&o.jsx(X9,{room:p,location:m,setLocation:g,resetForm:C})]})}function J9({badge_uuid:e}){return o.jsxs("span",{className:"rounded p-2 bg-success",children:["Card read: ",e]})}function Q9({user_id:e}){const[t,n]=x.useState("");return x.useEffect(()=>{const r="https://"+Qm+`/api/onelab/view/user/${e}`;(async()=>{try{const s=await fetch(r);if(!s.ok)throw new Error(`Response status: ${s.status} with body: ${await s.text()}`);const a=await s.json();n(a.full_name)}catch(s){console.log(s)}})()},[]),o.jsxs("span",{className:"rounded p-2 bg-success",children:["Clients has detected user: ",t||"loading..."]})}function K9(){return o.jsx("div",{})}const ip=["all","equipment","not_set"],Qm=document.getElementById("root")?.dataset.goldsteinEndpoint??"",e5="mock-token",t5=10,n5=15;async function r5(e){const t="https://"+Qm+"/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(":"),s=Number(i);if(!r||isNaN(s)||s===0){alert("Please follow the correct format: $item:$id");return}if(!ip.slice(1).includes(r)){alert("Please select a valid $item: (equipment, not_set)");return}const a=await fetch(t,{method:"PATCH",body:JSON.stringify({previous_association:e,new_association:n}),headers:{"Content-type":"application/json; charset=UTF-8"}});if(!a.ok)throw new Error(`Response status: ${a.status} with body: ${await a.text()}`);const l=await a.text();alert(l)}function i5(){const e=x.useRef(null),[t,n]=x.useState(new Map);async function r(c){const d=_S(c.notifications_list,new Date,t5,n5);n(d)}function i(){const d=`
45
+ `+new Error().stack),_=!1}return v.apply(this,arguments)},v)}var B={};function V(f,v){r.deprecationHandler!=null&&r.deprecationHandler(f,v),B[f]||(F(v),B[f]=!0)}r.suppressDeprecationWarnings=!1,r.deprecationHandler=null;function z(f){return typeof Function<"u"&&f instanceof Function||Object.prototype.toString.call(f)==="[object Function]"}function Y(f){var v,_;for(_ in f)l(f,_)&&(v=f[_],z(v)?this[_]=v:this["_"+_]=v);this._config=f,this._dayOfMonthOrdinalParseLenient=new RegExp((this._dayOfMonthOrdinalParse.source||this._ordinalParse.source)+"|"+/\d{1,2}/.source)}function T(f,v){var _=m({},f),j;for(j in v)l(v,j)&&(a(f[j])&&a(v[j])?(_[j]={},m(_[j],f[j]),m(_[j],v[j])):v[j]!=null?_[j]=v[j]:delete _[j]);for(j in f)l(f,j)&&!l(v,j)&&a(f[j])&&(_[j]=m({},_[j]));return _}function U(f){f!=null&&this.set(f)}var ie;Object.keys?ie=Object.keys:ie=function(f){var v,_=[];for(v in f)l(f,v)&&_.push(v);return _};var oe={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"};function he(f,v,_){var j=this._calendar[f]||this._calendar.sameElse;return z(j)?j.call(v,_):j}function N(f,v,_){var j=""+Math.abs(f),O=v-j.length,G=f>=0;return(G?_?"+":"":"-")+Math.pow(10,Math.max(0,O)).toString().substr(1)+j}var ne=/(\[[^\[]*\])|(\\)?([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,D={},ae={};function K(f,v,_,j){var O=j;typeof j=="string"&&(O=function(){return this[j]()}),f&&(ae[f]=O),v&&(ae[v[0]]=function(){return N(O.apply(this,arguments),v[1],v[2])}),_&&(ae[_]=function(){return this.localeData().ordinal(O.apply(this,arguments),f)})}function ce(f){return f.match(/\[[\s\S]/)?f.replace(/^\[|\]$/g,""):f.replace(/\\/g,"")}function Ce(f){var v=f.match(ne),_,j;for(_=0,j=v.length;_<j;_++)ae[v[_]]?v[_]=ae[v[_]]:v[_]=ce(v[_]);return function(O){var G="",re;for(re=0;re<j;re++)G+=z(v[re])?v[re].call(O,f):v[re];return G}}function ge(f,v){return f.isValid()?(v=Ae(v,f.localeData()),D[v]=D[v]||Ce(v),D[v](f)):f.localeData().invalidDate()}function Ae(f,v){var _=5;function j(O){return v.longDateFormat(O)||O}for(se.lastIndex=0;_>=0&&se.test(f);)f=f.replace(se,j),se.lastIndex=0,_-=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 Ye(f){var v=this._longDateFormat[f],_=this._longDateFormat[f.toUpperCase()];return v||!_?v:(this._longDateFormat[f]=_.match(ne).map(function(j){return j==="MMMM"||j==="MM"||j==="DD"||j==="dddd"?j.slice(1):j}).join(""),this._longDateFormat[f])}var Z="Invalid date";function Je(){return this._invalidDate}var st="%d",Le=/\d{1,2}/;function Gt(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 Wt(f,v,_,j){var O=this._relativeTime[_];return z(O)?O(f,v,_,j):O.replace(/%d/i,f)}function Tt(f,v){var _=this._relativeTime[f>0?"future":"past"];return z(_)?_(v):_.replace(/%s/i,v)}var Qe={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 L(f){return typeof f=="string"?Qe[f]||Qe[f.toLowerCase()]:void 0}function W(f){var v={},_,j;for(j in f)l(f,j)&&(_=L(j),_&&(v[_]=f[j]));return v}var te={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 X(f){var v=[],_;for(_ in f)l(f,_)&&v.push({unit:_,priority:te[_]});return v.sort(function(j,O){return j.priority-O.priority}),v}var ee=/\d/,M=/\d\d/,q=/\d{3}/,le=/\d{4}/,be=/[+-]?\d{6}/,we=/\d\d?/,bt=/\d\d\d\d?/,Nt=/\d\d\d\d\d\d?/,zt=/\d{1,3}/,Xt=/\d{1,4}/,Zt=/[+-]?\d{1,6}/,wt=/\d+/,Jt=/[+-]?\d+/,en=/Z|[+-]\d\d:?\d\d/gi,Ar=/Z|[+-]\d\d(?::?\d\d)?/gi,L1=/[+-]?\d+(\.\d{1,3})?/,sa=/[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,os=/^[1-9]\d?/,mc=/^([1-9]\d|\d)/,Do;Do={};function je(f,v,_){Do[f]=z(v)?v:function(j,O){return j&&_?_:v}}function V1(f,v){return l(Do,f)?Do[f](v._strict,v._locale):new RegExp(B1(f))}function B1(f){return Nr(f.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(v,_,j,O,G){return _||j||O||G}))}function Nr(f){return f.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function Bn(f){return f<0?Math.ceil(f)||0:Math.floor(f)}function et(f){var v=+f,_=0;return v!==0&&isFinite(v)&&(_=Bn(v)),_}var hc={};function gt(f,v){var _,j=v,O;for(typeof f=="string"&&(f=[f]),d(v)&&(j=function(G,re){re[v]=et(G)}),O=f.length,_=0;_<O;_++)hc[f[_]]=j}function aa(f,v){gt(f,function(_,j,O,G){O._w=O._w||{},v(_,O._w,O,G)})}function G1(f,v,_){v!=null&&l(hc,f)&&hc[f](v,_._a,_,f)}function Mo(f){return f%4===0&&f%100!==0||f%400===0}var rn=0,Or=1,fr=2,Ut=3,Kn=4,Dr=5,Ci=6,z1=7,Y1=8;K("Y",0,0,function(){var f=this.year();return f<=9999?N(f,4):"+"+f}),K(0,["YY",2],0,function(){return this.year()%100}),K(0,["YYYY",4],0,"year"),K(0,["YYYYY",5],0,"year"),K(0,["YYYYYY",6,!0],0,"year"),je("Y",Jt),je("YY",we,M),je("YYYY",Xt,le),je("YYYYY",Zt,be),je("YYYYYY",Zt,be),gt(["YYYYY","YYYYYY"],rn),gt("YYYY",function(f,v){v[rn]=f.length===2?r.parseTwoDigitYear(f):et(f)}),gt("YY",function(f,v){v[rn]=r.parseTwoDigitYear(f)}),gt("Y",function(f,v){v[rn]=parseInt(f,10)});function oa(f){return Mo(f)?366:365}r.parseTwoDigitYear=function(f){return et(f)+(et(f)>68?1900:2e3)};var Km=ls("FullYear",!0);function H1(){return Mo(this.year())}function ls(f,v){return function(_){return _!=null?(eh(this,f,_),r.updateOffset(this,v),this):la(this,f)}}function la(f,v){if(!f.isValid())return NaN;var _=f._d,j=f._isUTC;switch(v){case"Milliseconds":return j?_.getUTCMilliseconds():_.getMilliseconds();case"Seconds":return j?_.getUTCSeconds():_.getSeconds();case"Minutes":return j?_.getUTCMinutes():_.getMinutes();case"Hours":return j?_.getUTCHours():_.getHours();case"Date":return j?_.getUTCDate():_.getDate();case"Day":return j?_.getUTCDay():_.getDay();case"Month":return j?_.getUTCMonth():_.getMonth();case"FullYear":return j?_.getUTCFullYear():_.getFullYear();default:return NaN}}function eh(f,v,_){var j,O,G,re,Ie;if(!(!f.isValid()||isNaN(_))){switch(j=f._d,O=f._isUTC,v){case"Milliseconds":return void(O?j.setUTCMilliseconds(_):j.setMilliseconds(_));case"Seconds":return void(O?j.setUTCSeconds(_):j.setSeconds(_));case"Minutes":return void(O?j.setUTCMinutes(_):j.setMinutes(_));case"Hours":return void(O?j.setUTCHours(_):j.setHours(_));case"Date":return void(O?j.setUTCDate(_):j.setDate(_));case"FullYear":break;default:return}G=_,re=f.month(),Ie=f.date(),Ie=Ie===29&&re===1&&!Mo(G)?28:Ie,O?j.setUTCFullYear(G,re,Ie):j.setFullYear(G,re,Ie)}}function $1(f){return f=L(f),z(this[f])?this[f]():this}function W1(f,v){if(typeof f=="object"){f=W(f);var _=X(f),j,O=_.length;for(j=0;j<O;j++)this[_[j].unit](f[_[j].unit])}else if(f=L(f),z(this[f]))return this[f](v);return this}function U1(f,v){return(f%v+v)%v}var Pt;Array.prototype.indexOf?Pt=Array.prototype.indexOf:Pt=function(f){var v;for(v=0;v<this.length;++v)if(this[v]===f)return v;return-1};function gc(f,v){if(isNaN(f)||isNaN(v))return NaN;var _=U1(v,12);return f+=(v-_)/12,_===1?Mo(f)?29:28:31-_%7%2}K("M",["MM",2],"Mo",function(){return this.month()+1}),K("MMM",0,0,function(f){return this.localeData().monthsShort(this,f)}),K("MMMM",0,0,function(f){return this.localeData().months(this,f)}),je("M",we,os),je("MM",we,M),je("MMM",function(f,v){return v.monthsShortRegex(f)}),je("MMMM",function(f,v){return v.monthsRegex(f)}),gt(["M","MM"],function(f,v){v[Or]=et(f)-1}),gt(["MMM","MMMM"],function(f,v,_,j){var O=_._locale.monthsParse(f,j,_._strict);O!=null?v[Or]=O:b(_).invalidMonth=f});var q1="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),th="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),nh=/D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,X1=sa,Z1=sa;function J1(f,v){return f?s(this._months)?this._months[f.month()]:this._months[(this._months.isFormat||nh).test(v)?"format":"standalone"][f.month()]:s(this._months)?this._months:this._months.standalone}function Q1(f,v){return f?s(this._monthsShort)?this._monthsShort[f.month()]:this._monthsShort[nh.test(v)?"format":"standalone"][f.month()]:s(this._monthsShort)?this._monthsShort:this._monthsShort.standalone}function K1(f,v,_){var j,O,G,re=f.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],j=0;j<12;++j)G=g([2e3,j]),this._shortMonthsParse[j]=this.monthsShort(G,"").toLocaleLowerCase(),this._longMonthsParse[j]=this.months(G,"").toLocaleLowerCase();return _?v==="MMM"?(O=Pt.call(this._shortMonthsParse,re),O!==-1?O:null):(O=Pt.call(this._longMonthsParse,re),O!==-1?O:null):v==="MMM"?(O=Pt.call(this._shortMonthsParse,re),O!==-1?O:(O=Pt.call(this._longMonthsParse,re),O!==-1?O:null)):(O=Pt.call(this._longMonthsParse,re),O!==-1?O:(O=Pt.call(this._shortMonthsParse,re),O!==-1?O:null))}function e_(f,v,_){var j,O,G;if(this._monthsParseExact)return K1.call(this,f,v,_);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),j=0;j<12;j++){if(O=g([2e3,j]),_&&!this._longMonthsParse[j]&&(this._longMonthsParse[j]=new RegExp("^"+this.months(O,"").replace(".","")+"$","i"),this._shortMonthsParse[j]=new RegExp("^"+this.monthsShort(O,"").replace(".","")+"$","i")),!_&&!this._monthsParse[j]&&(G="^"+this.months(O,"")+"|^"+this.monthsShort(O,""),this._monthsParse[j]=new RegExp(G.replace(".",""),"i")),_&&v==="MMMM"&&this._longMonthsParse[j].test(f))return j;if(_&&v==="MMM"&&this._shortMonthsParse[j].test(f))return j;if(!_&&this._monthsParse[j].test(f))return j}}function rh(f,v){if(!f.isValid())return f;if(typeof v=="string"){if(/^\d+$/.test(v))v=et(v);else if(v=f.localeData().monthsParse(v),!d(v))return f}var _=v,j=f.date();return j=j<29?j:Math.min(j,gc(f.year(),_)),f._isUTC?f._d.setUTCMonth(_,j):f._d.setMonth(_,j),f}function ih(f){return f!=null?(rh(this,f),r.updateOffset(this,!0),this):la(this,"Month")}function t_(){return gc(this.year(),this.month())}function n_(f){return this._monthsParseExact?(l(this,"_monthsRegex")||sh.call(this),f?this._monthsShortStrictRegex:this._monthsShortRegex):(l(this,"_monthsShortRegex")||(this._monthsShortRegex=X1),this._monthsShortStrictRegex&&f?this._monthsShortStrictRegex:this._monthsShortRegex)}function r_(f){return this._monthsParseExact?(l(this,"_monthsRegex")||sh.call(this),f?this._monthsStrictRegex:this._monthsRegex):(l(this,"_monthsRegex")||(this._monthsRegex=Z1),this._monthsStrictRegex&&f?this._monthsStrictRegex:this._monthsRegex)}function sh(){function f(He,nt){return nt.length-He.length}var v=[],_=[],j=[],O,G,re,Ie;for(O=0;O<12;O++)G=g([2e3,O]),re=Nr(this.monthsShort(G,"")),Ie=Nr(this.months(G,"")),v.push(re),_.push(Ie),j.push(Ie),j.push(re);v.sort(f),_.sort(f),j.sort(f),this._monthsRegex=new RegExp("^("+j.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+_.join("|")+")","i"),this._monthsShortStrictRegex=new RegExp("^("+v.join("|")+")","i")}function i_(f,v,_,j,O,G,re){var Ie;return f<100&&f>=0?(Ie=new Date(f+400,v,_,j,O,G,re),isFinite(Ie.getFullYear())&&Ie.setFullYear(f)):Ie=new Date(f,v,_,j,O,G,re),Ie}function ua(f){var v,_;return f<100&&f>=0?(_=Array.prototype.slice.call(arguments),_[0]=f+400,v=new Date(Date.UTC.apply(null,_)),isFinite(v.getUTCFullYear())&&v.setUTCFullYear(f)):v=new Date(Date.UTC.apply(null,arguments)),v}function Fo(f,v,_){var j=7+v-_,O=(7+ua(f,0,j).getUTCDay()-v)%7;return-O+j-1}function ah(f,v,_,j,O){var G=(7+_-j)%7,re=Fo(f,j,O),Ie=1+7*(v-1)+G+re,He,nt;return Ie<=0?(He=f-1,nt=oa(He)+Ie):Ie>oa(f)?(He=f+1,nt=Ie-oa(f)):(He=f,nt=Ie),{year:He,dayOfYear:nt}}function ca(f,v,_){var j=Fo(f.year(),v,_),O=Math.floor((f.dayOfYear()-j-1)/7)+1,G,re;return O<1?(re=f.year()-1,G=O+Mr(re,v,_)):O>Mr(f.year(),v,_)?(G=O-Mr(f.year(),v,_),re=f.year()+1):(re=f.year(),G=O),{week:G,year:re}}function Mr(f,v,_){var j=Fo(f,v,_),O=Fo(f+1,v,_);return(oa(f)-j+O)/7}K("w",["ww",2],"wo","week"),K("W",["WW",2],"Wo","isoWeek"),je("w",we,os),je("ww",we,M),je("W",we,os),je("WW",we,M),aa(["w","ww","W","WW"],function(f,v,_,j){v[j.substr(0,1)]=et(f)});function s_(f){return ca(f,this._week.dow,this._week.doy).week}var a_={dow:0,doy:6};function o_(){return this._week.dow}function l_(){return this._week.doy}function u_(f){var v=this.localeData().week(this);return f==null?v:this.add((f-v)*7,"d")}function c_(f){var v=ca(this,1,4).week;return f==null?v:this.add((f-v)*7,"d")}K("d",0,"do","day"),K("dd",0,0,function(f){return this.localeData().weekdaysMin(this,f)}),K("ddd",0,0,function(f){return this.localeData().weekdaysShort(this,f)}),K("dddd",0,0,function(f){return this.localeData().weekdays(this,f)}),K("e",0,0,"weekday"),K("E",0,0,"isoWeekday"),je("d",we),je("e",we),je("E",we),je("dd",function(f,v){return v.weekdaysMinRegex(f)}),je("ddd",function(f,v){return v.weekdaysShortRegex(f)}),je("dddd",function(f,v){return v.weekdaysRegex(f)}),aa(["dd","ddd","dddd"],function(f,v,_,j){var O=_._locale.weekdaysParse(f,j,_._strict);O!=null?v.d=O:b(_).invalidWeekday=f}),aa(["d","e","E"],function(f,v,_,j){v[j]=et(f)});function d_(f,v){return typeof f!="string"?f:isNaN(f)?(f=v.weekdaysParse(f),typeof f=="number"?f:null):parseInt(f,10)}function f_(f,v){return typeof f=="string"?v.weekdaysParse(f)%7||7:isNaN(f)?null:f}function vc(f,v){return f.slice(v,7).concat(f.slice(0,v))}var p_="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),oh="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),m_="Su_Mo_Tu_We_Th_Fr_Sa".split("_"),h_=sa,g_=sa,v_=sa;function x_(f,v){var _=s(this._weekdays)?this._weekdays:this._weekdays[f&&f!==!0&&this._weekdays.isFormat.test(v)?"format":"standalone"];return f===!0?vc(_,this._week.dow):f?_[f.day()]:_}function y_(f){return f===!0?vc(this._weekdaysShort,this._week.dow):f?this._weekdaysShort[f.day()]:this._weekdaysShort}function b_(f){return f===!0?vc(this._weekdaysMin,this._week.dow):f?this._weekdaysMin[f.day()]:this._weekdaysMin}function w_(f,v,_){var j,O,G,re=f.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],j=0;j<7;++j)G=g([2e3,1]).day(j),this._minWeekdaysParse[j]=this.weekdaysMin(G,"").toLocaleLowerCase(),this._shortWeekdaysParse[j]=this.weekdaysShort(G,"").toLocaleLowerCase(),this._weekdaysParse[j]=this.weekdays(G,"").toLocaleLowerCase();return _?v==="dddd"?(O=Pt.call(this._weekdaysParse,re),O!==-1?O:null):v==="ddd"?(O=Pt.call(this._shortWeekdaysParse,re),O!==-1?O:null):(O=Pt.call(this._minWeekdaysParse,re),O!==-1?O:null):v==="dddd"?(O=Pt.call(this._weekdaysParse,re),O!==-1||(O=Pt.call(this._shortWeekdaysParse,re),O!==-1)?O:(O=Pt.call(this._minWeekdaysParse,re),O!==-1?O:null)):v==="ddd"?(O=Pt.call(this._shortWeekdaysParse,re),O!==-1||(O=Pt.call(this._weekdaysParse,re),O!==-1)?O:(O=Pt.call(this._minWeekdaysParse,re),O!==-1?O:null)):(O=Pt.call(this._minWeekdaysParse,re),O!==-1||(O=Pt.call(this._weekdaysParse,re),O!==-1)?O:(O=Pt.call(this._shortWeekdaysParse,re),O!==-1?O:null))}function S_(f,v,_){var j,O,G;if(this._weekdaysParseExact)return w_.call(this,f,v,_);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),j=0;j<7;j++){if(O=g([2e3,1]).day(j),_&&!this._fullWeekdaysParse[j]&&(this._fullWeekdaysParse[j]=new RegExp("^"+this.weekdays(O,"").replace(".","\\.?")+"$","i"),this._shortWeekdaysParse[j]=new RegExp("^"+this.weekdaysShort(O,"").replace(".","\\.?")+"$","i"),this._minWeekdaysParse[j]=new RegExp("^"+this.weekdaysMin(O,"").replace(".","\\.?")+"$","i")),this._weekdaysParse[j]||(G="^"+this.weekdays(O,"")+"|^"+this.weekdaysShort(O,"")+"|^"+this.weekdaysMin(O,""),this._weekdaysParse[j]=new RegExp(G.replace(".",""),"i")),_&&v==="dddd"&&this._fullWeekdaysParse[j].test(f))return j;if(_&&v==="ddd"&&this._shortWeekdaysParse[j].test(f))return j;if(_&&v==="dd"&&this._minWeekdaysParse[j].test(f))return j;if(!_&&this._weekdaysParse[j].test(f))return j}}function C_(f){if(!this.isValid())return f!=null?this:NaN;var v=la(this,"Day");return f!=null?(f=d_(f,this.localeData()),this.add(f-v,"d")):v}function __(f){if(!this.isValid())return f!=null?this:NaN;var v=(this.day()+7-this.localeData()._week.dow)%7;return f==null?v:this.add(f-v,"d")}function E_(f){if(!this.isValid())return f!=null?this:NaN;if(f!=null){var v=f_(f,this.localeData());return this.day(this.day()%7?v:v-7)}else return this.day()||7}function I_(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||xc.call(this),f?this._weekdaysStrictRegex:this._weekdaysRegex):(l(this,"_weekdaysRegex")||(this._weekdaysRegex=h_),this._weekdaysStrictRegex&&f?this._weekdaysStrictRegex:this._weekdaysRegex)}function j_(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||xc.call(this),f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(l(this,"_weekdaysShortRegex")||(this._weekdaysShortRegex=g_),this._weekdaysShortStrictRegex&&f?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function R_(f){return this._weekdaysParseExact?(l(this,"_weekdaysRegex")||xc.call(this),f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(l(this,"_weekdaysMinRegex")||(this._weekdaysMinRegex=v_),this._weekdaysMinStrictRegex&&f?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function xc(){function f(pn,Vr){return Vr.length-pn.length}var v=[],_=[],j=[],O=[],G,re,Ie,He,nt;for(G=0;G<7;G++)re=g([2e3,1]).day(G),Ie=Nr(this.weekdaysMin(re,"")),He=Nr(this.weekdaysShort(re,"")),nt=Nr(this.weekdays(re,"")),v.push(Ie),_.push(He),j.push(nt),O.push(Ie),O.push(He),O.push(nt);v.sort(f),_.sort(f),j.sort(f),O.sort(f),this._weekdaysRegex=new RegExp("^("+O.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+j.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+_.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+v.join("|")+")","i")}function yc(){return this.hours()%12||12}function k_(){return this.hours()||24}K("H",["HH",2],0,"hour"),K("h",["hh",2],0,yc),K("k",["kk",2],0,k_),K("hmm",0,0,function(){return""+yc.apply(this)+N(this.minutes(),2)}),K("hmmss",0,0,function(){return""+yc.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),K("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),K("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)});function lh(f,v){K(f,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),v)})}lh("a",!0),lh("A",!1);function uh(f,v){return v._meridiemParse}je("a",uh),je("A",uh),je("H",we,mc),je("h",we,os),je("k",we,os),je("HH",we,M),je("hh",we,M),je("kk",we,M),je("hmm",bt),je("hmmss",Nt),je("Hmm",bt),je("Hmmss",Nt),gt(["H","HH"],Ut),gt(["k","kk"],function(f,v,_){var j=et(f);v[Ut]=j===24?0:j}),gt(["a","A"],function(f,v,_){_._isPm=_._locale.isPM(f),_._meridiem=f}),gt(["h","hh"],function(f,v,_){v[Ut]=et(f),b(_).bigHour=!0}),gt("hmm",function(f,v,_){var j=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j)),b(_).bigHour=!0}),gt("hmmss",function(f,v,_){var j=f.length-4,O=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j,2)),v[Dr]=et(f.substr(O)),b(_).bigHour=!0}),gt("Hmm",function(f,v,_){var j=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j))}),gt("Hmmss",function(f,v,_){var j=f.length-4,O=f.length-2;v[Ut]=et(f.substr(0,j)),v[Kn]=et(f.substr(j,2)),v[Dr]=et(f.substr(O))});function A_(f){return(f+"").toLowerCase().charAt(0)==="p"}var N_=/[ap]\.?m?\.?/i,O_=ls("Hours",!0);function D_(f,v,_){return f>11?_?"pm":"PM":_?"am":"AM"}var ch={calendar:oe,longDateFormat:ke,invalidDate:Z,ordinal:st,dayOfMonthOrdinalParse:Le,relativeTime:Rt,months:q1,monthsShort:th,week:a_,weekdays:p_,weekdaysMin:m_,weekdaysShort:oh,meridiemParse:N_},kt={},da={},fa;function M_(f,v){var _,j=Math.min(f.length,v.length);for(_=0;_<j;_+=1)if(f[_]!==v[_])return _;return j}function dh(f){return f&&f.toLowerCase().replace("_","-")}function F_(f){for(var v=0,_,j,O,G;v<f.length;){for(G=dh(f[v]).split("-"),_=G.length,j=dh(f[v+1]),j=j?j.split("-"):null;_>0;){if(O=To(G.slice(0,_).join("-")),O)return O;if(j&&j.length>=_&&M_(G,j)>=_-1)break;_--}v++}return fa}function T_(f){return!!(f&&f.match("^[^/\\\\]*$"))}function To(f){var v=null,_;if(kt[f]===void 0&&e&&e.exports&&T_(f))try{v=fa._abbr,_=JW,_("./locale/"+f),si(v)}catch{kt[f]=null}return kt[f]}function si(f,v){var _;return f&&(c(v)?_=Fr(f):_=bc(f,v),_?fa=_:typeof console<"u"&&console.warn&&console.warn("Locale "+f+" not found. Did you forget to load it?")),fa._abbr}function bc(f,v){if(v!==null){var _,j=ch;if(v.abbr=f,kt[f]!=null)V("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."),j=kt[f]._config;else if(v.parentLocale!=null)if(kt[v.parentLocale]!=null)j=kt[v.parentLocale]._config;else if(_=To(v.parentLocale),_!=null)j=_._config;else return da[v.parentLocale]||(da[v.parentLocale]=[]),da[v.parentLocale].push({name:f,config:v}),null;return kt[f]=new U(T(j,v)),da[f]&&da[f].forEach(function(O){bc(O.name,O.config)}),si(f),kt[f]}else return delete kt[f],null}function P_(f,v){if(v!=null){var _,j,O=ch;kt[f]!=null&&kt[f].parentLocale!=null?kt[f].set(T(kt[f]._config,v)):(j=To(f),j!=null&&(O=j._config),v=T(O,v),j==null&&(v.abbr=f),_=new U(v),_.parentLocale=kt[f],kt[f]=_),si(f)}else kt[f]!=null&&(kt[f].parentLocale!=null?(kt[f]=kt[f].parentLocale,f===si()&&si(f)):kt[f]!=null&&delete kt[f]);return kt[f]}function Fr(f){var v;if(f&&f._locale&&f._locale._abbr&&(f=f._locale._abbr),!f)return fa;if(!s(f)){if(v=To(f),v)return v;f=[f]}return F_(f)}function L_(){return ie(kt)}function wc(f){var v,_=f._a;return _&&b(f).overflow===-2&&(v=_[Or]<0||_[Or]>11?Or:_[fr]<1||_[fr]>gc(_[rn],_[Or])?fr:_[Ut]<0||_[Ut]>24||_[Ut]===24&&(_[Kn]!==0||_[Dr]!==0||_[Ci]!==0)?Ut:_[Kn]<0||_[Kn]>59?Kn:_[Dr]<0||_[Dr]>59?Dr:_[Ci]<0||_[Ci]>999?Ci:-1,b(f)._overflowDayOfYear&&(v<rn||v>fr)&&(v=fr),b(f)._overflowWeeks&&v===-1&&(v=z1),b(f)._overflowWeekday&&v===-1&&(v=Y1),b(f).overflow=v),f}var V_=/^\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)?)?$/,B_=/^\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)?)?$/,G_=/Z|[+-]\d\d(?::?\d\d)?/,Po=[["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]],Sc=[["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/]],z_=/^\/?Date\((-?\d+)/i,Y_=/^(?:(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}))$/,H_={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function fh(f){var v,_,j=f._i,O=V_.exec(j)||B_.exec(j),G,re,Ie,He,nt=Po.length,pn=Sc.length;if(O){for(b(f).iso=!0,v=0,_=nt;v<_;v++)if(Po[v][1].exec(O[1])){re=Po[v][0],G=Po[v][2]!==!1;break}if(re==null){f._isValid=!1;return}if(O[3]){for(v=0,_=pn;v<_;v++)if(Sc[v][1].exec(O[3])){Ie=(O[2]||" ")+Sc[v][0];break}if(Ie==null){f._isValid=!1;return}}if(!G&&Ie!=null){f._isValid=!1;return}if(O[4])if(G_.exec(O[4]))He="Z";else{f._isValid=!1;return}f._f=re+(Ie||"")+(He||""),_c(f)}else f._isValid=!1}function $_(f,v,_,j,O,G){var re=[W_(f),th.indexOf(v),parseInt(_,10),parseInt(j,10),parseInt(O,10)];return G&&re.push(parseInt(G,10)),re}function W_(f){var v=parseInt(f,10);return v<=49?2e3+v:v<=999?1900+v:v}function U_(f){return f.replace(/\([^()]*\)|[\n\t]/g," ").replace(/(\s\s+)/g," ").replace(/^\s\s*/,"").replace(/\s\s*$/,"")}function q_(f,v,_){if(f){var j=oh.indexOf(f),O=new Date(v[0],v[1],v[2]).getDay();if(j!==O)return b(_).weekdayMismatch=!0,_._isValid=!1,!1}return!0}function X_(f,v,_){if(f)return H_[f];if(v)return 0;var j=parseInt(_,10),O=j%100,G=(j-O)/100;return G*60+O}function ph(f){var v=Y_.exec(U_(f._i)),_;if(v){if(_=$_(v[4],v[3],v[2],v[5],v[6],v[7]),!q_(v[1],_,f))return;f._a=_,f._tzm=X_(v[8],v[9],v[10]),f._d=ua.apply(null,f._a),f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),b(f).rfc2822=!0}else f._isValid=!1}function Z_(f){var v=z_.exec(f._i);if(v!==null){f._d=new Date(+v[1]);return}if(fh(f),f._isValid===!1)delete f._isValid;else return;if(ph(f),f._isValid===!1)delete f._isValid;else return;f._strict?f._isValid=!1:r.createFromInputFallback(f)}r.createFromInputFallback=P("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 us(f,v,_){return f??v??_}function J_(f){var v=new Date(r.now());return f._useUTC?[v.getUTCFullYear(),v.getUTCMonth(),v.getUTCDate()]:[v.getFullYear(),v.getMonth(),v.getDate()]}function Cc(f){var v,_,j=[],O,G,re;if(!f._d){for(O=J_(f),f._w&&f._a[fr]==null&&f._a[Or]==null&&Q_(f),f._dayOfYear!=null&&(re=us(f._a[rn],O[rn]),(f._dayOfYear>oa(re)||f._dayOfYear===0)&&(b(f)._overflowDayOfYear=!0),_=ua(re,0,f._dayOfYear),f._a[Or]=_.getUTCMonth(),f._a[fr]=_.getUTCDate()),v=0;v<3&&f._a[v]==null;++v)f._a[v]=j[v]=O[v];for(;v<7;v++)f._a[v]=j[v]=f._a[v]==null?v===2?1:0:f._a[v];f._a[Ut]===24&&f._a[Kn]===0&&f._a[Dr]===0&&f._a[Ci]===0&&(f._nextDay=!0,f._a[Ut]=0),f._d=(f._useUTC?ua:i_).apply(null,j),G=f._useUTC?f._d.getUTCDay():f._d.getDay(),f._tzm!=null&&f._d.setUTCMinutes(f._d.getUTCMinutes()-f._tzm),f._nextDay&&(f._a[Ut]=24),f._w&&typeof f._w.d<"u"&&f._w.d!==G&&(b(f).weekdayMismatch=!0)}}function Q_(f){var v,_,j,O,G,re,Ie,He,nt;v=f._w,v.GG!=null||v.W!=null||v.E!=null?(G=1,re=4,_=us(v.GG,f._a[rn],ca(Et(),1,4).year),j=us(v.W,1),O=us(v.E,1),(O<1||O>7)&&(He=!0)):(G=f._locale._week.dow,re=f._locale._week.doy,nt=ca(Et(),G,re),_=us(v.gg,f._a[rn],nt.year),j=us(v.w,nt.week),v.d!=null?(O=v.d,(O<0||O>6)&&(He=!0)):v.e!=null?(O=v.e+G,(v.e<0||v.e>6)&&(He=!0)):O=G),j<1||j>Mr(_,G,re)?b(f)._overflowWeeks=!0:He!=null?b(f)._overflowWeekday=!0:(Ie=ah(_,j,O,G,re),f._a[rn]=Ie.year,f._dayOfYear=Ie.dayOfYear)}r.ISO_8601=function(){},r.RFC_2822=function(){};function _c(f){if(f._f===r.ISO_8601){fh(f);return}if(f._f===r.RFC_2822){ph(f);return}f._a=[],b(f).empty=!0;var v=""+f._i,_,j,O,G,re,Ie=v.length,He=0,nt,pn;for(O=Ae(f._f,f._locale).match(ne)||[],pn=O.length,_=0;_<pn;_++)G=O[_],j=(v.match(V1(G,f))||[])[0],j&&(re=v.substr(0,v.indexOf(j)),re.length>0&&b(f).unusedInput.push(re),v=v.slice(v.indexOf(j)+j.length),He+=j.length),ae[G]?(j?b(f).empty=!1:b(f).unusedTokens.push(G),G1(G,j,f)):f._strict&&!j&&b(f).unusedTokens.push(G);b(f).charsLeftOver=Ie-He,v.length>0&&b(f).unusedInput.push(v),f._a[Ut]<=12&&b(f).bigHour===!0&&f._a[Ut]>0&&(b(f).bigHour=void 0),b(f).parsedDateParts=f._a.slice(0),b(f).meridiem=f._meridiem,f._a[Ut]=K_(f._locale,f._a[Ut],f._meridiem),nt=b(f).era,nt!==null&&(f._a[rn]=f._locale.erasConvertYear(nt,f._a[rn])),Cc(f),wc(f)}function K_(f,v,_){var j;return _==null?v:f.meridiemHour!=null?f.meridiemHour(v,_):(f.isPM!=null&&(j=f.isPM(_),j&&v<12&&(v+=12),!j&&v===12&&(v=0)),v)}function eE(f){var v,_,j,O,G,re,Ie=!1,He=f._f.length;if(He===0){b(f).invalidFormat=!0,f._d=new Date(NaN);return}for(O=0;O<He;O++)G=0,re=!1,v=k({},f),f._useUTC!=null&&(v._useUTC=f._useUTC),v._f=f._f[O],_c(v),R(v)&&(re=!0),G+=b(v).charsLeftOver,G+=b(v).unusedTokens.length*10,b(v).score=G,Ie?G<j&&(j=G,_=v):(j==null||G<j||re)&&(j=G,_=v,re&&(Ie=!0));m(f,_||v)}function tE(f){if(!f._d){var v=W(f._i),_=v.day===void 0?v.date:v.day;f._a=h([v.year,v.month,_,v.hour,v.minute,v.second,v.millisecond],function(j){return j&&parseInt(j,10)}),Cc(f)}}function nE(f){var v=new I(wc(mh(f)));return v._nextDay&&(v.add(1,"d"),v._nextDay=void 0),v}function mh(f){var v=f._i,_=f._f;return f._locale=f._locale||Fr(f._l),v===null||_===void 0&&v===""?w({nullInput:!0}):(typeof v=="string"&&(f._i=v=f._locale.preparse(v)),A(v)?new I(wc(v)):(p(v)?f._d=v:s(_)?eE(f):_?_c(f):rE(f),R(f)||(f._d=null),f))}function rE(f){var v=f._i;c(v)?f._d=new Date(r.now()):p(v)?f._d=new Date(v.valueOf()):typeof v=="string"?Z_(f):s(v)?(f._a=h(v.slice(0),function(_){return parseInt(_,10)}),Cc(f)):a(v)?tE(f):d(v)?f._d=new Date(v):r.createFromInputFallback(f)}function hh(f,v,_,j,O){var G={};return(v===!0||v===!1)&&(j=v,v=void 0),(_===!0||_===!1)&&(j=_,_=void 0),(a(f)&&u(f)||s(f)&&f.length===0)&&(f=void 0),G._isAMomentObject=!0,G._useUTC=G._isUTC=O,G._l=_,G._i=f,G._f=v,G._strict=j,nE(G)}function Et(f,v,_,j){return hh(f,v,_,j,!1)}var iE=P("moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=Et.apply(null,arguments);return this.isValid()&&f.isValid()?f<this?this:f:w()}),sE=P("moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var f=Et.apply(null,arguments);return this.isValid()&&f.isValid()?f>this?this:f:w()});function gh(f,v){var _,j;if(v.length===1&&s(v[0])&&(v=v[0]),!v.length)return Et();for(_=v[0],j=1;j<v.length;++j)(!v[j].isValid()||v[j][f](_))&&(_=v[j]);return _}function aE(){var f=[].slice.call(arguments,0);return gh("isBefore",f)}function oE(){var f=[].slice.call(arguments,0);return gh("isAfter",f)}var lE=function(){return Date.now?Date.now():+new Date},pa=["year","quarter","month","week","day","hour","minute","second","millisecond"];function uE(f){var v,_=!1,j,O=pa.length;for(v in f)if(l(f,v)&&!(Pt.call(pa,v)!==-1&&(f[v]==null||!isNaN(f[v]))))return!1;for(j=0;j<O;++j)if(f[pa[j]]){if(_)return!1;parseFloat(f[pa[j]])!==et(f[pa[j]])&&(_=!0)}return!0}function cE(){return this._isValid}function dE(){return er(NaN)}function Lo(f){var v=W(f),_=v.year||0,j=v.quarter||0,O=v.month||0,G=v.week||v.isoWeek||0,re=v.day||0,Ie=v.hour||0,He=v.minute||0,nt=v.second||0,pn=v.millisecond||0;this._isValid=uE(v),this._milliseconds=+pn+nt*1e3+He*6e4+Ie*1e3*60*60,this._days=+re+G*7,this._months=+O+j*3+_*12,this._data={},this._locale=Fr(),this._bubble()}function Vo(f){return f instanceof Lo}function Ec(f){return f<0?Math.round(-1*f)*-1:Math.round(f)}function fE(f,v,_){var j=Math.min(f.length,v.length),O=Math.abs(f.length-v.length),G=0,re;for(re=0;re<j;re++)et(f[re])!==et(v[re])&&G++;return G+O}function vh(f,v){K(f,0,0,function(){var _=this.utcOffset(),j="+";return _<0&&(_=-_,j="-"),j+N(~~(_/60),2)+v+N(~~_%60,2)})}vh("Z",":"),vh("ZZ",""),je("Z",Ar),je("ZZ",Ar),gt(["Z","ZZ"],function(f,v,_){_._useUTC=!0,_._tzm=Ic(Ar,f)});var pE=/([\+\-]|\d\d)/gi;function Ic(f,v){var _=(v||"").match(f),j,O,G;return _===null?null:(j=_[_.length-1]||[],O=(j+"").match(pE)||["-",0,0],G=+(O[1]*60)+et(O[2]),G===0?0:O[0]==="+"?G:-G)}function jc(f,v){var _,j;return v._isUTC?(_=v.clone(),j=(A(f)||p(f)?f.valueOf():Et(f).valueOf())-_.valueOf(),_._d.setTime(_._d.valueOf()+j),r.updateOffset(_,!1),_):Et(f).local()}function Rc(f){return-Math.round(f._d.getTimezoneOffset())}r.updateOffset=function(){};function mE(f,v,_){var j=this._offset||0,O;if(!this.isValid())return f!=null?this:NaN;if(f!=null){if(typeof f=="string"){if(f=Ic(Ar,f),f===null)return this}else Math.abs(f)<16&&!_&&(f=f*60);return!this._isUTC&&v&&(O=Rc(this)),this._offset=f,this._isUTC=!0,O!=null&&this.add(O,"m"),j!==f&&(!v||this._changeInProgress?wh(this,er(f-j,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,r.updateOffset(this,!0),this._changeInProgress=null)),this}else return this._isUTC?j:Rc(this)}function hE(f,v){return f!=null?(typeof f!="string"&&(f=-f),this.utcOffset(f,v),this):-this.utcOffset()}function gE(f){return this.utcOffset(0,f)}function vE(f){return this._isUTC&&(this.utcOffset(0,f),this._isUTC=!1,f&&this.subtract(Rc(this),"m")),this}function xE(){if(this._tzm!=null)this.utcOffset(this._tzm,!1,!0);else if(typeof this._i=="string"){var f=Ic(en,this._i);f!=null?this.utcOffset(f):this.utcOffset(0,!0)}return this}function yE(f){return this.isValid()?(f=f?Et(f).utcOffset():0,(this.utcOffset()-f)%60===0):!1}function bE(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function wE(){if(!c(this._isDSTShifted))return this._isDSTShifted;var f={},v;return k(f,this),f=mh(f),f._a?(v=f._isUTC?g(f._a):Et(f._a),this._isDSTShifted=this.isValid()&&fE(f._a,v.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function SE(){return this.isValid()?!this._isUTC:!1}function CE(){return this.isValid()?this._isUTC:!1}function xh(){return this.isValid()?this._isUTC&&this._offset===0:!1}var _E=/^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,EE=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function er(f,v){var _=f,j=null,O,G,re;return Vo(f)?_={ms:f._milliseconds,d:f._days,M:f._months}:d(f)||!isNaN(+f)?(_={},v?_[v]=+f:_.milliseconds=+f):(j=_E.exec(f))?(O=j[1]==="-"?-1:1,_={y:0,d:et(j[fr])*O,h:et(j[Ut])*O,m:et(j[Kn])*O,s:et(j[Dr])*O,ms:et(Ec(j[Ci]*1e3))*O}):(j=EE.exec(f))?(O=j[1]==="-"?-1:1,_={y:_i(j[2],O),M:_i(j[3],O),w:_i(j[4],O),d:_i(j[5],O),h:_i(j[6],O),m:_i(j[7],O),s:_i(j[8],O)}):_==null?_={}:typeof _=="object"&&("from"in _||"to"in _)&&(re=IE(Et(_.from),Et(_.to)),_={},_.ms=re.milliseconds,_.M=re.months),G=new Lo(_),Vo(f)&&l(f,"_locale")&&(G._locale=f._locale),Vo(f)&&l(f,"_isValid")&&(G._isValid=f._isValid),G}er.fn=Lo.prototype,er.invalid=dE;function _i(f,v){var _=f&&parseFloat(f.replace(",","."));return(isNaN(_)?0:_)*v}function yh(f,v){var _={};return _.months=v.month()-f.month()+(v.year()-f.year())*12,f.clone().add(_.months,"M").isAfter(v)&&--_.months,_.milliseconds=+v-+f.clone().add(_.months,"M"),_}function IE(f,v){var _;return f.isValid()&&v.isValid()?(v=jc(v,f),f.isBefore(v)?_=yh(f,v):(_=yh(v,f),_.milliseconds=-_.milliseconds,_.months=-_.months),_):{milliseconds:0,months:0}}function bh(f,v){return function(_,j){var O,G;return j!==null&&!isNaN(+j)&&(V(v,"moment()."+v+"(period, number) is deprecated. Please use moment()."+v+"(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info."),G=_,_=j,j=G),O=er(_,j),wh(this,O,f),this}}function wh(f,v,_,j){var O=v._milliseconds,G=Ec(v._days),re=Ec(v._months);f.isValid()&&(j=j??!0,re&&rh(f,la(f,"Month")+re*_),G&&eh(f,"Date",la(f,"Date")+G*_),O&&f._d.setTime(f._d.valueOf()+O*_),j&&r.updateOffset(f,G||re))}var jE=bh(1,"add"),RE=bh(-1,"subtract");function Sh(f){return typeof f=="string"||f instanceof String}function kE(f){return A(f)||p(f)||Sh(f)||d(f)||NE(f)||AE(f)||f===null||f===void 0}function AE(f){var v=a(f)&&!u(f),_=!1,j=["years","year","y","months","month","M","days","day","d","dates","date","D","hours","hour","h","minutes","minute","m","seconds","second","s","milliseconds","millisecond","ms"],O,G,re=j.length;for(O=0;O<re;O+=1)G=j[O],_=_||l(f,G);return v&&_}function NE(f){var v=s(f),_=!1;return v&&(_=f.filter(function(j){return!d(j)&&Sh(f)}).length===0),v&&_}function OE(f){var v=a(f)&&!u(f),_=!1,j=["sameDay","nextDay","lastDay","nextWeek","lastWeek","sameElse"],O,G;for(O=0;O<j.length;O+=1)G=j[O],_=_||l(f,G);return v&&_}function DE(f,v){var _=f.diff(v,"days",!0);return _<-6?"sameElse":_<-1?"lastWeek":_<0?"lastDay":_<1?"sameDay":_<2?"nextDay":_<7?"nextWeek":"sameElse"}function ME(f,v){arguments.length===1&&(arguments[0]?kE(arguments[0])?(f=arguments[0],v=void 0):OE(arguments[0])&&(v=arguments[0],f=void 0):(f=void 0,v=void 0));var _=f||Et(),j=jc(_,this).startOf("day"),O=r.calendarFormat(this,j)||"sameElse",G=v&&(z(v[O])?v[O].call(this,_):v[O]);return this.format(G||this.localeData().calendar(O,this,Et(_)))}function FE(){return new I(this)}function TE(f,v){var _=A(f)?f:Et(f);return this.isValid()&&_.isValid()?(v=L(v)||"millisecond",v==="millisecond"?this.valueOf()>_.valueOf():_.valueOf()<this.clone().startOf(v).valueOf()):!1}function PE(f,v){var _=A(f)?f:Et(f);return this.isValid()&&_.isValid()?(v=L(v)||"millisecond",v==="millisecond"?this.valueOf()<_.valueOf():this.clone().endOf(v).valueOf()<_.valueOf()):!1}function LE(f,v,_,j){var O=A(f)?f:Et(f),G=A(v)?v:Et(v);return this.isValid()&&O.isValid()&&G.isValid()?(j=j||"()",(j[0]==="("?this.isAfter(O,_):!this.isBefore(O,_))&&(j[1]===")"?this.isBefore(G,_):!this.isAfter(G,_))):!1}function VE(f,v){var _=A(f)?f:Et(f),j;return this.isValid()&&_.isValid()?(v=L(v)||"millisecond",v==="millisecond"?this.valueOf()===_.valueOf():(j=_.valueOf(),this.clone().startOf(v).valueOf()<=j&&j<=this.clone().endOf(v).valueOf())):!1}function BE(f,v){return this.isSame(f,v)||this.isAfter(f,v)}function GE(f,v){return this.isSame(f,v)||this.isBefore(f,v)}function zE(f,v,_){var j,O,G;if(!this.isValid())return NaN;if(j=jc(f,this),!j.isValid())return NaN;switch(O=(j.utcOffset()-this.utcOffset())*6e4,v=L(v),v){case"year":G=Bo(this,j)/12;break;case"month":G=Bo(this,j);break;case"quarter":G=Bo(this,j)/3;break;case"second":G=(this-j)/1e3;break;case"minute":G=(this-j)/6e4;break;case"hour":G=(this-j)/36e5;break;case"day":G=(this-j-O)/864e5;break;case"week":G=(this-j-O)/6048e5;break;default:G=this-j}return _?G:Bn(G)}function Bo(f,v){if(f.date()<v.date())return-Bo(v,f);var _=(v.year()-f.year())*12+(v.month()-f.month()),j=f.clone().add(_,"months"),O,G;return v-j<0?(O=f.clone().add(_-1,"months"),G=(v-j)/(j-O)):(O=f.clone().add(_+1,"months"),G=(v-j)/(O-j)),-(_+G)||0}r.defaultFormat="YYYY-MM-DDTHH:mm:ssZ",r.defaultFormatUtc="YYYY-MM-DDTHH:mm:ss[Z]";function YE(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function HE(f){if(!this.isValid())return null;var v=f!==!0,_=v?this.clone().utc():this;return _.year()<0||_.year()>9999?ge(_,v?"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYYYY-MM-DD[T]HH:mm:ss.SSSZ"):z(Date.prototype.toISOString)?v?this.toDate().toISOString():new Date(this.valueOf()+this.utcOffset()*60*1e3).toISOString().replace("Z",ge(_,"Z")):ge(_,v?"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYY-MM-DD[T]HH:mm:ss.SSSZ")}function $E(){if(!this.isValid())return"moment.invalid(/* "+this._i+" */)";var f="moment",v="",_,j,O,G;return this.isLocal()||(f=this.utcOffset()===0?"moment.utc":"moment.parseZone",v="Z"),_="["+f+'("]',j=0<=this.year()&&this.year()<=9999?"YYYY":"YYYYYY",O="-MM-DD[T]HH:mm:ss.SSS",G=v+'[")]',this.format(_+j+O+G)}function WE(f){f||(f=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var v=ge(this,f);return this.localeData().postformat(v)}function UE(f,v){return this.isValid()&&(A(f)&&f.isValid()||Et(f).isValid())?er({to:this,from:f}).locale(this.locale()).humanize(!v):this.localeData().invalidDate()}function qE(f){return this.from(Et(),f)}function XE(f,v){return this.isValid()&&(A(f)&&f.isValid()||Et(f).isValid())?er({from:this,to:f}).locale(this.locale()).humanize(!v):this.localeData().invalidDate()}function ZE(f){return this.to(Et(),f)}function Ch(f){var v;return f===void 0?this._locale._abbr:(v=Fr(f),v!=null&&(this._locale=v),this)}var _h=P("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 Eh(){return this._locale}var Go=1e3,cs=60*Go,zo=60*cs,Ih=(365*400+97)*24*zo;function ds(f,v){return(f%v+v)%v}function jh(f,v,_){return f<100&&f>=0?new Date(f+400,v,_)-Ih:new Date(f,v,_).valueOf()}function Rh(f,v,_){return f<100&&f>=0?Date.UTC(f+400,v,_)-Ih:Date.UTC(f,v,_)}function JE(f){var v,_;if(f=L(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(_=this._isUTC?Rh:jh,f){case"year":v=_(this.year(),0,1);break;case"quarter":v=_(this.year(),this.month()-this.month()%3,1);break;case"month":v=_(this.year(),this.month(),1);break;case"week":v=_(this.year(),this.month(),this.date()-this.weekday());break;case"isoWeek":v=_(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case"day":case"date":v=_(this.year(),this.month(),this.date());break;case"hour":v=this._d.valueOf(),v-=ds(v+(this._isUTC?0:this.utcOffset()*cs),zo);break;case"minute":v=this._d.valueOf(),v-=ds(v,cs);break;case"second":v=this._d.valueOf(),v-=ds(v,Go);break}return this._d.setTime(v),r.updateOffset(this,!0),this}function QE(f){var v,_;if(f=L(f),f===void 0||f==="millisecond"||!this.isValid())return this;switch(_=this._isUTC?Rh:jh,f){case"year":v=_(this.year()+1,0,1)-1;break;case"quarter":v=_(this.year(),this.month()-this.month()%3+3,1)-1;break;case"month":v=_(this.year(),this.month()+1,1)-1;break;case"week":v=_(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case"isoWeek":v=_(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case"day":case"date":v=_(this.year(),this.month(),this.date()+1)-1;break;case"hour":v=this._d.valueOf(),v+=zo-ds(v+(this._isUTC?0:this.utcOffset()*cs),zo)-1;break;case"minute":v=this._d.valueOf(),v+=cs-ds(v,cs)-1;break;case"second":v=this._d.valueOf(),v+=Go-ds(v,Go)-1;break}return this._d.setTime(v),r.updateOffset(this,!0),this}function KE(){return this._d.valueOf()-(this._offset||0)*6e4}function eI(){return Math.floor(this.valueOf()/1e3)}function tI(){return new Date(this.valueOf())}function nI(){var f=this;return[f.year(),f.month(),f.date(),f.hour(),f.minute(),f.second(),f.millisecond()]}function rI(){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 iI(){return this.isValid()?this.toISOString():null}function sI(){return R(this)}function aI(){return m({},b(this))}function oI(){return b(this).overflow}function lI(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}K("N",0,0,"eraAbbr"),K("NN",0,0,"eraAbbr"),K("NNN",0,0,"eraAbbr"),K("NNNN",0,0,"eraName"),K("NNNNN",0,0,"eraNarrow"),K("y",["y",1],"yo","eraYear"),K("y",["yy",2],0,"eraYear"),K("y",["yyy",3],0,"eraYear"),K("y",["yyyy",4],0,"eraYear"),je("N",kc),je("NN",kc),je("NNN",kc),je("NNNN",yI),je("NNNNN",bI),gt(["N","NN","NNN","NNNN","NNNNN"],function(f,v,_,j){var O=_._locale.erasParse(f,j,_._strict);O?b(_).era=O:b(_).invalidEra=f}),je("y",wt),je("yy",wt),je("yyy",wt),je("yyyy",wt),je("yo",wI),gt(["y","yy","yyy","yyyy"],rn),gt(["yo"],function(f,v,_,j){var O;_._locale._eraYearOrdinalRegex&&(O=f.match(_._locale._eraYearOrdinalRegex)),_._locale.eraYearOrdinalParse?v[rn]=_._locale.eraYearOrdinalParse(f,O):v[rn]=parseInt(f,10)});function uI(f,v){var _,j,O,G=this._eras||Fr("en")._eras;for(_=0,j=G.length;_<j;++_)switch(typeof G[_].since==="string"&&(O=r(G[_].since).startOf("day"),G[_].since=O.valueOf()),typeof G[_].until){case"undefined":G[_].until=1/0;break;case"string":O=r(G[_].until).startOf("day").valueOf(),G[_].until=O.valueOf();break}return G}function cI(f,v,_){var j,O,G=this.eras(),re,Ie,He;for(f=f.toUpperCase(),j=0,O=G.length;j<O;++j)if(re=G[j].name.toUpperCase(),Ie=G[j].abbr.toUpperCase(),He=G[j].narrow.toUpperCase(),_)switch(v){case"N":case"NN":case"NNN":if(Ie===f)return G[j];break;case"NNNN":if(re===f)return G[j];break;case"NNNNN":if(He===f)return G[j];break}else if([re,Ie,He].indexOf(f)>=0)return G[j]}function dI(f,v){var _=f.since<=f.until?1:-1;return v===void 0?r(f.since).year():r(f.since).year()+(v-f.offset)*_}function fI(){var f,v,_,j=this.localeData().eras();for(f=0,v=j.length;f<v;++f)if(_=this.clone().startOf("day").valueOf(),j[f].since<=_&&_<=j[f].until||j[f].until<=_&&_<=j[f].since)return j[f].name;return""}function pI(){var f,v,_,j=this.localeData().eras();for(f=0,v=j.length;f<v;++f)if(_=this.clone().startOf("day").valueOf(),j[f].since<=_&&_<=j[f].until||j[f].until<=_&&_<=j[f].since)return j[f].narrow;return""}function mI(){var f,v,_,j=this.localeData().eras();for(f=0,v=j.length;f<v;++f)if(_=this.clone().startOf("day").valueOf(),j[f].since<=_&&_<=j[f].until||j[f].until<=_&&_<=j[f].since)return j[f].abbr;return""}function hI(){var f,v,_,j,O=this.localeData().eras();for(f=0,v=O.length;f<v;++f)if(_=O[f].since<=O[f].until?1:-1,j=this.clone().startOf("day").valueOf(),O[f].since<=j&&j<=O[f].until||O[f].until<=j&&j<=O[f].since)return(this.year()-r(O[f].since).year())*_+O[f].offset;return this.year()}function gI(f){return l(this,"_erasNameRegex")||Ac.call(this),f?this._erasNameRegex:this._erasRegex}function vI(f){return l(this,"_erasAbbrRegex")||Ac.call(this),f?this._erasAbbrRegex:this._erasRegex}function xI(f){return l(this,"_erasNarrowRegex")||Ac.call(this),f?this._erasNarrowRegex:this._erasRegex}function kc(f,v){return v.erasAbbrRegex(f)}function yI(f,v){return v.erasNameRegex(f)}function bI(f,v){return v.erasNarrowRegex(f)}function wI(f,v){return v._eraYearOrdinalRegex||wt}function Ac(){var f=[],v=[],_=[],j=[],O,G,re,Ie,He,nt=this.eras();for(O=0,G=nt.length;O<G;++O)re=Nr(nt[O].name),Ie=Nr(nt[O].abbr),He=Nr(nt[O].narrow),v.push(re),f.push(Ie),_.push(He),j.push(re),j.push(Ie),j.push(He);this._erasRegex=new RegExp("^("+j.join("|")+")","i"),this._erasNameRegex=new RegExp("^("+v.join("|")+")","i"),this._erasAbbrRegex=new RegExp("^("+f.join("|")+")","i"),this._erasNarrowRegex=new RegExp("^("+_.join("|")+")","i")}K(0,["gg",2],0,function(){return this.weekYear()%100}),K(0,["GG",2],0,function(){return this.isoWeekYear()%100});function Yo(f,v){K(0,[f,f.length],0,v)}Yo("gggg","weekYear"),Yo("ggggg","weekYear"),Yo("GGGG","isoWeekYear"),Yo("GGGGG","isoWeekYear"),je("G",Jt),je("g",Jt),je("GG",we,M),je("gg",we,M),je("GGGG",Xt,le),je("gggg",Xt,le),je("GGGGG",Zt,be),je("ggggg",Zt,be),aa(["gggg","ggggg","GGGG","GGGGG"],function(f,v,_,j){v[j.substr(0,2)]=et(f)}),aa(["gg","GG"],function(f,v,_,j){v[j]=r.parseTwoDigitYear(f)});function SI(f){return kh.call(this,f,this.week(),this.weekday()+this.localeData()._week.dow,this.localeData()._week.dow,this.localeData()._week.doy)}function CI(f){return kh.call(this,f,this.isoWeek(),this.isoWeekday(),1,4)}function _I(){return Mr(this.year(),1,4)}function EI(){return Mr(this.isoWeekYear(),1,4)}function II(){var f=this.localeData()._week;return Mr(this.year(),f.dow,f.doy)}function jI(){var f=this.localeData()._week;return Mr(this.weekYear(),f.dow,f.doy)}function kh(f,v,_,j,O){var G;return f==null?ca(this,j,O).year:(G=Mr(f,j,O),v>G&&(v=G),RI.call(this,f,v,_,j,O))}function RI(f,v,_,j,O){var G=ah(f,v,_,j,O),re=ua(G.year,0,G.dayOfYear);return this.year(re.getUTCFullYear()),this.month(re.getUTCMonth()),this.date(re.getUTCDate()),this}K("Q",0,"Qo","quarter"),je("Q",ee),gt("Q",function(f,v){v[Or]=(et(f)-1)*3});function kI(f){return f==null?Math.ceil((this.month()+1)/3):this.month((f-1)*3+this.month()%3)}K("D",["DD",2],"Do","date"),je("D",we,os),je("DD",we,M),je("Do",function(f,v){return f?v._dayOfMonthOrdinalParse||v._ordinalParse:v._dayOfMonthOrdinalParseLenient}),gt(["D","DD"],fr),gt("Do",function(f,v){v[fr]=et(f.match(we)[0])});var Ah=ls("Date",!0);K("DDD",["DDDD",3],"DDDo","dayOfYear"),je("DDD",zt),je("DDDD",q),gt(["DDD","DDDD"],function(f,v,_){_._dayOfYear=et(f)});function AI(f){var v=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return f==null?v:this.add(f-v,"d")}K("m",["mm",2],0,"minute"),je("m",we,mc),je("mm",we,M),gt(["m","mm"],Kn);var NI=ls("Minutes",!1);K("s",["ss",2],0,"second"),je("s",we,mc),je("ss",we,M),gt(["s","ss"],Dr);var OI=ls("Seconds",!1);K("S",0,0,function(){return~~(this.millisecond()/100)}),K(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),K(0,["SSS",3],0,"millisecond"),K(0,["SSSS",4],0,function(){return this.millisecond()*10}),K(0,["SSSSS",5],0,function(){return this.millisecond()*100}),K(0,["SSSSSS",6],0,function(){return this.millisecond()*1e3}),K(0,["SSSSSSS",7],0,function(){return this.millisecond()*1e4}),K(0,["SSSSSSSS",8],0,function(){return this.millisecond()*1e5}),K(0,["SSSSSSSSS",9],0,function(){return this.millisecond()*1e6}),je("S",zt,ee),je("SS",zt,M),je("SSS",zt,q);var ai,Nh;for(ai="SSSS";ai.length<=9;ai+="S")je(ai,wt);function DI(f,v){v[Ci]=et(("0."+f)*1e3)}for(ai="S";ai.length<=9;ai+="S")gt(ai,DI);Nh=ls("Milliseconds",!1),K("z",0,0,"zoneAbbr"),K("zz",0,0,"zoneName");function MI(){return this._isUTC?"UTC":""}function FI(){return this._isUTC?"Coordinated Universal Time":""}var fe=I.prototype;fe.add=jE,fe.calendar=ME,fe.clone=FE,fe.diff=zE,fe.endOf=QE,fe.format=WE,fe.from=UE,fe.fromNow=qE,fe.to=XE,fe.toNow=ZE,fe.get=$1,fe.invalidAt=oI,fe.isAfter=TE,fe.isBefore=PE,fe.isBetween=LE,fe.isSame=VE,fe.isSameOrAfter=BE,fe.isSameOrBefore=GE,fe.isValid=sI,fe.lang=_h,fe.locale=Ch,fe.localeData=Eh,fe.max=sE,fe.min=iE,fe.parsingFlags=aI,fe.set=W1,fe.startOf=JE,fe.subtract=RE,fe.toArray=nI,fe.toObject=rI,fe.toDate=tI,fe.toISOString=HE,fe.inspect=$E,typeof Symbol<"u"&&Symbol.for!=null&&(fe[Symbol.for("nodejs.util.inspect.custom")]=function(){return"Moment<"+this.format()+">"}),fe.toJSON=iI,fe.toString=YE,fe.unix=eI,fe.valueOf=KE,fe.creationData=lI,fe.eraName=fI,fe.eraNarrow=pI,fe.eraAbbr=mI,fe.eraYear=hI,fe.year=Km,fe.isLeapYear=H1,fe.weekYear=SI,fe.isoWeekYear=CI,fe.quarter=fe.quarters=kI,fe.month=ih,fe.daysInMonth=t_,fe.week=fe.weeks=u_,fe.isoWeek=fe.isoWeeks=c_,fe.weeksInYear=II,fe.weeksInWeekYear=jI,fe.isoWeeksInYear=_I,fe.isoWeeksInISOWeekYear=EI,fe.date=Ah,fe.day=fe.days=C_,fe.weekday=__,fe.isoWeekday=E_,fe.dayOfYear=AI,fe.hour=fe.hours=O_,fe.minute=fe.minutes=NI,fe.second=fe.seconds=OI,fe.millisecond=fe.milliseconds=Nh,fe.utcOffset=mE,fe.utc=gE,fe.local=vE,fe.parseZone=xE,fe.hasAlignedHourOffset=yE,fe.isDST=bE,fe.isLocal=SE,fe.isUtcOffset=CE,fe.isUtc=xh,fe.isUTC=xh,fe.zoneAbbr=MI,fe.zoneName=FI,fe.dates=P("dates accessor is deprecated. Use date instead.",Ah),fe.months=P("months accessor is deprecated. Use month instead",ih),fe.years=P("years accessor is deprecated. Use year instead",Km),fe.zone=P("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",hE),fe.isDSTShifted=P("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",wE);function TI(f){return Et(f*1e3)}function PI(){return Et.apply(null,arguments).parseZone()}function Oh(f){return f}var at=U.prototype;at.calendar=he,at.longDateFormat=Ye,at.invalidDate=Je,at.ordinal=Gt,at.preparse=Oh,at.postformat=Oh,at.relativeTime=Wt,at.pastFuture=Tt,at.set=Y,at.eras=uI,at.erasParse=cI,at.erasConvertYear=dI,at.erasAbbrRegex=vI,at.erasNameRegex=gI,at.erasNarrowRegex=xI,at.months=J1,at.monthsShort=Q1,at.monthsParse=e_,at.monthsRegex=r_,at.monthsShortRegex=n_,at.week=s_,at.firstDayOfYear=l_,at.firstDayOfWeek=o_,at.weekdays=x_,at.weekdaysMin=b_,at.weekdaysShort=y_,at.weekdaysParse=S_,at.weekdaysRegex=I_,at.weekdaysShortRegex=j_,at.weekdaysMinRegex=R_,at.isPM=A_,at.meridiem=D_;function Ho(f,v,_,j){var O=Fr(),G=g().set(j,v);return O[_](G,f)}function Dh(f,v,_){if(d(f)&&(v=f,f=void 0),f=f||"",v!=null)return Ho(f,v,_,"month");var j,O=[];for(j=0;j<12;j++)O[j]=Ho(f,j,_,"month");return O}function Nc(f,v,_,j){typeof f=="boolean"?(d(v)&&(_=v,v=void 0),v=v||""):(v=f,_=v,f=!1,d(v)&&(_=v,v=void 0),v=v||"");var O=Fr(),G=f?O._week.dow:0,re,Ie=[];if(_!=null)return Ho(v,(_+G)%7,j,"day");for(re=0;re<7;re++)Ie[re]=Ho(v,(re+G)%7,j,"day");return Ie}function LI(f,v){return Dh(f,v,"months")}function VI(f,v){return Dh(f,v,"monthsShort")}function BI(f,v,_){return Nc(f,v,_,"weekdays")}function GI(f,v,_){return Nc(f,v,_,"weekdaysShort")}function zI(f,v,_){return Nc(f,v,_,"weekdaysMin")}si("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 v=f%10,_=et(f%100/10)===1?"th":v===1?"st":v===2?"nd":v===3?"rd":"th";return f+_}}),r.lang=P("moment.lang is deprecated. Use moment.locale instead.",si),r.langData=P("moment.langData is deprecated. Use moment.localeData instead.",Fr);var Tr=Math.abs;function YI(){var f=this._data;return this._milliseconds=Tr(this._milliseconds),this._days=Tr(this._days),this._months=Tr(this._months),f.milliseconds=Tr(f.milliseconds),f.seconds=Tr(f.seconds),f.minutes=Tr(f.minutes),f.hours=Tr(f.hours),f.months=Tr(f.months),f.years=Tr(f.years),this}function Mh(f,v,_,j){var O=er(v,_);return f._milliseconds+=j*O._milliseconds,f._days+=j*O._days,f._months+=j*O._months,f._bubble()}function HI(f,v){return Mh(this,f,v,1)}function $I(f,v){return Mh(this,f,v,-1)}function Fh(f){return f<0?Math.floor(f):Math.ceil(f)}function WI(){var f=this._milliseconds,v=this._days,_=this._months,j=this._data,O,G,re,Ie,He;return f>=0&&v>=0&&_>=0||f<=0&&v<=0&&_<=0||(f+=Fh(Oc(_)+v)*864e5,v=0,_=0),j.milliseconds=f%1e3,O=Bn(f/1e3),j.seconds=O%60,G=Bn(O/60),j.minutes=G%60,re=Bn(G/60),j.hours=re%24,v+=Bn(re/24),He=Bn(Th(v)),_+=He,v-=Fh(Oc(He)),Ie=Bn(_/12),_%=12,j.days=v,j.months=_,j.years=Ie,this}function Th(f){return f*4800/146097}function Oc(f){return f*146097/4800}function UI(f){if(!this.isValid())return NaN;var v,_,j=this._milliseconds;if(f=L(f),f==="month"||f==="quarter"||f==="year")switch(v=this._days+j/864e5,_=this._months+Th(v),f){case"month":return _;case"quarter":return _/3;case"year":return _/12}else switch(v=this._days+Math.round(Oc(this._months)),f){case"week":return v/7+j/6048e5;case"day":return v+j/864e5;case"hour":return v*24+j/36e5;case"minute":return v*1440+j/6e4;case"second":return v*86400+j/1e3;case"millisecond":return Math.floor(v*864e5)+j;default:throw new Error("Unknown unit "+f)}}function Pr(f){return function(){return this.as(f)}}var Ph=Pr("ms"),qI=Pr("s"),XI=Pr("m"),ZI=Pr("h"),JI=Pr("d"),QI=Pr("w"),KI=Pr("M"),ej=Pr("Q"),tj=Pr("y"),nj=Ph;function rj(){return er(this)}function ij(f){return f=L(f),this.isValid()?this[f+"s"]():NaN}function Ei(f){return function(){return this.isValid()?this._data[f]:NaN}}var sj=Ei("milliseconds"),aj=Ei("seconds"),oj=Ei("minutes"),lj=Ei("hours"),uj=Ei("days"),cj=Ei("months"),dj=Ei("years");function fj(){return Bn(this.days()/7)}var Lr=Math.round,fs={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function pj(f,v,_,j,O){return O.relativeTime(v||1,!!_,f,j)}function mj(f,v,_,j){var O=er(f).abs(),G=Lr(O.as("s")),re=Lr(O.as("m")),Ie=Lr(O.as("h")),He=Lr(O.as("d")),nt=Lr(O.as("M")),pn=Lr(O.as("w")),Vr=Lr(O.as("y")),oi=G<=_.ss&&["s",G]||G<_.s&&["ss",G]||re<=1&&["m"]||re<_.m&&["mm",re]||Ie<=1&&["h"]||Ie<_.h&&["hh",Ie]||He<=1&&["d"]||He<_.d&&["dd",He];return _.w!=null&&(oi=oi||pn<=1&&["w"]||pn<_.w&&["ww",pn]),oi=oi||nt<=1&&["M"]||nt<_.M&&["MM",nt]||Vr<=1&&["y"]||["yy",Vr],oi[2]=v,oi[3]=+f>0,oi[4]=j,pj.apply(null,oi)}function hj(f){return f===void 0?Lr:typeof f=="function"?(Lr=f,!0):!1}function gj(f,v){return fs[f]===void 0?!1:v===void 0?fs[f]:(fs[f]=v,f==="s"&&(fs.ss=v-1),!0)}function vj(f,v){if(!this.isValid())return this.localeData().invalidDate();var _=!1,j=fs,O,G;return typeof f=="object"&&(v=f,f=!1),typeof f=="boolean"&&(_=f),typeof v=="object"&&(j=Object.assign({},fs,v),v.s!=null&&v.ss==null&&(j.ss=v.s-1)),O=this.localeData(),G=mj(this,!_,j,O),_&&(G=O.pastFuture(+this,G)),O.postformat(G)}var Dc=Math.abs;function ps(f){return(f>0)-(f<0)||+f}function $o(){if(!this.isValid())return this.localeData().invalidDate();var f=Dc(this._milliseconds)/1e3,v=Dc(this._days),_=Dc(this._months),j,O,G,re,Ie=this.asSeconds(),He,nt,pn,Vr;return Ie?(j=Bn(f/60),O=Bn(j/60),f%=60,j%=60,G=Bn(_/12),_%=12,re=f?f.toFixed(3).replace(/\.?0+$/,""):"",He=Ie<0?"-":"",nt=ps(this._months)!==ps(Ie)?"-":"",pn=ps(this._days)!==ps(Ie)?"-":"",Vr=ps(this._milliseconds)!==ps(Ie)?"-":"",He+"P"+(G?nt+G+"Y":"")+(_?nt+_+"M":"")+(v?pn+v+"D":"")+(O||j||f?"T":"")+(O?Vr+O+"H":"")+(j?Vr+j+"M":"")+(f?Vr+re+"S":"")):"P0D"}var rt=Lo.prototype;rt.isValid=cE,rt.abs=YI,rt.add=HI,rt.subtract=$I,rt.as=UI,rt.asMilliseconds=Ph,rt.asSeconds=qI,rt.asMinutes=XI,rt.asHours=ZI,rt.asDays=JI,rt.asWeeks=QI,rt.asMonths=KI,rt.asQuarters=ej,rt.asYears=tj,rt.valueOf=nj,rt._bubble=WI,rt.clone=rj,rt.get=ij,rt.milliseconds=sj,rt.seconds=aj,rt.minutes=oj,rt.hours=lj,rt.days=uj,rt.weeks=fj,rt.months=cj,rt.years=dj,rt.humanize=vj,rt.toISOString=$o,rt.toString=$o,rt.toJSON=$o,rt.locale=Ch,rt.localeData=Eh,rt.toIsoString=P("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",$o),rt.lang=_h,K("X",0,0,"unix"),K("x",0,0,"valueOf"),je("x",Jt),je("X",L1),gt("X",function(f,v,_){_._d=new Date(parseFloat(f)*1e3)}),gt("x",function(f,v,_){_._d=new Date(et(f))});return r.version="2.30.1",i(Et),r.fn=fe,r.min=aE,r.max=oE,r.now=lE,r.utc=g,r.unix=TI,r.months=LI,r.isDate=p,r.locale=si,r.invalid=w,r.duration=er,r.isMoment=A,r.weekdays=BI,r.parseZone=PI,r.localeData=Fr,r.isDuration=Vo,r.monthsShort=VI,r.weekdaysMin=zI,r.defineLocale=bc,r.updateLocale=P_,r.locales=L_,r.weekdaysShort=GI,r.normalizeUnits=L,r.relativeTimeRounding=hj,r.relativeTimeThreshold=gj,r.calendarFormat=DE,r.prototype=fe,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}))})(Ml)),Ml.exports}var eU=KW();const gl=bi(eU);function oy({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r,expanded:i=!0}){const[s,a]=x.useState(null),[l,u]=x.useState(!1),[c,d]=x.useState(i),p=g=>{r(["issue","attachment","status_mail"]),r(["issue","status_mail"])},h=()=>n.filter(g=>g.issue.id===e.id),m=()=>{a(o.jsx(No,{equipment:t,showModal:!0,onClose:g=>{u(!1),g&&p()},issue:e,attachments:h()})),u(!0)};return o.jsxs("div",{className:"p-3 mb-4 border-bottom",children:[o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-2",children:[o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(hn,{bg:"dark",children:"Issue"}),o.jsx("h4",{className:e.date_closed?"text-danger mb-0":"mb-0",children:e.date_closed?o.jsx("s",{children:e.issue}):e.issue})]}),o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(de,{variant:"outline-primary",size:"sm",onClick:()=>d(g=>!g),"aria-label":"Toggle Details",children:c?"Hide Details":"Show Details"}),o.jsx(de,{variant:"secondary",size:"sm",onClick:m,"aria-label":"Edit Issue",children:"Edit"})]})]}),c&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"mb-2",children:o.jsx(ss,{children:e.description})}),o.jsx("p",{className:"mb-3",children:e.actions}),o.jsxs("div",{className:"d-flex flex-wrap gap-4 text-muted",children:[o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Creator"}),o.jsx("div",{className:"text-body",children:e.owner.full_name})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Date Created"}),o.jsx("div",{className:"text-body",children:gl(e.date_created).format("DD MMMM YYYY")})]}),e.date_closed&&o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Date Closed"}),o.jsx("div",{className:"text-body",children:gl(e.date_closed).format("DD MMMM YYYY")})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Forecast Up"}),o.jsx("div",{className:"text-body",children:gl(e.forecast_up).format("DD MMMM YYYY")})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Issue Type"}),o.jsxs("div",{className:"text-body",children:[e.issue_type===Wr.DEFAULT&&"Issue",e.issue_type===Wr.ESCALATION&&"Escalation",e.issue_type===Wr.PRIORITY&&"Priority"]})]}),o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Attachments"}),o.jsx("div",{className:"text-body",children:e.attachments})]}),e.updated_by&&o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Last Update By"}),o.jsx("div",{className:"text-body",children:e.updated_by.full_name})]}),e.last_update&&o.jsxs("div",{children:[o.jsx("small",{className:"text-muted",children:"Last Update"}),o.jsx("div",{className:"text-body",children:gl(e.last_update).format("DD MMMM YYYY")})]})]})]}),l&&s]})}function ly({reservations:e}){if(!e||e.length<1)return o.jsx(o.Fragment,{});const t=e[0];return o.jsx(Wi,{placement:"top",overlay:o.jsxs(xi,{id:`tooltip-${t.id}`,children:[o.jsx("h5",{children:t.title}),o.jsx("p",{children:e[0].active?"Currently active":`Upcoming in: ${ye(e[0].start).format("DD MMMM YYYY")}`}),o.jsx("p",{children:e[1]?`Next upcoming reservation in: ${ye(e[1].start).format("DD MMMM YYYY")}`:"No next upcoming reservations"})]}),children:o.jsxs(hn,{bg:e[0].active?"info":"dark",children:["Reserved by: ",e[0].user.full_name]})})}function tU({equipment:e,modules:t,issues:n,issueAttachments:r,ecnNotes:i,ecnAttachments:s,reloadQueryFn:a,showIssues:l,reservations:u}){const[c,d]=x.useState(null),[p,h]=x.useState(!1),[m,g]=x.useState(null),[y,b]=x.useState(!1),[S,R]=x.useState([]),[w,E]=x.useState(void 0),[C,k]=x.useState([]),[I,A]=x.useState([]),F=T=>{a(["ecn","attachment","status_mail"]),k([...C,T])},P=T=>{a(["issue","status_mail"]),a(["issue","attachment","status_mail"]),A([...I,T])};x.useEffect(()=>{k(i),A(n),R(t.filter(T=>T.equipment.id===e.id&&!T.type.is_main_tool)),E(t.findLast(T=>T.equipment.id===e.id&&T.type.is_main_tool))},[i,n,e,t]);const B=T=>C.filter(U=>U.module_id===T),V=T=>I.filter(U=>U.module_id===T),z=()=>{g(o.jsx(Ju,{equipment:e,showModal:!0,onClose:T=>{b(!1),T&&F(T)}})),b(!0)},Y=()=>{d(o.jsx(No,{equipment:e,showModal:!0,onClose:T=>{h(!1),T&&P(T)}})),h(!0)};return o.jsxs("div",{className:"card mb-4",children:[o.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsxs("h4",{className:"mb-0",children:[e.number," - ",e.name]}),w&&o.jsx(qi,{module:w}),w&&o.jsx(ly,{reservations:u.filter(T=>T.modules.some(U=>U.id===w.id))})]}),o.jsxs(fo,{as:cb,title:"Action",id:"bg-nested-dropdown",children:[o.jsx(Ue.Item,{eventKey:"1",onClick:z,children:"New ECN"}),l!==1&&o.jsx(Ue.Item,{eventKey:"1",onClick:Y,children:"New Issue"})]})]}),o.jsx("div",{className:"card-body",children:o.jsxs(Un,{children:[w&&o.jsx(Mt,{xs:12,md:S.length>0?6:12,children:o.jsx(Ze,{className:"mb-3",children:o.jsxs(Ze.Body,{children:[o.jsxs(Ze.Title,{className:"d-flex align-items-center",children:[o.jsx("span",{children:"Main module"}),o.jsx("div",{className:"ms-2"})]}),o.jsxs("div",{className:"mt-3",children:[B(w.id).map((T,U)=>o.jsx(sy,{ecn:T,equipment:e,ecnAttachments:s,reloadQueryFn:a,expanded:!0},U)),l!==1&&V(w.id).map((T,U)=>o.jsx(oy,{issue:T,equipment:e,issueAttachments:r,reloadQueryFn:a,expanded:l!==3},U))]})]})})}),S.length>0&&o.jsx(Mt,{xs:12,md:w?6:12,children:S.map((T,U)=>o.jsx(Ze,{className:"mb-3",children:o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{className:"d-flex align-items-center",children:o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx("span",{children:T.name}),o.jsx(qi,{module:T}),o.jsx(ly,{reservations:u.filter(ie=>ie.modules.some(oe=>oe.id===T.id))})]})}),o.jsxs("div",{className:"mt-3",children:[B(T.id).map((ie,oe)=>o.jsx(sy,{ecn:ie,equipment:e,ecnAttachments:s,reloadQueryFn:a,expanded:!0},oe)),l!==1&&V(T.id).map((ie,oe)=>o.jsx(oy,{issue:ie,equipment:e,issueAttachments:r,reloadQueryFn:a,expanded:l!==3},oe))]})]})},U))})]})}),y&&m,p&&c]})}const o1=({showModal:e,onClose:t,message:n})=>{const{register:r,handleSubmit:i,setValue:s,reset:a,control:l}=gn({defaultValues:{title:n?.title,description:n?.description,rooms:n?.rooms,type:n?.type,owner:n?.owner}}),[u,c]=x.useState([]),[d,p]=x.useState([]),[h,m]=x.useState(""),g=()=>document.documentElement.getAttribute("data-bs-theme")==="dark",y={control:w=>({...w,backgroundColor:g()?"#212529":w.backgroundColor,borderColor:g()?"#495057":w.borderColor,color:g()?"#fff":w.color}),menu:w=>({...w,backgroundColor:g()?"#212529":w.backgroundColor}),option:(w,E)=>({...w,backgroundColor:g()?E.isSelected?"#0d6efd":E.isFocused?"#343a40":"#212529":w.backgroundColor,color:g()?"#fff":w.color}),singleValue:w=>({...w,color:g()?"#fff":w.color}),multiValue:w=>({...w,backgroundColor:g()?"#343a40":w.backgroundColor}),multiValueLabel:w=>({...w,color:g()?"#fff":w.color}),input:w=>({...w,color:g()?"#fff":w.color})};let{statusMail:b}=x.useContext(Xu);x.useEffect(()=>{Ee.get("/list/room").then(w=>{const C=(w.data._embedded.items||[]).map(k=>({value:k,label:k.name}));c(C)}).catch(w=>{console.error("Error fetching rooms:",w),m("Error fetching rooms:"+w)}),Ee.get("/list/location/message/type").then(w=>{const E=b.filter.messageType,k=(w.data._embedded.items||[]).filter(I=>E.includes(I.id.toString())).map(I=>({value:I,label:I.type}));p(k),s("type",n?.type||k[0].value)}).catch(w=>{console.error("Error fetching message types:",w),m("Error fetching message types:"+w)})},[]);const S=w=>{if(w.title){if(w?.owner.value===void 0&&n?.owner===void 0)return"owner";if(w.rooms===void 0||w.rooms.map(E=>E.id).length<=0)return"room";if(!w.type)return"type"}else return"title";return""},R=async w=>{const E=S(w);if(E!==""){m("Please fill: "+E);return}try{const C={title:w.title,description:w.description,owner:w?.owner.value||n?.owner.id,type:w.type.id,rooms:w.rooms.map(I=>I.id)};let k;if(n?k=await Ee.patch(`/update/location/message/${n.id}`,C):k=await Ee.post("/create/location/message",C),k){t(k?.data),a();return}console.error("No response received"),m("No response received")}catch(C){console.error("Error submitting the form:",C),m("Error submitting the form:"+C)}};return o.jsx(xe,{show:e,size:"lg",centered:!0,onHide:()=>t(n),children:o.jsxs(H,{onSubmit:i(R),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Edit status mail message"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Title"}),o.jsx(H.Control,{type:"text",placeholder:"Enter the title",...r("title")})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Message"}),o.jsx(H.Control,{as:"textarea",rows:3,placeholder:"Give the message",...r("description")})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Owner"}),o.jsx(_o,{control:l,...r("owner",{required:"Owner is required"}),name:"owner"})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Rooms"}),o.jsx(ar,{name:"rooms",control:l,render:({field:w})=>o.jsx(Af,{isMulti:!0,options:u,classNamePrefix:"react-select",placeholder:"Select one or more rooms",value:u.filter(E=>w.value?.some(C=>C.id===E.value.id)),onChange:E=>w.onChange(E.map(C=>C.value)),styles:y})})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Type"}),o.jsx(ar,{name:"type",control:l,render:({field:w})=>o.jsx(Af,{options:d,classNamePrefix:"react-select",placeholder:"Select a message type",value:d.find(E=>E.value.id===w.value?.id)||null,onChange:E=>w.onChange(E?.value),styles:y})})]})]}),o.jsxs(xe.Footer,{children:[h!=""&&o.jsx("span",{className:"text-danger",children:h}),o.jsx(de,{variant:"secondary",onClick:()=>t(n),children:"Cancel"}),o.jsx(de,{variant:"primary",type:"submit",children:n?"Update Message":"Create Message"})]})]})})};function nU({message:e}){const[t,n]=x.useState(null),[r,i]=x.useState(!1),[s,a]=x.useState(e),l=c=>{a({...s,...c})},u=()=>{n(o.jsx(o1,{showModal:!0,onClose:c=>{i(!1),c&&l(c)},message:s})),i(!0)};return o.jsxs("div",{className:"card mb-4",children:[o.jsxs("div",{className:"card-header d-flex justify-content-between align-items-center",children:[o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(hn,{bg:"dark",children:s.type.type}),o.jsx("h5",{className:"mb-0",children:s.title})]}),o.jsx(de,{variant:"secondary",size:"sm",onClick:u,children:"Edit"})]}),o.jsx("div",{className:"card-body",children:o.jsx(ss,{children:s.description})}),o.jsx("div",{className:"card-footer bg-transparent",children:o.jsxs("small",{className:"text-muted d-flex flex-wrap gap-3",children:[o.jsxs("span",{children:["Created: ",ye(s.date_created).format("DD MMM YYYY")]}),s.last_update&&o.jsxs("span",{children:["Updated: ",ye(s.last_update).format("DD MMM YYYY")]}),s.rooms.length>0&&o.jsxs("span",{children:["Rooms:"," ",s.rooms.map((c,d)=>o.jsxs(x.Fragment,{children:[d>0&&", ",c.name]},c.id))]}),o.jsxs("span",{children:["Owner: ",s.owner.full_name]})]})}),r&&t]})}function rU({messageList:e,refetchFn:t}){const[n,r]=x.useState(null),[i,s]=x.useState(!1),a=()=>{r(o.jsx(o1,{showModal:!0,onClose:l=>{s(!1),t()}})),s(!0)};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"d-flex gap-3",children:[o.jsx("h2",{children:"Messages"}),o.jsx("div",{children:o.jsx(de,{variant:"secondary",onClick:a,children:"New message"})})]}),e.map((l,u)=>o.jsx("div",{children:o.jsx(nU,{message:l})},l.id)),i&&n]})}function iU({issue:e,moduleName:t,issueAttachments:n,equipment:r,reloadQueryFn:i}){const[s,a]=x.useState(null),[l,u]=x.useState(!1),c=h=>{i(["issue","status_mail"]),i(["issue","attachment","status_mail"])},d=()=>n.filter(h=>h.issue.id===e.id),p=()=>{if(!r){console.error("equipment is null in the table");return}u(!0),a(o.jsx(No,{equipment:r,showModal:!0,onClose:h=>{u(!1),h&&c()},issue:e,attachments:d()}))};return o.jsxs(o.Fragment,{children:[o.jsxs("tr",{className:"align-middle",children:[o.jsx("td",{className:"text-nowrap",children:t??"-"}),o.jsx("td",{children:e.issue}),o.jsx("td",{children:o.jsx(ss,{children:e.description})}),o.jsx("td",{className:"text-nowrap",children:ye(e.forecast_up).format("DD MMMM YYYY")}),o.jsx("td",{className:"text-nowrap",children:e.owner.full_name}),o.jsx("td",{className:"text-center",children:o.jsx("button",{type:"button",className:"btn btn-sm btn-outline-light",onClick:p,children:"Edit"})})]},e.id),l&&s]})}function sU({issues:e,modules:t,issueAttachments:n,reloadQueryFn:r}){return o.jsx("div",{className:"table-responsive",children:o.jsxs("table",{className:"table table-hover table-striped table-bordered table-sm",children:[o.jsx("thead",{className:"bg-primary text-white",children:o.jsxs("tr",{children:[o.jsx("th",{scope:"col",children:"Module"}),o.jsx("th",{scope:"col",children:"Issue"}),o.jsx("th",{scope:"col",children:"Description"}),o.jsx("th",{scope:"col",children:"Forecast Up"}),o.jsx("th",{scope:"col",children:"Owner"}),o.jsx("th",{scope:"col",className:"text-center",children:"Actions"})]})}),o.jsx("tbody",{children:e.map(i=>o.jsx(iU,{issue:i,moduleName:t.find(s=>s.id===i.module_id)?.name,issueAttachments:n,equipment:t.find(s=>s.id===i.module_id)?.equipment,reloadQueryFn:r},i.id))})]})})}function aU({statusMail:e}){const[t,n]=x.useState(!1),[r,i]=x.useState(!1),s=async()=>{try{if(n(!0),!e.id||e.id<=0)throw new Error("Status Mail ID is not correctly set");const a={status_mail:e.id};await Ee.post("/send/status-mail",a),i(!0)}catch(a){console.error("Error sending status mail:",a),alert("Error sending status mail. Please try again.")}finally{n(!1)}};return o.jsx(de,{variant:"primary",size:"sm",onClick:s,disabled:t,"aria-label":"Toggle Details",children:t?"Sending...":r?"Sending successful":"Send Status Mail"})}function oU(){let{statusMail:e}=x.useContext(Xu);const[t,n]=x.useState([]),r=Pe.useQueryClient(),i=Pe.useQueries({queries:[{queryKey:["equipment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Vy({statusMail:e})},{queryKey:["module","status_mail",JSON.stringify(e.filter)],queryFn:()=>Hi({statusMail:e})},{queryKey:["ecn","status_mail",JSON.stringify(e.filter)],queryFn:()=>up({statusMail:e})},{queryKey:["issue","status_mail",JSON.stringify(e.filter)],queryFn:()=>zy({statusMail:e})},{queryKey:["messages","status_mail",JSON.stringify(e.filter)],queryFn:()=>ck({statusMail:e})},{queryKey:["ecn","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>By({statusMail:e})},{queryKey:["issue","attachment","status_mail",JSON.stringify(e.filter)],queryFn:()=>Gy({statusMail:e})},{queryKey:["reservation","active","status_mail",JSON.stringify(e.filter)],queryFn:()=>Tl({which:"active"})},{queryKey:["reservation","upcoming","status_mail",JSON.stringify(e.filter)],queryFn:()=>Tl({which:"upcoming"})}]}),s=E=>{let C=E;C.push(JSON.stringify(e.filter)),r.refetchQueries({queryKey:C})},[a,l,u,c,d,p,h,m,g]=i,y=i.some(E=>E.isLoading),b=i.some(E=>E.isError),S=i.every(E=>E.isSuccess);x.useEffect(()=>{S&&n(a.data.items)},[S]);const R=()=>{if(!t.length)return o.jsx("p",{children:"No equipment available."});t.sort((I,A)=>e.classification===ji.ROOM?I.room.name.localeCompare(A.room.name):e.classification===ji.AREA?I.area.localeCompare(A.area):e.classification===ji.AREA_PER_FACILITY?I.facility.localeCompare(A.facility)||I.area.localeCompare(A.area):0);let E="",C="",k="";return t.map((I,A)=>{const F=[];return e.classification===ji.ROOM?I.room.name!==k&&(F.push(o.jsxs("h2",{children:["Room: ",I.room.name]},`room-${I.room.name}`)),k=I.room.name):e.classification===ji.AREA?I.area!==C&&(F.push(o.jsxs("h2",{children:["Area: ",I.area]},`area-${I.area}`)),C=I.area):e.classification===ji.AREA_PER_FACILITY&&(I.facility!==E&&(F.push(o.jsxs("h2",{children:["Facility: ",I.facility]},`facility-${I.facility}`)),E=I.facility),I.area!==C&&(F.push(o.jsxs("h4",{children:["Area: ",I.area]},`area-${I.area}`)),C=I.area)),F.push(o.jsx(tU,{equipment:I,modules:l.data.items,issues:c.data.items,issueAttachments:h.data.items,ecnNotes:u.data.items,ecnAttachments:p.data.items,reloadQueryFn:s,showIssues:e.show_issues,reservations:e.show_reservations?m.data.items.concat(g.data.items):[]},A)),F})},w=()=>{const E=c.data.items.filter(C=>C.issue_type===2);return E.length===0?o.jsx(o.Fragment,{}):o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:"Issues with priority"}),o.jsx(sU,{issues:E,modules:l.data.items,issueAttachments:h.data.items,reloadQueryFn:s})]})};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"d-flex justify-content-between align-items-center",children:[o.jsxs("h1",{className:"display-4",children:["Status mail ",e.name]}),o.jsx("div",{children:o.jsx(aU,{statusMail:e})})]}),o.jsx("p",{children:e.subject}),y&&o.jsx(Bt,{variant:"info",children:"Loading status mail"}),b&&o.jsx(Bt,{variant:"danger",children:"Error loading status mail"}),S&&e.show_issues_with_priority&&w(),S&&d.data&&o.jsx(rU,{messageList:d.data.items,refetchFn:d.refetch}),S&&R()]})}function lU(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 uU(e,t){const n=lU(e);if(!n)return"";const r=a=>a.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 s=t;return Object.keys(i).sort((a,l)=>l.length-a.length).forEach(a=>{s=s.replace(new RegExp(a,"g"),i[a])}),s}function Ln(e,t="DD-MM-YY HH:mm"){return uU(e,t)}function Um({monitor:e}){const{environment:t}=Te.useParams(),[n]=Pe.useQueries({queries:[{queryKey:["requirement",e],queryFn:()=>Yy({monitorId:e.id})}]});return n.isLoading?o.jsx("div",{children:"Loading requirements..."}):n.data?.items.map((r,i)=>{let s="bg-secondary-subtle";if(r.latest_result)for(let a=0;a<r.latest_result.values.length;a++){if(r.latest_result.values[a].value_is_valid===!1){s="bg-danger-subtle";break}if(r.latest_result.values[a].value_is_valid===!0){s="bg-success-subtle";break}}return o.jsx(Ze,{className:"mb-2 me-2",children:o.jsxs(Ze.Body,{className:s,children:[o.jsx(Ze.Title,{children:o.jsx(Te.Link,{to:`/${t}/operator/monitor/`+e.id,children:e.name})}),o.jsxs(Ze.Text,{children:[r.title,r.latest_result&&o.jsxs(o.Fragment,{children:["Latest measurement: ",Ln(r.latest_result.date_created,"DD-MM-YY HH:mm")]})]})]})},i)})}const l1=({moduleId:e,size:t})=>{const[n,r]=x.useState(!1),[i,s]=x.useState(!1),[a,l]=x.useState("");function u(){Ee.create().post("create/equipment/module/changelog",{module:e,changelog:a}).finally(()=>{r(!1),s(!0),l("")})}const c=p=>{l(p.target.value)};function d(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>s(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Assist logged"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Assist was logged successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"primary",size:t,onClick:()=>r(!0),children:"Log assist"}),o.jsxs(xe,{show:n,size:"lg",onHide:()=>r(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Log assist"})}),o.jsx(xe.Body,{children:o.jsx(H,{children:o.jsxs(H.Group,{className:"mb-3",controlId:"modal.ControlTextarea1",children:[o.jsx(H.Label,{children:"Describe the assist"}),o.jsx(H.Control,{as:"textarea",rows:3,value:a,onChange:p=>c(p)})]})})}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",variant:"primary",onClick:()=>u(),children:"Log assist"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{r(!1)},children:"Close"})]})]}),o.jsx(d,{})]})},fc=x.createContext({equipment:{},reloadEquipment:()=>{}});function cU({issue:e,equipment:t,issueAttachments:n,reloadQueryFn:r}){const[i,s]=x.useState(null),[a,l]=x.useState(!1),[u,c]=x.useState(e),d=m=>{r(["issue",t.name]),r(["issue","attachment",t.name]),c({...u,...m})},p=()=>n.filter(m=>m.issue.id===e.id),h=()=>{s(o.jsx(No,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},issue:u,attachments:p()})),l(!0)};return o.jsxs("div",{children:[o.jsxs(Ze,{className:"my-2",children:[o.jsxs(Ze.Body,{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs(Ze.Title,{children:[o.jsx(hn,{bg:"dark",children:"Issue"})," ",u.issue]}),o.jsx(de,{variant:"secondary",size:"sm",onClick:h,children:"Edit"})]}),o.jsx(Ze.Text,{children:o.jsx(ss,{children:u.description})})]}),o.jsxs(Wn,{className:"list-group-flush",children:[u.date_created&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Created:"}),o.jsx("span",{className:"ms-1",children:Ln(u.date_created,"DD-MM-YY HH:mm")})]}),u.owner&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Owner:"}),o.jsx("span",{className:"ms-1",children:u.owner.full_name})]}),u.updated_by&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Updated:"}),o.jsx("span",{className:"ms-1",children:u.updated_by.full_name}),o.jsxs("span",{className:"ms-1",children:["(",Ln(u.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},u.module_id),a&&i]})}function dU({ecn:e,equipment:t,ecnAttachments:n,reloadQueryFn:r}){const[i,s]=x.useState(null),[a,l]=x.useState(!1),[u,c]=x.useState(e),d=m=>{r(["ecn",t.name]),r(["ecn","attachment",t.name]),c({...u,...m})},p=()=>n.filter(m=>m.ecn.id===e.id),h=()=>{s(o.jsx(Ju,{equipment:t,showModal:!0,onClose:m=>{l(!1),m&&d(m)},ecn:u,attachments:p()})),l(!0)};return o.jsxs("div",{children:[o.jsxs(Ze,{className:"my-2",children:[o.jsxs(Ze.Body,{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs(Ze.Title,{children:[o.jsx(hn,{bg:"dark",children:"ECN"})," ",e.ecn]}),o.jsx(de,{variant:"secondary",size:"sm",onClick:h,children:"Edit"})]}),o.jsx(Ze.Text,{children:o.jsx(ss,{children:e.description})})]}),o.jsxs(Wn,{className:"list-group-flush",children:[u.date_created&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Created:"}),o.jsx("span",{className:"ms-1",children:Ln(u.date_created,"DD-MM-YY HH:mm")})]}),u.owner&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Owner:"}),o.jsx("span",{className:"ms-1",children:u.owner.full_name})]}),u.updated_by&&o.jsxs(Wn.Item,{className:"d-flex align-items-center",children:[o.jsx("span",{className:"text-muted",children:"Updated:"}),o.jsx("span",{className:"ms-1",children:u.updated_by.full_name}),o.jsxs("span",{className:"ms-1",children:["(",Ln(u.last_update,"DD-MM-YY HH:mm"),")"]})]})]})]},e.module_id),a&&i]})}function fU(){const{id:e}=Te.useParams(),[t,n]=x.useState([]),r=Pe.useQueries({queries:[{queryKey:["service","equipment",e],queryFn:()=>Ek({equipmentId:Number(e)})}]}),[i]=r,s=r.some(c=>c.isLoading),a=r.some(c=>c.isError),l=r.every(c=>c.isSuccess);if(x.useEffect(()=>{l&&n(i.data.items)},[l,i.data]),s)return o.jsx("div",{children:"Loading..."});if(a)return o.jsx("div",{children:"Error loading services."});const u=c=>{if(c<60)return`${c} min`;const d=Math.floor(c/60),p=c%60;return`${d}h ${p>0?`${p}min`:""}`.trim()};return i.data.items.length===0?o.jsxs("div",{children:[o.jsx("h2",{children:"Services"}),o.jsx(Bt,{variant:"info",children:"No services found"})]}):o.jsxs("div",{children:[o.jsx("h2",{children:"Services"}),o.jsxs(Kt,{striped:!0,bordered:!0,hover:!0,responsive:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Id"}),o.jsx("th",{children:"Name"}),o.jsx("th",{children:"Type"}),o.jsx("th",{children:"Team"}),o.jsx("th",{children:"Department"}),o.jsx("th",{children:"Duration"}),o.jsx("th",{children:"Report2"})]})}),o.jsx("tbody",{children:t.map(c=>o.jsxs("tr",{children:[o.jsx("td",{children:c.id}),o.jsx("td",{children:o.jsx("a",{href:`/${window.location.pathname.split("/")[1]}/service/details/${c.id}/general.html`,children:c.name})}),o.jsx("td",{children:c.type?.name||"N/A"}),o.jsx("td",{children:c.team?.name||"N/A"}),o.jsx("td",{children:c.department?.name||"N/A"}),o.jsx("td",{children:u(c.minutes_needed_for_service)}),o.jsx("td",{children:c.latest_event_report_id&&o.jsx("a",{className:"btn btn-primary btn-sm",href:`/${window.location.pathname.split("/")[1]}/service/event/report/${c.latest_event_report_id}/results`,children:"View Report"})})]},c.id))})]})]})}function pU(){const{environment:e}=Te.useParams(),{equipment:t}=x.useContext(fc),n=Pe.useQueryClient(),[r,i]=x.useState(null),[s,a]=x.useState(!1),[l,u]=x.useState(null),[c,d]=x.useState(!1),[p,h,m,g,y,b,S]=Pe.useQueries({queries:[{queryKey:["runs",t.name,e],queryFn:()=>yk({firstUnfinishedStepEquipment:t,environment:e})},{queryKey:["monitors",t.name],queryFn:()=>Hy({equipment:t})},{queryKey:["ecn",t.name],queryFn:()=>up({equipment:t})},{queryKey:["issue",t.name],queryFn:()=>zy({equipment:t})},{queryKey:["module",t.name],queryFn:()=>Hi({equipment:t})},{queryKey:["ecn","attachment",t.name],queryFn:()=>By({equipment:t})},{queryKey:["issue","attachment",t.name],queryFn:()=>Gy({equipment:t})}]}),R=I=>{n.invalidateQueries({queryKey:I})},w=I=>I?m.data?.items.filter(A=>A.module_id===I):[],E=I=>I?g.data?.items.filter(A=>A.module_id===I):[],C=()=>{u(o.jsx(Ju,{equipment:t,showModal:!0,onClose:()=>{d(!1),setTimeout(()=>{R(["ecn",t.name]),R(["ecn","attachment",t.name])},100)}})),d(!0)},k=()=>{i(o.jsx(No,{equipment:t,showModal:!0,onClose:()=>{a(!1),setTimeout(()=>{R(["issue",t.name]),R(["issue","attachment",t.name])},100)}})),a(!0)};return o.jsxs(es,{fluid:!0,children:[o.jsx("div",{className:"d-flex justify-content-left",children:h.data?.items&&h.data.items.map((I,A)=>o.jsx(Um,{monitor:I},A))}),o.jsxs(Un,{children:[o.jsxs(Mt,{md:8,children:[o.jsx("h2",{children:"Runs"}),p.isLoading&&o.jsx("div",{children:"Loading..."})," ",p.isError&&o.jsx("div",{children:"Error..."}),p.isFetched&&p.data&&p.data?.items.length===0&&o.jsx(Bt,{variant:"info",children:"No runs found"}),p.isFetched&&p.data&&p.data?.items.length>0&&o.jsxs(Kt,{striped:!0,bordered:!0,hover:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Run"}),o.jsx("th",{children:"Priority"}),o.jsx("th",{children:"Hold Code"}),o.jsx("th",{children:"Batch Card"}),o.jsx("th",{children:"Project"})]})}),o.jsx("tbody",{children:p.data?.items.map((I,A)=>o.jsxs("tr",{children:[o.jsxs("td",{children:[I.first_unfinished_step&&o.jsx(Te.Link,{to:`/${e}/operator/run/step/${I.first_unfinished_step.id}`,children:I.name}),I.first_unfinished_step===void 0&&I.last_finished_step&&o.jsx(Te.Link,{to:`/${e}/operator/run/step/${I.last_finished_step.id}`,children:I.name})]}),o.jsxs("td",{children:[I.priority&&o.jsx("span",{className:"badge",style:{backgroundColor:I.priority.priority.back_color,color:I.priority.priority.front_color},children:I.priority.priority.code}),!I.priority&&o.jsx("span",{className:"badge bg-info",children:"NORMAL"})]}),o.jsx("td",{children:I.hold_code&&o.jsx("span",{className:"badge handle",style:{backgroundColor:I.hold_code.hold_code.back_color,color:I.hold_code.hold_code.front_color},children:I.hold_code.hold_code.code})}),o.jsx("td",{children:I.batch_card&&I.batch_card.content&&o.jsx("span",{className:"text-danger",children:I.batch_card.content})}),o.jsx("td",{children:I.project.name})]},A))})]}),o.jsx(fU,{})]}),o.jsxs(Mt,{md:4,children:[o.jsx("h2",{children:"Assistance"}),y.data?.items.map((I,A)=>o.jsxs(x.Fragment,{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("h3",{children:I.type.is_main_tool?"Main tool":I.name}),o.jsx("div",{children:o.jsx(qi,{module:I})})]}),o.jsxs("div",{className:"pb-lg-5",children:[o.jsx("div",{className:"d-flex justify-content-between",children:o.jsxs("div",{className:"d-flex gap-2",children:[o.jsx("div",{children:o.jsx(de,{variant:"primary",size:"sm",onClick:k,children:"New Issue"})}),o.jsx("div",{children:o.jsx(de,{variant:"primary",size:"sm",onClick:C,children:"New ECN"})}),o.jsx("div",{children:I.type.is_main_tool&&o.jsx(l1,{size:"sm",moduleId:I.id})})]})}),w(I.id)?.map((F,P)=>o.jsx(dU,{ecn:F,equipment:t,ecnAttachments:b.data?.items??[],reloadQueryFn:R},`ecn-${A}-${P}`)),E(I.id)?.map((F,P)=>o.jsx(cU,{issue:F,equipment:t,issueAttachments:S.data?.items??[],reloadQueryFn:R},`issue-${A}-${P}`))]})]},A))]})]}),c&&l,s&&r]})}const mU=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&eg({id:parseInt(n)}).then(t)},[n,e]);function r(){eg({id:parseInt(n)}).then(t)}return{equipment:e,setEquipment:t,reloadEquipment:r}};function u1({children:e}){const{equipment:t,reloadEquipment:n}=mU();return t===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading Equipment"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading equipment"})})]})}):o.jsx(fc.Provider,{value:{equipment:t,reloadEquipment:n},children:e})}function hU(){const{equipment:e}=x.useContext(fc),t=Pe.useQueries({queries:[{queryKey:["activeReservationQuery",e],queryFn:()=>Tl({equipment:e,which:"active"})},{queryKey:["upcomingReservationQuery",e],queryFn:()=>Tl({equipment:e,which:"upcoming"})},{queryKey:["modules",e],queryFn:()=>Hi({equipment:e})}]}),[n,r,i]=t,s=t.some(l=>l.isLoading);t.some(l=>l.isError);const a=t.every(l=>l.isSuccess);return s?o.jsx("div",{children:"Loading..."}):(i.data?.items.findLast(l=>l.type.is_main_tool),a&&o.jsxs("div",{className:"d-flex align-items-center justify-content-between mb-3",children:[o.jsxs("h1",{className:"display-4",children:[e.name," Operator Dashboard"]}),o.jsxs("div",{children:[n.data?.items.map((l,u)=>o.jsxs("div",{className:"mx-2 p-2 rounded border-danger",style:{backgroundColor:l.color},children:[o.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Active reservation",o.jsx("br",{}),"Until ",Ln(l.end,"DD-MM-YY HH:mm")," by ",l.user.full_name]},u)),r.data?.items.map((l,u)=>o.jsxs("div",{className:"mx-2 p-2 rounded border-success border-2",style:{backgroundColor:l.color},children:[o.jsx("i",{className:"fa fa-calendar-o text-white pe-2","aria-hidden":"true"}),"Next reservation",o.jsx("br",{}),Ln(l.start,"DD-MM-YY HH:mm"),o.jsx("br",{}),l.user.full_name]},u))]})]}))}function gU(){return o.jsxs(u1,{children:[o.jsx(hU,{}),o.jsx(Te.Outlet,{})]})}function vU({children:e}){const{id:t}=Te.useParams(),n=Pe.useQuery({queryKey:["statusMail",t],queryFn:()=>sk({id:parseInt(t)}),enabled:!!t});return n.isLoading||n.isFetching?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading statusMail"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading status Mail"})})]})}):o.jsx(Xu.Provider,{value:{statusMail:n.data},children:e})}function xU(e){const[t,n]=x.useState(!0),[r,i]=x.useState(null),[s,a]=x.useState(!1),l=()=>{n(!1),a(!0)};return x.useEffect(()=>{if(!document){const p=new Error(`[ScriptLoadingError] document not defined when attempting to load ${e}`);i(p);return}const u=document.querySelector(`script[src="${e}"]`);if(u?.dataset.loaded){l();return}const c=u||document.createElement("script");u||(c.src=e);const d=()=>{c.dataset.loaded="1",l()};c.addEventListener("load",d),c.addEventListener("error",p=>{console.error("Failed to load script:",e,p);const h=new Error(`[ScriptLoadingError] Failed to load script: ${e}`);i(h)}),u||document.head.append(c)},[]),{isLoading:t,error:r,isSuccess:s}}const yU=e=>e&&e.charts,uy=(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)},bU=e=>window.google;function wU(e){const{chartVersion:t="current",chartPackages:n=["corechart","controls"],chartLanguage:r="en",mapsApiKey:i}=e,[s,a]=x.useState(null),[l,u]=x.useState(null),[c,d]=x.useState(null),{isLoading:p,error:h,isSuccess:m}=xU(e.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return x.useEffect(()=>{if(!m)return;const g=bU();if(!yU(g)){const y=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");u(y);return}if(uy(e,g)){a(g);return}g.charts.load(t,{packages:n,language:r,mapsApiKey:i}),g.charts.setOnLoadCallback(()=>{if(!uy(e,g)){const y=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(y),d(y);return}a(g)})},[m]),{error:h||l||c,isLoading:p,google:s}}const c1={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},SU=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:s,control:a}=i;return r?r({control:a,controlProp:s}):!0}).map(i=>{let{control:s}=i;return x.createElement("div",{key:s.getContainerId(),id:s.getContainerId()})}))};let cy=0;const d1=()=>(cy+=1,`reactgooglegraph-${cy}`),vr=class vr{};tr(vr,"initializeControls",t=>{for(let n=0;n<t.length;n+=1){const{controlType:r,options:i,controlWrapperParams:s}=t[n].controlProp;s&&"state"in s&&t[n].control.setState(s.state),t[n].control.setOptions(i),t[n].control.setControlType(r)}}),tr(vr,"listenToControlEvents",(t,n)=>{const{google:r}=n;return t.flatMap(i=>{const{control:s,controlProp:a}=i,{controlEvents:l=[]}=a;return l.map(u=>{const{callback:c,eventName:d}=u;return r.visualization.events.addListener(s,d,function(){for(var p=arguments.length,h=new Array(p),m=0;m<p;m++)h[m]=arguments[m];c({chartWrapper:null,controlWrapper:s,props:n,google:r,eventArgs:h})})})})}),tr(vr,"createControlId",t=>{let n;return typeof t>"u"?n=`googlechart-control-${d1()}`:n=t,n}),tr(vr,"createChartControls",t=>{const{controls:n,google:r}=t;return n?n.map((i,s)=>{const{controlID:a,controlType:l,options:u,controlWrapperParams:c}=i,d=vr.createControlId(a);return{controlProp:i,control:new r.visualization.ControlWrapper({containerId:d,controlType:l,options:u,...c})}}):null}),tr(vr,"addControls",t=>{const{chartWrapper:n,chartDashboard:r}=t,i=vr.createChartControls(t);return!i||!r||!n?null:(r.bind(i.map(s=>{let{control:a}=s;return a}),n),vr.initializeControls(i),i)});let pu=vr;const CU=e=>{const[t,n]=$.useState(null);return[$.useMemo(()=>!t||!e?null:e.map((i,s)=>{const a=t[s];return a?{controlProp:i,control:a}:void 0}).flatMap(i=>i?[i]:[]),[t,e]),n]},_U=(e,t)=>{$.useEffect(()=>{const n=pu.listenToControlEvents(e??[],t);return()=>{n.forEach(r=>{t.google.visualization.events.removeListener(r)})}},[e,t])},EU=e=>{const[t,n]=CU(e.controls);return _U(t??[],e),{addControls:i=>{const s=pu.addControls(i);n(s?.map(a=>a.control)??null)},renderControl:i=>{const{chartWrapper:s,chartDashboard:a}=e;return $.createElement(SU,{...e,isReady:!!(s&&a),chartControls:t,filter:i})}}},IU=e=>{const t=$.useRef(null);return{chartId:(()=>{const{graphID:i,graph_id:s}=e,a=i||s;let l;return a?l=a:l=t.current||d1(),t.current=l,t.current})()}},jU=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],RU=async function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((r,i)=>{const s=`${n.headers?`headers=${n.headers}`:"headers=0"}`,a=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,l=`${n.gid?`&gid=${n.gid}`:""}`,u=`${n.sheet?`&sheet=${n.sheet}`:""}`,c=`${n.access_token?`&access_token=${n.access_token}`:""}`,d=`${s}${l}${u}${a}${c}`,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())})})},kU="#CCCCCC",Gn=class Gn{};tr(Gn,"grayOutHiddenColumnsLabel",(t,n)=>{const{googleChartWrapper:r,options:i}=t;if(!r){console.error("googleChartWrapper is not defined");return}const s=r.getDataTable();if(!s)return;const a=s.getNumberOfColumns();if(n.length>0===!1)return;const u=Array.from({length:a-1}).map((c,d)=>{const p=Gn.getColumnId(s,d+1);return n.includes(p)?kU:i&&i.colors?i.colors[d]:jU[d]});r.setOptions({...i,colors:u}),r.draw()}),tr(Gn,"listenToLegendToggle",(t,n)=>{const[r,i]=n,{google:s,googleChartWrapper:a}=t;if(!a){console.error("googleChartWrapper is not defined");return}return s.visualization.events.addListener(a,"select",()=>{const u=a.getChart().getSelection(),c=a.getDataTable();if(u.length===0||u[0].row!==null||!c)return;const d=u[0].column,p=Gn.getColumnId(c,d);r?.includes(p)?i(h=>[...h.filter(m=>m!==p)]):i(h=>[...h,p])})}),tr(Gn,"draw",async t=>{const{data:n,diffdata:r,rows:i,columns:s,options:a,chartType:l,formatters:u,spreadSheetUrl:c,spreadSheetQueryParameters:d,googleChartDashboard:p,googleChartWrapper:h,google:m,hiddenColumns:g,legendToggle:y,legend_toggle:b}=t;if(!h){console.error("draw was called with googleChartWrapper = null");return}let S,R=null;if(r){const I=m.visualization.arrayToDataTable(r.old),A=m.visualization.arrayToDataTable(r.new);R=m.visualization[l].prototype.computeDiff(I,A)}n?n instanceof m.visualization.DataTable?S=n:Array.isArray(n)?S=m.visualization.arrayToDataTable(n):S=new m.visualization.DataTable(n):i&&s?S=m.visualization.arrayToDataTable([s,...i]):c?S=await RU(m,c,d):S=m.visualization.arrayToDataTable([]);const w=S.getNumberOfColumns(),E=Array(w).fill(0).map((I,A)=>{const F=Gn.getColumnId(S,A);return g.includes(F)?{label:S.getColumnLabel(A),type:S.getColumnType(A),calc:()=>null}:A}),C=h.getChart();h.getChartType()==="Timeline"&&C&&C.clearChart(),h.setChartType(l),h.setOptions(a||{});const k=new m.visualization.DataView(S);k.setColumns(E),h.setDataTable(k),h.draw(),p&&p.draw(S),R&&(h.setDataTable(R),h.draw()),u&&(Gn.applyFormatters({dataTable:S,formatters:u,google:m}),h.setDataTable(S),h.draw()),(y===!0||b===!0)&&Gn.grayOutHiddenColumnsLabel(t,g)}),tr(Gn,"getColumnId",(t,n)=>t.getColumnId(n)||t.getColumnLabel(n)),tr(Gn,"applyFormatters",t=>{let{dataTable:n,formatters:r,google:i}=t;for(let s of r)switch(s.type){case"ArrowFormat":{new i.visualization.ArrowFormat(s.options).format(n,s.column);return}case"BarFormat":{new i.visualization.BarFormat(s.options).format(n,s.column);return}case"ColorFormat":{const a=new i.visualization.ColorFormat(s.options),{ranges:l}=s;if(l)for(let u of l)a.addRange(...u);a.format(n,s.column);return}case"DateFormat":{new i.visualization.DateFormat(s.options).format(n,s.column);return}case"NumberFormat":{new i.visualization.NumberFormat(s.options).format(n,s.column);return}case"PatternFormat":{new i.visualization.PatternFormat(s.options).format(n,s.column);return}default:{console.warn(`Unknown formatter type: ${s.type}`);return}}});let La=Gn;const AU=e=>{const{google:t,googleChartWrapper:n,googleChartDashboard:r}=e,[i,s]=$.useState([]);$.useEffect(()=>{n&&La.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 a=()=>{const{googleChartWrapper:c}=e;c&&c.draw()},l=c=>{const d=[],{legendToggle:p,legend_toggle:h}=e;if(La.draw({...e,hiddenColumns:i,googleChartWrapper:c,googleChartDashboard:r,google:t}),window.addEventListener("resize",a),h||p){const m=La.listenToLegendToggle(e,[i,s]);m&&d.push(m)}return d},u=(c,d)=>{window.removeEventListener("resize",a),d.forEach(p=>{t.visualization.events.removeListener(p)}),c.getChartType()==="Timeline"&&c.getChart()&&c.getChart().clearChart()};$.useEffect(()=>{if(!n)return;const c=l(n);return()=>{u(n,c)}},[n,l,u])},NU=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:s,callback:a}=i;return n.visualization.events.addListener(r,s,function(){for(var l=arguments.length,u=new Array(l),c=0;c<l;c++)u[c]=arguments[c];a({chartWrapper:r,props:e,google:n,eventArgs:u})})})}},OU=e=>{x.useEffect(()=>{if(!e.googleChartWrapper)return;const t=NU(e);return()=>{t?.forEach(n=>{e.google.visualization.events.removeListener(n)})}},[e])},DU=e=>{const[t,n]=$.useState(null),[r,i]=$.useState(null),{addControls:s,renderControl:a}=EU({...e,chartDashboard:r,chartWrapper:t});OU({...e,googleChartWrapper:t});const{chartId:l}=IU(e),u=$.useRef(null),c=$.useRef(null);$.useEffect(()=>{const{options:S,google:R,chartType:w,chartWrapperParams:E,toolbarItems:C,getChartEditor:k,getChartWrapper:I,onLoad:A}=e,F={chartType:w,options:S,containerId:l,...E},P=new R.visualization.ChartWrapper(F);P.setOptions(S||{}),I?.(P,R);const B=new R.visualization.Dashboard(u.current);C&&R.visualization.drawToolbar(c.current,C);let V=null;k&&(V=new R.visualization.ChartEditor,k({chartEditor:V,chartWrapper:P,google:R})),s({...e,chartDashboard:B,chartWrapper:P}),n(P),i(B),A?.(R,{google:R,chartWrapper:P,chartEditor:V,chartDashboard:B})},[]),AU({...e,googleChartWrapper:t,googleChartDashboard:r});const d=()=>{const{width:S,height:R,options:w,style:E,className:C,rootProps:k,google:I}=e,A={height:R||w&&w.height,width:S||w&&w.width,...E};return $.createElement("div",{id:l,style:A,className:C,...k})},p=()=>e.toolbarItems?$.createElement("div",{ref:c}):null,{width:h,height:m,options:g,style:y}=e,b={height:m||g&&g.height,width:h||g&&g.width,...y};return e.render?$.createElement("div",{ref:u,style:b},$.createElement("div",{ref:c,id:"toolbar"}),e.render({renderChart:d,renderControl:a,renderToolbar:p})):$.createElement("div",{ref:u,style:b},a(S=>{let{controlProp:R}=S;return R.controlPosition!=="bottom"}),d(),a(S=>{let{controlProp:R}=S;return R.controlPosition==="bottom"}),p())},MU=$.createContext(c1),FU=e=>{let{children:t,value:n}=e;return $.createElement(MU.Provider,{value:n},t)},TU=e=>{const{google:t,isLoading:n,error:r}=wU(e);return n?e.loader??null:r?e.errorElement??null:t?x.createElement(DU,{google:t,...e}):null},PU=e=>{const t={...c1,...e};return x.createElement(FU,{value:t},x.createElement(TU,t))};var dy;(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"})(dy||(dy={}));function LU({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(s=>{s.values.filter(a=>a.logging_parameter.id===e.logging_parameter.id).filter(a=>a.float_value!==0).forEach(a=>{let l=new Date(s.date_created);r.push([l,a.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?o.jsx("div",{className:"text-center",children:"No data available"}):o.jsx(PU,{chartType:"ScatterChart",width:"100%",height:"400px",data:r,options:n})}const Oo=({data:e,setPage:t,setPageSize:n,pageSize:r,isPlaceholderData:i})=>{if(e===void 0||i)return o.jsx(o.Fragment,{});let s=[];for(let a=1;a<=e.amountOfPages;a++)s.push(o.jsx($g.Item,{active:a===e.currentPage,onClick:()=>t(l=>a),children:a},a));return o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs("div",{className:"d-flex gap-2",children:[o.jsx("div",{children:o.jsx(de,{size:"sm",onClick:()=>t(a=>Math.max(a-1,0)),disabled:e.currentPage===1,children:"Previous Page"})}),o.jsx($g,{size:"sm",children:s.map((a,l)=>o.jsx("div",{children:a},l))}),o.jsx("div",{children:o.jsx(de,{size:"sm",onClick:()=>{!i&&e.hasMore&&t(a=>a+1)},disabled:i||!e.hasMore,children:"Next Page"})})]}),n!==void 0?o.jsx("div",{children:o.jsxs(H.Select,{onChange:a=>{n(l=>parseInt(a.target.value))},value:r,size:"sm",children:[o.jsx("option",{value:10,children:"10"}),o.jsx("option",{value:25,children:"25"}),o.jsx("option",{value:50,children:"50"}),o.jsx("option",{value:100,children:"100"})]})}):null]})},VU=new Date().toISOString().split("T")[0],BU=({requirement:e,targets:t,refetchResults:n})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(!1),[l,u]=x.useState(!1),{control:c,register:d,handleSubmit:p,reset:h,watch:m,formState:{errors:g,isValid:y}}=gn({defaultValues:{date:VU}}),{fields:b,append:S,remove:R}=jD({control:c,name:"results",rules:{required:!0}});x.useEffect(()=>{R(),t.forEach(k=>{S({id:k.id,label:k.logging_parameter.name,logging_parameter_id:k.logging_parameter.id,value:""})})},[t]);const w=m();x.useEffect(()=>{u(y)},[w,y]);async function E(k){await Ee.post("create/monitor/requirement/result",{requirement:e.id,date:k.date,values:k.results}),a(!0),i(!1),n(),h()}function C(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>a(!1),show:s,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Results saved"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Measurement results were saved successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"primary",onClick:()=>i(!0),children:"Add manual result"}),o.jsx(xe,{show:r,size:"lg",onHide:()=>i(!1),children:o.jsxs(H,{onSubmit:p(k=>E(k)),validated:l,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Add manual result"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Date"}),o.jsx(H.Control,{type:"date",placeholder:"Date",required:!0,...d("date",{required:"This field is required"})},"date"),g.date&&o.jsx(H.Control.Feedback,{children:g.date.message})]}),b.map((k,I)=>o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:k.label}),o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{type:"number",step:.01,placeholder:k.label,required:!0,...d(`results.${I}.value`,{required:"This field is required"})},k.id),g?.results?.[I]?.value&&o.jsx(H.Control.Feedback,{children:g.results[I].value.message})]})]},I))]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{h(),i(!1)},children:"Close"})]})]})}),o.jsx(C,{})]})},GU=({requirement:e,result:t,refetchMonitorStepParameterValues:n})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(!1),[l,u]=x.useState(!1),[c,d]=x.useState([]),{control:p,register:h,handleSubmit:m,reset:g,watch:y,formState:{errors:b,isValid:S}}=gn({defaultValues:{}});x.useEffect(()=>{async function C(){const k=await $y({result:t}),I=await vk({requirement:e}),A=await uk({module:e.step.process_module.module});I.items=I.items.filter(F=>!k.items.map(P=>P.step_parameter.id).includes(F.id)),I.items=I.items.filter(F=>A.items.map(P=>P.parameter.id).includes(F.parameter.id)),d(I.items)}r&&C()},[r]);const R=y();x.useEffect(()=>{u(S)},[R,S]);async function w(C){await Ee.post("create/monitor/requirement/result/step-parameter-value",{result:t.id,step_parameter:C.module_step_parameter_id,value:C.value}),a(!0),i(!1),n(),g()}function E(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>a(!1),show:s,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Results saved"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Measurement results were saved successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"primary",size:"sm",onClick:()=>i(!0),children:"+"}),o.jsx(xe,{show:r,size:"lg",onHide:()=>i(!1),children:o.jsxs(H,{onSubmit:m(C=>w(C)),validated:l,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Add process parameter"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Date"}),o.jsx(H.Control,{type:"text",value:t.date_created,readOnly:!0})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Module Step Parameter"}),o.jsxs(H.Select,{...h("module_step_parameter_id",{required:!0}),children:[o.jsx("option",{value:"",children:"— Select a parameter"}),c.map(C=>o.jsx("option",{value:C.id,children:C.parameter.name},C.id))]}),o.jsx(H.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"})]}),o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{type:"number",step:.01,required:!0,...h("value",{required:"This field is required"})}),b?.value&&o.jsx(H.Control.Feedback,{children:b.value.message})]})]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",type:"submit",variant:"primary",children:"Add manual result"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{g(),i(!1)},children:"Close"})]})]})}),o.jsx(E,{})]})},zU=({monitorResultStepParameterValue:e,refetchMonitorStepParameterValues:t})=>{const[n,r]=x.useState(!1),[i,s]=x.useState(!1),[a,l]=x.useState(!1),{control:u,register:c,handleSubmit:d,reset:p,watch:h,formState:{errors:m,isValid:g}}=gn({defaultValues:{value:e.value.toString()}}),y=h();x.useEffect(()=>{l(g)},[y,g]);async function b(w){await Ee.patch("update/monitor/requirement/result/step-parameter-value/"+e.id,{value:w.value}),s(!0),r(!1),t(),p()}async function S(){await Ee.delete("delete/monitor/requirement/result/step-parameter-value/"+e.id,{}),s(!0),r(!1),t(),p()}function R(){return o.jsx(go,{position:"top-end",className:"p-3",children:o.jsxs(qn,{onClose:()=>s(!1),show:i,delay:3e3,autohide:!0,bg:"light",children:[o.jsxs(qn.Header,{children:[o.jsx("strong",{className:"me-auto",children:"Results saved"}),o.jsx("small",{children:"Just now"})]}),o.jsx(qn.Body,{children:"Measurement results were saved successfully"})]})})}return o.jsxs(o.Fragment,{children:[o.jsx("span",{onClick:()=>r(!0),children:e.value}),o.jsx(xe,{show:n,size:"lg",onHide:()=>r(!1),children:o.jsxs(H,{onSubmit:d(w=>b(w)),validated:a,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Add process parameter"})}),o.jsxs(xe.Body,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Date"}),o.jsx(H.Control,{type:"text",value:e.date_created,readOnly:!0})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Module Step Parameter"}),o.jsx(H.Control,{type:"text",value:e.step_parameter.parameter.name,readOnly:!0})]}),o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{type:"number",step:.01,required:!0,...c("value",{required:"This field is required"})}),m?.value&&o.jsx(H.Control.Feedback,{children:m.value.message})]})]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",type:"submit",variant:"primary",children:"Update value"}),o.jsx(de,{className:"float-end",variant:"danger",onClick:()=>S(),children:"Delete value"}),o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{p(),r(!1)},children:"Close"})]})]})}),o.jsx(R,{})]})};function YU({requirement:e}){const[n,r]=x.useState([]),[i,s]=x.useState(""),[a,l]=x.useState(1),[u,c]=x.useState(15),[d,p]=x.useState([]),[h,m,g,y]=Pe.useQueries({queries:[{queryKey:["requirement","files",e.step,11],queryFn:()=>gk({step:e.step,pageSize:11,order:"date-created",direction:"desc"})},{queryKey:["requirement","target",e],queryFn:()=>hk({requirement:e})},{queryKey:["requirement","results",e,a,u],queryFn:()=>mk({requirement:e,pageSize:u,order:"date-created",direction:"desc",page:a}),placeholderData:Pe.keepPreviousData},{queryKey:["requirement","monitor_step_parameters",e,a,u],queryFn:()=>$y({requirement:e,pageSize:u,order:"date-created",direction:"desc",page:a}),placeholderData:Pe.keepPreviousData}]});x.useEffect(()=>{r([]),!h.isLoading&&h.data.items.forEach(I=>{r(A=>[...A,I])})},[h.isLoading]),x.useEffect(()=>{if(!y.data)return;const I=Array.from(new Map(y.data.items.map(A=>[A.step_parameter.id,A.step_parameter])).values());p(I)},[y.isLoading,y.data]);const b=x.useCallback(I=>{I.forEach(A=>{const F=new FileReader;F.onload=async()=>{const P=F.result;try{await Ee.create().post("update/monitor/requirement/upload-file/"+e.id,{content:P,filename:A.name,type:A.type})}catch(B){s("Upload failed due to: "+B.response.data.detail)}await h.refetch(),await g.refetch()},F.readAsDataURL(A)})},[e.id,h,g]),{getRootProps:S,getInputProps:R,isDragActive:w,isDragAccept:E,isDragReject:C}=Co({onDrop:b}),k=x.useMemo(()=>({...w?{borderColor:"#83afee"}:{},...E?{borderColor:"#00e676"}:{},...C?{borderColor:"#ff1744"}:{}}),[E,C,w]);return m.isLoading||m.isFetching?o.jsx(Bt,{variant:"info",children:"Loading targets..."}):g.isLoading||g.isFetching?o.jsx(Bt,{variant:"info",children:"Loading results..."}):o.jsxs(o.Fragment,{children:[o.jsxs("h1",{className:"display-5",children:["Requirement: ",e.title]}),o.jsx("p",{className:"lead",children:e.definition}),o.jsx(Un,{className:"my-3",children:o.jsxs(Mt,{children:[o.jsx("h2",{children:"Charts"}),o.jsx("div",{className:"d-flex",children:m.data?.items.map((I,A)=>o.jsx(LU,{target:I,results:g.data.items},A))})]})}),o.jsxs(Un,{children:[o.jsxs(Mt,{md:8,children:[e.method&&e.method!=="-"&&o.jsxs(o.Fragment,{children:[o.jsx("h2",{children:"Method"}),o.jsx("p",{children:e.method})]}),m.data?.items.length===0&&o.jsx(Bt,{variant:"danger",children:"No targets found"}),o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("h2",{children:"Results"}),o.jsx("div",{children:o.jsx(BU,{requirement:e,targets:m.data.items,refetchResults:g.refetch})})]}),o.jsxs(Kt,{size:"sm",striped:!0,bordered:!0,hover:!0,children:[o.jsxs("thead",{children:[o.jsxs("tr",{children:[o.jsx("th",{children:"ID"}),o.jsx("th",{children:"Date"}),m.data?.items.map((I,A)=>o.jsx("th",{children:I.logging_parameter.name},A)),d.map((I,A)=>o.jsx("th",{children:I.parameter.name},A)),o.jsx("th",{children:"+"})]}),o.jsxs("tr",{children:[o.jsx("th",{colSpan:2}),m.data?.items.map((I,A)=>o.jsxs("td",{children:[I.min_value,I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:"≤"}),!I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:"<"}),I.target??"X",I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:"≥"}),!I.is_value_inclusive&&o.jsx("span",{className:"text-muted px-2",children:">"}),I.max_value]},A)),d.map((I,A)=>o.jsx("th",{className:"table-secondary"},A)),o.jsx("th",{})]})]}),o.jsx("tbody",{children:g.data?.items.map((I,A)=>o.jsxs("tr",{children:[o.jsx("th",{children:o.jsx("small",{className:"text-muted",children:I.id})},A),o.jsx("td",{children:Ln(I.date_created,"DD-MM-YY HH:mm")}),m.data?.items.map((F,P)=>o.jsx("td",{children:I.values.filter(B=>B.logging_parameter.id===F.logging_parameter.id).map((B,V)=>o.jsx("span",{className:B.value_is_valid?"text-success":"text-danger",children:B.float_value},V))},P)),d.map((F,P)=>o.jsx("td",{className:"table-secondary",children:y.data?.items.filter(B=>B.step_parameter.id===F.id&&B.result.id===I.id).map((B,V)=>o.jsx(zU,{monitorResultStepParameterValue:B,refetchMonitorStepParameterValues:y.refetch},V))},P)),o.jsx("td",{children:o.jsx(GU,{result:I,requirement:e,refetchMonitorStepParameterValues:y.refetch})})]},A))})]}),o.jsx(Oo,{data:g.data,setPage:l,setPageSize:c,pageSize:u,isPlaceholderData:g.isPlaceholderData})]}),o.jsxs(Mt,{md:4,children:[o.jsx("h2",{children:"Upload new results"}),o.jsx("p",{children:"Drop your results file here"}),o.jsxs("div",{...S({style:k,className:"dropzone"}),children:[o.jsx("input",{...R()}),w?o.jsx("p",{children:"Drop file(s) here ..."}):o.jsx("p",{children:"Drag and drop file(s) here, or click to select files"}),o.jsx("p",{children:i})]}),n.length>0&&o.jsxs(o.Fragment,{children:[o.jsx("h2",{className:"mt-2",children:"Uploaded files"}),o.jsxs("p",{children:["Last ",11," uploaded files"]}),o.jsx("ul",{className:"list-group",children:n.map((I,A)=>o.jsxs("li",{className:"list-group-item",children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsxs("span",{children:[A+1," ",o.jsx("a",{href:lm()+I.url,children:I.name}),I.has_monitor_step_loggings&&o.jsx(hn,{className:"ms-1 bg-primary",children:"Logging"})]}),o.jsxs("span",{children:[Math.round(I.size/1024),"kiB"]})]}),o.jsx("small",{className:"text-muted",children:Ln(I.date_created,"DD-MM-YY HH:mm")})]},A))})]})]})]})]})}function HU(){let{id:e}=Te.useParams();const[t,n]=Pe.useQueries({queries:[{queryKey:["monitor",e],queryFn:()=>Xd({id:parseInt(e)})},{queryKey:["requirements",e],queryFn:()=>Yy({monitorId:parseInt(e)})}]});return t.isLoading?o.jsx("div",{children:"Loading..."}):o.jsxs("div",{children:[o.jsxs("h1",{className:"display-4",children:["SPC Test ",t.data?.name]}),n.data?.items.map((r,i)=>o.jsx("div",{className:"border border-1 p-3 my-3",children:o.jsx(YU,{requirement:r})},i))]})}function $U(){return o.jsx(es,{fluid:!0,children:o.jsx(Te.Outlet,{})})}const WU=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{e===null&&Xd({id:parseInt(n)}).then(t)},[n,e]);function r(){Xd({id:parseInt(n)}).then(t)}return{monitor:e,setMonitor:t,reloadMonitor:r}},f1=x.createContext({monitor:{},reloadMonitor:()=>{}});function UU({children:e}){const{monitor:t,reloadMonitor:n}=WU();return t===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading Monitor"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading monitor"})})]})}):o.jsx(f1.Provider,{value:{monitor:t,reloadMonitor:n},children:e})}const qU=()=>{const[e,t]=x.useState(null),{id:n}=Te.useParams();x.useEffect(()=>{(e===null||n!==e.id.toString())&&Pl({id:parseInt(n)}).then(t)},[n,e]);function r(){Pl({id:parseInt(n)}).then(t)}return{run:e,reloadRun:r}},as=x.createContext({run:{},reloadRun:()=>{}});function p1({children:e}){const{run:t,reloadRun:n}=qU();return t===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[o.jsx("h1",{children:"Loading run"}),o.jsx("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:o.jsx("span",{className:"visually-hidden",children:"Loading run"})})]})}):o.jsx(as.Provider,{value:{run:t,reloadRun:n},children:e})}function XU({text:e}){if(!e)return null;const t=e.split(/\r\n|\n|\r/);return o.jsx(o.Fragment,{children:t.map((n,r)=>o.jsxs(x.Fragment,{children:[n,r<t.length-1&&o.jsx("br",{})]},r))})}const Zi=({children:e,format:t="d-M-Y"})=>{const n=Date.parse(e);return o.jsx(o.Fragment,{children:ye(n).format(t)})},m1=({run:e})=>{const[t,n]=x.useState(e.batch_card),[r,i]=x.useState(!1),{register:s,handleSubmit:a,formState:l,resetField:u}=gn({defaultValues:{content:t?.content}}),{isSubmitting:c,errors:d}=l,p=async m=>{await Ee.create().patch("update/run/batch-card/"+e.id,{content:m.content}),i(!1);const g=await Ee.get("view/run/"+e.id);n(g.data.batch_card)},h=async m=>{await Ee.create().delete("delete/run/batch-card/"+e.id),i(!1),n(void 0),u("content")};return r?o.jsxs(H,{onSubmit:a(p),className:"mb-3",children:[o.jsxs(un,{hasValidation:!0,children:[o.jsx(H.Control,{as:"textarea",rows:6,...s("content",{required:!0}),isInvalid:d.content!==void 0}),d.content&&o.jsx(H.Control.Feedback,{type:"invalid",children:"This field is required"})]}),o.jsxs("div",{className:"d-flex gap-2 justify-content-between mt-2",children:[o.jsxs("div",{children:[o.jsxs(de,{variant:"primary",type:"submit",disabled:c,children:[c&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save batch card"]}),o.jsx(de,{variant:"secondary",className:"ms-2",onClick:()=>i(!1),children:"Cancel"})]}),t&&o.jsx("div",{children:o.jsx(de,{variant:"danger",className:"ms-auto",onClick:()=>h(),children:"Delete batch card"})})]})]}):t?t&&o.jsxs(Ze,{className:"rounded my-4",children:[o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{className:"text-muted",children:"Batch card"}),o.jsx(Ze.Text,{children:t&&o.jsx("span",{className:"text-danger fs-3",children:o.jsx(XU,{text:t.content})})})]}),o.jsxs(Ze.Footer,{className:"d-flex justify-content-between align-items-center",children:[o.jsxs("div",{children:["Created by ",t.user.first_name," ",t.user.last_name," on"," ",o.jsx(Zi,{format:"DD-MM-YY",children:t.date_created}),t.last_update&&o.jsxs("span",{children:[" ","- Updated on ",o.jsx(Zi,{format:"DD-MM-YY H:m",children:t.last_update})]})]}),o.jsx("div",{children:o.jsx(de,{variant:"primary",size:"sm",onClick:()=>i(!0),children:"Update Batch Card"})})]})]}):o.jsx(de,{variant:"primary",className:"mb-4",onClick:()=>i(!0),children:"Create Batch Card"})};function ZU(){const{run:e}=x.useContext(as);return o.jsxs(o.Fragment,{children:[e.run_type===Hn.RESEARCH&&o.jsx("small",{children:"Research run"}),e.run_type===Hn.PRODUCTION&&o.jsx("small",{children:"Production run"}),o.jsx("div",{className:"d-flex justify-content-between align-items-center mb-3",children:o.jsxs("h1",{className:"display-4",children:[e.name," (",e.project.name,")"]})}),o.jsx(m1,{run:e})]})}function JU(e){const{run:t,reloadRun:n}=x.useContext(as),{environment:r}=Te.useParams(),i=window.location.pathname;let s=[{title:"Information",link:`/${r}/operator/run/details/${t.id}/information`}];return s.push({title:"Steps",link:`/${r}/operator/run/details/${t.id}/steps`}),o.jsx(zg,{variant:"tabs",className:e.className,defaultActiveKey:"/home",activeKey:i,children:s.map((a,l)=>o.jsx(zg.Item,{children:o.jsx(Te.Link,{to:a.link,className:"nav-link "+(a.link===i?"active":""),children:a.title})},l))})}function QU(){return o.jsx(p1,{children:o.jsxs(es,{fluid:!0,children:[o.jsx(ZU,{}),o.jsx(JU,{className:"mb-4"}),o.jsx(Te.Outlet,{})]})})}const pc=x.createContext({showOnlyEmphasizedParameters:!1,setShowOnlyEmphasizedParameters:()=>{}}),KU=({parameter:e,value:t,refetchFn:n})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(t.value),l=async u=>{const c={value:u};try{t.id!==void 0?await Ee.patch(`/update/run/step/parameter/value/${t.id}`,c):(c.parameter=e.id,await Ee.post("/create/run/step/parameter/value",c))}catch(d){console.error("Failed to update parameter value with error: ",d)}n(),i(!1)};return o.jsxs(o.Fragment,{children:[o.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"}),o.jsxs("div",{style:{display:r?"":"none"},className:"btn-group",children:[o.jsx("input",{type:"text",value:s??"",className:"form-control",onChange:u=>a(u.target.value)}),o.jsx("button",{onClick:()=>{l(s)},className:"btn btn-success btn-sm",children:o.jsx("i",{className:"fa fa-check"})}),o.jsx("button",{onClick:()=>{i(!1)},className:"btn btn-danger btn-sm",children:o.jsx("i",{className:"fa fa-times"})})]})]})},qm=({runStep:e,showOnlyEmphasizedParameters:t,editableParameters:n=!0,refetchFn:r})=>{const{data:i,isLoading:s}=Pe.useQuery({queryKey:["runStepParameters",e.id],queryFn:()=>Sk({runStep:e})}),a=Pe.useQueryClient(),l=()=>{a.refetchQueries({queryKey:["runStepParameters",e.id]}),r&&r()},u=i?.items??[],c=t?u.filter(d=>d.emphasize):u;return s?o.jsx("div",{children:"Loading..."}):u.length===0?o.jsx(Bt,{variant:"info",children:"No parameters found"}):o.jsxs(Kt,{children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Pos"}),o.jsx("th",{children:"Parameter"}),u[0].values.map((d,p)=>o.jsx("th",{children:"Value"},p)),o.jsx("th",{children:"Unit"})]})}),o.jsx("tbody",{children:c.length>0?c.map(d=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("small",{className:"text-muted",children:d.sequence})}),o.jsx("td",{children:d.parameter.name}),d.values.map((p,h)=>o.jsx("td",{children:n?o.jsx(KU,{parameter:d,refetchFn:l,value:p}):o.jsx("span",{children:p.value})},h)),o.jsx("td",{children:d.unit?.abbr??""})]},d.id)):o.jsx("tr",{children:o.jsx("td",{colSpan:3+u[0].values.length,children:"No emphasized parameters found."})})})]})},e9=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 Xm({runStep:e,refetchFn:t}){const[n,r]=x.useState([]),[i,s]=x.useState(""),{data:a,isLoading:l}=Pe.useQuery({queryKey:["files",e.id],queryFn:()=>wk({step:e})}),u=Pe.useQueryClient(),c=()=>{u.refetchQueries({queryKey:["files",e.id]}),t&&t()},d=a?.items??[],p=async E=>{if(confirm(`Are you sure you want to delete ${E.name}? You can not undo this action`))try{await Ee.delete(`delete/run/step/file/${E.id}`),c()}catch(C){console.error(C)}},h=E=>{r(C=>[...C,...E]),s(`${E.length} file(s) selected`)},{getRootProps:m,getInputProps:g,isDragActive:y,isDragAccept:b,isDragReject:S}=Co({onDrop:h}),R=x.useMemo(()=>({...y?{borderColor:"#83afee"}:{},...b?{borderColor:"#00e676"}:{},...S?{borderColor:"#ff1744"}:{}}),[b,S,y]),w=()=>{n.forEach(E=>{const C=new FileReader;C.onload=async()=>{const k=C.result;try{await Ee.create().post("update/run/step/upload-file/"+e.id,{content:k,filename:E.name,type:E.type})}catch(I){s("Upload failed due to: "+I.response.data.detail)}try{c(),s("Files uploaded succesfully"),r([])}catch(I){s("Error refetching file data"),console.error(I)}},C.readAsDataURL(E)})};return l?o.jsx("div",{children:"Loading..."}):o.jsxs("div",{children:[d&&d.length>0&&o.jsxs(Kt,{hover:!0,striped:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"No"}),o.jsx("th",{children:"File"}),o.jsx("th",{children:"Size"}),o.jsx("th",{children:"Date"})]})}),o.jsx("tbody",{children:d.map((E,C)=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("small",{className:"text-muted",children:C+1})}),o.jsxs("td",{children:[o.jsx("a",{href:`${lm()}${E.url}`,children:E.name}),E.has_run_step_loggings&&o.jsx(hn,{className:"ms-1 bg-primary",children:"Logging"})]}),o.jsxs("td",{children:[o.jsx("i",{className:"fa fa-trash-o remove-file handle",style:{cursor:"pointer"},onClick:()=>p(E)})," ",e9(E.size)]}),o.jsx("td",{children:Ln(E.date_created,"DD-MM-YY HH:mm")})]},C))})]}),o.jsxs("div",{...m({style:R,className:"dropzone bg-secondary-subtle border rounded dz-clickable"}),children:[o.jsx("input",{...g()}),y?o.jsx("p",{children:"Drop files here..."}):o.jsx("p",{children:"Drag and drop files here or click to select"})]}),n.length>0&&o.jsx(Wn,{className:"mt-3",children:n.map((E,C)=>o.jsx(Wn.Item,{children:E.name},C))}),o.jsx(de,{className:"mt-3",onClick:w,disabled:n.length===0,children:"Upload Selected Files"}),o.jsx("p",{className:"mt-2 text-muted",children:i})]})}const Kf=({runStepPart:e,setRunStepPart:t,editable:n=!0})=>{const[r,i]=x.useState(!1),[s,a]=x.useState(e.comment),{register:l,handleSubmit:u,formState:c,resetField:d}=gn({defaultValues:{comment:s}}),{isSubmitting:p,errors:h}=c,m=async g=>{await Ee.create().patch("update/run/step/part/"+e.id,{comment:g.comment}).then(y=>{t({...e,comment:y.data.comment}),a(y.data.comment),i(!1)})};return n?r?o.jsxs(H,{onSubmit:u(m),children:[o.jsx(H.Group,{className:"mb-3",controlId:"formBasicEmail",children:o.jsx(H.Control,{as:"textarea",...l("comment")})}),o.jsx(de,{size:"sm",type:"submit",disabled:p,children:"Save"}),o.jsx(de,{variant:"warning",size:"sm",className:"ms-2",onClick:()=>i(!1),children:"Cancel"})]}):s===null?o.jsx(de,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Add comment"}):o.jsxs("div",{className:"d-flex align-items-start gap-2",children:[o.jsx("div",{className:"text-break",children:s}),o.jsx(de,{variant:"link",size:"sm",className:"p-0 text-muted",onClick:()=>i(!0),children:"Edit"})]}):o.jsx("div",{children:s})},t9=({runStepPart:e,editable:t=!0,reloadFn:n,partIsSelected:r,setPartAsSelected:i})=>{const[s,a]=x.useState(e);x.useEffect(()=>{a(e)},[e]);const l=s.latest_action?.type.id===Ge.FINISH_PROCESSING,u=s.latest_action?.type.id===Ge.FAILED_PROCESSING,c=({runStepPart:d,runStepPartAction:p})=>{Su({runStepPart:d,runStepPartAction:p}).then(h=>{a({...d,latest_action:h,actions:d.actions+1})}).then(()=>{n&&n()})};return e.part_processing_failed_in_previous_step?o.jsxs("tr",{className:"table-danger",children:[o.jsxs("td",{children:[e.part.short_label,e.part.label&&e.part.label.trim().length>0?` (${e.part.label})`:""]}),o.jsx("td",{colSpan:t?3:2,children:o.jsx("span",{children:"Processing failed in a previous step"})}),o.jsx("td",{children:o.jsx(Kf,{runStepPart:e,setRunStepPart:a})})]}):o.jsxs("tr",{className:l?"table-success":u?"table-danger":"",children:[o.jsxs("td",{children:[s.part.short_label,s.part.label&&s.part.label.trim().length>0?` (${s.part.label})`:""," ",i&&r!==void 0&&o.jsx("input",{type:"checkbox",name:"tomato",checked:r,onChange:()=>{i(s.id)}})]}),o.jsx("td",{className:"text-center",children:s.latest_action?.type.name}),t&&o.jsx("td",{className:"text-center",children:o.jsxs("div",{className:" d-flex gap-2 justify-content-center",children:[s.actions===0&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.START_PROCESSING}),className:"btn-success btn-sm",children:"Start"}),s.actions>0&&s.latest_action?.type.id!==Ge.FINISH_PROCESSING&&s.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.FINISH_PROCESSING}),className:"btn-primary btn-sm",children:"Finish"}),s.actions>0&&s.latest_action?.type.id!==Ge.FINISH_PROCESSING&&s.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.FAILED_PROCESSING}),className:"btn-danger btn-sm",children:"Failed"}),s.actions>0&&o.jsx(de,{onClick:()=>c({runStepPart:s,runStepPartAction:Ge.REWORK}),className:"btn-info btn-sm",children:"Rework"})]})}),o.jsx("td",{children:o.jsx(Kf,{editable:t,runStepPart:e,setRunStepPart:a})})]})},Zm=({run:e,runStep:t,runStepParts:n,editable:r=!0,refetchFn:i=()=>{}})=>{const[s,a]=x.useState(n||[]),{isLoading:l,isError:u,error:c,data:d}=Pe.useQuery({queryKey:["stepParts",t],queryFn:()=>ro({step:t}),enabled:!n}),[p,h]=x.useState(new Map);if(x.useEffect(()=>{for(const S of s)h(R=>{const w=new Map(R);return w.set(S.id,!1),w})},[s]),x.useEffect(()=>{u&&console.error("RunPartsResearchRun query error",{error:c,runStep:t})},[u,c,t]),x.useEffect(()=>{!l&&d&&!n&&a(d.items)},[l,d,n]),x.useEffect(()=>{n&&a(n)},[n]),l)return o.jsx("div",{children:"Loading..."});if(u)return o.jsx("div",{className:"text-danger",children:"Error loading run parts."});if(s.length===0)return null;const m=S=>{h(R=>{const w=new Map(R);return w.set(S,!R.get(S)),w})},g=()=>{h(S=>{const R=new Map(S);for(const w of R.keys())R.set(w,!0);return R})},y=()=>{h(S=>{const R=new Map(S);for(const w of R.keys())R.set(w,!1);return R})},b=()=>{const S=n?.filter(w=>p.get(w.id));if(!S||S.length===0)return null;const R=new Set;return S.forEach(w=>{ep(w).forEach(C=>R.add(C))}),R.size===0?null:o.jsxs(Ue,{align:"end",children:[o.jsx(Ue.Toggle,{size:"sm",variant:"outline-secondary",children:"Actions"}),o.jsxs(Ue.Menu,{children:[R.has(Ge.START_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Start"}),R.has(Ge.FINISH_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Finish"}),R.has(Ge.FAILED_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Failed"}),R.has(Ge.REWORK)&&o.jsx(Ue.Item,{onClick:()=>!1,children:"Rework"})]})]})};return o.jsx(x.Fragment,{children:s&&s.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs(Kt,{size:"sm",striped:!0,bordered:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Part"}),o.jsx("th",{className:"text-center",children:"Status"}),r&&o.jsx("th",{className:"text-center",children:"Operation"}),o.jsx("th",{children:"Comment"})]})}),o.jsx("tbody",{children:s.map((S,R)=>o.jsx(t9,{editable:r,runStepPart:S,reloadFn:i,...r?{partIsSelected:p.get(S.id),setPartAsSelected:m}:{}},R))})]}),r&&o.jsxs("div",{children:[o.jsxs("div",{className:"btn-group",children:[o.jsx("button",{className:"part-check-all btn btn-sm btn-outline-secondary",onClick:g,children:"All"}),o.jsx("button",{className:"part-check-none btn btn-sm btn-outline-secondary",onClick:y,children:"None"})]}),p.values().some(S=>S)&&b()]})]})})},ep=e=>{if(e.part_processing_failed_in_previous_step)return[];const t=e.latest_action?.type.id,n=[];return e.actions===0&&n.push(Ge.START_PROCESSING),e.actions>0&&t!==Ge.FINISH_PROCESSING&&t!==Ge.FAILED_PROCESSING&&n.push(Ge.FINISH_PROCESSING,Ge.FAILED_PROCESSING),e.actions>0&&n.push(Ge.REWORK),n},n9=({runPart:e,runStepParts:t,runStep:n,refetchFn:r=()=>{},partIsSelected:i,setPartAsSelected:s})=>{const[a,l]=x.useState(void 0),u=Pe.useQueryClient();x.useEffect(()=>{l(t.find(m=>m.part.id===e.id&&m.step.id===n.id))},[t,e,n]);const c=()=>{Ee.post("/create/run/step/part",{run_part_id:e.id,run_step_id:n.id}).then(m=>{l({...m.data}),r(),u.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},d=({runStepPart:m,runStepPartAction:g})=>{Su({runStepPart:m,runStepPartAction:g}).then(y=>{l({...m,latest_action:y,actions:m.actions+1})}).then(()=>{r(),u.invalidateQueries({queryKey:["runSteps"]})})};if(!a)return o.jsxs("tr",{children:[o.jsxs("td",{children:["Part ",e.short_label,e.label&&e.label.trim().length>0?` (${e.label})`:""]}),o.jsx("td",{colSpan:2}),o.jsx("td",{children:o.jsx(de,{size:"sm",variant:"outline-info",onClick:()=>c(),children:"Init"})}),o.jsx("td",{})]});const p=a.latest_action?.type.id===Ge.FINISH_PROCESSING,h=a.latest_action?.type.id===Ge.FAILED_PROCESSING;return o.jsxs("tr",{className:p?"table-success":h?"table-danger":"",children:[o.jsxs("td",{children:["Part ",a.part.short_label,a.part.label&&a.part.label.trim().length>0?` (${a.part.label})`:"",s&&i!==void 0&&o.jsx("input",{type:"checkbox",name:"tomato",checked:i,onChange:()=>{s(a.id)}})]}),o.jsx("td",{children:a.latest_action?.type.name}),o.jsx("td",{children:o.jsx(o.Fragment,{children:Ln(a.latest_action?.date_created,"DD-MM-YY HH:mm")})}),o.jsx("td",{children:o.jsxs(Ue,{align:"end",children:[o.jsx(Ue.Toggle,{size:"sm",variant:"outline-secondary",children:"Actions"}),o.jsxs(Ue.Menu,{children:[a.actions===0&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.START_PROCESSING}),children:"Start"}),a.actions>0&&a.latest_action?.type.id!==Ge.FINISH_PROCESSING&&a.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.FINISH_PROCESSING}),children:"Finish"}),a.actions>0&&a.latest_action?.type.id!==Ge.FINISH_PROCESSING&&a.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.FAILED_PROCESSING}),children:"Failed"}),a.actions>0&&o.jsx(Ue.Item,{onClick:()=>d({runStepPart:a,runStepPartAction:Ge.REWORK}),children:"Rework"})]})]})}),o.jsx("td",{children:o.jsx(Kf,{runStepPart:a,setRunStepPart:l})})]})},h1=({run:e,runStep:t,runStepParts:n,runParts:r,refetchFn:i=()=>{}})=>{const s=Pe.useQueryClient(),a=Pe.useQueries({queries:[{queryKey:["runParts",e],queryFn:()=>bu({run:e}),enabled:!r},{queryKey:["runStepParts",t.id],queryFn:()=>ro({step:t}),enabled:!n}]}),[l,u]=a,c=a.some(C=>C.isLoading),d=a.some(C=>C.isError),p=x.useMemo(()=>r??l.data?.items??[],[r,l.data]),h=x.useMemo(()=>n??u.data?.items??[],[n,u.data]),[m,g]=x.useState(new Map);x.useEffect(()=>{for(const C of h)g(k=>{const I=new Map(k);return I.set(C.id,!1),I})},[h]);const y=C=>{g(k=>{const I=new Map(k);return I.set(C,!k.get(C)),I})},b=()=>{g(C=>{const k=new Map(C);for(const I of k.keys())k.set(I,!0);return k})},S=()=>{g(C=>{const k=new Map(C);for(const I of k.keys())k.set(I,!1);return k})};if(c)return o.jsx("div",{children:"Loading..."});if(d)return o.jsx("div",{className:"text-danger",children:"Error loading run parts."});const R=p.filter(C=>C.part_level===t.part_level),w=C=>{h.filter(I=>R.find(A=>A.id==I.part.id)).filter(I=>m.get(I.id)).forEach(I=>{ep(I).some(A=>A===C)&&Su({runStepPart:I,runStepPartAction:C}).then(()=>{s.refetchQueries({queryKey:["runStepParts",t.id]}),i&&i()})})},E=()=>{const C=h.filter(I=>R.find(A=>A.id==I.part.id)).filter(I=>m.get(I.id));if(!C||C.length===0)return null;const k=new Set;return C.forEach(I=>{ep(I).forEach(F=>k.add(F))}),k.size===0?null:o.jsxs(Ue,{align:"end",children:[o.jsx(Ue.Toggle,{size:"sm",variant:"secondary",children:"Actions"}),o.jsxs(Ue.Menu,{children:[k.has(Ge.START_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.START_PROCESSING)},children:"Start"}),k.has(Ge.FINISH_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.FINISH_PROCESSING)},children:"Finish"}),k.has(Ge.FAILED_PROCESSING)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.FAILED_PROCESSING)},children:"Failed"}),k.has(Ge.REWORK)&&o.jsx(Ue.Item,{onClick:()=>{w(Ge.REWORK)},children:"Rework"})]})]})};return o.jsx(x.Fragment,{children:R.length>0&&o.jsxs(o.Fragment,{children:[o.jsx("h3",{children:"Available parts"}),o.jsxs(Kt,{size:"sm",striped:!0,hover:!0,responsive:!0,className:"align-middle",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Part"}),o.jsx("th",{children:"Status"}),o.jsx("th",{children:"Date"}),o.jsx("th",{children:"Actions"}),o.jsx("th",{children:"Comment"})]})}),o.jsx("tbody",{children:R.map((C,k)=>o.jsx(n9,{runStep:t,runPart:C,runStepParts:h,refetchFn:i,partIsSelected:m.get(h?.find(I=>I.part.id===C.id&&I.step.id===t.id)?.id??0),setPartAsSelected:y},k))})]}),o.jsxs("div",{className:"d-flex gap-3",children:[o.jsxs("div",{className:"btn-group",children:[o.jsx("button",{className:"part-check-all btn btn-sm btn-outline-secondary",onClick:b,children:"All"}),o.jsx("button",{className:"part-check-none btn btn-sm btn-outline-secondary",onClick:S,children:"None"})]}),m.values().some(C=>C)&&E()]})]})})};function r9({step:e,stepParts:t,parts:n,refetchFn:r}){const{showOnlyEmphasizedParameters:i}=x.useContext(pc),{run:s}=x.useContext(as);return o.jsx(Ze,{className:"p-4 my-3",children:o.jsx(Ze.Body,{children:o.jsxs(Un,{children:[o.jsxs(Mt,{md:"6",children:[s.run_type===Hn.RESEARCH&&o.jsx(Zm,{run:s,runStep:e,runStepParts:t,refetchFn:()=>{r(["runStepParts"])}}),s.run_type===Hn.PRODUCTION&&o.jsx(h1,{run:s,runStep:e,runParts:n,refetchFn:()=>{r(["runStepParts"])}}),e.has_remark&&o.jsxs(o.Fragment,{children:[o.jsx("h4",{children:"Remark"}),o.jsx("span",{dangerouslySetInnerHTML:{__html:e.remark}})]})]}),o.jsxs(Mt,{md:"6",children:[o.jsx("h4",{children:"Parameters"}),o.jsx(qm,{runStep:e,showOnlyEmphasizedParameters:i,refetchFn:()=>{r([JSON.stringify(e),"parameters"])}}),o.jsx("h4",{children:"Files"}),o.jsx(Xm,{runStep:e,refetchFn:()=>{r(["runSteps"])}})]})]})})})}const g1=({step:e,parts:t,stepParts:n})=>{const r=t.filter(l=>l.part_level===e.part_level).sort((l,u)=>l.root_id&&u.root_id&&l.root_id!==u.root_id?l.root_id-u.root_id:l.left-u.left),i=r.reduce((l,u)=>{const c=u.root_id??u.id;return l[c]||(l[c]=[]),l[c].push(u),l},{}),s=l=>{const u=n.find(c=>c.part.id===l.id&&c.step.id===e.id);return u?u.part_processing_failed_in_previous_step?"badge-failed-previous":u.failed?"badge-failed":u.processed?"badge-processed":u.started?"badge-started":"":"badge-inactive"},a=l=>o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${l.id}`,children:`Level: ${l.part_level}${l.parent?`, Parent: ${l.parent.short_label}`:""}`}),children:o.jsx("span",{className:`badge badge-level-${l.part_level} ${s(l)} me-1`,children:l.label??l.short_label},l.id)},l.id);return o.jsx(o.Fragment,{children:r[0]&&r[0].parent?Object.entries(i).map(([l,u])=>o.jsxs("div",{className:"mb-2",children:[o.jsxs("label",{className:"text-muted me-1",children:[u[0].parent?.short_label,":"]})," ",u.map(c=>a(c))]},l)):r.map(l=>a(l))})},i9=({runPart:e,runStepParts:t,runStep:n,reloadFn:r=()=>{}})=>{const[i,s]=x.useState(void 0),a=Pe.useQueryClient();x.useEffect(()=>{s(t.find(d=>d.part.id===e.id&&d.step.id===n.id))},[t,e,n]);const l=()=>{Ee.post("/create/run/step/part",{run_part_id:e.id,run_step_id:n.id}).then(d=>{s({...d.data}),r(),a.invalidateQueries({queryKey:["runSteps","runStepParts"]})})},u=({runStepPart:d,runStepPartAction:p})=>{Su({runStepPart:d,runStepPartAction:p}).then(h=>{s({...d,latest_action:h,actions:d.actions+1})}).then(()=>{r(),a.invalidateQueries({queryKey:["runSteps"]})})},c=d=>{const p=t.find(h=>h.part.id===d.id&&h.step.id===n.id);return p?p.part_processing_failed_in_previous_step?"badge-failed-previous":p.failed?"badge-failed":p.processed?"badge-processed":p.started?"badge-started":"":"badge-inactive"};return i?o.jsx("div",{style:{minWidth:"100px"},children:o.jsxs(Ue,{children:[o.jsxs(Ue.Toggle,{size:"sm",variant:"outline-secondary",className:"border-2 w-100 "+c(e),children:["Part ",i.part.label??i.part.short_label]}),o.jsxs(Ue.Menu,{children:[i.actions===0&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.START_PROCESSING}),children:"Start"}),i.actions>0&&i.latest_action?.type.id!==Ge.FINISH_PROCESSING&&i.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.FINISH_PROCESSING}),children:"Finish"}),i.actions>0&&i.latest_action?.type.id!==Ge.FINISH_PROCESSING&&i.latest_action?.type.id!==Ge.FAILED_PROCESSING&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.FAILED_PROCESSING}),children:"Failed"}),i.actions>0&&o.jsx(Ue.Item,{onClick:()=>u({runStepPart:i,runStepPartAction:Ge.REWORK}),children:"Rework"})]})]})}):o.jsxs(de,{size:"sm",variant:"outline-secondary",style:{minWidth:"100px"},onClick:()=>l(),children:["Init ",e.label??e.short_label]})},s9=({runStep:e,parts:t,runStepParts:n,reloadFn:r})=>{const i=t.filter(l=>l.part_level===e.part_level).sort((l,u)=>l.root_id&&u.root_id&&l.root_id!==u.root_id?l.root_id-u.root_id:l.left-u.left),s=i.reduce((l,u)=>{const c=u.root_id??u.id;return l[c]||(l[c]=[]),l[c].push(u),l},{}),a=l=>o.jsx(i9,{runStep:e,runPart:l,runStepParts:n,reloadFn:r},l.id);return o.jsx("div",{className:"d-flex flex-wrap gap-2",children:i[0]&&i[0].parent?Object.entries(s).map(([l,u])=>o.jsxs("div",{className:"mb-2",children:[o.jsxs("label",{className:"text-muted me-1",children:[u[0].parent?.short_label,":"]})," ",u.map(c=>a(c))]},l)):i.map(l=>a(l))})};function a9({run:e,step:t,parts:n,stepParts:r,monitoredBy:i,refetchFn:s}){const{environment:a}=Te.useParams(),[l,u]=x.useState(!1),c=()=>{u(!l)},[d,p]=x.useState(t.process_module.module);return x.useEffect(()=>{p(t.process_module.module)},[t.process_module.module]),o.jsxs(o.Fragment,{children:[o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("i",{className:"fa ms-2 "+(l?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:c})}),o.jsxs("td",{className:d.latest_module_status&&d.latest_module_status.status.is_down_status?"table-danger":"",children:[e.run_type===Hn.RESEARCH&&o.jsx(g1,{step:t,parts:n,stepParts:r}),e.run_type===Hn.PRODUCTION&&o.jsx(s9,{runStep:t,parts:n,runStepParts:r,reloadFn:()=>{s(["runStepParts"])}})]}),o.jsxs("td",{children:[i&&o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${i.id}`,children:`Monitored by step: ${i.step.number}`}),children:o.jsx("i",{className:"fa fa-search me-2"})}),t.amount_of_files>0&&o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&o.jsx("i",{className:"fa fa-comment-o text-warning me-3"}),t.is_finished&&o.jsx("i",{className:"fa fa-check text-success me-3"})]}),o.jsxs("td",{className:t.has_step_group?"ps-4":"",children:[t.number," - ",o.jsx(Te.Link,{to:`/${a}/operator/run/step/${t.id}`,children:o.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]}),o.jsxs("td",{children:[o.jsx(Te.Link,{to:`/${a}/operator/equipment/${d.equipment.id}`,className:"me-2",children:d.equipment.name}),o.jsx(qi,{module:d,refetchFn:()=>{s(["runSteps"])}})]})]}),l&&o.jsx("tr",{children:o.jsx("td",{colSpan:n.length+6,children:o.jsx(r9,{step:t,stepParts:r,parts:n,refetchFn:s})})})]})}const tp=({requirement:e,result:t,show:n,setShow:r,refetchFn:i,part:s,stepPart:a})=>{const[l,u]=x.useState({}),[c,d]=x.useState(!1),[p,h]=x.useState(null),[m,g]=x.useState(!1);x.useEffect(()=>{if(Object.keys(l).length>0)return;let w={};for(const E of e.targets){let C="";t!==void 0&&(C=t.values.find(k=>k.logging_parameter.id==E.logging_parameter.id)?.string_value??""),w[E.logging_parameter.id]=C}u(w)},[e]),x.useEffect(()=>{g(!1),h(null),d(!1)},[n]);const y=async()=>{try{h(null),g(!1),d(!0),await Ee.delete(`/delete/run/measurement/result/${t?.id??0}`),g(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(w){console.error(w),h("Update of results failed")}finally{d(!1)}},b=async()=>{try{h(null),g(!1),d(!0);const w=Object.entries(l).map(async([E,C])=>{const k=Number.parseInt(E),I={value:C},A=t?.values.find(F=>F.logging_parameter.id===k)?.id;await Ee.patch(`/update/run/measurement/result/value/${A??0}`,I)});await Promise.all(w),g(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(w){console.error(w),h("Update of results failed")}finally{d(!1)}},S=async()=>{const w={measurement:e.measurement.id,values:Object.entries(l).flatMap(E=>({logging_parameter:Number.parseInt(E[0]),value:E[1]}))};a&&(w.step_part=a?.id??0,w.part=s?.id??0,w.step=e.step.id??0);try{h(null),g(!1),d(!0),await Ee.post("/create/run/measurement/result",w),g(!0),i(["requirement","measurementResults",JSON.stringify(e.measurement.id)])}catch(E){console.error(E),h("Update of results failed")}finally{d(!1)}},R=w=>{w.preventDefault(),t?b():S()};return o.jsxs(xe,{show:n,size:"lg",onHide:()=>r(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:t?o.jsx(o.Fragment,{children:"Update results"}):o.jsx(o.Fragment,{children:"Create result"})})}),o.jsxs(H,{onSubmit:R,children:[o.jsxs(xe.Body,{children:[p&&o.jsx(Bt,{variant:"danger",children:p}),m&&o.jsx(Bt,{variant:"success",children:"Results have been updated successfully"}),e.targets.map(w=>(t?.values.find(E=>E.logging_parameter.id===w.logging_parameter.id)?.string_value,o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:w.logging_parameter.name}),o.jsx(H.Control,{type:"number",step:"any",placeholder:"Thickness",value:l[w.logging_parameter.id]??"",onChange:E=>u(C=>({...C,[w.logging_parameter.id]:E.target.value}))})]},w.id)))]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{variant:"warning",onClick:()=>r(!1),children:"Close"}),c?o.jsxs(de,{type:"submit",variant:"info",disabled:c,children:[o.jsx(Lp,{animation:"border",size:"sm",className:"me-2"})," Updating results..."]}):t?o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"danger",disabled:c,onClick:y,children:"Delete result"}),o.jsx(de,{type:"submit",variant:"info",disabled:c,children:"Update result"})]}):o.jsx(de,{type:"submit",variant:"info",disabled:c,children:"Create result"})]})]})]})},vn=x.createContext({runStep:{},setRunStep:e=>{},reloadRunStep:()=>{},run:{},modalProperties:{},setModalProperties:e=>{}});function Jm({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:s,editOnly:a=!1}){const{run:l}=x.useContext(vn),[u,c]=x.useState(r??[]),[d,p]=x.useState(n??[]),[h,m]=x.useState(i??[]),g=Pe.useQueryClient(),y=Pe.useQueries({queries:[{queryKey:["runParts",`${l?.id??"unknown"}`],queryFn:async()=>await bu({run:l}),enabled:!r||r.length===0,retry:1},{queryKey:["runStepParts",`${t?.run_id??"unknown"}`,`${t?.id??"unknown"}`],queryFn:async()=>await ro({step:e.requirement_for_step??e.step}),enabled:!n||n.length===0,retry:1},{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await wu({measurement:e.measurement}),enabled:!i||i.length===0,retry:1}]}),b=()=>{g.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[S,R,w]=y;x.useEffect(()=>{r&&r.length>0?c(r):S?.data&&c(S.data.items)},[r,S?.data]),x.useEffect(()=>{n&&n.length>0?p(n):R?.data&&p(R.data.items)},[n,R?.data]),x.useEffect(()=>{i&&i.length>0?m(i):w?.data&&m(w.data.items)},[i,w?.data]);const[E,C]=x.useState(null),k=r&&r.length>0?r:u,A=((n&&n.length>0?n:d)??[]).filter(T=>(k??[]).find(U=>U.id===T.part.id&&U.part_level===t.part_level)!==void 0),F=!r||r.length===0,P=!n||n.length===0,B=!i||i.length===0,V=F&&S?.isLoading||P&&R?.isLoading||B&&w?.isLoading,z=F&&S?.isError||P&&R?.isError||B&&w?.isError;if(V&&A.length===0)return o.jsxs("div",{className:"d-flex align-items-center gap-2",children:[o.jsx(Lp,{animation:"border",size:"sm"})," ",o.jsx("span",{children:"Loading data…"})]});if(z&&A.length===0)return o.jsxs(Bt,{variant:"danger",className:"d-flex justify-content-between align-items-center",children:[o.jsx("div",{children:"Failed to load required data. Please try again."}),o.jsxs("div",{children:[F&&S?.isError&&o.jsx(de,{size:"sm",variant:"outline-light",onClick:()=>S.refetch(),children:"Retry parts"})," ",P&&R?.isError&&o.jsx(de,{size:"sm",variant:"outline-light",onClick:()=>R.refetch(),children:"Retry step parts"})," ",B&&w?.isError&&o.jsx(de,{size:"sm",variant:"outline-light",onClick:()=>w.refetch(),children:"Retry results"})]})]});const Y=T=>{if(!(T&&!isNaN(parseFloat(T.string_value))))return"";const U=parseFloat(T.string_value),ie=e.targets.find(he=>he.logging_parameter.id===T.logging_parameter.id);return ie?(ie.inclusive?!(ie.min_value<=U&&ie.max_value>=U):!(ie.min_value<U&&ie.max_value>U))?"table-danger":"table-success":""};return o.jsx(o.Fragment,{children:A.length>0?o.jsxs(o.Fragment,{children:[o.jsxs(Kt,{size:"sm",striped:!0,hover:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{style:{width:"26%"},children:"Part"}),o.jsx("th",{children:"Parameter"}),o.jsx("th",{children:"Value"}),o.jsx("th",{children:"Unit"}),!a&&o.jsx("th",{style:{width:"1%"}})]})}),o.jsx("tbody",{children:A.map(T=>{const U=h.find(he=>he.values.some(N=>N.step_part_id===T.id)),ie=(U?.values??[]).filter(he=>he.step_part_id===T.id),oe=e.targets.length;return e.targets.map((he,N)=>{const ne=ie.find(D=>D.logging_parameter.id===he.logging_parameter.id)??null,se=ne?Y(ne):"";return o.jsxs("tr",{className:se,children:[N===0&&o.jsxs("td",{rowSpan:oe,children:[T.part.short_label," ",o.jsxs("small",{className:"text-muted",children:["(",T.id,")"]})]}),o.jsx("td",{children:he.logging_parameter.name}),o.jsx("td",{children:ne?ne.string_value:o.jsx("span",{className:"text-muted",children:"not set"})}),o.jsx("td",{children:he.logging_parameter.unit?.abbr??""}),!a&&N===0&&o.jsx("td",{rowSpan:oe,className:"align-middle text-nowrap",children:o.jsxs(de,{size:"sm",variant:U?"outline-primary":"outline-success",onClick:()=>C(String(T.id)),children:[o.jsx("i",{className:"fa fa-edit"})," ",U?"Edit values":"Add values"]})})]},`${T.id}:${he.logging_parameter.id}`)})})})]}),!a&&A.map(T=>{const U=h.find(ie=>ie.values.some(oe=>oe.step_part_id===T.id));return o.jsx(tp,{requirement:e,...U?{result:U}:{part:T.part,stepPart:T},show:E===String(T.id),setShow:ie=>{ie||C(null)},refetchFn:s??b},`modal:${T.id}`)})]}):o.jsx(Bt,{variant:"secondary",className:"mb-0",children:"No selected parts"})})}function v1({requirement:e,measurementResults:t,refetchFn:n,editOnly:r=!1}){const[i,s]=x.useState(t??[]),a=Pe.useQueryClient(),l=Pe.useQueries({queries:[{queryKey:["requirement","measurementResults",e.measurement.id],queryFn:async()=>await wu({measurement:e.measurement}),enabled:!t||t.length===0,retry:1}]}),u=()=>{a.refetchQueries({queryKey:["requirement","measurementResults",e.measurement.id]})},[c]=l;x.useEffect(()=>{t&&t.length>0?s(t.filter(S=>S.values.some(R=>!R.step_part_id))):c?.data&&s(c.data.items.filter(S=>S.values.some(R=>!R.step_part_id)))},[t,c?.data]);const[d,p]=x.useState(null),[h,m]=x.useState(!1),g=l.some(S=>S.isLoading);if(l.some(S=>S.isError))return l.filter(S=>S.isError).forEach((S,R)=>{console.error("StepDashboard query error",{index:R,error:S.error})}),o.jsx(o.Fragment,{children:"Error fetching data"});if(g)return o.jsx("div",{children:"Loading..."});const b=S=>{if(!(S&&!isNaN(parseFloat(S.string_value))))return"";const R=parseFloat(S.string_value),w=e.targets.find(C=>C.logging_parameter.id===S.logging_parameter.id);return w&&(w.inclusive?!(w.min_value<=R&&w.max_value>=R):!(w.min_value<R&&w.max_value>R))?"table-danger":""};return o.jsxs("div",{className:"d-flex flex-column gap-4",children:[i.map(S=>o.jsxs("div",{className:"border rounded p-3 shadow-sm",children:[o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[o.jsxs("h6",{className:"mb-0",children:["Result ",o.jsxs("small",{className:"text-muted",children:["#",S.id]})]}),!r&&o.jsxs(de,{size:"sm",variant:"outline-primary",onClick:()=>p(S.id),children:[o.jsx("i",{className:"fa fa-edit"})," Update value"]})]}),o.jsxs("table",{className:"table table-striped table-sm mb-0",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Parameter"}),o.jsx("th",{children:"Value"}),o.jsx("th",{children:"Unit"})]})}),o.jsx("tbody",{children:S.values.map(R=>o.jsxs("tr",{className:R?b(R):"",children:[o.jsx("td",{children:R.logging_parameter.name}),o.jsx("td",{children:R.string_value}),o.jsx("td",{children:R.logging_parameter.unit?.abbr??""})]},`value:${R.id}`))})]}),o.jsx(tp,{requirement:e,result:S,show:d===S.id,setShow:R=>{R||p(null)},refetchFn:n??u})]},S.id)),o.jsx("div",{className:"mt-3",children:o.jsxs(de,{size:"sm",onClick:()=>m(!h),children:[o.jsx("i",{className:"fa fa-plus"})," Add results"]})}),o.jsx(tp,{requirement:e,show:h,setShow:S=>{S||m(!1)},refetchFn:n??u})]})}function o9({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:s}){const{environment:a}=Te.useParams();return o.jsx(Ze,{className:"p-4 my-3",children:o.jsx(Ze.Body,{children:o.jsxs(Un,{children:[o.jsxs(Mt,{md:"7",children:[o.jsx("h4",{children:"Measurements by part"}),o.jsx(Jm,{requirement:e,step:t,stepParts:n,parts:r,measurementResults:i,refetchFn:s}),o.jsx("h4",{children:"Measurements for whole step"}),o.jsx(v1,{requirement:e,measurementResults:i,refetchFn:s})]}),o.jsxs(Mt,{md:"5",children:[o.jsx("h4",{children:"Monitored Step"}),o.jsx(Te.Link,{to:`/${a}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),o.jsx("h4",{children:"Definition"}),o.jsx("span",{children:e.definition}),o.jsx("h4",{children:"Targets"}),o.jsxs(Kt,{size:"sm",striped:!1,bordered:!1,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"parameter"}),o.jsx("th",{children:"min value"}),o.jsx("th",{children:"max value"}),o.jsx("th",{children:"inclusive"})]})}),o.jsx("tbody",{children:e.targets.map(l=>o.jsxs("tr",{children:[o.jsx("td",{children:l.logging_parameter.name}),o.jsx("td",{children:l.min_value}),o.jsx("td",{children:l.max_value}),o.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]}),o.jsx("h4",{children:"Files"}),o.jsx(Xm,{runStep:t,refetchFn:()=>{s(["requirements"])}})]})]})})})}const x1=({requirement:e,step:t,measurementResults:n,parts:r,stepParts:i})=>{const s=r.filter(c=>c.part_level===t.part_level).sort((c,d)=>c.root_id&&d.root_id&&c.root_id!==d.root_id?c.root_id-d.root_id:c.left-d.left),a=s.reduce((c,d)=>{const p=d.root_id??d.id;return c[p]||(c[p]=[]),c[p].push(d),c},{}),l=c=>{const d=i.find(h=>h.part.id===c.id);if(!d)return"badge-inactive";const p=n.find(h=>h.values.some(m=>m.step_part_id===d.id));if(!p)return"";for(const h of p.values){const m=parseFloat(h.string_value),g=e.targets.find(y=>y.logging_parameter.id==h.logging_parameter.id);if(g){if(g.inclusive){if(!(g.min_value<=m&&g.max_value>=m))return"badge-failed"}else if(!(g.min_value<m&&g.max_value>m))return"badge-failed"}}return"badge-processed"},u=c=>o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${c.id}`,children:`Level: ${c.part_level}${c.parent?`, Parent: ${c.parent.short_label}`:""}`}),children:o.jsx("span",{className:`badge badge-level-${c.part_level} ${l(c)} me-1`,children:c.short_label},c.id)},c.id);return o.jsxs("div",{children:[s[0].parent?Object.entries(a).map(([c,d])=>o.jsxs("div",{className:"mb-2",children:[o.jsxs("label",{className:"text-muted me-1",children:[d[0].parent?.short_label,":"]})," ",d.map(p=>u(p))]},c)):s.map(c=>u(c)),o.jsx("label",{children:"(measurements)"})]})};function l9({requirement:e,step:t,parts:n,stepParts:r,refetchFn:i}){const{environment:s}=Te.useParams(),[a,l]=x.useState(!1),[u,c]=x.useState(t.process_module.module);x.useEffect(()=>{c(t.process_module.module)},[t.process_module.module]);const d=()=>{l(!a)},p=Pe.useQueryClient(),h=Pe.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>wu({measurement:e.measurement})}]}),m=S=>{S[0]==="requirement"&&p.refetchQueries({queryKey:S}),i(S)},[g]=h,y=h.some(S=>S.isLoading),b=S=>{if(S.length==0)return y?"":"table-info";let R=!1;for(const w of S)if(w.values.some(C=>{if(!(C&&!isNaN(parseFloat(C.string_value))))return!1;const k=parseFloat(C.string_value),I=e.targets.find(A=>A.logging_parameter.id==C.logging_parameter.id);return I?I.inclusive?!(I.min_value<=k&&I.max_value>=k):!(I.min_value<k&&I.max_value>k):!1})){R=!0;break}return R?"table-danger":""};return o.jsxs(o.Fragment,{children:[o.jsxs("tr",{className:b(g.data?.items??[]),children:[o.jsx("td",{children:o.jsx("i",{className:"fa ms-2 "+(a?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:d})}),o.jsx("td",{children:o.jsx(x1,{requirement:e,step:t,measurementResults:g.data?.items??[],parts:n,stepParts:r})}),o.jsxs("td",{children:[o.jsx(hn,{bg:"info",children:"requirement"}),t.amount_of_files>0&&o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-paperclip"})," ",t.amount_of_files]}),t.has_remark&&o.jsx("i",{className:"fa fa-comment-o text-warning"})]}),o.jsx("td",{className:t.has_step_group?"ps-4":"",children:o.jsxs("div",{children:["(",t.number,")"," ",o.jsx(Te.Link,{to:`/${s}/operator/run/step/${t.id}`,children:o.jsx("span",{dangerouslySetInnerHTML:{__html:t.name}})})," "]})}),o.jsxs("td",{children:[o.jsx(Te.Link,{to:`/${s}/operator/equipment/${u.equipment.id}`,className:"me-2",children:u.equipment.name}),o.jsx(qi,{module:u,refetchFn:()=>{i(["runSteps"])}})]})]}),a&&o.jsx("tr",{children:o.jsx("td",{colSpan:n.length+5,children:y?"Loading...":o.jsx(o9,{requirement:e,step:t,stepParts:r,parts:n,measurementResults:g.data?.items??[],refetchFn:m})})})]})}function u9(){const{run:e}=x.useContext(as),{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n}=x.useContext(pc),[r,i]=x.useState(1),[s]=x.useState(25),[a,l]=x.useState(new Map),u=Pe.useQueryClient(),c=Pe.useQueries({queries:[{queryKey:["runSteps",JSON.stringify(e),r],queryFn:()=>dp({run:e,page:r,pageSize:s}),placeholderData:Pe.keepPreviousData},{queryKey:["runParts",JSON.stringify(e)],queryFn:()=>bu({run:e})},{queryKey:["runStepParts",JSON.stringify(e)],queryFn:()=>ro({run:e})},{queryKey:["requirements",JSON.stringify(e)],queryFn:()=>cp({run:e})}]}),d=P=>{const B=[...P,JSON.stringify(e)];P[0]==="runSteps"&&B.push(r),u.refetchQueries({queryKey:B})},[p,h,m,g]=c,y=c.some(P=>P.isLoading),b=c.some(P=>P.isError);b&&c.filter(P=>P.isError).forEach((P,B)=>{console.error("RunStepsElement query error",{index:B,error:P.error,run:e})});const S=x.useMemo(()=>p.data?.items??[],[p.data?.items]),R=x.useMemo(()=>h.data?.items??[],[h.data?.items]),w=x.useMemo(()=>m.data?.items??[],[m.data?.items]),E=x.useMemo(()=>g.data?.items??[],[g.data?.items]);if(x.useEffect(()=>{l(P=>{const B=new Map(P);return S.forEach(V=>{const z=V.label?.id;z!==void 0&&!B.has(z)&&B.set(z,!0)}),B})},[S]),y)return o.jsx("div",{children:"Loading..."});if(b)return o.jsx("div",{className:"text-danger",children:"Error loading run steps."});const C=new Set,k=S.filter(P=>!P.has_step_group||typeof P.step_group?.id!="number"||C.has(String(P.step_group.id))?!1:(C.add(String(P.step_group.id)),!0)),I={};for(const P of E)P.requirement_for_step!=null&&(I[String(P.requirement_for_step.id)]=P);const A=P=>o.jsx("tr",{style:{pointerEvents:"none"},children:o.jsx("td",{colSpan:5,style:{margin:0},className:"bg-info",children:o.jsx("span",{children:P.step_group?.label})})}),F=P=>{const B=P.label,V=B?.id;if(!P.is_own_label||!B||V===void 0)return null;const z=Y=>{l(T=>{const U=new Map(T);return U.set(Y,!U.get(Y)),U})};return o.jsx("tr",{style:{cursor:"pointer"},onClick:()=>z(V),children:o.jsx("td",{colSpan:5,style:{margin:0},className:"bg-secondary",children:o.jsxs("span",{className:"label-toggle",children:[o.jsx("i",{className:"fa "+(a.get(P.label?.id??-1)?"fa-caret-down":"fa-caret-right")})," ",B.label]})})})};return o.jsxs("div",{children:[o.jsx("h2",{children:"Run steps"}),o.jsx("div",{className:"d-flex justify-content-between align-items-center",children:o.jsxs("div",{className:"form-check form-switch",children:[o.jsx("input",{type:"checkbox",checked:t,className:"form-check-input","data-toggle":"toggle",onChange:()=>n(!t)}),o.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]})}),o.jsxs(Kt,{borderless:!0,hover:!0,striped:!0,size:"sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{}),o.jsx("th",{children:"Parts"}),o.jsx("th",{}),o.jsx("th",{children:"Process"}),o.jsx("th",{children:"Equipment"})]})}),o.jsx("tbody",{children:S.map((P,B)=>{const V=`step-${P.id}`;return o.jsxs(x.Fragment,{children:[P.has_label&&F(P),(!P.has_label||a.get(P.label?.id??-1))&&o.jsxs(o.Fragment,{children:[P.has_step_group&&k.includes(P)&&A(P),P.has_requirement?(()=>{const z=E.find(Y=>Y.step.id===P.id);return o.jsx(l9,{requirement:z,step:P,parts:R,stepParts:w.filter(Y=>Y.step.id===(z.requirement_for_step?.id??z.step.id)),refetchFn:d})})():o.jsx(a9,{run:e,step:P,parts:R,stepParts:w.filter(z=>z.step.id===P.id),monitoredBy:I[P.id],refetchFn:d})]})]},V)})})]}),o.jsx(Oo,{data:p.data,setPage:i,isPlaceholderData:p.isPlaceholderData})]})}function c9(){const{run:e}=x.useContext(as);return o.jsxs("div",{children:[o.jsx("h2",{children:"Run information"}),o.jsx("h3",{children:"Run name"}),o.jsx("p",{children:e.name}),o.jsx("h3",{children:"Project name"}),o.jsx("p",{children:e.project.name})]})}const d9=()=>{const[e,t]=x.useState(null),[n,r]=x.useState(null),{id:i}=Te.useParams();x.useEffect(()=>{(e===null||i!==e.id.toString())&&tg({id:parseInt(i)}).then(a=>(Pl({id:a.run_id}).then(r),a)).then(t)},[i,e]);function s(){tg({id:parseInt(i)}).then(a=>(Pl({id:a.run_id}).then(r),a)).then(t)}return{run:n,runStep:e,setRunStep:t,reloadRunStep:s}};function y1({children:e}){const{runStep:t,setRunStep:n,run:r,reloadRunStep:i}=d9(),[s,a]=x.useState({});return t===null||r===null?o.jsx("div",{className:"d-flex justify-content-center h-100 vh-100 flex-row align-items-center",children:o.jsxs("div",{className:"d-flex flex-column align-items-center",children:[t===null&&o.jsx("h1",{children:"Loading run..."}),r===null&&o.jsx("h1",{children:"Loading run step..."}),o.jsxs("div",{className:"spinner-border",style:{width:"3rem",height:"3rem"},role:"status",children:[t===null&&o.jsx("span",{className:"visually-hidden",children:"Loading run step..."}),r===null&&o.jsx("span",{className:"visually-hidden",children:"Loading run..."})]})]})}):o.jsx(vn.Provider,{value:{runStep:t,setRunStep:n,reloadRunStep:i,run:r,modalProperties:s,setModalProperties:a},children:e})}function f9(){return o.jsx(y1,{children:o.jsx(es,{fluid:!0,children:o.jsx(Te.Outlet,{})})})}const p9=({label:e})=>o.jsx("div",{className:"p-2 h4 mb-1 bg-info text-white",children:e.label}),m9=({runStep:e})=>{const{environment:t}=Te.useParams();return o.jsxs("h2",{children:[" ",e.number," -",e.process_module.process.name," on"," ",o.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,")"]})]})},h9=({checklistItem:e,show:t,setModalShow:n,mutation:r})=>{const i=()=>n(!1);return o.jsxs(xe,{show:t,size:"lg",onHide:i,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Checklist item"})}),o.jsxs(xe.Body,{children:[o.jsx("h2",{children:e.task}),o.jsx("span",{dangerouslySetInnerHTML:{__html:e.description}})]}),o.jsxs(xe.Footer,{children:[o.jsx(de,{className:"float-end",variant:"primary",onClick:()=>{r.mutate()},children:"Done"}),o.jsx(de,{variant:"secondary",onClick:()=>n(!1),children:"Close"})]})]})},g9=({checklistItem:e,refetch:t})=>{const[n,r]=x.useState(!1),i=async()=>(await Ee.create().patch("update/run/step/checklist/done/"+e.id,{})).data,s=Pe.useMutation({mutationFn:i,onSuccess:l=>{r(!1),t()}}),a=()=>e.can_finish?e.description!==""?o.jsx(de,{className:"float-end",variant:"primary",onClick:()=>r(!0),children:"Execute checklist step"}):o.jsx(de,{className:"float-end",variant:"success",onClick:()=>{s.mutate()},children:"Done checklist step"}):null;return o.jsxs(Wn.Item,{disabled:e.is_executed,className:"d-flex justify-content-between align-items-start",children:[o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx("span",{className:"h5",children:e.task}),e.is_executed&&o.jsxs("small",{children:["Executed on ",o.jsx(Zi,{format:"DD-MM-YYYY",children:e.date_executed})]})]}),o.jsx("div",{className:"flex-shrink-0",children:o.jsx(a,{})}),o.jsx(h9,{checklistItem:e,show:n,setModalShow:r,mutation:s})]})},v9=()=>{let e=Te.useNavigate();const{environment:t}=Te.useParams(),{runStep:n,reloadRunStep:r,run:i}=x.useContext(vn);let s=x.useRef(!1);const{data:a,error:l,isLoading:u,refetch:c}=Pe.useQuery({queryKey:["checklist",n.id],queryFn:()=>bk({runStep:n})});if(u)return o.jsx("div",{children:"Loading..."});function d(g){Ee.create().patch("update/run/step/finish/"+g.id,{}).then(y=>{y.data.next_step_id!==null&&e(`/${t}/operator/run/step/${y.data.next_step_id}`)})}function p(g){Ee.create().patch("update/run/step/skip/"+g.id,{}).then(()=>{r(),g.next_step_id})}function h(g){Ee.create().patch("update/run/step/un-skip/"+g.id,{}).then(()=>{r()})}let m=!1;return s.current=!n.is_finished,a.items.forEach(g=>{let y=!g.is_executed&&!m;g.can_finish=y,y&&(m=!0,s.current=!1)}),o.jsxs(o.Fragment,{children:[a.items.length===0&&o.jsx(Bt,{variant:"info",children:"No checklist found"}),a.items.length>0&&o.jsx(Wn,{children:a.items.map((g,y)=>o.jsx(g9,{checklistItem:g,refetch:c},y))}),o.jsxs("div",{className:"d-flex justify-content-between mt-3",children:[o.jsxs("div",{className:"d-flex gap-2",children:[s.current&&o.jsx("div",{children:o.jsx(de,{variant:"success",onClick:()=>d(n),children:"Move out"})}),i.access.edit&&!n.is_skipped&&o.jsx("div",{children:o.jsx(de,{variant:"primary",onClick:()=>p(n),children:"Skip operation"})}),i.access.edit&&n.is_skipped&&o.jsx("div",{children:o.jsx(de,{variant:"warning",onClick:()=>h(n),children:"Unskip operation"})})]}),o.jsx("div",{className:"d-flex gap-2",children:n.next_step_id&&o.jsx("div",{children:o.jsx(Te.Link,{to:`/${t}/operator/run/step/${n.next_step_id}`,className:"btn btn-secondary",children:"Next step"})})})]})]})},x9=()=>{const{runStep:e,setRunStep:t}=x.useContext(vn),[n,r]=x.useState(!1),[i,s]=x.useState(!e.is_finished),{register:a,handleSubmit:l,formState:u}=gn({defaultValues:{remark:e.remark_unparsed}}),{isSubmitting:c}=u,d=async p=>{await Ee.create().patch("update/run/step/"+e.id,{remark:p.remark});const h=await Ee.get("view/run/step/"+e.id);t({...e,remark:h.data.remark,remark_unparsed:h.data.remark_unparsed}),r(!1)};return!n||!i?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"text-success",dangerouslySetInnerHTML:{__html:e.remark}}),i&&o.jsx(de,{variant:"primary",className:"mt-3",onClick:()=>r(!0),children:"Edit Remark"})]}):o.jsxs(H,{onSubmit:l(d),children:[o.jsx(H.Control,{as:"textarea",rows:6,...a("remark")}),o.jsx("p",{children:o.jsx("small",{className:"text-muted",children:"If a non-conformity happens during the process, write it down in the form field below"})}),o.jsxs(de,{variant:"primary",type:"submit",disabled:c,children:[c&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Save remark"]}),o.jsx(de,{variant:"secondary",className:"ms-2",onClick:()=>r(!1),children:"Cancel"})]})},y9=({run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})=>{const[s,a]=x.useState(!1),{register:l,control:u,setValue:c,handleSubmit:d,formState:p}=gn({defaultValues:{holdCode:r?{value:r.hold_code.id,label:r.hold_code.code}:{},description:r?r.description:""}}),{errors:h,isSubmitting:m}=p,g=async b=>{try{const S=await Ee.patch("update/run/hold-code/"+e.id,{holdcode:s?null:b.holdCode.value,description:b.description});S.data.hold_code?i(S.data):i(void 0),a(!1)}finally{n(!1)}},y=(b,S)=>{Ee.get("list/run/hold-code").then(R=>{const{data:w}=R;return w._embedded.items}).then(R=>{S(R.map(w=>({value:w.id,label:w.code})))})};return o.jsx(xe,{show:t,size:"lg",onHide:()=>n(!1),children:o.jsxs(H,{onSubmit:d(g),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:s?"Reset hold code":"Update hold code"})}),o.jsxs(xe.Body,{children:[!s&&o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Hold code"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(ar,{name:"holdCode",control:u,rules:{validate:{required:b=>b.value!==void 0||s||"A hold code is required"}},render:({field:b})=>o.jsx(Zu,{isSearchable:!1,defaultOptions:!0,placeholder:"Select a hold code",loadOptions:y,value:b.value,onChange:S=>{b.onChange(S)}})}),h.holdCode&&o.jsx("span",{className:"text-danger",children:h.holdCode.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Message"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"textarea",rows:3,...l("description",{required:"A message is required"}),isInvalid:h.description!==void 0}),h.description&&o.jsx(H.Control.Feedback,{type:"invalid",children:h.description.message})]})]})]}),o.jsxs(xe.Footer,{children:[o.jsxs(de,{type:"submit",variant:s?"success":"primary",disabled:m,children:[m&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),s?"Release lot":"Update Hold code"]}),r&&o.jsx(de,{variant:"outline-danger",onClick:()=>{c("description",s?r.description:""),a(!s)},children:s?"Update hold Code":"Reset hold code"})]})]})})},b9=()=>{const{run:e}=x.useContext(vn),[t,n]=x.useState(!1),[r,i]=x.useState(e.hold_code),s=()=>{n(!0)};return o.jsxs(o.Fragment,{children:[r&&o.jsx("span",{className:"badge handle",style:{backgroundColor:r.hold_code.back_color,color:r.hold_code.front_color,fontSize:"1.5rem",cursor:"pointer"},onClick:()=>s(),children:r.hold_code.code}),!r&&o.jsx(hn,{bg:"secondary",className:"handle",onClick:()=>s(),style:{fontSize:"1.5rem",cursor:"pointer"},children:"No hold code"}),o.jsx(y9,{run:e,show:t,setShow:n,runHoldCode:r,setRunHoldCode:i})]})},w9=()=>{const{run:e}=x.useContext(vn),[t,n]=x.useState(e.priority);return o.jsxs(x.Fragment,{children:[t&&o.jsx("span",{className:"badge",style:{backgroundColor:t.priority.back_color,color:t.priority.front_color,fontSize:"1.5rem"},children:t.priority.code}),!t&&o.jsx("span",{className:"badge bg-info",style:{fontSize:"1.5rem"},children:"NORMAL"})]})},S9=({run:e,runStep:t,showOnlyEmphasizedParameters:n})=>o.jsx(o.Fragment,{children:o.jsx("tr",{children:o.jsx("td",{colSpan:6,children:o.jsxs("div",{className:"d-flex gap-2",children:[o.jsx("div",{style:{flexGrow:1,flex:"1 1 50%"},children:o.jsx(Zm,{run:e,editable:!1,runStep:t})}),o.jsxs("div",{style:{flexGrow:1,flex:"1 1 50%"},children:[n&&o.jsx("h4",{children:"Emphasized parameters"}),!n&&o.jsx("h4",{children:"Parameters"}),o.jsx(qm,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:n})]})]})})})}),C9=({run:e,monitoredBy:t,runStep:n,runParts:r,runStepParts:i,hideLabel:s,firstInGroup:a})=>{const{environment:l}=Te.useParams(),[u,c]=x.useState(!1),{runStep:d}=x.useContext(vn);return o.jsxs(o.Fragment,{children:[!s&&n.has_label&&n.is_own_label&&o.jsx("tr",{children:o.jsx("td",{className:"bg-info",colSpan:7,children:n.label?.label})}),n.step_group&&a&&o.jsx("tr",{children:o.jsx("td",{className:"bg-secondary",colSpan:7,children:n.step_group?.label})}),o.jsxs("tr",{children:[o.jsxs("td",{className:n.has_step_group?"ps-4":"",children:[n.id!==d.id&&o.jsx("i",{className:"fa "+(u?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{c(!u)}}),n.id===d.id&&o.jsx("i",{className:"fa fa-chevron-right text-success",style:{cursor:"pointer"},title:"This step is currently running"})]}),o.jsx("td",{children:o.jsx(g1,{step:n,parts:r,stepParts:i})}),o.jsxs("td",{children:[n.number," ",n.is_skipped&&o.jsx(hn,{bg:"info",children:"Skipped"})]}),o.jsxs("td",{children:[o.jsx(Te.Link,{to:`/${l}/operator/run/step/${n.id}`,dangerouslySetInnerHTML:{__html:n.name}})," ",t&&o.jsx(Wi,{placement:"top",overlay:o.jsx(xi,{id:`tooltip-${t.id}`,children:`Monitored by step: ${t.step.number}`}),children:o.jsx("i",{className:"fa fa-search me-2"})})]}),o.jsx("td",{children:n.finish_user?n.finish_user.initials:""}),o.jsx("td",{children:n.has_rework?o.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),o.jsx("td",{children:n.is_finished?o.jsx(Zi,{format:"DD-MM-YYYY",children:n.finish_date}):""})]}),u&&o.jsx(S9,{run:e,runStep:n,showOnlyEmphasizedParameters:!1})]})};function _9({requirement:e,step:t,stepParts:n,parts:r,measurementResults:i}){const s=n.filter(l=>l.step.id===(e.requirement_for_step?.id??e.step.id)),{environment:a}=Te.useParams();return o.jsx(o.Fragment,{children:o.jsx("tr",{children:o.jsx("td",{colSpan:7,children:o.jsxs("div",{className:"d-flex gap-2",children:[o.jsxs("div",{style:{flexGrow:1,flex:"1 1 50%"},children:[o.jsx("h4",{children:"Measurement results"}),o.jsx(Jm,{requirement:e,step:t,stepParts:s,parts:r,measurementResults:i,editOnly:!0})]}),o.jsxs("div",{style:{flexGrow:1,flex:"1 1 50%"},children:[" ",o.jsx("h4",{children:"Monitored Step"}),o.jsx(Te.Link,{to:`/${a}/operator/run/step/${e.requirement_for_step?.id??e.step.id}`,children:o.jsxs("span",{children:[o.jsx("i",{className:"fa fa-search"})," ",e.requirement_for_step?.name??e.step.name]})}),o.jsx("h4",{children:"Definition"}),o.jsx("span",{children:e.definition}),o.jsx("h4",{children:"Targets"}),o.jsxs(Kt,{size:"sm",striped:!1,bordered:!1,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"min value"}),o.jsx("th",{children:"max value"}),o.jsx("th",{children:"inclusive"})]})}),o.jsx("tbody",{children:e.targets.map(l=>o.jsxs("tr",{children:[o.jsx("td",{children:l.min_value}),o.jsx("td",{children:l.max_value}),o.jsx("td",{children:l.inclusive?"yes":"no"})]},l.id))})]})]})]})})})})}function E9({requirement:e,runParts:t,runStepParts:n,hideLabel:r,firstInGroup:i}){const s=e.step,{environment:a}=Te.useParams(),{runStep:l}=x.useContext(vn),[u,c]=x.useState(!1),d=Pe.useQueries({queries:[{queryKey:["requirement","measurementResults",JSON.stringify(e.measurement.id)],queryFn:()=>wu({measurement:e.measurement})}]}),[p]=d,h=()=>{if(!p.data)return"";let m=!1;for(const g of n){const y=p.data?.items.find(R=>R.values.some(w=>w.step_part_id===g.id))?.values.find(R=>R.step_part_id===g.id);if(!(y&&!isNaN(parseFloat(y.string_value))))return s.id===l.id?"table-success":"";const b=parseFloat(y.string_value);if(e.targets.some(R=>R.inclusive?!(R.min_value<=b&&R.max_value>=b):!(R.min_value<b&&R.max_value>b))){m=!0;break}}return m?"table-danger":s.id===l.id?"table-success":""};return o.jsxs(o.Fragment,{children:[!r&&s.has_label&&s.is_own_label&&o.jsx("tr",{children:o.jsx("td",{className:"bg-info",colSpan:7,children:s.label?.label})}),s.step_group&&i&&o.jsx("tr",{children:o.jsx("td",{className:"bg-secondary",colSpan:7,children:s.step_group?.label})}),o.jsxs("tr",{className:h(),children:[o.jsx("td",{className:s.has_step_group?"ps-4":"",children:s.id!==l.id&&o.jsx("i",{className:"fa "+(u?"fa-chevron-down":"fa-chevron-right"),style:{cursor:"pointer"},onClick:()=>{c(!u)}})}),o.jsx("td",{children:o.jsx(x1,{requirement:e,step:s,parts:t,stepParts:n,measurementResults:p.data?.items??[]})}),o.jsxs("td",{children:[s.number," ",s.is_skipped&&o.jsx(hn,{bg:"info",children:"Skipped"})]}),o.jsxs("td",{children:[o.jsx(hn,{bg:"info",children:"requirement"})," ",o.jsx(Te.Link,{to:`/${a}/operator/run/step/${s.id}`,dangerouslySetInnerHTML:{__html:s.name}})," "]}),o.jsx("td",{children:s.finish_user?s.finish_user.initials:""}),o.jsx("td",{children:s.has_rework?o.jsx("span",{className:"badge bg-primary",children:"Rework"}):""}),o.jsx("td",{children:s.is_finished?o.jsx(Zi,{format:"DD-MM-YYYY",children:s.finish_date}):""})]}),u&&o.jsx(_9,{requirement:e,step:s,stepParts:n,parts:t,measurementResults:p.data?.items??[]})]})}const b1=({pageSize:e=25,hideLabel:t=!1})=>{const{runStep:n,run:r}=x.useContext(vn),[i,s]=x.useState(1);x.useEffect(()=>{n?.sequence&&s(Math.max(1,Math.ceil(n.sequence/e)))},[n?.sequence,e]);const a=r?.id??null,l=Pe.useQuery({queryKey:["runParts",`${a}`],queryFn:()=>bu({run:r}),enabled:!!a}),u=Pe.useQuery({queryKey:["runStepParts",`${a}`],queryFn:()=>ro({run:r}),enabled:!!a}),c=Pe.useQuery({queryKey:["runSteps",a,i,e],queryFn:()=>dp({run:r,page:i,pageSize:e}),enabled:!!a,placeholderData:Pe.keepPreviousData}),d=Pe.useQuery({queryKey:["requirements",a],queryFn:()=>cp({run:r}),enabled:!!a,placeholderData:Pe.keepPreviousData}),p=l.isLoading||u.isLoading||c.isLoading||d.isLoading,h=l.isError||u.isError||c.isError||d.isError,m=l.error||u.error||c.error||d.error,g=l.data?.items??[],y=u.data?.items??[],b=c.data?.items??[],S=d.data?.items??[],R=new Set,w=b.filter(C=>!C.has_step_group||typeof C.step_group?.id!="number"||R.has(String(C.step_group.id))?!1:(R.add(String(C.step_group.id)),!0)),E={};for(const C of S)C.requirement_for_step!=null&&(E[String(C.requirement_for_step.id)]=C);return x.useEffect(()=>{h&&console.error("RunStepSimpleList query error",{runId:a,errors:[l.error,u.error,c.error,d.error]})},[h,a,l.error,u.error,c.error,d.error]),o.jsxs("div",{children:[p?o.jsx("div",{children:"Loading..."}):h?o.jsxs("div",{children:["Error: ",String(m?.message??m)]}):o.jsx(Kt,{size:"sm",striped:!0,bordered:!0,hover:!0,children:o.jsx("tbody",{children:b.map((C,k)=>o.jsx(x.Fragment,{children:C.has_requirement?(()=>{const I=S.find(A=>A.step.id===C.id);return o.jsx(E9,{requirement:I,runParts:g,runStepParts:y,firstInGroup:w.includes(C)},C.id??C.sequence??k)})():o.jsx(C9,{run:r,monitoredBy:E[C.id],runParts:g,runStepParts:y,hideLabel:t,firstInGroup:w.includes(C),runStep:C},C.id??C.sequence??k)},k))})}),o.jsx(Oo,{data:c.data,setPage:s,isPlaceholderData:c.isPlaceholderData}),c.isFetching?o.jsx("span",{children:" Loading..."}):null]})},I9=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(vn),[r,i]=x.useState(1),{isPending:s,isLoading:a,isError:l,error:u,data:c,isFetching:d,isPlaceholderData:p}=Pe.useQuery({queryKey:["run_changelog",n,r],queryFn:()=>xk({run:n,page:r}),placeholderData:Pe.keepPreviousData});return o.jsxs(xe,{show:e,size:"lg",onHide:()=>t(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsxs(xe.Title,{children:["History of Run ",n.label]})}),o.jsx(xe.Body,{children:o.jsxs("div",{children:[s?o.jsx("div",{children:"Loading..."}):l?o.jsxs("div",{children:["Error: ",u.message]}):o.jsx(Kt,{size:"sm",striped:!0,bordered:!0,hover:!0,children:o.jsx("tbody",{children:c.items.map((h,m)=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx(Zi,{format:"DD-MM-YYYY",children:h.date_created})}),o.jsx("td",{children:o.jsx("span",{dangerouslySetInnerHTML:{__html:h.message}})}),o.jsxs("td",{children:[h.user.first_name," ",h.user.last_name]})]},m))})}),o.jsx(Oo,{data:c,setPage:i,isPlaceholderData:p}),d?o.jsx("span",{children:" Loading..."}):null]})}),o.jsx(xe.Footer,{children:o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},j9=({size:e})=>{const[t,n]=x.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx(de,{size:e,variant:"primary",onClick:()=>n(!t),children:"Run history"}),t&&o.jsx(I9,{show:t,setModalShow:n})]})},R9=({show:e,setModalShow:t})=>{const{run:n}=x.useContext(vn);return o.jsxs(xe,{show:e,size:"xl",onHide:()=>t(!1),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsxs(xe.Title,{children:["All steps of run ",n.label]})}),o.jsx(xe.Body,{children:o.jsx(b1,{hideLabel:!1})}),o.jsx(xe.Footer,{children:o.jsx(de,{className:"float-end",variant:"secondary",onClick:()=>{t(!1)},children:"Close"})})]})},k9=({size:e})=>{const[t,n]=x.useState(!1);return o.jsxs(x.Fragment,{children:[o.jsx(de,{size:e,variant:"primary",onClick:()=>n(!0),children:"All run steps"}),t&&o.jsx(R9,{show:t,setModalShow:n})]})},A9=()=>{const{runStep:e,run:t}=x.useContext(vn),[n,r]=x.useState(!1),[i,s]=x.useState({}),[a,l]=x.useState(null),[u,c]=x.useState([]),[d,p]=x.useState([]),[h,m]=x.useState([]),[g,y]=x.useState(""),[b,S]=x.useState(!1);if(!e.has_recipe)return"Reworks are only possible for steps with a recipe";const[R,w,E]=Pe.useQueries({queries:[{queryKey:["templates",h],queryFn:()=>jk({reworkRecipes:h}),enabled:n&&h.length>0},{queryKey:["run_steps",e.id],queryFn:()=>dp({run:t,page:1,pageSize:1e3}),enabled:n},{queryKey:["template_steps","rework",a,e.id],queryFn:()=>Ik({template:a,pageSize:1e3}),enabled:a!==null}]});x.useEffect(()=>{if(w.isSuccess&&u.length>0){let I=w.data.items.filter(A=>u.includes(A.id)).map(A=>A.recipe_version.recipe);m([...I])}},[w.isSuccess,u]);function C(I){let A=R.data.templates.find(F=>F.id===I);A!==void 0&&l(A)}function k(){let I={};s({}),u.length===0&&(I.runStep="Please select at least one step"),s(A=>({...A,...I})),Object.keys(I).length===0&&(S(!0),Ee.create().patch("/update/run/step/rework/"+e.id,{reworked_run_steps:u,template_steps:d,comment:g}).then(()=>{S(!1),window.location.reload()}))}return o.jsxs(o.Fragment,{children:[n&&o.jsxs(H,{method:"post",onSubmit:()=>k(),children:[o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Template"}),o.jsxs("div",{className:"col-sm-9",children:[h.length===0&&o.jsx(Bt,{variant:"info",children:"Please select a rework step"}),h.length>0&&o.jsxs(H.Control,{as:"select",name:"template",onChange:I=>C(parseInt(I.target.value)),isInvalid:!!i.template,children:[o.jsx("option",{value:"",children:"— Select a template"}),R.data!==void 0&&R.data.templates.map((I,A)=>o.jsxs("option",{value:I.id,children:[I.label,": ",I.name]},A))]}),i.template&&o.jsx("span",{className:"text-danger",children:i.template})]})]}),a!==null&&o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Include template steps"}),o.jsx("div",{className:"col-sm-9",children:o.jsx("ul",{className:"list-group",children:!E.isLoading&&E.data!==void 0&&E.data.steps.map((I,A)=>o.jsx("li",{className:"list-group-item ",children:o.jsxs("div",{className:"form-check",children:[o.jsx("input",{type:"checkbox",className:"form-check-input",id:"templateStep"+I.id,name:"templateStep",onChange:F=>{F.target.checked?p([...d,I.id]):p(d.filter(P=>P!==I.id))},value:I.id}),o.jsxs("label",{htmlFor:"templateStep"+I.id,className:"from-check-label",children:[o.jsxs("small",{className:"text-muted pe-2",children:[I.number,":"]}),I.process_module.process.name]})]})},A))})})]}),o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Repeat steps"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsxs("ul",{className:"list-group",children:[w.isLoading&&o.jsx("option",{children:"Loading run steps..."}),!w.isLoading&&w.data.items.map((I,A)=>{if(e.sequence>=I.sequence)return o.jsxs("li",{className:"list-group-item d-flex justify-content-between"+(e.id===I.id?" bg-success-subtle":""),children:[o.jsxs("div",{className:"form-check",children:[o.jsx("input",{type:"checkbox",className:"form-check-input",id:"runStep"+I.id,name:"runStep",onChange:F=>{F.target.checked?c([...u,I.id]):c(u.filter(P=>P!==I.id))},value:I.id}),o.jsxs("label",{htmlFor:"runStep"+I.id,className:"from-check-label",children:[o.jsxs("small",{className:"text-muted pe-2",children:[I.number,":"]}),I.process_module.process.name]})]}),I.is_finished&&o.jsx("div",{children:o.jsx("span",{className:"badge bg-success",children:"Finished"})})]},A)})]}),i.runStep&&o.jsx("span",{className:"text-danger",children:i.runStep})]})]}),o.jsxs("div",{className:"row mb-3",children:[o.jsx(H.Label,{className:"col-sm-3 col-form-label text-end",children:"Comment"}),o.jsx("div",{className:"col-sm-9",children:o.jsxs(H.Group,{controlId:"runStep.remark",children:[o.jsx(H.Control,{as:"textarea",rows:6,onChange:I=>y(I.target.value),value:g,isInvalid:!!i.comment}),o.jsx("small",{className:"text-muted",children:"Optional comment for the rework"})]})})]}),o.jsx("div",{className:"row mb-3",children:o.jsxs("div",{className:"col-sm-9 offset-sm-3",children:[o.jsxs(de,{variant:"primary",onClick:()=>k(),disabled:b,children:[b&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create rework"]})," ",o.jsx(de,{variant:"warning",onClick:()=>r(!1),children:"Cancel"})]})})]}),!n&&o.jsx(de,{variant:"primary",className:"mt-3",onClick:()=>r(!0),children:"Set Rework"})]})},N9=()=>{const{environment:e}=Te.useParams(),{runStep:t,run:n}=x.useContext(vn),r=Pe.useQueries({queries:[{queryKey:["monitors",t.process_module.module.equipment],queryFn:()=>Hy({equipment:t.process_module.module.equipment})},{queryKey:["ecn",t.process_module.module],queryFn:()=>up({module:t.process_module.module})},{queryKey:["equipmentModule",t.process_module.module],queryFn:()=>lk({id:t.process_module.module.id})},{queryKey:["requirement",t.id],queryFn:()=>cp({run:n,step:t})}]}),[i,s,a,l]=r,[u,c]=x.useState(!0),d=r.some(m=>m.isLoading);if(r.some(m=>m.isError))return r.filter(m=>m.isError).forEach((m,g)=>{console.error("StepDashboard query error",{index:g,error:m.error,runStep:t,run:n})}),o.jsx(o.Fragment,{children:"Error fetching data"});if(d)return o.jsx("div",{children:"Loading..."});const h=a.data;return o.jsx(es,{fluid:!0,children:o.jsxs(Un,{children:[o.jsxs(Mt,{className:"col-9",children:[n.run_type===Hn.RESEARCH&&o.jsx("small",{children:"Research run"}),n.run_type===Hn.PRODUCTION&&o.jsx("small",{children:"Production run"}),o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[o.jsxs("h1",{className:"display-4",children:[n.name," (",n.project.name,")"]}),o.jsxs("div",{className:"d-flex flex-column flex-lg-row gap-2 flex-wrap justify-content-end",children:[t.has_rework&&o.jsx("span",{style:{fontSize:"1.5rem"},className:"mx-1 badge bg-primary",children:"Rework"}),o.jsx(w9,{}),o.jsx(b9,{}),t.is_skipped&&o.jsx("span",{style:{fontSize:"1.5rem"},className:"badge bg-info",children:"SKIPPED"})]})]}),o.jsx(m1,{run:n}),t.label&&o.jsx(p9,{label:t.label}),o.jsx(m9,{runStep:t}),t.is_finished&&o.jsxs(Bt,{variant:"success",children:["This step has been finished by ",t.finish_user?.first_name," ",t.finish_user?.last_name]}),t.has_recipe&&o.jsx(Ze,{className:"rounded my-4",children:o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{className:"text-muted",children:"Recipe"}),o.jsxs(Ze.Text,{className:"display-5",children:[t.recipe_version.recipe.name," (Version ",t.recipe_version.version,")"]})]})}),l.data?.items.length==1&&o.jsxs(o.Fragment,{children:[o.jsx("h4",{children:"Measurements by part"}),o.jsx(Jm,{requirement:l.data.items[0],step:t,editOnly:!1}),o.jsx("h4",{children:"Measurements for whole step"}),o.jsx(v1,{requirement:l.data.items[0],editOnly:!1})]}),l.data?.items.length!=1&&n.run_type===Hn.RESEARCH&&o.jsx(Zm,{run:n,runStep:t}),l.data?.items.length!=1&&n.run_type===Hn.PRODUCTION&&o.jsx(h1,{run:n,runStep:t}),o.jsxs(Un,{className:"py-4",children:[o.jsxs(Mt,{children:[o.jsx("h3",{children:"Checklist"}),o.jsx(v9,{})]}),o.jsxs(Mt,{children:[o.jsx("h2",{children:"Parameters"}),o.jsxs("div",{className:"form-check form-switch",children:[o.jsx("input",{type:"checkbox",checked:u,className:"form-check-input","data-toggle":"toggle",onChange:()=>c(!u)}),o.jsx("label",{className:"ms-2",children:"Show only emphasized parameters"})]}),o.jsx(qm,{runStep:t,editableParameters:!1,showOnlyEmphasizedParameters:u}),t.has_instructions&&t.instructions&&o.jsxs(o.Fragment,{children:[o.jsx("h3",{children:"Instructions"}),o.jsx("span",{dangerouslySetInnerHTML:{__html:t.instructions}})]}),o.jsx("h3",{children:"Remark"}),o.jsx(x9,{}),o.jsx("h3",{className:"pt-3",children:"Rework"}),o.jsx(A9,{})]})]}),o.jsxs(Un,{children:[o.jsxs(Mt,{children:[o.jsx("h2",{children:"Step files"}),o.jsx(Xm,{runStep:t})]}),o.jsxs(Mt,{children:[o.jsxs("div",{className:"d-flex justify-content-between mb-3",children:[o.jsx("h2",{children:"Run steps"}),o.jsxs("div",{className:"d-flex gap-2 flex-wrap justify-content-end",children:[o.jsx("div",{children:o.jsx(k9,{size:void 0})}),o.jsx("div",{children:o.jsx(j9,{size:void 0})}),o.jsx("div",{children:o.jsx(l1,{size:void 0,moduleId:t.process_module.module.id})})]})]}),o.jsx(b1,{pageSize:n.run_type===Hn.RESEARCH?5:1e3,hideLabel:!0})]})]})]}),o.jsx(Mt,{className:"col-3",children:o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx("h2",{children:o.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,")"]})}),h&&o.jsx("div",{children:o.jsx("h2",{children:o.jsx(qi,{module:h})})}),i.data?.items&&i.data.items.map((m,g)=>o.jsx(Um,{monitor:m},g)),s.data?.items.map(function(m,g){return o.jsxs(Ze,{className:"my-2",children:[o.jsxs(Ze.Header,{children:["ECN: ",m.ecn]}),o.jsx(Ze.Body,{children:o.jsx(Ze.Text,{children:o.jsx(ss,{children:m.description})})}),o.jsxs(Ze.Footer,{children:[m.date_created&&o.jsxs(o.Fragment,{children:["Created by ",Ln(m.date_created,"DD-MM-YY H:m")," by ",m.owner.full_name]}),m.last_update&&o.jsxs(o.Fragment,{children:[" ","· Updated by ",Ln(m.last_update,"DD-MM-YY H:m")," by"," ",m.owner.full_name]})]})]},g)})]})})]})})},w1=()=>{const[e,t]=x.useState(!1),{modalProperties:n}=x.useContext(vn),r=()=>{t(!1),n.show=!1};return x.useEffect(()=>{t(n.show)},[n]),o.jsxs(xe,{show:e,size:"xl",onHide:r,children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:n.modalTitle})}),o.jsx(xe.Body,{children:n.modalContent}),o.jsxs(xe.Footer,{children:[o.jsx(de,{variant:"secondary",onClick:r,children:"Save"}),n.modalSaveButton]})]})};function O9(){return o.jsxs(o.Fragment,{children:[o.jsx(N9,{}),o.jsx(w1,{})]})}function D9({children:e}){const[t,n]=x.useState(!1);return o.jsx(pc.Provider,{value:{showOnlyEmphasizedParameters:t,setShowOnlyEmphasizedParameters:n},children:e})}function M9(){return o.jsx(es,{fluid:!0,children:o.jsx(Te.Outlet,{})})}function F9({control:e,name:t}){const{environment:n}=Te.useParams(),[r,i]=x.useState([]),[s,a]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const u=await pk({environment:n,withLocations:!0});i(u.items)}catch(u){console.error("Error fetching rooms:",u)}finally{a(!1)}}l()},[]),s?o.jsx("p",{children:"Loading labs..."}):o.jsxs("div",{children:[o.jsx("h3",{children:"Choose a labs"}),o.jsx(H.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:o.jsx(ar,{name:t,render:({field:{onChange:l,value:u}})=>o.jsxs(H.Select,{"aria-label":"Choose a lab",value:u?.id||"",onChange:c=>{const d=r.find(p=>p.id.toString()===c.target.value);l(d||null)},children:[o.jsx("option",{value:"",children:"— Choose a lab"}),r.map(c=>o.jsx("option",{value:c.id,children:c.name},c.id))]}),control:e})})]})}function T9({control:e}){return o.jsx(H.Group,{className:"mb-3",controlId:"chemical.scanBarcode",children:o.jsx(ar,{name:"barcode",control:e,render:({field:t})=>o.jsx("input",{...t,id:"chemical.scanBarcodeElement",type:"text",autoFocus:!0,placeholder:"Scan or enter barcode",className:"form-control form-control-lg"})})})}var P9=Object.defineProperty,mu=Object.getOwnPropertySymbols,S1=Object.prototype.hasOwnProperty,C1=Object.prototype.propertyIsEnumerable,fy=(e,t,n)=>t in e?P9(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,np=(e,t)=>{for(var n in t||(t={}))S1.call(t,n)&&fy(e,n,t[n]);if(mu)for(var n of mu(t))C1.call(t,n)&&fy(e,n,t[n]);return e},rp=(e,t)=>{var n={};for(var r in e)S1.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&mu)for(var r of mu(e))t.indexOf(r)<0&&C1.call(e,r)&&(n[r]=e[r]);return n};var Ji;(e=>{const t=class Ke{constructor(u,c,d,p){if(this.version=u,this.errorCorrectionLevel=c,this.modules=[],this.isFunction=[],u<Ke.MIN_VERSION||u>Ke.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=u*4+17;let h=[];for(let g=0;g<this.size;g++)h.push(!1);for(let g=0;g<this.size;g++)this.modules.push(h.slice()),this.isFunction.push(h.slice());this.drawFunctionPatterns();const m=this.addEccAndInterleave(d);if(this.drawCodewords(m),p==-1){let g=1e9;for(let y=0;y<8;y++){this.applyMask(y),this.drawFormatBits(y);const b=this.getPenaltyScore();b<g&&(p=y,g=b),this.applyMask(y)}}i(0<=p&&p<=7),this.mask=p,this.applyMask(p),this.drawFormatBits(p),this.isFunction=[]}static encodeText(u,c){const d=e.QrSegment.makeSegments(u);return Ke.encodeSegments(d,c)}static encodeBinary(u,c){const d=e.QrSegment.makeBytes(u);return Ke.encodeSegments([d],c)}static encodeSegments(u,c,d=1,p=40,h=-1,m=!0){if(!(Ke.MIN_VERSION<=d&&d<=p&&p<=Ke.MAX_VERSION)||h<-1||h>7)throw new RangeError("Invalid value");let g,y;for(g=d;;g++){const w=Ke.getNumDataCodewords(g,c)*8,E=a.getTotalBits(u,g);if(E<=w){y=E;break}if(g>=p)throw new RangeError("Data too long")}for(const w of[Ke.Ecc.MEDIUM,Ke.Ecc.QUARTILE,Ke.Ecc.HIGH])m&&y<=Ke.getNumDataCodewords(g,w)*8&&(c=w);let b=[];for(const w of u){n(w.mode.modeBits,4,b),n(w.numChars,w.mode.numCharCountBits(g),b);for(const E of w.getData())b.push(E)}i(b.length==y);const S=Ke.getNumDataCodewords(g,c)*8;i(b.length<=S),n(0,Math.min(4,S-b.length),b),n(0,(8-b.length%8)%8,b),i(b.length%8==0);for(let w=236;b.length<S;w^=253)n(w,8,b);let R=[];for(;R.length*8<b.length;)R.push(0);return b.forEach((w,E)=>R[E>>>3]|=w<<7-(E&7)),new Ke(g,c,R,h)}getModule(u,c){return 0<=u&&u<this.size&&0<=c&&c<this.size&&this.modules[c][u]}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 u=this.getAlignmentPatternPositions(),c=u.length;for(let d=0;d<c;d++)for(let p=0;p<c;p++)d==0&&p==0||d==0&&p==c-1||d==c-1&&p==0||this.drawAlignmentPattern(u[d],u[p]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(u){const c=this.errorCorrectionLevel.formatBits<<3|u;let d=c;for(let h=0;h<10;h++)d=d<<1^(d>>>9)*1335;const p=(c<<10|d)^21522;i(p>>>15==0);for(let h=0;h<=5;h++)this.setFunctionModule(8,h,r(p,h));this.setFunctionModule(8,7,r(p,6)),this.setFunctionModule(8,8,r(p,7)),this.setFunctionModule(7,8,r(p,8));for(let h=9;h<15;h++)this.setFunctionModule(14-h,8,r(p,h));for(let h=0;h<8;h++)this.setFunctionModule(this.size-1-h,8,r(p,h));for(let h=8;h<15;h++)this.setFunctionModule(8,this.size-15+h,r(p,h));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let u=this.version;for(let d=0;d<12;d++)u=u<<1^(u>>>11)*7973;const c=this.version<<12|u;i(c>>>18==0);for(let d=0;d<18;d++){const p=r(c,d),h=this.size-11+d%3,m=Math.floor(d/3);this.setFunctionModule(h,m,p),this.setFunctionModule(m,h,p)}}drawFinderPattern(u,c){for(let d=-4;d<=4;d++)for(let p=-4;p<=4;p++){const h=Math.max(Math.abs(p),Math.abs(d)),m=u+p,g=c+d;0<=m&&m<this.size&&0<=g&&g<this.size&&this.setFunctionModule(m,g,h!=2&&h!=4)}}drawAlignmentPattern(u,c){for(let d=-2;d<=2;d++)for(let p=-2;p<=2;p++)this.setFunctionModule(u+p,c+d,Math.max(Math.abs(p),Math.abs(d))!=1)}setFunctionModule(u,c,d){this.modules[c][u]=d,this.isFunction[c][u]=!0}addEccAndInterleave(u){const c=this.version,d=this.errorCorrectionLevel;if(u.length!=Ke.getNumDataCodewords(c,d))throw new RangeError("Invalid argument");const p=Ke.NUM_ERROR_CORRECTION_BLOCKS[d.ordinal][c],h=Ke.ECC_CODEWORDS_PER_BLOCK[d.ordinal][c],m=Math.floor(Ke.getNumRawDataModules(c)/8),g=p-m%p,y=Math.floor(m/p);let b=[];const S=Ke.reedSolomonComputeDivisor(h);for(let w=0,E=0;w<p;w++){let C=u.slice(E,E+y-h+(w<g?0:1));E+=C.length;const k=Ke.reedSolomonComputeRemainder(C,S);w<g&&C.push(0),b.push(C.concat(k))}let R=[];for(let w=0;w<b[0].length;w++)b.forEach((E,C)=>{(w!=y-h||C>=g)&&R.push(E[w])});return i(R.length==m),R}drawCodewords(u){if(u.length!=Math.floor(Ke.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let c=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 h=0;h<2;h++){const m=d-h,y=(d+1&2)==0?this.size-1-p:p;!this.isFunction[y][m]&&c<u.length*8&&(this.modules[y][m]=r(u[c>>>3],7-(c&7)),c++)}}i(c==u.length*8)}applyMask(u){if(u<0||u>7)throw new RangeError("Mask value out of range");for(let c=0;c<this.size;c++)for(let d=0;d<this.size;d++){let p;switch(u){case 0:p=(d+c)%2==0;break;case 1:p=c%2==0;break;case 2:p=d%3==0;break;case 3:p=(d+c)%3==0;break;case 4:p=(Math.floor(d/3)+Math.floor(c/2))%2==0;break;case 5:p=d*c%2+d*c%3==0;break;case 6:p=(d*c%2+d*c%3)%2==0;break;case 7:p=((d+c)%2+d*c%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[c][d]&&p&&(this.modules[c][d]=!this.modules[c][d])}}getPenaltyScore(){let u=0;for(let h=0;h<this.size;h++){let m=!1,g=0,y=[0,0,0,0,0,0,0];for(let b=0;b<this.size;b++)this.modules[h][b]==m?(g++,g==5?u+=Ke.PENALTY_N1:g>5&&u++):(this.finderPenaltyAddHistory(g,y),m||(u+=this.finderPenaltyCountPatterns(y)*Ke.PENALTY_N3),m=this.modules[h][b],g=1);u+=this.finderPenaltyTerminateAndCount(m,g,y)*Ke.PENALTY_N3}for(let h=0;h<this.size;h++){let m=!1,g=0,y=[0,0,0,0,0,0,0];for(let b=0;b<this.size;b++)this.modules[b][h]==m?(g++,g==5?u+=Ke.PENALTY_N1:g>5&&u++):(this.finderPenaltyAddHistory(g,y),m||(u+=this.finderPenaltyCountPatterns(y)*Ke.PENALTY_N3),m=this.modules[b][h],g=1);u+=this.finderPenaltyTerminateAndCount(m,g,y)*Ke.PENALTY_N3}for(let h=0;h<this.size-1;h++)for(let m=0;m<this.size-1;m++){const g=this.modules[h][m];g==this.modules[h][m+1]&&g==this.modules[h+1][m]&&g==this.modules[h+1][m+1]&&(u+=Ke.PENALTY_N2)}let c=0;for(const h of this.modules)c=h.reduce((m,g)=>m+(g?1:0),c);const d=this.size*this.size,p=Math.ceil(Math.abs(c*20-d*10)/d)-1;return i(0<=p&&p<=9),u+=p*Ke.PENALTY_N4,i(0<=u&&u<=2568888),u}getAlignmentPatternPositions(){if(this.version==1)return[];{const u=Math.floor(this.version/7)+2,c=this.version==32?26:Math.ceil((this.version*4+4)/(u*2-2))*2;let d=[6];for(let p=this.size-7;d.length<u;p-=c)d.splice(1,0,p);return d}}static getNumRawDataModules(u){if(u<Ke.MIN_VERSION||u>Ke.MAX_VERSION)throw new RangeError("Version number out of range");let c=(16*u+128)*u+64;if(u>=2){const d=Math.floor(u/7)+2;c-=(25*d-10)*d-55,u>=7&&(c-=36)}return i(208<=c&&c<=29648),c}static getNumDataCodewords(u,c){return Math.floor(Ke.getNumRawDataModules(u)/8)-Ke.ECC_CODEWORDS_PER_BLOCK[c.ordinal][u]*Ke.NUM_ERROR_CORRECTION_BLOCKS[c.ordinal][u]}static reedSolomonComputeDivisor(u){if(u<1||u>255)throw new RangeError("Degree out of range");let c=[];for(let p=0;p<u-1;p++)c.push(0);c.push(1);let d=1;for(let p=0;p<u;p++){for(let h=0;h<c.length;h++)c[h]=Ke.reedSolomonMultiply(c[h],d),h+1<c.length&&(c[h]^=c[h+1]);d=Ke.reedSolomonMultiply(d,2)}return c}static reedSolomonComputeRemainder(u,c){let d=c.map(p=>0);for(const p of u){const h=p^d.shift();d.push(0),c.forEach((m,g)=>d[g]^=Ke.reedSolomonMultiply(m,h))}return d}static reedSolomonMultiply(u,c){if(u>>>8||c>>>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^=(c>>>p&1)*u;return i(d>>>8==0),d}finderPenaltyCountPatterns(u){const c=u[1];i(c<=this.size*3);const d=c>0&&u[2]==c&&u[3]==c*3&&u[4]==c&&u[5]==c;return(d&&u[0]>=c*4&&u[6]>=c?1:0)+(d&&u[6]>=c*4&&u[0]>=c?1:0)}finderPenaltyTerminateAndCount(u,c,d){return u&&(this.finderPenaltyAddHistory(c,d),c=0),c+=this.size,this.finderPenaltyAddHistory(c,d),this.finderPenaltyCountPatterns(d)}finderPenaltyAddHistory(u,c){c[0]==0&&(u+=this.size),c.pop(),c.unshift(u)}};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,u,c){if(u<0||u>31||l>>>u)throw new RangeError("Value out of range");for(let d=u-1;d>=0;d--)c.push(l>>>d&1)}function r(l,u){return(l>>>u&1)!=0}function i(l){if(!l)throw new Error("Assertion error")}const s=class Dt{constructor(u,c,d){if(this.mode=u,this.numChars=c,this.bitData=d,c<0)throw new RangeError("Invalid argument");this.bitData=d.slice()}static makeBytes(u){let c=[];for(const d of u)n(d,8,c);return new Dt(Dt.Mode.BYTE,u.length,c)}static makeNumeric(u){if(!Dt.isNumeric(u))throw new RangeError("String contains non-numeric characters");let c=[];for(let d=0;d<u.length;){const p=Math.min(u.length-d,3);n(parseInt(u.substring(d,d+p),10),p*3+1,c),d+=p}return new Dt(Dt.Mode.NUMERIC,u.length,c)}static makeAlphanumeric(u){if(!Dt.isAlphanumeric(u))throw new RangeError("String contains unencodable characters in alphanumeric mode");let c=[],d;for(d=0;d+2<=u.length;d+=2){let p=Dt.ALPHANUMERIC_CHARSET.indexOf(u.charAt(d))*45;p+=Dt.ALPHANUMERIC_CHARSET.indexOf(u.charAt(d+1)),n(p,11,c)}return d<u.length&&n(Dt.ALPHANUMERIC_CHARSET.indexOf(u.charAt(d)),6,c),new Dt(Dt.Mode.ALPHANUMERIC,u.length,c)}static makeSegments(u){return u==""?[]:Dt.isNumeric(u)?[Dt.makeNumeric(u)]:Dt.isAlphanumeric(u)?[Dt.makeAlphanumeric(u)]:[Dt.makeBytes(Dt.toUtf8ByteArray(u))]}static makeEci(u){let c=[];if(u<0)throw new RangeError("ECI assignment value out of range");if(u<128)n(u,8,c);else if(u<16384)n(2,2,c),n(u,14,c);else if(u<1e6)n(6,3,c),n(u,21,c);else throw new RangeError("ECI assignment value out of range");return new Dt(Dt.Mode.ECI,0,c)}static isNumeric(u){return Dt.NUMERIC_REGEX.test(u)}static isAlphanumeric(u){return Dt.ALPHANUMERIC_REGEX.test(u)}getData(){return this.bitData.slice()}static getTotalBits(u,c){let d=0;for(const p of u){const h=p.mode.numCharCountBits(c);if(p.numChars>=1<<h)return 1/0;d+=4+h+p.bitData.length}return d}static toUtf8ByteArray(u){u=encodeURI(u);let c=[];for(let d=0;d<u.length;d++)u.charAt(d)!="%"?c.push(u.charCodeAt(d)):(c.push(parseInt(u.substring(d+1,d+3),16)),d+=2);return c}};s.NUMERIC_REGEX=/^[0-9]*$/,s.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,s.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=s;e.QrSegment=s})(Ji||(Ji={}));(e=>{(t=>{const n=class{constructor(i,s){this.ordinal=i,this.formatBits=s}};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={}))})(Ji||(Ji={}));(e=>{(t=>{const n=class{constructor(i,s){this.modeBits=i,this.numBitsCharCount=s}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={}))})(Ji||(Ji={}));var js=Ji;var L9={L:js.QrCode.Ecc.LOW,M:js.QrCode.Ecc.MEDIUM,Q:js.QrCode.Ecc.QUARTILE,H:js.QrCode.Ecc.HIGH},_1=128,E1="L",I1="#FFFFFF",j1="#000000",R1=!1,k1=1,V9=4,B9=0,G9=.1;function A1(e,t=0){const n=[];return e.forEach(function(r,i){let s=null;r.forEach(function(a,l){if(!a&&s!==null){n.push(`M${s+t} ${i+t}h${l-s}v1H${s+t}z`),s=null;return}if(l===r.length-1){if(!a)return;s===null?n.push(`M${l+t},${i+t} h1v1H${l+t}z`):n.push(`M${s+t},${i+t} h${l+1-s}v1H${s+t}z`);return}a&&s===null&&(s=l)})}),n.join("")}function N1(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,s)=>s<t.x||s>=t.x+t.w?i:!1))}function z9(e,t,n,r){if(r==null)return null;const i=e.length+n*2,s=Math.floor(t*G9),a=i/t,l=(r.width||s)*a,u=(r.height||s)*a,c=r.x==null?e.length/2-l/2:r.x*a,d=r.y==null?e.length/2-u/2:r.y*a,p=r.opacity==null?1:r.opacity;let h=null;if(r.excavate){let g=Math.floor(c),y=Math.floor(d),b=Math.ceil(l+c-g),S=Math.ceil(u+d-y);h={x:g,y,w:b,h:S}}const m=r.crossOrigin;return{x:c,y:d,h:u,w:l,excavation:h,opacity:p,crossOrigin:m}}function Y9(e,t){return t!=null?Math.max(Math.floor(t),0):e?V9:B9}function O1({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:s,size:a,boostLevel:l}){let u=x.useMemo(()=>{const g=(Array.isArray(e)?e:[e]).reduce((y,b)=>(y.push(...js.QrSegment.makeSegments(b)),y),[]);return js.QrCode.encodeSegments(g,L9[t],n,void 0,void 0,l)},[e,t,n,l]);const{cells:c,margin:d,numCells:p,calculatedImageSettings:h}=x.useMemo(()=>{let m=u.getModules();const g=Y9(r,i),y=m.length+g*2,b=z9(m,a,g,s);return{cells:m,margin:g,numCells:y,calculatedImageSettings:b}},[u,a,s,r,i]);return{qrcode:u,margin:d,cells:c,numCells:p,calculatedImageSettings:h}}var H9=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),$9=x.forwardRef(function(t,n){const r=t,{value:i,size:s=_1,level:a=E1,bgColor:l=I1,fgColor:u=j1,includeMargin:c=R1,minVersion:d=k1,boostLevel:p,marginSize:h,imageSettings:m}=r,y=rp(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:b}=y,S=rp(y,["style"]),R=m?.src,w=x.useRef(null),E=x.useRef(null),C=x.useCallback(Y=>{w.current=Y,typeof n=="function"?n(Y):n&&(n.current=Y)},[n]),[k,I]=x.useState(!1),{margin:A,cells:F,numCells:P,calculatedImageSettings:B}=O1({value:i,level:a,minVersion:d,boostLevel:p,includeMargin:c,marginSize:h,imageSettings:m,size:s});x.useEffect(()=>{if(w.current!=null){const Y=w.current,T=Y.getContext("2d");if(!T)return;let U=F;const ie=E.current,oe=B!=null&&ie!==null&&ie.complete&&ie.naturalHeight!==0&&ie.naturalWidth!==0;oe&&B.excavation!=null&&(U=N1(F,B.excavation));const he=window.devicePixelRatio||1;Y.height=Y.width=s*he;const N=s/P*he;T.scale(N,N),T.fillStyle=l,T.fillRect(0,0,P,P),T.fillStyle=u,H9?T.fill(new Path2D(A1(U,A))):F.forEach(function(ne,se){ne.forEach(function(D,ae){D&&T.fillRect(ae+A,se+A,1,1)})}),B&&(T.globalAlpha=B.opacity),oe&&T.drawImage(ie,B.x+A,B.y+A,B.w,B.h)}}),x.useEffect(()=>{I(!1)},[R]);const V=np({height:s,width:s},b);let z=null;return R!=null&&(z=x.createElement("img",{src:R,key:R,style:{display:"none"},onLoad:()=>{I(!0)},ref:E,crossOrigin:B?.crossOrigin})),x.createElement(x.Fragment,null,x.createElement("canvas",np({style:V,height:s,width:s,ref:C,role:"img"},S)),z)});$9.displayName="QRCodeCanvas";var Qi=x.forwardRef(function(t,n){const r=t,{value:i,size:s=_1,level:a=E1,bgColor:l=I1,fgColor:u=j1,includeMargin:c=R1,minVersion:d=k1,boostLevel:p,title:h,marginSize:m,imageSettings:g}=r,y=rp(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:b,cells:S,numCells:R,calculatedImageSettings:w}=O1({value:i,level:a,minVersion:d,boostLevel:p,includeMargin:c,marginSize:m,imageSettings:g,size:s});let E=S,C=null;g!=null&&w!=null&&(w.excavation!=null&&(E=N1(S,w.excavation)),C=x.createElement("image",{href:g.src,height:w.h,width:w.w,x:w.x+b,y:w.y+b,preserveAspectRatio:"none",opacity:w.opacity,crossOrigin:w.crossOrigin}));const k=A1(E,b);return x.createElement("svg",np({height:s,width:s,viewBox:`0 0 ${R} ${R}`,ref:n,role:"img"},y),!!h&&x.createElement("title",null,h),x.createElement("path",{fill:l,d:`M0,0 h${R}v${R}H0z`,shapeRendering:"crispEdges"}),x.createElement("path",{fill:u,d:k,shapeRendering:"crispEdges"}),C)});Qi.displayName="QRCodeSVG";function D1({control:e,name:t,room:n}){const[r,i]=x.useState([]),[s,a]=x.useState(!0);return x.useEffect(()=>{async function l(){try{const u=await fk({room:n,pageSize:1e3});i(u.items),a(!1)}catch(u){console.error("Error fetching locations:",u)}}l()},[n]),s?o.jsx("p",{children:"Loading locations..."}):o.jsxs(H.Group,{className:"mb-3",controlId:"chemical.roomSelect",children:[o.jsx(H.Label,{children:"Select a storage location"}),o.jsx(ar,{name:t,control:e,defaultValue:"",render:({field:{onChange:l,value:u}})=>o.jsx(o.Fragment,{children:o.jsx(Un,{children:r.map(c=>o.jsx(Mt,{xs:4,md:3,className:"mb-3",children:o.jsx(Ze,{onClick:()=>l(c.id.toString()),style:{cursor:"pointer",border:u.toString()===c.id.toString()?"2px solid #007bff":"1px solid #ddd",borderRadius:"8px"},className:"h-100",children:o.jsxs(Ze.Body,{children:[o.jsx(Ze.Title,{children:c.name}),o.jsxs("div",{className:"text-muted small mb-2 d-flex gap-2 justify-content-between",children:[c.code&&o.jsxs("div",{children:["Code: ",c.code]}),c.zone_group&&o.jsxs("div",{children:["Zone group: ",c.zone_group.name]})]}),o.jsxs("div",{style:{textAlign:"center",marginTop:"10px"},children:[o.jsx(Qi,{value:"/l/"+c.id.toString(),size:128})," "]})]})})},c.id))})})})]})}const W9=({show:e,setShow:t,onChemicalCreate:n})=>{const{register:r,control:i,setValue:s,handleSubmit:a,formState:{errors:l,isSubmitting:u}}=gn({defaultValues:{}}),c=async d=>{try{const p=await Ee.post("create/chemical",d);p.data&&n(p.data)}finally{t(!1)}};return o.jsx(xe,{show:e,size:"lg",onHide:()=>t(!1),children:o.jsxs(H,{onSubmit:a(c),children:[o.jsx(xe.Header,{closeButton:!0,children:o.jsx(xe.Title,{children:"Create new chemical"})}),o.jsxs(xe.Body,{children:[o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"CAS Number"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"input",...r("cas_number",{required:"A cas number is required"}),isInvalid:l.cas_number!==void 0}),l.cas_number&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.cas_number.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Name"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"input",...r("name",{required:"A name is required"}),isInvalid:l.name!==void 0}),l.name&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.name.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Description"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsx(H.Control,{as:"textarea",rows:3,...r("description")}),l.description&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.description.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Standard product"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsxs(H.Select,{...r("standard_product",{required:"A standard product is required"}),isInvalid:l.standard_product!==void 0,children:[o.jsx("option",{value:Zd.NON_STANDARD_PRODUCT,children:"Non standard product"}),o.jsx("option",{value:Zd.STANDARD_PRODUCT,children:"Standard product"})]}),l.standard_product&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.standard_product.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx("label",{className:"col-sm-3 col-form-label text-end",children:"Physical state"}),o.jsxs("div",{className:"col-sm-9",children:[o.jsxs(H.Select,{...r("physical_state",{required:"A physical state is required"}),isInvalid:l.physical_state!==void 0,children:[o.jsx("option",{value:ja.SOLID,children:"Solid"}),o.jsx("option",{value:ja.LIQUID,children:"Liquid"}),o.jsx("option",{value:ja.GAS,children:"Gas"}),o.jsx("option",{value:ja.OTHER,children:"Other"})]}),l.physical_state&&o.jsx(H.Control.Feedback,{type:"invalid",children:l.physical_state.message})]})]})]}),o.jsx(xe.Footer,{children:o.jsxs(de,{variant:"primary",disabled:u,onClick:()=>a(c)(),children:[u&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Create new chemical"]})})]})})};function M1({control:e,name:t,setValue:n,errors:r}){const[i,s]=x.useState({}),[a,l]=x.useState(!1),[u,c]=x.useState(null),d=(m,g)=>{try{rk({query:m}).then(b=>{const S=b.items.map(w=>({value:w.id,label:w.name+(w.cas_number?" ("+w.cas_number+")":"")})),R={...i};S.forEach(w=>{R[w.value]=w}),s(R),g(S)})}catch(y){console.error("Error fetching chemicals:",y)}},p=m=>m&&i[m]?i[m]:u||null,h=async m=>{try{const g=await Ee.post("create/chemical",m),y={value:g.data.id,label:g.data.name+(g.data.cas_number?` (${g.data.cas_number})`:"")};s(b=>({...b,[y.value]:y})),c(y),l(!1),n(t,g.data.id)}catch(g){console.error("Error creating chemical:",g)}};return o.jsxs(o.Fragment,{children:[o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Search Existing Chemicals"}),o.jsxs(Un,{children:[o.jsx(ar,{name:t,control:e,render:({field:m})=>o.jsx(Zu,{isSearchable:!0,isClearable:!0,defaultOptions:!0,placeholder:"— Select a chemical, or start typing",loadOptions:d,value:p(m.value),styles:cm,onChange:g=>{c(null),m.onChange(g?.value)}})}),r.chemical&&o.jsx(H.Control.Feedback,{type:"invalid",children:r.chemical.message}),o.jsx("div",{children:o.jsx(de,{variant:"primary",className:"mt-2",onClick:()=>l(!0),children:"Create New Chemical"})})]})]}),o.jsx(W9,{show:a,setShow:l,onChemicalCreate:h})]})}function F1(e){return/\/l\/\d+$/.test(e)}function T1(e){const t=e.match(/\/l\/(\d+)$/);return t?parseInt(t[1],10):null}const P1=[{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 U9({room:e,barcode:t,resetForm:n,location:r,setLocation:i}){const{user:s}=x.useContext($s),{environment:a}=Te.useParams(),[l,u]=x.useState(null);let c=new Date;c.setFullYear(c.getFullYear()+5);const{register:d,control:p,handleSubmit:h,watch:m,setValue:g,formState:{errors:y,isSubmitting:b}}=gn({defaultValues:{expire_date:c.toISOString().split("T")[0],owner:{value:s?.id,label:s?.full_name}}}),S=m("location");x.useEffect(()=>{S&&Va({id:S}).then(E=>{i(E)})},[S]),x.useEffect(()=>{let E="";const C=k=>{if(!(k.target instanceof HTMLInputElement||k.target instanceof HTMLTextAreaElement)&&!(k.key.length>1&&k.key!=="Enter"))if(k.key==="Enter"){if(F1(E)){const I=T1(E);I!==null&&(Va({id:I}).then(A=>{i(A)}),g("location",I))}E.startsWith("reset-scan-location")&&w(),E=""}else E+=k.key};return window.addEventListener("keydown",C),()=>{window.removeEventListener("keydown",C)}},[g]);const R=async E=>{if(E.user=E.owner.value,(await Ly({qrCodeContent:t})).items.length>0){alert("This barcode is already registered to a container");return}const k=await Ee.post("create/chemical/container",E);u(k.data),await Ee.post("create/chemical/container/external-label",{container:k.data.id,qr_code_content:t})},w=()=>{i(null),g("location",0)};return o.jsxs(o.Fragment,{children:[o.jsxs(H,{onSubmit:h(R),children:[!r&&o.jsx(D1,{room:e,control:p,name:"location"}),r&&o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Scanned location"}),o.jsx(Mt,{children:o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("span",{className:"h1",children:r.name}),o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx(Qi,{value:"reset-scan-location",size:100,onClick:()=>w()}),o.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),r&&o.jsxs(o.Fragment,{children:[o.jsx(M1,{control:p,errors:y,setValue:g,...d("chemical",{required:"Chemical is required"})}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Owner"}),o.jsx(_o,{control:p,...d("owner",{required:"Owner is required"}),name:"owner"})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Concentration"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...d("concentration",{required:"An concentration is required"}),isInvalid:y.concentration!==void 0}),y.concentration&&o.jsx(H.Control.Feedback,{type:"invalid",children:y.concentration.message})]})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Amount"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...d("amount",{required:"An amount is required"}),isInvalid:y.amount!==void 0}),o.jsx(ar,{name:"amount_unit",control:p,render:({field:E})=>o.jsxs(fo,{id:"input-group-dropdown-1",title:E.value||"(no unit)",onSelect:C=>E.onChange(C),children:[o.jsx(Ue.Item,{eventKey:"",children:"(no unit)"},0),P1.map(C=>o.jsxs(Ue.Item,{eventKey:C.value,children:[C.label," (",C.value,")"]},C.value))]})}),y.amount&&o.jsx(H.Control.Feedback,{type:"invalid",children:y.amount.message})]})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Expire date"}),o.jsx(H.Control,{type:"date",...d("expire_date",{required:"An expire date is required"}),isInvalid:y.expire_date!==void 0}),y.expire_date&&o.jsx(H.Control.Feedback,{type:"invalid",children:y.expire_date.message})]}),o.jsxs(de,{type:"submit",variant:"primary",disabled:b,children:[b&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),l&&o.jsxs("div",{className:"mt-3",children:[o.jsx(Bt,{variant:"success",children:"Container registered successfully"}),o.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[o.jsx("div",{children:o.jsx("a",{className:"btn btn-primary",href:`${a}/chemical/container/details/${l.id}/general.html`,children:"Go to container"})}),o.jsx(Qi,{value:"reset-form",size:100,className:"float-end",onClick:()=>n()})]})]})]})}function q9({control:e,errors:t}){const[n,r]=x.useState({}),i=(a,l)=>{try{nk({query:a}).then(c=>{const d=c.items.map(h=>({value:h.id,label:h.name})),p={...n};d.forEach(h=>{p[h.value]=h}),r(p),l(d)})}catch(u){console.error("Error fetching types:",u)}},s=a=>n[a]||null;return o.jsx(ar,{name:"container_type",control:e,render:({field:a})=>o.jsx(Zu,{isSearchable:!0,defaultOptions:!0,placeholder:"— Select a container type",loadOptions:i,value:s(a.value),onChange:l=>{a.onChange(l?.value)},styles:cm})})}function X9({room:e,resetForm:t,location:n,setLocation:r}){const{user:i}=x.useContext($s),{environment:s}=Te.useParams(),[a,l]=x.useState(null);let u=new Date;u.setFullYear(u.getFullYear()+5);const{register:c,control:d,handleSubmit:p,watch:h,setValue:m,formState:{errors:g,isSubmitting:y}}=gn({defaultValues:{expire_date:u.toISOString().split("T")[0],owner:{value:i?.id,label:i?.full_name}}}),b=h("location");x.useEffect(()=>{b&&Va({id:b}).then(w=>{r(w)})},[b]),x.useEffect(()=>{let w="";const E=C=>{if(!(C.target instanceof HTMLInputElement||C.target instanceof HTMLTextAreaElement)&&!(C.key.length>1&&C.key!=="Enter"))if(C.key==="Enter"){if(F1(w)){const k=T1(w);k!==null&&(Va({id:k}).then(I=>{r(I)}),m("location",k))}w.startsWith("reset-scan-location")&&R(),w=""}else w+=C.key};return window.addEventListener("keydown",E),()=>{window.removeEventListener("keydown",E)}},[m]);const S=async w=>{w.user=w.owner.value;const E=await Ee.post("create/chemical/container",w);l(E.data)},R=()=>{r(null),m("location",0)};return o.jsxs(o.Fragment,{children:[o.jsxs(H,{onSubmit:p(S),children:[!n&&o.jsx(D1,{room:e,control:d,name:"location"}),n&&o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Scanned location"}),o.jsx(Mt,{children:o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx("span",{className:"h1",children:n.name}),o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx(Qi,{value:"reset-scan-location",size:100,onClick:()=>R()}),o.jsx("span",{className:"text-muted",children:"Reset location"})]})]})})]}),n&&o.jsxs(o.Fragment,{children:[o.jsx(M1,{control:d,errors:g,setValue:m,...c("chemical",{required:"Chemical is required"})}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Owner"}),o.jsx(_o,{control:d,...c("owner",{required:"Owner is required"}),name:"owner"})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Concentration"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...c("concentration",{required:"An concentration is required"}),isInvalid:g.concentration!==void 0}),g.concentration&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.concentration.message})]})]}),o.jsxs(H.Group,{className:"mb-3",children:[o.jsx(H.Label,{children:"Amount"}),o.jsxs(un,{className:"mb-3 w-25",hasValidation:!0,children:[o.jsx(H.Control,{as:"input",...c("amount",{required:"An amount is required"}),isInvalid:g.amount!==void 0}),o.jsx(ar,{name:"amount_unit",control:d,render:({field:w})=>o.jsxs(fo,{id:"input-group-dropdown-1",title:w.value||"(no unit)",onSelect:E=>w.onChange(E),children:[o.jsx(Ue.Item,{eventKey:"",children:"(no unit)"},0),P1.map(E=>o.jsxs(Ue.Item,{eventKey:E.value,children:[E.label," (",E.value,")"]},E.value))]})}),g.amount&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.amount.message})]})]}),o.jsxs(un,{hasValidation:!0,className:"mb-3 row",children:[o.jsx(H.Label,{children:"Container type"}),o.jsx(q9,{control:d,...c("container_type",{required:"Container type is required"}),errors:g}),g.container_type&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.container_type.message})]}),o.jsxs(H.Group,{className:"mb-3 w-50 w-25-sm",children:[o.jsx(H.Label,{children:"Expire date"}),o.jsx(H.Control,{type:"date",...c("expire_date",{required:"An expire date is required"}),isInvalid:g.expire_date!==void 0}),g.expire_date&&o.jsx(H.Control.Feedback,{type:"invalid",children:g.expire_date.message})]}),o.jsxs(de,{type:"submit",variant:"primary",disabled:y,children:[y&&o.jsx("span",{className:"spinner-border spinner-border-sm me-1"}),"Register container"]})]})]}),a&&o.jsxs("div",{className:"mt-3",children:[o.jsx(Bt,{variant:"success",children:"Container registered successfully"}),o.jsxs("div",{className:"d-flex justify-content-between align-items-center gap-2",children:[o.jsx("div",{children:o.jsx("a",{className:"btn btn-primary",href:`${s}/chemical/container/render/single-${a.id}.pdf`,children:"Print label"})}),o.jsx("div",{children:o.jsx("a",{className:"btn btn-primary",href:`${s}/chemical/container/details/${a.id}/general.html`,children:"Go to container"})}),o.jsx(Qi,{value:"reset-form",size:100,className:"float-end",onClick:()=>t()})]})]})]})}function Z9(){const{environment:e}=Te.useParams(),[t,n]=x.useState(null),[r,i]=x.useState([]),[s,a]=x.useState(null),[l,u]=x.useState(!1),[c,d]=x.useState(!1),[p,h]=x.useState(null),[m,g]=x.useState(null),{control:y,watch:b,reset:S,setValue:R}=gn({defaultValues:{room:p,barcode:""}}),w=b("room");x.useEffect(()=>{w&&(h(w),d(w.building.site.has_external_chemical_labelling))},[w]),x.useEffect(()=>{const I=new URLSearchParams(window.location.search).get("room");I&&dk({id:parseInt(I)}).then(A=>{h(A),d(A.building.site.has_external_chemical_labelling),R("room",A)})},[R]),x.useEffect(()=>{const I=new URLSearchParams(window.location.search).get("location");I&&Va({id:parseInt(I)}).then(A=>{g(A),h(A.zone_group.room),d(A.zone_group.room.building.site.has_external_chemical_labelling),R("room",A.zone_group.room)})},[R]);const E=b("barcode");x.useEffect(()=>{const I=setTimeout(()=>{if(!E?.includes("/l/")){if(E?.includes("/cc/")){n(E);const A=E.split("/cc/")[1];tk({id:parseInt(A)}).then(F=>{a(F)})}E&&(n(E),k({barcode:E}))}},1e3);return()=>{clearTimeout(I)}},[E,S]),x.useEffect(()=>{let I="";const A=F=>{F.target instanceof HTMLInputElement||F.target instanceof HTMLTextAreaElement||F.key.length>1&&F.key!=="Enter"||(F.key==="Enter"?(I==="reset-form"&&C(),I=""):I+=F.key)};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[S]);const C=()=>{S({room:p,barcode:""}),n(null),g(null)};async function k({barcode:I}){try{const A=await Ly({qrCodeContent:I});A&&Array.isArray(A.items)&&A.items.length>0?(i(A.items),u(!1)):(u(!0),i([]))}catch(A){console.error("Error fetching chemical container external labels",A),i([]),u(!1)}}return o.jsxs("div",{children:[o.jsxs("div",{className:"d-flex justify-content-between",children:[o.jsx(F9,{control:y,name:"room"}),o.jsxs("div",{className:"d-flex flex-column",children:[o.jsx(Qi,{value:"reset-form",size:100,className:"float-end",onClick:()=>C()}),o.jsx("span",{className:"text-muted",children:"Reset form"})]})]}),p&&c&&o.jsxs(Bt,{children:["Lab ",p.name," has external labels, each chemical material should have a material from the internal supplier/warehouse"]}),p&&!c&&o.jsxs(Bt,{children:["Lab ",p.name," has no external labels, labels can be printed via the intake form"]}),p!==null&&!t&&c&&o.jsx(T9,{control:y}),t&&s&&o.jsxs(Bt,{variant:"info d-flex flex-column gap-3",children:["This is already an own chemical material, this is ",s.chemical.name," and should be stored on"," ",s.location.name," in ",s.location.zone_group.room.name,o.jsx("a",{className:"alert-link",href:`${e}/chemical/container/details/${s.id}/general.html`,children:"Go to container"})]}),!s&&t&&o.jsx(o.Fragment,{children:r.length===0?o.jsx(Bt,{variant:"info d-flex flex-column gap-3",children:o.jsxs("div",{children:["No chemical container external labels found with label ",o.jsx("strong",{children:t})]})}):o.jsxs(Kt,{children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"ID"}),o.jsx("th",{children:"Label"}),o.jsx("th",{children:"Container"}),o.jsx("th",{children:"Location"})]})}),o.jsx("tbody",{children:r.map(I=>o.jsxs("tr",{children:[o.jsx("td",{children:I.id}),o.jsx("td",{children:I.label}),o.jsx("td",{children:o.jsx("a",{href:`/${e}/chemical/container/details/${I.container.id}/general.html`,children:I.container.chemical.name})}),o.jsx("td",{children:o.jsx("a",{href:`/${e}/location/details/${I.container.location.id}/general.html`,children:I.container.location.name})})]},I.id))})]})}),!s&&l&&p&&t&&o.jsx(U9,{room:p,barcode:t,location:m,setLocation:g,resetForm:C}),!s&&p&&!c&&o.jsx(X9,{room:p,location:m,setLocation:g,resetForm:C})]})}function J9({badge_uuid:e}){return o.jsxs("span",{className:"rounded p-2 bg-success",children:["Card read: ",e]})}function Q9({user_id:e}){const[t,n]=x.useState("");return x.useEffect(()=>{const r="https://"+Qm+`/api/onelab/view/user/${e}`;(async()=>{try{const s=await fetch(r);if(!s.ok)throw new Error(`Response status: ${s.status} with body: ${await s.text()}`);const a=await s.json();n(a.full_name)}catch(s){console.log(s)}})()},[]),o.jsxs("span",{className:"rounded p-2 bg-success",children:["Clients has detected user: ",t||"loading..."]})}function K9(){return o.jsx("div",{})}const ip=["all","equipment","not_set"],Qm=document.getElementById("root")?.dataset.goldsteinEndpoint??"",e5="mock-token",t5=10,n5=15;async function r5(e){const t="https://"+Qm+"/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(":"),s=Number(i);if(!r||isNaN(s)||s===0){alert("Please follow the correct format: $item:$id");return}if(!ip.slice(1).includes(r)){alert("Please select a valid $item: (equipment, not_set)");return}const a=await fetch(t,{method:"PATCH",body:JSON.stringify({previous_association:e,new_association:n}),headers:{"Content-type":"application/json; charset=UTF-8"}});if(!a.ok)throw new Error(`Response status: ${a.status} with body: ${await a.text()}`);const l=await a.text();alert(l)}function i5(){const e=x.useRef(null),[t,n]=x.useState(new Map);async function r(c){const d=_S(c.notifications_list,new Date,t5,n5);n(d)}function i(){const d=`
46
46
  SELECT * FROM notifications
47
47
  ${l==="all"?"":`WHERE association_item = "${l}"`}
48
48
  `.trim(),p={listening_association:`${l}:*`,sql_statement:d};let h={package_type:Vi.UPDATE_LISTENING_DATA,payload:JSON.stringify(p)};Bi(e.current,h),h={package_type:Vi.GET_DATA,payload:""},Bi(e.current,h)}const s=()=>{setTimeout(()=>{(e.current===null||e.current.readyState===WebSocket.CLOSED||e.current.readyState===WebSocket.CLOSING)&&a()},1e3)},a=()=>{CS("wss://"+Qm+"/ws",e5).then(c=>{e.current!==null&&e.current.close(),c.onmessage=p=>{SS(p,r)},c.onclose=()=>{console.log("WebSocket closed"),s()},c.onerror=p=>{console.error("WebSocket error",p),s()},e.current=c,console.log("WebSocket connected"),i();const d={package_type:Vi.GET_DATA,payload:""};Bi(c,d)}).catch(c=>{console.error("WebSocket connection failed",c),s()})};x.useEffect(()=>(a(),()=>{e.current&&(e.current.close(),console.log("Web socket disconnected"))}),[]);const[l,u]=x.useState(ip[0]);return x.useEffect(()=>{i()},[l]),o.jsxs("div",{children:[o.jsx("h1",{children:"Goldstein Clients"}),o.jsxs("div",{children:[o.jsx("label",{htmlFor:"typeFilter",children:"Filter by type:"}),o.jsx("select",{className:"form-control",id:"typeFilter",value:l,onChange:c=>u(c.target.value),children:ip.map(c=>o.jsx("option",{value:c,children:c},c))})]}),o.jsxs(Kt,{size:"sm",striped:!0,bordered:!0,hover:!0,children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Client"}),o.jsx("th",{children:"Status"}),o.jsx("th",{children:"Actions"})]})}),o.jsx("tbody",{children:Array.from(t.entries()).map(([c,d])=>o.jsxs("tr",{children:[o.jsx("td",{children:c}),o.jsxs("td",{children:[d.status===Gi.CLIENT_CONNECTED&&o.jsx(K9,{}),d.status===Gi.CARD_READED&&o.jsx(J9,{badge_uuid:d.message.badgeUUID}),d.status===Gi.USER_AUTHENTICATED&&o.jsx(Q9,{user_id:d.message.userID})]}),o.jsx("td",{children:o.jsx("button",{className:"btn btn-primary",onClick:()=>r5(c),children:"Edit association"})})]},c))})]})]})}function s5({result:e,value:t,onChange:n,error:r,onSubmit:i,saving:s}){const a=e.criterion_version,l=a.criterion.background_color&&a.criterion.has_background_color?{backgroundColor:a.criterion.background_color}:void 0;return o.jsxs("div",{className:`form-group mb-3 p-3 rounded ${a.highlighted?"border border-warning":""}`,style:l,children:[o.jsxs("label",{htmlFor:`result-${e.id}`,className:"form-label",children:[a.criterion.criterion,a.required&&o.jsx("span",{className:"text-danger",children:"*"})]}),(()=>{const u={id:`result-${e.id}`,value:t??"",onChange:c=>n(e,c.target.value)};switch(a.criterion.input_type){case"integer":case"float":return o.jsx("input",{...u,type:"number",step:a.criterion.input_type==="float"?"0.01":"1",className:`form-control ${r?"is-invalid":""}`});case"date":return o.jsx("input",{...u,type:"date",className:`form-control ${r?"is-invalid":""}`});case"text":return o.jsx("textarea",{...u,className:`form-control ${r?"is-invalid":""}`,rows:3});case"string":return o.jsx("input",{...u,type:"text",className:`form-control ${r?"is-invalid":""}`});case"select":return o.jsxs("select",{...u,className:`form-select ${r?"is-invalid":""}`,children:[o.jsx("option",{value:"",children:"-- select --"}),Object.entries(a.criterion.values).map(([c,d])=>o.jsx("option",{value:c,children:d},c))]});case"radio":{const{id:c,value:d,onChange:p}=u,h=String(d??"");return o.jsx("div",{className:`form-check ${r?"is-invalid":""}`,children:Object.entries(a.criterion.values).map(([m,g])=>o.jsxs("div",{className:"form-check",children:[o.jsx("input",{type:"radio",id:`${c}_${m}`,name:c,value:m,checked:h===m,onChange:p,className:"form-check-input"}),o.jsx("label",{htmlFor:`${c}_${m}`,className:"form-check-label",children:g})]},m))})}case"checkbox":{const{id:c,value:d}=u,p=Array.isArray(d)?d:[],h=(m,g)=>{const y=g?[...p,m]:p.filter(b=>b!==m);n(e,y)};return o.jsx("div",{className:`form-check ${r?"is-invalid":""}`,children:Object.entries(a.criterion.values).map(([m,g])=>o.jsxs("div",{className:"form-check",children:[o.jsx("input",{type:"checkbox",id:`${c}_${m}`,name:c,value:m,checked:p.includes(m),onChange:y=>h(m,y.target.checked),className:"form-check-input"}),o.jsx("label",{htmlFor:`${c}_${m}`,className:"form-check-label",children:g})]},m))})}case"bool":return o.jsx("div",{className:`form-check form-switch ${r?"is-invalid":""}`,children:o.jsx("input",{type:"checkbox",...u,checked:!!t,onChange:c=>n(e,c.target.checked),className:"form-check-input"})});case"action":return o.jsxs("div",{className:`d-flex align-items-center ${r?"is-invalid":""}`,children:[o.jsx("label",{className:"me-2",children:"Done "}),o.jsxs("div",{role:"group","aria-label":`${e.id}-action`,className:"btn-group btn-group-sm",children:[o.jsx("button",{type:"button",className:`btn ${t?"btn-primary":"btn-outline-secondary"}`,onClick:()=>n(e,!0),"aria-pressed":t,children:"Yes"}),o.jsx("button",{type:"button",className:`btn ${t?"btn-outline-secondary":"btn-primary"}`,onClick:()=>n(e,!1),"aria-pressed":!t,children:"No"})]})]});default:return null}})(),a.criterion.help_block&&o.jsx("small",{className:"form-text text-muted",children:a.criterion.help_block}),r&&o.jsx("div",{className:"invalid-feedback",children:r}),o.jsx("div",{className:"mt-2",children:o.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:()=>i(e),disabled:!!s,children:s?"Saving…":"Save"})})]})}function a5({categoryId:e,label:t,results:n}){const[r,i]=x.useState({}),[s,a]=x.useState({}),[l,u]=x.useState({}),[c,d]=x.useState({});x.useEffect(()=>{const m=String(e);if(r[m])a(r[m].values),u(r[m].errors);else{const g={};n.forEach(b=>{const S=b.criterion_version;if(S.criterion.input_type==="checkbox"){const R=b.value||S.default_value||"";g[b.id]=R?R.toString().split(", "):[]}else if(S.criterion.input_type==="bool"||S.criterion.input_type==="action"){const R=b.value??S.default_value??"false";g[b.id]=R==="true"}else g[b.id]=b.value??S.default_value??""});const y={...r,[m]:{values:g,errors:{}}};i(y),a(g),u({})}},[e]),x.useEffect(()=>{const m=String(e);r[m]&&i(g=>({...g,[m]:{values:s,errors:l}}))},[s,l,e]);const p=async m=>{const g=m.id,y=s[g],b=m.criterion_version,S=y==null||y===""||Array.isArray(y)&&y.length===0;if(b.required&&S){u(w=>({...w,[g]:"This field is required."}));return}u(w=>{const{[g]:E,...C}=w;return C}),d(w=>({...w,[g]:!0}));let R=y;Array.isArray(y)?R=y.join(", "):typeof y=="boolean"&&(R=y?"true":"false");try{await Ee.patch(`/update/service/event/report/result/${g}`,{value:R})}catch(w){console.error("Failed to save:",w)}finally{d(w=>({...w,[g]:!1}))}},h=x.useCallback((m,g)=>{a(y=>({...y,[m.id]:g}))},[]);return o.jsxs("div",{children:[o.jsx("legend",{children:t}),n.map(m=>o.jsx(s5,{result:m,value:s[m.id],onChange:h,error:l[m.id],onSubmit:p,saving:c[m.id]},m.id))]})}function o5(){const{id:e}=Te.useParams(),t=Te.useLocation(),n=Te.useNavigate(),[r,i]=x.useState(),[s,a]=x.useState({}),[l,u]=x.useState({}),[c,d]=x.useState(0),[p,h]=x.useState(null);x.useEffect(()=>{e&&(Ck({id:Number(e)}).then(k=>{const I=k.reduce((P,B)=>{const V=B.criterion_version.type.category,z=String(V.id);return P[z]||(P[z]=[]),P[z].push(B),P},{}),A={},F={};k.forEach(P=>{const B=P.criterion_version.type.category,V=String(B.id);A[V]=B.category,F[V]=typeof B.sequence=="number"?B.sequence:Number.MAX_SAFE_INTEGER}),i(I),a(A),u(F)}),_k({id:Number(e)}).then(k=>h(k)).catch(()=>h(null)))},[e]);const m=x.useMemo(()=>r?Object.keys(r).sort((k,I)=>{const A=l[k]??Number.MAX_SAFE_INTEGER,F=l[I]??Number.MAX_SAFE_INTEGER;return A!==F?A-F:Number(k)-Number(I)}):[],[r,l]),g=m.length;if(x.useEffect(()=>{if(!g)return;const I=new URLSearchParams(t.search).get("category");if(I){const A=m.indexOf(I);if(A!==-1){d(A);return}}d(0)},[g,t.search,m]),x.useEffect(()=>{if(!g)return;const k=m[c],I=new URLSearchParams(t.search);k&&I.get("category")!==k&&(I.set("category",k),n({pathname:t.pathname,search:I.toString()},{replace:!1}))},[c,g,m,t.pathname,t.search,n]),!r)return o.jsx("div",{children:"Loading…"});if(g===0)return o.jsx("div",{children:"No categories found"});const y=()=>{d(k=>Math.max(k-1,0))},b=()=>{d(k=>Math.min(k+1,g-1))},S=p?.event,R=S?.service?.name,w=S?.place?.name,E=S?.date_planned?new Date(S.date_planned).toLocaleString():void 0,C=S?.date_executed?new Date(S.date_executed).toLocaleString():void 0;return o.jsxs("div",{className:"container mt-4",children:[S&&o.jsx("div",{className:"card mb-3",children:o.jsxs("div",{className:"card-body",children:[o.jsx("div",{className:"d-flex justify-content-between align-items-start",children:o.jsxs("div",{children:[o.jsx("h2",{className:"h4 mb-1",children:R||"Service"}),o.jsxs("div",{className:"text-muted small",children:["Report #",e," • Event #",S.id,S.guid?` • ${S.guid}`:""]})]})}),o.jsxs("div",{className:"row mt-2",children:[w&&o.jsxs("div",{className:"col-md-4",children:[o.jsx("div",{className:"fw-semibold",children:"Place"}),o.jsx("div",{children:w})]}),E&&o.jsxs("div",{className:"col-md-4",children:[o.jsx("div",{className:"fw-semibold",children:"Planned"}),o.jsx("div",{children:E})]}),C&&o.jsxs("div",{className:"col-md-4",children:[o.jsx("div",{className:"fw-semibold",children:"Executed"}),o.jsx("div",{children:C})]})]})]})}),o.jsx(a5,{categoryId:m[c],label:s[m[c]],results:r[m[c]]}),o.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-3",children:[o.jsx("button",{className:"btn btn-outline-primary",onClick:y,disabled:c===0,children:"Previous"}),o.jsxs("div",{className:"text-center",children:["Category ",c+1," of ",g]}),o.jsx("button",{className:"btn btn-outline-primary",onClick:b,disabled:c===g-1,children:"Next"})]})]})}exports.AuthContext=$s;exports.AuthProvider=kk;exports.ChemicalHeaderElement=M9;exports.ChemicalIntakeElement=Z9;exports.DateFormat=Zi;exports.EmphasizedParametersContext=pc;exports.EmphasizedParametersProvider=D9;exports.EquipmentContext=fc;exports.EquipmentDashboard=pU;exports.EquipmentHeaderElement=gU;exports.EquipmentProvider=u1;exports.GoldsteinClientsDashboard=i5;exports.GoldsteinEquipmentDashboard=DV;exports.InputModal=w1;exports.MonitorCard=Um;exports.MonitorContext=f1;exports.MonitorHeaderElement=$U;exports.MonitorPage=HU;exports.MonitorProvider=UU;exports.PaginationLinks=Oo;exports.ReportResults=o5;exports.RunContext=as;exports.RunHeaderElement=QU;exports.RunInformationElement=c9;exports.RunProvider=p1;exports.RunStepContext=vn;exports.RunStepExecuteElement=O9;exports.RunStepHeaderElement=f9;exports.RunStepProvider=y1;exports.RunStepsElement=u9;exports.SetupUpdateEquipment=uV;exports.StatusMailComponent=oU;exports.StatusMailContext=Xu;exports.StatusMailProvider=vU;exports.initSolodbComponents=Rk;exports.useAuth=qy;