import{_ as e,u as t,s as a,o as s,c as n,a as i,t as r,b as l,d as m,w as o,D as d,r as p,e as c,F as u,q as x,g as v,v as h,H as f,f as g,I as b,A as _,h as y,m as I,p as w,J as $,K as S,L as E,M as k}from"./index-5CctA6VU.js";import{_ as L,a as j,D as R}from"./SLStatusLabel-CpoGmtz3.js";import{u as F}from"./experiment-BWsAMZL-.js";import"./SLLoading-CnnPDveI.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=b(),$=t(),S=F(),E=a(S.experiment),k=()=>{y.delete(`/experiment/${S.id}`).then(({data:e})=>{$.deleteExperiment(e.experiment_id),w.replace("/").then(()=>{I.success(_("common.delete.success"))})}).catch(({data:e})=>{I.error(e.message)})},J=async(e,t)=>{const a=S.id,{data:s}=await y.patch(`/experiment/${a}`,e);s.name=s.name.trim(),S.setExperimentPartial(s),$.setExperimentInfo(a,e),t()},K=g(()=>[{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=j,g=h,b=f("RouterLink");return s(),n("div",C,[i("div",D,[i("div",M,[i("div",N,[i("h1",T,[i("span",q,r(l(S).name),1)]),m(L,{type:"experiment",onModify:J,disabled:l(S).isRunning},null,8,["disabled"]),m(a,{name:E.value.name,status:E.value.status},{default:o(()=>[d(r(e.$t("experiment.status."+E.value.status)),1)]),_:1},8,["name","status"]),l(S).isRunning?p(e.$slots,"stop-button",{key:0},void 0,!0):c("",!0)]),i("div",A,[m(R,{type:"experiment",onConfirm:k})])]),l(S).description?(s(),n("p",B,r(l(S).description),1)):c("",!0),i("nav",H,[(s(!0),n(u,null,x(l(K),e=>(s(),v(b,{class:"nav-item","active-class":"nav-active","data-text":e.label,key:e.to,to:e.to},{default:o(()=>[m(g,{icon:e.icon,class:"w-5 h-5"},null,8,["icon"]),d(" "+r(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(),i=a.id,r=a.status,l=g(()=>0===r),m=()=>{$(_("experiment.index.header.stop.modal.title"),_("experiment.index.header.stop.modal.text")).then(o)},o=async()=>{const{data:e}=await y.get(`/experiment/${i}/stop`);e&&(a.setStatus(e.status),a.setFinishTime(e.finish_time),t().setExperimentStatus(i,-1,e.finish_time),I.success("State changed"))};return(e,t)=>(s(),n("button",{class:w(["underline text-dimmest ml-2",l.value?"":"cursor-not-allowed"]),onClick:m}," is over? ",2))}},P={__name:"ExperimentView",setup(e){const i=k(),r=F(),d=t(),p=g(()=>void 0!==r.id),x=a(0),h=async(e=i.params.experimentId)=>{r.experiment=void 0,r.charts=void 0,y.get(`/experiment/${e}`).then(({data:e})=>{r.experiment=e,d.setExperimentStatus(e.id,e.status,e.finish_time),r.isRunning&&_()}).catch(e=>{var t;x.value=(null==(t=e.data)?void 0:t.code)||3e3})};h(),S((e,t)=>{e.params.experimentId!==t.params.experimentId&&(h(e.params.experimentId),clearInterval(b))});let b=null;const _=()=>{b=setInterval(()=>{y.get(`/experiment/${r.id}/status`).then(({data:e})=>{Number(r.id)===Number(i.params.experimentId)?(r.setStatus(e.status),r.setFinishTime(e.finish_time),d.setExperimentStatus(r.id,e.status,e.finish_time),r.charts=e.charts,r.isRunning||clearInterval(b)):clearInterval(b)}).catch(e=>{clearInterval(b)})},1e3)};return(e,t)=>{const a=f("router-view");return s(),n(u,null,[p.value?(s(),v(J,{key:l(r).id},{"stop-button":o(()=>[m(K)]),default:o(()=>[m(a)]),_:1})):c("",!0),!p.value&&x.value?(s(),v(E,{key:1,code:x.value},null,8,["code"])):c("",!0)],64)}}};export{P as default};
