"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const devices_1 = require("@ledgerhq/devices");
const semver_1 = __importDefault(require("semver"));
/**
 * This code enforces a maximum device name length on the Live side due to a bug
 * in LNX <2.2.0 that breaks the BLE stack if the name is longer than 17 characters.
 * To ensure consistency with the maximum length that can be set on Stax (23), the
 * visible characters (20), and the maximum APDU-driven rename length (30), this
 * patch introduces a maximum length of 20 characters until all inconsistencies
 * are aligned.
 */
const getDeviceNameMaxLength = (props) => {
    const { deviceModelId, version } = props;
    let maxLength = 17; // Default for other models and versions.
    switch (deviceModelId) {
        case devices_1.DeviceModelId.nanoX: {
            const coercedVersion = semver_1.default.coerce(version);
            const validVersion = semver_1.default.valid(coercedVersion) || "";
            if (semver_1.default.gte(validVersion, "2.2.0")) {
                maxLength = 20;
            }
            break;
        }
        case devices_1.DeviceModelId.stax:
        case devices_1.DeviceModelId.europa:
        case devices_1.DeviceModelId.apex:
            maxLength = 20;
            break;
    }
    return maxLength;
};
exports.default = getDeviceNameMaxLength;
//# sourceMappingURL=getDeviceNameMaxLength.js.map