<?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\PluginCollector $collector
 */
$viewModel = $block->getViewModel();
$collector = $block->getCollector();
?>
<div>
    <h2><?= $escaper->escapeHtml(__('Plugins')) ?></h2>
</div>

<?php if (!$collector->hasPlugins()): ?>
    <div class="empty">
        <p><?= $escaper->escapeHtml(__('No plugins have been processed.')) ?></p>
    </div>
<?php else: ?>
    <div class="sf-tabs">
        <div class="tab">
            <h3 class="tab-title">
                <?= $escaper->escapeHtml(__('BEFORE')) ?>
                <span class="badge"><?= /* @noEscape */ $collector->getBeforePluginsCount(); ?></span>
            </h3>
            <div class="tab-content">
                <table class="auto">
                    <?php foreach ($collector->getBeforePlugins() as $type => $plugins): ?>
                        <thead>
                            <tr>
                                <th><?= /* @noEscape */$type; ?></th>
                                <th><?= $escaper->escapeHtml(__('Name')) ?></th>
                                <th><?= $escaper->escapeHtml(__('Sort order')) ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php /** @var \ClawRock\Debug\Model\ValueObject\Plugin $plugin */ ?>
                            <?php foreach ($plugins as $plugin): ?>
                                <tr>
                                    <td>
                                        <?=
                                        /* @noEscape */ $plugin->getClass();
                                        ?>::<?=
                                        /* @noEscape */ $plugin->getMethod(); ?>
                                    </td>
                                    <td><?= /* @noEscape */ $plugin->getName(); ?></td>
                                    <td class="text-center">
                                        <?= /* @noEscape */ $plugin->getSortOrder(); ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    <?php endforeach; ?>
                </table>
            </div>
        </div>
        <div class="tab">
            <h3 class="tab-title">
                <?= $escaper->escapeHtml(__('AROUND')) ?>
                <span class="badge"><?= /* @noEscape */ $collector->getAroundPluginsCount() ?></span>
            </h3>
            <div class="tab-content">
                <table class="auto">
                    <?php foreach ($collector->getAroundPlugins() as $type => $plugins): ?>
                        <thead>
                            <tr>
                                <th><?= /* @noEscape */ $type; ?></th>
                                <th><?= $escaper->escapeHtml(__('Name')) ?></th>
                                <th><?= $escaper->escapeHtml(__('Sort order')) ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php /** @var \ClawRock\Debug\Model\ValueObject\Plugin $plugin */ ?>
                            <?php foreach ($plugins as $plugin): ?>
                                <tr>
                                    <td>
                                        <?=
                                        /* @noEscape */ $plugin->getClass();
                                        ?>::<?=
                                        /* @noEscape */ $plugin->getMethod(); ?>
                                    </td>
                                    <td><?= /* @noEscape */ $plugin->getName(); ?></td>
                                    <td class="text-center"><?= /* @noEscape */ $plugin->getSortOrder(); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    <?php endforeach; ?>
                </table>
            </div>
        </div>
        <div class="tab">
            <h3 class="tab-title">
                <?= $escaper->escapeHtml(__('AFTER')) ?>
                <span class="badge"><?= /* @noEscape */ $collector->getAfterPluginsCount() ?></span>
            </h3>
            <div class="tab-content">
                <table class="auto">
                    <?php foreach ($collector->getAfterPlugins() as $type => $plugins): ?>
                        <thead>
                            <tr>
                                <th><?= /* @noEscape */ $type; ?></th>
                                <th><?= $escaper->escapeHtml(__('Name')) ?></th>
                                <th><?= $escaper->escapeHtml(__('Sort order')) ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php /** @var \ClawRock\Debug\Model\ValueObject\Plugin $plugin */ ?>
                            <?php foreach ($plugins as $plugin): ?>
                                <tr>
                                    <td>
                                        <?=
                                        /* @noEscape */ $plugin->getClass();
                                        ?>::<?=
                                        /* @noEscape */ $plugin->getMethod(); ?>
                                    </td>
                                    <td><?= /* @noEscape */ $plugin->getName(); ?></td>
                                    <td class="text-center"><?= /* @noEscape */ $plugin->getSortOrder(); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    <?php endforeach; ?>
                </table>
            </div>
        </div>
    </div>
<?php endif; ?>
