"use client"; import { useEffect, useState } from "react"; import { Sun, Sunrise, Sunset } from "lucide-react"; import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card"; import { SunTimes } from "@/app/api/sun-times/route"; export default function SunTimesWidget() { const [sunTimes, setSunTimes] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchSunTimes = async () => { try { const response = await fetch("/api/sun-times"); const data = await response.json(); setSunTimes(data); } catch (error) { console.error("Erreur lors du chargement des heures du soleil:", error); } finally { setLoading(false); } }; fetchSunTimes(); }, []); if (loading) { return (
Chargement...
); } if (!sunTimes) { return null; } const getCurrentTime = () => { const now = new Date(); return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}`; }; const currentTime = getCurrentTime(); const isDay = currentTime >= sunTimes.sunrise && currentTime < sunTimes.sunset; return ( Lever / Coucher du Soleil

Lever

{sunTimes.sunrise}

Coucher

{sunTimes.sunset}

{isDay ? "☀️ Soleil actuellement visible" : "🌙 Nuit"}

); }