<?php
/**
 * Copyright 2014 Adobe
 * All Rights Reserved.
 */

// phpcs:disable Magento2.Templates.ThisInTemplate
// phpcs:disable Generic.Files.LineLength

/** @var $block \Magento\Checkout\Block\Cart\Item\Renderer */
/** @var \Magento\Framework\Escaper $escaper */

$_item = $block->getItem();
$product = $_item->getProduct();
$isVisibleProduct = $product->isVisibleInSiteVisibility();
/** @var \Magento\Msrp\Helper\Data $helper */
$helper = $this->helper(Magento\Msrp\Helper\Data::class);
$canApplyMsrp = $helper->isShowBeforeOrderConfirm($product) && $helper->isMinimalPriceLessMsrp($product);
?>
<tbody class="cart item">
    <tr class="item-info">
        <td data-th="<?= $escaper->escapeHtml(__('Item')) ?>" class="col item">
            <?php if ($block->hasProductUrl()): ?>
                <a href="<?= $escaper->escapeUrl($block->getProductUrl()) ?>"
                   title="<?= $escaper->escapeHtml($block->getProductName()) ?>"
                   tabindex="-1"
                   class="product-item-photo">
            <?php else: ?>
                <span class="product-item-photo">
            <?php endif; ?>
            <?= $block->getImage($block->getProductForThumbnail(), 'cart_page_product_thumbnail')->toHtml() ?>
            <?php if ($block->hasProductUrl()): ?>
                </a>
            <?php else: ?>
                </span>
            <?php endif; ?>
            <div class="product-item-details">
                <strong class="product-item-name">
                    <?php if ($block->hasProductUrl()): ?>
                        <a href="<?= $escaper->escapeUrl($block->getProductUrl()) ?>"><?= $escaper->escapeHtml($block->getProductName()) ?></a>
                    <?php else: ?>
                        <?= $escaper->escapeHtml($block->getProductName()) ?>
                    <?php endif; ?>
                </strong>
                <?php if ($_options = $block->getOptionList()): ?>
                    <dl class="item-options">
                        <?php foreach ($_options as $_option): ?>
                            <?php $_formatedOptionValue = $block->getFormatedOptionValue($_option) ?>
                            <dt><?= $escaper->escapeHtml($_option['label']) ?></dt>
                            <dd>
                                <?php if (isset($_formatedOptionValue['full_view'])): ?>
                                        <?= $escaper->escapeHtml($_formatedOptionValue['full_view'], ['span', 'a']) ?>
                                    <?php else: ?>
                                        <?= $escaper->escapeHtml($_formatedOptionValue['value'], ['span', 'a']) ?>
                                <?php endif; ?>
                            </dd>
                        <?php endforeach; ?>
                    </dl>
                <?php endif; ?>
                <?php if ($messages = $block->getMessages()): ?>
                    <?php foreach ($messages as $message): ?>
                        <div class="cart item message <?= $escaper->escapeHtmlAttr($message['type']) ?>">
                            <div><?= $escaper->escapeHtml($message['text']) ?></div>
                        </div>
                    <?php endforeach; ?>
                <?php endif; ?>
                <?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
                <?php if ($addInfoBlock): ?>
                    <?= $addInfoBlock->setItem($_item)->toHtml() ?>
                <?php endif; ?>
            </div>
        </td>

        <?php if ($canApplyMsrp): ?>
            <td class="col msrp" data-th="<?= $escaper->escapeHtml(__('Price')) ?>">
                <span class="pricing msrp">
                    <span class="msrp notice"><?= $escaper->escapeHtml(__('See price before order confirmation.')) ?></span>
                    <?php $helpLinkId = 'cart-msrp-help-' . $_item->getId(); ?>
                    <a href="#" class="action help map"
                       id="<?= ($escaper->escapeHtmlAttr($helpLinkId)) ?>"
                       data-mage-init='{"addToCart":{
                                            "origin": "info",
                                            "helpLinkId": "#<?= $escaper->escapeJs($escaper->escapeHtml($helpLinkId)) ?>",
                                            "productName": "<?= $escaper->escapeJs($escaper->escapeHtml($product->getName())) ?>",
                                            "showAddToCart": false
                                            }
                                        }'
                    >
                        <span><?= $escaper->escapeHtml(__("What's this?")) ?></span>
                    </a>
                </span>
            </td>
        <?php else: ?>
            <td class="col price" data-th="<?= $escaper->escapeHtml(__('Price')) ?>">
                <?= $block->getUnitPriceHtml($_item) ?>
            </td>
        <?php endif; ?>
        <td class="col qty" data-th="<?= $escaper->escapeHtml(__('Qty')) ?>">
            <div class="field qty">
                <div class="control qty">
                    <label for="cart-<?= $escaper->escapeHtmlAttr($_item->getId()) ?>-qty">
                        <span class="label"><?= $escaper->escapeHtml(__('Qty')) ?></span>
                        <input id="cart-<?= $escaper->escapeHtmlAttr($_item->getId()) ?>-qty"
                               name="cart[<?= $escaper->escapeHtmlAttr($_item->getId()) ?>][qty]"
                               data-cart-item-id="<?= $escaper->escapeHtmlAttr($_item->getSku()) ?>"
                               value="<?= $escaper->escapeHtmlAttr($block->getQty()) ?>"
                               type="number"
                               min="0"
                               size="4"
                               step="any"
                               title="<?= $escaper->escapeHtmlAttr(__('Qty')) ?>"
                               class="input-text qty"
                               data-validate="{required:true,'validate-greater-than-zero':true}"
                               data-item-qty="<?= $escaper->escapeHtmlAttr($block->getQty()) ?>"
                               data-role="cart-item-qty"/>
                    </label>
                </div>
            </div>
        </td>

        <td class="col subtotal" data-th="<?= $escaper->escapeHtml(__('Subtotal')) ?>">
            <?php if ($canApplyMsrp): ?>
                <span class="cart msrp subtotal">--</span>
            <?php else: ?>
                <?= $block->getRowTotalHtml($_item) ?>
            <?php endif; ?>
        </td>
    </tr>
    <tr class="item-actions">
        <td colspan="4">
            <div class="actions-toolbar">
                <?= /* @noEscape */ $block->getActions($_item) ?>
            </div>
        </td>
    </tr>
</tbody>
