import React, { useState } from 'react'; import { Card, CardContent, CardHeader } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; const CreditCalculator = () => { const [amount, setAmount] = useState(''); const [term, setTerm] = useState(''); const [rate, setRate] = useState(''); const [payment, setPayment] = useState(null); const [totalCost, setTotalCost] = useState(null); const calculateLoan = () => { const p = parseFloat(amount); const r = parseFloat(rate) / 100 / 12; const n = parseFloat(term) * 12; const monthlyPayment = (p * r * Math.pow(1 + r, n)) / (Math.pow(1 + r, n) - 1); const totalCostOfLoan = monthlyPayment * n; setPayment(monthlyPayment.toFixed(2)); setTotalCost(totalCostOfLoan.toFixed(2)); }; return ( Калькулятор кредита
setAmount(e.target.value)} /> setTerm(e.target.value)} /> setRate(e.target.value)} /> {payment && totalCost && (

Ежемесячный платеж: {payment} руб.

Общая стоимость кредита: {totalCost} руб.

)}
); }; export default CreditCalculator;