"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.compareReferencePositions = exports.maxReferencePosition = exports.minReferencePosition = exports.DetachedReferencePosition = exports.refHasTileLabels = exports.refHasTileLabel = exports.refGetTileLabels = exports.refTypeIncludesFlag = exports.reservedRangeLabelsKey = exports.reservedTileLabelsKey = void 0;
const ops_1 = require("./ops.cjs");
/**
 * @internal
 */
exports.reservedTileLabelsKey = "referenceTileLabels";
/**
 * @internal
 */
exports.reservedRangeLabelsKey = "referenceRangeLabels";
/**
 * @internal
 */
function refTypeIncludesFlag(refPosOrType, flags) {
    const refType = typeof refPosOrType === "number" ? refPosOrType : refPosOrType.refType;
    // eslint-disable-next-line no-bitwise
    return (refType & flags) !== 0;
}
exports.refTypeIncludesFlag = refTypeIncludesFlag;
/**
 * @internal
 */
const refGetTileLabels = (refPos) => refTypeIncludesFlag(refPos, ops_1.ReferenceType.Tile) && refPos.properties
    ? refPos.properties[exports.reservedTileLabelsKey]
    : undefined;
exports.refGetTileLabels = refGetTileLabels;
/**
 * @internal
 */
function refHasTileLabel(refPos, label) {
    const tileLabels = (0, exports.refGetTileLabels)(refPos);
    return tileLabels?.includes(label) ?? false;
}
exports.refHasTileLabel = refHasTileLabel;
/**
 * @internal
 */
function refHasTileLabels(refPos) {
    return (0, exports.refGetTileLabels)(refPos) !== undefined;
}
exports.refHasTileLabels = refHasTileLabels;
/**
 * @internal
 */
exports.DetachedReferencePosition = -1;
/**
 * @internal
 */
function minReferencePosition(a, b) {
    return compareReferencePositions(a, b) < 0 ? a : b;
}
exports.minReferencePosition = minReferencePosition;
/**
 * @internal
 */
function maxReferencePosition(a, b) {
    return compareReferencePositions(a, b) > 0 ? a : b;
}
exports.maxReferencePosition = maxReferencePosition;
/**
 * @internal
 */
function compareReferencePositions(a, b) {
    const aSeg = a.getSegment();
    const bSeg = b.getSegment();
    if (aSeg === bSeg) {
        return a.getOffset() - b.getOffset();
    }
    else {
        return aSeg === undefined || (bSeg !== undefined && aSeg.ordinal < bSeg.ordinal) ? -1 : 1;
    }
}
exports.compareReferencePositions = compareReferencePositions;
//# sourceMappingURL=referencePositions.cjs.map