import { Component, Input } from '@angular/core';
import { gettext } from '@c8y/ngx-components';
import { ControlContainer, NgForm } from '@angular/forms';
import { TenantUiService } from '@c8y/ngx-components';
import { TenantLoginOptionType } from '@c8y/client';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components";
import * as i2 from "@angular/common";
import * as i3 from "@angular/forms";
import * as i4 from "ngx-bootstrap/popover";
export class LoginSettingsComponent {
    constructor(tenantUiService) {
        this.tenantUiService = tenantUiService;
        this.PREFERRED_LOGIN_MODE_POPOVER = gettext('Main difference is the storage of the authentication information. With Basic Auth, it is saved in a session storage and with OAI-Secure in a HttpOnly cookie. OAI-Secure grant is recommended as the authentication information is not accessible via JavaScript. Single sign-on redirect allows a user to login with a single 3rd-party authorization server using the OAuth2 protocol.');
        this.ENFORCED_BY_PLATFORM_POPOVER = gettext('The setting is enforced on the platform level.');
        this.IGNORE_CASE_SENSITIVITY_POPOVER = gettext('If selected, the letter case of the username does not matter during login.');
        this.tenantLoginOptionTypeEnum = TenantLoginOptionType;
        this.PASSWORD_CATEGORY = 'password';
        this.LIMIT_VALIDITY_KEY = 'limit.validity';
        this.TENANT_STRENGTH_VALIDITY_KEY = 'strength.validity';
        this.SYSTEM_STRENGTH_VALIDITY_KEY = 'enforce.strength';
    }
    ngOnChanges(changes) {
        if (changes.authConfiguration && changes.authConfiguration.currentValue) {
            this.isOauth2 = !!changes.authConfiguration.currentValue.loginOptions.find(this.tenantUiService.isOauth2);
        }
    }
    get systemPasswordLimitValidity() {
        return this.authConfiguration.systemOptions[this.PASSWORD_CATEGORY][this.LIMIT_VALIDITY_KEY];
    }
    get passwordLimitValidity() {
        return this.systemPasswordLimitValidity !== null
            ? this.systemPasswordLimitValidity
            : this.authConfiguration.tenantOptions[this.PASSWORD_CATEGORY][this.LIMIT_VALIDITY_KEY];
    }
    set passwordLimitValidity(value) {
        if (this.systemPasswordLimitValidity === null) {
            this.authConfiguration.tenantOptions[this.PASSWORD_CATEGORY][this.LIMIT_VALIDITY_KEY] = value;
        }
    }
    get systemPasswordEnforceStrength() {
        return this.authConfiguration.systemOptions[this.PASSWORD_CATEGORY][this.SYSTEM_STRENGTH_VALIDITY_KEY];
    }
    get passwordEnforceStrength() {
        return this.systemPasswordEnforceStrength
            ? this.systemPasswordEnforceStrength
            : this.authConfiguration.tenantOptions[this.PASSWORD_CATEGORY][this.TENANT_STRENGTH_VALIDITY_KEY];
    }
    set passwordEnforceStrength(value) {
        if (!this.systemPasswordEnforceStrength) {
            this.authConfiguration.tenantOptions[this.PASSWORD_CATEGORY][this.TENANT_STRENGTH_VALIDITY_KEY] = value;
        }
    }
    get tenantLoginIgnoreCase() {
        return this.authConfiguration.tenantOptions['configuration']['tenant.login.ignore-case'];
    }
    set tenantLoginIgnoreCase(value) {
        this.authConfiguration.tenantOptions['configuration']['tenant.login.ignore-case'] = value;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: LoginSettingsComponent, deps: [{ token: i1.TenantUiService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: LoginSettingsComponent, selector: "c8y-login-settings", inputs: { authConfiguration: "authConfiguration" }, usesOnChanges: true, ngImport: i0, template: "<div class=\"card-block separator-top overflow-auto\" *ngIf=\"authConfiguration\">\n  <div class=\"col-sm-2\">\n    <div class=\"h4 text-normal text-right text-left-xs\">{{ 'Login settings' | translate }}</div>\n  </div>\n\n  <div class=\"col-sm-9\">\n    <div class=\"row m-b-8\">\n      <c8y-form-group class=\"col-sm-6\">\n        <label>\n          {{ 'Preferred login mode' | translate }}\n          <button\n            class=\"btn-help btn-help--sm\"\n            type=\"button\"\n            [attr.aria-label]=\"'Help' | translate\"\n            popover=\"{{ PREFERRED_LOGIN_MODE_POPOVER | translate }}\"\n            placement=\"right\"\n            triggers=\"focus\"\n            container=\"body\"\n          ></button>\n        </label>\n        <div class=\"c8y-select-wrapper\">\n          <select\n            [attr.aria-label]=\"'Auth type' | translate\"\n            class=\"form-control\"\n            id=\"preferredLoginOptionType\"\n            name=\"preferredLoginOptionType\"\n            [(ngModel)]=\"authConfiguration.preferredLoginOptionType\"\n          >\n            <option value=\"{{ tenantLoginOptionTypeEnum.BASIC }}\" translate>Basic Auth</option>\n            <option value=\"{{ tenantLoginOptionTypeEnum.OAUTH2_INTERNAL }}\" translate>\n              OAI-Secure\n            </option>\n            <option value=\"{{ tenantLoginOptionTypeEnum.OAUTH2 }}\" [disabled]=\"!isOauth2\" translate>\n              Single sign-on redirect\n            </option>\n          </select>\n        </div>\n      </c8y-form-group>\n    </div>\n    <div class=\"row\">\n      <div class=\"col-sm-6\">\n        <c8y-form-group>\n          <label title=\"{{ 'Password validity limit' | translate }}\">\n            {{ 'Password validity limit' | translate }}\n            <button\n              class=\"btn-help btn-help--sm\"\n              type=\"button\"\n              [attr.aria-label]=\"'Help' | translate\"\n              popover=\"{{ ENFORCED_BY_PLATFORM_POPOVER | translate }}\"\n              placement=\"bottom\"\n              triggers=\"focus\"\n              *ngIf=\"systemPasswordLimitValidity\"\n            ></button>\n          </label>\n          <div class=\"input-group\">\n            <input\n              type=\"number\"\n              name=\"passwordLimitValidity\"\n              class=\"form-control text-right\"\n              [(ngModel)]=\"passwordLimitValidity\"\n              min=\"0\"\n              max=\"999999\"\n              step=\"1\"\n              required\n              [disabled]=\"systemPasswordLimitValidity\"\n            />\n            <span class=\"input-group-addon\" translate>days</span>\n          </div>\n          <p class=\"help-block\">\n            {{ 'Default: 0 (unlimited validity)' | translate }}\n          </p>\n        </c8y-form-group>\n      </div>\n      <div class=\"col-sm-6\">\n        <c8y-form-group>\n          <label title=\"{{ 'Password strength' | translate }}\">\n            {{ 'Password strength' | translate }}\n            <button\n              class=\"btn-help btn-help--sm\"\n              type=\"button\"\n              [attr.aria-label]=\"'Help' | translate\"\n              popover=\"{{ ENFORCED_BY_PLATFORM_POPOVER | translate }}\"\n              placement=\"bottom\"\n              triggers=\"focus\"\n              *ngIf=\"systemPasswordEnforceStrength\"\n            ></button>\n          </label>\n          <div>\n            <label\n              title=\"{{ 'Enforce that all passwords are strong' | translate }}\"\n              class=\"c8y-switch\"\n            >\n              <input\n                type=\"checkbox\"\n                name=\"passwordEnforceStrength\"\n                data-cy=\"c8y-form-group--password-enforce-toggle-btn\"\n                [(ngModel)]=\"passwordEnforceStrength\"\n                [disabled]=\"systemPasswordEnforceStrength\"\n              />\n              <span></span>\n              <span>{{ 'Enforce strong passwords (green)' | translate }}</span>\n            </label>\n          </div>\n        </c8y-form-group>\n      </div>\n    </div>\n    <div class=\"row\">\n      <div class=\"col-sm-6\">\n        <c8y-form-group>\n          <label\n            title=\"{{ 'Ignore case when logging in' | translate }}\"\n            data-cy=\"c8y-authentication-configuration--ignore-case-when-logging-in\"\n            class=\"c8y-switch\"\n          >\n            <input\n              type=\"checkbox\"\n              name=\"tenantLoginIgnoreCase\"\n              [(ngModel)]=\"tenantLoginIgnoreCase\"\n            />\n            <span></span>\n            <span>{{ 'Ignore case when logging in' | translate }}</span>\n            <button\n              class=\"btn-help btn-help--sm\"\n              type=\"button\"\n              [attr.aria-label]=\"'Help' | translate\"\n              popover=\"{{ IGNORE_CASE_SENSITIVITY_POPOVER | translate }}\"\n              placement=\"right\"\n              triggers=\"focus\"\n              container=\"body\"\n            ></button>\n          </label>\n        </c8y-form-group>\n      </div>\n    </div>\n  </div>\n</div>\n", dependencies: [{ kind: "directive", type: i1.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.MinValidationDirective, selector: "[min]", inputs: ["min"] }, { kind: "directive", type: i1.MaxValidationDirective, selector: "[max]", inputs: ["max"] }, { kind: "directive", type: i3.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i3.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { 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.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i3.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i3.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i3.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i3.MaxValidator, selector: "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", inputs: ["max"] }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i1.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "directive", type: i1.RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { 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: "pipe", type: i1.C8yTranslatePipe, name: "translate" }], viewProviders: [{ provide: ControlContainer, useExisting: NgForm }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: LoginSettingsComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-login-settings', viewProviders: [{ provide: ControlContainer, useExisting: NgForm }], template: "<div class=\"card-block separator-top overflow-auto\" *ngIf=\"authConfiguration\">\n  <div class=\"col-sm-2\">\n    <div class=\"h4 text-normal text-right text-left-xs\">{{ 'Login settings' | translate }}</div>\n  </div>\n\n  <div class=\"col-sm-9\">\n    <div class=\"row m-b-8\">\n      <c8y-form-group class=\"col-sm-6\">\n        <label>\n          {{ 'Preferred login mode' | translate }}\n          <button\n            class=\"btn-help btn-help--sm\"\n            type=\"button\"\n            [attr.aria-label]=\"'Help' | translate\"\n            popover=\"{{ PREFERRED_LOGIN_MODE_POPOVER | translate }}\"\n            placement=\"right\"\n            triggers=\"focus\"\n            container=\"body\"\n          ></button>\n        </label>\n        <div class=\"c8y-select-wrapper\">\n          <select\n            [attr.aria-label]=\"'Auth type' | translate\"\n            class=\"form-control\"\n            id=\"preferredLoginOptionType\"\n            name=\"preferredLoginOptionType\"\n            [(ngModel)]=\"authConfiguration.preferredLoginOptionType\"\n          >\n            <option value=\"{{ tenantLoginOptionTypeEnum.BASIC }}\" translate>Basic Auth</option>\n            <option value=\"{{ tenantLoginOptionTypeEnum.OAUTH2_INTERNAL }}\" translate>\n              OAI-Secure\n            </option>\n            <option value=\"{{ tenantLoginOptionTypeEnum.OAUTH2 }}\" [disabled]=\"!isOauth2\" translate>\n              Single sign-on redirect\n            </option>\n          </select>\n        </div>\n      </c8y-form-group>\n    </div>\n    <div class=\"row\">\n      <div class=\"col-sm-6\">\n        <c8y-form-group>\n          <label title=\"{{ 'Password validity limit' | translate }}\">\n            {{ 'Password validity limit' | translate }}\n            <button\n              class=\"btn-help btn-help--sm\"\n              type=\"button\"\n              [attr.aria-label]=\"'Help' | translate\"\n              popover=\"{{ ENFORCED_BY_PLATFORM_POPOVER | translate }}\"\n              placement=\"bottom\"\n              triggers=\"focus\"\n              *ngIf=\"systemPasswordLimitValidity\"\n            ></button>\n          </label>\n          <div class=\"input-group\">\n            <input\n              type=\"number\"\n              name=\"passwordLimitValidity\"\n              class=\"form-control text-right\"\n              [(ngModel)]=\"passwordLimitValidity\"\n              min=\"0\"\n              max=\"999999\"\n              step=\"1\"\n              required\n              [disabled]=\"systemPasswordLimitValidity\"\n            />\n            <span class=\"input-group-addon\" translate>days</span>\n          </div>\n          <p class=\"help-block\">\n            {{ 'Default: 0 (unlimited validity)' | translate }}\n          </p>\n        </c8y-form-group>\n      </div>\n      <div class=\"col-sm-6\">\n        <c8y-form-group>\n          <label title=\"{{ 'Password strength' | translate }}\">\n            {{ 'Password strength' | translate }}\n            <button\n              class=\"btn-help btn-help--sm\"\n              type=\"button\"\n              [attr.aria-label]=\"'Help' | translate\"\n              popover=\"{{ ENFORCED_BY_PLATFORM_POPOVER | translate }}\"\n              placement=\"bottom\"\n              triggers=\"focus\"\n              *ngIf=\"systemPasswordEnforceStrength\"\n            ></button>\n          </label>\n          <div>\n            <label\n              title=\"{{ 'Enforce that all passwords are strong' | translate }}\"\n              class=\"c8y-switch\"\n            >\n              <input\n                type=\"checkbox\"\n                name=\"passwordEnforceStrength\"\n                data-cy=\"c8y-form-group--password-enforce-toggle-btn\"\n                [(ngModel)]=\"passwordEnforceStrength\"\n                [disabled]=\"systemPasswordEnforceStrength\"\n              />\n              <span></span>\n              <span>{{ 'Enforce strong passwords (green)' | translate }}</span>\n            </label>\n          </div>\n        </c8y-form-group>\n      </div>\n    </div>\n    <div class=\"row\">\n      <div class=\"col-sm-6\">\n        <c8y-form-group>\n          <label\n            title=\"{{ 'Ignore case when logging in' | translate }}\"\n            data-cy=\"c8y-authentication-configuration--ignore-case-when-logging-in\"\n            class=\"c8y-switch\"\n          >\n            <input\n              type=\"checkbox\"\n              name=\"tenantLoginIgnoreCase\"\n              [(ngModel)]=\"tenantLoginIgnoreCase\"\n            />\n            <span></span>\n            <span>{{ 'Ignore case when logging in' | translate }}</span>\n            <button\n              class=\"btn-help btn-help--sm\"\n              type=\"button\"\n              [attr.aria-label]=\"'Help' | translate\"\n              popover=\"{{ IGNORE_CASE_SENSITIVITY_POPOVER | translate }}\"\n              placement=\"right\"\n              triggers=\"focus\"\n              container=\"body\"\n            ></button>\n          </label>\n        </c8y-form-group>\n      </div>\n    </div>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.TenantUiService }], propDecorators: { authConfiguration: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 