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';
import { IdentityResourceVO } from '../../vo/identity-resource.vo';
let IdentityApiResourceUpdateComponent = class IdentityApiResourceUpdateComponent {
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.apiResource = new IdentityResourceVO();
        this.apiResourceFetching = false;
        this.apiResourceUpdating = 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.identityApiResourceUpdateScopeComponentProp = {
            visible: false,
        };
        this.identityApiResourceUpdateSecretComponentProp = {
            visible: false,
        };
        this.ok = new EventEmitter();
        this.visible = false;
        this.visibleChange = new EventEmitter();
    }
    get userClaimsControl() {
        return this.formGroup.get('userClaims');
    }
    handleAfterClose() {
        this.formGroup.reset({
            enabled: true,
            userClaims: [],
        });
    }
    handleAfterOpen() {
        this.fetchApiResource();
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    handleOk() {
        if (this.formGroup.invalid) {
            return;
        }
        this.apiResourceUpdating = true;
        API.Identity.ApiResourceController.Update({
            resource: this.apiResource.name,
        }, new DEF.Identity.ApiResource(Object.assign({}, this.formGroup.getRawValue()))).subscribe({
            next: () => {
                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: () => {
                this.apiResourceUpdating = false;
            },
        });
    }
    openIdentityApiResourceUpdateScopeComponent() {
        this.identityApiResourceUpdateScopeComponentProp.visible = true;
    }
    openIdentityApiResourceUpdateSecretComponent() {
        this.identityApiResourceUpdateSecretComponentProp.visible = true;
    }
    fetchApiResource() {
        this.apiResourceFetching = true;
        API.Identity.ApiResourceController.Details({
            resource: this.apiResource.name,
        }).subscribe({
            next: (data) => {
                this.formGroup.patchValue(data);
                this.apiResourceFetching = false;
            },
            error: () => {
                this.apiResourceFetching = false;
            },
        });
    }
};
IdentityApiResourceUpdateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
__decorate([
    Input(),
    __metadata("design:type", IdentityResourceVO)
], IdentityApiResourceUpdateComponent.prototype, "apiResource", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityApiResourceUpdateComponent.prototype, "ok", void 0);
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityApiResourceUpdateComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityApiResourceUpdateComponent.prototype, "visibleChange", void 0);
IdentityApiResourceUpdateComponent = __decorate([
    Component({
        selector: 'kg---identity--api-resource--update',
        template: "<nz-modal\n  (nzAfterClose)=\"handleAfterClose()\"\n  (nzAfterOpen)=\"handleAfterOpen()\"\n  (nzOnCancel)=\"handleCancel()\"\n  [nzBodyStyle]=\"{\n    padding: '12px 16px 6px 16px'\n  }\"\n  [nzCancelDisabled]=\"apiResourceUpdating\"\n  [nzClosable]=\"!apiResourceUpdating\"\n  [nzKeyboard]=\"false\"\n  [nzMaskClosable]=\"false\"\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.title' | i18n\"\n  [nzVisible]=\"visible\"\n  nzWidth=\"748px\"\n>\n  <ng-template #nzIndicatorTpl><i nz-icon nzType=\"loading\" style=\"font-size: 24px;\"></i> </ng-template>\n\n  <nz-spin [nzIndicator]=\"nzIndicatorTpl\" [nzSpinning]=\"apiResourceFetching\">\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/identity--api-resource--update.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/update/identity--api-resource--update.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/update/identity--api-resource--update.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      <div [nzGutter]=\"32\" nz-row>\n        <div [nzSpan]=\"8\" nz-col>\n          <nz-form-item>\n            <nz-form-label> {{ 'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_secrets' | i18n }}: </nz-form-label>\n            <nz-form-control>\n              <button (click)=\"openIdentityApiResourceUpdateSecretComponent()\" nz-button nzType=\"primary\" type=\"button\">\n                {{ 'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_secrets' | i18n }}\n              </button>\n            </nz-form-control>\n          </nz-form-item>\n        </div>\n\n        <div [nzSpan]=\"8\" nz-col>\n          <nz-form-item>\n            <nz-form-label> {{ 'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_scopes' | i18n }}: </nz-form-label>\n            <nz-form-control>\n              <button (click)=\"openIdentityApiResourceUpdateScopeComponent()\" nz-button nzType=\"primary\" type=\"button\">\n                {{ 'projects/fe-ng/src/lib/page/identity/api-resource/update/identity--api-resource--update.api_scopes' | i18n }}\n              </button>\n            </nz-form-control>\n          </nz-form-item>\n        </div>\n      </div>\n\n      <button [hidden]=\"true\"></button>\n    </form>\n  </nz-spin>\n\n  <div *nzModalFooter>\n    <button (click)=\"handleCancel()\" [disabled]=\"apiResourceUpdating\" 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]=\"apiResourceFetching || formGroup.invalid\" [nzLoading]=\"apiResourceUpdating\" 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\n<kg---identity--api-resource--update--secret\n  [(visible)]=\"identityApiResourceUpdateSecretComponentProp.visible\"\n  [apiResourceName]=\"apiResource.name\"\n></kg---identity--api-resource--update--secret>\n\n<kg---identity--api-resource--update--scope\n  [(visible)]=\"identityApiResourceUpdateScopeComponentProp.visible\"\n  [apiResourceName]=\"apiResource.name\"\n></kg---identity--api-resource--update--scope>\n"
    }),
    __metadata("design:paramtypes", [NzMessageService, TranslateService])
], IdentityApiResourceUpdateComponent);
export { IdentityApiResourceUpdateComponent };
//# sourceMappingURL=data:application/json;base64, 