<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<?php if ($_entity = $block->getEntity()): ?>
<div id="comments_block" class="edit-order-comments">
    <div class="order-history-block">
        <div class="admin__field field-row">
            <label class="admin__field-label"
                   for="history_comment"><?= $block->escapeHtml(__('Comment Text')) ?></label>
            <div class="admin__field-control">
                <textarea name="comment[comment]"
                          class="admin__control-textarea"
                          rows="3"
                          cols="5"
                          id="history_comment"></textarea>
            </div>
        </div>
        <div class="admin__field">
            <div class="order-history-comments-options">
                <?php if ($block->canSendCommentEmail()): ?>
                    <div class="admin__field admin__field-option">
                        <input name="comment[is_customer_notified]"
                               type="checkbox"
                               class="admin__control-checkbox"
                               id="history_notify"
                               value="1" />
                        <label class="admin__field-label"
                               for="history_notify"><?= $block->escapeHtml(__('Notify Customer by Email')) ?></label>
                    </div>
                <?php endif; ?>
                <div class="admin__field admin__field-option">
                    <input name="comment[is_visible_on_front]"
                           type="checkbox"
                           id="history_visible"
                           class="admin__control-checkbox"
                           value="1" />
                    <label class="admin__field-label"
                           for="history_visible"> <?= $block->escapeHtml(__('Visible on Storefront')) ?></label>
                </div>
            </div>
            <div class="order-history-comments-actions">
                <?= $block->getChildHtml('submit_button') ?>
            </div>
        </div>
    </div>

    <ul class="note-list">
        <?php foreach ($_entity->getCommentsCollection(true) as $_comment): ?>
            <li>
                <span class="note-list-date">
                    <?= /* @noEscape */ $block->formatDate($_comment->getCreatedAt(), \IntlDateFormatter::MEDIUM) ?>
                </span>
                <span class="note-list-time">
                    <?= /* @noEscape */ $block->formatTime($_comment->getCreatedAt(), \IntlDateFormatter::MEDIUM) ?>
                </span>
                <span class="note-list-customer">
                    <?= $block->escapeHtml(__('Customer')) ?>
                    <?php if ($_comment->getIsCustomerNotified()): ?>
                        <span class="note-list-customer-notified"><?= $block->escapeHtml(__('Notified')) ?></span>
                    <?php else: ?>
                        <span class="note-list-customer-not-notified">
                            <?= $block->escapeHtml(__('Not Notified')) ?>
                        </span>
                    <?php endif; ?>
                </span>
                <div class="note-list-comment">
                    <?= $block->escapeHtml($_comment->getComment(), ['b', 'br', 'strong', 'i', 'u', 'a']) ?>
                </div>
            </li>
        <?php endforeach; ?>
    </ul>
</div>
    <?php $scriptString = <<<script
require(['prototype'], function(){
    submitComment = function() {
        submitAndReloadArea($('comments_block').parentNode, '{$block->escapeJs($block->getSubmitUrl())}')
    };
    if ($('submit_comment_button')) {
        $('submit_comment_button').observe('click', submitComment);
    }
});
script;
    ?>
    <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
<?php endif; ?>
