<?php
/**
 * Copyright © Magefan (support@magefan.com). All rights reserved.
 * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
 *
 * Glory to Ukraine! Glory to the heroes!
 */
?>
<?php
/**
 * Blog post comments template
 *
 * @var $block \Magefan\Blog\Block\Post\View\Comments\Magefan\Comment
 */
?>
<?php
    $comment = $block->getComment();
    $numberOfCommentsToDisplay = $block->getNumberOfReplies();
?>
<div class="c-comment c-comment-parent-<?= (int)$comment->getParentId() ?>"
    <?php if ($comment->getIsHidden()) { echo 'style="display:none"'; } ?>>
    <?php if ($authorImage = $comment->getAuthorImage()) { ?>
    <div class="c-img">
        <img src="<?= $block->escapeUrl($authorImage) ?>" alt="<?= $block->escapeHtml($comment->getAuthorName()) ?>">
    </div>
    <?php } ?>
    <div class="c-post c-post-<?= (int)$comment->getId() ?>" id="c-post-<?= (int)$comment->getId() ?>">
        <div class="p-info">
            <div class="p-name"><?= $block->escapeHtml($comment->getAuthor()->getNickname()) ?></div>
            <div class="publish-date"><?php echo $block->escapeHtml($block->getPublishDate()) ?></div>
        </div>

        <div class="p-text"><?= /*@noEscape*/ nl2br($block->escapeHtml($comment->getText())) ?></div>
        <div class="p-actions">
            <a href="#" class="reply-action"
               data-comment="<?= $comment->isReply() ?
                   (int)$comment->getParentId() :
                   (int)$comment->getId() ?>"
               title="<?= $block->escapeHtml(__('Reply')) ?>"><?= $block->escapeHtml(__('Reply')) ?></a>
        </div>
        <?php
            $replies = $block->getRepliesCollection();
            $commentsCount = count($replies);
        if ($commentsCount) {
            ?>
            <div class="p-replies">
            <?php $i = 0 ?>
            <?php foreach ($replies as $reply) { ?>
                    <?php
                        $i++;
                        $reply->setIsHidden($i > $numberOfCommentsToDisplay);
                    ?>
                    <?= /*@noEscape*/ $block->setComment($reply)->toHtml() ?>
                <?php } ?>

                <?php if ($commentsCount > $numberOfCommentsToDisplay) { ?>
                <div class="c-more more-comments-action" data-comment="<?= (int)$comment->getId() ?>">
                    <a href="#" ><?= $block->escapeHtml(__('Show more replies in this thread')) ?><i></i></a>
                </div>
                <?php } ?>
            </div>
        <?php } ?>
    </div>
</div>
