import { useState, useEffect } from 'react';

const useTimerLiveStream = isStreaming => {
  const [elapsedSeconds, setElapsedSeconds] = useState(0);

  useEffect(() => {
    let recordingInterval = null;

    if (isStreaming) {
      recordingInterval = setInterval(() => {
        setElapsedSeconds(prevSeconds => prevSeconds + 1);
      }, 1000);
    } else clearInterval(recordingInterval);

    return () => clearInterval(recordingInterval);
  }, [isStreaming]);

  const recordingHours = Math.floor(elapsedSeconds / 3600);
  const recordingMinutes = Math.floor((elapsedSeconds % 3600) / 60);
  const recordingSeconds = elapsedSeconds % 60;

  return { recordingHours, recordingMinutes, recordingSeconds };
};

export default useTimerLiveStream;
