import { __decorate, __metadata } from "tslib";
import { Component } from '@angular/core';
import { ClientVO } from '../vo/client.vo';
import { API } from '../../../api';
import { NzMessageService } from 'ng-zorro-antd/message';
import { TranslateService } from '@ngx-translate/core';
let IdentityClientsComponent = class IdentityClientsComponent {
    constructor(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.clientsFetching = false;
        this.clients = [];
        this.identityClientsCreateComponentProp = {
            visible: false,
        };
        this.identityClientsUpdateComponentProp = {
            visible: false,
            client: new ClientVO(),
        };
    }
    ngOnInit() {
        this.fetchClients();
    }
    openIdentityClientsCreateComponent() {
        this.identityClientsCreateComponentProp.visible = true;
    }
    openIdentityClientsUpdateComponent(item) {
        this.identityClientsUpdateComponentProp.client = item;
        this.identityClientsUpdateComponentProp.visible = true;
    }
    handleIdentityClientsCreateComponentOk() {
        this.fetchClients();
    }
    handleIdentityClientsUpdateComponentOk() {
        this.fetchClients();
    }
    fetchClients() {
        this.clientsFetching = true;
        API.Identity.ClientController.ListClients().subscribe({
            next: data => {
                this.clients = ClientVO.fromArray(data);
                this.clientsFetching = false;
            },
            error: () => {
                this.clientsFetching = false;
            },
        });
    }
    deleteClient(item) {
        item.deleting = true;
        API.Identity.ClientController.Delete({
            client: item.clientId,
        }).subscribe({
            next: () => {
                item.deleting = false;
                this.nzMessageService.success(this.translateService.instant('projects/fe-ng/src/lib/page/identity/clients/identity--clients.delete_successfully'));
                this.fetchClients();
            },
            error: () => {
                item.deleting = false;
            },
        });
    }
    copyClient(item) {
        item.copying = true;
        API.Identity.ClientController.Copy({
            clientId: item.clientId,
        }).subscribe({
            next: () => {
                item.copying = false;
                this.nzMessageService.success(this.translateService.instant('projects/fe-ng/src/lib/page/identity/clients/identity--clients.copy_successfully'));
                this.fetchClients();
            },
            error: () => {
                item.copying = false;
            },
        });
    }
};
IdentityClientsComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
IdentityClientsComponent = __decorate([
    Component({
        selector: 'kg---identity--clients',
        template: "<page-header title=\"\"></page-header>\r\n\r\n<nz-card\r\n  [ngStyle]=\"{\r\n    marginBottom: '0px',\r\n    height: 'calc(100% - 42px)'\r\n  }\"\r\n  [nzBodyStyle]=\"{\r\n    padding: '10px',\r\n    height: '100%'\r\n  }\"\r\n  [nzBordered]=\"false\"\r\n>\r\n  <div>\r\n    <button\r\n      (click)=\"fetchClients()\"\r\n      [ngStyle]=\"{\r\n        float: 'left',\r\n        marginBottom: '10px'\r\n      }\"\r\n      [nzLoading]=\"clientsFetching\"\r\n      class=\"btn-outline-primary\"\r\n      nz-button\r\n    >\r\n      <i nz-icon nzType=\"reload\" nzTheme=\"outline\"></i>\r\n      {{ 'app.common.refresh' | i18n }}\r\n    </button>\r\n\r\n    <button\r\n      (click)=\"openIdentityClientsCreateComponent()\"\r\n      [disabled]=\"clientsFetching\"\r\n      [ngStyle]=\"{\r\n        float: 'left',\r\n        marginBottom: '10px'\r\n      }\"\r\n      nz-button\r\n      nzType=\"primary\"\r\n    >\r\n      <i nz-icon nzType=\"plus-circle\" nzTheme=\"outline\"></i>\r\n      {{ 'app.common.create' | i18n }}\r\n    </button>\r\n  </div>\r\n\r\n  <nz-table\r\n    #table\r\n    [className]=\"'table-responsive'\"\r\n    [ngStyle]=\"{ marginTop: '10px', clear: 'both' }\"\r\n    [nzData]=\"clients\"\r\n    [nzFrontPagination]=\"false\"\r\n    [nzLoadingIndicator]=\"loadingIndicatorTpl\"\r\n    [nzLoading]=\"clientsFetching\"\r\n    [nzScroll]=\"{ x: '840px', y: 'auto' }\"\r\n    [nzShowPagination]=\"false\"\r\n    [nzWidthConfig]=\"['80px', '200px', '200px', '80px', '280px']\"\r\n    nzSize=\"small\"\r\n  >\r\n    <thead>\r\n      <tr>\r\n        <th>{{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.logo' | i18n }}</th>\r\n        <th>{{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.client_id' | i18n }}</th>\r\n        <th>{{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.client_name' | i18n }}</th>\r\n        <th class=\"text-center\">\r\n          {{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.enabled' | i18n }}\r\n        </th>\r\n        <th [nzRight]=\"'0px'\" class=\"text-center\">{{ 'app.common.action' | i18n }}</th>\r\n      </tr>\r\n    </thead>\r\n\r\n    <tbody>\r\n      <ng-container *ngFor=\"let item of table.data\">\r\n        <tr>\r\n          <td>\r\n            <img\r\n              *ngIf=\"item.logoUri\"\r\n              [ngStyle]=\"{\r\n                width: '28px',\r\n                height: '28px',\r\n                borderRadius: '2px'\r\n              }\"\r\n              [src]=\"item.logoUri\"\r\n            />\r\n          </td>\r\n\r\n          <td [nzBreakWord]=\"true\">{{ item.clientId }}</td>\r\n\r\n          <td [nzBreakWord]=\"true\">{{ item.clientName }}</td>\r\n\r\n          <td class=\"text-center\">\r\n            <kg--yes-or-no [value]=\"item.enabled\"></kg--yes-or-no>\r\n          </td>\r\n\r\n          <td class=\"text-right\" [nzRight]=\"'0px'\">\r\n            <button\r\n              (nzOnConfirm)=\"copyClient(item)\"\r\n              [disabled]=\"item.deleting\"\r\n              [ngStyle]=\"{ height: '28px' }\"\r\n              [nzLoading]=\"item.copying\"\r\n              [nzPopconfirmTitle]=\"'projects/fe-ng/src/lib/page/identity/clients/identity--clients.confirm_copy' | i18n\"\r\n              class=\"btn-outline-primary\"\r\n              nz-button\r\n              nz-popconfirm\r\n              nzPopconfirmPlacement=\"topRight\"\r\n              nzSize=\"small\"\r\n            >\r\n              <i nz-icon nzTheme=\"outline\" nzType=\"copy\"></i>\r\n              {{ 'app.common.copy' | i18n }}\r\n            </button>\r\n\r\n            <button\r\n              (click)=\"openIdentityClientsUpdateComponent(item)\"\r\n              [disabled]=\"item.deleting || item.copying\"\r\n              [ngStyle]=\"{ height: '28px' }\"\r\n              class=\"btn-outline-primary\"\r\n              nz-button\r\n              nzSize=\"small\"\r\n            >\r\n              <i nz-icon nzType=\"form\" nzTheme=\"outline\"></i>\r\n              {{ 'app.common.update' | i18n }}\r\n            </button>\r\n\r\n            <button\r\n              (nzOnConfirm)=\"deleteClient(item)\"\r\n              [disabled]=\"item.copying\"\r\n              [ngStyle]=\"{ height: '28px' }\"\r\n              [nzLoading]=\"item.deleting\"\r\n              [nzPopconfirmTitle]=\"'app.common.confirm-deletion' | i18n\"\r\n              class=\"btn-outline-warning\"\r\n              nz-button\r\n              nz-popconfirm\r\n              nzPopconfirmPlacement=\"topRight\"\r\n              nzSize=\"small\"\r\n            >\r\n              <i nz-icon nzType=\"delete\" nzTheme=\"outline\"></i>\r\n              {{ 'app.common.delete' | i18n }}\r\n            </button>\r\n          </td>\r\n        </tr>\r\n      </ng-container>\r\n    </tbody>\r\n\r\n    <ng-template #loadingIndicatorTpl>\r\n      <i\r\n        [ngStyle]=\"{\r\n          fontSize: '24px',\r\n          marginTop: '10px'\r\n        }\"\r\n        nz-icon\r\n        nzTheme=\"outline\"\r\n        nzType=\"loading\"\r\n      ></i>\r\n    </ng-template>\r\n  </nz-table>\r\n</nz-card>\r\n\r\n<kg---identity--clients--create\r\n  (ok)=\"handleIdentityClientsCreateComponentOk()\"\r\n  [(visible)]=\"identityClientsCreateComponentProp.visible\"\r\n></kg---identity--clients--create>\r\n\r\n<kg---identity--clients--update\r\n  (ok)=\"handleIdentityClientsUpdateComponentOk()\"\r\n  [(visible)]=\"identityClientsUpdateComponentProp.visible\"\r\n  [client]=\"identityClientsUpdateComponentProp.client\"\r\n></kg---identity--clients--update>\r\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% - 42px)}: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}"]
    }),
    __metadata("design:paramtypes", [NzMessageService, TranslateService])
], IdentityClientsComponent);
export { IdentityClientsComponent };
//# sourceMappingURL=data:application/json;base64, 