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

// @codingStandardsIgnoreFile

?>
<legend class="admin__legend"><span><?php /* @escapeNotVerified */ echo __('Order Totals') ?></span></legend>
<br>

<table class="admin__table-secondary data-table">
    <tbody>
        <?php /* @escapeNotVerified */ echo $block->renderTotals(); ?>
        <?php /* @escapeNotVerified */ echo $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"><?php /* @escapeNotVerified */ echo __('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"><?php /* @escapeNotVerified */ echo __('Email Order Confirmation') ?></label>
    </div>
    <?php endif; ?>
    <div class="actions">
        <?php echo $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>
