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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
  if (!privateMap.has(receiver)) {
    throw new TypeError("attempted to set private field on non-instance");
  }
  privateMap.set(receiver, value);
  return value;
};
var _url, _sameSite, _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';
export class ResourceCard {
  constructor() {
    this.row = false;
    this.headingLevel = 4;
    this.type = true;
    this.tags = true;
    this.author = true;
    this.description = true;
    _url.set(this, void 0);
    _sameSite.set(this, void 0);
    _defaults.set(this, {
      routing: {
        includeType: true,
        base: ''
      }
    });
    this.SameSiteCard = () => {
      const { CardContents } = this;
      return (h("a", Object.assign({ class: "contents-wrapper" }, href(__classPrivateFieldGet(this, _url), this.routing.router)),
        h(CardContents, null)));
    };
    this.ExternalCard = () => {
      const { CardContents } = this;
      return (h("a", { class: "contents-wrapper", href: __classPrivateFieldGet(this, _url), target: "_blank", rel: "noopener" },
        h(CardContents, null)));
    };
    this.CardContents = () => {
      const { title, description, type, tags, doc: { data: { hero_image } } } = this.prismicData;
      const hasDescriptors = this.type || (tags && this.tags);
      const authors = getAuthorsForPrismicDoc(this.prismicData.doc);
      const hasAuthors = this.author && authors.length > 0;
      return [
        h("div", { class: "image-wrapper" },
          h(PrismicResponsiveImage, { image: hero_image })),
        h("div", { class: "content" },
          hasDescriptors
            ? h("div", { class: "meta" },
              this.type
                ? h(Heading, { class: "type | ui-theme--editorial", level: 6 }, type)
                : null,
              tags && this.tags
                ? h("resource-meta", { class: "ui-theme--editorial", tags: tags })
                : null)
            : null,
          h(Heading, { class: "title | ui-theme--editorial", level: this.headingLevel }, title),
          this.description
            ? h(Paragraph, { class: "description" }, description)
            : null,
          hasAuthors
            ? h("div", { class: "author" },
              h("resource-author-item", { author: authors[0] }))
            : null)
      ];
    };
  }
  componentWillLoad() {
    if (!this.prismicData)
      return;
    this.routing = Object.assign(__classPrivateFieldGet(this, _defaults).routing, this.routing);
    __classPrivateFieldSet(this, _url, this.getUrl(this.prismicData.id));
  }
  getUrl(uid) {
    var _a;
    const { base, includeType } = this.routing;
    const type = resourceTypeToPath(this.prismicData.type);
    if ((_a = this.prismicData.doc.data.content_url) === null || _a === void 0 ? void 0 : _a.url) {
      return this.prismicData.doc.data.content_url.url;
    }
    if (base.includes('ionicframework.com/resources') && type === 'blog') {
      return `${base.replace('resources', 'blog')}/${uid}`;
    }
    __classPrivateFieldSet(this, _sameSite, !!this.routing.router);
    if (includeType) {
      return `${base}/${type}/${uid}`;
    }
    else {
      return `${base}/${uid}`;
    }
  }
  render() {
    if (!this.prismicData)
      return;
    const { SameSiteCard, ExternalCard } = this;
    return (h(Host, { class: {
        'row': this.row,
        'column': !this.row
      } }, __classPrivateFieldGet(this, _sameSite) ? h(SameSiteCard, null)
      : h(ExternalCard, null)));
  }
  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"
    },
    "type": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "type",
      "reflect": false,
      "defaultValue": "true"
    },
    "tags": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "tags",
      "reflect": false,
      "defaultValue": "true"
    },
    "author": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "author",
      "reflect": false,
      "defaultValue": "true"
    },
    "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": "unknown",
      "mutable": false,
      "complexType": {
        "original": "RoutingProps",
        "resolved": "RoutingProps",
        "references": {
          "RoutingProps": {
            "location": "local"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
}
_url = new WeakMap(), _sameSite = new WeakMap(), _defaults = new WeakMap();
