Liferay.Loader.define("data-engine-js-components-web@1.0.107/js/custom/form-report/components/sidebar/SidebarContext",["module","exports","require","liferay!frontend-js-react-web$react","../../hooks/useOnClickOutside"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.SidebarContextProvider=t.SidebarContext=void 0;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 i=n?Object.getOwnPropertyDescriptor(e,o):null;i&&(i.get||i.set)?Object.defineProperty(r,o,i):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),o=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(r("../../hooks/useOnClickOutside"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function ownKeys(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 _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const e=(0,n.createContext)({});t.SidebarContext=e;const SidebarContextProvider=({children:t,dataEngineModule:r,formReportRecordsFieldValuesURL:i,portletNamespace:c})=>{const[a,d]=(0,n.useState)({field:null,isOpen:!1,totalEntries:0,type:null});return(0,n.useEffect)((()=>{const e={},eventHandlerClickOutside=({target:e})=>{a.isOpen&&(0,o.default)(e,"#"+c+"sidebar-reports","#"+c+a.field.name+"-see-more")&&d((()=>({isOpen:!1})))},focusOnLiElement=e=>{const t=document.querySelector("#".concat(c,"_entry_slidebar_").concat(e));t&&t.focus()},eventHandlerKeyUp=({keyCode:t,target:r})=>{const n=(0,o.default)(r,"#"+c+"sidebar-reports"),i=Number(r.getAttribute("index")),s=a.totalEntries-1,u="".concat(c,"close-sidebar"),l=r.id===u,f=9===t||e[9],p=16===t||e[16],b=27===t||e[27];if(a.isOpen)if(n&&f)focusOnLiElement(0);else if(b)d((()=>({isOpen:!1})));else if(!n){if(f&&!p&&i===s){const e=document.querySelector("#".concat(u));e&&e.focus()}f&&p&&l&&focusOnLiElement(s)}delete e[t]},eventHandlerKeyDown=({keyCode:t})=>{e[t]=!0};return window.addEventListener("click",eventHandlerClickOutside),window.addEventListener("keydown",eventHandlerKeyDown),window.addEventListener("keyup",eventHandlerKeyUp),()=>{window.removeEventListener("click",eventHandlerClickOutside),window.removeEventListener("keydown",eventHandlerKeyDown),window.removeEventListener("keyup",eventHandlerKeyUp)}})),n.default.createElement(e.Provider,{value:_objectSpread(_objectSpread({},a),{},{dataEngineModule:r,formReportRecordsFieldValuesURL:i,portletNamespace:c,toggleSidebar:(e,t,r,n)=>{const o=void 0!==e;d(o?()=>({field:e,isOpen:o,summary:t,totalEntries:r,type:n}):()=>_objectSpread(_objectSpread({},a),{},{isOpen:o}))}})},t)};t.SidebarContextProvider=SidebarContextProvider}}));
//# sourceMappingURL=SidebarContext.js.map