import { Plus } from 'lucide-react'
import { AiIconAnimation } from 'ui'
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
interface CreateTriggerButtonsProps {
hasTables: boolean
canCreateTriggers: boolean
selectedSchema: string
onCreateTrigger: () => void
showPlusIcon?: boolean
buttonType?: 'default'
}
export const CreateTriggerButtons = ({
hasTables,
canCreateTriggers,
selectedSchema,
onCreateTrigger,
showPlusIcon = true,
buttonType,
}: CreateTriggerButtonsProps) => {
const aiSnap = useAiAssistantStateSnapshot()
const { openSidebar } = useSidebarManagerSnapshot()
return (
: undefined}
tooltip={{
content: {
side: 'bottom',
text: !hasTables
? 'Create a table first before creating triggers'
: !canCreateTriggers
? 'You need additional permissions to create triggers'
: undefined,
},
}}
>
New trigger
{hasTables && (
}
onClick={() => {
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
aiSnap.newChat({
name: 'Create new trigger',
initialInput: `Create a new trigger for the schema ${selectedSchema} that does ...`,
suggestions: {
title:
'I can help you create a new trigger, here are a few example prompts to get you started:',
prompts: [
{
label: 'Log Changes',
description: 'Create a trigger that logs changes to the users table',
},
{
label: 'Update Timestamp',
description: 'Create a trigger that updates updated_at timestamp',
},
{
label: 'Validate Email',
description: 'Create a trigger that validates email format before insert',
},
],
},
})
}}
tooltip={{
content: {
side: 'bottom',
text: !canCreateTriggers
? 'You need additional permissions to create triggers'
: 'Create with Briven Assistant',
},
}}
/>
)}
)
}