<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">customer_form.customer_form_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">Customer Information</item>
        <item name="reverseMetadataMerge" xsi:type="boolean">true</item>
    </argument>
    <settings>
        <buttons>
            <button name="save_and_continue" class="Magento\Customer\Block\Adminhtml\Edit\SaveAndContinueButton"/>
            <button name="save" class="Magento\Customer\Block\Adminhtml\Edit\SaveButton"/>
            <button name="reset" class="Magento\Customer\Block\Adminhtml\Edit\ResetButton"/>
            <button name="order" class="Magento\Customer\Block\Adminhtml\Edit\OrderButton"/>
            <button name="resetPassword" class="Magento\Customer\Block\Adminhtml\Edit\ResetPasswordButton"/>
            <button name="unlock" class="Magento\Customer\Block\Adminhtml\Edit\UnlockButton"/>
            <button name="invalidateToken" class="Magento\Customer\Block\Adminhtml\Edit\InvalidateTokenButton"/>
            <button name="delete" class="Magento\Customer\Block\Adminhtml\Edit\DeleteButton"/>
            <button name="back" class="Magento\Customer\Block\Adminhtml\Edit\BackButton"/>
        </buttons>
        <layout>
            <navContainerName>left</navContainerName>
            <type>tabs</type>
        </layout>
        <deps>
            <dep>customer_form.customer_form_data_source</dep>
        </deps>
    </settings>
    <dataSource name="customer_form_data_source">
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
            </item>
        </argument>
        <settings>
            <validateUrl path="customer/index/validate"/>
            <submitUrl path="customer/index/save"/>
        </settings>
        <dataProvider class="Magento\Customer\Model\Customer\DataProviderWithDefaultAddresses" name="customer_form_data_source">
            <settings>
                <requestFieldName>id</requestFieldName>
                <primaryFieldName>entity_id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <htmlContent name="customer_edit_tab_view_content">
        <block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View" name="customer_edit_tab_view" template="Magento_Customer::tab/view.phtml">
            <arguments>
                <argument name="sort_order" xsi:type="number">10</argument>
                <argument name="tab_label" xsi:type="string" translate="true">Customer View</argument>
            </arguments>
            <block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo" name="personal_info" template="Magento_Customer::tab/view/personal_info.phtml"/>
        </block>
    </htmlContent>
    <fieldset name="customer">
        <settings>
            <label translate="true">Account Information</label>
        </settings>
        <field name="entity_id" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>false</visible>
            </settings>
        </field>
        <field name="confirmation" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>false</visible>
            </settings>
        </field>
        <field name="created_in" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <visible>false</visible>
            </settings>
        </field>
        <field name="default_billing" formElement="checkbox">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>boolean</dataType>
                <visible>false</visible>
            </settings>
        </field>
        <field name="default_shipping" formElement="checkbox">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>boolean</dataType>
                <visible>false</visible>
            </settings>
        </field>
        <field name="website_id" component="Magento_Customer/js/form/element/website" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>number</dataType>
                <tooltip>
                    <link>https://docs.magento.com/user-guide/configuration/scope.html</link>
                    <description translate="true">If your Magento installation has multiple websites, you can edit the scope to associate the customer with a specific site.</description>
                </tooltip>
                <imports>
                    <link name="customerId">${ $.provider }:data.customer.entity_id</link>
                </imports>
            </settings>
            <formElements>
                <select>
                    <settings>
                        <options class="Magento\Customer\ViewModel\Customer\Website"/>
                    </settings>
                </select>
            </formElements>
        </field>
        <field name="prefix" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>true</visible>
            </settings>
        </field>
        <container name="container_group" component="Magento_Ui/js/form/components/group" sortOrder="20">
            <argument name="data" xsi:type="array">
                <item name="type" xsi:type="string">group</item>
                <item name="config" xsi:type="array">
                    <item name="dataScope" xsi:type="boolean">false</item>
                    <item name="validateWholeGroup" xsi:type="boolean">true</item>
                </item>
            </argument>
            <field name="group_id" formElement="select">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="fieldGroup" xsi:type="string">group_id</item>
                        <item name="source" xsi:type="string">customer</item>
                    </item>
                </argument>
                <settings>
                    <required>true</required>
                    <dataType>number</dataType>
                </settings>
            </field>
            <field name="disable_auto_group_change" formElement="checkbox" class="Magento\Customer\Ui\Component\Form\Field\DisableAutoGroupChange">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="fieldGroup" xsi:type="string">group_id</item>
                        <item name="source" xsi:type="string">customer</item>
                        <item name="default" xsi:type="number">0</item>
                    </item>
                </argument>
                <settings>
                    <dataType>boolean</dataType>
                </settings>
                <formElements>
                    <checkbox>
                        <settings>
                            <description translate="true">Disable Automatic Group Change Based on VAT ID</description>
                            <valueMap>
                                <map name="false" xsi:type="string">0</map>
                                <map name="true" xsi:type="string">1</map>
                            </valueMap>
                            <prefer>checkbox</prefer>
                        </settings>
                    </checkbox>
                </formElements>
            </field>
        </container>
        <field name="firstname" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>text</dataType>
            </settings>
        </field>
        <field name="middlename" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>true</visible>
            </settings>
        </field>
        <field name="lastname" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>text</dataType>
            </settings>
        </field>
        <field name="suffix" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>true</visible>
            </settings>
        </field>
        <field name="email" formElement="email">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="validate-email" xsi:type="boolean">true</rule>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>text</dataType>
            </settings>
        </field>
        <field name="dob" formElement="date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="validate-date" xsi:type="boolean">true</rule>
                    <rule name="validate-dob" xsi:type="boolean">true</rule>
                </validation>
                <dataType>text</dataType>
                <visible>true</visible>
            </settings>
            <formElements>
                <date>
                    <settings>
                        <options>
                            <option name="maxDate" xsi:type="string">-1d</option>
                        </options>
                    </settings>
                </date>
            </formElements>
        </field>
        <field name="taxvat" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>true</visible>
            </settings>
        </field>
        <field name="gender" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>true</visible>
            </settings>
        </field>
        <field name="sendemail_store_id" component="Magento_Ui/js/form/element/select" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">customer</item>
                </item>
            </argument>
            <settings>
                <dataType>number</dataType>
                <label translate="true">Send Welcome Email From</label>
                <imports>
                    <link name="value">${ $.provider }:data.customer.store_id</link>
                </imports>
            </settings>
            <formElements>
                <select>
                    <settings>
                        <options class="Magento\Customer\ViewModel\Customer\Store"/>
                        <filterBy>
                            <field>website_id</field>
                            <target>${ $.provider }:${ $.parentScope }.website_id</target>
                        </filterBy>
                    </settings>
                </select>
            </formElements>
        </field>
    </fieldset>
    <fieldset name="address" class="Magento\Customer\Ui\Component\Form\AddressFieldset">
        <settings>
            <collapsible>false</collapsible>
            <label translate="true">Addresses</label>
            <componentType>fieldset</componentType>
            <additionalClasses>
                <class name="customer-address-form">true</class>
            </additionalClasses>
        </settings>
        <container name="customer_default_billing_address_wrapper" template="Magento_Customer/default-address-wrapper">
            <component name="customer_default_billing_address_content" template="Magento_Customer/default-address">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="defaultAddressClass" xsi:type="string">billing-address</item>
                        <item name="defaultAddressId" xsi:type="string">billing-address-caption</item>
                        <item name="title" translate="true" xsi:type="string">Default Billing Address</item>
                        <item name="contentClass" xsi:type="string">customer-default-billing-address-content</item>
                        <item name="notExistsMessage" xsi:type="string" translate="true">The customer does not have default billing address</item>
                        <item name="tracks" xsi:type="array">
                            <item name="address" xsi:type="boolean">true</item>
                        </item>
                    </item>
                </argument>
                <settings>
                    <imports>
                        <link name="address">${ $.provider}:data.default_billing_address</link>
                    </imports>
                </settings>
            </component>
            <button name="edit_billing_address" component="Magento_Customer/js/address/default-address">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="buttonClasses" xsi:type="string">edit-default-billing-address-button</item>
                        <item name="buttonTextId" xsi:type="string">edit-billing-address</item>
                        <item name="ariLabelledby" xsi:type="string">billing-address-caption edit-billing-address</item>
                        <item name="actions" xsi:type="array">
                            <item name="0" xsi:type="array">
                                <item name="targetName" xsi:type="string">customer_form.areas.address.address.customer_address_update_modal.update_customer_address_form_loader</item>
                                <item name="actionName" xsi:type="string">destroyInserted</item>
                            </item>
                            <item name="1" xsi:type="array">
                                <item name="targetName" xsi:type="string">customer_form.areas.address.address.customer_address_update_modal</item>
                                <item name="actionName" xsi:type="string">openModal</item>
                            </item>
                            <item name="2" xsi:type="array">
                                <item name="targetName" xsi:type="string">customer_form.areas.address.address.customer_address_update_modal.update_customer_address_form_loader</item>
                                <item name="actionName" xsi:type="string">render</item>
                            </item>
                        </item>
                    </item>
                </argument>
                <settings>
                    <componentType>button</componentType>
                    <title translate="true">Edit</title>
                    <displayAsLink>true</displayAsLink>
                    <imports>
                        <link name="entityId">${ $.provider}:data.default_billing_address.entity_id</link>
                        <link name="entity">${ $.provider}:data.default_billing_address</link>
                    </imports>
                </settings>
            </button>
        </container>
        <container name="customer_default_shipping_address_wrapper" template="Magento_Customer/default-address-wrapper">
            <component name="customer_default_shipping_address_content" template="Magento_Customer/default-address">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="defaultAddressClass" xsi:type="string">shipping-address</item>
                        <item name="defaultAddressId" xsi:type="string">shipping-address-caption</item>
                        <item name="title" xsi:type="string" translate="true">Default Shipping Address</item>
                        <item name="contentClass" xsi:type="string">customer-default-shipping-address-content</item>
                        <item name="notExistsMessage" xsi:type="string" translate="true">The customer does not have default shipping address</item>
                        <item name="tracks" xsi:type="array">
                            <item name="address" xsi:type="boolean">true</item>
                        </item>
                    </item>
                </argument>
                <settings>
                    <imports>
                        <link name="address">${ $.provider}:data.default_shipping_address</link>
                    </imports>
                </settings>
            </component>
            <button name="edit_shipping_address" component="Magento_Customer/js/address/default-address">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="buttonClasses" xsi:type="string">edit-default-shipping-address-button</item>
                        <item name="buttonTextId" xsi:type="string">edit-shipping-address</item>
                        <item name="ariLabelledby" xsi:type="string">shipping-address-caption edit-shipping-address</item>
                        <item name="actions" xsi:type="array">
                            <item name="0" xsi:type="array">
                                <item name="targetName" xsi:type="string">customer_form.areas.address.address.customer_address_update_modal.update_customer_address_form_loader</item>
                                <item name="actionName" xsi:type="string">destroyInserted</item>
                            </item>
                            <item name="1" xsi:type="array">
                                <item name="targetName" xsi:type="string">customer_form.areas.address.address.customer_address_update_modal</item>
                                <item name="actionName" xsi:type="string">openModal</item>
                            </item>
                            <item name="2" xsi:type="array">
                                <item name="targetName" xsi:type="string">customer_form.areas.address.address.customer_address_update_modal.update_customer_address_form_loader</item>
                                <item name="actionName" xsi:type="string">render</item>
                            </item>
                        </item>
                    </item>
                </argument>
                <settings>
                    <componentType>button</componentType>
                    <title translate="true">Edit</title>
                    <displayAsLink>true</displayAsLink>
                    <imports>
                        <link name="entityId">${ $.provider}:data.default_shipping_address.entity_id</link>
                        <link name="entity">${ $.provider}:data.default_shipping_address</link>
                    </imports>
                </settings>
            </button>
        </container>
        <button name="add_address" component="Magento_Customer/js/address/default-address">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="formElement" xsi:type="string">container</item>
                    <item name="buttonClasses" xsi:type="string">add-new-address-button</item>
                    <item name="actions" xsi:type="array">
                        <item name="0" xsi:type="array">
                            <item name="targetName" xsi:type="string">${ $.parentName}.customer_address_update_modal.update_customer_address_form_loader</item>
                            <item name="actionName" xsi:type="string">destroyInserted</item>
                        </item>
                        <item name="1" xsi:type="array">
                            <item name="targetName" xsi:type="string">${ $.parentName}.customer_address_update_modal</item>
                            <item name="actionName" xsi:type="string">openModal</item>
                        </item>
                        <item name="2" xsi:type="array">
                            <item name="targetName" xsi:type="string">${ $.parentName}.customer_address_update_modal.update_customer_address_form_loader</item>
                            <item name="actionName" xsi:type="string">render</item>
                        </item>
                    </item>
                </item>
            </argument>
            <settings>
                <title translate="true">Add New Address</title>
                <imports>
                    <link name="parentId">${ $.provider}:data.customer_id</link>
                </imports>
            </settings>
        </button>
        <modal name="customer_address_update_modal">
            <settings>
                <options>
                    <option name="title" xsi:type="string" translate="true">Add/Update Address</option>
                </options>
            </settings>
            <insertForm name="update_customer_address_form_loader" component="Magento_Customer/js/form/components/insert-form">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="addressListingProvider" xsi:type="string">ns = customer_address_listing, index = customer_address_listing</item>
                        <item name="addressModalProvider" xsi:type="string">${ $.parentName }</item>
                    </item>
                </argument>
                <settings>
                    <formSubmitType>ajax</formSubmitType>
                    <renderUrl path="mui/index/render_handle">
                        <param name="handle">customer_address_edit</param>
                        <param name="buttons">1</param>
                    </renderUrl>
                    <loading>false</loading>
                    <toolbarContainer>${ $.parentName }</toolbarContainer>
                    <externalProvider>${ $.ns }.customer_address_form_data_source</externalProvider>
                    <ns>customer_address_form</ns>
                    <exports>
                        <link name="parentId">${ $.externalProvider }:data.parent_id</link>
                    </exports>
                    <imports>
                        <link name="parentId">${ $.provider}:data.customer_id</link>
                        <link name="onAddressDelete">${ $.ns }.${ $.ns }:deleteAddressAction</link>
                    </imports>
                </settings>
            </insertForm>
        </modal>
        <insertListing name="customer_address_listing" component="Magento_Customer/js/form/components/insert-listing">
            <settings>
                <dataLinks>
                    <exports>false</exports>
                    <imports>true</imports>
                </dataLinks>
                <externalProvider>customer_address_listing.customer_address_listing_data_source</externalProvider>
                <selectionsProvider>customer_address_listing.customer_address_listing.customer_address_columns.ids</selectionsProvider>
                <autoRender>true</autoRender>
                <dataScope>customer_address_listing</dataScope>
                <ns>customer_address_listing</ns>
                <exports>
                    <link name="parent_id">${ $.externalProvider }:params.parent_id</link>
                </exports>
                <imports>
                    <link name="parent_id">${ $.provider }:data.customer.entity_id</link>
                    <link name="onAction">ns = ${ $.ns }, index = actions:action</link>
                    <link name="onMassAction">ns = ${ $.ns }, index = listing_massaction:massaction</link>
                </imports>
            </settings>
        </insertListing>
    </fieldset>
</form>
