import React from 'react';
import { Tag } from 'antd';
import "./index.less";
import { PREFIX } from "../../index";
var colors = ['magenta', 'volcano', 'orange', 'gold', 'green', 'cyan', 'blue', 'geekblue', 'purple'];
function getColor(n) {
  // 用质数扰动 + 取余
  return colors[n * 31 % colors.length];
}
var Resources = function Resources(props) {
  var _props$dataSource = props.dataSource,
    dataSource = _props$dataSource === void 0 ? {} : _props$dataSource;
  var multiResources = dataSource.multiResources,
    isMultipleResource = dataSource.isMultipleResource;
  var renderResourceItem = function renderResourceItem(item, index) {
    var ids = item.id,
      lists = item.lists,
      _id = item._id;
    return Array.isArray(ids) ? ids.map(function (id) {
      var targetRes = lists.find(function (l) {
        return l.id === id;
      });
      if (targetRes !== null && targetRes !== void 0 && targetRes.label) {
        return /*#__PURE__*/React.createElement(Tag, {
          color: getColor(_id),
          className: "resource-tag"
        }, targetRes.label);
      }
      return null;
    }) : null;
  };
  if (isMultipleResource && (multiResources === null || multiResources === void 0 ? void 0 : multiResources.length) > 0) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__resources")
    }, multiResources.map(renderResourceItem));
  }
  return null;
};
export default Resources;