'use strict';

var _tslib = require('../chunks/bundle-CxoFSSXv.js');
var React = require('react');
var ui_Label = require('../chunks/bundle-B0UICprZ.js');
var ui_Icon = require('./Icon.js');
var ui_TextButton = require('./TextButton.js');
var index = require('../chunks/bundle-D7YiKR6i.js');
var color = require('../chunks/bundle-BIrmQghI.js');
var MediaQueryContext = require('../chunks/bundle-CyQD5TkW.js');
var utils = require('../chunks/bundle-DQNu-S6D.js');
var useSendbird = require('../chunks/bundle-LI9JjqG2.js');
require('../chunks/bundle-EhtiN7UV.js');
require('@sendbird/chat/groupChannel');
require('../utils/message/getOutgoingMessageState.js');
require('../chunks/bundle-dfqZUdij.js');
require('../chunks/bundle-Dn0hi6OJ.js');
require('../chunks/bundle-C1G0SKDq.js');
require('../chunks/bundle-yU9Mr2pS.js');
require('../chunks/bundle-AAO7jUU2.js');
require('@sendbird/chat');
require('@sendbird/chat/openChannel');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefaultCompat(React);

function FileMessageItemBody(_a) {
    var _this = this;
    var _b;
    var _c = _a.className, className = _c === void 0 ? '' : _c, message = _a.message, _d = _a.isByMe, isByMe = _d === void 0 ? false : _d, _e = _a.mouseHover, mouseHover = _e === void 0 ? false : _e, _f = _a.isReactionEnabled, isReactionEnabled = _f === void 0 ? false : _f, truncateLimit = _a.truncateLimit, onBeforeDownloadFileMessage = _a.onBeforeDownloadFileMessage;
    var logger = null;
    try {
        var globalLogger = useSendbird.useSendbird().state.config.logger;
        logger = globalLogger;
    }
    catch (err) {
        // TODO: Handle error
    }
    var isMobile = MediaQueryContext.useMediaQueryContext().isMobile;
    var truncateMaxNum = truncateLimit !== null && truncateLimit !== void 0 ? truncateLimit : (isMobile ? 20 : undefined);
    var downloadFileWithUrl = function () { return utils.openURL(message === null || message === void 0 ? void 0 : message.url); };
    var handleOnClickTextButton = onBeforeDownloadFileMessage
        ? function () { return _tslib.__awaiter(_this, void 0, void 0, function () {
            var allowDownload, err_1;
            var _a, _b;
            return _tslib.__generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        _c.trys.push([0, 2, , 3]);
                        return [4 /*yield*/, onBeforeDownloadFileMessage({ message: message })];
                    case 1:
                        allowDownload = _c.sent();
                        if (allowDownload) {
                            downloadFileWithUrl();
                        }
                        else {
                            (_a = logger === null || logger === void 0 ? void 0 : logger.info) === null || _a === void 0 ? void 0 : _a.call(logger, 'FileMessageItemBody: Not allowed to download.');
                        }
                        return [3 /*break*/, 3];
                    case 2:
                        err_1 = _c.sent();
                        (_b = logger === null || logger === void 0 ? void 0 : logger.error) === null || _b === void 0 ? void 0 : _b.call(logger, 'FileMessageItemBody: Error occurred while determining download continuation:', err_1);
                        return [3 /*break*/, 3];
                    case 3: return [2 /*return*/];
                }
            });
        }); }
        : downloadFileWithUrl;
    return (React__default.default.createElement("div", { className: index.getClassName([
            className,
            'sendbird-file-message-item-body',
            isByMe ? 'outgoing' : 'incoming',
            mouseHover ? 'mouse-hover' : '',
            (isReactionEnabled && ((_b = message === null || message === void 0 ? void 0 : message.reactions) === null || _b === void 0 ? void 0 : _b.length) > 0) ? 'reactions' : '',
        ]) },
        React__default.default.createElement("div", { className: "sendbird-file-message-item-body__file-icon" },
            React__default.default.createElement(ui_Icon.default, { className: "sendbird-file-message-item-body__file-icon__icon", type: {
                    IMAGE: ui_Icon.IconTypes.PHOTO,
                    VIDEO: ui_Icon.IconTypes.PLAY,
                    AUDIO: ui_Icon.IconTypes.FILE_AUDIO,
                    GIF: ui_Icon.IconTypes.GIF,
                    OTHERS: ui_Icon.IconTypes.FILE_DOCUMENT,
                }[index.getUIKitFileType(message === null || message === void 0 ? void 0 : message.type)], fillColor: ui_Icon.IconColors.PRIMARY, width: "24px", height: "24px" })),
        React__default.default.createElement(ui_TextButton, { className: "sendbird-file-message-item-body__file-name", onClick: handleOnClickTextButton, color: isByMe ? color.Colors.ONCONTENT_1 : color.Colors.ONBACKGROUND_1 },
            React__default.default.createElement(ui_Label.Label, { className: "sendbird-file-message-item-body__file-name__text", testID: "sendbird-file-message-item-body__file-name__text", type: ui_Label.LabelTypography.BODY_1, color: isByMe ? ui_Label.LabelColors.ONCONTENT_1 : ui_Label.LabelColors.ONBACKGROUND_1 }, index.truncateString((message === null || message === void 0 ? void 0 : message.name) || (message === null || message === void 0 ? void 0 : message.url), truncateMaxNum)))));
}

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