import { __decorate, __metadata } from "tslib";
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd/message';
import { TranslateService } from '@ngx-translate/core';
import { API, DEF } from '../../../../../../api';
let IdentityClientsUpdateSecretCreateComponent = class IdentityClientsUpdateSecretCreateComponent {
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.clientId = '';
        this.formGroup = new FormGroup({
            type: new FormControl('SharedSecret', {
                validators: [Validators.required],
            }),
            value: new FormControl('', {
                validators: Validators.required,
            }),
            hash: new FormControl(0),
            expiration: new FormControl(''),
            description: new FormControl(''),
        });
        this.ok = new EventEmitter();
        this.secretCreating = false;
        this.visible = false;
        this.visibleChange = new EventEmitter();
    }
    handleAfterClose() {
        this.formGroup.reset({
            type: 'SharedSecret',
            hash: 0,
        });
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    handleOk() {
        if (this.formGroup.invalid) {
            return;
        }
        this.secretCreating = true;
        API.Identity.ClientController.SaveSecret({ client: this.clientId }, new DEF.Identity.SaveClientSecretQuery(Object.assign(Object.assign({}, this.formGroup.getRawValue()), { clientId: this.clientId }))).subscribe({
            next: () => {
                this.secretCreating = false;
                this.visibleChange.emit(false);
                this.ok.emit();
                this.nzMessageService.success(this.translateService.instant('projects/fe-ng/src/lib/page/identity/clients/update/secret/create/identity--clients--update--secret--create.create_successfully'));
            },
            error: () => {
                this.secretCreating = false;
            },
        });
    }
};
IdentityClientsUpdateSecretCreateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], IdentityClientsUpdateSecretCreateComponent.prototype, "clientId", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsUpdateSecretCreateComponent.prototype, "ok", void 0);
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityClientsUpdateSecretCreateComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsUpdateSecretCreateComponent.prototype, "visibleChange", void 0);
IdentityClientsUpdateSecretCreateComponent = __decorate([
    Component({
        selector: 'kg---identity--clients--update--secret--create',
        template: "<nz-modal\n  (nzAfterClose)=\"handleAfterClose()\"\n  (nzOnCancel)=\"handleCancel()\"\n  [nzBodyStyle]=\"{\n    padding: '12px 16px 6px 16px'\n  }\"\n  [nzCancelDisabled]=\"secretCreating\"\n  [nzClosable]=\"!secretCreating\"\n  [nzKeyboard]=\"false\"\n  [nzMaskClosable]=\"false\"\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/clients/update/secret/create/identity--clients--update--secret--create.title' | i18n\"\n  [nzVisible]=\"visible\"\n  [nzWrapClassName]=\"'identity--clients--update--secret--create'\"\n  nzWidth=\"748px\"\n>\n  <form (ngSubmit)=\"handleOk()\" [formGroup]=\"formGroup\" nz-form nzLayout=\"vertical\">\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'type'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/update/secret/create/identity--clients--update--secret--create.type' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <nz-select [attr.id]=\"'type'\" [formControlName]=\"'type'\">\n          <nz-option [nzLabel]=\"'Shared Secret'\" [nzValue]=\"'SharedSecret'\"></nz-option>\n          <nz-option [nzLabel]=\"'X509 Thumbprint'\" [nzValue]=\"'X509Thumbprint'\"></nz-option>\n          <nz-option [nzLabel]=\"'X509 Name'\" [nzValue]=\"'X509Name'\"></nz-option>\n          <nz-option [nzLabel]=\"'X509 Certificate Base64'\" [nzValue]=\"'X509CertificateBase64'\"></nz-option>\n        </nz-select>\n      </nz-form-control>\n    </nz-form-item>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'value'\" [nzRequired]=\"true\">\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/update/secret/create/identity--clients--update--secret--create.value' | i18n }}:\n      </nz-form-label>\n      <nz-form-control [nzErrorTip]=\"'app__required' | i18n\">\n        <input [attr.id]=\"'value'\" [formControlName]=\"'value'\" nz-input />\n      </nz-form-control>\n    </nz-form-item>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'hash'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/update/secret/create/identity--clients--update--secret--create.hash' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <nz-select [attr.id]=\"'hash'\" [formControlName]=\"'hash'\">\n          <nz-option [nzLabel]=\"'Sha256'\" [nzValue]=\"0\"></nz-option>\n          <nz-option [nzLabel]=\"'Sha512'\" [nzValue]=\"1\"></nz-option>\n        </nz-select>\n      </nz-form-control>\n    </nz-form-item>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'description'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/update/secret/create/identity--clients--update--secret--create.description' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <input [attr.id]=\"'description'\" [formControlName]=\"'description'\" nz-input />\n      </nz-form-control>\n    </nz-form-item>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'expiration'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/update/secret/create/identity--clients--update--secret--create.expiration' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <nz-date-picker\n          [attr.id]=\"'expiration'\"\n          [formControlName]=\"'expiration'\"\n          [nzClassName]=\"'nz-date-picker-expiration'\"\n          nzFormat=\"YYYY-MM-DD HH:mm:ss\"\n          nzShowTime\n        ></nz-date-picker>\n      </nz-form-control>\n    </nz-form-item>\n\n    <button [hidden]=\"true\"></button>\n  </form>\n\n  <div *nzModalFooter>\n    <button (click)=\"handleCancel()\" [disabled]=\"secretCreating\" nz-button nzType=\"default\">\n      <i nz-icon nzTheme=\"outline\" nzType=\"stop\"></i>\n      {{ 'app__cancel' | i18n }}\n    </button>\n\n    <button (click)=\"handleOk()\" [disabled]=\"formGroup.invalid\" [nzLoading]=\"secretCreating\" nz-button nzType=\"primary\">\n      <i nz-icon nzTheme=\"outline\" nzType=\"check\"></i>\n      {{ 'app__ok' | i18n }}\n    </button>\n  </div>\n</nz-modal>\n",
        styles: ["::ng-deep .identity--clients--update--secret--create nz-date-picker{width:100%!important}::ng-deep .identity--clients--update--secret--create nz-date-picker .nz-date-picker-expiration{width:100%!important}"]
    }),
    __metadata("design:paramtypes", [NzMessageService, TranslateService])
], IdentityClientsUpdateSecretCreateComponent);
export { IdentityClientsUpdateSecretCreateComponent };
//# sourceMappingURL=data:application/json;base64, 