import { jsx } from "react/jsx-runtime";
import { IconButton } from "@choiceform/design-system";
import { PromptToolbarAudioLines, PromptToolbarMic } from "@choiceform/icons-react";
import { memo } from "react";
import { t } from "../../../../i18n/index.js";
import { promptVoiceInputTv } from "./tv.js";
import { usePromptInputContext } from "../../context/prompt-input-context.js";
const PromptVoiceInput = memo(function PromptVoiceInput2(props) {
  const { className, ...rest } = props;
  const {
    isVoiceSupported,
    isVoiceListening,
    handleVoiceMouseDown,
    handleVoiceMouseUp,
    handleVoiceClick
  } = usePromptInputContext();
  const recording = t("prompt-input", "recording");
  const voiceInput = t("prompt-input", "voice-input");
  const voiceNotSupported = t("prompt-input", "voice-not-supported");
  const tv = promptVoiceInputTv({ isVoiceListening });
  return /* @__PURE__ */ jsx(
    IconButton,
    {
      ...rest,
      className: tv.button({ className }),
      onMouseDown: (e) => {
        e.preventDefault();
        if (!isVoiceSupported) return;
        handleVoiceMouseDown();
      },
      onMouseUp: (e) => {
        e.preventDefault();
        if (!isVoiceSupported) return;
        handleVoiceMouseUp();
      },
      onMouseLeave: () => {
        if (!isVoiceSupported) return;
        handleVoiceMouseUp();
      },
      onClick: (e) => {
        e.preventDefault();
        if (!isVoiceSupported) return;
        handleVoiceClick();
      },
      onTouchStart: () => {
        if (!isVoiceSupported) return;
        handleVoiceMouseDown();
      },
      onTouchEnd: () => {
        if (!isVoiceSupported) return;
        handleVoiceMouseUp();
      },
      onTouchCancel: () => {
        if (!isVoiceSupported) return;
        handleVoiceMouseUp();
      },
      disabled: !isVoiceSupported,
      tooltip: {
        content: isVoiceSupported ? isVoiceListening ? recording : voiceInput : voiceNotSupported
      },
      children: isVoiceListening ? /* @__PURE__ */ jsx(PromptToolbarAudioLines, {}) : /* @__PURE__ */ jsx(PromptToolbarMic, {})
    }
  );
});
export {
  PromptVoiceInput
};
//# sourceMappingURL=prompt-voice-input.js.map
