'use strict';

var _tslib = require('../chunks/bundle-Cu2j1EmN.js');
var React = require('react');
var _const$1 = require('../chunks/bundle-CWAjZyWA.js');
var _const = require('../chunks/bundle-BIlOa8cH.js');
var ui_IconButton = require('./IconButton.js');
var ui_Button = require('./Button.js');
var ui_MessageInput_hooks_usePaste = require('../chunks/bundle-bgI8QY8V.js');
var ui_Icon = require('./Icon.js');
var ui_Label = require('../chunks/bundle-BM95N32D.js');
var LocalizationContext = require('../chunks/bundle-Bq4FcvTF.js');
var useSendbirdStateContext = require('../useSendbirdStateContext.js');
var index = require('../chunks/bundle-VyDwmxN4.js');
var tokenize = require('../chunks/bundle-auAyIyjy.js');
var utils = require('../chunks/bundle-CO52Wsr3.js');
var browser = require('../chunks/bundle-CTW4jbtw.js');
require('dompurify');
require('../chunks/bundle-BqL8lmhl.js');
require('../chunks/bundle-CiIb5etk.js');
require('../chunks/bundle-BKID5CS2.js');
require('../chunks/bundle-CrkUdg03.js');
require('../chunks/bundle-DQG6eG4l.js');
require('../withSendbird.js');
require('@sendbird/chat/groupChannel');
require('../utils/message/getOutgoingMessageState.js');
require('../chunks/bundle-_xb0mhf9.js');

/**
 * FIXME:
 * Import this ChannelType enum from @sendbird/chat
 * once MessageInput.spec unit tests can be run \wo jest <-> ESM issue
 */
var ChannelType;
(function (ChannelType) {
    ChannelType["BASE"] = "base";
    ChannelType["GROUP"] = "group";
    ChannelType["OPEN"] = "open";
})(ChannelType || (ChannelType = {}));
/**
 * FIXME: Simplify this in UIKit@v4
 * If customer is using MessageInput inside our modules(ie: Channel, Thread, etc),
 * we should use the config from the module.
 * If customer is using MessageInput outside our modules(ie: custom UI),
 * we expect Channel to be undefined and customer gets control to show/hide file-upload.
 * @param {*} channel GroupChannel | OpenChannel
 * @param {*} config SendBirdStateConfig
 * @returns boolean
 */
var checkIfFileUploadEnabled = function (_a) {
    var channel = _a.channel, config = _a.config;
    var isEnabled = index.K(channel === null || channel === void 0 ? void 0 : channel.channelType)
        .with(ChannelType.GROUP, function () { var _a; return (_a = config === null || config === void 0 ? void 0 : config.groupChannel) === null || _a === void 0 ? void 0 : _a.enableDocument; })
        .with(ChannelType.OPEN, function () { var _a; return (_a = config === null || config === void 0 ? void 0 : config.openChannel) === null || _a === void 0 ? void 0 : _a.enableDocument; })
        .otherwise(function () { return true; });
    return isEnabled;
};

var TEXT_FIELD_ID = 'sendbird-message-input-text-field';
var LINE_HEIGHT = 76;
var DEFAULT_CHAT_VIEW_HEIGHT = 600;
var noop = function () {
    return null;
};
var displayCaret = function (element, position) {
    var range = document.createRange();
    var sel = window.getSelection();
    range.setStart(element.childNodes[0], position);
    range.collapse(true);
    sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
    sel === null || sel === void 0 ? void 0 : sel.addRange(range);
    element.focus();
};
var resetInput = function (ref) {
    if (ref && ref.current) {
        ref.current.innerHTML = '';
    }
};
var initialTargetStringInfo = {
    targetString: '',
    startNodeIndex: null,
    startOffsetIndex: null,
    endNodeIndex: null,
    endOffsetIndex: null,
};
var MessageInput = React.forwardRef(function (props, externalRef) {
    var _a, _b, _c, _d, _e;
    var channel = props.channel, _f = props.className, className = _f === void 0 ? '' : _f, _g = props.messageFieldId, messageFieldId = _g === void 0 ? '' : _g, _h = props.isEdit, isEdit = _h === void 0 ? false : _h, _j = props.isMobile, isMobile = _j === void 0 ? false : _j, _k = props.isMentionEnabled, isMentionEnabled = _k === void 0 ? false : _k, _l = props.isVoiceMessageEnabled, isVoiceMessageEnabled = _l === void 0 ? true : _l, _m = props.isSelectingMultipleFilesEnabled, isSelectingMultipleFilesEnabled = _m === void 0 ? false : _m, _o = props.disabled, disabled = _o === void 0 ? false : _o, _p = props.message, message = _p === void 0 ? null : _p, _q = props.placeholder, placeholder = _q === void 0 ? '' : _q, _r = props.maxLength, maxLength = _r === void 0 ? 5000 : _r, _s = props.onFileUpload, onFileUpload = _s === void 0 ? noop : _s, _t = props.onSendMessage, onSendMessage = _t === void 0 ? noop : _t, _u = props.onUpdateMessage, onUpdateMessage = _u === void 0 ? noop : _u, _v = props.onCancelEdit, onCancelEdit = _v === void 0 ? noop : _v, _w = props.onStartTyping, onStartTyping = _w === void 0 ? noop : _w, _x = props.channelUrl, channelUrl = _x === void 0 ? '' : _x, _y = props.mentionSelectedUser, mentionSelectedUser = _y === void 0 ? null : _y, _z = props.onUserMentioned, onUserMentioned = _z === void 0 ? noop : _z, _0 = props.onMentionStringChange, onMentionStringChange = _0 === void 0 ? noop : _0, _1 = props.onMentionedUserIdsUpdated, onMentionedUserIdsUpdated = _1 === void 0 ? noop : _1, _2 = props.onVoiceMessageIconClick, onVoiceMessageIconClick = _2 === void 0 ? noop : _2, _3 = props.onKeyUp, onKeyUp = _3 === void 0 ? noop : _3, _4 = props.onKeyDown, onKeyDown = _4 === void 0 ? noop : _4, _5 = props.renderFileUploadIcon, renderFileUploadIcon = _5 === void 0 ? noop : _5, _6 = props.renderVoiceMessageIcon, renderVoiceMessageIcon = _6 === void 0 ? noop : _6, _7 = props.renderSendMessageIcon, renderSendMessageIcon = _7 === void 0 ? noop : _7, _8 = props.setMentionedUsers, setMentionedUsers = _8 === void 0 ? noop : _8, acceptableMimeTypes = props.acceptableMimeTypes;
    var internalRef = (externalRef && 'current' in externalRef) ? externalRef : null;
    var ghostInputRef = React.useRef(null);
    var textFieldId = messageFieldId || TEXT_FIELD_ID;
    var stringSet = LocalizationContext.useLocalization().stringSet;
    var config = useSendbirdStateContext.useSendbirdStateContext().config;
    var isFileUploadEnabled = checkIfFileUploadEnabled({
        channel: channel,
        config: config,
    });
    var fileInputRef = React.useRef();
    var _9 = React.useState(false), isInput = _9[0], setIsInput = _9[1];
    var _10 = React.useState([]), mentionedUserIds = _10[0], setMentionedUserIds = _10[1];
    var _11 = React.useState(_tslib.__assign({}, initialTargetStringInfo)), targetStringInfo = _11[0], setTargetStringInfo = _11[1];
    var setHeight = React.useCallback(function () {
        var elem = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
        if (!elem)
            return;
        try {
            var estimatedChatViewHeight = window.document.body.offsetHeight || DEFAULT_CHAT_VIEW_HEIGHT;
            var MAX_HEIGHT = estimatedChatViewHeight * 0.6;
            if (elem.scrollHeight >= LINE_HEIGHT) {
                if (MAX_HEIGHT < elem.scrollHeight) {
                    elem.style.height = 'auto';
                    elem.style.height = "".concat(MAX_HEIGHT, "px");
                }
                else {
                    elem.style.height = '';
                }
            }
        }
        catch (error) {
            // error
        }
    }, []);
    // #Edit mode
    // for easilly initialize input value from outside, but
    // useEffect(_, [channelUrl]) erase it
    var initialValue = props === null || props === void 0 ? void 0 : props.value;
    React.useEffect(function () {
        var textField = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
        try {
            if (textField && initialValue) {
                textField.innerHTML = initialValue;
                displayCaret(textField, initialValue === null || initialValue === void 0 ? void 0 : initialValue.length);
            }
        }
        catch (_a) {
            //
        }
        setMentionedUserIds([]);
        setIsInput((textField === null || textField === void 0 ? void 0 : textField.textContent) ? textField.textContent.trim().length > 0 : false);
        setHeight();
    }, [initialValue]);
    // #Mention | Clear input value when channel changes
    React.useEffect(function () {
        if (!isEdit) {
            setIsInput(false);
            resetInput(internalRef);
        }
    }, [channelUrl]);
    // #Mention & #Edit | Fill message input values
    React.useEffect(function () {
        var _a, _b;
        if (isEdit && (message === null || message === void 0 ? void 0 : message.messageId)) {
            // const textField = document.getElementById(textFieldId);
            var textField = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
            if (isMentionEnabled
                && (message === null || message === void 0 ? void 0 : message.mentionedUsers)
                && message.mentionedUsers.length > 0
                && (message === null || message === void 0 ? void 0 : message.mentionedMessageTemplate)
                && message.mentionedMessageTemplate.length > 0) {
                /* mention enabled */
                var _c = message.mentionedUsers, mentionedUsers_1 = _c === void 0 ? [] : _c;
                var tokens = tokenize.tokenizeMessage({
                    messageText: message === null || message === void 0 ? void 0 : message.mentionedMessageTemplate,
                    mentionedUsers: mentionedUsers_1,
                    includeMarkdown: channel.isGroupChannel() && config.groupChannel.enableMarkdownForUserMessage,
                });
                if (textField) {
                    textField.innerHTML = tokens
                        .map(function (token) {
                        if (token.type === tokenize.TOKEN_TYPES.mention) {
                            var mentionedUser = mentionedUsers_1.find(function (user) { return user.userId === token.userId; });
                            var nickname = "".concat(tokenize.USER_MENTION_PREFIX).concat((mentionedUser === null || mentionedUser === void 0 ? void 0 : mentionedUser.nickname) || token.value || stringSet.MENTION_NAME__NO_NAME);
                            return ui_MessageInput_hooks_usePaste.renderToString({
                                userId: token.userId,
                                nickname: nickname,
                            });
                        }
                        return ui_MessageInput_hooks_usePaste.sanitizeString(token.value);
                    })
                        .join('');
                }
            }
            else {
                /* mention disabled */
                try {
                    if (textField) {
                        textField.innerHTML = (_a = ui_MessageInput_hooks_usePaste.sanitizeString(message === null || message === void 0 ? void 0 : message.message)) !== null && _a !== void 0 ? _a : '';
                    }
                }
                catch (_d) {
                    //
                }
                setMentionedUserIds([]);
            }
            setIsInput((textField === null || textField === void 0 ? void 0 : textField.textContent) ? ((_b = textField === null || textField === void 0 ? void 0 : textField.textContent) === null || _b === void 0 ? void 0 : _b.trim().length) > 0 : false);
            setHeight();
        }
    }, [isEdit, message]);
    // #Mention | Detect MentionedLabel modified
    var useMentionedLabelDetection = React.useCallback(function () {
        var _a;
        var textField = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
        if (isMentionEnabled && textField) {
            var newMentionedUserIds = Array.from(textField.getElementsByClassName('sendbird-mention-user-label')).map(
            // @ts-ignore
            function (node) { var _a; return (_a = node === null || node === void 0 ? void 0 : node.dataset) === null || _a === void 0 ? void 0 : _a.userid; });
            if (!index.arrayEqual(mentionedUserIds, newMentionedUserIds) || newMentionedUserIds.length === 0) {
                onMentionedUserIdsUpdated(newMentionedUserIds);
                setMentionedUserIds(newMentionedUserIds);
            }
        }
        setIsInput((textField === null || textField === void 0 ? void 0 : textField.textContent) ? ((_a = textField.textContent) === null || _a === void 0 ? void 0 : _a.trim().length) > 0 : false);
    }, [targetStringInfo, isMentionEnabled]);
    // #Mention | Replace selected user nickname to the MentionedUserLabel
    React.useEffect(function () {
        var _a, _b, _c, _d;
        if (isMentionEnabled && mentionSelectedUser) {
            var targetString = targetStringInfo.targetString, startNodeIndex = targetStringInfo.startNodeIndex, startOffsetIndex = targetStringInfo.startOffsetIndex, endNodeIndex = targetStringInfo.endNodeIndex, endOffsetIndex = targetStringInfo.endOffsetIndex;
            var textField_1 = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
            if (targetString && startNodeIndex !== null && startOffsetIndex !== null && endOffsetIndex !== null && endNodeIndex !== null && textField_1) {
                // const textField = document.getElementById(textFieldId);
                var childNodes = ui_MessageInput_hooks_usePaste.nodeListToArray(textField_1 === null || textField_1 === void 0 ? void 0 : textField_1.childNodes);
                var startNodeTextContent = (_b = (_a = childNodes[startNodeIndex]) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '';
                var frontTextNode = document.createTextNode(startNodeTextContent.slice(0, startOffsetIndex));
                var endNodeTextContent = (_d = (_c = childNodes[endNodeIndex]) === null || _c === void 0 ? void 0 : _c.textContent) !== null && _d !== void 0 ? _d : '';
                var backTextNode = endOffsetIndex && document.createTextNode("\u00A0".concat(endNodeTextContent.slice(endOffsetIndex)));
                var mentionLabel = ui_MessageInput_hooks_usePaste.renderToString({
                    userId: mentionSelectedUser === null || mentionSelectedUser === void 0 ? void 0 : mentionSelectedUser.userId,
                    nickname: "".concat(_const.USER_MENTION_TEMP_CHAR).concat((mentionSelectedUser === null || mentionSelectedUser === void 0 ? void 0 : mentionSelectedUser.nickname) || stringSet.MENTION_NAME__NO_NAME),
                });
                var div = document.createElement('div');
                div.innerHTML = mentionLabel;
                var newNodes = _tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray([], childNodes.slice(0, startNodeIndex), true), [
                    frontTextNode,
                    div.childNodes[0],
                    backTextNode
                ], false), childNodes.slice(endNodeIndex + 1), true);
                if (textField_1) {
                    textField_1.innerHTML = '';
                    newNodes.forEach(function (newNode) {
                        if (newNode) {
                            textField_1.appendChild(newNode);
                        }
                    });
                }
                onUserMentioned(mentionSelectedUser);
                if (window.getSelection || document.getSelection) {
                    // set caret postion
                    var selection = window.getSelection() || document.getSelection();
                    selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
                    var range = new Range();
                    range.selectNodeContents(textField_1);
                    range.setStart(textField_1.childNodes[startNodeIndex + 2], 1);
                    range.setEnd(textField_1.childNodes[startNodeIndex + 2], 1);
                    range.collapse(false);
                    selection === null || selection === void 0 ? void 0 : selection.addRange(range);
                    textField_1.focus();
                }
                setTargetStringInfo(_tslib.__assign({}, initialTargetStringInfo));
                setHeight();
                useMentionedLabelDetection();
            }
        }
    }, [mentionSelectedUser, isMentionEnabled]);
    // #Mention | Detect mentioning user nickname
    var useMentionInputDetection = React.useCallback(function () {
        var _a, _b;
        var selection = ((_a = window === null || window === void 0 ? void 0 : window.getSelection) === null || _a === void 0 ? void 0 : _a.call(window)) || ((_b = document === null || document === void 0 ? void 0 : document.getSelection) === null || _b === void 0 ? void 0 : _b.call(document));
        var textField = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
        if ((selection === null || selection === void 0 ? void 0 : selection.anchorNode) === textField) {
            onMentionStringChange('');
        }
        if (isMentionEnabled
            && textField
            && selection
            && selection.anchorNode === selection.focusNode
            && selection.anchorOffset === selection.focusOffset) {
            var textStack = '';
            var startNodeIndex = null;
            var startOffsetIndex = null;
            var _loop_1 = function (index) {
                var currentNode = textField.childNodes[index];
                if (currentNode.nodeType === _const$1.NodeTypes.TextNode) {
                    /* text node */
                    var textContent = (function () {
                        var _a;
                        if (currentNode === selection.anchorNode) {
                            return (currentNode === null || currentNode === void 0 ? void 0 : currentNode.textContent) ? currentNode === null || currentNode === void 0 ? void 0 : currentNode.textContent.slice(0, selection.anchorOffset) : '';
                        }
                        return (_a = currentNode === null || currentNode === void 0 ? void 0 : currentNode.textContent) !== null && _a !== void 0 ? _a : '';
                    })();
                    if (textStack.length > 0) {
                        textStack += textContent;
                    }
                    else {
                        var charLastIndex = textContent.lastIndexOf(_const.USER_MENTION_TEMP_CHAR);
                        for (var i = charLastIndex - 1; i > -1; i -= 1) {
                            if (textContent[i] === _const.USER_MENTION_TEMP_CHAR) {
                                charLastIndex = i;
                            }
                            else {
                                break;
                            }
                        }
                        if (charLastIndex > -1) {
                            textStack = textContent;
                            startNodeIndex = index;
                            startOffsetIndex = charLastIndex;
                        }
                    }
                }
                else {
                    /* other nodes */
                    textStack = '';
                    startNodeIndex = null;
                    startOffsetIndex = null;
                }
                if (currentNode === selection.anchorNode) {
                    /**
                     * targetString could be ''
                     * startNodeIndex and startOffsetIndex could be null
                     */
                    var targetString = textStack && startOffsetIndex !== null ? textStack.slice(startOffsetIndex) : ''; // include template character
                    setTargetStringInfo({
                        targetString: targetString,
                        startNodeIndex: startNodeIndex,
                        startOffsetIndex: startOffsetIndex,
                        endNodeIndex: index,
                        endOffsetIndex: selection.anchorOffset,
                    });
                    onMentionStringChange(targetString);
                    return { value: void 0 };
                }
            };
            for (var index = 0; index < textField.childNodes.length; index += 1) {
                var state_1 = _loop_1(index);
                if (typeof state_1 === "object")
                    return state_1.value;
            }
        }
    }, [isMentionEnabled]);
    var sendMessage = function () {
        var textField = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
        if (!isEdit && (textField === null || textField === void 0 ? void 0 : textField.textContent)) {
            var _a = ui_MessageInput_hooks_usePaste.extractTextAndMentions(textField.childNodes), messageText = _a.messageText, mentionTemplate = _a.mentionTemplate;
            var params = { message: messageText, mentionTemplate: mentionTemplate };
            onSendMessage(params);
            resetInput(internalRef);
            /**
             * Note: contentEditable does not work as expected in mobile WebKit (Safari).
             * @see https://github.com/sendbird/sendbird-uikit-react/pull/1108
             */
            if (browser.isMobileIOS(navigator.userAgent)) {
                if (ghostInputRef.current)
                    ghostInputRef.current.focus();
                requestAnimationFrame(function () { return textField.focus(); });
            }
            else {
                // important: keeps the keyboard open -> must add test on refactor
                textField.focus();
            }
            setIsInput(false);
            setHeight();
        }
    };
    var isEditDisabled = !((_b = (_a = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim());
    var editMessage = function () {
        var textField = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current;
        var messageId = message === null || message === void 0 ? void 0 : message.messageId;
        if (isEdit && messageId && textField) {
            var _a = ui_MessageInput_hooks_usePaste.extractTextAndMentions(textField.childNodes), messageText = _a.messageText, mentionTemplate = _a.mentionTemplate;
            var params = { messageId: messageId, message: messageText, mentionTemplate: mentionTemplate };
            onUpdateMessage(params);
            resetInput(internalRef);
        }
    };
    var onPaste = ui_MessageInput_hooks_usePaste.usePaste({
        ref: internalRef,
        setMentionedUsers: setMentionedUsers,
        channel: channel,
        setIsInput: setIsInput,
        setHeight: setHeight,
    });
    return (React.createElement("form", { className: utils.classnames.apply(void 0, _tslib.__spreadArray(_tslib.__spreadArray([], (Array.isArray(className) ? className : [className]), false), [isEdit && 'sendbird-message-input__edit',
            disabled && 'sendbird-message-input-form__disabled'], false)) },
        React.createElement("div", { className: utils.classnames('sendbird-message-input', disabled && 'sendbird-message-input__disabled'), "data-testid": "sendbird-message-input" },
            browser.isMobileIOS(navigator.userAgent) && (React.createElement("input", { id: 'ghost-input-reset-ime-cjk', ref: ghostInputRef, style: { opacity: 0, padding: 0, margin: 0, height: 0, border: 'none', position: 'absolute', top: -9999 }, defaultValue: '_' })),
            React.createElement("div", { id: "".concat(textFieldId).concat(isEdit ? message === null || message === void 0 ? void 0 : message.messageId : ''), className: "sendbird-message-input--textarea ".concat(textFieldId), contentEditable: !disabled, role: "textbox", "aria-label": "Text Input", ref: externalRef, 
                // @ts-ignore
                disabled: disabled, maxLength: maxLength, onKeyDown: function (e) {
                    var _a, _b, _c, _d;
                    var preventEvent = onKeyDown(e);
                    if (preventEvent) {
                        e.preventDefault();
                    }
                    else {
                        if (!e.shiftKey
                            && e.key === _const$1.MessageInputKeys.Enter
                            && !isMobile
                            && ((_a = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current) === null || _a === void 0 ? void 0 : _a.textContent)
                            && internalRef.current.textContent.trim().length > 0
                            && ((_b = e === null || e === void 0 ? void 0 : e.nativeEvent) === null || _b === void 0 ? void 0 : _b.isComposing) !== true
                        /**
                         * NOTE: What isComposing does?
                         * Check if the user has finished composing characters
                         * (e.g., for languages like Korean, Japanese, where characters are composed from multiple keystrokes)
                         * Prevents executing the code while the user is still composing characters.
                         */
                        ) {
                            e.preventDefault();
                            sendMessage();
                        }
                        if (e.key === _const$1.MessageInputKeys.Backspace
                            && ((_d = (_c = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current) === null || _c === void 0 ? void 0 : _c.childNodes) === null || _d === void 0 ? void 0 : _d.length) === 2
                            && !internalRef.current.childNodes[0].textContent
                            && internalRef.current.childNodes[1].nodeType === _const$1.NodeTypes.ElementNode) {
                            internalRef.current.removeChild(internalRef.current.childNodes[1]);
                        }
                    }
                }, onKeyUp: function (e) {
                    var preventEvent = onKeyUp(e);
                    if (preventEvent) {
                        e.preventDefault();
                    }
                    else {
                        useMentionInputDetection();
                    }
                }, onClick: function () {
                    useMentionInputDetection();
                }, onInput: function () {
                    var _a;
                    setHeight();
                    onStartTyping();
                    setIsInput(((_a = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current) === null || _a === void 0 ? void 0 : _a.textContent) ? internalRef.current.textContent.trim().length > 0 : false);
                    useMentionedLabelDetection();
                }, onPaste: onPaste }),
            ((_e = (_d = (_c = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) === 0 && (React.createElement(ui_Label.Label, { className: "sendbird-message-input--placeholder", type: ui_Label.LabelTypography.BODY_1, color: disabled ? ui_Label.LabelColors.ONBACKGROUND_4 : ui_Label.LabelColors.ONBACKGROUND_3 }, placeholder || stringSet.MESSAGE_INPUT__PLACE_HOLDER)),
            !isEdit && isInput && (React.createElement(ui_IconButton, { className: "sendbird-message-input--send", height: "32px", width: "32px", onClick: function () { return sendMessage(); }, testID: "sendbird-message-input-send-button" }, (renderSendMessageIcon === null || renderSendMessageIcon === void 0 ? void 0 : renderSendMessageIcon()) || (React.createElement(ui_Icon.default, { type: ui_Icon.IconTypes.SEND, fillColor: disabled ? ui_Icon.IconColors.ON_BACKGROUND_4 : ui_Icon.IconColors.PRIMARY, width: "20px", height: "20px" })))),
            !isEdit
                && !isInput
                && ((renderFileUploadIcon === null || renderFileUploadIcon === void 0 ? void 0 : renderFileUploadIcon())
                    // UIKit Dashboard configuration should have lower priority than
                    // renderFileUploadIcon which is set in code level
                    || (isFileUploadEnabled && (React.createElement(ui_IconButton, { className: utils.classnames('sendbird-message-input--attach', isVoiceMessageEnabled && 'is-voice-message-enabled'), height: "32px", width: "32px", onClick: function () {
                            var _a, _b;
                            // todo: clear previous input
                            (_b = (_a = fileInputRef === null || fileInputRef === void 0 ? void 0 : fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click) === null || _b === void 0 ? void 0 : _b.call(_a);
                        } },
                        React.createElement(ui_Icon.default, { type: ui_Icon.IconTypes.ATTACH, fillColor: disabled ? ui_Icon.IconColors.ON_BACKGROUND_4 : ui_Icon.IconColors.CONTENT_INVERSE, width: "20px", height: "20px" }),
                        React.createElement("input", { className: "sendbird-message-input--attach-input", type: "file", ref: fileInputRef, 
                            // It will affect to <Channel /> and <Thread />
                            onChange: function (event) {
                                var files = event.currentTarget.files;
                                if (files) {
                                    onFileUpload(files && files.length === 1 ? [files[0]] : Array.from(files));
                                }
                                event.target.value = '';
                            }, accept: index.getMimeTypesUIKitAccepts(acceptableMimeTypes), multiple: isSelectingMultipleFilesEnabled && ui_MessageInput_hooks_usePaste.isChannelTypeSupportsMultipleFilesMessage(channel) }))))),
            isVoiceMessageEnabled && !isEdit && !isInput && (React.createElement(ui_IconButton, { className: "sendbird-message-input--voice-message", width: "32px", height: "32px", onClick: onVoiceMessageIconClick }, (renderVoiceMessageIcon === null || renderVoiceMessageIcon === void 0 ? void 0 : renderVoiceMessageIcon()) || (React.createElement(ui_Icon.default, { type: ui_Icon.IconTypes.AUDIO_ON_LINED, fillColor: disabled ? ui_Icon.IconColors.ON_BACKGROUND_4 : ui_Icon.IconColors.CONTENT_INVERSE, width: "20px", height: "20px" }))))),
        isEdit && (React.createElement("div", { className: "sendbird-message-input--edit-action", "data-testid": "sendbird-message-input--edit-action" },
            React.createElement(ui_Button.default, { className: "sendbird-message-input--edit-action__cancel", type: ui_Button.ButtonTypes.SECONDARY, size: ui_Button.ButtonSizes.SMALL, onClick: onCancelEdit }, stringSet.BUTTON__CANCEL),
            React.createElement(ui_Button.default, { className: "sendbird-message-input--edit-action__save", type: ui_Button.ButtonTypes.PRIMARY, size: ui_Button.ButtonSizes.SMALL, disabled: isEditDisabled, onClick: function () { return editMessage(); } }, stringSet.BUTTON__SAVE)))));
});

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