import { CountUp } from './CountUp.jsx';
import { ArrowPathIcon, HomeIcon } from '@heroicons/react/24/outline';
import { motion, useReducedMotion } from 'framer-motion';
import { useNavigate } from 'react-router-dom';
import logo from '../assets/logolang.png';
import { Button } from './Button.jsx';

export function Header({ count, title = 'Kenteken Generator', onRestart, onHome }) {
  const navigate = useNavigate();
  const reduceMotion = useReducedMotion();
  return (
    <motion.header
      className="header"
      initial={reduceMotion ? { opacity: 1 } : { y: -20, opacity: 0 }}
      animate={{ y: 0, opacity: 1 }}
      transition={{ duration: reduceMotion ? 0 : 0.28 }}
    >
      <div className="header-inner">
        <div
          className="flex items-center gap-2 sm:gap-3 cursor-pointer min-w-0"
          onClick={() => navigate('/generate')}
        >
          <motion.img
            src={logo}
            alt="CarKiddo"
            className="header-logo"
            whileHover={reduceMotion ? undefined : { rotate: 2, y: -1 }}
            transition={{ type: 'spring', stiffness: 300, damping: 20 }}
          />
          <motion.div
            className="header-title truncate"
            initial={reduceMotion ? false : { opacity: 0 }}
            animate={{ opacity: 1 }}
            transition={{ duration: 0.3 }}
          >
            {title}
          </motion.div>
        </div>
        <div className="header-right">
          <div className="header-stat">
            <CountUp value={count} /> auto's
          </div>
          {onHome && (
            <Button
              type="button"
              variant="ghost"
              className="header-btn"
              onClick={onHome}
            >
              <HomeIcon className="w-4 h-4" />
              <span className="hidden sm:inline">Home</span>
            </Button>
          )}
          {onRestart && (
            <Button
              type="button"
              variant="ghost"
              className="header-btn"
              onClick={onRestart}
            >
              <ArrowPathIcon className="w-4 h-4" />
              <span className="hidden sm:inline">Opnieuw</span>
            </Button>
          )}
        </div>
      </div>
    </motion.header>
  );
}
