'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { Sparkles, Bot } from 'lucide-react';
import { toast } from 'sonner';
import { summarizeSeoAudit } from '../../lib/seo-service.js';
import { Drawer } from './Drawer.js';
import { SeoLoading, SeoEmptyState, btnPrimary } from './primitives.js';
/**
 * AI Copilot drawer — summarizes the current SEO state and surfaces the top
 * priorities. Degrades gracefully when AI is unconfigured. All AI text is
 * advisory; the editor takes action via the tabs/drawers.
 */
export function SeoCopilotDrawer({ open, onOpenChange, }) {
    const [loading, setLoading] = useState(false);
    const [summary, setSummary] = useState(null);
    const [unavailable, setUnavailable] = useState(false);
    async function handleSummarize() {
        setLoading(true);
        setUnavailable(false);
        const res = await summarizeSeoAudit();
        setLoading(false);
        if (res.unavailable) {
            setUnavailable(true);
            return;
        }
        if (res.text)
            setSummary(res.text);
        else
            toast.error('No summary was returned.');
    }
    return (_jsx(Drawer, { open: open, onOpenChange: onOpenChange, title: "SEO Copilot", description: "AI-assisted analysis of your site's SEO health", width: "max-w-md", footer: _jsxs("button", { className: btnPrimary, onClick: handleSummarize, disabled: loading, children: [_jsx(Sparkles, { className: `h-4 w-4 ${loading ? 'animate-pulse' : ''}`, "aria-hidden": true }), loading ? 'Analyzing…' : summary ? 'Re-analyze' : 'Analyze my SEO'] }), children: loading ? (_jsx(SeoLoading, { label: "Analyzing your SEO\u2026" })) : unavailable ? (_jsx(SeoEmptyState, { icon: _jsx(Bot, { size: 24 }), title: "AI is not configured", description: "Install and configure an AI provider (plugin-ai) to enable the SEO Copilot." })) : summary ? (_jsx("div", { className: "text-foreground space-y-3 text-sm leading-relaxed", children: summary.split(/\n+/).map((para, i) => (_jsx("p", { children: para }, i))) })) : (_jsx(SeoEmptyState, { icon: _jsx(Bot, { size: 24 }), title: "Ask the Copilot", description: "Get an AI summary of your open issues and the top priorities to fix first." })) }));
}
//# sourceMappingURL=SeoCopilotDrawer.js.map