import { CdkPortalOutlet, PortalInjector } from '@angular/cdk/portal';
import { ChangeDetectorRef, Component, ComponentFactoryResolver, HostBinding, Injector, Input, ViewChild, ViewContainerRef, } from '@angular/core';
import { RPosition } from './overlay-position';
export class RPositionedContainerComponent {
    get top() {
        return this.position === RPosition.TOP;
    }
    get topStart() {
        return this.position === RPosition.TOP_START;
    }
    get topEnd() {
        return this.position === RPosition.TOP_END;
    }
    get right() {
        return this.position === RPosition.RIGHT || this.position === RPosition.END;
    }
    get endTop() {
        return this.position === RPosition.END_TOP;
    }
    get endBottom() {
        return this.position === RPosition.END_BOTTOM;
    }
    get bottom() {
        return this.position === RPosition.BOTTOM;
    }
    get bottomStart() {
        return this.position === RPosition.BOTTOM_START;
    }
    get bottomEnd() {
        return this.position === RPosition.BOTTOM_END;
    }
    get left() {
        return this.position === RPosition.LEFT || this.position === RPosition.START;
    }
    get startTop() {
        return this.position === RPosition.START_TOP;
    }
    get startBottom() {
        return this.position === RPosition.START_BOTTOM;
    }
}
RPositionedContainerComponent.decorators = [
    { type: Component, args: [{
                template: ''
            },] }
];
RPositionedContainerComponent.propDecorators = {
    position: [{ type: Input }],
    top: [{ type: HostBinding, args: ['class.r-overlay-top',] }],
    topStart: [{ type: HostBinding, args: ['class.r-overlay-top-start',] }],
    topEnd: [{ type: HostBinding, args: ['class.r-overlay-top-end',] }],
    right: [{ type: HostBinding, args: ['class.r-overlay-right',] }],
    endTop: [{ type: HostBinding, args: ['class.r-overlay-end-top',] }],
    endBottom: [{ type: HostBinding, args: ['class.r-overlay-end-bottom',] }],
    bottom: [{ type: HostBinding, args: ['class.r-overlay-bottom',] }],
    bottomStart: [{ type: HostBinding, args: ['class.r-overlay-bottom-start',] }],
    bottomEnd: [{ type: HostBinding, args: ['class.r-overlay-bottom-end',] }],
    left: [{ type: HostBinding, args: ['class.r-overlay-left',] }],
    startTop: [{ type: HostBinding, args: ['class.r-overlay-start-top',] }],
    startBottom: [{ type: HostBinding, args: ['class.r-overlay-start-bottom',] }]
};
export class ROverlayContainerComponent {
    constructor(vcr, injector, changeDetectorRef) {
        this.vcr = vcr;
        this.injector = injector;
        this.changeDetectorRef = changeDetectorRef;
        this.isAttached = false;
    }
    get isStringContent() {
        return !!this.content;
    }
    attachComponentPortal(portal, context) {
        portal.injector = this.createChildInjector(portal.componentFactoryResolver);
        console.log(this.portalOutlet);
        const componentRef = this.portalOutlet.attachComponentPortal(portal);
        if (context) {
            Object.assign(componentRef.instance, context);
        }
        componentRef.changeDetectorRef.markForCheck();
        componentRef.changeDetectorRef.detectChanges();
        this.isAttached = true;
        return componentRef;
    }
    attachTemplatePortal(portal) {
        const templateRef = this.portalOutlet.attachTemplatePortal(portal);
        templateRef.detectChanges();
        this.isAttached = true;
        return templateRef;
    }
    attachStringContent(content) {
        this.content = content;
        this.changeDetectorRef.markForCheck();
        this.changeDetectorRef.detectChanges();
        this.isAttached = true;
    }
    detach() {
        if (this.portalOutlet.hasAttached()) {
            this.portalOutlet.detach();
        }
        this.attachStringContent(null);
        this.isAttached = false;
    }
    createChildInjector(cfr) {
        return new PortalInjector(this.injector, new WeakMap([
            [ComponentFactoryResolver, cfr],
        ]));
    }
}
ROverlayContainerComponent.decorators = [
    { type: Component, args: [{
                selector: 'r-overlay-container',
                template: `
    <div *ngIf="isStringContent" class="primitive-overlay">{{ content }}</div>
    <ng-template cdkPortalOutlet></ng-template>
  `
            },] }
];
ROverlayContainerComponent.ctorParameters = () => [
    { type: ViewContainerRef },
    { type: Injector },
    { type: ChangeDetectorRef }
];
ROverlayContainerComponent.propDecorators = {
    portalOutlet: [{ type: ViewChild, args: [CdkPortalOutlet,] }]
};
//# sourceMappingURL=overlay-container.js.map