/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
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';
import { IdentityResourceVO } from '../../vo/identity-resource.vo';
var IdentityApiResourceUpdateComponent = /** @class */ (function () {
    function IdentityApiResourceUpdateComponent(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.visible = false;
        this.visibleChange = new EventEmitter();
        this.apiResource = new IdentityResourceVO();
        this.ok = new EventEmitter();
        this.apiResourceUpdating = false;
        this.apiResourceFetching = false;
        this.identityApiResourceUpdateSecretComponentProp = {
            visible: false,
        };
        this.identityApiResourceUpdateScopeComponentProp = {
            visible: 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(IdentityApiResourceUpdateComponent.prototype, "userClaimsControl", {
        get: /**
         * @return {?}
         */
        function () {
            return (/** @type {?} */ (this.formGroup.get('userClaims')));
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @private
     * @return {?}
     */
    IdentityApiResourceUpdateComponent.prototype.fetchApiResource = /**
     * @private
     * @return {?}
     */
    function () {
        var _this = this;
        this.apiResourceFetching = true;
        API.Identity.ApiResourceController.Details({
            resource: this.apiResource.name,
        }).subscribe({
            next: (/**
             * @param {?} data
             * @return {?}
             */
            function (data) {
                _this.formGroup.patchValue(data);
                _this.apiResourceFetching = false;
            }),
            error: (/**
             * @return {?}
             */
            function () {
                _this.apiResourceFetching = false;
            }),
        });
    };
    /**
     * @return {?}
     */
    IdentityApiResourceUpdateComponent.prototype.openIdentityApiResourceUpdateSecretComponent = /**
     * @return {?}
     */
    function () {
        this.identityApiResourceUpdateSecretComponentProp.visible = true;
    };
    /**
     * @return {?}
     */
    IdentityApiResourceUpdateComponent.prototype.openIdentityApiResourceUpdateScopeComponent = /**
     * @return {?}
     */
    function () {
        this.identityApiResourceUpdateScopeComponentProp.visible = true;
    };
    /**
     * @return {?}
     */
    IdentityApiResourceUpdateComponent.prototype.handleOk = /**
     * @return {?}
     */
    function () {
        var _this = this;
        if (this.formGroup.invalid) {
            return;
        }
        this.apiResourceUpdating = true;
        API.Identity.ApiResourceController.Update({
            resource: this.apiResource.name,
        }, new DEF.Identity.ApiResource(tslib_1.__assign({}, this.formGroup.getRawValue()))).subscribe({
            next: (/**
             * @return {?}
             */
            function () {
                _this.apiResourceUpdating = false;
                _this.visibleChange.emit(false);
                _this.ok.emit();
                _this.nzMessageService.success(_this.translateService.instant('projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.update_successfully'));
            }),
            error: (/**
             * @return {?}
             */
            function () {
                _this.apiResourceUpdating = false;
            }),
        });
    };
    /**
     * @return {?}
     */
    IdentityApiResourceUpdateComponent.prototype.handleCancel = /**
     * @return {?}
     */
    function () {
        this.visibleChange.emit(false);
    };
    /**
     * @return {?}
     */
    IdentityApiResourceUpdateComponent.prototype.handleAfterOpen = /**
     * @return {?}
     */
    function () {
        this.fetchApiResource();
    };
    /**
     * @return {?}
     */
    IdentityApiResourceUpdateComponent.prototype.handleAfterClose = /**
     * @return {?}
     */
    function () {
        this.formGroup.reset({
            enabled: true,
            userClaims: [],
        });
    };
    IdentityApiResourceUpdateComponent.decorators = [
        { type: Component, args: [{
                    selector: 'kg---identity--api-resource--update',
                    template: "<nz-modal\r\n  (nzAfterClose)=\"handleAfterClose()\"\r\n  (nzAfterOpen)=\"handleAfterOpen()\"\r\n  (nzOnCancel)=\"handleCancel()\"\r\n  [nzBodyStyle]=\"{\r\n    padding: '12px 16px 6px 16px'\r\n  }\"\r\n  [nzCancelDisabled]=\"apiResourceUpdating\"\r\n  [nzClosable]=\"!apiResourceUpdating\"\r\n  [nzKeyboard]=\"false\"\r\n  [nzMaskClosable]=\"false\"\r\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.title' | i18n\"\r\n  [nzVisible]=\"visible\"\r\n  nzWidth=\"748px\"\r\n>\r\n  <ng-template #nzIndicatorTpl><i nz-icon nzType=\"loading\" style=\"font-size: 24px;\"></i> </ng-template>\r\n\r\n  <nz-spin [nzIndicator]=\"nzIndicatorTpl\" [nzSpinning]=\"apiResourceFetching\">\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/identity--api-resource--update.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      <nz-form-item>\r\n        <nz-form-label [nzFor]=\"'enabled'\">\r\n          {{\r\n            'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.enabled' | 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\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/identity--api-resource--update.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      <div nz-row [nzGutter]=\"32\">\r\n        <div nz-col [nzSpan]=\"8\">\r\n          <nz-form-item>\r\n            <nz-form-label>\r\n              {{\r\n                'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_secrets'\r\n                  | i18n\r\n              }}:\r\n            </nz-form-label>\r\n            <nz-form-control>\r\n              <button (click)=\"openIdentityApiResourceUpdateSecretComponent()\" nz-button nzType=\"primary\" type=\"button\">\r\n                {{\r\n                  'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_secrets'\r\n                    | i18n\r\n                }}\r\n              </button>\r\n            </nz-form-control>\r\n          </nz-form-item>\r\n        </div>\r\n\r\n        <div nz-col [nzSpan]=\"8\">\r\n          <nz-form-item>\r\n            <nz-form-label>\r\n              {{\r\n                'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_scopes'\r\n                  | i18n\r\n              }}:\r\n            </nz-form-label>\r\n            <nz-form-control>\r\n              <button (click)=\"openIdentityApiResourceUpdateScopeComponent()\" nz-button nzType=\"primary\" type=\"button\">\r\n                {{\r\n                  'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_scopes'\r\n                    | i18n\r\n                }}\r\n              </button>\r\n            </nz-form-control>\r\n          </nz-form-item>\r\n        </div>\r\n      </div>\r\n\r\n      <button [hidden]=\"true\"></button>\r\n    </form>\r\n  </nz-spin>\r\n\r\n  <div *nzModalFooter>\r\n    <button (click)=\"handleCancel()\" [disabled]=\"apiResourceUpdating\" 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]=\"apiResourceFetching || formGroup.invalid\"\r\n      [nzLoading]=\"apiResourceUpdating\"\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\r\n<kg---identity--api-resource--update--secret\r\n  [(visible)]=\"identityApiResourceUpdateSecretComponentProp.visible\"\r\n  [apiResourceName]=\"apiResource.name\"\r\n></kg---identity--api-resource--update--secret>\r\n\r\n<kg---identity--api-resource--update--scope\r\n  [(visible)]=\"identityApiResourceUpdateScopeComponentProp.visible\"\r\n  [apiResourceName]=\"apiResource.name\"\r\n></kg---identity--api-resource--update--scope>\r\n"
                }] }
    ];
    /** @nocollapse */
    IdentityApiResourceUpdateComponent.ctorParameters = function () { return [
        { type: NzMessageService },
        { type: TranslateService }
    ]; };
    IdentityApiResourceUpdateComponent.propDecorators = {
        visible: [{ type: Input }],
        visibleChange: [{ type: Output }],
        apiResource: [{ type: Input }],
        ok: [{ type: Output }]
    };
    return IdentityApiResourceUpdateComponent;
}());
export { IdentityApiResourceUpdateComponent };
if (false) {
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.visible;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.visibleChange;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.apiResource;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.ok;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.apiResourceUpdating;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.apiResourceFetching;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.identityApiResourceUpdateSecretComponentProp;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.identityApiResourceUpdateScopeComponentProp;
    /** @type {?} */
    IdentityApiResourceUpdateComponent.prototype.formGroup;
    /**
     * @type {?}
     * @private
     */
    IdentityApiResourceUpdateComponent.prototype.nzMessageService;
    /**
     * @type {?}
     * @private
     */
    IdentityApiResourceUpdateComponent.prototype.translateService;
}
//# sourceMappingURL=data:application/json;base64, 