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.claimCreating = false;
        this.clientId = '';
        this.formGroup = new FormGroup({
            type: new FormControl('sub', {
                validators: [Validators.required],
            }),
            value: new FormControl('', {
                validators: [Validators.required],
            }),
        });
        this.ok = new EventEmitter();
        this.visible = false;
        this.visibleChange = new EventEmitter();
    }
    handleAfterClose() {
        this.formGroup.reset({
            type: 'sub',
        });
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    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;
            },
        });
    }
};
IdentityClientsUpdateClaimCreateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], IdentityClientsUpdateClaimCreateComponent.prototype, "clientId", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsUpdateClaimCreateComponent.prototype, "ok", void 0);
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityClientsUpdateClaimCreateComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsUpdateClaimCreateComponent.prototype, "visibleChange", void 0);
IdentityClientsUpdateClaimCreateComponent = __decorate([
    Component({
        selector: 'kg---identity--clients--update--claim--create',
        template: "<nz-modal\n  (nzAfterClose)=\"handleAfterClose()\"\n  (nzOnCancel)=\"handleCancel()\"\n  [nzBodyStyle]=\"{\n    padding: '12px 16px 6px 16px'\n  }\"\n  [nzCancelDisabled]=\"claimCreating\"\n  [nzClosable]=\"!claimCreating\"\n  [nzKeyboard]=\"false\"\n  [nzMaskClosable]=\"false\"\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/clients/update/claim/create/identity--clients--update--claim--create.title' | i18n\"\n  [nzVisible]=\"visible\"\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/claim/create/identity--clients--update--claim--create.type' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <nz-select [attr.id]=\"'type'\" [formControlName]=\"'type'\">\n          <nz-option [nzLabel]=\"'sub'\" [nzValue]=\"'sub'\"></nz-option>\n          <nz-option [nzLabel]=\"'name'\" [nzValue]=\"'name'\"></nz-option>\n          <nz-option [nzLabel]=\"'given_name'\" [nzValue]=\"'given_name'\"></nz-option>\n          <nz-option [nzLabel]=\"'family_name'\" [nzValue]=\"'family_name'\"></nz-option>\n          <nz-option [nzLabel]=\"'middle_name'\" [nzValue]=\"'middle_name'\"></nz-option>\n          <nz-option [nzLabel]=\"'nickname'\" [nzValue]=\"'nickname'\"></nz-option>\n          <nz-option [nzLabel]=\"'preferred_username'\" [nzValue]=\"'preferred_username'\"></nz-option>\n          <nz-option [nzLabel]=\"'profile'\" [nzValue]=\"'profile'\"></nz-option>\n          <nz-option [nzLabel]=\"'picture'\" [nzValue]=\"'picture'\"></nz-option>\n          <nz-option [nzLabel]=\"'website'\" [nzValue]=\"'website'\"></nz-option>\n          <nz-option [nzLabel]=\"'email'\" [nzValue]=\"'email'\"></nz-option>\n          <nz-option [nzLabel]=\"'email_verified'\" [nzValue]=\"'email_verified'\"></nz-option>\n          <nz-option [nzLabel]=\"'gender'\" [nzValue]=\"'gender'\"></nz-option>\n          <nz-option [nzLabel]=\"'birthdate'\" [nzValue]=\"'birthdate'\"></nz-option>\n          <nz-option [nzLabel]=\"'zoneinfo'\" [nzValue]=\"'zoneinfo'\"></nz-option>\n          <nz-option [nzLabel]=\"'locale'\" [nzValue]=\"'locale'\"></nz-option>\n          <nz-option [nzLabel]=\"'phone_number'\" [nzValue]=\"'phone_number'\"></nz-option>\n          <nz-option [nzLabel]=\"'phone_number_verified'\" [nzValue]=\"'phone_number_verified'\"></nz-option>\n          <nz-option [nzLabel]=\"'address'\" [nzValue]=\"'address'\"></nz-option>\n          <nz-option [nzLabel]=\"'updated_at'\" [nzValue]=\"'updated_at'\"></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/claim/create/identity--clients--update--claim--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    <button [hidden]=\"true\"></button>\n  </form>\n\n  <div *nzModalFooter>\n    <button (click)=\"handleCancel()\" [disabled]=\"claimCreating\" 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]=\"claimCreating\" 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"
    }),
    __metadata("design:paramtypes", [NzMessageService, TranslateService])
], IdentityClientsUpdateClaimCreateComponent);
export { IdentityClientsUpdateClaimCreateComponent };
//# sourceMappingURL=data:application/json;base64, 