"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSecurityFlyoutUrlSync = exports.SecuritySolutionFlyoutUrlSyncProvider = exports.SecuritySolutionFlyoutCloseContext = void 0; var _react = _interopRequireWildcard(require("react")); var _use_sync_flyout_state_with_url = require("../hooks/url/use_sync_flyout_state_with_url"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ const SecuritySolutionFlyoutCloseContext = /*#__PURE__*/(0, _react.createContext)(undefined); /** * Exposes the flyout close context value (returned from syncUrl) as a hook. */ exports.SecuritySolutionFlyoutCloseContext = SecuritySolutionFlyoutCloseContext; const useSecurityFlyoutUrlSync = () => { const contextValue = (0, _react.useContext)(SecuritySolutionFlyoutCloseContext); if (!contextValue) { throw new Error('useSecurityFlyoutUrlSync can only be used inside respective provider'); } return contextValue; }; /** * Provides urlSync hook return value as a context value, for reuse in other components. * Main goal here is to avoid calling useSyncFlyoutStateWithUrl multiple times. */ exports.useSecurityFlyoutUrlSync = useSecurityFlyoutUrlSync; const SecuritySolutionFlyoutUrlSyncProvider = ({ children }) => { const [flyoutRef, handleFlyoutChangedOrClosed] = (0, _use_sync_flyout_state_with_url.useSyncFlyoutStateWithUrl)(); const value = (0, _react.useMemo)(() => [flyoutRef, handleFlyoutChangedOrClosed], [flyoutRef, handleFlyoutChangedOrClosed]); return /*#__PURE__*/_react.default.createElement(SecuritySolutionFlyoutCloseContext.Provider, { value: value }, children); }; exports.SecuritySolutionFlyoutUrlSyncProvider = SecuritySolutionFlyoutUrlSyncProvider;