// @flow

import './init/constants'
import './init/fetch'
import './init/moment'
import './init/analytics'
import './init/api'
import './init/theme'
import {ONESIGNAL_APP_ID} from './init/notifications'

import * as React from 'react'
import {Provider} from 'react-redux'
import {makeStore, initRedux} from './redux'
import * as navigation from './navigation'
import OneSignal from 'react-native-onesignal'
import {ThemeProvider} from '@callstack/react-theme-provider'
import {getTheme} from '@frogpond/app-theme'

const store = makeStore()
initRedux(store)

type Props = {}

export default class App extends React.Component<Props> {
	componentDidMount() {
		OneSignal.init(ONESIGNAL_APP_ID, {kOSSettingsKeyAutoPrompt: false})

		OneSignal.addEventListener('received', this.onReceived)
		OneSignal.addEventListener('opened', this.onOpened)
		OneSignal.addEventListener('ids', this.onIds)
	}

	componentWillUnmount() {
		OneSignal.removeEventListener('received', this.onReceived)
		OneSignal.removeEventListener('opened', this.onOpened)
		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)
	}

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

	render() {
		let theme = getTheme()

		return (
			<Provider store={store}>
				<ThemeProvider theme={theme}>
					<navigation.AppNavigator
						onNavigationStateChange={navigation.trackScreenChanges}
						persistenceKey={navigation.persistenceKey}
					/>
				</ThemeProvider>
			</Provider>
		)
	}
}

@@ -369,16 +369,103 @@
 neSignal
+, %7B%0A%09type OneSignalOpenResult,%0A%09type OneSignalNotification,%0A%09type OneSignalIdsResult,%0A%7D
  from 'r
@@ -1197,19 +1197,37 @@
 cation: 
-any
+OneSignalNotification
 ) %7B%0A%09%09co
@@ -1303,19 +1303,35 @@
 Result: 
-any
+OneSignalOpenResult
 ) %7B%0A%09%09co
@@ -1349,17 +1349,16 @@
 Message:
- 
 ', openR
@@ -1410,17 +1410,16 @@
 g('Data:
- 
 ', openR
@@ -1485,17 +1485,16 @@
 sActive:
- 
 ', openR
@@ -1552,17 +1552,16 @@
 nResult:
- 
 ', openR
@@ -1590,11 +1590,26 @@
 ce: 
-any
+OneSignalIdsResult
 ) %7B%0A
@@ -1635,17 +1635,16 @@
 ce info:
- 
 ', devic

add types to onesignal in app.js