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

// @codingStandardsIgnoreFile

?>
<?php $_source  = $block->getSource() ?>
<?php if ($_source): ?>
    <tr>
        <td class="label"><?php /* @escapeNotVerified */ echo $block->getShippingLabel() ?><div id="shipping_amount_adv"></div></td>
        <td>
            <input type="text"
                   name="creditmemo[shipping_amount]"
                   value="<?php /* @escapeNotVerified */ echo $block->getShippingAmount()?>"
                   class="input-text admin__control-text not-negative-amount"
                   id="shipping_amount" />
        </td>
    </tr>
    <tr>
        <td class="label"><?php /* @escapeNotVerified */ echo __('Adjustment Refund') ?><div id="adjustment_positive_adv"></div></td>
        <td>
            <input type="text"
                   name="creditmemo[adjustment_positive]"
                   value="<?php /* @escapeNotVerified */ echo $_source->getBaseAdjustmentFeePositive()*1 ?>"
                   class="input-text admin__control-text not-negative-amount"
                   id="adjustment_positive" />
        </td>
    </tr>
    <tr>
        <td class="label"><?php /* @escapeNotVerified */ echo __('Adjustment Fee') ?><div id="adjustment_negative_adv"></div></td>
        <td>
            <input type="text"
                   name="creditmemo[adjustment_negative]"
                   value="<?php /* @escapeNotVerified */ echo $_source->getBaseAdjustmentFeeNegative()*1 ?>"
                   class="input-text admin__control-text not-negative-amount"
                   id="adjustment_negative"/>
            <script>
                require(['prototype'], function(){

                //<![CDATA[
                Validation.addAllThese([
                    ['not-negative-amount', '<?php /* @escapeNotVerified */ echo __('Please enter a positive number in this field.') ?>', function(v) {
                        if(v.length)
                            return /^\s*\d+([,.]\d+)*\s*%?\s*$/.test(v);
                        else
                            return true;
                    }]
                ]);

                if ($('shipping_amount')) {
                    $('shipping_amount').advaiceContainer = $('shipping_amount_adv');
                    unblockSubmit('shipping_amount');
                }
                if ($('adjustment_positive')) {
                    $('adjustment_positive').advaiceContainer = $('adjustment_positive_adv');
                    unblockSubmit('adjustment_positive');
                }
                if ($('adjustment_negative')) {
                    $('adjustment_negative').advaiceContainer = $('adjustment_negative_adv');
                    unblockSubmit('adjustment_negative');
                }

                function unblockSubmit(id) {
                    $(id).observe('focus', function(event) {
                        if ($$('button[class="scalable update-button disabled"]').size() > 0) {
                            enableElements('submit-button');
                        }
                    });
                }
                //]]>

                });
            </script>
        </td>
    </tr>

<?php endif; ?>
