import { Component, Inject } from "@angular/core";
import { MAT_DIALOG_DATA } from "@angular/material/dialog";
import { Subject } from "rxjs";
import { takeUntil } from "rxjs/operators";
import { DataType } from "../../../../common/enum/data-type.enum";
import * as i0 from "@angular/core";
import * as i1 from "../../../../services/translation-registry.service";
import * as i2 from "@angular/material/dialog";
import * as i3 from "@angular/common";
import * as i4 from "@angular/material/icon";
import * as i5 from "../../../button/button";
import * as i6 from "../../../tree/tree.component";
import * as i7 from "../../model/risk-analysis.model";
export class RiskAnalysisComponent {
    ;
    constructor(translate, dialog, dialogRef, data) {
        this.translate = translate;
        this.dialog = dialog;
        this.dialogRef = dialogRef;
        this.data = data;
        this.dangers = [];
        this.analysisDanger = [];
        this.selectedData = [];
        this.nodeCheckedItem = [];
        this.disabledList = [];
        this.riskData = [];
        this.ngUnsubscribe = new Subject();
    }
    ngOnInit() {
        this.translate.getLanguageSubject$.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res) => {
            if (res) {
                this.LANG = this.translate.getObjectLang(res);
            }
        });
        this.title = this.data.title;
        this.dangers = this.data.dangers;
        this.dangerConfig = this.data.dangerConfig;
        this.selectedData = [...this.data.selectedDangers];
        this.disabledList = this.data.disabledList || [];
        // cheat not null when selected
        if (this.data.selectedDangers.length) {
            this.analysisDanger.push({
                analysisId: 1,
                analysisName: 'string',
                dangerId: 1,
                dangerName: 'string',
            });
        }
        this.riskConfig = {
            showCheckBox: true,
            allowMultipleCheck: true,
            onlyCheckBoxForChild: false,
            moduleId: DataType.risk,
            openIcon: 'keyboard_arrow_up',
            openIconColor: '#1954A9',
            closeIcon: 'keyboard_arrow_down',
            closeIconColor: '',
            itemIcon: 'border_all',
            itemIconPath: '',
            itemIconBase64: '',
            singleSelectedNode: false,
            canHaveDupId: false
        };
    }
    ngOnDestroy() {
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete();
    }
    toggleChileNode(list) {
        this.analysisDanger = [];
        this.nodeCheckedItem = [];
        if (list.length) {
            this.dangers.forEach(el => {
                list.forEach(x => {
                    if (x.id === el.childId) {
                        // keep array node selected
                        this.nodeCheckedItem.push(x);
                        // create format show analysis 
                        this.analysisDanger.push({
                            analysisId: +el.rootId,
                            analysisName: el.rootName,
                            dangerId: +el.childId,
                            dangerName: el.childName
                        });
                    }
                });
            });
        }
    }
    onCloseClick() {
        this.dialogRef.close();
    }
    onFinishClick() {
        const data = {
            'nodeSelected': this.nodeCheckedItem,
            'analysisData': this.analysisDanger,
            'riskData': this.dangers || []
        };
        this.dialogRef.close(data);
    }
    onCancelClick() {
        this.dialogRef.close();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RiskAnalysisComponent, deps: [{ token: i1.TranslateLibraryService }, { token: i2.MatDialog }, { token: i2.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: RiskAnalysisComponent, selector: "qms-risk-analysis", ngImport: i0, template: "<div\n  id=\"qmslib_risk_analysis\"\n  class=\"qmslib__risk__analysis__container qms__popup\"\n>\n  <div id=\"qmslib_risk_analysis_title\">\n    <span mat-icon-button class=\"button__close\" (click)=\"onCloseClick()\">\n      <mat-icon mat-icon>close</mat-icon>\n    </span>\n    <div id=\"qmslib_risk_analysis_title_001\" mat-dialog-content class=\"title\">\n      <span>{{ title }}</span>\n    </div>\n  </div>\n  <div id=\"qmslib_risk_analysis_header_001\" class=\"regular\">\n    <span>{{ LANG.REGULAR_TITLE }}</span>\n  </div>\n  <div id=\"qmslib_risk_analysis_header_002\" class=\"caption__regular\">\n    <span>{{ LANG.CAPTION_TITLE }}</span>\n  </div>\n  <div class=\"line__divider\"></div>\n  <div id=\"qmslib_risk_analysis_header_003\" class=\"overline\">\n    <span>{{ LANG.CAUSAL_ANALYZES | uppercase }}</span>\n  </div>\n  <div\n    id=\"qmslib_risk_analysis_content\"\n    class=\"panel__content qms-scrollbar\"\n    [ngClass]=\"\n      !analysisDanger.length ? 'panel__content__error' : 'panel__content'\n    \"\n  >\n    <qms-tree\n      [treeData]=\"dangers\"\n      [treeConfig]=\"dangerConfig\"\n      [selectedData]=\"selectedData\"\n      [disabledList]=\"disabledList\"\n      (checkBoxEvent)=\"toggleChileNode($event)\"\n    ></qms-tree>\n  </div>\n\n  <div *ngIf=\"!analysisDanger.length\" class=\"line__divider\"></div>\n\n  <div *ngIf=\"!analysisDanger.length\" class=\"panel__error\">\n    <span class=\"material-icons-outlined\">info</span>\n    <span class=\"message\"> {{ LANG.ERROR.SELECT_DANGER }}</span>\n  </div>\n\n  <div class=\"line__divider\"></div>\n\n  <div class=\"confirm__button__groups\">\n    <button\n      qms-btn\n      [disabled]=\"!analysisDanger.length\"\n      (click)=\"onFinishClick()\"\n    >\n      {{ LANG.FINISHED }}\n    </button>\n    <button qms-btn-text (click)=\"onCancelClick()\">\n      {{ LANG.CANCEL }}\n    </button>\n  </div>\n</div>\n", styles: ["::-webkit-scrollbar{width:12px}::-webkit-scrollbar-track{background:#0000001f;background-clip:content-box}::-webkit-scrollbar-thumb{background:#00000061;border-radius:20px;width:4px;border:4px solid transparent;background-clip:content-box}::-webkit-scrollbar-thumb:hover{background:#00000080;background-clip:content-box;border:4px solid transparent}.qms__popup .button__close{float:right;top:-24px;right:-24px;cursor:pointer}.qms__danger button{border:none;color:var(--text-white);padding:0;text-align:center;text-decoration:none;display:inline-block;cursor:pointer;height:20px;width:20px;font-family:Open Sans;font-size:12px;font-weight:600;font-style:normal;line-height:16px}.qms__danger .red{background-color:var(--button-red-background);margin-left:10px}.qms__danger .yellow{background-color:var(--button-yellow-background);margin-left:10px;color:var(--popup-title-color)}.qms__danger .green{background-color:var(--button-green-background);margin-left:10px}.confirm__button__groups{margin-top:11px}.confirm__button__groups button{min-height:36px;width:auto;font-family:Open Sans;font-weight:500;font-size:14px;letter-spacing:1px;line-height:16px;padding-left:15px;padding-right:15px;margin-right:5px;float:right}.confirm__button__groups .confirm{background:var(--button-background)}.confirm__button__groups .confirm:hover{background:var(--primary-button-background-color);color:var(--primary-button-text-color)}.confirm__button__groups .confirm:disabled{cursor:not-allowed}.confirm__button__groups .cancel{background:var(--button-background)}.confirm__button__groups .cancel:hover{background:var(--primary-button-background-color);color:var(--primary-button-text-color)}.qmslib__risk__analysis__container .title{font:Raleway;font-weight:600;font-style:normal;font-size:16px;line-height:22px;color:var(--popup-title-color)}.qmslib__risk__analysis__container .line__divider{border-bottom:1px solid #ccc;height:1px;min-width:300px;max-width:100%}.qmslib__risk__analysis__container .regular{font-family:Open Sans;font-weight:400;font-style:normal;font-size:16px;line-height:28px;margin-top:10px}.qmslib__risk__analysis__container .caption__regular{font-family:Open Sans;font-weight:400;font-style:normal;font-size:12px;line-height:16px;margin-top:10px}.qmslib__risk__analysis__container .overline{font-family:Raleway;font-weight:600;font-style:normal;font-size:12px;letter-spacing:1px;line-height:16px;margin-top:15px}.qmslib__risk__analysis__container .panel__content{height:394px;overflow:auto;margin-top:12px}.qmslib__risk__analysis__container .panel__content__error{height:354px;overflow:auto;margin-top:12px}.qmslib__risk__analysis__container .panel__error{height:40px;color:var(--popup-error-color);display:flex;flex-wrap:wrap;align-content:center;margin-left:15px}.qmslib__risk__analysis__container .panel__error .message{font-family:Open Sans;font-weight:400;font-style:normal;font-size:14px;line-height:22px;margin-left:10px}\n"], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: i2.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "component", type: i5.QMSButton, selector: "button[qms-btn], button[qms-btn-lg], button[qms-btn-outlined],\n               button[qms-btn-outlined-lg], button[qms-btn-text], button[qms-btn-text-lg],\n               button[qms-btn-fab],button[qms-btn-fab-sm],button[qms-btn-fab-ext],\n               button[qms-btn-fab-outlined],button[qms-btn-fab-outlined-sm],button[qms-btn-fab-outlined-ext]", inputs: ["disabled", "color"], exportAs: ["qmsButton"] }, { kind: "component", type: i6.TreeComponent, selector: "qms-tree", inputs: ["treeData", "treeConfig", "selectedData", "selectedRiskData", "disabledList", "expandOnTitleClick", "expandToChildNode", "parentNodeOnClick"], outputs: ["selectNodeEvent", "selectFolderEvent", "checkBoxEvent", "childCheckedEvent", "nodeExpandEvent", "treeControlNodes", "nodeCondensedEvent"] }, { kind: "pipe", type: i3.UpperCasePipe, name: "uppercase" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RiskAnalysisComponent, decorators: [{
            type: Component,
            args: [{ selector: 'qms-risk-analysis', template: "<div\n  id=\"qmslib_risk_analysis\"\n  class=\"qmslib__risk__analysis__container qms__popup\"\n>\n  <div id=\"qmslib_risk_analysis_title\">\n    <span mat-icon-button class=\"button__close\" (click)=\"onCloseClick()\">\n      <mat-icon mat-icon>close</mat-icon>\n    </span>\n    <div id=\"qmslib_risk_analysis_title_001\" mat-dialog-content class=\"title\">\n      <span>{{ title }}</span>\n    </div>\n  </div>\n  <div id=\"qmslib_risk_analysis_header_001\" class=\"regular\">\n    <span>{{ LANG.REGULAR_TITLE }}</span>\n  </div>\n  <div id=\"qmslib_risk_analysis_header_002\" class=\"caption__regular\">\n    <span>{{ LANG.CAPTION_TITLE }}</span>\n  </div>\n  <div class=\"line__divider\"></div>\n  <div id=\"qmslib_risk_analysis_header_003\" class=\"overline\">\n    <span>{{ LANG.CAUSAL_ANALYZES | uppercase }}</span>\n  </div>\n  <div\n    id=\"qmslib_risk_analysis_content\"\n    class=\"panel__content qms-scrollbar\"\n    [ngClass]=\"\n      !analysisDanger.length ? 'panel__content__error' : 'panel__content'\n    \"\n  >\n    <qms-tree\n      [treeData]=\"dangers\"\n      [treeConfig]=\"dangerConfig\"\n      [selectedData]=\"selectedData\"\n      [disabledList]=\"disabledList\"\n      (checkBoxEvent)=\"toggleChileNode($event)\"\n    ></qms-tree>\n  </div>\n\n  <div *ngIf=\"!analysisDanger.length\" class=\"line__divider\"></div>\n\n  <div *ngIf=\"!analysisDanger.length\" class=\"panel__error\">\n    <span class=\"material-icons-outlined\">info</span>\n    <span class=\"message\"> {{ LANG.ERROR.SELECT_DANGER }}</span>\n  </div>\n\n  <div class=\"line__divider\"></div>\n\n  <div class=\"confirm__button__groups\">\n    <button\n      qms-btn\n      [disabled]=\"!analysisDanger.length\"\n      (click)=\"onFinishClick()\"\n    >\n      {{ LANG.FINISHED }}\n    </button>\n    <button qms-btn-text (click)=\"onCancelClick()\">\n      {{ LANG.CANCEL }}\n    </button>\n  </div>\n</div>\n", styles: ["::-webkit-scrollbar{width:12px}::-webkit-scrollbar-track{background:#0000001f;background-clip:content-box}::-webkit-scrollbar-thumb{background:#00000061;border-radius:20px;width:4px;border:4px solid transparent;background-clip:content-box}::-webkit-scrollbar-thumb:hover{background:#00000080;background-clip:content-box;border:4px solid transparent}.qms__popup .button__close{float:right;top:-24px;right:-24px;cursor:pointer}.qms__danger button{border:none;color:var(--text-white);padding:0;text-align:center;text-decoration:none;display:inline-block;cursor:pointer;height:20px;width:20px;font-family:Open Sans;font-size:12px;font-weight:600;font-style:normal;line-height:16px}.qms__danger .red{background-color:var(--button-red-background);margin-left:10px}.qms__danger .yellow{background-color:var(--button-yellow-background);margin-left:10px;color:var(--popup-title-color)}.qms__danger .green{background-color:var(--button-green-background);margin-left:10px}.confirm__button__groups{margin-top:11px}.confirm__button__groups button{min-height:36px;width:auto;font-family:Open Sans;font-weight:500;font-size:14px;letter-spacing:1px;line-height:16px;padding-left:15px;padding-right:15px;margin-right:5px;float:right}.confirm__button__groups .confirm{background:var(--button-background)}.confirm__button__groups .confirm:hover{background:var(--primary-button-background-color);color:var(--primary-button-text-color)}.confirm__button__groups .confirm:disabled{cursor:not-allowed}.confirm__button__groups .cancel{background:var(--button-background)}.confirm__button__groups .cancel:hover{background:var(--primary-button-background-color);color:var(--primary-button-text-color)}.qmslib__risk__analysis__container .title{font:Raleway;font-weight:600;font-style:normal;font-size:16px;line-height:22px;color:var(--popup-title-color)}.qmslib__risk__analysis__container .line__divider{border-bottom:1px solid #ccc;height:1px;min-width:300px;max-width:100%}.qmslib__risk__analysis__container .regular{font-family:Open Sans;font-weight:400;font-style:normal;font-size:16px;line-height:28px;margin-top:10px}.qmslib__risk__analysis__container .caption__regular{font-family:Open Sans;font-weight:400;font-style:normal;font-size:12px;line-height:16px;margin-top:10px}.qmslib__risk__analysis__container .overline{font-family:Raleway;font-weight:600;font-style:normal;font-size:12px;letter-spacing:1px;line-height:16px;margin-top:15px}.qmslib__risk__analysis__container .panel__content{height:394px;overflow:auto;margin-top:12px}.qmslib__risk__analysis__container .panel__content__error{height:354px;overflow:auto;margin-top:12px}.qmslib__risk__analysis__container .panel__error{height:40px;color:var(--popup-error-color);display:flex;flex-wrap:wrap;align-content:center;margin-left:15px}.qmslib__risk__analysis__container .panel__error .message{font-family:Open Sans;font-weight:400;font-style:normal;font-size:14px;line-height:22px;margin-left:10px}\n"] }]
        }], ctorParameters: () => [{ type: i1.TranslateLibraryService }, { type: i2.MatDialog }, { type: i2.MatDialogRef }, { type: i7.RiskAnalysis, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }] });
//# sourceMappingURL=data:application/json;base64, 