'use client' import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Plus, Trash2 } from 'lucide-react' import type { AutomationTrigger, TriggerAndGroup, TriggerOrGroup, TriggerType, } from '@/lib/mail-automation/types' import { AUTOMATION_DOMAIN_LABELS, DOMAIN_TRIGGER_TYPES, TRIGGER_LABELS, defaultTriggerForDomain, inferDomainsFromTriggers, triggerDomain, triggerUsesContactLabel, triggerUsesFolderPath, triggerUsesMailFolder, triggerUsesMailLabel, } from '@/lib/mail-automation/domains' import type { AutomationDomain } from '@/lib/mail-automation/domains' import { triggerValueSuggestionKind } from '@/lib/mail-automation/condition-helpers' import { AutomationSuggestInput } from './automation-suggest-input' const ALL_DOMAINS: AutomationDomain[] = ['mail', 'drive', 'contacts'] interface WorkflowTriggersPanelProps { triggers: TriggerOrGroup onChange: (triggers: TriggerOrGroup) => void disabled?: boolean } export function WorkflowTriggersPanel({ triggers, onChange, disabled, }: WorkflowTriggersPanelProps) { const groups = triggers.groups.length > 0 ? triggers.groups : [{ operator: 'and' as const, items: [{ type: 'message_received' as const }] }] const activeDomains = inferDomainsFromTriggers(triggers) const multiDomain = activeDomains.length > 1 function updateGroups(next: TriggerAndGroup[]) { onChange({ operator: 'or', groups: next.length > 0 ? next : [{ operator: 'and', items: [] }], }) } function updateGroup(gi: number, group: TriggerAndGroup) { const next = [...groups] next[gi] = group updateGroups(next) } function addOrGroup() { onChange({ operator: 'or', groups: [...groups, { operator: 'and', items: [defaultTriggerForDomain(activeDomains[0] ?? 'mail')] }], }) } function removeOrGroup(gi: number) { updateGroups(groups.filter((_, i) => i !== gi)) } function removeTrigger(gi: number, ti: number) { const group = groups[gi] const items = group.items.filter((_, i) => i !== ti) if (items.length === 0) { removeOrGroup(gi) return } updateGroup(gi, { ...group, items }) } return (
Domaines actifs : {activeDomains.map((d) => AUTOMATION_DOMAIN_LABELS[d]).join(', ')} — seules les conditions et actions compatibles sont proposées.
) : null}OU
) : ( )} {groups.length > 1 ? ( ) : null}Aucun déclencheur — ajoutez-en un ci-dessous
) : null} {group.items.map((item, ti) => (