"use client";
const s = (function() {
  const e = async function(n) {
    try {
      const r = new MediaRecorder(n, {
        mimeType: "audio/webm;codecs=opus"
      }), c = [];
      return new Promise((d, a) => {
        r.ondataavailable = (t) => {
          t.data.size > 0 && c.push(t.data);
        }, r.onstop = () => {
          const t = new Blob(c, { type: "audio/webm" });
          d(t);
        }, r.onerror = () => {
          a(new Error("MediaRecorder error occurred"));
        }, r.start(1e3), e.currentRecorder = r;
      });
    } catch (r) {
      const c = r instanceof Error ? r.message : "Unknown error occurred";
      throw new Error("Failed to start recording: " + c);
    }
  };
  return e.stop = () => {
    const o = e.currentRecorder;
    o && o.state !== "inactive" && o.stop(), delete e.currentRecorder;
  }, e;
})();
export {
  s as recordAudio
};
