
class SetNameColor {

    static initSetNameColor() {
        if (window.sigApi !== undefined) {
            const fm = new SetNameColor(window.sigApi);
        } else {
            // ist sigApi noch nicht geladen, als EventListener fuer 'SigApiReady' registrieren
            window.addEventListener('SigApiReady', () => {
                const fm = new SetNameColor(window.sigApi);
            });
        }
    }

    constructor(api) {
        this.events = null;
        this.eventMediator = null;
        this.datapointAPI = null;
        this._initAPIs(api);
        this._registerEvents();
    }

    _initAPIs(api) {
        if ((api !== null) && (api !== undefined)) {
            if (api.datapointManager !== undefined) {
                this.datapointAPI = api.datapointManager;
            }
            if (api.eventMediator !== undefined) {
                this.eventMediator = api.eventMediator;
            }
            if (api.events !== undefined) {
                this.events = api.events;
            }
        }
    }

    _registerEvents() {

        let normaleDuese = 0;
        let Anschluss = 0;
        let Verteiler = 0;
        let language = 0;

        if ((this.eventMediator !== null) && (this.eventMediator !== undefined) && (this.events !== null) && (this.events !== undefined)) {

            this.eventMediator.subscribe(this.events.getUserDefinedInternalEvent('ClassifyGroups'), () => {

                sigApi.datapointManager.readDataPoint('10:Global_Set1.Language_Number', 0)
                    .then((resolve) => {
                               language = resolve.value;

                        if (language === 1){
                            this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Duese', 0)
                                .then((resolve) => {
                                    normaleDuese = resolve.value;
                                    this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Anschluss', 0)
                                        .then((resolve) => {
                                            Anschluss = resolve.value;
                                            this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Verteiler', 0)
                                                .then((resolve) => {
                                                    Verteiler = resolve.value;

                                                    if ((normaleDuese !== 0) && (Anschluss !== 0) && (Verteiler !== 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");

                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        /*      this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Anschluß");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4284022783);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 2: 200 °c:
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "Verteiler");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 4281216255);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass3.GroupOn', 1);*/
                                                        // set default SetPoint for Group 3: 200 °c:
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.SetPoint', 2000);

                                                    }
                                                    else if ((normaleDuese !== 0) && (Anschluss !== 0) && (Verteiler === 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");
                                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Anschluß");
                                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4284022783);
                                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 2: 200 °c:
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese !== 0) && (Anschluss === 0) && (Verteiler !== 0)){

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Verteiler");
                                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4281216255);
                                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 3: 200 °c:
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese !== 0) && (Anschluss === 0) && (Verteiler === 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        /*  this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese === 0) && (Anschluss !== 0) && (Verteiler !== 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Anschluß");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4284022783);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Verteiler");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4281216255);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 3: 200 °c:
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);


                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese === 0) && (Anschluss !== 0) && (Verteiler === 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Anschluß");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4284022783);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        //      this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese === 0) && (Anschluss === 0) && (Verteiler !== 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Verteiler");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4281216255);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //  this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }


                                                    else {
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "-");
                                                        /*  this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 1838350335);
                                                          this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }

                                                    normaleDuese = 0;
                                                    Anschluss = 0;
                                                    Verteiler = 0;

                                                });
                                        });
                                });

                        }
                        else {

                            this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Duese', 0)
                                .then((resolve) => {
                                    normaleDuese = resolve.value;
                                    this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Anschluss', 0)
                                        .then((resolve) => {
                                            Anschluss = resolve.value;
                                            this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Verteiler', 0)
                                                .then((resolve) => {
                                                    Verteiler = resolve.value;

                                                    if ((normaleDuese !== 0) && (Anschluss !== 0) && (Verteiler !== 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Nozzle");

                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        /*      this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Connection");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4284022783);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 2: 200 °c:
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "Distributor");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 4281216255);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass3.GroupOn', 1);*/
                                                        // set default SetPoint for Group 3: 200 °c:
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.SetPoint', 2000);

                                                    }
                                                    else if ((normaleDuese !== 0) && (Anschluss !== 0) && (Verteiler === 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Nozzle");
                                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Connection");
                                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4284022783);
                                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 2: 200 °c:
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese !== 0) && (Anschluss === 0) && (Verteiler !== 0)){

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Nozzle");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Distributor");
                                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4281216255);
                                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 3: 200 °c:
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese !== 0) && (Anschluss === 0) && (Verteiler === 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Nozzle");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        /*  this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese === 0) && (Anschluss !== 0) && (Verteiler !== 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Connection");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4284022783);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Distributor");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4281216255);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                                        // set default SetPoint for Group 3: 200 °c:
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);


                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese === 0) && (Anschluss !== 0) && (Verteiler === 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Connection");
                                                        /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4284022783);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                           this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        //      this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }
                                                    else if ((normaleDuese === 0) && (Anschluss === 0) && (Verteiler !== 0)){
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Distributor");
                                                        /*     this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4281216255);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                                             this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                                        // set default SetPoint for Group 1: 200 °c:
                                                        //  this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }


                                                    else {
                                                        this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "-");
                                                        /*  this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 1838350335);
                                                          this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                                        //     this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                                        this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                                        //   this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                                    }

                                                    normaleDuese = 0;
                                                    Anschluss = 0;
                                                    Verteiler = 0;

                                                });
                                        });
                                });
                        }


                this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Duese', 0)
                    .then((resolve) => {
                        normaleDuese = resolve.value;
                        this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Anschluss', 0)
                            .then((resolve) => {
                                Anschluss = resolve.value;
                                this.datapointAPI.readDataPoint('10:AutomaticGroupClassification1.Verteiler', 0)
                                    .then((resolve) => {
                                        Verteiler = resolve.value;

                                        if ((normaleDuese !== 0) && (Anschluss !== 0) && (Verteiler !== 0)){
                                            this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");

                                         /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                            // set default SetPoint for Group 1: 200 °c:
                                      /*      this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);*/

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Anschluß");
                                         /*   this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4284022783);
                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                            // set default SetPoint for Group 2: 200 °c:
                                         /*   this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);*/

                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "Verteiler");
                                       /*     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 4281216255);
                                            this.datapointAPI.writeDataPoint('10:HelperClass3.GroupOn', 1);*/
                                            // set default SetPoint for Group 3: 200 °c:
                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.SetPoint', 2000);

                                        }
                                        else if ((normaleDuese !== 0) && (Anschluss !== 0) && (Verteiler === 0)){
                                           this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");
                                         /*    this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                            // set default SetPoint for Group 1: 200 °c:
                                         /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);*/

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Anschluß");
                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4284022783);
                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                            // set default SetPoint for Group 2: 200 °c:
                                       //     this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                       //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                        }
                                        else if ((normaleDuese !== 0) && (Anschluss === 0) && (Verteiler !== 0)){

                                            this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");
                                         /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                            // set default SetPoint for Group 1: 200 °c:
                                         //   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Verteiler");
                                        /*    this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4281216255);
                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                            // set default SetPoint for Group 3: 200 °c:
                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                       //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                        }
                                        else if ((normaleDuese !== 0) && (Anschluss === 0) && (Verteiler === 0)){
                                            this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Düse");
                                       /*     this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 855582463);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 1);*/
                                            // set default SetPoint for Group 1: 200 °c:
                                       //     this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                          /*  this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);*/

                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                        }
                                        else if ((normaleDuese === 0) && (Anschluss !== 0) && (Verteiler !== 0)){
                                            this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Anschluß");
                                         /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4284022783);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                            // set default SetPoint for Group 1: 200 °c:
                                         //   this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "Verteiler");
                                       /*     this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 4281216255);
                                            this.datapointAPI.writeDataPoint('10:HelperClass2.GroupOn', 1);*/
                                            // set default SetPoint for Group 3: 200 °c:
                                         //   this.datapointAPI.writeDataPoint('10:PIDGroup2.SetPoint', 2000);


                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                       //     this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                        }
                                        else if ((normaleDuese === 0) && (Anschluss !== 0) && (Verteiler === 0)){
                                            this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Anschluß");
                                         /*   this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4284022783);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                            // set default SetPoint for Group 1: 200 °c:
                                       //     this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                      //      this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                        //    this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                        }
                                        else if ((normaleDuese === 0) && (Anschluss === 0) && (Verteiler !== 0)){
                                            this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "Verteiler");
                                       /*     this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 4281216255);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.GroupOn', 1);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/
                                            // set default SetPoint for Group 1: 200 °c:
                                          //  this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                         //   this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                         //   this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                        }


                                        else {
                                            this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupName', "-");
                                          /*  this.datapointAPI.writeDataPoint('10:PIDGroup1.GroupColorScheme', 1838350335);
                                            this.datapointAPI.writeDataPoint('10:HelperClass1.IsNozzle', 0);*/

                                            this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupName', "-");
                                       //     this.datapointAPI.writeDataPoint('10:PIDGroup2.GroupColorScheme', 1838350335);

                                            this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupName', "-");
                                         //   this.datapointAPI.writeDataPoint('10:PIDGroup3.GroupColorScheme', 1838350335);

                                        }

                                        normaleDuese = 0;
                                        Anschluss = 0;
                                        Verteiler = 0;

                                    });
                            });
                    });
                    });







            });

            this.eventMediator.subscribe(this.events.getUserDefinedInternalEvent('SetEmptyStringAsToolName'), () => {
                this.datapointAPI.writeDataPoint('10:ToolsName1.Tools_Name_Unsaved', "");
            });

            this.eventMediator.subscribe(this.events.getUserDefinedInternalEvent('NavigateToDashboard'), () => {
                this.datapointAPI.readDataPoint('10:SelectedZone1.ZoneID', 0)
                    .then((resolve) => {
                        this._navigateToDashboard(resolve.value);
                    });
            });

            this.eventMediator.subscribe(this.events.getUserDefinedInternalEvent('GoToStart'), () => {
                this.datapointAPI.writeDataPoint('10:SelectedAssistant1.Assistant1', 0)
                    .then(() => {window.sigApi.appRouter.navigate('Startseite');});

            });

            }
    }

    _navigateToDashboard(id) {
        switch (id) {
            case 1:
                this.datapointAPI.readDataPoint('10:Zone1.OperationMode', 0)
                .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 2:
                this.datapointAPI.readDataPoint('10:Zone2.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 3:
                this.datapointAPI.readDataPoint('10:Zone3.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 4:
                this.datapointAPI.readDataPoint('10:Zone4.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 5:
                this.datapointAPI.readDataPoint('10:Zone5.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 6:
                this.datapointAPI.readDataPoint('10:Zone6.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 7:
                this.datapointAPI.readDataPoint('10:Zone7.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 8:
                this.datapointAPI.readDataPoint('10:Zone8.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 9:
                this.datapointAPI.readDataPoint('10:Zone9.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;

            case 10:
                this.datapointAPI.readDataPoint('10:Zone10.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 11:
                this.datapointAPI.readDataPoint('10:Zone11.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 12:
                this.datapointAPI.readDataPoint('10:Zone12.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 13:
                this.datapointAPI.readDataPoint('10:Zone13.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 14:
                this.datapointAPI.readDataPoint('10:Zone14.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 15:
                this.datapointAPI.readDataPoint('10:Zone15.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 16:
                this.datapointAPI.readDataPoint('10:Zone16.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 17:
                this.datapointAPI.readDataPoint('10:Zone17.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 18:
                this.datapointAPI.readDataPoint('10:Zone18.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 19:
                this.datapointAPI.readDataPoint('10:Zone19.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 20:
                this.datapointAPI.readDataPoint('10:Zone20.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 21:
                this.datapointAPI.readDataPoint('10:Zone21.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 22:
                this.datapointAPI.readDataPoint('10:Zone22.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 23:
                this.datapointAPI.readDataPoint('10:Zone23.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
            case 24:
                this.datapointAPI.readDataPoint('10:Zone24.OperationMode', 0)
                    .then((resolve) => {this._navigateToRightDashboard(resolve.value);});
                break;
        }
    }

    _navigateToRightDashboard(index) {
        if (index === 0) {

            window.sigApi.appRouter.navigate('ZoneDetail');

        } else if (index === 1) {

            window.sigApi.appRouter.navigate('ZoneDetail_Stellbetrieb');

        } else if (index === 2) {

            window.sigApi.appRouter.navigate('ZoneDetail_Leitbetrieb');

        } else if (index === 3) {

            window.sigApi.appRouter.navigate('ZoneDetail_Monitorbetrieb');

        } else if (index === 4) {

            window.sigApi.appRouter.navigate('ZoneDetail_Tuning');

        } else {

            window.sigApi.appRouter.navigate('ZoneDetail_Inaktiv');

        }
    }

}

SetNameColor.initSetNameColor();