<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

// ======================================================
// 🏛️ NYLTA.com Pre-Registration Certificate Generator
// ======================================================

require_once __DIR__ . '/vendor/autoload.php';

// ------------------------------------------------------
// 1. Get parameters from URL
// ------------------------------------------------------
$llc_name = $_GET['llc_name'] ?? '';
$registrant_name = $_GET['registrant_name'] ?? '';

if (empty($llc_name) || empty($registrant_name)) {
    die('Error: Both "llc_name" and "registrant_name" are required in the URL.');
}

$llc_name = htmlspecialchars($llc_name, ENT_QUOTES, 'UTF-8');
$registrant_name = htmlspecialchars($registrant_name, ENT_QUOTES, 'UTF-8');
date_default_timezone_set('America/New_York');
$date_issued = $_GET['month'] . ' ' . $_GET['date'] . ', ' . $_GET['year'] . ' at ' . $_GET['time'];

// ------------------------------------------------------
// 2. Inline icons
// ------------------------------------------------------

// ------------------------------------------------------
// 3. Build HTML
// ------------------------------------------------------
$llc_name = str_replace(' ', '&nbsp;', $llc_name);
$fontSize = strlen($llc_name) > 30 ? 32 : 42; // auto shrink if long

$html = '
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>NYLTA.com Pre-Registration Certificate</title>
  <style>
    @page {
      margin: 50px;
      background-image: url("http://certificate.nylta.com/bg-certificate-min.jpg");
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
      background-color: #fff;
    }

    body {
      font-family: "poppins", sans-serif;
      line-height: 1.5;
      color: #222;
    }
    h1, h2, h3 {
      font-family: "librebaskerville", serif;
      color: #000;
      margin-bottom: 5px;
    }
    ul {
      margin-top: 5px;
      padding-left: 15px;
      list-style: none;
    }
    .medium {
      font-family: "poppinsmedium";
    }
  </style>
</head>
<body>
<div style="display: flex; flex-direction: row;">
  <div align="left" style="width: 20%; float: left;">
  <p>&nbsp;</p>
  </div>
  <div style="width: 60%; float: left; text-align: center;">
  <h3 style="margin: 0; text-align: center; font-size: 36px; text-transform: uppercase; color: #02316a; font-weight: bold;">Pre-Registration</h3>
  <h6 style="margin: 0 auto 20px; text-align: center; font-size: 16px; text-transform: uppercase; color: #ffffff; background: #02316a; padding: 4px 20px; border-radius: 50px; width: 180px;">certificate</h6>
</div>
  <div style="width: 20%; float: left; text-align: right;">
  <img 
    src="http://certificate.nylta.com/icons/badge_ribbon.png" 
    width="80" 
    style="display: block; margin: 0 0 0 auto; padding: 0 20px 0 0" 
  />
  </div>
</div>
<p style="margin: 0 0 8px; text-align: center; font-size: 16px; color: #02316a;" class="medium">This certifies that</p>
<h1 style="margin: 0; text-align: center; font-size:' . $fontSize . 'px; line-height: 36px; text-transform: uppercase; color: #02316a; font-weight: normal; white-space: nowrap;">' . $llc_name . '</h1>
<h2 style="margin: 0; text-align: center; font-size: 36px; text-transform: uppercase; color: #02316a; font-weight: normal;">' . $registrant_name . '</h2>
<p style="margin: 0 0 8px; text-align: center; font-size: 16px; color: #02316a;" class="medium">has successfully pre-registered with NYLTA.com to prepare and submit their<br>
  New York LLC Transparency Act (NYLTA) disclosure filing when the law takes<br> effect on January 1, 2026.
</p>
<p style="margin: 0; text-align: center; font-size: 7px; color: #02316a; font-weight: bold;">Pre-Registration Benefits</p>
<ul style="margin: 0 0 10px; text-align: center; font-size: 7px; color: #02316a; list-style: none; font-weight: normal;">
  <li>Priority placement in our filing queue on January 1, 2026</li>
  <li>Free updates on NYLTA compliance requirements</li>
  <li>Early access to reminders and support resources</li>
</ul>
<p style="margin: 0; text-align: center; font-size: 10px; color: #02316a;" class="medium">' . $date_issued . '</p>
<div style="display: flex; flex-direction: row;">
  <div align="left" style="width: 33.333%; float: left;">
    <div align="left" style="width: 90%; float: left;">
    <p style="margin: 0; font-size: 7px; color: #545454; font-weight: bold; text-decoration: underline;">Important Notes:</p>
    <ul style="margin: 0; font-size: 7px; color: #545454; list-style: none; padding: 0; font-weight: normal;">
      <li>This certificate confirms your pre-registration only.</li>
      <li><span style="font-weight: bold;">No payment has been collected</span> at this stage. Filing will be completed once the New York Department of State portal opens on January 1, 2026 and payment is submitted.</li>
      <li>NYLTA.com is a private compliance technology platform, not affiliated with the New York Department of State.</li>
    </ul>
    </div>
    <p style="margin: 0; font-size: 7px; color: #545454;  font-weight: normal;">
      <span style="font-weight: bold;">Corporate Office:</span> 66 W Flagler St, STE 900-11220, Miami, FL 33130<br>
      <span style="font-weight: bold;">Correspondence & Processing:</span> 1060 Broadway #1192, Albany, NY 12204
    </p>
    <p style="margin: 0; font-size: 7px; color: #545454;">
    <img src="http://certificate.nylta.com/icons/envelope.png" width="8" style="display: block; margin: 0 4px 0 0;"/>
    <a href="mailto:support@nylta.com" style="color:#333;text-decoration:none;">support@nylta.com</a>
    </p>
  </div>
  <div style="width: 33.333%; float: left; text-align: center;">
  <p style="margin: 30px 0 5px; font-size: 10px; color: #02316a; font-weight: bold;">Issued by:</p>
  <img 
    src="http://certificate.nylta.com/logo-v2.png" 
    width="140" 
    style="display: block; margin: 0 auto;" 
  />
</div>

  <div align="left" style="width: 33.333%; float: left;">
  </div>
</div>

</body>
</html>
';

// ------------------------------------------------------
// 4. Register fonts & generate PDF
// ------------------------------------------------------
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];

$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8',
    'format' => [222.26, 156.10],
    'margin_top' => 0,
    'margin_bottom' => 0,
    'margin_left' => 0,
    'margin_right' => 0,
    'fontDir' => array_merge($fontDirs, [__DIR__ . '/fonts']),
    'fontdata' => $fontData + [
            'poppins' => [
                'R' => 'Poppins-Regular.ttf',
                'B' => 'Poppins-Bold.ttf',
            ],
            'poppinsmedium' => [ // 👈 new font alias
                'R' => 'Poppins-Medium.ttf',
            ],
            'librebaskerville' => [
                'R' => 'LibreBaskerville-Regular.ttf',
                'B' => 'LibreBaskerville-Bold.ttf',
            ],
        ],
    'default_font' => 'poppins',
]);

// ✅ Optional watermark
$mpdf->SetWatermarkImage(
    'http://certificate.nylta.com/logo-v2.png',
    0.1,
    [100, 35],
    [50, 55]
);
$mpdf->showWatermarkImage = true;

// Write the HTML
$mpdf->WriteHTML($html);

// ------------------------------------------------------
// 5. Output as downloadable file
// ------------------------------------------------------
$filename = "NYLTA_PreRegistration_" . preg_replace('/[^A-Za-z0-9_-]/', '', $registrant_name) . ".pdf";
$mpdf->Output($filename, 'D');
?>