export function evChargerInstallationCalculator(form: FormTs) {
// Charger level pricing
const chargerPricing: Record<string, number> = {
'level1': 300,
'level2-basic': 500,
'level2-smart': 800,
'level2-premium': 1200
};
// Installation complexity multipliers
const installationMultipliers: Record<string, number> = {
'simple': 1.0,
'moderate': 1.3,
'complex': 1.6,
'extensive': 2.0
};
// Panel upgrade costs
const panelUpgradeCosts: Record<string, number> = {
'none': 0,
'subpanel': 1500,
'main-panel': 3000,
'service-upgrade': 5000
};
form.addRow(row => {
row.addTextPanel('header', {
computedValue: () => 'EV Charger Installation Estimate',
customStyles: { 'font-size': '1.5rem', 'font-weight': '600', 'color': '#1e293b' }
});
});
form.addSpacer({ height: 20 });
// Service Location Section
const locationSection = form.addSubform('serviceLocation', { title: '📍 Installation Location' });
locationSection.addRow(row => {
row.addAddress('propertyAddress', {
label: 'Property Address',
placeholder: 'Enter your property address...',
showMap: true,
showDistance: true,
referenceAddress: {
formattedAddress: 'Service Center, Denver, CO',
coordinates: { lat: 39.7392, lng: -104.9903 }
},
restrictToCountries: ['US', 'CA'],
distanceUnit: 'miles',
isRequired: true
});
});
locationSection.addRow(row => {
row.addTextPanel('serviceAreaInfo', {
computedValue: () => {
const addressField = locationSection.address('propertyAddress');
const miles = addressField?.distance();
if (miles == null) return '📍 Enter address to check service area';
if (miles <= 25) return '📍 Within service area - No travel fee';
if (miles <= 50) return '📍 Extended area - $75 travel fee';
if (miles <= 75) return '📍 Remote area - $150 travel fee';
return '📍 Outside service area - Please call for availability';
},
customStyles: { 'font-size': '0.9rem', 'color': '#0369a1', 'background': '#e0f2fe', 'padding': '10px', 'border-radius': '6px' }
});
});
// Property Details Section
const propertySection = form.addSubform('propertyDetails', { title: '🏠 Property Details' });
propertySection.addRow(row => {
row.addDropdown('homeType', {
label: 'Home Type',
options: [
{ id: 'single-family', name: 'Single Family Home' },
{ id: 'townhouse', name: 'Townhouse' },
{ id: 'condo', name: 'Condo/Apartment' },
{ id: 'multi-family', name: 'Multi-Family' }
],
defaultValue: 'single-family',
isRequired: true
}, '1fr');
row.addDropdown('garageType', {
label: 'Parking Location',
options: [
{ id: 'attached-garage', name: 'Attached Garage' },
{ id: 'detached-garage', name: 'Detached Garage' },
{ id: 'carport', name: 'Carport' },
{ id: 'driveway', name: 'Driveway/Outdoor' }
],
defaultValue: 'attached-garage',
isRequired: true
}, '1fr');
});
propertySection.addRow(row => {
row.addSlider('distanceToPanel', {
label: 'Distance from Panel to Charger (feet)',
min: 10,
max: 200,
step: 10,
defaultValue: 30,
showValue: true
});
});
// Charger Selection Section
const chargerSection = form.addSubform('chargerConfig', { title: '⚡ Charger Selection' });
chargerSection.addRow(row => {
row.addRadioButton('chargerLevel', {
label: 'Charger Type',
options: [
{ id: 'level1', name: 'Level 1 (120V) - 3-5 miles/hour' },
{ id: 'level2-basic', name: 'Level 2 Basic (240V) - 12-25 miles/hour' },
{ id: 'level2-smart', name: 'Level 2 Smart (240V + WiFi) - 12-25 miles/hour' },
{ id: 'level2-premium', name: 'Level 2 Premium (240V + Smart Features) - 25-30 miles/hour' }
],
defaultValue: 'level2-smart',
orientation: 'vertical',
isRequired: true
});
});
chargerSection.addRow(row => {
row.addDropdown('amperage', {
label: 'Amperage',
options: [
{ id: '16', name: '16 Amp' },
{ id: '32', name: '32 Amp' },
{ id: '40', name: '40 Amp' },
{ id: '48', name: '48 Amp (Fastest)' }
],
defaultValue: '40',
isRequired: true,
isVisible: () => {
const level = chargerSection.radioButton('chargerLevel')?.value();
return level !== 'level1';
}
}, '1fr');
row.addDropdown('cordLength', {
label: 'Cord Length',
options: [
{ id: '18', name: '18 feet' },
{ id: '24', name: '24 feet (+$50)' },
{ id: '25', name: '25 feet (+$75)' }
],
defaultValue: '18',
isRequired: true,
isVisible: () => {
const level = chargerSection.radioButton('chargerLevel')?.value();
return level !== 'level1';
}
}, '1fr');
});
// Electrical Section
const electricalSection = form.addSubform('electrical', { title: '🔌 Electrical Requirements' });
electricalSection.addRow(row => {
row.addRadioButton('panelUpgrade', {
label: 'Panel Upgrade Needed',
options: [
{ id: 'none', name: 'No Upgrade Needed' },
{ id: 'subpanel', name: 'Add Subpanel (+$1,500)' },
{ id: 'main-panel', name: 'Upgrade Main Panel (+$3,000)' },
{ id: 'service-upgrade', name: 'Service Upgrade to 200A (+$5,000)' }
],
defaultValue: 'none',
orientation: 'vertical',
isRequired: true
});
});
electricalSection.addRow(row => {
row.addDropdown('installComplexity', {
label: 'Installation Complexity',
options: [
{ id: 'simple', name: 'Simple - Panel nearby, easy access' },
{ id: 'moderate', name: 'Moderate - Some obstacles, longer run' },
{ id: 'complex', name: 'Complex - Through walls, difficult access' },
{ id: 'extensive', name: 'Extensive - Trenching or major work needed' }
],
defaultValue: 'moderate',
isRequired: true
});
});
// Additional Options Section
const addonsSection = form.addSubform('addons', { title: '✨ Additional Options' });
addonsSection.addRow(row => {
row.addCheckbox('permit', {
label: 'Permit & Inspection (+$150)',
defaultValue: true
}, '1fr');
row.addCheckbox('loadManagement', {
label: 'Load Management Device (+$300)',
defaultValue: false
}, '1fr');
});
addonsSection.addRow(row => {
row.addCheckbox('weatherproof', {
label: 'Weatherproof Outdoor Enclosure (+$200)',
defaultValue: false,
isVisible: () => {
const garage = propertySection.dropdown('garageType')?.value();
return garage === 'carport' || garage === 'driveway';
}
}, '1fr');
row.addCheckbox('dedicatedCircuit', {
label: 'GFCI Protection (+$100)',
defaultValue: true
}, '1fr');
});
form.addSpacer({ height: 20, showLine: true, lineStyle: 'dashed' });
// Helper to calculate travel fee
const getTravelFee = () => {
const addressField = locationSection.address('propertyAddress');
const miles = addressField?.distance();
if (miles == null || miles <= 25) return 0;
if (miles <= 50) return 75;
if (miles <= 75) return 150;
return 200;
};
// Price Summary Section
const summarySection = form.addSubform('summary', { title: '💰 Cost Breakdown', isCollapsible: false });
summarySection.addRow(row => {
row.addPriceDisplay('chargerCost', {
label: 'EV Charger Equipment',
computedValue: () => {
const chargerLevel = chargerSection.radioButton('chargerLevel')?.value() || 'level2-smart';
let cost = chargerPricing[chargerLevel] || 800;
const cordLength = chargerSection.dropdown('cordLength')?.value();
if (cordLength === '24') cost += 50;
if (cordLength === '25') cost += 75;
return cost;
},
variant: 'default'
}, '1fr');
row.addPriceDisplay('installationCost', {
label: 'Installation Labor',
computedValue: () => {
const complexity = electricalSection.dropdown('installComplexity')?.value() || 'moderate';
const distance = propertySection.slider('distanceToPanel')?.value() || 30;
const multiplier = installationMultipliers[complexity] || 1.3;
const baseCost = 500;
const distanceCost = distance * 8;
return Math.round((baseCost + distanceCost) * multiplier);
},
variant: 'default',
prefix: '+'
}, '1fr');
});
summarySection.addRow(row => {
row.addPriceDisplay('panelCost', {
label: 'Electrical Panel Work',
computedValue: () => {
const panel = electricalSection.radioButton('panelUpgrade')?.value() || 'none';
return panelUpgradeCosts[panel] || 0;
},
variant: 'default',
prefix: '+'
}, '1fr');
row.addPriceDisplay('addonsCost', {
label: 'Additional Options',
computedValue: () => {
let total = 0;
if (addonsSection.checkbox('permit')?.value()) total += 150;
if (addonsSection.checkbox('loadManagement')?.value()) total += 300;
if (addonsSection.checkbox('weatherproof')?.value()) total += 200;
if (addonsSection.checkbox('dedicatedCircuit')?.value()) total += 100;
return total;
},
variant: 'default',
prefix: '+'
}, '1fr');
});
summarySection.addRow(row => {
row.addPriceDisplay('travelFee', {
label: 'Travel Fee',
computedValue: () => getTravelFee(),
variant: 'default',
prefix: '+',
isVisible: () => getTravelFee() > 0
});
});
const finalSection = form.addSubform('final', {
title: '🔋 Your Estimate',
isCollapsible: false,
sticky: 'bottom'
});
finalSection.addRow(row => {
row.addPriceDisplay('totalCost', {
label: 'Total Estimated Cost',
computedValue: () => {
const chargerLevel = chargerSection.radioButton('chargerLevel')?.value() || 'level2-smart';
let chargerCost = chargerPricing[chargerLevel] || 800;
const cordLength = chargerSection.dropdown('cordLength')?.value();
if (cordLength === '24') chargerCost += 50;
if (cordLength === '25') chargerCost += 75;
const complexity = electricalSection.dropdown('installComplexity')?.value() || 'moderate';
const distance = propertySection.slider('distanceToPanel')?.value() || 30;
const multiplier = installationMultipliers[complexity] || 1.3;
const installCost = Math.round((500 + distance * 8) * multiplier);
const panel = electricalSection.radioButton('panelUpgrade')?.value() || 'none';
const panelCost = panelUpgradeCosts[panel] || 0;
let addonsCost = 0;
if (addonsSection.checkbox('permit')?.value()) addonsCost += 150;
if (addonsSection.checkbox('loadManagement')?.value()) addonsCost += 300;
if (addonsSection.checkbox('weatherproof')?.value()) addonsCost += 200;
if (addonsSection.checkbox('dedicatedCircuit')?.value()) addonsCost += 100;
const travelFee = getTravelFee();
return chargerCost + installCost + panelCost + addonsCost + travelFee;
},
variant: 'large'
}, '1fr');
row.addPriceDisplay('taxCredit', {
label: 'Federal Tax Credit (30%)',
computedValue: () => {
const chargerLevel = chargerSection.radioButton('chargerLevel')?.value() || 'level2-smart';
let chargerCost = chargerPricing[chargerLevel] || 800;
const cordLength = chargerSection.dropdown('cordLength')?.value();
if (cordLength === '24') chargerCost += 50;
if (cordLength === '25') chargerCost += 75;
const complexity = electricalSection.dropdown('installComplexity')?.value() || 'moderate';
const distance = propertySection.slider('distanceToPanel')?.value() || 30;
const multiplier = installationMultipliers[complexity] || 1.3;
const installCost = Math.round((500 + distance * 8) * multiplier);
const panel = electricalSection.radioButton('panelUpgrade')?.value() || 'none';
const panelCost = panelUpgradeCosts[panel] || 0;
let addonsCost = 0;
if (addonsSection.checkbox('permit')?.value()) addonsCost += 150;
if (addonsSection.checkbox('loadManagement')?.value()) addonsCost += 300;
if (addonsSection.checkbox('weatherproof')?.value()) addonsCost += 200;
if (addonsSection.checkbox('dedicatedCircuit')?.value()) addonsCost += 100;
const travelFee = getTravelFee();
const total = chargerCost + installCost + panelCost + addonsCost + travelFee;
return -Math.min(Math.round(total * 0.30), 1000);
},
variant: 'success',
prefix: ''
}, '1fr');
});
finalSection.addRow(row => {
row.addTextPanel('disclaimer', {
computedValue: () => 'Estimates based on average costs. Final price depends on site assessment. Federal tax credit capped at $1,000. Additional utility rebates may apply.',
customStyles: { 'font-size': '0.85rem', 'color': '#64748b', 'font-style': 'italic' }
});
});
form.configureSubmitButton({
label: 'Get Free Quote'
});
}