import{bz as M,az as f,q as L,r as F,F as W,aK as K,a_ as _,dg as X,dh as $,di as Y,bG as Z,c7 as G,cf as ee,c8 as te,dj as ie,dk as se,dl as D,cg as le,dm as re,dn as ne,dp as oe,aM as E,o as p,bs as o,bC as ae,z as a,bD as y,ce as ue,b_ as q,y as V,bE as w,cc as N,c4 as ce,dq as de,ah as fe,p as P,dr as me}from"./index-p5QwxXYb.js";import{g as pe}from"./graphql-1_B3k2Rp.js";import{V as he}from"./ViewToolbar-OKhjCBXz.js";import{V as ge}from"./VAlert-euxRuCvE.js";const be={name:"LogComponent",props:{placeholder:{type:String,required:!1},timestamps:{type:Boolean,required:!1,default:!0},logs:{type:Array,required:!0}},data(){return{match:""}},computed:{computedLogs(){return this.logs.length>0?this.timestamps?this.logs:this.updateLogs():this.placeholder?[this.placeholder]:[]}},methods:{updateLogs(){return this.logs.map(e=>this.stripTimestamp(e))},stripTimestamp(e){const t=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-][\d:]+)?\s(.*\s*)/;return this.match=e.match(t),this.match?this.match[1]:e}}};function ye(e,t,s,u,i,c){return f(),L("div",null,[F("pre",null,[(f(!0),L(W,null,K(c.computedLogs,(d,r)=>(f(),L("span",{key:r},_(d),1))),128))])])}const ke=M(be,[["render",ye]]);var we=X,Le=function(){return we.Date.now()},_e=Le,ve=/\s/;function Te(e){for(var t=e.length;t--&&ve.test(e.charAt(t)););return t}var Ie=Te,Ve=Ie,xe=/^\s+/;function Fe(e){return e&&e.slice(0,Ve(e)+1).replace(xe,"")}var Oe=Fe,Ce=Oe,A=$,Se=Y,B=0/0,je=/^[-+]0x[0-9a-f]+$/i,De=/^0b[01]+$/i,Ee=/^0o[0-7]+$/i,qe=parseInt;function Ne(e){if(typeof e=="number")return e;if(Se(e))return B;if(A(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=A(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=Ce(e);var s=De.test(e);return s||Ee.test(e)?qe(e.slice(2),s?2:8):je.test(e)?B:+e}var Pe=Ne,Ae=$,x=_e,R=Pe,Be="Expected a function",Re=Math.max,Ue=Math.min;function Me(e,t,s){var u,i,c,d,r,n,h=0,O=!1,g=!1,v=!0;if(typeof e!="function")throw new TypeError(Be);t=R(t)||0,Ae(s)&&(O=!!s.leading,g="maxWait"in s,c=g?Re(R(s.maxWait)||0,t):c,v="trailing"in s?!!s.trailing:v);function T(l){var m=u,b=i;return u=i=void 0,h=l,d=e.apply(b,m),d}function Q(l){return h=l,r=setTimeout(k,t),O?T(l):d}function z(l){var m=l-n,b=l-h,j=t-m;return g?Ue(j,c-b):j}function C(l){var m=l-n,b=l-h;return n===void 0||m>=t||m<0||g&&b>=c}function k(){var l=x();if(C(l))return S(l);r=setTimeout(k,z(l))}function S(l){return r=void 0,v&&u?T(l):(u=i=void 0,d)}function H(){r!==void 0&&clearTimeout(r),h=0,u=n=i=r=void 0}function J(){return r===void 0?d:S(x())}function I(){var l=x(),m=C(l);if(u=arguments,i=this,n=l,m){if(r===void 0)return Q(n);if(g)return clearTimeout(r),r=setTimeout(k,t),T(n)}return r===void 0&&(r=setTimeout(k,t)),d}return I.cancel=H,I.flush=J,I}var We=Me;const $e=Z(We),Ge=G`
subscription LogData ($id: ID!, $file: String!) {
  logs (id: $id, file: $file) {
    lines
    connected
    path
    error
  }
}
`,Qe=G`
query LogFiles($id: ID!) {
  logFiles(id: $id) {
    files
  }
}
`,ze=[/job\.out/,/job/,/scheduler\/*/];class U{constructor(){this.lines=[],this.path=null,this.connected=null,this.error=null}}class He{constructor(t){this.results=t}onAdded(t,s,u){t.lines&&this.results.lines.push(...t.lines),t.connected!==null&&(this.results.connected=t.connected),t.error!==null&&(this.results.error=t.error),t.path!==null&&(this.results.path=t.path)}tearDown(t,s){}commit(t,s){}}const Je={name:"Log",mixins:[pe,ee],components:{LogComponent:ke,ViewToolbar:he},head(){return{title:te("App.workflow",{name:this.workflowName})}},props:{initialOptions:{type:Object,required:!1,default:()=>{}}},data(){return{query:null,logFiles:[],results:new U,relativeID:null,file:null,fileLabel:"Select File",fileDisabled:!1,jobLog:0,timestamps:!0,controlGroups:[{title:"Log",controls:[{title:"Timestamps",icon:ie,action:"toggle",value:!0,key:"timestamps"},{title:"Refresh File List",icon:se,action:"callback",callback:()=>{this.updateLogFileList(!1)}}]}]}},created(){var e,t,s;(t=(e=this.initialOptions)==null?void 0:e.tokens)!=null&&t.task&&(this.relativeID=this.initialOptions.tokens.relative_id,this.jobLog=1),(s=this.initialOptions)!=null&&s.file&&(this.file=this.initialOptions.file)},async mounted(){await this.updateLogFileList()},computed:{workflowTokens(){return new D(this.workflowId)},id(){if(this.jobLog)try{const e=new D(this.relativeID,!0);return!e||!e.task?null:this.workflowTokens.clone({cycle:e.cycle,task:e.task,job:e.job}).id}catch{return null}return this.workflowId}},methods:{setOption(e,t){this[e]=t},reset(){this.results=new U},updateQuery(){if(this.reset(),!this.file||!this.id){this.query=null;return}this.query=new le(Ge,{id:this.id,file:this.file},`log-query-${this._uid}`,[new He(this.results)],!1,!1)},async updateLogFileList(e=!0){this.fileLabel="Updating available files...",this.fileDisabled=!0;let t;try{t=await this.$workflowService.apolloClient.query({query:Qe,variables:{id:this.id}})}catch{this.fileLabel=`No log files for ${this.id}`,this.fileDisabled=!0;return}let s;if(t.data.logFiles?s=t.data.logFiles.files:s=[],e&&(this.file&&!(this.file in s)&&(this.file=null),!this.file&&s))for(const u of ze){for(const i of s)if(u.exec(i)){this.file=i;break}if(this.file)break}s.length?(this.fileLabel="Select File",this.fileDisabled=!1,this.logFiles=s):(this.fileLabel=`No log files for ${this.id}`,this.fileDisabled=!0,this.logFiles=[])}},watch:{id:$e(async function(){await this.updateLogFileList(),this.updateQuery()},500),jobLog(){this.file=null},file(){this.updateQuery()}},icons:{mdiFileAlertOutline:re,mdiPowerPlug:ne,mdiPowerPlugOff:oe}},Ke={"data-cy":"log-path",style:{"padding-left":"0.5em",color:"rgb(150,150,150)"}},Xe={class:"text-pre-wrap text-break"};function Ye(e,t,s,u,i,c){const d=E("ViewToolbar"),r=E("log-component");return f(),p(ae,{class:"c-log py-1",fluid:""},{default:o(()=>[a(w,{dense:""},{default:o(()=>[a(y,null,{default:o(()=>[a(ue,{modelValue:i.jobLog,"onUpdate:modelValue":t[0]||(t[0]=n=>i.jobLog=n),divided:"",mandatory:"",variant:"outlined",color:"primary"},{default:o(()=>[a(q,{"data-cy":"workflow-toggle"},{default:o(()=>[V("Workflow")]),_:1}),a(q,{"data-cy":"job-toggle"},{default:o(()=>[V("Job")]),_:1})]),_:1},8,["modelValue"]),a(d,{groups:i.controlGroups,onSetOption:c.setOption},null,8,["groups","onSetOption"])]),_:1})]),_:1}),a(w,{dense:""},{default:o(()=>[a(y,{cols:"8"},{default:o(()=>[i.jobLog?(f(),p(N,{key:0,"data-cy":"job-id-input",class:"flex-grow-1 flex-column",modelValue:i.relativeID,"onUpdate:modelValue":t[1]||(t[1]=n=>i.relativeID=n),placeholder:"cycle/task/job",clearable:""},null,8,["modelValue"])):(f(),p(N,{key:1,"data-cy":"workflow-id-input",modelValue:e.workflowId,"onUpdate:modelValue":t[2]||(t[2]=n=>e.workflowId=n),disabled:""},null,8,["modelValue"]))]),_:1}),a(y,{cols:"4"},{default:o(()=>[a(ce,{"data-cy":"file-input",label:i.fileLabel,disabled:i.fileDisabled,items:i.logFiles,modelValue:i.file,"onUpdate:modelValue":t[3]||(t[3]=n=>i.file=n),clearable:"","menu-props":{"data-cy":"file-input-menu"}},null,8,["label","disabled","items","modelValue"])]),_:1})]),_:1}),a(w,{dense:""},{default:o(()=>[i.results.path?(f(),p(y,{key:0,class:"d-flex align-center overflow-x-auto text-pre"},{default:o(()=>[a(de,fe({"data-cy":"connected-icon",variant:"outlined",class:"flex-shrink-0"},i.results.connected?{color:"success",prependIcon:e.$options.icons.mdiPowerPlug}:{color:"error",prependIcon:e.$options.icons.mdiPowerPlugOff,onClick:c.updateQuery}),{default:o(()=>[V(_(i.results.connected?"Connected":"Reconnect"),1)]),_:1},16),F("span",Ke,_(i.results.path),1)]),_:1})):P("",!0)]),_:1}),a(w,null,{default:o(()=>[a(y,null,{default:o(()=>[c.id&&i.file&&i.results.connected==null?(f(),p(me,{key:0,indeterminate:""})):(f(),L(W,{key:1},[i.results.error?(f(),p(ge,{key:0,type:"error",variant:"tonal",density:"comfortable",class:"mb-4",icon:e.$options.icons.mdiFileAlertOutline},{default:o(()=>[F("span",Xe,_(i.results.error),1)]),_:1},8,["icon"])):P("",!0),a(r,{"data-cy":"log-viewer",logs:i.results.lines,timestamps:i.timestamps},null,8,["logs","timestamps"])],64))]),_:1})]),_:1})]),_:1})}const st=M(Je,[["render",Ye]]);export{st as default};
