import i18n from 'ui-i18n';
import { isNil } from 'ramda';
export var getAbbreviationFromUserName = function (username) {
    return username
        .split('.')
        .map(function (item) { return item[0].toUpperCase(); })
        .join('');
};
export var getRelatedEntityUri = function (comment, entityUri) {
    var index = comment.relatedObjectUris.indexOf(entityUri);
    if (index >= 0)
        return comment.relatedObjectUris[1 - index];
};
export var formatDate = function (time) { return "".concat(i18n.date(time, 'LT'), " ").concat(i18n.date(time, 'LL')); };
export var processMentions = function (text, mentions, processor, trigger) {
    if (processor === void 0) { processor = function (value) { return value; }; }
    if (trigger === void 0) { trigger = '+'; }
    var arr = [];
    var currentStr = '';
    var process = false;
    for (var i = 0; i <= text.length; i++) {
        var currentCharacter = text[i];
        var nextCharacter = text[i + 1];
        var isLastCharacter = i === text.length - 1;
        currentStr += currentCharacter;
        if (currentCharacter === trigger && i === 0) {
            process = true;
        }
        if (process && mentions.includes(currentStr.slice(trigger.length))) {
            process = false;
            arr.push(processor(currentStr));
            currentStr = '';
        }
        if (nextCharacter === trigger) {
            process = true;
            arr.push(currentStr);
            currentStr = '';
        }
        if (isLastCharacter) {
            arr.push(currentStr);
        }
    }
    return arr;
};
export var createNewCommentUri = function () { return 'comment/new'; };
export var createNewReplyUri = function (comment) { return "comment/".concat(comment.commentId, "/reply/new"); };
export var createEditedCommentUri = function (comment) { return "comment/".concat(comment.commentId); };
export var createEditedReplyUri = function (comment, reply) {
    return "comment/".concat(comment.commentId, "/reply/").concat(reply.replyId);
};
export var createCommentUri = function (_a) {
    var comment = _a.comment, reply = _a.reply, isEditingComment = _a.isEditingComment, isEditingReply = _a.isEditingReply;
    if (isNil(comment)) {
        return createNewCommentUri();
    }
    if (isEditingComment) {
        return createEditedCommentUri(comment);
    }
    if (isEditingReply) {
        return createEditedReplyUri(comment, reply);
    }
    return createNewReplyUri(comment);
};
export var transformPlainTextValueToValueWithMentions = function (plainTextValue, mentions) {
    var value = plainTextValue;
    for (var _i = 0, mentions_1 = mentions; _i < mentions_1.length; _i++) {
        var mention = mentions_1[_i];
        value = value.split("+".concat(mention)).join("@[".concat(mention, "](").concat(mention, ")"));
    }
    return value;
};
