import{bI as x,u as P,b9 as A,r as p,bJ as K,k7 as Y,bh as k,a2 as t,j as s,D as R,b as v,$ as D,c8 as O,q as b,b1 as H,o as N,y as E,aQ as m,ao as J,bs as w,bA as L,gz as _,bu as S,gw as F}from"./index-Cc-6WbPt.js";import{M as G,y as U}from"./Project-BB6nGAyP.js";import{u as T}from"./useJupyterSettings-C-cEjZB2.js";import{K as B}from"./KubernetesProjectEdit-BWf57EkW.js";import"./alertManagerConfig.selectors-ob2Z93Rq.js";import"./complement-BOrTcrWV.js";import"./index-DeWhk8_Z.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-FE3v46aY.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-CGP_51ct.js";import"./Anchor-BpzIF9LH.js";const M=["python","ray"],re=()=>{const c=x(),{id:u}=P(),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(b.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(G,{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(q,{}),s.jsx(Q,{})]}),children:a}),s.jsx(B,{prefix:[l],init:!1,isDisabled:!!g,enabledKueue:M.includes(l)},l)]})},JSON.stringify(o))},q=()=>{const{id:c}=P();return s.jsx(H,{intent:"secondary",href:N(b.project.settings.computeConfiguration,b.project.value,{id:c}),children:"Go to default configuration"})},Q=()=>{const c=x(),{id:u}=P(),{data:i}=T(+u),{data:n}=U(),[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=_((r,o)=>o.type===t.SPARK?S("jobConfig",o,r):o.type===t.PYTHON?F(["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{re as default};
