<?php
/**
 * Template View: Product Mini
 *
 * Compact product display for use inside bundles.
 *
 * @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          Current price.
 * @var float  $original_price Original price (if on sale).
 * @var float  $rating         Rating (1-5).
 */

// 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 ) || ! isset( $price ) ) {
    return;
}

$is_on_sale = ! empty( $original_price ) && $original_price > $price;
$has_rating = ! empty( $rating ) && $rating > 0;
?>

<div class="bb-product-mini">
    <?php if ( ! empty( $image ) ) : ?>
        <div class="bb-product-mini-image">
            <img src="<?php echo esc_url( $image ); ?>" alt="<?php echo esc_attr( $name ); ?>">
            <?php if ( $is_on_sale ) : ?>
                <span class="bb-product-mini-badge"><?php esc_html_e( 'מבצע', 'boostbot' ); ?></span>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    
    <div class="bb-product-mini-info">
        <div class="bb-product-mini-name"><?php echo esc_html( $name ); ?></div>
        <?php if ( $has_rating ) : ?>
            <div class="bb-product-mini-rating">
                <span class="bb-rating-star">⭐</span>
                <span class="bb-rating-value"><?php echo esc_html( number_format( $rating, 1 ) ); ?></span>
            </div>
        <?php endif; ?>
    </div>
    
    <div class="bb-product-mini-prices">
        <span class="bb-product-mini-price">₪<?php echo esc_html( number_format( $price, 0 ) ); ?></span>
        <?php if ( $is_on_sale ) : ?>
            <span class="bb-product-mini-original">₪<?php echo esc_html( number_format( $original_price, 0 ) ); ?></span>
        <?php endif; ?>
    </div>
</div>

