"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/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.FcrDropOption = exports.FcrDropMenu = void 0;
require("core-js/modules/es.array.map.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.map.js");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
require("./index.css");
var _classnames2 = _interopRequireDefault(require("classnames"));
var _icon = require("../icon");
var _type = require("../icon/type");
var _popover = require("../popover");
var _jsxRuntime = require("react/jsx-runtime");
var _react = require("react");
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 FcrDropOption = exports.FcrDropOption = function FcrDropOption(option) {
  var _option$type = option.type,
    type = _option$type === void 0 ? 'primary' : _option$type,
    loading = option.loading,
    wrapperClassName = option.wrapperClassName,
    isOptionIconAlignsToLeft = option.isOptionIconAlignsToLeft;
  switch (type) {
    case 'title':
    case 'group':
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "fcr-drop-menu-".concat(type),
        onClick: !option.disabled ? option.onButtonClick : undefined,
        children: option.title
      });
    case 'line':
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "fcr-drop-menu-line"
      });
    default:
      var hasSubMenu = option.options && option.options.length > 0;
      var icon = hasSubMenu ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
        size: 24,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_icontext1)'
        },
        type: _type.FcrIconType.FCR_TO2
      }) : option.icon;
      var popoverProps = typeof option.visible === 'boolean' ? {
        visible: option.visible
      } : {};
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_popover.FcrPopover, _objectSpread(_objectSpread({
        showArrow: false,
        trigger: "click",
        disable: option.disabled || !hasSubMenu,
        content: FcrDropMenu({
          options: option.options
        })
      }, popoverProps), {}, {
        placement: "right",
        overlayClassName: wrapperClassName,
        children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
          style: {
            flexDirection: isOptionIconAlignsToLeft ? 'row-reverse' : 'row'
          },
          className: (0, _classnames2["default"])(option.classNames, 'fcr-drop-menu-option', (0, _defineProperty2["default"])({}, "fcr-drop-menu-option-".concat(type), !!type), {
            'fcr-drop-menu-option-disabled': option.disabled
          }),
          onClick: !option.disabled ? option.onButtonClick : undefined,
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
            className: "fcr-drop-menu-option-text",
            children: option.title
          }), icon && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
            className: "fcr-drop-menu-option-icon",
            children: icon
          }), loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
            className: (0, _classnames2["default"])('fcr-drop-menu-item-icon', {
              'fcr-drop-menu-item-loading': loading
            }),
            type: _type.FcrIconType.FCR_BTN_LOADING
          })]
        })
      }));
  }
};
var FcrDropMenu = exports.FcrDropMenu = function FcrDropMenu(props) {
  var title = props.title,
    options = props.options,
    children = props.children,
    styles = props.styles,
    className = props.className,
    isOptionIconAlignsToLeft = props.isOptionIconAlignsToLeft;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames2["default"])('fcr-drop-menu', className),
    children: [title && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "fcr-drop-menu-title",
      children: title
    }), options && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "fcr-drop-menu-options",
      children: options.map(function (option, index) {
        return /*#__PURE__*/(0, _react.createElement)(FcrDropOption, _objectSpread(_objectSpread({
          isOptionIconAlignsToLeft: isOptionIconAlignsToLeft,
          wrapperClassName: className
        }, option), {}, {
          key: "drop_".concat(index)
        }));
      })
    }), children]
  });
};