import{fL as u,hA as b,hB as y,H as x,hC as M,I as P,hD as E,hE as S,hF as C,hG as f,hH as N,hI as A,u as k,X as p,r as I,fI as j,j as g,aI as w,gR as Y}from"./index-CK33qGU_.js";import{c as G,d as L}from"./index-Cwe0XbXT.js";import{F as O}from"./FileContent-BRNHLExA.js";import{d as H}from"./useDownload-hrjXceJg.js";function U(s,e){const t=u(s),n=u(e);return t.getFullYear()-n.getFullYear()}function R(s,e){const t=u(s),n=u(e),r=v(t,n),o=Math.abs(b(t,n));t.setDate(t.getDate()-r*o);const c=+(v(t,n)===-r),a=r*(o-c);return a===0?0:a}function v(s,e){const t=s.getFullYear()-e.getFullYear()||s.getMonth()-e.getMonth()||s.getDate()-e.getDate()||s.getHours()-e.getHours()||s.getMinutes()-e.getMinutes()||s.getSeconds()-e.getSeconds()||s.getMilliseconds()-e.getMilliseconds();return t<0?-1:t>0?1:t}function z(s,e,t){const n=y(s,e)/x;return M(t==null?void 0:t.roundingMethod)(n)}function B(s,e,t){const n=y(s,e)/P;return M(t==null?void 0:t.roundingMethod)(n)}function _(s,e){const t=u(s),n=u(e),r=E(t,n),o=Math.abs(U(t,n));t.setFullYear(1584),n.setFullYear(1584);const c=E(t,n)===-r,a=r*(o-+c);return a===0?0:a}const T=["years","months","weeks","days","hours","minutes","seconds"];function $(s,e){const t=C(),n=(e==null?void 0:e.locale)??t.locale??S,r=(e==null?void 0:e.format)??T,o=(e==null?void 0:e.zero)??!1,c=(e==null?void 0:e.delimiter)??" ";return n.formatDistance?r.reduce((i,l)=>{const h=`x${l.replace(/(^.)/,m=>m.toUpperCase())}`,d=s[l];return d!==void 0&&(o||s[l])?i.concat(n.formatDistance(h,d)):i},[]).join(c):""}function J(s){const e=u(s.start),t=u(s.end),n={},r=_(t,e);r&&(n.years=r);const o=f(e,{years:n.years}),c=N(t,o);c&&(n.months=c);const a=f(o,{months:n.months}),i=R(t,a);i&&(n.days=i);const l=f(a,{days:n.days}),h=z(t,l);h&&(n.hours=h);const d=f(l,{hours:n.hours}),m=B(t,d);m&&(n.minutes=m);const F=f(d,{minutes:n.minutes}),D=A(t,F);return D&&(n.seconds=D),n}const W=s=>$(J({start:0,end:s}),{format:["years","months","days","hours","minutes","seconds"],locale:{formatDistance:(e,t)=>K[e].replace("{{count}}",t)}}),K={xSeconds:"{{count}}s",xMinutes:"{{count}}m",xHours:"{{count}}h",xDays:"{{count}}d",xMonths:"{{count}}m",xYears:"{{count}}y"},Z=({projectId:s,jobName:e,exectution:t})=>{const{id:n}=k(),o={pId:s??n,name:e,execId:(t==null?void 0:t.id)??0},{currentData:c}=G.getJobExecution.useQueryState(o),a=p(t??{},c??{}),i=(a==null?void 0:a.finalStatus)==="UNDEFINED"||(a==null?void 0:a.state)==="AGGREGATING_LOGS";return L(o,{skip:!i,pollingInterval:5e3}),I.useMemo(()=>({execution:a,isStillExecuting:i}),[a,i])},tt=(s,e=[])=>{const t=e.filter(n=>n.state==="RUNNING").length;if(t)return{width:"fit-content",value:`${t} ${t>1?"executions":"execution"} in progress`,variant:"light",loading:!0};switch(s){case"SUCCEEDED":return{width:"fit-content",value:"Success",variant:"success"};case"FAILED":return{width:"fit-content",value:"Fail",variant:"fail"};case"IN_PROGRESS":return{width:"fit-content",value:"In progress",variant:"light",loading:!0};case"KILLED":return{width:"fit-content",value:"Killed",variant:"label"};case"UNDEFINED":return{width:"fit-content",value:"-",variant:"label",loading:!0};default:return{width:"fit-content",value:s?j(s).replaceAll("_"," "):"-",variant:"label"}}},et=({execution:s,isOpenPopup:e,handleTogglePopup:t})=>{const[n,r]=I.useState("stdoutPath"),o=s[n]??"",c=I.useMemo(()=>[{title:"stdout",isActive:n==="stdoutPath",onClick:()=>r("stdoutPath")},{title:"stderr",isActive:n==="stderrPath",onClick:()=>r("stderrPath")},...s.notebookOutPath?[{title:"notebook out",isActive:n==="notebookOutPath",onClick:()=>r("notebookOutPath")}]:[]],[n,s.notebookOutPath]);return g.jsx(w,{size:"7xl",isOpen:e,onClose:t,hasCloseButton:!0,title:g.jsx(Y,{title:"Logs",tabs:c,width:"90%"}),bodyProps:{pt:0,mt:"10px"},children:g.jsx(O,{file:{attributes:{path:o,name:H(o)}}},n)})};export{et as E,tt as g,W as m,Z as u};
