import "choerodon-ui/lib/dropdown/style";
import _Dropdown from "choerodon-ui/lib/dropdown";
import "choerodon-ui/lib/button/style";
import _Button from "choerodon-ui/lib/button";
import "choerodon-ui/lib/menu/style";
import _Menu from "choerodon-ui/lib/menu";
var _excluded = ["key", "text", "display", "service"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

/**
 * master 中的 Action 不支持单个选项的disabled
 * 该组件实现可以对单个item进行禁用，后期会更换到master的Action
 */
import React, { memo } from 'react';
import { Permission } from '@choerodon/boot';
import map from 'lodash/map';
import "./index.less";
var HeaderAction = /*#__PURE__*/memo(function (_ref) {
  var menuClick = _ref.menuClick,
      items = _ref.items,
      placement = _ref.placement,
      style = _ref.style,
      buttonStyle = _ref.buttonStyle;

  function getMenuItem() {
    var menuItem = map(items, function (_ref2) {
      var key = _ref2.key,
          text = _ref2.text,
          display = _ref2.display,
          service = _ref2.service,
          rest = _objectWithoutProperties(_ref2, _excluded);

      var item = /*#__PURE__*/React.createElement(_Menu.Item, Object.assign({
        key: key
      }, rest), text);
      var itemWithPermission = service ? /*#__PURE__*/React.createElement(Permission, {
        key: key,
        service: service
      }, item) : item;
      return display ? itemWithPermission : null;
    });
    return /*#__PURE__*/React.createElement(_Menu, {
      onClick: menuClick
    }, menuItem);
  }

  function handleClick(e) {
    e.stopPropagation();
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "c7ncd-action-wrap",
    style: style
  }, /*#__PURE__*/React.createElement(_Dropdown, {
    placement: placement,
    trigger: ['click'],
    overlay: getMenuItem()
  }, /*#__PURE__*/React.createElement(_Button, {
    style: _objectSpread({}, buttonStyle),
    size: "small",
    shape: "circle",
    funcType: "flat",
    icon: "more_vert",
    onClick: handleClick
  })));
});
HeaderAction.defaultProps = {
  placement: 'bottomLeft'
};
export default HeaderAction;