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

// @codingStandardsIgnoreFile

?>
<?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"><?= /* @escapeNotVerified */ __('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"><?= /* @escapeNotVerified */ __('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"> <?= /* @escapeNotVerified */ __('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">
                    <?= /* @escapeNotVerified */ __('Customer') ?>
                    <?php if ($_comment->getIsCustomerNotified()): ?>
                        <span class="note-list-customer-notified"><?= /* @escapeNotVerified */ __('Notified') ?></span>
                    <?php else: ?>
                        <span class="note-list-customer-not-notified"><?= /* @escapeNotVerified */ __('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>
<script>
require(['prototype'], function(){

submitComment = function() {
    submitAndReloadArea($('comments_block').parentNode, '<?= /* @escapeNotVerified */ $block->getSubmitUrl() ?>')
}

if ($('submit_comment_button')) {
    $('submit_comment_button').observe('click', submitComment);
}

});
</script>
<?php endif; ?>
