import { Component, h, Prop, State } from '@stencil/core';
import { Grid, Col } from '../../../core';
import { prismicDocToResource } from '../../utils/prismic/prismic';
import { Client } from '../../utils/prismic/prismic-configuration';
export class MoreResources {
  constructor() {
    this.description = false;
  }
  async componentWillLoad() {
    if (this.resources)
      return this.prismicResources = this.resources;
    const client = Client();
    const requests = this.resourceData.map(r => client.getByUID(r.type, r.uid, null));
    try {
      this.prismicResources = (await Promise.all(requests)).map(d => prismicDocToResource(d));
    }
    catch (e) {
      console.error('Unable to load more resources', e);
    }
  }
  render() {
    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, sm: 4 });
        break;
    }
    return (h(Grid, { class: `size-${this.resources.length}` }, this.prismicResources.map((d, i) => (h(Col, Object.assign({}, props, { key: d.id }),
      h("resource-card", { prismicData: d, description: this.description, routing: Array.isArray(this.routing) ? this.routing[i] : this.routing }))))));
  }
  static get is() { return "more-resources"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["more-resources.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["more-resources.css"]
  }; }
  static get properties() { return {
    "resourceData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "{ uid: string, type: string }[]",
        "resolved": "{ uid: string; type: string; }[]",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "resources": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "PrismicResource[]",
        "resolved": "PrismicResource[]",
        "references": {
          "PrismicResource": {
            "location": "import",
            "path": "../../models"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "description": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "description",
      "reflect": false,
      "defaultValue": "false"
    },
    "routing": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "ResourceCard['routing'] | ResourceCard['routing'][]",
        "resolved": "(string | RoutingProps)[] | RoutingProps | string",
        "references": {
          "ResourceCard": {
            "location": "import",
            "path": "../../../resource-center/resource-card/resource-card"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "routing",
      "reflect": false
    }
  }; }
  static get states() { return {
    "prismicResources": {}
  }; }
}
