import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
import _createClass from '@babel/runtime/helpers/createClass';
import { getAreaCode } from '../../city/city.mjs';
import { loader } from '../../loader/loader-unity.mjs';
import { tencentMapConfig, LocationFlag } from '../location-interface.mjs';
import '../../city/data.mjs';
import '../../loader/little-loader.mjs';
import '../../loader/loader.mjs';

// 用腾讯地图sdk获取lbs地址
var TencentMapLocation = /*#__PURE__*/function () {
  function TencentMapLocation() {
    _classCallCheck(this, TencentMapLocation);
  }
  return _createClass(TencentMapLocation, [{
    key: "getLocation",
    value: function getLocation(options) {
      return new Promise(function (resolve, reject) {
        function geoShowPosition(location) {
          if (!!location.province && !!location.city) {
            var retList = getAreaCode(location.province, location.city);
            if (retList.length > 1) {
              location.provinceId = retList[0] || 0;
              location.cityId = retList[1] || 0;
            }
          }
          if (location && location.type !== 'ip') {
            // 拒绝定位会使用ip地址定位
            resolve({
              location: location,
              flag: LocationFlag.LocationSuccess
            });
          } else if (location) {
            resolve({
              location: location,
              flag: LocationFlag.LocationIpSuccess
            });
          } else {
            reject();
          }
        }
        function geoShowError() {
          reject();
        }
        loader('https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js', function () {
          // @ts-ignore
          var geolocation = new window.qq.maps.Geolocation(tencentMapConfig.GEO_KEY, tencentMapConfig.GEO_REFERER);
          var tencentMapOptions = {
            timeout: options.timeout
          };
          geolocation.getLocation(geoShowPosition, geoShowError, tencentMapOptions);
        });
      });
    }
  }]);
}();

export { TencentMapLocation as default };
