<?php
declare(strict_types=1);

/**
 * @var \Magento\Framework\View\Element\Template $block
 * @var \Magento\Framework\Escaper $escaper
 * @var \ClawRock\Debug\Model\View\Profiler $viewModel
 * @var \ClawRock\Debug\Model\Collector\ConfigCollector $collector
 */
$viewModel = $block->getViewModel();
$collector = $block->getCollector();
?>
<h2><?= $escaper->escapeHtml(__('PHP Configuration')) ?></h2>
<div class="metrics">
    <div class="metric">
        <span class="value"><?= /* @noEscape */ $collector->getPhpVersion() ?></span>
        <span class="label"><?= $escaper->escapeHtml(__('PHP version')) ?></span>
    </div>
    <div class="metric">
        <span class="value">
            <?php if ($collector->hasAccelerator()): ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/yes.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('Yes')) ?>"/>
            <?php else: ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/no.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('No')) ?>"/>
            <?php endif; ?>
        </span>
        <span class="label"><?= $escaper->escapeHtml(__('PHP acceleration')) ?></span>
    </div>
    <div class="metric">
        <span class="value">
            <?php if ($collector->hasXDebug()): ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/yes.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('Yes')) ?>"/>
            <?php else: ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/no.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('No')) ?>"/>
            <?php endif; ?>
        </span>
        <span class="label">Xdebug</span>
    </div>
</div>
<div class="metrics metrics-horizontal">
    <div class="metric">
        <span
        <span class="value">
            <?php if ($collector->hasZendOpcache()): ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/yes.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('Yes')) ?>"/>
            <?php else: ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/no.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('No')) ?>"/>
            <?php endif; ?>
        </span>
        <span class="label">OPcache</span>
    </div>
    <div class="metric">
        <span class="value">
            <?php if ($collector->hasApc()): ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/yes.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('Yes')) ?>"/>
            <?php else: ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/no.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('No')) ?>"/>
            <?php endif; ?>
        </span>
        <span class="label">APC</span>
    </div>
    <div class="metric">
        <span class="value">
            <?php if ($collector->hasXCache()): ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/yes.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('Yes')) ?>"/>
            <?php else: ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/no.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('No')) ?>"/>
            <?php endif; ?>
        </span>
        <span class="label">XCache</span>
    </div>
    <div class="metric">
        <span
        <span class="value">
            <?php if ($collector->hasEAccelerator()): ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/yes.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('Yes')) ?>"/>
            <?php else: ?>
                <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/icon/no.svg'); ?>"
                     alt="<?= $escaper->escapeHtmlAttr(__('No')) ?>"/>
            <?php endif; ?>
        </span>
        <span class="label">EAccelerator</span>
    </div>
</div>
<p>
    <a href="<?= $escaper->escapeUrl($block->getUrl('_debug/profiler/phpinfo')) ?>">
        <?= $escaper->escapeHtml(__('View full PHP configuration')) ?>
    </a>
</p>
<h2>Magento</h2>
<table>
    <thead>
        <tr>
            <th class="key"><?= $escaper->escapeHtml(__('Key')) ?></th>
            <th><?= $escaper->escapeHtml(__('Value')) ?></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><?= $escaper->escapeHtml(__('Admin Url')) ?></td>
            <td>
                <a href="<?= /* @noEscape */ $collector->getAdminUrl(); ?>">
                    <?= /* @noEscape */ $collector->getAdminUrl(); ?>
                </a>
            </td>
        </tr>
        <tr>
            <td><?= $escaper->escapeHtml(__('Website')) ?></td>
            <td>
                <?= /* @noEscape */ $collector->getWebsiteName() ?>
                (<?= /* @noEscape */ $collector->getWebsiteCode() ?>)
            </td>
        </tr>
        <tr>
            <td><?= $escaper->escapeHtml(__('Store')) ?></td>
            <td>
                <?= /* @noEscape */ $collector->getStoreName() ?>
                (<?= /* @noEscape */ $collector->getStoreCode() ?>)
            </td>
        </tr>
    </tbody>
</table>
<h2><?= $escaper->escapeHtml(__('Modules')) ?></h2>
<table>
    <thead>
        <tr>
            <th><?= $escaper->escapeHtml(__('Module')) ?></th>
            <th><?= $escaper->escapeHtml(__('Version')) ?></th>
            <th><?= $escaper->escapeHtml(__('Sequence')) ?></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($collector->getModules() as $name => $data): ?>
            <tr>
                <td style="white-space: nowrap;"><?= /* @noEscape */$name ?></td>
                <td><?= /* @noEscape */$data['setup_version'] ?? 'n/a'; ?></td>
                <td><?= /* @noEscape */implode(', ', $data['sequence']); ?></td>
            </tr>
        <?php endforeach; ?>
    </tbody>
</table>
