"use client"; import Link from "next/link"; import { useState } from "react"; import { MoreHorizontal, PlusCircle, Search, Eye, Edit, Trash2, ArrowLeft, } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { mockAppointments, mockProfessionals } from "@/lib/mocks/appointment-mocks"; import { CalendarRegistrationForm } from "@/components/forms/calendar-registration-form"; const formatDate = (date: string | Date) => { if (!date) return ""; return new Date(date).toLocaleDateString("pt-BR", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", }); }; const capitalize = (s: string) => { if (typeof s !== 'string' || s.length === 0) return ''; return s.charAt(0).toUpperCase() + s.slice(1); }; export default function ConsultasPage() { const [appointments, setAppointments] = useState(mockAppointments); const [showForm, setShowForm] = useState(false); const [editingAppointment, setEditingAppointment] = useState(null); const [viewingAppointment, setViewingAppointment] = useState(null); const mapAppointmentToFormData = (appointment: any) => { const professional = mockProfessionals.find(p => p.id === appointment.professional); const appointmentDate = new Date(appointment.time); return { id: appointment.id, patientName: appointment.patient, professionalName: professional ? professional.name : '', appointmentDate: appointmentDate.toISOString().split('T')[0], startTime: appointmentDate.toTimeString().split(' ')[0].substring(0, 5), endTime: new Date(appointmentDate.getTime() + appointment.duration * 60000).toTimeString().split(' ')[0].substring(0, 5), status: appointment.status, appointmentType: appointment.type, notes: appointment.notes, cpf: '', rg: '', birthDate: '', phoneCode: '+55', phoneNumber: '', email: '', unit: 'nei', }; }; const handleDelete = (appointmentId: string) => { if (window.confirm("Tem certeza que deseja excluir esta consulta?")) { setAppointments((prev) => prev.filter((a) => a.id !== appointmentId)); } }; const handleEdit = (appointment: any) => { const formData = mapAppointmentToFormData(appointment); setEditingAppointment(formData); setShowForm(true); }; const handleView = (appointment: any) => { setViewingAppointment(appointment); }; const handleCancel = () => { setEditingAppointment(null); setShowForm(false); }; const handleSave = (formData: any) => { const updatedAppointment = { id: formData.id, patient: formData.patientName, time: new Date(`${formData.appointmentDate}T${formData.startTime}`).toISOString(), duration: 30, type: formData.appointmentType as any, status: formData.status as any, professional: appointments.find(a => a.id === formData.id)?.professional || '', notes: formData.notes, }; setAppointments(prev => prev.map(a => a.id === updatedAppointment.id ? updatedAppointment : a) ); handleCancel(); }; if (showForm && editingAppointment) { return (

Editar Consulta

) } return (

Gerenciamento de Consultas

Visualize, filtre e gerencie todas as consultas da clínica.

Consultas Agendadas Visualize, filtre e gerencie todas as consultas da clínica.
Paciente Médico Status Data e Hora Ações {appointments.map((appointment) => { const professional = mockProfessionals.find( (p) => p.id === appointment.professional ); return ( {appointment.patient} {professional ? professional.name : "Não encontrado"} {capitalize(appointment.status)} {formatDate(appointment.time)} handleView(appointment)} > Ver handleEdit(appointment)}> Editar handleDelete(appointment.id)} className="text-destructive" > Excluir ); })}
{viewingAppointment && ( setViewingAppointment(null)}> Detalhes da Consulta Informações detalhadas da consulta de {viewingAppointment?.patient}.
{viewingAppointment?.patient}
{mockProfessionals.find(p => p.id === viewingAppointment?.professional)?.name || "Não encontrado"}
{viewingAppointment?.time ? formatDate(viewingAppointment.time) : ''}
{capitalize(viewingAppointment?.status || '')}
{capitalize(viewingAppointment?.type || '')}
{viewingAppointment?.notes || "Nenhuma"}
)}
); }