import React, { useState } from 'react'; import Image from 'next/image'; import { ColorScheme, encodeThemeForUrl } from '../utils/colorSchemes'; import { generateYAML, generateJSON, generateXResources, generateTOML, generateITerm2, generateWindowsTerminal, generateTerminalApp } from '../utils/exportFormats'; import { motion, useAnimation } from 'framer-motion'; import ColorPalette from './ColorPalette'; import confetti from 'canvas-confetti'; import { AppSettings } from '../utils/types'; import CodePreview from './CodePreview'; interface ColorSchemeCardProps { scheme: ColorScheme; onLike: () => void; onDislike: () => void; index: number; isDarkMode: boolean; settings: AppSettings; } const ColorSchemeCard: React.FC = ({ scheme, onLike, onDislike, index, isDarkMode, settings }) => { const [overlayColor, setOverlayColor] = useState('rgba(0, 0, 0, 0)'); const controls = useAnimation(); const handleDownload = (e: React.MouseEvent) => { e.stopPropagation(); let content: string; let fileExtension: string; switch (settings.outputFormat) { case 'json': content = generateJSON(scheme); fileExtension = 'json'; break; case 'xresources': content = generateXResources(scheme); fileExtension = 'Xresources'; break; case 'toml': content = generateTOML(scheme); fileExtension = 'toml'; break; case 'iterm2': content = generateITerm2(scheme); fileExtension = 'itermcolors'; break; case 'windows-terminal': content = generateWindowsTerminal(scheme); fileExtension = 'json'; break; case 'terminal-app': content = generateTerminalApp(scheme); fileExtension = 'terminal'; break; case 'yaml': default: content = generateYAML(scheme); fileExtension = 'yaml'; } const blob = new Blob([content], { type: 'text/plain' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${scheme.name.replace(/\s+/g, '_').toLowerCase()}.${fileExtension}`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; const handleLike = () => { setOverlayColor('rgba(0, 255, 0, 0.1)'); controls.start({ x: 300, opacity: 0, transition: { duration: 0.3 } }).then(() => { if (settings.partyMode) { confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } }); } onLike(); }); }; const handleDislike = () => { setOverlayColor('rgba(255, 0, 0, 0.1)'); controls.start({ x: -300, opacity: 0, transition: { duration: 0.3 } }).then(onDislike); }; const handleShare = (e: React.MouseEvent) => { e.stopPropagation(); const encodedTheme = encodeThemeForUrl(scheme); window.open(`/share/${encodedTheme}`, '_blank'); }; const paletteColors = [ scheme.colors.normal.black, scheme.colors.normal.red, scheme.colors.normal.green, scheme.colors.normal.yellow, scheme.colors.normal.blue, scheme.colors.normal.magenta, scheme.colors.normal.cyan, scheme.colors.normal.white, scheme.colors.bright.black, scheme.colors.bright.red, scheme.colors.bright.green, scheme.colors.bright.yellow, scheme.colors.bright.blue, scheme.colors.bright.magenta, scheme.colors.bright.cyan, scheme.colors.bright.white, ]; return ( { if (offset.x > 50) handleLike(); else if (offset.x < -50) handleDislike(); }} >

{scheme.name}

); }; export default ColorSchemeCard;