'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.touchBarReset = exports.touchBarReInit = exports.touchBar = exports.refreshconfirm = exports.touchbaresc = undefined;

var _electron = require('electron');

var _config = require('./config');

var _config2 = _interopRequireDefault(_config);

var _pathExtra = require('path-extra');

var _pathExtra2 = _interopRequireDefault(_pathExtra);

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 = exports.touchbaresc = () => {
  mainWindow.webContents.sendInputEvent({
    type: "keyDown",
    keyCode: 'Escape'
  }), mainWindow.webContents.sendInputEvent({
    type: "keyUp",
    keyCode: 'Escape'
  });
};
// buttons
const devtools = new TouchBarButton({
  icon: _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'gears.png'),
  click: () => {
    mainWindow.openDevTools({ detach: true });
  }
});
const screenshot = new TouchBarButton({
  icon: _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'camera-retro.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'screenshot');
  }
});
const volume = new TouchBarButton({
  icon: _config2.default.get('poi.content.muted') ? _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-off.png') : _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-up.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'volume');
  }
});
const cachedir = new TouchBarButton({
  icon: _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'bolt.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'cachedir');
  }
});
const screenshotdir = new TouchBarButton({
  icon: _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'photo.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'screenshotdir');
  }
});
const adjust = new TouchBarButton({
  icon: _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'arrows-alt.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'adjust');
  }
});
const refresh = new TouchBarButton({
  icon: _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'refresh.png'),
  click: () => {
    mainWindow.webContents.send('touchbar', 'refresh');
  }
});
// poi esc
const poibutton = new TouchBarButton({
  icon: _pathExtra2.default.join(ROOT, 'assets', 'icons', 'poi_36x36.png'),
  backgroundColor: '#000000'
});
//confirmation modal
const refreshconfirm = exports.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
const touchBar = exports.touchBar = new _electron.TouchBar({
  items: [devtools, screenshot, volume, cachedir, screenshotdir, adjust, refresh],
  escapeItem: poibutton
});
//Change Volume btn
const touchBarReInit = exports.touchBarReInit = () => {
  volume.icon = _config2.default.get('poi.content.muted') ? _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-off.png') : _pathExtra2.default.join(ROOT, 'assets', 'img', 'touchbar', 'volume-up.png');
};
//Touchbar reset
const touchBarReset = exports.touchBarReset = () => {
  mainWindow.setTouchBar(touchBar);
};