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

// import { configWx } from '../../tools/weixin';
// 用微信sdk获取lbs定位
var WechatSdkLocation = /*#__PURE__*/function () {
  function WechatSdkLocation() {
    _classCallCheck(this, WechatSdkLocation);
  }
  return _createClass(WechatSdkLocation, [{
    key: "getLocation",
    value: function getLocation(options) {
      return new Promise(function (resolve, reject) {
        var _a;
        if (!options.configWx) {
          reject();
          return;
        }
        var locationSuccessFlag = false;
        (_a = options.configWx) === null || _a === void 0 ? void 0 : _a.call(options, ['getLocation', 'openLocation'], []).then(function (wx) {
          var tmp = {
            type: 'gcj02',
            success: function success(res) {
              var location = {
                lat: parseFloat(res.latitude),
                lng: parseFloat(res.longitude)
              };
              resolve({
                location: location,
                flag: LocationFlag.LocationSuccess
              });
              locationSuccessFlag = true;
            },
            fail: function fail(error) {
              console.log('WechatSdkLocation', error);
              reject();
              locationSuccessFlag = false;
            },
            complete: function complete() {
              if (!locationSuccessFlag) {
                reject();
              }
            }
          };
          wx.getLocation(tmp);
        })["catch"](function (error) {
          console.log('WechatSdkLocation', error);
          reject();
        });
      });
    }
  }]);
}();

export { WechatSdkLocation as default };
