import{FlowNode as e}from"./flow-node";import{ConnectionLine as t}from"../flow-viewer";import{integration as o,project as n,copyPasteManager as a,input as l,exporter as r,modal as i}from"./flow-editor";import{i18next as p}from"@openremote/or-translate";import{Utilities as c}from"../utils";import{CopyMachine as s}from"../node-structure";import{ContextMenu as f}from"./context-menu";import{html as d}from"lit";export const createContextMenuButtons=(u,m)=>{let y=l.selected.filter(t=>t instanceof e&&t.selected),b=l.selected.filter(e=>e instanceof t&&e.selected),h=e=>{let t=[{type:"button",label:"",icon:"arrow-left",action:()=>{u.dispatchEvent(new MouseEvent("contextmenu",m))}}];return t.concat(o.nodes.filter(t=>t.type===e).map(e=>({type:"button",label:p.t("flow."+e.name,c.humanLike(e.name)),action:()=>{let t=s.copy(e);t.position=u.offsetToWorld({x:m.offsetX-u.offsetLeft,y:m.offsetY-u.offsetTop}),n.createUndoSnapshot(),n.addNode(t)}})))},g=[{type:"button",label:p.t("input","Input"),icon:"arrow-collapse-right",action:()=>{f.open(m.pageX,m.pageY,u,h("INPUT"))}},{type:"button",label:p.t("processors","Processors"),icon:"cog",action:()=>{f.open(m.pageX,m.pageY,u,h("PROCESSOR"))}},{type:"button",label:p.t("output","Output"),icon:"arrow-expand-right",action:()=>{f.open(m.pageX,m.pageY,u,h("OUTPUT"))}}];return g.concat([{type:"separator"},{type:"button",icon:"content-copy",label:p.t("copy","Copy"),action:()=>{let e=u.offsetToWorld({x:m.offsetX,y:m.offsetY});a.copy(e.x,e.y)},disabled:0===y.length},{type:"button",icon:"content-paste",label:p.t("paste","Paste"),action:()=>{n.createUndoSnapshot();let e=u.offsetToWorld({x:m.offsetX,y:m.offsetY});n.notifyChange(),u.pasteAt(e.x,e.y)},disabled:a.isFull},{type:"button",icon:"delete",label:p.t("delete","Delete"),action:()=>{n.createUndoSnapshot(),y.forEach(e=>{e.frozen||n.removeNode(e.node)}),b.forEach(e=>n.removeConnection(e.connection)),n.notifyChange()},disabled:0===y.length&&0===b.length||0!==y.length&&y.every(e=>e.frozen)},{type:"separator"},{type:"button",icon:"fit-to-page-outline",label:p.t("fitViewToSelectedNodes","Fit view to selected nodes"),action:()=>u.fitCamera(y.map(e=>e.node)),disabled:0===y.length},{type:"button",icon:"snowflake",label:"TOGGLE FROZEN [DEBUG FUNCTION]",action:()=>y.forEach(e=>e.frozen=!e.frozen),disabled:0===y.length},{type:"separator"},{type:"button",icon:"export",label:"Export to JSON",action:()=>{i.anything("Export result",d`
                <div style="user-select: all;font-family: monospace; padding: 5px; overflow: auto; background: whitesmoke; max-width:50vw; max-height:50vh">
                ${r.flowToJson(n.toNodeCollection("Exported on "+new Date,""))}
                </div>
                `)}}])};