/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd';
import { TranslateService } from '@ngx-translate/core';
import { API, DEF } from '../../../../../../api';
export class IdentityApiResourceUpdateScopeCreateComponent {
    /**
     * @param {?} nzMessageService
     * @param {?} translateService
     */
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.visible = false;
        this.visibleChange = new EventEmitter();
        this.apiResourceName = '';
        this.ok = new EventEmitter();
        this.scopeCreating = false;
        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([]),
        });
    }
    /**
     * @return {?}
     */
    get userClaimsControl() {
        return (/** @type {?} */ (this.formGroup.get('userClaims')));
    }
    /**
     * @return {?}
     */
    handleOk() {
        if (this.formGroup.invalid) {
            return;
        }
        this.scopeCreating = true;
        API.Identity.ApiResourceController.SaveScope({ resource: this.apiResourceName }, new DEF.Identity.SaveApiScopeQuery(Object.assign({}, this.formGroup.getRawValue(), { resourceName: this.apiResourceName }))).subscribe({
            next: (/**
             * @return {?}
             */
            () => {
                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: (/**
             * @return {?}
             */
            () => {
                this.scopeCreating = false;
            }),
        });
    }
    /**
     * @return {?}
     */
    handleCancel() {
        this.visibleChange.emit(false);
    }
    /**
     * @return {?}
     */
    handleAfterClose() {
        this.formGroup.reset({
            enabled: true,
            showInDiscoveryDocument: true,
            required: false,
            emphasize: false,
            userClaims: [],
        });
    }
}
IdentityApiResourceUpdateScopeCreateComponent.decorators = [
    { type: Component, args: [{
                selector: 'kg---identity--api-resource--update--scope--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]=\"scopeCreating\"\r\n  [nzClosable]=\"!scopeCreating\"\r\n  [nzKeyboard]=\"false\"\r\n  [nzMaskClosable]=\"false\"\r\n  [nzTitle]=\"\r\n    'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--create.title'\r\n      | i18n\r\n  \"\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/update/scope/create/identity--api-resource--update--scope--create.display_name'\r\n            | 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    <div nz-row [nzGutter]=\"32\">\r\n      <div nz-col [nzSpan]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'enabled'\">\r\n            {{\r\n              'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--create.enabled'\r\n                | i18n\r\n            }}:\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      </div>\r\n\r\n      <div nz-col [nzSpan]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'showInDiscoveryDocument'\">\r\n            {{\r\n              'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--create.show_in_discovery_document'\r\n                | i18n\r\n            }}:\r\n          </nz-form-label>\r\n          <nz-form-control>\r\n            <nz-switch [formControlName]=\"'showInDiscoveryDocument'\" [attr.id]=\"'showInDiscoveryDocument'\"></nz-switch>\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n    </div>\r\n\r\n    <div nz-row [nzGutter]=\"32\">\r\n      <div nz-col [nzSpan]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'required'\">{{ 'app.common.required' | i18n }}:</nz-form-label>\r\n          <nz-form-control>\r\n            <nz-switch [formControlName]=\"'required'\" [attr.id]=\"'required'\"></nz-switch>\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n\r\n      <div nz-col [nzSpan]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'emphasize'\">\r\n            {{\r\n              'projects/fe-ng/src/lib/page/identity/api-resource/update/scope/create/identity--api-resource--update--scope--create.emphasize'\r\n                | i18n\r\n            }}:\r\n          </nz-form-label>\r\n          <nz-form-control>\r\n            <nz-switch [formControlName]=\"'emphasize'\" [attr.id]=\"'emphasize'\"></nz-switch>\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n    </div>\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/update/scope/create/identity--api-resource--update--scope--create.user_claims'\r\n            | 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]=\"scopeCreating\" 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]=\"scopeCreating\" 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"
            }] }
];
/** @nocollapse */
IdentityApiResourceUpdateScopeCreateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
IdentityApiResourceUpdateScopeCreateComponent.propDecorators = {
    visible: [{ type: Input }],
    visibleChange: [{ type: Output }],
    apiResourceName: [{ type: Input }],
    ok: [{ type: Output }]
};
if (false) {
    /** @type {?} */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.visible;
    /** @type {?} */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.visibleChange;
    /** @type {?} */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.apiResourceName;
    /** @type {?} */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.ok;
    /** @type {?} */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.scopeCreating;
    /** @type {?} */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.formGroup;
    /**
     * @type {?}
     * @private
     */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.nzMessageService;
    /**
     * @type {?}
     * @private
     */
    IdentityApiResourceUpdateScopeCreateComponent.prototype.translateService;
}
//# sourceMappingURL=data:application/json;base64, 