// Long-form report response — for big multi-section analytical answers.
// Used when the agent returns a comprehensive report (multiple tables,
// dimensions, callouts, collapsible detail) rather than a single answer.
const { useState: useStateRR, useEffect: useEffectRR, useRef: useRefRR } = React;
// Flag → visual treatment (status badge color)
const FLAG_STYLE = {
ok: { color: 'var(--verified)', bg: 'var(--verified-bg)', label: 'On track', sym: '✓' },
warn: { color: '#B65E07', bg: 'var(--warn-bg)', label: 'Below', sym: '⚠' },
bad: { color: '#C2410C', bg: 'rgba(220,80,40,.10)', label: 'Critical', sym: '✗' },
};
const FlagPill = ({ flag }) => {
if (!flag) return null;
const s = FLAG_STYLE[flag];
return (
{s.sym}
{s.label}
);
};
const SectionNav = ({ sections, active, onJump }) => (
{sections.map(s => (
))}
);
const Callout = ({ kind = 'insight', label, children }) => (
{label || kind}
{children}
);
const SmartTable = ({ headers, rows, hasFlag, dense }) => (
{headers.map((h, i) => (
| {h} |
))}
{hasFlag && Status | }
{rows.map((r, i) => {
const flag = hasFlag ? r[r.length - 1] : null;
const cells = hasFlag ? r.slice(0, -1) : r;
return (
{cells.map((c, j) => (
| {c} |
))}
{hasFlag && (
|
)}
);
})}
);
const CollapsibleDetail = ({ name, sub, headers, rows, startOpen }) => {
const [open, setOpen] = useStateRR(!!startOpen);
return (
{open && (
)}
);
};
const ReportResponse = ({ tweaks, onOpenTrail }) => {
const D = window.OMNI_DATA;
const R = D.OTIF_REPORT;
const [activeSection, setActiveSection] = useStateRR('hero');
const [showExport, setShowExport] = useStateRR(false);
const [feedback, setFeedback] = useStateRR(null);
const containerRef = useRefRR();
const sections = [
{ id: 'hero', label: 'Executive summary' },
{ id: 'fiscal', label: 'By fiscal year' },
{ id: 'quarter', label: 'By quarter' },
{ id: 'product', label: 'By product' },
{ id: 'region', label: 'By region' },
{ id: 'customer', label: 'By customer' },
{ id: 'detail', label: 'Detail' },
];
// Track which section is in view (intersection observer)
useEffectRR(() => {
if (!containerRef.current) return;
const root = containerRef.current.closest('.feed');
const els = sections.map(s => containerRef.current.querySelector('#sec-' + s.id)).filter(Boolean);
const io = new IntersectionObserver((entries) => {
const visible = entries.filter(e => e.isIntersecting).sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top);
if (visible[0]) setActiveSection(visible[0].target.id.replace('sec-', ''));
}, { root, rootMargin: '-120px 0px -60% 0px', threshold: 0 });
els.forEach(el => io.observe(el));
return () => io.disconnect();
}, []);
const jumpTo = (id) => {
const el = containerRef.current.querySelector('#sec-' + id);
const feed = containerRef.current.closest('.feed');
if (el && feed) {
const top = el.getBoundingClientRect().top - feed.getBoundingClientRect().top + feed.scrollTop - 100;
feed.scrollTo({ top, behavior: 'smooth' });
}
};
return (
Comprehensive report · 7 sections
{R.title}
{R.dataset}
{/* Executive summary */}
01
Executive summary — global OTIF metrics
{R.hero.map((h, i) => (
{h.k}
{h.v}
{h.flag === 'warn' && ⚠}
{h.flag === 'ok' && ✓}
{h.sub &&
{h.sub}
}
))}
{R.insight}
{/* By fiscal year */}
{/* By quarter */}
03
By fiscal quarter — recent
{R.quarter.trend}
{/* By product */}
04
By product category — top 11 by volume
Worst performers: {R.product.worst}.
{/* By region */}
05
By region
{R.region.note}
Regions captured ({R.region.captured.length * 18 + 2}):
{R.region.captured.map((r, i) => - {r}
)}
{/* By customer */}
06
By customer — top 20 by volume
{R.customer.note}
Sample customers:
{R.customer.sample.map((c, i) =>
{c}
)}
{/* Detailed breakdown */}
07
Detailed breakdown — product × fiscal year
Expand any product category to see the full year-by-year breakdown.
{R.detail.map((d, i) => (
))}
{tweaks.showCost && (
5 calls
·
42,180 tokens
·
$0.0428
)}
{showExport && setShowExport(false)}/>}
);
};
Object.assign(window, { ReportResponse, SmartTable, Callout, SectionNav, CollapsibleDetail });