"use client";

import { createContext, ReactNode, useContext } from "react";

import { useAudio } from "@/hooks/audio/useAudio";

type AudioContextValue = ReturnType<typeof useAudio>;

const AudioContext = createContext<AudioContextValue | null>(null);

export function useAudioContext() {
  const ctx = useContext(AudioContext);
  if (!ctx) {
    throw new Error("useAudio must be used within <AudioProvider>");
  }
  return ctx;
}

interface AudioProviderProps {
  children: ReactNode;
}

export function AudioProvider({ children }: AudioProviderProps) {
  const value = useAudio();

  return (
    <AudioContext.Provider value={value}>{children}</AudioContext.Provider>
  );
}
