<?php
if (!defined('ABSPATH')) exit;

class SIMPINBY_PDF_Actions {

  public function __construct() {
    add_action("admin_init", [$this, "handle_pdf_download"]);
  }

  public function handle_pdf_download() {
    if (!current_user_can("manage_options")) return;

    if (isset($_GET["download_pdf"]) && isset($_GET["id"])) {
      $invoice_id = intval($_GET["id"]);
      check_admin_referer("simpinby_download_pdf_" . $invoice_id);

      SIMPINBY_PDF::download_invoice_pdf($invoice_id);
    }
  }
}
