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

declare(strict_types=1);

use Hyva\Theme\Model\ViewModelRegistry;
use Hyva\Theme\ViewModel\CurrentProduct;
use Hyva\Theme\ViewModel\EmailToFriend;
use Hyva\Theme\ViewModel\HeroiconsSolid;
use Magento\Catalog\Block\Product\View;
use Magento\Catalog\Model\Product;
use Magento\Framework\Escaper;

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

/** @var CurrentProduct $currentProduct */
$currentProduct = $viewModels->require(CurrentProduct::class);
/** @var EmailToFriend $sendFriendViewModel */
$sendFriendViewModel = $viewModels->require(EmailToFriend::class);

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

/** @var Product $product */
$product = $currentProduct->exists() ? $currentProduct->get() : false;

if (!$product) {
    return '';
}

$mailtoUrl = $sendFriendViewModel->getEmailToFriendUrl($product);
?>
<?php if ($sendFriendViewModel->canEmailToFriend()): ?>
    <a href="<?= $escaper->escapeUrl($mailtoUrl) ?>"
       title="<?= $escaper->escapeHtmlAttr(__('Email to a Friend')) ?>"
       aria-label="<?= $escaper->escapeHtmlAttr(__('Email to a Friend')) ?>"
       class="mailto friend rounded-full w-10 h-10 bg-gray-200 p-0 border-0 inline-flex
       items-center justify-center text-gray-500 hover:text-blue-600 ml-2"
    >
        <?= $heroicons->mailHtml('', 20, 20, ['aria-hidden' => 'true']) ?>
        <span class="sr-only"><?= $escaper->escapeHtml(__('Email to a Friend')) ?></span>
    </a>
<?php endif; ?>
