<?php
/** @var \Magetop\Advancepreview\Block\CustomProduct $block */
$productId = $block->getRequest()->getParam('product',0);
$qty = $block->getRequest()->getParam('qty',1);
$tierPrices = $block->getTierPriceByProductId($productId);
$ourPrice = $block->getTierPriceItemByQty($tierPrices, $qty);
$previewDiscount = $block->getCustomPreviewDiscount($productId);
$customerGroup = $block->getCustomerGroup();
$colPriceClass = 'custom-tier-price-price';
if($customerGroup > 1) {
    $colPriceClass = 'custom-tier-price-price-big';
}

?>

<?php if(count($tierPrices)) : ?>
    <div class="custom-tier-price-item">
        <span class="custom-tier-price-qty">
            <?php echo __('QUANTITY') ?>
        </span>
        <span class="<?php echo $colPriceClass; ?>">
            <?php echo __('pcs') ?>
        </span>
        <?php if ($customerGroup > 0) : ?>
            <span class="<?php echo $colPriceClass; ?>">
                <?php echo __('Discount (%1', $previewDiscount) ?>%)
            </span>
        <?php endif; ?>
    </div>
    <?php $i = 0; ?>
    <?php foreach ($tierPrices as $tierPrice) : ?>
        <?php $i++ ?>
        <?php
        $qty = (int)$tierPrice['price_qty'];
        $class = 'custom-tier-price-item';
        if($i == count($tierPrices)) {
            $class .= ' custom-tier-price-item-last';
        }
        if($ourPrice == $tierPrice['price']) {
            $class .= ' custom-tier-price-item-active';
        }

        ?>


        <div class="<?php echo $class; ?>" id="custom-tier-price-item-<?php echo $qty; ?>">
            <span class="custom-tier-price-qty">
                <?php echo $i == 1 ? '1 - ' .$qty : $qty; ?>
            </span>
            <span class="<?php echo $colPriceClass; ?>">
                 <?php echo $block->convertNumberToPrice($tierPrice['price'])?>
            </span>
            <?php if ($customerGroup > 0) : ?>
                <?php $priceDiscount = $tierPrice['price'] - (($tierPrice['price'] * $previewDiscount) / 100) ?>
                <span class="<?php echo $colPriceClass; ?>">
                 <?php echo $block->convertNumberToPrice($priceDiscount)?>
                </span>
            <?php endif; ?>

        </div>
    <?php endforeach; ?>
<?php endif; ?>

