import { directive, Directive, PartType } from 'lit/directive.js';
class UpdateHostDirective extends Directive {
    constructor(partInfo) {
        super(partInfo);
        if (partInfo.type !== PartType.CHILD) {
            throw new Error('retargetEvents() can only be used on a template result');
        }
    }
    render(host, template) {
        return template;
    }
    update(containerPart, [host, v]) {
        if (containerPart.options) {
            containerPart.options.host = host;
        }
        return this.render(host, v);
    }
}
/**
 * A directive to be used to update the `host` property on the
 * lit template. This can be used when the rendering happens outside
 * the main template (in another class). In such case instead of
 * calling `.listener.bind(this)` whenever using a listener you can
 * use this directive to render entire template belonging to another host.
 *
 * ```typescript
 * class NonLitHtmlContext {
 *   handleButton(): void {
 *     console.log(this); // -> NonLitHtmlContext
 *   }
 *
 *   render(): TemplateRest {
 *     const content = this.renderUi();
 *     return html`${retargetHost(this, content)}`;
 *   }
 *
 *   renderUi(): TemplateRest {
 *     return html`<button \@click="${this.handleButton}"></button>`;
 *   }
 * }
 *
 * class LitElementInstance extends LitElement {
 *   ui = new NonLitHtmlContext();
 *   render(): TemplateResult {
 *     return this.ui.render();
 *   }
 * }
 * ```
 */
export const retargetHost = directive(UpdateHostDirective);
//# sourceMappingURL=retargetHost.js.map