import{bf as P,u as C,bg as v,r as p,bh as I,aZ as T,Y as n,j as t,L as h,Q as D,d as K,b6 as N,o as O,q as y,w,aG as b,am as A,be as H,bE as J,dI as L,b9 as Y,ek as G}from"./index-CK33qGU_.js";import{P as F,G as B}from"./Project-j3KdDsvH.js";import{s as E}from"./jupyter.selectors-B8a5Dlnv.js";import{B as Q}from"./ButtonWithRole-NHXEosto.js";import{u as x}from"./useJupyterSettings-DOiqFzDK.js";import"./alertManagerConfig.selectors-BX2JGYEL.js";import"./__-BIxbRvwe.js";import"./useDownload-hrjXceJg.js";import"./useProject-BzBQtp4J.js";import"./length-fOfC3W0h.js";import"./complement-M2aUPqXA.js";import"./FileUploaderButton-Bppadu35.js";import"./dumbPluralize-CcxDsNiu.js";import"./PrimaryIconButton-DQUEhx3G.js";import"./zipObj-DQ8OxaYj.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./git-C8OLuEaG.js";import"./NoData-CuLyR2Bg.js";import"./useCopyToClipboard-_4vnCVip.js";import"./Anchor-HBBcGDu5.js";const pe=()=>{const r=P(),{id:a}=C(),c=v(),[o,g]=p.useState(!1),{data:e,isLoading:j}=x(+a),{data:u,isLoading:l}=I(E),{data:m,isLoading:d}=T();p.useEffect(()=>(r.jupyter.fetchRunningServer({projectId:+a}),()=>{r.jupyter.clear()}),[r.jupyter,a]);const i=async f=>{g(!0);const R=f.type===n.PYTHON,k={...e,dockerConfig:{...e.dockerConfig,resourceConfig:{...e.dockerConfig.resourceConfig,...f[n.PYTHON].resourceConfig}},jobConfig:J(["experimentType"],{...e.jobConfig,...f[n.SPARK]}),pythonKernel:R};await r.jupyter.update({projectId:+a,settings:k}),c(y.jupyter.overview),g(!1)},{initialData:s,selectedConfig:S}=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(h,{}):t.jsx(F,{isDisabled:!!u,initialData:s,submitHandler:i,canSave:!u,onlyAdvancedConfig:!0,selectedConfig:S,isSubmiting:o,checkedAdvancedConfig:!0,noPythonFiles:!0,isJupyter:!0,children:({advanceConfig:f})=>t.jsxs(t.Fragment,{children:[j&&t.jsx(h,{}),t.jsx(D,{width:"100%",title:"Jupyter server configuration",actions:!u&&t.jsxs(K,{gap:"8px",children:[t.jsx(q,{}),t.jsx(M,{})]}),children:f})]})},JSON.stringify(s))},q=()=>{const{id:r}=C();return t.jsx(N,{intent:"secondary",href:O(y.project.settings.computeConfiguration,y.project.value,{id:r}),children:"Go to default configuration"})},M=()=>{const r=P(),{id:a}=C(),{data:c}=x(+a),{data:o}=B(),[g,e]=w(),[j,u]=p.useState(!1),l=p.useMemo(()=>{const d=o==null?void 0:o.find(s=>s.type===n.SPARK),i=o==null?void 0:o.find(s=>s.type===n.PYTHON);return(!d||b(c.jobConfig,d))&&(!i||b(c.dockerConfig.resourceConfig,i.resourceConfig))},[o,c.jobConfig,c.dockerConfig]),m=async()=>{u(!0);const d=L((i,s)=>s.type===n.SPARK?Y("jobConfig",s,i):s.type===n.PYTHON?G(["dockerConfig","resourceConfig"],s.resourceConfig,i):i,c,o??[]);await r.jupyter.update({projectId:+a,settings:d}),u(!1),e()};return t.jsxs(t.Fragment,{children:[t.jsx(A,{disabled:!l,mainText:"It's already set to default config",children:t.jsx(Q,{onClick:e,disabled:l,children:"Reset to default configuration"})}),t.jsx(H,{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{pe as default};
