'use client'; import { Check, ChevronDown, Link2 } from 'lucide-react'; import { useState } from 'react'; import { cn } from '@djangocfg/ui-core/lib'; import { useEndpointDocContext } from '../context'; import { buildSectionHash } from '../hooks/useSectionHash'; import type { SectionId } from '../types'; interface SectionHeaderProps { /** Section identifier — needed to build the shareable hash link. */ sectionId: SectionId; title: string; badge?: number; open: boolean; onToggle: () => void; } /** Clickable header for a collapsible section. The whole row toggles, * plus a hover-revealed anchor button copies a ``#section=...`` URL so * users can share a link that lands with this exact section already * expanded (handled by ``useSectionHashRouter``). */ export function SectionHeader({ sectionId, title, badge, open, onToggle }: SectionHeaderProps) { const { endpointId } = useEndpointDocContext(); const [copied, setCopied] = useState(false); const copyHash = (e: React.MouseEvent) => { // Prevent the row toggle — the anchor button must not collapse // the section while the user is copying the link. e.stopPropagation(); if (typeof window === 'undefined') return; const hash = buildSectionHash(endpointId, sectionId); const url = `${window.location.origin}${window.location.pathname}#${hash}`; void navigator.clipboard?.writeText(url).then(() => { setCopied(true); setTimeout(() => setCopied(false), 1200); }); }; return (