import { useState } from "react";
import { Button, Tooltip } from "antd";
import { DownloadOutlined } from "@ant-design/icons";
import { download } from "../../utils";

export const handleExportSuccess = (data) => {
  download("postamates.xlsx", data);
};

export const ExportButton = ({ provider }) => {
  const [startExport, setStartExport] = useState(false);

  provider(startExport, () => setStartExport(false));

  const handleExport = (e) => {
    e.stopPropagation();
    setStartExport(true);
  };

  return (
    <Tooltip title="Скачать данные">
      <Button
        onClick={handleExport}
        loading={startExport}
        disabled={startExport}
      >
        <DownloadOutlined />
      </Button>
    </Tooltip>
  );
};
