import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
import _createClass from '@babel/runtime/helpers/createClass';
import { LocationFlag } from '../location-interface.mjs';

// import { post } from '../../network/post';
// 用特权sdk获取lbs地址
var TipSdkLocation = /*#__PURE__*/function () {
  function TipSdkLocation() {
    _classCallCheck(this, TipSdkLocation);
  }
  return _createClass(TipSdkLocation, [{
    key: "getLocation",
    value: function getLocation(options) {
      return new Promise(function (resolve, reject) {
        var _a;
        if (!options.fetchTipSdkLBSRequest) {
          reject();
          return;
        }
        (_a = options.fetchTipSdkLBSRequest) === null || _a === void 0 ? void 0 : _a.call(options).then(function (response) {
          var _a, _b;
          // }))
          // post({
          //   url: 'https://a.igame.qq.com/pmdtrpc.commcgi.user.user/GetUserLbsInfo',
          //   showMsgToast: false,
          //   timeout: options.timeout,
          // }).then((response) => {
          if (response.lbsinfo) {
            if (((_a = response.lbsinfo.gpsinfo) === null || _a === void 0 ? void 0 : _a.lat) && response.lbsinfo.gpsinfo.lng) {
              var location = {
                lat: parseFloat("".concat(response.lbsinfo.gpsinfo.lat)),
                lng: parseFloat("".concat(response.lbsinfo.gpsinfo.lng))
              };
              resolve({
                location: location,
                flag: LocationFlag.LocationSuccess
              });
            } else if (((_b = response.lbsinfo.netinfo) === null || _b === void 0 ? void 0 : _b.iplat) && response.lbsinfo.netinfo.iplng) {
              var _location = {
                lat: parseFloat("".concat(response.lbsinfo.netinfo.iplat)),
                lng: parseFloat("".concat(response.lbsinfo.netinfo.iplng))
              };
              resolve({
                location: _location,
                flag: LocationFlag.LocationIpSuccess
              });
            } else {
              reject();
            }
          } else {
            reject();
          }
        })["catch"](function (error) {
          console.log('GetUserLbsInfo', error);
          reject();
        });
      });
    }
  }]);
}();

export { TipSdkLocation as default };
