import React, { useEffect, useState } from "react"; import { Card, CardContent, CardHeader, CardTitle, CardDescription, } from "./MetricCard"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Calendar } from "@/components/ui/calendar"; import { Textarea } from "@/components/ui/textarea"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { ENDPOINTS } from "../services/endpoints"; import api from "../services/api"; // Adapte conforme o seu projeto const months = [ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro", ]; const currentYear = new Date().getFullYear(); const years = Array.from({ length: 10 }, (_, i) => currentYear - 2 + i); export default function BookAppointment() { const [doctors, setDoctors] = useState([]); const [searchTerm, setSearchTerm] = useState(""); const [selectedSpecialty, setSelectedSpecialty] = useState("all"); const [selectedDate, setSelectedDate] = useState( new Date() ); const [currentMonth, setCurrentMonth] = useState(new Date()); const [selectedDoctor, setSelectedDoctor] = useState(null); const [selectedTime, setSelectedTime] = useState(""); const [appointmentType, setAppointmentType] = useState< "presential" | "online" >("presential"); const [showConfirmDialog, setShowConfirmDialog] = useState(false); const [reason, setReason] = useState(""); const [loading, setLoading] = useState(false); useEffect(() => { // Busca médicos da API api .get(ENDPOINTS.DOCTORS) .then((res) => setDoctors(res.data)) .catch(() => setDoctors([])); }, []); const filteredDoctors = doctors.filter((doctor) => { const matchesSearch = doctor.name?.toLowerCase().includes(searchTerm.toLowerCase()) || doctor.specialty?.toLowerCase().includes(searchTerm.toLowerCase()); const matchesSpecialty = selectedSpecialty === "all" || doctor.specialty === selectedSpecialty; return matchesSearch && matchesSpecialty; }); const handleBookAppointment = () => { if (selectedDoctor && selectedTime) { setShowConfirmDialog(true); } }; const confirmAppointment = async () => { if (!selectedDoctor || !selectedTime || !selectedDate) return; setLoading(true); try { await api.post(ENDPOINTS.APPOINTMENTS, { doctor_id: selectedDoctor.id, date: selectedDate.toISOString().split("T")[0], time: selectedTime, type: appointmentType, reason, }); alert("Agendamento realizado com sucesso!"); setShowConfirmDialog(false); setSelectedDoctor(null); setSelectedTime(""); setReason(""); } catch (e) { alert("Erro ao agendar consulta"); } finally { setLoading(false); } }; const handleMonthChange = (month: string) => { const newDate = new Date(currentMonth.getFullYear(), Number(month)); setCurrentMonth(newDate); }; const handleYearChange = (year: string) => { const newDate = new Date(Number(year), currentMonth.getMonth()); setCurrentMonth(newDate); }; return (

Agendar Consulta

Escolha um médico e horário disponível

Buscar Médicos
setSearchTerm(e.target.value)} />
{filteredDoctors.map((doctor) => (
{/* Adapte para seu componente de avatar */}
{doctor.name ?.split(" ") .map((n: string) => n[0]) .join("")}

{doctor.name}

{doctor.specialty}

{doctor.rating || "-"}
{doctor.location || "-"}
{doctor.price || "-"}
))}
{selectedDoctor && ( Detalhes do Agendamento Consulta com {selectedDoctor.name} - {selectedDoctor.specialty} setAppointmentType(v as "presential" | "online") } > Presencial Online
date < new Date() || date.getDay() === 0 || date.getDay() === 6 } />

🔴 Finais de semana não disponíveis

{selectedDate?.toLocaleDateString("pt-BR", { weekday: "long", day: "numeric", month: "long", year: "numeric", })}

{/* Adapte para buscar horários reais da API se disponível */}
{["09:00", "10:00", "14:00", "15:00", "16:00"].map( (slot) => ( ) )}