import { r as registerInstance, h, H as Host } from './index-ecdfb761.js';
import { L as ListFetchState } from './list-fetch-state-e772aa74.js';
import { T as TextField } from './index-150b6a59.js';
import './data-model-88af49fc.js';
import './FieldGenerator-3ae403b2.js';
import './BaseField-0b01dc2c.js';

const damgaDomainLogsCss = "";

const DamgaDashboard = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.domains = ListFetchState.init();
    this.logs = 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 (h(Host, { class: "-container d-flex flex-grow-1 flex-column" }, 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 TextField('msg', 'Message'),
        new TextField('target-response-time', 'Duration'),
        new TextField('method', 'Method'),
        new TextField('path', 'Path'),
        new TextField('status-code', 'Status Code'),
        new 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;

export { DamgaDashboard as damga_domain_logs };
