import React from 'react';

interface XPBarProps {
  currentXP: number;
  nextLevelXP: number;
  level: number;
  size?: 'sm' | 'md' | 'lg';
  showLabels?: boolean;
  className?: string;
}

export const XPBar: React.FC<XPBarProps> = ({
  currentXP,
  nextLevelXP,
  level,
  size = 'md',
  showLabels = true,
  className = '',
}) => {
  const percentage = Math.min(
    100,
    Math.max(0, (currentXP / nextLevelXP) * 100),
  );

  const heightClasses = {
    sm: 'h-2',
    md: 'h-4',
    lg: 'h-6',
  };

  const textClasses = {
    sm: 'text-[10px]',
    md: 'text-xs',
    lg: 'text-sm',
  };

  return (
    <div className={`w-full ${className}`}>
      {showLabels && (
        <div
          className={`flex justify-between items-end mb-1 font-mono font-bold ${textClasses[size]}`}
        >
          <span className="text-kodo-gold">LVL {level}</span>
          <span className="text-gray-400">
            <span className="text-white">{currentXP}</span> / {nextLevelXP} XP
          </span>
        </div>
      )}

      <div
        className={`w-full bg-kodo-void rounded-full overflow-hidden border border-kodo-gold/30 ${heightClasses[size]} relative`}
      >
        {/* Background Pattern */}
        <div className="absolute inset-0 bg-[url('https://www.transparenttextures.com/patterns/carbon-fibre.png')] opacity-20"></div>

        {/* Progress Fill */}
        <div
          className="h-full bg-gradient-to-r from-kodo-gold/80 to-kodo-gold transition-all duration-500 shadow-[0_0_15px_rgba(234,179,8,0.4)] relative"
          style={{ width: `${percentage}%` }}
        >
          {/* Shimmer Effect */}
          <div className="absolute top-0 left-0 w-full h-full bg-gradient-to-r from-transparent via-white/20 to-transparent -skew-x-12 translate-x-[-100%] animate-shimmer"></div>
        </div>
      </div>

      {showLabels && size === 'lg' && (
        <div className="text-right text-[10px] text-gray-500 mt-1 font-mono">
          {Math.round(nextLevelXP - currentXP)} XP to next level
        </div>
      )}
    </div>
  );
};
