import axios from 'axios';
import i18n from 'i18next';

import { URL as API_BASE_URL } from '@/utils/url';

export interface IvoryProduct {
  id: number;
  image: string | null;
  link: string | null;
  title: string;
}

interface ApiResponse {
  status: number;
  message: string;
  data: {
    data: IvoryProduct[];
    links: any;
    meta: any;
  };
}

export const getIvoryProducts = async (): Promise<IvoryProduct[]> => {
  try {
    const lang = i18n.language === 'en' ? 'en' : 'ar';
    const response = await axios.get<ApiResponse>(`${API_BASE_URL}/${lang}/ivory-products`);
    
    if (response.data && response.data.data && Array.isArray(response.data.data.data)) {
      return response.data.data.data;
    }
    return [];
  } catch (error) {
    console.error('Error fetching ivory products:', error);
    return [];
  }
};
