import { useEffect, useRef, useState } from "react" import { CaretRightIcon, ClockIcon, PlusIcon } from "@phosphor-icons/react" import { CRON_PRESETS } from "@/lib/agents/cron" import { cn } from "@/lib/utils" interface ScheduleTriggerPickerProps { /** Called with a cron value for a preset, or null when the user picks Custom. */ onSelect: (cron: string | null) => void triggerLabel?: string } const OPTIONS: Array<{ id: string; label: string; cron: string | null }> = [ ...CRON_PRESETS.map((preset) => ({ id: preset.id, label: preset.label, cron: preset.value, })), { id: "custom", label: "Custom (cron)", cron: null }, ] export function ScheduleTriggerPicker({ onSelect, triggerLabel = "Add Trigger", }: ScheduleTriggerPickerProps) { const [open, setOpen] = useState(false) const ref = useRef(null) useEffect(() => { function handleClickOutside(e: MouseEvent) { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false) } } document.addEventListener("mousedown", handleClickOutside) return () => document.removeEventListener("mousedown", handleClickOutside) }, []) return (
{open && (
Scheduled
{OPTIONS.map((option) => ( ))}
)}
) }