"use client"; import { useState } from "react"; import { Zap, Play, Pause } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Label } from "@/components/ui/label"; import { toast } from "sonner"; import { apiFetch, type Automation } from "./types"; interface Props { automations: Automation[]; onCreated: () => void; } export default function AutomationTab({ automations, onCreated }: Props) { const [automationName, setAutomationName] = useState(""); const [automationType, setAutomationType] = useState("content_generation"); const handleCreateAutomation = async () => { if (!automationName.trim()) { toast.error("Dale un nombre"); return; } try { const result = await apiFetch("/automation", { method: "POST", body: JSON.stringify({ name: automationName, type: automationType, trigger: "schedule", triggerConfig: { schedule: "daily:09:00" }, actions: [{ type: "generate_content", prompt: "Genera contenido de lifestyle" }], }), }); if (result.success) { toast.success("Automatización creada"); setAutomationName(""); onCreated(); } else toast.error(result.error); } catch { toast.error("Error"); } }; const handleToggleAutomation = async (id: string, currentStatus: boolean) => { try { await apiFetch("/automation", { method: "PUT", body: JSON.stringify({ id, isActive: !currentStatus }), }); onCreated(); } catch { toast.error("Error"); } }; return (
No hay automatizaciones
) : ({a.name}
{a.type} • {a.runCount} ejecuciones