<?php
/**
 * Hyvä Themes - https://hyva.io
 * Copyright © Hyvä Themes. All rights reserved.
 * See COPYING.txt for license details.
 */

use Hyva\Theme\Model\ViewModelRegistry;
use Hyva\Theme\ViewModel\LucideIcons;
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 LucideIcons $lucideIcons */
$lucideIcons = $viewModels->require(LucideIcons::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="btn p-2"
        href="<?= $escaper->escapeUrl($editProductUrl) ?>"
    >
        <?= $lucideIcons->pencilHtml('', 20, 20, ["aria-hidden" => "true"]); ?>
        <span class="sr-only">
            <?= $escaper->escapeHtml(__('Edit %1', $product->getName())) ?>
        </span>
    </a>
<?php endif ?>
