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