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

/** @var \Magento\Sales\Block\Adminhtml\Order\Create\Totals $block */
?>
<legend class="admin__legend"><span><?= $block->escapeHtml(__('Order Totals')) ?></span></legend>
<br>

<table class="admin__table-secondary data-table">
    <tbody>
        <?= /* @noEscape */ $block->renderTotals() ?>
        <?= /* @noEscape */ $block->renderTotals('footer') ?>
    </tbody>
</table>

<div class="order-totals-actions">
    <div class="admin__field admin__field-option field-append-comments">
        <input type="checkbox" id="notify_customer" name="order[comment][customer_note_notify]"
               value="1"<?php if ($block->getNoteNotify()) : ?> checked="checked"<?php endif; ?>
               class="admin__control-checkbox"/>
        <label for="notify_customer" class="admin__field-label"><?= $block->escapeHtml(__('Append Comments')) ?></label>
    </div>
    <?php if ($block->canSendNewOrderConfirmationEmail()) : ?>
    <div class="admin__field admin__field-option field-email-order-confirmation">
        <input type="checkbox" id="send_confirmation" name="order[send_confirmation]" value="1" checked="checked"
               class="admin__control-checkbox"/>
        <label for="send_confirmation" class="admin__field-label"><?= $block->escapeHtml(__('Email Order Confirmation')) ?></label>
    </div>
    <?php endif; ?>
    <div class="actions">
        <?= $block->getButtonHtml(__('Submit Order'), 'order.submit()', 'save primary') ?>
    </div>
</div>

<script>
require(['prototype'], function(){

//<![CDATA[
var sendEmailCheckbox = $('send_confirmation');
if (sendEmailCheckbox) {
    Event.observe(sendEmailCheckbox, 'change', notifyCustomerUpdate);
    notifyCustomerUpdate();
}

function notifyCustomerUpdate() {
    var sendEmailCheckbox = $('send_confirmation');
    var notifyCustomerCheckbox = $('notify_customer');
    if (!sendEmailCheckbox || !notifyCustomerCheckbox)
        return;
    notifyCustomerCheckbox.disabled = !sendEmailCheckbox.checked;
}
//]]>

window.notifyCustomerUpdate = notifyCustomerUpdate;
window.sendEmailCheckbox = sendEmailCheckbox;

});
</script>
