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

// src/primitives/tag/tag.tsx
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var tagVariants = cva(
  [
    "inline-flex items-center gap-[var(--gap-xs,0.25rem)] rounded-full border px-2.5 py-0.5 text-xs font-medium",
    "transition-all duration-[var(--duration-normal,200ms)] ease-out",
    "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
  ].join(" "),
  {
    variants: {
      variant: {
        default: "border-transparent bg-primary text-primary-foreground",
        secondary: "border-foreground/15 bg-secondary text-secondary-foreground hover:border-foreground/20",
        destructive: "border-transparent bg-destructive text-destructive-foreground",
        outline: "border-foreground/20 text-foreground hover:border-foreground/30"
      }
    },
    defaultVariants: { variant: "default" }
  }
);
function extractStringLabel(children) {
  const parts = [];
  const visit = (node) => {
    if (node === null || node === void 0 || typeof node === "boolean") return;
    if (typeof node === "string") {
      parts.push(node);
      return;
    }
    if (typeof node === "number") {
      parts.push(String(node));
      return;
    }
    if (Array.isArray(node)) {
      for (const item of node) visit(item);
      return;
    }
    if (React.isValidElement(node)) {
      const props = node.props;
      visit(props.children);
    }
  };
  visit(children);
  const joined = parts.join(" ").replace(/\s+/g, " ").trim();
  return joined.length > 0 ? joined : null;
}
function Tag({
  className,
  variant,
  icon,
  onRemove,
  removeLabel,
  children,
  ref,
  ...props
}) {
  const labelText = extractStringLabel(children);
  const ariaLabel = removeLabel ?? (labelText ? `Remove ${labelText}` : "Remove");
  return /* @__PURE__ */ jsxs("span", { ref, className: cn(tagVariants({ variant }), className), ...props, children: [
    icon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "-ml-0.5 [&_svg]:size-3 [&_svg]:shrink-0", children: icon }) : null,
    /* @__PURE__ */ jsx("span", { children }),
    onRemove ? /* @__PURE__ */ jsx(
      "button",
      {
        type: "button",
        onClick: onRemove,
        "aria-label": ariaLabel,
        className: cn(
          "-mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full",
          "transition-all duration-[var(--duration-normal,200ms)] ease-out",
          "hover:bg-foreground/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
          "active:scale-[0.98]"
        ),
        children: /* @__PURE__ */ jsxs(
          "svg",
          {
            xmlns: "http://www.w3.org/2000/svg",
            viewBox: "0 0 24 24",
            fill: "none",
            stroke: "currentColor",
            strokeWidth: "2.5",
            strokeLinecap: "round",
            strokeLinejoin: "round",
            className: "size-3",
            "aria-hidden": "true",
            children: [
              /* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
              /* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
            ]
          }
        )
      }
    ) : null
  ] });
}

export { Tag, tagVariants };
//# sourceMappingURL=tag.js.map
//# sourceMappingURL=tag.js.map