"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _icon = _interopRequireDefault(require("@alifd/next/lib/icon"));
var _dropdown = _interopRequireDefault(require("@alifd/next/lib/dropdown"));
var _menu = _interopRequireDefault(require("@alifd/next/lib/menu"));
var _button = _interopRequireDefault(require("@alifd/next/lib/button"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
require("./index.scss");
var _excluded = ["category", "trigger", "color", "bacColor", "label", "dataSource", "style"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var TextDropdown = function TextDropdown(_ref) {
  var category = _ref.category,
    trigger = _ref.trigger,
    color = _ref.color,
    bacColor = _ref.bacColor,
    label = _ref.label,
    dataSource = _ref.dataSource,
    _ref$style = _ref.style,
    style = _ref$style === void 0 ? {} : _ref$style,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _style = style || {};
  if (color) {
    _style.color = color;
  }
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var _useState = (0, React.useState)(false),
    ifIcon = _useState[0],
    setIcon = _useState[1];
  var _onVisibleChange = function onVisibleChange() {
    if (ifIcon) {
      setIcon(false);
    } else {
      setIcon(true);
    }
  };
  return category === '按钮' ? /*#__PURE__*/React.createElement(_dropdown["default"], {
    trigger: /*#__PURE__*/React.createElement(_button["default"], {
      style: {
        border: "1px solid " + color,
        color: color,
        fontSize: '14px',
        backgroundColor: bacColor
      }
    }, label),
    triggerType: trigger === 'hover' ? ["hover"] : ["click"]
  }, /*#__PURE__*/React.createElement(_menu["default"], _otherProps, dataSource.map(function (item, index) {
    return /*#__PURE__*/React.createElement(_menu["default"].Item, null, item.label);
  }))) : /*#__PURE__*/React.createElement(_dropdown["default"], {
    trigger: /*#__PURE__*/React.createElement("span", {
      style: {
        padding: '2px 8px',
        fontSize: '14px',
        display: 'inline-block',
        backgroundColor: bacColor
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        color: color
      }
    }, label), /*#__PURE__*/React.createElement(_icon["default"], {
      style: {
        color: color,
        marginLeft: '5px'
      },
      size: "small",
      type: !ifIcon ? "arrow-down" : "arrow-up"
    })),
    triggerType: trigger === 'hover' ? ["hover"] : ["click"],
    onVisibleChange: function onVisibleChange() {
      _onVisibleChange();
    }
  }, /*#__PURE__*/React.createElement(_menu["default"], _otherProps, dataSource.map(function (item, index) {
    return /*#__PURE__*/React.createElement(_menu["default"].Item, {
      disabled: item.disabled
    }, item.label);
  })));
};
var _default = TextDropdown;
exports["default"] = _default;