import{bI as x,u as h,bJ as I,r as d,bK as K,jL as T,bj as A,a0 as s,j as t,L as b,y as k,B as D,b4 as N,q as O,s as m,w as Y,aU as P,at as H,bs as w,bA as J,c8 as L,gD as B,bv as F,gz as E}from"./index-C1DmWO_C.js";import{K as G,y as q}from"./Project-CpwJZ-CK.js";import{u as S}from"./useJupyterSettings-DB2CmnMH.js";import{K as M}from"./KubernetesProjectEdit-O522bxXP.js";import"./alertManagerConfig.selectors-B9ELaxCY.js";import"./index-Dub34MAX.js";import"./FileUploaderButton-BtxUzlTS.js";import"./zipObj-D8EtfWld.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-B3GPGppJ.js";import"./git-C8OLuEaG.js";import"./NoData-Y_e6mfNf.js";import"./useCopyToClipboard-v9FBn9Nz.js";import"./Anchor-DFXOcnPw.js";const ae=()=>{const r=x(),{id:c}=h(),u=I(),[o,l]=d.useState(!1),{data:e,isLoading:y}=S(+c),{data:g,isLoading:p}=K(T),{data:C,isLoading:f}=A();d.useEffect(()=>(r.jupyter.fetchRunningServer({projectId:+c}),()=>{r.jupyter.clear()}),[r.jupyter,c]);const a=async i=>{l(!0);const j=i.type===s.PYTHON,v={...e,rayConfig:{...e.rayConfig,...i[s.RAY],schedulingConfig:i[s.RAY].schedulingConfig},dockerConfig:{...e.dockerConfig,schedulingConfig:i[s.PYTHON].schedulingConfig,resourceConfig:{...e.dockerConfig.resourceConfig,...i[s.PYTHON].resourceConfig}},jobConfig:L(["experimentType"],{...e.jobConfig,...i[s.SPARK],schedulingConfig:i[s.SPARK].schedulingConfig}),pythonKernel:j};await r.jupyter.update({projectId:+c,settings:v}),u(m.jupyter.overview),l(!1)},{initialData:n,selectedConfig:R}=d.useMemo(()=>e?{initialData:[e.jobConfig,{...e.dockerConfig,type:s.PYTHON},{...e.rayConfig,type:s.RAY}],selectedConfig:e.pythonKernel&&C?s.PYTHON:s.SPARK}:{initialData:[]},[C,e]);return!e||p||f?t.jsx(b,{}):t.jsx(G,{isDisabled:!!g,initialData:n,submitHandler:a,canSave:!g,onlyAdvancedConfig:!0,selectedConfig:R,isSubmiting:o,checkedAdvancedConfig:!0,noPythonFiles:!0,isJupyter:!0,children:({advanceConfig:i,type:j})=>t.jsxs(t.Fragment,{children:[y&&t.jsx(b,{}),t.jsx(k,{width:"100%",title:"Jupyter server configuration",actions:!g&&t.jsxs(D,{gap:"8px",children:[t.jsx(z,{}),t.jsx(Q,{})]}),children:i}),t.jsx(M,{prefix:[j],init:!1},j)]})},JSON.stringify(n))},z=()=>{const{id:r}=h();return t.jsx(N,{intent:"secondary",href:O(m.project.settings.computeConfiguration,m.project.value,{id:r}),children:"Go to default configuration"})},Q=()=>{const r=x(),{id:c}=h(),{data:u}=S(+c),{data:o}=q(),[l,e]=Y(),[y,g]=d.useState(!1),p=d.useMemo(()=>{const f=o==null?void 0:o.find(n=>n.type===s.SPARK),a=o==null?void 0:o.find(n=>n.type===s.PYTHON);return(!f||P(u.jobConfig,f))&&(!a||P(u.dockerConfig.resourceConfig,a.resourceConfig))},[o,u.jobConfig,u.dockerConfig]),C=async()=>{g(!0);const f=B((a,n)=>n.type===s.SPARK?F("jobConfig",n,a):n.type===s.PYTHON?E(["dockerConfig","resourceConfig"],n.resourceConfig,a):a,u,o??[]);await r.jupyter.update({projectId:+c,settings:f}),g(!1),e()};return t.jsxs(t.Fragment,{children:[t.jsx(H,{disabled:!p,mainText:"It's already set to default config",children:t.jsx(w,{onClick:e,disabled:p,children:"Reset to default configuration"})}),t.jsx(J,{title:"Reset to default config",secondaryText:"Are you sure that you want to reset to default config?",isOpen:l,onClose:e,mainButtonProps:{children:"Reset config",onClick:C,isLoading:y},secondaryButtonProps:{children:"Cancel",onClick:e}})]})};export{ae as default};
