<?php
/**
 * Modern — a banded header in the brand colour, otherwise the same print-safe,
 * fully-escaped structure as Classic. Shared body from _content.php.
 *
 * @var array<string, mixed> $data
 */

if (!defined('ABSPATH')) {
    exit;
}

// Template partial included in a render method; its locals are not globals.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

$accent = '#4f46e5';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
    body { font-family: <?php echo esc_attr($data['font']); ?>; font-size: 12px; color: #1f2937; margin: 0; }
    .band { background: <?php echo esc_attr($accent); ?>; color: #fff; padding: 24px 32px; }
    .band table { width: 100%; } .band td { vertical-align: middle; color: #fff; }
    .band h1 { margin: 0; font-size: 24px; } .band .logo img { max-height: 56px; }
    .band .no { text-align: right; font-size: 13px; }
    .wrap { padding: 24px 32px; }
    .meta { width: 100%; margin: 8px 0 20px; } .meta td { vertical-align: top; width: 50%; font-size: 11px; }
    .label { text-transform: uppercase; font-size: 10px; letter-spacing: .04em; color: <?php echo esc_attr($accent); ?>; margin-bottom: 4px; font-weight: bold; }
    table.items { width: 100%; border-collapse: collapse; }
    table.items th { text-align: left; background: #eef2ff; padding: 10px 8px; font-size: 11px; }
    table.items td { padding: 9px 8px; border-bottom: 1px solid #e5e7eb; }
    .right { text-align: right; }
    table.totals { width: 42%; margin-left: 58%; margin-top: 12px; border-collapse: collapse; }
    table.totals td { padding: 6px 8px; }
    table.totals tr:last-child td { border-top: 2px solid <?php echo esc_attr($accent); ?>; font-weight: bold; font-size: 13px; }
    .foot { margin-top: 40px; font-size: 10px; color: #6b7280; }
</style>
</head>
<body>
    <?php require $data['partials'] . '/_watermark.php'; ?>

    <div class="band">
        <table>
            <tr>
                <td>
                    <?php if (!empty($data['logo'])) : ?>
                        <div class="logo"><img src="<?php echo esc_attr($data['logo']); ?>" alt=""></div>
                    <?php else : ?>
                        <h1><?php echo esc_html($data['seller']['name']); ?></h1>
                    <?php endif; ?>
                </td>
                <td class="no">
                    <strong><?php echo esc_html(strtoupper($data['doc_title'])); ?></strong><br>
                    #<?php echo esc_html($data['invoice_no']); ?><br>
                    <?php echo esc_html($data['date']); ?>
                    <?php if (!empty($data['po_number'])) : ?><br><?php echo esc_html__('PO', 'softminal-b2b-wholesale-for-woocommerce') . ': ' . esc_html($data['po_number']); ?><?php endif; ?>
                </td>
            </tr>
        </table>
    </div>

    <div class="wrap">
        <table class="meta">
            <tr>
                <td>
                    <div class="label"><?php echo esc_html__('From', 'softminal-b2b-wholesale-for-woocommerce'); ?></div>
                    <strong><?php echo esc_html($data['seller']['name']); ?></strong><br>
                    <?php echo nl2br(esc_html($data['seller']['address'])); ?>
                    <?php if ($data['seller']['vat'] !== '') : ?><br><?php echo esc_html__('VAT', 'softminal-b2b-wholesale-for-woocommerce') . ': ' . esc_html($data['seller']['vat']); ?><?php endif; ?>
                </td>
                <td>
                    <div class="label"><?php echo esc_html__('Bill to', 'softminal-b2b-wholesale-for-woocommerce'); ?></div>
                    <?php echo wp_kses_post($data['billing']); ?>
                    <?php if ($data['vat_number'] !== '') : ?><br><?php echo esc_html__('VAT', 'softminal-b2b-wholesale-for-woocommerce') . ': ' . esc_html($data['vat_number']); ?><?php endif; ?>
                </td>
            </tr>
        </table>

        <table class="items">
            <thead>
                <tr>
                    <th><?php echo esc_html__('Product', 'softminal-b2b-wholesale-for-woocommerce'); ?></th>
                    <th><?php echo esc_html__('SKU', 'softminal-b2b-wholesale-for-woocommerce'); ?></th>
                    <th class="right"><?php echo esc_html__('Qty', 'softminal-b2b-wholesale-for-woocommerce'); ?></th>
                    <th class="right"><?php echo esc_html__('Total', 'softminal-b2b-wholesale-for-woocommerce'); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($data['lines'] as $line) : ?>
                    <tr>
                        <td><?php echo esc_html($line['name']); ?></td>
                        <td><?php echo esc_html($line['sku'] ?: '—'); ?></td>
                        <td class="right"><?php echo esc_html((string) $line['quantity']); ?></td>
                        <td class="right"><?php echo wp_kses_post($line['total']); ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <table class="totals">
            <?php foreach ($data['totals'] as $total) : ?>
                <tr>
                    <td><?php echo esc_html($total['label']); ?></td>
                    <td class="right"><?php echo wp_kses_post($total['value']); ?></td>
                </tr>
            <?php endforeach; ?>
        </table>

        <?php if ($data['note'] !== '') : ?>
            <div class="foot"><?php echo nl2br(esc_html($data['note'])); ?></div>
        <?php endif; ?>
    </div>
</body>
</html>
