"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, /**
 * nvu list
 *
 * List all installed Node versions.
 */ "default", {
    enumerable: true,
    get: function() {
        return listCmd;
    }
});
var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"));
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
var _compatts = require("../compat.js");
var _constantsts = require("../constants.js");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function listCmd(_args) {
    var versionsPath = _path.default.join(_constantsts.storagePath, 'installed');
    // Check if versions directory exists
    if (!_fs.default.existsSync(versionsPath)) {
        console.log('No Node versions installed.');
        console.log('Install a version: nvu install <version>');
        (0, _exitcompat.default)(0);
        return;
    }
    // Read all directories in versions folder
    var entries = (0, _compatts.readdirWithTypes)(versionsPath);
    var versions = entries.filter(function(entry) {
        return entry.isDirectory();
    }).map(function(entry) {
        return entry.name;
    });
    if (versions.length === 0) {
        console.log('No Node versions installed.');
        console.log('Install a version: nvu install <version>');
        (0, _exitcompat.default)(0);
        return;
    }
    // Get the current default
    var defaultFilePath = _path.default.join(_constantsts.storagePath, 'default');
    var defaultVersion = '';
    if (_fs.default.existsSync(defaultFilePath)) {
        defaultVersion = _fs.default.readFileSync(defaultFilePath, 'utf8').trim();
    }
    // Sort versions (simple string sort, could be improved with semver)
    versions.sort(function(a, b) {
        var aParts = a.split('.').map(function(n) {
            return parseInt(n, 10) || 0;
        });
        var bParts = b.split('.').map(function(n) {
            return parseInt(n, 10) || 0;
        });
        for(var i = 0; i < Math.max(aParts.length, bParts.length); i++){
            var aVal = aParts[i] || 0;
            var bVal = bParts[i] || 0;
            if (aVal !== bVal) return bVal - aVal; // Descending order
        }
        return 0;
    });
    console.log('Installed Node versions:');
    for(var i = 0; i < versions.length; i++){
        var version = versions[i];
        var isDefault = version === defaultVersion || "v".concat(version) === defaultVersion || version === "v".concat(defaultVersion);
        var marker = isDefault ? ' (default)' : '';
        console.log("  ".concat(version).concat(marker));
    }
    (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; }