var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
  if (!privateMap.has(receiver)) {
    throw new TypeError("attempted to get private field on non-instance");
  }
  return privateMap.get(receiver);
};
var _defaults;
import { Component, h, Host, Prop } from '@stencil/core';
import { Heading, Paragraph } from '../../core';
import { PrismicResponsiveImage } from '../../web/components/prismic/PrismicResponsiveImage';
import { getAuthorsForPrismicDoc } from '../../web/utils/prismic/prismic';
import { href } from 'stencil-router-v2';
import { resourceTypeToPath } from '../../web/utils/prismic/data';
import { isString } from '../../core/utils/tools';
export class ResourceCard {
  constructor() {
    this.row = false;
    this.headingLevel = 4;
    this.description = true;
    _defaults.set(this, {
      routing: {
        includeType: true,
        base: ''
      }
    });
  }
  componentWillLoad() {
    if (!isString(this.routing))
      this.routing = Object.assign(__classPrivateFieldGet(this, _defaults).routing, this.routing);
  }
  getUrl(id) {
    var _a;
    if (!this.routing)
      return (_a = this.prismicData.doc.data.content_url) === null || _a === void 0 ? void 0 : _a.url;
    if (isString(this.routing))
      return this.routing;
    const { base, includeType } = this.routing;
    const type = resourceTypeToPath(this.prismicData.type);
    if (includeType) {
      return `${base}/${type}/${id}`;
    }
    else {
      return `${base}/${id}`;
    }
  }
  render() {
    if (!this.prismicData)
      return;
    const { title, description, type, tags, id } = this.prismicData;
    const { hero_image } = this.prismicData.doc.data;
    const authors = getAuthorsForPrismicDoc(this.prismicData.doc);
    let url = this.getUrl(id);
    return (h(Host, { class: {
        'row': this.row,
      } },
      h("div", null, isString(this.routing)
        ? h("a", { class: "image-wrapper", href: url, target: "_blank", rel: "noopener nofollow" },
          h(PrismicResponsiveImage, { image: hero_image }))
        : h("a", Object.assign({ class: "image-wrapper" }, href(url, this.routing.router)),
          h(PrismicResponsiveImage, { image: hero_image }))),
      h("div", { class: "content" },
        h("div", { class: "meta" },
          h(Heading, { class: "type | ui-theme--editorial", level: 6 }, type),
          tags
            ? h("resource-meta", { class: "ui-theme--editorial", tags: tags }) : ''),
        isString(this.routing)
          ? h("a", { href: url, target: "_blank", rel: "noopener nofollow" },
            h(Heading, { class: "title | ui-theme--editorial", level: this.headingLevel }, title))
          : h("a", Object.assign({}, href(url, this.routing.router)),
            h(Heading, { class: "title | ui-theme--editorial", level: this.headingLevel }, title)),
        this.description
          ? h(Paragraph, { class: "description" }, description) : '',
        authors
          ? h("div", { class: "author" },
            h("resource-author-item", { author: authors[0] })) : '')));
  }
  static get is() { return "resource-card"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["resource-card.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["resource-card.css"]
  }; }
  static get properties() { return {
    "prismicData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "PrismicResource",
        "resolved": "PrismicResource",
        "references": {
          "PrismicResource": {
            "location": "import",
            "path": "../../web/models"
          }
        }
      },
      "required": true,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "row": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "row",
      "reflect": false,
      "defaultValue": "false"
    },
    "headingLevel": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "1 | 2 | 3 | 4 | 5 | 6",
        "resolved": "1 | 2 | 3 | 4 | 5 | 6",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "heading-level",
      "reflect": false,
      "defaultValue": "4"
    },
    "description": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "description",
      "reflect": false,
      "defaultValue": "true"
    },
    "routing": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "RoutingProps | string",
        "resolved": "RoutingProps | string",
        "references": {
          "RoutingProps": {
            "location": "local"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "routing",
      "reflect": false
    }
  }; }
}
_defaults = new WeakMap();
