import { Component, Host, h, Prop, State } from '@stencil/core';
import { Grid, Col } from '../../../core';
import { Client, prismicDocToResource } from '../../utils/prismic';
import ResourceCard from '../resources/ResourceCard';
export class MoreResources {
    constructor() {
        this.showAuthor = false;
        this.showDescription = true;
        this.prismicEndpoint = 'https://ionicframeworkcom.cdn.prismic.io/api/v2';
    }
    async componentWillLoad() {
        const client = Client(this.prismicEndpoint);
        const requests = this.resources.map(r => client.getByUID(r.type, r.uid, null));
        try {
            this.docs = await (await Promise.all(requests)).map(d => prismicDocToResource(d));
        }
        catch (e) {
            console.error('Unable to load more resources', e);
        }
    }
    render() {
        const { showAuthor, showDescription } = this;
        return (h(Host, null,
            h(Grid, null, this.docs.map(d => (h(Col, { md: 4, sm: 4, xs: 12, cols: 12, key: d.id },
                h(ResourceCard, { resource: d, showDescription: showDescription, showAuthor: showAuthor })))))));
    }
    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 {
        "resources": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "any[]",
                "resolved": "any[]",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "showAuthor": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "show-author",
            "reflect": false,
            "defaultValue": "false"
        },
        "showDescription": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "show-description",
            "reflect": false,
            "defaultValue": "true"
        },
        "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'"
        }
    }; }
    static get states() { return {
        "docs": {}
    }; }
}
