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 IdentityApiResourceUpdateScopeCreateComponent = class IdentityApiResourceUpdateScopeCreateComponent {
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.apiResourceName = '';
        this.formGroup = new FormGroup({
            name: new FormControl('', {
                validators: Validators.required,
            }),
            displayName: new FormControl(''),
            description: new FormControl(''),
            enabled: new FormControl(true),
            showInDiscoveryDocument: new FormControl(true),
            required: new FormControl(false),
            emphasize: new FormControl(false),
            userClaims: new FormControl([]),
        });
        this.ok = new EventEmitter();
        this.scopeCreating = false;
        this.visible = false;
        this.visibleChange = new EventEmitter();
    }
    get userClaimsControl() {
        return this.formGroup.get('userClaims');
    }
    handleAfterClose() {
        this.formGroup.reset({
            enabled: true,
            showInDiscoveryDocument: true,
            required: false,
            emphasize: false,
            userClaims: [],
        });
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    handleOk() {
        if (this.formGroup.invalid) {
            return;
        }
        this.scopeCreating = true;
        API.Identity.ApiResourceController.SaveScope({ resource: this.apiResourceName }, new DEF.Identity.SaveApiScopeQuery(Object.assign(Object.assign({}, this.formGroup.getRawValue()), { resourceName: this.apiResourceName }))).subscribe({
            next: () => {
                this.scopeCreating = false;
                this.visibleChange.emit(false);
                this.ok.emit();
                this.nzMessageService.success(this.translateService.instant('projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--create.create_successfully'));
            },
            error: () => {
                this.scopeCreating = false;
            },
        });
    }
};
IdentityApiResourceUpdateScopeCreateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], IdentityApiResourceUpdateScopeCreateComponent.prototype, "apiResourceName", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityApiResourceUpdateScopeCreateComponent.prototype, "ok", void 0);
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityApiResourceUpdateScopeCreateComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityApiResourceUpdateScopeCreateComponent.prototype, "visibleChange", void 0);
IdentityApiResourceUpdateScopeCreateComponent = __decorate([
    Component({
        selector: 'kg---identity--api-resource--update--scope--create',
        template: "<nz-modal\n  (nzAfterClose)=\"handleAfterClose()\"\n  (nzOnCancel)=\"handleCancel()\"\n  [nzBodyStyle]=\"{\n    padding: '12px 16px 6px 16px'\n  }\"\n  [nzCancelDisabled]=\"scopeCreating\"\n  [nzClosable]=\"!scopeCreating\"\n  [nzKeyboard]=\"false\"\n  [nzMaskClosable]=\"false\"\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--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/update/scope/create/identity--api-resource--update--scope--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    <div [nzGutter]=\"32\" nz-row>\n      <div [nzSpan]=\"12\" nz-col>\n        <nz-form-item>\n          <nz-form-label [nzFor]=\"'enabled'\">\n            {{ 'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--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      </div>\n\n      <div [nzSpan]=\"12\" nz-col>\n        <nz-form-item>\n          <nz-form-label [nzFor]=\"'showInDiscoveryDocument'\">\n            {{\n              'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--create.show_in_discovery_document'\n                | i18n\n            }}:\n          </nz-form-label>\n          <nz-form-control>\n            <nz-switch [attr.id]=\"'showInDiscoveryDocument'\" [formControlName]=\"'showInDiscoveryDocument'\"></nz-switch>\n          </nz-form-control>\n        </nz-form-item>\n      </div>\n    </div>\n\n    <div [nzGutter]=\"32\" nz-row>\n      <div [nzSpan]=\"12\" nz-col>\n        <nz-form-item>\n          <nz-form-label [nzFor]=\"'required'\">{{ 'app__required' | i18n }}:</nz-form-label>\n          <nz-form-control>\n            <nz-switch [attr.id]=\"'required'\" [formControlName]=\"'required'\"></nz-switch>\n          </nz-form-control>\n        </nz-form-item>\n      </div>\n\n      <div [nzSpan]=\"12\" nz-col>\n        <nz-form-item>\n          <nz-form-label [nzFor]=\"'emphasize'\">\n            {{ 'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--create.emphasize' | i18n }}:\n          </nz-form-label>\n          <nz-form-control>\n            <nz-switch [attr.id]=\"'emphasize'\" [formControlName]=\"'emphasize'\"></nz-switch>\n          </nz-form-control>\n        </nz-form-item>\n      </div>\n    </div>\n\n    <nz-form-item>\n      <nz-form-label [nzFor]=\"'userClaims'\">\n        {{ 'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--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]=\"scopeCreating\" 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]=\"scopeCreating\" 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])
], IdentityApiResourceUpdateScopeCreateComponent);
export { IdentityApiResourceUpdateScopeCreateComponent };
//# sourceMappingURL=data:application/json;base64, 