"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";


var _chunkT7AJBKZPcjs = require('./chunk-T7AJBKZP.cjs');





var _chunkY2B6WDU6cjs = require('./chunk-Y2B6WDU6.cjs');


var _chunk722TTRIJcjs = require('./chunk-722TTRIJ.cjs');



var _chunkFIG2RKZFcjs = require('./chunk-FIG2RKZF.cjs');

// src/components/faq/faq-section.tsx
var _react = require('react');

// src/components/faq-accordion.tsx

_chunkFIG2RKZFcjs.init_cn.call(void 0, );
var _jsxruntime = require('react/jsx-runtime');
var useMeasuredHeight = (isOpen) => {
  const ref = _react.useRef.call(void 0, null);
  const [maxHeight, setMaxHeight] = _react.useState.call(void 0, "0px");
  const measure = _react.useCallback.call(void 0, () => {
    if (ref.current) {
      const height = ref.current.scrollHeight;
      setMaxHeight(`${height}px`);
    }
  }, []);
  _react.useEffect.call(void 0, () => {
    if (isOpen) {
      measure();
    } else {
      setMaxHeight("0px");
    }
  }, [isOpen, measure]);
  return { ref, maxHeight };
};
function FaqAccordion({ items, defaultOpenIds = [] }) {
  const [openSet, setOpenSet] = _react.useState.call(void 0, new Set(defaultOpenIds));
  const toggle = (id) => {
    setOpenSet((prev) => {
      const next = new Set(prev);
      if (next.has(id)) next.delete(id);
      else next.add(id);
      return next;
    });
  };
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rounded-3xl border border-ods-border divide-y divide-ods-border bg-ods-card overflow-hidden", children: items.map((item) => {
    const isOpen = openSet.has(item.id);
    const { ref, maxHeight } = useMeasuredHeight(isOpen);
    return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
      "div",
      {
        className: _chunkFIG2RKZFcjs.cn.call(void 0, "group transition-colors hover:bg-[#1E1E1E]", isOpen ? "bg-ods-bg" : "bg-transparent"),
        children: [
          /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
            "div",
            {
              role: "button",
              tabIndex: 0,
              onClick: () => toggle(item.id),
              onKeyDown: (e) => {
                if (e.key === "Enter" || e.key === " ") {
                  e.preventDefault();
                  toggle(item.id);
                }
              },
              "aria-expanded": isOpen,
              className: "flex w-full items-center justify-between px-6 md:px-8 py-6 text-left focus:outline-none transition-colors cursor-pointer",
              children: [
                /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "min-w-0 pr-4", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { children: item.question }) }),
                /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-shrink-0", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                  _chunkY2B6WDU6cjs.ChevronButton,
                  {
                    "aria-label": isOpen ? "Collapse question" : "Expand question",
                    size: "md",
                    isExpanded: isOpen,
                    backgroundColor: "transparent",
                    borderColor: "#3A3A3A"
                  }
                ) })
              ]
            }
          ),
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
            "div",
            {
              style: { maxHeight, transition: "max-height 0.35s ease-in-out, opacity 0.35s ease-in-out", opacity: isOpen ? 1 : 0 },
              className: "overflow-hidden group-hover:bg-[#1E1E1E]/30",
              children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ref, className: "px-6 md:px-8 pb-6 text-ods-text-primary text-h4", children: item.answer })
            }
          )
        ]
      },
      item.id
    );
  }) });
}

// src/components/faq/faq-section.tsx
_chunkFIG2RKZFcjs.init_cn.call(void 0, );

// src/components/faq/json-ld.ts
var DEFAULT_NAME = "Frequently Asked Questions";
var DEFAULT_DESCRIPTION = "Answers to common questions.";
function baseFaqSchema(opts = {}) {
  return {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    name: _nullishCoalesce(opts.name, () => ( DEFAULT_NAME)),
    description: _nullishCoalesce(opts.description, () => ( DEFAULT_DESCRIPTION)),
    ...opts.url ? { url: opts.url } : {}
  };
}
function buildFaqJsonLdFromFaqs(faqs, opts = {}) {
  return {
    ...baseFaqSchema(opts),
    mainEntity: faqs.map((faq) => ({
      "@type": "Question",
      name: faq.question,
      acceptedAnswer: {
        "@type": "Answer",
        text: faq.answer
      }
    }))
  };
}

// src/components/faq/faq-section.tsx

var DEFAULT_HEADING_TEXT = "Frequently Asked Questions";
function buildFaqsUrl(entityType, entityId, minResults, apiBaseUrl = "") {
  return _chunkY2B6WDU6cjs.buildSuggestionUrl.call(void 0, "/api/faqs", { apiBaseUrl, entityType, entityId, count: minResults });
}
function sectionSlug(section) {
  return "faq-" + section.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
}
function groupFaqsBySection(faqs) {
  const order = [];
  const byName = /* @__PURE__ */ new Map();
  let uncategorized = null;
  for (const faq of faqs) {
    const item = { id: faq.id, question: faq.question, answer: faq.answer };
    const name = _optionalChain([faq, 'access', _2 => _2.section, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]);
    if (!name) {
      if (!uncategorized) uncategorized = { section: null, slug: null, items: [] };
      uncategorized.items.push(item);
      continue;
    }
    let group = byName.get(name);
    if (!group) {
      group = { section: name, slug: sectionSlug(name), items: [] };
      byName.set(name, group);
      order.push(name);
    }
    group.items.push(item);
  }
  const groups = order.map((name) => byName.get(name));
  if (uncategorized) groups.push(uncategorized);
  return groups;
}
var FAQ_NAV_HEADER_OFFSET = 96;
function GroupedFaqList({
  groups,
  categoryHeadingAs
}) {
  const CategoryHeading = categoryHeadingAs;
  const navGroups = _react.useMemo.call(void 0, () => groups.filter((g) => g.slug), [groups]);
  const [activeSlug, setActiveSlug] = _react.useState.call(void 0, _nullishCoalesce(_optionalChain([navGroups, 'access', _5 => _5[0], 'optionalAccess', _6 => _6.slug]), () => ( null)));
  const slugKey = navGroups.map((g) => g.slug).join("|");
  _react.useEffect.call(void 0, () => {
    if (navGroups.length < 2) return;
    const tops = /* @__PURE__ */ new Map();
    const observer = new IntersectionObserver(
      (entries) => {
        for (const entry of entries) {
          const id = entry.target.id;
          if (entry.isIntersecting) tops.set(id, entry.boundingClientRect.top);
          else tops.delete(id);
        }
        let bestId = null;
        let bestTop = Number.POSITIVE_INFINITY;
        for (const [id, top] of tops) {
          if (top < bestTop) {
            bestTop = top;
            bestId = id;
          }
        }
        if (bestId) setActiveSlug(bestId);
      },
      { rootMargin: `-${FAQ_NAV_HEADER_OFFSET}px 0px -55% 0px`, threshold: 0 }
    );
    for (const group of navGroups) {
      const el = group.slug ? document.getElementById(group.slug) : null;
      if (el) observer.observe(el);
    }
    return () => observer.disconnect();
  }, [slugKey]);
  const handleJump = _react.useCallback.call(void 0, 
    (e, slug) => {
      e.preventDefault();
      setActiveSlug(slug);
      _chunkY2B6WDU6cjs.scrollElementIntoView.call(void 0, document.getElementById(slug), {
        headerOffset: FAQ_NAV_HEADER_OFFSET
      });
      if (typeof history !== "undefined") history.replaceState(null, "", `#${slug}`);
    },
    []
  );
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-8", children: [
    navGroups.length > 1 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "nav", { "aria-label": "FAQ categories", className: "flex flex-wrap gap-2", children: navGroups.map((group) => {
      const isActive = group.slug === activeSlug;
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        "a",
        {
          href: `#${group.slug}`,
          "aria-current": isActive ? "true" : void 0,
          onClick: (e) => handleJump(e, group.slug),
          className: _chunkFIG2RKZFcjs.cn.call(void 0, 
            "rounded-full border px-4 py-2 text-sm font-medium font-['DM_Sans'] transition-colors",
            isActive ? "border-ods-text-primary bg-ods-card text-ods-text-primary" : "border-ods-border bg-ods-card text-ods-text-secondary hover:border-ods-text-secondary hover:text-ods-text-primary"
          ),
          children: group.section
        },
        group.slug
      );
    }) }),
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-10", children: groups.map((group) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
      "section",
      {
        id: _nullishCoalesce(group.slug, () => ( void 0)),
        className: "scroll-mt-24 space-y-4",
        children: [
          group.section && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CategoryHeading, { className: _chunk722TTRIJcjs.SECTION_HEADING_CLASS, children: group.section }),
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FaqAccordion, { items: group.items })
        ]
      },
      _nullishCoalesce(group.slug, () => ( "faq-uncategorized"))
    )) })
  ] });
}
function FaqSkeleton() {
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-8 animate-pulse", children: [
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-12 md:h-14 w-2/3 rounded bg-ods-border" }),
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rounded-3xl border border-ods-border overflow-hidden bg-ods-card divide-y divide-ods-border w-full", children: Array.from({ length: 8 }).map((_, idx) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center justify-between px-6 md:px-8 py-6", children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-6 w-5/6 rounded bg-ods-border" }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-10 w-10 rounded-md bg-ods-border" })
    ] }, idx)) })
  ] });
}
function FaqSection({
  initialFaqs,
  entityType,
  entityId,
  heading,
  emitJsonLd = false,
  jsonLd,
  className,
  minResults,
  apiBaseUrl = ""
}) {
  const url = buildFaqsUrl(entityType, entityId, minResults, apiBaseUrl);
  const initialData = _react.useMemo.call(void 0, 
    () => initialFaqs ? { faqs: initialFaqs } : void 0,
    [initialFaqs]
  );
  const { data, isLoading, error } = _chunkT7AJBKZPcjs.useSelfFetch.call(void 0, url, { initialData });
  const faqs = _nullishCoalesce(_optionalChain([data, 'optionalAccess', _7 => _7.faqs]), () => ( []));
  const groups = _react.useMemo.call(void 0, () => faqs.length > 0 ? groupFaqsBySection(faqs) : [], [faqs]);
  const headingNode = heading === void 0 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: _chunk722TTRIJcjs.SECTION_HEADING_CLASS, children: DEFAULT_HEADING_TEXT }) : heading;
  if (error) return null;
  if (!isLoading && faqs.length === 0) return null;
  if (isLoading && faqs.length === 0) {
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FaqSkeleton, {}) });
  }
  const schema = emitJsonLd ? buildFaqJsonLdFromFaqs(faqs, jsonLd) : null;
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
    /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "section", { className: _nullishCoalesce(className, () => ( "space-y-10")), children: [
      headingNode,
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GroupedFaqList, { groups, categoryHeadingAs: heading === null ? "h2" : "h3" })
    ] }),
    schema && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      "script",
      {
        type: "application/ld+json",
        dangerouslySetInnerHTML: { __html: _chunkY2B6WDU6cjs.serializeJsonLd.call(void 0, schema) }
      }
    )
  ] });
}




exports.FaqAccordion = FaqAccordion; exports.FaqSection = FaqSection;
//# sourceMappingURL=chunk-5QJQAFTP.cjs.map