// services/searchApi.js
const API_BASE_URL = process.env.NEXT_PUBLIC_APP_URL_DOMAIN; // Replace with your actual API URL

export const searchApi = {
  async searchUniversities(query) {
    try {
      const response = await fetch(`${API_BASE_URL}/api/frontend/search/universities?query=${encodeURIComponent(query)}`, {
        method: "POST",
      });
      if (!response.ok) throw new Error('Search failed');
      return await response.json();
    } catch (error) {
      console.error('University search error:', error);
      return [];
    }
  },

  async searchCourses(query) {
    try {
      const response = await fetch(`${API_BASE_URL}/api/frontend/search/courses?query=${encodeURIComponent(query)}`, {
        method: "POST"
      });
      if (!response.ok) throw new Error('Search failed');
      return await response.json();
    } catch (error) {
      console.error('Course search error:', error);
      return [];
    }
  }
};