import React, { useState } from "react"; import { View, Text, TextInput, TouchableOpacity, Image, StyleSheet, } from "react-native"; interface BuyInSelectorProps { setBuyInAmount: React.Dispatch>; } const defaultBuyInOptions = [10, 25, 50]; // Default buy-in values const BuyInSelector: React.FC = ({ setBuyInAmount }) => { const [customAmount, setCustomAmount] = useState(""); const [buyInAmount, setBuyInAmountState] = useState(null); // Store the selected amount locally const handleCustomAmountChange = (value: string) => { const numericValue = parseFloat(value); if (!isNaN(numericValue) && numericValue >= 0) { setCustomAmount(value); setBuyInAmountState(numericValue); // Update buy-in amount setBuyInAmount(numericValue); // Pass it back to parent component } else { setCustomAmount(""); setBuyInAmountState(null); // Reset if invalid setBuyInAmount(null); } }; const handleBuyInSelection = (amount: number) => { setBuyInAmountState(amount); setCustomAmount(""); setBuyInAmount(amount); // Pass it back to parent component }; return ( {/* Title with Money Icon */} Select Buy-in Amount: {/* Default Buy-In Options */} {defaultBuyInOptions.map((amount) => ( handleBuyInSelection(amount)} > {amount} ))} {/* Custom Amount Input */} Or enter a custom amount: {/* Display the selected buy-in amount */} Selected Buy-in: {buyInAmount !== null ? buyInAmount : "None"} ); }; const styles = StyleSheet.create({ container: { padding: 20, }, header: { flexDirection: "row", alignItems: "center", marginBottom: 10, }, icon: { width: 50, height: 50, marginRight: 15, }, title: { fontSize: 22, }, optionsContainer: { flexDirection: "row", justifyContent: "space-around", marginVertical: 10, }, buyInButton: { backgroundColor: "#ddd", padding: 10, borderRadius: 5, }, selectedButton: { backgroundColor: "#4caf50", }, buttonText: { fontSize: 16, }, orText: { marginTop: 10, textAlign: "center", }, input: { borderWidth: 1, borderColor: "#ccc", padding: 8, marginVertical: 10, borderRadius: 5, }, selectionText: { marginTop: 15, fontSize: 16, fontWeight: "bold", }, }); export default BuyInSelector;