import { h } from "@stencil/core";
import { load } from "./new-loader";
export class Embed {
    async componentWillLoad() {
        const dataset = this.el.dataset || {};
        const { tag, url } = dataset;
        if (!url) {
            return;
        }
        if (!tag) {
            return;
        }
        this.tag = tag;
        const names = this.el.getAttributeNames();
        this.params = Object.entries(names).reduce((acc, [index, n]) => {
            if (n !== "data-tag" && n !== "data-url") {
                acc[n] = this.el.getAttribute(n);
            }
            return acc;
        }, {});
        await load(tag, url);
    }
    render() {
        if (this.tag) {
            const Tag = this.tag;
            return h(Tag, Object.assign({}, this.params));
        }
    }
    static get is() { return "pie-embed"; }
    static get originalStyleUrls() { return {
        "$": ["../components.css"]
    }; }
    static get styleUrls() { return {
        "$": ["../components.css"]
    }; }
    static get contextProps() { return [{
            "name": "doc",
            "context": "document"
        }]; }
    static get states() { return {
        "tag": {},
        "params": {}
    }; }
    static get elementRef() { return "el"; }
}
