<div id="btb-post-<?php echo $comment['id']; ?>" class="<?php echo $cc; ?> card <?php if ( ($cc + 1) != count($comments) ) : ?>mb-4<?php else : ?>mb-2<?php endif; ?>">
    <div class="card-header">
        <div class="d-flex justify-content-between">
            <div class="d-flex">
<?php
                if ( !file_exists(PATH_ASSETS.'/images/avatar/'.$comment['createdByName'].'.jpg')) :
                    $parts    = explode(' ', $comment['createdByName']);
                    $initials = substr($parts[0], 0, 1) . substr(end($parts), 0, 1);
?>
                    <div class="initial-avatar flex-shrink-0 me-2" alt="<?php echo $comment['createdByName']; ?>" title="<?php echo $comment['createdByName']; ?>"><?php echo $initials; ?></div>
<?php
                else :
?>
                    <img src="<?php echo URL_ASSETS; ?>/images/avatar/<?php echo $comment['createdByName']; ?>.jpg" alt="<?php echo $comment['createdByName']; ?>" title="<?php echo $comment['createdByName']; ?>" class="avatar-small">
<?php
                endif;
?>
                <div class="flex-1 align-self-center ms-2">
                    <p class="mb-0"><span class="fw-bold"><?php echo $comment['createdByName']; ?></span> posted an update</p>
                    <small class="text-muted"><?php echo time_elapsed_string($comment['createdAt']); ?> &#183; <?php echo $comment['city']; ?>, <?php echo COMPANY_STATE_ABBR; ?></small>
                </div>
            </div>
        </div>
    </div>
    <div id="btb-post-body-<?php echo $comment['id']; ?>" class="card-body">
        <p class="mb-0"><?php echo nl2br(htmlspecialchars($comment['text'])); ?></p>
        <div class="row mt-2">
<?php
            foreach ( $comment['attachments'] as $attachment ) {
                include 'template/comment-attachment.php';
            }
?>
        </div>
    </div>
    <div id="btb-post-footer-<?php echo $comment['id']; ?>" class="card-footer" style="background-color: var(--bs-tertiary-bg);">
        <span>
            <a id="btb-post-like-count-<?php echo $comment['id']; ?>" <?php if ( $comment['likedBy'] ) : ?>data-bs-toggle="tooltip" data-bs-html="true" data-bs-title="<?php echo $comment['likedBy']; ?>" <?php endif; ?> class="text-danger" role="button"><?php echo $likeText; ?></a>
            &#183;
            <a id="btb-post-comment-count-<?php echo $comment['id']; ?>" onclick="document.getElementById('textarea-<?php echo $comment['id']; ?>').scrollIntoView();" class="text-danger" role="button">
                <?php echo ( count($comment['replies']) > 0 ) ? count($comment['replies']) : 0; ?> Comments
            </a>
            </span>
        <hr>
        <div class="d-flex">
            <button id="btb-post-like-btn-<?php echo $comment['id']; ?>" class="btn p-0 btbLike btbAction" data-comment-id="<?php echo $comment['id']; ?>" data-action="click" data-target="like/dislike comment id <?php echo $comment['id']; ?>">
                <span id="btb-post-like-icon-<?php echo $comment['id']; ?>" class="btbLikeIcon">
                    <?php if ( in_array($comment['id'], $userLikes) ) : ?>
                        <i class="bi bi-hand-thumbs-up-fill text-danger"></i>
                    <?php else : ?>
                        <i class="bi bi-hand-thumbs-up"></i>
                    <?php endif; ?>
                </span>
                <span class="text-muted ms-1">Like</span>
            </button>
            <a id="btb-post-comment-btn-<?php echo $comment['id']; ?>" onclick="document.getElementById('textarea-<?php echo $comment['id']; ?>').focus();" class="btn p-0 ms-3">
                <i class="bi bi-chat"></i>
                <span class="text-muted ms-1">Comment</span>
            </a>
        </div>
        <hr>
        <div id="btb-post-comments-<?php echo $comment['id']; ?>" class="d-flex mb-4">
<?php
            if ( isset($user['client']) || !file_exists(PATH_ASSETS.'/images/avatar/'.$user['name'].'.jpg')) :
                $parts    = explode(' ', $user['name']);
                $initials = substr($parts[0], 0, 1) . substr(end($parts), 0, 1);
?>
                <div class="initial-avatar flex-shrink-0 me-2" alt="<?php echo $user['name']; ?>" title="<?php echo $user['name']; ?>"><?php echo $initials; ?></div>
<?php
            else : 
?>
                <img src="<?php echo URL_ASSETS; ?>/images/avatar/<?php echo $user['name']; ?>.jpg" alt="<?php echo $user['name']; ?>" title="<?php echo $user['name']; ?>" class="avatar-small me-2">
<?php
            endif; 
?>
            <div class="input-group">
                <textarea id="textarea-<?php echo $comment['id']; ?>" class="form-control border-end-0 p-2" placeholder="Write a comment..." rows="1" style="resize:none;"></textarea>
                <button style="" id="btb-post-reply-btn-<?php echo $comment['id']; ?>" class="btn border border-start-0 btbPostComment btbAction" type="button" data-comment-id="<?php echo $comment['id']; ?>" data-action="click" data-target="reply to comment id <?php echo $comment['id']; ?> button">
                    <i class="bi bi-send text-danger"></i>
                </button>
            </div>
        </div>
        <div id="btb-post-replies-<?php echo $comment['id']; ?>">
<?php
            $i = 0;
            $collapse = false;
            foreach ( $comment['replies'] as $reply ) {
                $replyLikeText = ( count($reply['likes']) == 1 )
                    ? count($reply['likes']).' Like'
                    : count($reply['likes']).' Likes'
                ;
                
                if ( $i == 3 ) :
                    $collapse = true;
?>
                    <div id="btb-reply-collapse-container-<?php echo $comment['id']; ?>" class="d-flex justify-content-center mb-4">
                        <a id="btb-reply-collapse-toggle-<?php echo $comment['id']; ?>" class="text-danger" data-bs-toggle="collapse" href="#btb-reply-collapse-<?php echo $comment['id']; ?>" role="button" onclick="this.textContent = ( this.textContent == 'Show fewer' ) ? 'Show more' : 'Show fewer';">Show more</a>
                    </div>
                    <div id="btb-reply-collapse-<?php echo $comment['id']; ?>" class="collapse">
<?php
                endif;
                include 'template/comment-reply.php';
                $i++;
            }
            if ( $collapse ) :
?>
                </div>
<?php
            endif;
?>
        </div>
    </div>
</div>