import React, { useState } from 'react' import { Platform, StyleSheet, View, Vibration } from 'react-native' import { useLanguage, useOrder, useConfig } from 'ordering-components/native' import { useTheme } from 'styled-components/native'; import { OText, OButton } from '../shared' import { CartList, CartDivider, TopActionsHeader, TopHeader } from './styles' import { OrderSummary } from '../OrderSummary'; import { Cart } from '../Cart'; import { ScrollView } from 'react-native-gesture-handler'; import IconAntDesign from 'react-native-vector-icons/AntDesign'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { UpsellingLayout } from './UpsellingLayout'; export const UpsellingContent = (props: any) => { const { onGoBack, handleUpsellingPage, onNavigationRedirect, cart, productsList } = props const theme = useTheme(); const [{ carts }] = useOrder() const [{ configs }] = useConfig() const [, t] = useLanguage() const { bottom } = useSafeAreaInsets() const [isCartsLoading, setIsCartsLoading] = useState(false) const [showTitle, setShowTitle] = useState(false) const isMultiCheckout = configs?.checkout_multi_business_enabled?.value === '1' const isChewLayout = theme?.header?.components?.layout?.type?.toLowerCase() === 'chew' const showCartList = isChewLayout const commentDelayTime = isChewLayout ? 500 : null const cartList = (carts && Object.values(carts).filter((_cart: any) => _cart?.products?.length > 0 && _cart.uuid !== cart?.uuid)) || [] const styles = StyleSheet.create({ closeUpsellingButton: { borderRadius: 7.6, borderWidth: 1, alignSelf: 'center', height: 44, shadowOpacity: 0, width: '80%', }, cancelBtn: { paddingHorizontal: 18, borderWidth: 1, borderRadius: 7.6, borderColor: theme.colors.textSecondary, height: 38 }, headerItem: { flexDirection: 'row', alignItems: 'center', marginVertical: 2, marginHorizontal: 20, }, btnBackArrow: { borderWidth: 0, width: 26, height: 26, backgroundColor: theme.colors.clear, borderColor: theme.colors.clear, shadowColor: theme.colors.clear, paddingLeft: 0, paddingRight: 0, marginLeft: 20, marginBottom: 10 }, wrapperNavbar: { paddingHorizontal: 20, paddingTop: 0, } }) const handleScroll = ({ nativeEvent: { contentOffset } }: any) => { setShowTitle(contentOffset.y > 30) } const handleClickCheckout = () => { Vibration.vibrate(100) handleUpsellingPage(cart) } return ( <> <> onGoBack()}> {showTitle && ( {t('WANT_SOMETHING_ELSE', 'Do you want something else?')} )} {productsList.length > 0 && {t('WANT_SOMETHING_ELSE', 'Do you want something else?')} } {t('YOUR_CART', 'Your cart')} {showCartList && cartList.map((cart: any, i: number) => ( ))} handleClickCheckout()} /> ) }