Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.169/page_editor/plugins/fragments_and_widgets/hooks/useKeyboardNavigation",["module","exports","require","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$react","../../../app/config/constants/keyboardCodes","../../../app/config/constants/listItemTypes"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function useKeyboardNavigation({handleOpen:t,type:n}){var r,u;const[c,a]=(0,i.useState)(null),[_,f]=(0,i.useState)(!1),E="rtl"===(null===(r=Liferay.Language.direction)||void 0===r?void 0:r[null===(u=themeDisplay)||void 0===u?void 0:u.getLanguageId()]);return(0,i.useEffect)((()=>{const e=null==c?void 0:c.closest('[role="menubar"]'),t=(null==c?void 0:c.closest("li"))===(null==e?void 0:e.firstChild);f(t)}),[c]),(0,o.useEventListener)("keydown",(o=>{const{code:i}=o;if(!e.includes(i))return;let r=i;E&&i===l.ARROW_RIGHT_KEY_CODE&&(r=l.ARROW_LEFT_KEY_CODE),E&&i===l.ARROW_LEFT_KEY_CODE&&(r=l.ARROW_RIGHT_KEY_CODE),o.preventDefault(),n===s.LIST_ITEM_TYPES.header?function onHeaderKeyDown(e,t,n){if(t===l.ARROW_DOWN_KEY_CODE){const t=e.nextSibling,n=null==t?void 0:t.querySelector("li");if(n)n.focus();else{const t=e.parentElement.nextSibling,n=null==t?void 0:t.querySelector("button");null==n||n.focus()}}else if(t===l.ARROW_UP_KEY_CODE){const t=e.parentElement.previousSibling;if(!t)return;const n=t.querySelector("ul");if(n){n.lastChild.focus()}else{t.querySelector("button").focus()}}else t===l.ARROW_RIGHT_KEY_CODE?n(!0):t===l.ARROW_LEFT_KEY_CODE&&n(!1)}(c,r,t):n===s.LIST_ITEM_TYPES.listItem&&function onListItemKeyDown(e,t){if(t===l.ARROW_UP_KEY_CODE)if(e.previousSibling)e.previousSibling.focus();else{e.closest(".page-editor__collapse").querySelector("button").focus()}else if(t===l.ARROW_DOWN_KEY_CODE)if(e.nextSibling)e.nextSibling.focus();else{const t=e.closest(".page-editor__collapse").nextSibling,n=null==t?void 0:t.querySelector("button");null==n||n.focus()}else if(t===l.ARROW_RIGHT_KEY_CODE)if(document.activeElement===e){e.querySelector("button").focus()}else{const e=document.activeElement.nextSibling;null==e||e.focus()}else if(t===l.ARROW_LEFT_KEY_CODE){const t=document.activeElement.previousSibling;"BUTTON"===(null==t?void 0:t.tagName)?t.focus():e.focus()}}(c,r)}),!0,c),(0,o.useEventListener)("focus",(()=>f(!0)),!0,c),(0,o.useEventListener)("blur",(e=>{const t=e.target.closest('[role="menubar"]'),n=e.relatedTarget;t.contains(n)&&f(!1)}),!0,c),{isTarget:_,setElement:a}};var o=n("@liferay/frontend-js-react-web"),i=n("liferay!frontend-js-react-web$react"),l=n("../../../app/config/constants/keyboardCodes"),s=n("../../../app/config/constants/listItemTypes");const e=[l.ARROW_DOWN_KEY_CODE,l.ARROW_LEFT_KEY_CODE,l.ARROW_RIGHT_KEY_CODE,l.ARROW_UP_KEY_CODE]}}));
//# sourceMappingURL=useKeyboardNavigation.js.map