"use client"; import { useMemo, useState } from "react"; import { computeMortgage, minDownPayment, transferDuty } from "@/lib/mortgage"; import { fmtPrice, fmtPct } from "@/lib/format"; import { Notice, Stat } from "@/components/ui"; const DEFAULT_RATE = 4.89; // hypothèse éditable — aucun taux « réel » n'est importé ; l'utilisateur saisit le taux de son prêteur function F({ label, value, set, step = 1, suffix = "" }: { label: string; value: number; set: (v: number) => void; step?: number; suffix?: string }): React.ReactElement { return ( ); } export function MortgageWidget({ price: p0 = 500000, city, compact = false, taxes: t0, schoolTaxes: s0, condoFees: c0 }: { price?: number; city?: string | null; compact?: boolean; taxes?: number; schoolTaxes?: number; condoFees?: number }) { const [price, setPrice] = useState(p0); const [dpPct, setDpPct] = useState(20); const [rate, setRate] = useState(DEFAULT_RATE); const [amort, setAmort] = useState(25); const [freq, setFreq] = useState<12 | 26 | 52>(12); const [taxes, setTaxes] = useState(t0 ?? Math.round(p0 * 0.009)); const [school, setSchool] = useState(s0 ?? Math.round(p0 * 0.0007)); const [ins, setIns] = useState(90); const [condo, setCondo] = useState(c0 ?? 0); const [heat, setHeat] = useState(150); const dp = Math.round(price * dpPct / 100); const r = useMemo(() => computeMortgage({ price, downPayment: dp, rateAnnualPct: rate, amortYears: amort, paymentsPerYear: freq, municipalTaxAnnual: taxes, schoolTaxAnnual: school, insuranceMonthly: ins, condoFeesMonthly: condo, heatingMonthly: heat }), [price, dp, rate, amort, freq, taxes, school, ins, condo, heat]); const isMtl = /montr[ée]al/i.test(city ?? ""); const duty = transferDuty(price, isMtl); const closing = duty + 1500 + 1000; // notaire + inspection (ordres de grandeur éditables mentalement) return (
| Année | Intérêts | Capital | Solde |
|---|---|---|---|
| {s.year} | {fmtPrice(s.interest)} | {fmtPrice(s.principal)} | {fmtPrice(s.balance)} |