'use strict';

var React = require('react');
var LocalizationContext = require('../chunks/bundle-DDNdw3A9.js');
var ui_Modal = require('../chunks/bundle-YeW89zsR.js');
var ui_Button = require('./Button.js');
var ui_Input = require('./Input.js');
var ui_Label = require('../chunks/bundle-B0UICprZ.js');
var MediaQueryContext = require('../chunks/bundle-CyQD5TkW.js');
var useKeyDown = require('../chunks/bundle-DNjcGEfJ.js');
require('../chunks/bundle-CxoFSSXv.js');
require('../chunks/bundle-EhtiN7UV.js');
require('../chunks/bundle-BV7y6VDn.js');
require('react-dom');
require('../chunks/bundle-DQNu-S6D.js');
require('./IconButton.js');
require('./Icon.js');
require('../chunks/bundle-BUGwK1WK.js');
require('../chunks/bundle-LI9JjqG2.js');
require('../chunks/bundle-AAO7jUU2.js');
require('../chunks/bundle-yU9Mr2pS.js');
require('@sendbird/chat');
require('@sendbird/chat/groupChannel');
require('@sendbird/chat/openChannel');
require('@sendbird/uikit-tools');

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

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

function MessageFeedbackModal(props) {
    var _a, _b;
    var selectedFeedback = props.selectedFeedback, message = props.message, onClose = props.onClose, onSubmit = props.onSubmit, onUpdate = props.onUpdate, onRemove = props.onRemove;
    var stringSet = React.useContext(LocalizationContext.LocalizationContext).stringSet;
    var isMobile = MediaQueryContext.useMediaQueryContext().isMobile;
    var isEdit = (message === null || message === void 0 ? void 0 : message.myFeedback) && selectedFeedback === message.myFeedback.rating;
    var hasComment = (_a = message === null || message === void 0 ? void 0 : message.myFeedback) === null || _a === void 0 ? void 0 : _a.comment;
    var onSubmitWrapper = function () {
        var _a, _b, _c;
        if (!selectedFeedback)
            return;
        var comment = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
        if (isEdit) {
            if (comment !== ((_c = message.myFeedback) === null || _c === void 0 ? void 0 : _c.comment)) {
                onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(selectedFeedback, comment);
            }
            else {
                onClose === null || onClose === void 0 ? void 0 : onClose();
            }
        }
        else if (!message.myFeedback) {
            onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(selectedFeedback, comment);
        }
    };
    var modalRef = React.useRef();
    var inputRef = React.useRef();
    var onKeyDown = useKeyDown.useKeyDown(modalRef, {
        Enter: function () { return onSubmitWrapper(); },
        Escape: function () { return onClose === null || onClose === void 0 ? void 0 : onClose(); },
    });
    return (React__default.default.createElement("div", { onKeyDown: onKeyDown },
        React__default.default.createElement(ui_Modal.Modal, { contentClassName: 'sendbird-message-feedback-modal-content__mobile', type: ui_Button.ButtonTypes.PRIMARY, onCancel: onClose, onSubmit: function () {
                onSubmitWrapper();
            }, submitText: stringSet.BUTTON__SUBMIT, renderHeader: function () { return (React__default.default.createElement("div", { className: 'sendbird-modal__header' },
                React__default.default.createElement(ui_Label.Label, { type: ui_Label.LabelTypography.H_1, color: ui_Label.LabelColors.ONBACKGROUND_1, className: 'sendbird-message-feedback-modal-header' }, stringSet.FEEDBACK_MODAL_TITLE))); }, customFooter: React__default.default.createElement("div", { className: 'sendbird-message-feedback-modal-footer__root' },
                !isMobile && (message === null || message === void 0 ? void 0 : message.myFeedback) && selectedFeedback === message.myFeedback.rating
                    ? React__default.default.createElement(ui_Button.default, { type: ui_Button.ButtonTypes.WARNING, onClick: onRemove, labelType: ui_Label.LabelTypography.BUTTON_3 }, stringSet.BUTTON__REMOVE_FEEDBACK)
                    : React__default.default.createElement("div", null),
                React__default.default.createElement("div", { className: 'sendbird-message-feedback-modal-footer__right-content' },
                    React__default.default.createElement(ui_Button.default, { type: ui_Button.ButtonTypes.SECONDARY, onClick: onClose },
                        React__default.default.createElement(ui_Label.Label, { type: ui_Label.LabelTypography.BUTTON_3, color: ui_Label.LabelColors.ONBACKGROUND_1 }, stringSet.BUTTON__CANCEL)),
                    React__default.default.createElement(ui_Button.default, { onClick: function () { return onSubmitWrapper(); } },
                        React__default.default.createElement(ui_Label.Label, { type: ui_Label.LabelTypography.BUTTON_3, color: ui_Label.LabelColors.ONCONTENT_1 }, hasComment ? stringSet.BUTTON__SAVE : stringSet.BUTTON__SUBMIT)))) },
            React__default.default.createElement("div", { className: 'sendbird-message-feedback-modal-body__root' },
                React__default.default.createElement(ui_Input.default, { name: 'sendbird-message-feedback-modal-body__root', ref: inputRef, value: isEdit ? (_b = message.myFeedback) === null || _b === void 0 ? void 0 : _b.comment : undefined, placeHolder: stringSet.FEEDBACK_CONTENT_PLACEHOLDER, autoFocus: true })))));
}

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