import e from"react";function t(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?r(Object(o),!0).forEach(function(r){t(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):r(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}var o={"Ctrl/Cmd+K":!0,"/":!0};function i(t){var r,i=t.isOpen,c=t.onOpen,a=t.onClose,u=t.isAskAiActive,s=t.onAskAiToggle,f=t.keyboardShortcuts,p=(r=f,n(n({},o),r));e.useEffect(function(){function e(e){var t;if(i&&"Escape"===e.code&&u)s(!1);else{var r=p["Ctrl/Cmd+K"]&&"k"===(null===(t=e.key)||void 0===t?void 0:t.toLowerCase())&&(e.metaKey||e.ctrlKey),n=p["/"]&&"/"===e.key;("Escape"===e.code&&i||r||!function(e){var t=e.composedPath()[0],r=t.tagName;return t.isContentEditable||"INPUT"===r||"SELECT"===r||"TEXTAREA"===r}(e)&&n&&!i)&&(e.preventDefault(),i?a():document.body.classList.contains("DocSearch--active")||c())}}return window.addEventListener("keydown",e),function(){window.removeEventListener("keydown",e)}},[i,c,a,u,s,p])}export{i as useDocSearchKeyboardEvents};
