'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useCallback } from 'react';
import { Sparkles, Loader2 } from 'lucide-react';
import { toast } from 'sonner';
import { cmsApi } from '../../lib/api.js';
export function AIBlockAssist({ block, pageTitle, businessName, onUpdateData, }) {
    const [generating, setGenerating] = useState(false);
    const handleGenerate = useCallback(async () => {
        setGenerating(true);
        try {
            const res = await cmsApi('/page-builder/generate-block', {
                method: 'POST',
                body: JSON.stringify({
                    blockType: block.settings.blockType,
                    variant: block.settings.variant,
                    pageContext: {
                        pageTitle,
                        businessName,
                    },
                }),
            });
            if (res.error) {
                toast.error(res.error);
            }
            else if (res.data) {
                onUpdateData(res.data);
                toast.success('Content generated');
            }
        }
        catch {
            toast.error('Failed to generate content');
        }
        finally {
            setGenerating(false);
        }
    }, [block, pageTitle, businessName, onUpdateData]);
    return (_jsxs("button", { onClick: handleGenerate, disabled: generating, className: "text-primary hover:bg-primary/10 flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors disabled:opacity-50", title: "Generate content with AI", children: [generating ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Sparkles, { size: 12 }), generating ? 'Generating...' : 'AI Fill'] }));
}
//# sourceMappingURL=AIBlockAssist.js.map