import { useProjectsQuery } from 'data/projects/projects-query' import { useSendEventMutation } from 'data/telemetry/send-event-mutation' import { AnimatePresence, motion } from 'framer-motion' import { MessageSquare } from 'lucide-react' import Link from 'next/link' import { useCallback, useEffect, useState } from 'react' import { Button } from 'ui' interface AIAssistantOptionProps { projectRef: string organizationSlug: string isCondensed?: boolean } export const AIAssistantOption = ({ projectRef, organizationSlug, isCondensed = false, }: AIAssistantOptionProps) => { const { data } = useProjectsQuery() const projects = data?.projects ?? [] const { mutate: sendEvent } = useSendEventMutation() const [isVisible, setIsVisible] = useState(isCondensed ? true : false) useEffect(() => { const timer = setTimeout(() => setIsVisible(true), 800) return () => clearTimeout(timer) }, []) const onAiAssistantClicked = useCallback(() => { sendEvent({ action: 'ai_assistant_in_support_form_clicked', groups: { project: projectRef === 'no-project' ? undefined : projectRef, organization: organizationSlug, }, }) }, [projectRef, organizationSlug, sendEvent]) if (!organizationSlug || organizationSlug === 'no-org') { return null } const getProjectRef = () => { if (projectRef !== 'no-project') { return projectRef } // If no specific project selected, use first project from the org const orgProjects = projects?.filter((p) => p.organization_slug === organizationSlug) return orgProjects?.[0]?.ref || '_' } const aiLink = `/project/${getProjectRef()}?aiAssistantPanelOpen=true` return ( {isVisible && (

Try the AI Assistant

Ask the AI assistant to help you with your support issue

{!isCondensed && (

Hi! I'm your AI assistant. How can I help you today?

I can help you with database queries, API endpoints, or any other technical questions you might have.

)}
)} ) }