import { useState } from 'react'; import { MessageSquare, Plus, Pencil, Eye, AlertTriangle, OctagonX, Scale, Star, Clock, } from 'lucide-react'; import { Button } from '../../../components/ui/Button'; import { Badge } from '../../../components/ui/Badge'; import { Select } from '../../../components/ui/Select'; import { useToast } from '../../../components/ui/Toast'; import { useNotes, useUpdateNote } from '../../../hooks/useNotes'; import { NoteType } from '../../../types/deliverable.types'; import type { NoteItem } from '../../../types/deliverable.types'; import { NoteModal } from './NoteModal'; interface EntregavelNotesTabProps { serviceOrderId: string; readOnly?: boolean; } const NOTE_TYPE_OPTIONS = [ { value: '', label: 'Todas' }, { value: NoteType.OBSERVACAO, label: 'Observação' }, { value: NoteType.RISCO, label: 'Risco' }, { value: NoteType.IMPEDIMENTO, label: 'Impedimento' }, { value: NoteType.DECISAO, label: 'Decisão' }, ]; const NOTE_TYPE_CONFIG: Record< NoteType, { icon: typeof Eye; label: string; variant: 'info' | 'warning' | 'danger' | 'purple' } > = { [NoteType.OBSERVACAO]: { icon: Eye, label: 'Observação', variant: 'info' }, [NoteType.RISCO]: { icon: AlertTriangle, label: 'Risco', variant: 'warning' }, [NoteType.IMPEDIMENTO]: { icon: OctagonX, label: 'Impedimento', variant: 'danger' }, [NoteType.DECISAO]: { icon: Scale, label: 'Decisão', variant: 'purple' }, }; function formatDateTime(dateStr: string): string { return new Date(dateStr).toLocaleString('pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', }); } export function EntregavelNotesTab({ serviceOrderId, readOnly = false }: EntregavelNotesTabProps) { const [typeFilter, setTypeFilter] = useState(); const [isModalOpen, setIsModalOpen] = useState(false); const [editingNote, setEditingNote] = useState(); const { data: notes = [], isLoading } = useNotes(serviceOrderId, { type: typeFilter, }); const updateNote = useUpdateNote(); const { showToast } = useToast(); function handleAdd() { setEditingNote(undefined); setIsModalOpen(true); } function handleEdit(note: NoteItem) { setEditingNote(note); setIsModalOpen(true); } function handleCloseModal() { setIsModalOpen(false); setEditingNote(undefined); } function handleToggleRelevance(note: NoteItem) { updateNote.mutate( { osId: serviceOrderId, noteId: note.id, data: { isRelevant: !note.isRelevant }, }, { onSuccess: () => { showToast(note.isRelevant ? 'Relevância removida' : 'Marcada como relevante', 'success'); }, onError: () => { showToast('Erro ao atualizar relevância', 'error'); }, }, ); } function handleTypeChange(value: string) { setTypeFilter(value ? (value as NoteType) : undefined); } if (isLoading) { return (
); } if (notes.length === 0 && !typeFilter) { return ( <>

Nenhuma anotação registrada

{!readOnly && ( )}
); } return ( <> {/* Header com filtro e botão */}