const menuParser = (data: any) => {
  // Transform the data to match the expected format
  let products: any[] = [];
  (data.result?.menu || []).forEach((m: any) => {
    if (!m?.items?.data) return;
    
    products = [
      ...m.items.data.map((i: any) => ({
        ...i,
        categoryId: m.caregory?.id || '',
        category_name: m.caregory?.name || '',
        is_available: true,
        nameAR: i.name,
        descriptionAR: i.description,
        category_nameAR: m.caregory?.name || '',
        is_featured: false,
        order: 0,
        created_at: new Date().toISOString(),
        updated_at: new Date().toISOString(),
        ingredients: [],
        nutritionalInfo: {
          calories: 0,
          protein: 0,
          carbs: 0,
          fat: 0,
        },
      })),
      ...products,
    ];
  });
  return {
    products,
    categories: data.result.menu
    .filter((m: any) => m.items.data.length > 0)
    .map((m: any) => m.caregory),
  };
};

export default menuParser;
