import{a as e,d as t,f as n,i as r,l as i,s as a,t as o}from"./hooks.module-BrXTvcfS.js";import{t as s}from"./bootstrap.esm-DbsKxb7T.js";import{k as c}from"./i18n-BaLR3UdQ.js";import{p as l,t as u}from"./compat.module-C8KToj4y.js";import{t as d}from"./jsxRuntime.module-Cao1NCKs.js";import{et as f,q as p}from"./hooks-ClTXKdUl.js";import{t as m}from"./modal_focustrap-BhwPuWvY.js";l(),t();function h({id:t,className:l,buttonClassName:h,isStatic:g,children:_,title:v,text:y,dropdownContainerStyle:b,dropdownContainerClassName:x,dropdownContainerRef:S,hideToggleArrow:C,iconAction:w,disabled:T,noSelectButtonStyle:E,noDropdownListStyle:D,forceShown:O,onShown:k,onHidden:A,dropdownOptions:j,buttonProps:M,dropdownRef:N,titlePosition:P,titleOptions:F,mobileBackdrop:I,portalToBody:L}){let R=o(null),z=o(null),B=o(null),{showTooltip:V,hideTooltip:H}=p(R,r(()=>({...F,title:v??F?.title??``,placement:P??`bottom`,fallbackPlacements:[P??`bottom`],trigger:`manual`}),[v,F,P])),[U,W]=a(!1),[G,K]=a(!1),q=!L||U||G||!!O,J=o(null);e(()=>{if(!z.current)return;let e=s.getOrCreateInstance(z.current,j);J.current=e,N&&(N.current=e),L&&B.current&&(e._menu=B.current);let t;return B.current&&(t=new ResizeObserver(()=>e.update()),t.observe(B.current)),()=>t?.disconnect()},[q]),i(()=>(O&&(J.current?.show(),W(!0)),()=>{J.current?.dispose(),J.current=null}),[]);let Y=n(()=>{W(!0),k?.(),H(),I&&c()&&document.getElementById(`context-menu-cover`)?.classList.add(`show`,`global-menu-cover`)},[H,I]),X=n(()=>{W(!1),K(!1),A?.(),I&&c()&&document.getElementById(`context-menu-cover`)?.classList.remove(`show`,`global-menu-cover`)},[I]);i(()=>{if(!(!L||!U))return m()},[L,U]),i(()=>{if(!R.current)return;S&&(S.current=R.current);let e=$(R.current);return e.on(`show.bs.dropdown`,e=>{e.stopPropagation(),Y()}),e.on(`hide.bs.dropdown`,e=>{e.stopPropagation(),X()}),()=>{e.off(`show.bs.dropdown`,Y),e.off(`hide.bs.dropdown`,X)}},[Y,X]);let Z=f(`button`),Q=d(`ul`,{class:`dropdown-menu tn-dropdown-menu ${g?`static`:``} ${x??``} ${D?``:`tn-dropdown-list`}`,style:b,"aria-labelledby":Z,ref:B,onClick:e=>{e.target===B.current&&e.stopPropagation()},children:U&&_});return d(`div`,{ref:R,class:`dropdown ${l??``}`,style:{display:`flex`},title:v,children:[d(`button`,{className:`${w?`icon-action`:`btn`} ${E?``:`select-button`} ${h??``} ${C?``:`dropdown-toggle`}`,ref:z,type:`button`,"data-bs-toggle":`dropdown`,"data-bs-display":g?`static`:void 0,"aria-haspopup":`true`,"aria-expanded":`false`,id:t??Z,disabled:T,onMouseEnter:V,onMouseLeave:H,onPointerDown:L?()=>K(!0):void 0,onFocus:L?()=>K(!0):void 0,onBlur:L?()=>{U||K(!1)}:void 0,...M,children:[y,d(`span`,{className:`caret`})]}),L?q&&u(d(`div`,{class:l??``,children:Q}),document.body):Q]})}export{h as t};