import{gh as u,i0 as x,i1 as y,M as F,i2 as E,O as P,i3 as M,i4 as S,i5 as C,i6 as f,i7 as N,i8 as A,u as k,a2 as p,r as D,j as h,b2 as j,hi as w,gg as O}from"./index-dP1W1_bd.js";import{c as Y,d as L}from"./index-DqSuv-hx.js";import{F as G}from"./Project-CsYwwOpN.js";import{d as U}from"./useDownload-C3yCvYJa.js";function H(s,e){const t=u(s),n=u(e);return t.getFullYear()-n.getFullYear()}function z(s,e){const t=u(s),n=u(e),a=v(t,n),o=Math.abs(x(t,n));t.setDate(t.getDate()-a*o);const c=+(v(t,n)===-a),r=a*(o-c);return r===0?0:r}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 R(s,e,t){const n=y(s,e)/F;return E(t==null?void 0:t.roundingMethod)(n)}function _(s,e,t){const n=y(s,e)/P;return E(t==null?void 0:t.roundingMethod)(n)}function T(s,e){const t=u(s),n=u(e),a=M(t,n),o=Math.abs(H(t,n));t.setFullYear(1584),n.setFullYear(1584);const c=M(t,n)===-a,r=a*(o-+c);return r===0?0:r}const $=["years","months","weeks","days","hours","minutes","seconds"];function B(s,e){const t=C(),n=(e==null?void 0:e.locale)??t.locale??S,a=(e==null?void 0:e.format)??$,o=(e==null?void 0:e.zero)??!1,c=(e==null?void 0:e.delimiter)??" ";return n.formatDistance?a.reduce((i,l)=>{const m=`x${l.replace(/(^.)/,g=>g.toUpperCase())}`,d=s[l];return d!==void 0&&(o||s[l])?i.concat(n.formatDistance(m,d)):i},[]).join(c):""}function J(s){const e=u(s.start),t=u(s.end),n={},a=T(t,e);a&&(n.years=a);const o=f(e,{years:n.years}),c=N(t,o);c&&(n.months=c);const r=f(o,{months:n.months}),i=z(t,r);i&&(n.days=i);const l=f(r,{days:n.days}),m=R(t,l);m&&(n.hours=m);const d=f(l,{hours:n.hours}),g=_(t,d);g&&(n.minutes=g);const b=f(d,{minutes:n.minutes}),I=A(t,b);return I&&(n.seconds=I),n}const W=s=>B(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"},X=({projectId:s,jobName:e,execution:t})=>{const{id:n}=k(),o={pId:s??n,name:e,execId:(t==null?void 0:t.id)??0},{currentData:c}=Y.getJobExecution.useQueryState(o),r=p(t??{},c??{}),i=(r==null?void 0:r.finalStatus)==="UNDEFINED"||(r==null?void 0:r.state)==="AGGREGATING_LOGS";return L(o,{skip:!i,pollingInterval:5e3}),D.useMemo(()=>({execution:r,isStillExecuting:i}),[r,i])},tt=({execution:s,isOpenPopup:e,handleTogglePopup:t})=>{const[n,a]=D.useState("stdoutPath"),o=s[n]??"",c=D.useMemo(()=>[{title:"stdout",isActive:n==="stdoutPath",onClick:()=>a("stdoutPath")},{title:"stderr",isActive:n==="stderrPath",onClick:()=>a("stderrPath")},...s.notebookOutPath?[{title:"notebook out",isActive:n==="notebookOutPath",onClick:()=>a("notebookOutPath")}]:[]],[n,s.notebookOutPath]);return h.jsx(j,{size:"7xl",isOpen:e,onClose:t,hasCloseButton:!0,title:h.jsx(w,{title:"Logs",tabs:c,width:"90%"}),bodyProps:{pt:0,mt:"10px"},children:h.jsx(G,{file:{attributes:{path:o,name:U(o)}},errorContent:{title:"Logs not found",message:""}},n)})},et=(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?O(s).replaceAll("_"," "):"-",variant:"label"}}};export{tt as E,et as g,W as m,X as u};
