"use strict";

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

const TABLE_EVENT_TYPE_1 = require("../../../core/TABLE_EVENT_TYPE");

function bindAxisHoverEvent(table) {
    table.isPivotChart() && (table.on(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.MOUSEENTER_CELL, (e => {
        table.scenegraph.getCell(e.col, e.row).forEachChildren((child => {
            if ("axis" === child.name) {
                const position = getAxisPosition(e.col, e.row, table.internalProps.layoutMap);
                e.axisPosition = position, table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.MOUSEENTER_AXIS, e);
            }
        }));
    })), table.on(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.MOUSELEAVE_CELL, (e => {
        table.scenegraph.getCell(e.col, e.row).forEachChildren((child => {
            if ("axis" === child.name) {
                const position = getAxisPosition(e.col, e.row, table.internalProps.layoutMap);
                e.axisPosition = position, table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.MOUSELEAVE_AXIS, e);
            }
        }));
    })));
}

function getAxisPosition(col, row, layout) {
    if (layout.indicatorsAsCol) {
        if (layout.hasTopIndicatorAxis && row === layout.columnHeaderLevelCount - 1 && col >= layout.rowHeaderLevelCount && col < layout.colCount - layout.rightFrozenColCount) return "top";
        if (row === layout.rowCount - layout.bottomFrozenRowCount && col >= layout.rowHeaderLevelCount && col < layout.colCount - layout.rightFrozenColCount) return "bottom";
        if (col === layout.rowHeaderLevelCount - 1 && row >= layout.rowHeaderLevelCount && row < layout.rowCount - layout.bottomFrozenRowCount) return "left";
    } else {
        if (col === layout.rowHeaderLevelCount - 1 && row >= layout.columnHeaderLevelCount && row < layout.rowCount - layout.bottomFrozenRowCount) return "left";
        if (col === layout.colCount - layout.rightFrozenColCount && row >= layout.columnHeaderLevelCount && row < layout.rowCount - layout.bottomFrozenRowCount) return "right";
        if (row === layout.rowCount - layout.bottomFrozenRowCount && col >= layout.rowHeaderLevelCount && col < layout.colCount - layout.rightFrozenColCount) return "bottom";
    }
    return "bottom";
}

exports.bindAxisHoverEvent = bindAxisHoverEvent;
//# sourceMappingURL=axis-hover.js.map
