/**
 * @flow
 * All About Olaf
 * Index view
 */

import './globalize-fetch'
import './setup-moment'
import OneSignal from 'react-native-onesignal'

import React from 'react'
import {Provider} from 'react-redux'
import {store} from './flux'
import {tracker} from './analytics'
import {AppNavigator} from './navigation'
import type {NavigationState} from 'react-navigation'

// gets the current screen from navigation state
function getCurrentRouteName(navigationState: NavigationState): ?string {
  if (!navigationState) {
    return null
  }
  const route = navigationState.routes[navigationState.index]
  // dive into nested navigators
  if (route.routes) {
    return getCurrentRouteName(route)
  }
  return route.routeName
}

export default class App extends React.Component {
  componentDidMount() {
    OneSignal.addEventListener('received', this.onReceived)
    OneSignal.addEventListener('opened', this.onOpened)
    OneSignal.addEventListener('registered', this.onRegistered)
    OneSignal.addEventListener('ids', this.onIds)
  }

  componentWillUnmount() {
    OneSignal.removeEventListener('received', this.onReceived)
    OneSignal.removeEventListener('opened', this.onOpened)
    OneSignal.removeEventListener('registered', this.onRegistered)
    OneSignal.removeEventListener('ids', this.onIds)
  }

  onReceived(notification: any) {
    console.log('Notification received:', notification)
  }

  onOpened(openResult: any) {
    console.log('Message:', openResult.notification.payload.body)
    console.log('Data:', openResult.notification.payload.additionalData)
    console.log('isActive:', openResult.notification.isAppInFocus)
    console.log('openResult:', openResult)
  }

  onRegistered(notifData: any) {
    console.log('Device is now registered for push notifications!', notifData)
  }

  onIds(device: any) {
    console.log('Device info:', device)
  }

  trackScreenChanges(
    prevState: NavigationState,
    currentState: NavigationState,
  ) {
    const currentScreen = getCurrentRouteName(currentState)
    const prevScreen = getCurrentRouteName(prevState)

    if (currentScreen !== prevScreen) {
      tracker.trackScreenView(currentScreen)
    }
  }

  render() {
    return (
      <Provider store={store}>
        <AppNavigator onNavigationStateChange={this.trackScreenChanges} />
      </Provider>
    )
  }
}

@@ -94,16 +94,19 @@
 moment'%0A
+// 
 import O
@@ -778,16 +778,19 @@
 nent %7B%0A 
+ //
  compone
@@ -797,32 +797,35 @@
 ntDidMount() %7B%0A 
+ //
    OneSignal.add
@@ -860,32 +860,35 @@
 is.onReceived)%0A 
+ //
    OneSignal.add
@@ -920,34 +920,37 @@
 his.onOpened)%0A  
+//
   
+ 
 OneSignal.addEve
@@ -986,32 +986,35 @@
 .onRegistered)%0A 
+ //
    OneSignal.add
@@ -1047,21 +1047,27 @@
 onIds)%0A 
+ //
  %7D%0A%0A 
+ //
  compone
@@ -1085,16 +1085,19 @@
 nt() %7B%0A 
+ //
    OneSi
@@ -1148,26 +1148,29 @@
 Received)%0A  
+//
   
+ 
 OneSignal.re
@@ -1209,24 +1209,27 @@
 .onOpened)%0A 
+ //
    OneSignal
@@ -1283,16 +1283,19 @@
 tered)%0A 
+ //
    OneSi
@@ -1339,21 +1339,27 @@
 onIds)%0A 
+ //
  %7D%0A%0A 
+ //
  onRecei
@@ -1377,34 +1377,37 @@
 ation: any) %7B%0A  
+//
   
+ 
 console.log('Not
@@ -1443,21 +1443,27 @@
 ation)%0A 
+ //
  %7D%0A%0A 
+ //
  onOpene
@@ -1476,32 +1476,35 @@
 Result: any) %7B%0A 
+ //
    console.log('
@@ -1553,16 +1553,19 @@
 .body)%0A 
+ //
    conso
@@ -1626,26 +1626,29 @@
 onalData)%0A  
+//
   
+ 
 console.log(
@@ -1699,16 +1699,19 @@
 Focus)%0A 
+ //
    conso
@@ -1745,21 +1745,27 @@
 esult)%0A 
+ //
  %7D%0A%0A 
+ //
  onRegis
@@ -1781,32 +1781,35 @@
 ifData: any) %7B%0A 
+ //
    console.log('
@@ -1871,21 +1871,27 @@
 fData)%0A 
+ //
  %7D%0A%0A 
+ //
  onIds(d
@@ -1901,24 +1901,27 @@
 ce: any) %7B%0A 
+ //
    console.l
@@ -1948,16 +1948,19 @@
 evice)%0A 
+ //
  %7D%0A%0A  tr

disable onesignal in js