import { r as registerInstance, h, H as Host } from './index-acdc1ac0.js';
import './index-d9d18e9c.js';
import './data-model-bb5789f5.js';
import './BaseField-d94c5b14.js';
import './filter-cbaa3d7d.js';
import { I as ItemFetchState } from './item-fetch-state-3ee8988a.js';
import './filter-8542e288.js';
import { I as ItemDataProvider } from './data-provider-3b86770f.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) {
    registerInstance(this, hostRef);
    this.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 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 (h(Host, null, (!itemFetchState.isPending && !itemFetchState.error) &&
      h("dvn-card-view", { config: ui.cardConfig, fields: fields, item: item, cornerRadius: 0, leaned: true, overrideStyle: { width: '100%' } }), itemFetchState.isPending &&
      h("div", { class: "d-flex flex-grow-1 align-items-center justify-content-center detail-view-progress-container" }, h("dvn-progress", { indefinite: true, tint: "primary" })), itemFetchState.error &&
      h("div", { class: "d-flex flex-grow-1 align-items-center justify-content-center flex-column detail-view-progress-container" }, "Fetching data failed.", h("dvn-button", { onClick: () => this.itemDataProvider.fetchData(this.itemFetchState) }, "Retry"))));
  }
};
DvnAppViewDetailView.style = dvnAppViewDetailViewCss;

export { DvnAppViewDetailView as dvn_app_view_detail_view };
