<?php
declare(strict_types=1);

/**
 * @var \Magento\Framework\View\Element\Template $block
 * @var \Magento\Framework\Escaper $escaper
 * @var \ClawRock\Debug\Model\Collector\CacheCollector $collector
 */
$collector = $block->getCollector();
?>
<div class="sf-toolbar-block sf-toolbar-block-<?= /* @noEscape */ $collector->getName() ?>">
    <a target="_blank" href="<?= $escaper->escapeUrl($block->getProfilerUrl()); ?>">
        <div class="sf-toolbar-icon">
            <img src="<?= /* @noEscape */ $block->getViewFileUrl('ClawRock_Debug::images/collector/cache.svg'); ?>"
                 alt="<?= $escaper->escapeHtmlAttr(__('Cache')) ?>"/>
            <span class="sf-toolbar-value"><?= /* @noEscape */ $collector->getTotalTime(); ?> ms</span>
        </div>
    </a>
    <div class="sf-toolbar-info">
        <div class="sf-toolbar-info-group">
            <?php foreach ($collector->getCacheList() as $cache): ?>
                <div class="sf-toolbar-info-piece">
                    <strong><?= /* @noEscape */ $cache->getCacheType(); ?></strong>
                    <?php if ($cache->getStatus() === 1): ?>
                        <?php if ($collector->isInvalidated($cache->getId())): ?>
                            <span class="sf-toolbar-status sf-toolbar-status-yellow">
                                <?= $escaper->escapeHtml(__('INV')); ?>
                            </span>
                        <?php else: ?>
                            <span class="sf-toolbar-status sf-toolbar-status-green">
                                <?= $escaper->escapeHtml(__('YES')); ?>
                            </span>
                        <?php endif; ?>
                        &nbsp;
                        <a href="#"
                           data-url="<?= $escaper->escapeUrl($block->getUrl('_debug/cache/clean', [
                               'type' => $cache->getId(),
                           ])) ?>"
                           class="ajax-action"><?= $escaper->escapeHtml(__('Clean')); ?></a> /
                        <a href="#"
                           data-url="<?= $escaper->escapeUrl($block->getUrl('_debug/cache/disable', [
                               'type' => $cache->getId(),
                           ])) ?>"
                           class="ajax-action"><?= $escaper->escapeHtml(__('Disable')); ?></a>
                    <?php else:?>
                        <span class="sf-toolbar-status"><?= $escaper->escapeHtml(__('NO')); ?></span>
                        &nbsp;
                        <a href="#"
                           data-url="<?= $escaper->escapeUrl($block->getUrl('_debug/cache/enable', [
                               'type' => $cache->getId(),
                           ])) ?>"
                           class="ajax-action"><?= $escaper->escapeHtml(__('Enable')); ?></a>
                    <?php endif;?>
                </div>
            <?php endforeach; ?>
        </div>
        <div class="sf-toolbar-info-group" >
            <div class="sf-toolbar-info-piece" style="text-align: right; display: block;">
                <a href="#"
                   data-url="<?= $escaper->escapeUrl($block->getUrl('_debug/cache/clean')) ?>"
                   class="ajax-action">
                    <?= $escaper->escapeHtml(__('Clean')); ?>
                </a> /
                <a href="#"
                   data-url="<?= $escaper->escapeUrl($block->getUrl('_debug/cache/flush')) ?>"
                   class="ajax-action">
                    <?= $escaper->escapeHtml(__('Flush')); ?>
                </a>
            </div>
        </div>
        <div class="sf-toolbar-info-group" >
            <div class="sf-toolbar-info-piece">
                <strong><?= $escaper->escapeHtml(__('Cache calls')); ?></strong>
                <span class="sf-toolbar-status"><?= /* @noEscape */ $collector->getCacheCalls() ?></span>
            </div>
            <div class="sf-toolbar-info-piece">
                <strong><?= $escaper->escapeHtml(__('Time')); ?></strong>
                <span><?= /* @noEscape */ $collector->getTotalTime() ?> ms</span>
            </div>
        </div>
    </div>
</div>
