import { EmptyBank } from "@/components/EmptyBank";
import { MoneyPlan, type PlanState } from "@/components/MoneyPlan";
import { PlanChat } from "@/components/PlanChat";
import { PlanContext } from "@/components/PlanContext";
import { getUser, today, typicalMonthly } from "@/lib/data";
import { money0, ymd } from "@/lib/format";
import { loadPlan } from "@/lib/plan-facts";
export default async function Plan() {
const { supabase, user } = await getUser();
const now = await today(); // the tz cookie, no database call
const [state, { count }, typical] = await Promise.all([
loadPlan(supabase, user!.id),
supabase.from("accounts").select("id", { count: "exact", head: true }).eq("user_id", user!.id),
typicalMonthly(supabase, user!.id, ymd(now)),
]);
if (!count) return
In a typical month {money0(typical!.income)} comes in and {money0(typical!.spend)} goes out.{" "} {rate >= 0 ? <>You save {Math.round(rate * 100)}% of it.> : That's {money0(typical!.spend - typical!.income)} more out than in.}
)} {/* The plan, written by your AI from your accounts, then a place to talk it through. */}