import axios from 'axios'

const api = axios.create({
  baseURL: import.meta.env.VITE_API_BASE || '/api/public/website',
  headers: { 'Content-Type': 'application/json' },
})

export function getSermons(limit = 0, offset = 0) {
  return api.get('/sermons', { params: { limit, offset } }).then(r => r.data)
}

export function getFeaturedSermon() {
  return api.get('/sermons/featured').then(r => r.data)
}

export function getSermon(id) {
  return api.get(`/sermons/${id}`).then(r => r.data)
}

export function getVideos(limit = 0, offset = 0) {
  return api.get('/videos', { params: { limit, offset } }).then(r => r.data)
}

export function getFeaturedVideo() {
  return api.get('/videos/featured').then(r => r.data)
}

export function getAnsweredPrayers() {
  return api.get('/prayers/answered').then(r => r.data)
}

export function submitPrayerRequest(data) {
  return api.post('/prayer', data).then(r => r.data)
}

export function submitContactForm(data) {
  return api.post('/contact', data).then(r => r.data)
}

export function getChurchInfo() {
  return api.get('/info').then(r => r.data)
}

export function getAllContent() {
  return api.get('/content').then(r => r.data)
}

export function getContentByKey(key) {
  return api.get(`/content/${key}`).then(r => r.data)
}

export function getEvents(limit = 0, featured = false) {
  return api.get('/events', { params: { limit, featured: featured ? 1 : undefined } }).then(r => r.data)
}

export function getGallery(category = '') {
  return api.get('/gallery', { params: { category } }).then(r => r.data)
}

export function getGalleryCategories() {
  return api.get('/gallery/categories').then(r => r.data)
}

export function getGroups() {
  return api.get('/groups').then(r => r.data)
}

export function submitGroupJoin(data) {
  return api.post('/groups/join', data).then(r => r.data)
}

export function getTeam() {
  return api.get('/team').then(r => r.data)
}

export function getMinistries() {
  return api.get('/ministries').then(r => r.data)
}

export default api
