import { __assign, __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';
var IdentityApiResourceUpdateSecretCreateComponent = /** @class */ (function () {
    function IdentityApiResourceUpdateSecretCreateComponent(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.apiResourceName = '';
        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();
    }
    IdentityApiResourceUpdateSecretCreateComponent.prototype.handleAfterClose = function () {
        this.formGroup.reset({
            type: 'SharedSecret',
            hash: 0,
        });
    };
    IdentityApiResourceUpdateSecretCreateComponent.prototype.handleCancel = function () {
        this.visibleChange.emit(false);
    };
    IdentityApiResourceUpdateSecretCreateComponent.prototype.handleOk = function () {
        var _this = this;
        if (this.formGroup.invalid) {
            return;
        }
        this.secretCreating = true;
        API.Identity.ApiResourceController.SaveSecret({ resource: this.apiResourceName }, new DEF.Identity.SaveApiSecretQuery(__assign(__assign({}, this.formGroup.getRawValue()), { resourceName: this.apiResourceName }))).subscribe({
            next: function () {
                _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: function () {
                _this.secretCreating = false;
            },
        });
    };
    IdentityApiResourceUpdateSecretCreateComponent.ctorParameters = function () { return [
        { type: NzMessageService },
        { type: TranslateService }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], IdentityApiResourceUpdateSecretCreateComponent.prototype, "apiResourceName", void 0);
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], IdentityApiResourceUpdateSecretCreateComponent.prototype, "ok", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Boolean)
    ], IdentityApiResourceUpdateSecretCreateComponent.prototype, "visible", void 0);
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], IdentityApiResourceUpdateSecretCreateComponent.prototype, "visibleChange", void 0);
    IdentityApiResourceUpdateSecretCreateComponent = __decorate([
        Component({
            selector: 'kg---identity--api-resource--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/api-resource/update/secret/create/identity--api-resource--update--secret--create.title' | i18n\"\n  [nzVisible]=\"visible\"\n  [nzWrapClassName]=\"'identity--api-resource--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/api-resource/update/secret/create/identity--api-resource--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/api-resource/update/secret/create/identity--api-resource--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/api-resource/update/secret/create/identity--api-resource--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/api-resource/update/secret/create/identity--api-resource--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/api-resource/update/secret/create/identity--api-resource--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          class=\"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--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);
    return IdentityApiResourceUpdateSecretCreateComponent;
}());
export { IdentityApiResourceUpdateSecretCreateComponent };
//# sourceMappingURL=data:application/json;base64, 