"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 BindRowsWithHeaders () {
        return BindRowsWithHeaders;
    },
    get PLUGIN_KEY () {
        return PLUGIN_KEY;
    },
    get PLUGIN_PRIORITY () {
        return PLUGIN_PRIORITY;
    }
});
const _base = require("../base");
const _looseBindsMap = /*#__PURE__*/ _interop_require_default(require("./maps/looseBindsMap"));
const _strictBindsMap = /*#__PURE__*/ _interop_require_default(require("./maps/strictBindsMap"));
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_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
    };
}
const PLUGIN_KEY = 'bindRowsWithHeaders';
const PLUGIN_PRIORITY = 210;
const DEFAULT_BIND = 'loose';
const bindTypeToMapStrategy = new Map([
    [
        'loose',
        _looseBindsMap.default
    ],
    [
        'strict',
        _strictBindsMap.default
    ]
]);
var /**
   * On modify row header listener.
   *
   * @param {number} row Row index.
   * @returns {number}
   */ _onModifyRowHeader = /*#__PURE__*/ new WeakSet();
class BindRowsWithHeaders 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 BindRowsWithHeaders#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 MapStrategy = bindTypeToMapStrategy.get(this.getSetting()) ?? bindTypeToMapStrategy.get(DEFAULT_BIND);
        this.headerIndexes = this.hot.rowIndexMapper.registerMap('bindRowsWithHeaders', new MapStrategy());
        this.addHook('modifyRowHeader', (row)=>_class_private_method_get(this, _onModifyRowHeader, onModifyRowHeader).call(this, row));
        super.enablePlugin();
    }
    /**
   * Disables the plugin functionality for this Handsontable instance.
   */ disablePlugin() {
        this.hot.rowIndexMapper.unregisterMap('bindRowsWithHeaders');
        super.disablePlugin();
    }
    /**
   * Destroys the plugin instance.
   */ destroy() {
        super.destroy();
    }
    constructor(...args){
        super(...args), _class_private_method_init(this, _onModifyRowHeader), /**
   * Plugin indexes cache.
   *
   * @private
   * @type {null|IndexMap}
   */ this.headerIndexes = null;
    }
}
function onModifyRowHeader(row) {
    return this.headerIndexes.getValueAtIndex(this.hot.toPhysicalRow(row));
}
