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

export const apiLoadCategories = (callback) => {
  apiLoadList(callback, 'categories');
}

export const apiSaveSettings = (data, callback, onError) => {
  if (Configuration.getInstance().is_debug) {
    callback()
    return
  }
  const requestUrl = getAjaxActionUrl('save_settings');
  const ajax = axios.post(requestUrl, {
    data: data,
  })
  ajax.then(response => {
    if (callback) callback(response)
  }).catch(err => {
    console.error('Dreamfox WDD: AJAX error saving settings', err);
    if (onError) onError(err)
  });
}