<?php
/**
 * Copyright © 2016 Magento. 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"><?php /* @escapeNotVerified */ echo __('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"><?php /* @escapeNotVerified */ echo __('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"> <?php /* @escapeNotVerified */ echo __('Visible on Storefront') ?></label>
                </div>
            </div>
            <div class="order-history-comments-actions">
                <?php echo $block->getChildHtml('submit_button') ?>
            </div>
        </div>
    </div>

    <ul class="note-list">
        <?php foreach ($_entity->getCommentsCollection(true) as $_comment): ?>
            <li>
                <span class="note-list-date"><?php /* @escapeNotVerified */ echo $block->formatDate($_comment->getCreatedAtDate(), \IntlDateFormatter::MEDIUM) ?></span>
                <span class="note-list-time"><?php /* @escapeNotVerified */ echo $block->formatTime($_comment->getCreatedAtDate(), \IntlDateFormatter::MEDIUM) ?></span>
                <span class="note-list-customer">
                    <?php /* @escapeNotVerified */ echo __('Customer') ?>
                    <?php if ($_comment->getIsCustomerNotified()): ?>
                        <span class="note-list-customer-notified"><?php /* @escapeNotVerified */ echo __('Notified') ?></span>
                    <?php else: ?>
                        <span class="note-list-customer-not-notified"><?php /* @escapeNotVerified */ echo __('Not Notified') ?></span>
                    <?php endif; ?>
                </span>
                <div class="note-list-comment"><?php echo $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, '<?php /* @escapeNotVerified */ echo $block->getSubmitUrl() ?>')
}

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

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