/*!
 * @file save_pdf_button.js
 * @brief Handles the "Save as PDF" button behavior for Shibuya theme
 * @details Triggers the browser's print dialog, allowing users to save the current page as PDF.
 * @author STMicroelectronics
 * @copyright Copyright (c) 2026 STMicroelectronics.
 *            All rights reserved.
 *            This software is licensed under SLA0044 terms that can be found at:
 *            https://www.st.com/SLA0044
 *            or in the LICENSE.md file in the root directory of this software component.
 */
(function() {
  const initSavePdfButton = () => {
    const btn = document.getElementById('save-pdf-btn');
    if (!btn) return;
    btn.addEventListener('click', (ev) => {
      ev.preventDefault();
      try {
        window.print();
      } catch (e) {
        console.error('[save_pdf_button] failed to trigger print:', e);
      }
    });
  };
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initSavePdfButton);
  } else {
    initSavePdfButton();
  }
})();
