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);
}
import { BasePlugin } from '../base/index.mjs';
import { clamp } from '../../helpers/number.mjs';
import { getScrollbarWidth } from '../../helpers/dom/element.mjs';
import { PaginationUI } from './ui.mjs';
import { announce } from '../../utils/a11yAnnouncer.mjs';
import { createPaginatorStrategy } from './strategies/index.mjs';
import { toSingleLine } from '../../helpers/templateLiteralTag.mjs';
import { warn } from '../../helpers/console.mjs';
import { registerConflict } from '../base/conflictRegistry.mjs';
// Hard conflicts: Pagination stays off while any of these top-level settings is truthy.
registerConflict('pagination', [
    'nestedRows',
    'mergeCells',
    'fixedRowsTop',
    'fixedRowsBottom'
]);
export const PLUGIN_KEY = 'pagination';
export const PLUGIN_PRIORITY = 900;
const SHORTCUTS_CONTEXT_NAME = `plugin:${PLUGIN_KEY}`;
const AUTO_PAGE_SIZE_WARNING = toSingleLine`The \`auto\` page size setting requires the \`autoRowSize\`\x20
  plugin to be enabled. Set the \`autoRowSize: true\` in the configuration to ensure correct behavior.`;
var /**
   * Map of hidden rows controlled by the pagination plugin.
   *
   * @type {HiddenMap | null}
   */ _pagedRowsMap = /*#__PURE__*/ new WeakMap(), /**
   * Current page number.
   *
   * @type {number}
   */ _currentPage = /*#__PURE__*/ new WeakMap(), /**
   * Page size setup by the user. It can be a number or 'auto' (in which case the plugin will
   * calculate the page size based on the viewport size and row heights).
   *
   * @type {number | 'auto'}
   */ _pageSize = /*#__PURE__*/ new WeakMap(), /**
   * UI instance of the pagination plugin.
   *
   * @type {PaginationUI}
   */ _ui = /*#__PURE__*/ new WeakMap(), /**
   * Pagination calculation strategy instance. It is used to calculate the pagination state
   * based on the user-defined settings. The result of the state is used to update the
   * pagination index mapper.
   *
   * @type {AutoPageSizeStrategy | FixedPageSizeStrategy | null}
   */ _calcStrategy = /*#__PURE__*/ new WeakMap(), /**
   * Flag indicating if the plugin is in the process of updating the index cache (execution operation).
   * Prevents circular calls when the index cache is updated.
   *
   * @type {boolean}
   */ _internalExecutionCall = /*#__PURE__*/ new WeakMap(), /**
   * Flag indicating if the plugin is in the process of updating the internal state (render operation).
   * Prevents circular calls when the render call is triggered by the pagination plugin itself.
   *
   * @type {boolean}
   */ _internalRenderCall = /*#__PURE__*/ new WeakMap(), /**
   * Whether settings include a complete `dataProvider` configuration (server-backed rows).
   *
   * @type {boolean}
   */ _isDataProviderActive = /*#__PURE__*/ new WeakMap(), /**
   * Total row count from the last successful `afterDataProviderFetch` when `#isDataProviderActive` is true.
   *
   * @type {number|null}
   */ _serverSideTotalCount = /*#__PURE__*/ new WeakMap(), /**
   * @param {object} result [[Hooks#afterDataProviderFetch]] payload.
   * @param {{ page: number, pageSize: number, sort: *, filters: * }} result.queryParameters Query parameters for the completed fetch.
   * @param {number} result.totalRows Total row count from the provider response.
   * @returns {void}
   */ _onAfterDataProviderFetch = /*#__PURE__*/ new WeakMap(), /**
   * Sets the current page (internal state only). Use before #refreshUI when changing page.
   *
   * @param {number} page Page number (1-based).
   */ _setCurrentPage = /*#__PURE__*/ new WeakSet(), /**
   * Sets the page size and strategy (internal state only). Use before #refreshUI when changing page size.
   *
   * @param {number|'auto'} pageSize Page size or 'auto'.
   */ _setPageSizeValue = /*#__PURE__*/ new WeakSet(), /**
   * Recomputes pagination state, adjusts viewport elements, and re-renders the table.
   * Use this single entry point for all UI refresh after changing currentPage or pageSize.
   *
   */ _refreshUI = /*#__PURE__*/ new WeakSet(), /**
   * Updates the visibility state of the pagination sections based on the current settings.
   */ _updateSectionsVisibilityState = /*#__PURE__*/ new WeakSet(), /**
   * Applies the current pagination state to the internal index mapper and updates the UI.
   */ _computeAndApplyState = /*#__PURE__*/ new WeakSet(), /**
   * Based on the external factors (like the scroll position of the table, size etc.) it computes
   * the need for the top border of the pagination UI container.
   *
   * @returns {boolean} Returns `true` if the pagination UI should have a top border, `false` otherwise.
   */ _computeNeedsBorder = /*#__PURE__*/ new WeakSet(), /**
   * Registers the focus scope for the pagination plugin.
   */ _registerFocusScope = /*#__PURE__*/ new WeakSet(), /**
   * Unregisters the focus scope for the pagination plugin.
   */ _unregisterFocusScope = /*#__PURE__*/ new WeakSet(), /**
   * Called before the selection of columns or all table is made. It modifies the selection rows range
   * to the range of the current page.
   *
   * @param {CellCoords} from Starting cell coordinates.
   * @param {CellCoords} to Ending cell coordinates.
   */ _onBeforeSelectAllRows = /*#__PURE__*/ new WeakSet(), /**
   * Called before the selection end is fired. It modifies the selection to the range of
   * the current page.
   *
   * @param {CellCoords} coords Ending cell coordinates.
   */ _onBeforeSetRangeEnd = /*#__PURE__*/ new WeakSet(), /**
   * The hook corrects the focus position (before drawing it) after the selection was made
   * (the visual coordinates was collected).
   */ _onBeforeSelectionHighlightSet = /*#__PURE__*/ new WeakSet(), /**
   * Called before the paste operation is performed. It removes the rows that are not visible
   * from the pasted data.
   *
   * @param {Array} pastedData The data that was pasted.
   * @param {Array<{startRow: number, endRow: number}>} ranges The ranges of the pasted data.
   * @returns {boolean} Returns `false` to prevent the paste operation.
   */ _onBeforePaste = /*#__PURE__*/ new WeakSet(), /**
   * Called after the view is rendered. It recalculates the pagination state only when
   * the `pageSize` is set to `'auto'`. In this case, the plugin will compute the
   * page size based on the viewport size and row heights for each render cycle to make sure
   * that each row resize, multiline cell value, or other factors that may affect the
   * rows height will be taken into account.
   */ _onAfterViewRender = /*#__PURE__*/ new WeakSet(), /**
   * Called after the rendering of the table is completed. It updates the width of
   * the pagination container to the same size as the table.
   */ _onAfterRender = /*#__PURE__*/ new WeakSet(), /**
   * Called before the height of the table is changed. It adjusts the table height to fit the pagination container
   * in declared height.
   *
   * @param {number|string} height Table height.
   * @returns {string} Returns the new table height.
   */ _onBeforeHeightChange = /*#__PURE__*/ new WeakSet(), /**
   * Called after the initialization of the plugin. It computes the initial state of the pagination.
   */ _onInit = /*#__PURE__*/ new WeakSet(), /**
   * Called after the vertical scrolling of the table is completed. It refreshes
   * the border state of the pagination UI.
   */ _onAfterScrollVertically = /*#__PURE__*/ new WeakSet(), /**
   * Called after the language change. It recomputes the pagination state which updates the UI.
   */ _onAfterLanguageChange = /*#__PURE__*/ new WeakSet(), /**
   * Called after the theme is set. It updates the theme of the pagination container.
   *
   * @param {string | undefined} themeName The name of the theme to use.
   */ _onAfterSetTheme = /*#__PURE__*/ new WeakSet(), /**
   * IndexMapper cache update listener. Once the cache is updated, we need to recompute
   * the pagination state.
   *
   * The method uses arrow function to keep the reference to the class method. Necessary for
   * the `removeLocalHook` method of the row index mapper.
   */ _onIndexCacheUpdate = /*#__PURE__*/ new WeakMap();
/* eslint-disable jsdoc/require-description-complete-sentence */ /**
 * @plugin Pagination
 * @class Pagination
 *
 * @description
 * The plugin adds full-featured pagination capabilities to a table component.
 * It manages splitting rows into pages, rendering navigation controls, and exposing
 * methods and configuration for initializing and updating pagination state.
 *
 * Core responsibilities:
 *  - Calculate which rows should be visible based on current `page` and `pageSize`.
 *  - Render a toolbar area containing:
 *    - a page size dropdown section (if `showPageSize` = `true`)
 *    - a row counter section ("1 - 10 of 50", if `showCounter` = `true`)
 *    - page navigation section (if `showNavigation` = `true`)
 *  - Emit hooks when:
 *    - the user navigates to a different page
 *    - the user changes the number of rows per page
 *    - the user changes the visibility of any sections
 *  - Allow external code to programmatically:
 *    - jump to a specific page
 *    - change the page size
 *    - change the visibility of UI sections
 *
 * @example
 *
 * ::: only-for javascript
 * ```js
 * const hot = new Handsontable(document.getElementById('example'), {
 *   data: getData(),
 *   pagination: {
 *     pageSize: 10,
 *     pageSizeList: ['auto', 5, 10, 20, 50, 100],
 *     initialPage: 1,
 *     showPageSize: true,
 *     showCounter: true,
 *     showNavigation: true,
 *  },
 * });
 * ```
 * :::
 *
 * ::: only-for react
 * ```jsx
 * <HotTable
 *   data={getData()}
 *   pagination={{
 *     pageSize: 10,
 *     pageSizeList: ['auto', 5, 10, 20, 50, 100],
 *     initialPage: 1,
 *     showPageSize: true,
 *     showCounter: true,
 *     showNavigation: true,
 *   }}
 * />
 * ```
 * :::
 *
 * ::: only-for angular
 * ```ts
 * settings = {
 *   pagination: {
 *     pageSize: 10,
 *     pageSizeList: ['auto', 5, 10, 20, 50, 100],
 *     initialPage: 1,
 *     showPageSize: true,
 *     showCounter: true,
 *     showNavigation: true,
 *   },
 * };
 * ```
 * :::
 */ export class Pagination extends BasePlugin {
    static get PLUGIN_KEY() {
        return PLUGIN_KEY;
    }
    static get PLUGIN_PRIORITY() {
        return PLUGIN_PRIORITY;
    }
    static get DEFAULT_SETTINGS() {
        return {
            pageSize: 10,
            pageSizeList: [
                'auto',
                5,
                10,
                20,
                50,
                100
            ],
            initialPage: 1,
            showPageSize: true,
            showCounter: true,
            showNavigation: true,
            uiContainer: null
        };
    }
    /**
   * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
   * hook and if it returns `true` than the {@link Pagination#enablePlugin} method is called.
   *
   * @returns {boolean}
   */ isEnabled() {
        return !!this.hot.getSettings()[PLUGIN_KEY];
    }
    /**
   * Enables the plugin functionality for this Handsontable instance.
   */ enablePlugin() {
        if (this.enabled) {
            return;
        }
        const settings = this.hot.getSettings()[PLUGIN_KEY];
        if (settings?.initialPage !== undefined) {
            _class_private_field_set(this, _currentPage, this.getSetting('initialPage'));
        }
        if (settings?.pageSize !== undefined) {
            _class_private_field_set(this, _pageSize, this.getSetting('pageSize'));
        }
        _class_private_field_set(this, _isDataProviderActive, this.hot.runHooks('hasExternalDataSource') === true);
        _class_private_field_set(this, _serverSideTotalCount, null);
        _class_private_field_set(this, _pagedRowsMap, this.hot.rowIndexMapper.createAndRegisterIndexMap(this.pluginName, 'hiding', false));
        if (_class_private_field_get(this, _pageSize) === 'auto' && !this.hot.getPlugin('autoRowSize')?.enabled) {
            warn(AUTO_PAGE_SIZE_WARNING);
        }
        _class_private_field_set(this, _calcStrategy, createPaginatorStrategy(_class_private_field_get(this, _pageSize) === 'auto' ? 'auto' : 'fixed'));
        if (!_class_private_field_get(this, _ui)) {
            _class_private_field_set(this, _ui, new PaginationUI({
                rootElement: this.hot.rootGridElement,
                uiContainer: this.getSetting('uiContainer'),
                isRtl: this.hot.isRtl(),
                themeName: this.hot.getCurrentThemeName(),
                phraseTranslator: (...args)=>this.hot.getTranslatedPhrase(...args),
                shouldHaveBorder: ()=>_class_private_method_get(this, _computeNeedsBorder, computeNeedsBorder).call(this),
                a11yAnnouncer: (message)=>announce(message)
            }));
            _class_private_method_get(this, _updateSectionsVisibilityState, updateSectionsVisibilityState).call(this);
            _class_private_field_get(this, _ui).addLocalHook('firstPageClick', ()=>this.firstPage()).addLocalHook('prevPageClick', ()=>this.prevPage()).addLocalHook('nextPageClick', ()=>this.nextPage()).addLocalHook('lastPageClick', ()=>this.lastPage()).addLocalHook('pageSizeChange', (pageSize)=>this.setPageSize(pageSize));
        }
        // Place the onInit hook before others to make sure that the pagination state is computed
        // and applied to the index mapper before AutoColumnSize plugin begins calculate the column sizes.
        this.addHook('init', (...args)=>_class_private_method_get(this, _onInit, onInit).call(this, ...args), -1);
        this.addHook('beforeSelectAll', (...args)=>_class_private_method_get(this, _onBeforeSelectAllRows, onBeforeSelectAllRows).call(this, ...args));
        this.addHook('beforeSelectColumns', (...args)=>_class_private_method_get(this, _onBeforeSelectAllRows, onBeforeSelectAllRows).call(this, ...args));
        this.addHook('beforeSetRangeEnd', (...args)=>_class_private_method_get(this, _onBeforeSetRangeEnd, onBeforeSetRangeEnd).call(this, ...args));
        this.addHook('beforeSelectionHighlightSet', (...args)=>_class_private_method_get(this, _onBeforeSelectionHighlightSet, onBeforeSelectionHighlightSet).call(this, ...args));
        this.addHook('beforePaste', (...args)=>_class_private_method_get(this, _onBeforePaste, onBeforePaste).call(this, ...args));
        this.addHook('afterViewRender', (...args)=>_class_private_method_get(this, _onAfterViewRender, onAfterViewRender).call(this, ...args));
        this.addHook('afterRender', (...args)=>_class_private_method_get(this, _onAfterRender, onAfterRender).call(this, ...args));
        this.addHook('afterScrollVertically', (...args)=>_class_private_method_get(this, _onAfterScrollVertically, onAfterScrollVertically).call(this, ...args));
        this.addHook('afterLanguageChange', (...args)=>_class_private_method_get(this, _onAfterLanguageChange, onAfterLanguageChange).call(this, ...args));
        this.addHook('beforeHeightChange', (...args)=>_class_private_method_get(this, _onBeforeHeightChange, onBeforeHeightChange).call(this, ...args));
        this.addHook('afterSetTheme', (...args)=>_class_private_method_get(this, _onAfterSetTheme, onAfterSetTheme).call(this, ...args));
        this.addHook('afterDataProviderFetch', (...args)=>_class_private_field_get(this, _onAfterDataProviderFetch).call(this, ...args), -1);
        this.hot.rowIndexMapper.addLocalHook('cacheUpdated', _class_private_field_get(this, _onIndexCacheUpdate));
        _class_private_method_get(this, _registerFocusScope, registerFocusScope).call(this);
        super.enablePlugin();
    }
    /**
   * Restores the page after a failed external load.
   *
   * @param {number} previousPage Page to restore (1-based).
   * @category Pagination
   */ revertPageTo(previousPage) {
        const attemptedPage = _class_private_field_get(this, _currentPage);
        _class_private_method_get(this, _setCurrentPage, setCurrentPage).call(this, previousPage);
        this.hot.scrollViewportTo({
            row: 0
        });
        _class_private_method_get(this, _refreshUI, refreshUI).call(this);
        this.hot.runHooks('afterPageChange', attemptedPage, previousPage);
    }
    /**
   * Restores the page size after a failed external load.
   *
   * @param {number | 'auto'} previousPageSize Previous page size.
   * @category Pagination
   */ revertPageSizeTo(previousPageSize) {
        const attemptedPageSize = _class_private_field_get(this, _pageSize);
        _class_private_method_get(this, _setPageSizeValue, setPageSizeValue).call(this, previousPageSize);
        _class_private_method_get(this, _refreshUI, refreshUI).call(this);
        this.hot.runHooks('afterPageSizeChange', attemptedPageSize, previousPageSize);
    }
    /**
   * Updates the plugin state. This method is executed when {@link Core#updateSettings} is invoked.
   */ updatePlugin() {
        this.disablePlugin();
        this.enablePlugin();
        _class_private_method_get(this, _refreshUI, refreshUI).call(this);
        super.updatePlugin();
    }
    /**
   * Disables the plugin functionality for this Handsontable instance.
   */ disablePlugin() {
        this.hot.rowIndexMapper.removeLocalHook('cacheUpdated', _class_private_field_get(this, _onIndexCacheUpdate)).unregisterMap(this.pluginName);
        _class_private_method_get(this, _unregisterFocusScope, unregisterFocusScope).call(this);
        _class_private_field_get(this, _ui).destroy();
        _class_private_field_set(this, _ui, null);
        super.disablePlugin();
    }
    /**
   * Gets the pagination current state. Returns an object with the following properties:
   *  - `currentPage`: The current page number.
   *  - `totalPages`: The total number of pages.
   *  - `pageSize`: The page size.
   *  - `pageSizeList`: The list of page sizes.
   *  - `autoPageSize`: Whether the page size is calculated automatically.
   *  - `numberOfRenderedRows`: The number of rendered rows.
   *  - `firstVisibleRowIndex`: The index of the first visible row.
   *  - `lastVisibleRowIndex`: The index of the last visible row.
   *
   * @returns {{
   *   currentPage: number,
   *   totalPages: number,
   *   pageSize: number,
   *   pageSizeList: Array<number | 'auto'>,
   *   autoPageSize: boolean,
   *   numberOfRenderedRows: number,
   *   firstVisibleRowIndex: number,
   *   lastVisibleRowIndex: number
   * }}
   */ getPaginationData() {
        const totalPages = _class_private_field_get(this, _calcStrategy).getTotalPages();
        let firstVisibleRowIndex = -1;
        let lastVisibleRowIndex = -1;
        if (_class_private_field_get(this, _isDataProviderActive)) {
            const countRows = this.hot.countRows();
            if (countRows > 0) {
                firstVisibleRowIndex = 0;
                lastVisibleRowIndex = countRows - 1;
            }
        } else {
            const { pageSize, startIndex } = _class_private_field_get(this, _calcStrategy).getState(_class_private_field_get(this, _currentPage));
            const countRows = this.hot.countRows();
            let visibleCount = 0;
            for(let rowIndex = startIndex; visibleCount < pageSize; rowIndex++){
                if (rowIndex >= countRows) {
                    break;
                }
                if (this.hot.rowIndexMapper.isHidden(this.hot.toPhysicalRow(rowIndex))) {
                    continue;
                }
                if (firstVisibleRowIndex === -1) {
                    firstVisibleRowIndex = rowIndex;
                }
                lastVisibleRowIndex = rowIndex;
                visibleCount += 1;
            }
        }
        const stateForReturn = _class_private_field_get(this, _calcStrategy).getState(_class_private_field_get(this, _currentPage));
        return {
            currentPage: _class_private_field_get(this, _currentPage),
            totalPages,
            pageSize: stateForReturn?.pageSize ?? _class_private_field_get(this, _pageSize),
            pageSizeList: [
                ...this.getSetting('pageSizeList')
            ],
            autoPageSize: _class_private_field_get(this, _pageSize) === 'auto',
            numberOfRenderedRows: this.hot.rowIndexMapper.getRenderableIndexesLength(),
            firstVisibleRowIndex,
            lastVisibleRowIndex
        };
    }
    /**
   * Returns the current 1-based page index from internal pagination state.
   *
   * @returns {number} Current page (at least 1).
   */ getCurrentPage() {
        return _class_private_field_get(this, _currentPage);
    }
    /**
   * Returns the current page size from internal pagination state. May be `'auto'`.
   *
   * @returns {number | 'auto'} Current page size or `'auto'`.
   */ getCurrentPageSize() {
        return _class_private_field_get(this, _pageSize);
    }
    /**
   * Allows changing the page for specified page number.
   *
   * @param {number} pageNumber The page number to set (from 1 to N). If `0` is passed, it
   * will be transformed to `1`.
   * @fires Hooks#beforePageChange
   * @fires Hooks#afterPageChange
   */ setPage(pageNumber) {
        const oldPage = _class_private_field_get(this, _currentPage);
        const shouldProceed = this.hot.runHooks('beforePageChange', oldPage, pageNumber);
        if (shouldProceed === false) {
            return;
        }
        _class_private_method_get(this, _setCurrentPage, setCurrentPage).call(this, pageNumber);
        _class_private_method_get(this, _refreshUI, refreshUI).call(this);
        this.hot.scrollViewportTo({
            row: 0
        });
        this.hot.runHooks('afterPageChange', oldPage, _class_private_field_get(this, _currentPage));
    }
    /**
   * Resets the current page to the initial page (`initialValue`) defined in the settings.
   */ resetPage() {
        this.setPage(this.getSetting('initialPage'));
    }
    /**
   * Changes the page size for the pagination. The method recalculates the state based
   * on the new page size and re-renders the table. If `'auto'` is passed, the plugin will
   * calculate the page size based on the viewport size and row heights to make sure
   * that there will be no vertical scrollbar in the table.
   *
   * @param {number | 'auto'} pageSize The page size to set.
   * @fires Hooks#beforePageSizeChange
   * @fires Hooks#afterPageSizeChange
   */ setPageSize(pageSize) {
        const oldPageSize = _class_private_field_get(this, _pageSize);
        const shouldProceed = this.hot.runHooks('beforePageSizeChange', oldPageSize, pageSize);
        if (shouldProceed === false) {
            return;
        }
        if (pageSize === 'auto' && !this.hot.getPlugin('autoRowSize')?.enabled) {
            warn(AUTO_PAGE_SIZE_WARNING);
        }
        _class_private_method_get(this, _setPageSizeValue, setPageSizeValue).call(this, pageSize);
        _class_private_method_get(this, _refreshUI, refreshUI).call(this);
        this.hot.runHooks('afterPageSizeChange', oldPageSize, _class_private_field_get(this, _pageSize));
    }
    /**
   * Resets the page size to the initial value (`pageSize`) defined in the settings.
   */ resetPageSize() {
        this.setPageSize(this.getSetting('pageSize'));
    }
    /**
   * Resets the pagination state to the initial values defined in the settings.
   */ resetPagination() {
        this.resetPage();
        this.resetPageSize();
        _class_private_method_get(this, _updateSectionsVisibilityState, updateSectionsVisibilityState).call(this);
    }
    /**
   * Switches the page to the next one.
   */ nextPage() {
        this.setPage(_class_private_field_get(this, _currentPage) + 1);
    }
    /**
   * Switches the page to the previous one.
   */ prevPage() {
        this.setPage(_class_private_field_get(this, _currentPage) - 1);
    }
    /**
   * Switches the page to the first one.
   */ firstPage() {
        this.setPage(1);
    }
    /**
   * Switches the page to the last one.
   */ lastPage() {
        this.setPage(_class_private_field_get(this, _calcStrategy).getTotalPages());
    }
    /**
   * Checks, based on the current internal state, if there is a previous page.
   *
   * @returns {boolean}
   */ hasPreviousPage() {
        return _class_private_field_get(this, _currentPage) > 1;
    }
    /**
   * Checks, based on the current internal state, if there is a next page.
   *
   * @returns {boolean}
   */ hasNextPage() {
        return _class_private_field_get(this, _currentPage) < _class_private_field_get(this, _calcStrategy).getTotalPages();
    }
    /**
   * Gets the visual data for the current page. The returned data may be longer than the defined
   * page size as the data may contain hidden rows (rows that are not rendered in the table).
   *
   * @returns {Array<Array>} Returns the data for the current page.
   */ getCurrentPageData() {
        const { firstVisibleRowIndex, lastVisibleRowIndex } = this.getPaginationData();
        if (firstVisibleRowIndex === -1 || lastVisibleRowIndex === -1) {
            return [];
        }
        return this.hot.getData(firstVisibleRowIndex, 0, lastVisibleRowIndex, this.hot.countCols() - 1);
    }
    /**
   * Shows the page size section in the pagination UI.
   *
   * @fires Hooks#afterPageSizeVisibilityChange
   */ showPageSizeSection() {
        _class_private_field_get(this, _ui).setPageSizeSectionVisibility(true);
        this.hot.runHooks('afterPageSizeVisibilityChange', true);
    }
    /**
   * Hides the page size section in the pagination UI.
   *
   * @fires Hooks#afterPageSizeVisibilityChange
   */ hidePageSizeSection() {
        _class_private_field_get(this, _ui).setPageSizeSectionVisibility(false);
        this.hot.runHooks('afterPageSizeVisibilityChange', false);
    }
    /**
   * Shows the page counter section in the pagination UI.
   *
   * @fires Hooks#afterPageCounterVisibilityChange
   */ showPageCounterSection() {
        _class_private_field_get(this, _ui).setCounterSectionVisibility(true);
        this.hot.runHooks('afterPageCounterVisibilityChange', true);
    }
    /**
   * Hides the page counter section in the pagination UI.
   *
   * @fires Hooks#afterPageCounterVisibilityChange
   */ hidePageCounterSection() {
        _class_private_field_get(this, _ui).setCounterSectionVisibility(false);
        this.hot.runHooks('afterPageCounterVisibilityChange', false);
    }
    /**
   * Shows the page navigation section in the pagination UI.
   *
   * @fires Hooks#afterPageNavigationVisibilityChange
   */ showPageNavigationSection() {
        _class_private_field_get(this, _ui).setNavigationSectionVisibility(true);
        this.hot.runHooks('afterPageNavigationVisibilityChange', true);
    }
    /**
   * Hides the page navigation section in the pagination UI.
   *
   * @fires Hooks#afterPageNavigationVisibilityChange
   */ hidePageNavigationSection() {
        _class_private_field_get(this, _ui).setNavigationSectionVisibility(false);
        this.hot.runHooks('afterPageNavigationVisibilityChange', false);
    }
    /**
   * Destroys the plugin instance.
   */ destroy() {
        _class_private_field_set(this, _pagedRowsMap, null);
        _class_private_field_set(this, _calcStrategy, null);
        _class_private_field_get(this, _ui)?.destroy();
        _class_private_field_set(this, _ui, null);
        super.destroy();
    }
    constructor(...args){
        super(...args), _class_private_method_init(this, _setCurrentPage), _class_private_method_init(this, _setPageSizeValue), _class_private_method_init(this, _refreshUI), _class_private_method_init(this, _updateSectionsVisibilityState), _class_private_method_init(this, _computeAndApplyState), _class_private_method_init(this, _computeNeedsBorder), _class_private_method_init(this, _registerFocusScope), _class_private_method_init(this, _unregisterFocusScope), _class_private_method_init(this, _onBeforeSelectAllRows), _class_private_method_init(this, _onBeforeSetRangeEnd), _class_private_method_init(this, _onBeforeSelectionHighlightSet), _class_private_method_init(this, _onBeforePaste), _class_private_method_init(this, _onAfterViewRender), _class_private_method_init(this, _onAfterRender), _class_private_method_init(this, _onBeforeHeightChange), _class_private_method_init(this, _onInit), _class_private_method_init(this, _onAfterScrollVertically), _class_private_method_init(this, _onAfterLanguageChange), _class_private_method_init(this, _onAfterSetTheme), _class_private_field_init(this, _pagedRowsMap, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _currentPage, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _pageSize, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _ui, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _calcStrategy, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _internalExecutionCall, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _internalRenderCall, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _isDataProviderActive, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _serverSideTotalCount, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _onAfterDataProviderFetch, {
            writable: true,
            value: void 0
        }), _class_private_field_init(this, _onIndexCacheUpdate, {
            writable: true,
            value: void 0
        }), _class_private_field_set(this, _pagedRowsMap, null), _class_private_field_set(this, _currentPage, 1), _class_private_field_set(this, _pageSize, 10), _class_private_field_set(this, _ui, null), _class_private_field_set(this, _calcStrategy, null), _class_private_field_set(this, _internalExecutionCall, false), _class_private_field_set(this, _internalRenderCall, false), _class_private_field_set(this, _isDataProviderActive, false), _class_private_field_set(this, _serverSideTotalCount, null), _class_private_field_set(this, _onAfterDataProviderFetch, ({ queryParameters, totalRows })=>{
            if (!_class_private_field_get(this, _isDataProviderActive)) {
                return;
            }
            const oldPage = _class_private_field_get(this, _currentPage);
            const oldPageSize = _class_private_field_get(this, _pageSize);
            const { page, pageSize } = queryParameters;
            if (typeof page === 'number' && page >= 1) {
                _class_private_method_get(this, _setCurrentPage, setCurrentPage).call(this, page);
            }
            if (pageSize === 'auto') {
                _class_private_method_get(this, _setPageSizeValue, setPageSizeValue).call(this, 'auto');
            } else if (typeof pageSize === 'number' && pageSize >= 1) {
                _class_private_method_get(this, _setPageSizeValue, setPageSizeValue).call(this, pageSize);
            }
            if (_class_private_field_get(this, _isDataProviderActive) && typeof totalRows === 'number' && totalRows >= 0) {
                _class_private_field_set(this, _serverSideTotalCount, totalRows);
            }
            _class_private_method_get(this, _refreshUI, refreshUI).call(this);
            if (oldPage !== _class_private_field_get(this, _currentPage)) {
                this.hot.runHooks('afterPageChange', oldPage, _class_private_field_get(this, _currentPage));
            }
            if (oldPageSize !== _class_private_field_get(this, _pageSize)) {
                this.hot.runHooks('afterPageSizeChange', oldPageSize, _class_private_field_get(this, _pageSize));
            }
        }), _class_private_field_set(this, _onIndexCacheUpdate, ()=>{
            if (!_class_private_field_get(this, _internalExecutionCall) && this.hot?.view) {
                _class_private_method_get(this, _computeAndApplyState, computeAndApplyState).call(this);
            }
        });
    }
}
function setCurrentPage(page) {
    _class_private_field_set(this, _currentPage, page);
}
function setPageSizeValue(pageSize) {
    _class_private_field_set(this, _calcStrategy, createPaginatorStrategy(pageSize === 'auto' ? 'auto' : 'fixed'));
    _class_private_field_set(this, _pageSize, pageSize);
}
function refreshUI() {
    _class_private_method_get(this, _computeAndApplyState, computeAndApplyState).call(this);
    this.hot.view.adjustElementsSize();
    this.hot.render();
}
function updateSectionsVisibilityState() {
    if (this.getSetting('showPageSize')) {
        this.showPageSizeSection();
    } else {
        this.hidePageSizeSection();
    }
    if (this.getSetting('showCounter')) {
        this.showPageCounterSection();
    } else {
        this.hidePageCounterSection();
    }
    if (this.getSetting('showNavigation')) {
        this.showPageNavigationSection();
    } else {
        this.hidePageNavigationSection();
    }
}
function computeAndApplyState() {
    _class_private_field_set(this, _internalExecutionCall, true);
    _class_private_field_get(this, _pagedRowsMap).clear();
    const renderableIndexes = this.hot.rowIndexMapper.getRenderableIndexes();
    const renderableRowsLength = renderableIndexes.length;
    const { stylesHandler } = this.hot;
    const externalPagedMode = _class_private_field_get(this, _isDataProviderActive);
    const totalItems = externalPagedMode ? _class_private_field_get(this, _serverSideTotalCount) ?? renderableRowsLength : renderableRowsLength;
    _class_private_field_get(this, _calcStrategy).calculate({
        pageSize: _class_private_field_get(this, _pageSize),
        totalItems,
        viewportSizeProvider: ()=>{
            const { view } = this.hot;
            if (view.isVerticallyScrollableByWindow()) {
                const bodyStyle = getComputedStyle(this.hot.rootDocument.body);
                const margin = Number.parseInt(bodyStyle.marginTop, 10) + Number.parseInt(bodyStyle.marginBottom, 10);
                const columnHeaderHeight = this.hot.hasColHeaders() ? view._wt.wtTable.getColumnHeaderHeight() : 0;
                const paginationContainerHeight = _class_private_field_get(this, _ui).getHeight();
                const workspaceHeight = view.getWorkspaceHeight();
                return workspaceHeight - paginationContainerHeight - columnHeaderHeight - margin;
            }
            const scrollbarWidth = view.hasHorizontalScroll() ? getScrollbarWidth() : 0;
            return view.getViewportHeight() - scrollbarWidth;
        },
        itemsSizeProvider: ()=>{
            const rowHeights = this.hot.rowIndexMapper.getRenderableIndexes().map((physicalIndex)=>{
                const visualRowIndex = this.hot.toVisualRow(physicalIndex);
                return this.hot.getRowHeight(visualRowIndex) ?? stylesHandler.getDefaultRowHeight(visualRowIndex);
            });
            return rowHeights;
        }
    });
    const totalPages = _class_private_field_get(this, _calcStrategy).getTotalPages();
    _class_private_field_set(this, _currentPage, clamp(_class_private_field_get(this, _currentPage), 1, totalPages));
    if (!externalPagedMode && renderableIndexes.length > 0) {
        const { startIndex, pageSize } = _class_private_field_get(this, _calcStrategy).getState(_class_private_field_get(this, _currentPage));
        renderableIndexes.splice(startIndex, pageSize);
    }
    if (!externalPagedMode && renderableIndexes.length > 0) {
        this.hot.batchExecution(()=>{
            renderableIndexes.forEach((index)=>_class_private_field_get(this, _pagedRowsMap).setValueAtIndex(index, true));
        }, true);
    } else if (!externalPagedMode) {
        this.hot.rowIndexMapper.updateCache(true);
    }
    _class_private_field_set(this, _internalExecutionCall, false);
    const paginationData = this.getPaginationData();
    const uiState = {
        ...paginationData,
        totalRenderedRows: externalPagedMode ? totalItems : renderableRowsLength
    };
    if (externalPagedMode) {
        const totalRows = totalItems;
        const pageSize = _class_private_field_get(this, _calcStrategy).getState(_class_private_field_get(this, _currentPage))?.pageSize ?? _class_private_field_get(this, _pageSize);
        uiState.counterStartRow = (_class_private_field_get(this, _currentPage) - 1) * pageSize + 1;
        uiState.counterEndRow = Math.min(_class_private_field_get(this, _currentPage) * pageSize, totalRows);
    }
    _class_private_field_get(this, _ui).updateState(uiState);
}
function computeNeedsBorder() {
    if (!this.hot.view) {
        return true;
    }
    const { view } = this.hot;
    if (view.isVerticallyScrollableByWindow()) {
        return false;
    }
    if (view.hasHorizontalScroll() || view.getTableHeight() < view.getWorkspaceHeight()) {
        return true;
    }
    const { lastVisibleRowIndex } = this.getPaginationData();
    return view.getLastFullyVisibleRow() !== lastVisibleRowIndex;
}
function registerFocusScope() {
    this.hot.getFocusScopeManager().registerScope(PLUGIN_KEY, _class_private_field_get(this, _ui).getContainer(), {
        shortcutsContextName: SHORTCUTS_CONTEXT_NAME,
        runOnlyIf: ()=>this.getSetting('showPageSize') || this.getSetting('showNavigation'),
        onActivate: (focusSource)=>{
            const focusableElements = _class_private_field_get(this, _ui).getFocusableElements();
            if (focusableElements.length > 0) {
                if (focusSource === 'tab_from_above') {
                    focusableElements.at(0).focus();
                } else if (focusSource === 'tab_from_below') {
                    focusableElements.at(-1).focus();
                }
            }
        }
    });
}
function unregisterFocusScope() {
    this.hot.getFocusScopeManager().unregisterScope(PLUGIN_KEY);
}
function onBeforeSelectAllRows(from, to) {
    const { firstVisibleRowIndex, lastVisibleRowIndex } = this.getPaginationData();
    if (_class_private_field_get(this, _currentPage) > 1 || from.row >= 0) {
        from.row = firstVisibleRowIndex;
    }
    to.row = lastVisibleRowIndex;
}
function onBeforeSetRangeEnd(coords) {
    if (this.hot.selection.isSelectedByColumnHeader()) {
        const { lastVisibleRowIndex } = this.getPaginationData();
        coords.row = lastVisibleRowIndex;
    }
}
function onBeforeSelectionHighlightSet() {
    if (!this.hot.getSettings().navigableHeaders) {
        return;
    }
    const selectedRange = this.hot.getSelectedRangeLast();
    if (!selectedRange.isSingle()) {
        const { highlight } = selectedRange;
        highlight.row = clamp(highlight.row, selectedRange.getTopStartCorner().row, selectedRange.getBottomEndCorner().row);
    }
}
function onBeforePaste(pastedData, ranges) {
    const { firstVisibleRowIndex, lastVisibleRowIndex } = this.getPaginationData();
    if (firstVisibleRowIndex === -1 || lastVisibleRowIndex === -1) {
        return false;
    }
    ranges.forEach(({ startRow })=>{
        if (pastedData.length === 0) {
            return;
        }
        const rowsToRemove = Math.min(pastedData.length - (lastVisibleRowIndex - startRow + 1), pastedData.length);
        pastedData.splice(0, rowsToRemove);
    });
}
function onAfterViewRender() {
    if (_class_private_field_get(this, _pageSize) !== 'auto' || _class_private_field_get(this, _internalRenderCall)) {
        _class_private_field_set(this, _internalRenderCall, false);
        return;
    }
    _class_private_field_set(this, _internalRenderCall, true);
    _class_private_method_get(this, _refreshUI, refreshUI).call(this);
}
function onAfterRender() {
    const { view } = this.hot;
    const width = view.isHorizontallyScrollableByWindow() ? view.getTotalTableWidth() : view.getWorkspaceWidth();
    _class_private_field_get(this, _ui).updateWidth(width).refreshBorderState();
}
function onBeforeHeightChange(height) {
    if (this.getSetting('uiContainer')) {
        return height;
    }
    const isPixelValue = typeof height === 'number' || typeof height === 'string' && /^\d+$/.test(height) || typeof height === 'string' && height.endsWith('px');
    if (!isPixelValue) {
        return height;
    }
    const heightValue = typeof height === 'string' && height.endsWith('px') ? height : `${height}px`;
    return `calc(${heightValue} - ${_class_private_field_get(this, _ui).getHeight()}px)`;
}
function onInit() {
    if (_class_private_field_get(this, _pageSize) === 'auto') {
        return;
    }
    _class_private_method_get(this, _computeAndApplyState, computeAndApplyState).call(this);
}
function onAfterScrollVertically() {
    _class_private_field_get(this, _ui).refreshBorderState();
}
function onAfterLanguageChange() {
    _class_private_method_get(this, _refreshUI, refreshUI).call(this);
}
function onAfterSetTheme(themeName) {
    _class_private_field_get(this, _ui).updateTheme(themeName);
}
