<div class="container">
    <pre><?php print_r($selections); ?></pre>
    <pre><?php print_r($rooms); ?></pre>
    <?php 
        foreach ( $categories as $category ) :
            if ( empty($selections[$category]) ) {
                continue;
            }
    ?>
        <div class="row">
            <div class="bg-body sticky-top pt-2">
                <h5><?php echo $category; ?></h5>
            </div>
            <?php 
                foreach ( $selections[$category] as $selection ) :
                    if ( $selection['image'] ) {
                        $baseSrc  = URL_SELECTION_ATTACHMENTS;
                        $basePath = PATH_SELECTION_ATTACHMENTS;
            
                        $link = "$baseSrc/$selection[image]";
                        $dl   = $link;
                        $src  = $link;
                        if ( file_exists("$basePath/small/$selection[image]") ) {
                            $link = "$baseSrc/small/$selection[image]";
                            $src  = $link;
                        }
                        if ( file_exists("$basePath/thumbs/$selection[image]") ) {
                            $src = "$baseSrc/thumbs/$selection[image]";
                        }
                    } else {
                        $link = URL_ASSETS.'/images/btb-logo-abbr-trans.png';
                        $dl   = $link;
                        $src  = $link;
                    }
            ?>
                <div class="col-6 col-md-4 mb-3">
                    <div class="card">
                        <?php
                            $badgeClass = ( $selection['selected'] )
                                ? 'text-bg-success'
                                : 'text-bg-warning'
                            ;
                            $badgeText = ( $selection['selected'] )
                                ? 'Selected'
                                : 'Needs Selection'
                            ;
                        ?>
                        <?php if ( $selection['priority'] ) : ?>
                            <!-- <div class="position-absolute top-0 start-0 ps-2 pt-2" style="z-index:1;">
                                <span class="badge rounded-pill py-2 text-bg-danger shadow border">Priority</span>
                            </div> -->
                            <i class="bi bi-star-fill position-absolute text-danger fs-3 ms-2" title="Priority"></i>
                        <?php endif; ?>
                        <div class="position-absolute top-0 end-0 pe-2 pt-2" style="z-index:1;">
                            <span class="badge rounded-pill py-2 <?php echo $badgeClass; ?> shadow border"><?php echo $badgeText; ?></span>
                        </div>
                        <a href="<?php echo $link; ?>" class="lightboxLink position-relative" rel="btb-lb-<?php echo $selection['id']; ?>" data-fancybox="btb-selection-<?php echo $selection['id']; ?>" data-download-src="<?php echo $dl; ?>">
                            <img 
                                data-src="<?php echo $src; ?>" 
                                alt="<?php echo $userProject['title'] ?>" 
                                class="lazy card-img-top"
                            >
                        </a>
                        <div class="card-body">
                            <?php if ( $selection['link'] ) : ?>
                                <a href="<?php echo $selection['link']; ?>" target="_blank" class="card-title text-truncate fw-bold text-danger d-block">
                                    <?php echo $selection['title']; ?>
                                </a>
                            <?php else : ?>
                                <div class="card-title text-truncate fw-bold">
                                    <?php echo $selection['title']; ?>
                                </div>
                            <?php endif; ?>
                            <div class="d-flex justify-content-between">
                                <span class="small text-muted">
                                    <?php echo $selection['category']; ?> (<?php echo $selection['type']; ?>) 
                                </span>
                            </div>
                            <span class="small text-muted">
                                <?php echo $selection['level']; ?> Level <?php echo $selection['room']; ?>
                            </span>
                            <?php if ( $selection['description'] ) : ?>
                                <hr>
                                <p><?php echo $selection['description']; ?></p>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endforeach; ?>
</div>