import { r as registerInstance, h, H as Host } from './index-ecdfb761.js';
import { I as ItemDataProvider } from './data-provider-d3b64335.js';
import { I as ItemFetchState } from './item-fetch-state-610938e5.js';
import './data-model-f7ccf826.js';
import './filter-cbaa3d7d.js';
import './filter-8542e288.js';

const dvnAppViewDetailViewCardDefault = {
  seeMore: 'See More',
};

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

const DvnAppViewDetailViewCard = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.showInfoDetailDialog = false;
    this.itemFetchState = ItemFetchState.init();
  }
  async componentWillLoad() {
    this.strings = await this.apiSozluk.getContent(this.view.i18nEntryId, dvnAppViewDetailViewCardDefault);
    const { apiData, params, view } = this;
    const { query, table } = view;
    const fields = (query === null || query === void 0 ? void 0 : query.fields) || view.table.fields;
    // itemDataProvider must be generated even though the params.item exists
    // invalidate() function needs it to fetch the fresh data
    this.itemDataProvider = new ItemDataProvider(apiData, params, table, query, fields, (itemFetchState) => {
      this.itemFetchState = itemFetchState;
    });
    if (params === null || params === void 0 ? void 0 : params.item) {
      return;
    }
    this.itemDataProvider.fetchData(this.itemFetchState);
  }
  // needed for invalidation
  componentDidUpdate() {
    const { params, itemFetchState } = this;
    if (params === null || params === void 0 ? void 0 : params.item) {
      return;
    }
    if (!itemFetchState.data && !itemFetchState.isPending && !itemFetchState.error) {
      this.itemDataProvider.fetchData(this.itemFetchState);
    }
  }
  async invalidate(_event) {
    this.itemDataProvider.fetchData(this.itemFetchState);
  }
  ;
  onAction(event) {
    const action = event.detail;
    if (action.name === 'open-dvn-card-view-detail-view') {
      event.preventDefault();
      this.showInfoDetailDialog = true;
    }
  }
  render() {
    var _a, _b, _c;
    const { itemFetchState, showInfoDetailDialog, view } = this;
    const { ui } = view;
    const fields = view.table.fields;
    const item = ((_a = this.params) === null || _a === void 0 ? void 0 : _a.item) || itemFetchState.data;
    return (h(Host, null, (!itemFetchState.isPending && !itemFetchState.error) &&
      (!ui.summaryCardConfig
        ? h("dvn-card-view", { key: `card-view-${item._id}`, config: ui.cardConfig, fields: fields, item: item, cornerRadius: ui.cardCornerRadius, leaned: true, overrideStyle: { width: '100%' } })
        : h("dvn-card-view", { key: `summary-card-view-${item._id}`, config: Object.assign(Object.assign({}, ui.summaryCardConfig), { footer: Object.assign(Object.assign({}, (ui.summaryCardConfig.footer || {})), { actions: [
                ...(((_c = (_b = ui.summaryCardConfig) === null || _b === void 0 ? void 0 : _b.footer) === null || _c === void 0 ? void 0 : _c.actions) || []),
                {
                  ui: {
                    label: this.strings.seeMore,
                    name: 'open-dvn-card-view-detail-view',
                    view: 'flat'
                  }
                }
              ] }) }), fields: fields, item: item, cornerRadius: ui.cardCornerRadius, 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")), showInfoDetailDialog &&
      h("dvn-dialog", { shown: this.showInfoDetailDialog, onDismiss: () => this.showInfoDetailDialog = false, raw: true }, h("dvn-card-view", { key: `detail-card-view-${item._id}`, config: ui.cardConfig, fields: fields, item: item, cornerRadius: ui.cardCornerRadius, leaned: true, overrideStyle: { width: '100%' } }))));
  }
};
DvnAppViewDetailViewCard.style = dvnAppViewDetailViewCardCss;

export { DvnAppViewDetailViewCard as dvn_app_view_detail_view_card };
