import React from "react"; import { View, Text, ScrollView, Share } from "react-native"; import { Button } from "~/components/ui/button"; import { SafeAreaView } from "react-native-safe-area-context"; import { router, useLocalSearchParams } from "expo-router"; import { ROUTES } from "~/lib/routes"; import { SuccessIconNewCard } from "~/components/ui/icons"; import ScreenWrapper from "~/components/ui/ScreenWrapper"; import ModalToast from "~/components/ui/toast"; import { useTranslation } from "react-i18next"; export default function CardAddedComp() { const params = useLocalSearchParams<{ message?: string; cardName?: string; cardNumber?: string; }>(); const { t } = useTranslation(); const [toastVisible, setToastVisible] = React.useState(false); const [toastTitle, setToastTitle] = React.useState(""); const [toastDescription, setToastDescription] = React.useState< string | undefined >(undefined); const [toastVariant, setToastVariant] = React.useState< "success" | "error" | "warning" | "info" >("info"); const toastTimeoutRef = React.useRef | null>( null ); const showToast = ( title: string, description?: string, variant: "success" | "error" | "warning" | "info" = "info" ) => { if (toastTimeoutRef.current) { clearTimeout(toastTimeoutRef.current); } setToastTitle(title); setToastDescription(description); setToastVariant(variant); setToastVisible(true); toastTimeoutRef.current = setTimeout(() => { setToastVisible(false); toastTimeoutRef.current = null; }, 2500); }; const handleAddAnother = () => { // Navigate to add card page router.replace(ROUTES.ADD_CARD); }; const handleGoToCards = () => { // Navigate to list cards page router.replace(ROUTES.LIST_CARD); }; const handleShare = async () => { try { const shareMessage = params.message ? t("cardaddedcomp.shareMessageWithParam", { message: params.message, }) : t("cardaddedcomp.shareMessageDefault"); const result = await Share.share({ message: shareMessage, title: t("cardaddedcomp.shareTitle"), }); if (result.action === Share.sharedAction) { // Content was shared console.log("Content shared successfully"); } else if (result.action === Share.dismissedAction) { // Share dialog was dismissed console.log("Share dialog dismissed"); } } catch (error) { console.error("Error sharing:", error); showToast( t("cardaddedcomp.toastErrorTitle"), t("cardaddedcomp.toastShareError"), "error" ); } }; return ( {/* Center content */} {t("cardaddedcomp.title")} {t("cardaddedcomp.description")} {/* Bottom buttons */} ); }