var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyManager = void 0;
var Logger_1 = require("../Logger");
var KeyManager = /** @class */ (function () {
    function KeyManager() {
        this.ids = [];
    }
    KeyManager.prototype.register = function (keyID) {
        if (!this.ids.includes(keyID))
            this.ids.push(keyID);
        else {
            (0, Logger_1.Log)('warn', "Duplicate key IDs '".concat(keyID, "'"));
            keyID = this.generateNew();
        }
        return keyID;
    };
    KeyManager.prototype.generateNew = function () {
        var _this = this;
        return this.register(Undecked.generateRandom(16, function (checkValid) {
            return !_this.ids.includes(checkValid);
        }));
    };
    KeyManager.prototype.getLocation = function (keyID) {
        var pages = Undecked.Pages.getAll();
        for (var pageID in pages) {
            var page = pages[pageID];
            if (page.hasKeyWithID(keyID)) {
                return __assign({ pageID: pageID }, page.getKeyLocationWithID(keyID));
            }
        }
        return { pageID: null, x: null, y: null };
    };
    return KeyManager;
}());
exports.KeyManager = KeyManager;
//# sourceMappingURL=KeyManager.js.map