"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"] = _default;

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

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

var _context = require("../../../context");

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

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

var _platform = require("../../../../../utils/platform");

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; }

function _default(props) {
  var data = props.data,
      isSelectedPanel = props.isSelectedPanel,
      onRemove = props.onRemove;

  var _useContext = (0, _react.useContext)(_context.TreeNodeContext),
      hideUserInfo = _useContext.hideUserInfo;

  var onRemoveHandler = function onRemoveHandler() {
    onRemove && onRemove(props);
  };

  var renderAvatar = function renderAvatar() {
    var _data$avatar, _data$avatar2, _data$avatar3;

    if ((data === null || data === void 0 ? void 0 : (_data$avatar = data.avatar) === null || _data$avatar === void 0 ? void 0 : _data$avatar.hasAvatar) === false) {
      return /*#__PURE__*/_react["default"].createElement("span", {
        style: {
          backgroundColor: data.avatar.color
        }
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "perspm-person__avatar-text",
        title: ""
      }, /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
        id: data.userId,
        name: data.name
      })));
    } else if (data !== null && data !== void 0 && (_data$avatar2 = data.avatar) !== null && _data$avatar2 !== void 0 && _data$avatar2.original || data !== null && data !== void 0 && (_data$avatar3 = data.avatar) !== null && _data$avatar3 !== void 0 && _data$avatar3.small) {
      var _data$avatar4, _data$avatar5;

      return /*#__PURE__*/_react["default"].createElement("img", {
        key: data.userId,
        src: (data === null || data === void 0 ? void 0 : (_data$avatar4 = data.avatar) === null || _data$avatar4 === void 0 ? void 0 : _data$avatar4.original) || (data === null || data === void 0 ? void 0 : (_data$avatar5 = data.avatar) === null || _data$avatar5 === void 0 ? void 0 : _data$avatar5.small),
        style: {
          width: "100%",
          height: "100%",
          position: 'relative',
          top: '-1px'
        }
      });
    } else {
      var _data$avatar6;

      return /*#__PURE__*/_react["default"].createElement("span", {
        style: {
          backgroundColor: data === null || data === void 0 ? void 0 : (_data$avatar6 = data.avatar) === null || _data$avatar6 === void 0 ? void 0 : _data$avatar6.color
        }
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "perspm-person__avatar-text",
        title: ""
      }, /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
        id: data.userId,
        name: data.name
      })));
    }
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("perspm-person", {
      "perspm-person--small": hideUserInfo
    })
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "perspm-person__avatar"
  }, renderAvatar(), (data === null || data === void 0 ? void 0 : data.jobState) === 0 && /*#__PURE__*/_react["default"].createElement("span", {
    className: "perspm-person__avatar-dimission"
  }, (0, _platform.isOfficialSite)() ? '离职' : '禁用')), /*#__PURE__*/_react["default"].createElement("span", {
    className: "perspm-person__info"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      flexDirection: "column",
      display: "flex"
    }
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("perspm-person__info-title", {
      "perspm-person__info-title--single": !data.email
    })
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "perspm-person__info-title-name",
    title: ""
  }, /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
    id: data.userId,
    name: data.name
  })), !hideUserInfo && /*#__PURE__*/_react["default"].createElement("span", {
    className: "perspm-person__info-title-depart",
    title: ""
  }, /*#__PURE__*/_react["default"].createElement(_openData.OpenDepartmentName, {
    id: data.departmentId,
    name: data.departmentName
  }))), data.email && !hideUserInfo && /*#__PURE__*/_react["default"].createElement("span", {
    className: "perspm-person__info-email",
    title: ""
  }, data.email))), !isSelectedPanel ? /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("perspm-tree__selector", "perspm-tree__selector-person")
  }) : undefined, isSelectedPanel ? /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("perspm-tree__close"),
    onClick: onRemoveHandler
  }) : undefined);
}