import React from 'react';
import { ArrowDownRightIcon, ArrowUpRightIcon, EyeIcon } from 'lucide-react';
import {
bandForScore,
type ScoreBand,
} from '../../../lib/dashboard/score-bands';
import { useCopilot } from '../../../context/copilot.context';
import { TURN_CREDITS } from '../../../service/copilot/pricing';
import type {
ScanHistoryPoint,
WeeklyReportResponse,
} from '../../../service/visibility/visibility.interface';
/** One number on the strip, with everything needed to draw it. */
interface Metric {
value: string;
label: string;
/** The same number last week, or empty when there is no last week. */
previous: string;
/** Week-over-week change, or null when there is nothing to compare. */
delta: number | null;
/** Unit appended to the delta. */
deltaSuffix: string;
/** Colour for the number itself. */
valueColor: string;
/** What this number means at its current level, when it has a reading. */
reading: string;
}
/** One week-over-week change beside its number. */
function Delta({
delta,
suffix,
}: {
delta: number | null;
suffix: string;
}): React.ReactElement | null {
if (delta === null) return null;
const rounded: number = Math.round(delta * 10) / 10;
if (rounded === 0) return null;
const isUp: boolean = rounded > 0;
const Icon = isUp ? ArrowUpRightIcon : ArrowDownRightIcon;
return (
{isUp ? '+' : ''}
{rounded}
{suffix}
);
}
/**
* Where visibility stands this week, where it stood last week and — for the
* score itself — what that level means, coloured on the same bands the
* dashboard's ring uses. A number below the band where AI engines start
* citing you should not be the same colour as one above it.
*/
export function WeekPanel({
report,
scans,
onAsk,
}: {
report: WeeklyReportResponse | null;
scans: ScanHistoryPoint[];
onAsk: (prompt: string) => void;
}): React.ReactElement {
const copilot = useCopilot();
const thisWeek: ScanHistoryPoint | undefined = scans[0];
const lastWeek: ScanHistoryPoint | undefined = scans[1];
if (!report && !thisWeek) {
return (