<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_FrequentlyBought
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */
?>
<?php /** @var Magento\GroupedProduct\Block\Product\View\Type\Grouped $block */ ?>
<?php $block->setPreconfiguredValue(); ?>
<?php $_product = $block->getProduct(); ?>
<?php $_associatedProducts = $block->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>

<div class="table-wrapper mageplaza-fbt-grouped">
    <table class="table data grouped" id="mageplaza-fbt-super-product-table-<?php /* @noEscape */ echo $_product->getId(); ?>">
        <caption class="table-caption"><?php /* @escapeNotVerified */ echo __('Grouped product items') ?></caption>
        <thead>
        <tr>
            <th class="col item" scope="col"><?php /* @escapeNotVerified */ echo __('Product Name') ?></th>
            <?php if ($_product->isSaleable()): ?>
                <th class="col qty" scope="col"><?php /* @escapeNotVerified */ echo __('Qty') ?></th>
            <?php endif; ?>
        </tr>
        </thead>

        <?php if ($_hasAssociatedProducts): ?>
            <?php foreach ($_associatedProducts as $_item): ?>
        <tbody>
            <tr>
                <td data-th="<?php echo $block->escapeHtml(__('Product Name')); ?>" class="col item">
                    <strong class="product-item-name"><?php echo $block->escapeHtml($_item->getName()) ?></strong>
                    <?php if ($block->getCanShowProductPrice($_product)): ?>
                        <?php if ($block->getCanShowProductPrice($_item)): ?>
                            <?php /* @escapeNotVerified */ echo $block->getProductPrice($_item) ?>
                        <?php endif; ?>
                        <?php endif; ?>
                </td>
                <?php if ($_product->isSaleable()): ?>
                <td data-th="<?php echo $block->escapeHtml(__('Qty')); ?>" class="col qty">
                    <?php if ($_item->isSaleable()): ?>
                    <div class="control qty">
                        <label>
                            <input type="number" name="super_group[<?php /* @escapeNotVerified */ echo $_product->getId() ?>][<?php /* @escapeNotVerified */ echo $_item->getId() ?>]"
                                   data-selector="super_group[<?php /* @escapeNotVerified */ echo $_product->getId() ?>][<?php /* @escapeNotVerified */ echo $_item->getId() ?>]"
                                   maxlength="12"
                                   value="<?php /* @escapeNotVerified */ echo $_item->getQty() * 1 ?>"
                                   title="<?php /* @escapeNotVerified */ echo __('Qty') ?>"
                                   class="input-text qty mageplaza-fbt-grouped-qty"
                                   data-validate="{'validate-grouped-qty':'#mageplaza-fbt-super-product-table-<?php /* @noEscape */ echo $_product->getId(); ?>'}"
                                   data-errors-message-box="#mageplaza-fbt-validation-message-box-<?php /* @noEscape */ echo $_product->getId(); ?>"
                                   data-child-product-id="<?php /* @escapeNotVerified */ echo $_item->getId() ?>"
                                   data-child-product-price-amount="<?php /* @noEscape */ echo $_item->getPriceInfo()->getPrice('final_price')->getAmount()->getValue()?>"
                                   data-child-product-price-total="0"/>
                        </label>
                    </div>
                <?php else: ?>
                    <div class="stock unavailable" title="<?php /* @escapeNotVerified */ echo __('Availability') ?>">
                        <span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span>
                    </div>
                <?php endif; ?>
                </td>
                <?php endif; ?>
            </tr>
                <?php if ($block->getCanShowProductPrice($_product)
                && $block->getCanShowProductPrice($_item)
                && trim($block->getProductPriceHtml(
                    $_item,
                    \Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE
                ))): ?>
                <tr class="row-tier-price">
                    <td colspan="2">
                        <?php echo $block->getProductPriceHtml(
                            $_item,
                            \Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE
                        ) ?>
                    </td>
                </tr>
            <?php endif; ?>
        </tbody>
        <?php endforeach; ?>
        <?php else: ?>
        <tbody>
            <tr>
                <td class="unavailable"
                    colspan="<?php if ($_product->isSaleable()): ?>4<?php else: ?>3<?php endif; ?>">
                    <?php /* @escapeNotVerified */ echo __('No options of this product are available.') ?>
                </td>
            </tr>
        </tbody>
        <?php endif; ?>
    </table>
</div>
<div id="mageplaza-fbt-validation-message-box-<?php /* @noEscape */ echo $_product->getId(); ?>"></div>
