import { useCallback as a } from "react";
const b = (u, n, l, o = ",") => {
  if (!u.length)
    return "";
  const s = (e) => {
    if (e == null)
      return "";
    const t = String(e), i = t.includes(o) || t.includes('"') || t.includes(`
`), r = t.replace(/"/g, '""');
    return i ? `"${r}"` : r;
  }, p = n.map((e) => s(l?.[e] ?? String(e))).join(o), d = u.map((e) => n.map((t) => s(e[t])).join(o));
  return [p, ...d].join(`
`);
}, f = () => ({ exportToCSV: a(
  ({ data: n, fileName: l = "export.csv", columns: o, headers: s, delimiter: p = ",", withBom: d = !0 }) => {
    if (!n.length)
      return;
    const e = o ?? Object.keys(n[0]), t = b(n, e, s, p), i = d ? "\uFEFF" : "", r = new Blob([i + t], { type: "text/csv;charset=utf-8;" }), c = document.createElement("a");
    c.href = URL.createObjectURL(r), c.setAttribute("download", l), document.body.appendChild(c), c.click(), document.body.removeChild(c);
  },
  []
) });
export {
  f as default
};
//# sourceMappingURL=useTableExport.js.map
