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

// components/blocks/faq/faq-sidebar-navigation.tsx
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;
}
function Accordion({
  ...props
}) {
  return /* @__PURE__ */ jsx(AccordionPrimitive.Root, { "data-slot": "accordion", ...props });
}
function AccordionItem({
  className,
  ...props
}) {
  return /* @__PURE__ */ jsx(
    AccordionPrimitive.Item,
    {
      "data-slot": "accordion-item",
      className: cn("border-b last:border-b-0", className),
      ...props
    }
  );
}
function AccordionTrigger({
  className,
  children,
  ...props
}) {
  return /* @__PURE__ */ jsx(AccordionPrimitive.Header, { className: "flex", children: /* @__PURE__ */ jsxs(
    AccordionPrimitive.Trigger,
    {
      "data-slot": "accordion-trigger",
      className: cn(
        "focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
        className
      ),
      ...props,
      children: [
        children,
        /* @__PURE__ */ jsx(DynamicIcon, { name: "lucide/chevron-down", className: "text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" })
      ]
    }
  ) });
}
function AccordionContent({
  className,
  children,
  ...props
}) {
  return /* @__PURE__ */ jsx(
    AccordionPrimitive.Content,
    {
      "data-slot": "accordion-content",
      className: "data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm",
      ...props,
      children: /* @__PURE__ */ jsx("div", { className: cn("pt-0 pb-4", className), children })
    }
  );
}
var defaultCategories = [
  {
    id: "general",
    title: "General",
    items: [
      {
        id: "general-1",
        question: "What is a FAQ?",
        answer: "A FAQ is a list of frequently asked questions and answers on a particular topic."
      },
      {
        id: "general-2",
        question: "What is the purpose of a FAQ?",
        answer: "The purpose of a FAQ is to provide answers to common questions and help users find the information they need quickly and easily."
      },
      {
        id: "general-3",
        question: "How do I create a FAQ?",
        answer: "To create a FAQ, you need to compile a list of common questions and answers on a particular topic and organize them in a clear and easy-to-navigate format."
      }
    ]
  },
  {
    id: "billing",
    title: "Billing",
    items: [
      {
        id: "billing-1",
        question: "What payment methods do you accept?",
        answer: "We accept all major credit cards, PayPal, and bank transfers for annual subscriptions."
      },
      {
        id: "billing-2",
        question: "Can I get a refund?",
        answer: "Yes, we offer a 30-day money-back guarantee for all our plans. If you're not satisfied, contact our support team for a full refund."
      },
      {
        id: "billing-3",
        question: "How do I cancel my subscription?",
        answer: "You can cancel your subscription at any time from your account settings. Your access will continue until the end of your current billing period."
      }
    ]
  },
  {
    id: "support",
    title: "Support",
    items: [
      {
        id: "support-1",
        question: "How do I contact support?",
        answer: "You can reach our support team via email at support@example.com or through our live chat feature available on our website."
      },
      {
        id: "support-2",
        question: "What are your support hours?",
        answer: "Our support team is available Monday through Friday, 9am to 6pm EST. We also offer 24/7 support for enterprise customers."
      }
    ]
  }
];
function FaqSidebarNavigation({
  heading = "Frequently asked questions",
  description = "Find answers to common questions about our products. Can't find what you're looking for? Contact our support team.",
  categories = defaultCategories,
  className
}) {
  const [activeCategory, setActiveCategory] = React.useState(
    categories[0]?.id || ""
  );
  const scrollToCategory = (categoryId) => {
    setActiveCategory(categoryId);
    const element = document.getElementById(`faq-category-${categoryId}`);
    if (element) {
      element.scrollIntoView({ behavior: "smooth", block: "start" });
    }
  };
  return /* @__PURE__ */ jsx("section", { className: cn("py-32", className), children: /* @__PURE__ */ jsxs("div", { className: "container", children: [
    /* @__PURE__ */ jsxs("div", { className: "mx-auto flex max-w-3xl flex-col text-left md:text-center", children: [
      /* @__PURE__ */ jsx("h2", { className: "mb-3 text-3xl font-semibold md:mb-4 lg:mb-6 lg:text-4xl", children: heading }),
      /* @__PURE__ */ jsx("p", { className: "text-muted-foreground lg:text-lg", children: description })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "mx-auto mt-10 flex max-w-7xl flex-col gap-10 lg:flex-row lg:gap-16", children: [
      /* @__PURE__ */ jsx("nav", { className: "lg:w-1/4", children: /* @__PURE__ */ jsx("div", { className: "sticky top-24 space-y-2", children: categories.map((category) => /* @__PURE__ */ jsx(
        "button",
        {
          onClick: () => scrollToCategory(category.id),
          className: cn(
            "w-full rounded-lg px-4 py-2 text-left text-sm font-medium transition-colors",
            activeCategory === category.id ? "bg-primary text-primary-foreground" : "hover:bg-muted"
          ),
          children: category.title
        },
        category.id
      )) }) }),
      /* @__PURE__ */ jsx("div", { className: "space-y-10 lg:w-3/4", children: categories.map((category) => /* @__PURE__ */ jsxs(
        "div",
        {
          id: `faq-category-${category.id}`,
          className: "scroll-mt-24",
          children: [
            /* @__PURE__ */ jsx("h3", { className: "mb-4 text-xl font-semibold", children: category.title }),
            /* @__PURE__ */ jsx(Accordion, { type: "single", collapsible: true, children: category.items.map((item) => /* @__PURE__ */ jsxs(AccordionItem, { value: item.id, children: [
              /* @__PURE__ */ jsx(AccordionTrigger, { className: "transition-opacity duration-200 hover:no-underline hover:opacity-60", children: /* @__PURE__ */ jsx("div", { className: "font-medium sm:py-1 lg:py-2 lg:text-lg", children: item.question }) }),
              /* @__PURE__ */ jsx(AccordionContent, { className: "sm:mb-1 lg:mb-2", children: /* @__PURE__ */ jsx("div", { className: "text-muted-foreground lg:text-lg", children: item.answer }) })
            ] }, item.id)) })
          ]
        },
        category.id
      )) })
    ] })
  ] }) });
}

export { FaqSidebarNavigation };
//# sourceMappingURL=faq-sidebar-navigation.js.map
//# sourceMappingURL=faq-sidebar-navigation.js.map