import React, { useEffect } from 'react'; import { BusinessController as BusinessSingleCard, useUtils, useOrder, useLanguage, } from 'ordering-components/native'; import { OIcon, OText } from '../shared'; import { StyleSheet, TextStyle, View } from 'react-native'; import { useTheme } from 'styled-components/native'; import { BusinessControllerParams } from '../../types'; import { convertHoursToMinutes } from '../../utils'; import { Card, BusinessHero, BusinessContent, BusinessCategory, BusinessInfo, Metadata, BusinessState, } from './styles'; export const BusinessControllerUI = (props: BusinessControllerParams) => { const { business, handleClick, isBusinessOpen, businessWillCloseSoonMinutes, isHorizontal } = props; const [{ parsePrice, parseDistance, parseNumber, optimizeImage }] = useUtils(); const [orderState] = useOrder(); const [, t] = useLanguage(); const theme = useTheme(); const styles = StyleSheet.create({ headerStyle: { borderRadius: 7.6, }, businessLogo: { width: 75, height: 75, marginLeft: 20, marginBottom: 20, borderRadius: 25, justifyContent: 'flex-start', alignItems: 'flex-start', }, businessStateView: { backgroundColor: theme.colors.backgroundGray300, borderRadius: 7.6, }, businessStateText: { textAlign: 'center', paddingHorizontal: 7, paddingVertical: 4, }, metadata: { fontWeight: '400', fontSize: 10, color: theme.colors.textSecondary }, 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, borderRadius: 7.6, }, bullet: { flexDirection: 'row', alignItems: 'center' } }); 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)} style={{ width: isHorizontal ? 188 : '100%', marginEnd: isHorizontal ? 27 : 0, overflow: 'hidden' }}> {!isBusinessOpen && ( {t('CLOSED', 'CLOSED')} )} {!!businessWillCloseSoonMinutes && orderState.options?.moment === null && isBusinessOpen && ( {businessWillCloseSoonMinutes} {t('MINUTES_TO_CLOSE', 'minutes to close')} )} {!isBusinessOpen && ( {t('PREORDER', 'PREORDER')} )} {business?.name} {getBusinessType()} {t('DELIVERY_TIME', 'Delivery time') + ' \u2022 '} {convertHoursToMinutes( orderState?.options?.type === 1 ? business?.delivery_time : business?.pickup_time, )} {!isHorizontal && ( <> {t('SERVICE_FEE', 'Service fee') + ' \u2022 '} {parsePrice(business?.delivery_price)} {t('DISTANCE', 'Distance') + ' \u2022 '} {parseDistance(business?.distance)} )} ); }; export const BusinessController = (props: BusinessControllerParams) => { const BusinessControllerProps = { ...props, UIComponent: BusinessControllerUI, }; return ; };