import{bI as x,u as b,b9 as A,r as p,bJ as K,kC as Y,bh as k,a2 as t,j as s,D as R,W as v,a as D,c8 as O,t as P,aJ as H,s as N,y as E,a$ as m,ao as J,bs as w,bA as L,gE as F,bu as S,gB as _}from"./index-_eM6l4Nf.js";import{P as B,z as G}from"./Project-BTH4PZdL.js";import{u as T}from"./useJupyterSettings-CqEZAE50.js";import{K as U}from"./KubernetesProjectEdit-CZi-T2Qi.js";import"./alertManagerConfig.selectors-B-zYrdGC.js";import"./complement-CE-nEpWn.js";import"./index-B-5JhFyZ.js";import"./form-CMT9TYED.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-BIbwssIf.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-BUvZjse8.js";import"./Anchor-JEsUSbQH.js";const W=["python","ray"],ae=()=>{const c=x(),{id:u}=b(),i=A(),[n,y]=p.useState(!1),{data:e,isLoading:h}=T(+u),{data:g,isLoading:C}=K(Y),{data:j,isLoading:d}=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,I={...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:O(["experimentType"],{...e.jobConfig,...a[t.SPARK],schedulingConfig:a[t.SPARK].schedulingConfig}),pythonKernel:l};await c.jupyter.update({projectId:+u,settings:I}),i(P.project.jupyter.overview),y(!1)},{initialData:o,selectedConfig:f}=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||d?s.jsx(R,{}):s.jsx(B,{isDisabled:!!g,initialData:o,submitHandler:r,canSave:!g,onlyAdvancedConfig:!0,selectedConfig:f,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:!g&&s.jsxs(D,{gap:"8px",children:[s.jsx(M,{}),s.jsx($,{})]}),children:a}),s.jsx(U,{prefix:[l],init:!1,isDisabled:!!g,enabledKueue:W.includes(l)},l)]})},JSON.stringify(o))},M=()=>{const{id:c}=b();return s.jsx(H,{intent:"secondary",href:N(P.project.settings.computeConfiguration,P.project.value,{id:c}),children:"Go to default configuration"})},$=()=>{const c=x(),{id:u}=b(),{data:i}=T(+u),{data:n}=G(),[y,e]=E(),[h,g]=p.useState(!1),C=p.useMemo(()=>{const d=n==null?void 0:n.find(f=>f.type===t.SPARK),r=n==null?void 0:n.find(f=>f.type===t.PYTHON),o=n==null?void 0:n.find(f=>f.type===t.RAY);return(!d||m(i.jobConfig,d))&&(!r||m(i.dockerConfig.resourceConfig,r.resourceConfig))&&(!o||m(i.rayConfig,o))},[n,i.jobConfig,i.dockerConfig,i.rayConfig]),j=async()=>{g(!0);const d=F((r,o)=>o.type===t.SPARK?S("jobConfig",o,r):o.type===t.PYTHON?_(["dockerConfig","resourceConfig"],o.resourceConfig,r):o.type===t.RAY?S("rayConfig",o,r):r,i,n??[]);await c.jupyter.update({projectId:+u,settings:d}),g(!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{ae as default};
