import { __decorate, __metadata } from "tslib";
import { Component, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { InventoryService } from '@c8y/client';
import { AlertService, GainsightService, gettext, memoize, ModalService, Status } from '@c8y/ngx-components';
import { PRODUCT_EXPERIENCE_REPOSITORY_SHARED, RepositoryService, SoftwareTypeComponent } from '@c8y/ngx-components/repository/shared';
import { TranslateService } from '@ngx-translate/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BehaviorSubject, from, merge, Subject } from 'rxjs';
import { distinctUntilKeyChanged, map, shareReplay, switchMap, take, takeUntil, tap, withLatestFrom } from 'rxjs/operators';
import { AddSoftwareModalComponent } from './add-software-modal.component';
import * as i0 from "@angular/core";
import * as i1 from "@angular/router";
import * as i2 from "@c8y/client";
import * as i3 from "@c8y/ngx-components/repository/shared";
import * as i4 from "@c8y/ngx-components";
import * as i5 from "@ngx-translate/core";
import * as i6 from "ngx-bootstrap/modal";
import * as i7 from "@angular/common";
import * as i8 from "@angular/forms";
import * as i9 from "ngx-bootstrap/popover";
import * as i10 from "ngx-bootstrap/tooltip";
export class SoftwareDetailsComponent {
    constructor(activatedRoute, inventoryService, repositoryService, alertService, translateService, modalService, bsModalService, gainsightService, router) {
        this.activatedRoute = activatedRoute;
        this.inventoryService = inventoryService;
        this.repositoryService = repositoryService;
        this.alertService = alertService;
        this.translateService = translateService;
        this.modalService = modalService;
        this.bsModalService = bsModalService;
        this.gainsightService = gainsightService;
        this.router = router;
        this.reload$ = new Subject();
        this.reloading$ = new BehaviorSubject(false);
        this.isSoftwareTypeChanged = false;
        this.updateSoftware$ = new Subject();
        this.softwareUpdated$ = new Subject();
        this.baseVersionsUpdated$ = new Subject();
        this.software$ = merge(this.activatedRoute.params.pipe(map(params => params.id), switchMap(id => from(this.inventoryService.detail(id).then(result => result.data)))), this.reload$.pipe(tap(() => this.reloading$.next(true)), switchMap(() => this.activatedRoute.params), map(params => params.id), switchMap(id => from(this.inventoryService.detail(id).then(result => result.data))), tap(() => this.reloading$.next(false))), this.softwareUpdated$).pipe(shareReplay(1));
        this.baseVersions$ = merge(this.software$.pipe(distinctUntilKeyChanged('id')), this.baseVersionsUpdated$, this.reload$).pipe(switchMap(() => this.software$), switchMap(software => this.repositoryService.listBaseVersions(software)), shareReplay(1));
        this.isLegacy$ = this.software$.pipe(map(software => this.repositoryService.isLegacyEntry(software)), shareReplay(1));
        this.destroy$ = new Subject();
    }
    ngOnInit() {
        this.updateSoftware$
            .pipe(withLatestFrom(this.software$), switchMap(([softwarePartial, software]) => this.inventoryService.update({
            id: software.id,
            ...softwarePartial
        })), map(({ data }) => data), tap(software => this.softwareUpdated$.next(software)), tap(() => this.alertService.success(gettext('Saved.'))), tap(() => this.gainsightService.triggerEvent(PRODUCT_EXPERIENCE_REPOSITORY_SHARED.SOFTWARE.EVENTS.REPOSITORY, {
            result: PRODUCT_EXPERIENCE_REPOSITORY_SHARED.SOFTWARE.RESULTS.EDIT_SOFTWARE
        })), takeUntil(this.destroy$))
            .subscribe();
        this.software$.subscribe(software => {
            this.softwareTypeObject = software;
        });
    }
    getBinaryName$(binaryUrl) {
        return this.repositoryService.getBinaryName$(binaryUrl);
    }
    addBaseVersion() {
        this.software$
            .pipe(take(1), switchMap(software => {
            const initialState = {
                model: {
                    selected: software,
                    description: software.description
                }
            };
            const config = {
                class: 'modal-sm',
                ariaDescribedby: 'addSoftwareModalDescription',
                ariaLabelledBy: 'addSoftwareModalTitle',
                ignoreBackdropClick: true,
                keyboard: false,
                initialState
            };
            const modalRef = this.bsModalService.show(AddSoftwareModalComponent, config);
            return modalRef.content.saved;
        }))
            .subscribe(() => this.baseVersionsUpdated$.next());
    }
    async deleteBaseVersion(baseVersion) {
        try {
            const title = gettext('Delete software');
            const body = `
        ${this.translateService.instant(gettext('You are about to delete software {{ version }}.'), { version: baseVersion.c8y_Software.version })}
        ${this.translateService.instant(gettext('This operation is irreversible.'))}
        ${this.translateService.instant(gettext('Do you want to proceed?'))}
      `;
            const labels = {
                ok: gettext('Delete')
            };
            await this.modalService.confirm(title, body, Status.DANGER, labels);
            const isLastVersion = await this.baseVersions$
                .pipe(map(versions => versions?.data?.length === 1), take(1))
                .toPromise();
            if (isLastVersion) {
                await this.repositoryService.delete(this.softwareTypeObject);
                this.router.navigateByUrl('/software');
            }
            else {
                await this.repositoryService.delete(baseVersion);
                this.baseVersionsUpdated$.next();
            }
            this.alertService.success(gettext('Software deleted.'));
        }
        catch (ex) {
            // only if not cancel from modal
            if (ex) {
                this.alertService.addServerFailure(ex);
            }
        }
    }
    onSelectSoftwareType(software) {
        this.isSoftwareTypeChanged = !(this.softwareTypeObject?.softwareType === software?.softwareType);
        this.softwareTypeObject = software;
    }
    ngOnDestroy() {
        this.destroy$.next(true);
        this.destroy$.unsubscribe();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SoftwareDetailsComponent, deps: [{ token: i1.ActivatedRoute }, { token: i2.InventoryService }, { token: i3.RepositoryService }, { token: i4.AlertService }, { token: i5.TranslateService }, { token: i4.ModalService }, { token: i6.BsModalService }, { token: i4.GainsightService }, { token: i1.Router }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: SoftwareDetailsComponent, selector: "c8y-software-details", viewQueries: [{ propertyName: "softwareType", first: true, predicate: SoftwareTypeComponent, descendants: true, static: true }], ngImport: i0, template: "<c8y-title>\n  {{ (software$ | async)?.name }}\n</c8y-title>\n\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    label=\"{{ 'Management' | translate }}\"\n    icon=\"c8y-management\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    path=\"#/software\"\n    label=\"{{ 'Software repository' | translate }}\"\n    icon=\"c8y-tools\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    label=\"{{ (software$ | async)?.name }}\"\n    icon=\"c8y-tools\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    type=\"button\"\n    title=\"{{ 'Add software' | translate }}\"\n    (click)=\"addBaseVersion()\"\n    *ngIf=\"!(isLegacy$ | async)\"\n  >\n    <i c8yIcon=\"plus-circle\"></i>\n    {{ 'Add software' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    type=\"button\"\n    title=\"{{ 'Reload' | translate }}\"\n    (click)=\"reload$.next()\"\n  >\n    <i\n      c8yIcon=\"refresh\"\n      [ngClass]=\"{ 'icon-spin': reloading$ | async }\"\n    ></i>\n    {{ 'Reload' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<div class=\"row\">\n  <div class=\"col-lg-12 col-lg-max\">\n    <div class=\"card card--fullpage\">\n      <div class=\"card-block bg-level-1 flex-no-shrink p-t-24 p-b-24 overflow-visible\">\n        <div class=\"content-flex-70\">\n          <div class=\"text-center\">\n            <i class=\"c8y-icon-duocolor icon-48 c8y-icon c8y-icon-tools\"></i>\n            <p>\n              <small class=\"label label-info\">Software</small>\n            </p>\n          </div>\n          <div class=\"flex-grow col-10\">\n            <div class=\"row\">\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Name' | translate }}\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <input\n                      #nameInput\n                      type=\"text\"\n                      class=\"form-control\"\n                      [ngModel]=\"(software$ | async)?.name\"\n                      #nameModel=\"ngModel\"\n                      placeholder=\"{{ 'e.g. My software' | translate }}\"\n                      [ngStyle]=\"{ 'width.ch': (software$ | async)?.name?.length + 2 || 31 }\"\n                      required\n                    />\n                    <span></span>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        (click)=\"updateSoftware$.next({ name: nameInput.value }); nameModel.reset()\"\n                        [disabled]=\"nameInput.value.length === 0\"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Description' | translate }}\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <input\n                      #descriptionInput\n                      type=\"text\"\n                      class=\"form-control\"\n                      [ngModel]=\"(software$ | async)?.description\"\n                      #descriptionModel=\"ngModel\"\n                      placeholder=\"{{ 'e.g. Cloud connectivity software' | translate }}\"\n                      [ngStyle]=\"{ 'width.ch': (software$ | async)?.description?.length + 2 || 31 }\"\n                    />\n                    <span></span>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        (click)=\"\n                          updateSoftware$.next({ description: descriptionInput.value });\n                          descriptionModel.reset()\n                        \"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n            </div>\n            <div class=\"row\">\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Device type' | translate }}\n                    <button\n                      class=\"btn-help\"\n                      type=\"button\"\n                      [attr.aria-label]=\"'Help' | translate\"\n                      popover=\"{{\n                        'If the filter is set, the software will show up for installation only for devices of that type. If no filter is set, it will be available for all devices.'\n                          | translate\n                      }}\"\n                      triggers=\"focus\"\n                      container=\"body\"\n                    >\n                      <i c8yIcon=\"question-circle-o\"></i>\n                    </button>\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <input\n                      #deviceTypeInput\n                      type=\"text\"\n                      class=\"form-control\"\n                      [ngModel]=\"(software$ | async)?.c8y_Filter?.type\"\n                      #deviceTypeModel=\"ngModel\"\n                      placeholder=\"{{ 'e.g.' | translate }} c8y_Linux\"\n                      [ngStyle]=\"{ 'width.ch': (software$ | async)?.type?.length + 2 || 31 }\"\n                    />\n                    <span></span>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        (click)=\"\n                          updateSoftware$.next({ c8y_Filter: { type: deviceTypeInput.value } });\n                          deviceTypeModel.reset()\n                        \"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Software type' | translate }}\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <c8y-software-type\n                      [softwareTypeMO]=\"softwareTypeObject\"\n                      [style]=\"{ 'width.ch': softwareTypeObject?.softwareType?.length + 2 || 31 }\"\n                      (onSelectSoftware)=\"onSelectSoftwareType($event)\"\n                    ></c8y-software-type>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        [ngClass]=\"isSoftwareTypeChanged ? '' : 'hidden'\"\n                        [disabled]=\"softwareTypeObject?.softwareType === ''\"\n                        (click)=\"\n                          updateSoftware$.next({ softwareType: softwareTypeObject.softwareType });\n                          softwareType.resetInput();\n                          isSoftwareTypeChanged = false\n                        \"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n            </div>\n          </div>\n        </div>\n      </div>\n      <div class=\"inner-scroll\">\n        <div class=\"card-header separator-top-bottom sticky-top bg-component\">\n          <div\n            class=\"card-title\"\n            translate\n          >\n            Versions\n          </div>\n        </div>\n\n        <div class=\"card-block p-t-0 p-b-24\">\n          <c8y-ui-empty-state\n            *ngIf=\"(baseVersions$ | async)?.data.length === 0\"\n            [icon]=\"'c8y-tools'\"\n            [title]=\"'No versions to display.' | translate\"\n            [subtitle]=\"'Add a new version by clicking below.' | translate\"\n          >\n            <p>\n              <button\n                class=\"btn btn-primary\"\n                type=\"button\"\n                title=\"{{ 'Add software' | translate }}\"\n                (click)=\"addBaseVersion()\"\n              >\n                {{ 'Add software' | translate }}\n              </button>\n            </p>\n          </c8y-ui-empty-state>\n\n          <c8y-list-group *ngIf=\"(baseVersions$ | async)?.data.length > 0\">\n            <c8y-li\n              *c8yFor=\"let baseVersion of baseVersions$ | async; let i = index; loadMore: 'auto'\"\n            >\n              <c8y-li-icon>\n                <i c8yIcon=\"c8y-tools\"></i>\n              </c8y-li-icon>\n\n              <c8y-li-body class=\"content-flex-50\">\n                <div class=\"col-4\">\n                  <p\n                    class=\"text-truncate-wrap\"\n                    title=\"{{ baseVersion.c8y_Software.version }}\"\n                  >\n                    {{ baseVersion.c8y_Software.version }}\n                  </p>\n                </div>\n                <div class=\"col-5\">\n                  <p class=\"text-truncate-wrap\">\n                    <span\n                      class=\"text-label-small m-r-8\"\n                      translate\n                    >\n                      File\n                    </span>\n                    <span title=\" {{ getBinaryName$(baseVersion.c8y_Software.url) | async }}\">\n                      <c8y-file-download\n                        url=\"{{ baseVersion.c8y_Software.url }}\"\n                      ></c8y-file-download>\n                    </span>\n                  </p>\n                </div>\n                <div class=\"col-2 d-flex a-i-start\">\n                  <span\n                    *ngIf=\"isLegacy$ | async\"\n                    class=\"label label-warning m-l-auto-sm\"\n                  >\n                    {{ 'Legacy' | translate }}\n                  </span>\n\n                  <div\n                    class=\"fit-h-20\"\n                    *ngIf=\"!(isLegacy$ | async)\"\n                  >\n                    <button\n                      class=\"btn btn-danger btn-xs visible-xs m-l-auto m-r-8 m-t-8\"\n                      type=\"button\"\n                      title=\"{{ 'Delete' | translate }}\"\n                      (click)=\"deleteBaseVersion(baseVersion)\"\n                    >\n                      <i c8yIcon=\"delete\"></i>\n                      {{ 'Delete' | translate }}\n                    </button>\n                  </div>\n                </div>\n                <div\n                  *ngIf=\"!(isLegacy$ | async)\"\n                  class=\"m-l-auto fit-h-20 hidden-xs\"\n                >\n                  <button\n                    class=\"btn btn-dot text-danger showOnHover\"\n                    type=\"button\"\n                    data-cy=\"software-details-component--Delete-button\"\n                    [attr.aria-label]=\"'Delete' | translate\"\n                    tooltip=\"{{ 'Delete' | translate }}\"\n                    [delay]=\"500\"\n                    (click)=\"deleteBaseVersion(baseVersion)\"\n                  >\n                    <i c8yIcon=\"delete\"></i>\n                  </button>\n                </div>\n              </c8y-li-body>\n            </c8y-li>\n          </c8y-list-group>\n        </div>\n      </div>\n    </div>\n  </div>\n</div>\n", dependencies: [{ kind: "directive", type: i7.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i7.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i7.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: i4.ActionBarItemComponent, selector: "c8y-action-bar-item", inputs: ["placement", "priority", "itemClass", "injector", "groupId", "inGroupPriority"] }, { kind: "component", type: i4.BreadcrumbComponent, selector: "c8y-breadcrumb" }, { kind: "component", type: i4.BreadcrumbItemComponent, selector: "c8y-breadcrumb-item", inputs: ["icon", "translate", "label", "path", "injector"] }, { kind: "component", type: i4.EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "directive", type: i4.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i4.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i4.ForOfDirective, selector: "[c8yFor]", inputs: ["c8yForOf", "c8yForLoadMore", "c8yForPipe", "c8yForNotFound", "c8yForMaxIterations", "c8yForLoadingTemplate", "c8yForLoadNextLabel", "c8yForLoadingLabel", "c8yForRealtime", "c8yForRealtimeOptions", "c8yForComparator", "c8yForEnableVirtualScroll", "c8yForVirtualScrollElementSize", "c8yForVirtualScrollStrategy", "c8yForVirtualScrollContainerHeight"], outputs: ["c8yForCount", "c8yForChange", "c8yForLoadMoreComponent"] }, { kind: "component", type: i4.TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "directive", type: i8.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i8.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i8.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i8.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i4.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "directive", type: i4.RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { kind: "component", type: i4.ListGroupComponent, selector: "c8y-list-group" }, { kind: "component", type: i4.ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "component", type: i4.ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "component", type: i4.ListItemBodyComponent, selector: "c8y-list-item-body, c8y-li-body", inputs: ["body"] }, { kind: "directive", type: i9.PopoverDirective, selector: "[popover]", inputs: ["adaptivePosition", "boundariesElement", "popover", "popoverContext", "popoverTitle", "placement", "outsideClick", "triggers", "container", "containerClass", "isOpen", "delay"], outputs: ["onShown", "onHidden"], exportAs: ["bs-popover"] }, { kind: "directive", type: i10.TooltipDirective, selector: "[tooltip], [tooltipHtml]", inputs: ["adaptivePosition", "tooltip", "placement", "triggers", "container", "containerClass", "boundariesElement", "isOpen", "isDisabled", "delay", "tooltipHtml", "tooltipPlacement", "tooltipIsOpen", "tooltipEnable", "tooltipAppendToBody", "tooltipAnimation", "tooltipClass", "tooltipContext", "tooltipPopupDelay", "tooltipFadeDuration", "tooltipTrigger"], outputs: ["tooltipChange", "onShown", "onHidden", "tooltipStateChanged"], exportAs: ["bs-tooltip"] }, { kind: "component", type: i3.FileDownloadComponent, selector: "c8y-file-download", inputs: ["url"] }, { kind: "component", type: i3.SoftwareTypeComponent, selector: "c8y-software-type", inputs: ["softwareTypeMO", "disabled", "style", "required", "placeholder", "emitResultsOnly", "showBtnInNotFoundMessage", "allowFreeEntries", "showClearSelectionOption", "clearSelectionOptionLabel", "presetSoftwareTypes"], outputs: ["onSelectSoftware"] }, { kind: "pipe", type: i7.AsyncPipe, name: "async" }, { kind: "pipe", type: i4.C8yTranslatePipe, name: "translate" }] }); }
}
__decorate([
    memoize(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], SoftwareDetailsComponent.prototype, "getBinaryName$", null);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SoftwareDetailsComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-software-details', template: "<c8y-title>\n  {{ (software$ | async)?.name }}\n</c8y-title>\n\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    label=\"{{ 'Management' | translate }}\"\n    icon=\"c8y-management\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    path=\"#/software\"\n    label=\"{{ 'Software repository' | translate }}\"\n    icon=\"c8y-tools\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    label=\"{{ (software$ | async)?.name }}\"\n    icon=\"c8y-tools\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    type=\"button\"\n    title=\"{{ 'Add software' | translate }}\"\n    (click)=\"addBaseVersion()\"\n    *ngIf=\"!(isLegacy$ | async)\"\n  >\n    <i c8yIcon=\"plus-circle\"></i>\n    {{ 'Add software' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    type=\"button\"\n    title=\"{{ 'Reload' | translate }}\"\n    (click)=\"reload$.next()\"\n  >\n    <i\n      c8yIcon=\"refresh\"\n      [ngClass]=\"{ 'icon-spin': reloading$ | async }\"\n    ></i>\n    {{ 'Reload' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<div class=\"row\">\n  <div class=\"col-lg-12 col-lg-max\">\n    <div class=\"card card--fullpage\">\n      <div class=\"card-block bg-level-1 flex-no-shrink p-t-24 p-b-24 overflow-visible\">\n        <div class=\"content-flex-70\">\n          <div class=\"text-center\">\n            <i class=\"c8y-icon-duocolor icon-48 c8y-icon c8y-icon-tools\"></i>\n            <p>\n              <small class=\"label label-info\">Software</small>\n            </p>\n          </div>\n          <div class=\"flex-grow col-10\">\n            <div class=\"row\">\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Name' | translate }}\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <input\n                      #nameInput\n                      type=\"text\"\n                      class=\"form-control\"\n                      [ngModel]=\"(software$ | async)?.name\"\n                      #nameModel=\"ngModel\"\n                      placeholder=\"{{ 'e.g. My software' | translate }}\"\n                      [ngStyle]=\"{ 'width.ch': (software$ | async)?.name?.length + 2 || 31 }\"\n                      required\n                    />\n                    <span></span>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        (click)=\"updateSoftware$.next({ name: nameInput.value }); nameModel.reset()\"\n                        [disabled]=\"nameInput.value.length === 0\"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Description' | translate }}\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <input\n                      #descriptionInput\n                      type=\"text\"\n                      class=\"form-control\"\n                      [ngModel]=\"(software$ | async)?.description\"\n                      #descriptionModel=\"ngModel\"\n                      placeholder=\"{{ 'e.g. Cloud connectivity software' | translate }}\"\n                      [ngStyle]=\"{ 'width.ch': (software$ | async)?.description?.length + 2 || 31 }\"\n                    />\n                    <span></span>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        (click)=\"\n                          updateSoftware$.next({ description: descriptionInput.value });\n                          descriptionModel.reset()\n                        \"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n            </div>\n            <div class=\"row\">\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Device type' | translate }}\n                    <button\n                      class=\"btn-help\"\n                      type=\"button\"\n                      [attr.aria-label]=\"'Help' | translate\"\n                      popover=\"{{\n                        'If the filter is set, the software will show up for installation only for devices of that type. If no filter is set, it will be available for all devices.'\n                          | translate\n                      }}\"\n                      triggers=\"focus\"\n                      container=\"body\"\n                    >\n                      <i c8yIcon=\"question-circle-o\"></i>\n                    </button>\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <input\n                      #deviceTypeInput\n                      type=\"text\"\n                      class=\"form-control\"\n                      [ngModel]=\"(software$ | async)?.c8y_Filter?.type\"\n                      #deviceTypeModel=\"ngModel\"\n                      placeholder=\"{{ 'e.g.' | translate }} c8y_Linux\"\n                      [ngStyle]=\"{ 'width.ch': (software$ | async)?.type?.length + 2 || 31 }\"\n                    />\n                    <span></span>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        (click)=\"\n                          updateSoftware$.next({ c8y_Filter: { type: deviceTypeInput.value } });\n                          deviceTypeModel.reset()\n                        \"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n              <div class=\"col-sm-6\">\n                <c8y-form-group>\n                  <label class=\"control-label\">\n                    {{ 'Software type' | translate }}\n                  </label>\n                  <div class=\"input-group input-group-editable\">\n                    <c8y-software-type\n                      [softwareTypeMO]=\"softwareTypeObject\"\n                      [style]=\"{ 'width.ch': softwareTypeObject?.softwareType?.length + 2 || 31 }\"\n                      (onSelectSoftware)=\"onSelectSoftwareType($event)\"\n                    ></c8y-software-type>\n                    <div class=\"input-group-btn\">\n                      <button\n                        class=\"btn btn-primary\"\n                        type=\"button\"\n                        title=\"{{ 'Save' | translate }}\"\n                        [ngClass]=\"isSoftwareTypeChanged ? '' : 'hidden'\"\n                        [disabled]=\"softwareTypeObject?.softwareType === ''\"\n                        (click)=\"\n                          updateSoftware$.next({ softwareType: softwareTypeObject.softwareType });\n                          softwareType.resetInput();\n                          isSoftwareTypeChanged = false\n                        \"\n                      >\n                        {{ 'Save' | translate }}\n                      </button>\n                    </div>\n                  </div>\n                </c8y-form-group>\n              </div>\n            </div>\n          </div>\n        </div>\n      </div>\n      <div class=\"inner-scroll\">\n        <div class=\"card-header separator-top-bottom sticky-top bg-component\">\n          <div\n            class=\"card-title\"\n            translate\n          >\n            Versions\n          </div>\n        </div>\n\n        <div class=\"card-block p-t-0 p-b-24\">\n          <c8y-ui-empty-state\n            *ngIf=\"(baseVersions$ | async)?.data.length === 0\"\n            [icon]=\"'c8y-tools'\"\n            [title]=\"'No versions to display.' | translate\"\n            [subtitle]=\"'Add a new version by clicking below.' | translate\"\n          >\n            <p>\n              <button\n                class=\"btn btn-primary\"\n                type=\"button\"\n                title=\"{{ 'Add software' | translate }}\"\n                (click)=\"addBaseVersion()\"\n              >\n                {{ 'Add software' | translate }}\n              </button>\n            </p>\n          </c8y-ui-empty-state>\n\n          <c8y-list-group *ngIf=\"(baseVersions$ | async)?.data.length > 0\">\n            <c8y-li\n              *c8yFor=\"let baseVersion of baseVersions$ | async; let i = index; loadMore: 'auto'\"\n            >\n              <c8y-li-icon>\n                <i c8yIcon=\"c8y-tools\"></i>\n              </c8y-li-icon>\n\n              <c8y-li-body class=\"content-flex-50\">\n                <div class=\"col-4\">\n                  <p\n                    class=\"text-truncate-wrap\"\n                    title=\"{{ baseVersion.c8y_Software.version }}\"\n                  >\n                    {{ baseVersion.c8y_Software.version }}\n                  </p>\n                </div>\n                <div class=\"col-5\">\n                  <p class=\"text-truncate-wrap\">\n                    <span\n                      class=\"text-label-small m-r-8\"\n                      translate\n                    >\n                      File\n                    </span>\n                    <span title=\" {{ getBinaryName$(baseVersion.c8y_Software.url) | async }}\">\n                      <c8y-file-download\n                        url=\"{{ baseVersion.c8y_Software.url }}\"\n                      ></c8y-file-download>\n                    </span>\n                  </p>\n                </div>\n                <div class=\"col-2 d-flex a-i-start\">\n                  <span\n                    *ngIf=\"isLegacy$ | async\"\n                    class=\"label label-warning m-l-auto-sm\"\n                  >\n                    {{ 'Legacy' | translate }}\n                  </span>\n\n                  <div\n                    class=\"fit-h-20\"\n                    *ngIf=\"!(isLegacy$ | async)\"\n                  >\n                    <button\n                      class=\"btn btn-danger btn-xs visible-xs m-l-auto m-r-8 m-t-8\"\n                      type=\"button\"\n                      title=\"{{ 'Delete' | translate }}\"\n                      (click)=\"deleteBaseVersion(baseVersion)\"\n                    >\n                      <i c8yIcon=\"delete\"></i>\n                      {{ 'Delete' | translate }}\n                    </button>\n                  </div>\n                </div>\n                <div\n                  *ngIf=\"!(isLegacy$ | async)\"\n                  class=\"m-l-auto fit-h-20 hidden-xs\"\n                >\n                  <button\n                    class=\"btn btn-dot text-danger showOnHover\"\n                    type=\"button\"\n                    data-cy=\"software-details-component--Delete-button\"\n                    [attr.aria-label]=\"'Delete' | translate\"\n                    tooltip=\"{{ 'Delete' | translate }}\"\n                    [delay]=\"500\"\n                    (click)=\"deleteBaseVersion(baseVersion)\"\n                  >\n                    <i c8yIcon=\"delete\"></i>\n                  </button>\n                </div>\n              </c8y-li-body>\n            </c8y-li>\n          </c8y-list-group>\n        </div>\n      </div>\n    </div>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.ActivatedRoute }, { type: i2.InventoryService }, { type: i3.RepositoryService }, { type: i4.AlertService }, { type: i5.TranslateService }, { type: i4.ModalService }, { type: i6.BsModalService }, { type: i4.GainsightService }, { type: i1.Router }], propDecorators: { softwareType: [{
                type: ViewChild,
                args: [SoftwareTypeComponent, { static: true }]
            }], getBinaryName$: [] } });
//# sourceMappingURL=data:application/json;base64, 