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';
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.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;
        }
    }
}
LoginSettingsComponent.decorators = [
    { type: Component, args: [{
                selector: 'c8y-login-settings',
                template: "<div class=\"card-block separator-top overflow-auto\" *ngIf=\"authConfiguration\">\n  <div class=\"col-sm-2\">\n    <h4 class=\"text-right\">{{ 'Login settings' | translate }}</h4>\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 title=\"{{ 'Preferred login mode' | translate }}\">\n          {{ 'Preferred login mode' | translate }}\n          <button\n            class=\"btn btn-clean\"\n            popover=\"{{ PREFERRED_LOGIN_MODE_POPOVER | translate }}\"\n            placement=\"right\"\n            [outsideClick]=\"true\"\n          >\n            <i [c8yIcon]=\"'question-circle-o'\" class=\"text-info\"></i>\n          </button>\n        </label>\n        <div class=\"c8y-select-wrapper\">\n          <select\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>OAI-Secure</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 btn-clean\"\n              popover=\"{{ ENFORCED_BY_PLATFORM_POPOVER | translate }}\"\n              placement=\"bottom\"\n              [outsideClick]=\"true\"\n              *ngIf=\"systemPasswordLimitValidity\"\n            >\n              <i [c8yIcon]=\"'question-circle-o'\"></i>\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 btn-clean\"\n              popover=\"{{ ENFORCED_BY_PLATFORM_POPOVER | translate }}\"\n              placement=\"bottom\"\n              [outsideClick]=\"true\"\n              *ngIf=\"systemPasswordEnforceStrength\"\n            >\n              <i [c8yIcon]=\"'question-circle-o'\"></i>\n            </button>\n          </label>\n          <div>\n            <label\n              title=\"{{ 'Enforce that all passwords are strong (green)' | translate }}\"\n              class=\"c8y-switch\"\n            >\n              <input\n                type=\"checkbox\"\n                name=\"passwordEnforceStrength\"\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>\n</div>\n",
                viewProviders: [{ provide: ControlContainer, useExisting: NgForm }]
            },] }
];
LoginSettingsComponent.ctorParameters = () => [
    { type: TenantUiService }
];
LoginSettingsComponent.propDecorators = {
    authConfiguration: [{ type: Input }]
};
//# sourceMappingURL=data:application/json;base64, 