<script type="text/javascript">
    // Inject GetAddress.io configuration directly into checkoutConfig
    require(['jquery', 'domReady!'], function($) {
        'use strict';

        // Merge the getaddress_autocomplete config
        var configData = <?php echo $block->getAddressAutocompleteConfig(); ?>;

        // Expose a fallback global config
        window.getAddressAutocompleteConfig = configData.getaddress_autocomplete || {};

        function mergeConfig() {
            if (typeof window.checkoutConfig === 'undefined') {
                window.checkoutConfig = {};
            }

            if (!window.checkoutConfig.getaddress_autocomplete) {
                window.checkoutConfig = $.extend(true, window.checkoutConfig, configData);
                console.log('GetAddress.io Config Injected:', window.checkoutConfig.getaddress_autocomplete);
            } else {
                console.log('GetAddress.io Config Already Present:', window.checkoutConfig.getaddress_autocomplete);
            }
        }

        // Try immediately and after a short delay in case checkoutConfig is set later
        mergeConfig();
        setTimeout(mergeConfig, 0);
        setTimeout(mergeConfig, 200);
    });
</script>
