"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleRegister = handleRegister;
const workspace_root_1 = require("../../utils/workspace-root");
const enquirer_1 = require("enquirer");
const require_nx_key_1 = require("../../utils/require-nx-key");
async function handleRegister(options) {
    const nxKey = await (0, require_nx_key_1.requireNxKey)();
    // If a key was provided through options, activate it directly
    if (options.key) {
        return nxKey.activateNxKey(workspace_root_1.workspaceRoot, options.key);
    }
    // Try to auto-register a key
    const generatedKey = await nxKey.autoRegisterNxKey(workspace_root_1.workspaceRoot);
    if (generatedKey) {
        return;
    }
    // If auto-registration was skipped, prompt for a key
    const { key } = await (0, enquirer_1.prompt)({
        type: 'input',
        name: 'key',
        message: 'Enter your key',
    });
    return nxKey.activateNxKey(workspace_root_1.workspaceRoot, key);
}
