/**
 * @file PositionPopCalculation vendor
 * @author liangxiaojun(liangxiaojun@derbysoft.com)
 */

import Position from '../_statics/Position';

function horizontalCenter(popupEl) {
    return (window.innerWidth - popupEl.offsetWidth) / 2;
}

function horizontalRight(popupEl) {
    return window.innerWidth - popupEl.offsetWidth;
}

function verticalMiddle(popupEl) {
    return (window.innerHeight - popupEl.offsetHeight) / 2;
}

function verticalBottom(popupEl) {
    return window.innerHeight - popupEl.offsetHeight;
}

function getStyle(popupEl, position) {

    if (!popupEl) {
        return;
    }

    let result = {};

    switch (position) {
        case Position.TOP_LEFT: {
            result.left = 0;
            result.top = 0;
            break;
        }
        case Position.TOP: {
            result.left = horizontalCenter(popupEl);
            result.top = 0;
            break;
        }
        case Position.TOP_RIGHT: {
            result.left = horizontalRight(popupEl);
            result.top = 0;
            break;
        }
        case Position.BOTTOM_LEFT: {
            result.left = 0;
            result.top = verticalBottom(popupEl);
            break;
        }
        case Position.BOTTOM: {
            result.left = horizontalCenter(popupEl);
            result.top = verticalBottom(popupEl);
            break;
        }
        case Position.BOTTOM_RIGHT: {
            result.left = horizontalRight(popupEl);
            result.top = verticalBottom(popupEl);
            break;
        }
        case Position.LEFT_TOP: {
            result.left = 0;
            result.top = 0;
            break;
        }
        case Position.LEFT: {
            result.left = 0;
            result.top = verticalMiddle(popupEl);
            break;
        }
        case Position.LEFT_BOTTOM: {
            result.left = 0;
            result.top = verticalBottom(popupEl);
            break;
        }
        case Position.RIGHT_TOP: {
            result.left = horizontalRight(popupEl);
            result.top = 0;
            break;
        }
        case Position.RIGHT: {
            result.left = horizontalRight(popupEl);
            result.top = verticalMiddle(popupEl);
            break;
        }
        case Position.RIGHT_BOTTOM: {
            result.left = horizontalRight(popupEl);
            result.top = verticalBottom(popupEl);
            break;
        }
        case Position.CENTER: {
            result.left = horizontalCenter(popupEl);
            result.top = verticalMiddle(popupEl);
            break;
        }
    }

    return result;

}

function setStyle(popupEl, position) {

    const style = getStyle(popupEl, position);

    if (!style) {
        return;
    }

    popupEl.style.left = style.left + 'px';
    popupEl.style.top = style.top + 'px';

}

export default {
    getStyle,
    setStyle
};
@@ -250,275 +250,92 @@
 ion 
-horizontalRight(popupEl) %7B%0A    return window.innerWidth - popupEl.offsetWidth;%0A%7D%0A%0Afunction verticalMiddle(popupEl) %7B%0A    return (window.innerHeight - popupEl.offsetHeight) / 2;%0A%7D%0A%0Afunction verticalBottom(popupEl) %7B%0A    return window.innerHeight - popupEl.offsetHeight
+verticalMiddle(popupEl) %7B%0A    return (window.innerHeight - popupEl.offsetHeight) / 2
 ;%0A%7D%0A
@@ -781,39 +781,17 @@
 ult.
-left = horizontalRight(popupEl)
+right = 0
 ;%0A  
@@ -934,37 +934,18 @@
 ult.
+bot
 to
-p = verticalBottom(popupEl)
+m = 0
 ;%0A  
@@ -1079,37 +1079,18 @@
 ult.
+bot
 to
-p = verticalBottom(popupEl)
+m = 0
 ;%0A  
@@ -1177,39 +1177,17 @@
 ult.
-left = horizontalRight(popupEl)
+right = 0
 ;%0A  
@@ -1207,37 +1207,18 @@
 ult.
+bot
 to
-p = verticalBottom(popupEl)
+m = 0
 ;%0A  
@@ -1591,37 +1591,18 @@
 ult.
+bot
 to
-p = verticalBottom(popupEl)
+m = 0
 ;%0A  
@@ -1686,39 +1686,17 @@
 ult.
-left = horizontalRight(popupEl)
+right = 0
 ;%0A  
@@ -1804,39 +1804,17 @@
 ult.
-left = horizontalRight(popupEl)
+right = 0
 ;%0A  
@@ -1951,39 +1951,17 @@
 ult.
-left = horizontalRight(popupEl)
+right = 0
 ;%0A  
@@ -1981,37 +1981,18 @@
 ult.
+bot
 to
-p = verticalBottom(popupEl)
+m = 0
 ;%0A  
@@ -2370,27 +2370,113 @@
 t = 
-style.left + 'px';%0A
+popupEl.style.right = popupEl.style.top = popupEl.style.bottom = null;%0A%0A    for (let key in style) %7B%0A    
     
@@ -2492,20 +2492,21 @@
 tyle
-.top
+%5Bkey%5D
  = style
 .top
@@ -2505,20 +2505,21 @@
 tyle
-.top
+%5Bkey%5D
  + 'px';
 %0A%0A%7D%0A
@@ -2514,16 +2514,22 @@
  + 'px';
+%0A    %7D
 %0A%0A%7D%0A%0Aexp

update PositionPopCalculation