import React from 'react' import { useLanguage, useSession, useOrder, useConfig, useUtils } from 'ordering-components/native'; import { Platform, ScrollView, StyleSheet, TouchableOpacity, View } from 'react-native'; import { OIcon, OModal, OText } from '../../../shared' import { useTheme } from 'styled-components/native'; import { OrderProgress } from '../../../OrderProgress'; import { useIsFocused } from '@react-navigation/native'; import { Search, OrderControlContainer, AddressInput, WrapMomentOption, HeaderWrapper, ListWrapper, FeaturedWrapper, FarAwayMessage, AddressInputContainer, PreorderInput, OrderTypesContainer } from './styles'; import { BusinessFeaturedController } from '../../../BusinessFeaturedController'; import { HighestRatedBusinesses } from '../../../HighestRatedBusinesses'; import { PageBanner } from '../../../PageBanner'; import { NotFoundSource } from '../../../NotFoundSource'; import { BusinessTypeFilter } from '../../../BusinessTypeFilter'; import { OrderTypeSelector } from '../../../OrderTypeSelector'; import { getTypesText } from '../../../../utils'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import Ionicons from 'react-native-vector-icons/Ionicons' import { CitiesControl } from '../../../CitiesControl'; export const FlatListBusinessListHeader = (props: any) => { const { navigation, businessesList, handleChangeBusinessType, handleBusinessClick, businessId, isGuestUser, citiesState, enabledPoweredByOrdering, orderTypeValue, setIsOpenCities, allCitiesDisabled, featuredBusiness, favoriteIds, setFavoriteIds, setOrderTypeValue, isFarAway, isOpenCities, handleChangeCity } = props const theme = useTheme() const [{ user, auth }] = useSession() const [orderState] = useOrder() const [{ configs }] = useConfig() const isFocused = useIsFocused() const [, t] = useLanguage() const [{ parseDate }] = useUtils(); const { top } = useSafeAreaInsets(); const hideCities = (theme?.business_listing_view?.components?.cities?.hidden || orderState?.options?.type !== 2 || allCitiesDisabled) ?? true const hideHero = theme?.business_listing_view?.components?.business_hero?.hidden const hidePreviousOrders = theme?.business_listing_view?.components?.previous_orders_block?.hidden const hideHighestBusiness = theme?.business_listing_view?.components?.highest_rated_business_block?.hidden const isAllCategoriesHidden = theme?.business_listing_view?.components?.categories?.hidden const bgHeader = theme?.business_listing_view?.components?.business_hero?.components?.image const bgHeaderHeight = theme?.business_listing_view?.components?.business_hero?.components?.style?.height const isChewLayout = theme?.header?.components?.layout?.type?.toLowerCase() === 'chew' const chewOrderTypes = [{ name: t('DELIVERY', 'Delivery').toUpperCase(), value: 1 }, { name: t('PICKUP', 'Pickup').toUpperCase(), value: 2 }] const isPreOrderSetting = configs?.preorder_status_enabled?.value === '1' const isPreorderEnabled = (configs?.preorder_status_enabled?.value === '1' || configs?.preorder_status_enabled?.value === 'true') && Number(configs?.max_days_preorder?.value) > 0 const configTypes = configs?.order_types_allowed?.value .split('|') .map((value: any) => Number(value)) || []; const styles = StyleSheet.create({ container: { marginBottom: 0, }, welcome: { flex: 1, flexDirection: 'row', }, inputStyle: { backgroundColor: theme.colors.inputDisabled, flex: 1, }, wrapperOrderOptions: { width: '100%', flexDirection: 'row', justifyContent: 'center', marginBottom: 10, zIndex: 100, }, borderStyle: { borderColor: theme.colors.backgroundGray, borderWidth: 1, borderRadius: 10, }, searchInput: { fontSize: 16, backgroundColor: theme.colors.white, paddingLeft: 10, paddingTop: 7 }, iconStyle: { fontSize: 18, color: theme.colors.warning5, marginRight: 8 }, farAwayMsg: { paddingVertical: 6, paddingHorizontal: 20 }, inputContainerStyles: { backgroundColor: theme.colors.white, borderColor: theme.colors.backgroundGray, borderWidth: 1, }, buttonCityStyle: { backgroundColor: theme.colors.white, borderColor: theme.colors.backgroundGray, borderRadius: 8, marginHorizontal: 20, minHeight: 45, paddingVertical: 5, paddingHorizontal: 20, borderWidth: 1, justifyContent: 'center' }, businessSkeleton: { borderRadius: 8, marginRight: 20, width: 56, height: 56 }, }); const handleMomentClick = () => { if (isPreorderEnabled) { navigation.navigate('MomentOption') } } return ( <> {enabledPoweredByOrdering && auth && ( Powered By Ordering.co )} {isChewLayout && ( {t('WELCOME', 'Welcome')} {user?.name} )} auth ? navigation.navigate('AddressList', { isFromBusinesses: true }) : navigation.navigate('AddressForm', { address: orderState.options?.address, isFromBusinesses: true, isGuestUser: isGuestUser }) }> {orderState?.options?.address?.address || t('WHAT_IS_YOUR_ADDRESS', 'What\'s your address?')} {!isChewLayout && ( )} {isFarAway && !isChewLayout && ( {t('YOU_ARE_FAR_FROM_ADDRESS', 'You are far from this address')} )} {!isChewLayout ? ( {isPreOrderSetting && ( handleMomentClick()}> {orderState.options?.moment ? parseDate(orderState.options?.moment, { outputFormat: configs?.dates_moment_format?.value }) : t('ASAP_ABBREVIATION', 'ASAP')} {isPreorderEnabled && ( )} )} navigation.navigate('OrderTypes', { configTypes: configTypes, setOrderTypeValue })}> {t(getTypesText(orderTypeValue || orderState?.options?.type || 1), 'Delivery')} ) : ( <> {isPreOrderSetting && ( handleMomentClick()} > {orderState.options?.moment ? parseDate(orderState.options?.moment, { outputFormat: configs?.dates_moment_format?.value }) : t('ASAP_ABBREVIATION', 'ASAP')} )} )} {!isChewLayout ? ( <> {!hideHero ? ( {!auth && ( navigation?.canGoBack() && navigation.goBack()} style={{ position: 'absolute', marginStart: 20, paddingVertical: 20 }}> )} ) : ( <> {!auth && ( navigation?.canGoBack() && navigation.goBack()} style={{ position: 'absolute', marginStart: 20, paddingVertical: 20 }}> )} )} ) : ( )} {!hideCities && orderTypeValue === 2 && ( setIsOpenCities(true)} disabled={orderState?.loading} > {citiesState?.cities?.find((city: any) => city?.id === orderState?.options?.city_id)?.name || t('FILTER_BY_CITY', 'Filter by city')} )} {!hidePreviousOrders && ( )} { !businessId && !props.franchiseId && featuredBusiness && featuredBusiness.length > 0 && ( {t('BUSINESS_FEATURE', 'Featured business')} {featuredBusiness.map((bAry: any, idx: number) => ( {bAry.length > 1 && ( )} ))} ) } {!isChewLayout && !hideHighestBusiness && ( <> { !businessId && !props.franchiseId && ( ) } )} {!businessId && !isAllCategoriesHidden && ( )} {!businessesList.loading && businessesList.businesses.length === 0 && businessesList?.fetched && ( )} setIsOpenCities(false)} title={t('SELECT_A_CITY', 'Select a city')} > setIsOpenCities(false)} handleChangeCity={handleChangeCity} /> ) }