"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var TableRow_1 = require("./components/TableRow");
var TableRowWithDnd_1 = require("./components/TableRowWithDnd");
var DndComponent_1 = require("./components/DndComponent");
var VerticalHeadingsTable = function (_a) {
    var className = _a.className, rowsData = _a.rowsData, columnsData = _a.columnsData, containerRef = _a.containerRef, _b = _a.theadRowsNumber, theadRowsNumber = _b === void 0 ? 0 : _b, onMoveRow = _a.onMoveRow, onDropRow = _a.onDropRow, onMoveColumn = _a.onMoveColumn, onDropColumn = _a.onDropColumn, setHoveredColumn = _a.setHoveredColumn, resetHoveredColumn = _a.resetHoveredColumn;
    var columnsId = (0, react_1.useMemo)(function () { return columnsData.map(function (columnData) { return columnData.id; }); }, [columnsData]);
    var rowsId = (0, react_1.useMemo)(function () { return rowsData.map(function (rowData) { return rowData.id; }); }, [rowsData]);
    var isMoveColumnEnabled = !!onMoveColumn;
    return (react_1.default.createElement(DndComponent_1.DndComponent, { containerRef: containerRef, onMoveColumn: onMoveColumn, onDropColumn: onDropColumn, onMoveRow: onMoveRow, onDropRow: onDropRow, columnsId: columnsId, rowsId: rowsId, tableClassName: className },
        react_1.default.createElement("table", { className: className },
            theadRowsNumber > 0 && (react_1.default.createElement("thead", null, rowsData.slice(0, theadRowsNumber).map(function (rowData, index) { return (react_1.default.createElement(TableRow_1.TableRow, { key: rowData.id || index, rowData: rowData, columnsData: columnsData, index: index, isMoveColumnEnabled: isMoveColumnEnabled, setHoveredColumn: setHoveredColumn, resetHoveredColumn: resetHoveredColumn })); }))),
            react_1.default.createElement("tbody", null, rowsData.slice(theadRowsNumber).map(function (rowData, index) {
                return onMoveRow ? (react_1.default.createElement(TableRowWithDnd_1.TableRowWithDnd, { key: rowData.id || index, rowData: rowData, columnsData: columnsData, isMoveColumnEnabled: isMoveColumnEnabled, setHoveredColumn: setHoveredColumn, resetHoveredColumn: resetHoveredColumn })) : (react_1.default.createElement(TableRow_1.TableRow, { key: rowData.id || index, index: index + theadRowsNumber, rowData: rowData, columnsData: columnsData, isMoveColumnEnabled: isMoveColumnEnabled, setHoveredColumn: setHoveredColumn, resetHoveredColumn: resetHoveredColumn }));
            })))));
};
exports.default = (0, react_1.memo)(VerticalHeadingsTable);
