<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php

$numColumns = count($block->getColumns());
?>
<?php if ($block->getCollection()) : ?>
<div class="dashboard-item-content">
    <?php if ($block->getCollection()->getSize() > 0) : ?>
        <table class="admin__table-primary dashboard-data" id="<?= $block->escapeHtmlAttr($block->getId()) ?>_table">
            <?php
            /* This part is commented to remove all <col> tags from the code. */
            /* foreach ($block->getColumns() as $_column): ?>
            <col <?= $_column->getHtmlProperty() ?> />
            <?php endforeach; */ ?>
            <?php if ($block->getHeadersVisibility() || $block->getFilterVisibility()) : ?>
                <thead>
                <?php if ($block->getHeadersVisibility()) : ?>
                    <tr>
                        <?php foreach ($block->getColumns() as $_column) : ?>
                            <?= $_column->getHeaderHtml() ?>
                        <?php endforeach; ?>
                    </tr>
                <?php endif; ?>
                </thead>
            <?php endif; ?>
            <?php if (!$block->getIsCollapsed()) : ?>
                <tbody>
                <?php foreach ($block->getCollection() as $_index => $_item) : ?>
                    <tr title="<?= $block->escapeHtmlAttr($block->getRowUrl($_item)) ?>">
                    <?php $i = 0; foreach ($block->getColumns() as $_column) : ?>
                        <td class="<?= $block->escapeHtmlAttr($_column->getCssProperty()) ?> <?= /* @noEscape */ ++$i == $numColumns ? 'last' : '' ?>"><?= /* @noEscape */ (($_html = $_column->getRowField($_item)) != '' ? $_html : '&nbsp;') ?></td>
                    <?php endforeach; ?>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            <?php endif; ?>
        </table>
    <?php else : ?>
        <div class="<?= $block->escapeHtmlAttr($block->getEmptyTextClass()) ?>"><?= $block->escapeHtml($block->getEmptyText()) ?></div>
    <?php endif; ?>
</div>
    <?php if ($block->canDisplayContainer()) : ?>
<script>
var deps = [];

        <?php if ($block->getDependencyJsObject()) : ?>
deps.push('uiRegistry');
        <?php endif; ?>

        <?php if (strpos($block->getRowClickCallback(), 'order.') !== false) : ?>
deps.push('Magento_Sales/order/create/form');
        <?php endif; ?>

deps.push('mage/adminhtml/grid');

require(deps, function(<?= ($block->getDependencyJsObject() ? 'registry' : '') ?>){
        <?php //TODO: getJsObjectName and getRowClickCallback has unexpected behavior. Should be removed ?>

        <?php if ($block->getDependencyJsObject()) : ?>
        registry.get('<?= $block->escapeJs($block->getDependencyJsObject()) ?>', function (<?= $block->escapeJs($block->getDependencyJsObject()) ?>) {
        <?php endif; ?>

        <?= $block->escapeJs($block->getJsObjectName()) ?> = new varienGrid('<?= $block->escapeJs($block->getId()) ?>', '<?= $block->escapeJs($block->getGridUrl()) ?>', '<?= $block->escapeJs($block->getVarNamePage()) ?>', '<?= $block->escapeJs($block->getVarNameSort()) ?>', '<?= $block->escapeJs($block->getVarNameDir()) ?>', '<?= $block->escapeJs($block->getVarNameFilter()) ?>');
        <?= $block->escapeJs($block->getJsObjectName()) ?>.useAjax = '<?= $block->escapeJs($block->getUseAjax()) ?>';
        <?php if ($block->getRowClickCallback()) : ?>
            <?= $block->escapeJs($block->getJsObjectName()) ?>.rowClickCallback = <?= /* @noEscape */ $block->getRowClickCallback() ?>;
        <?php endif; ?>
        <?php if ($block->getCheckboxCheckCallback()) : ?>
            <?= $block->escapeJs($block->getJsObjectName()) ?>.checkboxCheckCallback = <?= /* @noEscape */ $block->getCheckboxCheckCallback() ?>;
        <?php endif; ?>
        <?php if ($block->getRowInitCallback()) : ?>
            <?= $block->escapeJs($block->getJsObjectName()) ?>.initRowCallback = <?= /* @noEscape */ $block->getRowInitCallback() ?>;
            <?= $block->escapeJs($block->getJsObjectName()) ?>.rows.each(function(row){<?= /* @noEscape */ $block->getRowInitCallback() ?>(<?= $block->escapeJs($block->getJsObjectName()) ?>, row)});
        <?php endif; ?>
        <?php if ($block->getMassactionBlock()->isAvailable()) : ?>
            <?= /* @noEscape */ $block->getMassactionBlock()->getJavaScript() ?>
        <?php endif ?>

        <?php if ($block->getDependencyJsObject()) : ?>
    });
        <?php endif; ?>

});
</script>
<?php endif; ?>
<?php endif ?>
