import { Component, h, Host, Prop } from '@stencil/core';
const renderReference = (field, data, meta) => {
  var _a;
  const imageSrc = field.imageField ? data[field.imageField] : undefined;
  const initialLetters = field.titleField
    ? (_a = data[field.titleField]) === null || _a === void 0 ? void 0 : _a.split(' ').map(word => word[0]).join('') : undefined;
  const title = data[field.titleField];
  if (meta.showTitle) {
    return (h("dvn-info-summary", { title: title, leaned: true },
      h("dvn-image", { slot: "media", bordered: true, leaned: true, src: imageSrc, text: initialLetters })));
  }
  return (h("abbr", { title: title, style: { border: 'none', textDecoration: 'none' } },
    h("dvn-image", { bordered: true, src: imageSrc, text: initialLetters })));
};
export class DvnFieldDisplayReference {
  constructor() {
    this.meta = {};
  }
  render() {
    const { field, meta } = this;
    const value = this.value || [];
    return (h(Host, null, Array.isArray(value)
      ? value.map(data => renderReference(field, data, meta))
      : renderReference(field, value, meta)));
  }
  static get is() { return "dvn-field-display-reference"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-field-display-reference.css"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-field-display-reference.css"]
  }; }
  static get properties() { return {
    "value": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "any[]",
        "resolved": "any[]",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "field": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "ReferenceField",
        "resolved": "ReferenceField",
        "references": {
          "ReferenceField": {
            "location": "import",
            "path": "../reference-field"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "meta": {
      "type": "any",
      "mutable": false,
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "meta",
      "reflect": false,
      "defaultValue": "{}"
    }
  }; }
}
