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

// @codingStandardsIgnoreFile

?>
<?php

$numColumns = sizeof($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="<?php /* @escapeNotVerified */ echo $block->getId() ?>_table">
            <?php
            /* This part is commented to remove all <col> tags from the code. */
            /* foreach ($block->getColumns() as $_column): ?>
            <col <?php echo $_column->getHtmlProperty() ?> />
            <?php endforeach; */ ?>
            <?php if ($block->getHeadersVisibility() || $block->getFilterVisibility()): ?>
                <thead>
                <?php if ($block->getHeadersVisibility()): ?>
                    <tr>
                        <?php foreach ($block->getColumns() as $_column): ?>
                            <?php echo $_column->getHeaderHtml() ?>
                        <?php endforeach; ?>
                    </tr>
                <?php endif; ?>
                </thead>
            <?php endif; ?>
            <?php if (!$block->getIsCollapsed()): ?>
                <tbody>
                <?php foreach ($block->getCollection() as $_index => $_item): ?>
                    <tr title="<?php /* @escapeNotVerified */ echo $block->getRowUrl($_item) ?>">
                    <?php $i = 0; foreach ($block->getColumns() as $_column): ?>
                        <td class="<?php /* @escapeNotVerified */ echo $_column->getCssProperty() ?> <?php echo ++$i == $numColumns ? 'last' : '' ?>"><?php echo(($_html = $_column->getRowField($_item)) != '' ? $_html : '&nbsp;') ?></td>
                    <?php endforeach; ?>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            <?php endif; ?>
        </table>
    <?php else: ?>
        <div class="<?php /* @escapeNotVerified */ echo $block->getEmptyTextClass() ?>"><?php /* @escapeNotVerified */ echo $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(<?php echo ($block->getDependencyJsObject() ? 'registry' : '') ?>){
    <?php //TODO: getJsObjectName and getRowClickCallback has unexpected behavior. Should be removed ?>

    <?php if ($block->getDependencyJsObject()): ?>
        registry.get('<?php /* @escapeNotVerified */ echo $block->getDependencyJsObject() ?>', function (<?php /* @escapeNotVerified */ echo $block->getDependencyJsObject() ?>) {
    <?php endif; ?>

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

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

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