import{aD as P,u as h,bL as T,r as d,aL as k,br as A,a3 as o,j as t,L as b,m as I,B as K,aG as D,q as O,s as y,c as N,ba as x,ar as Y,bE as H,c3 as L,aS as J,bA as w,eO as B}from"./index-dP1W1_bd.js";import{ah as E,a4 as F,W as G}from"./Project-CsYwwOpN.js";import{B as q}from"./ButtonWithRole-CF64B_Or.js";import{u as S}from"./useJupyterSettings-NqiqVDlq.js";import{K as M}from"./KubernetesProjectEdit-CcUpiV79.js";import"./alertManagerConfig.selectors-B_R5cvew.js";import"./__-BIxbRvwe.js";import"./useDownload-C3yCvYJa.js";import"./useProject-CXVt1xnE.js";import"./length-BzpOfCdE.js";import"./complement-D_Q2yZKt.js";import"./index-MHdXqM53.js";import"./FileUploaderButton-frSujVRY.js";import"./uniq-98MdbBvs.js";import"./uniqBy-6mvKp2Ip.js";import"./dumbPluralize-CcxDsNiu.js";import"./CardActionButton-BtCnEqTK.js";import"./utils-UGwNsahk.js";import"./useKeyPress-OcDHupLZ.js";import"./zipObj-DEkcXp9d.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-mJT60wVA.js";import"./git-C8OLuEaG.js";import"./NoData-DLZ_8GEo.js";import"./useCopyToClipboard-DTBM3H3Z.js";import"./Anchor-B_lGyhCa.js";const he=()=>{const r=P(),{id:c}=h(),u=T(),[n,p]=d.useState(!1),{data:e,isLoading:j}=S(+c),{data:g,isLoading:l}=k(E),{data:m,isLoading:f}=A();d.useEffect(()=>(r.jupyter.fetchRunningServer({projectId:+c}),()=>{r.jupyter.clear()}),[r.jupyter,c]);const a=async i=>{p(!0);const C=i.type===o.PYTHON,v={...e,rayConfig:{...e.rayConfig,...i[o.RAY],schedulingConfig:i[o.RAY].schedulingConfig},dockerConfig:{...e.dockerConfig,schedulingConfig:i[o.PYTHON].schedulingConfig,resourceConfig:{...e.dockerConfig.resourceConfig,...i[o.PYTHON].resourceConfig}},jobConfig:L(["experimentType"],{...e.jobConfig,...i[o.SPARK],schedulingConfig:i[o.SPARK].schedulingConfig}),pythonKernel:C};await r.jupyter.update({projectId:+c,settings:v}),u(y.jupyter.overview),p(!1)},{initialData:s,selectedConfig:R}=d.useMemo(()=>e?{initialData:[e.jobConfig,{...e.dockerConfig,type:o.PYTHON},{...e.rayConfig,type:o.RAY}],selectedConfig:e.pythonKernel&&m?o.PYTHON:o.SPARK}:{initialData:[]},[m,e]);return!e||l||f?t.jsx(b,{}):t.jsx(F,{isDisabled:!!g,initialData:s,submitHandler:a,canSave:!g,onlyAdvancedConfig:!0,selectedConfig:R,isSubmiting:n,checkedAdvancedConfig:!0,noPythonFiles:!0,isJupyter:!0,children:({advanceConfig:i,type:C})=>t.jsxs(t.Fragment,{children:[j&&t.jsx(b,{}),t.jsx(I,{width:"100%",title:"Jupyter server configuration",actions:!g&&t.jsxs(K,{gap:"8px",children:[t.jsx(W,{}),t.jsx(Q,{})]}),children:i}),t.jsx(M,{prefix:[C],init:!1},C)]})},JSON.stringify(s))},W=()=>{const{id:r}=h();return t.jsx(D,{intent:"secondary",href:O(y.project.settings.computeConfiguration,y.project.value,{id:r}),children:"Go to default configuration"})},Q=()=>{const r=P(),{id:c}=h(),{data:u}=S(+c),{data:n}=G(),[p,e]=N(),[j,g]=d.useState(!1),l=d.useMemo(()=>{const f=n==null?void 0:n.find(s=>s.type===o.SPARK),a=n==null?void 0:n.find(s=>s.type===o.PYTHON);return(!f||x(u.jobConfig,f))&&(!a||x(u.dockerConfig.resourceConfig,a.resourceConfig))},[n,u.jobConfig,u.dockerConfig]),m=async()=>{g(!0);const f=J((a,s)=>s.type===o.SPARK?w("jobConfig",s,a):s.type===o.PYTHON?B(["dockerConfig","resourceConfig"],s.resourceConfig,a):a,u,n??[]);await r.jupyter.update({projectId:+c,settings:f}),g(!1),e()};return t.jsxs(t.Fragment,{children:[t.jsx(Y,{disabled:!l,mainText:"It's already set to default config",children:t.jsx(q,{onClick:e,disabled:l,children:"Reset to default configuration"})}),t.jsx(H,{title:"Reset to default config",secondaryText:"Are you sure that you want to reset to default config?",isOpen:p,onClose:e,mainButtonProps:{children:"Reset config",onClick:m,isLoading:j},secondaryButtonProps:{children:"Cancel",onClick:e}})]})};export{he as default};
