import Header from "@/components/common/Header"; import ProgressCard from "@/components/common/ProgressCard"; import { RootState } from "@/store/rootReducer"; import { useRouter } from "expo-router"; import React from "react"; import { useTranslation } from "react-i18next"; import { View, Text, StyleSheet, TouchableOpacity, RootViewStyleProvider, ScrollView, } from "react-native"; import { useSelector } from "react-redux"; const MyPlanScreen: React.FC = () => { const myPlan = useSelector((state: RootState) => state.payments.myPlan); const advance_balance = useSelector( (state: RootState) => state.payments.advance_balance ); const dueAmount = useSelector( (state: RootState) => state.payments.due_amount ); const router = useRouter(); // Helper function to format currency const formatCurrency = (amount?: number | null): string => { if (amount == null) return "---"; return `₹${amount.toLocaleString("en-IN")}`; }; // Helper function to display value or fallback const displayValue = (value?: string | number | null): string => { if (value == null || value === "") return "---"; return value.toString(); }; // Calculate progress percentage for EMI progress bar const getProgressPercentage = ( firstValue: number, secondValue: number ): number => { if (!firstValue || !secondValue) return 0; return (firstValue / secondValue) * 100; }; const { t } = useTranslation(); return (
{/* Plan Details Card */} {t("payment.plan-details")} {/* Plan Type Row */} {t("payment.plan-type")} {displayValue(myPlan?.no_of_emi)} {/* Total Cost Row */} {t("payment.total-cost")} {formatCurrency(myPlan?.total_amount)} {/* Down Payment Row */} {t("payment.down-payment")} {formatCurrency(myPlan?.down_payment)} {/* Total EMI Row */} {t("payment.total-emi")} {formatCurrency(myPlan?.total_emi)} {/* Total Amount Due Card */} {t("payment.total-amount-due")} {formatCurrency(dueAmount)} {/* Monthly EMI Card */} {t("payment.monthly-emi")} {formatCurrency(myPlan?.emi_amount)} {t("payment.installments-paid")} {displayValue(myPlan?.installment_paid)} / {displayValue(myPlan?.no_of_emi)} {t("payment.advance-amount")} {formatCurrency(advance_balance)} router.push("/payments/selectAmount")} > {t("payment.pay-emi")} ); }; const styles = StyleSheet.create({ amount: { fontSize: 14, fontWeight: "600", color: "#252A34", height: 20, lineHeight: 20, }, container: { flex: 1, backgroundColor: "#F3F5F8", }, headerTitle: { fontSize: 18, fontWeight: "600", color: "#252A34", }, contentFrame: { flex: 1, paddingHorizontal: 16, paddingBottom: 16, gap: 16, }, card: { backgroundColor: "#FCFCFC", borderRadius: 8, padding: 12, gap: 12, }, cardTitle: { fontSize: 14, fontWeight: "600", color: "#252A34", height: 20, }, divider: { height: 1, backgroundColor: "#E5E9F0", }, content: { gap: 8, }, row: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", height: 20, }, label: { fontSize: 14, fontWeight: "400", color: "#252A34", }, value: { fontSize: 14, fontWeight: "600", color: "#252A34", }, centerLabel: { fontSize: 14, fontWeight: "400", color: "#252A34", textAlign: "center", height: 20, }, amountContainer: { height: 28, justifyContent: "center", alignItems: "center", }, dueAmount: { fontSize: 20, fontWeight: "600", color: "#252A34", textAlign: "center", }, twoColumnContainer: { flexDirection: "row", gap: 16, }, halfCard: { flex: 1, backgroundColor: "#FCFCFC", borderRadius: 8, padding: 12, gap: 8, height: 72, }, installmentRow: { flexDirection: "row", alignItems: "flex-end", gap: 4, }, installmentTotal: { fontSize: 14, fontWeight: "500", color: "#565F70", }, progressAmountRow: { flexDirection: "row", alignItems: "flex-end", gap: 4, }, progressTotal: { fontSize: 14, fontWeight: "500", color: "#565F70", }, progressBarContainer: { width: "100%", height: 8, }, progressBarBackground: { width: "100%", height: 8, backgroundColor: "#E5EAF0", borderRadius: 10, overflow: "hidden", }, progressBarFill: { height: "100%", backgroundColor: "#4CAF50", borderRadius: 10, }, payButton: { backgroundColor: "#008761", borderRadius: 8, paddingVertical: 16, alignItems: "center", justifyContent: "center", }, payButtonText: { fontSize: 16, fontWeight: "600", color: "#FFFFFF", }, }); export default MyPlanScreen;