import { useTaehuiStore } from "@/state/Stores";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useMutation } from "@tanstack/react-query";
import { getMillis } from "taehui-lib/date";

export default function usePostDrawing() {
  const { totem } = useTaehuiStore();

  return useMutation({
    mutationFn: async ({ file }: { file: File }) => {
      const formData = new FormData();
      formData.append("data", file);
      await wwwAPI.post("/avatar/drawing", formData, {
        headers: { millis: getMillis(), totem },
      });
    },
    onSuccess: async () => {
      window.location.reload();
    },
  });
}
