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