import axios from "axios";

//axios.defaults.headers.common = { 'X-Requested-With': 'XMLHttpRequest' }
axios.defaults.baseURL = (process.env.NODE_ENV !== 'production') ? 'http://localhost/app_dev.php/' : ''

export default {
    user: {
        login: credentials =>
            axios.post("/api/login_check", { username: credentials.email, password: credentials.password }).then(res => res.data)
    },
    ads: {
        fetchAd: (id) => {
            console.debug("--- fetchAd")
            console.debug(id)
            return axios.get(`api/ads/${id}`).then(res => res.data)
        },
        fetchAds: ({ limit = "", order = "", keyword = "", offset = 1 }) => {
            console.debug("--- fetchAds" + offset, limit, order, keyword)
            return axios.get('api/ads', { params: { offset, limit, order, keyword } })
                .then(res => res.data)
        }
    },
    companies: {
        fetchCompany: id =>
            axios.get(`api/companies/${id}`).then(res => res.data),
        fetchCompanies: (limit = "", order = "", keyword = "", offset = 1) =>
            axios.get('api/companies', { params: { offset, limit, order, keyword } }).then(res => res.data)
    }
};
