"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mouseCell = void 0;
var common_1 = require("../common");
function mouseCell(grid, type) {
    return function (e, coords, td) {
        var row = coords.row, column = coords.col;
        var payload = toMousePayload(e, type, grid, column, row);
        if (payload) {
            grid.fire({ type: 'GRID/mouse', payload: payload });
        }
        if (payload && type === 'UP') {
            grid.fire({
                type: 'GRID/mouse',
                payload: toMousePayload(e, 'CLICK', grid, column, row),
            });
        }
    };
}
exports.mouseCell = mouseCell;
function toMousePayload(e, type, grid, column, row) {
    var cell = common_1.coord.cell.toKey(column, row);
    var cellType = common_1.coord.cell.toType({ row: row, column: column });
    if (!cellType) {
        return;
    }
    var payload = {
        cell: cell,
        cellType: cellType,
        button: e.button === 2 ? 'RIGHT' : 'LEFT',
        grid: grid,
        type: type,
        isCancelled: false,
        cancel: function () {
            e.preventDefault();
            e.stopImmediatePropagation();
            payload.isCancelled = true;
        },
    };
    return payload;
}
