import React, { useState } from 'react';
import { View, StyleSheet, Dimensions, FlatList, KeyboardAvoidingView, Platform } from 'react-native';
import {
PaymentOptionStripe as PaymentOptionStripeController,
useSession,
useLanguage
} from 'ordering-components/native';
import { PlaceholderLine } from 'rn-placeholder';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { getIconCard } from '../../utils';
import { OAlert, OButton, OModal, OText } from '../shared';
import { NotFoundSource } from '../NotFoundSource';
import { StripeElementsForm } from '../StripeElementsForm';
import {
OSContainer,
OSItem,
OSItemContent,
OSItemActions,
OSWrapper,
OSActions
} from './styles';
import { useTheme } from 'styled-components/native';
const PaymentOptionStripeUI = (props: any) => {
const {
onSelectCard,
onCancel,
deleteCard,
cardSelected,
cardsList,
handleCardClick,
handleNewCard
} = props;
const theme = useTheme();
const [{ token }] = useSession();
const [, t] = useLanguage();
const [addCartOpen, setAddCardOpen] = useState(false)
const _handleNewCard = (card: any) => {
setAddCardOpen(false);
handleNewCard(card);
}
const handleDeleteCard = (card: any) => {
deleteCard(card);
};
const renderCards = ({ item }: any) => {
return (
handleCardClick(item)}>
{item.id === cardSelected?.id ? (
) : (
)}
{getIconCard(item.brand, 26)}
XXXX-XXXX-XXXX-{item.last4}
handleDeleteCard(item)}
>
)
}
return (
{token && !cardsList.loading && cardsList.cards && cardsList.cards.length === 0 && (
{t('YOU_DONT_HAVE_CARDS', 'You don\'t have cards')}
)}
{token && cardsList.error && cardsList.error.length > 0 && (
)}
{token && cardsList.cards && cardsList.cards.length > 0 && (
card.id?.toString()}
style={{ height: '65%', flexGrow: 0 }}
/>
)}
{token && !cardsList.loading && (
setAddCardOpen(true)}
/>
onCancel()}
/>
onSelectCard(cardSelected)}
/>
)}
setAddCardOpen(false)}
>
setAddCardOpen(false)}
/>
{token && cardsList.loading && (
<>
{[...Array(5)].map((_, i) => (
))}
>
)}
)
}
const screenHeight = Dimensions.get('window').height;
const styles = StyleSheet.create({
container: {
height: screenHeight - 90
},
bottom: {
position: 'absolute',
bottom: 0,
marginBottom: 20
},
viewStyle: {
marginRight: 10
},
btnAddStyle: {
marginTop: 20
},
btnAction: {
paddingHorizontal: 20
}
})
export const PaymentOptionStripe = (props: any) => {
const paymentOptionStripeProps = {
...props,
UIComponent: PaymentOptionStripeUI
}
return (
)
}