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 IdentityIdentityResourceUpdateComponent = class IdentityIdentityResourceUpdateComponent {
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        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.identityResource = new IdentityResourceVO();
        this.identityResourceFetching = false;
        this.identityResourceUpdating = 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,
            showInDiscoveryDocument: true,
            required: false,
            emphasize: false,
            userClaims: [],
        });
    }
    handleAfterOpen() {
        this.fetchIdentityResource();
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    handleOk() {
        if (this.formGroup.invalid) {
            return;
        }
        this.identityResourceUpdating = true;
        API.Identity.IdentityResourceController.Update({
            resource: this.identityResource.name,
        }, new DEF.Identity.IdentityResource(Object.assign({}, this.formGroup.getRawValue()))).subscribe({
            next: () => {
                this.identityResourceUpdating = false;
                this.visibleChange.emit(false);
                this.ok.emit();
                this.nzMessageService.success(this.translateService.instant('projects/fe-ng/src/lib/page/identity/identity-resource/update/identity--identity-resource--update.update_successfully'));
            },
            error: () => {
                this.identityResourceUpdating = false;
            },
        });
    }
    fetchIdentityResource() {
        this.identityResourceFetching = true;
        API.Identity.IdentityResourceController.Details({
            resource: this.identityResource.name,
        }).subscribe({
            next: (data) => {
                this.formGroup.patchValue(data);
                this.identityResourceFetching = false;
            },
            error: () => {
                this.identityResourceFetching = false;
            },
        });
    }
};
IdentityIdentityResourceUpdateComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
__decorate([
    Input(),
    __metadata("design:type", IdentityResourceVO)
], IdentityIdentityResourceUpdateComponent.prototype, "identityResource", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityIdentityResourceUpdateComponent.prototype, "ok", void 0);
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityIdentityResourceUpdateComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityIdentityResourceUpdateComponent.prototype, "visibleChange", void 0);
IdentityIdentityResourceUpdateComponent = __decorate([
    Component({
        selector: 'kg---identity--identity-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]=\"identityResourceUpdating\"\n  [nzClosable]=\"!identityResourceUpdating\"\n  [nzKeyboard]=\"false\"\n  [nzMaskClosable]=\"false\"\n  [nzTitle]=\"'projects/fe-ng/src/lib/page/identity/identity-resource/update/identity--identity-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]=\"identityResourceFetching\">\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/identity-resource/update/identity--identity-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      <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/identity-resource/update/identity--identity-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        </div>\n\n        <div [nzSpan]=\"12\" nz-col>\n          <nz-form-item>\n            <nz-form-label [nzFor]=\"'showInDiscoveryDocument'\">\n              {{ 'projects/fe-ng/src/lib/page/identity/identity-resource/update/identity--identity-resource--update.show_in_discovery_document' | i18n }}:\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/identity-resource/update/identity--identity-resource--update.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/identity-resource/update/identity--identity-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      <button [hidden]=\"true\"></button>\n    </form>\n  </nz-spin>\n\n  <div *nzModalFooter>\n    <button (click)=\"handleCancel()\" [disabled]=\"identityResourceUpdating\" 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]=\"identityResourceFetching || formGroup.invalid\" [nzLoading]=\"identityResourceUpdating\" 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])
], IdentityIdentityResourceUpdateComponent);
export { IdentityIdentityResourceUpdateComponent };
//# sourceMappingURL=data:application/json;base64, 