<?php
/**
 * Shared invoice body — addresses, the line-item table, totals and the note.
 *
 * Every ready-made template renders this same content and only varies the CSS
 * for these classes (.meta, .label, .items, .right, .totals, .foot) plus its own
 * header. Included with $data in scope; all values are escaped here.
 *
 * @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
?>
<table class="meta">
    <tr>
        <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>
        <td>
            <?php if (trim(wp_strip_all_tags($data['shipping'])) !== '') : ?>
                <div class="label"><?php echo esc_html__('Ship to', 'softminal-b2b-wholesale-for-woocommerce'); ?></div>
                <?php echo wp_kses_post($data['shipping']); ?>
            <?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" style="text-align:center"><?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" style="text-align:center"><?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; ?>
