import Box from "@components/bases/Box";
import Text from "@components/bases/Text";
import Card from "@re-card";
import { images } from "@styles/Commons";
import * as LocalAuthentication from "expo-local-authentication";
import { useState } from "react";
import { Image, TouchableOpacity } from "react-native";

type Props = { balance: number; label: string };

const BalanceContainer = ({ label, balance }: Props) => {
	const [showBalance, setShowBalance] = useState(false);

	const handleLocalAuthentication = async () => {
		console.log("handleLocalAuthentication :: start");
		if (showBalance) {
			return setShowBalance(false);
		}
		const result = await LocalAuthentication.authenticateAsync();
		if (result.success) {
			setShowBalance(true);
		}
		console.log("handleLocalAuthentication :: end", result);
	};

	return (
		<Card position={"relative"} variant={"balanceContainer"}>
			<Card variant={"balanceContainer"} position={"absolute"}>
				<Image
					source={require("../../assets/balance_container.png")}
					style={images.cover}
				/>
			</Card>

			<Box alignItems={"center"} gap={"s"}>
				<TouchableOpacity onPress={handleLocalAuthentication}>
					<Box height={50} alignItems={"center"} justifyContent={"center"}>
						{showBalance ? (
							<Text fontSize={30} variant={"black"}>
								{balance}
							</Text>
						) : (
							<Box width={40} height={40}>
								<Image
									source={require("../../assets/eye_hidden.png")}
									style={images.contain}
								/>
							</Box>
						)}
					</Box>
				</TouchableOpacity>

				<Text color={"gray"}>{label}</Text>
			</Box>
		</Card>
	);
};

export default BalanceContainer;
