import{b0 as S,u as C,b1 as D,r as p,b2 as K,fR as A,E as n,j as t,a_ as x,K as H,a as J,aT as P,g as L,e as y,l as N,az as b,ae as O,a$ as w,bx as F,f0 as Y,cT as E,hl as G}from"./index-d6499a22.js";import{J as B,a as M}from"./Project-92985c5d.js";import{s as U}from"./jupyter.selectors-97655dc7.js";import{u as R}from"./useJupyterSettings-e66352d2.js";import"./index-ddf2d065.js";import"./FileUploaderButton-c4f1b533.js";import"./useDownload-7167ff3b.js";import"./useCurrentProject-b23444be.js";import"./useProject-0d0fdeb3.js";import"./PrimaryIconButton-fd23494f.js";import"./zipObj-e651182a.js";import"./dumbPluralize-86a9b9d6.js";import"./git-d9965c1a.js";import"./NoData-789df290.js";import"./index-da50fbe6.js";import"./file-utils-b5704e1c.js";import"./alertManagerConfig.selectors-c57f191b.js";const de=()=>{const r=S(),{id:a}=C(),c=D(),[s,g]=p.useState(!1),{data:e,isLoading:j}=R(+a),{data:u,isLoading:l}=K(U),{data:m,isLoading:d}=A();p.useEffect(()=>(r.jupyter.fetchRunningServer({projectId:+a}),()=>{r.jupyter.clear()}),[r.jupyter,a]);const i=async f=>{g(!0);const k=f.type===n.SPARK,h=f.type===n.PYTHON,{resourceConfig:v}=f,I={...e,...h&&{dockerConfig:{...e.dockerConfig,resourceConfig:{...e.dockerConfig.resourceConfig,...v}}},...k&&{jobConfig:F(["experimentType"],{...e.jobConfig,...f})},pythonKernel:h};await r.jupyter.update({projectId:+a,settings:I}),c(y.jupyter.overview),g(!1)},{initialData:o,selectedConfig:T}=p.useMemo(()=>e?{initialData:[e.jobConfig,{...e.dockerConfig,type:n.PYTHON}],selectedConfig:e.pythonKernel&&m?n.PYTHON:n.SPARK}:{initialData:[]},[m,e]);return!e||l||d?t.jsx(x,{}):t.jsx(B,{isDisabled:!!u,initialData:o,submitHandler:i,canSave:!u,onlyAdvancedConfig:!0,selectedConfig:T,isSubmiting:s,checkedAdvancedConfig:!0,noPythonFiles:!0,isJupyter:!0,children:({advanceConfig:f})=>t.jsxs(t.Fragment,{children:[j&&t.jsx(x,{}),t.jsx(H,{width:"100%",title:"Jupyter server configuration",actions:!u&&t.jsxs(J,{gap:"8px",children:[t.jsx(q,{}),t.jsx(z,{})]}),children:f})]})})},q=()=>{const{id:r}=C();return t.jsx(P,{intent:"secondary",href:L(y.project.settings.computeConfiguration,y.project.value,{id:r}),children:"Go to default configuration"})},z=()=>{const r=S(),{id:a}=C(),{data:c}=R(+a),{data:s}=M(),[g,e]=N(),[j,u]=p.useState(!1),l=p.useMemo(()=>{const d=s==null?void 0:s.find(o=>o.type===n.SPARK),i=s==null?void 0:s.find(o=>o.type===n.PYTHON);return(!d||b(c.jobConfig,d))&&(!i||b(c.dockerConfig.resourceConfig,i.resourceConfig))},[s,c.jobConfig,c.dockerConfig]),m=async()=>{u(!0);const d=Y((i,o)=>o.type===n.SPARK?E("jobConfig",o,i):o.type===n.PYTHON?G(["dockerConfig","resourceConfig"],o.resourceConfig,i):i,c,s??[]);await r.jupyter.update({projectId:+a,settings:d}),u(!1),e()};return t.jsxs(t.Fragment,{children:[t.jsx(O,{disabled:!l,mainText:"It's already set to default config",children:t.jsx(P,{onClick:e,disabled:l,children:"Reset to default configuration"})}),t.jsx(w,{title:"Reset to default config",secondaryText:"Are you sure that you want to reset to default config?",isOpen:g,onClose:e,mainButtonProps:{children:"Reset config",onClick:m,isLoading:j},secondaryButtonProps:{children:"Cancel",onClick:e}})]})};export{de as default};
