Liferay.Loader.define("data-engine-js-components-web@1.0.89/js/core/components/AutoFocus.es",["module","exports","require","liferay!frontend-js-react-web$react","../hooks/usePage.es"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.AutoFocus=function AutoFocus({children:e}){const t=(0,n.useRef)(),{activePage:r,containerElement:l}=(0,o.usePage)(),[u,i]=(0,n.useState)(0);return(0,n.useLayoutEffect)((()=>{if(t.current&&(null==l?void 0:l.current))if(t.current.querySelector(".loading-animation"))setTimeout((()=>i((e=>e+1))),5);else if(!document.activeElement||!Liferay.ThemeDisplay.isControlPanel()&&document.activeElement.querySelector("input")&&"hidden"===document.activeElement.querySelector("input").type||(null==l?void 0:l.current.parentNode.className.includes("ddm-form-builder-app"))){!function removeTabs(){const e=document.querySelector('div[class^="lfr-layout-structure-item');var t;(null==e?void 0:e.querySelector(".portlet-forms"))||null===(t=document.querySelectorAll(".lfr-ddm__default-page-header-title,.lfr-ddm__default-page-header-description,.lfr-ddm-form-page-title,.lfr-ddm-form-page-description"))||void 0===t||t.forEach((e=>e.removeAttribute("tabindex")))}();const e=null==l?void 0:l.current.parentNode.getElementsByClassName("lfr-ddm__default-page-header-title")[0];scrollComponentToTop(e);const t=null==e?void 0:e.innerHTML,r=null==l?void 0:l.current.parentNode.getElementsByClassName(".lfr-ddm__default-page-header-description")[0],n=null==r?void 0:r.innerHTML,o=document.activeElement.querySelector(".ddm-layout-builder:not(.hide)"),u=null==o?void 0:o.querySelector('input:not([type="hidden"])'),i=document.querySelector(".ddm-form-builder--sidebar-open"),c=l.current.querySelector(".ddm-user-view-content"),d=Liferay.Language.get("untitled-form");t&&t!==d||n||!u||l.current.contains(document.activeElement)||!i&&!c||(u.focus({behavior:"smooth",preventScroll:!1}),u.select&&u.select()),scrollComponentToTop(e)}}),[r,t,l,u]),n.default.cloneElement(e,{ref:e=>{t.current=e}})};var n=function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var l=n?Object.getOwnPropertyDescriptor(e,o):null;l&&(l.get||l.set)?Object.defineProperty(r,o,l):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),o=r("../hooks/usePage.es");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function scrollComponentToTop(e){if(e){var t;const r=e.getBoundingClientRect(),n=null===(t=document.querySelector(".control-menu-container"))||void 0===t?void 0:t.clientHeight;window.scroll(r.x-n,r.y-n)}}}}));
//# sourceMappingURL=AutoFocus.es.js.map