<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="PortalPeople_GetAddressAutocomplete::css/address-autocomplete.css"/>
    </head>
    <body>
        <referenceContainer name="before.body.end">
            <!-- Inject GetAddress.io configuration into window.checkoutConfig -->
            <block class="PortalPeople\GetAddressAutocomplete\Block\Checkout\ConfigBlock" name="getaddress_config_inject" template="PortalPeople_GetAddressAutocomplete::config-inject.phtml"/>
        </referenceContainer>

        <referenceBlock name="checkout.root">
            <!-- Inject GetAddress.io configuration within checkout root as a fallback -->
            <block class="PortalPeople\GetAddressAutocomplete\Block\Checkout\ConfigBlock" name="getaddress_config_inject_root" template="PortalPeople_GetAddressAutocomplete::config-inject.phtml"/>
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shipping-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <!-- Inject into the shippingAddress regions that are rendered by the checkout template -->
                                                <item name="shippingAddress" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="before-fields" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="address-autocomplete" xsi:type="array">
                                                                    <item name="component" xsi:type="string">PortalPeople_GetAddressAutocomplete/js/view/address-autocomplete</item>
                                                                    <item name="displayArea" xsi:type="string">before-fields</item>
                                                                    <item name="sortOrder" xsi:type="string">0</item>
                                                                    <item name="config" xsi:type="array">
                                                                        <item name="template" xsi:type="string">PortalPeople_GetAddressAutocomplete/address-autocomplete</item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                        <item name="before-form" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>
