import{X as I}from"./index.f528fccb.js";import{c as f,G as C}from"./vendor-ant-design-vue.e5e30ccc.js";import{f as j,r as h,e as k,b as M,n as $,d as O,u as d,c as l,i as N,F as S}from"./vendor-@vue.d54eea3a.js";function A(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!N(n)}const p="context-menu",D={width:{type:Number,default:156},customEvent:{type:Object,default:null},styles:{type:Object},showIcon:{type:Boolean,default:!0},axis:{type:Object,default(){return{x:0,y:0}}},items:{type:Array,default(){return[]}}},x=n=>{const{item:u}=n;return l("span",{style:"display: inline-block; width: 100%; ",class:"px-4",onClick:n.handler.bind(null,u)},[n.showIcon&&u.icon&&l(I,{class:"mr-2",icon:u.icon},null),l("span",null,[u.label])])};var R=j({name:"ContextMenu",props:D,setup(n){const u=h(null),r=h(!1),_=k(()=>{const{axis:e,items:t,styles:o,width:s}=n,{x:a,y:c}=e||{x:0,y:0},i=(t||[]).length*40,y=s,b=document.body,w=b.clientWidth<a+y?a-y:a,g=b.clientHeight<c+i?c-i:c;return{...o,width:`${s}px`,left:`${w+1}px`,top:`${g+1}px`}});M(()=>{$(()=>r.value=!0)}),O(()=>{const e=d(u);e&&document.body.removeChild(e)});function v(e,t){const{handler:o,disabled:s}=e;s||(r.value=!1,t==null||t.stopPropagation(),t==null||t.preventDefault(),o==null||o())}function m(e){return e.map(t=>{const{disabled:o,label:s,children:a,divider:c=!1}=t,i={item:t,handler:v,showIcon:n.showIcon};return!a||a.length===0?l(S,null,[l(f.Item,{disabled:o,class:`${p}__item`,key:s},{default:()=>[l(x,i,null)]}),c?l(C,{key:`d-${s}`},null):null]):d(r)?l(f.SubMenu,{key:s,disabled:o,popupClassName:`${p}__popup`},{title:()=>l(x,i,null),default:()=>m(a)}):null})}return()=>{let e;if(!d(r))return null;const{items:t}=n;return l(f,{inlineIndent:12,mode:"vertical",class:p,ref:u,style:d(_)},A(e=m(t))?e:{default:()=>[e]})}}});export{R as _};
