import{j as e}from"./reactflow-vendor-BDofclgK.js";import{c as m,S as g,a as d,F as f,I as j,B as p}from"./Stack-B0H3UBj-.js";import{I as v,C as k,a as y}from"./TopMenu-BTBlWog1.js";import{r as t}from"./react-vendor-4ldeB94U.js";import{r as N,f as x,u as b}from"./index-DXXsU5Ky.js";import{D as I,a as C,b as D,c as S}from"./dialog-Bsewgbrm.js";/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var F=m("outline","box","IconBox",[["path",{d:"M12 3l8 4.5l0 9l-8 4.5l-8 -4.5l0 -9l8 -4.5",key:"svg-0"}],["path",{d:"M12 12l8 -4.5",key:"svg-1"}],["path",{d:"M12 12l0 9",key:"svg-2"}],["path",{d:"M12 12l-8 -4.5",key:"svg-3"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var P=m("outline","brand-tabler","IconBrandTabler",[["path",{d:"M8 9l3 3l-3 3",key:"svg-0"}],["path",{d:"M13 15l3 0",key:"svg-1"}],["path",{d:"M4 4m0 4a4 4 0 0 1 4 -4h8a4 4 0 0 1 4 4v8a4 4 0 0 1 -4 4h-8a4 4 0 0 1 -4 -4z",key:"svg-2"}]]);function u({path:r}){const[l,o]=t.useState([]),{setDropingNode:i}=N(),[h,c]=t.useState(!1);return t.useEffect(()=>{c(!0),x("/list_package_children?path="+encodeURIComponent(r)).then(a=>a.json()).then(a=>{o(a)}).finally(()=>{c(!1)})},[]),e.jsx("div",{className:"flex flex-col",children:e.jsxs("div",{className:"flex flex-col",children:[h&&e.jsx(g,{}),l.map(a=>{var s;return a.type==="folder"?e.jsx(w,{node:a},a.path):e.jsxs(d,{onClick:()=>{},children:[e.jsx(f,{children:e.jsx("p",{className:"text-muted-foreground",children:a.name})}),(s=a.functions)==null?void 0:s.map(n=>e.jsxs("div",{draggable:!0,onDragStart:_=>{console.log(n),i(n)},className:"flex flex-row items-center ml-2 py-1 font-semibold gap-1 cursor-pointer hover:bg-secondary",children:[e.jsx(P,{size:18}),e.jsx("span",{children:n.name})]},a.path+"_"+n.name))]},a.type+"_"+a.name)})]})})}function w({node:r}){const[l,o]=t.useState(!1);return e.jsxs(d,{className:"",children:[e.jsxs("div",{className:"flex flex-row items-center cursor-pointer hover:bg-secondary",onClick:()=>o(!l),children:[e.jsx(v,{size:8,className:l?"mr-1":"-rotate-90 mr-1"}),e.jsx(j,{className:"mr-1"}),r.name]}),l&&e.jsx("div",{className:"ml-3",children:e.jsx(u,{path:r.path})})]})}function M({onClose:r}){const{toast:l}=b(),[o,i]=t.useState([]),[h,c]=t.useState(null);t.useEffect(()=>{x("/package/list_community").then(s=>s.json()).then(i)},[]);const a=s=>{c(s),x("/package/install",{method:"POST",body:JSON.stringify({url:s})}).then(n=>n.json()).then(n=>{c(null),n.error?l({title:`❌Failed to install package ${s}`,description:n.error}):l({title:`✅Installed package ${s}`,description:"Please refresh the page."})})};return e.jsx(I,{onOpenChange:r,open:!0,children:e.jsxs(C,{className:"sm:max-w-[50vw]","aria-describedby":"Choose File",children:[e.jsx(D,{children:e.jsx(S,{children:"Community Node Packages"})}),e.jsx(d,{children:e.jsx("div",{className:"grid grid-cols-[2fr_3fr_1fr] gap-4",children:o.map(s=>e.jsxs(t.Fragment,{children:[e.jsx("div",{className:"font-bold",children:s.name}),e.jsx("div",{children:s.description}),e.jsx(p,{onClick:()=>a(s.url),isLoading:h===s.url,children:"Install"})]},s.url))})})]})})}function R(){const[r,l]=t.useState(!1),[o,i]=t.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(p,{onClick:()=>l(!0),left:e.jsx(F,{size:18}),children:"Nodes"}),r&&e.jsx(k,{onClose:()=>l(!1),backdrop:null,children:e.jsxs(d,{className:"w-[400px] py-2 px-2 overflow-y-auto h-[100vh]",children:[e.jsxs(f,{className:"justify-between",children:[e.jsx("h2",{className:"text-xl font-bold p-2",children:"Nodes"}),e.jsx(p,{onClick:()=>i(!0),left:e.jsx(y,{size:18}),children:e.jsx("span",{children:"Install Node Package"})})]}),e.jsx(u,{path:""})]})}),o&&e.jsx(M,{onClose:()=>i(!1)})]})}export{R as default};
