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

// src/lib/utils.ts
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
function toStars(rating) {
  return Math.max(0, Math.min(5, Math.round(rating)));
}
function Stars({ rating }) {
  const filled = toStars(rating);
  return /* @__PURE__ */ jsx("span", { className: "inline-flex", "aria-hidden": "true", children: [0, 1, 2, 3, 4].map((index) => /* @__PURE__ */ jsx(
    "svg",
    {
      viewBox: "0 0 20 20",
      fill: "currentColor",
      className: cn("size-4", index < filled ? "text-primary" : "text-muted"),
      children: /* @__PURE__ */ jsx("path", { d: "M10 1.5l2.6 5.3 5.9.9-4.3 4.1 1 5.8L10 15l-5.2 2.7 1-5.8L1.5 7.7l5.9-.9L10 1.5z" })
    },
    index
  )) });
}
function CommerceReviews({
  reviews,
  averageRating,
  totalCount,
  className
}) {
  return /* @__PURE__ */ jsx("section", { className: cn("bg-background py-16 sm:py-20", className), children: /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-3xl px-6 lg:px-8", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
      /* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold tracking-tight text-foreground", children: "Customer reviews" }),
      averageRating !== void 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ jsx(Stars, { rating: averageRating }),
        /* @__PURE__ */ jsxs("span", { className: "text-sm text-muted-foreground", children: [
          averageRating.toFixed(1),
          " out of 5",
          totalCount !== void 0 ? ` \xB7 ${totalCount} reviews` : null
        ] })
      ] }) : null
    ] }),
    /* @__PURE__ */ jsx("ul", { className: "mt-10 flex flex-col divide-y divide-border", children: reviews.map((review, index) => /* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-2 py-8 first:pt-0", children: [
      /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
        /* @__PURE__ */ jsx(Stars, { rating: review.rating }),
        review.date ? /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: review.date }) : null
      ] }),
      review.title ? /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground", children: review.title }) : null,
      /* @__PURE__ */ jsx("p", { className: "text-pretty text-sm text-muted-foreground", children: review.body }),
      /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-foreground", children: review.author })
    ] }, index)) })
  ] }) });
}

export { CommerceReviews };
//# sourceMappingURL=commerce-reviews.js.map
//# sourceMappingURL=commerce-reviews.js.map