import React, { useState } from 'react'; import { ClayCard } from './ClayCard'; import { Button } from './Button'; import { ArrowRight, ArrowLeft, TrendingUp, Users, BookOpen } from 'lucide-react'; export interface QuizResult { yearsInBusiness: string; dealsLast12Months: number; leadsPerMonth: number; hoursProspecting: number; performanceLevel: 'below' | 'at' | 'above'; recommendedAction: 'coaching' | 'team' | 'none'; } interface QuizProps { onComplete: (result: QuizResult) => void; calendlyCoachingLink?: string; calendlyTeamLink?: string; } interface Question { id: keyof Pick; question: string; type: 'select' | 'number'; options?: { value: string; label: string }[]; placeholder?: string; } const questions: Question[] = [ { id: 'yearsInBusiness', question: 'How long have you been in real estate?', type: 'select', options: [ { value: '0-1', label: 'Less than 1 year' }, { value: '1-3', label: '1-3 years' }, { value: '3-5', label: '3-5 years' }, { value: '5-10', label: '5-10 years' }, { value: '10+', label: '10+ years' }, ], }, { id: 'dealsLast12Months', question: 'How many deals did you close in the last 12 months?', type: 'number', placeholder: 'Enter number of deals', }, { id: 'leadsPerMonth', question: 'How many leads do you generate per month?', type: 'number', placeholder: 'Enter number of leads', }, { id: 'hoursProspecting', question: 'How many hours per week do you spend prospecting?', type: 'number', placeholder: 'Enter hours per week', }, ]; // Peer benchmarks based on years of experience const getPeerBenchmarks = (years: string) => { const benchmarks: Record = { '0-1': { deals: 3, leads: 10, hours: 15 }, '1-3': { deals: 8, leads: 20, hours: 12 }, '3-5': { deals: 12, leads: 30, hours: 10 }, '5-10': { deals: 18, leads: 40, hours: 10 }, '10+': { deals: 24, leads: 50, hours: 8 }, }; return benchmarks[years] || benchmarks['1-3']; }; const calculatePerformanceLevel = ( answers: Partial ): { level: 'below' | 'at' | 'above'; action: 'coaching' | 'team' | 'none' } => { const benchmarks = getPeerBenchmarks(answers.yearsInBusiness || '1-3'); let score = 0; // Compare deals (weight: 40%) const dealsRatio = (answers.dealsLast12Months || 0) / benchmarks.deals; if (dealsRatio >= 1.2) score += 40; else if (dealsRatio >= 0.8) score += 25; else score += 10; // Compare leads (weight: 35%) const leadsRatio = (answers.leadsPerMonth || 0) / benchmarks.leads; if (leadsRatio >= 1.2) score += 35; else if (leadsRatio >= 0.8) score += 22; else score += 8; // Compare prospecting hours (weight: 25%) const hoursRatio = (answers.hoursProspecting || 0) / benchmarks.hours; if (hoursRatio >= 1.2) score += 25; else if (hoursRatio >= 0.8) score += 16; else score += 6; // Determine performance level let level: 'below' | 'at' | 'above'; let action: 'coaching' | 'team' | 'none'; if (score >= 80) { level = 'above'; action = 'none'; } else if (score >= 55) { level = 'at'; action = 'coaching'; } else { level = 'below'; action = 'team'; } return { level, action }; }; export const Quiz: React.FC = ({ onComplete, calendlyCoachingLink = 'https://calendly.com/coaching', calendlyTeamLink = 'https://calendly.com/team', }) => { const [currentStep, setCurrentStep] = useState(0); const [answers, setAnswers] = useState>({}); const [showResults, setShowResults] = useState(false); const [result, setResult] = useState(null); const currentQuestion = questions[currentStep]; const isLastQuestion = currentStep === questions.length - 1; const progress = ((currentStep + 1) / questions.length) * 100; const handleAnswer = (value: string | number) => { setAnswers((prev) => ({ ...prev, [currentQuestion.id]: value, })); }; const getCurrentAnswer = () => { return answers[currentQuestion.id]; }; const canProceed = () => { const answer = getCurrentAnswer(); return answer !== undefined && answer !== ''; }; const handleNext = () => { if (!canProceed()) return; if (isLastQuestion) { const { level, action } = calculatePerformanceLevel(answers); const finalResult: QuizResult = { yearsInBusiness: answers.yearsInBusiness || '', dealsLast12Months: Number(answers.dealsLast12Months) || 0, leadsPerMonth: Number(answers.leadsPerMonth) || 0, hoursProspecting: Number(answers.hoursProspecting) || 0, performanceLevel: level, recommendedAction: action, }; setResult(finalResult); setShowResults(true); onComplete(finalResult); } else { setCurrentStep((prev) => prev + 1); } }; const handleBack = () => { if (currentStep > 0) { setCurrentStep((prev) => prev - 1); } }; const handleCalendlyClick = (link: string) => { window.open(link, '_blank', 'noopener,noreferrer'); }; if (showResults && result) { return (

Your Results

{result.performanceLevel === 'above' && (

Great work! Based on your responses, you're performing above your peers. Keep up the excellent momentum!

)} {result.performanceLevel === 'at' && (

You're performing at peer level. With some additional coaching, you could take your business to the next level.

)} {result.performanceLevel === 'below' && (

Based on your peers, you may benefit from additional support. Would you like to learn more about coaching or joining our team?

)} {result.performanceLevel !== 'above' && (
)}

Your Responses

Experience

{result.yearsInBusiness} years

Deals (12 mo)

{result.dealsLast12Months}

Leads/Month

{result.leadsPerMonth}

Prospecting Hrs/Wk

{result.hoursProspecting}

); } return (
{/* Progress Bar */}
Question {currentStep + 1} of {questions.length} {Math.round(progress)}% complete

{currentQuestion.question}

{currentQuestion.type === 'select' && currentQuestion.options && (
{currentQuestion.options.map((option) => ( handleAnswer(option.value)} selected={getCurrentAnswer() === option.value} className="!p-4 !rounded-xl" > {option.label} ))}
)} {currentQuestion.type === 'number' && ( handleAnswer(e.target.value ? Number(e.target.value) : '')} /> )}
{currentStep > 0 && ( )}
{/* Input field styles */}
); };