import React from 'react' import { ProductsList, useLanguage } from 'ordering-components/native' import { SingleProductCard } from '../SingleProductCard' import { NotFoundSource } from '../NotFoundSource' import { BusinessProductsListParams } from '../../types' import { OText } from '../shared' import { ProductsContainer, ErrorMessage, WrapperNotFound } from './styles' import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder' import { View } from 'react-native' const BusinessProductsListUI = (props: BusinessProductsListParams) => { const { errors, businessId, category, categories, categoryState, onProductClick, featured, searchValue, isBusinessLoading, handleSearchRedirect, handleClearSearch, errorQuantityProducts, handleCancelSearch } = props const [, t] = useLanguage() return ( {category.id && ( categoryState.products?.sort((a: any, b: any) => a.rank - b.rank).map((product: any, index: number) => ( onProductClick(product)} /> )) )} { !category.id && ( featured && categoryState?.products?.find((product: any) => product.featured) && ( <> {t('FEATURED', 'Featured')} <> {categoryState.products?.sort((a: any, b: any) => a.rank - b.rank).map((product: any, index: number) => product.featured && ( ))} ) ) } { !category.id && categories && categories.filter(category => category.id !== null).map((category, i, _categories) => { const products = categoryState.products?.filter((product: any) => category?.children?.some((cat: any) => cat?.category_id === product?.category_id) || product.category_id === category.id) || [] return ( { products.length > 0 && ( <> {category.name} <> { products?.sort((a: any, b: any) => a.rank - b.rank).map((product: any, index: number) => ( )) } ) } ) }) } { (categoryState.loading || isBusinessLoading) && ( <> {[...Array(categoryState?.pagination?.nextPageItems).keys()].map((item, i) => ( ))} ) } { !categoryState.loading && !isBusinessLoading && categoryState.products.length === 0 && !errors && !((searchValue && errorQuantityProducts) || (!searchValue && !errorQuantityProducts)) && ( !searchValue ? handleSearchRedirect && handleSearchRedirect() : handleCancelSearch && handleCancelSearch()} /> ) } {errors && errors.length > 0 && ( errors.map((e: any, i: number) => ( ERROR: {e} )) )} ) } export const BusinessProductsList = (props: BusinessProductsListParams) => { const businessProductsListProps = { ...props, UIComponent: BusinessProductsListUI } return ( ) }