var formatValue = function formatValue(value) {
  if (value === null || value === undefined) return "-";
  if (typeof value === "object") return JSON.stringify(value);
  return value;
};
var convertToCSV = function convertToCSV(data) {
  return data.reduce(function (h, row) {
    return h + row.map(formatValue).join(",") + "\n";
  }, "");
};
export default (function (name) {
  if (name === void 0) {
    name = "netdata";
  }
  return function (_, table) {
    var data = [table.getFlatHeaders().map(function (header) {
      return header.id;
    })];
    table.getRowModel().rows.forEach(function (row) {
      data.push(table.getFlatHeaders().map(function (header) {
        return row.renderValue(header.id);
      }));
    });
    var url = window.URL.createObjectURL(new Blob([convertToCSV(data)], {
      type: "text/csv;charset=utf-8;"
    }));
    var link = document.createElement("a");
    link.href = url;
    var fileName = name + ".csv";
    link.setAttribute("download", fileName);
    document.body.appendChild(link);
    link.click();
    link.remove();
  };
});