import React, { useEffect } from 'react';
import {
BusinessList as BusinessesListingController,
useLanguage,
useOrder
} from 'ordering-components/native';
import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
import { View, ScrollView, Platform, Dimensions } from 'react-native';
import { OText } from '../shared';
import { HighestRatedBusinessesParams } from '../../types';
import { BusinessController } from '../BusinessController'
import { NotFoundSource } from '../NotFoundSource'
import {
ListWrapper
} from './styles'
const HighestRatedBusinessesUI = (props: HighestRatedBusinessesParams) => {
const {
businessesList,
onBusinessClick,
navigation,
isLoading,
getBusinesses,
favoriteIds,
setFavoriteIds,
handleUpdateBusinessList
} = props;
const [, t] = useLanguage()
const [orderState] = useOrder()
const windowWidth = Dimensions.get('window').width;
useEffect(() => {
if (businessesList?.loading || !isLoading) return
getBusinesses(true)
}, [isLoading])
useEffect(() => {
if (!businessesList?.businesses?.length) return
const ids = [...favoriteIds]
businessesList.businesses.forEach(business => {
if (business?.favorite) {
ids.push(business.id)
}
})
setFavoriteIds([...new Set(ids)])
}, [businessesList?.businesses?.length])
return (
<>
{businessesList.loading ? (
<>
{[
...Array(10).keys()
].map((item, i) => (
))}
>
) : (
<>
{businessesList.businesses.length > 0 && (
{t('HIGHEST_RATED', 'Highest rated')}
{t('TOP_RATINGS_AND_GREAT_SERVICE', 'Top ratings and great service')}
{
businessesList.businesses?.map(
(business: any) => (
)
)
}
)}
>
)}
>
)
}
export const HighestRatedBusinesses = (props: any) => {
const highestRatedBusinessesProps = {
...props,
UIComponent: HighestRatedBusinessesUI,
initialOrderByValue: 'rating'
};
return ;
};