"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSettings = void 0;
var grid_1 = require("../grid");
var common_1 = require("../common");
var hooks = require("./hooks");
var DEFAULT = common_1.constants.DEFAULT;
function getSettings(args) {
    var grid = args.grid;
    var selectionHandler = hooks.afterSelectionHandler(grid);
    var createColumns = function (length) {
        var col = {
            renderer: DEFAULT.CELL.RENDERER,
            editor: grid_1.Editor,
        };
        return Array.from({ length: length }).map(function () { return col; });
    };
    var rowHeights = function (index) {
        var _a, _b;
        var height = grid.defaults.rowHeight;
        if (grid.isInitialized) {
            var row = grid.data.rows[index];
            var props = row ? row.props : undefined;
            height = props && ((_a = props.grid) === null || _a === void 0 ? void 0 : _a.height) !== undefined ? (_b = props.grid) === null || _b === void 0 ? void 0 : _b.height : height;
        }
        return height;
    };
    var colWidths = function (index) {
        var _a, _b;
        var width = grid.defaults.columnWidth;
        if (grid.isInitialized) {
            var key = common_1.coord.cell.toKey(index);
            var column = grid.data.columns[key];
            var props = column ? column.props : undefined;
            width = props && ((_a = props.grid) === null || _a === void 0 ? void 0 : _a.width) !== undefined ? (_b = props.grid) === null || _b === void 0 ? void 0 : _b.width : width;
        }
        return width;
    };
    var size = hooks.sizeHandlers(grid);
    var afterColumnResize = size.afterColumnResize, afterRowResize = size.afterRowResize, modifyColWidth = size.modifyColWidth, modifyRowHeight = size.modifyRowHeight;
    var afterSelection = selectionHandler.afterSelection, afterDeselect = selectionHandler.afterDeselect;
    var settings = {
        data: [],
        rowHeaders: true,
        rowHeights: rowHeights,
        colHeaders: true,
        colWidths: colWidths,
        columns: createColumns(grid.totalColumns),
        viewportRowRenderingOffset: 20,
        manualRowResize: true,
        manualColumnResize: true,
        renderAllRows: false,
        undo: false,
        beforeKeyDown: hooks.beforeKeyDownHandler(grid),
        afterSelection: afterSelection,
        afterDeselect: afterDeselect,
        afterColumnResize: afterColumnResize,
        afterRowResize: afterRowResize,
        modifyColWidth: modifyColWidth,
        modifyRowHeight: modifyRowHeight,
        fillHandle: true,
        beforeAutofill: function () {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            return false;
        },
        beforeAutofillInsidePopulate: function () {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            return false;
        },
        beforeOnCellMouseDown: hooks.mouseCell(grid, 'DOWN'),
        beforeOnCellMouseUp: hooks.mouseCell(grid, 'UP'),
        beforeOnCellMouseOver: hooks.mouseCell(grid, 'ENTER'),
        beforeOnCellMouseOut: hooks.mouseCell(grid, 'LEAVE'),
        beforeUndo: hooks.undo(grid, 'BEFORE', 'UNDO'),
        afterUndo: hooks.undo(grid, 'AFTER', 'UNDO'),
        beforeRedo: hooks.undo(grid, 'BEFORE', 'REDO'),
        afterRedo: hooks.undo(grid, 'AFTER', 'REDO'),
    };
    return settings;
}
exports.getSettings = getSettings;
