"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const open_1 = __importDefault(require("open"));
const processManager_1 = require("../utils/processManager");
class OpenCommand {
    processManager;
    constructor() {
        this.processManager = new processManager_1.ProcessManager();
    }
    async execute(options) {
        const port = parseInt(options.port || '5173');
        const url = `http://localhost:${port}`;
        console.log(chalk_1.default.blue('🌐 Opening One Logger Web UI...'));
        // Check if the web UI is running
        const isRunning = await this.processManager.isPortInUse(port);
        if (!isRunning) {
            console.log(chalk_1.default.red(`❌ Web UI is not running on port ${port}`));
            console.log(chalk_1.default.yellow('💡 Run "one-logger start" to start the services first'));
            return;
        }
        try {
            await (0, open_1.default)(url);
            console.log(chalk_1.default.green(`✅ Opened ${url} in your default browser`));
        }
        catch (error) {
            console.error(chalk_1.default.red('❌ Failed to open browser:'), error);
            console.log(chalk_1.default.cyan(`🔗 You can manually open: ${url}`));
            throw error;
        }
    }
}
exports.OpenCommand = OpenCommand;
//# sourceMappingURL=open.js.map