import { __decorate, __metadata } from "tslib";
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { SecretVO } from '../../../vo/secret.vo';
import { API } from '../../../../../api';
let IdentityApiResourceUpdateSecretComponent = class IdentityApiResourceUpdateSecretComponent {
    constructor() {
        this.visible = false;
        this.visibleChange = new EventEmitter();
        this.apiResourceName = '';
        this.secrets = [];
        this.secretsFetching = false;
        this.identityApiResourceUpdateSecretCreateComponentProp = { visible: false };
    }
    fetchSecrets() {
        this.secretsFetching = true;
        API.Identity.ApiResourceController.Secrets({
            resource: this.apiResourceName,
        }).subscribe({
            next: data => {
                this.secrets = SecretVO.fromArray(data);
                this.secretsFetching = false;
            },
            error: () => {
                this.secretsFetching = false;
            },
        });
    }
    deleteSecret(item) {
        item.deleting = true;
        API.Identity.ApiResourceController.RemoveSecret(new API.Identity.ApiResourceController.RemoveSecretParam(Object.assign(Object.assign({}, item), { resource: this.apiResourceName }))).subscribe({
            next: () => {
                item.deleting = false;
                this.fetchSecrets();
            },
            error: () => {
                item.deleting = false;
            },
        });
    }
    openIdentityApiResourceUpdateSecretCreateComponent() {
        this.identityApiResourceUpdateSecretCreateComponentProp.visible = true;
    }
    handleIdentityApiResourceUpdateSecretCreateComponentOk() {
        this.fetchSecrets();
    }
    handleCancel() {
        this.visibleChange.emit(false);
    }
    handleAfterOpen() {
        this.fetchSecrets();
    }
};
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], IdentityApiResourceUpdateSecretComponent.prototype, "visible", void 0);
__decorate([
    Output(),
    __metadata("design:type", EventEmitter)
], IdentityApiResourceUpdateSecretComponent.prototype, "visibleChange", void 0);
__decorate([
    Input(),
    __metadata("design:type", String)
], IdentityApiResourceUpdateSecretComponent.prototype, "apiResourceName", void 0);
IdentityApiResourceUpdateSecretComponent = __decorate([
    Component({
        selector: 'kg---identity--api-resource--update--secret',
        template: "<nz-modal\r\n  (nzOnCancel)=\"handleCancel()\"\r\n  (nzAfterOpen)=\"handleAfterOpen()\"\r\n  [nzBodyStyle]=\"{\r\n    padding: '12px 16px 16px 16px'\r\n  }\"\r\n  [nzKeyboard]=\"false\"\r\n  [nzMaskClosable]=\"false\"\r\n  [nzTitle]=\"\r\n    'projects/fe-ng/src/lib/page/identity/api-resource/update/secret/identity--api-resource--update--secret.title'\r\n      | i18n\r\n  \"\r\n  [nzVisible]=\"visible\"\r\n  nzWidth=\"1198px\"\r\n>\r\n  <div>\r\n    <button\r\n      (click)=\"fetchSecrets()\"\r\n      [ngStyle]=\"{\r\n        float: 'left',\r\n        marginBottom: '10px'\r\n      }\"\r\n      [nzLoading]=\"secretsFetching\"\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)=\"openIdentityApiResourceUpdateSecretCreateComponent()\"\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    [ngStyle]=\"{ marginTop: '10px', clear: 'both' }\"\r\n    [nzData]=\"secrets\"\r\n    [nzFrontPagination]=\"false\"\r\n    [nzLoadingIndicator]=\"loadingIndicatorTpl\"\r\n    [nzLoading]=\"secretsFetching\"\r\n    [nzScroll]=\"{ x: '940px' }\"\r\n    [nzShowPagination]=\"false\"\r\n    [nzWidthConfig]=\"['260px', '160px', '160px', '260px', '100px']\"\r\n    nzSize=\"small\"\r\n  >\r\n    <thead>\r\n      <tr>\r\n        <th>{{ 'app.common.value' | i18n }}</th>\r\n        <th>\r\n          {{\r\n            'projects/fe-ng/src/lib/page/identity/api-resource/update/secret/identity--api-resource--update--secret.type'\r\n              | i18n\r\n          }}\r\n        </th>\r\n        <th>\r\n          {{\r\n            'projects/fe-ng/src/lib/page/identity/api-resource/update/secret/identity--api-resource--update--secret.expiration'\r\n              | i18n\r\n          }}\r\n        </th>\r\n        <th>{{ 'app.common.description' | i18n }}</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 [nzBreakWord]=\"true\">{{ item.value }}</td>\r\n\r\n          <td [nzBreakWord]=\"true\">{{ item.type }}</td>\r\n\r\n          <td [nzBreakWord]=\"true\">{{ item.expiration | kgDate }}</td>\r\n\r\n          <td [nzBreakWord]=\"true\">{{ item.description }}</td>\r\n\r\n          <td class=\"text-right\" [nzRight]=\"'0px'\">\r\n            <button\r\n              (nzOnConfirm)=\"deleteSecret(item)\"\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\r\n  <div *nzModalFooter>\r\n    <button (click)=\"handleCancel()\" nz-button nzType=\"default\">\r\n      <i nz-icon nzType=\"stop\" nzTheme=\"outline\"></i>\r\n      {{ 'app.common.cancel' | i18n }}\r\n    </button>\r\n  </div>\r\n</nz-modal>\r\n\r\n<kg---identity--api-resource--update--secret--create\r\n  (ok)=\"handleIdentityApiResourceUpdateSecretCreateComponentOk()\"\r\n  [(visible)]=\"identityApiResourceUpdateSecretCreateComponentProp.visible\"\r\n  [apiResourceName]=\"apiResourceName\"\r\n></kg---identity--api-resource--update--secret--create>\r\n"
    })
], IdentityApiResourceUpdateSecretComponent);
export { IdentityApiResourceUpdateSecretComponent };
//# sourceMappingURL=data:application/json;base64, 