import{s as l}from"./chunk-LvLJmgfZ.js";import{p as x}from"./useEvent-D91BmmQi.js";import{t as k}from"./react-Bj1aDYRI.js";import{g as v}from"./useEventListener-C0195JsF.js";import{t as f}from"./jsx-runtime-Blw4afVn.js";import{r as j}from"./requests-9-v2bhoi.js";import{t as n}from"./use-toast-BwJoaaDM.js";import{t as o}from"./kbd-C5HnBH5U.js";const y=x(null),m="packages-install-input",p=()=>{requestAnimationFrame(()=>{let e=document.getElementById(m);e&&e.focus()})},P=e=>{e.openApplication("packages"),p()};var a=l(f(),1);const g=(e,t)=>{n(t?{title:"Failed to add package",description:t,variant:"danger"}:{title:"Package added",description:(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{children:["The package ",(0,a.jsx)(o,{className:"inline",children:e})," and its dependencies has been added to your environment."]}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1",children:"Some Python packages may require a kernel restart to see changes."})]})})},N=(e,t)=>{n(t?{title:"Failed to upgrade package",description:t,variant:"danger"}:{title:"Package upgraded",description:(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{children:["The package ",(0,a.jsx)(o,{className:"inline",children:e})," has been upgraded."]}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1",children:"Some Python packages may require a kernel restart to see changes."})]})})},q=(e,t)=>{n(t?{title:"Failed to remove package",description:t,variant:"danger"}:{title:"Package removed",description:(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{children:["The package ",(0,a.jsx)(o,{className:"inline",children:e})," has been removed from your environment."]}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground mt-1",children:"Some Python packages may require a kernel restart to see changes."})]})})};var F=l(k(),1);function S(){let[e,t]=(0,F.useState)(!1),{addPackage:h}=j();return{loading:e,handleInstallPackages:async(d,r)=>{t(!0);try{for(let[s,i]of d.entries()){let c=await h({package:i});c.success?g(i):g(i,c.error),s<d.length-1&&await new Promise(u=>setTimeout(u,1e3))}r==null||r()}catch(s){v.error(s)}finally{t(!1)}}}}export{p as a,m as i,q as n,P as o,N as r,y as s,S as t};
