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

export const FactTrafficSlider = ({ fullRange }) => {
  const {
    filters: { factTraffic },
    setFactTraffic,
  } = useFilters();

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

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

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

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

  return (
    <Slider
      title={"Фактический трафик"}
      value={factTraffic}
      onAfterChange={handleAfterChange}
      min={fullRange?.fact[0]}
      max={fullRange?.fact[1]}
      range
    />
  );
};
