(async () => {
  const { pdfHTML, pdfTitle } = await chrome.storage.local.get(["pdfHTML", "pdfTitle"]);

  if (!pdfHTML) {
    document.getElementById("loading").innerHTML =
      '<div style="color:#ef4444;">خطا: محتوای PDF یافت نشد.</div>';
    return;
  }

  // Set title
  document.title = pdfTitle || "ChatGPT Backup";

  // Show content
  document.getElementById("content").innerHTML = pdfHTML;
  document.getElementById("content").style.display = "block";
  document.getElementById("loading").style.display = "none";
  document.getElementById("printBar").style.display = "flex";

  // Clean up storage
  chrome.storage.local.remove(["pdfHTML", "pdfTitle"]);

  // Print button
  document.getElementById("printBtn").addEventListener("click", () => window.print());

  // Auto-open print dialog
  setTimeout(() => window.print(), 600);
})();
