import * as i0 from '@angular/core';
import { Directive, Input, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

class TeleportingDirective {
    constructor(templateRef, vcr) {
        this.templateRef = templateRef;
        this.vcr = vcr;
        this.addChildNodes = [];
        this.hasTeleported = false;
    }
    ngOnInit() {
        this.viewRef = this.vcr.createEmbeddedView(this.templateRef);
        this.teleportingView();
    }
    ngAfterViewInit() {
        this.teleportingView();
    }
    ngOnDestroy() {
        this.clearAttachedNodes();
    }
    teleportingView() {
        if (this.selector && !this.hasTeleported) {
            this.host = document.querySelector(this.selector);
            if (this.host) {
                this.viewRef.rootNodes.forEach(node => {
                    this.host.appendChild(node);
                    this.addChildNodes.push(node);
                });
                this.hasTeleported = true;
            }
        }
    }
    clearAttachedNodes() {
        if (!!this.host && this.host.hasChildNodes() && this.addChildNodes.length) {
            this.addChildNodes.forEach(node => {
                try {
                    this.host.removeChild(node);
                }
                catch (e) {
                    console.warn(`teleported : ${e}`);
                }
            });
        }
        if (this.viewRef) {
            this.viewRef.destroy();
        }
    }
    static { this.ɵfac = function TeleportingDirective_Factory(t) { return new (t || TeleportingDirective)(i0.ɵɵdirectiveInject(i0.TemplateRef), i0.ɵɵdirectiveInject(i0.ViewContainerRef)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: TeleportingDirective, selectors: [["", "fusionTeleporting", ""]], inputs: { selector: [i0.ɵɵInputFlags.None, "fusionTeleporting", "selector"] } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TeleportingDirective, [{
        type: Directive,
        args: [{
                selector: '[fusionTeleporting]'
            }]
    }], () => [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }], { selector: [{
            type: Input,
            args: ['fusionTeleporting']
        }] }); })();

class TeleportingModule {
    static { this.ɵfac = function TeleportingModule_Factory(t) { return new (t || TeleportingModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: TeleportingModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TeleportingModule, [{
        type: NgModule,
        args: [{
                declarations: [TeleportingDirective],
                exports: [TeleportingDirective],
                imports: [CommonModule]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(TeleportingModule, { declarations: [TeleportingDirective], imports: [CommonModule], exports: [TeleportingDirective] }); })();

/**
 * Generated bundle index. Do not edit.
 */

export { TeleportingDirective, TeleportingModule };
//# sourceMappingURL=ironsource-fusion-ui-directives-teleporting.mjs.map
