const DIV_ELEMENT = "div";
class OverlayViewHost {
    constructor(document) {
        this.document = document;
    }
    createElement(elementClassNames) {
        this.element = this.document.createElement(DIV_ELEMENT);
        if (elementClassNames.length) {
            for (let className of elementClassNames) {
                this.addClass(className);
            }
        }
        this.element.style.left = "0px";
        this.element.style.top = "0px";
        this.appendToBody();
    }
    appendChild(htmlElement) {
        this.element.appendChild(htmlElement);
    }
    show() {
        this.setStyle({ 'display': '' });
    }
    hide() {
        this.setStyle({ 'display': 'none' });
    }
    addClass(className) {
        this.element.classList.add(className);
    }
    removeClass(className) {
        this.element.classList.remove(className);
    }
    applyPlacement(calculatedOffset) {
        this.element.style.left = String(calculatedOffset.left) + "px";
        this.element.style.top = String(calculatedOffset.top) + "px";
    }
    setStyle(params) {
        let propNames = Object.getOwnPropertyNames(params);
        for (let key of propNames) {
            this.element.style[key] = params[key];
        }
    }
    appendToBody() {
        this.document.body.appendChild(this.element);
    }
    destroy() {
        this.element.parentNode.removeChild(this.element);
        this.element = undefined;
    }
}
class OverlayPositionHost {
    getClientRectangle(htmlElement) {
        let box = htmlElement.getBoundingClientRect();
        var parentNode = htmlElement.parentNode;
        var doc = parentNode.ownerDocument;
        var docElement = doc.documentElement;
        var parentBox = parentNode.getBoundingClientRect();
        var parentOffset = {
            top: box.top + window.pageYOffset - docElement.clientTop,
            left: box.left + window.pageXOffset - docElement.clientLeft,
            bottom: box.bottom, height: box.height, right: box.right, width: box.width
        };
        return parentOffset;
    }
    getOffset(htmlElement) {
        return new ElementOffsetModel(htmlElement.offsetWidth, htmlElement.offsetHeight);
    }
    getCalculatedOffset(offSetModel) {
        if (offSetModel.isCenterOverlay)
            return offSetModel.placement == 'bottom' ? { top: offSetModel.position.top + offSetModel.position.height, left: offSetModel.position.left + (offSetModel.position.width / 2) - (offSetModel.overlayElementOffset.width / 2) } :
                offSetModel.placement == 'top' ? { top: (offSetModel.position.top) - (offSetModel.overlayElementOffset.height), left: offSetModel.position.left + ((offSetModel.mainElementOffset.width - offSetModel.overlayElementOffset.width) / 2) } :
                    offSetModel.placement == 'left' ? { top: (offSetModel.position.top + (offSetModel.position.height / 2) - (offSetModel.overlayElementOffset.height / 2)), left: offSetModel.position.left - offSetModel.overlayElementOffset.width } :
                        { top: (offSetModel.position.top + (offSetModel.position.height / 2) - (offSetModel.overlayElementOffset.height / 2)), left: offSetModel.position.left + offSetModel.position.width };
        else
            return offSetModel.placement == 'bottom' ? { top: offSetModel.position.top + offSetModel.position.height + 5, left: offSetModel.position.left + 5 } :
                offSetModel.placement == 'top' ? { top: (offSetModel.position.top) - (offSetModel.overlayElementOffset.height), left: offSetModel.position.left + ((offSetModel.position.width - offSetModel.overlayElementOffset.width) / 2) } :
                    offSetModel.placement == 'left' ? { top: (offSetModel.position.top + (offSetModel.position.height / 2) - (offSetModel.overlayElementOffset.height / 2)), left: offSetModel.position.left - offSetModel.overlayElementOffset.width } :
                        { top: (offSetModel.position.top + (offSetModel.position.height / 2) - (offSetModel.overlayElementOffset.height / 2)), left: offSetModel.position.left + offSetModel.position.width };
    }
}
class BackDrop {
    static create() {
        this.overlayViewHost = new OverlayViewHost(document);
        this.overlayViewHost.createElement(["modal-backdrop", "fade", "in", "show"]);
    }
    static createValidation() {
        this.validationOverlayViewHost = new OverlayViewHost(document);
        this.validationOverlayViewHost.createElement(["modal-backdrop-validation", "fade", "in", "show"]);
    }
    static isBackdrop() {
        return this.overlayViewHost && this.overlayViewHost.element !== undefined;
    }
    static removeValidation() {
        this.validationOverlayViewHost.destroy();
        this.validationOverlayViewHost = undefined;
    }
    static remove() {
        this.overlayViewHost.destroy();
        this.overlayViewHost = undefined;
    }
}
BackDrop.overlayViewHost = new OverlayViewHost(document);
BackDrop.validationOverlayViewHost = new OverlayViewHost(document);
class OffSetModel {
    constructor(placement, position, mainElementOffset, overlayElementOffset, isCenterOverlay = true) {
        this.placement = placement;
        this.position = position;
        this.mainElementOffset = mainElementOffset;
        this.overlayElementOffset = overlayElementOffset;
        this.isCenterOverlay = isCenterOverlay;
    }
}
class ElementOffsetModel {
    constructor(width, height) {
        this.width = width;
        this.height = height;
    }
}

class ComponentView {
    constructor(_component, _viewContainerRef, _componentFactoryResolver) {
        this.component = _component;
        this.viewContainerRef = _viewContainerRef;
        this.componentFactoryResolver = _componentFactoryResolver;
    }
    create(params) {
        let componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.component);
        this.componentRef = this.viewContainerRef.createComponent(componentFactory, this.viewContainerRef.length, this.viewContainerRef.parentInjector);
        if (params)
            this.setParams(params);
    }
    setParams(params) {
        let propNames = Object.getOwnPropertyNames(params);
        for (let key of propNames) {
            this.componentRef.instance[key] = params[key];
        }
    }
    rootNode() {
        return this.componentRef.hostView.rootNodes[0];
    }
    getComponentRef() {
        return this.componentRef;
    }
    destroy() {
        if (this.componentRef) {
            this.componentRef.destroy();
            this.componentRef = undefined;
        }
    }
}

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

export { BackDrop, ComponentView, DIV_ELEMENT, ElementOffsetModel, OffSetModel, OverlayPositionHost, OverlayViewHost };
//# sourceMappingURL=rxweb-angular-api.js.map
