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 (
{/* 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 && (
{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')}
)}
{/* The screen itself */}
{context.hero && (
{t(ctxKey(context.id, 'title'))}
)}
{/* What is on it */}
{bullets.length > 0 && (
{t('help.center.onThisScreen')}
)
}
/**
* 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