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

// lib/utils.ts
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var svgCache = /* @__PURE__ */ new Map();
function DynamicIcon({
  name,
  size = 28,
  color,
  className,
  alt
}) {
  const [svgContent, setSvgContent] = React.useState(null);
  const [isLoading, setIsLoading] = React.useState(true);
  const [error, setError] = React.useState(null);
  const { url, iconName } = React.useMemo(() => {
    const separator = name.includes("/") ? "/" : ":";
    const [prefix, iconName2] = name.split(separator);
    const baseUrl = `https://icons.opensite.ai/api/icon/${prefix}/${iconName2}?format=svg&width=${size}&height=${size}`;
    return {
      url: baseUrl,
      iconName: iconName2
    };
  }, [name, size]);
  React.useEffect(() => {
    let isMounted = true;
    const fetchSvg = async () => {
      const cached = svgCache.get(url);
      if (cached) {
        if (isMounted) {
          setSvgContent(cached);
          setIsLoading(false);
        }
        return;
      }
      try {
        setIsLoading(true);
        setError(null);
        const response = await fetch(url);
        if (!response.ok) {
          throw new Error(`Failed to fetch icon: ${response.status}`);
        }
        let svg = await response.text();
        svg = processSvgForCurrentColor(svg);
        svgCache.set(url, svg);
        if (isMounted) {
          setSvgContent(svg);
          setIsLoading(false);
        }
      } catch (err) {
        if (isMounted) {
          setError(err instanceof Error ? err.message : "Failed to load icon");
          setIsLoading(false);
        }
      }
    };
    fetchSvg();
    return () => {
      isMounted = false;
    };
  }, [url]);
  if (isLoading) {
    return /* @__PURE__ */ jsx(
      "span",
      {
        className: cn("inline-block", className),
        style: { width: size, height: size },
        "aria-hidden": "true"
      }
    );
  }
  if (error || !svgContent) {
    return /* @__PURE__ */ jsx(
      "span",
      {
        className: cn("inline-block", className),
        style: { width: size, height: size },
        role: "img",
        "aria-label": alt || iconName
      }
    );
  }
  return /* @__PURE__ */ jsx(
    "span",
    {
      className: cn("inline-flex items-center justify-center", className),
      style: {
        width: size,
        height: size,
        color: color || "inherit"
      },
      role: "img",
      "aria-label": alt || iconName,
      dangerouslySetInnerHTML: { __html: svgContent }
    }
  );
}
function processSvgForCurrentColor(svg) {
  let processed = svg;
  processed = processed.replace(
    /stroke=["'](#000000|#000|black)["']/gi,
    'stroke="currentColor"'
  );
  processed = processed.replace(
    /fill=["'](#000000|#000|black)["']/gi,
    'fill="currentColor"'
  );
  return processed;
}
var defaultStats = [
  {
    label: "Active Users",
    value: "120K+",
    growth: "18% growth",
    isPositive: true,
    icon: "lucide/users"
  },
  {
    label: "Avg. Session",
    value: "4:30",
    growth: "+2 min",
    isPositive: true,
    icon: "lucide/clock"
  },
  {
    label: "Revenue",
    value: "$3.2M",
    growth: "32% increase",
    isPositive: true,
    icon: "lucide/dollar-sign"
  },
  {
    label: "Conversion",
    value: "9.5%",
    growth: "2.1% higher",
    isPositive: true,
    icon: "lucide/target"
  }
];
function StatsIconCards({
  className,
  heading = "Our Growth in Numbers",
  description = "Key metrics that showcase our impact in the market",
  stats = defaultStats
}) {
  return /* @__PURE__ */ jsx(
    "div",
    {
      className: cn(
        "container mx-auto px-4 py-24 md:px-6 lg:py-32 2xl:max-w-[1400px]",
        className
      ),
      children: /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-5xl", children: [
        /* @__PURE__ */ jsxs("div", { className: "mb-10 text-center", children: [
          /* @__PURE__ */ jsx("h2", { className: "text-3xl font-bold md:text-4xl", children: heading }),
          /* @__PURE__ */ jsx("p", { className: "mt-3 text-muted-foreground", children: description })
        ] }),
        /* @__PURE__ */ jsx("div", { className: "grid gap-8 sm:grid-cols-2 lg:grid-cols-4", children: stats.map((stat, index) => /* @__PURE__ */ jsx(
          "div",
          {
            className: "relative overflow-hidden rounded-xl border bg-background p-6",
            children: /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
              /* @__PURE__ */ jsxs("div", { children: [
                /* @__PURE__ */ jsx("p", { className: "font-medium text-muted-foreground", children: stat.label }),
                /* @__PURE__ */ jsx("h3", { className: "mt-4 text-4xl font-bold", children: stat.value }),
                /* @__PURE__ */ jsxs(
                  "p",
                  {
                    className: cn(
                      "mt-1 flex items-center text-sm font-medium",
                      stat.isPositive !== false ? "text-emerald-500" : "text-rose-500"
                    ),
                    children: [
                      /* @__PURE__ */ jsx(
                        DynamicIcon,
                        {
                          name: stat.isPositive !== false ? "lucide/arrow-up-right" : "lucide/arrow-down-right",
                          size: 16,
                          className: "mr-1"
                        }
                      ),
                      /* @__PURE__ */ jsx("span", { children: stat.growth })
                    ]
                  }
                )
              ] }),
              /* @__PURE__ */ jsx("div", { className: "flex h-12 w-12 items-center justify-center rounded-full bg-primary/10", children: /* @__PURE__ */ jsx(
                DynamicIcon,
                {
                  name: stat.icon,
                  size: 24,
                  className: "text-primary"
                }
              ) })
            ] })
          },
          index
        )) })
      ] })
    }
  );
}

export { StatsIconCards };
//# sourceMappingURL=stats-icon-cards.js.map
//# sourceMappingURL=stats-icon-cards.js.map