import { ScreenEdge } from 'openfin-react-hooks';

const DEFAULT_LAUNCHER_SIZE = 50;
const DEFAULT_SEARCH_RESULTS_SIZE = 400;

export default (searchButtonRef, inputRef, dockedTo, windowBounds) => {
  const searchButtonRect = searchButtonRef.current.getBoundingClientRect();
  switch (dockedTo) {
    case ScreenEdge.TOP:
      const searchInputRect = inputRef.current.getBoundingClientRect();
      return {
        defaultTop: DEFAULT_LAUNCHER_SIZE,
        defaultLeft: parseInt(searchInputRect.left),
        defaultWidth: parseInt(searchInputRect.width),
        defaultHeight: DEFAULT_SEARCH_RESULTS_SIZE
      };
    case ScreenEdge.LEFT:
      return {
        defaultTop: parseInt(searchButtonRect.top),
        defaultLeft: DEFAULT_LAUNCHER_SIZE,
        defaultWidth: DEFAULT_SEARCH_RESULTS_SIZE,
        defaultHeight: DEFAULT_SEARCH_RESULTS_SIZE
      };
    case ScreenEdge.RIGHT:
      return {
        defaultTop: parseInt(searchButtonRect.top),
        defaultLeft: windowBounds.left - DEFAULT_SEARCH_RESULTS_SIZE,
        defaultWidth: DEFAULT_SEARCH_RESULTS_SIZE,
        defaultHeight: DEFAULT_SEARCH_RESULTS_SIZE
      };
    default:
      return {
        defaultTop: 0,
        defaultLeft: 0,
        defaultWidth: DEFAULT_SEARCH_RESULTS_SIZE,
        defaultHeight: DEFAULT_SEARCH_RESULTS_SIZE
      };
  }
};

@@ -1159,38 +1159,952 @@
     
-return %7B%0A        defaultTop: 0
+const searchInputBox = inputRef.current.getBoundingClientRect();%0A      if (searchInputBox.x !== 0) %7B%0A        return %7B%0A          defaultTop: parseInt(windowBounds.top) + DEFAULT_LAUNCHER_SIZE,%0A          defaultLeft: windowBounds.left + parseInt(searchInputBox.left),%0A          defaultWidth: DEFAULT_SEARCH_RESULTS_SIZE,%0A          defaultHeight: DEFAULT_SEARCH_RESULTS_SIZE%0A        %7D;%0A      %7D else %7B%0A        const rightPosition =%0A          windowBounds.left + windowBounds.width + DEFAULT_SEARCH_RESULTS_SIZE;%0A        let leftPosition = windowBounds.left + windowBounds.width;%0A        if (rightPosition %3E window.screen.width) %7B%0A          leftPosition = windowBounds.left - DEFAULT_SEARCH_RESULTS_SIZE;%0A        %7D else %7B%0A          if (windowBounds.left %3C 0 && rightPosition %3E 0) %7B%0A            leftPosition = windowBounds.left - DEFAULT_SEARCH_RESULTS_SIZE;%0A          %7D%0A        %7D%0A        return %7B%0A          defaultTop: parseInt(searchButtonRect.top)
 ,%0A  
@@ -2101,32 +2101,34 @@
 t.top),%0A        
+  
 defaultLeft: 0,%0A
@@ -2124,17 +2124,28 @@
 ltLeft: 
-0
+leftPosition
 ,%0A      
@@ -2138,32 +2138,34 @@
 sition,%0A        
+  
 defaultWidth: DE
@@ -2183,32 +2183,34 @@
 H_RESULTS_SIZE,%0A
+  
         defaultH
@@ -2250,18 +2250,28 @@
 E%0A      
+  %7D;%0A      
 %7D
-;
 %0A  %7D%0A%7D;%0A

fix positioning of search on non docked launcher