'use strict';

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

const index = require('./index-7cdf1df1.js');
require('./index-c2a077ae.js');
require('./data-model-f9df493f.js');
require('./BaseField-f50bb8f0.js');
require('./filter-52876f3c.js');
const itemFetchState = require('./item-fetch-state-18978ab4.js');
require('./filter-a24b968a.js');
const dataProvider = require('./data-provider-66807db9.js');

const dvnAppViewDetailViewCss = ".sc-dvn-app-view-detail-view-h{display:flex;flex:1;align-items:stretch;max-width:100%}.detail-view-progress-container.sc-dvn-app-view-detail-view{padding:calc(4 * var(--spacing-unit))}";

const DvnAppViewDetailView = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.itemFetchState = itemFetchState.ItemFetchState.init();
  }
  componentWillLoad() {
    const { apiData, params, view } = this;
    const { query, table, ui } = view;
    const fields = (query === null || query === void 0 ? void 0 : query.fields) || ui.fields || view.table.fields;
    this.itemDataProvider = new dataProvider.ItemDataProvider(apiData, params, table, query, fields, (itemFetchState) => {
      this.itemFetchState = itemFetchState;
    });
    this.itemDataProvider.fetchData(this.itemFetchState);
  }
  // needed for invalidation
  componentDidUpdate() {
    const { itemFetchState } = this;
    if (!itemFetchState.data && !itemFetchState.isPending && !itemFetchState.error) {
      this.itemDataProvider.fetchData(this.itemFetchState);
    }
  }
  async invalidate(_event) {
    this.itemDataProvider.fetchData(this.itemFetchState);
  }
  ;
  render() {
    const { itemFetchState, view } = this;
    const { ui } = view;
    const fields = ui.fields || view.table.fields;
    const item = itemFetchState.data;
    return (index.h(index.Host, null, (!itemFetchState.isPending && !itemFetchState.error) &&
      index.h("dvn-card-view", { config: ui.cardConfig, fields: fields, item: item, cornerRadius: 0, leaned: true, overrideStyle: { width: '100%' } }), itemFetchState.isPending &&
      index.h("div", { class: "d-flex flex-grow-1 align-items-center justify-content-center detail-view-progress-container" }, index.h("dvn-progress", { indefinite: true, tint: "primary" })), itemFetchState.error &&
      index.h("div", { class: "d-flex flex-grow-1 align-items-center justify-content-center flex-column detail-view-progress-container" }, "Fetching data failed.", index.h("dvn-button", { onClick: () => this.itemDataProvider.fetchData(this.itemFetchState) }, "Retry"))));
  }
};
DvnAppViewDetailView.style = dvnAppViewDetailViewCss;

exports.dvn_app_view_detail_view = DvnAppViewDetailView;
