export function insuranceCoverageQuiz(form: FormTs) {
form.setTitle(() => '🛡️ What Insurance Coverage Do You Need?');
// ============ SCORING SYSTEM ============
const recommendations = form.state<Record<string, number>>({});
const updateRecommendation = (type: string, score: number) => {
recommendations.update(current => ({ ...current, [type]: (current[type] || 0) + score }));
};
type InsuranceType = 'life' | 'health' | 'disability' | 'property' | 'auto' | 'umbrella' | 'business';
const getTopRecommendations = (): InsuranceType[] => {
const r = recommendations();
const sorted = Object.entries(r)
.sort((a, b) => b[1] - a[1])
.slice(0, 3)
.map(([key]) => key as InsuranceType);
return sorted.length > 0 ? sorted : ['health', 'auto', 'life'];
};
const getInsuranceInfo = (type: InsuranceType) => {
const info = {
life: {
label: '💚 Life Insurance',
description: 'Protects your family\'s financial future if something happens to you. Essential if you have dependents or debt.',
priority: 'Critical if you have dependents',
coverage: 'Typically 10-12x annual income',
cost: '$20-50/month for term life'
},
health: {
label: '🏥 Health Insurance',
description: 'Covers medical expenses, doctor visits, prescriptions, and hospital stays. Required by many employers.',
priority: 'Essential for everyone',
coverage: 'Varies by plan type (HMO, PPO, HDHP)',
cost: '$200-600/month individual'
},
disability: {
label: '♿ Disability Insurance',
description: 'Replaces income if you become unable to work due to illness or injury. Often overlooked but crucial.',
priority: 'High if income-dependent',
coverage: '60-70% of income replacement',
cost: '1-3% of annual salary'
},
property: {
label: '🏠 Home/Renters Insurance',
description: 'Protects your home, belongings, and provides liability coverage. Required by mortgage lenders.',
priority: 'Essential for property owners/renters',
coverage: 'Full replacement cost',
cost: '$100-300/month homeowners'
},
auto: {
label: '🚗 Auto Insurance',
description: 'Covers vehicle damage, injuries, and liability from accidents. Required by law in most states.',
priority: 'Required if you own a vehicle',
coverage: 'Liability + Collision + Comprehensive',
cost: '$100-200/month'
},
umbrella: {
label: '☂️ Umbrella Insurance',
description: 'Extra liability protection beyond other policies. Important for high net worth or high-risk situations.',
priority: 'Recommended for high assets',
coverage: '$1-5 million additional liability',
cost: '$150-300/year'
},
business: {
label: '💼 Business Insurance',
description: 'Protects your business from liability, property damage, and employee claims. Essential for entrepreneurs.',
priority: 'Required for business owners',
coverage: 'General liability + E&O + Workers comp',
cost: 'Varies by business type'
}
};
return info[type];
};
// ============ COMPLETION SCREEN ============
form.configureCompletionScreen({
type: 'text',
title: () => 'Your Insurance Recommendations',
message: () => {
const top = getTopRecommendations();
return `Based on your profile, we recommend: ${top.map(t => getInsuranceInfo(t).label).join(', ')}. Download your personalized insurance guide for detailed coverage recommendations.`;
}
});
// ============ PAGES SETUP ============
const pages = form.addPages('quiz-pages', { heightMode: 'current-page' });
// ============ PAGE 1: Personal Profile ============
const page1 = pages.addPage('personal-profile', { mobileBreakpoint: 500 });
page1.addRow(row => {
row.addTextPanel('header1', {
label: 'Step 1 of 5: Personal Profile',
computedValue: () => 'Tell us about yourself to get personalized recommendations',
customStyles: { fontSize: '0.9rem', color: '#6b7280', marginBottom: '1rem' }
});
});
page1.addSpacer({ height: '24px' });
page1.addRow(row => {
row.addDropdown('age', {
label: 'Age Range',
isRequired: true,
options: [
{ id: '18-25', name: '18-25 years' },
{ id: '26-35', name: '26-35 years' },
{ id: '36-45', name: '36-45 years' },
{ id: '46-55', name: '46-55 years' },
{ id: '56-65', name: '56-65 years' },
{ id: '65+', name: '65+ years' }
],
placeholder: 'Select age range',
onValueChange: (val) => {
if (val === '18-25') { updateRecommendation('health', 3); updateRecommendation('auto', 3); }
if (val === '26-35') { updateRecommendation('life', 3); updateRecommendation('disability', 2); }
if (val === '36-45') { updateRecommendation('life', 4); updateRecommendation('disability', 3); }
if (val === '46-55') { updateRecommendation('health', 3); updateRecommendation('life', 3); }
if (val === '56-65') { updateRecommendation('health', 4); updateRecommendation('life', 2); }
if (val === '65+') { updateRecommendation('health', 5); }
}
}, '1fr');
row.addDropdown('maritalStatus', {
label: 'Marital Status',
isRequired: true,
options: [
{ id: 'single', name: 'Single' },
{ id: 'married', name: 'Married' },
{ id: 'divorced', name: 'Divorced' },
{ id: 'widowed', name: 'Widowed' }
],
placeholder: 'Select status',
onValueChange: (val) => {
if (val === 'married') { updateRecommendation('life', 3); updateRecommendation('health', 2); }
}
}, '1fr');
});
page1.addRow(row => {
row.addRadioButton('dependents', {
label: 'Do you have dependents (children, elderly parents)?',
isRequired: true,
orientation: 'horizontal',
options: [
{ id: 'yes', name: 'Yes' },
{ id: 'no', name: 'No' }
],
onValueChange: (val) => {
if (val === 'yes') {
updateRecommendation('life', 5);
updateRecommendation('health', 3);
updateRecommendation('disability', 3);
}
}
});
});
page1.addRow(row => {
row.addDropdown('income', {
label: 'Annual Household Income',
isRequired: true,
options: [
{ id: 'under-50k', name: 'Under $50,000' },
{ id: '50k-100k', name: '$50,000 - $100,000' },
{ id: '100k-200k', name: '$100,000 - $200,000' },
{ id: '200k-500k', name: '$200,000 - $500,000' },
{ id: 'over-500k', name: 'Over $500,000' }
],
placeholder: 'Select income range',
onValueChange: (val) => {
if (val === '100k-200k') { updateRecommendation('umbrella', 2); }
if (val === '200k-500k') { updateRecommendation('umbrella', 4); updateRecommendation('disability', 3); }
if (val === 'over-500k') { updateRecommendation('umbrella', 5); updateRecommendation('disability', 4); }
}
}, '1fr');
row.addDropdown('netWorth', {
label: 'Approximate Net Worth',
options: [
{ id: 'under-100k', name: 'Under $100,000' },
{ id: '100k-500k', name: '$100,000 - $500,000' },
{ id: '500k-1m', name: '$500,000 - $1 million' },
{ id: 'over-1m', name: 'Over $1 million' }
],
placeholder: 'Select net worth',
onValueChange: (val) => {
if (val === '500k-1m') { updateRecommendation('umbrella', 3); }
if (val === 'over-1m') { updateRecommendation('umbrella', 5); }
}
}, '1fr');
});
// ============ PAGE 2: Assets & Property ============
const page2 = pages.addPage('assets', { mobileBreakpoint: 500 });
page2.addRow(row => {
row.addTextPanel('header2', {
label: 'Step 2 of 5: Assets & Property',
computedValue: () => 'What assets do you need to protect?',
customStyles: { fontSize: '0.9rem', color: '#6b7280', marginBottom: '1rem' }
});
});
page2.addSpacer({ height: '24px' });
page2.addRow(row => {
row.addRadioButton('homeOwnership', {
label: 'Housing Situation',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'own-mortgage', name: '🏠 Own home with mortgage' },
{ id: 'own-outright', name: '🏡 Own home outright' },
{ id: 'rent', name: '🏢 Rent' },
{ id: 'other', name: '👥 Live with family/other' }
],
onValueChange: (val) => {
if (val === 'own-mortgage' || val === 'own-outright') {
updateRecommendation('property', 5);
updateRecommendation('umbrella', 2);
}
if (val === 'rent') { updateRecommendation('property', 3); }
}
});
});
page2.addRow(row => {
row.addSuggestionChips('vehicles', {
label: 'What vehicles do you own?',
suggestions: [
{ id: 'car', name: '🚗 Car' },
{ id: 'multiple-cars', name: '🚙 Multiple Cars' },
{ id: 'motorcycle', name: '🏍️ Motorcycle' },
{ id: 'boat', name: '⛵ Boat' },
{ id: 'rv', name: '🚐 RV/Camper' },
{ id: 'none', name: '❌ None' }
],
onValueChange: (val) => {
if (!val) return;
for (const v of val) {
if (v === 'car') updateRecommendation('auto', 4);
if (v === 'multiple-cars') { updateRecommendation('auto', 5); updateRecommendation('umbrella', 2); }
if (v === 'motorcycle') { updateRecommendation('auto', 4); updateRecommendation('umbrella', 2); }
if (v === 'boat') updateRecommendation('umbrella', 3);
if (v === 'rv') updateRecommendation('auto', 3);
}
}
});
});
page2.addRow(row => {
row.addSlider('valuables', {
label: 'Value of jewelry, art, collectibles ($)',
min: 0,
max: 100000,
step: 5000,
defaultValue: 0,
showValue: true,
onValueChange: (val) => {
if ((val || 0) > 10000) updateRecommendation('property', 2);
if ((val || 0) > 50000) { updateRecommendation('property', 3); updateRecommendation('umbrella', 2); }
}
});
});
// ============ PAGE 3: Employment & Business ============
const page3 = pages.addPage('employment', { mobileBreakpoint: 500 });
page3.addRow(row => {
row.addTextPanel('header3', {
label: 'Step 3 of 5: Employment & Business',
computedValue: () => 'Tell us about your work situation',
customStyles: { fontSize: '0.9rem', color: '#6b7280', marginBottom: '1rem' }
});
});
page3.addSpacer({ height: '24px' });
page3.addRow(row => {
row.addRadioButton('employment', {
label: 'Employment Status',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'employed', name: '💼 Employed full-time' },
{ id: 'self-employed', name: '🏢 Self-employed / Freelancer' },
{ id: 'business-owner', name: '🚀 Business owner with employees' },
{ id: 'part-time', name: '⏰ Part-time / Contract' },
{ id: 'retired', name: '🌴 Retired' },
{ id: 'student', name: '🎓 Student' }
],
onValueChange: (val) => {
if (val === 'employed') {
updateRecommendation('disability', 4);
updateRecommendation('life', 2);
}
if (val === 'self-employed') {
updateRecommendation('disability', 5);
updateRecommendation('health', 4);
updateRecommendation('business', 3);
}
if (val === 'business-owner') {
updateRecommendation('business', 5);
updateRecommendation('umbrella', 3);
updateRecommendation('disability', 4);
}
if (val === 'retired') {
updateRecommendation('health', 5);
}
}
});
});
// Conditional business questions
const businessSection = page3.addSubform('businessSection', {
title: '💼 Business Details',
isVisible: () => {
const emp = page3.radioButton('employment')?.value();
return emp === 'self-employed' || emp === 'business-owner';
},
isCollapsible: false,
customStyles: { marginTop: '1rem', padding: '15px', background: '#f0fdf4', borderRadius: '8px' }
});
businessSection.addRow(row => {
row.addDropdown('businessType', {
label: 'Type of Business',
options: [
{ id: 'consulting', name: 'Consulting/Professional Services' },
{ id: 'retail', name: 'Retail/E-commerce' },
{ id: 'restaurant', name: 'Restaurant/Food Service' },
{ id: 'construction', name: 'Construction/Trades' },
{ id: 'healthcare', name: 'Healthcare/Medical' },
{ id: 'tech', name: 'Technology/Software' },
{ id: 'other', name: 'Other' }
],
placeholder: 'Select business type',
onValueChange: (val) => {
if (val === 'construction') updateRecommendation('business', 3);
if (val === 'healthcare') { updateRecommendation('business', 4); updateRecommendation('umbrella', 2); }
}
}, '1fr');
row.addDropdown('employees', {
label: 'Number of Employees',
options: [
{ id: 'solo', name: 'Just me' },
{ id: '1-5', name: '1-5 employees' },
{ id: '6-20', name: '6-20 employees' },
{ id: '20+', name: '20+ employees' }
],
placeholder: 'Select size',
onValueChange: (val) => {
if (val !== 'solo') { updateRecommendation('business', 4); }
}
}, '1fr');
});
page3.addRow(row => {
row.addRadioButton('hasEmployerInsurance', {
label: 'Does your employer provide health insurance?',
orientation: 'horizontal',
options: [
{ id: 'yes', name: 'Yes' },
{ id: 'no', name: 'No' },
{ id: 'na', name: 'N/A' }
],
onValueChange: (val) => {
if (val === 'no') updateRecommendation('health', 4);
}
});
});
// ============ PAGE 4: Health & Lifestyle ============
const page4 = pages.addPage('health', { mobileBreakpoint: 500 });
page4.addRow(row => {
row.addTextPanel('header4', {
label: 'Step 4 of 5: Health & Lifestyle',
computedValue: () => 'A few questions about your health situation',
customStyles: { fontSize: '0.9rem', color: '#6b7280', marginBottom: '1rem' }
});
});
page4.addSpacer({ height: '24px' });
page4.addRow(row => {
row.addRatingScale('healthStatus', {
label: 'How would you rate your current health?',
isRequired: true,
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Poor',
highLabel: 'Excellent',
size: 'md',
variant: 'segmented',
onValueChange: (val) => {
if (val == null) return;
if (val <= 2) { updateRecommendation('health', 4); updateRecommendation('disability', 3); }
if (val >= 4) { updateRecommendation('life', 2); } // Good time to lock in rates
}
});
});
page4.addRow(row => {
row.addCheckboxList('healthConcerns', {
label: 'Any specific health concerns?',
orientation: 'horizontal',
options: [
{ id: 'chronic', name: 'Chronic condition' },
{ id: 'surgery', name: 'Recent surgery' },
{ id: 'medications', name: 'Regular medications' },
{ id: 'family-history', name: 'Family health history' },
{ id: 'none', name: 'None' }
],
onValueChange: (val) => {
if (!val) return;
if (val.includes('chronic') || val.includes('medications')) {
updateRecommendation('health', 3);
}
if (val.includes('family-history')) {
updateRecommendation('life', 3);
}
}
});
});
page4.addRow(row => {
row.addSuggestionChips('lifestyle', {
label: 'Select any that apply to your lifestyle:',
suggestions: [
{ id: 'travel', name: '✈️ Frequent travel' },
{ id: 'extreme-sports', name: '🏂 Extreme sports' },
{ id: 'pets', name: '🐕 Pet owner' },
{ id: 'pool', name: '🏊 Swimming pool' },
{ id: 'home-business', name: '🏠 Home-based business' },
{ id: 'none', name: '❌ None of these' }
],
onValueChange: (val) => {
if (!val) return;
if (val.includes('extreme-sports')) { updateRecommendation('life', 2); updateRecommendation('disability', 2); }
if (val.includes('pool')) updateRecommendation('umbrella', 3);
if (val.includes('pets')) updateRecommendation('umbrella', 2);
if (val.includes('home-business')) updateRecommendation('business', 3);
}
});
});
// ============ PAGE 5: Results ============
const page5 = pages.addPage('results', { mobileBreakpoint: 500 });
page5.addRow(row => {
row.addTextPanel('header5', {
label: 'Step 5 of 5: Your Insurance Recommendations',
computedValue: () => 'Based on your profile, here\'s what we recommend',
customStyles: { fontSize: '0.9rem', color: '#6b7280', marginBottom: '1rem' }
});
});
page5.addSpacer({ height: '24px' });
page5.addRow(row => {
row.addTextPanel('topRec1', {
computedValue: () => {
const top = getTopRecommendations();
const info = getInsuranceInfo(top[0]);
return `#1 ${info.label}`;
},
customStyles: {
fontSize: '1.3rem',
fontWeight: '700',
textAlign: 'center',
color: '#059669',
padding: '15px',
background: '#ecfdf5',
borderRadius: '10px',
border: '2px solid #059669'
}
});
});
page5.addRow(row => {
row.addTextPanel('topRec1Details', {
computedValue: () => {
const top = getTopRecommendations();
const info = getInsuranceInfo(top[0]);
return `${info.description}\n\n📊 Priority: ${info.priority}\n💰 Typical Cost: ${info.cost}`;
},
customStyles: {
fontSize: '0.95rem',
color: '#374151',
padding: '15px',
background: '#f3f4f6',
borderRadius: '8px',
lineHeight: '1.6',
whiteSpace: 'pre-line'
}
});
});
// Additional recommendations
const moreRecs = page5.addSubform('moreRecommendations', {
title: '📋 Additional Recommendations (click to expand)',
isCollapsible: true,
customStyles: { marginTop: '1rem', background: '#f9fafb', borderRadius: '8px' }
});
moreRecs.addRow(row => {
row.addTextPanel('rec2', {
computedValue: () => {
const top = getTopRecommendations();
if (top.length < 2) return '';
const info = getInsuranceInfo(top[1]);
return `#2 ${info.label}: ${info.priority}`;
},
customStyles: { fontSize: '0.9rem', padding: '10px', background: '#dbeafe', borderRadius: '6px' }
});
});
moreRecs.addRow(row => {
row.addTextPanel('rec3', {
computedValue: () => {
const top = getTopRecommendations();
if (top.length < 3) return '';
const info = getInsuranceInfo(top[2]);
return `#3 ${info.label}: ${info.priority}`;
},
customStyles: { fontSize: '0.9rem', padding: '10px', background: '#fef3c7', borderRadius: '6px' }
});
});
// ============ PAGE 6: Lead Capture ============
const page6 = pages.addPage('lead-capture', { mobileBreakpoint: 500 });
page6.addRow(row => {
row.addTextPanel('header6', {
label: 'Step 6 of 6: Get Your Insurance Guide',
computedValue: () => 'Receive your personalized insurance recommendations',
customStyles: { fontSize: '0.9rem', color: '#6b7280', marginBottom: '1rem' }
});
});
page6.addSpacer({ height: '24px' });
page6.addRow(row => {
row.addTextbox('name', { label: 'Your Name', isRequired: true, placeholder: 'Jane Smith' }, '1fr');
row.addEmail('email', { label: 'Email', isRequired: true, placeholder: 'jane@email.com' }, '1fr');
});
page6.addRow(row => {
row.addTextbox('phone', { label: 'Phone (optional)', placeholder: '(555) 123-4567' }, '1fr');
row.addTextbox('zipCode', { label: 'ZIP Code', placeholder: '10001' }, '1fr');
});
page6.addRow(row => {
row.addCheckboxList('consent', {
options: [
{ id: 'report', name: '📄 Send me my personalized insurance guide', isRequired: true },
{ id: 'quotes', name: '💰 Get quotes from insurance providers' },
{ id: 'advisor', name: '📞 Connect me with an insurance advisor' }
],
defaultValue: ['report'],
orientation: 'vertical'
});
});
// ============ PDF REPORT ============
form.configurePdf('insurance-guide', pdf => {
pdf.configure({
filename: 'insurance-coverage-guide.pdf',
pageSize: 'A4',
allowUserDownload: true,
downloadButtonLabel: '📄 Download Insurance Guide',
header: { title: 'Your Insurance Coverage Guide', subtitle: 'Personalized Recommendations' },
footer: { text: 'Generated by FormTs Insurance Assessment', showPageNumbers: true }
});
pdf.addSection('Recommended Coverage', section => {
const top = getTopRecommendations();
for (let i = 0; i < top.length; i++) {
const info = getInsuranceInfo(top[i]);
section.addText(`${i + 1}. ${info.label}`);
section.addText(` Priority: ${info.priority}`);
section.addText(` Typical Cost: ${info.cost}`);
section.addSpacer(10);
}
});
pdf.addSection('Coverage Details', section => {
const top = getTopRecommendations();
for (const type of top) {
const info = getInsuranceInfo(type);
section.addText(`${info.label}`);
section.addText(info.description);
section.addText(`Coverage: ${info.coverage}`);
section.addSpacer(15);
}
});
pdf.addPageBreak();
pdf.addSection('Next Steps', section => {
section.addText('1. Review each recommended coverage type');
section.addText('2. Gather quotes from multiple insurance providers');
section.addText('3. Compare coverage levels, deductibles, and premiums');
section.addText('4. Consider bundling policies for discounts');
section.addText('5. Review coverage annually or when life changes occur');
});
});
// ============ SUBMIT BUTTON ============
form.configureSubmitButton({
label: () => '🛡️ Get My Insurance Guide'
});
form.configureSubmitBehavior({ sendToServer: true });
}