import React from "react";
//@ts-ignore
import { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatMessageTypes, GroupMemberScope, MessageCategoryConstants, MessageOptionConstants, MessageTypeConstants } from "../constants/UIKitConstants";
import { CometChatMessageTemplate } from "../modals/CometChatMessageTemplate";
import { localize } from "../resources/CometChatLocalize";
import { CometChatTextBubble } from "../views/CometChatTextBubble";
import { CometChatVideoBubble } from "../views/CometChatVideoBubble";
import { CometChatImageBubble } from "../views/CometChatImageBubble";
import { CometChatAudioBubble } from "../views/CometChatAudioBubble";
import { CometChatFileBubble } from "../views/CometChatFileBubble";
import { ChatConfigurator } from "./ChatConfigurator";
import { ICONS } from "./resources";
import { CometChatConversationUtils } from "../utils/conversationUtils";
import { CometChatFormBubble, CometChatCardBubble } from "../views";
import { CometChatSchedulerBubble } from "../views/CometChatSchedulerBubble";
import { View } from "react-native";
import { CommonUtils } from "../utils/CommonUtils";
import { CometChatUIKit } from "../CometChatUiKit";
import { CometChatMentionsFormatter, CometChatUrlsFormatter, MentionTextStyle } from "../formatters";
function isAudioMessage(message) {
    return message.getCategory() == CometChat.CATEGORY_MESSAGE &&
        message.getType() == CometChat.MESSAGE_TYPE.AUDIO;
}
function isVideoMessage(message) {
    return message.getCategory() == CometChat.CATEGORY_MESSAGE &&
        message.getType() == CometChat.MESSAGE_TYPE.VIDEO;
}
function isFileMessage(message) {
    return message.getCategory() == CometChat.CATEGORY_MESSAGE &&
        message.getType() == CometChat.MESSAGE_TYPE.FILE;
}
function isActionMessage(message) {
    return message.getCategory() == CometChat.CATEGORY_ACTION;
}
function isTextMessage(message) {
    return message.getCategory() == CometChat.CATEGORY_MESSAGE &&
        message.getType() == CometChat.MESSAGE_TYPE.TEXT;
}
function isImageMessage(message) {
    return message.getCategory() == CometChat.CATEGORY_MESSAGE &&
        message.getType() == CometChat.MESSAGE_TYPE.IMAGE;
}
function isDeletedMessage(message) {
    return message.getDeletedBy() != null;
}
export class MessageDataSource {
    getEditOption() {
        return {
            id: MessageOptionConstants.editMessage,
            title: localize("EDIT"),
            icon: ICONS.EDIT
        };
    }
    getDeleteOption() {
        return {
            id: MessageOptionConstants.deleteMessage,
            title: localize("DELETE"),
            icon: ICONS.DELETE
        };
    }
    getReplyOption() {
        return {
            id: MessageOptionConstants.replyMessage,
            title: localize("REPLY"),
            icon: ICONS.REPLY
        };
    }
    getReplyInThreadOption() {
        return {
            id: MessageOptionConstants.replyInThread,
            title: localize("REPLY"),
            icon: ICONS.THREAD
        };
    }
    getShareOption() {
        return {
            id: MessageOptionConstants.shareMessage,
            title: localize("SHARE"),
            icon: ICONS.SHARE
        };
    }
    getCopyOption() {
        return {
            id: MessageOptionConstants.copyMessage,
            title: localize("COPY"),
            icon: ICONS.COPY
        };
    }
    // getForwardOption(): CometChatMessageOption {
    //     return {
    //         id: MessageOptionConstants.forwardMessage,
    //         title: localize("FORWARD"),
    //         icon: ICONS.FORWARD
    //     }
    // }
    getInformationOption() {
        return {
            id: MessageOptionConstants.messageInformation,
            title: localize("INFO"),
            icon: ICONS.INFO
        };
    }
    getPrivateMessageOption() {
        return {
            id: MessageOptionConstants.sendMessagePrivately,
            title: localize('MESSAGE_PRIVATELY'),
            icon: ICONS.PRIVATE_MESSAGE
        };
    }
    isSentByMe(loggedInUser, message) {
        if (!loggedInUser)
            return false;
        return loggedInUser.getUid() == message?.getSender()?.getUid();
    }
    getTextMessageOptions(loggedInUser, messageObject, group) {
        let messageOptionList = [];
        if (isDeletedMessage(messageObject))
            return messageOptionList;
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.replyInThread)) {
            messageOptionList.push(this.getReplyInThreadOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.shareMessage)) {
            messageOptionList.push(this.getShareOption());
        }
        messageOptionList.push(this.getCopyOption());
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.editMessage)) {
            messageOptionList.push(this.getEditOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.messageInformation)) {
            messageOptionList.push(this.getInformationOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.deleteMessage)) {
            messageOptionList.push(this.getDeleteOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.sendMessagePrivately)) {
            messageOptionList.push(this.getPrivateMessageOption());
        }
        return messageOptionList;
    }
    getFormMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (!isDeletedMessage(messageObject))
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        return optionsList;
    }
    getSchedulerMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (!isDeletedMessage(messageObject))
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        return optionsList;
    }
    getCardMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (!isDeletedMessage(messageObject))
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        return optionsList;
    }
    getAudioMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (!isDeletedMessage(messageObject))
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        return optionsList;
    }
    getVideoMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (!isDeletedMessage(messageObject))
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        return optionsList;
    }
    getImageMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (!isDeletedMessage(messageObject))
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        return optionsList;
    }
    getFileMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (!isDeletedMessage(messageObject))
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        return optionsList;
    }
    getMessageOptions(loggedInUser, messageObject, group) {
        let optionsList = [];
        if (isDeletedMessage(messageObject))
            return optionsList;
        if (messageObject.getCategory() == MessageCategoryConstants.message) {
            let type = messageObject.getType();
            switch (type) {
                case MessageTypeConstants.audio:
                    optionsList.push(...ChatConfigurator.dataSource.getAudioMessageOptions(loggedInUser, messageObject, group));
                    break;
                case MessageTypeConstants.video:
                    optionsList.push(...ChatConfigurator.dataSource.getVideoMessageOptions(loggedInUser, messageObject, group));
                    break;
                case MessageTypeConstants.image:
                    optionsList.push(...ChatConfigurator.dataSource.getImageMessageOptions(loggedInUser, messageObject, group));
                    break;
                case MessageTypeConstants.text:
                    optionsList.push(...ChatConfigurator.dataSource.getTextMessageOptions(loggedInUser, messageObject, group));
                    break;
                case MessageTypeConstants.file:
                    optionsList.push(...ChatConfigurator.dataSource.getFileMessageOptions(loggedInUser, messageObject, group));
                    break;
            }
        }
        else if (messageObject.getCategory() == MessageCategoryConstants.custom) {
            optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
        }
        else if (messageObject.getCategory() == MessageCategoryConstants.interactive) {
            let type = messageObject.getType();
            switch (type) {
                case MessageTypeConstants.form:
                    optionsList.push(...ChatConfigurator.dataSource.getFormMessageOptions(loggedInUser, messageObject, group));
                    break;
                case MessageTypeConstants.card:
                    optionsList.push(...ChatConfigurator.dataSource.getCardMessageOptions(loggedInUser, messageObject, group));
                    break;
                case MessageTypeConstants.scheduler:
                    optionsList.push(...ChatConfigurator.dataSource.getSchedulerMessageOptions(loggedInUser, messageObject, group));
                    break;
            }
        }
        return optionsList;
    }
    validateOption(loggedInUser, messageObject, group, optionId) {
        if (MessageOptionConstants.replyInThread === optionId && (!messageObject.parentMessageId || messageObject.parentMessageId === 0)) {
            return true;
        }
        if (MessageOptionConstants.shareMessage === optionId && (messageObject instanceof CometChat.TextMessage || messageObject instanceof CometChat.MediaMessage)) {
            return true;
        }
        if (MessageOptionConstants.copyMessage === optionId && messageObject instanceof CometChat.TextMessage) {
            return true;
        }
        let isSentByMe = this.isSentByMe(loggedInUser, messageObject);
        if (MessageOptionConstants.messageInformation === optionId && isSentByMe) {
            return true;
        }
        let memberIsNotParticipant = group && (group.owner === loggedInUser.uid || group.scope !== GroupMemberScope.participant);
        if (MessageOptionConstants.deleteMessage === optionId && (isSentByMe || memberIsNotParticipant)) {
            return true;
        }
        if (MessageOptionConstants.editMessage === optionId && (isSentByMe || memberIsNotParticipant)) {
            return true;
        }
        if (MessageOptionConstants.copyMessage === optionId && messageObject instanceof CometChat.TextMessage) {
            return true;
        }
        if (MessageOptionConstants.sendMessagePrivately === optionId && group
            && loggedInUser.getUid() != messageObject.getSender()?.getUid()) {
            return true;
        }
        return false;
    }
    getCommonOptions(loggedInUser, messageObject, group) {
        let messageOptionList = [];
        if (isDeletedMessage(messageObject))
            return messageOptionList;
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.replyInThread)) {
            messageOptionList.push(this.getReplyInThreadOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.shareMessage)) {
            messageOptionList.push(this.getShareOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.messageInformation)) {
            messageOptionList.push(this.getInformationOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.deleteMessage)) {
            messageOptionList.push(this.getDeleteOption());
        }
        if (this.validateOption(loggedInUser, messageObject, group, MessageOptionConstants.sendMessagePrivately)) {
            messageOptionList.push(this.getPrivateMessageOption());
        }
        return messageOptionList;
    }
    getGroupActionBubble(message, theme) {
        if (isActionMessage(message)) {
            return <CometChatTextBubble text={`${message.getMessage()}`} textContainerStyle={{ marginStart: 4, marginEnd: 4 }} style={{
                    backgroundColor: theme?.palette?.getAccent50(),
                    textFont: {
                        fontSize: theme?.typography?.subtitle2?.fontSize,
                        fontWeight: theme?.typography?.subtitle2?.fontWeight,
                    },
                    textColor: theme?.palette?.getAccent600()
                }}/>;
        }
        return null;
    }
    getBottomView(message, alignment) {
        return null;
    }
    getDeleteMessageBubble(message, theme) {
        return <View style={{ paddingBottom: 8, borderWidth: 1, borderStyle: "dashed", borderRadius: 8, borderColor: theme?.palette?.getAccent600() }}>
            <CometChatTextBubble textContainerStyle={{ marginStart: 4, marginEnd: 4 }} text={localize("MESSAGE_IS_DELETED")} style={{
                backgroundColor: "transparent",
                textFont: {
                    fontSize: theme?.typography?.subtitle2?.fontSize,
                    fontWeight: theme?.typography?.subtitle2?.fontWeight,
                },
                textColor: theme?.palette?.getAccent600()
            }}/>
        </View>;
    }
    getVideoMessageBubble(videoUrl, thumbnailUrl, message, theme, videoBubbleStyle) {
        if (isVideoMessage(message)) {
            return <CometChatVideoBubble videoUrl={videoUrl} thumbnailUrl={{ uri: thumbnailUrl }} style={{ height: 200, width: 200, borderRadius: 8, ...videoBubbleStyle }}/>;
        }
        return null;
    }
    getTextMessageBubble(messageText, message, alignment, theme, additionalParams) {
        let loggedInUser = CometChatUIKit.loggedInUser;
        let mentionedUsers = message.getMentionedUsers();
        let textFormatters = [...(additionalParams?.textFormatters || [])] || [];
        let linksTextFormatter = ChatConfigurator.getDataSource().getUrlsFormatter(loggedInUser);
        linksTextFormatter.setMessage(message);
        linksTextFormatter.setId("ccDefaultUrlsFormatterId");
        textFormatters.push(linksTextFormatter);
        if (!additionalParams?.disableMentions && mentionedUsers && mentionedUsers.length) {
            let mentionsTextFormatter = ChatConfigurator.getDataSource().getMentionsFormatter(loggedInUser);
            mentionsTextFormatter.setLoggedInUser(loggedInUser);
            mentionsTextFormatter.setId("ccDefaultMentionFormatterId");
            let isUserSentMessage = alignment === "right";
            if (isUserSentMessage) {
                mentionsTextFormatter.setMentionsStyle(new MentionTextStyle({
                    loggedInUserTextStyle: {
                        color: theme.palette.getTertiary(),
                        ...theme.typography.title2,
                        fontSize: 16
                    },
                    textStyle: {
                        color: theme.palette.getTertiary(),
                        ...theme.typography.subtitle1,
                        fontSize: 16
                    },
                }));
            }
            else {
                mentionsTextFormatter.setMentionsStyle(new MentionTextStyle({
                    loggedInUserTextStyle: {
                        color: theme.palette.getPrimary(),
                        ...theme.typography.title2,
                        fontSize: 16
                    },
                    textStyle: {
                        color: theme.palette.getPrimary(),
                        ...theme.typography.subtitle1,
                        fontSize: 16
                    },
                }));
            }
            textFormatters.push(mentionsTextFormatter);
        }
        let finalFormatters = [];
        let customerHasPassedUrlsFormatter;
        textFormatters.forEach(formatter => {
            if (formatter instanceof CometChatUrlsFormatter) {
                if (formatter.getId() !== "ccDefaultUrlsFormatterId") {
                    customerHasPassedUrlsFormatter = true;
                }
            }
            formatter.setMessage(message);
            let suggestionUsers = formatter.getSuggestionItems();
            suggestionUsers.length > 0 && formatter.setSuggestionItems(suggestionUsers);
            let _formatter = CommonUtils.clone(formatter);
            finalFormatters.push(_formatter);
        });
        if (customerHasPassedUrlsFormatter) {
            let customUrlsIndex = finalFormatters.findIndex((formatter) => (formatter instanceof CometChatUrlsFormatter && formatter.getId() === "ccDefaultUrlsFormatterId"));
            if (customUrlsIndex > -1) {
                finalFormatters.splice(customUrlsIndex, 1);
            }
        }
        return <CometChatTextBubble text={messageText} style={{
                backgroundColor: "transparent",
                textFont: theme?.typography.body,
                textColor: alignment == "right" ? theme?.palette.getSecondary() : theme?.palette?.getAccent(),
                borderRadius: 8
            }} textFormatters={finalFormatters}/>;
    }
    getFormMessageBubble(message, theme, style, onSubmitClick) {
        return <CometChatFormBubble message={message} onSubmitClick={onSubmitClick} style={style}/>;
    }
    getSchedulerMessageBubble(message, theme, style, onScheduleClick) {
        return <CometChatSchedulerBubble schedulerMessage={message} onScheduleClick={onScheduleClick} style={style}/>;
    }
    getCardMessageBubble(message, theme, style, onSubmitClick) {
        return <CometChatCardBubble message={message} onSubmitClick={onSubmitClick} style={style}/>;
    }
    getImageMessageBubble(imageUrl, caption, style, message, theme) {
        if (isImageMessage(message)) {
            return <CometChatImageBubble imageUrl={{ uri: imageUrl }} style={{ height: 200, width: 200, borderRadius: 8, ...style }}/>;
        }
        return null;
    }
    getAudioMessageBubble(audioUrl, title, style, message, theme) {
        if (isAudioMessage(message)) {
            return <CometChatAudioBubble audioUrl={audioUrl} title={title} style={{ width: 200, borderRadius: 8, ...style }}/>;
        }
        return null;
    }
    getFileMessageBubble(fileUrl, title, style, message, theme) {
        if (isFileMessage(message)) {
            return <CometChatFileBubble fileUrl={fileUrl} title={title} style={{ width: 200, ...style }}/>;
        }
        return null;
    }
    getTextMessageContentView(message, alignment, theme, additionalParams) {
        return ChatConfigurator.dataSource.getTextMessageBubble(message.getText(), message, alignment, theme, additionalParams);
    }
    getFormMessageContentView(message, alignment, theme) {
        return ChatConfigurator.dataSource.getFormMessageBubble(message, theme);
    }
    getSchedulerMessageContentView(message, alignment, theme) {
        return ChatConfigurator.dataSource.getSchedulerMessageBubble(message, theme);
    }
    getCardMessageContentView(message, alignment, theme) {
        return ChatConfigurator.dataSource.getCardMessageBubble(message, theme);
    }
    getAudioMessageContentView(message, alignment, theme) {
        let attachment = message.getAttachment();
        return ChatConfigurator.dataSource.getAudioMessageBubble(attachment.getUrl(), attachment.getName(), {
            iconTint: theme?.palette?.getPrimary(),
            backgroundColor: "transparent",
            titleColor: theme?.palette.getAccent(),
            titleFont: theme?.typography.body,
            subtitleColor: theme?.palette.getAccent(),
            subtitleFont: theme?.typography.subtitle1,
        }, message, theme);
    }
    getVideoMessageContentView(message, alignment, theme) {
        let attachment = message.getAttachment();
        return ChatConfigurator.dataSource.getVideoMessageBubble(attachment.getUrl(), undefined, message, theme, {
            backgroundColor: "transparent",
            playIconBackgroundColor: theme?.palette?.getAccent50(),
            playIconTint: theme?.palette.getPrimary(),
        });
    }
    getImageMessageContentView(message, alignment, theme) {
        let attachment = message.getAttachment();
        let url = attachment.getUrl();
        if (url == undefined)
            url = message['data']['url'];
        return ChatConfigurator.dataSource.getImageMessageBubble(url, attachment.getName(), {
            backgroundColor: theme?.palette.getAccent50()
        }, message, theme);
    }
    getFileMessageContentView(message, alignment, theme) {
        let attachment = message.getAttachment();
        return ChatConfigurator.dataSource.getFileMessageBubble(attachment.getUrl(), attachment.getName(), {
            iconTint: theme?.palette?.getPrimary(),
            backgroundColor: "transparent",
            titleColor: theme?.palette.getAccent(),
            titleFont: theme?.typography.body,
            subtitleColor: theme?.palette.getAccent(),
            subtitleFont: theme?.typography.subtitle1,
        }, message, theme);
    }
    getTextMessageTemplate(theme, additionalParams) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.text,
            category: MessageCategoryConstants.message,
            ContentView: (message, _alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else {
                    return ChatConfigurator.dataSource.getTextMessageContentView(message, _alignment, theme, additionalParams);
                }
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getTextMessageOptions(loggedInuser, message, group),
        });
    }
    getFormMessageTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.form,
            category: MessageCategoryConstants.interactive,
            ContentView: (message, _alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else {
                    return ChatConfigurator.dataSource.getFormMessageContentView(message, _alignment, theme);
                }
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getFormMessageOptions(loggedInuser, message, group),
        });
    }
    getSchedulerMessageTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.scheduler,
            category: MessageCategoryConstants.interactive,
            ContentView: (message, _alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else {
                    return ChatConfigurator.dataSource.getSchedulerMessageContentView(message, _alignment, theme);
                }
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getSchedulerMessageOptions(loggedInuser, message, group),
        });
    }
    getCardMessageTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.card,
            category: MessageCategoryConstants.interactive,
            ContentView: (message, _alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else {
                    return ChatConfigurator.dataSource.getCardMessageContentView(message, _alignment, theme);
                }
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getCardMessageOptions(loggedInuser, message, group),
        });
    }
    getAudioMessageTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.audio,
            category: MessageCategoryConstants.message,
            ContentView: (message, alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else
                    return ChatConfigurator.dataSource.getAudioMessageContentView(message, alignment, theme);
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getAudioMessageOptions(loggedInuser, message, group),
        });
    }
    getVideoMessageTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.video,
            category: MessageCategoryConstants.message,
            ContentView: (message, alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else
                    return ChatConfigurator.dataSource.getVideoMessageContentView(message, alignment, theme);
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getVideoMessageOptions(loggedInuser, message, group),
        });
    }
    getImageMessageTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.image,
            category: MessageCategoryConstants.message,
            ContentView: (message, alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else
                    return ChatConfigurator.dataSource.getImageMessageContentView(message, alignment, theme);
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getImageMessageOptions(loggedInuser, message, group),
        });
    }
    getFileMessageTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.file,
            category: MessageCategoryConstants.message,
            ContentView: (message, alignment) => {
                if (isDeletedMessage(message)) {
                    return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
                }
                else
                    return ChatConfigurator.dataSource.getFileMessageContentView(message, alignment, theme);
            },
            options: (loggedInuser, message, group) => ChatConfigurator.dataSource.getFileMessageOptions(loggedInuser, message, group),
        });
    }
    getGroupActionTemplate(theme) {
        return new CometChatMessageTemplate({
            type: MessageTypeConstants.groupMember,
            category: MessageCategoryConstants.action,
            ContentView: (message, alignment) => {
                return ChatConfigurator.dataSource.getGroupActionBubble(message, theme);
            }
        });
    }
    getAllMessageTemplates(theme, additionalParams) {
        return [
            ChatConfigurator.dataSource.getTextMessageTemplate(theme, additionalParams),
            ChatConfigurator.dataSource.getFormMessageTemplate(theme),
            ChatConfigurator.dataSource.getSchedulerMessageTemplate(theme),
            ChatConfigurator.dataSource.getCardMessageTemplate(theme),
            ChatConfigurator.dataSource.getAudioMessageTemplate(theme),
            ChatConfigurator.dataSource.getVideoMessageTemplate(theme),
            ChatConfigurator.dataSource.getFileMessageTemplate(theme),
            ChatConfigurator.dataSource.getImageMessageTemplate(theme),
            ChatConfigurator.dataSource.getGroupActionTemplate(theme)
        ];
    }
    getMessageTemplate(messageType, MessageCategory, theme) {
        // let _theme: CometChatTheme = useContext("theme")         ???
        let template;
        //in case of call message return undefined
        if (MessageCategory == MessageCategoryConstants.call)
            return template;
        switch (messageType) {
            case MessageTypeConstants.text:
                template = ChatConfigurator.dataSource.getTextMessageTemplate(theme);
                break;
            case MessageTypeConstants.audio:
                template = ChatConfigurator.dataSource.getAudioMessageTemplate(theme);
                break;
            case MessageTypeConstants.video:
                template = ChatConfigurator.dataSource.getVideoMessageTemplate(theme);
                break;
            case MessageTypeConstants.groupActions:
            case MessageTypeConstants.groupMember:
                template = ChatConfigurator.dataSource.getGroupActionTemplate(theme);
                break;
            case MessageTypeConstants.file:
                template = ChatConfigurator.dataSource.getFileMessageTemplate(theme);
                break;
            case MessageTypeConstants.form:
                template = ChatConfigurator.dataSource.getFormMessageTemplate(theme);
                break;
            case MessageTypeConstants.scheduler:
                template = ChatConfigurator.dataSource.getSchedulerMessageTemplate(theme);
                break;
            case MessageTypeConstants.card:
                template = ChatConfigurator.dataSource.getCardMessageTemplate(theme);
                break;
        }
        return template;
    }
    getAllMessageTypes() {
        return [
            CometChatMessageTypes.text,
            CometChatMessageTypes.image,
            CometChatMessageTypes.audio,
            CometChatMessageTypes.video,
            CometChatMessageTypes.file,
            MessageTypeConstants.groupActions,
            MessageTypeConstants.groupMember,
            MessageTypeConstants.form,
            MessageTypeConstants.card,
            MessageTypeConstants.scheduler
        ];
    }
    getAllMessageCategories() {
        return [MessageCategoryConstants.message, MessageCategoryConstants.action, MessageCategoryConstants.interactive];
    }
    getAuxiliaryOptions(user, group, id, theme) {
        return [];
    }
    getAuxiliaryHeaderAppbarOptions(user, group) {
        return null;
    }
    getId() {
        return "messageUtils";
    }
    getMessageTypeToSubtitle(messageType) {
        let subtitle = messageType;
        switch (messageType) {
            case MessageTypeConstants.text:
                subtitle = localize("TEXT");
                break;
            case MessageTypeConstants.image:
                subtitle = localize("MESSAGE_IMAGE");
                break;
            case MessageTypeConstants.video:
                subtitle = localize("MESSAGE_VIDEO");
                break;
            case MessageTypeConstants.file:
                subtitle = localize("MESSAGE_FILE");
                break;
            case MessageTypeConstants.audio:
                subtitle = localize("MESSAGE_AUDIO");
                break;
            default:
                subtitle = messageType;
                break;
        }
        return subtitle;
    }
    usersActionList = () => [
        {
            id: MessageTypeConstants.takePhoto,
            title: localize('TAKE_PHOTO'),
            iconUrl: ICONS.IMAGE,
            onClick: null,
        },
        {
            id: MessageTypeConstants.image,
            title: localize('ATTACH_IMAGE'),
            iconUrl: ICONS.IMAGE,
            onClick: null,
        },
        {
            id: MessageTypeConstants.audio,
            title: localize('ATTACH_AUDIO'),
            iconUrl: ICONS.AUDIO,
            onClick: null,
        },
        {
            id: MessageTypeConstants.video,
            title: localize('ATTACH_VIDEO'),
            iconUrl: ICONS.VIDEO,
            onClick: null,
        },
        {
            id: MessageTypeConstants.file,
            title: localize('ATTACH_FILE'),
            iconUrl: ICONS.FILE,
            onClick: null,
        },
    ];
    groupActionList = () => [
        {
            id: MessageTypeConstants.takePhoto,
            title: localize('TAKE_PHOTO'),
            iconUrl: ICONS.IMAGE,
            onClick: null,
        },
        {
            id: MessageTypeConstants.image,
            title: localize('ATTACH_IMAGE'),
            iconUrl: ICONS.IMAGE,
            onClick: null,
        },
        {
            id: MessageTypeConstants.audio,
            title: localize('ATTACH_AUDIO'),
            iconUrl: ICONS.AUDIO,
            onClick: null,
        },
        {
            id: MessageTypeConstants.video,
            title: localize('ATTACH_VIDEO'),
            iconUrl: ICONS.VIDEO,
            onClick: null,
        },
        {
            id: MessageTypeConstants.file,
            title: localize('ATTACH_FILE'),
            iconUrl: ICONS.FILE,
            onClick: null,
        },
    ];
    getAttachmentOptions(user, group, composerId) {
        if (user) {
            return this.usersActionList();
        }
        else if (group) {
            return this.groupActionList();
        }
        else {
            return this.usersActionList();
        }
    }
    getAuxiliaryButtonOptions() {
        return null;
    }
    getAIOptions(user, group, theme, id, AIOptionsStyle) {
        return [];
    }
    getLastConversationMessage(conversation) {
        return CometChatConversationUtils.getMessagePreview(conversation.getLastMessage());
    }
    ;
    getAllTextFormatters(loggedInUser) {
        return [ChatConfigurator.getDataSource().getMentionsFormatter(loggedInUser),
            ChatConfigurator.getDataSource().getUrlsFormatter(loggedInUser)];
    }
    getMentionsFormatter(loggedInUser) {
        return new CometChatMentionsFormatter(loggedInUser);
    }
    getUrlsFormatter(loggedInUser) {
        return new CometChatUrlsFormatter(loggedInUser);
    }
}
//# sourceMappingURL=MessageDataSource.js.map