let BrowserWindow;
let CONFIG;

module.exports = function (electron, _CONFIG) {
  BrowserWindow = electron.BrowserWindow;
  CONFIG = _CONFIG;

  return {
    openMainWindow,
    openLogInWindow,
    closeLogInWindow,
    activateWithNoOpenWindows,
  };
};

const MAIN_WINDOW = 'main';
const AUTH_WINDOW = 'auth';

let windows = {};

function openMainWindow() {
  if (!windows[MAIN_WINDOW])
    windows[MAIN_WINDOW] = createMainWindow();
}

function openLogInWindow(url) {
  windows[AUTH_WINDOW] = createLogInWindow(url);
}

function closeLogInWindow() {
  windows[AUTH_WINDOW].close();
}

function createWindow(windowName, url, width, height, isDevToolsOpen) {
  const win = new BrowserWindow({ width, height });

  win.loadURL(url);
  win.on('closed', onClosed.bind(null, windowName));
  win.on('enter-html-full-screen', (event) => {
    // tmp
    // This event is called when the YouTube player goes fullscreen
    // It should only fullscreen the webview, but it does fullscreen the app
    setTimeout(function () {
      win.setFullScreen(false);
    }, 1000);
  });

  win.setMinimumSize(780, 270);
  if (isDevToolsOpen) win.openDevTools();

  return win;
}

function createMainWindow() {
  const url = 'file://' + __dirname + '/client/index.html';

  return createWindow(
    MAIN_WINDOW,
    url,
    CONFIG.MAIN_WINDOW.WIDTH,
    CONFIG.MAIN_WINDOW.HEIGHT,
    CONFIG.MAIN_WINDOW.IS_DEV_TOOLS_OPEN
  );
}

function createLogInWindow(url) {
  return createWindow(
    AUTH_WINDOW,
    url,
    CONFIG.AUTH_WINDOW.WIDTH,
    CONFIG.AUTH_WINDOW.HEIGHT,
    CONFIG.AUTH_WINDOW.IS_DEV_TOOLS_OPEN
  );
}

function activateWithNoOpenWindows() {
  if (!windows[MAIN_WINDOW]) {
    windows[MAIN_WINDOW] = createMainWindow();
  }
}

function onClosed(windowName) {
  // dereference the window
  windows[windowName] = null;
}

@@ -784,294 +784,8 @@
 ));%0A
-  win.on('enter-html-full-screen', (event) =%3E %7B%0A    // tmp%0A    // This event is called when the YouTube player goes fullscreen%0A    // It should only fullscreen the webview, but it does fullscreen the app%0A    setTimeout(function () %7B%0A      win.setFullScreen(false);%0A    %7D, 1000);%0A  %7D);%0A%0A
   wi
@@ -812,16 +812,17 @@
 , 270);%0A
+%0A
   if (is

Remove the full-screen hack