{"version":3,"file":"excelDownload-C-Qcu2fl.cjs","names":[],"sources":["../src/Utils/excelDownload.ts"],"sourcesContent":["import FileSaver from 'file-saver';\r\nimport * as XLSX from 'xlsx';\r\n\r\ninterface WsColInterface {\r\n  wch: number;\r\n}\r\n/**\r\n * Downloads CSV data as an Excel file with specified headers and column widths.\r\n *\r\n * The function converts JSON data (`csvData`) to an Excel sheet, adds headers, and applies custom column widths.\r\n * The resulting file is then downloaded using `file-saver` as an `.xlsx` file.\r\n *\r\n * @param csvData - The data to be exported as an Excel sheet, represented as an array of objects.\r\n * @param fileName - The name of the file to be downloaded (without extension).\r\n * @param headers - The headers for the Excel sheet.\r\n * @param xlsxHeader - The header data to be used for the Excel file (should match `headers`).\r\n * @param wscols - The column width configuration, where each item corresponds to a column.\r\n *\r\n * @example\r\n * const data = [{ name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }];\r\n * const headers = ['name', 'age'];\r\n * const xlsxHeader = {\r\n *  name: \"Full Name\",\r\n *  age: \"Age\",\r\n * };\r\n * const columnWidths = [{ wch: 10 }, { wch: 5 }];\r\n * excelDownload(data, 'user_data', headers, xlsxHeader, columnWidths);\r\n */\r\n\r\nexport const excelDownload = (\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  csvData: any,\r\n  fileName: string,\r\n  headers: string[],\r\n  xlsxHeader: {\r\n    [key: string]: string;\r\n  },\r\n  wscols: WsColInterface[],\r\n) => {\r\n  const fileType =\r\n    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';\r\n  const ws = XLSX.utils.json_to_sheet([xlsxHeader], {\r\n    header: headers,\r\n    skipHeader: true,\r\n  });\r\n\r\n  ws['!cols'] = wscols;\r\n  XLSX.utils.sheet_add_json(ws, csvData, {\r\n    header: headers,\r\n    skipHeader: true,\r\n    origin: -1,\r\n  });\r\n  const wb = { Sheets: { data: ws }, SheetNames: ['data'] };\r\n  const excelBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });\r\n  const dataForExcel = new Blob([excelBuffer], { type: fileType });\r\n  FileSaver.saveAs(dataForExcel, `${fileName}.xlsx`);\r\n};\r\n"],"mappings":"gHA6BA,IAAa,GAEX,EACA,EACA,EACA,EAGA,IACG,CACH,IAEM,EAAK,EAAK,MAAM,cAAc,CAAC,CAAU,EAAG,CAChD,OAAQ,EACR,WAAY,EACd,CAAC,EAED,EAAG,SAAW,EACd,EAAK,MAAM,eAAe,EAAI,EAAS,CACrC,OAAQ,EACR,WAAY,GACZ,OAAQ,EACV,CAAC,EACD,IAAM,EAAK,CAAE,OAAQ,CAAE,KAAM,CAAG,EAAG,WAAY,CAAC,MAAM,CAAE,EAClD,EAAc,EAAK,MAAM,EAAI,CAAE,SAAU,OAAQ,KAAM,OAAQ,CAAC,EAChE,EAAe,IAAI,KAAK,CAAC,CAAW,EAAG,CAAE,KAAM,iFAAS,CAAC,EAC/D,EAAA,QAAU,OAAO,EAAc,GAAG,EAAS,MAAM,CACnD"}