'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _typeof = require('@babel/runtime/helpers/typeof');
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
var _createClass = require('@babel/runtime/helpers/createClass');
var msdk_msdk = require('../../msdk/msdk.js');
var location_locationInterface = require('../location-interface.js');
require('../../env/env.js');
require('../../loader/little-loader.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);

var SlugSdkLocation = /*#__PURE__*/function () {
  function SlugSdkLocation() {
    _classCallCheck__default["default"](this, SlugSdkLocation);
  }
  return _createClass__default["default"](SlugSdkLocation, [{
    key: "getLocation",
    value: function getLocation() {
      return new Promise(function (resolve, reject) {
        msdk_msdk.callJsBrowserAdapter().then(function () {
          if (_typeof__default["default"](window.customBrowserInterface) === 'object') {
            window.customBrowserInterface.getLocationInfo(function (result) {
              if ((result === null || result === void 0 ? void 0 : result.code) == 1) {
                var location = {
                  lat: result.latitude,
                  lng: result.longitude
                };
                resolve({
                  location: location,
                  flag: location_locationInterface.LocationFlag.LocationSuccess
                });
              } else {
                reject({
                  flag: result.code
                });
              }
            });
          } else {
            reject({
              flag: location_locationInterface.LocationFlag.LocationFailed
            });
          }
        })["catch"](function () {
          reject({
            flag: location_locationInterface.LocationFlag.LocationFailed
          });
        });
      });
    }
  }]);
}();

exports["default"] = SlugSdkLocation;
