<?php
/**
 * Maho
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2024 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /** @var Mage_Core_Block_Template $this */?>
<div <?= $this->getGridHtmlClass() ? ' class="' . $this->getGridHtmlClass() . '"' : '' ?><?= $this->getGridHtmlCss() ? ' style="' . $this->getGridHtmlCss() . '"' : '' ?>>

<?php if ($caption = $this->getGridCaption()): ?>
<h2 class="table-caption"><?= $this->escapeHtml($caption) ?></h2>
<?php endif ?>

<?php $gridElements = $this->getGridElements(); ?>
<?php if ($gridElements): ?>
    <?= $this->getChildHtml('pager') ?>
    <table id="<?= $this->getGridHtmlId() ?>" class="data-table">
<?php foreach ($this->getGridColumns() as $column):?>
        <col <?php $width = $this->getObjectData($column, 'width'); echo $width ? ' width="' . $width . '"' : '' ?>/>
<?php endforeach ?>
        <thead>
            <tr>
<?php foreach ($this->getGridColumns() as $column):
$nobr = $this->getObjectData($column, 'is_nobr') ? '<span class="nobr">%s</span>' : '%s';
$title = $this->getObjectData($column, 'title');
?>
                <th><?= $title ? sprintf($nobr, $this->escapeHtml($title)) : '&nbsp;' ?></th>
<?php endforeach ?>
            </tr>
        </thead>
        <tbody>
<?php foreach($gridElements as $row): ?>
            <tr>
<?php foreach ($this->getGridColumns() as $column):
$nobr = $this->getObjectData($column, 'is_nobr') ? '<span class="nobr">%s</span>' : '%s';
$index = $this->getObjectData($column, 'index');
$value = $this->getObjectData($row, $index);
$linkUrl = $this->getObjectData($row, "{$index}_link_url");
$linkAnchorText = $this->getObjectData($row, "{$index}_link_text");
$linkText = $linkUrl ? ($linkAnchorText ? $linkAnchorText : $value) : '';
$linkFormat = $linkUrl ? '<a href="%s">%s</a>' : '';
?>
                <td<?php $this->getObjectData($row, 'is_amount') ? ' class="a-right"' : '' ?>><?php
if ($linkFormat) {
    echo sprintf($nobr, sprintf($linkFormat, $this->escapeHtml($linkUrl), $this->escapeHtml($linkText)));
} else {
    echo sprintf($nobr, $this->escapeHtml($value));
}
                ?></td>
<?php endforeach ?>
            </tr>
<?php endforeach ?>
        </tbody>
    </table>
    <?= $this->getChildHtml('pager') ?>
<?php else: ?>
    <p><?= $this->escapeHtml($this->getEmptyGridMessage()) ?></p>
<?php endif ?>
</div>
