"use client";
'use strict';

var clsx = require('clsx');
var tailwindMerge = require('tailwind-merge');
var React = require('react');
var jsxRuntime = require('react/jsx-runtime');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);

// lib/utils.ts
function cn(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
var svgCache = /* @__PURE__ */ new Map();
function DynamicIcon({
  name,
  size = 28,
  color,
  className,
  alt
}) {
  const [svgContent, setSvgContent] = React__namespace.useState(null);
  const [isLoading, setIsLoading] = React__namespace.useState(true);
  const [error, setError] = React__namespace.useState(null);
  const { url, iconName } = React__namespace.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__namespace.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__ */ jsxRuntime.jsx(
      "span",
      {
        className: cn("inline-block", className),
        style: { width: size, height: size },
        "aria-hidden": "true"
      }
    );
  }
  if (error || !svgContent) {
    return /* @__PURE__ */ jsxRuntime.jsx(
      "span",
      {
        className: cn("inline-block", className),
        style: { width: size, height: size },
        role: "img",
        "aria-label": alt || iconName
      }
    );
  }
  return /* @__PURE__ */ jsxRuntime.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;
}
function ComparisonFeatureGrid({
  heading,
  description,
  optionALabel = "Our Solution",
  optionBLabel = "Alternative",
  features,
  gridSlot,
  className,
  containerClassName,
  headingClassName,
  descriptionClassName,
  gridWrapperClassName,
  gridHeaderClassName,
  gridRowClassName
}) {
  const renderStatusIcon = (status) => {
    if (status === true) {
      return /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/check", size: 20, className: "text-success" });
    }
    if (status === "partial") {
      return /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/check", size: 20, className: "text-accent" });
    }
    return /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/x", size: 20, className: "text-destructive" });
  };
  const renderGrid = () => {
    if (gridSlot) return gridSlot;
    if (!features || features.length === 0) return null;
    return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("mx-auto max-w-4xl divide-y divide-border overflow-x-auto rounded-lg border-border bg-background shadow", gridWrapperClassName), children: [
      /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("hidden rounded-t-lg bg-muted text-left text-base font-semibold text-foreground sm:flex", gridHeaderClassName), children: [
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-16 px-6 py-4" }),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 px-6 py-4", children: "Feature" }),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-40 px-6 py-4", children: optionALabel }),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-40 px-6 py-4", children: optionBLabel })
      ] }),
      features.map((row, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
        "div",
        {
          className: cn("flex flex-col items-start text-left sm:flex-row sm:items-center", gridRowClassName),
          children: [
            /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-start px-6 pt-4 sm:w-16 sm:justify-center sm:py-4", children: [
              /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: row.icon, size: 20, className: "text-gray-500" }),
              /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-3 text-base font-medium sm:hidden", children: row.label })
            ] }),
            /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1 px-6 pb-2 sm:py-4", children: [
              /* @__PURE__ */ jsxRuntime.jsx("div", { className: "hidden font-medium sm:block", children: row.label }),
              /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 mb-2 text-sm text-muted-foreground sm:mb-0", children: row.description })
            ] }),
            /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-start px-6 pb-2 sm:w-40 sm:justify-center sm:py-4", children: [
              renderStatusIcon(row.optionA),
              /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-2 text-xs font-medium text-muted-foreground sm:hidden", children: optionALabel })
            ] }),
            /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-start border-border px-6 pb-4 sm:w-40 sm:justify-center sm:border-0 sm:py-4", children: [
              renderStatusIcon(row.optionB),
              /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-2 text-xs font-medium text-muted-foreground sm:hidden", children: optionBLabel })
            ] })
          ]
        },
        idx
      ))
    ] });
  };
  return /* @__PURE__ */ jsxRuntime.jsx("section", { className: cn("py-32", className), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("container", containerClassName), children: [
    heading && (typeof heading === "string" ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: cn("mb-4 text-center text-4xl font-semibold", headingClassName), children: heading }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: headingClassName, children: heading })),
    description && (typeof description === "string" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: cn("mb-8 text-center text-muted-foreground", descriptionClassName), children: description }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: descriptionClassName, children: description })),
    renderGrid()
  ] }) });
}

exports.ComparisonFeatureGrid = ComparisonFeatureGrid;
