"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMatchesColumnsData = void 0;
var react_1 = require("react");
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var helpers_1 = require("./helpers");
var useMatchesColumnsData = function (_a) {
    var defaultColumnsData = _a.defaultColumnsData, defaultVisibleColumns = _a.defaultVisibleColumns, additionalColumnsData = _a.additionalColumnsData, metadata = _a.metadata, entityTypeUri = _a.entityTypeUri, _b = _a.enableAttrColumnSorting, enableAttrColumnSorting = _b === void 0 ? false : _b;
    return (0, react_1.useMemo)(function () {
        var attrColumnsData = (0, helpers_1.getColumnsData)(metadata, entityTypeUri).map(function (column) {
            return enableAttrColumnSorting ? __assign(__assign({}, column), { sortable: true }) : column;
        });
        var allColumnsData = defaultColumnsData
            .concat(additionalColumnsData || [])
            .concat(attrColumnsData);
        var matchAttributes = (0, mdm_sdk_1.getEntityTypeMatchAttributes)(metadata, entityTypeUri);
        var groupedColumnsData = (0, helpers_1.groupColumnsDataByMatchAttributes)(matchAttributes, allColumnsData);
        var defaultColumns = (0, ramda_1.pipe)(helpers_1.getMatchAttrColumns, (0, ramda_1.pluck)('id'), (0, ramda_1.concat)(defaultVisibleColumns || (0, ramda_1.pluck)('id', defaultColumnsData)))(matchAttributes, attrColumnsData);
        return { allColumnsData: allColumnsData, groupedColumnsData: groupedColumnsData, defaultColumns: defaultColumns };
    }, [
        defaultColumnsData,
        additionalColumnsData,
        metadata,
        entityTypeUri,
        defaultVisibleColumns,
        enableAttrColumnSorting
    ]);
};
exports.useMatchesColumnsData = useMatchesColumnsData;
