import { saveAs as e } from "file-saver";
//#region src/lib/utils/excel-reader.ts
function t(e) {
	return new Promise((t, n) => {
		let r = new FileReader();
		r.onload = async function(e) {
			try {
				let { default: n } = await import("./xlsx-DmWbdnhm.js").then((e) => e.t), r = e.target.result, i = n.read(r, { type: "string" }), a = i.SheetNames[0];
				if (!a) {
					t("[]");
					return;
				}
				let o = i.Sheets[a];
				if (!o) {
					t("[]");
					return;
				}
				let s = n.utils.sheet_to_json(o);
				t(JSON.stringify(s));
			} catch (e) {
				n(e);
			}
		}, r.onerror = (e) => n(e), r.readAsArrayBuffer(e);
	});
}
function n({ sheets: t, fileName: n = "data.xlsx" }) {
	import("./xlsx-DmWbdnhm.js").then((e) => e.t).then(({ default: r }) => {
		let i = r.utils.book_new();
		t.forEach((e) => {
			let { sheetName: t, jsonData: n, fields: a, fieldLabels: o, formatMap: s } = e, c = n.map((e) => {
				let t = {};
				for (let n of a) {
					let r = e[n], i = s?.[n];
					t[n] = i ? i(r, e) : r;
				}
				return t;
			}), l = r.utils.json_to_sheet(c, { header: a });
			if (o) {
				let e = a.map((e) => o[e] || e);
				r.utils.sheet_add_aoa(l, [e], { origin: "A1" });
			}
			r.utils.book_append_sheet(i, l, t);
		});
		let a = r.write(i, {
			bookType: "xlsx",
			type: "array"
		});
		e(new Blob([a], { type: "application/octet-stream" }), n);
	});
}
//#endregion
export { t as n, n as t };
