'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import type { ReactNode } from 'react';
import { pageSupportsEngine } from '@embedpdf/docs-kit';
import { DOCS_SITE } from '@/docs-site';
import { docsIntegrationFromPath, docsIntegrationHref } from '@/lib/docs-integrations';
import { useConfig } from './config-provider';
import { DocsProductSwitcher } from './docs-product-switcher';
import { IntegrationSwitcher } from './integration';
import { MethodBadge } from './method-badge';
type TreeItem = {
name: string;
route?: string;
title: ReactNode;
/**
* Page frontmatter; API reference pages carry their HTTP `method`
* and — for API-token-only operations — `audience: operator` here.
*/
frontMatter?: { method?: string; audience?: string; engines?: string[] };
children?: TreeItem[];
};
/**
* A section is operator surface when every page in it is — on managed
* CloudPDF those sections (Deployment, Tenants) belong to the platform.
*/
function isOperatorSection(item: TreeItem): boolean {
const pages = (item.children ?? []).filter((child) => child.route);
return pages.length > 0 && pages.every((child) => child.frontMatter?.audience === 'operator');
}
function SidebarLink({ item, pathname }: { item: TreeItem; pathname: string }) {
if (!item.route) return null;
// Content routes are integration-less; rendered hrefs carry the active
// integration so every crawlable link is a concrete destination.
const integration = docsIntegrationFromPath(pathname);
const href = integration ? docsIntegrationHref(item.route, integration) : item.route;
const active = pathname === href;
const method = item.frontMatter?.method;
return (
{method ?
{item.title} {isOperatorSection(item) ? ( Self-hosted ) : null}