import { h } from '@stencil/core';
import { ResourceType } from '../../models';
import ResourceAuthorItem from './ResourceAuthorItem';
import { getResourceUrl } from '../../urls';
import ResourceMeta from './ResourceMeta';
import { Card, Heading } from '../../ds';
const ResourceCard = (props) => {
    if (props.hero) {
        return h(StandardResourceCard, Object.assign({}, props));
    }
    switch (props.resource.type) {
        case ResourceType.Whitepaper:
            return h(WhitepaperResourceCard, Object.assign({}, props));
        default:
            return h(StandardResourceCard, Object.assign({}, props));
    }
};
const StandardResourceCard = ({ resource, headingLevel = 3, showAuthor = true, showImage = true, showDescription = true, metaTop = false, key, }) => (h(Card, { embelish: false, class: `resource-card${metaTop ? ` resource-card--meta-top` : ''}`, key: key },
    metaTop && h(ResourceMeta, { resource: resource }),
    showImage && (h("a", { href: getResourceUrl(resource), class: "resource-card__image" },
        h(HeroImage, { resource: resource }))),
    !metaTop && h(ResourceMeta, { resource: resource }),
    h("div", { class: "resource-card__content" },
        h("a", { href: getResourceUrl(resource) },
            h(Heading, { level: headingLevel }, resource.title)),
        showDescription && h("p", null, resource.description)),
    showAuthor && h(ResourceAuthorItem, { author: resource.authors[0] })));
const WhitepaperResourceCard = (props) => {
    const r = props.resource;
    return (h(Card, { embelish: false, class: `resource-card resource-card--ad`, key: props.key },
        h("a", { href: getResourceUrl(props.resource) },
            h(Heading, { level: 3 }, r.doc.data.ad || r.title),
            h(HeroImage, { resource: props.resource }))));
};
const HeroImage = ({ resource }) => (h("img", { loading: 'lazy', class: "resource-card__featured-image", src: resource.heroImage, alt: resource.title }));
export default ResourceCard;
