function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/*
Copyright (c) 2018-2019 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { styled } from '../styles/index.js';
import { getOverrides } from '../helpers/overrides.js';
const StyledAppContainer = styled('div', {});
StyledAppContainer.displayName = "StyledAppContainer";
const StyledLayersContainer = styled('div', {});
StyledLayersContainer.displayName = "StyledLayersContainer";
export const {
  Provider,
  Consumer
} = React.createContext({});
export default class LayersManager extends React.Component {
  constructor(...args) {
    super(...args);

    _defineProperty(this, "host", React.createRef());
  }

  componentDidMount() {
    this.forceUpdate();
  }

  render() {
    const {
      overrides = {}
    } = this.props;
    const [AppContainer, appContainerProps] = getOverrides(overrides.AppContainer, StyledAppContainer);
    const [LayersContainer, layersContainerProps] = getOverrides(overrides.LayersContainer, StyledLayersContainer);
    return React.createElement(Consumer, null, ({
      host
    }) => {
      if (process.env.NODE_ENV !== "production") {
        if (host !== undefined) {
          // eslint-disable-next-line no-console
          console.warn('There is a LayersManager already exists in your application. It is not recommended to have more than one LayersManager in an application.');
        }
      }

      return React.createElement(Provider, {
        value: {
          host: host || this.host.current,
          zIndex: this.props.zIndex
        }
      }, React.createElement(AppContainer, appContainerProps, this.props.children), React.createElement(LayersContainer, _extends({}, layersContainerProps, {
        ref: this.host
      })));
    });
  }

}