"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 defaultFeatures = [
  {
    iconName: "lucide/timer",
    title: "Performance",
    description: "Lorem ipsum dolor sit amet, consectetur adipis elit. Sunt beatae tenetur."
  },
  {
    iconName: "lucide/zap",
    title: "Innovation",
    description: "Lorem ipsum dolor sit amet, consectetur adipis elit. Sunt beatae tenetur."
  },
  {
    iconName: "lucide/zoom-in",
    title: "Quality",
    description: "Lorem ipsum dolor sit amet, consectetur adipis elit. Sunt beatae tenetur."
  },
  {
    iconName: "lucide/person-standing",
    title: "Accessibility",
    description: "Lorem ipsum dolor sit amet, consectetur adipis elit. Sunt beatae tenetur."
  }
];
function FeatureIconGridBordered({
  label = "Why Us?",
  title = "A better way to build websites",
  features = defaultFeatures,
  featuresSlot,
  className,
  containerClassName,
  labelClassName,
  titleClassName,
  gridClassName,
  cardClassName
}) {
  const renderFeatures = () => {
    if (featuresSlot) return featuresSlot;
    if (!features || features.length === 0) return null;
    return features.map((feature, index) => {
      const renderIcon = () => {
        if (feature.icon) return feature.icon;
        if (feature.iconName) {
          return /* @__PURE__ */ jsx(DynamicIcon, { name: feature.iconName, size: 20, className: "md:size-6" });
        }
        return /* @__PURE__ */ jsx(DynamicIcon, { name: "lucide/star", size: 20, className: "md:size-6" });
      };
      return /* @__PURE__ */ jsxs(
        "div",
        {
          className: cn("relative flex gap-3 rounded-lg border-dashed md:block md:border-l md:p-5", cardClassName, feature.className),
          children: [
            /* @__PURE__ */ jsx("span", { className: cn("mb-8 flex size-10 shrink-0 items-center justify-center rounded-full bg-accent md:size-12", feature.iconClassName), children: renderIcon() }),
            /* @__PURE__ */ jsxs("div", { children: [
              feature.title && (typeof feature.title === "string" ? /* @__PURE__ */ jsxs("h3", { className: cn("font-medium md:mb-2 md:text-xl", feature.titleClassName), children: [
                feature.title,
                /* @__PURE__ */ jsx("span", { className: "absolute -left-px hidden h-6 w-px bg-primary md:inline-block" })
              ] }) : /* @__PURE__ */ jsxs("div", { className: cn("font-medium md:mb-2 md:text-xl", feature.titleClassName), children: [
                feature.title,
                /* @__PURE__ */ jsx("span", { className: "absolute -left-px hidden h-6 w-px bg-primary md:inline-block" })
              ] })),
              feature.description && (typeof feature.description === "string" ? /* @__PURE__ */ jsx("p", { className: cn("text-sm text-muted-foreground md:text-base", feature.descriptionClassName), children: feature.description }) : /* @__PURE__ */ jsx("div", { className: cn("text-sm text-muted-foreground md:text-base", feature.descriptionClassName), children: feature.description }))
            ] })
          ]
        },
        index
      );
    });
  };
  return /* @__PURE__ */ jsx("section", { className: cn("py-32", className), children: /* @__PURE__ */ jsxs("div", { className: cn("container", containerClassName), children: [
    label && (typeof label === "string" ? /* @__PURE__ */ jsx("p", { className: cn("mb-4 text-xs text-muted-foreground", labelClassName), children: label }) : /* @__PURE__ */ jsx("div", { className: cn("mb-4 text-xs text-muted-foreground", labelClassName), children: label })),
    title && (typeof title === "string" ? /* @__PURE__ */ jsx("h2", { className: cn("text-3xl font-medium lg:text-4xl", titleClassName), children: title }) : /* @__PURE__ */ jsx("div", { className: cn("text-3xl font-medium lg:text-4xl", titleClassName), children: title })),
    /* @__PURE__ */ jsx("div", { className: cn("mt-14 grid gap-6 md:grid-cols-2 lg:mt-20 lg:grid-cols-4", gridClassName), children: renderFeatures() })
  ] }) });
}

export { FeatureIconGridBordered };
//# sourceMappingURL=feature-icon-grid-bordered.js.map
//# sourceMappingURL=feature-icon-grid-bordered.js.map