// Page building blocks of the console (PEP-38): header, sections, empty states, status badges, alerts. import Link from "next/link"; import type { ReactNode } from "react"; import { CircleAlert, CircleCheck } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { SESSION_STATUS, TASK_STATUS, TONE_BG } from "@/lib/status"; import { cn } from "@/lib/utils"; import { getT } from "@/lib/i18n"; import { intlLocale, type Translator } from "@peppa/shared/i18n"; export function PageHeader({ title, crumbs, actions, children }: { title: ReactNode; crumbs?: ReactNode; actions?: ReactNode; children?: ReactNode }) { return (
{crumbs &&
{crumbs}
}

{title}

{actions &&
{actions}
}
{children &&
{children}
}
); } export function Section({ title, count, actions, children, className, id }: { title: ReactNode; count?: number; actions?: ReactNode; children: ReactNode; className?: string; id?: string }) { return (

{title}

{count != null && count > 0 && {count}} {actions &&
{actions}
}
{children}
); } export function MoreLink({ href, children }: { href: string; children: ReactNode }) { return ( {children} → ); } export function Empty({ children }: { children: ReactNode }) { return

{children}

; } /** Monospace task/project key, optionally a link. */ export function Key({ children, href, className }: { children: ReactNode; href?: string; className?: string }) { const cls = cn("font-mono text-[0.9em] whitespace-nowrap", href ? "text-primary hover:underline" : "text-muted-foreground", className); return href ? {children} : {children}; } export async function StatusBadge({ status, kind = "task" }: { status: string; kind?: "task" | "session" }) { const t = await getT(); const s = (kind === "task" ? TASK_STATUS : SESSION_STATUS)[status] ?? { label: status, tone: "muted" as const }; return ( {kind === "session" && } {t.text(s.label)} ); } export async function Flash({ error }: { error?: string }) { const t = await getT(); return error ? ( // Sticky: an action far down the page (a board card, «Принять») must not fail silently above the fold.

{t.text(error)}

) : null; } export function Notice({ children }: { children: ReactNode }) { return (
{children}
); } /** Collapsible block styled as a card (native
: no client JS). */ export function Disclosure({ summary, children, open, className }: { summary: ReactNode; children: ReactNode; open?: boolean; className?: string }) { return (
› {summary}
{children}
); } /** «5 мин назад» in the page's language. */ export function ago(d: Date | null | undefined, t: Translator): string { if (!d) return "—"; const s = Math.round((Date.now() - d.getTime()) / 1000); if (s < 60) return t("{n} с назад", { n: s }); if (s < 3600) return t("{n} мин назад", { n: Math.round(s / 60) }); if (s < 86400) return t("{n} ч назад", { n: Math.round(s / 3600) }); return d.toLocaleDateString(intlLocale(t.locale)); } /** Text with its http(s) addresses as links. */ export function linkify(text: string) { return text.split(/(https?:\/\/[^\s<>«»"]+[^\s<>«»".,;:!?)])/g).map((part, i) => i % 2 ? ( {part} ) : ( part ), ); }