import { Button } from "@mantine/core";
import { IconTrash } from "@tabler/icons-react";
import { useChoosesStore } from "../../lib/zustand/use-chooses-store";
import { useConfirmStore } from "../../lib/zustand/use-confirm";
import { deletesBid } from "../../apis/bid";

export default function DeleteRowAction({
  onDeleted,
}: {
  onDeleted?: () => void;
}) {
  const { chooses } = useChoosesStore();

  const { setConfirm } = useConfirmStore();

  const handleDelete = () => {
    setConfirm({
      handleOk: async () => {
        const result = await deletesBid(chooses);
        if (!result) return;
        onDeleted?.();
      },
      title: 'Delete',
      message: `This action will remove ${chooses.length} products.`
    });
  };

  return (
    <Button
      onClick={handleDelete}
      disabled={chooses.length <= 0}
      size={"xs"}
      color="red"
    >
      <IconTrash size={16} />
    </Button>
  );
}
