import { useState } from "react"; import { fixedPlansApi } from "../api/fixedPlans"; import { Money } from "./ui"; type FundingConfirmationModalProps = { planId: string; planName: string; totalCents: number; fundedCents: number; availableBudget: number; onClose: () => void; onFundingComplete: (result: { totalCents: number; fundedCents: number; isOverdue?: boolean; overdueAmount?: number; message?: string; }) => void; }; export default function FundingConfirmationModal({ planId, planName, totalCents, fundedCents, availableBudget, onClose, onFundingComplete, }: FundingConfirmationModalProps) { const [isProcessing, setIsProcessing] = useState(false); const [error, setError] = useState(""); const shortfall = totalCents - fundedCents; const canFund = availableBudget >= shortfall; const handleRemindLater = () => { // Store dismissal timestamp in localStorage (4 hours from now) const dismissedUntil = Date.now() + (4 * 60 * 60 * 1000); // 4 hours localStorage.setItem(`overdue-dismissed-${planId}`, dismissedUntil.toString()); onClose(); }; const handlePullFromBudget = async () => { setError(""); setIsProcessing(true); try { const result = await fixedPlansApi.attemptFinalFunding(planId); onFundingComplete(result); } catch (err: any) { setError(err?.message || "Failed to fund from available budget"); setIsProcessing(false); } }; return (
{/* Header */}

{planName} is due today

This bill is not fully funded yet.

{/* Funding Details */}
Total amount:
Currently funded:
Still needed:
{/* Available Budget */}
Available budget:
{/* Message */} {canFund ? (
Would you like to pull from your available budget to fully fund this payment?
) : (
Insufficient available budget. You need more to fully fund this payment.
)} {/* Error */} {error && (
{error}
)} {/* Actions */}
{canFund && ( )}
); }