"use client";
import React from "react";
import {Button} from "./ui/button";
import {Trash} from "lucide-react";
import {useDeleteFile} from "@/hooks";
import {handleAxiosError} from "@/lib/utils";
import {toast} from "react-toastify";

export default function DeleteFileButton({
  type,
  fileKey,
  fileUrl,
}: {
  type: "image" | "document";
  fileKey: string;
  fileUrl: string;
}) {
  const {mutateAsync} = useDeleteFile();

  const handleDeleteThumbnail = async () => {
    try {
      const {message} = await mutateAsync({fileKey, fileUrl, type});
      toast.success(message);
    } catch (error) {
      toast.error(handleAxiosError(error));
    }
  };
  return (
    <>
      <Button
        type="button"
        variant={"destructive"}
        className="text-white absolute top-2 left-2 z-10"
        onClick={handleDeleteThumbnail}
      >
        <Trash />
      </Button>
    </>
  );
}
