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


var _chunk7VMEOFEAcjs = require('./chunk-7VMEOFEA.cjs');




var _chunkUUARMJJEcjs = require('./chunk-UUARMJJE.cjs');

// src/components/related-content/related-content-section.tsx
var _react = require('react');
_chunkQAQ7AROScjs.init_pagination.call(void 0, );
var _jsxruntime = require('react/jsx-runtime');
function DefaultLinkPropsProvider({ href, targetPlatform, children }) {
  if (!href) return children(null);
  const newTab = _chunkUUARMJJEcjs.decideNewTab.call(void 0, { href, targetPlatform, currentSource: "" });
  return children(
    newTab ? { href, target: "_blank", rel: "noopener noreferrer" } : { href }
  );
}
function defaultResolveHref(ref) {
  return { href: ref.url || null, targetPlatform: _nullishCoalesce(ref.targetPlatform, () => ( null)) };
}
function renderSkeletonForType(type, size, adminCampaignCard) {
  const legacySize = size === "sm" ? "sm" : "default";
  switch (type) {
    case "blog_post_existing":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.BlogCardSkeleton, { size: legacySize });
    case "case_study":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.CaseStudyCardSkeleton, { size: legacySize });
    case "customer_interview":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.CustomerInterviewCardSkeleton, { size: legacySize });
    case "product_release":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.ProductReleaseCardSkeleton, { size: size === "sm" ? "sm" : "lg" });
    case "podcast":
    case "webinar":
    case "event":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.ProgramCardSkeleton, { size: legacySize });
    case "investor_update":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.InvestorUpdateCardSkeleton, { size: legacySize });
    case "onboarding_guide":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUUARMJJEcjs.OnboardingGuideCardSkeleton, { size: size === "sm" ? "sm" : "catalog" });
    case "marketing_campaign":
      return adminCampaignCard ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, adminCampaignCard.Skeleton, { size: legacySize }) : null;
    case "roadmap_item":
    case "delivery_item":
    case "internal_task":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.RoadmapCardSkeleton, { size: legacySize });
    default:
      return null;
  }
}
function CardForType({
  type,
  item,
  size,
  href,
  targetPlatform,
  linkProps,
  extras,
  adminCampaignCard
}) {
  const legacySize = size === "sm" ? "sm" : "default";
  const placeholderUrl = _nullishCoalesce(_optionalChain([extras, 'optionalAccess', _ => _.buildOgPlaceholderUrl, 'optionalCall', _2 => _2(_nullishCoalesce(_optionalChain([item, 'optionalAccess', _3 => _3.title]), () => ( "")))]), () => ( void 0));
  const anchorAttrs = linkProps ? { target: linkProps.target, rel: linkProps.rel } : {};
  switch (type) {
    case "blog_post_existing":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.BlogCard, { post: item, size: legacySize, href, targetPlatform, placeholderUrl, ...anchorAttrs });
    case "case_study":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.CaseStudyCard, { study: item, size: legacySize, href, targetPlatform, placeholderUrl, ...anchorAttrs });
    case "customer_interview":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.CustomerInterviewCard, { interview: item, size: legacySize, href, targetPlatform, placeholderUrl, ...anchorAttrs });
    case "product_release": {
      const releaseSize = size === "sm" ? "sm" : "lg";
      const buildReleaseProps = _nullishCoalesce(_optionalChain([extras, 'optionalAccess', _4 => _4.buildProductReleaseCardProps]), () => ( _chunkQAQ7AROScjs.buildProductReleaseCardProps));
      const releaseProps = buildReleaseProps(item);
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkQAQ7AROScjs.ProductReleaseCard,
        {
          size: releaseSize,
          title: item.title,
          summary: item.summary,
          version: item.version,
          ...releaseProps,
          anchorProps: _nullishCoalesce(linkProps, () => ( void 0))
        }
      );
    }
    case "podcast":
      return _optionalChain([extras, 'optionalAccess', _5 => _5.programConfigs, 'optionalAccess', _6 => _6.podcast]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.ProgramCard, { config: extras.programConfigs.podcast, item, size: legacySize, href, targetPlatform, placeholderUrl, ...anchorAttrs }) : null;
    case "webinar":
      return _optionalChain([extras, 'optionalAccess', _7 => _7.programConfigs, 'optionalAccess', _8 => _8.webinar]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.ProgramCard, { config: extras.programConfigs.webinar, item, size: legacySize, href, targetPlatform, placeholderUrl, ...anchorAttrs }) : null;
    case "event":
      return _optionalChain([extras, 'optionalAccess', _9 => _9.programConfigs, 'optionalAccess', _10 => _10.event]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.ProgramCard, { config: extras.programConfigs.event, item, size: legacySize, href, targetPlatform, placeholderUrl, ...anchorAttrs }) : null;
    case "investor_update":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.InvestorUpdateCard, { update: item, size: legacySize, href, targetPlatform, placeholderUrl, ...anchorAttrs });
    case "onboarding_guide":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUUARMJJEcjs.OnboardingGuideCard, { guide: item, size: size === "sm" ? "sm" : "catalog", href, targetPlatform, placeholderUrl, ...anchorAttrs });
    case "marketing_campaign":
      return adminCampaignCard ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, adminCampaignCard.Card, { campaign: item }) : null;
    case "roadmap_item":
    case "delivery_item":
    case "internal_task":
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkQAQ7AROScjs.RoadmapCard,
        {
          item,
          href: _nullishCoalesce(href, () => ( "")),
          targetPlatform,
          userVote: null,
          onVote: () => {
          },
          size: legacySize,
          cardType: type,
          ...anchorAttrs
        }
      );
    default:
      return null;
  }
}
function useGroupItems(type, refs, buildUrl) {
  const ids = refs.map((r) => r.id);
  const url = ids.length > 0 ? buildUrl(type, ids) : null;
  const { data, isLoading } = _chunkT7AJBKZPcjs.useSelfFetch.call(void 0, url);
  const items = data != null ? _chunkQAQ7AROScjs.extractItems.call(void 0, data) : null;
  return { items, isLoading };
}
function gridClassFor(columns) {
  return columns === 3 ? "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6" : "grid grid-cols-1 sm:grid-cols-2 gap-6";
}
function resolveGroupConfig(type) {
  return _nullishCoalesce(_chunkQAQ7AROScjs.CONTENT_REF_GROUPS[type], () => ( {
    label: type,
    order: 999,
    layout: "grid",
    gridSize: "default"
  }));
}
var GROUP_PAGE_SIZE = 12;
function ContentGroup({
  type,
  refs,
  columns,
  buildUrl,
  resolveHref,
  LinkProvider,
  extras,
  adminCampaignCard,
  heading
}) {
  const { items, isLoading } = useGroupItems(type, refs, buildUrl);
  const config = resolveGroupConfig(type);
  const isListLayout = config.layout === "list";
  const cardSize = config.gridSize;
  const [page, setPage] = _react.useState.call(void 0, 1);
  const refsKey = refs.map((r) => r.id).join("|");
  const prevRefsKeyRef = _react.useRef.call(void 0, refsKey);
  _react.useEffect.call(void 0, () => {
    if (prevRefsKeyRef.current !== refsKey) {
      prevRefsKeyRef.current = refsKey;
      setPage(1);
    }
  }, [refsKey]);
  const totalGroupPages = Math.max(1, Math.ceil(refs.length / GROUP_PAGE_SIZE));
  const safePage = Math.min(page, totalGroupPages);
  const visibleGroupRefs = refs.length > GROUP_PAGE_SIZE ? refs.slice((safePage - 1) * GROUP_PAGE_SIZE, safePage * GROUP_PAGE_SIZE) : refs;
  const groupPagination = totalGroupPages > 1 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.Pagination, { currentPage: safePage, totalPages: totalGroupPages, onPageChange: setPage }) : null;
  if (isLoading && !items) {
    const skeletons = visibleGroupRefs.map((r) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: renderSkeletonForType(type, cardSize, adminCampaignCard) }, r.id));
    return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-4", children: [
      heading,
      isListLayout ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-4", children: skeletons }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: gridClassFor(columns), children: skeletons })
    ] });
  }
  if (!items || items.length === 0) return null;
  const itemById = new Map(
    items.map((it) => [_nullishCoalesce(_chunkQAQ7AROScjs.extractItemId.call(void 0, type, it), () => ( String(_optionalChain([it, 'optionalAccess', _11 => _11.id])))), it])
  );
  const cards = visibleGroupRefs.map((contentRef) => {
    const itemId = String(contentRef.id);
    const item = itemById.get(itemId);
    if (!item) return null;
    const resolved = resolveHref(contentRef);
    const href = _nullishCoalesce(resolved.href, () => ( ""));
    const targetPlatform = _nullishCoalesce(_nullishCoalesce(resolved.targetPlatform, () => ( contentRef.targetPlatform)), () => ( null));
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LinkProvider, { href: href || null, targetPlatform, children: (linkProps) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      CardForType,
      {
        type,
        item,
        size: cardSize,
        href,
        targetPlatform,
        linkProps,
        extras,
        adminCampaignCard
      }
    ) }) }, itemId);
  }).filter(Boolean);
  if (cards.length === 0) {
    if (groupPagination) {
      return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-4", children: [
        heading,
        groupPagination
      ] });
    }
    return null;
  }
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-4", children: [
    heading,
    isListLayout ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-4", children: cards }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: gridClassFor(columns), children: cards }),
    groupPagination
  ] });
}
function RelatedContentSection({
  contentRefs,
  entityType,
  entityId,
  authorId,
  minResults,
  sameTypeMinResults,
  includeTypes,
  initialItems,
  title = "Related Content",
  columns = 2,
  excludeTypes,
  apiBaseUrl = "",
  extras,
  resolveHref = defaultResolveHref,
  buildListUrl: buildListUrl2,
  LinkProvider = DefaultLinkPropsProvider,
  adminCampaignCard
}) {
  const suggestionsDisabled = _optionalChain([includeTypes, 'optionalAccess', _12 => _12.length]) === 0;
  const typeFilterParams = {
    types: includeTypes !== void 0 ? includeTypes.join(",") : void 0,
    excludeTypes: excludeTypes && excludeTypes.length > 0 ? excludeTypes.join(",") : void 0
  };
  const authorUrl = contentRefs === void 0 && authorId && !suggestionsDisabled ? _chunk7VMEOFEAcjs.buildSuggestionUrl.call(void 0, "/api/related-content", {
    apiBaseUrl,
    extraParams: { authorId, ...typeFilterParams }
  }) : null;
  const suggestUrl = _nullishCoalesce(authorUrl, () => ( (contentRefs === void 0 && entityType && entityId !== void 0 && entityId !== null && entityId !== "" && !suggestionsDisabled ? _chunk7VMEOFEAcjs.buildSuggestionUrl.call(void 0, "/api/related-content", {
    apiBaseUrl,
    entityType,
    entityId,
    count: minResults,
    extraParams: {
      sameTypeCount: sameTypeMinResults !== void 0 ? String(sameTypeMinResults) : void 0,
      ...typeFilterParams
    }
  }) : null)));
  const initialData = _react.useMemo.call(void 0, 
    // An explicitly disabled rail (includeTypes: []) must ignore SSR-hydrated
    // refs too — otherwise useSelfFetch(null, {initialData}) keeps serving
    // initialItems and the "nothing participates" contract silently breaks.
    () => !suggestionsDisabled && initialItems ? { refs: initialItems } : void 0,
    [initialItems, suggestionsDisabled]
  );
  const { data } = _chunkT7AJBKZPcjs.useSelfFetch.call(void 0, suggestUrl, { initialData });
  const effectiveBuildListUrl = _react.useMemo.call(void 0, 
    () => _nullishCoalesce(buildListUrl2, () => ( ((type, ids) => _chunkQAQ7AROScjs.buildListUrl.call(void 0, type, ids, apiBaseUrl)))),
    [buildListUrl2, apiBaseUrl]
  );
  const refs = _nullishCoalesce(_nullishCoalesce(contentRefs, () => ( _optionalChain([data, 'optionalAccess', _13 => _13.refs]))), () => ( []));
  const exclude = new Set(excludeTypes || []);
  const visibleRefs = exclude.size > 0 ? refs.filter((r) => !exclude.has(r.type)) : refs;
  if (!visibleRefs.length) return null;
  const grouped = {};
  for (const ref of visibleRefs) {
    if (!grouped[ref.type]) grouped[ref.type] = [];
    grouped[ref.type].push(ref);
  }
  let orderedTypes = _chunkQAQ7AROScjs.orderContentRefTypes.call(void 0, Object.keys(grouped));
  if (entityType) {
    const canonicalEntityType = _chunkQAQ7AROScjs.canonicalContentRefType.call(void 0, entityType);
    const sameType = orderedTypes.filter((t) => _chunkQAQ7AROScjs.canonicalContentRefType.call(void 0, t) === canonicalEntityType);
    if (sameType.length > 0) {
      orderedTypes = [...sameType, ...orderedTypes.filter((t) => _chunkQAQ7AROScjs.canonicalContentRefType.call(void 0, t) !== canonicalEntityType)];
    }
  }
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-8", children: [
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "text-2xl font-bold text-ods-text-primary", children: title }),
    orderedTypes.map((type) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      ContentGroup,
      {
        type,
        refs: grouped[type],
        columns,
        buildUrl: effectiveBuildListUrl,
        resolveHref,
        LinkProvider,
        extras,
        adminCampaignCard,
        heading: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "font-['Azeret_Mono'] text-[14px] font-semibold uppercase text-ods-text-secondary tracking-wider", children: _chunkQAQ7AROScjs.getContentRefLabelOrTitleCase.call(void 0, type) })
      },
      type
    ))
  ] });
}




exports.GROUP_PAGE_SIZE = GROUP_PAGE_SIZE; exports.RelatedContentSection = RelatedContentSection;
//# sourceMappingURL=chunk-WB2JXKEI.cjs.map