import { DOCUMENT, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Component, Inject, ViewChild, NgModule } from '@angular/core';
import { forEach } from 'lodash-es';

class PortalComponent {
    constructor(appRef, doc) {
        this.appRef = appRef;
        this.doc = doc;
        this.document = this.doc;
    }
    addContent() {
        this.portalContainer = this.document.createElement('div');
        this.viewRef = this.templateRef.createEmbeddedView(this);
        forEach(this.viewRef.rootNodes, (node) => {
            this.portalContainer.appendChild(node);
        });
        this.appRef.attachView(this.viewRef);
        this.document.body.appendChild(this.portalContainer);
    }
    open() {
        this.close();
        this.addContent();
    }
    close() {
        if (this.viewRef && this.portalContainer) {
            this.document.body.removeChild(this.portalContainer);
            this.viewRef.destroy();
            this.viewRef = null;
            this.portalContainer = null;
        }
    }
}
PortalComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: PortalComponent, deps: [{ token: i0.ApplicationRef }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Component });
PortalComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.0", type: PortalComponent, selector: "d-portal", viewQueries: [{ propertyName: "templateRef", first: true, predicate: ["templateRef"], descendants: true, static: true }], ngImport: i0, template: `
                   <ng-template #templateRef>
                        <ng-content></ng-content>
                    </ng-template>`, isInline: true });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: PortalComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'd-portal',
                    template: `
                   <ng-template #templateRef>
                        <ng-content></ng-content>
                    </ng-template>`,
                    preserveWhitespaces: false,
                }]
        }], ctorParameters: function () {
        return [{ type: i0.ApplicationRef }, { type: undefined, decorators: [{
                        type: Inject,
                        args: [DOCUMENT]
                    }] }];
    }, propDecorators: { templateRef: [{
                type: ViewChild,
                args: ['templateRef', { static: true }]
            }] } });

class PortalModule {
}
PortalModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: PortalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
PortalModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.0", ngImport: i0, type: PortalModule, declarations: [PortalComponent], imports: [CommonModule], exports: [PortalComponent] });
PortalModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: PortalModule, imports: [CommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: PortalModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CommonModule,
                    ],
                    declarations: [
                        PortalComponent,
                    ],
                    exports: [
                        PortalComponent,
                    ],
                }]
        }] });

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

export { PortalComponent, PortalModule };
//# sourceMappingURL=ng-devui-portal.mjs.map
