"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getPlaceByRadius = void 0;
require("core-js/modules/es.promise.js");
var _queryString = _interopRequireDefault(require("query-string"));
var _jsonp = require("@wii/jsonp");
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

const getApiUrl = params => {
  const {
    center,
    radius,
    keyWords,
    pageNo,
    pageSize,
    key,
    filter
  } = params;
  const paramsQueryStr = _queryString.default.stringify({
    boundary: `nearby(${center === null || center === void 0 ? void 0 : center.join(',')},${radius || 1000})`,
    keyword: keyWords || undefined,
    page_size: pageSize || 15,
    page_index: pageNo || 1,
    orderby: '_distance',
    key,
    output: 'jsonp',
    filter
  });
  return `https://apis.map.qq.com/ws/place/v1/search?${paramsQueryStr}`;
};
const getPlaceByRadius = options => {
  return new Promise((resolve, reject) => {
    (0, _jsonp.jsonp)(getApiUrl(options), (err, data) => {
      if (err) {
        reject(err);
      } else if (data) {
        resolve(data);
      }
    });
  });
};
exports.getPlaceByRadius = getPlaceByRadius;