'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-1141a245.js');
const listFetchState = require('./list-fetch-state-a9e880b1.js');
const index$1 = require('./index-61f9621a.js');
require('./data-model-9afb7f54.js');
require('./FieldGenerator-279a646b.js');
require('./BaseField-381327a9.js');

const damgaDomainLogsCss = "";

const DamgaDashboard = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.domains = listFetchState.ListFetchState.init();
    this.logs = listFetchState.ListFetchState.init();
    this.relativeTime = 30;
    this.startDate = undefined;
    this.endDate = undefined;
  }
  componentWillLoad() {
    this.endDate = new Date();
    this.startDate = new Date(new Date().getTime() - (this.relativeTime * 60 * 1000));
    this.fetchList();
  }
  async fetchList() {
    // const { domains } = this;
    //
    // this.domains = this.domains.beforeFetch();
    // const response = await this.apiDamga.getDomains().catch(error => {
    //   this.domains = domains.afterFetchError(error);
    // });
    // if (!response) return;
    // this.domains = domains.afterFetch(response, false);
    // this.domains.data.sort((a, b) => a.domain.localeCompare(b.domain))
    // this.selectedDomain = this.domains.data?.at(0)?.domain;
    this.selectedDomain = 'api.mentornity.com';
    this.fetchLogs();
  }
  async fetchLogs() {
    const { logs, endDate, startDate } = this;
    this.logs = this.logs.beforeFetch();
    const response = await this.apiServicesDamga.getLogs(this.selectedDomain, startDate, endDate).catch(error => {
      this.logs = logs.afterFetchError(error);
    });
    if (!response)
      return;
    this.logs = logs.afterFetch(response);
  }
  render() {
    const { logs } = this;
    // const items = (logs.data || []).sort((a, b) => a.path.localeCompare(b.path));
    const items = (logs.data || []);
    return (index.h(index.Host, { class: "-container d-flex flex-grow-1 flex-column" }, index.h("dvn-list-view-table", { config: {
        fields: [
          { fieldId: 'msg' },
          { fieldId: 'target-response-time' },
          { fieldId: 'method' },
          { fieldId: 'path' },
          { fieldId: 'status-code' },
          { fieldId: 'time' },
        ],
        columns: {
          'msg': { width: 200 },
          'target-response-time': { width: 100 },
          'method': { width: 100 },
          'path': { weight: 1 },
          'status-code': { width: 100 },
          'time': { width: 200 },
        }
      }, fields: [
        new index$1.TextField('msg', 'Message'),
        new index$1.TextField('target-response-time', 'Duration'),
        new index$1.TextField('method', 'Method'),
        new index$1.TextField('path', 'Path'),
        new index$1.TextField('status-code', 'Status Code'),
        new index$1.TextField('time', 'Time'),
      ], items: items, isEndReached: logs.isEndReached(), isProgressing: logs.isPending, error: logs.error ? 'Fetching list failed' : undefined, onRetry: () => this.fetchLogs(),
      // params={this.params}
      scrollToFit: true })));
  }
};
DamgaDashboard.style = damgaDomainLogsCss;

exports.damga_domain_logs = DamgaDashboard;
