import React, { useState, useRef } from "react"; import { View, Text, ScrollView, TouchableOpacity } from "react-native"; import { router, useLocalSearchParams } from "expo-router"; import ScreenWrapper from "~/components/ui/ScreenWrapper"; import BackButton from "~/components/ui/backButton"; import { AwashIcon, TeleBirrIcon } from "~/components/ui/icons"; import { LucideChevronRightCircle } from "lucide-react-native"; import { Button } from "~/components/ui/button"; import ModalToast from "~/components/ui/toast"; import { useTranslation } from "react-i18next"; import { ROUTES } from "~/lib/routes"; import { awardPoints } from "~/lib/services/pointsService"; export default function RequestProvider() { const { t } = useTranslation(); const params = useLocalSearchParams<{ amount: string; recipientName: string; recipientPhoneNumber: string; recipientType: string; recipientId: string; note: string; requestorName: string; requestorPhoneNumber: string; requestorType: string; type: string; }>(); const [selectedProvider, setSelectedProvider] = useState< "awash" | "telebirr" | null >(null); const [toastVisible, setToastVisible] = useState(false); const [toastTitle, setToastTitle] = useState(""); const [toastDescription, setToastDescription] = useState( undefined ); const [toastVariant, setToastVariant] = useState< "success" | "error" | "warning" | "info" >("info"); const toastTimeoutRef = 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 handleContinue = () => { if (!selectedProvider) { showToast( t("sendbank.toastErrorTitle"), t("sendbank.toastNoMethod"), "error" ); return; } awardPoints("make_request").catch((error) => { console.warn( "[RequestProvider] Failed to award make request points", error ); }); router.push({ pathname: ROUTES.NOTIFICATION_OPTION, params: { ...params, provider: selectedProvider, } as any, }); }; return ( {t("sendbank.paymentOptionsTitle")} {selectedProvider ? t("sendbank.paymentOptionsSelected", { providerName: selectedProvider === "awash" ? t("sendbank.awashName") : t("sendbank.telebirrName"), }) : t("sendbank.paymentOptionsUnselected")} {/* Telebirr Section */} {t("sendbank.telebirrName")} setSelectedProvider("telebirr")} className={`flex flex-row w-full justify-between items-center py-4 rounded-md px-3 mb-4 ${ selectedProvider === "telebirr" ? "bg-orange-100 border-2 border-orange-300" : "bg-green-50 border border-gray-200" }`} > {t("sendbank.telebirrName")} {t("sendbank.telebirrSubtitle")} {/* Bank Section with Awash */} Bank setSelectedProvider("awash")} className={`flex flex-row w-full justify-between items-center py-4 rounded-md px-3 ${ selectedProvider === "awash" ? "bg-blue-100 border-2 border-blue-300" : "bg-green-50 border border-gray-200" }`} > {t("sendbank.awashName")} {t("sendbank.awashSubtitle")} ); }