/* eslint-disable max-len */
require('muicss');
const $ = require('jquery');
const _ = require('underscore');
const Backbone = require('backbone');

const { LocationModel } = require('./Location');
const { GreetModel, GreetView } = require('./Greet');
const { NearbyModel, NearbyView } = require('./Nearby');
const { WeatherModel, WeatherView } = require('./Weather');
const { WeatherAlertModel, WeatherAlertView } = require('./WeatherAlert');
const { ForecastModel, ForecastView } = require('./Forecast');
const { NewsModel, NewsView } = require('./News');
const { NewsCardModel, NewsCardView } = require('./NewsViewer');
const { ByMeModel, ByMeView } = require('./RightByMe');

var app = app || {};

const live = true;

if (live) {
  window.loc = 'https://jubilee.silvrtree.co.uk';
  if ('serviceWorker' in navigator)
    navigator.serviceWorker
      .register('./service-worker.js')
      .then(function() {
        console.log('Service Worker Registered');
      });
}
else
  window.loc = 'http://localhost:8110';

(function () {
  const offline = false;

  /* var myRouter = Backbone.Router.extend({
    //

  });*/

  app.eventBus = _.extend({}, Backbone.Events);

  app.locationModel = new LocationModel();

  // new TrainView({ 'model': new TrainModel(route), 'eventBus': app.eventBus });

  app.greetView = new GreetView({ 'model': new GreetModel(), 'eventBus': app.eventBus, 'location': app.locationModel });

  app.nearby = new NearbyView({ 'model': new NearbyModel(), 'eventBus': app.eventBus, 'location': app.locationModel, 'el':'#nearby' });

  app.weather = new WeatherView({ 'model': new WeatherModel(), 'eventBus': app.eventBus, 'location': app.locationModel, 'el':'#weather', 'viewFrame':'#viewFrame' });

  app.weatherAlert = new WeatherAlertView({ 'model': new WeatherAlertModel(), 'eventBus': app.eventBus, 'location': app.locationModel, 'el':'#weatherAlert', 'viewFrame':'#viewFrame' });

  app.forecastCard = new ForecastView({ 'model': new ForecastModel(), 'eventBus': app.eventBus });

  app.newsCard = new NewsCardView({ 'model': new NewsCardModel(), 'eventBus': app.eventBus });

  app.news = new NewsView({ 'model': new NewsModel(), 'eventBus': app.eventBus, 'el':'#news' });

  app.byMe = new ByMeView({ 'model': new ByMeModel(), 'eventBus': app.eventBus, 'location': app.locationModel, 'el':'#byme' });

  window.addEventListener('focus', () => {
    console.log('Window has focus...');
    app.eventBus.trigger('focused');
  });
})();
