import _extends from "@babel/runtime/helpers/esm/extends";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
var _class, _IgnoreLayerClickWrapper;
import React from 'react';
import { globalObject } from '@skbkontur/global-object';
import { getRootNode, rootNode } from "../../../lib/rootNode";
import { isInstanceOf } from "../../../lib/isInstanceOf";
import { CommonWrapper } from "../../CommonWrapper";
export var IgnoreLayerClick = /*#__PURE__*/function (_React$Component) {
  function IgnoreLayerClick() {
    return _React$Component.apply(this, arguments) || this;
  }
  _inheritsLoose(IgnoreLayerClick, _React$Component);
  var _proto = IgnoreLayerClick.prototype;
  _proto.render = function render() {
    var child = React.Children.only(this.props.children);
    return this.props.active ? /*#__PURE__*/React.createElement(IgnoreLayerClickWrapper, null, child) : child;
  };
  return IgnoreLayerClick;
}(React.Component);

// NOTE Используется только в команде Контур.Бухгалтерия
var IgnoreLayerClickWrapper = rootNode(_class = (_IgnoreLayerClickWrapper = /*#__PURE__*/function (_React$Component2) {
  function IgnoreLayerClickWrapper() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component2.call.apply(_React$Component2, [this].concat(args)) || this;
    _this.element = null;
    _this.handleMouseDown = function (event) {
      event.stopPropagation();
    };
    return _this;
  }
  _inheritsLoose(IgnoreLayerClickWrapper, _React$Component2);
  var _proto2 = IgnoreLayerClickWrapper.prototype;
  _proto2.componentDidMount = function componentDidMount() {
    var element = getRootNode(this);
    if (isInstanceOf(element, globalObject.Element)) {
      element.addEventListener('mousedown', this.handleMouseDown);
      this.element = element;
    }
  };
  _proto2.componentWillUnmount = function componentWillUnmount() {
    if (this.element) {
      this.element.removeEventListener('mousedown', this.handleMouseDown);
      this.element = null;
    }
  };
  _proto2.render = function render() {
    return /*#__PURE__*/React.createElement(CommonWrapper, _extends({
      rootNodeRef: this.setRootNode
    }, this.props), React.Children.only(this.props.children));
  };
  return IgnoreLayerClickWrapper;
}(React.Component), _IgnoreLayerClickWrapper.__KONTUR_REACT_UI__ = 'IgnoreLayerClick', _IgnoreLayerClickWrapper.displayName = 'IgnoreLayerClick', _IgnoreLayerClickWrapper)) || _class;