const { contextBridge, ipcRenderer } = require("electron");

contextBridge.exposeInMainWorld("electronAPI", {
  // 获取PDF（绕过CORS）
  fetchPdf: (pdfUrl) => ipcRenderer.invoke("fetch-pdf", pdfUrl),
  // 打印PDF
  printPdf: (pdfUrl, options) => ipcRenderer.invoke("print-pdf", pdfUrl, options),
  // 获取打印机列表
  getPrinters: () => ipcRenderer.invoke("get-printers"),
  startIdCardListen: () => ipcRenderer.invoke("start_idcard_listen"),
  stopIdCardListen: () => ipcRenderer.invoke("stop_idcard_listen"),
  onIdCardData: (callback) =>
    ipcRenderer.on("idcard-data", (event, value) => callback(value)),
  onIdCardError: (callback) =>
    ipcRenderer.on("idcard-error", (event, value) => callback(value)),
  log: (level, message) => ipcRenderer.send("log-message", { level, message }),
  removeIdCardListeners: () => {
    ipcRenderer.removeAllListeners("idcard-data");
    ipcRenderer.removeAllListeners("idcard-error");
  },
});
