<?php
/**
 * Template View: Order Summary
 *
 * Order/cart summary display.
 *
 * @package    BoostBot
 * @subpackage Templates/Views
 * @since      1.6.0
 *
 * @var array  $items     Array of item objects with name, quantity, price.
 * @var float  $subtotal  Subtotal before discounts.
 * @var float  $discount  Discount amount (optional).
 * @var float  $shipping  Shipping cost (optional).
 * @var float  $total     Final total.
 * @var string $currency  Currency symbol (optional, defaults to ₪).
 */

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

$currency = $currency ?? '₪';
?>

<div class="bb-order-summary">
    <div class="bb-order-header">
        <span class="bb-order-icon">🛒</span>
        <span class="bb-order-title"><?php esc_html_e( 'סיכום הזמנה', 'boostbot' ); ?></span>
    </div>
    
    <div class="bb-order-items">
        <?php foreach ( $items as $item ) : 
            if ( empty( $item['name'] ) ) {
                continue;
            }
            $qty = $item['quantity'] ?? 1;
            $price = $item['price'] ?? 0;
        ?>
            <div class="bb-order-item">
                <div class="bb-item-info">
                    <span class="bb-item-name"><?php echo esc_html( $item['name'] ); ?></span>
                    <?php if ( $qty > 1 ) : ?>
                        <span class="bb-item-qty">x<?php echo esc_html( $qty ); ?></span>
                    <?php endif; ?>
                </div>
                <span class="bb-item-price"><?php echo esc_html( $currency . number_format( $price, 0 ) ); ?></span>
            </div>
        <?php endforeach; ?>
    </div>
    
    <div class="bb-order-totals">
        <?php if ( isset( $subtotal ) ) : ?>
            <div class="bb-order-row">
                <span><?php esc_html_e( 'סכום ביניים', 'boostbot' ); ?></span>
                <span><?php echo esc_html( $currency . number_format( $subtotal, 0 ) ); ?></span>
            </div>
        <?php endif; ?>
        
        <?php if ( ! empty( $discount ) && $discount > 0 ) : ?>
            <div class="bb-order-row bb-discount-row">
                <span><?php esc_html_e( 'הנחה', 'boostbot' ); ?></span>
                <span>-<?php echo esc_html( $currency . number_format( $discount, 0 ) ); ?></span>
            </div>
        <?php endif; ?>
        
        <?php if ( isset( $shipping ) ) : ?>
            <div class="bb-order-row">
                <span><?php esc_html_e( 'משלוח', 'boostbot' ); ?></span>
                <span><?php echo $shipping > 0 ? esc_html( $currency . number_format( $shipping, 0 ) ) : esc_html__( 'חינם', 'boostbot' ); ?></span>
            </div>
        <?php endif; ?>
        
        <div class="bb-order-row bb-total-row">
            <span><?php esc_html_e( 'סה"כ לתשלום', 'boostbot' ); ?></span>
            <span class="bb-order-total"><?php echo esc_html( $currency . number_format( $total, 0 ) ); ?></span>
        </div>
    </div>
</div>
