"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReviewDCRDialog = void 0;
var react_1 = __importDefault(require("react"));
var Dialog_1 = __importDefault(require("@mui/material/Dialog"));
var DialogTitle_1 = __importDefault(require("@mui/material/DialogTitle"));
var DialogContent_1 = __importDefault(require("@mui/material/DialogContent"));
var Typography_1 = __importDefault(require("@mui/material/Typography"));
var SmallIconButton_1 = require("../../../SmallIconButton");
var Close_1 = __importDefault(require("@mui/icons-material/Close"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var useWorkflowCheckPermission_1 = require("../hooks/useWorkflowCheckPermission");
var useWorkflowActions_1 = require("../hooks/useWorkflowActions");
var MdmModuleContext_1 = require("../../../contexts/MdmModuleContext");
var ProfileBand_1 = require("../../../ProfileBand");
var DueDateField_1 = require("../DueDateField");
var PrioritySelector_1 = require("../PrioritySelector");
var AssigneeSelector_1 = require("../AssigneeSelector");
var WorkflowComments_1 = require("../WorkflowComments");
var WorkflowActionButtons_1 = require("../WorkflowActionButtons");
var DCRSummaryInfo_1 = require("./components/DCRSummaryInfo/DCRSummaryInfo");
var ChangeRequestEditor_1 = require("../ChangeRequestEditor");
var useApplyDcrChanges_1 = require("../hooks/useApplyDcrChanges");
var DCRErrorsPanel_1 = require("./DCRErrorsPanel/DCRErrorsPanel");
var ReviewDCRDialog_module_css_1 = __importDefault(require("./ReviewDCRDialog.module.css"));
var ReviewDCRDialog = function (_a) {
    var open = _a.open, onClose = _a.onClose, dcr = _a.dcr, task = _a.task, groupedObjects = _a.groupedObjects;
    var entity = (0, MdmModuleContext_1.useMdmEntity)();
    var checkWorkflowPermission = (0, useWorkflowCheckPermission_1.useWorkflowCheckPermission)();
    var canViewComments = checkWorkflowPermission('VIEW_PROCESS_INSTANCE_COMMENTS');
    var applyDcrChanges = (0, useApplyDcrChanges_1.useApplyDcrChanges)(dcr);
    var _b = (0, useWorkflowActions_1.useWorkflowActions)({
        task: {
            taskId: task.taskId,
            possibleActions: task.possibleActions,
            assignee: task.assignee,
            isOpen: task.isOpen
        },
        beforeAction: applyDcrChanges
    }), workflowActions = _b.actions, actionRequestIsInProgress = _b.actionRequestIsInProgress;
    return (react_1.default.createElement(Dialog_1.default, { open: open, onClose: onClose, fullScreen: true },
        react_1.default.createElement(DialogTitle_1.default, { className: ReviewDCRDialog_module_css_1.default.dialogTitle },
            react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.titleContent },
                react_1.default.createElement(Typography_1.default, { variant: "h6", className: ReviewDCRDialog_module_css_1.default.titleText }, ui_i18n_1.default.text('Review DCR')),
                react_1.default.createElement(WorkflowActionButtons_1.WorkflowActionButtons, { workflowActions: workflowActions, actionRequestIsInProgress: actionRequestIsInProgress, preferredAction: task.preferredAction })),
            react_1.default.createElement(SmallIconButton_1.SmallIconButtonWithTooltip, { tooltipTitle: ui_i18n_1.default.text('Close'), "aria-label": ui_i18n_1.default.text('Close'), icon: Close_1.default, onClick: onClose, className: ReviewDCRDialog_module_css_1.default.closeButton, size: "L" })),
        react_1.default.createElement(DialogContent_1.default, { classes: { root: ReviewDCRDialog_module_css_1.default.content } },
            react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.leftSection },
                react_1.default.createElement(ProfileBand_1.ProfileBand, { entity: entity, className: ReviewDCRDialog_module_css_1.default.profileBandRoot, classes: { profileBand: ReviewDCRDialog_module_css_1.default.profileBand } }),
                react_1.default.createElement(DCRErrorsPanel_1.DCRErrorsPanel, null),
                react_1.default.createElement(DCRSummaryInfo_1.DCRSummaryInfo, { dcr: dcr, task: task, groupedObjects: groupedObjects }),
                react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.editableSection },
                    react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.editableGrid },
                        react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.editableItem },
                            react_1.default.createElement(DueDateField_1.DueDateField, { taskId: task.taskId, dueDate: task.dueDate, isTaskOpen: task.isOpen })),
                        react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.editableItem },
                            react_1.default.createElement(PrioritySelector_1.PrioritySelector, { taskId: task.taskId, priority: task.priority || 50, isTaskOpen: task.isOpen, className: ReviewDCRDialog_module_css_1.default.priorityField })),
                        react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.editableItem },
                            react_1.default.createElement(AssigneeSelector_1.AssigneeSelector, { taskId: task.taskId, assignee: task.assignee, isTaskOpen: task.isOpen })))),
                react_1.default.createElement("div", { className: ReviewDCRDialog_module_css_1.default.changesSection },
                    react_1.default.createElement(ChangeRequestEditor_1.ChangeRequestEditor, { dcr: dcr, task: task, groupedObjects: groupedObjects }))),
            canViewComments && (react_1.default.createElement(WorkflowComments_1.WorkflowComments, { workflowActions: workflowActions, actionRequestIsInProgress: actionRequestIsInProgress, preferredAction: task.preferredAction, taskId: task.taskId, processInstanceComments: task.processInstanceComments, isTaskOpen: task.isOpen, showActionButtons: false, alwaysExpanded: true, classes: {
                    container: ReviewDCRDialog_module_css_1.default.commentsRootContainer,
                    commentsContainer: ReviewDCRDialog_module_css_1.default.commentsContainer
                } })))));
};
exports.ReviewDCRDialog = ReviewDCRDialog;
