import { createElement as engineCreateElement } from 'lwc';
import { getComponent } from 'talon/moduleRegistry';
import { moduleSpecifierToElementName } from '@webruntime/common';
import { getLwcFallback } from 'talon/configProvider';

export async function createElement(name) {
    return getComponent(name).then(ctor => {
        const customElementName = moduleSpecifierToElementName(name);
        return engineCreateElement(customElementName, {
            is: ctor,
            fallback: getLwcFallback(),
        });
    });
}

export default { createElement };
