"use strict";

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _default2 = _interopRequireDefault(require("../../../avatar/default"));

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

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

var _openData = require("../../../../utils/open-data");

require("./index.css");

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

var preCls = 'form-field-user';

function _default(props) {
  var _props$multiple = props.multiple,
      multiple = _props$multiple === void 0 ? false : _props$multiple,
      users = props.users,
      _props$placeholder = props.placeholder,
      placeholder = _props$placeholder === void 0 ? (0, _getLocale.getLocale)('Mod_Pleaseselect') : _props$placeholder,
      onClear = props.onClear;
  var userNames = [];
  (users || []).forEach(function (user) {
    userNames.push( /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])("".concat(preCls, "__input-user-info"))
    }, /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
      overlay: user.name,
      placement: "top"
    }, /*#__PURE__*/_react["default"].createElement(_default2["default"], {
      name: user.name,
      src: user.avatar.small,
      color: user.avatar.color,
      userId: user.userId
    })), !multiple && /*#__PURE__*/_react["default"].createElement("p", {
      className: (0, _classnames["default"])("".concat(preCls, "__input-user-info__name"))
    }, /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
      id: user.userId,
      name: user.name
    }))));
  });

  var onHandleClear = function onHandleClear(e) {
    e.preventDefault();
    e.stopPropagation();
    onClear();
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__input"))
  }, !users || !users.length ? /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__input--placeholder"))
  }, placeholder) : userNames, users && users.length > 0 && /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("tu-icon-cross ".concat(preCls, "__input--clear")),
    onClick: onHandleClear
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__input--down tu-icon-caret-down"))
  }));
}