"use strict";const o=require("react/jsx-runtime"),u=require("../vendor.cjs"),t=require("react"),i=require("../tools/tools.cjs"),F=require("./dropdown-divider.cjs"),H=require("./dropdown-header.cjs"),B=require("./dropdown-item-text.cjs"),M=require("./dropdown-item.cjs"),A=require("./dropdown-menu.cjs"),D=require("./dropdown-toggle.cjs"),d=function(K){const{as:V="div",autoClose:x=!0,btnGroup:I,buttonProps:k,center:y,children:z,className:q,customMenu:p,dropend:v,dropOldClass:E,dropstart:a,dropup:C,dropupCenter:T,menuProps:l,offset:G,options:U,split:f,strategy:J="absolute",style:R,toggle:j,toggleProps:s,variables:N,visible:b,...Q}=K,W=(U??[]).map((e,r)=>({...e,id:e.id??r})),[X]=t.useState(W),[n,w]=t.useState(b??!1),g=t.useRef(i.generateRandomId()),[O,S]=t.useState(),[_,L]=t.useState(!1),{floatingStyles:Y,refs:h}=u.useFloating({middleware:[u.offset(()=>G??0,[n]),u.shift(e=>e,[n]),u.flip(e=>e,[n]),u.size(e=>e,[n])],onOpenChange:w,open:n,placement:i.findTruthyClassOrDefault([["bottom",y],["bottom-end",O==="end"],["bottom-start",O==="start"],["left-start",a],["right-start",v],["top",T],["top-start",C]],"bottom-start"),strategy:J,whileElementsMounted:u.autoUpdate}),Z=t.useMemo(()=>{const e=i.classx(!E&&i.findTruthyClass(["btn-group",f||I],["dropdown-center",y],["dropup-center",T],["dropdown",!0]),C&&"dropup",v&&"dropend",a&&"dropstart",q),r=i.stylex((c,ee)=>({tKey:i.convertBsKeyToVar(ee)}),N,R);return{className:e,style:r}},[I,y,q,E,v,a,C,T,f,R,N]),m=t.useCallback(e=>{var r;w(typeof e=="boolean"?e:e?!n:!1),(r=s==null?void 0:s.onClick)==null||r.call(s,e)},[n,s==null?void 0:s.onClick]),$=t.useCallback(()=>{p&&L(!0)},[p]),P=t.useCallback(()=>{p&&L(!1)},[p]);return t.useEffect(()=>{typeof b=="boolean"&&w(b)},[b]),t.useEffect(()=>{if(!x||_)return;const e=r=>{const c=r.target;if(c.className.includes("dropdown")){if(x==="outside")return;c.dataset.toggleId!==g.current&&m()}else x!=="inside"&&m()};return document.body.addEventListener("click",e),()=>document.body.removeEventListener("click",e)},[x,_,m]),t.useEffect(()=>{var r;if(!l||!((r=l.className)!=null&&r.includes("dropdown-menu-")))return;const e=h.floating.current;if(e){const c=getComputedStyle(e).getPropertyValue("--bs-position");S(c||!1)}},[l,h.floating]),o.jsxs(V,{...Q,...Z,children:[f?o.jsxs(o.Fragment,{children:[!(f&&a)&&o.jsx(D.DropdownToggle,{dropOldClass:!0,...k,children:j}),o.jsx(D.DropdownToggle,{"aria-expanded":n?"true":"false",className:"dropdown-toggle-split",show:n,...s,"data-toggle-id":g.current,onClick:m,onRef:h.setReference,children:o.jsx("span",{className:"visually-hidden",children:"Toggle Dropdown"})})]}):o.jsxs(D.DropdownToggle,{"aria-expanded":n?"true":"false",show:n,...s,"data-toggle-id":g.current,onClick:m,onRef:h.setReference,children:[a&&o.jsx("span",{className:"dropdown-nbsp","data-toggle-id":g.current,children:" "}),j,!a&&o.jsx("span",{className:"dropdown-nbsp","data-toggle-id":g.current,children:" "})]}),o.jsx(A.DropdownMenu,{...i.mergeProps(l,{style:{...l==null?void 0:l.style,...Y}}),onMouseEnter:$,onMouseLeave:P,onRef:h.setFloating,show:n,children:p?z:o.jsx(o.Fragment,{children:X.map(e=>e.header?o.jsx(H.DropdownHeader,{children:e.header},e.id):e.itemText?o.jsx(B.DropdownItemText,{children:e.itemText},e.id):e.divider?o.jsx(F.DropdownDivider,{},e.id):e.as==="a"?o.jsx(M.DropdownItem,{active:e.active,as:"a",disabled:e.disabled,href:e.href,children:e.item},e.id):o.jsx(M.DropdownItem,{active:e.active,as:"button",disabled:e.disabled,children:e.item},e.id))})}),f&&a&&o.jsx(D.DropdownToggle,{dropOldClass:!0,...k,children:j})]})};d.Toggle=D.DropdownToggle;d.Item=M.DropdownItem;d.ItemText=B.DropdownItemText;d.Menu=A.DropdownMenu;d.Divider=F.DropdownDivider;d.Header=H.DropdownHeader;d.displayName="BRL.Dropdown";exports.Dropdown=d;
//# sourceMappingURL=dropdown.cjs.map
