import React from 'react'; import { ColorScheme, encodeThemeForUrl } from '../utils/colorSchemes'; import { generateYAML, generateJSON, generateXResources, generateTOML } from '../utils/exportFormats'; import Image from 'next/image'; import ColorPalette from './ColorPalette'; import { useRouter } from 'next/navigation'; interface HistoryPopupProps { likedSchemes: ColorScheme[]; dislikedSchemes: ColorScheme[]; onClose: () => void; onClearHistory: () => void; isDarkMode: boolean; outputFormat: string; } const HistoryPopup: React.FC = ({ likedSchemes, dislikedSchemes, onClose, onClearHistory, isDarkMode, outputFormat }) => { const router = useRouter(); const handleDownload = (scheme: ColorScheme) => { let content: string; let fileExtension: string; switch (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 '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 handleThemeClick = (scheme: ColorScheme) => { const encodedTheme = encodeThemeForUrl(scheme); router.push(`/share/${encodedTheme}`); }; const renderSchemeGrid = (schemes: ColorScheme[], title: string) => (

{title}

{schemes.map((scheme, index) => (
handleThemeClick(scheme)} >

{scheme.name}

))}
); return (

Color Scheme History

{renderSchemeGrid(likedSchemes, "Liked Schemes")} {renderSchemeGrid(dislikedSchemes, "Disliked Schemes")}
); }; export default HistoryPopup;