import React, { HTMLAttributes } from 'react';
import classNames from 'classnames';
import { FaPlay, FaPause, FaStepForward, FaStepBackward, FaVolumeUp } from 'react-icons/fa';

interface NowPlayingProps extends HTMLAttributes<HTMLDivElement> {
  songName: string;
  fileName: string;
  isPlaying: boolean;
  volume: number;
  onPlayPause: () => void;
  onSkip: () => void;
  onPrevious: () => void;
  
  // Sent when the volume setting actually changes value
  onVolumeSettingChange: (volume: number) => void;

  // Sent when the volume is about to start changing
  onVolumeWillChange: (volume: number) => void;

  // Sent when the volume has changed
  onVolumeDidChange: (volume: number) => void;
}

const NowPlaying: React.FC<NowPlayingProps> = (props) => {
  return (
    <div className={classNames(props.className, 'bg-black/50 h-fit p-5')}>
      <div className="flex flex-col w-full gap-2">
        <div className="flex flex-col md:flex-row w-full h-full bg-black/50 rounded-lg p-5 items-center gap-4">
          <div className="flex-grow min-w-0 w-full md:w-auto text-white">
            <div className="text-lg font-bold truncate text-center md:text-left">{props.songName}</div>
            <div className="text-sm truncate text-center md:text-left">{props.fileName}</div>
          </div>
          <div className="flex flex-row items-center gap-4 justify-center md:justify-end">
            <div className="flex items-center gap-2 text-white">
              <FaVolumeUp size={20} />
              <input
                type="range"
                min="0"
                max="100"
                value={props.volume}
                onMouseDown={() => props.onVolumeWillChange(props.volume)}
                onMouseUp={() => props.onVolumeDidChange(props.volume)}
                onChange={(e) => props.onVolumeSettingChange(Number(e.target.value))}
                className="fancy-slider w-48 md:w-24 h-2"
              />
            </div>

            <button className="text-white hover:text-violet-300 transition-colors" onClick={props.onPrevious}>
              <FaStepBackward size={24} />
            </button>

            <button className="text-white hover:text-violet-300 transition-colors" onClick={props.onPlayPause}>
              {props.isPlaying ? <FaPause size={24} /> : <FaPlay size={24} />}
            </button>

            <button className="text-white hover:text-violet-300 transition-colors" onClick={props.onSkip}>
              <FaStepForward size={24} />
            </button>
          </div>
        </div>
      </div>
    </div>
  );
};

export default NowPlaying;
