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

/** @var \Magento\Wishlist\Block\Share\Wishlist $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>

<?php if ($block->hasWishlistItems()): ?>
    <form class="form shared wishlist" action="<?= $block->escapeUrl($block->getUrl('wishlist/index/update')) ?>"
          method="post">
        <div class="wishlist table-wrapper">
            <table class="table data wishlist" id="wishlist-table">
                <caption class="table-caption"><?= $block->escapeHtml(__('Wish List')) ?></caption>
                <thead>
                <tr>
                    <th class="col product" scope="col"><?= $block->escapeHtml(__('Product')) ?></th>
                    <th class="col comment" scope="col"><?= $block->escapeHtml(__('Comment')) ?></th>
                    <th class="col actions" scope="col"><?= $block->escapeHtml(__('Add to Cart')) ?></th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($block->getWishlistItems() as $item): ?>
                    <?php
                    $product = $item->getProduct();
                    $isVisibleProduct = $product->isVisibleInSiteVisibility();
                    ?>
                    <tr>
                        <td data-th="<?= $block->escapeHtmlAttr(__('Product')) ?>" class="col product">
                            <a class="product photo" href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>"
                               title="<?= $block->escapeHtmlAttr($product->getName()) ?>">
                                <?= $block->getImage($product, 'customer_shared_wishlist')->toHtml() ?>
                            </a>
                            <strong class="product name">
                                <a href="<?= $block->escapeUrl($block->getProductUrl($item)) ?>">
                                    <?= $block->escapeHtml($product->getName()) ?>
                                </a>
                            </strong>
                            <?=
                                $block->getProductPriceHtml(
                                    $product,
                                    'wishlist_configured_price',
                                    \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
                                    ['item' => $item]
                                );
                            ?>
                            <?= $block->getDetailsHtml($item) ?>
                        </td>
                        <td data-th="<?= $block->escapeHtmlAttr(__('Comment')) ?>"
                            class="col comment"><?= /* @noEscape */ $block->getEscapedDescription($item) ?>
                        </td>
                        <td data-th="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>" class="col actions"
                            data-role="add-to-links">
                            <?php if ($product->isSaleable()): ?>
                                <?php if ($isVisibleProduct): ?>
                                    <button type="button"
                                            title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
                                            data-post='<?= /* @noEscape */ $block->getSharedItemAddToCartUrl($item) ?>'
                                            class="action tocart">
                                        <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                    </button>
                                <?php endif ?>
                            <?php endif; ?>
                            <a href="#" data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($item) ?>'
                               id="wishlist-shared-item-<?= /* @noEscape */ $item->getId() ?>"
                               class="action towishlist" data-action="add-to-wishlist">
                                <span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
                            </a>
                            <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
                                'onclick',
                                "location.assign(this.href); event.preventDefault();",
                                'a#wishlist-shared-item-' . $item->getId()
                            ) ?>
                        </td>
                    </tr>
                <?php endforeach ?>
                </tbody>
            </table>
        </div>

        <div class="actions-toolbar">
            <?php if ($block->isSaleable()): ?>
                <div class="primary">
                    <button type="button"
                            title="<?= $block->escapeHtmlAttr(__('Add All to Cart')) ?>"
                            data-post='<?= $block->escapeUrl($block->getSharedAddAllToCartUrl()) ?>'
                            class="action tocart primary">
                        <span><?= $block->escapeHtml(__('Add All to Cart')) ?></span>
                    </button>
                </div>
            <?php endif;?>
            <div class="secondary">
                <a href="<?= $block->escapeUrl($block->getBackUrl()) ?>" class="action back">
                    <span><?= $block->escapeHtml(__('Back')) ?></span>
                </a>
            </div>
        </div>
    </form>
<?php else: ?>
    <div class="message info empty"><div><?= $block->escapeHtml(__('Wish List is empty now.')) ?></div></div>
<?php endif ?>
