import { saveAs } from "file-saver"; import { _4X4Cert } from "./certs/4X4"; import { CertData } from "./certs/CertData"; import { matpelCert } from "./certs/MATPEL"; import { Matpel } from "./certs/utils"; import { manejoDefensivoCert } from "./certs/MANEJO_DEFENSIVO"; import { mecanicaBasicaCert } from "./certs/MECANICA_BASICA"; import { segOpMaqPesCert } from "./certs/SEG_OP_MAQ_PES"; import { supervisorEscolta } from "./certs/SUPERVISOR_ESCOLTA"; import { ipercCert } from "./certs/IPERC"; declare global { interface Window { // eslint-disable-next-line @typescript-eslint/no-explicit-any docx: any, } } async function download(document: Document, filename: string = "filename.docx") { const blob = await window.docx.Packer.toBlob(document); saveAs(blob, filename); } const certGeneratorGenerator = (generatorFn: (options: CertData) => Promise) => (options: CertData, filename: string) => { generatorFn(options) .then((doc) => { download(doc, filename); }); }; export const certGenerator = Object.freeze({ matpel1: (options: CertData, filename: string) => { const options_f: CertData = { ...options, matpel: Matpel._1, }; matpelCert(options_f) .then((doc) => { download(doc, filename); }); }, matpel2: (options: CertData, filename: string) => { const options_f: CertData = { ...options, matpel: Matpel._2, }; matpelCert(options_f) .then((doc) => { download(doc, filename); }); }, matpel3: (options: CertData, filename: string) => { const options_f: CertData = { ...options, matpel: Matpel._3, }; matpelCert(options_f) .then((doc) => { download(doc, filename); }); }, manejoDefensivo: certGeneratorGenerator(manejoDefensivoCert), mecanicaBasica: certGeneratorGenerator(mecanicaBasicaCert), "4x4": certGeneratorGenerator(_4X4Cert), segOpMaqPes: certGeneratorGenerator(segOpMaqPesCert), supervisorEscolta: certGeneratorGenerator(supervisorEscolta), iperc: certGeneratorGenerator(ipercCert), });