import { Component, h, Prop } from '@stencil/core';
import { Grid, Col } from '../../../core';
import { prismicDocToResource } from '../../utils/prismic/prismic';
import { Client } from '../../utils/prismic/prismic-configuration';
export class MoreResources {
  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 => 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 (h(Grid, { class: `size-${this.resources.length}` }, this.resources.map((d, i) => (h(Col, Object.assign({}, props, { cols: 12, key: d.id }),
      h("resource-card", Object.assign({ prismicData: d, routing: Array.isArray(this.routing) ? this.routing[i] : this.routing }, data)))))));
  }
  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": ""
      }
    },
    "headingLevel": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "ResourceCard['headingLevel']",
        "resolved": "1 | 2 | 3 | 4 | 5 | 6",
        "references": {
          "ResourceCard": {
            "location": "import",
            "path": "../../../resource-center/resource-card/resource-card"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "heading-level",
      "reflect": false
    },
    "type": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "ResourceCard['type']",
        "resolved": "boolean",
        "references": {
          "ResourceCard": {
            "location": "import",
            "path": "../../../resource-center/resource-card/resource-card"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "type",
      "reflect": false
    },
    "tags": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "ResourceCard['tags']",
        "resolved": "boolean",
        "references": {
          "ResourceCard": {
            "location": "import",
            "path": "../../../resource-center/resource-card/resource-card"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "tags",
      "reflect": false
    },
    "description": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "ResourceCard['description']",
        "resolved": "boolean",
        "references": {
          "ResourceCard": {
            "location": "import",
            "path": "../../../resource-center/resource-card/resource-card"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "description",
      "reflect": false
    },
    "author": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "ResourceCard['author']",
        "resolved": "boolean",
        "references": {
          "ResourceCard": {
            "location": "import",
            "path": "../../../resource-center/resource-card/resource-card"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "author",
      "reflect": 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": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "routing",
      "reflect": false
    }
  }; }
}
