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