'use strict';

var _tslib = require('./bundle-H3iUL9jU.js');
var React = require('react');
var Channel_context = require('../Channel/context.js');
var useSendbirdStateContext = require('../useSendbirdStateContext.js');
var TypingIndicator = require('./bundle-jI1VVAdg.js');
var Channel_components_MessageList = require('./bundle-qLmNEs3L.js');
var ui_ConnectionStatus = require('../ui/ConnectionStatus.js');
var ui_PlaceHolder = require('../ui/PlaceHolder.js');
var Channel_components_ChannelHeader = require('./bundle-5E4_BBHS.js');
var Channel_components_MessageInput = require('../Channel/components/MessageInput.js');

var GroupChannelUIView = function (props) {
    var _a, _b, _c, _d;
    var loading = props.loading, isInvalid = props.isInvalid, channelUrl = props.channelUrl, renderChannelHeader = props.renderChannelHeader, renderMessageList = props.renderMessageList, renderMessageInput = props.renderMessageInput, renderTypingIndicator = props.renderTypingIndicator, renderPlaceholderLoader = props.renderPlaceholderLoader, renderPlaceholderInvalid = props.renderPlaceholderInvalid;
    var _e = useSendbirdStateContext.useSendbirdStateContext(), stores = _e.stores, config = _e.config;
    var sdkError = (_a = stores === null || stores === void 0 ? void 0 : stores.sdkStore) === null || _a === void 0 ? void 0 : _a.error;
    var logger = config.logger, isOnline = config.isOnline;
    if (loading) {
        return React.createElement("div", { className: "sendbird-conversation" }, (renderPlaceholderLoader === null || renderPlaceholderLoader === void 0 ? void 0 : renderPlaceholderLoader()) || React.createElement(ui_PlaceHolder.default, { type: ui_PlaceHolder.PlaceHolderTypes.LOADING }));
    }
    if (!channelUrl) {
        return (React.createElement("div", { className: "sendbird-conversation" }, (renderPlaceholderInvalid === null || renderPlaceholderInvalid === void 0 ? void 0 : renderPlaceholderInvalid()) || React.createElement(ui_PlaceHolder.default, { type: ui_PlaceHolder.PlaceHolderTypes.NO_CHANNELS })));
    }
    if (isInvalid) {
        return React.createElement("div", { className: "sendbird-conversation" }, (renderPlaceholderInvalid === null || renderPlaceholderInvalid === void 0 ? void 0 : renderPlaceholderInvalid()) || React.createElement(ui_PlaceHolder.default, { type: ui_PlaceHolder.PlaceHolderTypes.WRONG }));
    }
    if (sdkError) {
        return (React.createElement("div", { className: "sendbird-conversation" }, (renderPlaceholderInvalid === null || renderPlaceholderInvalid === void 0 ? void 0 : renderPlaceholderInvalid()) || (React.createElement(ui_PlaceHolder.default, { type: ui_PlaceHolder.PlaceHolderTypes.WRONG, retryToConnect: function () {
                logger.info('Channel: reconnecting');
                // reconnect();
            } }))));
    }
    return (React.createElement("div", { className: "sendbird-conversation" }, renderChannelHeader === null || renderChannelHeader === void 0 ? void 0 :
        renderChannelHeader({ className: 'sendbird-conversation__channel-header' }), renderMessageList === null || renderMessageList === void 0 ? void 0 :
        renderMessageList(props),
        React.createElement("div", { className: "sendbird-conversation__footer" }, renderMessageInput === null || renderMessageInput === void 0 ? void 0 :
            renderMessageInput(),
            React.createElement("div", { className: "sendbird-conversation__footer__typing-indicator" },
                (renderTypingIndicator === null || renderTypingIndicator === void 0 ? void 0 : renderTypingIndicator())
                    || (((_b = config === null || config === void 0 ? void 0 : config.groupChannel) === null || _b === void 0 ? void 0 : _b.enableTypingIndicator) && ((_d = (_c = config === null || config === void 0 ? void 0 : config.groupChannel) === null || _c === void 0 ? void 0 : _c.typingIndicatorTypes) === null || _d === void 0 ? void 0 : _d.has(Channel_components_MessageList.TypingIndicatorType.Text)) && (React.createElement(TypingIndicator.TypingIndicator, { channelUrl: channelUrl }))),
                !isOnline && React.createElement(ui_ConnectionStatus, null)))));
};

var ChannelUI = function (props) {
    var _a;
    var context = Channel_context.useChannelContext();
    var channelUrl = context.channelUrl, isInvalid = context.isInvalid, loading = context.loading;
    // Inject components to presentation layer
    var _b = props.renderChannelHeader, renderChannelHeader = _b === void 0 ? function (p) { return React.createElement(Channel_components_ChannelHeader.ChannelHeader, _tslib.__assign({}, p)); } : _b, _c = props.renderMessageList, renderMessageList = _c === void 0 ? function (p) { return React.createElement(Channel_components_MessageList.MessageList, _tslib.__assign({}, p, { className: "sendbird-conversation__message-list" })); } : _c, _d = props.renderMessageInput, renderMessageInput = _d === void 0 ? function () { return React.createElement(Channel_components_MessageInput.MessageInputWrapper, _tslib.__assign({}, props)); } : _d;
    return (React.createElement(GroupChannelUIView, _tslib.__assign({}, props, context, { loading: (_a = props === null || props === void 0 ? void 0 : props.isLoading) !== null && _a !== void 0 ? _a : loading, isInvalid: isInvalid, channelUrl: channelUrl, renderChannelHeader: renderChannelHeader, renderMessageList: renderMessageList, renderMessageInput: renderMessageInput })));
};

exports.ChannelUI = ChannelUI;
exports.GroupChannelUIView = GroupChannelUIView;
//# sourceMappingURL=bundle-3MlXHMIm.js.map
