import{_ as e,u as t,i as a,c as s,o as n,a as i,b as r,t as l,d as m,e as o,w as d,D as c,r as p,f as u,F as x,s as v,g as h,H as f,h as g,m as b,y as _,A as y,I,q as w,J as $,K as S,L as E,M as k}from"./index-mtICtCH6.js";import{_ as L,D as j,a as R}from"./SLStatusLabel-DUMYVfZs.js";import{u as F}from"./experiment-C9fiIMV8.js";import"./SLLoading-Ba4myrl9.js";const C={class:"w-full h-full py-5"},D={class:"px-6 border-b"},M={class:"experiment-title transition-marging duration-300"},N={class:"flex items-center gap-3"},T={class:"text-2xl items-center gap-1 truncate max-w-sm sm:max-w-lg 2xl:max-w-5xl"},q={class:"font-semibold"},A={class:"flex justify-end grow transition-padding duration-300 ml-1"},B={key:0,class:"experiment-description"},H={class:"experiment-navs"},J=e({__name:"ExperimentLayout",setup(e){const w=f(),$=t(),S=F(),E=a(S.experiment),k=()=>{g.delete(`/experiment/${S.id}`).then((({data:e})=>{$.deleteExperiment(e.experiment_id),w.replace("/").then((()=>{b.success(_("common.delete.success"))}))})).catch((({data:e})=>{b.error(e.message)}))},J=async(e,t)=>{const a=S.id,{data:s}=await g.patch(`/experiment/${a}`,e);s.name=s.name.trim(),S.setExperimentPartial(s),$.setExperimentInfo(a,e),t()},K=s((()=>[{label:_("experiment.navs.index"),to:`/experiment/${S.id}/index`,icon:"experiment"},{label:_("experiment.navs.chart"),to:`/experiment/${S.id}/chart`,icon:"chart"},{label:_("experiment.navs.log"),to:`/experiment/${S.id}/log`,icon:"logs"},{label:_("experiment.navs.env"),to:`/experiment/${S.id}/env`,icon:"info"}]));return(e,t)=>{const a=R,s=y,f=I("RouterLink");return n(),i("div",C,[r("div",D,[r("div",M,[r("div",N,[r("h1",T,[r("span",q,l(m(S).name),1)]),o(L,{type:"experiment",onModify:J,disabled:m(S).isRunning},null,8,["disabled"]),o(a,{name:E.value.name,status:E.value.status},{default:d((()=>[c(l(e.$t("experiment.status."+E.value.status)),1)])),_:1},8,["name","status"]),m(S).isRunning?p(e.$slots,"stop-button",{key:0},void 0,!0):u("",!0)]),r("div",A,[o(j,{type:"experiment",onConfirm:k})])]),m(S).description?(n(),i("p",B,l(m(S).description),1)):u("",!0),r("nav",H,[(n(!0),i(x,null,v(m(K),(e=>(n(),h(f,{class:"nav-item","active-class":"nav-active","data-text":e.label,key:e.to,to:e.to},{default:d((()=>[o(s,{icon:e.icon,class:"w-5 h-5"},null,8,["icon"]),c(" "+l(e.label),1)])),_:2},1032,["data-text","to"])))),128))])]),p(e.$slots,"default",{},void 0,!0)])}}},[["__scopeId","data-v-941ebc81"]]),K={__name:"StopButton",setup(e){const a=F(),r=a.id,l=a.status,m=s((()=>0===l)),o=()=>{$(_("experiment.index.header.stop.modal.title"),_("experiment.index.header.stop.modal.text")).then(d)},d=async()=>{const{data:e}=await g.get(`/experiment/${r}/stop`);e&&(a.setStatus(e.status),a.setFinishTime(e.finish_time),t().setExperimentStatus(r,-1,e.finish_time),b.success("State changed"))};return(e,t)=>(n(),i("button",{class:w(["underline text-dimmest ml-2",m.value?"":"cursor-not-allowed"]),onClick:o}," is over? ",2))}},P={__name:"ExperimentView",setup(e){const r=k(),l=F(),c=t(),p=s((()=>void 0!==l.id)),v=a(0),f=async(e=r.params.experimentId)=>{l.experiment=void 0,l.charts=void 0,g.get(`/experiment/${e}`).then((({data:e})=>{l.experiment=e,c.setExperimentStatus(e.id,e.status,e.finish_time),l.isRunning&&_()})).catch((e=>{var t;v.value=(null==(t=e.data)?void 0:t.code)||3e3}))};f(),S(((e,t)=>{e.params.experimentId!==t.params.experimentId&&(f(e.params.experimentId),clearInterval(b))}));let b=null;const _=()=>{b=setInterval((()=>{g.get(`/experiment/${l.id}/status`).then((({data:e})=>{Number(l.id)===Number(r.params.experimentId)?(l.setStatus(e.status),l.setFinishTime(e.finish_time),c.setExperimentStatus(l.id,e.status,e.finish_time),l.charts=e.charts,l.isRunning||clearInterval(b)):clearInterval(b)})).catch((e=>{clearInterval(b)}))}),1e3)};return(e,t)=>{const a=I("router-view");return n(),i(x,null,[p.value?(n(),h(J,{key:m(l).id},{"stop-button":d((()=>[o(K)])),default:d((()=>[o(a)])),_:1})):u("",!0),!p.value&&v.value?(n(),h(E,{key:1,code:v.value},null,8,["code"])):u("",!0)],64)}}};export{P as default};
