<?php
    $attachmentId = $attachment['id'];
    switch ( $attachment['mimeType'] ) :
        case 'image/jpeg' :
        case 'image/png'  :
            if ( count($comment['attachments']) == 1 ) {
                $col     = 'col-12';
                $padding = '50%';
            } else {
                $col     = 'col-6';
                $padding = '75%';
            }

            $baseSrc  = URL_ATTACHMENTS;
            $basePath = PATH_ATTACHMENTS;

            $link = "$baseSrc/$attachment[pathname]";
            $dl   = $link;
            $src  = $link;
            if ( file_exists("$basePath/small/$attachment[pathname]") ) {
                $link = "$baseSrc/small/$attachment[pathname]";
                $src  = $link;
            }
            if ( file_exists("$basePath/thumbs/$attachment[pathname]") ) {
                $src = "$baseSrc/thumbs/$attachment[pathname]";
            }
?>
            <div class="<?php echo $col; ?> p-1">
                <div class="position-relative overflow-hidden" style="padding-bottom:<?php echo $padding; ?>;">
                    <a href="<?php echo $link; ?>" class="lightboxLink" rel="btb-lb-<?php echo $comment['id']; ?>" data-fancybox="btb-post-<?php echo $comment['id']; ?>" data-download-src="<?php echo $dl; ?>">
                        <img 
                            data-src="<?php echo $src; ?>" 
                            alt="<?php echo $userProject['title'] ?>" 
                            class="lazy img-thumbnail position-absolute object-fit-cover w-100 h-100"
                        >
                    </a>
                </div>
            </div>
<?php
            break;
        // case 'application/octet-stream':
            // if ( str_contains($attachment['name'], '.heic') || str_contains($attachment['name'], '.heif') ) :
                // $attachment['pathname'] = str_replace('.heic', '.heif', $attachment['pathname']);
                // $attachment['pathname'] = str_replace('.heif', '.jpg', $attachment['pathname']);
?>
                <!-- <div class="col-6 p-1">
                    <div class="position-relative overflow-hidden" style="padding-bottom:75%;">
                        <a href="<?php echo URL_ATTACHMENTS; ?>/<?php echo $attachment['pathname']; ?>" class="lightboxLink" rel="btb-lb-<?php echo $comment['id']; ?>">
                            <img 
                                data-src="<?php echo URL_ATTACHMENTS; ?>/thumbs/<?php echo $attachment['pathname']; ?>" 
                                onerror="this.onerror=null;this.src='<?php echo URL_ATTACHMENTS; ?>/<?php echo $attachment['pathname']; ?>';" 
                                alt="<?php echo $userProject['title'] ?>" 
                                class="lazy img-thumbnail position-absolute object-fit-cover w-100 h-100"
                            >
                        </a>
                    </div>
                </div> -->
<?php
            // endif;
            // break;
        case 'application/pdf' :
?> 
            <div class="col-6 text-center">
                <a href="<?php echo URL_ATTACHMENTS; ?>/<?php echo $attachment['pathname']; ?>" data-fancybox="<?php echo $attachment['id']; ?>" data-download-src="<?php echo $dl; ?>">
                    <img src="<?php echo URL_ASSETS; ?>/images/pdf-icon.png" class="img-fluid img-thumbnail"/>
                </a>
                <a href="<?php echo URL_ATTACHMENTS; ?>/<?php echo $attachment['pathname']; ?>" class="text-truncate text-danger d-block" data-fancybox="<?php echo $attachment['id']; ?>" data-download-src="<?php echo $dl; ?>">
                    <?php echo $attachment['pathname']; ?>
                </a>
            </div>
<?php
            break;
        case 'video/quicktime' :
        case 'video/mp4' :
?>
            <div class="col-12 p-1">
                <video width="100%" controls class="img-thumbnail">
                    <!-- <source src="<?php echo URL_ATTACHMENTS; ?>/<?php echo $attachment['pathname']; ?>" type="<?php echo $attachment['mimeType']; ?>"> -->
                    <source src="<?php echo URL_ATTACHMENTS; ?>/<?php echo $attachment['pathname']; ?>" type="video/mp4">
                </video>
            </div>
<?php
            break;
    endswitch;
?>