"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseResmon = void 0;
var inversify_1 = require("inversify");
var widget_1 = require("@theia/core/lib/browser/widgets/widget");
var BaseResmon = /** @class */ (function (_super) {
    __extends(BaseResmon, _super);
    function BaseResmon() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.rowDefs = [];
        _this.initialized = false;
        return _this;
    }
    BaseResmon.prototype.init = function () {
        this.setup();
        this.addClass('fxdk-resmon-widget');
        this.scrollOptions = {};
    };
    BaseResmon.prototype.renderRows = function (rows) {
        var _this = this;
        if (!this.initialized) {
            return;
        }
        if (this.tbodyNode) {
            this.tbodyNode.innerHTML = rows.map(function (row) {
                return "<tr>" + row.map(function (cell, i) { return _this.renderCell(i, cell); }).join('') + "</tr>";
            }).join('');
        }
    };
    BaseResmon.prototype.renderCell = function (i, cell) {
        var _a;
        var formatted = this.formatCell(i, cell);
        var align = ((_a = this.rowDefs[i]) === null || _a === void 0 ? void 0 : _a.align) || 'center';
        return "<td class=\"align-" + align + "\">" + formatted + "</td>";
    };
    BaseResmon.prototype.formatCell = function (i, cell) {
        var _a;
        var formatter = (_a = this.rowDefs[i]) === null || _a === void 0 ? void 0 : _a.format;
        if (formatter) {
            return formatter(cell);
        }
        return cell;
    };
    BaseResmon.prototype.onActivateRequest = function (msg) {
        _super.prototype.onActivateRequest.call(this, msg);
        this.node.focus();
    };
    BaseResmon.prototype.onAfterShow = function (msg) {
        _super.prototype.onAfterShow.call(this, msg);
        this.update();
    };
    BaseResmon.prototype.onAfterAttach = function (msg) {
        _super.prototype.onAfterAttach.call(this, msg);
        this.update();
    };
    BaseResmon.prototype.onBeforeDetach = function (msg) {
        _super.prototype.onBeforeDetach.call(this, msg);
    };
    BaseResmon.prototype.onResize = function (msg) {
        _super.prototype.onResize.call(this, msg);
        this.update();
        this.updateScroll();
    };
    BaseResmon.prototype.onUpdateRequest = function (msg) {
        var _this = this;
        _super.prototype.onUpdateRequest.call(this, msg);
        if (!this.isVisible || !this.isAttached) {
            return;
        }
        if (!this.initialized) {
            this.initialized = true;
            this.node.innerHTML = "\n        <table cellpadding=0 cellspacing=0>\n          <thead>\n            " + this.rowDefs.map(function (_, i) { return _this.renderHeader(i); }).join('') + "\n          </thead>\n          <tbody>\n          </tbody>\n        </table>\n      ";
            this.tbodyNode = this.node.querySelector('tbody');
            this.initializeResmon();
        }
        this.updateScroll();
    };
    BaseResmon.prototype.renderHeader = function (i) {
        var _a = this.rowDefs[i], title = _a.title, _b = _a.align, align = _b === void 0 ? 'center' : _b;
        return "<th class=\"align-" + align + "\">" + title + "</th>";
    };
    BaseResmon.prototype.updateScroll = function () {
        var _a;
        (_a = this.scrollBar) === null || _a === void 0 ? void 0 : _a.update();
    };
    __decorate([
        inversify_1.postConstruct(),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], BaseResmon.prototype, "init", null);
    BaseResmon = __decorate([
        inversify_1.injectable()
    ], BaseResmon);
    return BaseResmon;
}(widget_1.BaseWidget));
exports.BaseResmon = BaseResmon;
//# sourceMappingURL=base-resmon.js.map