import * as React from "react"; import { type LucideIcon, BrainCircuit, Database, Layers } from "lucide-react"; import { cn } from "@/lib/utils"; import { formatCurrentMonthYear } from "@/lib/format-date"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Separator } from "@/components/ui/separator"; import type { PolicyQueryContext, PolicyQueryType, } from "./policy-ai-primitives"; // --------------------------------------------------------------------------- // Props // --------------------------------------------------------------------------- export interface PolicyAIContextSidebarProps { /** Context detected from the most recent query (absent in home state). */ lastQueryContext?: PolicyQueryContext; /** Follow-up question suggestions shown below the query context. */ suggestedFollowUps?: string[]; /** Called when user clicks a suggested follow-up question. */ onFollowUpClick?: (question: string) => void; /** Number of banks indexed. Defaults to 0. */ bankCount?: number; /** Number of policy categories indexed. Defaults to 0. */ categoryCount?: number; /** Human-readable date of last policy update. Defaults to the current month. */ lastUpdated?: string; className?: string; } // --------------------------------------------------------------------------- // Internal helpers // --------------------------------------------------------------------------- const QUERY_TYPE_DESCRIPTIONS: Record = { single_bank: "Answered from a single bank's policy documents.", cross_bank_comparison: "Compared across all indexed banks simultaneously.", threshold_filter: "Filtered banks against a specific threshold or limit.", ranking: "Ranked banks using TOPSIS multi-criteria scoring.", scenario_match: "Matched your scenario against all bank lending criteria.", general: "General policy question answered from the knowledge base.", }; const QUERY_TYPE_LABELS: Record = { single_bank: "Single bank", cross_bank_comparison: "Cross-bank", threshold_filter: "Threshold filter", ranking: "Ranked list", scenario_match: "Scenario match", general: "General", }; // --------------------------------------------------------------------------- // Sub-components // --------------------------------------------------------------------------- function SidebarSection({ title, children, className, }: { title: string; children: React.ReactNode; className?: string; }) { return (

{title}

{children}
); } function StatRow({ icon: Icon, children, }: { icon: LucideIcon; children: React.ReactNode; }) { return (
); } // --------------------------------------------------------------------------- // PolicyAIContextSidebar (Organism) // --------------------------------------------------------------------------- /** * Right sidebar for the Policy AI dedicated page. * Displays: * - Coverage stats (banks + categories indexed) * - Last query context as a source reference card * - Suggested follow-up questions * * @example * */ export function PolicyAIContextSidebar({ lastQueryContext, suggestedFollowUps, onFollowUpClick, bankCount = 0, categoryCount = 0, lastUpdated = formatCurrentMonthYear(), className, }: PolicyAIContextSidebarProps) { return (
{/* ── Coverage stats ── */}
{bankCount} banks indexed {categoryCount} policy categories Updated {lastUpdated}
{/* ── Last query context — source reference card ── */} {lastQueryContext && ( <> {/* * Styled as a "source" card — three zones: * Header → policy type + query type badge * Body → bank name + category badges * Footer → one-line method description */} {/* Header */}
{lastQueryContext.policyType} {QUERY_TYPE_LABELS[lastQueryContext.queryType]}
{/* Body */}
{lastQueryContext.bankName && (

{lastQueryContext.bankName}

)} {lastQueryContext.categories.length > 0 && (
{lastQueryContext.categories.map((cat) => ( {cat} ))}
)}
{/* Footer — method description */}

{QUERY_TYPE_DESCRIPTIONS[lastQueryContext.queryType]}

)} {/* ── Suggested follow-ups ── */} {!!suggestedFollowUps?.length && ( <>
{suggestedFollowUps.map((q) => ( ))}
)}
); }