define(
    [
        'jquery',
        'Magento_Checkout/js/model/quote',
        'mage/url',
        'Magento_Catalog/js/price-utils'
    ],
    function ($, quote, url, priceUtils) {
        "use strict";

        function getFormattedPrice(price) {
            return priceUtils.formatPrice(price.toFixed(2), quote.getPriceFormat());
        }

        quote.getTotals().subscribe(function (value) {
            $.get(
                url.build('threebyfour/payment/simulation') + "?amount=" + value['base_grand_total']
            ).done(function (response) {
                response = JSON.parse(response);
                response.forEach(function (simulation) {
                    console.log(simulation);
                    var code = simulation.business_transaction_details.business_transaction_code;
                    if ($("#" + code).length > 0) {
                        $("#" + code + "_total")[0].innerText = getFormattedPrice(simulation.payment_amount + simulation.total_cost);
                    }
                })
            })
        });
    }
);
