<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Blog Pro for Magento 2
 */
/** @var $block \Amasty\Blog\Block\Comments */
/** @var \Magento\Framework\Escaper $escaper */

$collection = $block->getCollection();
?>

<div data-amblog-js="livestream">
    <div class="amblog-comments-block" data-amblog-js="comments_wrapper">
        <?php if ($collection && $collection->getSize()): ?>
            <?php foreach ($collection as $message): ?>
                <?= /* @noEscape */ $block->getMessageHtml($message); ?>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
    <div class="amblog-comment-reply" id="amblog-comment-form"></div>
</div>

<script>
    require([
        'jquery',
        'Amasty_Blog/js/amblog/comments',
        'domReady!'
    ], function ($) {
        $('[data-amblog-js="livestream"]').amblogComments({
            form_selector: '.amblog-comment-reply',
            form_url: '<?= $escaper->escapeUrl($block->getFormUrl()) ?>',
            update_url: '<?= $escaper->escapeUrl($block->getUpdateUrl()) ?>',
            post_url: '<?= $escaper->escapeUrl($block->getPostUrl()) ?>',
            post_id: '<?= $escaper->escapeHtml($block->getPostId()); ?>',
            session_id: '<?= $escaper->escapeHtml($block->getSessionId()); ?>'
        });
    });
</script>
