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 IdentityClientsUpdateClaimCreateComponent = class IdentityClientsUpdateClaimCreateComponent {
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.visible = false;
        this.visibleChange = new EventEmitter();
        this.clientId = '';
        this.ok = new EventEmitter();
        this.claimCreating = false;
        this.formGroup = new FormGroup({
            type: new FormControl('sub', {
                validators: [Validators.required],
            }),
            value: new FormControl('', {
                validators: [Validators.required],
            }),
        });
    }
    handleOk() {
        if (this.formGroup.invalid) {
            return;
        }
        this.claimCreating = true;
        API.Identity.ClientController.SaveClaim({ client: this.clientId }, new DEF.Identity.SaveClientClaimQuery(Object.assign(Object.assign({}, this.formGroup.getRawValue()), { clientId: this.clientId }))).subscribe({
            next: () => {
                this.claimCreating = false;
                this.visibleChange.emit(false);
                this.ok.emit();
                this.nzMessageService.success(this.translateService.instant('projects/fe-ng/src/lib/page/identity/clients/update/claim/create/identity--clients--update--claim--create.create_successfully'));
            },
            error: () => {
                this.claimCreating = false;
            },
        });
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    handleAfterClose() {
        this.formGroup.reset({
            type: 'sub',
        });
    }
};
IdentityClientsUpdateClaimCreateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityClientsUpdateClaimCreateComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsUpdateClaimCreateComponent.prototype, "visibleChange", void 0);
__decorate([
    Input(),
    __metadata("design:type", String)
], IdentityClientsUpdateClaimCreateComponent.prototype, "clientId", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsUpdateClaimCreateComponent.prototype, "ok", void 0);
IdentityClientsUpdateClaimCreateComponent = __decorate([
    Component({
        selector: 'kg---identity--clients--update--claim--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]=\"claimCreating\"\r\n  [nzClosable]=\"!claimCreating\"\r\n  [nzKeyboard]=\"false\"\r\n  [nzMaskClosable]=\"false\"\r\n  [nzTitle]=\"\r\n    'projects/fe-ng/src/lib/page/identity/clients/update/claim/create/identity--clients--update--claim--create.title'\r\n      | i18n\r\n  \"\r\n  [nzVisible]=\"visible\"\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/clients/update/claim/create/identity--clients--update--claim--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]=\"'sub'\" [nzLabel]=\"'sub'\"></nz-option>\r\n          <nz-option [nzValue]=\"'name'\" [nzLabel]=\"'name'\"></nz-option>\r\n          <nz-option [nzValue]=\"'given_name'\" [nzLabel]=\"'given_name'\"></nz-option>\r\n          <nz-option [nzValue]=\"'family_name'\" [nzLabel]=\"'family_name'\"></nz-option>\r\n          <nz-option [nzValue]=\"'middle_name'\" [nzLabel]=\"'middle_name'\"></nz-option>\r\n          <nz-option [nzValue]=\"'nickname'\" [nzLabel]=\"'nickname'\"></nz-option>\r\n          <nz-option [nzValue]=\"'preferred_username'\" [nzLabel]=\"'preferred_username'\"></nz-option>\r\n          <nz-option [nzValue]=\"'profile'\" [nzLabel]=\"'profile'\"></nz-option>\r\n          <nz-option [nzValue]=\"'picture'\" [nzLabel]=\"'picture'\"></nz-option>\r\n          <nz-option [nzValue]=\"'website'\" [nzLabel]=\"'website'\"></nz-option>\r\n          <nz-option [nzValue]=\"'email'\" [nzLabel]=\"'email'\"></nz-option>\r\n          <nz-option [nzValue]=\"'email_verified'\" [nzLabel]=\"'email_verified'\"></nz-option>\r\n          <nz-option [nzValue]=\"'gender'\" [nzLabel]=\"'gender'\"></nz-option>\r\n          <nz-option [nzValue]=\"'birthdate'\" [nzLabel]=\"'birthdate'\"></nz-option>\r\n          <nz-option [nzValue]=\"'zoneinfo'\" [nzLabel]=\"'zoneinfo'\"></nz-option>\r\n          <nz-option [nzValue]=\"'locale'\" [nzLabel]=\"'locale'\"></nz-option>\r\n          <nz-option [nzValue]=\"'phone_number'\" [nzLabel]=\"'phone_number'\"></nz-option>\r\n          <nz-option [nzValue]=\"'phone_number_verified'\" [nzLabel]=\"'phone_number_verified'\"></nz-option>\r\n          <nz-option [nzValue]=\"'address'\" [nzLabel]=\"'address'\"></nz-option>\r\n          <nz-option [nzValue]=\"'updated_at'\" [nzLabel]=\"'updated_at'\"></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/clients/update/claim/create/identity--clients--update--claim--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    <button [hidden]=\"true\"></button>\r\n  </form>\r\n\r\n  <div *nzModalFooter>\r\n    <button (click)=\"handleCancel()\" [disabled]=\"claimCreating\" 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]=\"claimCreating\" 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"
    }),
    __metadata("design:paramtypes", [NzMessageService, TranslateService])
], IdentityClientsUpdateClaimCreateComponent);
export { IdentityClientsUpdateClaimCreateComponent };
//# sourceMappingURL=data:application/json;base64, 