"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_base_enterprise_1 = require("../command-base-enterprise");
const open = require("open");
const operators_1 = require("rxjs/operators");
class Portal extends command_base_enterprise_1.CommandBaseEnterprise {
    run() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
                try {
                    this.bootstrap();
                    const { args, flags } = yield this.parse(Portal);
                    const portalUrl = 'https://app.codiac.io/#/public/login';
                    // const relayContainer = new RelayContainer(this._styler, this.logger, undefined, undefined, this._projectRoot
                    //     , /* TEMP HACK!! --> update this class... */(<any>this.localConfig)?.localEntities ?? this._cliCfg?.localEntities);
                    // relayContainer.userMessages
                    //     .pipe(distinctUntilChanged())
                    //     .pipe(map(msg => {
                    //         if (msg) {
                    //             this._ui.userMessage(`${this._styler.colorGood(msg)}`);
                    //         }
                    //     }))
                    //     .subscribe();
                    this._relayContainer.ready$.pipe((0, operators_1.take)(1))
                        .pipe((0, operators_1.map)(_ => open(portalUrl, {})))
                        .subscribe();
                    resolve();
                }
                catch (err) {
                    reject(err);
                }
                finally {
                    yield this.closeConnections();
                }
            }));
        });
    }
    failed() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.logger.detail(`Codiac Relay Service died.`);
            // depricated for docker restart cmd instead
            // this._relayContainer = new RelayContainer(this._styler, this.logger);
        });
    }
}
exports.default = Portal;
Portal.description = 'Starts the codiac relay services, maintains container instance, and opens the web app.';
Portal.flags = {};
Portal.args = {};
//# sourceMappingURL=portal.js.map