import { SliderComponent as Slider } from "../../../components/SliderComponent";
import { INITIAL, useFilters } from "../../../stores/useFilters";
import { useEffect } from "react";

export const PredictionSlider = ({ disabled, fullRange }) => {
  const {
    filters: { prediction },
    setPrediction,
  } = useFilters();

  const handleAfterChange = (range) => setPrediction(range);

  useEffect(() => {
    if (!fullRange) return;

    const min = fullRange.prediction_current[0];
    const max = fullRange.prediction_current[1];

    if (
      prediction[0] === INITIAL.prediction[0] &&
      prediction[1] === INITIAL.prediction[1]
    ) {
      setPrediction([min, max]);
    }
  }, [fullRange]);

  return (
    <Slider
      title={"Прогнозный трафик"}
      value={prediction}
      onAfterChange={handleAfterChange}
      min={fullRange?.prediction_current[0]}
      max={fullRange?.prediction_current[1]}
      range
      disabled={disabled}
    />
  );
};
