export function irrigationSystemCalculator(form: FormTs) {
// System type base costs
const systemBaseCosts: Record<string, number> = {
'sprinkler-basic': 1500,
'sprinkler-premium': 2500,
'drip': 2000,
'combined': 3500
};
// Per zone costs
const costPerZone: Record<string, number> = {
'sprinkler-basic': 350,
'sprinkler-premium': 500,
'drip': 250,
'combined': 400
};
// Controller pricing
const controllerPricing: Record<string, number> = {
'basic': 150,
'smart': 350,
'premium': 600
};
form.addRow(row => {
row.addTextPanel('header', {
computedValue: () => 'Irrigation System 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 - $100 travel fee';
if (miles <= 75) return '📍 Remote area - $200 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.addSlider('yardSize', {
label: 'Yard Size (square feet)',
min: 1000,
max: 20000,
step: 500,
defaultValue: 5000,
showValue: true
});
});
propertySection.addRow(row => {
row.addDropdown('soilType', {
label: 'Soil Type',
options: [
{ id: 'sandy', name: 'Sandy (drains quickly)' },
{ id: 'loam', name: 'Loam (ideal balance)' },
{ id: 'clay', name: 'Clay (drains slowly)' },
{ id: 'rocky', name: 'Rocky (difficult digging)' }
],
defaultValue: 'loam',
isRequired: true
}, '1fr');
row.addDropdown('landscape', {
label: 'Landscape Type',
options: [
{ id: 'lawn-only', name: 'Mostly Lawn' },
{ id: 'mixed', name: 'Lawn + Garden Beds' },
{ id: 'gardens', name: 'Mostly Gardens/Beds' },
{ id: 'diverse', name: 'Diverse (lawn, beds, trees)' }
],
defaultValue: 'mixed',
isRequired: true
}, '1fr');
});
// System Configuration Section
const systemSection = form.addSubform('systemConfig', { title: '💧 System Configuration' });
systemSection.addRow(row => {
row.addRadioButton('systemType', {
label: 'Irrigation System Type',
options: [
{ id: 'sprinkler-basic', name: 'Basic Sprinkler System - Pop-up heads' },
{ id: 'sprinkler-premium', name: 'Premium Sprinkler - Rotary heads, high efficiency' },
{ id: 'drip', name: 'Drip Irrigation - Best for gardens and beds' },
{ id: 'combined', name: 'Combined System - Sprinklers + Drip zones' }
],
defaultValue: 'sprinkler-premium',
orientation: 'vertical',
isRequired: true
});
});
systemSection.addRow(row => {
row.addSlider('zones', {
label: 'Number of Zones',
min: 2,
max: 12,
step: 1,
defaultValue: 5,
showValue: true
});
});
systemSection.addRow(row => {
row.addRadioButton('controllerType', {
label: 'Controller Type',
options: [
{ id: 'basic', name: 'Basic Timer ($150) - Manual programming' },
{ id: 'smart', name: 'Smart Controller ($350) - WiFi, weather-based' },
{ id: 'premium', name: 'Premium Smart ($600) - AI, sensors, app control' }
],
defaultValue: 'smart',
orientation: 'vertical',
isRequired: true
});
});
// Installation Options Section
const installSection = form.addSubform('installation', { title: '🔧 Installation Options' });
installSection.addRow(row => {
row.addDropdown('installType', {
label: 'Installation Type',
options: [
{ id: 'new', name: 'New Installation' },
{ id: 'replacement', name: 'System Replacement' },
{ id: 'expansion', name: 'Expansion of Existing System' }
],
defaultValue: 'new',
isRequired: true
}, '1fr');
row.addDropdown('waterSource', {
label: 'Water Source',
options: [
{ id: 'municipal', name: 'Municipal Water' },
{ id: 'well', name: 'Well Water (+$500 pump)' },
{ id: 'rainwater', name: 'Rainwater Collection (+$800)' }
],
defaultValue: 'municipal',
isRequired: true
}, '1fr');
});
installSection.addRow(row => {
row.addCheckbox('backflowPreventer', {
label: 'Backflow Preventer (+$250)',
defaultValue: true
}, '1fr');
row.addCheckbox('pressureRegulator', {
label: 'Pressure Regulator (+$150)',
defaultValue: true
}, '1fr');
});
// Additional Features Section
const addonsSection = form.addSubform('addons', { title: '✨ Additional Features' });
addonsSection.addRow(row => {
row.addCheckbox('rainSensor', {
label: 'Rain Sensor (+$75)',
defaultValue: true
}, '1fr');
row.addCheckbox('soilSensor', {
label: 'Soil Moisture Sensors (+$200)',
defaultValue: false
}, '1fr');
});
addonsSection.addRow(row => {
row.addCheckbox('winterization', {
label: 'Winterization Service (+$125)',
defaultValue: true
}, '1fr');
row.addCheckbox('maintenancePlan', {
label: 'Annual Maintenance Plan (+$250/year)',
defaultValue: false
}, '1fr');
});
addonsSection.addRow(row => {
row.addCheckbox('dripConversion', {
label: 'Convert Existing Beds to Drip (+$400)',
defaultValue: false,
isVisible: () => {
const type = systemSection.radioButton('systemType')?.value();
return type !== 'drip' && type !== 'combined';
}
}, '1fr');
row.addCheckbox('flowerBedZone', {
label: 'Dedicated Flower Bed Zone (+$300)',
defaultValue: false
}, '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 100;
if (miles <= 75) return 200;
return 300;
};
// Price Summary Section
const summarySection = form.addSubform('summary', { title: '💰 Cost Breakdown', isCollapsible: false });
summarySection.addRow(row => {
row.addPriceDisplay('systemCost', {
label: 'Irrigation System',
computedValue: () => {
const systemType = systemSection.radioButton('systemType')?.value() || 'sprinkler-premium';
const zones = systemSection.slider('zones')?.value() || 5;
const soilType = propertySection.dropdown('soilType')?.value() || 'loam';
const baseCost = systemBaseCosts[systemType] || 2500;
const zoneCost = (costPerZone[systemType] || 500) * zones;
const soilMultiplier: Record<string, number> = {
'sandy': 0.9, 'loam': 1.0, 'clay': 1.1, 'rocky': 1.3
};
return Math.round((baseCost + zoneCost) * (soilMultiplier[soilType] || 1.0));
},
variant: 'default'
}, '1fr');
row.addPriceDisplay('controllerCost', {
label: 'Controller & Sensors',
computedValue: () => {
const controller = systemSection.radioButton('controllerType')?.value() || 'smart';
let total = controllerPricing[controller] || 350;
if (addonsSection.checkbox('rainSensor')?.value()) total += 75;
if (addonsSection.checkbox('soilSensor')?.value()) total += 200;
return total;
},
variant: 'default',
prefix: '+'
}, '1fr');
});
summarySection.addRow(row => {
row.addPriceDisplay('installationCost', {
label: 'Installation & Equipment',
computedValue: () => {
let total = 0;
const waterSource = installSection.dropdown('waterSource')?.value() || 'municipal';
if (waterSource === 'well') total += 500;
if (waterSource === 'rainwater') total += 800;
if (installSection.checkbox('backflowPreventer')?.value()) total += 250;
if (installSection.checkbox('pressureRegulator')?.value()) total += 150;
const installType = installSection.dropdown('installType')?.value() || 'new';
if (installType === 'replacement') total += 300;
return total;
},
variant: 'default',
prefix: '+'
}, '1fr');
row.addPriceDisplay('addonsCost', {
label: 'Additional Features',
computedValue: () => {
let total = 0;
if (addonsSection.checkbox('winterization')?.value()) total += 125;
if (addonsSection.checkbox('maintenancePlan')?.value()) total += 250;
if (addonsSection.checkbox('dripConversion')?.value()) total += 400;
if (addonsSection.checkbox('flowerBedZone')?.value()) total += 300;
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: () => {
// System cost
const systemType = systemSection.radioButton('systemType')?.value() || 'sprinkler-premium';
const zones = systemSection.slider('zones')?.value() || 5;
const soilType = propertySection.dropdown('soilType')?.value() || 'loam';
const baseCost = systemBaseCosts[systemType] || 2500;
const zoneCost = (costPerZone[systemType] || 500) * zones;
const soilMultiplier: Record<string, number> = {
'sandy': 0.9, 'loam': 1.0, 'clay': 1.1, 'rocky': 1.3
};
const systemCost = Math.round((baseCost + zoneCost) * (soilMultiplier[soilType] || 1.0));
// Controller cost
const controller = systemSection.radioButton('controllerType')?.value() || 'smart';
let controllerCost = controllerPricing[controller] || 350;
if (addonsSection.checkbox('rainSensor')?.value()) controllerCost += 75;
if (addonsSection.checkbox('soilSensor')?.value()) controllerCost += 200;
// Installation cost
let installCost = 0;
const waterSource = installSection.dropdown('waterSource')?.value() || 'municipal';
if (waterSource === 'well') installCost += 500;
if (waterSource === 'rainwater') installCost += 800;
if (installSection.checkbox('backflowPreventer')?.value()) installCost += 250;
if (installSection.checkbox('pressureRegulator')?.value()) installCost += 150;
const installType = installSection.dropdown('installType')?.value() || 'new';
if (installType === 'replacement') installCost += 300;
// Addons cost
let addonsCost = 0;
if (addonsSection.checkbox('winterization')?.value()) addonsCost += 125;
if (addonsSection.checkbox('maintenancePlan')?.value()) addonsCost += 250;
if (addonsSection.checkbox('dripConversion')?.value()) addonsCost += 400;
if (addonsSection.checkbox('flowerBedZone')?.value()) addonsCost += 300;
const travelFee = getTravelFee();
return systemCost + controllerCost + installCost + addonsCost + travelFee;
},
variant: 'large'
}, '1fr');
row.addPriceDisplay('perZone', {
label: 'Cost Per Zone',
computedValue: () => {
const systemType = systemSection.radioButton('systemType')?.value() || 'sprinkler-premium';
const zones = systemSection.slider('zones')?.value() || 5;
const soilType = propertySection.dropdown('soilType')?.value() || 'loam';
const baseCost = systemBaseCosts[systemType] || 2500;
const zoneCost = (costPerZone[systemType] || 500) * zones;
const soilMultiplier: Record<string, number> = {
'sandy': 0.9, 'loam': 1.0, 'clay': 1.1, 'rocky': 1.3
};
const systemCost = Math.round((baseCost + zoneCost) * (soilMultiplier[soilType] || 1.0));
return Math.round(systemCost / zones);
},
variant: 'default',
suffix: '/zone'
}, '1fr');
});
finalSection.addRow(row => {
row.addTextPanel('savings', {
computedValue: () => {
const controller = systemSection.radioButton('controllerType')?.value() || 'smart';
let savings = 'Standard water savings.';
if (controller === 'smart') savings = 'Smart controller can save 20-40% on water bills.';
if (controller === 'premium') savings = 'Premium smart system can save 30-50% on water bills.';
return savings;
},
customStyles: { 'font-size': '0.95rem', 'color': '#059669', 'font-weight': '500' }
});
});
finalSection.addRow(row => {
row.addTextPanel('disclaimer', {
computedValue: () => 'Estimates based on average costs. Final price depends on site conditions, existing landscaping, and local labor rates. On-site assessment required.',
customStyles: { 'font-size': '0.85rem', 'color': '#64748b', 'font-style': 'italic' }
});
});
form.configureSubmitButton({
label: 'Get Free Quote'
});
}