import{a as e}from"./chunk-Cyuzqnbw.js";import{i as t}from"./bundle-mjs-DssaXR6m.js";import{B as n,d as r,j as i,m as a,u as o,z as s}from"./api-DTaM-PBA.js";var c=e(t()),l=c.createContext(void 0);function u(e=!1){let t=c.useContext(l);if(t===void 0&&!e)throw Error(s(16));return t}function d(e){let{focusableWhenDisabled:t,disabled:n,composite:r=!1,tabIndex:i=0,isNativeButton:a}=e,o=r&&t!==!1,s=r&&t===!1;return{props:c.useMemo(()=>{let e={onKeyDown(e){n&&t&&e.key!==`Tab`&&e.preventDefault()}};return r||(e.tabIndex=i,!a&&n&&(e.tabIndex=t?i:-1)),(a&&(t||o)||!a&&n)&&(e[`aria-disabled`]=n),a&&(!t||s)&&(e.disabled=n),e},[r,n,t,o,s,a,i])}}function f(e={}){let{disabled:t=!1,focusableWhenDisabled:i,tabIndex:s=0,native:l=!0,composite:f}=e,h=c.useRef(null),g=u(!0),_=f??g!==void 0,{props:v}=d({focusableWhenDisabled:i,disabled:t,composite:_,tabIndex:s,isNativeButton:l}),y=c.useCallback(()=>{let e=h.current;p(e)&&_&&t&&v.disabled===void 0&&e.disabled&&(e.disabled=!1)},[t,v.disabled,_]);return n(y,[y]),{getButtonProps:c.useCallback((e={})=>{let{onClick:n,onMouseDown:i,onKeyUp:a,onKeyDown:s,onPointerDown:c,...u}=e;return r({onClick(e){if(t){e.preventDefault();return}n?.(e)},onMouseDown(e){t||i?.(e)},onKeyDown(e){if(t||(o(e),s?.(e),e.baseUIHandlerPrevented))return;let r=e.target===e.currentTarget,i=e.currentTarget,a=p(i),c=!l&&m(i),u=r&&(l?a:!c),d=e.key===`Enter`,f=e.key===` `,h=i.getAttribute(`role`),g=h?.startsWith(`menuitem`)||h===`option`||h===`gridcell`;if(r&&_&&f){if(e.defaultPrevented&&g)return;e.preventDefault(),c||l&&a?(i.click(),e.preventBaseUIHandler()):u&&(n?.(e),e.preventBaseUIHandler());return}u&&(!l&&(f||d)&&e.preventDefault(),!l&&d&&n?.(e))},onKeyUp(e){if(!t){if(o(e),a?.(e),e.target===e.currentTarget&&l&&_&&p(e.currentTarget)&&e.key===` `){e.preventDefault();return}e.baseUIHandlerPrevented||e.target===e.currentTarget&&!l&&!_&&e.key===` `&&n?.(e)}},onPointerDown(e){if(t){e.preventDefault();return}c?.(e)}},l?{type:`button`}:{role:`button`},v,u)},[t,v,_,l]),buttonRef:a(e=>{h.current=e,y()})}}function p(e){return i(e)&&e.tagName===`BUTTON`}function m(e){return!!(e?.tagName===`A`&&e?.href)}export{l as n,u as r,f as t};