import{bH as x,u as P,b9 as K,r as p,bI as Y,k5 as k,bh as A,a2 as t,j as s,D as R,b as v,$ as D,c7 as H,q as b,b1 as O,o as N,y as E,aQ as m,ao as w,br as J,bz as L,gw as _,bt as S,gt as F}from"./index-46ma1THH.js";import{M as G,y as U}from"./Project-DqNODNns.js";import{u as T}from"./useJupyterSettings-CcsWT1dz.js";import{K as B}from"./KubernetesProjectEdit-DOgOIrBH.js";import"./alertManagerConfig.selectors-ByceE4ck.js";import"./complement-Cl658Mix.js";import"./index-CcWUz40c.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-Bbf2VNbK.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-B8vQLvqE.js";import"./Anchor-VqM1KJ3L.js";const M=["python","ray"],re=()=>{const c=x(),{id:u}=P(),i=K(),[n,y]=p.useState(!1),{data:e,isLoading:h}=T(+u),{data:g,isLoading:C}=Y(k),{data:j,isLoading:d}=A();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:H(["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(O,{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(w,{disabled:!C,mainText:"It's already set to default config",children:s.jsx(J,{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};
