import axios from 'axios'

// In dev, leave VITE_API_BASE_URL empty and let Vite proxy /api → Django.
// In prod, set VITE_API_BASE_URL=https://api.risingcompute.in (or same origin).
const baseURL = (import.meta.env.VITE_API_BASE_URL || '') + '/api'

const client = axios.create({
  baseURL,
  timeout: 15000,
  headers: { 'Content-Type': 'application/json' },
})

export const api = {
  // Content
  listProducts: () => client.get('/products/').then(r => r.data),
  getProduct: (slug) => client.get(`/products/${slug}/`).then(r => r.data),
  listFounders: () => client.get('/founders/').then(r => r.data),
  listPosts: () => client.get('/posts/').then(r => r.data),
  getPost: (slug) => client.get(`/posts/${slug}/`).then(r => r.data),
  listJobs: () => client.get('/jobs/').then(r => r.data),

  // Submissions
  submitContact: (payload) => client.post('/contact/', payload).then(r => r.data),
  subscribeNewsletter: (email, source = '') =>
    client.post('/newsletter/', { email, source }).then(r => r.data),
  submitApplication: (formData) =>
    client.post('/apply/', formData, {
      headers: { 'Content-Type': 'multipart/form-data' },
    }).then(r => r.data),
}

export default client
