import { SlickEventHandler, SlickEventData } from '../core/index';
export class GridEventService {
    get eventHandler() {
        return this._eventHandler;
    }
    constructor() {
        this._eventHandler = new SlickEventHandler();
    }
    dispose() {
        this._eventHandler.unsubscribeAll();
    }
    /* OnBeforeEditCell Event */
    bindOnBeforeEditCell(grid) {
        const dataView = grid?.getData();
        // subscribe to this Slickgrid event of onBeforeEditCell
        this._eventHandler.subscribe(grid.onBeforeEditCell, (e, args) => {
            if (!e || !args || !grid || args.cell === undefined || !grid.getColumns || !grid.getDataItem) {
                return;
            }
            const column = grid.getColumns()[args.cell];
            // if the column definition has a onBeforeEditCell property (a callback function), then run it
            if (typeof column.onBeforeEditCell === 'function') {
                // add to the output gridOptions & dataView since we'll need them inside the AJAX column.onBeforeEditCell
                const returnedArgs = {
                    row: args.row,
                    cell: args.cell,
                    dataView,
                    grid,
                    columnDef: column,
                    dataContext: grid.getDataItem(args.row)
                };
                // finally call up the Slick column.onBeforeEditCells.... function
                column.onBeforeEditCell(e instanceof SlickEventData ? e.getNativeEvent() : e, returnedArgs);
            }
        });
    }
    /* OnCellChange Event */
    bindOnCellChange(grid) {
        const dataView = grid?.getData();
        // subscribe to this Slickgrid event of onCellChange
        this._eventHandler.subscribe(grid.onCellChange, (e, args) => {
            if (!e || !args || !grid || args.cell === undefined || !grid.getColumns || !grid.getDataItem) {
                return;
            }
            const column = grid.getColumns()[args.cell];
            // if the column definition has a onCellChange property (a callback function), then run it
            if (typeof column.onCellChange === 'function') {
                // add to the output gridOptions & dataView since we'll need them inside the AJAX column.onCellChange
                const returnedArgs = {
                    row: args.row,
                    cell: args.cell,
                    dataView,
                    grid,
                    columnDef: column,
                    dataContext: grid.getDataItem(args.row)
                };
                // finally call up the Slick column.onCellChanges.... function
                column.onCellChange(e instanceof SlickEventData ? e.getNativeEvent() : e, returnedArgs);
            }
        });
    }
    /* OnClick Event */
    bindOnClick(grid) {
        const dataView = grid?.getData();
        this._eventHandler.subscribe(grid.onClick, (e, args) => {
            if (!e || !args || !grid || args.cell === undefined || !grid.getColumns || !grid.getDataItem) {
                return;
            }
            const column = grid.getColumns()[args.cell];
            // if the column definition has a onCellClick property (a callback function), then run it
            if (typeof column.onCellClick === 'function') {
                // add to the output gridOptions & dataView since we'll need them inside the AJAX column.onClick
                const returnedArgs = {
                    row: args.row,
                    cell: args.cell,
                    dataView,
                    grid,
                    columnDef: column,
                    dataContext: grid.getDataItem(args.row)
                };
                // finally call up the Slick column.onCellClick.... function
                column.onCellClick(e instanceof SlickEventData ? e.getNativeEvent() : e, returnedArgs);
            }
        });
    }
}
//# sourceMappingURL=gridEvent.service.js.map