import{bW as S,u as b,ba as K,r as p,bX as Y,ll as I,bq as k,a3 as t,j as s,L as R,f as v,q as D,cl as N,x as P,aJ as O,t as H,w as E,b0 as m,an as J,bB as w,bJ as L,hA as B,bD as x,aE as F}from"./index-DHiyXWqE.js";import{M as q,B as M}from"./Project-DwrxbZJj.js";import{u as T}from"./useJupyterSettings-CX_6_2FA.js";import{K as U}from"./KubernetesProjectEdit-Dg3mVF7r.js";import"./alertManagerConfig.selectors-0se_RTtj.js";import"./defineProperty-C28_3XcK.js";import"./HumanizedCronExpression-FxwdMNJF.js";import"./index-5hEKE-oe.js";import"./form-CrZPXKpD.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-BqIFhGVd.js";import"./index-C52WzLFZ.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-D6oq-fy9.js";const _=["python","ray"],ce=()=>{const c=S(),{id:u}=b(),i=K(),[n,y]=p.useState(!1),{data:e,isLoading:h}=T(+u),{data:f,isLoading:C}=Y(I),{data:j,isLoading:g}=k();p.useEffect(()=>(c.jupyter.fetchRunningServer({projectId:+u}),()=>{c.jupyter.clear()}),[c.jupyter,u]);const r=async a=>{y(!0);const l=a.type===t.PYTHON,A={...e,rayConfig:{...e.rayConfig,...a[t.RAY],schedulingConfig:a[t.RAY].schedulingConfig},dockerConfig:{...e.dockerConfig,schedulingConfig:a[t.PYTHON].schedulingConfig,resourceConfig:{...e.dockerConfig.resourceConfig,...a[t.PYTHON].resourceConfig}},jobConfig:N(["experimentType"],{...e.jobConfig,...a[t.SPARK],schedulingConfig:a[t.SPARK].schedulingConfig}),pythonKernel:l};await c.jupyter.update({projectId:+u,settings:A}),i(P.project.jupyter.overview),y(!1)},{initialData:o,selectedConfig:d}=p.useMemo(()=>e?{initialData:[e.jobConfig,{...e.dockerConfig,type:t.PYTHON},{...e.rayConfig,type:t.RAY}],selectedConfig:e.pythonKernel&&j?t.PYTHON:t.SPARK}:{initialData:[]},[j,e]);return!e||C||g?s.jsx(R,{}):s.jsx(q,{isDisabled:!!f,initialData:o,submitHandler:r,canSave:!f,onlyAdvancedConfig:!0,selectedConfig:d,isSubmiting:n,noPythonFiles:!0,isJupyter:!0,children:({advanceConfig:a,type:l})=>s.jsxs(s.Fragment,{children:[h&&s.jsx(R,{}),s.jsx(v,{width:"100%",title:"Jupyter server configuration",actions:!f&&s.jsxs(D,{gap:"8px",children:[s.jsx(G,{}),s.jsx(W,{})]}),children:a}),s.jsx(U,{prefix:[l],init:!1,isDisabled:!!f,enabledKueue:_.includes(l)},l)]})},JSON.stringify(o))},G=()=>{const{id:c}=b();return s.jsx(O,{intent:"secondary",href:H(P.project.settings.computeConfiguration,P.project.value,{id:c}),children:"Go to default configuration"})},W=()=>{const c=S(),{id:u}=b(),{data:i}=T(+u),{data:n}=M(),[y,e]=E(),[h,f]=p.useState(!1),C=p.useMemo(()=>{const g=n==null?void 0:n.find(d=>d.type===t.SPARK),r=n==null?void 0:n.find(d=>d.type===t.PYTHON),o=n==null?void 0:n.find(d=>d.type===t.RAY);return(!g||m(i.jobConfig,g))&&(!r||m(i.dockerConfig.resourceConfig,r.resourceConfig))&&(!o||m(i.rayConfig,o))},[n,i.jobConfig,i.dockerConfig,i.rayConfig]),j=async()=>{f(!0);const g=B((r,o)=>o.type===t.SPARK?x("jobConfig",o,r):o.type===t.PYTHON?F(["dockerConfig","resourceConfig"],o.resourceConfig,r):o.type===t.RAY?x("rayConfig",o,r):r,i,n??[]);await c.jupyter.update({projectId:+u,settings:g}),f(!1),e()};return s.jsxs(s.Fragment,{children:[s.jsx(J,{disabled:!C,mainText:"It's already set to default config",children:s.jsx(w,{onClick:e,disabled:C,children:"Reset to default configuration"})}),s.jsx(L,{title:"Reset to default config",secondaryText:"Are you sure that you want to reset to default config?",isOpen:y,onClose:e,mainButtonProps:{children:"Reset config",onClick:j,isLoading:h},secondaryButtonProps:{children:"Cancel",onClick:e}})]})};export{ce as default};
