import { Component } from '@angular/core';
import { AlertService, AppStateService, gettext } from '@c8y/ngx-components';
import { DEFAULT_CONFIG } from './cockpit-config.model';
import { CockpitConfigService } from './cockpit-config.service';
import * as i0 from "@angular/core";
import * as i1 from "./cockpit-config.service";
import * as i2 from "@c8y/ngx-components";
import * as i3 from "@angular/forms";
import * as i4 from "ngx-bootstrap/popover";
import * as i5 from "@c8y/ngx-components/icon-selector";
import * as i6 from "./feature-config.component";
import * as i7 from "./root-node-config.component";
import * as i8 from "./home-dashboard-config.component";
import * as i9 from "./misc-config.component";
export class CockpitConfigurationComponent {
    constructor(cockpitConfigService, alertService, appState) {
        this.cockpitConfigService = cockpitConfigService;
        this.alertService = alertService;
        this.appState = appState;
        /**
         * The currently used configuration.
         */
        this.config = DEFAULT_CONFIG;
        this.rootNodeDisabled = false;
    }
    /**
     * @ignore
     */
    ngOnInit() {
        this.config = this.cockpitConfigService.currentConfig;
    }
    /**
     * Stores the configuration and shows a success message.
     */
    async save() {
        try {
            await this.cockpitConfigService.saveConfig(this.config);
            this.alertService.success(gettext('Cockpit configuration saved.'));
        }
        catch (ex) {
            this.alertService.addServerFailure(ex);
        }
    }
    /**
     * @ignore
     */
    iconSelectionChange(icon) {
        this.config.icon = { class: icon };
        this.appState.currentApplication.next({
            ...this.appState.currentApplication.value,
            ...{ config: this.config }
        });
    }
    /**
     * Updates the features to directly reflect the results of the change.
     */
    updateFeatures() {
        this.cockpitConfigService.currentConfig = this.config;
        this.cockpitConfigService.refresh();
    }
    /**
     * Updates the root nodes to directly reflect the results of the change.
     */
    async updateRootNodes() {
        this.rootNodeDisabled = true;
        this.cockpitConfigService.currentConfig = this.config;
        await this.cockpitConfigService.setRootNodes();
        this.rootNodeDisabled = false;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: CockpitConfigurationComponent, deps: [{ token: i1.CockpitConfigService }, { token: i2.AlertService }, { token: i2.AppStateService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: CockpitConfigurationComponent, selector: "c8y-cockpit-configuration", ngImport: i0, template: "<c8y-title>{{ 'Application configuration' | translate }}</c8y-title>\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-tools'\"\n    [label]=\"'Configuration' | translate\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-tools'\"\n    [label]=\"'Application configuration' | translate\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n<div class=\"row\">\n  <div class=\"col-lg-12 col-lg-max\">\n    <form #configForm=\"ngForm\">\n      <div class=\"card card--fullpage\">\n        <div class=\"card-header separator\">\n          <div class=\"card-title\">\n            {{ config.appTitle || ('Cockpit' | translate) }} {{ 'configuration' | translate }}\n          </div>\n        </div>\n\n        <div class=\"inner-scroll\">\n          <div class=\"card-block p-t-0 p-b-0\">\n            <fieldset class=\"row separator-bottom p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div\n                  class=\"h4 text-medium d-inline-block m-r-4\"\n                  translate\n                >\n                  Title, icon, and navigator collapse\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-9 col-md-8 p-l-16\">\n                <div class=\"d-flex a-i-start gap-16\">\n                  <div class=\"form-group d-inline-block\">\n                    <label>{{ 'Icon' | translate }}</label>\n                    <c8y-icon-selector-wrapper\n                      [selectedIcon]=\"config?.icon?.class || 'c8y-cockpit'\"\n                      [iconSize]=\"24\"\n                      (onSelect)=\"iconSelectionChange($event)\"\n                    ></c8y-icon-selector-wrapper>\n                  </div>\n                  <div class=\"form-group flex-grow\">\n                    <label\n                      for=\"confAppTitle\"\n                      translate\n                    >\n                      Change application title\n                    </label>\n                    <input\n                      class=\"form-control\"\n                      id=\"confAppTitle\"\n                      placeholder=\"{{ 'e.g. Cockpit' | translate }} \"\n                      type=\"text\"\n                      maxlength=\"254\"\n                      [(ngModel)]=\"config.appTitle\"\n                      [ngModelOptions]=\"{ standalone: true }\"\n                    />\n                  </div>\n                </div>\n\n                <c8y-misc-config [config]=\"config\"></c8y-misc-config>\n              </div>\n            </fieldset>\n            <fieldset class=\"row separator-bottom p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div class=\"d-inline-flex m-b-16\">\n                  <div\n                    class=\"h4 text-medium m-r-4\"\n                    translate\n                  >\n                    Features\n                  </div>\n                  <button\n                    class=\"btn-help btn-help--sm\"\n                    [attr.aria-label]=\"'Help' | translate\"\n                    popover=\"{{\n                      'Define which are the enabled features in the current application.'\n                        | translate\n                    }}\"\n                    placement=\"right\"\n                    triggers=\"focus\"\n                    container=\"body\"\n                    type=\"button\"\n                  ></button>\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-9 col-md-8\">\n                <c8y-feature-config\n                  [config]=\"config\"\n                  (onUpdate)=\"updateFeatures()\"\n                ></c8y-feature-config>\n              </div>\n            </fieldset>\n            <fieldset class=\"row separator-bottom p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div class=\"d-inline-flex m-b-16\">\n                  <div\n                    class=\"h4 text-medium m-r-8\"\n                    translate\n                  >\n                    Top level nodes\n                  </div>\n                  <button\n                    class=\"btn-help btn-help--sm\"\n                    [attr.aria-label]=\"'Help' | translate\"\n                    popover=\"{{\n                      'Select which nodes to display in the top level of the navigator menu. By default, only Groups is shown.'\n                        | translate\n                    }}\"\n                    placement=\"right\"\n                    triggers=\"focus\"\n                    container=\"body\"\n                    type=\"button\"\n                  ></button>\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-10 col-md-10\">\n                <div class=\"row\">\n                  <c8y-root-node-config\n                    [config]=\"config\"\n                    (onUpdate)=\"updateRootNodes()\"\n                    [disabled]=\"rootNodeDisabled\"\n                  ></c8y-root-node-config>\n                </div>\n              </div>\n            </fieldset>\n\n            <fieldset class=\"row p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div class=\"d-inline-flex m-b-16\">\n                  <div\n                    class=\"h4 text-medium m-r-8\"\n                    translate\n                  >\n                    Home dashboard\n                  </div>\n                  <button\n                    class=\"btn-help btn-help--sm\"\n                    [attr.aria-label]=\"'Help' | translate\"\n                    popover=\"{{\n                      'The homepage of this application. By default, it is a customizable dashboard displaying the most important alarms and shortcuts to frequently used features.'\n                        | translate\n                    }}\"\n                    placement=\"right\"\n                    triggers=\"focus\"\n                    container=\"body\"\n                    type=\"button\"\n                  ></button>\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-9 col-md-8\">\n                <c8y-home-dashboard-config [config]=\"config\"></c8y-home-dashboard-config>\n              </div>\n            </fieldset>\n          </div>\n        </div>\n        <div class=\"card-footer separator\">\n          <button\n            class=\"btn btn-primary\"\n            title=\"{{ 'Save' | translate }}\"\n            type=\"submit\"\n            [disabled]=\"!configForm.form.valid\"\n            (click)=\"save()\"\n            [actionName]=\"'cockpitConfigurationSaved'\"\n            [actionData]=\"{ config: config }\"\n            c8yProductExperience\n          >\n            {{ 'Save' | translate }}\n          </button>\n        </div>\n      </div>\n    </form>\n  </div>\n</div>\n", dependencies: [{ kind: "component", type: i2.BreadcrumbComponent, selector: "c8y-breadcrumb" }, { kind: "component", type: i2.BreadcrumbItemComponent, selector: "c8y-breadcrumb-item", inputs: ["icon", "translate", "label", "path", "injector"] }, { kind: "directive", type: i2.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "component", type: i2.TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.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: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i3.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i2.ProductExperienceDirective, selector: "[c8yProductExperience]", inputs: ["actionName", "actionData", "inherit", "suppressDataOverriding"] }, { kind: "directive", type: i4.PopoverDirective, selector: "[popover]", inputs: ["adaptivePosition", "boundariesElement", "popover", "popoverContext", "popoverTitle", "placement", "outsideClick", "triggers", "container", "containerClass", "isOpen", "delay"], outputs: ["onShown", "onHidden"], exportAs: ["bs-popover"] }, { kind: "component", type: i5.IconSelectorWrapperComponent, selector: "c8y-icon-selector-wrapper", inputs: ["canRemoveIcon", "selectedIcon", "iconSize"], outputs: ["onSelect"] }, { kind: "component", type: i6.FeatureConfigComponent, selector: "c8y-feature-config", inputs: ["config"], outputs: ["onUpdate"] }, { kind: "component", type: i7.RootNodeConfigComponent, selector: "c8y-root-node-config", inputs: ["config", "disabled"], outputs: ["onUpdate"] }, { kind: "component", type: i8.HomeDashboardConfigComponent, selector: "c8y-home-dashboard-config", inputs: ["config"] }, { kind: "component", type: i9.MiscConfigComponent, selector: "c8y-misc-config", inputs: ["config"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: CockpitConfigurationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-cockpit-configuration', template: "<c8y-title>{{ 'Application configuration' | translate }}</c8y-title>\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-tools'\"\n    [label]=\"'Configuration' | translate\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-tools'\"\n    [label]=\"'Application configuration' | translate\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n<div class=\"row\">\n  <div class=\"col-lg-12 col-lg-max\">\n    <form #configForm=\"ngForm\">\n      <div class=\"card card--fullpage\">\n        <div class=\"card-header separator\">\n          <div class=\"card-title\">\n            {{ config.appTitle || ('Cockpit' | translate) }} {{ 'configuration' | translate }}\n          </div>\n        </div>\n\n        <div class=\"inner-scroll\">\n          <div class=\"card-block p-t-0 p-b-0\">\n            <fieldset class=\"row separator-bottom p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div\n                  class=\"h4 text-medium d-inline-block m-r-4\"\n                  translate\n                >\n                  Title, icon, and navigator collapse\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-9 col-md-8 p-l-16\">\n                <div class=\"d-flex a-i-start gap-16\">\n                  <div class=\"form-group d-inline-block\">\n                    <label>{{ 'Icon' | translate }}</label>\n                    <c8y-icon-selector-wrapper\n                      [selectedIcon]=\"config?.icon?.class || 'c8y-cockpit'\"\n                      [iconSize]=\"24\"\n                      (onSelect)=\"iconSelectionChange($event)\"\n                    ></c8y-icon-selector-wrapper>\n                  </div>\n                  <div class=\"form-group flex-grow\">\n                    <label\n                      for=\"confAppTitle\"\n                      translate\n                    >\n                      Change application title\n                    </label>\n                    <input\n                      class=\"form-control\"\n                      id=\"confAppTitle\"\n                      placeholder=\"{{ 'e.g. Cockpit' | translate }} \"\n                      type=\"text\"\n                      maxlength=\"254\"\n                      [(ngModel)]=\"config.appTitle\"\n                      [ngModelOptions]=\"{ standalone: true }\"\n                    />\n                  </div>\n                </div>\n\n                <c8y-misc-config [config]=\"config\"></c8y-misc-config>\n              </div>\n            </fieldset>\n            <fieldset class=\"row separator-bottom p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div class=\"d-inline-flex m-b-16\">\n                  <div\n                    class=\"h4 text-medium m-r-4\"\n                    translate\n                  >\n                    Features\n                  </div>\n                  <button\n                    class=\"btn-help btn-help--sm\"\n                    [attr.aria-label]=\"'Help' | translate\"\n                    popover=\"{{\n                      'Define which are the enabled features in the current application.'\n                        | translate\n                    }}\"\n                    placement=\"right\"\n                    triggers=\"focus\"\n                    container=\"body\"\n                    type=\"button\"\n                  ></button>\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-9 col-md-8\">\n                <c8y-feature-config\n                  [config]=\"config\"\n                  (onUpdate)=\"updateFeatures()\"\n                ></c8y-feature-config>\n              </div>\n            </fieldset>\n            <fieldset class=\"row separator-bottom p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div class=\"d-inline-flex m-b-16\">\n                  <div\n                    class=\"h4 text-medium m-r-8\"\n                    translate\n                  >\n                    Top level nodes\n                  </div>\n                  <button\n                    class=\"btn-help btn-help--sm\"\n                    [attr.aria-label]=\"'Help' | translate\"\n                    popover=\"{{\n                      'Select which nodes to display in the top level of the navigator menu. By default, only Groups is shown.'\n                        | translate\n                    }}\"\n                    placement=\"right\"\n                    triggers=\"focus\"\n                    container=\"body\"\n                    type=\"button\"\n                  ></button>\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-10 col-md-10\">\n                <div class=\"row\">\n                  <c8y-root-node-config\n                    [config]=\"config\"\n                    (onUpdate)=\"updateRootNodes()\"\n                    [disabled]=\"rootNodeDisabled\"\n                  ></c8y-root-node-config>\n                </div>\n              </div>\n            </fieldset>\n\n            <fieldset class=\"row p-t-24 p-b-24\">\n              <div class=\"col-xs-12 col-sm-3 col-md-2 text-left-xs text-right-sm\">\n                <div class=\"d-inline-flex m-b-16\">\n                  <div\n                    class=\"h4 text-medium m-r-8\"\n                    translate\n                  >\n                    Home dashboard\n                  </div>\n                  <button\n                    class=\"btn-help btn-help--sm\"\n                    [attr.aria-label]=\"'Help' | translate\"\n                    popover=\"{{\n                      'The homepage of this application. By default, it is a customizable dashboard displaying the most important alarms and shortcuts to frequently used features.'\n                        | translate\n                    }}\"\n                    placement=\"right\"\n                    triggers=\"focus\"\n                    container=\"body\"\n                    type=\"button\"\n                  ></button>\n                </div>\n              </div>\n              <div class=\"col-xs-12 col-sm-9 col-md-8\">\n                <c8y-home-dashboard-config [config]=\"config\"></c8y-home-dashboard-config>\n              </div>\n            </fieldset>\n          </div>\n        </div>\n        <div class=\"card-footer separator\">\n          <button\n            class=\"btn btn-primary\"\n            title=\"{{ 'Save' | translate }}\"\n            type=\"submit\"\n            [disabled]=\"!configForm.form.valid\"\n            (click)=\"save()\"\n            [actionName]=\"'cockpitConfigurationSaved'\"\n            [actionData]=\"{ config: config }\"\n            c8yProductExperience\n          >\n            {{ 'Save' | translate }}\n          </button>\n        </div>\n      </div>\n    </form>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.CockpitConfigService }, { type: i2.AlertService }, { type: i2.AppStateService }] });
//# sourceMappingURL=data:application/json;base64, 