export function phoneComputerRepairCalculator(form: FormTs) {
// Base repair prices by device and repair type
const defaultPhonePrices = { 'screen': 69, 'battery': 39, 'charging': 45, 'speaker': 35, 'camera': 59, 'water': 69 };
const phonePrices: Record<string, Record<string, number>> = {
'iphone-standard': { 'screen': 89, 'battery': 49, 'charging': 59, 'speaker': 45, 'camera': 79, 'water': 89 },
'iphone-pro': { 'screen': 149, 'battery': 69, 'charging': 79, 'speaker': 55, 'camera': 129, 'water': 99 },
'iphone-promax': { 'screen': 199, 'battery': 79, 'charging': 89, 'speaker': 65, 'camera': 159, 'water': 109 },
'samsung-standard': { 'screen': 79, 'battery': 45, 'charging': 49, 'speaker': 39, 'camera': 69, 'water': 79 },
'samsung-premium': { 'screen': 159, 'battery': 65, 'charging': 69, 'speaker': 55, 'camera': 119, 'water': 99 },
'other-phone': { 'screen': 69, 'battery': 39, 'charging': 45, 'speaker': 35, 'camera': 59, 'water': 69 }
};
const defaultComputerPrices = { 'screen': 149, 'battery': 89, 'keyboard': 99, 'ssd': 79, 'ram': 49, 'virus': 79, 'os': 69, 'fan': 59 };
const computerPrices: Record<string, Record<string, number>> = {
'laptop': { 'screen': 149, 'battery': 89, 'keyboard': 99, 'ssd': 79, 'ram': 49, 'virus': 79, 'os': 69, 'fan': 59 },
'macbook': { 'screen': 299, 'battery': 149, 'keyboard': 199, 'ssd': 129, 'ram': 99, 'virus': 89, 'os': 99, 'fan': 89 },
'desktop': { 'screen': 0, 'battery': 0, 'keyboard': 29, 'ssd': 69, 'ram': 39, 'virus': 69, 'os': 59, 'fan': 39 }
};
form.addRow(row => {
row.addTextPanel('header', {
computedValue: () => 'Device Repair Cost Calculator',
customStyles: { 'font-size': '1.5rem', 'font-weight': '600', 'color': '#1e293b' }
});
});
form.addSpacer({ height: 20 });
// Device Type Section
const deviceSection = form.addSubform('deviceType', { title: '๐ฑ Device Information' });
deviceSection.addRow(row => {
row.addRadioButton('deviceCategory', {
label: 'Device Category',
options: [
{ id: 'phone', name: 'Phone/Tablet' },
{ id: 'computer', name: 'Computer/Laptop' }
],
defaultValue: 'phone',
orientation: 'horizontal',
isRequired: true
});
});
deviceSection.addRow(row => {
row.addDropdown('phoneModel', {
label: 'Phone Model',
options: [
{ id: 'iphone-standard', name: 'iPhone (Standard models)' },
{ id: 'iphone-pro', name: 'iPhone Pro' },
{ id: 'iphone-promax', name: 'iPhone Pro Max / Plus' },
{ id: 'samsung-standard', name: 'Samsung Galaxy (Standard)' },
{ id: 'samsung-premium', name: 'Samsung Galaxy (Premium/Ultra)' },
{ id: 'other-phone', name: 'Other Phone/Tablet' }
],
defaultValue: 'iphone-standard',
isRequired: true,
isVisible: () => deviceSection.radioButton('deviceCategory')?.value() === 'phone'
}, '1fr');
row.addDropdown('computerModel', {
label: 'Computer Type',
options: [
{ id: 'laptop', name: 'Windows Laptop' },
{ id: 'macbook', name: 'MacBook' },
{ id: 'desktop', name: 'Desktop PC' }
],
defaultValue: 'laptop',
isRequired: true,
isVisible: () => deviceSection.radioButton('deviceCategory')?.value() === 'computer'
}, '1fr');
});
deviceSection.addRow(row => {
row.addDropdown('deviceAge', {
label: 'Device Age',
options: [
{ id: 'new', name: 'Less than 1 year' },
{ id: '1-2', name: '1-2 years' },
{ id: '3-4', name: '3-4 years' },
{ id: '5plus', name: '5+ years (parts may be limited)' }
],
defaultValue: '1-2',
tooltip: 'Older devices may have limited part availability'
}, '1fr');
});
// Phone Repairs Section
const phoneRepairsSection = form.addSubform('phoneRepairs', {
title: '๐ง Phone Repairs',
isVisible: () => deviceSection.radioButton('deviceCategory')?.value() === 'phone'
});
phoneRepairsSection.addRow(row => {
row.addCheckbox('screenRepair', {
label: 'Screen Replacement',
defaultValue: true,
tooltip: 'Cracked or non-responsive display'
}, '1fr');
row.addCheckbox('batteryRepair', {
label: 'Battery Replacement',
defaultValue: false,
tooltip: 'Poor battery life or swelling'
}, '1fr');
});
phoneRepairsSection.addRow(row => {
row.addCheckbox('chargingRepair', {
label: 'Charging Port Repair',
defaultValue: false,
tooltip: 'Not charging or loose connection'
}, '1fr');
row.addCheckbox('speakerRepair', {
label: 'Speaker/Microphone Repair',
defaultValue: false,
tooltip: 'Audio issues during calls or media'
}, '1fr');
});
phoneRepairsSection.addRow(row => {
row.addCheckbox('cameraRepair', {
label: 'Camera Repair',
defaultValue: false,
tooltip: 'Blurry photos or camera not working'
}, '1fr');
row.addCheckbox('waterDamage', {
label: 'Water Damage Treatment',
defaultValue: false,
tooltip: 'Cleaning and component replacement'
}, '1fr');
});
// Computer Repairs Section
const computerRepairsSection = form.addSubform('computerRepairs', {
title: '๐ป Computer Repairs',
isVisible: () => deviceSection.radioButton('deviceCategory')?.value() === 'computer'
});
computerRepairsSection.addRow(row => {
row.addCheckbox('compScreenRepair', {
label: 'Screen Replacement',
defaultValue: false,
tooltip: 'Cracked or damaged laptop display',
isVisible: () => deviceSection.dropdown('computerModel')?.value() !== 'desktop'
}, '1fr');
row.addCheckbox('compBatteryRepair', {
label: 'Battery Replacement',
defaultValue: false,
tooltip: 'Not holding charge',
isVisible: () => deviceSection.dropdown('computerModel')?.value() !== 'desktop'
}, '1fr');
});
computerRepairsSection.addRow(row => {
row.addCheckbox('keyboardRepair', {
label: 'Keyboard Repair/Replacement',
defaultValue: false,
tooltip: 'Keys not working or damaged keyboard'
}, '1fr');
row.addCheckbox('fanRepair', {
label: 'Fan/Cooling System',
defaultValue: false,
tooltip: 'Overheating or noisy fan'
}, '1fr');
});
computerRepairsSection.addRow(row => {
row.addCheckbox('ssdUpgrade', {
label: 'SSD Upgrade/Replacement',
defaultValue: false,
tooltip: 'Faster storage or failed drive'
}, '1fr');
row.addCheckbox('ramUpgrade', {
label: 'RAM Upgrade',
defaultValue: false,
tooltip: 'More memory for better performance'
}, '1fr');
});
computerRepairsSection.addRow(row => {
row.addCheckbox('virusRemoval', {
label: 'Virus/Malware Removal',
defaultValue: false,
tooltip: 'Deep scan and cleaning'
}, '1fr');
row.addCheckbox('osReinstall', {
label: 'OS Reinstallation',
defaultValue: false,
tooltip: 'Fresh system install with data backup'
}, '1fr');
});
// Additional Options
const optionsSection = form.addSubform('options', { title: 'โจ Additional Services' });
optionsSection.addRow(row => {
row.addCheckbox('diagnostics', {
label: 'Full Diagnostics (+$25)',
defaultValue: false,
tooltip: 'Complete device inspection and report'
}, '1fr');
row.addCheckbox('dataBackup', {
label: 'Data Backup (+$35)',
defaultValue: false,
tooltip: 'Backup important files before repair'
}, '1fr');
});
optionsSection.addRow(row => {
row.addCheckbox('expressService', {
label: 'Express Service (+50%)',
defaultValue: false,
tooltip: 'Same-day or next-day repair'
}, '1fr');
row.addCheckbox('extendedWarranty', {
label: 'Extended Warranty (+$29)',
defaultValue: false,
tooltip: '90-day warranty on repairs (standard: 30 days)'
}, '1fr');
});
optionsSection.addRow(row => {
row.addDropdown('partsQuality', {
label: 'Parts Quality',
options: [
{ id: 'aftermarket', name: 'Quality Aftermarket' },
{ id: 'oem', name: 'OEM/Original (+25%)' },
{ id: 'refurbished', name: 'Certified Refurbished (-15%)' }
],
defaultValue: 'aftermarket',
tooltip: 'OEM parts come with manufacturer warranty'
}, '1fr');
});
form.addSpacer({ height: 20, showLine: true, lineStyle: 'dashed' });
// Price Summary Section
const summarySection = form.addSubform('summary', { title: '๐ฐ Repair Estimate', isCollapsible: false });
summarySection.addRow(row => {
row.addPriceDisplay('repairsTotal', {
label: 'Repairs',
computedValue: () => {
const deviceCategory = deviceSection.radioButton('deviceCategory')?.value() || 'phone';
let total = 0;
if (deviceCategory === 'phone') {
const model = deviceSection.dropdown('phoneModel')?.value() || 'iphone-standard';
const prices = phonePrices[model] || defaultPhonePrices;
if (phoneRepairsSection.checkbox('screenRepair')?.value()) total += prices['screen'];
if (phoneRepairsSection.checkbox('batteryRepair')?.value()) total += prices['battery'];
if (phoneRepairsSection.checkbox('chargingRepair')?.value()) total += prices['charging'];
if (phoneRepairsSection.checkbox('speakerRepair')?.value()) total += prices['speaker'];
if (phoneRepairsSection.checkbox('cameraRepair')?.value()) total += prices['camera'];
if (phoneRepairsSection.checkbox('waterDamage')?.value()) total += prices['water'];
} else {
const model = deviceSection.dropdown('computerModel')?.value() || 'laptop';
const prices = computerPrices[model] || defaultComputerPrices;
if (computerRepairsSection.checkbox('compScreenRepair')?.value()) total += prices['screen'];
if (computerRepairsSection.checkbox('compBatteryRepair')?.value()) total += prices['battery'];
if (computerRepairsSection.checkbox('keyboardRepair')?.value()) total += prices['keyboard'];
if (computerRepairsSection.checkbox('fanRepair')?.value()) total += prices['fan'];
if (computerRepairsSection.checkbox('ssdUpgrade')?.value()) total += prices['ssd'];
if (computerRepairsSection.checkbox('ramUpgrade')?.value()) total += prices['ram'];
if (computerRepairsSection.checkbox('virusRemoval')?.value()) total += prices['virus'];
if (computerRepairsSection.checkbox('osReinstall')?.value()) total += prices['os'];
}
return total;
},
variant: 'default'
}, '1fr');
row.addPriceDisplay('partsAdjustment', {
label: 'Parts Quality',
computedValue: () => {
const partsQuality = optionsSection.dropdown('partsQuality')?.value() || 'aftermarket';
const deviceCategory = deviceSection.radioButton('deviceCategory')?.value() || 'phone';
let repairsTotal = 0;
if (deviceCategory === 'phone') {
const model = deviceSection.dropdown('phoneModel')?.value() || 'iphone-standard';
const prices = phonePrices[model] || defaultPhonePrices;
if (phoneRepairsSection.checkbox('screenRepair')?.value()) repairsTotal += prices['screen'];
if (phoneRepairsSection.checkbox('batteryRepair')?.value()) repairsTotal += prices['battery'];
if (phoneRepairsSection.checkbox('chargingRepair')?.value()) repairsTotal += prices['charging'];
if (phoneRepairsSection.checkbox('speakerRepair')?.value()) repairsTotal += prices['speaker'];
if (phoneRepairsSection.checkbox('cameraRepair')?.value()) repairsTotal += prices['camera'];
if (phoneRepairsSection.checkbox('waterDamage')?.value()) repairsTotal += prices['water'];
} else {
const model = deviceSection.dropdown('computerModel')?.value() || 'laptop';
const prices = computerPrices[model] || defaultComputerPrices;
if (computerRepairsSection.checkbox('compScreenRepair')?.value()) repairsTotal += prices['screen'];
if (computerRepairsSection.checkbox('compBatteryRepair')?.value()) repairsTotal += prices['battery'];
if (computerRepairsSection.checkbox('keyboardRepair')?.value()) repairsTotal += prices['keyboard'];
if (computerRepairsSection.checkbox('fanRepair')?.value()) repairsTotal += prices['fan'];
if (computerRepairsSection.checkbox('ssdUpgrade')?.value()) repairsTotal += prices['ssd'];
if (computerRepairsSection.checkbox('ramUpgrade')?.value()) repairsTotal += prices['ram'];
if (computerRepairsSection.checkbox('virusRemoval')?.value()) repairsTotal += prices['virus'];
if (computerRepairsSection.checkbox('osReinstall')?.value()) repairsTotal += prices['os'];
}
if (partsQuality === 'oem') return Math.round(repairsTotal * 0.25);
if (partsQuality === 'refurbished') return Math.round(-repairsTotal * 0.15);
return 0;
},
variant: 'default',
prefix: ''
}, '1fr');
});
summarySection.addRow(row => {
row.addPriceDisplay('additionalServices', {
label: 'Additional Services',
computedValue: () => {
let total = 0;
if (optionsSection.checkbox('diagnostics')?.value()) total += 25;
if (optionsSection.checkbox('dataBackup')?.value()) total += 35;
if (optionsSection.checkbox('extendedWarranty')?.value()) total += 29;
return total;
},
variant: 'default',
prefix: '+'
}, '1fr');
row.addPriceDisplay('expressCharge', {
label: 'Express Service',
computedValue: () => {
if (!optionsSection.checkbox('expressService')?.value()) return 0;
const deviceCategory = deviceSection.radioButton('deviceCategory')?.value() || 'phone';
let repairsTotal = 0;
if (deviceCategory === 'phone') {
const model = deviceSection.dropdown('phoneModel')?.value() || 'iphone-standard';
const prices = phonePrices[model] || defaultPhonePrices;
if (phoneRepairsSection.checkbox('screenRepair')?.value()) repairsTotal += prices['screen'];
if (phoneRepairsSection.checkbox('batteryRepair')?.value()) repairsTotal += prices['battery'];
if (phoneRepairsSection.checkbox('chargingRepair')?.value()) repairsTotal += prices['charging'];
if (phoneRepairsSection.checkbox('speakerRepair')?.value()) repairsTotal += prices['speaker'];
if (phoneRepairsSection.checkbox('cameraRepair')?.value()) repairsTotal += prices['camera'];
if (phoneRepairsSection.checkbox('waterDamage')?.value()) repairsTotal += prices['water'];
} else {
const model = deviceSection.dropdown('computerModel')?.value() || 'laptop';
const prices = computerPrices[model] || defaultComputerPrices;
if (computerRepairsSection.checkbox('compScreenRepair')?.value()) repairsTotal += prices['screen'];
if (computerRepairsSection.checkbox('compBatteryRepair')?.value()) repairsTotal += prices['battery'];
if (computerRepairsSection.checkbox('keyboardRepair')?.value()) repairsTotal += prices['keyboard'];
if (computerRepairsSection.checkbox('fanRepair')?.value()) repairsTotal += prices['fan'];
if (computerRepairsSection.checkbox('ssdUpgrade')?.value()) repairsTotal += prices['ssd'];
if (computerRepairsSection.checkbox('ramUpgrade')?.value()) repairsTotal += prices['ram'];
if (computerRepairsSection.checkbox('virusRemoval')?.value()) repairsTotal += prices['virus'];
if (computerRepairsSection.checkbox('osReinstall')?.value()) repairsTotal += prices['os'];
}
return Math.round(repairsTotal * 0.5);
},
variant: 'default',
prefix: '+'
}, '1fr');
});
const finalSection = form.addSubform('final', {
title: '๐งพ Summary',
isCollapsible: false,
sticky: 'bottom'
});
finalSection.addRow(row => {
row.addPriceDisplay('totalPrice', {
label: 'Total Estimate',
computedValue: () => {
const deviceCategory = deviceSection.radioButton('deviceCategory')?.value() || 'phone';
const partsQuality = optionsSection.dropdown('partsQuality')?.value() || 'aftermarket';
let repairsTotal = 0;
if (deviceCategory === 'phone') {
const model = deviceSection.dropdown('phoneModel')?.value() || 'iphone-standard';
const prices = phonePrices[model] || defaultPhonePrices;
if (phoneRepairsSection.checkbox('screenRepair')?.value()) repairsTotal += prices['screen'];
if (phoneRepairsSection.checkbox('batteryRepair')?.value()) repairsTotal += prices['battery'];
if (phoneRepairsSection.checkbox('chargingRepair')?.value()) repairsTotal += prices['charging'];
if (phoneRepairsSection.checkbox('speakerRepair')?.value()) repairsTotal += prices['speaker'];
if (phoneRepairsSection.checkbox('cameraRepair')?.value()) repairsTotal += prices['camera'];
if (phoneRepairsSection.checkbox('waterDamage')?.value()) repairsTotal += prices['water'];
} else {
const model = deviceSection.dropdown('computerModel')?.value() || 'laptop';
const prices = computerPrices[model] || defaultComputerPrices;
if (computerRepairsSection.checkbox('compScreenRepair')?.value()) repairsTotal += prices['screen'];
if (computerRepairsSection.checkbox('compBatteryRepair')?.value()) repairsTotal += prices['battery'];
if (computerRepairsSection.checkbox('keyboardRepair')?.value()) repairsTotal += prices['keyboard'];
if (computerRepairsSection.checkbox('fanRepair')?.value()) repairsTotal += prices['fan'];
if (computerRepairsSection.checkbox('ssdUpgrade')?.value()) repairsTotal += prices['ssd'];
if (computerRepairsSection.checkbox('ramUpgrade')?.value()) repairsTotal += prices['ram'];
if (computerRepairsSection.checkbox('virusRemoval')?.value()) repairsTotal += prices['virus'];
if (computerRepairsSection.checkbox('osReinstall')?.value()) repairsTotal += prices['os'];
}
// Parts quality adjustment
if (partsQuality === 'oem') repairsTotal *= 1.25;
if (partsQuality === 'refurbished') repairsTotal *= 0.85;
// Express service
if (optionsSection.checkbox('expressService')?.value()) repairsTotal *= 1.5;
// Additional services
if (optionsSection.checkbox('diagnostics')?.value()) repairsTotal += 25;
if (optionsSection.checkbox('dataBackup')?.value()) repairsTotal += 35;
if (optionsSection.checkbox('extendedWarranty')?.value()) repairsTotal += 29;
return Math.round(repairsTotal);
},
variant: 'large'
}, '1fr');
});
finalSection.addRow(row => {
row.addTextPanel('disclaimer', {
computedValue: () => 'Free diagnostics with repair. 30-day warranty on all repairs. Final price confirmed after inspection.',
customStyles: { 'font-size': '0.85rem', 'color': '#64748b', 'font-style': 'italic' }
});
});
form.configureSubmitButton({
label: 'Book Repair'
});
}