import React from 'react'
import { useLanguage, useOrder, useConfig } from 'ordering-components/native'
import { ScrollView, StyleSheet, TouchableOpacity, View, Dimensions } from 'react-native'
import { useTheme } from 'styled-components/native'
import { OButton, OModal, OText } from '../shared'
import AntDesignIcon from 'react-native-vector-icons/AntDesign'
import {
ProductsList,
TagsContainer,
SortContainer,
BrandContainer,
BrandItem,
PriceFilterWrapper,
BContainer,
WrapperButtons
} from './styles'
import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder'
import { MaxSectionItem } from './MaxSectionItem'
export const BusinessSearchFooter = (props: any) => {
const {
businessesSearchList,
handleCloseFilters,
handleChangeFilters,
brandList,
filters,
handleChangeBrandFilter,
handleChangePriceRange,
businessTypes,
handleApplyFilters,
clearFilters,
handleChangeActiveBusinessType,
openFilters
} = props
const screenHeight = Dimensions.get('window').height;
const theme = useTheme()
const [orderState] = useOrder()
const [, t] = useLanguage()
const [{ configs }] = useConfig()
const maxDeliveryFeeOptions = [15, 25, 35, 'default']
// const maxProductPriceOptions = [5, 10, 15, 'default']
const maxDistanceOptions = [1000, 2000, 5000, 'default']
const maxTimeOptions = [5, 15, 30, 'default']
const sortItems = [
{ text: t('PICKED_FOR_YOU', 'Picked for you (default)'), value: 'distance' },
{ text: t('DELIVERY_TIME', 'Delivery time'), value: 'delivery_time' },
{ text: t('PICKUP_TIME', 'Pickup time'), value: 'pickup_time' }
]
const priceList = [
{ level: '1', content: '$' },
{ level: '2', content: '$$' },
{ level: '3', content: '$$$' },
{ level: '4', content: '$$$$' },
{ level: '5', content: '$$$$$' }
]
const filterOptionsEnabled = configs?.filter_search_options?.value?.split('|') || []
const styles = StyleSheet.create({
container: {
paddingHorizontal: 40,
width: '100%'
},
filterContainer: {
maxHeight: screenHeight - 150,
paddingHorizontal: 20,
width: '100%'
},
businessTypesContainer: {
width: '100%',
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center'
},
priceContainer: {
width: '100%',
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-between'
},
categoryStyle: {
marginRight: 10,
marginTop: 10,
borderRadius: 50,
paddingHorizontal: 10,
paddingVertical: 4,
paddingLeft: 0,
paddingRight: 0,
height: 28,
borderWidth: 0
},
priceItem: {
marginRight: 10,
marginTop: 10,
borderRadius: 50,
paddingVertical: 4,
paddingLeft: 5,
paddingRight: 5,
height: 27,
borderWidth: 0
},
applyButton: {
paddingHorizontal: 10,
width: '100%',
marginTop: 20
}
});
return (
<>
{businessesSearchList?.loading && (
<>
{[...Array(3).keys()].map(
(item, i) => (
),
)}
>
)}
handleCloseFilters()}
onClose={() => handleCloseFilters()}
>
{t('FILTER', 'Filter')}
{filterOptionsEnabled.includes('sort') && (
{t('SORT', 'Sort')}
{sortItems?.filter(item => !(orderState?.options?.type === 1 && item?.value === 'pickup_time') && !(orderState?.options?.type === 2 && item?.value === 'delivery_time'))?.map(item => (
handleChangeFilters('orderBy', item?.value)}
style={{ marginBottom: 7 }}
>
{item?.text} {(filters?.orderBy?.includes(item?.value)) && <>{filters?.orderBy?.includes('-') ? : }>}
))}
)}
{filterOptionsEnabled.includes('brands') && (
{t('BRANDS', 'Brands')}
{!brandList?.loading && !brandList?.error && brandList?.brands?.length > 0 && (
{brandList?.brands.map((brand: any, i: number) => brand?.enabled && (
handleChangeBrandFilter(brand?.id)}
>
{brand?.name}
{filters?.franchise_ids?.includes(brand?.id) && (
)}
))}
)}
{!brandList?.loading && ((brandList?.brands?.filter((brand: any) => brand?.enabled))?.length === 0) && (
{t('NO_RESULTS_FOUND', 'Sorry, no results found')}
)}
)}
{filterOptionsEnabled.includes('price_range') && (
{t('PRICE_RANGE', 'Price range')}
{priceList.map((price: any, i: number) => (
handleChangePriceRange(price?.level)}
text={`${price.content} ${(filters?.price_level === price?.level) ? ' X' : ''}`}
style={styles.priceItem}
textStyle={{ fontSize: 10, color: (filters?.price_level === price?.level) ? theme.colors.white : theme.colors.textNormal }}
/>
))}
)}
{orderState?.options?.type === 1 && filterOptionsEnabled.includes('max_delivery_fee') && (
)}
{[1, 2].includes(orderState?.options?.type) && filterOptionsEnabled.includes('max_delivery_time') && (
)}
{filterOptionsEnabled.includes('max_distance') && (
)}
{businessTypes?.length > 0 && filterOptionsEnabled.includes('business_categories') && (
{t('BUSINESS_CATEGORIES', 'Business categories')}
{businessTypes.map((type: any, i: number) => type.enabled && (
handleChangeActiveBusinessType(type)}
text={`${t(`BUSINESS_TYPE_${type.name.replace(/\s/g, '_').toUpperCase()}`, type.name)} ${filters?.business_types?.includes(type?.id) ? 'X' : ''}`}
style={styles.categoryStyle}
textStyle={{ fontSize: 10, color: (filters?.business_types?.includes(type?.id) || (type?.id === null && filters?.business_types?.length === 0)) ? theme.colors.white : theme.colors.textNormal }}
/>
))}
)}
handleApplyFilters()}
/>
clearFilters()}
/>
>
)
}