import { Editor } from '../grid';
import { constants, coord } from '../common';
import * as hooks from './hooks';
const { DEFAULT } = constants;
export function getSettings(args) {
    const { grid } = args;
    const selectionHandler = hooks.afterSelectionHandler(grid);
    const createColumns = (length) => {
        const col = {
            renderer: DEFAULT.CELL.RENDERER,
            editor: Editor,
        };
        return Array.from({ length }).map(() => col);
    };
    const rowHeights = (index) => {
        var _a, _b;
        let height = grid.defaults.rowHeight;
        if (grid.isInitialized) {
            const row = grid.data.rows[index];
            const 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;
    };
    const colWidths = (index) => {
        var _a, _b;
        let width = grid.defaults.columnWidth;
        if (grid.isInitialized) {
            const key = coord.cell.toKey(index);
            const column = grid.data.columns[key];
            const 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;
    };
    const size = hooks.sizeHandlers(grid);
    const { afterColumnResize, afterRowResize, modifyColWidth, modifyRowHeight } = size;
    const { afterSelection, afterDeselect } = selectionHandler;
    const settings = {
        data: [],
        rowHeaders: true,
        rowHeights,
        colHeaders: true,
        colWidths,
        columns: createColumns(grid.totalColumns),
        viewportRowRenderingOffset: 20,
        manualRowResize: true,
        manualColumnResize: true,
        renderAllRows: false,
        undo: false,
        beforeKeyDown: hooks.beforeKeyDownHandler(grid),
        afterSelection,
        afterDeselect,
        afterColumnResize,
        afterRowResize,
        modifyColWidth,
        modifyRowHeight,
        fillHandle: true,
        beforeAutofill(...args) {
            return false;
        },
        beforeAutofillInsidePopulate(...args) {
            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;
}
