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';
var IdentityApiResourceCreateComponent = /** @class */ (function () {
    function IdentityApiResourceCreateComponent(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.apiResourceCreating = false;
        this.formGroup = new FormGroup({
            name: new FormControl('', {
                validators: Validators.required,
            }),
            displayName: new FormControl(''),
            description: new FormControl(''),
            enabled: new FormControl(true),
            userClaims: new FormControl([]),
        });
        this.ok = new EventEmitter();
        this.visible = false;
        this.visibleChange = new EventEmitter();
    }
    Object.defineProperty(IdentityApiResourceCreateComponent.prototype, "userClaimsControl", {
        get: function () {
            return this.formGroup.get('userClaims');
        },
        enumerable: true,
        configurable: true
    });
    IdentityApiResourceCreateComponent.prototype.handleAfterClose = function () {
        this.formGroup.reset({
            enabled: true,
            userClaims: [],
        });
    };
    IdentityApiResourceCreateComponent.prototype.handleCancel = function () {
        this.visibleChange.emit(false);
    };
    IdentityApiResourceCreateComponent.prototype.handleOk = function () {
        var _this = this;
        if (this.formGroup.invalid) {
            return;
        }
        this.apiResourceCreating = true;
        API.Identity.ApiResourceController.Save(undefined, new DEF.Identity.ApiResource(this.formGroup.getRawValue())).subscribe({
            next: function () {
                _this.apiResourceCreating = false;
                _this.visibleChange.emit(false);
                _this.ok.emit();
                _this.nzMessageService.success(_this.translateService.instant('projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--create.create_successfully'));
            },
            error: function () {
                _this.apiResourceCreating = false;
            },
        });
    };
    IdentityApiResourceCreateComponent.ctorParameters = function () { return [
        { type: NzMessageService },
        { type: TranslateService }
    ]; };
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], IdentityApiResourceCreateComponent.prototype, "ok", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Boolean)
    ], IdentityApiResourceCreateComponent.prototype, "visible", void 0);
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], IdentityApiResourceCreateComponent.prototype, "visibleChange", void 0);
    IdentityApiResourceCreateComponent = __decorate([
        Component({
            selector: 'kg---identity--api-resource--create',
            template: "<nz-modal\n  (nzAfterClose)=\"handleAfterClose()\"\n  (nzOnCancel)=\"handleCancel()\"\n  [nzBodyStyle]=\"{\n    padding: '12px 16px 6px 16px'\n  }\"\n  [nzCancelDisabled]=\"apiResourceCreating\"\n  [nzClosable]=\"!apiResourceCreating\"\n  [nzKeyboard]=\"false\"\n  [nzMaskClosable]=\"false\"\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--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]=\"'name'\" [nzRequired]=\"true\">{{ 'app__name' | i18n }}:</nz-form-label>\n      <nz-form-control [nzErrorTip]=\"'app__required' | i18n\">\n        <input [attr.id]=\"'name'\" [formControlName]=\"'name'\" nz-input />\n      </nz-form-control>\n    </nz-form-item>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'displayName'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--create.display_name' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <input [attr.id]=\"'displayName'\" [formControlName]=\"'displayName'\" nz-input />\n      </nz-form-control>\n    </nz-form-item>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'description'\">{{ 'app__description' | i18n }}:</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]=\"'enabled'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--create.enabled' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <nz-switch [attr.id]=\"'enabled'\" [formControlName]=\"'enabled'\"></nz-switch>\n      </nz-form-control>\n    </nz-form-item>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'userClaims'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--create.user_claims' | i18n }}:\n      </nz-form-label>\n      <nz-form-control>\n        <nz-select [attr.id]=\"'userClaims'\" [formControlName]=\"'userClaims'\" nzMode=\"tags\">\n          <nz-option *ngFor=\"let item of userClaimsControl.value\" [nzLabel]=\"item\" [nzValue]=\"item\"></nz-option>\n        </nz-select>\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]=\"apiResourceCreating\" 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]=\"apiResourceCreating\" 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])
    ], IdentityApiResourceCreateComponent);
    return IdentityApiResourceCreateComponent;
}());
export { IdentityApiResourceCreateComponent };
//# sourceMappingURL=data:application/json;base64, 