"use strict";

exports.__esModule = true;
exports.touchBarReset = exports.touchBarReInit = exports.touchBar = exports.refreshconfirm = exports.touchbaresc = void 0;

var _electron = require("electron");

var _config = _interopRequireDefault(require("./config"));

var _pathExtra = _interopRequireDefault(require("path-extra"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const {
  TouchBarButton,
  TouchBarSpacer
} = _electron.TouchBar;
const mainWindow = global.mainWindow;
const ROOT = global.ROOT; // simulate Escape key

const touchbaresc = () => {
  mainWindow.webContents.sendInputEvent({
    type: "keyDown",
    keyCode: 'Escape'
  }), mainWindow.webContents.sendInputEvent({
    type: "keyUp",
    keyCode: 'Escape'
  });
}; // buttons


exports.touchbaresc = touchbaresc;
const devtools = new TouchBarButton({
  icon: _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'gears.png'),
  click: () => {
    mainWindow.openDevTools({
      mode: 'detach'
    });
  }
});
const screenshot = new TouchBarButton({
  icon: _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'camera-retro.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'screenshot');
  }
});
const volume = new TouchBarButton({
  icon: _config.default.get('poi.content.muted') ? _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-off.png') : _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-up.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'volume');
  }
});
const cachedir = new TouchBarButton({
  icon: _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'bolt.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'cachedir');
  }
});
const screenshotdir = new TouchBarButton({
  icon: _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'photo.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'screenshotdir');
  }
});
const adjust = new TouchBarButton({
  icon: _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'arrows-alt.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'adjust');
  }
});
const refresh = new TouchBarButton({
  icon: _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'refresh.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'refresh');
  }
}); // poi esc

const poibutton = new TouchBarButton({
  icon: _pathExtra.default.join(ROOT, 'assets', 'icons', 'poi_36x36.png'),
  backgroundColor: '#000000'
}); //confirmation modal

const refreshconfirm = (btn1, btn2) => {
  mainWindow.setTouchBar(new _electron.TouchBar({
    items: [new TouchBarSpacer({
      size: 'flexible'
    }), new TouchBarButton({
      label: btn1,
      backgroundColor: '#E08E0B',
      click: () => {
        mainWindow.webContents.send('touchbar', 'gameRefreshPage');
        touchbaresc();
      }
    }), new TouchBarButton({
      label: btn2,
      backgroundColor: '#E43725',
      click: () => {
        mainWindow.webContents.send('touchbar', 'gameReloadFlash');
        touchbaresc();
      }
    }), new TouchBarSpacer({
      size: 'flexible'
    })]
  }));
}; //main-touchbar


exports.refreshconfirm = refreshconfirm;
const touchBar = new _electron.TouchBar({
  items: [devtools, screenshot, volume, cachedir, screenshotdir, adjust, refresh],
  escapeItem: poibutton
}); //Change Volume btn

exports.touchBar = touchBar;

const touchBarReInit = () => {
  volume.icon = _config.default.get('poi.content.muted') ? _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-off.png') : _pathExtra.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-up.png');
}; //Touchbar reset


exports.touchBarReInit = touchBarReInit;

const touchBarReset = () => {
  mainWindow.setTouchBar(touchBar);
};

exports.touchBarReset = touchBarReset;