"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServicesList = void 0;
const react_1 = __importStar(require("react"));
const ink_1 = require("ink");
const service_status_1 = require("../../lerna/enums/service.status");
const chalk_1 = __importDefault(require("chalk"));
const packages_list_1 = require("./packages-list");
class ServicesList extends react_1.Component {
    static _formatService(service) {
        const getStatus = () => {
            if (!service.enabled) {
                return '';
            }
            switch (service.status) {
                case service_status_1.ServiceStatus.CRASHED:
                    return chalk_1.default.bgRed('[Crashed]');
                case service_status_1.ServiceStatus.RUNNING:
                    return chalk_1.default.green(`[Running on :${service.port}]`);
                case service_status_1.ServiceStatus.STARTING:
                    return chalk_1.default.cyan(`[Starting on :${service.port}]`);
                case service_status_1.ServiceStatus.STOPPED:
                    return chalk_1.default.red('[Stopped]');
                case service_status_1.ServiceStatus.STOPPING:
                    return chalk_1.default.yellow('[Stopping]');
            }
        };
        return `${packages_list_1.PackagesList.getCompilationStatus(service)} ${getStatus()}`;
    }
    render() {
        return this.props.services
            ? this.props.services.map((service) => (react_1.default.createElement(ink_1.Box, { key: service.name, flexDirection: 'row', justifyContent: 'space-between' },
                react_1.default.createElement(ink_1.Text, { bold: true }, service.name === this.props.selected ? '->' : ''),
                react_1.default.createElement(ink_1.Text, { bold: false }, service.name),
                react_1.default.createElement(ink_1.Text, null,
                    " ",
                    ServicesList._formatService(service)))))
            : [react_1.default.createElement(ink_1.Text, { key: 'no-service' }, "No services")];
    }
}
exports.ServicesList = ServicesList;
//# sourceMappingURL=services-list.js.map