/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
/**
 * Compares two PropertySets for equality.
 *
 * @internal
 */
export function matchProperties(a, b) {
    if (!a && !b) {
        return true;
    }
    const keysA = a ? Object.keys(a) : [];
    const keysB = b ? Object.keys(b) : [];
    if (keysA.length !== keysB.length) {
        return false;
    }
    for (const key of keysA) {
        if (b?.[key] === undefined) {
            return false;
        }
        else if (typeof b[key] === "object") {
            // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
            if (!matchProperties(a?.[key], b[key])) {
                return false;
            }
        }
        else if (b[key] !== a?.[key]) {
            return false;
        }
    }
    return true;
}
/**
 * Adds properties from one PropertySet to another.
 *
 * @internal
 */
export function extend(base, extension) {
    if (extension !== undefined) {
        for (const [key, v] of Object.entries(extension)) {
            if (v === undefined) {
                continue;
            }
            else if (v === null) {
                // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
                delete base[key];
            }
            else {
                base[key] = v;
            }
        }
    }
    return base;
}
/**
 * Clones properties in a given PropertySet into a new PropertySet.
 *
 * @internal
 */
export function clone(extension) {
    if (extension === undefined) {
        return undefined;
    }
    const cloneMap = createMap();
    return extend(cloneMap, extension);
}
/**
 * Add properties in one PropertySet to another PropertySet. If the PropertySet we are adding
 * to does not exist, create one.
 *
 * @internal
 */
export function addProperties(oldProps, newProps) {
    return extend(oldProps ?? createMap(), newProps);
}
/**
 * Replace values of undefined in one PropertySet with values for the same key from another PropertySet.
 *
 * @internal
 */
export function extendIfUndefined(base, extension) {
    if (extension !== undefined) {
        for (const [key, value] of Object.entries(extension)) {
            if (base[key] === undefined) {
                base[key] = value;
            }
        }
    }
    return base;
}
/**
 * Create a MapLike with good performance.
 *
 * @internal
 */
export function createMap() {
    return Object.create(null);
}
//# sourceMappingURL=properties.js.map