import { Discount } from "@/interfaces/paypal";
import { Code, Group, User } from "@/interfaces/user";
import axios from "axios";
import { useEffect, useState } from "react";

export default function useDiscounts(creator?: string) {
  const [discounts, setDiscounts] = useState<Discount[]>([]);
  const [isLoading, setIsLoading] = useState(false);
  const [isError, setIsError] = useState(false);

  const getData = () => {
    setIsLoading(true);
    axios
      .get<Discount[]>("/api/discounts")
      .then((response) => setDiscounts(response.data))
      .finally(() => setIsLoading(false));
  };

  useEffect(getData, [creator]);

  return { discounts, isLoading, isError, reload: getData };
}
