import axios from 'axios';
import Configuration from '../Configuration';
import { getAjaxActionUrl } from '../utils';

const apiLoadList = (callback, listName) => {
  if (Configuration.getInstance().is_debug) {
    const config = Configuration.getInstance();
    const argData = {}
    argData[listName] = config[listName];
    callback({data: argData});
    return;
  }

  const requestUrl = getAjaxActionUrl('load_' + listName);
  const ajax = axios.post(requestUrl);
  if (callback) {
    ajax.then(response => callback(response)).catch(err => {
      console.error('Dreamfox WDD: AJAX error loading ' + listName, err);
    });
  }
}
export default apiLoadList;