const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TopMenuNodes-DtY7xZ_c.js","assets/reactflow-vendor-BDofclgK.js","assets/react-vendor-4ldeB94U.js","assets/Stack-2Xb3rVeY.js","assets/index-D-ULYqgV.js","assets/index-nIlKpDnX.css","assets/dialog-BbYNcTN7.js","assets/TopMenuCodePreviewButton-B6MsSgqQ.js"])))=>i.map(i=>d[i]);
import{c as p,f as g,a as z,u as M,b as x,d as v,g as j,s as w,_}from"./index-D-ULYqgV.js";import{j as e}from"./reactflow-vendor-BDofclgK.js";import{c as h,B as d,S as C,a as y,I as T,F as S}from"./Stack-2Xb3rVeY.js";import{r as c,a as O}from"./react-vendor-4ldeB94U.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 E=h("outline","device-floppy","IconDeviceFloppy",[["path",{d:"M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2",key:"svg-0"}],["path",{d:"M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-1"}],["path",{d:"M14 4l0 4l-6 0l0 -4",key:"svg-2"}]]);/**
 * @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=h("outline","download","IconDownload",[["path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2",key:"svg-0"}],["path",{d:"M7 11l5 5l5 -5",key:"svg-1"}],["path",{d:"M12 4l0 12",key:"svg-2"}]]);/**
 * @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=h("outline","folder-open","IconFolderOpen",[["path",{d:"M5 19l2.757 -7.351a1 1 0 0 1 .936 -.649h12.307a1 1 0 0 1 .986 1.164l-.996 5.211a2 2 0 0 1 -1.964 1.625h-14.026a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2",key:"svg-0"}]]);/**
 * @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 R=h("outline","pencil","IconPencil",[["path",{d:"M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4",key:"svg-0"}],["path",{d:"M13.5 6.5l4 4",key:"svg-1"}]]);/**
 * @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 D=h("outline","plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);/**
 * @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 L=h("filled","player-play-filled","IconPlayerPlayFilled",[["path",{d:"M6 4v16a1 1 0 0 0 1.524 .852l13 -8a1 1 0 0 0 0 -1.704l-13 -8a1 1 0 0 0 -1.524 .852z",key:"svg-0"}]]);/**
 * @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 b=h("filled","triangle-inverted-filled","IconTriangleInvertedFilled",[["path",{d:"M20.118 3h-16.225a2.914 2.914 0 0 0 -2.503 4.371l8.116 13.549a2.917 2.917 0 0 0 4.987 .005l8.11 -13.539a2.914 2.914 0 0 0 -2.486 -4.386z",key:"svg-0"}]]);function W(){const[n,t]=c.useState(!1),o=z("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",12);return e.jsx(d,{left:e.jsx(L,{size:15}),isLoading:n,onClick:()=>{const a={job_id:o(),nodes:p.graph.nodes,edges:p.graph.edges,values:p.graph.values};console.log("graph",a),t(!0),g("/run_job",{method:"POST",body:JSON.stringify(a)}).finally(()=>{t(!1)})},children:"Run"})}function G(){const[n,t]=c.useState(!1),{toast:o}=M(),{onSaveGraph:a,name:l}=x(v(i=>({onSaveGraph:i.onSaveGraph,name:i.name})));return e.jsx(d,{variant:"ghost",size:"sm",title:"Save workflow",isLoading:n,onClick:()=>{const i={nodes:p.graph.nodes,edges:p.graph.edges,values:p.graph.values,job_status:p.graph.job_status};console.log("graph",i);let s=j();s||(s=prompt("Enter workflow name",l??"")),s&&(t(!0),g("/workflow/save",{method:"POST",body:JSON.stringify({graph:i,path:s.endsWith(".json")?s:`${s}.json`,new:j()==null})}).then(r=>r.json()).then(r=>{if(typeof r.path!="string")throw new Error(r.error);w(r.path),a(),o({title:"✅ Workflow saved to",description:r.root_rel})}).catch(r=>{o({title:"Error saving workflow",variant:"destructive",description:r.message}),console.error(r)}).finally(()=>{t(!1)}))},children:e.jsx(E,{size:18})})}function B({onClose:n,children:t,className:o="",backdrop:a="rgba(0, 0, 0, 0.5)",position:l="left"}){const i=c.useRef(null);return c.useEffect(()=>{const s=r=>{i.current&&!i.current.contains(r.target)&&n()};return document.addEventListener("mousedown",s,!0),()=>{document.removeEventListener("mousedown",s,!0)}},[]),O.createPortal(e.jsxs(e.Fragment,{children:[a&&e.jsx("div",{onClick:n,style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:a}}),e.jsx("div",{style:{height:"100vh",position:"fixed",top:0,left:l==="right"?"auto":0,right:l==="right"?0:"auto"},ref:i,className:`bg-zinc-800 ${o}`,children:t})]}),document.body)}function I({path:n,onClickWorkflow:t}){const[o,a]=c.useState([]),[l,i]=c.useState(!1);return c.useEffect(()=>{i(!0),g("/workflow/list?path="+encodeURIComponent(n)).then(s=>s.json()).then(s=>{a(s)}).finally(()=>{i(!1)})},[]),e.jsx("div",{className:"flex flex-col",children:e.jsxs("div",{className:"flex flex-col",children:[l&&e.jsx(C,{}),o.map(s=>s.type==="folder"?e.jsx(A,{node:s,onClickWorkflow:t},s.path):e.jsx(y,{children:e.jsx(d,{variant:"ghost",className:"justify-start text-lg",onClick:()=>{typeof s.rel_path=="string"&&t(s.rel_path)},children:e.jsx("p",{className:"",children:s.name})})},s.type+"_"+s.name))]})})}function A({node:n,onClickWorkflow:t}){const[o,a]=c.useState(!1);return e.jsxs(y,{className:"",children:[e.jsxs("div",{className:"flex flex-row items-center cursor-pointer",onClick:()=>a(!o),children:[e.jsx(b,{size:8,className:o?"mr-1":"-rotate-90 mr-1"}),e.jsx(T,{className:"mr-1"}),n.name]}),o&&e.jsx("div",{className:"ml-3",children:e.jsx(I,{path:n.path,onClickWorkflow:t})})]})}function U(){const[n,t]=c.useState(!1),{name:o,isDirty:a}=x(v(l=>({name:l.name,isDirty:l.isDirty})));return e.jsxs(e.Fragment,{children:[e.jsx(d,{onClick:()=>t(!0),className:"px-[8px] bg-zinc-800 hover:bg-zinc-500",children:e.jsxs(S,{className:"gap-[4px]",children:[a&&e.jsx("span",{children:" * "}),e.jsx("span",{className:"mr-1",children:o??"Untitled"}),e.jsx(b,{size:7})]})}),n&&e.jsx(B,{onClose:()=>t(!1),backdrop:null,children:e.jsxs(y,{className:"w-[400px] py-2 px-2 overflow-y-auto h-[100vh]",children:[e.jsx("h2",{className:"text-xl font-bold p-2",children:"Workflows"}),e.jsx(I,{path:"",onClickWorkflow:l=>{w(l),t(!1)}})]})})]})}function $(){const{setName:n}=x(v(t=>({setName:t.setName})));return e.jsx(d,{className:"text-sm",size:"sm",title:"Rename workflow",variant:"ghost",onClick:()=>{const t=j(),o=prompt("Enter a name for this workflow",(t==null?void 0:t.slice(0,-5))??"");o&&(t?g("/workflow/rename",{method:"POST",body:JSON.stringify({path:t,new_name:o.endsWith(".json")?o:`${o}.json`})}).then(a=>a.json()).then(a=>{const l=a.path;if(typeof l!="string")throw new Error(a.error);w(l)}).catch(a=>{alert(`❌Failed to rename workflow: ${a.message}`)}):n(o))},children:e.jsx(R,{size:18})})}const J=c.lazy(()=>_(()=>import("./TopMenuNodes-DtY7xZ_c.js"),__vite__mapDeps([0,1,2,3,4,5,6]))),V=c.lazy(()=>_(()=>import("./TopMenuCodePreviewButton-B6MsSgqQ.js"),__vite__mapDeps([7,1,2,3,4,5])));function q(){const{name:n,loadGraph:t,clearGraph:o}=x(v(s=>({name:s.name,loadGraph:s.loadGraph,clearGraph:s.clearGraph}))),a=()=>{var m;(m=document.getElementById("workflow-download"))==null||m.click();const s=JSON.stringify(p.graph,null,2);console.log("common_app.graph",p.graph);const r=new Blob([s],{type:"application/json"}),f=URL.createObjectURL(r),u=document.createElement("a");u.href=f,u.download=`${n??"nozy_workflow"}.json`,u.click()},l=c.useRef(null),i=s=>{var u;const r=(u=s.target.files)==null?void 0:u[0],f=new FileReader;r&&(f.readAsText(r,"UTF-8"),f.onload=m=>{var N;const k=JSON.parse((N=m.target)==null?void 0:N.result);k.name=r.name.replace(/\.json$/,""),t(k)})};return e.jsxs("div",{className:"flex items-center justify-between absolute top-0 left-0 right-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{}),e.jsx(d,{size:"sm",className:"px-1",variant:"ghost",title:"New workflow",onClick:()=>{o()},children:e.jsx(D,{size:18})}),e.jsx(U,{}),e.jsxs(S,{className:"gap-0",children:[e.jsx(G,{}),e.jsx($,{}),e.jsx(d,{size:"sm",variant:"ghost",title:"Download workflow",onClick:a,children:e.jsx(F,{size:18})}),e.jsx(d,{size:"sm",variant:"ghost",title:"Open workflow",onClick:()=>{var s;(s=l.current)==null||s.click()},children:e.jsx(P,{size:18})}),e.jsx("input",{type:"file",accept:".json",id:"workflow-upload",ref:l,style:{display:"none"},onChange:i})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{}),e.jsx(W,{})]})]})}const Y=Object.freeze(Object.defineProperty({__proto__:null,default:q},Symbol.toStringTag,{value:"Module"}));export{B as C,b as I,Y as T,D as a};
