import React from 'react'; import { BusinessController as BusinessSingleCard, useUtils, useOrder, useLanguage, } from 'ordering-components/native'; import { useTheme } from 'styled-components/native'; import { OIcon, OText } from '../shared'; import { StyleSheet, View } from 'react-native'; import { BusinessControllerParams } from '../../types'; import { convertHoursToMinutes } from '../../utils'; import { Card, BusinessHero, BusinessContent, BusinessCategory, BusinessInfo, Metadata, BusinessState, BusinessLogo, Reviews, } from './styles'; import IconAntDesign from 'react-native-vector-icons/AntDesign'; import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome5'; import MaterialComIcon from 'react-native-vector-icons/MaterialCommunityIcons'; import MaterialIcon from 'react-native-vector-icons/MaterialIcons'; export const BusinessControllerUI = (props: BusinessControllerParams) => { const { business, handleClick, isBusinessOpen, getBusinessOffer, businessWillCloseSoonMinutes, isBusinessClose } = props; const theme = useTheme() const styles = StyleSheet.create({ headerStyle: { borderTopLeftRadius: 25, borderTopRightRadius: 25, }, businessLogo: { width: 75, height: 75, marginLeft: 20, marginBottom: 20, borderRadius: 25, justifyContent: 'flex-start', alignItems: 'flex-start', }, businessStateView: { backgroundColor: '#6C6C6C', borderRadius: 10, }, businessStateText: { color: theme.colors.white, textAlign: 'center', padding: 8, }, metadata: { marginRight: 20, marginLeft: 5, marginBottom: -5, }, starIcon: { marginTop: 1.5, marginHorizontal: 5, }, featured: { position: 'absolute', padding: 8, backgroundColor: theme.colors.backgroundDark, opacity: 0.8, borderRadius: 10, left: 20, top: 10 }, closed: { position: 'absolute', width: '100%', height: '100%', justifyContent: 'center', alignItems: 'center', backgroundColor: theme.colors.backgroundDark, opacity: 0.6, borderTopRightRadius: 25, borderTopLeftRadius: 25, }, textClosed: { bottom: 10 }, bullet: { flexDirection: 'row', alignItems: 'center' } }); const [{ parsePrice, parseDistance, parseNumber, optimizeImage }] = useUtils(); const [orderState] = useOrder(); const [, t] = useLanguage(); const types = ['food', 'laundry', 'alcohol', 'groceries']; const getBusinessType = () => { if (Object.keys(business).length <= 0) return t('GENERAL', 'General'); const _types: any = []; types.forEach((type) => { if (business[type]) { _types.push(t(type.toUpperCase(), type)); } }); return _types.join(', '); }; return ( handleClick(business)}> {business?.featured && ( )} {(!isBusinessOpen || isBusinessClose) && ( {t('CLOSED', 'CLOSED')} )} {!!businessWillCloseSoonMinutes && orderState.options?.moment === null && isBusinessOpen && ( {businessWillCloseSoonMinutes} {t('MINUTES_TO_CLOSE', 'minutes to close')} )} {(!isBusinessOpen || !!getBusinessOffer(business?.offers)) && ( {getBusinessOffer(business?.offers) && ( {getBusinessOffer(business?.offers) || parsePrice(0)} )} {!isBusinessOpen && ( {t('PREORDER', 'PREORDER')} )} )} {business?.name} {business?.reviews?.total > 0 && ( {parseNumber(business?.reviews?.total, { separator: '.' })} )} {getBusinessType()} {convertHoursToMinutes( orderState?.options?.type === 1 ? business?.delivery_time : business?.pickup_time, )} {parseDistance(business?.distance)} {parsePrice(business?.delivery_price)} ); }; export const BusinessController = (props: BusinessControllerParams) => { const BusinessControllerProps = { ...props, UIComponent: BusinessControllerUI, }; return ; };