import { CdkStep } from '@angular/cdk/stepper';
import { Component } from '@angular/core';
import { C8yStepper } from '../stepper/stepper.component';
import { SetupComponent } from './setup.component';
import { gettext } from '../i18n/gettext';
import * as i0 from "@angular/core";
import * as i1 from "../stepper/stepper.component";
import * as i2 from "@angular/cdk/stepper";
import * as i3 from "./setup.component";
import * as i4 from "../common/icon.directive";
import * as i5 from "../i18n/c8y-translate.directive";
import * as i6 from "@angular/common";
import * as i7 from "../common/operation-result.component";
import * as i8 from "../i18n/c8y-translate.pipe";
export class SetupCompletedComponent {
    constructor(stepper, step, setup) {
        this.stepper = stepper;
        this.step = step;
        this.setup = setup;
        this.status = 'done';
        this.STEP_LABEL = gettext('Step');
        this.isVerified = false;
    }
    ngOnInit() {
        this.stepperSelectionChangeSubscription = this.stepper.selectionChange.subscribe(({ selectedIndex }) => {
            this.verify(selectedIndex);
        });
    }
    ngOnDestroy() {
        this.stepperSelectionChangeSubscription.unsubscribe();
    }
    verify(selectedIndex) {
        const isLastStep = this.stepper.steps.length - 1 === selectedIndex;
        if (isLastStep || this.isVerified) {
            // set the last step to completed
            this.getOverallStatus();
            this.setup.verify();
            this.isVerified = true;
        }
    }
    start() {
        this.setup.finish();
    }
    back() {
        this.stepper.previous();
    }
    gotoStep(index) {
        this.stepper.selectedIndex = index;
    }
    getOverallStatus() {
        const validSteps = this.setup.steps.slice(0, this.setup.steps.length - 1);
        this.status = 'done';
        if (validSteps.find(step => !step.completed && step.required)) {
            this.status = 'error';
        }
        else if (validSteps.find(step => !step.completed && !step.required)) {
            this.status = 'warning';
        }
        this.step.state = this.status;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: SetupCompletedComponent, deps: [{ token: i1.C8yStepper }, { token: i2.CdkStep }, { token: i3.SetupComponent }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: SetupCompletedComponent, selector: "c8y-setup-completed", host: { classAttribute: "d-contents" }, ngImport: i0, template: "<div class=\"container-fluid flex-no-shrink fit-w\">\n  <div class=\"row separator-bottom\">\n    <div class=\"col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3 p-t-24 p-l-16 p-r-16\">\n      <h3 translate class=\"text-medium l-h-base\" data-cy=\"c8y-setup--completed-header-title\">Summary</h3>\n      <p translate class=\"lead text-normal p-t-8 p-b-8\">\n        Verify the setup result. If any step is not finished but required, you need to ensure that\n        you have finished the step.\n      </p>\n    </div>\n  </div>\n</div>\n<div class=\"inner-scroll flex-grow\">\n  <div class=\"container-fluid fit-w p-t-16\">\n    <div class=\"row\">\n      <div class=\"col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3\">\n        <div class=\"text-center\" [ngSwitch]=\"status\">\n          <c8y-operation-result\n            *ngSwitchCase=\"'done'\"\n            text=\"{{ 'Setup completed' | translate }}\"\n            [size]=\"120\"\n            [vertical]=\"true\"\n            type=\"success\"\n          ></c8y-operation-result>\n          <c8y-operation-result\n            *ngSwitchCase=\"'warning'\"\n            text=\"{{ 'Setup completed with warnings' | translate }}\"\n            [size]=\"120\"\n            [vertical]=\"true\"\n            type=\"warning\"\n          ></c8y-operation-result>\n          <c8y-operation-result\n            *ngSwitchCase=\"'error'\"\n            text=\"{{ 'Setup not completed' | translate }}\"\n            [size]=\"120\"\n            [vertical]=\"true\"\n            type=\"error\"\n          ></c8y-operation-result>\n        </div>\n        <ul class=\"list-unstyled m-t-16 separator-top\">\n          <li\n            class=\"p-t-4 p-b-4 d-flex a-i-center separator-bottom text-nowrap l-h-1\"\n            *ngFor=\"let step of setup.steps.slice(0, setup.steps.length - 1)\"\n            (click)=\"gotoStep(step.index)\"\n            style=\"cursor: pointer\"\n          >\n            <span *ngIf=\"step.label\">\n              <span\n                class=\"dot small m-r-4 l-h-1\"\n                [ngClass]=\"{\n                  'dot-success': step.completed,\n                  'dot-error': !step.completed && step.required,\n                  'dot-warning': !step.completed && !step.required\n                }\"\n              >\n                {{ step.index + 1 }}\n              </span>\n              {{ step.label || (STEP_LABEL | translate) + ' ' }}\n            </span>\n            <span *ngIf=\"!step.label\">\n              <span translate>Step</span>\n              {{ ' ' + (step.index + 1) }}\n            </span>\n            <span class=\"m-l-auto icon-20 l-h-1\">\n              <i\n                *ngIf=\"step.completed\"\n                [c8yIcon]=\"'success'\"\n                class=\"text-success\"\n                [title]=\"'Completed' | translate\"\n              ></i>\n              <i\n                *ngIf=\"!step.completed && step.required\"\n                [c8yIcon]=\"'error'\"\n                class=\"text-danger\"\n                [title]=\"\n                  'Not completed and required. Go to the step and fulfill the setup.' | translate\n                \"\n              ></i>\n              <i\n                *ngIf=\"!step.completed && !step.required\"\n                [c8yIcon]=\"'warning'\"\n                class=\"text-warning\"\n                [title]=\"'This step was not completed but it is also not required.' | translate\"\n              ></i>\n            </span>\n          </li>\n        </ul>\n      </div>\n    </div>\n  </div>\n</div>\n<div class=\"card-footer separator d-flex j-c-center\">\n  <button\n    translate\n    class=\"btn btn-default\"\n    type=\"button\"\n    (click)=\"back()\"\n    *ngIf=\"stepper.selectedIndex !== 0\"\n    [disabled]=\"\n      setup.currentSetupState === setup.setupState.FINALIZING ||\n      setup.currentSetupState === setup.setupState.RELOADING\n    \"\n  >\n    Back\n  </button>\n  <button\n    class=\"btn btn-primary\"\n    type=\"button\"\n    data-cy=\"c8y-setup-completed--done-button\"\n    (click)=\"start()\"\n    [disabled]=\"\n      status === 'error' ||\n      setup.currentSetupState === setup.setupState.FINALIZING ||\n      setup.currentSetupState === setup.setupState.RELOADING\n    \"\n    [ngClass]=\"{\n      'btn-pending':\n        setup.currentSetupState === setup.setupState.FINALIZING ||\n        setup.currentSetupState === setup.setupState.RELOADING\n    }\"\n  >\n    <span *ngIf=\"setup.currentSetupState === setup.setupState.WIZARD\" translate>\n      Save and reload\n    </span>\n    <span *ngIf=\"setup.currentSetupState === setup.setupState.FINALIZING\" translate>\n      Getting things ready\u2026\n    </span>\n    <span *ngIf=\"setup.currentSetupState === setup.setupState.RELOADING\" translate>\n      Done. Reloading the application.\n    </span>\n  </button>\n</div>\n", dependencies: [{ kind: "directive", type: i4.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i5.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i6.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i6.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i6.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i6.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "component", type: i7.OperationResultComponent, selector: "c8y-operation-result", inputs: ["text", "vertical", "size", "type"] }, { kind: "pipe", type: i8.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: SetupCompletedComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-setup-completed', host: { class: 'd-contents' }, template: "<div class=\"container-fluid flex-no-shrink fit-w\">\n  <div class=\"row separator-bottom\">\n    <div class=\"col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3 p-t-24 p-l-16 p-r-16\">\n      <h3 translate class=\"text-medium l-h-base\" data-cy=\"c8y-setup--completed-header-title\">Summary</h3>\n      <p translate class=\"lead text-normal p-t-8 p-b-8\">\n        Verify the setup result. If any step is not finished but required, you need to ensure that\n        you have finished the step.\n      </p>\n    </div>\n  </div>\n</div>\n<div class=\"inner-scroll flex-grow\">\n  <div class=\"container-fluid fit-w p-t-16\">\n    <div class=\"row\">\n      <div class=\"col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3\">\n        <div class=\"text-center\" [ngSwitch]=\"status\">\n          <c8y-operation-result\n            *ngSwitchCase=\"'done'\"\n            text=\"{{ 'Setup completed' | translate }}\"\n            [size]=\"120\"\n            [vertical]=\"true\"\n            type=\"success\"\n          ></c8y-operation-result>\n          <c8y-operation-result\n            *ngSwitchCase=\"'warning'\"\n            text=\"{{ 'Setup completed with warnings' | translate }}\"\n            [size]=\"120\"\n            [vertical]=\"true\"\n            type=\"warning\"\n          ></c8y-operation-result>\n          <c8y-operation-result\n            *ngSwitchCase=\"'error'\"\n            text=\"{{ 'Setup not completed' | translate }}\"\n            [size]=\"120\"\n            [vertical]=\"true\"\n            type=\"error\"\n          ></c8y-operation-result>\n        </div>\n        <ul class=\"list-unstyled m-t-16 separator-top\">\n          <li\n            class=\"p-t-4 p-b-4 d-flex a-i-center separator-bottom text-nowrap l-h-1\"\n            *ngFor=\"let step of setup.steps.slice(0, setup.steps.length - 1)\"\n            (click)=\"gotoStep(step.index)\"\n            style=\"cursor: pointer\"\n          >\n            <span *ngIf=\"step.label\">\n              <span\n                class=\"dot small m-r-4 l-h-1\"\n                [ngClass]=\"{\n                  'dot-success': step.completed,\n                  'dot-error': !step.completed && step.required,\n                  'dot-warning': !step.completed && !step.required\n                }\"\n              >\n                {{ step.index + 1 }}\n              </span>\n              {{ step.label || (STEP_LABEL | translate) + ' ' }}\n            </span>\n            <span *ngIf=\"!step.label\">\n              <span translate>Step</span>\n              {{ ' ' + (step.index + 1) }}\n            </span>\n            <span class=\"m-l-auto icon-20 l-h-1\">\n              <i\n                *ngIf=\"step.completed\"\n                [c8yIcon]=\"'success'\"\n                class=\"text-success\"\n                [title]=\"'Completed' | translate\"\n              ></i>\n              <i\n                *ngIf=\"!step.completed && step.required\"\n                [c8yIcon]=\"'error'\"\n                class=\"text-danger\"\n                [title]=\"\n                  'Not completed and required. Go to the step and fulfill the setup.' | translate\n                \"\n              ></i>\n              <i\n                *ngIf=\"!step.completed && !step.required\"\n                [c8yIcon]=\"'warning'\"\n                class=\"text-warning\"\n                [title]=\"'This step was not completed but it is also not required.' | translate\"\n              ></i>\n            </span>\n          </li>\n        </ul>\n      </div>\n    </div>\n  </div>\n</div>\n<div class=\"card-footer separator d-flex j-c-center\">\n  <button\n    translate\n    class=\"btn btn-default\"\n    type=\"button\"\n    (click)=\"back()\"\n    *ngIf=\"stepper.selectedIndex !== 0\"\n    [disabled]=\"\n      setup.currentSetupState === setup.setupState.FINALIZING ||\n      setup.currentSetupState === setup.setupState.RELOADING\n    \"\n  >\n    Back\n  </button>\n  <button\n    class=\"btn btn-primary\"\n    type=\"button\"\n    data-cy=\"c8y-setup-completed--done-button\"\n    (click)=\"start()\"\n    [disabled]=\"\n      status === 'error' ||\n      setup.currentSetupState === setup.setupState.FINALIZING ||\n      setup.currentSetupState === setup.setupState.RELOADING\n    \"\n    [ngClass]=\"{\n      'btn-pending':\n        setup.currentSetupState === setup.setupState.FINALIZING ||\n        setup.currentSetupState === setup.setupState.RELOADING\n    }\"\n  >\n    <span *ngIf=\"setup.currentSetupState === setup.setupState.WIZARD\" translate>\n      Save and reload\n    </span>\n    <span *ngIf=\"setup.currentSetupState === setup.setupState.FINALIZING\" translate>\n      Getting things ready\u2026\n    </span>\n    <span *ngIf=\"setup.currentSetupState === setup.setupState.RELOADING\" translate>\n      Done. Reloading the application.\n    </span>\n  </button>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.C8yStepper }, { type: i2.CdkStep }, { type: i3.SetupComponent }] });
//# sourceMappingURL=data:application/json;base64, 