PageSourceSearch

https://homelensais.com/assets/Calculators-BH9-eLcV.js

js homelensais.com collected 2026-10-02 01:31:50 UTC 17,922 bytes, 3 lines download raw bytes

1import{ae as Te,aO as De,aP as Le,U as ke,r as t,W as $e,q as e,af as He,al as _e,B as h,aQ as he,T as Fe,H as Ue,I as xe,J as pe,s as B,t as T,v as D,N as Z,x as ge,F as L,ar as n,ay as r,aR as Oe,aS as Ee,aT as ze,aU as Ge,S as Ye,Z as qe,_ as We,a2 as k,a3 as Ve}from"./index-RQZfdGSV.js";import{BrrrrCalculatorPanel as Je}from"./CalculatorBrrrr-Ow0a5HW5.js";import{S as Qe}from"./save-iRHaixmg.js";import{W as Ze}from"./wallet-CFkmYcPh.js";import"./wrench-Cd2mECKW.js";function Ke(v){const{annualIncome:N,monthlyDebts:S,downPaymentAvailable:x,assumptions:l}=v,m=N/12,$=m>0?S/m*100:0,H=m*.28,o=Math.max(0,m*(l.dtiCapPct/100)-S);if(N<=0||x<=0||o<=0)return{monthlyIncome:m,actualDTI:$,maxAffordablePayment:H,maxHousingPayment:o,estimatedBuyingPower:0};const f=l.rateApr/100/12,g=l.termYears*12,_=d=>{const c=Math.max(0,d-x),w=f>0?c*(f*Math.pow(1+f,g))/(Math.pow(1+f,g)-1):c/g,P=d*(l.propertyTaxPct/100)/12,C=d*(l.insurancePct/100)/12,I=(d>0?x/d*100:100)<20?c*(l.pmiPct/100)/12:0;return w+P+C+I+l.hoaMonthly};let j=x,M=x+1e7;for(let d=0;d<40;d++){const c=(j+M)/2;_(c)>o?M=c:j=c}const F=Math.round(j/1e3)*1e3,A=x/(l.minDownPct/100),U=Math.min(F,A);return{monthlyIncome:m,actualDTI:$,maxAffordablePayment:H,maxHousingPayment:o,estimatedBuyingPower:U}}function rs(){const v=Te(),N=De(),[S,x]=Le(),{toast:l}=ke(),m=S.get("tab"),$=m==="mortgage"||m==="brrrr"?m:"buying-power",H=s=>{const a=new URLSearchParams(S);a.set("tab",s),x(a,{replace:!0})},[o,f]=t.useState(null),[g,_]=t.useState(!1),[j,M]=t.useState(""),F=$e(),A=F.warningLevel==="exceeded",[U,d]=t.useState(!1),[c,w]=t.useState(0),[P,C]=t.useState(0),[y,I]=t.useState(0),O={rateApr:7,termYears:30,propertyTaxPct:1.2,insurancePct:.35,pmiPct:.5,dtiCapPct:43,minDownPct:3.5,hoaMonthly:0},[u,E]=t.useState(O),[K,Ie]=t.useState(!1),p=(s,a)=>E(i=>({...i,[s]:a})),[b,X]=t.useState(0),[z,ee]=t.useState(0),[se,ae]=t.useState(0),[te,ne]=t.useState(30),[re,le]=t.useState(1.2),[G,ce]=t.useState(0),[Y,ie]=t.useState(0),[je,ye]=t.useState(.5),[be,oe]=t.useState(0);t.useEffect(()=>{var a;if((async()=>{const{data:{session:i}}=await k.auth.getSession();if(f((i==null?void 0:i.user)??null),!i){v("/auth?redirect=/calculators");return}})(),(a=N.state)!=null&&a.calculationData){const i=N.state.calculationData;w(i.annualIncome||0),C(i.monthlyDebts||0),I(i.downPaymentAvailable||0)}},[v,N.state]);const Re=()=>{w(0),C(0),I(0),X(0),ee(0),ae(0),ne(30),le(1.2),ce(0),ie(0),ye(.5),oe(0),M(""),E(O)},Se=()=>{w(0),C(0),I(0),E(O)},Me=async()=>{if(!o){l({title:"Sign in required",description:"Please sign in to save this to your preferences.",variant:"destructive"});return}if(!(R<=0)){d(!0);try{const{data:s}=await k.from("profiles").select("preferences").eq("id",o.id).maybeSingle(),a=(s==null?void 0:s.preferences)??{},i={...a,budget:{...a.budget??{},purchase_price_max:Math.round(R),...y>0?{down_payment:y}:{}}},{error:Ce}=await k.functions.invoke("preferences-assistant",{body:{action:"edit",preferences:i}});if(Ce)throw Ce;l({title:"Budget updated",description:`Max purchase price set to $${Math.round(R).toLocaleString()} in your preferences.`})}catch(s){l({title:"Couldn't update preferences",description:(s==null?void 0:s.message)??"Please try again.",variant:"destructive"})}finally{d(!1)}}},Ae=()=>{X(0),ee(0),ae(0),ne(30),le(1.2),ce(0),ie(0),ye(.5),oe(0)},Be=async()=>{if(!o)return;const s={annualIncome:c,monthlyDebts:P,downPaymentAvailable:y};try{const{error:a}=await k.from("saved_calculations").insert([{user_id:o.id,name:`Buying Power ${new Date().toLocaleDateString()}`,calculation_type:"buying-power",data:s}]);if(a)throw a;l({title:"Saved",description:"Your calculation has been saved successfully"})}catch(a){l({title:"Error",description:a.message,variant:"destructive"})}},{monthlyIncome:Xe,actualDTI:q,maxAffordablePayment:ve,maxHousingPayment:Ne,estimatedBuyingPower:R}=Ke({annualIncome:c,monthlyDebts:P,downPaymentAvailable:y,assumptions:u}),W=b-z,V=b>0?z/b*100:0,J=se/100/12,fe=te*12,de=W>0&&J>0?W*(J*Math.pow(1+J,fe))/(Math.pow(1+J,fe)-1):0,me=b*(re/100)/12,ue=G>0?G/12:b*.0035/12,Q=V<20?W*(je/100)/12:0,we=de+me+ue+Y+Q,Pe=async()=>{if(!o){l({title:"Authentication Required",description:"Please sign in to generate AI insights",variant:"destructive"});return}_(!0);try{const{data:s,error:a}=await k.functions.invoke("calculator-insights",{body:{buyingPower:{annualIncome:c,monthlyDebts:P,downPaymentAvailable:y,estimatedBuyingPower:Math.round(R),maxAffordablePayment:Math.round(ve),maxHousingPayment:Math.round(Ne),actualDTI:q.toFixed(2),assumptions:u},mortgage:{homePrice:b,downPayment:z,downPaymentPercent:V.toFixed(2),loanAmount:W,interestRate:se,loanTerm:te,monthlyPI:Math.round(de),monthlyPropertyTax:Math.round(me),monthlyInsurance:Math.round(ue),monthlyPMI:Math.round(Q),hoaMonthly:Y,totalMonthlyPayment:Math.round(we),propertyTaxRate:re,insuranceAnnual:G,pmiRate:je,closingCosts:be}}});if(a)throw a;M(s.insights)}catch(s){if(await Ve(s,"calculator_insights"))return;l({title:"Error",description:s.message,variant:"destructive"})}finally{_(!1)}};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsxs(He,{children:[e.jsx("title",{children:"Buying Power, Mortgage & BRRRR Calculators | HomeLens"}),e.jsx("meta",{name:"description",content:"Free calculators for US buyers and investors: buying power, mortgage PITI breakdown, and BRRRR cash-on-cash after refinance."}),e.jsx("link",{rel:"canonical",href:"https://homelensais.com/calculators"}),e.jsx("meta",{property:"og:title",content:"Buying Power, Mortgage & BRRRR Calculators | HomeLens"}),e.jsx("meta",{property:"og:description",content:"Free calculators for buyers and investors: buying power, mortgage PITI, and BRRRR cash-on-cash."}),e.jsx("meta",{property:"og:url",content:"https://homelensais.com/calculators"}),e.jsx("meta",{property:"og:type",content:"website"}),e.jsx("meta",{name:"twitter:title",content:"Buying Power, Mortgage & BRRRR Calculators | HomeLens"}),e.jsx("meta",{name:"twitter:description",content:"Free calculators for buyers and investors: buying power, mortgage PITI, and BRRRR cash-on-cash."})]}),e.jsx(_e,{}),e.jsxs("div",{className:"container mx-auto px-4 py-8 pb-24 lg:pb-8",children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-bold mb-2",children:"Financial Calculators"}),e.jsx("p",{className:"text-muted-foreground",children:"Buying power, mortgage payment, and BRRRR — pick a tab."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:Re,children:[e.jsx(he,{className:"h-4 w-4 mr-2"}),"Reset"]}),o&&e.jsxs(h,{variant:"outline",size:"sm",onClick:Be,children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Save"]})]})]}),e.jsxs(Fe,{value:$,onValueChange:H,className:"space-y-6",children:[e.jsxs(Ue,{className:"grid w-full grid-cols-3 sm:w-auto 
1sm:inline-flex",children:[e.jsx(xe,{value:"buying-power",children:"Buying Power"}),e.jsx(xe,{value:"mortgage",children:"Mortgage"}),e.jsx(xe,{value:"brrrr",children:"BRRRR"})]}),e.jsx(pe,{value:"buying-power",className:"mt-0",children:e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(B,{children:[e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{as:"h2",className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5 text-primary"}),"Buying Power Summary"]}),e.jsx(h,{variant:"ghost",size:"sm",onClick:Se,"aria-label":"Reset buying power",children:e.jsx(he,{className:"h-4 w-4"})})]}),e.jsx(ge,{children:"Calculate your home buying capacity"})]}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Annual Income (USD)"}),e.jsx(r,{type:"number",value:c||"",onChange:s=>w(Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Monthly Debts (USD)"}),e.jsx(r,{type:"number",value:P||"",onChange:s=>C(Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Down Payment Available (USD)"}),e.jsx(r,{type:"number",value:y||"",onChange:s=>I(Number(s.target.value)),className:"mt-1"})]}),e.jsxs(Oe,{open:K,onOpenChange:Ie,children:[e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(h,{variant:"ghost",size:"sm",className:"gap-2 -ml-2",children:[e.jsx(ze,{className:`h-4 w-4 transition-transform ${K?"rotate-180":""}`}),"Advanced assumptions"]})}),K&&e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>E(O),children:"Reset"})]}),e.jsxs(Ge,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Interest Rate (%)"}),e.jsx(r,{type:"number",step:"0.01",value:u.rateApr,onChange:s=>p("rateApr",Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Loan Term (years)"}),e.jsx(r,{type:"number",value:u.termYears,onChange:s=>p("termYears",Number(s.target.value)),className:"mt-1"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Property Tax (%/yr)"}),e.jsx(r,{type:"number",step:"0.01",value:u.propertyTaxPct,onChange:s=>p("propertyTaxPct",Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Insurance (%/yr of price)"}),e.jsx(r,{type:"number",step:"0.01",value:u.insurancePct,onChange:s=>p("insurancePct",Number(s.target.value)),className:"mt-1"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"PMI (%/yr, if down < 20%)"}),e.jsx(r,{type:"number",step:"0.01",value:u.pmiPct,onChange:s=>p("pmiPct",Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Back-end DTI cap (%)"}),e.jsx(r,{type:"number",step:"1",value:u.dtiCapPct,onChange:s=>p("dtiCapPct",Number(s.target.value)),className:"mt-1"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Min Down Payment (%)"}),e.jsx(r,{type:"number",step:"0.5",value:u.minDownPct,onChange:s=>p("minDownPct",Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Monthly HOA ($)"}),e.jsx(r,{type:"number",value:u.hoaMonthly||"",onChange:s=>p("hoaMonthly",Number(s.target.value)),className:"mt-1"})]})]})]})]})]})]}),e.jsxs(B,{children:[e.jsx(T,{children:e.jsxs(D,{as:"h2",className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5 text-primary"}),"Buying Power Results"]})}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your DTI Ratio"}),e.jsxs("p",{className:`text-2xl font-bold ${q<30?"text-green-600":q<43?"text-yellow-600":"text-red-600"}`,children:[q.toFixed(1),"%"]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Estimated Buying Power"}),e.jsxs("p",{className:"text-2xl font-bold text-primary",children:["$",Math.round(R).toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Max Affordable Payment"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",Math.round(ve).toLocaleString()]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Max Housing Payment (DTI)"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",Math.round(Ne).toLocaleString()]})]})]}),e.jsxs("div",{className:"pt-4 border-t space-y-2",children:[e.jsxs(h,{onClick:Me,disabled:R<=0||U,className:"w-full",children:[e.jsx(Ze,{className:"h-4 w-4 mr-2"}),U?"Saving…":"Set as my budget preference"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Updates the max purchase price used across HomeLens."," ",e.jsx("button",{type:"button",onClick:()=>v("/console?tab=preferences"),className:"text-primary underline-offset-4 hover:underline",children:"View preferences"})]})]})]})]})]})}),e.jsx(pe,{value:"mortgage",className:"mt-0",children:e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(B,{children:[e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{as:"h2",className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5 text-primary"}),"Mortgage Calculator"]}),e.jsx(h,{variant:"ghost",size:"sm",onClick:Ae,"aria-label":"Reset mortgage calculator",children:e.jsx(he,{className:"h-4 w-4"})})]}),e.jsx(ge,{children:"Calculate your monthly PITI payment"})]}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Home Price ($)"}),e.jsx(r,{type:"number",value:b||"",onChange:s=>X(Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Down Payment ($)"}),e.jsx(r,{type:"number",value:z||"",onChange:s=>ee(Number(s.target.value)),className:"mt-1"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Interest Rate (%)"}),e.jsx(r,{type:"number",step:"0.01",value:se||"",onChange:s=>ae(Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Loan Term (years)"}),e.jsx(r,{type:"number",value:te||"",onChange:s=>ne(Number(s.target.value)),className:"mt-1"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Property Tax Rate (%)"}),e.jsx(r,{type:"number",step:"0.1",value:re||"",onChange:s=>le(Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Annual Insurance ($)"}),e.jsx(r,{type:"number",value:G||"",onChange:s=>ce(Number(s.target.value)),className:"mt-1",placeholder:"Auto-estimated if empty"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Monthly HOA ($)"}),e.jsx(r,{type:"number",value:Y||"",onChange:s=>ie(Number(s.target.value)),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Closing Costs ($)"}),e.jsx(r,{type:"number",value:be||"",onChange:s=>oe(Number(s.target.value)),className:"mt-1"})]})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(B,{children:[e.jsx(T,{children:e.jsxs(D,{as:"h2",className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5 text-primary"}),"Monthly Payment Breakdown (PITI)"]})}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center pb-2 border-b",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Principal & Interest"}),e.jsxs("span",{className:"font-semibold",children:["$",Math.round(de).toLocaleString()]})]}),e.jsxs("div",{className:"flex justify-between items-center pb-2 border-b",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Property Taxes"}),e.jsxs("span",{className:"font-semibold",children:["$",Math.round(me).toLocaleString()]})]}),e.jsxs("div",{className:"flex justify-between items-center pb-2 border-b",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Homeowners Insurance"}),e.jsxs("span",{className:"font-semibold",children:["$",Math.round(ue).toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"flex justify-between items-center pb-2 border-b",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"HOA Fees"}),e.jsxs("span",{className:"font-semibold",children:["$",Y.toLocaleString()]})]}),Q>0&&e.jsxs("div",{className:"flex justify-between items-center pb-2 border-b",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"PMI (Down < 20%)"}),e.jsxs("span",{className:"font-semibold text-yellow-600",children:["$",Math.round(Q).toLocaleString()]})]}),e.jsxs("div",{className:"flex justify-between items-center pt-2",children:[e.jsx("span",{className:"font-bold",children:"Total Monthly Payment"}),e.jsxs("span",{className:"text-2xl font-bold text-primary",children:["$",Math.round(we).toLocaleString()]})]})]}),V<20&&e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-950 p-3 rounded-lg space-y-1",children:[e.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200",children:["⚠️ PMI required: Down payment is ",V.toFixed(1),"% (less than 20%)"]}),e.jsx("p",{className:"text-xs text-yellow-700 dark:text-yellow-300",children:"PMI auto-populated with typical rate (0.5%). Adjust if needed."})]})]})]}),e.jsxs(B,{children:[e.jsxs(T,{children:[e.jsxs(D,{as:"h2",className:"flex items-center gap-2",children:[e.jsx(Ye,{className:"h-5 w-5 text-primary"}),"💡 AI Insight"]}),e.jsx(ge,{children:"Get personalized analysis from AI"})]}),e.jsxs(L,{className:"space-y-4",children:[F.warningLevel==="approaching"&&e.jsx(qe,{surface:"calculator_insights"}),A&&e.jsx(We,{surface:"calculator_insights",compact:!0}),j?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-muted/50 p-4 rounded-lg",children:e.jsx("div",{className:"space-y-2 text-foreground whitespace-pre-wrap",children:j})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{variant:"outline",onClick:Pe,disabled:g||A,className:"flex-1",children:"Regenerate Insights"}),e.jsx(h,{onClick:()=>v("/chats",{state:{initialMessage:`[CALCULATORS_AI_INSIGHT]
2
3${j}`,newConversation:!0,skipAuthCheck:!0}}),className:"flex-1",children:"Start Chat with this Insight"})]})]}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Generate AI-powered insights based on your buying power"}),e.jsx(h,{onClick:Pe,disabled:g||A,children:g?"Generating...":"Generate Insights"})]})]})]})]})]})}),e.jsx(pe,{value:"brrrr",className:"mt-0",children:e.jsx(Je,{showHeading:!0})})]})]})]})}export{rs as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.