import React, { useState, useEffect, useCallback } from "react";
import { Quote } from "@/entities/Quote";
import HomeSpecs from "../components/calculator/HomeSpecs";
import MaterialSelection from "../components/calculator/MaterialSelection";
import CostBreakdown from "../components/calculator/CostBreakdown";
import ClientInfo from "../components/calculator/ClientInfo";
import QuoteActions from "../components/calculator/QuoteActions";
// Updated pricing data based on real Whitis Premium Builders estimate
// Assuming ~2400 sq ft home based on typical proportions from the estimate
const baseCostPerSqFt = 115; // Base construction (framing, roofing, siding, drywall, etc.)
const flooringCosts = {
carpet: 2,
luxury_vinyl: 4,
tile: 6,
hardwood: 8,
concrete: 5
};
const countertopCosts = {
laminate: 30,
butcher_block: 45,
granite: 60,
quartz: 75,
marble: 90
};
const fixtureLevelMultipliers = {
basic: 0.8, // Lower cost fixtures/finishes
mid_range: 1.0, // Standard level
premium: 1.4, // Higher quality
luxury: 1.8 // High-end everything
};
// Site preparation costs based on estimate breakdown
const terrainCosts = {
flat: 8000, // Basic excavation and prep
sloped: 18000, // Additional grading and retaining
rocky: 28000, // Rock removal and heavy equipment
forested: 22000 // Clearing and stump removal
};
const utilitiesCosts = {
city: 3500, // City hookup fees and basic trenching
septic_well: 28000 // Septic system + well installation
};
const roadCostPerFoot = 85; // Driveway and utility line costs per foot
export default function Calculator() {
const [specs, setSpecs] = useState({
square_footage: 2000,
bedrooms: 3,
bathrooms: 2,
stories: 1
});
const [materials, setMaterials] = useState({
flooring_type: "hardwood",
countertop_type: "granite",
fixture_level: "mid_range"
});
const [siteInfo, setSiteInfo] = useState({
terrain_type: "flat",
utilities_type: "city",
distance_from_road: 50,
location_multiplier: 1.0,
});
const [clientInfo, setClientInfo] = useState({
client_name: "",
client_email: "",
client_phone: "",
notes: ""
});
const [costs, setCosts] = useState({
base_cost: 0,
site_prep_cost: 0,
material_cost: 0,
labor_cost: 0,
total_estimate: 0
});
const [isSaving, setIsSaving] = useState(false);
// Calculate costs whenever inputs change
useEffect(() => {
const calculateCosts = () => {
// Base construction cost (includes framing, roofing, siding, basic electrical/plumbing rough-in, drywall)
const baseConstruction = specs.square_footage * baseCostPerSqFt;
// Site preparation costs
const terrainCost = terrainCosts[siteInfo.terrain_type];
const utilityCost = utilitiesCosts[siteInfo.utilities_type];
const roadCost = siteInfo.distance_from_road * roadCostPerFoot;
// Add permits, surveys, insurance (~$6000 based on estimate)
const permitsCost = 6000;
const totalSitePrepCost = terrainCost + utilityCost + roadCost + permitsCost;
// Material upgrade costs (flooring, countertops, fixture quality)
const flooringCost = specs.square_footage * flooringCosts[materials.flooring_type];
// Countertop cost based on kitchen + bathroom count (estimated linear feet)
const estimatedLinearFeet = (specs.bedrooms * 0.5) + (specs.bathrooms * 2) + 12; // Kitchen base
const countertopCost = estimatedLinearFeet * countertopCosts[materials.countertop_type];
// Fixture level affects cabinets, appliances, lighting, plumbing fixtures
// Base fixture allowance: ~$20,000 for mid-range home
const baseFixtureAllowance = 20000;
const fixtureUpgradeCost = baseFixtureAllowance * fixtureLevelMultipliers[materials.fixture_level];
const totalMaterialCost = flooringCost + countertopCost + fixtureUpgradeCost;
// Labor calculation - varies by project complexity
// From estimate: labor is roughly 25-30% of material costs
const laborPercentage = 0.28;
const laborCost = (baseConstruction + totalSitePrepCost + totalMaterialCost) * laborPercentage;
// Apply location multiplier to everything
const subtotal = baseConstruction + totalSitePrepCost + totalMaterialCost + laborCost;
const finalTotal = subtotal * siteInfo.location_multiplier;
setCosts({
base_cost: Math.round(baseConstruction),
site_prep_cost: Math.round(totalSitePrepCost),
material_cost: Math.round(totalMaterialCost),
labor_cost: Math.round(laborCost),
total_estimate: Math.round(finalTotal)
});
};
calculateCosts();
}, [specs, materials, siteInfo]);
const handleSaveQuote = async () => {
setIsSaving(true);
try {
await Quote.create({
...specs,
...materials,
...siteInfo,
...clientInfo,
...costs,
markup_percentage: 0 // No client-facing markup
});
// Reset client info after saving
setClientInfo({
client_name: "",
client_email: "",
client_phone: "",
notes: ""
});
alert("Quote saved successfully!");
} catch (error) {
alert("Error saving quote. Please try again.");
}
setIsSaving(false);
};
return (
);
}
Custom Home Calculator
Generate instant cost estimates for your custom home projects
{/* Input Forms */}
{/* Cost Breakdown */}