import { b as __awaiter, c as __generator } from '../chunks/bundle-B8Grfnrx.js';
import React__default from 'react';
import { L as Label, a as LabelTypography, b as LabelColors } from '../chunks/bundle-HspRRkmy.js';
import Icon, { IconTypes, IconColors } from './Icon.js';
import TextButton from './TextButton.js';
import { y as getClassName, p as getUIKitFileType, t as truncateString } from '../chunks/bundle-CgLhYjm5.js';
import { C as Colors } from '../chunks/bundle-DED6q4Ti.js';
import { u as useMediaQueryContext } from '../chunks/bundle-yKqHFFfz.js';
import { o as openURL } from '../chunks/bundle-CDcu1I4f.js';
import { u as useSendbird } from '../chunks/bundle-I25ah_Bv.js';
import '../chunks/bundle-Y2KBbxRr.js';
import '@sendbird/chat/groupChannel';
import '../utils/message/getOutgoingMessageState.js';
import '../chunks/bundle-BTxw_tIt.js';
import '../chunks/bundle-De-3zaYV.js';
import '../chunks/bundle-DYBTopZK.js';
import '../chunks/bundle-Ob7Cw3V-.js';
import '../chunks/bundle-C4OmfIXk.js';
import '@sendbird/chat';
import '@sendbird/chat/openChannel';

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().state.config.logger;
        logger = globalLogger;
    }
    catch (err) {
        // TODO: Handle error
    }
    var isMobile = useMediaQueryContext().isMobile;
    var truncateMaxNum = truncateLimit !== null && truncateLimit !== void 0 ? truncateLimit : (isMobile ? 20 : undefined);
    var downloadFileWithUrl = function () { return openURL(message === null || message === void 0 ? void 0 : message.url); };
    var handleOnClickTextButton = onBeforeDownloadFileMessage
        ? function () { return __awaiter(_this, void 0, void 0, function () {
            var allowDownload, err_1;
            var _a, _b;
            return __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.createElement("div", { className: 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.createElement("div", { className: "sendbird-file-message-item-body__file-icon" },
            React__default.createElement(Icon, { className: "sendbird-file-message-item-body__file-icon__icon", type: {
                    IMAGE: IconTypes.PHOTO,
                    VIDEO: IconTypes.PLAY,
                    AUDIO: IconTypes.FILE_AUDIO,
                    GIF: IconTypes.GIF,
                    OTHERS: IconTypes.FILE_DOCUMENT,
                }[getUIKitFileType(message === null || message === void 0 ? void 0 : message.type)], fillColor: IconColors.PRIMARY, width: "24px", height: "24px" })),
        React__default.createElement(TextButton, { className: "sendbird-file-message-item-body__file-name", onClick: handleOnClickTextButton, color: isByMe ? Colors.ONCONTENT_1 : Colors.ONBACKGROUND_1 },
            React__default.createElement(Label, { className: "sendbird-file-message-item-body__file-name__text", testID: "sendbird-file-message-item-body__file-name__text", type: LabelTypography.BODY_1, color: isByMe ? LabelColors.ONCONTENT_1 : LabelColors.ONBACKGROUND_1 }, truncateString((message === null || message === void 0 ? void 0 : message.name) || (message === null || message === void 0 ? void 0 : message.url), truncateMaxNum)))));
}

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