import { __assign, __decorate, __metadata } from "tslib";
import { Component, Input } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { API, DEF } from '../../../../../api';
var IdentityRoleRolesUpdateComponent = /** @class */ (function () {
    function IdentityRoleRolesUpdateComponent(nzModalRef) {
        this.nzModalRef = nzModalRef;
        this.formGroup = new FormGroup({
            description: new FormControl('', {
                validators: Validators.required,
            }),
            name: new FormControl({ value: '', disabled: true }),
            showName: new FormControl('', {
                validators: Validators.required,
            }),
        });
        this.saving = false;
    }
    IdentityRoleRolesUpdateComponent.prototype.handleCancel = function () {
        this.nzModalRef.destroy();
    };
    IdentityRoleRolesUpdateComponent.prototype.handleOk = function () {
        var _this = this;
        if (this.formGroup.invalid) {
            return;
        }
        this.saving = true;
        var rolePermissions = new DEF.Identity.RolePermissions(this.formGroup.getRawValue());
        API.Identity.RoleController.UpdateRole(undefined, rolePermissions).subscribe(function () {
            _this.formGroup.reset();
            _this.saving = false;
            _this.nzModalRef.close(__assign(__assign({}, _this.record), rolePermissions));
        }, function () {
            _this.saving = false;
        });
    };
    IdentityRoleRolesUpdateComponent.prototype.ngOnInit = function () {
        this.formGroup.patchValue(this.record);
    };
    IdentityRoleRolesUpdateComponent.ctorParameters = function () { return [
        { type: NzModalRef }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", DEF.Identity.RolePermissions)
    ], IdentityRoleRolesUpdateComponent.prototype, "record", void 0);
    IdentityRoleRolesUpdateComponent = __decorate([
        Component({
            selector: 'kg---identity--role--roles--update',
            template: "<div class=\"modal-header\">\n  <div class=\"modal-title\">\n    {{ 'projects/fe-ng/src/lib/page/identity/role/roles/update/role-roles-update.update-role' | i18n }}\n  </div>\n</div>\n\n<form (ngSubmit)=\"handleOk()\" [formGroup]=\"formGroup\" [nzNoAnimation]=\"true\" nz-form nzLayout=\"vertical\">\n  <div [nzGutter]=\"12\" nz-row>\n    <div [nzMd]=\"12\" [nzSm]=\"24\" nz-col>\n      <nz-form-item>\n        <nz-form-label [nzFor]=\"'name'\"> {{ 'app__name' | i18n }}: </nz-form-label>\n        <nz-form-control>\n          <input [attr.id]=\"'name'\" [formControlName]=\"'name'\" nz-input />\n        </nz-form-control>\n      </nz-form-item>\n    </div>\n\n    <div [nzMd]=\"12\" [nzSm]=\"24\" nz-col>\n      <nz-form-item>\n        <nz-form-label [nzFor]=\"'showName'\" [nzRequired]=\"true\"> {{ 'app__display-name' | i18n }}: </nz-form-label>\n        <nz-form-control nzErrorTip=\"{{ 'projects/fe-ng/src/lib/page/identity/role/roles/create/role-roles-create.display-name-is-required' | i18n }}\">\n          <input [attr.id]=\"'showName'\" [formControlName]=\"'showName'\" nz-input />\n        </nz-form-control>\n      </nz-form-item>\n    </div>\n\n    <div [nzMd]=\"24\" [nzSm]=\"24\" nz-col>\n      <nz-form-item class=\"mb-sm\">\n        <nz-form-label [nzFor]=\"'description'\" [nzRequired]=\"true\"> {{ 'app__description' | i18n }}: </nz-form-label>\n        <nz-form-control nzErrorTip=\"{{ 'projects/fe-ng/src/lib/page/identity/role/roles/create/role-roles-create.description-is-required' | i18n }}\">\n          <textarea [attr.id]=\"'description'\" [formControlName]=\"'description'\" [rows]=\"3\" nz-input></textarea>\n        </nz-form-control>\n      </nz-form-item>\n    </div>\n  </div>\n\n  <button [hidden]=\"true\"></button>\n</form>\n\n<div class=\"modal-footer\">\n  <button (click)=\"handleCancel()\" [disabled]=\"saving\" [nzType]=\"'default'\" nz-button>\n    {{ 'app__cancel' | i18n }}\n  </button>\n  <button (click)=\"handleOk()\" [disabled]=\"!formGroup.valid || saving\" [nzLoading]=\"saving\" [nzType]=\"'primary'\" nz-button>\n    {{ 'app__save' | i18n }}\n  </button>\n</div>\n"
        }),
        __metadata("design:paramtypes", [NzModalRef])
    ], IdentityRoleRolesUpdateComponent);
    return IdentityRoleRolesUpdateComponent;
}());
export { IdentityRoleRolesUpdateComponent };
//# sourceMappingURL=data:application/json;base64, 