"use client";
import { jsx } from "react/jsx-runtime";
import dynamic from "next/dynamic";
import { LoadingMessage } from "../detail/LoadingMessage.js";
import { useMarkdownRemarkPlugins } from "../markdown/useMarkdownRemarkPlugins.js";
const isTestEnv = typeof process !== "undefined" && process.env.NODE_ENV === "test";
const MarkdownEditorTestStub = ({ value, onChange }) => /* @__PURE__ */ jsx(
  "textarea",
  {
    className: "min-h-[160px] w-full rounded border px-3 py-2 text-sm",
    value: value ?? "",
    onChange: (event) => onChange?.(event.target.value)
  }
);
const UiMarkdownEditor = isTestEnv ? MarkdownEditorTestStub : dynamic(() => import("@uiw/react-md-editor"), {
  ssr: false,
  loading: () => /* @__PURE__ */ jsx(
    LoadingMessage,
    {
      label: "Loading editor...",
      className: "min-h-[220px] justify-center"
    }
  )
});
function SwitchableMarkdownInput({
  value,
  onChange,
  isMarkdownEnabled,
  disableMarkdown,
  height = 220,
  placeholder,
  rows = 3,
  textareaRef,
  onTextareaInput,
  textareaClassName,
  editorWrapperClassName,
  editorClassName,
  disabled,
  remarkPlugins
}) {
  const resolvedPlugins = useMarkdownRemarkPlugins(remarkPlugins);
  const editorWrapperClasses = editorWrapperClassName ?? "w-full rounded-lg border border-muted-foreground/20 bg-background p-2";
  const editorClasses = editorClassName ?? "w-full";
  const textareaClasses = textareaClassName ?? "w-full resize-none overflow-hidden rounded-lg border border-muted-foreground/20 bg-background px-3 py-2 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary";
  if (isMarkdownEnabled && !disableMarkdown) {
    return /* @__PURE__ */ jsx("div", { className: editorWrapperClasses, children: /* @__PURE__ */ jsx("div", { "data-color-mode": "light", className: editorClasses, children: /* @__PURE__ */ jsx(
      UiMarkdownEditor,
      {
        value,
        height,
        onChange: (nextValue) => onChange(typeof nextValue === "string" ? nextValue : ""),
        previewOptions: resolvedPlugins.length ? { remarkPlugins: resolvedPlugins } : void 0
      }
    ) }) });
  }
  return /* @__PURE__ */ jsx(
    "textarea",
    {
      ref: textareaRef,
      rows,
      className: textareaClasses,
      placeholder,
      value,
      onChange: (event) => onChange(event.target.value),
      onInput: onTextareaInput,
      disabled
    }
  );
}
export {
  SwitchableMarkdownInput
};
//# sourceMappingURL=SwitchableMarkdownInput.js.map
