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.clients = [];
        this.clientsFetching = false;
        this.identityClientsCreateComponentProp = {
            visible: false,
        };
        this.identityClientsUpdateComponentProp = {
            visible: false,
            client: new ClientVO(),
        };
    }
    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;
            },
        });
    }
    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;
            },
        });
    }
    fetchClients() {
        this.clientsFetching = true;
        API.Identity.ClientController.ListClients().subscribe({
            next: (data) => {
                this.clients = ClientVO.fromArray(data);
                this.clientsFetching = false;
            },
            error: () => {
                this.clientsFetching = false;
            },
        });
    }
    handleIdentityClientsCreateComponentOk() {
        this.fetchClients();
    }
    handleIdentityClientsUpdateComponentOk() {
        this.fetchClients();
    }
    ngOnInit() {
        this.fetchClients();
    }
    openIdentityClientsCreateComponent() {
        this.identityClientsCreateComponentProp.visible = true;
    }
    openIdentityClientsUpdateComponent(item) {
        this.identityClientsUpdateComponentProp.client = item;
        this.identityClientsUpdateComponentProp.visible = true;
    }
};
IdentityClientsComponent.ctorParameters = () => [
    { type: NzMessageService },
    { type: TranslateService }
];
IdentityClientsComponent = __decorate([
    Component({
        selector: 'kg---identity--clients',
        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)=\"fetchClients()\"\n      [ngStyle]=\"{\n        float: 'left',\n        marginBottom: '10px'\n      }\"\n      [nzLoading]=\"clientsFetching\"\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\n    <button\n      (click)=\"openIdentityClientsCreateComponent()\"\n      [disabled]=\"clientsFetching\"\n      [ngStyle]=\"{\n        float: 'left',\n        marginBottom: '10px'\n      }\"\n      nz-button\n      nzType=\"primary\"\n    >\n      <i nz-icon nzTheme=\"outline\" nzType=\"plus-circle\"></i>\n      {{ 'app__create' | i18n }}\n    </button>\n  </div>\n\n  <nz-table\n    #table\n    [className]=\"'table-responsive'\"\n    [ngStyle]=\"{ marginTop: '10px', clear: 'both' }\"\n    [nzData]=\"clients\"\n    [nzFrontPagination]=\"false\"\n    [nzLoadingIndicator]=\"loadingIndicatorTpl\"\n    [nzLoading]=\"clientsFetching\"\n    [nzScroll]=\"{ x: '840px', y: 'auto' }\"\n    [nzShowPagination]=\"false\"\n    [nzWidthConfig]=\"['80px', '200px', '200px', '80px', '280px']\"\n    nzSize=\"small\"\n  >\n    <thead>\n      <tr>\n        <th>{{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.logo' | i18n }}</th>\n        <th>{{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.client_id' | i18n }}</th>\n        <th>{{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.client_name' | i18n }}</th>\n        <th class=\"text-center\">\n          {{ 'projects/fe-ng/src/lib/page/identity/clients/identity--clients.enabled' | 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>\n            <img\n              *ngIf=\"item.logoUri\"\n              [ngStyle]=\"{\n                width: '28px',\n                height: '28px',\n                borderRadius: '2px'\n              }\"\n              [src]=\"item.logoUri\"\n            />\n          </td>\n\n          <td [nzBreakWord]=\"true\">{{ item.clientId }}</td>\n\n          <td [nzBreakWord]=\"true\">{{ item.clientName }}</td>\n\n          <td class=\"text-center\">\n            <kg--yes-or-no [value]=\"item.enabled\"></kg--yes-or-no>\n          </td>\n\n          <td [nzRight]=\"'0px'\" class=\"text-right\">\n            <button\n              (nzOnConfirm)=\"copyClient(item)\"\n              [disabled]=\"item.deleting\"\n              [ngStyle]=\"{ height: '28px' }\"\n              [nzLoading]=\"item.copying\"\n              [nzPopconfirmTitle]=\"'projects/fe-ng/src/lib/page/identity/clients/identity--clients.confirm_copy' | i18n\"\n              class=\"btn-outline-primary\"\n              nz-button\n              nz-popconfirm\n              nzPopconfirmPlacement=\"topRight\"\n              nzSize=\"small\"\n            >\n              <i nz-icon nzTheme=\"outline\" nzType=\"copy\"></i>\n              {{ 'app__copy' | i18n }}\n            </button>\n\n            <button\n              (click)=\"openIdentityClientsUpdateComponent(item)\"\n              [disabled]=\"item.deleting || item.copying\"\n              [ngStyle]=\"{ height: '28px' }\"\n              class=\"btn-outline-primary\"\n              nz-button\n              nzSize=\"small\"\n            >\n              <i nz-icon nzTheme=\"outline\" nzType=\"form\"></i>\n              {{ 'app__update' | i18n }}\n            </button>\n\n            <button\n              (nzOnConfirm)=\"deleteClient(item)\"\n              [disabled]=\"item.copying\"\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  </nz-table>\n</nz-card>\n\n<kg---identity--clients--create\n  (ok)=\"handleIdentityClientsCreateComponentOk()\"\n  [(visible)]=\"identityClientsCreateComponentProp.visible\"\n></kg---identity--clients--create>\n\n<kg---identity--clients--update\n  (ok)=\"handleIdentityClientsUpdateComponentOk()\"\n  [(visible)]=\"identityClientsUpdateComponentProp.visible\"\n  [client]=\"identityClientsUpdateComponentProp.client\"\n></kg---identity--clients--update>\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, 