'use strict';

var React = require('react');
var ui_Label = require('../chunks/bundle-VxcYXhwp.js');
var ui_LinkLabel = require('./LinkLabel.js');
var uuid = require('../chunks/bundle-TB_UEIPg.js');
var index = require('../chunks/bundle-nox41MG6.js');
var ui_MentionLabel = require('./MentionLabel.js');
require('../chunks/bundle-DhtZdKsr.js');
require('../chunks/bundle-H9rcn1PJ.js');
require('@sendbird/chat/groupChannel');
require('../utils/message/getOutgoingMessageState.js');
require('../chunks/bundle-xM2DAzE6.js');
require('./ContextMenu.js');
require('react-dom');
require('./SortByRow.js');
require('./UserProfile.js');
require('../chunks/bundle-6SzyBwQ5.js');
require('../chunks/bundle-AN4eZ2xs.js');
require('../chunks/bundle-TPy0gj60.js');
require('../sendbirdSelectors.js');
require('../chunks/bundle-77qvrXp8.js');
require('../chunks/bundle-Y-_KhZFq.js');
require('../chunks/bundle-w0ATt2gt.js');
require('./ImageRenderer.js');
require('../chunks/bundle-HQAiUNev.js');
require('./Icon.js');
require('./Button.js');
require('../useSendbirdStateContext.js');
require('../withSendbird.js');

/**
 * @deprecated  This component is deprecated and will be removed in the next major version.
 * Use TextFragment instead.
 */
// Word and StringObj will include types: normal, mention, url
function Word(props) {
    var word = props.word, message = props.message, _a = props.isByMe, isByMe = _a === void 0 ? false : _a, _b = props.mentionTemplate, mentionTemplate = _b === void 0 ? '@' : _b, _c = props.renderString, renderString = _c === void 0 ? null : _c;
    if (word === '') {
        return null;
    }
    return (React.createElement("span", { className: "sendbird-word" }, index.convertWordToStringObj(word, message === null || message === void 0 ? void 0 : message.mentionedUsers).map(function (stringObj) {
        var _a;
        var type = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.type) || '';
        var value = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.value) || '';
        var userId = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.userId) || '';
        if (renderString && typeof renderString === 'function') {
            return renderString(stringObj);
        }
        if (type === index.StringObjType.mention) {
            return (React.createElement(ui_MentionLabel, { mentionTemplate: mentionTemplate, mentionedUserId: userId, mentionedUserNickname: value, key: uuid.uuidv4(), isByMe: isByMe }));
        }
        else if (type === index.StringObjType.url) {
            var urlRegex = /([a-zA-Z0-9]+:\/\/)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\.[A-Za-z]{2,4})(:[0-9]+)?(\/.*)?/;
            var targetUrl = (_a = value.match(urlRegex)) === null || _a === void 0 ? void 0 : _a[0];
            var stringUrl = { front: '', url: '', back: '' };
            if (targetUrl) {
                var targetUrlIndex = value.indexOf(targetUrl);
                if (targetUrlIndex > 0) {
                    stringUrl.front = value.slice(0, targetUrlIndex);
                }
                stringUrl.url = value.slice(targetUrlIndex, targetUrlIndex + targetUrl.length);
                if (targetUrlIndex + targetUrl.length < value.length) {
                    stringUrl.back = value.slice(targetUrlIndex + targetUrl.length);
                }
            }
            if (targetUrl) {
                return [
                    stringUrl.front ? stringUrl.front : '',
                    stringUrl.url ? (React.createElement(ui_LinkLabel.default, { className: "sendbird-word__url", key: uuid.uuidv4(), src: stringUrl.url, type: ui_Label.LabelTypography.BODY_1 }, stringUrl.url)) : null,
                    stringUrl.back ? stringUrl.back : '',
                ];
            }
            return (React.createElement(ui_LinkLabel.default, { className: "sendbird-word__url", key: uuid.uuidv4(), src: word, type: ui_Label.LabelTypography.BODY_1 }, value));
        }
        else {
            return value;
        }
    })));
}

module.exports = Word;
//# sourceMappingURL=Word.js.map
