import{gx as i,jq as x,jr as M,K as b,js as E,M as S,jt as v,ju as F,jv as P,jw as f,jx as C,jy as N,u as w,$ as k,r as D,j as h,aZ as A,hV as Y,aY as p,aX as L,gw as O}from"./index-C1DmWO_C.js";import{c as G,d as U}from"./index-GabIfpNZ.js";function H(s,e){const t=i(s),n=i(e);return t.getFullYear()-n.getFullYear()}function _(s,e){const t=i(s),n=i(e),r=y(t,n),o=Math.abs(x(t,n));t.setDate(t.getDate()-r*o);const c=+(y(t,n)===-r),a=r*(o-c);return a===0?0:a}function y(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=M(s,e)/b;return E(t==null?void 0:t.roundingMethod)(n)}function R(s,e,t){const n=M(s,e)/S;return E(t==null?void 0:t.roundingMethod)(n)}function $(s,e){const t=i(s),n=i(e),r=v(t,n),o=Math.abs(H(t,n));t.setFullYear(1584),n.setFullYear(1584);const c=v(t,n)===-r,a=r*(o-+c);return a===0?0:a}const K=["years","months","weeks","days","hours","minutes","seconds"];function T(s,e){const t=P(),n=(e==null?void 0:e.locale)??t.locale??F,r=(e==null?void 0:e.format)??K,o=(e==null?void 0:e.zero)??!1,c=(e==null?void 0:e.delimiter)??" ";return n.formatDistance?r.reduce((u,l)=>{const g=`x${l.replace(/(^.)/,m=>m.toUpperCase())}`,d=s[l];return d!==void 0&&(o||s[l])?u.concat(n.formatDistance(g,d)):u},[]).join(c):""}function q(s){const e=i(s.start),t=i(s.end),n={},r=$(t,e);r&&(n.years=r);const o=f(e,{years:n.years}),c=C(t,o);c&&(n.months=c);const a=f(o,{months:n.months}),u=_(t,a);u&&(n.days=u);const l=f(a,{days:n.days}),g=z(t,l);g&&(n.hours=g);const d=f(l,{hours:n.hours}),m=R(t,d);m&&(n.minutes=m);const j=f(d,{minutes:n.minutes}),I=N(t,j);return I&&(n.seconds=I),n}const V=s=>T(q({start:0,end:s}),{format:["years","months","days","hours","minutes","seconds"],locale:{formatDistance:(e,t)=>B[e].replace("{{count}}",t)}}),B={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}=w(),o={pId:s??n,name:e,execId:(t==null?void 0:t.id)??0},{currentData:c}=G.getJobExecution.useQueryState(o),a=k(t??{},c??{}),u=(a==null?void 0:a.finalStatus)==="UNDEFINED"||(a==null?void 0:a.state)==="AGGREGATING_LOGS";return U(o,{skip:!u,pollingInterval:5e3}),D.useMemo(()=>({execution:a,isStillExecuting:u}),[a,u])},Z=({execution:s,isOpenPopup:e,handleTogglePopup:t})=>{const[n,r]=D.useState("stdoutPath"),o=s[n]??"",c=D.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 h.jsx(A,{size:"7xl",isOpen:e,onClose:t,hasCloseButton:!0,title:h.jsx(Y,{title:"Logs",tabs:c,width:"90%"}),bodyProps:{pt:0,mt:"10px"},children:h.jsx(p,{file:{attributes:{path:o,name:L(o)}},errorContent:{title:"Logs not found",message:""}},n)})},W=(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{Z as E,W as g,V as m,X as u};
