"use strict";

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

const cell_pos_1 = require("../utils/cell-pos"), vrender_1 = require("./../../vrender"), create_select_border_1 = require("./create-select-border");

function updateCustomSelectBorder(scene, selectRange, style) {
    const table = scene.table, newStartCol = selectRange.start.col, newStartRow = selectRange.start.row, newEndCol = selectRange.end.col, newEndRow = selectRange.end.row, startCol = (selectRange.skipBodyMerge, 
    Math.max(Math.min(newEndCol, newStartCol), 0)), startRow = Math.max(Math.min(newEndRow, newStartRow), 0), endCol = Math.min(Math.max(newEndCol, newStartCol), table.colCount - 1), endRow = Math.min(Math.max(newEndRow, newStartRow), table.rowCount - 1), {needRowHeader: needRowHeader, needRightRowHeader: needRightRowHeader, needColumnHeader: needColumnHeader, needBottomColumnHeader: needBottomColumnHeader, needBody: needBody, needCornerHeader: needCornerHeader, needRightTopCornerHeader: needRightTopCornerHeader, needLeftBottomCornerHeader: needLeftBottomCornerHeader, needRightBottomCornerHeader: needRightBottomCornerHeader} = (0, 
    cell_pos_1.calculateCellRangeDistribution)(startCol, startRow, endCol, endRow, table);
    if (needCornerHeader) {
        createCustomCellSelectBorder(scene, startCol, startRow, Math.min(endCol, table.frozenColCount - 1), Math.min(endRow, table.frozenRowCount - 1), "cornerHeader", `${startCol}${startRow}${endCol}${endRow}`, [ !0, !needColumnHeader, !needRowHeader, !0 ], style);
    }
    if (needRightTopCornerHeader) {
        createCustomCellSelectBorder(scene, Math.max(startCol, table.colCount - table.rightFrozenColCount), startRow, endCol, Math.min(endRow, table.frozenRowCount - 1), "rightTopCorner", `${startCol}${startRow}${endCol}${endRow}`, [ !0, !0, !needRightRowHeader, !needColumnHeader ], style);
    }
    if (needLeftBottomCornerHeader) {
        const cornerEndCol = Math.min(endCol, table.frozenColCount - 1);
        createCustomCellSelectBorder(scene, startCol, Math.max(startRow, table.rowCount - table.bottomFrozenRowCount), cornerEndCol, endRow, "leftBottomCorner", `${startCol}${startRow}${endCol}${endRow}`, [ !needRowHeader, !needBottomColumnHeader, !0, !0 ], style);
    }
    if (needRightBottomCornerHeader) {
        createCustomCellSelectBorder(scene, Math.max(startCol, table.colCount - table.rightFrozenColCount), Math.max(startRow, table.rowCount - table.bottomFrozenRowCount), endCol, endRow, "rightBottomCorner", `${startCol}${startRow}${endCol}${endRow}`, [ !needRightRowHeader, !0, !0, !needBottomColumnHeader ], style);
    }
    if (needColumnHeader) {
        createCustomCellSelectBorder(scene, Math.max(startCol, table.frozenColCount), startRow, Math.min(endCol, table.colCount - table.rightFrozenColCount - 1), Math.min(endRow, table.frozenRowCount - 1), "columnHeader", `${startCol}${startRow}${endCol}${endRow}`, [ !0, !needRightTopCornerHeader, !needBody, !needCornerHeader ], style);
    }
    if (needBottomColumnHeader) {
        const columnHeaderStartCol = Math.max(startCol, table.frozenColCount), columnHeaderEndCol = Math.min(endCol, table.colCount - table.rightFrozenColCount - 1);
        createCustomCellSelectBorder(scene, columnHeaderStartCol, Math.max(startRow, table.rowCount - table.bottomFrozenRowCount), columnHeaderEndCol, endRow, "bottomFrozen", `${startCol}${startRow}${endCol}${endRow}`, [ !needBody, !needRightBottomCornerHeader, !0, !needLeftBottomCornerHeader ], style);
    }
    if (needRowHeader) {
        const columnHeaderStartRow = Math.max(startRow, table.frozenRowCount), columnHeaderEndRow = Math.min(endRow, table.rowCount - table.bottomFrozenRowCount - 1);
        createCustomCellSelectBorder(scene, startCol, columnHeaderStartRow, Math.min(endCol, table.frozenColCount - 1), columnHeaderEndRow, "rowHeader", `${startCol}${startRow}${endCol}${endRow}`, [ !needCornerHeader, !needBody, !needLeftBottomCornerHeader, !0 ], style);
    }
    if (needRightRowHeader) {
        const columnHeaderStartRow = Math.max(startRow, table.frozenRowCount), columnHeaderEndRow = Math.min(endRow, table.rowCount - table.bottomFrozenRowCount - 1);
        createCustomCellSelectBorder(scene, Math.max(startCol, table.colCount - table.rightFrozenColCount), columnHeaderStartRow, endCol, columnHeaderEndRow, "rightFrozen", `${startCol}${startRow}${endCol}${endRow}`, [ !needRightTopCornerHeader, !0, !needRightBottomCornerHeader, !needBody ], style);
    }
    if (needBody) {
        createCustomCellSelectBorder(scene, Math.max(startCol, table.frozenColCount), Math.max(startRow, table.frozenRowCount), Math.min(endCol, table.colCount - table.rightFrozenColCount - 1), Math.min(endRow, table.rowCount - table.bottomFrozenRowCount - 1), "body", `${startCol}${startRow}${endCol}${endRow}`, [ !needColumnHeader, !needRightRowHeader, !needBottomColumnHeader, !needRowHeader ], style);
    }
}

function createCustomCellSelectBorder(scene, start_Col, start_Row, end_Col, end_Row, selectRangeType, selectId, strokes, style) {
    var _a, _b, _c, _d;
    const startCol = Math.min(start_Col, end_Col), startRow = Math.min(start_Row, end_Row), endCol = Math.max(start_Col, end_Col), endRow = Math.max(start_Row, end_Row), firstCellBound = scene.highPerformanceGetCell(startCol, startRow).globalAABBBounds, rect = (0, 
    vrender_1.createRect)({
        pickable: !1,
        fill: null !== (_a = style.cellBgColor) && void 0 !== _a && _a,
        lineWidth: null !== (_b = style.cellBorderLineWidth) && void 0 !== _b ? _b : 0,
        lineDash: null !== (_c = style.cellBorderLineDash) && void 0 !== _c ? _c : [],
        stroke: strokes.map((stroke => !!stroke && style.cellBorderColor)),
        x: firstCellBound.x1 - scene.tableGroup.attribute.x,
        y: firstCellBound.y1 - scene.tableGroup.attribute.y,
        width: 0,
        height: 0,
        visible: !0,
        cornerRadius: (0, create_select_border_1.getCornerRadius)(selectRangeType, null === (_d = scene.table.theme.frameStyle) || void 0 === _d ? void 0 : _d.cornerRadius, start_Col, start_Row, end_Col, end_Row, scene.table)
    });
    scene.customSelectedRangeComponents.set(`${startCol}-${startRow}-${endCol}-${endRow}-${selectId}`, {
        rect: rect,
        role: selectRangeType
    }), scene.tableGroup.insertAfter(rect, "body" === selectRangeType ? scene.bodyGroup : "columnHeader" === selectRangeType ? scene.colHeaderGroup : "rowHeader" === selectRangeType ? scene.rowHeaderGroup : "cornerHeader" === selectRangeType ? scene.cornerHeaderGroup : "rightTopCorner" === selectRangeType ? scene.rightTopCornerGroup : "rightFrozen" === selectRangeType ? scene.rightFrozenGroup : "leftBottomCorner" === selectRangeType ? scene.leftBottomCornerGroup : "bottomFrozen" === selectRangeType ? scene.bottomFrozenGroup : scene.rightBottomCornerGroup);
}

exports.updateCustomSelectBorder = updateCustomSelectBorder;
//# sourceMappingURL=update-custom-select-border.js.map
