"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommentDialog = void 0;
var react_1 = __importStar(require("react"));
var Button_1 = __importDefault(require("@mui/material/Button"));
var Dialog_1 = __importDefault(require("@mui/material/Dialog"));
var DialogActions_1 = __importDefault(require("@mui/material/DialogActions"));
var DialogContent_1 = __importDefault(require("@mui/material/DialogContent"));
var DialogTitle_1 = __importDefault(require("@mui/material/DialogTitle"));
var TextField_1 = __importDefault(require("@mui/material/TextField"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var CommentDialog_module_css_1 = __importDefault(require("./CommentDialog.module.css"));
var CommentDialog = function (_a) {
    var _b = _a.open, open = _b === void 0 ? true : _b, title = _a.title, confirmLabel = _a.confirmLabel, cancelLabel = _a.cancelLabel, _c = _a.defaultComment, defaultComment = _c === void 0 ? '' : _c, _d = _a.required, required = _d === void 0 ? true : _d, onConfirm = _a.onConfirm, onCancel = _a.onCancel;
    var _e = (0, react_1.useState)(defaultComment || ''), comment = _e[0], setComment = _e[1];
    var handleChangeComment = (0, react_1.useCallback)(function (e) {
        setComment(e.target.value);
    }, []);
    var handleConfirm = (0, react_1.useCallback)(function () {
        if (required && !comment.trim())
            return;
        onConfirm(comment);
        setComment('');
    }, [comment, required, onConfirm]);
    var handleCancel = (0, react_1.useCallback)(function () {
        onCancel();
    }, [onCancel]);
    var isConfirmDisabled = required && !comment.trim();
    return (react_1.default.createElement(Dialog_1.default, { open: open, onClose: handleCancel, fullWidth: true, classes: { paper: CommentDialog_module_css_1.default.dialog } },
        react_1.default.createElement(DialogTitle_1.default, { classes: { root: CommentDialog_module_css_1.default.dialogTitle } }, title || ui_i18n_1.default.text('Please provide a comment for your action')),
        react_1.default.createElement(DialogContent_1.default, { classes: { root: CommentDialog_module_css_1.default.dialogContent } },
            react_1.default.createElement(TextField_1.default, { autoFocus: true, multiline: true, minRows: 5, fullWidth: true, variant: "filled", value: comment, size: "small", onChange: handleChangeComment, required: required, InputLabelProps: {
                    classes: {
                        root: CommentDialog_module_css_1.default.inputLabelRoot,
                        asterisk: CommentDialog_module_css_1.default.asterisk
                    }
                }, InputProps: {
                    classes: {
                        input: CommentDialog_module_css_1.default.input,
                        formControl: CommentDialog_module_css_1.default.formControl
                    }
                }, label: ui_i18n_1.default.text('Type a comment') })),
        react_1.default.createElement(DialogActions_1.default, { classes: { root: CommentDialog_module_css_1.default.dialogActions } },
            react_1.default.createElement(Button_1.default, { onClick: handleCancel }, cancelLabel || ui_i18n_1.default.text('Cancel')),
            react_1.default.createElement(Button_1.default, { onClick: handleConfirm, disabled: isConfirmDisabled, color: "primary" }, confirmLabel || ui_i18n_1.default.text('Done')))));
};
exports.CommentDialog = CommentDialog;
