"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/esnext.weak-map.delete-all.js");
require("core-js/modules/esnext.weak-map.emplace.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FrcTooltipButton = void 0;
require("core-js/modules/es.array.concat.js");
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _icon = require("../icon");
var _type = require("../icon/type");
var _popover = require("../popover");
var _tooltip = require("../tooltip");
require("./tooltip-button.css");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var FrcTooltipButton = exports.FrcTooltipButton = function FrcTooltipButton(props) {
  var active = props.active,
    withPopover = props.withPopover,
    classNames = props.classNames,
    _props$tooltip = props.tooltip,
    tooltipIcon = _props$tooltip.icon,
    _props$tooltip$trigge = _props$tooltip.trigger,
    tooltipTrigger = _props$tooltip$trigge === void 0 ? 'hover' : _props$tooltip$trigge,
    _props$tooltip$placem = _props$tooltip.placement,
    tooltipPlacement = _props$tooltip$placem === void 0 ? 'top' : _props$tooltip$placem,
    tooltipContent = _props$tooltip.content,
    _props$popover = props.popover,
    _props$popover2 = _props$popover === void 0 ? {} : _props$popover,
    popoverIcon = _props$popover2.icon,
    _props$popover2$trigg = _props$popover2.trigger,
    popoverTrigger = _props$popover2$trigg === void 0 ? 'click' : _props$popover2$trigg,
    _props$popover2$place = _props$popover2.placement,
    popoverPlacement = _props$popover2$place === void 0 ? 'top' : _props$popover2$place,
    popoverContent = _props$popover2.content,
    onVisibleChange = _props$popover2.onVisibleChange,
    _props$popover2$visib = _props$popover2.visible,
    visible = _props$popover2$visib === void 0 ? false : _props$popover2$visib,
    _props$onTooltipButto = props.onTooltipButtonClick,
    onTooltipButtonClick = _props$onTooltipButto === void 0 ? function () {} : _props$onTooltipButto,
    children = props.children;
  var _React$useState = _react["default"].useState(visible),
    _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
    popoverVisible = _React$useState2[0],
    setVisible = _React$useState2[1];
  var handlerVisibleChange = function handlerVisibleChange(visible) {
    setVisible(visible);
    onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(visible);
  };
  (0, _react.useEffect)(function () {
    setVisible(visible);
  }, [visible]);
  (0, _react.useEffect)(function () {
    function handleBlur(event) {
      setVisible(false);
    }
    window.addEventListener('blur', handleBlur);
    return function () {
      window.removeEventListener('blur', handleBlur);
    };
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "frc-tooltip-button ".concat(classNames === null || classNames === void 0 ? void 0 : classNames.container, " ").concat(active ? 'frc-tooltip-button--active' : ''),
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.FcrToolTip, {
      content: tooltipContent,
      trigger: tooltipTrigger,
      placement: tooltipPlacement,
      overlayInnerStyle: {
        border: 0,
        boxShadow: '0px 0px 15px var(--fcr_web_light_dropup_m)',
        borderRadius: 'var(--fcr_cornerradius_l)',
        padding: 10
      },
      mouseEnterDelay: 0,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: "tooltip-button ".concat(withPopover ? '' : 'tooltip-single-button'),
        onClick: onTooltipButtonClick,
        children: [(tooltipIcon === null || tooltipIcon === void 0 ? void 0 : tooltipIcon.type) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
          type: tooltipIcon.type,
          size: tooltipIcon.size,
          colors: tooltipIcon.colors
        }), children]
      })
    }), withPopover && /*#__PURE__*/(0, _jsxRuntime.jsx)(_popover.FcrPopover, {
      trigger: popoverTrigger,
      overlayClassName: "frc-tooltip-button__popover ".concat(classNames === null || classNames === void 0 ? void 0 : classNames.container),
      placement: popoverPlacement,
      mouseEnterDelay: 0,
      onVisibleChange: handlerVisibleChange,
      visible: popoverVisible,
      overlayInnerStyle: {
        border: 0,
        boxShadow: 'none',
        borderRadius: 0
      },
      content: popoverContent,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "popover-button ".concat(active ? 'popover-button--active' : ''),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
          type: _type.FcrIconType.FCR_DROPUP4,
          size: 24,
          colors: {
            iconPrimary: 'var(--fcr_web_ui_scene_mainicon1)'
          }
        })
      })
    })]
  });
};