<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Prodigy\includes\content\Prodigy_Product_Parser;
use Prodigy\Includes\Helpers\Prodigy_Formatting;
?>
<!-- qty -->
<?php if ( ! empty( $product->get_tiered_prices() ) ) : ?>
	<div class="prodigy-tabs__desc prodigy-custom-template" id="prodigy-tabs__desc-qty">
		<p class="prodigy-tab__tiered-info">
			<?php esc_html_e( 'Below is information about wholesale prices for the product, as well as your savings.', 'prodigy-commerce' ); ?>
		</p>
		<div class="prodigy-table__bulk-qty-description">
			<div class="prodigy-table__bulk-qty-description-head d-flex w-100">
				<div class="prodigy-table__bulk-head-cell flex-shrink-1"><?php esc_html_e( 'Quantity', 'prodigy-commerce' ); ?></div>
				<div class="prodigy-table__bulk-head-cell flex-grow-1 text-center"><?php esc_html_e( 'Price per unit', 'prodigy-commerce' ); ?></div>
				<div class="prodigy-table__bulk-head-cell flex-shrink-1 text-right"><?php esc_html_e( 'You save', 'prodigy-commerce' ); ?></div>
			</div>
			<?php foreach ( $product->get_tiered_prices() as $key => $price ) : ?>
				<div class="prodigy-table__bulk-qty-description-cell w-100">
					<div class="flex-1 prodigy-table__bulk-body-cell">
						<?php if ( $price['attributes']['min-quantity'] === $price['attributes']['max-quantity'] ) : ?>
							<span><?php echo esc_attr( $price['attributes']['min-quantity'] ); ?></span>
						<?php elseif ( $price['attributes']['max-quantity'] === Prodigy_Product_Parser::MAX_RANGE_LIMIT ) : ?>
							<span><?php echo esc_attr( $price['attributes']['min-quantity'] ); ?>+</span>
						<?php else : ?>
							<span><?php echo esc_attr( $price['attributes']['min-quantity'] ); ?>-<?php echo esc_attr( $price['attributes']['max-quantity'] ); ?></span>
						<?php endif; ?>
					</div>
					<div class="flex-1 prodigy-table__bulk-body-cell">
						<span>
							<span><?php echo esc_attr( get_option( 'pg_currency_type' ) ); ?></span><?php echo esc_attr( Prodigy_Formatting::prodigy_price_format( $price['attributes']['flat-price'] ) ); ?>
						</span>
					</div>
					<div class="flex-1 prodigy-table__bulk-body-cell">
						<span><?php echo wp_kses( $price['attributes']['discount'], Prodigy_Formatting::get_allowed_html() ); ?></span>
					</div>
				</div>
			<?php endforeach; ?>
		</div>
	</div>
<?php endif; ?>
<!-- end qty -->
