"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 _chunk7VMEOFEAcjs = require('./chunk-7VMEOFEA.cjs');





var _chunkJMU4RU5Jcjs = require('./chunk-JMU4RU5J.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.jsxs.call(void 0, "div", { className: "flex min-w-0 flex-col items-start gap-2 pr-4", children: [
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { children: item.question }),
                  item.badge && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                    _chunkJMU4RU5Jcjs.StatusBadge,
                    {
                      text: item.badge.toUpperCase(),
                      variant: "card",
                      className: _chunkJMU4RU5Jcjs.TAG_BADGE_CLASS
                    }
                  )
                ] }),
                /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-shrink-0", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                  _chunk7VMEOFEAcjs.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/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 _chunk7VMEOFEAcjs.buildSuggestionUrl.call(void 0, "/api/faqs", { apiBaseUrl, entityType, entityId, count: minResults });
}
function toAccordionItems(faqs) {
  return faqs.map((faq) => ({
    id: faq.id,
    question: faq.question,
    answer: faq.answer,
    badge: faq.section || void 0
  }));
}
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,
  variant,
  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', _2 => _2.faqs]), () => ( []));
  const isEmbedded = variant ? variant === "embedded" : heading === null;
  const headingNode = heading === void 0 ? isEmbedded ? (
    // Embedded default is an <h2> — a host page already owns the <h1>,
    // and the schema/heading pair must read "Frequently Asked Questions"
    // (one FAQ heading per page, never tag/section names).
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: _chunkJMU4RU5Jcjs.SECTION_HEADING_CLASS, children: DEFAULT_HEADING_TEXT })
  ) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h1", { className: _chunkJMU4RU5Jcjs.PAGE_HEADING_CLASS, children: DEFAULT_HEADING_TEXT }) : heading;
  if (error && isEmbedded) {
    return null;
  }
  if (!isLoading && !error && faqs.length === 0 && isEmbedded) {
    return null;
  }
  if (isLoading && faqs.length === 0) {
    if (isEmbedded) {
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FaqSkeleton, {}) });
    }
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "main", { className: _nullishCoalesce(className, () => ( "bg-ods-bg")), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "max-w-[1920px] px-6 md:px-20 py-6 md:py-10 mx-auto", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FaqSkeleton, {}) }) });
  }
  if (error && faqs.length === 0) {
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "main", { className: _nullishCoalesce(className, () => ( "bg-ods-bg flex items-center justify-center py-20")), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-ods-text-primary font-medium", children: "Failed to load FAQs. Please try again later." }) });
  }
  const schema = emitJsonLd ? buildFaqJsonLdFromFaqs(faqs, jsonLd) : null;
  const accordion = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FaqAccordion, { items: toAccordionItems(faqs) });
  const body = isEmbedded ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "section", { className: _nullishCoalesce(className, () => ( "space-y-10")), children: [
    headingNode,
    accordion
  ] }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "main", { className: _nullishCoalesce(className, () => ( "bg-ods-bg")), children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "max-w-[1920px] px-6 md:px-20 py-6 md:py-10 mx-auto space-y-10", children: [
    headingNode,
    accordion
  ] }) });
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
    body,
    schema && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      "script",
      {
        type: "application/ld+json",
        dangerouslySetInnerHTML: { __html: _chunk7VMEOFEAcjs.serializeJsonLd.call(void 0, schema) }
      }
    )
  ] });
}




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