import { DateField } from '@dvn/core/doldurma/src/fields/date';
import { TextField } from '@dvn/core/doldurma/src/fields/text';
import { ListFetchState } from '@dvn/core/models/list-fetch-state';
import { Component, h, Host, Prop, State } from '@stencil/core';
export class DamgaDomainList {
  constructor() {
    this.list = ListFetchState.init();
  }
  componentWillLoad() {
    this.fetchList();
  }
  async fetchList() {
    const { list } = this;
    this.list = this.list.beforeFetch();
    const response = await this.apiDamga.getDomains().catch(error => {
      this.list = list.afterFetchError(error);
    });
    if (!response)
      return;
    this.list = list.afterFetch(response, false);
  }
  render() {
    const { list } = this;
    return (h(Host, { class: "container d-flex flex-grow-1 flex-column" },
      h("dvn-list-view-table", { config: {
          actions: [
            {
              ui: {
                name: 'edit',
                buttonType: 'icon-button',
                iconName: 'uil uil-pen',
                view: 'flat',
              },
            },
            {
              ui: {
                name: 'delete',
                buttonType: 'icon-button',
                iconName: 'uil uil-trash',
                view: 'flat',
                tint: 'danger',
              },
            },
          ],
          fields: [
            { fieldId: 'domain' },
            { fieldId: '_created' },
          ]
        }, fields: [
          new TextField('domain', 'Domain').setInputType('url'),
          new DateField('_created', 'Creation Date'),
        ], items: (list.data || []).sort((a, b) => a.domain.localeCompare(b.domain)), isEndReached: list.isEndReached(), isProgressing: list.isPending, error: list.error ? 'Fetching list failed' : undefined, onRetry: () => this.fetchList(), scrollToFit: true })));
  }
  static get is() { return "damga-domain-list"; }
  static get properties() { return {
    "apiDamga": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DamgaApi",
        "resolved": "DamgaApi",
        "references": {
          "DamgaApi": {
            "location": "import",
            "path": "../../api/damga-api"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "list": {}
  }; }
}
