"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeHierarchicalOrdinal = void 0;
/* eslint-disable no-bitwise */
const internal_1 = require("@fluidframework/core-utils/internal");
function computeHierarchicalOrdinal(maxCount, actualCount, parentOrdinal, previousOrdinal) {
    (0, internal_1.assert)(maxCount <= 16 && actualCount <= maxCount, 0x3f0 /* count must be less than max, and max must be 16 or less */);
    const ordinalWidth = 1 << (maxCount - actualCount);
    let ordinal;
    if (previousOrdinal === undefined) {
        // Ordinals exist purely for lexicographical sort order and use a small set of valid bytes for each string character.
        // The extra handling fromCodePoint has for things like surrogate pairs is therefore unnecessary.
        // disable the rule to use code points when dealing with ordinals.
        // eslint-disable-next-line unicorn/prefer-code-point
        ordinal = parentOrdinal + String.fromCharCode(ordinalWidth - 1);
    }
    else {
        // eslint-disable-next-line unicorn/prefer-code-point
        const prevOrdCode = previousOrdinal.charCodeAt(previousOrdinal.length - 1);
        (0, internal_1.assert)(prevOrdCode !== undefined, 0x9ad /* previous ordinal should not be empty */);
        const localOrdinal = prevOrdCode + ordinalWidth;
        // eslint-disable-next-line unicorn/prefer-code-point
        ordinal = parentOrdinal + String.fromCharCode(localOrdinal);
    }
    return ordinal;
}
exports.computeHierarchicalOrdinal = computeHierarchicalOrdinal;
//# sourceMappingURL=ordinal.js.map