<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="1column" />

    <!-- Remove the original product attributes block -->
    <referenceContainer name="product.info.details">
        <referenceBlock name="product.attributes" remove="true" />
    </referenceContainer>

    <referenceContainer name="page.wrapper">
        <!-- Create new product details wrapper under main.content for tabs section -->
        <container name="product.info.details.wrapper" after="main.content" htmlTag="div" htmlClass="page-main page-main-details">
            <container name="product.info.details.wrapper.columns" htmlTag="div" htmlClass="columns">
                <container name="product.info.details.wrapper.main" label="Product Details Main Content Container" htmlTag="div" htmlClass="column main"/>
            </container>
        </container>
        <!-- Create wrapper for description without page-main class which adds gutters -->
        <container name="product.info.description.wrapper" after="main.content" before="product.info.details.after.wrapper" htmlTag="div" htmlClass="page-main-description product-full-width-section" htmlId="description"/>
        <!-- Create a new wrapper to house the custom Page Builder attributes -->
        <container name="product.attributes.pagebuilder.wrapper" after="product.info.description.wrapper" before="product.info.details.after.wrapper" htmlTag="div" htmlClass="page-main-pagebuilder-attributes">
            <block class="Magento\PageBuilder\Block\Catalog\Block\Product\View\Attributes" name="product.attributes.only.pagebuilder" as="additional.pagebuilder" template="Magento_PageBuilder::catalog/product/view/attribute_list.phtml">
                <arguments>
                    <argument name="display_attributes" xsi:type="string">pagebuilder_only</argument>
                </arguments>
            </block>
        </container>
        <!-- Create new product details wrapper under main.content for tabs section -->
        <container name="product.info.details.after.wrapper" after="product.attributes.pagebuilder.wrapper" before="product.info.details.wrapper" htmlTag="div" htmlClass="page-main page-main-details">
            <container name="product.info.details.after.wrapper.columns" htmlTag="div" htmlClass="columns">
                <container name="product.info.details.after.wrapper.main" label="Product Details Main Content Container" htmlTag="div" htmlClass="column main">
                    <block class="Magento\Framework\View\Element\Template" name="product.attributes.wrapper" template="Magento_PageBuilder::catalog/product/view/section_wrapper.phtml">
                        <arguments>
                            <argument name="title" translate="true" xsi:type="string">More Information</argument>
                        </arguments>
                        <!-- Create a new instance of attributes which excludes Page Builder attributes -->
                        <block class="Magento\PageBuilder\Block\Catalog\Block\Product\View\Attributes" name="product.attributes.exclude.pagebuilder" as="additional" template="Magento_Catalog::product/view/attributes.phtml">
                            <arguments>
                                <argument name="display_attributes" xsi:type="string">non_pagebuilder</argument>
                            </arguments>
                        </block>
                    </block>
                    <block class="Magento\Framework\View\Element\Template" name="product.reviews.wrapper" after="product.attributes.wrapper" template="Magento_PageBuilder::catalog/product/view/section_wrapper.phtml">
                        <arguments>
                            <argument name="title" translate="true" xsi:type="string">Reviews</argument>
                        </arguments>
                        <block class="Magento\Review\Block\Product\View\ListView" name="product.info.product_additional_data.wrapper" template="Magento_Review::product/view/list.phtml" ifconfig="catalog/review/active">
                            <arguments>
                                <argument name="hide_title" xsi:type="boolean">true</argument>
                            </arguments>
                        </block>
                    </block>
                </container>
            </container>
        </container>
    </referenceContainer>

    <!-- Move details & description into their new wrappers -->
    <move element="product.info.details" destination="product.info.details.wrapper.main"/>
    <move element="product.info.description" destination="product.info.description.wrapper"/>

    <!-- Move reviews into the section after the description -->
    <move element="reviews.tab" destination="product.reviews.wrapper"/>

    <!-- Move content.aside below the reviews -->
    <move element="content.aside" destination="product.info.details.after.wrapper.main" after="product.reviews.wrapper"/>
</layout>
