"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, /**
 * nvu install <version>
 *
 * Download and install a specific Node version.
 */ "default", {
    enumerable: true,
    get: function() {
        return installCmd;
    }
});
var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"));
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
var _constantsts = require("../constants.js");
var _loadNodeVersionInstallts = /*#__PURE__*/ _interop_require_default(require("../lib/loadNodeVersionInstall.js"));
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function installCmd(args) {
    if (args.length === 0) {
        console.log('Usage: nvu install <version>');
        console.log('Example: nvu install 20');
        console.log('         nvu install 20.10.0');
        console.log('         nvu install lts');
        (0, _exitcompat.default)(1);
        return;
    }
    var version = args[0].trim();
    // Validate version format (basic check, indexOf for Node 0.8+ compat)
    if (!version || version.indexOf('-') === 0) {
        console.log('Usage: nvu install <version>');
        (0, _exitcompat.default)(1);
        return;
    }
    console.log("Installing Node ".concat(version, "..."));
    // Load node-version-install dynamically
    (0, _loadNodeVersionInstallts.default)(function(err, nodeVersionInstall) {
        if (err || !nodeVersionInstall) {
            console.error('Failed to load node-version-install:', (err === null || err === void 0 ? void 0 : err.message) || 'Module not available');
            console.error('Make sure node-version-install is installed: npm install node-version-install');
            (0, _exitcompat.default)(1);
            return;
        }
        var versionsPath = _path.default.join(_constantsts.storagePath, 'installed');
        nodeVersionInstall(version, {
            installPath: versionsPath
        }, function(installErr, results) {
            if (installErr) {
                console.error("Failed to install Node ".concat(version, ":"), installErr.message);
                (0, _exitcompat.default)(1);
                return;
            }
            if (results && results.length > 0) {
                var result = results[0];
                console.log("Successfully installed Node ".concat(result.version));
                console.log("Location: ".concat(result.installPath));
            } else {
                console.log("Node ".concat(version, " installed successfully."));
            }
            (0, _exitcompat.default)(0);
        });
    });
}
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }