"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.checkHaveDrill = exports.drillClick = exports.bindDrillEvent = void 0;

const TABLE_EVENT_TYPE_1 = require("../core/TABLE_EVENT_TYPE"), PIVOT_TABLE_EVENT_TYPE_1 = require("../ts-types/pivot-table/PIVOT_TABLE_EVENT_TYPE");

function bindDrillEvent(table) {
    table.on(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.MOUSEENTER_CELL, (e => {
        const {col: col, row: row} = e;
        if (-1 === col || -1 === row) return;
        const dimension = table.internalProps.layoutMap.getHeaderDimension(col, row);
        (null == dimension ? void 0 : dimension.drillDown) || (null == dimension ? void 0 : dimension.drillUp) ? table.stateManager.updateDrillState(dimension.dimensionKey, dimension.title, dimension.drillDown, dimension.drillUp, col, row) : table.stateManager.updateDrillState(void 0, void 0, !1, !1, -1, -1);
    })), table.on(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.MOUSELEAVE_TABLE, (e => {
        table.stateManager.updateDrillState(void 0, void 0, !1, !1, -1, -1);
    }));
}

function drillClick(table) {
    table.fireListeners(PIVOT_TABLE_EVENT_TYPE_1.PIVOT_TABLE_EVENT_TYPE.DRILLMENU_CLICK, table.stateManager.drill);
}

function checkHaveDrill(table) {
    const rowsDefine = table.internalProps.layoutMap.rowsDefine, columnsDefine = table.internalProps.layoutMap.columnsDefine;
    for (let i = 0; i < rowsDefine.length; i++) {
        const row = rowsDefine[i];
        if ("string" != typeof row && (row.drillDown || row.drillUp)) return !0;
    }
    for (let i = 0; i < columnsDefine.length; i++) {
        const column = columnsDefine[i];
        if ("string" != typeof column && (column.drillDown || column.drillUp)) return !0;
    }
    return !1;
}

exports.bindDrillEvent = bindDrillEvent, exports.drillClick = drillClick, exports.checkHaveDrill = checkHaveDrill;