<?xml version="1.0"?>
<!--
/**
 * Hyvä Themes - https://hyva.io
 * Copyright © Hyvä Themes 2022-present. All rights reserved.
 * This product is licensed per Magento install
 * See https://hyva.io/license
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"
>
    <body>
        <!-- The hyva.checkout.components block does not really exist. It is only a virtual "container". -->
        <!-- To render a component declared here, it needs to be <move>d to the target column in the step. -->
        <!-- The reason to declare a component here is if it is more complex and will be used in more than one step. -->
        <referenceBlock name="hyva.checkout.components">
            <!-- Component: Guest Details -->
            <container name="checkout.guest-details.section" htmlTag="fieldset" htmlId="guest-details">
                <block name="checkout.guest-details.title"
                       template="Hyva_Checkout::section/title.phtml"
                >
                    <arguments>
                        <argument name="html_tag" xsi:type="string">legend</argument>
                    </arguments>

                    <action method="setTitle">
                        <argument name="title" translate="true" xsi:type="string">Contact Information</argument>
                    </action>
                </block>

                <block name="additional.signin-register"
                       template="Hyva_Checkout::breadcrumbs/signin-register.phtml"
                       ifconfig="hyva_themes_checkout/signin_registration/show_signin_registration_button"
                />

                <!-- Component Messenger: Guest Details -->
                <block name="component-messenger-guest-details"
                       template="Hyva_Checkout::page/messenger.phtml"
                       before="-"
                >
                    <arguments>
                        <argument name="event_prefix" xsi:type="string">guest:details</argument>
                    </arguments>
                </block>

                <block name="checkout.guest-details"
                       template="Hyva_Checkout::magewire/component/form.phtml"
                >
                    <arguments>
                        <argument name="magewire" xsi:type="object">
                            \Hyva\Checkout\Magewire\Checkout\GuestDetails
                        </argument>
                    </arguments>

                    <!-- Essential containers mandated by the template. -->
                    <container name="checkout.guest-details.before" as="before"/>
                    <container name="checkout.guest-details.after" as="after"/>
                </block>
            </container>

            <!-- Component: Shipping Details -->
            <container name="checkout.shipping-details.section" htmlTag="fieldset" htmlId="shipping-details">
                <block name="checkout.shipping-details.title"
                       template="Hyva_Checkout::section/title.phtml"
                       before="-"
                >
                    <arguments>
                        <argument name="html_tag" xsi:type="string">legend</argument>
                    </arguments>

                    <action method="setTitle">
                        <argument name="title" translate="true" xsi:type="string">Shipping Address</argument>
                    </action>
                </block>

                <container name="checkout.shipping-details.before">

                    <!-- Component Messenger: Shipping Details -->
                    <block name="component-messenger-shipping-details"
                           template="Hyva_Checkout::page/messenger.phtml"
                           before="-"
                    >
                        <arguments>
                            <argument name="event_prefix" xsi:type="string">shipping:details</argument>
                        </arguments>
                    </block>
                </container>

                <!-- @see \Hyva\Checkout\Model\Frontend\AddressTypeShipping -->
                <block name="checkout.shipping-details"
                       template="Hyva_Checkout::checkout/address-view/entity-details.phtml"
                >
                    <arguments>
                        <argument name="address_view" xsi:type="object">
                            \Hyva\Checkout\ViewModel\Checkout\AddressView\AddressViewShipping
                        </argument>

                        <argument name="magewire" xsi:type="object">
                            \Hyva\Checkout\Magewire\Checkout\AddressView\ShippingDetails
                        </argument>
                    </arguments>

                    <block name="checkout.shipping-details.address-list"
                           as="address-list"
                           template="Hyva_Checkout::checkout/address-view/address-list.phtml"
                    >
                        <arguments>
                            <argument name="address_list" xsi:type="object">
                                \Hyva\Checkout\ViewModel\Checkout\AddressView\AddressList\AddressListShipping
                            </argument>

                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\AddressView\ShippingDetails\AddressList
                            </argument>
                        </arguments>

                        <!-- Renderer: grid view -->
                        <block name="checkout.shipping-details.address-list.grid"
                               template="Hyva_Checkout::checkout/address-view/address-list/grid.phtml"
                               as="grid"/>
                         <!-- Renderer: list view -->
                        <block name="checkout.shipping-details.address-list.list"
                               template="Hyva_Checkout::checkout/address-view/address-list/list.phtml"
                               as="list"/>
                        <!-- Renderer: select (dropdown) view -->
                        <block name="checkout.shipping-details.address-list.select"
                               template="Hyva_Checkout::checkout/address-view/address-list/select.phtml"
                               as="select"/>

                        <!-- Form: shipping address (V1) -->
                        <block name="checkout.shipping-details.address-list.form"
                               as="address-form"
                               template="Hyva_Checkout::checkout/address-view/address-list/form.phtml"
                        >
                            <container name="shipping-details.address-form.before" as="address-form.before"/>

                            <arguments>
                                <argument name="magewire" xsi:type="object">
                                    \Hyva\Checkout\Magewire\Checkout\AddressView\ShippingDetails\AddressForm
                                </argument>
                            </arguments>

                            <container name="shipping-details.address-form.after" as="address-form.after"/>
                        </block>
                    </block>

                    <!-- Form: shipping address (V1) -->
                    <block name="checkout.shipping-details.address-form"
                           template="Hyva_Checkout::checkout/address-view/address-form.phtml"
                    >
                        <container name="shipping-details.address-form.customer.before" as="address-form.before"/>

                        <arguments>
                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\AddressView\ShippingDetails\AddressForm
                            </argument>
                        </arguments>

                        <container name="shipping-details.address-form.customer.after" as="address-form.after"/>
                    </block>

                    <!-- Address renderer for when the shipping address is the same as billing -->
                    <block name="checkout.shipping-details.address"
                           template="Hyva_Checkout::checkout/address-view/shipping-details/address.phtml"/>

                    <!-- Rendered by whichever address is collected second -->
                    <block name="checkout.shipping-details.same-address-toggle"
                           as="same-address-toggle"
                           template="Hyva_Checkout::checkout/address-view/same-address-toggle.phtml"
                    >
                        <arguments>
                            <argument name="address_view" xsi:type="object">
                                \Hyva\Checkout\ViewModel\Checkout\AddressView\AddressViewShipping
                            </argument>

                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\AddressView\SameAddressToggle
                            </argument>
                        </arguments>
                    </block>
                </block>
            </container>

            <!-- Component: Billing Details -->
            <container name="checkout.billing-details.section" htmlTag="fieldset" htmlId="billing-details">
                <block name="checkout.billing-details.title"
                       template="Hyva_Checkout::section/title.phtml"
                       before="-"
                >
                    <arguments>
                        <argument name="html_tag" xsi:type="string">legend</argument>
                    </arguments>

                    <action method="setTitle">
                        <argument name="title" translate="true" xsi:type="string">Billing Address</argument>
                    </action>
                </block>

                <container name="checkout.billing-details.before">

                    <!-- Component Messenger: Billing Details -->
                    <block name="component-messenger-billing-details"
                           template="Hyva_Checkout::page/messenger.phtml"
                           before="-"
                    >
                        <arguments>
                            <argument name="event_prefix" xsi:type="string">billing:details</argument>
                        </arguments>
                    </block>
                </container>

                <!-- @see \Hyva\Checkout\Model\Frontend\AddressTypeBilling -->
                <block name="checkout.billing-details"
                       template="Hyva_Checkout::checkout/address-view/entity-details.phtml"
                >
                    <arguments>
                        <argument name="address_view" xsi:type="object">
                            \Hyva\Checkout\ViewModel\Checkout\AddressView\AddressViewBilling
                        </argument>

                        <argument name="magewire" xsi:type="object">
                            \Hyva\Checkout\Magewire\Checkout\AddressView\BillingDetails
                        </argument>
                    </arguments>

                    <block name="checkout.billing-details.address-list"
                           as="address-list"
                           template="Hyva_Checkout::checkout/address-view/address-list.phtml"
                    >
                        <arguments>
                            <argument name="address_list" xsi:type="object">
                                \Hyva\Checkout\ViewModel\Checkout\AddressView\AddressList\AddressListBilling
                            </argument>

                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\AddressView\BillingDetails\AddressList
                            </argument>
                        </arguments>

                        <!-- Renderer: grid view -->
                        <block name="checkout.billing-details.address-list.grid"
                               template="Hyva_Checkout::checkout/address-view/address-list/grid.phtml"
                               as="grid"/>
                        <block name="checkout.billing-details.address-list.list"
                               template="Hyva_Checkout::checkout/address-view/address-list/list.phtml"
                               as="list"/>
                        <!-- Renderer: select (dropdown) view -->
                        <block name="checkout.billing-details.address-list.select"
                               template="Hyva_Checkout::checkout/address-view/address-list/select.phtml"
                               as="select"/>

                        <!-- Form: billing address -->
                        <block name="checkout.billing-details.address-list.form"
                               as="address-form"
                               template="Hyva_Checkout::checkout/address-view/address-list/form.phtml"
                        >
                            <container name="billing-details.address-form.before" as="address-form.before"/>

                            <arguments>
                                <argument name="magewire" xsi:type="object">
                                    \Hyva\Checkout\Magewire\Checkout\AddressView\BillingDetails\AddressForm
                                </argument>
                            </arguments>

                            <container name="billing-details.address-form.after" as="address-form.after"/>
                        </block>
                    </block>

                    <!-- Billing address form -->
                    <block name="checkout.billing-details.address-form"
                           template="Hyva_Checkout::checkout/address-view/address-form.phtml"
                    >
                        <container name="billing-details.address-form.customer.before" as="address-form.before"/>

                        <arguments>
                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\AddressView\BillingDetails\AddressForm
                            </argument>
                        </arguments>

                        <container name="billing-details.address-form.customer.after" as="address-form.after"/>
                    </block>

                    <!-- Address renderer for when the billing address is the same as shipping -->
                    <block name="checkout.billing-details.address"
                           template="Hyva_Checkout::checkout/address-view/billing-details/address.phtml"/>

                    <!-- Rendered by whichever address is collected second -->
                    <block name="checkout.billing-details.same-address-toggle"
                           as="same-address-toggle"
                           template="Hyva_Checkout::checkout/address-view/same-address-toggle.phtml"
                    >
                        <arguments>
                            <argument name="address_view" xsi:type="object">
                                \Hyva\Checkout\ViewModel\Checkout\AddressView\AddressViewBilling
                            </argument>

                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\AddressView\SameAddressToggle
                            </argument>
                        </arguments>
                    </block>
                </block>

                <container name="checkout.billing-details.after"/>
            </container>

            <!-- Section: Shipping -->
            <container name="checkout.shipping.section" htmlTag="fieldset" htmlId="shipping-section">
                <block name="checkout.shipping.title"
                       template="Hyva_Checkout::section/title.phtml"
                       before="-"
                >
                    <arguments>
                        <argument name="html_tag" xsi:type="string">legend</argument>
                    </arguments>

                    <action method="setTitle">
                        <argument name="title" translate="true" xsi:type="string">Shipping Methods</argument>
                    </action>
                </block>

                <container name="checkout.shipping.methods.before">

                    <!-- Component Messenger: Shipping Methods -->
                    <block name="component-messenger-shipping-methods"
                           template="Hyva_Checkout::page/messenger.phtml"
                           before="-"
                    >
                        <arguments>
                            <argument name="event_prefix" xsi:type="string">shipping:method</argument>
                        </arguments>
                    </block>
                </container>

                <block name="checkout.shipping.methods"
                       template="Hyva_Checkout::checkout/shipping/method-list.phtml"
                >
                    <arguments>
                        <argument name="magewire" xsi:type="object">
                            \Hyva\Checkout\Magewire\Checkout\Shipping\MethodList
                        </argument>
                    </arguments>

                    <!-- Register payment method view and make hereby available -->
                    <!-- Will not show an additional view as long as the template is not assigned onto the block -->
                    <!-- Shipping method view should go into templates/component/shipping/method/{carrier-method}.phtml-->
                    <block name="checkout.shipping.method.freeshipping_freeshipping" as="freeshipping_freeshipping"/>
                    <block name="checkout.shipping.method.flatrate_flatrate" as="flatrate_flatrate"/>
                    <block name="checkout.shipping.method.tablerate_bestway" as="tablerate_bestway"/>
                </block>

                <!-- In case you want to add block after the shipping method list -->
                <container name="checkout.shipping.methods.after"/>
            </container>

            <!-- Component: Payment -->
            <container name="checkout.payment.section"
                       htmlTag="fieldset"
                       htmlId="payment-section"
            >
                <block name="checkout.payment.title"
                       template="Hyva_Checkout::section/title.phtml"
                       before="-"
                >
                    <arguments>
                        <argument name="html_tag" xsi:type="string">legend</argument>
                    </arguments>

                    <action method="setTitle">
                        <argument name="title" translate="true" xsi:type="string">Payment Method</argument>
                    </action>
                </block>

                <container name="checkout.payment.methods.before">

                    <!-- Component Messenger: Payment Methods -->
                    <block name="component-messenger-payment-methods"
                           template="Hyva_Checkout::page/messenger.phtml"
                           before="-"
                    >
                        <arguments>
                            <argument name="event_prefix" xsi:type="string">payment:method</argument>
                        </arguments>
                    </block>
                </container>

                <block name="checkout.payment.methods"
                       template="Hyva_Checkout::checkout/payment/method-list.phtml"
                >
                    <arguments>
                        <argument name="magewire" xsi:type="object">
                            \Hyva\Checkout\Magewire\Checkout\Payment\MethodList
                        </argument>
                    </arguments>

                    <!-- Payment Renderer: Apple Pay: -->
                    <block name="checkout.payment.method.applepay"
                           as="braintree_applepay"
                           template="Hyva_Checkout::checkout/payment/method/applepay.phtml"/>

                    <!-- Payment Renderer: Bank Transfer Payment -->
                    <block name="checkout.payment.method.banktransfer"
                           as="banktransfer"
                           template="Hyva_Checkout::checkout/payment/method/banktransfer.phtml"/>

                    <!-- Payment Renderer: Check / Money Order -->
                    <block name="checkout.payment.method.checkmo"
                           as="checkmo"
                           template="Hyva_Checkout::checkout/payment/method/checkmo.phtml"/>

                    <!-- Payment Renderer: Cash on Delivery Payment -->
                    <block name="checkout.payment.method.cashondelivery"
                           as="cashondelivery"
                           template="Hyva_Checkout::checkout/payment/method/cashondelivery.phtml"/>

                    <!-- Payment Renderer: Purchase Order -->
                    <block name="checkout.payment.method.purchaseorder"
                           as="purchaseorder"
                           template="Hyva_Checkout::checkout/payment/method/purchaseorder.phtml"
                    >
                        <arguments>
                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\Payment\Method\PurchaseOrder
                            </argument>
                        </arguments>
                    </block>
                </block>

                <!-- In case you want to add block after the payment method list -->
                <container name="checkout.payment.methods.after"/>
            </container>

            <!-- Component: Quote Summary -->
            <container name="checkout.quote-summary.section"
                       htmlTag="div"
                       htmlId="quote-summary"
                       htmlClass="space-y-6"
            >
                <container name="checkout.price-summary.section"
                           htmlTag="div"
                           htmlClass="price-summary"
                >
                    <block name="checkout.quote-summary.title"
                           template="Hyva_Checkout::section/title.phtml"
                           before="-"
                    >
                        <action method="setTitle">
                            <argument name="title" translate="true" xsi:type="string">Order Summary</argument>
                        </action>
                    </block>

                    <block name="price-summary.cart-items"
                           template="Hyva_Checkout::checkout/price-summary/cart-items.phtml"
                    >
                        <arguments>
                            <argument name="magewire" xsi:type="object">Hyva\Checkout\Magewire\Checkout\PriceSummary\CartItems</argument>
                        </arguments>

                        <!-- Cart item type renderer options -->
                        <block name="cart-items.product-type-renderers"
                               as="product-type-renderers"
                        >
                            <block name="product-type.simple"
                                   as="default"
                                   template="Hyva_Checkout::checkout/price-summary/cart-items/type/default.phtml"/>
                        </block>
                    </block>

                    <block name="coupon-code"
                           template="Hyva_Checkout::checkout/coupon-code.phtml"
                           before="price-summary.total-segments"
                           ifconfig="hyva_themes_checkout/component/discount_code/enable"
                    >
                        <arguments>
                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\CouponCode
                            </argument>
                        </arguments>

                        <!--
                            Essential containers mandated by the template.

                            No component messenger here on purpose: everything the coupon code reports,
                            its own successes and failures as well as a refused reCAPTCHA, goes out as a
                            Magewire flash message.
                        -->
                        <container name="checkout.coupon-code.before" as="before"/>
                        <container name="checkout.coupon-code.after" as="after"/>
                    </block>

                    <block name="price-summary.total-segments"
                           template="Hyva_Checkout::checkout/price-summary/total-segments.phtml"
                    >
                        <arguments>
                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\PriceSummary
                            </argument>
                        </arguments>

                        <!-- Note: In order for each total renderer to become visible, a manual set renderer block is required. -->
                        <block name="price-summary.total-segment.subtotal"
                               as="subtotal"
                               template="Hyva_Checkout::checkout/price-summary/total-segments/subtotal.phtml"
                        >
                            <block name="total-segment.tax.tax_subtotals_details"
                                   as="tax_details"
                                   template="Hyva_Checkout::checkout/price-summary/total-segments/extension-attributes/subtotal-tax-details.phtml"
                            />
                        </block>

                        <block name="price-summary.total-segment.discount"
                               as="discount"
                               template="Hyva_Checkout::checkout/price-summary/total-segments/discount.phtml"
                        />

                        <block name="price-summary.total-segment.tax"
                               as="tax"
                               template="Hyva_Checkout::checkout/price-summary/total-segments/tax.phtml"
                        >
                            <block name="total-segment.tax.tax_grandtotal_details"
                                   as="tax_grandtotal_details"
                                   template="Hyva_Checkout::checkout/price-summary/total-segments/extension-attributes/tax-grandtotal-details.phtml"
                            />
                        </block>

                        <block name="price-summary.total-segment.weee"
                               as="weee"
                               template="Hyva_Checkout::checkout/price-summary/total-segments/weee.phtml"
                        />

                        <block name="price-summary.total-segment.weee_tax"
                               as="weee_tax"
                               template="Hyva_Checkout::checkout/price-summary/total-segments/weee.phtml"
                        />

                        <block name="price-summary.total-segment.grand_total"
                               as="grand_total"
                               template="Hyva_Checkout::checkout/price-summary/total-segments/grand-total.phtml"
                        >
                            <block name="total-segment.tax.tax_grand_total_details"
                                   as="tax_details"
                                   template="Hyva_Checkout::checkout/price-summary/total-segments/extension-attributes/grand-total-tax-details.phtml"
                            />
                        </block>
                    </block>
                </container>
            </container>

            <!-- Component: Additional Options -->
            <container name="checkout.section.additional-options" htmlTag="fieldset" htmlId="additional-options">
                <block name="checkout.order-comment.title"
                       template="Hyva_Checkout::section/title.phtml"
                >
                    <arguments>
                        <argument name="html_tag" xsi:type="string">legend</argument>
                    </arguments>

                    <action method="setTitle">
                        <argument name="title" translate="true" xsi:type="string">Options</argument>
                    </action>
                </block>

                <block name="checkout.order-comment"
                       template="Hyva_Checkout::checkout/customer-comment.phtml"
                       ifconfig="hyva_themes_checkout/component/order_comment/enable"
                >
                    <arguments>
                        <argument name="magewire" xsi:type="object">
                            \Hyva\Checkout\Magewire\Checkout\CustomerComment
                        </argument>
                    </arguments>
                </block>
            </container>

            <!-- Component: Quote Actions -->
            <container name="checkout.section.quote-actions"
                       htmlTag="fieldset"
                       htmlId="quote-actions"
            >
                <container name="checkout.section.quote-actions.before">

                    <!-- Component Messenger: Quote Actions -->
                    <block name="component-messenger-quote-actions"
                           template="Hyva_Checkout::page/messenger.phtml"
                           before="-"
                    >
                        <arguments>
                            <argument name="event_prefix" xsi:type="string">quote:actions</argument>
                        </arguments>
                    </block>
                </container>

                <!-- Wrapper: title is dependent on if any agreements are available. -->
                <block name="checkout.terms-conditions.wrapper"
                       template="Hyva_Checkout::section/terms/terms-wrapper.phtml"
                       ifconfig="checkout/options/enable_agreements"
                >
                    <block name="checkout.terms-conditions.title"
                           template="Hyva_Checkout::section/title.phtml"
                    >
                        <arguments>
                            <argument name="html_tag" xsi:type="string">legend</argument>
                        </arguments>

                        <action method="setTitle">
                            <argument name="title" translate="true" xsi:type="string">Terms and Conditions</argument>
                        </action>
                    </block>

                    <!-- Component Messenger: Terms and Conditions -->
                    <block name="component-messenger-terms-conditions-details"
                           as="messenger"
                           template="Hyva_Checkout::page/messenger.phtml"
                           before="-"
                    >
                        <arguments>
                            <argument name="event_prefix" xsi:type="string">terms-conditions:details</argument>
                        </arguments>
                    </block>

                    <block name="checkout.terms-conditions"
                           template="Hyva_Checkout::checkout/terms-conditions.phtml"
                    >
                        <arguments>
                            <argument name="magewire" xsi:type="object">
                                \Hyva\Checkout\Magewire\Checkout\TermsConditions
                            </argument>
                        </arguments>

                        <block name="checkout.terms-conditions.list"
                               as="list"
                               template="Hyva_Checkout::checkout/terms-conditions/list.phtml"/>
                        <block name="checkout.terms-conditions.message-only"
                               as="message"
                               template="Hyva_Checkout::checkout/terms-conditions/message.phtml"/>
                        <block name="checkout.terms-conditions.message-including-page"
                               as="page"
                               template="Hyva_Checkout::checkout/terms-conditions/message.phtml"/>
                    </block>
                </block>
            </container>

            <!--
                Component: Place Order reCAPTCHA.

                The "ifconfig" on the block is enough to leave nothing behind, since a container whose
                children rendered nothing is not rendered either.
            -->
            <container name="checkout.place-order-recaptcha.section"
                       htmlTag="div"
                       htmlId="place-order-recaptcha"
            >
                <block name="checkout.place-order-recaptcha"
                       template="Hyva_Checkout::checkout/place-order-recaptcha.phtml"
                       ifconfig="recaptcha_frontend/type_for/place_order"
                >
                    <arguments>
                        <argument name="magewire" xsi:type="object">
                            \Hyva\Checkout\Magewire\Checkout\PlaceOrderReCaptcha
                        </argument>
                        <!--
                            Do not remove the view model from layout!

                            Passing it here instead of requiring it inside the template keeps the
                            reCAPTCHA implementation in sync with Magento: disabling Magento's reCAPTCHA
                            modules makes the view model unavailable and the markup is skipped, without
                            the template needing to know about it.
                        -->
                        <argument name="viewModelRecaptcha" xsi:type="object">Hyva\Theme\ViewModel\ReCaptcha</argument>
                    </arguments>
                </block>
            </container>
        </referenceBlock>

        <!-- Summary: Adding shipping total costs. -->
        <referenceBlock name="price-summary.total-segments">
            <block name="price-summary.total-segment.shipping"
                   as="shipping"
                   template="Hyva_Checkout::checkout/price-summary/total-segments/shipping.phtml"
            >
                <block name="total-segment.tax.tax_shipping_details"
                       as="tax_details"
                       template="Hyva_Checkout::checkout/price-summary/total-segments/extension-attributes/shipping-tax-details.phtml"
                />
            </block>
        </referenceBlock>
    </body>
</page>

