import React, { useState, useEffect } from 'react'
import {
useLanguage,
useEvent,
useUtils,
useConfig,
OrderDetails as OrderDetailsController
} from 'ordering-components/native'
import { View, StyleSheet, TouchableOpacity, Linking } from 'react-native'
import { useTheme } from 'styled-components/native'
import { OText, OButton, OIcon } from '../shared'
import LinearGradient from 'react-native-linear-gradient'
import {
SingleOrderContainer,
StaturBar,
Icons
} from './styles'
import { getOrderStatus } from '../../utils'
const SingleOrderCardUI = (props: any) => {
const {
navigation,
orderTypes,
readMessages,
messages,
setMessages,
handleGoToOrderDetails,
showProgressBar
} = props
const { order } = props.order
const theme = useTheme()
const [, t] = useLanguage()
const [{ parseDate, parsePrice }] = useUtils()
const [{ configs }] = useConfig()
const hideIndividualButton = configs.multi_business_checkout_remove_individual_buttons?.value === '1'
const styles = StyleSheet.create({
statusBar: {
height: 12,
}
})
const handleGoToMessages = (type: string) => {
readMessages && readMessages();
navigation.navigate(
'MessageDetails',
{
type,
order,
messages,
setMessages,
orderId: order?.id,
business: type === 'business',
driver: type === 'driver',
onClose: () => navigation?.canGoBack()
? navigation.goBack()
: navigation.navigate('BottomTab', { screen: 'MyOrders' }),
}
)
}
return (
{t('ORDER', 'Order')} #{order.id}
{orderTypes?.find((type: any) => order?.delivery_type === type?.value)?.text}:
{
order?.delivery_datetime_utc
? parseDate(order?.delivery_datetime_utc)
: parseDate(order?.delivery_datetime, { utc: false })
}
{!hideIndividualButton && (
handleGoToOrderDetails(order?.uuid)}
textStyle={{ color: theme.colors.primary, textAlign: 'center', fontSize: 14 }}
style={{ flexDirection: 'row', justifyContent: 'center', borderRadius: 7.6, shadowOpacity: 0, paddingLeft: 5, paddingRight: 5, height: 44 }}
text={t('ORDER_DETAILS', 'Order Details')}
bgColor={theme.colors.white}
borderColor={theme.colors.primary}
/>
)}
{t('FROM', 'From')}
{order?.business?.name}
{!!order?.business?.cellphone && (
order?.business?.cellphone &&
Linking.openURL(`tel:${order?.business?.cellphone}`)
}
style={{ paddingEnd: 5 }}
>
)}
handleGoToMessages('business')}>
{order?.business?.email}
{!!order?.business?.cellphone && (
{order?.business?.cellphone}
)}
{order?.business?.address}
{showProgressBar && (
<>
{getOrderStatus(order?.status, t)?.value}
>
)}
{t('EXPORT_ORDER_TOTAL', 'Order total')}: {parsePrice(order?.summary?.total ?? order?.total)}
)
}
export const SingleOrderCard = (props: any) => {
const [, t] = useLanguage()
const orderDetailsProps = {
...props,
orderTypes: props.orderTypes || [
{ value: 1, text: t('DELIVERY', 'Delivery') },
{ value: 2, text: t('PICKUP', 'Pickup') },
{ value: 3, text: t('EAT_IN', 'Eat in') },
{ value: 4, text: t('CURBSIDE', 'Curbside') },
{ value: 5, text: t('DRIVE_THRU', 'Drive thru') }
],
UIComponent: SingleOrderCardUI
}
return (
)
}