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

function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var RESET_DELAY_MS = 1500;
function CodeBlockCopy({ code, className, ...props }) {
  const [state, setState] = React.useState("idle");
  React.useEffect(() => {
    if (state === "idle") return;
    const id = window.setTimeout(() => setState("idle"), RESET_DELAY_MS);
    return () => window.clearTimeout(id);
  }, [state]);
  async function handleClick() {
    try {
      await navigator.clipboard.writeText(code);
      setState("copied");
    } catch {
      setState("error");
    }
  }
  const ariaLabel = state === "copied" ? "Copied" : state === "error" ? "Copy failed" : "Copy code";
  return /* @__PURE__ */ jsx(
    "button",
    {
      type: "button",
      onClick: handleClick,
      "aria-label": ariaLabel,
      title: ariaLabel,
      className: cn(
        "inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground",
        "transition-all duration-[var(--duration-normal,200ms)] ease-out",
        "hover:bg-foreground/10 hover:text-foreground",
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
        className
      ),
      ...props,
      children: state === "copied" ? /* @__PURE__ */ jsx(CheckGlyph, {}) : state === "error" ? /* @__PURE__ */ jsx(ErrorGlyph, {}) : /* @__PURE__ */ jsx(CopyGlyph, {})
    }
  );
}
function CopyGlyph() {
  return /* @__PURE__ */ jsxs(
    "svg",
    {
      "aria-hidden": true,
      viewBox: "0 0 16 16",
      width: "13",
      height: "13",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "1.5",
      strokeLinecap: "round",
      strokeLinejoin: "round",
      children: [
        /* @__PURE__ */ jsx("rect", { x: "5", y: "5", width: "9", height: "9", rx: "1.5" }),
        /* @__PURE__ */ jsx("path", { d: "M11 5V3.5A1.5 1.5 0 0 0 9.5 2h-6A1.5 1.5 0 0 0 2 3.5v6A1.5 1.5 0 0 0 3.5 11H5" })
      ]
    }
  );
}
function CheckGlyph() {
  return /* @__PURE__ */ jsx(
    "svg",
    {
      "aria-hidden": true,
      viewBox: "0 0 16 16",
      width: "13",
      height: "13",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "1.5",
      strokeLinecap: "round",
      strokeLinejoin: "round",
      className: "text-emerald-500",
      children: /* @__PURE__ */ jsx("path", { d: "M3 8l3.5 3.5L13 5" })
    }
  );
}
function ErrorGlyph() {
  return /* @__PURE__ */ jsxs(
    "svg",
    {
      "aria-hidden": true,
      viewBox: "0 0 16 16",
      width: "13",
      height: "13",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: "1.5",
      strokeLinecap: "round",
      strokeLinejoin: "round",
      className: "text-destructive",
      children: [
        /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6.5" }),
        /* @__PURE__ */ jsx("path", { d: "M8 5v3.5M8 11v.01" })
      ]
    }
  );
}

export { CodeBlockCopy };
//# sourceMappingURL=code-block-copy.js.map
//# sourceMappingURL=code-block-copy.js.map