import styles from "./MessageAudio.module.scss";

interface MessageAudioProps {
  src: string;
  duration?: number;
}

export default function MessageAudio({ src, duration }: MessageAudioProps) {
  return (
    <div className={styles.audio}>
      <audio controls src={src} />
      {duration && (
        <span className={styles.duration}>{formatDuration(duration)}</span>
      )}
    </div>
  );
}
function formatDuration(sec?: number) {
  if (!sec) return null;
  const m = Math.floor(sec / 60);
  const s = sec % 60;
  return `${m}:${s.toString().padStart(2, "0")}`;
}
