"use strict";
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.ListItemRenderer = void 0;
var React = require("react");
var inversify_1 = require("inversify");
var window_service_1 = require("@theia/core/lib/browser/window/window-service");
var ListItemRenderer = /** @class */ (function () {
    function ListItemRenderer() {
        var _this = this;
        this.onMoreInfoClick = function (event) {
            var target = event.nativeEvent.target;
            if (target instanceof HTMLAnchorElement) {
                _this.windowService.openNewWindow(target.href, { external: true });
                event.nativeEvent.preventDefault();
            }
        };
    }
    ListItemRenderer.prototype.renderItem = function (input, install, uninstall, onVersionChange) {
        var item = input.item;
        var nameAndAuthor;
        if (item.name && item.author) {
            var name_1 = React.createElement("span", { className: 'name' }, item.name);
            var author = React.createElement("span", { className: 'author' }, item.author);
            nameAndAuthor = React.createElement("span", null,
                name_1,
                " by ",
                author);
        }
        else if (item.name) {
            nameAndAuthor = React.createElement("span", { className: 'name' }, item.name);
        }
        else if (item.id) {
            nameAndAuthor = React.createElement("span", { className: 'name' }, item.id);
        }
        else {
            nameAndAuthor = React.createElement("span", { className: 'name' }, "Unknown");
        }
        var onClickUninstall = function () { return uninstall(item); };
        var installedVersion = !!item.installedVersion && React.createElement("div", { className: 'version-info' },
            React.createElement("span", { className: 'version' },
                "Version ",
                item.installedVersion),
            React.createElement("span", { className: 'installed', onClick: onClickUninstall }));
        var summary = React.createElement("div", { className: 'summary' }, item.summary);
        var description = React.createElement("div", { className: 'summary' }, item.description);
        var moreInfo = !!item.moreInfoLink && React.createElement("a", { href: item.moreInfoLink, onClick: this.onMoreInfoClick }, "More info");
        var onClickInstall = function () { return install(item); };
        var installButton = item.installable &&
            React.createElement("button", { className: 'theia-button install', onClick: onClickInstall }, "INSTALL");
        var onSelectChange = function (event) {
            var version = event.target.value;
            if (version) {
                onVersionChange(version);
            }
        };
        var versions = (function () {
            var availableVersions = item.availableVersions;
            if (availableVersions.length === 0) {
                return undefined;
            }
            else if (availableVersions.length === 1) {
                return React.createElement("label", null, availableVersions[0]);
            }
            else {
                return React.createElement("select", { className: 'theia-select', value: input.selectedVersion, onChange: onSelectChange }, item.availableVersions
                    .filter(function (version) { return version !== item.installedVersion; }) // Filter the version that is currently installed.
                    .map(function (version) { return React.createElement("option", { value: version, key: version }, version); }));
            }
        })();
        return React.createElement("div", { className: 'component-list-item noselect' },
            React.createElement("div", { className: 'header' },
                nameAndAuthor,
                installedVersion),
            React.createElement("div", { className: 'content' },
                summary,
                description),
            React.createElement("div", { className: 'info' }, moreInfo),
            React.createElement("div", { className: 'footer' },
                installButton,
                versions));
    };
    __decorate([
        inversify_1.inject(window_service_1.WindowService),
        __metadata("design:type", Object)
    ], ListItemRenderer.prototype, "windowService", void 0);
    ListItemRenderer = __decorate([
        inversify_1.injectable()
    ], ListItemRenderer);
    return ListItemRenderer;
}());
exports.ListItemRenderer = ListItemRenderer;
//# sourceMappingURL=list-item-renderer.js.map