Liferay.Loader.define("@liferay/analytics-settings-web@5.0.51/js/components/table/Context",["module","exports","require","liferay!frontend-js-react-web$react","../../utils/filter","../../utils/pagination","./utils"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.useDispatch=t.useData=t.Events=void 0;var a=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={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var n=a?Object.getOwnPropertyDescriptor(e,o):null;n&&(n.get||n.set)?Object.defineProperty(r,o,n):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),o=r("../../utils/filter"),n=r("../../utils/pagination"),c=r("./utils");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 a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}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}let e;t.Events=e,function(e){e.ChangeFilter="CHANGE_FILTER",e.ChangeItem="CHANGE_ITEM",e.ChangeItems="CHANGE_ITEMS",e.ChangeKeywords="CHANGE_KEYWORDS",e.ChangePagination="CHANGE_PAGINATION",e.FormatData="FORMAT_DATA",e.Reload="RELOAD",e.ToggleGlobalCheckbox="TOGGLE_CHECKBOX"}(e||(t.Events=e={}));const d={filter:o.DEFAULT_FILTER,formattedItems:{},globalChecked:!1,internalKeywords:"",keywords:"",pagination:n.DEFAULT_PAGINATION,reload:()=>{},rows:[]},i=(0,a.createContext)(d),l=(0,a.createContext)(null),useData=()=>(0,a.useContext)(i);t.useData=useData;const useDispatch=()=>(0,a.useContext)(l);function reducer(t,r){switch(r.type){case e.ChangeFilter:return _objectSpread(_objectSpread({},t),{},{filter:_objectSpread(_objectSpread({},t.filter),r.payload)});case e.ChangeItem:{const{columns:e,id:a}=r.payload,o=[...t.formattedItems[a].columns];return e.forEach((({column:e,index:t})=>{o[t]=_objectSpread(_objectSpread({},o[t]),e)})),_objectSpread(_objectSpread({},t),{},{formattedItems:_objectSpread(_objectSpread({},t.formattedItems),{},{[a]:_objectSpread(_objectSpread({},t.formattedItems[a]),{},{columns:o})})})}case e.ChangeItems:{const{formattedItems:e,rows:a}=t,o=_objectSpread(_objectSpread({},e),{},{[r.payload]:_objectSpread(_objectSpread({},e[r.payload]),{},{checked:!e[r.payload].checked})});return _objectSpread(_objectSpread({},t),{},{formattedItems:o,globalChecked:(0,c.getGlobalChecked)((0,c.selectFormattedItems)(o,a))})}case e.ChangeKeywords:return _objectSpread(_objectSpread({},t),{},{keywords:r.payload,pagination:_objectSpread(_objectSpread({},t.pagination),{},{page:1})});case e.FormatData:{const{formattedItems:e,pagination:a}=t,{items:o,page:n,pageSize:d,totalCount:i}=r.payload,l=o.map((({id:e})=>e)),p=_objectSpread(_objectSpread({},(0,c.formattingItems)(o)),e);return _objectSpread(_objectSpread({},t),{},{formattedItems:p,globalChecked:(0,c.getGlobalChecked)((0,c.selectFormattedItems)(p,l)),pagination:{maxCount:a.maxCount||i,page:n,pageSize:d,totalCount:i},rows:l})}case e.ChangePagination:return _objectSpread(_objectSpread({},t),{},{pagination:_objectSpread(_objectSpread({},t.pagination),r.payload)});case e.Reload:return _objectSpread(_objectSpread({},t),{},{reload:r.payload});case e.ToggleGlobalCheckbox:{const{formattedItems:e,rows:r}=t,a=!t.globalChecked;return _objectSpread(_objectSpread({},t),{},{formattedItems:_objectSpread(_objectSpread({},e),(0,c.updateFormattedItems)((0,c.selectFormattedItems)(e,r),a)),globalChecked:a})}default:throw new Error}}t.useDispatch=useDispatch;var _default=({children:e,initialFilter:t,initialKeywords:r,initialPagination:o})=>{const[n,c]=(0,a.useReducer)(reducer,_objectSpread(_objectSpread(_objectSpread(_objectSpread({},d),t&&{filter:t}),r&&{keywords:r}),o&&{pagination:o}));return a.default.createElement(i.Provider,{value:n},a.default.createElement(l.Provider,{value:c},e))};t.default=_default}}));
//# sourceMappingURL=Context.js.map