"use strict";

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

const vrender_1 = require("@visactor/vtable/es/vrender"), cell_range_1 = require("@visactor/vtable/es/tools/cell-range"), helper_1 = require("@visactor/vtable/es/tools/helper");

class InvertHighlightPlugin {
    constructor(table, options) {
        var _a, _b;
        this.table = table, this._fill = null !== (_a = null == options ? void 0 : options.fill) && void 0 !== _a ? _a : "#000", 
        this._opacity = null !== (_b = null == options ? void 0 : options.opacity) && void 0 !== _b ? _b : .5;
    }
    setInvertHighlightRange(range) {
        (0, cell_range_1.isSameRange)(this.range, range) || (this.range = range, range ? this.updateCellGroupShadow() : this.deleteAllCellGroupShadow(), 
        this.table.scenegraph.updateNextFrame());
    }
    deleteAllCellGroupShadow() {
        this.table.isPivotTable() || (this.updateCellGroupShadowInContainer(this.table.scenegraph.rowHeaderGroup), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.leftBottomCornerGroup)), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.bodyGroup), this.updateCellGroupShadowInContainer(this.table.scenegraph.rightFrozenGroup), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.bottomFrozenGroup), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.rightBottomCornerGroup);
    }
    updateCellGroupShadow() {
        this.table.isPivotTable() || (this.updateCellGroupShadowInContainer(this.table.scenegraph.rowHeaderGroup, this.range), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.leftBottomCornerGroup, this.range)), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.bodyGroup, this.range), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.rightFrozenGroup, this.range), 
        this.updateCellGroupShadowInContainer(this.table.scenegraph.bottomFrozenGroup), 
        this.range, this.updateCellGroupShadowInContainer(this.table.scenegraph.rightBottomCornerGroup, this.range);
    }
    updateCellGroupShadowInContainer(container, range) {
        container.forEachChildrenSkipChild((item => {
            const column = item;
            "column" === column.role && column.forEachChildrenSkipChild((item => {
                const cell = item;
                if ("cell" !== cell.role) return;
                cell.attachShadow(cell.shadowRoot);
                const shadowGroup = cell.shadowRoot;
                if (range) {
                    if ((0, helper_1.cellInRange)(range, cell.col, cell.row)) shadowGroup.removeAllChild(); else if (!shadowGroup.firstChild) {
                        const shadowRect = (0, vrender_1.createRect)({
                            x: 0,
                            y: 0,
                            width: cell.attribute.width,
                            height: cell.attribute.height,
                            fill: this._fill,
                            opacity: this._opacity
                        });
                        shadowRect.name = "shadow-rect", shadowGroup.appendChild(shadowRect);
                    }
                } else shadowGroup.removeAllChild();
            }));
        }));
    }
}

exports.InvertHighlightPlugin = InvertHighlightPlugin;
//# sourceMappingURL=invert-highlight.js.map