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

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

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

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

    const min = fullRange.age_day[0];
    const max = fullRange.age_day[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_day[0]}
      max={fullRange?.age_day[1]}
      range
    />
  );
};
