"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index42.css');const a=require("react/jsx-runtime"),g=require("../../classix-5H4IWnMA.cjs"),o=require("react"),R=require("../button/index.cjs"),x="_popover_ttn4t_1",F="_left_ttn4t_23",P="_right_ttn4t_28",b="_trigger_ttn4t_33",s={popover:x,"popover-panel":"_popover-panel_ttn4t_6",left:F,right:P,trigger:b},j=({children:i,position:_="left",triggerAccessibleLabel:m,triggerAriaHasPopup:y,triggerButtonContent:w})=>{const u=o.useRef(null),l=o.useRef(void 0),p=o.useId(),f=o.useRef(null),[t,d]=o.useState(!1),c=({initialFocus:e}={})=>{l.current=e,d(!0)},n=o.useCallback(({restoreFocus:e=!0}={})=>{var r;d(!1),e&&((r=f.current)==null||r.focus())},[]),h=e=>{t&&e.key==="Escape"&&n()},D=e=>{if(!t){if(e.key==="ArrowDown"){e.preventDefault(),c({initialFocus:"first"});return}e.key==="ArrowUp"&&(e.preventDefault(),c({initialFocus:"last"}))}};return o.useEffect(()=>{if(!t)return;const e=r=>{var v;(v=u.current)!=null&&v.contains(r.target)||n({restoreFocus:!1})};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[n,t]),a.jsxs("div",{className:s.popover,onKeyDown:h,ref:u,"data-component":"popover",children:[a.jsx(R.Button,{"aria-controls":t?p:void 0,"aria-expanded":t,"aria-haspopup":y,"aria-label":m,className:g.t(s.trigger),onKeyDown:D,onClick:()=>t?n({restoreFocus:!1}):c(),ref:f,variant:"minimal",children:w}),t&&a.jsx("div",{className:g.t(s["popover-panel"],s[_]),id:p,children:typeof i=="function"?i({close:n,initialFocus:l.current,isOpen:t}):i})]})};exports.Popover=j;
//# sourceMappingURL=index.cjs.map
