import { __assign, __decorate, __metadata } from "tslib";
import { Component } from '@angular/core';
import { PersistedGrantVO } from '../vo/persisted-grant.vo';
import { NzMessageService } from 'ng-zorro-antd/message';
import { TranslateService } from '@ngx-translate/core';
import { API } from '../../../api';
var IdentityPersistedGrantsComponent = /** @class */ (function () {
    function IdentityPersistedGrantsComponent(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.listParam = new API.Identity.PersistedGrantController.ListParam({
            pageIndex: 1,
            pageSize: 10,
        });
        this.persistedGrants = [];
        this.persistedGrantsFetching = false;
        this.persistedGrantsTotal = 0;
    }
    IdentityPersistedGrantsComponent.prototype.deletePersistedGrant = function (item) {
        var _this = this;
        item.deleting = true;
        API.Identity.PersistedGrantController.Remove({
            id: item.key,
        }).subscribe({
            next: function () {
                item.deleting = false;
                _this.nzMessageService.success(_this.translateService.instant('projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.delete_successfully'));
                _this.fetchPersistedGrants(true);
            },
            error: function () {
                item.deleting = false;
            },
        });
    };
    IdentityPersistedGrantsComponent.prototype.fetchPersistedGrants = function (fromStart) {
        var _this = this;
        if (fromStart === void 0) { fromStart = false; }
        if (fromStart) {
            this.listParam.pageIndex = 1;
        }
        this.persistedGrantsFetching = true;
        API.Identity.PersistedGrantController.List(__assign(__assign({}, this.listParam), { pageIndex: this.listParam.pageIndex === undefined ? 0 : this.listParam.pageIndex - 1 })).subscribe({
            next: function (_a) {
                var items = _a.items, total = _a.total;
                _this.persistedGrantsTotal = total;
                _this.persistedGrants = PersistedGrantVO.fromArray(items);
                _this.persistedGrantsFetching = false;
            },
            error: function () {
                _this.persistedGrantsFetching = false;
            },
        });
    };
    IdentityPersistedGrantsComponent.prototype.handlePageIndexChange = function (pageIndex) {
        this.listParam.pageIndex = pageIndex;
        this.fetchPersistedGrants();
    };
    IdentityPersistedGrantsComponent.prototype.handlePageSizeChange = function (pageSize) {
        this.listParam.pageSize = pageSize;
        this.fetchPersistedGrants(true);
    };
    IdentityPersistedGrantsComponent.prototype.ngOnInit = function () {
        this.fetchPersistedGrants(true);
    };
    IdentityPersistedGrantsComponent.ctorParameters = function () { return [
        { type: NzMessageService },
        { type: TranslateService }
    ]; };
    IdentityPersistedGrantsComponent = __decorate([
        Component({
            selector: 'kg---identity--persisted-grants',
            template: "<page-header title=\"\"></page-header>\n\n<nz-card\n  [ngStyle]=\"{\n    marginBottom: '0px',\n    height: 'calc(100% - 42px)'\n  }\"\n  [nzBodyStyle]=\"{\n    padding: '10px',\n    height: '100%'\n  }\"\n  [nzBordered]=\"false\"\n>\n  <div>\n    <button\n      (click)=\"fetchPersistedGrants(true)\"\n      [ngStyle]=\"{\n        float: 'left',\n        marginBottom: '10px'\n      }\"\n      [nzLoading]=\"persistedGrantsFetching\"\n      class=\"btn-outline-primary\"\n      nz-button\n    >\n      <i nz-icon nzTheme=\"outline\" nzType=\"reload\"></i>\n      {{ 'app__refresh' | i18n }}\n    </button>\n  </div>\n\n  <nz-table\n    #table\n    (nzPageIndexChange)=\"handlePageIndexChange($event)\"\n    (nzPageSizeChange)=\"handlePageSizeChange($event)\"\n    [className]=\"'table-responsive'\"\n    [ngStyle]=\"{ marginTop: '10px', clear: 'both' }\"\n    [nzData]=\"persistedGrants\"\n    [nzFrontPagination]=\"false\"\n    [nzLoadingIndicator]=\"loadingIndicatorTpl\"\n    [nzLoading]=\"persistedGrantsFetching\"\n    [nzPageIndex]=\"listParam.pageIndex\"\n    [nzPageSize]=\"listParam.pageSize\"\n    [nzScroll]=\"{ x: '1800px', y: 'auto' }\"\n    [nzShowQuickJumper]=\"true\"\n    [nzShowSizeChanger]=\"true\"\n    [nzShowTotal]=\"totalTpl\"\n    [nzTotal]=\"persistedGrantsTotal\"\n    [nzWidthConfig]=\"['160px', '300px', '200px', '140px', '160px', '200px', '300px', '140px', '200px']\"\n    nzSize=\"small\"\n  >\n    <thead>\n      <tr>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.creation_time' | i18n }}\n        </th>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.client_id' | i18n }}\n        </th>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.data' | i18n }}\n        </th>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.email' | i18n }}\n        </th>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.expiration' | i18n }}\n        </th>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.key' | i18n }}\n        </th>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.subject_id' | i18n }}\n        </th>\n        <th>\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.type' | i18n }}\n        </th>\n        <th [nzRight]=\"'0px'\" class=\"text-center\">{{ 'app__action' | i18n }}</th>\n      </tr>\n    </thead>\n\n    <tbody>\n      <ng-container *ngFor=\"let item of table.data\">\n        <tr>\n          <td>{{ item.creationTime | kgDate }}</td>\n\n          <td>{{ item.clientId }}</td>\n\n          <td>{{ item.data }}</td>\n\n          <td>{{ item.email }}</td>\n\n          <td>{{ item.expiration | kgDate }}</td>\n\n          <td>{{ item.key }}</td>\n\n          <td>{{ item.subjectId }}</td>\n\n          <td>{{ item.type }}</td>\n\n          <td [nzRight]=\"'0px'\" class=\"text-right\">\n            <button\n              (nzOnConfirm)=\"deletePersistedGrant(item)\"\n              [ngStyle]=\"{ height: '28px' }\"\n              [nzLoading]=\"item.deleting\"\n              [nzPopconfirmTitle]=\"'app__confirm_delete_message' | i18n\"\n              class=\"btn-outline-warning\"\n              nz-button\n              nz-popconfirm\n              nzPopconfirmPlacement=\"topRight\"\n              nzSize=\"small\"\n            >\n              <i nz-icon nzTheme=\"outline\" nzType=\"delete\"></i>\n              {{ 'app__delete' | i18n }}\n            </button>\n          </td>\n        </tr>\n      </ng-container>\n    </tbody>\n\n    <ng-template #loadingIndicatorTpl>\n      <i\n        [ngStyle]=\"{\n          fontSize: '24px',\n          marginTop: '10px'\n        }\"\n        nz-icon\n        nzTheme=\"outline\"\n        nzType=\"loading\"\n      ></i>\n    </ng-template>\n\n    <ng-template #totalTpl let-range=\"range\" let-total>\n      {{ 'app__st-page-total' | i18n: { total: total, 'range[0]': range[0], 'range[1]': range[1] } }}\n    </ng-template>\n  </nz-table>\n</nz-card>\n",
            styles: [":host ::ng-deep .ant-card{margin-bottom:10px}:host ::ng-deep .ant-card .ant-card-head{min-height:auto;padding:0 12px}:host ::ng-deep nz-table.table-responsive{height:calc(100% - 83px)}:host ::ng-deep nz-table.table-responsive .ant-table-placeholder{height:calc(100% - 90px)}:host ::ng-deep nz-table.table-responsive .ant-spin-nested-loading .ant-spin-container .ant-table .ant-table-content .ant-table-scroll .ant-table-body{height:calc(100% - 37px)!important}:host ::ng-deep nz-table.table-responsive.table-responsive.ant-table-empty .ant-spin-nested-loading .ant-spin-container .ant-table .ant-table-content .ant-table-scroll .ant-table-body{height:0!important}"]
        }),
        __metadata("design:paramtypes", [NzMessageService, TranslateService])
    ], IdentityPersistedGrantsComponent);
    return IdentityPersistedGrantsComponent;
}());
export { IdentityPersistedGrantsComponent };
//# sourceMappingURL=data:application/json;base64, 