'use client'; import { useTranslations } from 'next-intl'; import { Accessibility, BookOpen, Flag, Hand, HelpCircle } from '@/components/icons'; import { useConfig } from '@/hooks/use-config'; import { helpLinksFrom, type HelpLink, type HelpLinkId } from '@/lib/help-links'; import { cn } from '@/lib/utils'; const ICONS: Record = { statement: Accessibility, feedback: Flag, help: HelpCircle, easy_read: BookOpen, sign_language: Hand, }; /** The configured accessibility and help links, in their fixed order. */ export function useHelpLinks(): HelpLink[] { const { accessibilityStatementUrl, accessibilityFeedbackUrl, helpUrl, easyReadUrl, signLanguageUrl } = useConfig(); return helpLinksFrom({ accessibilityStatementUrl, accessibilityFeedbackUrl, helpUrl, easyReadUrl, signLanguageUrl }); } function LinkText({ link }: { link: HelpLink }) { const t = useTranslations('help_links'); return ( <> {t(link.id)} {link.external && ({t('new_tab')})} ); } /** * The links as a small navigation list, for the login page footer and the * settings sidebar. Renders nothing when the operator set none. */ export function HelpLinks({ className, listClassName, linkClassName }: { className?: string; listClassName?: string; linkClassName?: string }) { const t = useTranslations('help_links'); const links = useHelpLinks(); if (links.length === 0) return null; return ( ); } /** * The links as menu items, for the account menu. `onSelect` closes the * menu. Renders nothing when the operator set none. */ export function HelpMenuItems({ onSelect, className, itemClassName, iconClassName = 'w-4 h-4 shrink-0' }: { onSelect?: () => void; className?: string; itemClassName?: string; iconClassName?: string; }) { const t = useTranslations('help_links'); const links = useHelpLinks(); if (links.length === 0) return null; return (
{links.map((link) => { const Icon = ICONS[link.id]; return ( onSelect?.()} className={itemClassName} > ); })}
); }