'use strict';

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

const index = require('./index-ce58ddc5.js');
const dataProvider = require('./data-provider-d86d3bcf.js');
const itemFetchState = require('./item-fetch-state-0a5bc42a.js');
require('./data-model-9afb7f54.js');
require('./filter-d5040f65.js');
require('./filter-a24b968a.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))}";

let DvnAppViewDetailViewCard = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.showInfoDetailDialog = false;
    this.itemFetchState = 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 dataProvider.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 (index.h(index.Host, null, (!itemFetchState.isPending && !itemFetchState.error) &&
      (!ui.summaryCardConfig
        ? index.h("dvn-card-view", { key: `card-view-${item._id}`, config: ui.cardConfig, fields: fields, item: item, cornerRadius: ui.cardCornerRadius, leaned: true, overrideStyle: { width: '100%' } })
        : index.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 &&
      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")), showInfoDetailDialog &&
      index.h("dvn-dialog", { shown: this.showInfoDetailDialog, onDismiss: () => this.showInfoDetailDialog = false, raw: true }, index.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;

exports.dvn_app_view_detail_view_card = DvnAppViewDetailViewCard;
