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