"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.Hint = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _react = _interopRequireDefault(require("react"));

var _globalObject = require("@skbkontur/global-object");

var _ThemeContext = require("../../lib/theming/ThemeContext");
var _ThemeFactory = require("../../lib/theming/ThemeFactory");


var _Popup = require("../../internal/Popup");


var _currentEnvironment = require("../../lib/currentEnvironment");

var _CommonWrapper = require("../../internal/CommonWrapper");
var _Emotion = require("../../lib/theming/Emotion");

var _rootNode = require("../../lib/rootNode");

var _createPropsGetter = require("../../lib/createPropsGetter");

var _Hint2 = require("./Hint.styles");var _class, _Hint;

var HINT_BORDER_COLOR = 'transparent';














































/**
 * Всплывающая подсказка `Hint`.
 * По умолчанию отображается при наведении на элемент, но можно задать другие условия отображения.
 *
 * Для подсказки, всплывающей по клику используйте Tooltip.
 */var

Hint = exports.Hint = (0, _rootNode.rootNode)(_class = (_Hint = /*#__PURE__*/function (_React$PureComponent) {function Hint() {var _this;for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}_this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;_this.











    getProps = (0, _createPropsGetter.createPropsGetter)(Hint.defaultProps);_this.

    state = {
      opened: _this.getProps().manual ? !!_this.getProps().opened : false,
      position: _Popup.DUMMY_LOCATION.position
    };_this.






    popupRef = /*#__PURE__*/_react.default.createRef();_this.













































































    getAnchorElement = function () {var _this$popupRef$curren;
      return (_this$popupRef$curren = _this.popupRef.current) == null ? void 0 : _this$popupRef$curren.anchorElement;
    };_this.



















    getPositions = function () {
      return _this.props.allowedPositions;
    };_this.

    handleMouseEnter = function (e) {
      if (!_this.getProps().manual && !_this.timer) {
        _this.timer = _globalObject.globalObject.setTimeout(_this.open, 400);
      }

      if (_this.props.onMouseEnter) {
        _this.props.onMouseEnter(e);
      }
    };_this.

    handleMouseLeave = function (e) {
      if (!_this.getProps().manual && _this.timer) {
        _globalObject.globalObject.clearTimeout(_this.timer);
        _this.timer = null;
        _this.setState({ opened: false });
      }

      if (_this.props.onMouseLeave) {
        _this.props.onMouseLeave(e);
      }
    };_this.

    open = function () {
      _this.setState({ opened: true });
    };return _this;}(0, _inheritsLoose2.default)(Hint, _React$PureComponent);var _proto = Hint.prototype;_proto.getAllowedPositions = function getAllowedPositions() {return this.props.allowedPositions;};_proto.componentDidUpdate = function componentDidUpdate(prevProps) {var _this$getProps = this.getProps(),opened = _this$getProps.opened,manual = _this$getProps.manual;if (!manual) {return;}if (this.timer) {_globalObject.globalObject.clearTimeout(this.timer);this.timer = null;}if (opened !== prevProps.opened) {this.setState({ opened: !!opened });}};_proto.componentWillUnmount = function componentWillUnmount() {if (this.timer) {_globalObject.globalObject.clearTimeout(this.timer);this.timer = null;}};_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Provider, { value: _ThemeFactory.ThemeFactory.create({ popupMargin: theme.hintMargin, popupBorder: theme.hintBorder, popupBorderRadius: theme.hintBorderRadius }, _this2.theme) }, _this2.renderMain());});};_proto.renderMain = function renderMain() {var _this3 = this;var _this$getProps2 = this.getProps(),disableAnimations = _this$getProps2.disableAnimations,useWrapper = _this$getProps2.useWrapper;return /*#__PURE__*/_react.default.createElement(_CommonWrapper.CommonWrapper, (0, _extends2.default)({ rootNodeRef: this.setRootNode }, this.props), /*#__PURE__*/_react.default.createElement(_Popup.Popup, { hasPin: false, opened: this.state.opened, anchorElement: this.props.children, positions: this.getPositions(), pos: this.props.pos, backgroundColor: this.theme.hintBgColor, borderColor: HINT_BORDER_COLOR, onPositionChange: function onPositionChange(position) {return _this3.setState({ position: position });}, disableAnimations: disableAnimations, onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave, useWrapper: useWrapper, ref: this.popupRef, withoutMobile: true }, this.renderContent()));};_proto.renderContent = function renderContent() {var _cx;if (!this.props.text) {return null;}var _this$getProps3 = this.getProps(),maxWidth = _this$getProps3.maxWidth;var centerAlignPositions = ['top', 'top center', 'bottom', 'bottom center'];var className = (0, _Emotion.cx)((_cx = {}, _cx[_Hint2.styles.content(this.theme)] = true, _cx[_Hint2.styles.contentCenter(this.theme)] = centerAlignPositions.includes(this.state.position), _cx));return /*#__PURE__*/_react.default.createElement("div", { className: className, style: { maxWidth: maxWidth } }, this.props.text);};return Hint;}(_react.default.PureComponent), _Hint.__KONTUR_REACT_UI__ = 'Hint', _Hint.displayName = 'Hint', _Hint.defaultProps = { manual: false, opened: false, maxWidth: 200, disableAnimations: _currentEnvironment.isTestEnv, useWrapper: false }, _Hint)) || _class;