/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { TypeRegistrar } from './type';
import { render, html } from './template';
export class IgcTemplateContentComponent extends HTMLElement {
    constructor() {
        super();
        this._template = null;
        this._attached = false;
        this._context = null;
        this.template = (context) => {
            return html `
               <div></div>  
            `;
        };
    }
    set template(value) {
        this._template = value;
        this.onTemplateChanged();
    }
    get template() {
        return this._template;
    }
    connectedCallback() {
        this.attachedCallback();
    }
    attachedCallback() {
        this._attached = true;
        this.render();
    }
    set context(value) {
        if (this._context == null && value == null) {
            return;
        }
        this._context = value;
        this.onContextChanged();
    }
    get context() {
        return this._context;
    }
    markChanged() {
        this.onContextChanged();
    }
    onContextChanged() {
        this.render();
    }
    onTemplateChanged() {
        if (this._attached) {
            this.render();
        }
    }
    render() {
        if (!this.context || !this.template) {
            if (this.template) {
                render(this.template(this.context), this);
            }
            else {
                this.innerHTML = '';
            }
        }
        else {
            render(this.template(this.context), this);
        }
    }
    get owner() {
        return this._owner;
    }
    set owner(v) {
        this._owner = v;
    }
    static register() {
        if (!IgcTemplateContentComponent._registered) {
            IgcTemplateContentComponent._registered = true;
            if (window.customElements) {
                window.customElements.define(IgcTemplateContentComponent.htmlTagName, IgcTemplateContentComponent);
            }
            else {
                document.registerElement(IgcTemplateContentComponent.htmlTagName, IgcTemplateContentComponent);
            }
            TypeRegistrar.registerCons("IgcTemplateContentComponent", IgcTemplateContentComponent);
        }
    }
}
IgcTemplateContentComponent.htmlTagName = "igc-template-content";
IgcTemplateContentComponent._registered = false;
