<?php
/**
 * Hyvä Themes - https://hyva.io
 * Copyright © Hyvä Themes 2020-present. All rights reserved.
 * This product is licensed per Magento install
 * See https://hyva.io/license
 */

declare(strict_types=1);

use Hyva\Theme\Model\ViewModelRegistry;
use Hyva\Theme\ViewModel\HeroiconsOutline;
use Magento\Framework\Escaper;
use Magento\Sales\Block\Order\Info\Buttons;

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper

/** @var Escaper $escaper */
/** @var Buttons $block */
/** @var ViewModelRegistry $viewModels */

/** @var HeroiconsOutline $heroicons */
$heroicons = $viewModels->require(HeroiconsOutline::class);
?>
<div class="flex items-center justify-center md:justify-start flex-wrap gap-4 md:gap-x-6 my-4 md:my-0 hg">
    <?php $order = $block->getOrder() ?>
    <?php if ($this->helper(\Magento\Sales\Helper\Reorder::class)->canReorder($order->getEntityId())): ?>
        <?php $formData = json_decode(
            $this->helper(\Magento\Framework\Data\Helper\PostHelper::class)->getPostData(
                $block->getReorderUrl($order)
            ),
            true
        ) ?>
        <form id="reorder-form"
              action="<?= $escaper->escapeUrl($formData['action']) ?>"
              method="post"
              class="inline-flex items-center"
        >
            <?= $block->getBlockHtml('formkey'); ?>
            <input type="hidden" name="data" value='<?= /** @noEscape */ json_encode($formData['data']) ?>'/>
            <button type="submit" class="btn btn-primary text-white">
                <?= $heroicons->refreshHtml('mr-1 inline-block', 24, 24, ['aria-hidden' => 'true']); ?>
                <span><?= $escaper->escapeHtml(__('Reorder')) ?></span>
            </button>
        </form>
    <?php endif ?>
    <a href="<?= $escaper->escapeUrl($block->getPrintUrl($order)) ?>"
       class="btn btn-primary text-white"
       target="_blank"
       rel="noopener">
        <?= $heroicons->printerHtml('mr-1 inline-block', 24, 24, ['aria-hidden' => 'true']); ?>
        <span><?= $escaper->escapeHtml(__('Print Order')) ?></span>
    </a>
    <?= $block->getChildHtml() ?>
</div>
