<?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 = esc_attr( $brand_primary ?? '#244b8e' );
?>
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">
<title>Packing Slip #<?php echo esc_html($order_number??''); ?></title>
<?php pbuaiv_style_tag_open(); ?>
* { box-sizing:border-box; margin:0; padding:0; }
body { font-family:'Segoe UI',Arial,sans-serif; font-size:12px; color:#1e293b; }
.pg { max-width:794px; margin:0 auto; padding:30px; }
.hdr { display:flex; justify-content:space-between; align-items:center; border-bottom:2px solid <?php echo esc_attr( $primary ); ?>; padding-bottom:12px; margin-bottom:20px; }
h1 { font-size:18px; color:<?php echo esc_attr( $primary ); ?>; }
.meta { font-size:11px; color:#64748b; }
.ship-to { border:1px solid #e2e8f0; padding:14px; border-radius:6px; margin-bottom:20px; }
.ship-to h3 { font-size:10px; text-transform:uppercase; color:<?php echo esc_attr( $primary ); ?>; margin-bottom:8px; }
table.items { width:100%; border-collapse:collapse; }
table.items th { background:<?php echo esc_attr( $primary ); ?>; color:#fff; padding:8px; font-size:10px; }
table.items td { padding:8px; border-bottom:1px solid #f1f5f9; font-size:11px; }
.checkbox { width:20px; height:20px; border:1.5px solid #64748b; display:inline-block; }
<?php pbuaiv_style_tag_close(); ?></head><body>
<div class="pg">
  <div class="hdr">
    <div>
      <?php if(!empty($company['logo_url'])): ?><img src="<?php echo esc_url($company['logo_url']); ?>" style="max-height:40px;margin-bottom:4px;" /><br><?php endif; ?>
      <h1>Packing Slip</h1>
    </div>
    <div class="meta">
      <strong>Order:</strong> #<?php echo esc_html($order_number??''); ?><br>
      <strong>Date:</strong> <?php echo esc_html(date_i18n(get_option('date_format'),strtotime($doc_date??wp_date('Y-m-d')))); ?><br>
      <strong>Pieces:</strong> <?php echo esc_html( array_sum( array_column( $items ?? [], 'qty' ) ) ); ?>
    </div>
  </div>
  <div class="ship-to">
    <h3>Ship To</h3>
    <strong><?php echo esc_html($customer['name']??''); ?></strong><br>
    <?php if(!empty($customer['company'])): ?><?php echo esc_html($customer['company']); ?><br><?php endif; ?>
    <?php echo wp_kses_post(nl2br($customer['address']??'')); ?><br>
    <?php if(!empty($customer['phone'])): ?>Tel: <?php echo esc_html($customer['phone']); ?><?php endif; ?>
  </div>
  <table class="items">
    <thead><tr><th style="width:30px;"> </th><th style="text-align:left;">Item</th><th>SKU</th><th>Qty</th></tr></thead>
    <tbody>
      <?php foreach($items??[] as $item): ?>
      <tr>
        <td><div class="checkbox"></div></td>
        <td><?php echo esc_html($item['name']); ?></td>
        <td style="font-size:10px;color:#94a3b8;"><?php echo esc_html($item['sku']??'—'); ?></td>
        <td style="text-align:center;font-weight:700;"><?php echo esc_html($item['qty']); ?></td>
      </tr>
      <?php endforeach; ?>
    </tbody>
  </table>
  <div style="margin-top:20px;font-size:10px;color:#94a3b8;text-align:center;"><?php echo esc_html( get_option( 'pbuaiv_company_name', '' ) ); ?></div>
</div></body></html>
