'use client'; import { useState, useEffect, Suspense } from 'react'; import { useSearchParams, useRouter } from 'next/navigation'; import { ColorPicker } from '@/components/pastel/color/ColorPicker'; import { ColorDisplay } from '@/components/pastel/color/ColorDisplay'; import { ColorInfo } from '@/components/pastel/color/ColorInfo'; import { ManipulationPanel } from '@/components/pastel/tools/ManipulationPanel'; import { useColorInfo } from '@/lib/pastel/api/queries'; import { useColorHistory } from '@/lib/pastel/stores/historyStore'; import { Loader2, Share2, History, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { toast } from 'sonner'; function PlaygroundContent() { const searchParams = useSearchParams(); const router = useRouter(); const [color, setColor] = useState(() => { // Initialize from URL if available const urlColor = searchParams.get('color'); return urlColor ? `#${urlColor.replace('#', '')}` : '#ff0099'; }); const { data, isLoading, isError, error } = useColorInfo({ colors: [color], }); const colorInfo = data?.colors[0]; // Color history const { history, addColor, removeColor, clearHistory, getRecent } = useColorHistory(); const recentColors = getRecent(10); // Update URL when color changes useEffect(() => { const hex = color.replace('#', ''); if (hex.length === 6 || hex.length === 3) { router.push(`/pastel?color=${hex}`, { scroll: false }); } }, [color, router]); // Debounced history update useEffect(() => { const timer = setTimeout(() => { const hex = color.replace('#', ''); // Only add valid hex colors to history if (hex.length === 6 || hex.length === 3) { addColor(color); } }, 1000); // Wait 1 second before adding to history return () => clearTimeout(timer); }, [color, addColor]); // Share color via URL const handleShare = () => { const url = `${window.location.origin}/pastel?color=${color.replace('#', '')}`; navigator.clipboard.writeText(url); toast.success('Link copied to clipboard!'); }; // Copy color to clipboard const handleCopyColor = () => { navigator.clipboard.writeText(color); toast.success('Color copied to clipboard!'); }; // Random color generation const handleRandomColor = () => { const randomHex = '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0'); setColor(randomHex); }; return (
Interactive color manipulation and analysis tool
Error loading color information
{error?.message || 'Unknown error'}