import React, { useState } from 'react';
import { Canvas } from '@react-three/fiber';
import { OrbitControls, PerspectiveCamera } from '@react-three/drei';
import './App.css';

const variants = {
  black: {
    geometry: <boxGeometry args={[2, 2, 2]} />,
    material: { color: "black", roughness: 1, metalness: 0 }
  },
  silver: {
    geometry: <sphereGeometry args={[1.5, 32, 32]} />,
    material: { color: "#C0C0C0", roughness: 0.3, metalness: 1 }
  },
  gold: {
    geometry: <torusGeometry args={[1.2, 0.4, 16, 100]} />,
    material: { color: "#FFD700", roughness: 0.4, metalness: 1 }
  }
};

function Product({ variant }) {
  const { geometry, material } = variants[variant];
  
  return (
    <mesh>
      {geometry}
      <meshStandardMaterial {...material} />
    </mesh>
  );
}

export default function App() {
  const [activeVariant, setActiveVariant] = useState('black');

  return (
    <div className="app-container">
      <div id="controls">
        {Object.keys(variants).map((variant) => (
          <button
            key={variant}
            className={activeVariant === variant ? 'active' : ''}
            onClick={() => setActiveVariant(variant)}
          >
            {variant.charAt(0).toUpperCase() + variant.slice(1)}
          </button>
        ))}
      </div>

      <div className="canvas-wrapper">
        <Canvas dpr={[1, 2]}>
          <color attach="background" args={["white"]} />
          <PerspectiveCamera makeDefault position={[0, 0, 5]} />
          
          <ambientLight intensity={0.6 * Math.PI} />
          <pointLight position={[5, 5, 5]} intensity={1.0 * Math.PI} />

          <Product variant={activeVariant} />

          <OrbitControls makeDefault enableDamping dampingFactor={0.05} />
        </Canvas>
      </div>
    </div>
  );
}