import React from 'react' import { Link } from 'react-router' import { ArrowRight, ArrowUpRight, BookOpen, LayoutList, ListOrdered, Compass, ChevronRight, Camera, LayoutGrid } from 'lucide-react' import { useTranslation } from '../../i18n' import { useHelpStore, docTitle } from '../../store/helpStore' import { ctxKey, ctxBulletKey, guideKey, guidesFor, helpMedia, docsRoute, helpContextTrail, childHelpContexts } from '../../help/registry' import type { HelpContext, HelpDocLink as HelpDocTarget, HelpGuide } from '../../help/types' import { helpIcon } from './helpIcons' import HelpBadge from './HelpBadge' import HelpDocLink from './HelpDocLink' import { useAuthStore } from '../../store/authStore' import HelpSizeChip from './HelpSizeChip' import { useScreenRoute } from './useScreenRoute' /** * The overview of a screen: what it is, what is on it, and a card per guide. * With no registered context (a screen that has no help yet) it says so and * leaves the search box as the way forward. */ export default function HelpHome({ context }: { context: HelpContext | null }): React.ReactElement { const { t } = useTranslation() const docIndex = useHelpStore(s => s.docIndex) // No Help & Docs page on a managed install (App.tsx), so no links into it. const managed = useAuthStore(s => s.managed) const closeHelp = useHelpStore(s => s.closeHelp) const screenRoute = useScreenRoute(context?.route) if (!context) { return (

{t('help.center.noContext')}

{t('help.center.noContextHint')}

) } const guides = guidesFor(context) const bullets = Array.from({ length: context.bullets }, (_, i) => t(ctxBulletKey(context.id, i + 1))) const children = childHelpContexts(context.id) const docs = managed ? [] : onePerPage(context.docs) const trail = helpContextTrail(context).slice(0, -1) const Icon = helpIcon(context.icon) return (
{/* Which screen, what it is, what help there is */}
{/* Where a sub-screen sits; a screen of its own needs no trail, the switcher names it. */} {trail.length > 0 && (
{trail.map((parent, i) => ( {i > 0 && } {t(ctxKey(parent.id, 'title'))} ))}
)}

{t(ctxKey(context.id, 'title'))}

{t(ctxKey(context.id, 'summary'))}

{screenRoute && ( {t('help.center.goToScreen', { screen: t(ctxKey(context.id, 'title')) })} )}
{/* Screens under this one (the columns and tabs of a trip, the tabs of Settings), always in view: each holds guides of its own, and a fold hid that they are there at all. */} {children.length > 0 && (
{t('help.center.subScreensLabel')}
)} {/* Guides */} {guides.length > 0 && (
{t('help.center.howTo')}
)} {/* The screen itself */} {context.hero && (
{t(ctxKey(context.id, 'title'))}
)} {/* What is on it */} {bullets.length > 0 && (
{t('help.center.onThisScreen')}
)} {/* Docs */} {docs.length > 0 && (
{t('help.center.docsSection')}
)}
) } /** * The docs of a screen, one link per page: several sections of one page would * all read as that page's title, the same name two or three times in a row. */ function onePerPage(docs: readonly HelpDocTarget[]): HelpDocTarget[] { const seen = new Set() return docs.filter(link => { if (seen.has(link.slug)) return false seen.add(link.slug) return true }) } /** One sub-screen: opens its overview in place; the one the reader is on says so. */ function SubScreenCard({ screen }: { screen: HelpContext }): React.ReactElement { const { t } = useTranslation() const browse = useHelpStore(s => s.browse) const contextId = useHelpStore(s => s.contextId) const current = screen.id === contextId const Icon = helpIcon(screen.icon) return ( ) } /** The marker for the screen the reader is actually on. */ export function ThisScreenChip(): React.ReactElement { const { t } = useTranslation() return ( {t('help.center.thisScreen')} ) } export function SectionLabel({ children }: { children: React.ReactNode }): React.ReactElement { return

{children}

} export function GuideCard({ guide }: { guide: HelpGuide }): React.ReactElement { const { t } = useTranslation() const openGuide = useHelpStore(s => s.openGuide) const Icon = helpIcon(guide.icon) return ( ) }