import { Alert, Anchor, Button, Code, CopyButton, Group, Pagination, Popover, Text, Tooltip } from '@mantine/core';
import { IconCheck, IconCopy, IconHelp, IconPlus, IconRobot, IconShieldLock } from '@/components/icons';
import type { ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { explainError, supportDetails } from '../api/errors';
import { useAuth } from '../auth/AuthContext';
import { decisionWords, GLOSSARY, RUN_STATUS_WORDS } from '../domain/glossary';
import { TextBlurReveal } from './wensity/text-blur-reveal';
export const MOCK_TEXT = 'Mock app, not Oracle Fusion';
export function MockBanner({ fusion = false }: { fusion?: boolean }) {
return (
{fusion ? 'Test environments: the practice app and Oracle Fusion pods' : `Practice environment: ${MOCK_TEXT}`}
);
}
export type Tone = 'neutral' | 'mint' | 'lav' | 'amber' | 'red' | 'green' | 'ink';
/** Small rounded tag (date, tier, status), the design's basic unit. Tones are AA-contrast pairs from styles.css. */
export function Pill({ tone = 'neutral', icon, children, testId, title, outline }: { tone?: Tone | string; icon?: ReactNode; children: ReactNode; testId?: string; title?: string; outline?: boolean }) {
return {icon}{children};
}
/** "Written by the AI model" as dim text with a robot icon (not a coloured pill). */
export function AiText({ children = 'Written by the AI model' }: { children?: ReactNode }) {
return {children};
}
/** A priority word ("Critical") as plain 600-weight text: priority is not a state to act on. */
export function Prio({ words }: { words: string }) {
return {words};
}
/** Page header: the page's large heading, a back link on detail pages, its one-line description (`extra`) and actions
* (`children`). The top navigation is on every screen size, so a page draws no toolbar of its own; `bar` (a short title
* for one) is kept for callers. */
export function PageHeader({ crumbs, title, children, extra, eyebrow }: { crumbs: { label: string; to?: string }[]; title: ReactNode; children?: ReactNode; extra?: ReactNode; bar?: string; eyebrow?: ReactNode }) {
const trail = crumbs.filter((c) => c.to);
// detail pages (three or more crumbs) get a back link to their parent; top-level pages have none
const last = trail[trail.length - 1];
const back = crumbs.length >= 3 && last ? (last.label === 'Home' ? { label: 'Settings', to: '/admin' } : { label: last.label, to: last.to! }) : undefined;
return (
<>
{back && ← {back.label}}
{!back && eyebrow && {eyebrow}}
{/* the title blurs in word by word (Wensity UI); the full title stays its accessible name */}
{typeof title === 'string' ? :
{title}
}
{extra &&
{extra}
}
{children &&
{children}
}
>
);
}
const STATUS_TONE: Record = {
queued: 'neutral', running: 'ink', waiting_approval: 'amber', waiting_sign_in: 'amber', waiting_review: 'amber', completed: 'green', failed: 'red',
killed: 'red', cancelled: 'neutral', interrupted: 'amber', pending: 'neutral', approved: 'green', rejected: 'red', staged: 'ink',
promoted: 'green', discarded: 'neutral', no_snapshot: 'neutral', no_candidate: 'neutral', open: 'red',
};
const STATUS_LABEL: Record = RUN_STATUS_WORDS;
export function StatusBadge({ status }: { status?: string | null }) {
if (!status) return -;
return {STATUS_LABEL[status] ?? status.replace(/_/g, ' ')};
}
/** Decision in consultant words ("Ready" / "Not ready" / "On hold"); the exact rule result stays on the element
* (data-rule) and in the tooltip, and RuleResult shows it in reports for audit. */
export function DecisionBadge({ decision, size = 'md' }: { decision?: string | null; size?: 'sm' | 'md' | 'lg' | 'xl' }) {
if (!decision) return Not decided yet;
const tone = decision === 'GO' ? 'green' : decision === 'HELD' ? 'amber' : 'red';
// the text content is exactly the verdict words: the dot carries no text
return (
{decisionWords(decision)}
);
}
/** The exact go/no-go rule result, for audit. */
export function RuleResult({ decision }: { decision?: string | null }) {
return Rule result: {decision ?? 'none'};
}
/** A consultant word with its meaning (and the technical term) on hover/focus. */
export function Term({ children, k, plain }: { children: ReactNode; k?: string; plain?: boolean }) {
const g = GLOSSARY.find((x) => x.term.toLowerCase() === String(k ?? children).toLowerCase());
if (!g) return <>{children}>;
return (
{children}
);
}
/** The words of the app with their meaning and technical name, plus the keyboard keys. */
export function GlossaryList() {
return (
<>
{GLOSSARY.map((g) => (
{g.term}
{g.means} ({g.technical})
))}
Keys: N new test run · Ctrl K search, go to a page or ask · [ hide the sidebar ·{' '}
? all shortcuts · on a test run Alt 1 the steps, Alt 3 the details panel,{' '}
Ctrl \ show or hide the details panel.
>
);
}
export function GlossaryButton() {
return (
Words used in this app
);
}
/** An error in plain words: what happened, the fields to fix, what to do (or a link that helps), and a small
* "Copy details for support" control that holds the code and request id. */
export function ErrorAlert({ error, title = 'That did not work', hint, onRetry }: { error: unknown; title?: string; hint?: string; onRetry?: () => void }) {
if (!error) return null;
const i = explainError(error);
return (
{i.message}
{i.fields && i.fields.length > 0 && (