"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, /**
 * nvu local [version] [--nvurc]
 *
 * Write .nvmrc (or .nvurc) to the current directory.
 * This pins the Node version for the current project.
 */ "default", {
    enumerable: true,
    get: function() {
        return localCmd;
    }
});
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"));
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function localCmd(args) {
    var cwd = process.cwd();
    // Check for --nvurc flag (indexOf for Node 0.8+ compat)
    var useNvurc = args.indexOf('--nvurc') !== -1;
    var filteredArgs = args.filter(function(arg) {
        return arg !== '--nvurc';
    });
    var fileName = useNvurc ? '.nvurc' : '.nvmrc';
    var filePath = _path.default.join(cwd, fileName);
    // If no version provided, display current local version
    if (filteredArgs.length === 0) {
        // Check for existing version files
        var nvurcPath = _path.default.join(cwd, '.nvurc');
        var nvmrcPath = _path.default.join(cwd, '.nvmrc');
        if (_fs.default.existsSync(nvurcPath)) {
            var version = _fs.default.readFileSync(nvurcPath, 'utf8').trim();
            console.log("Current local version (.nvurc): ".concat(version));
            (0, _exitcompat.default)(0);
            return;
        }
        if (_fs.default.existsSync(nvmrcPath)) {
            var version1 = _fs.default.readFileSync(nvmrcPath, 'utf8').trim();
            console.log("Current local version (.nvmrc): ".concat(version1));
            (0, _exitcompat.default)(0);
            return;
        }
        console.log('No local version set in this directory.');
        console.log('Usage: nvu local <version>');
        console.log('       nvu local <version> --nvurc  (use .nvurc instead of .nvmrc)');
        (0, _exitcompat.default)(0);
        return;
    }
    var version2 = filteredArgs[0].trim();
    // Validate version format (basic check, indexOf for Node 0.8+ compat)
    if (!version2 || version2.indexOf('-') === 0) {
        console.log('Usage: nvu local <version>');
        console.log('Example: nvu local 20');
        (0, _exitcompat.default)(1);
        return;
    }
    // Write the version file
    _fs.default.writeFileSync(filePath, "".concat(version2, "\n"), 'utf8');
    console.log("Created ".concat(fileName, " with version: ").concat(version2));
    (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; }