"use strict";

exports.__esModule = true;
exports.windowWidth = exports.windowHeight = exports.systemInfo = exports.screenWidth = exports.screenRate = exports.screenPixelRatio = exports.screenHeight = exports.osVersion = exports.osName = exports.isStrictWechatMiniProgram = exports.isStrictMiniApp = exports.isStrictByteDanceMicroApp = exports.isProduction = exports.isMiniappPlatform = exports.isIOS = exports.isAndroid = exports.dpr = void 0;
var _env = require("@uni/env");
var _fp = require("./fp");
function formatVersion(v) {
  return String(v).replace(/_/g, '.');
}
function getOSInfo(ua) {
  var OSList = {
    ios: /(like Mac OS X)/i,
    android: /Android/i,
    wp: /Windows Phone/i,
    bb: /(BlackBerry)|(RIM)/i,
    win: /(Windows 95)|(Win95)|(Windows_95)|(Windows ME)|(Windows 98)|(Win98)|(Windows NT 5.0)|(Windows 2000)|(Windows NT)|(WinNT)|(Windows XP)/i,
    linux: /(Linux)|(X11)/i,
    macos: /(Mac_PowerPC)|(Macintosh)/i,
    robot: /(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(ia_archiver)/i
  };
  var os = {
    name: 'unknown',
    version: '0.0.0'
  };
  if (/Windows\sPhone\s(?:OS\s)?([\d.]+)/.test(ua)) {
    os.version = RegExp.$1;
  } else if (/Safari/.test(ua) && /Android[\s/]([\d.]+)/.test(ua)) {
    os.version = RegExp.$1;
  } else if (/(iPhone|iPad|iPod)/.test(ua) && /OS ([\d_.]+) like Mac OS X/.test(ua)) {
    os.version = RegExp.$1;
  }
  os.version = formatVersion(os.version);
  for (var _osName in OSList) {
    var Reg = OSList[_osName];
    if (Reg.test(ua)) {
      os.name = _osName;
      break;
    }
  }
  return os;
}
var isStrictMiniApp = _env.isMiniApp && !_env.isWeb;
exports.isStrictMiniApp = isStrictMiniApp;
var isStrictWechatMiniProgram = _env.isWeChatMiniProgram && !_env.isWeb;
exports.isStrictWechatMiniProgram = isStrictWechatMiniProgram;
var isStrictByteDanceMicroApp = _env.isByteDanceMicroApp && !_env.isWeb;
exports.isStrictByteDanceMicroApp = isStrictByteDanceMicroApp;
var isMiniappPlatform = !_env.isWeb && (_env.isMiniApp || _env.isWeChatMiniProgram || _env.isByteDanceMicroApp);
exports.isMiniappPlatform = isMiniappPlatform;
var systemInfo;
exports.systemInfo = systemInfo;
if (isStrictMiniApp) {
  exports.systemInfo = systemInfo = my.getSystemInfoSync();
} else if (isStrictWechatMiniProgram) {
  exports.systemInfo = systemInfo = wx.getSystemInfoSync();
} else if (isStrictByteDanceMicroApp) {
  exports.systemInfo = systemInfo = tt.getSystemInfoSync();
}
var name = 'unknown';
var version = '0.0.0';
if (isStrictWechatMiniProgram) {
  var _systemInfo = systemInfo,
    system = _systemInfo.system;
  name = system.split(' ')[0].toLowerCase();
  version = system.split(' ')[1];
} else if (isStrictMiniApp) {
  var _systemInfo2 = systemInfo,
    _system = _systemInfo2.system,
    platform = _systemInfo2.platform;
  name = platform.toLowerCase();
  version = _system;
} else if (isStrictByteDanceMicroApp) {
  var _systemInfo3 = systemInfo,
    _system2 = _systemInfo3.system,
    _platform = _systemInfo3.platform;
  name = _platform.toLowerCase();
  version = _system2;
} else if (_env.isNode) {
  exports.systemInfo = systemInfo = {
    screenWidth: 0,
    screenHeight: 0,
    windowWidth: 0,
    windowHeight: 0,
    devicePixelRatio: 1
  };
} else {
  var UA = (0, _fp.isUndef)(navigator) ? '' : navigator.userAgent;
  var info = getOSInfo(UA);
  name = info.name;
  version = info.version;
}
var screenWidth = systemInfo && !(0, _fp.isUndef)(systemInfo.screenWidth) ? systemInfo.screenWidth : window.screen.width;
exports.screenWidth = screenWidth;
var screenHeight = systemInfo && !(0, _fp.isUndef)(systemInfo.screenHeight) ? systemInfo.screenHeight : window.screen.height;
exports.screenHeight = screenHeight;
var windowWidth = systemInfo && !(0, _fp.isUndef)(systemInfo.windowWidth) ? systemInfo.windowWidth : document.documentElement.clientWidth;
exports.windowWidth = windowWidth;
var windowHeight = systemInfo && !(0, _fp.isUndef)(systemInfo.windowHeight) ? systemInfo.windowHeight : document.documentElement.clientHeight;
exports.windowHeight = windowHeight;
var dpr = systemInfo && (systemInfo.devicePixelRatio || systemInfo.pixelRatio) ? systemInfo.devicePixelRatio || systemInfo.pixelRatio : window.devicePixelRatio;
exports.dpr = dpr;
var osName = name;
exports.osName = osName;
var osVersion = version;
exports.osVersion = osVersion;
var isIOS = name === 'ios';
exports.isIOS = isIOS;
var isAndroid = name === 'android';
exports.isAndroid = isAndroid;
var screenRate = screenWidth / 750;
exports.screenRate = screenRate;
var screenPixelRatio = isMiniappPlatform ? 1 : windowWidth / 750;
exports.screenPixelRatio = screenPixelRatio;
var isProduction = function () {
  var result = false;
  try {
    if (process.env.NODE_ENV === 'production') {
      result = true;
    }
  } catch (err) {}
  return result;
};
exports.isProduction = isProduction;