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.visible = false;
        this.visibleChange = new EventEmitter();
        this.ok = new EventEmitter();
        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([]),
        });
    }
    Object.defineProperty(IdentityApiResourceCreateComponent.prototype, "userClaimsControl", {
        get: function () {
            return this.formGroup.get('userClaims');
        },
        enumerable: true,
        configurable: true
    });
    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.prototype.handleCancel = function () {
        this.visibleChange.emit(false);
    };
    IdentityApiResourceCreateComponent.prototype.handleAfterClose = function () {
        this.formGroup.reset({
            enabled: true,
            userClaims: [],
        });
    };
    IdentityApiResourceCreateComponent.ctorParameters = function () { return [
        { type: NzMessageService },
        { type: TranslateService }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", Boolean)
    ], IdentityApiResourceCreateComponent.prototype, "visible", void 0);
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], IdentityApiResourceCreateComponent.prototype, "visibleChange", void 0);
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], IdentityApiResourceCreateComponent.prototype, "ok", void 0);
    IdentityApiResourceCreateComponent = __decorate([
        Component({
            selector: 'kg---identity--api-resource--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]=\"apiResourceCreating\"\r\n  [nzClosable]=\"!apiResourceCreating\"\r\n  [nzKeyboard]=\"false\"\r\n  [nzMaskClosable]=\"false\"\r\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--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]=\"'name'\" [nzRequired]=\"true\">{{ 'app.common.name' | i18n }}:</nz-form-label>\r\n      <nz-form-control [nzErrorTip]=\"'app.common.required' | i18n\">\r\n        <input nz-input [formControlName]=\"'name'\" [attr.id]=\"'name'\" />\r\n      </nz-form-control>\r\n    </nz-form-item>\r\n\r\n    <nz-form-item>\r\n      <nz-form-label [nzFor]=\"'displayName'\">\r\n        {{\r\n          'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--create.display_name' | i18n\r\n        }}:\r\n      </nz-form-label>\r\n      <nz-form-control>\r\n        <input nz-input [formControlName]=\"'displayName'\" [attr.id]=\"'displayName'\" />\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]=\"'enabled'\">\r\n        {{ 'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--create.enabled' | i18n }}:\r\n      </nz-form-label>\r\n      <nz-form-control>\r\n        <nz-switch [formControlName]=\"'enabled'\" [attr.id]=\"'enabled'\"></nz-switch>\r\n      </nz-form-control>\r\n    </nz-form-item>\r\n\r\n    <nz-form-item>\r\n      <nz-form-label [nzFor]=\"'userClaims'\">\r\n        {{\r\n          'projects/fe-ng/src/lib/page/identity/api-resource/create/identity--api-resource--create.user_claims' | i18n\r\n        }}:\r\n      </nz-form-label>\r\n      <nz-form-control>\r\n        <nz-select [formControlName]=\"'userClaims'\" [attr.id]=\"'userClaims'\" nzMode=\"tags\">\r\n          <nz-option *ngFor=\"let item of userClaimsControl.value\" [nzLabel]=\"item\" [nzValue]=\"item\"></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]=\"apiResourceCreating\" 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\r\n      (click)=\"handleOk()\"\r\n      [disabled]=\"formGroup.invalid\"\r\n      [nzLoading]=\"apiResourceCreating\"\r\n      nz-button\r\n      nzType=\"primary\"\r\n    >\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])
    ], IdentityApiResourceCreateComponent);
    return IdentityApiResourceCreateComponent;
}());
export { IdentityApiResourceCreateComponent };
//# sourceMappingURL=data:application/json;base64, 