<?php
/**
 * Template View: Gallery Grid
 *
 * Image gallery display.
 *
 * @package    BoostBot
 * @subpackage Templates/Views
 * @since      1.6.0
 *
 * @var array  $images  Array of image objects with url, alt, and optional caption.
 * @var int    $columns Number of columns (2, 3, or 4).
 */

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

$columns = $columns ?? 3;
$columns = min( 4, max( 2, (int) $columns ) );
$cols_class = 'bb-gallery-cols-' . $columns;
?>

<div class="bb-gallery-grid <?php echo esc_attr( $cols_class ); ?>">
    <?php foreach ( $images as $image ) : 
        if ( empty( $image['url'] ) ) {
            continue;
        }
    ?>
        <div class="bb-gallery-item">
            <img src="<?php echo esc_url( $image['url'] ); ?>" 
                 alt="<?php echo esc_attr( $image['alt'] ?? '' ); ?>"
                 loading="lazy">
            <?php if ( ! empty( $image['caption'] ) ) : ?>
                <div class="bb-gallery-caption"><?php echo esc_html( $image['caption'] ); ?></div>
            <?php endif; ?>
        </div>
    <?php endforeach; ?>
</div>

