export function mattressFinderQuiz(form: FormTs) {
form.setTitle(() => '🛏️ Find Your Perfect Mattress');
// ============ RECOMMENDATION SYSTEM ============
const answers = form.state<Record<string, string | string[] | number>>({});
const setAnswer = (key: string, value: string | string[] | number) => {
answers.update(current => ({ ...current, [key]: value }));
};
type MattressType = 'memory-foam' | 'hybrid' | 'innerspring' | 'latex' | 'airbed';
type Firmness = 'soft' | 'medium-soft' | 'medium' | 'medium-firm' | 'firm';
type SleepPosition = 'side' | 'back' | 'stomach' | 'combination';
const getMattressRecommendation = (): { type: MattressType; name: string; firmness: Firmness; brands: string[]; priceRange: string } => {
const position = answers()['sleepPosition'] as SleepPosition;
const bodyType = answers()['bodyType'] as string;
const concerns = (answers()['concerns'] as string[]) || [];
const budget = answers()['budget'] as string;
const temperature = answers()['temperature'] as string;
let type: MattressType = 'hybrid';
let firmness: Firmness = 'medium';
let brands: string[] = [];
let priceRange = '$800-1500';
// Determine firmness based on sleep position and body type
if (position === 'side') {
firmness = bodyType === 'light' ? 'soft' : 'medium-soft';
} else if (position === 'stomach') {
firmness = bodyType === 'heavy' ? 'firm' : 'medium-firm';
} else if (position === 'back') {
firmness = 'medium';
} else {
firmness = 'medium';
}
// Determine mattress type based on concerns and preferences
if (concerns.includes('back-pain') || concerns.includes('pressure-points')) {
type = 'memory-foam';
} else if (concerns.includes('hot-sleeper') || temperature === 'hot') {
type = 'hybrid';
} else if (concerns.includes('motion-transfer') && !concerns.includes('hot-sleeper')) {
type = 'memory-foam';
} else if (concerns.includes('edge-support') || concerns.includes('durability')) {
type = 'hybrid';
} else if (concerns.includes('allergies')) {
type = 'latex';
}
// Brand and price recommendations based on budget
if (budget === 'budget') {
brands = type === 'memory-foam'
? ['Nectar', 'Zinus', 'Linenspa']
: ['Allswell', 'Lucid', 'Classic Brands'];
priceRange = '$300-600';
} else if (budget === 'mid-range') {
brands = type === 'memory-foam'
? ['Casper Original', 'Leesa', 'Tuft & Needle']
: ['Purple', 'Bear', 'Brooklyn Bedding'];
priceRange = '$800-1500';
} else if (budget === 'premium') {
brands = type === 'memory-foam'
? ['Tempur-Pedic', 'Casper Wave', 'Molecule']
: ['Helix Luxe', 'DreamCloud Premier', 'WinkBed'];
priceRange = '$1500-2500';
} else {
brands = type === 'memory-foam'
? ['Tempur-Pedic ProAdapt', 'IDLE Sleep', 'Avocado Luxury']
: ['Saatva HD', 'Stearns & Foster', 'Beautyrest Black'];
priceRange = '$2500+';
}
const typeNames: Record<MattressType, string> = {
'memory-foam': 'Memory Foam',
'hybrid': 'Hybrid',
'innerspring': 'Innerspring',
'latex': 'Natural Latex',
'airbed': 'Adjustable Airbed'
};
return { type, name: typeNames[type], firmness, brands, priceRange };
};
const getFirmnessDescription = (firmness: Firmness) => {
const descriptions: Record<Firmness, string> = {
'soft': '2-3/10 - Deep sink, maximum pressure relief',
'medium-soft': '4-5/10 - Gentle contouring, good for side sleepers',
'medium': '5-6/10 - Balanced support, versatile',
'medium-firm': '6-7/10 - Supportive with some contouring',
'firm': '7-9/10 - Minimal sink, maximum support'
};
return descriptions[firmness];
};
// ============ COMPLETION SCREEN ============
form.configureCompletionScreen({
type: 'text',
title: () => '🛏️ Your Perfect Mattress Match',
message: () => {
const rec = getMattressRecommendation();
return `Based on your sleep style, we recommend a ${rec.firmness} ${rec.name} mattress. Download your complete guide with brand comparisons and buying tips!`;
}
});
// ============ PAGES SETUP ============
const pages = form.addPages('quiz-pages', {
heightMode: 'current-page'
});
// ============ PAGE 1: Sleep Position ============
const page1 = pages.addPage('sleep-position', { mobileBreakpoint: 500 });
page1.addRow(row => {
row.addTextPanel('header1', {
label: 'Step 1 of 6: How Do You Sleep?',
computedValue: () => 'Your sleep position determines the ideal firmness level',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page1.addSpacer({ height: '24px' });
page1.addRow(row => {
row.addRadioButton('sleepPosition', {
label: 'What\'s your primary sleep position?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'side', name: '🛏️ Side Sleeper - Curled up on your side' },
{ id: 'back', name: '🧘 Back Sleeper - Flat on your back' },
{ id: 'stomach', name: '🏊 Stomach Sleeper - Face down' },
{ id: 'combination', name: '🔄 Combination - Move around all night' }
],
onValueChange: (val) => setAnswer('sleepPosition', val || '')
});
});
page1.addRow(row => {
row.addTextPanel('positionTip', {
computedValue: () => {
const pos = answers()['sleepPosition'];
if (pos === 'side') return '💡 Side sleepers need softer mattresses for shoulder and hip pressure relief';
if (pos === 'back') return '💡 Back sleepers need medium firmness for spinal alignment';
if (pos === 'stomach') return '💡 Stomach sleepers need firmer support to prevent back strain';
if (pos === 'combination') return '💡 Combo sleepers need a versatile medium mattress';
return '';
},
customStyles: {
fontSize: '0.85rem',
color: '#6b7280',
fontStyle: 'italic',
padding: '10px',
background: '#f0f9ff',
borderRadius: '8px',
marginTop: '0.5rem'
}
});
});
// ============ PAGE 2: Body Type ============
const page2 = pages.addPage('body-type', { mobileBreakpoint: 500 });
page2.addRow(row => {
row.addTextPanel('header2', {
label: 'Step 2 of 6: Body Type',
computedValue: () => 'Your weight affects how deeply you sink into a mattress',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page2.addSpacer({ height: '24px' });
page2.addRow(row => {
row.addRadioButton('bodyType', {
label: 'What\'s your body type?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'light', name: '🪶 Light (under 130 lbs) - Need softer mattresses to sink in' },
{ id: 'average', name: '⚖️ Average (130-230 lbs) - Most mattresses work well' },
{ id: 'heavy', name: '💪 Heavy (over 230 lbs) - Need firmer, more durable support' }
],
onValueChange: (val) => setAnswer('bodyType', val || '')
});
});
page2.addRow(row => {
row.addRadioButton('partnerWeight', {
label: 'Do you share the bed with a partner?',
isRequired: true,
orientation: 'horizontal',
options: [
{ id: 'no', name: 'Sleep alone' },
{ id: 'similar', name: 'Similar weight' },
{ id: 'different', name: 'Different weights' }
],
onValueChange: (val) => setAnswer('partnerWeight', val || '')
});
});
// ============ PAGE 3: Sleep Concerns ============
const page3 = pages.addPage('concerns', { mobileBreakpoint: 500 });
page3.addRow(row => {
row.addTextPanel('header3', {
label: 'Step 3 of 6: Sleep Concerns',
computedValue: () => 'What issues do you want your new mattress to solve?',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page3.addSpacer({ height: '24px' });
page3.addRow(row => {
row.addSuggestionChips('concerns', {
label: 'Select all that apply',
suggestions: [
{ id: 'back-pain', name: '😣 Back Pain' },
{ id: 'pressure-points', name: '🎯 Pressure Points' },
{ id: 'hot-sleeper', name: '🔥 Sleep Hot' },
{ id: 'motion-transfer', name: '🏃 Partner Movement' },
{ id: 'edge-support', name: '📐 Edge Support' },
{ id: 'allergies', name: '🤧 Allergies' },
{ id: 'durability', name: '💪 Durability' },
{ id: 'noise', name: '🔇 Noise' }
],
alignment: 'left',
onValueChange: (val) => setAnswer('concerns', val || [])
});
});
page3.addRow(row => {
row.addRadioButton('temperature', {
label: 'Do you tend to sleep hot or cold?',
isRequired: true,
orientation: 'horizontal',
options: [
{ id: 'hot', name: '🔥 Hot' },
{ id: 'neutral', name: '😐 Neutral' },
{ id: 'cold', name: '❄️ Cold' }
],
onValueChange: (val) => setAnswer('temperature', val || '')
});
});
// ============ PAGE 4: Preferences ============
const page4 = pages.addPage('preferences', { mobileBreakpoint: 500 });
page4.addRow(row => {
row.addTextPanel('header4', {
label: 'Step 4 of 6: Preferences',
computedValue: () => 'Tell us about your mattress preferences',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page4.addSpacer({ height: '24px' });
page4.addRow(row => {
row.addRatingScale('firmnessPreference', {
label: 'Firmness preference (if you have one)',
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Plush/Soft',
highLabel: 'Firm/Hard',
variant: 'segmented',
size: 'md',
alignment: 'center',
onValueChange: (val) => setAnswer('firmnessPreference', val || 3)
});
});
page4.addRow(row => {
row.addDropdown('currentMattress', {
label: 'What type of mattress do you currently have?',
options: [
{ id: 'memory-foam', name: 'Memory Foam' },
{ id: 'innerspring', name: 'Innerspring/Coil' },
{ id: 'hybrid', name: 'Hybrid' },
{ id: 'latex', name: 'Latex' },
{ id: 'unknown', name: 'Not sure' }
],
placeholder: 'Select current mattress type',
onValueChange: (val) => setAnswer('currentMattress', val || '')
}, '1fr');
row.addDropdown('currentSatisfaction', {
label: 'How satisfied are you with it?',
options: [
{ id: 'hate', name: 'Hate it - need complete change' },
{ id: 'dislike', name: 'Don\'t like it' },
{ id: 'ok', name: 'It\'s okay' },
{ id: 'like', name: 'Like it, want similar' }
],
placeholder: 'Select satisfaction level',
onValueChange: (val) => setAnswer('currentSatisfaction', val || '')
}, '1fr');
});
// ============ PAGE 5: Budget ============
const page5 = pages.addPage('budget', { mobileBreakpoint: 500 });
page5.addRow(row => {
row.addTextPanel('header5', {
label: 'Step 5 of 6: Budget & Size',
computedValue: () => 'Let\'s find the perfect mattress for your budget',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page5.addSpacer({ height: '24px' });
page5.addRow(row => {
row.addRadioButton('budget', {
label: 'What\'s your budget for a Queen size?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'budget', name: '💵 Under $600 - Budget-friendly options' },
{ id: 'mid-range', name: '💰 $600-1,500 - Best value range' },
{ id: 'premium', name: '💎 $1,500-2,500 - Premium quality' },
{ id: 'luxury', name: '👑 $2,500+ - Luxury/high-end' }
],
onValueChange: (val) => setAnswer('budget', val || '')
});
});
page5.addRow(row => {
row.addDropdown('size', {
label: 'What size do you need?',
isRequired: true,
options: [
{ id: 'twin', name: 'Twin (38" x 75")' },
{ id: 'twin-xl', name: 'Twin XL (38" x 80")' },
{ id: 'full', name: 'Full/Double (54" x 75")' },
{ id: 'queen', name: 'Queen (60" x 80")' },
{ id: 'king', name: 'King (76" x 80")' },
{ id: 'cal-king', name: 'California King (72" x 84")' }
],
placeholder: 'Select mattress size',
onValueChange: (val) => setAnswer('size', val || '')
});
});
// ============ PAGE 6: Results ============
const page6 = pages.addPage('results', { mobileBreakpoint: 500 });
page6.addRow(row => {
row.addTextPanel('header6', {
label: 'Step 6 of 6: Your Perfect Mattress',
computedValue: () => 'Here\'s our recommendation based on your sleep profile',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page6.addSpacer({ height: '24px' });
page6.addRow(row => {
row.addTextPanel('recommendation', {
computedValue: () => {
const rec = getMattressRecommendation();
return `🏆 ${rec.name} Mattress`;
},
customStyles: {
fontSize: '1.5rem',
fontWeight: '700',
textAlign: 'center',
color: '#1e40af',
padding: '20px',
background: 'linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%)',
borderRadius: '12px',
border: '2px solid #3b82f6'
}
});
});
page6.addRow(row => {
row.addTextPanel('firmnessResult', {
computedValue: () => {
const rec = getMattressRecommendation();
return `Recommended Firmness: ${rec.firmness.charAt(0).toUpperCase() + rec.firmness.slice(1)}\n${getFirmnessDescription(rec.firmness)}`;
},
customStyles: {
fontSize: '1rem',
textAlign: 'center',
whiteSpace: 'pre-line',
marginTop: '1rem',
padding: '15px',
background: '#f0fdf4',
borderRadius: '8px'
}
});
});
// Brand recommendations
const brandsSection = page6.addSubform('brands', {
title: '🏷️ Top Brand Recommendations',
isCollapsible: true,
customStyles: {
marginTop: '1rem',
background: '#f9fafb',
borderRadius: '8px'
}
});
brandsSection.addRow(row => {
row.addTextPanel('brandList', {
computedValue: () => {
const rec = getMattressRecommendation();
return `${rec.brands.map((b, i) => `${i + 1}. ${b}`).join('\n')}\n\nPrice Range: ${rec.priceRange}`;
},
customStyles: {
fontSize: '0.95rem',
whiteSpace: 'pre-line',
lineHeight: '1.8'
}
});
});
// Why this recommendation
const whySection = page6.addSubform('why', {
title: '❓ Why This Recommendation',
isCollapsible: true,
customStyles: {
marginTop: '1rem',
background: '#fef3c7',
borderRadius: '8px'
}
});
whySection.addRow(row => {
row.addTextPanel('whyExplanation', {
computedValue: () => {
const rec = getMattressRecommendation();
const pos = answers()['sleepPosition'] as string;
const concerns = (answers()['concerns'] as string[]) || [];
let explanation = `Based on your profile:\n`;
explanation += `• ${pos} sleeper → ${rec.firmness} firmness for proper alignment\n`;
if (concerns.includes('hot-sleeper')) {
explanation += `• Hot sleeper → ${rec.type === 'hybrid' ? 'Hybrid with coils for airflow' : 'Cooling technology recommended'}\n`;
}
if (concerns.includes('back-pain')) {
explanation += `• Back pain → Memory foam contouring for support\n`;
}
if (concerns.includes('motion-transfer')) {
explanation += `• Partner movement → Foam layers absorb motion\n`;
}
return explanation;
},
customStyles: {
fontSize: '0.9rem',
whiteSpace: 'pre-line',
lineHeight: '1.6'
}
});
});
// ============ PAGE 7: Lead Capture ============
const page7 = pages.addPage('lead-capture', { mobileBreakpoint: 500 });
page7.addRow(row => {
row.addTextPanel('header7', {
label: 'Get Your Complete Mattress Guide',
computedValue: () => 'Receive brand comparisons, buying tips, and exclusive discounts',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page7.addSpacer({ height: '24px' });
page7.addRow(row => {
row.addTextbox('name', {
label: 'Your Name',
isRequired: true,
placeholder: 'Mike Johnson'
}, '1fr');
row.addEmail('email', {
label: 'Email Address',
isRequired: true,
placeholder: 'mike@email.com'
}, '1fr');
});
page7.addRow(row => {
row.addCheckboxList('consent', {
options: [
{ id: 'guide', name: '📧 Send me my mattress buying guide (PDF)', isRequired: true },
{ id: 'deals', name: '🏷️ Exclusive mattress deals and discounts' },
{ id: 'tips', name: '💡 Sleep tips and bedroom optimization' }
],
defaultValue: ['guide'],
orientation: 'vertical'
});
});
// ============ PDF REPORT ============
form.configurePdf('mattress-report', pdf => {
pdf.configure({
filename: 'your-mattress-guide.pdf',
pageSize: 'A4',
allowUserDownload: true,
downloadButtonLabel: '📄 Download Mattress Guide',
header: {
title: 'Your Perfect Mattress Guide',
subtitle: 'Personalized recommendations for better sleep'
},
footer: {
text: 'Generated by FormTs Mattress Finder',
showPageNumbers: true
}
});
const rec = getMattressRecommendation();
pdf.addSection('Your Sleep Profile', section => {
section.addRow(row => {
row.addField('Sleep Position', (answers()['sleepPosition'] as string) || 'Not specified');
row.addField('Body Type', (answers()['bodyType'] as string) || 'Not specified');
});
section.addRow(row => {
row.addField('Temperature', (answers()['temperature'] as string) || 'Not specified');
row.addField('Budget', (answers()['budget'] as string) || 'Not specified');
});
});
pdf.addSection('Our Recommendation', section => {
section.addRow(row => {
row.addField('Mattress Type', rec.name);
row.addField('Firmness', rec.firmness);
});
section.addRow(row => {
row.addField('Price Range', rec.priceRange);
});
});
pdf.addSection('Top Brands to Consider', section => {
section.addTable(
['Rank', 'Brand', 'Best For'],
rec.brands.map((b, i) => [`#${i + 1}`, b, 'Your sleep profile'])
);
});
pdf.addSection('Buying Tips', section => {
section.addText('1. Always check the trial period (aim for 100+ nights)');
section.addText('2. Look for at least a 10-year warranty');
section.addText('3. Read reviews from similar sleepers');
section.addText('4. Consider adjustable base compatibility');
section.addText('5. Check return policy and fees');
});
});
// ============ SUBMIT BUTTON ============
form.configureSubmitButton({
label: () => '🛏️ Get My Mattress Guide'
});
form.configureSubmitBehavior({
sendToServer: true
});
}