'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _reactDom2 = _interopRequireDefault(_reactDom);

var _fsExtra = require('fs-extra');

var _fsExtra2 = _interopRequireDefault(_fsExtra);

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

var _pathExtra2 = _interopRequireDefault(_pathExtra);

var _reactRedux = require('react-redux');

var _electron = require('electron');

require('../assets/css/app.css');

require('../assets/css/global.css');

var _createStore = require('./create-store');

var _tabarea = require('./tabarea');

var _tabarea2 = _interopRequireDefault(_tabarea);

var _alert = require('./components/info/alert');

var _mapReminder = require('./components/info/map-reminder');

var _mapReminder2 = _interopRequireDefault(_mapReminder);

var _control = require('./components/info/control');

var _toastr = require('./components/info/toastr');

var _modal = require('./components/etc/modal');

var _httpBasicAuth = require('./utils/http-basic-auth');

var _menu = require('./components/etc/menu');

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

const { EXROOT, $ } = window;
const config = _electron.remote.require('./lib/config');

// Disable OSX zoom
_electron.webFrame.setZoomLevelLimits(1, 1);

// Workaround for false BrowserWindow size
if (!config.get('poi.window.isMaximized', false) && !config.get('poi.window.isFullScreen', false) && config.get('poi.window.width') && config.get('poi.window.height')) {
  _electron.remote.getCurrentWindow().setSize(config.get('poi.window.width'), config.get('poi.window.height'));
}

// Hackable panels
window.hack = {};

// Alert functions
require('./services/alert');

const CustomCssInjector = () => {
  const cssPath = _pathExtra2.default.join(EXROOT, 'hack', 'custom.css');
  _fsExtra2.default.ensureFileSync(cssPath);
  return _react2.default.createElement('link', { rel: 'stylesheet', id: 'custom-css', href: cssPath });
};

_reactDom2.default.render(_react2.default.createElement(
  _reactRedux.Provider,
  { store: _createStore.store },
  _react2.default.createElement(
    'div',
    null,
    config.get('poi.useCustomTitleBar', process.platform === 'win32' || process.platform === 'linux') && _reactDom2.default.createPortal(_react2.default.createElement(_menu.TitleBarWrapper, null), $('title-bar')),
    _reactDom2.default.createPortal(_react2.default.createElement(_control.PoiControl, null), $('poi-control')),
    _reactDom2.default.createPortal(_react2.default.createElement(_alert.PoiAlert, { id: 'poi-alert' }), $('poi-alert')),
    _reactDom2.default.createPortal(_react2.default.createElement(_mapReminder2.default, { id: 'poi-map-reminder' }), $('poi-map-reminder')),
    _react2.default.createElement(_tabarea2.default, null),
    _reactDom2.default.createPortal(_react2.default.createElement(_modal.ModalTrigger, null), $('poi-modal-trigger')),
    _reactDom2.default.createPortal(_react2.default.createElement(_toastr.Toastr, null), $('poi-toast-trigger')),
    _reactDom2.default.createPortal(_react2.default.createElement(CustomCssInjector, null), $('poi-css-injector')),
    _reactDom2.default.createPortal(_react2.default.createElement(_httpBasicAuth.BasicAuth, null), $('poi-auth-trigger'))
  )
), $('poi-nav-tabs'));