var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { ChangeDetectorRef, Component, ComponentFactoryResolver, HostBinding, Injector, Input, ViewChild, ViewContainerRef, } from '@angular/core';
import { ElPosition } from './overlay-position';
import { ElPortalInjector, ElPortalOutletDirective } from './mapping';
export class ElPositionedContainer {
    get top() {
        return this.position === ElPosition.TOP;
    }
    get topStart() {
        return this.position === ElPosition.TOP_START;
    }
    get topEnd() {
        return this.position === ElPosition.TOP_END;
    }
    get right() {
        return this.position === ElPosition.RIGHT || this.position === ElPosition.END;
    }
    get endTop() {
        return this.position === ElPosition.END_TOP;
    }
    get endBottom() {
        return this.position === ElPosition.END_BOTTOM;
    }
    get bottom() {
        return this.position === ElPosition.BOTTOM;
    }
    get bottomStart() {
        return this.position === ElPosition.BOTTOM_START;
    }
    get bottomEnd() {
        return this.position === ElPosition.BOTTOM_END;
    }
    get left() {
        return this.position === ElPosition.LEFT || this.position === ElPosition.START;
    }
    get startTop() {
        return this.position === ElPosition.START_TOP;
    }
    get startBottom() {
        return this.position === ElPosition.START_BOTTOM;
    }
}
__decorate([
    Input(),
    __metadata("design:type", String)
], ElPositionedContainer.prototype, "position", void 0);
__decorate([
    HostBinding('class.el-overlay-top'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "top", null);
__decorate([
    HostBinding('class.el-overlay-top-start'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "topStart", null);
__decorate([
    HostBinding('class.el-overlay-top-end'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "topEnd", null);
__decorate([
    HostBinding('class.el-overlay-right'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "right", null);
__decorate([
    HostBinding('class.el-overlay-end-top'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "endTop", null);
__decorate([
    HostBinding('class.el-overlay-end-bottom'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "endBottom", null);
__decorate([
    HostBinding('class.el-overlay-bottom'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "bottom", null);
__decorate([
    HostBinding('class.el-overlay-bottom-start'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "bottomStart", null);
__decorate([
    HostBinding('class.el-overlay-bottom-end'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "bottomEnd", null);
__decorate([
    HostBinding('class.el-overlay-left'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "left", null);
__decorate([
    HostBinding('class.el-overlay-start-top'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "startTop", null);
__decorate([
    HostBinding('class.el-overlay-start-bottom'),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [])
], ElPositionedContainer.prototype, "startBottom", null);
let ElOverlayContainerComponent = class ElOverlayContainerComponent {
    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);
        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 ElPortalInjector(this.injector, new WeakMap([
            [ComponentFactoryResolver, cfr],
        ]));
    }
};
__decorate([
    ViewChild(ElPortalOutletDirective, { static: true }),
    __metadata("design:type", ElPortalOutletDirective)
], ElOverlayContainerComponent.prototype, "portalOutlet", void 0);
ElOverlayContainerComponent = __decorate([
    Component({
        selector: 'el-overlay-container',
        template: `
    <div *ngIf="isStringContent" class="primitive-overlay">{{ content }}</div>
    <ng-template elPortalOutlet></ng-template>
  `
    }),
    __metadata("design:paramtypes", [ViewContainerRef,
        Injector, ChangeDetectorRef])
], ElOverlayContainerComponent);
export { ElOverlayContainerComponent };
//# sourceMappingURL=overlay-container.js.map