/**
 * @flow
 * Created by Rabbit on 2018/7/11.
 */


import { Dimensions, Platform, PixelRatio } from 'react-native';
//import type { ConnectionType } from '@react-native-community/netinfo';
const { width } = Dimensions.get('window');

const basePx = Platform.OS === 'ios' ? 750 : 720;

export const Px2Dp = function px2dp(px: number): number {
  const layoutSize = (px / basePx) * width;

  return PixelRatio.roundToNearestPixel(layoutSize);
};

export const getNetInfoStatus = (netInfo: any) => {
  const { type } = netInfo;
  return {
    isConnect: type.toUpperCase() === 'WIFI' || type.toUpperCase() === 'CELLULAR',
    isWifi: type.toUpperCase() === 'WIFI',
    isCellular: type.toUpperCase() === 'CELLULAR',
  };
};

export const findPopKey = (routes: Array, pageName) => {
  let key = '';
  if (routes.length > 0) {
    const tag = routes.find(route => route.routeName === pageName);
    key = tag.key;
  }
  return key;
};
