'use strict';

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

const index = require('./index-bb72bde3.js');
require('./common-a086c7ac.js');
const Col = require('./Col-1452580d.js');
const Grid = require('./Grid-d43e9218.js');
require('./IntersectionHelper-16aa1ea1.js');
require('./_commonjsHelpers-2e75ad90.js');
const prismicJavascript_min = require('./prismic-javascript.min-7ccc1fcb.js');
const prismic = require('./prismic-b998d186.js');

const apiEndpoint = 'https://ionicframeworkcom.prismic.io/api/v2';
// Client method to query documents from the Prismic repo
const Client = (req = null) => prismicJavascript_min.Prismic.client(apiEndpoint, createClientOptions(req, null));
const createClientOptions = (req = null, prismicAccessToken = null) => {
  const reqOption = req ? { req } : {};
  const accessTokenOption = prismicAccessToken ? { accessToken: prismicAccessToken } : {};
  return Object.assign(Object.assign({}, reqOption), accessTokenOption);
};

const moreResourcesCss = ".sc-more-resources-h{display:block;--column-gap:var(--space-6);--row-gap:var(--space-9)}.ui-grid.sc-more-resources{column-gap:var(--column-gap);row-gap:var(--row-gap)}@media screen and (max-width: 640px){.ui-grid.sc-more-resources{column-gap:0}}.ui-grid.size-2.sc-more-resources resource-card.sc-more-resources{--image-height:128px}";

const MoreResources = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  async componentWillLoad() {
    if (this.resources)
      return;
    const client = Client();
    const requests = this.resourceData.map(r => client.getByUID(r.type, r.uid, null));
    try {
      this.resources = (await Promise.all(requests)).map(d => prismic.prismicDocToResource(d));
    }
    catch (e) {
      console.error('Unable to load more resources', e);
    }
  }
  render() {
    const { headingLevel, type, tags, description, author } = this;
    const data = { headingLevel, type, tags, description, author };
    let props = {
      xs: 12,
      cols: 12
    };
    switch (this.resources.length) {
      case 2:
        props = Object.assign(Object.assign({}, props), { md: 6, sm: 6 });
        break;
      case 3:
        props = Object.assign(Object.assign({}, props), { md: 4, xs: 6 });
        break;
    }
    return (index.h(Grid.Grid, { class: `size-${this.resources.length}` }, this.resources.map((d, i) => (index.h(Col.Col, Object.assign({}, props, { cols: 12, key: d.id }), index.h("resource-card", Object.assign({ prismicData: d, routing: Array.isArray(this.routing) ? this.routing[i] : this.routing }, data)))))));
  }
};
MoreResources.style = moreResourcesCss;

exports.more_resources = MoreResources;
