"use strict";

require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.array.for-each.js");
require("core-js/modules/es.array.push.js");
require("core-js/modules/es.object.define-properties.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.get-own-property-descriptors.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.for-each.js");
require("core-js/modules/web.dom-collections.for-each.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PopoverWithTooltip = exports.FcrPopover = exports.DoubleDeckPopoverWithTooltip = exports.DoubleDeckPopover = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = require("react");
var _tooltip = require("../tooltip");
var _classnames = _interopRequireDefault(require("classnames"));
require("./index.css");
var _icon = require("../icon");
var _type = require("../icon/type");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "overlayClassName", "showArrow", "overlayInnerStyle", "size", "overlayOffset", "afterVisibleChange"],
  _excluded2 = ["children", "bottomDeckContent", "topDeckContent"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var FcrPopover = exports.FcrPopover = function FcrPopover(props) {
  var children = props.children,
    overlayClassName = props.overlayClassName,
    showArrow = props.showArrow,
    overlayInnerStyle = props.overlayInnerStyle,
    _props$size = props.size,
    size = _props$size === void 0 ? 'large' : _props$size,
    _props$overlayOffset = props.overlayOffset,
    overlayOffset = _props$overlayOffset === void 0 ? 6 : _props$overlayOffset,
    afterVisibleChange = props.afterVisibleChange,
    otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
  var defaultLargePopoverOverlayInnerStyle = {
    width: 222,
    padding: 0,
    background: "var(--fcr_mobile_ui_scene_color_popup_fill2)",
    border: "0.5px solid var(--fcr_ui_scene_line1)",
    boxShadow: "var(--fcr_web_light_dropup_m)",
    borderRadius: "var(--fcr_cornerradius_l)",
    overflow: 'hidden'
  };
  var defaultSmallPopoverOverlayInnerStyle = {
    width: 171,
    padding: 0,
    background: "var(--fcr_mobile_ui_scene_color_popup_fill2)",
    border: "0.5px solid var(--fcr_ui_scene_line1)",
    boxShadow: "var(--fcr_web_light_dropup_m)",
    borderRadius: "var(--fcr_cornerradius_m)",
    overflow: 'hidden'
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.FcrToolTip, _objectSpread(_objectSpread({}, otherProps), {}, {
    afterVisibleChange: afterVisibleChange,
    overlayClassName: (0, _classnames["default"])('fcr-popover', overlayClassName),
    showArrow: showArrow,
    arrowContent: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
      type: _type.FcrIconType.FCR_TOOLTIP_ARROW,
      size: 16,
      colors: {
        iconPrimary: 'var(--fcr_ui_scene_white10)'
      }
    }),
    overlayOffset: overlayOffset,
    overlayInnerStyle: _objectSpread(_objectSpread({}, size === 'large' ? defaultLargePopoverOverlayInnerStyle : defaultSmallPopoverOverlayInnerStyle), overlayInnerStyle),
    children: children
  }));
};
var DoubleDeckPopover = exports.DoubleDeckPopover = function DoubleDeckPopover(props) {
  var children = props.children,
    bottomDeckContent = props.bottomDeckContent,
    topDeckContent = props.topDeckContent,
    otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded2);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(FcrPopover, _objectSpread(_objectSpread({}, otherProps), {}, {
    size: "large",
    content: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "fcr-double-deck-popover-overlay",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "fcr-double-deck-popover-top",
        children: topDeckContent
      }), bottomDeckContent]
    }),
    children: children
  }));
};
var usePopoverVisibleState = function usePopoverVisibleState() {
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    clicked = _useState2[0],
    setClicked = _useState2[1];
  var _useState3 = (0, _react.useState)(false),
    _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
    hovered = _useState4[0],
    setHovered = _useState4[1];
  var handleHoverChange = function handleHoverChange(open) {
    if (clicked) return;
    setHovered(open);
    setClicked(false);
  };
  var handleClickChange = function handleClickChange(open) {
    setHovered(false);
    setClicked(open);
  };
  return {
    clicked: clicked,
    hovered: hovered,
    handleHoverChange: handleHoverChange,
    handleClickChange: handleClickChange
  };
};
var PopoverWithTooltip = exports.PopoverWithTooltip = /*#__PURE__*/(0, _react.forwardRef)(function PopoverWithTooltip(props, ref) {
  var popoverProps = props.popoverProps,
    toolTipProps = props.toolTipProps,
    children = props.children,
    triggerCls = props.triggerCls;
  var _usePopoverVisibleSta = usePopoverVisibleState(),
    clicked = _usePopoverVisibleSta.clicked,
    hovered = _usePopoverVisibleSta.hovered,
    handleHoverChange = _usePopoverVisibleSta.handleHoverChange,
    handleClickChange = _usePopoverVisibleSta.handleClickChange;
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      closePopover: function closePopover() {
        console.log('closePopover');
        handleClickChange(false);
      }
    };
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.FcrToolTip, _objectSpread(_objectSpread({}, toolTipProps), {}, {
    visible: hovered,
    trigger: "hover",
    onVisibleChange: function onVisibleChange(visible) {
      var _toolTipProps$onVisib;
      handleHoverChange(visible);
      toolTipProps === null || toolTipProps === void 0 || (_toolTipProps$onVisib = toolTipProps.onVisibleChange) === null || _toolTipProps$onVisib === void 0 || _toolTipProps$onVisib.call(toolTipProps, visible);
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(FcrPopover, _objectSpread(_objectSpread({}, popoverProps), {}, {
      visible: clicked,
      trigger: "click",
      onVisibleChange: function onVisibleChange(visible) {
        var _popoverProps$onVisib;
        handleClickChange(visible);
        popoverProps === null || popoverProps === void 0 || (_popoverProps$onVisib = popoverProps.onVisibleChange) === null || _popoverProps$onVisib === void 0 || _popoverProps$onVisib.call(popoverProps, visible);
      },
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: (0, _classnames["default"])(triggerCls, {
          'fcr-popover-trigger-opened': clicked
        }),
        children: children
      })
    }))
  }));
});
var DoubleDeckPopoverWithTooltip = exports.DoubleDeckPopoverWithTooltip = function DoubleDeckPopoverWithTooltip(props) {
  var doulebDeckPopoverProps = props.doulebDeckPopoverProps,
    toolTipProps = props.toolTipProps,
    children = props.children;
  var _usePopoverVisibleSta2 = usePopoverVisibleState(),
    clicked = _usePopoverVisibleSta2.clicked,
    hovered = _usePopoverVisibleSta2.hovered,
    handleHoverChange = _usePopoverVisibleSta2.handleHoverChange,
    handleClickChange = _usePopoverVisibleSta2.handleClickChange;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.FcrToolTip, _objectSpread(_objectSpread({}, toolTipProps), {}, {
    trigger: "hover",
    visible: hovered,
    onVisibleChange: function onVisibleChange(visible) {
      var _toolTipProps$onVisib2;
      handleHoverChange(visible);
      toolTipProps === null || toolTipProps === void 0 || (_toolTipProps$onVisib2 = toolTipProps.onVisibleChange) === null || _toolTipProps$onVisib2 === void 0 || _toolTipProps$onVisib2.call(toolTipProps, visible);
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DoubleDeckPopover, _objectSpread(_objectSpread({}, doulebDeckPopoverProps), {}, {
      visible: clicked,
      trigger: "click",
      onVisibleChange: function onVisibleChange(visible) {
        var _doulebDeckPopoverPro;
        handleClickChange(visible);
        doulebDeckPopoverProps === null || doulebDeckPopoverProps === void 0 || (_doulebDeckPopoverPro = doulebDeckPopoverProps.onVisibleChange) === null || _doulebDeckPopoverPro === void 0 || _doulebDeckPopoverPro.call(doulebDeckPopoverProps, visible);
      },
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: (0, _classnames["default"])({
          'fcr-popover-trigger-opened': clicked
        }),
        children: children
      })
    }))
  }));
};