export function petInsuranceCalculator(form: FormTs) {
form.addRow(row => {
row.addTextPanel('header', {
computedValue: () => 'Pet Insurance Calculator',
customStyles: { 'font-size': '1.5rem', 'font-weight': '600', 'color': '#1e293b' }
});
});
form.addSpacer({ height: 20 });
// Pet Information Section
const petSection = form.addSubform('pet', { title: '🐾 Pet Information' });
petSection.addRow(row => {
row.addDropdown('petType', {
label: 'Pet Type',
options: [
{ id: 'dog', name: 'Dog' },
{ id: 'cat', name: 'Cat' }
],
defaultValue: 'dog',
isRequired: true
}, '1fr');
row.addDropdown('breed', {
label: 'Breed',
options: [
{ id: 'mixed-small', name: 'Mixed Breed - Small' },
{ id: 'mixed-medium', name: 'Mixed Breed - Medium' },
{ id: 'mixed-large', name: 'Mixed Breed - Large' },
{ id: 'labrador', name: 'Labrador Retriever' },
{ id: 'golden', name: 'Golden Retriever' },
{ id: 'german-shepherd', name: 'German Shepherd' },
{ id: 'bulldog', name: 'Bulldog (English/French)' },
{ id: 'poodle', name: 'Poodle' },
{ id: 'beagle', name: 'Beagle' },
{ id: 'husky', name: 'Siberian Husky' },
{ id: 'boxer', name: 'Boxer' },
{ id: 'dachshund', name: 'Dachshund' },
{ id: 'chihuahua', name: 'Chihuahua' },
{ id: 'domestic-short', name: 'Domestic Shorthair' },
{ id: 'domestic-long', name: 'Domestic Longhair' },
{ id: 'siamese', name: 'Siamese' },
{ id: 'persian', name: 'Persian' },
{ id: 'maine-coon', name: 'Maine Coon' },
{ id: 'other', name: 'Other Breed' }
],
defaultValue: 'mixed-medium',
isRequired: true
}, '1fr');
});
petSection.addRow(row => {
row.addInteger('age', {
label: 'Pet Age (Years)',
min: 0,
max: 20,
defaultValue: 3,
isRequired: true
}, '1fr');
row.addDropdown('gender', {
label: 'Gender',
options: [
{ id: 'male', name: 'Male' },
{ id: 'female', name: 'Female' }
],
defaultValue: 'male'
}, '1fr');
});
petSection.addRow(row => {
row.addCheckbox('spayedNeutered', {
label: 'Spayed/Neutered',
defaultValue: true,
tooltip: 'Spayed/neutered pets may qualify for discounts'
}, '1fr');
row.addCheckbox('microchipped', {
label: 'Microchipped',
defaultValue: false,
tooltip: 'Some insurers offer microchip discounts'
}, '1fr');
});
// Coverage Section
const coverageSection = form.addSubform('coverage', { title: '🛡️ Coverage Options' });
coverageSection.addRow(row => {
row.addRadioButton('planType', {
label: 'Plan Type',
options: [
{ id: 'accident', name: 'Accident Only - Injuries, emergencies' },
{ id: 'accident-illness', name: 'Accident & Illness - Most common' },
{ id: 'comprehensive', name: 'Comprehensive - Includes wellness' }
],
defaultValue: 'accident-illness',
isRequired: true
});
});
coverageSection.addRow(row => {
row.addDropdown('annualLimit', {
label: 'Annual Coverage Limit',
options: [
{ id: '5000', name: '$5,000/year' },
{ id: '10000', name: '$10,000/year' },
{ id: '15000', name: '$15,000/year' },
{ id: '20000', name: '$20,000/year' },
{ id: 'unlimited', name: 'Unlimited' }
],
defaultValue: '10000',
tooltip: 'Maximum amount insurer pays annually'
}, '1fr');
row.addDropdown('deductible', {
label: 'Annual Deductible',
options: [
{ id: '100', name: '$100' },
{ id: '250', name: '$250' },
{ id: '500', name: '$500' },
{ id: '750', name: '$750' },
{ id: '1000', name: '$1,000' }
],
defaultValue: '250',
tooltip: 'Amount you pay before insurance kicks in'
}, '1fr');
});
coverageSection.addRow(row => {
row.addDropdown('reimbursement', {
label: 'Reimbursement Rate',
options: [
{ id: '70', name: '70%' },
{ id: '80', name: '80%' },
{ id: '90', name: '90%' },
{ id: '100', name: '100%' }
],
defaultValue: '80',
tooltip: 'Percentage of covered costs insurer pays'
});
});
// Add-ons Section
const addonsSection = form.addSubform('addons', { title: '✨ Optional Add-ons' });
addonsSection.addRow(row => {
row.addCheckbox('wellness', {
label: 'Wellness/Preventive Care',
defaultValue: false,
tooltip: 'Covers vaccines, annual exams, flea prevention',
isVisible: () => coverageSection.radioButton('planType')?.value() !== 'comprehensive'
}, '1fr');
row.addCheckbox('dental', {
label: 'Dental Coverage',
defaultValue: false,
tooltip: 'Covers dental cleanings and extractions'
}, '1fr');
});
addonsSection.addRow(row => {
row.addCheckbox('behavioral', {
label: 'Behavioral Therapy',
defaultValue: false,
tooltip: 'Covers training and behavioral issues'
}, '1fr');
row.addCheckbox('alternative', {
label: 'Alternative Therapies',
defaultValue: false,
tooltip: 'Acupuncture, physical therapy, chiropractic'
}, '1fr');
});
addonsSection.addRow(row => {
row.addCheckbox('prescription', {
label: 'Prescription Food',
defaultValue: false,
tooltip: 'Covers prescribed specialty diets'
}, '1fr');
row.addCheckbox('endOfLife', {
label: 'End-of-Life Care',
defaultValue: false,
tooltip: 'Covers euthanasia and cremation'
}, '1fr');
});
form.addSpacer({ height: 20, showLine: true, lineStyle: 'dashed' });
// Pricing Breakdown
const breakdownSection = form.addSubform('breakdown', { title: '📊 Premium Breakdown', isCollapsible: true });
breakdownSection.addRow(row => {
row.addPriceDisplay('basePremium', {
label: 'Base Premium',
computedValue: () => {
const petType = petSection.dropdown('petType')?.value() || 'dog';
const breed = petSection.dropdown('breed')?.value() || 'mixed-medium';
const age = petSection.integer('age')?.value() || 3;
const planType = coverageSection.radioButton('planType')?.value() || 'accident-illness';
// Base rates by pet type
let baseRate = petType === 'dog' ? 35 : 25;
// Breed risk multipliers
const breedMultipliers: Record<string, number> = {
'mixed-small': 0.9, 'mixed-medium': 1, 'mixed-large': 1.1,
'labrador': 1.15, 'golden': 1.2, 'german-shepherd': 1.25,
'bulldog': 1.5, 'poodle': 1.1, 'beagle': 1.05,
'husky': 1.2, 'boxer': 1.3, 'dachshund': 1.15,
'chihuahua': 1.05, 'domestic-short': 0.9, 'domestic-long': 0.95,
'siamese': 1.1, 'persian': 1.2, 'maine-coon': 1.15, 'other': 1
};
baseRate *= breedMultipliers[breed] || 1;
// Age multipliers
if (age < 1) baseRate *= 1.1;
else if (age < 4) baseRate *= 1;
else if (age < 7) baseRate *= 1.2;
else if (age < 10) baseRate *= 1.5;
else baseRate *= 2;
// Plan type multipliers
const planMultipliers: Record<string, number> = {
'accident': 0.5, 'accident-illness': 1, 'comprehensive': 1.4
};
baseRate *= planMultipliers[planType] || 1;
return Math.round(baseRate * 100) / 100;
},
variant: 'default'
}, '1fr');
row.addPriceDisplay('coverageAdjustment', {
label: 'Coverage Adjustment',
computedValue: () => {
const petType = petSection.dropdown('petType')?.value() || 'dog';
const breed = petSection.dropdown('breed')?.value() || 'mixed-medium';
const age = petSection.integer('age')?.value() || 3;
const planType = coverageSection.radioButton('planType')?.value() || 'accident-illness';
const annualLimit = coverageSection.dropdown('annualLimit')?.value() || '10000';
const deductible = coverageSection.dropdown('deductible')?.value() || '250';
const reimbursement = coverageSection.dropdown('reimbursement')?.value() || '80';
// Calculate base first
let baseRate = petType === 'dog' ? 35 : 25;
const breedMultipliers: Record<string, number> = {
'mixed-small': 0.9, 'mixed-medium': 1, 'mixed-large': 1.1,
'labrador': 1.15, 'golden': 1.2, 'german-shepherd': 1.25,
'bulldog': 1.5, 'poodle': 1.1, 'beagle': 1.05,
'husky': 1.2, 'boxer': 1.3, 'dachshund': 1.15,
'chihuahua': 1.05, 'domestic-short': 0.9, 'domestic-long': 0.95,
'siamese': 1.1, 'persian': 1.2, 'maine-coon': 1.15, 'other': 1
};
baseRate *= breedMultipliers[breed] || 1;
if (age < 1) baseRate *= 1.1;
else if (age < 4) baseRate *= 1;
else if (age < 7) baseRate *= 1.2;
else if (age < 10) baseRate *= 1.5;
else baseRate *= 2;
const planMultipliers: Record<string, number> = { 'accident': 0.5, 'accident-illness': 1, 'comprehensive': 1.4 };
baseRate *= planMultipliers[planType] || 1;
// Coverage adjustments
const limitMultipliers: Record<string, number> = { '5000': 0.85, '10000': 1, '15000': 1.1, '20000': 1.2, 'unlimited': 1.35 };
const deductibleMultipliers: Record<string, number> = { '100': 1.2, '250': 1, '500': 0.85, '750': 0.75, '1000': 0.65 };
const reimbursementMultipliers: Record<string, number> = { '70': 0.85, '80': 1, '90': 1.15, '100': 1.3 };
const adjustment = baseRate * ((limitMultipliers[annualLimit] || 1) + (deductibleMultipliers[deductible] || 1) + (reimbursementMultipliers[reimbursement] || 1) - 3);
return Math.round(adjustment * 100) / 100;
},
variant: 'default'
}, '1fr');
});
breakdownSection.addRow(row => {
row.addPriceDisplay('addonsCost', {
label: 'Add-ons',
computedValue: () => {
let addons = 0;
const planType = coverageSection.radioButton('planType')?.value() || 'accident-illness';
if (addonsSection.checkbox('wellness')?.value() && planType !== 'comprehensive') addons += 15;
if (addonsSection.checkbox('dental')?.value()) addons += 10;
if (addonsSection.checkbox('behavioral')?.value()) addons += 8;
if (addonsSection.checkbox('alternative')?.value()) addons += 12;
if (addonsSection.checkbox('prescription')?.value()) addons += 7;
if (addonsSection.checkbox('endOfLife')?.value()) addons += 5;
return addons;
},
variant: 'default'
}, '1fr');
row.addPriceDisplay('discounts', {
label: 'Discounts',
computedValue: () => {
let discount = 0;
if (petSection.checkbox('spayedNeutered')?.value()) discount += 3;
if (petSection.checkbox('microchipped')?.value()) discount += 2;
return -discount;
},
variant: 'success'
}, '1fr');
});
// Quote Section
const quoteSection = form.addSubform('quote', { title: '💰 Your Quote', isCollapsible: false });
quoteSection.addRow(row => {
row.addPriceDisplay('monthlyPremium', {
label: 'Monthly Premium',
computedValue: () => {
const petType = petSection.dropdown('petType')?.value() || 'dog';
const breed = petSection.dropdown('breed')?.value() || 'mixed-medium';
const age = petSection.integer('age')?.value() || 3;
const planType = coverageSection.radioButton('planType')?.value() || 'accident-illness';
const annualLimit = coverageSection.dropdown('annualLimit')?.value() || '10000';
const deductible = coverageSection.dropdown('deductible')?.value() || '250';
const reimbursement = coverageSection.dropdown('reimbursement')?.value() || '80';
let baseRate = petType === 'dog' ? 35 : 25;
const breedMultipliers: Record<string, number> = {
'mixed-small': 0.9, 'mixed-medium': 1, 'mixed-large': 1.1,
'labrador': 1.15, 'golden': 1.2, 'german-shepherd': 1.25,
'bulldog': 1.5, 'poodle': 1.1, 'beagle': 1.05,
'husky': 1.2, 'boxer': 1.3, 'dachshund': 1.15,
'chihuahua': 1.05, 'domestic-short': 0.9, 'domestic-long': 0.95,
'siamese': 1.1, 'persian': 1.2, 'maine-coon': 1.15, 'other': 1
};
baseRate *= breedMultipliers[breed] || 1;
if (age < 1) baseRate *= 1.1;
else if (age < 4) baseRate *= 1;
else if (age < 7) baseRate *= 1.2;
else if (age < 10) baseRate *= 1.5;
else baseRate *= 2;
const planMultipliers: Record<string, number> = { 'accident': 0.5, 'accident-illness': 1, 'comprehensive': 1.4 };
baseRate *= planMultipliers[planType] || 1;
const limitMultipliers: Record<string, number> = { '5000': 0.85, '10000': 1, '15000': 1.1, '20000': 1.2, 'unlimited': 1.35 };
const deductibleMultipliers: Record<string, number> = { '100': 1.2, '250': 1, '500': 0.85, '750': 0.75, '1000': 0.65 };
const reimbursementMultipliers: Record<string, number> = { '70': 0.85, '80': 1, '90': 1.15, '100': 1.3 };
baseRate *= limitMultipliers[annualLimit] || 1;
baseRate *= deductibleMultipliers[deductible] || 1;
baseRate *= reimbursementMultipliers[reimbursement] || 1;
// Add-ons
if (addonsSection.checkbox('wellness')?.value() && planType !== 'comprehensive') baseRate += 15;
if (addonsSection.checkbox('dental')?.value()) baseRate += 10;
if (addonsSection.checkbox('behavioral')?.value()) baseRate += 8;
if (addonsSection.checkbox('alternative')?.value()) baseRate += 12;
if (addonsSection.checkbox('prescription')?.value()) baseRate += 7;
if (addonsSection.checkbox('endOfLife')?.value()) baseRate += 5;
// Discounts
if (petSection.checkbox('spayedNeutered')?.value()) baseRate -= 3;
if (petSection.checkbox('microchipped')?.value()) baseRate -= 2;
return Math.max(Math.round(baseRate * 100) / 100, 10);
},
variant: 'large'
}, '1fr');
row.addPriceDisplay('annualPremium', {
label: 'Annual Premium',
computedValue: () => {
const petType = petSection.dropdown('petType')?.value() || 'dog';
const breed = petSection.dropdown('breed')?.value() || 'mixed-medium';
const age = petSection.integer('age')?.value() || 3;
const planType = coverageSection.radioButton('planType')?.value() || 'accident-illness';
const annualLimit = coverageSection.dropdown('annualLimit')?.value() || '10000';
const deductible = coverageSection.dropdown('deductible')?.value() || '250';
const reimbursement = coverageSection.dropdown('reimbursement')?.value() || '80';
let baseRate = petType === 'dog' ? 35 : 25;
const breedMultipliers: Record<string, number> = {
'mixed-small': 0.9, 'mixed-medium': 1, 'mixed-large': 1.1,
'labrador': 1.15, 'golden': 1.2, 'german-shepherd': 1.25,
'bulldog': 1.5, 'poodle': 1.1, 'beagle': 1.05,
'husky': 1.2, 'boxer': 1.3, 'dachshund': 1.15,
'chihuahua': 1.05, 'domestic-short': 0.9, 'domestic-long': 0.95,
'siamese': 1.1, 'persian': 1.2, 'maine-coon': 1.15, 'other': 1
};
baseRate *= breedMultipliers[breed] || 1;
if (age < 1) baseRate *= 1.1;
else if (age < 4) baseRate *= 1;
else if (age < 7) baseRate *= 1.2;
else if (age < 10) baseRate *= 1.5;
else baseRate *= 2;
const planMultipliers: Record<string, number> = { 'accident': 0.5, 'accident-illness': 1, 'comprehensive': 1.4 };
baseRate *= planMultipliers[planType] || 1;
const limitMultipliers: Record<string, number> = { '5000': 0.85, '10000': 1, '15000': 1.1, '20000': 1.2, 'unlimited': 1.35 };
const deductibleMultipliers: Record<string, number> = { '100': 1.2, '250': 1, '500': 0.85, '750': 0.75, '1000': 0.65 };
const reimbursementMultipliers: Record<string, number> = { '70': 0.85, '80': 1, '90': 1.15, '100': 1.3 };
baseRate *= limitMultipliers[annualLimit] || 1;
baseRate *= deductibleMultipliers[deductible] || 1;
baseRate *= reimbursementMultipliers[reimbursement] || 1;
if (addonsSection.checkbox('wellness')?.value() && planType !== 'comprehensive') baseRate += 15;
if (addonsSection.checkbox('dental')?.value()) baseRate += 10;
if (addonsSection.checkbox('behavioral')?.value()) baseRate += 8;
if (addonsSection.checkbox('alternative')?.value()) baseRate += 12;
if (addonsSection.checkbox('prescription')?.value()) baseRate += 7;
if (addonsSection.checkbox('endOfLife')?.value()) baseRate += 5;
if (petSection.checkbox('spayedNeutered')?.value()) baseRate -= 3;
if (petSection.checkbox('microchipped')?.value()) baseRate -= 2;
return Math.max(Math.round(baseRate * 12 * 0.95 * 100) / 100, 120); // 5% annual discount
},
variant: 'success'
}, '1fr');
});
quoteSection.addRow(row => {
row.addTextPanel('savings', {
computedValue: () => 'Pay annually and save 5%!',
customStyles: { 'font-size': '0.9rem', 'color': '#059669', 'text-align': 'center' }
});
});
// Summary Section
const summarySection = form.addSubform('summary', {
title: '🐕 Summary',
isCollapsible: false,
sticky: 'bottom'
});
summarySection.addRow(row => {
row.addTextPanel('summaryText', {
computedValue: () => {
const petType = petSection.dropdown('petType')?.value() || 'dog';
const age = petSection.integer('age')?.value() || 3;
const planType = coverageSection.radioButton('planType')?.value() || 'accident-illness';
const reimbursement = coverageSection.dropdown('reimbursement')?.value() || '80';
const planLabels: Record<string, string> = {
'accident': 'accident-only', 'accident-illness': 'accident & illness', 'comprehensive': 'comprehensive'
};
return `${planLabels[planType]} coverage for your ${age}-year-old ${petType} at ${reimbursement}% reimbursement`;
},
customStyles: { 'font-size': '0.95rem', 'font-weight': '500', 'text-align': 'center', 'color': '#1e293b' }
});
});
summarySection.addRow(row => {
row.addTextPanel('disclaimer', {
computedValue: () => 'Estimates only. Actual premiums vary by insurer and location. Pre-existing conditions excluded.',
customStyles: { 'font-size': '0.8rem', 'color': '#64748b', 'text-align': 'center' }
});
});
form.configureSubmitButton({
label: 'Get Quotes'
});
}