<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.DirectDatabaseQuery.SchemaChange
if ( ! defined( 'ABSPATH' ) ) exit;
$primary = get_option( 'pbuaiv_brand_primary', '#244b8e' );
$accent  = get_option( 'pbuaiv_brand_secondary', '#f59e0b' );
?>
<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title><?php echo esc_html($label??'Document'); ?></title>
<?php pbuaiv_style_tag_open(); ?>
body { font-family:'Segoe UI',Arial,sans-serif; background:#f8fafc; color:#334155; margin:0; padding:0; }
.wrap { max-width:600px; margin:30px auto; }
.header { background:<?php echo esc_attr($primary); ?>; color:#fff; padding:24px 32px; border-radius:10px 10px 0 0; }
.header h1 { font-size:18px; margin:0; }
.header p { font-size:12px; opacity:.8; margin:4px 0 0; }
.body { background:#fff; padding:32px; border:1px solid #e2e8f0; border-top:none; }
.summary { background:#f0f6ff; border-radius:8px; padding:16px; margin:20px 0; }
.summary-row { display:flex; justify-content:space-between; padding:4px 0; font-size:13px; }
.total { font-size:18px; font-weight:700; color:<?php echo esc_attr($primary); ?>; }
.btn { display:inline-block; background:<?php echo esc_attr($primary); ?>; color:#fff; text-decoration:none; padding:12px 24px; border-radius:8px; font-weight:600; margin-top:20px; font-size:14px; }
.footer { text-align:center; font-size:10px; color:#94a3b8; padding:20px; }
<?php pbuaiv_style_tag_close(); ?></head>
<body>
<div class="wrap">
  <div class="header">
    <h1>🇦🇪 <?php echo esc_html($label??'Document'); ?> <?php echo esc_html($doc_number??''); ?></h1>
    <p><?php echo esc_html(get_option('pbuaiv_company_name','')); ?> · <?php echo esc_html(date_i18n(get_option('date_format'),strtotime($doc_date??wp_date('Y-m-d')))); ?></p>
  </div>
  <div class="body">
    <?php /* translators: %s: customer name. */ ?>
    <p><?php printf( esc_html__( 'Hello %s,', 'pb-invoicing-system' ), esc_html( $customer['name'] ?? '' ) ); ?></p>
    <?php /* translators: 1: document label, 2: order number. */ ?>
    <p style="margin-top:12px;"><?php printf( esc_html__( 'Please find your %1$s for Order #%2$s attached to this email.', 'pb-invoicing-system' ), esc_html( strtolower( $label ?? 'document' ) ), esc_html( $order_number ?? '' ) ); ?></p>

    <div class="summary">
      <div class="summary-row"><span><?php esc_html_e('Order','pb-invoicing-system'); ?></span><span>#<?php echo esc_html($order_number??''); ?></span></div>
      <div class="summary-row"><span><?php esc_html_e('Date','pb-invoicing-system'); ?></span><span><?php echo esc_html(date_i18n(get_option('date_format'),strtotime($doc_date??wp_date('Y-m-d')))); ?></span></div>
      <div class="summary-row"><span><?php esc_html_e('Subtotal','pb-invoicing-system'); ?></span><span><?php echo esc_html(number_format($subtotal??0,2)); ?> <?php echo esc_html($currency??'AED'); ?></span></div>
      <div class="summary-row"><span><?php esc_html_e('VAT','pb-invoicing-system'); ?></span><span><?php echo esc_html(number_format($vat_amount??0,2)); ?> <?php echo esc_html($currency??'AED'); ?></span></div>
      <div class="summary-row total"><span><?php esc_html_e('Total','pb-invoicing-system'); ?></span><span><?php echo esc_html(number_format($total??0,2)); ?> <?php echo esc_html($currency??'AED'); ?></span></div>
    </div>

    <p style="font-size:12px;color:#64748b;">
      🇦🇪 <?php esc_html_e('UAE VAT:','pb-invoicing-system'); ?>
      TRN <?php echo esc_html(get_option('pbuaiv_trn','—')); ?> ·
      VAT AED <?php echo esc_html(number_format($vat_amount_aed??$vat_amount??0,2)); ?>
    </p>

    <p style="margin-top:16px;"><?php esc_html_e('The PDF document is attached to this email.','pb-invoicing-system'); ?></p>

    <?php if(!empty($custom_notes)): ?>
    <p style="margin-top:16px;padding:12px;background:#f8fafc;border-radius:6px;font-size:12px;"><?php echo esc_html($custom_notes); ?></p>
    <?php endif; ?>
  </div>
  <div class="footer">
    <?php echo esc_html(get_option('pbuaiv_company_name','')); ?> · <?php echo esc_html(get_option('pbuaiv_company_email','')); ?><br>
    <?php echo esc_html( get_option( 'pbuaiv_company_name', '' ) ); ?>
  </div>
</div>
</body></html>
