import { save } from "@tauri-apps/plugin-dialog"; import { api } from "./api"; import { flattenInBrowser } from "./browserFlatten"; import type { ExportDeps } from "./exportFlow"; import { renderInvoicePdf } from "./pdf"; import { getRenderClient, nextRenderJobId } from "./renderClient"; import type { BankAccount, Settings } from "./types"; /** The real collaborators of the export flow: Tauri commands, the render client, pdf.js and the save dialog. */ export function createExportDeps(ctx: { settings: Settings; bank: BankAccount | null }): ExportDeps { return { issueInvoice: (input, renderPrefs) => api.issueInvoice(input, renderPrefs), render: async (invoice) => { const { bytes, fingerprint } = await renderInvoicePdf(invoice, ctx.settings, ctx.bank); return { bytes, fingerprint }; }, archivePdf: api.archivePdf, readArchive: api.readArchive, flatten: (bytes, opts) => flattenInBrowser(bytes, opts), assemble: async (pages, title) => (await getRenderClient().assemble({ id: nextRenderJobId(), pages, title })).bytes, getLastExportDir: api.getLastExportDir, save: ({ defaultPath }) => save({ defaultPath, filters: [{ name: "PDF document", extensions: ["pdf"] }] }), writeExportFile: api.writeExportFile, }; }