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

export const AgeSlider = ({ fullRange }) => {
  const {
    filters: { age },
    setAge,
  } = useWorkingPointsFilters();

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

  useEffect(() => {
    const min = fullRange.age[0];
    const max = fullRange.age[1];

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

  return (
    <Slider
      title={"Зрелость постамата, дней"}
      value={age}
      onAfterChange={handleAfterChange}
      min={fullRange.age[0]}
      max={fullRange.age[1]}
      range
    />
  );
};
