import type { RowState } from "../grid/rowModel";
import type { MarketData } from "../market/sx5e";
import { isoDate } from "../pricing";
import { buildPricerWorkbook } from "./pricerWorkbook";
/** Builds the pricer workbook in the browser and downloads it (ExcelJS is loaded on demand). */
export async function downloadPricerXlsx(market: MarketData, rows: RowState[]): Promise<void> {
// the prebuilt browser bundle: the package's Node entry pulls in Node-only dependencies
const Excel = (await import("exceljs/dist/exceljs.min.js")).default;
const buffer = await buildPricerWorkbook(Excel, market, rows).xlsx.writeBuffer();
const blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `funding-pricer_${isoDate(market.valuationDate)}.xlsx`;
a.click();
URL.revokeObjectURL(url);
}