/**
 * Monkey-patches jsPDF.prototype.save so every call goes through our
 * centralized saveFile helper, which prompts the user with a native
 * "Save As" dialog when the browser supports it.
 *
 * Imported once from src/main.tsx — do not import elsewhere.
 */
import { jsPDF } from "jspdf";
import { savePdfDoc } from "@/lib/saveFile";

const proto = (jsPDF as any).prototype as { save?: (...args: any[]) => any };

if (proto && typeof proto.save === "function" && !(proto as any).__savePatched) {
  proto.save = function patchedSave(this: any, filename?: string) {
    const name = (filename && String(filename)) || "document.pdf";
    // Fire-and-forget — preserve the original sync-ish signature.
    void savePdfDoc(this, name);
    return this;
  };
  (proto as any).__savePatched = true;
}

export {};
