import { useState, useEffect } from "react";
import { useDispatch } from "react-redux";
import { slaughterGetCars } from "../../slaughter-house/services/slaughter-get-cars";

export const useSlaughterHouseCars = (id, killHouseKey, killRequestKey) => {
  const dispatch = useDispatch();
  // const { slaughterHouseCars } = useSelector((state) => state.slaughterSlice);
  const [data, setData] = useState([]);

  useEffect(() => {
    if (id) {
      dispatch(slaughterGetCars({ id, killHouseKey, killRequestKey })).then(
        (r) => setData(r.payload.data)
      );
    } else {
      dispatch(slaughterGetCars()).then((r) => setData(r.payload.data));
    }
  }, []);

  // useEffect(() => {
  //   setData(slaughterHouseCars);
  // }, [slaughterHouseCars]);

  return data ? data : [];
};
