import React, { useState } from 'react'
import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder'
import { View, StyleSheet, ScrollView, Platform, TouchableOpacity } from 'react-native'
import {
BusinessList as BusinessesListingController,
BusinessAndProductList,
useLanguage,
useSession,
useOrder,
useConfig,
useUtils,
ToastType,
useToast
} from 'ordering-components/native'
import { Search, WrapContent } from './styles'
import { SearchBar } from '../SearchBar'
import { OIcon, OModal, OText } from '../shared'
import { BusinessesListingParams, BusinessProductsListingParams } from '../../types'
import { NotFoundSource } from '../NotFoundSource'
import { BusinessTypeFilter } from '../BusinessTypeFilter'
import { BusinessController } from '../BusinessController'
import { useTheme } from 'styled-components/native'
import { BusinessProductsListingContainer } from '../BusinessProductsListing/styles'
import { BusinessProductsList } from '../BusinessProductsList'
import { ProductForm } from '../ProductForm'
import { UpsellingProducts } from '../UpsellingProducts'
const PIXELS_TO_SCROLL = 1200
const SearchBusinessUI = (props: BusinessesListingParams) => {
const {
navigation,
businessesList,
searchValue,
getBusinesses,
handleChangeBusinessType,
handleBusinessClick,
paginationProps,
handleChangeSearch
} = props
const theme = useTheme();
const styles = StyleSheet.create({
container: {
marginBottom: 0
},
welcome: {
flex: 1,
flexDirection: 'row'
},
inputStyle: {
backgroundColor: theme.colors.clear,
flex: 1,
paddingStart: 12,
},
wrapperOrderOptions: {
width: '100%',
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 10,
zIndex: 100
},
borderStyle: {
}
})
const [, t] = useLanguage()
const [{ user, auth }] = useSession()
const [orderState] = useOrder()
const [{ configs }] = useConfig()
const [{ parseDate }] = useUtils()
const [, { showToast }] = useToast()
const [isFilter, setIsFilter] = useState(false);
const configTypes = configs?.order_types_allowed?.value.split('|').map((value: any) => Number(value)) || []
const handleScroll = ({ nativeEvent }: any) => {
const y = nativeEvent.contentOffset.y
const height = nativeEvent.contentSize.height
const hasMore = !(paginationProps.totalPages === paginationProps.currentPage)
if (y + PIXELS_TO_SCROLL > height && !businessesList.loading && hasMore) {
getBusinesses()
showToast(ToastType.Info, 'loading more business')
}
}
return (
handleChangeSearch('')}
placeholder={t('FIND_BUSINESS', 'Find a Business')}
/>
setIsFilter(!isFilter)}>
handleScroll(e)}>
{isFilter && }
{
!businessesList.loading && businessesList.businesses.length === 0 && (
)
}
{!businessesList.loading && businessesList.businesses.length > 0 && (
businessesList.businesses?.map((business: any) => (
))
)
}
{businessesList.loading && (
<>
{[...Array(paginationProps.nextPageItems ? paginationProps.nextPageItems : 8).keys()].map((item, i) => (
))}
>
)}
)
}
const SearchBusinessList = (businessProps: BusinessesListingParams) => {
const BusinessesListingProps = {
...businessProps,
isForceSearch: Platform.OS === 'ios',
UIComponent: SearchBusinessUI
}
return
}
const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
const {
navigation,
errors,
businessState,
categoryState,
handleChangeSearch,
categorySelected,
searchValue,
handleSearchRedirect,
featuredProducts,
errorQuantityProducts,
header,
logo,
productModal,
handleChangeCategory,
setProductLogin,
updateProductModal
} = props
const theme = useTheme()
const [, t] = useLanguage()
const [{ auth }] = useSession()
const [orderState] = useOrder()
const [{ parsePrice }] = useUtils()
const { business, loading, error } = businessState
const [openBusinessInformation, setOpenBusinessInformation] = useState(false)
const [curProduct, setCurProduct] = useState(null)
const [openUpselling, setOpenUpselling] = useState(false)
const [canOpenUpselling, setCanOpenUpselling] = useState(false)
const styles = StyleSheet.create({
mainContainer: {
flex: 1,
},
BackIcon: {
paddingRight: 20,
},
headerItem: {
flexDirection: 'row',
alignItems: 'center',
marginHorizontal: 20,
},
btnBackArrow: {
borderWidth: 0,
color: '#FFF',
backgroundColor: 'transparent',
borderRadius: 24,
marginRight: 15,
},
searchIcon: {
borderWidth: 0,
color: '#FFF',
backgroundColor: 'rgba(0,0,0,0.3)',
borderRadius: 24,
padding: 15,
justifyContent: 'center'
}
})
const currentCart: any = Object.values(orderState.carts).find((cart: any) => cart?.business?.slug === business?.slug) ?? {}
const onRedirect = (route: string, params?: any) => {
navigation.navigate(route, params)
}
const onProductClick = (product: any) => {
setCurProduct(product)
}
const handleCancel = () => {
handleChangeSearch('')
}
const handleCloseProductModal = () => {
setCurProduct(null)
updateProductModal && updateProductModal(null)
}
const handlerProductAction = () => {
handleCloseProductModal()
}
const handleUpsellingPage = () => {
onRedirect('CheckoutNavigator', {
screen: 'CheckoutPage',
cartUuid: currentCart?.uuid,
businessLogo: logo,
businessName: business?.name,
cartTotal: currentCart?.total
})
setOpenUpselling(false)
}
return (
<>
0 && categoryState.products.length !== 0}
contentContainerStyle={{ paddingBottom: 40 }}
showsVerticalScrollIndicator={false}
>
{!loading && business?.id && (
<>
a.rank - b.rank)
]}
category={categorySelected}
categoryState={categoryState}
businessId={business.id}
errors={errors}
onProductClick={onProductClick}
handleSearchRedirect={handleSearchRedirect}
featured={featuredProducts}
searchValue={searchValue}
handleClearSearch={handleChangeSearch}
errorQuantityProducts={errorQuantityProducts}
handleCancelSearch={handleCancel}
/>
>
)}
{openUpselling && (
)}
>
)
}
const SearchProductsListing = (props: BusinessProductsListingParams) => {
const businessProductslistingProps = {
...props,
UIComponent: BusinessProductsListingUI
}
return (
)
}
interface SearchProps {
bProps: BusinessesListingParams,
pProps: BusinessProductsListingParams
}
export const SearchList = ({ bProps, pProps }: SearchProps) => {
return (
//
//
//
)
}