/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { ReferenceType } from "./ops.mjs";
/**
 * @internal
 */
export const reservedTileLabelsKey = "referenceTileLabels";
/**
 * @internal
 */
export const reservedRangeLabelsKey = "referenceRangeLabels";
/**
 * @internal
 */
export function refTypeIncludesFlag(refPosOrType, flags) {
    const refType = typeof refPosOrType === "number" ? refPosOrType : refPosOrType.refType;
    // eslint-disable-next-line no-bitwise
    return (refType & flags) !== 0;
}
/**
 * @internal
 */
export const refGetTileLabels = (refPos) => refTypeIncludesFlag(refPos, ReferenceType.Tile) && refPos.properties
    ? refPos.properties[reservedTileLabelsKey]
    : undefined;
/**
 * @internal
 */
export function refHasTileLabel(refPos, label) {
    const tileLabels = refGetTileLabels(refPos);
    return tileLabels?.includes(label) ?? false;
}
/**
 * @internal
 */
export function refHasTileLabels(refPos) {
    return refGetTileLabels(refPos) !== undefined;
}
/**
 * @internal
 */
export const DetachedReferencePosition = -1;
/**
 * @internal
 */
export function minReferencePosition(a, b) {
    return compareReferencePositions(a, b) < 0 ? a : b;
}
/**
 * @internal
 */
export function maxReferencePosition(a, b) {
    return compareReferencePositions(a, b) > 0 ? a : b;
}
/**
 * @internal
 */
export 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;
    }
}
//# sourceMappingURL=referencePositions.mjs.map