<?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 Magento\Framework\Escaper;
use Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Cart;
use Magento\Wishlist\Model\Item;
use Magento\Wishlist\ViewModel\AllowedQuantity;

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

/** @var Item $item */
$item = $block->getItem();
$product = $item->getProduct();
/** @var AllowedQuantity $viewModel */
$viewModel = $viewModels->require(AllowedQuantity::class);
$allowedQty = $viewModel->setItem($item)->getMinMaxQty();
?>
<?php foreach ($block->getChildNames() as $childName): ?>
    <?= /* @noEscape */ $block->getLayout()->renderElement($childName, false) ?>
<?php endforeach;?>
<div class="box-tocart">
    <fieldset class="fieldset">
    <?php if ($item->canHaveQty() && $product->isVisibleInSiteVisibility()): ?>
        <div class="field qty hidden ">
            <label class="label"
                   for="qty[<?= $escaper->escapeHtmlAttr($item->getId()) ?>]">
                <span>
                    <?= $escaper->escapeHtml(__('Qty')) ?>
                </span>
            </label>
            <div class="control">
                <input type="number"
                       x-ref="product-qty-<?= $escaper->escapeHtmlAttr($item->getId()) ?>"
                       data-role="qty"
                       id="qty[<?= $escaper->escapeHtmlAttr($item->getId()) ?>]"
                       class="form-input qty"
                       name="qty[<?= $escaper->escapeHtmlAttr($item->getId()) ?>]"
                       value="<?= /* @noEscape */ $block->getAddToCartQty($item) * 1 ?>"
                    <?= $product->isSaleable() ? '' : 'disabled' ?>
                >
            </div>
        </div>
    <?php endif; ?>
    <?php if ($product->isSaleable()): ?>
    <div class="product-item-actions">
        <div class="actions-primary">
            <button type="button"
                    data-role="tocart"
                    @click.prevent='addToCart("<?= $escaper->escapeHtmlAttr($item->getId()) ?>",
                        <?= /* @noEscape */ $block->getItemAddToCartParams($item) ?>)'
                    title="<?= $escaper->escapeHtmlAttr(__('Add %1 to Cart', $product->getName())) ?>"
                    aria-label="<?= $escaper->escapeHtmlAttr(__('Add to Cart %1', $product->getName())) ?>"
                    class="action tocart primary btn btn-primary md:text-sm lg:text-base"
                    data-addto="cart"
            >
                <span><?= $escaper->escapeHtml(__('Add to Cart')) ?></span>
            </button>
        </div>
    </div>
    <?php else: ?>
        <?php if ($product->getIsSalable()): ?>
            <p class="available stock" title="<?= $escaper->escapeHtmlAttr(__('Availability')) ?>">
                <span><?= $escaper->escapeHtml(__('In stock')) ?></span>
            </p>
        <?php else: ?>
            <p class="unavailable stock" title="<?= $escaper->escapeHtmlAttr(__('Availability')) ?>">
                <span><?= $escaper->escapeHtml(__('Out of stock')) ?></span>
            </p>
        <?php endif; ?>
    <?php endif; ?>
    </fieldset>
</div>
