"use strict";
// Copyright 2017-2020 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("@polkadot/util");
function hasMismatch(a, b) {
    return util_1.isUndefined(a) || (
    // Codec has .eq, use it here
    util_1.isFunction(a.eq)
        ? !a.eq(b)
        : a !== b);
}
function notEntry(value) {
    return !Array.isArray(value) || value.length !== 2;
}
// NOTE These are used internally and when comparing objects, expects that
// when the second is an Map<string, Codec> that the first has to be as well
function compareMap(a, b) {
    if (Array.isArray(b)) {
        // equal number of entries and each entry in the array should match
        return (a.size === b.length) && !b.some((entry) => notEntry(entry) || hasMismatch(a.get(entry[0]), entry[1]));
    }
    else if (b instanceof Map) {
        return compareMap(a, [...b.entries()]);
    }
    else if (util_1.isObject(b)) {
        return compareMap(a, Object.entries(b));
    }
    return false;
}
exports.default = compareMap;
