import { h } from '@stencil/core';
export class Post {
    componentDidLoad() {
        this.postRender();
    }
    componentDidUpdate() {
        this.postRender();
    }
    postRender() {
        let titleField = this.el.querySelector('.field--name-title');
        let bodyField = this.el.querySelector('.field--name-content');
        if (this.data.title)
            titleField.innerHTML = this.data.title.rendered;
        if (this.data.content) {
            bodyField.innerHTML = this.data.content.rendered;
        }
        else {
            bodyField.innerHTML = '';
        }
    }
    parsePost(post) {
        //console.log(post);
        // let type = post.type.split('--')[1];
        // switch (type) {
        //     case 'app':
        //         // this.postData = JSON.parse(post.field_json[0].value);
        //         break;
        //     case 'iframe':
        //         // code block
        //         break;
        //     case 'page':
        //         // code block
        //         break;
        //     default:
        //     // code block
        // }
        return post;
    }
    render() {
        if (this.dataJson) {
            var post = this.parsePost(JSON.parse(this.dataJson));
            this.data = post;
        }
        return (h("article", { class: 'post post-type-' + post.type + ' clearfix', id: 'post-' + post.id },
            h("header", null,
                h("h2", { class: "field field--name-title" })),
            h("div", { class: "content clearfix" },
                h("div", { class: "field field--name-content" }),
                post.type == 'iframe' && post.url &&
                    h("div", { class: "field field--name-url" },
                        h("ema-iframe", { src: post.url, width: post.width, height: post.height })))));
    }
    static get is() { return "ema-post"; }
    static get originalStyleUrls() { return {
        "$": ["post.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["post.css"]
    }; }
    static get properties() { return {
        "dataJson": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "data-json",
            "reflect": false
        }
    }; }
    static get states() { return {
        "data": {}
    }; }
    static get elementRef() { return "el"; }
}
