"use strict";

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

var _flatten = _interopRequireDefault(require("lodash/flatten"));

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var UserTypeNumberEnum;
exports.UserTypeNumberEnum = UserTypeNumberEnum;

(function (UserTypeNumberEnum) {
  UserTypeNumberEnum[UserTypeNumberEnum["User"] = 1] = "User";
  UserTypeNumberEnum[UserTypeNumberEnum["AllMembers"] = 2] = "AllMembers";
  UserTypeNumberEnum[UserTypeNumberEnum["ProjectOrTarget"] = 4] = "ProjectOrTarget";
  UserTypeNumberEnum[UserTypeNumberEnum["Department"] = 15] = "Department";
  UserTypeNumberEnum[UserTypeNumberEnum["Group"] = 78] = "Group";
})(UserTypeNumberEnum || (exports.UserTypeNumberEnum = UserTypeNumberEnum = {}));

var appendUsers = function appendUsers(users) {
  return (0, _flatten["default"])(users.map(function (_ref) {
    var Name = _ref.Name,
        Id = _ref.Id,
        DepartmentName = _ref.DepartmentName,
        _ref$type = _ref.type,
        type = _ref$type === void 0 ? 'user' : _ref$type;
    var mentionName = Name || DepartmentName;
    return [{
      type: 'mention',
      attrs: {
        mentionId: Id,
        mentionName: mentionName,
        mentionType: type
      },
      content: [{
        type: 'text',
        text: "@".concat(mentionName)
      }]
    }, {
      type: 'text',
      text: ' '
    }];
  }));
};

exports.appendUsers = appendUsers;

var userSelectTypeToEditorType = function userSelectTypeToEditorType(type) {
  return {
    person: 'user',
    depart: 'department',
    group: 'group'
  }[type];
};

var appendUserSelectorData = function appendUserSelectorData(selectNodes) {
  return (0, _flatten["default"])(selectNodes.map(function (_ref2) {
    var nodeType = _ref2.nodeType,
        title = _ref2.title,
        id = _ref2.id;
    return [{
      type: 'mention',
      attrs: {
        mentionId: id,
        mentionName: title,
        mentionType: userSelectTypeToEditorType(nodeType)
      },
      content: ['depart', 'person'].includes(nodeType) ? undefined : [{
        type: 'text',
        text: "@".concat(title)
      }]
    }, {
      type: 'text',
      text: ' '
    }];
  }));
};

exports.appendUserSelectorData = appendUserSelectorData;

var appendImgs = function appendImgs(src, name) {
  return [{
    type: 'image',
    attrs: {
      src: src,
      alt: name
    },
    content: [{
      type: 'text',
      text: name
    }]
  }];
};

exports.appendImgs = appendImgs;

var usersTypeToNumber = function usersTypeToNumber(mentionUsers) {
  return mentionUsers.map(function (user) {
    return _objectSpread(_objectSpread({}, user), {}, {
      mentionType: {
        user: UserTypeNumberEnum.User,
        all_members: UserTypeNumberEnum.AllMembers,
        department: UserTypeNumberEnum.Department,
        group: UserTypeNumberEnum.Group
      }[user.mentionType]
    });
  });
};

exports.usersTypeToNumber = usersTypeToNumber;
var _default = appendUsers;
exports["default"] = _default;