Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.132/page_editor/app/contexts/ControlsContext",["module","exports","require","liferay!frontend-js-react-web$react","../components/layout-data-items/Collection","../config/constants/itemActivationOrigins","../config/constants/itemTypes","../thunks/switchSidebarPanel","./CollectionItemContext","./StoreContext"],(function(e,t,r){var n;window;{Object.defineProperty(t,"__esModule",{value:!0}),t.useSelectItem=t.useIsHovered=t.useIsActive=t.useHoverItem=t.useHoveringOrigin=t.useHoveredItemType=t.useHoveredItemId=t.useActiveItemType=t.useActiveItemId=t.useActivationOrigin=t.reducer=t.ControlsProvider=void 0;var o=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=d();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")),i=r("../components/layout-data-items/Collection"),a=r("../config/constants/itemActivationOrigins"),c=r("../config/constants/itemTypes"),s=(n=r("../thunks/switchSidebarPanel"))&&n.__esModule?n:{default:n},u=r("./CollectionItemContext"),l=r("./StoreContext");function d(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return d=function(){return e},e}function I(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 v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?I(Object(r),!0).forEach((function(t){m(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function m(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={activationOrigin:null,activeItemId:null,activeItemType:null},p={hoveredItemId:null},f="HOVER_ITEM",y="SELECT_ITEM",O=o.default.createContext(e),b=o.default.createContext((()=>{})),g=o.default.createContext(p),C=o.default.createContext((()=>{})),T=(e,t)=>{const{itemId:r,itemType:n,origin:o,type:i}=t;let a=e;return i===f&&r!==a.hoveredItemId?a=v(v({},a),{},{activationOrigin:o,hoveredItemId:r,hoveredItemType:n}):i===y&&r!==a.activeItemId&&(a=v(v({},a),{},{activationOrigin:o,activeItemId:r,activeItemType:n})),a};t.reducer=T;const P=({children:e,initialState:t})=>{const[r,n]=(0,o.useReducer)(T,t);return o.default.createElement(b.Provider,{value:n},o.default.createElement(O.Provider,{value:r},e))},E=({children:e,initialState:t})=>{const[r,n]=(0,o.useReducer)(T,t);return o.default.createElement(C.Provider,{value:n},o.default.createElement(g.Provider,{value:r},e))},h=({activeInitialState:t=e,hoverInitialState:r=p,children:n})=>o.default.createElement(P,{initialState:t},o.default.createElement(E,{initialState:r},n));t.ControlsProvider=h;const S=()=>(0,o.useContext)(O).activationOrigin;t.useActivationOrigin=S;const j=()=>(0,i.fromControlsId)((0,o.useContext)(O).activeItemId);t.useActiveItemId=j;const x=()=>(0,o.useContext)(O).activeItemType;t.useActiveItemType=x;const w=()=>(0,i.fromControlsId)((0,o.useContext)(g).hoveredItemId);t.useHoveredItemId=w;const _=()=>(0,o.useContext)(g).hoveredItemType;t.useHoveredItemType=_;const A=()=>(0,o.useContext)(g).activationOrigin;t.useHoveringOrigin=A;const M=()=>{const e=(0,o.useContext)(C),t=(0,u.useToControlsId)();return(0,o.useCallback)(((r,{itemType:n=c.ITEM_TYPES.layoutDataItem,origin:o=a.ITEM_ACTIVATION_ORIGINS.pageEditor}={itemType:c.ITEM_TYPES.layoutDataItem})=>e({itemId:t(r),itemType:n,origin:o,type:f})),[e,t])};t.useHoverItem=M;const D=()=>{const{activeItemId:e}=(0,o.useContext)(O),t=(0,u.useToControlsId)();return(0,o.useCallback)((r=>e===t(r)),[e,t])};t.useIsActive=D;const H=()=>{const{hoveredItemId:e}=(0,o.useContext)(g),t=(0,u.useToControlsId)();return(0,o.useCallback)((r=>e===t(r)),[e,t])};t.useIsHovered=H;const k=()=>{const e=(0,o.useContext)(b),t=(0,l.useSelector)((e=>{var t,r;return(null===(t=e.sidebar)||void 0===t?void 0:t.open)?null===(r=e.sidebar)||void 0===r?void 0:r.panelId:null})),r=(0,l.useDispatch)(),n=(0,u.useToControlsId)();return(0,o.useCallback)(((o,{itemType:i=c.ITEM_TYPES.layoutDataItem,origin:u=a.ITEM_ACTIVATION_ORIGINS.pageEditor}={itemType:c.ITEM_TYPES.layoutDataItem})=>{e({itemId:n(o),itemType:i,origin:u,type:y}),o&&t&&!["browser","comments","page-content"].includes(t)&&r((0,s.default)({sidebarOpen:!0,sidebarPanelId:"browser"}))}),[e,t,r,n])};t.useSelectItem=k}}));
//# sourceMappingURL=ControlsContext.js.map