import { buildCustomEvent } from "../../../../utils/event-utils.js";
const childTemplatesContextEventName = 'atomic/resolveChildTemplates';
class ChildTemplatesContextController {
    get itemTemplateProvider() {
        return this._itemTemplateProvider;
    }
    hostConnected() {
        this._resolveChildTemplatesContext();
    }
    _resolveChildTemplatesContext() {
        const event = buildCustomEvent(childTemplatesContextEventName, (itemTemplateProvider)=>{
            if (this._itemTemplateProvider) return;
            this._itemTemplateProvider = itemTemplateProvider || null;
            this.host.requestUpdate();
        });
        const canceled = this.host.dispatchEvent(event);
        if (canceled) {
            this._itemTemplateProvider = null;
            this.host.requestUpdate();
        }
    }
    constructor(host){
        this._itemTemplateProvider = null;
        this.host = host;
        host.addController(this);
    }
}
export { ChildTemplatesContextController };
