"use client";
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { jsxs, jsx } from 'react/jsx-runtime';

function cn(...inputs) {
  return twMerge(clsx(inputs));
}
function Branch({
  current,
  total,
  onCurrentChange,
  children,
  "aria-label": ariaLabel = "Response branches",
  className
}) {
  if (total <= 0) return null;
  const interactive = typeof onCurrentChange === "function";
  const atFirst = current <= 0;
  const atLast = current >= total - 1;
  function go(delta) {
    if (!interactive) return;
    const next = current + delta;
    if (next < 0 || next > total - 1) return;
    onCurrentChange(next);
  }
  function handleKeyDown(event) {
    if (!interactive) return;
    if (event.key === "ArrowLeft") {
      event.preventDefault();
      go(-1);
    } else if (event.key === "ArrowRight") {
      event.preventDefault();
      go(1);
    }
  }
  return /* @__PURE__ */ jsxs(
    "div",
    {
      role: "group",
      "aria-label": ariaLabel,
      onKeyDown: handleKeyDown,
      className: cn("flex flex-col gap-2", className),
      children: [
        /* @__PURE__ */ jsx("div", { children }),
        /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-1", children: [
          /* @__PURE__ */ jsx(
            "button",
            {
              type: "button",
              "aria-label": "Previous response",
              disabled: !interactive || atFirst,
              onClick: () => go(-1),
              className: cn(
                "inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground",
                "transition-all duration-[var(--duration-normal,200ms)] ease-out",
                "hover:bg-muted hover:text-foreground",
                "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
                "disabled:pointer-events-none disabled:opacity-50"
              ),
              children: /* @__PURE__ */ jsx(ChevronLeft, {})
            }
          ),
          /* @__PURE__ */ jsxs(
            "span",
            {
              "aria-live": interactive ? "polite" : void 0,
              "aria-atomic": interactive ? "true" : void 0,
              className: "select-none px-1 text-xs tabular-nums text-muted-foreground",
              children: [
                current + 1,
                " of ",
                total
              ]
            }
          ),
          /* @__PURE__ */ jsx(
            "button",
            {
              type: "button",
              "aria-label": "Next response",
              disabled: !interactive || atLast,
              onClick: () => go(1),
              className: cn(
                "inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground",
                "transition-all duration-[var(--duration-normal,200ms)] ease-out",
                "hover:bg-muted hover:text-foreground",
                "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
                "disabled:pointer-events-none disabled:opacity-50"
              ),
              children: /* @__PURE__ */ jsx(ChevronRight, {})
            }
          )
        ] })
      ]
    }
  );
}
function ChevronLeft() {
  return /* @__PURE__ */ jsx(
    "svg",
    {
      "aria-hidden": true,
      viewBox: "0 0 16 16",
      width: "14",
      height: "14",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "1.75",
      strokeLinecap: "round",
      strokeLinejoin: "round",
      children: /* @__PURE__ */ jsx("path", { d: "M10 4l-4 4 4 4" })
    }
  );
}
function ChevronRight() {
  return /* @__PURE__ */ jsx(
    "svg",
    {
      "aria-hidden": true,
      viewBox: "0 0 16 16",
      width: "14",
      height: "14",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "1.75",
      strokeLinecap: "round",
      strokeLinejoin: "round",
      children: /* @__PURE__ */ jsx("path", { d: "M6 4l4 4-4 4" })
    }
  );
}

export { Branch };
//# sourceMappingURL=branch.js.map
//# sourceMappingURL=branch.js.map