diff --git a/package.json b/package.json index ebf5e6a..1f9a6fa 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,11 @@ "ci:verify": "prettier --check . && eslint . && tsc --noEmit" }, "dependencies": { + "@radix-ui/react-alert-dialog": "^1.1.15", "@radix-ui/react-avatar": "^1.1.11", + "@radix-ui/react-collapsible": "^1.1.12", "@radix-ui/react-dialog": "^1.1.15", + "@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-label": "^2.1.8", "@radix-ui/react-popover": "^1.1.15", "@radix-ui/react-scroll-area": "^1.2.10", @@ -38,6 +41,7 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.1.1", + "date-fns": "^4.1.0", "lucide-react": "^0.561.0", "react": "^19.2.0", "react-dom": "^19.2.0", diff --git a/src/components/asignaturas/detalle/BibliographyItem.tsx b/src/components/asignaturas/detalle/BibliographyItem.tsx index 21c5bde..2560cba 100644 --- a/src/components/asignaturas/detalle/BibliographyItem.tsx +++ b/src/components/asignaturas/detalle/BibliographyItem.tsx @@ -1,84 +1,291 @@ -import { useState } from 'react' -import { Textarea } from '@/components/ui/textarea' -import { Button } from '@/components/ui/button' -import { Pencil, BookOpen } from 'lucide-react' -import { cn } from '@/lib/utils' +import { useState } from 'react'; +import { Plus, Search, BookOpen, Trash2, Library, Edit3, Save } from 'lucide-react'; +import { Card, CardContent } from '@/components/ui/card'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Textarea } from '@/components/ui/textarea'; +import { Badge } from '@/components/ui/badge'; +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog'; +import { cn } from '@/lib/utils'; +//import { toast } from 'sonner'; +//import { mockLibraryResources } from '@/data/mockMateriaData'; -type Props = { - value: string - onSave: (value: string) => void +export const mockLibraryResources = [ + { + id: 'lib-1', + titulo: 'Deep Learning', + autor: 'Goodfellow, I., Bengio, Y., & Courville, A.', + editorial: 'MIT Press', + anio: 2016, + isbn: '9780262035613', + disponible: true + }, + { + id: 'lib-2', + titulo: 'Artificial Intelligence: A Modern Approach', + autor: 'Russell, S., & Norvig, P.', + editorial: 'Pearson', + anio: 2020, + isbn: '9780134610993', + disponible: true + }, + { + id: 'lib-3', + titulo: 'Hands-On Machine Learning', + autor: 'Aurélien Géron', + editorial: 'O\'Reilly Media', + anio: 2019, + isbn: '9781492032649', + disponible: false + } +]; + +// --- Interfaces --- +export interface BibliografiaEntry { + id: string; + tipo: 'BASICA' | 'COMPLEMENTARIA'; + cita: string; + fuenteBibliotecaId?: string; + fuenteBiblioteca?: any; } -export function BibliographyItem({ value, onSave }: Props) { - const [isEditing, setIsEditing] = useState(false) - const [draft, setDraft] = useState(value) +interface BibliografiaTabProps { + bibliografia: BibliografiaEntry[]; + onSave: (bibliografia: BibliografiaEntry[]) => void; + isSaving: boolean; +} - function handleCancel() { - setDraft(value) - setIsEditing(false) - } +export function BibliographyItem({ bibliografia, onSave, isSaving }: BibliografiaTabProps) { + const [entries, setEntries] = useState(bibliografia); + const [isAddDialogOpen, setIsAddDialogOpen] = useState(false); + const [isLibraryDialogOpen, setIsLibraryDialogOpen] = useState(false); + const [deleteId, setDeleteId] = useState(null); + const [editingId, setEditingId] = useState(null); + const [newEntryType, setNewEntryType] = useState<'BASICA' | 'COMPLEMENTARIA'>('BASICA'); - function handleSave() { - onSave(draft) - setIsEditing(false) - } + const basicaEntries = entries.filter(e => e.tipo === 'BASICA'); + const complementariaEntries = entries.filter(e => e.tipo === 'COMPLEMENTARIA'); + + const handleAddManual = (cita: string) => { + const newEntry: BibliografiaEntry = { id: `manual-${Date.now()}`, tipo: newEntryType, cita }; + setEntries([...entries, newEntry]); + setIsAddDialogOpen(false); + //toast.success('Referencia manual añadida'); + }; + + const handleAddFromLibrary = (resource: any, tipo: 'BASICA' | 'COMPLEMENTARIA') => { + const cita = `${resource.autor} (${resource.anio}). ${resource.titulo}. ${resource.editorial}.`; + const newEntry: BibliografiaEntry = { + id: `lib-ref-${Date.now()}`, + tipo, + cita, + fuenteBibliotecaId: resource.id, + fuenteBiblioteca: resource, + }; + setEntries([...entries, newEntry]); + setIsLibraryDialogOpen(false); + //toast.success('Añadido desde biblioteca'); + }; + + const handleUpdateCita = (id: string, cita: string) => { + setEntries(entries.map(e => e.id === id ? { ...e, cita } : e)); + }; return ( -
-
- - -
- {!isEditing ? ( - <> -

{value}

- - - - ) : ( - <> -