import React__default from 'react';
import { a as LabelTypography } from '../chunks/bundle-I8JFwttJ.js';
import LinkLabel from './LinkLabel.js';
import { u as uuidv4 } from '../chunks/bundle-YoWLsJ0C.js';
import { y as convertWordToStringObj, S as StringObjType } from '../chunks/bundle-N9hMnIRl.js';
import MentionLabel from './MentionLabel.js';
import '../chunks/bundle-BA7tv0JB.js';
import '../chunks/bundle-jy6_UG14.js';
import '@sendbird/chat/groupChannel';
import '../utils/message/getOutgoingMessageState.js';
import '../chunks/bundle-aKXnhi3A.js';
import './ContextMenu.js';
import 'react-dom';
import './SortByRow.js';
import './UserProfile.js';
import '../chunks/bundle-BBjosDA0.js';
import '../chunks/bundle-ULVw0l0r.js';
import '../chunks/bundle-vOT5acXc.js';
import '../sendbirdSelectors.js';
import '../chunks/bundle-nlOgiAcu.js';
import '../chunks/bundle-cA_r9HRx.js';
import '../chunks/bundle-Qufz6_i_.js';
import './ImageRenderer.js';
import '../chunks/bundle-jDjj3eHU.js';
import './Icon.js';
import './Button.js';
import '../useSendbirdStateContext.js';
import '../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__default.createElement("span", { className: "sendbird-word" }, 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 === StringObjType.mention) {
            return (React__default.createElement(MentionLabel, { mentionTemplate: mentionTemplate, mentionedUserId: userId, mentionedUserNickname: value, key: uuidv4(), isByMe: isByMe }));
        }
        else if (type === 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__default.createElement(LinkLabel, { className: "sendbird-word__url", key: uuidv4(), src: stringUrl.url, type: LabelTypography.BODY_1 }, stringUrl.url)) : null,
                    stringUrl.back ? stringUrl.back : '',
                ];
            }
            return (React__default.createElement(LinkLabel, { className: "sendbird-word__url", key: uuidv4(), src: word, type: LabelTypography.BODY_1 }, value));
        }
        else {
            return value;
        }
    })));
}

export { Word as default };
//# sourceMappingURL=Word.js.map
