/**
 * DevExtreme (cjs/__internal/utils/version.js)
 * Version: 23.2.9 (build 24294-0112)
 * Build date: Sun Oct 20 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.assertDevExtremeVersion = assertDevExtremeVersion;
exports.assertedVersionsCompatible = assertedVersionsCompatible;
exports.clearAssertedVersions = clearAssertedVersions;
exports.parseVersion = parseVersion;
var _errors = _interopRequireDefault(require("../../core/errors"));

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}
const assertedVersions = [];
const VERSION_SPLITTER = ".";

function stringifyVersion(version) {
    const {
        major: major,
        minor: minor,
        patch: patch
    } = version;
    return [major, minor, patch].join(".")
}

function parseVersion(version) {
    const [major, minor, patch] = version.split(".").map(Number);
    return {
        major: major,
        minor: minor,
        patch: patch
    }
}

function assertDevExtremeVersion(packageName, version) {
    assertedVersions.push({
        packageName: packageName,
        version: version
    })
}

function clearAssertedVersions() {}

function stringifyVersionList(assertedVersionList) {
    return assertedVersionList.map(assertedVersion => "".concat(assertedVersion.packageName, ": ").concat(assertedVersion.version)).join("\n")
}

function versionsEqual(versionA, versionB) {
    return versionA.major === versionB.major && versionA.minor === versionB.minor && versionA.patch === versionB.patch
}

function assertedVersionsCompatible(currentVersion) {
    const mismatchingVersions = assertedVersions.filter(assertedVersion => !versionsEqual(parseVersion(assertedVersion.version), currentVersion));
    if (mismatchingVersions.length) {
        _errors.default.log("W0023", stringifyVersionList([{
            packageName: "devextreme",
            version: stringifyVersion(currentVersion)
        }, ...mismatchingVersions]));
        return false
    }
    return true
}
