<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Cart $block */

/** @var \Magento\Wishlist\Model\Item $item */
$item = $block->getItem();
$product = $item->getProduct();
/** @var \Magento\Wishlist\ViewModel\AllowedQuantity $viewModel */
$viewModel = $block->getData('allowedQuantityViewModel');
$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">
            <label class="label" for="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]"><span><?= $block->escapeHtml(__('Qty')) ?></span></label>
            <div class="control">
                <input type="number" data-role="qty" id="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]" class="input-text qty" data-validate="{'required-number':true,'validate-greater-than-zero':true, 'validate-item-quantity':{'minAllowed':<?= /* @noEscape */ $allowedQty['minAllowed'] ?>,'maxAllowed':<?= /* @noEscape */ $allowedQty['maxAllowed'] ?>}}"
               name="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]" value="<?= /* @noEscape */ $block->getAddToCartQty($item) * 1 ?>" <?= $product->isSaleable() ? '' : 'disabled="disabled"' ?>>
            </div>
        </div>
    <?php endif; ?>
    <?php if ($product->isSaleable()) : ?>
    <div class="product-item-actions">
        <div class="actions-primary">
            <button type="button" data-role="tocart" data-post='<?= /* @noEscape */ $block->getItemAddToCartParams($item) ?>' title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>" data-item-id="<?= $block->escapeHtmlAttr($item->getId()) ?>" class="action tocart action btn btn-primary primary">
                <span class="fa fa-shopping-cart"></span>
                <span class="text"><?= $block->escapeHtml(__('Add to Cart')) ?></span>
            </button>
        </div>
    </div>
    <?php else : ?>
        <?php if ($product->getIsSalable()) : ?>
            <p class="available stock" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
                <span><?= $block->escapeHtml(__('In stock')) ?></span>
            </p>
        <?php else : ?>
            <p class="unavailable stock" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
                <span><?= $block->escapeHtml(__('Out of stock')) ?></span>
            </p>
        <?php endif; ?>
    <?php endif; ?>
    </fieldset>
</div>
