import{__assign as n}from"tslib";import{jsxs as t,jsx as o}from"react/jsx-runtime";import{useState as e,useRef as i,useEffect as r}from"react";import{MoreVertical as c}from"lucide-react";import a from"../../styles/ScopeTree.module.css.js";import{TreeTooltip as l}from"./TreeTooltip.js";var d=function(d){var s=d.options,u=void 0===s?[]:s,m=d.buttonClassName,p=void 0===m?"":m,f=d.iconSize,v=void 0===f?16:f,h=e(!1),b=h[0],g=h[1],w=e(!1),N=w[0],C=w[1],y=i(null),k=i(null);r(function(){var n=function(n){y.current&&!y.current.contains(n.target)&&g(!1)};return document.addEventListener("mousedown",n),function(){return document.removeEventListener("mousedown",n)}},[]);return t("div",n({className:a.menuContainer,ref:y},{children:[o("div",{children:o("button",n({ref:k,type:"button",className:p||a.optionsButton,onClick:function(n){if(n.stopPropagation(),!b&&k.current){var t=k.current.getBoundingClientRect(),o=window.innerHeight-t.bottom,e=40*u.length+20;C(o<e)}g(!b)}},{children:o(c,{size:v,"aria-hidden":"true"})}))}),b&&o("div",n({className:"".concat(a.menuDropdown," ").concat(N?a.menuDropdownTop:a.menuDropdownBottom),role:"menu","aria-orientation":"vertical"},{children:u.map(function(e,i){var r=t("button",n({disabled:e.disabled,onClick:function(n){var t;(n.stopPropagation(),e.disabled)||((t=e.onClick)&&"function"==typeof t&&t(),g(!1))},className:"".concat(a.menuOption," ").concat(e.disabled?a.menuOptionDisabled:""," ").concat(e.className||""),role:"menuitem"},{children:[e.icon&&o(e.icon,{size:16,className:a.menuOptionIcon}),e.label]}),"btn-".concat(i));return e.tooltip&&e.disabled?o("div",n({className:a.tooltipWrapper,onClick:function(n){return n.stopPropagation()}},{children:o(l,n({content:e.tooltip,placement:"right"},{children:o("div",n({style:{width:"100%"}},{children:r}))}))}),i):o("div",n({style:{width:"100%"}},{children:r}),i)})}))]}))};export{d as TreeMenu};
//# sourceMappingURL=TreeMenu.js.map
