import { jsPDF } from "jspdf";

/**
 * This function generate a pdf with a secret key for a user.
 */
function generateBackupPDF(personalName, personalEmail, generatedKey) {
  const imgData =
    "data:image/png;base64,[encoded data, 38816 characters]";

  // new jsPDF('p', 'mm', [297, 210]);
  var today = new Date();
  var dd = String(today.getDate()).padStart(2, "0");
  var mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
  var yyyy = today.getFullYear();

  today = mm + "/" + dd + "/" + yyyy;

  var doc = new jsPDF("p", "pt");
  doc.setFillColor(13, 17, 23);
  doc.rect(0, 0, 600, 900, "F");
  doc.setTextColor(227, 227, 227);
  doc.addImage(imgData, "png", 30, 35, 535, 72);
  doc.addFont("helvetica", "normal");
  doc.setFontSize(12);
  doc.text(
    290,
    130,
    "Created for " + personalName + " on " + today + ".",
    "center"
  );
  doc.setFontSize(14);
  doc.text(
    32,
    180,
    "In case you get locked out of you Infisical account, you`ll need these account details"
  );
  doc.text(32, 200, "to sign in —");
  doc.setFont(undefined, "bold");
  doc.text(
    110,
    200,
    "including your Secret Key, which we absolutely cannot access or"
  );
  doc.text(32, 220, "recover for you. ");
  doc.setFont(undefined, "normal");
  doc.text(32, 250, "Recommendations:");
  doc.text(
    32,
    280,
    "1. We recommend to get your Emergency Kit off your computer and print a copy."
  );
  doc.text(
    32,
    310,
    "2. Store it somewhere safe (such as with your birth certificate, your will, or on your"
  );
  doc.text(32, 330, "personal cloud storage).");
  doc.setFillColor(206, 217, 111);
  doc.roundedRect(32, 350, 530, 190, 5, 5, "F");
  doc.setDrawColor(228, 255, 0);
  doc.setLineWidth(1);
  doc.roundedRect(32, 350, 530, 190, 5, 5, "S");
  doc.setTextColor(43, 43, 43);
  doc.setFont(undefined, "bold");
  doc.setFontSize(15);
  doc.text(290, 375, "Infisical Account Details", "center");
  doc.setFont(undefined, "normal");
  doc.setFontSize(12);
  doc.text(50, 420, "SIGN-IN URL");
  doc.text(50, 465, "EMAIL ADDRESS");
  doc.text(50, 510, "SECRET KEY");
  doc.setFillColor(23, 27, 33);
  doc.roundedRect(170, 398, 375, 35, 5, 5, "F");
  doc.roundedRect(170, 443, 375, 35, 5, 5, "F");
  doc.roundedRect(170, 488, 375, 35, 5, 5, "F");
  doc.setTextColor(227, 227, 227);
  doc.setFontSize(14);
  doc.text(180, 420, "https://app.infisical.com/login");
  doc.text(180, 465, personalEmail);
  doc.text(180, 510, generatedKey);
  doc.text(32, 575, "Need help? Contact us at support@infisical.com");

  doc.save("Infisical Emergency Kit.pdf");
}

export default generateBackupPDF;
