import { AppRegistry, Platform, Dimensions } from 'react-native'
import RN_SDK from '@hyext/hyext-rn-sdk'
import * as Wup from '@hyext/hyext-rn-sdk/wup/libwup'
import { defineProxy } from './global'

global.__os = Platform.OS
var device = global.__device = {}
defineProxy(device, 'height', () => Dimensions.get('window').height)
defineProxy(device, 'width', () => Dimensions.get('window').width)

/* 配置sentry */
if (RN_SDK && RN_SDK.setupSentry) {
  try {
    RN_SDK.setupSentry()
  } catch (err) {
    // 配置错误, 静默失败
    console.log('failed to setupSentry:', err)
  }
}

export var registerApp = (componentName, component) => {
  // eslint-disable-next-line no-undef
  if (!__DEV__) {
    console.log = () => {}
  }

  AppRegistry.registerComponent(componentName, () => component)
}

export var SDK = global.hyExt = RN_SDK
export var Taf = global.Taf = Wup.Taf
