import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
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) { _defineProperty(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; }
import { forwardRef, useState, useImperativeHandle } from 'react';
import { FcrToolTip } from '../tooltip';
import classnames from 'classnames';
import './index.css';
import { FcrIcon } from '../icon';
import { FcrIconType } from '../icon/type';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var 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 = _objectWithoutProperties(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__*/_jsx(FcrToolTip, _objectSpread(_objectSpread({}, otherProps), {}, {
    afterVisibleChange: afterVisibleChange,
    overlayClassName: classnames('fcr-popover', overlayClassName),
    showArrow: showArrow,
    arrowContent: /*#__PURE__*/_jsx(FcrIcon, {
      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
  }));
};
export var DoubleDeckPopover = function DoubleDeckPopover(props) {
  var children = props.children,
    bottomDeckContent = props.bottomDeckContent,
    topDeckContent = props.topDeckContent,
    otherProps = _objectWithoutProperties(props, _excluded2);
  return /*#__PURE__*/_jsx(FcrPopover, _objectSpread(_objectSpread({}, otherProps), {}, {
    size: "large",
    content: /*#__PURE__*/_jsxs("div", {
      className: "fcr-double-deck-popover-overlay",
      children: [/*#__PURE__*/_jsx("div", {
        className: "fcr-double-deck-popover-top",
        children: topDeckContent
      }), bottomDeckContent]
    }),
    children: children
  }));
};
var usePopoverVisibleState = function usePopoverVisibleState() {
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    clicked = _useState2[0],
    setClicked = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_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
  };
};
export var PopoverWithTooltip = /*#__PURE__*/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;
  useImperativeHandle(ref, function () {
    return {
      closePopover: function closePopover() {
        console.log('closePopover');
        handleClickChange(false);
      }
    };
  }, []);
  return /*#__PURE__*/_jsx(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__*/_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__*/_jsx("div", {
        className: classnames(triggerCls, {
          'fcr-popover-trigger-opened': clicked
        }),
        children: children
      })
    }))
  }));
});
export var 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__*/_jsx(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__*/_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__*/_jsx("div", {
        className: classnames({
          'fcr-popover-trigger-opened': clicked
        }),
        children: children
      })
    }))
  }));
};