import { Box } from '@vtex/store-ui' import React, { Fragment } from 'react' import { ItemContextProvider } from './ItemContext' import { AVAILABLE } from './constants/Availability' interface Props { items: any[] loading: boolean onQuantityChange: (uniqueId: string, value: number, item?: any) => void onRemove: (uniqueId: string, item?: any) => void } export const ProductList: React.FC = ({ items, loading, onQuantityChange, onRemove, children, }) => { const [availableItems, unavailableItems] = items.reduce( (acc: any, item) => { acc[item.availability === AVAILABLE ? 0 : 1].push(item) return acc }, [[], []] ) const productList = (itemList: any) => itemList.map((item: any) => ( onQuantityChange(item.uniqueId, value, item), onRemove: () => onRemove(item.uniqueId, item), }} > {children} )) return ( {unavailableItems.length > 0 ? ( {unavailableItems.length} unavailable products ) : null} {productList(unavailableItems)} {unavailableItems.length > 0 && availableItems.length > 0 ? ( {availableItems.length} available products ) : null} {productList(availableItems)} ) }