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 IdentityClientsCreateComponent = class IdentityClientsCreateComponent {
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.visible = false;
        this.visibleChange = new EventEmitter();
        this.ok = new EventEmitter();
        this.clientCreating = false;
        this.formGroup = new FormGroup({
            clientId: new FormControl('', {
                validators: Validators.required,
            }),
            clientName: new FormControl('', {
                validators: [Validators.required],
            }),
            description: new FormControl(''),
            clientUri: new FormControl(''),
            logoutUri: new FormControl(''),
            logoUri: new FormControl(''),
            clientType: new FormControl(0),
        });
    }
    handleOk() {
        if (this.formGroup.invalid) {
            return;
        }
        this.clientCreating = true;
        API.Identity.ClientController.Post(undefined, new DEF.Identity.SaveClientQuery(this.formGroup.getRawValue())).subscribe({
            next: () => {
                this.clientCreating = false;
                this.visibleChange.emit(false);
                this.ok.emit();
                this.nzMessageService.success(this.translateService.instant('projects/fe-ng/src/lib/page/identity/clients/create/identity--clients--create.create_successfully'));
            },
            error: () => {
                this.clientCreating = false;
            },
        });
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    handleAfterClose() {
        this.formGroup.reset({
            clientType: 0,
        });
    }
};
IdentityClientsCreateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityClientsCreateComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsCreateComponent.prototype, "visibleChange", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityClientsCreateComponent.prototype, "ok", void 0);
IdentityClientsCreateComponent = __decorate([
    Component({
        selector: 'kg---identity--clients--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]=\"clientCreating\"\r\n  [nzClosable]=\"!clientCreating\"\r\n  [nzKeyboard]=\"false\"\r\n  [nzMaskClosable]=\"false\"\r\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/clients/create/identity--clients--create.title' | i18n\"\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]=\"'clientId'\" [nzRequired]=\"true\">\r\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.client_id' | i18n }}:\r\n      </nz-form-label>\r\n      <nz-form-control [nzErrorTip]=\"'app.common.required' | i18n\">\r\n        <input nz-input [formControlName]=\"'clientId'\" [attr.id]=\"'clientId'\" />\r\n      </nz-form-control>\r\n    </nz-form-item>\r\n\r\n    <nz-form-item>\r\n      <nz-form-label [nzFor]=\"'clientName'\" [nzRequired]=\"true\">\r\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.client_name' | i18n }}:\r\n      </nz-form-label>\r\n      <nz-form-control [nzErrorTip]=\"'app.common.required' | i18n\">\r\n        <input nz-input [formControlName]=\"'clientName'\" [attr.id]=\"'clientName'\" />\r\n      </nz-form-control>\r\n    </nz-form-item>\r\n\r\n    <nz-form-item>\r\n      <nz-form-label [nzFor]=\"'description'\">{{ 'app.common.description' | i18n }}:</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]=\"'clientUri'\">\r\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/create/identity--clients--create.client_uri' | i18n }}:\r\n      </nz-form-label>\r\n      <nz-form-control>\r\n        <input nz-input [formControlName]=\"'clientUri'\" [attr.id]=\"'clientUri'\" />\r\n      </nz-form-control>\r\n    </nz-form-item>\r\n\r\n    <nz-form-item>\r\n      <nz-form-label [nzFor]=\"'logoutUri'\">\r\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/create/identity--clients--create.logout_uri' | i18n }}:\r\n      </nz-form-label>\r\n      <nz-form-control>\r\n        <input nz-input [formControlName]=\"'logoutUri'\" [attr.id]=\"'logoutUri'\" />\r\n      </nz-form-control>\r\n    </nz-form-item>\r\n\r\n    <nz-form-item>\r\n      <nz-form-label [nzFor]=\"'logoUri'\">\r\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/create/identity--clients--create.logo_uri' | i18n }}:\r\n      </nz-form-label>\r\n      <nz-form-control>\r\n        <input nz-input [formControlName]=\"'logoUri'\" [attr.id]=\"'logoUri'\" />\r\n      </nz-form-control>\r\n    </nz-form-item>\r\n\r\n    <nz-form-item>\r\n      <nz-form-label [nzFor]=\"'clientType'\">\r\n        {{ 'projects/fe-ng/src/lib/page/identity/clients/create/identity--clients--create.client_type' | i18n }}:\r\n      </nz-form-label>\r\n      <nz-form-control>\r\n        <nz-select [attr.id]=\"'clientType'\" [formControlName]=\"'clientType'\">\r\n          <nz-option\r\n            [nzValue]=\"0\"\r\n            [nzLabel]=\"\r\n              'projects/fe-ng/src/lib/page/identity/shared/pipes/client-type/kg--identity--client-type.empty' | i18n\r\n            \"\r\n          ></nz-option>\r\n          <nz-option\r\n            [nzValue]=\"1\"\r\n            [nzLabel]=\"\r\n              'projects/fe-ng/src/lib/page/identity/shared/pipes/client-type/kg--identity--client-type.web_server_side_renderer'\r\n                | i18n\r\n            \"\r\n          ></nz-option>\r\n          <nz-option\r\n            [nzValue]=\"2\"\r\n            [nzLabel]=\"\r\n              'projects/fe-ng/src/lib/page/identity/shared/pipes/client-type/kg--identity--client-type.web_hybrid'\r\n                | i18n\r\n            \"\r\n          ></nz-option>\r\n          <nz-option\r\n            [nzValue]=\"3\"\r\n            [nzLabel]=\"\r\n              'projects/fe-ng/src/lib/page/identity/shared/pipes/client-type/kg--identity--client-type.spa' | i18n\r\n            \"\r\n          ></nz-option>\r\n          <nz-option\r\n            [nzValue]=\"4\"\r\n            [nzLabel]=\"\r\n              'projects/fe-ng/src/lib/page/identity/shared/pipes/client-type/kg--identity--client-type.native' | i18n\r\n            \"\r\n          ></nz-option>\r\n          <nz-option\r\n            [nzValue]=\"5\"\r\n            [nzLabel]=\"\r\n              'projects/fe-ng/src/lib/page/identity/shared/pipes/client-type/kg--identity--client-type.machine' | i18n\r\n            \"\r\n          ></nz-option>\r\n          <nz-option\r\n            [nzValue]=\"6\"\r\n            [nzLabel]=\"\r\n              'projects/fe-ng/src/lib/page/identity/shared/pipes/client-type/kg--identity--client-type.device' | i18n\r\n            \"\r\n          ></nz-option>\r\n        </nz-select>\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]=\"clientCreating\" 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]=\"clientCreating\" 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])
], IdentityClientsCreateComponent);
export { IdentityClientsCreateComponent };
//# sourceMappingURL=data:application/json;base64, 