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/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import "core-js/modules/es.array.map.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.map.js";
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 './index.css';
import classnames from 'classnames';
import { FcrIcon } from '../icon';
import { FcrIconType } from '../icon/type';
import { FcrPopover } from '../popover';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { createElement as _createElement } from "react";
export var 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__*/_jsx("div", {
        className: "fcr-drop-menu-".concat(type),
        onClick: !option.disabled ? option.onButtonClick : undefined,
        children: option.title
      });
    case 'line':
      return /*#__PURE__*/_jsx("div", {
        className: "fcr-drop-menu-line"
      });
    default:
      var hasSubMenu = option.options && option.options.length > 0;
      var icon = hasSubMenu ? /*#__PURE__*/_jsx(FcrIcon, {
        size: 24,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_icontext1)'
        },
        type: FcrIconType.FCR_TO2
      }) : option.icon;
      var popoverProps = typeof option.visible === 'boolean' ? {
        visible: option.visible
      } : {};
      return /*#__PURE__*/_jsx(FcrPopover, _objectSpread(_objectSpread({
        showArrow: false,
        trigger: "click",
        disable: option.disabled || !hasSubMenu,
        content: FcrDropMenu({
          options: option.options
        })
      }, popoverProps), {}, {
        placement: "right",
        overlayClassName: wrapperClassName,
        children: /*#__PURE__*/_jsxs("div", {
          style: {
            flexDirection: isOptionIconAlignsToLeft ? 'row-reverse' : 'row',
            gap: '8px'
          },
          className: classnames(option.classNames, 'fcr-drop-menu-option', _defineProperty({}, "fcr-drop-menu-option-".concat(type), !!type), {
            'fcr-drop-menu-option-disabled': option.disabled
          }),
          onClick: !option.disabled ? option.onButtonClick : undefined,
          children: [/*#__PURE__*/_jsx("span", {
            className: "fcr-drop-menu-option-text",
            children: option.title
          }), (option.value && hasSubMenu || icon) && /*#__PURE__*/_jsxs("div", {
            className: "fcr-drop-menu-option-content",
            children: [option.value && hasSubMenu && /*#__PURE__*/_jsx("span", {
              className: "fcr-drop-menu-option-value",
              children: option.value
            }), icon && /*#__PURE__*/_jsx("span", {
              className: "fcr-drop-menu-option-icon",
              children: icon
            })]
          }), loading && /*#__PURE__*/_jsx(FcrIcon, {
            className: classnames('fcr-drop-menu-item-icon', {
              'fcr-drop-menu-item-loading': loading
            }),
            type: FcrIconType.FCR_BTN_LOADING
          })]
        })
      }));
  }
};
export var 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__*/_jsxs("div", {
    className: classnames('fcr-drop-menu', className),
    children: [title && /*#__PURE__*/_jsx("div", {
      className: "fcr-drop-menu-title",
      children: title
    }), options && /*#__PURE__*/_jsx("div", {
      className: "fcr-drop-menu-options",
      children: options.map(function (option, index) {
        return /*#__PURE__*/_createElement(FcrDropOption, _objectSpread(_objectSpread({
          isOptionIconAlignsToLeft: isOptionIconAlignsToLeft,
          wrapperClassName: className
        }, option), {}, {
          key: "drop_".concat(index)
        }));
      })
    }), children]
  });
};