import * as i from "react";
import { LocalAudioTrack as m } from "@cc-livekit/livekit-client";
import { D as E } from "./hooks-2Nak3q2j.mjs";
function b(n = {}) {
  const [o, f] = i.useState(!1), [u, a] = i.useState(!1), [p, l] = i.useState(!1);
  let e = E().microphoneTrack;
  const [t, d] = i.useState();
  n.trackRef && (e = n.trackRef.publication);
  const k = i.useCallback(async (r) => {
    if (r) {
      const { KrispNoiseFilter: s, isKrispNoiseFilterSupported: c } = await import("@livekit/krisp-noise-filter");
      if (!c()) {
        console.warn("Krisp noise filter is not supported in this browser");
        return;
      }
      t || d(s(n.filterOptions));
    }
    f((s) => (s !== r && a(!0), r));
  }, []);
  return i.useEffect(() => {
    var r;
    if (e && e.track instanceof m && t) {
      const s = e.track.getProcessor();
      s && s.name === "livekit-noise-filter" ? (a(!0), s.setEnabled(o).finally(() => {
        a(!1), l(o);
      })) : !s && o && (a(!0), (r = e == null ? void 0 : e.track) == null || r.setProcessor(t).then(() => t.setEnabled(o)).then(() => {
        l(!0);
      }).catch((c) => {
        l(!1), console.error(c);
      }).finally(() => {
        a(!1);
      }));
    }
  }, [o, e, t]), {
    setNoiseFilterEnabled: k,
    isNoiseFilterEnabled: p,
    isNoiseFilterPending: u,
    processor: t
  };
}
export {
  b as useKrispNoiseFilter
};
//# sourceMappingURL=krisp.mjs.map
