{
}
export class Repeater {
    constructor() {
        this.content = [];
        this.element = "ul";
        this.template = '';
    }
    componentDidLoad() {
        this.postRender();
    }
    componentDidUpdate() {
        this.postRender();
    }
    postRender() {
        this.el.innerHTML = this.html;
    }
    async setData(content) {
        this.content = content;
    }
    async setTemplate(template) {
        this.templateString = template;
    }
    interpolate(template, obj) {
        if (typeof obj == "object") {
            for (let key in obj) {
                const find = "${" + key + "}";
                if (template.indexOf(find) > -1) {
                    template = template.replace(find, obj[key]);
                    delete obj[key];
                }
            }
        }
        return template;
    }
    render() {
        const element = this.element;
        let html = (element !== null) ? "<" + element.toLowerCase() + ">" : "";
        if (this.template) {
            this.templateString = this.template;
        }
        if (this.dataJson) {
            this.content = JSON.parse(this.dataJson);
        }
        if (Array.isArray(this.content)) {
            this.content.forEach((item) => {
                html += this.interpolate(this.templateString, item);
            });
        }
        else {
            throw new Error("Content should be an Array of objects.");
        }
        html += (element !== null) ? "</" + element.toLowerCase() + ">" : "";
        this.html = html;
        return (h("div", null));
    }
    static get is() { return "ema-repeater"; }
    static get properties() { return {
        "content": {
            "state": true
        },
        "dataJson": {
            "type": String,
            "attr": "data-json"
        },
        "el": {
            "elementRef": true
        },
        "element": {
            "type": String,
            "attr": "element"
        },
        "setData": {
            "method": true
        },
        "setTemplate": {
            "method": true
        },
        "template": {
            "type": String,
            "attr": "template"
        },
        "templateString": {
            "state": true
        }
    }; }
}
