import React, { useState, useEffect } from "react";
import {
UserPlus,
LogIn,
BadgePlus,
RadioTower,
Search,
Cloud,
CloudRain,
Droplets,
Wind,
Thermometer,
Sun,
Moon,
MapPin,
CalendarClock,
ArrowRight,
BellRing,
LayoutDashboard,
TowerControl,
} from "lucide-react";
import { useAuth } from "../AuthContext";
import axios from "axios";
import { useTranslation } from "react-i18next";
import { API_BASE_URL } from "../config";
function EnhancedWeatherHome() {
const { t } = useTranslation();
const [searchQuery, setSearchQuery] = useState("");
const [locations, setLocations] = useState([]);
const [infoMeteo, setInfoMeteo] = useState([]);
const [activeFilter, setActiveFilter] = useState("all");
const [currentTime, setCurrentTime] = useState(new Date());
const { user, token } = useAuth();
const [ville, setVille] = useState("Paris, France");
const heure = currentTime.getHours();
const isDayTime = heure > 6 && heure < 20;
useEffect(() => {
const timer = setInterval(() => {
setCurrentTime(new Date());
}, 60000);
return () => clearInterval(timer);
}, []);
useEffect(() => {
axios
.post(`${API_BASE_URL}/getMeteoHome`, {
location: ville,
})
.then((response) => {
if (response.data.length === 0) {
console.warn("Aucun infos disponible.");
} else {
console.log(response.data[0]);
setInfoMeteo(response.data[0]);
}
})
.catch((error) => {
console.error("Erreur lors de la récupération des infos :", error);
});
}, [ville]);
useEffect(() => {
axios
.get(`${API_BASE_URL}/getLocations`)
.then((response) => {
if (response.data.length === 0) {
console.warn("Aucun lieu disponible.");
} else {
console.log(response.data);
setLocations(response.data);
}
})
.catch((error) => {
console.error("Erreur lors de la récupération des catégories :", error);
});
}, []);
const filteredLocations = locations.filter((loc) =>
loc.toLowerCase().includes(searchQuery.toLowerCase())
);
const formatDate = (date) => {
const options = { weekday: "long", day: "numeric", month: "long" };
return date.toLocaleDateString("fr-FR", options);
};
const formatHeure = (h) => {
const heureFormatee = (h % 24).toString().padStart(2, "0");
return `${heureFormatee}:00`;
};
const hourlyForecast = [
{
time: "Maintenant",
temp: "22°",
icon:
{t('home.subtitle')}
{formatDate(currentTime)}
{t('home.partlyCloudy')}
{t('home.feelsLike')}
{t('home.humidity')}
{t('home.wind')}
{t('home.rain')}
{t('home.sunrise')}
{t('home.sunset')}
{item.time}
{item.icon}{item.temp}