import { IonButton } from '@ionic/react';
import { FunctionComponent, useEffect } from 'react';
import { useGlobalAudioPlayer } from 'react-use-audio-player';
import { useMyIonMetric } from '../../../contexts/MyIonMetric';
import { useListeningPracticeTimeSpent } from '../../../contexts/MyIonMetric/ListeningPracticeTimeSpent';
// import { useMyIonMetric } from '../../contexts/MyIonMetric';

export const AudioControls: FunctionComponent<{ audio_src: string }> = ({ audio_src }) => {
  const { play, pause, playing, duration } = useGlobalAudioPlayer();
  const { load, src: loadedSrc } = useGlobalAudioPlayer();
  let { myIonMetricIncListeningPracticeTimeSpent } = useListeningPracticeTimeSpent();

  useEffect(() => {
    if (audio_src) {
      load(audio_src);
    }
  }, [audio_src]);

  useEffect(() => {
    if (loadedSrc) {
    }
  }, [loadedSrc]);

  useEffect(() => {
    if (playing) {
      myIonMetricIncListeningPracticeTimeSpent(duration);
    }
  }, [playing]);

  return <></>;
};
