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

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

var _commenComponents = require("../commen-components");

var _scrollTips = require("../commen-components/scroll-tips");

var _network = _interopRequireDefault(require("../util/network"));

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

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

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

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

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var ComponentId = "Personal-Information-Display";

function PersonalInfoComponent() {
  var _useState = (0, _react.useState)(""),
      _useState2 = _slicedToArray(_useState, 2),
      avatarUrl = _useState2[0],
      setAvatarUrl = _useState2[1];

  var _useState3 = (0, _react.useState)({
    name: "",
    userId: -1
  }),
      _useState4 = _slicedToArray(_useState3, 2),
      userName = _useState4[0],
      setUserName = _useState4[1];

  var _useState5 = (0, _react.useState)({
    name: "",
    departmentId: -1
  }),
      _useState6 = _slicedToArray(_useState5, 2),
      department = _useState6[0],
      setDepartment = _useState6[1];

  var _useState7 = (0, _react.useState)(0),
      _useState8 = _slicedToArray(_useState7, 2),
      fansNum = _useState8[0],
      setFansNum = _useState8[1];

  var _useState9 = (0, _react.useState)(0),
      _useState10 = _slicedToArray(_useState9, 2),
      likeNum = _useState10[0],
      setLikeNum = _useState10[1];

  var _useState11 = (0, _react.useState)({
    name: "",
    date: "",
    userId: -1
  }),
      _useState12 = _slicedToArray(_useState11, 2),
      scrollMessage = _useState12[0],
      setScrollMessage = _useState12[1];

  var _useState13 = (0, _react.useState)([]),
      _useState14 = _slicedToArray(_useState13, 2),
      userRoles = _useState14[0],
      setUserRoles = _useState14[1];

  var _useState15 = (0, _react.useState)(""),
      _useState16 = _slicedToArray(_useState15, 2),
      avatarColor = _useState16[0],
      setAvatarColor = _useState16[1];

  var toolTipRef = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    // 获取个人标签
    // @ts-ignore
    var loginUserInfo = BSGlobal && BSGlobal.loginUserInfo;
    var userRoleList = [];

    for (var item in loginUserInfo) {
      switch (item) {
        case "IsBoss":
          (loginUserInfo === null || loginUserInfo === void 0 ? void 0 : loginUserInfo.IsBoss) && userRoleList.push("boss");
          break;

        case "Role":
          (loginUserInfo === null || loginUserInfo === void 0 ? void 0 : loginUserInfo.Role) === 2 && userRoleList.push("super");
          (loginUserInfo === null || loginUserInfo === void 0 ? void 0 : loginUserInfo.Role) === 4 && userRoleList.push("userManager");
          break;

        case "IsTitaFeedSystemManager":
          (loginUserInfo === null || loginUserInfo === void 0 ? void 0 : loginUserInfo.IsTitaFeedSystemManager) && userRoleList.push("assistant");
          break;
      }
    }

    setUserRoles(userRoleList.slice(0, 2)); // 请求获取信息

    (0, _network["default"])(ComponentId).then(function (res) {
      var _item$componentData$, _item$componentData$$, _item$componentData$2, _item$componentData$3, _item$componentData$4, _item$componentData$5, _item$componentData$6, _item$componentData$7, _item$componentData$8, _item$componentData$9, _item$componentData$10, _item$componentData$11, _item$componentData$12, _item$componentData$13, _item$componentData$14, _item$componentData$15, _item$componentData$16, _item$componentData$17, _item$componentData$18, _item$componentData$19, _item$componentData$20, _item$componentData$21, _item$componentData$22;

      var _iterator = _createForOfIteratorHelper(res),
          _step;

      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var _item = _step.value;

          switch (_item.componentDataProp) {
            case "myInfo":
              setAvatarUrl(_item === null || _item === void 0 ? void 0 : _item.componentData[0].simpleUserModelV2.avatar.large);
              setUserName({
                name: _item === null || _item === void 0 ? void 0 : (_item$componentData$ = _item.componentData[0]) === null || _item$componentData$ === void 0 ? void 0 : (_item$componentData$$ = _item$componentData$.simpleUserModelV2) === null || _item$componentData$$ === void 0 ? void 0 : _item$componentData$$.name,
                userId: _item === null || _item === void 0 ? void 0 : (_item$componentData$2 = _item.componentData[0]) === null || _item$componentData$2 === void 0 ? void 0 : (_item$componentData$3 = _item$componentData$2.simpleUserModelV2) === null || _item$componentData$3 === void 0 ? void 0 : _item$componentData$3.userId
              });
              setDepartment({
                name: _item === null || _item === void 0 ? void 0 : (_item$componentData$4 = _item.componentData[0]) === null || _item$componentData$4 === void 0 ? void 0 : (_item$componentData$5 = _item$componentData$4.simpleUserModelV2) === null || _item$componentData$5 === void 0 ? void 0 : _item$componentData$5.departmentName,
                departmentId: _item === null || _item === void 0 ? void 0 : (_item$componentData$6 = _item.componentData[0]) === null || _item$componentData$6 === void 0 ? void 0 : (_item$componentData$7 = _item$componentData$6.simpleUserModelV2) === null || _item$componentData$7 === void 0 ? void 0 : _item$componentData$7.departmentId
              });
              setAvatarColor(_item === null || _item === void 0 ? void 0 : (_item$componentData$8 = _item.componentData[0]) === null || _item$componentData$8 === void 0 ? void 0 : (_item$componentData$9 = _item$componentData$8.simpleUserModelV2) === null || _item$componentData$9 === void 0 ? void 0 : (_item$componentData$10 = _item$componentData$9.avatar) === null || _item$componentData$10 === void 0 ? void 0 : _item$componentData$10.color);
              break;

            case "myFollowInfo":
              setFansNum(_item === null || _item === void 0 ? void 0 : (_item$componentData$11 = _item.componentData[0]) === null || _item$componentData$11 === void 0 ? void 0 : _item$componentData$11.total);
              break;

            case "myPraiseInfo":
              setLikeNum(_item === null || _item === void 0 ? void 0 : _item.componentDataCount);
              break;

            case "latelyFPInfo":
              (_item === null || _item === void 0 ? void 0 : _item.componentData[0]) && setScrollMessage({
                name: _item === null || _item === void 0 ? void 0 : (_item$componentData$12 = _item.componentData[0]) === null || _item$componentData$12 === void 0 ? void 0 : (_item$componentData$13 = _item$componentData$12.simpleUserModelV2) === null || _item$componentData$13 === void 0 ? void 0 : _item$componentData$13.name,
                date: _item === null || _item === void 0 ? void 0 : (_item$componentData$14 = _item.componentData[0]) === null || _item$componentData$14 === void 0 ? void 0 : _item$componentData$14.folowPariseDate,
                userId: _item === null || _item === void 0 ? void 0 : (_item$componentData$15 = _item.componentData[0]) === null || _item$componentData$15 === void 0 ? void 0 : (_item$componentData$16 = _item$componentData$15.simpleUserModelV2) === null || _item$componentData$16 === void 0 ? void 0 : _item$componentData$16.userId,
                avatarSrc: _item === null || _item === void 0 ? void 0 : (_item$componentData$17 = _item.componentData[0]) === null || _item$componentData$17 === void 0 ? void 0 : (_item$componentData$18 = _item$componentData$17.simpleUserModelV2) === null || _item$componentData$18 === void 0 ? void 0 : (_item$componentData$19 = _item$componentData$18.avatar) === null || _item$componentData$19 === void 0 ? void 0 : _item$componentData$19.large,
                avatarColor: _item === null || _item === void 0 ? void 0 : (_item$componentData$20 = _item.componentData[0]) === null || _item$componentData$20 === void 0 ? void 0 : (_item$componentData$21 = _item$componentData$20.simpleUserModelV2) === null || _item$componentData$21 === void 0 ? void 0 : (_item$componentData$22 = _item$componentData$21.avatar) === null || _item$componentData$22 === void 0 ? void 0 : _item$componentData$22.color
              });
              break;
          }
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
    });
  }, []);
  return /*#__PURE__*/_react["default"].createElement(_commenComponents.CardContainer, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "PersonalInfoComponent-PersonalInfo__photoMask"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "PersonalInfoComponent-PersonalInfo__maskimg"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "PersonalInfoComponent-PersonalInfo__maskimg-mask"
  }), /*#__PURE__*/_react["default"].createElement("img", {
    className: "PersonalInfoComponent-PersonalInfo__maskimg-img",
    style: {
      filter: avatarUrl ? "blur(10px)" : "blur(6px)"
    },
    src: avatarUrl || require("../image/default-background-img.png")
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "PersonalInfoComponent-PersonalInfo__personInfo",
    ref: toolTipRef
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "PersonalInfoComponent-PersonalInfo__personInfo--avatar"
  }, /*#__PURE__*/_react["default"].createElement(_avatar["default"], {
    name: userName.name,
    color: avatarColor,
    size: {
      width: 56,
      textNum: 3,
      fontSize: 14
    },
    src: avatarUrl
  })), /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
    overlay: "".concat(userName.name, "\xB7").concat(department.name),
    getTooltipContainer: function getTooltipContainer() {
      return toolTipRef.current;
    },
    placement: "top"
  }, /*#__PURE__*/_react["default"].createElement("p", {
    className: "PersonalInfoComponent-PersonalInfo__personInfo__info"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      textAlign: "right"
    }
  }, /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
    name: userName.name,
    id: userName.userId
  })), /*#__PURE__*/_react["default"].createElement("i", null), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      textAlign: "left"
    }
  }, /*#__PURE__*/_react["default"].createElement(_openData.OpenDepartmentName, {
    name: department.name,
    id: department.departmentId
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "PersonalInfoComponent-PersonalInfo__personInfo__label"
  }, userRoles.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement("img", {
      src: require("../image/".concat(item, "-icon.svg")),
      key: index
    });
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "PersonalInfoComponent-PersonalInfo__fansinfo"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "PersonalInfoComponent-PersonalInfo__fansinfo__attention"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: require("../image/visit-icon.png")
  }), " ", /*#__PURE__*/_react["default"].createElement("b", null, fansNum), (0, _getLocale.getLocale)("HP_peoplefollow")), /*#__PURE__*/_react["default"].createElement("span", {
    className: "PersonalInfoComponent-PersonalInfo__fansinfo__like"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: require("../image/liking.png")
  }), " ", /*#__PURE__*/_react["default"].createElement("b", null, likeNum), (0, _getLocale.getLocale)("HP_Kudos"))), scrollMessage.name && scrollMessage.name.length ? /*#__PURE__*/_react["default"].createElement(_scrollTips.AvatarTips, {
    message: scrollMessage,
    content: "\u5173\u6CE8\u4E86\u6211",
    styles: {
      height: "28px",
      padding: "0 28px",
      lineHeight: "28px"
    }
  }) :
  /*#__PURE__*/
  // @ts-ignore
  _react["default"].createElement(_scrollTips.AvatarTips, {
    content: "\uD83E\uDD70 ".concat((0, _getLocale.getLocale)("HP_Smallwindow")),
    styles: {
      height: "28px",
      padding: "0 28px",
      lineHeight: "28px"
    }
  }));
}