import { aliApiPromise } from '@whale.io/mini/es/utils/fn';
import { getCityList } from '../service/store';

async function chooseCity(storeId, cityList) {
  if (!cityList) {
    cityList = await getCityList(storeId);
  }

  const cityInfo = await aliApiPromise('chooseCity', {
    showLocatedCity: true,
    showHotCities: false,
    cities: cityList.map(({
      cityName,
      cityCode,
      cityFirstChar
    }) => ({
      city: cityName,
      adCode: cityCode,
      spell: cityFirstChar
    }))
  }, false);
  return cityInfo;
}

export default chooseCity;
export { getCityList };