import axios from "axios";

export const apiClient = axios.create({
  baseURL: process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000",
  timeout: 10000,
  headers: {
    "Content-Type": "application/json",
  },
});

export async function sendContactMessage(payload: {
  name: string;
  phone: string;
  message?: string;
  productSlug?: string;
  lang?: "uz" | "ru";
}) {
  try {
    const response = await apiClient.post("/api/contact", payload);
    return { success: true, data: response.data };
  } catch (error) {
    if (axios.isAxiosError(error)) {
      return {
        success: false,
        error: error.response?.data?.error || "Failed to send message",
      };
    }
    return { success: false, error: "Network error" };
  }
}
