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.prismicEndpoint = 'https://ionicframeworkcom.cdn.prismic.io/api/v2';
    this.description = false;
  }
  async componentWillLoad() {
    if (this.resources)
      return this.prismicResources = this.resources;
    const client = Client(this.prismicEndpoint);
    const requests = this.resourceData.map(r => client.getByUID(r.type, r.uid, null));
    try {
      this.prismicResources = await (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,
      md: undefined,
      sm: undefined
    };
    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) => (h(Col, Object.assign({}, props, { key: d.id }),
      h("resource-card", { prismicData: d, description: this.description, routing: 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": ""
      }
    },
    "prismicEndpoint": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "prismic-endpoint",
      "reflect": false,
      "defaultValue": "'https://ionicframeworkcom.cdn.prismic.io/api/v2'"
    },
    "description": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "description",
      "reflect": false,
      "defaultValue": "false"
    },
    "routing": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "{\n    base?: string,\n    includeType?: boolean,\n    router?: Router \n  }",
        "resolved": "{ base?: string; includeType?: boolean; router?: Router; }",
        "references": {
          "Router": {
            "location": "import",
            "path": "stencil-router-v2"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "prismicResources": {}
  }; }
}
