"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { cn } from "@open-mercato/shared/lib/utils";
function normalizeCollectionLabels(values) {
  return values.map((value) => typeof value === "string" ? value.trim() : "").filter((value) => value.length > 0);
}
function buildCollectionPreview(labels, maxVisible = 2) {
  const normalized = normalizeCollectionLabels(labels);
  if (!normalized.length) {
    return {
      visibleText: "",
      hiddenCount: 0,
      tooltipText: ""
    };
  }
  const cappedVisible = Math.max(1, Math.floor(maxVisible));
  const visible = normalized.slice(0, cappedVisible);
  const hiddenCount = Math.max(0, normalized.length - visible.length);
  return {
    visibleText: visible.join(", "),
    hiddenCount,
    tooltipText: normalized.join(", ")
  };
}
function CollectionPreviewCell({
  labels,
  maxVisible = 2,
  className
}) {
  const { visibleText, hiddenCount, tooltipText } = React.useMemo(
    () => buildCollectionPreview(labels, maxVisible),
    [labels, maxVisible]
  );
  if (!visibleText) return null;
  return /* @__PURE__ */ jsxs(
    "span",
    {
      className: cn("inline-flex max-w-full items-center gap-1 text-sm", className),
      title: tooltipText,
      children: [
        /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: visibleText }),
        hiddenCount > 0 ? /* @__PURE__ */ jsx("span", { className: "shrink-0 text-muted-foreground", children: `+${hiddenCount}` }) : null
      ]
    }
  );
}
export {
  CollectionPreviewCell,
  buildCollectionPreview,
  normalizeCollectionLabels
};
//# sourceMappingURL=CollectionPreviewCell.js.map
