"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get ManualColumnMove () {
        return ManualColumnMove;
    },
    get PLUGIN_KEY () {
        return PLUGIN_KEY;
    },
    get PLUGIN_PRIORITY () {
        return PLUGIN_PRIORITY;
    }
});
const _base = require("../base");
const _hooks = require("../../core/hooks");
const _array = require("../../helpers/array");
const _element = require("../../helpers/dom/element");
const _event = require("../../helpers/dom/event");
const _number = require("../../helpers/number");
const _backlight = /*#__PURE__*/ _interop_require_default(require("./ui/backlight"));
const _guideline = /*#__PURE__*/ _interop_require_default(require("./ui/guideline"));
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);
}
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
_hooks.Hooks.getSingleton().register('beforeColumnMove');
_hooks.Hooks.getSingleton().register('afterColumnMove');
const PLUGIN_KEY = 'manualColumnMove';
const PLUGIN_PRIORITY = 120;
const CSS_PLUGIN = 'ht__manualColumnMove';
const CSS_SHOW_UI = 'show-ui';
const CSS_ON_MOVING = 'on-moving--columns';
const CSS_AFTER_SELECTION = 'after-selection--columns';
var /**
   * Backlight UI object.
   *
   * @type {object}
   */ _backlight1 = /*#__PURE__*/ new WeakMap(), /**
   * Guideline UI object.
   *
   * @type {object}
   */ _guideline1 = /*#__PURE__*/ new WeakMap(), /**
   * @type {number[]}
   */ _columnsToMove = /*#__PURE__*/ new WeakMap(), /**
   * @type {number}
   */ _countCols = /*#__PURE__*/ new WeakMap(), /**
   * @type {boolean}
   */ _pressed = /*#__PURE__*/ new WeakMap(), /**
   * @type {object}
   */ _target = /*#__PURE__*/ new WeakMap(), /**
   * @type {number}
   */ _cachedDropIndex = /*#__PURE__*/ new WeakMap(), /**
   * @type {number}
   */ _hoveredColumn = /*#__PURE__*/ new WeakMap(), /**
   * @type {number}
   */ _rootElementOffset = /*#__PURE__*/ new WeakMap(), /**
   * @type {boolean}
   */ _hasRowHeaders = /*#__PURE__*/ new WeakMap(), /**
   * @type {number}
   */ _fixedColumnsStart = /*#__PURE__*/ new WeakMap(), /**
   * Change the behavior of selection / dragging.
   *
   * @param {MouseEvent} event `mousedown` event properties.
   * @param {CellCoords} coords Visual cell coordinates where was fired event.
   * @param {HTMLElement} TD Cell represented as HTMLElement.
   * @param {object} controller An object with properties `row`, `column` and `cell`. Each property contains
   *                            a boolean value that allows or disallows changing the selection for that particular area.
   */ _onBeforeOnCellMouseDown = /*#__PURE__*/ new WeakSet(), /**
   * 'mouseMove' event callback. Fired when pointer move on document.documentElement.
   *
   * @param {MouseEvent} event `mousemove` event properties.
   */ _onMouseMove = /*#__PURE__*/ new WeakSet(), /**
   * 'beforeOnCellMouseOver' hook callback. Fired when pointer was over cell.
   *
   * @param {MouseEvent} event `mouseover` event properties.
   * @param {CellCoords} coords Visual cell coordinates where was fired event.
   * @param {HTMLElement} TD Cell represented as HTMLElement.
   * @param {object} controller An object with properties `row`, `column` and `cell`. Each property contains
   *                            a boolean value that allows or disallows changing the selection for that particular area.
   */ _onBeforeOnCellMouseOver = /*#__PURE__*/ new WeakSet(), /**
   * `onMouseUp` hook callback.
   */ _onMouseUp = /*#__PURE__*/ new WeakSet(), /**
   * `afterScrollHorizontally` hook callback. Fired the table was scrolled horizontally.
   */ _onAfterScrollVertically = /*#__PURE__*/ new WeakSet(), /**
   * Callback for the `afterLoadData` hook.
   *
   * @private
   */ _onAfterLoadData = /*#__PURE__*/ new WeakSet();
class ManualColumnMove extends _base.BasePlugin {
    static get PLUGIN_KEY() {
        return PLUGIN_KEY;
    }
    static get PLUGIN_PRIORITY() {
        return PLUGIN_PRIORITY;
    }
    /**
   * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
   * hook and if it returns `true` then the {@link ManualColumnMove#enablePlugin} method is called.
   * When [[Options#dataProvider]] is a complete server-backed configuration, the DataProvider plugin blocks this plugin from enabling.
   *
   * @returns {boolean}
   */ isEnabled() {
        return !!this.hot.getSettings()[PLUGIN_KEY];
    }
    /**
   * Enables the plugin functionality for this Handsontable instance.
   */ enablePlugin() {
        if (this.enabled) {
            return;
        }
        this.addHook('beforeOnCellMouseDown', (...args)=>_class_private_method_get(this, _onBeforeOnCellMouseDown, onBeforeOnCellMouseDown).call(this, ...args));
        this.addHook('beforeOnCellMouseOver', (...args)=>_class_private_method_get(this, _onBeforeOnCellMouseOver, onBeforeOnCellMouseOver).call(this, ...args));
        this.addHook('afterScrollVertically', ()=>_class_private_method_get(this, _onAfterScrollVertically, onAfterScrollVertically).call(this));
        this.addHook('afterLoadData', (...args)=>_class_private_method_get(this, _onAfterLoadData, onAfterLoadData).call(this, ...args));
        this.buildPluginUI();
        this.registerEvents();
        // TODO: move adding plugin classname to BasePlugin.
        (0, _element.addClass)(this.hot.rootElement, CSS_PLUGIN);
        super.enablePlugin();
    }
    /**
   * Updates the plugin's state.
   *
   * This method is executed when [`updateSettings()`](@/api/core.md#updatesettings) is invoked with any of the following configuration options:
   *  - [`manualColumnMove`](@/api/options.md#manualcolumnmove)
   */ updatePlugin() {
        this.disablePlugin();
        this.enablePlugin();
        this.moveBySettingsOrLoad();
        super.updatePlugin();
    }
    /**
   * Disables the plugin functionality for this Handsontable instance.
   */ disablePlugin() {
        (0, _element.removeClass)(this.hot.rootElement, CSS_PLUGIN);
        this.unregisterEvents();
        _class_private_field_get(this, _backlight1).destroy();
        _class_private_field_get(this, _guideline1).destroy();
        super.disablePlugin();
    }
    /**
   * Moves a single column.
   *
   * @param {number} column Visual column index to be moved.
   * @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
   * To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
   * @fires Hooks#beforeColumnMove
   * @fires Hooks#afterColumnMove
   * @returns {boolean}
   */ moveColumn(column, finalIndex) {
        return this.moveColumns([
            column
        ], finalIndex);
    }
    /**
   * Moves a multiple columns.
   *
   * @param {Array} columns Array of visual column indexes to be moved.
   * @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
   * To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
   * @fires Hooks#beforeColumnMove
   * @fires Hooks#afterColumnMove
   * @returns {boolean}
   */ moveColumns(columns, finalIndex) {
        const dropIndex = _class_private_field_get(this, _cachedDropIndex);
        const movePossible = this.isMovePossible(columns, finalIndex);
        const beforeMoveHook = this.hot.runHooks('beforeColumnMove', columns, finalIndex, dropIndex, movePossible);
        _class_private_field_set(this, _cachedDropIndex, undefined);
        if (beforeMoveHook === false) {
            return;
        }
        if (movePossible) {
            this.hot.columnIndexMapper.moveIndexes(columns, finalIndex);
        }
        const movePerformed = movePossible && this.isColumnOrderChanged(columns, finalIndex);
        this.hot.runHooks('afterColumnMove', columns, finalIndex, dropIndex, movePossible, movePerformed);
        return movePerformed;
    }
    /**
   * Drag a single column to drop index position.
   *
   * @param {number} column Visual column index to be dragged.
   * @param {number} dropIndex Visual column index, being a drop index for the moved columns. Points to where we are going to drop the moved elements.
   * To check visualization of drop index please take a look at [documentation](@/guides/columns/column-moving/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
   * @fires Hooks#beforeColumnMove
   * @fires Hooks#afterColumnMove
   * @returns {boolean}
   */ dragColumn(column, dropIndex) {
        return this.dragColumns([
            column
        ], dropIndex);
    }
    /**
   * Drag multiple columns to drop index position.
   *
   * @param {Array} columns Array of visual column indexes to be dragged.
   * @param {number} dropIndex Visual column index, being a drop index for the moved columns. Points to where we are going to drop the moved elements.
   * To check visualization of drop index please take a look at [documentation](@/guides/columns/column-moving/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
   * @fires Hooks#beforeColumnMove
   * @fires Hooks#afterColumnMove
   * @returns {boolean}
   */ dragColumns(columns, dropIndex) {
        const finalIndex = this.countFinalIndex(columns, dropIndex);
        _class_private_field_set(this, _cachedDropIndex, dropIndex);
        return this.moveColumns(columns, finalIndex);
    }
    /**
   * Indicates if it's possible to move columns to the desired position. Some of the actions aren't
   * possible, i.e. You can’t move more than one element to the last position.
   *
   * @param {Array} movedColumns Array of visual column indexes to be moved.
   * @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
   * To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
   * @returns {boolean}
   */ isMovePossible(movedColumns, finalIndex) {
        const length = this.hot.columnIndexMapper.getNotTrimmedIndexesLength();
        // An attempt to transfer more columns to start destination than is possible (only when moving from the top to the bottom).
        const tooHighDestinationIndex = movedColumns.length + finalIndex > length;
        const tooLowDestinationIndex = finalIndex < 0;
        const tooLowMovedColumnIndex = movedColumns.some((movedColumn)=>movedColumn < 0);
        const tooHighMovedColumnIndex = movedColumns.some((movedColumn)=>movedColumn >= length);
        if (tooHighDestinationIndex || tooLowDestinationIndex || tooLowMovedColumnIndex || tooHighMovedColumnIndex) {
            return false;
        }
        return true;
    }
    /**
   * Indicates if order of columns was changed.
   *
   * @private
   * @param {Array} movedColumns Array of visual column indexes to be moved.
   * @param {number} finalIndex Visual column index, being a start index for the moved columns. Points to where the elements will be placed after the moving action.
   * To check the visualization of the final index, please take a look at [documentation](@/guides/columns/column-moving/column-moving.md#drag-and-move-actions-of-manualcolumnmove-plugin).
   * @returns {boolean}
   */ isColumnOrderChanged(movedColumns, finalIndex) {
        return movedColumns.some((column, nrOfMovedElement)=>column - nrOfMovedElement !== finalIndex);
    }
    /**
   * Count the final column index from the drop index.
   *
   * @private
   * @param {Array} movedColumns Array of visual column indexes to be moved.
   * @param {number} dropIndex Visual column index, being a drop index for the moved columns.
   * @returns {number} Visual column index, being a start index for the moved columns.
   */ countFinalIndex(movedColumns, dropIndex) {
        const numberOfColumnsLowerThanDropIndex = (0, _array.arrayReduce)(movedColumns, (numberOfColumns, currentColumnIndex)=>{
            if (currentColumnIndex < dropIndex) {
                numberOfColumns += 1;
            }
            return numberOfColumns;
        }, 0);
        return dropIndex - numberOfColumnsLowerThanDropIndex;
    }
    /**
   * Gets the sum of the widths of columns in the provided range.
   *
   * @private
   * @param {number} fromColumn Visual column index.
   * @param {number} toColumn Visual column index.
   * @returns {number}
   */ getColumnsWidth(fromColumn, toColumn) {
        const columnMapper = this.hot.columnIndexMapper;
        let columnsWidth = 0;
        for(let visualColumnIndex = fromColumn; visualColumnIndex <= toColumn; visualColumnIndex += 1){
            const renderableIndex = columnMapper.getRenderableFromVisualIndex(visualColumnIndex);
            if (visualColumnIndex < 0) {
                columnsWidth += this.hot.view._wt.wtViewport.getRowHeaderWidth() || 0;
            } else if (renderableIndex !== null) {
                columnsWidth += this.hot.view._wt.wtTable.getColumnWidth(renderableIndex) || 0;
            }
        }
        return columnsWidth;
    }
    /**
   * Loads initial settings when state was saved (e.g. via hooks) or when plugin was initialized as an array.
   *
   * @private
   */ moveBySettingsOrLoad() {
        const pluginSettings = this.hot.getSettings()[PLUGIN_KEY];
        if (Array.isArray(pluginSettings)) {
            this.moveColumns(pluginSettings, 0);
        }
    }
    /**
   * Checks if the provided column is in the fixedColumnsTop section.
   *
   * @private
   * @param {number} column Visual column index to check.
   * @returns {boolean}
   */ isFixedColumnsStart(column) {
        return column < this.hot.getSettings().fixedColumnsStart;
    }
    /**
   * Prepares an array of indexes based on actual selection.
   *
   * @private
   * @param {number} start The start index.
   * @param {number} end The end index.
   * @returns {Array}
   */ prepareColumnsToMoving(start, end) {
        const selectedColumns = [];
        (0, _number.rangeEach)(start, end, (i)=>{
            selectedColumns.push(i);
        });
        return selectedColumns;
    }
    /**
   * Update the UI visual position.
   *
   * @private
   */ refreshPositions() {
        const firstVisible = this.hot.view.getFirstFullyVisibleColumn();
        if (this.isFixedColumnsStart(_class_private_field_get(this, _hoveredColumn)) && firstVisible > 0) {
            this.hot.scrollViewportTo({
                col: this.hot.columnIndexMapper.getNearestNotHiddenIndex(firstVisible - 1, -1)
            });
        }
        const wtTable = this.hot.view._wt.wtTable;
        const scrollableElement = this.hot.view._wt.wtOverlays.scrollableElement;
        const scrollStart = typeof scrollableElement.scrollX === 'number' ? scrollableElement.scrollX : scrollableElement.scrollLeft;
        let tdOffsetStart = this.hot.view.THEAD.offsetLeft + this.getColumnsWidth(0, _class_private_field_get(this, _hoveredColumn) - 1);
        const hiderWidth = wtTable.hider.offsetWidth;
        const tbodyOffsetLeft = wtTable.TBODY.offsetLeft;
        const backlightElemMarginStart = _class_private_field_get(this, _backlight1).getOffset().start;
        const backlightElemWidth = _class_private_field_get(this, _backlight1).getSize().width;
        let rowHeaderWidth = 0;
        let mouseOffsetStart = 0;
        if (this.hot.isRtl()) {
            const rootWindow = this.hot.rootWindow;
            const containerWidth = (0, _element.outerWidth)(this.hot.rootElement);
            const gridMostRightPos = rootWindow.innerWidth - _class_private_field_get(this, _rootElementOffset) - containerWidth;
            mouseOffsetStart = rootWindow.innerWidth - _class_private_field_get(this, _target).eventPageX - gridMostRightPos - (scrollableElement.scrollX === undefined ? scrollStart : 0);
        } else {
            mouseOffsetStart = _class_private_field_get(this, _target).eventPageX - (_class_private_field_get(this, _rootElementOffset) - (scrollableElement.scrollX === undefined ? scrollStart : 0));
        }
        if (_class_private_field_get(this, _hasRowHeaders)) {
            rowHeaderWidth = this.hot.view._wt.wtOverlays.inlineStartOverlay.clone.wtTable.getColumnHeader(-1).offsetWidth;
        }
        if (this.isFixedColumnsStart(_class_private_field_get(this, _hoveredColumn))) {
            tdOffsetStart += scrollStart;
        }
        tdOffsetStart += rowHeaderWidth;
        if (_class_private_field_get(this, _hoveredColumn) < 0) {
            // if hover on rowHeader
            if (_class_private_field_get(this, _fixedColumnsStart) > 0) {
                _class_private_field_get(this, _target).col = 0;
            } else {
                _class_private_field_get(this, _target).col = firstVisible > 0 ? firstVisible - 1 : firstVisible;
            }
        } else if (_class_private_field_get(this, _target).TD.offsetWidth / 2 + tdOffsetStart <= mouseOffsetStart) {
            const newCoordsCol = _class_private_field_get(this, _hoveredColumn) >= _class_private_field_get(this, _countCols) ? _class_private_field_get(this, _countCols) - 1 : _class_private_field_get(this, _hoveredColumn);
            // if hover on right part of TD
            _class_private_field_get(this, _target).col = newCoordsCol + 1;
            // unfortunately first column is bigger than rest
            tdOffsetStart += _class_private_field_get(this, _target).TD.offsetWidth;
        } else {
            // elsewhere on table
            _class_private_field_get(this, _target).col = _class_private_field_get(this, _hoveredColumn);
        }
        let backlightStart = mouseOffsetStart;
        let guidelineStart = tdOffsetStart;
        if (mouseOffsetStart + backlightElemWidth + backlightElemMarginStart >= hiderWidth) {
            // prevent display backlight on the right side of the table
            backlightStart = hiderWidth - backlightElemWidth - backlightElemMarginStart;
        } else if (mouseOffsetStart + backlightElemMarginStart < tbodyOffsetLeft + rowHeaderWidth) {
            // prevent display backlight on the left side of the table
            backlightStart = tbodyOffsetLeft + rowHeaderWidth + Math.abs(backlightElemMarginStart);
        }
        if (tdOffsetStart >= hiderWidth - 1) {
            // prevent display guideline outside the table
            guidelineStart = hiderWidth - 1;
        } else if (guidelineStart === 0) {
            // guideline has got `margin-left: -1px` as default
            guidelineStart = 1;
        } else if (scrollableElement.scrollX !== undefined && _class_private_field_get(this, _hoveredColumn) < _class_private_field_get(this, _fixedColumnsStart)) {
            guidelineStart -= _class_private_field_get(this, _rootElementOffset) <= scrollableElement.scrollX ? _class_private_field_get(this, _rootElementOffset) : 0;
        }
        _class_private_field_get(this, _backlight1).setPosition(null, backlightStart);
        _class_private_field_get(this, _guideline1).setPosition(null, guidelineStart);
    }
    /**
   * Binds the events used by the plugin.
   *
   * @private
   */ registerEvents() {
        const { documentElement } = this.hot.rootDocument;
        this.eventManager.addEventListener(documentElement, 'mousemove', (event)=>_class_private_method_get(this, _onMouseMove, onMouseMove).call(this, event));
        this.eventManager.addEventListener(documentElement, 'mouseup', ()=>_class_private_method_get(this, _onMouseUp, onMouseUp).call(this));
    }
    /**
   * Unbinds the events used by the plugin.
   *
   * @private
   */ unregisterEvents() {
        this.eventManager.clear();
    }
    /**
   * Builds the plugin's UI.
   *
   * @private
   */ buildPluginUI() {
        _class_private_field_get(this, _backlight1).build();
        _class_private_field_get(this, _guideline1).build();
    }
    /**
   * Destroys the plugin instance.
   */ destroy() {
        _class_private_field_get(this, _backlight1).destroy();
        _class_private_field_get(this, _guideline1).destroy();
        super.destroy();
    }
    constructor(...args){
        super(...args), _class_private_method_init(this, _onBeforeOnCellMouseDown), _class_private_method_init(this, _onMouseMove), _class_private_method_init(this, _onBeforeOnCellMouseOver), _class_private_method_init(this, _onMouseUp), _class_private_method_init(this, _onAfterScrollVertically), _class_private_method_init(this, _onAfterLoadData), _class_private_field_init(this, _backlight1, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _guideline1, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _columnsToMove, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _countCols, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _pressed, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _target, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _cachedDropIndex, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _hoveredColumn, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _rootElementOffset, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _hasRowHeaders, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _fixedColumnsStart, {
            writable: true,
            value: void 0
        }), _class_private_field_set(this, _backlight1, new _backlight.default(this.hot)), _class_private_field_set(this, _guideline1, new _guideline.default(this.hot)), _class_private_field_set(this, _columnsToMove, []), _class_private_field_set(this, _countCols, 0), _class_private_field_set(this, _pressed, false), _class_private_field_set(this, _target, {});
    }
}
function onBeforeOnCellMouseDown(event, coords, TD, controller) {
    const wtTable = this.hot.view._wt.wtTable;
    const isHeaderSelection = this.hot.selection.isSelectedByColumnHeader();
    const selection = this.hot.getSelectedRangeActive();
    // This block action shouldn't be handled below.
    const isSortingElement = (0, _element.hasClass)(event.target, 'sortAction');
    if (!selection || !isHeaderSelection || _class_private_field_get(this, _pressed) || event.button !== 0 || isSortingElement) {
        _class_private_field_set(this, _pressed, false);
        _class_private_field_get(this, _columnsToMove).length = 0;
        (0, _element.removeClass)(this.hot.rootElement, [
            CSS_ON_MOVING,
            CSS_SHOW_UI
        ]);
        return;
    }
    const guidelineIsNotReady = _class_private_field_get(this, _guideline1).isBuilt() && !_class_private_field_get(this, _guideline1).isAppended();
    const backlightIsNotReady = _class_private_field_get(this, _backlight1).isBuilt() && !_class_private_field_get(this, _backlight1).isAppended();
    if (guidelineIsNotReady && backlightIsNotReady) {
        _class_private_field_get(this, _guideline1).appendTo(wtTable.hider);
        _class_private_field_get(this, _backlight1).appendTo(wtTable.hider);
    }
    const { from, to } = selection;
    const start = Math.min(from.col, to.col);
    const end = Math.max(from.col, to.col);
    if (coords.row < 0 && coords.col >= start && coords.col <= end) {
        controller.column = true;
        _class_private_field_set(this, _pressed, true);
        const eventOffsetX = TD.firstChild ? (0, _event.offsetRelativeTo)(event, TD.firstChild).x : event.offsetX;
        _class_private_field_get(this, _target).eventPageX = event.pageX;
        _class_private_field_set(this, _hoveredColumn, coords.col);
        _class_private_field_get(this, _target).TD = TD;
        _class_private_field_get(this, _target).col = coords.col;
        _class_private_field_set(this, _columnsToMove, this.prepareColumnsToMoving(start, end));
        _class_private_field_set(this, _hasRowHeaders, !!this.hot.getSettings().rowHeaders);
        _class_private_field_set(this, _countCols, this.hot.countCols());
        _class_private_field_set(this, _fixedColumnsStart, this.hot.getSettings().fixedColumnsStart);
        _class_private_field_set(this, _rootElementOffset, (0, _element.offset)(this.hot.rootElement).left);
        const countColumnsFrom = _class_private_field_get(this, _hasRowHeaders) ? -1 : 0;
        const topPos = wtTable.holder.scrollTop + wtTable.getColumnHeaderHeight(0) + 1;
        const fixedColumnsStart = coords.col < _class_private_field_get(this, _fixedColumnsStart);
        const horizontalScrollPosition = this.hot.view._wt.wtOverlays.inlineStartOverlay.getOverlayOffset();
        const offsetX = Math.abs(eventOffsetX - (this.hot.isRtl() ? TD.offsetWidth : 0));
        const inlineOffset = this.getColumnsWidth(start, coords.col - 1) + offsetX;
        const inlinePos = this.getColumnsWidth(countColumnsFrom, start - 1) + (fixedColumnsStart ? horizontalScrollPosition : 0) + inlineOffset;
        _class_private_field_get(this, _backlight1).setPosition(topPos, inlinePos);
        _class_private_field_get(this, _backlight1).setSize(this.getColumnsWidth(start, end), wtTable.hider.offsetHeight - topPos);
        _class_private_field_get(this, _backlight1).setOffset(null, -inlineOffset);
        (0, _element.addClass)(this.hot.rootElement, CSS_ON_MOVING);
    } else {
        (0, _element.removeClass)(this.hot.rootElement, CSS_AFTER_SELECTION);
        _class_private_field_set(this, _pressed, false);
        _class_private_field_get(this, _columnsToMove).length = 0;
    }
}
function onMouseMove(event) {
    if (!_class_private_field_get(this, _pressed)) {
        return;
    }
    _class_private_field_get(this, _target).eventPageX = event.pageX;
    this.refreshPositions();
}
function onBeforeOnCellMouseOver(event, coords, TD, controller) {
    const selectedRange = this.hot.getSelectedRangeActive();
    if (!selectedRange || !_class_private_field_get(this, _pressed)) {
        return;
    }
    if (_class_private_field_get(this, _columnsToMove).indexOf(coords.col) > -1) {
        (0, _element.removeClass)(this.hot.rootElement, CSS_SHOW_UI);
    } else {
        (0, _element.addClass)(this.hot.rootElement, CSS_SHOW_UI);
    }
    controller.row = true;
    controller.column = true;
    controller.cell = true;
    _class_private_field_set(this, _hoveredColumn, coords.col);
    _class_private_field_get(this, _target).TD = TD;
}
function onMouseUp() {
    const target = _class_private_field_get(this, _target).col;
    const columnsLen = _class_private_field_get(this, _columnsToMove).length;
    _class_private_field_set(this, _hoveredColumn, undefined);
    _class_private_field_set(this, _pressed, false);
    (0, _element.removeClass)(this.hot.rootElement, [
        CSS_ON_MOVING,
        CSS_SHOW_UI,
        CSS_AFTER_SELECTION
    ]);
    if (this.hot.selection.isSelectedByColumnHeader()) {
        (0, _element.addClass)(this.hot.rootElement, CSS_AFTER_SELECTION);
    }
    if (columnsLen < 1 || target === undefined) {
        return;
    }
    const firstMovedVisualColumn = _class_private_field_get(this, _columnsToMove)[0];
    const firstMovedPhysicalColumn = this.hot.toPhysicalColumn(firstMovedVisualColumn);
    const movePerformed = this.dragColumns(_class_private_field_get(this, _columnsToMove), target);
    _class_private_field_get(this, _columnsToMove).length = 0;
    if (movePerformed === true) {
        this.hot.view.adjustElementsSize();
        this.hot.render();
        const selectionStart = this.hot.toVisualColumn(firstMovedPhysicalColumn);
        const selectionEnd = selectionStart + columnsLen - 1;
        this.hot.selectColumns(selectionStart, selectionEnd);
    }
}
function onAfterScrollVertically() {
    const wtTable = this.hot.view._wt.wtTable;
    const headerHeight = wtTable.getColumnHeaderHeight(0) + 1;
    const scrollTop = wtTable.holder.scrollTop;
    const posTop = headerHeight + scrollTop;
    _class_private_field_get(this, _backlight1).setPosition(posTop);
    _class_private_field_get(this, _backlight1).setSize(null, wtTable.hider.offsetHeight - posTop);
}
function onAfterLoadData() {
    this.moveBySettingsOrLoad();
}
