<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
// phpcs:disable WordPress.Security.NonceVerification
// phpcs:disable WordPress.Security.ValidatedSanitizedInput
// phpcs:disable WordPress.WP.EnqueuedResourceParameters
// phpcs:disable WordPress.PHP.DevelopmentFunctions
// phpcs:disable WordPress.DB.PreparedSQL
// phpcs:disable WordPress.DB.PreparedSQLPlaceholders
// phpcs:disable WordPress.DB.DirectDatabaseQuery
// phpcs:disable WordPress.DB.SlowDBQuery
// phpcs:disable PluginCheck.Security.DirectDB
// phpcs:disable PluginCheck.CodeAnalysis
// phpcs:disable WordPressVIPMinimum

/**
 * Email: License Purchased
 * Variables available:
 *   $customer_name    string
 *   $customer_email   string
 *   $order_id         string|int
 *   $amount           string  (numeric, no $)
 *   $license_keys     array   (all keys in order)
 *   $license_key      string|array (single or array)
 *   $license_type     string  'subscription' | 'lifetime'  (default 'subscription')
 *   $purchase_date    string  e.g. 'March 8, 2026'
 *   $renewal_date     string  e.g. 'March 8, 2027'  (subscriptions only)
 *   $products         array   [{name, type('pack'|'bundle'|'subscription')}]
 */
if ( ! defined( 'ABSPATH' ) ) exit;

$display_name  = ! empty( $customer_name )  ? esc_html( $customer_name )  : 'there';
$display_email = ! empty( $customer_email ) ? esc_html( $customer_email ) : '';
$display_order = ! empty( $order_id )       ? esc_html( $order_id )       : '—';
$display_amt   = ! empty( $amount )         ? '$' . esc_html( $amount )   : '—';
$lic_type      = ! empty( $license_type )   ? $license_type               : 'subscription';
$purchase_dt   = ! empty( $purchase_date )  ? esc_html( $purchase_date )  : esc_html( gmdate( 'F j, Y' ) );
$renewal_dt    = ! empty( $renewal_date )   ? esc_html( $renewal_date )   : '';
$is_subscription = ( $lic_type === 'subscription' );
$products_list = ! empty( $products ) && is_array( $products ) ? $products : [];

// Normalise license keys
if ( ! empty( $license_keys ) && is_array( $license_keys ) )      { $keys = array_values( array_filter( array_map( 'sanitize_text_field', $license_keys ) ) ); }
elseif ( ! empty( $license_key ) && is_array( $license_key ) )    { $keys = array_values( array_filter( array_map( 'sanitize_text_field', $license_key ) ) ); }
elseif ( ! empty( $license_key ) )                                 { $keys = [ sanitize_text_field( $license_key ) ]; }
else                                                               { $keys = []; }

$keys      = array_slice( $keys, 0, 100 );
$key_count = count( $keys );
$is_bulk   = $key_count > 1;
?><!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>Your GT BOGO Engine PRO License</title></head>
<body style="margin:0;padding:0;background-color:#070C1C;">
<table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#070C1C" style="background-color:#070C1C;padding:0;">
<tr><td align="center" style="padding:32px 16px 48px 16px;">
<table width="620" cellpadding="0" cellspacing="0" border="0" style="max-width:620px;width:100%;background-color:#070C1C;">

<!-- TOP RED BAR -->
<tr><td><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="height:5px;background:#E10000;font-size:0;line-height:0;">&nbsp;</td></tr></table></td></tr>

<!-- LOGO HEADER -->
<tr><td style="background-color:#070C1C;padding:40px 48px 32px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;">
  <table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>
    <td style="vertical-align:middle;width:80px;">
      <?php // phpcs:ignore PluginCheck.CodeAnalysis.Offloading.OffloadedContent ?>
      <img src="https://graphictshirts.shop/bogo/icon-128x128.png" width="72" height="72" alt="GT BOGO Engine" style="display:block;border-radius:10px;" />
    </td>
    <td style="vertical-align:middle;padding-left:20px;">
      <p style="margin:0 0 3px 0;font-family:Georgia,'Times New Roman',serif;font-size:24px;font-weight:700;color:#ffffff;letter-spacing:0.5px;line-height:1;">GT BOGO ENGINE</p>
      <p style="margin:0 0 5px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;color:#E10000;letter-spacing:3px;text-transform:uppercase;line-height:1;">for WooCommerce — PRO</p>
      <p style="margin:0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:10px;font-weight:700;color:#2a4a6a;letter-spacing:3px;text-transform:uppercase;line-height:1;">Enterprise Edition</p>
    </td>
  </tr></table>
</td></tr>

<!-- RED RULE -->
<tr><td style="padding:0 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;"><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="height:1px;background:#E10000;font-size:0;line-height:0;">&nbsp;</td></tr></table></td></tr>

<!-- HERO -->
<tr><td style="background-color:#070C1C;padding:44px 48px 40px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;">
  <p style="margin:0 0 10px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;letter-spacing:4px;text-transform:uppercase;color:#E10000;">License <?php echo esc_html( $is_bulk ) ? 'Order' : 'Confirmed'; ?></p>
  <h1 style="margin:0 0 20px 0;font-family:Georgia,'Times New Roman',serif;font-size:42px;font-weight:700;color:#ffffff;letter-spacing:-0.5px;line-height:1.15;"><?php echo esc_html( $is_bulk ) ? 'Your ' . esc_html( $key_count ) . ' Licenses<br>Are Ready.' : 'Your License<br>Is Ready.'; ?></h1>
  <p style="margin:0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:17px;font-weight:600;color:#8ab0d0;line-height:1.7;">Hi <strong style="color:#ffffff;"><?php echo esc_html( $display_name ); ?></strong> — thank you for your purchase. <?php echo esc_html( $is_bulk ) ? 'All ' . esc_html( $key_count ) . ' license keys are listed below.' : 'Your license key is below.'; ?> Keep <?php echo esc_html( $is_bulk ) ? 'them' : 'it'; ?> somewhere safe.</p>
</td></tr>

<!-- LICENSE KEYS -->
<tr><td style="background-color:#050a16;padding:40px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;border-top:1px solid #0f1a30;">
  <p style="margin:0 0 24px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;letter-spacing:4px;text-transform:uppercase;color:#E10000;"><?php echo esc_html( $is_bulk ) ? 'License Keys — ' . esc_html( $key_count ) . ' Total' : 'Your License Key'; ?></p>
  <?php if ( $is_bulk ) : ?>
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <?php foreach ( $keys as $idx => $k ) : ?>
    <tr><td style="padding:<?php echo $idx === 0 ? '0' : '16px'; ?> 0 16px 0;<?php echo $idx > 0 ? 'border-top:1px solid #0f1a30;' : ''; ?>">
      <table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>
        <td style="vertical-align:middle;width:36px;"><p style="margin:0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:12px;font-weight:700;color:#2a4a6a;"><?php echo esc_html( str_pad( $idx + 1, 2, '0', STR_PAD_LEFT   )); ?></p></td>
        <td style="vertical-align:middle;padding-left:18px;border-left:3px solid #E10000;"><p style="margin:0;font-family:'Courier New',Courier,monospace;font-size:17px;font-weight:700;color:#ffffff;letter-spacing:2px;word-break:break-all;line-height:1.5;"><?php echo esc_html( $k ); ?></p></td>
      </tr></table>
    </td></tr>
    <?php endforeach; ?>
    </table>
  <?php else : ?>
    <p style="margin:0;font-family:'Courier New',Courier,monospace;font-size:22px;font-weight:700;color:#ffffff;letter-spacing:3px;word-break:break-all;line-height:1.6;border-left:4px solid #E10000;padding-left:22px;"><?php echo esc_html( $keys[0] ?? '' ); ?></p>
  <?php endif; ?>
</td></tr>

<!-- ORDER DETAILS -->
<tr><td style="background-color:#070C1C;padding:40px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;border-top:1px solid #0f1a30;">
  <p style="margin:0 0 22px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;letter-spacing:4px;text-transform:uppercase;color:#E10000;">Order Details</p>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;width:40%;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">Order ID</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#ffffff;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;"><?php echo esc_html( $display_order ); ?></td>
    </tr>
    <?php if ( ! empty( $products_list ) ) : ?>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;vertical-align:top;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">Products</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#ffffff;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">
        <?php foreach ( $products_list as $prod ) : ?>
          <div><?php echo esc_html( $prod['name'] ?? '' ); ?></div>
        <?php endforeach; ?>
      </td>
    </tr>
    <?php endif; ?>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">Quantity</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#ffffff;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;"><?php echo esc_html( $key_count ); ?> license<?php echo $key_count > 1 ? 's' : ''; ?></td>
    </tr>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">Amount</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#ffffff;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;"><?php echo esc_html( $display_amt ); ?></td>
    </tr>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">Purchase Date</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#ffffff;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;"><?php echo esc_html( $purchase_dt ); ?></td>
    </tr>
    <?php if ( $is_subscription ) : ?>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">License Type</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">
        <span style="background:rgba(59,130,246,0.1);border:1px solid rgba(59,130,246,0.3);color:#93c5fd;padding:2px 10px;border-radius:50px;font-size:12px;font-weight:700">Annual — 1 Year</span>
      </td>
    </tr>
    <?php if ( $renewal_dt ) : ?>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">Renewal Date</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#ffffff;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;"><?php echo esc_html( $renewal_dt ); ?></td>
    </tr>
    <?php endif; ?>
    <?php else : ?>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">License Type</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;text-align:right;border-bottom:1px solid #0f1a30;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">
        <span style="background:rgba(34,197,94,0.08);border:1px solid rgba(34,197,94,0.05);color:#86efac;padding:2px 10px;border-radius:50px;font-size:12px;font-weight:700">Lifetime</span>
      </td>
    </tr>
    <?php endif; ?>
    <tr>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#4a6a8a;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">Valid For</td>
      <td style="padding:13px 0;font-size:15px;font-weight:700;color:#ffffff;text-align:right;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;">1 website at a time</td>
    </tr>
  </table>

  <!-- STATEMENT DESCRIPTOR NOTE -->
  <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-top:24px;">
    <tr>
      <td style="padding:2px 0 2px 18px;border-left:2px solid #1e3a5f;">
        <p style="margin:0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;font-weight:600;color:#c8d8e8;line-height:1.65;">Your card or PayPal statement will show this charge from <strong style="color:#ffffff;">GRAPHIC T-SHIRTS</strong>, the company behind GT BOGO Engine.</p>
      </td>
    </tr>
  </table>
</td></tr>

<!-- ACTIVATION STEPS -->
<tr><td style="background-color:#050a16;padding:40px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;border-top:1px solid #0f1a30;">
  <p style="margin:0 0 26px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;letter-spacing:4px;text-transform:uppercase;color:#E10000;">Activation<?php echo esc_html( $is_bulk ) ? ' — Per Site' : ''; ?></p>
  <?php
  $steps = [
      'Log in to your WordPress admin panel',
      'Navigate to GT BOGO Engine in the sidebar',
      'Go to the License tab and enter your license key',
      'Click Activate — all PRO features unlock immediately',
  ];
  if ( $is_bulk ) $steps[] = 'Repeat on each additional WordPress site using a separate key';
  foreach ( $steps as $i => $step ) : ?>
  <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom:20px"><tr>
    <td style="width:36px;vertical-align:top;padding-top:2px"><p style="margin:0;font-family:Georgia,'Times New Roman',serif;font-size:24px;font-weight:700;color:#E10000;line-height:1"><?php echo esc_html( $i + 1 ); ?></p></td>
    <td style="vertical-align:top;padding-left:18px"><p style="margin:0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:16px;font-weight:600;color:#c8d8e8;line-height:1.6"><?php echo esc_html( $step ); ?></p></td>
  </tr></table>
  <?php endforeach; ?>
  <?php if ( $is_subscription ) : ?>
  <div style="margin-top:8px;padding:16px 20px;background:rgba(59,130,246,0.05);border:1px solid rgba(59,130,246,0.15);border-radius:6px">
    <p style="margin:0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;font-weight:600;color:#8ab0d0;line-height:1.6">Your annual license is valid for one website at a time. Licenses can be transferred to a different site at any time. Subscription renews on <?php echo esc_html( $renewal_dt ) ?: 'your renewal date'; ?>.</p>
  </div>
  <?php endif; ?>
</td></tr>

<!-- CTA -->
<tr><td style="background-color:#070C1C;padding:44px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;border-top:1px solid #0f1a30;text-align:center;">
  <a href="https://graphictshirts.shop/bogo" style="display:inline-block;padding:18px 56px;background:#E10000;color:#ffffff;text-decoration:none;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:12px;font-weight:700;letter-spacing:3px;text-transform:uppercase;">VIEW PRODUCT PAGE</a>
</td></tr>

<!-- RED RULE -->
<tr><td style="border-left:1px solid #0f1a30;border-right:1px solid #0f1a30"><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="height:1px;background:#E10000;font-size:0;line-height:0">&nbsp;</td></tr></table></td></tr>

<!-- GRAPHIC T-SHIRTS -->
<tr><td style="background-color:#03060f;padding:44px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;">
  <table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>
    <td style="vertical-align:middle">
      <p style="margin:0 0 5px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;letter-spacing:4px;text-transform:uppercase;color:#E10000">GRAPHIC T-SHIRTS</p>
      <p style="margin:0 0 10px 0;font-family:Georgia,'Times New Roman',serif;font-size:22px;font-weight:700;color:#ffffff;line-height:1.25">Luxury Urban Couture<br>for the Bold.</p>
      <p style="margin:0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;font-weight:600;color:#4a6a8a;line-height:1.6">1,300+ unique pieces. Free worldwide shipping.</p>
    </td>
    <td style="text-align:right;vertical-align:middle;padding-left:24px;white-space:nowrap">
      <a href="https://graphictshirts.shop" style="display:inline-block;padding:14px 28px;border:1px solid #1e3a5f;color:#7a9bc0;text-decoration:none;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;letter-spacing:2px;text-transform:uppercase">EXPLORE</a>
    </td>
  </tr></table>
</td></tr>

<!-- FOOTER -->
<tr><td style="background-color:#03060f;padding:18px 48px 36px 48px;border-left:1px solid #0f1a30;border-right:1px solid #0f1a30;border-top:1px solid #0a1628;text-align:center">
  <p style="margin:0 0 5px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;font-weight:700;letter-spacing:2px;text-transform:uppercase;color:#ffffff">GT BOGO ENGINE FOR WOOCOMMERCE</p>
  <p style="margin:0 0 8px 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;font-weight:600;color:#8ab0d0">A product by GRAPHIC T-SHIRTS</p>
  <a href="https://graphictshirts.shop/bogo" style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;color:#E10000;text-decoration:none;letter-spacing:1px">graphictshirts.shop/bogo</a>
  <p style="margin:14px 0 0 0;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:11px;color:#2a4a6a">&copy; <?php echo esc_html( gmdate('Y') ); ?> GRAPHIC T-SHIRTS. All rights reserved.</p>
</td></tr>

<!-- BOTTOM RED BAR -->
<tr><td><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="height:5px;background:#E10000;font-size:0;line-height:0">&nbsp;</td></tr></table></td></tr>

</table></td></tr></table>
</body></html>
