<?php
/**
 * Template View: Bundle Product Item
 *
 * Shows a single product inside a bundle.
 * Requires Pro + Bundles license.
 *
 * @package    BoostBot
 * @subpackage Templates/Views
 * @since      1.6.0
 *
 * @var int    $id             Product ID.
 * @var string $name           Product name.
 * @var string $image          Product image URL.
 * @var float  $price          Original price.
 * @var float  $bundle_price   Price in bundle.
 * @var int    $quantity       Quantity in bundle.
 */

// phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-scope variables set by the includer, not true globals.

// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Validate required data
if ( empty( $name ) ) {
    return;
}

$quantity = $quantity ?? 1;
$has_discount = ! empty( $price ) && ! empty( $bundle_price ) && $price > $bundle_price;
?>

<div class="bb-bundle-product-item-full">
    <div class="bb-bpi-image">
        <?php if ( ! empty( $image ) ) : ?>
            <img src="<?php echo esc_url( $image ); ?>" alt="<?php echo esc_attr( $name ); ?>">
        <?php else : ?>
            <span class="bb-bpi-placeholder">📦</span>
        <?php endif; ?>
        <?php if ( $quantity > 1 ) : ?>
            <span class="bb-bpi-quantity">x<?php echo esc_html( $quantity ); ?></span>
        <?php endif; ?>
    </div>
    
    <div class="bb-bpi-info">
        <div class="bb-bpi-name"><?php echo esc_html( $name ); ?></div>
        <div class="bb-bpi-pricing">
            <?php if ( $has_discount ) : ?>
                <span class="bb-bpi-original">₪<?php echo esc_html( number_format( $price, 0 ) ); ?></span>
                <span class="bb-bpi-bundle-price">₪<?php echo esc_html( number_format( $bundle_price, 0 ) ); ?></span>
            <?php elseif ( ! empty( $price ) ) : ?>
                <span class="bb-bpi-price">₪<?php echo esc_html( number_format( $price, 0 ) ); ?></span>
            <?php endif; ?>
        </div>
    </div>
    
    <?php if ( $has_discount ) : ?>
        <div class="bb-bpi-check">✓</div>
    <?php endif; ?>
</div>
