import React, { useState }  from "react";
import "./WordBundleDeepLearning.css";

const WordBundleDeepLearning = ({ contents }) => {
  const [isPlaying, setIsPlaying] = useState(false);

  const toggleAudio = () => {
    const audio = document.getElementById("song-audio");
    if (isPlaying) {
      audio.pause();
    } else {
      audio.play();
    }
    setIsPlaying(!isPlaying);
  };


  if (!contents) {
    return <div>Loading...</div>;
  }
  return (
    <>
      <img
        src={contents.image}
        alt="이미지"
        className="wordBundle-basic-learning-img"
        onClick={toggleAudio}
      />

      <div className="wordBundle-basic-learning-word">
        <h1>{contents.sentence}</h1>
        <h3>{contents.sentence_meaning}</h3>
      </div>
      <audio id="song-audio" controls style={{ display: "none" }}>
            <source src={contents.sentence_file} type="audio/mpeg" />
          </audio>

    </>
  );
};

export default WordBundleDeepLearning;
