import { useState } from 'react'; import { useCollections } from '@/hooks/useCollections'; import { FolderHeart, Plus, Trash2, Edit2, Eye, Globe, Lock, RefreshCw, Search, MoreVertical, Image as ImageIcon, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Switch } from '@/components/ui/switch'; const Collections = () => { const { collections, stats, loading, error, loadCollections, createCollection, updateCollection, deleteCollection, getCollectionById, selectedCollection, setSelectedCollection, } = useCollections(); const [searchTerm, setSearchTerm] = useState(''); const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); const [collectionToDelete, setCollectionToDelete] = useState(null); // Form state const [formData, setFormData] = useState({ name: '', description: '', coverImageUrl: '', color: '#3b82f6', isPublic: false, }); const filteredCollections = collections.filter(col => col.name.toLowerCase().includes(searchTerm.toLowerCase()) || col.description?.toLowerCase().includes(searchTerm.toLowerCase()) ); const handleRefresh = async () => { await loadCollections(); }; const handleCreate = async () => { const result = await createCollection(formData); if (result) { setIsCreateDialogOpen(false); resetForm(); } }; const handleEdit = async () => { if (!selectedCollection) return; const success = await updateCollection(selectedCollection.id, formData); if (success) { setIsEditDialogOpen(false); resetForm(); } }; const handleDelete = async () => { if (!collectionToDelete) return; const success = await deleteCollection(collectionToDelete); if (success) { setIsDeleteDialogOpen(false); setCollectionToDelete(null); } }; const openEditDialog = async (collectionId: string) => { const collection = await getCollectionById(collectionId); if (collection) { setFormData({ name: collection.name, description: collection.description || '', coverImageUrl: collection.coverImageUrl || '', color: collection.color || '#3b82f6', isPublic: collection.isPublic, }); setIsEditDialogOpen(true); } }; const openDeleteDialog = (collectionId: string) => { setCollectionToDelete(collectionId); setIsDeleteDialogOpen(true); }; const resetForm = () => { setFormData({ name: '', description: '', coverImageUrl: '', color: '#3b82f6', isPublic: false, }); setSelectedCollection(null); }; if (loading && collections.length === 0) { return (

Cargando colecciones...

); } return (
{/* Header */}

Gestión de Colecciones

Administra las colecciones de lugares favoritos

Crear Colección Crea una nueva colección para organizar lugares.
setFormData({ ...formData, name: e.target.value })} placeholder="Mi colección" />