import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import ConfigBox from "@/Components/v1/ConfigBox/index.jsx"; import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx"; import { useTheme } from "@emotion/react"; import { PropTypes } from "prop-types"; import { useTranslation } from "react-i18next"; const SettingsGlobalThresholds = ({ isAdmin, HEADING_SX, settingsData, setSettingsData, }) => { const { t } = useTranslation(); // For language translation const theme = useTheme(); // MUI theme access // Handles input change and updates parent state const handleChange = (e, min, max) => { const { name, value } = e.target; const numValue = parseFloat(value); const isValidNumber = value === "" || (!isNaN(numValue) && isFinite(numValue) && numValue >= min && numValue <= max); if (isValidNumber) { setSettingsData((prev) => ({ ...prev, settings: { ...prev.settings, globalThresholds: { ...prev.settings?.globalThresholds, [name]: value, }, }, })); } }; // Only render this section for admins if (!isAdmin) return null; return ( {/* Header and description */} {t("settingsPage.globalThresholds.title", "Global Thresholds")} {t( "settingsPage.globalThresholds.description", "Configure global CPU, Memory, Disk, and Temperature thresholds." )} {/* Threshold inputs */} {[ ["CPU Threshold (%)", "cpu", 1, 100], ["Memory Threshold (%)", "memory", 1, 100], ["Disk Threshold (%)", "disk", 1, 100], ["Temperature Threshold (°C)", "temperature", 1, 150], ].map(([label, name, min, max]) => ( handleChange(e, min, max)} /> ))} ); }; // Prop types SettingsGlobalThresholds.propTypes = { isAdmin: PropTypes.bool, HEADING_SX: PropTypes.object, settingsData: PropTypes.object, setSettingsData: PropTypes.func, }; export default SettingsGlobalThresholds;