import{b1 as x,u as C,b2 as A,r as p,b3 as D,fX as K,G as n,j as t,a$ as b,E as H,Q as J,aU as S,c as N,b as y,P as O,aA as P,af as w,b0 as L,by as E,f5 as F,cW as G,hq as Y}from"./index-ea7817a2.js";import{J as Q,a as q}from"./Project-80a71be4.js";import{s as B}from"./jupyter.selectors-97655dc7.js";import{u as R}from"./useJupyterSettings-ccbf1a02.js";import"./index-43e7382e.js";import"./FileUploaderButton-495e1c87.js";import"./useDownload-09eaf3eb.js";import"./useCurrentProject-0132f110.js";import"./useProject-77619fff.js";import"./PrimaryIconButton-fe990c52.js";import"./zipObj-08c84ab1.js";import"./dumbPluralize-86a9b9d6.js";import"./git-d9965c1a.js";import"./NoData-8733f606.js";import"./index-8f672200.js";import"./file-utils-a5f053e8.js";import"./alertManagerConfig.selectors-c57f191b.js";const de=()=>{const r=x(),{id:a}=C(),c=A(),[s,g]=p.useState(!1),{data:e,isLoading:j}=R(+a),{data:u,isLoading:l}=D(B),{data:m,isLoading:d}=K();p.useEffect(()=>(r.jupyter.fetchRunningServer({projectId:+a}),()=>{r.jupyter.clear()}),[r.jupyter,a]);const i=async f=>{g(!0);const v=f.type===n.SPARK,h=f.type===n.PYTHON,{resourceConfig:I}=f,T={...e,...h&&{dockerConfig:{...e.dockerConfig,resourceConfig:{...e.dockerConfig.resourceConfig,...I}}},...v&&{jobConfig:E(["experimentType"],{...e.jobConfig,...f})},pythonKernel:h};await r.jupyter.update({projectId:+a,settings:T}),c(y.jupyter.overview),g(!1)},{initialData:o,selectedConfig:k}=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(b,{}):t.jsx(Q,{isDisabled:!!u,initialData:o,submitHandler:i,canSave:!u,onlyAdvancedConfig:!0,selectedConfig:k,isSubmiting:s,checkedAdvancedConfig:!0,noPythonFiles:!0,isJupyter:!0,children:({advanceConfig:f})=>t.jsxs(t.Fragment,{children:[j&&t.jsx(b,{}),t.jsx(H,{width:"100%",title:"Jupyter server configuration",actions:!u&&t.jsxs(J,{gap:"8px",children:[t.jsx(M,{}),t.jsx(U,{})]}),children:f})]})})},M=()=>{const{id:r}=C();return t.jsx(S,{intent:"secondary",href:N(y.project.settings.computeConfiguration,y.project.value,{id:r}),children:"Go to default configuration"})},U=()=>{const r=x(),{id:a}=C(),{data:c}=R(+a),{data:s}=q(),[g,e]=O(),[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||P(c.jobConfig,d))&&(!i||P(c.dockerConfig.resourceConfig,i.resourceConfig))},[s,c.jobConfig,c.dockerConfig]),m=async()=>{u(!0);const d=F((i,o)=>o.type===n.SPARK?G("jobConfig",o,i):o.type===n.PYTHON?Y(["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(w,{disabled:!l,mainText:"It's already set to default config",children:t.jsx(S,{onClick:e,disabled:l,children:"Reset to default configuration"})}),t.jsx(L,{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};
