'use client'; import React, { useState, useEffect } from 'react'; import ColorSchemeCard from "./components/ColorSchemeCard"; import ActionButton from "./components/ActionButton"; import SettingsIcon from "./components/SettingsIcon"; import Settings from "./components/Settings"; import { ColorScheme, knownSchemes, generateRandomScheme, crossSchemes, generateSchemeFromGeneticAlgorithm } from './utils/colorSchemes'; export default function Home() { const [schemes, setSchemes] = useState([]); const [selectedSchemes, setSelectedSchemes] = useState([]); const [isDarkMode, setIsDarkMode] = useState(false); const [isSettingsOpen, setIsSettingsOpen] = useState(false); const [likedSchemes, setLikedSchemes] = useState([]); const [dislikedSchemes, setDislikedSchemes] = useState([]); useEffect(() => { generateNewSchemes(); setIsDarkMode(window.matchMedia('(prefers-color-scheme: dark)').matches); const storedLikedSchemes = localStorage.getItem('likedSchemes'); const storedDislikedSchemes = localStorage.getItem('dislikedSchemes'); if (storedLikedSchemes) { setLikedSchemes(JSON.parse(storedLikedSchemes)); } if (storedDislikedSchemes) { setDislikedSchemes(JSON.parse(storedDislikedSchemes)); } }, []); useEffect(() => { document.documentElement.classList.toggle('dark', isDarkMode); }, [isDarkMode]); useEffect(() => { localStorage.setItem('likedSchemes', JSON.stringify(likedSchemes)); }, [likedSchemes]); useEffect(() => { localStorage.setItem('dislikedSchemes', JSON.stringify(dislikedSchemes)); }, [dislikedSchemes]); const generateNewSchemes = () => { const newSchemes = [ knownSchemes[Math.floor(Math.random() * knownSchemes.length)], generateRandomScheme(), likedSchemes.length > 0 ? generateSchemeFromGeneticAlgorithm(likedSchemes, dislikedSchemes) : generateRandomScheme() ]; setSchemes(newSchemes); setSelectedSchemes([]); }; const handleSchemeSelect = (index: number) => { setSelectedSchemes(prev => { if (prev.includes(index)) { return prev.filter(i => i !== index); } else if (prev.length < 2) { return [...prev, index]; } return prev; }); }; const handleAction = () => { if (selectedSchemes.length === 2) { const crossedScheme = crossSchemes(schemes[selectedSchemes[0]], schemes[selectedSchemes[1]]); setLikedSchemes(prev => [...prev, schemes[selectedSchemes[0]], schemes[selectedSchemes[1]]]); setSchemes([crossedScheme, knownSchemes[Math.floor(Math.random() * knownSchemes.length)], generateSchemeFromGeneticAlgorithm(likedSchemes, dislikedSchemes)]); setSelectedSchemes([]); } else { setDislikedSchemes(prev => [...prev, ...schemes]); generateNewSchemes(); } }; const toggleDarkMode = () => { setIsDarkMode(prev => !prev); }; return (

Terminal Color Scheme Generator

setIsSettingsOpen(true)} />
{schemes.map((scheme, index) => ( handleSchemeSelect(index)} /> ))}
setIsSettingsOpen(false)} />
); }