<?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
 */

use Hyva\Theme\Model\ViewModelRegistry;
use Hyva\Theme\ViewModel\HeroiconsOutline;
use Magento\Framework\Escaper;
use Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Edit;
use Magento\Wishlist\Model\Item;

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

/** @var HeroiconsOutline $heroicons */
$heroicons = $viewModels->require(HeroiconsOutline::class);

/** @var Item $item */
$item = $block->getItem();
$product = $item->getProduct();

// The product url contains a hash with selected product options
// We're going to use that hash
$productUrl = $block->getProductUrl($item);
$urlHash = explode('#', $productUrl);
// it would be nicer if we would one day extend the getItemConfigureUrl instead
$configureUrl = $block->getItemConfigureUrl($item);

// we add the hash from productUrl to the configureUrl
$editProductUrl = $configureUrl . (count($urlHash) > 1 ? '#' . $urlHash[1] : '');
?>

<?php if ($product->isVisibleInSiteVisibility()): ?>
    <a class="action edit btn btn-secondary inline-flex mr-2 p-2 border-2 text-black font-sen border-primary-darker"
       href="<?= $escaper->escapeUrl($editProductUrl) ?>">
        <?= $heroicons->pencilHtml('', 20, 20); ?>
        <span class="sr-only">
            <?= $escaper->escapeHtml(__('Edit %1', $product->getName())) ?>
        </span>
    </a>
<?php endif ?>
