"use client";
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { jsxs, jsx } from 'react/jsx-runtime';

function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var STATE_LABEL = {
  pending: "Pending",
  running: "Running",
  result: "Done",
  error: "Error"
};
var STATE_CLASSES = {
  pending: "bg-muted text-muted-foreground",
  // `text-foreground` (12:1) survives axe's mid-pulse capture; the
  // previous `text-primary` (`#7081a8` on dark `--muted`, 4.28:1) was
  // intermittently flagged below AA 4.5:1 at the 10px badge size when
  // `animate-pulse` caught the scan during a low-opacity frame.
  running: "bg-muted text-foreground font-medium animate-pulse",
  result: "bg-accent/30 text-accent-foreground",
  error: "bg-destructive/15 text-destructive"
};
function ToolCall({
  name,
  state,
  args,
  result,
  defaultOpen = false,
  className
}) {
  return /* @__PURE__ */ jsxs(
    CollapsiblePrimitive.Root,
    {
      defaultOpen,
      className: cn(
        "overflow-hidden rounded-md border bg-card text-card-foreground",
        "transition-all duration-[var(--duration-normal,200ms)] ease-out",
        "data-[state=open]:shadow-sm",
        className
      ),
      children: [
        /* @__PURE__ */ jsxs(
          CollapsiblePrimitive.Trigger,
          {
            className: cn(
              "group flex w-full items-center justify-between gap-3 px-3 py-2 text-left text-sm",
              "hover:bg-muted/40",
              "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
            ),
            children: [
              /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
                /* @__PURE__ */ jsx(ToolGlyph, {}),
                /* @__PURE__ */ jsx("span", { className: "truncate font-mono text-xs text-foreground", children: name }),
                /* @__PURE__ */ jsx(
                  "span",
                  {
                    className: cn(
                      "inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium",
                      STATE_CLASSES[state]
                    ),
                    children: STATE_LABEL[state]
                  }
                )
              ] }),
              /* @__PURE__ */ jsx(Chevron, {})
            ]
          }
        ),
        /* @__PURE__ */ jsxs(CollapsiblePrimitive.Content, { className: "overflow-hidden border-t bg-muted/20 px-3 py-2 text-xs", children: [
          args !== void 0 ? /* @__PURE__ */ jsx(CodeSection, { label: "Arguments", value: args }) : null,
          result !== void 0 ? /* @__PURE__ */ jsx(CodeSection, { label: "Result", value: result }) : null,
          args === void 0 && result === void 0 ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "No arguments or result yet." }) : null
        ] })
      ]
    }
  );
}
function CodeSection({ label, value }) {
  const text = typeof value === "string" ? value : safeStringify(value);
  return /* @__PURE__ */ jsxs("div", { className: "space-y-1 py-1", children: [
    /* @__PURE__ */ jsx("div", { className: "text-[10px] uppercase tracking-wide text-muted-foreground", children: label }),
    /* @__PURE__ */ jsx("pre", { className: "overflow-x-auto rounded bg-background/60 p-2 font-mono text-[11px] leading-snug", children: text })
  ] });
}
function safeStringify(value) {
  try {
    return JSON.stringify(value, null, 2);
  } catch {
    return String(value);
  }
}
function ToolGlyph() {
  return /* @__PURE__ */ jsxs(
    "svg",
    {
      "aria-hidden": true,
      viewBox: "0 0 16 16",
      width: "14",
      height: "14",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "1.5",
      strokeLinecap: "round",
      strokeLinejoin: "round",
      className: "shrink-0 text-muted-foreground",
      children: [
        /* @__PURE__ */ jsx("path", { d: "M11.5 1.5l3 3-2.5 2.5-3-3 2.5-2.5z" }),
        /* @__PURE__ */ jsx("path", { d: "M9 4l-7 7v3h3l7-7" })
      ]
    }
  );
}
function Chevron() {
  return /* @__PURE__ */ jsx(
    "svg",
    {
      "aria-hidden": true,
      viewBox: "0 0 16 16",
      width: "14",
      height: "14",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "1.5",
      strokeLinecap: "round",
      strokeLinejoin: "round",
      className: "shrink-0 text-muted-foreground transition-transform duration-200 group-data-[state=open]:rotate-180",
      children: /* @__PURE__ */ jsx("path", { d: "M4 6l4 4 4-4" })
    }
  );
}

export { ToolCall };
//# sourceMappingURL=tool-call.js.map
//# sourceMappingURL=tool-call.js.map