"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.DCRChangesSummary = void 0;
var react_1 = __importStar(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var Skeleton_1 = __importDefault(require("@mui/material/Skeleton"));
var MdmModuleContext_1 = require("../../../../../contexts/MdmModuleContext");
var helpers_1 = require("../../helpers");
var common_1 = require("../../../helpers/common");
var DCRChangesSummary_module_css_1 = __importDefault(require("./DCRChangesSummary.module.css"));
var ChangeItem = function (_a) {
    var count = _a.count, operation = _a.operation;
    return count > 0 && (react_1.default.createElement("div", { className: DCRChangesSummary_module_css_1.default.changeItem },
        react_1.default.createElement("div", { className: (0, classnames_1.default)(DCRChangesSummary_module_css_1.default.changeNumber, DCRChangesSummary_module_css_1.default[operation]) }, count),
        react_1.default.createElement("div", { className: DCRChangesSummary_module_css_1.default.changeLabel }, (0, common_1.getOperationLabel)(operation))));
};
var LoadingSkeleton = function () { return (react_1.default.createElement(react_1.default.Fragment, null, Array.from({ length: 4 }).map(function (_, index) { return (react_1.default.createElement("div", { key: "summary-changes-skeleton-".concat(index), className: DCRChangesSummary_module_css_1.default.changeItem },
    react_1.default.createElement(Skeleton_1.default, { variant: "text", width: 24, height: 16, className: DCRChangesSummary_module_css_1.default.changeNumber }),
    react_1.default.createElement(Skeleton_1.default, { variant: "text", width: 60, height: 13, className: DCRChangesSummary_module_css_1.default.changeLabel }))); }))); };
var DCRChangesSummary = function (_a) {
    var changes = _a.changes, groupedObjects = _a.groupedObjects;
    var metadata = (0, MdmModuleContext_1.useMdmMetadata)();
    var dcrChanges = (0, react_1.useMemo)(function () { return (changes ? (0, helpers_1.calculateDCRChanges)(metadata, changes, groupedObjects) : null); }, [metadata, changes, groupedObjects]);
    var changesLoaded = !!dcrChanges && groupedObjects.length > 0;
    return (react_1.default.createElement("div", { className: DCRChangesSummary_module_css_1.default.changesSummary, "data-reltio-id": "dcr-changes-summary" },
        !changesLoaded && react_1.default.createElement(LoadingSkeleton, null),
        changesLoaded &&
            Object.entries(dcrChanges).map(function (_a) {
                var operation = _a[0], count = _a[1];
                return (react_1.default.createElement(ChangeItem, { key: operation, count: count, operation: operation }));
            })));
};
exports.DCRChangesSummary = DCRChangesSummary;
