import { useState } from "react"; import { CalendarDays, Check, ChevronDown, ChevronRight, ClipboardList, CircleHelp, FileSearch, FileText, ListChecks, Mail, Paperclip, PenLine, Send, Settings, Sparkles, } from "lucide-react"; import AgentInsight from "./AgentInsight"; import AgentSpark from "./AgentSpark"; import SenderAvatar from "./SenderAvatar"; import { inboxContext } from "../utils/inboxSignals"; const ICON = { size: 14, strokeWidth: 1.75 }; const ICON_SM = { size: 13, strokeWidth: 1.75 }; const cards = [ { key: "important", label: "Important emails", captionKey: "importantFromClients", captionSuffix: "from clients", hint: "In your inbox", icon: Mail, tone: "rose", }, { key: "actionItems", label: "Action items", hint: "Need your response", icon: ClipboardList, tone: "blue", }, { key: "meetings", label: "Meetings mentioned", hint: "In your emails", icon: CalendarDays, tone: "green", }, { key: "invoices", label: "Invoices & bills", hint: "This week", icon: FileText, tone: "purple", }, ]; function greeting(name) { const hour = new Date().getHours(); const period = hour < 12 ? "Good morning" : hour < 17 ? "Good afternoon" : "Good evening"; return `${period}, ${name}`; } function statCaption(card, stats) { const count = stats[card.key] || 0; if (count === 0) return card.hint; if (card.captionKey && stats[card.captionKey] > 0) { return `${stats[card.captionKey]} ${card.captionSuffix}`; } return card.hint; } function metricTotal(stats) { return cards.reduce((sum, card) => sum + (stats[card.key] || 0), 0); } export default function AgAgentPanel({ account, emails, focus, insight, loading = false, mailboxEmpty = false, isBrandNewMailbox = false, onCompose, onQuickAction, onOpenEmail, onAgentAsk, }) { const { stats, needsReply, today, deadlines } = inboxContext(emails); const [agentQuery, setAgentQuery] = useState(""); const [panelOpen, setPanelOpen] = useState(true); const firstName = account?.first_name || "there"; const allMetricsZero = metricTotal(stats) === 0; const hasQuery = agentQuery.trim().length > 0; const showOnboarding = !insight && !loading && mailboxEmpty && isBrandNewMailbox; const showQuietEmpty = !insight && !loading && mailboxEmpty && !isBrandNewMailbox; const showFullPanel = !insight && !loading && !mailboxEmpty; function submitAgentQuery(event) { event.preventDefault(); const query = agentQuery.trim(); if (!query) return; onAgentAsk?.(query); setAgentQuery(""); } return (

AG Agent

Your email co-pilot

{panelOpen && (
{!insight && (
{greeting(firstName)} {showOnboarding ? "Your new inbox is ready." : showQuietEmpty ? "Nothing needs your attention right now." : "Here's what needs your attention today."}
)} {!insight && loading && ( )} {showOnboarding && (

AGMail is ready

No messages yet. I'll start organizing and surfacing important items as email arrives.

)} {showQuietEmpty && (

You're all caught up.

Your inbox is clear for now.

)} {showFullPanel && !allMetricsZero && (
{cards.map((card) => { const Icon = card.icon; const count = stats[card.key] || 0; const isEmpty = count === 0; return ( ); })}
)} {showFullPanel && allMetricsZero && (

You're all caught up.

No urgent messages or outstanding actions.

)} {!insight && focus && showFullPanel && !allMetricsZero && (

{focus}

)}

{showOnboarding ? "Quick start" : "Quick actions"}

{showOnboarding ? ( <> ) : ( <> )}
{showFullPanel && !insight && (

Today's agenda

{today.length > 0 ? (
    {today.map((item) => (
  • ))}
) : (

No meetings in your emails today.

)}
)} {showFullPanel && !insight && (

Needs attention

{needsReply.length > 0 ? (
    {needsReply.slice(0, 3).map((item) => (
  • ))}
) : (

Nothing needs your attention right now.

)}
)} {showFullPanel && !insight && deadlines.length > 0 && (

Deadlines

    {deadlines.map((item) => (
  • {item.label} {item.due}
  • ))}
)}
setAgentQuery(event.target.value)} placeholder="Ask about your emails..." />
)}
); }