import { jsx as t, jsxs as w } from "react/jsx-runtime";
import { Fragment as N } from "react";
import { Loader as S } from "../atoms/loader.js";
import { Skeleton as u } from "../atoms/skeleton.js";
import { Message as f, MessageContent as p } from "./message.js";
import { cn as o } from "../../../lib/utils.js";
function b({
  messages: a,
  isStreaming: l = !1,
  renderMessage: e,
  loadingIndicator: n,
  children: c,
  className: s,
  ...m
}) {
  const h = o(
    "mx-auto flex w-full max-w-3xl flex-col gap-8 px-6",
    s
  );
  if (c)
    return /* @__PURE__ */ t(
      "div",
      {
        "aria-live": "polite",
        className: h,
        "data-slot": "chat-message-list",
        role: "log",
        ...m,
        children: c
      }
    );
  if (!a)
    return null;
  const i = a.at(-1), g = l && (!i || i.role !== "assistant" || !i.content);
  return /* @__PURE__ */ w(
    "div",
    {
      "aria-live": "polite",
      className: h,
      "data-slot": "chat-message-list",
      role: "log",
      ...m,
      children: [
        a.map((r) => {
          const x = r.role === "user", d = r === i;
          return e ? /* @__PURE__ */ t(N, { children: e(r, {
            isLast: d,
            isStreaming: d && l
          }) }, r.id) : x || r.content ? x ? /* @__PURE__ */ t(v, { children: r.content }, r.id) : /* @__PURE__ */ t(
            y,
            {
              isAnimating: d && l,
              children: r.content
            },
            r.id
          ) : null;
        }),
        g && /* @__PURE__ */ t(C, { children: n })
      ]
    }
  );
}
function v({
  children: a,
  className: l,
  ...e
}) {
  return /* @__PURE__ */ t(
    f,
    {
      className: o("ml-auto max-w-2xl", l),
      "data-slot": "chat-user-message",
      ...e,
      children: /* @__PURE__ */ t(p, { className: "rounded-xl bg-primary px-4 py-2 text-primary-foreground", children: a })
    }
  );
}
function y({
  children: a,
  isAnimating: l,
  className: e,
  ...n
}) {
  return /* @__PURE__ */ t(
    f,
    {
      className: e,
      "data-slot": "chat-assistant-message",
      ...n,
      children: typeof a == "string" ? /* @__PURE__ */ t(
        p,
        {
          className: "prose-sm bg-transparent p-0 [&_h1]:text-2xl [&_h2]:text-xl [&_h3]:text-lg",
          isAnimating: l,
          markdown: !0,
          children: a
        }
      ) : a
    }
  );
}
function C({
  children: a,
  className: l,
  ...e
}) {
  return /* @__PURE__ */ t(
    "div",
    {
      className: o("flex items-center gap-2 px-1", l),
      "data-slot": "chat-streaming-indicator",
      ...e,
      children: a ?? /* @__PURE__ */ t(S, { variant: "typing" })
    }
  );
}
const M = [
  { role: "user", lines: 1, width: "60%" },
  { role: "assistant", lines: 3, width: "85%" },
  { role: "user", lines: 1, width: "45%" },
  { role: "assistant", lines: 2, width: "75%" }
];
function U({
  className: a,
  ...l
}) {
  return /* @__PURE__ */ t(
    "div",
    {
      className: o(
        "mx-auto flex w-full max-w-3xl flex-col gap-8 px-6",
        a
      ),
      ...l,
      children: M.map(
        (e, n) => e.role === "user" ? /* @__PURE__ */ t(
          "div",
          {
            className: "ml-auto flex max-w-2xl items-start gap-3",
            children: /* @__PURE__ */ t(
              u,
              {
                className: "h-10 rounded-xl",
                style: { width: e.width }
              }
            )
          },
          `msg-skeleton-${n.toString()}`
        ) : /* @__PURE__ */ t(
          "div",
          {
            className: "flex flex-col gap-2",
            style: { maxWidth: e.width },
            children: Array.from({ length: e.lines }).map((c, s) => /* @__PURE__ */ t(
              u,
              {
                className: "h-4 rounded",
                style: {
                  width: s === e.lines - 1 ? "65%" : "100%"
                }
              },
              `line-${n.toString()}-${s.toString()}`
            ))
          },
          `msg-skeleton-${n.toString()}`
        )
      )
    }
  );
}
export {
  y as ChatAssistantMessage,
  b as ChatMessageList,
  U as ChatMessageListSkeleton,
  C as ChatStreamingIndicator,
  v as ChatUserMessage
};
