function _check_private_redeclaration(obj, privateCollection) {
    if (privateCollection.has(obj)) {
        throw new TypeError("Cannot initialize the same private elements twice on an object");
    }
}
function _class_apply_descriptor_get(receiver, descriptor) {
    if (descriptor.get) {
        return descriptor.get.call(receiver);
    }
    return descriptor.value;
}
function _class_apply_descriptor_set(receiver, descriptor, value) {
    if (descriptor.set) {
        descriptor.set.call(receiver, value);
    } else {
        if (!descriptor.writable) {
            throw new TypeError("attempted to set read only private field");
        }
        descriptor.value = value;
    }
}
function _class_extract_field_descriptor(receiver, privateMap, action) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to " + action + " private field on non-instance");
    }
    return privateMap.get(receiver);
}
function _class_private_field_get(receiver, privateMap) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
    return _class_apply_descriptor_get(receiver, descriptor);
}
function _class_private_field_init(obj, privateMap, value) {
    _check_private_redeclaration(obj, privateMap);
    privateMap.set(obj, value);
}
function _class_private_field_set(receiver, privateMap, value) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
    _class_apply_descriptor_set(receiver, descriptor, value);
    return value;
}
function _class_private_method_get(receiver, privateSet, fn) {
    if (!privateSet.has(receiver)) {
        throw new TypeError("attempted to get private field on non-instance");
    }
    return fn;
}
function _class_private_method_init(obj, privateSet) {
    _check_private_redeclaration(obj, privateSet);
    privateSet.add(obj);
}
var /**
   * The instance of the IndexMapper class for row indexes.
   *
   * @param {IndexMapper}
   */ _rowIndexMapper = /*#__PURE__*/ new WeakMap(), /**
   * The instance of the IndexMapper class for row indexes.
   *
   * @param {IndexMapper}
   */ _columnIndexMapper = /*#__PURE__*/ new WeakMap(), /**
   * Gets nearest coordinates that points to the visible row and column indexes. If there are no visible
   * rows and/or columns the `null` value is returned.
   *
   * @private
   * @param {CellCoords} coords The coords object as starting point for finding the nearest visible coordinates.
   * @param {1|-1} rowSearchDirection The search direction. For value 1, it means searching from top to bottom for
   *                                  rows and from left to right for columns. For -1, it is the other way around.
   * @param {1|-1} columnSearchDirection The same as above but for rows.
   * @returns {CellCoords|null} Visual cell coordinates.
   */ _getNearestNotHiddenCoords = /*#__PURE__*/ new WeakSet(), /**
   * Gets nearest visual index. If there are no visible rows or columns the `null` value is returned.
   *
   * @private
   * @param {IndexMapper} indexMapper The IndexMapper instance for specific axis.
   * @param {number} visualIndex The index as starting point for finding the nearest visible index.
   * @param {1|-1} searchDirection The search direction. For value 1, it means searching from top to bottom for
   *                               rows and from left to right for columns. For -1, it is the other way around.
   * @returns {number|null} Visual row/column index.
   */ _getNearestNotHiddenIndex = /*#__PURE__*/ new WeakSet();
/* eslint-disable jsdoc/require-description-complete-sentence */ /**
 * CellRangeToRenderableMapper is a utility responsible for converting CellRange instances
 * defined in visual coordinates (which may include hidden rows/columns) into renderable
 * coordinates (excluding hidden indices).
 *
 * This class encapsulates the translation logic, allowing other modules to operate
 * on renderable coordinates without needing to be aware of the underlying index mapping implementation.
 *
 * It promotes separation of concerns by decoupling the transformation logic from data structures
 * like CellRange or CellCoords, keeping those classes clean and focused on structural concerns.
 *
 * Example usage:
 *   import { resolveWithInstance } from './utils/staticRegister.mjs';
 *
 *   const cellRange = new CellRange(...);
 *   const renderableRange = resolveWithInstance(this.hot, 'cellRangeMapper')
 *     .toRenderable(cellRange);
 */ export class CellRangeToRenderableMapper {
    /**
   * Converts the visual coordinates of the CellRange instance to the renderable coordinates.
   *
   * @param {CellRange} range The CellRange instance with defined visual coordinates.
   * @returns {CellRange | null}
   */ toRenderable(range) {
        const rowDirection = range.getVerticalDirection() === 'N-S' ? 1 : -1;
        const columnDirection = range.getHorizontalDirection() === 'W-E' ? 1 : -1;
        const from = _class_private_method_get(this, _getNearestNotHiddenCoords, getNearestNotHiddenCoords).call(this, range.from, rowDirection, columnDirection);
        if (from === null) {
            return null;
        }
        const to = _class_private_method_get(this, _getNearestNotHiddenCoords, getNearestNotHiddenCoords).call(this, range.to, -rowDirection, -columnDirection);
        if (to === null) {
            return null;
        }
        const newRange = range.clone();
        newRange.from = from;
        newRange.to = to;
        if (!newRange.includes(range.highlight)) {
            newRange.highlight = from;
        }
        return newRange;
    }
    constructor({ rowIndexMapper, columnIndexMapper }){
        _class_private_method_init(this, _getNearestNotHiddenCoords);
        _class_private_method_init(this, _getNearestNotHiddenIndex);
        _class_private_field_init(this, _rowIndexMapper, {
            writable: true,
            value: void 0
        });
        _class_private_field_init(this, _columnIndexMapper, {
            writable: true,
            value: void 0
        });
        _class_private_field_set(this, _rowIndexMapper, rowIndexMapper);
        _class_private_field_set(this, _columnIndexMapper, columnIndexMapper);
    }
}
function getNearestNotHiddenCoords(coords, rowSearchDirection, columnSearchDirection = rowSearchDirection) {
    const nextVisibleRow = _class_private_method_get(this, _getNearestNotHiddenIndex, getNearestNotHiddenIndex).call(this, _class_private_field_get(this, _rowIndexMapper), coords.row, rowSearchDirection);
    if (nextVisibleRow === null) {
        return null;
    }
    const nextVisibleColumn = _class_private_method_get(this, _getNearestNotHiddenIndex, getNearestNotHiddenIndex).call(this, _class_private_field_get(this, _columnIndexMapper), coords.col, columnSearchDirection);
    if (nextVisibleColumn === null) {
        return null;
    }
    return coords.clone().assign({
        row: nextVisibleRow,
        col: nextVisibleColumn
    });
}
function getNearestNotHiddenIndex(indexMapper, visualIndex, searchDirection) {
    if (visualIndex < 0) {
        return visualIndex;
    }
    return indexMapper.getNearestNotHiddenIndex(visualIndex, searchDirection);
}
