import { jsxs as f, jsx as i, Fragment as g } from "react/jsx-runtime";
import { Button as a } from "../ui/button.es.js";
import { cn as n } from "../../utils/tailwindUtil.es.js";
import { useStreamContext as k } from "../../providers/Stream.es.js";
import { Check as N, Copy as R, RefreshCw as S, ThumbsUp as T, ThumbsDown as b } from "lucide-react";
import { useState as x } from "react";
import { toast as s } from "sonner";
function U({
  message: t,
  onRegenerate: c,
  feedback: r,
  onFeedback: o,
  className: u
}) {
  const [y, l] = x(!1), [h, p] = x(!1), d = k().getMessagesMetadata(t)?.firstSeenState?.parent_checkpoint, v = async () => {
    try {
      let e = "";
      typeof t.content == "string" ? e = t.content : Array.isArray(t.content) && (e = t.content.map((m) => m.type === "text" ? m.text : "").filter(Boolean).join(`
`)), await navigator.clipboard.writeText(e), l(!0), s.success("Copied to clipboard"), setTimeout(() => l(!1), 2e3);
    } catch (e) {
      s.error("Failed to copy"), console.error("Copy failed:", e);
    }
  }, w = async () => {
    if (!(!c || !d || !t.id))
      try {
        p(!0), await c(d, t.id, t);
      } catch (e) {
        s.error("Failed to regenerate"), console.error("Regenerate failed:", e);
      } finally {
        p(!1);
      }
  }, z = () => {
    if (!o || !t.id) return;
    const e = r === "like" ? null : "like";
    o(t.id, e);
  }, C = () => {
    if (!o || !t.id) return;
    const e = r === "dislike" ? null : "dislike";
    o(t.id, e);
  };
  return /* @__PURE__ */ f(
    "div",
    {
      className: n(
        "flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",
        u
      ),
      children: [
        /* @__PURE__ */ i(
          a,
          {
            variant: "ghost",
            size: "icon",
            onClick: v,
            className: "h-7 w-7 text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800",
            title: "Copy message",
            children: y ? /* @__PURE__ */ i(N, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ i(R, { className: "h-3.5 w-3.5" })
          }
        ),
        c && /* @__PURE__ */ i(
          a,
          {
            variant: "ghost",
            size: "icon",
            onClick: w,
            disabled: h,
            className: "h-7 w-7 text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 disabled:opacity-50",
            title: "Regenerate response",
            children: /* @__PURE__ */ i(
              S,
              {
                className: n("h-3.5 w-3.5", h && "animate-spin")
              }
            )
          }
        ),
        o && /* @__PURE__ */ f(g, { children: [
          /* @__PURE__ */ i(
            a,
            {
              variant: "ghost",
              size: "icon",
              onClick: z,
              className: n(
                "h-7 w-7 hover:bg-zinc-800",
                r === "like" ? "text-green-500 hover:text-green-400" : "text-zinc-500 hover:text-zinc-300"
              ),
              title: "Good response",
              children: /* @__PURE__ */ i(
                T,
                {
                  className: n(
                    "h-3.5 w-3.5",
                    r === "like" && "fill-current"
                  )
                }
              )
            }
          ),
          /* @__PURE__ */ i(
            a,
            {
              variant: "ghost",
              size: "icon",
              onClick: C,
              className: n(
                "h-7 w-7 hover:bg-zinc-800",
                r === "dislike" ? "text-red-500 hover:text-red-400" : "text-zinc-500 hover:text-zinc-300"
              ),
              title: "Bad response",
              children: /* @__PURE__ */ i(
                b,
                {
                  className: n(
                    "h-3.5 w-3.5",
                    r === "dislike" && "fill-current"
                  )
                }
              )
            }
          )
        ] })
      ]
    }
  );
}
export {
  U as MessageActions
};
//# sourceMappingURL=MessageActions.es.js.map
