"use client"; import { useState } from "react"; import { Calendar } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; 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, getStatusColor, type Post } from "./types"; interface Props { posts: Post[]; onCreated: () => void; } export default function PostsTab({ posts, onCreated }: Props) { const [postTitle, setPostTitle] = useState(""); const [postType, setPostType] = useState("reel"); const [postCaption, setPostCaption] = useState(""); const [scheduledTime, setScheduledTime] = useState(""); const handleCreatePost = async () => { if (!postTitle.trim()) { toast.error("Añade un título"); return; } try { const result = await apiFetch("/posts", { method: "POST", body: JSON.stringify({ title: postTitle, type: postType, caption: postCaption, scheduledAt: scheduledTime || null, autoGenerateCaption: true, }), }); if (result.success) { toast.success(scheduledTime ? "Post programado" : "Post creado"); setPostTitle(""); setPostCaption(""); setScheduledTime(""); onCreated(); } else toast.error(result.error); } catch { toast.error("Error"); } }; return (
Crear Publicación setPostTitle(e.target.value)} className="bg-slate-800 border-slate-700" />