"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _avatar = _interopRequireDefault(require("../../../avatar"));

var _userSelector = _interopRequireDefault(require("../../../user-selector"));

var _baseInfoAdd = _interopRequireDefault(require("../img/base-info-add.svg"));

var _tooltip = _interopRequireDefault(require("../../../tooltip"));

var _getLocale = require("../../../../utils/getLocale");

require("./index.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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 Person = function Person(_ref) {
  var users = _ref.users,
      canEdit = _ref.canEdit,
      onAddUser = _ref.onAddUser,
      onDelUser = _ref.onDelUser,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? "participant" : _ref$type;
  var selectorRef = (0, _react.useRef)();

  var handleSelected = function handleSelected(data) {
    onAddUser && onAddUser(data, type); // @ts-ignore

    selectorRef.current && selectorRef.current.close();
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-info__person-wrapper"
  }, users && users.length > 0 && users.map(function (user) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "base-info__person-item",
      key: user.id
    }, /*#__PURE__*/_react["default"].createElement(_avatar["default"].Name, {
      textClass: "base-info__person-text",
      showNameTips: true,
      canDelUser: canEdit,
      textWidth: 42,
      onDelUser: onDelUser,
      size: {
        width: 24,
        textNum: 1,
        fontSize: 12
      },
      name: user.name,
      src: user.avatar.medium || user.avatar.Medium,
      color: user.avatar.color,
      userId: user.userId || user.id
    }));
  }), canEdit ? /*#__PURE__*/_react["default"].createElement("div", {
    className: "base-info__person-item base-info__person-add"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: _baseInfoAdd["default"]
  }), /*#__PURE__*/_react["default"].createElement(_userSelector["default"], {
    ref: selectorRef // @ts-ignore
    ,
    multiple: true,
    position: "centerRight",
    selectNodes: {},
    onOk: handleSelected,
    destroyPopupOnHide: true,
    trigger: /*#__PURE__*/_react["default"].createElement("div", {
      className: "base-info-other-infos__principal-trigger-content"
    }, /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
      overlay: type === "participant" ? (0, _getLocale.getLocale)("OKR_MyO_Es_Addparticipant") : (0, _getLocale.getLocale)("OKR_MyO_Es_Addfollowers"),
      placement: "top"
    }, /*#__PURE__*/_react["default"].createElement("div", {
      style: {
        width: "24px",
        height: "24px"
      }
    })))
  })) : null);
};

var _default = Person;
exports["default"] = _default;