"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react"),b=require("../../../../../@radix-ui_primitive@1.1.3/node_modules/@radix-ui/primitive/dist/index.cjs.js"),m=require("../../../../../@radix-ui_react-primitive@2.1.3_@types_react-dom@19.2.3_@types_react@19.2.8__@types_rea_b16411dad6e6f8e2d0d80dbd3d639048/node_modules/@radix-ui/react-primitive/dist/index.cjs.js"),R=require("../../../../../@radix-ui_react-compose-refs@1.1.2_@types_react@19.2.8_react@19.2.3/node_modules/@radix-ui/react-compose-refs/dist/index.cjs.js"),w=require("../../../../../@radix-ui_react-use-callback-ref@1.1.1_@types_react@19.2.8_react@19.2.3/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs.js"),H=require("../../../../../@radix-ui_react-use-escape-keydown@1.1.1_@types_react@19.2.8_react@19.2.3/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs.js"),x=require("react/jsx-runtime");function U(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const i=U(q);var z="DismissableLayer",h="dismissableLayer.update",M="dismissableLayer.pointerDownOutside",$="dismissableLayer.focusOutside",L,T=i.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),S=i.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:c,onInteractOutside:f,onDismiss:d,...v}=e,a=i.useContext(T),[u,I]=i.useState(null),l=u?.ownerDocument??globalThis?.document,[,N]=i.useState({}),W=R.useComposedRefs(t,s=>I(s)),p=Array.from(a.layers),[_]=[...a.layersWithOutsidePointerEventsDisabled].slice(-1),A=p.indexOf(_),D=u?p.indexOf(u):-1,j=a.layersWithOutsidePointerEventsDisabled.size>0,O=D>=A,k=X(s=>{const E=s.target,C=[...a.branches].some(y=>y.contains(E));!O||C||(o?.(s),f?.(s),s.defaultPrevented||d?.())},l),P=Y(s=>{const E=s.target;[...a.branches].some(y=>y.contains(E))||(c?.(s),f?.(s),s.defaultPrevented||d?.())},l);return H.useEscapeKeydown(s=>{D===a.layers.size-1&&(r?.(s),!s.defaultPrevented&&d&&(s.preventDefault(),d()))},l),i.useEffect(()=>{if(u)return n&&(a.layersWithOutsidePointerEventsDisabled.size===0&&(L=l.body.style.pointerEvents,l.body.style.pointerEvents="none"),a.layersWithOutsidePointerEventsDisabled.add(u)),a.layers.add(u),g(),()=>{n&&a.layersWithOutsidePointerEventsDisabled.size===1&&(l.body.style.pointerEvents=L)}},[u,l,n,a]),i.useEffect(()=>()=>{u&&(a.layers.delete(u),a.layersWithOutsidePointerEventsDisabled.delete(u),g())},[u,a]),i.useEffect(()=>{const s=()=>N({});return document.addEventListener(h,s),()=>document.removeEventListener(h,s)},[]),x.jsx(m.Primitive.div,{...v,ref:W,style:{pointerEvents:j?O?"auto":"none":void 0,...e.style},onFocusCapture:b.composeEventHandlers(e.onFocusCapture,P.onFocusCapture),onBlurCapture:b.composeEventHandlers(e.onBlurCapture,P.onBlurCapture),onPointerDownCapture:b.composeEventHandlers(e.onPointerDownCapture,k.onPointerDownCapture)})});S.displayName=z;var K="DismissableLayerBranch",B=i.forwardRef((e,t)=>{const n=i.useContext(T),r=i.useRef(null),o=R.useComposedRefs(t,r);return i.useEffect(()=>{const c=r.current;if(c)return n.branches.add(c),()=>{n.branches.delete(c)}},[n.branches]),x.jsx(m.Primitive.div,{...e,ref:o})});B.displayName=K;function X(e,t=globalThis?.document){const n=w.useCallbackRef(e),r=i.useRef(!1),o=i.useRef(()=>{});return i.useEffect(()=>{const c=d=>{if(d.target&&!r.current){let v=function(){F(M,n,a,{discrete:!0})};const a={originalEvent:d};d.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=v,t.addEventListener("click",o.current,{once:!0})):v()}else t.removeEventListener("click",o.current);r.current=!1},f=window.setTimeout(()=>{t.addEventListener("pointerdown",c)},0);return()=>{window.clearTimeout(f),t.removeEventListener("pointerdown",c),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Y(e,t=globalThis?.document){const n=w.useCallbackRef(e),r=i.useRef(!1);return i.useEffect(()=>{const o=c=>{c.target&&!r.current&&F($,n,{originalEvent:c},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function g(){const e=new CustomEvent(h);document.dispatchEvent(e)}function F(e,t,n,{discrete:r}){const o=n.originalEvent.target,c=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?m.dispatchDiscreteCustomEvent(o,c):o.dispatchEvent(c)}exports.DismissableLayer=S;exports.DismissableLayerBranch=B;
//# sourceMappingURL=index.cjs.js.map
