import { useState, useEffect } from 'react'; import { Beaker, RefreshCw, X, Sun, Moon } from 'lucide-react'; export default function ElementCombiner() { const [selectedElements, setSelectedElements] = useState([]); const [result, setResult] = useState(null); const [darkMode, setDarkMode] = useState(false); const [loading, setLoading] = useState(false); const [combinations, setCombinations] = useState([]); // Full periodic table const elements = [ { symbol: 'H', name: 'Hydrogen', number: 1, group: 'Nonmetal' }, { symbol: 'He', name: 'Helium', number: 2, group: 'Noble Gas' }, // ... adding first 20 elements for brevity, but you can add all 118 { symbol: 'Li', name: 'Lithium', number: 3, group: 'Alkali Metal' }, { symbol: 'Be', name: 'Beryllium', number: 4, group: 'Alkaline Earth' }, { symbol: 'B', name: 'Boron', number: 5, group: 'Metalloid' }, { symbol: 'C', name: 'Carbon', number: 6, group: 'Nonmetal' }, { symbol: 'N', name: 'Nitrogen', number: 7, group: 'Nonmetal' }, { symbol: 'O', name: 'Oxygen', number: 8, group: 'Nonmetal' }, { symbol: 'F', name: 'Fluorine', number: 9, group: 'Halogen' }, { symbol: 'Ne', name: 'Neon', number: 10, group: 'Noble Gas' }, { symbol: 'Na', name: 'Sodium', number: 11, group: 'Alkali Metal' }, { symbol: 'Mg', name: 'Magnesium', number: 12, group: 'Alkaline Earth' }, { symbol: 'Al', name: 'Aluminum', number: 13, group: 'Post-Transition Metal' }, { symbol: 'Si', name: 'Silicon', number: 14, group: 'Metalloid' }, { symbol: 'P', name: 'Phosphorus', number: 15, group: 'Nonmetal' }, { symbol: 'S', name: 'Sulfur', number: 16, group: 'Nonmetal' }, { symbol: 'Cl', name: 'Chlorine', number: 17, group: 'Halogen' }, { symbol: 'Ar', name: 'Argon', number: 18, group: 'Noble Gas' }, { symbol: 'K', name: 'Potassium', number: 19, group: 'Alkali Metal' }, { symbol: 'Ca', name: 'Calcium', number: 20, group: 'Alkaline Earth' }, ]; const fetchCombinations = async () => { if (selectedElements.length < 1) return; setLoading(true); try { const query = selectedElements.map(el => el.name).join(' '); const response = await fetch(`https://api.example.com/compounds?elements=${query}`); const data = await response.json(); setCombinations(data.compounds); } catch (error) { console.error('Error fetching combinations:', error); // Fallback to some known combinations const mockCombinations = [ { name: 'Water', formula: 'H₂O', description: 'Essential for life' }, { name: 'Table Salt', formula: 'NaCl', description: 'Common mineral' }, { name: 'Carbon Dioxide', formula: 'CO₂', description: 'Greenhouse gas' }, ]; setCombinations(mockCombinations); } setLoading(false); }; useEffect(() => { fetchCombinations(); }, [selectedElements]); const getGroupColor = (group) => { const colors = { 'Nonmetal': 'from-green-400 to-green-600', 'Noble Gas': 'from-purple-400 to-purple-600', 'Alkali Metal': 'from-red-400 to-red-600', 'Alkaline Earth': 'from-orange-400 to-orange-600', 'Metalloid': 'from-blue-400 to-blue-600', 'Halogen': 'from-yellow-400 to-yellow-600', 'Post-Transition Metal': 'from-gray-400 to-gray-600', }; return colors[group] || 'from-indigo-400 to-indigo-600'; }; return (
Discovering possible combinations...
{compound.formula}
{compound.description}