import axios from '@/axios-client.js';
import store from '../store';


const baseUrl = store.state.configuration.VUE_APP_DJANGO_API_BASE;

const mapAPI = {

  async postOrPut({ basemap, projectSlug, newBasemapIds }) {
    basemap['project'] = projectSlug;
    if (newBasemapIds.includes(basemap.id)) {
      return axios
        .post(`${baseUrl}base-maps/`, basemap)
        .then((response) => response)
        .catch((error) => {
          throw error;
        });
    } else {
      return axios
        .put(`${baseUrl}base-maps/${basemap.id}/`, basemap)
        .then((response) => response)
        .catch((error) => {
          throw error;
        });
    }
  }


};

export default mapAPI;