import { Component, ViewChild } from '@angular/core';
import { ApplicationService } from '@c8y/client';
import { C8yStepper, WizardComponent } from '@c8y/ngx-components';
import { BehaviorSubject } from 'rxjs';
import { EcosystemService } from '../ecosystem.service';
import * as i0 from "@angular/core";
import * as i1 from "../ecosystem.service";
import * as i2 from "@c8y/client";
import * as i3 from "@c8y/ngx-components";
import * as i4 from "@angular/common";
import * as i5 from "@angular/cdk/stepper";
import * as i6 from "./duplicate-application-list/duplicate-application-list.component";
import * as i7 from "./duplicate-application-properties/duplicate-application-properties.component";
export class DuplicateApplicationComponent {
    constructor(ecosystemService, applicationService, wizardComponent) {
        this.ecosystemService = ecosystemService;
        this.applicationService = applicationService;
        this.wizardComponent = wizardComponent;
        this.selectedApp = new BehaviorSubject(null);
        this.existingApps = [];
        this.directlyMoveToSecondStep = false;
        this.noBackButton = false;
    }
    async ngOnInit() {
        this.existingApps = await this.ecosystemService.getWebApplications();
        if (this.selectedApp.value) {
            this.directlyMoveToSecondStep = true;
        }
    }
    onSelectedApp(app) {
        this.selectedApp.next(app);
    }
    getHref(app) {
        return this.applicationService.getHref(app);
    }
    done() {
        this.wizardComponent.close();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DuplicateApplicationComponent, deps: [{ token: i1.EcosystemService }, { token: i2.ApplicationService }, { token: i3.WizardComponent }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: DuplicateApplicationComponent, selector: "c8y-duplicate-application", viewQueries: [{ propertyName: "stepper", first: true, predicate: C8yStepper, descendants: true, static: true }], ngImport: i0, template: "<c8y-wizard-header>\n  <i [c8yIcon]=\"'copy'\"></i>\n  <h4\n    id=\"modal-title\"\n    translate\n  >\n    Duplicate application\n  </h4>\n</c8y-wizard-header>\n\n<c8y-wizard-body id=\"modal-body\">\n  <c8y-stepper\n    [disableDefaultIcons]=\"{ edit: true, done: false }\"\n    [customClasses]=\"['hidden']\"\n    linear\n  >\n    <!-- 1st step -->\n    <cdk-step *ngIf=\"!directlyMoveToSecondStep\">\n      <p class=\"p-16 text-center text-medium separator-bottom sticky-top bg-level-0\">\n        {{ 'Select application to duplicate' | translate }}\n      </p>\n      <c8y-duplicate-application-list\n        class=\"d-block\"\n        style=\"min-height: 257px\"\n        (onSelectedApp)=\"onSelectedApp($event)\"\n        *ngIf=\"stepper.selectedIndex === 0\"\n        [existingApps]=\"existingApps\"\n        [stepper]=\"stepper\"\n      ></c8y-duplicate-application-list>\n    </cdk-step>\n    <!-- 2nd step -->\n    <cdk-step>\n      <c8y-duplicate-application-properties\n        class=\"d-flex d-col j-c-center a-i-center\"\n        style=\"min-height: 257px\"\n        (duplicatedApp)=\"duplicatedApp = $event\"\n        *ngIf=\"\n          stepper.selectedIndex === 1 || (stepper.selectedIndex === 0 && directlyMoveToSecondStep)\n        \"\n        [existingApps]=\"existingApps\"\n        [selectedApp]=\"selectedApp\"\n        [stepper]=\"stepper\"\n        [isFirstStep]=\"directlyMoveToSecondStep\"\n      ></c8y-duplicate-application-properties>\n    </cdk-step>\n    <!-- Final step -->\n    <cdk-step>\n      <ng-container\n        *ngIf=\"\n          stepper.selectedIndex === 2 || (stepper.selectedIndex === 1 && directlyMoveToSecondStep)\n        \"\n      >\n        <div\n          class=\"d-flex a-i-center j-c-center\"\n          style=\"min-height: 257px\"\n          *ngIf=\"duplicatedApp; else duplicateAppFailed\"\n        >\n          <c8y-operation-result\n            type=\"success\"\n            text=\"{{ 'Application created' | translate }}\"\n            [size]=\"84\"\n            [vertical]=\"true\"\n          ></c8y-operation-result>\n        </div>\n        <ng-template #duplicateAppFailed>\n          <div\n            class=\"d-flex a-i-center j-c-center\"\n            style=\"min-height: 257px\"\n          >\n            <c8y-operation-result\n              type=\"error\"\n              text=\"{{ 'Application creation failed' | translate }}\"\n              [size]=\"84\"\n              [vertical]=\"true\"\n            ></c8y-operation-result>\n          </div>\n        </ng-template>\n      </ng-container>\n    </cdk-step>\n  </c8y-stepper>\n</c8y-wizard-body>\n\n<c8y-wizard-footer *ngIf=\"stepper.selectedIndex === 0 && noBackButton\">\n  <button\n    class=\"btn btn-default\"\n    title=\"{{ 'Cancel' | translate }}\"\n    type=\"button\"\n    (click)=\"done()\"\n  >\n    {{ 'Cancel' | translate }}\n  </button>\n</c8y-wizard-footer>\n\n<c8y-wizard-footer\n  *ngIf=\"stepper.selectedIndex === 2 || (stepper.selectedIndex === 1 && directlyMoveToSecondStep)\"\n>\n  <button\n    class=\"btn btn-default\"\n    title=\"{{ 'Done' | translate }}\"\n    type=\"button\"\n    (click)=\"done()\"\n  >\n    {{ 'Done' | translate }}\n  </button>\n  <a\n    class=\"btn btn-primary\"\n    title=\"{{ 'Open' | translate }}\"\n    target=\"_blank\"\n    (click)=\"$event.stopPropagation()\"\n    [href]=\"getHref(duplicatedApp)\"\n    rel=\"noopener noreferrer\"\n  >\n    <i\n      class=\"m-r-4\"\n      c8yIcon=\"external-link\"\n    ></i>\n    {{ 'Open' | translate }}\n  </a>\n</c8y-wizard-footer>\n", dependencies: [{ kind: "directive", type: i3.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i3.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.OperationResultComponent, selector: "c8y-operation-result", inputs: ["text", "vertical", "size", "type"] }, { kind: "component", type: i3.C8yStepper, selector: "c8y-stepper", inputs: ["disableDefaultIcons", "disableProgressButtons", "customClasses", "hideStepProgress", "useStepLabelsAsTitlesOnly"], outputs: ["onStepChange"] }, { kind: "component", type: i5.CdkStep, selector: "cdk-step", inputs: ["stepControl", "label", "errorMessage", "aria-label", "aria-labelledby", "state", "editable", "optional", "completed", "hasError"], outputs: ["interacted"], exportAs: ["cdkStep"] }, { kind: "component", type: i3.WizardHeaderComponent, selector: "c8y-wizard-header" }, { kind: "component", type: i3.WizardBodyComponent, selector: "c8y-wizard-body" }, { kind: "component", type: i3.WizardFooterComponent, selector: "c8y-wizard-footer" }, { kind: "component", type: i6.DuplicateApplicationListComponent, selector: "c8y-duplicate-application-list", inputs: ["stepper", "existingApps"], outputs: ["onSelectedApp"] }, { kind: "component", type: i7.DuplicateApplicationPropertiesComponent, selector: "c8y-duplicate-application-properties", inputs: ["stepper", "existingApps", "selectedApp", "isFirstStep"], outputs: ["duplicatedApp"] }, { kind: "pipe", type: i3.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DuplicateApplicationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-duplicate-application', template: "<c8y-wizard-header>\n  <i [c8yIcon]=\"'copy'\"></i>\n  <h4\n    id=\"modal-title\"\n    translate\n  >\n    Duplicate application\n  </h4>\n</c8y-wizard-header>\n\n<c8y-wizard-body id=\"modal-body\">\n  <c8y-stepper\n    [disableDefaultIcons]=\"{ edit: true, done: false }\"\n    [customClasses]=\"['hidden']\"\n    linear\n  >\n    <!-- 1st step -->\n    <cdk-step *ngIf=\"!directlyMoveToSecondStep\">\n      <p class=\"p-16 text-center text-medium separator-bottom sticky-top bg-level-0\">\n        {{ 'Select application to duplicate' | translate }}\n      </p>\n      <c8y-duplicate-application-list\n        class=\"d-block\"\n        style=\"min-height: 257px\"\n        (onSelectedApp)=\"onSelectedApp($event)\"\n        *ngIf=\"stepper.selectedIndex === 0\"\n        [existingApps]=\"existingApps\"\n        [stepper]=\"stepper\"\n      ></c8y-duplicate-application-list>\n    </cdk-step>\n    <!-- 2nd step -->\n    <cdk-step>\n      <c8y-duplicate-application-properties\n        class=\"d-flex d-col j-c-center a-i-center\"\n        style=\"min-height: 257px\"\n        (duplicatedApp)=\"duplicatedApp = $event\"\n        *ngIf=\"\n          stepper.selectedIndex === 1 || (stepper.selectedIndex === 0 && directlyMoveToSecondStep)\n        \"\n        [existingApps]=\"existingApps\"\n        [selectedApp]=\"selectedApp\"\n        [stepper]=\"stepper\"\n        [isFirstStep]=\"directlyMoveToSecondStep\"\n      ></c8y-duplicate-application-properties>\n    </cdk-step>\n    <!-- Final step -->\n    <cdk-step>\n      <ng-container\n        *ngIf=\"\n          stepper.selectedIndex === 2 || (stepper.selectedIndex === 1 && directlyMoveToSecondStep)\n        \"\n      >\n        <div\n          class=\"d-flex a-i-center j-c-center\"\n          style=\"min-height: 257px\"\n          *ngIf=\"duplicatedApp; else duplicateAppFailed\"\n        >\n          <c8y-operation-result\n            type=\"success\"\n            text=\"{{ 'Application created' | translate }}\"\n            [size]=\"84\"\n            [vertical]=\"true\"\n          ></c8y-operation-result>\n        </div>\n        <ng-template #duplicateAppFailed>\n          <div\n            class=\"d-flex a-i-center j-c-center\"\n            style=\"min-height: 257px\"\n          >\n            <c8y-operation-result\n              type=\"error\"\n              text=\"{{ 'Application creation failed' | translate }}\"\n              [size]=\"84\"\n              [vertical]=\"true\"\n            ></c8y-operation-result>\n          </div>\n        </ng-template>\n      </ng-container>\n    </cdk-step>\n  </c8y-stepper>\n</c8y-wizard-body>\n\n<c8y-wizard-footer *ngIf=\"stepper.selectedIndex === 0 && noBackButton\">\n  <button\n    class=\"btn btn-default\"\n    title=\"{{ 'Cancel' | translate }}\"\n    type=\"button\"\n    (click)=\"done()\"\n  >\n    {{ 'Cancel' | translate }}\n  </button>\n</c8y-wizard-footer>\n\n<c8y-wizard-footer\n  *ngIf=\"stepper.selectedIndex === 2 || (stepper.selectedIndex === 1 && directlyMoveToSecondStep)\"\n>\n  <button\n    class=\"btn btn-default\"\n    title=\"{{ 'Done' | translate }}\"\n    type=\"button\"\n    (click)=\"done()\"\n  >\n    {{ 'Done' | translate }}\n  </button>\n  <a\n    class=\"btn btn-primary\"\n    title=\"{{ 'Open' | translate }}\"\n    target=\"_blank\"\n    (click)=\"$event.stopPropagation()\"\n    [href]=\"getHref(duplicatedApp)\"\n    rel=\"noopener noreferrer\"\n  >\n    <i\n      class=\"m-r-4\"\n      c8yIcon=\"external-link\"\n    ></i>\n    {{ 'Open' | translate }}\n  </a>\n</c8y-wizard-footer>\n" }]
        }], ctorParameters: () => [{ type: i1.EcosystemService }, { type: i2.ApplicationService }, { type: i3.WizardComponent }], propDecorators: { stepper: [{
                type: ViewChild,
                args: [C8yStepper, { static: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 