import getViewportSize from '../../utils/dom/getViewportSize';
import { BottomLeft } from './bottom-left';
import { BottomRight } from './bottom-right';
import { BottomCenter } from './bottom-center';
import { TopLeft } from './top-left';
import { TopRight } from './top-right';
import { TopCenter } from './top-center';
var positionMap = {
    BottomLeft: BottomLeft,
    BottomRight: BottomRight,
    BottomCenter: BottomCenter,
    TopLeft: TopLeft,
    TopRight: TopRight,
    TopCenter: TopCenter,
};
export var AutoBottomCenter = function (props) {
    var contentRect = props.contentRect, cushion = props.cushion, anchorRect = props.anchorRect;
    var viewport = getViewportSize();
    var horizontal;
    var vertical;
    var mid = (anchorRect.left + anchorRect.right) / 2;
    var halfWidth = contentRect.width / 2;
    if (mid + halfWidth > viewport.width &&
        anchorRect.right - contentRect.width > 0) {
        horizontal = 'Right';
    }
    else if (mid - halfWidth < 0 &&
        anchorRect.left + contentRect.width < viewport.width) {
        horizontal = 'Left';
    }
    else {
        horizontal = 'Center';
    }
    if (anchorRect.bottom + cushion + contentRect.height > viewport.height &&
        anchorRect.top - cushion - contentRect.height > 0) {
        vertical = 'Top';
    }
    else {
        vertical = 'Bottom';
    }
    var key = "" + vertical + horizontal;
    return positionMap[key](props);
};
