"use client";
import * as React from 'react';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { jsx } from 'react/jsx-runtime';

function cn(...inputs) {
  return twMerge(clsx(inputs));
}
function AudioWaveform({
  src,
  height = 48,
  waveColor = "#a3a3a3",
  progressColor,
  onReady,
  onError,
  className,
  ...rest
}) {
  const containerRef = React.useRef(null);
  const onReadyRef = React.useRef(onReady);
  const onErrorRef = React.useRef(onError);
  onReadyRef.current = onReady;
  onErrorRef.current = onError;
  React.useEffect(() => {
    if (!containerRef.current) return;
    let disposed = false;
    let ws = null;
    const objectUrl = src instanceof Blob ? URL.createObjectURL(src) : null;
    void (async () => {
      const { default: WaveSurfer } = await import('wavesurfer.js');
      if (disposed || !containerRef.current) return;
      ws = WaveSurfer.create({
        container: containerRef.current,
        waveColor,
        progressColor: progressColor ?? waveColor,
        cursorColor: "transparent",
        height,
        barWidth: 2,
        barGap: 1,
        barRadius: 1,
        normalize: true,
        interact: false
      });
      ws.on("ready", () => {
        if (ws) onReadyRef.current?.(ws.getDuration());
      });
      ws.on("error", (err) => {
        onErrorRef.current?.(err.message);
      });
      void ws.load(objectUrl ?? src);
    })();
    return () => {
      disposed = true;
      ws?.destroy();
      if (objectUrl) URL.revokeObjectURL(objectUrl);
    };
  }, [src, height, waveColor, progressColor]);
  return /* @__PURE__ */ jsx(
    "div",
    {
      ...rest,
      ref: containerRef,
      "data-hex-audio-waveform": true,
      className: cn("w-full", className)
    }
  );
}

export { AudioWaveform };
//# sourceMappingURL=audio-waveform.js.map
//# sourceMappingURL=audio-waveform.js.map