'use client'; import { useState } from 'react'; import { ColorPicker } from '@/components/color/ColorPicker'; import { ColorDisplay } from '@/components/color/ColorDisplay'; import { Button } from '@/components/ui/button'; import { Select } from '@/components/ui/select'; import { useSimulateColorBlindness } from '@/lib/api/queries'; import { Loader2, Eye, Plus, X } from 'lucide-react'; import { toast } from 'sonner'; type ColorBlindnessType = 'protanopia' | 'deuteranopia' | 'tritanopia'; export default function ColorBlindPage() { const [colors, setColors] = useState(['#ff0099']); const [blindnessType, setBlindnessType] = useState('protanopia'); const [simulations, setSimulations] = useState< Array<{ input: string; output: string; difference_percentage: number }> >([]); const simulateMutation = useSimulateColorBlindness(); const handleSimulate = async () => { try { const result = await simulateMutation.mutateAsync({ colors, type: blindnessType, }); setSimulations(result.colors); toast.success(`Simulated ${blindnessType}`); } catch (error) { toast.error('Failed to simulate color blindness'); console.error(error); } }; const addColor = () => { if (colors.length < 10) { setColors([...colors, '#000000']); } }; const removeColor = (index: number) => { if (colors.length > 1) { setColors(colors.filter((_, i) => i !== index)); } }; const updateColor = (index: number, color: string) => { const newColors = [...colors]; newColors[index] = color; setColors(newColors); }; const typeDescriptions: Record = { protanopia: 'Red-blind (affects ~1% of males)', deuteranopia: 'Green-blind (affects ~1% of males)', tritanopia: 'Blue-blind (rare, affects ~0.001%)', }; return (

Color Blindness Simulator

Simulate how colors appear with different types of color blindness

{/* Controls */}

Colors to Test

{colors.map((color, index) => (
updateColor(index, newColor)} />
{colors.length > 1 && ( )}
))}

Blindness Type

{typeDescriptions[blindnessType]}

{/* Results */}
{simulations.length > 0 ? ( <>

Simulation Results

Compare original colors (left) with how they appear to people with{' '} {blindnessType} (right)

{simulations.map((sim, index) => (

Original

{sim.input}

As Seen ({sim.difference_percentage.toFixed(1)}% difference)

{sim.output}
))}

Accessibility Tip

Ensure important information isn't conveyed by color alone. Use text labels, patterns, or icons to make your design accessible to everyone.

) : (

Add colors and click Simulate to see how they appear

with different types of color blindness

)}
); }