import React, { useEffect, useState } from "react"; import BoutonGraphique from "./BoutonGraphique"; import { Bell } from "lucide-react"; import Slider from "@mui/material/Slider"; import { API_BASE_URL } from "../config"; import axios from "axios"; import { useAuth } from "../AuthContext"; import { useTranslation } from "react-i18next"; const identifiant = new URLSearchParams(window.location.search).get("id"); function ParticularMeteo({ type, data, Icon, texte1, texte2, graphStates, setGraphStates, graphRefs, }) { const { t } = useTranslation(); const {user} = useAuth(); const [affRegles, setAffRegles] = useState(false); const [rangeValue, setRangeValue] = useState([0, 0]); const [alerteActive, setAlerteActive] = useState(false); const minMaxValues = { temperature: [-50, 60], pressure: [940, 1060], humidity: [10, 100], }; const MIN = minMaxValues[type][0]; const MAX = minMaxValues[type][1]; const formatLabel = (value) => { switch (type) { case "temperature": return `${value}°C`; case "pressure": return `${value} hPa`; case "humidity": return `${value}%`; default: return value; } }; const marks = [ { value: MIN, label: formatLabel(MIN), }, { value: MAX, label: formatLabel(MAX), }, ]; useEffect(() => { axios.get(`${API_BASE_URL}/getRange?id=${identifiant}`).then((response) => { setRangeValue([ response.data[0][type + "_min"], response.data[0][type + "_max"], ]); }); }, [identifiant]); const color = rangeValue[0] > data[type] || rangeValue[1] < data[type] ? "text-red-600" : "text-indigo-600"; const defRangeData = () => { console.log("Données envoyées :", { id: identifiant, min: rangeValue[0], max: rangeValue[1], type, }); axios .post(`${API_BASE_URL}/modifRangeData`, { id: identifiant, idUser:user.id, min: parseFloat(rangeValue[0]), max: parseFloat(rangeValue[1]), type, }) .then((response) => { console.log("Modification réussie :", response.data); }) .catch((error) => { console.error("Erreur lors de la modification :", error); }); window.location.reload(); }; const handleChange = (event, newValue) => { setRangeValue(newValue); }; function valuetext(value) { return `${value}°C`; } if (data[type]) { return (
{t('components.particularMeteo.outOfBounds')}
)}