"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEqualReactSimple = exports.isEqualSimple = exports.isEqualReact = exports.isEqual = void 0;
var comparators_1 = require("./comparators");
var _a = Object.prototype, valueOf = _a.valueOf, toString = _a.toString;
var isEqual = function (a, b) {
    if (a === b)
        return true;
    if (a && b && typeof a === 'object' && typeof b === 'object') {
        var ctor = a.constructor;
        if (ctor !== b.constructor)
            return false;
        if (ctor === Array)
            return (0, comparators_1.compareArrays)(a, b, exports.isEqual);
        if (ctor === Date)
            return (0, comparators_1.compareDates)(a, b);
        if (ctor === RegExp)
            return (0, comparators_1.compareRegexps)(a, b);
        if (ctor === Map && a instanceof Map && b instanceof Map)
            return (0, comparators_1.compareMaps)(a, b, exports.isEqual);
        if (ctor === Set && a instanceof Set && b instanceof Set)
            return (0, comparators_1.compareSets)(a, b);
        if (ctor === DataView)
            return (0, comparators_1.compareDataViews)(a, b);
        if (ctor === ArrayBuffer) {
            return (0, comparators_1.compareArrayBuffers)(new Uint8Array(a), new Uint8Array(b));
        }
        if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
            return (0, comparators_1.compareArrayBuffers)(a, b);
        }
        if (a.valueOf !== valueOf)
            return a.valueOf() === b.valueOf();
        if (a.toString !== toString)
            return a.toString() === b.toString();
        return (0, comparators_1.compareObjects)(a, b, exports.isEqual);
    }
    // eslint-disable-next-line no-self-compare
    return a !== a && b !== b;
};
exports.isEqual = isEqual;
var isEqualReact = function (a, b) {
    if (a === b)
        return true;
    if (a && b && typeof a === 'object' && typeof b === 'object') {
        var ctor = a.constructor;
        if (ctor !== b.constructor)
            return false;
        if (ctor === Array)
            return (0, comparators_1.compareArrays)(a, b, exports.isEqual);
        if (ctor === Date)
            return (0, comparators_1.compareDates)(a, b);
        if (ctor === RegExp)
            return (0, comparators_1.compareRegexps)(a, b);
        if (ctor === Map && a instanceof Map && b instanceof Map)
            return (0, comparators_1.compareMaps)(a, b, exports.isEqual);
        if (ctor === Set && a instanceof Set && b instanceof Set)
            return (0, comparators_1.compareSets)(a, b);
        if (ctor === DataView)
            return (0, comparators_1.compareDataViews)(a, b);
        if (ctor === ArrayBuffer) {
            return (0, comparators_1.compareArrayBuffers)(new Uint8Array(a), new Uint8Array(b));
        }
        if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
            return (0, comparators_1.compareArrayBuffers)(a, b);
        }
        if (a.valueOf !== valueOf)
            return a.valueOf() === b.valueOf();
        if (a.toString !== toString)
            return a.toString() === b.toString();
        return (0, comparators_1.compareObjectsReact)(a, b, exports.isEqual);
    }
    // eslint-disable-next-line no-self-compare
    return a !== a && b !== b;
};
exports.isEqualReact = isEqualReact;
var isEqualSimple = function (a, b) {
    if (a === b)
        return true;
    if (a && b && typeof a === 'object' && typeof b === 'object') {
        var ctor = a.constructor;
        if (ctor !== b.constructor)
            return false;
        if (ctor === Array)
            return (0, comparators_1.compareArrays)(a, b, exports.isEqual);
        if (ctor === Date)
            return (0, comparators_1.compareDates)(a, b);
        if (ctor === RegExp)
            return (0, comparators_1.compareRegexps)(a, b);
        if (a.valueOf !== valueOf)
            return a.valueOf() === b.valueOf();
        if (a.toString !== toString)
            return a.toString() === b.toString();
        return (0, comparators_1.compareObjects)(a, b, exports.isEqual);
    }
    // eslint-disable-next-line no-self-compare
    return a !== a && b !== b;
};
exports.isEqualSimple = isEqualSimple;
var isEqualReactSimple = function (a, b) {
    if (a === b)
        return true;
    if (a && b && typeof a === 'object' && typeof b === 'object') {
        var ctor = a.constructor;
        if (ctor !== b.constructor)
            return false;
        if (ctor === Array)
            return (0, comparators_1.compareArrays)(a, b, exports.isEqual);
        if (ctor === Date)
            return (0, comparators_1.compareDates)(a, b);
        if (ctor === RegExp)
            return (0, comparators_1.compareRegexps)(a, b);
        if (a.valueOf !== valueOf)
            return a.valueOf() === b.valueOf();
        if (a.toString !== toString)
            return a.toString() === b.toString();
        return (0, comparators_1.compareObjectsReact)(a, b, exports.isEqual);
    }
    // eslint-disable-next-line no-self-compare
    return a !== a && b !== b;
};
exports.isEqualReactSimple = isEqualReactSimple;
