import axios from 'axios'

const api = axios.create({
  baseURL: 'http://10.10.10.143:3000/api',
  headers: { 'Content-Type': 'application/json' }
})

export async function getEntries() {
  const { data } = await api.get('/entries')
  return data
}

export async function createEntry(formData) {
  const { data } = await api.post('/entries', formData, {
    headers: { 'Content-Type': 'multipart/form-data' }
  })
  return data
}

export async function deleteEntry(id) {
  await api.delete(`/entries/${id}`)
}

export async function searchFoods(query) {
  const { data } = await api.get(`/foods/search?q=${encodeURIComponent(query)}`)
  return data
}